diff --git a/poincare/include/poincare/absolute_value.h b/poincare/include/poincare/absolute_value.h index 2ec3526b5..edf35d2a4 100644 --- a/poincare/include/poincare/absolute_value.h +++ b/poincare/include/poincare/absolute_value.h @@ -13,14 +13,14 @@ public: Type type() const override; Sign sign() const override { return Sign::Positive; } private: - ExpressionReference setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; /* Layout */ LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "abs"); } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index 6d4a9e6ad..d1dcd7512 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -40,7 +40,7 @@ private: static const char * name() { return "+"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; Expression * shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; Expression * factorizeOnCommonDenominator(Context & context, Preferences::AngleUnit angleUnit); void factorizeOperands(Expression * e1, Expression * e2, Context & context, Preferences::AngleUnit angleUnit); diff --git a/poincare/include/poincare/arc_cosine.h b/poincare/include/poincare/arc_cosine.h index 01c12dd8e..a1c2be8ad 100644 --- a/poincare/include/poincare/arc_cosine.h +++ b/poincare/include/poincare/arc_cosine.h @@ -24,7 +24,7 @@ private: return "acos"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/arc_sine.h b/poincare/include/poincare/arc_sine.h index 03fb2780b..1bbb2a2b0 100644 --- a/poincare/include/poincare/arc_sine.h +++ b/poincare/include/poincare/arc_sine.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "asin"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/arc_tangent.h b/poincare/include/poincare/arc_tangent.h index 899c2ab94..ba82d0c21 100644 --- a/poincare/include/poincare/arc_tangent.h +++ b/poincare/include/poincare/arc_tangent.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "atan"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/binomial_coefficient.h b/poincare/include/poincare/binomial_coefficient.h index 2ab22ea37..a959ec1c0 100644 --- a/poincare/include/poincare/binomial_coefficient.h +++ b/poincare/include/poincare/binomial_coefficient.h @@ -20,7 +20,7 @@ private: return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "binomial"); } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/ceiling.h b/poincare/include/poincare/ceiling.h index bcb738211..ea95fdf32 100644 --- a/poincare/include/poincare/ceiling.h +++ b/poincare/include/poincare/ceiling.h @@ -19,7 +19,7 @@ private: } const char * name() const { return "ceil"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/complex_argument.h b/poincare/include/poincare/complex_argument.h index 7375af607..76ca77df6 100644 --- a/poincare/include/poincare/complex_argument.h +++ b/poincare/include/poincare/complex_argument.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "arg"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/confidence_interval.h b/poincare/include/poincare/confidence_interval.h index 15c4064cb..5532fb6c5 100644 --- a/poincare/include/poincare/confidence_interval.h +++ b/poincare/include/poincare/confidence_interval.h @@ -21,7 +21,7 @@ private: } virtual const char * name() const { return "confidence"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(Expression::SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation * privateApproximate(Expression::DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/conjugate.h b/poincare/include/poincare/conjugate.h index b55164e1e..3e2c41604 100644 --- a/poincare/include/poincare/conjugate.h +++ b/poincare/include/poincare/conjugate.h @@ -18,7 +18,7 @@ private: return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "conj"); } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/cosine.h b/poincare/include/poincare/cosine.h index d631ba326..de0660352 100644 --- a/poincare/include/poincare/cosine.h +++ b/poincare/include/poincare/cosine.h @@ -26,7 +26,7 @@ private: } const char * name() const { return "cos"; } /* Simplication */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ApproximationEngine::map(this, context, angleUnit,computeOnComplex); diff --git a/poincare/include/poincare/decimal.h b/poincare/include/poincare/decimal.h index 92990710f..2bcd9b2ac 100644 --- a/poincare/include/poincare/decimal.h +++ b/poincare/include/poincare/decimal.h @@ -40,8 +40,8 @@ public: int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; // Simplification - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; - ExpressionReference shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) override; // Layout bool needsParenthesisWithParent(SerializableNode * parentNode) const override; diff --git a/poincare/include/poincare/derivative.h b/poincare/include/poincare/derivative.h index f2bb8cf30..2ced6221c 100644 --- a/poincare/include/poincare/derivative.h +++ b/poincare/include/poincare/derivative.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "diff"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/determinant.h b/poincare/include/poincare/determinant.h index 02be13888..68ab315be 100644 --- a/poincare/include/poincare/determinant.h +++ b/poincare/include/poincare/determinant.h @@ -20,7 +20,7 @@ private: } const char * name() const { return "det"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, 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); } diff --git a/poincare/include/poincare/division.h b/poincare/include/poincare/division.h index 655fa3c51..dfe0d11d8 100644 --- a/poincare/include/poincare/division.h +++ b/poincare/include/poincare/division.h @@ -24,7 +24,7 @@ private: return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "/"); } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static MatrixComplex computeOnMatrixAndComplex(const MatrixComplex m, const std::complex c) { return ApproximationEngine::elementWiseOnMatrixComplexAndComplex(m, c, compute); diff --git a/poincare/include/poincare/division_quotient.h b/poincare/include/poincare/division_quotient.h index 57b339827..4f656d7f6 100644 --- a/poincare/include/poincare/division_quotient.h +++ b/poincare/include/poincare/division_quotient.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "quo"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, 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); } diff --git a/poincare/include/poincare/division_remainder.h b/poincare/include/poincare/division_remainder.h index dcfe73f21..761bcedf8 100644 --- a/poincare/include/poincare/division_remainder.h +++ b/poincare/include/poincare/division_remainder.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "rem"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, 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); } diff --git a/poincare/include/poincare/equal.h b/poincare/include/poincare/equal.h index 285c2da36..e7b3f1689 100644 --- a/poincare/include/poincare/equal.h +++ b/poincare/include/poincare/equal.h @@ -16,7 +16,7 @@ public: Expression * standardEquation(Context & context, Preferences::AngleUnit angleUnit) const; private: /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Layout */ LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { diff --git a/poincare/include/poincare/factor.h b/poincare/include/poincare/factor.h index 012966b36..0466cc8bd 100644 --- a/poincare/include/poincare/factor.h +++ b/poincare/include/poincare/factor.h @@ -23,7 +23,7 @@ private: } const char * name() const { return "factor"; } /* Simplification */ - ExpressionReference shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) override; Expression * createMultiplicationOfIntegerPrimeDecomposition(Integer i, Context & context, Preferences::AngleUnit angleUnit); /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index a0987d578..14dbb72d2 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -17,8 +17,8 @@ private: LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplication */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; - ExpressionReference shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/floor.h b/poincare/include/poincare/floor.h index c4ba7ea1b..642cfd198 100644 --- a/poincare/include/poincare/floor.h +++ b/poincare/include/poincare/floor.h @@ -19,7 +19,7 @@ private: } const char * name() const { return "floor"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/frac_part.h b/poincare/include/poincare/frac_part.h index 2977f56a9..6b7d22c43 100644 --- a/poincare/include/poincare/frac_part.h +++ b/poincare/include/poincare/frac_part.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "frac"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/global_context.h b/poincare/include/poincare/global_context.h index de4881647..36a753907 100644 --- a/poincare/include/poincare/global_context.h +++ b/poincare/include/poincare/global_context.h @@ -17,16 +17,16 @@ public: GlobalContext(); /* The expression recorded in global context is already a expression. * Otherwise, we would need the context and the angle unit to evaluate it */ - const ExpressionReference expressionForSymbol(const SymbolReference symbol) override; + const Expression expressionForSymbol(const SymbolReference symbol) override; LayoutRef layoutForSymbol(const SymbolReference symbol, int numberOfSignificantDigits); - void setExpressionForSymbolName(const ExpressionReference expression, const SymbolReference symbol, Context & context) override; + void setExpressionForSymbolName(const Expression expression, const SymbolReference symbol, Context & context) override; static constexpr uint16_t k_maxNumberOfScalarExpressions = 26; static constexpr uint16_t k_maxNumberOfListExpressions = 10; static constexpr uint16_t k_maxNumberOfMatrixExpressions = 10; private: static Decimal * defaultExpression(); int symbolIndex(const Symbol * symbol) const; - ExpressionReference m_expressions[k_maxNumberOfScalarExpressions]; + Expression m_expressions[k_maxNumberOfScalarExpressions]; MatrixReference m_matrixExpressions[k_maxNumberOfMatrixExpressions]; /* Matrix layout memoization */ LayoutRef m_matrixLayouts[k_maxNumberOfMatrixExpressions]; diff --git a/poincare/include/poincare/great_common_divisor.h b/poincare/include/poincare/great_common_divisor.h index cb7b481dd..5833fe680 100644 --- a/poincare/include/poincare/great_common_divisor.h +++ b/poincare/include/poincare/great_common_divisor.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "gcd"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/hyperbolic_arc_cosine.h b/poincare/include/poincare/hyperbolic_arc_cosine.h index be2ad1827..ae06f058e 100644 --- a/poincare/include/poincare/hyperbolic_arc_cosine.h +++ b/poincare/include/poincare/hyperbolic_arc_cosine.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "acosh"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/hyperbolic_arc_sine.h b/poincare/include/poincare/hyperbolic_arc_sine.h index d60fd6917..652c544de 100644 --- a/poincare/include/poincare/hyperbolic_arc_sine.h +++ b/poincare/include/poincare/hyperbolic_arc_sine.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "asinh"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/hyperbolic_arc_tangent.h b/poincare/include/poincare/hyperbolic_arc_tangent.h index b3defa05d..fd67c33fd 100644 --- a/poincare/include/poincare/hyperbolic_arc_tangent.h +++ b/poincare/include/poincare/hyperbolic_arc_tangent.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "atanh"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/hyperbolic_cosine.h b/poincare/include/poincare/hyperbolic_cosine.h index 603ba5582..22963d0a7 100644 --- a/poincare/include/poincare/hyperbolic_cosine.h +++ b/poincare/include/poincare/hyperbolic_cosine.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "cosh"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ApproximationEngine::map(this, context, angleUnit,computeOnComplex); diff --git a/poincare/include/poincare/hyperbolic_sine.h b/poincare/include/poincare/hyperbolic_sine.h index 17218bb2b..4008b1971 100644 --- a/poincare/include/poincare/hyperbolic_sine.h +++ b/poincare/include/poincare/hyperbolic_sine.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "sinh"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ApproximationEngine::map(this, context, angleUnit,computeOnComplex); diff --git a/poincare/include/poincare/hyperbolic_tangent.h b/poincare/include/poincare/hyperbolic_tangent.h index 07aa50d06..8d7b93065 100644 --- a/poincare/include/poincare/hyperbolic_tangent.h +++ b/poincare/include/poincare/hyperbolic_tangent.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "tanh"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ApproximationEngine::map(this, context, angleUnit,computeOnComplex); diff --git a/poincare/include/poincare/imaginary_part.h b/poincare/include/poincare/imaginary_part.h index f7bee92cd..d069d1a7d 100644 --- a/poincare/include/poincare/imaginary_part.h +++ b/poincare/include/poincare/imaginary_part.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "im"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/integer.h b/poincare/include/poincare/integer.h index 27b27a4b7..ffafd6606 100644 --- a/poincare/include/poincare/integer.h +++ b/poincare/include/poincare/integer.h @@ -114,7 +114,7 @@ public: Type type() const override { return Type::Integer; } // Simplification - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; // Approximation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ComplexReference(templatedApproximate()); } @@ -133,7 +133,7 @@ public: // ExpressionNode Sign sign() const override { return m_negative ? Sign::Negative : Sign::Positive; } - ExpressionReference setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; void setNegative(bool negative); diff --git a/poincare/include/poincare/integral.h b/poincare/include/poincare/integral.h index 7919b7c67..c53e5a423 100644 --- a/poincare/include/poincare/integral.h +++ b/poincare/include/poincare/integral.h @@ -19,7 +19,7 @@ private: return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "int"); } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/least_common_multiple.h b/poincare/include/poincare/least_common_multiple.h index 563fb430c..773fb339a 100644 --- a/poincare/include/poincare/least_common_multiple.h +++ b/poincare/include/poincare/least_common_multiple.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "lcm"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index 050613324..42ac61229 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -19,7 +19,7 @@ private: return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "log"); } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; Expression * simpleShallowReduce(Context & context, Preferences::AngleUnit angleUnit); Expression * shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; bool parentIsAPowerOfSameBase() const; diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index ef5e8d75c..053de8634 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -47,7 +47,7 @@ private: int m_numberOfColumns; }; -class MatrixReference : public ExpressionReference { +class MatrixReference : public Expression { template friend class MatrixComplexNode; friend class GlobalContext; public: @@ -55,25 +55,25 @@ public: int numberOfRows() const; int numberOfColumns() const; void addChildTreeAtIndex(TreeReference t, int index, int currentNumberOfChildren) override; - ExpressionReference matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); } + Expression matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); } /* Operation on matrix */ int rank(Context & context, Preferences::AngleUnit angleUnit, bool inPlace); // 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 - ExpressionReference trace() const; - ExpressionReference determinant() const; + Expression trace() const; + Expression determinant() const; MatrixReference transpose() const; static MatrixReference createIdentity(int dim); /* createInverse can be called on any matrix reduce or not, approximate or not. */ - ExpressionReference inverse(Context & context, Preferences::AngleUnit angleUnit) const; + Expression inverse(Context & context, Preferences::AngleUnit angleUnit) const; #endif private: // TODO: find another solution for inverse and determinant (avoid capping the matrix) static constexpr int k_maxNumberOfCoefficients = 100; - MatrixReference(TreeNode * node) : ExpressionReference(node) {} + MatrixReference(TreeNode * node) : Expression(node) {} MatrixNode * typedNode() const { assert(!isAllocationFailure()); return static_cast(node()); } void setNumberOfRows(int rows); void setNumberOfColumns(int columns); diff --git a/poincare/include/poincare/matrix_dimension.h b/poincare/include/poincare/matrix_dimension.h index 692926262..48fe9bff9 100644 --- a/poincare/include/poincare/matrix_dimension.h +++ b/poincare/include/poincare/matrix_dimension.h @@ -20,7 +20,7 @@ private: } const char * name() const { return "dim"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/matrix_inverse.h b/poincare/include/poincare/matrix_inverse.h index d045ac518..e9bda8d08 100644 --- a/poincare/include/poincare/matrix_inverse.h +++ b/poincare/include/poincare/matrix_inverse.h @@ -20,7 +20,7 @@ private: } const char * name() const { return "inverse"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, 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); } diff --git a/poincare/include/poincare/matrix_trace.h b/poincare/include/poincare/matrix_trace.h index 5ca534f01..f5ce4f15c 100644 --- a/poincare/include/poincare/matrix_trace.h +++ b/poincare/include/poincare/matrix_trace.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "trace"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, 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); } diff --git a/poincare/include/poincare/matrix_transpose.h b/poincare/include/poincare/matrix_transpose.h index 819ac7c15..837811140 100644 --- a/poincare/include/poincare/matrix_transpose.h +++ b/poincare/include/poincare/matrix_transpose.h @@ -20,7 +20,7 @@ private: } const char * name() const { return "transpose"; } /* Simplification */ - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context & context, 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); } diff --git a/poincare/include/poincare/multiplication.h b/poincare/include/poincare/multiplication.h index 13af934d7..ef7016a55 100644 --- a/poincare/include/poincare/multiplication.h +++ b/poincare/include/poincare/multiplication.h @@ -32,13 +32,13 @@ public: template static MatrixComplex computeOnMatrices(const MatrixComplex m, const MatrixComplex n); private: /* Property */ - ExpressionReference setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; /* Layout */ bool needsParenthesisWithParent(SerializableNode * parentNode) const override; LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; Expression * privateShallowReduce(Context& context, Preferences::AngleUnit angleUnit, bool expand, bool canBeInterrupted); void mergeMultiplicationOperands(); void factorizeBase(Expression * e1, Expression * e2, Context & context, Preferences::AngleUnit angleUnit); diff --git a/poincare/include/poincare/n_ary_expression_node.h b/poincare/include/poincare/n_ary_expression_node.h index 17800e554..1b36b5c24 100644 --- a/poincare/include/poincare/n_ary_expression_node.h +++ b/poincare/include/poincare/n_ary_expression_node.h @@ -21,7 +21,7 @@ public: // Commutative properties void sortOperands(ExpressionOrder order, bool canBeInterrupted); - ExpressionReference squashUnaryHierarchy(); + Expression squashUnaryHierarchy(); protected: int m_numberOfChildren; @@ -30,23 +30,23 @@ private: int simplificationOrderGreaterType(const ExpressionNode * e, bool canBeInterrupted) const override; }; -class NAryExpressionRef : public ExpressionReference { +class NAryExpressionRef : public Expression { public: void addChildTreeAtIndex(TreeReference t, int index, int currentNumberOfChildren) override { - ExpressionReference::addChildTreeAtIndex(t, index, currentNumberOfChildren); + Expression::addChildTreeAtIndex(t, index, currentNumberOfChildren); } // Remove puts a child at the end of the pool void removeChildAtIndex(int i) override { - ExpressionReference::removeChildAtIndex(i); + Expression::removeChildAtIndex(i); } void removeChild(TreeReference t, int childNumberOfChildren) override { - ExpressionReference::removeChild(t, childNumberOfChildren); + Expression::removeChild(t, childNumberOfChildren); } void removeChildren(int currentNumberOfChildren) { - ExpressionReference::removeChildren(currentNumberOfChildren); + Expression::removeChildren(currentNumberOfChildren); } void removeChildrenAndDestroy(int currentNumberOfChildren) { - ExpressionReference::removeChildren(currentNumberOfChildren); + Expression::removeChildren(currentNumberOfChildren); } }; diff --git a/poincare/include/poincare/naperian_logarithm.h b/poincare/include/poincare/naperian_logarithm.h index 67bc1492d..6f53dcde3 100644 --- a/poincare/include/poincare/naperian_logarithm.h +++ b/poincare/include/poincare/naperian_logarithm.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "ln"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/nth_root.h b/poincare/include/poincare/nth_root.h index c1b3b1229..7e7c4fa11 100644 --- a/poincare/include/poincare/nth_root.h +++ b/poincare/include/poincare/nth_root.h @@ -17,7 +17,7 @@ private: return LayoutEngine::writePrefixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "root"); } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/parenthesis.h b/poincare/include/poincare/parenthesis.h index 63b30da21..d1cdb0918 100644 --- a/poincare/include/poincare/parenthesis.h +++ b/poincare/include/poincare/parenthesis.h @@ -23,9 +23,11 @@ public: // Layout LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; - int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const; + int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { + return LayoutEngine::writePrefixSerializableRefTextInBuffer(Expression(this), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ""); + } // Simplification - Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; // Approximation Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -34,12 +36,9 @@ private: template Evaluation templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const; }; -class Parenthesis : public Expression { +class ParenthesisReference : public Expression { public: - Parenthesis(const ParenthesisNode * n) : Expression(n) {} - Parenthesis(Expression exp) : - Expression(TreePool::sharedPool()->createTreeNode()) - { + ParenthesisReference(Expression exp) : Expression(TreePool::sharedPool()->createTreeNode()) { replaceChildAtIndexInPlace(0, exp); } // Expression diff --git a/poincare/include/poincare/permute_coefficient.h b/poincare/include/poincare/permute_coefficient.h index a1bd3f585..45e8731fa 100644 --- a/poincare/include/poincare/permute_coefficient.h +++ b/poincare/include/poincare/permute_coefficient.h @@ -22,7 +22,7 @@ private: } const char * name() const { return "permute"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, 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); } diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index cdd81c9c0..664660a18 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -28,7 +28,7 @@ private: constexpr static int k_maxNumberOfTermsInExpandedMultinome = 25; constexpr static int k_maxExactPowerMatrix = 100; /* Property */ - ExpressionReference setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; /* Layout */ LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; bool needsParenthesisWithParent(SerializableNode * parentNode) const override; @@ -37,7 +37,7 @@ private: } static const char * name() { return "^"; } /* Simplify */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; Expression * shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; int simplificationOrderGreaterType(const Expression * e, bool canBeInterrupted) const override; int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; diff --git a/poincare/include/poincare/prediction_interval.h b/poincare/include/poincare/prediction_interval.h index 4e0fc5b44..d16411a05 100644 --- a/poincare/include/poincare/prediction_interval.h +++ b/poincare/include/poincare/prediction_interval.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "prediction95"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(Expression::SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } Evaluation * privateApproximate(Expression::DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } diff --git a/poincare/include/poincare/random.h b/poincare/include/poincare/random.h index 276002384..5706dcd4b 100644 --- a/poincare/include/poincare/random.h +++ b/poincare/include/poincare/random.h @@ -14,7 +14,7 @@ public: Sign sign() const override { return Sign::Positive; } template static T random(); private: - ExpressionReference setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override; /* Layout */ LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override { return LayoutEngine::createPrefixLayout(this, floatDisplayMode, numberOfSignificantDigits, name()); diff --git a/poincare/include/poincare/rational.h b/poincare/include/poincare/rational.h index 6de3a6a5d..3438f5c2e 100644 --- a/poincare/include/poincare/rational.h +++ b/poincare/include/poincare/rational.h @@ -46,12 +46,12 @@ public: static int NaturalOrder(const RationalNode i, const RationalNode j); private: int simplificationOrderSameType(const ExpressionNode * e, bool canBeInterrupted) const override; - ExpressionReference shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; - ExpressionReference setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override { + Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) override; + Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override { setSign(s); - return ExpressionReference(this); + return Expression(this); } - ExpressionReference cloneDenominator(Context & context, Preferences::AngleUnit angleUnit) const override; + Expression cloneDenominator(Context & context, Preferences::AngleUnit angleUnit) const override; bool m_negative; size_t m_numberOfDigitsNumerator; size_t m_numberOfDigitsDenominator; diff --git a/poincare/include/poincare/real_part.h b/poincare/include/poincare/real_part.h index be99a9105..73be6d331 100644 --- a/poincare/include/poincare/real_part.h +++ b/poincare/include/poincare/real_part.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "re"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/round.h b/poincare/include/poincare/round.h index 906eab037..d680dbe6a 100644 --- a/poincare/include/poincare/round.h +++ b/poincare/include/poincare/round.h @@ -21,7 +21,7 @@ private: } const char * name() const { return "round"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Complex */ 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); } diff --git a/poincare/include/poincare/simplification_root.h b/poincare/include/poincare/simplification_root.h index 4a1c31b57..5eccc798d 100644 --- a/poincare/include/poincare/simplification_root.h +++ b/poincare/include/poincare/simplification_root.h @@ -32,7 +32,7 @@ public: return nullptr; } private: - ExpressionReference shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override { return this; } + Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override { return this; } }; } diff --git a/poincare/include/poincare/sine.h b/poincare/include/poincare/sine.h index 24bdf44dd..fb551d490 100644 --- a/poincare/include/poincare/sine.h +++ b/poincare/include/poincare/sine.h @@ -25,7 +25,7 @@ private: } const char * name() const { return "sin"; } /* Simplication */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ApproximationEngine::map(this, context, angleUnit,computeOnComplex); diff --git a/poincare/include/poincare/square_root.h b/poincare/include/poincare/square_root.h index 43ee62563..e29d3f1f0 100644 --- a/poincare/include/poincare/square_root.h +++ b/poincare/include/poincare/square_root.h @@ -16,7 +16,7 @@ private: LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit); Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { diff --git a/poincare/include/poincare/store.h b/poincare/include/poincare/store.h index f8134235e..96c4b4fe9 100644 --- a/poincare/include/poincare/store.h +++ b/poincare/include/poincare/store.h @@ -16,7 +16,7 @@ public: int polynomialDegree(char symbolName) const override; private: /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Layout */ LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index efeddfce3..3dc672725 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -24,7 +24,7 @@ private: } static const char * name() { return "-"; } /* Simplification */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static MatrixComplex computeOnMatrixAndComplex(const MatrixComplex m, const std::complex c) { return ApproximationEngine::elementWiseOnMatrixComplexAndComplex(m, c, compute); diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index 6822bd188..02dfcbe0b 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -37,7 +37,7 @@ public: int writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; /* Simplification */ - Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Approximation */ Evaluation approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate(context, angleUnit); } @@ -50,7 +50,7 @@ private: char m_name; }; -class Symbol : public Expression { +class SymbolReference : public Expression { public: enum SpecialSymbols : char { /* We can use characters from 1 to 31 as they do not correspond to usual @@ -85,9 +85,10 @@ public: X3, Y3 = 29 }; - Symbol(const SymbolNode * n) : Expression(n) {} - Symbol(const char name) : Expression(TreePool::sharedPool()->createTreeNode()) { - node()->setName(name); + SymbolReference(const char name) : Expression(TreePool::sharedPool()->createTreeNode()) { + if (!node->isAllocationFailure()) { + static_cast(node)->setName(name); + } } // Symbol properties diff --git a/poincare/include/poincare/tangent.h b/poincare/include/poincare/tangent.h index 0cf5f8cb4..374905ba4 100644 --- a/poincare/include/poincare/tangent.h +++ b/poincare/include/poincare/tangent.h @@ -23,7 +23,7 @@ private: } const char * name() const { return "tan"; } /* Simplication */ - ExpressionReference shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; + Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override; /* Evaluation */ template static std::complex computeOnComplex(const std::complex c, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Radian); 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 e5e69116c..ce587722a 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -27,7 +27,7 @@ LayoutRef AbsoluteValue::createLayout(Preferences::PrintFloatMode floatDisplayMo return AbsoluteValueLayoutRef(operand(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } -ExpressionReference AbsoluteValue::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression AbsoluteValue::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index 1f61755bd..5c4110e78 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -35,7 +35,7 @@ int Addition::polynomialDegree(char symbolName) const { return degree; } -int Addition::getPolynomialCoefficients(char symbolName, ExpressionReference coefficients[]) const { +int Addition::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const { int deg = polynomialDegree(symbolName); if (deg < 0 || deg > k_maxPolynomialDegree) { return -1; @@ -63,7 +63,7 @@ bool Addition::needParenthesisWithParent(const Expression * e) const { /* Simplication */ -ExpressionReference Addition::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Addition::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index 0aa59aa67..498305ba7 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -17,7 +17,7 @@ Expression * ArcCosine::clone() const { return a; } -ExpressionReference ArcCosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression ArcCosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index 1e0df8859..886140c27 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -17,7 +17,7 @@ Expression * ArcSine::clone() const { return a; } -ExpressionReference ArcSine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression ArcSine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index e52c84b84..c338b34f0 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -17,7 +17,7 @@ Expression * ArcTangent::clone() const { return a; } -ExpressionReference ArcTangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression ArcTangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/binomial_coefficient.cpp b/poincare/src/binomial_coefficient.cpp index 2e85fff7a..212114560 100644 --- a/poincare/src/binomial_coefficient.cpp +++ b/poincare/src/binomial_coefficient.cpp @@ -20,7 +20,7 @@ Expression * BinomialCoefficient::clone() const { return b; } -ExpressionReference BinomialCoefficient::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression BinomialCoefficient::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index 076641f1d..68247aa88 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -20,7 +20,7 @@ Expression * Ceiling::clone() const { return c; } -ExpressionReference Ceiling::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Ceiling::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/complex_argument.cpp b/poincare/src/complex_argument.cpp index 91a0148d1..a376ac1fd 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -16,7 +16,7 @@ Expression * ComplexArgument::clone() const { return a; } -ExpressionReference ComplexArgument::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression ComplexArgument::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/confidence_interval.cpp b/poincare/src/confidence_interval.cpp index 96ca296ea..9d19fbd2b 100644 --- a/poincare/src/confidence_interval.cpp +++ b/poincare/src/confidence_interval.cpp @@ -24,7 +24,7 @@ int ConfidenceInterval::polynomialDegree(char symbolName) const { return -1; } -ExpressionReference ConfidenceInterval::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression ConfidenceInterval::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/conjugate.cpp b/poincare/src/conjugate.cpp index fe5e7f52e..840feb724 100644 --- a/poincare/src/conjugate.cpp +++ b/poincare/src/conjugate.cpp @@ -19,7 +19,7 @@ LayoutRef Conjugate::createLayout(Preferences::PrintFloatMode floatDisplayMode, return ConjugateLayoutRef(operand(0)->createLayout(floatDisplayMode, numberOfSignificantDigits)); } -ExpressionReference Conjugate::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Conjugate::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index dffda5643..05343bb1b 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -32,7 +32,7 @@ std::complex Cosine::computeOnComplex(const std::complex c, Preferences::A return Trigonometry::RoundToMeaningfulDigits(res); } -ExpressionReference Cosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Cosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index e335af874..03ec8adec 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -58,12 +58,12 @@ int DecimalNode::simplificationOrderSameType(const ExpressionNode * e, bool canB return ((int)sign())*unsignedComparison; } -ExpressionReference DecimalNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { - ExpressionReference e = ExpressionNode::shallowReduce(context, angleUnit); +Expression DecimalNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { + Expression e = ExpressionNode::shallowReduce(context, angleUnit); if (e.node() != this) { return e; } - ExpressionReference reference(this); + Expression reference(this); NaturalIntegerPointer m = mantissa(); IntegerReference numerator(&m); removeZeroAtTheEnd(&numerator); @@ -87,8 +87,8 @@ ExpressionReference DecimalNode::shallowReduce(Context& context, Preferences::An return RationalReference(numerator, denominator); } -ExpressionReference DecimalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - ExpressionReference reference(this); +Expression DecimalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { + Expression reference(this); if (m_negative) { m_negative = false; return OppositeReference(reference); diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index c5004d557..f4d0cae92 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -29,7 +29,7 @@ int Derivative::polynomialDegree(char symbolName) const { return Expression::polynomialDegree(symbolName); } -ExpressionReference Derivative::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Derivative::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/determinant.cpp b/poincare/src/determinant.cpp index 97e0c93f1..8f78aeab5 100644 --- a/poincare/src/determinant.cpp +++ b/poincare/src/determinant.cpp @@ -16,7 +16,7 @@ Expression * Determinant::clone() const { return a; } -ExpressionReference Determinant::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Determinant::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index bb1909743..93100af49 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -35,7 +35,7 @@ bool Division::needParenthesisWithParent(const Expression * e) const { return e->isOfType(types, 3); } -ExpressionReference Division::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Division::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/division_quotient.cpp b/poincare/src/division_quotient.cpp index 3c0827176..43ab98131 100644 --- a/poincare/src/division_quotient.cpp +++ b/poincare/src/division_quotient.cpp @@ -18,7 +18,7 @@ Expression * DivisionQuotient::clone() const { return a; } -ExpressionReference DivisionQuotient::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression DivisionQuotient::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/division_remainder.cpp b/poincare/src/division_remainder.cpp index d2c52e496..ffe6b4841 100644 --- a/poincare/src/division_remainder.cpp +++ b/poincare/src/division_remainder.cpp @@ -18,7 +18,7 @@ Expression * DivisionRemainder::clone() const { return a; } -ExpressionReference DivisionRemainder::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression DivisionRemainder::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/equal.cpp b/poincare/src/equal.cpp index e7e95467d..77648deb5 100644 --- a/poincare/src/equal.cpp +++ b/poincare/src/equal.cpp @@ -38,7 +38,7 @@ Expression * Equal::standardEquation(Context & context, Preferences::AngleUnit a return sub; } -ExpressionReference Equal::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Equal::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 70a15ce5a..ce2b5d175 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -13,7 +13,7 @@ //#include "expression_parser.hpp" //#include "expression_lexer.hpp" -int poincare_expression_yyparse(Poincare::ExpressionReference * expressionOutput); +int poincare_expression_yyparse(Poincare::Expression * expressionOutput); namespace Poincare { @@ -21,15 +21,15 @@ namespace Poincare { /* Constructor & Destructor */ -ExpressionReference ExpressionReference::parse(char const * string) { +Expression Expression::parse(char const * string) { if (string[0] == 0) { return nullptr; } YY_BUFFER_STATE buf = poincare_expression_yy_scan_string(string); - ExpressionReference expression(nullptr); + Expression expression(nullptr); if (poincare_expression_yyparse(&expression) != 0) { // Parsing failed because of invalid input or memory exhaustion - expression = ExpressionReference(nullptr); + expression = Expression(nullptr); } poincare_expression_yy_delete_buffer(buf); @@ -38,14 +38,14 @@ ExpressionReference ExpressionReference::parse(char const * string) { /* Circuit breaker */ -static ExpressionReference::CircuitBreaker sCircuitBreaker = nullptr; +static Expression::CircuitBreaker sCircuitBreaker = nullptr; static bool sSimplificationHasBeenInterrupted = false; -void ExpressionReference::setCircuitBreaker(CircuitBreaker cb) { +void Expression::setCircuitBreaker(CircuitBreaker cb) { sCircuitBreaker = cb; } -bool ExpressionReference::shouldStopProcessing() { +bool Expression::shouldStopProcessing() { if (sCircuitBreaker == nullptr) { return false; } @@ -58,11 +58,11 @@ bool ExpressionReference::shouldStopProcessing() { /* Properties */ -bool ExpressionReference::isRationalZero() const { +bool Expression::isRationalZero() const { return this->node()->type() == ExpressionNode::Type::Rational && static_cast(this->node())->isZero(); } -bool ExpressionReference::recursivelyMatches(ExpressionTest test, Context & context) const { +bool Expression::recursivelyMatches(ExpressionTest test, Context & context) const { if (test(*this, context)) { return true; } @@ -74,21 +74,21 @@ bool ExpressionReference::recursivelyMatches(ExpressionTest test, Context & cont return false; } -bool ExpressionReference::isApproximate(Context & context) const { - return recursivelyMatches([](const ExpressionReference e, Context & context) { - return e.node()->type() == ExpressionNode::Type::Decimal || e.node()->type() == ExpressionNode::Type::Double || ExpressionReference::IsMatrix(e, context) || (e.node()->type() == ExpressionNode::Type::Symbol && SymbolReference::isApproximate(static_cast(e.node())->name(), context)); +bool Expression::isApproximate(Context & context) const { + return recursivelyMatches([](const Expression e, Context & context) { + return e.node()->type() == ExpressionNode::Type::Decimal || e.node()->type() == ExpressionNode::Type::Double || Expression::IsMatrix(e, context) || (e.node()->type() == ExpressionNode::Type::Symbol && SymbolReference::isApproximate(static_cast(e.node())->name(), context)); }, context); } -bool ExpressionReference::IsMatrix(const ExpressionReference e, Context & context) { +bool Expression::IsMatrix(const Expression e, Context & context) { return e.node()->type() == ExpressionNode::Type::Matrix || e.node()->type() == ExpressionNode::Type::ConfidenceInterval || e.node()->type() == ExpressionNode::Type::MatrixDimension || e.node()->type() == ExpressionNode::Type::PredictionInterval || e.node()->type() == ExpressionNode::Type::MatrixInverse || e.node()->type() == ExpressionNode::Type::MatrixTranspose || (e.node()->type() == ExpressionNode::Type::Symbol && SymbolReference::isMatrixSymbol(static_cast(e.node())->name())); } -bool dependsOnVariables(const ExpressionReference e, Context & context) { +bool dependsOnVariables(const Expression e, Context & context) { return e.node()->type() == ExpressionNode::Type::Symbol && SymbolReference::isVariableSymbol(static_cast(e.node())->name()); } -bool ExpressionReference::getLinearCoefficients(char * variables, ExpressionReference coefficients[], ExpressionReference constant[], Context & context, Preferences::AngleUnit angleUnit) const { +bool Expression::getLinearCoefficients(char * variables, Expression coefficients[], Expression constant[], Context & context, Preferences::AngleUnit angleUnit) const { char * x = variables; while (*x != 0) { int degree = polynomialDegree(*x); @@ -97,10 +97,10 @@ bool ExpressionReference::getLinearCoefficients(char * variables, ExpressionRefe } x++; } - ExpressionReference equation = clone(); + Expression equation = clone(); x = variables; int index = 0; - ExpressionReference polynomialCoefficients[k_maxNumberOfPolynomialCoefficients]; + Expression polynomialCoefficients[k_maxNumberOfPolynomialCoefficients]; while (*x != 0) { int degree = equation.getPolynomialCoefficients(*x, polynomialCoefficients, context, angleUnit); if (degree == 1) { @@ -126,15 +126,15 @@ bool ExpressionReference::getLinearCoefficients(char * variables, ExpressionRefe } if (isMultivariablePolynomial) { for (int i = 0; i < index; i++) { - coefficients[i] = ExpressionReference(nullptr); + coefficients[i] = Expression(nullptr); } - constant[0] = ExpressionReference(nullptr); + constant[0] = Expression(nullptr); return false; } return true; } -int ExpressionReference::getPolynomialCoefficients(char symbolName, ExpressionReference coefficients[], Context & context, Preferences::AngleUnit angleUnit) const { +int Expression::getPolynomialCoefficients(char symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const { int degree = this->node()->getPolynomialCoefficients(symbolName, coefficients); for (int i = 0; i <= degree; i++) { coefficients[i] = coefficients[i].deepReduce(context, angleUnit); @@ -144,7 +144,7 @@ int ExpressionReference::getPolynomialCoefficients(char symbolName, ExpressionRe /* Comparison */ -bool ExpressionReference::isEqualToItsApproximationLayout(ExpressionReference approximation, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context) { +bool Expression::isEqualToItsApproximationLayout(Expression approximation, int bufferSize, Preferences::AngleUnit angleUnit, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits, Context & context) { char buffer[bufferSize]; approximation.writeTextInBuffer(buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits); /* Warning: we cannot use directly the the approximate expression but we have @@ -153,15 +153,15 @@ bool ExpressionReference::isEqualToItsApproximationLayout(ExpressionReference ap * identical. (For example, 0.000025 might be displayed "0.00003" and stored * as Decimal(0.000025) and isEqualToItsApproximationLayout should return * false) */ - ExpressionReference approximateOutput = ExpressionReference::ParseAndSimplify(buffer, context, angleUnit); + Expression approximateOutput = Expression::ParseAndSimplify(buffer, context, angleUnit); bool equal = isIdenticalTo(approximateOutput); return equal; } /* Simplification */ -ExpressionReference ExpressionReference::ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit) { - ExpressionReference exp = parse(text); +Expression Expression::ParseAndSimplify(const char * text, Context & context, Preferences::AngleUnit angleUnit) { + Expression exp = parse(text); if (!exp.isDefined()) { return UndefinedReference(); } @@ -172,7 +172,7 @@ ExpressionReference ExpressionReference::ParseAndSimplify(const char * text, Con return exp; } -void ExpressionReference::Simplify(ExpressionReference * expressionAddress, Context & context, Preferences::AngleUnit angleUnit) { +void Expression::Simplify(Expression * expressionAddress, Context & context, Preferences::AngleUnit angleUnit) { sSimplificationHasBeenInterrupted = false; #if MATRIX_EXACT_REDUCING #else @@ -183,14 +183,14 @@ void ExpressionReference::Simplify(ExpressionReference * expressionAddress, Cont *expressionAddress = expressionAddress->deepReduce(context, angleUnit); *expressionAddress = expressionAddress->deepBeautify(context, angleUnit); if (sSimplificationHasBeenInterrupted) { - *expressionAddress = ExpressionReference(nullptr); + *expressionAddress = Expression(nullptr); } } -ExpressionReference ExpressionReference::deepReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression Expression::deepReduce(Context & context, Preferences::AngleUnit angleUnit) { int nbChildren = this->numberOfChildren(); for (int i = 0; i < nbChildren; i++) { - ExpressionReference reducedChild = childAtIndex(i).deepReduce(context, angleUnit); + Expression reducedChild = childAtIndex(i).deepReduce(context, angleUnit); if (numberOfChildren() < nbChildren) { addChildTreeAtIndex(reducedChild, i, nbChildren-1); } else { @@ -200,11 +200,11 @@ ExpressionReference ExpressionReference::deepReduce(Context & context, Preferenc return shallowReduce(context, angleUnit); } -ExpressionReference ExpressionReference::deepBeautify(Context & context, Preferences::AngleUnit angleUnit) { - ExpressionReference beautifiedExpression = shallowBeautify(context, angleUnit); +Expression Expression::deepBeautify(Context & context, Preferences::AngleUnit angleUnit) { + Expression beautifiedExpression = shallowBeautify(context, angleUnit); int nbChildren = beautifiedExpression.numberOfChildren(); for (int i = 0; i < nbChildren; i++) { - ExpressionReference beautifiedChild = beautifiedExpression.childAtIndex(i).deepBeautify(context, angleUnit); + Expression beautifiedChild = beautifiedExpression.childAtIndex(i).deepBeautify(context, angleUnit); if (beautifiedExpression.numberOfChildren() < nbChildren) { beautifiedExpression.addChildTreeAtIndex(beautifiedChild, i, nbChildren-1); } else { @@ -217,69 +217,69 @@ ExpressionReference ExpressionReference::deepBeautify(Context & context, Prefere /* Evaluation */ template -ExpressionReference ExpressionReference::approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::Preferences::ComplexFormat complexFormat) const { +Expression Expression::approximate(Context& context, Preferences::AngleUnit angleUnit, Preferences::Preferences::ComplexFormat complexFormat) const { Evaluation e = this->node()->approximate(U(), context, angleUnit); return e->complexToExpression(complexFormat); } template -U ExpressionReference::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const { +U Expression::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const { Evaluation evaluation = this->node()->approximate(U(), context, angleUnit); return evaluation->toScalar(); } template -U ExpressionReference::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit) { - ExpressionReference exp = ParseAndSimplify(text, context, angleUnit); +U Expression::approximateToScalar(const char * text, Context& context, Preferences::AngleUnit angleUnit) { + Expression exp = ParseAndSimplify(text, context, angleUnit); return exp.approximateToScalar(context, angleUnit); } template -U ExpressionReference::approximateWithValueForSymbol(char symbol, U x, Context & context, Preferences::AngleUnit angleUnit) const { +U Expression::approximateWithValueForSymbol(char symbol, U x, Context & context, Preferences::AngleUnit angleUnit) const { VariableContext variableContext = VariableContext(symbol, &context); variableContext.setApproximationForVariable(x); return approximateToScalar(variableContext, angleUnit); } template -U ExpressionReference::epsilon() { +U Expression::epsilon() { static U epsilon = sizeof(U) == sizeof(double) ? 1E-15 : 1E-7f; return epsilon; } /* Expression roots/extrema solver*/ -typename ExpressionReference::Coordinate2D ExpressionReference::nextMinimum(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { - return nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression0, const ExpressionReference expression1 = nullptr) { +typename Expression::Coordinate2D Expression::nextMinimum(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { + return nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = nullptr) { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit); } -typename ExpressionReference::Coordinate2D ExpressionReference::nextMaximum(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { - Coordinate2D minimumOfOpposite = nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression0, const ExpressionReference expression1 = nullptr) { +typename Expression::Coordinate2D Expression::nextMaximum(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { + Coordinate2D minimumOfOpposite = nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = nullptr) { return -expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit); return {.abscissa = minimumOfOpposite.abscissa, .value = -minimumOfOpposite.value}; } -double ExpressionReference::nextRoot(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { - return nextIntersectionWithExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression0, const ExpressionReference expression1 = nullptr) { +double Expression::nextRoot(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { + return nextIntersectionWithExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = nullptr) { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit, nullptr); } -typename ExpressionReference::Coordinate2D ExpressionReference::nextIntersection(char symbol, double start, double step, double max, Poincare::Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression) const { - double resultAbscissa = nextIntersectionWithExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression0, const ExpressionReference expression1) { +typename Expression::Coordinate2D Expression::nextIntersection(char symbol, double start, double step, double max, Poincare::Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const { + double resultAbscissa = nextIntersectionWithExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1) { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit)-expression1.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit, expression); - typename ExpressionReference::Coordinate2D result = {.abscissa = resultAbscissa, .value = approximateWithValueForSymbol(symbol, resultAbscissa, context, angleUnit)}; + typename Expression::Coordinate2D result = {.abscissa = resultAbscissa, .value = approximateWithValueForSymbol(symbol, resultAbscissa, context, angleUnit)}; if (std::fabs(result.value) < step*k_solverPrecision) { result.value = 0.0; } return result; } -typename ExpressionReference::Coordinate2D ExpressionReference::nextMinimumOfExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluate, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression, bool lookForRootMinimum) const { +typename Expression::Coordinate2D Expression::nextMinimumOfExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluate, Context & context, Preferences::AngleUnit angleUnit, const Expression expression, bool lookForRootMinimum) const { Coordinate2D result = {.abscissa = NAN, .value = NAN}; if (start == max || step == 0.0) { return result; @@ -316,7 +316,7 @@ typename ExpressionReference::Coordinate2D ExpressionReference::nextMinimumOfExp return result; } -void ExpressionReference::bracketMinimum(char symbol, double start, double step, double max, double result[3], EvaluationAtAbscissa evaluate, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression) const { +void Expression::bracketMinimum(char symbol, double start, double step, double max, double result[3], EvaluationAtAbscissa evaluate, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const { Coordinate2D p[3]; p[0] = {.abscissa = start, .value = evaluate(symbol, start, context, angleUnit, *this, expression)}; p[1] = {.abscissa = start+step, .value = evaluate(symbol, start+step, context, angleUnit, *this, expression)}; @@ -341,7 +341,7 @@ void ExpressionReference::bracketMinimum(char symbol, double start, double step, result[2] = NAN; } -typename ExpressionReference::Coordinate2D ExpressionReference::brentMinimum(char symbol, double ax, double bx, EvaluationAtAbscissa evaluate, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression) const { +typename Expression::Coordinate2D Expression::brentMinimum(char symbol, double ax, double bx, EvaluationAtAbscissa evaluate, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const { /* Bibliography: R. P. Brent, Algorithms for finding zeros and extrema of * functions without calculating derivatives */ if (ax > bx) { @@ -435,7 +435,7 @@ typename ExpressionReference::Coordinate2D ExpressionReference::brentMinimum(cha return result; } -double ExpressionReference::nextIntersectionWithExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression) const { +double Expression::nextIntersectionWithExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const { if (start == max || step == 0.0) { return NAN; } @@ -451,14 +451,14 @@ double ExpressionReference::nextIntersectionWithExpression(char symbol, double s double extremumMax = std::isnan(result) ? max : result; Coordinate2D resultExtremum[2] = { - nextMinimumOfExpression(symbol, start, step, extremumMax, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression0, const ExpressionReference expression1) { + nextMinimumOfExpression(symbol, start, step, extremumMax, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1) { if (expression1.isDefined()) { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit)-expression1.approximateWithValueForSymbol(symbol, x, context, angleUnit); } else { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); } }, context, angleUnit, expression, true), - nextMinimumOfExpression(symbol, start, step, extremumMax, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression0, const ExpressionReference expression1) { + nextMinimumOfExpression(symbol, start, step, extremumMax, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1) { if (expression1.isDefined()) { return expression1.approximateWithValueForSymbol(symbol, x, context, angleUnit)-expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); } else { @@ -476,7 +476,7 @@ double ExpressionReference::nextIntersectionWithExpression(char symbol, double s return result; } -void ExpressionReference::bracketRoot(char symbol, double start, double step, double max, double result[2], EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression) const { +void Expression::bracketRoot(char symbol, double start, double step, double max, double result[2], EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const { double a = start; double b = start+step; while (step > 0.0 ? b <= max : b >= max) { @@ -494,7 +494,7 @@ void ExpressionReference::bracketRoot(char symbol, double start, double step, do result[1] = NAN; } -double ExpressionReference::brentRoot(char symbol, double ax, double bx, double precision, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const ExpressionReference expression) const { +double Expression::brentRoot(char symbol, double ax, double bx, double precision, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const { if (ax > bx) { return brentRoot(symbol, bx, ax, precision, evaluation, context, angleUnit, expression); } diff --git a/poincare/src/factor.cpp b/poincare/src/factor.cpp index 248147973..b0f5db9fb 100644 --- a/poincare/src/factor.cpp +++ b/poincare/src/factor.cpp @@ -22,7 +22,7 @@ Expression * Factor::clone() const { return b; } -ExpressionReference Factor::shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) { +Expression Factor::shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) { Expression * op = editableOperand(0); if (op->type() != Type::Rational) { return new Undefined(); diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index 88e2ac670..240a1101d 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -36,7 +36,7 @@ bool Factorial::needParenthesisWithParent(const Expression * e) const { /* Simplification */ -ExpressionReference Factorial::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Factorial::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; @@ -66,7 +66,7 @@ ExpressionReference Factorial::shallowReduce(Context& context, Preferences::Angl return this; } -ExpressionReference Factorial::shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) { +Expression Factorial::shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) { // +(a,b)! ->(+(a,b))! if (operand(0)->type() == Type::Addition || operand(0)->type() == Type::Multiplication || operand(0)->type() == Type::Power) { const Expression * o[1] = {operand(0)}; diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index bd5e23ba1..e0cd5592a 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -20,7 +20,7 @@ Expression * Floor::clone() const { return c; } -ExpressionReference Floor::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Floor::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/frac_part.cpp b/poincare/src/frac_part.cpp index 019fb5076..3a2bbc7e3 100644 --- a/poincare/src/frac_part.cpp +++ b/poincare/src/frac_part.cpp @@ -17,7 +17,7 @@ Expression * FracPart::clone() const { return c; } -ExpressionReference FracPart::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression FracPart::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/great_common_divisor.cpp b/poincare/src/great_common_divisor.cpp index ef0069bff..1dcf5d96b 100644 --- a/poincare/src/great_common_divisor.cpp +++ b/poincare/src/great_common_divisor.cpp @@ -19,7 +19,7 @@ Expression * GreatCommonDivisor::clone() const { return a; } -ExpressionReference GreatCommonDivisor::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression GreatCommonDivisor::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/hyperbolic_arc_cosine.cpp b/poincare/src/hyperbolic_arc_cosine.cpp index a1954c459..3c5186882 100644 --- a/poincare/src/hyperbolic_arc_cosine.cpp +++ b/poincare/src/hyperbolic_arc_cosine.cpp @@ -17,7 +17,7 @@ Expression * HyperbolicArcCosine::clone() const { return a; } -ExpressionReference HyperbolicArcCosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicArcCosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/hyperbolic_arc_sine.cpp b/poincare/src/hyperbolic_arc_sine.cpp index 2fd88acda..7cae95c63 100644 --- a/poincare/src/hyperbolic_arc_sine.cpp +++ b/poincare/src/hyperbolic_arc_sine.cpp @@ -17,7 +17,7 @@ Expression * HyperbolicArcSine::clone() const { return a; } -ExpressionReference HyperbolicArcSine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicArcSine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/hyperbolic_arc_tangent.cpp b/poincare/src/hyperbolic_arc_tangent.cpp index 87d990d53..48e48e168 100644 --- a/poincare/src/hyperbolic_arc_tangent.cpp +++ b/poincare/src/hyperbolic_arc_tangent.cpp @@ -17,7 +17,7 @@ Expression * HyperbolicArcTangent::clone() const { return a; } -ExpressionReference HyperbolicArcTangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicArcTangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/hyperbolic_cosine.cpp b/poincare/src/hyperbolic_cosine.cpp index cdad8a2cc..3719a4f09 100644 --- a/poincare/src/hyperbolic_cosine.cpp +++ b/poincare/src/hyperbolic_cosine.cpp @@ -21,7 +21,7 @@ Expression * HyperbolicCosine::clone() const { return a; } -ExpressionReference HyperbolicCosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicCosine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/hyperbolic_sine.cpp b/poincare/src/hyperbolic_sine.cpp index 214194281..7eab2b5ad 100644 --- a/poincare/src/hyperbolic_sine.cpp +++ b/poincare/src/hyperbolic_sine.cpp @@ -21,7 +21,7 @@ Expression * HyperbolicSine::clone() const { return a; } -ExpressionReference HyperbolicSine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicSine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/hyperbolic_tangent.cpp b/poincare/src/hyperbolic_tangent.cpp index f6feebb89..49651ce5b 100644 --- a/poincare/src/hyperbolic_tangent.cpp +++ b/poincare/src/hyperbolic_tangent.cpp @@ -20,7 +20,7 @@ Expression * HyperbolicTangent::clone() const { return a; } -ExpressionReference HyperbolicTangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression HyperbolicTangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/imaginary_part.cpp b/poincare/src/imaginary_part.cpp index 3f8c89d59..ea68ccc26 100644 --- a/poincare/src/imaginary_part.cpp +++ b/poincare/src/imaginary_part.cpp @@ -18,7 +18,7 @@ Expression * ImaginaryPart::clone() const { } -ExpressionReference ImaginaryPart::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression ImaginaryPart::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 47348ebee..95f468ce4 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -406,7 +406,7 @@ void IntegerNode::setDigits(const native_uint_t * digits, size_t size, bool nega m_negative = negative; } -ExpressionReference IntegerNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { +Expression IntegerNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) { return RationalReference(IntegerReference((NaturalIntegerAbstract *)this), IntegerReference(1)); } @@ -446,7 +446,7 @@ size_t IntegerNode::size() const { return m_numberOfDigits*sizeof(native_uint_t)+sizeof(IntegerNode); } -ExpressionReference IntegerNode::setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) { +Expression IntegerNode::setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) { setNegative(s == Sign::Negative); return IntegerReference((NaturalIntegerAbstract *)this); } diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index 3e421979a..e9ab9edef 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -31,7 +31,7 @@ int Integral::polynomialDegree(char symbolName) const { return Expression::polynomialDegree(symbolName); } -ExpressionReference Integral::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Integral::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/least_common_multiple.cpp b/poincare/src/least_common_multiple.cpp index 2b281bd3b..8027c3447 100644 --- a/poincare/src/least_common_multiple.cpp +++ b/poincare/src/least_common_multiple.cpp @@ -19,7 +19,7 @@ Expression * LeastCommonMultiple::clone() const { return a; } -ExpressionReference LeastCommonMultiple::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression LeastCommonMultiple::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index cf2245639..eaf09e7f5 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -59,7 +59,7 @@ Expression * Logarithm::simpleShallowReduce(Context & context, Preferences::Angl return this; } -ExpressionReference Logarithm::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Logarithm::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index 7c91dab53..2c6087027 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -118,7 +118,7 @@ int MatrixReference::numberOfColumns() const { } void MatrixReference::addChildTreeAtIndex(TreeReference t, int index, int currentNumberOfChildren) { - ExpressionReference::addChildTreeAtIndex(t, index, currentNumberOfChildren); + Expression::addChildTreeAtIndex(t, index, currentNumberOfChildren); if (isAllocationFailure()) { return; } @@ -133,7 +133,7 @@ int MatrixReference::rank(Context & context, Preferences::AngleUnit angleUnit, b int i = rank-1; while (i >= 0) { int j = m.numberOfColumns()-1; - ExpressionReference child = matrixChild(i,j); + Expression child = matrixChild(i,j); if (child.isAllocationFailure()) { return 0; } @@ -200,7 +200,7 @@ void MatrixReference::setNumberOfColumns(int columns) { void MatrixReference::rowCanonize(Context & context, Preferences::AngleUnit angleUnit, MultiplicationReference determinant) { // The matrix has to be reduced to be able to spot 0 inside it - ExpressionReference reduced = deepReduce(context, angleUnit); + Expression reduced = deepReduce(context, angleUnit); /* The MatrixNode should change only in 2 cases: * - Allocation failure * - One of the child is Undefined @@ -236,12 +236,12 @@ void MatrixReference::rowCanonize(Context & context, Preferences::AngleUnit angl if (determinant) { determinant.addChildTreeAtIndex(RationalReference(-1), 0, determinant.numberOfChildren()); } } /* Set to 1 M[h][k] by linear combination */ - ExpressionReference divisor = matrixChild(h, k); + Expression divisor = matrixChild(h, k); // Update determinant: det *= divisor if (determinant) { determinant.addChildTreeAtIndex(divisor.clone()); } for (int j = k+1; j < n; j++) { - ExpressionReference opHJ = matrixChild(h, j); - ExpressionReference newOpHJ = DivisionReference(opHJ, divisor.clone()); + Expression opHJ = matrixChild(h, j); + Expression newOpHJ = DivisionReference(opHJ, divisor.clone()); replaceTreeChildAtIndex(h*n+j, newOpHJ); newOpHJ.node()->shallowReduce(context, angleUnit); } @@ -250,10 +250,10 @@ void MatrixReference::rowCanonize(Context & context, Preferences::AngleUnit angl /* Set to 0 all M[i][j] i != h, j > k by linear combination */ for (int i = 0; i < m; i++) { if (i == h) { continue; } - ExpressionReference factor = matrixChild(i, k); + Expression factor = matrixChild(i, k); for (int j = k+1; j < n; j++) { - ExpressionReference opIJ = matrixChild(i, j); - ExpressionReference newOpIJ = SubtractionReference(opIJ, MultiplicationReference(matrixChild(h, j).clone(), factor.clone())); + Expression opIJ = matrixChild(i, j); + Expression newOpIJ = SubtractionReference(opIJ, MultiplicationReference(matrixChild(h, j).clone(), factor.clone())); replaceTreeChildAtIndex(i*n+j, newOpIJ); newOpIJ.childAtIndex(1)->node()->shallowReduce(context, angleUnit); newOpIJ.node()->shallowReduce(context, angleUnit); diff --git a/poincare/src/matrix_dimension.cpp b/poincare/src/matrix_dimension.cpp index 17f78b409..58b27c276 100644 --- a/poincare/src/matrix_dimension.cpp +++ b/poincare/src/matrix_dimension.cpp @@ -16,7 +16,7 @@ Expression * MatrixDimension::clone() const { return a; } -ExpressionReference MatrixDimension::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression MatrixDimension::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/matrix_inverse.cpp b/poincare/src/matrix_inverse.cpp index 142cb5cf8..e3c9eb6d7 100644 --- a/poincare/src/matrix_inverse.cpp +++ b/poincare/src/matrix_inverse.cpp @@ -19,7 +19,7 @@ Expression * MatrixInverse::clone() const { return a; } -ExpressionReference MatrixInverse::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression MatrixInverse::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/matrix_trace.cpp b/poincare/src/matrix_trace.cpp index 905ef5657..d23404214 100644 --- a/poincare/src/matrix_trace.cpp +++ b/poincare/src/matrix_trace.cpp @@ -18,7 +18,7 @@ Expression * MatrixTrace::clone() const { return a; } -ExpressionReference MatrixTrace::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression MatrixTrace::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/matrix_transpose.cpp b/poincare/src/matrix_transpose.cpp index 04d000f4b..0d2e40864 100644 --- a/poincare/src/matrix_transpose.cpp +++ b/poincare/src/matrix_transpose.cpp @@ -17,7 +17,7 @@ Expression * MatrixTranspose::clone() const { return a; } -ExpressionReference MatrixTranspose::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression MatrixTranspose::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 5ed15dd85..125258bf6 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -43,7 +43,7 @@ int Multiplication::polynomialDegree(char symbolName) const { return degree; } -int Multiplication::getPolynomialCoefficients(char symbolName, ExpressionReference coefficients[]) const { +int Multiplication::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const { int deg = polynomialDegree(symbolName); if (deg < 0 || deg > k_maxPolynomialDegree) { return -1; @@ -174,7 +174,7 @@ static inline const Expression * Base(const Expression * e) { return e; } -ExpressionReference Multiplication::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Multiplication::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { return privateShallowReduce(context, angleUnit, true, true); } diff --git a/poincare/src/n_ary_expression_node.cpp b/poincare/src/n_ary_expression_node.cpp index 42ccf4ea9..e2c84b0dd 100644 --- a/poincare/src/n_ary_expression_node.cpp +++ b/poincare/src/n_ary_expression_node.cpp @@ -7,7 +7,7 @@ extern "C" { namespace Poincare { void NAryExpressionNode::sortOperands(ExpressionOrder order, bool canBeInterrupted) { - ExpressionReference reference(this); + Expression reference(this); for (int i = reference.numberOfChildren()-1; i > 0; i--) { bool isSorted = true; for (int j = 0; j < reference.numberOfChildren()-1; j++) { @@ -28,11 +28,11 @@ void NAryExpressionNode::sortOperands(ExpressionOrder order, bool canBeInterrupt } } -ExpressionReference NAryExpressionNode::squashUnaryHierarchy() { - ExpressionReference reference(this); +Expression NAryExpressionNode::squashUnaryHierarchy() { + Expression reference(this); if (reference.numberOfChildren() == 1) { assert(parent() != nullptr); - ExpressionReference o = reference.childAtIndex(0); + Expression o = reference.childAtIndex(0); reference.replaceWith(o); return o; } diff --git a/poincare/src/naperian_logarithm.cpp b/poincare/src/naperian_logarithm.cpp index 10ad148d2..391b5ce92 100644 --- a/poincare/src/naperian_logarithm.cpp +++ b/poincare/src/naperian_logarithm.cpp @@ -20,7 +20,7 @@ Expression * NaperianLogarithm::clone() const { return a; } -ExpressionReference NaperianLogarithm::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression NaperianLogarithm::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index fa3400904..864ab17c6 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -19,7 +19,7 @@ Expression * NthRoot::clone() const { NthRoot * a = new NthRoot(m_operands, true); return a; } -ExpressionReference NthRoot::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression NthRoot::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 4e6eeb333..472ad0123 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -84,12 +84,12 @@ Expression Opposite::shallowReduce(Context & context, Preferences::AngleUnit ang } #if 0 -ExpressionReference OppositeNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { - ExpressionReference e = ExpressionNode::shallowReduce(context, angleUnit); +Expression OppositeNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { + Expression e = ExpressionNode::shallowReduce(context, angleUnit); if (e.node() != this) { return e; } - const ExpressionReference child = ExpressionReference(childAtIndex(0)); + const Expression child = Expression(childAtIndex(0)); #if MATRIX_EXACT_REDUCING if (op->type() == Type::Matrix) { return SimplificationEngine::map(this, context, angleUnit); diff --git a/poincare/src/parenthesis.cpp b/poincare/src/parenthesis.cpp index 27c1d3a42..ec6a2afd8 100644 --- a/poincare/src/parenthesis.cpp +++ b/poincare/src/parenthesis.cpp @@ -17,12 +17,12 @@ LayoutRef ParenthesisNode::createLayout(Preferences::PrintFloatMode floatDisplay return LayoutEngine::createParenthesedLayout(childAtIndex(0)->createLayout(floatDisplayMode, numberOfSignificantDigits), false); } -int ParenthesisNode::writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { - return LayoutEngine::writePrefixSerializableRefTextInBuffer(Parenthesis(const_cast(this)), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, ""); -} - -Expression ParenthesisNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const { - return Parenthesis(this).shallowReduce(context, angleUnit); +Expression ParenthesisNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { + Expression e = ExpressionNode::shallowReduce(context, angleUnit); + if (e.node() != this) { + return e; + } + return Expression(childAtIndex(0)); } template diff --git a/poincare/src/permute_coefficient.cpp b/poincare/src/permute_coefficient.cpp index 509ed6ca8..b4645184e 100644 --- a/poincare/src/permute_coefficient.cpp +++ b/poincare/src/permute_coefficient.cpp @@ -18,7 +18,7 @@ Expression * PermuteCoefficient::clone() const { return b; } -ExpressionReference PermuteCoefficient::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression PermuteCoefficient::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 62138baac..bfc197fe5 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -83,7 +83,7 @@ int Power::polynomialDegree(char symbolName) const { return -1; } -int Power::getPolynomialCoefficients(char symbolName, ExpressionReference coefficients[]) const { +int Power::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const { int deg = polynomialDegree(symbolName); if (deg <= 0) { return Expression::privateGetPolynomialCoefficients(symbolName, coefficients); @@ -205,7 +205,7 @@ int Power::simplificationOrderGreaterType(const Expression * e, bool canBeInterr return SimplificationOrder(operand(1), &one, canBeInterrupted); } -ExpressionReference Power::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Power::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; @@ -665,7 +665,7 @@ Expression * Power::CreateNthRootOfUnity(const Rational r) { #endif } -ExpressionReference Power::shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) { +Expression Power::shallowBeautify(Context& context, Preferences::AngleUnit angleUnit) { // X^-y -> 1/(X->shallowBeautify)^y if (operand(1)->sign() == Sign::Negative) { Expression * p = cloneDenominator(context, angleUnit); diff --git a/poincare/src/prediction_interval.cpp b/poincare/src/prediction_interval.cpp index 087c1e6ec..d9100da2d 100644 --- a/poincare/src/prediction_interval.cpp +++ b/poincare/src/prediction_interval.cpp @@ -25,7 +25,7 @@ int PredictionInterval::polynomialDegree(char symbolName) const { return -1; } -ExpressionReference PredictionInterval::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression PredictionInterval::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index 0242378ba..02bd19423 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -132,8 +132,8 @@ int RationalNode::simplificationOrderSameType(const ExpressionNode * e, bool can // Simplification -ExpressionReference RationalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { - ExpressionReference reference(this); +Expression RationalNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) { + Expression reference(this); if (m_negative) { m_negative = false; return OppositeReference(reference); @@ -141,9 +141,9 @@ ExpressionReference RationalNode::shallowBeautify(Context & context, Preferences return reference; } -ExpressionReference RationalNode::cloneDenominator(Context & context, Preferences::AngleUnit angleUnit) const { +Expression RationalNode::cloneDenominator(Context & context, Preferences::AngleUnit angleUnit) const { if (denominator().isOne()) { - return ExpressionReference(nullptr); + return Expression(nullptr); } NaturalIntegerPointer d = denominator(); assert(!d.isInfinity()); diff --git a/poincare/src/real_part.cpp b/poincare/src/real_part.cpp index 0df595f41..fe36fb654 100644 --- a/poincare/src/real_part.cpp +++ b/poincare/src/real_part.cpp @@ -16,7 +16,7 @@ Expression * RealPart::clone() const { return a; } -ExpressionReference RealPart::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression RealPart::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/round.cpp b/poincare/src/round.cpp index 919bd1dc8..9f2b9ec4d 100644 --- a/poincare/src/round.cpp +++ b/poincare/src/round.cpp @@ -19,7 +19,7 @@ Expression * Round::clone() const { return c; } -ExpressionReference Round::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Round::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index d6aad46d9..80af8c725 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -32,7 +32,7 @@ std::complex Sine::computeOnComplex(const std::complex c, Preferences::Ang return Trigonometry::RoundToMeaningfulDigits(res); } -ExpressionReference Sine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Sine::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 879cabfca..937e3d31e 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -36,7 +36,7 @@ std::complex SquareRoot::computeOnComplex(const std::complex c, Preference return ApproximationEngine::truncateRealOrImaginaryPartAccordingToArgument(result); } -ExpressionReference SquareRoot::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression SquareRoot::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index db91f56d7..bb7647876 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -28,7 +28,7 @@ int Store::writeTextInBuffer(char * buffer, int bufferSize, Preferences::PrintFl return LayoutEngine::writeInfixExpressionTextInBuffer(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "\x90"); } -ExpressionReference Store::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Store::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { context.setExpressionForSymbolName(value(), symbol(), context); return replaceWith(editableOperand(1), true)->shallowReduce(context, angleUnit); } diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index bce3c663f..70eaaed65 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -54,7 +54,7 @@ template MatrixComplex Subtraction::computeOnComplexAndMatrix(con return result; } -ExpressionReference Subtraction::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Subtraction::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e; diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index a1cd709ff..5ac41be13 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -33,7 +33,14 @@ ExpressionNode::Sign SymbolNode::sign() const { } Expression SymbolNode::replaceSymbolWithExpression(char symbol, Expression expression) { - return Symbol(this).replaceSymbolWithExpression(symbol, expression); + if (m_name == symbol) { + Expression value = expression.clone(); + if (parent() && value.needsParenthesisWithParent(parent())) { + value = ParenthesisReference(value); + } + return value; + } + return Expression(this); } int SymbolNode::polynomialDegree(char symbol) const { @@ -44,7 +51,13 @@ int SymbolNode::polynomialDegree(char symbol) const { } int SymbolNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const { - return Symbol(this).getPolynomialCoefficients(symbolName, coefficients); + if (m_name == symbolName) { + coefficients[0] = RationalReference(0); + coefficients[1] = RationalReference(1); + return 1; + } + coefficients[0] = SymbolReference(m_name); + return 0; } int SymbolNode::getVariables(isVariableTest isVariable, char * variables) const { @@ -140,8 +153,22 @@ int SymbolNode::writeTextInBuffer(char * buffer, int bufferSize, Preferences::Pr return 1; } -Expression SymbolNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const { - return Symbol(this).shallowReduce(context, angleUnit); +Expression SymbolNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { + // Do not replace symbols in expression of type: 3->A + if (parent() && parent()->type() == Type::Store && parent()->childAtIndex(1) == this) { + return this; + } + const Expression e = context.expressionForSymbol(SymbolReference(m_name)); + if (e.isDefined() && hasAnExactRepresentation(context)) { // TODO: later AZ should be replaced. + /* The stored expression had been beautified which forces to call deepReduce. */ + return e.clone().deepReduce(context, angleUnit); + } + return Expression(this); +} + +bool SymbolNode::hasAnExactRepresentation(Context & context) const { + // TODO: so far, no symbols can be exact but A, ..Z should be able to hold exact values later. + return false; } template @@ -149,7 +176,7 @@ Evaluation SymbolNode::templatedApproximate(Context& context, Preferences::An if (m_name == Ion::Charset::IComplex) { return Complex(0.0, 1.0); } - const Expression e = context.expressionForSymbol(Symbol(m_name)); + const Expression e = context.expressionForSymbol(SymbolReference(m_name)); if (e.isDefined()) { return e.node()->approximate(T(), context, angleUnit); } diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index cd09c99b3..3a2b4cbaa 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -33,7 +33,7 @@ std::complex Tangent::computeOnComplex(const std::complex c, Preferences:: return Trigonometry::RoundToMeaningfulDigits(res); } -ExpressionReference Tangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { +Expression Tangent::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) { Expression * e = Expression::shallowReduce(context, angleUnit); if (e != this) { return e;