from math import prod,gcd def primes(x):return [p for p in range(2,x+1) if all(p%d for d in range(2,int(p**.5)+1))] def gaps(s,w):return [s[(i+1)%len(s)]-a+(w if i==len(s)-1 else 0) for i,a in enumerate(s)] def twin(x): w=prod(primes(x));s=[r for r in range(w) if gcd(r*(r+2),w)==1] return w,gaps(s,w) def canon(g):return min(tuple(g[i:]+g[:i]) for i in range(len(g))) def fold_word(g,q): w=sum(g);s=[0] for v in g[:-1]:s.append(s[-1]+v) keep=[a+k*w for k in range(q) for a in s if (a+k*w)%q not in (0,q-2)] return gaps(keep,q*w) print('Exact word-level iteration, with arbitrary origin reset at every step:') w,word=twin(5) for q in [7,11,13]: word=fold_word(word,q);w*=q true_w,true_g=twin(q) assert w==true_w and canon(word)==canon(true_g) print(f'fold{q}: D={len(word)}, G2={max(word)}, entire cyclic gap word matches direct tile') # The published loose-certificate example changes a general-threshold # implication, but is not a counterexample at theta=q^2. G=258;Mloose=270;q=29 for theta in [264,q*q]: A=G=theta is {B}') if theta==264:assert A and not B else:assert A and B assert all(not(Mloose=theta) => G2{b}, factor q-1=4, not q-2=3.') # The class-minimum inequality gives an upper bound on run length for a # fixed span. It cannot require a long interior in a large outer window. q=7;outer=[24,30] assert sum(outer)>=q*q print('Abstract legal-interior window only: outer gaps24,30 at q7 sum54>=q^2; L1, empty interior. No long qualifying run is forced by the span alone.') print('All assertions PASS; only tiny tiles and exact integer arithmetic.')