Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions research/current-moment-integer-fastpath/PROOF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Exact equivalence of the integer kernel

Fix any exact Fraction argument x. Negative arguments follow the unchanged
reciprocal branch; zero and positive arguments use exactly the predecessor's
halving loop until 0 <= x = p/q <= 1/64, q > 0. Thus both algorithms have the
same reduced argument and the same number of subsequent squarings.

Write D_j = q^j j!, P_j = p^j, and S_j = sum_{i=0}^j x^i/i!.
Induction gives S_j = N_j / D_j with

N_0 = D_0 = P_0 = 1
P_j = p P_{j-1}
D_j = j q D_{j-1}
N_j = j q N_{j-1} + P_j.

These are integer operations. They compute exactly the reference's forty
Fraction multiply/add steps without reducing intermediate numerator/denominator
pairs. The final term is P_40 / D_40. The reference's exact positive tail is

R = (P_40/D_40) (p/q) / 41 / (1 - p/(42q))
= 42 P_40 p / [41 D_40 (42q-p)].

The denominator is positive on the reduced domain, including p=0. Therefore
`taylor_parts` returns exact unreduced fractions for S_40 and S_40+R. No error
term or positive tail is dropped merely because it is usually below one grid unit.

For M=10^65 and nonnegative integers a,b with b>0, the reference's grid floor
of a/b is floor(a M/b)/M and the grid ceiling is ceil(a M/b)/M. Python integer
`//` and `(a*M+b-1)//b` implement these exactly. Once a bound is represented
as n/M, flooring its square is floor(n^2/M)/M, and ceiling its square is
ceil(n^2/M)/M. Hence induction through every squaring gives the identical
pair of rational endpoints. The negative branch applies identical reciprocals
and identical outward rounding to identical endpoints. The unchanged logarithm,
power, moment, interval subtraction and strict allowance functions consequently
produce identical results for their supported exact inputs.

This is an algebraic equivalence proof for the fixed authenticated engine, not
a new proof of its transcendental enclosure theorem or of integer multiplication.
The executable differential tests support the implementation of the recurrence;
finite tests alone are not the universal argument. Authentication, the original
rank checks, and explicit guards remain active under `python -O`.
82 changes: 82 additions & 0 deletions research/current-moment-integer-fastpath/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Exact integer fast path for the selected moment engine

**Tooling result; no new κ.** An opt-in adapter returns the same exact rational
intervals as the selected #5413 caller's 72-term-log / 40-term-exp engine.
It removes intermediate Fraction reductions from the exponential sum. The
Taylor degree, positive remainder, range reduction, negative reciprocal,
10^65 grid, and every outward-rounded squaring stay identical. See [PROOF.md](PROOF.md).

On Windows / CPython 3.12.2, three alternating fresh-process pairs give median
**4.1874 s → 0.2770 s (15.12×)** for 24 actual invoice ranks × 12 distinct
exponents, complete paid/productive moments and strict homogeneous allowances.
All six mathematical receipts have SHA256
`fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd`.
[Final samples](benchmark-final-windows.json) and [earlier samples](benchmark-windows.json)
are retained. Timings exclude source loading/imports but include cold logarithm
and power caches. They measure this pricing workload, not a full caller replay.
The earlier instrumented 288-power profile took 4.538 s, with 3.345 s in gcd;
it motivated this change but is not used for the speedup ratio.

## Reproduce and use

Python 3.12 standard library only, from repository root:

```sh
python3.12 -B scripts/research_package.py --package research/current-moment-integer-fastpath
python3.12 -B research/current-moment-integer-fastpath/benchmark.py --pairs 3 --output /tmp/fresh-moment-benchmark.json
```

The benchmark refuses an existing output path. Each sample uses a fresh subprocess
and fresh caches; a differing receipt aborts the timing comparison. No unstable
wall-time threshold is a CI acceptance condition.

