#!/usr/bin/env python3
"""Class-function coefficients of the aligned pure part (k=1) by character inner products; a_rho must be 0.  python3 coeff_check.py"""
import sys, json
sys.argv = ['run.py', sys.argv[1] if len(sys.argv) > 1 else 'b.a']
import run as R, numpy as np
sizes = {}
for k, c in R.cq.items(): sizes[c] = sizes.get(c, 0)+1
out = {}
f_n = {}; f_u = {}
for c, q in R.REP.items():
    f_n[c] = float(np.dot(R.NH[1:], q[1:])) if c != R.c4 else 0.0
    f_u[c] = float(q[1]) if c == R.c4 else 0.0
for nm, f in (('n (coefficient of n-hat)', f_n), ('u (coefficient of u=i)', f_u)):
    out[nm] = {}
    for ch in range(7):
        a = sum(sizes[c]*f[c]*R.tab[c][ch].conjugate() for c in f)/24
        out[nm][R.NAME[ch]] = [round(a.real, 12), round(a.imag, 12)]
    print(nm, out[nm])
json.dump(out, open(f'coeffs-{R.KEY}.json', 'w'), indent=1)
