"""Law-9 audit of THE THREE-HALVES ECHO — independent Python reproduction. Different language, different code, same definitions (read from the C++ instrument and from THE SIBLING SIGN's lineage): fine_r(k): Pearson r of x_j = 2*A[2^k + j] - (2^k + j) vs y_j = 2*A[2^(k-1) + j] - (2^(k-1) + j), j in [0, 2^(k-1)). env_r(k): 64-bin mean-|2A[n]-n| profiles of block [2^k, 3*2^(k-1)) vs block [2^(k-1), 2^k), each z-normalized (population sd), dot/64. Targets: published fine/env k=22 (old lamp) and NEW fine/env k=27. Needs A up to 3*2^26 - 1 = 201,326,591; clock gate at 2^27 included. """ import sys, time from array import array import numpy as np K = 27 N = 3 * (1 << (K - 1)) # 201,326,592 — covers fine/env at k=27 A = array('I', bytes(4 * (N + 1))) A[1] = A[2] = 1 t0 = time.time() BENCH = 10_000_000 a = A # local alias for n in range(3, BENCH): p = a[n - 1] a[n] = a[p] + a[n - p] rate = (BENCH - 3) / (time.time() - t0) eta = (N + 1 - BENCH) / rate print(f"[meter] {rate/1e6:.2f}M steps/s; remaining ~{eta/60:.1f} min for {N:,}", flush=True) for n in range(BENCH, N + 1): p = a[n - 1] a[n] = a[p] + a[n - p] print(f"[meter] recurrence done in {(time.time()-t0)/60:.1f} min total", flush=True) # gates: range (sampled full-strength via vector check) + exact clock V = np.frombuffer(A, dtype=np.uint32) idx = np.arange(1, N + 1, dtype=np.int64) if not ((V[1:N+1] >= 1).all() and (V[1:N+1] <= idx).all()): sys.exit("range breach") for k in range(1, K + 1): if A[1 << k] != 1 << (k - 1): sys.exit(f"clock breach k={k}") print("[audit] range + clock gates PASSED", flush=True) def fine_r(k): half = 1 << (k - 1) x0, y0 = 1 << k, half x = 2.0 * V[x0:x0+half] - np.arange(x0, x0 + half, dtype=np.float64) y = 2.0 * V[y0:y0+half] - np.arange(y0, y0 + half, dtype=np.float64) x -= x.mean(); y -= y.mean() return float((x @ y) / np.sqrt((x @ x) * (y @ y))) def env_profile(lo, hi, bins=64): E = np.abs(2.0 * V[lo:hi] - np.arange(lo, hi, dtype=np.float64)) p = E.reshape(bins, -1).mean(axis=1) return (p - p.mean()) / p.std() def env_r(k): lo = 1 << k x = env_profile(lo, lo + (1 << (k - 1))) y = env_profile(1 << (k - 1), 1 << k) return float((x @ y) / 64) for k, fw, ew in ((22, 0.29829476, 0.29812658), (27, 0.30136301, 0.30119130)): f, e = fine_r(k), env_r(k) tag = "OLD-LAMP" if k == 22 else "NEW-RUNG" ok = abs(f - fw) < 5e-9 and abs(e - ew) < 5e-9 print(f"[{tag}] k={k} fine={f:+.8f} (want {fw:+.8f}) env={e:+.8f} (want {ew:+.8f}) " + ("MATCH all 8 decimals" if ok else "MISMATCH"), flush=True) if not ok: sys.exit(9) print("[audit] independent reproduction PASSED — old lamp k=22 and new rung k=27, both grains")