mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[poincare] Opposite::simplify
Change-Id: I6af7c645f989e43b86a210430868e164f3f18f64
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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>);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user