diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index e6699ca1a..142b8966a 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -297,6 +297,7 @@ protected: /* Hierarchy */ Expression parent() const; // TODO try to inline + Expression replaceWithUndefinedInPlace(); void defaultSetChildrenInPlace(Expression other); void addChildAtIndexInPlace(TreeHandle t, int index, int currentNumberOfChildren) = delete; void removeChildAtIndexInPlace(int i) = delete; diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index b2b316994..f949c068a 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -175,9 +175,7 @@ Expression Addition::shallowReduce(ExpressionNode::ReductionContext reductionCon /* If there is a matrix in the children, the last child is a matrix. If * there is a ascalar, the first child is a scalar. * We forbid the addition of a matrix and a scalar. */ - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } // Create the addition matrix (in place of the first child) Matrix resultMatrix = static_cast(firstChild); @@ -191,9 +189,7 @@ Expression Addition::shallowReduce(ExpressionNode::ReductionContext reductionCon int currentM = currentMatrix.numberOfColumns(); if (currentN != n || currentM != m) { // Addition of matrices of different dimensions -> undef - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } // Dispatch the current matrix children in the created addition matrix for (int j = 0; j < n*m; j++) { diff --git a/poincare/src/binomial_coefficient.cpp b/poincare/src/binomial_coefficient.cpp index 343de9a9e..51f83857d 100644 --- a/poincare/src/binomial_coefficient.cpp +++ b/poincare/src/binomial_coefficient.cpp @@ -65,25 +65,19 @@ Expression BinomialCoefficient::shallowReduce(Context * context) { Expression c1 = childAtIndex(1); if (SortedIsMatrix(c0, context) || SortedIsMatrix(c1, context)) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (!r0.integerDenominator().isOne() || r0.isNegative()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne() || r1.isNegative()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { @@ -95,9 +89,7 @@ Expression BinomialCoefficient::shallowReduce(Context * context) { Integer n = r0.signedIntegerNumerator(); Integer k = r1.signedIntegerNumerator(); if (n.isLowerThan(k)) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } /* If n is too big, we do not reduce in order to avoid too long computation. * The binomial coefficient will be approximatively evaluated later. */ diff --git a/poincare/src/confidence_interval.cpp b/poincare/src/confidence_interval.cpp index db026ccd6..a0439125c 100644 --- a/poincare/src/confidence_interval.cpp +++ b/poincare/src/confidence_interval.cpp @@ -62,24 +62,18 @@ Expression ConfidenceInterval::shallowReduce(ExpressionNode::ReductionContext re Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (SortedIsMatrix(c0, reductionContext.context()) || SortedIsMatrix(c1, reductionContext.context())) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (r0.signedIntegerNumerator().isNegative() || Integer::NaturalOrder(r0.signedIntegerNumerator(), r0.integerDenominator()) > 0) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne() || r1.signedIntegerNumerator().isNegative()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index 52cb396ce..99e821b13 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -146,9 +146,7 @@ Expression Derivative::shallowReduce(Context * context) { || SortedIsMatrix(childAtIndex(1), context) || SortedIsMatrix(childAtIndex(2), context)) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } // TODO: to be implemented diff(+) -> +diff() etc return *this; diff --git a/poincare/src/division_quotient.cpp b/poincare/src/division_quotient.cpp index f62a6b240..cffae83bc 100644 --- a/poincare/src/division_quotient.cpp +++ b/poincare/src/division_quotient.cpp @@ -46,24 +46,18 @@ Expression DivisionQuotient::shallowReduce() { Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (!r0.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { diff --git a/poincare/src/division_remainder.cpp b/poincare/src/division_remainder.cpp index 9f0f13c01..14b5723ec 100644 --- a/poincare/src/division_remainder.cpp +++ b/poincare/src/division_remainder.cpp @@ -47,24 +47,18 @@ Expression DivisionRemainder::shallowReduce() { Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (!r0.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 9b98414b7..d881bb6e3 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -1,9 +1,9 @@ #include #include -#include #include -#include +#include #include +#include #include #include #include @@ -240,6 +240,12 @@ Expression Expression::parent() const { return static_cast(p); } +Expression Expression::replaceWithUndefinedInPlace() { + Expression result = Undefined::Builder(); + replaceWithInPlace(result); + return result; +} + void Expression::defaultSetChildrenInPlace(Expression other) { assert(numberOfChildren() == other.numberOfChildren()); for (int i = 0; i < numberOfChildren(); i++) { diff --git a/poincare/src/factor.cpp b/poincare/src/factor.cpp index 52b67dfd4..059f7091b 100644 --- a/poincare/src/factor.cpp +++ b/poincare/src/factor.cpp @@ -67,9 +67,7 @@ Expression Factor::shallowReduce() { } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { // TODO LEA SortedIsMatrix? - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } return *this; } @@ -77,9 +75,7 @@ Expression Factor::shallowReduce() { Expression Factor::shallowBeautify(ExpressionNode::ReductionContext reductionContext) { Expression c = childAtIndex(0); if (c.type() != ExpressionNode::Type::Rational) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Rational r = static_cast(c); if (r.isZero()) { @@ -88,17 +84,13 @@ Expression Factor::shallowBeautify(ExpressionNode::ReductionContext reductionCon } Multiplication numeratorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.unsignedIntegerNumerator(), reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()); if (numeratorDecomp.numberOfChildren() == 0) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Expression result = numeratorDecomp.squashUnaryHierarchyInPlace(); if (!r.integerDenominator().isOne()) { Multiplication denominatorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.integerDenominator(), reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()); if (denominatorDecomp.numberOfChildren() == 0) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } result = Division::Builder(result, denominatorDecomp.squashUnaryHierarchyInPlace()); } diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index f5f6c5a64..5e12fa7cb 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -91,9 +91,7 @@ Expression Factorial::shallowReduce(ExpressionNode::ReductionContext reductionCo if (c.type() == ExpressionNode::Type::Rational) { Rational r = c.convert(); if (!r.integerDenominator().isOne() || r.sign() == ExpressionNode::Sign::Negative) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (Integer(k_maxOperandValue).isLowerThan(r.unsignedIntegerNumerator())) { return *this; @@ -105,9 +103,7 @@ Expression Factorial::shallowReduce(ExpressionNode::ReductionContext reductionCo } if (c.type() == ExpressionNode::Type::Constant) { // e! = undef, i! = undef, pi! = undef - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } return *this; } diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index d7e98e09b..25ddbeb38 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -138,9 +138,7 @@ Expression Function::shallowReduce(ExpressionNode::ReductionContext reductionCon return e.deepReduce(reductionContext); } if (!reductionContext.symbolicComputation()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } return *this; } diff --git a/poincare/src/great_common_divisor.cpp b/poincare/src/great_common_divisor.cpp index 2086df496..32ee6155c 100644 --- a/poincare/src/great_common_divisor.cpp +++ b/poincare/src/great_common_divisor.cpp @@ -60,24 +60,18 @@ Expression GreatCommonDivisor::shallowReduce() { Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { //TODO LEA SortedIsMatrix ? - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (!r0.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index 6542fe855..661bfa879 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -225,9 +225,7 @@ Expression Integral::shallowReduce(Context * context) { || SortedIsMatrix(childAtIndex(2), context) || SortedIsMatrix(childAtIndex(3), context)) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } return *this; } diff --git a/poincare/src/least_common_multiple.cpp b/poincare/src/least_common_multiple.cpp index af091c500..33a32fdc9 100644 --- a/poincare/src/least_common_multiple.cpp +++ b/poincare/src/least_common_multiple.cpp @@ -64,24 +64,18 @@ Expression LeastCommonMultiple::shallowReduce() { Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (!r0.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index 7d2387362..2386e4084 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -111,9 +111,7 @@ Expression Logarithm::shallowReduce(ExpressionNode::ReductionContext reductionCo } if (SortedIsMatrix(childAtIndex(1), reductionContext.context())) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Expression c = childAtIndex(0); @@ -220,15 +218,11 @@ Expression Logarithm::simpleShallowReduce(Context * context, Preferences::Comple Expression b = childAtIndex(1); // log(0,0)->Undefined if (c.type() == ExpressionNode::Type::Rational && b.type() == ExpressionNode::Type::Rational && static_cast(b).isZero() && static_cast(c).isZero()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } // log(x,1)->Undefined if (b.type() == ExpressionNode::Type::Rational && static_cast(b).isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } bool infiniteArg = c.recursivelyMatches(Expression::IsInfinity, context); // log(x,x)->1 with x != inf and log(inf,inf) = undef @@ -251,9 +245,7 @@ Expression Logarithm::simpleShallowReduce(Context * context, Preferences::Comple bool infiniteBase = b.recursivelyMatches(Expression::IsInfinity, context); // Special case: log(0,inf) -> undef if (infiniteBase) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } bool isNegative = true; Expression result; diff --git a/poincare/src/matrix_identity.cpp b/poincare/src/matrix_identity.cpp index 79f6112e8..c015030d8 100644 --- a/poincare/src/matrix_identity.cpp +++ b/poincare/src/matrix_identity.cpp @@ -47,22 +47,19 @@ Expression MatrixIdentity::shallowReduce(ExpressionNode::ReductionContext reduct if (e.isUndefined()) { return e; } - - Expression c = childAtIndex(0); - if (!c.isRationalOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; - } - Integer dimension = static_cast(c).signedIntegerNumerator(); - if (Integer::NaturalOrder(dimension, Integer(Integer::k_maxExtractableInteger)) > 0) { - return *this; - } - int dim = dimension.extractedInt(); - Expression result = Matrix::CreateIdentity(dim); - replaceWithInPlace(result); - return result; } + Expression c = childAtIndex(0); + if (!c.isRationalOne()) { + return replaceWithUndefinedInPlace(); + } + Integer dimension = static_cast(c).signedIntegerNumerator(); + if (Integer::NaturalOrder(dimension, Integer(Integer::k_maxExtractableInteger)) > 0) { + return *this; + } + int dim = dimension.extractedInt(); + Expression result = Matrix::CreateIdentity(dim); + replaceWithInPlace(result); + return result; } } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 3bfdbc1ab..c3c8bf636 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -297,9 +297,7 @@ Expression Multiplication::privateShallowReduce(ExpressionNode::ReductionContext int currentM = currentMatrix.numberOfColumns(); if (currentM != n) { // Matrices dimensions do not match for multiplication - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } /* Create the matrix resulting of the multiplication of the current matrix * and the result matrix diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index 1a577dbe3..a3bddbf73 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -72,9 +72,7 @@ Expression NthRoot::shallowReduce(ExpressionNode::ReductionContext reductionCont } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix || childAtIndex(1).type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Expression invIndex = Power::Builder(childAtIndex(1), Rational::Builder(-1)); Power p = Power::Builder(childAtIndex(0), invIndex); diff --git a/poincare/src/permute_coefficient.cpp b/poincare/src/permute_coefficient.cpp index 459636603..62e0d66c8 100644 --- a/poincare/src/permute_coefficient.cpp +++ b/poincare/src/permute_coefficient.cpp @@ -60,24 +60,18 @@ Expression PermuteCoefficient::shallowReduce() { Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (!r0.integerDenominator().isOne() || r0.sign() == ExpressionNode::Sign::Negative) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne() || r1.sign() == ExpressionNode::Sign::Negative) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 71107ed3c..48f4e35d3 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -292,9 +292,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex // Step 0: Handle matrices if (index.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (base.type() == ExpressionNode::Type::Matrix) { Matrix matrixBase = static_cast(base); @@ -302,9 +300,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex || !static_cast(index).integerDenominator().isOne() || matrixBase.numberOfRows() != matrixBase.numberOfColumns()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Integer exponent = static_cast(index).signedIntegerNumerator(); if (exponent.isNegative()) { @@ -359,9 +355,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex if (b.isZero()) { // 0^0 = undef or (±inf)^0 = undef if ((childAtIndex(0).type() == ExpressionNode::Type::Rational && childAtIndex(0).convert().isZero()) || childAtIndex(0).type() == ExpressionNode::Type::Infinity) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } // x^0 if (reductionContext.target() == ExpressionNode::ReductionTarget::User || childAtIndex(0).isNumber()) { @@ -393,9 +387,7 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex } // 0^x with x < 0 = undef if (childAtIndex(1).sign(reductionContext.context()) == ExpressionNode::Sign::Negative) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } // 1^x = 1 if x != ±inf diff --git a/poincare/src/prediction_interval.cpp b/poincare/src/prediction_interval.cpp index cf67a1d87..dee435bbb 100644 --- a/poincare/src/prediction_interval.cpp +++ b/poincare/src/prediction_interval.cpp @@ -57,24 +57,18 @@ Expression PredictionInterval::shallowReduce(ExpressionNode::ReductionContext re Expression c0 = childAtIndex(0); Expression c1 = childAtIndex(1); if (c0.type() == ExpressionNode::Type::Matrix || c1.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (c0.type() == ExpressionNode::Type::Rational) { Rational r0 = static_cast(c0); if (r0.sign() == ExpressionNode::Sign::Negative || Integer::NaturalOrder(r0.unsignedIntegerNumerator(), r0.integerDenominator()) > 0) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c1.type() == ExpressionNode::Type::Rational) { Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne() || r1.sign() == ExpressionNode::Sign::Negative) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } } if (c0.type() != ExpressionNode::Type::Rational || c1.type() != ExpressionNode::Type::Rational) { @@ -83,9 +77,7 @@ Expression PredictionInterval::shallowReduce(ExpressionNode::ReductionContext re Rational r0 = static_cast(c0); Rational r1 = static_cast(c1); if (!r1.integerDenominator().isOne() || r1.sign() == ExpressionNode::Sign::Negative || r0.sign() == ExpressionNode::Sign::Negative || Integer::NaturalOrder(r0.unsignedIntegerNumerator(), r0.integerDenominator()) > 0) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } /* [r0-1.96*sqrt(r0*(1-r0)/r1), r0+1.96*sqrt(r0*(1-r0)/r1)]*/ // Compute numerator = r0*(1-r0) diff --git a/poincare/src/round.cpp b/poincare/src/round.cpp index 6895d0fec..ea6f8ae1b 100644 --- a/poincare/src/round.cpp +++ b/poincare/src/round.cpp @@ -46,9 +46,7 @@ Expression Round::shallowReduce(ExpressionNode::ReductionContext reductionContex } } if (childAtIndex(1).type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { return mapOnMatrixFirstChild(reductionContext); @@ -59,9 +57,7 @@ Expression Round::shallowReduce(ExpressionNode::ReductionContext reductionContex Rational r1 = childAtIndex(0).convert(); Rational r2 = childAtIndex(1).convert(); if (!r2.integerDenominator().isOne()) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } const Rational ten = Rational::Builder(10); if (Power::RationalExponentShouldNotBeReduced(ten, r2)) { diff --git a/poincare/src/sequence.cpp b/poincare/src/sequence.cpp index 693878760..c6dd14e2f 100644 --- a/poincare/src/sequence.cpp +++ b/poincare/src/sequence.cpp @@ -56,9 +56,7 @@ Expression Sequence::shallowReduce() { } assert(childAtIndex(1).type() != ExpressionNode::Type::Matrix); if (childAtIndex(2).type() == ExpressionNode::Type::Matrix || childAtIndex(3).type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } return *this; } diff --git a/poincare/src/sign_function.cpp b/poincare/src/sign_function.cpp index 5a0c30504..dc8549513 100644 --- a/poincare/src/sign_function.cpp +++ b/poincare/src/sign_function.cpp @@ -63,9 +63,7 @@ Expression SignFunction::shallowReduce(ExpressionNode::ReductionContext reductio } Expression child = childAtIndex(0); if (child.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Rational resultSign = Rational::Builder(1); ExpressionNode::Sign s = child.sign(reductionContext.context()); diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 7aef0720b..f49603a0e 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -52,9 +52,7 @@ Expression SquareRoot::shallowReduce(ExpressionNode::ReductionContext reductionC } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - Expression result = Undefined::Builder(); - replaceWithInPlace(result); - return result; + return replaceWithUndefinedInPlace(); } Power p = Power::Builder(c, Rational::Builder(1, 2)); replaceWithInPlace(p);