# For each of the 126 rank-one cases: is the glued point W_X-conjugate to y identically along every component of the curve?
# y' (e1) = q^{3+<rho_L,c1>} u^{c1_1} v^{c1_6}, y'(e6) likewise (c1 = w^{-1} alpha_1^vee, c6 = w^{-1} alpha_6^vee).
# g in W_X acts by monomials; y' = g y on the curve {u^p v^q = q^m zeta} iff for both coordinates the ratio monomial
# q^{k} u^{d1} v^{d2} is identically 1 there: (d1,d2) = t (p,q) with q-power and root-of-unity parts matching.
import sys, pickle; sys.path.insert(0, '/private/tmp/claude-501/-Users-miltonlin-Projects-Trees/75c2c3d9-ef06-4644-b59b-d12583740b0c/scratchpad/anim/work/G5/scripts')
from fractions import Fraction as F
from math import gcd
from e6_pointsearch import winv, apply, E, rhoL   # re-runs search on import (prints); acceptable
curve_ws = pickle.load(open('/private/tmp/claude-501/-Users-miltonlin-Projects-Trees/75c2c3d9-ef06-4644-b59b-d12583740b0c/scratchpad/anim/work/G5/curve_ws.pkl', 'rb'))
# W_X elements as 2x2 integer matrices acting on exponent vectors: g.y has (g.y)(e) = y(g^{-1} e); represent by action on
# (log u, log v) vectors: s1: (s,t) -> (-s, s+t), s6: (s,t) -> (s+t, -t)
def s1(M): return tuple(tuple(r) for r in [[-M[0][0], -M[0][1]], [M[0][0] + M[1][0], M[0][1] + M[1][1]]])
def s6(M): return tuple(tuple(r) for r in [[M[0][0] + M[1][0], M[0][1] + M[1][1]], [-M[1][0], -M[1][1]]])
Id = ((1, 0), (0, 1)); G = {Id}; fr = [Id]
while fr:
    nf = []
    for M in fr:
        for N in (s1(M), s6(M)):
            if N not in G: G.add(N); nf.append(N)
    fr = nf
assert len(G) == 6
ok_all = True; bad = []
for w in curve_ws:
    wi = winv(w)
    cs = [apply(wi, E[j]) for j in (1, 2, 3, 4)]
    eqs = [(c[0], c[5], 1 - rhoL(c)) for c in cs]
    rows = [(a, b, k) for a, b, k in eqs if (a, b) != (0, 0)]
    a0, b0, _ = rows[0]; g0 = gcd(abs(a0), abs(b0)); p, qq = a0 // g0, b0 // g0
    t0 = a0 // p if p != 0 else b0 // qq
    m = F(rows[0][2], t0)          # curve: u^p v^qq = q^m * (root of unity of order dividing gcd of the t's)
    tg = 0
    for a, b, k in rows:
        t = a // p if p != 0 else b // qq; tg = gcd(tg, abs(t))
    c1 = apply(wi, E[0]); c6 = apply(wi, E[5])
    # log-linear map: y' exponents (on u,v) and q-shifts
    Yexp = [(c1[0], c1[5], 3 + rhoL(c1)), (c6[0], c6[5], 3 + rhoL(c6))]
    found = False
    for M in G:
        # (g.y) in log coords: (s,t) -> M (s,t); coordinate i: M[i][0]*s + M[i][1]*t, no q shift
        good = True
        for i in range(2):
            d1 = Yexp[i][0] - M[i][0]; d2 = Yexp[i][1] - M[i][1]; k = Yexp[i][2]
            # need q^k u^d1 v^d2 == 1 on every component {u^p v^qq = q^m zeta}, zeta^{tg} = 1
            if p * d2 - qq * d1 != 0: good = False; break      # not proportional to (p,qq)
            s = F(d1, p) if p != 0 else F(d2, qq)               # u^d1 v^d2 = (u^p v^qq)^s
            if not (s * m + k == 0): good = False; break        # q-power must cancel
            # root of unity part: zeta^s must be 1 for all zeta with zeta^{tg}=1 -> s*tg... need s integer multiple of tg? zeta^{s}
            # (u^p v^qq)^s with s possibly fractional: since (p,qq) primitive, s = d1/p is an integer when p != 0 and gcd(p,qq)=1
            if s.denominator != 1 or (int(s) % tg) != 0: good = False; break
        if good: found = True; break
    if not found: ok_all = False; bad.append(w)
print('rank-one cases:', len(curve_ws), ' identically W_X-conjugate along every component:', len(curve_ws) - len(bad))
