diff --git a/research/rotation-row-rectangles/.gitattributes b/research/rotation-row-rectangles/.gitattributes new file mode 100644 index 0000000000..130a3ecaa2 --- /dev/null +++ b/research/rotation-row-rectangles/.gitattributes @@ -0,0 +1 @@ +retained/** -text whitespace=cr-at-eol diff --git a/research/rotation-row-rectangles/CREDITS.md b/research/rotation-row-rectangles/CREDITS.md new file mode 100644 index 0000000000..3efc2eba3b --- /dev/null +++ b/research/rotation-row-rectangles/CREDITS.md @@ -0,0 +1,35 @@ +# Credit and source boundaries + +Prepared by Ali Romman with substantial OpenAI Codex assistance in research, +implementation, verification and writing. New work is Apache-2.0. + +- Ali Romman's [PR #7734](https://github.com/CrocSwap/integer-mult-bounds/pull/7734) + supplied the [closed descent](https://github.com/aliromman/integer-mult-bounds/blob/57bb6efed1be1dda9eb1a0f622ec2773bc8b0047/research/rotation-switch-closed-descent/PROOF.md) + and [point query](https://github.com/aliromman/integer-mult-bounds/blob/57bb6efed1be1dda9eb1a0f622ec2773bc8b0047/research/rotation-switch-closed-descent/query.py). + Its proof, query and credit file are retained unchanged. +- Nick Petalas supplied the endpoint formulas and child recurrence in + [PR #7504](https://github.com/CrocSwap/integer-mult-bounds/pull/7504). + The [source proof](https://github.com/petalas/integer-mult-bounds/blob/7efb9a84277ec31abe2a934aeef8c8a70548aa5b/research/canonical-rotation-switch-query/PROOF.md) + is an inherited mathematical premise. The new rectangle description is + a consequence of those endpoints and the closed descent. +- Cinna Davis supplied the [canonical compiler](https://github.com/CrocSwap/integer-mult-bounds/blob/337d04939571a637aeab54a0f58f54fde811663a/research/unconditional-batched-crt/check_batched_crt.py) + in [PR #4100](https://github.com/CrocSwap/integer-mult-bounds/pull/4100). + It is retained unchanged as the finite table oracle, together with its + NOTICE. The proposed complete unconditional construction is not a premise. + +Related work has different contracts. Jerry Chen's +[PR #7593](https://github.com/CrocSwap/integer-mult-bounds/pull/7593) and +Ali Romman's [PR #7735](https://github.com/CrocSwap/integer-mult-bounds/pull/7735) +supply physical point queries. Nick Petalas's +[PR #6629](https://github.com/CrocSwap/integer-mult-bounds/pull/6629) changes +the routing choices to compact Waksman rows. His +[PR #4876](https://github.com/CrocSwap/integer-mult-bounds/pull/4876) gives a +minimum swap count for full dyadic rotations. This package keeps the exact +canonical padded table and does not claim those physical or global optima. + +The six retained files have source commits, Git blobs and SHA256 hashes +in `SOURCE-PINS.json`. `SOURCES.json` binds only the base catalogue and +selected record as provenance. No unmerged source ancestry is asserted. +The base license is retained. Source authors keep all credit in their notices. +The canonical table is a separate finite oracle; the point query shares the +proof's predecessor. These checks are not independent human review. diff --git a/research/rotation-row-rectangles/PROOF.md b/research/rotation-row-rectangles/PROOF.md new file mode 100644 index 0000000000..144b300003 --- /dev/null +++ b/research/rotation-row-rectangles/PROOF.md @@ -0,0 +1,186 @@ +# Three rectangles describe a canonical rotation row + +This is a row-description theorem and an arithmetic generation algorithm. +It uses the closed descent in Ali Romman's PR7734 and the canonical endpoint +formulas of Nick Petalas. Cinna Davis's canonical Beneš compiler defines the +table. Exact source files and credit are in [CREDITS.md](CREDITS.md) and +[SOURCE-PINS.json](SOURCE-PINS.json). The canonical routing choices do not change. + +## 1. Contract and result + +Let `h>=1`, `N=2^h`, `1<=s<=N`, `0<=a=D-u], +B = floor((s-a+D-1-t)/D) = q + [t=D-u`, the +possible pairs are `(p,q+1)`, `(p+1,q+1)`, and `(p+1,q)`; their qualifying +parities are `(odd,odd)`, `(even,odd)`, and `(even,even)`. Again, at most +one strip qualifies. Equal cuts and zero lengths only remove strips. + +At the center, `H=1`. The condition that both lengths are positive is + +```text +max(0,D-a) <= t < min(D,s-a). +``` + +It is one interval, possibly empty. The quotient interval is `[0,2)`. +Thus the center also needs at most one rectangle. For `h=1`, this is the +only row. + +## 4. The three-rectangle bound is sharp + +Take `(h,s,a,j)=(6,53,25,7)`, so `d=3` and `D=8`. Direct substitution gives + +| Remainder interval | Quotient interval | +|---|---| +| `[0,4)` | `[2,8)` | +| `[4,7)` | `[0,6)` | +| `[7,8)` | `[0,4)` | + +The one entries at `(t,y)=(0,6),(4,4),(7,0)` form a three-point fooling +set. A Cartesian rectangle that contains two points must contain both +cross points. For the three pairs, respectively, `(4,6)`, `(0,0)`, and +`(7,4)` are zero entries. Thus no all-one rectangle contains two witness +points. Every exact rectangle cover has at least three members. This +argument even allows arbitrary Cartesian subsets, not only intervals. + +The descriptor contains `4*6+3*6+1*4=46` active wire bits. The row has +23 active switches, since each switch has two paired wires. In general, +the active-bit count is the sum of the three rectangle areas, and the +active-switch count is half this sum. These are counts for the canonical +row. They are not minima over all routing networks or swap factorizations. + +## 5. Emit the row without a full-width query at each wire + +The output order is increasing `y`, then increasing `t`. Sort all quotient +endpoints together with `0` and `2^H`. At most seven nonempty phases result. +Within one phase the pattern over `t` is fixed. Sort all remainder endpoints +together with `0,D`. There are at most seven runs, including zero runs. +Evaluate the constant bit of each run once per phase. + +For a phase of `R` quotient values, repeat its run pattern `R` times. +Use canonical least-significant-bit-first countdowns for `R` and each run +length `L`. Zero is the empty list. A decrement of `n>0` visits +`v_2(n)+1` bits; if it clears the highest bit, remove that bit. Across a +complete countdown from `n` to zero, the exact number of visits is + +```text +sum_(k=1)^n (v_2(k)+1) = 2n-popcount(n) < 2n, n>0. +``` + +Return scans to the low end add only a constant factor. Empty-list tests +do not scan a fixed-width zero field. Retain one binary template for each +run length. Reset the inner counter by copying this template. For positive +`L`, its binary length is at most `L`. Thus all inner resets in one block +copy at most `D` bits. Across the whole row they copy at most `N` bits. + +There are `2^H<=N` outer decrements. Inner counters have exactly `N` +decrements. The sum of their bit visits is less than `4N`. Outer resets +copy at most `7(h+1)` bits. The at most seven phases, each with at most +seven run templates and one outer template, use at most `56(h+1)` template +bits in total. Phase preparation and interval comparisons cost `O(h)`. +Loop control is constant per run, block or output bit; each nonempty run +emits at least one bit. Total work is therefore `O(N+h)=O(N)`. + +Only a constant number of binary counters, templates and endpoints are +live. They need `O(h)` bits. The lower bound is `N` output writes for an +explicit `N`-bit row. This proves the stated `Theta(N)` bound. It is not +a lower bound for a compressed row or for a consumer that skips outputs. + +`row.py` supplies the descriptor and stream control. Its statistics count +counter visits, template bits, copies and outputs. Python object management +and statistics updates are not a literal machine-transition measurement. +The proof describes the bit algorithm; it does not assert that Python's +runtime has that bound under an arbitrary interpreter cost model. + +## 6. Verification and remaining boundary + +The finite oracle is the unchanged PR4100 deterministic compiler. The +verifier checks every row for every legal modulus and offset at heights +one through six: 2,793 networks, 28,797 rows and 1,633,182 wire entries. +It also compares the retained PR7734 point query, all streamed bits, +rectangle areas, switch pairing, first/center caps and the work inequalities. +The table digest agrees with the predecessor census. + +An additional 280 descriptors, with 4,937 boundary and random point checks, +reach height 65,536 without materializing large rows. There are 131,328 +individual countdown checks, fourteen input rejection checks, three +rectangle mutation controls and a coordinate-order mutation control. +The executable height cap bounds descriptor input size; the written proof +has no height cap. Wide tests are finite evidence, not its proof. + +A literal row producer still needs an ABI, scratch ownership, output +placement, head return and complete transition and historical-space bills. +Comparison with stored ROM requires the actual query/reuse workload and +transport, current-state offsets, payload use and retirement charges. +None is supplied by this descriptor theorem. All five selected framework +assumptions remain. No new kappa or full multiplication theorem is claimed. diff --git a/research/rotation-row-rectangles/README.md b/research/rotation-row-rectangles/README.md new file mode 100644 index 0000000000..ce9afc73a0 --- /dev/null +++ b/research/rotation-row-rectangles/README.md @@ -0,0 +1,69 @@ +# Canonical rotation rows have a sharp three-rectangle description + +Every canonical padded-rotation row is the union of at most three rectangles +in quotient/remainder wire coordinates. First and center rows need at most +one. A 64-wire example needs three, even for overlapping rectangle covers. +The descriptor uses O(h) bits and O(h) arithmetic bit work. It gives a stream +of the complete row in Theta(2^h) bit work and O(h) temporary bits. + +This is an enabling proof and arithmetic algorithm. No new kappa, literal +tape row producer, complete CRT caller or discharged framework assumption +is claimed. All five selected assumptions remain. The canonical routing +rule and current-wire table are unchanged. + +Read [PROOF.md](PROOF.md), [row.py](row.py), [RESULT.json](RESULT.json), +[SOURCE-PINS.json](SOURCE-PINS.json), and [CREDITS.md](CREDITS.md). +The exact finite census covers 2,793 networks, 28,797 rows and 1,633,182 +entries at heights one through six. Every entry matches the unchanged +canonical compiler, the retained point query and the stream. The checks +include rectangle counts, switch pairs, areas, work bounds, 280 wide +descriptors with 4,937 point checks, 131,328 counter decrements, fourteen +domain rejections and four semantic controls. The descriptor cap is 65,536; +large rows are not materialized. The written theorem covers every height. + +## Reproduce + +Use Python 3.12 and its standard library, from the repository root: + +```sh +python3.12 -B scripts/research_package.py --package research/rotation-row-rectangles +``` + +Both registered normal and optimized commands must print: + +```text +PASS_ROTATION_ROW_RECTANGLES sharp three-rectangle row and output-linear stream +``` + +The runner validates provenance through Git. The six retained source files +are authenticated directly by the verifier. An exported package can run +`python3.12 -W error -B research/rotation-row-rectangles/verify.py` without +Git or network access. No historical full suite, selected cold replay, +Lean, Docker, physical row execution or complete ROM workload ran. +Counters measure the stated bit algorithm, not Python runtime or literal +tape transitions. Finite tests and source retention are not formal proof +checking or independent human acceptance. + +## Selection and scope + +The base is e54523517d0f03e58352e647c403a5af3e525a57, priority revision 8. +The selected bindings pass; the catalogue assessment is older. TASK.json +records the changed compiler-interface scope under uniform-transfer-audit. +The parent handoff asks about whole-row generation and ROM reuse. This +result resolves the row-description and arithmetic-output part only. +Exact-source intake, live handoffs, open/closed bodies, a rotation/rectangle +search and relevant omitted main notes found no matching claim in their +coverage. The sparse local inventory and unpublished work remain limits. + +## Open next questions + +- Can a fixed tape program emit this row with a complete linear transition + bill and full private restoration? Start with one descriptor on the + existing point-query ABI. Output layout and ownership need explicit costs. +- When does a row descriptor beat a stored ROM for an actual CRT caller? + Bind the current offset producer and the caller's reuse order first. + Transport, payload use and retirement are still unpriced here. + +Ali Romman, with substantial OpenAI Codex assistance. Apache-2.0. The closed +formula, endpoint rules and canonical compiler retain their predecessor +credit in CREDITS.md and the unchanged source notices. diff --git a/research/rotation-row-rectangles/RESULT.json b/research/rotation-row-rectangles/RESULT.json new file mode 100644 index 0000000000..fd71adb586 --- /dev/null +++ b/research/rotation-row-rectangles/RESULT.json @@ -0,0 +1,126 @@ +{ + "canonical_entries": 1633182, + "center_rows": 2793, + "closed_entries": 1633182, + "counter_decrements": 131328, + "counter_starts": 513, + "domain_rejections": 14, + "first_rows": 13002, + "maximum_height": 65536, + "networks": 2793, + "rectangle_histogram": { + "0": 10407, + "1": 14562, + "2": 3558, + "3": 270 + }, + "rows": 28797, + "scope": "Three rectangles per canonical row and optimal output bit work; no physical row producer or kappa", + "semantic_mutants": { + "lost rectangle": { + "expected": 1, + "mutant": 0, + "query": [ + 1, + 2, + 1, + 0, + 0 + ] + }, + "lost remainder boundary": { + "expected": 1, + "mutant": 0, + "query": [ + 1, + 2, + 1, + 0, + 0 + ] + }, + "short quotient interval": { + "expected": 1, + "mutant": 0, + "query": [ + 1, + 2, + 1, + 0, + 1 + ] + } + }, + "sharpness": { + "active_bits": 46, + "active_switches": 23, + "cross_zeros": [ + [ + 4, + 6 + ], + [ + 0, + 0 + ], + [ + 7, + 4 + ] + ], + "one_points": [ + [ + 0, + 6 + ], + [ + 4, + 4 + ], + [ + 7, + 0 + ] + ], + "parameters": [ + 6, + 53, + 25, + 7 + ], + "rectangles": [ + [ + 0, + 4, + 2, + 8 + ], + [ + 4, + 7, + 0, + 6 + ], + [ + 7, + 8, + 0, + 4 + ] + ] + }, + "stream_order_mutant_rejected": true, + "stream_work": { + "blocks": 593346, + "counter_bit_visits": 3498070, + "counter_bits_copied": 1368581, + "emitted_bits": 1633182, + "phases": 50748, + "template_bits": 357245 + }, + "streamed_entries": 1633182, + "switch_pairs": 816591, + "table_sha256": "a03bef31f1c4d89ada71e74120ba6cf3ce329153abcb6b38860242d7d95f1863", + "wide_descriptors": 280, + "wide_queries": 4937 +} diff --git a/research/rotation-row-rectangles/SOURCE-PINS.json b/research/rotation-row-rectangles/SOURCE-PINS.json new file mode 100644 index 0000000000..47f0388d36 --- /dev/null +++ b/research/rotation-row-rectangles/SOURCE-PINS.json @@ -0,0 +1,50 @@ +[ + { + "path": "retained/pr7734/query.py", + "source_repository": "aliromman/integer-mult-bounds", + "source_commit": "57bb6efed1be1dda9eb1a0f622ec2773bc8b0047", + "source_path": "research/rotation-switch-closed-descent/query.py", + "git_blob": "5d5aa278a67f9a69c5d080a2781b68d5c0d953ef", + "sha256": "cee90bb9255113d0180f69d68ba8b4f45f8a3f104c33029ce7bcb247f285cea2" + }, + { + "path": "retained/pr7734/PROOF.md", + "source_repository": "aliromman/integer-mult-bounds", + "source_commit": "57bb6efed1be1dda9eb1a0f622ec2773bc8b0047", + "source_path": "research/rotation-switch-closed-descent/PROOF.md", + "git_blob": "65f3702b100b57e1bc178dbbc9478732c783fc37", + "sha256": "8103406c30f14631289fab4d6227da1c691851eac01ee4ed2991722d233e28f7" + }, + { + "path": "retained/pr7734/CREDITS.md", + "source_repository": "aliromman/integer-mult-bounds", + "source_commit": "57bb6efed1be1dda9eb1a0f622ec2773bc8b0047", + "source_path": "research/rotation-switch-closed-descent/CREDITS.md", + "git_blob": "939b2827ff073a68e8505656c401df6cccd21f75", + "sha256": "7fda78a59b54ab7ecb2ff9dee9a161cc6a7d20a779a29cc5bfd664dd7b4cecb2" + }, + { + "path": "retained/pr4100/check_batched_crt.py", + "source_repository": "CrocSwap/integer-mult-bounds", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "source_path": "research/unconditional-batched-crt/check_batched_crt.py", + "git_blob": "1cf78abccd5e06beecc3ed21ba55f7c03b65fdbc", + "sha256": "681e2e3d71fa74c8b9b326f3860104fd9d89590a222e26ae6ee718d1fd40ff2e" + }, + { + "path": "retained/pr4100/NOTICE.md", + "source_repository": "CrocSwap/integer-mult-bounds", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "source_path": "research/unconditional-batched-crt/NOTICE.md", + "git_blob": "886a8fdee275f01b459cbd68ae2815dc9269502f", + "sha256": "924109837e71c52392191710d49c9deb42780878d1094f0b01e8690dbe799461" + }, + { + "path": "retained/base/LICENSE", + "source_repository": "CrocSwap/integer-mult-bounds", + "source_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "source_path": "LICENSE", + "git_blob": "261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64", + "sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4" + } +] diff --git a/research/rotation-row-rectangles/SOURCES.json b/research/rotation-row-rectangles/SOURCES.json new file mode 100644 index 0000000000..5335fa97d9 --- /dev/null +++ b/research/rotation-row-rectangles/SOURCES.json @@ -0,0 +1,18 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + } + ] +} diff --git a/research/rotation-row-rectangles/TASK.json b/research/rotation-row-rectangles/TASK.json new file mode 100644 index 0000000000..2db425ad39 --- /dev/null +++ b/research/rotation-row-rectangles/TASK.json @@ -0,0 +1,89 @@ +{ + "schema_version": 1, + "task_id": "uniform-transfer-audit", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "uniform-transfer-audit", + "question": "Can one of the selected record's five inherited assumptions be proved at its actual caller?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "Identify the proposition and what would change downstream; do not equate a finite replay with a universal proof.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Choose one assumption ID (native_all_columns, owned_erasure, compiler, precision_tape, analytic_recovery), one quantified implication and exact dependency closure. Check current handoffs, including #5625 row reentry and #5707 root-prefix lowering, without treating their partial scope as the whole theorem. Prove or falsify that implication with a caller-bound argument; stop at the chosen obligation. Finite tests or root digits do not discharge an all-size statement.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "native_all_columns", + "owned_erasure", + "compiler", + "precision_tape", + "analytic_recovery" + ], + "existing_checks": [ + { + "scope": "PR #4100: proposed unconditional construction and finite checks, without independent acceptance.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Independent proof audit of one caller-bound all-size implication; all other premises remain explicit.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Prove a sharp three-rectangle description of each unchanged canonical padded-rotation row and an output-linear arithmetic stream.", + "scope_change_reason": "The parent query handoff leaves whole-row generation and ROM reuse open. This resolves a compiler-interface lemma, not the full selected assumption.", + "bottleneck_link": "An O(h)-bit row descriptor removes the need for N separate width-h point queries when an entire canonical row is required. The physical producer and full caller bill remain open.", + "budget_minutes": 60, + "stop_rule": "Stop at the exact row theorem, sharp example and output-work proof; do not infer a physical caller or new kappa.", + "outcome": "completed", + "evidence": "PROOF.md and RESULT.json; complete small canonical rows, wide boundary checks, exact counter laws and semantic/domain controls.", + "author": "Ali Romman", + "ai_assistance": "Substantial OpenAI Codex assistance in research, implementation, verification and writing.", + "open_questions": [ + { + "question": "Can a fixed tape program emit a complete canonical row in O(2^h+h) transitions with full restoration?", + "why_it_matters": "The arithmetic descriptor alone does not provide a literal producer.", + "first_step": "Bind the row output layout and private ownership on the existing point-query ABI.", + "blocked_by": "A complete transition and historical-space bill with output lifecycle." + }, + { + "question": "When does the descriptor beat stored ROM at an actual CRT caller?", + "why_it_matters": "The reuse workload determines whether row generation replaces paid work.", + "first_step": "Pin the current offset producer and query order before comparison.", + "blocked_by": "Transport, payload use and retirement costs." + } + ] +} diff --git a/research/rotation-row-rectangles/VERIFY.json b/research/rotation-row-rectangles/VERIFY.json new file mode 100644 index 0000000000..c4086906ec --- /dev/null +++ b/research/rotation-row-rectangles/VERIFY.json @@ -0,0 +1,32 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact canonical rows, sharp rectangle cover, stream order and amortized counters, wide boundary queries, source hashes and semantic/domain controls" + }, + { + "argv": [ + "{python}", + "-W", + "error", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact canonical rows, sharp rectangle cover, stream order and amortized counters, wide boundary queries, source hashes and semantic/domain controls" + } + ] +} diff --git a/research/rotation-row-rectangles/retained/base/LICENSE b/research/rotation-row-rectangles/retained/base/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/research/rotation-row-rectangles/retained/base/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/rotation-row-rectangles/retained/pr4100/NOTICE.md b/research/rotation-row-rectangles/retained/pr4100/NOTICE.md new file mode 100644 index 0000000000..886a8fdee2 --- /dev/null +++ b/research/rotation-row-rectangles/retained/pr4100/NOTICE.md @@ -0,0 +1,38 @@ +# Attribution and source boundaries + +New construction and audit: Cinna Davis, with substantial OpenAI Codex +assistance. Apache-2.0. No independent human or new formal-kernel review +is claimed. SOURCES.json and EXPORTED-SOURCES.json retain exact identities. +Source-specific notices are unchanged. + +- Douglas Colkitt and OpenAI's framework: stream algorithms, compact controls, + ordinary interchange, row-volume and tape contracts. +- Jose Manuel (jmbarrancoml), selected recursive/physical BIT and complex + closure packages: class-indexed callers, ring descriptors, fixed-state + compilation, common-grid precision and source integration. +- DreamingOfClouds, eumemic, Dugongue, Rohan Arun, alephnan and the retained + PR589/PR1627 lineage: the finite BIT word and chronological hosting. +- commdata2338, Ross Richardson and source527 contributors: normal forms, + fallback covariance, weighted leaves and recursive parking. +- PR2915's selected fast-primitive work: replacing both the weighted leaf + and the reached owner-header sites with a completed previous stage. +- Vlado Vojdanovski, PR1673 and its credited contributors: capped Gaussian + cells, finite LDU, shallow Toeplitz circuits, tensor compilation, support + routing, sparse layouts and conditioning audits. +- Chafik Boukhalfa, PR1758/1786: shifted Gaussian accretivity, per-visit + union scheduling, fine prime intervals and separate setup precision. +- PR4088 and its NOTICE retain the mixed-provider lineage, including Rohan + Arun, David Ganz/Dugongue, Nick Petalas, Ross Richardson, dataisfire, + Erwan Secousses, Sagar Thakrar, roger-sato, Marius-Paul Dumitrean and the + native compiler/geometry contributors. +- Tekalign, Ali Romman, Charles Bethin and the native source notices: + exact native replay and sparse Clifford-state evaluation. +- Tim Trudgian: the explicit unconditional prime-counting estimate. +- David Harvey and Joris van der Hoeven: the established O(N log N) + multiplier used on the shorter numerical records. + +This package contributes batched nonlinear CRT and its enlarged-guard cost; +independent full-ring normal-form and fallback derivations; the retuned BIT +assembly; the mixed-provider free-algebra lift with external spectators; +conservative position-dependent halos; cached chirps; and the proposed outer +composition. The predecessor words, identities and compilers retain their credit. diff --git a/research/rotation-row-rectangles/retained/pr4100/check_batched_crt.py b/research/rotation-row-rectangles/retained/pr4100/check_batched_crt.py new file mode 100644 index 0000000000..1cf78abccd --- /dev/null +++ b/research/rotation-row-rectangles/retained/pr4100/check_batched_crt.py @@ -0,0 +1,265 @@ +"""Exact finite controls for the draft; not a machine-cost certificate.""" +import itertools +import json +import math + + +def need(condition, message): + if not condition: + raise ValueError(message) + + +def benes(permutation): + """Return (bit, switch table) layers on precisely len(permutation) wires.""" + size = len(permutation) + need(size >= 2 and size & (size - 1) == 0, "dyadic network size") + need(sorted(permutation) == list(range(size)), "permutation") + if size == 2: + return [(0, (permutation[0],) * 2)] + inverse = [0] * size + for x, y in enumerate(permutation): + inverse[y] = x + color = [-1] * size + for initial in range(size): + if color[initial] >= 0: + continue + color[initial] = 0 + stack = [initial] + while stack: + x = stack.pop() + for other in (x ^ 1, inverse[permutation[x] ^ 1]): + if color[other] < 0: + color[other] = color[x] ^ 1 + stack.append(other) + need(color[other] == color[x] ^ 1, "even cycle coloring") + first = tuple(color[x] ^ (x & 1) for x in range(size)) + last = tuple(color[inverse[y]] ^ (y & 1) for y in range(size)) + children = [] + for c in (0, 1): + child = [None] * (size // 2) + for x in range(size): + if color[x] == c: + child[x // 2] = permutation[x] // 2 + children.append(benes(child)) + result = [(0, first)] + for left, right in zip(*children): + need(left[0] == right[0], "common network schedule") + table = tuple((left, right)[x & 1][1][x // 2] for x in range(size)) + result.append((left[0] + 1, table)) + result.append((0, last)) + return result + + +def run_network(layers, value): + for bit, table in layers: + value ^= table[value] << bit + return value + + +def rotation(size, modulus, offset): + return tuple((x + offset) % modulus if x < modulus else x for x in range(size)) + + +def decode_group(values, moduli): + """Recover the integer from locally scaled CRT residues.""" + product = math.prod(moduli) + answer = 0 + prefix = 1 + for value, modulus in zip(values, moduli): + complement = product // modulus + residue = value * prefix % modulus + answer += residue * complement * pow(complement, -1, modulus) + prefix *= modulus + return answer % product + + +def balanced(values, moduli, reverse=False, compiled=False): + count = len(moduli) + need(count > 0 and count & (count - 1) == 0, "power-of-two axis count") + state = list(values) + levels = list(range(1, count.bit_length())) + for level in reversed(levels) if reverse else levels: + width = 1 << level + half = width // 2 + for start in range(0, count, width): + middle = start + half + valid = all(state[i] < moduli[i] for i in range(start, middle)) + lower = decode_group(state[start:middle], moduli[start:middle]) if valid else 0 + prefix = math.prod(moduli[start:middle]) + for i in range(middle, start + width): + offset = lower * pow(prefix, -1, moduli[i]) % moduli[i] + if reverse: + offset = -offset % moduli[i] + if compiled: + size = 1 << (moduli[i] - 1).bit_length() + state[i] = run_network(benes(rotation(size, moduli[i], offset)), state[i]) + elif state[i] < moduli[i]: + state[i] = (state[i] + offset) % moduli[i] + prefix *= moduli[i] + return tuple(state) + + +def direct(values, moduli): + prefix = 1 + integer = 0 + prefixes = [] + for value, modulus in zip(values, moduli): + prefixes.append(prefix) + integer += value * prefix + prefix *= modulus + return tuple(integer * pow(prefix, -1, modulus) % modulus + for prefix, modulus in zip(prefixes, moduli)) + + +def primitive_f(u, t, y, bits, positions, ybits, control_bits): + radix = 1 << bits + control_mask = (1 << control_bits) - 1 + ymask = (1 << ybits) - 1 + z = [(u >> (bits * i)) & 1 for i in range(len(positions))] + digits = [(t >> (bits * i)) & (radix - 1) for i in range(len(positions))] + y = (y + sum(2 * bit * digit * (1 << pos) + for bit, digit, pos in zip(z, digits, positions))) & ymask + t = (t + sum(((y >> pos) & 1) << (bits * i) + for i, pos in enumerate(positions))) & control_mask + digits = [(t >> (bits * i)) & (radix - 1) for i in range(len(positions))] + y = (y + sum(bit * (1 - 2 * digit) * (1 << pos) + for bit, digit, pos in zip(z, digits, positions))) & ymask + t = (t - sum((((y >> pos) & 1) ^ z[i]) << (bits * i) + for i, pos in enumerate(positions))) & control_mask + return u, t, y + + +def compact(u, t, y, source, bits=2, positions=(0,), ybits=6, control_bits=2): + need(control_bits >= bits * len(positions), "control field capacity") + mask = (1 << control_bits) - 1 + u, t, y = primitive_f(u, t, y, bits, positions, ybits, control_bits) + u = (u + sum(value << (bits * i) for i, value in enumerate(source(y)))) & mask + u, t, y = primitive_f(u, t, y, bits, positions, ybits, control_bits) + u = (u - sum(value << (bits * i) for i, value in enumerate(source(y)))) & mask + return u, t, y + + +def good(u, t, y, bits=2, positions=(0,), guard=6): + radix = 1 << bits + return all(((u >> (bits * i)) & (radix - 1)) != radix - 1 + and ((t >> (bits * i)) & (radix - 1)) != radix - 1 + and 2 * radix <= ((y >> (pos + 1)) & ((1 << (guard - 1)) - 1)) + < (1 << (guard - 1)) - 2 * radix + for i, pos in enumerate(positions)) + + +def linear_guard(u, t, y, bits=2, positions=(0,), guard=6, + control_bits=2, ybits=6): + """Bit-by-bit guard predicate; source functions are never evaluated.""" + steps = 0 + accepted = True + for word in (u, t): + for digit in range(len(positions)): + all_ones = True + for bit in range(bits): + all_ones = all_ones and bool((word >> (digit * bits + bit)) & 1) + steps += 1 + accepted = accepted and not all_ones + for pos in positions: + lower = 2 * (1 << bits) + upper = (1 << (guard - 1)) - lower + comparison = [0, 0] + for bit in range(guard - 2, -1, -1): + value = (y >> (pos + 1 + bit)) & 1 + for index, bound in enumerate((lower, upper)): + if comparison[index] == 0: + comparison[index] = value - ((bound >> bit) & 1) + steps += 2 + accepted = accepted and comparison[0] >= 0 and comparison[1] < 0 + need(steps <= 2 * control_bits + 2 * ybits, "linear tested-bit budget") + return accepted + + +def check(): + network_count = address_count = 0 + for bits in range(1, 7): + size = 1 << bits + for modulus in range(max(2, size // 2), size): + for offset in range(modulus): + permutation = rotation(size, modulus, offset) + layers = benes(permutation) + need(len(layers) == 2 * bits - 1, "network depth") + for bit, table in layers: + need(all(table[x] == table[x ^ (1 << bit)] for x in range(size)), + "switch control omits its target bit") + need(tuple(run_network(layers, x) for x in range(size)) == permutation, + "all-column modular rotation") + network_count += 1 + address_count += size + crt_addresses = valid_addresses = 0 + for moduli in ((3,), (3, 5), (3, 5, 7, 11)): + sizes = [1 << (s - 1).bit_length() for s in moduli] + seen = set() + for source in itertools.product(*(range(size) for size in sizes)): + target = balanced(source, moduli) + need(target not in seen, "padded CRT injection") + seen.add(target) + need(balanced(target, moduli, reverse=True) == source, "padded CRT inverse") + valid = all(x < s for x, s in zip(source, moduli)) + need(valid == all(x < s for x, s in zip(target, moduli)), "padding invariance") + if valid: + need(target == direct(source, moduli), "scaled CRT endpoint") + valid_addresses += 1 + need(balanced(source, moduli, compiled=True) == target, "compiled CRT endpoint") + crt_addresses += 1 + compact_cases = good_cases = repair_cases = 0 + functions = [lambda y: (0,), lambda y: (1,), lambda y: ((y >> 2) & 1,), + lambda y: ((y >> 1).bit_count() & 1,), + lambda y: ((((y >> 1) & 1) & ((y >> 4) & 1)),)] + for source_function, control_bits in itertools.product(functions, (2, 4)): + actual = {} + ideal = {} + for u, t, y in itertools.product(range(1 << control_bits), + range(1 << control_bits), range(64)): + start = (u, t, y) + end = compact(*start, source_function, control_bits=control_bits) + wanted = (u, t, y ^ source_function(y)[0]) + need(end not in actual, "actual gadget bijection") + need(wanted not in ideal, "ideal switch bijection") + actual[end] = start + ideal[wanted] = start + is_good = good(*start) + need(linear_guard(*start, control_bits=control_bits) == is_good, + "linear guard agrees with interval predicate") + need(good(*end) == is_good and good(*wanted) == is_good, "good/bad invariance") + if is_good: + need(end == wanted, "compact endpoint on good addresses") + good_cases += 1 + compact_cases += 1 + # Each arbitrary dirty input column follows S, then T S^-1 on bad holes. + for end, start in actual.items(): + u, t, y = start + repaired = (u, t, y ^ source_function(y)[0]) if not good(*end) else end + need(ideal[repaired] == start, "sparse correction column") + repair_cases += not good(*end) + multi_cases = 0 + def source_pair(y): + return (y >> 3) & 1, (y & ~65).bit_count() & 1 + for u, t in ((0, 0), (0, 15), (5, 5), (10, 10), (15, 0), (15, 15)): + for y in range(1 << 12): + start = (u, t, y) + end = compact(*start, source_pair, positions=(0, 6), ybits=12, control_bits=4) + f0, f1 = source_pair(y) + wanted = (u, t, y ^ f0 ^ (f1 << 6)) + is_good = good(*start, positions=(0, 6)) + need(linear_guard(*start, positions=(0, 6), control_bits=4, ybits=12) == is_good, + "two-target linear guard") + need(good(*end, positions=(0, 6)) == is_good, "two-target guard invariance") + if is_good: + need(end == wanted, "two-target compact endpoint") + multi_cases += 1 + return dict(status="PASS_FINITE_BATCHED_CRT_CONTROLS", network_count=network_count, + network_addresses=address_count, crt_addresses=crt_addresses, + valid_crt_addresses=valid_addresses, compact_addresses=compact_cases, + good_addresses=good_cases, repaired_bad_addresses=repair_cases, + two_target_addresses=multi_cases, linear_guard_verified=True, + machine_cost_verified=False, multiplication_kappa_claimed=False) + + +if __name__ == "__main__": + print(json.dumps(check(), sort_keys=True, indent=2)) diff --git a/research/rotation-row-rectangles/retained/pr7734/CREDITS.md b/research/rotation-row-rectangles/retained/pr7734/CREDITS.md new file mode 100644 index 0000000000..939b2827ff --- /dev/null +++ b/research/rotation-row-rectangles/retained/pr7734/CREDITS.md @@ -0,0 +1,30 @@ +# Credit and exact sources + +Prepared by Ali Romman with substantial OpenAI Codex assistance in research, +implementation, verification and writing. New work is Apache-2.0. + +- Nick Petalas supplied the canonical endpoint formulas and child recurrence + in [PR #7504](https://github.com/CrocSwap/integer-mult-bounds/pull/7504). + The [source proof](https://github.com/petalas/integer-mult-bounds/blob/7efb9a84277ec31abe2a934aeef8c8a70548aa5b/research/canonical-rotation-switch-query/PROOF.md) + and [query](https://github.com/petalas/integer-mult-bounds/blob/7efb9a84277ec31abe2a934aeef8c8a70548aa5b/research/canonical-rotation-switch-query/rotation_query.py) + are retained unchanged. The source README retains its related-work credit. +- Cinna Davis supplied the deterministic compiler in + [PR #4100](https://github.com/CrocSwap/integer-mult-bounds/pull/4100). + The [canonical source](https://github.com/CrocSwap/integer-mult-bounds/blob/337d04939571a637aeab54a0f58f54fde811663a/research/unconditional-batched-crt/check_batched_crt.py) + is called unchanged for finite table comparisons. Its NOTICE is retained. + The full unconditional construction is not an accepted premise here. +- Jerry Chen supplied the fourteen-tape implementation in + [PR #7593](https://github.com/CrocSwap/integer-mult-bounds/pull/7593), + head `56335a406469fad85e88ff72820d506d8bea6f63`. It is related physical + work, not a consumed executable or a claimed automatic speedup. + +The new contribution is the two-length closed descent, direct query and +matching bit-probe lower bound. The endpoint formulas retain their source +credit. The canonical compiler is a separate finite oracle; the recurrence +comparison shares the mathematical predecessor. Neither is an independent +human review. + +`SOURCE-PINS.json` binds six retained files byte for byte. `SOURCES.json` +binds the base catalogue and selected record as provenance. No unmerged +source ancestry is asserted. The base license is retained. All predecessor +authors named in the retained notices keep their credit. diff --git a/research/rotation-row-rectangles/retained/pr7734/PROOF.md b/research/rotation-row-rectangles/retained/pr7734/PROOF.md new file mode 100644 index 0000000000..65f3702b10 --- /dev/null +++ b/research/rotation-row-rectangles/retained/pr7734/PROOF.md @@ -0,0 +1,158 @@ +# A closed formula for canonical rotation switch queries + +This proof changes the arithmetic query in Nick Petalas's +[PR #7504](https://github.com/CrocSwap/integer-mult-bounds/pull/7504). +Its endpoint formulas and child-closure theorem are cited premises, retained +with exact bytes in `retained/pr7504/PROOF.md`. The new result is a closed +descent formula, a linear bit-cost query, and a matching worst-case lower +bound. No new kappa or complete compiler follows. + +## 1. Contract + +Let `h>=1`, `N=2^h`, `1<=s<=N`, and `0<=a0` as a nonidentity +child gives a wrong central switch already at `(h,s,a,j,x)=(2,2,1,1,1)`. + +## 3. Collapse any number of child steps + +The child branches of a table query are the low bits of its current wire: +`c_i=(x>>i) mod 2`. For any depth `0<=d>d`. After exactly `d` +interior descents, the requested row is an endpoint of height `H`. +The query uses the pair in Section 3 once. If either length is zero, +return zero. If `H=1`, both positive integer lengths must be one; return +one. Otherwise set `S=A_d+B_d` and `A=A_d`. + +For the first endpoint, when `j=d`, return + +```text +[S and A are odd] [floor(y/2)=floor(S/2)]. +``` + +For the last endpoint, return + +```text +[A is odd] [y=2`, `s=2^h-1`, `j=2h-2`, and `x=0`. With an `h`-bit offset field, +the all-zero offset returns zero. Changing any one offset bit `k` with +`1<=k=3`, +fix `x=a=2^(h-1)`, the same odd `s` and last row. The baseline answer is +zero. Changing any offset bit `1<=k> depth, + (modulus - offset + mask - tail) >> depth) + + +def endpoint(left, right, address, height, last): + """Evaluate the endpoint, including every identity child.""" + if left == 0 or right == 0: + return 0 + if height == 1: + return 1 + modulus = left + right + if not last: + return int((modulus & left & 1) and address // 2 == modulus // 2) + if modulus % 2 == 0: + return int(left % 2 == 1 and address < modulus) + if left % 2 == 0: + return int(address < left) + return int(left - 1 <= address <= modulus) + + +def switch_bit(height, modulus, offset, layer, address): + """Return the source's current-wire table bit with O(height) bit work.""" + require(all(type(v) is int for v in (height, modulus, offset, layer, address)), + "integer parameters") + require(1 <= height <= MAX_HEIGHT, "height outside the executable limit") + require(1 <= modulus <= 1 << height, "modulus outside the address domain") + require(0 <= offset < modulus, "offset outside the canonical interval") + require(0 <= layer < 2 * height - 1, "layer outside the network") + require(0 <= address < 1 << height, "address outside the network") + depth = min(layer, 2 * height - 2 - layer) + left, right = interval_pair(modulus, offset, depth, address) + return endpoint(left, right, address >> depth, height - depth, layer != depth) diff --git a/research/rotation-row-rectangles/row.py b/research/rotation-row-rectangles/row.py new file mode 100644 index 0000000000..11cf4ada09 --- /dev/null +++ b/research/rotation-row-rectangles/row.py @@ -0,0 +1,129 @@ +"""Describe and emit a canonical padded-rotation row. + +Prepared by Ali Romman with substantial OpenAI Codex assistance. Apache-2.0. +The descriptor uses the closed descent from PR7734 and Petalas's endpoints. +""" + +from dataclasses import dataclass + +MAX_HEIGHT = 65536 + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +@dataclass(frozen=True) +class Row: + height: int + depth: int + rectangles: tuple + + def bit(self, address): + require(type(address) is int and 0 <= address < 1 << self.height, + "address outside the row") + y, t = divmod(address, 1 << self.depth) + return int(any(t0 <= t < t1 and y0 <= y < y1 + for t0, t1, y0, y1 in self.rectangles)) + + def ones(self): + return sum((t1 - t0) * (y1 - y0) + for t0, t1, y0, y1 in self.rectangles) + + +def describe(height, modulus, offset, layer): + require(all(type(v) is int for v in (height, modulus, offset, layer)), + "integer parameters") + require(1 <= height <= MAX_HEIGHT, "height outside the executable limit") + require(1 <= modulus <= 1 << height, "modulus outside the address domain") + require(0 <= offset < modulus, "offset outside the canonical interval") + require(0 <= layer < 2 * height - 1, "layer outside the network") + depth = min(layer, 2 * height - 2 - layer) + period = 1 << depth + quotient_a, remainder_a = divmod(offset, period) + quotient_b, remainder_b = divmod(modulus - offset, period) + cuts = sorted({0, period, period - remainder_a, remainder_b}) + rectangles = [] + for t0, t1 in zip(cuts, cuts[1:]): + left = quotient_a + (t0 >= period - remainder_a) + right = quotient_b + (t0 < remainder_b) + if not left or not right: + continue + total = left + right + if height - depth == 1: + y0, y1 = 0, 2 + elif layer == depth: + if total % 2 == 0 or left % 2 == 0: + continue + y0, y1 = total - 1, total + 1 + elif total % 2 == 0: + if left % 2 == 0: + continue + y0, y1 = 0, total + elif left % 2 == 0: + y0, y1 = 0, left + else: + y0, y1 = left - 1, total + 1 + if rectangles and rectangles[-1][1] == t0 and rectangles[-1][2:] == (y0, y1): + previous = rectangles.pop() + rectangles.append((previous[0], t1, y0, y1)) + else: + rectangles.append((t0, t1, y0, y1)) + return Row(height, depth, tuple(rectangles)) + + +def binary_template(value, stats): + bits = tuple(int(c) for c in reversed(format(value, "b"))) if value else () + stats["template_bits"] += len(bits) + return bits + + +class Countdown: + """Use an empty list for zero and remove the highest zero after a borrow.""" + + def __init__(self, template, stats): + self.bits = list(template) + self.stats = stats + stats["counter_bits_copied"] += len(template) + + def take(self): + if not self.bits: + return False + index = 0 + while self.bits[index] == 0: + self.bits[index] = 1 + self.stats["counter_bit_visits"] += 1 + index += 1 + self.bits[index] = 0 + self.stats["counter_bit_visits"] += 1 + if index == len(self.bits) - 1: + self.bits.pop() + return True + + +def stream(row, stats): + """Emit current-wire order with amortized constant counter work per bit. + + The counters model bit work. Python instrumentation is not a tape bill. + """ + stats.update(template_bits=0, counter_bits_copied=0, + counter_bit_visits=0, emitted_bits=0, blocks=0, phases=0) + period = 1 << row.depth + height = 1 << (row.height - row.depth) + y_cuts = sorted({0, height, *(y for rect in row.rectangles for y in rect[2:])}) + t_cuts = sorted({0, period, *(t for rect in row.rectangles for t in rect[:2])}) + for y0, y1 in zip(y_cuts, y_cuts[1:]): + stats["phases"] += 1 + outer = Countdown(binary_template(y1 - y0, stats), stats) + runs = [(binary_template(t1 - t0, stats), + int(any(a <= t0 < b and c <= y0 < d + for a, b, c, d in row.rectangles))) + for t0, t1 in zip(t_cuts, t_cuts[1:])] + while outer.take(): + stats["blocks"] += 1 + for template, bit in runs: + inner = Countdown(template, stats) + while inner.take(): + stats["emitted_bits"] += 1 + yield bit diff --git a/research/rotation-row-rectangles/verify.py b/research/rotation-row-rectangles/verify.py new file mode 100644 index 0000000000..0918050764 --- /dev/null +++ b/research/rotation-row-rectangles/verify.py @@ -0,0 +1,218 @@ +"""Check row descriptors against the retained canonical routing compiler. + +Prepared by Ali Romman with substantial OpenAI Codex assistance. Apache-2.0. +""" + +import argparse +import hashlib +import importlib.util +import json +from pathlib import Path +import random + +from row import MAX_HEIGHT, Countdown, Row, binary_template, describe, require, stream + +PACKAGE = Path(__file__).resolve().parent + + +def load_sources(): + for pin in json.loads((PACKAGE / "SOURCE-PINS.json").read_text()): + require(hashlib.sha256((PACKAGE / pin["path"]).read_bytes()).hexdigest() + == pin["sha256"], "retained source hash") + modules = [] + for name, path in (("canonical", "retained/pr4100/check_batched_crt.py"), + ("closed", "retained/pr7734/query.py")): + spec = importlib.util.spec_from_file_location(name, PACKAGE / path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + modules.append(module) + return modules + + +def inspect_row(row): + require(len(row.rectangles) <= 3, "rectangle cap") + previous = 0 + for t0, t1, y0, y1 in row.rectangles: + require(previous <= t0 < t1 <= 1 << row.depth, "disjoint remainder strips") + require(0 <= y0 < y1 <= 1 << (row.height - row.depth), "quotient bounds") + require(y0 % 2 == y1 % 2 == 0, "switch-pair endpoints") + previous = t1 + + +def census(canonical, closed): + result = dict(networks=0, rows=0, canonical_entries=0, closed_entries=0, + streamed_entries=0, switch_pairs=0, first_rows=0, center_rows=0) + histogram = {str(k): 0 for k in range(4)} + digest = hashlib.sha256() + total_stats = dict(template_bits=0, counter_bits_copied=0, + counter_bit_visits=0, emitted_bits=0, blocks=0, phases=0) + mutants = {} + for h in range(1, 7): + size = 1 << h + for s in range(1, size + 1): + for a in range(s): + layers = canonical.benes(canonical.rotation(size, s, a)) + result["networks"] += 1 + for j, (axis, expected) in enumerate(layers): + row = describe(h, s, a, j) + inspect_row(row) + require(axis == row.depth, "canonical row axis") + if j < h - 1: + require(len(row.rectangles) <= 1, "first row cap") + result["first_rows"] += 1 + if j == h - 1: + require(len(row.rectangles) <= 1, "center row cap") + result["center_rows"] += 1 + bits = [row.bit(x) for x in range(size)] + require(bits == list(expected), "canonical row mismatch") + require(bits == [closed.switch_bit(h, s, a, j, x) for x in range(size)], + "closed point mismatch") + stats = {} + require(list(stream(row, stats)) == bits, "stream order or value") + require(stats["counter_bit_visits"] < 4 * size, "counter work") + require(stats["counter_bits_copied"] <= size + 7 * (h + 1), "counter copies") + require(stats["template_bits"] <= 56 * (h + 1), "template work") + require(stats["emitted_bits"] == size and stats["phases"] <= 7, + "stream output size") + for key, value in stats.items(): + total_stats[key] += value + require(row.ones() == sum(expected), "rectangle areas") + for x in range(size): + require(bits[x] == bits[x ^ (1 << axis)], "paired switch bits") + result["switch_pairs"] += size // 2 + histogram[str(len(row.rectangles))] += 1 + result["rows"] += 1 + for key in ("canonical_entries", "closed_entries", "streamed_entries"): + result[key] += size + digest.update(bytes(bits)) + if row.rectangles: + rects = row.rectangles + t0, t1, y0, y1 = rects[0] + candidates = { + "lost rectangle": rects[1:], + "short quotient interval": ((t0, t1, y0, y1 - 1),) + rects[1:], + "lost remainder boundary": ((t0 + 1, t1, y0, y1),) + rects[1:], + } + for name, changed in candidates.items(): + if name not in mutants: + mutant = Row(h, row.depth, changed) + witness = next((x for x in range(size) if mutant.bit(x) != bits[x]), None) + if witness is not None: + mutants[name] = dict(query=[h, s, a, j, witness], expected=bits[witness], + mutant=mutant.bit(witness)) + require(len(mutants) == 3, "undetected rectangle mutation") + result.update(rectangle_histogram=histogram, table_sha256=digest.hexdigest(), + stream_work=total_stats, semantic_mutants=mutants) + return result + + +def sharpness(closed): + row = describe(6, 53, 25, 7) + expected = ((0, 4, 2, 8), (4, 7, 0, 6), (7, 8, 0, 4)) + require(row.rectangles == expected, "sharp row descriptor") + points = [(0, 6), (4, 4), (7, 0)] + cross_zeros = [] + for t, y in points: + require(closed.switch_bit(6, 53, 25, 7, 8*y+t) == 1, "fooling-set point") + for i, (t, y) in enumerate(points): + for u, v in points[i+1:]: + candidates = [(t, v), (u, y)] + zero = next(((r, q) for r, q in candidates + if closed.switch_bit(6, 53, 25, 7, 8*q+r) == 0), None) + require(zero is not None, "rectangle fooling-set cross") + cross_zeros.append(list(zero)) + return dict(parameters=[6, 53, 25, 7], rectangles=[list(r) for r in expected], + one_points=[list(p) for p in points], cross_zeros=cross_zeros, + active_bits=row.ones(), active_switches=row.ones() // 2) + + +def wide_checks(closed): + rng = random.Random(637734) + descriptors = queries = 0 + for h in (7, 31, 65, 127, 511, 4096, 65536): + for _ in range(40): + s = rng.randrange(1, (1 << h) + 1) + a, j = rng.randrange(s), rng.randrange(2*h-1) + row = describe(h, s, a, j) + inspect_row(row) + if j <= h - 1: + require(len(row.rectangles) <= 1, "wide first or center cap") + addresses = {0, (1 << h) - 1, rng.getrandbits(h)} + for t0, t1, y0, y1 in row.rectangles: + for t in {max(0, t0 - 1), t0, t1 - 1, min((1 << row.depth)-1, t1)}: + for y in {max(0, y0-1), y0, y1-1, + min((1 << (h-row.depth))-1, y1)}: + addresses.add((y << row.depth) + t) + for x in addresses: + require(row.bit(x) == closed.switch_bit(h, s, a, j, x), "wide boundary query") + queries += 1 + descriptors += 1 + return dict(wide_descriptors=descriptors, wide_queries=queries, maximum_height=MAX_HEIGHT) + + +def counter_controls(): + checks = 0 + for value in range(513): + stats = dict(template_bits=0, counter_bits_copied=0, counter_bit_visits=0) + counter = Countdown(binary_template(value, stats), stats) + for remaining in range(value, 0, -1): + require(counter.take(), "counter stopped early") + represented = sum(bit << i for i, bit in enumerate(counter.bits)) + require(represented == remaining - 1, "counter value") + require(not counter.bits or counter.bits[-1] == 1, "counter canonical end") + checks += 1 + require(not counter.take(), "counter did not stop") + require(stats["counter_bit_visits"] == 2*value - value.bit_count(), "exact counter work") + row = describe(6, 53, 25, 7) + correct = [row.bit(x) for x in range(64)] + reversed_coordinates = [row.bit(((x % 8) << 3) + x // 8) for x in range(64)] + require(correct != reversed_coordinates, "stream coordinate mutation") + return dict(counter_decrements=checks, counter_starts=513, + stream_order_mutant_rejected=True) + + +def domain_controls(): + invalid = [(0, 1, 0, 0), (MAX_HEIGHT + 1, 1, 0, 0), (2, 0, 0, 0), + (2, 5, 0, 0), (2, 3, -1, 0), (2, 3, 3, 0), + (2, 3, 0, -1), (2, 3, 0, 3), (True, 1, 0, 0), (2, 3.0, 0, 0)] + for case in invalid: + try: + describe(*case) + except ValueError: + continue + raise ValueError("invalid descriptor accepted") + row = describe(2, 3, 1, 1) + for x in (-1, 4, True, 0.0): + try: + row.bit(x) + except ValueError: + continue + raise ValueError("invalid address accepted") + return len(invalid) + 4 + + +def calculate(): + canonical, closed = load_sources() + result = census(canonical, closed) + result.update(wide_checks(closed)) + result.update(counter_controls()) + result["sharpness"] = sharpness(closed) + result["domain_rejections"] = domain_controls() + result["scope"] = "Three rectangles per canonical row and optimal output bit work; no physical row producer or kappa" + return result + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--write-result", action="store_true") + args = parser.parse_args() + result = calculate() + if args.write_result: + (PACKAGE / "RESULT.json").write_text(json.dumps(result, indent=2, sort_keys=True) + "\n") + else: + require(result == json.loads((PACKAGE / "RESULT.json").read_text()), "result mismatch") + print("PASS_ROTATION_ROW_RECTANGLES sharp three-rectangle row and output-linear stream") + + +if __name__ == "__main__": + main()