mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Add context argument to some ExpressionNode methods
This commit is contained in:
@@ -266,7 +266,8 @@ bool StoreController::privateFillColumnWithFormula(Expression formula, Expressio
|
||||
// Fetch the series used in the formula to compute the size of the filled in series
|
||||
char variables[Expression::k_maxNumberOfVariables];
|
||||
variables[0] = 0;
|
||||
formula.getVariables(isVariable, variables);
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
formula.getVariables(*(appsContainer->globalContext()), isVariable, variables);
|
||||
int numberOfValuesToCompute = -1;
|
||||
int index = 0;
|
||||
while (variables[index] != 0) {
|
||||
|
||||
@@ -107,7 +107,7 @@ EquationStore::Error EquationStore::exactSolve(Poincare::Context * context) {
|
||||
if (e.isUninitialized() || e.type() == ExpressionNode::Type::Undefined) {
|
||||
return Error::EquationUndefined;
|
||||
}
|
||||
numberOfVariables = definedModelAtIndex(i)->standardForm(context).getVariables(Symbol::isVariableSymbol, m_variables);
|
||||
numberOfVariables = definedModelAtIndex(i)->standardForm(context).getVariables(*context, Symbol::isVariableSymbol, m_variables);
|
||||
if (numberOfVariables < 0) {
|
||||
return Error::TooManyVariables;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Addition; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const override;
|
||||
|
||||
// Evaluation
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d) { return Complex<T>(c+d); }
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const;
|
||||
private:
|
||||
static const Number NumeralFactor(const Expression & e);
|
||||
static inline int NumberOfNonNumeralFactors(const Expression & e);
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::ConfidenceInterval; }
|
||||
int polynomialDegree(char symbolName) const override { return -1; }
|
||||
int polynomialDegree(Context & context, char symbolName) const override { return -1; }
|
||||
private:
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Derivative; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
|
||||
private:
|
||||
// Layout
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Division; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
|
||||
// Approximation
|
||||
virtual Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
// ExpressionNode
|
||||
Type type() const override { return Type::Equal; }
|
||||
int polynomialDegree(char symbolName) const override { return -1; }
|
||||
int polynomialDegree(Context & context, char symbolName) const override { return -1; }
|
||||
private:
|
||||
// Simplification
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
|
||||
@@ -121,14 +121,14 @@ public:
|
||||
/* polynomialDegree returns:
|
||||
* - (-1) if the expression is not a polynome
|
||||
* - the degree of the polynome otherwise */
|
||||
int polynomialDegree(char symbolName) const { return this->node()->polynomialDegree(symbolName); }
|
||||
int polynomialDegree(Context & context, char symbolName) const { return this->node()->polynomialDegree(context, symbolName); }
|
||||
/* getVariables fills the table variables with the variable present in the
|
||||
* expression and returns the number of entries in filled in variables.
|
||||
* For instance getVariables('x+y+2*w/cos(4)') would result in
|
||||
* variables = « xyw » and would return 3. If the final number of
|
||||
* variables would overflow the maxNumberOfVariables, getVariables return -1 */
|
||||
static constexpr int k_maxNumberOfVariables = 6;
|
||||
int getVariables(ExpressionNode::isVariableTest isVariable, char * variables) const { return node()->getVariables(isVariable, variables); }
|
||||
int getVariables(Context & context, ExpressionNode::isVariableTest isVariable, char * variables) const { return node()->getVariables(context, isVariable, variables); }
|
||||
static bool DependsOnVariables(const Expression e, Context & context);
|
||||
/* getLinearCoefficients return false if the expression is not linear with
|
||||
* the variables hold in 'variables'. Otherwise, it fills 'coefficients' with
|
||||
@@ -213,7 +213,7 @@ protected:
|
||||
void removeChildrenInPlace(int currentNumberOfChildren) = delete;
|
||||
|
||||
/* Properties */
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const { return node()->getPolynomialCoefficients(symbolName, coefficients); }
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const { return node()->getPolynomialCoefficients(context, symbolName, coefficients); }
|
||||
|
||||
/* Simplification */
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const { return node()->denominator(context, angleUnit); }
|
||||
@@ -231,7 +231,7 @@ private:
|
||||
|
||||
/* Properties */
|
||||
Expression defaultReplaceSymbolWithExpression(char symbol, Expression expression);
|
||||
int defaultGetPolynomialCoefficients(char symbol, Expression expression[]) const;
|
||||
int defaultGetPolynomialCoefficients(Context & context, char symbol, Expression expression[]) const;
|
||||
|
||||
/* Expression roots/extrema solver*/
|
||||
constexpr static double k_solverPrecision = 1.0E-5;
|
||||
|
||||
@@ -100,10 +100,10 @@ public:
|
||||
virtual bool isNumber() const { return false; }
|
||||
/*!*/ virtual Expression replaceSymbolWithExpression(char symbol, Expression & expression);
|
||||
/*!*/ virtual Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit);
|
||||
virtual int polynomialDegree(char symbolName) const;
|
||||
/*!*/ virtual int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const;
|
||||
virtual int polynomialDegree(Context & context, char symbolName) const;
|
||||
/*!*/ virtual int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const;
|
||||
typedef bool (*isVariableTest)(char c);
|
||||
virtual int getVariables(isVariableTest isVariable, char * variables) const;
|
||||
virtual int getVariables(Context & context, isVariableTest isVariable, char * variables) const;
|
||||
virtual float characteristicXRange(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
bool isOfType(Type * types, int length) const;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
|
||||
// ExpressionNode
|
||||
Type type() const override { return Type::Integral; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
private:
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Matrix; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
|
||||
// Approximation
|
||||
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override {
|
||||
|
||||
@@ -22,8 +22,8 @@ public:
|
||||
// Properties
|
||||
Type type() const override { return Type::Multiplication; }
|
||||
Sign sign() const override;
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const override;
|
||||
|
||||
// Approximation
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d) { return Complex<T>(c*d); }
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
Expression setSign(ExpressionNode::Sign s, Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const;
|
||||
Expression denominator(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
private:
|
||||
// Simplification
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Opposite; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
Sign sign() const override;
|
||||
|
||||
// Approximation
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Parenthesis; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -27,8 +27,8 @@ public:
|
||||
Sign sign() const override;
|
||||
Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const override;
|
||||
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d);
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
Power(Expression base, Expression exponent);
|
||||
Power(const PowerNode * n) : Expression(n) {}
|
||||
Expression setSign(ExpressionNode::Sign s, Context & context, Preferences::AngleUnit angleUnit);
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const;
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression shallowBeautify(Context & context, Preferences::AngleUnit angleUnit);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::PredictionInterval; }
|
||||
int polynomialDegree(char symbolName) const override { return -1; }
|
||||
int polynomialDegree(Context & context, char symbolName) const override { return -1; }
|
||||
private:
|
||||
// Layout
|
||||
Layout createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
|
||||
// ExpressionNode
|
||||
Type type() const override { return Type::Store; }
|
||||
int polynomialDegree(char symbolName) const override { return -1; }
|
||||
int polynomialDegree(Context & context, char symbolName) const override { return -1; }
|
||||
|
||||
private:
|
||||
// Simplification
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Subtraction; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
|
||||
// Approximation
|
||||
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d) { return Complex<T>(c - d); }
|
||||
|
||||
@@ -30,9 +30,9 @@ public:
|
||||
Type type() const override { return Type::Symbol; }
|
||||
Sign sign() const override;
|
||||
Expression replaceSymbolWithExpression(char symbol, Expression & expression) override;
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const override;
|
||||
int getVariables(isVariableTest isVariable, char * variables) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const override;
|
||||
int getVariables(Context & context, isVariableTest isVariable, char * variables) const override;
|
||||
float characteristicXRange(Context & context, Preferences::AngleUnit angleUnit) const override;
|
||||
|
||||
/* Comparison */
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
// Expression
|
||||
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit);
|
||||
Expression replaceSymbolWithExpression(char symbol, Expression & expression);
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const;
|
||||
int getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const;
|
||||
|
||||
// Symbol
|
||||
char name() const { return node()->name(); }
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Undefined; }
|
||||
int polynomialDegree(char symbolName) const override;
|
||||
int polynomialDegree(Context & context, char symbolName) const override;
|
||||
Expression setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) override;
|
||||
|
||||
// Approximation
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int AdditionNode::polynomialDegree(char symbolName) const {
|
||||
int AdditionNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
int degree = 0;
|
||||
for (ExpressionNode * e : children()) {
|
||||
int d = e->polynomialDegree(symbolName);
|
||||
int d = e->polynomialDegree(context, symbolName);
|
||||
if (d < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -21,8 +21,8 @@ int AdditionNode::polynomialDegree(char symbolName) const {
|
||||
return degree;
|
||||
}
|
||||
|
||||
int AdditionNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
return Addition(this).getPolynomialCoefficients(symbolName, coefficients);
|
||||
int AdditionNode::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
return Addition(this).getPolynomialCoefficients(context, symbolName, coefficients);
|
||||
}
|
||||
|
||||
// Private
|
||||
@@ -60,8 +60,8 @@ const Number Addition::NumeralFactor(const Expression & e) {
|
||||
return Rational(1);
|
||||
}
|
||||
|
||||
int Addition::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(symbolName);
|
||||
int Addition::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(context, symbolName);
|
||||
if (deg < 0 || deg > Expression::k_maxPolynomialDegree) {
|
||||
return -1;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ int Addition::getPolynomialCoefficients(char symbolName, Expression coefficients
|
||||
}
|
||||
Expression intermediateCoefficients[Expression::k_maxNumberOfPolynomialCoefficients];
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
int d = childAtIndex(i).getPolynomialCoefficients(symbolName, intermediateCoefficients);
|
||||
int d = childAtIndex(i).getPolynomialCoefficients(context, symbolName, intermediateCoefficients);
|
||||
assert(d < Expression::k_maxNumberOfPolynomialCoefficients);
|
||||
for (int j = 0; j < d+1; j++) {
|
||||
static_cast<Addition&>(coefficients[j]).addChildAtIndexInPlace(intermediateCoefficients[j], coefficients[j].numberOfChildren(), coefficients[j].numberOfChildren());
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int DerivativeNode::polynomialDegree(char symbolName) const {
|
||||
if (childAtIndex(0)->polynomialDegree(symbolName) == 0
|
||||
&& childAtIndex(1)->polynomialDegree(symbolName) == 0)
|
||||
int DerivativeNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
if (childAtIndex(0)->polynomialDegree(context, symbolName) == 0
|
||||
&& childAtIndex(1)->polynomialDegree(context, symbolName) == 0)
|
||||
{
|
||||
// If no child depends on the symbol, the polynomial degree is 0.
|
||||
return 0;
|
||||
}
|
||||
// If one of the children depends on the symbol, we do not know the degree.
|
||||
return ExpressionNode::polynomialDegree(symbolName);
|
||||
return ExpressionNode::polynomialDegree(context, symbolName);
|
||||
}
|
||||
|
||||
Expression DerivativeNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int DivisionNode::polynomialDegree(char symbolName) const {
|
||||
if (childAtIndex(1)->polynomialDegree(symbolName) != 0) {
|
||||
int DivisionNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
if (childAtIndex(1)->polynomialDegree(context, symbolName) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return childAtIndex(0)->polynomialDegree(symbolName);
|
||||
return childAtIndex(0)->polynomialDegree(context, symbolName);
|
||||
}
|
||||
|
||||
bool DivisionNode::childNeedsParenthesis(const TreeNode * child) const {
|
||||
|
||||
@@ -109,7 +109,7 @@ bool Expression::getLinearCoefficients(char * variables, Expression coefficients
|
||||
assert(!recursivelyMatches(IsMatrix, context));
|
||||
char * x = variables;
|
||||
while (*x != 0) {
|
||||
int degree = polynomialDegree(*x);
|
||||
int degree = polynomialDegree(context, *x);
|
||||
if (degree > 1 || degree < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -193,8 +193,8 @@ Expression Expression::defaultReplaceSymbolWithExpression(char symbol, Expressio
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Expression::defaultGetPolynomialCoefficients(char symbol, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(symbol);
|
||||
int Expression::defaultGetPolynomialCoefficients(Context & context, char symbol, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(context, symbol);
|
||||
if (deg == 0) {
|
||||
coefficients[0] = clone();
|
||||
return 0;
|
||||
@@ -203,7 +203,7 @@ int Expression::defaultGetPolynomialCoefficients(char symbol, Expression coeffic
|
||||
}
|
||||
|
||||
int Expression::getPolynomialReducedCoefficients(char symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
int degree = getPolynomialCoefficients(symbolName, coefficients);
|
||||
int degree = getPolynomialCoefficients(context, symbolName, coefficients);
|
||||
for (int i = 0; i <= degree; i++) {
|
||||
coefficients[i] = coefficients[i].deepReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
@@ -13,23 +13,23 @@ Expression ExpressionNode::setSign(Sign s, Context & context, Preferences::Angle
|
||||
return Expression();
|
||||
}
|
||||
|
||||
int ExpressionNode::polynomialDegree(char symbolName) const {
|
||||
int ExpressionNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
for (ExpressionNode * c : children()) {
|
||||
if (c->polynomialDegree(symbolName) != 0) {
|
||||
if (c->polynomialDegree(context, symbolName) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ExpressionNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
return Expression(this).defaultGetPolynomialCoefficients(symbolName, coefficients);
|
||||
int ExpressionNode::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
return Expression(this).defaultGetPolynomialCoefficients(context, symbolName, coefficients);
|
||||
}
|
||||
|
||||
int ExpressionNode::getVariables(isVariableTest isVariable, char * variables) const {
|
||||
int ExpressionNode::getVariables(Context & context, isVariableTest isVariable, char * variables) const {
|
||||
int numberOfVariables = 0;
|
||||
for (ExpressionNode * c : children()) {
|
||||
int n = c->getVariables(isVariable, variables);
|
||||
int n = c->getVariables(context, isVariable, variables);
|
||||
if (n < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int IntegralNode::polynomialDegree(char symbolName) const {
|
||||
if (childAtIndex(0)->polynomialDegree(symbolName) == 0
|
||||
&& childAtIndex(1)->polynomialDegree(symbolName) == 0
|
||||
&& childAtIndex(2)->polynomialDegree(symbolName) == 0)
|
||||
int IntegralNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
if (childAtIndex(0)->polynomialDegree(context, symbolName) == 0
|
||||
&& childAtIndex(1)->polynomialDegree(context, symbolName) == 0
|
||||
&& childAtIndex(2)->polynomialDegree(context, symbolName) == 0)
|
||||
{
|
||||
// If no child depends on the symbol, the polynomial degree is 0.
|
||||
return 0;
|
||||
}
|
||||
return ExpressionNode::polynomialDegree(symbolName);
|
||||
return ExpressionNode::polynomialDegree(context, symbolName);
|
||||
}
|
||||
|
||||
Layout IntegralNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
|
||||
@@ -17,7 +17,7 @@ void MatrixNode::didAddChildAtIndex(int newNumberOfChildren) {
|
||||
setNumberOfColumns(newNumberOfChildren);
|
||||
}
|
||||
|
||||
int MatrixNode::polynomialDegree(char symbolName) const {
|
||||
int MatrixNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,10 @@ ExpressionNode::Sign MultiplicationNode::sign() const {
|
||||
return (Sign)sign;
|
||||
}
|
||||
|
||||
int MultiplicationNode::polynomialDegree(char symbolName) const {
|
||||
int MultiplicationNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
int degree = 0;
|
||||
for (ExpressionNode * c : children()) {
|
||||
int d = c->polynomialDegree(symbolName);
|
||||
int d = c->polynomialDegree(context, symbolName);
|
||||
if (d < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -40,8 +40,8 @@ int MultiplicationNode::polynomialDegree(char symbolName) const {
|
||||
return degree;
|
||||
}
|
||||
|
||||
int MultiplicationNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
return Multiplication(this).getPolynomialCoefficients(symbolName, coefficients);
|
||||
int MultiplicationNode::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
return Multiplication(this).getPolynomialCoefficients(context, symbolName, coefficients);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -195,8 +195,8 @@ Expression Multiplication::shallowBeautify(Context & context, Preferences::Angle
|
||||
return thisExp;
|
||||
}
|
||||
|
||||
int Multiplication::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(symbolName);
|
||||
int Multiplication::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(context, symbolName);
|
||||
if (deg < 0 || deg > Expression::k_maxPolynomialDegree) {
|
||||
return -1;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ int Multiplication::getPolynomialCoefficients(char symbolName, Expression coeffi
|
||||
// Let's note result = a(0)+a(1)*X+a(2)*X^2+a(3)*x^3+..
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
// childAtIndex(i) = b(0)+b(1)*X+b(2)*X^2+b(3)*x^3+...
|
||||
int degI = childAtIndex(i).getPolynomialCoefficients(symbolName, intermediateCoefficients);
|
||||
int degI = childAtIndex(i).getPolynomialCoefficients(context, symbolName, intermediateCoefficients);
|
||||
assert(degI <= Expression::k_maxPolynomialDegree);
|
||||
for (int j = deg; j > 0; j--) {
|
||||
// new coefficients[j] = b(0)*a(j)+b(1)*a(j-1)+b(2)*a(j-2)+...
|
||||
|
||||
@@ -13,8 +13,8 @@ extern "C" {
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int OppositeNode::polynomialDegree(char symbolName) const {
|
||||
return childAtIndex(0)->polynomialDegree(symbolName);
|
||||
int OppositeNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
return childAtIndex(0)->polynomialDegree(context, symbolName);
|
||||
}
|
||||
|
||||
ExpressionNode::Sign OppositeNode::sign() const {
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int ParenthesisNode::polynomialDegree(char symbolName) const {
|
||||
return childAtIndex(0)->polynomialDegree(symbolName);
|
||||
int ParenthesisNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
return childAtIndex(0)->polynomialDegree(context, symbolName);
|
||||
}
|
||||
|
||||
Layout ParenthesisNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
|
||||
|
||||
@@ -48,12 +48,12 @@ Expression PowerNode::setSign(Sign s, Context & context, Preferences::AngleUnit
|
||||
return Power(this).setSign(s, context, angleUnit);
|
||||
}
|
||||
|
||||
int PowerNode::polynomialDegree(char symbolName) const {
|
||||
int deg = ExpressionNode::polynomialDegree(symbolName);
|
||||
int PowerNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
int deg = ExpressionNode::polynomialDegree(context, symbolName);
|
||||
if (deg == 0) {
|
||||
return deg;
|
||||
}
|
||||
int op0Deg = childAtIndex(0)->polynomialDegree(symbolName);
|
||||
int op0Deg = childAtIndex(0)->polynomialDegree(context, symbolName);
|
||||
if (op0Deg < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -72,8 +72,8 @@ int PowerNode::polynomialDegree(char symbolName) const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int PowerNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
return Power(this).getPolynomialCoefficients(symbolName, coefficients);
|
||||
int PowerNode::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
return Power(this).getPolynomialCoefficients(context, symbolName, coefficients);
|
||||
}
|
||||
|
||||
// Private
|
||||
@@ -206,10 +206,10 @@ Expression Power::setSign(ExpressionNode::Sign s, Context & context, Preferences
|
||||
return result;
|
||||
}
|
||||
|
||||
int Power::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(symbolName);
|
||||
int Power::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(context, symbolName);
|
||||
if (deg <= 0) {
|
||||
return Expression::defaultGetPolynomialCoefficients(symbolName, coefficients);
|
||||
return Expression::defaultGetPolynomialCoefficients(context, symbolName, coefficients);
|
||||
}
|
||||
/* Here we only consider the case x^4 as privateGetPolynomialCoefficients is
|
||||
* supposed to be called after reducing the expression. */
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int SubtractionNode::polynomialDegree(char symbolName) const {
|
||||
int SubtractionNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
int degree = 0;
|
||||
for (ExpressionNode * e : children()) {
|
||||
int d = e->polynomialDegree(symbolName);
|
||||
int d = e->polynomialDegree(context, symbolName);
|
||||
if (d < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -30,18 +30,18 @@ Expression SymbolNode::replaceSymbolWithExpression(char symbol, Expression & exp
|
||||
return Symbol(this).replaceSymbolWithExpression(symbol, expression);
|
||||
}
|
||||
|
||||
int SymbolNode::polynomialDegree(char symbol) const {
|
||||
if (m_name == symbol) {
|
||||
int SymbolNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
if (m_name == symbolName) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SymbolNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
return Symbol(this).getPolynomialCoefficients(symbolName, coefficients);
|
||||
int SymbolNode::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
return Symbol(this).getPolynomialCoefficients(context, symbolName, coefficients);
|
||||
}
|
||||
|
||||
int SymbolNode::getVariables(isVariableTest isVariable, char * variables) const {
|
||||
int SymbolNode::getVariables(Context & context, isVariableTest isVariable, char * variables) const {
|
||||
size_t variablesLength = strlen(variables);
|
||||
if (isVariable(m_name)) {
|
||||
char * currentChar = variables;
|
||||
@@ -318,7 +318,7 @@ Expression Symbol::replaceSymbolWithExpression(char symbol, Expression & express
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Symbol::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
int Symbol::getPolynomialCoefficients(Context & context, char symbolName, Expression coefficients[]) const {
|
||||
if (name() == symbolName) {
|
||||
coefficients[0] = Rational(0);
|
||||
coefficients[1] = Rational(1);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Poincare {
|
||||
|
||||
float Trigonometry::characteristicXRange(const Expression & e, Context & context, Preferences::AngleUnit angleUnit) {
|
||||
assert(e.numberOfChildren() == 1);
|
||||
int d = e.childAtIndex(0).polynomialDegree('x');
|
||||
int d = e.childAtIndex(0).polynomialDegree(context, 'x');
|
||||
if (d < 0 || d > 1) {
|
||||
// child(0) is not linear so we cannot easily find an interesting range
|
||||
return e.childAtIndex(0).characteristicXRange(context, angleUnit);
|
||||
|
||||
@@ -9,7 +9,7 @@ extern "C" {
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
int UndefinedNode::polynomialDegree(char symbolName) const {
|
||||
int UndefinedNode::polynomialDegree(Context & context, char symbolName) const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user