import sys, os; sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# (A4)-type data for E6/F4: spherical roots, types, colours' valuations, r-values, Theta, Statement 7.1.5; no real roots.
from e6core import *
from fractions import Fraction as Fr
g1 = phi(E[0]); g6 = phi(E[5])     # alpha - theta(alpha) as root-coordinate vectors (simply laced identification)
print('gamma1 = alpha1 - theta alpha1 =', g1, ' weight coords', wtcoords(g1))
print('gamma6 =', g6, ' weight coords', wtcoords(g6))
print('-theta(alpha1) = w_L alpha1 =', wL(E[0]), 'is root:', wL(E[0]) in Phi, ' (alpha1, w_L alpha1) =', ip(E[0], wL(E[0])))
print('gamma1 a root?', g1 in Phi, '; gamma1/2 integral?', all(x % 2 == 0 for x in g1))
print('any root proportional to gamma1?', [r for r in Phi if any(all(Fr(r[i])*c == g1[i] for i in range(n)) for c in (Fr(1,2),1,2,-1,Fr(-1,2),-2))])
print('supports:', [i+1 for i in range(n) if g1[i]], [i+1 for i in range(n) if g6[i]])
# roots lying in the (-1)-eigenspace of theta (real roots) -> none means no type T/N at maximal-rank orbits
print('roots with theta(r) = -r:', [r for r in Phi if theta(r) == tuple(-x for x in r)])
print('roots with theta(r) = r:', len([r for r in Phi if theta(r) == r]), '(should be the 24 roots of L)')
# rho_{P(X)} = rho - rho_L paired with lifts of the colour valuations e1 = phi(alpha1^vee) (lift alpha1^vee), e6
def half_pair(two_vec, v): return Fr(ip(two_vec, v), 2)
rP = tuple(two_rho[i] - two_rhoL[i] for i in range(n))
print('<rho_P(X), alpha1^vee> =', half_pair(rP, E[0]), ' <rho_P(X), alpha6^vee> =', half_pair(rP, E[5]))
print('<rho_P(X), black coroots> =', [half_pair(rP, E[j]) for j in black])
print('<rho_L, alpha_j^vee> =', [half_pair(two_rhoL, E[j]) for j in range(n)])
# pairing of A_X-cocharacters e_i = phi(alpha_i^vee) with characters omega_1, omega_6 of A_X: <phi(l), chi>_{A_X} = <l, chi>_T
# so e1, e6 dual basis to omega1, omega6.  Spherical roots in X(X)=Z w1+Z w6: gamma1 = 2w1 - w6, gamma6 = -w1 + 2w6.
C = [[ip(E[0], g1)//1, ip(E[5], g1)], [ip(E[0], g6), ip(E[5], g6)]]
print('<e_i, gamma_j> matrix (rows e1,e6; cols g1,g6):', [[C[0][0], C[1][0]], [C[0][1], C[1][1]]])
# Theta: W_X-saturation of {(e1,+,4),(e6,+,4)} and negatives; W_X = S3 on Lambda_X with simple reflections
def s1(v): a, b = v; return (-a, a + b)          # in basis e1,e6 coordinates? use (c1,c6) coords of Lambda_X = Z e1 + Z e6
# In (c1,c6) coordinates (v = c1 e1 + c6 e6): reflection in gamma1: v -> v - <v,gamma1> e1, <v,gamma1> = 2c1 - c6
def r1(v): c1, c6 = v; return (c1 - (2*c1 - c6), c6)
def r6(v): c1, c6 = v; return (c1, c6 - (2*c6 - c1))
def orb(v):
    s = {v}; fr = [v]
    while fr:
        nf = []
        for x in fr:
            for y in (r1(x), r6(x)):
                if y not in s: s.add(y); nf.append(y)
        fr = nf
    return s
Theta = orb((1, 0)) | orb((0, 1)); Theta |= {(-a, -b) for a, b in Theta}
print('Theta (c1,c6 coords):', sorted(Theta))
pos = [t for t in Theta if t[0] >= 0 and t[1] >= 0]   # cone generated by colour valuations e1=(1,0), e6=(0,1)
print('Theta^+ :', sorted(pos), ' every element >0 or <0:', all((t in pos) != ((-t[0], -t[1]) in pos) for t in Theta))
for name, r in (('gamma1', r1), ('gamma6', r6)):
    flips = [t for t in pos if (lambda u: u[0] <= 0 and u[1] <= 0)(r(t))]
    print(name, ': {theta in Theta^+ : w_gamma theta < 0} =', flips)
# number of B-orbits of maximal rank = |W| / |W_X x W_P(X)| = 51840 / (6 * |W(D4)|)
print('max-rank B-orbits:', 51840 // (6 * 192))
