diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 5eacbb45c..e6699ca1a 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -214,7 +214,7 @@ public: void simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool symbolicComputation = true); Expression reduce(Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); - Expression mapOnMatrixChild(ExpressionNode::ReductionContext reductionContext); + Expression mapOnMatrixFirstChild(ExpressionNode::ReductionContext reductionContext); static Expression ExpressionWithoutSymbols(Expression expressionWithSymbols, Context * context); Expression radianToDegree(); Expression degreeToRadian(); diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index 8c3768ddf..037306c1a 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -37,7 +37,7 @@ Expression AbsoluteValue::shallowReduce(ExpressionNode::ReductionContext reducti } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.isReal(reductionContext.context())) { float app = c.node()->approximate(float(), reductionContext.context(), reductionContext.complexFormat(), reductionContext.angleUnit()).toScalar(); diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index 6b90aaaad..9980d0bd5 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -57,7 +57,7 @@ Expression ArcCosine::shallowReduce(ExpressionNode::ReductionContext reductionCo } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return Trigonometry::shallowReduceInverseFunction(*this, reductionContext); } diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index f6e893a79..f62eaa7c9 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -57,7 +57,7 @@ Expression ArcSine::shallowReduce(ExpressionNode::ReductionContext reductionCont } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return Trigonometry::shallowReduceInverseFunction(*this, reductionContext); } diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index 153bf6820..1f33c83fe 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -56,7 +56,7 @@ Expression ArcTangent::shallowReduce(ExpressionNode::ReductionContext reductionC } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return Trigonometry::shallowReduceInverseFunction(*this, reductionContext); } diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index fb8758ac5..285d63496 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -45,7 +45,7 @@ Expression Ceiling::shallowReduce(ExpressionNode::ReductionContext reductionCont } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.type() == ExpressionNode::Type::Constant) { Constant s = static_cast(c); diff --git a/poincare/src/complex_argument.cpp b/poincare/src/complex_argument.cpp index 059039054..e1b01e426 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -43,7 +43,7 @@ Expression ComplexArgument::shallowReduce(ExpressionNode::ReductionContext reduc } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } bool real = c.isReal(reductionContext.context()); if (real) { diff --git a/poincare/src/conjugate.cpp b/poincare/src/conjugate.cpp index 29d07219d..b7c40c3ed 100644 --- a/poincare/src/conjugate.cpp +++ b/poincare/src/conjugate.cpp @@ -41,7 +41,7 @@ Expression Conjugate::shallowReduce(ExpressionNode::ReductionContext reductionCo } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.isReal(reductionContext.context())) { replaceWithInPlace(c); diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index 17b08ca1c..a47356564 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -43,7 +43,7 @@ Expression Cosine::shallowReduce(ExpressionNode::ReductionContext reductionConte } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return Trigonometry::shallowReduceDirectFunction(*this, reductionContext); } diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 80c72e736..52d43ad79 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -530,8 +530,10 @@ Expression Expression::ExpressionWithoutSymbols(Expression e, Context * context) return e; } -Expression Expression::mapOnMatrixChild(ExpressionNode::ReductionContext reductionContext) { - assert(numberOfChildren() == 1 && childAtIndex(0).type() == ExpressionNode::Type::Matrix); +Expression Expression::mapOnMatrixFirstChild(ExpressionNode::ReductionContext reductionContext) { + /* For now, the matrix child on which the mapping must be done is always at + * the index 0. */ + assert(childAtIndex(0).type() == ExpressionNode::Type::Matrix); Expression c = childAtIndex(0); Matrix matrix = Matrix::Builder(); for (int i = 0; i < c.numberOfChildren(); i++) { diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index ab769b20f..f5f6c5a64 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -86,7 +86,7 @@ Expression Factorial::shallowReduce(ExpressionNode::ReductionContext reductionCo } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.type() == ExpressionNode::Type::Rational) { Rational r = c.convert(); diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index bc39a305c..4267a3abf 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -44,7 +44,7 @@ Expression Floor::shallowReduce(ExpressionNode::ReductionContext reductionContex } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.type() == ExpressionNode::Type::Constant) { Constant s = static_cast(c); diff --git a/poincare/src/frac_part.cpp b/poincare/src/frac_part.cpp index c49dd0357..4ca63fe07 100644 --- a/poincare/src/frac_part.cpp +++ b/poincare/src/frac_part.cpp @@ -41,7 +41,7 @@ Expression FracPart::shallowReduce(ExpressionNode::ReductionContext reductionCon } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.type() != ExpressionNode::Type::Rational) { return *this; diff --git a/poincare/src/hyperbolic_trigonometric_function.cpp b/poincare/src/hyperbolic_trigonometric_function.cpp index efb562c63..86815c938 100644 --- a/poincare/src/hyperbolic_trigonometric_function.cpp +++ b/poincare/src/hyperbolic_trigonometric_function.cpp @@ -16,7 +16,7 @@ Expression HyperbolicTrigonometricFunction::shallowReduce(ExpressionNode::Reduct } Expression c = childAtIndex(0); if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return *this; } diff --git a/poincare/src/imaginary_part.cpp b/poincare/src/imaginary_part.cpp index 8c2987e4d..5dd188b58 100644 --- a/poincare/src/imaginary_part.cpp +++ b/poincare/src/imaginary_part.cpp @@ -33,7 +33,7 @@ Expression ImaginaryPart::shallowReduce(ExpressionNode::ReductionContext reducti } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.isReal(reductionContext.context())) { Expression result = Rational::Builder(0); diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index 004ec86f9..7d2387362 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -95,7 +95,7 @@ Expression CommonLogarithm::shallowReduce(ExpressionNode::ReductionContext reduc } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } Logarithm log = Logarithm::Builder(childAtIndex(0), Rational::Builder(10)); replaceWithInPlace(log); @@ -209,7 +209,7 @@ Expression Logarithm::shallowReduce(ExpressionNode::ReductionContext reductionCo // log(m) with m Matrix if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return *this; diff --git a/poincare/src/naperian_logarithm.cpp b/poincare/src/naperian_logarithm.cpp index 88522f1b3..cda1b199a 100644 --- a/poincare/src/naperian_logarithm.cpp +++ b/poincare/src/naperian_logarithm.cpp @@ -32,7 +32,7 @@ Expression NaperianLogarithm::shallowReduce(ExpressionNode::ReductionContext red } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } Logarithm l = Logarithm::Builder(c, Constant::Builder(UCodePointScriptSmallE)); replaceWithInPlace(l); diff --git a/poincare/src/real_part.cpp b/poincare/src/real_part.cpp index 35140833b..60ccf90c4 100644 --- a/poincare/src/real_part.cpp +++ b/poincare/src/real_part.cpp @@ -33,7 +33,7 @@ Expression RealPart::shallowReduce(ExpressionNode::ReductionContext reductionCon } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } if (c.isReal(reductionContext.context())) { replaceWithInPlace(c); diff --git a/poincare/src/round.cpp b/poincare/src/round.cpp index 041857a05..6895d0fec 100644 --- a/poincare/src/round.cpp +++ b/poincare/src/round.cpp @@ -51,7 +51,7 @@ Expression Round::shallowReduce(ExpressionNode::ReductionContext reductionContex return result; } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } /* We reduce only round(Rational, Rational). We do not reduce * round(Float, Float) which is equivalent to what is done in approximate. */ diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index f43482635..c7b5f902f 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -43,7 +43,7 @@ Expression Sine::shallowReduce(ExpressionNode::ReductionContext reductionContext } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } return Trigonometry::shallowReduceDirectFunction(*this, reductionContext); } diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index 14f8bccd2..c731e78c8 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -47,7 +47,7 @@ Expression Tangent::shallowReduce(ExpressionNode::ReductionContext reductionCont } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return mapOnMatrixChild(reductionContext); + return mapOnMatrixFirstChild(reductionContext); } Expression newExpression = Trigonometry::shallowReduceDirectFunction(*this, reductionContext);