From a5285f0bf839f67b2eac96bada3beb4abc934de8 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 20 Oct 2026 02:32:38 +0000 Subject: [PATCH] Audit the P104 index-to-tensor bridge without replaying events. Check the PR #3996 index against the eight local sweeps and shears, record the transpose-order gap 18432, and exhibit the omitted-side rank 10816. Co-authored-by: unpaidmoon --- research/p104-index-tensor-bridge/README.md | 94 +++++ .../p104-index-tensor-bridge/SOURCES.json | 24 ++ research/p104-index-tensor-bridge/TASK.json | 94 +++++ research/p104-index-tensor-bridge/VERIFY.json | 29 ++ .../p104-index-tensor-bridge/test_verify.py | 54 +++ research/p104-index-tensor-bridge/verify.py | 355 ++++++++++++++++++ 6 files changed, 650 insertions(+) create mode 100644 research/p104-index-tensor-bridge/README.md create mode 100644 research/p104-index-tensor-bridge/SOURCES.json create mode 100644 research/p104-index-tensor-bridge/TASK.json create mode 100644 research/p104-index-tensor-bridge/VERIFY.json create mode 100644 research/p104-index-tensor-bridge/test_verify.py create mode 100644 research/p104-index-tensor-bridge/verify.py diff --git a/research/p104-index-tensor-bridge/README.md b/research/p104-index-tensor-bridge/README.md new file mode 100644 index 0000000000..8b91b39701 --- /dev/null +++ b/research/p104-index-tensor-bridge/README.md @@ -0,0 +1,94 @@ +# Index-to-tensor bridge for the scalar P104 code + +**Audit of one published convention. No new κ.** Selected κ stays +`0.001672660197076918`. + +PR #3996 checks 763,392 literal events and, separately, the block algebra of +`U`. Its proof states the bridge between them and does not execute that +bridge. This package executes it. + +## Scope and evidence + +The index in that proof is + +```text +index(bank, i, j) = (bank*104 + i)*104 + j +``` + +Axis 0 varies `i` at fixed `j`. Axis 1 varies `j` at fixed `i`. On every +coefficient of widths 2 and 8, and on one dense width-104 state: + +- broadcasting a one-axis map `K` along axis 0 is `K tensor I` (left multiplication); +- broadcasting it along axis 1 is `I tensor K`, which right-multiplies by `K^t`. + +The second identity fails if the column fiber is implemented as right +multiplication by `K`. The four sweeps `U`, `U^{-1}`, `U^t` and `U^{-t}` of +the canonical code are checked in that form. The four shears are the block +maps with factors `A` and `M`: lower/upper `A` use axis 0 and axis 1 of `A`, +and the coded Gram shears use `M = U U^t`. + +On the canonical fixture +`research/p104-native-channel/inputs/P104-FIXTURE.json` +(SHA256 `516c06f6ec3cb84be588c546108de897650288576dd5fbf5fe44b9c5546ad8a4`), +an independent root enumeration rebuilds the 768 signed-half entries. Their +ASCII digest is +`88e9a726e8c8aec055bfd7cd024883b5c8ecbda0cd6471e591a08c43a108a535`, +the same digest PR #3996 binds. For this `U`: + +- `A = U^t P U` satisfies `A^2 = 13 A`, and `(I-A)` has an exhibited rational inverse; +- `M = U U^t` is invertible, and `M` is not `U^t U`; +- the bank block `P tensor (M - U^t U)` has Frobenius square **18432**; +- `N - P = U^{-t}(I-A)U^{-1}` is invertible, so each omitted side + `(N-P) tensor M` and `M tensor (N-P)` has rational rank **10816**. + +The contraction identity +`||sum c_k A_k tensor B_k||_F^2 = sum c_k c_l ` +was checked against the dense Kronecker matrix at widths 2 and 3, including +a nonzero sample. The width-104 gap uses that identity. Both factors of an +omitted side have exhibited inverses. The identity +`(A tensor B)(A^{-1} tensor B^{-1}) = I` was checked on a 2-by-2 pair. At +width 104 it is the same entrywise rule, not a stored 10816-square product. +That is the rank step. + +This does **not** replay the 763,392 events, localize a fiber of PR #3979, or +supply a physical consumer. Algebraic rank is not a native-call price. No +supplier is admitted. + +## Reproduce + +Python 3.12, standard library, from the repository root: + +```sh +python3.12 -B research/p104-index-tensor-bridge/verify.py +python3.12 -B research/p104-index-tensor-bridge/test_verify.py +python3.12 -B scripts/research_package.py --package research/p104-index-tensor-bridge +``` + +Expected markers: + +```text +PASS_P104_INDEX_TENSOR_BRIDGE +PASS_P104_INDEX_TENSOR_BRIDGE_TESTS +``` + +The tests reject a column convention that drops the transpose, and they reject +a one-entry change to `B2`. + +## Open next questions + +1. One frozen encoder fiber from PR #3996 should be compared with axis 0 of + `U`, without calling that package's checker. The word bytes are on head + `b8dd4e04bf8490aca121abc7ba0e503651db6c97`, not on this main checkout. +2. A repeated physical consumer still has to pay `(N-P) tensor M` or show a + different interface. Rank 10816 says the Gram shear is not that payment. + +## Credit + +The code, the index sentence, and the rank claim under audit are Chris R / +Clear1nsight's PR #3979, audited by ToikY in PR #3996. The fixture and root +normalization come from the retained P104 native channel (Rohan Arun, Chafik +Boukhalfa, Adam Gall, and the native/E8 lineage named there). This package +does not import either checker's source. + +Prepared by unpaidmoon with substantial Cursor Grok assistance. Apache-2.0. +No independent human review is claimed. diff --git a/research/p104-index-tensor-bridge/SOURCES.json b/research/p104-index-tensor-bridge/SOURCES.json new file mode 100644 index 0000000000..6441450d9e --- /dev/null +++ b/research/p104-index-tensor-bridge/SOURCES.json @@ -0,0 +1,24 @@ +{ + "schema_version": 1, + "base_commit": "bb4bccbf42844d2801487450727c2f63e10d1d0f", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0" + }, + { + "path": "research/p104-native-channel/inputs/P104-FIXTURE.json", + "usage": "input", + "git_blob": "2e16f99b295bb386fd13bd8fbd57b42ef54143a9", + "sha256": "516c06f6ec3cb84be588c546108de897650288576dd5fbf5fe44b9c5546ad8a4" + } + ] +} diff --git a/research/p104-index-tensor-bridge/TASK.json b/research/p104-index-tensor-bridge/TASK.json new file mode 100644 index 0000000000..4dfea5e6f8 --- /dev/null +++ b/research/p104-index-tensor-bridge/TASK.json @@ -0,0 +1,94 @@ +{ + "schema_version": 1, + "task_id": "p104-side-correction", + "priority_revision": 6, + "base_commit": "bb4bccbf42844d2801487450727c2f63e10d1d0f", + "original_card": { + "id": "p104-side-correction", + "question": "Can the proposed P104 joint endpoint flags be realized by a chronological correction program with coefficients, dirty restoration and an affordable complete bill?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/p104-native-channel/README.md", + "research/p104-native-channel/PROOF.md", + "docs/research/community-efficient1000-review.md", + "research/p104-joint-unit-flags/README.md" + ], + "methods": [ + "Construct one side-correction word at an explicit chronological cut with the needed frames still available.", + "Derive a lower bound on the side correction and hosting costs that decides whether this channel can beat the selected budget." + ], + "acceptance_gate": "An exact arbitrary-input identity, source/target frame availability and restoration at the chosen cut, plus the complete channel+correction+idle/hosting bill or an explicit favorable bound. The native channel alone is not a supplier. A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read the revision-6 family record and #2981 static joint flags, alongside the reviewed #1991 channel. #2981 is an author-checked source archive, not an independently validated executable correction or a refutation of program-level lifetime floors.", + "scope": "Source-bound orientation only. Read the named package and review before relying on its local evidence; this command is not its replay or supplier admission." + }, + "first_experiment": "After checking live handoffs, pin one named collection from #2981 and attach acquisition/delivery times, source dependencies and coefficient requirements. Test legal access and arbitrary dirty restoration; price any completion against the full channel/endpoint/hosting allowance. Stop with the exact missing implication or a scoped counterexample rather than expanding the static cover census.", + "bottleneck_link": "Completing an already realized changed channel tests a concrete construction opportunity, instead of refining the incumbent packing. A positive local result still needs global and all-size admission.", + "allowed_variations": [ + "One correction factorization, one chronological cut, or one explicit hosting obstruction.", + "A changed correction schedule with an updated full bill and native frame contract." + ], + "scope_change_triggers": [ + "Recompiling the already certified low-rank channel without closing a new obligation.", + "Treating a pending ancestor, local histogram or unpriced side correction as an admitted global supplier.", + "Repeating a correction or physical conversion already supplied by a pending follow-up without adding independent coverage or a different unresolved obligation.", + "Repeating the 208-flag static matching or calling a static nested cover a chronological correction program. Independent audit of that certificate is distinct and remains useful." + ], + "overlap_terms": [ + "P104", + "I-G/2", + "side correction", + "native channel", + "1972", + "1991", + "2586", + "endpoint transport", + "physical dual", + "relay composition", + "2981", + "joint unit flags", + "acquisition delivery", + "static nesting" + ], + "existing_checks": [ + { + "scope": "PR #2981 reports static joint endpoint flags and a matching of 208 departure and arrival flags; archival intake is not independent verification.", + "evidence": "research/p104-joint-unit-flags/README.md", + "remaining": "Independent flag check and a chronological coefficient program with dirty restoration and a complete cost.", + "status": "author-checked", + "source_commit": "3d24b92d8ba057b57cb2d480170ec407520e6882", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Under the index in PR #3996, do the eight stated local sweeps and shears equal the published tensor factors, and is the omitted identity side full rank?", + "scope_change_reason": "The catalogue card asks for a chronological correction program. Discussion #1166 comment 19035716 instead asks for an independent inspection of PR #3996's literal-index-to-tensor bridge. This package answers that audit and does not construct a new correction word.", + "bottleneck_link": "No kappa change. The bridge decides whether the scalar code's local maps are the tensors P tensor M and M tensor P with M = U U^t. Replacing M by U^t U changes the coded shear. The omitted identity side stays rank 10816, so the Gram-only saving is not an identity-shear completion.", + "budget_minutes": 60, + "stop_rule": "Stop after the index bridge, the transpose-order gap, and the rank consequence. Do not replay the 763,392 events and do not build a physical consumer.", + "outcome": "partial", + "evidence": "PASS_P104_INDEX_TENSOR_BRIDGE and PASS_P104_INDEX_TENSOR_BRIDGE_TESTS. The wrong-factor block Frobenius square is 18432/1. Literal events were not replayed.", + "author": "unpaidmoon", + "ai_assistance": "Cursor Grok 4.7 agent, including the verifier and tests.", + "open_questions": [ + { + "question": "Does one frozen fiber of PR #3979's event list implement these eight broadcasts?", + "why_it_matters": "This package certifies the operator interpretation of the stated maps. It does not read the 763,392 events, so a wrong event could still fail to be the tensor factor.", + "first_step": "Localize one encoder fiber from the frozen PR #3996 word bytes and compare it with axis-0 of U, without calling that package's checker.", + "blocked_by": "The word bytes live on PR #3996 head b8dd4e04bf8490aca121abc7ba0e503651db6c97 and are not on this main checkout." + }, + { + "question": "Is there one repeated physical consumer whose complete bill keeps the k=2 Gram saving?", + "why_it_matters": "Rank 10816 says the identity shear is not the Gram shear. A consumer that pays the omitted side can erase the scalar saving.", + "first_step": "Pin one chronological producer/consumer pair and price N-P tensor M with owners, frames, and dirty return before any native expansion.", + "blocked_by": "No such pair is fixed. PR #3996 open question 1 is still open." + } + ] +} diff --git a/research/p104-index-tensor-bridge/VERIFY.json b/research/p104-index-tensor-bridge/VERIFY.json new file mode 100644 index 0000000000..6c204efd0b --- /dev/null +++ b/research/p104-index-tensor-bridge/VERIFY.json @@ -0,0 +1,29 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/p104-native-channel/inputs/P104-FIXTURE.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Index bridge at widths 2, 8 and 104; A^2=13A; exhibited inverse of N-P; positive transpose-order gap 18432." + }, + { + "argv": [ + "{python}", + "-B", + "{package}/test_verify.py" + ], + "timeout_seconds": 120, + "checks": "Wrong column convention and a one-entry B2 mutation both fail closed." + } + ] +} diff --git a/research/p104-index-tensor-bridge/test_verify.py b/research/p104-index-tensor-bridge/test_verify.py new file mode 100644 index 0000000000..d4e699fbb8 --- /dev/null +++ b/research/p104-index-tensor-bridge/test_verify.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +"""Failure controls for the index-to-tensor bridge. Standard library only.""" +from __future__ import annotations + +import json +from pathlib import Path +import sys + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import verify + + +def require(condition, message): + if not condition: + raise SystemExit("FAIL: " + message) + + +def test_wrong_column_convention(): + operator = verify.witness(verify.N) + state = verify.state_from(verify.N, 4) + fiber = verify.axis1_broadcast(operator, state) + omitted_transpose = verify.matmul(state, operator) + gaps = verify.compare(fiber, omitted_transpose) + require(gaps > 0, "omitting K^t must disagree on the non-symmetric witness") + + +def test_mutated_coefficient_breaks_square(): + b2, _gram = verify.load_b2() + mutated = [row[:] for row in b2] + mutated[0][0] += 1 + try: + verify.check_geometry(mutated) + except SystemExit as exc: + require(str(exc).startswith("FAIL:"), "mutation must fail closed") + return + raise SystemExit("FAIL: mutated B2 was accepted") + + +def test_receipt_shape(): + b2, gram = verify.load_b2() + require(gram[0][0] == 8 and len(b2) == 8 and len(b2[0]) == 96, "fixture shape") + require(verify.factored_frobenius_square([(1, [[1]], [[1]])]) == 1, "one-cell contraction") + + +def main(): + test_wrong_column_convention() + test_mutated_coefficient_breaks_square() + test_receipt_shape() + print("PASS_P104_INDEX_TENSOR_BRIDGE_TESTS " + json.dumps({ + "groups": 3, "new_kappa": False}, sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/research/p104-index-tensor-bridge/verify.py b/research/p104-index-tensor-bridge/verify.py new file mode 100644 index 0000000000..f804021602 --- /dev/null +++ b/research/p104-index-tensor-bridge/verify.py @@ -0,0 +1,355 @@ +#!/usr/bin/env python3 +"""Index-to-tensor bridge for the scalar P104 code described in PR #3996. + +The published index is index(bank, i, j) = (bank*104 + i)*104 + j. +Axis 0 varies i at fixed j. Axis 1 varies j at fixed i. This checker +does not import PR #3996 and does not replay its 763,392 events. +""" +from __future__ import annotations + +import hashlib +import itertools +import json +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +FIXTURE = ROOT / "research/p104-native-channel/inputs/P104-FIXTURE.json" +FIXTURE_SHA256 = "516c06f6ec3cb84be588c546108de897650288576dd5fbf5fe44b9c5546ad8a4" +B2_SHA256 = "88e9a726e8c8aec055bfd7cd024883b5c8ecbda0cd6471e591a08c43a108a535" +N = 104 +PIVOTS = (0, 1, 3, 6, 22, 31, 93, 103) + + +def require(condition, message): + if not condition: + raise SystemExit("FAIL: " + message) + + +def matvec(matrix, vector): + return [sum(coefficient * entry for coefficient, entry in zip(row, vector)) + for row in matrix] + + +def matmul(left, right): + right_columns = list(zip(*right)) + return [[sum(x * y for x, y in zip(row, column)) for column in right_columns] + for row in left] + + +def transpose(matrix): + return [list(row) for row in zip(*matrix)] + + +def eye(scale=1): + return [[scale if i == j else 0 for j in range(N)] for i in range(N)] + + +def unit(length, index): + vector = [0] * length + vector[index] = 1 + return vector + + +def frobenius_inner(left, right): + return sum(x * y for row, other in zip(left, right) for x, y in zip(row, other)) + + +def dense_kronecker(left, right): + blocks = [] + for i in range(len(left)): + for j in range(len(right)): + row = [] + for p in range(len(left)): + for q in range(len(right)): + row.append(left[i][p] * right[j][q]) + blocks.append(row) + return blocks + + +def factored_frobenius_square(terms): + """||sum c_k A_k tensor B_k||_F^2 = sum c_k c_l .""" + total = 0 + for coeff, row_factor, column_factor in terms: + for other, other_row, other_column in terms: + total += (coeff * other * frobenius_inner(row_factor, other_row) + * frobenius_inner(column_factor, other_column)) + return total + + +def dense_frobenius_square(terms): + size = len(terms[0][1]) * len(terms[0][2]) + matrix = [[0] * size for _ in range(size)] + for coeff, row_factor, column_factor in terms: + block = dense_kronecker(row_factor, column_factor) + for i in range(size): + for j in range(size): + matrix[i][j] += coeff * block[i][j] + return frobenius_inner(matrix, matrix) + + +def axis0_broadcast(matrix, state): + """Apply matrix to every column. This is the axis-0 fiber broadcast.""" + width = len(matrix) + output = [[0] * width for _ in range(width)] + for column in range(width): + image = matvec(matrix, [state[row][column] for row in range(width)]) + for row in range(width): + output[row][column] = image[row] + return output + + +def axis1_broadcast(matrix, state): + """Apply matrix to every row-vector ordered by j. This is axis 1.""" + width = len(matrix) + output = [[0] * width for _ in range(width)] + for row in range(width): + image = matvec(matrix, state[row]) + output[row] = image + return output + + +def kronecker_from_index(left, right, state): + """(left tensor right) on row-major index i*n+j, summed from the coefficients.""" + width = len(left) + output = [[0] * width for _ in range(width)] + for i in range(width): + for j in range(width): + total = 0 + for p in range(width): + for q in range(width): + total += left[i][p] * right[j][q] * state[p][q] + output[i][j] = total + return output + + +def witness(width): + return [[(3 * i + 5 * j + 1) % 7 - 3 for j in range(width)] for i in range(width)] + + +def state_from(width, seed): + return [[(i * i + 3 * j + seed) % 5 - 2 for j in range(width)] for i in range(width)] + + +def compare(left, right): + gaps = 0 + for row, other in zip(left, right): + for entry, expected in zip(row, other): + if entry != expected: + gaps += 1 + return gaps + + +def check_small_index_bridge(): + """Brute-force every coefficient at widths 2 and 8, then one dense width-104 state.""" + naive_positions = 0 + for width in (2, 8): + operator = witness(width) + state = state_from(width, 1) + identity = [[1 if i == j else 0 for j in range(width)] for i in range(width)] + naive_positions += width ** 4 + require(axis0_broadcast(operator, state) == kronecker_from_index(operator, identity, state), + "axis 0 differs from K tensor I at width %d" % width) + require(axis1_broadcast(operator, state) == kronecker_from_index(identity, operator, state), + "axis 1 differs from I tensor K at width %d" % width) + swapped = axis0_broadcast(identity, state) # not used; keep identity path obvious + require(swapped == state, "identity broadcast") + operator = witness(N) + state = state_from(N, 4) + identity = eye() + # The coefficient (I tensor K)_(i j),(p q) is δ_ip K_jq. Sum that explicitly. + summed = [[0] * N for _ in range(N)] + for i in range(N): + for j in range(N): + total = 0 + for q in range(N): + total += operator[j][q] * state[i][q] + summed[i][j] = total + require(axis1_broadcast(operator, state) == summed, "axis-1 fiber differs from the index sum") + column_sum = [[0] * N for _ in range(N)] + for j in range(N): + image = matvec(operator, [state[row][j] for row in range(N)]) + for i in range(N): + column_sum[i][j] = image[i] + require(axis0_broadcast(operator, state) == column_sum, "axis-0 fiber differs from its column sum") + # One full naive Kronecker product is too large at width 104. The width-8 + # check above executed every coefficient. Here compare axis 0 with K tensor I + # through the same δ-sum the definition gives, on this dense state. + axis0_sum = [[0] * N for _ in range(N)] + for i in range(N): + for j in range(N): + total = 0 + for p in range(N): + total += operator[i][p] * state[p][j] + axis0_sum[i][j] = total + require(axis0_broadcast(operator, state) == axis0_sum, "axis 0 differs from K tensor I") + wrong = matmul(state, operator) # right multiply, omitting the transpose + require(compare(wrong, axis1_broadcast(operator, state)) > 0, + "a non-symmetric witness must expose the column transpose") + return naive_positions + + +def check_contraction_formula(): + samples = [] + for width, seed in ((2, 0), (3, 1)): + first = witness(width) + second = state_from(width, seed) + third = transpose(first) + terms = [(1, first, second), (-2, third, first), (3, second, third)] + factored = factored_frobenius_square(terms) + dense = dense_frobenius_square(terms) + require(factored == dense and factored > 0, "contraction formula mismatch") + samples.append(factored) + single = [(1, eye(), eye())] + require(factored_frobenius_square(single) == N * N, "identity tensor norm") + return samples + + +def integer_lift(b2): + """2U and 2U^{-1}. U = [I, B; 0, I] with B = B2/2.""" + upper = eye(2) + inverse = eye(2) + for i in range(8): + for j in range(96): + upper[i][8 + j] = b2[i][j] + inverse[i][8 + j] = -b2[i][j] + require(matmul(upper, inverse) == eye(4), "integer lift is a two-sided inverse up to scale 4") + require(matmul(inverse, upper) == eye(4), "inverse on the left") + return upper, inverse + + +def load_b2(): + raw = FIXTURE.read_bytes() + require(hashlib.sha256(raw).hexdigest() == FIXTURE_SHA256, "canonical P104 fixture") + section = json.loads(raw)["section4_explicit_P104"] + roots = set() + for coords in itertools.product((-2, 0, 2), repeat=8): + support = [value for value in coords if value] + if len(support) == 2 and support[0] > 0: + roots.add(coords) + for coords in itertools.product((-1, 1), repeat=8): + if coords[0] == 1 and coords.count(-1) % 2 == 0: + roots.add(coords) + removed = {tuple(row) for row in section["F0"] + section["C"]} + require(len(roots) == 120 and len(removed) == 16 and removed <= roots, "E8 root domain") + original = sorted(roots - removed) + order = list(PIVOTS) + [index for index in range(N) if index not in PIVOTS] + ports = [original[index] for index in order] + gram = [[sum(x * y for x, y in zip(row, other)) for other in ports] for row in ports] + b2 = [[gram[i][8 + j] // 4 for j in range(96)] for i in range(8)] + digest = hashlib.sha256(json.dumps(b2, separators=(",", ":")).encode("ascii")).hexdigest() + require(digest == B2_SHA256, "ordered B2 digest") + require(all(sum(b2[i][k] * b2[j][k] for k in range(96)) == 48 * int(i == j) + for i in range(8) for j in range(8)), "B2 B2^t = 48 I") + return b2, gram + + +def projector(): + return [[1 if i == j < 8 else 0 for j in range(N)] for i in range(N)] + + +def check_geometry(b2): + upper, inverse = integer_lift(b2) + pivot = projector() + moment = matmul(upper, transpose(upper)) # 4 U U^t + wrong = matmul(transpose(upper), upper) # 4 U^t U + require(moment != wrong, "U U^t and U^t U differ on this code") + gram_scale = matmul(matmul(transpose(upper), pivot), upper) # 4 A + squared = matmul(gram_scale, gram_scale) + require(squared == [[52 * entry for entry in row] for row in gram_scale], "A^2 = 13 A") + # A = G/4 with G = gram_scale. (I - G/4)(12 I - G/4) = 12 I, + # so (4I - G)(48I - G) = 192 I. + left = [[4 * int(i == j) - gram_scale[i][j] for j in range(N)] for i in range(N)] + right = [[48 * int(i == j) - gram_scale[i][j] for j in range(N)] for i in range(N)] + require(matmul(left, right) == eye(192), "I-A is invertible over Q") + moment_inverse_num = matmul(transpose(inverse), inverse) # 4 U^{-t} U^{-1} = 4 M^{-1} + require(matmul(moment, moment_inverse_num) == eye(16), "M is invertible") + side = [[moment_inverse_num[i][j] - 4 * pivot[i][j] for j in range(N)] for i in range(N)] + # side = 4(N-P). inverse = 2 U^{-1} and left = 4(I-A), so + # inverse^t left inverse = 16 U^{-t}(I-A)U^{-1} = 16(N-P) = 4*side. + expected_side = matmul(matmul(transpose(inverse), left), inverse) + return upper, moment, wrong, gram_scale, side, expected_side + + +def reduced_fraction(numerator, denominator): + sign = 1 if numerator * denominator >= 0 else -1 + numerator, denominator = abs(numerator), abs(denominator) + common = numerator + other = denominator + while other: + common, other = other, common % other + return sign * numerator // common, denominator // common + + +def main(): + naive_positions = check_small_index_bridge() + contraction_samples = check_contraction_formula() + b2, gram = load_b2() + upper, moment, wrong, gram_scale, side, expected_side = check_geometry(b2) + # Scales: inverse = 2 U^{-1}, left = 4(I-A), so + # inverse^t left inverse = 2 U^{-t} * 4(I-A) * 2 U^{-1} = 16(N-P). + # side was defined as 4(N-P). The equality N-P = U^{-t}(I-A)U^{-1} + # is 16(N-P) = 4 * side. + require(expected_side == [[4 * entry for entry in row] for row in side], + "N-P congruence") + completion = [[48 * (i == j) - gram_scale[i][j] for j in range(N)] for i in range(N)] + exhibited = matmul(side, matmul(upper, matmul(completion, transpose(upper)))) + require(exhibited == eye(768), "exhibited rational inverse of N-P") + # (A tensor B)(A^{-1} tensor B^{-1}) = I on a 2-by-2 invertible pair. + factor_a = [[1, 2], [0, 1]] + factor_ainv = [[1, -2], [0, 1]] + factor_b = [[1, 1], [0, 1]] + factor_binv = [[1, -1], [0, 1]] + require(matmul(factor_b, factor_binv) == [[1, 0], [0, 1]], "2x2 inverse") + product = matmul(dense_kronecker(factor_a, factor_b), dense_kronecker(factor_ainv, factor_binv)) + require(product == [[1 if i == j else 0 for j in range(4)] for i in range(4)], + "Kronecker product of inverses") + gap_entries = [[moment[i][j] - wrong[i][j] for j in range(N)] for i in range(N)] + # moment - wrong = 4(M - U^t U). ||P tensor (M - U^t U)||^2 + # = ||P||^2 ||M - U^t U||^2 = 8 * ||gap_entries||^2 / 16. + gap_square = frobenius_inner(gap_entries, gap_entries) + require(gap_square > 0 and gap_square % 16 == 0, "transpose-order gap") + block_square = 8 * (gap_square // 16) + numerator, denominator = reduced_fraction(block_square, 1) + # Four sweeps through the index bridge. The four shears are the A/M block + # maps named in the receipt; their factors are the matrices checked above. + inverse_lift = integer_lift(b2)[1] + sweeps = { + "U": upper, + "U_inverse": inverse_lift, + "U_transpose": transpose(upper), + "U_inverse_transpose": transpose(inverse_lift), + } + for name, operator in sweeps.items(): + state = state_from(N, 2) + require(axis0_broadcast(operator, state) + == [[sum(operator[i][p] * state[p][j] for p in range(N)) for j in range(N)] + for i in range(N)], + name + " axis 0") + require(axis1_broadcast(operator, state) + == [[sum(operator[j][q] * state[i][q] for q in range(N)) for j in range(N)] + for i in range(N)], + name + " axis 1 is I tensor K, hence right multiplication by K^t") + # Shears, as block maps on a bank pair (X, Y), checked by the matrix factors. + # Lower A: Y := Y + A X with A acting on axis 0. Upper A uses axis 1 of A, + # which right-multiplies by A^t. Coded forms use M = U U^t, not U^t U. + require(gram_scale == matmul(matmul(transpose(upper), projector()), upper), "A factor") + receipt = { + "index": "(bank*104+i)*104+j", + "naive_kronecker_positions": naive_positions, + "contraction_samples": contraction_samples, + "b2_nonzero": sum(value != 0 for row in b2 for value in row), + "A_square_is_13A": True, + "I_minus_A_invertible_over_Q": True, + "M_invertible": True, + "omitted_side_rank": N * N, + "wrong_factor_block_frobenius_square": "%d/%d" % (numerator, denominator), + "literal_events_replayed": False, + "new_kappa": False, + } + # gram is retained so a reviewer can see the integer normalization used above. + require(gram[0][0] == 8, "pivot norm") + print("PASS_P104_INDEX_TENSOR_BRIDGE " + json.dumps(receipt, sort_keys=True)) + + +if __name__ == "__main__": + main()