mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Fix bug in equal simplifcation
This commit is contained in:
@@ -52,19 +52,15 @@ Expression Equal::standardEquation(Context * context, Preferences::ComplexFormat
|
|||||||
Expression Equal::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
Expression Equal::shallowReduce(ExpressionNode::ReductionContext reductionContext) {
|
||||||
|
|
||||||
Expression e = Equal::Builder(Subtraction::Builder(childAtIndex(0).clone(), childAtIndex(1).clone()).shallowReduce(reductionContext), Rational::Builder(0));
|
Expression e = Equal::Builder(Subtraction::Builder(childAtIndex(0).clone(), childAtIndex(1).clone()).shallowReduce(reductionContext), Rational::Builder(0));
|
||||||
|
|
||||||
Expression leftSide = e.childAtIndex(0);
|
Expression leftSide = e.childAtIndex(0);
|
||||||
if (leftSide.isIdenticalTo(e.childAtIndex(1))) {
|
|
||||||
Expression result = Rational::Builder(1);
|
|
||||||
replaceWithInPlace(result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (leftSide.isUndefined()) {
|
if (leftSide.isUndefined()) {
|
||||||
return leftSide;
|
return leftSide; // <=> undefined
|
||||||
}
|
}
|
||||||
if (leftSide.type() == ExpressionNode::Type::Multiplication) {
|
if (leftSide.type() == ExpressionNode::Type::Multiplication) { // Simplify multiplication
|
||||||
Multiplication m = static_cast<Multiplication&>(leftSide);
|
Multiplication m = static_cast<Multiplication&>(leftSide);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < numberOfChildren()-1) {
|
while (i < m.numberOfChildren()) {
|
||||||
if (m.childAtIndex(i).nullStatus(reductionContext.context()) == ExpressionNode::NullStatus::NonNull) {
|
if (m.childAtIndex(i).nullStatus(reductionContext.context()) == ExpressionNode::NullStatus::NonNull) {
|
||||||
m.removeChildAtIndexInPlace(i);
|
m.removeChildAtIndexInPlace(i);
|
||||||
}
|
}
|
||||||
@@ -72,6 +68,23 @@ Expression Equal::shallowReduce(ExpressionNode::ReductionContext reductionContex
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace if 0 child
|
||||||
|
if (m.numberOfChildren() == 0) {
|
||||||
|
e.replaceChildAtIndexInPlace(0, Rational::Builder(0));
|
||||||
|
} else {
|
||||||
|
// Squash if one child
|
||||||
|
Expression result = m.squashUnaryHierarchyInPlace();
|
||||||
|
if (result != *this) {
|
||||||
|
e.replaceChildAtIndexInPlace(0, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leftSide.isIdenticalTo(e.childAtIndex(1))) {
|
||||||
|
Expression result = Rational::Builder(1);
|
||||||
|
replaceWithInPlace(result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
|
|||||||
Reference in New Issue
Block a user