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
126 changes: 126 additions & 0 deletions research/r437-fixed-pair-cse/PROOF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Fixed-PAIR common-subexpression elimination on the physical coefficient path

## Domain and theorem

Fix the authenticated `controller.py`, `children.py`, `records.py`, `matrices.py`
and binary-word arithmetic in SOURCES.json. Inputs, source specifications and raw
field bytes stay fixed during a call. Give both evaluators sufficient arena/tape
capacity. This is the actual `children.coefficient` entry point: it admits the
parent, serializes an extension, admits a leaf, evaluates its weight, optionally
negates its inverse, then disposes the leaf, parent and extended program.

For every input accepted by the original evaluator, the package-local adapter
returns the same residue and preserves borrowed Program/Fields bytes, public
heads and numerical ownership. It changes only `Callback.weight`; admission,
serialization, matrix preparation and cleanup remain the authenticated code.
The theorem is uniform over prime-power local rings and arbitrary admitted high
lifts. No assumption that a high lift leaves a permutation fixed is made: the
optimization tests the **actual prepared** `permutation[field] == field` and
`field < 64` at each visited PAIR node.

The checker-only `prepared_codes` set is unchanged: eliminating a duplicate
subtree removes only repeated insertions of the same source codes. Preparation
call counts intentionally change and are not an observable numerical result.

The returned value at a PAIR node is `d[field] * H(pi[field],j) / H(field,j)`,
where H is the prior coefficient on head rows and 1 on tail rows. Reversal maps
both occurrences to the same `f-1-coordinate`. If the actual permutation fixes a
head field, the two recursive requests have identical `(slot,position)`. Their
subcomputations are deterministic on stable borrowed inputs. Evaluating this
request once therefore yields the same value `v` as both old requests. The
new unary continuation still computes `inverse(v)`, requires it to exist, and
performs `d*v*inverse(v)`. It does **not** replace the expression by `d` before
checking the ancestor. This preserves all high-digit, preparation, matrix and
ancestor unit failures in the omitted duplicate subtree.

Induct on the descriptor depth. ROOT and UNIT (including half-unit) are unchanged.
GOOD retains preparation, pivot selection, one ancestor and multiplication.
Nonfixed PAIR and tail PAIR retain both operands and their order. A fixed head
PAIR uses the inductive result once and the same unit check and arithmetic as
above. Child extents strictly decrease under unchanged admission, so induction
terminates. The argument neither relies on root coefficients being one nor on
an all-fixed history. Finite tests supplement this source argument.

## Encoded continuation and resource simulation

The old Stack already accepts RETURN with one residue word. On the **pending**
stack, this previously unused tag now denotes the unary fixed-PAIR continuation.
The values stack continues using RETURN normally. The guarded source adapter
checks the complete original weight-method AST and exact three replacement
sites. There is no new dynamic dictionary, key decoder, descriptor cache or tape.
A variable index is never converted to a native Python integer. The only new
predicate compares bounded native row labels, already part of the finite control
alphabet. Its comparison cost must be charged; it is a fixed finite-control test.

The unary continuation pops one value, allocates inverse, product and result,
pushes a RETURN value and frees all five owned residues. The corresponding binary
continuation used a second owned value as well. Other numerical frees are
unchanged. Pending requests have the same arity and bit width as before; the
second identical VALUE is absent. Their pop/reverse/erase work is removed.
No extra record or numerical backing is needed for the successful simulation.
The high-water comparison is a consequence of removing a subtree and one stored
value, not a claim about the host Python container allocator.

For malformed data, the same first failing ancestor remains evaluated. Source
mutation is rejected by authentication/AST guard before adaptation. Byte-level
admission is unchanged. Under an allocation cap that is sufficient for one
implementation but not the other, acceptance need not match: the theorem compares
mathematical/encoded checks under sufficient capacity. Concurrent input mutation,
side-effectful external specifications, arbitrary forged continuation tapes and
asynchronous failures are outside the input contract. Rejection cleanup is still
performed by unchanged `children.coefficient` rollback; fixture controls check it.

## Exact recursive work and full coefficient bill

