[poincare/power] Fix infinite loop in reduction

Fix the broken simplification test 1/identity(2)^500
This commit is contained in:
Léa Saviot
2020-06-03 11:39:37 +02:00
committed by Émilie Feral
parent 55ae258653
commit 0c040a7db6

View File

@@ -439,6 +439,12 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex
if (exponent.isNegative()) {
index.setSign(ExpressionNode::Sign::Positive, reductionContext);
Expression reducedPositiveExponentMatrix = shallowReduce(reductionContext);
if (reducedPositiveExponentMatrix.type() == ExpressionNode::Type::Power) {
/* The shallowReduce did not work, stop here so we do not get in an
* infinite loop. */
static_cast<Power &>(reducedPositiveExponentMatrix).childAtIndex(1).setSign(ExpressionNode::Sign::Negative, reductionContext);
return reducedPositiveExponentMatrix;
}
Expression dummyExpression = Undefined::Builder();
MatrixInverse inv = MatrixInverse::Builder(dummyExpression);
reducedPositiveExponentMatrix.replaceWithInPlace(inv);