Download verify_triangle.py from UltranetCommand/t112-triangle-vs-ring: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/datasets/UltranetCommand/t112-triangle-vs-ring/resolve/main/verify_triangle.py
- Command line
-
hf download hf://datasets/UltranetCommand/t112-triangle-vs-ring/verify_triangle.py
-
curl -L -o verify_triangle.py https://huggingface.co/datasets/UltranetCommand/t112-triangle-vs-ring/resolve/main/verify_triangle.py
2.31 kB
| 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") | |