diff --git a/poincare/Makefile b/poincare/Makefile index 66f38166f..5753a6b07 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -113,7 +113,6 @@ src += $(addprefix poincare/src/,\ sequence.cpp \ serialization_helper.cpp \ sign_function.cpp \ - simplification_helper.cpp \ sine.cpp \ square_root.cpp \ store.cpp \ diff --git a/poincare/include/poincare/absolute_value.h b/poincare/include/poincare/absolute_value.h index 1180898c6..5a85fd21f 100644 --- a/poincare/include/poincare/absolute_value.h +++ b/poincare/include/poincare/absolute_value.h @@ -53,7 +53,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("abs", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); private: Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; diff --git a/poincare/include/poincare/arc_cosine.h b/poincare/include/poincare/arc_cosine.h index 337ddd276..e12c8787c 100644 --- a/poincare/include/poincare/arc_cosine.h +++ b/poincare/include/poincare/arc_cosine.h @@ -45,7 +45,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acos", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; diff --git a/poincare/include/poincare/arc_sine.h b/poincare/include/poincare/arc_sine.h index 459595615..e4efaf1b4 100644 --- a/poincare/include/poincare/arc_sine.h +++ b/poincare/include/poincare/arc_sine.h @@ -44,7 +44,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asin", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/arc_tangent.h b/poincare/include/poincare/arc_tangent.h index 39657231c..ca755d1de 100644 --- a/poincare/include/poincare/arc_tangent.h +++ b/poincare/include/poincare/arc_tangent.h @@ -48,7 +48,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atan", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/ceiling.h b/poincare/include/poincare/ceiling.h index 943542010..60a3501d6 100644 --- a/poincare/include/poincare/ceiling.h +++ b/poincare/include/poincare/ceiling.h @@ -46,7 +46,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ceil", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/complex_argument.h b/poincare/include/poincare/complex_argument.h index c5e9f1594..89ba80dad 100644 --- a/poincare/include/poincare/complex_argument.h +++ b/poincare/include/poincare/complex_argument.h @@ -45,7 +45,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("arg", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/complex_cartesian.h b/poincare/include/poincare/complex_cartesian.h index 951373e2b..377394e87 100644 --- a/poincare/include/poincare/complex_cartesian.h +++ b/poincare/include/poincare/complex_cartesian.h @@ -52,12 +52,12 @@ public: // Common operations (done in-place) Expression squareNorm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); Expression norm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); ComplexCartesian inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); ComplexCartesian squareRoot(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + ComplexCartesian powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); ComplexCartesian multiply(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + ComplexCartesian power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); private: static constexpr int k_maxNumberOfNodesBeforeInterrupting = 50; void factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); diff --git a/poincare/include/poincare/conjugate.h b/poincare/include/poincare/conjugate.h index 7983a5d44..9c0a82c52 100644 --- a/poincare/include/poincare/conjugate.h +++ b/poincare/include/poincare/conjugate.h @@ -45,7 +45,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("conj", 1, &UntypedBuilderOneChild);; - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/cosine.h b/poincare/include/poincare/cosine.h index 7fe3ecc1d..42f7c35a1 100644 --- a/poincare/include/poincare/cosine.h +++ b/poincare/include/poincare/cosine.h @@ -50,7 +50,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cos", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 49b4b1f2b..e5313d4d4 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -213,6 +213,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(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); static Expression ExpressionWithoutSymbols(Expression expressionWithSymbols, Context & context); Expression radianToDegree(); Expression degreeToRadian(); diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index 34c0fbc52..06bfec105 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -54,7 +54,7 @@ public: Factorial(const FactorialNode * n) : Expression(n) {} static Factorial Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); Expression shallowBeautify(); private: constexpr static int k_maxOperandValue = 100; diff --git a/poincare/include/poincare/floor.h b/poincare/include/poincare/floor.h index f2db0393a..2b56b4a52 100644 --- a/poincare/include/poincare/floor.h +++ b/poincare/include/poincare/floor.h @@ -48,7 +48,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("floor", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/frac_part.h b/poincare/include/poincare/frac_part.h index 9c4c8a559..80f7c3008 100644 --- a/poincare/include/poincare/frac_part.h +++ b/poincare/include/poincare/frac_part.h @@ -48,7 +48,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("frac", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/hyperbolic_trigonometric_function.h b/poincare/include/poincare/hyperbolic_trigonometric_function.h index 228d62f93..ae6884dcc 100644 --- a/poincare/include/poincare/hyperbolic_trigonometric_function.h +++ b/poincare/include/poincare/hyperbolic_trigonometric_function.h @@ -18,7 +18,7 @@ private: class HyperbolicTrigonometricFunction : public Expression { public: HyperbolicTrigonometricFunction(const HyperbolicTrigonometricFunctionNode * n) : Expression(n) {} - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/imaginary_part.h b/poincare/include/poincare/imaginary_part.h index e76c55bb4..a9b760aa1 100644 --- a/poincare/include/poincare/imaginary_part.h +++ b/poincare/include/poincare/imaginary_part.h @@ -49,7 +49,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("im", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index b08ddaeaf..1e8bf22f6 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -47,7 +47,7 @@ public: static Logarithm Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder>(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 2, &UntypedBuilderTwoChildren); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); Expression shallowBeautify(); private: @@ -64,7 +64,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/naperian_logarithm.h b/poincare/include/poincare/naperian_logarithm.h index 4ea96319c..f227a81ca 100644 --- a/poincare/include/poincare/naperian_logarithm.h +++ b/poincare/include/poincare/naperian_logarithm.h @@ -48,7 +48,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ln", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/nth_root.h b/poincare/include/poincare/nth_root.h index 78e2861ca..b0554785d 100644 --- a/poincare/include/poincare/nth_root.h +++ b/poincare/include/poincare/nth_root.h @@ -38,7 +38,7 @@ public: static NthRoot Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("root", 2, &UntypedBuilderTwoChildren); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index ab78b950a..eccb7093d 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -71,7 +71,7 @@ public: Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const; - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: @@ -81,12 +81,12 @@ private: // Simplification Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; - Expression simplifyPowerPower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression simplifyPowerMultiplication(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression simplifyPowerPower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); + Expression simplifyPowerMultiplication(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); Expression simplifyRationalRationalPower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); static Expression CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression removeSquareRootsFromDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression removeSquareRootsFromDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool symbolicComputation); bool parentIsALogarithmOfSameBase() const; bool isNthRootOfUnity() const; Expression equivalentExpressionUsingStandardExpression() const; diff --git a/poincare/include/poincare/real_part.h b/poincare/include/poincare/real_part.h index e898a6b68..716fa5196 100644 --- a/poincare/include/poincare/real_part.h +++ b/poincare/include/poincare/real_part.h @@ -49,7 +49,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("re", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/sign_function.h b/poincare/include/poincare/sign_function.h index 6686ef6a0..4ba6c2914 100644 --- a/poincare/include/poincare/sign_function.h +++ b/poincare/include/poincare/sign_function.h @@ -49,7 +49,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sign", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/simplification_helper.h b/poincare/include/poincare/simplification_helper.h deleted file mode 100644 index aa35b20df..000000000 --- a/poincare/include/poincare/simplification_helper.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef POINCARE_SIMPLIFICATION_HELPER_H -#define POINCARE_SIMPLIFICATION_HELPER_H - -#include - -namespace Poincare { - -namespace SimplificationHelper { - Expression Map(const Expression & e, Context & context, Preferences::AngleUnit angleUnit); -}; - -} - -#endif diff --git a/poincare/include/poincare/sine.h b/poincare/include/poincare/sine.h index e147682b3..d78deaf02 100644 --- a/poincare/include/poincare/sine.h +++ b/poincare/include/poincare/sine.h @@ -52,7 +52,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sin", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/square_root.h b/poincare/include/poincare/square_root.h index a1e949a61..dcf030882 100644 --- a/poincare/include/poincare/square_root.h +++ b/poincare/include/poincare/square_root.h @@ -42,7 +42,7 @@ public: SquareRoot(const SquareRootNode * n) : Expression(n) {} static SquareRoot Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("√", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/include/poincare/tangent.h b/poincare/include/poincare/tangent.h index 2c505c7f1..a82e636ec 100644 --- a/poincare/include/poincare/tangent.h +++ b/poincare/include/poincare/tangent.h @@ -50,7 +50,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("tan", 1, &UntypedBuilderOneChild); - Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation); }; } diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index 48073d873..2f57e7b72 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -28,7 +27,7 @@ int AbsoluteValueNode::serialize(char * buffer, int bufferSize, Preferences::Pri } Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return AbsoluteValue(this).shallowReduce(context, complexFormat, angleUnit, target); + return AbsoluteValue(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { @@ -36,14 +35,14 @@ Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Pre return *this; } -Expression AbsoluteValue::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression AbsoluteValue::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } if (c.isReal(context)) { float app = c.node()->approximate(float(), context, complexFormat, angleUnit).toScalar(); diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index 432d39e70..8a281fdcb 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include namespace Poincare { @@ -20,7 +20,7 @@ int ArcCosineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl } Expression ArcCosineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return ArcCosine(this).shallowReduce(context, complexFormat, angleUnit, target); + return ArcCosine(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -49,7 +49,7 @@ Complex ArcCosineNode::computeOnComplex(const std::complex c, Preferences: } -Expression ArcCosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ArcCosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -57,7 +57,7 @@ Expression ArcCosine::shallowReduce(Context & context, Preferences::ComplexForma } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target); } diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index bf4941b07..516dde0c4 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include namespace Poincare { @@ -20,7 +20,7 @@ int ArcSineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloa } Expression ArcSineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return ArcSine(this).shallowReduce(context, complexFormat, angleUnit, target); + return ArcSine(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -49,7 +49,7 @@ Complex ArcSineNode::computeOnComplex(const std::complex c, Preferences::C } -Expression ArcSine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ArcSine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -57,7 +57,7 @@ Expression ArcSine::shallowReduce(Context & context, Preferences::ComplexFormat } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target); } diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index 9c35e07c4..df4b031f5 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include namespace Poincare { @@ -45,11 +45,10 @@ Complex ArcTangentNode::computeOnComplex(const std::complex c, Preferences } Expression ArcTangentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return ArcTangent(this).shallowReduce(context, complexFormat, angleUnit, target); + return ArcTangent(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } - -Expression ArcTangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ArcTangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -57,7 +56,7 @@ Expression ArcTangent::shallowReduce(Context & context, Preferences::ComplexForm } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target); } diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index d99f60d20..8ee0713a6 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include #include #include @@ -32,11 +32,11 @@ Complex CeilingNode::computeOnComplex(const std::complex c, Preferences::C } Expression CeilingNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Ceiling(this).shallowReduce(context, angleUnit); + return Ceiling(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Ceiling::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Ceiling::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -45,7 +45,7 @@ Expression Ceiling::shallowReduce(Context & context, Preferences::AngleUnit angl } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } 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 34b1dd7bd..651101cbe 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include #include extern "C" { @@ -25,7 +25,7 @@ int ComplexArgumentNode::serialize(char * buffer, int bufferSize, Preferences::P } Expression ComplexArgumentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return ComplexArgument(this).shallowReduce(context, complexFormat, angleUnit, target); + return ComplexArgument(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -34,7 +34,7 @@ Complex ComplexArgumentNode::computeOnComplex(const std::complex c, Prefer } -Expression ComplexArgument::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexArgument::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -43,7 +43,7 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::Comple } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } bool real = c.isReal(context); if (real) { @@ -62,7 +62,7 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::Comple } if (real || c.type() == ExpressionNode::Type::ComplexCartesian) { ComplexCartesian complexChild = real ? ComplexCartesian::Builder(c, Rational::Builder(0)) : static_cast(c); - Expression childArg = complexChild.argument(context, complexFormat, angleUnit, target); + Expression childArg = complexChild.argument(context, complexFormat, angleUnit, target, symbolicComputation); replaceWithInPlace(childArg); return childArg.shallowReduce(context, complexFormat, angleUnit, target); } diff --git a/poincare/src/complex_cartesian.cpp b/poincare/src/complex_cartesian.cpp index ecee23825..1c5824c05 100644 --- a/poincare/src/complex_cartesian.cpp +++ b/poincare/src/complex_cartesian.cpp @@ -136,7 +136,7 @@ Expression ComplexCartesian::norm(Context & context, Preferences::ComplexFormat return n; } -Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { Expression a = real(); Expression b = imag(); if (!b.isRationalZero()) { @@ -160,7 +160,7 @@ Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFor return sub; } else { // if b == 0, argument = (1-sign(a))*π/2 - Expression signa = SignFunction::Builder(a).shallowReduce(context, complexFormat, angleUnit, target); + Expression signa = SignFunction::Builder(a).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); Subtraction sub = Subtraction::Builder(Rational::Builder(1), signa); signa.shallowReduce(context, complexFormat, angleUnit, target); Multiplication mul = Multiplication::Builder(Rational::Builder(1,2), Constant::Builder(UCodePointGreekSmallLetterPi), sub); @@ -228,7 +228,7 @@ ComplexCartesian ComplexCartesian::squareRoot(Context & context, Preferences::Co } -ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { Expression a = real(); Expression b = imag(); assert(n > 0); @@ -266,8 +266,8 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer Power bpow = Power::Builder(bclone, Rational::Builder(i)); Multiplication m = Multiplication::Builder(binom, apow, bpow); binom.shallowReduce(context); - apow.shallowReduce(context, complexFormat, angleUnit, target); - bpow.shallowReduce(context, complexFormat, angleUnit, target); + apow.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); + bpow.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); if (i/2%2 == 1) { m.addChildAtIndexInPlace(Rational::Builder(-1), 0, m.numberOfChildren()); } @@ -318,10 +318,10 @@ Expression ComplexCartesian::powerHelper(Expression norm, Expression trigo, Cont return m; } -ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { Expression r = clone().convert().norm(context, complexFormat, angleUnit, target); Expression rclone = r.clone(); - Expression th = argument(context, complexFormat, angleUnit, target); + Expression th = argument(context, complexFormat, angleUnit, target, symbolicComputation); Expression thclone = th.clone(); Expression c = other.real(); Expression d = other.imag(); diff --git a/poincare/src/conjugate.cpp b/poincare/src/conjugate.cpp index 686c4e293..140b20dc2 100644 --- a/poincare/src/conjugate.cpp +++ b/poincare/src/conjugate.cpp @@ -4,7 +4,7 @@ #include #include #include -#include + #include #include #include @@ -24,7 +24,7 @@ int ConjugateNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl } Expression ConjugateNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Conjugate(this).shallowReduce(context, complexFormat, angleUnit, target); + return Conjugate(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -32,7 +32,7 @@ Complex ConjugateNode::computeOnComplex(const std::complex c, Preferences: return Complex::Builder(std::conj(c)); } -Expression Conjugate::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Conjugate::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -41,7 +41,7 @@ Expression Conjugate::shallowReduce(Context & context, Preferences::ComplexForma } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } if (c.isReal(context)) { replaceWithInPlace(c); diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index 880fcc863..7c0e411a6 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include namespace Poincare { @@ -31,10 +31,10 @@ int CosineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat } Expression CosineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Cosine(this).shallowReduce(context, complexFormat, angleUnit, target); + return Cosine(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Cosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Cosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -43,7 +43,7 @@ Expression Cosine::shallowReduce(Context & context, Preferences::ComplexFormat c } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); } diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index ea8a60542..1a36475ce 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -1,7 +1,7 @@ #include #include #include -#include + #include #include #include diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index d711cf32b..4ca7d6dfe 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -477,7 +477,7 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre ecomplex.clone().convert().norm(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, symbolicComputation) : ecomplex.real(); Expression tb = complexFormat == Preferences::ComplexFormat::Polar ? - ecomplex.argument(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, symbolicComputation) : + ecomplex.argument(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, symbolicComputation).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, symbolicComputation) : ecomplex.imag(); ra = ra.deepBeautify(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); tb = tb.deepBeautify(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); @@ -527,6 +527,21 @@ Expression Expression::ExpressionWithoutSymbols(Expression e, Context & context) return e; } +Expression Expression::mapOnMatrixChild(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { + assert(numberOfChildren() == 1 && childAtIndex(0).type() == ExpressionNode::Type::Matrix); + Expression c = childAtIndex(0); + Matrix matrix = Matrix::Builder(); + for (int i = 0; i < c.numberOfChildren(); i++) { + Expression f = clone(); // TODO Avoid cloning because 'this' might be very big TODO LEA: emptyBuilder? + f.replaceChildAtIndexInPlace(0, c.childAtIndex(i)); + matrix.addChildAtIndexInPlace(f, i, i); + f.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); + } + matrix.setDimensions(c.convert().numberOfRows(), c.convert().numberOfColumns()); + replaceWithInPlace(matrix); + return matrix.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); +} + Expression Expression::radianToDegree() { // e*180/Pi return Multiplication::Builder(*this, Rational::Builder(180), Power::Builder(Constant::Builder(UCodePointGreekSmallLetterPi), Rational::Builder(-1))); diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index bfa3afa88..5fa5a51b1 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -5,7 +5,7 @@ #include #include #include -#include + #include #include #include @@ -35,7 +35,7 @@ bool FactorialNode::childNeedsParenthesis(const TreeNode * child) const { // Simplification Expression FactorialNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Factorial(this).shallowReduce(context, angleUnit); + return Factorial(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } Expression FactorialNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { @@ -77,7 +77,7 @@ int FactorialNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl } -Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Factorial::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -86,7 +86,7 @@ Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit an } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } if (c.type() == ExpressionNode::Type::Rational) { Rational r = c.convert(); diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index 058f69cca..03eaded5a 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -3,7 +3,7 @@ #include #include #include -#include + #include #include #include @@ -32,10 +32,10 @@ Complex FloorNode::computeOnComplex(const std::complex c, Preferences::Com } Expression FloorNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Floor(this).shallowReduce(context, angleUnit); + return Floor(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Floor::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Floor::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -44,7 +44,7 @@ Expression Floor::shallowReduce(Context & context, Preferences::AngleUnit angleU } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } 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 dd2e7f9c9..29256d1f4 100644 --- a/poincare/src/frac_part.cpp +++ b/poincare/src/frac_part.cpp @@ -1,7 +1,7 @@ #include #include #include -#include + #include #include @@ -20,7 +20,7 @@ int FracPartNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo } Expression FracPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return FracPart(this).shallowReduce(context, angleUnit); + return FracPart(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -32,7 +32,7 @@ Complex FracPartNode::computeOnComplex(const std::complex c, Preferences:: } -Expression FracPart::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression FracPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -41,7 +41,7 @@ Expression FracPart::shallowReduce(Context & context, Preferences::AngleUnit ang } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } if (c.type() != ExpressionNode::Type::Rational) { return *this; diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index a4c4a9da0..cca092f6c 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -3,7 +3,7 @@ #include #include #include -#include + #include #include #include diff --git a/poincare/src/hyperbolic_trigonometric_function.cpp b/poincare/src/hyperbolic_trigonometric_function.cpp index ea464f6a8..6789fd5e8 100644 --- a/poincare/src/hyperbolic_trigonometric_function.cpp +++ b/poincare/src/hyperbolic_trigonometric_function.cpp @@ -1,13 +1,13 @@ #include -#include + namespace Poincare { Expression HyperbolicTrigonometricFunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return HyperbolicTrigonometricFunction(this).shallowReduce(context, angleUnit); + return HyperbolicTrigonometricFunction(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -16,7 +16,7 @@ Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Pre } Expression c = childAtIndex(0); if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return *this; } diff --git a/poincare/src/imaginary_part.cpp b/poincare/src/imaginary_part.cpp index 6886fb054..d35e0db86 100644 --- a/poincare/src/imaginary_part.cpp +++ b/poincare/src/imaginary_part.cpp @@ -1,7 +1,7 @@ #include #include #include -#include + #include #include #include @@ -21,10 +21,10 @@ int ImaginaryPartNode::serialize(char * buffer, int bufferSize, Preferences::Pri } Expression ImaginaryPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return ImaginaryPart(this).shallowReduce(context, complexFormat, angleUnit, target); + return ImaginaryPart(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression ImaginaryPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ImaginaryPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -33,7 +33,7 @@ Expression ImaginaryPart::shallowReduce(Context & context, Preferences::ComplexF } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } if (c.isReal(context)) { Expression result = Rational::Builder(0); diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index 079d767a5..42ae7689b 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -11,7 +11,7 @@ #include #include #include -#include + #include #include #include @@ -50,12 +50,12 @@ int LogarithmNode::serialize(char * buffer, int bufferSize, Preferences::Prin template<> Expression LogarithmNode<1>::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { - return CommonLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target); + return CommonLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template<> Expression LogarithmNode<2>::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { - return Logarithm(this).shallowReduce(context, complexFormat, angleUnit, target); + return Logarithm(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template<> @@ -86,7 +86,7 @@ template Evaluation LogarithmNode<2>::templatedApproximate(Contex return Complex::Builder(result); } -Expression CommonLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ +Expression CommonLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -95,14 +95,14 @@ Expression CommonLogarithm::shallowReduce(Context & context, Preferences::Comple } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } Logarithm log = Logarithm::Builder(childAtIndex(0), Rational::Builder(10)); replaceWithInPlace(log); - return log.shallowReduce(context, complexFormat, angleUnit, target); + return log.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ +Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -161,7 +161,7 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexForma Multiplication mult = Multiplication::Builder(y); replaceWithInPlace(mult); mult.addChildAtIndexInPlace(*this, 1, 1); // --> y*log(x,b) - shallowReduce(context, complexFormat, angleUnit, target); // reduce log (ie log(e, e) = 1) + shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); // reduce log (ie log(e, e) = 1) return mult.shallowReduce(context, complexFormat, angleUnit, target); } // log(x*y, b)->log(x,b)+log(y, b) if x,y>0 @@ -174,12 +174,12 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexForma static_cast(c).removeChildInPlace(factor, factor.numberOfChildren()); newLog.replaceChildAtIndexInPlace(0, factor); a.addChildAtIndexInPlace(newLog, a.numberOfChildren(), a.numberOfChildren()); - newLog.shallowReduce(context, complexFormat, angleUnit, target); + newLog.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } } if (a.numberOfChildren() > 0) { c.shallowReduce(context, complexFormat, angleUnit, target); - Expression reducedLastLog = shallowReduce(context, complexFormat, angleUnit, target); + Expression reducedLastLog = shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); reducedLastLog.replaceWithInPlace(a); a.addChildAtIndexInPlace(reducedLastLog, a.numberOfChildren(), a.numberOfChildren()); return a.shallowReduce(context, complexFormat, angleUnit, target); @@ -205,7 +205,7 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexForma // log(m) with m Matrix if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return *this; diff --git a/poincare/src/n_ary_expression.cpp b/poincare/src/n_ary_expression.cpp index d2c328b65..c57ae085b 100644 --- a/poincare/src/n_ary_expression.cpp +++ b/poincare/src/n_ary_expression.cpp @@ -99,7 +99,7 @@ bool NAryExpression::SortedIsMatrix(Expression e, Context & context) { assert(IsNAry(e, context)); int childrenCount = e.numberOfChildren(); if (childrenCount > 0) { - return SortedIsMatrix(e.childAtIndex(childrenCount - 1), context); + return Expression::SortedIsMatrix(e.childAtIndex(childrenCount - 1), context); } return false; } diff --git a/poincare/src/naperian_logarithm.cpp b/poincare/src/naperian_logarithm.cpp index 5d359fb28..184070a72 100644 --- a/poincare/src/naperian_logarithm.cpp +++ b/poincare/src/naperian_logarithm.cpp @@ -3,7 +3,7 @@ #include #include #include -#include + namespace Poincare { @@ -19,11 +19,11 @@ int NaperianLogarithmNode::serialize(char * buffer, int bufferSize, Preferences: } Expression NaperianLogarithmNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return NaperianLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target); + return NaperianLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -32,11 +32,11 @@ Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::Comp } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } Logarithm l = Logarithm::Builder(c, Constant::Builder(UCodePointScriptSmallE)); replaceWithInPlace(l); - return l.shallowReduce(context, complexFormat, angleUnit, target); + return l.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } } diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index c11a01b43..c212bb5f4 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -29,7 +29,7 @@ int NthRootNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloa } Expression NthRootNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return NthRoot(this).shallowReduce(context, complexFormat, angleUnit, target); + return NthRoot(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -64,7 +64,7 @@ Evaluation NthRootNode::templatedApproximate(Context& context, Preferences::C } -Expression NthRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression NthRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -80,7 +80,7 @@ Expression NthRoot::shallowReduce(Context & context, Preferences::ComplexFormat Power p = Power::Builder(childAtIndex(0), invIndex); invIndex.shallowReduce(context, complexFormat, angleUnit, target); replaceWithInPlace(p); - return p.shallowReduce(context, complexFormat, angleUnit, target); + return p.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 6e5361593..bd26b5a45 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -7,7 +7,7 @@ #include #include #include -#include + extern "C" { #include #include diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 298b6f677..b1c474141 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -165,7 +165,7 @@ int PowerNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatM // Simplify Expression PowerNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Power(this).shallowReduce(context, complexFormat, angleUnit, target); + return Power(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } Expression PowerNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { @@ -275,7 +275,7 @@ int Power::getPolynomialCoefficients(Context & context, const char * symbolName, return -1; } -Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); @@ -424,11 +424,11 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co } else if (r.integerDenominator().isOne() && r.unsignedIntegerNumerator().isLowerThan(ten)) { if (r.sign() == ExpressionNode::Sign::Positive) { // (x+iy)^n, n integer positive n < 10 - result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, complexFormat, angleUnit, target); + result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, complexFormat, angleUnit, target, symbolicComputation); } else { // (x+iy)^(-n), n integer positive n < 10 assert(r.sign() == ExpressionNode::Sign::Negative); - result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, complexFormat, angleUnit, target).inverse(context, complexFormat, angleUnit, target); + result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, complexFormat, angleUnit, target, symbolicComputation).inverse(context, complexFormat, angleUnit, target); } } if (!result.isUninitialized()) { @@ -443,7 +443,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co (!letPowerAtRoot && base.type() == ExpressionNode::Type::ComplexCartesian && index.type() == ExpressionNode::Type::ComplexCartesian)) { complexBase = base.type() == ExpressionNode::Type::ComplexCartesian ? static_cast(base) : ComplexCartesian::Builder(base, Rational::Builder(0)); complexIndex = index.type() == ExpressionNode::Type::ComplexCartesian ? static_cast(index) : ComplexCartesian::Builder(index, Rational::Builder(0)); - result = complexBase.power(complexIndex, context, complexFormat, angleUnit, target); + result = complexBase.power(complexIndex, context, complexFormat, angleUnit, target, symbolicComputation); replaceWithInPlace(result); return result.shallowReduce(); } @@ -451,7 +451,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co /* Step 3: We look for square root and sum of square roots (two terms maximum * so far) at the denominator and move them to the numerator. */ if (target == ExpressionNode::ReductionTarget::User) { - Expression r = removeSquareRootsFromDenominator(context, complexFormat, angleUnit); + Expression r = removeSquareRootsFromDenominator(context, complexFormat, angleUnit, symbolicComputation); if (!r.isUninitialized()) { return r; } @@ -482,7 +482,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co // (-inf)^x --> (-1)^x*inf Power p = Power::Builder(Rational::Builder(-1), childAtIndex(1)); result = Multiplication::Builder(p, result); - p.shallowReduce(context, complexFormat, angleUnit, target); + p.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } } if (!result.isUninitialized()) { @@ -525,7 +525,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co m1.addChildAtIndexInPlace(i, 0, 0); i.shallowReduce(context, complexFormat, angleUnit, target); m1.addChildAtIndexInPlace(*this, 1, 1); - shallowReduce(context, complexFormat, angleUnit, target); + shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); return m1.shallowReduce(context, complexFormat, angleUnit, target); } } @@ -606,7 +606,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co return approximation; } } - return simplifyPowerPower(context, complexFormat, angleUnit, target); + return simplifyPowerPower(context, complexFormat, angleUnit, target, symbolicComputation); } } // Step 11: (a*b*c*...)^r ? @@ -614,7 +614,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co Multiplication m = childAtIndex(0).convert(); // Case 1: (a*b*c*...)^n = a^n*b^n*c^n*... if n integer if (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().integerDenominator().isOne()) { - return simplifyPowerMultiplication(context, complexFormat, angleUnit, target); + return simplifyPowerMultiplication(context, complexFormat, angleUnit, target, symbolicComputation); } // Case 2: (a*b*...)^r -> |a|^r*(sign(a)*b*...)^r if a not -1 for (int i = 0; i < m.numberOfChildren(); i++) { @@ -644,8 +644,8 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co Multiplication root = Multiplication::Builder(p); replaceWithInPlace(root); root.addChildAtIndexInPlace(thisRef, 1, 1); - p.shallowReduce(context, complexFormat, angleUnit, target); - thisRef.shallowReduce(context, complexFormat, angleUnit, target); + p.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); + thisRef.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); return root.shallowReduce(context, complexFormat, angleUnit, target); } } @@ -747,7 +747,7 @@ Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat co } if (nr.sign() == ExpressionNode::Sign::Negative) { nr.replaceWithInPlace(Rational::Builder(-1)); - return shallowReduce(context, complexFormat, angleUnit, target); + return shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } else { replaceWithInPlace(result); return result; @@ -858,24 +858,24 @@ Expression Power::denominator(Context & context, Preferences::ComplexFormat comp return Expression(); } -Expression Power::simplifyPowerPower(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::simplifyPowerPower(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { // this is p^e = (a^b)^e, we want a^(b*e) Expression p = childAtIndex(0); Multiplication m = Multiplication::Builder(p.childAtIndex(1), childAtIndex(1)); replaceChildAtIndexInPlace(0, p.childAtIndex(0)); replaceChildAtIndexInPlace(1, m); m.shallowReduce(context, complexFormat, angleUnit, target); - return shallowReduce(context, complexFormat, angleUnit, target); + return shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Power::simplifyPowerMultiplication(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::simplifyPowerMultiplication(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { // this is m^r= (a*b*c*...)^r, we want a^r * b^r *c^r * ... Expression m = childAtIndex(0); Expression r = childAtIndex(1); for (int index = 0; index < m.numberOfChildren(); index++) { Power p = Power::Builder(m.childAtIndex(index).clone(), r.clone()); // We copy r and factor to avoid inheritance issues m.replaceChildAtIndexInPlace(index, p); - p.shallowReduce(context, complexFormat, angleUnit, target); + p.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } replaceWithInPlace(m); return m.shallowReduce(context, complexFormat, angleUnit, target); @@ -974,7 +974,7 @@ Expression Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bo return m.shallowReduce(context, complexFormat, angleUnit, target); } -Expression Power::removeSquareRootsFromDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { +Expression Power::removeSquareRootsFromDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool symbolicComputation) { Expression result; if (childAtIndex(0).type() == ExpressionNode::Type::Rational && childAtIndex(1).type() == ExpressionNode::Type::Rational @@ -1001,7 +1001,7 @@ Expression Power::removeSquareRootsFromDenominator(Context & context, Preference } else { result = Multiplication::Builder(Rational::Builder(one, p), sqrt); // We use here the assertion that p != 0 } - sqrt.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); + sqrt.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, symbolicComputation); } } else if (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().isMinusOne() diff --git a/poincare/src/real_part.cpp b/poincare/src/real_part.cpp index d105b607f..3ce0754d0 100644 --- a/poincare/src/real_part.cpp +++ b/poincare/src/real_part.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include #include @@ -21,11 +21,10 @@ int RealPartNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo } Expression RealPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return RealPart(this).shallowReduce(context, complexFormat, angleUnit, target); + return RealPart(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } - -Expression RealPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression RealPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -34,7 +33,7 @@ Expression RealPart::shallowReduce(Context & context, Preferences::ComplexFormat } Expression c = childAtIndex(0); if (c.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } if (c.isReal(context)) { replaceWithInPlace(c); diff --git a/poincare/src/sign_function.cpp b/poincare/src/sign_function.cpp index 1b448d438..4d468c159 100644 --- a/poincare/src/sign_function.cpp +++ b/poincare/src/sign_function.cpp @@ -3,7 +3,7 @@ #include #include #include -#include + #include #include #include @@ -35,7 +35,7 @@ int SignFunctionNode::serialize(char * buffer, int bufferSize, Preferences::Prin } Expression SignFunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return SignFunction(this).shallowReduce(context, complexFormat, angleUnit, target); + return SignFunction(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } template @@ -53,7 +53,7 @@ Complex SignFunctionNode::computeOnComplex(const std::complex c, Preferenc } -Expression SignFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression SignFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -62,7 +62,7 @@ Expression SignFunction::shallowReduce(Context & context, Preferences::ComplexFo } Expression child = childAtIndex(0); if (child.type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } Rational resultSign = Rational::Builder(1); ExpressionNode::Sign s = child.sign(&context); diff --git a/poincare/src/simplification_helper.cpp b/poincare/src/simplification_helper.cpp deleted file mode 100644 index 1d062b6b0..000000000 --- a/poincare/src/simplification_helper.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -namespace Poincare { - -//TODO: , Preferences::ComplexFormat complexFormat? -Expression SimplificationHelper::Map(const Expression & e, Context & context, Preferences::AngleUnit angleUnit) { - //TODO LEA -#if 0 - // TODO Use clones - assert(e->numberOfChildren() == 1 && e->childAtIndex(0)->type() == ExpressionNode::Type::Matrix); - Expression c = e.childAtIndex(0); - Matrix matrix = Matrix::Builder(); - for (int i = 0; i < c->numberOfChildren(); i++) { - Expression f = e.replaceChildAtIndexInPlace(0, e.childAtIndex(0).childAtIndex(i)); - matrix.addChildAtIndexInPlace(f, i, i); - f.shallowReduce(context, complexFormat, angleUnit); - } - replaceWithInPlace(matrix); - return matrix.shallowReduce(context, complexFormat, angleUnit); -#endif - return Undefined::Builder(); -} - -} diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index 7f94392d7..8732933de 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include namespace Poincare { @@ -31,11 +31,11 @@ int SineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMo } Expression SineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Sine(this).shallowReduce(context, complexFormat, angleUnit, target); + return Sine(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Sine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Sine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -43,7 +43,7 @@ Expression Sine::shallowReduce(Context & context, Preferences::ComplexFormat com } } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } return Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); } diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index ab21de5ee..471f14dce 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -4,7 +4,7 @@ #include #include #include -#include + #include #include #include @@ -39,11 +39,10 @@ Complex SquareRootNode::computeOnComplex(const std::complex c, Preferences } Expression SquareRootNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return SquareRoot(this).shallowReduce(context, complexFormat, angleUnit, target); + return SquareRoot(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } - -Expression SquareRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression SquareRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -57,7 +56,7 @@ Expression SquareRoot::shallowReduce(Context & context, Preferences::ComplexForm #endif Power p = Power::Builder(childAtIndex(0), Rational::Builder(1, 2)); replaceWithInPlace(p); - return p.shallowReduce(context, complexFormat, angleUnit, target); + return p.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } } diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index 3923aef14..0ab38d391 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -3,7 +3,7 @@ #include #include #include -#include + #include #include #include @@ -34,11 +34,11 @@ Complex TangentNode::computeOnComplex(const std::complex c, Preferences::C } Expression TangentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target, bool symbolicComputation) { - return Tangent(this).shallowReduce(context, complexFormat, angleUnit, target); + return Tangent(this).shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); } -Expression Tangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Tangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) { { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { @@ -47,7 +47,7 @@ Expression Tangent::shallowReduce(Context & context, Preferences::ComplexFormat } if (childAtIndex(0).type() == ExpressionNode::Type::Matrix) { - return SimplificationHelper::Map(*this, context, angleUnit); + return mapOnMatrixChild(context, complexFormat, angleUnit, target, symbolicComputation); } Expression newExpression = Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); @@ -55,8 +55,8 @@ Expression Tangent::shallowReduce(Context & context, Preferences::ComplexFormat Sine s = Sine::Builder(newExpression.childAtIndex(0).clone()); Cosine c = Cosine::Builder(newExpression.childAtIndex(0)); Division d = Division::Builder(s, c); - s.shallowReduce(context, complexFormat, angleUnit, target); - c.shallowReduce(context, complexFormat, angleUnit, target); + s.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); + c.shallowReduce(context, complexFormat, angleUnit, target, symbolicComputation); newExpression.replaceWithInPlace(d); return d.shallowReduce(context, complexFormat, angleUnit, target); }