diff --git a/research/streaming-gaussian-phase-tariff/PROOF.md b/research/streaming-gaussian-phase-tariff/PROOF.md new file mode 100644 index 0000000000..7dbb312e37 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/PROOF.md @@ -0,0 +1,104 @@ +# Exact phase-scan reduction + +This construction changes the payload execution of the retained PR2250 +Gaussian phase pass. The phase polynomial, tensor convention, address order, +affine word and compact operations stay the same. The source proof remains +the authority for those contracts; this proof covers the new scan and bill. + +## Domain + +A complete declared address rectangle has M records, each with an integral +number of Gaussian coefficients. A coefficient is two b-bit two's-complement +words, real first, in least-significant-bit order, with b>=2. Put V equal to +the complete payload bit count. The source head initially has offset h from +its origin. Phase controls depend only on the current address, with the +retained tensor exponent f*p0+sum_j q(x_j) modulo four. For an inverse pass, +negate this exponent on the recovered input address. Let V_odd be the total +payload volume of records whose phase is odd. + +The result is exact modulo 2^b in each component. It is also exact on signed +Gaussian integers when the usual symmetric headroom prevents overflow. +The most negative two's-complement word is included in the modular theorem; +it is not evidence that signed negation cannot overflow. + +## Scan and correctness + +For phase 0, copy both halves directly to the output. For phase 2, stream +the negation of each half directly. Reset the one-bit carry before each +half. The recurrence starts with carry=1 and emits the low bit of +1-input_bit+carry, then retains its high bit. Induction on the consumed +prefix proves two's-complement negation modulo 2^b. + +For an odd phase, copy the real half into one scratch tape. Stream the +imaginary half directly to output, negating it for phase 1. Rewind scratch +and append the real half, negating it for phase 3. Erase scratch before the +next coefficient. The resulting pairs are (-imag,real) and (imag,-real). +Together with the even cases, these are exactly multiplication by i^phase. + +Every branch consumes exactly one coefficient and appends exactly one +coefficient. It cannot mix record boundaries. Induction over coefficients +and records proves the complete endpoint. Finish and erase the consumed +input, rewind output and return with empty scratch at its origin. No +payload is addressed by an output index. Bulk copy abbreviates consecutive +bit reads and writes; the charge includes every bit. + +The scan uses three payload roles in total: input, output and one real-half +scratch tape. Scratch has peak extent b, independent of the number of +records. The phase counter/arithmetic interface is inherited and separately +charged. The complete monomial wrapper uses the unchanged affine word, +compact operations and inverse chronology, so replacing only this phase +pass preserves its endpoint and ordinary-call inventory. + +## Exact invoice + +The following counts include input erasure, scratch clearing and output +rewind. They apply per R=2b coefficient when h=0. + +| Phase parity | Reads | Writes | Erasures | Moves | Total | +|---|---:|---:|---:|---:|---:| +| even | R | R | R | 6R | 9R | +| odd | 3R/2 | 3R/2 | 3R/2 | 9R | 27R/2 | + +In the odd branch, the extra half is copied to scratch, rewound, read, +rewound again and erased. These actions account for the complete extra +9R/2. The final source erase contributes its head return as well as its +forward erase and return. An initial rewind contributes h once. +Therefore the total is + +```text +new = 9V + (9/2)V_odd + h +old = 18V + h +saving = 9V - (9/2)V_odd. +``` + +The old formula follows by counting both half-scratch paths in the unchanged +source. At h=0, the new payload bill saves at least one quarter and at most +one half. A nonzero initial head adds the same h to both bills; do not apply +the percentage to that extra charge. The number of control evaluations is +still M. No lower bound over all phase implementations is claimed. + +For each actual event8814 right/left fixture, V=32768 and V_odd=16384. +The phase bill decreases from 589824 to 368640, exactly 37.5 percent. +This percentage is for the phase component, not a complete monomial, +recursive caller, runtime benchmark or multiplication exponent. The unchanged +affine/ordinary calls can dominate the full monomial cost. + +## Evidence and remaining costs + +The verifier checks all coefficient pairs of widths 2 through 6 in all four +phases, 768 tensor/polynomial/inverse patterns with nonzero initial heads, +the actual right/left recipes and both complete monomial directions. It also +checks a two-column compact fixture in both directions with arbitrary dirty +compact fields and identical ordinary-call inventories. An independent +integer oracle checks phase values. All measured bills must match exactly. + +Three arithmetic discriminators distinguish inverse phase, missing carry and +missing odd-phase sign. Three malformed extents are executed and rejected. +Finite checks corroborate the scan proof; they are not its all-width basis. + +Descriptor production, encoded phase arithmetic, the complete physical +caller, recursive child, precision and final supplier admission remain open. +This local constant reduction does not change the complete kappa calculation. +It does not replace the separate Word RAM cost model or Gaussian normalization +kernel. New work: Ali Romman with substantial OpenAI Codex assistance, +Apache-2.0. Jose Manuel and the retained source authors keep their credit. diff --git a/research/streaming-gaussian-phase-tariff/README.md b/research/streaming-gaussian-phase-tariff/README.md new file mode 100644 index 0000000000..3a2cc6c8dc --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/README.md @@ -0,0 +1,63 @@ +# Streaming Gaussian phase tariff + +**Local algorithmic improvement; no new kappa.** Use direct streaming for +even Gaussian phases and one real-half scratch tape for odd phases. The +complete payload bill is `9V+(9/2)V_odd+h`, instead of the retained source's +`18V+h`. Here h is the initial head offset and V_odd is the volume with an +odd phase. From origin, this saves 25 to 50 percent of phase payload work. + +The [proof](PROOF.md) covers all valid complete record layouts and coefficient +widths. The unchanged phase polynomial, affine word and compact interpreter +are composed in [phase.py](phase.py). No frozen source file is changed. +The actual event8814 right and left phase passes each save 37.5 percent: +589824 to 368640 transitions. [RESULT.json](RESULT.json) records these values. +This is a component tape invoice, not an end-to-end runtime or kappa gain. + +## Replay + +Use CPython 3.12, standard library only, from the repository root: + +```sh +python3.12 -B scripts/research_package.py --package research/streaming-gaussian-phase-tariff +``` + +Expected status: `PASS_STREAMING_GAUSSIAN_PHASE_TARIFF_NO_NEW_KAPPA`. +The registered hook runs normal and optimized modes and checks source hashes +and a typed exact receipt. Evidence includes 21824 coefficient/phase cases, +768 tensor phase patterns, four actual complete monomial cases, two compact +tensor round trips, three arithmetic discriminators and three input rejections. +Every new result agrees with the unchanged predecessor and an independent +integer phase oracle. All source ordinary calls and control evaluations are +retained. The official export permits a Git-free replay. + +No full supplier, native catalogue replay, encoded-control lowering, Lean, +Docker or selected cold replay was run. Human and formal-kernel review are +unclaimed. The written scan proof supplies the uniform result. The complete +caller, recursive child, precision and supplier budget remain separate. + +## Attribution and scope + +Base `7c472563474e60185e6ca101a17622133d047e56`, priority revision 7. +[SOURCES.json](SOURCES.json) pins consumed files; selected-result and catalogue +files are historical provenance. Jose Manuel/jmbarrancoml supplied the source +scan, affine/compact routines and proof in +[PR #2250](https://github.com/CrocSwap/integer-mult-bounds/pull/2250). +Douglas Colkitt's compact construction remains credited there. JoyboyBrian's +[PR #5327](https://github.com/CrocSwap/integer-mult-bounds/pull/5327) +binds the actual event8814 fixture to Cinna Davis's mixed caller and retained +native/Clifford lineage. The Word RAM phase work in +[PR #4538](https://github.com/CrocSwap/integer-mult-bounds/pull/4538) +and Gaussian normalization in +[PR #3127](https://github.com/CrocSwap/integer-mult-bounds/pull/3127) +are related work with different operations and cost models, not consumed +implementations or new results claimed here. + +Prepared by Ali Romman with substantial OpenAI Codex assistance. New code and +proof: Apache-2.0. Existing source notices remain unchanged. + +## Open next questions + +Lower this scan onto the encoded physical coefficient/Count interface and +charge the phase controls there. Use the exact component bill and preserved +ordinary-call inventory as comparison points. The full caller and recursive +child are required before any complete supplier gain can be claimed. diff --git a/research/streaming-gaussian-phase-tariff/RESULT.json b/research/streaming-gaussian-phase-tariff/RESULT.json new file mode 100644 index 0000000000..d4bd549d21 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/RESULT.json @@ -0,0 +1,27 @@ +{ + "status": "PASS_STREAMING_GAUSSIAN_PHASE_TARIFF_NO_NEW_KAPPA", + "coefficient_cases": 20, + "coefficient_pairs": 21824, + "pattern_cases": 768, + "actual_recipe_phase_receipts": { + "right": { + "volume": 32768, + "odd_volume": 16384, + "new_transitions": 368640, + "old_transitions": 589824, + "output_sha256": "9ef1f647a6725b96633d79231f30f617ff2719b1534628615474cec42b0d8a3e" + }, + "left": { + "volume": 32768, + "odd_volume": 16384, + "new_transitions": 368640, + "old_transitions": 589824, + "output_sha256": "3b5c2bdc4689619fe654625df3a73264f30be479b531d5f8b0f85cc6b23183e5" + } + }, + "actual_monomial_cases": 4, + "compact_tensor_cases": 2, + "controls": 6, + "worst_case_payload_saving": "1/4", + "even_phase_payload_saving": "1/2" +} diff --git a/research/streaming-gaussian-phase-tariff/SOURCES.json b/research/streaming-gaussian-phase-tariff/SOURCES.json new file mode 100644 index 0000000000..4ed36d1f09 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/SOURCES.json @@ -0,0 +1,54 @@ +{ + "schema_version": 1, + "base_commit": "7c472563474e60185e6ca101a17622133d047e56", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "c35482cd9035843b15a634cc8276a7e1e40e8395", + "sha256": "6fe0a099b89aa2aed796a13c3a21dafc63f3388ebf397464e44e0451893b9375" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "f126dd2e2dad2b669e75d1d0d0bd05c600725602", + "sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72" + }, + { + "path": "research/complex-four-base-packet/FIXTURE.json", + "usage": "input", + "git_blob": "4788ef4a4c74847432ad1bb928d736f71245db9d", + "sha256": "25b296e61180c5d2683fef88edb4244faaeb35898ff76c7a8368ca7063a1ca86" + }, + { + "path": "research/complex-four-base-packet/README.md", + "usage": "input", + "git_blob": "2b6caf55cb15a9bdff4ecb2c576de628c93a71cd", + "sha256": "f5653a054a3caa44343aec4f20b180c6c745af7bf1ad7404d77626e7d28fce0e" + }, + { + "path": "research/selected-complex-compact-adapters/PROOF.md", + "usage": "input", + "git_blob": "685efc529493e4b841c1ce8799d28968b4991d7e", + "sha256": "804446e22304540eb02a5f4da3f71464a217be830a33b11420ea31eea878782c" + }, + { + "path": "research/selected-complex-compact-adapters/compact.py", + "usage": "input", + "git_blob": "60bc206c78150f23563a4775800b0dd32025843d", + "sha256": "0e1027a60f38c21cfd808c8ce44dcc2423810efdab0e15f02b07f261ad48fc3c" + }, + { + "path": "research/selected-complex-compact-adapters/monomial.py", + "usage": "input", + "git_blob": "5fa4494167c4ba668993a2b1c902969518728a4c", + "sha256": "394f9a465ac9148af0c20844d375e4befbef17d92b2fcc840d83419480dd4740" + }, + { + "path": "research/selected-complex-compact-adapters/streams.py", + "usage": "input", + "git_blob": "61542ce4c9eb51bfc113475b4f98649cb90a853e", + "sha256": "718a582a50aee8f1f04945ed942be1d4162962fe47dbf05c6ff37b7fb8c61257" + } + ] +} diff --git a/research/streaming-gaussian-phase-tariff/TASK.json b/research/streaming-gaussian-phase-tariff/TASK.json new file mode 100644 index 0000000000..58879ec7f9 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/TASK.json @@ -0,0 +1,78 @@ +{ + "schema_version": 1, + "task_id": "uniform-transfer-audit", + "priority_revision": 7, + "base_commit": "7c472563474e60185e6ca101a17622133d047e56", + "original_card": { + "id": "uniform-transfer-audit", + "question": "Does one quantified step of the proposed #4100 all-size construction hold at its actual caller?", + "starting_points": [ + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "research/unconditional-batched-crt/README.md" + ], + "methods": [ + "Prove one missing implication with explicit quantified hypotheses.", + "Find an exact counterexample at the claimed interface boundary." + ], + "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_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read PROOF.md and AUDIT.md in #4100. Select one distinct obligation: CRT total repair, native/free-algebra lifting, precision/conditioning, or complete fixed-tape cost. This is an author-submitted proof, not an accepted unconditional theorem.", + "scope": "Source-binding orientation only; no scientific replay, theorem acceptance or supplier admission. Budget any heavy replay separately." + }, + "first_experiment": "Check live handoffs; name one proposition, its caller, quantified domain and dependency closure. Independently prove the implication or exhibit a precise gap/counterexample. Prioritize CRT.md total repair or COMPLEX.md free-algebra lift only if unclaimed. Stop at the chosen obligation; do not substitute finite samples or root arithmetic for an all-size proof, or launch the complete package by default.", + "bottleneck_link": "Finite supplier improvements are useful only under the retained transfer obligations.", + "allowed_variations": [ + "One CRT repair, native lift, precision/conditioning or tape-cost proposition, with its exact caller." + ], + "scope_change_triggers": [ + "Replacing a quantified obligation with another finite smoke test.", + "Treating archive intake, an author PASS receipt or a finite composed fixture as discharge of the universal hypotheses." + ], + "overlap_terms": [ + "uniform transfer", + "all-size", + "precision", + "4100", + "unconditional-batched-crt" + ], + "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_status": "changed", + "actual_scope": "An exact lower-cost sequential Gaussian phase scan and source monomial composition.", + "scope_change_reason": "Replace two unconditional half-scratch paths with direct even phases and one odd-phase scratch path; a scoped local implementation improvement.", + "bottleneck_link": "Reduces paid payload work in the actual monomial adapter, without claiming a complete supplier or asymptotic gain.", + "budget_minutes": 60, + "stop_rule": "Finish exact scan correctness and tariff; do not expand into encoded control or full supplier work.", + "outcome": "completed", + "evidence": "PROOF.md, RESULT.json, exhaustive small coefficients, mixed tensor patterns, actual complete monomials and compact composition.", + "author": "Ali Romman", + "ai_assistance": "Substantial OpenAI Codex assistance; independent human and proof-kernel review unclaimed.", + "open_questions": [ + { + "question": "Can this scan be lowered to encoded physical controls with the same bill?", + "why_it_matters": "The current address/control interface is inherited and separately charged.", + "first_step": "Bind one actual coefficient/Count traversal and charge its phase controls.", + "blocked_by": "Full caller, recursive child and complete supplier pricing." + } + ], + "coordination": { + "claim": "https://github.com/CrocSwap/integer-mult-bounds/discussions/2238#discussioncomment-19153519", + "overlap": "318 open PRs, 4648 Discussion records, all 7267 main notes and targeted all-state searches; arbitrary diffs and unpublished work not covered." + } +} diff --git a/research/streaming-gaussian-phase-tariff/VERIFY.json b/research/streaming-gaussian-phase-tariff/VERIFY.json new file mode 100644 index 0000000000..119e078301 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/VERIFY.json @@ -0,0 +1,41 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/complex-four-base-packet/FIXTURE.json", + "research/complex-four-base-packet/README.md", + "research/selected-complex-compact-adapters/PROOF.md", + "research/selected-complex-compact-adapters/compact.py", + "research/selected-complex-compact-adapters/monomial.py", + "research/selected-complex-compact-adapters/streams.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact phase values and invoices, source monomial endpoints, compact composition, source hashes and typed receipt." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact phase values and invoices, source monomial endpoints, compact composition, source hashes and typed receipt." + } + ] +} diff --git a/research/streaming-gaussian-phase-tariff/phase.py b/research/streaming-gaussian-phase-tariff/phase.py new file mode 100644 index 0000000000..938502e3f3 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/phase.py @@ -0,0 +1,70 @@ +"""Stream Gaussian phases with at most one coefficient half in scratch. + +Ali Romman with OpenAI Codex assistance. Apache-2.0. +The affine/compact composition follows Jose Manuel's retained PR2250 code. +""" +from pathlib import Path +import sys +SOURCE = Path(__file__).resolve().parents[1] / "selected-complex-compact-adapters" +sys.path.insert(0, str(SOURCE)) +from streams import Tape, need, copy, digit_permutation, flip_digit +from compact import Compact, execute +from monomial import tensor_phase, binary_word + + +def phase_pass(source, layout, recipe, f, K, rho, coefficient_bits, inverse=False): + need(coefficient_bits >= 2 and layout.record_bits % (2 * coefficient_bits) == 0, + "Gaussian record extent") + need(len(source.data) == layout.records * layout.record_bits, "complete record rectangle") + source.rewind() + out, real = Tape(source.meter), Tape(source.meter) + def emit(tape, negative): + if not negative: + copy(tape, out, coefficient_bits) + else: + carry = 1 + for _ in range(coefficient_bits): + value = 1 - tape.read(1)[0] + carry + out.write(bytes((value & 1,))) + carry = value >> 1 + for index in range(layout.records): + phase = tensor_phase(recipe, layout.decode(index), f, K, rho) + if inverse: + phase = -phase % 4 + source.meter.control_evaluations += 1 + for _ in range(layout.record_bits // (2 * coefficient_bits)): + if phase % 2 == 0: + emit(source, phase == 2) + emit(source, phase == 2) + else: + copy(source, real, coefficient_bits) + emit(source, phase == 1) + real.rewind() + emit(real, phase == 3) + real.finish(); real.erase() + source.finish(); source.erase(); out.rewind() + need(not real.data and real.head == 0, "phase scratch not retired") + return out + + +def execute_monomial(source, layout, recipe, f, K, G, rho, coefficient_bits, inverse=False): + """Use the unchanged affine word and compact operations with this phase pass.""" + need(f >= 1, "positive tensor width") + word = binary_word(recipe) + if not inverse: + source = phase_pass(source, layout, recipe, f, K, rho, coefficient_bits) + for kind, i, k in reversed(word) if inverse else word: + target = "v" + str(i) + control = None if kind == "flip" else "v" + str(k) + if f > 1: + source = execute(source, layout, Compact(f-1, K, G, rho, control, target, + False if control is None else k > i)) + elif control is None: + source = flip_digit(source, layout.bits, layout.position(target, rho), layout.record_bits) + else: + a, b = layout.position(control, rho), layout.position(target, rho) + mapping = (0, 1, 3, 2) if a < b else (0, 3, 2, 1) + source = digit_permutation(source, layout.bits, min(a,b), max(a,b), layout.record_bits, mapping) + if inverse: + source = phase_pass(source, layout, recipe, f, K, rho, coefficient_bits, True) + return source diff --git a/research/streaming-gaussian-phase-tariff/verify.py b/research/streaming-gaussian-phase-tariff/verify.py new file mode 100644 index 0000000000..68865d6275 --- /dev/null +++ b/research/streaming-gaussian-phase-tariff/verify.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python3 +"""Compare exact coefficient values, source endpoints and complete tape invoices.""" +from hashlib import sha256 +from itertools import product +import json +from pathlib import Path +import sys +HERE=Path(__file__).resolve().parent +ROOT=HERE.parents[1] +sys.path.insert(0,str(HERE)) +import phase +from streams import Tape,Meter,need +from compact import Layout +import monomial as old + + +def units(m):return m.reads+m.writes+m.moves+m.erases + + +def encode(pair,b):return bytes((x>>i)&1 for x in pair for i in range(b)) + + +def decode(raw,b):return tuple(sum(bit<>(rho+j*K))&1 for i in range(len(recipe["matrix_rows"]))] + result+=sum(a*x for a,x in zip(recipe["linear_Z4"],bits)) + result+=2*sum(bits[i]*bits[k] for i in range(len(bits)) for k in range(i+1,len(bits)) + if recipe["quadratic_rows"][i]>>k&1) + return result%4 + + +def phase_case(layout,recipe,f,K,rho,b,raw,inverse=False,head=0): + new_meter,old_meter=Meter(),Meter() + new_input,old_input=Tape(new_meter,raw),Tape(old_meter,raw) + new_input.head=old_input.head=head + new=phase.phase_pass(new_input,layout,recipe,f,K,rho,b,inverse) + prior=old.phase_pass(old_input,layout,recipe,f,K,rho,b,inverse) + expected=bytearray();odd=0 + for i in range(layout.records): + k=independent_phase(recipe,layout.decode(i),f,K,rho) + if inverse:k=-k%4 + odd+=(k%2)*layout.record_bits + for j in range(layout.record_bits//(2*b)): + at=i*layout.record_bits+j*2*b + expected.extend(encode(rotate(decode(raw[at:at+2*b],b),k,b),b)) + need(new.data==prior.data==expected,"phase endpoint disagreement") + need(not new_input.data and not old_input.data and new.head==prior.head==0,"retirement or head failure") + V=len(raw) + need(units(new_meter)==9*V+9*odd//2+head,"new exact tariff") + need(units(old_meter)==18*V+head,"source exact tariff") + need(new_meter.control_evaluations==old_meter.control_evaluations==layout.records, + "control coverage changed") + return {"volume":V,"odd_volume":odd,"new_transitions":units(new_meter), + "old_transitions":units(old_meter),"output_sha256":sha256(new.data).hexdigest()} + + +def replay(): + for item in json.loads((HERE/"SOURCES.json").read_text())["files"]: + if item["usage"]=="input":need(sha256((ROOT/item["path"]).read_bytes()).hexdigest()==item["sha256"],"source hash mismatch") + coefficient_pairs=cases=0 + for b in range(2,7): + pairs=list(product(range(1<