Skip to content

Commit e3c7e78

Browse files
committed
fix bug in TinyEcm64.searchFactors() +++ add more test numbers
1 parent 5ce96ca commit e3c7e78

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

src/main/java/de/tilman_neumann/jml/factor/ecm/TinyEcm64.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,24 +1145,24 @@ public void searchFactors(FactorArguments args, FactorResult result) {
11451145
// tinyEcm is unstable when it comes to find factors of small composites like 735 = 3*5*7^2
11461146
// so we need some trial division first
11471147
tdiv.setTestLimit(1<<16).searchFactors(args, result);
1148-
1148+
if (DEBUG) LOG.debug("result after tdiv = " + result);
1149+
11491150
if (result.untestedFactors.isEmpty()) return; // N was "easy"
11501151
// Otherwise we continue
11511152
BigInteger N = result.untestedFactors.firstKey();
1152-
int exp = result.untestedFactors.removeAll(N);
1153-
if (DEBUG) Ensure.ensureEquals(1, exp); // looks safe, otherwise we'ld have to consider exp below
1153+
int exp = result.untestedFactors.removeAll(N); // can be > 1
11541154

11551155
if (bpsw.isProbablePrime(N)) {
1156-
result.primeFactors.add(N);
1156+
result.primeFactors.add(N, exp);
11571157
return;
11581158
}
11591159

11601160
BigInteger factor1 = findSingleFactor(N);
1161-
//LOG.debug("After findSingleFactor()...");
1161+
if (DEBUG) LOG.debug("result after findSingleFactor() = " + result);
11621162
if (factor1.compareTo(I_1) > 0 && factor1.compareTo(N) < 0) {
11631163
// We found a factor, but here we cannot know if it is prime or composite
1164-
result.untestedFactors.add(factor1, args.exp);
1165-
result.untestedFactors.add(N.divide(factor1), args.exp);
1164+
result.untestedFactors.add(factor1, exp);
1165+
result.untestedFactors.add(N.divide(factor1), exp);
11661166
}
11671167

11681168
// nothing found

src/main/java/de/tilman_neumann/jml/factor/ecm/TinyEcm64MH.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,24 +1149,24 @@ public void searchFactors(FactorArguments args, FactorResult result) {
11491149
// tinyEcm is unstable when it comes to find factors of small composites like 735 = 3*5*7^2
11501150
// so we need some trial division first
11511151
tdiv.setTestLimit(1<<16).searchFactors(args, result);
1152-
1152+
if (DEBUG) LOG.debug("result after tdiv = " + result);
1153+
11531154
if (result.untestedFactors.isEmpty()) return; // N was "easy"
11541155
// Otherwise we continue
11551156
BigInteger N = result.untestedFactors.firstKey();
1156-
int exp = result.untestedFactors.removeAll(N);
1157-
if (DEBUG) Ensure.ensureEquals(1, exp); // looks safe, otherwise we'ld have to consider exp below
1157+
int exp = result.untestedFactors.removeAll(N); // can be > 1
11581158

11591159
if (bpsw.isProbablePrime(N)) {
1160-
result.primeFactors.add(N);
1160+
result.primeFactors.add(N, exp);
11611161
return;
11621162
}
11631163

11641164
BigInteger factor1 = findSingleFactor(N);
1165-
//LOG.debug("After findSingleFactor()...");
1165+
if (DEBUG) LOG.debug("result after findSingleFactor() = " + result);
11661166
if (factor1.compareTo(I_1) > 0 && factor1.compareTo(N) < 0) {
11671167
// We found a factor, but here we cannot know if it is prime or composite
1168-
result.untestedFactors.add(factor1, args.exp);
1169-
result.untestedFactors.add(N.divide(factor1), args.exp);
1168+
result.untestedFactors.add(factor1, exp);
1169+
result.untestedFactors.add(N.divide(factor1), exp);
11701170
}
11711171

11721172
// nothing found

src/main/java/de/tilman_neumann/jml/factor/ecm/TinyEcm64MHInlined.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,24 +1158,24 @@ public void searchFactors(FactorArguments args, FactorResult result) {
11581158
// tinyEcm is unstable when it comes to find factors of small composites like 735 = 3*5*7^2
11591159
// so we need some trial division first
11601160
tdiv.setTestLimit(1<<16).searchFactors(args, result);
1161-
1161+
if (DEBUG) LOG.debug("result after tdiv = " + result);
1162+
11621163
if (result.untestedFactors.isEmpty()) return; // N was "easy"
11631164
// Otherwise we continue
11641165
BigInteger N = result.untestedFactors.firstKey();
1165-
int exp = result.untestedFactors.removeAll(N);
1166-
if (DEBUG) Ensure.ensureEquals(1, exp); // looks safe, otherwise we'ld have to consider exp below
1166+
int exp = result.untestedFactors.removeAll(N); // can be > 1
11671167

11681168
if (bpsw.isProbablePrime(N)) {
1169-
result.primeFactors.add(N);
1169+
result.primeFactors.add(N, exp);
11701170
return;
11711171
}
11721172

11731173
BigInteger factor1 = findSingleFactor(N);
1174-
//LOG.debug("After findSingleFactor()...");
1174+
if (DEBUG) LOG.debug("result after findSingleFactor() = " + result);
11751175
if (factor1.compareTo(I_1) > 0 && factor1.compareTo(N) < 0) {
11761176
// We found a factor, but here we cannot know if it is prime or composite
1177-
result.untestedFactors.add(factor1, args.exp);
1178-
result.untestedFactors.add(N.divide(factor1), args.exp);
1177+
result.untestedFactors.add(factor1, exp);
1178+
result.untestedFactors.add(N.divide(factor1), exp);
11791179
}
11801180

11811181
// nothing found

src/test/java/de/tilman_neumann/jml/factor/ecm/TinyEcm64MHInlinedTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public void testCompositesWithSmallFactors() {
7171

7272
@Test
7373
public void testCompositesWithManyFactors() {
74+
assertFullFactorizationSuccess(853079565045063L, "3 * 2389^2 * 2579 * 19319");
75+
assertFullFactorizationSuccess(641200294641979L, "1487^2 * 6791 * 42701");
76+
assertFullFactorizationSuccess(22436046236739091L, "11 * 2267^2 * 13681 * 29009");
77+
assertFullFactorizationSuccess(25702072057537247L, "83 * 1231^2 * 1777 * 114997");
78+
assertFullFactorizationSuccess(1052330620377735995L, "5 * 5107^2 * 20549 * 392699");
79+
assertFullFactorizationSuccess(772770126233127151L, "1493^2 * 11273 * 30753263");
7480
assertFullFactorizationSuccess(35184372094495L, "5 * 13^2 * 17 * 19 * 29 * 47 * 271 * 349"); // 46 bit
7581
assertFullFactorizationSuccess(1096954293075013905L, "3 * 5 * 7^2 * 169681 * 8795650783"); // 60 bit
7682
assertFullFactorizationSuccess(1100087778366101931L, "3 * 7 * 43 * 89 * 199 * 263 * 307 * 881 * 967"); // Fibonacci(88), 60 bit
@@ -200,10 +206,4 @@ public void testHarderSemiprimesWithFactorsOfDifferentSize() {
200206
//assertFactorizationSuccess(8940500625246794041L, "240556271 * 37165942871"); // 63 bit
201207
//assertFactorizationSuccess(9170754184293724117L, "290060959 * 31616644363"); // 63 bit
202208
}
203-
204-
@Test
205-
public void testNumbersWithManyFactors() {
206-
assertFullFactorizationSuccess(1096954293075013905L, "3 * 5 * 7^2 * 169681 * 8795650783");
207-
assertFullFactorizationSuccess(1100087778366101931L, "3 * 7 * 43 * 89 * 199 * 263 * 307 * 881 * 967"); // Fibonacci(88)
208-
}
209209
}

src/test/java/de/tilman_neumann/jml/factor/ecm/TinyEcm64MHTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public void testCompositesWithSmallFactors() {
7171

7272
@Test
7373
public void testCompositesWithManyFactors() {
74+
assertFullFactorizationSuccess(853079565045063L, "3 * 2389^2 * 2579 * 19319");
75+
assertFullFactorizationSuccess(641200294641979L, "1487^2 * 6791 * 42701");
76+
assertFullFactorizationSuccess(22436046236739091L, "11 * 2267^2 * 13681 * 29009");
77+
assertFullFactorizationSuccess(25702072057537247L, "83 * 1231^2 * 1777 * 114997");
78+
assertFullFactorizationSuccess(1052330620377735995L, "5 * 5107^2 * 20549 * 392699");
79+
assertFullFactorizationSuccess(772770126233127151L, "1493^2 * 11273 * 30753263");
7480
assertFullFactorizationSuccess(35184372094495L, "5 * 13^2 * 17 * 19 * 29 * 47 * 271 * 349"); // 46 bit
7581
assertFullFactorizationSuccess(1096954293075013905L, "3 * 5 * 7^2 * 169681 * 8795650783"); // 60 bit
7682
assertFullFactorizationSuccess(1100087778366101931L, "3 * 7 * 43 * 89 * 199 * 263 * 307 * 881 * 967"); // Fibonacci(88), 60 bit
@@ -200,10 +206,4 @@ public void testHarderSemiprimesWithFactorsOfDifferentSize() {
200206
//assertFactorizationSuccess(8940500625246794041L, "240556271 * 37165942871"); // 63 bit
201207
//assertFactorizationSuccess(9170754184293724117L, "290060959 * 31616644363"); // 63 bit
202208
}
203-
204-
@Test
205-
public void testNumbersWithManyFactors() {
206-
assertFullFactorizationSuccess(1096954293075013905L, "3 * 5 * 7^2 * 169681 * 8795650783");
207-
assertFullFactorizationSuccess(1100087778366101931L, "3 * 7 * 43 * 89 * 199 * 263 * 307 * 881 * 967"); // Fibonacci(88)
208-
}
209209
}

src/test/java/de/tilman_neumann/jml/factor/ecm/TinyEcm64Test.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public void testCompositesWithSmallFactors() {
7171

7272
@Test
7373
public void testCompositesWithManyFactors() {
74+
assertFullFactorizationSuccess(853079565045063L, "3 * 2389^2 * 2579 * 19319");
75+
assertFullFactorizationSuccess(641200294641979L, "1487^2 * 6791 * 42701");
76+
assertFullFactorizationSuccess(22436046236739091L, "11 * 2267^2 * 13681 * 29009");
77+
assertFullFactorizationSuccess(25702072057537247L, "83 * 1231^2 * 1777 * 114997");
78+
assertFullFactorizationSuccess(1052330620377735995L, "5 * 5107^2 * 20549 * 392699");
79+
assertFullFactorizationSuccess(772770126233127151L, "1493^2 * 11273 * 30753263");
7480
assertFullFactorizationSuccess(35184372094495L, "5 * 13^2 * 17 * 19 * 29 * 47 * 271 * 349"); // 46 bit
7581
assertFullFactorizationSuccess(1096954293075013905L, "3 * 5 * 7^2 * 169681 * 8795650783"); // 60 bit
7682
assertFullFactorizationSuccess(1100087778366101931L, "3 * 7 * 43 * 89 * 199 * 263 * 307 * 881 * 967"); // Fibonacci(88), 60 bit
@@ -200,10 +206,4 @@ public void testHarderSemiprimesWithFactorsOfDifferentSize() {
200206
//assertFactorizationSuccess(8940500625246794041L, "240556271 * 37165942871"); // 63 bit
201207
//assertFactorizationSuccess(9170754184293724117L, "290060959 * 31616644363"); // 63 bit
202208
}
203-
204-
@Test
205-
public void testNumbersWithManyFactors() {
206-
assertFullFactorizationSuccess(1096954293075013905L, "3 * 5 * 7^2 * 169681 * 8795650783");
207-
assertFullFactorizationSuccess(1100087778366101931L, "3 * 7 * 43 * 89 * 199 * 263 * 307 * 881 * 967"); // Fibonacci(88)
208-
}
209209
}

0 commit comments

Comments
 (0)