mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 19:49:58 +02:00
[poincare] Add a method to Reduce
Change-Id: I831b9c98dff6c15ddbf4111bd9715776b0f7bc5d
This commit is contained in:
@@ -195,6 +195,7 @@ private:
|
||||
/* Layout Engine */
|
||||
virtual ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const = 0;
|
||||
/* Simplification */
|
||||
static void Reduce(Expression ** expressionAddress, Context & context, AngleUnit angleUnit);
|
||||
Expression * deepBeautify(Context & context, AngleUnit angleUnit);
|
||||
Expression * deepSimplify(Context & context, AngleUnit angleUnit);
|
||||
// TODO: should be virtual pure
|
||||
|
||||
@@ -131,6 +131,12 @@ void Expression::simplify(Expression ** expressionAddress, Context & context, An
|
||||
*expressionAddress = root.editableOperand(0);
|
||||
}
|
||||
|
||||
void Expression::Reduce(Expression ** expressionAddress, Context & context, AngleUnit angleUnit) {
|
||||
SimplificationRoot root(*expressionAddress);
|
||||
root.deepSimplify(context, angleUnit);
|
||||
*expressionAddress = root.editableOperand(0);
|
||||
}
|
||||
|
||||
Expression * Expression::deepSimplify(Context & context, AngleUnit angleUnit) {
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
if ((editableOperand(i))->deepSimplify(context, angleUnit)->type() == Type::Undefined && this->type() != Type::SimplificationRoot) {
|
||||
|
||||
@@ -495,7 +495,7 @@ void Multiplication::addMissingFactors(Expression * factor, Context & context, A
|
||||
for (int i = 0; i < numberOfOperands(); i++) {
|
||||
if (TermsHaveIdenticalBase(operand(i), factor)) {
|
||||
Subtraction * sub = new Subtraction(CreateExponent(editableOperand(i)), CreateExponent(factor), false);
|
||||
Expression::simplify((Expression **)&sub, context, angleUnit);
|
||||
Reduce((Expression **)&sub, context, angleUnit);
|
||||
if (sub->sign() == Sign::Negative) { // index[0] < index[1]
|
||||
factor->replaceOperand(factor->editableOperand(1), new Opposite(sub, true), true);
|
||||
factor->deepSimplify(context, angleUnit);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <poincare/trigonometry.h>
|
||||
#include <poincare/simplification_root.h>
|
||||
#include <poincare/hyperbolic_cosine.h>
|
||||
#include <poincare/complex.h>
|
||||
#include <poincare/symbol.h>
|
||||
@@ -180,15 +179,14 @@ Expression * Trigonometry::table(const Expression * e, Expression::Type type, Co
|
||||
if (input == nullptr) {
|
||||
continue;
|
||||
}
|
||||
SimplificationRoot inputRoot(input);
|
||||
inputRoot.deepSimplify(context, angleUnit); // input expression does not change, no root needed and we can use entry after
|
||||
if (inputRoot.operand(0)->isIdenticalTo(e)) {
|
||||
Expression::Reduce(&input, context, angleUnit);
|
||||
if (input->isIdenticalTo(e)) {
|
||||
Expression * output = Expression::parse(cheatTable[i][outputIndex]);
|
||||
if (output == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
SimplificationRoot outputRoot(output);
|
||||
return outputRoot.deepSimplify(context, angleUnit)->editableOperand(0);
|
||||
Expression::Reduce(&output, context, angleUnit);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
Reference in New Issue
Block a user