# w_1 = w_0(D5 on 1..5) w_0(D4 on 2..5); w_0(J) = -(opposition of J) on span(J), identity on span(J)^perp.
import sys; sys.path.insert(0, '/private/tmp/claude-501/-Users-miltonlin-Projects-Trees/75c2c3d9-ef06-4644-b59b-d12583740b0c/scratchpad/anim/work/G5/scripts')
from e6model import *
from e6_theta import theta, phi, rhoL, e1, e6
def w0(J, opp):
    GJ = [[dot(al[i], al[j]) for j in J] for i in J]
    def f(v):
        c = solve(GJ, [dot(v, al[i]) for i in J])
        pv = (F(0),) * 8
        for k, i in enumerate(J): pv = add(pv, sc(c[k], al[i]))
        perp = sub(v, pv)
        img = (F(0),) * 8
        for k, i in enumerate(J): img = add(img, sc(-c[k], al[opp.get(i, i)]))
        return add(perp, img)
    return f
wD5a = w0([1, 2, 3, 4, 5], {2: 5, 5: 2}); wD5b = w0([2, 3, 4, 5, 6], {2: 3, 3: 2}); wD4 = w0([2, 3, 4, 5], {})
# sanity: these map positive roots of J to negative roots of J
def w1(v): return wD5a(wD4(v))
def w6(v): return wD5b(wD4(v))
assert all(w1(r) in roots and w6(r) in roots for r in roots)
def ab(v): return (dot(v, al[1]), dot(v, al[6]))
print('w1 fixes rho_L:', w1(rhoL) == rhoL, ' w6 fixes rho_L:', w6(rhoL) == rhoL)
print('w1: e1 ->', ab(w1(e1)), ' e6 ->', ab(w1(e6)), '   (s1: e1 -> -e1=(-2,1), e6 -> e1+e6=(1,1))')
print('w6: e1 ->', ab(w6(e1)), ' e6 ->', ab(w6(e6)), '   (s6: e1 -> e1+e6=(1,1), e6 -> -e6=(1,-2))')
print('w1, w6 commute with theta on roots:', all(theta(w1(r)) == w1(theta(r)) and theta(w6(r)) == w6(theta(r)) for r in roots))
# length check: number of positive roots made negative
def length(f): return sum(1 for r in pos if f(r) not in pos)
print('lengths of w0(D5), w0(D4), w1:', length(wD5a), length(wD4), length(w1))
