From f5f11c64786d7941f3374349251e13dcb571b1f3 Mon Sep 17 00:00:00 2001 From: Laury Date: Sat, 25 Sep 2021 19:30:37 +0200 Subject: [PATCH] [poincare] Added simplification of equals --- poincare/src/equal.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/poincare/src/equal.cpp b/poincare/src/equal.cpp index 3e8ca67bd..8f3b2932e 100644 --- a/poincare/src/equal.cpp +++ b/poincare/src/equal.cpp @@ -52,11 +52,28 @@ Expression Equal::standardEquation(Context * context, Preferences::ComplexFormat Expression Equal::shallowReduce(ExpressionNode::ReductionContext reductionContext) { Expression e = Equal::Builder(Subtraction::Builder(childAtIndex(0).clone(), childAtIndex(1).clone()).shallowReduce(reductionContext), Rational::Builder(0)); - if (e.childAtIndex(0).isIdenticalTo(e.childAtIndex(1))) { + Expression leftSide = e.childAtIndex(0); + if (leftSide.isIdenticalTo(e.childAtIndex(1))) { Expression result = Rational::Builder(1); replaceWithInPlace(result); return result; } + if (leftSide.isUndefined()) { + return leftSide; + } + if (leftSide.type() == ExpressionNode::Type::Multiplication) { + Multiplication m = static_cast(leftSide); + int i = 0; + while (i < numberOfChildren()-1) { + if (m.childAtIndex(i).nullStatus(reductionContext.context()) == ExpressionNode::NullStatus::NonNull) { + m.removeChildAtIndexInPlace(i); + } + else { + i++; + } + } + } + return e; }