#!/usr/bin/env python3
"""N23 — J_CKM (row 23, DIAGNOSTIC). Standard library only. Added S363 under PI ruling R174-b (queue S349.R147a).
Reproduces the suite's J_read = 3.30e-5 from the four scored CKM formulas and compares it with SL-10 (PDG 2026 Eq. 12.27).
Naive comparator distance only; J is a function of four rows already scored, so nothing here is independent evidence."""
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")
V_us = math.sqrt((3.0 / (PHI**4 + 3.0)) / 6.0)          # Scorecard row 9 (Route B)
V_cb = 1.0 / (9.0 * math.sqrt(7.0))                     # Scorecard row 10 (DET-7)
V_ub = V_us * V_cb / math.sqrt(6.0)                     # Scorecard row 11
G7 = PHI + 5.0 * PHI**-5
delta = math.atan(math.sqrt(3.0 * G7))                  # Scorecard row 12a
s13 = V_ub; c13 = math.sqrt(1 - s13**2)
s12 = V_us / c13; c12 = math.sqrt(1 - s12**2)
s23 = V_cb / c13; c23 = math.sqrt(1 - s23**2)
J = s12 * s23 * s13 * c12 * c23 * c13**2 * math.sin(delta)
ref, up, lo = 3.16e-5, 0.13e-5, 0.11e-5                 # SL-10, PDG 2026 Eq. 12.27, +0.13/-0.11
off = J - ref; u = up if off > 0 else lo
print("=== row 23: J_CKM (DIAGNOSTIC) ===")
print("inputs: |V_us| = " + shown(V_us) + " · |V_cb| = " + shown(V_cb) + " · |V_ub| = " + shown(V_ub) + " · delta_CKM_deg = " + shown(math.degrees(delta), 6))
print("J_theory = " + format(J, ".6e") + "  (s12 s23 s13 c12 c23 c13^2 sin delta)")
print("J_comparator = 3.16e-05 +1.3e-06 / -1.1e-06  (SL-10, PDG 2026 Eq. 12.27)")
print("signed_percent = " + shown(100 * off / ref, 2, True) + "%")
print("uncertainty_used = " + format(u, ".1e") + " (" + ("upper" if off > 0 else "lower") + ")")
print("d_cmp = " + shown(off / u, 2, True))
print("status = DIAGNOSTIC — a function of rows 9, 10, 11, 12a; counted in no tally")
