mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 03:29:58 +02:00
[poincare/simplification] add integer fraction reduction transformation
Change-Id: I28dfe64bceb0863c781e631f80ff2684b22670b9
This commit is contained in:
@@ -23,6 +23,7 @@ objs += $(addprefix $(prefix)/,\
|
||||
transform/remove_parenthesis_transform.o \
|
||||
transform/subtraction_transform.o \
|
||||
transform/integer_addition_transform.o \
|
||||
transform/integer_fraction_reduction_transform.o \
|
||||
transform/integer_multiplication_transform.o \
|
||||
transform/merge_dynamic_hierarchy_transform.o \
|
||||
)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "transform.h"
|
||||
#include <assert.h>
|
||||
#include <poincare/multiplication.h>
|
||||
#include <poincare/power.h>
|
||||
#include <poincare/arithmetic.h>
|
||||
#include <poincare/integer.h>
|
||||
|
||||
bool Poincare::Simplification::IntegerFractionReductionTransform(Expression * captures[]) {
|
||||
Multiplication * m = static_cast<Multiplication *>(captures[0]);
|
||||
Power * p = static_cast<Power *>(captures[2]);
|
||||
Integer * i1 = (Integer *)(captures[1]);
|
||||
Integer * i2 = (Integer *)(captures[3]);
|
||||
Integer gcd = Arithmetic::GCD(i1, i2);
|
||||
Integer one(1);
|
||||
if (gcd.compareTo(&one) == 0) {
|
||||
return false;
|
||||
}
|
||||
Integer * r1 = new Integer(Integer::Division(*i1, gcd).quotient);
|
||||
Integer * r2 = new Integer(Integer::Division(*i2, gcd).quotient);
|
||||
m->replaceOperand(i1, r1, true);
|
||||
p->replaceOperand(i2, r2, true);
|
||||
return true;
|
||||
}
|
||||
@@ -16,6 +16,7 @@ bool MergeDynamicHierarchyTransform(Expression * captures[]);
|
||||
bool IntegerAdditionTransform(Expression * captures[]);
|
||||
bool IntegerMultiplicationTransform(Expression * captures[]);
|
||||
bool PowerPowerTransform(Expression * captures[]);
|
||||
bool IntegerFractionReductionTransform(Expression * captures[]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user