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
128 changes: 128 additions & 0 deletions research/signed-swap-residue-bank/PROOF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# A smaller forward bank by signed exchange

## Contract and cited input

Let `1 <= a,b <= 12`. The caller supplies both residues before drawing coins.
It requests two independent Bernoulli outputs with parameters `a/13,b/13`.
Coins are independent fair bits, with no free initial random state.

zxv's [#6072](https://github.com/CrocSwap/integer-mult-bounds/pull/6072)
supplies the following input theorem. Its fixed-parameter dyadic decision graph
returns labels `00,01,10,11` with weights

```
w(a,b) = ((13-a)(13-b), (13-a)b, a(13-b), ab), denominator 169.
```

At every depth `k`, the number of completed label-`i` binary prefixes is
`floor(2^k w_i/169)`. This saturates the fair-prefix lower bound and attains the
optimal expected draw count. Its periodic representation has 312 pending states
and four terminal labels, hence 624 nine-bit targets, or 702 bytes. These are
cited predecessor results. The present verification does not rerun its law,
mean catalogue or optimality verifier.

The new contract permits changing which output a particular coin tape returns.
It retains the requested joint law and, as shown below, the original stopping
time on every coin tape. It is a forward logical contract only.

## Theorem

All 144 requested pairs can be served from 21 unchanged canonical source tables,
a 144-byte selector and fixed output logic. Their transition and selector payload
is exactly 14,886 bytes. The resulting sampler has the requested independent
product law, the cited optimal expected draw count, and the original first
stopping depth on every finite or infinite coin tape.

This is a constructive upper bound. No global minimum ROM size, physical tariff
or reversible implementation is asserted.

## Canonicalization and the output map

Put `c=min(a,13-a)`, `d=min(b,13-b)`, and let `u=min(c,d)`, `v=max(c,d)`.
The representatives are exactly `(u,v)` with `1 <= u <= v <= 6`. There are
`6+5+4+3+2+1=21`. Independent complements give four pairs on each diagonal
representative; complement and exchange give eight on each off-diagonal one.
Thus the orbit sizes are six fours and fifteen eights, totaling 144 pairs.
These are precisely the orbits under these specified operations, not a minimum
number of tables under arbitrary sampler redesigns.

Draw `(U,V)` from the canonical `(u,v)` source table. Exchange its coordinates
when `c>d`, then complement its first coordinate when `a>6` and its second when
`b>6`. Call this bijection `F`. Independent complements and exchange preserve
independence and give the two required parameters. More explicitly,

```
w(a,b)[F(i)] = w(u,v)[i] for i=0,1,2,3.
```

For each depth `k`, relabelled completed prefix counts therefore equal
`floor(2^k w(a,b)[j]/169)` for every requested label `j`. This proves the full
joint law and transfers the cited depth-optimal expected-bit bound. It uses no
floating point, finite draw cap or assumption about an actual inverse caller.

## Pointwise stopping times

Permuting the four weights preserves their residue sum at every binary phase.
It therefore preserves the pending-node counts `n_k` and the total number `D_k`
of terminal children at the next level. The literal source rule orders all
terminal children before the pending children. At node `j` with coin `t`, put
`l=2j+t`. If `l<D_k`, the path stops; otherwise its next pending index is
`l-D_k`. Both decisions depend only on `D_k`, not on the ordering of labels.

The canonical and requested source graphs consequently have the same phase/node
enumeration and pending transition on every coin. Induction preserves every
first stopping time, including nontermination and phase wrapping. The terminal
labels themselves need not agree. For example, on the seven-coin tape `1111100`
the requested `(12,2)` source table returns `01`; the canonical `(1,2)` table
with its first bit complemented returns `10`. Both stop at depth seven.
Thus this construction does not preserve every original coin-to-label function.

## Packed representation and exact inventory

The first 144 bytes, in `(a-1)*12+b-1` order, contain `8*i+flags`. Here `i` is
the canonical table index `0..20`; flag bits 2,1,0 request exchange, first
complement and second complement. All codes are below 168. Each subsequent
702-byte table stores its 624 targets consecutively, least significant bit
first, nine bits each. Targets `0..311` are pending states and `312..315` are
terminal labels. Every source root is state zero, so no entry-pointer table
or representative-name table is needed at runtime.

