#!/usr/bin/env python3 """Rigorous building blocks for the level-set lower bound (massless Skyrme energy), written from scratch on top of ival.py (independent of global/levelset_cert*.py and src/iv.py). h_kappa(D) = 2 sqrt((1+2D)(D^2+2D+kappa)), c(tau) = 4 pi sin^2 tau, g(v) = (36 pi)^(1/3) v^(2/3), Xi(tau, v) = 4 pi (pi - tau)^2 r(v), 4 pi r^3 / 3 = v. certify(): proof that alpha + beta D <= h_kappa(D) for all D >= 0 ("minorant"), by the identity h^2 - (alpha + beta D)^2 = 8 (D-m)^2 (D+e) + q2 D^2 + q1 D + q0 (any m, e) and the test m, e >= 0, q2 >= 0, q0 >= 0, (q1 >= 0 or q1^2 <= 4 q2 q0), evaluated with outward rounding. """ import math import numpy as np import ival as iv from ival import I, iadd, isub, imul, isqr, dn, up, PI_LO, PI_HI K1 = 0.3819660112501051 # (3 - sqrt 5)/2 (floating-point heuristics only) K2 = 2.618033988749895 # (3 + sqrt 5)/2 EPS_MIN = 1e-7 # relative lowering of alpha, beta: slack for the cubic test def g_lower(v): """floats g_lo >= 0 with g_lo^3 <= 36 pi v^2, i.e. g_lo <= g(v); verified with directed rounding""" g = np.cbrt(36.0 * math.pi * v * v) * (1.0 - 1e-15) rhs = dn(dn(36.0 * PI_LO) * dn(v * v)) for _ in range(200): bad = (up(up(g * g) * g) > rhs) & (v > 0) if not bad.any(): break g = np.where(bad, dn(g * (1.0 - 1e-15)), g) g = np.where(v > 0, g, 0.0) assert not ((up(up(g * g) * g) > rhs) & (v > 0)).any() and np.all(g >= 0) return g def r_lower(v): """floats r_lo >= 0 with 4 pi r_lo^3 <= 3 v, i.e. r_lo <= r(v)""" r = np.cbrt(3.0 * v / (4.0 * math.pi)) * (1.0 - 1e-15) rhs = dn(3.0 * v) f = up(4.0 * PI_HI) for _ in range(200): bad = (up(up(up(r * r) * r) * f) > rhs) & (v > 0) if not bad.any(): break r = np.where(bad, dn(r * (1.0 - 1e-15)), r) r = np.where(v > 0, r, 0.0) assert not ((up(up(up(r * r) * r) * f) > rhs) & (v > 0)).any() and np.all(r >= 0) return r def xi_lower(tau, rlo): """float(s) <= 4 pi (pi - tau)^2 r, for tau < pi and r >= rlo >= 0""" d = dn(PI_LO - tau) assert np.all(d > 0) return dn(dn(dn(4.0 * PI_LO) * dn(d * d)) * rlo) def xi_mu_lower(tau, rlo, mu_lo): """float(s) <= Xi_mu(tau, v) = 16 pi cos^2(tau/2) (r + mu r^2), for 0 < tau < pi, r >= rlo >= 0, mu >= mu_lo >= 0""" half = np.asarray(tau, dtype=np.float64) / 2.0 # exact (division by two) ch = iv.isincos(I(half))[1].lo # <= cos(tau/2) assert np.all(ch > 0) and mu_lo >= 0 return dn(dn(dn(16.0 * PI_LO) * dn(ch * ch)) * dn(rlo + dn(mu_lo * dn(rlo * rlo)))) def V_lower(taus, mu): """floats 0 <= V_lo <= V(tau) = 2 mu^2 (1 + cos tau) at the given levels; mu is an exact Fraction""" m2 = I(*iv.frac_enclosure(2 * mu * mu)) c = iv.isincos(I(np.asarray(taus, dtype=np.float64)))[1] val = imul(m2, iadd(I(1.0), c)) return np.maximum(val.lo, 0.0) def c_integral_lower(taus): """floats C_lo[i] <= int_{tau_i}^{tau_{i+1}} 4 pi sin^2 = 2 pi [(tau_{i+1}-tau_i) - (s1 c1 - s0 c0)], 0 < tau < pi""" s, c = iv.isincos(I(taus)) sc = imul(s, c) T = I(taus) d = isub(I(T.lo[1:]), I(T.lo[:-1])) e = isub(I(sc.lo[1:], sc.hi[1:]), I(sc.lo[:-1], sc.hi[:-1])) val = imul(imul(I(2.0), iv.PI), isub(d, e)) assert np.all(val.lo > 0) return val.lo def minorant(kap, g, c): """FLOATING-POINT proposal (alpha, beta, m, e): tangent of the convex envelope of h_kap at D0 = c/g (free-area line if c/g >= D*, two-phase line if c/g <= D_t), lowered by the factor 1 - EPS_MIN.""" with np.errstate(divide='ignore', invalid='ignore'): Ds = 0.5 * (1.0 + np.sqrt(1.0 + 4.0 * kap)) free = (g <= 0.0) | (c >= Ds * g) sk = np.sqrt(kap) bt = np.where(kap >= K2, 4.0 * np.sqrt(1.0 + sk) - 2.0, 4.0 * np.sqrt(np.maximum(1.0 - sk, 0.0)) + 2.0) has2 = (kap >= K2) | (kap <= K1) Dt = np.where(has2, np.maximum((bt * bt - 20.0) / 16.0, 0.0), 0.0) D0 = np.where(g > 0, c / np.where(g > 0, g, 1.0), np.inf) two = (~free) & has2 & (D0 <= Dt) m1 = np.where(np.isfinite(D0), D0, 1.0) rad = np.sqrt((1.0 + 2.0 * m1) * (m1 * m1 + 2.0 * m1 + kap)) b1 = (6.0 * m1 * m1 + 10.0 * m1 + 2.0 + 2.0 * kap) / rad a1 = np.maximum(2.0 * rad - m1 * b1, 0.0) e1 = np.maximum((20.0 + 16.0 * m1 - b1 * b1) / 8.0, 0.0) alpha = np.where(free, 0.0, np.where(two, 2.0 * sk, a1)) beta = np.where(free, 2.0 * (1.0 + 2.0 * Ds) / np.sqrt(Ds), np.where(two, bt, b1)) m = np.where(free, Ds, np.where(two, Dt, m1)) e = np.where(free, kap / (2.0 * Ds * Ds), np.where(two, 0.0, e1)) return alpha * (1.0 - EPS_MIN), beta * (1.0 - EPS_MIN), m, e def certify(alpha, beta, kap, m, e): """RIGOROUS: True where 'alpha + beta D <= h_kap(D) for all D >= 0' is proved""" A, B, K, M, E = I(alpha), I(beta), I(kap), I(m), I(e) c8, c20, c4, c2 = I(8.0), I(20.0), I(4.0), I(2.0) q2 = isub(isub(c20, isqr(B)), imul(c8, isub(E, imul(c2, M)))) q1 = isub(isub(iadd(c8, imul(c8, K)), imul(c2, imul(A, B))), imul(c8, isub(isqr(M), imul(c2, imul(M, E))))) q0 = isub(isub(imul(c4, K), isqr(A)), imul(c8, imul(isqr(M), E))) base = (alpha >= 0) & (beta >= 0) & (kap >= 0) & (m >= 0) & (e >= 0) & (q2.lo >= 0) & (q0.lo >= 0) amax = np.maximum(np.abs(q1.lo), np.abs(q1.hi)) disc = up(amax * amax) <= dn(4.0 * dn(q2.lo * q0.lo)) return base & ((q1.lo >= 0) | disc) & np.isfinite(alpha) & np.isfinite(beta) def certified_minorant(kap, g, c): """(alpha, beta, n_fallback) with alpha + beta D <= h_kap(D) on [0, inf) PROVED for every entry. Fallback (always provable): the Bogomolny line 6 D <= h_0(D) <= h_kap(D).""" alpha, beta, m, e = minorant(kap, g, c) ok = certify(alpha, beta, kap, m, e) if not ok.all(): ok = ok | certify(alpha, beta, kap, m, e * (1.0 - 1e-10)) nfb = int((~ok).sum()) if nfb: # Bogomolny line: h_kap(D)^2 >= h_0(D)^2 = 36 D^2 + 8 D (D-1)^2 >= (6 D)^2 for all kap, D >= 0 (exact identity, # no computation needed); used with the slope 6 (1 - EPS_MIN) < 6. assert np.all(kap >= 0) alpha = np.where(ok, alpha, 0.0); beta = np.where(ok, beta, 6.0 * (1.0 - EPS_MIN)) return alpha, beta, nfb def selftest(): """the certified minorants really are below h_kappa (floating-point spot check), and the test is not vacuous""" rng = np.random.default_rng(3) kap = np.concatenate([10.0 ** rng.uniform(-9, 5, 4000), [0.0, K1, K2, 1.0]]) g = 10.0 ** rng.uniform(-3, 3, len(kap)); c = 10.0 ** rng.uniform(-3, 3, len(kap)) a, b, nfb = certified_minorant(kap, g, c) D = 10.0 ** np.linspace(-8, 6, 1401) h = 2.0 * np.sqrt((1 + 2 * D[None, :]) * (D[None, :] ** 2 + 2 * D[None, :] + kap[:, None])) gap = h - (a[:, None] + b[:, None] * D[None, :]) assert (gap >= -1e-9 * h).all(), "certified minorant above h" D0 = c / g h0 = 2.0 * np.sqrt((1 + 2 * D0) * (D0 ** 2 + 2 * D0 + kap)) # a deliberately wrong line must be rejected bad = certify(a * 1.01 + 1e-3, b * 1.01, kap, *minorant(kap, g, c)[2:]) return nfb, float(np.median((a + b * D0) / h0)), int(bad.sum()) if __name__ == "__main__": print("fallbacks %d, median (minorant at D0)/h(D0) = %.6f, wrong lines accepted: %d" % selftest())