mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare/multiplication] Handle non reduced matrices in shallowReduce
This commit is contained in:
@@ -261,7 +261,7 @@ Expression Multiplication::denominator(Context * context, Preferences::ComplexFo
|
||||
|
||||
Expression Multiplication::privateShallowReduce(ExpressionNode::ReductionContext reductionContext, bool shouldExpand, bool canBeInterrupted) {
|
||||
{
|
||||
Expression e = Expression::defaultShallowReduce();;
|
||||
Expression e = Expression::defaultShallowReduce();
|
||||
if (e.isUndefined()) {
|
||||
return e;
|
||||
}
|
||||
@@ -275,9 +275,8 @@ Expression Multiplication::privateShallowReduce(ExpressionNode::ReductionContext
|
||||
sortChildrenInPlace([](const ExpressionNode * e1, const ExpressionNode * e2, bool canBeInterrupted) { return ExpressionNode::SimplificationOrder(e1, e2, true, canBeInterrupted); }, reductionContext.context(), true);
|
||||
|
||||
// Step 3: Handle matrices
|
||||
/* All children have been simplified so if any child contains a matrix, it
|
||||
* is at the root node of the child. Moreover, thanks to the simplification
|
||||
* order, all matrix children (if any) are the last children. */
|
||||
/* Thanks to the simplification order, all matrix children (if any) are the
|
||||
* last children. */
|
||||
Expression lastChild = childAtIndex(numberOfChildren()-1);
|
||||
if (lastChild.type() == ExpressionNode::Type::Matrix) {
|
||||
Matrix resultMatrix = static_cast<Matrix &>(lastChild);
|
||||
@@ -343,9 +342,14 @@ Expression Multiplication::privateShallowReduce(ExpressionNode::ReductionContext
|
||||
resultMatrix = newResult;
|
||||
multiplicationChildIndex--;
|
||||
}
|
||||
// Distribute the remaining multiplication children on the matrix children
|
||||
int remainingChildrenCount = numberOfChildren();
|
||||
if (remainingChildrenCount > 1) {
|
||||
/* Distribute the remaining multiplication children on the matrix children,
|
||||
* if there are no oether matrices (such as a non reduced confidence
|
||||
* interval). */
|
||||
|
||||
if (multiplicationChildIndex >= 0) {
|
||||
if (SortedIsMatrix(childAtIndex(multiplicationChildIndex), reductionContext.context())) {
|
||||
return *this;
|
||||
}
|
||||
removeChildInPlace(resultMatrix, resultMatrix.numberOfChildren());
|
||||
for (int i = 0; i < n*m; i++) {
|
||||
Multiplication m = clone().convert<Multiplication>();
|
||||
@@ -552,7 +556,7 @@ void Multiplication::mergeMultiplicationChildrenInPlace() {
|
||||
while (i < numberOfChildren()) {
|
||||
Expression c = childAtIndex(i);
|
||||
if (c.type() == ExpressionNode::Type::Multiplication) {
|
||||
mergeChildrenAtIndexInPlace(c, numberOfChildren()); // TODO: ensure that matrix children are not swapped to implement MATRIX_EXACT_REDUCING
|
||||
mergeChildrenAtIndexInPlace(c, i); // TODO: ensure that matrix children are not swapped to implement MATRIX_EXACT_REDUCING
|
||||
continue;
|
||||
}
|
||||
i++;
|
||||
|
||||
@@ -70,4 +70,5 @@ QUIZ_CASE(poincare_multiplication_simplify) {
|
||||
assert_parsed_expression_simplify_to("12^(1/4)×(π/6)×(12×π)^(1/4)", "(√(3)×π^(5/4))/3");
|
||||
assert_parsed_expression_simplify_to("[[1,2+𝐢][3,4][5,6]]×[[1,2+𝐢,3,4][5,6+𝐢,7,8]]", "[[11+5×𝐢,13+9×𝐢,17+7×𝐢,20+8×𝐢][23,30+7×𝐢,37,44][35,46+11×𝐢,57,68]]");
|
||||
assert_parsed_expression_simplify_to("[[1,2][3,4]]×[[1,3][5,6]]×[[2,3][4,6]]", "[[82,123][178,267]]");
|
||||
assert_parsed_expression_simplify_to("π×confidence(π/5,3)[[1,2]]", "π×confidence(π/5,3)×[[1,2]]");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user