mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[poincare] Correct Multiplication::simplify to avoid factorizing
2*2^(1/2) Change-Id: I32d51584a372afa29a36a3e94f65b024bc9e9bc4
This commit is contained in:
@@ -38,6 +38,7 @@ private:
|
||||
void factorizeChildren(Expression * e1, Expression * e2);
|
||||
void distributeOnChildAtIndex(int index);
|
||||
static bool TermsHaveIdenticalBase(const Expression * e1, const Expression * e2);
|
||||
static bool TermHasRationalBaseAndExponent(const Expression * e);
|
||||
static const Expression * CreateExponent(Expression * e);
|
||||
};
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ void Multiplication::immediateSimplify() {
|
||||
Rational a = Rational::Multiplication(*(static_cast<const Rational *>(operand(i))), *(static_cast<const Rational *>(operand(i+1))));
|
||||
replaceOperand(operand(i), new Rational(a), true);
|
||||
removeOperand(operand(i+1), true);
|
||||
} else if (TermsHaveIdenticalBase(operand(i), operand(i+1))) {
|
||||
} else if (TermsHaveIdenticalBase(operand(i), operand(i+1)) && !(TermHasRationalBaseAndExponent(operand(i)) && TermHasRationalBaseAndExponent(operand(i+1)))) {
|
||||
factorizeChildren(const_cast<Expression *>(operand(i)), const_cast<Expression *>(operand(i+1)));
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,12 @@ bool Multiplication::TermsHaveIdenticalBase(const Expression * e1, const Express
|
||||
return (f1->compareTo(f2) == 0);
|
||||
}
|
||||
|
||||
bool Multiplication::TermHasRationalBaseAndExponent(const Expression * e) {
|
||||
bool hasRationalBase = e->type() == Type::Power ? e->operand(0)->type() == Type::Rational : e->type() == Type::Rational;
|
||||
bool hasRationalExponent = e->type() == Type::Power ? e->operand(1)->type() == Type::Rational : true;
|
||||
return hasRationalBase && hasRationalExponent;
|
||||
}
|
||||
|
||||
template Poincare::Evaluation<float>* Poincare::Multiplication::computeOnComplexAndMatrix<float>(Poincare::Complex<float> const*, Poincare::Evaluation<float>*);
|
||||
template Poincare::Evaluation<double>* Poincare::Multiplication::computeOnComplexAndMatrix<double>(Poincare::Complex<double> const*, Poincare::Evaluation<double>*);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user