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
3 changes: 3 additions & 0 deletions research/fraction-native-qualification/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
work/
*.so
4 changes: 4 additions & 0 deletions research/fraction-native-qualification/GETTER-SHAPES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"numerator": "2223091528d16d7797026549874741a186c586604b625862f0c09b4baadafdcf",
"denominator": "dba448f5b021e71de33e6a5b388bac53022b886e7d8cb0ca59577ff038467efd"
}
3 changes: 3 additions & 0 deletions research/fraction-native-qualification/NATIVE-SOURCE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sha256": "78ed2e240ee40ce4989a4718e77e8b3967b092d2bf8c900124a26942c98a14cb"
}
9 changes: 9 additions & 0 deletions research/fraction-native-qualification/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Fraction arithmetic primitive profile and bounded contribution-table feasibility
============================================================================
Original Fraction/error arithmetic: Ali Romman, retaining Adam Gall/ywz65/PR2878, PR5826/5819, Mason Hale/PR5811 and all P104/native/compiler/precision notices. Full PR5848, PR5831 and nested source archives are unchanged. Apache-2.0.

New primitive profiling, exact local table, finite/key/capacity/failure checks and complete-cost screen: Chris R / Clear1nsight, substantial OpenAI Codex assistance; no subagents or independent human/kernel acceptance. Memoization is a standard technique. PR5848/5839 supply the qualifier/Linux baseline; PR5816/5818/5832/5761 retain tooling and test-repair credit with original authorship. The prior zero/unit negative artifact71f22c77b393e5cc14925c771894dc1a92c8443c supplies source-binding and finite-fixture lineage. No complete performance or kappa improvement is claimed.

Source-bound entry type gate: Chris R / Clear1nsight with substantial OpenAI Codex assistance; no independent human or proof-kernel acceptance. Parent table/finite bytes retained exactly from df9dc4c89b31494f1390d16b9ca2a15e5946e853 (PR5852). Publication agents handled only earlier branches, not this scientific test.

Native cache/context, source-bound slot/compact-key integration and complete cold-build qualifier: Chris R / Clear1nsight with substantial OpenAI Codex assistance and GPT-6-astra xhigh static review. The original Fraction miss arithmetic and independent exact integer engine are unchanged. C API/reference-counting/memoization are standard techniques. Preserve all inherited authors and Apache-2.0 notices. The C helper is new code; it does not port CPython arithmetic. Local measured timings are not a universal speedup or hosted performance validation. No kappa claim.
37 changes: 37 additions & 0 deletions research/fraction-native-qualification/PROOF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Equivalence and complete-cost obligations

This is a source-bound implementation argument for the frozen PR5848 qualifier, supported by exact finite/actual comparisons and local cold-process measurements. It is not a formal proof of arbitrary Python callbacks, a multiplication theorem or a kappa admission.

## Entry domain and arithmetic

Retain the predecessor's conservative identity-only exact-container/type predicate. For that domain, induction through empty rows, INIT/CLEAR resets, F(1) injections, SCALE and ADD/COPY gives exact Fraction row coefficients. Weights are exact Fractions. Stable standard Fraction operations on exact operands return exact Fractions. Unknown/custom domains retain the checked generic behavior. Native selection additionally requires valid distinct source/destination rows, sufficient source-site metadata, and well-formed exact-Fraction scalar slots; other such cases use the literal original trace so error type/message/order are preserved.

The canonical numerator/denominator property getters are bound to their pure executable shapes, owned member descriptors and ordinary object attribute lookup. Before each trace, identity/code/presence freshness is rechecked. Getter, slot or lookup drift selects the literal original. The miss callback is extracted from raw class MRO dictionaries only after verifying an exact staticmethod descriptor, exact FunctionType, no closure/defaults, the literal original compute code shape and captured builtin abs. A foreign descriptor is not invoked to inspect it. Nonqualifying callbacks select the checked parent path, allowing retained corruption controls to detect altered arithmetic.