For exploratory pricing, put this directory on the Python import path and call
`from fast_moments import load_engine; engine = load_engine()`.
Use its unchanged `moment`, `minus`, `power` and `homogeneous_limit` interfaces.
`load_engine(False)` loads the authenticated reference. Both inputs are local
snapshots with SHA256 rejection before evaluation; no cached mathematical result
or external checkout is needed. Installing into arbitrary engines is unsupported.

The verifier compares the complete workload, all 600 exponential invocation/result
records, 121 boundary/seeded rational arguments, exact unrounded polynomial and
remainder parts, and 35 signed/zero-exponent rank cases. It checks the selected
positive lower point and rejected raw ceiling. Executed degree, tail and inward
rounding mutations, source/fixture tampering, an omitted charge and an invalid
rank are detected. The same explicit checks run under normal and optimized Python.

The frozen source and invoice provenance are in [SOURCES.json](SOURCES.json).
`inputs/invoice.json` is exactly the `histograms` object extracted from the pinned
invoice receipt. The unchanged source is copied byte for byte. The grid and source
hash are fixed deliberately: a new source version needs a new review, not a silent
cache reuse. The source's other acceptance logic remains compiled with assertions
enabled. Native identity, target independence, physical admission, full compiler,
precision and outer-theorem checks are outside this adapter. No full-caller,
whole-repository, Lean, or independent-human verification is claimed.

## Overlap and credit

Chris R / Clear1nsight supplies the exact arithmetic and #5413 completion.
Dillon, Ali Romman, Cao Yifan, Dugongue, Cinna Davis, zxv and the retained lineage
supply the selected construction. Their existing notices are preserved.

