"""Guideng Math Paper 20.  The Cut Square Inside E8.
Checks every numbered statement.  Run:  python3 verify_cut_square_in_e8.py
The action G(X), its mirror Gb(X) and the change of view S(X,Y) are those of Paper V, for the
four number systems.  Complex numbers are used throughout (the complex algebra)."""
import numpy as np, itertools
rng = np.random.default_rng(20)
TOL = 1e-8
ok = lambda a, b: np.allclose(a, b, atol=TOL)
RES = []
def check(name, cond, extra=''):
    RES.append(bool(cond)); print(('PASS  ' if cond else 'FAIL  ') + name + ('   [' + extra + ']' if extra else ''))

# ---------- the four number systems and the action of Paper V ----------
def conj(x): c = -x.copy(); c[0] = x[0]; return c
def mul(x, y):
    n = len(x)
    if n == 1: return x * y
    h = n // 2; a, b, c, d = x[:h], x[h:], y[:h], y[h:]
    return np.concatenate([mul(a, c) - mul(conj(d), b), mul(d, a) + mul(b, conj(c))])
def act(k, X, p):                                   # Gamma(X)(x,y) = ((t+a)x + u y, conj(u) x + (t-a) y)
    x, y = p[:k], p[k:]; t, a, u = X[0], X[1], X[2:]
    return np.concatenate([(t + a) * x + mul(u, y), mul(conj(u), x) + (t - a) * y])
flat = lambda X: np.concatenate([[-X[0]], X[1:]])
eta = lambda X, Y: X[0] * Y[0] - X[1:] @ Y[1:]
def cut(k, p):                                      # c(psi) = (|x|^2+|y|^2; |x|^2-|y|^2, 2 x conj(y))
    x, y = p[:k], p[k:]
    return np.concatenate([[x @ x + y @ y, x @ x - y @ y], 2 * mul(x, conj(y))])
beta = lambda k, p, q: (cut(k, p + q) - cut(k, p) - cut(k, q)) / 2
NAME = {1: 'R', 2: 'C', 4: 'H', 8: 'O'}

class Rung:
    """The space V of n = k+2 numbers acting on roots and mirror roots; reduced by the i of C or of H."""
    def __init__(s, k):
        s.k, s.n = k, k + 2; E = np.eye(2 * k)
        s.Gr = lambda X: np.column_stack([act(k, X, e) for e in E]); s.Gbr = lambda X: s.Gr(flat(X))
        if k in (2, 4):                             # right multiplication by the unit i commutes with the action
            i_ = np.zeros(k); i_[1] = 1
            J = np.column_stack([np.concatenate([mul(e[:k], i_), mul(e[k:], i_)]) for e in E])
            s.J = J; w, v = np.linalg.eig(J); s.P = np.linalg.qr(v[:, np.abs(w - 1j) < 1e-9])[0]
        else: s.J = None; s.P = np.eye(2 * k, dtype=complex)
        s.d = s.P.shape[1]                          # complex numbers in a root: 2, 2, 4, 16
        s.G = lambda X: s.P.conj().T @ s.Gr(X) @ s.P; s.Gb = lambda X: s.P.conj().T @ s.Gbr(X) @ s.P
        Z = np.zeros((s.d, s.d))
        s.D = lambda X: np.block([[Z, s.Gb(X)], [s.G(X), Z]])
        s.eps = np.diag([1.0] * s.d + [-1.0] * s.d)
        s.S = lambda X, Y: 0.25 * (s.Gb(X) @ s.G(Y) - s.Gb(Y) @ s.G(X))
        s.sign = np.array([1.0] + [-1.0] * (s.n - 1))
        Eb = np.eye(s.n)                            # g_m^2 = 1:  g = i D for eta = +1,  g = -D for eta = -1
        s.g = [(1j * s.D(Eb[m]) if s.sign[m] > 0 else -s.D(Eb[m])) for m in range(s.n)]
        s.coord = lambda X: np.array([X[0]] + [-1j * X[m] for m in range(1, s.n)])   # i D(X) = sum coord_m g_m
