intersubject.py — src/22-quantum

The script src/22-quantum/intersubject.py of the validation package of the paper 22-qm, rendered with an anchor per line. ▶ run the predicates on Google Colab.

22-quantum ledgersrc/22-quantum/intersubject.py · 14.3 KBintersubject.pyColab
1## intersubject.py2## Open item (3): consistency of sequential registrations by distinct Subjects.3## Two Subjects S, S' read one Object O in the Carrier F_421. Cores4##   K  = Phi_S  cap Phi_O = C_d,   K' = Phi_S' cap Phi_O = C_d',5##   common core  K^ = K cap K' = C_e,  e = gcd(d, d') = gcd(n_S, n_S', n_O),6## with 4 | e for symmetry-complete shells; generically K^ = Q4 (e = 4).7##8## Result (verified, exact arithmetic in the ledger Z[zeta_{n_O}]; no floats):9##  (I)  Order-independent joint refinement. The S- and S'-fibre partitions of10##       Phi_O refine to the partition by K^; each non-empty joint cell11##       C = F_a cap F'_a' is one K^-coset, the same for both registration orders.12##  (II) Shared-core agreement. For a winding psi_s the selection rule lets S13##       register only in channels r = s (mod d) and S' only in r' = s (mod d');14##       both reduce to the one core index s (mod e), so S and S' induce the15##       identical core character eta_{s mod e} on K^ -- the same quarter-turn datum.16##  (III) No contradiction; order-independence on the shared cell. A sequence is17##       realisable in a given order exactly when its first registration is18##       selection-allowed, the fibres meet, and the channels agree on K^19##       (r = r' mod e). For ANY realisable sequence, in EITHER order, the joint20##       cell C is one K^-coset and the post-state restricted to C is the core21##       character eta_{s mod e}. So the two Subjects never assign different22##       values to the shared core. The post-state off the shared cell sits on23##       the last frame's fibre -- ordinary back-action, not a contradiction.24##25## Carrier F_421 (g = 2, N = 420). Configurations:26##   A  O_29 read by S = S_61 and S' = S_13   (equal cores, K = K' = Q4)27##   B  O_61 read by S = S_29 and S' = S_13   (embedded cores, K = Q4 < K' = C_12)28##   R  abstract C_24, cores C_12 and C_8     (incomparable, gcd = C_4): part (I)2930from math import gcd31from itertools import product3233PASS = 034def report(label, ok):35    global PASS36    print(('PASS ' if ok else 'FAIL ') + label)37    assert ok, label38    PASS += 13940def lcm(a, b):41    return a * b // gcd(a, b)4243# ----------------------------------------------------------------------44# Exact cyclotomic ring Z[zeta_n] = Z[x]/(Phi_n), integer coefficients.45# ----------------------------------------------------------------------46def _trim(a):47    while len(a) > 1 and a[-1] == 0:48        a.pop()49    return a5051def _mul(a, b):52    r = [0] * (len(a) + len(b) - 1)53    for i, x in enumerate(a):54        if x:55            for j, y in enumerate(b):56                r[i + j] += x * y57    return _trim(r)5859def _divexact(a, b):                       # exact quotient, b monic60    a = a[:]; db = len(b) - 1; q = [0] * (len(a) - db)61    for i in range(len(a) - 1, db - 1, -1):62        c = a[i]63        if c:64            q[i - db] = c65            for j, bc in enumerate(b):66                a[i - db + j] -= c * bc67    return _trim(q)6869def _mod(a, m):                            # remainder mod monic m70    a = a[:]; dm = len(m) - 171    while len(a) - 1 >= dm and not (len(a) == 1 and a[0] == 0):72        if a[-1] == 0:73            a.pop(); continue74        c = a[-1]; sh = len(a) - 1 - dm75        for j, mc in enumerate(m):76            a[sh + j] -= c * mc77        _trim(a)78    return _trim(a)7980_CYC = {}81def cyclotomic(n):82    if n in _CYC:83        return _CYC[n]84    num = [-1] + [0] * (n - 1) + [1]       # x^n - 185    for d in range(1, n):86        if n % d == 0:87            num = _divexact(num, cyclotomic(d))88    _CYC[n] = num89    return num9091class Cyc:92    __slots__ = ('n', 'a')93    def __init__(self, n, a):94        self.n = n95        self.a = _mod(a, cyclotomic(n))96    @staticmethod97    def mono(n, e, k=1):98        e %= n99        return Cyc(n, [0] * e + [k])100    @staticmethod101    def zero(n):102        return Cyc(n, [0])103    def __add__(s, t):104        m = max(len(s.a), len(t.a)); r = [0] * m105        for i, v in enumerate(s.a): r[i] += v106        for i, v in enumerate(t.a): r[i] += v107        return Cyc(s.n, r)108    def __mul__(s, t):109        return Cyc(s.n, _mul(s.a, t.a))110    def conj(s):                            # zeta -> zeta^{-1}111        out = Cyc.zero(s.n)112        for e, v in enumerate(s.a):113            if v:114                out = out + Cyc.mono(s.n, (-e) % s.n, v)115        return out116    def is_zero(s):117        return len(s.a) == 1 and s.a[0] == 0118    def __eq__(s, t):119        return (s + Cyc(s.n, [-c for c in t.a])).is_zero()120121# self-test: sum of all d-th roots of unity vanishes in Z[zeta_n].122_s = Cyc.zero(28)123for ell in range(4):124    _s = _s + Cyc.mono(28, 7 * ell)125report('ring Z[zeta_28] exact: 1 + i + i^2 + i^3 = 0 (cyclotomic reduction)', _s.is_zero())126127# ----------------------------------------------------------------------128# Carrier and observation.  States are sparse dicts {exponent: Cyc} (nonzero only).129# ----------------------------------------------------------------------130p, g = 421, 2131N = p - 1132def order_mod(a, p):133    x, k = 1, 0134    while True:135        x = (x * a) % p; k += 1136        if x == 1: return k137report('admissibility: 421 = 4*105+1 prime-shell, g = 2 primitive (order 420)',138       p % 4 == 1 and order_mod(g, p) == N)139140def fibre(nO, d, alpha):141    step = nO // d142    return frozenset((alpha + step * ell) % nO for ell in range(d))143144def eta(nO, d, r, ell):145    return Cyc.mono(nO, (nO // d) * r * ell)146147def amplitude(state, nO, d, r, alpha):148    step = nO // d; acc = Cyc.zero(nO)149    for ell in range(d):150        j = (alpha + step * ell) % nO151        v = state.get(j)152        if v is not None:153            acc = acc + eta(nO, d, r, ell).conj() * v154    return acc155156def luders(state, nO, d, r, alpha):        # sparse post-state on the fibre157    psi = amplitude(state, nO, d, r, alpha)158    if psi.is_zero():159        return {}160    step = nO // d; out = {}161    for ell in range(d):162        j = (alpha + step * ell) % nO163        out[j] = eta(nO, d, r, ell) * psi164    return out165166def winding(nO, s):167    return {j: Cyc.mono(nO, s * j) for j in range(nO)}168169def support(state):170    return frozenset(state.keys())171172def restrict(state, cell):173    return {j: state[j] for j in cell if j in state}174175def proportional(X, Y):                    # equal support, proportional by one ledger scalar176    SX, SY = support(X), support(Y)177    if SX != SY or not SX:178        return SX == SY179    S = sorted(SX)180    for i in S:181        for j in S:182            if not (X[i] * Y[j] == X[j] * Y[i]):183                return False184    return True185186def k_cosets(nO, e):187    step = nO // e; seen, out = set(), []188    for a in range(nO):189        cs = frozenset((a + step * ell) % nO for ell in range(e))190        if cs not in seen:191            seen.add(cs); out.append(cs)192    return out193194def transported_char(nO, e, idx, coset):   # eta_idx of K^ transported on one K^-coset195    rep = min(coset); step = nO // e; out = {}196    for j in coset:197        ell = ((j - rep) // step) % e198        out[j] = Cyc.mono(nO, (nO // e) * idx * ell)199    return out200201# ----------------------------------------------------------------------202# Configurations.203# ----------------------------------------------------------------------204A = dict(nO=28, nS=60, nSp=12, tag="A  O_29 | S=S_61, S'=S_13  (equal cores Q4)")205B = dict(nO=60, nS=28, nSp=12, tag="B  O_61 | S=S_29, S'=S_13  (embedded, K=Q4 < K'=C_12)")206for cfg in (A, B):207    nO, nS, nSp = cfg['nO'], cfg['nS'], cfg['nSp']208    d, dp = gcd(nS, nO), gcd(nSp, nO)209    e = gcd(gcd(nS, nSp), nO)210    cfg.update(d=d, dp=dp, e=e)211    report(f"[{cfg['tag']}] cores d={d}, d'={dp}, common e={e}; 4|e and e=|Q4|=4",212           e == gcd(d, dp) and e % 4 == 0 and e == 4)213214# ======================================================================215# (I) Order-independent joint refinement.216# ======================================================================217for cfg in (A, B):218    nO, d, dp, e = cfg['nO'], cfg['d'], cfg['dp'], cfg['e']219    F = [fibre(nO, d, a) for a in range(nO // d)]220    Fp = [fibre(nO, dp, a) for a in range(nO // dp)]221    K = set(k_cosets(nO, e)); ok, cells = True, 0222    for f in F:223        for fp in Fp:224            it = f & fp225            if it:226                cells += 1227                if it != (fp & f) or frozenset(it) not in K:228                    ok = False229    report(f"[{cfg['tag']}] (I) each joint cell C = F cap F' is one K^-coset, order-symmetric", ok)230    report(f"[{cfg['tag']}] (I) joint refinement = partition by K^ ([Phi_O:K^]={nO//e} cells)",231           cells == nO // e)232233nO = 24; F = [fibre(nO, 12, a) for a in range(2)]; Fp = [fibre(nO, 8, a) for a in range(3)]234K = set(k_cosets(nO, 4)); ok, cells = True, 0235for f in F:236    for fp in Fp:237        it = f & fp238        if it:239            cells += 1240            if it != (fp & f) or frozenset(it) not in K:241                ok = False242report("R  C_24 incomparable cores C_12,C_8 (gcd C_4): (I) joint cells are C_4 cosets, "243       "order-symmetric", ok)244report("R  C_24 incomparable: refinement = partition by C_4 ([24:4]=6 cells)", cells == 6)245246# ======================================================================247# (II) Shared-core agreement via the selection rule, every winding.248# ======================================================================249for cfg in (A, B):250    nO, d, dp, e = cfg['nO'], cfg['d'], cfg['dp'], cfg['e']251    ok_sel = ok_chr = True252    for s in range(nO):253        st = winding(nO, s)254        live = {r for r in range(d)255                if any(not amplitude(st, nO, d, r, a).is_zero() for a in range(nO // d))}256        livep = {r for r in range(dp)257                 if any(not amplitude(st, nO, dp, r, a).is_zero() for a in range(nO // dp))}258        if live != {s % d} or livep != {s % dp}:259            ok_sel = False; break260        if (s % d) % e != s % e or (s % dp) % e != s % e:261            ok_sel = False; break262        ch  = [eta(nO, e, (s % d) % e, ell) for ell in range(e)]263        chp = [eta(nO, e, (s % dp) % e, ell) for ell in range(e)]264        chs = [eta(nO, e, s % e, ell) for ell in range(e)]265        if not (all(x == y for x, y in zip(ch, chp)) and all(x == y for x, y in zip(ch, chs))):266            ok_chr = False; break267    report(f"[{cfg['tag']}] (II) selection: live(S)={{s mod d}}, live(S')={{s mod d'}}, "268           f"both reduce to s mod 4 (all {nO} windings)", ok_sel)269    report(f"[{cfg['tag']}] (II) S and S' induce the identical core character "270           f"eta_(s mod 4) on Q4 (all windings)", ok_chr)271272# ======================================================================273# (III) Realisability, no contradiction, order-independence on the shared cell.274# ======================================================================275def seq(state, first, second, nO):276    (d1, r1, a1), (d2, r2, a2) = first, second277    s1 = luders(state, nO, d1, r1, a1)278    if not s1:279        return {}280    return luders(s1, nO, d2, r2, a2)281282for cfg in (A, B):283    nO, d, dp, e = cfg['nO'], cfg['d'], cfg['dp'], cfg['e']284    nout, noutp = nO // d, nO // dp285    Kset = set(k_cosets(nO, e))286    ok_pred = ok_value = ok_both = True287    n_fwd = n_both = 0288    for s in range(lcm(d, dp)):                          # residue-exhaustive winding inputs289        st = winding(nO, s)290        for (r, a, rp, ap) in product(range(d), range(nout), range(dp), range(noutp)):291            C = fibre(nO, d, a) & fibre(nO, dp, ap)292            meet = bool(C)293            agree = (r % e) == (rp % e)294            pred_f = meet and (r % d == s % d) and agree295            pred_r = meet and (rp % dp == s % dp) and agree296            fwd = seq(st, (d, r, a), (dp, rp, ap), nO)297            rev = seq(st, (dp, rp, ap), (d, r, a), nO)298            if bool(fwd) != pred_f or bool(rev) != pred_r:299                ok_pred = False300            ref = transported_char(nO, e, s % e, C) if meet else None301            if fwd:302                n_fwd += 1303                if frozenset(C) not in Kset or not proportional(restrict(fwd, C), ref):304                    ok_value = False305            if rev:306                if frozenset(C) not in Kset or not proportional(restrict(rev, C), ref):307                    ok_value = False308            if fwd and rev:309                n_both += 1310                if not proportional(restrict(fwd, C), restrict(rev, C)):311                    ok_both = False312    report(f"[{cfg['tag']}] (III) realisability predicate exact, both orders "313           f"(first selection-allowed, fibres meet, r=r' mod 4)", ok_pred)314    report(f"[{cfg['tag']}] (III) every realisable sequence reads core value "315           f"eta_(s mod 4) on the K^-coset C  [{n_fwd} forward cases]", ok_value)316    report(f"[{cfg['tag']}] (III) both-order sequences agree on the shared cell C "317           f"[{n_both} cases]", ok_both)318319# ======================================================================320# (III') Gaussian-integer superposition input (config A): shared-cell agreement.321# ======================================================================322nO, d, dp, e = A['nO'], A['d'], A['dp'], A['e']323nout, noutp = nO // d, nO // dp; iexp = nO // 4324st = {}325for j in range(nO):326    acc = Cyc.zero(nO)327    for s in range(nO):328        cs = Cyc.mono(nO, 0, 1 + s) + Cyc.mono(nO, iexp, 1 + (s % 5))329        acc = acc + cs * Cyc.mono(nO, s * j)330    if not acc.is_zero():331        st[j] = acc332ok_sup, both = True, 0333for (r, a, rp, ap) in product(range(d), range(nout), range(dp), range(noutp)):334    C = fibre(nO, d, a) & fibre(nO, dp, ap)335    fwd = seq(st, (d, r, a), (dp, rp, ap), nO)336    rev = seq(st, (dp, rp, ap), (d, r, a), nO)337    if fwd and rev:338        both += 1339        if not proportional(restrict(fwd, C), restrict(rev, C)):340            ok_sup = False341report(f"[{A['tag']}] (III') Gaussian-integer superposition input: {both} both-order "342       f"sequences, all agree on the shared cell", ok_sup)343344# ======================================================================345# Teeth: channels disagreeing on Q4 (r != r' mod 4) are forbidden in BOTH orders.346# ======================================================================347nO, d, dp, e = A['nO'], A['d'], A['dp'], A['e']348nout, noutp = nO // d, nO // dp349st = winding(nO, 1); bad = []350for (r, a, rp, ap) in product(range(d), range(nout), range(dp), range(noutp)):351    if (r % e) != (rp % e):352        fwd = seq(st, (d, r, a), (dp, rp, ap), nO)353        rev = seq(st, (dp, rp, ap), (d, r, a), nO)354        bad.append(bool(fwd) or bool(rev))355report("[teeth] channels disagreeing on Q4 (r != r' mod 4) are null in BOTH orders "356       "-- inconsistency would show as nullity, never as a contradiction",357       len(bad) > 0 and not any(bad))358359print(f"\nintersubject: {PASS}/{PASS} checks passing (exact arithmetic in Z[zeta_n], no floats)")360