This is an adaptation of a classical integer Taylor recurrence, not a new
mathematical method. Related exact-output integer kernels already occur in
[PR672](https://github.com/CrocSwap/integer-mult-bounds/pull/672) (a different,
degree-16 / 200-bit engine; its full owner check saved only 2–3%) and
[PR2552](https://github.com/CrocSwap/integer-mult-bounds/pull/2552).
This package targets the currently selected 72/40 engine and its actual invoice,
without editing a frozen predecessor or substituting one engine's truncation
parameters for another's. Live title/body overlap searches are partial coverage,
not a novelty proof. New material: Joseph Anglada with substantial OpenAI Codex
assistance, Apache-2.0; no independent human or proof-kernel review.

## Open next questions

- How much does this save in a complete caller replay? First build a source-bound
adapter that substitutes only this arithmetic and compare complete receipts in
matched fresh processes. Native validation and other replay costs may dominate;
a separate full replay budget and adapter review are needed.
- Can a changed physical word earn a better κ? First supply a literal changed word
and complete paid/target invoice, then use this kernel for exact screening.
Operator identity, independent targets, restoration, ordinary work, precision and
compiler/outer funding remain the gates. Faster pricing alone changes no κ.
30 changes: 30 additions & 0 deletions research/current-moment-integer-fastpath/SOURCES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"base_commit": "32890bc5de034ab8fc93ac88ead7279a6a416d04",
"files": [
{
"git_blob": "fc3d4ba105e1f097d0d7d051a308281e86ab1446",
"path": "certificates/selected-result.json",
"sha256": "66974efdced4083c00025f97d95d83909a226cdf801edb9301c195c6641f6903",
"usage": "provenance"
},
{
"git_blob": "f126dd2e2dad2b669e75d1d0d0bd05c600725602",
"path": "docs/research/agent-task-catalog.json",
"sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72",
"usage": "provenance"
},
{
"git_blob": "bf31af785122dea7cbceacbfa64c21e567e4fca7",
"path": "research/coupled-helper-neutral-completion/capsule/workspace/swarm-coupled-caller-sol-high-20261024/agents/invoice/exact_moments.py",
"sha256": "cf7439c9eb4095224126dd5eefc9f1c5dfe1968d6e8eca5b87d4a3897841182d",
"usage": "provenance"
},
{
"git_blob": "d66216ad80b502c4042979269655bacb9f6668b9",
"path": "research/coupled-helper-neutral-completion/reports/expected/invoice.json",
"sha256": "e7df9fe1a7a00f67bbf35e9b155537fd26a0c05b61788653b878bd84d9006450",
"usage": "provenance"
}
],
"schema_version": 1
}
67 changes: 67 additions & 0 deletions research/current-moment-integer-fastpath/TASK.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"actual_scope": "Accelerate the selected caller exact moment pricing kernel without changing any rational endpoint.",
"ai_assistance": "Substantial OpenAI Codex assistance in profiling, implementation, derivation and verification. No independent human or proof-kernel review.",
"author": "Joseph Anglada, with substantial OpenAI Codex assistance",
"base_commit": "32890bc5de034ab8fc93ac88ead7279a6a416d04",
"bottleneck_link": "Fraction normalization consumes about 74 percent of profiled pricing time. Integer Taylor recurrence permits more candidate invoices to be screened with exactly the same arithmetic acceptance.",
"budget_minutes": 60,
"evidence": "verify.py, PROOF.md, benchmark-final-windows.json; 600 exponential calls and complete moment/allowance outputs agree exactly.",
"open_questions": [
{
"blocked_by": "Requires a separate scoped full-caller adapter and complete replay budget.",
"first_step": "Run matched fresh-process complete caller replays with only this engine substituted and compare complete receipts.",
"question": "How much does opt-in substitution save in a complete caller replay?",
"why_it_matters": "Kernel timing does not measure the rest of native validation, compiler and source checks."
},
{
"blocked_by": "A legal changed word, independent targets and all physical and compiler charges are needed.",
"first_step": "Use load_engine() to screen a changed fully charged paid/target histogram, then verify its actual operator and fund compiler/outer costs.",
"question": "Can changed physical words produce a better complete signed invoice?",
"why_it_matters": "Unchanged arithmetic cannot improve the mathematical kappa."
}
],
"original_card": {
"acceptance_gate": "Report before/after wall time on the same fixture, retained checks and invalidation behavior.",
"allowed_variations": [
"Profile one stage or design one source-bound cache boundary."
],
"bottleneck_link": "Faster trustworthy replays increase review throughput and let mechanism candidates be checked sooner.",
"first_experiment": "Measure one unchanged fixture, preserve check coverage, and test one optimization with invalidation controls.",
"first_step": {
"command": [
"python3",
"-B",
"scripts/research_baseline.py"
],
"expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY",
"inspect": "Read the selected reproduction command and choose a single replay stage for profiling.",
"scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay."
},
"id": "replay-runtime",
"methods": [
"Profile one isolated replay and optimize the measured bottleneck.",
"Design source-bound reuse with explicit dependency invalidation and negative controls."
],
"overlap_terms": [
"replay runtime",
"cache invalidation",
"isolated tests"
],
"question": "Can one measured replay bottleneck be sped up without dropping coverage?",
"scope_change_triggers": [
"Skipping coverage or comparing different fixtures to claim speedup."
],
"starting_points": [
"scripts/run_isolated_tests.py",
"scripts/verify_replay_coverage.py",
"certificates/selected-result.json"
]
},
"outcome": "completed",
"priority_revision": 7,
"schema_version": 1,
"scope_change_reason": "Explicit user request to optimize checks and then resume changed-profile kappa exploration; profile selected moment arithmetic rather than unrelated replay routing.",
"scope_status": "refined",
"stop_rule": "Publish only after exact differential controls, paired fresh-process timing and package replay; do not infer full-caller speedup or a new kappa from kernel timing.",
"task_id": "replay-runtime"
}
28 changes: 28 additions & 0 deletions research/current-moment-integer-fastpath/VERIFY.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"commands": [
{
"argv": [
"{python}",
"-B",
"{package}/verify.py"
],
"checks": "Complete exact pricing and invocation trace equality, unrounded Taylor and remainder oracle, signed powers, source/fixture tampering, paid-charge and executed kernel mutations.",
"timeout_seconds": 120
},
{
"argv": [
"{python}",
"-O",
"-B",
"{package}/verify.py"
],
"checks": "Same explicit checks under optimized Python; frozen source compiles with optimize=0.",
"timeout_seconds": 120
}
],
"inputs": [],
"python": "3.12",
"requirements": [],
"schema_version": 1,
"status": "ready"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"median_seconds": {
"fast": 0.2769799999659881,
"reference": 4.187386899953708
},
"median_speedup": 15.118011771492167,
"new_kappa": null,
"platform": "Windows-10-10.0.19045-SP0",
"python": "3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]",
"samples": [
{
"mode": "reference",
"seconds": 4.04614740004763,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "fast",
"seconds": 0.2769799999659881,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "fast",
"seconds": 0.27250459999777377,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "reference",
"seconds": 4.766304199933074,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "reference",
"seconds": 4.187386899953708,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "fast",
"seconds": 0.3445142999989912,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
}
],
"scope": "24 ranks x 12 exponents, complete moments and strict allowances; cold engine caches"
}
43 changes: 43 additions & 0 deletions research/current-moment-integer-fastpath/benchmark-windows.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"median_seconds": {
"fast": 0.2735154000110924,
"reference": 4.0972460000775754
},
"median_speedup": 14.979946284236323,
"new_kappa": null,
"platform": "Windows-10-10.0.19045-SP0",
"python": "3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]",
"samples": [
{
"mode": "reference",
"seconds": 4.160859999945387,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "fast",
"seconds": 0.2735154000110924,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "fast",
"seconds": 0.34580119990278035,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "reference",
"seconds": 4.044113300042227,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "reference",
"seconds": 4.0972460000775754,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
},
{
"mode": "fast",
"seconds": 0.2694238000549376,
"sha256": "fd2027763821b8623d579c37a7826a686d2725c0fdd18c193e59a64e481a98fd"
}
],
"scope": "24 ranks x 12 exponents, complete moments and strict allowances; cold engine caches"
}
53 changes: 53 additions & 0 deletions research/current-moment-integer-fastpath/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
"""Fresh subprocess pairs; timings are evidence, never a CI acceptance threshold."""
import argparse
import json
from pathlib import Path
import platform
import statistics
import subprocess
import sys
from time import perf_counter
import fast_moments
import workload


