#!/usr/bin/env python3
"""N24 — J_PMNS (row 24, DIAGNOSTIC; the comparator band includes zero). Standard library only. Added S363 under PI ruling
R174-b (queue S349.R147b). Reproduces the suite's J_CP = -0.0107 from the four printed PMNS formulas and compares it with SL-31
(house MC over NuFIT 6.1 NH, correlations ignored; 16-84 band [-0.0286, +0.0022]). The comparator itself is 0.94 sigma from zero,
so no d printed here is a constraint."""
import math
from decimal import Decimal, ROUND_HALF_UP
PHI = (1.0 + math.sqrt(5.0)) / 2.0
def shown(v, p=9, signed=False):
    d = Decimal(repr(v)).quantize(Decimal(1).scaleb(-p), rounding=ROUND_HALF_UP)
    return format(d, ("+" if signed else "") + "." + str(p) + "f")
s12sq = 3.0 / (PHI**4 + 3.0)            # Scorecard row 4
s13sq = (3.0 - 2.0 * math.sqrt(2.0)) / 8.0   # Scorecard row 6
s23sq = 7.0 / 16.0                      # Scorecard row 5
dcp = -2.0 * math.pi / math.sqrt(5.0)   # Scorecard row 7
J = math.sqrt(s12sq*(1-s12sq)*s23sq*(1-s23sq)*s13sq) * (1 - s13sq) * math.sin(dcp)
ref, sig, lo, hi = -0.0140, 0.0149, -0.0286, 0.0022   # SL-31
print("=== row 24: J_PMNS (DIAGNOSTIC; comparator band includes zero) ===")
print("inputs: sin2_12 = " + shown(s12sq) + " · sin2_13 = " + shown(s13sq) + " · sin2_23 = " + shown(s23sq) + " · delta_CP_deg = " + shown(math.degrees(dcp), 6))
print("J_theory = " + shown(J, 6, True))
print("J_comparator = -0.0140 +/- 0.0149  (SL-31, house MC over NuFIT 6.1 NH, correlations ignored)")
print("comparator_band_16_84 = [" + shown(lo, 4, True) + ", " + shown(hi, 4, True) + "]  includes_zero = " + str(lo < 0 < hi))
print("comparator_distance_from_zero = " + shown(abs(ref) / sig, 2) + " sigma")
print("d_cmp = " + shown((J - ref) / sig, 2, True) + "  — consistent with the data AND with CP conservation; not a constraint")
print("status = DIAGNOSTIC — a function of rows 4, 5, 6, 7; counted in no tally; becomes a constraint only when the band excludes zero")
