mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 01:59:59 +01:00
[poincare] Expression: methods that should return an Expression HAVE to
be implemented on Expression and not on ExpressionNode in order to copy the returned Expression.
This commit is contained in:
@@ -133,11 +133,13 @@ public:
|
||||
|
||||
protected:
|
||||
Expression(const ExpressionNode * n) : TreeByValue(n) {}
|
||||
Expression simpleShallowReduce(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression defaultShallowBeautify(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
private:
|
||||
/* Properties */
|
||||
Expression privateReplaceSymbolWithExpression(char symbol, Expression expression) const;
|
||||
Expression defaultReplaceSymbolWithExpression(char symbol, Expression expression) const;
|
||||
int defaultGetPolynomialCoefficients(char symbol, Expression expression[]) const;
|
||||
int getPolynomialCoefficients(char symbolName, Expression coefficients[]) const { return node()->getPolynomialCoefficients(symbolName, coefficients); }
|
||||
|
||||
/* Simplification */
|
||||
|
||||
@@ -209,7 +209,7 @@ Expression Addition::shallowBeautify(Context & context, Preferences::AngleUnit a
|
||||
}
|
||||
|
||||
Expression Addition::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression e = Expression::simpleShallowReduce(context, angleUnit);
|
||||
Expression e = Expression::defaultShallowReduce(context, angleUnit);
|
||||
if (e.isUndefinedOrAllocationFailure()) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ bool Expression::getLinearCoefficients(char * variables, Expression coefficients
|
||||
return true;
|
||||
}
|
||||
|
||||
Expression Expression::simpleShallowReduce(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression Expression::defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
Expression childI = childAtIndex(i);
|
||||
if (childI.isAllocationFailure()) {
|
||||
@@ -144,13 +144,16 @@ Expression Expression::simpleShallowReduce(Context & context, Preferences::Angle
|
||||
return Undefined();
|
||||
}
|
||||
}
|
||||
Expression thisCopy = *this;
|
||||
return thisCopy;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Expression Expression::defaultShallowBeautify(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
Expression Expression::privateReplaceSymbolWithExpression(char symbol, Expression expression) const {
|
||||
Expression Expression::defaultReplaceSymbolWithExpression(char symbol, Expression expression) const {
|
||||
Expression e = *this;
|
||||
int nbChildren = numberOfChildren();
|
||||
for (int i = 0; i < nbChildren; i++) {
|
||||
@@ -159,6 +162,15 @@ Expression Expression::privateReplaceSymbolWithExpression(char symbol, Expressio
|
||||
return e;
|
||||
}
|
||||
|
||||
int Expression::defaultGetPolynomialCoefficients(char symbol, Expression coefficients[]) const {
|
||||
int deg = polynomialDegree(symbol);
|
||||
if (deg == 0) {
|
||||
coefficients[0] = *this;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Expression::getPolynomialReducedCoefficients(char symbolName, Expression coefficients[], Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
int degree = getPolynomialCoefficients(symbolName, coefficients);
|
||||
for (int i = 0; i <= degree; i++) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace Poincare {
|
||||
|
||||
Expression ExpressionNode::replaceSymbolWithExpression(char symbol, Expression expression) const {
|
||||
return Expression(this).privateReplaceSymbolWithExpression(symbol, expression);
|
||||
return Expression(this).defaultReplaceSymbolWithExpression(symbol, expression);
|
||||
}
|
||||
|
||||
Expression ExpressionNode::setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
@@ -23,6 +23,7 @@ int ExpressionNode::polynomialDegree(char symbolName) const {
|
||||
}
|
||||
|
||||
int ExpressionNode::getPolynomialCoefficients(char symbolName, Expression coefficients[]) const {
|
||||
return Expression(this).defaultGetPolynomialCoefficients(symbolName, coefficients);
|
||||
int deg = polynomialDegree(symbolName);
|
||||
if (deg == 0) {
|
||||
coefficients[0] = Expression(this);
|
||||
@@ -76,12 +77,11 @@ int ExpressionNode::SimplificationOrder(const ExpressionNode * e1, const Express
|
||||
}
|
||||
|
||||
Expression ExpressionNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
return Expression(this).simpleShallowReduce(context, angleUnit);
|
||||
return Expression(this).defaultShallowReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
Expression ExpressionNode::shallowBeautify(Context & context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression result = Expression(this);
|
||||
return result;
|
||||
return Expression(this).defaultShallowBeautify(context, angleUnit);
|
||||
}
|
||||
|
||||
bool ExpressionNode::isOfType(Type * types, int length) const {
|
||||
|
||||
@@ -36,8 +36,7 @@ Expression Parenthesis::shallowReduce(Context& context, Preferences::AngleUnit a
|
||||
if (e.isUndefinedOrAllocationFailure()) {
|
||||
return e;
|
||||
}
|
||||
Expression result = childAtIndex(0);
|
||||
return result;
|
||||
return childAtIndex(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user