Skip to content
Open
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
101 changes: 101 additions & 0 deletions research/chirp-residue-loop/BENCHMARK.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"python": "3.12.15 (main, Oct 14 2026, 00:55:37) [Clang 23.1.3 ]",
"platform": "macOS-27.0.1-arm64-arm-64bit",
"logical_cpus": 18,
"load_average": [
4.34033203125,
3.3828125,
2.54541015625
],
"samples": [
{
"trial": 0,
"mode": "baseline",
"seconds": 2.4566558750811964,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 0,
"mode": "fast",
"seconds": 1.9595325000118464,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 1,
"mode": "baseline",
"seconds": 2.44032737496309,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 1,
"mode": "fast",
"seconds": 1.9822481670416892,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 2,
"mode": "baseline",
"seconds": 2.456384208984673,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 2,
"mode": "fast",
"seconds": 2.0032798750326037,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 3,
"mode": "baseline",
"seconds": 2.4750329998787493,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 3,
"mode": "fast",
"seconds": 1.9908895001281053,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 4,
"mode": "baseline",
"seconds": 2.45319641684182,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
},
{
"trial": 4,
"mode": "fast",
"seconds": 1.9722066670656204,
"stdout_sha256": "d2af94ba9138a742e51c11e0c3331ffc24e5ea64bb64353f0d654adf4a3db2b6",
"errors": 0
}
],
"summary": {
"baseline": {
"median": 2.456384208984673,
"minimum": 2.44032737496309,
"maximum": 2.4750329998787493
},
"fast": {
"median": 1.9822481670416892,
"minimum": 1.9595325000118464,
"maximum": 2.0032798750326037
}
},
"reduction": 0.19302193859118,
"errors": 0,
"source_hashes": {
"loop.py": "d81d6177971e9948fd82607e68691b2fbf45f1423c71fcdc01390e00e68d52f0",
"replay.py": "48af4465ee424f761ea9cee791a70e6c46a4cff4c05135b07e016967b5e06a7b",
"benchmark.py": "b4fa62123aa5c2561b9b6036bf1045f7661de397478c64269d7eb9712c94d109"
}
}
50 changes: 50 additions & 0 deletions research/chirp-residue-loop/PROFILE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"baseline": {
"total_profile_seconds": 5.156292709000001,
"functions": [
{
"file": "research/chirp-residue-step/verify.py",
"line": 24,
"name": "require",
"primitive_calls": 42099208,
"total_calls": 42099208,
"self_seconds": 0.9858124140000001,
"cumulative_seconds": 0.9858124140000001
},
{
"file": "research/chirp-residue-step/verify.py",
"line": 38,
"name": "one_axis",
"primitive_calls": 6141,
"total_calls": 6141,
"self_seconds": 4.1104735660000005,
"cumulative_seconds": 5.093219727
}
],
"source_main_seconds": 5.151132625000001
},
"fast": {
"total_profile_seconds": 2.17950446,
"functions": [
{
"file": "chirp-residue-step/verify.py",
"line": 24,
"name": "require",
"primitive_calls": 143896,
"total_calls": 143896,
"self_seconds": 0.003372458,
"cumulative_seconds": 0.003372458
},
{
"file": "chirp-residue-loop/loop.py",
"line": 4,
"name": "one_axis",
"primitive_calls": 6141,
"total_calls": 6141,
"self_seconds": 2.122359931,
"cumulative_seconds": 2.122359931
}
]
},
"warning": "Instrumented profiles identify the limiting code and counted calls; their elapsed times are not speedup samples."
}
89 changes: 89 additions & 0 deletions research/chirp-residue-loop/PROOF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Equivalence of the bounded one-axis loop

This is an implementation-equivalence argument for PR3806's primary command.
It establishes no new chirp identity or multiplication theorem. James Reed's
mathematical result remains the credited predecessor.

## Domain and state induction

The ordinary interface has integer radius r=2^ell for 2<=ell<=12,
length t in {r/2,r}, and odd slope s with 0<s<t. The specialization's
test-only initial-state argument is outside that ordinary interface.