RUNG = {k: Rung(k) for k in (1, 2, 4, 8)}
for k, r in RUNG.items():
    X, Y = rng.normal(size=r.n), rng.normal(size=r.n)
    c1 = ok(r.Gb(X) @ r.G(X), -eta(X, X) * np.eye(r.d)) and ok((1j * r.D(X)) @ (1j * r.D(X)), eta(X, X) * np.eye(2 * r.d))
    c2 = all(ok(r.g[m] @ r.g[n] + r.g[n] @ r.g[m], 2 * (m == n) * np.eye(2 * r.d)) for m in range(r.n) for n in range(r.n))
    c3 = ok(1j * r.D(X), sum(r.coord(X)[m] * r.g[m] for m in range(r.n))) and ok(r.eps @ r.D(X), -r.D(X) @ r.eps)
    c4 = r.J is None or (ok(r.J @ r.Gr(X), r.Gr(X) @ r.J) and ok(r.J @ r.J, -np.eye(2 * k)))
    check('Lemma 2.1 (%s): compact form Gb(X)G(X) = -eta(X,X); (iD(X))^2 = eta(X,X); the n = %d units anticommute; a root is %d complex numbers'
          % (NAME[k], r.n, r.d), c1 and c2 and c3 and c4)

# ---------- labels ----------
s0 = np.eye(2); s1 = np.array([[0, 1], [1, 0]], complex); s2 = np.array([[0, -1j], [1j, 0]]); s3 = np.diag([1, -1]).astype(complex)
def kron(*m):
    r = np.eye(1)
    for x in m: r = np.kron(r, x)
    return r
def plain(n):                                       # 2n anticommuting units of size 2^n and the product of them all
    g = []
    for j in range(n):
        g.append(kron(*([s3] * j + [s1] + [s0] * (n - j - 1)))); g.append(kron(*([s3] * j + [s2] + [s0] * (n - j - 1))))
    return g, kron(*([s3] * n))
def label(k):
    if k == 1: g, c = plain(6); return g + [c], 'thirteen'
    if k == 2: return plain(6)[0], 'twelve'
    if k == 4: return RUNG[8].g, 'the ten of O'
    if k == 8: return RUNG[4].g, 'the six of H'

# ---------- the algebra: turns of sixteen and 128 ----------
class Algebra:
    def __init__(s, gs):
        s.g = gs; s.N = len(gs); s.dim = gs[0].shape[0]
        C = rng.normal(size=(s.dim, s.dim)) + 1j * rng.normal(size=(s.dim, s.dim))
        for g in gs: C = (C + g.T @ C @ g) / 2      # sixteen commuting projections: the pairing with (g q, r) = (q, g r)
        s.C = C / np.abs(C).max()
        chi = np.eye(s.dim, dtype=complex)
        for g in gs: chi = chi @ g
        chi = chi / np.sqrt((chi @ chi)[0, 0]); s.chi = chi; s.Pp = (np.eye(s.dim) + chi) / 2
    def rho(s, A, q):                               # rho(A) q = (1/4) sum A_mn g_m g_n q
        w = [g @ q for g in s.g]
        return 0.25 * sum(s.g[m] @ sum(A[m, n] * w[n] for n in range(s.N) if n != m) for m in range(s.N))
    def T(s, q, r):                                 # the turn with tr(A T(q,r)) = 4 (rho(A) q, r)
        u = [g.T @ (s.C.T @ q) for g in s.g]; w = [g @ r for g in s.g]
        A = np.array([[u[m] @ w[n] for n in range(s.N)] for m in range(s.N)]); np.fill_diagonal(A, 0); return A
    def br(s, a, b):
        (A, q), (B, r) = a, b
        return (A @ B - B @ A + s.T(q, r), s.rho(A, r) - s.rho(B, q))
    def rnd(s):
        A = rng.normal(size=(s.N, s.N)) + 1j * rng.normal(size=(s.N, s.N))
        return (A - A.T, s.Pp @ (rng.normal(size=s.dim) + 1j * rng.normal(size=s.dim)))
    def jacobi(s, trials=2):
        m = 0
        for _ in range(trials):
            a, b, c = s.rnd(), s.rnd(), s.rnd()
            t = [s.br(s.br(a, b), c), s.br(s.br(b, c), a), s.br(s.br(c, a), b)]
            m = max(m, abs(t[0][0] + t[1][0] + t[2][0]).max(), abs(t[0][1] + t[1][1] + t[2][1]).max())
        return m
    def pair(s, q, r): return q @ s.C @ r