The total is `144 + 21*624*9/8 = 14,886` bytes. The bank retains an eight-bit
selector and a nine-bit local state, at most 17 logical control bits. The
selector is retained through terminal relabelling. Random tape, cursor, output
storage, code, headers and physical access are outside this payload count.

The constructor emits exactly those bytes. The checker checks all 144 selectors
against the four requested integer weights, the eight output permutations, and
every selector/state/coin lookup, `144*312*2=89,856` checks. Terminating and
unfinished fixtures exercise the new runtime; they do not re-establish the
predecessor's probability theorem. The lookup identity lifts by induction to
every finite tape and hence to pointwise first-stop behavior.

## Limits and code constraints

The finite `run` helper accepts at most 4096 supplied coins. It is an executable
finite-prefix interpreter, not a cap on the mathematical sampler. Longer paths
follow from the transition proof. Worst-case stopping time stays unbounded.
Restored coins would remain correlated with a retained output. No reversal,
freshness restoration, physical selector/lookup or native/caller bill follows.
No selected assumption is discharged and no new kappa is claimed.

The new code is nonrecursive. Constructor loops have at most 21 tables, 312
states and two coins; validation has 144 selectors and the same state bound.
Fixture traversal visits at most 312 states per table. Every new function is
below 60 physical lines. ValueError contracts remain active under `-O`.

Power-of-Ten deviations are confined to the verifier. Rule 3 cannot prohibit
Python's managed allocations. Source tables, fixtures and all working
collections have the fixed finite bounds above; byte output capacity is fixed
before packing. Python object overhead is not a physical storage certificate.
Rule 8 uses one dynamic load because the pinned predecessor is a standalone
script in a directory whose name is not an ordinary import identifier. Exactly
the SHA256-authenticated source bytes are compiled, bypassing bytecode caches;
only its `make` constructor is called. Its CLI verifier is never called. If the
predecessor later exposes a stable importable constructor, a new package can use
that interface. Rule 9's indirect calls are that single fixed constructor and
the finite negative-control lambdas; no external callback is accepted. Normal
and optimized warning-strict execution, static compilation and the finite
controls check these boundaries. No project-wide diagnostic change is needed.
107 changes: 107 additions & 0 deletions research/signed-swap-residue-bank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# A 14,886-byte paired residue sampler bank

All 144 nonzero ordered residue pairs `(a,b)` can share **21 canonical tables**
from zxv's [#6072](https://github.com/CrocSwap/integer-mult-bounds/pull/6072).
The new bank uses **14,886 payload bytes**, including all 144 selectors. It
preserves the independent Bernoulli laws, the cited optimal expected draws and
each coin tape's original stopping time. Output labels on an individual tape
may change.

The construction and package were produced by Nick Petalas. Claim types are a
scoped written proof and an exact finite certificate. This is a forward logical
storage improvement, with no new kappa or physical service claimed.

## The changed interface

Reduce each parameter to `min(a,13-a)` and sort the pair. The resulting
representatives are `1 <= u <= v <= 6`. After sampling, exchange and complement
the output bits as required. [PROOF.md](PROOF.md) gives the full law, prefix-count
and pointwise stopping-time arguments.

The source's per-configuration 702-byte table is unchanged. A fully resident
144-table bank has 101,088 transition bytes. This construction stores
`21*702=14,742` transition bytes and a 144-byte selector. The selector contains
the table index and all three output flags; no entry-pointer array is needed.
Runtime logical control needs at most 17 bits, including the retained selector.