Let d be the depth of an all-fixed-head-PAIR evaluated history, including the
appended current child. The original preparation recurrence is
`B(0)=0, B(d)=1+2 B(d-1)`, hence `B(d)=2^d-1`. The adapted recurrence is
`C(0)=0, C(d)=1+C(d-1)`, hence `C(d)=d`. The number of root visits goes from `2^d`
to 1. This is exponential-to-linear **matrix-preparation count** on this stated
subclass. It does not assert linear total tape actions: the retained field and
program access methods repeatedly seek from the beginning.

For a general descriptor tree, replace each fixed head PAIR's two identical
subtrees by one; GOOD and UNIT stay as before and nonfixed PAIR may still branch.
No global linear-depth or global polynomial coefficient bound is proved.
For a chain of d fixed head PAIRs, sum the actual depth-dependent cost at each
level once, including `step`, Fields.read/prepare, full 64-dimensional preparation
and 128-dimensional fallback, unary continuation, word arithmetic and erase.
Their original multiplicities were `2^(d-l)` at level l; they become 1.
The remaining arithmetic inversions/multiplications still occur at every visited
level. Unknown bit-operation tariffs are not assigned zero.

Write A_parent and A_leaf for the two complete Callback admissions, E for extension
construction, D for disposal/erase, W_CSE for this complete weight evaluation and
N for optional negative inversion. The entire call is
`K_CSE = A_parent + E + A_leaf + W_CSE + N + D`, including prime-power checks,
all live field records, word lifetimes and restoration. Nothing here removes the
two admissions or their repeated scans. PR4011's independent admission cursor
can be composed later, but is not silently assumed or credited as this saving.

PR4008 establishes that a physical leaf atom/prefix uses three semantic ADDs but
**six** independent coefficient evaluations, because split and merge each prepare.
Its full coefficient contribution remains `4 K_CSE(positive) + 2 K_CSE(negative)`
(or `6 K_CSE + 2 J` when J is separately defined as the extra negative-inverse
work). The adapter introduces no cross-call cache. Source generation, GL64 payload
routing, packet traversal and stock/precision/lifetime obligations outside these
calls remain additional costs. The selected kappa does not change.

## Independent checks and scope

`check.py` invokes the real serialized entry point with Word.inspect disabled
inside runtime. Rank-seven synthetic but fully admitted source definitions have
identity preparation and a head/tail-permuted low matrix, with nonzero high lifts.
The independent native-integer oracle constructs the projector and full fallback
matrix over Z/9Z, then compares values. Good, ordinary nonfixed PAIR, reverse tail,
unit, half-unit and negative-inverse branches are covered. These fixtures prove
neither that all R437 sites use the fixed-field path nor a full physical payload
run. The full R437 source-plan catalogue is deliberately not reconstructed.

Preparation counts, all created record tapes, numerical word actions, public
heads/bytes and live ownership are measured after fixture creation. Thus the
receipt includes both admissions, extension serialization and erase, stacks and
complete coefficient evaluation. Python execution time is not a machine-step
claim. Finite controls reject a malformed ancestor high digit, nonunit root,
changed AST, false receipt and missing/changed/symlinked source input. A mutant
that treats nonfixed rows as fixed is detected by the field-57 root-unit-2 case.
87 changes: 87 additions & 0 deletions research/r437-fixed-pair-cse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Remove duplicate ancestors from fixed PAIR coefficient evaluation

This package pairs local-ring coefficient algebra with compiler
common-subexpression elimination. It changes the actual serialized
`children.coefficient` path through a guarded, package-local `Callback.weight`
adapter. When the actual prepared fallback permutation fixes a head field,
two identical ancestor requests become one. The ancestor still runs, and the
inverse/unit check and both multiplications remain: malformed high fields and
nonunit ancestors are not hidden by premature algebraic cancellation.

