[poincare] Update Division

This commit is contained in:
Léa Saviot
2018-08-31 11:16:12 +02:00
parent c97f3cc929
commit 009a372c32
2 changed files with 5 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ public:
}
// Simplification
virtual Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit, const Expression futureParent) override;
Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit, const Expression futureParent) override;
private:
template<typename T> static Complex<T> compute(const std::complex<T> c, const std::complex<T> d);

View File

@@ -65,10 +65,11 @@ Expression Division::shallowReduce(Context& context, Preferences::AngleUnit angl
if (result.isUndefinedOrAllocationFailure()) {
return result;
}
Multiplication m = Multiplication(childAtIndex(0));
Expression p = Power(childAtIndex(1), Rational(-1));
p = p.shallowReduce(context, angleUnit); // Imagine Division(2,1). p would be 1^(-1) which can be simplified
Multiplication m = Multiplication(childAtIndex(0), p);
return m.shallowReduce(context, angleUnit);
p = p.shallowReduce(context, angleUnit, m); // Imagine Division(2,1). p would be 1^(-1) which can be simplified
m.addChildAtIndexInPlace(p, m.numberOfChildren(), m.numberOfChildren());
return m.shallowReduce(context, angleUnit, futureParent);
}
}