[poincare] Replace functions when replacing symbols iteratively

This commit is contained in:
Léa Saviot
2018-11-09 14:22:14 +01:00
committed by Émilie Feral
parent cb88dbc0a1
commit 17eaadb280
2 changed files with 17 additions and 2 deletions

View File

@@ -38,6 +38,7 @@ private:
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
// Simplification
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true) override;
Expression replaceReplaceableSymbols(Context & context) override;
// Evaluation
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override;
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override;
@@ -52,7 +53,8 @@ public:
replaceChildAtIndexInPlace(0, child);
}
static Expression UntypedBuilder(const char * name, size_t length, Expression child, Context * context) {
// create an expression only if it is not in the context or defined as a function
/* Create an expression only if it is not in the context or defined as a
* function */
Function f(name, length, child);
if (SymbolAbstract::ValidInContext(f, context)) {
return f;
@@ -60,9 +62,9 @@ public:
return Expression();
}
Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression);
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);
Expression replaceReplaceableSymbols(Context & context);
};
}

View File

@@ -73,6 +73,10 @@ Expression FunctionNode::shallowReduce(Context & context, Preferences::AngleUnit
return Function(this).shallowReduce(context, angleUnit, replaceSymbols); // This uses Symbol::shallowReduce
}
Expression FunctionNode::replaceReplaceableSymbols(Context & context) {
return Function(this).replaceReplaceableSymbols(context);
}
Evaluation<float> FunctionNode::approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const {
return templatedApproximate<float>(context, angleUnit);
}
@@ -134,4 +138,13 @@ Expression Function::shallowReduce(Context & context, Preferences::AngleUnit ang
return *this;
}
Expression Function::replaceReplaceableSymbols(Context & context) {
Expression e = context.expressionForSymbol(*this);
if (e.isUninitialized()) {
return *this;
}
replaceWithInPlace(e);
return e;
}
}