#!/usr/bin/env python3 """Independent re-derivation of the certified level-set lower bound for the degree-1 Skyrme energy (massless pions, and since the eighth part also massive pions: last argument mu, see PION MASS below). New code (ival.py, lsb.py); nothing is shared with global/levelset_cert*.py. SETTING. U finite-energy, degree 1; theta = dist(U, -1); v(tau) = |{theta < tau}|; e(tau) = energy carried by the level set {theta = tau} (coarea); E(U) >= int_0^pi e. For a.e. tau, every kappa >= 0 and every minorant alpha + beta D <= h_kappa(D) (D >= 0; alpha, beta >= 0): e(tau) >= alpha g(v(tau)) + beta c(tau) - kappa M(tau), int_a^b M <= v(b) - v(a). (*) STEP LEMMA. Levels tau_0 < ... < tau_N. Integrating (*) over [tau_i, tau_{i+1}] (g(v(tau)) >= g(v(tau_i))): int_{tau_i}^{tau_{i+1}} e >= alpha g(v) dt_i + beta C_i - kappa (v' - v), v = v(tau_i), v' = v(tau_{i+1}) >= v, C_i = int c. REFINED FORM (used below; P = 1 is the line above). Cut the step into P pieces of lengths D_m with int c = C_m, and let v' <= v_J. With sigma <= g'(v_J) (g concave, so g(w) >= g(v) + sigma (w - v) on [v, v_J]), multipliers kappa_m <= kappa + sigma A_m, A_m = sum_{l > m} alpha_l D_l, and minorants (alpha_m, beta_m) of h_{kappa_m}: int_{tau_i}^{tau_{i+1}} e >= (sum_m alpha_m D_m) g(v) + sum_m beta_m C_m - kappa (v' - v). (Proof: apply the first line on every piece, with the volume w_{m-1} at its start; then sum_m alpha_m D_m sigma (w_{m-1} - v) = sigma sum_l (w_l - w_{l-1}) A_l, and kappa_l - sigma A_l <= kappa.) Earlier pieces thus get larger multipliers, which recovers most of the growth of g during the step. Hence if int_{tau_{i+1}}^pi e >= W_{i+1}(v(tau_{i+1})) for all maps, then int_{tau_i}^pi e >= W_i(v(tau_i)) for any W_i with W_i(v) <= alpha g(v) dt_i + beta C_i - kappa (v'-v) + W_{i+1}(v') for all v' >= v, where the minorant may depend on (v, v'). DATA STRUCTURE. W_i is continuous, piecewise linear on the nodes 0 = v_0 < v_1 < ... < v_n, nondecreasing, and W_i(v) = Xi(tau_i, v) for v > v_n (Xi(tau, v) = 4 pi (pi-tau)^2 r(v): Dirichlet bound, valid at every level), with W_i(v_n) <= Xi(tau_i, v_n). Start: W_N = interpolant of Xi(tau_N, .) (Xi is concave in v). ONE STEP, CELL j (v in [v_j, v_{j+1}]). The arrival volumes v' >= v are split into ranges with end nodes j = J_0 < J_1 <= ... <= J_K <= n; range k has its own multiplier kappa_k and certified minorant (alpha_k, beta_k): range 1, v' in [v, v_{J_1}]: bound_1(v) = alpha_1 g(v) dt + beta_1 C + min(W_{i+1}(v), kappa_1 v + min_{j= v_{J_K}: bound(v) = 6 C + W_{i+1}(v_{J_K}) (Bogomolny line 6 D <= h_0, W_{i+1} nondecreasing) with psi_k(j') = W_{i+1}(v_j') - kappa_k v_j' (W_{i+1} - kappa v' is piecewise linear, so its minimum over a range is attained at a node or at v' = v). Every bound is concave in v on the cell (g is concave), so the chord of W_i lies below it as soon as the two end values do. For each range the program may replace bound_k by the alternative 6 C + W_{i+1}(v_{J_{k-1}}) (6 C + W_{i+1}(v) for k = 1), valid for the same reason as the far bound; one of the two is chosen per (cell, range) and used at both end points. A cell may stop after range k and use 6 C + W_{i+1}(v_{J_k}) for all v' >= v_{J_k}. The nodal value w_{i,j} is DEFINED as the minimum of the lower-end bounds of cell j and the upper-end bounds of cell j-1 (rounded down), capped by Xi at the last node and made nondecreasing. The output is therefore valid by construction; the heuristics (ranges, multipliers) only influence its size. RESULT. E(U) >= W_0(v(tau_0)) >= w_{0,0}. PION MASS (mu > 0). The level-set inequality has the extra term V(tau) M(tau), V(tau) = 2 mu^2 (1 + cos tau) (decreasing): e(tau) >= alpha g(v(tau)) + beta c(tau) - (kappa - V(tau)) M(tau) for every minorant of h_kappa, kappa >= 0. On a piece of a step ending at s_m, V >= V_m := V(s_m), so the piece inequality holds with K_m = kappa_m - V_m in the place of kappa_m, and the refined lemma reads: for K >= 0 and multipliers kappa_m <= K + sigma A_m + V_m, int_{tau_i}^{tau_{i+1}} e >= (sum_m alpha_m D_m) g(v) + sum_m beta_m C_m - K (v' - v). Nothing else changes except the closed-form bound used at the last level, at the last node and beyond it: Xi_mu(tau, v) = 16 pi cos^2(tau/2) (r + mu r^2) (Lemma 3 of global/note_levelset.tex; concave, nondecreasing in v). mu is given as a decimal string and treated as the exact rational it denotes. usage: python3 step_cert.py [levels_mid] [q-1] [gamma0] [gammapi] [tau_a] [pi - tau_b] [v_min] [r_hi] [seconds] [P] [mu] (levels: dt = min((tau_b-tau_a)/levels_mid, gamma0 tau, gammapi (pi - tau)); with [seconds] the run stops after that time, writes a checkpoint and continues when the same command is issued again) """ import sys, os, math, json, time import numpy as np import ival as iv import lsb from ival import dn, up, PI_LO, PI_HI from lsb import K1, K2 HERE = os.path.dirname(os.path.abspath(__file__)) BOUNDS = np.array([1, 2, 3, 4, 6, 8, 11, 16, 23, 32, 45, 64, 91, 128, 181, 256, 362, 512, 724, 1024]) # cell offsets NSAMP = 7 GR = 0.6180339887498949 def Hhat_float(kap, g, c): """floating-point heuristic: relaxed per-level Hamiltonian min over areas A >= g of A conv(h_kap)(c/A)""" 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) has2 = (kap >= K2) | (kap <= K1) 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) Dt = np.where(has2, np.maximum((bt * bt - 20.0) / 16.0, 0.0), 0.0) gs = np.where(g > 0, g, 1.0) D0 = c / gs two = (~free) & has2 & (D0 <= Dt) Hf = c * 2.0 * (1.0 + 2.0 * Ds) / np.sqrt(Ds) H2 = 2.0 * sk * gs + bt * c H1 = gs * 2.0 * np.sqrt((1.0 + 2.0 * D0) * (D0 * D0 + 2.0 * D0 + kap)) return np.where(free, Hf, np.where(two, H2, H1)) def best_multiplier(Wn, Dn, g, c, dt, Vbar=0.0): """heuristic: maximiser over K >= 0 of Hhat(K + Vbar) dt + min_s [Wn[:, s] - K Dn[:, s]] (concave)""" m = Wn.shape[0] def phi(k): return Hhat_float(k + Vbar, g, c) * dt + (Wn - k[:, None] * Dn).min(axis=1) lo = np.full(m, math.log(1e-14)); hi = np.full(m, math.log(1e13)) x1 = hi - GR * (hi - lo); x2 = lo + GR * (hi - lo) f1 = phi(np.exp(x1)); f2 = phi(np.exp(x2)) for _ in range(44): left = f1 >= f2 hi = np.where(left, x2, hi); lo = np.where(left, lo, x1) x1 = hi - GR * (hi - lo); x2 = lo + GR * (hi - lo) f1 = phi(np.exp(x1)); f2 = phi(np.exp(x2)) k = np.exp(0.5 * (lo + hi)) k = np.where(phi(np.zeros(m)) >= phi(k), 0.0, k) return np.where(k < 1e-12, 0.0, k) def win_min(W, v, kap, a, b, ve): """RIGOROUS lower bound of min_{a <= j' <= b} [ W[j'] - kap (v[j'] - ve) ] (ve <= v[a], kap >= 0), per cell""" L = int((b - a).max()) + 1 idx = np.minimum(a[:, None] + np.arange(L)[None, :], b[:, None]) dvv = up(v[idx] - ve[:, None]) assert (dvv >= 0).all() vals = dn(W[idx] - up(kap[:, None] * dvv)) return vals.min(axis=1) def step(W, v, glo, gp_lo, sdt_lo, sC_lo, cap, stats, sV_lo=None): """one backward step: returns the nodal values of W_i (valid by construction). sdt_lo, sC_lo: lower bounds of the lengths of the P pieces of the step and of the integrals of c over them; gp_lo[j] <= g'(v_j); sV_lo (pion mass only): lower bounds 0 <= sV_lo[m] <= V(end of piece m).""" n = len(v) - 1 P = len(sdt_lo) # lower bound of the integral of c over the whole step: every term is lowered by the factor 1 - 1e-15, and the # rounding error of a floating-point sum of n positive terms is at most (n - 1) 2^-53 times the sum (n <= 8 here) assert P <= 8 C_lo = float(np.sum(dn(sC_lo * (1.0 - 1e-15)))) dt_lo = float(np.sum(sdt_lo)) # (floating point; used only by the heuristics) cbar = C_lo / dt_lo six_C = dn(6.0 * C_lo) Vbar = 0.0 if sV_lo is None else float(np.mean(sV_lo)) # (heuristics only) Blo = np.full(n, np.inf); Bup = np.full(n, np.inf) act = np.arange(n) # cells still active prev = act.copy() # J_{k-1} for the active cells frac = np.linspace(0.0, 1.0, NSAMP) for k, off in enumerate(BOUNDS): if len(act) == 0: break a_ = prev b_ = np.maximum(np.minimum(act + off, n), a_) # (a_ = b_ = n possible: single node) g0 = glo[act]; g1 = glo[act + 1] # ---- heuristic multiplier for this range (floating point; any kappa >= 0 is admissible) sidx = a_[:, None] + np.rint(frac[None, :] * (b_ - a_)[:, None]).astype(np.int64) kk = best_multiplier(W[sidx], v[sidx] - v[act][:, None], g0, cbar, dt_lo, Vbar) # ---- rigorous part: refined step lemma with P pieces (last piece first) sigma = gp_lo[b_] # <= g'(v_J), J = end node of the range abar = np.zeros(len(act)); bbar = np.zeros(len(act)); A = np.zeros(len(act)) for m in range(P - 1, -1, -1): km = dn(kk + dn(sigma * A)) # kappa_m <= kappa + sigma A_m if sV_lo is not None: km = dn(km + sV_lo[m]) # ... + V_m (pion mass) km = np.maximum(km, kk) alpha, beta, nfb = lsb.certified_minorant(km, g0, float(sC_lo[m] / sdt_lo[m])) # PROVED minorants stats['fallback'] += nfb ad = dn(alpha * sdt_lo[m]) abar = dn(abar + ad); bbar = dn(bbar + dn(beta * sC_lo[m])); A = dn(A + ad) base_lo = dn(dn(abar * g0) + bbar) base_up = dn(dn(abar * g1) + bbar) if k == 0: Tlo = win_min(W, v, kk, act, b_, v[act]) # includes j' = j, i.e. v' = v Tup = win_min(W, v, kk, act + 1, np.maximum(b_, act + 1), v[act + 1]) alt_lo = dn(six_C + W[act]); alt_up = dn(six_C + W[act + 1]) else: Tlo = win_min(W, v, kk, a_, b_, v[act]) Tup = win_min(W, v, kk, a_, b_, v[act + 1]) alt_lo = dn(six_C + W[a_]); alt_up = alt_lo m_lo = dn(base_lo + Tlo); m_up = dn(base_up + Tup) use = (m_lo >= alt_lo) & (m_up >= alt_up) # ONE branch per (cell, range), used at both end points stats['alt'] += int((~use).sum()); stats['ranges'] += len(act) Blo[act] = np.minimum(Blo[act], np.where(use, m_lo, alt_lo)) Bup[act] = np.minimum(Bup[act], np.where(use, m_up, alt_up)) # ---- can the cell stop here? far bound 6 C + W(v_{J_k}) for all v' >= v_{J_k} far = dn(six_C + W[b_]) done = (far >= Blo[act]) & (far >= Bup[act]) last = (k == len(BOUNDS) - 1) fin = done | (b_ >= n) | last Blo[act[fin]] = np.minimum(Blo[act[fin]], far[fin]); Bup[act[fin]] = np.minimum(Bup[act[fin]], far[fin]) if last: bad = ~done & (b_ < n) stats['unfinished'] += int(bad.sum()) if 'unf_log' in stats and bad.any(): # (diagnostics only) stats['unf_log'].append((int(bad.sum()), float(v[act[bad]].min()), float(v[act[bad]].max()))) act = act[~fin]; prev = b_[~fin] w = np.empty(n + 1) w[0] = Blo[0] w[1:n] = np.minimum(Blo[1:], Bup[:-1]) w[n] = min(Bup[n - 1], cap) w = np.minimum.accumulate(w[::-1])[::-1] # nondecreasing in v (lowering is allowed) if not np.all(np.isfinite(w)): raise FloatingPointError("non-finite nodal value") return w def make_levels(tau_a, tau_b, nmid, gamma0, gammapi): """levels with dt = min(dt_mid, gamma0 tau, gammapi (pi - tau))""" dt_mid = (tau_b - tau_a) / nmid taus = [tau_a] while taus[-1] < tau_b - 1e-12: t = taus[-1] dt = min(dt_mid, gamma0 * t, gammapi * (math.pi - t)) taus.append(min(t + dt, tau_b)) taus = np.array(taus) if taus[-1] - taus[-2] < 0.2 * (taus[-2] - taus[-3]): taus = np.delete(taus, -2) return taus def make_grid(v_min, qm1, v_hi): """v_j = v_min ((1+q)^j - 1)/q: spacing ~ v_min near 0, geometric (ratio 1+q) for large j""" nx = int(math.ceil(math.log1p(v_hi * qm1 / v_min) / math.log1p(qm1))) v = v_min * np.expm1(np.arange(nx + 1) * math.log1p(qm1)) / qm1 v[0] = 0.0 assert np.all(np.diff(v) > 0) return v def main(): nmid = int(sys.argv[1]) if len(sys.argv) > 1 else 150 qm1 = float(sys.argv[2]) if len(sys.argv) > 2 else 0.004 gamma0 = float(sys.argv[3]) if len(sys.argv) > 3 else 0.0167 gammapi = float(sys.argv[4]) if len(sys.argv) > 4 else 0.005 tau_a = float(sys.argv[5]) if len(sys.argv) > 5 else 0.1 eb = float(sys.argv[6]) if len(sys.argv) > 6 else 0.04 v_min = float(sys.argv[7]) if len(sys.argv) > 7 else 1e-5 r_hi = float(sys.argv[8]) if len(sys.argv) > 8 else 3000.0 budget = float(sys.argv[9]) if len(sys.argv) > 9 else 1e9 # seconds per invocation (checkpoint/resume) P = int(sys.argv[10]) if len(sys.argv) > 10 else 4 # pieces per step (refined step lemma) mu_str = sys.argv[11] if len(sys.argv) > 11 else "0" mu = iv.Fraction(mu_str) # exact rational value of the decimal string assert mu >= 0 massive = mu > 0 t0 = time.time() iv.selftest(); lsb.selftest() tau_b = math.pi - eb taus = make_levels(tau_a, tau_b, nmid, gamma0, gammapi) N = len(taus) - 1 assert taus[0] > 0 and taus[-1] < PI_LO and np.all(np.diff(taus) > 0) v = make_grid(v_min, qm1, 4.0 * math.pi / 3.0 * r_hi ** 3) n = len(v) - 1 glo = lsb.g_lower(v); rlo = lsb.r_lower(v) # every step is cut into P pieces (refined step lemma) fine = np.unique(np.concatenate([taus[:-1, None] + (taus[1:, None] - taus[:-1, None]) * (np.arange(P) / P)[None, :], taus[-1:, None]], axis=None)) assert len(fine) == N * P + 1 and np.all(fine[::P] == taus) sdt_lo = dn(fine[1:] - fine[:-1]).reshape(N, P) sC_lo = lsb.c_integral_lower(fine).reshape(N, P) assert np.all(sdt_lo > 0) and np.all(sC_lo > 0) two_thirds = lsb.iv.frac_enclosure(lsb.iv.Fraction(2, 3))[0] with np.errstate(divide='ignore', invalid='ignore'): gp_lo = np.where(v > 0, dn(dn(two_thirds * glo) / np.where(v > 0, v, 1.0)), 0.0) # <= g'(v) = (2/3) g(v)/v if massive: mu_lo = iv.frac_enclosure(mu)[0] Vfine = lsb.V_lower(fine, mu) # <= V at every fine level sV_lo = Vfine[1:].reshape(N, P) # piece m of step i ends at fine[i P + m + 1] assert np.all(sV_lo >= 0) xi = lambda tau, rr: lsb.xi_mu_lower(tau, rr, mu_lo) else: sV_lo = None xi = lsb.xi_lower W = xi(taus[-1], rlo) # W_N: nodal values <= Xi(tau_N, v_j); Xi concave in v assert np.all(np.diff(W) >= 0) and W[0] <= 0.0 print(f"levels {N} (dt_mid = {(tau_b - tau_a) / nmid:.2e}, gamma0 = {gamma0}, gammapi = {gammapi}), tau in [{tau_a}, pi - {eb}]; " f"{n} cells in v (ratio 1 + {qm1}), v_min = {v_min:g}, r_hi = {r_hi:g}; {P} pieces per step; mu = {mu_str}", flush=True) stats = dict(fallback=0, alt=0, ranges=0, unfinished=0) E0 = 12 * math.pi ** 2 probe = {} tag = f"{nmid}_{qm1:g}_{gamma0:g}_{gammapi:g}_P{P}" + (f"_mu{mu_str}" if massive else "") ck = os.path.join(HERE, f"step_cert_{tag}_ckpt.npz") start = N - 1 used = 0.0 if os.path.exists(ck): # resume (same grid and levels are rebuilt deterministically) d = np.load(ck, allow_pickle=True) assert len(d['W']) == n + 1 and int(d['N']) == N W = d['W']; start = int(d['next']); stats = d['stats'].item(); probe = d['probe'].item(); used = float(d['used']) print(f"resuming at level {start} (time used so far {used:.0f} s)", flush=True) for i in range(start, -1, -1): cap = float(xi(taus[i], rlo[n])) W = step(W, v, glo, gp_lo, sdt_lo[i], sC_lo[i], cap, stats, None if sV_lo is None else sV_lo[i]) if i % max(1, N // 12) == 0: probe[float(taus[i])] = float(W[0]) print(f" level {i:5d} tau = {taus[i]:.4f} W(tau, 0)/(12 pi^2) = {W[0] / E0:.6f} max W/E0 = {W[-1] / E0:.3f}" f" [{used + time.time() - t0:.0f} s]", flush=True) if time.time() - t0 > budget and i > 0: np.savez(ck, W=W, next=i - 1, N=N, stats=np.array(stats, dtype=object), probe=np.array(probe, dtype=object), used=used + time.time() - t0) print(f"checkpoint written at level {i} ({used + time.time() - t0:.0f} s); run the same command again", flush=True) return if os.path.exists(ck): os.remove(ck) assert np.all(np.diff(W) >= 0) assert float(xi(taus[0], rlo[n])) >= W[n] >= W[0] # maps with v(tau_a) > v_n: E >= Xi >= W_0(0) E0_hi = float(up(12.0 * up(PI_HI * PI_HI))) bound = float(dn(W[0] / E0_hi)) print(f"(cell, range) pairs {stats['ranges']}, Bogomolny alternatives {stats['alt']}, fallback minorants " f"{stats['fallback']}, cells that ran out of ranges {stats['unfinished']}") print(f"CERTIFIED (mu = {mu_str}): E(U) >= {W[0]!r} for every degree-1 map, i.e. I_1/(12 pi^2) >= {math.floor(bound * 1e6) / 1e6:.6f}" f" [{used + time.time() - t0:.0f} s]") out = dict(mu=mu_str, nmid=nmid, qm1=qm1, gamma0=gamma0, gammapi=gammapi, P=P, tau_a=tau_a, pi_minus_tau_b=eb, v_min=v_min, r_hi=r_hi, levels=int(N), cells=int(n), W00=float(W[0]), bound=bound, stats=stats, probe=probe, seconds=used + time.time() - t0) with open(os.path.join(HERE, f"step_cert_{tag}.json"), "w") as fh: json.dump(out, fh, indent=1) np.savez(os.path.join(HERE, f"step_cert_{tag}_start.npz"), v=v, W=W, tau_a=tau_a) if __name__ == "__main__": main()