#!/usr/bin/env python3
"""
PROVENANCE: PROOF

Computation 128 -- the KO split 10 = 4 + 6 is forced given the inputs; the only
undeived substrate-side choice is the odd-|D| parity  (open_research.md §7.1)
=============================================================================
Backs the §7.1 refined verdict on the minimal-KO-split principle. The Lorentzian
target is KO_total = 2 (mod 8) (the Connes value for the product spectral triple).
The substrate internal factor is forced to KO = 6 (Computation 3 / 19), conditional
on the parity-selected odd-|D| sub-limit. Given those two inputs, the spacetime KO
s satisfies s + 6 = 2 (mod 8), i.e. s = 4 (mod 8); among physical Mosco-limit
spacetime dimensions s in {0,...,7} the unique solution is s = 4, the next is 12.
So the split 10 = 4 + 6 is FORCED given (KO_internal = 6, target = 2 mod 8); the
residual minimality is only the lift (s = 4 over 12, 20, ...), itself fixed by the
Mosco limit producing the 4-dimensional M = R x S^3. The single genuinely undeived
substrate-side foundational choice is the odd-|D| parity restriction that fixes
KO = 6 -- a binary choice, not the mod-8 arithmetic.

CHECKS
------
  (1) Given f = 6 and target = 2 (mod 8), s in {0..7}: s = 4 unique (next s = 12).
      Spacetime KO-4 is the arithmetic complement 2 - 6 = 4 (mod 8), not independent.
  (2) Minimal total = 2 (mod 8) with f = 6 and spacetime s >= 1 is 10 = 4 + 6; next
      is 18 = 12 + 6. So '10 = 4+6 minimal' is forced given f = 6; the only residual
      is the lift s = 4 over 12.
  (3) Sensitivity: varying f flips the split (the part that is spacetime vs internal),
      so f = 6 (the odd-|D| parity) is the load-bearing undeived input, not the
      arithmetic, which is forced once f is fixed.
"""

def main():
    print("=" * 100)
    print("  Computation 128 -- KO split 10=4+6 forced given inputs; residual choice = odd-|D| parity (Sec 7.1)")
    print("=" * 100)
    print()
    target = 2   # KO_total = 2 (mod 8), Lorentzian Connes value for the product triple
    f = 6        # substrate internal KO, forced (Comp 3/19) on the odd-|D| sub-limit

    print(f"  Inputs: target KO_total = {target} (mod 8); internal KO f = {f} (Comp 3, odd-|D| sub-limit)")
    print()

    print("  (1) spacetime KO s with s + f = target (mod 8), s in {0..7}:")
    sols = [s for s in range(8) if (s + f) % 8 == target % 8]
    nxt = [s for s in range(16) if (s + f) % 8 == target % 8][1]
    print(f"      solutions in 0..7: {sols}    unique s = {sols[0]} ; next (s<16): {nxt}")
    p1 = (sols == [4])
    print(f"      -> spacetime KO-4 is the complement 2 - 6 = 4 (mod 8), forced given f: {p1}")
    print()

    print("  (2) minimal total = 2 (mod 8) with f = 6 and spacetime s >= 1:")
    ladder = [(s + f, s) for s in range(1, 40) if (s + f) % 8 == target % 8]
    print(f"      (total, s) ladder: {ladder[:4]}")
    p2 = (ladder[0] == (10, 4))
    print(f"      -> minimal split 10 = 4 + {f}; next {ladder[1][0]} = {ladder[1][1]} + {f}: {p2}")
    print(f"      residual minimality = the lift s = 4 over {ladder[1][1]}, fixed by Mosco -> M = R x S^3 (4-dim).")
    print()

    print("  (3) sensitivity to the odd-|D| parity (does f = 6 carry the split, or the arithmetic?):")
    for ff in (4, 5, 6, 7, 8):
        s = [x for x in range(8) if (x + ff) % 8 == target % 8][0]
        tag = "   <- selected (odd-|D| parity)" if ff == 6 else ""
        print(f"      f = {ff}: spacetime KO s = {s}  ->  total {s + ff} = {s} + {ff}{tag}")
    print(f"      -> the split (which factor is the 4-dim spacetime) flips with f; f = 6 is the undeived")
    print(f"         choice, the mod-8 arithmetic being forced once f is fixed.")
    print()

    print("=" * 100)
    print("  ASSESSMENT")
    print("=" * 100)
    print(f"  (1) KO-4 = arithmetic complement, forced given f = 6 & target = 2 : {p1}")
    print(f"  (2) 10 = 4 + 6 minimal given f = 6; residual = the lift s = 4 over 12 : {p2}")
    ok = p1 and p2
    print()
    print(f"  RESULT: {'CONFIRMS Sec 7.1 -- 10=4+6 forced given (f=6, target=2 mod 8); the only undeived substrate choice is the odd-|D| parity' if ok else 'MISMATCH'}")


if __name__ == "__main__":
    main()
