[poincare] Fix: always attach to parent before shallow reducing an

expression
This commit is contained in:
Émilie Feral
2018-09-12 15:40:40 +02:00
parent 4712aaa872
commit 978053e01f
4 changed files with 11 additions and 5 deletions

View File

@@ -49,6 +49,7 @@ Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUni
}
Expression c = childAtIndex(0);
#if MATRIX_EXACT_REDUCING
#if 0
if (!c.recursivelyMatches(Expression::IsMatrix)) {
return Power(c, Rational(-1).shallowReduce(context, angleUnit);
}
@@ -59,10 +60,12 @@ Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUni
}
}
return *this;
#endif
#else
if (c.type() != ExpressionNode::Type::Matrix) {
Expression result = Power(c, Rational(-1)).shallowReduce(context, angleUnit);
Expression result = Power(c, Rational(-1));
replaceWithInPlace(result);
result = result.shallowReduce(context, angleUnit);
return result;
}
return *this;

View File

@@ -39,6 +39,7 @@ Expression MatrixTrace::shallowReduce(Context & context, Preferences::AngleUnit
}
Expression c = childAtIndex(0);
#if MATRIX_EXACT_REDUCING
#if 0
if (c.type() == ExpressionNode::Type::Matrix) {
Matrix m = static_cast<Matrix&>(c);
if (m.numberOfRows() != m.numberOfColumns()) {
@@ -55,6 +56,7 @@ Expression MatrixTrace::shallowReduce(Context & context, Preferences::AngleUnit
return c;
}
return *this;
#endif
#else
if (c.type() != ExpressionNode::Type::Matrix) {
replaceWithInPlace(c);

View File

@@ -24,9 +24,8 @@ Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::Angl
}
#endif
Logarithm l = Logarithm(childAtIndex(0), Symbol(Ion::Charset::Exponential));
Expression result = l.shallowReduce(context, angleUnit);
replaceWithInPlace(result);
return result;
replaceWithInPlace(l);
return l.shallowReduce(context, angleUnit);
}
}

View File

@@ -10,8 +10,10 @@ Expression SimplificationHelper::Map(const Expression & e, Context & context, Pr
Matrix matrix;
for (int i = 0; i < c->numberOfChildren(); i++) {
Expression f = e.replaceChildAtIndexInPlace(0, e.childAtIndex(0).childAtIndex(i));
matrix.addChildAtIndexInPlace(f.shallowReduce(context, angleUnit), i, i);
matrix.addChildAtIndexInPlace(f, i, i);
f.shallowReduce(context, angleUnit);
}
replaceWithInPlace(matrix);
return matrix.shallowReduce(context, angleUnit);
}