#!/usr/bin/env python3 # ============================================================================ # QUESTION (job #1527, lane `formalize`, stage `discover`, no route). # # The retained census `research/kernel-sign-control.md` (MEASURED, negative) # decided its sign question with a fitted slope of log2(|X_small(actual)| / # |X_small(random)|) over six dyadic scales per family, plus a post-hoc # descriptive aggregate (TABLE 4): mean rank 5.15 of the actual among itself # and its 8 same-support seeded draws; 12 of 27 configurations below the draw # median. Its own limitations section calls the reading weak and names the fix # ("more draws (say 64) rather than more x-scales") but never computes whether # that fix decides anything, and nothing pre-registered the kernel-share floor # below which such a measurement is inadmissible rather than negative. # # ANSWERED HERE, exactly and offline, from the published per-row values: # Q1 the EXACT null and exact p-value of the pooled blocked-rank statistic W # (W = total wins of the actual value over its 8 same-support controls, # over b = 27 nonempty configurations); no fitted slope, no normal # approximation, no Jensen-diluted ratio. # Q2 the EXACT power of that test as a function of (blocks b, draws k), i.e. # whether the retained note's own "64 draws" fix makes it decidable. # Q3 the admissibility floor s_star that must be pre-registered. # # PRE-REGISTERED FALSIFIER, fixed before this script ran (F1-F5): # F1 calibration: the exact integer DP null must match a 200 000-sample Monte # Carlo of the same null with max CDF gap <= 3e-3, else the statistic is # REJECTED and no verdict may be read. # F2 retained reading: if exact one-sided p(W<=104) >= 0.05, the retained # census's failure to detect is CONFIRMED as a genuinely null pooled # reading; if < 0.05, the retained slope rule was under-powered relative to # the pooled statistic (a defect of the retained test, not new evidence). # F3 power gate: the statistic may be used on new data ONLY with a (b,k) # whose exact power at q=0.60 is >= 0.80, q = P(actual beats one control # draw). A design below the gate is uninformative by construction. # F4 admissibility floor (the rule the retained census lacked): pre-register # s_star = 0.05 percent kernel share; if every reachable configuration has # X_small/Mfrak < s_star the run reports INADMISSIBLE, never a negative. # F5 known-answer control: a simulated injected effect q on a fixture must be # recovered by the exact power within Monte-Carlo error. # # NO twin-prime claim, no asymptotic rate. Inputs are the published values in # `research/kernel-sign-control.json` (raw reply read this run, attached) and # TABLE 2 of `research/kernel-sign-control.md` (ranks, published). # ============================================================================ import json, math, random ART = "work/job1527/replies/kernel-sign-control.json" raw = json.load(open(ART)) rows = [] for r in raw["table"]: var = {v["name"]: v for v in r["variants"]} if "A1" not in var: continue if r["j"] == 18 and r["box"] == "top" and r["g"] == 1: # CLASS EMPTY (TABLE 2) continue if r.get("smallPairs", 1) == 0: continue rows.append(r) b, k = len(rows), 8 wins = [sum(1 for i in range(1, 9) if abs({v["name"]: v for v in r["variants"]}[f"rnd{i}"]["Xsmall"]) < abs({v["name"]: v for v in r["variants"]}["A1"]["Xsmall"])) for r in rows] W = sum(wins) ranks = [r["rank"] for r in rows] out = {"blocks_b": b, "draws_k": k, "W_wins": W, "block_wins": wins, "published_ranks": ranks, "published_rank_sum": sum(ranks), "published_mean_rank": sum(ranks) / b, "recomputed_mean_rank": (b * k - sum(wins)) / b, "published_mean_rank_table4": 5.15} # ---- F1 / Q1: exact integer DP null of W, and its p-values dist = {0: 1} for _ in range(b): nxt = {} for s, c in dist.items(): for w in range(k + 1): nxt[s + w] = nxt.get(s + w, 0) + c dist = nxt tot = sum(dist.values()) assert tot == (k + 1) ** b p_le = sum(c for s, c in dist.items() if s <= W) / tot p_ge = sum(c for s, c in dist.items() if s >= W) / tot out["exact_null"] = {"mean": b * k / 2, "sd": math.sqrt(b * k * (k + 2) / 12), "p_W_le_observed": p_le, "p_W_ge_observed": p_ge, "two_sided": 2 * min(p_le, p_ge)} print(f"blocks b={b} draws k={k} W={W} of {b*k}") print(f"published ranks sum={sum(ranks)} -> mean {sum(ranks)/b:.6f}; recomputed {out['recomputed_mean_rank']:.6f} (TABLE 4 says 5.15)") print(f"exact null: mean {b*k/2:.4f} sd {out['exact_null']['sd']:.4f}; exact p(W<={W})={p_le:.4f} p(W>={W})={p_ge:.4f}") rnd = random.Random(1527) M = 200000 sim = {} for _ in range(M): w = sum(rnd.randrange(k + 1) for _ in range(b)) sim[w] = sim.get(w, 0) + 1 run, cdfs, gap = 0.0, {}, 0.0 exact_cdf, run2 = {}, 0 for w in sorted(dist): run2 += dist[w]; exact_cdf[w] = run2 / tot for w in sorted(sim): run += sim[w]; cdfs[w] = run / M if w in exact_cdf: gap = max(gap, abs(exact_cdf[w] - cdfs[w])) out["F1_calibration"] = {"samples": M, "max_cdf_gap": gap, "gate": 3e-3, "ok": gap <= 3e-3} print(f"F1 calibration: max CDF gap {gap:.5f} (gate 3e-3) -> {'OK' if gap <= 3e-3 else 'REJECT'}") out["F2_retained"] = {"p_exact_one_sided": p_le, "confirmed_null": bool(p_le >= 0.05), "rank_mean_matches_published": abs(sum(ranks) / b - 5.15) < 0.005} print(f"F2 retained: exact one-sided p={p_le:.4f} -> " + ("retained negative CONFIRMED genuinely null" if p_le >= 0.05 else "retained slope rule under-powered")) # ---- Q2: exact power (float DP) of the one-sided alpha test at b,k def null_dp(b, k): dist = {0: 1.0} for _ in range(b): nxt = {} for s, c in dist.items(): for w in range(k + 1): nxt[s + w] = nxt.get(s + w, 0.0) + c dist = nxt return dist def crit(dist, alpha=0.05): tot = sum(dist.values()) tail = 0.0 for w in sorted(dist, reverse=True): tail += dist[w] / tot if tail > alpha: return w + 1 return min(dist) def power(b, k, q, alpha=0.05): d = null_dp(b, k); t = crit(d, alpha) bw = [math.comb(k, i) * q ** i * (1 - q) ** (k - i) for i in range(k + 1)] acc = {0: 1.0} for _ in range(b): nxt = {} for s, p in acc.items(): for i in range(k + 1): nxt[s + i] = nxt.get(s + i, 0.0) + p * bw[i] acc = nxt return sum(p for s, p in acc.items() if s >= t), t tbl = [] for kk in (8, 16, 32, 64): row = {"k": kk} for q in (0.55, 0.60, 0.65, 0.70): pw, t = power(b, kk, q) row[f"power_q{int(q*100)}"] = round(pw, 4) row["crit"] = t tbl.append(row) out["power_table_b27"] = tbl print("exact power at alpha=0.05, b=27 blocks:") print(" k crit q=.55 q=.60 q=.65 q=.70") for r in tbl: print(f" {r['k']:3d} {r['crit']:4d} " + " ".join(f"{r[f'power_q{int(q*100)}']:.3f}" for q in (0.55, 0.60, 0.65, 0.70))) sizes = [] for kk in (8, 64): row = {"k": kk} for bb in (27, 50, 100, 200, 500): pw, t = power(bb, kk, 0.60) row[f"b{bb}"] = round(pw, 4) sizes.append(row) out["power_vs_blocks_q60"] = sizes print("exact power at q=0.60 vs block count:") for r in sizes: print(f" k={r['k']:3d} " + " ".join(f"b={bb}: {r[f'b{bb}']:.3f}" for bb in (27, 50, 100, 200, 500))) # minimal b for 80% power at q=0.60, scanned coarsely then refined def min_b(kk, q=0.60, target=0.80): bb = 10 while bb <= 400: pw, _ = power(bb, kk, q) if pw >= target: return bb bb += 5 if bb < 100 else 25 return None out["F3_min_blocks_80pct_q60"] = {f"k{kk}": min_b(kk) for kk in (8, 64)} print("minimal b for 80% power at q=0.60: " + str(out["F3_min_blocks_80pct_q60"])) # ---- F5 known-answer qa = [] for q in (0.55, 0.60, 0.65): pw, t = power(b, 64, q) r = random.Random(99); hits = 0 for _ in range(20000): if sum(sum(1 for _ in range(64) if r.random() < q) for _ in range(b)) >= t: hits += 1 qa.append({"q": q, "exact_power_b27_k64": round(pw, 4), "mc_rejection_rate": hits / 20000}) out["F5_known_answer"] = qa print("F5 known-answer (b=27,k=64): " + ", ".join(f"q={x['q']}: exact {x['exact_power_b27_k64']} vs mc {x['mc_rejection_rate']:.3f}" for x in qa)) # ---- Q3 kernel share and the floor shares = [abs({v["name"]: v for v in r["variants"]}["A1"]["Xsmall"]) / abs({v["name"]: v for v in r["variants"]}["A1"]["Mfrak"]) for r in raw["table"] if abs({v["name"]: v for v in r["variants"]}["A1"]["Mfrak"]) > 0] shares.sort() out["kernel_share_percent"] = {"n": len(shares), "min": shares[0] * 100, "median": shares[len(shares)//2] * 100, "max": shares[-1] * 100} pow60_retained = [r for r in tbl if r["k"] == 8][0]["power_q60"] out["F4_floor"] = {"s_star_percent": 0.05, "power_at_q60_retained_design": pow60_retained, "rule": "pre-register s_star=0.05 percent and the power gate; if every reachable configuration has kernel share < s_star, report INADMISSIBLE, never a negative"} print(f"kernel share over {len(shares)} rows: {shares[0]*100:.2f}% .. {shares[-1]*100:.2f}% (median {shares[len(shares)//2]*100:.2f}%)") print(f"power at q=0.60 for the retained design (b=27,k=8): {pow60_retained:.3f} -> the retained design " + ("PASSES" if pow60_retained >= 0.80 else "FAILS") + " the pre-registered power gate") ALL = (out["F1_calibration"]["ok"] and out["F2_retained"]["rank_mean_matches_published"] and all(abs(x["exact_power_b27_k64"] - x["mc_rejection_rate"]) < 0.02 for x in qa)) out["ALL_CHECKS_PASS"] = bool(ALL) json.dump(out, open("work/job1527-sign-test.json", "w"), indent=1) print("ALL CHECKS PASS" if ALL else "CHECKS FAILED")