mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Replace functions when replacing symbols iteratively
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user