mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Simplification: R(a) with a < 0 --> R(-a)*i
This commit is contained in:
@@ -260,6 +260,7 @@ Expression * Power::shallowReduce(Context& context, AngleUnit angleUnit) {
|
||||
Complex<float> * op0 = static_cast<Complex<float> *>(operand(0)->approximate<float>(context, angleUnit));
|
||||
Complex<float> * op1 = static_cast<Complex<float> *>(operand(1)->approximate<float>(context, angleUnit));
|
||||
bool bothOperandsComplexes = op0->b() != 0 && op1->b() != 0;
|
||||
bool nonComplexNegativeOperand0 = op0->b() == 0 && op0->a() < 0;
|
||||
delete op0;
|
||||
delete op1;
|
||||
if (bothOperandsComplexes) {
|
||||
@@ -332,6 +333,19 @@ Expression * Power::shallowReduce(Context& context, AngleUnit angleUnit) {
|
||||
return simplifyRationalRationalPower(this, a, exp, context, angleUnit);
|
||||
}
|
||||
}
|
||||
// (a)^(1/2) with a < 0 --> i*(-a)^(1/2)
|
||||
if (!letPowerAtRoot && nonComplexNegativeOperand0 && operand(1)->type() == Type::Rational && static_cast<const Rational *>(operand(1))->numerator().isOne() && static_cast<const Rational *>(operand(1))->denominator().isTwo()) {
|
||||
Expression * o0 = editableOperand(0);
|
||||
Expression * m0 = new Multiplication(new Rational(-1), o0, false);
|
||||
replaceOperand(o0, m0, false);
|
||||
m0->shallowReduce(context, angleUnit);
|
||||
Multiplication * m1 = new Multiplication();
|
||||
replaceWith(m1, false);
|
||||
m1->addOperand(new Symbol(Ion::Charset::IComplex));
|
||||
m1->addOperand(this);
|
||||
shallowReduce(context, angleUnit);
|
||||
return m1->shallowReduce(context, angleUnit);
|
||||
}
|
||||
// e^(i*Pi*r) with r rational
|
||||
if (!letPowerAtRoot && isNthRootOfUnity()) {
|
||||
Expression * m = editableOperand(1);
|
||||
|
||||
@@ -64,6 +64,7 @@ QUIZ_CASE(poincare_power_simplify) {
|
||||
assert_parsed_expression_simplify_to("R(x*144)", "12*R(x)");
|
||||
assert_parsed_expression_simplify_to("R(x*144*P^2)", "12*R(x)*P");
|
||||
assert_parsed_expression_simplify_to("R(x*144*P)", "12*R(x)*R(P)");
|
||||
assert_parsed_expression_simplify_to("R(2-4*R(2))", "R((-2)+4*R(2))*I");
|
||||
assert_parsed_expression_simplify_to("x^(1/2)", "R(x)");
|
||||
assert_parsed_expression_simplify_to("x^(-1/2)", "1/R(x)");
|
||||
assert_parsed_expression_simplify_to("x^(1/7)", "root(x,7)");
|
||||
|
||||
Reference in New Issue
Block a user