[poincare] Correct Multiplication::simplify to avoid factorizing

2*2^(1/2)

Change-Id: I32d51584a372afa29a36a3e94f65b024bc9e9bc4
This commit is contained in:
Émilie Feral
2017-10-06 15:55:42 +02:00
parent 22be8032e1
commit ed9aae3003
2 changed files with 8 additions and 1 deletions

View File

@@ -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);
};

View File

@@ -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>*);
}