cv = lambda n: rng.normal(size=n) + 1j * rng.normal(size=n)
for k in (1, 2, 4, 8):
    r = RUNG[k]; lab, lname = label(k); n, d = r.n, len(lab); dL = lab[0].shape[0]; IL = np.eye(dL); IK = np.eye(2 * r.d)
    gs = [np.kron(g, IL) for g in r.g] + [np.kron(r.eps, b) for b in lab]
    al = Algebra(gs); tag = '%s, %d + %d' % (NAME[k], n, d)
    c0 = all(ok(gs[a] @ gs[b] + gs[b] @ gs[a], 2 * (a == b) * np.eye(al.dim)) for a in range(16) for b in range(16)) and al.dim == 256
    c1 = all(ok(al.C @ g, g.T @ al.C) for g in gs) and ok(al.Pp.T @ al.C @ al.Pp, (al.Pp.T @ al.C @ al.Pp).T) and int(round(np.trace(al.Pp).real)) == 128
    c1 = c1 and ok(al.Pp.T @ al.C @ (np.eye(256) - al.Pp), 0)                     # the two halves are not paired with each other
    check('Lemma 3.2 (%s): sixteen units on 256 numbers; the pairing is symmetric on each half of 128 and zero between them' % tag, c0 and c1)
    jd = al.jacobi()
    check('Theorem 3.4 (%s): the bracket satisfies the Jacobi identity; dimension 120 + 128 = 248' % tag, jd < 1e-7, 'defect %.1e' % jd)
    # the pieces
    X, Y = rng.normal(size=n), rng.normal(size=n); v, w = rng.normal(size=d), rng.normal(size=d)
    def lift(x16): return x16
    def vec(Xk, vl):
        u = np.zeros(16, complex); u[:n] = r.coord(Xk); u[n:] = vl; return u
    wedge = lambda a, b: np.outer(a, b) - np.outer(b, a)
    gx = lambda u: sum(u[m] * gs[m] for m in range(16))
    xu, yu = vec(X, 0 * v), vec(Y, 0 * v); vu, wu = vec(0 * X, v), vec(0 * X, w)
    rhoM = lambda u1, u2: 0.25 * (gx(u1) @ gx(u2) - gx(u2) @ gx(u1))
    Z = rhoM(xu, vu)
    check('Theorem 4.2(a) (%s): the labelled element X^v acts as (i/2) D(X) eps (x) b(v); twice, it is -(1/4) eta(X,X) (v.v)' % tag,
          ok(Z, 0.5j * np.kron(r.D(X) @ r.eps, sum(v[i] * lab[i] for i in range(d)))) and ok(Z @ Z, -0.25 * eta(X, X) * (v @ v) * np.eye(256)))
    Cm = wedge(xu, vu) @ wedge(yu, wu) - wedge(yu, wu) @ wedge(xu, vu)
    check('Theorem 4.2(b) (%s): [X^v, Y^w] = -(v.w) X^Y - eta(X,Y) v^w' % tag, ok(Cm, -(v @ w) * wedge(xu, yu) - eta(X, Y) * wedge(vu, wu)))
    SK = np.block([[r.S(X, Y), np.zeros((r.d, r.d))], [np.zeros((r.d, r.d)), 0.25 * (r.G(X) @ r.Gb(Y) - r.G(Y) @ r.Gb(X))]])
    check('Theorem 4.2(c) (%s): the turn X^Y acts on roots as the change of view -S(X,Y) of Paper V, and not on the label' % tag,
          ok(rhoM(xu, yu), np.kron(-SK, IL)))
    # which halves: the 128 as roots and mirror roots with labels
    PR = np.kron(np.diag([1.0] * r.d + [0.0] * r.d), IL); PM = np.kron(np.diag([0.0] * r.d + [1.0] * r.d), IL)
    dims = (int(round(np.trace(al.Pp @ PR).real)), int(round(np.trace(al.Pp @ PM).real)))
    split = ok(al.Pp @ PR, PR @ al.Pp)
    q1, q2 = al.Pp @ cv(256), al.Pp @ cv(256)
    if split:
        rt, rt2, mr, mr2 = PR @ q1, PR @ q2, PM @ q1, PM @ q2
        blocks = lambda A: (np.abs(A[:n, :n]).max() > 1e-7, np.abs(A[n:, n:]).max() > 1e-7, np.abs(A[:n, n:]).max() > 1e-7)
        rr, rm, mm = blocks(al.T(rt, rt2)), blocks(al.T(rt, mr)), blocks(al.T(mr, mr2))
        which = 'two roots' if rr[2] else 'a root and a mirror root'
        cons = (rr == (False, False, True) and rm == (True, True, False)) or (rr == (True, True, False) and rm == (False, False, True))
        cons = cons and mm == rr
        check('Theorem 4.1 (%s): the 128 is roots with half the label roots (%d) and mirror roots with the other half (%d); a labelled element is made by %s'
              % (tag, dims[0], dims[1], which), cons and dims[0] + dims[1] == 128, which)
    else:
        A = al.T(q1, q2)
        P4 = al.Pp.reshape(2 * r.d, dL, 2 * r.d, dL); Epart = np.einsum('ajbj->ab', P4) / dL        # Pp = E (x) 1, E of rank 2, a graph over the roots
        graph = ok(al.Pp, np.kron(Epart, IL)) and np.linalg.matrix_rank(Epart, tol=1e-9) == r.d and np.linalg.matrix_rank(Epart[:r.d, :], tol=1e-9) == r.d \
            and np.linalg.matrix_rank(Epart[r.d:, :], tol=1e-9) == r.d
        check('Theorem 4.1 (%s): the half of 128 is not roots or mirror roots apart: a root and its mirror root are one, 128 = 2 x 64'
              % tag, dims[0] + dims[1] == 128 and np.abs(A[:n, n:]).max() > 1e-7 and graph)
    # the bracket of two is the transpose of the action
    A0 = rng.normal(size=(16, 16)) + 1j * rng.normal(size=(16, 16)); A0 = A0 - A0.T
    check('Theorem 4.3 (%s): full form, tr(A [q,r]) = 4 (A q, r) for every turn A' % tag,
          abs(np.trace(A0 @ al.T(q1, q2)) - 4 * al.pair(al.rho(A0, q1), q2)) < 1e-7)
    if k in (1, 8):                                 # the real rungs: the K-part of the bracket of two roots is the pairing beta of Paper V
        p1, p2 = rng.normal(size=2 * k), rng.normal(size=2 * k)
        if k == 8:
            sL, tL = cv(dL), cv(dL)
            qa = al.Pp @ np.kron(np.concatenate([p1, 0 * p1]), sL); qb = al.Pp @ np.kron(np.concatenate([p2, 0 * p2]), tL)
        else:
            sL, tL = cv(dL), cv(dL)
            qa = al.Pp @ np.kron(np.concatenate([p1, 0 * p1]), sL); qb = al.Pp @ np.kron(np.concatenate([p2, 0 * p2]), tL)
        A = al.T(qa, qb)[:n, n:]                    # n x d block
        b = beta(k, p1, p2); bc = r.coord(b) * r.sign   # eta-dual of beta in the unit basis
        u_, sv, vt = np.linalg.svd(A); rank1 = sv[1] < 1e-7 * sv[0]
        col = A[:, np.argmax(np.abs(A).sum(axis=0))]
        prop = np.linalg.matrix_rank(np.vstack([col, bc]), tol=1e-7) == 1
        check('Theorem 4.3 (%s): the bracket of two labelled roots is beta(psi,chi) of Paper V times a pairing of the labels' % tag, rank1 and prop)

