mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[poincare] Clean Symbol
This commit is contained in:
@@ -82,6 +82,7 @@ public:
|
||||
Expression replaceReplaceableSymbols(Context & context);
|
||||
private:
|
||||
SymbolNode * node() const { return static_cast<SymbolNode *>(Expression::node()); }
|
||||
Expression expand(Context & context) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -126,10 +126,7 @@ Expression SymbolNode::replaceReplaceableSymbols(Context & context) {
|
||||
|
||||
template<typename T>
|
||||
Evaluation<T> SymbolNode::templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const {
|
||||
Expression e = context.expressionForSymbol(Symbol(this));
|
||||
/* Replace all the symbols iteratively. This prevents a memory failure when
|
||||
* symbols are defined circularly. */
|
||||
e = Expression::ExpressionWithoutSymbols(e, context);
|
||||
Expression e = Symbol(this).expand(context);
|
||||
if (e.isUninitialized()) {
|
||||
return Complex<T>::Undefined();
|
||||
}
|
||||
@@ -159,8 +156,7 @@ bool Symbol::isRegressionSymbol(const char * c) {
|
||||
}
|
||||
|
||||
bool Symbol::matches(ExpressionTest test, Context & context) const {
|
||||
Expression e = context.expressionForSymbol(*this);
|
||||
e = ExpressionWithoutSymbols(e, context);
|
||||
Expression e = expand(context);
|
||||
return !e.isUninitialized() && test(e, context, true);
|
||||
}
|
||||
|
||||
@@ -168,15 +164,12 @@ Expression Symbol::shallowReduce(Context & context, Preferences::AngleUnit angle
|
||||
if (!replaceSymbols) {
|
||||
return *this;
|
||||
}
|
||||
Expression result = context.expressionForSymbol(*this);
|
||||
/* The stored expression is as entered by the user, so we need to call reduce
|
||||
* First, replace all the symbols iteratively. This prevents a memory failure
|
||||
* when symbols are defined circularly. */
|
||||
result = ExpressionWithoutSymbols(result, context);
|
||||
Expression result = expand(context);
|
||||
if (result.isUninitialized()) {
|
||||
return *this;
|
||||
}
|
||||
replaceWithInPlace(result);
|
||||
// The stored expression is as entered by the user, so we need to call reduce
|
||||
return result.deepReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
@@ -215,4 +208,11 @@ Expression Symbol::replaceReplaceableSymbols(Context & context) {
|
||||
return e;
|
||||
}
|
||||
|
||||
Expression Symbol::expand(Context & context) const {
|
||||
/* Replace all the symbols iteratively. This prevents a memory failure when
|
||||
* symbols are defined circularly. */
|
||||
Expression e = context.expressionForSymbol(*this);
|
||||
return ExpressionWithoutSymbols(e, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user