Skip to content

Commit

Permalink
Better heuristics for univariate factorization over Z
Browse files Browse the repository at this point in the history
  • Loading branch information
PoslavskySV committed May 2, 2022
1 parent cfd6722 commit 8097385
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rings.repl/rings.repl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ case $os in
;;
esac

ringsVersion=2.5.7
ringsVersion=2.5.8
ammArgs=()
javaArgs=()

Expand Down
4 changes: 2 additions & 2 deletions rings.scaladsl/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ organization := "cc.redberry"

name := "rings.scaladsl"

version := "2.5.7"
version := "2.5.8"

scalaVersion := "2.13.5"

crossScalaVersions := Seq("2.11.12", "2.12.13", "2.13.5")
crossScalaVersions := Seq("2.12.13", "2.13.5")

moduleName := name.value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ private static int next32BitPrime(int val) {
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
N_MODULAR_FACTORIZATION_TRIALS = 4, // maximal number of modular trials
N_TOO_MUCH_FACTORS_COUNT = 22, // if there are more modular factors, then we will use more modular factorization attempts
N_MODULAR_FACTORIZATION_TRIALS_TOO_MUCH_FACTORS = 12; // maximal number of modular trials if there are too many factors

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

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

long tmpModulus;
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,4 +553,10 @@ public void test7() {
UnivariatePolynomial<BigInteger> poly = UnivariatePolynomial.parse("x^259 - 1", Z, "x");
assertEquals(4, Factor(poly).size());
}

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

0 comments on commit 8097385

Please sign in to comment.