Skip to content

Commit 24327b4

Browse files
Merge pull request #89 from AndrewVSutherland/main
add 2/7 support to egs.c and corresponding hint file for 210-67425
2 parents 76f3ac1 + ceadb3c commit 24327b4

File tree

3 files changed

+106
-22
lines changed

3 files changed

+106
-22
lines changed

src/fastegs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The following files contain bounds on $$t(N)$$ produced as above:
5050
To see all the command line options that are supported, run `egs` without specifying any arguments:
5151
```
5252
$ ./egs
53-
Usage: egs [-v level] [-h filename] [-d filename] [-r] [-c] [-e] [-f] N-range [t]
53+
Usage: egs [-v level] [-h filename] [-d filename] [-r] [-c] [-e] [-f] N-range [t or t/N ratio]
5454
-v level integer verbosity level -1 to 4 (optional, default is 0)
5555
-h filename hint-file with records N:t (required if range of N is specified)
5656
-d filename output-file to dump factorization to (one factor per line, only valid if t is specified)
@@ -61,4 +61,5 @@ Usage: egs [-v level] [-h filename] [-d filename] [-r] [-c] [-e] [-f] N-range [t
6161
-m exponent for primecount/primesieve cutuff, must lie in [1/6,1/3]
6262
N-range integer N or range of integers minN-maxN (required, scientific notation supported)
6363
t integer t to use for single N (optional, a good t will be determined if unspecified)
64+
t/N ratio a/b with integers a,b>0 specifying t = ceil(aN/b) (optional, set to 1/3 if unspecified)
6465
```

src/fastegs/egs.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,11 @@ int64_t tfac (int64_t N, int64_t t, int fast, int feasible, int verbosity, int v
586586
}
587587

588588

589-
// returns a value of t >= N/3 that yields a good lower bound on t(N), or 0 if no such t can be found
590-
int64_t tbound (int64_t N, int fast, int exhaustive, int verbosity, int verify)
589+
// returns a value of t >= aN/b that yields a good lower bound on t(N), or 0 if no such t can be found
590+
int64_t tbound (int64_t N, int a, int b, int fast, int exhaustive, int verbosity, int verify)
591591
{
592-
int64_t t = cdiv(N,3);
592+
assert (a*5 <= 2*b && a*4 >= b);
593+
int64_t t = cdiv(a*N,b);
593594
int64_t cnt = tfac(N,t,fast,0,verbosity,verify,0);
594595
while ( cnt < N ) cnt = tfac(N,--t,fast,0,verbosity,verify,0);
595596
int64_t tmin = t, tmax = (2*N)/5;
@@ -645,7 +646,7 @@ int64_t tbound (int64_t N, int fast, int exhaustive, int verbosity, int verify)
645646
static void usage (void)
646647
{
647648
fprintf(stderr,
648-
"Usage: egs [-v level] [-h filename] [-d filename] [-r] [-c] [-e] [-f] N-range [t]\n"
649+
"Usage: egs [-v level] [-h filename] [-d filename] [-r] [-c] [-e] [-f] N-range [t or t/N ratio]\n"
649650
" -v level integer verbosity level -1 to 4 (optional, default is 0)\n"
650651
" -h filename hint-file with records N:t (required if range of N is specified)\n"
651652
" -d filename output-file to dump factorization to (one factor per line, only valid if t is specified)\n"
@@ -655,7 +656,8 @@ static void usage (void)
655656
" -f use fast version of greedy algorithm\n"
656657
" -m exponent for primecount/primesieve cutuff, must lie in [1/6,1/3]\n"
657658
" N-range integer N or range of integers minN-maxN (required, scientific notation supported)\n"
658-
" t integer t to use for single N (optional, a good t will be determined if unspecified)\n");
659+
" t integer t to use for single N (optional, a good t will be determined if unspecified)\n"
660+
" t/N ratio a/b with integers a,b>0 specifying t = ceil(aN/b), set to 1/3 if unspecified\n");
659661

660662
}
661663

@@ -666,10 +668,11 @@ int main (int argc, char *argv[])
666668
int verbosity=0, exhaustive=0, create=0, fast=0, verify=0;
667669
char *hintfile = 0, *dumpfile = 0;
668670
int64_t minN=0, maxN=0, t=0;
671+
int a=1, b=3;
669672

