"""Exact interval check of a four-state Mpemba witness with rational data. Input: a JSON file with rational strings E : four energies 0 = E_1 < E_2 < E_3 < E_4, beta_b : bath inverse temperature, beta_h, beta_c : initial inverse temperatures, 0 <= beta_h < beta_c < beta_b, d : symmetric conductances d12, d13, d14, d23, d24, d34 (> 0), mu_brackets : three rational intervals claimed to contain the nonzero eigenvalues of M (each is verified by a strict sign change). Rates (rate j -> i): a_ij = exp(-beta_b E_i) d_ij, so detailed balance holds exactly. Every exponential is enclosed by a rigorous rational interval (alternating Taylor series plus repeated squaring, outward rounding to a dyadic grid), and every later step uses outward interval arithmetic over fractions.Fraction. All decisions raise exceptions (active under python -O). Usage: python check_robust_four_state.py [witness.json] [receipt.json] (default witness: robust_witness.json beside this script; the receipt is printed and, if a second path is given, written there). Python standard library only. """ from fractions import Fraction as F from itertools import permutations, combinations from pathlib import Path import hashlib import json import sys import time GRID = F(1, 2**320) # outward rounding grid for all interval endpoints def require(condition, message): if not condition: raise ValueError(message) def down(x): return F((x / GRID).__floor__()) * GRID def up(x): return F((x / GRID).__ceil__()) * GRID class I: """Closed interval [lo, hi] with rational endpoints, outward rounded.""" def __init__(self, lo=0, hi=None): if isinstance(lo, I): self.lo, self.hi = lo.lo, lo.hi return lo = F(lo) hi = lo if hi is None else F(hi) require(lo <= hi, "reversed interval") self.lo, self.hi = lo, hi @staticmethod def rnd(lo, hi): return I(down(lo), up(hi)) def __add__(self, o): o = I(o) return I.rnd(self.lo + o.lo, self.hi + o.hi) __radd__ = __add__ def __neg__(self): return I(-self.hi, -self.lo) def __sub__(self, o): return self + (-I(o)) def __rsub__(self, o): return I(o) - self def __mul__(self, o): o = I(o) p = [a * b for a in (self.lo, self.hi) for b in (o.lo, o.hi)] return I.rnd(min(p), max(p)) __rmul__ = __mul__ def __truediv__(self, o): o = I(o) require(o.lo > 0 or o.hi < 0, "division by an interval containing zero") return self * I.rnd(min(1 / o.lo, 1 / o.hi), max(1 / o.lo, 1 / o.hi)) def __rtruediv__(self, o): return I(o) / self def pos(self): return self.lo > 0 def neg(self): return self.hi < 0 def width(self): return self.hi - self.lo def exp_neg(y): """Rigorous enclosure of exp(-y) for rational y >= 0.""" y = F(y) require(y >= 0, "exp_neg needs y >= 0") k = 0 while y / 2**k > F(1, 8): k += 1 z = y / 2**k # 0 <= z <= 1/8: the terms z^n/n! decrease, so exp(-z) lies between # consecutive partial sums of the alternating series. term, s, n = F(1), F(1), 0 while True: n += 1 term = -term * z / n s_next = s + term if abs(term) < GRID / 4: lo, hi = min(s, s_next), max(s, s_next) break s = s_next r = I(down(lo), up(hi)) for _ in range(k): r = r * r # positive interval: squaring is monotone require(r.lo > 0, "exp enclosure not positive") return r def parity(p): n = len(p) return -1 if sum(p[i] > p[j] for i in range(n) for j in range(i + 1, n)) % 2 else 1 def det(a): n = len(a) total = I(0) for p in permutations(range(n)): term = I(parity(p)) for i in range(n): term = term * a[i][p[i]] total = total + term return total def pmul(a, b): c = [I(0)] * (len(a) + len(b) - 1) for i, x in enumerate(a): for j, y in enumerate(b): c[i + j] = c[i + j] + x * y return c def charpoly(m): """Interval enclosures of the coefficients of det(zI - m), ascending.""" n = len(m) res = [I(0)] * (n + 1) for p in permutations(range(n)): term = [I(parity(p))] for i in range(n): term = pmul(term, [-m[i][p[i]], I(1)] if i == p[i] else [-m[i][p[i]]]) for k, c in enumerate(term): res[k] = res[k] + c return res def peval(coeffs, x): v = I(0) for c in reversed(coeffs): v = v * x + c return v def dec(x, digits=12): """Outward decimal rendering of an interval (strings).""" s = 10**digits lo = F((x.lo * s).__floor__(), s) hi = F((x.hi * s).__ceil__(), s) return [str(lo), str(hi)] if lo.denominator == 1 and hi.denominator == 1 else [ format_fraction(lo, digits), format_fraction(hi, digits)] def format_fraction(v, digits): sign = "-" if v < 0 else "" v = abs(v) whole = v.numerator // v.denominator frac = v - whole return f"{sign}{whole}.{str((frac * 10**digits).numerator // (frac * 10**digits).denominator).zfill(digits)}" def main(path, out=None): t0 = time.perf_counter() raw = json.loads(Path(path).read_text(encoding="utf-8")) E = [F(v) for v in raw["E"]] bb, bh, bc = F(raw["beta_b"]), F(raw["beta_h"]), F(raw["beta_c"]) pairs = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] d = dict(zip(pairs, [F(v) for v in raw["d"]])) require(len(E) == 4 and E[0] == 0 and all(E[i] < E[i + 1] for i in range(3)), "energies must satisfy 0 = E1 < E2 < E3 < E4") require(0 <= bh < bc < bb, "need 0 <= beta_h < beta_c < beta_b") require(all(v > 0 for v in d.values()), "conductances must be positive") q = [exp_neg(bb * e) for e in E] # e^{-beta_b E_i} # m[i][j] = rate j -> i = q_i d_ij (i != j); the diagonal makes columns sum to zero. m = [[I(0)] * 4 for _ in range(4)] for (i, j), dij in d.items(): m[i][j] = q[i] * dij m[j][i] = q[j] * dij for j in range(4): s = I(0) for i in range(4): if i != j: s = s + m[i][j] m[j][j] = -s # Triplet tests, Eq. (3) of arXiv:2603.04567, with the original rates. trip = [] for u, v, w in combinations(range(4), 3): x, y, z = m[u][v], m[u][w], m[v][w] # a_{-0}, a_{-+}, a_{0+} s = exp_neg(bb * (E[v] - E[u])) # e^{-beta_b Delta_{0-}} cpm = 1 + exp_neg(bb * (E[w] - E[u])) * F(1, 2) cp0 = 1 + exp_neg(bb * (E[w] - E[v])) * F(1, 2) kappa = (y + z) / (x * (1 + s)) r1 = y * cpm - z * cp0 - x * (1 - s) r2 = y * s - z require(kappa.lo > 1 or kappa.hi < 1, "kappa interval contains 1: branch not decided") branch = 1 if kappa.lo > 1 else 2 rel = r1 if branch == 1 else r2 require(rel.neg(), f"triplet {u+1}{v+1}{w+1}: failure of the test not certified") scale_hi = max(x.hi, y.hi, z.hi) margin_lo = -rel.hi / scale_hi # lower bound on -residual / max rate trip.append({"triplet": f"{u+1}{v+1}{w+1}", "kappa": dec(kappa, 8), "branch": "kappa>1, first line" if branch == 1 else "kappa<1, second line", "residual": dec(rel, 10), "residual_other_line": dec(r2 if branch == 1 else r1, 10), "relative_margin_lower_bound": format_fraction(F((margin_lo * 10**8).__floor__(), 10**8), 8)}) # Spectrum. Columns of M sum to zero, so det(zI-M) = z f(z) with f monic # cubic whose coefficients are enclosed by c_1, ..., c_4. cp = charpoly(m) require(cp[0].lo <= 0 <= cp[0].hi, "constant coefficient enclosure must contain 0") f = cp[1:] brackets = [] for lo, hi in raw["mu_brackets"]: a, b = F(lo), F(hi) fa, fb = peval(f, I(a)), peval(f, I(b)) require((fa.pos() and fb.neg()) or (fa.neg() and fb.pos()), f"no certified sign change on [{lo}, {hi}]") brackets.append(I(a, b)) brackets.sort(key=lambda r: -r.hi) require(brackets[0].hi < 0 and all(brackets[i + 1].hi < brackets[i].lo for i in range(2)), "eigenvalue brackets not disjoint and negative") # A cubic has at most three roots: each bracket holds exactly one, all simple. mu2 = brackets[0] # Slow left eigenvector: (M^T - mu2 I) l = 0 with l_k = 1, by interval Cramer. k = int(raw.get("ell_fixed_index", 0)) B = [[m[j][i] - (mu2 if i == j else 0) for j in range(4)] for i in range(4)] J = [i for i in range(4) if i != k] BJJ = [[B[i][j] for j in J] for i in J] rhs = [-B[i][k] for i in J] den = det(BJJ) require(den.pos() or den.neg(), "Cramer denominator not certified nonzero") ell = [None] * 4 ell[k] = I(1) for col, j in enumerate(J): rep = [[rhs[r] if c == col else BJJ[r][c] for c in range(3)] for r in range(3)] ell[j] = det(rep) / den def thermal(beta): w = [exp_neg(beta * e) for e in E] z = w[0] + w[1] + w[2] + w[3] return [wi / z for wi in w] ph, pc = thermal(bh), thermal(bc) bhot = ell[0] * ph[0] + ell[1] * ph[1] + ell[2] * ph[2] + ell[3] * ph[3] bcold = ell[0] * pc[0] + ell[1] * pc[1] + ell[2] * pc[2] + ell[3] * pc[3] diff = (ell[0] * (pc[0] - ph[0]) + ell[1] * (pc[1] - ph[1]) + ell[2] * (pc[2] - ph[2]) + ell[3] * (pc[3] - ph[3])) require(bhot.pos() or bhot.neg(), "sign of b(beta_h) not certified") require(bcold.pos() or bcold.neg(), "sign of b(beta_c) not certified") require(bhot.pos() == bcold.pos(), "b(beta_h), b(beta_c) of opposite sign: not handled") sgn = 1 if bcold.pos() else -1 absgap = diff * sgn # = |b_c| - |b_h| require(absgap.pos(), "|b(beta_c)| > |b(beta_h)| not certified") rel_h = absgap / (bhot * sgn) rel_c = absgap / (bcold * sgn) # Diagnostics for the mechanism discussion (not part of the Mpemba claim). # (a) escape rate of the ground level versus |lambda_2|; # (b) triplet 234 tested with the lambda_2-renormalised rates obtained by # eliminating level 1: a~_ji = a_ji + a_j1 a_1i / (gamma_1 + lambda_2). gamma1 = -m[0][0] g_plus_mu = gamma1 + mu2 require(g_plus_mu.neg(), "diagnostic: gamma_1 + lambda_2 < 0 not certified") def ren(i, j): # renormalised rate j -> i, i, j in {2,3,4} return m[i][j] + m[i][0] * m[0][j] / g_plus_mu xr, yr, zr = ren(1, 2), ren(1, 3), ren(2, 3) sr = exp_neg(bb * (E[2] - E[1])) kr = (yr + zr) / (xr * (1 + sr)) r2r = yr * sr - zr require(kr.hi < 1 and r2r.pos(), "diagnostic: renormalised triplet 234 does not pass the second line") receipt = { "status": "PASS", "input": raw, "arithmetic": "fractions.Fraction intervals, outward rounding to multiples of 2^-320; " "exp(-y) by alternating Taylor series and repeated squaring", "triplets": trip, "max_width_cubic_coefficients": f"{float(max(c.width() for c in f)):.3e}", "eigenvalue_brackets_tau_units": [dec(r, 12) for r in brackets], "cramer_denominator": dec(den, 10), "ell_fixed_index_0based": k, "ell": [dec(v, 12) for v in ell], "b_hot": dec(bhot, 12), "b_cold": dec(bcold, 12), "abs_b_cold_minus_abs_b_hot": dec(absgap, 12), "relative_gap_over_abs_b_hot": dec(rel_h, 8), "relative_gap_over_abs_b_cold": dec(rel_c, 8), "diagnostic_gamma1": dec(gamma1, 10), "diagnostic_gamma1_plus_lambda2": dec(g_plus_mu, 10), "diagnostic_renormalised_234_kappa": dec(kr, 8), "diagnostic_renormalised_234_second_line_residual": dec(r2r, 10), "seconds": round(time.perf_counter() - t0, 3), "script_sha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), } text = json.dumps(receipt, indent=2) + "\n" if out: Path(out).write_text(text, encoding="utf-8") print(text) if __name__ == "__main__": default = Path(__file__).with_name("robust_witness.json") main(sys.argv[1] if len(sys.argv) > 1 else default, sys.argv[2] if len(sys.argv) > 2 else None)