From d8be1f19b46c1f565cefe5e21c9b6682d2e591e8 Mon Sep 17 00:00:00 2001 From: axexlck Date: Sat, 26 Dec 2020 16:43:45 +0100 Subject: [PATCH] Latest from jml --- .../jml/CollatzSequenceTest.java | 10 +- .../jml/factor/CombinedFactorAlgorithm.java | 4 +- .../jml/factor/FactorAlgorithm.java | 13 +- .../base/matrixSolver/FactorTest01.java | 2 +- .../jml/factor/cfrac/CFrac63.java | 5 +- .../jml/factor/ecm/EllipticCurveMethod.java | 36 ++-- .../lehman/Lehman_AnalyzeKFactoringMostN.java | 2 +- .../lehman/Lehman_AnalyzeKFactoringSameN.java | 2 +- .../factor/lehman/Lehman_AnalyzeKMods.java | 2 +- .../lehman/Lehman_AnalyzeKProgressions.java | 2 +- .../lehman/Lehman_AnalyzeKProgressions2.java | 2 +- .../lehman/Lehman_AnalyzeKStructure.java | 2 +- .../factor/lehman/Lehman_CustomKOrder.java | 5 +- .../jml/factor/psiqs/PSIQSBase.java | 198 +++++++++-------- .../tilman_neumann/jml/factor/siqs/SIQS.java | 203 +++++++++--------- .../factor/siqs/poly/AParamGenerator01.java | 2 +- .../jml/factor/siqs/poly/BParamTest.java | 2 +- .../factor/siqs/poly/SIQSPolyGenerator.java | 2 +- .../siqs/sieve/DoubleBlockHybridSieve.java | 4 +- .../siqs/sieve/DoubleBlockHybridSieveU.java | 4 +- .../factor/siqs/sieve/DoubleBlockSieve.java | 2 +- .../jml/factor/siqs/sieve/SieveParams.java | 5 +- .../siqs/sieve/SingleBlockHybridSieve.java | 4 +- .../siqs/sieve/SingleBlockHybridSieveU.java | 4 +- .../factor/siqs/sieve/SingleBlockSieve.java | 2 +- .../factor/siqs/sieve/SingleBlockSieveU.java | 2 +- .../jml/factor/tdiv/TDiv31Barrett.java | 24 ++- .../jml/factor/tdiv/TDiv31Inverse.java | 9 +- .../jml/primes/exact/SSOZJ.java | 5 +- 29 files changed, 294 insertions(+), 265 deletions(-) diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/CollatzSequenceTest.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/CollatzSequenceTest.java index 74b5ddf7d9..7de88e00aa 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/CollatzSequenceTest.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/CollatzSequenceTest.java @@ -106,12 +106,12 @@ private static void test3nPlus1DroppingSequence() { LOG.info( "record lengths = " + recordLengths); // A217934 = (0,) 1, 6, 11, 96, 132, 171, 220, 267, 269, 282, 287, - // 298, 365, 401, 468, 476, 486, 502, 613 + // 298, 365, 401, 468, 476, 486, 502, 613 LOG.info( "N(record lengths)= " + recordLengthsN); // A060412 = (1,) 2, 3, 7, 27, 703, 10087, 35655, 270271, 362343, - // 381727, 626331, 1027431, 1126015, 8088063, 13421671, 20638335, - // 26716671, 56924955, 63728127 + // 381727, 626331, 1027431, 1126015, 8088063, 13421671, 20638335, + // 26716671, 56924955, 63728127 analyzeNStartSequences(length2NStartList); analyzeProgressions(progressionToMaxLength); @@ -186,11 +186,11 @@ private static void test3nPlus1RepeatSequence() { LOG.info( "record lengths = " + recordLengths); // not on OEIS: 0, 1, 6, 10, 95, 132, 219, 262, 269, 271, 297, 305, - // 343, 357, 400, 468, 485 + // 343, 357, 400, 468, 485 LOG.info( "N(record lengths)= " + recordLengthsN); // not on OEIS: 1, 2, 3, 7, 27, 703, 35655, 270271, 362343, 401151, - // 1027431, 1327743, 1394431, 6206655, 8088063, 13421671, 26716671 + // 1027431, 1327743, 1394431, 6206655, 8088063, 13421671, 26716671 analyzeNStartSequences(length2NStartList); analyzeProgressions(progressionToMaxLength); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/CombinedFactorAlgorithm.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/CombinedFactorAlgorithm.java index 79b6944e71..96f321af5c 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/CombinedFactorAlgorithm.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/CombinedFactorAlgorithm.java @@ -41,7 +41,7 @@ import de.tilman_neumann.jml.factor.siqs.sieve.Sieve03gU; import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_1Large_UBI; import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_2Large_UBI; -import de.tilman_neumann.jml.factor.tdiv.TDiv31Inverse; +import de.tilman_neumann.jml.factor.tdiv.TDiv31Barrett; import de.tilman_neumann.util.ConfigUtil; import de.tilman_neumann.util.SortedMultiset; import de.tilman_neumann.util.TimeUtil; @@ -55,7 +55,7 @@ public class CombinedFactorAlgorithm extends FactorAlgorithm { @SuppressWarnings("unused") private static final Logger LOG = Logger.getLogger(CombinedFactorAlgorithm.class); - private TDiv31Inverse tDiv31 = new TDiv31Inverse(); + private TDiv31Barrett tDiv31 = new TDiv31Barrett(); private Hart_TDiv_Race hart = new Hart_TDiv_Race(); private PollardRhoBrentMontgomeryR64Mul63 pollardRhoR64Mul63 = new PollardRhoBrentMontgomeryR64Mul63(); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/FactorAlgorithm.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/FactorAlgorithm.java index 51f807c709..f924f24229 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/FactorAlgorithm.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/FactorAlgorithm.java @@ -111,10 +111,10 @@ public void factor(BigInteger N, SortedMultiset primeFactors) { if (lsb > 0) { primeFactors.add(I_2, lsb); N = N.shiftRight(lsb); - } - if (N.equals(I_1)) { - // N was a power of 2 - return; + if (N.equals(I_1)) { + // N was a power of 2 + return; + } } // N contains larger factors... @@ -187,8 +187,7 @@ public void factor(BigInteger N, SortedMultiset primeFactors) { // resolve untested factors while (untestedFactors.size() > 0) { BigInteger untestedFactor = untestedFactors.firstKey(); - int exp = untestedFactors.get(untestedFactor); - untestedFactors.removeAll(untestedFactor); + int exp = untestedFactors.removeAll(untestedFactor); if (bpsw.isProbablePrime(untestedFactor)) { // The untestedFactor is probable prime. In exceptional cases this prediction may be // wrong and untestedFactor composite @@ -215,7 +214,7 @@ public void factor(BigInteger N, SortedMultiset primeFactors) { break; } - BigInteger compositeFactor = factorResult.compositeFactors.keySet().iterator().next(); + BigInteger compositeFactor = factorResult.compositeFactors.firstKey(); int exp = factorResult.compositeFactors.removeAll(compositeFactor); FactorArguments args = new FactorArguments(compositeFactor, exp, smallestPossibleFactor); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/FactorTest01.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/FactorTest01.java index 90ec5d1dd5..7964661b08 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/FactorTest01.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/FactorTest01.java @@ -72,7 +72,7 @@ public void testForFactor(Set aqPairs) throws FactorException { for (long factor : totalQ_factors.keySet()) { if (factor == -1) continue; // sqrt(Q-product) can be positive or negative, but we want the positive solution - // -> skip sign + // -> skip sign int exp = totalQ_factors.get(factor); if ((exp & 1) == 1) { // non-square "solution" -> early exit diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/cfrac/CFrac63.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/cfrac/CFrac63.java index d7183af6e6..f94d328b43 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/cfrac/CFrac63.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/cfrac/CFrac63.java @@ -193,9 +193,8 @@ public BigInteger findSingleFactor(BigInteger N) { floor_sqrt_kN = (long) Math.sqrt( - kN - .doubleValue()); // faster than BigInteger sqrt; but the type conversion may - // give ceil(sqrt(kN)) for some N >= 54 bit + kN.doubleValue()); // faster than BigInteger sqrt; but the type conversion may + // give ceil(sqrt(kN)) for some N >= 54 bit BigInteger sqrt_kN_big = BigInteger.valueOf(floor_sqrt_kN); long diff = kN.subtract(sqrt_kN_big.multiply(sqrt_kN_big)).longValue(); if (diff == 0) return N.gcd(sqrt_kN_big); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/ecm/EllipticCurveMethod.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/ecm/EllipticCurveMethod.java index 26f5454c6b..bbd2e5cff8 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/ecm/EllipticCurveMethod.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/ecm/EllipticCurveMethod.java @@ -731,7 +731,7 @@ private void prac(int n, int[] x, int[] z, int[] xT, int[] zT, int[] xT2, int[] } /* do the first line of Table 4 whose condition qualifies */ if (4 * d <= 5 * e && ((d + e) % 3) == 0) { - /* condition 1 */ + /* condition 1 */ r = (2 * d - e) / 3; e = (2 * e - d) / 3; d = r; @@ -745,12 +745,12 @@ private void prac(int n, int[] x, int[] z, int[] xT, int[] zT, int[] xT2, int[] zA = zT2; zT2 = t; /* swap A and T2 */ } else if (4 * d <= 5 * e && (d - e) % 6 == 0) { - /* condition 2 */ + /* condition 2 */ d = (d - e) / 2; add3(xB, zB, xA, zA, xB, zB, xC, zC); /* B = f(A,B,C) */ duplicate(xA, zA, xA, zA, AA); /* A = 2*A */ } else if (d <= (4 * e)) { - /* condition 3 */ + /* condition 3 */ d -= e; add3(xT, zT, xB, zB, xA, zA, xC, zC); /* T = f(B,A,C) */ t = xB; @@ -762,17 +762,17 @@ private void prac(int n, int[] x, int[] z, int[] xT, int[] zT, int[] xT2, int[] zT = zC; zC = t; /* circular permutation (B,T,C) */ } else if ((d + e) % 2 == 0) { - /* condition 4 */ + /* condition 4 */ d = (d - e) / 2; add3(xB, zB, xB, zB, xA, zA, xC, zC); /* B = f(B,A,C) */ duplicate(xA, zA, xA, zA, AA); /* A = 2*A */ } else if (d % 2 == 0) { - /* condition 5 */ + /* condition 5 */ d /= 2; add3(xC, zC, xC, zC, xA, zA, xB, zB); /* C = f(C,A,B) */ duplicate(xA, zA, xA, zA, AA); /* A = 2*A */ } else if (d % 3 == 0) { - /* condition 6 */ + /* condition 6 */ d = d / 3 - e; duplicate(xT, zT, xA, zA, AA); /* T1 = 2*A */ add3(xT2, zT2, xA, zA, xB, zB, xC, zC); /* T2 = f(A,B,C) */ @@ -787,14 +787,14 @@ private void prac(int n, int[] x, int[] z, int[] xT, int[] zT, int[] xT2, int[] zB = zT; zT = t; /* circular permutation (C,B,T) */ } else if ((d + e) % 3 == 0) { - /* condition 7 */ + /* condition 7 */ d = (d - 2 * e) / 3; add3(xT, zT, xA, zA, xB, zB, xC, zC); /* T1 = f(A,B,C) */ add3(xB, zB, xT, zT, xA, zA, xB, zB); /* B = f(T1,A,B) */ duplicate(xT, zT, xA, zA, AA); add3(xA, zA, xA, zA, xT, zT, xA, zA); /* A = 3*A */ } else if ((d - e) % 3 == 0) { - /* condition 8 */ + /* condition 8 */ d = (d - e) / 3; add3(xT, zT, xA, zA, xB, zB, xC, zC); /* T1 = f(A,B,C) */ add3(xC, zC, xC, zC, xA, zA, xB, zB); /* C = f(A,C,B) */ @@ -807,7 +807,7 @@ private void prac(int n, int[] x, int[] z, int[] xT, int[] zT, int[] xT2, int[] duplicate(xT, zT, xA, zA, AA); add3(xA, zA, xA, zA, xT, zT, xA, zA); /* A = 3*A */ } else if (e % 2 == 0) { - /* condition 9 */ + /* condition 9 */ e /= 2; add3(xC, zC, xC, zC, xB, zB, xA, zA); /* C = f(C,B,A) */ duplicate(xB, zB, xB, zB, AA); /* B = 2*B */ @@ -834,41 +834,41 @@ private static int lucas_cost(int n, double v) { e = r; } if (4 * d <= 5 * e && ((d + e) % 3) == 0) { - /* condition 1 */ + /* condition 1 */ r = (2 * d - e) / 3; e = (2 * e - d) / 3; d = r; c += 3 * ADD; /* 3 additions */ } else if (4 * d <= 5 * e && (d - e) % 6 == 0) { - /* condition 2 */ + /* condition 2 */ d = (d - e) / 2; c += ADD + DUP; /* one addition, one duplicate */ } else if (d <= (4 * e)) { - /* condition 3 */ + /* condition 3 */ d -= e; c += ADD; /* one addition */ } else if ((d + e) % 2 == 0) { - /* condition 4 */ + /* condition 4 */ d = (d - e) / 2; c += ADD + DUP; /* one addition, one duplicate */ } else if (d % 2 == 0) { - /* condition 5 */ + /* condition 5 */ d /= 2; c += ADD + DUP; /* one addition, one duplicate */ } else if (d % 3 == 0) { - /* condition 6 */ + /* condition 6 */ d = d / 3 - e; c += 3 * ADD + DUP; /* three additions, one duplicate */ } else if ((d + e) % 3 == 0) { - /* condition 7 */ + /* condition 7 */ d = (d - 2 * e) / 3; c += 3 * ADD + DUP; /* three additions, one duplicate */ } else if ((d - e) % 3 == 0) { - /* condition 8 */ + /* condition 8 */ d = (d - e) / 3; c += 3 * ADD + DUP; /* three additions, one duplicate */ } else if (e % 2 == 0) { - /* condition 9 */ + /* condition 9 */ e /= 2; c += ADD + DUP; /* one addition, one duplicate */ } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringMostN.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringMostN.java index 60d179c2a4..8d3e917480 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringMostN.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringMostN.java @@ -107,7 +107,7 @@ public long findSingleFactor(long N) { aLimit += adjust1 < adjust2 ? adjust1 : adjust2; aStep = 4; // stepping over both adjusts with step width 16 would be more exact but is not - // faster + // faster } } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringSameN.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringSameN.java index 93523a49b2..e95d651491 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringSameN.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKFactoringSameN.java @@ -110,7 +110,7 @@ public long findSingleFactor(long N) { aLimit += adjust1 < adjust2 ? adjust1 : adjust2; aStep = 4; // stepping over both adjusts with step width 16 would be more exact but is not - // faster + // faster } } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKMods.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKMods.java index b66f14897f..866774e0b3 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKMods.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKMods.java @@ -110,7 +110,7 @@ public long findSingleFactor(long N) { aLimit += adjust1 < adjust2 ? adjust1 : adjust2; aStep = 4; // stepping over both adjusts with step width 16 would be more exact but is not - // faster + // faster } } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions.java index 740f4af794..0394318a77 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions.java @@ -127,7 +127,7 @@ public void findSingleFactor(long N, Progression progression) { aLimit += adjust1 < adjust2 ? adjust1 : adjust2; aStep = 4; // XXX true step widths may be bigger, like 4, 28, 4, 28, ... But computations - // are too costly. + // are too costly. } } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions2.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions2.java index bcf4f43851..0bfa08f5d6 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions2.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKProgressions2.java @@ -129,7 +129,7 @@ public void findSingleFactor(long N, Progression progression) { aLimit += adjust1 < adjust2 ? adjust1 : adjust2; aStep = 4; // XXX true step widths may be bigger, like 4, 28, 4, 28, ... But computations - // are too costly. + // are too costly. } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKStructure.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKStructure.java index 2c9863e693..0ccf86811b 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKStructure.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_AnalyzeKStructure.java @@ -125,7 +125,7 @@ public long findSingleFactor(long N) { aLimit += adjust1 < adjust2 ? adjust1 : adjust2; aStep = 4; // stepping over both adjusts with step width 16 would be more exact but is not - // faster + // faster } } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_CustomKOrder.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_CustomKOrder.java index 97e356a1fb..2c0554c39d 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_CustomKOrder.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/lehman/Lehman_CustomKOrder.java @@ -200,9 +200,8 @@ private long test( aStep = 8; aLimit += ((kPlusN - aLimit) & 7); } else { - aStep = - 4; // stepping over both adjusts with step width 16 would be more exact but is not - // faster + aStep = 4; // stepping over both adjusts with step width 16 would be more exact but is not + // faster final long adjust1 = (kPlusN - aLimit) & 15; final long adjust2 = (-kPlusN - aLimit) & 15; aLimit += adjust1 < adjust2 ? adjust1 : adjust2; diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSBase.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSBase.java index ab1f8990b4..ffb4fbe001 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSBase.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSBase.java @@ -395,94 +395,16 @@ private BigInteger findSingleFactorInternal(BigInteger N) { BigInteger factor = congruenceCollector.factor; if (ANALYZE) { - // assemble reports from all threads - PolyReport polyReport = threadArray[0].getPolyReport(); - SieveReport sieveReport = threadArray[0].getSieveReport(); - TDivReport tdivReport = threadArray[0].getTDivReport(); - for (int threadIndex = 1; threadIndex < numberOfThreads; threadIndex++) { - polyReport.add(threadArray[threadIndex].getPolyReport()); - sieveReport.add(threadArray[threadIndex].getSieveReport()); - tdivReport.add(threadArray[threadIndex].getTDivReport()); - } - CongruenceCollectorReport ccReport = congruenceCollector.getReport(); - // a detailed solverReport is not needed yet - - long initPolyDuration = polyReport.getTotalDuration(numberOfThreads); - long sieveDuration = sieveReport.getTotalDuration(numberOfThreads); - long tdivDuration = tdivReport.getTotalDuration(numberOfThreads); - - // report results - LOG.info(getName() + ":"); - LOG.info( - "Found factor " - + factor - + " (" - + factor.bitLength() - + " bits) of N=" - + N - + " (" - + N.bitLength() - + " bits) in " - + TimeUtil.timeStr(timer.totalRuntime())); - int pMaxBits = 32 - Integer.numberOfLeadingZeros(pMax); - LOG.info( - " multiplier k = " - + k - + ", kN%8 = " - + kN.mod(I_8) - + ", primeBaseSize = " - + primeBaseSize - + ", pMax = " - + pMax - + " (" - + pMaxBits - + " bits), sieveArraySize = " - + adjustedSieveArraySize); - LOG.info(" polyGenerator: " + polyReport.getOperationDetails()); - LOG.info(" tDiv: " + tdivReport.getOperationDetails()); - if (ANALYZE_LARGE_FACTOR_SIZES) LOG.info(" " + tdivReport.getQRestSizes()); - LOG.info(" cc: " + ccReport.getOperationDetails()); - if (ANALYZE_LARGE_FACTOR_SIZES) { - LOG.info(" " + ccReport.getPartialBigFactorSizes()); - LOG.info(" " + ccReport.getSmoothBigFactorSizes()); - LOG.info(" " + ccReport.getSmoothBigFactorPercentiles()); - LOG.info(" " + ccReport.getNonIntFactorPercentages()); - } - if (ANALYZE_Q_SIGNS) { - LOG.info(" " + ccReport.getPartialQSignCounts()); - LOG.info(" " + ccReport.getSmoothQSignCounts()); - } - LOG.info( - " #solverRuns = " - + congruenceCollector.getSolverRunCount() - + ", #tested null vectors = " - + matrixSolver.getTestedNullVectorCount()); - LOG.info( - " Approximate phase timings: tdiv=" - + initialTdivDuration - + "ms, ecm=" - + ecmDuration - + "ms, powerTest=" - + powerTestDuration - + "ms, initN=" - + initNDuration - + "ms, createThreads=" - + createThreadDuration - + "ms, initPoly=" - + initPolyDuration - + "ms, sieve=" - + sieveDuration - + "ms, tdiv=" - + tdivDuration - + "ms, cc=" - + congruenceCollector.getCollectDuration() - + "ms, solver=" - + congruenceCollector.getSolverDuration() - + "ms"); - LOG.info(" -> initPoly sub-timings: " + polyReport.getPhaseTimings(numberOfThreads)); - LOG.info(" -> sieve sub-timings: " + sieveReport.getPhaseTimings(numberOfThreads)); - LOG.info(" -> tdiv sub-timings: " + tdivReport.getPhaseTimings(numberOfThreads)); - // CC and solver have no sub-timings yet + logResults( + N, + k, + kN, + factor, + primeBaseSize, + pMax, + adjustedSieveArraySize, + threadArray, + numberOfThreads); } // kill all threads & release memory @@ -548,4 +470,104 @@ private void killThread(PSIQSThreadBase t) { } if (DEBUG) LOG.debug("thread " + t.getName() + " has been killed."); } + + private void logResults( + BigInteger N, + int k, + BigInteger kN, + BigInteger factor, + int primeBaseSize, + int pMax, + int adjustedSieveArraySize, + PSIQSThreadBase[] threadArray, + int numberOfThreads) { + // assemble reports from all threads + PolyReport polyReport = threadArray[0].getPolyReport(); + SieveReport sieveReport = threadArray[0].getSieveReport(); + TDivReport tdivReport = threadArray[0].getTDivReport(); + for (int threadIndex = 1; threadIndex < numberOfThreads; threadIndex++) { + polyReport.add(threadArray[threadIndex].getPolyReport()); + sieveReport.add(threadArray[threadIndex].getSieveReport()); + tdivReport.add(threadArray[threadIndex].getTDivReport()); + } + CongruenceCollectorReport ccReport = congruenceCollector.getReport(); + // a detailed solverReport is not needed yet + + long initPolyDuration = polyReport.getTotalDuration(numberOfThreads); + long sieveDuration = sieveReport.getTotalDuration(numberOfThreads); + long tdivDuration = tdivReport.getTotalDuration(numberOfThreads); + + // report results + LOG.info(getName() + ":"); + LOG.info( + "Found factor " + + factor + + " (" + + factor.bitLength() + + " bits) of N=" + + N + + " (" + + N.bitLength() + + " bits) in " + + TimeUtil.timeStr(timer.totalRuntime())); + int pMaxBits = 32 - Integer.numberOfLeadingZeros(pMax); + LOG.info( + " multiplier k = " + + k + + ", kN%8 = " + + kN.mod(I_8) + + ", primeBaseSize = " + + primeBaseSize + + ", pMax = " + + pMax + + " (" + + pMaxBits + + " bits), sieveArraySize = " + + adjustedSieveArraySize); + LOG.info(" polyGenerator: " + polyReport.getOperationDetails()); + LOG.info(" tDiv: " + tdivReport.getOperationDetails()); + if (ANALYZE_LARGE_FACTOR_SIZES) LOG.info(" " + tdivReport.getQRestSizes()); + LOG.info(" cc: " + ccReport.getOperationDetails()); + if (ANALYZE_LARGE_FACTOR_SIZES) { + LOG.info(" " + ccReport.getPartialBigFactorSizes()); + LOG.info(" " + ccReport.getSmoothBigFactorSizes()); + LOG.info(" " + ccReport.getSmoothBigFactorPercentiles()); + LOG.info(" " + ccReport.getNonIntFactorPercentages()); + } + if (ANALYZE_Q_SIGNS) { + LOG.info(" " + ccReport.getPartialQSignCounts()); + LOG.info(" " + ccReport.getSmoothQSignCounts()); + } + LOG.info( + " #solverRuns = " + + congruenceCollector.getSolverRunCount() + + ", #tested null vectors = " + + matrixSolver.getTestedNullVectorCount()); + LOG.info( + " Approximate phase timings: tdiv=" + + initialTdivDuration + + "ms, ecm=" + + ecmDuration + + "ms, powerTest=" + + powerTestDuration + + "ms, initN=" + + initNDuration + + "ms, createThreads=" + + createThreadDuration + + "ms, initPoly=" + + initPolyDuration + + "ms, sieve=" + + sieveDuration + + "ms, tdiv=" + + tdivDuration + + "ms, cc=" + + congruenceCollector.getCollectDuration() + + "ms, solver=" + + congruenceCollector.getSolverDuration() + + "ms"); + LOG.info(" -> initPoly sub-timings: " + polyReport.getPhaseTimings(numberOfThreads)); + LOG.info(" -> sieve sub-timings: " + sieveReport.getPhaseTimings(numberOfThreads)); + LOG.info(" -> tdiv sub-timings: " + tdivReport.getPhaseTimings(numberOfThreads)); + // CC and solver have no sub-timings yet + } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/SIQS.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/SIQS.java index b0aad4cb80..7830c49e42 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/SIQS.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/SIQS.java @@ -502,92 +502,7 @@ private BigInteger findSingleFactorInternal(BigInteger N) { BigInteger factor = fe.getFactor(); if (ANALYZE) { solverDuration += timer.capture(); - // get all reports - PolyReport polyReport = polyGenerator.getReport(); - SieveReport sieveReport = sieve.getReport(); - TDivReport tdivReport = auxFactorizer.getReport(); - CongruenceCollectorReport ccReport = congruenceCollector.getReport(); - // solverReport is not urgently needed - - long initPolyDuration = polyReport.getTotalDuration(1); - long sieveDuration = sieveReport.getTotalDuration(1); - long tdivDuration = tdivReport.getTotalDuration(1); - - // report results - LOG.info(getName() + ":"); - LOG.info( - "Found factor " - + factor - + " (" - + factor.bitLength() - + " bits) of N=" - + N - + " (" - + N.bitLength() - + " bits) in " - + TimeUtil.timeStr(timer.totalRuntime())); - int pMaxBits = 32 - Integer.numberOfLeadingZeros(pMax); - LOG.info( - " multiplier k = " - + k - + ", kN%8 = " - + kN.mod(I_8) - + ", primeBaseSize = " - + primeBaseSize - + ", pMax = " - + pMax - + " (" - + pMaxBits - + " bits), sieveArraySize = " - + adjustedSieveArraySize); - LOG.info(" polyGenerator: " + polyReport.getOperationDetails()); - LOG.info(" tDiv: " + tdivReport.getOperationDetails()); - if (ANALYZE_LARGE_FACTOR_SIZES) { - String qRestSizes = tdivReport.getQRestSizes(); - if (qRestSizes != null) { - LOG.info(" " + qRestSizes); - } - } - LOG.info(" cc: " + ccReport.getOperationDetails()); - if (ANALYZE_LARGE_FACTOR_SIZES) { - LOG.info(" " + ccReport.getPartialBigFactorSizes()); - LOG.info(" " + ccReport.getSmoothBigFactorSizes()); - LOG.info(" " + ccReport.getSmoothBigFactorPercentiles()); - LOG.info(" " + ccReport.getNonIntFactorPercentages()); - } - if (ANALYZE_Q_SIGNS) { - LOG.info(" " + ccReport.getPartialQSignCounts()); - LOG.info(" " + ccReport.getSmoothQSignCounts()); - } - LOG.info( - " #solverRuns = " - + solverRunCount - + ", #tested null vectors = " - + matrixSolver.getTestedNullVectorCount()); - LOG.info( - " Approximate phase timings: tdiv=" - + initialTdivDuration - + "ms, ecm=" - + ecmDuration - + "ms, powerTest=" - + powerTestDuration - + "ms, initN=" - + initNDuration - + "ms, initPoly=" - + initPolyDuration - + "ms, sieve=" - + sieveDuration - + "ms, tdiv=" - + tdivDuration - + "ms, cc=" - + ccDuration - + "ms, solver=" - + solverDuration - + "ms"); - LOG.info(" -> initPoly sub-timings: " + polyReport.getPhaseTimings(1)); - LOG.info(" -> sieve sub-timings: " + sieveReport.getPhaseTimings(1)); - LOG.info(" -> tdiv sub-timings: " + tdivReport.getPhaseTimings(1)); - // CC and solver have no sub-timings yet + logResults(N, k, kN, factor, primeBaseSize, pMax, adjustedSieveArraySize); } if (TEST_SIEVE) { float perfectSmoothPercentage = @@ -607,7 +522,7 @@ private BigInteger findSingleFactorInternal(BigInteger N) { // release memory after a factorization; this improves the accuracy of timings when several // algorithms are tested in parallel this.cleanUp(); - // return factor + // done return factor; } } @@ -620,15 +535,6 @@ private byte[] computeLogPArray(int[] primesArray, int primeBaseSize, float lnPM return logPArray; } - public void cleanUp() { - apg.cleanUp(); - polyGenerator.cleanUp(); - sieve.cleanUp(); - auxFactorizer.cleanUp(); - congruenceCollector.cleanUp(); - matrixSolver.cleanUp(); - } - private void testSieve(List foundAQPairs, int sieveArraySize) { for (AQPair aqPair : foundAQPairs) { if (aqPair instanceof Smooth) foundPerfectSmoothCount++; @@ -647,6 +553,111 @@ private void testSieve(List foundAQPairs, int sieveArraySize) { allAQPairsCount += allAQPairs.size(); } + private void logResults( + BigInteger N, + int k, + BigInteger kN, + BigInteger factor, + int primeBaseSize, + int pMax, + int adjustedSieveArraySize) { + // get all reports + PolyReport polyReport = polyGenerator.getReport(); + SieveReport sieveReport = sieve.getReport(); + TDivReport tdivReport = auxFactorizer.getReport(); + CongruenceCollectorReport ccReport = congruenceCollector.getReport(); + // solverReport is not urgently needed + + long initPolyDuration = polyReport.getTotalDuration(1); + long sieveDuration = sieveReport.getTotalDuration(1); + long tdivDuration = tdivReport.getTotalDuration(1); + + // report results + LOG.info(getName() + ":"); + LOG.info( + "Found factor " + + factor + + " (" + + factor.bitLength() + + " bits) of N=" + + N + + " (" + + N.bitLength() + + " bits) in " + + TimeUtil.timeStr(timer.totalRuntime())); + int pMaxBits = 32 - Integer.numberOfLeadingZeros(pMax); + LOG.info( + " multiplier k = " + + k + + ", kN%8 = " + + kN.mod(I_8) + + ", primeBaseSize = " + + primeBaseSize + + ", pMax = " + + pMax + + " (" + + pMaxBits + + " bits), sieveArraySize = " + + adjustedSieveArraySize); + LOG.info(" polyGenerator: " + polyReport.getOperationDetails()); + LOG.info(" tDiv: " + tdivReport.getOperationDetails()); + if (ANALYZE_LARGE_FACTOR_SIZES) { + String qRestSizes = tdivReport.getQRestSizes(); + if (qRestSizes != null) { + LOG.info(" " + qRestSizes); + } + } + LOG.info(" cc: " + ccReport.getOperationDetails()); + if (ANALYZE_LARGE_FACTOR_SIZES) { + LOG.info(" " + ccReport.getPartialBigFactorSizes()); + LOG.info(" " + ccReport.getSmoothBigFactorSizes()); + LOG.info(" " + ccReport.getSmoothBigFactorPercentiles()); + LOG.info(" " + ccReport.getNonIntFactorPercentages()); + } + if (ANALYZE_Q_SIGNS) { + LOG.info(" " + ccReport.getPartialQSignCounts()); + LOG.info(" " + ccReport.getSmoothQSignCounts()); + } + LOG.info( + " #solverRuns = " + + solverRunCount + + ", #tested null vectors = " + + matrixSolver.getTestedNullVectorCount()); + LOG.info( + " Approximate phase timings: tdiv=" + + initialTdivDuration + + "ms, ecm=" + + ecmDuration + + "ms, powerTest=" + + powerTestDuration + + "ms, initN=" + + initNDuration + + "ms, initPoly=" + + initPolyDuration + + "ms, sieve=" + + sieveDuration + + "ms, tdiv=" + + tdivDuration + + "ms, cc=" + + ccDuration + + "ms, solver=" + + solverDuration + + "ms"); + LOG.info(" -> initPoly sub-timings: " + polyReport.getPhaseTimings(1)); + LOG.info(" -> sieve sub-timings: " + sieveReport.getPhaseTimings(1)); + LOG.info(" -> tdiv sub-timings: " + tdivReport.getPhaseTimings(1)); + // CC and solver have no sub-timings yet + } + + public void cleanUp() { + apg.cleanUp(); + polyGenerator.cleanUp(); + sieve.cleanUp(); + auxFactorizer.cleanUp(); + congruenceCollector.cleanUp(); + matrixSolver.cleanUp(); + } + // Standalone test // -------------------------------------------------------------------------------------------------- diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/AParamGenerator01.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/AParamGenerator01.java index c623ed09b4..a95734eb3c 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/AParamGenerator01.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/AParamGenerator01.java @@ -291,7 +291,7 @@ public BigInteger computeNextAParameter() { int[] disjunctQCountCounts = new int [qCount]; // entry 0: #aParams with 1 disjunct q, entry 1: #aParams with 2 disjunct q, - // ... + // ... for (int[] oldQArray : aParamHistory.values()) { int sharedQCount = getSharedQCount(oldQArray, qArray); int disjunctQCount = qCount - sharedQCount; diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/BParamTest.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/BParamTest.java index dbf238101c..3520721ed0 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/BParamTest.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/BParamTest.java @@ -71,7 +71,7 @@ private void computeFirstBParameter() { B2Array[l] = Bl.shiftLeft( 1); // store 2 * B_l in B2[0]...B2[s-1] (the last one is only required to compute b - // below) + // below) // WARNING: In contrast to the description in [Contini p.10, 2nd paragraph], // WARNING: b must not be computed (mod a) ! b = b.add(Bl); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/SIQSPolyGenerator.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/SIQSPolyGenerator.java index 5026de7a6f..b4062ad86a 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/SIQSPolyGenerator.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/poly/SIQSPolyGenerator.java @@ -296,7 +296,7 @@ private void computeFirstBParameter() { B2Array[l] = Bl.shiftLeft( 1); // store 2 * B_l in B2[0]...B2[s-1] (the last one is only required to compute b - // below) + // below) B2Array_UBI[l] = new UnsignedBigInt(B2Array[l]); // WARNING: In contrast to the description in [Contini p.10, 2nd paragraph], // WARNING: b must not be computed (mod a) ! diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieve.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieve.java index 28f7236cbe..fb546bd0d4 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieve.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieve.java @@ -240,7 +240,7 @@ public List sieve() { for (int b2 = 0; b2 < k2; b2++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block final int b2Offset = b2 * effectiveB2; System.arraycopy(sieveArray, b2Offset, sieveBlock, 0, effectiveB2); @@ -314,7 +314,7 @@ public List sieve() { for (int b2 = 0; b2 < k2; b2++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted final int b2Offset = b2 * effectiveB2; System.arraycopy(sieveArray, b2Offset, sieveBlock, 0, effectiveB2); if (ANALYZE) initDuration += timer.capture(); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieveU.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieveU.java index 919fe91f6c..a372d03a8d 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieveU.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockHybridSieveU.java @@ -252,7 +252,7 @@ public List sieve() { for (int b2 = 0; b2 < k2; b2++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block final int b2Offset = b2 * effectiveB2; UNSAFE.copyMemory(sieveArrayAddress + b2Offset, sieveBlockAddress, effectiveB2); @@ -359,7 +359,7 @@ public List sieve() { for (int b2 = 0; b2 < k2; b2++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted final int b2Offset = b2 * effectiveB2; UNSAFE.copyMemory(sieveArrayAddress + b2Offset, sieveBlockAddress, effectiveB2); if (ANALYZE) initDuration += timer.capture(); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockSieve.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockSieve.java index d331464179..1c94f9dce1 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockSieve.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/DoubleBlockSieve.java @@ -182,7 +182,7 @@ public List sieve() { for (int b2 = 0; b2 < k2; b2++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block System.arraycopy(initializedBlock, 0, sieveBlock, 0, effectiveB2); if (ANALYZE) initDuration += timer.capture(); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SieveParams.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SieveParams.java index 5682e2fd9c..291a4efee5 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SieveParams.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SieveParams.java @@ -82,9 +82,8 @@ public SieveParams( } initializer = computeInitializerValue(primeBase, pMinIndex, minLogPSum, lnLogBase); lnPMultiplier = - 1.0F - / lnLogBase; // normalizer to be used as a multiplier for p_i values (faster than a - // divisor) + 1.0F / lnLogBase; // normalizer to be used as a multiplier for p_i values (faster than a + // divisor) } /** diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieve.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieve.java index 526e29d632..6577853e77 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieve.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieve.java @@ -232,7 +232,7 @@ public List sieve() { for (int b = 0; b < blockCount; b++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block final int blockOffset = b * effectiveBlockSize; System.arraycopy(sieveArray, blockOffset, sieveBlock, 0, effectiveBlockSize); @@ -305,7 +305,7 @@ public List sieve() { for (int b = 0; b < blockCount; b++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // negative x: initialize block final int blockOffset = b * effectiveBlockSize; System.arraycopy(sieveArray, blockOffset, sieveBlock, 0, effectiveBlockSize); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieveU.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieveU.java index 8545dd4d86..8b7fb9bcab 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieveU.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockHybridSieveU.java @@ -245,7 +245,7 @@ public List sieve() { for (int b = 0; b < blockCount; b++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block final int blockOffset = b * effectiveBlockSize; UNSAFE.copyMemory(sieveArrayAddress + blockOffset, sieveBlockAddress, effectiveBlockSize); @@ -342,7 +342,7 @@ public List sieve() { for (int b = 0; b < blockCount; b++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // negative x: initialize block final int blockOffset = b * effectiveBlockSize; UNSAFE.copyMemory(sieveArrayAddress + blockOffset, sieveBlockAddress, effectiveBlockSize); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieve.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieve.java index 03f43b04b8..818b453dad 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieve.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieve.java @@ -158,7 +158,7 @@ public List sieve() { for (int b = 0; b < blockCount; b++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block System.arraycopy(initializedBlock, 0, sieveBlock, 0, effectiveBlockSize); if (ANALYZE) initDuration += timer.capture(); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieveU.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieveU.java index 5d83a8f0f2..d68b306571 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieveU.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SingleBlockSieveU.java @@ -161,7 +161,7 @@ public List sieve() { for (int b = 0; b < blockCount; b++) { // bottom-up order is required because in each block, the data for the next block is - // adjusted + // adjusted // positive x: initialize block UNSAFE.copyMemory(initializedBlockAddress, sieveBlockAddress, effectiveBlockSize); if (ANALYZE) initDuration += timer.capture(); diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Barrett.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Barrett.java index 08f348df98..99ccc49273 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Barrett.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Barrett.java @@ -58,29 +58,35 @@ public String getName() { @Override public void factor(BigInteger Nbig, SortedMultiset primeFactors) { + factor(Nbig, 1, primeFactors); + } + + /** + * Find all factor of NBig, which must have less than 32 bit. + * + * @param Nbig + * @param Nexp the exponent which with found factors are added to primeFactors + * @param primeFactors + */ + public void factor(BigInteger Nbig, int Nexp, SortedMultiset primeFactors) { int N = Nbig.intValue(); // Powers of 2 can be removed very fast. // This is required also because the Barrett division does not work with p=2. int lsb = Integer.numberOfTrailingZeros(N); if (lsb > 0) { - primeFactors.add(I_2, lsb); + primeFactors.add(I_2, lsb * Nexp); N >>= lsb; } // Test odd primes int q; for (int i = 1; ; i++) { - final long r = pinv[i]; final int p = primes[i]; - int exp = 0; - while ((q = (1 + (int) ((N * r) >> 32))) * p == N) { - exp++; + while ((q = (1 + (int) ((N * pinv[i]) >> 32))) * p == N) { + primeFactors.add(BigInteger.valueOf(p), Nexp); N = q; } - if (exp > 0) { - primeFactors.add(BigInteger.valueOf(p), exp); - } if (p * (long) p > N) { break; } @@ -88,7 +94,7 @@ public void factor(BigInteger Nbig, SortedMultiset primeFactors) { if (N > 1) { // either N is prime, or we could not find all factors -> add the rest to the result - primeFactors.add(BigInteger.valueOf(N)); + primeFactors.add(BigInteger.valueOf(N), Nexp); } } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Inverse.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Inverse.java index 2eba55643d..05f5c12534 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Inverse.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Inverse.java @@ -76,18 +76,13 @@ public void factor(BigInteger Nbig, int Nexp, SortedMultiset primeFa int q; for (int i = 0; ; i++) { - final double r = reciprocals[i]; final int p = primes[i]; - int exp = 0; - while ((q = (int) (N * r + DISCRIMINATOR)) * p == N) { - exp++; + while ((q = (int) (N * reciprocals[i] + DISCRIMINATOR)) * p == N) { + primeFactors.add(BigInteger.valueOf(p), Nexp); N = q; // avoiding a division here by storing q benefits the int version but not the long // version } - if (exp > 0) { - primeFactors.add(BigInteger.valueOf(p), exp * Nexp); - } if (p * (long) p > N) { break; } diff --git a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/primes/exact/SSOZJ.java b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/primes/exact/SSOZJ.java index 12b1ea954d..fd0f449080 100644 --- a/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/primes/exact/SSOZJ.java +++ b/symja_android_library/matheclipse-external/src/main/java/de/tilman_neumann/jml/primes/exact/SSOZJ.java @@ -476,9 +476,8 @@ static void twinprimes_ssoz() { public static void main(String[] args) { // if (args==null) Scanner userInput = new Scanner(System.in); - userInput.useDelimiter( - "[,\\s+]"); // see - // https://stackoverflow.com/questions/11463327/is-this-a-memory-leak-or-a-false-positive + userInput.useDelimiter("[,\\s+]"); // see + // https://stackoverflow.com/questions/11463327/is-this-a-memory-leak-or-a-false-positive System.out.println("Please enter an range of integer (comma or space separated): "); // Only BigDecimal understand scientific notation BigInteger stop = userInput.nextBigDecimal().toBigIntegerExact();