mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-25 08:41:01 +01:00
[poincare] ExpressionReference becomes Expression
This commit is contained in:
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(Expression::SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> * privateApproximate(Expression::DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationEngine::map<float>(this, context, angleUnit,computeOnComplex<float>);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<typename T> static MatrixComplex<T> computeOnMatrixAndComplex(const MatrixComplex<T> m, const std::complex<T> c) {
|
||||
return ApproximationEngine::elementWiseOnMatrixComplexAndComplex(m, c, compute<T>);
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationEngine::map<float>(this, context, angleUnit,computeOnComplex<float>);
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationEngine::map<float>(this, context, angleUnit,computeOnComplex<float>);
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationEngine::map<float>(this, context, angleUnit,computeOnComplex<float>);
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return ComplexReference<float>(templatedApproximate<float>()); }
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
int m_numberOfColumns;
|
||||
};
|
||||
|
||||
class MatrixReference : public ExpressionReference {
|
||||
class MatrixReference : public Expression {
|
||||
template<typename T> 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<typename T> 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<MatrixNode *>(node()); }
|
||||
void setNumberOfRows(int rows);
|
||||
void setNumberOfColumns(int columns);
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -32,13 +32,13 @@ public:
|
||||
template<typename T> static MatrixComplex<T> computeOnMatrices(const MatrixComplex<T> m, const MatrixComplex<T> 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
@@ -34,12 +36,9 @@ private:
|
||||
template<typename T> Evaluation<T> 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<ParenthesisNode>())
|
||||
{
|
||||
ParenthesisReference(Expression exp) : Expression(TreePool::sharedPool()->createTreeNode<ParenthesisNode>()) {
|
||||
replaceChildAtIndexInPlace(0, exp);
|
||||
}
|
||||
// Expression
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<float> approximate(Expression::SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> * privateApproximate(Expression::DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
Sign sign() const override { return Sign::Positive; }
|
||||
template<typename T> 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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
|
||||
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
return ApproximationEngine::map<float>(this, context, angleUnit,computeOnComplex<float>);
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<typename T> static MatrixComplex<T> computeOnMatrixAndComplex(const MatrixComplex<T> m, const std::complex<T> c) {
|
||||
return ApproximationEngine::elementWiseOnMatrixComplexAndComplex(m, c, compute<T>);
|
||||
|
||||
@@ -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<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(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<SymbolNode>()) {
|
||||
node()->setName(name);
|
||||
SymbolReference(const char name) : Expression(TreePool::sharedPool()->createTreeNode<SymbolNode>()) {
|
||||
if (!node->isAllocationFailure()) {
|
||||
static_cast<SymbolNode *>(node)->setName(name);
|
||||
}
|
||||
}
|
||||
|
||||
// Symbol properties
|
||||
|
||||
@@ -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<typename T> static std::complex<T> computeOnComplex(const std::complex<T> c, Preferences::AngleUnit angleUnit = Preferences::AngleUnit::Radian);
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -32,7 +32,7 @@ std::complex<T> Cosine::computeOnComplex(const std::complex<T> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<const RationalNode *>(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<SymbolNode *>(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<SymbolNode *>(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<SymbolNode *>(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<SymbolNode *>(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<typename U>
|
||||
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<U> e = this->node()->approximate(U(), context, angleUnit);
|
||||
return e->complexToExpression(complexFormat);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
U ExpressionReference::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const {
|
||||
U Expression::approximateToScalar(Context& context, Preferences::AngleUnit angleUnit) const {
|
||||
Evaluation<U> evaluation = this->node()->approximate(U(), context, angleUnit);
|
||||
return evaluation->toScalar();
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
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<U>(context, angleUnit);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
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<U> variableContext = VariableContext<U>(symbol, &context);
|
||||
variableContext.setApproximationForVariable(x);
|
||||
return approximateToScalar<U>(variableContext, angleUnit);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user