670673
for ( int i = 1 ; i < argc ; i++ ) {
671674
char *s = argv[i];
672-
if ( maxN > minN || t ) { fprintf(stderr, "ignoring extraneous argument %s\n",s); continue; }
675+
if ( maxN > minN && t ) { fprintf(stderr, "ignoring extraneous argument %s\n",s); continue; }
673676
if ( *s == '-' ) {
674677
switch(*(s+1)) {
675678
case 'v': { if ( i+1 >= argc) { usage(); return -1; } verbosity = atoi(argv[i+1]); i++; break; }
@@ -698,7 +701,14 @@ int main (int argc, char *argv[])
698701
maxN = minN;
699702
}
700703
} else {
701-
t = strtold(s,0);
704+
char *x;
705+
if ( (x=strchr(s,'/')) ) {
706+
a = atoi(s); b = atoi(x+1);
707+
assert (a > 0 && b > 0 && 4*a >= b && 5*a <= 2*b);
708+
} else {
709+
if ( maxN > minN && t ) { fprintf(stderr, "For a range of N you need to specify the t/N ratio (e.g. 1/3) not a fixed value of t\n"); return -1; }
710+
t = strtold(s,0);
711+
}
702712
}
703713
}
704714
}
@@ -720,6 +730,9 @@ int main (int argc, char *argv[])
720730
setup(maxp,maxm);
721731
if ( verbosity > 0 ) fprintf(stderr,"Computed %d-smooth factorizations of m <= %d using %.3fMB of memory (%.3fs)\n", MAXP,MAXM,4.0*(MAXM+(Fend-F))/(1<<20),get_time()-start);
722732