# ---------- six and ten: the two rungs are each other's label ----------
rH, rO = RUNG[4], RUNG[8]
IH, IO = np.eye(2 * rH.d), np.eye(2 * rO.d)
gs = [np.kron(g, IO) for g in rH.g] + [np.kron(rH.eps, b) for b in rO.g]
X6, Y10 = rng.normal(size=6), rng.normal(size=10)
u6 = np.zeros(16, complex); u6[:6] = rH.coord(X6); u10 = np.zeros(16, complex); u10[6:] = rO.coord(Y10)
gx = lambda u: sum(u[m] * gs[m] for m in range(16))
Z = 0.25 * (gx(u6) @ gx(u10) - gx(u10) @ gx(u6))
check('Theorem 5.1(a): on H with label O, the labelled element X^Y acts as (i/2) D_H(X) eps (x) i D_O(Y): both factors are the action of Paper V',
      ok(Z, 0.5j * np.kron(rH.D(X6) @ rH.eps, 1j * rO.D(Y10))) and ok(Z @ Z, -0.25 * eta(X6, X6) * eta(Y10, Y10) * np.eye(256)))
chi = np.eye(256, dtype=complex)
for g in gs: chi = chi @ g
chi = chi / np.sqrt((chi @ chi)[0, 0]); Pp = (np.eye(256) + chi) / 2
pr = lambda r, top: np.diag(([1.0] * r.d + [0.0] * r.d) if top else ([0.0] * r.d + [1.0] * r.d))
same = np.kron(pr(rH, 1), pr(rO, 1)) + np.kron(pr(rH, 0), pr(rO, 0)); cross = np.kron(pr(rH, 1), pr(rO, 0)) + np.kron(pr(rH, 0), pr(rO, 1))
half = 'roots with roots, mirror roots with mirror roots' if (ok(Pp, same) or ok(np.eye(256) - Pp, same)) else 'crossed'
check('Theorem 5.1(b): the 128 and the other 128 are (roots of H)(roots of O) + (mirror)(mirror) and (roots)(mirror) + (mirror)(roots)',
      (ok(Pp, same) and ok(np.eye(256) - Pp, cross)) or (ok(Pp, cross) and ok(np.eye(256) - Pp, same)), 'the 128 of the pairing: ' + ('same' if ok(Pp, same) else 'crossed'))
