[poincare] Power of true complexes is undefined (otherwise, some rules

cannot be applied: (x^y)^z)

Change-Id: I44b64a9fb80997abb7d957b9ac9c1d4d38f8de8e
This commit is contained in:
Émilie Feral
2017-11-23 13:47:29 +01:00
parent 888d1a6df1
commit a90228a48f
2 changed files with 14 additions and 1 deletions

View File

@@ -181,7 +181,18 @@ Expression * Power::shallowReduce(Context& context, AngleUnit angleUnit) {
}
#endif
/* Step 0: We look for square root and sum of square roots (two terms maximum
/* Step 0: if both operands are true complexes, the result is undefined.
* We can assert that evaluations is a complex as matrix are not simplified */
Complex<float> * op0 = static_cast<Complex<float> *>(operand(0)->evaluate<float>(context, angleUnit));
Complex<float> * op1 = static_cast<Complex<float> *>(operand(1)->evaluate<float>(context, angleUnit));
bool bothOperandsComplexes = op0->b() != 0 && op1->b() != 0;
delete op0;
delete op1;
if (bothOperandsComplexes) {
return replaceWith(new Undefined(), true);
}
/* Step 1: We look for square root and sum of square roots (two terms maximum
* so far) at the denominator and move them to the numerator. */
Expression * r = removeSquareRootsFromDenominator(context, angleUnit);
if (r) {

View File

@@ -511,6 +511,8 @@ QUIZ_CASE(poincare_simplify_easy) {
assert_parsed_expression_simplify_to("A^0", "1");
assert_parsed_expression_simplify_to("(-3)^0", "1");
assert_parsed_expression_simplify_to("(R(2)*P + R(2)*X)/R(2)", "P+X");
assert_parsed_expression_simplify_to("root(5^(-I)3^9,I)", "undef");
assert_parsed_expression_simplify_to("I^I", "undef");
assert_parsed_expression_simplify_to("ln(1881676377434183981909562699940347954480361860897069)", "ln(1881676377434183981909562699940347954480361860897069)");