"""Bounded counterchecks for return27. No large sieve or random simulation.""" from fractions import Fraction as F from decimal import Decimal as D, localcontext from itertools import product from math import gcd, exp, prod def tile(w): return [i for i in range(w) if gcd(i*(i+2),w)==1] def gaps(s,w): return [s[(i+1)%len(s)]+(w if i==len(s)-1 else 0)-v for i,v in enumerate(s)] old,new=gaps(tile(30),30),gaps(tile(210),210) m,n=F(sum(old),len(old)),F(sum(new),len(new)) a,b=F(sum(v*v for v in old),2*len(old)),F(sum(v*v for v in new),2*len(new)) slope=(5*b-7*a)/n-2*m assert slope == -F(20,7) print('T5 -> T7: c_min(lambda)=2-(20/7)*lambda+O(lambda^2).') with localcontext() as ctx: ctx.prec=60 for t in ['0.0001','0.00001','0.000001']: lam=D(t) phi=sum((lam*v).exp() for v in old)/len(old) pn=sum((lam*v).exp() for v in new)/len(new) c=7*(pn-phi)/(phi*(pn-1)) print('lambda='+t+', (2-c_min)/lambda='+format((2-c)/lam,'.9f')) # Theorem3's first fixed-lambda conclusion holds, but its claimed stronger # exponent with the same C is false on the very first fold. lam=.001; alpha=5/3; w=exp(6*lam) C=w/(alpha-(alpha-1)*w) phi5=sum(exp(lam*v) for v in old)/len(old) assert w<5/2 and phi5<=C and w<1/(1-1/alpha) actual=1.0; claimed=C*exp(-6/10) assert actual>claimed print(f'Theorem3 counterexample: x5,c_prime2,lambda.001,theta6: hypotheses hold; P=1 > claimed {claimed:.9f}.') print('Repair: keep exponent lambda*mbar, or assume domination at lambda=1/(6*alpha_prime).') # The rate used in the paper is geometric gaps followed by CRT scoring. p=7; alpha=F(5,3);rho=1-1/alpha hybrid=(2*rho**(p-1)+rho**1+rho**4)/(2*alpha*(1-rho**p)) iid=F(2,p) assert hybrid != iid print(f'Fold7 hybrid CRT-scored geometric rate={float(hybrid):.9f}; independent-deletion E[X]/E[kills]={float(iid):.9f}.') # A singleton deletion consumes outer gaps below the qualifying threshold. s=[v+30*k for k in range(7) for v in tile(30)] dead=[v%7 in (0,5) for v in s] witness=None for i,v in enumerate(s): if dead[i] and not dead[(i-1)%len(s)] and not dead[(i+1)%len(s)]: h0=(v-s[(i-1)%len(s)])%210;h1=(s[(i+1)%len(s)]-v)%210 if min(h0,h1)<12:witness=(v,h0,h1);break assert witness print(f'Singleton kill at {witness[0]} consumes outer gaps {witness[1:]}, including one below theta7=12.') # Finite window means are not the infinite periodic density. rows=[] for anchor in range(0,210,6): ss=[v for v in range(anchor,anchor+60) if gcd(v*(v+2),210)==1] if len(ss)>1:rows.append((anchor,len(ss),F(ss[-1]-ss[0],len(ss)-1),F(60,len(ss)))) r0=rows[0];r1=next(r for r in rows if r[1]!=r0[1] and r[2]!=r0[2]) print('T7 windows length60: (anchor,N,mean interior gap,Y/N)=',r0,r1) assert r0[2]!=r1[2] and r0[3]!=r1[3] # A fixed-window maximum has bounded support; an iid geometric sample does not. # Bernoulli(1/2) survivors on four sites 0,6,12,18: every internal gap <24. for mask in product([0,1],repeat=4): ss=[6*i for i in range(4) if mask[i]] assert all(b-a<24 for a,b in zip(ss,ss[1:])) print('Four-site Bernoulli window: P(internal max>=24)=0; geometric gap with alpha2 gives1/8.') # Same exponential-moment sign does not determine every threshold correlation. # Abstract word, not a primorial tile; lambda=log(2)/6 gives weights 2^k. word=[3,1,2,1,3];v=[2**k for k in word];N=len(v) cov=F(sum(v[i]*v[(i+1)%N] for i in range(N)),N)-F(sum(v),N)**2 tailcov=F(1,5)-F(2,5)**2 assert cov==-F(16,25) and tailcov==F(1,25) print('Abstract gaps[18,6,12,6,18]: exponential covariance=-16/25, threshold18 covariance=+1/25.') # The source's fifth-window totals force at least one length3 run at p>=100. assert 70>69 print('Captured fifth-window S1=70>N2=69 forces a run of length>=3 in the scored range.') # A shared offset does not force its reconstruction from every outside event. b3=F(0) for target,other in [(0,1),(1,0)]: for observed in [False,True]: cell=[u for u in range(5) if (u==other)==observed] conditional=F(sum(u==target for u in cell),len(cell)) b3+=F(len(cell),5)*abs(conditional-F(1,5)) ceiling=2*sum(F(1,5)*(1-F(1,5)) for _ in range(2)) assert b3==F(4,25) and ceiling==F(16,25) print('Shared uniform Z5, singleton events 0 and 1: b3=4/25 < ceiling16/25.') print('All assertions PASS. Tiny exact examples; no large recipe replay.')