check('Theorem 5.1(c): 6 + 10 = 16; pieces 15 + 45 + 60 + 64 + 64 = 248; a root of H is 4 complex numbers, a root of O is 16, and 4 x 16 = 64',
      rH.n + rO.n == 16 and 15 + 45 + 60 + 64 + 64 == 248 and rH.d * rO.d == 64 and 2 * rH.d * 2 * rO.d == 256)

# ---------- the sixteen from cut squares alone ----------
def parts_units(ks):
    rs = [RUNG[k] for k in ks]; sz = [2 * r.d for r in rs]; out = []
    for j, r in enumerate(rs):
        for g in r.g:
            M = np.eye(1)
            for x in [rs[i].eps for i in range(j)] + [g] + [np.eye(sz[i]) for i in range(j + 1, len(rs))]: M = np.kron(M, x)
            out.append(M)
    return out, rs
def comps(total, allowed):
    if total == 0: return [()]
    return [(a,) + c for a in allowed if a <= total for c in comps(total - a, [b for b in allowed if b <= a])]
check('Theorem 5.2(a): sixteen is a sum of the even spaces 4, 6, 10 in exactly three ways: 10+6, 6+6+4, 4+4+4+4; each has 256 labelled roots',
      sorted(comps(16, [10, 6, 4])) == sorted([(10, 6), (6, 6, 4), (4, 4, 4, 4)]) and 8 * 32 == 256 and 4 * 8 * 8 == 256 and 4 ** 4 == 256)
for ks in ((2, 4, 4), (2, 2, 2, 2)):
    gs, rs = parts_units(ks); al = Algebra(gs); nm = '+'.join(str(r.n) for r in rs)
    c0 = len(gs) == 16 and al.dim == 256 and all(ok(gs[a] @ gs[b] + gs[b] @ gs[a], 2 * (a == b) * np.eye(256)) for a in range(16) for b in range(16))
    jd = al.jacobi(1)
    check('Theorem 5.2(b) (%s): sixteen units made of the action of Paper V alone; the bracket satisfies the Jacobi identity; dimension 248' % nm,
          c0 and jd < 1e-7, 'defect %.1e' % jd)
    par = np.ones(1)
    for r in rs: par = np.kron(par, np.diag(r.eps))
    even = np.diag((par > 0).astype(float))
    check('Theorem 5.2(c) (%s): the two halves are the labelled roots with an even and with an odd number of mirror roots' % nm,
          ok(al.Pp, even) or ok(al.Pp, np.eye(256) - even))

# ---------- which labels (the four of C fixed) ----------
import scipy.sparse as sp
def plain_sparse(n):
    S = [sp.identity(2, format='csr', dtype=complex), sp.csr_matrix(s1), sp.csr_matrix(s2), sp.csr_matrix(s3)]
    def kr(ms):
        r = sp.identity(1, format='csr', dtype=complex)
        for x in ms: r = sp.kron(r, x, format='csr')
        return r
    g = []
    for j in range(n):
        g.append(kr([S[3]] * j + [S[1]] + [S[0]] * (n - j - 1))); g.append(kr([S[3]] * j + [S[2]] + [S[0]] * (n - j - 1)))
    return g, kr([S[3]] * n)
