[poincare] When simplification has been interrupted, escape the end of

simplification. Otherwise we can be stuck in infinite loop.

This fixes the following bug: when simplifying an expression as
'bigRational1^x*bigRational2^x', we use the rule a^x*b^x --> (a¨b)^x. However,
in this case, a*b can't be reduce (resulting rational would be too big) and
we're stuck in the loop a^x*b^x --> (a¨b)^x --> a^x*b^x --> (a¨b)^x...
This commit is contained in:
Émilie Feral
2020-03-24 12:16:05 +01:00
committed by LeaNumworks
parent c0f73e97d2
commit 7c79c70890
2 changed files with 18 additions and 12 deletions

View File

@@ -321,18 +321,22 @@ void Expression::defaultDeepReduceChildren(ExpressionNode::ReductionContext redu
Expression Expression::defaultShallowReduce() {
Expression result;
const int childrenCount = numberOfChildren();
for (int i = 0; i < childrenCount; i++) {
/* The reduction is shortcut if one child is unreal or undefined:
* - the result is unreal if at least one child is unreal
* - the result is undefined if at least one child is undefined but no child
* is unreal */
ExpressionNode::Type childIType = childAtIndex(i).type();
if (childIType == ExpressionNode::Type::Unreal) {
result = Unreal::Builder();
break;
} else if (childIType == ExpressionNode::Type::Undefined) {
result = Undefined::Builder();
if (sSimplificationHasBeenInterrupted) {
result = Undefined::Builder();
} else {
const int childrenCount = numberOfChildren();
for (int i = 0; i < childrenCount; i++) {
/* The reduction is shortcut if one child is unreal or undefined:
* - the result is unreal if at least one child is unreal
* - the result is undefined if at least one child is undefined but no child
* is unreal */
ExpressionNode::Type childIType = childAtIndex(i).type();
if (childIType == ExpressionNode::Type::Unreal) {
result = Unreal::Builder();
break;
} else if (childIType == ExpressionNode::Type::Undefined) {
result = Undefined::Builder();
}
}
}
if (!result.isUninitialized()) {