Each successful miss computes exactly `value = old + q*v`, `change = abs(value)-abs(old)`, then returns `(value, change*a, change*c, change)`, with the original Python Fraction operations. The native helper does not implement rational arithmetic. Cached values are immutable exact-Fraction tuples under the predecessor's stable-input/runtime premise.

## Complete key and FIFO invariant

The key is `(old_n,old_d,q_n,q_d,v_n,v_d,weight_token)`. Per-trace tokens are assigned injectively to complete `(a_n,a_d,c_n,c_d)` pairs using full Python integer equality after hash comparison, bounded to 16,384 distinct pairs with no recycling. Equal canonical weights share a token; unequal pairs cannot. Metadata is indexed by original source site i, not event position. Event owns q and its canonical key components. Overflow or invalid metadata selects original behavior.

Initially dictionary and fixed ring are empty. Each dictionary entry has exactly one owned ring-key reference, with `used` resident entries and `head` at the next insertion/oldest eviction slot. Hits return an owned reference to the dictionary result and do not reorder the ring. A miss increments the same counters and performs original computation before eviction. At capacity, delete the oldest dictionary key and clear its ring reference; then insert and advance. Failed computation never evicts or caches. If insertion itself fails after eviction, the ring/dictionary remain consistent with a smaller cache, and the error propagates. Counters are bounded against C signed overflow. Per-trace Cache objects are fresh; only code is reused in a process.

## Coefficient-loop correspondence and native ownership

The complete literal source loop is authenticated before replacement. Native apply uses the actual Python dict-items iterator, preserving order and its size/key mutation errors. Each item tuple holds source index/value strongly across callbacks. Each iteration constructs F(0), obtains the destination's old coefficient, gets the exact contribution tuple, performs the three ordered PyNumber_InPlaceAdd updates and updates/removes the destination exactly as the Python loop. Checked score retrieval and strong temporary references remain safe around Python callbacks. Rounded injection, score peaks, witness capture, stream hashing and return structure remain in the unchanged outer source.

Cache owns dictionary, ring, immutable metadata snapshots, callback, descriptors and Fraction class. Event owns Cache and q context. Constructor tokens use checked owned reads, not unchecked reads from a mutable caller list across allocations. Partial initialization, error exits, GC traversal/clear/deallocation and Event-outliving-Cache cases are covered by source review and finite checks. A busy guard rejects reentrant mutation; errors reset it. Descriptor reads stop at the first failure. These defenses protect the packet API; the wrapper's semantic qualification is still required.

The loader authenticates C bytes, copies exactly those bytes into an owned read-only build snapshot and compiles that snapshot. Loaded-code reuse requires the same authenticated source digest. Builds occur in a fresh temporary directory per complete candidate process, with explicit cleanup. Every fresh complete process pays compilation, linking, loading and validation. There is no system installation, persistent compiled-answer cache or native arithmetic shared with the independent integer engine.

## Complete caller and oracle boundary

The new full entry authenticates the complete readonly PR5848 export and changes exactly the sole actual noisy_precision error_trace immediately before the existing Observation wrapper. The separately loaded reference/integer engine, source contract, all reverse checks, 120 finite fixtures, six controls, final receipt and original Observation finite tests remain unchanged. Capture by program length is scoped to this exact frozen source, which calls error_trace once; it is not a general caller-identification rule. The full native output digest and exact cache counters are required in addition to the original complete scientific comparisons.

The new native finite stage runs before the original complete entry in every timed C command. All 964 comparisons / 73 inherited +45 native controls are charged. The four inherited custody checks remain separate registered-verification obligations, just as in the predecessor benchmark. Independent backends do not share mutable caches or answers. Complete normal/O and exported-source replays supplement the finite gate.

## Economics and limits

