diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index ff7c1502e..5124ede3b 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -413,7 +413,7 @@ Expression * Power::shallowReduce(Context& context, AngleUnit angleUnit) { } } } - // a^(b+c) -> Rational(a^b)*a^c with a and b rational and a != 0 + // a^(b+c+...) -> Rational(a^b)*a^c with a and b rational and a != 0 if (!letPowerAtRoot && operand(0)->type() == Type::Rational && !static_cast(operand(0))->isZero() && operand(1)->type() == Type::Addition) { Addition * a = static_cast(editableOperand(1)); // Check is b is rational @@ -423,11 +423,11 @@ Expression * Power::shallowReduce(Context& context, AngleUnit angleUnit) { if (RationalExponentShouldNotBeReduced(rationalBase, rationalIndex)) { return this; } - Power * p1 = static_cast(clone()); - replaceOperand(a, a->editableOperand(1), true); + Power * p1 = new Power(editableOperand(0), a->editableOperand(0), true); // a^b Power * p2 = static_cast(clone()); + static_cast(p2->editableOperand(1))->removeOperand(p2->editableOperand(1)->editableOperand(0), true); // p2 = a^(c+...) Multiplication * m = new Multiplication(p1, p2, false); - simplifyRationalRationalPower(p1, static_cast(p1->editableOperand(0)), static_cast(p1->editableOperand(1)->editableOperand(0)), context, angleUnit); + simplifyRationalRationalPower(p1, static_cast(p1->editableOperand(0)), static_cast(p1->editableOperand(1)), context, angleUnit); replaceWith(m, true); return m->shallowReduce(context, angleUnit); } diff --git a/poincare/test/power.cpp b/poincare/test/power.cpp index 96c0b4c4a..21b8b29ac 100644 --- a/poincare/test/power.cpp +++ b/poincare/test/power.cpp @@ -89,4 +89,5 @@ QUIZ_CASE(poincare_power_simplify) { assert_parsed_expression_simplify_to("(1+R(2)+R(3))^5", "296+224*R(2)+184*R(3)+120*R(6)"); assert_parsed_expression_simplify_to("(P+R(2)+R(3)+x)^(-3)", "1/(11*R(2)+9*R(3)+15*x+6*R(6)*x+3*R(2)*x^2+3*R(3)*x^2+x^3+15*P+6*R(6)*P+6*R(2)*x*P+6*R(3)*x*P+3*x^2*P+3*R(2)*P^2+3*R(3)*P^2+3*x*P^2+P^3)"); assert_parsed_expression_simplify_to("1.006666666666667^60", "(1006666666666667/1000000000000000)^60"); + assert_parsed_expression_simplify_to("2^(6+P+x)", "64*2^(x+P)"); }