diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index e672bdcc8..cead102dc 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -89,7 +89,7 @@ private: bool parentIsALogarithmOfSameBase() const; bool isNthRootOfUnity() const; Expression equivalentExpressionUsingStandardExpression() const; - static Expression CreateComplexExponent(const Expression & r); // Returns e^(i*pi*r) + static Expression CreateComplexExponent(const Expression & r, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); // Returns e^(i*pi*r) static bool TermIsARationalSquareRootOrRational(const Expression& e); static const Rational RadicandInExpression(const Expression & e); static const Rational RationalFactorInExpression(const Expression & e); diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 5147bbcaa..e6c9d0adf 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -453,16 +453,16 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU } } - /*if (target == ExpressionNode::ReductionTarget::User && childAtIndex(1).type() == ExpressionNode::Type::Rational) { + if (childAtIndex(1).type() == ExpressionNode::Type::Rational) { const Rational b = childAtIndex(1).convert(); // i^(p/q) if (childAtIndex(0).type() == ExpressionNode::Type::Constant && childAtIndex(0).convert().isIComplex()) { Number r = Number::Multiplication(b, Rational(1, 2)); - Expression result = CreateComplexExponent(r); + Expression result = CreateComplexExponent(r, context, angleUnit, target); replaceWithInPlace(result); return result.shallowReduce(context, angleUnit, target); } - }*/ + } // (±inf)^x if (childAtIndex(0).type() == ExpressionNode::Type::Infinity) { @@ -519,14 +519,17 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU //m0.shallowReduce(context, angleUnit, target); Multiplication m1 = Multiplication(); replaceWithInPlace(m1); - m1.addChildAtIndexInPlace(Constant(Ion::Charset::IComplex), 0, 0); + // Multiply m1 by i complex + Constant i(Ion::Charset::IComplex); + m1.addChildAtIndexInPlace(i, 0, 0); + i.shallowReduce(context, angleUnit, target); m1.addChildAtIndexInPlace(*this, 1, 1); shallowReduce(context, angleUnit, target); return m1.shallowReduce(context, angleUnit, target); } } // e^(i*Pi*r) with r rational - /*if (!letPowerAtRoot && isNthRootOfUnity()) { + if (!letPowerAtRoot && isNthRootOfUnity()) { Expression m = childAtIndex(1); Expression i = m.childAtIndex(m.numberOfChildren()-1); static_cast(m).removeChildAtIndexInPlace(m.numberOfChildren()-1); @@ -543,7 +546,7 @@ Expression Power::shallowReduce(Context & context, Preferences::AngleUnit angleU complexPart.shallowReduce(context, angleUnit, target); replaceWithInPlace(a); return a.shallowReduce(context, angleUnit, target); - }*/ + } // x^log(y,x)->y if y > 0 if (childAtIndex(1).type() == ExpressionNode::Type::Logarithm) { if (childAtIndex(1).numberOfChildren() == 2 && childAtIndex(0).isIdenticalTo(childAtIndex(1).childAtIndex(1))) { @@ -887,7 +890,7 @@ Expression Power::CreateSimplifiedIntegerRationalPower(Integer i, Rational r, bo m.addChildAtIndexInPlace(p, 1, 1); } if (i.isNegative()) { - Expression exp = CreateComplexExponent(r); + Expression exp = CreateComplexExponent(r, context, angleUnit, target); m.addChildAtIndexInPlace(exp, m.numberOfChildren(), m.numberOfChildren()); exp.shallowReduce(context, angleUnit, target); } @@ -1073,14 +1076,16 @@ Expression Power::equivalentExpressionUsingStandardExpression() const { return Expression(); } -Expression Power::CreateComplexExponent(const Expression & r) { +Expression Power::CreateComplexExponent(const Expression & r, Context & context, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { // Returns e^(i*pi*r) const Constant exp = Constant(Ion::Charset::Exponential); - const Constant iComplex = Constant(Ion::Charset::IComplex); + Constant iComplex = Constant(Ion::Charset::IComplex); const Constant pi = Constant(Ion::Charset::SmallPi); Multiplication mExp = Multiplication(iComplex, pi, r.clone()); - mExp.sortChildrenInPlace(PowerNode::SimplificationOrder, false); - return Power(exp, mExp); + iComplex.shallowReduce(context, angleUnit, target); + Power p(exp, mExp); + mExp.shallowReduce(context, angleUnit, target); + return p; #if 0 const Constant iComplex = Constant(Ion::Charset::IComplex); const Constant pi = Constant(Ion::Charset::SmallPi);