[poincare] Fix Power and Multiplication

This commit is contained in:
Léa Saviot
2018-08-28 11:46:54 +02:00
parent d980bb3da9
commit 170a0d78b6
3 changed files with 8 additions and 15 deletions

View File

@@ -83,7 +83,7 @@ public:
addChildAtIndexInPlace(e1, 0, numberOfChildren());
}
Multiplication(Expression e1, Expression e2, Expression e3) : Multiplication(e2, e3) {
addChildAtIndexInPlace(e3, 0, numberOfChildren());
addChildAtIndexInPlace(e1, 0, numberOfChildren());
}
// Expression

View File

@@ -41,9 +41,9 @@ int primeFactors[Arithmetic::k_numberOfPrimeFactors] = {2, 3, 5, 7, 11, 13, 17,
// we can go to 7907*7907 = 62 520 649
void Arithmetic::PrimeFactorization(const Integer n, Integer outputFactors[], Integer outputCoefficients[], int outputLength) {
outputCoefficients[0] = -1;
if (n.isAllocationFailure()) {
/* Special case 0: Allocation failure. */
outputCoefficients[0] = -1;
return;
}
@@ -63,7 +63,6 @@ void Arithmetic::PrimeFactorization(const Integer n, Integer outputFactors[], In
/* Special case 1: We do not want to break i in prime factor because it
* might take too many factors... More than k_maxNumberOfPrimeFactors.
* outputCoefficients[0] is set to -1 to indicate a special case. */
outputCoefficients[0] = -1;
return;
}
for (int index = 0; index < outputLength; index++) {

View File

@@ -2,8 +2,8 @@
#include <poincare/addition.h>
#include <poincare/arithmetic.h>
//#include <poincare/binomial_coefficient.h>
//#include <poincare/cosine.h>
#include <poincare/binomial_coefficient.h>
#include <poincare/cosine.h>
#include <poincare/division.h>
#include <poincare/global_context.h>
//#include <poincare/matrix.h>
@@ -12,7 +12,7 @@
#include <poincare/opposite.h>
#include <poincare/parenthesis.h>
//#include <poincare/simplification_root.h>
//#include <poincare/sine.h>
#include <poincare/sine.h>
#include <poincare/square_root.h>
#include <poincare/symbol.h>
#include <poincare/subtraction.h>
@@ -395,16 +395,11 @@ Expression Power::shallowReduce(Context& context, Preferences::AngleUnit angleUn
const Expression pi = m.childAtIndex(m.numberOfChildren()-1);
m.replaceChildAtIndexInPlace(numberOfChildren()-1, Rational(180));
}
#if 0
Expression reducedM = m.shallowReduce(context, angleUnit);
Cosine cos = Cosine(reducedM).shallowReduce(context, angleUnit);
Expression cos = Cosine(reducedM).shallowReduce(context, angleUnit);
Expression sinPart = Sine(reducedM).shallowReduce(context, angleUnit);
sinPart = Multiplication(sinPart, i).shallowReduce(context, angleUnit);
return Addition(cos, sinPart).shallowReduce(context, angleUnit);
#else
// TODO remove if 0 once we have cos
return Rational(1);
#endif
}
// x^log(y,x)->y if y > 0
if (childAtIndex(1).type() == ExpressionNode::Type::Logarithm) {
@@ -514,10 +509,9 @@ Expression Power::shallowReduce(Context& context, Preferences::AngleUnit angleUn
/* The multinome (a0+a2+...+a(m-1))^n has BinomialCoefficient(n+m-1,n) terms;
* we expand the multinome only when the number of terms in the resulting
* sum has less than k_maxNumberOfTermsInExpandedMultinome terms. */
//TODO Decomment when BinomialCoefficient available
/*if (k_maxNumberOfTermsInExpandedMultinome < BinomialCoefficient::compute(static_cast<double>(clippedN), static_cast<double>(clippedN+m-1))) {
if (k_maxNumberOfTermsInExpandedMultinome < BinomialCoefficientNode::compute(static_cast<double>(clippedN), static_cast<double>(clippedN+m-1))) {
return *this;
}*/
}
Expression result = childAtIndex(0);
Expression a = result;