#!/usr/bin/env python3 """Local Perturbation Lemma: exact check on the Sebo-Long ten-barrier example. Holds all 10 marginals and all 45 pairwise distributions fixed; moves the conjunction across the 0.1% threshold in both directions. Exact fractions, all 1,024 states. Tony T. Nguyen, Highland Reflexive Press, 2026. Released under the MIT License (see LICENSE.txt).""" from fractions import Fraction as Fr from itertools import product, combinations q = [Fr(s) for s in "0.20 0.93 0.93 0.51 0.51 0.51 0.51 0.44 0.625 0.325".split()] tau, F, ONES = Fr(1, 1000), (0, 7, 9), (1,) * 10 # F = barriers 1, 8, 10 states = list(product((0, 1), repeat=10)) def P0(x): # independent law m = Fr(1) for xi, qi in zip(x, q): m *= qi if xi else 1 - qi return m def s(x): # parity correction on the cube C if any(x[i] == 0 for i in range(10) if i not in F): return 0 return -1 if sum(x[i] for i in F) % 2 else 1 def law(t): return {x: P0(x) + t * s(x) for x in states} def pairs(L): return [sum(m for x, m in L.items() if x[i] == a and x[j] == b) for i, j in combinations(range(10), 2) for a in (0, 1) for b in (0, 1)] base = law(0) p0 = base[ONES] for name, t in (("independent", 0), ("down", p0 / 20), ("up", -p0 / 20)): L = law(t) assert all(m >= 0 for m in L.values()) and sum(L.values()) == 1 assert pairs(L) == pairs(base) # all 45 pairs (hence all marginals) unchanged side = "above" if L[ONES] > tau else "below" print(f"{name:12s} P(all ten) = {float(L[ONES]) * 100:.7f}% ({side} 0.1%)") print("All 10 marginals and all 45 pairwise distributions identical across the three laws.")