Skip to content

Commit

Permalink
[poincare] Improve PrimeFactorization: n decomposition requires searc…
Browse files Browse the repository at this point in the history
…hing among prime factors p with p^2 <= n
  • Loading branch information
EmilieNumworks committed Jan 25, 2018
1 parent 0c96996 commit 3c5b840
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions poincare/src/arithmetic.cpp
Expand Up @@ -65,8 +65,8 @@ void Arithmetic::PrimeFactorization(const Integer * n, Integer * outputFactors,
IntegerDivision d = {.quotient = 0, .remainder = 0};
bool stopCondition;
do {
stopCondition = Integer::Power(outputFactors[t], Integer(2)).isLowerThan(m);
d = Integer::Division(m, testedPrimeFactor);
stopCondition = outputFactors[t].isLowerThan(d.quotient); // We evaluate the condition here in case we move d.quotient in n
if (d.remainder.isEqualTo(Integer(0))) {
outputCoefficients[t] = Integer::Addition(outputCoefficients[t], Integer(1));
m = std::move(d.quotient);
Expand All @@ -82,7 +82,7 @@ void Arithmetic::PrimeFactorization(const Integer * n, Integer * outputFactors,
testedPrimeFactor = k < k_numberOfPrimeFactors ? Integer(primeFactors[k]) : Integer::Addition(testedPrimeFactor, Integer(1));
outputFactors[t] = testedPrimeFactor;
} while (stopCondition && testedPrimeFactor.isLowerThan(Integer(k_biggestPrimeFactor)));
if (Integer(k_biggestPrimeFactor).isLowerThan(m)) {
if (Integer::Power(Integer(k_biggestPrimeFactor), Integer(2)).isLowerThan(m)) {
/* Special case 2: We do not want to break i in prime factor because it
* take too much time: the prime factor that should be tested is above
* k_biggestPrimeFactor.
Expand Down
3 changes: 2 additions & 1 deletion poincare/test/function.cpp
Expand Up @@ -307,7 +307,8 @@ QUIZ_CASE(poincare_function_simplify) {
assert_parsed_expression_simplify_to("99!", "933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000");
assert_parsed_expression_simplify_to("factor(-10008/6895)", "-(2^3*3^2*139)/(5*7*197)");
assert_parsed_expression_simplify_to("factor(1008/6895)", "(2^4*3^2)/(5*197)");
assert_parsed_expression_simplify_to("factor(10007)", "undef");
assert_parsed_expression_simplify_to("factor(10007)", "10007");
assert_parsed_expression_simplify_to("factor(10007^2)", "undef");
assert_parsed_expression_simplify_to("floor(-1.3)", "-2");
assert_parsed_expression_simplify_to("frac(-1.3)", "7/10");
assert_parsed_expression_simplify_to("gcd(123,278)", "1");
Expand Down

0 comments on commit 3c5b840

Please sign in to comment.