Both implementations set M=2r, c=(-s*(r//t)) mod M and start at

```text
index=0, value=0, difference=c, total=0, steps=0.
```

Before each transition they evaluate, in this order,

```text
value == (c*index*index) mod M
difference == (c*(2*index+1)) mod M
total == value.
```

The retained `require` calls have no successful-path state effect. On a
false predicate they call `fail`, which raises SystemExit with a fixed prefix
and the predicate's label. The new branches evaluate the same expressions
and raise the same exception text in the same order. They retain the separately
updated total and evaluate the third predicate at every state.

After all three predicates pass, both increment steps. If index+1<t,
both execute the same assignments in the same order,

```text
total = (total+difference) mod M
value = (value+difference) mod M
difference = (difference+2*c) mod M
index = index+1.
```

Otherwise both subtract value from total modulo M, restore index and value
to zero and difference to c, and break. Induction proves equality of every
visited state and transition. Neither closed-form check becomes a recurrence.

Before the final transition index is t-1. There are exactly t visits, so
replacing the source's open-ended loop by `for _ in range(t)` cannot truncate
an ordinary execution. The final rollover and steps==t predicates are
unchanged. Their logical rewrites are equivalent for the admitted integers
and have the same first failure text. Computing c directly uses exactly
the authenticated source helper's expression.

## Complete command and counted work

The adapter authenticates all four declared source files before loading the
retained module. It changes only `one_axis`. Every square identity, two-axis
state, recursive visit tuple, historical selected-value check and stored-receipt
comparison executes as before. No scientific result is cached.

The differential run records all 6,141 ordered
(radius,length,slope,returned_steps) tuples on both sides. Their arrays and
stdout agree exactly. The sum of enumerated returned step counts is
13,981,010. Each state loses three successful `require` call boundaries;
each rollout loses two final `require` boundaries. Thus exactly

```text
3*13,981,010 + 2*6,141 = 41,955,312
```

such calls disappear while their predicates remain. Separate profiles
corroborate this count. Timing covers the source primary command, including
authentication, import, all enumerations and receipt comparisons. It excludes
the separate retained test command and the new conformance harness, which
are checked separately.

## Rejection evidence and limits

For three smallest admitted length/slope pairs, the checker enumerates all
512 triples of value, difference and total modulo eight at initial index zero.
The 1,533 bad states must raise the original first predicate label; the three
valid states complete. Fifteen malformed domain/control cases reject. A
changed source program rejects at its hash before its appended exception can
execute. The original independent test script runs unchanged in a separate
nonoptimized interpreter, also when the conformance harness runs with -O.

The written argument covers the stated interface. Finite controls do not
provide independent human or proof-kernel review. No physical consumer,
supplier invoice, selected-frontier change or multiplication theorem is supplied.
119 changes: 119 additions & 0 deletions research/chirp-residue-loop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Faster complete chirp-residue replay

This contribution was produced by Nick Petalas. Apache-2.0.

Claim type: a bounded implementation improvement with a scoped equivalence
proof and measured complete-command evidence. No new kappa is claimed.

Inlining the one-axis predicate calls reduces the complete PR3806 primary
replay's median wall time by **19.30%**, from 2.4564 s to 1.9822 s, in five
alternating fresh-process pairs. All ten outputs match and there are zero
errors. Baseline times range from 2.4403 to 2.4750 s; fast times range from
1.9595 to 2.0033 s. [BENCHMARK.json](BENCHMARK.json) retains the generated
samples, source hashes, interpreter and host information. The shared macOS
host had 18 logical cores. These are local timings; a physical-consumer
speedup and cross-platform performance are unclaimed.

The source profile spends 5.093 of 5.151 profiled primary-command seconds in
the one-axis loop. Profiling is separate from the reported timings. The new
loop eliminates exactly 41,955,312 successful condition-call boundaries while
still evaluating their predicates. It retains every 13,981,010 one-axis state,
6,141 rollout, 21,840 two-axis state, 4,096 square check and 3,905 visit tuple.
The whole source driver and its receipt checks run with only the one-axis
function substituted. Frozen sources are unchanged.

[PROOF.md](PROOF.md) gives the state induction, loop bound, first-failure
equivalence and counted work. The mathematical chirp result is James Reed's
credited prior work. This package contributes the faster implementation.

## Reproduction

From the repository root, with standard-library CPython 3.12:

```sh
/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/chirp-residue-loop/verify.py
/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -O -B research/chirp-residue-loop/verify.py
/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/chirp-residue-loop
/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/chirp-residue-loop --check-source-history
```

Any CPython 3.12 path may replace the local interpreter. The direct verifier
prints `PASS_CHIRP_RESIDUE_LOOP` in a generated receipt bound to every package
file's SHA256. It compares complete stdout and every ordered rollout tuple,
checks all 1,533 corrupted initial states, rejects fifteen malformed domain
or control states and a changed source program, and runs the unchanged
independent source test. All checks remain active under optimization.
Both registered commands have 120-second limits. Timing is not a CI gate.

The fast primary command alone is:

```sh
/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/chirp-residue-loop/replay.py
```

To repeat the ten timings, choose a fresh output path outside the checkout:

```sh
/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/chirp-residue-loop/benchmark.py --output /absolute/scratch/benchmark.json
```

Both modes use the same wrapper, authentication, interpreter flags and fixture;
baseline runs the unchanged original main. Measurement includes startup and the
complete primary command. It excludes the separate independent test script and
conformance harness. The host was shared; the sample ranges remain separated.

## Sources and scope

James Reed / jwr404's [PR3806](https://github.com/CrocSwap/integer-mult-bounds/pull/3806)
supplies the residue replay and its mathematical claims. Credit Jose Manuel's
PR3763 for the producer, Chafik Boukhalfa for the residue schedule and Ross
Richardson for the symbolic-transition lineage. Their files and credit are
unchanged. No predecessor theorem or count is claimed as a new result.

[SOURCES.json](SOURCES.json) authenticates four live files at canonical main
`7c49fe32c55de02c2c873655c804b16e4c3fef0a`. The replay-runtime card is refined
to this full command. [TASK.json](TASK.json) records scope and coordination. The
[advance claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19372291)
precedes implementation. Cached overlap covered 541 open PRs and 6,563
Discussion records; main and merged searches also checked distinctive
object/count terms. Sparse notes, arbitrary diffs and unpublished work remain
coverage limits. The selected metadata orientation passed.

The loop accepts only the predecessor driver's admitted domain and explicitly
rejects other arguments. An unrestricted API replacement is unclaimed. Native
realization, physical time, precision, storage, ownership, compiler and outer
recovery obligations remain separate. All five selected framework assumptions
remain. No selected cold replay, Lean, Docker, independent human or proof-kernel
acceptance is claimed. The selected frontier is unchanged.

## Implementation constraints

The new loop has at most 4,096 iterations. The complete driver calls it 6,141
times. The conformance census stores 6,141 four-integer rows per side; the
fault census has three groups of 512 states. Ordinary arithmetic operands
have fewer than forty bits. Test-only initial components are capped at 64 bits.
New functions are below sixty physical lines.

Power of Ten deviations are confined to this offline checker. Rule 1:
the immutable source's visit enumeration recurses to depth five and is retained
to preserve coverage. Rule 3: CPython allocates integers and bounded collections
dynamically; a static allocation guarantee is unclaimed. Rules 8 and 9:
the adapter loads one authenticated module and replaces one fixed function
binding; the optional census uses one bounded callback. The controlled import
path names only the package directory. The independent source test is one
child with a ten-second timeout; benchmark children have 120-second timeouts
and there are exactly ten. Temporary source-drift copies are removed by their
context manager. Warning-strict normal and optimized replay provide available
diagnostics. No separate type checker or linter is installed. A broader runtime
or input domain would require revisiting these bounds and allocation/import
deviations.

## Open next questions

1. Can remaining closed-form arithmetic be reduced while retaining a separate
predicate at every state? Start with the final fast profile and one exact
change, then prove preserved coverage and measure the whole command. No
further optimization is supplied here.
2. Does an actual physical chirp-consumer replay use this loop and benefit?
First identify a caller and measure its complete execution. This residue
checker does not price a multiplication consumer.
Loading