diff --git a/research/complex-rank4-retimed-blocks/README.md b/research/complex-rank4-retimed-blocks/README.md new file mode 100644 index 0000000000..e9c043f479 --- /dev/null +++ b/research/complex-rank4-retimed-blocks/README.md @@ -0,0 +1,44 @@ +# Rank-4 retimed block calls in the selected gauge44 word + +**Scoped zero-charge screen. No physical supplier or new κ is claimed.** + +## Finding + +The selected gauge44 local word has 142 rank-4 child calls per orientation. Fourteen target frames expose a useful grouping: frames 415–422 each contain seven rank-4 calls, while frames 431–434, 436 and 437 each contain four. The verifier partitions each seven-call frame into one four-call block and one three-call block, and each four-call frame into one four-call block. This yields 22 direct sums covering 80 calls: fourteen rank-16 children and eight rank-12 children. The grouped rank mass remains 320, so the full local mass remains 5,586. + +The forward and backward traces have the same groups. Every proposed block has distinct output registers, one target frame and one operand phase. Between its calls, the only events are scalar additions on L registers. The verifier checks that no such addition reads or writes a later call's register, then symbolically compares the original and retimed rational linear maps on arbitrary initial register values. The block identity is + +\[ +\operatorname{diag}(A_1,\ldots,A_t)\operatorname{diag}(B_1,\ldots,B_t) +=\operatorname{diag}(A_1B_1,\ldots,A_tB_t), +\qquad t\in\{3,4\}. +\] + +The standalone profile changes from `{1:2412, 2:418, 3:432, 4:142, 5:82, 8:8}` to `{1:2412, 2:418, 3:432, 4:62, 5:82, 8:8, 12:8, 16:14}`. At the retained fixed-word ceiling, this raises the ideal exponent-saving ceiling by **2.0187%**, below the rank-shape card's 5% screen. Its corresponding ideal κ cap is about 0.00172120. This is a relaxation with gathering, output routing, frame/interface conversion, hosting, precision and arbitrary-dirty restoration all waived; it is not an attained κ. + +For context, the package also composes this disjoint rank-4 profile delta arithmetically with the pinned rank-2/rank-3 zero-charge profile from [`complex-mixed-rank-diagonal-seed8433`](../complex-mixed-rank-diagonal-seed8433/README.md). The resulting hypothetical profile has an ideal ceiling gain of **6.6289%** and a κ cap of about 0.00179884. The registered replay runs that predecessor's verifier first. This composition crosses 5% only under the same zero-charge relaxation and admits no supplier or new κ. + +## Scope and wall + +This screen tests the rank-4 same-target-frame pattern beyond the selected-word rank-1 batching of [PR #1779](https://github.com/CrocSwap/integer-mult-bounds/pull/1779) and the strict chronological rank-2/rank-3 blocks of [PR #1960](https://github.com/CrocSwap/integer-mult-bounds/pull/1960) and [PR #2014](https://github.com/CrocSwap/integer-mult-bounds/pull/2014). It does not generalize those results or certify a full recursive interface. + +The frozen local trace provides ranks, registers, source/target frames and scalar references. It does not identify the physical left/right operand banks, block-input layout, output ownership, scratch lifetime or dirty-state restoration contract for a fused rank-12/rank-16 call. Those costs remain unknown. The standalone rank-4 screen misses 5%, and the joint profile is only an optimistic composition, so this contribution stops at the exact local handoff rather than starting another implementation round. + +## Reproduce + +From the repository root, the registered replay runs both the predecessor screen and this package: + +```sh +python3 scripts/research_package.py --package research/complex-rank4-retimed-blocks --check-only +python3.12 scripts/research_package.py --package research/complex-rank4-retimed-blocks +``` + +The source archive, exact program member and canonical word are pinned in [SOURCES.json](SOURCES.json). The verifier checks both orientations, symbolic retiming, rank-mass preservation and exact rational ceiling brackets. `RESULT.json` is recomputed byte-for-byte by the verifier. + +## Open next questions + +Can one concrete rank-4 group (for example target frame 431) be emitted as an actual rank-16 child with its left/right operands, output owners, scratch lifetime and arbitrary-dirty restoration fully specified? The next step is to trace its four child recipes through the producer and consumer, materialize the 16-by-16 block inputs and output map, and price every copy, frame conversion, hosted slot, precision term and restoration operation. The current trace lacks the physical ownership and lifetime contract needed for that invoice. + +## Credit + +The selected word, source archive and predecessor constructions retain their original authorship and citation chain. This scoped verifier and screen were prepared by Gonzalo Mier with substantial OpenAI Codex assistance; no independent human review is claimed. New work is Apache-2.0. diff --git a/research/complex-rank4-retimed-blocks/RESULT.json b/research/complex-rank4-retimed-blocks/RESULT.json new file mode 100644 index 0000000000..4ce7eb4542 --- /dev/null +++ b/research/complex-rank4-retimed-blocks/RESULT.json @@ -0,0 +1,149 @@ +{ + "status": "PASS_COMPLEX_RANK4_RETIMED_BLOCKS", + "source": { + "archive_sha256": "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6", + "local_program_sha256": "241fde27d4e43f5a9cb6b128f9f76c5131a53d09f0371676163f914d0b0fef3a", + "canonical_word_sha256": "16bc0ebb04b4be6c0ade74badc6a0c0cdba4215eda86e4ff9f13abf8ecebd219", + "selected_profile": { + "1": 2412, + "2": 418, + "3": 432, + "4": 142, + "5": 82, + "8": 8 + } + }, + "per_orientation": { + "forward": { + "rank4_calls": 142, + "eligible_target_frames": { + "415": 7, + "416": 7, + "417": 7, + "418": 7, + "419": 7, + "420": 7, + "421": 7, + "422": 7, + "431": 4, + "432": 4, + "433": 4, + "434": 4, + "436": 4, + "437": 4 + }, + "blocks": 22, + "grouped_calls": 80, + "grouped_rank_mass": 320, + "block_sides": { + "12": 8, + "16": 14 + }, + "retimed_scalar_events": 62 + }, + "backward": { + "rank4_calls": 142, + "eligible_target_frames": { + "415": 7, + "416": 7, + "417": 7, + "418": 7, + "419": 7, + "420": 7, + "421": 7, + "422": 7, + "431": 4, + "432": 4, + "433": 4, + "434": 4, + "436": 4, + "437": 4 + }, + "blocks": 22, + "grouped_calls": 80, + "grouped_rank_mass": 320, + "block_sides": { + "12": 8, + "16": 14 + }, + "retimed_scalar_events": 62 + } + }, + "direct_sum_identity": { + "tested_block_counts": [ + 3, + 4 + ], + "child_side_4_to_block_side": { + "3": 12, + "4": 16 + }, + "identity": "diag(A_1,...,A_t) diag(B_1,...,B_t) = diag(A_1 B_1,...,A_t B_t)" + }, + "rank4_candidate": { + "grouped_calls": 80, + "new_blocks": { + "12": 8, + "16": 14 + }, + "profile": { + "1": 2412, + "2": 418, + "3": 432, + "4": 62, + "5": 82, + "8": 8, + "12": 8, + "16": 14 + }, + "rank_mass": 5586, + "charges_waived": [ + "physical input gathering and block-diagonal layout", + "output routing and storage", + "frame/interface conversion", + "hosting and precision", + "arbitrary-dirty restoration" + ], + "ceiling_a_hi": "8620858381/5000000000000", + "kappa_cap_hi": "8620858381/5008620858381", + "ceiling_gain_percent_over_selected": "2.01872631866020768222278215341", + "five_percent_gate_passed_alone": false + }, + "joint_zero_charge_screen": { + "predecessor": "research/complex-mixed-rank-diagonal-seed8433/RESULT.json", + "predecessor_profile": { + "1": 2412, + "2": 362, + "3": 123, + "4": 158, + "5": 87, + "6": 127, + "8": 9, + "9": 1, + "12": 4, + "15": 5, + "16": 3 + }, + "composed_profile": { + "1": 2412, + "2": 362, + "3": 123, + "4": 78, + "5": 87, + "6": 127, + "8": 9, + "9": 1, + "12": 12, + "15": 5, + "16": 17 + }, + "composed_ceiling_a_hi": "2252606751/1250000000000", + "composed_kappa_cap_hi": "2252606751/1252252606751", + "ceiling_gain_percent_over_selected": "6.62885827718615024075621769097", + "five_percent_gate_passed_under_zero_charge_only": true, + "new_supplier_or_kappa": false + }, + "baseline_ceiling_a_hi": "16900541091/10000000000000", + "mixed_rank23_ceiling_a_hi": "8824220643/5000000000000", + "scope_wall": "The frozen trace authenticates child ranks, target frames and scalar register context, but does not specify a physical block-input/output ownership contract or complete gathering, routing, hosting, precision and dirty-restoration bill for a fused rank-12/rank-16 call." +} diff --git a/research/complex-rank4-retimed-blocks/SOURCES.json b/research/complex-rank4-retimed-blocks/SOURCES.json new file mode 100644 index 0000000000..2e51b2b3d0 --- /dev/null +++ b/research/complex-rank4-retimed-blocks/SOURCES.json @@ -0,0 +1,54 @@ +{ + "schema_version": 1, + "base_commit": "20ecf2891d80b5acf18d980b2164fb44ea7faa90", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "input", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0" + }, + { + "path": "research/community-frontier1094-audit/SELECTED-SOURCE.json", + "usage": "input", + "git_blob": "6a75493790b4eff9c4a98051ef8b01d6aad0d5a8", + "sha256": "79b3de5db3dbcb9829789ba58e9e45758926031e2a7d80667a08429d369be53b" + }, + { + "path": "research/community-frontier1094-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "c24daf067f9c543421d89ca2eeaa4eb78a57fb6f", + "sha256": "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6" + }, + { + "path": "research/complex-local-word-ceiling/RESULT.json", + "usage": "input", + "git_blob": "77f55043a679dd722330f1e2499863e36376d9f9", + "sha256": "d91d6c46509875abf1f61de67c2609656d3dc685451299f83caa6f922493692d" + }, + { + "path": "research/complex-local-word-ceiling/ceiling.py", + "usage": "input", + "git_blob": "6c0f54527d879396f689523bfde19928a9b6157c", + "sha256": "86a1432870b3b21d8454106ec9162fddc0471472d9214c590a1420f2426cedfc" + }, + { + "path": "research/complex-mixed-rank-diagonal-seed8433/RESULT.json", + "usage": "input", + "git_blob": "0d9f6c9304ffe26796940660ba4f6ff7eafdb8c2", + "sha256": "852119a9c37789b82cf3ab20546c1e61349753f4046d86ecd7d8af4e0c33ee78" + }, + { + "path": "research/complex-mixed-rank-diagonal-seed8433/verify.py", + "usage": "input", + "git_blob": "853cadec3fe364863e00c44cb9ab1e2637772732", + "sha256": "cb4d9bdddebc7907bc9d961e67cbe034c537f0596f3185ac7532160b7b7576c0" + } + ] +} diff --git a/research/complex-rank4-retimed-blocks/TASK.json b/research/complex-rank4-retimed-blocks/TASK.json new file mode 100644 index 0000000000..9488597481 --- /dev/null +++ b/research/complex-rank4-retimed-blocks/TASK.json @@ -0,0 +1,86 @@ +{ + "schema_version": 1, + "task_id": "complex-rank-shape-decoder", + "priority_revision": 6, + "base_commit": "20ecf2891d80b5acf18d980b2164fb44ea7faa90", + "original_card": { + "id": "complex-rank-shape-decoder", + "question": "Can a decoder deliver the local paid mass in fewer, larger-rank children (block frame climbs instead of rank-1 to rank-3 steps)?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/complex-local-word-ceiling/README.md", + "research/complex-decoder-field-extension-seed44/README.md", + "research/complex-frame-pair-decoders/README.md", + "research/selected-k8-unrestricted-ends/README.md", + "research/eisenstein-reduction-copy-floor/README.md" + ], + "methods": [ + "Find one exact small decoding identity whose frame path climbs in blocks, and price its complete per-call profile.", + "Bound the best effective child rank achievable for one fixed support alphabet, including copies, frames and restoration." + ], + "acceptance_gate": "A per-call local profile, with all copied information, frames and restoration counted, whose ceiling exceeds the selected word's by at least 5%; masked or overcomplete supports must change an assumption of the eight-term all-pairs bound. 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", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Before any synthesis, write the candidate per-call local profile (and centre charge / unpaid coordinates if changed) and screen it with ceiling.ceiling(); reject it if even the ideal ceiling does not beat the selected word's by your stated margin. Ideal budget: rank-16 delivery is 2.31x (levers.py).", + "bottleneck_link": "Rank-1 children are about half of recursive cost; the selected word's effective child rank is about 3.9. Larger-rank delivery lowers recursive cost per unit of paid mass.", + "allowed_variations": [ + "One masked, overcomplete or block decoder family with exact labels and supports.", + "A scoped lower bound on effective rank for one alphabet.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Repacking idle remainders of an unchanged word (covered by the packing ceiling).", + "Repeating the eight-term all-pairs search inside its proved scope.", + "Only changing helper terminal subspaces and monotone frames within the fixed scalar word, entrances and cleanup contract already covered by #1995/#2013.", + "Searching below C=40 in the #2017 Eisenstein binary scalar-rectangle or fixed-support block-linear additive pairing model; specify a changed premise instead. This bound does not cover every complex decoder.", + "Continuing a partial cost improvement while leaving the same unpriced consumer, restoration or central-readout obligation unresolved; refresh the family expansion decision first. Local product-retiming evidence has a narrow scope and is not a ban on changed graphs or contracts." + ], + "overlap_terms": [ + "rank shape", + "block climb", + "masked decoder", + "overcomplete", + "effective rank" + ] + }, + "scope_status": "refined", + "actual_scope": "On both pinned orientations of the selected gauge44 local program, identify rank-4 child groups sharing a target frame, retime only intervening scalar L-register additions across those independent calls, and replace groups of four or three by exact block-diagonal rank-16 or rank-12 calls. Recompute the fixed-word zero-charge ceiling; also compose the profile arithmetically with the pinned rank-2/rank-3 screen as a joint relaxation.", + "scope_change_reason": "The card's broad block-climb question is narrowed to one source-bound rank-4 pattern absent from the predecessor rank-1 and strict rank-2/rank-3 screens: fourteen same-target-frame groups containing either four or seven calls. The verifier proves the register-level retiming and block-diagonal identity, but waives the physical block-input/output layout and complete supplier bill. The joint profile is only the arithmetic composition of two zero-charge screens.", + "bottleneck_link": "At fixed paid rank mass, replacing four rank-4 calls by one rank-16 call, or three by one rank-12 call, lowers the recursive moment for every positive saving exponent. Whether that ceiling headroom survives input layout, routing, frames, hosting, precision and dirty restoration is the unresolved mechanism.", + "budget_minutes": 50, + "stop_rule": "Stop construction expansion at this screen. The standalone rank-4 profile gains only 2.02% in the ideal ceiling and misses the card's 5% gate. The arithmetic composition with the earlier rank-2/rank-3 zero-charge profile clears 5%, but supplies no physical interface or total cost. Resume only after a source-bound operand/owner/restoration contract is available for one concrete fused block and a complete bill shows the omitted costs can fit.", + "outcome": "completed", + "evidence": "RESULT.json and verify.py pin the selected archive and both orientations, enumerate 22 blocks covering 80 rank-4 calls, preserve rank mass 5,586, symbolically verify the rank-12/rank-16 block-diagonal identities, and check exact rational ceiling brackets. The standalone zero-charge ceiling gain is 2.0187%; the composed zero-charge profile is 6.6289% above the selected-word ceiling. No supplier or new kappa is claimed.", + "author": "Gonzalo Mier", + "ai_assistance": "Substantial OpenAI Codex assistance in source analysis, mathematical screening, verifier implementation and package writing; no independent human review is claimed.", + "predecessors": [ + { + "reference": "CrocSwap/integer-mult-bounds#1779", + "relationship": "Selected-word direct-sum batching of rank-one climbs; this package changes the child rank to four and retimes only within verified same-target-frame groups." + }, + { + "reference": "CrocSwap/integer-mult-bounds#1960 and #2014", + "relationship": "Strict chronological rank-2/rank-3 block screens; this package's separate rank-4 groups may be composed only as a zero-charge profile relaxation." + }, + { + "reference": "research/complex-mixed-rank-diagonal-seed8433", + "relationship": "Pinned predecessor profile whose independent verifier is rerun by this package before the joint arithmetic screen." + } + ], + "open_questions": [ + { + "question": "Can one concrete rank-4 group (for example target frame 431) be emitted as an actual rank-16 child with its left/right operands, output owners, scratch lifetime and arbitrary-dirty restoration fully specified?", + "why_it_matters": "The positive ceiling is only useful if constructing and consuming the block-diagonal inputs costs less than the moment saved; unknown interface costs are not zero.", + "first_step": "Trace the four exact child recipes and their source/output banks through the selected producer and consumer, write the 16-by-16 block inputs and output map, then price every copy, frame conversion, hosted slot, precision term and restoration operation.", + "blocked_by": "The frozen local event trace records child rank, register, source/target frame and scalar references, but not the physical ownership and lifetime contract for a fused block call." + } + ] +} diff --git a/research/complex-rank4-retimed-blocks/VERIFY.json b/research/complex-rank4-retimed-blocks/VERIFY.json new file mode 100644 index 0000000000..a0cee0f245 --- /dev/null +++ b/research/complex-rank4-retimed-blocks/VERIFY.json @@ -0,0 +1,35 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "certificates/selected-result.json", + "research/community-frontier1094-audit/SELECTED-SOURCE.json", + "research/community-frontier1094-audit/selected-replay.tar.gz", + "research/complex-local-word-ceiling/RESULT.json", + "research/complex-local-word-ceiling/ceiling.py", + "research/complex-mixed-rank-diagonal-seed8433/RESULT.json", + "research/complex-mixed-rank-diagonal-seed8433/verify.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "research/complex-mixed-rank-diagonal-seed8433/verify.py" + ], + "timeout_seconds": 120, + "checks": "Recompute the pinned predecessor's rank-2/rank-3 zero-charge profile before using it in the joint arithmetic screen." + }, + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Archive/member pins; selected profile in both orientations; exact rank-4 target-frame census; scalar-reference liveness; symbolic affine equivalence after retiming; exact rank-12/rank-16 block-diagonal multiplication identities; rank-mass conservation; rational ceiling brackets; and standalone/joint 5% controls." + } + ] +} diff --git a/research/complex-rank4-retimed-blocks/verify.py b/research/complex-rank4-retimed-blocks/verify.py new file mode 100644 index 0000000000..9cc113d7df --- /dev/null +++ b/research/complex-rank4-retimed-blocks/verify.py @@ -0,0 +1,335 @@ +#!/usr/bin/env python3 +"""Verify a scoped rank-4 block-retiming screen on the pinned gauge44 trace.""" + +from collections import Counter, defaultdict +from decimal import Decimal, localcontext +from fractions import Fraction as Q +import gzip +import hashlib +import json +from pathlib import Path +import sys +import tarfile + + +ROOT = Path(__file__).resolve().parents[2] +PACKAGE = Path(__file__).resolve().parent +ARCHIVE = ROOT / "research/community-frontier1094-audit/selected-replay.tar.gz" +MEMBER = "candidate/strict/global/base/providers/gauge44/LOCAL-PROGRAMS.json.gz" +CANONICAL_MEMBER = "candidate/strict/global/base/providers/gauge44/CANONICAL-WORD.json.gz" +ARCHIVE_SHA256 = "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6" +PROGRAM_SHA256 = "241fde27d4e43f5a9cb6b128f9f76c5131a53d09f0371676163f914d0b0fef3a" +WORD_SHA256 = "16bc0ebb04b4be6c0ade74badc6a0c0cdba4215eda86e4ff9f13abf8ecebd219" +EXPECTED_PROFILE = {1: 2412, 2: 418, 3: 432, 4: 142, 5: 82, 8: 8} +EXPECTED_TARGETS = { + **{frame: 7 for frame in range(415, 423)}, + 431: 4, 432: 4, 433: 4, 434: 4, 436: 4, 437: 4, +} +MODEL = (73, 896, 9, 64) +GRID = Q(1, 10**13) + + +def require(condition, message): + if not condition: + raise AssertionError(message) + + +def read_json_gzip(raw): + return json.loads(gzip.decompress(raw)) + + +def lregisters(operation): + """Return the L-registers read or written by a local scalar macro.""" + require(operation[0] == "add", f"unexpected retimed scalar macro: {operation}") + require(operation[1][0] == "L" and operation[2][0] == "L", + f"rank-4 retiming is not confined to L registers: {operation}") + return {operation[1][1], operation[2][1]} + + +def linear_state(events): + """Symbolically execute child outputs and rational ADDs on arbitrary L state.""" + state = {} + + def get(reg): + return state.get(reg, {f"x{reg}": Q(1)}) + + def add_scaled(left, right, scale): + out = dict(left) + for symbol, coefficient in right.items(): + out[symbol] = out.get(symbol, Q(0)) + scale * coefficient + if out[symbol] == 0: + del out[symbol] + return out + + for position, event in enumerate(events): + if event[0] == "climb": + reg = event[2] + state[reg] = {f"q{id(event)}": Q(1)} + else: + require(event[0] == "scalar", f"unexpected event in block window: {event}") + operation = event[1] + lregisters(operation) + destination, source = operation[1][1], operation[2][1] + scale = Q(operation[3], operation[4]) + state[destination] = add_scaled(get(destination), get(source), scale) + return state + + +def verify_batch(events, call_indices, block_side): + """Check a zero-charge retiming and the linear context around a block.""" + calls = [events[index] for index in call_indices] + require(len(calls) in (3, 4), "a block must contain three or four rank-4 calls") + require(all(call[0] == "climb" and call[-1] == 4 for call in calls), + "a block contains a non-rank-4 child") + require(len({call[1] for call in calls}) == 1, "mixed operand phase in one block") + require(len({call[4] for call in calls}) == 1, "mixed target frame in one block") + registers = [call[2] for call in calls] + require(len(set(registers)) == len(registers), "block child outputs alias") + require(sum(call[-1] for call in calls) == block_side, "wrong direct-sum side") + + lo, hi = call_indices[0], call_indices[-1] + interval = events[lo:hi + 1] + interval_calls = [lo + j for j, event in enumerate(interval) if event[0] == "climb"] + require(interval_calls == call_indices, "another child occurs inside the proposed block") + for event in interval: + if event[0] == "scalar": + lregisters(event[1]) + else: + require(event[0] == "climb", f"non-scalar event inside block: {event}") + + # A scalar reference to a later child register would observe a different value + # after the calls are moved before the ADDs. Exclude every such hazard. + for position in range(lo, hi + 1): + event = events[position] + if event[0] != "scalar": + continue + future = {call[2] for call_index, call in zip(call_indices, calls) + if call_index > position} + require(not (lregisters(event[1]) & future), + f"retiming changes a future child's input at event {position}") + + original = interval + retimed = [events[index] for index in call_indices] + retimed.extend(event for event in interval if event[0] == "scalar") + require(linear_state(original) == linear_state(retimed), + "moving the ADDs after independent child calls changes the exact linear map") + return { + "target_frame": calls[0][4], + "phase": calls[0][1], + "source_frames": [call[3] for call in calls], + "output_registers": registers, + "event_interval": [lo, hi], + "retimed_scalar_events": sum(event[0] == "scalar" for event in interval), + "block_side": block_side, + } + + +def verify_direct_sum_identity(blocks): + """Exhaustively compare all entries in diag(A_i)diag(B_i).""" + side = 4 * blocks + + def matrix_entry(operand, row, column): + if row // 4 != column // 4: + return None + return f"{operand}{row // 4}_{row % 4}_{column % 4}" + + for row in range(side): + for column in range(side): + actual = Counter() + for inner in range(side): + left = matrix_entry("a", row, inner) + right = matrix_entry("b", inner, column) + if left is not None and right is not None: + actual[(left, right)] += 1 + expected = Counter() + if row // 4 == column // 4: + block = row // 4 + for inner in range(4): + expected[(f"a{block}_{row % 4}_{inner}", + f"b{block}_{inner}_{column % 4}")] += 1 + require(actual == expected, + f"block-diagonal multiplication identity failed at {(row, column)}") + + +def decimal(q): + with localcontext() as context: + context.prec = 30 + return str(Decimal(q.numerator) / Decimal(q.denominator)) + + +def as_profile(counter): + return {str(rank): counter[rank] for rank in sorted(counter) if counter[rank]} + + +def ceiling(profile): + sys.path.insert(0, str(ROOT / "research/complex-local-word-ceiling")) + import ceiling as engine + return engine.ceiling(profile, *MODEL, grid=GRID)[1] + + +def main(write=False): + archive_bytes = ARCHIVE.read_bytes() + require(hashlib.sha256(archive_bytes).hexdigest() == ARCHIVE_SHA256, + "selected replay archive SHA-256 mismatch") + with tarfile.open(ARCHIVE, "r:gz") as archive: + program_bytes = archive.extractfile(MEMBER).read() + word_bytes = archive.extractfile(CANONICAL_MEMBER).read() + require(hashlib.sha256(program_bytes).hexdigest() == PROGRAM_SHA256, + "local program member SHA-256 mismatch") + require(hashlib.sha256(word_bytes).hexdigest() == WORD_SHA256, + "canonical word member SHA-256 mismatch") + + programs = read_json_gzip(program_bytes) + canonical = read_json_gzip(word_bytes) + selected_profile = {int(rank): int(count) + for rank, count in canonical["local_profile"].items()} + require(selected_profile == EXPECTED_PROFILE, "canonical local profile changed") + require(sum(rank * count for rank, count in selected_profile.items()) == 5586, + "selected paid rank mass changed") + + orientation_results = {} + first_orientation_batches = None + for orientation in ("forward", "backward"): + events = programs[orientation] + profile = Counter(event[-1] for event in events + if event[0] == "climb" or event[0] == "center") + require(dict(profile) == EXPECTED_PROFILE, + f"{orientation} event profile differs from the pinned word") + + by_target = defaultdict(list) + for index, event in enumerate(events): + if event[0] == "climb" and event[-1] == 4: + by_target[event[4]].append(index) + eligible = {frame: indices for frame, indices in by_target.items() + if len(indices) >= 4} + require({frame: len(indices) for frame, indices in eligible.items()} == EXPECTED_TARGETS, + f"{orientation} rank-4 target-frame census changed") + + batches = [] + for frame in sorted(eligible): + indices = eligible[frame] + sizes = [4, 3] if len(indices) == 7 else [4] + offset = 0 + for size in sizes: + chunk = indices[offset:offset + size] + offset += size + batches.append(verify_batch(events, chunk, size * 4)) + require(offset == len(indices), "target-frame calls were not fully partitioned") + require(len(batches) == 22, "unexpected number of direct-sum blocks") + require(Counter(batch["block_side"] for batch in batches) == {12: 8, 16: 14}, + "unexpected block-side distribution") + if first_orientation_batches is None: + first_orientation_batches = batches + else: + require(batches == first_orientation_batches, + "forward and backward retiming schedules differ") + orientation_results[orientation] = { + "rank4_calls": profile[4], + "eligible_target_frames": {str(frame): len(indices) + for frame, indices in sorted(eligible.items())}, + "blocks": len(batches), + "grouped_calls": sum(len(batch["output_registers"]) for batch in batches), + "grouped_rank_mass": sum(batch["block_side"] for batch in batches), + "block_sides": {str(side): count for side, count in + sorted(Counter(batch["block_side"] for batch in batches).items())}, + "retimed_scalar_events": sum(batch["retimed_scalar_events"] for batch in batches), + } + + verify_direct_sum_identity(3) + verify_direct_sum_identity(4) + + candidate = dict(selected_profile) + candidate[4] -= 80 + candidate[12] = candidate.get(12, 0) + 8 + candidate[16] = candidate.get(16, 0) + 14 + require(candidate[4] == 62, "candidate rank-4 count mismatch") + require(sum(rank * count for rank, count in candidate.items()) == 5586, + "rank-4 fusion changed paid rank mass") + + mixed_result = json.loads((ROOT / "research/complex-mixed-rank-diagonal-seed8433/RESULT.json") + .read_text()) + mixed_profile = {int(rank): int(count) + for rank, count in mixed_result["selected_profile"].items()} + require(sum(rank * count for rank, count in mixed_profile.items()) == 5586, + "pinned rank-2/3 profile does not preserve selected mass") + require(mixed_profile.get(4, 0) >= 80, + "rank-2/3 comparison profile lacks disjoint rank-4 calls") + combined = dict(mixed_profile) + combined[4] -= 80 + combined[12] = combined.get(12, 0) + 8 + combined[16] = combined.get(16, 0) + 14 + require(sum(rank * count for rank, count in combined.items()) == 5586, + "composed zero-charge profile changes paid mass") + + baseline_hi = ceiling(selected_profile) + candidate_hi = ceiling(candidate) + mixed_hi = ceiling(mixed_profile) + combined_hi = ceiling(combined) + kappa = lambda alpha: alpha / (1 + alpha) + result = { + "status": "PASS_COMPLEX_RANK4_RETIMED_BLOCKS", + "source": { + "archive_sha256": ARCHIVE_SHA256, + "local_program_sha256": PROGRAM_SHA256, + "canonical_word_sha256": WORD_SHA256, + "selected_profile": as_profile(Counter(selected_profile)), + }, + "per_orientation": orientation_results, + "direct_sum_identity": { + "tested_block_counts": [3, 4], + "child_side_4_to_block_side": {"3": 12, "4": 16}, + "identity": "diag(A_1,...,A_t) diag(B_1,...,B_t) = diag(A_1 B_1,...,A_t B_t)", + }, + "rank4_candidate": { + "grouped_calls": 80, + "new_blocks": {"12": 8, "16": 14}, + "profile": as_profile(Counter(candidate)), + "rank_mass": 5586, + "charges_waived": [ + "physical input gathering and block-diagonal layout", + "output routing and storage", + "frame/interface conversion", + "hosting and precision", + "arbitrary-dirty restoration", + ], + "ceiling_a_hi": str(candidate_hi), + "kappa_cap_hi": str(kappa(candidate_hi)), + "ceiling_gain_percent_over_selected": decimal(100 * (candidate_hi / baseline_hi - 1)), + "five_percent_gate_passed_alone": candidate_hi >= baseline_hi * Q(105, 100), + }, + "joint_zero_charge_screen": { + "predecessor": "research/complex-mixed-rank-diagonal-seed8433/RESULT.json", + "predecessor_profile": as_profile(Counter(mixed_profile)), + "composed_profile": as_profile(Counter(combined)), + "composed_ceiling_a_hi": str(combined_hi), + "composed_kappa_cap_hi": str(kappa(combined_hi)), + "ceiling_gain_percent_over_selected": decimal(100 * (combined_hi / baseline_hi - 1)), + "five_percent_gate_passed_under_zero_charge_only": combined_hi >= baseline_hi * Q(105, 100), + "new_supplier_or_kappa": False, + }, + "baseline_ceiling_a_hi": str(baseline_hi), + "mixed_rank23_ceiling_a_hi": str(mixed_hi), + "scope_wall": "The frozen trace authenticates child ranks, target frames and scalar register context, but does not specify a physical block-input/output ownership contract or complete gathering, routing, hosting, precision and dirty-restoration bill for a fused rank-12/rank-16 call.", + } + + result_path = PACKAGE / "RESULT.json" + if write: + result_path.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8") + else: + recorded = json.loads(result_path.read_text(encoding="utf-8")) + require(recorded == result, "RESULT.json differs from the independently recomputed screen") + + print("PASS_COMPLEX_RANK4_RETIMED_BLOCKS") + print(json.dumps({ + "forward_backward_batches": len(first_orientation_batches), + "grouped_calls": 80, + "new_block_sides": {"12": 8, "16": 14}, + "candidate_ceiling_a_hi": str(candidate_hi), + "combined_zero_charge_ceiling_a_hi": str(combined_hi), + "combined_five_percent_gate": result["joint_zero_charge_screen"]["five_percent_gate_passed_under_zero_charge_only"], + "new_kappa": False, + }, sort_keys=True)) + + +if __name__ == "__main__": + main(write="--write" in sys.argv[1:])