From a13246fca17447b4aaabbd9fb7c6703ff27d8727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 30 Nov 2018 11:47:30 +0100 Subject: [PATCH] [poincare] simplifyForComplexFormat: simplify instead of reducing before extracting real and imaginary parts --- poincare/src/expression.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index cfd69d964..0f3960a31 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -360,19 +360,21 @@ bool isMinusOne(const Expression e) { Expression Expression::simplifyForComplexFormat(Context & context, Preferences::AngleUnit angleUnit, Preferences::ComplexFormat complexFormat) { sSimplificationHasBeenInterrupted = false; - Expression e = deepReduce(context, angleUnit, ExpressionNode::ReductionTarget::User); + // We simplify before extracting the real and imaginary part to develop expression of type (a+b*i)^3 for example + // We could have deepReduce the expression but we want to keep division which are easier to extract complex parts from + Expression e = simplify(context, angleUnit); if (sSimplificationHasBeenInterrupted) { return Expression(); } Expression ra = complexFormat == Preferences::ComplexFormat::Cartesian ? e.realPart(context, angleUnit) : e.complexNorm(context, angleUnit); Expression tb = complexFormat == Preferences::ComplexFormat::Cartesian ? e.imaginaryPart(context, angleUnit) : e.complexArgument(context, angleUnit); if (ra.isUninitialized() || tb.isUninitialized()) { - return e.deepBeautify(context, angleUnit); + return e; } ra = ra.simplify(context, angleUnit); tb = tb.simplify(context, angleUnit); if (ra.isUninitialized() || tb.isUninitialized()) { - return e.deepBeautify(context, angleUnit); + return e; } e = CreateComplexExpression(ra, tb, complexFormat, ra.type() == ExpressionNode::Type::Undefined || tb.type() == ExpressionNode::Type::Undefined,