mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-26 09:10:48 +01:00
[poincare} Resolve bug in dynamicHierarchy::simplify
Change-Id: Iad798f0c51c29ba49e79b63ceab70225a75d495a
This commit is contained in:
@@ -39,7 +39,7 @@ void Addition::immediateSimplify() {
|
||||
}
|
||||
sortChildren();
|
||||
int i = 0;
|
||||
while (i < numberOfOperands()-1) {
|
||||
while (i < numberOfOperands()) {
|
||||
if (deleteUselessOperand(i) && i > 0) {
|
||||
i--;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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--;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user