Research source · python

verify_structural_controls.py

site/public/evidence/supertannakian-semisimplicity/candidate-resolution-checks/verify_structural_controls.py

265 lines. Source is displayed for inspection; it is not executed by this page.

File fingerprint

SHA-256: 597febd84b7995974dc8dc5557ebe76c8e53cd9ee45ba654ab58a21c6cdb5048

#!/usr/bin/env python3
"""Exact finite controls for the Kac--Grassmann candidate proof.

These calculations test sign conventions and two smallest model algebras.
They are not used as a completeness argument.
"""

from fractions import Fraction
from itertools import product


ZERO = (Fraction(0),) * 4
ONE = (Fraction(1), Fraction(0), Fraction(0), Fraction(1))


def madd(a, b):
    return tuple(x + y for x, y in zip(a, b))


def mneg(a):
    return tuple(-x for x in a)


def mscale(c, a):
    return tuple(c * x for x in a)


def mmul(a, b):
    a00, a01, a10, a11 = a
    b00, b01, b10, b11 = b
    return (
        a00 * b00 + a01 * b10,
        a00 * b01 + a01 * b11,
        a10 * b00 + a11 * b10,
        a10 * b01 + a11 * b11,
    )


def comm(a, b):
    return madd(mmul(a, b), mneg(mmul(b, a)))


E = [
    (Fraction(1), Fraction(0), Fraction(0), Fraction(0)),
    (Fraction(0), Fraction(1), Fraction(0), Fraction(0)),
    (Fraction(0), Fraction(0), Fraction(1), Fraction(0)),
    (Fraction(0), Fraction(0), Fraction(0), Fraction(1)),
]
N = E[1]


def aadd(x, y):
    return madd(x[0], y[0]), madd(x[1], y[1])


def aneg(x):
    return mneg(x[0]), mneg(x[1])


def amul(x, y):
    # M_2 is placed in even degree; theta is odd and theta^2=0.
    return mmul(x[0], y[0]), madd(mmul(x[0], y[1]), mmul(x[1], y[0]))


def qmap(x):
    # Q(b_0 + theta b_1) = b_1 + theta [N,b_0].
    return x[1], comm(N, x[0])


def ad_n(x):
    return comm(N, x[0]), comm(N, x[1])


def theta_left(x):
    return ZERO, x[0]


def iterate(f, x, n):
    for _ in range(n):
        x = f(x)
    return x


def check_rank_one_control():
    even_basis = [(e, ZERO) for e in E]
    odd_basis = [(ZERO, e) for e in E]
    homogeneous = [(x, 0) for x in even_basis] + [(x, 1) for x in odd_basis]

    leibniz = 0
    for (a, pa), (b, _pb) in product(homogeneous, repeat=2):
        lhs = qmap(amul(a, b))
        rhs_second = amul(a, qmap(b))
        if pa:
            rhs_second = aneg(rhs_second)
        rhs = aadd(amul(qmap(a), b), rhs_second)
        assert lhs == rhs
        leibniz += 1

    for x, _p in homogeneous:
        assert iterate(qmap, x, 2) == ad_n(x)
        assert iterate(qmap, x, 6) == (ZERO, ZERO)
        contracted = aadd(qmap(theta_left(x)), theta_left(qmap(x)))
        assert contracted == x

    witness = (E[2], ZERO)
    assert iterate(qmap, witness, 2) != (ZERO, ZERO)
    return {
        "homogeneous_leibniz_pairs": leibniz,
        "q_squared_equals_ad_N": True,
        "q_squared_is_nonzero": True,
        "q_to_the_sixth_is_zero": True,
        "theta_contraction_identity": True,
    }


def exterior_product(left, right):
    if left & right:
        return 0, 0
    inversions = 0
    for i in range(2):
        if left & (1 << i):
            inversions += sum(1 for j in range(i) if right & (1 << j))
    return (-1 if inversions % 2 else 1), left | right


QBASIS = [(q, mask) for q in range(2) for mask in range(4)]


def basis_parity(b):
    q, mask = b
    return (q + mask.bit_count()) % 2


def qlambda_mul(a, b):
    qa, ma = a
    qb, mb = b
    exterior_sign, mask = exterior_product(ma, mb)
    if not exterior_sign:
        return 0, (0, 0)
    tensor_sign = -1 if (ma.bit_count() * qb) % 2 else 1
    return exterior_sign * tensor_sign, ((qa + qb) % 2, mask)


