#!/usr/bin/env python3 """Rigorous upper bound for the Skyrme energy (with or without pion mass) of the axially symmetric degree-2 trial map stored by trial_b2.py. THE MAP (defined exactly by float data). Data: nodes 0 = r_0 < ... < r_N = R, 0 = t_0 < ... < t_K = 1 and nodal values phi_{ik}, gam_{ik} (float64) with phi_{0k} = 1, phi_{Nk} = 0, gam_{i0} = 0, gam_{iK} = 1. Let phi, gam be the continuous piecewise bilinear interpolants on [0,R] x [0,1] and f(r, th) = pi * phi(r, t), g(r, th) = (pi/2) * gam(r, t), th = (pi/2) t (0 <= th <= pi/2), f(r, pi - th) = f(r, th), g(r, pi - th) = pi - g(r, th), U = (cos f, sin f sin g cos 2 phi_az, sin f sin g sin 2 phi_az, sin f cos g) for |x| <= R, U = (1,0,0,0) outside. U is Lipschitz, equals the vacuum outside the ball, and has degree -2 (boundary term; see the note). Its energy is E / (12 pi^2) = (1/6) int_0^R int_0^1 G dt dr, G = (P + s^2 Q)(w + 4 s^2 sg^2/(r^2 w)) + 4 s^2 sg^2 / w + w s^2 K^2, P = r^2 f_r^2 + f_th^2, Q = r^2 g_r^2 + g_th^2, K = f_r g_th - f_th g_r, s = sin f, sg = sin g, w = sin th. With a pion mass mu (energy density + 2 mu^2 (1 - cos f)) G gets the extra term 2 mu^2 r^2 w (1 - cos f); mu is given as a decimal string and treated as the exact rational number it denotes. THE BOUND. Every cell is cut into m x m boxes. * regular cells (i >= 1, k >= 1; G is analytic there): second-order Taylor bound around the box centre c, int_Q G <= |Q| G(c) + grad G . int_Q (x - c) + 1/2 sup G_rr int (r-c_r)^2 + sup|G_rt| int |r-c_r||t-c_t| + 1/2 sup G_tt int (t-c_t)^2, with G(c) from interval arithmetic at the centre and the suprema of the second derivatives over Q from interval jets (automatic differentiation with interval coefficients). * first radial column (r <= r_1) and first angular row (t <= t_1): |Q| sup_Q G, with the removable singularities bounded by sin^2 f / r^2 <= pi^2 (1 - phi(r_1,t))^2 / r_1^2 and sin^2 g / sin th <= (pi/2) gam(r,t_1)^2 t / (t_1^2 (1 - th^2/6)). WINDING. With a fifth argument w (default 2) the azimuth enters as w * phi_az: U = (cos f, sin f sin g cos(w phi_az), sin f sin g sin(w phi_az), sin f cos g), the degree is -w, and the factor 4 = 2^2 in G becomes w^2. w = 1 is used for upper bounds of I_1 (maps of degree -1). usage: python3 verify_b2.py [m_regular] [m_singular] [mu] [w] """ import sys, math, json, time import numpy as np import ival as iv from ival import I, iadd, isub, imul, isqr, iinv, ihull, Jet, add, sub, mul, sqr, sin, cos, inv, scale, PI, PIH, ZERO TWO = I(2.0) ONE = I(1.0) MASS = None # enclosure of 2 mu^2 (set in main); None for massless pions WIND2 = 4.0 # square of the azimuthal winding number (exact small integer; set in main) def load(path): d = np.load(path) if 'phi' in d.files: # exact data (r, t, phi, gam): this file DEFINES the map r, t, phi, gam = (np.array(d[k], dtype=np.float64) for k in ('r', 't', 'phi', 'gam')) else: # output of trial_b2.py (r, th, f, g); converted once, see export_exact() r = np.array(d['r'], dtype=np.float64) t = np.array(d['th'], dtype=np.float64) / (math.pi / 2) phi = np.array(d['f'], dtype=np.float64) / math.pi gam = np.array(d['g'], dtype=np.float64) / (math.pi / 2) # exact boundary data (this DEFINES the map) r[0] = 0.0; t[0] = 0.0; t[-1] = 1.0 phi[0, :] = 1.0; phi[-1, :] = 0.0; gam[:, 0] = 0.0; gam[:, -1] = 1.0 assert np.all(np.diff(r) > 0) and np.all(np.diff(t) > 0) assert np.all(np.isfinite(phi)) and np.all(np.isfinite(gam)) return r, t, phi, gam def export_exact(path_in, path_out): r, t, phi, gam = load(path_in) np.savez(path_out, r=r, t=t, phi=phi, gam=gam) def make_boxes(r, t, ci, ck, m): """float box boundaries for cells (ci, ck), m x m boxes per cell; boundaries are floats, ends exact""" r0, r1, t0, t1 = r[ci], r[ci + 1], t[ck], t[ck + 1] a = np.arange(m + 1) / m rb = r0[:, None] + a[None, :] * (r1 - r0)[:, None]; rb[:, 0] = r0; rb[:, -1] = r1 tb = t0[:, None] + a[None, :] * (t1 - t0)[:, None]; tb[:, 0] = t0; tb[:, -1] = t1 assert np.all(np.diff(rb, axis=1) > 0) and np.all(np.diff(tb, axis=1) > 0) nc = len(ci) shp = (nc, m, m) rl = np.broadcast_to(rb[:, :-1, None], shp).ravel(); rh = np.broadcast_to(rb[:, 1:, None], shp).ravel() tl = np.broadcast_to(tb[:, None, :-1], shp).ravel(); th = np.broadcast_to(tb[:, None, 1:], shp).ravel() rep = lambda x: np.repeat(x, m * m) return rl, rh, tl, th, rep(ci), rep(ck) class Cell: """bilinear data on the boxes' cells and enclosures of phi, gam and their derivatives on a sub-rectangle""" def __init__(self, r, t, phi, gam, ci, ck): self.r0, self.r1, self.t0, self.t1 = I(r[ci]), I(r[ci + 1]), I(t[ck]), I(t[ck + 1]) self.iDr = iinv(isub(self.r1, self.r0)); self.iDt = iinv(isub(self.t1, self.t0)) self.p = [I(phi[ci, ck]), I(phi[ci + 1, ck]), I(phi[ci, ck + 1]), I(phi[ci + 1, ck + 1])] self.q = [I(gam[ci, ck]), I(gam[ci + 1, ck]), I(gam[ci, ck + 1]), I(gam[ci + 1, ck + 1])] def coords(self, rl, rh, tl, th): xl = imul(isub(I(rl), self.r0), self.iDr); xh = imul(isub(I(rh), self.r0), self.iDr) el = imul(isub(I(tl), self.t0), self.iDt); eh = imul(isub(I(th), self.t0), self.iDt) return xl, xh, el, eh def field(self, c, xl, xh, el, eh): """enclosures over the rectangle [xl,xh] x [el,eh] (local coordinates) of u, u_r, u_t, u_rt""" c00, c10, c01, c11 = c c1 = isub(c10, c00); c2 = isub(c01, c00); c3 = iadd(isub(isub(c11, c10), c01), c00) def bil(x, e): return iadd(iadd(c00, imul(c1, x)), iadd(imul(c2, e), imul(c3, imul(x, e)))) v = ihull(ihull(bil(xl, el), bil(xh, el)), ihull(bil(xl, eh), bil(xh, eh))) X = I(xl.lo, xh.hi); E = I(el.lo, eh.hi) ur = imul(iadd(c1, imul(c3, E)), self.iDr) ut = imul(iadd(c2, imul(c3, X)), self.iDt) urt = imul(c3, imul(self.iDr, self.iDt)) return v, ur, ut, urt def G_formula(r, w, s2, sg2, fr, fth, gr, gth, X=None, Y=None, one_minus_cos=None): """G = (P + s^2 Q)(w + 4 X Y) + 4 s^2 Y + w s^2 K^2 [+ 2 mu^2 r^2 w (1 - cos f)] with X = s^2/r^2, Y = sg^2/w (generic in intervals / jets)""" r2 = sqr(r) P = add(mul(r2, sqr(fr)), sqr(fth)) Q = add(mul(r2, sqr(gr)), sqr(gth)) K = sub(mul(fr, gth), mul(fth, gr)) if X is None: X = mul(s2, inv(r2)) if Y is None: Y = mul(sg2, inv(w)) t1 = mul(add(P, mul(s2, Q)), add(w, scale(mul(X, Y), WIND2))) t2 = scale(mul(s2, Y), WIND2) t3 = mul(w, mul(s2, sqr(K))) out = add(add(t1, t2), t3) if MASS is not None: m2 = Jet(MASS) if isinstance(r, Jet) else MASS out = add(out, mul(mul(mul(r2, w), one_minus_cos), m2)) return out def eval_values(cell, rl, rh, tl, th, special_r=False, special_t=False): """interval enclosure of G over the boxes [rl,rh] x [tl,th] (values only)""" xl, xh, el, eh = cell.coords(rl, rh, tl, th) pv, pr, pt, _ = cell.field(cell.p, xl, xh, el, eh) qv, qr, qt, _ = cell.field(cell.q, xl, xh, el, eh) R = I(rl, rh); T = I(tl, th) theta = imul(PIH, T) f = imul(PI, pv); g = imul(PIH, qv) fr = imul(PI, pr); fth = imul(TWO, pt); gr = imul(PIH, qr); gth = qt w = sin(theta); s2 = isqr(sin(f)); sg2 = isqr(sin(g)) X = Y = None if special_r: # column 0: phi = 1 - (r/r_1)(1 - phi_1(t)), sin^2 f <= pi^2 r^2 (1 - phi_1)^2 / r_1^2 E = I(el.lo, eh.hi) one_minus = isub(I(1.0), iadd(cell.p[1], imul(isub(cell.p[3], cell.p[1]), E))) Xb = imul(imul(isqr(PI), isqr(one_minus)), isqr(cell.iDr)) X = I(np.zeros_like(Xb.hi), Xb.hi) if special_t: # row 0: gam = (t/t_1) gam_1(r), sin^2 g <= (pi/2)^2 gam_1^2 t^2/t_1^2, sin th >= th (1 - th^2/6) Xr = I(xl.lo, xh.hi) gam1 = iadd(cell.q[2], imul(isub(cell.q[3], cell.q[2]), Xr)) den = isub(I(1.0), imul(isqr(theta), I(iv.frac_enclosure(iv.Fraction(1, 6))[0], iv.frac_enclosure(iv.Fraction(1, 6))[1]))) Yb = imul(imul(imul(PIH, isqr(gam1)), imul(T, isqr(cell.iDt))), iinv(den)) Y = I(np.zeros_like(Yb.hi), Yb.hi) omc = isub(ONE, cos(f)) if MASS is not None else None return G_formula(R, w, s2, sg2, fr, fth, gr, gth, X, Y, omc) def eval_jets(cell, rl, rh, tl, th): """interval jets (value, gradient, Hessian in (r,t)) of G over the boxes""" xl, xh, el, eh = cell.coords(rl, rh, tl, th) pv, pr, pt, prt = cell.field(cell.p, xl, xh, el, eh) qv, qr, qt, qrt = cell.field(cell.q, xl, xh, el, eh) R = Jet(I(rl, rh), r=I(1.0)) theta = Jet(imul(PIH, I(tl, th)), t=PIH) f = Jet(imul(PI, pv), r=imul(PI, pr), t=imul(PI, pt), rt=imul(PI, prt)) g = Jet(imul(PIH, qv), r=imul(PIH, qr), t=imul(PIH, qt), rt=imul(PIH, qrt)) fr = Jet(imul(PI, pr), t=imul(PI, prt)) fth = Jet(imul(TWO, pt), r=imul(TWO, prt)) gr = Jet(imul(PIH, qr), t=imul(PIH, qrt)) gth = Jet(qt, r=qrt) w = sin(theta); s2 = sqr(sin(f)); sg2 = sqr(sin(g)) omc = sub(Jet(ONE), cos(f)) if MASS is not None else None return G_formula(R, w, s2, sg2, fr, fth, gr, gth, one_minus_cos=omc) def bound_regular(r, t, phi, gam, ci, ck, m, chunk=40000): rl, rh, tl, th, bi, bk = make_boxes(r, t, ci, ck, m) n = len(rl) main = np.empty(n); rem = np.empty(n) for a in range(0, n, chunk): sl = slice(a, min(n, a + chunk)) cell = Cell(r, t, phi, gam, bi[sl], bk[sl]) cr = 0.5 * (rl[sl] + rh[sl]); ct = 0.5 * (tl[sl] + th[sl]) assert np.all((cr > rl[sl]) & (cr < rh[sl]) & (ct > tl[sl]) & (ct < th[sl])) Gc = eval_values(cell, cr, cr, ct, ct) J = eval_jets(cell, rl[sl], rh[sl], tl[sl], th[sl]) assert np.all(Gc.lo >= J.v.lo - 1e-9 * (1 + np.abs(J.v.lo))) and np.all(Gc.hi <= J.v.hi + 1e-9 * (1 + np.abs(J.v.hi))) # geometric factors (intervals) ar = isub(I(rh[sl]), I(cr)); br = isub(I(cr), I(rl[sl])) # b - c, c - a (r) at = isub(I(th[sl]), I(ct)); bt = isub(I(ct), I(tl[sl])) wr = isub(I(rh[sl]), I(rl[sl])); wt = isub(I(th[sl]), I(tl[sl])) area = imul(wr, wt) third = I(*iv.frac_enclosure(iv.Fraction(1, 3))) Irr = imul(imul(iadd(imul(isqr(ar), ar), imul(isqr(br), br)), third), wt) # int (r - c)^2 Itt = imul(imul(iadd(imul(isqr(at), at), imul(isqr(bt), bt)), third), wr) Irt = imul(imul(iadd(isqr(ar), isqr(br)), I(0.5)), imul(iadd(isqr(at), isqr(bt)), I(0.5))) # int |r-c||t-c| Lr = imul(imul(isub(isqr(ar), isqr(br)), I(0.5)), wt) # int (r - c) Lt = imul(imul(isub(isqr(at), isqr(bt)), I(0.5)), wr) m0 = imul(area, I(Gc.hi)) lin = iadd(imul(J.r, Lr), imul(J.t, Lt)) hrr = imul(imul(I(J.rr.hi), Irr), I(0.5)) htt = imul(imul(I(J.tt.hi), Itt), I(0.5)) hrt = imul(I(np.maximum(np.abs(J.rt.lo), np.abs(J.rt.hi))), Irt) rr = iadd(iadd(lin, hrr), iadd(hrt, htt)) main[sl] = m0.hi; rem[sl] = rr.hi if not (np.all(np.isfinite(main[sl])) and np.all(np.isfinite(rem[sl]))): raise FloatingPointError("non-finite bound") return main, rem, bi, bk def bound_singular(r, t, phi, gam, ci, ck, m): rl, rh, tl, th, bi, bk = make_boxes(r, t, ci, ck, m) out = np.empty(len(rl)) for flag_r in (False, True): for flag_t in (False, True): sel = ((bi == 0) == flag_r) & ((bk == 0) == flag_t) if not sel.any(): continue assert flag_r or flag_t cell = Cell(r, t, phi, gam, bi[sel], bk[sel]) if flag_r: assert np.all(phi[0, :] == 1.0) if flag_t: assert np.all(gam[:, 0] == 0.0) G = eval_values(cell, rl[sel], rh[sel], tl[sel], th[sel], special_r=flag_r, special_t=flag_t) area = imul(isub(I(rh[sel]), I(rl[sel])), isub(I(th[sel]), I(tl[sel]))) out[sel] = imul(area, I(np.maximum(G.hi, 0.0))).hi if not np.all(np.isfinite(out)): raise FloatingPointError("non-finite bound (singular cells)") return out, bi, bk def main(): global MASS, WIND2 path = sys.argv[1] m = int(sys.argv[2]) if len(sys.argv) > 2 else 8 ms = int(sys.argv[3]) if len(sys.argv) > 3 else 8 mu_str = sys.argv[4] if len(sys.argv) > 4 else "0" mu = iv.Fraction(mu_str) # exact rational value of the decimal string assert mu >= 0 if mu > 0: MASS = I(*iv.frac_enclosure(2 * mu * mu)) wind = int(sys.argv[5]) if len(sys.argv) > 5 else 2 assert wind in (1, 2, 3, 4) WIND2 = float(wind * wind) t0 = time.time() iv.selftest() r, t, phi, gam = load(path) N, K = len(r) - 1, len(t) - 1 ii, kk = np.meshgrid(np.arange(N), np.arange(K), indexing='ij') ii, kk = ii.ravel(), kk.ravel() reg = (ii >= 1) & (kk >= 1) main_, rem, bi, bk = bound_regular(r, t, phi, gam, ii[reg], kk[reg], m) sing, si, sk = bound_singular(r, t, phi, gam, ii[~reg], kk[~reg], ms) # exact summation of the box bounds (math.fsum is correctly rounded), then outward rounding S_main = math.fsum(main_.tolist()); S_rem = math.fsum(rem.tolist()); S_sing = math.fsum(sing.tolist()) total = math.nextafter(math.fsum(main_.tolist() + rem.tolist() + sing.tolist()), math.inf) sixth_hi = iv.frac_enclosure(iv.Fraction(1, 6))[1] E_hi = math.nextafter(total * sixth_hi, math.inf) print(f"file {path}: grid {N} x {K}, R = {r[-1]}, boxes per cell {m}x{m} (regular), {ms}x{ms} (singular), mu = {mu_str}, winding = {wind}") print(f" centre terms {S_main / 6:.9f}") print(f" remainders {S_rem / 6:.3e}") print(f" singular cells {S_sing / 6:.3e}") print(f" RIGOROUS UPPER BOUND E(U)/(12 pi^2) <= {math.ceil(E_hi * 1e9) / 1e9:.9f} [{time.time() - t0:.0f} s]") # per-cell diagnostics: largest remainders cellrem = np.zeros((N, K)); np.add.at(cellrem, (bi, bk), rem) worst = np.unravel_index(np.argmax(cellrem), cellrem.shape) print(f" largest remainder in a cell: {cellrem.max() / 6:.2e} at cell {worst}, r in [{r[worst[0]]:.3f},{r[worst[0] + 1]:.3f}]," f" t in [{t[worst[1]]:.4f},{t[worst[1] + 1]:.4f}]") thr = {"0": 2.38408, "0.526": 2.60342, "0.65": 2.66184, "1": 2.82864}.get(mu_str) # 2 x first certificate out = dict(file=path, N=int(N), K=int(K), R=float(r[-1]), m=m, ms=ms, mu=mu_str, winding=wind, centre=S_main / 6, remainder=S_rem / 6, singular=S_sing / 6, E_upper=E_hi, threshold=thr) with open(path.replace('.npz', f'_verified_m{m}.json'), 'w') as fh: json.dump(out, fh, indent=1) return E_hi if __name__ == "__main__": main()