"""Exact check for rmk:non_layered. For beta_1 = 523/131072, every layered permutation w(b) in S_17 has Upsilon_{w(b)}(beta_1) < Upsilon_{u*}(0), where u* is the permutation of Anderson-Panova-Petrov (PNAS version, Thm. 2; Thm. 1.2 in arXiv:2603.20104v1). Layered values use the block factorization (eq:layered_product) with F from the Toda recursion of prop:exact, in exact rational arithmetic. For beta_2 = 75/65536, the largest t = p/2^17 with max_b Upsilon_{w(b)}(t) < Upsilon_{u*}(0) * (2 - (1+t)^82), where 82 = binom(17,2) - inv(u*); this extends the failure to -beta_2 <= beta <= 0. """ from fractions import Fraction as Fr from itertools import product from math import comb M = 17 U_STAR = 3528445515842977489500 LAYERED_MAX_0 = 3050684475186219300000 def narayana(m, x): if m == 0: return Fr(1) return sum(Fr(comb(m, j) * comb(m, j - 1), m) * x ** (j - 1) for j in range(1, m + 1)) def f_table(beta, nmax=M): x = 1 + beta top = 2 * nmax + 2 F = {} for n in range(top + 1): F[0, n] = Fr(1) F[1, n] = narayana(n, x) for k in range(1, nmax): for n in range(top - 2 * k): F[k + 1, n] = (F[k, n] * F[k, n + 2] - F[k, n + 1] ** 2) / (x * F[k - 1, n + 2]) return F def check_proctor(F): for k in range(8): for n in range(1, M + 1 - k): p = Fr(1) for i in range(1, n + 1): for j in range(i + 1, n + 1): p *= Fr(2 * k + i + j - 1, i + j - 1) assert F[k, n] == p, (k, n) def compositions(m): for cuts in product((0, 1), repeat=m - 1): blocks, size = [], 1 for c in cuts: if c: blocks.append(size) size = 1 else: size += 1 blocks.append(size) yield blocks def layered_max(beta): F = f_table(beta) best, arg = None, None for b in compositions(M): val, pre = Fr(1), 0 for blk in b: val *= F[pre, blk] pre += blk if best is None or val > best: best, arg = val, b return best, arg def negative_beta_bound(q=17): """Largest t = p/2^q with layered_max(t) < U_STAR*(2 - (1+t)^A). For such t, no layered permutation maximizes over S_17 at any beta in [-t, 0]: Upsilon_{u*}(-s) >= 2*U_STAR - Upsilon_{u*}(s) >= U_STAR*(2-(1+s)^A) and Upsilon_{w(b)}(-s) <= Upsilon_{w(b)}(t) for 0 <= s <= t. """ u_star = (1, 3, 2, 8, 6, 5, 17, 4, 16, 15, 14, 13, 12, 11, 10, 9, 7) inv = sum(u_star[i] > u_star[j] for i in range(M) for j in range(i + 1, M)) A = comb(M, 2) - inv def holds(p): t = Fr(p, 2 ** q) return layered_max(t)[0] < U_STAR * (2 - (1 + t) ** A) lo, hi = 0, 1 while holds(hi): lo, hi = hi, 2 * hi while hi - lo > 1: mid = (lo + hi) // 2 lo, hi = (mid, hi) if holds(mid) else (lo, mid) t = Fr(lo, 2 ** q) return inv, A, t, layered_max(t)[0], U_STAR * (2 - (1 + t) ** A) if __name__ == "__main__": check_proctor(f_table(Fr(0))) v0, b0 = layered_max(Fr(0)) print("beta=0: layered max", v0, "at blocks", b0, "matches APP:", v0 == LAYERED_MAX_0) beta1 = Fr(523, 131072) v1, b1 = layered_max(beta1) print("beta=%s: layered max < Upsilon_u*(0): %s (ratio %.8f, blocks %s)" % (beta1, v1 < U_STAR, float(v1 / U_STAR), b1)) inv, A, t, lhs, rhs = negative_beta_bound() print("inv(u*)=%d, A=%d, t=%s: layered max(t) = %s < %s = U*(2-(1+t)^A) (ratio %.8f)" % (inv, A, t, float(lhs), float(rhs), float(lhs / rhs)))