"""D1259 exact verification. All arithmetic is symbolic or rational.
Run without -O. No external data, network calls, floating-point tolerance, or
claim of equivalence to unavailable frozen programme arrays is used.
"""
import sympy as S
import platform
if not __debug__:
    raise SystemExit("Assertions require a run without -O.")
def report(key, value):
    print(key + " = " + str(value))
report("environment", "Python " + platform.python_version() + "; SymPy " + S.__version__)
report("arithmetic", "exact rationals / symbolic polynomials / algebraic radicals")

from itertools import product
R=S.Rational
# Polynomial proof in the quotient ring R[a]/(a^2-3a+1).
a=S.symbols("a")
p=S.Poly(a*a-3*a+1,a)
def rem(expr): return S.rem(S.Poly(S.expand(expr),a),p).as_expr().expand()
assert rem((a+1)**2/5-a)==0
assert rem((a+1)*(4-a)/5-1)==0
report("universal_square_root_residual",rem((a+1)**2/5-a))
report("universal_inverse_residual",rem((a+1)*(4-a)/5-1))
# A fully stated standard 2x2 realization is a negative/control model,
# NOT a replacement for the missing frozen-frame intertwiners.
U=S.Matrix([[1,1],[0,1]])
V=S.Matrix([[1,0],[-1,1]])
Om=S.Matrix([[0,1],[-1,0]])
A=U*V.inv()
H=(A+S.eye(2))/S.sqrt(5)
assert U*V*U==V*U*V
assert U.T*Om*U==V.T*Om*V==Om
assert (U*V)**3==-S.eye(2)
assert A*A-3*A+S.eye(2)==S.zeros(2)
assert S.simplify(H*H-A)==S.zeros(2)
assert S.simplify(H.T*Om*H-Om)==S.zeros(2)
assert S.simplify(H.det())==1
report("model_U",U.tolist());report("model_V",V.tolist())
report("model_hyperbolic_word",A.tolist())
report("model_word_characteristic",A.charpoly().as_expr())
report("model_braid_residual_zero",True)
report("model_central_cube",(U*V)**3)
report("model_square_root",H.tolist())
report("model_root_trace_and_determinant",(S.simplify(S.trace(H)),S.simplify(H.det())))
# Formal Clifford identities in an explicit simple component.
g0=S.diag(1,-1);g1=S.Matrix([[0,1],[1,0]]);k0=g0*g1
gs=[g0,g1,k0]
assert g0*g0==g1*g1==S.eye(2) and k0*k0==-S.eye(2)
assert all(gs[i]*gs[j]+gs[j]*gs[i]==S.zeros(2) for i in range(3) for j in range(i))
report("model_Clifford_squares",["I","I","-I"])
# The all-T Gram law is proved by these matrix identities; a symbolic
# arbitrary two-row T tests the complete bilinear polynomial in this block.
v0,v1,v2,v3,v4,v5=S.symbols("v0:6")
T=S.Matrix([[v0,v1,v2],[v3,v4,v5]])
Ws=[g0/S.sqrt(24),g1/S.sqrt(24)]
G=S.Matrix(2,2,lambda i,j:S.expand(S.trace((Ws[i]*T).T*(Ws[j]*T))))
rhs=sum(x*x for x in T)/24*S.eye(2)
assert G==rhs
report("symbolic_model_Gram_residual_zero",True)
# Clifford relations alone are not invariant statements about a fixed
# Euclidean Frobenius metric under non-orthogonal similarity.
C=S.diag(2,1)
g1bad=C*g1*C.inv()
assert g1bad*g1bad==S.eye(2)
assert g0*g1bad+g1bad*g0==S.zeros(2)
Tb=S.Matrix([1,0])
badWs=[g0/S.sqrt(24),g1bad/S.sqrt(24)]
Gbad=S.Matrix(2,2,lambda i,j:((badWs[i]*Tb).T*(badWs[j]*Tb))[0])
assert Gbad==S.diag(R(1,24),R(1,96))
report("nonorthogonal_Clifford_control_Gram",Gbad.tolist())
report("Clifford_relations_alone_force_Frobenius_isotropy",False)
# If the registered decomposition is supplied, this implication pads it.
copies=12;inactive=32
Uc=S.diag(*([U]*copies+[S.eye(inactive)]))
Vc=S.diag(*([V]*copies+[S.eye(inactive)]))
P=S.diag(*([1]*(2*copies)+[0]*inactive))
centre=(Uc*Vc)**3
assert centre==S.eye(56)-2*P
assert centre != S.eye(56) and centre != -S.eye(56)
report("conditional_model_active_inactive_dimensions",(2*copies,inactive))
report("conditional_model_central_eigenvalue_multiplicities",{-1:2*copies,1:inactive})
report("conditional_model_global_projectivization_to_PSL2Z",False)
report("unit_column_Gram_coefficients",{1:R(1,24),10:R(10,24)})
# Z4 arithmetic: not a census of the programme's generator products.
tests=0
for x,y in product(range(4),repeat=2):
    assert (-(x+y))%4==((-x)%4+(-y)%4)%4
    tests+=1
report("Z4_arithmetic_mirror_checks",tests)
report("Z4_checks_are_registered_generator_census",False)
report("registered_frame_tick_cylinder_winding_scale","NOT VERIFIED: frozen matrices / cochain complex absent")
report("result","PASS: universal polynomial implications and explicitly marked standard models")
