[poincare} Resolve bug in dynamicHierarchy::simplify

Change-Id: Iad798f0c51c29ba49e79b63ceab70225a75d495a
This commit is contained in:
Émilie Feral
2017-10-11 11:44:42 +02:00
parent 26f2b410ac
commit ce050253fb
4 changed files with 5 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ void Addition::immediateSimplify() {
}
sortChildren();
int i = 0;
while (i < numberOfOperands()-1) {
while (i < numberOfOperands()) {
if (deleteUselessOperand(i) && i > 0) {
i--;
}

View File

@@ -159,8 +159,8 @@ void DynamicHierarchy::squashUnaryHierarchy() {
}
bool DynamicHierarchy::deleteUselessOperand(int index) {
assert(index < numberOfOperands() && numberOfOperands() > 1);
if (operand(index)->type() == Type::Rational && isUselessOperand(static_cast<const Rational *>(operand(index)))) {
assert(index < numberOfOperands());
if (numberOfOperands() >1 && operand(index)->type() == Type::Rational && isUselessOperand(static_cast<const Rational *>(operand(index)))) {
removeOperand(operand(index), true);
return true;
}

View File

@@ -113,7 +113,7 @@ void Multiplication::immediateSimplify() {
sortChildren();
/* Now, no more node can be an addition or a multiplication */
int i = 0;
while (i < numberOfOperands()-1) {
while (i < numberOfOperands()) {
if (deleteUselessOperand(i) && i > 0) {
i--;
}

View File

@@ -120,6 +120,7 @@ QUIZ_CASE(poincare_simplify_easy) {
assert_parsed_expression_simplify_to("A^3*A^(-3)", "1");
assert_parsed_expression_simplify_to("1+A+2+B+3", "6+A+B");
assert_parsed_expression_simplify_to("(x+1)*(x+2)", "x^2+3x+2");
assert_parsed_expression_simplify_to("(x+1)*(x-1)", "-1+x^2");
/* This does not work but should not as it is above k_primorial32 = 1*3*5*7*11*... (product of first 32 primes. */
//assert_parsed_expression_simplify_to("1881676377434183981909562699940347954480361860897069^(1/3)", "123456789123456789");