The immutable-code build is shared only between the new finite stage and actual trace inside one process. The complete outer process is measured with GNU time, so compiler/linker child CPU is included. In six fresh serial B,C,C,B,B,C processes, wall medians are 40.516156 and 32.771297 seconds, CPU medians 40.33 and 32.74 seconds: 19.1155% and 18.8197% saved, passing both declared 15% gates. All observations, source inventories, stdout/stderr and failed harness attempts are retained. This evidence is specific to the frozen fixture and recorded Linux/CPython/GCC environment; inner trace timings, cost models and hosted finite replay are distinct claims.

Static/API review by GPT-6-astra xhigh ran no compiler or numerical replay. Chris R / Clear1nsight with substantial OpenAI Codex assistance performed the single serial numerical execution. Original arithmetic/provenance remains Ali Romman and all retained predecessor authors; see NOTICE. No kappa or selected metadata changes.
62 changes: 62 additions & 0 deletions research/fraction-native-qualification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Native bookkeeping for complete PR5848 qualification

The complete frozen qualifier runs in **32.77 rather than 40.52 seconds median wall time (19.12% less)** and **32.74 rather than 40.33 seconds median CPU (18.82% less)** on this Linux host. Each candidate command includes every new finite/native check and a fresh compile, link and load. Compiler-child CPU is counted. This is a local six-process B,C,C,B,B,C comparison, not a universal speedup or hosted performance result.

