"""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 combinations,product
# Standard root-system identification control. These are NOT the programme's
# tangent-plane matrices or a re-expression of their output.
D=S.Matrix([[2,-1,0,0],[-1,2,-1,-1],[0,-1,2,0],[0,-1,0,2]])
G=S.Matrix([[2,-1],[-3,2]])
GG=S.diag(G,G)
def roots(C):
    n=C.rows
    seen={tuple(int(i==j) for i in range(n)) for j in range(n)}
    todo=list(seen)
    while todo:
        v=todo.pop()
        for i in range(n):
            w=list(v)
            w[i]-=sum(C[i,j]*v[j] for j in range(n))
            w=tuple(w)
            if w not in seen:
                seen.add(w);todo.append(w)
        if len(seen)>10000: raise RuntimeError("Non-finite root closure")
    return seen
def components(C):
    unseen=set(range(C.rows));out=[]
    while unseen:
        seed=min(unseen);q=[seed];got=set()
        while q:
            j=q.pop()
            if j in got: continue
            got.add(j)
            q.extend(i for i in range(C.rows) if i not in got and (C[i,j] or C[j,i]))
        unseen-=got;out.append(sorted(got))
    return out
RD=roots(D); RG=roots(GG)
assert len(RD)==len(RG)==24
assert len(components(D))==1 and len(components(GG))==2
# For a split semisimple real form: one compact direction per positive
# root, and a split Cartan plus one noncompact direction per positive root.
def fingerprint(C,rr):
    rank=C.rows;positive=len(rr)//2
    return {"rank":rank,"dimension":rank+len(rr),
            "compact_dimension":positive,"noncompact_dimension":rank+positive,
            "Cartan_character":rank,"center_dimension":0}
fd=fingerprint(D,RD);fg=fingerprint(GG,RG)
assert fd==fg
report("object","root-data control for identification fingerprints, not frozen complement")
report("D4_Cartan_matrix",D.tolist())
report("G2_plus_G2_Cartan_matrix",GG.tolist())
report("root_counts",(len(RD),len(RG)))
report("identical_split_fingerprints",fd)
report("Dynkin_component_counts",(len(components(D)),len(components(GG))))
report("Cartan_determinants",(D.det(),GG.det()))
# The explicitly specified 8x8 so(4,4) Cartan decomposition gives an
# independent elementary dimension and trace-form sign check for this model.
eta=S.diag(1,1,1,1,-1,-1,-1,-1)
B=[]
for i,j in combinations(range(8),2):
    M=S.zeros(8);M[i,j]=1;M[j,i]=-eta[i,i]/eta[j,j];B.append(M)
assert all(M.T*eta+eta*M==S.zeros(8) for M in B)
compact=[M for M in B if M.T==-M]
noncompact=[M for M in B if M.T==M]
assert len(compact)==12 and len(noncompact)==16
T=S.Matrix(28,28,lambda i,j:S.trace(B[i]*B[j]))
assert T.is_diagonal()
positive=sum(bool(T[i,i]>0) for i in range(28))
negative=sum(bool(T[i,i]<0) for i in range(28))
report("explicit_so44_model_k_p_dimensions",(len(compact),len(noncompact)))
report("explicit_so44_trace_form_inertia",(positive,negative,0))
report("fingerprint_is_complete_type_certificate",False)
report("registered_54_failure_16_closure_and_generated_algebra","NOT VERIFIED: exact frozen arrays absent")
report("result","PASS: standard diagnostic only; no registered Lie-triple result reexecuted")
