|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Boundary-exit potential share in #4436's direct p7 flow (evidence for a conditional reduction). |
| 3 | +
|
| 4 | +Using an independent implementation of #4436's partially matched flow (the same as research/pr4436-direct-flow-check), |
| 5 | +for every rank 121 <= N <= 3000 and a 1%-geometric grid up to 5*10^5 this computes |
| 6 | + beta(N) = sum over boundary exits x_e e^t / sum over sources w_s s^t, t = 1 - 0.0026865, |
| 7 | +and checks: every exit is at most r_max N / m (r_max = 48, m = 121), every leaf exit is at most r_max^(G+1), the |
| 8 | +exact rank-one potential identity holds, and max beta < 0.16 (observed 0.1545). Floating-point shares are |
| 9 | +numerical evidence for the README's conditional lemma, not a proof of a uniform bound. |
| 10 | +Ryanson Jonathan with Claude Code (Claude Opus 5.5) assistance. Apache-2.0. |
| 11 | +""" |
| 12 | +import json |
| 13 | +import sys |
| 14 | + |
| 15 | +from fractions import Fraction as Q |
| 16 | +from math import factorial |
| 17 | +def multis(n_types, size): |
| 18 | + if n_types == 0: |
| 19 | + if size == 0: yield () |
| 20 | + return |
| 21 | + for x in range(size + 1): |
| 22 | + for rest in multis(n_types - 1, size - x): yield (x,) + rest |
| 23 | +def flow(N, W, P): |
| 24 | + ks = sorted(W); m = ks[-1]; kmin = ks[0] |
| 25 | + def c(a): |
| 26 | + v = 1 |
| 27 | + for k, x in zip(ks, a): v *= k ** x |
| 28 | + return v |
| 29 | + def u(a): |
| 30 | + v = factorial(sum(a)) |
| 31 | + for k, x in zip(ks, a): v = v // factorial(x) * W[k] ** x |
| 32 | + return v |
| 33 | + G = 0 |
| 34 | + while kmin ** (G + 1) <= N // m: G += 1 |
| 35 | + F = [{1: 1}] |
| 36 | + for d in range(1, G + 1): |
| 37 | + nxt = {} |
| 38 | + for rho, cnt in F[d - 1].items(): |
| 39 | + for r, pr in P.items(): |
| 40 | + if m * rho * r <= N: nxt[rho * r] = nxt.get(rho * r, 0) + cnt * pr |
| 41 | + F.append(nxt) |
| 42 | + S, X, BX = {}, {}, {} |
| 43 | + col = units = matched = 0 |
| 44 | + add = lambda D, k, v: D.__setitem__(k, D.get(k, 0) + v) |
| 45 | + present = lambda rho, a: m * rho * c(a) <= N |
| 46 | + for d in range(G + 1): |
| 47 | + for rho, cnt in F[d].items(): |
| 48 | + for b in multis(len(ks), G - d): |
| 49 | + if not present(rho, b): continue |
| 50 | + units += cnt * u(b); col += cnt * u(b) * rho * c(b) |
| 51 | + for r, pr in P.items(): |
| 52 | + issued = cnt * pr * u(b); rank = r * rho * c(b) |
| 53 | + if d == G: |
| 54 | + add(X, rank, issued); continue |
| 55 | + D = sum(W[k] * u(tuple(x - (i == j) for j, x in enumerate(b))) |
| 56 | + for i, k in enumerate(ks) if b[i] > 0 and present(rho * r, tuple(x - (i == j) for j, x in enumerate(b)))) |
| 57 | + matched += cnt * pr * D |
| 58 | + if issued - cnt * pr * D: |
| 59 | + add(X, rank, issued - cnt * pr * D); add(BX, rank, issued - cnt * pr * D) |
| 60 | + for a in multis(len(ks), G): |
| 61 | + if present(1, a): |
| 62 | + for k in ks: add(S, k * c(a), W[k] * u(a)) |
| 63 | + for d in range(1, G + 1): |
| 64 | + for rho, cnt in F[d - 1].items(): |
| 65 | + for r, pr in P.items(): |
| 66 | + for a in multis(len(ks), G - d): |
| 67 | + if not present(rho * r, a): continue |
| 68 | + for i, k in enumerate(ks): |
| 69 | + b = list(a); b[i] += 1 |
| 70 | + if not present(rho, tuple(b)): |
| 71 | + add(S, rho * r * c(tuple(b)), cnt * pr * u(a) * W[k]) |
| 72 | + return dict(G=G, S=S, X=X, BX=BX, col=col, units=units, matched=matched) |
| 73 | + |
| 74 | + |
| 75 | +def need(condition, message): |
| 76 | + if not condition: |
| 77 | + raise AssertionError(message) |
| 78 | + |
| 79 | + |
| 80 | +def main(): |
| 81 | + W = {5: 420, 6: 270, 7: 840, 8: 1395, 9: 3195, 25: 448, 41: 448, 57: 448, 121: 224} |
| 82 | + P = {1: 37305, 2: 10695, 3: 3360, 4: 1530, 5: 300, 8: 1464, 16: 448, 32: 448, 48: 448} |
| 83 | + m, rmax, surplus = 121, 48, 608 |
| 84 | + t = 1 - 0.0026865 |
| 85 | + Ns = sorted(set(list(range(121, 3001)) + [int(121 * 1.01 ** k) for k in range(0, 850)])) |
| 86 | + Ns = [n for n in Ns if n <= 500000] |
| 87 | + best, at = 0.0, None |
| 88 | + for N in Ns: |
| 89 | + r = flow(N, W, P) |
| 90 | + need(all(e * m <= rmax * N for e in r["X"]), f"N={N}: exits <= r_max N/m") |
| 91 | + need(all(e <= rmax ** (r["G"] + 1) or e in r["BX"] for e in r["X"]), f"N={N}: leaf exits <= r_max^(G+1)") |
| 92 | + need(sum(s * v for s, v in r["S"].items()) - sum(e * v for e, v in r["X"].items()) == surplus * r["col"], |
| 93 | + f"N={N}: potential identity") |
| 94 | + st = sum(v * s ** t for s, v in r["S"].items()) |
| 95 | + bt = sum(v * e ** t for e, v in r["BX"].items()) |
| 96 | + if bt / st > best: |
| 97 | + best, at = bt / st, N |
| 98 | + need(best < 0.16, "max boundary share below 0.16") |
| 99 | + print(json.dumps({"status": "PASS_DIRECT_FLOW_BOUNDARY_SHARE", "ranks_scanned": len(Ns), "max_N": Ns[-1], |
| 100 | + "max_boundary_share": round(best, 6), "at_N": at, "eta_reference": 0.984, |
| 101 | + "new_kappa_claimed": False}, indent=1)) |
| 102 | + |
| 103 | + |
| 104 | +if __name__ == "__main__": |
| 105 | + sys.exit(main()) |
0 commit comments