[poincare] Opposite::simplify

Change-Id: I6af7c645f989e43b86a210430868e164f3f18f64
This commit is contained in:
Émilie Feral
2017-10-05 18:24:35 +02:00
parent 58cdf3e6c3
commit 96661a53e2
3 changed files with 14 additions and 1 deletions

View File

@@ -19,6 +19,8 @@ public:
template<typename T> static Evaluation<T> * computeOnMatrices(Evaluation<T> * m, Evaluation<T> * n);
static bool HaveSameNonRationalFactors(const Expression * e1, const Expression * e2);
/* Simplification */
void immediateSimplify() override;
private:
template<typename T> static Evaluation<T> * computeOnMatrixAndComplex(Evaluation<T> * m, const Complex<T> * c) {
return EvaluationEngine::elementWiseOnComplexAndComplexMatrix(c, m, compute<T>);
@@ -33,7 +35,6 @@ private:
return LayoutEngine::createInfixLayout(this, floatDisplayMode, complexFormat, "*");
}
/* Simplification */
void immediateSimplify() override;
void factorizeChildren(Expression * e1, Expression * e2);
void distributeOnChildAtIndex(int index);
static bool TermsHaveIdenticalBase(const Expression * e1, const Expression * e2);

View File

@@ -13,6 +13,8 @@ public:
Expression * clone() const override;
Type type() const override;
template<typename T> static Complex<T> compute(const Complex<T> c, AngleUnit angleUnit);
/* Simplification */
void immediateSimplify() override;
private:
virtual Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override {
return EvaluationEngine::map<float>(this, context, angleUnit, compute<float>);

View File

@@ -1,6 +1,8 @@
#include <poincare/opposite.h>
#include <poincare/complex_matrix.h>
#include <poincare/complex.h>
#include <poincare/multiplication.h>
#include <poincare/rational.h>
extern "C" {
#include <assert.h>
#include <stdlib.h>
@@ -26,6 +28,14 @@ Complex<T> Opposite::compute(const Complex<T> c, AngleUnit angleUnit) {
return Complex<T>::Cartesian(-c.a(), -c.b());
}
void Opposite::immediateSimplify() {
const Expression * multOperands[2] = {new Rational(Integer(-1)), operand(0)};
detachOperand(operand(0));
Multiplication * m = new Multiplication(multOperands, 2, false);
replaceWith(m, true);
m->immediateSimplify();
}
ExpressionLayout * Opposite::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
assert(complexFormat != ComplexFormat::Default);