#!/usr/bin/env python3
"""N14 — arithmetic from D1287 supplied sources.
No network, external packages, fitting operations or shared runtime files.
Printed source cells and unrounded arithmetic are distinct outputs.
"""

import math
from decimal import Decimal, ROUND_HALF_UP, getcontext
from fractions import Fraction

getcontext().prec = 40
PHI = (1.0 + math.sqrt(5.0)) / 2.0


def shown(value, places=9, signed=False):
    """Decimal half-up display; never use display-rounded inputs implicitly."""
    value = Decimal(str(value))
    rounded = value.quantize(Decimal(1).scaleb(-places), rounding=ROUND_HALF_UP)
    return format(rounded, ("+" if signed else "") + "." + str(places) + "f")

def main():
    print('=== row 14 ===')
    print('Scorecard (verbatim): b 1 , b 2 , b 3 41/10, −19/6, −7 theory exact experiment SM one-loop constants deviation 0 · d = exact no tier assigned —')
    values = (Fraction(41,10), Fraction(-19,6), Fraction(-7,1))
    reference = (Fraction(41,10), Fraction(-19,6), Fraction(-7,1))
    for i,(value,ref) in enumerate(zip(values,reference),1):
        assert value == ref
        print("b" + str(i) + " = " + str(value)
              + "; decimal = " + shown(float(value),12)
              + "; adopted_reference = " + str(ref)
              + "; signed_percent = 0%")
        print("inverse_alpha_slope_"+str(i)+" = "
              + shown(-float(value)/(2.0*math.pi),12))
    print("normalization = GUT hypercharge; alternative b1=41/6 is not used")
    print("d = exact (same adopted constants, not experimental distances)")
    print("loop_derivation = NOT IN SUITE (supplied excerpts do not provide it)")
    print()


if __name__ == "__main__":
    main()