Nick Petalas's older
[#6124](https://github.com/CrocSwap/integer-mult-bounds/pull/6124) reports an
84,578-byte shared bank that preserves every ordered coin-to-label function.
This bank saves a further 69,692 payload bytes by changing that contract. It
does not contradict #6124's fixed-function state minimum. Those predecessor
counts are cited, not replayed. A single on-demand source table still needs only
702 bytes, so a resident bank is not always the best physical choice.

## Evidence

[bank.py](bank.py) constructs the packed bytes and interprets supplied finite
coin prefixes. [verify.py](verify.py) checks all 144 selector product laws,
all eight output permutations and all **89,856** selector/state/coin transitions.
It checks 576 terminating paths, their 576 unfinished prefixes, 144 two-period
continuations and 15 exact-reason rejection controls. Six orbits have size four;
fifteen have size eight. No sampling estimate or floating-point acceptance is
used. The source sampler's law and expected-bit optimum remain cited premises.

The generated bank SHA256 is
`1604e7b1fc7492e034a9160d8001ba58235aa81273848982154e7d16a14ffd2c`.
The verifier can emit both the bank and a receipt binding every package file
and the declared source manifest. It writes no file by default.

## Reproduce

From the worktree root, using CPython 3.12.15 and the standard library:

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

Expected markers are `PASS_REGISTERED_RESEARCH_PACKAGE`,
`PASS_RESEARCH_COMMIT_BYTES` and `PASS_SIGNED_SWAP_RESIDUE_BANK`. Elsewhere,
substitute a local CPython 3.12 executable. For optional artifacts, append
`--emit-bank /absolute/external/path/bank.bin --receipt /absolute/external/path/receipt.json`
to the direct verifier. The parent directory must exist outside the checkout.

## Limitations

The original 144-table coin-to-label functions are not preserved. This is not
a minimum-state or minimum-byte result over all samplers. Code, headers,
physical table access, selector preparation, tape movement, stopping records,
output storage and reversible cleanup are outside the payload count. The
finite-prefix interpreter has a 4096-coin fixture limit; the written proof
handles arbitrary paths. Mathematical stopping time remains unbounded.

No source-bound inverse caller, conditionally fresh reused tape, physical
speedup, supplier admission, selected-frontier change, independent human review
or formal proof-kernel acceptance is claimed. The five selected framework
assumptions remain. No predecessor probability/mean suite, selected/native
cold replay, Lean or Docker was run.

## Open next questions

Price one actual nonadaptive caller's selector, packed lookup, output and tape
movement against on-demand generation. Begin with the reached residue pair
and its ownership layout. The missing physical caller contract blocks a runtime
comparison.

Derive a reversible lifecycle retaining the selector through terminal
relabelling, then price its stopping record and returned tape. Forward law
preservation alone cannot transfer the tariffs of #6102 or #6127. The structured
questions and blockers are in [TASK.json](TASK.json).

## Credit

zxv supplies #6072's exact graph, probability law, expected-bit optimum and
table-sharing question. Classical DDG methods and output symmetries are not
claimed as new. The new contribution is their explicit signed-exchange bank,
packed representation, changed contract and checked inventory.

JoyboyBrian's #5037/#5069 inverse lineage and #6096/#6102 residue and reversal
interfaces retain their credit. Nick Petalas's #6026 stochastic-prefix context,
#6124 fixed-function shared bank and #6127 counterless reversal are distinct
predecessors. ToikY's #6747/#6749 are written reviews of the original sampler
and fixed-function quotient. Their original notices and bytes are unchanged.
New work is Apache-2.0. Exact source blobs and SHA256 pins are in
[SOURCES.json](SOURCES.json).
30 changes: 30 additions & 0 deletions research/signed-swap-residue-bank/SOURCES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"schema_version": 1,
"base_commit": "e54523517d0f03e58352e647c403a5af3e525a57",
"files": [
{
"path": "certificates/selected-result.json",
"usage": "provenance",
"git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8",
"sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1"
},
{
"path": "docs/research/agent-task-catalog.json",
"usage": "provenance",
"git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec",
"sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81"
},
{
"path": "research/paired-residue-sampler/README.md",
"usage": "input",
"git_blob": "615c4890ec797561fd4287445ceb1019905175bc",
"sha256": "4a8d35da8cde11b127b490abdcaf0f085643313603d8b93d5773968a2e81a695"
},
{
"path": "research/paired-residue-sampler/verify.py",
"usage": "input",
"git_blob": "eda448fbda7b6a78f340086fcaac6e7556bf1383",
"sha256": "a3f14b87169b934489fc7d01d82ff36f6a671bc6c38e4761443f5481e36c2f63"
}
]
}
Loading
Loading