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 *
from e6_restrict import wx_orbit
from fractions import Fraction as Fr
from collections import Counter
import pickle
data=pickle.load(open('e6_restrict_20.pkl','rb'))
# points y=(u,v) with u=t^eu, v=t^ev (positive real); x(lam) = t^{<2rho_L,lam> + lam_1 eu + lam_6 ev}
def logx(y,lam): return two_rhoL_pair(lam)+lam[0]*y[0]+lam[5]*y[1]
y1=(-10,2); y2=(-10,8)
def m_at(mu,y):   # orbit sum of mu at x(y) as Counter of t-exponents
    c=Counter()
    for nu in orbit(mu): c[logx(y,nu)]+=1
    return c
allok=True
for mu in sorted(data,key=norm2):
    a=m_at(mu,y1); b=m_at(mu,y2)
    if a!=b: allok=False; print('MISMATCH at mu',data[mu][0])
print('m_mu(x1)==m_mu(x2) for all %d dominant mu of norm<=20:'%len(data), allok)
# M_kappa(y) for kappa=(a,b): kappa = c1 e1 + c6 e6 with c1=(2a+b)/3, c6=(a+2b)/3 ; y^kappa = u^c1 v^c6
def M_at(kappa,y):
    c=Counter()
    for (a,b) in wx_orbit(kappa):
        c1=Fr(2*a+b,3); c6=Fr(a+2*b,3); c[c1*y[0]+c6*y[1]]+=1
    return c
for k in [(1,1),(3,0),(0,3),(2,2),(4,1),(1,4)]:
    print('M_%s: at y1 exps %s ; at y2 exps %s ; equal? %s'%(k,dict(M_at(k,y1)),dict(M_at(k,y2)),M_at(k,y1)==M_at(k,y2)))
# sigma(y1): swap c1<->c6 i.e. (u,v)->(v,u)
print('W_X-orbit of y1 (log_t u, log_t v):',sorted(wxo:=set()))
def wx_pts(y):
    def s1(p): return (-p[0],p[0]+p[1])
    def s6(p): return (p[0]+p[1],-p[1])
    o={y}; fr=[y]
    while fr:
        nf=[]
        for p in fr:
            for q in (s1(p),s6(p)):
                if q not in o: o.add(q); nf.append(q)
        fr=nf
    return o
print('W_X orbit of y1:',sorted(wx_pts(y1)),' contains y2?',y2 in wx_pts(y1),' contains sigma(y1)=(2,-10)?',(2,-10) in wx_pts(y1))
print('W_X orbit of y2:',sorted(wx_pts(y2)),' contains sigma(y1)?',(2,-10) in wx_pts(y2))
# explicit w: from e6_points.pkl
G=pickle.load(open('e6_points.pkl','rb'))
for y,yp,w in G['glued']:
    if (y[0],y[2])==(-10,2) and y[1]==0 and y[3]==0 and (yp[0],yp[2])==(-10,8):
        print('one w with w.x(y1)=x(y2); columns w(alpha_i^vee)=',w)
        # verify directly: (w.x)(alpha_i^vee)=x(w^{-1}alpha_i^vee); check instead x1(w^{-1} lam)=x2(lam) <=> x1(mu)=x2(w mu) for all basis mu
        def apply(w, lam): return tuple(sum(w[j][i]*lam[j] for j in range(n)) for i in range(n))
        print('  check x1(mu)=x2(w mu) on basis:',all(logx(y1,e)==logx(y2,apply(w,e)) for e in I))
        break
# weights: x1 = q^{lambda*}: <lambda*,alpha_i^vee> = logx/2
print('x1 = q^{lambda1*}, <lambda1*,alpha_i^vee> =',[Fr(logx(y1,e),2) for e in I])
print('x2 = q^{lambda2*}, <lambda2*,alpha_i^vee> =',[Fr(logx(y2,e),2) for e in I])
