# Canonical little Weyl group: minimal-length representatives in N_W(Phi_L) preserving Phi_L^+.
exec(open('/private/tmp/claude-501/-Users-miltonlin-Projects-Trees/75c2c3d9-ef06-4644-b59b-d12583740b0c/scratchpad/solve-vi/A3/e6_charp_checks.py').read().split('# ---- matrices for Weyl group elements')[0].replace('print(', 'pass; (lambda *a, **k: None)('))
def word_op(word):
    def f(v):
        for i in reversed(word): v = refl(i, v)
        return v
    return f
PLpos = set(r for r in PhiL if all(x>=0 for x in r))
for name, word in [("w_g1 = s1 s3 s4 s2 s5 s4 s3 s1", [0,2,3,1,4,3,2,0]), ("w_g6 = s6 s5 s4 s2 s3 s4 s5 s6", [5,4,3,1,2,3,4,5])]:
    op = word_op(word)
    print(name, ": preserves Phi_L^+:", set(op(r) for r in PLpos) == PLpos,
          "; involution:", all(op(op(s)) == s for s in simple),
          "; length:", len([r for r in pos if all(x<=0 for x in op(r))]))
# group generated by the two, as permutations of roots
def key(op): return tuple(op(s) for s in simple)
g1 = word_op([0,2,3,1,4,3,2,0]); g6 = word_op([5,4,3,1,2,3,4,5])
ops = {key(lambda v: v): (lambda v: v)}; frontier = [lambda v: v]
while frontier:
    new = []
    for f in frontier:
        for g in (g1, g6):
            h = (lambda f=f, g=g: (lambda v: g(f(v))))()
            k = key(h)
            if k not in ops: ops[k] = h; new.append(h)
    frontier = new
print("order of <w_g1, w_g6>:", len(ops), "; all preserve Phi_L^+:", all(set(h(r) for r in PLpos)==PLpos for h in ops.values()))
# s_a1 s_b1 preserves Phi_L^+ ?
def refl_root(beta, v):
    k = pair(v, beta); return tuple(v[i]-k*beta[i] for i in range(n))
a1 = simple[0]; b1 = tuple(-x for x in theta(a1))
w1 = lambda v: refl_root(a1, refl_root(b1, v))
print("s_a1 s_b1 preserves Phi_L^+:", set(w1(r) for r in PLpos)==PLpos, "; length of s_a1 s_b1:", len([r for r in pos if all(x<=0 for x in w1(r))]))
