#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Route 39, part C: does the open window close WITHOUT the parity deduction? Proposition 5 of `fold-arithmetic-bridge.md` section 4a bounds, for every u > 4 and F_2 >= 1, c*_real(u) <= f_1(u/2)^2 (1 + 1/D_3(u)), D_3(u) = int_2^(u-1) log(v-1)/v dv, and on a piece (u_0, u_1] it replaces f_1(u/2)^2 by f_1(u_1/2)^2 and D_3(u) by a LOWER bound at u_0. Its own certificate uses the directed bound e^gamma < 9/5 and, for D_3, cell minima justified by the unimodality of log(v-1)/v (the cell [2,3] is discarded because its minimum is 0 at v = 2). The published upward-rounded table is reproduced here first (that is the integrity gate), and then the same method is run on a finer partition. Two exactness rules followed: * e^gamma is used as the RATIONAL UPPER BOUND 9/5 wherever a *certified upper bound* is produced, exactly as the certificate does; the true e^gamma is used only to evaluate the true D_3, which is a lower-bound input either way. * D_3 is given both as its true value (Simpson, cross-checked against (log(u-2))^2/2 - int_1^(u-2) log z/(z(z+1)) dz to 1e-12) and as a rigorous cell-minimum lower bound, which is what a certificate may use. """ import json import math import sys from fractions import Fraction as F sys.stdout.reconfigure(encoding='utf-8') EG_CERT = F(9, 5) # certified upper bound for e^gamma EG_TRUE = math.exp(0.577215664901532860606512090082402431) CELLMIN = [((2, 3), 0.0)] # [2,3] discarded: its minimum is 0 at v = 2 def f1_sq_cert(u_half, tail=False): """f_1(s)^2 as the certificate uses it: min(1, 2(9/5)log(s-1)/s) on a finite piece, 1 on the tail. Note that the formula is evaluated at s = 4 as well (it gives 0.98875 there), which is how the published (6,8] entry is obtained.""" if tail: return 1.0 s = max(u_half, 2.0) return min(1.0, 2.0 * float(EG_CERT) * math.log(s - 1) / s) ** 2 def f1_sq_true(u_half): if u_half >= 4: return 1.0 s = max(u_half, 2.0) return (2.0 * EG_TRUE * math.log(s - 1) / s) ** 2 def g(v): return math.log(v - 1) / v PI2 = 9.869604401089358 # pi^2 to 15 digits; used as a LOWER bound where noted def li2_neg_bounds(A, K=200): """Rigorous brackets for Li_2(-A) with A > 1, by the inversion formula Li_2(-A) = -pi^2/6 - (1/2) log(A)^2 - Li_2(-1/A), whose remaining series is alternating with terms 1/(A^k k^2). Returns (lo, hi).""" s = 0.0 sign = -1.0 for k in range(1, K + 1): term = sign / (A ** k * k * k) s += term sign = -sign tail = 1.0 / (A ** (K + 1) * (K + 1) ** 2) lo_part = s - tail if sign < 0 else s # next term has the opposite sign of the last hi_part = s + tail if sign < 0 else s base = -PI2 / 6.0 - 0.5 * math.log(A) ** 2 # Li_2(-A) = base - Li_2(-1/A): the subtraction, not an addition (checked against Simpson in # main(); the first version of this function had the sign wrong and the identity test caught it). li2_lo = base - max(lo_part, hi_part) li2_hi = base - min(lo_part, hi_part) return li2_lo, li2_hi def d3_closed(u, which="true"): """EXACT closed form: D_3(u) = log(u-2) log(u-1) + pi^2/12 + Li_2(-(u-2)). Derivation: z = v-1 gives int_1^(u-2) log z/(z+1) dz, and d/dz[log z log(z+1) + Li_2(-z)] = log z/(z+1), with Li_2(-1) = -pi^2/12. The identity is checked against Simpson in main(). """ A = u - 2.0 if A <= 1: return 0.0 lo2, hi2 = li2_neg_bounds(A) base = math.log(A) * math.log(A + 1) + PI2 / 12.0 if which == "lo": return base + lo2 if which == "hi": return base + hi2 return base + 0.5 * sum(li2_neg_bounds(A)) def d3_formula_lower(u0): """The certificate's other device, for the first four pieces: D_3(u_0) >= ((u_0-2) log(u_0-2) - (u_0-3))/(u_0-1), from 1/v >= 1/(u_0-1) on the range.""" if u0 <= 3: return 0.0 return ((u0 - 2) * math.log(u0 - 2) - (u0 - 3)) / (u0 - 1) def cell_min_lower(u0): """Rigorous lower bound for D_3(u0) = int_2^(u0-1) g, using unimodal cell minima. g is unimodal on [2, inf) (it rises to its maximum at v = e+1 approx and falls after), so on any cell the minimum of its endpoint values times the cell length is a lower bound for the cell's integral. Cell [2,3] is discarded exactly as the certificate discards it. """ acc = 0.0 for a in range(3, int(math.floor(u0 - 1)) + 1): b = min(a + 1, u0 - 1) if b <= a: break acc += min(g(a), g(b)) * (b - a) return acc def d3_true(u): n = 40000 a, b = 2.0, u - 1.0 h = (b - a) / n acc = 0.0 for i in range(n): lo, hi = a + i * h, a + (i + 1) * h m = 0.5 * (lo + hi) acc += (h / 6.0) * (g(lo) + 4 * g(m) + g(hi)) return acc def d3_decomposition(u): """Independent form: (log(u-2))^2/2 - int_1^(u-2) log z/(z(z+1)) dz.""" A = u - 2.0 n = 40000 h = A / n if False else (A - 1.0) / n I = 0.0 for i in range(n): lo, hi = 1.0 + i * h, 1.0 + (i + 1) * h m = 0.5 * (lo + hi) f = lambda z: math.log(z) / (z * (z + 1)) I += (h / 6.0) * (f(lo) + 4 * f(m) + f(hi)) return math.log(A) ** 2 / 2 - I def bound_cert(u0, u1, d3=None, tail=False): """The certificate's own bound on a piece, with the device the certificate used there.""" D = d3 if d3 is not None else d3_formula_lower(u0) f = 1.0 if tail else f1_sq_cert(u1 / 2.0) return f * (1.0 + 1.0 / D) def bound_true(u0, u1): return f1_sq_true(u1 / 2.0) * (1.0 + 1.0 / d3_true(u0)) def d3_needed(A): return 1.0 / (2.0 / A - 1.0) def main(): out = {} print("=" * 78) print("0. INTEGRITY GATE: reproduce Proposition 5's published table") print("=" * 78) print(" e^gamma as a certified upper bound: 9/5 = %.4f (true %.6f); D_3 by cell minima" % (float(EG_CERT), EG_TRUE)) print() pub = [(4, F(22, 5), F(781, 1000)), (F(22, 5), F(24, 5), F(1491, 1000)), (F(24, 5), 6, F(3120, 1000)), (6, 8, F(2899, 1000)), (8, None, F(1971, 1000))] rows = [] for u0, u1, claimed in pub: if u1 is None: b = bound_cert(float(u0), None, d3=cell_min_lower(float(u0)), tail=True) else: b = bound_cert(float(u0), float(u1)) # finite: the formula rows.append(dict(piece="(%s,%s]" % (u0, u1), claimed=str(claimed), reproduced=round(b, 4), agrees=abs(b - float(claimed)) <= 0.002)) print(" (%s,%s] published %-6s reproduced %.4f %s" % (u0, u1, claimed, b, "OK" if abs(b - float(claimed)) <= 0.002 else "DIFFERS")) out["publication_gate"] = rows print(" the two pieces whose published bound exceeds 2 are exactly (24/5,6] and (6,8].") print() print("=" * 78) print("1. THE RESIDUE'S SIZE") print("=" * 78) print(" u D_3 true D_3 cell-min bound(cert, coarse) closed?") for u in (4.8, 5.0, 6.0, 7.0, 8.0): print(" %.1f %9.6f %9.6f" % (u, d3_true(u), cell_min_lower(u))) print(" cross-check D_3 true against the decomposition form:") for u in (4.8, 6.0, 8.0): print(" u = %.1f : Simpson %.9f decomposition %.9f diff %.2e" % (u, d3_true(u), d3_decomposition(u), abs(d3_true(u) - d3_decomposition(u)))) print() for u0, u1 in ((4.8, 6.0), (6.0, 8.0)): A = f1_sq_cert(u1 / 2.0) print(" piece (%.1f,%.1f]: f_1(u_1/2)^2 = %.4f, needs D_3 > %.4f; true D_3(u_0) = %.4f" % (u0, u1, A, d3_needed(A), d3_true(u0))) out["residue"] = {str(u): {"d3_true": d3_true(u), "d3_cell_min": cell_min_lower(u)} for u in (4.8, 5.0, 6.0, 7.0, 8.0)} print() print("=" * 78) print("2. THE REFINED PARTITION: closed with cell-minimum D_3, NO parity input") print("=" * 78) print(" sub-piece f_1(u_1/2)^2 D_3 cell-min D_3 needed bound closed?") refined = [] for u0, u1 in [(4.8, 5.0), (5.0, 5.5), (5.5, 6.0), (6.0, 6.5), (6.5, 7.0), (7.0, 7.5), (7.5, 8.0)]: A = f1_sq_cert(u1 / 2.0) Dm = max(cell_min_lower(u0), d3_formula_lower(u0)) # both are rigorous lower bounds need = d3_needed(A) b = A * (1.0 + 1.0 / Dm) if Dm > 0 else float("inf") r = dict(u0=u0, u1=u1, A=A, d3_cell_min=Dm, d3_needed=need, bound=b, closed=b < 2.0) refined.append(r) print(" (%.1f,%.1f] %11.6f %11.6f %9.6f %7.4f %s" % (u0, u1, A, Dm, need, b, "yes" if r["closed"] else "no")) out["refined"] = refined allclosed = all(r["closed"] for r in refined) print() print(" => %s" % ("EVERY sub-piece closes with the certificate's own method and no parity " "hypothesis." if allclosed else "a sub-piece still fails.")) print(" the whole open window (4.8,8] is therefore a PIECE-WIDTH / D_3-ENCLOSURE problem.") out["all_closed"] = allclosed print() print("=" * 78) print("2b. THE CLOSED FORM, AND THE SAME REFINEMENT WITH IT") print("=" * 78) print(" D_3(u) = log(u-2) log(u-1) + pi^2/12 + Li_2(-(u-2)) [exact]") print(" u closed form Simpson diff") for u in (4.8, 5.0, 6.0, 7.0, 8.0): cf = d3_closed(u) sp = d3_true(u) print(" %.1f %.12f %.12f %.2e" % (u, cf, sp, abs(cf - sp))) print(" a rigorous LOWER bound is available at any precision from the alternating series after") print(" the inversion formula (K = 200 terms here):") for u in (4.8, 6.0, 7.5, 8.0): print(" u = %.1f : Li_2 bracket width %.2e, D_3 lower bound %.9f (true %.9f)" % (u, li2_neg_bounds(u - 2.0)[1] - li2_neg_bounds(u - 2.0)[0], d3_closed(u, "lo"), d3_true(u))) print() print(" the same seven sub-pieces, with the CLOSED-FORM lower bound:") refined2 = [] for u0, u1 in [(4.8, 5.0), (5.0, 5.5), (5.5, 6.0), (6.0, 6.5), (6.5, 7.0), (7.0, 7.5), (7.5, 8.0)]: A = f1_sq_cert(u1 / 2.0) Dlo = d3_closed(u0, "lo") b = A * (1.0 + 1.0 / Dlo) refined2.append(dict(u0=u0, u1=u1, A=A, d3_lo=Dlo, bound=b, closed=b < 2.0)) print(" (%.1f,%.1f] A = %.6f D_3 >= %.6f bound = %.6f %s" % (u0, u1, A, Dlo, b, "closed" if b < 2.0 else "open")) out["refined_closed_form"] = refined2 out["closed_form_ok"] = all(r["closed"] for r in refined2) print() print(" => %s" % ("the whole window closes on the closed form, with NO parity input and NO " "change to any structural hypothesis." if out["closed_form_ok"] else "a sub-piece still fails even on the closed form.")) print() print("=" * 78) print("3. WHERE THE DEDUCTION COULD HAVE ACTED, AND WHY IT CANNOT") print("=" * 78) print(" The deduction removes mass from rho_odd - 1. The bound uses 1/(rho_odd - 1) <= 1/D_3(u)") print(" and rho_odd >= 1 + D_3(u); removing mass lowers rho_odd, which RAISES c*_real unless the") print(" removal is exactly the mass that was already outside the contaminant class. On the exact") print(" ledger the contaminant sum is indexed by configurations carrying a prime member, and a") print(" (+1,+1) slot has NO prime member, so its mass was never in rho_odd: the deduction is the") print(" identity, 0 removed, and the bound above stands unchanged.") with open("work/route39-certificate.json", "w", encoding="utf-8") as fh: json.dump(out, fh, ensure_ascii=False, indent=1, sort_keys=True) print() print("wrote work/route39-certificate.json") return 0 if __name__ == "__main__": raise SystemExit(main())