diff --git a/research/qq16-bidirectional-sweeps/README.md b/research/qq16-bidirectional-sweeps/README.md new file mode 100644 index 0000000000..0511bdd5f2 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/README.md @@ -0,0 +1,214 @@ +# Exact optimal directions for QQ16 scalar sweeps + +For the **fixed dirty-bridge word and bank-major access protocol of +[PR #2722](https://github.com/CrocSwap/integer-mult-bounds/pull/2722)**, choosing +one increasing or decreasing complete site sweep per scalar instruction gives +this exact minimum closed two-tape word-address travel, for every integer `N >= 1`: + +| Window | PR2722: every pass increasing | Optimal pass directions | +|---|---:|---:| +| L2 | `3564N - 896` | `3518N - 850` | +| F0 inverse | `8302N - 1944` | `8222N - 1864` | +| Total | `11866N - 2840` | **`11740N - 2714`** | + +The saving is exactly **`126(N-1)` address steps**. At `N=2`, the total falls +from 20,892 to 20,766. At `N=1` the protocols coincide. The provided schedule +uses 23 reverse L2 passes and 40 reverse F0-inverse passes. + +This is a source-bound **local access lemma**, with an optimality proof for +this stated protocol. It does not give a minimum over instruction reorderings, +scalar resynthesis, layouts, caching or general tape programs. It does not +complete a QQ16 caller or improve kappa. PR2722's increasing-pass tariffs remain +correct for its specified protocol. + +## Exact boundary and unchanged charges + +There are two independently movable word-address tapes. Z and W each contain +112 banks, with `address(bank, site) = bank*N + site`. An ADD reads its source +and updates its destination at the **same site**, using one scalar source +register; a CLEAR updates its target. Every instruction visits all sites +contiguously, either `0..N-1` or `N-1..0`, and finishes before the next +instruction. Both tapes start and return to address zero separately for each +window. Idle heads remain where they were; motion is charged by the sum of +absolute head displacements. The unchanged physical layout needs no conversion. + +The source is ywz65's PR2709 word at +`d7749c49e967b214537c0bd832e435e177e21d4f`, with the L2 markers at zero-based +indices 633 and 1066, and F0-inverse markers at 1172 and 2125. Interior events +are scalar ADDs/CLEARs only. The verifier checks the source bytes, markers, +coefficient alphabet and owned bank bounds before using them. + +As in Nick Petalas's PR2722, the eight `W[k] -= W[k+8]` instructions use the +existing dirty Z0 bank via four cross-tape ADDs: + +```text +Z0 += W[k+8]; W[k] -= Z0; Z0 -= W[k+8]; W[k] += Z0 +``` + +For arbitrary `(Z0,W[k],W[k+8])=(z,f,g)`, these return `(z,f-g,g)`. +This bridge is inherited, not a new construction. The resulting windows have +432 and 976 instructions; every ADD touches distinct tapes. The sole change +here is the direction in which each complete instruction sweeps its sites. +[SCHEDULE.json](SCHEDULE.json) records one direction per instruction in the +reconstructed bridge word: `0` increases, `1` decreases. Ties are resolved +lexicographically at `N=2`; all paths tie at `N=1`. + +The complete added local invoice remains **864 unit ADDs, 832 quarter ADDs and +288 CLEARs: 17,472 real scalar primitives** at the inherited prices 8, 12 and 2. +This includes PR2722's 24 extra unit ADDs relative to PR2709. Native events +are unchanged: the inherited invoice has 224 rank-one and 16 rank-eight +children (mass 352), 480 wrappers and 208 full-cover maps. Original F0/B1 work +is additional. The new checker independently counts the source scalar word; +it does not replay those native kernels or admit their prices. + +The **whole-window ownership premise is retained**: W0 for L2, W0..W15 for +F0 inverse, and the temporary dirty-Z0 bridge access. Scratch at many sites +coexists between passes. There is no additional payload bank, and this is not +a return to PR2709's one-owner-at-a-time release contract. The precision-sized +source register, instruction control, in-word arithmetic and surrounding native +movement still require physical implementation and pricing. + +## Proof of semantics and optimality for all N + +**Semantics.** Each site executes precisely the same ordered scalar instruction +sequence as PR2722. Changing an instruction's site direction only reorders +operations on disjoint cells. Thus the transformation preserves every cell for +arbitrary initial inputs and disposable output dirt, and retains the bridge's +exact restoration of dirty Z0. No original clear, frame change or native event +moves across a window boundary. This argument is dimension-independent; +small rational fixtures below are controls, not its universal justification. + +**Endpoint state.** Before an instruction, each head is at +`b_t*N + e_t*(N-1)`, where `b_t` is the last bank touched on tape `t` and +`e_t` is 0 or 1. Initially both pairs are `(0,0)`. The last bank depends only +on the fixed instruction prefix. The two endpoint bits therefore give at most +four states. For instruction direction `d` (0 increasing, 1 decreasing), a +touched tape enters bank `b` at offset `d*(N-1)`, travels `N-1` within that +bank, and finishes with endpoint bit `1-d`. An untouched head keeps its bit. +The exact entry distance is + +```text +abs((b - b_t)*N + (d - e_t)*(N-1)). +``` + +The final return charge is `sum_t (b_t*N + e_t*(N-1))`. Direct walks attain +these distances; triangle inequality precludes a cheaper walk with those same +visits. Reading then writing distinct tapes does not change the sum of their +individual head distances. + +**Affine law.** Write `delta=b-b_t` and `v=d-e_t`, so `v` is -1, 0 or 1. +For every positive integer N, the entry distance equals: + +```text + delta*N + v*(N-1), delta > 0 +-delta*N - v*(N-1), delta < 0 + abs(v)*(N-1), delta = 0. +``` + +The signs hold even at `N=1`: a nonzero integer bank difference dominates an +offset of magnitude at most `N-1`. Within-bank travel and final returns are +also affine in N. Consequently every complete direction word has travel +`T_path(N) = T_one + (N-1)*A_path`. Here `T_one` is the **same for every +path**, because at `N=1` every pass is a single bank address, independent of +direction. Minimizing at `N=2` therefore minimizes `A_path` and is optimal for +all `N>1`; it also attains the common value at `N=1`. This is not a polynomial +fit or a conclusion extrapolated from finitely sampled N. + +**Bellman lower bound and witness.** For each instruction, `optimize` enumerates +both directions from every reachable endpoint state and retains the least +cost for each successor state at `N=2`. Induction on the prefix proves that +these are exactly the minimum prefix costs. Including the final returns and +minimizing over terminal states gives the complete minimum; the retained path +attains it. This covers all `2^432` and `2^976` direction choices without an +exponential enumeration. The two separately closed windows optimize independently, +so their minima add. [RESULT.json](RESULT.json) records all reported constants. + +## Reproduce and evidence + +Standard-library Python 3.12, from the repository root: + +```sh +python3.12 -I -B scripts/research_package.py --package research/qq16-bidirectional-sweeps +``` + +Expected primary output, normally and with optimization: + +```text +PASS_QQ16_BIDIRECTIONAL_SWEEPS minimum=11740*N-2714 scalar=17472 no_new_kappa +``` + +The registered command also runs five CLI integrity groups. Direct replay needs +only the package files, works from another directory without Git, and writes +nothing. The generic runner uses Git only to authenticate historical task/base +provenance. There are no imported predecessor executables or Python packages. + +Checks include: + +- Independent literal address enumeration at `N=1..32,64`, including recovery + of both original PR2722 tariffs and both optimized tariffs. +- Exhaustive direction enumeration for all 120 words of lengths 1..4 over a + three-instruction toy alphabet, at `N=1,2,3,5` (6,216 path cases), compared + with the endpoint DP. This covers single-tape clears and idle-head state. +- The affine edge identity for all 223 possible bank differences, both previous + endpoints, both directions and `N=1,2,3,64` (3,568 cases). +- Exact rational full-cell comparisons against the unbridged original windows + at `N=2,3,5`, including nonzero dirty Z0. A wrong source-site alignment at one + final Z write disagrees. Omitting head returns also disagrees. +- Rejection of native events inside a scalar window, borrowed X access, + inactive W16 scratch and aliased ADD fields. +- Git-free read-only replay, source-byte corruption, typed result corruption, + direction-receipt corruption and equivalent gzip recompression. + +Local registered replay passes on CPython 3.12.14 / macOS arm64; direct CPython +3.14.7 replay also passes. Frozen input pins use SHA256 of the decompressed word +and its original Git blob. Gzip container headers do not define mathematical +equality. The verifier is bounded to 256,000 source bytes, 2,415 source events, +1,408 rewritten instructions per window, 64 literal sites and five fixture sites. +Python's managed allocations remain; this is an offline verifier, not a +finite-control tape implementation or a formal-kernel proof. + +## Scope, overlap and family decision + +Selected-source bindings passed; the selected record is unchanged. Base main is +`b017900dbb94d81afec343924c1a7fa6d540a7db`, priority revision 5. The task picker +selected recursive interfaces with nonce `2b009b56cc2256f685cd5a8d0b321095`. +[TASK.json](TASK.json) refines `joint-query-controller` to this exact access +obligation and records live-overlap freshness and source heads. + +PR2722 explicitly leaves other sweep schedules outside its tariff; this provides +one exact protocol optimum, not a correction to that predecessor. PR2540, +PR2651 and PR2709 supply the decoder, bank coalescing and scratch ownership +premises. Later zero-retention QQ16 words have different instructions and are +outside this theorem. The existing investigation is +[Discussion #2617](https://github.com/CrocSwap/integer-mult-bounds/discussions/2617). +No advance public reservation was made; work is reported as a finding. + +The family decision is **narrow and stop at this local lemma**. Unknown caller, +retention, precision, instruction-control and output-consumer costs are not zero. +No complete favorable supplier moment, selected cold replay, full native-kernel +replay, independent human review or new kappa is claimed. A smaller local address +bill alone does not justify another dependent construction campaign. + +## Open next questions + +Can an actual QQ16 caller afford the **whole** physical bill under these +whole-window ownership conditions? Pin its producer/native/consumer schedule, +check W and Z0 availability throughout each window, and combine native +movement, instruction control, precision-dependent source-register work and +retention in one budget. The absent complete caller and physical ledger are the +blockers. Stop if that complete bill is unfavorable. Optimizing more local +schedules before this budget exists is not the recommended next task. + +## Credit + +Arham Tahir, with substantial OpenAI Codex assistance in derivation, +implementation, verification and writing. New work is Apache-2.0. + +Credit **Nick Petalas / PR2722** for the access model, increasing-pass tariffs, +dirty-bridge word and physical-cost handoff; **ywz65 / PR2709 and PR2540** for +scratch-slice reuse and the complete local decoder; **commdata2338 / PR2651** +for output-bank coalescing; and the retained QQ16/native lineage of Ali Romman, +starship-s, Sagar Thakrar, Ross Richardson and the geometry/supplier contributors. +The exact predecessor word is retained byte-for-byte in the compressed input. +Bellman optimization and sweep reversal are standard; this contribution is the +source-bound optimum and all-N proof for the stated physical access protocol. diff --git a/research/qq16-bidirectional-sweeps/RESULT.json b/research/qq16-bidirectional-sweeps/RESULT.json new file mode 100644 index 0000000000..6b6652f0e0 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/RESULT.json @@ -0,0 +1,92 @@ +{ + "windows": { + "L2": { + "instructions": 432, + "bridges": 0, + "maximum_DP_states": 4, + "minimum_travel": [ + 3518, + -850 + ], + "increasing_travel": [ + 3564, + -896 + ], + "reverse_passes": 23 + }, + "F0_inverse": { + "instructions": 976, + "bridges": 8, + "maximum_DP_states": 4, + "minimum_travel": [ + 8222, + -1864 + ], + "increasing_travel": [ + 8302, + -1944 + ], + "reverse_passes": 40 + } + }, + "minimum_total": [ + 11740, + -2714 + ], + "increasing_total": [ + 11866, + -2840 + ], + "scalar_invoice": { + "unit_adds": 864, + "quarter_adds": 832, + "clears": 288, + "real_scalar_primitives": 17472 + }, + "small_controls": { + "tiny_words": 120, + "exhaustive_path_cases": 6216 + }, + "affine_edge_cases": 3568, + "literal_sites": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 64 + ], + "semantic_sites": [ + 2, + 3, + 5 + ], + "scope": "fixed instruction sweeps only; no complete caller or new kappa" +} diff --git a/research/qq16-bidirectional-sweeps/SCHEDULE.json b/research/qq16-bidirectional-sweeps/SCHEDULE.json new file mode 100644 index 0000000000..3777815b02 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/SCHEDULE.json @@ -0,0 +1,4 @@ +{ + "L2": "000001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001010001000000000000000000000000000000000000000000000001", + "F0_inverse": "0000000000000000000000000000000000000001001000000100100000010010000001001000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000101000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000101000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000001010000000000000000000000000000000000000000000000000101000000000000000000000000000000000000000000000001010000100000000010000000001000010000000010000010000100001000010000100001000000010000000000000000" +} diff --git a/research/qq16-bidirectional-sweeps/SOURCES.json b/research/qq16-bidirectional-sweeps/SOURCES.json new file mode 100644 index 0000000000..41b3dd19b4 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/SOURCES.json @@ -0,0 +1,41 @@ +{ + "schema_version": 1, + "base_commit": "b017900dbb94d81afec343924c1a7fa6d540a7db", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "889b95d936746df124872133ae1e7cc339adcb92", + "sha256": "7d185cd8c2af35988d638d969748ad7b670f902606444dbfc748e4402c340df6" + }, + { + "path": "research/joint-query/verify_scalar.py", + "usage": "provenance", + "git_blob": "7a7051fa8a70f48589fa1fccd5c38fccb5eacbf7", + "sha256": "33bdbad17a0531fe527aff306eb235d9c38c1629db4fd167b989725930b0327a" + } + ], + "pending_source": { + "pr": "https://github.com/CrocSwap/integer-mult-bounds/pull/2709", + "author": "ywz65", + "commit": "d7749c49e967b214537c0bd832e435e177e21d4f", + "path": "research/qq16-output-slice-scratch/WORD.json", + "archive": "source-word.json.gz", + "uncompressed_bytes": 202523, + "sha256": "5854aae388d1f11d201b8a02db92dd9b688827dc24280f753c3dc5db069704c5", + "git_blob": "90cd824dbb7cd3d37e519fc1e188e3c944c41119" + }, + "tariff_predecessor": { + "pr": "https://github.com/CrocSwap/integer-mult-bounds/pull/2722", + "author": "Nick Petalas", + "commit": "a9ec1a4f45f36d4ec131e43cf8528ea0e40ea4e8", + "README_sha256": "67485ae1ac211cfd2ca8edb47d1c49c9306d8bcc43c2a9c2eb674f52bf1d387e", + "RESULT_sha256": "0d49c6316319a9234a746b4eb8b6a487ab8d35cd64197cafd197b7c6411ec05b" + } +} diff --git a/research/qq16-bidirectional-sweeps/TASK.json b/research/qq16-bidirectional-sweeps/TASK.json new file mode 100644 index 0000000000..0e89437421 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/TASK.json @@ -0,0 +1,162 @@ +{ + "schema_version": 1, + "task_id": "joint-query-controller", + "priority_revision": 5, + "base_commit": "b017900dbb94d81afec343924c1a7fa6d540a7db", + "original_card": { + "id": "joint-query-controller", + "question": "Can one unresolved retention, output-consumer, hosting or physical-cost obligation complete a pinned QQ16 controller proposal within budget?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/joint-query/README.md", + "research/joint-query/evidence/QQ16-SELECTED-WITNESS.md", + "research/joint-query/evidence/JOINT-QUERY-TRANSFER.md", + "docs/research/community-efficient1000-review.md" + ], + "methods": [ + "Design and price one consumer or retained-state boundary for a pinned local decoder, including final restoration.", + "Audit one claimed physical invoice or prove a target-specific obstruction for its explicit retention/hosting contract." + ], + "acceptance_gate": "Name the changed premise of the fixed F0/B1 observation obstruction. Show exactly which query is recovered, legal native reads and restoration, and a full favorable budget including cover maps, helpers and endpoints. Local inverse identities alone do not close the global controller. 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 QQ16 row in research-family-status.md. The fixed-first-pair witness remains scoped; pending #2540 adds early records and claims a complete local native decoder, but not a favorable global controller. Read its output-frame and ownership contract before designing another inverse.", + "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": "Check live claims and pin the newest relevant completed local word (starting lead #2540). Choose one unresolved consumer, retention, whole-cover movement, hosting or precision obligation. Price the complete proposal and test that obligation; do not repeat its claimed local inverse or native reconstruction unless providing distinct independent verification.", + "bottleneck_link": "The native local words exist; retained query information and its physical access are the missing link to a composed recursive interface.", + "allowed_variations": [ + "One paid query, one changed first pair, or one precisely specified affine helper state.", + "A counterexample or lower bound for that exact proposed repair.", + "One unresolved obligation of a newer local decoder, with exact source heads and a distinct claim/domain." + ], + "scope_change_triggers": [ + "Retaining the fixed first pair and ordinary schedule while allowing only homogeneous selected-only control, already excluded by the witness.", + "Treating cover-map counts as zero-cost physical address operations.", + "Recreating the pending complete local decoder or early-record/output-bank coalescing already under investigation without a distinct audit or changed premise." + ], + "overlap_terms": [ + "QQ16", + "joint-query", + "changing-chart controller", + "selected observation", + "1969", + "2540", + "early record", + "output-bank retention", + "complete native decoder" + ] + }, + "scope_status": "refined", + "actual_scope": "PR2722 fixed dirty-bridge scalar word: exact minimum closed two-tape bank-major word-address travel over one forward or backward complete site sweep per instruction, for every integer N>=1.", + "scope_change_reason": "The complete decoder and scratch access tariff already exist in PR2540/2651/2709/2722. Audit and optimize the still-unoptimized sweep direction within PR2722's explicit bank-major streaming contract, keeping its full scalar bill and ownership premise.", + "bottleneck_link": "Physical scalar access is one unresolved QQ16 caller charge. This result prices the same local word without assuming a free layout conversion or a new native supplier.", + "budget_minutes": 60, + "stop_rule": "Stop on semantic mismatch, changed native/scalar invoice or no distinct travel result. One bounded fixed-word DP; no expanded supplier construction.", + "outcome": "completed", + "evidence": "Exact fixed-protocol optimum 11740*N-2714 versus 11866*N-2840, saving 126*(N-1), with unchanged scalar invoice 17472. Four-state Bellman proof for all N>=1; literal traces, exhaustive tiny-word optimum controls, dirty-state fixtures and CLI integrity tests.", + "author": "Arham Tahir", + "ai_assistance": "Substantial OpenAI Codex assistance in task selection, proof, implementation, checking and writing. No independent human review claimed.", + "open_questions": [ + { + "question": "Can an actual QQ16 caller afford the complete physical bill while owning W and Z0 through these windows?", + "why_it_matters": "Local scalar head travel alone cannot determine whether a complete recursive consumer saves work.", + "first_step": "Pin the actual producer/native/consumer schedule, check whole-window bank lifetimes, and price native movement, retention, source-register arithmetic and instruction control alongside these access tariffs.", + "blocked_by": "No complete physical caller and unified budget are supplied by these pending local modules; unknown costs are not zero." + } + ], + "seed": "2b009b56cc2256f685cd5a8d0b321095", + "selector_scope_key": "b8872a10540bed52f194", + "scope_key": "PR2722/fixed-bridge-word/bidirectional-full-instruction-sweeps", + "declared_milestone": "local module", + "claim_status": "No advance public claim; report as FINDING/DONE after public artifact publication. Initial sandbox-only gh connectivity failure was resolved by authorized network access; Discussion posting is available.", + "optimistic_full_cost_budget": "Keep PR2722's 17472 scalar primitives, native mass 352, wrappers 480 and cover maps 208. Optimize only its 11866*N-2840 closed address travel; unknown caller costs are not zero.", + "unresolved_costs": [ + "whole-window W0..W15 ownership and retention", + "bit-level scalar register arithmetic", + "instruction control", + "surrounding native placement and movement", + "complete output consumer and supplier moment" + ], + "family_expansion_decision": "narrow and stop at one exact access-protocol lemma; full caller costs remain unknown, so no dependent construction campaign", + "method": "Dynamic program over the two head endpoints (at most four states), exact affine-in-N edge costs, separately reconstructed literal address walks and exhaustive tiny-word orientation controls.", + "parameter_domain": "Two pinned windows only; fixed PR2722 dirty bridges; one direction per whole instruction; monotone contiguous pass; both heads start and end at zero for each window; all positive integer site counts.", + "predecessors": [ + { + "pr": 2722, + "author": "Nick Petalas", + "head": "a9ec1a4f45f36d4ec131e43cf8528ea0e40ea4e8" + }, + { + "pr": 2709, + "author": "ywz65", + "head": "d7749c49e967b214537c0bd832e435e177e21d4f" + }, + { + "pr": 2651, + "author": "commdata2338", + "head": "a3b82e6f4ddcf999f8b6dcd3a6dfc3a9543a1533" + }, + { + "pr": 2540, + "author": "ywz65", + "head": "630d557af5088f66b45c447969cee9576600e50b" + } + ], + "overlap": { + "initial_utc": "2026-10-15T21:55:21.594303+00:00", + "read_discussion": "https://github.com/CrocSwap/integer-mult-bounds/discussions/2617", + "coverage": "Complete cached 719 open PRs at 2026-10-15T21:52:04Z; stale 244-record Discussion cache at 2026-10-14T03:53Z. Live topic Discussion2617 and relevant PR2540/2651/2709/2722/2736/2771 read separately. No arbitrary diff or unpublished-work coverage.", + "nearest_overlap": "PR2722 prices exclusively increasing streaming sweeps and explicitly excludes schedule optimization. This refines the same physical access model by changing sweep orientations only.", + "initial_limit_correction": "The initial sandbox-only gh failure did not establish invalid credentials. Authorized network access succeeded; a complete private-cache overlap refresh was subsequently performed.", + "final": { + "searched_at": "2026-10-15T22:05:40.132854+00:00", + "terms": [ + "QQ16", + "serpentine", + "sweep direction", + "scratch-travel", + "bidirectional-sweeps" + ], + "coverage": { + "open_prs": { + "fetched_at": "2026-10-15T22:03:01.690161+00:00", + "complete_pagination": true, + "records": 723 + }, + "discussions": { + "fetched_at": "2026-10-15T22:05:39.993395+00:00", + "complete_pagination": true, + "records": 1434 + } + }, + "warnings": [], + "matches_total": 182, + "limits": "Remote PR scope is open PRs including drafts. Closed work is searched through local READMEs, TASK metadata and ledger only. No code diffs or arbitrary package files are searched. Recheck relevant heads before submission.", + "decision": "No separate QQ16 sweep-direction result identified in the complete body snapshot. Nearest exact overlap remains PR2722, whose increasing protocol is independently reproduced. Broader bidirectional connector results are unrelated. No diffs or unpublished work searched.", + "predecessor_heads_rechecked": { + "2722": "a9ec1a4f45f36d4ec131e43cf8528ea0e40ea4e8", + "2709": "d7749c49e967b214537c0bd832e435e177e21d4f" + } + } + }, + "upstream_checkpoint": { + "checked_main": "84f8e607779b81c05edc962d4981d1f9b4b9bc9f", + "priority_revision": 5, + "checked_utc": "2026-10-15T22:05:15.714660+00:00", + "decision": "Fast-forwarded isolated branch to fetched main; guidance, selected record, runner and consumed scientific inputs are unchanged from the pinned b017900d task base. Historical provenance pins intentionally remain unchanged." + }, + "validation": { + "python": "3.12.14", + "platform": "macOS arm64", + "registered_replay": "normal and optimized primary plus five CLI integrity groups PASS", + "metadata": "PASS_PACKAGE_METADATA_AND_PINS", + "additional_python": "3.14.7 optimized direct primary PASS", + "source_authentication": "Retained decompressed word exactly equals original PR2709 Git blob at d7749c49e967b214537c0bd832e435e177e21d4f, independently fetched." + } +} diff --git a/research/qq16-bidirectional-sweeps/VERIFY.json b/research/qq16-bidirectional-sweeps/VERIFY.json new file mode 100644 index 0000000000..cf5f8e8ed4 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/VERIFY.json @@ -0,0 +1,43 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "-Werror", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact fixed-word Bellman optimum, all-N affine argument controls, literal source/destination travel, dirty-state semantics and source/scoping controls." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "-Werror", + "-O", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "The same acceptance checks under optimization." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "-Werror", + "{package}/test_artifacts.py" + ], + "timeout_seconds": 120, + "checks": "Five CLI groups: Git-free read-only export, source corruption, type-sensitive result corruption, direction-receipt corruption, and equivalent gzip recompression." + } + ] +} diff --git a/research/qq16-bidirectional-sweeps/source-word.json.gz b/research/qq16-bidirectional-sweeps/source-word.json.gz new file mode 100644 index 0000000000..d6f1503718 Binary files /dev/null and b/research/qq16-bidirectional-sweeps/source-word.json.gz differ diff --git a/research/qq16-bidirectional-sweeps/test_artifacts.py b/research/qq16-bidirectional-sweeps/test_artifacts.py new file mode 100644 index 0000000000..a53ce4e0b1 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/test_artifacts.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +"""CLI integrity and portability controls. Apache-2.0.""" +import gzip +import json +import shutil +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path + +HERE = Path(__file__).resolve().parent + + +class Artifacts(unittest.TestCase): + def setUp(self): + self.temporary = tempfile.TemporaryDirectory() + self.root = Path(self.temporary.name) + self.package = self.root / 'export' + self.package.mkdir() + for source in HERE.iterdir(): + if source.is_file(): + shutil.copyfile(source, self.package / source.name) + + def tearDown(self): + self.package.chmod(0o755) + for path in self.package.iterdir(): + path.chmod(0o644) + self.temporary.cleanup() + + def replay(self, success, diagnostic=''): + result = subprocess.run( + [sys.executable, '-I', '-B', '-O', '-Werror', str(self.package / 'verify.py')], + cwd=self.root, capture_output=True, text=True, timeout=30, + ) + self.assertEqual(result.returncode == 0, success, result.stdout + result.stderr) + self.assertIn(diagnostic, result.stdout + result.stderr) + + def test_git_free_read_only_export(self): + before = {p.name: p.read_bytes() for p in self.package.iterdir()} + for path in self.package.iterdir(): + path.chmod(0o444) + self.package.chmod(0o555) + self.replay(True, 'PASS_QQ16_BIDIRECTIONAL_SWEEPS') + self.assertEqual(before, {p.name: p.read_bytes() for p in self.package.iterdir()}) + + def test_source_byte_corruption(self): + path = self.package / 'source-word.json.gz' + raw = gzip.decompress(path.read_bytes()) + changed = raw[:-1] + (b' ' if raw[-1:] != b' ' else b'\n') + path.write_bytes(gzip.compress(changed, mtime=0)) + self.replay(False, 'source SHA256') + + def test_typed_result_corruption(self): + path = self.package / 'RESULT.json' + result = json.loads(path.read_text()) + result['scalar_invoice']['unit_adds'] = True + path.write_text(json.dumps(result)) + self.replay(False, 'typed RESULT.json receipt') + + def test_direction_receipt_corruption(self): + path = self.package / 'SCHEDULE.json' + result = json.loads(path.read_text()) + result['L2'] = ('1' if result['L2'][0] == '0' else '0') + result['L2'][1:] + path.write_text(json.dumps(result)) + self.replay(False, 'typed SCHEDULE.json receipt') + + def test_equivalent_recompression(self): + path = self.package / 'source-word.json.gz' + path.write_bytes(gzip.compress(gzip.decompress(path.read_bytes()), compresslevel=1, mtime=42)) + self.replay(True, 'PASS_QQ16_BIDIRECTIONAL_SWEEPS') + + +if __name__ == '__main__': + unittest.main() diff --git a/research/qq16-bidirectional-sweeps/verify.py b/research/qq16-bidirectional-sweeps/verify.py new file mode 100644 index 0000000000..ed0f63bd52 --- /dev/null +++ b/research/qq16-bidirectional-sweeps/verify.py @@ -0,0 +1,291 @@ +#!/usr/bin/env python3 +"""Optimal QQ16 sweep directions. Arham Tahir, OpenAI Codex assistance. Apache-2.0.""" +import gzip +import hashlib +import itertools +import json +from fractions import Fraction +from pathlib import Path + +HERE = Path(__file__).resolve().parent +WINDOWS = ((633, 1066, 'L2'), (1172, 2125, 'F0_inverse')) +MAX_BYTES = 256_000 +MAX_EVENTS = 1408 +MAX_SITES = 64 + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def field(name): + require(type(name) is str and 2 <= len(name) <= 4, 'field syntax') + require(name[0] in 'ZW' and name[1:].isdigit(), 'owned field') + bank = int(name[1:]) + require(0 <= bank < 112 and name == name[0] + str(bank), 'canonical bank') + return (0 if name[0] == 'Z' else 1), bank + + +def roles(event): + if event['op'] == 'clear': + return [field(event['field'])] + require(event['op'] == 'add', 'scalar-only instruction') + require(event['coefficient'] in ('1', '-1', '1/4', '-1/4'), 'coefficient') + require(event['src'] != event['dst'], 'distinct scalar fields') + return [field(event['src']), field(event['dst'])] + + +def load_word(): + pins = json.loads((HERE / 'SOURCES.json').read_text())['pending_source'] + require(pins['archive'] == 'source-word.json.gz', 'fixed input path') + archive = HERE / 'source-word.json.gz' + require(archive.stat().st_size <= MAX_BYTES, 'compressed source capacity') + with gzip.open(archive, 'rb') as stream: + raw = stream.read(MAX_BYTES + 1) + require(len(raw) == pins['uncompressed_bytes'] <= MAX_BYTES, 'source capacity') + require(hashlib.sha256(raw).hexdigest() == pins['sha256'], 'source SHA256') + header = b'blob ' + str(len(raw)).encode() + b'\0' + require(hashlib.sha1(header + raw).hexdigest() == pins['git_blob'], 'Git blob') + word = json.loads(raw) + require(type(word) is list and len(word) == 2415, 'source word extent') + return word + + +def extract(word, start, stop, name): + first, last = word[start], word[stop] + active = ['W0'] if name == 'L2' else [f'W{i}' for i in range(16)] + for marker, op in ((first, 'output_slices_begin'), (last, 'output_slices_end')): + require(marker['op'] == op and marker['name'] == name, 'window marker') + require(marker['fields'] == active, 'window scratch allocation') + body = word[start + 1:stop] + require(0 < len(body) <= MAX_EVENTS, 'window capacity') + for event in body: + for tape, bank in roles(event): + require(tape == 0 or 'W' + str(bank) in active, 'active W field') + if event['op'] == 'clear': + require(event['frame'] in ('current', 'identity'), 'CLEAR frame') + return body + + +def bridge(body): + """Reconstruct PR2722's dirty bridges without importing its implementation.""" + rewritten, count = [], 0 + for event in body: + touched = roles(event) + if len(touched) == 2 and touched[0][0] == touched[1][0]: + require(touched[0][0] == 1, 'only W-to-W bridges') + require(event['coefficient'] == '-1', 'bridge subtraction') + src, dst = event['src'], event['dst'] + require(int(src[1:]) == int(dst[1:]) + 8, 'paired W bridge') + for source, target, value in ( + (src, 'Z0', '1'), ('Z0', dst, '-1'), + (src, 'Z0', '-1'), ('Z0', dst, '1'), + ): + rewritten.append(dict(op='add', src=source, dst=target, coefficient=value)) + count += 1 + else: + rewritten.append(dict(event)) + require(len(rewritten) <= MAX_EVENTS, 'rewritten event capacity') + for event in rewritten: + ts = [t for t, _ in roles(event)] + require(len(ts) == len(set(ts)), 'at most one bank per tape per instruction') + return rewritten, count + + +def transition(touched, banks, state, direction, sites): + """Endpoint recurrence; direction 0 increases, 1 decreases.""" + next_state, cost = list(state), 0 + for tape, bank in touched: + previous = banks[tape] * sites + state[tape] * (sites - 1) + start = bank * sites + direction * (sites - 1) + cost += abs(start - previous) + sites - 1 + next_state[tape] = 1 - direction + return tuple(next_state), cost + + +def optimize(body): + """Minimizing N=2 minimizes every N>1; all paths have the same cost at N=1.""" + states, banks, largest = {(0, 0): (0, '')}, [0, 0], 1 + for event in body: + touched, following = roles(event), {} + for state, (cost, path) in sorted(states.items()): + for direction in (0, 1): + key, charge = transition(touched, banks, state, direction, 2) + candidate = cost + charge, path + str(direction) + if key not in following or candidate < following[key]: + following[key] = candidate + for tape, bank in touched: + banks[tape] = bank + states = following + largest = max(largest, len(states)) + require(len(states) <= 4, 'two endpoint bits') + options = [] + for state, (cost, path) in states.items(): + home = sum(2 * banks[tape] + state[tape] for tape in (0, 1)) + options.append((cost + home, path)) + minimum, path = min(options) + base = literal_travel(body, path, 1) + return path, [minimum - base, 2 * base - minimum], largest + + +def literal_travel(body, path, sites, return_home=True): + """Separate reference: enumerate actual source and destination addresses.""" + require(type(sites) is int and 1 <= sites <= MAX_SITES, 'trace capacity') + require(type(path) is str and len(path) == len(body), 'one direction per event') + require(set(path) <= {'0', '1'}, 'binary directions') + heads, total = [0, 0], 0 + for event, direction in zip(body, path, strict=True): + order = range(sites) if direction == '0' else range(sites - 1, -1, -1) + for site in order: + for tape, bank in roles(event): + address = bank * sites + site + total += abs(address - heads[tape]) + heads[tape] = address + return total + (sum(heads) if return_home else 0) + + +def execute(body, path, sites, wrong_pair=False): + """Exact dirty scalar fixtures, independent of the movement recurrence.""" + require(1 <= sites <= 5, 'semantic fixture capacity') + rows = { + f'{tape}{bank}': [Fraction((bank + 3)**2 * (s + 1) + offset, 8) + for s in range(sites)] + for tape, offset in (('Z', 0), ('W', 10000)) for bank in range(112) + } + bad_index = max(i for i, event in enumerate(body) + if event['op'] == 'add' and event['dst'][0] == 'Z') + for index, (event, direction) in enumerate(zip(body, path, strict=True)): + order = range(sites) if direction == '0' else range(sites - 1, -1, -1) + for site in order: + if event['op'] == 'clear': + rows[event['field']][site] = Fraction(0) + else: + source_site = sites - 1 - site if wrong_pair and index == bad_index else site + rows[event['dst']][site] += ( + Fraction(event['coefficient']) * rows[event['src']][source_site] + ) + return rows + + +def small_optimality_controls(): + """Exhaust every direction of all words through length 4 in a tiny alphabet.""" + alphabet = [dict(op='clear', field='Z0'), dict(op='clear', field='W1'), + dict(op='add', src='Z2', dst='W0', coefficient='1')] + words, paths = 0, 0 + for length in range(1, 5): + for body in itertools.product(alphabet, repeat=length): + chosen, (slope, intercept), _ = optimize(body) + for sites in (1, 2, 3, 5): + costs = [literal_travel(body, ''.join(p), sites) + for p in itertools.product('01', repeat=length)] + require(min(costs) == slope * sites + intercept, 'exhaustive optimum') + require(literal_travel(body, chosen, sites) == min(costs), 'attainment') + paths += len(costs) + words += 1 + return {'tiny_words': words, 'exhaustive_path_cases': paths} + + +def affine_controls(): + """Check the signed-distance derivation over the entire bank-delta alphabet.""" + cases = 0 + for delta in range(-111, 112): + for previous, start in itertools.product((0, 1), repeat=2): + offset = start - previous + if delta > 0: + slope, intercept = delta + offset, -offset + elif delta < 0: + slope, intercept = -delta - offset, offset + else: + slope, intercept = abs(offset), -abs(offset) + for sites in (1, 2, 3, MAX_SITES): + actual = abs(delta * sites + offset * (sites - 1)) + require(actual == slope * sites + intercept, 'affine edge law') + cases += 1 + return cases + + +def check_window(body, name): + candidate, count = bridge(body) + require(count == (0 if name == 'L2' else 8), 'exact bridge inventory') + path, polynomial, states = optimize(candidate) + increasing = '0' * len(candidate) + old = [3564, -896] if name == 'L2' else [8302, -1944] + for sites in (*range(1, 33), MAX_SITES): + require(literal_travel(candidate, path, sites) == polynomial[0] * sites + + polynomial[1], 'literal optimized address trace') + require(literal_travel(candidate, increasing, sites) == old[0] * sites + + old[1], 'independent PR2722 tariff control') + for sites in (2, 3, 5): + reference = execute(body, '0' * len(body), sites) + require(execute(candidate, path, sites) == reference, 'arbitrary dirty fixture') + require(execute(candidate, path, sites, True) != reference, 'wrong-site control') + require(literal_travel(candidate, path, 3, False) != polynomial[0] * 3 + + polynomial[1], 'omitted return control') + return {'instructions': len(candidate), 'bridges': count, + 'maximum_DP_states': states, 'minimum_travel': polynomial, + 'increasing_travel': old, 'reverse_passes': path.count('1')}, path + + +def reject_controls(word): + for mutation in ('native', 'borrowed', 'inactive', 'alias'): + wrong = [dict(e) for e in word] + if mutation == 'native': + wrong[635] = dict(op='native', field='Z0') + elif mutation == 'borrowed': + wrong[635]['src'] = 'X76' + elif mutation == 'inactive': + wrong[635]['dst'] = 'W16' + else: + wrong[635]['src'] = wrong[635]['dst'] + try: + extract(wrong, 633, 1066, 'L2') + except (KeyError, ValueError): + continue + raise ValueError('accepted malformed source: ' + mutation) + + +def calculate(): + word = load_word() + result, schedule = {}, {} + for start, stop, name in WINDOWS: + result[name], schedule[name] = check_window(extract(word, start, stop, name), name) + reject_controls(word) + receipt = { + 'windows': result, + 'minimum_total': [sum(r['minimum_travel'][i] for r in result.values()) + for i in (0, 1)], + 'increasing_total': [11866, -2840], + 'scalar_invoice': {'unit_adds': 864, 'quarter_adds': 832, 'clears': 288, + 'real_scalar_primitives': 17472}, + 'small_controls': small_optimality_controls(), + 'affine_edge_cases': affine_controls(), + 'literal_sites': [*range(1, 33), MAX_SITES], + 'semantic_sites': [2, 3, 5], + 'scope': 'fixed instruction sweeps only; no complete caller or new kappa', + } + counts = {'unit': 0, 'quarter': 0, 'clear': 0} + for event in word: + if event['op'] == 'clear': + counts['clear'] += 1 + if event['op'] == 'add': + coefficient = abs(Fraction(event['coefficient'])) + require(coefficient in (1, Fraction(1, 4)), 'full-word scalar alphabet') + counts['unit' if coefficient == 1 else 'quarter'] += 1 + require(counts == {'unit': 840, 'quarter': 832, 'clear': 288}, 'source invoice') + return receipt, schedule + + +def main(): + result, schedule = calculate() + for filename, actual in (('RESULT.json', result), ('SCHEDULE.json', schedule)): + expected = json.loads((HERE / filename).read_text()) + require(json.dumps(actual, sort_keys=True) == json.dumps(expected, sort_keys=True), + 'typed ' + filename + ' receipt') + slope, intercept = result['minimum_total'] + print(f'PASS_QQ16_BIDIRECTIONAL_SWEEPS minimum={slope}*N{intercept:+d} ' + 'scalar=17472 no_new_kappa') + + +if __name__ == '__main__': + main()