diff --git a/research/positive-frame-subset-join/BENCHMARK.json b/research/positive-frame-subset-join/BENCHMARK.json new file mode 100644 index 0000000000..dc73240a23 --- /dev/null +++ b/research/positive-frame-subset-join/BENCHMARK.json @@ -0,0 +1,117 @@ +{ + "environment": { + "cores": 18, + "executable": "/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12", + "load_average_at_finish": [ + 5.43017578125, + 3.62109375, + 3.080078125 + ], + "platform": "macOS-27.0.1-arm64-arm-64bit", + "python": "3.12.15 (main, Oct 14 2026, 00:55:37) [Clang 23.1.3 ]" + }, + "errors": 0, + "implementation_sha256": { + "SOURCES.json": "4b6b36c69d72135b80a7e4359af28bd80cc2098bf8475ba8d5214cde0c0a6194", + "benchmark.py": "2485364ad607abb9ea2d0895235ff1d4422b1864c7a6e601133e9accc76d2eaf", + "fast_support.py": "9fd50dcbd54aaffb2e2f84c1357b7937d9e4c3cec3c0f243428efd3ee0bd383c", + "run.py": "7c48db5e75352713e9d4900d9b3fe1feabaccdafee425d9262f53c78e467b99b" + }, + "pairs": 5, + "runs": [ + { + "elapsed_ns": 30160228625, + "mode": "baseline", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 8189630625, + "mode": "accelerated", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 28718976666, + "mode": "baseline", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 8254057875, + "mode": "accelerated", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 30836784042, + "mode": "baseline", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 8290262334, + "mode": "accelerated", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 29031493791, + "mode": "baseline", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 8377977166, + "mode": "accelerated", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 28521156625, + "mode": "baseline", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + }, + { + "elapsed_ns": 8393955666, + "mode": "accelerated", + "returncode": 0, + "stderr_bytes": 0, + "stdout_bytes": 787, + "stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c" + } + ], + "saved_fraction": 0.7144390022200632, + "schema_version": 1, + "summary": { + "accelerated": { + "maximum_ns": 8393955666, + "median_ns": 8290262334, + "minimum_ns": 8189630625 + }, + "baseline": { + "maximum_ns": 30836784042, + "median_ns": 29031493791, + "minimum_ns": 28521156625 + } + } +} diff --git a/research/positive-frame-subset-join/PROOF.md b/research/positive-frame-subset-join/PROOF.md new file mode 100644 index 0000000000..c0239aca73 --- /dev/null +++ b/research/positive-frame-subset-join/PROOF.md @@ -0,0 +1,121 @@ +# Equivalence of the integer subset join + +This contribution was produced by Nick Petalas. Apache-2.0. + +## Predicate + +Let L_0,...,L_5 and H_0,...,H_3 be rational triples. Let c_0,...,c_5 be +nonnegative integer multiplicities. The predicate required for each target H is + + H in {sum_i u_i L_i : 0 <= u_i <= c_i, u_i integer}. + +This is membership in a set of possible exponents. It is not a count of +representations or a sum of coefficients modulo two. Repeated labels and +cancellation of different representations must preserve existential membership. +The predecessor uses precisely this predicate in its concrete regression. + +The implementation accepts six labels, four targets, three coordinates, +sum c_i <= 8, and rational numerators and denominators of at most 256 bits. +The algebraic equivalence below holds without these finite resource bounds. + +## Integer join + +Take D to be the least common multiple of every denominator in the six labels +and four targets. In particular, target denominators participate. Multiplication +by the positive integer D is injective on rational triples and maps all ten +vectors to integer triples. Define + + O = {sum_(i=0..3) u_i D L_i : 0 <= u_i <= c_i}, + N = {sum_(i=4..5) u_i D L_i : 0 <= u_i <= c_i}. + +The full scaled subset set is exactly O+N. Every six-tuple of multiplicities +splits into one four-tuple and one two-tuple, and every such pair recombines +into a legal six-tuple. Consequently + + H is in the original set iff some n in N has D H - n in O. + +`integer_vectors`, `subset_sums` and `support_mask` implement these three +operations using exact Python integers. Sets remove duplicate values on both +sides of the equivalence. Negative coordinates, zero counts, repeated labels +and targets with denominators absent from the labels require no exceptions. +No parity reduction, rounding, probabilistic hash or numerical tolerance is used. + +## Complete replay adapter + +`run.py` authenticates the exact predecessor source and every declared external +input before compiling that source. A fresh module has the predecessor's actual +file path, so its own input authentication uses the original repository layout. +The baseline calls its unchanged `main`. The accelerated mode replaces only its +`direct_support_regression` function. + +The replacement preserves the original outer profile order, the direction grid, +primitive-direction filter, sorted rational scale set, rank-one checks, target +conjunction, exact-lattice test for each support survivor, and returned counters. +`concrete_splits` copies the original inventory construction, credited to Josie +Elliston. Its only extracted responsibility is emitting the same concrete labels. +The proved join replaces the full rational subset-set expression. All other +functions, symbolic support classification, source checks, eight-call control, +target mutation and denominator control execute their original source bytes. +`source.TARGETS` is read at each predicate call; no result cache can retain an old +target or split. Unknown source revisions fail authentication. + +Under successful execution and the authenticated source's stated domain, every +concrete support decision and every subsequent lattice call therefore agrees. +The complete output agrees as well. This is a scoped program-equivalence +argument. It neither reproves nor independently accepts the predecessor theorem. + +## Finite corroboration and performance boundary + +`verify.py` compares every four-bit support mask in the complete concrete +inventory with a separately written literal Fraction enumeration, then executes +the complete accelerated predecessor command. It also checks small rational +fixtures and input/source rejections. `RESULT.json` is generated by that command; +it binds the implementation and input manifest by SHA256. Default replay checks +the receipt and writes no files. + +`benchmark.py` starts a fresh complete process for each side in five or more +alternating pairs. Timing includes source authentication, imports, every check, +captured output and process completion. Every return code, stderr and complete +stdout is checked. It records individual nanosecond timings, environment and +code hashes. It does not reuse subset results across processes. Profiling is a +separate diagnostic run, excluded from the reported timings. Hosted conformance +does not certify a local machine's performance percentage. + +## Resource bounds and implementation constraints + +The four old-label subset loops have at most 81 iterations, and the two added +loops at most 25, by the total-multiplicity bound of eight. Each target checks at +most 25 integer differences. Denominator clearing visits exactly 30 coordinates. +There are at most 442 profiles; each profile's scale generator has at most +sum_(m=2..40)(m-1)=780 iterations, or at most 17*9 direction candidates. The +generic conformance grid has 4^6 candidate multiplicities. Benchmarking permits +five through nine pairs, with a 300-second timeout per complete process. + +New code has no recursion, persistent cache, network call or background process. +All new functions fit within 60 lines. Explicit exceptions retain checks under +optimized Python. Warning-strict normal and optimized execution and AST parsing +are the diagnostics; no separate static type analyzer is claimed. + +Power-of-ten rule 3 deviation: CPython allocates integers, Fractions, sets and +modules dynamically. The new join has at most 106 stored subset triples, with +integer bit lengths below 8192 under its enforced generic input bound. The +concrete generator stores at most 780 splits at a time. Source files are capped +at one MiB each. Runtime allocation internals are not instrumented. A fixed +allocation implementation is required before using this reference in an +allocation-prohibited runtime. + +Rules 8 and 9 deviation: the adapter executes one hash-authenticated predecessor +module and calls its fixed helper functions. This is required to run the actual +unchanged complete checker without editing frozen evidence. No CLI-supplied +code or module name is accepted. All external source paths are declared in +VERIFY.json and authenticated. A future different source requires a new pin and +equivalence assessment. The predecessor's preexisting lattice loops and long +`main` remain frozen; this package makes no new resource-compliance claim about +that retained implementation. + +The verifier's complete reference enumeration intentionally uses Fractions to +avoid depending on the proposed denominator-clearing mechanism. It has at most +144 multiplicity tuples per concrete split under the source's total bound of +seven, and uses the same finite split inventory. This extra conformance work is +verification overhead; it is not included as part of the accelerated scientific +command being compared with the original scientific command. diff --git a/research/positive-frame-subset-join/README.md b/research/positive-frame-subset-join/README.md new file mode 100644 index 0000000000..268343d74b --- /dev/null +++ b/research/positive-frame-subset-join/README.md @@ -0,0 +1,122 @@ +# Complete positive-frame replay in less time + +This contribution was produced by Nick Petalas. Apache-2.0. + +Claim type: **measured verifier improvement with a scoped equivalence proof +and finite conformance checks**. No new kappa is claimed. + +An exact integer subset join reduces the complete PR #6111 command's local +median elapsed time from 29.031 s to 8.290 s, **71.4% less**. +All ten fresh commands emit the same 787 bytes, with zero errors. The frozen +predecessor checker and its mathematical result remain Josie Elliston's work. +This package contributes the accelerator, its equivalence proof and measurement. + +| Complete command | Median | Range | Runs | +| --- | ---: | ---: | ---: | +| Original predicates | 29.031 s | 28.521–30.837 s | 5 | +| Integer subset join | 8.290 s | 8.190–8.394 s | 5 | + +[BENCHMARK.json](BENCHMARK.json) is generated by five alternating baseline/fast +pairs on CPython 3.12.15, macOS arm64. Timing includes fresh process startup, +source authentication, all original checks and controls, output and exit. +Other processes were active on this 18-core host. This is a single-host result, +not a cross-platform performance guarantee or a new mathematical bound. + +## What changes + +The concrete scan originally constructs every rational six-label subset sum. +The new calculation clears all label **and target** denominators once, builds +integer subset sets for four old labels and two added labels, then tests +membership by subtraction. The inventory, rank-one checks, exact lattice +filters, source checks and remaining complete command execute unchanged. +A separate profile placed 84.219 of 102.461 instrumented seconds in the concrete +scan. The instrumented run is excluded from the benchmark. Repeated Fraction +multiplication and addition were the measured bottleneck. + +[PROOF.md](PROOF.md) proves the membership equivalence, including repeated +labels, negative coordinates, zero multiplicities and different target +denominators. `run.py` authenticates the fixed external source bytes before +compiling them. It changes one function in a fresh module. No source file or +persistent cache is changed, and a changed input fails its source pin. + +## Evidence + +The generated [RESULT.json](RESULT.json) binds the new implementation and input +manifest. The verifier compares all four target decisions on **46,916 concrete +splits** against a separately written literal Fraction enumeration. Those are +conformance cases for the new implementation, not a new predecessor census. +It also checks 420 small rational cases and seven input/source rejections, +then runs the complete accelerated source checker and checks its full output. +Normal and optimized verification are registered in VERIFY.json. + +The complete output SHA256 is +`429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c`. +Every timed output has that hash. No non-success command is included as a fast +sample. The generator records every return code, stderr length and elapsed time. +The standard join technique itself is not claimed as a new algorithm. + +## Reproduce + +From the repository root, using CPython 3.12 and the standard library: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -W error -B research/positive-frame-subset-join/run.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -W error -B research/positive-frame-subset-join/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -O -W error -B research/positive-frame-subset-join/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/positive-frame-subset-join +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/positive-frame-subset-join --check-source-history +``` + +Another machine can substitute its CPython 3.12 path. Add `--baseline` to run.py +for the original predicates. To rerun the timing experiment, use `benchmark.py +--pairs 5 --output PATH` with a chosen output path outside the checkout. The +benchmark is opt-in; CI runs conformance rather than asserting a machine speed. +The standalone adapter and verifier also work in the official Git-free export +with the declared inputs. Receipt regeneration is explicit `verify.py --write +PATH`; default replay writes nothing. + +## Scope, sources and limits + +The replay-runtime card is refined to an original exact-support performance +question. [Advance claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19267812). +Base main is `3f0152a32eeebac0df11946dbd50cabe5a7f7839`, priority revision 8. +The current selected source-binding orientation passed; no selected scientific +cold replay was run. SOURCES.json pins the original source and its complete +runtime input closure. Frozen predecessor files are unchanged. + +Live open PRs, recent claims and local reservations, all 373 account PRs in the +prior seven days, distinctive main README terms and merged searches were +inspected. The overlap helper covered all 318 open PRs and 5,870 Discussion +records, but only 81 of 8,567 local note records. This is bounded overlap +coverage, not proof of novelty or coverage of unpublished work. No same-checker +performance target was found. This work does not extend this account's earlier +endpoint theorems or use another package's open question as its target. + +The equivalence statement concerns successful execution of this exact checker +on its fixed domain. It supplies no new positive-frame theorem, native word, +physical supplier, compiler/precision/ownership proof or multiplication theorem. +The predecessor's scientific review status is inherited. Independent human and +formal proof-kernel review are unclaimed. No Lean, Docker, historical full suite +or selected supplier replay was run. Managed-allocation and fixed authenticated +module-execution deviations are recorded in PROOF.md. + +## Open next questions + +The unchanged symbolic support stage may warrant a separate integer formulation. +First profile the complete accelerated command and define that stage's exact +return-value contract. A separate implementation and measurement are required; +no such improvement or follow-on reservation is claimed here. + +## Credit + +Josie Elliston's [PR #6111](https://github.com/CrocSwap/integer-mult-bounds/pull/6111) +supplies the theorem, source checker, concrete split inventory and existing +controls. Its retained head is `961b749fa40a1117d0746064528d2dfa290c57e0`. +JoyboyBrian's handoff #6104 supplies the underlying two-frame question and +parameterization; apoursh's #6089 supplies the one-frame classification and +symmetries. Cinna Davis supplies the PR2085/2112 model; Philippe Van Velzen +supplies the earlier eight-call floor; Nick Petalas supplies the determinant +method. Retain the BIT and formal-model lineage credited in those sources. +Their original notices are unchanged. Denominator clearing and subset joining +are standard techniques; the new contribution is their source-bound integration, +coverage argument and complete-command performance evidence. diff --git a/research/positive-frame-subset-join/RESULT.json b/research/positive-frame-subset-join/RESULT.json new file mode 100644 index 0000000000..4e5bedfe59 --- /dev/null +++ b/research/positive-frame-subset-join/RESULT.json @@ -0,0 +1,16 @@ +{ + "benchmark_pairs": 5, + "complete_stdout_sha256": "429df60e41b623420af1af7119a0734a6686e3a0b4bd75e360317ea3b8efe15c", + "implementation_sha256": { + "BENCHMARK.json": "d52d116955011550bc1f7908e179018f671e16192d42e263e3f901e023d0a59f", + "SOURCES.json": "4b6b36c69d72135b80a7e4359af28bd80cc2098bf8475ba8d5214cde0c0a6194", + "fast_support.py": "9fd50dcbd54aaffb2e2f84c1357b7937d9e4c3cec3c0f243428efd3ee0bd383c", + "run.py": "7c48db5e75352713e9d4900d9b3fe1feabaccdafee425d9262f53c78e467b99b", + "verify.py": "2bbdde2ef2d7d3f40be79424da6dc94ac9babfedd97318ee1c99c987cc35f482" + }, + "mask_sha256": "c55f7be3beb1c63e74d8b78473c2ec6fea526a15adaf4ac6c9030bff38a4136c", + "rejections": 7, + "small_cases": 420, + "source_sha256": "7d68cce0cdd09c1e6afb7dc2b78e298b6f5c92ad39958e3a79f5d53e8377f5e1", + "split_masks_compared": 46916 +} diff --git a/research/positive-frame-subset-join/SOURCES.json b/research/positive-frame-subset-join/SOURCES.json new file mode 100644 index 0000000000..f8c668bef2 --- /dev/null +++ b/research/positive-frame-subset-join/SOURCES.json @@ -0,0 +1,42 @@ +{ + "schema_version": 1, + "base_commit": "3f0152a32eeebac0df11946dbd50cabe5a7f7839", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "d59b5035e7b4cbaa9d688a1d32dd0d6eb79c466a", + "sha256": "9b8d0eea95b3bf0dfcb7938a732a6439b87a2685dec2a5ab9e525b3b34debbfa" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/bit-fifth-frame-determinant-obstruction/README.md", + "usage": "input", + "git_blob": "608a24af8bc3d27ee1554c94872601bb3a409f67", + "sha256": "fa3f0f951146caa5b1eb7b7417175eb7a380cae8674e4a470407517dac40f227" + }, + { + "path": "research/bit-two-positive-frames-seven-call/README.md", + "usage": "input", + "git_blob": "98eb6718d0ae424c129cf08b186fd2a5593ca783", + "sha256": "8832e843b129a1fc802e1f0db54d6f731eb9bd7b2b82f583c7809dbd9c0857d5" + }, + { + "path": "research/bit-two-positive-frames-seven-call/SOURCES.json", + "usage": "input", + "git_blob": "71e4b3eeded06a3a2586935d331b3599fdcd7aad", + "sha256": "aaf779f02dc63857c326bebce240240c0ac13f8b9ba8d3723e1c9a2c9a7a8e5c" + }, + { + "path": "research/bit-two-positive-frames-seven-call/verify.py", + "usage": "input", + "git_blob": "9603a845bd1f7cf1f34d7e4fb7c599edf3bef1e2", + "sha256": "7d68cce0cdd09c1e6afb7dc2b78e298b6f5c92ad39958e3a79f5d53e8377f5e1" + } + ] +} diff --git a/research/positive-frame-subset-join/TASK.json b/research/positive-frame-subset-join/TASK.json new file mode 100644 index 0000000000..d31a52090d --- /dev/null +++ b/research/positive-frame-subset-join/TASK.json @@ -0,0 +1,62 @@ +{ + "schema_version": 1, + "task_id": "replay-runtime", + "priority_revision": 8, + "base_commit": "3f0152a32eeebac0df11946dbd50cabe5a7f7839", + "original_card": { + "id": "replay-runtime", + "question": "Can one measured replay bottleneck be sped up without dropping coverage?", + "starting_points": [ + "scripts/run_isolated_tests.py", + "scripts/verify_replay_coverage.py", + "certificates/selected-result.json" + ], + "methods": [ + "Profile one isolated replay and optimize the measured bottleneck.", + "Design source-bound reuse with explicit dependency invalidation and negative controls." + ], + "acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.", + "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": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.", + "bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.", + "allowed_variations": [ + "Profile one stage or design one source-bound cache boundary." + ], + "scope_change_triggers": [ + "Skipping coverage or comparing different fixtures to claim speedup." + ], + "overlap_terms": [ + "replay runtime", + "cache invalidation", + "isolated tests" + ] + }, + "scope_status": "refined", + "actual_scope": "Accelerate the complete frozen PR6111 replay by replacing its concrete rational subset-set expansion with an exact integer meet-in-the-middle support join; retain every split, target predicate, lattice check, existing control and complete output.", + "scope_change_reason": "Original verifier-engineering question on the replay-runtime card. This is a performance mechanism, not a theorem extension or audit of the predecessor.", + "bottleneck_link": "The measured concrete subset scan dominates a complete exact BIT obstruction replay. Reducing this cost improves future mechanism-screening throughput without changing mathematical acceptance.", + "budget_minutes": 60, + "stop_rule": "Ship the first complete-command speedup exceeding five-pair timing noise with exact output and full concrete support-mask agreement; otherwise hand off the negative performance finding.", + "outcome": "completed", + "evidence": "Generated five-pair benchmark: 71.4% less complete-command median elapsed time, 10 identical successful outputs. Exact agreement on 46916 concrete four-target support masks, 420 small rational fixtures and seven rejections. Written predicate-equivalence proof. No new mathematical endpoint theorem.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Can the unchanged symbolic support-classification stage benefit from a separate exact integer formulation?", + "why_it_matters": "It may become the dominant cost after the concrete scan is accelerated.", + "first_step": "Profile the complete accelerated command and state a distinct equivalence contract before changing that stage.", + "blocked_by": "No such implementation or measurement is supplied here." + } + ], + "coordination_url": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19267812" +} diff --git a/research/positive-frame-subset-join/VERIFY.json b/research/positive-frame-subset-join/VERIFY.json new file mode 100644 index 0000000000..b95bd5f500 --- /dev/null +++ b/research/positive-frame-subset-join/VERIFY.json @@ -0,0 +1,37 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/bit-fifth-frame-determinant-obstruction/README.md", + "research/bit-two-positive-frames-seven-call/README.md", + "research/bit-two-positive-frames-seven-call/SOURCES.json", + "research/bit-two-positive-frames-seven-call/verify.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 300, + "checks": "Exact generic rational support controls, all concrete support masks compared with independent literal Fraction enumeration, authenticated complete accelerated predecessor replay and generated receipt." + }, + { + "argv": [ + "{python}", + "-O", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 300, + "checks": "Same complete conformance and replay with Python assertions disabled." + } + ] +} diff --git a/research/positive-frame-subset-join/benchmark.py b/research/positive-frame-subset-join/benchmark.py new file mode 100644 index 0000000000..20c4e903d1 --- /dev/null +++ b/research/positive-frame-subset-join/benchmark.py @@ -0,0 +1,73 @@ +"""Time complete authenticated commands. Produced by Nick Petalas, Apache-2.0.""" + +import argparse +import hashlib +import json +import os +from pathlib import Path +import platform +import statistics +import subprocess +import sys +import time + + +PACKAGE = Path(__file__).resolve().parent + + +def one(mode, expected): + command = [sys.executable, "-W", "error", "-B", str(PACKAGE / "run.py")] + if mode == "baseline": + command.append("--baseline") + started = time.perf_counter_ns() + child = subprocess.run(command, capture_output=True, timeout=300, check=False) + elapsed = time.perf_counter_ns() - started + if child.returncode != 0 or child.stderr: + raise RuntimeError(f"{mode} failed: {child.returncode}, {child.stderr!r}") + if expected is not None and child.stdout != expected: + raise RuntimeError("complete command stdout changed") + if not child.stdout.endswith(b"positive rank-one frames\n"): + raise RuntimeError("complete command did not finish") + return ({"mode": mode, "elapsed_ns": elapsed, "returncode": child.returncode, + "stdout_bytes": len(child.stdout), "stderr_bytes": len(child.stderr), + "stdout_sha256": hashlib.sha256(child.stdout).hexdigest()}, child.stdout) + + +def benchmark(pairs): + if not 5 <= pairs <= 9: + raise ValueError("use five through nine alternating pairs") + runs = [] + expected = None + for _ in range(pairs): + for mode in ("baseline", "accelerated"): + run, expected = one(mode, expected) + runs.append(run) + print(json.dumps(run), flush=True) + summary = {} + for mode in ("baseline", "accelerated"): + values = [r["elapsed_ns"] for r in runs if r["mode"] == mode] + summary[mode] = {"median_ns": statistics.median(values), + "minimum_ns": min(values), "maximum_ns": max(values)} + before, after = (summary[m]["median_ns"] for m in ("baseline", "accelerated")) + return {"schema_version": 1, "pairs": pairs, "errors": 0, "runs": runs, + "summary": summary, "saved_fraction": 1 - after / before, + "environment": {"python": sys.version, "executable": sys.executable, + "platform": platform.platform(), "cores": os.cpu_count(), + "load_average_at_finish": list(os.getloadavg())}, + "implementation_sha256": { + name: hashlib.sha256((PACKAGE / name).read_bytes()).hexdigest() + for name in ("fast_support.py", "run.py", "benchmark.py", "SOURCES.json")}} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--pairs", type=int, default=5) + parser.add_argument("--output", type=Path, required=True) + args = parser.parse_args() + result = benchmark(args.pairs) + args.output.write_text(json.dumps(result, indent=2, sort_keys=True) + "\n") + print(json.dumps(result["summary"], sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/research/positive-frame-subset-join/fast_support.py b/research/positive-frame-subset-join/fast_support.py new file mode 100644 index 0000000000..6c775b440a --- /dev/null +++ b/research/positive-frame-subset-join/fast_support.py @@ -0,0 +1,80 @@ +"""Exact integer subset joins. Produced by Nick Petalas, Apache-2.0.""" + +from fractions import Fraction +from itertools import product +from math import gcd, lcm + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def integer_vectors(vectors): + """One injective denominator clearing for all labels and targets.""" + require(len(vectors) == 10, "six labels and four targets required") + denominator = 1 + for vector in vectors: + require(len(vector) == 3, "three coordinates required") + for value in vector: + require(type(value) in (int, Fraction), "exact rational required") + value = Fraction(value) + require(max(value.numerator.bit_length(), value.denominator.bit_length()) + <= 256, "rational exceeds 256-bit input bound") + denominator = lcm(denominator, value.denominator) + return tuple(tuple(Fraction(value).numerator + * (denominator // Fraction(value).denominator) + for value in vector) for vector in vectors) + + +def subset_sums(vectors, counts): + """At most 81 old-label or 25 added-label integer triples.""" + return {tuple(sum(u[j] * vectors[j][axis] for j in range(len(counts))) + for axis in range(3)) + for u in product(*(range(count + 1) for count in counts))} + + +def support_mask(counts, labels, targets): + require(len(counts) == 6, "six multiplicities required") + require(all(type(count) is int and 0 <= count <= 8 for count in counts) + and sum(counts) <= 8, "total multiplicity must be at most eight") + require(len(labels) == 6 and len(targets) == 4, "wrong label or target count") + vectors = integer_vectors(tuple(labels) + tuple(targets)) + old = subset_sums(vectors[:4], counts[:4]) + added = subset_sums(vectors[4:6], counts[4:]) + return tuple(any(tuple(target[i] - value[i] for i in range(3)) in old + for value in added) for target in vectors[6:]) + + +def concrete_splits(source, profiles, grid=8): + """PR6111's concrete split inventory, in its original order.""" + require(len(profiles) <= 442 and type(grid) is int and 1 <= grid <= 8, + "concrete inventory exceeds the frozen replay bounds") + for counts, residual in profiles: + r, s = counts[4:] + if source.det(residual) > 0: + splits = [source.split_from_direction(residual, x, y) + for x in range(-grid, grid + 1) for y in range(grid + 1) + if gcd(x, y) == 1 and not (y == 0 and x != 1)] + else: + splits = sorted({source.sc(Fraction(k, m), residual) + for m in range(2, 41) for k in range(1, m)}) + for split in splits: + left = source.sc(Fraction(1, r), split) + right = source.sc(Fraction(1, s), + source.add(residual, source.sc(-1, split))) + if not (source.psd_rank1(left) and source.psd_rank1(right)): + raise SystemExit("FAIL: concrete split") + yield counts, left, right + + +def direct_support_regression(source, profiles, grid=8): + """Adapt PR6111's loop, changing only the subset-support predicate.""" + tested = passed = 0 + for counts, left, right in concrete_splits(source, profiles, grid): + tested += 1 + if all(support_mask(counts, source.OLD + (left, right), source.TARGETS)): + passed += 1 + if not source.lattice_killers(counts, left, right): + raise SystemExit("FAIL: concrete survivor %r" % ((counts, left, right),)) + return tested, passed diff --git a/research/positive-frame-subset-join/run.py b/research/positive-frame-subset-join/run.py new file mode 100644 index 0000000000..6df7c739a1 --- /dev/null +++ b/research/positive-frame-subset-join/run.py @@ -0,0 +1,59 @@ +"""Source-bound complete replay adapter. Produced by Nick Petalas, Apache-2.0.""" + +import argparse +import hashlib +import json +from pathlib import Path +from types import ModuleType + +from fast_support import direct_support_regression, require + + +PACKAGE = Path(__file__).resolve().parent +ROOT = PACKAGE.parent.parent +SOURCE = "research/bit-two-positive-frames-seven-call/verify.py" + + +def authenticated_bytes(path, expected): + require(path.stat().st_size <= 1 << 20, "source exceeds one MiB") + payload = path.read_bytes() + require(hashlib.sha256(payload).hexdigest() == expected, + "source hash mismatch: " + str(path)) + return payload + + +def load_source(root=ROOT): + manifest = json.loads((PACKAGE / "SOURCES.json").read_bytes()) + require(len(manifest["files"]) <= 16, "too many source rows") + code = None + for row in manifest["files"]: + if row["usage"] == "input": + payload = authenticated_bytes(root / row["path"], row["sha256"]) + if row["path"] == SOURCE: + code = payload + require(code is not None, "missing source program") + module = ModuleType("positive_frame_source") + module.__file__ = str(root / SOURCE) + exec(compile(code, module.__file__, "exec"), module.__dict__) + return module + + +def replay(baseline=False): + source = load_source() + if not baseline: + def replacement(profiles, grid=8): + return direct_support_regression(source, profiles, grid) + source.direct_support_regression = replacement + source.main() + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--baseline", action="store_true", + help="execute every original predicate unchanged") + args = parser.parse_args() + replay(args.baseline) + + +if __name__ == "__main__": + main() diff --git a/research/positive-frame-subset-join/verify.py b/research/positive-frame-subset-join/verify.py new file mode 100644 index 0000000000..7597136d1b --- /dev/null +++ b/research/positive-frame-subset-join/verify.py @@ -0,0 +1,147 @@ +"""Conformance checks for the accelerator, not a new theorem audit.""" + +from contextlib import redirect_stdout +import argparse +from fractions import Fraction as F +import hashlib +import io +from itertools import product +import json +from pathlib import Path + +from fast_support import concrete_splits, require, support_mask +from run import PACKAGE, authenticated_bytes, load_source, replay + + +def literal_mask(counts, labels, targets): + sums = {tuple(sum((u[j] * labels[j][axis] for j in range(6)), F(0)) + for axis in range(3)) + for u in product(*(range(c + 1) for c in counts))} + return tuple(target in sums for target in targets) + + +def check_small(): + labels = ((F(1, 3), 0, 0), (0, F(-1, 5), 0), (0, 0, F(1, 7)), + (F(1, 6), F(1, 10), 0), (F(-1, 3), 0, F(1, 11)), + (F(1, 3), 0, 0)) + targets = ((0, 0, 0), labels[0], (F(1, 6), F(1, 10), F(1, 7)), + (F(1, 13), 0, 0)) + checked = 0 + for counts in product(range(4), repeat=6): + if sum(counts) > 5: + continue + require(support_mask(counts, labels, targets) + == literal_mask(counts, labels, targets), "small conformance") + checked += 1 + return checked + + +def check_controls(): + zero = (F(0), F(0), F(0)) + axis = (F(1, 3), F(0), F(0)) + labels = (zero,) * 4 + (axis, tuple(-x for x in axis)) + targets = (axis, tuple(-x for x in axis), zero, (F(1, 6), F(0), F(0))) + require(support_mask((0, 0, 0, 0, 1, 1), labels, targets) + == (True, True, True, False), "signed added-label fixture") + require(support_mask((0,) * 6, labels, targets) + == (False, False, True, False), "zero-count fixture") + invalid = [(9, 0, 0, 0, 0, 0), (True, 0, 0, 0, 0, 0), + (-1, 0, 0, 0, 0, 0), (1, 1)] + rejected = 0 + for counts in invalid: + try: + support_mask(counts, labels, targets) + except ValueError: + rejected += 1 + for value in (0.5, F(1, 1 << 257)): + changed = ((value, 0, 0),) + labels[1:] + try: + support_mask((0,) * 6, changed, targets) + except ValueError: + rejected += 1 + require(rejected == 6, "invalid input accepted") + try: + authenticated_bytes(PACKAGE / "fast_support.py", "0" * 64) + except ValueError: + rejected += 1 + require(rejected == 7, "source mutation accepted") + return rejected + + +def check_inventory(source): + digest = hashlib.sha256() + checked = 0 + for counts, left, right in concrete_splits(source, source.profiles(7)): + labels = source.OLD + (left, right) + literal = literal_mask(counts, labels, source.TARGETS) + require(support_mask(counts, labels, source.TARGETS) == literal, + "concrete support-mask mismatch") + digest.update(bytes(literal)) + checked += 1 + return {"split_masks_compared": checked, "mask_sha256": digest.hexdigest()} + + +def check_benchmark(): + receipt = json.loads((PACKAGE / "BENCHMARK.json").read_text()) + require(receipt["errors"] == 0 and 5 <= receipt["pairs"] <= 9, + "invalid benchmark completion") + require(len(receipt["runs"]) == 2 * receipt["pairs"], "missing benchmark runs") + hashes = set() + for index, run in enumerate(receipt["runs"]): + require(run["mode"] == ("baseline", "accelerated")[index % 2], + "benchmark did not alternate") + require(type(run["elapsed_ns"]) is int and run["elapsed_ns"] > 0 + and run["returncode"] == 0 and run["stderr_bytes"] == 0, + "benchmark contains an unsuccessful command") + hashes.add(run["stdout_sha256"]) + require(len(hashes) == 1, "benchmark outputs differ") + for name, expected in receipt["implementation_sha256"].items(): + require(name in ("fast_support.py", "run.py", "benchmark.py", "SOURCES.json"), + "unknown benchmark input") + authenticated_bytes(PACKAGE / name, expected) + require(set(receipt["implementation_sha256"]) + == {"fast_support.py", "run.py", "benchmark.py", "SOURCES.json"}, + "incomplete benchmark binding") + return receipt["pairs"], next(iter(hashes)) + + +def result(): + source = load_source() + pairs, benchmark_stdout = check_benchmark() + observed = {"small_cases": check_small(), "rejections": check_controls()} + observed.update(check_inventory(source)) + capture = io.StringIO() + with redirect_stdout(capture): + replay() + output = capture.getvalue().encode() + require(output.endswith(b"PASS: no exact word of at most seven calls uses two " + b"positive rank-one frames\n"), "incomplete replay") + observed["complete_stdout_sha256"] = hashlib.sha256(output).hexdigest() + require(observed["complete_stdout_sha256"] == benchmark_stdout, + "benchmark did not run this complete output") + observed["benchmark_pairs"] = pairs + observed["source_sha256"] = hashlib.sha256(Path(source.__file__).read_bytes()).hexdigest() + observed["implementation_sha256"] = { + name: hashlib.sha256((PACKAGE / name).read_bytes()).hexdigest() + for name in ("fast_support.py", "run.py", "verify.py", "SOURCES.json", + "BENCHMARK.json")} + return observed + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--write", type=Path, help="generate a receipt at this explicit path") + args = parser.parse_args() + observed = result() + if args.write is not None: + args.write.write_text(json.dumps(observed, indent=2, sort_keys=True) + "\n") + print("WROTE", args.write) + return + expected = json.loads((PACKAGE / "RESULT.json").read_text()) + require(observed == expected, "generated result differs from RESULT.json") + print(json.dumps(observed, sort_keys=True)) + print("PASS_POSITIVE_FRAME_SUBSET_JOIN_CONFORMANCE no_new_kappa") + + +if __name__ == "__main__": + main()