From a90228a48f4332cd95f23889e8dc41fe6014ca97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 23 Nov 2017 13:47:29 +0100 Subject: [PATCH] [poincare] Power of true complexes is undefined (otherwise, some rules cannot be applied: (x^y)^z) Change-Id: I44b64a9fb80997abb7d957b9ac9c1d4d38f8de8e --- poincare/src/power.cpp | 13 ++++++++++++- poincare/test/simplify_easy.cpp | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index b376b0c42..7b65bee9d 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -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 * op0 = static_cast *>(operand(0)->evaluate(context, angleUnit)); + Complex * op1 = static_cast *>(operand(1)->evaluate(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) { diff --git a/poincare/test/simplify_easy.cpp b/poincare/test/simplify_easy.cpp index 755e43eef..5b57e16b9 100644 --- a/poincare/test/simplify_easy.cpp +++ b/poincare/test/simplify_easy.cpp @@ -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)");