diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index a88ec8c4b..c37502501 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -186,7 +186,7 @@ Calculation::EqualSign Calculation::exactAndApproximateDisplayedOutputsAreEqual( if (exactOutputExpression.isUninitialized()) { exactOutputExpression = Undefined(); } - m_equalSign = exactOutputExpression.isEqualToItsApproximationLayout(approximateOutput(context), buffer, bufferSize, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation; + m_equalSign = exactOutputExpression.isEqualToItsApproximationLayout(approximateOutput(context), buffer, bufferSize, preferences->complexFormat(), preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context) ? EqualSign::Equal : EqualSign::Approximation; return m_equalSign; } diff --git a/apps/shared/poincare_helpers.h b/apps/shared/poincare_helpers.h index b666dd159..eb4162dcb 100644 --- a/apps/shared/poincare_helpers.h +++ b/apps/shared/poincare_helpers.h @@ -24,7 +24,9 @@ inline int Serialize(const Poincare::Expression e, char * buffer, int bufferSize template inline Poincare::Expression Approximate(const Poincare::Expression e, Poincare::Context & context) { - return e.approximate(context, Poincare::Preferences::sharedPreferences()->angleUnit(), Poincare::Preferences::sharedPreferences()->complexFormat()); + Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat(); + complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, e, context); + return e.approximate(context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit()); } template @@ -34,23 +36,27 @@ inline T ApproximateToScalar(const Poincare::Expression e, Poincare::Context & c template inline T ApproximateToScalar(const char * text, Poincare::Context & context) { - return Poincare::Expression::approximateToScalar(text, context, Poincare::Preferences::sharedPreferences()->angleUnit()); + Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat(); + complexFormat = Poincare::Expression::UpdatedComplexFormatWithTextInput(complexFormat, text); + return Poincare::Expression::approximateToScalar(text, context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit()); } inline Poincare::Expression ParseAndSimplify(const char * text, Poincare::Context & context) { - return Poincare::Expression::ParseAndSimplify(text, context, Poincare::Preferences::sharedPreferences()->angleUnit()); + return Poincare::Expression::ParseAndSimplify(text, context, Poincare::Preferences::sharedPreferences()->complexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit()); } -inline void Simplify(Poincare::Expression * e, Poincare::Context & context) { - *e = e->simplify(context, Poincare::Preferences::sharedPreferences()->angleUnit()); +inline void Simplify(Poincare::Expression * e, Poincare::Context & context, Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat()) { + complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, *e, context); + *e = e->simplify(context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit()); } inline void ParseAndSimplifyAndApproximate(const char * text, Poincare::Expression * simplifiedExpression, Poincare::Expression * approximateExpression, Poincare::Context & context) { - Poincare::Expression::ParseAndSimplifyAndApproximate(text, simplifiedExpression, approximateExpression, context, Poincare::Preferences::sharedPreferences()->angleUnit(), Poincare::Preferences::sharedPreferences()->complexFormat()); + Poincare::Expression::ParseAndSimplifyAndApproximate(text, simplifiedExpression, approximateExpression, context, Poincare::Preferences::sharedPreferences()->complexFormat(), Poincare::Preferences::sharedPreferences()->angleUnit()); } -inline void SimplifyAndApproximate(Poincare::Expression * e, Poincare::Expression * approximate, Poincare::Context & context) { - e->simplifyAndApproximate(e, approximate, context, Poincare::Preferences::sharedPreferences()->angleUnit(), Poincare::Preferences::sharedPreferences()->complexFormat()); +inline void SimplifyAndApproximate(Poincare::Expression * e, Poincare::Expression * approximate, Poincare::Context & context, Poincare::Preferences::ComplexFormat complexFormat = Poincare::Preferences::sharedPreferences()->complexFormat()) { + complexFormat = Poincare::Expression::UpdatedComplexFormatWithExpressionInput(complexFormat, *e, context); + e->simplifyAndApproximate(e, approximate, context, complexFormat, Poincare::Preferences::sharedPreferences()->angleUnit()); } } diff --git a/apps/solver/equation.cpp b/apps/solver/equation.cpp index 7a19ab32d..8032a9824 100644 --- a/apps/solver/equation.cpp +++ b/apps/solver/equation.cpp @@ -33,7 +33,8 @@ Expression Equation::standardForm(Context * context) const { return m_standardForm; } if (e.type() == ExpressionNode::Type::Equal) { - m_standardForm = static_cast(e).standardEquation(*context, Preferences::sharedPreferences()->angleUnit()); + Preferences * preferences = Preferences::sharedPreferences(); + m_standardForm = static_cast(e).standardEquation(*context, Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), text()), preferences->angleUnit()); } else { assert(e.type() == ExpressionNode::Type::Rational && static_cast(e).isOne()); // The equality was reduced which means the equality was always true. diff --git a/apps/solver/equation_store.cpp b/apps/solver/equation_store.cpp index dc5e8c251..708837b4d 100644 --- a/apps/solver/equation_store.cpp +++ b/apps/solver/equation_store.cpp @@ -126,7 +126,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) { bool isLinear = true; // Invalid the linear system if one equation is non-linear Preferences * preferences = Preferences::sharedPreferences(); for (int i = 0; i < numberOfDefinedModels(); i++) { - isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], *context, preferences->angleUnit()); + isLinear = isLinear && definedModelAtIndex(i)->standardForm(context).getLinearCoefficients((char *)m_variables, Poincare::SymbolAbstract::k_maxNameSize, coefficients[i], &constants[i], *context, updatedComplexFormat(), preferences->angleUnit()); if (!isLinear) { // TODO: should we clean pool allocated memory if the system is not linear #if 0 @@ -157,7 +157,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) { /* 2- Polynomial & Monovariable? */ assert(numberOfVariables == 1 && numberOfDefinedModels() == 1); Expression polynomialCoefficients[Expression::k_maxNumberOfPolynomialCoefficients]; - int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(m_variables[0], polynomialCoefficients, *context, preferences->angleUnit()); + int degree = definedModelAtIndex(0)->standardForm(context).getPolynomialReducedCoefficients(m_variables[0], polynomialCoefficients, *context, updatedComplexFormat(), preferences->angleUnit()); if (degree == 2) { /* Polynomial degree <= 2*/ m_type = Type::PolynomialMonovariable; @@ -201,7 +201,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) { /* Check for equality between exact and approximate layouts */ if (!m_exactSolutionIdentity[solutionIndex]) { char buffer[Shared::ExpressionModel::k_expressionBufferSize]; - m_exactSolutionEquality[solutionIndex] = exactSolutions[i].isEqualToItsApproximationLayout(exactSolutionsApproximations[i], buffer, Shared::ExpressionModel::k_expressionBufferSize, preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context); + m_exactSolutionEquality[solutionIndex] = exactSolutions[i].isEqualToItsApproximationLayout(exactSolutionsApproximations[i], buffer, Shared::ExpressionModel::k_expressionBufferSize, preferences->complexFormat(), preferences->angleUnit(), preferences->displayMode(), preferences->numberOfSignificantDigits(), *context); } solutionIndex++; } @@ -226,7 +226,7 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution Ab.setDimensions(m, n+1); // Compute the rank of (A | b) - int rankAb = Ab.rank(*context, angleUnit, true); + int rankAb = Ab.rank(*context, updatedComplexFormat(), angleUnit, true); // Initialize the number of solutions m_numberOfSolutions = INT_MAX; @@ -251,7 +251,7 @@ EquationStore::Error EquationStore::resolveLinearSystem(Expression exactSolution m_numberOfSolutions = n; for (int i = 0; i < m_numberOfSolutions; i++) { exactSolutions[i] = Ab.matrixChild(i,n); - PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context); + PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context, updatedComplexFormat()); } } } @@ -263,7 +263,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact assert(degree == 2); // Compute delta = b*b-4ac Expression delta = Subtraction(Power(coefficients[1].clone(), Rational(2)), Multiplication(Rational(4), coefficients[0].clone(), coefficients[2].clone())); - PoincareHelpers::Simplify(&delta, *context); + PoincareHelpers::Simplify(&delta, *context, updatedComplexFormat()); if (delta.isUninitialized()) { delta = Poincare::Undefined(); } @@ -280,7 +280,7 @@ EquationStore::Error EquationStore::oneDimensialPolynomialSolve(Expression exact } exactSolutions[m_numberOfSolutions] = delta; for (int i = 0; i <= m_numberOfSolutions; i++) { - PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context); + PoincareHelpers::SimplifyAndApproximate(&exactSolutions[i], &exactSolutionsApproximations[i], *context, updatedComplexFormat()); } return Error::NoError; #if 0 @@ -356,6 +356,14 @@ void EquationStore::tidySolution() { } } +Preferences::ComplexFormat EquationStore::updatedComplexFormat() { + Preferences::ComplexFormat complexFormat = Preferences::sharedPreferences()->complexFormat(); + if (complexFormat == Preferences::ComplexFormat::Real && isExplictlyComplex()) { + return Preferences::ComplexFormat::Cartesian; + } + return complexFormat; +} + bool EquationStore::isExplictlyComplex() { for (int i = 0; i < numberOfDefinedModels(); i++) { if (definedModelAtIndex(i)->containsIComplex()) { diff --git a/apps/solver/equation_store.h b/apps/solver/equation_store.h index bbce1439d..be4d91ff2 100644 --- a/apps/solver/equation_store.h +++ b/apps/solver/equation_store.h @@ -83,6 +83,7 @@ private: Error oneDimensialPolynomialSolve(Poincare::Expression solutions[k_maxNumberOfExactSolutions], Poincare::Expression solutionApproximations[k_maxNumberOfExactSolutions], Poincare::Expression polynomialCoefficients[Poincare::Expression::k_maxNumberOfPolynomialCoefficients], int degree, Poincare::Context * context); void tidySolution(); bool isExplictlyComplex(); + Poincare::Preferences::ComplexFormat updatedComplexFormat(); Equation m_equations[k_maxNumberOfEquations]; Type m_type; diff --git a/poincare/include/poincare/absolute_value.h b/poincare/include/poincare/absolute_value.h index 78ae396f7..f58d45944 100644 --- a/poincare/include/poincare/absolute_value.h +++ b/poincare/include/poincare/absolute_value.h @@ -21,7 +21,7 @@ public: // Properties Type type() const override { return Type::AbsoluteValue; } Sign sign(Context * context) const override { return Sign::Positive; } - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Complex bool isReal(Context & context) const override { return true; } @@ -42,7 +42,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; }; class AbsoluteValue final : public Expression { @@ -53,12 +53,12 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("abs", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit AbsoluteValue(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); } - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit); + Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; } diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index ca822b7a5..3b48de687 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -42,8 +42,8 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static MatrixComplex computeOnMatrixAndComplex(const MatrixComplex m, const std::complex c) { @@ -74,8 +74,8 @@ public: } } // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const; private: static const Number NumeralFactor(const Expression & e); @@ -83,8 +83,8 @@ private: static inline const Expression FirstNonNumeralFactor(const Expression & e); static bool TermsHaveIdenticalNonNumeralFactors(const Expression & e1, const Expression & e2); - Expression factorizeOnCommonDenominator(Context & context, Preferences::AngleUnit angleUnit); - void factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression factorizeOnCommonDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + void factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); AdditionNode * node() const { return static_cast(Expression::node()); } }; diff --git a/poincare/include/poincare/arc_cosine.h b/poincare/include/poincare/arc_cosine.h index ac84719cb..0a73494a2 100644 --- a/poincare/include/poincare/arc_cosine.h +++ b/poincare/include/poincare/arc_cosine.h @@ -27,7 +27,7 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; //Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -45,7 +45,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acos", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit ArcCosine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/arc_sine.h b/poincare/include/poincare/arc_sine.h index 1a0928e86..77a2c9ab8 100644 --- a/poincare/include/poincare/arc_sine.h +++ b/poincare/include/poincare/arc_sine.h @@ -26,7 +26,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; //Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -44,7 +44,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asin", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit ArcSine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/arc_tangent.h b/poincare/include/poincare/arc_tangent.h index 2f420652b..71fff6a69 100644 --- a/poincare/include/poincare/arc_tangent.h +++ b/poincare/include/poincare/arc_tangent.h @@ -30,7 +30,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; //Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -48,7 +48,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atan", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit ArcTangent(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/binomial_coefficient.h b/poincare/include/poincare/binomial_coefficient.h index e6d045226..0587257cf 100644 --- a/poincare/include/poincare/binomial_coefficient.h +++ b/poincare/include/poincare/binomial_coefficient.h @@ -29,7 +29,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -44,7 +44,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("binomial", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: BinomialCoefficient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/ceiling.h b/poincare/include/poincare/ceiling.h index 24cc2f873..44dafdbdf 100644 --- a/poincare/include/poincare/ceiling.h +++ b/poincare/include/poincare/ceiling.h @@ -28,7 +28,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -46,7 +46,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ceil", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit Ceiling(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/complex_argument.h b/poincare/include/poincare/complex_argument.h index be92899af..dee7b6aed 100644 --- a/poincare/include/poincare/complex_argument.h +++ b/poincare/include/poincare/complex_argument.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -45,7 +45,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("arg", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit ComplexArgument(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/complex_cartesian.h b/poincare/include/poincare/complex_cartesian.h index d1ab221b1..324dcf303 100644 --- a/poincare/include/poincare/complex_cartesian.h +++ b/poincare/include/poincare/complex_cartesian.h @@ -27,8 +27,8 @@ private: Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; private: template Complex templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const; @@ -46,28 +46,28 @@ public: Expression imag() { return childAtIndex(1); } // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); // Common operations (done in-place) - Expression squareNorm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression norm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression argument(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian inverse(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian squareRoot(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian powerInteger(int n, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian multiply(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - ComplexCartesian power(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + 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); + 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 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); private: static constexpr int k_maxNumberOfNodesBeforeInterrupting = 50; ComplexCartesian(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); replaceChildAtIndexInPlace(1, child1); } - void factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + void factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); ComplexCartesian interruptComputationIfManyNodes(); - static Multiplication squareRootHelper(Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - static Expression powerHelper(Expression norm, Expression trigo, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + static Multiplication squareRootHelper(Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + static Expression powerHelper(Expression norm, Expression trigo, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); }; diff --git a/poincare/include/poincare/confidence_interval.h b/poincare/include/poincare/confidence_interval.h index 78c526f68..9990c74d2 100644 --- a/poincare/include/poincare/confidence_interval.h +++ b/poincare/include/poincare/confidence_interval.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -50,7 +50,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("confidence", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: ConfidenceInterval(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/conjugate.h b/poincare/include/poincare/conjugate.h index 02907c9b2..8807657cf 100644 --- a/poincare/include/poincare/conjugate.h +++ b/poincare/include/poincare/conjugate.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -45,7 +45,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("conj", 1, &UntypedBuilder);; - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit Conjugate(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/constant.h b/poincare/include/poincare/constant.h index babaf7339..14e98e29f 100644 --- a/poincare/include/poincare/constant.h +++ b/poincare/include/poincare/constant.h @@ -38,7 +38,7 @@ public: bool isIComplex() const { return isConstantChar(Ion::Charset::IComplex); } // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; private: char m_name[0]; // MUST be the last member variable @@ -58,7 +58,7 @@ public: bool isIComplex() const { return node()->isIComplex(); } // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: ConstantNode * node() const { return static_cast(Expression::node()); } diff --git a/poincare/include/poincare/cosine.h b/poincare/include/poincare/cosine.h index 713f4ad64..bc9e69322 100644 --- a/poincare/include/poincare/cosine.h +++ b/poincare/include/poincare/cosine.h @@ -33,7 +33,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplication - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ApproximationHelper::Map(this, context, angleUnit,computeOnComplex); @@ -50,7 +50,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cos", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit Cosine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/decimal.h b/poincare/include/poincare/decimal.h index 1bf27f46e..f86bde4a7 100644 --- a/poincare/include/poincare/decimal.h +++ b/poincare/include/poincare/decimal.h @@ -48,7 +48,7 @@ public: // Properties Type type() const override { return Type::Decimal; } Sign sign(Context * context) const override { return m_negative ? Sign::Negative : Sign::Positive; } - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Approximation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -62,8 +62,8 @@ public: int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; // Serialization int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; @@ -104,8 +104,8 @@ private: Decimal(size_t size, const Integer & m, int e); Expression setSign(ExpressionNode::Sign s); // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; } diff --git a/poincare/include/poincare/derivative.h b/poincare/include/poincare/derivative.h index 2c182c9b2..f22b9b66e 100644 --- a/poincare/include/poincare/derivative.h +++ b/poincare/include/poincare/derivative.h @@ -33,7 +33,7 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -61,7 +61,7 @@ public: } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("diff", 3, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: Derivative(Expression child0, Expression child1, Expression child2) : Expression(TreePool::sharedPool()->createTreeNode()) { assert(child1.type() == ExpressionNode::Type::Symbol); diff --git a/poincare/include/poincare/determinant.h b/poincare/include/poincare/determinant.h index e48c0ffc4..62a36a7bd 100644 --- a/poincare/include/poincare/determinant.h +++ b/poincare/include/poincare/determinant.h @@ -24,7 +24,7 @@ private: /* Serialization */ int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; /* Approximation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -39,7 +39,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("det", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit Determinant(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/division.h b/poincare/include/poincare/division.h index 728f514aa..b14b45b4c 100644 --- a/poincare/include/poincare/division.h +++ b/poincare/include/poincare/division.h @@ -46,7 +46,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; private: // Approximation @@ -67,7 +67,7 @@ public: } Division(const DivisionNode * n) : Expression(n) {} - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); }; } diff --git a/poincare/include/poincare/division_quotient.h b/poincare/include/poincare/division_quotient.h index 030710664..3849503d5 100644 --- a/poincare/include/poincare/division_quotient.h +++ b/poincare/include/poincare/division_quotient.h @@ -28,7 +28,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -43,7 +43,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("quo", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: DivisionQuotient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/division_remainder.h b/poincare/include/poincare/division_remainder.h index a50d99653..1710553bf 100644 --- a/poincare/include/poincare/division_remainder.h +++ b/poincare/include/poincare/division_remainder.h @@ -29,7 +29,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -44,7 +44,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("rem", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: DivisionRemainder(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/equal.h b/poincare/include/poincare/equal.h index cb20d3bf4..0056082ba 100644 --- a/poincare/include/poincare/equal.h +++ b/poincare/include/poincare/equal.h @@ -22,7 +22,7 @@ public: int polynomialDegree(Context & context, const char * symbolName) const override { return -1; } private: // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Layout Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; @@ -41,9 +41,9 @@ public: } // For the equation A = B, create the reduced expression A-B - Expression standardEquation(Context & context, Preferences::AngleUnit angleUnit) const; + Expression standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; } diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index a741f9949..4f8bddee7 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -154,19 +154,21 @@ public: * the variables hold in 'variables'. Otherwise, it fills 'coefficients' with * the coefficients of the variables hold in 'variables' (following the same * order) and 'constant' with the constant of the expression. */ - bool getLinearCoefficients(char * variables, int maxVariableLength, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const; + bool getLinearCoefficients(char * variables, int maxVariableLength, Expression coefficients[], Expression constant[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; /* getPolynomialCoefficients fills the table coefficients with the expressions * of the first 3 polynomial coefficients and returns the polynomial degree. * It is supposed to be called on a reduced expression. * coefficients has up to 3 entries. */ static constexpr int k_maxPolynomialDegree = 2; static constexpr int k_maxNumberOfPolynomialCoefficients = k_maxPolynomialDegree+1; - int getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const; + int getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) { return node()->replaceSymbolWithExpression(symbol, expression); } Expression replaceUnknown(const Symbol & symbol); Expression defaultReplaceUnknown(const Symbol & symbol); /* Complex */ + static Preferences::ComplexFormat UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput); + static Preferences::ComplexFormat UpdatedComplexFormatWithExpressionInput(Preferences::ComplexFormat complexFormat, const Expression & e, Context & context); bool isReal(Context & context) const { return node()->isReal(context); } /* Comparison */ @@ -174,27 +176,27 @@ public: * same structures and all their nodes have same types and values (ie, * sqrt(pi^2) is NOT identical to pi). */ bool isIdenticalTo(const Expression e) const; - bool isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context); + bool isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context); /* Layout Helper */ Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = PrintFloat::k_numberOfStoredSignificantDigits) const; /* Simplification */ - static Expression ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit); - static void ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat); - Expression simplify(Context & context, Preferences::AngleUnit angleUnit); - void simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat); - Expression reduce(Context & context, Preferences::AngleUnit angleUnit); + static Expression ParseAndSimplify(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + static void ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression simplify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + void simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression reduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); static Expression ExpressionWithoutSymbols(Expression expressionWithSymbols, Context & context); Expression radianToDegree(); Expression degreeToRadian(); /* Approximation Helper */ template static U epsilon(); - template Expression approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const; + template Expression approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; template U approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const; - template static U approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit); + template static U approximateToScalar(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); template U approximateWithValueForSymbol(const char * symbol, U x, Context & context, Preferences::AngleUnit angleUnit) const; /* Expression roots/extrema solver */ struct Coordinate2D { @@ -276,24 +278,24 @@ protected: * is reduced (only a numeral factor was potentially made positive, and if it * was -1, it was removed from the multiplication). */ - Expression makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const { return node()->denominator(context, angleUnit); } - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { return node()->shallowReduce(context, angleUnit, target); } - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { return node()->shallowBeautify(context, angleUnit); } - Expression deepBeautify(Context & context, Preferences::AngleUnit angleUnit); - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { return node()->denominator(context, complexFormat, angleUnit); } + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { return node()->shallowReduce(context, complexFormat, angleUnit, target); } + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { return node()->shallowBeautify(context, complexFormat, angleUnit); } + Expression deepBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: static constexpr int k_maxSymbolReplacementsCount = 10; static bool sSymbolReplacementsCountLock; /* Simplification */ - Expression deepReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - void deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - return node()->deepReduceChildren(context, angleUnit, target); + Expression deepReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + void deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + return node()->deepReduceChildren(context, complexFormat, angleUnit, target); } - void defaultDeepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit); - Expression defaultShallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { return *this; } + void defaultDeepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression defaultShallowReduce(); + Expression defaultShallowBeautify() { return *this; } /* Approximation */ template Evaluation approximateToEvaluation(Context& context, Preferences::AngleUnit angleUnit) const; diff --git a/poincare/include/poincare/expression_node.h b/poincare/include/poincare/expression_node.h index 488c7869b..c5baa792a 100644 --- a/poincare/include/poincare/expression_node.h +++ b/poincare/include/poincare/expression_node.h @@ -116,7 +116,7 @@ public: virtual bool isNumber() const { return false; } /*!*/ virtual Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression); /*!*/ virtual Expression replaceUnknown(const Symbol & symbol); - /*!*/ virtual Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target); + /*!*/ virtual Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target); virtual int polynomialDegree(Context & context, const char * symbolName) const; /*!*/ virtual int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const; /*!*/ virtual Expression shallowReplaceReplaceableSymbols(Context & context); @@ -160,11 +160,11 @@ public: virtual Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const = 0; /* Simplification */ - /*!*/ virtual void deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target); - /*!*/ virtual Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target); - /*!*/ virtual Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + /*!*/ virtual void deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target); + /*!*/ virtual Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target); + /*!*/ virtual Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); /* Return a clone of the denominator part of the expression */ - /*!*/ virtual Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const; + /*!*/ virtual Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; /* Hierarchy */ ExpressionNode * childAtIndex(int i) const override { return static_cast(TreeNode::childAtIndex(i)); } diff --git a/poincare/include/poincare/factor.h b/poincare/include/poincare/factor.h index 1663727de..421c6744b 100644 --- a/poincare/include/poincare/factor.h +++ b/poincare/include/poincare/factor.h @@ -25,7 +25,7 @@ private: /* Serialization */ int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -41,8 +41,8 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("factor", 1, &UntypedBuilder); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); - Multiplication createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::AngleUnit angleUnit) const; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Multiplication createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; private: explicit Factor(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index 5ff8b4f66..52955b808 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -21,7 +21,7 @@ public: // Properties Type type() const override { return Type::Factorial; } Sign sign(Context * context) const override { return Sign::Positive; } - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Complex bool isReal(Context & context) const override { return true; } @@ -32,8 +32,8 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplication - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -57,8 +57,8 @@ public: replaceChildAtIndexInPlace(0, child); } - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: constexpr static int k_maxOperandValue = 100; }; diff --git a/poincare/include/poincare/float.h b/poincare/include/poincare/float.h index ea42c5d84..0f488f094 100644 --- a/poincare/include/poincare/float.h +++ b/poincare/include/poincare/float.h @@ -40,7 +40,7 @@ public: // Properties Type type() const override { return Type::Float; } Sign sign(Context * context) const override { return m_value < 0 ? Sign::Negative : Sign::Positive; } - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; // Layout diff --git a/poincare/include/poincare/floor.h b/poincare/include/poincare/floor.h index ba7ff823f..47606158b 100644 --- a/poincare/include/poincare/floor.h +++ b/poincare/include/poincare/floor.h @@ -30,7 +30,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -48,7 +48,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("floor", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit Floor(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/frac_part.h b/poincare/include/poincare/frac_part.h index 071a42c3d..7df4b717b 100644 --- a/poincare/include/poincare/frac_part.h +++ b/poincare/include/poincare/frac_part.h @@ -30,7 +30,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -48,7 +48,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("frac", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit FracPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/function.h b/poincare/include/poincare/function.h index 572c0557b..bc4de3f24 100644 --- a/poincare/include/poincare/function.h +++ b/poincare/include/poincare/function.h @@ -38,7 +38,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; Expression shallowReplaceReplaceableSymbols(Context & context) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override; @@ -66,7 +66,7 @@ public: // Simplification Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); Expression shallowReplaceReplaceableSymbols(Context & context); private: //VariableContext unknownXContext(Context & parentContext) const; diff --git a/poincare/include/poincare/great_common_divisor.h b/poincare/include/poincare/great_common_divisor.h index 8b21c67c1..3bdc5b8fb 100644 --- a/poincare/include/poincare/great_common_divisor.h +++ b/poincare/include/poincare/great_common_divisor.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -42,7 +42,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("gcd", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: GreatCommonDivisor(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/hyperbolic_trigonometric_function.h b/poincare/include/poincare/hyperbolic_trigonometric_function.h index 3f9edac25..18eaf7d54 100644 --- a/poincare/include/poincare/hyperbolic_trigonometric_function.h +++ b/poincare/include/poincare/hyperbolic_trigonometric_function.h @@ -12,13 +12,13 @@ public: int numberOfChildren() const override { return 1; } private: // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; }; 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); }; } diff --git a/poincare/include/poincare/imaginary_part.h b/poincare/include/poincare/imaginary_part.h index f0e838cd9..4637cfac5 100644 --- a/poincare/include/poincare/imaginary_part.h +++ b/poincare/include/poincare/imaginary_part.h @@ -29,7 +29,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit) { return Complex(std::imag(c)); @@ -49,7 +49,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("im", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit ImaginaryPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/infinity.h b/poincare/include/poincare/infinity.h index 9d3c8065d..66e9a37c2 100644 --- a/poincare/include/poincare/infinity.h +++ b/poincare/include/poincare/infinity.h @@ -9,7 +9,7 @@ class InfinityNode final : public NumberNode { public: void setNegative(bool negative) { m_negative = negative; } - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // TreeNode size_t size() const override { return sizeof(InfinityNode); } @@ -48,7 +48,7 @@ public: Infinity(bool negative) : Number(TreePool::sharedPool()->createTreeNode()) { node()->setNegative(negative); } - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit); + Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); static const char * Name() { return "inf"; } diff --git a/poincare/include/poincare/integral.h b/poincare/include/poincare/integral.h index cb7840b99..4860f80ad 100644 --- a/poincare/include/poincare/integral.h +++ b/poincare/include/poincare/integral.h @@ -31,7 +31,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -66,7 +66,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("int", 4, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: Integral(Expression child0, Expression child1, Expression child2, Expression child3) : Expression(TreePool::sharedPool()->createTreeNode()) { assert(child1.type() == ExpressionNode::Type::Symbol); diff --git a/poincare/include/poincare/least_common_multiple.h b/poincare/include/poincare/least_common_multiple.h index 78566ab35..f501b5ebc 100644 --- a/poincare/include/poincare/least_common_multiple.h +++ b/poincare/include/poincare/least_common_multiple.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -42,7 +42,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("lcm", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: LeastCommonMultiple(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index c3cf81943..e77e46dfd 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -27,8 +27,8 @@ public: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit) { /* log has a branch cut on ]-inf, 0]: it is then multivalued on this cut. We @@ -48,17 +48,17 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 2, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: Logarithm(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode >()) { replaceChildAtIndexInPlace(0, child0); replaceChildAtIndexInPlace(1, child1); } - Expression simpleShallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression simpleShallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); Integer simplifyLogarithmIntegerBaseInteger(Integer i, Integer & base, Addition & a, bool isDenominator); - Expression splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); bool parentIsAPowerOfSameBase() const; }; @@ -69,7 +69,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit CommonLogarithm(Expression child) : Expression(TreePool::sharedPool()->createTreeNode >()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index 1742543ec..270a6267f 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -79,7 +79,7 @@ public: Expression matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); } /* Operation on matrix */ - int rank(Context & context, Preferences::AngleUnit angleUnit, bool inPlace = false); + int rank(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool inPlace = false); // Inverse the array in-place. Array has to be given in the form array[row_index][column_index] template static int ArrayInverse(T * array, int numberOfRows, int numberOfColumns); #if MATRIX_EXACT_REDUCING @@ -88,7 +88,7 @@ public: Matrix transpose() const; static Matrix createIdentity(int dim); /* createInverse can be called on any matrix reduce or not, approximate or not. */ - Expression inverse(Context & context, Preferences::AngleUnit angleUnit) const; + Expression inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; #endif private: // TODO: find another solution for inverse and determinant (avoid capping the matrix) @@ -98,7 +98,7 @@ private: void setNumberOfRows(int rows) { assert(rows >= 0); node()->setNumberOfRows(rows); } void setNumberOfColumns(int columns) { assert(columns >= 0); node()->setNumberOfColumns(columns); } /* rowCanonize turns a matrix in its reduced row echelon form. */ - Matrix rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Multiplication m = Multiplication()); + Matrix rowCanonize(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Multiplication m = Multiplication()); // Row canonize the array in place template static void ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, T * c = nullptr); }; diff --git a/poincare/include/poincare/matrix_dimension.h b/poincare/include/poincare/matrix_dimension.h index 66fe2d550..ce5b3a796 100644 --- a/poincare/include/poincare/matrix_dimension.h +++ b/poincare/include/poincare/matrix_dimension.h @@ -25,7 +25,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -39,7 +39,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("dim", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit MatrixDimension(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/matrix_inverse.h b/poincare/include/poincare/matrix_inverse.h index 119d63108..d61bbf1e9 100644 --- a/poincare/include/poincare/matrix_inverse.h +++ b/poincare/include/poincare/matrix_inverse.h @@ -24,7 +24,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -38,7 +38,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("inverse", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit MatrixInverse(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/matrix_trace.h b/poincare/include/poincare/matrix_trace.h index c5aec75d2..27bc2234d 100644 --- a/poincare/include/poincare/matrix_trace.h +++ b/poincare/include/poincare/matrix_trace.h @@ -24,7 +24,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -38,7 +38,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("trace", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit MatrixTrace(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/matrix_transpose.h b/poincare/include/poincare/matrix_transpose.h index eba119f8e..97abb0234 100644 --- a/poincare/include/poincare/matrix_transpose.h +++ b/poincare/include/poincare/matrix_transpose.h @@ -24,7 +24,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -38,7 +38,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("transpose", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: explicit MatrixTranspose(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/multiplication.h b/poincare/include/poincare/multiplication.h index 07c621cbf..2f861777f 100644 --- a/poincare/include/poincare/multiplication.h +++ b/poincare/include/poincare/multiplication.h @@ -34,7 +34,7 @@ public: private: // Property - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Layout bool childNeedsParenthesis(const TreeNode * child) const override; @@ -44,9 +44,9 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override; /* Approximation */ template static MatrixComplex computeOnMatrixAndComplex(const MatrixComplex m, const std::complex c) { @@ -80,21 +80,21 @@ public: template static void computeOnArrays(T * m, T * n, T * result, int mNumberOfColumns, int mNumberOfRows, int nNumberOfColumns); // Expression - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const; - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const; + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; private: // Simplification - Expression privateShallowReduce(Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool expand, bool canBeInterrupted); + Expression privateShallowReduce(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool expand, bool canBeInterrupted); void mergeMultiplicationChildrenInPlace(); - void factorizeBase(int i, int j, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - void mergeInChildByFactorizingBase(int i, Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - void factorizeExponent(int i, int j, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression distributeOnOperandAtIndex(int index, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - void addMissingFactors(Expression factor, Context & context, Preferences::AngleUnit angleUnit); - void factorizeSineAndCosine(int i, int j, Context & context, Preferences::AngleUnit angleUnit); + void factorizeBase(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + void mergeInChildByFactorizingBase(int i, Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + void factorizeExponent(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression distributeOnOperandAtIndex(int index, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + void addMissingFactors(Expression factor, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + void factorizeSineAndCosine(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); static bool HaveSameNonNumeralFactors(const Expression & e1, const Expression & e2); static bool TermsHaveIdenticalBase(const Expression & e1, const Expression & e2); static bool TermsHaveIdenticalExponent(const Expression & e1, const Expression & e2); @@ -103,7 +103,7 @@ private: static const Expression CreateExponent(Expression e); /* Warning: mergeNegativePower doesnot always return a multiplication: * *(b^-1,c^-1) -> (bc)^-1 */ - Expression mergeNegativePower(Context & context, Preferences::AngleUnit angleUnit); + Expression mergeNegativePower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); static inline const Expression Base(const Expression e); }; diff --git a/poincare/include/poincare/naperian_logarithm.h b/poincare/include/poincare/naperian_logarithm.h index 26c4ca390..c8e4dca32 100644 --- a/poincare/include/poincare/naperian_logarithm.h +++ b/poincare/include/poincare/naperian_logarithm.h @@ -25,7 +25,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; /* Evaluation */ template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit) { /* ln has a branch cut on ]-inf, 0]: it is then multivalued on this cut. We @@ -48,7 +48,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ln", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit NaperianLogarithm(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/nth_root.h b/poincare/include/poincare/nth_root.h index 191d881db..2b23add02 100644 --- a/poincare/include/poincare/nth_root.h +++ b/poincare/include/poincare/nth_root.h @@ -24,7 +24,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -39,7 +39,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("root", 2, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: NthRoot(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/number.h b/poincare/include/poincare/number.h index 6ef5635cf..557fa5b0b 100644 --- a/poincare/include/poincare/number.h +++ b/poincare/include/poincare/number.h @@ -47,7 +47,7 @@ public: /* Number::sign() or Number::setSign does not need a context or an angle unit * (a number can be Infinity, Undefined, Float, Decimal, Rational). */ ExpressionNode::Sign sign() { return Expression::sign(nullptr); } - Number setSign(ExpressionNode::Sign s) { return Expression::setSign(s, nullptr, Preferences::AngleUnit::Degree, ExpressionNode::ReductionTarget::User).convert(); } + Number setSign(ExpressionNode::Sign s) { return Expression::setSign(s, nullptr, Preferences::ComplexFormat::Real, Preferences::AngleUnit::Degree, ExpressionNode::ReductionTarget::User).convert(); } protected: Number() : Expression() {} NumberNode * node() const { return static_cast(Expression::node()); } diff --git a/poincare/include/poincare/opposite.h b/poincare/include/poincare/opposite.h index aa2fe69d3..91722cff9 100644 --- a/poincare/include/poincare/opposite.h +++ b/poincare/include/poincare/opposite.h @@ -41,7 +41,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode = Preferences::PrintFloatMode::Decimal, int numberOfSignificantDigits = 0) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; }; class Opposite final : public Expression { @@ -52,7 +52,7 @@ public: replaceChildAtIndexInPlace(0, child); } - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); }; } diff --git a/poincare/include/poincare/parenthesis.h b/poincare/include/poincare/parenthesis.h index bd8e7d7ed..1e594500d 100644 --- a/poincare/include/poincare/parenthesis.h +++ b/poincare/include/poincare/parenthesis.h @@ -26,7 +26,7 @@ public: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Approximation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -42,7 +42,7 @@ public: replaceChildAtIndexInPlace(0, exp); } // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; } diff --git a/poincare/include/poincare/permute_coefficient.h b/poincare/include/poincare/permute_coefficient.h index c21e929d3..2c3f1a093 100644 --- a/poincare/include/poincare/permute_coefficient.h +++ b/poincare/include/poincare/permute_coefficient.h @@ -31,7 +31,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -46,7 +46,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("permute", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: PermuteCoefficient(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 05efc61d0..f99c1b530 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -27,7 +27,7 @@ public: // Properties Type type() const override { return Type::Power; } Sign sign(Context * context) const override; - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; int polynomialDegree(Context & context, const char * symbolName) const override; int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const override; @@ -45,11 +45,11 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplify - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; int simplificationOrderGreaterType(const ExpressionNode * e, bool canBeInterrupted) const override; int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override; + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override; // Evaluation template static MatrixComplex computeOnComplexAndMatrix(const std::complex c, const MatrixComplex n); template static MatrixComplex computeOnMatrixAndComplex(const MatrixComplex m, const std::complex d); @@ -68,28 +68,28 @@ class Power final : public Expression { public: Power(Expression base, Expression exponent); Power(const PowerNode * n) : Expression(n) {} - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + 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::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: constexpr static int k_maxExactPowerMatrix = 100; constexpr static int k_maxNumberOfTermsInExpandedMultinome = 25; // Simplification - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const; + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; - Expression simplifyPowerPower(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression simplifyPowerMultiplication(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression simplifyRationalRationalPower(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + 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 simplifyRationalRationalPower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - static Expression CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bool isDenominator, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - Expression removeSquareRootsFromDenominator(Context & context, Preferences::AngleUnit angleUnit); + 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); bool parentIsALogarithmOfSameBase() const; bool isNthRootOfUnity() const; Expression equivalentExpressionUsingStandardExpression() const; - static Expression CreateComplexExponent(const Expression & r, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // Returns e^(i*pi*r) + static Expression CreateComplexExponent(const Expression & r, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // Returns e^(i*pi*r) static bool TermIsARationalSquareRootOrRational(const Expression& e); static const Rational RadicandInExpression(const Expression & e); static const Rational RationalFactorInExpression(const Expression & e); diff --git a/poincare/include/poincare/prediction_interval.h b/poincare/include/poincare/prediction_interval.h index 9b27a7861..0c79083ed 100644 --- a/poincare/include/poincare/prediction_interval.h +++ b/poincare/include/poincare/prediction_interval.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -42,7 +42,7 @@ public: static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("prediction95", 2, &UntypedBuilder); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: PredictionInterval(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/random.h b/poincare/include/poincare/random.h index fad6266ad..524da8c9c 100644 --- a/poincare/include/poincare/random.h +++ b/poincare/include/poincare/random.h @@ -24,7 +24,7 @@ public: // Properties Type type() const override { return Type::Random; } Sign sign(Context * context) const override { return Sign::Positive; } - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; private: // Layout Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; @@ -50,7 +50,7 @@ public: template static T random(); private: Random() : Expression(TreePool::sharedPool()->createTreeNode()) {} - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit); + Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; } diff --git a/poincare/include/poincare/rational.h b/poincare/include/poincare/rational.h index fc5811504..6b98ec1f0 100644 --- a/poincare/include/poincare/rational.h +++ b/poincare/include/poincare/rational.h @@ -57,10 +57,10 @@ public: static int NaturalOrder(const RationalNode * i, const RationalNode * j); private: int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const override; bool m_negative; uint8_t m_numberOfDigitsNumerator; uint8_t m_numberOfDigitsDenominator; @@ -108,15 +108,15 @@ public: static int NaturalOrder(const Rational & i, const Rational & j) { return RationalNode::NaturalOrder(i.node(), j.node()); } // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: Rational(const native_uint_t * i, uint8_t numeratorSize, const native_uint_t * j, uint8_t denominatorSize, bool negative); RationalNode * node() { return static_cast(Number::node()); } /* Simplification */ - Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit); - Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const; + Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); + Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; Expression setSign(ExpressionNode::Sign s); }; diff --git a/poincare/include/poincare/real_part.h b/poincare/include/poincare/real_part.h index 5295ad2f6..28aa30832 100644 --- a/poincare/include/poincare/real_part.h +++ b/poincare/include/poincare/real_part.h @@ -29,7 +29,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit) { return Complex(std::real(c)); @@ -49,7 +49,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("re", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit RealPart(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/round.h b/poincare/include/poincare/round.h index f41d174af..7876622d6 100644 --- a/poincare/include/poincare/round.h +++ b/poincare/include/poincare/round.h @@ -28,7 +28,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -42,7 +42,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0), children.childAtIndex(1)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("round", 2, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); private: Round(Expression child0, Expression child1) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child0); diff --git a/poincare/include/poincare/sign_function.h b/poincare/include/poincare/sign_function.h index 54ee26dc9..464c79829 100644 --- a/poincare/include/poincare/sign_function.h +++ b/poincare/include/poincare/sign_function.h @@ -21,7 +21,7 @@ public: // Properties Type type() const override { return Type::SignFunction; } Sign sign(Context * context) const override; - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Complex bool isReal(Context & context) const override { return true; } @@ -31,7 +31,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -49,7 +49,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sign", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit SignFunction(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/sine.h b/poincare/include/poincare/sine.h index 91ba724fb..a36f2b3e0 100644 --- a/poincare/include/poincare/sine.h +++ b/poincare/include/poincare/sine.h @@ -34,7 +34,7 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplication - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -52,7 +52,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sin", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit Sine(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/square_root.h b/poincare/include/poincare/square_root.h index 3b815898f..7c692a0c2 100644 --- a/poincare/include/poincare/square_root.h +++ b/poincare/include/poincare/square_root.h @@ -27,7 +27,7 @@ private: Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplification - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { @@ -46,7 +46,7 @@ public: static_assert('\x91' == Ion::Charset::Root, "Charset error"); static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("\x91", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit SquareRoot(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/store.h b/poincare/include/poincare/store.h index eeb6f9573..223973bbd 100644 --- a/poincare/include/poincare/store.h +++ b/poincare/include/poincare/store.h @@ -25,8 +25,8 @@ public: private: // Simplification - void deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) override; - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + void deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Layout Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; @@ -55,7 +55,7 @@ public: } // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); }; } diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index 122c4f994..34df24d31 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -39,7 +39,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; private: /* Evaluation */ @@ -62,7 +62,7 @@ public: } // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); }; } diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 56bb8461d..027730740 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -34,7 +34,7 @@ public: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; Expression shallowReplaceReplaceableSymbols(Context & context) override; /* Approximation */ @@ -79,7 +79,7 @@ public: static bool isRegressionSymbol(const char * c); // Expression - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression); Expression replaceUnknown(const Symbol & symbol); int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const; diff --git a/poincare/include/poincare/symbol_abstract.h b/poincare/include/poincare/symbol_abstract.h index 0b0dfa24d..cab0fc9d3 100644 --- a/poincare/include/poincare/symbol_abstract.h +++ b/poincare/include/poincare/symbol_abstract.h @@ -36,7 +36,7 @@ public: // Property Sign sign(Context * context) const override; - Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // TreeNode #if POINCARE_TREE_LOG diff --git a/poincare/include/poincare/tangent.h b/poincare/include/poincare/tangent.h index c2c00d1d4..53535af37 100644 --- a/poincare/include/poincare/tangent.h +++ b/poincare/include/poincare/tangent.h @@ -31,7 +31,7 @@ private: int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; // Simplication - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Evaluation template static Complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Radian); @@ -50,7 +50,7 @@ public: static Expression UntypedBuilder(Expression children) { return Builder(children.childAtIndex(0)); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("tan", 1, &UntypedBuilder); - Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); private: explicit Tangent(Expression child) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, child); diff --git a/poincare/include/poincare/trigonometry.h b/poincare/include/poincare/trigonometry.h index 27787022b..5e46c82a7 100644 --- a/poincare/include/poincare/trigonometry.h +++ b/poincare/include/poincare/trigonometry.h @@ -17,10 +17,10 @@ public: static bool isInverseTrigonometryFunction(const Expression & e); static bool AreInverseFunctions(const Expression & directFunction, const Expression & inverseFunction); static bool ExpressionIsEquivalentToTangent(const Expression & e); - static Expression shallowReduceDirectFunction(Expression & e, Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); - static Expression shallowReduceInverseFunction(Expression & e, Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + static Expression shallowReduceDirectFunction(Expression & e, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); + static Expression shallowReduceInverseFunction(Expression & e, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); constexpr static int k_numberOfEntries = 37; - static Expression table(const Expression e, ExpressionNode::Type type, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // , Function f, bool inverse + static Expression table(const Expression e, ExpressionNode::Type type, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // , Function f, bool inverse template static std::complex ConvertToRadian(const std::complex c, Preferences::AngleUnit angleUnit); template static std::complex ConvertRadianToAngleUnit(const std::complex c, Preferences::AngleUnit angleUnit); template static std::complex RoundToMeaningfulDigits(const std::complex result, const std::complex input); diff --git a/poincare/include/poincare/undefined.h b/poincare/include/poincare/undefined.h index 759fc261c..f31e02096 100644 --- a/poincare/include/poincare/undefined.h +++ b/poincare/include/poincare/undefined.h @@ -22,7 +22,7 @@ public: // Properties Type type() const override { return Type::Undefined; } int polynomialDegree(Context & context, const char * symbolName) const override; - Expression setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) override; + Expression setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) override; // Approximation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index dc11e4f88..8a053454b 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -14,8 +14,8 @@ constexpr Expression::FunctionHelper AbsoluteValue::s_functionHelper; int AbsoluteValueNode::numberOfChildren() const { return AbsoluteValue::s_functionHelper.numberOfChildren(); } -Expression AbsoluteValueNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return AbsoluteValue(this).setSign(s, context, angleUnit); +Expression AbsoluteValueNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return AbsoluteValue(this).setSign(s, context, complexFormat, angleUnit); } Layout AbsoluteValueNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -26,17 +26,17 @@ int AbsoluteValueNode::serialize(char * buffer, int bufferSize, Preferences::Pri return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, AbsoluteValue::s_functionHelper.name()); } -Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return AbsoluteValue(this).shallowReduce(context, angleUnit, target); +Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return AbsoluteValue(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit) { +Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(s == ExpressionNode::Sign::Positive); return *this; } -Expression AbsoluteValue::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - Expression e = Expression::defaultShallowReduce(context, angleUnit); +Expression AbsoluteValue::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -58,17 +58,17 @@ Expression AbsoluteValue::shallowReduce(Context & context, Preferences::AngleUni // abs(a) = -a with a < 0 Multiplication m(Rational(-1), c); replaceWithInPlace(m); - return m.shallowReduce(context, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } } if (c.type() == ExpressionNode::Type::ComplexCartesian) { ComplexCartesian complexChild = static_cast(c); - Expression childNorm = complexChild.norm(context, angleUnit, target); + Expression childNorm = complexChild.norm(context, complexFormat, angleUnit, target); replaceWithInPlace(childNorm); - return childNorm.shallowReduce(context, angleUnit, target); + return childNorm.shallowReduce(context, complexFormat, angleUnit, target); } // abs(-x) = abs(x) - c.makePositiveAnyNegativeNumeralFactor(context, angleUnit, target); + c.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target); return *this; } diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index 1891befad..179e4425b 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -50,12 +50,12 @@ int AdditionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo // Simplication -Expression AdditionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Addition(this).shallowReduce(context, angleUnit, target); +Expression AdditionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Addition(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression AdditionNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Addition(this).shallowBeautify(context, angleUnit); +Expression AdditionNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Addition(this).shallowBeautify(context, complexFormat, angleUnit); } // Addition @@ -88,7 +88,7 @@ int Addition::getPolynomialCoefficients(Context & context, const char * symbolNa return deg; } -Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Addition::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { /* Beautifying AdditionNode essentially consists in adding Subtractions if * needed. * In practice, we want to turn "a+(-1)*b" into "a-b". Or, more precisely, any @@ -101,7 +101,7 @@ Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit a for (int i = 0; i < numberOfChildren(); i++) { // Try to make the child i positive if any negative numeral factor is found - Expression subtractant = childAtIndex(i).makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression subtractant = childAtIndex(i).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); if (subtractant.isUninitialized()) { // if subtractant is not initialized, it means the child i had no negative numeral factor @@ -131,9 +131,9 @@ Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit a return result; } -Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Addition::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -187,7 +187,7 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang resultMatrix->replaceOperand(resultMatrixEntryJ, a, false); a->addOperand(currentMatrix->childAtIndex(j)); a->addOperand(resultMatrixEntryJ); - a->shallowReduce(context, angleUnit); + a->shallowReduce(context, complexFormat, angleUnit); } currentMatrix->detachOperands(); removeOperand(currentMatrix, true); @@ -199,9 +199,9 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang Expression * entryI = resultMatrix->childAtIndex(i); resultMatrix->replaceOperand(entryI, a, false); a->addOperand(entryI); - a->shallowReduce(context, angleUnit); + a->shallowReduce(context, complexFormat, angleUnit); } - return replaceWith(resultMatrix, true)->shallowReduce(context, angleUnit); + return replaceWith(resultMatrix, true)->shallowReduce(context, complexFormat, angleUnit); } #endif #endif @@ -221,7 +221,7 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang continue; } if (TermsHaveIdenticalNonNumeralFactors(e1, e2)) { - factorizeChildrenAtIndexesInPlace(i, i+1, context, angleUnit, target); + factorizeChildrenAtIndexesInPlace(i, i+1, context, complexFormat, angleUnit, target); continue; } i++; @@ -275,9 +275,9 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang replaceWithInPlace(newComplexCartesian); newComplexCartesian.replaceChildAtIndexInPlace(0, real); newComplexCartesian.replaceChildAtIndexInPlace(1, imag); - real.shallowReduce(context, angleUnit, target); - imag.shallowReduce(context, angleUnit, target); - return newComplexCartesian.shallowReduce(context, angleUnit); + real.shallowReduce(context, complexFormat, angleUnit, target); + imag.shallowReduce(context, complexFormat, angleUnit, target); + return newComplexCartesian.shallowReduce(context, complexFormat, angleUnit); } /* Step 7: Let's put everything under a common denominator. @@ -286,7 +286,7 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang Expression p = result.parent(); if (target == ExpressionNode::ReductionTarget::User && result == *this && (p.isUninitialized() || p.type() != ExpressionNode::Type::Addition)) { // squashUnaryHierarchy didn't do anything: we're not an unary hierarchy - result = factorizeOnCommonDenominator(context, angleUnit); + result = factorizeOnCommonDenominator(context, complexFormat, angleUnit); } return result; } @@ -332,16 +332,16 @@ bool Addition::TermsHaveIdenticalNonNumeralFactors(const Expression & e1, const } } -Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences::AngleUnit angleUnit) { +Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { // We want to turn (a/b+c/d+e/b) into (a*d+b*c+e*d)/(b*d) // Step 1: We want to compute the common denominator, b*d Multiplication commonDenominator = Multiplication(); for (int i = 0; i < numberOfChildren(); i++) { - Expression currentDenominator = childAtIndex(i).denominator(context, angleUnit); + Expression currentDenominator = childAtIndex(i).denominator(context, complexFormat, angleUnit); if (!currentDenominator.isUninitialized()) { // Make commonDenominator = LeastCommonMultiple(commonDenominator, denominator); - commonDenominator.addMissingFactors(currentDenominator, context, angleUnit); + commonDenominator.addMissingFactors(currentDenominator, context, complexFormat, angleUnit); } } if (commonDenominator.numberOfChildren() == 0) { @@ -355,7 +355,7 @@ Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences for (int i = 0; i < numberOfChildren(); i++) { Multiplication m = Multiplication(childAtIndex(i), commonDenominator.clone()); numerator.addChildAtIndexInPlace(m, numerator.numberOfChildren(), numerator.numberOfChildren()); - m.privateShallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User, true, false); + m.privateShallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, true, false); } // Step 3: Add the denominator @@ -363,18 +363,18 @@ Expression Addition::factorizeOnCommonDenominator(Context & context, Preferences Multiplication result = Multiplication(numerator, inverseDenominator); // Step 4: Simplify the numerator - numerator.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + numerator.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); // Step 5: Simplify the denominator (in case it's a rational number) - inverseDenominator.deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + inverseDenominator.deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); /* Step 6: We simplify the resulting multiplication forbidding any * distribution of multiplication on additions (to avoid an infinite loop). */ replaceWithInPlace(result); - return result.privateShallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User, false, true); + return result.privateShallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User, false, true); } -void Addition::factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void Addition::factorizeChildrenAtIndexesInPlace(int index1, int index2, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { /* This function factorizes two children which only differ by a rational * factor. For example, if this is AdditionNode(2*pi, 3*pi), then 2*pi and 3*pi * could be merged, and this turned into AdditionNode(5*pi). */ @@ -410,7 +410,7 @@ void Addition::factorizeChildrenAtIndexesInPlace(int index1, int index2, Context } // Step 5: Reduce the multiplication (in case the new rational factor is zero) - m.shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); } template Complex Poincare::AdditionNode::compute(std::complex, std::complex); diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index 8bd1baae2..6e5538a2e 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -19,8 +19,8 @@ int ArcCosineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ArcCosine::s_functionHelper.name()); } -Expression ArcCosineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ArcCosine(this).shallowReduce(context, angleUnit, target); +Expression ArcCosineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ArcCosine(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -48,9 +48,9 @@ Complex ArcCosineNode::computeOnComplex(const std::complex c, Preferences: return Complex(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit)); } -Expression ArcCosine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ArcCosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -60,7 +60,7 @@ Expression ArcCosine::shallowReduce(Context & context, Preferences::AngleUnit an return SimplificationHelper::Map(*this, context, angleUnit); } #endif - return Trigonometry::shallowReduceInverseFunction(*this, context, angleUnit, target); + return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index cd28c1fcf..d117a404a 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -19,8 +19,8 @@ int ArcSineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloa return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ArcSine::s_functionHelper.name()); } -Expression ArcSineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ArcSine(this).shallowReduce(context, angleUnit, target); +Expression ArcSineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ArcSine(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -48,9 +48,9 @@ Complex ArcSineNode::computeOnComplex(const std::complex c, Preferences::A return Complex(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit)); } -Expression ArcSine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ArcSine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -60,7 +60,7 @@ Expression ArcSine::shallowReduce(Context & context, Preferences::AngleUnit angl return SimplificationHelper::Map(*this, context, angleUnit); } #endif - return Trigonometry::shallowReduceInverseFunction(*this, context, angleUnit, target); + return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index e5cc533d7..e73346485 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -44,13 +44,13 @@ Complex ArcTangentNode::computeOnComplex(const std::complex c, Preferences return Complex(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit)); } -Expression ArcTangentNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ArcTangent(this).shallowReduce(context, angleUnit, target); +Expression ArcTangentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ArcTangent(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression ArcTangent::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ArcTangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -60,7 +60,7 @@ Expression ArcTangent::shallowReduce(Context & context, Preferences::AngleUnit a return SimplificationHelper::Map(*this, context, angleUnit); } #endif - return Trigonometry::shallowReduceInverseFunction(*this, context, angleUnit, target); + return Trigonometry::shallowReduceInverseFunction(*this, context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/binomial_coefficient.cpp b/poincare/src/binomial_coefficient.cpp index 9269fd53d..398aa24cd 100644 --- a/poincare/src/binomial_coefficient.cpp +++ b/poincare/src/binomial_coefficient.cpp @@ -14,8 +14,8 @@ constexpr Expression::FunctionHelper BinomialCoefficient::s_functionHelper; int BinomialCoefficientNode::numberOfChildren() const { return BinomialCoefficient::s_functionHelper.numberOfChildren(); } -Expression BinomialCoefficientNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return BinomialCoefficient(this).shallowReduce(context, angleUnit); +Expression BinomialCoefficientNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return BinomialCoefficient(this).shallowReduce(context, complexFormat, angleUnit); } Layout BinomialCoefficientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -53,9 +53,9 @@ T BinomialCoefficientNode::compute(T k, T n) { return std::round(result); } -Expression BinomialCoefficient::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression BinomialCoefficient::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index cc0ab7f1f..1afb83571 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -31,13 +31,13 @@ Complex CeilingNode::computeOnComplex(const std::complex c, Preferences::A return Complex(std::ceil(c.real())); } -Expression CeilingNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Ceiling(this).shallowReduce(context, angleUnit); +Expression CeilingNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Ceiling(this).shallowReduce(context, complexFormat, angleUnit); } -Expression Ceiling::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Ceiling::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/complex_argument.cpp b/poincare/src/complex_argument.cpp index 046206fe8..c0aec6212 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -24,8 +24,8 @@ int ComplexArgumentNode::serialize(char * buffer, int bufferSize, Preferences::P return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ComplexArgument::s_functionHelper.name()); } -Expression ComplexArgumentNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ComplexArgument(this).shallowReduce(context, angleUnit, target); +Expression ComplexArgumentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ComplexArgument(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -33,9 +33,9 @@ Complex ComplexArgumentNode::computeOnComplex(const std::complex c, Prefer return Complex(std::arg(c)); } -Expression ComplexArgument::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexArgument::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -63,9 +63,9 @@ Expression ComplexArgument::shallowReduce(Context & context, Preferences::AngleU } if (real || c.type() == ExpressionNode::Type::ComplexCartesian) { ComplexCartesian complexChild = real ? ComplexCartesian::Builder(c, Rational(0)) : static_cast(c); - Expression childArg = complexChild.argument(context, angleUnit, target); + Expression childArg = complexChild.argument(context, complexFormat, angleUnit, target); replaceWithInPlace(childArg); - return childArg.shallowReduce(context, angleUnit, target); + return childArg.shallowReduce(context, complexFormat, angleUnit, target); } return *this; } diff --git a/poincare/src/complex_cartesian.cpp b/poincare/src/complex_cartesian.cpp index a83b04920..e0a9b2331 100644 --- a/poincare/src/complex_cartesian.cpp +++ b/poincare/src/complex_cartesian.cpp @@ -19,12 +19,12 @@ namespace Poincare { -Expression ComplexCartesianNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ComplexCartesian(this).shallowReduce(context, angleUnit); +Expression ComplexCartesianNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ComplexCartesian(this).shallowReduce(context, complexFormat, angleUnit); } -Expression ComplexCartesianNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return ComplexCartesian(this).shallowBeautify(context, angleUnit); +Expression ComplexCartesianNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return ComplexCartesian(this).shallowBeautify(context, complexFormat, angleUnit); } template @@ -40,7 +40,7 @@ Complex ComplexCartesianNode::templatedApproximate(Context& context, Preferen return Complex(a.real(), b.real()); } -Expression ComplexCartesian::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression ComplexCartesian::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { if (imag().isRationalZero()) { Expression r = real(); replaceWithInPlace(r); @@ -49,11 +49,11 @@ Expression ComplexCartesian::shallowReduce(Context & context, Preferences::Angle return *this; } -Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression a = real(); Expression b = imag(); - Expression oppositeA = a.makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User); - Expression oppositeB = b.makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression oppositeA = a.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); + Expression oppositeB = b.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); a = oppositeA.isUninitialized() ? a : oppositeA; b = oppositeB.isUninitialized() ? b : oppositeB; Expression e = Expression::CreateComplexExpression(a, b, Preferences::ComplexFormat::Cartesian, @@ -66,7 +66,7 @@ Expression ComplexCartesian::shallowBeautify(Context & context, Preferences::Ang return e; } -void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode::Type searchedType, Expression * factor, Expression * argument, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { if (e.type() == searchedType) { *factor = Rational(1); *argument = e.childAtIndex(0); @@ -78,8 +78,8 @@ void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode: *argument = e.childAtIndex(i).childAtIndex(0); *factor = e.clone(); static_cast(factor)->removeChildAtIndexInPlace(i); - *factor = factor->shallowReduce(context, angleUnit, target); - Expression positiveFactor = factor->makePositiveAnyNegativeNumeralFactor(context, angleUnit, target); + *factor = factor->shallowReduce(context, complexFormat, angleUnit, target); + Expression positiveFactor = factor->makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target); *factor = positiveFactor.isUninitialized() ? *factor : positiveFactor; return; } @@ -87,26 +87,26 @@ void ComplexCartesian::factorAndArgumentOfFunction(Expression e, ExpressionNode: } } -Expression ComplexCartesian::squareNorm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexCartesian::squareNorm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression a = real(); Expression b = imag(); Expression aFactor, bFactor, aArgument, bArgument; - factorAndArgumentOfFunction(a, ExpressionNode::Type::Cosine, &aFactor, &aArgument, context, angleUnit, target); - factorAndArgumentOfFunction(b, ExpressionNode::Type::Sine, &bFactor, &bArgument, context, angleUnit, target); + factorAndArgumentOfFunction(a, ExpressionNode::Type::Cosine, &aFactor, &aArgument, context, complexFormat, angleUnit, target); + factorAndArgumentOfFunction(b, ExpressionNode::Type::Sine, &bFactor, &bArgument, context, complexFormat, angleUnit, target); if (!aFactor.isUninitialized() && !aArgument.isUninitialized() && !bFactor.isUninitialized() && !bArgument.isUninitialized() && aFactor.isIdenticalTo(bFactor) && aArgument.isIdenticalTo(bArgument)) { Power result(aFactor, Rational(2)); - aFactor.shallowReduce(context, angleUnit, target); + aFactor.shallowReduce(context, complexFormat, angleUnit, target); return result; } Expression a2 = Power(a, Rational(2)); Expression b2 = Power(b, Rational(2)); Addition add(a2, b2); - a2.shallowReduce(context, angleUnit, target); - b2.shallowReduce(context, angleUnit, target); + a2.shallowReduce(context, complexFormat, angleUnit, target); + b2.shallowReduce(context, complexFormat, angleUnit, target); return add; } -Expression ComplexCartesian::norm(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexCartesian::norm(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { if (imag().isRationalZero()) { Expression a = real(); ExpressionNode::Sign s = a.sign(&context); @@ -115,16 +115,16 @@ Expression ComplexCartesian::norm(Context & context, Preferences::AngleUnit angl return a;; } else if (s == ExpressionNode::Sign::Negative) { // Case 2: the argument is negative real - return a.setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target); + return a.setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target); } } - Expression n2 = squareNorm(context, angleUnit, target); + Expression n2 = squareNorm(context, complexFormat, angleUnit, target); Expression n = SquareRoot::Builder(n2); - n2.shallowReduce(context, angleUnit, target); + n2.shallowReduce(context, complexFormat, angleUnit, target); return n; } -Expression ComplexCartesian::argument(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexCartesian::argument(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression a = real(); Expression b = imag(); if (!b.isRationalZero()) { @@ -132,91 +132,91 @@ Expression ComplexCartesian::argument(Context & context, Preferences::AngleUnit // First, compute arctan(a/b) or (Pi/180)*arctan(a/b) Expression divab = Division(a, b.clone()); Expression arcTangent = ArcTangent::Builder(divab); - divab.shallowReduce(context, angleUnit, target); + divab.shallowReduce(context, complexFormat, angleUnit, target); if (angleUnit == Preferences::AngleUnit::Degree) { Expression temp = arcTangent.degreeToRadian(); - arcTangent.shallowReduce(context, angleUnit, target); + arcTangent.shallowReduce(context, complexFormat, angleUnit, target); arcTangent = temp; } // Then, compute sign(b) * Pi/2 - arctan(a/b) Expression signb = SignFunction::Builder(b); Expression signbPi2 = Multiplication(Rational(1,2), signb, Constant(Ion::Charset::SmallPi)); - signb.shallowReduce(context, angleUnit, target); + signb.shallowReduce(context, complexFormat, angleUnit, target); Expression sub = Subtraction(signbPi2, arcTangent); - signbPi2.shallowReduce(context, angleUnit, target); - arcTangent.shallowReduce(context, angleUnit, target); + signbPi2.shallowReduce(context, complexFormat, angleUnit, target); + arcTangent.shallowReduce(context, complexFormat, angleUnit, target); return sub; } else { // if b == 0, argument = (1-sign(a))*Pi/2 - Expression signa = SignFunction::Builder(a).shallowReduce(context, angleUnit, target); + Expression signa = SignFunction::Builder(a).shallowReduce(context, complexFormat, angleUnit, target); Subtraction sub(Rational(1), signa); - signa.shallowReduce(context, angleUnit, target); + signa.shallowReduce(context, complexFormat, angleUnit, target); Multiplication mul(Rational(1,2), Constant(Ion::Charset::SmallPi), sub); - sub.shallowReduce(context, angleUnit, target); + sub.shallowReduce(context, complexFormat, angleUnit, target); return mul; } } -ComplexCartesian ComplexCartesian::inverse(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +ComplexCartesian ComplexCartesian::inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression a = real(); Expression b = imag(); // 1/(a+ib) = a/(a^2+b^2)+i*(-b/(a^2+b^2)) - Expression denominatorReal = clone().convert().squareNorm(context, angleUnit, target); + Expression denominatorReal = clone().convert().squareNorm(context, complexFormat, angleUnit, target); Expression denominatorImag = denominatorReal.clone(); Expression denominatorRealInv = Power(denominatorReal, Rational(-1)); - denominatorReal.shallowReduce(context, angleUnit, target); + denominatorReal.shallowReduce(context, complexFormat, angleUnit, target); Expression denominatorImagInv = Power(denominatorImag, Rational(-1)); - denominatorImag.shallowReduce(context, angleUnit, target); + denominatorImag.shallowReduce(context, complexFormat, angleUnit, target); Multiplication A(a, denominatorRealInv); - denominatorRealInv.shallowReduce(context, angleUnit, target); + denominatorRealInv.shallowReduce(context, complexFormat, angleUnit, target); Expression numeratorImag = Multiplication(Rational(-1), b); Multiplication B(numeratorImag, denominatorImagInv); - numeratorImag.shallowReduce(context, angleUnit, target); - denominatorImagInv.shallowReduce(context, angleUnit, target); + numeratorImag.shallowReduce(context, complexFormat, angleUnit, target); + denominatorImagInv.shallowReduce(context, complexFormat, angleUnit, target); ComplexCartesian result(A,B); - A.shallowReduce(context, angleUnit, target); - B.shallowReduce(context, angleUnit, target); + A.shallowReduce(context, complexFormat, angleUnit, target); + B.shallowReduce(context, complexFormat, angleUnit, target); return result.interruptComputationIfManyNodes(); } -Multiplication ComplexCartesian::squareRootHelper(Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Multiplication ComplexCartesian::squareRootHelper(Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { //(1/2)*sqrt(2*e) Multiplication doubleE(Rational(2), e); - e.shallowReduce(context, angleUnit, target); + e.shallowReduce(context, complexFormat, angleUnit, target); Expression sqrt = SquareRoot::Builder(doubleE); - doubleE.shallowReduce(context, angleUnit, target); + doubleE.shallowReduce(context, complexFormat, angleUnit, target); Multiplication result(Rational(1,2), sqrt); - sqrt.shallowReduce(context, angleUnit, target); + sqrt.shallowReduce(context, complexFormat, angleUnit, target); return result; } -ComplexCartesian ComplexCartesian::squareRoot(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +ComplexCartesian ComplexCartesian::squareRoot(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression a = real(); Expression b = imag(); // A: (1/2)*sqrt(2*(sqrt(a^2+b^2)+a)) // B: (1/2)*sqrt(2*(sqrt(a^2+b^2)-a))*sign(b) - Expression normA = clone().convert().norm(context, angleUnit, target); + Expression normA = clone().convert().norm(context, complexFormat, angleUnit, target); Expression normB = normA.clone(); // A = (1/2)*sqrt(2*(sqrt(a^2+b^2)+a)) Addition normAdda(normA, a.clone()); - normA.shallowReduce(context, angleUnit, target); - Multiplication A = squareRootHelper(normAdda, context, angleUnit, target); + normA.shallowReduce(context, complexFormat, angleUnit, target); + Multiplication A = squareRootHelper(normAdda, context, complexFormat, angleUnit, target); // B = B: (1/2)*sqrt(2*(sqrt(a^2+b^2)-a)) Subtraction normSuba(normB, a); - normB.shallowReduce(context, angleUnit, target); - Multiplication B = squareRootHelper(normSuba, context, angleUnit, target); + normB.shallowReduce(context, complexFormat, angleUnit, target); + Multiplication B = squareRootHelper(normSuba, context, complexFormat, angleUnit, target); // B = B: (1/2)*sqrt(2*(sqrt(a^2+b^2)-a))*sign(b) Expression signb = SignFunction::Builder(b); B.addChildAtIndexInPlace(signb, B.numberOfChildren(), B.numberOfChildren()); - signb.shallowReduce(context, angleUnit, target); + signb.shallowReduce(context, complexFormat, angleUnit, target); ComplexCartesian result = ComplexCartesian::Builder(A, B); - A.shallowReduce(context, angleUnit, target); - B.shallowReduce(context, angleUnit, target); + A.shallowReduce(context, complexFormat, angleUnit, target); + B.shallowReduce(context, complexFormat, angleUnit, target); return result.interruptComputationIfManyNodes(); } -ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression a = real(); Expression b = imag(); assert(n > 0); @@ -229,7 +229,7 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer Expression bpow = Power(b, Rational(n)); if (n/2%2 == 1) { Expression temp = Multiplication(Rational(-1), bpow); - bpow.shallowReduce(context, angleUnit, target); + bpow.shallowReduce(context, complexFormat, angleUnit, target); bpow = temp; } if (n%2 == 0) { @@ -237,7 +237,7 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer } else { result = ComplexCartesian(Rational(0), bpow); } - bpow.shallowReduce(context, angleUnit, target); + bpow.shallowReduce(context, complexFormat, angleUnit, target); return result; } // (a+ib) = a^n+i*b*a^(n-1)+(-1)*b^2*a^(n-2)+(-i)*b^3*a^(n-3)+b^3*a^(n-4)+... @@ -253,9 +253,9 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer Power apow(aclone, Rational(n-i)); Power bpow(bclone, Rational(i)); Multiplication m(binom, apow, bpow); - binom.shallowReduce(context, angleUnit); - apow.shallowReduce(context, angleUnit, target); - bpow.shallowReduce(context, angleUnit, target); + binom.shallowReduce(context, complexFormat, angleUnit); + apow.shallowReduce(context, complexFormat, angleUnit, target); + bpow.shallowReduce(context, complexFormat, angleUnit, target); if (i/2%2 == 1) { m.addChildAtIndexInPlace(Rational(-1), 0, m.numberOfChildren()); } @@ -264,18 +264,18 @@ ComplexCartesian ComplexCartesian::powerInteger(int n, Context & context, Prefer } else { B.addChildAtIndexInPlace(m, B.numberOfChildren(), B.numberOfChildren()); } - m.shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); result = result.interruptComputationIfManyNodes(); if (result.real().isUndefined()) { return result; } } - A.shallowReduce(context, angleUnit, target); - B.shallowReduce(context, angleUnit, target); + A.shallowReduce(context, complexFormat, angleUnit, target); + B.shallowReduce(context, complexFormat, angleUnit, target); return result; } -ComplexCartesian ComplexCartesian::multiply(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +ComplexCartesian ComplexCartesian::multiply(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression a = real(); Expression b = imag(); Expression c = other.real(); @@ -285,73 +285,73 @@ ComplexCartesian ComplexCartesian::multiply(ComplexCartesian & other, Context & Expression ac = Multiplication(a.clone(), c.clone()); Expression bd = Multiplication(b.clone(), d.clone()); Subtraction A(ac, bd); - ac.shallowReduce(context, angleUnit, target); - bd.shallowReduce(context, angleUnit, target); + ac.shallowReduce(context, complexFormat, angleUnit, target); + bd.shallowReduce(context, complexFormat, angleUnit, target); // Compute ad+bc Expression ad = Multiplication(a, d); Expression bc = Multiplication(b, c); Addition B(ad, bc); - ad.shallowReduce(context, angleUnit, target); - bc.shallowReduce(context, angleUnit, target); + ad.shallowReduce(context, complexFormat, angleUnit, target); + bc.shallowReduce(context, complexFormat, angleUnit, target); ComplexCartesian result = ComplexCartesian::Builder(A, B); - A.shallowReduce(context, angleUnit, target); - B.shallowReduce(context, angleUnit, target); + A.shallowReduce(context, complexFormat, angleUnit, target); + B.shallowReduce(context, complexFormat, angleUnit, target); return result.interruptComputationIfManyNodes(); } -Expression ComplexCartesian::powerHelper(Expression norm, Expression trigo, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ComplexCartesian::powerHelper(Expression norm, Expression trigo, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Multiplication m(norm, trigo); - norm.shallowReduce(context, angleUnit, target); - trigo.shallowReduce(context, angleUnit, target); + norm.shallowReduce(context, complexFormat, angleUnit, target); + trigo.shallowReduce(context, complexFormat, angleUnit, target); return m; } -ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - Expression r = clone().convert().norm(context, angleUnit, target); +ComplexCartesian ComplexCartesian::power(ComplexCartesian & other, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + Expression r = clone().convert().norm(context, complexFormat, angleUnit, target); Expression rclone = r.clone(); - Expression th = argument(context, angleUnit, target); + Expression th = argument(context, complexFormat, angleUnit, target); Expression thclone = th.clone(); Expression c = other.real(); Expression d = other.imag(); // R = r^c*e^(-th*d) Expression rpowc = Power(rclone, c.clone()); - rclone.shallowReduce(context, angleUnit, target); + rclone.shallowReduce(context, complexFormat, angleUnit, target); Expression thmuld = Multiplication(Rational(-1), thclone, d.clone()); - thclone.shallowReduce(context, angleUnit, target); + thclone.shallowReduce(context, complexFormat, angleUnit, target); Expression exp = Power(Constant(Ion::Charset::Exponential), thmuld); - thmuld.shallowReduce(context, angleUnit, target); + thmuld.shallowReduce(context, complexFormat, angleUnit, target); Multiplication norm(rpowc, exp); - rpowc.shallowReduce(context, angleUnit, target); - exp.shallowReduce(context, angleUnit, target); + rpowc.shallowReduce(context, complexFormat, angleUnit, target); + exp.shallowReduce(context, complexFormat, angleUnit, target); // TH = d*ln(r)+c*th Expression lnr = NaperianLogarithm::Builder(r); - r.shallowReduce(context, angleUnit, target); + r.shallowReduce(context, complexFormat, angleUnit, target); Multiplication dlnr(d, lnr); - lnr.shallowReduce(context, angleUnit, target); + lnr.shallowReduce(context, complexFormat, angleUnit, target); Multiplication thc(th, c); - th.shallowReduce(context, angleUnit, target); + th.shallowReduce(context, complexFormat, angleUnit, target); Expression argument = Addition(thc, dlnr); - thc.shallowReduce(context, angleUnit, target); - dlnr.shallowReduce(context, angleUnit, target); + thc.shallowReduce(context, complexFormat, angleUnit, target); + dlnr.shallowReduce(context, complexFormat, angleUnit, target); if (angleUnit == Preferences::AngleUnit::Degree) { Expression temp = argument.radianToDegree(); - argument.shallowReduce(context, angleUnit, target); + argument.shallowReduce(context, complexFormat, angleUnit, target); argument = temp; } // Result = (norm*cos(argument), norm*sin(argument)) Expression normClone = norm.clone(); Expression argClone = argument.clone(); Expression cos = Cosine::Builder(argClone); - argClone.shallowReduce(context, angleUnit, target); - Expression normcosarg = powerHelper(normClone, cos, context, angleUnit, target); + argClone.shallowReduce(context, complexFormat, angleUnit, target); + Expression normcosarg = powerHelper(normClone, cos, context, complexFormat, angleUnit, target); Expression sin = Sine::Builder(argument); - argument.shallowReduce(context, angleUnit, target); - Expression normsinarg = powerHelper(norm, sin, context, angleUnit, target); + argument.shallowReduce(context, complexFormat, angleUnit, target); + Expression normsinarg = powerHelper(norm, sin, context, complexFormat, angleUnit, target); ComplexCartesian result = ComplexCartesian::Builder(normcosarg, normsinarg); - normcosarg.shallowReduce(context, angleUnit, target); - normsinarg.shallowReduce(context, angleUnit, target); + normcosarg.shallowReduce(context, complexFormat, angleUnit, target); + normsinarg.shallowReduce(context, complexFormat, angleUnit, target); return result.interruptComputationIfManyNodes(); } diff --git a/poincare/src/confidence_interval.cpp b/poincare/src/confidence_interval.cpp index 1d99e4644..f110f94a8 100644 --- a/poincare/src/confidence_interval.cpp +++ b/poincare/src/confidence_interval.cpp @@ -25,8 +25,8 @@ int ConfidenceIntervalNode::serialize(char * buffer, int bufferSize, Preferences return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ConfidenceInterval::s_functionHelper.name()); } -Expression ConfidenceIntervalNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ConfidenceInterval(this).shallowReduce(context, angleUnit, target); +Expression ConfidenceIntervalNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ConfidenceInterval(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -52,9 +52,9 @@ int SimplePredictionIntervalNode::serialize(char * buffer, int bufferSize, Prefe return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SimplePredictionInterval::s_functionHelper.name()); } -Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -94,7 +94,7 @@ Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::Ang matrix.addChildAtIndexInPlace(Addition(r0, sqr), 1, 1); matrix.setDimensions(1, 2); replaceWithInPlace(matrix); - matrix.deepReduceChildren(context, angleUnit, target); + matrix.deepReduceChildren(context, complexFormat, angleUnit, target); return matrix; } diff --git a/poincare/src/conjugate.cpp b/poincare/src/conjugate.cpp index 3d2686250..8593b1053 100644 --- a/poincare/src/conjugate.cpp +++ b/poincare/src/conjugate.cpp @@ -23,8 +23,8 @@ int ConjugateNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Conjugate::s_functionHelper.name()); } -Expression ConjugateNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Conjugate(this).shallowReduce(context, angleUnit, target); +Expression ConjugateNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Conjugate(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -32,9 +32,9 @@ Complex ConjugateNode::computeOnComplex(const std::complex c, Preferences: return Complex(std::conj(c)); } -Expression Conjugate::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Conjugate::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -53,7 +53,7 @@ Expression Conjugate::shallowReduce(Context & context, Preferences::AngleUnit an ComplexCartesian complexChild = static_cast(c); Multiplication m(Rational(-1), complexChild.imag()); complexChild.replaceChildAtIndexInPlace(1, m); - m.shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); replaceWithInPlace(complexChild); return complexChild; } diff --git a/poincare/src/constant.cpp b/poincare/src/constant.cpp index c32ca4be0..038ab3400 100644 --- a/poincare/src/constant.cpp +++ b/poincare/src/constant.cpp @@ -45,15 +45,15 @@ Evaluation ConstantNode::templatedApproximate(Context& context, Preferences:: return Complex(M_E); } -Expression ConstantNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Constant(this).shallowReduce(context, angleUnit, target); +Expression ConstantNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Constant(this).shallowReduce(context, complexFormat, angleUnit, target); } Constant::Constant(char name) : SymbolAbstract(TreePool::sharedPool()->createTreeNode(SymbolAbstract::AlignedNodeSize(1, sizeof(ConstantNode)))) { node()->setName(&name, 1); } -Expression Constant::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Constant::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { if (target == ExpressionNode::ReductionTarget::User && isIComplex()) { ComplexCartesian c = ComplexCartesian::Builder(Rational(0), Rational(1)); replaceWithInPlace(c); diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index f5e9fbf04..84c66fc5c 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -30,13 +30,13 @@ int CosineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Cosine::s_functionHelper.name()); } -Expression CosineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Cosine(this).shallowReduce(context, angleUnit, target); +Expression CosineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Cosine(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression Cosine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Cosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -47,7 +47,7 @@ Expression Cosine::shallowReduce(Context & context, Preferences::AngleUnit angle return SimplificationHelper::Map(*this, context, angleUnit); } #endif - return Trigonometry::shallowReduceDirectFunction(*this, context, angleUnit, target); + return Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index 5be3623a8..94adda80e 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -56,7 +56,7 @@ size_t DecimalNode::size() const { return DecimalSize(m_numberOfDigitsInMantissa); } -Expression DecimalNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression DecimalNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { return Decimal(this).setSign(s); } @@ -85,12 +85,12 @@ int DecimalNode::simplificationOrderSameType(const ExpressionNode * e, bool canB return ((int)Number(this).sign())*unsignedComparison; } -Expression DecimalNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Decimal(this).shallowReduce(context, angleUnit); +Expression DecimalNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Decimal(this).shallowReduce(context, complexFormat, angleUnit); } -Expression DecimalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Decimal(this).shallowBeautify(context, angleUnit); +Expression DecimalNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Decimal(this).shallowBeautify(context, complexFormat, angleUnit); } Layout DecimalNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -342,8 +342,8 @@ Expression Decimal::setSign(ExpressionNode::Sign s) { return result; } -Expression Decimal::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { - Expression e = Expression::defaultShallowReduce(context, angleUnit); +Expression Decimal::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -370,7 +370,7 @@ Expression Decimal::shallowReduce(Context & context, Preferences::AngleUnit angl return result; } -Expression Decimal::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Decimal::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { if (sign() == ExpressionNode::Sign::Negative) { Expression abs = setSign(ExpressionNode::Sign::Positive); Opposite o; diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index 33ac1b490..4163b59ae 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -39,8 +39,8 @@ int DerivativeNode::serialize(char * buffer, int bufferSize, Preferences::PrintF return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Derivative::s_functionHelper.name()); } -Expression DerivativeNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Derivative(this).shallowReduce(context, angleUnit); +Expression DerivativeNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Derivative(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -137,9 +137,9 @@ T DerivativeNode::riddersApproximation(Context & context, Preferences::AngleUnit return ans; } -Expression Derivative::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Derivative::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/determinant.cpp b/poincare/src/determinant.cpp index 36bed8767..d73746c53 100644 --- a/poincare/src/determinant.cpp +++ b/poincare/src/determinant.cpp @@ -28,13 +28,13 @@ Evaluation DeterminantNode::templatedApproximate(Context& context, Preference return Complex(input.determinant()); } -Expression DeterminantNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Determinant(this).shallowReduce(context, angleUnit); +Expression DeterminantNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Determinant(this).shallowReduce(context, complexFormat, angleUnit); } -Expression Determinant::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Determinant::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index 34fbd6c79..d5a8f63ce 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -42,8 +42,8 @@ int DivisionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "/"); } -Expression DivisionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Division(this).shallowReduce(context, angleUnit, target); +Expression DivisionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Division(this).shallowReduce(context, complexFormat, angleUnit, target); } template Complex DivisionNode::compute(const std::complex c, const std::complex d) { @@ -72,18 +72,18 @@ template MatrixComplex DivisionNode::computeOnMatrices(const Matr Division::Division() : Expression(TreePool::sharedPool()->createTreeNode()) {} -Expression Division::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Division::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } } Expression p = Power(childAtIndex(1), Rational(-1)); Multiplication m = Multiplication(childAtIndex(0), p); - p.shallowReduce(context, angleUnit, target); // Imagine Division(2,1). p would be 1^(-1) which can be simplified + p.shallowReduce(context, complexFormat, angleUnit, target); // Imagine Division(2,1). p would be 1^(-1) which can be simplified replaceWithInPlace(m); - return m.shallowReduce(context, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/division_quotient.cpp b/poincare/src/division_quotient.cpp index bb2e5f4d2..acd244c53 100644 --- a/poincare/src/division_quotient.cpp +++ b/poincare/src/division_quotient.cpp @@ -12,8 +12,8 @@ constexpr Expression::FunctionHelper DivisionQuotient::s_functionHelper; int DivisionQuotientNode::numberOfChildren() const { return DivisionQuotient::s_functionHelper.numberOfChildren(); } -Expression DivisionQuotientNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return DivisionQuotient(this).shallowReduce(context, angleUnit); +Expression DivisionQuotientNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return DivisionQuotient(this).shallowReduce(context, complexFormat, angleUnit); } Layout DivisionQuotientNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -35,9 +35,9 @@ Evaluation DivisionQuotientNode::templatedApproximate(Context& context, Prefe return Complex(std::floor(f1/f2)); } -Expression DivisionQuotient::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression DivisionQuotient::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/division_remainder.cpp b/poincare/src/division_remainder.cpp index 6551d115d..4ed9a1bc5 100644 --- a/poincare/src/division_remainder.cpp +++ b/poincare/src/division_remainder.cpp @@ -20,8 +20,8 @@ int DivisionRemainderNode::serialize(char * buffer, int bufferSize, Preferences: return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, DivisionRemainder::s_functionHelper.name()); } -Expression DivisionRemainderNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return DivisionRemainder(this).shallowReduce(context, angleUnit); +Expression DivisionRemainderNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return DivisionRemainder(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -36,9 +36,9 @@ Evaluation DivisionRemainderNode::templatedApproximate(Context& context, Pref return Complex(std::round(f1-f2*std::floor(f1/f2))); } -Expression DivisionRemainder::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression DivisionRemainder::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/equal.cpp b/poincare/src/equal.cpp index a9e898d22..1c44a35b2 100644 --- a/poincare/src/equal.cpp +++ b/poincare/src/equal.cpp @@ -20,8 +20,8 @@ extern "C" { } namespace Poincare { -Expression EqualNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Equal(this).shallowReduce(context, angleUnit); +Expression EqualNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Equal(this).shallowReduce(context, complexFormat, angleUnit); } Layout EqualNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -41,14 +41,14 @@ Evaluation EqualNode::templatedApproximate(Context& context, Preferences::Ang return Complex::Undefined(); } -Expression Equal::standardEquation(Context & context, Preferences::AngleUnit angleUnit) const { +Expression Equal::standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { Expression sub = Subtraction(childAtIndex(0).clone(), childAtIndex(1).clone()); - return sub.reduce(context, angleUnit); + return sub.reduce(context, complexFormat, angleUnit); } -Expression Equal::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Equal::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index b6ac0eaac..63606669c 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -147,7 +147,7 @@ bool containsVariables(const Expression e, char * variables, int maxVariableSize return false; } -bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const { +bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Expression coefficients[], Expression constant[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { assert(!recursivelyMatches(IsMatrix, context, true)); // variables is in fact of type char[k_maxNumberOfVariables][maxVariableSize] int index = 0; @@ -162,7 +162,7 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex index = 0; Expression polynomialCoefficients[k_maxNumberOfPolynomialCoefficients]; while (variables[index*maxVariableSize] != 0) { - int degree = equation.getPolynomialReducedCoefficients(&variables[index*maxVariableSize], polynomialCoefficients, context, angleUnit); + int degree = equation.getPolynomialReducedCoefficients(&variables[index*maxVariableSize], polynomialCoefficients, context, complexFormat, angleUnit); switch (degree) { case 0: coefficients[index] = Rational(0); @@ -183,7 +183,7 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex equation = polynomialCoefficients[0]; index++; } - constant[0] = Opposite(equation.clone()).reduce(context, angleUnit); + constant[0] = Opposite(equation.clone()).reduce(context, complexFormat, angleUnit); /* The expression can be linear on all coefficients taken one by one but * non-linear (ex: xy = 2). We delete the results and return false if one of * the coefficients contains a variable. */ @@ -199,13 +199,13 @@ bool Expression::getLinearCoefficients(char * variables, int maxVariableSize, Ex // Private -void Expression::defaultDeepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void Expression::defaultDeepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { for (int i = 0; i < numberOfChildren(); i++) { - childAtIndex(i).deepReduce(context, angleUnit, target); + childAtIndex(i).deepReduce(context, complexFormat, angleUnit, target); } } -Expression Expression::defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Expression::defaultShallowReduce() { for (int i = 0; i < numberOfChildren(); i++) { if (childAtIndex(i).type() == ExpressionNode::Type::Undefined) { Expression result = Undefined(); @@ -246,10 +246,10 @@ Expression Expression::defaultReplaceReplaceableSymbols(Context & context) { return *this; } -Expression Expression::makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Expression::makePositiveAnyNegativeNumeralFactor(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { // The expression is a negative number if (isNumber() && sign(&context) == ExpressionNode::Sign::Negative) { - return setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target); + return setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target); } // The expression is a multiplication whose numeral factor is negative if (type() == ExpressionNode::Type::Multiplication && numberOfChildren() > 0 && childAtIndex(0).isNumber() && childAtIndex(0).sign(&context) == ExpressionNode::Sign::Negative) { @@ -261,7 +261,7 @@ Expression Expression::makePositiveAnyNegativeNumeralFactor(Context & context, P return m.squashUnaryHierarchyInPlace(); } else { // Otherwise, we make it positive - m.childAtIndex(0).setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target); + m.childAtIndex(0).setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target); } return m; } @@ -291,11 +291,11 @@ int Expression::defaultGetPolynomialCoefficients(Context & context, const char * return -1; } -int Expression::getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const { +int Expression::getPolynomialReducedCoefficients(const char * symbolName, Expression coefficients[], Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { // Reset interrupting flag because we use deepReduce int degree = getPolynomialCoefficients(context, symbolName, coefficients); for (int i = 0; i <= degree; i++) { - coefficients[i] = coefficients[i].reduce(context, angleUnit); + coefficients[i] = coefficients[i].reduce(context, complexFormat, angleUnit); } return degree; } @@ -312,6 +312,22 @@ Expression Expression::defaultReplaceUnknown(const Symbol & symbol) { return *this; } +/* Complex */ + +Preferences::ComplexFormat Expression::UpdatedComplexFormatWithTextInput(Preferences::ComplexFormat complexFormat, const char * textInput) { + if (complexFormat == Preferences::ComplexFormat::Real && strchr(textInput, Ion::Charset::IComplex) != nullptr) { + return Preferences::ComplexFormat::Cartesian; + } + return complexFormat; +} + +Preferences::ComplexFormat Expression::UpdatedComplexFormatWithExpressionInput(Preferences::ComplexFormat complexFormat, const Expression & exp, Context & context) { + if (complexFormat == Preferences::ComplexFormat::Real && exp.recursivelyMatches([](const Expression e, Context & context, bool replaceSymbols) { return e.type() == ExpressionNode::Type::Constant && static_cast(e).isIComplex(); }, context, true)) { + return Preferences::ComplexFormat::Cartesian; + } + return complexFormat; +} + /* Comparison */ bool Expression::isIdenticalTo(const Expression e) const { @@ -320,7 +336,7 @@ bool Expression::isIdenticalTo(const Expression e) const { return ExpressionNode::SimplificationOrder(node(), e.node(), true) == 0; } -bool Expression::isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context) { +bool Expression::isEqualToItsApproximationLayout(Expression approximation, char * buffer, int bufferSize, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context) { approximation.serialize(buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits); /* Warning: we cannot use directly the the approximate expression but we have * to re-serialize it because the number of stored significative @@ -328,7 +344,7 @@ bool Expression::isEqualToItsApproximationLayout(Expression approximation, char * identical. (For example, 0.000025 might be displayed "0.00003" and stored * as Decimal(0.000025) and isEqualToItsApproximationLayout should return * false) */ - Expression approximateOutput = Expression::ParseAndSimplify(buffer, context, angleUnit); + Expression approximateOutput = Expression::ParseAndSimplify(buffer, context, complexFormat, angleUnit); bool equal = isIdenticalTo(approximateOutput); return equal; } @@ -343,12 +359,12 @@ int Expression::serialize(char * buffer, int bufferSize, Preferences::PrintFloat /* Simplification */ -Expression Expression::ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit) { +Expression Expression::ParseAndSimplify(const char * text, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression exp = Parse(text); if (exp.isUninitialized()) { return Undefined(); } - exp = exp.simplify(context, angleUnit); + exp = exp.simplify(context, UpdatedComplexFormatWithTextInput(complexFormat, text), angleUnit); /* simplify might have been interrupted, in which case the resulting * expression is uninitialized, so we need to check that. */ if (exp.isUninitialized()) { @@ -357,7 +373,7 @@ Expression Expression::ParseAndSimplify(const char * text, Context & context, Pr return exp; } -void Expression::ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) { +void Expression::ParseAndSimplifyAndApproximate(const char * text, Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(simplifiedExpression); Expression exp = Parse(text); if (exp.isUninitialized()) { @@ -365,22 +381,22 @@ void Expression::ParseAndSimplifyAndApproximate(const char * text, Expression * *approximateExpression = Undefined(); return; } - exp.simplifyAndApproximate(simplifiedExpression, approximateExpression, context, angleUnit, complexFormat); + exp.simplifyAndApproximate(simplifiedExpression, approximateExpression, context, UpdatedComplexFormatWithTextInput(complexFormat, text), angleUnit); /* simplify might have been interrupted, in which case the resulting * expression is uninitialized, so we need to check that. */ if (simplifiedExpression->isUninitialized()) { *simplifiedExpression = Parse(text); if (approximateExpression) { - *approximateExpression = simplifiedExpression->approximate(context, angleUnit, complexFormat); + *approximateExpression = simplifiedExpression->approximate(context, complexFormat, angleUnit); } } } -Expression Expression::simplify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Expression::simplify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { sSimplificationHasBeenInterrupted = false; - Expression e = deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + Expression e = deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); if (!sSimplificationHasBeenInterrupted) { - e = e.deepBeautify(context, angleUnit); + e = e.deepBeautify(context, complexFormat, angleUnit); } return sSimplificationHasBeenInterrupted ? Expression() : e; } @@ -392,14 +408,14 @@ void makePositive(Expression * e, bool * isNegative) { } } -void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) { +void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expression * approximateExpression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(simplifiedExpression); sSimplificationHasBeenInterrupted = false; // Step 1: we reduce the expression - Expression e = clone().deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression e = clone().deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); if (sSimplificationHasBeenInterrupted) { sSimplificationHasBeenInterrupted = false; - e = deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + e = deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); } *simplifiedExpression = Expression(); if (!sSimplificationHasBeenInterrupted) { @@ -418,15 +434,15 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre // Clone the ComplexCartesian to use it to compute the approximation ComplexCartesian ecomplexClone = ecomplex.clone().convert(); // To minimize the error on the approximation, we reduce the number of nodes in the expression by beautifying - ecomplexClone.real().deepBeautify(context, angleUnit); - ecomplexClone.imag().deepBeautify(context, angleUnit); - *approximateExpression = ecomplexClone.approximate(context, angleUnit, complexFormat); + ecomplexClone.real().deepBeautify(context, complexFormat, angleUnit); + ecomplexClone.imag().deepBeautify(context, complexFormat, angleUnit); + *approximateExpression = ecomplexClone.approximate(context, complexFormat, angleUnit); } // Step 3: create the simplied expression with the required complex format - Expression ra = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.clone().convert().norm(context, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.real(); - Expression tb = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.argument(context, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.imag(); - ra = ra.deepBeautify(context, angleUnit); - tb = tb.deepBeautify(context, angleUnit); + Expression ra = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.clone().convert().norm(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.real(); + Expression tb = complexFormat == Preferences::ComplexFormat::Polar ? ecomplex.argument(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User) : ecomplex.imag(); + ra = ra.deepBeautify(context, complexFormat, angleUnit); + tb = tb.deepBeautify(context, complexFormat, angleUnit); bool raIsNegative = false; bool tbIsNegative = false; makePositive(&ra, &raIsNegative); @@ -435,9 +451,9 @@ void Expression::simplifyAndApproximate(Expression * simplifiedExpression, Expre } else { /* Case 2: The reduced expression has a complex component that could not * be bubbled up. */ - *simplifiedExpression = e.deepBeautify(context, angleUnit); + *simplifiedExpression = e.deepBeautify(context, complexFormat, angleUnit); if (approximateExpression) { - *approximateExpression = simplifiedExpression->approximate(context, angleUnit, complexFormat); + *approximateExpression = simplifiedExpression->approximate(context, complexFormat, angleUnit); } } } @@ -484,12 +500,12 @@ Expression Expression::degreeToRadian() { return Multiplication(*this, Rational(1, 180), Constant(Ion::Charset::SmallPi)); } -Expression Expression::reduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Expression::reduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { sSimplificationHasBeenInterrupted = false; - return deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + return deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); } -Expression Expression::deepReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Expression::deepReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { #if MATRIX_EXACT_REDUCING #else if (IsMatrix(*this, context, true)) { @@ -498,30 +514,30 @@ Expression Expression::deepReduce(Context & context, Preferences::AngleUnit angl } #endif - deepReduceChildren(context, angleUnit, target); + deepReduceChildren(context, complexFormat, angleUnit, target); if (sSimplificationHasBeenInterrupted) { return *this; } - return shallowReduce(context, angleUnit, target); + return shallowReduce(context, complexFormat, angleUnit, target); } -Expression Expression::deepBeautify(Context & context, Preferences::AngleUnit angleUnit) { - Expression e = shallowBeautify(context, angleUnit); +Expression Expression::deepBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + Expression e = shallowBeautify(context, complexFormat, angleUnit); int nbChildren = e.numberOfChildren(); for (int i = 0; i < nbChildren; i++) { - e.childAtIndex(i).deepBeautify(context, angleUnit); + e.childAtIndex(i).deepBeautify(context, complexFormat, angleUnit); } return e; } -Expression Expression::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - return node()->setSign(s, context, angleUnit, target); +Expression Expression::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + return node()->setSign(s, context, complexFormat, angleUnit, target); } /* Evaluation */ template -Expression Expression::approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const { +Expression Expression::approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { return isUninitialized() ? Undefined() : approximateToEvaluation(context, angleUnit).complexToExpression(complexFormat); } @@ -532,11 +548,9 @@ U Expression::approximateToScalar(Context& context, Preferences::AngleUnit angle } template -U Expression::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit) { - Expression exp = ParseAndSimplify(text, context, angleUnit); - if (exp.isUninitialized()) { - return NAN; - } +U Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + Expression exp = ParseAndSimplify(text, context, UpdatedComplexFormatWithTextInput(complexFormat, text), angleUnit); + assert(!exp.isUninitialized()); return exp.approximateToScalar(context, angleUnit); } @@ -958,14 +972,14 @@ double Expression::brentRoot(const char * symbol, double ax, double bx, double p template float Expression::epsilon(); template double Expression::epsilon(); -template Expression Expression::approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const; -template Expression Expression::approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) const; +template Expression Expression::approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; +template Expression Expression::approximate(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; template float Expression::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const; template double Expression::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const; -template float Expression::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit); -template double Expression::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit); +template float Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); +template double Expression::approximateToScalar(const char * text, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); template Evaluation Expression::approximateToEvaluation(Context& context, Preferences::AngleUnit angleUnit) const; template Evaluation Expression::approximateToEvaluation(Context& context, Preferences::AngleUnit angleUnit) const; diff --git a/poincare/src/expression_node.cpp b/poincare/src/expression_node.cpp index 0a9bbcc63..df89e10c7 100644 --- a/poincare/src/expression_node.cpp +++ b/poincare/src/expression_node.cpp @@ -22,7 +22,7 @@ Expression ExpressionNode::replaceUnknown(const Symbol & symbol) { return Expression(this).defaultReplaceUnknown(symbol); } -Expression ExpressionNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression ExpressionNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { assert(false); return Expression(); } @@ -108,16 +108,16 @@ int ExpressionNode::simplificationOrderSameType(const ExpressionNode * e, bool c return 0; } -void ExpressionNode::deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - Expression(this).defaultDeepReduceChildren(context, angleUnit, target); +void ExpressionNode::deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + Expression(this).defaultDeepReduceChildren(context, complexFormat, angleUnit, target); } -Expression ExpressionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Expression(this).defaultShallowReduce(context, angleUnit); +Expression ExpressionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Expression(this).defaultShallowReduce(); } -Expression ExpressionNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Expression(this).defaultShallowBeautify(context, angleUnit); +Expression ExpressionNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Expression(this).defaultShallowBeautify(); } bool ExpressionNode::isOfType(Type * types, int length) const { @@ -133,7 +133,7 @@ void ExpressionNode::setChildrenInPlace(Expression other) { Expression(this).defaultSetChildrenInPlace(other); } -Expression ExpressionNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const { +Expression ExpressionNode::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { return Expression(); } diff --git a/poincare/src/factor.cpp b/poincare/src/factor.cpp index 1cb6078b3..e1da25442 100644 --- a/poincare/src/factor.cpp +++ b/poincare/src/factor.cpp @@ -26,11 +26,11 @@ int FactorNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Factor::s_functionHelper.name()); } -Expression FactorNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Factor(this).shallowBeautify(context, angleUnit); +Expression FactorNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Factor(this).shallowBeautify(context, complexFormat, angleUnit); } -Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Factor::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression c = childAtIndex(0); if (c.type() != ExpressionNode::Type::Rational) { Expression result = Undefined(); @@ -42,7 +42,7 @@ Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit ang replaceWithInPlace(r); return r; } - Multiplication numeratorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.unsignedIntegerNumerator(), context, angleUnit); + Multiplication numeratorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.unsignedIntegerNumerator(), context, complexFormat, angleUnit); if (numeratorDecomp.numberOfChildren() == 0) { Expression result = Undefined(); replaceWithInPlace(result); @@ -50,7 +50,7 @@ Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit ang } Expression result = numeratorDecomp.squashUnaryHierarchyInPlace(); if (!r.integerDenominator().isOne()) { - Multiplication denominatorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.integerDenominator(), context, angleUnit); + Multiplication denominatorDecomp = createMultiplicationOfIntegerPrimeDecomposition(r.integerDenominator(), context, complexFormat, angleUnit); if (denominatorDecomp.numberOfChildren() == 0) { Expression result = Undefined(); replaceWithInPlace(result); @@ -65,7 +65,7 @@ Expression Factor::shallowBeautify(Context & context, Preferences::AngleUnit ang return result; } -Multiplication Factor::createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::AngleUnit angleUnit) const { +Multiplication Factor::createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { assert(!i.isZero()); assert(!i.isNegative()); Multiplication m; diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index 5929a02a1..3e4d8d60d 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -14,7 +14,7 @@ namespace Poincare { // Property -Expression FactorialNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression FactorialNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { assert(s == Sign::Positive); return Factorial(this); } @@ -34,12 +34,12 @@ bool FactorialNode::childNeedsParenthesis(const TreeNode * child) const { // Simplification -Expression FactorialNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Factorial(this).shallowReduce(context, angleUnit); +Expression FactorialNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Factorial(this).shallowReduce(context, complexFormat, angleUnit); } -Expression FactorialNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Factorial(this).shallowBeautify(context, angleUnit); +Expression FactorialNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Factorial(this).shallowBeautify(context, complexFormat, angleUnit); } template @@ -91,9 +91,9 @@ int FactorialNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl Factorial::Factorial() : Expression(TreePool::sharedPool()->createTreeNode()) {} -Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Factorial::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -127,7 +127,7 @@ Expression Factorial::shallowReduce(Context & context, Preferences::AngleUnit an return *this; } -Expression Factorial::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Factorial::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { // +(a,b)! ->(+(a,b))! if (childAtIndex(0).type() == ExpressionNode::Type::Addition || childAtIndex(0).type() == ExpressionNode::Type::Multiplication diff --git a/poincare/src/float.cpp b/poincare/src/float.cpp index eecf004ee..8fb98d2e1 100644 --- a/poincare/src/float.cpp +++ b/poincare/src/float.cpp @@ -4,7 +4,7 @@ namespace Poincare { template -Expression FloatNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression FloatNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { assert(s != Sign::Unknown); Sign currentSign = m_value < 0 ? Sign::Negative : Sign::Positive; Expression thisExpr = Number(this); diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index 1fa2bc521..97236d5f0 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -31,13 +31,13 @@ Complex FloorNode::computeOnComplex(const std::complex c, Preferences::Ang return Complex(std::floor(c.real())); } -Expression FloorNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Floor(this).shallowReduce(context, angleUnit); +Expression FloorNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Floor(this).shallowReduce(context, complexFormat, angleUnit); } -Expression Floor::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Floor::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/frac_part.cpp b/poincare/src/frac_part.cpp index 3cfd30f64..beae8c161 100644 --- a/poincare/src/frac_part.cpp +++ b/poincare/src/frac_part.cpp @@ -19,8 +19,8 @@ int FracPartNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, FracPart::s_functionHelper.name()); } -Expression FracPartNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return FracPart(this).shallowReduce(context, angleUnit); +Expression FracPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return FracPart(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -31,9 +31,9 @@ Complex FracPartNode::computeOnComplex(const std::complex c, Preferences:: return Complex(c.real()-std::floor(c.real())); } -Expression FracPart::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression FracPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index becd1f6ae..f21d0066e 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -62,8 +62,8 @@ int FunctionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, name()); } -Expression FunctionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Function(this).shallowReduce(context, angleUnit, target); // This uses Symbol::shallowReduce +Expression FunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Function(this).shallowReduce(context, complexFormat, angleUnit, target); // This uses Symbol::shallowReduce } Expression FunctionNode::shallowReplaceReplaceableSymbols(Context & context) { @@ -113,12 +113,12 @@ Expression Function::replaceSymbolWithExpression(const SymbolAbstract & symbol, return *this; } -Expression Function::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Function::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Function f(*this); Expression e = SymbolAbstract::Expand(f, context, true); if (!e.isUninitialized()) { replaceWithInPlace(e); - return e.deepReduce(context, angleUnit, target); + return e.deepReduce(context, complexFormat, angleUnit, target); } return *this; } diff --git a/poincare/src/great_common_divisor.cpp b/poincare/src/great_common_divisor.cpp index 5d1cd2265..0dda60aa5 100644 --- a/poincare/src/great_common_divisor.cpp +++ b/poincare/src/great_common_divisor.cpp @@ -20,8 +20,8 @@ int GreatCommonDivisorNode::serialize(char * buffer, int bufferSize, Preferences return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, GreatCommonDivisor::s_functionHelper.name()); } -Expression GreatCommonDivisorNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return GreatCommonDivisor(this).shallowReduce(context, angleUnit); +Expression GreatCommonDivisorNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return GreatCommonDivisor(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -48,9 +48,9 @@ Evaluation GreatCommonDivisorNode::templatedApproximate(Context& context, Pre return Complex(std::round((T)a)); } -Expression GreatCommonDivisor::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression GreatCommonDivisor::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/hyperbolic_trigonometric_function.cpp b/poincare/src/hyperbolic_trigonometric_function.cpp index 812c51d9a..d8f27740b 100644 --- a/poincare/src/hyperbolic_trigonometric_function.cpp +++ b/poincare/src/hyperbolic_trigonometric_function.cpp @@ -2,13 +2,13 @@ namespace Poincare { -Expression HyperbolicTrigonometricFunctionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return HyperbolicTrigonometricFunction(this).shallowReduce(context, angleUnit); +Expression HyperbolicTrigonometricFunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return HyperbolicTrigonometricFunction(this).shallowReduce(context, complexFormat, angleUnit); } -Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicTrigonometricFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/imaginary_part.cpp b/poincare/src/imaginary_part.cpp index 3f8e14e7d..7667e535b 100644 --- a/poincare/src/imaginary_part.cpp +++ b/poincare/src/imaginary_part.cpp @@ -20,13 +20,13 @@ int ImaginaryPartNode::serialize(char * buffer, int bufferSize, Preferences::Pri return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ImaginaryPart::s_functionHelper.name()); } -Expression ImaginaryPartNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return ImaginaryPart(this).shallowReduce(context, angleUnit, target); +Expression ImaginaryPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return ImaginaryPart(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression ImaginaryPart::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression ImaginaryPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -46,7 +46,7 @@ Expression ImaginaryPart::shallowReduce(Context & context, Preferences::AngleUni ComplexCartesian complexChild = static_cast(c); Expression i = complexChild.imag(); replaceWithInPlace(i); - return i.shallowReduce(context, angleUnit, target); + return i.shallowReduce(context, complexFormat, angleUnit, target); } return *this; } diff --git a/poincare/src/infinity.cpp b/poincare/src/infinity.cpp index 9b11e2296..23bb83526 100644 --- a/poincare/src/infinity.cpp +++ b/poincare/src/infinity.cpp @@ -9,8 +9,8 @@ extern "C" { namespace Poincare { -Expression InfinityNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Infinity(this).setSign(s, context, angleUnit); +Expression InfinityNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Infinity(this).setSign(s, context, complexFormat, angleUnit); } Layout InfinityNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -30,7 +30,7 @@ template Evaluation InfinityNode::templatedApproximate() const { return Complex(m_negative ? -INFINITY : INFINITY); } -Expression Infinity::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit) { +Expression Infinity::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression result = Infinity(s == ExpressionNode::Sign::Negative); replaceWithInPlace(result); return result; diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index 0c2c26fd5..7d17fe2d7 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -43,8 +43,8 @@ int IntegralNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Integral::s_functionHelper.name()); } -Expression IntegralNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Integral(this).shallowReduce(context, angleUnit); +Expression IntegralNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Integral(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -195,9 +195,9 @@ T IntegralNode::adaptiveQuadrature(T a, T b, T eps, int numberOfIterations, Cont } #endif -Expression Integral::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Integral::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/least_common_multiple.cpp b/poincare/src/least_common_multiple.cpp index e8092e698..aa20c0931 100644 --- a/poincare/src/least_common_multiple.cpp +++ b/poincare/src/least_common_multiple.cpp @@ -21,8 +21,8 @@ int LeastCommonMultipleNode::serialize(char * buffer, int bufferSize, Preference return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, LeastCommonMultiple::s_functionHelper.name()); } -Expression LeastCommonMultipleNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return LeastCommonMultiple(this).shallowReduce(context, angleUnit); +Expression LeastCommonMultipleNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return LeastCommonMultiple(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -53,9 +53,9 @@ Evaluation LeastCommonMultipleNode::templatedApproximate(Context& context, Pr return Complex(product/a); } -Expression LeastCommonMultiple::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression LeastCommonMultiple::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index 4295012eb..ccef5b82a 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -48,23 +48,23 @@ int LogarithmNode::serialize(char * buffer, int bufferSize, Preferences::Prin } template<> -Expression LogarithmNode<1>::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - return CommonLogarithm(this).shallowReduce(context, angleUnit, target); +Expression LogarithmNode<1>::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + return CommonLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target); } template<> -Expression LogarithmNode<2>::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - return Logarithm(this).shallowReduce(context, angleUnit, target); +Expression LogarithmNode<2>::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + return Logarithm(this).shallowReduce(context, complexFormat, angleUnit, target); } template<> -Expression LogarithmNode<1>::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression LogarithmNode<1>::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { return CommonLogarithm(this); } template<> -Expression LogarithmNode<2>::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Logarithm(this).shallowBeautify(context, angleUnit); +Expression LogarithmNode<2>::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Logarithm(this).shallowBeautify(context, complexFormat, angleUnit); } template<> @@ -85,9 +85,9 @@ template Evaluation LogarithmNode<2>::templatedApproximate(Contex return Complex(result); } -Expression CommonLogarithm::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ +Expression CommonLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -102,12 +102,12 @@ Expression CommonLogarithm::shallowReduce(Context & context, Preferences::AngleU #endif Logarithm log = Logarithm::Builder(childAtIndex(0), Rational(10)); replaceWithInPlace(log); - return log.shallowReduce(context, angleUnit, target); + return log.shallowReduce(context, complexFormat, angleUnit, target); } -Expression Logarithm::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ +Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -123,7 +123,7 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::AngleUnit an if (c.sign(&context) == ExpressionNode::Sign::Negative || childAtIndex(1).sign(&context) == ExpressionNode::Sign::Negative) { return *this; } - Expression f = simpleShallowReduce(context, angleUnit); + Expression f = simpleShallowReduce(context, complexFormat, angleUnit); if (f.type() != ExpressionNode::Type::Logarithm) { return f; } @@ -144,8 +144,8 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::AngleUnit an Multiplication mult(y); replaceWithInPlace(mult); mult.addChildAtIndexInPlace(*this, 1, 1); // --> y*log(x,b) - shallowReduce(context, angleUnit, target); // reduce log (ie log(e, e) = 1) - return mult.shallowReduce(context, angleUnit, target); + shallowReduce(context, complexFormat, angleUnit, target); // 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 if (!letLogAtRoot && c.type() == ExpressionNode::Type::Multiplication) { @@ -157,15 +157,15 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::AngleUnit an static_cast(c).removeChildInPlace(factor, factor.numberOfChildren()); newLog.replaceChildAtIndexInPlace(0, factor); a.addChildAtIndexInPlace(newLog, a.numberOfChildren(), a.numberOfChildren()); - newLog.shallowReduce(context, angleUnit, target); + newLog.shallowReduce(context, complexFormat, angleUnit, target); } } if (a.numberOfChildren() > 0) { - c.shallowReduce(context, angleUnit, target); - Expression reducedLastLog = shallowReduce(context, angleUnit, target); + c.shallowReduce(context, complexFormat, angleUnit, target); + Expression reducedLastLog = shallowReduce(context, complexFormat, angleUnit, target); reducedLastLog.replaceWithInPlace(a); a.addChildAtIndexInPlace(reducedLastLog, a.numberOfChildren(), a.numberOfChildren()); - return a.shallowReduce(context, angleUnit, target); + return a.shallowReduce(context, complexFormat, angleUnit, target); } } // log(r) with r Rational @@ -180,15 +180,15 @@ Expression Logarithm::shallowReduce(Context & context, Preferences::AngleUnit an r = Rational(newNumerator, newDenomitor); } // log(r) = a0log(p0)+a1log(p1)+... with r = p0^a0*p1^a1*... (Prime decomposition) - a.addChildAtIndexInPlace(splitLogarithmInteger(r.signedIntegerNumerator(), false, context, angleUnit, target), a.numberOfChildren(), a.numberOfChildren()); - a.addChildAtIndexInPlace(splitLogarithmInteger(r.integerDenominator(), true, context, angleUnit, target), a.numberOfChildren(), a.numberOfChildren()); + a.addChildAtIndexInPlace(splitLogarithmInteger(r.signedIntegerNumerator(), false, context, complexFormat, angleUnit, target), a.numberOfChildren(), a.numberOfChildren()); + a.addChildAtIndexInPlace(splitLogarithmInteger(r.integerDenominator(), true, context, complexFormat, angleUnit, target), a.numberOfChildren(), a.numberOfChildren()); replaceWithInPlace(a); - return a.shallowReduce(context, angleUnit, target); + return a.shallowReduce(context, complexFormat, angleUnit, target); } return *this; } -Expression Logarithm::simpleShallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Logarithm::simpleShallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression c = childAtIndex(0); // log(0,0)->Undefined if (c.type() == ExpressionNode::Type::Rational && childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().isZero() && static_cast(c).isZero()) { @@ -274,7 +274,7 @@ Integer Logarithm::simplifyLogarithmIntegerBaseInteger(Integer i, Integer & base return i; } -Expression Logarithm::splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Logarithm::splitLogarithmInteger(Integer i, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(!i.isZero()); assert(!i.isNegative()); Integer factors[Arithmetic::k_maxNumberOfPrimeFactors]; @@ -302,14 +302,14 @@ Expression Logarithm::splitLogarithmInteger(Integer i, bool isDenominator, Conte Logarithm e = clone().convert(); e.replaceChildAtIndexInPlace(0, Rational(factors[index])); Multiplication m = Multiplication(Rational(coefficients[index]), e); - e.simpleShallowReduce(context, angleUnit); + e.simpleShallowReduce(context, complexFormat, angleUnit); a.addChildAtIndexInPlace(m, a.numberOfChildren(), a.numberOfChildren()); - m.shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); } return a; } -Expression Logarithm::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Logarithm::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(numberOfChildren() == 2); Constant e = Constant(Ion::Charset::Exponential); if (childAtIndex(1).isIdenticalTo(e)) { diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index 527830845..6d5bd5398 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -107,9 +107,9 @@ void Matrix::addChildrenAsRowInPlace(TreeHandle t, int i) { setDimensions(previousNumberOfRows + 1, previousNumberOfColumns == 0 ? t.numberOfChildren() : previousNumberOfColumns); } -int Matrix::rank(Context & context, Preferences::AngleUnit angleUnit, bool inPlace) { +int Matrix::rank(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, bool inPlace) { Matrix m = inPlace ? *this : clone().convert(); - m = m.rowCanonize(context, angleUnit); + m = m.rowCanonize(context, complexFormat, angleUnit); int rank = m.numberOfRows(); int i = rank-1; while (i >= 0) { @@ -159,10 +159,10 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) { return 0; } -Matrix Matrix::rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Multiplication determinant) { +Matrix Matrix::rowCanonize(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, Multiplication determinant) { Expression::setInterruption(false); // The matrix children have to be reduced to be able to spot 0 - deepReduceChildren(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + deepReduceChildren(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); int m = numberOfRows(); int n = numberOfColumns(); @@ -198,7 +198,7 @@ Matrix Matrix::rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Expression opHJ = matrixChild(h, j); Expression newOpHJ = Division(opHJ, divisor.clone()); replaceChildAtIndexInPlace(h*n+j, newOpHJ); - newOpHJ = newOpHJ.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + newOpHJ = newOpHJ.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); } replaceChildInPlace(divisor, Rational(1)); @@ -210,8 +210,8 @@ Matrix Matrix::rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Expression opIJ = matrixChild(i, j); Expression newOpIJ = Subtraction(opIJ, Multiplication(matrixChild(h, j).clone(), factor.clone())); replaceChildAtIndexInPlace(i*n+j, newOpIJ); - newOpIJ.childAtIndex(1).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); - newOpIJ = newOpIJ.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + newOpIJ.childAtIndex(1).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); + newOpIJ = newOpIJ.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::TopDownComputation); } replaceChildAtIndexInPlace(i*n+k, Rational(0)); } @@ -299,7 +299,7 @@ Matrix Matrix::createIdentity(int dim) { return matrix; } -Expression Matrix::inverse(Context & context, Preferences::AngleUnit angleUnit) const { +Expression Matrix::inverse(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { if (m_numberOfRows != m_numberOfColumns) { return Undefined(); } @@ -315,7 +315,7 @@ Expression Matrix::inverse(Context & context, Preferences::AngleUnit angleUnit) } } AI.setDimensions(dim, 2*dim); - AI = AI.rowCanonize(context, angleUnit); + AI = AI.rowCanonize(context, complexFormat, angleUnit); // Check inversibility for (int i = 0; i < dim; i++) { if (AI.matrixChild(i, i)->type() != ExpressionNode::Type::Rational || !static_cast(AI.matrixChild(i, i)->node())->isOne()) { diff --git a/poincare/src/matrix_dimension.cpp b/poincare/src/matrix_dimension.cpp index e19409552..d1b12ed54 100644 --- a/poincare/src/matrix_dimension.cpp +++ b/poincare/src/matrix_dimension.cpp @@ -11,8 +11,8 @@ constexpr Expression::FunctionHelper MatrixDimension::s_functionHelper; int MatrixDimensionNode::numberOfChildren() const { return MatrixDimension::s_functionHelper.numberOfChildren(); } -Expression MatrixDimensionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return MatrixDimension(this).shallowReduce(context, angleUnit); +Expression MatrixDimensionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return MatrixDimension(this).shallowReduce(context, complexFormat, angleUnit); } Layout MatrixDimensionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -37,9 +37,9 @@ Evaluation MatrixDimensionNode::templatedApproximate(Context& context, Prefer return MatrixComplex(operands, 1, 2); } -Expression MatrixDimension::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression MatrixDimension::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/matrix_inverse.cpp b/poincare/src/matrix_inverse.cpp index 43890f656..eca3f9a69 100644 --- a/poincare/src/matrix_inverse.cpp +++ b/poincare/src/matrix_inverse.cpp @@ -14,8 +14,8 @@ constexpr Expression::FunctionHelper MatrixInverse::s_functionHelper; int MatrixInverseNode::numberOfChildren() const { return MatrixInverse::s_functionHelper.numberOfChildren(); } -Expression MatrixInverseNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return MatrixInverse(this).shallowReduce(context, angleUnit, target); +Expression MatrixInverseNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return MatrixInverse(this).shallowReduce(context, complexFormat, angleUnit, target); } Layout MatrixInverseNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -42,9 +42,9 @@ Evaluation MatrixInverseNode::templatedApproximate(Context& context, Preferen return inverse; } -Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression MatrixInverse::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -53,7 +53,7 @@ Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUni #if MATRIX_EXACT_REDUCING #if 0 if (!c.recursivelyMatches(Expression::IsMatrix)) { - return Power(c, Rational(-1).shallowReduce(context, angleUnit, target); + return Power(c, Rational(-1).shallowReduce(context, complexFormat, angleUnit, target); } if (c.type() == ExpressionNode::Type::Matrix) { Matrix mat = static_cast(c); @@ -67,7 +67,7 @@ Expression MatrixInverse::shallowReduce(Context & context, Preferences::AngleUni if (c.type() != ExpressionNode::Type::Matrix) { Expression result = Power(c, Rational(-1)); replaceWithInPlace(result); - result = result.shallowReduce(context, angleUnit, target); + result = result.shallowReduce(context, complexFormat, angleUnit, target); return result; } return *this; diff --git a/poincare/src/matrix_trace.cpp b/poincare/src/matrix_trace.cpp index aabe59807..ec7c9a866 100644 --- a/poincare/src/matrix_trace.cpp +++ b/poincare/src/matrix_trace.cpp @@ -13,8 +13,8 @@ constexpr Expression::FunctionHelper MatrixTrace::s_functionHelper; int MatrixTraceNode::numberOfChildren() const { return MatrixTrace::s_functionHelper.numberOfChildren(); } -Expression MatrixTraceNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return MatrixTrace(this).shallowReduce(context, angleUnit); +Expression MatrixTraceNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return MatrixTrace(this).shallowReduce(context, complexFormat, angleUnit); } Layout MatrixTraceNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -32,9 +32,9 @@ Evaluation MatrixTraceNode::templatedApproximate(Context& context, Preference return result; } -Expression MatrixTrace::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression MatrixTrace::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -52,7 +52,7 @@ Expression MatrixTrace::shallowReduce(Context & context, Preferences::AngleUnit for (int i = 0; i < n; i++) { a.addChildAtIndexInPlace(m.childAtIndex(i+n*i), i, a.numberOfChildren()); } - return a.shallowReduce(context, angleUnit); + return a.shallowReduce(context, complexFormat, angleUnit); } if (!c.recursivelyMatches(Expression::IsMatrix)) { return c; diff --git a/poincare/src/matrix_transpose.cpp b/poincare/src/matrix_transpose.cpp index 41ca47975..f19878254 100644 --- a/poincare/src/matrix_transpose.cpp +++ b/poincare/src/matrix_transpose.cpp @@ -12,8 +12,8 @@ constexpr Expression::FunctionHelper MatrixTranspose::s_functionHelper; int MatrixTransposeNode::numberOfChildren() const { return MatrixTranspose::s_functionHelper.numberOfChildren(); } -Expression MatrixTransposeNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return MatrixTranspose(this).shallowReduce(context, angleUnit); +Expression MatrixTransposeNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return MatrixTranspose(this).shallowReduce(context, complexFormat, angleUnit); } Layout MatrixTransposeNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -37,9 +37,9 @@ Evaluation MatrixTransposeNode::templatedApproximate(Context& context, Prefer return transpose; } -Expression MatrixTranspose::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression MatrixTranspose::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 2a51cf782..9e263b25b 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -66,8 +66,8 @@ MatrixComplex MultiplicationNode::computeOnMatrices(const MatrixComplex m, return result; } -Expression MultiplicationNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Multiplication(this).setSign(s, context, angleUnit, target); +Expression MultiplicationNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Multiplication(this).setSign(s, context, complexFormat, angleUnit, target); } bool MultiplicationNode::childNeedsParenthesis(const TreeNode * child) const { @@ -93,16 +93,16 @@ int MultiplicationNode::serialize(char * buffer, int bufferSize, Preferences::Pr return SerializationHelper::Infix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, multiplicationString); } -Expression MultiplicationNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Multiplication(this).shallowReduce(context, angleUnit, target); +Expression MultiplicationNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Multiplication(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression MultiplicationNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Multiplication(this).shallowBeautify(context, angleUnit); +Expression MultiplicationNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Multiplication(this).shallowBeautify(context, complexFormat, angleUnit); } -Expression MultiplicationNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const { - return Multiplication(this).denominator(context, angleUnit); +Expression MultiplicationNode::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { + return Multiplication(this).denominator(context, complexFormat, angleUnit); } /* Multiplication */ @@ -122,21 +122,21 @@ void Multiplication::computeOnArrays(T * m, T * n, T * result, int mNumberOfColu } } -Expression Multiplication::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Multiplication::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(s == ExpressionNode::Sign::Positive); for (int i = 0; i < numberOfChildren(); i++) { if (childAtIndex(i).sign(context) == ExpressionNode::Sign::Negative) { - replaceChildAtIndexInPlace(i, childAtIndex(i).setSign(s, context, angleUnit, target)); + replaceChildAtIndexInPlace(i, childAtIndex(i).setSign(s, context, complexFormat, angleUnit, target)); } } - return shallowReduce(*context, angleUnit, target); + return shallowReduce(*context, complexFormat, angleUnit, target); } -Expression Multiplication::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - return privateShallowReduce(context, angleUnit, target, true, true); +Expression Multiplication::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + return privateShallowReduce(context, complexFormat, angleUnit, target, true, true); } -Expression Multiplication::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Multiplication::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { /* Beautifying a Multiplication consists in several possible operations: * - Add Opposite ((-3)*x -> -(3*x), useful when printing fractions) * - Adding parenthesis if needed (a*(b+c) is not a*b+c) @@ -144,7 +144,7 @@ Expression Multiplication::shallowBeautify(Context & context, Preferences::Angle * shall become a/b) or a non-integer rational term (3/2*a -> (3*a)/2). */ // Step 1: Turn -n*A into -(n*A) - Expression noNegativeNumeral = makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression noNegativeNumeral = makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); // If one negative numeral factor was made positive, we turn the expression in an Opposite if (!noNegativeNumeral.isUninitialized()) { Opposite o = Opposite(); @@ -155,9 +155,9 @@ Expression Multiplication::shallowBeautify(Context & context, Preferences::Angle /* Step 2: Merge negative powers: a*b^(-1)*c^(-pi)*d = a*(b*c^pi)^(-1) * This also turns 2/3*a into 2*a*3^(-1) */ - Expression thisExp = mergeNegativePower(context, angleUnit); + Expression thisExp = mergeNegativePower(context, complexFormat, angleUnit); if (thisExp.type() == ExpressionNode::Type::Power) { - return thisExp.shallowBeautify(context, angleUnit); + return thisExp.shallowBeautify(context, complexFormat, angleUnit); } assert(thisExp.type() == ExpressionNode::Type::Multiplication); @@ -181,7 +181,7 @@ Expression Multiplication::shallowBeautify(Context & context, Preferences::Angle Expression denominatorOperand = childI.childAtIndex(0); removeChildInPlace(childI, childI.numberOfChildren()); - Expression numeratorOperand = shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression numeratorOperand = shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); // Delete unnecessary parentheses on numerator if (numeratorOperand.type() == ExpressionNode::Type::Parenthesis) { Expression numeratorChild0 = numeratorOperand.childAtIndex(0); @@ -193,7 +193,7 @@ Expression Multiplication::shallowBeautify(Context & context, Preferences::Angle numeratorOperand.replaceWithInPlace(d); d.replaceChildAtIndexInPlace(0, numeratorOperand); d.replaceChildAtIndexInPlace(1, denominatorOperand); - return d.shallowBeautify(context, angleUnit); + return d.shallowBeautify(context, complexFormat, angleUnit); } return thisExp; } @@ -233,13 +233,13 @@ int Multiplication::getPolynomialCoefficients(Context & context, const char * sy return deg; } -Expression Multiplication::denominator(Context & context, Preferences::AngleUnit angleUnit) const { +Expression Multiplication::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { // Merge negative power: a*b^-1*c^(-Pi)*d = a*(b*c^Pi)^-1 // WARNING: we do not want to change the expression but to create a new one. Multiplication thisClone = clone().convert(); - Expression e = thisClone.mergeNegativePower(context, angleUnit); + Expression e = thisClone.mergeNegativePower(context, complexFormat, angleUnit); if (e.type() == ExpressionNode::Type::Power) { - return e.denominator(context, angleUnit); + return e.denominator(context, complexFormat, angleUnit); } else { assert(e.type() == ExpressionNode::Type::Multiplication); for (int i = 0; i < e.numberOfChildren(); i++) { @@ -255,9 +255,9 @@ Expression Multiplication::denominator(Context & context, Preferences::AngleUnit return Expression(); } -Expression Multiplication::privateShallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool shouldExpand, bool canBeInterrupted) { +Expression Multiplication::privateShallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool shouldExpand, bool canBeInterrupted) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit);; + Expression e = Expression::defaultShallowReduce();; if (e.isUndefined()) { return e; } @@ -323,9 +323,9 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: for (int j = 0; j < n; j++) { Expression * mult = new Multiplication(currentMatrix->childAtIndex(j+om*i1), resultMatrix->childAtIndex(j*m+i2), true); static_cast(newMatrixOperands[e])->addOperand(mult); - mult->shallowReduce(context, angleUnit, target); + mult->shallowReduce(context, complexFormat, angleUnit, target); } - Reduce(&newMatrixOperands[e], context, angleUnit, false); + Reduce(&newMatrixOperands[e], context, complexFormat, angleUnit, false); } n = on; removeOperand(currentMatrix, true); @@ -339,9 +339,9 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: Expression * entryI = resultMatrix->childAtIndex(i); resultMatrix->replaceOperand(entryI, m, false); m->addOperand(entryI); - m->shallowReduce(context, angleUnit, target); + m->shallowReduce(context, complexFormat, angleUnit, target); } - return replaceWith(resultMatrix, true)->shallowReduce(context, angleUnit, target); + return replaceWith(resultMatrix, true)->shallowReduce(context, complexFormat, angleUnit, target); } #endif #endif @@ -363,11 +363,11 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: shouldFactorizeBase = oi.type() == ExpressionNode::Type::Power && oi1.type() == ExpressionNode::Type::Power; } if (shouldFactorizeBase) { - factorizeBase(i, i+1, context, angleUnit, target); + factorizeBase(i, i+1, context, complexFormat, angleUnit, target); continue; } } else if (TermHasNumeralBase(oi) && TermHasNumeralBase(oi1) && TermsHaveIdenticalExponent(oi, oi1)) { - factorizeExponent(i, i+1, context, angleUnit, target); + factorizeExponent(i, i+1, context, complexFormat, angleUnit, target); continue; } i++; @@ -387,7 +387,7 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: for (int j = i+1; j < numberOfChildren(); j++) { Expression o2 = childAtIndex(j); if (Base(o2).type() == ExpressionNode::Type::Cosine && TermHasNumeralExponent(o2) && Base(o2).childAtIndex(0).isIdenticalTo(x)) { - factorizeSineAndCosine(i, j, context, angleUnit); + factorizeSineAndCosine(i, j, context, complexFormat, angleUnit); break; } } @@ -456,7 +456,7 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: if (target != ExpressionNode::ReductionTarget::BottomUpComputation && shouldExpand && (p.isUninitialized() || p.type() != ExpressionNode::Type::Multiplication)) { for (int i = 0; i < numberOfChildren(); i++) { if (childAtIndex(i).type() == ExpressionNode::Type::Addition) { - return distributeOnOperandAtIndex(i, context, angleUnit, target); + return distributeOnOperandAtIndex(i, context, complexFormat, angleUnit, target); } } } @@ -490,7 +490,7 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: // the Multiplication is sorted so ComplexCartesian nodes are the last ones break; } - child = child.multiply(static_cast(e), context, angleUnit, target); + child = child.multiply(static_cast(e), context, complexFormat, angleUnit, target); removeChildAtIndexInPlace(i); i--; } @@ -503,9 +503,9 @@ Expression Multiplication::privateShallowReduce(Context & context, Preferences:: replaceWithInPlace(newComplexCartesian); newComplexCartesian.replaceChildAtIndexInPlace(0, real); newComplexCartesian.replaceChildAtIndexInPlace(1, imag); - real.shallowReduce(context, angleUnit, target); - imag.shallowReduce(context, angleUnit, target); - return newComplexCartesian.shallowReduce(context, angleUnit); + real.shallowReduce(context, complexFormat, angleUnit, target); + imag.shallowReduce(context, complexFormat, angleUnit, target); + return newComplexCartesian.shallowReduce(context, complexFormat, angleUnit); } return result; @@ -524,7 +524,7 @@ void Multiplication::mergeMultiplicationChildrenInPlace() { } } -void Multiplication::factorizeBase(int i, int j, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void Multiplication::factorizeBase(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { /* This function factorizes two children which have a common base. For example * if this is Multiplication(pi^2, pi^3), then pi^2 and pi^3 could be merged * and this turned into Multiplication(pi^5). */ @@ -533,10 +533,10 @@ void Multiplication::factorizeBase(int i, int j, Context & context, Preferences: // Step 1: Get rid of the child j removeChildAtIndexInPlace(j); // Step 2: Merge child j in child i by factorizing base - mergeInChildByFactorizingBase(i, e, context, angleUnit, target); + mergeInChildByFactorizingBase(i, e, context, complexFormat, angleUnit, target); } -void Multiplication::mergeInChildByFactorizingBase(int i, Expression e, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void Multiplication::mergeInChildByFactorizingBase(int i, Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { /* This function replace the child at index i by its factorization with e. e * and childAtIndex(i) are supposed to have a common base. */ @@ -544,10 +544,10 @@ void Multiplication::mergeInChildByFactorizingBase(int i, Expression e, Context Expression s = Addition(CreateExponent(childAtIndex(i)), CreateExponent(e)); // pi^2*pi^3 -> pi^(2+3) -> pi^5 // Step 2: Create the new Power Expression p = Power(Base(childAtIndex(i)), s); // pi^2*pi^-2 -> pi^0 -> 1 - s.shallowReduce(context, angleUnit, target); + s.shallowReduce(context, complexFormat, angleUnit, target); // Step 3: Replace one of the child replaceChildAtIndexInPlace(i, p); - p = p.shallowReduce(context, angleUnit, target); + p = p.shallowReduce(context, complexFormat, angleUnit, target); /* Step 4: Reducing the new power might have turned it into a multiplication, * ie: 12^(1/2) -> 2*3^(1/2). In that case, we need to merge the multiplication * node with this. */ @@ -556,7 +556,7 @@ void Multiplication::mergeInChildByFactorizingBase(int i, Expression e, Context } } -void Multiplication::factorizeExponent(int i, int j, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void Multiplication::factorizeExponent(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { /* This function factorizes children which share a common exponent. For * example, it turns Multiplication(2^x,3^x) into Multiplication(6^x). */ @@ -567,8 +567,8 @@ void Multiplication::factorizeExponent(int i, int j, Context & context, Preferen // Step 3: Replace the other child childAtIndex(i).replaceChildAtIndexInPlace(0, m); // Step 4: Reduce expressions - m.shallowReduce(context, angleUnit, target); - Expression p = childAtIndex(i).shallowReduce(context, angleUnit, target); // 2^x*(1/2)^x -> (2*1/2)^x -> 1 + m.shallowReduce(context, complexFormat, angleUnit, target); + Expression p = childAtIndex(i).shallowReduce(context, complexFormat, angleUnit, target); // 2^x*(1/2)^x -> (2*1/2)^x -> 1 /* Step 5: Reducing the new power might have turned it into a multiplication, * ie: 12^(1/2) -> 2*3^(1/2). In that case, we need to merge the multiplication * node with this. */ @@ -577,7 +577,7 @@ void Multiplication::factorizeExponent(int i, int j, Context & context, Preferen } } -Expression Multiplication::distributeOnOperandAtIndex(int i, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Multiplication::distributeOnOperandAtIndex(int i, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { /* This method creates a*...*b*y... + a*...*c*y... + ... from * a*...*(b+c+...)*y... */ assert(i >= 0 && i < numberOfChildren()); @@ -591,16 +591,16 @@ Expression Multiplication::distributeOnOperandAtIndex(int i, Context & context, m.replaceChildAtIndexInPlace(i, childI.childAtIndex(j)); // Reduce m: pi^(-1)*(pi + x) -> pi^(-1)*pi + pi^(-1)*x -> 1 + pi^(-1)*x a.addChildAtIndexInPlace(m, a.numberOfChildren(), a.numberOfChildren()); - m.shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); } replaceWithInPlace(a); - return a.shallowReduce(context, angleUnit, target); // Order terms, put under a common denominator if needed + return a.shallowReduce(context, complexFormat, angleUnit, target); // Order terms, put under a common denominator if needed } -void Multiplication::addMissingFactors(Expression factor, Context & context, Preferences::AngleUnit angleUnit) { +void Multiplication::addMissingFactors(Expression factor, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { if (factor.type() == ExpressionNode::Type::Multiplication) { for (int j = 0; j < factor.numberOfChildren(); j++) { - addMissingFactors(factor.childAtIndex(j), context, angleUnit); + addMissingFactors(factor.childAtIndex(j), context, complexFormat, angleUnit); } return; } @@ -623,7 +623,7 @@ void Multiplication::addMissingFactors(Expression factor, Context & context, Pre * base if any. Otherwise, we add it as an new child. */ for (int i = 0; i < numberOfChildren(); i++) { if (TermsHaveIdenticalBase(childAtIndex(i), factor)) { - Expression sub = Subtraction(CreateExponent(childAtIndex(i)), CreateExponent(factor)).deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression sub = Subtraction(CreateExponent(childAtIndex(i)), CreateExponent(factor)).deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); if (sub.sign(&context) == ExpressionNode::Sign::Negative) { // index[0] < index[1] sub = Opposite(sub); if (factor.type() == ExpressionNode::Type::Power) { @@ -631,10 +631,10 @@ void Multiplication::addMissingFactors(Expression factor, Context & context, Pre } else { factor = Power(factor, sub); } - sub.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); - mergeInChildByFactorizingBase(i, factor, context, angleUnit, ExpressionNode::ReductionTarget::User); + sub.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); + mergeInChildByFactorizingBase(i, factor, context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); } else if (sub.sign(&context) == ExpressionNode::Sign::Unknown) { - mergeInChildByFactorizingBase(i, factor, context, angleUnit, ExpressionNode::ReductionTarget::User); + mergeInChildByFactorizingBase(i, factor, context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); } return; } @@ -644,7 +644,7 @@ void Multiplication::addMissingFactors(Expression factor, Context & context, Pre sortChildrenInPlace(ExpressionNode::SimplificationOrder, false); } -void Multiplication::factorizeSineAndCosine(int i, int j, Context & context, Preferences::AngleUnit angleUnit) { +void Multiplication::factorizeSineAndCosine(int i, int j, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { /* This function turn sin(x)^p * cos(x)^q into either: * - tan(x)^p*cos(x)^(p+q) if |p|<|q| * - tan(x)^(-q)*sin(x)^(p+q) otherwise */ @@ -667,19 +667,19 @@ void Multiplication::factorizeSineAndCosine(int i, int j, Context & context, Pre } else { replaceChildAtIndexInPlace(i, Power(tan, p)); } - childAtIndex(i).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + childAtIndex(i).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); // Replace cos(x)^q by cos(x)^(p+q) replaceChildAtIndexInPlace(j, Power(Base(childAtIndex(j)), sumPQ)); - childAtIndex(j).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + childAtIndex(j).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); } else { // Replace cos(x)^q by tan(x)^(-q) Expression newPower = Power(tan, Number::Multiplication(q, Rational(-1))); - newPower.childAtIndex(1).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + newPower.childAtIndex(1).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); replaceChildAtIndexInPlace(j, newPower); - newPower.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + newPower.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); // Replace sin(x)^p by sin(x)^(p+q) replaceChildAtIndexInPlace(i, Power(Base(childAtIndex(i)), sumPQ)); - childAtIndex(i).shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + childAtIndex(i).shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); } } @@ -730,7 +730,7 @@ bool Multiplication::TermHasNumeralExponent(const Expression & e) { return false; } -Expression Multiplication::mergeNegativePower(Context & context, Preferences::AngleUnit angleUnit) { +Expression Multiplication::mergeNegativePower(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { /* mergeNegativePower groups all factors that are power of form a^(-b) together * for instance, a^(-1)*b^(-c)*c = c*(a*b^c)^(-1) */ Multiplication m; @@ -749,7 +749,7 @@ Expression Multiplication::mergeNegativePower(Context & context, Preferences::An while (i < numberOfChildren()) { if (childAtIndex(i).type() == ExpressionNode::Type::Power) { Expression p = childAtIndex(i); - Expression positivePIndex = p.childAtIndex(1).makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression positivePIndex = p.childAtIndex(1).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); if (!positivePIndex.isUninitialized()) { // Remove a^(-b) from the Multiplication removeChildAtIndexInPlace(i); diff --git a/poincare/src/naperian_logarithm.cpp b/poincare/src/naperian_logarithm.cpp index 852476d02..351c359b6 100644 --- a/poincare/src/naperian_logarithm.cpp +++ b/poincare/src/naperian_logarithm.cpp @@ -18,13 +18,13 @@ int NaperianLogarithmNode::serialize(char * buffer, int bufferSize, Preferences: return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, NaperianLogarithm::s_functionHelper.name()); } -Expression NaperianLogarithmNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return NaperianLogarithm(this).shallowReduce(context, angleUnit, target); +Expression NaperianLogarithmNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return NaperianLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -36,7 +36,7 @@ Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::Angl #endif Logarithm l = Logarithm::Builder(childAtIndex(0), Constant(Ion::Charset::Exponential)); replaceWithInPlace(l); - return l.shallowReduce(context, angleUnit, target); + return l.shallowReduce(context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index f4cdca87b..303dadd48 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -28,8 +28,8 @@ int NthRootNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloa return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, NthRoot::s_functionHelper.name()); } -Expression NthRootNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return NthRoot(this).shallowReduce(context, angleUnit, target); +Expression NthRootNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return NthRoot(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -47,9 +47,9 @@ Evaluation NthRootNode::templatedApproximate(Context& context, Preferences::A return result; } -Expression NthRoot::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression NthRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -61,9 +61,9 @@ Expression NthRoot::shallowReduce(Context & context, Preferences::AngleUnit angl #endif Expression invIndex = Power(childAtIndex(1), Rational(-1)); Power p = Power(childAtIndex(0), invIndex); - invIndex.shallowReduce(context, angleUnit, target); + invIndex.shallowReduce(context, complexFormat, angleUnit, target); replaceWithInPlace(p); - return p.shallowReduce(context, angleUnit, target); + return p.shallowReduce(context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 5edd341fe..5b67ade67 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -62,16 +62,16 @@ int OppositeNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo return numberOfChar; } -Expression OppositeNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Opposite(this).shallowReduce(context, angleUnit, target); +Expression OppositeNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Opposite(this).shallowReduce(context, complexFormat, angleUnit, target); } /* Simplification */ Opposite::Opposite() : Expression(TreePool::sharedPool()->createTreeNode()) {} -Expression Opposite::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - Expression result = Expression::defaultShallowReduce(context, angleUnit); +Expression Opposite::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + Expression result = Expression::defaultShallowReduce(); if (result.isUndefined()) { return result; } @@ -80,7 +80,7 @@ Expression Opposite::shallowReduce(Context & context, Preferences::AngleUnit ang #endif result = Multiplication(Rational(-1), child); replaceWithInPlace(result); - return result.shallowReduce(context, angleUnit, target); + return result.shallowReduce(context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/parenthesis.cpp b/poincare/src/parenthesis.cpp index 32b5152b5..981879045 100644 --- a/poincare/src/parenthesis.cpp +++ b/poincare/src/parenthesis.cpp @@ -16,8 +16,8 @@ int ParenthesisNode::serialize(char * buffer, int bufferSize, Preferences::Print return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ""); } -Expression ParenthesisNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Parenthesis(this).shallowReduce(context, angleUnit); +Expression ParenthesisNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Parenthesis(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -25,8 +25,8 @@ Evaluation ParenthesisNode::templatedApproximate(Context& context, Preference return childAtIndex(0)->approximate(T(), context, angleUnit); } -Expression Parenthesis::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { - Expression e = Expression::defaultShallowReduce(context, angleUnit); +Expression Parenthesis::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/permute_coefficient.cpp b/poincare/src/permute_coefficient.cpp index 8970f23a0..4087c64cc 100644 --- a/poincare/src/permute_coefficient.cpp +++ b/poincare/src/permute_coefficient.cpp @@ -23,8 +23,8 @@ int PermuteCoefficientNode::serialize(char * buffer, int bufferSize, Preferences return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, PermuteCoefficient::s_functionHelper.name()); } -Expression PermuteCoefficientNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return PermuteCoefficient(this).shallowReduce(context, angleUnit); +Expression PermuteCoefficientNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return PermuteCoefficient(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -49,9 +49,9 @@ Evaluation PermuteCoefficientNode::templatedApproximate(Context& context, Pre return Complex(std::round(result)); } -Expression PermuteCoefficient::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression PermuteCoefficient::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 1baf6d147..0d69de5bb 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -47,8 +47,8 @@ ExpressionNode::Sign PowerNode::sign(Context * context) const { return Sign::Unknown; } -Expression PowerNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Power(this).setSign(s, context, angleUnit, target); +Expression PowerNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Power(this).setSign(s, context, complexFormat, angleUnit, target); } int PowerNode::polynomialDegree(Context & context, const char * symbolName) const { @@ -164,12 +164,12 @@ int PowerNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatM // Simplify -Expression PowerNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Power(this).shallowReduce(context, angleUnit, target); +Expression PowerNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Power(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression PowerNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Power(this).shallowBeautify(context, angleUnit); +Expression PowerNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Power(this).shallowBeautify(context, complexFormat, angleUnit); } int PowerNode::simplificationOrderGreaterType(const ExpressionNode * e, bool canBeInterrupted) const { @@ -191,8 +191,8 @@ int PowerNode::simplificationOrderSameType(const ExpressionNode * e, bool canBeI return SimplificationOrder(childAtIndex(1), e->childAtIndex(1), canBeInterrupted); } -Expression PowerNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const { - return Power(this).denominator(context, angleUnit); +Expression PowerNode::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { + return Power(this).denominator(context, complexFormat, angleUnit); } // Evaluation @@ -238,12 +238,12 @@ Power::Power(Expression base, Expression exponent) : Expression(TreePool::shared replaceChildAtIndexInPlace(1, exponent); } -Expression Power::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(s == ExpressionNode::Sign::Positive); if (childAtIndex(0).sign(context) == ExpressionNode::Sign::Negative) { - Expression result = Power(childAtIndex(0).setSign(ExpressionNode::Sign::Positive, context, angleUnit, target), childAtIndex(1)); + Expression result = Power(childAtIndex(0).setSign(ExpressionNode::Sign::Positive, context, complexFormat, angleUnit, target), childAtIndex(1)); replaceWithInPlace(result); - return result.shallowReduce(*context, angleUnit, target); + return result.shallowReduce(*context, complexFormat, angleUnit, target); } return *this; } @@ -279,10 +279,10 @@ int Power::getPolynomialCoefficients(Context & context, const char * symbolName, return -1; } -Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -304,8 +304,8 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU return replaceWith(new Undefined(), true); } if (exponent.isNegative()) { - childAtIndex(1)->setSign(Sign::Positive, context, angleUnit); - Expression * newMatrix = shallowReduce(context, angleUnit, target); + childAtIndex(1)->setSign(Sign::Positive, context, complexFormat, angleUnit); + Expression * newMatrix = shallowReduce(context, complexFormat, angleUnit, target); Expression * parent = newMatrix->parent(); MatrixInverse * inv = new MatrixInverse(newMatrix, false); parent->replaceOperand(newMatrix, inv, false); @@ -325,7 +325,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU result->addOperand(mat->clone()); } replaceWith(result, true); - return result->shallowReduce(context, angleUnit, target); + return result->shallowReduce(context, complexFormat, angleUnit, target); } #endif #endif @@ -420,25 +420,25 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU Rational r = static_cast(index); if (r.isMinusOne()) { // (x+iy)^(-1) - result = complexBase.inverse(context, angleUnit, target); + result = complexBase.inverse(context, complexFormat, angleUnit, target); } else if (r.isHalf()) { // (x+iy)^(1/2) - result = complexBase.squareRoot(context, angleUnit, target); + result = complexBase.squareRoot(context, complexFormat, angleUnit, target); } else if (r.isMinusHalf()) { // (x+iy)^(-1/2) - result = complexBase.squareRoot(context, angleUnit, target).inverse(context, angleUnit, target); + result = complexBase.squareRoot(context, complexFormat, angleUnit, target).inverse(context, complexFormat, angleUnit, target); } 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, angleUnit, target); + result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, complexFormat, angleUnit, target); } else { // (x+iy)^(-n), n integer positive n < 10 - result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, angleUnit, target).inverse(context, angleUnit, target); + result = complexBase.powerInteger(r.unsignedIntegerNumerator().extractedInt(), context, complexFormat, angleUnit, target).inverse(context, complexFormat, angleUnit, target); } } if (!result.isUninitialized()) { replaceWithInPlace(result); - return result.shallowReduce(context, angleUnit); + return result.shallowReduce(context, complexFormat, angleUnit); } } } @@ -448,15 +448,15 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU (!letPowerAtRoot && base.type() == ExpressionNode::Type::ComplexCartesian && index.type() == ExpressionNode::Type::ComplexCartesian)) { complexBase = base.type() == ExpressionNode::Type::ComplexCartesian ? static_cast(base) : ComplexCartesian::Builder(base, Rational(0)); complexIndex = index.type() == ExpressionNode::Type::ComplexCartesian ? static_cast(index) : ComplexCartesian::Builder(index, Rational(0)); - result = complexBase.power(complexIndex, context, angleUnit, target); + result = complexBase.power(complexIndex, context, complexFormat, angleUnit, target); replaceWithInPlace(result); - return result.shallowReduce(context, angleUnit); + return result.shallowReduce(context, complexFormat, angleUnit); } /* 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, angleUnit); + Expression r = removeSquareRootsFromDenominator(context, complexFormat, angleUnit); if (!r.isUninitialized()) { return r; } @@ -468,9 +468,9 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU // i^(p/q) if (childAtIndex(0).type() == ExpressionNode::Type::Constant && childAtIndex(0).convert().isIComplex()) { Number r = Number::Multiplication(b, Rational(1, 2)); - Expression result = CreateComplexExponent(r, context, angleUnit, target); + Expression result = CreateComplexExponent(r, context, complexFormat, angleUnit, target); replaceWithInPlace(result); - return result.shallowReduce(context, angleUnit, target); + return result.shallowReduce(context, complexFormat, angleUnit, target); } } @@ -487,12 +487,12 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU // (-inf)^x --> (-1)^x*inf Power p(Rational(-1), childAtIndex(1)); result = Multiplication(p, result); - p.shallowReduce(context, angleUnit, target); + p.shallowReduce(context, complexFormat, angleUnit, target); } } if (!result.isUninitialized()) { replaceWithInPlace(result); - return result.shallowReduce(context, angleUnit, target); + return result.shallowReduce(context, complexFormat, angleUnit, target); } } @@ -506,7 +506,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU if (RationalExponentShouldNotBeReduced(a, exp)) { return *this; } - return simplifyRationalRationalPower(context, angleUnit, target); + return simplifyRationalRationalPower(context, complexFormat, angleUnit, target); } } // Step 7: (a)^(1/2) with a < 0 --> i*(-a)^(1/2) @@ -516,7 +516,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU && childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().isHalf()) { - Expression m0 = childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, angleUnit, target); + Expression m0 = childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target); if (!m0.isUninitialized()) { replaceChildAtIndexInPlace(0, m0); // m0 doest not need to be shallowReduce as makePositiveAnyNegativeNumeralFactor returns a reduced expression @@ -525,10 +525,10 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU // Multiply m1 by i complex Constant i(Ion::Charset::IComplex); m1.addChildAtIndexInPlace(i, 0, 0); - i.shallowReduce(context, angleUnit, target); + i.shallowReduce(context, complexFormat, angleUnit, target); m1.addChildAtIndexInPlace(*this, 1, 1); - shallowReduce(context, angleUnit, target); - return m1.shallowReduce(context, angleUnit, target); + shallowReduce(context, complexFormat, angleUnit, target); + return m1.shallowReduce(context, complexFormat, angleUnit, target); } } // Step 8: e^(i*Pi*r) with r rational --> cos(pi*r) + i*sin(pi*r) @@ -540,15 +540,15 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU m.replaceChildAtIndexInPlace(m.numberOfChildren()-1, Rational(180)); } Expression cos = Cosine::Builder(m); - m = m.shallowReduce(context, angleUnit, target); + m = m.shallowReduce(context, complexFormat, angleUnit, target); Expression sin = Sine::Builder(m.clone()); Expression complexPart = Multiplication(sin, i); - sin.shallowReduce(context, angleUnit, target); + sin.shallowReduce(context, complexFormat, angleUnit, target); Expression a = Addition(cos, complexPart); - cos.shallowReduce(context, angleUnit, target); - complexPart.shallowReduce(context, angleUnit, target); + cos.shallowReduce(context, complexFormat, angleUnit, target); + complexPart.shallowReduce(context, complexFormat, angleUnit, target); replaceWithInPlace(a); - return a.shallowReduce(context, angleUnit, target); + return a.shallowReduce(context, complexFormat, angleUnit, target); } // Step 9: x^log(y,x)->y if y > 0 if (childAtIndex(1).type() == ExpressionNode::Type::Logarithm) { @@ -578,7 +578,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU || (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().integerDenominator().isOne())) { - return simplifyPowerPower(context, angleUnit, target); + return simplifyPowerPower(context, complexFormat, angleUnit, target); } } // Step 11: (a*b*c*...)^r ? @@ -586,7 +586,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU 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, angleUnit, target); + return simplifyPowerMultiplication(context, complexFormat, angleUnit, target); } // Case 2: (a*b*...)^r -> |a|^r*(sign(a)*b*...)^r if a not -1 for (int i = 0; i < m.numberOfChildren(); i++) { @@ -602,11 +602,11 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU // (sign(a)*b*...)^r if (factor.sign(&context) == ExpressionNode::Sign::Negative) { m.replaceChildAtIndexInPlace(i, Rational(-1)); - factor = factor.setSign(ExpressionNode::Sign::Positive, &context, angleUnit, target); + factor = factor.setSign(ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target); } else { m.removeChildAtIndexInPlace(i); } - m.shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); // |a|^r Power p = Power(factor, rCopy); @@ -616,9 +616,9 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU Multiplication root = Multiplication(p); replaceWithInPlace(root); root.addChildAtIndexInPlace(thisRef, 1, 1); - p.shallowReduce(context, angleUnit, target); - thisRef.shallowReduce(context, angleUnit, target); - return root.shallowReduce(context, angleUnit, target); + p.shallowReduce(context, complexFormat, angleUnit, target); + thisRef.shallowReduce(context, complexFormat, angleUnit, target); + return root.shallowReduce(context, complexFormat, angleUnit, target); } } } @@ -644,8 +644,8 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU Multiplication m = Multiplication(p1); replaceWithInPlace(m); m.addChildAtIndexInPlace(thisRef, 1, 1); - p1.simplifyRationalRationalPower(context, angleUnit, target); - return m.shallowReduce(context, angleUnit, target); + p1.simplifyRationalRationalPower(context, complexFormat, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } } @@ -681,28 +681,28 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU // We need a 'double' distribution and newA will hold the new expanded form Expression newA = Addition(); for (int j = 0; j < a.numberOfChildren(); j++) { - Expression m = Multiplication(result.clone(), a.childAtIndex(j).clone()).distributeOnOperandAtIndex(0, context, angleUnit, target); + Expression m = Multiplication(result.clone(), a.childAtIndex(j).clone()).distributeOnOperandAtIndex(0, context, complexFormat, angleUnit, target); if (newA.type() == ExpressionNode::Type::Addition) { static_cast(newA).addChildAtIndexInPlace(m, newA.numberOfChildren(), newA.numberOfChildren()); } else { newA = Addition(newA, m); } - newA = newA.shallowReduce(context, angleUnit, target); + newA = newA.shallowReduce(context, complexFormat, angleUnit, target); } result.replaceWithInPlace(newA); result = newA; } else { // Just distribute result on a Multiplication m = Multiplication(a.clone(), result.clone()); - Expression distributedM = m.distributeOnOperandAtIndex(0, context, angleUnit, target); + Expression distributedM = m.distributeOnOperandAtIndex(0, context, complexFormat, angleUnit, target); result.replaceWithInPlace(distributedM); result = distributedM; - result = result.shallowReduce(context, angleUnit, target); + result = result.shallowReduce(context, complexFormat, angleUnit, target); } } if (nr.sign() == ExpressionNode::Sign::Negative) { nr.replaceWithInPlace(Rational(-1)); - return shallowReduce(context, angleUnit, target); + return shallowReduce(context, complexFormat, angleUnit, target); } else { replaceWithInPlace(result); return result; @@ -729,32 +729,32 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU Power * p1 = new Power(x1->clone(), new Rational(clippedN-i), false); const Expression * operands[3] = {r, p0, p1}; Multiplication * m = new Multiplication(operands, 3, false); - p0->shallowReduce(context, angleUnit, target); - p1->shallowReduce(context, angleUnit, target); + p0->shallowReduce(context, complexFormat, angleUnit, target); + p1->shallowReduce(context, complexFormat, angleUnit, target); a->addOperand(m); - m->shallowReduce(context, angleUnit, target); + m->shallowReduce(context, complexFormat, angleUnit, target); } if (nr->sign(&context) == Sign::Negative) { nr->replaceWith(new Rational(-1), true); - childAtIndex(0)->replaceWith(a, true)->shallowReduce(context, angleUnit, target); - return shallowReduce(context, angleUnit, target); + childAtIndex(0)->replaceWith(a, true)->shallowReduce(context, complexFormat, angleUnit, target); + return shallowReduce(context, complexFormat, angleUnit, target); } else { - return replaceWith(a, true)->shallowReduce(context, angleUnit, target); + return replaceWith(a, true)->shallowReduce(context, complexFormat, angleUnit, target); } } #endif return *this; } -Expression Power::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Power::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { // Step 1: X^-y -> 1/(X->shallowBeautify)^y - Expression p = denominator(context, angleUnit); + Expression p = denominator(context, complexFormat, angleUnit); // If the denominator is initialized, the index of the power is of form -y if (!p.isUninitialized()) { Division d = Division(Rational(1), p); - p.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + p.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); replaceWithInPlace(d); - return d.shallowBeautify(context, angleUnit); + return d.shallowBeautify(context, complexFormat, angleUnit); } // Step 2: Turn a^(1/n) into root(a, n) if (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().signedIntegerNumerator().isOne()) { @@ -783,11 +783,11 @@ Expression Power::shallowBeautify(Context & context, Preferences::AngleUnit angl // Private // Simplification -Expression Power::denominator(Context & context, Preferences::AngleUnit angleUnit) const { +Expression Power::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { // Clone the power Expression clone = Power(childAtIndex(0).clone(), childAtIndex(1).clone()); // If the power is of form x^(-y), denominator should be x^y - Expression positiveIndex = clone.childAtIndex(1).makePositiveAnyNegativeNumeralFactor(context, angleUnit, ExpressionNode::ReductionTarget::User); + Expression positiveIndex = clone.childAtIndex(1).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); if (!positiveIndex.isUninitialized()) { // if y was -1, clone is now x^1, denominator is then only x // we cannot shallowReduce the clone as it is not attached to its parent yet @@ -799,30 +799,30 @@ Expression Power::denominator(Context & context, Preferences::AngleUnit angleUni return Expression(); } -Expression Power::simplifyPowerPower(Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::simplifyPowerPower(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { // this is p^e = (a^b)^e, we want a^(b*e) Expression p = childAtIndex(0); Multiplication m(p.childAtIndex(1), childAtIndex(1)); replaceChildAtIndexInPlace(0, p.childAtIndex(0)); replaceChildAtIndexInPlace(1, m); - m.shallowReduce(context, angleUnit, target); - return shallowReduce(context, angleUnit, target); + m.shallowReduce(context, complexFormat, angleUnit, target); + return shallowReduce(context, complexFormat, angleUnit, target); } -Expression Power::simplifyPowerMultiplication(Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::simplifyPowerMultiplication(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { // 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(m.childAtIndex(index).clone(), r.clone()); // We copy r and factor to avoid inheritance issues m.replaceChildAtIndexInPlace(index, p); - p.shallowReduce(context, angleUnit, target); + p.shallowReduce(context, complexFormat, angleUnit, target); } replaceWithInPlace(m); - return m.shallowReduce(context, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } -Expression Power::simplifyRationalRationalPower(Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::simplifyRationalRationalPower(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { // this is a^b with a, b rationals Rational a = childAtIndex(0).convert(); Rational b = childAtIndex(1).convert(); @@ -838,18 +838,18 @@ Expression Power::simplifyRationalRationalPower(Context& context, Preferences::A Expression d; if (b.sign() == ExpressionNode::Sign::Negative) { b.setSign(ExpressionNode::Sign::Positive); - n = CreateSimplifiedIntegerRationalPower(a.integerDenominator(), b, false, context, angleUnit, target); - d = CreateSimplifiedIntegerRationalPower(a.signedIntegerNumerator(), b, true, context, angleUnit, target); + n = CreateSimplifiedIntegerRationalPower(a.integerDenominator(), b, false, context, complexFormat, angleUnit, target); + d = CreateSimplifiedIntegerRationalPower(a.signedIntegerNumerator(), b, true, context, complexFormat, angleUnit, target); } else { - n = CreateSimplifiedIntegerRationalPower(a.signedIntegerNumerator(), b, false, context, angleUnit, target); - d = CreateSimplifiedIntegerRationalPower(a.integerDenominator(), b, true, context, angleUnit, target); + n = CreateSimplifiedIntegerRationalPower(a.signedIntegerNumerator(), b, false, context, complexFormat, angleUnit, target); + d = CreateSimplifiedIntegerRationalPower(a.integerDenominator(), b, true, context, complexFormat, angleUnit, target); } Multiplication m = Multiplication(n, d); replaceWithInPlace(m); - return m.shallowReduce(context, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } -Expression Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bool isDenominator, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bool isDenominator, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(!i.isZero()); assert(r.sign() == ExpressionNode::Sign::Positive); if (i.isOne()) { @@ -861,7 +861,7 @@ Expression Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bo if (numberOfPrimeFactors < 0) { /* We could not break i in prime factors (it might take either too many * factors or too much time). */ - Expression rClone = r.clone().setSign(isDenominator ? ExpressionNode::Sign::Negative : ExpressionNode::Sign::Positive, &context, angleUnit, target); + Expression rClone = r.clone().setSign(isDenominator ? ExpressionNode::Sign::Negative : ExpressionNode::Sign::Positive, &context, complexFormat, angleUnit, target); return Power(Rational(i), rClone); } @@ -893,15 +893,15 @@ Expression Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bo m.addChildAtIndexInPlace(p, 1, 1); } if (i.isNegative()) { - Expression exp = CreateComplexExponent(r, context, angleUnit, target); + Expression exp = CreateComplexExponent(r, context, complexFormat, angleUnit, target); m.addChildAtIndexInPlace(exp, m.numberOfChildren(), m.numberOfChildren()); - exp.shallowReduce(context, angleUnit, target); + exp.shallowReduce(context, complexFormat, angleUnit, target); } m.sortChildrenInPlace(PowerNode::SimplificationOrder, false); return m; } -Expression Power::removeSquareRootsFromDenominator(Context & context, Preferences::AngleUnit angleUnit) { +Expression Power::removeSquareRootsFromDenominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression result; if (childAtIndex(0).type() == ExpressionNode::Type::Rational && childAtIndex(1).type() == ExpressionNode::Type::Rational @@ -928,7 +928,7 @@ Expression Power::removeSquareRootsFromDenominator(Context & context, Preference } else { result = Multiplication(Rational(one, p), sqrt); // We use here the assertion that p != 0 } - sqrt.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + sqrt.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); } } else if (childAtIndex(1).type() == ExpressionNode::Type::Rational && childAtIndex(1).convert().isMinusOne() @@ -996,14 +996,14 @@ Expression Power::removeSquareRootsFromDenominator(Context & context, Preference if (denominator.isInfinity() || factor1.isInfinity() || factor2.isInfinity() || pq1.isInfinity() || pq2.isInfinity()) { return result; // Escape } - numerator = numerator.deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + numerator = numerator.deepReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); Integer one(1); result = Multiplication(numerator, Rational(one, denominator)); } if (!result.isUninitialized()) { replaceWithInPlace(result); - result = result.shallowReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + result = result.shallowReduce(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User); } return result; } @@ -1079,22 +1079,22 @@ Expression Power::equivalentExpressionUsingStandardExpression() const { return Expression(); } -Expression Power::CreateComplexExponent(const Expression & r, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Power::CreateComplexExponent(const Expression & r, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { // Returns e^(i*pi*r) const Constant exp = Constant(Ion::Charset::Exponential); Constant iComplex = Constant(Ion::Charset::IComplex); const Constant pi = Constant(Ion::Charset::SmallPi); Multiplication mExp = Multiplication(iComplex, pi, r.clone()); - iComplex.shallowReduce(context, angleUnit, target); + iComplex.shallowReduce(context, complexFormat, angleUnit, target); Power p(exp, mExp); - mExp.shallowReduce(context, angleUnit, target); + mExp.shallowReduce(context, complexFormat, angleUnit, target); return p; #if 0 const Constant iComplex = Constant(Ion::Charset::IComplex); const Constant pi = Constant(Ion::Charset::SmallPi); - Expression op = Multiplication(pi, r).shallowReduce(context, angleUnit, false); - Cosine cos = Cosine(op).shallowReduce(context, angleUnit, false);; - Sine sin = Sine(op).shallowReduce(context, angleUnit, false); + Expression op = Multiplication(pi, r).shallowReduce(context, complexFormat, angleUnit, false); + Cosine cos = Cosine(op).shallowReduce(context, complexFormat, angleUnit, false);; + Sine sin = Sine(op).shallowReduce(context, complexFormat, angleUnit, false); Expression m = Multiplication(iComplex, sin); Expression a = Addition(cos, m); const Expression * multExpOperands[3] = {pi, r->clone()}; diff --git a/poincare/src/prediction_interval.cpp b/poincare/src/prediction_interval.cpp index 8f0a659b3..a294a5640 100644 --- a/poincare/src/prediction_interval.cpp +++ b/poincare/src/prediction_interval.cpp @@ -27,8 +27,8 @@ int PredictionIntervalNode::serialize(char * buffer, int bufferSize, Preferences } -Expression PredictionIntervalNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return PredictionInterval(this).shallowReduce(context, angleUnit, target); +Expression PredictionIntervalNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return PredictionInterval(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -46,9 +46,9 @@ Evaluation PredictionIntervalNode::templatedApproximate(Context& context, Pre return MatrixComplex(operands, 1, 2); } -Expression PredictionInterval::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression PredictionInterval::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -102,7 +102,7 @@ Expression PredictionInterval::shallowReduce(Context & context, Preferences::Ang matrix.addChildAtIndexInPlace(Addition(r0.clone(), m), 1, 1); matrix.setDimensions(1, 2); replaceWithInPlace(matrix); - matrix.deepReduceChildren(context, angleUnit, target); + matrix.deepReduceChildren(context, complexFormat, angleUnit, target); return matrix; } diff --git a/poincare/src/random.cpp b/poincare/src/random.cpp index 11a959e01..737082864 100644 --- a/poincare/src/random.cpp +++ b/poincare/src/random.cpp @@ -12,8 +12,8 @@ constexpr Expression::FunctionHelper Random::s_functionHelper; int RandomNode::numberOfChildren() const { return Random::s_functionHelper.numberOfChildren(); } -Expression RandomNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Random(this).setSign(s, context, angleUnit); +Expression RandomNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Random(this).setSign(s, context, complexFormat, angleUnit); } Layout RandomNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -28,7 +28,7 @@ template Evaluation RandomNode::templateApproximate() const { return Complex(Random::random()); } -Expression Random::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit) { +Expression Random::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(s == ExpressionNode::Sign::Positive); return *this; } diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index 48fb40659..ae11ffcaf 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -98,7 +98,7 @@ int RationalNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo // Expression subclassing -Expression RationalNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression RationalNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { return Rational(this).setSign(s); } @@ -143,16 +143,16 @@ int RationalNode::simplificationOrderSameType(const ExpressionNode * e, bool can // Simplification -Expression RationalNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Rational(this).shallowReduce(context, angleUnit); +Expression RationalNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Rational(this).shallowReduce(context, complexFormat, angleUnit); } -Expression RationalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - return Rational(this).shallowBeautify(context, angleUnit); +Expression RationalNode::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + return Rational(this).shallowBeautify(context, complexFormat, angleUnit); } -Expression RationalNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const { - return Rational(this).denominator(context, angleUnit); +Expression RationalNode::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { + return Rational(this).denominator(context, complexFormat, angleUnit); } /* Rational */ @@ -233,7 +233,7 @@ Rational::Rational(const native_uint_t * i, uint8_t numeratorSize, const native_ static_cast(node())->setDigits(i, numeratorSize, j, denominatorSize, negative); } -Expression Rational::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Rational::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { // FIXME: /* Infinite Rational should not exist as they aren't parsed and are supposed * to be turn in Float if they should appear. We assert(false) so far, but @@ -259,7 +259,7 @@ Expression Rational::shallowReduce(Context & context, Preferences::AngleUnit ang return *this; } -Expression Rational::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { +Expression Rational::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { if (sign() == ExpressionNode::Sign::Negative) { Expression abs = setSign(ExpressionNode::Sign::Positive); Opposite o; @@ -270,7 +270,7 @@ Expression Rational::shallowBeautify(Context & context, Preferences::AngleUnit a return *this; } -Expression Rational::denominator(Context & context, Preferences::AngleUnit angleUnit) const { +Expression Rational::denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { Integer d = integerDenominator(); if (d.isOne()) { return Expression(); diff --git a/poincare/src/real_part.cpp b/poincare/src/real_part.cpp index 0458f0038..4d5e58c7e 100644 --- a/poincare/src/real_part.cpp +++ b/poincare/src/real_part.cpp @@ -20,13 +20,13 @@ int RealPartNode::serialize(char * buffer, int bufferSize, Preferences::PrintFlo return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, RealPart::s_functionHelper.name()); } -Expression RealPartNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return RealPart(this).shallowReduce(context, angleUnit, target); +Expression RealPartNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return RealPart(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression RealPart::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression RealPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -45,7 +45,7 @@ Expression RealPart::shallowReduce(Context & context, Preferences::AngleUnit ang ComplexCartesian complexChild = static_cast(c); Expression r = complexChild.real(); replaceWithInPlace(r); - return r.shallowReduce(context, angleUnit, target); + return r.shallowReduce(context, complexFormat, angleUnit, target); } return *this; } diff --git a/poincare/src/round.cpp b/poincare/src/round.cpp index eea75450a..d6f105ae6 100644 --- a/poincare/src/round.cpp +++ b/poincare/src/round.cpp @@ -21,8 +21,8 @@ int RoundNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatM return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Round::s_functionHelper.name()); } -Expression RoundNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Round(this).shallowReduce(context, angleUnit); +Expression RoundNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Round(this).shallowReduce(context, complexFormat, angleUnit); } template @@ -38,9 +38,9 @@ Evaluation RoundNode::templatedApproximate(Context& context, Preferences::Ang return Complex(std::round(f1*err)/err); } -Expression Round::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Round::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } diff --git a/poincare/src/sign_function.cpp b/poincare/src/sign_function.cpp index 88867021c..ce7bd9868 100644 --- a/poincare/src/sign_function.cpp +++ b/poincare/src/sign_function.cpp @@ -17,7 +17,7 @@ ExpressionNode::Sign SignFunctionNode::sign(Context * context) const { return childAtIndex(0)->sign(context); } -Expression SignFunctionNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression SignFunctionNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { SignFunction sign(this); Rational r(s == ExpressionNode::Sign::Positive ? 1 : -1); sign.replaceWithInPlace(r); @@ -32,8 +32,8 @@ int SignFunctionNode::serialize(char * buffer, int bufferSize, Preferences::Prin return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SignFunction::s_functionHelper.name()); } -Expression SignFunctionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return SignFunction(this).shallowReduce(context, angleUnit, target); +Expression SignFunctionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return SignFunction(this).shallowReduce(context, complexFormat, angleUnit, target); } template @@ -47,9 +47,9 @@ Complex SignFunctionNode::computeOnComplex(const std::complex c, Preferenc return Complex(1.0); } -Expression SignFunction::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression SignFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -73,7 +73,7 @@ Expression SignFunction::shallowReduce(Context & context, Preferences::AngleUnit // c has no sign (c is complex or NAN) if (std::isnan(c.imag()) || std::isnan(c.real()) || c.imag() != 0) { // sign(-x) = -sign(x) - Expression oppChild = child.makePositiveAnyNegativeNumeralFactor(context, angleUnit, target); + Expression oppChild = child.makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target); if (oppChild.isUninitialized()) { return *this; } else { diff --git a/poincare/src/simplification_helper.cpp b/poincare/src/simplification_helper.cpp index 3afadd465..ce828c6a4 100644 --- a/poincare/src/simplification_helper.cpp +++ b/poincare/src/simplification_helper.cpp @@ -4,17 +4,17 @@ namespace Poincare { // TODO Use clones -Expression SimplificationHelper::Map(const Expression & e, Context & context, Preferences::AngleUnit angleUnit) { +Expression SimplificationHelper::Map(const Expression & e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(e->numberOfChildren() == 1 && e->childAtIndex(0)->type() == ExpressionNode::Type::Matrix); Expression c = e.childAtIndex(0); Matrix matrix; 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, angleUnit); + f.shallowReduce(context, complexFormat, angleUnit); } replaceWithInPlace(matrix); - return matrix.shallowReduce(context, angleUnit); + return matrix.shallowReduce(context, complexFormat, angleUnit); } } diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index e34607158..a04bd527f 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -30,13 +30,13 @@ int SineNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMo return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, Sine::s_functionHelper.name()); } -Expression SineNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Sine(this).shallowReduce(context, angleUnit, target); +Expression SineNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Sine(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression Sine::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Sine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -47,7 +47,7 @@ Expression Sine::shallowReduce(Context & context, Preferences::AngleUnit angleUn return SimplificationHelper::Map(*this, context, angleUnit); } #endif - return Trigonometry::shallowReduceDirectFunction(*this, context, angleUnit, target); + return Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 53f7379fd..253f473b4 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -38,13 +38,13 @@ Complex SquareRootNode::computeOnComplex(const std::complex c, Preferences return Complex(ApproximationHelper::TruncateRealOrImaginaryPartAccordingToArgument(result)); } -Expression SquareRootNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return SquareRoot(this).shallowReduce(context, angleUnit, target); +Expression SquareRootNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return SquareRoot(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression SquareRoot::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression SquareRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -56,7 +56,7 @@ Expression SquareRoot::shallowReduce(Context & context, Preferences::AngleUnit a #endif Power p = Power(childAtIndex(0), Rational(1, 2)); replaceWithInPlace(p); - return p.shallowReduce(context, angleUnit, target); + return p.shallowReduce(context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index 3aa3f341d..afac6fd1f 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -15,12 +15,12 @@ extern "C" { namespace Poincare { -void StoreNode::deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +void StoreNode::deepReduceChildren(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { return; } -Expression StoreNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Store(this).shallowReduce(context, angleUnit); +Expression StoreNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Store(this).shallowReduce(context, complexFormat, angleUnit); } int StoreNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { @@ -50,7 +50,7 @@ Evaluation StoreNode::templatedApproximate(Context& context, Preferences::Ang return e.approximateToEvaluation(context, angleUnit); } -Expression Store::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Store::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression finalValue; if (symbol().type() == ExpressionNode::Type::Function) { // In tata + 2 ->f(tata), replace tata with xUnknown symbol diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index f6ce7a4f6..3e410f31d 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -52,22 +52,22 @@ template MatrixComplex SubtractionNode::computeOnComplexAndMatrix return result; } -Expression SubtractionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Subtraction(this).shallowReduce(context, angleUnit, target); +Expression SubtractionNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Subtraction(this).shallowReduce(context, complexFormat, angleUnit, target); } Subtraction::Subtraction() : Expression(TreePool::sharedPool()->createTreeNode()) {} -Expression Subtraction::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { - Expression e = Expression::defaultShallowReduce(context, angleUnit); +Expression Subtraction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } Expression m = Multiplication(Rational(-1), childAtIndex(1)); Addition a(childAtIndex(0), m); - m = m.shallowReduce(context, angleUnit, target); + m = m.shallowReduce(context, complexFormat, angleUnit, target); replaceWithInPlace(a); - return a.shallowReduce(context, angleUnit, target); + return a.shallowReduce(context, complexFormat, angleUnit, target); } } diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 7fe6e3e06..8a83647a1 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -117,8 +117,8 @@ int SymbolNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat return strlcpy(buffer, m_name, bufferSize); } -Expression SymbolNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Symbol(this).shallowReduce(context, angleUnit, target); +Expression SymbolNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Symbol(this).shallowReduce(context, complexFormat, angleUnit, target); } Expression SymbolNode::shallowReplaceReplaceableSymbols(Context & context) { @@ -157,7 +157,7 @@ bool Symbol::isRegressionSymbol(const char * c) { return false; } -Expression Symbol::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Symbol::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Symbol s = *this; Expression result = SymbolAbstract::Expand(s, context, true); if (result.isUninitialized()) { @@ -165,7 +165,7 @@ Expression Symbol::shallowReduce(Context & context, Preferences::AngleUnit angle } replaceWithInPlace(result); // The stored expression is as entered by the user, so we need to call reduce - return result.deepReduce(context, angleUnit, target); + return result.deepReduce(context, complexFormat, angleUnit, target); } Expression Symbol::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) { diff --git a/poincare/src/symbol_abstract.cpp b/poincare/src/symbol_abstract.cpp index 91eedcf46..2fd65125b 100644 --- a/poincare/src/symbol_abstract.cpp +++ b/poincare/src/symbol_abstract.cpp @@ -37,12 +37,12 @@ ExpressionNode::Sign SymbolAbstractNode::sign(Context * context) const { return e.sign(context); } -Expression SymbolAbstractNode::setSign(ExpressionNode::Sign s, Context * context, Preferences::AngleUnit angleUnit, ReductionTarget target) { +Expression SymbolAbstractNode::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { SymbolAbstract sa(this); Expression e = SymbolAbstract::Expand(sa, *context, true); assert(!e.isUninitialized()); sa.replaceWithInPlace(e); - return e.setSign(s, context, angleUnit, target); + return e.setSign(s, context, complexFormat, angleUnit, target); } int SymbolAbstractNode::simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const { diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index dceb282df..01e342b50 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -33,13 +33,13 @@ Complex TangentNode::computeOnComplex(const std::complex c, Preferences::A return Complex(Trigonometry::RoundToMeaningfulDigits(res, angleInput)); } -Expression TangentNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ReductionTarget target) { - return Tangent(this).shallowReduce(context, angleUnit, target); +Expression TangentNode::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ReductionTarget target) { + return Tangent(this).shallowReduce(context, complexFormat, angleUnit, target); } -Expression Tangent::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Tangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { - Expression e = Expression::defaultShallowReduce(context, angleUnit); + Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { return e; } @@ -50,15 +50,15 @@ Expression Tangent::shallowReduce(Context & context, Preferences::AngleUnit angl return SimplificationHelper::Map(*this, context, angleUnit); } #endif - Expression newExpression = Trigonometry::shallowReduceDirectFunction(*this, context, angleUnit, target); + Expression newExpression = Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); if (newExpression.type() == ExpressionNode::Type::Tangent) { Sine s = Sine::Builder(newExpression.childAtIndex(0).clone()); Cosine c = Cosine::Builder(newExpression.childAtIndex(0)); Division d = Division(s, c); - s.shallowReduce(context, angleUnit, target); - c.shallowReduce(context, angleUnit, target); + s.shallowReduce(context, complexFormat, angleUnit, target); + c.shallowReduce(context, complexFormat, angleUnit, target); newExpression.replaceWithInPlace(d); - return d.shallowReduce(context, angleUnit, target); + return d.shallowReduce(context, complexFormat, angleUnit, target); } return newExpression; } diff --git a/poincare/src/trigonometry.cpp b/poincare/src/trigonometry.cpp index 06c14476f..92622c91c 100644 --- a/poincare/src/trigonometry.cpp +++ b/poincare/src/trigonometry.cpp @@ -83,11 +83,11 @@ bool Trigonometry::ExpressionIsEquivalentToTangent(const Expression & e) { return false; } -Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(isDirectTrigonometryFunction(e)); // Step 1. Try finding an easy standard calculation reduction - Expression lookup = Trigonometry::table(e.childAtIndex(0), e.type(), context, angleUnit, target); + Expression lookup = Trigonometry::table(e.childAtIndex(0), e.type(), context, complexFormat, angleUnit, target); if (!lookup.isUninitialized()) { e.replaceWithInPlace(lookup); return lookup; @@ -115,14 +115,14 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& co Rational(1,2) ); // reduce x^2 - sqrt.childAtIndex(0).childAtIndex(1).childAtIndex(1).shallowReduce(context, angleUnit, target); + sqrt.childAtIndex(0).childAtIndex(1).childAtIndex(1).shallowReduce(context, complexFormat, angleUnit, target); // reduce -1*x^2 - sqrt.childAtIndex(0).childAtIndex(1).shallowReduce(context, angleUnit, target); + sqrt.childAtIndex(0).childAtIndex(1).shallowReduce(context, complexFormat, angleUnit, target); // reduce 1-1*x^2 - sqrt.childAtIndex(0).shallowReduce(context, angleUnit, target); + sqrt.childAtIndex(0).shallowReduce(context, complexFormat, angleUnit, target); e.replaceWithInPlace(sqrt); // reduce sqrt(1+(-1)*x^2) - return sqrt.shallowReduce(context, angleUnit, target); + return sqrt.shallowReduce(context, complexFormat, angleUnit, target); } // Step 4. Look for an expression of type "cos(arctan(x))" or "sin(arctan(x))" @@ -144,33 +144,33 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& co ); // reduce x^2 - res.childAtIndex(0).childAtIndex(1).shallowReduce(context, angleUnit, target); + res.childAtIndex(0).childAtIndex(1).shallowReduce(context, complexFormat, angleUnit, target); // reduce 1+*x^2 - res.childAtIndex(0).shallowReduce(context, angleUnit, target); + res.childAtIndex(0).shallowReduce(context, complexFormat, angleUnit, target); if (e.type() == ExpressionNode::Type::Sine) { res = Multiplication(x, res); // reduce (1+x^2)^(-1/2) - res.childAtIndex(0).shallowReduce(context, angleUnit, target); + res.childAtIndex(0).shallowReduce(context, complexFormat, angleUnit, target); } e.replaceWithInPlace(res); // reduce (1+x^2)^(-1/2) or x*(1+x^2)^(-1/2) - return res.shallowReduce(context, angleUnit, target); + return res.shallowReduce(context, complexFormat, angleUnit, target); } // Step 5. Look for an expression of type "cos(-a)", return "+/-cos(a)" - Expression positiveArg = e.childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, angleUnit, target); + Expression positiveArg = e.childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target); if (!positiveArg.isUninitialized()) { // The argument was of form cos(-a) if (e.type() == ExpressionNode::Type::Cosine) { // cos(-a) = cos(a) - return e.shallowReduce(context, angleUnit, target); + return e.shallowReduce(context, complexFormat, angleUnit, target); } else { // sin(-a) = -sin(a) or tan(-a) = -tan(a) Multiplication m(Rational(-1)); e.replaceWithInPlace(m); m.addChildAtIndexInPlace(e, 1, 1); - e.shallowReduce(context, angleUnit, target); - return m.shallowReduce(context, angleUnit, target); + e.shallowReduce(context, complexFormat, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } } @@ -222,27 +222,27 @@ Expression Trigonometry::shallowReduceDirectFunction(Expression & e, Context& co Expression newR = Rational(div.remainder, rDenominator); Expression rationalParent = angleUnit == Preferences::AngleUnit::Radian ? e.childAtIndex(0) : e; rationalParent.replaceChildAtIndexInPlace(0, newR); - newR.shallowReduce(context, angleUnit, target); + newR.shallowReduce(context, complexFormat, angleUnit, target); if (angleUnit == Preferences::AngleUnit::Radian) { - e.childAtIndex(0).shallowReduce(context, angleUnit, target); + e.childAtIndex(0).shallowReduce(context, complexFormat, angleUnit, target); } if (Integer::Division(div.quotient, Integer(2)).remainder.isOne() && e.type() != ExpressionNode::Type::Tangent) { /* Step 4.6. If we subtracted an odd number of Pi in 4.2, we need to * multiply the result by -1 (because cos((2k+1)Pi + x) = -cos(x) */ unaryCoefficient *= -1; } - Expression simplifiedCosine = e.shallowReduce(context, angleUnit, target); // recursive + Expression simplifiedCosine = e.shallowReduce(context, complexFormat, angleUnit, target); // recursive Multiplication m = Multiplication(Rational(unaryCoefficient)); simplifiedCosine.replaceWithInPlace(m); m.addChildAtIndexInPlace(simplifiedCosine, 1, 1); - return m.shallowReduce(context, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } assert(r.sign() == ExpressionNode::Sign::Positive); } return e; } -Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(isInverseTrigonometryFunction(e)); float pi = angleUnit == Preferences::AngleUnit::Radian ? M_PI : 180; @@ -278,19 +278,19 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c if (target == ExpressionNode::ReductionTarget::User || x.isNumber()) { Expression sign = SignFunction::Builder(x.clone()); Multiplication m0(Rational(1,2), sign, Constant(Ion::Charset::SmallPi)); - sign.shallowReduce(context, angleUnit, target); + sign.shallowReduce(context, complexFormat, angleUnit, target); e.replaceChildAtIndexInPlace(0, x); Addition a(m0); e.replaceWithInPlace(a); Multiplication m1(Rational(-1), e); - e.shallowReduce(context, angleUnit, target); + e.shallowReduce(context, complexFormat, angleUnit, target); a.addChildAtIndexInPlace(m1, 1, 1); - return a.shallowReduce(context, angleUnit, target); + return a.shallowReduce(context, complexFormat, angleUnit, target); } } // Step 4. Try finding an easy standard calculation reduction - Expression lookup = Trigonometry::table(e.childAtIndex(0), e.type(), context, angleUnit, target); + Expression lookup = Trigonometry::table(e.childAtIndex(0), e.type(), context, complexFormat, angleUnit, target); if (!lookup.isUninitialized()) { e.replaceWithInPlace(lookup); return lookup; @@ -308,7 +308,7 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c * arcsin(-x) = -arcsin(x), arctan(-x)= -arctan(x) * */ if (!letArcFunctionAtRoot) { - Expression positiveArg = e.childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, angleUnit, target); + Expression positiveArg = e.childAtIndex(0).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, target); if (!positiveArg.isUninitialized()) { // The argument was made positive // acos(-x) = pi-acos(x) @@ -318,15 +318,15 @@ Expression Trigonometry::shallowReduceInverseFunction(Expression & e, Context& c e.replaceWithInPlace(s); s.replaceChildAtIndexInPlace(0, pi); s.replaceChildAtIndexInPlace(1, e); - e.shallowReduce(context, angleUnit, target); - return s.shallowReduce(context, angleUnit, target); + e.shallowReduce(context, complexFormat, angleUnit, target); + return s.shallowReduce(context, complexFormat, angleUnit, target); } else { // asin(-x) = -asin(x) or atan(-x) = -atan(x) Multiplication m(Rational(-1)); e.replaceWithInPlace(m); m.addChildAtIndexInPlace(e, 1, 1); - e.shallowReduce(context, angleUnit, target); - return m.shallowReduce(context, angleUnit, target); + e.shallowReduce(context, complexFormat, angleUnit, target); + return m.shallowReduce(context, complexFormat, angleUnit, target); } } } @@ -425,7 +425,7 @@ constexpr Pair cheatTable[Trigonometry::k_numberOfEntries][5] = {Pair("180",180.0f), Pair("\x8A",3.141592653589793f), Pair("-1",-1.0f), Pair("0",0.0f), Pair("0",0.0f)}}; -Expression Trigonometry::table(const Expression e, ExpressionNode::Type type, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression Trigonometry::table(const Expression e, ExpressionNode::Type type, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(type == ExpressionNode::Type::Sine || type == ExpressionNode::Type::Cosine || type == ExpressionNode::Type::Tangent @@ -461,14 +461,14 @@ Expression Trigonometry::table(const Expression e, ExpressionNode::Type type, Co // Our given expression approximation matches a table entry, we check that both expressions are identical Expression input = Expression::Parse(cheatTable[i][inputIndex].expression); assert(!input.isUninitialized()); - input = input.deepReduce(context, angleUnit, target); + input = input.deepReduce(context, complexFormat, angleUnit, target); bool rightInput = input.isIdenticalTo(e); if (rightInput) { Expression output = Expression::Parse(cheatTable[i][outputIndex].expression); if (output.isUninitialized()) { return Expression(); } - return output.deepReduce(context, angleUnit, target); + return output.deepReduce(context, complexFormat, angleUnit, target); } break; } diff --git a/poincare/src/undefined.cpp b/poincare/src/undefined.cpp index 2928c987a..4c821ffa6 100644 --- a/poincare/src/undefined.cpp +++ b/poincare/src/undefined.cpp @@ -13,7 +13,7 @@ int UndefinedNode::polynomialDegree(Context & context, const char * symbolName) return -1; } -Expression UndefinedNode::setSign(Sign s, Context * context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { +Expression UndefinedNode::setSign(Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { return Undefined(this); } diff --git a/poincare/test/float.cpp b/poincare/test/float.cpp index fbd9d6b69..d605cf819 100644 --- a/poincare/test/float.cpp +++ b/poincare/test/float.cpp @@ -16,7 +16,7 @@ void assert_float_evaluates_to(Float f, const char * result) { Shared::GlobalContext globalContext; int numberOfDigits = sizeof(T) == sizeof(double) ? PrintFloat::k_numberOfStoredSignificantDigits : PrintFloat::k_numberOfPrintedSignificantDigits; char buffer[500]; - f.template approximate(globalContext, Radian, Cartesian).serialize(buffer, sizeof(buffer), DecimalMode, numberOfDigits); + f.template approximate(globalContext, Cartesian, Radian).serialize(buffer, sizeof(buffer), DecimalMode, numberOfDigits); translate_in_ASCII_chars(buffer); quiz_assert(strcmp(buffer, result) == 0); } diff --git a/poincare/test/helper.cpp b/poincare/test/helper.cpp index 936c518e8..f35ebadd0 100644 --- a/poincare/test/helper.cpp +++ b/poincare/test/helper.cpp @@ -103,10 +103,10 @@ void assert_parsed_expression_is(const char * expression, Poincare::Expression r quiz_assert(expressions_are_equal(r, e)); } -void assert_parsed_expression_polynomial_degree(const char * expression, int degree, const char * symbolName) { +void assert_parsed_expression_polynomial_degree(const char * expression, int degree, const char * symbolName, Preferences::ComplexFormat complexFormat) { Shared::GlobalContext globalContext; Expression e = parse_expression(expression); - Expression result = e.clone().reduce(globalContext, Radian); + Expression result = e.clone().reduce(globalContext, complexFormat, Radian); if (result.isUninitialized()) { result = e; } @@ -117,13 +117,13 @@ void assert_simplify(const char * expression) { Shared::GlobalContext globalContext; Expression e = parse_expression(expression); quiz_assert(!e.isUninitialized()); - e = e.simplify(globalContext, Radian); + e = e.simplify(globalContext, Cartesian, Radian); quiz_assert(!e.isUninitialized()); } -typedef Expression (*ProcessExpression)(Expression, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat); +typedef Expression (*ProcessExpression)(Expression, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit); -void assert_parsed_expression_process_to(const char * expression, const char * result, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat, ProcessExpression process, int numberOfSignifiantDigits = PrintFloat::k_numberOfStoredSignificantDigits) { +void assert_parsed_expression_process_to(const char * expression, const char * result, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ProcessExpression process, int numberOfSignifiantDigits = PrintFloat::k_numberOfStoredSignificantDigits) { Shared::GlobalContext globalContext; Expression e = parse_expression(expression); @@ -131,7 +131,7 @@ void assert_parsed_expression_process_to(const char * expression, const char * r cout << " Entry expression: " << expression << "----" << endl; print_expression(e, 0); #endif - Expression m = process(e, globalContext, angleUnit, complexFormat); + Expression m = process(e, globalContext, complexFormat, angleUnit); char buffer[500]; m.serialize(buffer, sizeof(buffer), DecimalMode, numberOfSignifiantDigits); translate_in_ASCII_chars(buffer); @@ -149,12 +149,12 @@ void assert_parsed_expression_evaluates_to(const char * expression, const char * #endif int numberOfDigits = sizeof(T) == sizeof(double) ? PrintFloat::k_numberOfStoredSignificantDigits : PrintFloat::k_numberOfPrintedSignificantDigits; numberOfDigits = numberOfSignificantDigits > 0 ? numberOfSignificantDigits : numberOfDigits; - assert_parsed_expression_process_to(expression, approximation, angleUnit, complexFormat, [](Expression e, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) { - Expression result = e.clone().simplify(context, angleUnit); + assert_parsed_expression_process_to(expression, approximation, complexFormat, angleUnit, [](Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { + Expression result = e.clone().simplify(context, complexFormat, angleUnit); if (result.isUninitialized()) { result = e; } - return result.approximate(context, angleUnit, complexFormat); + return result.approximate(context, complexFormat, angleUnit); }, numberOfDigits); } @@ -169,9 +169,9 @@ void assert_parsed_expression_simplify_to(const char * expression, const char * #if POINCARE_TESTS_PRINT_EXPRESSIONS cout << "--------- Simplification ---------" << endl; #endif - assert_parsed_expression_process_to(expression, simplifiedExpression, angleUnit, complexFormat, [](Expression e, Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) { + assert_parsed_expression_process_to(expression, simplifiedExpression, complexFormat, angleUnit, [](Expression e, Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression copy = e.clone(); - copy.simplifyAndApproximate(©, nullptr, context, angleUnit, complexFormat); + copy.simplifyAndApproximate(©, nullptr, context, complexFormat, angleUnit); if (copy.isUninitialized()) { return e; } @@ -218,6 +218,6 @@ void assert_expression_layout_serialize_to(Poincare::Layout layout, const char * } template void assert_parsed_expression_evaluates_to(char const*, char const *, Poincare::Preferences::AngleUnit, Poincare::Preferences::ComplexFormat, int); -template void assert_parsed_expression_evaluates_to(char const*, char const *, Poincare::Preferences::AngleUnit, Poincare::Preferences::ComplexFormat, int); +template void assert_parsed_expression_evaluates_to(char const*, char const *, Poincare::Preferences::AngleUnit, Poincare::Preferences::ComplexFormat, int); template void assert_parsed_expression_approximates_with_value_for_symbol(Poincare::Expression, const char *, float, float, Poincare::Preferences::AngleUnit); template void assert_parsed_expression_approximates_with_value_for_symbol(Poincare::Expression, const char *, double, double, Poincare::Preferences::AngleUnit); diff --git a/poincare/test/helper.h b/poincare/test/helper.h index 00a0e8f20..e445f5488 100644 --- a/poincare/test/helper.h +++ b/poincare/test/helper.h @@ -12,6 +12,7 @@ constexpr Poincare::Preferences::AngleUnit Degree = Poincare::Preferences::Angle constexpr Poincare::Preferences::AngleUnit Radian = Poincare::Preferences::AngleUnit::Radian; constexpr Poincare::Preferences::ComplexFormat Cartesian = Poincare::Preferences::ComplexFormat::Cartesian; constexpr Poincare::Preferences::ComplexFormat Polar = Poincare::Preferences::ComplexFormat::Polar; +constexpr Poincare::Preferences::ComplexFormat Real = Poincare::Preferences::ComplexFormat::Real; constexpr Poincare::Preferences::PrintFloatMode DecimalMode = Poincare::Preferences::PrintFloatMode::Decimal; constexpr Poincare::Preferences::PrintFloatMode ScientificMode = Poincare::Preferences::PrintFloatMode::Scientific; @@ -22,7 +23,7 @@ Poincare::Expression parse_expression(const char * expression, bool canBeUnparsa void assert_expression_not_parsable(const char * expression); void assert_parsed_expression_type(const char * expression, Poincare::ExpressionNode::Type type); void assert_parsed_expression_is(const char * expression, Poincare::Expression r); -void assert_parsed_expression_polynomial_degree(const char * expression, int degree, const char * symbolName = "x"); +void assert_parsed_expression_polynomial_degree(const char * expression, int degree, const char * symbolName = "x", Poincare::Preferences::ComplexFormat complexFormat = Cartesian); void assert_simplify(const char * expression); template diff --git a/poincare/test/layouts.cpp b/poincare/test/layouts.cpp index 59133fb96..dff41720e 100644 --- a/poincare/test/layouts.cpp +++ b/poincare/test/layouts.cpp @@ -15,14 +15,14 @@ void assert_parsed_layout_is(Layout l, Poincare::Expression r) { l.serializeForParsing(buffer, bufferSize); Expression e = parse_expression(buffer); Expression eSimplified; - e.clone().simplifyAndApproximate(&eSimplified, nullptr, context, Degree, Cartesian); + e.clone().simplifyAndApproximate(&eSimplified, nullptr, context, Cartesian, Degree); if (eSimplified.isUninitialized()) { /* In case the simplification is impossible (if there are matrices for * instance), use the non simplified expression */ eSimplified = e; } Expression rSimplified; - r.clone().simplifyAndApproximate(&rSimplified, nullptr, context, Degree, Cartesian); + r.clone().simplifyAndApproximate(&rSimplified, nullptr, context, Cartesian, Degree); if (rSimplified.isUninitialized()) { /* In case the simplification is impossible (if there are matrices for * instance), use the non simplified expression */ diff --git a/poincare/test/properties.cpp b/poincare/test/properties.cpp index b5ac572d8..031a3f043 100644 --- a/poincare/test/properties.cpp +++ b/poincare/test/properties.cpp @@ -11,11 +11,11 @@ constexpr Poincare::ExpressionNode::Sign Positive = Poincare::ExpressionNode::Si constexpr Poincare::ExpressionNode::Sign Negative = Poincare::ExpressionNode::Sign::Negative; constexpr Poincare::ExpressionNode::Sign Unknown = Poincare::ExpressionNode::Sign::Unknown; -void assert_parsed_expression_sign(const char * expression, Poincare::ExpressionNode::Sign sign) { +void assert_parsed_expression_sign(const char * expression, Poincare::ExpressionNode::Sign sign, Poincare::Preferences::ComplexFormat complexFormat = Cartesian) { Shared::GlobalContext globalContext; Expression e = parse_expression(expression); quiz_assert(!e.isUninitialized()); - e = e.reduce(globalContext, Degree); + e = e.reduce(globalContext, complexFormat, Degree); quiz_assert(e.sign(&globalContext) == sign); } @@ -34,6 +34,8 @@ QUIZ_CASE(poincare_sign) { assert_parsed_expression_sign("-23/32", Negative); assert_parsed_expression_sign("P", Positive); assert_parsed_expression_sign("X", Positive); + assert_parsed_expression_sign("R(-1)", Unknown); + assert_parsed_expression_sign("R(-1)", Unknown, Real); } QUIZ_CASE(poincare_polynomial_degree) { @@ -62,7 +64,7 @@ QUIZ_CASE(poincare_polynomial_degree) { void assert_expression_has_characteristic_range(Expression e, float range, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Degree) { Shared::GlobalContext globalContext; quiz_assert(!e.isUninitialized()); - e = e.reduce(globalContext, angleUnit); + e = e.reduce(globalContext, Preferences::ComplexFormat::Cartesian, angleUnit); if (std::isnan(range)) { quiz_assert(std::isnan(e.characteristicXRange(globalContext, angleUnit))); } else { @@ -124,18 +126,18 @@ QUIZ_CASE(poincare_get_variables) { assert_parsed_expression_has_variables("f(tata)", variableBuffer7, 2); } -void assert_parsed_expression_has_polynomial_coefficient(const char * expression, const char * symbolName, const char ** coefficients, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Degree) { +void assert_parsed_expression_has_polynomial_coefficient(const char * expression, const char * symbolName, const char ** coefficients, Preferences::ComplexFormat complexFormat = Preferences::ComplexFormat::Cartesian, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Degree) { Shared::GlobalContext globalContext; Expression e = parse_expression(expression); quiz_assert(!e.isUninitialized()); - e = e.reduce(globalContext, angleUnit); + e = e.reduce(globalContext, complexFormat, angleUnit); Expression coefficientBuffer[Poincare::Expression::k_maxNumberOfPolynomialCoefficients]; - int d = e.getPolynomialReducedCoefficients(symbolName, coefficientBuffer, globalContext, Radian); + int d = e.getPolynomialReducedCoefficients(symbolName, coefficientBuffer, globalContext, complexFormat, Radian); for (int i = 0; i <= d; i++) { Expression f = parse_expression(coefficients[i]); quiz_assert(!f.isUninitialized()); - coefficientBuffer[i] = coefficientBuffer[i].reduce(globalContext, angleUnit); - f = f.reduce(globalContext, angleUnit); + coefficientBuffer[i] = coefficientBuffer[i].reduce(globalContext, complexFormat, angleUnit); + f = f.reduce(globalContext, complexFormat, angleUnit); quiz_assert(coefficientBuffer[i].isIdenticalTo(f)); } quiz_assert(coefficients[d+1] == 0);