"""
WIN-COLUMN conversion #3 (the hard one) — QFT/QED's electron g-2 to 12 digits.
The most precise theory-experiment agreement in science. Do NOT fake this.

The honest question: what does DFD actually have?
  * QED computes a_e = (g-2)/2 as a 5-loop series in alpha. It matches experiment to ~12 digits.
    BUT QED takes alpha as INPUT -- in practice a_e IS the most precise alpha-meter. The 12-digit
    agreement tests the LOOP STRUCTURE with alpha floated.
  * DFD's gauge sector = QED (SM emerges from M7=CP2xS3), so DFD INHERITS the identical loop series
    => it reproduces the same a_e. The 12-digit result is therefore not SOLELY QFT's.
  * DFD's distinctive edge: it DERIVES alpha^-1 = 137.03599985 from topology (corpus, -0.006 ppm),
    so a_e becomes a PARAMETER-FREE prediction -- something QED structurally cannot do.
  * Honesty-guard the other way: DFD does NOT reach 12 digits. Its alpha is good to ~6 ppb and it does
    not re-derive the loop coefficients from psi. So the 12-digit precision stays QED's machinery.
Grade target: TIE-by-inheritance (+ DFD parameter-free edge), NOT a manufactured DFD-WIN.
"""
import numpy as np

PI = np.pi
# QED mass-independent (A1) coefficients of a_e in powers of (alpha/pi)
C = [0.5,                       # Schwinger 1-loop
     -0.328478965579137,        # 2-loop
     1.181234016828,            # 3-loop
     -1.91298,                  # 4-loop (Laporta/Kinoshita)
     6.737]                     # 5-loop (Aoyama-Hayakawa-Kinoshita-Nio)
# small additions to a_e: mass-dependent (mu,tau loops) + hadronic + electroweak  [x10^-12]
SMALL = (2.748 + 1.6993 + 0.03053) * 1e-12

def a_e(alpha_inv):
    a = 1.0/alpha_inv
    x = a/PI
    series = sum(C[n]*x**(n+1) for n in range(len(C)))
    return series + SMALL

# inputs
ainv_codata = 137.035999084      # CODATA / a_e-extracted alpha (the input QED actually uses)
ainv_dfd    = 137.03599985       # DFD DERIVED (minimal faithful real-bimodule theorem, corpus)
a_e_exp     = 1.15965218059e-3   # measured (Fan, Gabrielse 2023), unc 0.13e-12

print("="*74)
print("WIN-COLUMN #3 — QFT/QED electron g-2 (the most precise prediction in science)")
print("="*74)
ae_c = a_e(ainv_codata)
ae_d = a_e(ainv_dfd)
print(f"\n  a_e (experiment, Fan-Gabrielse 2023) = {a_e_exp:.14f}  (+/- 0.13e-12)")
print(f"  a_e (QED 5-loop, alpha=CODATA)       = {ae_c:.14f}   <- 12-digit agreement (QFT's win)")
print(f"  a_e (DFD, derived alpha=137.03599985)= {ae_d:.14f}   <- PARAMETER-FREE prediction")

# precision accounting
dalpha_rel = (ainv_dfd - ainv_codata)/ainv_codata      # relative alpha error of DFD
print("\n  Precision accounting:")
print(f"    DFD alpha^-1 error vs experiment   = {1e6*(ainv_dfd-ainv_codata)/ainv_codata:+.4f} ppm "
      f"({1e9*(ainv_dfd-ainv_codata)/ainv_codata:+.2f} ppb)")
print(f"    => DFD a_e prediction error        = {1e9*(ae_d-ae_c)/ae_c:+.2f} ppb "
      f"({(ae_d-ae_c):+.2e} absolute)")
print(f"    experiment a_e precision           = {1e9*0.13e-12/a_e_exp:.2f} ppb")
print(f"    => DFD predicts a_e parameter-free to ~{abs(1e9*(ae_d-ae_c)/ae_c):.0f} ppb "
      f"(~{int(-np.log10(abs((ae_d-ae_c)/ae_c)))} significant figures), limited purely by its alpha.")

print("\n  Who can predict a_e from NOTHING (no fitted input)?")
print("    QED : NO  -- needs alpha as input; in fact a_e is QED's best alpha-meter.")
print("    DFD : YES -- derives alpha from M7 topology, then inherits QED's loop series.")

print("\n" + "="*74)
print("VERDICT (honesty-guard both ways):")
print("  * The 12-DIGIT precision and the 5-loop coefficients are QED's machinery. DFD INHERITS")
print("    them (its gauge sector IS QED) and reproduces the identical a_e -> the result is no")
print("    longer SOLELY QFT's. That demotes the item to a TIE.")
print("  * DFD adds a real edge QED lacks: it DERIVES alpha (6 ppb), making a_e a PARAMETER-FREE")
print("    prediction to ~8-9 sig figs. QED cannot predict a_e from nothing.")
print("  * Honest deficit: DFD does NOT reach 12 digits (alpha only 6 ppb; loop coeffs inherited,")
print("    not re-derived from psi). So this is NOT a clean DFD-WIN.")
print("  GRADE: TIE-by-inheritance (+ DFD parameter-free edge). QFT's column item -> not solely theirs.")