def rational_rank(rows):
    rows = [list(map(Fraction, row)) for row in rows if any(row)]
    if not rows:
        return 0
    ncols = len(rows[0])
    rank = 0
    for col in range(ncols):
        pivot = next((i for i in range(rank, len(rows)) if rows[i][col]), None)
        if pivot is None:
            continue
        rows[rank], rows[pivot] = rows[pivot], rows[rank]
        scale = rows[rank][col]
        rows[rank] = [x / scale for x in rows[rank]]
        for i in range(len(rows)):
            if i == rank or not rows[i][col]:
                continue
            factor = rows[i][col]
            rows[i] = [x - factor * y for x, y in zip(rows[i], rows[rank])]
        rank += 1
    return rank


def supercenter_kernel_dimension(parity):
    candidates = [b for b in QBASIS if basis_parity(b) == parity]
    equations = []
    for a in QBASIS:
        out_keys = QBASIS
        for out in out_keys:
            row = []
            for z in candidates:
                s1, b1 = qlambda_mul(z, a)
                s2, b2 = qlambda_mul(a, z)
                koszul = -1 if parity * basis_parity(a) else 1
                row.append((s1 if b1 == out else 0) - koszul * (s2 if b2 == out else 0))
            equations.append(row)
    return len(candidates) - rational_rank(equations)


def check_queer_center_and_separability():
    # Q(1) has basis 1 (even), j (odd), with j^2=1.  Tensoring with
    # Lambda(theta_1,theta_2) should have supercenter exactly Lambda(2).
    even_dim = supercenter_kernel_dimension(0)
    odd_dim = supercenter_kernel_dimension(1)
    assert (even_dim, odd_dim) == (2, 2)

    # e_Q=(1 tensor 1 + j tensor j)/2: multiplication is 1, and j e=e j.
    # Encode tensors by coefficients on (1x1,1xj,jx1,jxj).
    e_q = (Fraction(1, 2), Fraction(0), Fraction(0), Fraction(1, 2))
    mu = e_q[0] + e_q[3]
    left_j = (Fraction(0), e_q[3], e_q[0], Fraction(0))
    right_j = (Fraction(0), e_q[0], e_q[3], Fraction(0))
    assert mu == 1
    assert left_j == right_j

    # Matrix-type control for M(1|1).  We use the fixed-column element
    # e=sum_i E_i0 tensor E_0i.  The averaged Casimir checked in the original
    # attack is also valid; the publication audit verifies both formulas.
    tensor_e = {}
    for i in range(2):
        tensor_e[(i, 0, 0, i)] = Fraction(1)

    def left_matrix_unit(k, ell):
        out = {}
        for (i, j, r, s), coefficient in tensor_e.items():
            if ell == i:
                key = (k, j, r, s)
                out[key] = out.get(key, 0) + coefficient
        return out

    def right_matrix_unit(k, ell):
        out = {}
        for (i, j, r, s), coefficient in tensor_e.items():
            if s == k:
                key = (i, j, r, ell)
                out[key] = out.get(key, 0) + coefficient
        return out

    for k in range(2):
        for ell in range(2):
            assert left_matrix_unit(k, ell) == right_matrix_unit(k, ell)

    matrix_mu = [[Fraction(0) for _ in range(2)] for _ in range(2)]
    for (i, j, r, s), coefficient in tensor_e.items():
        if j == r:
            matrix_mu[i][s] += coefficient
    assert matrix_mu == [[1, 0], [0, 1]]

    averaged_casimir = {}
    for i in range(2):
        for j in range(2):
            averaged_casimir[(i, j, j, i)] = Fraction(1, 2)

    original_tensor_e = tensor_e
    tensor_e = averaged_casimir
    for k in range(2):
        for ell in range(2):
            assert left_matrix_unit(k, ell) == right_matrix_unit(k, ell)
    tensor_e = original_tensor_e

    return {
        "supercenter_Q1_tensor_Lambda2_even_dimension": even_dim,
        "supercenter_Q1_tensor_Lambda2_odd_dimension": odd_dim,
        "queer_separability_idempotent": True,
        "matrix_fixed_column_separability_idempotent": True,
        "averaged_matrix_casimir_separability_idempotent": True,
    }


def main():
    rank_one = check_rank_one_control()
    queer = check_queer_center_and_separability()
    print("rank_one_control")
    for key, value in rank_one.items():
        print(f"  {key}={value}")
    print("center_and_separability_controls")
    for key, value in queer.items():
        print(f"  {key}={value}")
    print("ALL EXACT CONTROLS PASSED")


if __name__ == "__main__":
    main()