mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Do not replace a symbol if it is an expression's parameter
This commit is contained in:
@@ -66,6 +66,7 @@ public:
|
||||
|
||||
// Symbol properties
|
||||
bool isSystemSymbol() const { return node()->isUnknown(UCodePointUnknownX) || node()->isUnknown(UCodePointUnknownN); }
|
||||
const char * name() const { return node()->name(); }
|
||||
static bool isSeriesSymbol(const char * c);
|
||||
static bool isRegressionSymbol(const char * c);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <ion/unicode/utf8_decoder.h>
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
#include <cmath>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Poincare {
|
||||
@@ -181,6 +182,32 @@ bool Symbol::isRegressionSymbol(const char * c) {
|
||||
}
|
||||
|
||||
Expression Symbol::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool symbolicComputation) {
|
||||
Expression parentExpression = parent();
|
||||
{
|
||||
Expression current = *this;
|
||||
Expression p = parentExpression;
|
||||
|
||||
while (!p.isUninitialized()) {
|
||||
if (p.type() == ExpressionNode::Type::Integral) { //TODO
|
||||
int index = p.indexOfChild(current);
|
||||
if (index == 1) { //TODO 1 for everybody?
|
||||
// The symbol is a paremetered expression's parameter
|
||||
return *this;
|
||||
}
|
||||
if (index == 0) { //TODO
|
||||
assert(p.childAtIndex(1).type() == ExpressionNode::Type::Symbol);
|
||||
Expression untypedParameter = p.childAtIndex(1);
|
||||
Symbol parameter = static_cast<Symbol &>(untypedParameter);
|
||||
if (strcmp(parameter.name(), name()) == 0) {
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
}
|
||||
current = p;
|
||||
p = current.parent();
|
||||
}
|
||||
}
|
||||
|
||||
Symbol s = *this;
|
||||
Expression result = SymbolAbstract::Expand(s, context, true);
|
||||
if (result.isUninitialized()) {
|
||||
@@ -189,7 +216,9 @@ Expression Symbol::shallowReduce(Context & context, Preferences::ComplexFormat c
|
||||
}
|
||||
result = Undefined::Builder();
|
||||
}
|
||||
replaceWithInPlace(result);
|
||||
if (!parentExpression.isUninitialized()) {
|
||||
parentExpression.replaceChildInPlace(*this, result);
|
||||
}
|
||||
// The stored expression is as entered by the user, so we need to call reduce
|
||||
return result.deepReduce(context, complexFormat, angleUnit, target, symbolicComputation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user