import sys; sys.path.insert(0, "/private/tmp/claude-501/-Users-miltonlin-Projects-Trees/75c2c3d9-ef06-4644-b59b-d12583740b0c/scratchpad/solve/A6")
from e6_setup import *
# longest element of a parabolic subsystem as a word: apply s_j with <alpha_j,v>>0 to a sub-regular dominant v until antidominant
def w0_word(nodes):
    v=tuple(sum(1 for _ in nodes) if i in nodes else 0 for i in range(n))  # placeholder
    # take v = sum of fundamental coweights of the subsystem restricted: use v with <alpha_j,v>=1 for j in nodes, 0 else -> solve A v = e
    # simpler: v = sum over nodes of (positive) multiples -- use fractions: v = A^{-1} e restricted; instead iterate on the vector of pairings
    import fractions
    # work with the vector of pairings c_j=<alpha_j,v>; s_j changes c_k -> c_k - c_j*A[k][j]
    c=[1 if j in nodes else 0 for j in range(n)]
    word=[]
    while True:
        js=[j for j in nodes if c[j]>0]
        if not js: break
        j=js[0]; word.append(j)
        cj=c[j]; c=[c[k]-cj*A[k][j] for k in range(n)]
    return word
def apply_word(word, lam):
    for j in word: lam=refl(j,lam)
    return lam
wD4=w0_word([1,2,3,4]); wD5=w0_word([0,1,2,3,4]); wD5b=w0_word([1,2,3,4,5])
print('lengths',len(wD4),len(wD5),len(wD5b))
# w1 := w0(D5 on 1..5) * w0(D4): action lam -> apply wD4 then wD5
def w1(lam): return apply_word(wD5, apply_word(wD4, lam))
def w6(lam): return apply_word(wD5b, apply_word(wD4, lam))
# check: they normalize Lambda_S (plane), induce s_1,s_6 on (a,b), and fix rho_L
rhoL2=two_rhoL
print('w1 fixes 2rho_L:', w1(rhoL2)==rhoL2, ' w6 fixes 2rho_L:', w6(rhoL2)==rhoL2)
for e in I:
    print('lam',e,'ab',ab(e),'ab(w1 lam)',ab(w1(e)),'ab(w6 lam)',ab(w6(e)))
# check ab(w1 lam) == s1(ab(lam)) with s1(a,b)=(-a,a+b), s6(a,b)=(a+b,-b)
def s1(a,b): return (-a,a+b)
def s6(a,b): return (a+b,-b)
import random
ok=True
for _ in range(200):
    lam=tuple(random.randint(-5,5) for _ in range(n))
    if ab(w1(lam))!=s1(*ab(lam)) or ab(w6(lam))!=s6(*ab(lam)): ok=False
print('w1,w6 induce s1,s6 on (a,b):',ok)
# phi(w1 lam) == w1 phi(lam)? i.e. w1 commutes with theta on Lambda_T?
ok2=all(phi(w1(lam))==w1(phi(lam)) for lam in [tuple(random.randint(-5,5) for _ in range(n)) for _ in range(100)])
print('w1 commutes with phi:',ok2)
