#!/usr/bin/env python3
"""AP44 -- "The Snap" -- independent verification script.

Reproduces, from CODATA 2022 alone, the Newton's-G fork on lucid.rodeo/prereg/ap44/:
structural G (AP28, provisioned) and realised G (AP44, LOCKED 2026-08-11).

No dependencies beyond the Python 3 standard library. No network access.

    python3 verify_ap44.py

Formulas are quoted verbatim from ap44/AP44_The_Snap_FINAL_v1_0.docx in
github.com/ajgreyling/the420code-proof (tag ap44-locked-2026-08-11):
  structural: G = alpha_em^21 * (1 + 1/pi) * hbar*c / m_e^2
  realised:   G = alpha_em^21 * (1 + 1/pi) / (1 + alpha_em) * hbar*c / m_e^2
            = structural / (1 + alpha_em)
"""
from __future__ import annotations

import math

# --------------------------------------------------------------------------- #
# CODATA 2022 -- the only measured inputs
# --------------------------------------------------------------------------- #
ALPHA = 7.2973525643e-3       # fine-structure constant
HBAR = 1.054571817e-34        # reduced Planck constant, J*s
C = 299792458.0               # speed of light, m/s (exact by SI definition)
M_E = 9.1093837139e-31        # electron mass, kg
G_CODATA = 6.67430e-11        # Newton's constant, CODATA 2022 centre, N*m^2/kg^2


def structural_g(alpha: float = ALPHA, hbar: float = HBAR, c: float = C, m_e: float = M_E) -> float:
    return alpha ** 21 * (1 + 1 / math.pi) * hbar * c / m_e ** 2


def realised_g(alpha: float = ALPHA, hbar: float = HBAR, c: float = C, m_e: float = M_E) -> float:
    return structural_g(alpha, hbar, c, m_e) / (1 + alpha)


def pct(value: float, measured: float) -> float:
    return (value - measured) / measured * 100


def ppm(value: float, measured: float) -> float:
    return (value - measured) / measured * 1e6


def main() -> int:
    g_struct = structural_g()
    g_real = realised_g()

    bar = "=" * 76
    print(bar)
    print("AP44 -- The Snap -- independent verification (CODATA 2022, stdlib only)")
    print(bar)

    print("\nStructural G (AP28, provisioned) -- LOCKED as part of AP44's fork:")
    print(f"  G = alpha^21 * (1 + 1/pi) * hbar*c / m_e^2")
    print(f"  = {g_struct:.11e} N*m^2/kg^2")
    print(f"  vs CODATA 2022 = {G_CODATA:.5e}   residual = {pct(g_struct, G_CODATA):+.4f}%"
          f"  ({ppm(g_struct, G_CODATA):+.1f} ppm)")

    print("\nRealised G (AP44 'The Snap') -- LOCKED 2026-08-11:")
    print(f"  G = structural / (1 + alpha)")
    print(f"  = {g_real:.11e} N*m^2/kg^2")
    print(f"  vs CODATA 2022 = {G_CODATA:.5e}   residual = {pct(g_real, G_CODATA):+.4f}%"
          f"  ({ppm(g_real, G_CODATA):+.1f} ppm)")

    print("\nWatch line -- KS-CCC.3 (not this script's business to adjudicate):")
    print("  Dies if metrology settles near structural (~6.7206e-11).")
    print("  Confirms/strengthens if metrology migrates toward realised (~6.6719e-11).")
    print("  Stays a fork -- as claimed -- while it sits near 6.6743e-11 (CODATA centre).")

    print(f"\n{bar}")
    print("Both rows are independently reproduced from the paper's own stated formulas.")
    print("No kill switch fires on either row from this script alone -- KS-CCC.3 is a")
    print("watch line on future metrology, not something this script can trigger.")
    print(bar)

    # This script doesn't adjudicate a kill switch -- it only checks that the two
    # numbers still reproduce from the stated formulas at today's CODATA constants.
    # A mismatch here would mean the formula transcription itself is wrong.
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
