mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Fix power simplification: a^(b+c+d) --> a^b*a^(c+d) instead
of a^b*a^c
This commit is contained in:
committed by
LeaNumworks
parent
9fbdc60572
commit
4dff3a2609
@@ -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<const Rational *>(operand(0))->isZero() && operand(1)->type() == Type::Addition) {
|
||||
Addition * a = static_cast<Addition *>(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<Power *>(clone());
|
||||
replaceOperand(a, a->editableOperand(1), true);
|
||||
Power * p1 = new Power(editableOperand(0), a->editableOperand(0), true); // a^b
|
||||
Power * p2 = static_cast<Power *>(clone());
|
||||
static_cast<Addition *>(p2->editableOperand(1))->removeOperand(p2->editableOperand(1)->editableOperand(0), true); // p2 = a^(c+...)
|
||||
Multiplication * m = new Multiplication(p1, p2, false);
|
||||
simplifyRationalRationalPower(p1, static_cast<Rational *>(p1->editableOperand(0)), static_cast<Rational *>(p1->editableOperand(1)->editableOperand(0)), context, angleUnit);
|
||||
simplifyRationalRationalPower(p1, static_cast<Rational *>(p1->editableOperand(0)), static_cast<Rational *>(p1->editableOperand(1)), context, angleUnit);
|
||||
replaceWith(m, true);
|
||||
return m->shallowReduce(context, angleUnit);
|
||||
}
|
||||
|
||||
@@ -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)");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user