Skip to content

Commit

Permalink
This fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
PoslavskySV committed Sep 16, 2018
1 parent b438f93 commit e960bcd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ private static int next32BitPrime(int val) {
return SmallPrimes.nextPrime(val);
}

final static int N_MODULAR_FACTORIZATION_TRIALS = 2;
final static int
N_MIN_MODULAR_FACTORIZATION_TRIALS = 2, // minimal number of modular trials
N_SIMPLE_MOD_PATTERN_FACTORS = 12, // number of modular factors sufficient small enough to proceed to reconstruction
N_MODULAR_FACTORIZATION_TRIALS = 4; // maximal number of modular trials

/**
* Factors primitive square-free polynomial using Hensel lifting
Expand All @@ -412,6 +415,9 @@ static PolynomialFactorDecomposition<UnivariatePolynomial<BigInteger>> FactorSqu
PolynomialFactorDecomposition<UnivariatePolynomialZp64> lModularFactors = null;

for (int attempt = 0; attempt < N_MODULAR_FACTORIZATION_TRIALS; attempt++) {
if (attempt >= N_MIN_MODULAR_FACTORIZATION_TRIALS && lModularFactors.size() <= N_SIMPLE_MOD_PATTERN_FACTORS)
break;

long tmpModulus;
do {
tmpModulus = SmallPrimes.nextPrime(randomModulusInf());
Expand All @@ -421,6 +427,7 @@ static PolynomialFactorDecomposition<UnivariatePolynomial<BigInteger>> FactorSqu

// do modular factorization
PolynomialFactorDecomposition<UnivariatePolynomialZp64> tmpFactors = FactorInGF(moduloImage.monic());

if (tmpFactors.size() == 1)
return PolynomialFactorDecomposition.of(poly);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.util.function.Supplier;

import static cc.redberry.rings.Rings.Q;
import static cc.redberry.rings.Rings.UnivariateRing;
import static cc.redberry.rings.Rings.*;
import static cc.redberry.rings.poly.univar.UnivariateFactorization.Factor;
import static cc.redberry.rings.poly.univar.UnivariateFactorization.FactorInNumberField;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -547,4 +547,10 @@ public void testNumberField3_random() {
}
}
}

@Test(timeout = 100_000)
public void test7() {
UnivariatePolynomial<BigInteger> poly = UnivariatePolynomial.parse("x^259 - 1", Z, "x");
assertEquals(4, Factor(poly).size());
}
}

0 comments on commit e960bcd

Please sign in to comment.