From 978053e01f29e29e5717c84591fe4278f41da473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 12 Sep 2018 15:40:40 +0200 Subject: [PATCH] [poincare] Fix: always attach to parent before shallow reducing an expression --- poincare/src/matrix_inverse.cpp | 5 ++++- poincare/src/matrix_trace.cpp | 2 ++ poincare/src/naperian_logarithm.cpp | 5 ++--- poincare/src/simplification_helper.cpp | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/poincare/src/matrix_inverse.cpp b/poincare/src/matrix_inverse.cpp index ad72cb278..42d651c07 100644 --- a/poincare/src/matrix_inverse.cpp +++ b/poincare/src/matrix_inverse.cpp @@ -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; diff --git a/poincare/src/matrix_trace.cpp b/poincare/src/matrix_trace.cpp index caa276f0b..d2b8883c1 100644 --- a/poincare/src/matrix_trace.cpp +++ b/poincare/src/matrix_trace.cpp @@ -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(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); diff --git a/poincare/src/naperian_logarithm.cpp b/poincare/src/naperian_logarithm.cpp index 02e238e61..aaf8fcb61 100644 --- a/poincare/src/naperian_logarithm.cpp +++ b/poincare/src/naperian_logarithm.cpp @@ -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); } } diff --git a/poincare/src/simplification_helper.cpp b/poincare/src/simplification_helper.cpp index 1c2dd24fa..3afadd465 100644 --- a/poincare/src/simplification_helper.cpp +++ b/poincare/src/simplification_helper.cpp @@ -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); }