File size: 2,306 Bytes
631ca3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import hashlib, math, numpy as np
from collections import defaultdict
from t112_triangle import *

def wl_bits(lut):
    adj=defaultdict(set)
    for v in range(N):
        for u in lut[v]:
            if u!=SENTINEL: adj[v].add(int(u)); adj[int(u)].add(v)
    col={v:0 for v in range(N)}
    for _ in range(40):
        new={v:(col[v],tuple(sorted(col[u] for u in adj[v]))) for v in range(N)}
        m={s:i for i,s in enumerate(sorted(set(new.values()),key=lambda x:hashlib.md5(str(x).encode()).hexdigest()))}
        nc={v:m[new[v]] for v in range(N)}
        if len(set(nc.values()))==len(set(col.values())): col=nc; break
        col=nc
    sz=defaultdict(int)
    for v in col: sz[col[v]]+=1
    return len(sz), -sum((c/N)*math.log2(c/N) for c in sz.values())

def connected(lut):
    seen=np.zeros(N,bool); st=[0]; seen[0]=True; c=1
    while st:
        v=st.pop()
        for u in lut[v]:
            if u!=SENTINEL and not seen[u]: seen[u]=True; c+=1; st.append(int(u))
    return c

lut,idx=build_triangle_lut()
print("[+] layout        ", LUT_BYTES, "B uint16, <=256 KiB:", LUT_BYTES<=262144)
print("[+] cells         ", N, "= T112")
print("[+] degrees       ", degree_hist(lut), " (NOT uniform - this is the point)")
print("[+] connected     ", f"{connected(lut)}/{N}", connected(lut)==N)
print("[+] symmetric     ", all(v in [int(x) for x in lut[int(u)] if x!=SENTINEL]
                               for v in range(N) for u in lut[v] if u!=SENTINEL))

k,H = wl_bits(lut)
print(f"[+] WL classes    {k}   node identity = {H:.2f} bits   (ring baseline: 1 class, 0.00 bits)")

node,acc = hop_loop(lut, 50_000, 7)
golden = hashlib.sha256(f"{node}:{acc}".encode()).hexdigest()
print(f"[+] golden        node={node} acc={acc}")
print(f"[+] sha256        {golden}")

# determinism across repeats & a second construction
lut2,_ = build_triangle_lut()
n2,a2 = hop_loop(lut2, 50_000, 7)
print("[+] reproducible  ", (n2,a2)==(node,acc))

# fail-closed: structural halt vs range halt
hops,err = hop_loop_failclosed(lut, 10_000, 7)
print(f"[+] structural halt at hop {hops} err={err}  (2 = fell off the triangle edge)")
for p in (6328, 65535, 99999):
    h,e = hop_loop_failclosed(lut, 10_000, 7, poison_at=3, poison_val=p)
    assert e==1, p
print("[+] range halt    6328/65535/99999 -> err=1 at hop 3")