733+
char rbuf[32];
734+
if ( a == 1 ) sprintf(rbuf,"N/%d",b); else sprintf(rbuf,"%dN/%d",a,b);
735+
723736
start = get_time();
724737
if ( maxN > minN ) {
725738
if ( create || !hintfile) {
@@ -729,15 +742,17 @@ int main (int argc, char *argv[])
729742
if ( hintfile && !fp ) { fprintf(stderr, "Error creating hint-file %s\n", hintfile); return -1; }
730743
int64_t N = minN;
731744
while ( N <= maxN ) {
732-
t = tbound(N,fast,exhaustive,verbosity,verify);
733-
if ( 3*t < N ) break;
734-
if ( verbosity >= 0 ) fprintf (stderr,"t(%ld) >= %ld (t-N/3 >= %ld) (%.3fs)\n", N, t, t-cdiv(N,3), get_time()-start);
745+
t = tbound(N,a,b,fast,exhaustive,verbosity,verify);
746+
if ( b*t < a*N ) break;
747+
if ( verbosity >= 0 ) fprintf (stderr,"t(%ld) >= %ld (t-%s >= %ld) (%.3fs)\n", N, t, rbuf, t-cdiv(a*N,b), get_time()-start);
735748
if ( fp ) fprintf(fp,"%ld:%ld\n",N,t);
736-
N = 3*t+1;
749+
N = b*t/a+1;
750+
}
751+
if ( N > maxN ) {
752+
fprintf (stderr,"Verified the %s Erdős-Guy-Selfridge conjecture for all N in [%ld,%ld] (%.3fs)\n",rbuf,minN,maxN,get_time()-start);
737753
}
738-
if ( N > maxN ) fprintf (stderr,"Verified the Erdős-Guy-Selfridge conjecture for N in [%ld,%ld] (%.3fs)\n",minN,maxN,get_time()-start);
739-
else if ( N == minN ) fprintf (stderr,"Unable to verify Erdős-Guy-Selfridge conjecture for N=%ld (%.3fs)\n",minN,get_time()-start);
740-
else fprintf (stderr,"Only able to verify the Erdős-Guy-Selfridge conjecture for N in [%ld,%ld] (%.3fs)\n",minN,N-1,get_time()-start);
754+
else if ( N == minN ) fprintf (stderr,"Unable to verify the %s Erdős-Guy-Selfridge conjecture for N=%ld in (%.3fs)\n",rbuf,minN,get_time()-start);
755+
else fprintf (stderr,"Only able to verify the %s Erdős-Guy-Selfridge conjecture for N in [%ld,%ld] (%.3fs)\n",rbuf,minN,N-1,get_time()-start);
741756
} else {
742757
FILE *fp = fopen(hintfile,"r"); if (!fp) { fprintf(stderr, "Error opening hint-file %s\n", hintfile); return -1; }
743758
char buf[256];
@@ -746,30 +761,30 @@ int main (int argc, char *argv[])
746761
int64_t N = atol(buf);
747762
char *s = strchr(buf,':'); if (!s) { fprintf(stderr, "Error parsing line %s\n", buf); return -1; }
748763
t = atol(s+1);
749-
if ( 3*t < N ) { fprintf(stderr, "Invalid N:t in hint file: 3*%ld < %ld\n", t, N); return -1; }
764+
if ( b*t < a*N ) { fprintf(stderr, "Invalid N:t in hint file: %d*%ld < %d*%ld\n", b, t, a, N); return -1; }
750765
double timer = get_time();
751766
if ( tfac(N,t,fast,0,verbosity,verify,0) < N ) { fprintf (stderr, "Failed to verify t(%ld) >= %ld !\n", N,t); return -1; }
752767
if (!minV) {
753768
if ( N > minN ) { fprintf(stderr, "Hint file starting N=%ld above range minimum %ld\n", N, minN); return -1; }
754769
minV = N;
755-
maxV = 3*t;
770+
maxV = b*t/a;
756771
} else {
757772
if ( N > maxV+1 ) { fprintf(stderr, "Hint file starting N=%ld leaves a gap!\n", N); return -1; }
758-
if ( 3*t <= maxV ) { fprintf (stderr, "Hint at N=%ld did not extend verified range!\n", N); return -1; }
759-
maxV = 3*t;
773+
if ( b*t <= a*maxV ) { fprintf (stderr, "Hint at N=%ld did not extend verified range!\n", N); return -1; }
774+
maxV = b*t/a;
760775
}
761776
if ( verbosity >= 0 ) printf ("t(%ld) >= %ld (%.3fs)\n", N, t, get_time()-timer);
762777
if ( maxV >= maxN ) break;
763778
}
764779
if ( minV > minN || maxV < maxN ) { fprintf (stderr, "Hint file only allowed verification [%ld,%ld]\n", minV,maxV); return -1; }
765-
fprintf (stderr,"Verified the Erdős-Guy-Selfridg conjecture for N in [%ld,%ld] (%.3fs)\n",minN,maxN,get_time()-start);
780+
fprintf (stderr,"Verified the %s Erdős-Guy-Selfridg conjecture for N in [%ld,%ld] (%.3fs)\n",rbuf,minN,maxN,get_time()-start);
766781
}
767782
} else {
768783
int64_t N = minN;
769784
if ( t && exhaustive ) { t=0; fprintf(stderr,"Ignoring specified value of t and searching for optimal value\n"); }
770785
if ( !t ) {
771-
t = tbound(N,fast,exhaustive,verbosity,verify);
772-
if ( t ) printf("t(%ld) >= %ld (%s %s) with (t-ceil(N/3)) = %ld (%.3fs)\n", N, t, exhaustive ? "exhaustive" : "heuristic", fast ? "fast" : "greedy",(t-cdiv(N,3)),get_time()-start);
786+
t = tbound(N,a,b,fast,exhaustive,verbosity,verify);
787+
if ( t ) printf("t(%ld) >= %ld (%s %s) with t-%s = %ld (%.3fs)\n", N, t, exhaustive ? "exhaustive" : "heuristic", fast ? "fast" : "greedy",rbuf,t-cdiv(a*N,b),get_time()-start);
773788
else fprintf(stderr,"failed to prove t(%ld) >= %ld (%.3fs)\n", N, cdiv(N,3), get_time()-start);
774789
} else {
775790
int64_t cnt = tfac(N,t,fast,0,verbosity,verify,dumpfile);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
210:61
2+
214:62
3+
218:65
4+
228:67
5+
235:70
6+
246:72
7+
253:74
8+
260:77
9+
270:80
10+
281:84
11+
295:88
12+
309:91
13+
319:93
14+
326:98
15+
344:104
16+
365:110
17+
386:117
18+
410:124
19+
435:133
20+
466:142
21+
498:150
22+
526:160
23+
561:171
24+
599:182
25+
638:197
26+
690:210
27+
736:225
28+
788:243
29+
851:259
30+
907:280
31+
981:301
32+
1054:319
33+
1117:341
34+
1194:374
35+
1310:405
36+
1418:441
37+
1544:486
38+
1702:531
39+
1859:580
40+
2031:644
41+
2255:710
42+
2486:775
43+
2713:860
44+
3011:957
45+
3350:1064
46+
3725:1184
47+
4145:1320
48+
4621:1479
49+
5177:1628
50+
5699:1817
51+
6360:2056
52+
7197:2335
53+
8173:2599
54+
9097:2961
55+
10364:3367
56+
11785:3796
57+
13287:4321
58+
15124:4930
59+
17256:5618
60+
19664:6475
61+
22663:7470
62+
26146:8635
63+
30223:9991
64+
34969:11594
65+
40580:13490
66+
47216:15555
67+
54443:18148
68+
63519:21147

0 commit comments

Comments
 (0)