For d consecutive fixed-head PAIR descriptors, preparation calls decrease from
`2^d-1` to `d`. Actual admitted nonzero-high-lift fixtures at d=1,2,3 verify
`1,3,7 -> 1,2,3`. At d=3 the entire coefficient call uses 2,228,010 record actions
instead of 2,840,912, a 21.57% reduction; both admissions, extension, stacks,
erasure and restoration are included. Numerical word actions decrease from 90,711,429 to 39,007,018 (57.00%)
on the same fixture; they are separately recorded in RESULT.json. The existing eleven record tapes and numerical backing suffice.
This is a measured fixture saving, not a full multiplication runtime claim.

The proof covers arbitrary accepted stable inputs and prime-power high lifts;
the shortcut is selected from the actual permutation, not inferred from a low
class. Nonfixed PAIR, reverse tail, GOOD, UNIT and half-unit branches retain their
contracts. General nonfixed trees may still branch exponentially. No runtime
coordinate is decoded into Python control, and no dynamic native cache is added.

The complete component invoice remains
`K_CSE = A_parent + E + A_leaf + W_CSE + N + D`.
Three physical leaf ADDs still require **six independent coefficient calls**,
with four positive and two negative-inverse calls. Admission scanning, matrix
preparation, source production, payload traversal and original-width stock are
not free. PR4011's separate admission cursor is not assumed in these measurements.
The selected conditional kappa remains 0.001672660197076918.

The finite fixtures are admitted rank-seven definitions in the exact physical
runtime, not an independently reconstructed full R437 source catalogue. An
actual-R437 occurrence census, complete physical payload replay and all caller
costs remain open. See PROOF.md for the sufficient-capacity error boundary;
source bytes and inputs must remain stable during execution.

## Replay

```
python3 -B scripts/research_package.py --package research/r437-fixed-pair-cse
python3 -B research/r437-fixed-pair-cse/verify.py
python3 -O -B research/r437-fixed-pair-cse/verify.py --quick
python3 -B research/r437-fixed-pair-cse/verify.py --export
```

The verifier never regenerates RESULT.json. Normal checks compare original and
adapted complete calls against an independent local-ring matrix oracle, with
Word.inspect forbidden in runtime. Controls cover malformed ancestor high digits,
nonunit root, false fixed-permutation guard, changed source/AST, false receipt,
missing input and symlink input. The export uses exactly declared inputs and the
package, without Git. All executable pins are canonical-main inputs; pending
predecessor PRs are attribution/motivation only.

## Open next questions

* Compose this adapter with PR4011's admission cursors on a source-bound pooled
R437 request, preserving six independent calls, actual raw-source precision,
and physical call/return. Start with the rank14 pooled request from PR4010;
source/stock and full payload tariffs remain blockers.
* A stronger cancellation could use PR4008’s actual-source unit recurrence and
credited `Page.child_weight` algebra, but only with a source-bound certificate
that every skipped validation and unit failure has already been discharged.
First price that certificate and its admission/cleanup; distinguish a generic
admitted context from an actual selected context. No such cancellation occurs
in this adapter.
* For nonfixed PAIR trees, measure repeated `(level, coordinate)` states and price
a genuine encoded DAG/cache. A free host-language dictionary is not an answer.
* Measure how frequently the actual R437 prepared permutations fix requested head
fields, and then incorporate this weighted saving into the complete invoice.
This package does not supply that frequency or a new kappa.

## Credit

Chris R / Clear1nsight, with substantial OpenAI Codex assistance and same-session
AI cross-review; no independent human or formal-kernel acceptance is claimed.
The physical coefficient runtime and normal forms retain source527,
PR2160/2159/2234/2310/2332/2405, Jose Manuel's PR2697 and David Arias's PR2753
credit. The current stream and remaining bill build on zxv's PR3690, Chris R's
PR3967, PR3950 and PR4008 (`70c5ed674c7dc1c339254bae3818dd52a0015ac1`).
PR4008 identified duplicate fixed-PAIR ancestors and the six-call physical bill;
this package implements and proves the guarded shortcut. PR4011
(`fc1426353de3389409a27e5b9bc146a95edf811c`) independently optimizes admission,
which remains unchanged here. Nick Petalas's PR2989/3041 and commdata2338's
PR2399/3223 retain their conditional correspondence/substitution/stock credit.
Apache-2.0; frozen predecessors and the selected frontier are unchanged.
Loading