def main():
ap = argparse.ArgumentParser()
ap.add_argument('--worker', choices=('reference', 'fast'))
ap.add_argument('--pairs', type=int, default=3)
ap.add_argument('--output', type=Path)
args = ap.parse_args()
if args.worker:
engine = fast_moments.load_engine(args.worker == 'fast')
start = perf_counter()
receipt = workload.run(engine)
print(json.dumps({'mode': args.worker, 'seconds': perf_counter()-start,
'sha256': workload.digest(receipt)}))
return
if not 1 <= args.pairs <= 20:
ap.error('--pairs must be 1..20')
samples = []
for j in range(args.pairs):
order = ('reference', 'fast') if j % 2 == 0 else ('fast', 'reference')
for mode in order:
output = subprocess.check_output([sys.executable, '-B', __file__, '--worker', mode], text=True)
samples.append(json.loads(output))
if len({x['sha256'] for x in samples}) != 1:
raise ValueError('different mathematical outputs; timing comparison invalid')
medians = {mode: statistics.median(x['seconds'] for x in samples if x['mode'] == mode)
for mode in ('reference', 'fast')}
result = {'python': sys.version, 'platform': platform.platform(), 'samples': samples,
'median_seconds': medians, 'median_speedup': medians['reference']/medians['fast'],
'scope': '24 ranks x 12 exponents, complete moments and strict allowances; cold engine caches',
'new_kappa': None}
encoded = json.dumps(result, sort_keys=True, indent=2)+'\n'
if args.output:
if args.output.exists():
raise ValueError('refusing to overwrite benchmark evidence')
args.output.write_bytes(encoded.encode())
print(encoded)


if __name__ == '__main__':
main()
Loading