This opt-in package follows [PR #5848](https://github.com/CrocSwap/integer-mult-bounds/pull/5848), [PR #5852](https://github.com/CrocSwap/integer-mult-bounds/pull/5852), [PR #5853](https://github.com/CrocSwap/integer-mult-bounds/pull/5853) and the [entry-domain handoff](https://github.com/CrocSwap/integer-mult-bounds/pull/5852#issuecomment-6436191164). It changes verification implementation; it makes no kappa, construction, physical-cost, compiler or selected-frontier claim. Kappa research remains paused.

## What changes

An exact 16,384-entry per-trace contribution table avoids recomputing pure Fraction contributions. Bounded injective tokens represent complete canonical weight pairs, always indexed by the original source site i. A small C extension implements the exact seven-integer key, FIFO bookkeeping and coefficient-loop control. It uses authenticated Fraction descriptors and ordinary Python C APIs, retaining the GIL. The original Python Fraction callback computes every miss; all three score additions still use Python numeric operations in their original order. Per-coefficient F(0) construction is deliberately retained.

Rows, rounded injections, ideal metadata, full output comparisons, signed witnesses, peaks, hashes, reverse checks and the independent exact integer backend remain active. Mutable caches and answers never cross traces or backends. Only loaded immutable native code is reused within one fresh process; each fresh process pays its build. Unsupported or changed native packets use the inherited checked path or literal original trace under the documented domain rules. A platform without the required compiler/headers fails native qualification explicitly.

## Frozen sources and coverage

Canonical main: `de5ec2e7a6074068452f45b1a191b5c72832df4a`, priority 8. Complete PR5848: `66fb6c6b8683b37967e9d7f313b3df99a49d2406`. Its 97-file official export remains byte-for-byte unchanged. The source manifest pins all 12 retained inputs to own ancestor `2ebc3a071c62fc839aaed1291220d78a317395d4`. The separate inherited test-only PR5761 repair retains its exact author/commit credit; no shared test is weakened here.

- **964** complete finite comparisons on 241 programs at four capacities, with full values, numeric types and input preservation.
- **73** inherited controls and **45** native controls, covering collision equality, FIFO wrap, exceptions, source/runtime drift, fallback, metadata ownership, cyclic GC, re-entry and malformed C API packets.
- **Four** unchanged predecessor source-custody rejection checks in registered verification, separate from both timed candidate.py stages as in PR5848.
- Complete independent qualification on **25,984 events / 799 coordinates**, including all 120 inherited independent finite fixtures, six source controls, full actual ideal/error outputs and witness comparisons. Actual output SHA256: `954c7448ff74d78753828e9623ad44c46da9e5ce459420b6e50a5d47294250b9`.
- Complete optimized qualification also passes. The C native actual path preserves 2,579,750 calls, 2,252,966 hits, 326,784 misses, 310,400 FIFO evictions and 3,587 weight tokens.

The native API accepts validated packets from the source-bound wrapper. Its error/lifetime checks are memory-safety defenses, not a theorem that arbitrary callbacks or noninjective supplied tokens have Fraction semantics. The proof assumes stable inputs/runtime during a trace, matching the predecessor. Full-C-API support is the tested CPython 3.12 ABI; this is not abi3, subinterpreter or free-threaded support.

## Reproduction

Tested on Linux x86_64, CPython 3.12.3 and GCC 13.3. An existing `cc` and Python 3.12 development headers are required; no dependencies are installed and no compiled binary is committed.

Registered finite/native/source verification, about three seconds here:

```sh
python3 -B scripts/research_package.py --package research/fraction-native-qualification
```

Explicit complete guarded replay, about 33 seconds here. Choose a new evidence directory outside the package; it retains stdout, stderr, timing, source inventory and RSS receipts:

```sh
python3 -B research/fraction-native-qualification/replay.py /tmp/native-qualification-evidence
```

Fresh complete timing round, first pair then the remaining fixed-order repetitions only if the first pair passes both 15% gates:

```sh
python3 -B research/fraction-native-qualification/benchmark.py pair /tmp/native-qualification-benchmark
python3 -B research/fraction-native-qualification/benchmark.py remaining /tmp/native-qualification-benchmark
```

The same default 180-second command / 1 GiB sampled process-group RSS / 600-second initial round and 1,500-second shared-round contract applies. One serial runner, zero automatic retries. Do not infer complete performance from the inner `qualify.seconds`: it excludes the preceding native finite/build stage. The outer GNU-time receipt is authoritative and includes compiler children. The original raw timing driver and every observation are retained under `evidence/runtime`; the portable wrapper changes evidence/source path resolution only.

## Findings, failures and limits

The earlier table, entry gate and compact keys were correct within their tested domains but failed their complete-cost screens. Cache-only C lookups were slightly slower than the Python slot-key parent in the fixed micro screen. The full coefficient-loop mechanism subsequently passed a complete actual audit and the complete timing gate. Do not discard those negative results or credit all improvement to C alone: the candidate combines the exact table, source-bound entry/compact/slot mechanisms and native bookkeeping.

The first debug attempt passed scientific checks but stopped on a temporary-directory cleanup ResourceWarning. Explicit cleanup fixed it without suppressing warnings. A later forced-GC constructor fixture was inert: its callback did not run during construction, so it did not demonstrate the intended interleaving. That failure and draft remain; a deterministic metadata-ownership test replaced it. Checked constructor token reads remain a source-reviewed safety condition. No empirically exercised constructor-GC interleaving is claimed. All attempts are retained; no automated retry or timing sample was dropped.

The source reviewer is a user-requested GPT-6-astra xhigh agent and performed static review only. All compiler and numerical execution used one parent runner. This is assisted engineering verification, without independent human or proof-kernel acceptance. Registered hosted replay covers finite/native/source checks; it does not itself freshly establish the local complete-performance measurements. See [PROOF.md](PROOF.md), [VALIDATION.json](VALIDATION.json), the [complete timing gate](evidence/runtime/GATE-6.json) and the retained static reviews.

## Open next questions

Can a further source-bound reduction in the remaining coefficient/score bookkeeping pay its additional validation bill? First census the new candidate, refresh upstream overlap and name one bounded feasibility test. Keep this measured candidate frozen during publication. A new arithmetic implementation would require a broader independent proof and validation bill; it is outside this contribution.

Original mathematics/arithmetic: Ali Romman and all retained P104/native/compiler/precision authors; see NOTICE and nested archives. New profiling, table/domain/compact/slot integration, C helper and validation: Chris R / Clear1nsight with substantial OpenAI Codex/Astra assistance. Apache-2.0.
Loading