diff --git a/research/z4-persistent-pair-seed57/LICENSE b/research/z4-persistent-pair-seed57/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/research/z4-persistent-pair-seed57/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/research/z4-persistent-pair-seed57/NOTICE.md b/research/z4-persistent-pair-seed57/NOTICE.md new file mode 100644 index 0000000000..63ac9aab12 --- /dev/null +++ b/research/z4-persistent-pair-seed57/NOTICE.md @@ -0,0 +1 @@ +The files under `inputs/` are copied from CrocSwap/integer-mult-bounds PR #1391 at head `6ce8017e4c27c8b220b6c3a27a53bb18f138212a`, with SHA-256 and Git blob IDs pinned in `verify.py`. They are included as predecessor evidence and to invoke the exact pinned child-word emitter. The new ten-child recurrence, path census, composition map checks, and cost comparison are by Cinna Davis with substantial OpenAI Codex assistance. Preserve upstream license notices when redistributing the copied predecessor files. diff --git a/research/z4-persistent-pair-seed57/README.md b/research/z4-persistent-pair-seed57/README.md new file mode 100644 index 0000000000..001929a89c --- /dev/null +++ b/research/z4-persistent-pair-seed57/README.md @@ -0,0 +1,67 @@ +# A persistent order-four boundary across two root echoes + +**Scoped recursive-interface construction; no new `kappa`, supplier admission, or change to the selected result.** For the pinned PR #1391 child family, two identical five-child root echoes on the same source can be replaced by one ten-child dirty echo that carries its order-four phase across the midpoint. The complete word has 1,904 scalar primitives versus 2,016 for two separate calls, saving 112 primitives and 232 data reads. Its peak prefix row-L1 is 42 instead of 30, so this result does not establish a precision improvement. + +## Assignment and scope + +The OS assignment seed was **57**, on the recursive-interfaces track. The pinned base is `bce54fb3f895cbe5cd4c0eb477c3afeed100190f`. Candidate tasks recorded before selection were (1) share the midpoint restoration between two identical PR #1391 root echoes, (2) extend the paired frame alphabet to order five, and (3) test a six-child extension. Seed rule `57 mod 3 = 0` selected the first. The short claim is recorded in [discussion #1163](https://github.com/CrocSwap/integer-mult-bounds/discussions/1163#discussioncomment-18911847). + +This is exact for the stated order-four macro alphabet and the fixed two-call same-source family. It composes the predecessor's five-child interface; it does not change the physical child supplier, address routing, precision model, selected certificate, or theorem exponent. The motivating interface card asks whether two consecutive calls can eliminate a restoration reconstructed by the next call. Here the joint word removes one separate call's copy/restoration wrapper and avoids paying two independent boundary schedules. It does not prove an improvement for heterogeneous calls or arbitrary ADD/NEG interleavings. + +## Recurrence and complete cost + +For phase `t` in `Z/4Z`, let `A(t)` be the cost of the three-octet workspace frame and `B(t)` the cost of the output frame. The source-pinned phase vectors are + +```text +B = [(0,0), (18,2), (12,4), (18,2)] +A = 3 B +``` + +where each pair is `(ADD, NEG)`. The predecessor recurrence is independently re-evaluated for five and ten children: + +```text +F0(t) = A(t) + B(t) +F(j+1)(s) = min_t { F(j)(t) + A(s-t-1 mod 4) + B(s-t mod 4) } +g(k) = Fk(0) +``` + +The five-child control has path `[0,1,2,3,0,0]`, boundary vector `(126,14)`, total 140; all `4^5 = 1,024` paths are checked. For ten children the optimum is `[0,1,2,3,0,1,2,3,0,1,0]`, with midpoint phase 1, boundary vector `(216,32)`, total 248; all `4^10 = 1,048,576` paths are checked. + +The complete dirty root echo has map + +```text +(D, X, W) -> (D + 2 sum_i R_i X, X, W) +``` + +for arbitrary input vectors `D`, `X`, and `W`. Its full invoice is + +| Schedule | ADD | NEG | Primitives | Reads | Writes | Prefix row-L1 peak | +|---|---:|---:|---:|---:|---:|---:| +| Two separate five-child calls | 1,840 | 176 | 2,016 | 3,856 | 2,016 | 30 | +| Joint ten-child call | 1,720 | 184 | 1,904 | 3,624 | 1,904 | 42 | +| Eager ten-child control | 2,368 | 240 | 2,608 | — | — | — | + +The joint schedule uses 120 fewer ADDs and 8 more NEGs than the two-call schedule. The total decreases by 112. Prefix row-L1 grows by 12; coefficient width, fixed-precision safety, and tape costs are outside this experiment. In particular the result is a gate-count construction, not a resource-admitted supplier or a revised recursive bound. + +## Evidence and reproduction + +`inputs/PR1391-CERTIFICATE.json`, `inputs/PR1391-verify.py`, and `inputs/PR1391-README.md` preserve the predecessor material from PR #1391 at head `6ce8017e4c27c8b220b6c3a27a53bb18f138212a`; hashes and Git blob IDs are checked before importing its word emitter. The inherited source pins are checked against the exact base. The new verifier independently implements the recurrence, complete vector invoice, map expectation, and full path census. The emitted predecessor circuit is reused only as the pinned child-word emitter. + +Run from the repository root: + +```sh +python3 -I -O -B research/z4-persistent-pair-seed57/verify.py +``` + +Expected output begins `PASS_Z4_PERSISTENT_PAIR` and reports `g5 140 g10 248 paths 1048576`, followed by `two_calls 2016 joint 1904 saving 112`. The same verifier also checks 56 basis columns for both separate and joint maps and rejects three controls: omitting the second call, using a wrong output phase, and failing terminal restoration. `test_package.py` repeats focused recurrence and result-receipt assertions. All arithmetic is exact integer arithmetic; the state/path search domain and stopping rule are the finite four-phase paths for exactly 5 and 10 children, exhaustively enumerated. Local replay and package-pin validation passed on CPython 3.14.7, and `make selected-record-check` passed with the exact base kappa unchanged. The registered wrapper declares Python 3.12, which is unavailable locally; that replay, hosted CI, and independent human review remain pending. Exact command receipts are in [VALIDATION.json](VALIDATION.json). + +## Predecessors and attribution + +This result extends the fixed order-four paired-frame construction in [PR #1391](https://github.com/CrocSwap/integer-mult-bounds/pull/1391), which in turn credits Ross Richardson's order-three cyclic-output frame in [PR #1287](https://github.com/CrocSwap/integer-mult-bounds/pull/1287) and Sagar Thakrar's paid output-sign frames in [PR #1227](https://github.com/CrocSwap/integer-mult-bounds/pull/1227). The imported emitter and predecessor certificate are byte-pinned. The ten-child recurrence, exhaustive census, composed dirty map and complete two-call comparison are new in this package. + +Prepared by **Cinna Davis** with substantial **OpenAI Codex assistance** in research, algebra, code, verification and prose. No independent human review or formal proof assistant is claimed. New package material is Apache-2.0; the copied predecessor README/code/certificate retain their upstream attribution and license context. + +## Open next questions + +- Does a named selected supplier expose this exact paired order-four intertwiner? This is necessary before transferring the gate saving into a selected recursive profile. First step: inspect one retained supplier's actual child matrix for the paired-cycle invariant. Blocked by the absence of a precision-admitted physical supplier with this interface. +- Can the 12-unit increase in prefix row-L1 be absorbed under the selected fixed-precision profile? First step: propagate the joint word's exact prefix coefficient envelope through the named host schedule. Blocked by the missing supplier and address/tape admission. diff --git a/research/z4-persistent-pair-seed57/RESULT.json b/research/z4-persistent-pair-seed57/RESULT.json new file mode 100644 index 0000000000..65f59761eb --- /dev/null +++ b/research/z4-persistent-pair-seed57/RESULT.json @@ -0,0 +1,141 @@ +{ + "assignment_seed": 57, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "basis_columns": 56, + "controls": { + "eager_map": "PASS", + "joint_word_map": "PASS", + "missing_terminal_restoration": "REJECTED", + "one_call_omission": "REJECTED", + "two_call_map": "PASS", + "wrong_output_phase": "REJECTED" + }, + "eager_ten_child_control": { + "primitives": 2608, + "vector_ADD_NEG": [ + 2368, + 240 + ] + }, + "five_child_control": { + "boundary_vector_ADD_NEG": [ + 126, + 14 + ], + "exhaustive_paths": 1024, + "states": [ + 0, + 1, + 2, + 3, + 0, + 0 + ], + "total": 140 + }, + "map": "(D,X,W)->(D + 2*sum_i R_i X, X, W)", + "phase_costs": { + "output_B_by_phase": [ + [ + 0, + 0 + ], + [ + 18, + 2 + ], + [ + 12, + 4 + ], + [ + 18, + 2 + ] + ], + "workspace_A_by_phase": [ + [ + 0, + 0 + ], + [ + 54, + 6 + ], + [ + 36, + 12 + ], + [ + 54, + 6 + ] + ] + }, + "predecessor": { + "certificate_git_blob": "0132b117d90f1a7a97c40af3e38503c117604e00", + "certificate_sha256": "2a6ac306ddc6f58514b89f680d8ff3027b4195e2754574f8f04ac1f17785c9d3", + "head": "6ce8017e4c27c8b220b6c3a27a53bb18f138212a", + "inherited_source_pin_count": 6, + "pr": 1391, + "verifier_git_blob": "9d866bbf57a6d1f012a21687bde2e231c90efd14", + "verifier_sha256": "c3d8e76dad9b3cc159affa5e56dbf73612eab0c0ce4a4464f523d4cf47669c05" + }, + "question": "carry the aligned P/Q frame across the middle of two identical five-child root echoes", + "saving_joint_vs_separate": { + "ADD": 120, + "NEG": -8, + "reads": 232, + "total_primitives": 112, + "writes": 112 + }, + "schema_version": 1, + "scope": "Exact for two identical calls on the same source X, the pinned PR1391 child family, and the stated order-four macro alphabet. No supplier admission or kappa claim.", + "ten_child_joint": { + "boundary_total": 248, + "boundary_vector_ADD_NEG": [ + 216, + 32 + ], + "complete_primitives": 1904, + "complete_vector_ADD_NEG": [ + 1720, + 184 + ], + "exhaustive_minimum": 248, + "exhaustive_paths": 1048576, + "mid_call_phase": 1, + "prefix_row_l1_peak": 42, + "reads": 3624, + "states": [ + 0, + 1, + 2, + 3, + 0, + 1, + 2, + 3, + 0, + 1, + 0 + ], + "word_sha256": "901dc9ffbd0f59b8988a3796cef037fbba8caa3ffeb6053b1b816b53e818b844", + "writes": 1904 + }, + "two_separate_calls": { + "combined_primitives": 2016, + "combined_vector_ADD_NEG": [ + 1840, + 176 + ], + "one_call_vector_ADD_NEG": [ + 920, + 88 + ], + "prefix_row_l1_peak": 30, + "reads": 3856, + "word_sha256": "53189fa94fc471b9655bca5154ac9c452054633bccf5fc3be1b798b9069c8422", + "writes": 2016 + } +} diff --git a/research/z4-persistent-pair-seed57/SOURCES.json b/research/z4-persistent-pair-seed57/SOURCES.json new file mode 100644 index 0000000000..9e110c4d48 --- /dev/null +++ b/research/z4-persistent-pair-seed57/SOURCES.json @@ -0,0 +1,55 @@ +{ + "schema_version": 1, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "snapshot": "Exact source tree at base commit; predecessor PR #1391 imported artifacts are separately pinned by verify.py and are not represented as base files.", + "files": [ + { + "path": "CONTRIBUTING.md", + "git_blob": "e51435543687f1bd88ab22248082dc689ce8b853", + "sha256": "df5b5646602f42cb5da5844f04ac925182ddcd0f627b9de1c96a5095bb7a277a", + "usage": "provenance" + }, + { + "path": "certificates/selected-result.json", + "git_blob": "ae6a99f28aa468649eb66a361e764d769363bf11", + "sha256": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "usage": "provenance" + }, + { + "path": "docs/research/current-status.md", + "git_blob": "aa3cf49715cd367ad8c4e63ab28856fc0d19794f", + "sha256": "1f59d648763c77d574d18dc59ea8bf62d2ee74aaed3c202c9c8cfa4f901badbd", + "usage": "provenance" + }, + { + "path": "docs/research/pr-ledger.md", + "git_blob": "4331ba3175b3418f70fb5cf7ee9689b3505c0678", + "sha256": "8030b58f708e40aee4e40f950a20a0b0ccef3f92b08e6e089fe35db82ec027e6", + "usage": "provenance" + }, + { + "path": "docs/research/agent-task-catalog.json", + "git_blob": "c05fafaa25ba95b2d5af86b1800427198e3d20eb", + "sha256": "89b5928bc92c81e2647b6d702a7ad85a6795b8f44e2eb267b2ff3145d8f2b2ce", + "usage": "provenance" + }, + { + "path": "docs/research/community-batch1099-review.md", + "git_blob": "6cb6ec061a071a06a2d18cd4dc3e9a2b05d28099", + "sha256": "7e76d2c38e5fce30587835b7251df1430488ae4dd372611ef69a3f03f476b6cb", + "usage": "provenance" + }, + { + "path": "research/community-frontier1094-audit/ASSEMBLY.json", + "git_blob": "5fd676df060f3b450782fdf5ff5f6beb63a5eeb0", + "sha256": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045", + "usage": "provenance" + }, + { + "path": "research/community-frontier1094-audit/SELECTED-SOURCE.json", + "git_blob": "6a75493790b4eff9c4a98051ef8b01d6aad0d5a8", + "sha256": "79b3de5db3dbcb9829789ba58e9e45758926031e2a7d80667a08429d369be53b", + "usage": "provenance" + } + ] +} diff --git a/research/z4-persistent-pair-seed57/TASK.json b/research/z4-persistent-pair-seed57/TASK.json new file mode 100644 index 0000000000..52f05da2b5 --- /dev/null +++ b/research/z4-persistent-pair-seed57/TASK.json @@ -0,0 +1,66 @@ +{ + "schema_version": 1, + "task_id": "persistent-boundary", + "track": "recursive-interfaces", + "assignment_seed": 57, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "original_card": { + "id": "persistent-boundary", + "question": "Can a specified pair of consecutive calls eliminate a restoration that the next call reconstructs?", + "starting_points": [ + "research/heterogeneous-owner-assembly/README.md", + "certificates/selected-result.json" + ], + "methods": [ + "Write typed entry/exit contracts and a contracting multitype recurrence.", + "Derive a lower bound for the compulsory transitions of one proposed typed interface." + ], + "acceptance_gate": "Show actual eliminated work and legal composition; changing a scalar recurrence into a matrix is insufficient.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Find a concrete consecutive-call boundary in the selected review and list its entry/exit obligations.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Specify two call types and one operation actually removed by composition; derive the normalized recurrence.", + "bottleneck_link": "Eliminating compulsory boundary work can lower recursive cost beyond packing gains.", + "allowed_variations": [ + "A two-type pilot or one explicit deferred restoration." + ], + "scope_change_triggers": [ + "Rewriting the old scalar recurrence as a matrix without eliminating work." + ], + "overlap_terms": [ + "persistent boundary", + "deferred restoration", + "multitype" + ] + }, + "scope_status": "refined", + "scope_change_reason": "The broad interface question is refined to the same-source, same-family pair of two order-four five-child echoes already pinned in PR #1391; no heterogeneous call types or supplier change are considered.", + "actual_scope": "For two identical five-child PR #1391 root echoes on the same source X, test a joint ten-child dirty echo that carries the order-four boundary phase across the midpoint; compare its fully priced word and exact map with two separate calls.", + "bottleneck_link": "The original card targets compulsory boundary work; a joint call can carry one legal phase path across the midpoint and avoid the second independently compiled copy/restoration wrapper.", + "stop_rule": "Stop after exact finite-state optimality for lengths 5 and 10, complete dirty-map and ADD/NEG/read/write/prefix invoices, or if the joint map fails or the favorable complete cost is not below two separate calls. Do not generalize beyond the pinned macro alphabet.", + "evidence": "The README, standalone verifier, deterministic RESULT.json, and focused test record the recurrence, full dirty-map checks, exhaustive path coverage and complete invoices.", + "author": "Cinna Davis", + "ai_assistance": "Substantial OpenAI Codex assistance in algebra, implementation, verification, and prose; no independent human review is claimed.", + "outcome": "completed", + "open_questions": [ + { + "question": "Does a named selected supplier expose this exact paired order-four intertwiner?", + "why_it_matters": "Only a compatible precision-admitted supplier could transfer this gate saving to a selected recursive profile.", + "first_step": "Inspect one retained supplier exact child matrix for the paired-cycle invariant.", + "blocked_by": "No physical supplier with this interface has been admitted." + }, + { + "question": "Can the larger prefix row-L1 peak be absorbed by a selected fixed-precision profile?", + "why_it_matters": "The joint call raises the checked peak from 30 to 42, so primitive savings alone do not establish precision feasibility.", + "first_step": "Propagate the exact joint-word prefix coefficient envelope through a named host schedule.", + "blocked_by": "Supplier, address, tape, and fixed-precision admission are outside this experiment." + } + ] +} diff --git a/research/z4-persistent-pair-seed57/VALIDATION.json b/research/z4-persistent-pair-seed57/VALIDATION.json new file mode 100644 index 0000000000..ad0fc11bd1 --- /dev/null +++ b/research/z4-persistent-pair-seed57/VALIDATION.json @@ -0,0 +1,35 @@ +{ + "schema_version": 1, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "environment": { + "python": "CPython 3.14.7", + "python_3_12": "unavailable in local environment" + }, + "passed": [ + { + "command": "python3 -I -O -B research/z4-persistent-pair-seed57/verify.py", + "result": "PASS_Z4_PERSISTENT_PAIR; g5=140, g10=248 over 1,048,576 paths; joint=1904, separate=2016; all 56 columns and three negative controls checked." + }, + { + "command": "python3 -I -O -B research/z4-persistent-pair-seed57/test_package.py", + "result": "PASS_SEED57_PACKAGE_TESTS focused_recurrence=1 receipt=1" + }, + { + "command": "python3 scripts/research_package.py --package research/z4-persistent-pair-seed57 --check-only", + "result": "PASS_PACKAGE_METADATA_AND_PINS; not a mathematical acceptance check." + }, + { + "command": "make selected-record-check", + "result": "PASS selected record, exact kappa, original source inventory and proof supplement: 836330098538459/500000000000000000" + }, + { + "command": "git diff --check", + "result": "PASS" + } + ], + "not_run": [ + "Registered Python 3.12 replay, because Python 3.12 is not installed locally.", + "Hosted CI and independent human review." + ], + "scope_limit": "The checks establish the finite stated macro-alphabet construction and pinned map only; they do not establish supplier admission, precision feasibility, a recursive-profile change or a new kappa." +} diff --git a/research/z4-persistent-pair-seed57/VERIFY.json b/research/z4-persistent-pair-seed57/VERIFY.json new file mode 100644 index 0000000000..a89dbdd312 --- /dev/null +++ b/research/z4-persistent-pair-seed57/VERIFY.json @@ -0,0 +1,45 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/z4-persistent-pair-seed57/README.md", + "research/z4-persistent-pair-seed57/NOTICE.md", + "research/z4-persistent-pair-seed57/LICENSE", + "research/z4-persistent-pair-seed57/TASK.json", + "research/z4-persistent-pair-seed57/SOURCES.json", + "research/z4-persistent-pair-seed57/VERIFY.json", + "research/z4-persistent-pair-seed57/verify.py", + "research/z4-persistent-pair-seed57/test_package.py", + "research/z4-persistent-pair-seed57/RESULT.json", + "research/z4-persistent-pair-seed57/inputs/PR1391-CERTIFICATE.json", + "research/z4-persistent-pair-seed57/inputs/PR1391-README.md", + "research/z4-persistent-pair-seed57/inputs/PR1391-verify.py", + "research/z4-persistent-pair-seed57/VALIDATION.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "research/z4-persistent-pair-seed57/verify.py" + ], + "checks": "Pinned predecessor artifacts and source pins; exact recurrence and exhaustive five/ten-child path minima; arbitrary dirty-state maps on 56 basis columns; complete gate/read/write/prefix invoices; three negative controls.", + "timeout_seconds": 90 + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-B", + "research/z4-persistent-pair-seed57/test_package.py" + ], + "checks": "Focused recurrence control and deterministic result receipt.", + "timeout_seconds": 90 + } + ] +} diff --git a/research/z4-persistent-pair-seed57/inputs/PR1391-CERTIFICATE.json b/research/z4-persistent-pair-seed57/inputs/PR1391-CERTIFICATE.json new file mode 100644 index 0000000000..0132b117d9 --- /dev/null +++ b/research/z4-persistent-pair-seed57/inputs/PR1391-CERTIFICATE.json @@ -0,0 +1,240 @@ +{ + "assignment": { + "cycle_order": 4, + "os_seed": 56, + "track": "recursive interfaces" + }, + "base_commit": "bce54fb3f895cbe5cd4c0eb477c3afeed100190f", + "boundary": { + "children": 5, + "dynamic_program_total": 140, + "eager_ADD": 270, + "eager_NEG": 30, + "eager_total": 300, + "eager_word_sha256": "90bf97554a5a1529e96f128ad93e54aeadbfeffbdd73f3c546ceb4f1e0d91273", + "exhaustive_path_count": 1024, + "exhaustive_path_minimum": 140, + "macro_alphabet": "canonical powers P^u and Q^v using the listed explicit words", + "optimized_ADD": 126, + "optimized_NEG": 14, + "optimized_word_sha256": "3459ba0aca8bd5e598696333a1a5b520d4a0e5353553d685732cf7d49acbd097", + "saved_per_batch": 160, + "states": [ + 0, + 1, + 2, + 3, + 0, + 0 + ], + "transitions": [ + { + "P_power": 0, + "Q_power": 1, + "after": 1, + "before": 0 + }, + { + "P_power": 0, + "Q_power": 1, + "after": 2, + "before": 1 + }, + { + "P_power": 0, + "Q_power": 1, + "after": 3, + "before": 2 + }, + { + "P_power": 0, + "Q_power": 1, + "after": 0, + "before": 3 + }, + { + "P_power": 3, + "Q_power": 0, + "after": 0, + "before": 0 + } + ] + }, + "child": { + "checked_basis_columns": 96, + "distinct_block_checks": [ + { + "ADD": 62, + "NEG": 6, + "basis_columns": 32, + "block": 0, + "inverse_word_sha256": "12a83c7b67cc26872a45569df66568dce8d6f47697ae23d08a7731d1c3e957d4", + "word_sha256": "24a9f259f8d8bcd826a8feec7f0dbbf22f10c5fa10e2ed0b5e101ea22bebfe95" + }, + { + "ADD": 62, + "NEG": 6, + "basis_columns": 32, + "block": 1, + "inverse_word_sha256": "ed74b775d98f56e0b6a9b6153f5dce0e352d7597dd275e84bdfe7ef91db8282c", + "word_sha256": "33c9708615463d38ac54c283ff87d3755c2a02edfa6535a3fdce7555ed8091ea" + }, + { + "ADD": 62, + "NEG": 6, + "basis_columns": 32, + "block": 2, + "inverse_word_sha256": "8f1ba7d29abb2b862f689a3ca7aec86cc9c7c8387aa5d66c905472dbcd6f46b5", + "word_sha256": "2d9232ba4a81a06041bf4057a798aa538985524cbf97b40caca085fcefd309e4" + } + ], + "per_call": { + "ADD": 62, + "NEG": 6, + "total": 68 + }, + "selection_blocks": [ + 0, + 1, + 2, + 0, + 1 + ] + }, + "complete_echo": { + "all_arbitrary_dirty_basis_columns": 56, + "dispatches": { + "eager": 1328, + "optimized": 1008 + }, + "eager": { + "ADD": 1208, + "NEG": 120, + "total": 1328 + }, + "eager_word_sha256": "ee0e4afaf3cf2b1dbfc65e2eff076c92dba34fe8aa768fc8b506f9d22382c883", + "internal_C_v_example": { + "all_arbitrary_input_and_scratch_basis_columns": 56, + "eager": { + "ADD": 1262, + "NEG": 126, + "total": 1388 + }, + "eager_word_sha256": "b63466d5724bf7e60b6fcdb8bca73feaec48788326b43f70804dff1764cc07dc", + "optimized": { + "ADD": 974, + "NEG": 94, + "total": 1068 + }, + "optimized_word_sha256": "436ab81a02fc6013b6b167937c2294d4547b6f8ffd3888db5569f5c2cedc3131" + }, + "layout": { + "output_D": 8, + "source_X": 24, + "total_data_coordinates": 56, + "working_W": 24 + }, + "map": "(D,X,W)->(D+sum_i R_i X,X,W)", + "optimized": { + "ADD": 920, + "NEG": 88, + "total": 1008 + }, + "optimized_word_sha256": "ecaf6008f7c81a6c495ce146b971b53d4c3a9b1fea6289645285045796235451", + "prefix_row_l1_peak": { + "eager": 11, + "optimized": 20 + }, + "reads": { + "eager": 2536, + "optimized": 1928 + }, + "saved_total_primitives": 320, + "writes": { + "eager": 1328, + "optimized": 1008 + } + }, + "controls": { + "count": 4, + "names": [ + "rotation sign mutation", + "wrong output phase", + "missing terminal restoration", + "forward word substituted for inverse" + ] + }, + "frame": { + "determinant": 1, + "intertwining_verified": true, + "order": 4, + "output_octets": 1, + "per_register": "two disjoint 4-cycles on one octet", + "phase_costs_per_octet": [ + { + "ADD": 0, + "NEG": 0, + "phase": 0, + "total": 0, + "word_sha256": "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945" + }, + { + "ADD": 18, + "NEG": 2, + "phase": 1, + "total": 20, + "word_sha256": "652fe5774a3dc187f9df6fd2e578f0270a4a898e76edd1c5e57446ad5281d6fa" + }, + { + "ADD": 12, + "NEG": 4, + "phase": 2, + "total": 16, + "word_sha256": "3db669a9548039bbfc034e92b0c3edf8a540d8b147cb95618eddd3e225e13bb4" + }, + { + "ADD": 18, + "NEG": 2, + "phase": 3, + "total": 20, + "word_sha256": "278ea7a94adedef7155f32189da6002570d43d68701817674a62494c22d0ea22" + } + ], + "readers": [ + 0, + 1, + 2, + 0, + 1 + ], + "workspace_octets": 3 + }, + "recursive_interface_cost": { + "complete_root_echo": "2*sum(child vectors) + (48,0) + 2*g(k_v)", + "depth_storage": "56 data coordinates for the root echo plus 24 per active nested internal C_v level", + "eager_comparator": "replace g(k_v) by k_v*(54,6)", + "g(k)": "minimum 4-state recurrence below; vector ADD/NEG invoice retained along chosen path", + "internal_C_v": "2*sum(child vectors) + (48,0) + 2*g(k_v) + (54,6)", + "leaf_forward": { + "ADD": 62, + "NEG": 6 + } + }, + "schema_version": 1, + "scope": "Exact finite dirty-state interface construction and macro-alphabet optimum for five children; no actual supplier admission, selected profile change, new kappa, or multiplication theorem.", + "selected_context": { + "decimal": "0.001672660197076918", + "kappa": "836330098538459/500000000000000000", + "review": "docs/research/community-batch1099-review.md", + "selected_source_pr": 1094 + }, + "source_pins": { + "certificates/selected-result.json": "10b9e340fd8e354a37a0c4813c90e5de1dd42044b5f6aca4a3fc5a42b685fa32", + "docs/research/agent-task-catalog.json": "89b5928bc92c81e2647b6d702a7ad85a6795b8f44e2eb267b2ff3145d8f2b2ce", + "docs/research/community-batch1099-review.md": "7e76d2c38e5fce30587835b7251df1430488ae4dd372611ef69a3f03f476b6cb", + "docs/research/current-status.md": "1f59d648763c77d574d18dc59ea8bf62d2ee74aaed3c202c9c8cfa4f901badbd", + "research/community-frontier1094-audit/ASSEMBLY.json": "1122cb3a575f8c788345fc1bf4c108ac7c3250fb81a5988671f5eb04b3ab3045", + "research/community-frontier1094-audit/SELECTED-SOURCE.json": "79b3de5db3dbcb9829789ba58e9e45758926031e2a7d80667a08429d369be53b" + }, + "task": "z4-paired-frame-restoration-seed56" +} diff --git a/research/z4-persistent-pair-seed57/inputs/PR1391-README.md b/research/z4-persistent-pair-seed57/inputs/PR1391-README.md new file mode 100644 index 0000000000..36a48934ed --- /dev/null +++ b/research/z4-persistent-pair-seed57/inputs/PR1391-README.md @@ -0,0 +1,136 @@ +# Paired order-four frames defer repeated workspace restoration + +**Scoped recursive-interface construction; no new `kappa` and no supplier adoption.** A fixed five-child interface admits a cheap boundary schedule when one four-cycle frame is carried across child calls and paid back at the end. The exact complete dirty echo uses **1,008 scalar primitives** instead of **1,328** for eager restoration. The order-four signed gate accounting and this fixture are new; this extends the order-three frame interface in [PR #1287](https://github.com/CrocSwap/integer-mult-bounds/pull/1287) without reusing its implementation. + +The assignment seed is **56**, on the recursive-interface track. The seed-selected cycle order is `2 + (56 mod 3) = 4`. The exact research base is `bce54fb3f895cbe5cd4c0eb477c3afeed100190f`. Current selected context at that base remains the maintainer-reviewed conditional finite construction with `kappa = 836330098538459/500000000000000000 = 0.001672660197076918`, selected from Rohan Arun's PR #1094 on Jeremy Kothe's retained word and the PR589/555 bit lineage. The source record, review, selected source manifest and assembly are pinned in [SOURCES.json](SOURCES.json). The selected record is unchanged. + +## The fixed child contract + +An **octet frame** is two disjoint four-cycles. On either quartet, + +```text +(a,b,c,d) -> (d,a,b,c). +``` + +Let `P` act by this same paired cycle on each of three eight-coordinate workspace blocks (`W` has 24 coordinates), and let `Q` act on one output octet (`D` has 8 coordinates). Each has order four and determinant `+1` because it is the product of two odd four-cycles. For `i` in `(0,1,2,0,1)`, `R_i` selects workspace octet `i` and the child is the indivisible map + +```text +C_i(D,W) = (D + R_i W, P W), R_i P = Q R_i. +``` + +All 8 output coordinates and all 24 workspace coordinates may be arbitrary. The displayed intertwining equality is checked exactly for all three distinct selectors. In an aligned frame `t`, the child contribution is `Q^t R_i W`; any different output phase gives the wrong contribution for that selector. + +The macro alphabet between children consists only of the explicit whole-register powers `P^u` and `Q^v`, for `u,v in Z/4Z`. A pure swap can use + +```text +a += b; b -= a; a += b; NEG(b) +``` + +and maps `(a,b)` to `(b,a)` exactly. The quarter-turn uses fewer gates than three pure swaps: apply the 3-ADD signed swaps `(a,b)->(b,-a)`, `(a,c)->(-c,a)`, and `(a,d)->(d,-a)`, then `NEG(b)`, to obtain `(d,a,b,c)` in **9 ADD + 1 NEG**. Its half-turn uses two disjoint pure swaps, costing **6 ADD + 2 NEG**. The inverse quarter-turn has the same counts. No frame annotation, clean scratch or free operation is used. These are explicit circuit costs, not claims of primitive optimality. + +The signed-swap words are + +```text +T+(a,b): a += b; b -= a; a += b gives (b,-a) +T-(a,b): b += a; a -= b; b += a gives (-b,a) +``` + +For a quartet, the sequence `T+(a,b); T-(a,c); T+(a,d); NEG(b)` passes through `(b,-a,c,d)`, `(-c,-a,b,d)`, `(d,-a,b,c)`, then `(d,a,b,c)`. + +Per output octet, the four phase costs are: + +| Phase | ADD | NEG | Total | +|---:|---:|---:|---:| +| 0 | 0 | 0 | 0 | +| 1 | 18 | 2 | 20 | +| 2 | 12 | 4 | 16 | +| 3 | 18 | 2 | 20 | + +`P` acts on three octets, so its phase cost is three times this vector; `Q` uses one copy. The full words and their exact matrices are produced by the verifier. + +## Exact boundary recurrence + +Let `t` be the common workspace/output phase immediately before a child. That child advances phases to `(t+1,t)`. To finish the gap in aligned phase `s`, there is one required pair of powers: + +```text +P^(s-t-1) on W, Q^(s-t) on D. +``` + +Write `A(r)` for the total primitive cost of `P^r` on all 24 workspace coordinates and `B(r)` for the total cost of `Q^r` on `D`. The exact shortest-path recurrence in this fixed macro alphabet is + +```text +F_0(t) = A(t) + B(t) +F_(j+1)(s) = min_t [F_j(t) + A(s-t-1 mod 4) + B(s-t mod 4)] +g(k) = F_k(0). +``` + +Entrance and terminal corrections are included. Before the first child the two phases must agree; after the last child both registers must be canonical because `D` and `W` are arbitrary. Every legal macro word therefore gives one path in the four-state graph, and every path is emitted by the stated powers. This proves the recurrence for every positive child count in the declared alphabet. For the five-child fixture, a complete path census checks all `4^5 = 1,024` phase paths. + +The minimum path is `[0,1,2,3,0,0]`. It rotates `Q` once after each of the first four children, then pays one `P^3` workspace correction after the fifth: + +| Batch boundary | Optimized ADD | Optimized NEG | Total | Eager total | +|---|---:|---:|---:|---:| +| `g(5)` | 126 | 14 | **140** | **300** | + +The eager schedule restores `P^-1` after every child. The optimized schedule saves 160 primitives per batch. This is exact optimality only among the fixed macro powers, not among arbitrary ADD/NEG words that might be inserted into gaps. + +## Complete dirty echo and recursive invoice + +Each leaf child reads eight selected coordinates with eight ADDs and applies `P` to the 24-coordinate workspace. Its complete forward and literal inverse costs are both `(62 ADD, 6 NEG) = 68` primitives. A five-child forward batch therefore costs `(436 ADD, 44 NEG) = 480` when optimized, versus `(580 ADD, 60 NEG) = 640` eagerly. + +The full echo uses a separate arbitrary source `X` and dirty work register `W`: + +```text +W += X; H(D,W); W -= X; H^-1(D,W) +``` + +Both copies cost 24 ADDs. `H^-1` is the literal reversed batch word with each ADD sign reversed; it includes every inverse child. The verified map is `(D,X,W) -> (D + sum_i R_i X, X, W)` for arbitrary dirty `D`, `X` and `W`. + +| Complete echo | ADD | NEG | Total primitives | Data reads | Data writes | +|---|---:|---:|---:|---:|---:| +| Optimized frames | 920 | 88 | **1,008** | 1,928 | 1,008 | +| Eager restoration | 1,208 | 120 | **1,328** | 2,536 | 1,328 | + +Here each ADD reads two cells and writes one; each NEG reads and writes one. Dispatches equal primitive count. Peak data storage is exactly 56 coordinates for this root echo: 8 output, 24 source and 24 work coordinates. Sums of intertwining readers still satisfy `R_v P = Q R_v`, so an internal node can use `R_v = sum_i R_i` as the same typed child interface. Its complete cost recurrence is + +```text +leaf C: T = (62,6) +internal C: T_v = 2 sum_i T_i + (48,0) + 2 g_vec(k_v) + (54,6) +root echo: E_v = 2 sum_i T_i + (48,0) + 2 g_vec(k_v) +``` + +Vectors are `(ADD,NEG)`. `g_vec` is the phase vector on a minimum-total path. The `(48,0)` term is the copy and restoration of all 24 coordinates. The final `(54,6)` in `C_v` applies `P` to its own input workspace. The eager comparison replaces `g_vec(k_v)` with `k_v*(54,6)`. Each simultaneously active nested internal child needs one additional 24-coordinate scratch block, so peak storage for this fixed interface is `56 + 24h`, where `h` is the number of nested internal levels below the root echo. No clean scratch is assumed. + +For the five-leaf fixture, the internal `C_v` itself costs `(974 ADD, 94 NEG) = 1,068` primitives with optimized frames and `(1,262 ADD, 126 NEG) = 1,388` eagerly. The verifier checks both internal maps and the literal inverse on all 56 input/scratch basis columns. The 60-operation final `P` on the interface input is included in both totals. + +For the root echo, the optimized word raises the exact prefix row-L1 bound from 11 to 20. Its benefit in primitive count carries a precision-width risk. Address travel, coefficient fetches and descriptor storage are not priced as a supplier implementation; no runtime or fixed-precision improvement is claimed. + +## Verification + +From the repository root, run: + +```sh +python3 -I -O -B research/z4-paired-frame-restoration-seed56/verify.py +``` + +Expected marker: + +```text +PASS_Z4_PAIRED_FRAME boundary=140_vs_300 echo=1008_vs_1328 saved=320 root_cost=ADD920+NEG88 basis_columns=56 controls=4 no_new_kappa +``` + +The standalone verifier checks the selected source pins; order-four frame powers and determinant; all `R_iP=QR_i` identities; child and literal inverse maps; the recurrence minimum against all 1,024 paths; both complete batch maps; the full echo on all 56 basis columns; the ADD/NEG, copy, inverse and data-access invoices; and four failure controls for a bad rotation sign, a wrong output phase, missing terminal restoration and forward-for-inverse substitution. It uses only the Python standard library. Local verification used CPython 3.14.7; the package hook declares the repository's Python 3.12 environment. The registered wrapper's replay mode requires Python 3.12, which is unavailable locally; its metadata/pin check and the standalone verifier pass. A full selected cold replay, hosted CI run and independent human review were not performed. + +## Scope and predecessors + +The closest predecessor is Ross Richardson's [PR #1287](https://github.com/CrocSwap/integer-mult-bounds/pull/1287), which supplies an order-three cyclic output-frame recurrence and dirty echo. This package independently treats an order-four, determinant-positive paired frame with explicit NEG costs and a new complete invoice. It also credits Sagar Thakrar's [PR #1227](https://github.com/CrocSwap/integer-mult-bounds/pull/1227) for paid output-sign frames. PR #805's determinant-balanced cyclic leaf concerns a different cyclic recurrence and coefficient/precision model; PR #846's cyclic inverse concerns stride-dependent tape scheduling. No predecessor implementation is copied. Exact checked-out source pins and predecessor heads are listed in [SOURCES.json](SOURCES.json) and [PREDECESSORS.json](PREDECESSORS.json). + +This does not identify a real selected supplier with the indivisible order-four child contract. Physical hosting, routing, tape, fixed precision, coefficient access, common-label admission and analytic transfer remain open. The selected `kappa` and all selected files are unchanged. No full multiplication theorem or universal optimality claim follows from this finite construction. + +## Open next questions + +Can a named candidate supplier expose the paired order-four intertwiner `R P = Q R`? This matters because only a compatible supplier can turn the boundary invoice into a changed recursive profile. A feasible first step is to inspect one retained supplier's exact child matrices for an eight-coordinate paired-cycle invariant; the blocker is that no physical hosting or precision-admitted supplier has yet been identified. + +## Credit + +Prepared by **Cinna Davis** with substantial **OpenAI Codex assistance** in algebra, code, verification and prose. The verifier and certificate are AI-assisted; no independent human review or proof-assistant formalization is implied. Prior work is credited above and pinned in `PREDECESSORS.json`. New package material is Apache-2.0. diff --git a/research/z4-persistent-pair-seed57/inputs/PR1391-verify.py b/research/z4-persistent-pair-seed57/inputs/PR1391-verify.py new file mode 100644 index 0000000000..9d866bbf57 --- /dev/null +++ b/research/z4-persistent-pair-seed57/inputs/PR1391-verify.py @@ -0,0 +1,606 @@ +#!/usr/bin/env python3 +"""Exact finite check for a paired order-four dirty-output frame.""" + +import argparse +import hashlib +import itertools +import json +import math +from pathlib import Path + + +PKG = Path(__file__).resolve().parent +ROOT = PKG.parent.parent +CERT = PKG / "CERTIFICATE.json" +SEED = 56 +BASE = "bce54fb3f895cbe5cd4c0eb477c3afeed100190f" +BLOCKS = (0, 1, 2, 0, 1) +WORK_OCTETS = 3 +OUTPUT_WIDTH = 8 +WORK_WIDTH = 8 * WORK_OCTETS +LOCAL_WIDTH = OUTPUT_WIDTH + WORK_WIDTH +ECHO_WIDTH = OUTPUT_WIDTH + WORK_WIDTH + WORK_WIDTH + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def add(target, source, sign=1): + require(sign in (-1, 1), "ADD sign must be +/-1") + return ("ADD", target, source, sign) + + +def neg(target): + return ("NEG", target, None, 0) + + +def inverse_word(word): + inverse = [] + for kind, target, source, sign in reversed(word): + inverse.append(add(target, source, -sign) if kind == "ADD" else neg(target)) + return inverse + + +def lift_word(word, indices): + lifted = [] + for kind, target, source, sign in word: + lifted.append((kind, indices[target], None if source is None else indices[source], sign)) + return lifted + + +def swap_word(a, b): + """Pure swap (a,b)->(b,a), using three ADDs and one NEG.""" + return [add(a, b), add(b, a, -1), add(a, b), neg(b)] + + +def signed_swap_positive(a, b): + """Three ADDs map (a,b)->(b,-a).""" + return [add(a, b), add(b, a, -1), add(a, b)] + + +def signed_swap_negative(a, b): + """Three ADDs map (a,b)->(-b,a).""" + return [add(b, a), add(a, b, -1), add(b, a)] + + +def one_cycle_word(phase, base=0): + """Powers of (a,b,c,d)->(d,a,b,c) on one four-register cycle.""" + require(phase in range(4), "invalid phase") + a, b, c, d = (base + i for i in range(4)) + if phase == 0: + return [] + if phase == 1: + # Three signed swaps compose to (d,-a,b,c); one NEG on b gives + # the requested pure cycle (d,a,b,c). + return (signed_swap_positive(a, b) + signed_swap_negative(a, c) + + signed_swap_positive(a, d) + [neg(b)]) + if phase == 2: + return swap_word(a, c) + swap_word(b, d) + return inverse_word(one_cycle_word(1, base)) + + +def octet_word(phase, base=0): + """Apply the same phase to two disjoint four-cycles.""" + return one_cycle_word(phase, base) + one_cycle_word(phase, base + 4) + + +def workspace_word(phase, base=0): + """Apply P^phase to three disjoint eight-register blocks.""" + return sum((octet_word(phase, base + 8 * j) for j in range(WORK_OCTETS)), []) + + +def word_counts(word): + adds = sum(kind == "ADD" for kind, *_ in word) + negs = sum(kind == "NEG" for kind, *_ in word) + return (adds, negs) + + +def word_sha256(word): + payload = json.dumps(word, separators=(",", ":"), ensure_ascii=True).encode("ascii") + return hashlib.sha256(payload).hexdigest() + + +def vector_add(a, b): + return tuple(x + y for x, y in zip(a, b)) + + +def vector_scale(a, n): + return tuple(n * x for x in a) + + +def vector_total(a): + return sum(a) + + +def phase_counts(phase): + return word_counts(octet_word(phase)) + + +def work_phase_counts(phase): + return word_counts(workspace_word(phase)) + + +def apply_word_matrix(word, width): + """Return output rows as exact integer linear forms in the input rows.""" + rows = [[int(i == j) for j in range(width)] for i in range(width)] + for kind, target, source, sign in word: + require(0 <= target < width, "gate target outside matrix") + if kind == "ADD": + require(source is not None and 0 <= source < width, "gate source outside matrix") + rows[target] = [a + sign * b for a, b in zip(rows[target], rows[source])] + else: + rows[target] = [-x for x in rows[target]] + return rows + + +def matmul(a, b): + require(bool(a) and bool(b) and len(a[0]) == len(b), "bad matrix dimensions") + bt = list(zip(*b)) + return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a] + + +def identity(n): + return [[int(i == j) for j in range(n)] for i in range(n)] + + +def matrix_power(a, exponent): + out = identity(len(a)) + for _ in range(exponent): + out = matmul(out, a) + return out + + +def expected_octet_frame(): + rows = [[0] * 8 for _ in range(8)] + for base in (0, 4): + # New tuple is (old d, old a, old b, old c). + for target, source in ((base, base + 3), (base + 1, base), + (base + 2, base + 1), (base + 3, base + 2)): + rows[target][source] = 1 + return rows + + +def block_diag(blocks): + widths = [len(block) for block in blocks] + total = sum(widths) + out = [[0] * total for _ in range(total)] + offset = 0 + for block, width in zip(blocks, widths): + for i in range(width): + for j in range(width): + out[offset + i][offset + j] = block[i][j] + offset += width + return out + + +def reader_matrix(block): + rows = [[0] * WORK_WIDTH for _ in range(OUTPUT_WIDTH)] + for j in range(OUTPUT_WIDTH): + rows[j][8 * block + j] = 1 + return rows + + +def child_word(block): + word = [add(j, OUTPUT_WIDTH + 8 * block + j) for j in range(OUTPUT_WIDTH)] + work_indices = [OUTPUT_WIDTH + j for j in range(WORK_WIDTH)] + return word + lift_word(workspace_word(1), work_indices) + + +def expected_child(block): + r = reader_matrix(block) + p = matrix_power(expected_octet_frame(), 1) + rows = [] + for i in range(OUTPUT_WIDTH): + rows.append([int(i == j) for j in range(OUTPUT_WIDTH)] + r[i]) + for i in range(WORK_WIDTH): + rows.append([0] * OUTPUT_WIDTH + block_diag([p] * WORK_OCTETS)[i]) + return rows + + +def expected_child_inverse(block): + r = reader_matrix(block) + p_inverse = matrix_power(expected_octet_frame(), 3) + correction = matmul(r, block_diag([p_inverse] * WORK_OCTETS)) + rows = [] + for i in range(OUTPUT_WIDTH): + rows.append([int(i == j) for j in range(OUTPUT_WIDTH)] + [-x for x in correction[i]]) + for i in range(WORK_WIDTH): + rows.append([0] * OUTPUT_WIDTH + block_diag([p_inverse] * WORK_OCTETS)[i]) + return rows + + +def batch_word(states, blocks=BLOCKS, wrong_first_output_phase=False, omit_last_gap=False): + """Emit a batch; states list aligned phases at entrance/after each child.""" + require(len(states) == len(blocks) + 1, "wrong state path length") + require(all(p in range(4) for p in states), "phase outside Z/4Z") + work_indices = [OUTPUT_WIDTH + j for j in range(WORK_WIDTH)] + word = lift_word(octet_word(states[0]), list(range(OUTPUT_WIDTH))) + word += lift_word(workspace_word(states[0]), work_indices) + for i, block in enumerate(blocks): + word += child_word(block) + if omit_last_gap and i == len(blocks) - 1: + continue + old, new = states[i], states[i + 1] + u = (new - old - 1) % 4 + v = (new - old) % 4 + if wrong_first_output_phase and i == 0: + v = (v + 1) % 4 + word += lift_word(workspace_word(u), work_indices) + word += lift_word(octet_word(v), list(range(OUTPUT_WIDTH))) + return word + + +def boundary_components(states): + total = vector_add(work_phase_counts(states[0]), phase_counts(states[0])) + for i, (old, new) in enumerate(zip(states, states[1:])): + u = (new - old - 1) % 4 + v = (new - old) % 4 + total = vector_add(total, work_phase_counts(u)) + total = vector_add(total, phase_counts(v)) + return total + + +def dynamic_plan(k): + require(k > 0, "positive child count required") + wcost = [vector_scale(phase_counts(p), WORK_OCTETS) for p in range(4)] + ocost = [phase_counts(p) for p in range(4)] + f = [vector_total(vector_add(wcost[t], ocost[t])) for t in range(4)] + predecessors = [] + for _ in range(k): + g = [0] * 4 + pred = [0] * 4 + for s in range(4): + choices = [] + for t in range(4): + u, v = (s - t - 1) % 4, (s - t) % 4 + step = vector_add(wcost[u], ocost[v]) + choices.append((f[t] + vector_total(step), t)) + g[s], pred[s] = min(choices) + f = g + predecessors.append(pred) + state = 0 # final arbitrary-output/restoration endpoint is canonical + reverse_states = [state] + for pred in reversed(predecessors): + state = pred[state] + reverse_states.append(state) + states = list(reversed(reverse_states)) + return states, f[0], boundary_components(states) + + +def brute_boundary_min(k): + best = None + for prefix in itertools.product(range(4), repeat=k): + states = list(prefix) + [0] + cost = vector_total(boundary_components(states)) + best = cost if best is None else min(best, cost) + return best + + +def expected_batch(blocks=BLOCKS): + rsum = [[0] * WORK_WIDTH for _ in range(OUTPUT_WIDTH)] + for block in blocks: + r = reader_matrix(block) + for i in range(OUTPUT_WIDTH): + rsum[i] = [a + b for a, b in zip(rsum[i], r[i])] + rows = [] + for i in range(OUTPUT_WIDTH): + rows.append([int(i == j) for j in range(OUTPUT_WIDTH)] + rsum[i]) + rows.extend([[0] * OUTPUT_WIDTH + row for row in identity(WORK_WIDTH)]) + return rows + + +def lifted_batch_word(states): + local = batch_word(states) + mapping = list(range(OUTPUT_WIDTH)) + [OUTPUT_WIDTH + WORK_WIDTH + i for i in range(WORK_WIDTH)] + return lift_word(local, mapping) + + +def echo_word(states): + word = [add(OUTPUT_WIDTH + WORK_WIDTH + i, OUTPUT_WIDTH + i) for i in range(WORK_WIDTH)] + body = lifted_batch_word(states) + word += body + word += [add(OUTPUT_WIDTH + WORK_WIDTH + i, OUTPUT_WIDTH + i, -1) for i in range(WORK_WIDTH)] + word += inverse_word(body) + return word + + +def expected_echo(blocks=BLOCKS): + rsum = [[0] * WORK_WIDTH for _ in range(OUTPUT_WIDTH)] + for block in blocks: + r = reader_matrix(block) + for i in range(OUTPUT_WIDTH): + rsum[i] = [a + b for a, b in zip(rsum[i], r[i])] + rows = [] + for i in range(OUTPUT_WIDTH): + rows.append([int(i == j) for j in range(OUTPUT_WIDTH)] + rsum[i] + [0] * WORK_WIDTH) + rows.extend([[0] * OUTPUT_WIDTH + row + [0] * WORK_WIDTH for row in identity(WORK_WIDTH)]) + rows.extend([[0] * (OUTPUT_WIDTH + WORK_WIDTH) + row for row in identity(WORK_WIDTH)]) + return rows + + +def internal_c_word(states): + """Implement one internal C_v using source X and a separate dirty scratch.""" + word = echo_word(states) + source_indices = [OUTPUT_WIDTH + j for j in range(WORK_WIDTH)] + return word + lift_word(workspace_word(1), source_indices) + + +def expected_internal_c(): + echo = expected_echo() + p = block_diag([expected_octet_frame()] * WORK_OCTETS) + rows = [row[:] for row in echo[:OUTPUT_WIDTH]] + rows.extend([[0] * OUTPUT_WIDTH + p[i] + [0] * WORK_WIDTH + for i in range(WORK_WIDTH)]) + rows.extend([[0] * (OUTPUT_WIDTH + WORK_WIDTH) + row + for row in identity(WORK_WIDTH)]) + return rows + + +def reject_controls(states, batch_expected): + controls = 0 + # A sign mutation in the rotation circuit must not pass its frame identity. + broken = octet_word(1) + kind, target, source, sign = broken[0] + broken[0] = (kind, target, source, -sign) + require(apply_word_matrix(broken, 8) != expected_octet_frame(), "bad rotation control escaped") + controls += 1 + + # An extra output phase at the first gap violates the reader/frame contract. + misaligned = batch_word(states, wrong_first_output_phase=True) + require(apply_word_matrix(misaligned, LOCAL_WIDTH) != batch_expected, + "misaligned phase control escaped") + controls += 1 + + # Omitting the terminal correction must leave a noncanonical dirty workspace. + unclosed = batch_word(states, omit_last_gap=True) + require(apply_word_matrix(unclosed, LOCAL_WIDTH) != batch_expected, + "missing terminal restoration control escaped") + controls += 1 + + # A forward batch followed by itself is not the literal inverse operation. + forward = batch_word(states) + doubled = forward + forward + require(apply_word_matrix(doubled, LOCAL_WIDTH) != identity(LOCAL_WIDTH), + "forward-for-inverse control escaped") + controls += 1 + return controls + + +def permutation_determinant(matrix): + columns = [] + signs = [] + for row in matrix: + nonzero = [(j, x) for j, x in enumerate(row) if x] + require(len(nonzero) == 1 and nonzero[0][1] in (-1, 1), + "frame is not a signed permutation") + columns.append(nonzero[0][0]) + signs.append(nonzero[0][1]) + inversions = sum(columns[i] > columns[j] + for i in range(len(columns)) for j in range(i + 1, len(columns))) + return (-1 if inversions % 2 else 1) * math.prod(signs) + + +def prefix_row_l1_peak(word, width): + rows = identity(width) + peak = max(sum(abs(x) for x in row) for row in rows) + for kind, target, source, sign in word: + if kind == "ADD": + rows[target] = [a + sign * b for a, b in zip(rows[target], rows[source])] + else: + rows[target] = [-x for x in rows[target]] + peak = max(peak, *(sum(abs(x) for x in row) for row in rows)) + return peak + + +def verify_source_pins(): + pins = json.loads((PKG / "SOURCES.json").read_text()) + require(pins["base_commit"] == BASE, "SOURCES base mismatch") + for entry in pins["files"]: + path = ROOT / entry["path"] + require(path.is_file(), "missing pinned input: " + entry["path"]) + got = hashlib.sha256(path.read_bytes()).hexdigest() + require(got == entry["sha256"], "pinned input bytes changed: " + entry["path"]) + return {entry["path"]: entry["sha256"] for entry in pins["files"]} + + +def build_certificate(): + source_pins = verify_source_pins() + p1 = expected_octet_frame() + phase_vectors = [word_counts(octet_word(p)) for p in range(4)] + require(phase_vectors == [(0, 0), (18, 2), (12, 4), (18, 2)], "octet gate-cost vector changed") + for phase in range(4): + require(apply_word_matrix(octet_word(phase), 8) == matrix_power(p1, phase), + "octet phase word does not implement P^phase") + require(apply_word_matrix(workspace_word(phase), WORK_WIDTH) + == block_diag([matrix_power(p1, phase)] * WORK_OCTETS), + "workspace phase word does not implement P^phase") + require(matrix_power(p1, 4) == identity(8) and p1 != identity(8), "frame is not order four") + require(matrix_power(p1, 2) != identity(8), "frame has order two") + require(permutation_determinant(p1) == 1, "paired four-cycle frame is not orientation-preserving") + + q = p1 + readers = [reader_matrix(block) for block in BLOCKS] + for r in readers: + require(matmul(r, block_diag([p1] * WORK_OCTETS)) == matmul(q, r), + "reader does not intertwine P and Q") + + child_counts = [] + child_columns = 0 + for block in sorted(set(BLOCKS)): + word = child_word(block) + expected = expected_child(block) + require(apply_word_matrix(word, LOCAL_WIDTH) == expected, + "child word differs from its declared dirty-state map") + inv = inverse_word(word) + require(apply_word_matrix(inv, LOCAL_WIDTH) == expected_child_inverse(block), + "literal child inverse differs from the block inverse formula") + require(matmul(apply_word_matrix(inv, LOCAL_WIDTH), expected) == identity(LOCAL_WIDTH), + "child inverse does not restore arbitrary input") + require(word_counts(word) == (62, 6), "child invoice changed") + require(word_counts(inv) == word_counts(word), "literal child inverse count changed") + child_counts.append({"block": block, "ADD": 62, "NEG": 6, + "word_sha256": word_sha256(word), + "inverse_word_sha256": word_sha256(inv), + "basis_columns": LOCAL_WIDTH}) + child_columns += LOCAL_WIDTH + + states, optimum, chosen_vector = dynamic_plan(5) + require(states == [0, 1, 2, 3, 0, 0], "unexpected deterministic shortest path") + require(optimum == 140 and chosen_vector == (126, 14) and vector_total(chosen_vector) == optimum, + "four-state recurrence returned an unexpected boundary cost") + require(brute_boundary_min(5) == optimum, "exhaustive 4^5 schedule census disagrees") + eager_vec = vector_scale(work_phase_counts(3), 5) + require(eager_vec == (270, 30) and vector_total(eager_vec) == 300, + "eager per-child restoration invoice changed") + + batch = batch_word(states) + batch_map = apply_word_matrix(batch, LOCAL_WIDTH) + expected_h = expected_batch() + require(batch_map == expected_h, "optimized batch does not implement the full typed map") + batch_inv = inverse_word(batch) + require(matmul(apply_word_matrix(batch_inv, LOCAL_WIDTH), batch_map) + == identity(LOCAL_WIDTH), "literal inverse batch fails on dirty columns") + eager_states = [0] * (len(BLOCKS) + 1) + eager_batch = batch_word(eager_states) + require(apply_word_matrix(eager_batch, LOCAL_WIDTH) == expected_h, + "eager baseline does not implement the same batch map") + require(word_counts(batch) == (436, 44), "optimized batch primitive invoice changed") + require(word_counts(eager_batch) == (580, 60), "eager batch primitive invoice changed") + + echo_opt = echo_word(states) + echo_eager = echo_word(eager_states) + echo_expected = expected_echo() + require(apply_word_matrix(echo_opt, ECHO_WIDTH) == echo_expected, + "optimized echo fails arbitrary dirty/source inputs") + require(apply_word_matrix(echo_eager, ECHO_WIDTH) == echo_expected, + "eager echo is not the same complete map") + require(word_counts(echo_opt) == (920, 88), "optimized echo primitive invoice changed") + require(word_counts(echo_eager) == (1208, 120), "eager echo primitive invoice changed") + require(len(echo_opt) == 1008 and len(echo_eager) == 1328, + "complete echo totals changed") + + internal_opt = internal_c_word(states) + internal_eager = internal_c_word(eager_states) + internal_expected = expected_internal_c() + require(apply_word_matrix(internal_opt, ECHO_WIDTH) == internal_expected, + "internal recursive C_v map fails arbitrary input/scratch columns") + require(apply_word_matrix(internal_eager, ECHO_WIDTH) == internal_expected, + "eager internal C_v map differs from the optimized interface") + require(matmul(apply_word_matrix(inverse_word(internal_opt), ECHO_WIDTH), internal_expected) + == identity(ECHO_WIDTH), "internal C_v literal inverse fails") + require(word_counts(internal_opt) == (974, 94), "optimized internal C_v invoice changed") + require(word_counts(internal_eager) == (1262, 126), "eager internal C_v invoice changed") + + control_count = reject_controls(states, expected_h) + phase_changes = [] + for old, new in zip(states, states[1:]): + phase_changes.append({"before": old, "after": new, + "P_power": (new - old - 1) % 4, + "Q_power": (new - old) % 4}) + return { + "schema_version": 1, + "task": "z4-paired-frame-restoration-seed56", + "base_commit": BASE, + "assignment": {"os_seed": SEED, "track": "recursive interfaces", + "cycle_order": 2 + SEED % 3}, + "selected_context": { + "kappa": "836330098538459/500000000000000000", + "decimal": "0.001672660197076918", + "selected_source_pr": 1094, + "review": "docs/research/community-batch1099-review.md", + }, + "frame": { + "per_register": "two disjoint 4-cycles on one octet", + "determinant": 1, + "order": 4, + "phase_costs_per_octet": [ + {"phase": p, "ADD": c[0], "NEG": c[1], "total": sum(c), + "word_sha256": word_sha256(octet_word(p))} + for p, c in enumerate(phase_vectors) + ], + "workspace_octets": WORK_OCTETS, + "output_octets": 1, + "readers": list(BLOCKS), + "intertwining_verified": True, + }, + "boundary": { + "children": len(BLOCKS), + "states": states, + "transitions": phase_changes, + "dynamic_program_total": optimum, + "exhaustive_path_count": 4 ** len(BLOCKS), + "exhaustive_path_minimum": brute_boundary_min(5), + "optimized_ADD": chosen_vector[0], + "optimized_NEG": chosen_vector[1], + "eager_ADD": eager_vec[0], + "eager_NEG": eager_vec[1], + "eager_total": vector_total(eager_vec), + "saved_per_batch": vector_total(eager_vec) - optimum, + "optimized_word_sha256": word_sha256(batch), + "eager_word_sha256": word_sha256(eager_batch), + "macro_alphabet": "canonical powers P^u and Q^v using the listed explicit words", + }, + "child": {"per_call": {"ADD": 62, "NEG": 6, "total": 68}, + "selection_blocks": list(BLOCKS), "distinct_block_checks": child_counts, + "checked_basis_columns": child_columns}, + "complete_echo": { + "layout": {"output_D": OUTPUT_WIDTH, "source_X": WORK_WIDTH, + "working_W": WORK_WIDTH, "total_data_coordinates": ECHO_WIDTH}, + "map": "(D,X,W)->(D+sum_i R_i X,X,W)", + "optimized": {"ADD": 920, "NEG": 88, "total": 1008}, + "eager": {"ADD": 1208, "NEG": 120, "total": 1328}, + "saved_total_primitives": 320, + "dispatches": {"optimized": 1008, "eager": 1328}, + "reads": {"optimized": 1928, "eager": 2536}, + "writes": {"optimized": 1008, "eager": 1328}, + "optimized_word_sha256": word_sha256(echo_opt), + "eager_word_sha256": word_sha256(echo_eager), + "all_arbitrary_dirty_basis_columns": ECHO_WIDTH, + "prefix_row_l1_peak": {"optimized": prefix_row_l1_peak(echo_opt, ECHO_WIDTH), + "eager": prefix_row_l1_peak(echo_eager, ECHO_WIDTH)}, + "internal_C_v_example": { + "optimized": {"ADD": 974, "NEG": 94, "total": 1068}, + "eager": {"ADD": 1262, "NEG": 126, "total": 1388}, + "optimized_word_sha256": word_sha256(internal_opt), + "eager_word_sha256": word_sha256(internal_eager), + "all_arbitrary_input_and_scratch_basis_columns": ECHO_WIDTH, + }, + }, + "recursive_interface_cost": { + "leaf_forward": {"ADD": 62, "NEG": 6}, + "internal_C_v": "2*sum(child vectors) + (48,0) + 2*g(k_v) + (54,6)", + "complete_root_echo": "2*sum(child vectors) + (48,0) + 2*g(k_v)", + "g(k)": "minimum 4-state recurrence below; vector ADD/NEG invoice retained along chosen path", + "eager_comparator": "replace g(k_v) by k_v*(54,6)", + "depth_storage": "56 data coordinates for the root echo plus 24 per active nested internal C_v level", + }, + "controls": {"count": control_count, + "names": ["rotation sign mutation", "wrong output phase", "missing terminal restoration", + "forward word substituted for inverse"]}, + "source_pins": source_pins, + "scope": "Exact finite dirty-state interface construction and macro-alphabet optimum for five children; no actual supplier admission, selected profile change, new kappa, or multiplication theorem.", + } + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--emit", action="store_true", help="write the exact computed certificate") + args = parser.parse_args() + certificate = build_certificate() + encoded = json.dumps(certificate, sort_keys=True, indent=2) + "\n" + if args.emit: + CERT.write_text(encoded) + else: + require(CERT.is_file(), "missing CERTIFICATE.json; run --emit once while authoring") + saved = json.loads(CERT.read_text()) + require(saved == certificate, "committed certificate differs from recomputed evidence") + echo = certificate["complete_echo"] + print("PASS_Z4_PAIRED_FRAME boundary=140_vs_300 " + "echo=1008_vs_1328 saved=320 root_cost=ADD920+NEG88 " + "basis_columns=56 controls=4 no_new_kappa") + + +if __name__ == "__main__": + main() diff --git a/research/z4-persistent-pair-seed57/test_package.py b/research/z4-persistent-pair-seed57/test_package.py new file mode 100644 index 0000000000..2a33186286 --- /dev/null +++ b/research/z4-persistent-pair-seed57/test_package.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +"""Focused assertions for the seed57 persistent-boundary package.""" +import importlib.util +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +spec = importlib.util.spec_from_file_location("seed57_verify", HERE / "verify.py") +module = importlib.util.module_from_spec(spec) +spec.loader.exec_module(module) +legacy, predecessor = module.load_legacy() +work, output = module.phase_vectors(legacy, predecessor) +states5, v5 = module.optimize(5, work, output) +brute5, paths5 = module.exhaustive(5, work, output) +assert (states5, v5, paths5, brute5[0]) == ([0, 1, 2, 3, 0, 0], (126, 14), 1024, 140) +result = json.loads((HERE / "RESULT.json").read_text()) +assert result["ten_child_joint"]["exhaustive_paths"] == 1048576 +assert result["ten_child_joint"]["complete_primitives"] == 1904 +assert result["two_separate_calls"]["combined_primitives"] == 2016 +assert result["saving_joint_vs_separate"]["total_primitives"] == 112 +assert result["controls"]["missing_terminal_restoration"] == "REJECTED" +print("PASS_SEED57_PACKAGE_TESTS focused_recurrence=1 receipt=1") diff --git a/research/z4-persistent-pair-seed57/verify.py b/research/z4-persistent-pair-seed57/verify.py new file mode 100644 index 0000000000..89cd11ccff --- /dev/null +++ b/research/z4-persistent-pair-seed57/verify.py @@ -0,0 +1,280 @@ +#!/usr/bin/env python3 +"""Check whether two order-four root echoes can share their middle restoration.""" + +import hashlib +import importlib.util +import itertools +import json +from pathlib import Path +import subprocess + + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +BASE = "bce54fb3f895cbe5cd4c0eb477c3afeed100190f" +PREDECESSOR_HEAD = "6ce8017e4c27c8b220b6c3a27a53bb18f138212a" +PREDECESSOR_CERT_SHA256 = "2a6ac306ddc6f58514b89f680d8ff3027b4195e2754574f8f04ac1f17785c9d3" +PREDECESSOR_CERT_BLOB = "0132b117d90f1a7a97c40af3e38503c117604e00" +PREDECESSOR_CODE_SHA256 = "c3d8e76dad9b3cc159affa5e56dbf73612eab0c0ce4a4464f523d4cf47669c05" +PREDECESSOR_CODE_BLOB = "9d866bbf57a6d1f012a21687bde2e231c90efd14" +CERT_PATH = HERE / "inputs/PR1391-CERTIFICATE.json" +CODE_PATH = HERE / "inputs/PR1391-verify.py" + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def load_legacy(): + cert_raw = CERT_PATH.read_bytes() + code_raw = CODE_PATH.read_bytes() + require(hashlib.sha256(cert_raw).hexdigest() == PREDECESSOR_CERT_SHA256, "PR1391 certificate SHA") + require(hashlib.sha256(code_raw).hexdigest() == PREDECESSOR_CODE_SHA256, "PR1391 verifier SHA") + cert_blob = subprocess.run(["git", "hash-object", str(CERT_PATH)], cwd=ROOT, + check=True, capture_output=True, text=True).stdout.strip() + code_blob = subprocess.run(["git", "hash-object", str(CODE_PATH)], cwd=ROOT, + check=True, capture_output=True, text=True).stdout.strip() + require(cert_blob == PREDECESSOR_CERT_BLOB and code_blob == PREDECESSOR_CODE_BLOB, + "PR1391 Git blob pins") + spec = importlib.util.spec_from_file_location("pr1391_pinned", CODE_PATH) + legacy = importlib.util.module_from_spec(spec) + spec.loader.exec_module(legacy) + cert = json.loads(cert_raw) + require(cert["base_commit"] == BASE and cert["assignment"]["os_seed"] == 56, + "PR1391 base/assignment pin") + for path, digest in cert["source_pins"].items(): + pinned = subprocess.run(["git", "show", BASE + ":" + path], cwd=ROOT, + check=True, capture_output=True).stdout + require(hashlib.sha256(pinned).hexdigest() == digest, "PR1391 inherited source pin " + path) + require(cert["boundary"]["dynamic_program_total"] == 140 + and cert["boundary"]["exhaustive_path_count"] == 1024, + "PR1391 five-child control") + return legacy, cert + + +def addv(a, b): + return tuple(x + y for x, y in zip(a, b)) + + +def total(v): + return sum(v) + + +def phase_vectors(legacy, cert): + per_octet = [legacy.word_counts(legacy.octet_word(p)) for p in range(4)] + recorded = [(row["ADD"], row["NEG"]) for row in cert["frame"]["phase_costs_per_octet"]] + require(per_octet == recorded == [(0, 0), (18, 2), (12, 4), (18, 2)], "phase gate costs") + return [tuple(3 * x for x in v) for v in per_octet], per_octet + + +def step_vector(old, new, work, output): + return addv(work[(new - old - 1) % 4], output[(new - old) % 4]) + + +def path_vector(states, work, output): + v = addv(work[states[0]], output[states[0]]) + for old, new in zip(states, states[1:]): + v = addv(v, step_vector(old, new, work, output)) + return v + + +def optimize(k, work, output): + # F_0(t)=A(t)+B(t); each step completes one child and aligns at s. + f = [total(addv(work[t], output[t])) for t in range(4)] + parents = [] + for _ in range(k): + nxt, pred = [0] * 4, [0] * 4 + for s in range(4): + nxt[s], pred[s] = min((f[t] + total(step_vector(t, s, work, output)), t) + for t in range(4)) + f = nxt + parents.append(pred) + state = 0 + reverse = [state] + for pred in reversed(parents): + state = pred[state] + reverse.append(state) + states = list(reversed(reverse)) + v = path_vector(states, work, output) + require(total(v) == f[0], "recurrence path vector") + return states, v + + +def exhaustive(k, work, output): + best = None + checked = 0 + for prefix in itertools.product(range(4), repeat=k): + states = prefix + (0,) + v = path_vector(states, work, output) + candidate = (total(v), states, v) + if best is None or candidate < best: + best = candidate + checked += 1 + return best, checked + + +def emit_echo(legacy, states, blocks, wrong_first_output_phase=False, require_terminal=True): + require(len(states) == len(blocks) + 1, "echo path length") + if require_terminal: + require(states[-1] == 0, "root echo must restore canonical terminal frame") + body_local = legacy.batch_word(states, blocks=blocks, + wrong_first_output_phase=wrong_first_output_phase) + mapping = list(range(legacy.OUTPUT_WIDTH)) + [ + legacy.OUTPUT_WIDTH + legacy.WORK_WIDTH + i for i in range(legacy.WORK_WIDTH)] + body = legacy.lift_word(body_local, mapping) + word = [legacy.add(legacy.OUTPUT_WIDTH + legacy.WORK_WIDTH + i, + legacy.OUTPUT_WIDTH + i) + for i in range(legacy.WORK_WIDTH)] + word += body + word += [legacy.add(legacy.OUTPUT_WIDTH + legacy.WORK_WIDTH + i, + legacy.OUTPUT_WIDTH + i, -1) + for i in range(legacy.WORK_WIDTH)] + word += legacy.inverse_word(body) + return word + + +def expected_double_echo(legacy, blocks): + width = legacy.ECHO_WIDTH + rows = legacy.identity(width) + for block in blocks: + for j in range(legacy.OUTPUT_WIDTH): + rows[j][legacy.OUTPUT_WIDTH + 8 * block + j] += 1 + return rows + + +def path_rows(states): + return [{"after_child": i, "phase": s} for i, s in enumerate(states)] + + +def build_result(): + legacy, predecessor = load_legacy() + work, output = phase_vectors(legacy, predecessor) + blocks5 = tuple(legacy.BLOCKS) + blocks10 = blocks5 + blocks5 + states5, g5 = optimize(5, work, output) + states10, g10 = optimize(10, work, output) + brute5, paths5 = exhaustive(5, work, output) + brute10, paths10 = exhaustive(10, work, output) + require((states5, g5, paths5, brute5[0]) == + ([0, 1, 2, 3, 0, 0], (126, 14), 1024, 140), "five-child control") + require((states10, g10, paths10, brute10[0]) == + ([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 0], (216, 32), 1048576, 248), + "ten-child exhaustive optimum") + + one = emit_echo(legacy, states5, blocks5) + separate = one + one + joint = emit_echo(legacy, states10, blocks10) + eager_states = [0] * 11 + eager = emit_echo(legacy, eager_states, blocks10) + expected_one = expected_double_echo(legacy, blocks5) + expected_joint = expected_double_echo(legacy, blocks10) + require(legacy.apply_word_matrix(one, legacy.ECHO_WIDTH) == expected_one, + "five-child positive control map") + require(legacy.apply_word_matrix(separate, legacy.ECHO_WIDTH) == expected_joint, + "two successive calls do not compose to the doubled reader map") + require(legacy.apply_word_matrix(joint, legacy.ECHO_WIDTH) == expected_joint, + "joint ten-child word has the wrong dirty-state map") + require(legacy.apply_word_matrix(eager, legacy.ECHO_WIDTH) == expected_joint, + "eager ten-child control map") + require(legacy.apply_word_matrix(one, legacy.ECHO_WIDTH) != expected_joint, + "one-call omission control escaped") + + wrong_output_phase = emit_echo(legacy, states10, blocks10, wrong_first_output_phase=True) + require(legacy.apply_word_matrix(wrong_output_phase, legacy.ECHO_WIDTH) != expected_joint, + "wrong output phase control escaped") + terminal_bad = list(states10) + terminal_bad[-1] = 1 + terminal_word = emit_echo(legacy, terminal_bad, blocks10, require_terminal=False) + require(legacy.apply_word_matrix(terminal_word, legacy.ECHO_WIDTH) != expected_joint, + "missing terminal restoration control escaped") + + leaf = tuple(predecessor["recursive_interface_cost"]["leaf_forward"][k] + for k in ("ADD", "NEG")) + require(leaf == (62, 6), "leaf vector") + def root_invoice(k, boundary): + return addv(addv(tuple(2 * k * x for x in leaf), (48, 0)), + tuple(2 * x for x in boundary)) + joint_vector = root_invoice(10, g10) + single_vector = root_invoice(5, g5) + separate_vector = tuple(2 * x for x in single_vector) + eager_boundary = tuple(10 * x for x in work[3]) + eager_vector = root_invoice(10, eager_boundary) + joint_counts = legacy.word_counts(joint) + separate_counts = legacy.word_counts(separate) + eager_counts = legacy.word_counts(eager) + joint_prefix = legacy.prefix_row_l1_peak(joint, legacy.ECHO_WIDTH) + separate_prefix = legacy.prefix_row_l1_peak(separate, legacy.ECHO_WIDTH) + require(joint_counts == joint_vector and separate_counts == separate_vector + and eager_counts == eager_vector, "complete vector invoice") + require((total(joint_vector), total(separate_vector), total(eager_vector)) == + (1904, 2016, 2608), "complete primitive total") + require(joint_vector == (1720, 184) and separate_vector == (1840, 176), + "ADD/NEG component totals") + require((joint_prefix, separate_prefix) == (42, 30), "complete echo prefix row-L1 peaks") + + result = { + "schema_version": 1, + "base_commit": BASE, + "assignment_seed": 57, + "predecessor": {"pr": 1391, "head": PREDECESSOR_HEAD, + "certificate_sha256": PREDECESSOR_CERT_SHA256, + "certificate_git_blob": PREDECESSOR_CERT_BLOB, + "verifier_sha256": PREDECESSOR_CODE_SHA256, + "verifier_git_blob": PREDECESSOR_CODE_BLOB, + "inherited_source_pin_count": len(predecessor["source_pins"])}, + "question": "carry the aligned P/Q frame across the middle of two identical five-child root echoes", + "phase_costs": {"workspace_A_by_phase": [list(v) for v in work], + "output_B_by_phase": [list(v) for v in output]}, + "five_child_control": {"states": states5, "boundary_vector_ADD_NEG": list(g5), + "total": total(g5), "exhaustive_paths": paths5}, + "ten_child_joint": {"states": states10, "mid_call_phase": states10[5], + "boundary_vector_ADD_NEG": list(g10), "boundary_total": total(g10), + "exhaustive_paths": paths10, "exhaustive_minimum": brute10[0], + "complete_vector_ADD_NEG": list(joint_vector), + "complete_primitives": total(joint_vector), + "word_sha256": legacy.word_sha256(joint), + "reads": 2 * joint_vector[0] + joint_vector[1], + "writes": total(joint_vector), + "prefix_row_l1_peak": legacy.prefix_row_l1_peak(joint, legacy.ECHO_WIDTH)}, + "two_separate_calls": {"one_call_vector_ADD_NEG": list(single_vector), + "combined_vector_ADD_NEG": list(separate_vector), + "combined_primitives": total(separate_vector), + "word_sha256": legacy.word_sha256(separate), + "prefix_row_l1_peak": separate_prefix, + "reads": 2 * separate_vector[0] + separate_vector[1], + "writes": total(separate_vector)}, + "eager_ten_child_control": {"vector_ADD_NEG": list(eager_vector), + "primitives": total(eager_vector)}, + "saving_joint_vs_separate": {"ADD": separate_vector[0] - joint_vector[0], + "NEG": separate_vector[1] - joint_vector[1], + "total_primitives": total(separate_vector) - total(joint_vector), + "reads": 2 * separate_vector[0] + separate_vector[1] + - (2 * joint_vector[0] + joint_vector[1]), + "writes": total(separate_vector) - total(joint_vector)}, + "map": "(D,X,W)->(D + 2*sum_i R_i X, X, W)", + "basis_columns": legacy.ECHO_WIDTH, + "controls": {"one_call_omission": "REJECTED", "wrong_output_phase": "REJECTED", + "missing_terminal_restoration": "REJECTED", "two_call_map": "PASS", + "joint_word_map": "PASS", "eager_map": "PASS"}, + "scope": "Exact for two identical calls on the same source X, the pinned PR1391 child family, and the stated order-four macro alphabet. No supplier admission or kappa claim." + } + return result + + +def main(): + result = build_result() + (HERE / "RESULT.json").write_text(json.dumps(result, indent=2, sort_keys=True) + "\n") + print("PASS_Z4_PERSISTENT_PAIR") + print("g5", result["five_child_control"]["total"], + "g10", result["ten_child_joint"]["boundary_total"], + "paths", result["ten_child_joint"]["exhaustive_paths"]) + print("two_calls", result["two_separate_calls"]["combined_primitives"], + "joint", result["ten_child_joint"]["complete_primitives"], + "saving", result["saving_joint_vs_separate"]["total_primitives"], + "vector", result["ten_child_joint"]["complete_vector_ADD_NEG"], + "basis_columns", result["basis_columns"], "negative_controls=3") + + +if __name__ == "__main__": + main()