From 13ef08d6282f3ab749cbacafe196ff7d2bf683b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 31 Oct 2017 11:25:12 +0100 Subject: [PATCH] [poincare] Change Expression::compareTo to SimplificationOrder Change-Id: I0f3dff0a0933f55164573623253ee24f1a85d2a7 --- poincare/include/poincare/decimal.h | 2 +- poincare/include/poincare/dynamic_hierarchy.h | 7 +-- poincare/include/poincare/expression.h | 51 ++++++++++++------- poincare/include/poincare/factorial.h | 4 +- poincare/include/poincare/power.h | 4 +- poincare/include/poincare/rational.h | 2 +- poincare/include/poincare/static_hierarchy.h | 2 +- poincare/include/poincare/symbol.h | 2 +- poincare/src/addition.cpp | 4 +- poincare/src/decimal.cpp | 2 +- poincare/src/division.cpp | 2 +- poincare/src/dynamic_hierarchy.cpp | 16 +++--- poincare/src/expression.cpp | 12 ++--- poincare/src/factorial.cpp | 10 ++-- poincare/src/logarithm.cpp | 4 +- poincare/src/multiplication.cpp | 16 +++--- poincare/src/power.cpp | 14 ++--- poincare/src/rational.cpp | 2 +- poincare/src/static_hierarchy.cpp | 6 +-- poincare/src/symbol.cpp | 2 +- poincare/src/trigonometry.cpp | 2 +- poincare/test/simplify_easy.cpp | 2 +- poincare/test/simplify_utils.cpp | 6 +-- 23 files changed, 95 insertions(+), 79 deletions(-) diff --git a/poincare/include/poincare/decimal.h b/poincare/include/poincare/decimal.h index 9bf3a5047..62b1f3955 100644 --- a/poincare/include/poincare/decimal.h +++ b/poincare/include/poincare/decimal.h @@ -29,7 +29,7 @@ private: int numberOfDigitsInMantissa() const; /* Sorting */ - int compareToSameTypeExpression(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; constexpr static int k_maxLength = 10; Integer m_mantissa; diff --git a/poincare/include/poincare/dynamic_hierarchy.h b/poincare/include/poincare/dynamic_hierarchy.h index 8a5baa9aa..08b2ae124 100644 --- a/poincare/include/poincare/dynamic_hierarchy.h +++ b/poincare/include/poincare/dynamic_hierarchy.h @@ -23,14 +23,15 @@ public: void addOperands(const Expression * const * operands, int numberOfOperands); void addOperandAtIndex(Expression * operand, int index); void mergeOperands(DynamicHierarchy * d); - void sortChildren(); + typedef int (*ExpressionOrder)(const Expression * e1, const Expression * e2); + void sortOperands(ExpressionOrder order); Expression * squashUnaryHierarchy(); protected: bool deleteUselessOperand(int index); private: void removeOperandAtIndex(int i, bool deleteAfterRemoval); - int compareToSameTypeExpression(const Expression * e) const override; - int compareToGreaterTypeExpression(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; + int simplificationOrderGreaterType(const Expression * e) const override; virtual bool isUselessOperand(const Rational * r) = 0; const Expression ** m_operands; int m_numberOfOperands; diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 18a8f4ef8..c03669a7e 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -135,12 +135,16 @@ public: virtual void swapOperands(int i, int j) = 0; //void removeFromParent(); - /* Sorting */ - /* compareTo returns: - * 1 if this > e - * -1 if this < e - * 0 if this == e */ - int compareTo(const Expression * e) const; + + // Comparison + /* isIdenticalTo is the "easy" equality, it returns true if both trees have + * same structures and all their nodes have same types and values (ie, + * sqrt(pi^2) is NOT identical to pi). */ + bool isIdenticalTo(const Expression * e) const { + /* We use the simplification order only because it is a already-coded total + * order on expresssions. */ + return SimplificationOrder(this, e) == 0; + } /* Layout Engine */ ExpressionLayout * createLayout(FloatDisplayMode floatDisplayMode = FloatDisplayMode::Default, ComplexFormat complexFormat = ComplexFormat::Default) const; // Returned object must be deleted @@ -166,10 +170,17 @@ protected: typedef float SinglePrecision; typedef double DoublePrecision; template static T epsilon(); - /* Compare (== < and >) the type of the root node of 2 expressions. - * This behavior makes sense for value-less nodes (addition, product, fraction - * power, etc… For nodes with a value (Integer, Complex), this must be over- - * -riden. */ + + /* Simplification order returns: + * 1 if e1 > e2 + * -1 if e1 < e2 + * 0 if e1 == e + * Following the order described in Computer Algebra and Symbolic Computation, + * Joel S. Cohen (section 3.1). The order groups like terms together to avoid + * quadratic complexity when factorizing addition or multiplication. For + * example, it groups terms with same bases together (ie Pi, Pi^3) and with + * same non-rational factors together (ie Pi, 2*Pi). */ + static int SimplificationOrder(const Expression * e1, const Expression * e2); private: /* Simplification */ Expression * deepBeautify(Context & context, AngleUnit angleUnit); @@ -182,15 +193,19 @@ private: /* Evaluation Engine */ virtual Evaluation * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const = 0; virtual Evaluation * privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const = 0; - /* Sorting */ - virtual int compareToGreaterTypeExpression(const Expression * e) const { - return -1; - } - /* What should be the implementation of complex? */ - virtual int compareToSameTypeExpression(const Expression * e) const { - return 0; - } + virtual Expression * setSign(Sign s, Context & context, AngleUnit angleUnit) { assert(false); return nullptr; } + + /* In the simplification order, most expressions are compared by only + * comparing their types. However hierarchical expressions of same type would + * compare their operands and thus need to reimplement + * simplificationOrderSameType. Besides, operations that can be simplified + * (ie +, *, ^, !) have specific rules to group like terms together and thus + * reimplement simplificationOrderGreaterType. */ + virtual int simplificationOrderGreaterType(const Expression * e) const { return -1; } + virtual int simplificationOrderSameType(const Expression * e) const { return 0; } + /* TODO: What should be the implementation for complex? */ + Expression * m_parent; }; diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index d2fad8b8e..1f9cb8057 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -22,8 +22,8 @@ private: Expression * shallowSimplify(Context& context, AngleUnit angleUnit) override; ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override; int writeTextInBuffer(char * buffer, int bufferSize) const override; - int compareToGreaterTypeExpression(const Expression * e) const override; - int compareToSameTypeExpression(const Expression * e) const override; + int simplificationOrderGreaterType(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; }; } diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 65da669f2..8bc324d07 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -39,8 +39,8 @@ private: return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, name()); } static const char * name() { return "^"; } - int compareToGreaterTypeExpression(const Expression * e) const override; - int compareToSameTypeExpression(const Expression * e) const override; + int simplificationOrderGreaterType(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; Expression * simplifyPowerPower(Power * p, Expression * r, Context & context, AngleUnit angleUnit); Expression * simplifyPowerMultiplication(Multiplication * m, Expression * r, Context & context, AngleUnit angleUnit); Expression * simplifyRationalRationalPower(Expression * result, Rational * a, Rational * b, Context & context, AngleUnit angleUnit); diff --git a/poincare/include/poincare/rational.h b/poincare/include/poincare/rational.h index e5518aac1..5fc0b6d4d 100644 --- a/poincare/include/poincare/rational.h +++ b/poincare/include/poincare/rational.h @@ -50,7 +50,7 @@ private: } /* Sorting */ - int compareToSameTypeExpression(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; Integer m_numerator; Integer m_denominator; diff --git a/poincare/include/poincare/static_hierarchy.h b/poincare/include/poincare/static_hierarchy.h index e13ea000e..0fe716d34 100644 --- a/poincare/include/poincare/static_hierarchy.h +++ b/poincare/include/poincare/static_hierarchy.h @@ -23,7 +23,7 @@ public: virtual bool hasValidNumberOfOperands(int numberOfOperands) const; protected: void build(const Expression * const * operands, int numberOfOperands, bool cloneOperands); - int compareToSameTypeExpression(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; const Expression * m_operands[T]; }; diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 341244000..cf80878d8 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -42,7 +42,7 @@ private: template Evaluation * templatedEvaluate(Context& context, AngleUnit angleUnit) const; ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override; int writeTextInBuffer(char * buffer, int bufferSize) const override; - int compareToSameTypeExpression(const Expression * e) const override; + int simplificationOrderSameType(const Expression * e) const override; const char m_name; }; diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index b2855ae23..30e672c6f 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -35,7 +35,7 @@ Expression * Addition::shallowSimplify(Context& context, AngleUnit angleUnit) { index = 0; } } - sortChildren(); + sortOperands(Expression::SimplificationOrder); int i = 0; while (i < numberOfOperands()) { if (deleteUselessOperand(i) && i > 0) { @@ -128,7 +128,7 @@ bool Addition::TermsHaveIdenticalNonRationalFactors(const Expression * e1, const } const Expression * f1 = (e1->type() == Type::Multiplication && e1->numberOfOperands() == 2 && e1->operand(0)->type() == Type::Rational) ? e1->operand(1) : e1; const Expression * f2 = (e2->type() == Type::Multiplication && e2->numberOfOperands() == 2 && e2->operand(0)->type() == Type::Rational) ? e2->operand(1) : e2; - return (f1->compareTo(f2) == 0); + return f1->isIdenticalTo(f2); } Expression * Addition::shallowBeautify(Context & context, AngleUnit angleUnit) { diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index f3d1be1c6..040cd8514 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -165,7 +165,7 @@ Expression * Decimal::shallowSimplify(Context& context, AngleUnit angleUnit) { return replaceWith(new Rational(numerator, denominator), true); } -int Decimal::compareToSameTypeExpression(const Expression * e) const { +int Decimal::simplificationOrderSameType(const Expression * e) const { // We should not get there are decimal are turned into Rational before simplification assert(false); return 0; diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index bc68f5d5b..ce0db326c 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -42,7 +42,7 @@ Expression * Division::shallowBeautify(Context & context, AngleUnit angleUnit) { if (sin == nullptr || cos == nullptr) { break; } - if (sin->operand(0)->compareTo(cos->operand(0)) != 0) { + if (!sin->operand(0)->isIdenticalTo(cos->operand(0))) { k++; continue; } diff --git a/poincare/src/dynamic_hierarchy.cpp b/poincare/src/dynamic_hierarchy.cpp index cbc0ac9f9..32c18a31a 100644 --- a/poincare/src/dynamic_hierarchy.cpp +++ b/poincare/src/dynamic_hierarchy.cpp @@ -102,7 +102,7 @@ void DynamicHierarchy::removeOperandAtIndex(int i, bool deleteAfterRemoval) { m_numberOfOperands--; } -int DynamicHierarchy::compareToSameTypeExpression(const Expression * e) const { +int DynamicHierarchy::simplificationOrderSameType(const Expression * e) const { int m = this->numberOfOperands(); int n = e->numberOfOperands(); for (int i = 1; i <= m; i++) { @@ -110,8 +110,8 @@ int DynamicHierarchy::compareToSameTypeExpression(const Expression * e) const { if (n < i) { return 1; } - if (this->operand(m-i)->compareTo(e->operand(n-i)) != 0) { - return this->operand(m-i)->compareTo(e->operand(n-i)); + if (SimplificationOrder(this->operand(m-i), e->operand(n-i)) != 0) { + return SimplificationOrder(this->operand(m-i), e->operand(n-i)); } } // The NULL node is the least node type. @@ -121,14 +121,14 @@ int DynamicHierarchy::compareToSameTypeExpression(const Expression * e) const { return 0; } -int DynamicHierarchy::compareToGreaterTypeExpression(const Expression * e) const { +int DynamicHierarchy::simplificationOrderGreaterType(const Expression * e) const { int m = numberOfOperands(); if (m == 0) { return -1; } /* Compare e to last term of hierarchy. */ - if (operand(m-1)->compareTo(e) != 0) { - return operand(m-1)->compareTo(e); + if (SimplificationOrder(operand(m-1), e) != 0) { + return SimplificationOrder(operand(m-1), e); } if (m > 1) { return 1; @@ -136,11 +136,11 @@ int DynamicHierarchy::compareToGreaterTypeExpression(const Expression * e) const return 0; } -void DynamicHierarchy::sortChildren() { +void DynamicHierarchy::sortOperands(ExpressionOrder order) { for (int i = numberOfOperands()-1; i > 0; i--) { bool isSorted = true; for (int j = 0; j < numberOfOperands()-1; j++) { - if (operand(j)->compareTo(operand(j+1)) > 0) { + if (order(operand(j), operand(j+1)) > 0) { swapOperands(j, j+1); isSorted = false; } diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index b17177eda..ccbc14f51 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -130,13 +130,13 @@ Expression * Expression::replaceWith(Expression * newOperand, bool deleteAfterRe static_cast(m_parent)->removeOperand(this); }*/ -int Expression::compareTo(const Expression * e) const { - if (this->type() > e->type()) { - return -(e->compareTo(this)); - } else if (this->type() == e->type()) { - return compareToSameTypeExpression(e); +int Expression::SimplificationOrder(const Expression * e1, const Expression * e2) { + if (e1->type() > e2->type()) { + return -(e2->simplificationOrderGreaterType(e1)); + } else if (e1->type() == e2->type()) { + return e1->simplificationOrderSameType(e2); } else { - return compareToGreaterTypeExpression(e); + return e1->simplificationOrderGreaterType(e2); } } diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index 4b0dc9541..8d1ce5088 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -69,11 +69,11 @@ ExpressionLayout * Factorial::privateCreateLayout(FloatDisplayMode floatDisplayM return new HorizontalLayout(childrenLayouts, 2); } -int Factorial::compareToGreaterTypeExpression(const Expression * e) const { - if (operand(0)->compareTo(e) == 0) { +int Factorial::simplificationOrderGreaterType(const Expression * e) const { + if (SimplificationOrder(operand(0),e) == 0) { return 1; } - return operand(0)->compareTo(e); + return SimplificationOrder(operand(0), e); } int Factorial::writeTextInBuffer(char * buffer, int bufferSize) const { @@ -90,8 +90,8 @@ int Factorial::writeTextInBuffer(char * buffer, int bufferSize) const { return numberOfChar; } -int Factorial::compareToSameTypeExpression(const Expression * e) const { - return operand(0)->compareTo(e->operand(0)); +int Factorial::simplificationOrderSameType(const Expression * e) const { + return SimplificationOrder(operand(0), e->operand(0)); } } diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index d66c77dce..4acb8a9ec 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -102,12 +102,12 @@ Expression * Logarithm::splitInteger(Integer i, bool isDenominator, Context & co Expression * Logarithm::shallowBeautify(Context & context, AngleUnit angleUnit) { Symbol e = Symbol(Ion::Charset::Exponential); const Expression * logOperand[1] = {operand(0)}; - if (numberOfOperands() == 2 && operand(1)->compareTo(&e) == 0) { + if (numberOfOperands() == 2 && operand(1)->isIdenticalTo(&e)) { NaperianLogarithm * nl = new NaperianLogarithm(logOperand, true); return replaceWith(nl, true); } Rational one = Rational(Integer(1)); - if (numberOfOperands() == 2 && operand(1)->compareTo(&one) == 0) { + if (numberOfOperands() == 2 && operand(1)->isIdenticalTo(&one)) { Logarithm * l = new Logarithm(logOperand, 1, true); return replaceWith(l, true); } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 8b21545a0..c8f607ee8 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -97,7 +97,7 @@ bool Multiplication::HaveSameNonRationalFactors(const Expression * e1, const Exp int firstNonRationalOperand1 = e1->operand(0)->type() == Type::Rational ? 1 : 0; int firstNonRationalOperand2 = e2->operand(0)->type() == Type::Rational ? 1 : 0; for (int i = 0; i < numberOfNonRationalFactors1; i++) { - if (e1->operand(firstNonRationalOperand1+i)->compareTo(e2->operand(firstNonRationalOperand2+i)) != 0) { + if (!(e1->operand(firstNonRationalOperand1+i)->isIdenticalTo(e2->operand(firstNonRationalOperand2+i)))) { return false; } } @@ -208,7 +208,7 @@ bool Multiplication::resolveSquareRootAtDenominator(Context & context, AngleUnit } void Multiplication::factorize(Context & context, AngleUnit angleUnit) { - sortChildren(); + sortOperands(SimplificationOrder); int i = 0; while (i < numberOfOperands()) { if (deleteUselessOperand(i) && i > 0) { @@ -320,11 +320,11 @@ const Rational * Multiplication::RationalFactorInExpression(const Expression * e bool Multiplication::TermsHaveIdenticalBase(const Expression * e1, const Expression * e2) { const Expression * f1 = e1->type() == Type::Power ? e1->operand(0) : e1; const Expression * f2 = e2->type() == Type::Power ? e2->operand(0) : e2; - return (f1->compareTo(f2) == 0); + return f1->isIdenticalTo(f2); } bool Multiplication::TermsHaveIdenticalNonUnitaryExponent(const Expression * e1, const Expression * e2) { - return e1->type() == Type::Power && e2->type() == Type::Power && (e1->operand(1)->compareTo(e2->operand(1)) == 0); + return e1->type() == Type::Power && e2->type() == Type::Power && (e1->operand(1)->isIdenticalTo(e2->operand(1))); } bool Multiplication::TermHasRationalBase(const Expression * e) { @@ -397,7 +397,7 @@ Expression * Multiplication::shallowBeautify(Context & context, AngleUnit angleU if (denominatorOperand->type() == Type::Multiplication) { const Expression * integerDenominator[1] = {new Rational(r->denominator())}; static_cast(denominatorOperand)->addOperands(integerDenominator, 1); - static_cast(denominatorOperand)->sortChildren(); + static_cast(denominatorOperand)->sortOperands(SimplificationOrder); } else { const Expression * multOperands[2] = {new Rational(r->denominator()), denominatorOperand->clone()}; Multiplication * m = new Multiplication(multOperands, 2, false); @@ -482,11 +482,11 @@ Expression * Multiplication::mergeNegativePower(Context & context, AngleUnit ang } const Expression * powOperands[2] = {m, new Rational(Integer(-1))}; Power * p = new Power(powOperands, false); - m->sortChildren(); + m->sortOperands(SimplificationOrder); m->squashUnaryHierarchy(); const Expression * multOperand[1] = {p}; addOperands(multOperand, 1); - sortChildren(); + sortOperands(SimplificationOrder); return squashUnaryHierarchy(); } @@ -515,7 +515,7 @@ void Multiplication::leastCommonMultiple(Expression * factor, Context & context, } const Expression * newOp[1] = {factor->clone()}; addOperands(newOp, 1); - sortChildren(); + sortOperands(SimplificationOrder); } template Poincare::Evaluation* Poincare::Multiplication::computeOnComplexAndMatrix(Poincare::Complex const*, Poincare::Evaluation*); diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index da4501556..c45a882b3 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -117,21 +117,21 @@ ExpressionLayout * Power::privateCreateLayout(FloatDisplayMode floatDisplayMode, return new BaselineRelativeLayout(m_operands[0]->createLayout(floatDisplayMode, complexFormat),indiceOperand->createLayout(floatDisplayMode, complexFormat), BaselineRelativeLayout::Type::Superscript); } -int Power::compareToSameTypeExpression(const Expression * e) const { - int baseComparison = operand(0)->compareTo(static_cast(e)->operand(0)); +int Power::simplificationOrderSameType(const Expression * e) const { + int baseComparison = SimplificationOrder(operand(0), e->operand(0)); if (baseComparison != 0) { return baseComparison; } - return operand(1)->compareTo(static_cast(e)->operand(1)); + return SimplificationOrder(operand(1), e->operand(1)); } -int Power::compareToGreaterTypeExpression(const Expression * e) const { - int baseComparison = operand(0)->compareTo(e); +int Power::simplificationOrderGreaterType(const Expression * e) const { + int baseComparison = SimplificationOrder(operand(0), e); if (baseComparison != 0) { return baseComparison; } Rational one(Integer(1)); - return operand(1)->compareTo(&one); + return SimplificationOrder(operand(1), &one); } Expression * Power::shallowSimplify(Context& context, AngleUnit angleUnit) { @@ -320,7 +320,7 @@ Expression * Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational * r const Expression * operand[1] = {pExp}; m->addOperands(operand, 1); } - m->sortChildren(); + m->sortOperands(SimplificationOrder); return m; } diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index 249eabe1c..e2f93eabd 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -114,7 +114,7 @@ Rational Rational::Power(const Rational & i, const Integer & j) { // Comparison -int Rational::compareToSameTypeExpression(const Expression * e) const { +int Rational::simplificationOrderSameType(const Expression * e) const { assert(e->type() == Expression::Type::Rational); const Rational * other = static_cast(e); Integer i1 = Integer::Multiplication(m_numerator, other->denominator()); diff --git a/poincare/src/static_hierarchy.cpp b/poincare/src/static_hierarchy.cpp index b240bb999..48eed941f 100644 --- a/poincare/src/static_hierarchy.cpp +++ b/poincare/src/static_hierarchy.cpp @@ -54,14 +54,14 @@ void StaticHierarchy::build(const Expression * const * operands, int numberOf } template -int StaticHierarchy::compareToSameTypeExpression(const Expression * e) const { +int StaticHierarchy::simplificationOrderSameType(const Expression * e) const { for (int i = 0; i < this->numberOfOperands(); i++) { // The NULL node is the least node type. if (e->numberOfOperands() <= i) { return 1; } - if (this->operand(i)->compareTo(e->operand(i)) != 0) { - return this->operand(i)->compareTo(e->operand(i)); + if (SimplificationOrder(this->operand(i), e->operand(i)) != 0) { + return SimplificationOrder(this->operand(i), e->operand(i)); } } // The NULL node is the least node type. diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 5f06254f6..1c255e62e 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -135,7 +135,7 @@ bool Symbol::isMatrixSymbol() const { return false; } -int Symbol::compareToSameTypeExpression(const Expression * e) const { +int Symbol::simplificationOrderSameType(const Expression * e) const { assert(e->type() == Expression::Type::Symbol); if (m_name == ((Symbol *)e)->m_name) { return 0; diff --git a/poincare/src/trigonometry.cpp b/poincare/src/trigonometry.cpp index ca0703e1a..ea244a7a1 100644 --- a/poincare/src/trigonometry.cpp +++ b/poincare/src/trigonometry.cpp @@ -186,7 +186,7 @@ Expression * Trigonometry::table(const Expression * e, Expression::Type type, Co } SimplificationRoot inputRoot(input); inputRoot.deepSimplify(context, angleUnit); // input expression does not change, no root needed and we can use entry after - if (inputRoot.operand(0)->compareTo(e) == 0) { + if (inputRoot.operand(0)->isIdenticalTo(e)) { Expression * output = Expression::parse(cheatTable[i][outputIndex]); if (output == nullptr) { return nullptr; diff --git a/poincare/test/simplify_easy.cpp b/poincare/test/simplify_easy.cpp index f51ee82e1..871b938d2 100644 --- a/poincare/test/simplify_easy.cpp +++ b/poincare/test/simplify_easy.cpp @@ -27,7 +27,7 @@ void assert_parsed_expression_simplify_to(const char * expression, const char * cout << "---- compared to: " << simplifiedExpression << "----" << endl; print_expression(f, 0); #endif - assert(e->compareTo(f) == 0); + assert(e->isIdenticalTo(f)); delete e; delete f; } diff --git a/poincare/test/simplify_utils.cpp b/poincare/test/simplify_utils.cpp index c837bb981..cb9381d46 100644 --- a/poincare/test/simplify_utils.cpp +++ b/poincare/test/simplify_utils.cpp @@ -34,7 +34,7 @@ bool simplifies_to(const char * input_string, const char * expected_string) { print_expression(expected); #endif - bool isIdentical = input->compareTo(expected) == 0; + bool isIdentical = input->isIdentical(expected); delete expected; delete input; @@ -61,7 +61,7 @@ bool identical_to(const char * input_string, const char * expected_string) { print_expression(expected); #endif - bool isIdentical = input->compareTo(expected) == 0; + bool isIdentical = input->isIdentical(expected); delete expected; delete input; @@ -99,7 +99,7 @@ bool equivalent_to(const char * input_string, const char * expected_string) { cout << "Simplified Expected = " << endl; print_expression(expected); #endif - bool isEquivalent = input->compareTo(expected) == 0; + bool isEquivalent = input->isIdentical(expected); delete expected; delete input;