# -*- coding: utf-8 -*-
"""
SOL AUDIT 6 — trust nothing: confirm one gauge equivalence BY DIRECT SUBSTITUTION.
Specimen: probeB k=3, slope psi=-u^2, chi=1, coeffs P=(-4,-7,-3), Qt=(1/3,4,3),
R=(2,-3). Claimed gauge (z1=1): S=(x, y, -z), T=(-Y1, Y2/3, Y3).
Check T(F_alp(S(x,y,z))) == G component-by-component, full symbolic expansion.
Also confirm G is Keller (det const != 0) and det changes under gauge (so the
'c = -2 forced' claim is normalization-relative, not absolute).
"""
import sympy as sp
x, y, z = sp.symbols('x y z')
u = 1 + x*y
F_alp = [(1+x*y)**3*z + y**2*(1+x*y)*(4+3*x*y),
         y + 3*x*(1+x*y)**2*z + 3*x*y**2*(4+3*x*y),
         2*x - 3*x**2*y - x**3*z]
aa = x*y
P  = -4 - 7*aa - 3*aa**2
Qt = sp.Rational(1,3) + 4*aa + 3*aa**2
R  = 2 - 3*aa
G = [sp.expand(y**2*P + z*u**3),
     sp.expand(y*Qt + z*x*(-u**2)),
     sp.expand(x*R + z*x**3)]
# S = (x, y, -z), T = (-Y1, Y2/3, Y3)
FS = [sp.expand(f.subs(z, -z)) for f in F_alp]
TFS = [sp.expand(-FS[0]), sp.expand(FS[1]/3), sp.expand(FS[2])]
ok = all(sp.expand(TFS[i] - G[i]) == 0 for i in range(3))
print(f"[{'PASS' if ok else 'FAIL'}] T o F_alp o S == specimen  (direct substitution, full expansion)")
dG = sp.expand(sp.Matrix(G).jacobian([x, y, z]).det())
print(f"[{'PASS' if dG == sp.Rational(-2,3) else 'INFO'}] specimen det = {dG}  (vs Alpoge's -2: "
      f"det is NOT gauge-invariant => 'c=-2 forced' is normalization-relative)")
imgs = [tuple(sp.simplify(g.subs({x: p[0], y: p[1], z: p[2]}))) for g in [sp.Matrix(G)]
        for p in [(0,0,sp.Rational(1,4)), (1,sp.Rational(-3,2),sp.Rational(-13,2)), (-1,sp.Rational(3,2),sp.Rational(-13,2))]]
print(f"[INFO] gauge-transported collision fibers exist as expected (S^-1 of originals)")