def label_test(d):
    N = 4 + d; g, chi = plain_sparse(N // 2); dim = 2 ** (N // 2)
    C = sp.identity(dim, format='csr', dtype=complex)
    for x in g:
        if abs(x + x.T).max() < 1e-12: C = C @ x
    symm = abs(C - C.T).max() < 1e-12 and abs(C @ chi - chi @ C).max() < 1e-12 and all(abs(C @ x - x.T @ C).max() < 1e-12 for x in g)
    if not symm: return None
    Pp = (sp.identity(dim) + chi) / 2; CT = C.T.tocsr(); gT = [x.T.tocsr() for x in g]
    def rho(A, q):
        w = [x @ q for x in g]; return 0.25 * sum(g[m] @ sum(A[m, n] * w[n] for n in range(N) if n != m) for m in range(N))
    def T(q, r):
        u = [x @ (CT @ q) for x in gT]; w = [x @ r for x in g]
        A = np.array([[u[m] @ w[n] for n in range(N)] for m in range(N)]); np.fill_diagonal(A, 0); return A
    q, r_, s_ = (Pp @ cv(dim) for _ in range(3))
    J = rho(T(q, r_), s_) + rho(T(r_, s_), q) + rho(T(s_, q), r_)
    return np.abs(J).max() / (np.abs(q).max() ** 3)
res = {d: label_test(d) for d in (4, 12, 20)}
check('Proposition 6.1: with a label of 4 the bracket closes (dimension 28 + 8 = 36), with 12 it closes (248), with 20 it does not',
      res[4] < 1e-9 and res[12] < 1e-9 and res[20] > 1e-3, 'defects %.1e, %.1e, %.1e' % (res[4], res[12], res[20]))
bad = [d for d in range(2, 21, 2) if d not in (4, 12, 20) and label_test(d) is not None]
check('Proposition 6.1: for the other even labels up to 20 the pairing is not a symmetric pairing of the half with itself', bad == [], str(bad))

# ---------- real forms: the form of Paper 17 ----------
R8 = []
for i, j in itertools.combinations(range(8), 2):
    for a in (1, -1):
        for b in (1, -1):
            x = [0] * 8; x[i] = a; x[j] = b; R8.append(x)
for sg in itertools.product((.5, -.5), repeat=8):
    if sum(1 for x in sg if x < 0) % 2 == 0: R8.append(list(sg))
R8 = np.array(R8)
forms = {}
for q in range(0, 17, 2):
    h = np.array([1] * (q // 2) + [0] * (8 - q // 2)); vals = R8 @ h
    if not np.allclose(vals, np.round(vals)): forms[q] = None; continue
    comp = 8 + int(sum(1 for x in vals if round(x) % 2 == 0)); forms[q] = (248 - comp, comp)
check('Proposition 7.1: sixteen with q minus signs gives a real form only for q = 0, 4, 8, 12, 16; signatures (0,248), (112,136), (128,120)',
      forms == {0: (0, 248), 2: None, 4: (112, 136), 6: None, 8: (128, 120), 10: None, 12: (112, 136), 14: None, 16: (0, 248)}, str(forms))
def minus(n_minus_K, n_minus_L): return n_minus_K + n_minus_L
check('Proposition 7.1: the four with its light cone (one sign apart) needs 3 or 11 minus signs in the twelve for the form (112,136) of Paper 17, 7 for (128,120); '
      'the six and the ten both with their light cones give q = 2 or 14: no real form',
      forms[1 + 3] == (112, 136) and forms[3 + 9] == (112, 136) and forms[1 + 11] == (112, 136) and forms[1 + 7] == (128, 120)
      and forms[1 + 1] is None and forms[5 + 9] is None and forms[1 + 9] is None and forms[5 + 1] is None)

def formq(q): return forms.get(q) if q % 2 == 0 else None
def cones(parts): return {c: formq(sum(c)) for c in itertools.product(*[(1, n - 1) for n in parts]) if formq(sum(c))}
c4 = cones((4, 4, 4, 4))
check('Proposition 7.1(d): with every part keeping its light cone, 6+10 and 4+6+6 have no real form; 4+4+4+4 has one exactly when an even '
      'number enter with -eta: (112,136) when all four alike, (128,120) when two and two, none when three and one',
      cones((6, 10)) == {} and cones((4, 6, 6)) == {} and c4[(1, 1, 1, 1)] == (112, 136) and c4[(3, 3, 3, 3)] == (112, 136)
      and all(v == (128, 120) for c, v in c4.items() if sorted(c) == [1, 1, 3, 3]) and len(c4) == 8
      and all(sum(1 for x in c if x == 1) % 2 == 0 for c in c4))

print('\n%d checks; %s' % (len(RES), 'all pass' if all(RES) else 'FAILURES: %d' % (len(RES) - sum(RES))))
