# Supergeometry model: decomposition of the 8 face positions, the 7 cage positions and their product 8x7=56 into O_h irreps.
# Run: python3 oh_states_8x7.py  (numpy only)
import numpy as np, itertools
# O_h: signed permutation matrices
G=[]
for p in itertools.permutations(range(3)):
    for s in itertools.product([1,-1],repeat=3):
        M=np.zeros((3,3));
        for i in range(3): M[i,p[i]]=s[i]
        G.append(M)
def cls(M):
    d=round(np.linalg.det(M)); R=M*d; t=round(np.trace(R))
    if t==3: c='E'
    elif t==0: c='C3'
    elif t==1: c='C4'
    else: c='C4sq' if np.allclose(R,np.diag(np.diag(R))) else 'C2p'
    return c if d==1 else {'E':'i','C3':'S6','C4':'S4','C4sq':'sh','C2p':'sd'}[c]
order=['E','C3','C2p','C4','C4sq','i','S4','S6','sh','sd']
tab={'A1g':[1,1,1,1,1,1,1,1,1,1],'A2g':[1,1,-1,-1,1,1,-1,1,1,-1],'Eg':[2,-1,0,0,2,2,0,-1,2,0],
'T1g':[3,0,-1,1,-1,3,1,0,-1,-1],'T2g':[3,0,1,-1,-1,3,-1,0,-1,1],'A1u':[1,1,1,1,1,-1,-1,-1,-1,-1],
'A2u':[1,1,-1,-1,1,-1,1,-1,-1,1],'Eu':[2,-1,0,0,2,-2,0,1,-2,0],'T1u':[3,0,-1,1,-1,-3,-1,0,1,1],'T2u':[3,0,1,-1,-1,-3,1,0,1,-1]}
faces=[np.array(s,float) for s in itertools.product([1,-1],repeat=3)]
cage=[np.zeros(3)]+[v*np.array(e,float) for e in np.eye(3) for v in (1,-1)]
def perm_char(pts,M): return sum(1 for p in pts if np.allclose(M@p,p))
def decomp(chi):
    out={}
    for k,row in tab.items():
        n=sum(chi[i]*row[order.index(cls(G[i]))] for i in range(48))/48
        if round(n): out[k]=round(n)
    return out
c8=[perm_char(faces,M) for M in G]; c7=[perm_char(cage,M) for M in G]
print("8 :",decomp(c8)); print("7 :",decomp(c7))
print("56:",decomp([a*b for a,b in zip(c8,c7)]))
