diff --git a/research/half-sum-clear-tape/.gitattributes b/research/half-sum-clear-tape/.gitattributes new file mode 100644 index 0000000000..130a3ecaa2 --- /dev/null +++ b/research/half-sum-clear-tape/.gitattributes @@ -0,0 +1 @@ +retained/** -text whitespace=cr-at-eol diff --git a/research/half-sum-clear-tape/CREDITS.md b/research/half-sum-clear-tape/CREDITS.md new file mode 100644 index 0000000000..a9dd28a586 --- /dev/null +++ b/research/half-sum-clear-tape/CREDITS.md @@ -0,0 +1,33 @@ +# Credit and source identity + +Nick Petalas produced the specialized half-sum circuit, proof and verifier +in [PR #7721](https://github.com/CrocSwap/integer-mult-bounds/pull/7721). +The [source README](https://github.com/petalas/integer-mult-bounds/blob/8f6279527c4362e2638737c90fa18c3cfec724fa/research/half-sum-clear-circuit/README.md) +states this credit and asks for a physical tape layout and bill. Its six +scientific files are copied without change from published head +8f6279527c4362e2638737c90fa18c3cfec724fa. SOURCE-PINS.json gives their Git +blobs and SHA-256 values. The source's shared-CI edits are not reused. + +SYLforge supplied the source word in +[PR #7669](https://github.com/CrocSwap/integer-mult-bounds/pull/7669), and the +row identification, complete XOR/diagnostic interface and general circuit in +[PR #7687](https://github.com/CrocSwap/integer-mult-bounds/pull/7687). +Read the [source interface](https://github.com/SYLforge/integer-mult-bounds/blob/e5ba67dfd6237a1a3acf4d67098d3242adee8229/research/clean-rational-clear-witness/README.md). +Those native and arithmetic results remain inherited. This package claims +only the emitted tape execution, endpoint check and execution/stock bound. + +[PR #3233](https://github.com/CrocSwap/integer-mult-bounds/pull/3233) prices a +different pooled high-field ADD and leaves a full finite-control bill open. +No code or constant from that package is used. The selected +[application review](https://github.com/CrocSwap/integer-mult-bounds/blob/e54523517d0f03e58352e647c403a5af3e525a57/docs/research/pr-intake-evidence/pr7000-application/PROOF-REVIEW.md) +already gives a conservative scalar grammar. Its admission does not transfer +to this successor row or stored-program service. + +Ripple arithmetic, reversible compute/copy/uncompute and multi-tape machine +simulation are standard methods. Credit the retained native and compiler +authors for the source context. Original notices remain in retained/source; +retained/LICENSE preserves the Apache-2.0 license from the repository base. + +Prepared by Ali Romman with substantial OpenAI Codex assistance in research, +implementation, verification and writing. Apache-2.0. This is source-aware +author checking, not independent human or formal acceptance. diff --git a/research/half-sum-clear-tape/PROGRAM-1076.bits.gz b/research/half-sum-clear-tape/PROGRAM-1076.bits.gz new file mode 100644 index 0000000000..779df33fa6 Binary files /dev/null and b/research/half-sum-clear-tape/PROGRAM-1076.bits.gz differ diff --git a/research/half-sum-clear-tape/PROOF.md b/research/half-sum-clear-tape/PROOF.md new file mode 100644 index 0000000000..fd43f8a001 --- /dev/null +++ b/research/half-sum-clear-tape/PROOF.md @@ -0,0 +1,156 @@ +# Fixed-tape execution of the half-sum CLEAR + +This package gives a stored-program execution service for the exact circuit +in PR #7721. At signed width 1076, it uses 589841 unit data instructions, +5308569 program bits and 11206982 interpreter steps. This bill includes work +initialization, output copy, reverse computation, work retirement, all data +head returns and the full program scan and return. It is an execution upper +bound, not an optimality result. No new kappa is claimed. + +## Exact entrance and exit + +Let `w>=1`, `n=w+3`, and let `x0,...,x7` be arbitrary signed w-bit integers. +Put `N=x0+x1+x2+x3-x4-x5-x6-x7` and `q=floor(N/2)`. The service leaves each +donor unchanged. It XORs the low w bits of q into an arbitrary w-bit target. +It XORs `N mod 2 OR q<-2^(w-1) OR q>=2^(w-1)` into an arbitrary diagnostic. + +There are 25 data tapes and one read-only program tape. Every tape uses the +same five symbols: `0`, `1`, `<`, `>` and blank. Data heads start on their +left marker `<`. Tapes 0 through 7 hold the donors, tape 8 holds the target, +and tape 9 holds the diagnostic. Each external bit block has a right marker. +The 14 tapes numbered 10 through 23 hold the seven successive result/carry +pairs, with lengths n and n-1. Tape 24 holds the four flags. The 15 work tapes +have a left marker and blank reserved cells at entrance. Their bit cells and +right-marker cells must return blank. All external markers remain unchanged. + +The input program is the marked binary string in PROGRAM-1076.bits.gz for +width 1076, or the output of compile_tape for another width. Its head starts +on `<`. The interpreter has two temporary bits A and B, initially zero, and +a fixed finite decoder state. It returns both temporary bits and all 26 heads +to their entrance states. The program is unchanged. The program is an input +resource: this result does not implement its physical generation or loading. + +The tape machine has a fixed number of tapes, a fixed alphabet and a +width-independent finite control. This is a classical multi-tape transition +model. No claim of transition-level reversible control is made. The specified +external XOR map is reversible, and the work and temporary data are restored. +This distinction is required before any use in an owned-erasure supplier. + +## Source circuit and address layout + +SOURCE-PINS.json binds all six unchanged source files and the source license. +The source README proves its complete arithmetic contract for every w. Its +range bound `abs(N)<=4*(2^w-1)` fits in signed n bits. Seven fresh ripple stages +compute N modulo 2^n; this is its exact signed value. Two top-bit comparisons +and two Boolean ORs compute the invalid flag. Copying bits 1 through w and +the invalid flag, then reversing the internal gates, restores every work bit. +The internal gates do not access the target or diagnostic. + +The circuit allocates its wires in exactly the tape order above. Each wire +has one fixed tape and one fixed cell. Sign extension uses the donor sign +cell repeatedly; it does not allocate or assume extra input bits. The gate +controls and target are distinct. The compiler checks the complete address +range. It emits every move needed to reach each cell from the head's current +position. Thus gate lookup is not an unpriced random-access operation during +execution: the resulting program contains only unit physical operations. + +## Instructions and interpreter + +Each instruction has nine bits. The first four bits name one of ten +operations; the last five name one of 25 data tapes. Unused codes are invalid. +LEFT and RIGHT move that tape head one cell. XORA and XORB XOR the current +cell into A or B. FLIPA toggles the current cell when A is one. FLIPAB toggles +it when both A and B are one. INIT changes blank to zero, RETIRE changes zero +to blank, MARK changes blank to `>`, and UNMARK changes `>` to blank. The +four conversion operations require the stated input symbol. Each operation +is one multi-tape transition after the instruction has been decoded. + +To execute a CNOT, read its control into A, visit and toggle the target, then +visit the control again and clear A. For a Toffoli, read both controls, toggle +the target, then visit the controls in reverse order and clear B and A. The +controls do not change. Thus each source gate has the same action, and both +temporary bits are zero at every gate boundary. This also covers controls +and targets on the same tape: each visit has its own emitted head movement. + +For every work tape, initialization writes each zero, writes its right +marker, then returns the head. Execute the forward gates, output copy and +reverse gates. Return all data heads. Retirement removes each work right +marker, changes each restored zero to blank, then returns its head. Source +correctness and gate simulation prove the complete endpoint for all input +bits, including invalid numerators and arbitrary initial output bits. + +One initial step moves the program head to its first bit. Each of L +instructions uses nine read/move steps and one data-operation step. Its +decoder can use finitely many states for all binary prefixes of length at +most nine; this number does not depend on w. At the end marker, one step +selects the return state. Exactly `9L+1` left moves return the program head. +The last move can enter the halt state. Thus the full bill is `19L+3` steps. +The simulator's array bounds are checks on the emitted trace, not a machine +oracle or a charged address lookup. Valid execution stays in the proved +reserved intervals. Program bytes are decoded in order, including in tests. + +## All-width execution and stock bounds + +The source has `59w+153` CNOTs and `28w+46` Toffolis. For each forward ripple, +the CNOT count is `3n-1`; a subtraction adds `2n-3`. The flag stage has eight +CNOTs and two Toffolis. The forward Toffoli count is `7*(2n-3)+2`. +Doubling these counts and adding w+1 output CNOTs gives the stated totals. +Consequently gate read/toggle operations cost +`A=3*(59w+153)+5*(28w+46)=317w+689` unit instructions. + +Let `W=14w+39` be the number of work bits. For a work bank of length l, +initialization costs `2l+2` moves and `l+1` writes. Retirement costs the same. +There are 15 work banks, so both phases cost `6W+90=84w+324` instructions. + +Each of the 14 forward or reverse ripple passes accesses at most four tapes. +The first access to each costs at most n moves. Within a pass, consecutive +accesses on each tape differ by at most two cells: columns are consecutive, +the carry accesses use adjacent columns, and sign extension clamps at the +last donor cell. Reverse order preserves this distance bound. The first +accesses therefore cost at most 56n; all remaining ripple movement costs +at most 2A. This overcounts non-ripple operations and is a valid upper bound. + +The two flag passes contain 20 gates. At most five cell visits per gate, +each of distance at most n, cost at most 100n. The output copy has four first +head accesses and two monotone bit scans, costing at most `4n+2w<=6n`. +The final data-head return costs at most 25n. The four-cell flag tape also +fits these bounds because `n>=4`. Thus all gate and final-return movement +costs at most `187n+2A`. Adding bit operations and allocation gives +`L<=187n+3A+84w+324=1222w+2952`. Therefore +`steps<=23218w+56091` for every positive w. This is a proof from the column +loops and access distances, not a fit to finite measurements. + +The data stock is `9w+1+W=23w+40` bit cells plus at most 50 markers. +The 15 work right-marker cells are initially and finally blank. The program +stock is `9L+2` cells, including its two markers. Two control bits and the +finite decoder are constant state. At width 1076, the bit stock is 24788, +of which 15103 are work bits. Program stock is 5308571 cells. Reserved blank +regions, origin markers and the marked input program are entrance resources. +They are not established by this local execution result. + +## Verification and limits + +The unchanged source verifier runs first. The new checker then decodes and +executes the tape program against direct signed-integer arithmetic. It checks +every cell, all heads, both control bits, instruction counts and retained +program bytes. Width one covers all 1024 donor/target/diagnostic combinations. +Width two covers all 65536 donor tuples with varied output bits. Width 1076 +uses the source's 32 published cases. Arbitrary output bits at every width +are justified by the source's XOR-only output interface, not by finite cases. +Seven widths check emitted stock and bounds. The all-width claim uses the +proof above. Bit-plane batching changes only test throughput, not the trace. + +Five changed streams are rejected: omitted initialization, omitted retirement, +omitted head return, malformed bits and a wrong target-toggle operation. A +valid extra right/left detour preserves the endpoint and costs exactly 38 +more interpreter steps. Thus endpoint equality cannot conceal an unpriced scan. +Normal and optimized Python runs use explicit exceptions, not assertions. + +The caller-to-row identification at event 88937 is inherited from PR #7687. +It was read but not rerun here. Program generation/loading, global blank-bank +provision, complete reset and stock budgets, rounded producer reachability, +native admission and complete caller integration remain open. No selected +assumption is discharged. The selected kappa .00363005817 and all five +framework assumptions remain unchanged. No full selected cold replay, Lean +or Docker check is included. These are source-aware author checks, not blind, +independent human or formal-kernel acceptance. diff --git a/research/half-sum-clear-tape/README.md b/research/half-sum-clear-tape/README.md new file mode 100644 index 0000000000..96fbdca1e1 --- /dev/null +++ b/research/half-sum-clear-tape/README.md @@ -0,0 +1,39 @@ +# Half-sum CLEAR on fixed tapes + +At width 1076, the exact PR #7721 circuit executes with 25 data tapes, one +read-only program tape and two temporary control bits. The emitted schedule +uses 589841 unit data instructions and 11206982 interpreter steps. All work +cells, markers, heads and control bits return to their specified exit state. +The program is preserved. No new kappa is claimed. + +Read [PROOF.md](PROOF.md) for the exact entrance contract, all-width bound, +stock bill and open obligations. [RESULT.json](RESULT.json) contains finite +receipts. [PROGRAM-1076.bits.gz](PROGRAM-1076.bits.gz) contains the complete +marked binary program. [SOURCE-PINS.json](SOURCE-PINS.json) binds the unchanged +source files; [CREDITS.md](CREDITS.md) gives attribution. + +Run with CPython 3.12 and its standard library: + +```sh +python3.12 -B scripts/research_package.py --package research/half-sum-clear-tape +``` + +The source verifier prints PASS_HALF_SUM_CLEAR. Each registered command then +prints: + +```text +PASS_HALF_SUM_CLEAR_FIXED_TAPE {'1': 1024, '2': 65536, '1076': 32} 11206982 +``` + +This service receives its width-dependent program and reserved tape regions +at entrance. A uniform physical program generator and complete caller +admission remain open. The result does not claim transition-level reversible +control or discharge an inherited framework assumption. + +## Open next questions + +Can a uniform physical generator supply the marked program and return its +own work to blank? Specify its input, fixed-tape transitions and full bill +before composition. Can the enclosing caller supply and retire the reserved +regions under its global stock and reset bounds? These services are required +before this execution result can support complete supplier admission. diff --git a/research/half-sum-clear-tape/RESULT.json b/research/half-sum-clear-tape/RESULT.json new file mode 100644 index 0000000000..3f3b2817ed --- /dev/null +++ b/research/half-sum-clear-tape/RESULT.json @@ -0,0 +1,285 @@ +{ + "status": "PASS_HALF_SUM_CLEAR_FIXED_TAPE", + "width_receipts": [ + { + "width": 1, + "commands": 1816, + "data_moves": 674, + "gate_bit_operations": 1006, + "initialize_bits": 53, + "retire_bits": 53, + "markers": 30, + "program_bits": 16344, + "interpreter_steps": 34507, + "phases": [ + { + "phase": "initialize", + "commands": 204 + }, + { + "phase": "forward", + "commands": 697 + }, + { + "phase": "copy", + "commands": 10 + }, + { + "phase": "reverse", + "commands": 676 + }, + { + "phase": "home", + "commands": 25 + }, + { + "phase": "retire", + "commands": 204 + } + ] + }, + { + "width": 2, + "commands": 2363, + "data_moves": 876, + "gate_bit_operations": 1323, + "initialize_bits": 67, + "retire_bits": 67, + "markers": 30, + "program_bits": 21267, + "interpreter_steps": 44900, + "phases": [ + { + "phase": "initialize", + "commands": 246 + }, + { + "phase": "forward", + "commands": 925 + }, + { + "phase": "copy", + "commands": 15 + }, + { + "phase": "reverse", + "commands": 905 + }, + { + "phase": "home", + "commands": 26 + }, + { + "phase": "retire", + "commands": 246 + } + ] + }, + { + "width": 3, + "commands": 2910, + "data_moves": 1078, + "gate_bit_operations": 1640, + "initialize_bits": 81, + "retire_bits": 81, + "markers": 30, + "program_bits": 26190, + "interpreter_steps": 55293, + "phases": [ + { + "phase": "initialize", + "commands": 288 + }, + { + "phase": "forward", + "commands": 1153 + }, + { + "phase": "copy", + "commands": 20 + }, + { + "phase": "reverse", + "commands": 1134 + }, + { + "phase": "home", + "commands": 27 + }, + { + "phase": "retire", + "commands": 288 + } + ] + }, + { + "width": 4, + "commands": 3457, + "data_moves": 1280, + "gate_bit_operations": 1957, + "initialize_bits": 95, + "retire_bits": 95, + "markers": 30, + "program_bits": 31113, + "interpreter_steps": 65686, + "phases": [ + { + "phase": "initialize", + "commands": 330 + }, + { + "phase": "forward", + "commands": 1381 + }, + { + "phase": "copy", + "commands": 25 + }, + { + "phase": "reverse", + "commands": 1363 + }, + { + "phase": "home", + "commands": 28 + }, + { + "phase": "retire", + "commands": 330 + } + ] + }, + { + "width": 8, + "commands": 5645, + "data_moves": 2088, + "gate_bit_operations": 3225, + "initialize_bits": 151, + "retire_bits": 151, + "markers": 30, + "program_bits": 50805, + "interpreter_steps": 107258, + "phases": [ + { + "phase": "initialize", + "commands": 498 + }, + { + "phase": "forward", + "commands": 2293 + }, + { + "phase": "copy", + "commands": 45 + }, + { + "phase": "reverse", + "commands": 2279 + }, + { + "phase": "home", + "commands": 32 + }, + { + "phase": "retire", + "commands": 498 + } + ] + }, + { + "width": 16, + "commands": 10021, + "data_moves": 3704, + "gate_bit_operations": 5761, + "initialize_bits": 263, + "retire_bits": 263, + "markers": 30, + "program_bits": 90189, + "interpreter_steps": 190402, + "phases": [ + { + "phase": "initialize", + "commands": 834 + }, + { + "phase": "forward", + "commands": 4117 + }, + { + "phase": "copy", + "commands": 85 + }, + { + "phase": "reverse", + "commands": 4111 + }, + { + "phase": "home", + "commands": 40 + }, + { + "phase": "retire", + "commands": 834 + } + ] + }, + { + "width": 1076, + "commands": 589841, + "data_moves": 217824, + "gate_bit_operations": 341781, + "initialize_bits": 15103, + "retire_bits": 15103, + "markers": 30, + "program_bits": 5308569, + "interpreter_steps": 11206982, + "phases": [ + { + "phase": "initialize", + "commands": 45354 + }, + { + "phase": "forward", + "commands": 245797 + }, + { + "phase": "copy", + "commands": 5385 + }, + { + "phase": "reverse", + "commands": 246851 + }, + { + "phase": "home", + "commands": 1100 + }, + { + "phase": "retire", + "commands": 45354 + } + ] + } + ], + "program_sha256": "1ba8585384a3a47c85b93461f174dac44ad9f9c700cc89d7716fca6f8f61c2be", + "executed_cases": { + "1": 1024, + "2": 65536, + "1076": 32 + }, + "controls": { + "rejected_programs": 5, + "priced_endpoint_preserving_detour": 38 + }, + "all_width_bound": { + "commands": "1222*w+2952", + "interpreter_steps": "23218*w+56091", + "data_bit_cells": "23*w+40", + "work_bit_cells": "14*w+39", + "data_markers": 50, + "program_cells": "9*L+2" + }, + "selected_kappa": "0.00363005817", + "new_kappa": null, + "claim_scope": "Stored-program execution only; program preparation, global stock/reset and full caller admission remain open." +} diff --git a/research/half-sum-clear-tape/SOURCE-PINS.json b/research/half-sum-clear-tape/SOURCE-PINS.json new file mode 100644 index 0000000000..97ae98738c --- /dev/null +++ b/research/half-sum-clear-tape/SOURCE-PINS.json @@ -0,0 +1,51 @@ +[ + { + "path": "retained/source/README.md", + "source_path": "research/half-sum-clear-circuit/README.md", + "source_commit": "8f6279527c4362e2638737c90fa18c3cfec724fa", + "git_blob": "7de5b202a26cfb246ddfdeb8c13b4908bbfcc6a5", + "sha256": "31afb7445fb3db4896caef06c41b19a777bd4c7bd2ac29e970c58f38f234d0de" + }, + { + "path": "retained/source/circuit.py", + "source_path": "research/half-sum-clear-circuit/circuit.py", + "source_commit": "8f6279527c4362e2638737c90fa18c3cfec724fa", + "git_blob": "a21ae75253d403e64d10f27a6dd8c858c3a54e52", + "sha256": "44e8e90f1e8d2493317afa176d03493af3c900a0704b72b99e94540058b7924d" + }, + { + "path": "retained/source/verify.py", + "source_path": "research/half-sum-clear-circuit/verify.py", + "source_commit": "8f6279527c4362e2638737c90fa18c3cfec724fa", + "git_blob": "f880633ca637a12a38663afb1e2a110d9f4724cf", + "sha256": "8991f1575c84e6db66405c9f6f867a0d5d859f4ab88eb452edef458b666bdaf1" + }, + { + "path": "retained/source/TASK.json", + "source_path": "research/half-sum-clear-circuit/TASK.json", + "source_commit": "8f6279527c4362e2638737c90fa18c3cfec724fa", + "git_blob": "b3592eee4c4fdb10d4647679e6fb19fbc4f3301d", + "sha256": "48c57e01e22168004f03c8296c0b6f0cceb61987cc20b8b6629f468aa7c138c1" + }, + { + "path": "retained/source/SOURCES.json", + "source_path": "research/half-sum-clear-circuit/SOURCES.json", + "source_commit": "8f6279527c4362e2638737c90fa18c3cfec724fa", + "git_blob": "5335fa97d97f6df5a917eea1ee2fcd01c082d261", + "sha256": "0761fd793723c2df1e2ca51733251cfd597ff3e120f7e2ee8ebb8e10e8e98c08" + }, + { + "path": "retained/source/VERIFY.json", + "source_path": "research/half-sum-clear-circuit/VERIFY.json", + "source_commit": "8f6279527c4362e2638737c90fa18c3cfec724fa", + "git_blob": "c4ff5d410607dd1f3c5a56ae03fff4df4f5f5415", + "sha256": "d414a9db303fe3b5338c4990f24fcff71d321e9646b2e3346f956759cc67e3af" + }, + { + "path": "retained/LICENSE", + "source_path": "LICENSE", + "source_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "git_blob": "261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64", + "sha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4" + } +] diff --git a/research/half-sum-clear-tape/SOURCES.json b/research/half-sum-clear-tape/SOURCES.json new file mode 100644 index 0000000000..5335fa97d9 --- /dev/null +++ b/research/half-sum-clear-tape/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/half-sum-clear-tape/TASK.json b/research/half-sum-clear-tape/TASK.json new file mode 100644 index 0000000000..d62a15936e --- /dev/null +++ b/research/half-sum-clear-tape/TASK.json @@ -0,0 +1,91 @@ +{ + "schema_version": 1, + "task_id": "supplier-boundary-audit", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "supplier-boundary-audit", + "question": "Does one changed supplier have complete source-bound native, caller, ordinary and outer admission coverage?", + "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": "Pin the current sources and one obligation; the historical owner audit is an example, not evidence of a current bug.", + "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 latest uncovered candidate and build a delta coverage map against the selected review. For P104, #5717 changes owned-lifetime assumptions and #5719 covers exact #5713 causal premises; neither automatically transfers to #5718. For BIT, #5679/#5708 need component admission and compatible outer use. Check controls and exact source identity before reuse; stop with one resolved gap or explicit remaining obligation. A heavy full replay requires a separate serial resource budget.", + "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": [ + "supplier admission", + "5717", + "5719", + "5708", + "owned lifetime" + ], + "existing_checks": [ + { + "scope": "PR #4088: author-checked local words, native receipts, owner/phase fill and exact moment.", + "evidence": "research/staged544-mixed-fourth-entry/README.md", + "remaining": "Rebind and validate ordinary/outer admission with all four providers; full mixed release not established.", + "status": "author-checked", + "source_commit": "72d7efc181edb21806a878f174847c96dd410ab0", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #3801: successor scatter-boundary decision package.", + "evidence": "research/scatter-boundary-decision/README.md", + "remaining": "Consult its exact acceptance scope before any new exporter audit; not proof of a selected failure.", + "status": "author-checked", + "source_commit": "911f8800ba7a4b03603ef62c5ffc6240e53cb5fd", + "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": "refined", + "actual_scope": "Stored-program fixed-tape execution of the exact PR7721 half-sum CLEAR, with complete local endpoint, program scan and all-width execution/stock bill.", + "scope_change_reason": "The released PR7721 handoff asks for tape layout and scan costs. This resolves that execution edge while keeping program preparation and full admission separate.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "budget_minutes": 60, + "stop_rule": "Finish one emitted and checked local tape execution with an all-width bill; do not infer complete caller admission or run a whole native/cold suite.", + "outcome": "completed", + "evidence": "PROOF.md; RESULT.json; PROGRAM-1076.bits.gz; SOURCE-PINS.json", + "author": "Ali Romman", + "ai_assistance": "Substantial OpenAI Codex assistance in research, implementation, verification and writing.", + "open_questions": [ + { + "question": "Can a uniform physical program generator and global stock/reset interface supply this local executor?", + "why_it_matters": "The executor receives its marked program and reserved blank regions at entrance.", + "first_step": "Specify the generator input, fixed-tape transitions, output program and complete storage/reset bill before composing the services.", + "blocked_by": "A source-bound uniform generator and enclosing caller admission." + } + ] +} diff --git a/research/half-sum-clear-tape/VERIFY.json b/research/half-sum-clear-tape/VERIFY.json new file mode 100644 index 0000000000..affe0488d5 --- /dev/null +++ b/research/half-sum-clear-tape/VERIFY.json @@ -0,0 +1,34 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Replay retained circuit checks, execute exact tape programs against integer arithmetic, check all cells and heads, exact stock and bills, five rejected mutations and one priced detour." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "-O", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Replay retained circuit checks, execute exact tape programs against integer arithmetic, check all cells and heads, exact stock and bills, five rejected mutations and one priced detour." + } + ] +} diff --git a/research/half-sum-clear-tape/retained/LICENSE b/research/half-sum-clear-tape/retained/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/research/half-sum-clear-tape/retained/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/half-sum-clear-tape/retained/source/README.md b/research/half-sum-clear-tape/retained/source/README.md new file mode 100644 index 0000000000..7de5b202a2 --- /dev/null +++ b/research/half-sum-clear-tape/retained/source/README.md @@ -0,0 +1,97 @@ +# A smaller reversible circuit for one signed half-sum CLEAR + +At signed width 1,076, this circuit implements the complete output map for the +eight-limb row at event 88937 with **93,811 gates and 15,103 internal zero bits**. +SYLforge reports 277,929 gates and 86,525 internal zero bits for the same row +in the general rational circuit. Specializing to four positive unit coefficients, +four negative unit coefficients and denominator two saves 184,118 gates and +71,422 work bits. Both counts include output copying and cleanup. +[Published comparator and source row](https://github.com/SYLforge/integer-mult-bounds/blob/e5ba67dfd6237a1a3acf4d67098d3242adee8229/research/clean-rational-clear-witness/README.md) + +## Interface and scope + +This is a scoped proof with an executable finite gate certificate. In SYLforge's +#7669 word, target 1502 uses donors 1072 and 500. The eight signed limbs are +the real and imaginary parts at addresses 0 and 102 of the first donor, then +the same four of the second donor. We use the real output at address zero +identified by #7687. The caller-to-row identification and the comparator counts +are taken from that work. The circuit accepts arbitrary donor bitstrings. +[Source word](https://github.com/CrocSwap/integer-mult-bounds/pull/7669) + +For any positive width w, let N be the sum of the first four signed donors +minus the sum of the last four. Put q = floor(N/2). The circuit leaves donors +untouched, XORs the low w bits of q into the target, and toggles the diagnostic +if N is odd or q is outside the signed w-bit range. Every work bit starts and +ends zero. With initial diagnostic zero, both outputs are zero exactly when +N equals twice the signed target. In particular, a fractional quotient or +signed overflow stays detectable even if the target XOR produces zero. + +## Construction and proof + +Let n = w + 3. The largest possible N is 4(2^w − 1), attained by placing +the four maxima before the four minima. Swapping the groups attains its +negative. Both fit in signed n bits. Sign extension aliases the donor sign +wire as a control. Start with the first extended donor and accumulate the +other seven modulo 2^n. The final residue therefore encodes N exactly. + +Each ripple stage uses fresh result bits and fresh internal carries. In a +column with accumulator bit a, operand bit b and incoming carry or borrow c, +first write p = a XOR b. Addition's outgoing carry is ab XOR cp. Subtraction's +outgoing borrow is (1−a)b XOR (1−p)c, or ab XOR b XOR cp XOR c. These formulas +follow by treating the equal-bit and unequal-bit cases separately. Both stages +then XOR c into p to produce the result bit. The low column takes c = 0 and +the top column discards its outgoing carry. This proves the modular stage +identity by induction over the columns. Donor wires appear only as controls. + +The low bit of N flags oddness, including for negative N. Bits 1 through w +give the low w quotient bits because arithmetic right shift gives floor +division by two. The quotient fits exactly if bits w+1 and w+2 of N both +equal bit w. Two XOR comparisons and Boolean ORs therefore implement the +specified diagnostic. Copy the result bits and flag to the output ports and +run the internal gate list backwards. Each gate is an involution, and the +internal list never accesses the output ports. This restores every work bit +regardless of validity or initial target. + +## Complete resource count + +Each of seven stages allocates n result bits and n−1 carry bits. Two comparison +bits and two OR bits give 7(2n−1)+4 = **14w+39 work bits**. The external wires +are the 8w immutable inputs, w target bits and one diagnostic bit. + +An addition uses 2n gates to form p, n−1 to copy incoming carries into the +result, n−1 for ab and n−2 for cp. Each of the four subtractions adds +(n−1)+(n−2) borrow toggles. The flag needs four CNOTs for comparisons and +three gates for each of two ORs. Thus the forward computation uses +7(5n−4)+4(2n−3)+10 = 43n−30 gates. Output copying costs w+1 and the reverse +costs another 43n−30, giving **87w+199 gates**. At width 1,076 the emitted +list contains 63,637 CNOTs and 30,174 Toffolis. + +## Reproduce + +From the repository root with CPython 3.12 and its standard library, run + +~~~sh +python3.12 -B research/half-sum-clear-circuit/verify.py +python3.12 -B scripts/research_package.py --package research/half-sum-clear-circuit +~~~ + +The verifier simulates every gate, checks wire indices and donor immutability, +and compares every output and workspace wire with an integer oracle. It +exhausts donor tuples at widths one and two, then executes 32 cases at width +1,076, including negative odd numerators, both signed endpoints, wrapped +overflow and reproducible mixed inputs. It prints PASS_HALF_SUM_CLEAR. +The gate certificate establishes an upper bound for this row. Optimality, +rounded producer reachability, full erasure, tape costs and a change to κ +remain outside its scope. + +## Open next questions + +What does this circuit cost on the physical tapes? Fix a tape layout and +account for its clean banks, carry access, output copy and reverse scans. + +## Credit + +The specialized circuit, proof and verifier were produced by Nick Petalas. +SYLforge supplied the source word, the coordinate identification, the complete +validity interface, the published comparator and the smaller-circuit question. +Ripple arithmetic and reversible compute/copy/uncompute are standard. diff --git a/research/half-sum-clear-tape/retained/source/SOURCES.json b/research/half-sum-clear-tape/retained/source/SOURCES.json new file mode 100644 index 0000000000..5335fa97d9 --- /dev/null +++ b/research/half-sum-clear-tape/retained/source/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/half-sum-clear-tape/retained/source/TASK.json b/research/half-sum-clear-tape/retained/source/TASK.json new file mode 100644 index 0000000000..b3592eee4c --- /dev/null +++ b/research/half-sum-clear-tape/retained/source/TASK.json @@ -0,0 +1,95 @@ +{ + "schema_version": 1, + "task_id": "formal-interface-lemma", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "formal-interface-lemma", + "question": "Can one uncovered interface implication be formalized with exact caller and certificate bindings?", + "starting_points": [ + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "research/gate-operand-parity-lean/README.md", + "research/staged544-certified-endpoint/README.md", + "research/unconditional-batched-crt/README.md" + ], + "methods": [ + "Formalize a missing boundary lemma identified by the selected review.", + "Audit a formal theorem-to-certificate binding independently." + ], + "acceptance_gate": "State the exact formalized proposition and remaining assumptions; avoid duplicate arithmetic formalizations already present.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "first_experiment": "Write one missing statement with quantified hypotheses, actual caller and existing coverage. A compact-switch lemma is a candidate only after its mathematical contract is reviewed. Establish a bounded proof plan before a separately budgeted proof-assistant build; do not rerun large Lean jobs as orientation.", + "bottleneck_link": "A missing interface proof can reduce the conditional gap even if it does not change kappa.", + "allowed_variations": [ + "Narrow to one formal lemma or one theorem-to-certificate binding." + ], + "scope_change_triggers": [ + "Formalizing already-covered arithmetic and claiming the full multiplication theorem." + ], + "overlap_terms": [ + "hyperplane end", + "formal interface", + "Lean binding", + "3807", + "3857", + "4100", + "gate-operand-parity-lean", + "staged544-certified-endpoint", + "unconditional-batched-crt" + ], + "existing_checks": [ + { + "scope": "PR #3807: scoped gate-operand parity formalization.", + "evidence": "research/gate-operand-parity-lean/README.md", + "remaining": "Exact theorem-to-caller binding and genuinely uncovered interface lemmas.", + "status": "author-checked", + "source_commit": "4c3530f42a6abcc48e7a6bcffd6c901911dc8269", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #3857: certified real-power moment/endpoint arithmetic.", + "evidence": "research/staged544-certified-endpoint/README.md", + "remaining": "Uniform algorithmic implications, not another endpoint digit.", + "status": "author-checked", + "source_commit": "ef4315b8caa605e47a2515004845eb2d2ed71a86", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4100: compact-switch formalization proposed as future validation.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Audit the statement and assumptions before a formal proof campaign.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Construct a smaller exact reversible gate circuit for the single signed half-sum CLEAR row at event 88937.", + "scope_change_reason": "Question 3 of PR #7687 asks for a constructive gate and workspace improvement under its existing output contract. This contributes a mathematical interface proof and executable circuit rather than a proof-assistant formalization.", + "bottleneck_link": "The owned_erasure interface needs an exact validity test and restoration of temporary storage at the chosen row. Gate-level cost is only one part of that service.", + "budget_minutes": 60, + "stop_rule": "Stop at the first construction improving the cited complete gate and clean-workspace counts at width 1076 with all four output obligations proved.", + "outcome": "completed", + "evidence": "README.md gives the all-input proof and resource count. verify.py executes the emitted gates and compares every wire to integer arithmetic.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "What tape movement and initialization cost does this row require?", + "why_it_matters": "The gate count omits physical access and clean-bank provisioning.", + "first_step": "Assign each bit block to a tape and count the full forward, output and reverse scans.", + "blocked_by": "A fixed tape layout and initialization service for this word remain unspecified." + } + ] +} diff --git a/research/half-sum-clear-tape/retained/source/VERIFY.json b/research/half-sum-clear-tape/retained/source/VERIFY.json new file mode 100644 index 0000000000..c4ff5d4106 --- /dev/null +++ b/research/half-sum-clear-tape/retained/source/VERIFY.json @@ -0,0 +1,18 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Check every gate and complete emitted resource counts. Compare all wires to exact arithmetic for all donor tuples at widths 1 and 2 and full-width fixtures at 1076." + } + ] +} diff --git a/research/half-sum-clear-tape/retained/source/circuit.py b/research/half-sum-clear-tape/retained/source/circuit.py new file mode 100644 index 0000000000..a21ae75253 --- /dev/null +++ b/research/half-sum-clear-tape/retained/source/circuit.py @@ -0,0 +1,59 @@ +"""Reversible CLEAR for (x0+x1+x2+x3-x4-x5-x6-x7)/2. + +Wires store little-endian bits. A gate tuple contains its controls followed +by its XOR target. The first 8*w wires are immutable inputs, followed by the +w target wires and the diagnostic. All remaining wires start and end zero. +""" + + +def compile_row(width): + if width < 1: + raise ValueError("positive signed width required") + size = width + 3 + next_wire = 9 * width + 1 + gates = [] + + def allocate(length): + nonlocal next_wire + block = range(next_wire, next_wire + length) + next_wire += length + return block + + def signed_operand(index): + start = index * width + return [start + min(bit, width - 1) for bit in range(size)] + + total = signed_operand(0) + for index in range(1, 8): + operand = signed_operand(index) + result = allocate(size) + carries = allocate(size - 1) + for bit, (a, b, out) in enumerate(zip(total, operand, result, strict=True)): + gates.extend(((a, out), (b, out))) # propagate bit p = a XOR b + if bit + 1 < size: + carry = carries[bit] + gates.append((a, b, carry)) + if index >= 4: + gates.append((b, carry)) + if bit: + gates.append((carries[bit - 1], out, carry)) + if index >= 4: + gates.append((carries[bit - 1], carry)) + if bit: + gates.append((carries[bit - 1], out)) + total = result + + mismatch = allocate(2) + for offset, flag in enumerate(mismatch): + gates.extend(((total[width], flag), (total[width + offset + 1], flag))) + + def boolean_or(left, right): + out, = allocate(1) + gates.extend(((left, out), (right, out), (left, right, out))) + return out + + overflow = boolean_or(*mismatch) + invalid = boolean_or(total[0], overflow) + copy_outputs = [(total[bit + 1], 8 * width + bit) for bit in range(width)] + copy_outputs.append((invalid, 9 * width)) + return next_wire, gates + copy_outputs + gates[::-1] diff --git a/research/half-sum-clear-tape/retained/source/verify.py b/research/half-sum-clear-tape/retained/source/verify.py new file mode 100644 index 0000000000..f880633ca6 --- /dev/null +++ b/research/half-sum-clear-tape/retained/source/verify.py @@ -0,0 +1,80 @@ +"""Execute the generated gates and compare all wires to signed integer arithmetic.""" + +from collections import Counter +from itertools import batched, product +from random import Random + +from circuit import compile_row + + +def check_batch(width, size, gates, cases): + """Each bit of a Python integer simulates one independent circuit input.""" + states = [0] * size + expected_outputs = [0] * (width + 1) + limit = 1 << (width - 1) + for lane, (donors, target, diagnostic) in enumerate(cases): + for port, value in enumerate((*donors, target)): + for bit in range(width): + states[port * width + bit] |= ((value >> bit) & 1) << lane + states[9 * width] |= diagnostic << lane + numerator = sum(donors[:4]) - sum(donors[4:]) + quotient, remainder = divmod(numerator, 2) + invalid = bool(remainder or not -limit <= quotient < limit) + for bit in range(width): + expected_outputs[bit] |= (((target ^ quotient) >> bit) & 1) << lane + expected_outputs[-1] |= (diagnostic ^ invalid) << lane + expected = states.copy() + expected[8 * width:9 * width + 1] = expected_outputs + for gate in gates: + flip = states[gate[0]] + if len(gate) == 3: + flip &= states[gate[1]] + states[gate[-1]] ^= flip + if states != expected: + raise ValueError("gate output differs from the full expected wire state") + + +def cases_for(width): + limit = 1 << (width - 1) + if width <= 2: + for values in product(range(-limit, limit), repeat=8): + # Targets are XOR outputs. Cover every donor configuration. + yield values, sum(values) % (2 * limit) - limit, values[0] & 1 + return + low, high = -limit, limit - 1 + for numerator in (-1, 0, 1, 2): + yield (numerator,) + (0,) * 7, numerator // 2, 0 + for value in (low, high): + yield (value, value, 0, 0, 0, 0, 0, 0), value, 0 + opposite = -1 - value + quotient = 2 * (value - opposite) + wrapped = (quotient + limit) % (2 * limit) - limit + yield (value,) * 4 + (opposite,) * 4, wrapped, 0 + rng = Random(88937) + for _ in range(24): + words = [rng.randrange(low, high + 1) for _ in range(9)] + yield tuple(words[:8]), words[8], rng.randrange(2) + + +def main(): + for width in (1, 2, 1076): + size, gates = compile_row(width) + counts = Counter(map(len, gates)) + for gate in gates: + if (len(gate) not in (2, 3) or len(set(gate)) != len(gate) + or min(gate) < 0 or max(gate) >= size or gate[-1] < 8 * width): + raise ValueError(f"illegal gate {gate}") + work = size - 9 * width - 1 + if (len(gates), work) != (87 * width + 199, 14 * width + 39): + raise ValueError("emitted gate or workspace count differs from the proof") + checked = 0 + for batch in batched(cases_for(width), 256): + check_batch(width, size, gates, batch) + checked += len(batch) + print(f"w={width} cases={checked} CNOT={counts[2]} Toffoli={counts[3]} " + f"total={len(gates)} work={size - 9 * width - 1}") + print("PASS_HALF_SUM_CLEAR") + + +if __name__ == "__main__": + main() diff --git a/research/half-sum-clear-tape/tape.py b/research/half-sum-clear-tape/tape.py new file mode 100644 index 0000000000..e721c01e4d --- /dev/null +++ b/research/half-sum-clear-tape/tape.py @@ -0,0 +1,153 @@ +"""Compile the retained half-sum circuit to unit tape instructions. + +Ali Romman, with substantial OpenAI Codex assistance. Apache-2.0. +""" + +from collections import Counter +import importlib.util +from pathlib import Path + + +ROOT = Path(__file__).resolve().parent +LEFT, RIGHT, XORA, XORB, FLIPA, FLIPAB, INIT, RETIRE, MARK, UNMARK = range(10) + + +def load_source(name): + spec = importlib.util.spec_from_file_location(name, ROOT / 'retained/source' / (name + '.py')) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def compile_tape(width): + if width < 1: + raise ValueError('positive width required') + lengths = [width] * 9 + [1] + [x for _ in range(7) for x in (width + 3, width + 2)] + [4] + addresses = [(tape, bit) for tape, length in enumerate(lengths) for bit in range(1, length + 1)] + size, gates = load_source('circuit').compile_row(width) + if size != len(addresses): + raise ValueError('source wire layout differs') + for gate in gates: + if len(gate) not in (2, 3) or len(set(gate)) != len(gate) or min(gate) < 0 or max(gate) >= size: + raise ValueError('invalid source gate') + heads = [0] * 25 + commands, phases = [], [] + + def emit(op, tape): + commands.append((op << 5) | tape) + + def goto(tape, position): + op = RIGHT if position > heads[tape] else LEFT + commands.extend([(op << 5) | tape] * abs(position - heads[tape])) + heads[tape] = position + + def phase(name, action): + before = len(commands) + action() + phases.append(dict(phase=name, commands=len(commands) - before)) + + def initialize(): + for tape in range(10, 25): + for position in range(1, lengths[tape] + 1): + goto(tape, position) + emit(INIT, tape) + goto(tape, lengths[tape] + 1) + emit(MARK, tape) + goto(tape, 0) + + def block(sequence): + for gate in sequence: + for index, wire in enumerate(gate[:-1]): + tape, position = addresses[wire] + goto(tape, position) + emit(XORA + index, tape) + tape, position = addresses[gate[-1]] + goto(tape, position) + emit(FLIPA if len(gate) == 2 else FLIPAB, tape) + for index in range(len(gate) - 2, -1, -1): + tape, position = addresses[gate[index]] + goto(tape, position) + emit(XORA + index, tape) + + def home(): + for tape in range(25): + goto(tape, 0) + + def retire(): + for tape in range(10, 25): + goto(tape, lengths[tape] + 1) + emit(UNMARK, tape) + for position in range(lengths[tape], 0, -1): + goto(tape, position) + emit(RETIRE, tape) + goto(tape, 0) + + half = (len(gates) - width - 1) // 2 + phase('initialize', initialize) + phase('forward', lambda: block(gates[:half])) + phase('copy', lambda: block(gates[half:half + width + 1])) + phase('reverse', lambda: block(gates[half + width + 1:])) + phase('home', home) + phase('retire', retire) + counts = Counter(command >> 5 for command in commands) + operations = sum(counts[op] for op in (XORA, XORB, FLIPA, FLIPAB)) + length = len(commands) + if operations != 317 * width + 689 or length > 1222 * width + 2952: + raise ValueError('proved instruction bound differs') + receipt = dict(width=width, commands=length, data_moves=counts[LEFT] + counts[RIGHT], + gate_bit_operations=operations, initialize_bits=counts[INIT], + retire_bits=counts[RETIRE], markers=counts[MARK] + counts[UNMARK], + program_bits=9 * length, interpreter_steps=19 * length + 3, phases=phases) + program = ('<' + ''.join(format(command, '09b') for command in commands) + '>').encode('ascii') + return lengths, program, receipt + + +def execute(program, tapes): + """Read binary instructions and return the final heads, registers and bill. + + Integer bit planes permit independent inputs to share one instruction + trace. Every lane has the same head positions and marker symbols. + """ + if len(tapes) != 25 or not program or program[0] != ord('<'): + raise ValueError('invalid tape entrance') + heads, registers = [0] * 25, [0, 0] + position, steps, commands = 1, 1, 0 + while position < len(program) and program[position] != ord('>'): + code = 0 + for _ in range(9): + if position >= len(program) or program[position] not in (48, 49): + raise ValueError('invalid instruction bits') + code = 2 * code + program[position] - 48 + position += 1 + steps += 1 + op, tape = code >> 5, code & 31 + if op >= 10 or tape >= 25: + raise ValueError('invalid instruction code') + head, cells = heads[tape], tapes[tape] + if op in (LEFT, RIGHT): + head += 1 if op == RIGHT else -1 + if not 0 <= head < len(cells): + raise ValueError('head leaves reserved region') + heads[tape] = head + elif op in (XORA, XORB, FLIPA, FLIPAB): + if type(cells[head]) is not int: + raise ValueError('bit operation on a marker or blank') + if op in (XORA, XORB): + registers[op - XORA] ^= cells[head] + else: + cells[head] ^= registers[0] if op == FLIPA else registers[0] & registers[1] + else: + before, after = {INIT: ('_', 0), RETIRE: (0, '_'), MARK: ('_', '>'), UNMARK: ('>', '_')}[op] + if cells[head] != before: + raise ValueError('allocation or retirement precondition fails') + cells[head] = after + commands += 1 + steps += 1 + if position != len(program) - 1 or program[position] != ord('>'): + raise ValueError('invalid program end') + steps += 1 + while position: + position -= 1 + steps += 1 + return dict(heads=heads, registers=registers, program_head=position, + commands=commands, interpreter_steps=steps) diff --git a/research/half-sum-clear-tape/verify.py b/research/half-sum-clear-tape/verify.py new file mode 100644 index 0000000000..68cdd831a7 --- /dev/null +++ b/research/half-sum-clear-tape/verify.py @@ -0,0 +1,131 @@ +"""Check the stored tape program, complete endpoint and instruction bill. + +Ali Romman, with substantial OpenAI Codex assistance. Apache-2.0. +""" + +from itertools import batched, product +from pathlib import Path +import gzip +import hashlib +import importlib.util +import json +import sys + + +ROOT = Path(__file__).resolve().parent +spec = importlib.util.spec_from_file_location('tape', ROOT / 'tape.py') +tape = importlib.util.module_from_spec(spec) +spec.loader.exec_module(tape) + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def entrance(width, lengths, cases): + cells = [['<'] + [0] * length + ['>'] for length in lengths[:10]] + cells += [['<'] + ['_'] * (length + 1) for length in lengths[10:]] + expected = [row.copy() for row in cells] + limit = 1 << (width - 1) + for lane, (donors, target, diagnostic) in enumerate(cases): + for port, value in enumerate((*donors, target)): + require(-limit <= value < limit, 'fixture outside signed input range') + for bit in range(width): + cells[port][bit + 1] |= ((value >> bit) & 1) << lane + expected[port][bit + 1] |= ((value >> bit) & 1) << lane + cells[9][1] |= diagnostic << lane + numerator = sum(donors[:4]) - sum(donors[4:]) + quotient, remainder = divmod(numerator, 2) + invalid = int(remainder != 0 or quotient < -limit or quotient >= limit) + for bit in range(width): + expected[8][bit + 1] ^= ((quotient >> bit) & 1) << lane + expected[9][1] |= (diagnostic ^ invalid) << lane + return cells, expected + + +def check_endpoint(width, lengths, program, cases): + cells, expected = entrance(width, lengths, cases) + state = tape.execute(program, cells) + require(cells == expected, 'complete tape endpoint differs from exact integer oracle') + require(state['heads'] == [0] * 25 and state['registers'] == [0, 0] + and state['program_head'] == 0, 'heads or control bits are not restored') + require(state['interpreter_steps'] == 19 * state['commands'] + 3, 'decoder step bill differs') + return state + + +def mutation_controls(): + lengths, program, _ = tape.compile_tape(2) + words = [program[position:position + 9] for position in range(1, len(program) - 1, 9)] + cases = list(tape.load_source('verify').cases_for(2))[:256] + cases += [((1,) * 4 + (-2,) * 4, -2, 0), ((-1, 0, 0, 0, 0, 0, 0, 0), -1, 0)] + def encode(parts): + return b'<' + b''.join(parts) + b'>' + changed = [] + for op in (tape.INIT, tape.RETIRE): + index = next(i for i, word in enumerate(words) if int(word, 2) >> 5 == op) + changed.append(encode(words[:index] + words[index + 1:])) + changed.append(encode(words[:-1])) + changed.append(b'<' + b'2' + program[2:]) + index = next(i for i, word in enumerate(words) if int(word, 2) >> 5 == tape.FLIPA) + altered = words.copy() + altered[index] = format((tape.FLIPAB << 5) | (int(words[index], 2) & 31), '09b').encode() + changed.append(encode(altered)) + for bad in changed: + try: + check_endpoint(2, lengths, bad, cases) + except ValueError: + continue + raise ValueError('changed instruction stream was accepted') + detour = encode(words + [format(tape.RIGHT << 5, '09b').encode(), b'000000000']) + before = check_endpoint(2, lengths, program, cases) + after = check_endpoint(2, lengths, detour, cases) + require(after['commands'] == before['commands'] + 2 + and after['interpreter_steps'] == before['interpreter_steps'] + 38, + 'endpoint-preserving movement escaped the price') + return dict(rejected_programs=len(changed), priced_endpoint_preserving_detour=38) + + +def main(): + pins = json.loads((ROOT / 'SOURCE-PINS.json').read_text()) + for row in pins: + raw = (ROOT / row['path']).read_bytes() + require(hashlib.sha256(raw).hexdigest() == row['sha256'], 'source byte pin differs') + require(hashlib.sha1(b'blob ' + str(len(raw)).encode() + b'\0' + raw).hexdigest() + == row['git_blob'], 'source Git blob differs') + circuit = tape.load_source('circuit') + sys.modules['circuit'] = circuit + source = tape.load_source('verify') + source.main() + receipt = json.loads((ROOT / 'RESULT.json').read_text()) + actual, checked = [], {} + for width in (1, 2, 3, 4, 8, 16, 1076): + lengths, program, row = tape.compile_tape(width) + require(len(program) == row['program_bits'] + 2, 'marked program size differs') + require(sum(lengths) == 23 * width + 40, 'data stock differs') + require(row['initialize_bits'] == row['retire_bits'] == 14 * width + 39, + 'work allocation or retirement count differs') + if width in (1, 2, 1076): + cases = source.cases_for(width) + if width == 1: + cases = ((donors, target, diagnostic) for donors in product((-1, 0), repeat=8) + for target in (-1, 0) for diagnostic in (0, 1)) + count = 0 + for batch in batched(cases, 256): + state = check_endpoint(width, lengths, program, batch) + require(state['commands'] == row['commands'] + and state['interpreter_steps'] == row['interpreter_steps'], 'execution bill differs') + count += len(batch) + checked[str(width)] = count + if width == 1076: + require(gzip.decompress((ROOT / 'PROGRAM-1076.bits.gz').read_bytes()) == program, + 'retained program differs from compilation') + require(hashlib.sha256(program).hexdigest() == receipt['program_sha256'], 'program hash differs') + actual.append(row) + require(actual == receipt['width_receipts'] and checked == receipt['executed_cases'], 'receipt differs') + require(mutation_controls() == receipt['controls'], 'control receipt differs') + print('PASS_HALF_SUM_CLEAR_FIXED_TAPE', checked, actual[-1]['interpreter_steps']) + + +if __name__ == '__main__': + main()