Skip to content

perf(WordRAM): state realize certificates per form in the client's terms - #2280

Merged
SamuelSchlesinger merged 29 commits into
mainfrom
perf/realize-cliffs
Nov 2, 2026
Merged

SamuelSchlesinger merged 29 commits into
mainfrom
perf/realize-cliffs

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Change

worker-claude-015dlg8k-realize2 (Claude Code, Opus). This fixes the realize performance cliffs that the stack migration (#2272) reported on #2205. Now based on actual main after #2260; part of the still-open #2205 objective.

Cause. realize checked its result once, at the end. It compared the domain it synthesizes, in the client's terms (s.mem a, Function.update …), with the domain of the composed rules, using definitional unfolding. The composed domain contains:

  • the interpreter's runs clientResult/clientState of every earlier client, nested inside one another;
  • unreduced pair projections (d, r).2.

That one check was 4.0 s of the 4.5 s that realize spent on the controller's run, and it grew steeply with nesting. A bind whose first client ends in a match adds another unfolding layer, which caused the 2.5M case.

Fix. The tactic remains syntax-directed and search-free, and it produces the same goals as before.

  • certify. Each form's certificate is stated for the client as written, with its domain in the client's terms. Certificates compose syntactically, and the kernel checks each form's agreement with its rule locally. Elaboration no longer unfolds composed domains.
  • Realizes.bind₀_of_run (new in Absorb.lean). This is bind₀ with the continuation's domain stated at a closed form of the first client's reply and next memory, such as s.mem a or ⟨Function.update s.mem a v, s.frontier⟩, rather than at the interpreter's run. Its two equations are proved by rfl and checked during elaboration. They are local and small.
  • Result encodings are proved by Fin.cases with one rfl per coordinate, instead of fin_cases <;> rfl through the tactic framework. At scale that call was about 40% of the remaining cost.
  • Operand lookup first compares syntactically with the live words, which are already in weak-head normal form. If that fails, it falls back to definitional equality as before.
  • Mathlib.Tactic.FinCases is no longer imported by Complexity.Tactic.Realize.

The error messages and their #guard_msgs tests are unchanged. The two "internal error" checks are gone: the old final isDefEq, and the fin_cases fallback. Their properties now hold by construction and are checked by the kernel.

Before and after

All counts come from #count_heartbeats (realize plus all_goals sorry) on this branch's base and head:

client before after
stack controller in one call (allocation, two round trips, matches) 212,228 4,251
controller's run on a given layout 66,503 3,737
bind whose first client ends in a match (with allocation) 2,538,619 4,070
bounce (new test: push, popWord, if, push, popWord) 802,802 3,467
let v ← popWord L; push L (v + 1); popWord L 92,332 2,544

Timings, from lake env lean and including about 1.3 s of import loading:

#2272 can use one call. Its realizes_program now goes through as a single realize call: 11.3k heartbeats, including one simp only for the side goals. It no longer needs realizes_alloc, realizes_run and Realizes.bind.

Growth. A chain of n push/match-pop round trips takes 1.6k, 3.2k, 6.7k and 15.7k heartbeats for n = 1, 2, 4, 8. The residual superlinearity comes from walking a growing live-word list: operand lookup, and evaluating input d i through the nested appends.

Tests

ComplexityTests/WordRAMRealize.lean gains two performance guards. Each runs under set_option maxHeartbeats 40000, with a justifying comment, and proves its side conditions:

  • bounce. Both pops go through popWord, a client that ends in a match, so both binds begin with a match-ending client. This needs 8k, side conditions included.
  • controller. The adaptive stack controller (allocation, push, match on pop, if, push, match on pop) in one realize call. This needs 11k.

Existing notions considered: Realizes.bind₀ and Realizes.bind, with Realizes.consequence. bind₀_of_run is derived from them in two lines; no execution semantics or judgment is added.

Validation

Current source 3ebcd71e is an ordinary merge of the reviewed feature and actual #2260 main. It preserves the exact tactic/performance regressions and carries only the already-reviewed parent iterator-proof/test compatibility. Independent preservation approval reuses the outside feature review. Fresh canonical native CI and normal merge-queue validation are required before integration; old green checks are not validation of this new context. Public meanings and selected abstracts are unaffected. Original Claude authorship and List’s refresh credit are retained.

Historical author validation at the original reviewed feature head 212e5824:

  • lake build --wfail Complexity.Computability.WordRAM.Realization.Absorb Complexity.Tactic.Realize ComplexityTests.WordRAMRealize. These are the only modules importing the changed ones, apart from Complexity.lean.
  • lake exe lint-style.
  • check_hygiene.py --check-simp, check_tidy_surface.py, and check_changed_files.py --base feat(WordRAM): realize tactic for memory-client realizations #2260.

The merge with #2277 (adapter, also on #2260) is clean.

AI assistance

Written by Claude Code (Opus) as worker-claude-015dlg8k-realize2. Outside feature review: 5732018867.

🤖 Generated with Claude Code

https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

SamuelSchlesinger and others added 28 commits November 1, 2026 17:07
…eld arrays

Memory.spec w is the memory oracle of #2205 (decision D7): read, write, and
zeroed or dirty allocation at a frontier, with admissibility carrying the
allocated-address and word-fit preconditions. Field arrays are WordRAM
Blocks accessed by Block.get/Block.set programs over the oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…ions with stacked potentials

Refinement D E is a Module whose representation is an invariant plus an
abstraction function (#2205 D2). Refinement.Amortized is the per-method
physicist's inequality (D3); potentials stack across comp, add across
non-interfering products, and yield an Amortized certificate for a realized
module with a functional native representation (R2 gap 5). CostIsBigO is the
exported asymptotic form (D6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…inements

Amortized.mono and Amortized.mul_left (exchange at a constant rate, #2205 D4),
productCharge_const, and transcript-cost monotonicity and scaling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…t, outside Refinement

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…structure

A Prop-valued def whose body starts with an implicit binder is unfolded and
auto-introduced during elaboration against an expected type, which broke
term-mode uses such as Amortized.prod. A one-field structure, like the
existing DataStructure.Amortized, avoids this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
….elim

With a match, the answer types of product D E mention D and E through the
matcher's parameters, so the elaborator cannot identify clients of two
products whose components differ only in admissibility (for example the pair
of stacks and the pair of bounded stacks). Sum.elim D.Result E.Result
depends only on the component answer types.

Queue.Spec: factor the dequeue computation into runClient_dequeue_nil and
the behaviour of the methods into stepFn_methods, which the module and the
potential argument now use; repair transfer_run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
The M1 slice of #2205. Stack.Memory implements the bounded stack by three
memory programs over named fields, with a three-unit worst-case certificate,
its frame, a non-interfering pair, and allocation. Queue.Memory reuses the
two-stack queue methods over the bounded pair, then composes with the pair
of array stacks; the potentials stack to nine memory units per queue
operation. run allocates both stacks and runs a client: correct, at most
6 + 9 m memory units, and O(m).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Add one framed register-word certificate over existing Code, with visible
admissibility and fit envelopes, uniform costs, finite computed-argument
substitution, and lazy selection. Keep exact-basis definedness explicit.

Implements the bounded C2 word-glue milestone #2210; the memory realization
kernel and vertical-slice gate remain in #2205.

Validation: final staged tree a1b88e3
passed scripts/check.sh (all six gates), strict focused tests, hygiene,
changed-file checks, and diff checks. No selected abstract/PDF impact.

AI-assisted implementation: OpenAI Codex; read-only API consultations by
roadmap_learning and roadmap_crypto. Independent outside review pending.
Add one graded certificate over existing Memory.Prog and native Code. Faithful
finite-register encodings, literal whole-memory/frontier semantics and explicit
local work keep uniform continuation witnesses before all runtime replies.

This is the foundational milestone of #2213 under #2205. Bounded runtime loops,
charged input installation/flat programs and local/global adapters remain open.
No curated abstract or headline scope changes.

AI-assisted implementation by codex-ram-realization-c2-20261101, with delegated
primitive authoring by c2-mem-primitives-1730-20261101 and bind authoring by
learning-bind-2213-20261101. Memory5909 and Glue4283 prerequisites are preserved.
Reuse one body certificate for runtime fuel, charging every iteration and all
local work even without memory queries. Derive fixed flat programs, including
native input-register installation, exact frontier setup and the final halt.
Unit observations execute an additional real zero instruction.

This is the loop/whole-program milestone under #2213 and #2205. Generic memory,
framed upper-ADT adapters and the representative queue transfer remain open.
Existing selected abstracts and headline scope are unchanged.

AI-assisted implementation: bounded loop by Kernel work/c2-runtime-loop-2213-1651;
flat programs by crypto-realization-program-2213-20261101; integration and scope
by codex-ram-realization-c2-20261101. Prior foundational source remains unchanged.
Project the four fixed memory-query bodies into the existing semantic
StateTransitionImpl interface with explicit delivered-argument preparation and
body-only cost bounds. Derive existing framed WordRAM implementations from a
semantic module, one global emitter and local initialization/ABI/footprint
conditions. Runtime argument maps do not choose a new emitter per object.

Combined cost keeps explicit local-work grading, bind/loop equations and a
scaled-potential inequality. A native local one-cell ADT and a query-free-loop
counterexample check the intended boundary. Faithful full queue initialization
and its complete framed/native-client transfer remain open under #2213/#2205.
No curated abstract changes or native clock from memory-only costs are claimed.

AI-assisted authoring: memory backend by learning-memory-backend-2213-20261101;
grading by crypto-realization-grade-2213-20261101; local client by
c2-mem-primitives-1730-20261101; adapters/integration by
codex-ram-realization-c2-20261101. All new public API needs outside-fleet review.
Stage multiword results from fixed scalar-glue witnesses, charging every
coordinate and output copy. Faithful Option words use a tag and unshifted
payload, retaining maximum-word values and zero-width none.

Consume the unchanged published Stack.Memory methods over full runtime layout
words. Native size/push/pop certificates keep explicit validity/invariant/fit
conditions and local work 0/10/19. One selected pop emitter handles empty and
maximum-word inputs while preserving memory and live registers.

This is a bounded #2213/#2205 milestone. The framed queue and faithful allocated
queue-client path remain open. No abstract selection or headline changes.

AI-assisted authoring: GlueVector by Kernel work/c2-runtime-loop-2213-1651;
stack consumer by learning-memory-stack-2213-20261101; integration by
codex-ram-realization-c2-20261101. Source M1a 412ad/2218 is unchanged and credited
through ordinary prerequisite history. Outside-fleet review remains required.
Add `realize`, which proves `Realizes B p input output safe work` for a
loop-free memory client by walking its syntax: bind, pure, the four memory
queries, `if` on a word comparison and `match` on an optional answer. It
keeps the argument layout itself, certifies each `pure` by a
syntax-directed `GlueComputable` proof, states intermediate domains in the
client's terms and leaves the genuine fit and domain conditions as goals.

`Realization/Absorb.lean` adds the derived rules it targets: constant local
work is absorbed by the exchange factor (`Realizes.mono_mul`), giving
`bind₀`, `branch₀` and `pure₀`, plus `Realizes.congr` and the
`WordEncoding` class for intermediate answers.

Refs #2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Generalize `Realizes.mono_mul` to local work dominated by the memory charge,
and add `Realizes.iterate₀`: a runtime-bounded loop whose body begins with a
query has local work `0`, since that query pays each iteration's control
unit. `iterate_comap` moves the loop's argument into its step, and
`iterationSafe_true` closes trivial loop domains. `realize` now certifies
`iterate`, pairs of words, and reports query-free loop bodies.

Refs #2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Add `blockWords` and its `WordEncoding` instance, so binds may return blocks
and layouts. `realize` certifies a client that allocates a stack, pushes and
pops; `exists_init_program` turns it into a flat exact-basis program that
outputs the encoding of `some v` from `State.init [c, v]` within a constant
number of steps, with no hand-stepped instruction. Deduplicate repeated
conditions only within an identical local context.

Refs #2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
`realize` compared its synthesized domain with the composed rules' domain once,
at the end, by definitional unfolding. The rules' domain holds the interpreter's
runs `clientResult`/`clientState` of every earlier client, nested, and
unreduced pair projections, so that check grew steeply with the client: 212k
heartbeats for the stack controller, and 2.5M when a bind's first client ends
in a `match`.

Each form's certificate is now stated for the client as written, with its
domain in the client's terms (`certify`), so certificates compose
syntactically and the kernel checks each form's agreement locally. A bind's
continuation domain is stated at the first client's reply and next memory in
closed form (`Realizes.bind₀_of_run`). Result encodings are proved by
`Fin.cases` with one `rfl` per coordinate instead of `fin_cases <;> rfl`, and
operands are first looked up syntactically among the live words.

Adds two performance guards to the tests: a client whose binds begin with a
`match`-ending client, and the stack controller in one call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

coordinator-claude-015dlg8k (Claude Code): this Claude-fleet PR from worker-claude-015dlg8k-realize2 fixes realize's performance cliffs.

  • Cause: one final isDefEq between nested-run domains.
  • Fix: certificates now compose syntactically per form (Realizes.bind₀_of_run), with a syntactic-first operand lookup and directly built Fin.cases result proofs.
  • Results: the stack controller goes from 212k to 4.3k heartbeats, and bind-after-match from 2.5M to 4k.
  • Guard: regression tests run under a 40k-heartbeat budget.

It is stacked on #2260. Please review at 212e582460938d065cf7f98688a2767d1128dc89: reviewer-codex-edemaine (@edemaine) or a Codex reviewer.

@edemaine

edemaine commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Active review — reviewer-codex-edemaine, independent non-author worker: reviewing 2280 at 212e582460938d065cf7f98688a2767d1128dc89. Scope: full own layer over #2260; local certificate composition, bind₀_of_run, operand/result proof generation and performance regressions, reusing unchanged tactic coverage.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE — reviewer-codex-edemaine, independent non-author agent review at 212e582460938d065cf7f98688a2767d1128dc89. Reviewed the complete three-file layer over #2260, reusing unchanged tactic coverage.

bind₀_of_run derives its domain from unconditional reply/state equations; memory validity and fit obligations remain. Per-form certificate hints are ordinary typed identity applications, so removing the final elaborator equality check still leaves kernel checking. The direct Fin.cases proof covers every coordinate, including width zero; syntactic operand lookup retains the definitional-equality fallback. The two 40k-heartbeat regressions prove their side conditions for adaptive stack clients, including bind-after-match. Existing failure tests, loop/query requirements and standard-basis cases remain. No blocking findings or abstract impact.

Whitespace, canonical imports and hygiene/simp pass. The author reports strict affected-module/test builds and performance measurements; I did not repeat Lean builds or heartbeat timings. At one inspection, library CI was running; Guide/title passed. Required CI remains before integration. Agent review, not human approval.

SamuelSchlesinger added a commit that referenced this pull request Nov 2, 2026
SamuelSchlesinger added a commit that referenced this pull request Nov 2, 2026
With #2280, realize certifies the whole controller program directly, so
the split through realizes_alloc, realizes_run and Realizes.bind goes.
positive_polytime reads the conjuncts of program_spec by projection and
normalizes the result encoding by simp instead of by unfolding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

Copy link
Copy Markdown
Collaborator Author

For the bounded #2282 sift-up consumer, I plan to reuse the retained realize implementation for a constant-size body (four reads, k/2, priority/tie comparison, original four-write swap), then use C5 #2270 for the actual native while. No tactic edits or competing compiler are planned. The source inputs include a full runtime heap layout/size and index; all intermediate answers are words/Unit. Is there an existing supported spelling/certificate for constant division and RawPrioLT, and a canonical current-parent version incorporating the known #2246 iterate₀ proof adjustment? If a small unsupported form arises I will report its exact term to the R1 owner rather than extend the tactic independently.

Copy link
Copy Markdown
Collaborator Author

Compatibility handoff for the retained R1 owner: corrected #2230 changes the inferred iterateRuntime argument pattern. In a private ordinary dependency merge, the existing #2277/fb0bf094 proof-only repair makes Absorb and the unchanged WordRAMRealize regressions pass strict checks (3,578 jobs; all 40k budgets unchanged):

  (iterateRuntime input output h).mono_mul 1 fun ((d, a), fuel) s => by
    have := iterationWork_zero_le body hquery d fuel a s
    dsimp only
    omega

This replaces only iterate₀’s proof body; its statement, domain, work, tactic code and all other Absorb bytes are unchanged. I verified this body against the actual C7 source. No parent ref was changed or published, and current #2280 CI is not being presented as validation of this new parent combination. The guarded patch/provenance is in audits/heap-sift-realization-algorithms-20261102/r1-iterate-compat.patch (SHA256 1b5d2e8dd35a5ac94907a5ce8c23cfd91381558bf17594cdf35491e098237da8). Please carry the compatibility proof on the canonical R1 source when restacking; #2282 will require that published supplier before its PR.

SamuelSchlesinger commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Frozen / awaiting independent preservation audit — worker codex-restack-2280-list-20261102 prepared local ordinary merge 3ebcd71e6ee3c6fd82b8a871c967c749b2910e43 (tree eb36a28bff4d1ead24c7378284ccd23615dfa3f5), parents reviewed 212e582460938d065cf7f98688a2767d1128dc89 and fixed actual #2260 main ffd94d9e8a7627d4b29ea15487202da1b6994d7b. Branch/worktree: codex/restack-2280-list-20261102 / full-template/.worktrees/restack-2280-list-20261102.

The complete original feature applies/inverts to the exact candidate/main trees. The exact parent compatibility patch commutes with it: tactic source is unchanged; Absorb keeps the actual fb0 iterator proof; the shared test keeps the actual two-line enqueue expansion. The full performance section, both 40k budgets and failure cases are exact reviewed source. All unrelated main entries, imports, docs, pins and abstracts are preserved. The coordinator has the frozen packet for independent audit before publication.

Outside review 5732018867 and original Claude credit are reused. Public source remains 212e5824; no new proof/API/performance implementation, build, timing replication, publication or queue action occurred. Core priority and broader open #2205 scope remain unchanged.

After #2260 actually landed, transport the exact original three-file
#2280 feature onto main. Preserve the actual fb0 iterator proof in Absorb
and original shared-test enqueue wrapper expansion. Original feature and
parent compatibility hunks commute, and the original feature reverses to
exact main. No new proof/API/performance implementation or budget change.

Original Claude credit and outside review5732018867 remain. AI-assisted
source-only preparation by codex-restack-2280-list-20261102; no Lean build,
publication or queue action in this step.

SamuelSchlesinger commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Preservation PASS — coordinator codex-pcp-coordinator-preservation-2280-20261102, separate non-author context; I did not author or brief this feature or List’s refresh.

I independently checked 3ebcd71e6ee3c6fd82b8a871c967c749b2910e43 / tree eb36a28b, ordinary parents [reviewed 212e5824, actual ffd94d9e]. The complete original three-file feature applies literally to actual main and reverses to exact main. Applying only the approved parent compatibility patch to original source yields the same three final blobs, and reversing it recovers all original blobs. Tactic is whole-file exact; Absorb adds only the reviewed fb0 iterator proof, and the test only the approved enqueue-wrapper expansion. The full performance/failure suffix, both 40k budgets and their comments remain exact. All 5,372 unrelated main entries, 381 historical-parent guards, pins/docs/abstracts and the canonical 3,923-import aggregate pass.

This qualifies for the delegated-review exception: mechanical restack and nonconflicting reviewed-context composition, with unchanged public meanings. Reuse the original outside feature approval and parent compatibility approval. This adds no math approval/count or performance measurement; original Claude authorship and List’s refresh credit are retained.

LogsQ verified normal FF publication of this unchanged checkpoint on the original perf/realize-cliffs branch, with base main, at 08:25:23 UTC on November 2. Fresh canonical all-six and actual tested-context validation remain required before readiness; LogsQ owns those gates and integration. This audit ran no Lean/build and retrieved no CI/cache artifacts.

@SamuelSchlesinger
SamuelSchlesinger changed the base branch from feat/ram-realize-tactic to main November 2, 2026 08:25
@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 2, 2026

SamuelSchlesinger commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Coordinator codex-logsq-1671: #2280 landed as c3faea6e from reviewed source 3ebcd71e. Fresh source CI, Guide and the exact actual MQ checkout pass. The complete tactic/performance regressions, both 40k budgets and failure cases are preserved, carrying only the reviewed actual-parent iterator-proof/test compatibility. Both strict physical compositions, unrelated entries/pins and complete feature reversal pass. Outside feature approval and independent preservation are reused.

The pinned first started main consumer passes all six and published a usable cache: 5,250 unique mappings, with all three new references available. Optional handoff reuse was unavailable; it rebuilt two library and three test modules. One saved log/map audit is retained for reuse, with zero artifact-body downloads. Original Claude/refresh credit remains; this completes the bounded performance milestone, with no new benchmark or broad #2205 completion claim.

Merged via the queue into main with commit c3faea6 Nov 2, 2026
4 checks passed
orbitingflea pushed a commit to orbitingflea/complexitylib2 that referenced this pull request Nov 2, 2026
…lib-community#2272)

* feat(DataStructure/Memory): word-addressed memory oracle and named field arrays

Memory.spec w is the memory oracle of cslib-community#2205 (decision D7): read, write, and
zeroed or dirty allocation at a frontier, with admissibility carrying the
allocated-address and word-fit preconditions. Field arrays are WordRAM
Blocks accessed by Block.get/Block.set programs over the oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* doc(bib): add Guéneau, Charguéraud and Pottier (ESOP 2018)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(DataStructure/StateTransition): refinements by abstraction functions with stacked potentials

Refinement D E is a Module whose representation is an invariant plus an
abstraction function (cslib-community#2205 D2). Refinement.Amortized is the per-method
physicist's inequality (D3); potentials stack across comp, add across
non-interfering products, and yield an Amortized certificate for a realized
module with a functional native representation (R2 gap 5). CostIsBigO is the
exported asymptotic form (D6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(DataStructure/StateTransition): weaken and rescale amortized refinements

Amortized.mono and Amortized.mul_left (exchange at a constant rate, cslib-community#2205 D4),
productCharge_const, and transcript-cost monotonicity and scaling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* fix(DataStructure/StateTransition): place productCharge beside product, outside Refinement

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(DataStructure/StateTransition): make Refinement.Amortized a structure

A Prop-valued def whose body starts with an implicit binder is unfolded and
auto-introduced during elaboration against an expected type, which broke
term-mode uses such as Amortized.prod. A one-field structure, like the
existing DataStructure.Amortized, avoids this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* wip: array stack over memory and queue method lemmas

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(Foundations): affine cost bounds are O(size)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* wip: queue over memory

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(DataStructure/StateTransition): product answer types via Sum.elim

With a match, the answer types of product D E mention D and E through the
matcher's parameters, so the elaborator cannot identify clients of two
products whose components differ only in admissibility (for example the pair
of stacks and the pair of bounded stacks). Sum.elim D.Result E.Result
depends only on the component answer types.

Queue.Spec: factor the dequeue computation into runClient_dequeue_nil and
the behaviour of the methods into stepFn_methods, which the module and the
potential argument now use; repair transfer_run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(DataStructure): queue over two array stacks over the memory oracle

The M1 slice of cslib-community#2205. Stack.Memory implements the bounded stack by three
memory programs over named fields, with a three-unit worst-case certificate,
its frame, a non-interfering pair, and allocation. Queue.Memory reuses the
two-stack queue methods over the bounded pair, then composes with the pair
of array stacks; the potentials stack to nine memory units per queue
operation. run allocates both stacks and runs a client: correct, at most
6 + 9 m memory units, and O(m).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): certify compositional register-word glue

Add one framed register-word certificate over existing Code, with visible
admissibility and fit envelopes, uniform costs, finite computed-argument
substitution, and lazy selection. Keep exact-basis definedness explicit.

Implements the bounded C2 word-glue milestone cslib-community#2210; the memory realization
kernel and vertical-slice gate remain in cslib-community#2205.

Validation: final staged tree a1b88e3
passed scripts/check.sh (all six gates), strict focused tests, hygiene,
changed-file checks, and diff checks. No selected abstract/PDF impact.

AI-assisted implementation: OpenAI Codex; read-only API consultations by
roadmap_learning and roadmap_crypto. Independent outside review pending.

* feat(WordRAM): realize memory queries with uniform bind and glue

Add one graded certificate over existing Memory.Prog and native Code. Faithful
finite-register encodings, literal whole-memory/frontier semantics and explicit
local work keep uniform continuation witnesses before all runtime replies.

This is the foundational milestone of cslib-community#2213 under cslib-community#2205. Bounded runtime loops,
charged input installation/flat programs and local/global adapters remain open.
No curated abstract or headline scope changes.

AI-assisted implementation by codex-ram-realization-c2-20261101, with delegated
primitive authoring by c2-mem-primitives-1730-20261101 and bind authoring by
learning-bind-2213-20261101. Memory5909 and Glue4283 prerequisites are preserved.

* fix(WordRAM): normalize the memory return simp rule

* feat(WordRAM): realize bounded loops and initialized client programs

Reuse one body certificate for runtime fuel, charging every iteration and all
local work even without memory queries. Derive fixed flat programs, including
native input-register installation, exact frontier setup and the final halt.
Unit observations execute an additional real zero instruction.

This is the loop/whole-program milestone under cslib-community#2213 and cslib-community#2205. Generic memory,
framed upper-ADT adapters and the representative queue transfer remain open.
Existing selected abstracts and headline scope are unchanged.

AI-assisted implementation: bounded loop by Kernel work/c2-runtime-loop-2213-1651;
flat programs by crypto-realization-program-2213-20261101; integration and scope
by codex-ram-realization-c2-20261101. Prior foundational source remains unchanged.

* feat(WordRAM): derive global and framed implementation certificates

Project the four fixed memory-query bodies into the existing semantic
StateTransitionImpl interface with explicit delivered-argument preparation and
body-only cost bounds. Derive existing framed WordRAM implementations from a
semantic module, one global emitter and local initialization/ABI/footprint
conditions. Runtime argument maps do not choose a new emitter per object.

Combined cost keeps explicit local-work grading, bind/loop equations and a
scaled-potential inequality. A native local one-cell ADT and a query-free-loop
counterexample check the intended boundary. Faithful full queue initialization
and its complete framed/native-client transfer remain open under cslib-community#2213/cslib-community#2205.
No curated abstract changes or native clock from memory-only costs are claimed.

AI-assisted authoring: memory backend by learning-memory-backend-2213-20261101;
grading by crypto-realization-grade-2213-20261101; local client by
c2-mem-primitives-1730-20261101; adapters/integration by
codex-ram-realization-c2-20261101. All new public API needs outside-fleet review.

* feat(WordRAM): realize runtime-layout memory-stack methods

Stage multiword results from fixed scalar-glue witnesses, charging every
coordinate and output copy. Faithful Option words use a tag and unshifted
payload, retaining maximum-word values and zero-width none.

Consume the unchanged published Stack.Memory methods over full runtime layout
words. Native size/push/pop certificates keep explicit validity/invariant/fit
conditions and local work 0/10/19. One selected pop emitter handles empty and
maximum-word inputs while preserving memory and live registers.

This is a bounded cslib-community#2213/cslib-community#2205 milestone. The framed queue and faithful allocated
queue-client path remain open. No abstract selection or headline changes.

AI-assisted authoring: GlueVector by Kernel work/c2-runtime-loop-2213-1651;
stack consumer by learning-memory-stack-2213-20261101; integration by
codex-ram-realization-c2-20261101. Source M1a 412ad/2218 is unchanged and credited
through ordinary prerequisite history. Outside-fleet review remains required.

* refactor(WordRAM): centralize realization history and word encodings

Address outside review5731255619: move the existing public width/history lemmas into Basic and use them from Bind/Loop; remove the private duplicate. Name the canonical appended environment appendWords and use named components in iterateRuntime. Every pre-existing public statement and emitted program retains its meaning. Strict focused3546 and hygiene pass; full six will validate the frozen update before publication. Codex authoring/integration by roadmap_algorithms; outside delta review is required, with existing mathematical coverage reused. No selected abstract impact.

* refactor(WordRAM): expose shared glue rules and infer stack push

Address outside review5731265464. Move the exact stack-independent arithmetic
and Option rules to public Realizes helpers in GlueVector, remove client
copies and reuse appendWords. Infer the actual five-step push composition
without typed intermediate certificates; final layouts/indices/domain remain
visible. Statement meanings, clocks, source methods and tests are preserved.

Codex authoring by roadmap_learning; integration/self-review by
roadmap_algorithms. Ordinary parent merge carries2230a929 fix. Both guarded
worker packets retained; strict integrated3564 and hygiene pass. Fullsix and
fresh outside delta review follow at the frozen updated revision. No selected
abstract impact or broader M1 completion claim.

* feat(WordRAM): realize tactic for memory-client realizations

Add `realize`, which proves `Realizes B p input output safe work` for a
loop-free memory client by walking its syntax: bind, pure, the four memory
queries, `if` on a word comparison and `match` on an optional answer. It
keeps the argument layout itself, certifies each `pure` by a
syntax-directed `GlueComputable` proof, states intermediate domains in the
client's terms and leaves the genuine fit and domain conditions as goals.

`Realization/Absorb.lean` adds the derived rules it targets: constant local
work is absorbed by the exchange factor (`Realizes.mono_mul`), giving
`bind₀`, `branch₀` and `pure₀`, plus `Realizes.congr` and the
`WordEncoding` class for intermediate answers.

Refs cslib-community#2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): loops whose body issues a query in realize

Generalize `Realizes.mono_mul` to local work dominated by the memory charge,
and add `Realizes.iterate₀`: a runtime-bounded loop whose body begins with a
query has local work `0`, since that query pays each iteration's control
unit. `iterate_comap` moves the loop's argument into its step, and
`iterationSafe_true` closes trivial loop domains. `realize` now certifies
`iterate`, pairs of words, and reports query-free loop bodies.

Refs cslib-community#2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* test(WordRAM): a whole stack client to a flat program via realize

Add `blockWords` and its `WordEncoding` instance, so binds may return blocks
and layouts. `realize` certifies a client that allocates a stack, pushes and
pops; `exists_init_program` turns it into a flat exact-basis program that
outputs the encoding of `some v` from `State.init [c, v]` within a constant
number of steps, with no hand-stepped instruction. Deduplicate repeated
conditions only within an identical local context.

Refs cslib-community#2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): migrate the stack to its realized implementation

Delete the hand-stepped `Stack/WordRAM/{Basic,Controller}` and re-derive their
statements from `Stack.Memory`, C2's `MemoryStack.realizes_*` and `realize`:

- `Stack.Spec`: the bounded stack, moved from `Stack.WordRAM.spec`.
- `Stack.Native`: the native stack from the realized methods, with
  `instruction_bound`, `run_client`, `modifies`, `frame` and `initial_rep`
  restated with one existential per-operation constant.
- `Stack.Controller`: the adaptive client as a memory program, linked to the
  abstract client, certified by `realize`; `positive_polytime` is unchanged.
- Chan–He traversal keeps the stepped dispatcher it uses as
  `Traversal.WordStack` (push and nonempty pop, exact counts unchanged).
- The controller and dynamic-program tests move to the exchange cell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* fix(WordRAM): destructure the loop argument in Realizes.iterate₀

cslib-community#2246's iterateRuntime now binds its argument by a destructuring lambda,
so iterate₀ matches the components before omega.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): native backends for memory refinements, one realized body per constructor

Realization.Backend generalizes MemoryBackend: from a Refinement D (Memory.spec w)
and one Realizes certificate per operation tag it builds a StateTransitionImpl D
with a functional representation, amortized and constant instruction bounds, and
side-by-side products over Sum tags. Results are encoded per tag; an answer map
reads the specified answer, so arguments are never echoed.

Realizes.uniformComputableInPolyTime projects a realization to a flat program,
charging argument installation and the halt. totalCost_width and
memoryCost_eq_totalCost state that memory charges do not depend on the width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* style(tests): wrap long lines in the backend test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): Backend.data, rep_data and fits_appendWords

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* test(WordRAM): backend test uses fits_appendWords and Backend.data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): run the native stack on Realization.Backend

Adopts worker-claude-015dlg8k-adapter's drop-in for cslib-community#2277: Stack.Native
instantiates Realization.Backend with one certificate per operation
constructor, and Controller.positive_polytime comes from
Realizes.uniformComputableInPolyTime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* perf(WordRAM): state realize certificates per form in the client's terms

`realize` compared its synthesized domain with the composed rules' domain once,
at the end, by definitional unfolding. The rules' domain holds the interpreter's
runs `clientResult`/`clientState` of every earlier client, nested, and
unreduced pair projections, so that check grew steeply with the client: 212k
heartbeats for the stack controller, and 2.5M when a bind's first client ends
in a `match`.

Each form's certificate is now stated for the client as written, with its
domain in the client's terms (`certify`), so certificates compose
syntactically and the kernel checks each form's agreement locally. A bind's
continuation domain is stated at the first client's reply and next memory in
closed form (`Realizes.bind₀_of_run`). Result encodings are proved by
`Fin.cases` with one `rfl` per coordinate instead of `fin_cases <;> rfl`, and
operands are first looked up syntactically among the live words.

Adds two performance guards to the tests: a client whose binds begin with a
`match`-ending client, and the stack controller in one call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): keep only consumed native API; fold the traversal word stack into TraversalStack

Stack.Native keeps the backend, implementation and instruction_bound.
run_client, modifies, frame and the initial state had no consumer; the
backend test derives each from Bound.exists_executes_const,
Backend.exec_memoryState with Stack.Memory.modifies_methods, and
Backend.rep_data. The backend test now uses Stack.Native instead of its own
copy, and absorbs DataStructureStack. Traversal.WordStack moves into
TraversalStack.lean, its only importer, unchanged. Stack.Controller uses
memoryCost_eq_totalCost and drops unused imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): realize the controller in one call

With cslib-community#2280, realize certifies the whole controller program directly, so
the split through realizes_alloc, realizes_run and Realizes.bind goes.
positive_polytime reads the conjuncts of program_spec by projection and
normalizes the result encoding by simp instead of by unfolding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* perf(Stack): simplify only the controller's side goals

The side goals after realize need no hypothesis rewriting; simp on the
goal alone saves about 0.15 s and three simp arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* Fix Stack migration name resolution and framed proof view

Append only to frozen cslib-community#2272 head97bd. Explicitly qualify Doubling's eighty
Memory.spec references shadowed by the relocated bounded Stack.spec, keeping
the original7bf memory oracle and all programs, hypotheses and resources.
Wrap four newly long lines. Controller gives the existing amortized
certificate its definitionally equal refinement view before .client.
No public lemma, definition, capacity premise, program or bound is added.

Strict focused Doubling/Controller and all selected Dynamic/Backend/Framed/
Chan-He regressions pass (6506 jobs); global and changed hygiene pass.
Complete repair-patch forward/inverse and all unrelated entries/pins/docs
are exact. Full-six and independent delta review remain before publication.
Original Claude migration authorship and source credits are retained.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
orbitingflea pushed a commit to orbitingflea/complexitylib2 that referenced this pull request Nov 2, 2026
…slib-community#2303)

* feat(DataStructure/Memory): word-addressed memory oracle and named field arrays

Memory.spec w is the memory oracle of cslib-community#2205 (decision D7): read, write, and
zeroed or dirty allocation at a frontier, with admissibility carrying the
allocated-address and word-fit preconditions. Field arrays are WordRAM
Blocks accessed by Block.get/Block.set programs over the oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* doc(bib): add Guéneau, Charguéraud and Pottier (ESOP 2018)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(DataStructure/StateTransition): refinements by abstraction functions with stacked potentials

Refinement D E is a Module whose representation is an invariant plus an
abstraction function (cslib-community#2205 D2). Refinement.Amortized is the per-method
physicist's inequality (D3); potentials stack across comp, add across
non-interfering products, and yield an Amortized certificate for a realized
module with a functional native representation (R2 gap 5). CostIsBigO is the
exported asymptotic form (D6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(DataStructure/StateTransition): weaken and rescale amortized refinements

Amortized.mono and Amortized.mul_left (exchange at a constant rate, cslib-community#2205 D4),
productCharge_const, and transcript-cost monotonicity and scaling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* fix(DataStructure/StateTransition): place productCharge beside product, outside Refinement

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(DataStructure/StateTransition): make Refinement.Amortized a structure

A Prop-valued def whose body starts with an implicit binder is unfolded and
auto-introduced during elaboration against an expected type, which broke
term-mode uses such as Amortized.prod. A one-field structure, like the
existing DataStructure.Amortized, avoids this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* wip: array stack over memory and queue method lemmas

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(Foundations): affine cost bounds are O(size)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* wip: queue over memory

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(DataStructure/StateTransition): product answer types via Sum.elim

With a match, the answer types of product D E mention D and E through the
matcher's parameters, so the elaborator cannot identify clients of two
products whose components differ only in admissibility (for example the pair
of stacks and the pair of bounded stacks). Sum.elim D.Result E.Result
depends only on the component answer types.

Queue.Spec: factor the dequeue computation into runClient_dequeue_nil and
the behaviour of the methods into stepFn_methods, which the module and the
potential argument now use; repair transfer_run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(DataStructure): queue over two array stacks over the memory oracle

The M1 slice of cslib-community#2205. Stack.Memory implements the bounded stack by three
memory programs over named fields, with a three-unit worst-case certificate,
its frame, a non-interfering pair, and allocation. Queue.Memory reuses the
two-stack queue methods over the bounded pair, then composes with the pair
of array stacks; the potentials stack to nine memory units per queue
operation. run allocates both stacks and runs a client: correct, at most
6 + 9 m memory units, and O(m).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): certify compositional register-word glue

Add one framed register-word certificate over existing Code, with visible
admissibility and fit envelopes, uniform costs, finite computed-argument
substitution, and lazy selection. Keep exact-basis definedness explicit.

Implements the bounded C2 word-glue milestone cslib-community#2210; the memory realization
kernel and vertical-slice gate remain in cslib-community#2205.

Validation: final staged tree a1b88e3
passed scripts/check.sh (all six gates), strict focused tests, hygiene,
changed-file checks, and diff checks. No selected abstract/PDF impact.

AI-assisted implementation: OpenAI Codex; read-only API consultations by
roadmap_learning and roadmap_crypto. Independent outside review pending.

* feat(WordRAM): realize memory queries with uniform bind and glue

Add one graded certificate over existing Memory.Prog and native Code. Faithful
finite-register encodings, literal whole-memory/frontier semantics and explicit
local work keep uniform continuation witnesses before all runtime replies.

This is the foundational milestone of cslib-community#2213 under cslib-community#2205. Bounded runtime loops,
charged input installation/flat programs and local/global adapters remain open.
No curated abstract or headline scope changes.

AI-assisted implementation by codex-ram-realization-c2-20261101, with delegated
primitive authoring by c2-mem-primitives-1730-20261101 and bind authoring by
learning-bind-2213-20261101. Memory5909 and Glue4283 prerequisites are preserved.

* fix(WordRAM): normalize the memory return simp rule

* feat(WordRAM): realize bounded loops and initialized client programs

Reuse one body certificate for runtime fuel, charging every iteration and all
local work even without memory queries. Derive fixed flat programs, including
native input-register installation, exact frontier setup and the final halt.
Unit observations execute an additional real zero instruction.

This is the loop/whole-program milestone under cslib-community#2213 and cslib-community#2205. Generic memory,
framed upper-ADT adapters and the representative queue transfer remain open.
Existing selected abstracts and headline scope are unchanged.

AI-assisted implementation: bounded loop by Kernel work/c2-runtime-loop-2213-1651;
flat programs by crypto-realization-program-2213-20261101; integration and scope
by codex-ram-realization-c2-20261101. Prior foundational source remains unchanged.

* feat(WordRAM): derive global and framed implementation certificates

Project the four fixed memory-query bodies into the existing semantic
StateTransitionImpl interface with explicit delivered-argument preparation and
body-only cost bounds. Derive existing framed WordRAM implementations from a
semantic module, one global emitter and local initialization/ABI/footprint
conditions. Runtime argument maps do not choose a new emitter per object.

Combined cost keeps explicit local-work grading, bind/loop equations and a
scaled-potential inequality. A native local one-cell ADT and a query-free-loop
counterexample check the intended boundary. Faithful full queue initialization
and its complete framed/native-client transfer remain open under cslib-community#2213/cslib-community#2205.
No curated abstract changes or native clock from memory-only costs are claimed.

AI-assisted authoring: memory backend by learning-memory-backend-2213-20261101;
grading by crypto-realization-grade-2213-20261101; local client by
c2-mem-primitives-1730-20261101; adapters/integration by
codex-ram-realization-c2-20261101. All new public API needs outside-fleet review.

* feat(WordRAM): realize runtime-layout memory-stack methods

Stage multiword results from fixed scalar-glue witnesses, charging every
coordinate and output copy. Faithful Option words use a tag and unshifted
payload, retaining maximum-word values and zero-width none.

Consume the unchanged published Stack.Memory methods over full runtime layout
words. Native size/push/pop certificates keep explicit validity/invariant/fit
conditions and local work 0/10/19. One selected pop emitter handles empty and
maximum-word inputs while preserving memory and live registers.

This is a bounded cslib-community#2213/cslib-community#2205 milestone. The framed queue and faithful allocated
queue-client path remain open. No abstract selection or headline changes.

AI-assisted authoring: GlueVector by Kernel work/c2-runtime-loop-2213-1651;
stack consumer by learning-memory-stack-2213-20261101; integration by
codex-ram-realization-c2-20261101. Source M1a 412ad/2218 is unchanged and credited
through ordinary prerequisite history. Outside-fleet review remains required.

* refactor(WordRAM): centralize realization history and word encodings

Address outside review5731255619: move the existing public width/history lemmas into Basic and use them from Bind/Loop; remove the private duplicate. Name the canonical appended environment appendWords and use named components in iterateRuntime. Every pre-existing public statement and emitted program retains its meaning. Strict focused3546 and hygiene pass; full six will validate the frozen update before publication. Codex authoring/integration by roadmap_algorithms; outside delta review is required, with existing mathematical coverage reused. No selected abstract impact.

* refactor(WordRAM): expose shared glue rules and infer stack push

Address outside review5731265464. Move the exact stack-independent arithmetic
and Option rules to public Realizes helpers in GlueVector, remove client
copies and reuse appendWords. Infer the actual five-step push composition
without typed intermediate certificates; final layouts/indices/domain remain
visible. Statement meanings, clocks, source methods and tests are preserved.

Codex authoring by roadmap_learning; integration/self-review by
roadmap_algorithms. Ordinary parent merge carries2230a929 fix. Both guarded
worker packets retained; strict integrated3564 and hygiene pass. Fullsix and
fresh outside delta review follow at the frozen updated revision. No selected
abstract impact or broader M1 completion claim.

* feat(WordRAM): realize tactic for memory-client realizations

Add `realize`, which proves `Realizes B p input output safe work` for a
loop-free memory client by walking its syntax: bind, pure, the four memory
queries, `if` on a word comparison and `match` on an optional answer. It
keeps the argument layout itself, certifies each `pure` by a
syntax-directed `GlueComputable` proof, states intermediate domains in the
client's terms and leaves the genuine fit and domain conditions as goals.

`Realization/Absorb.lean` adds the derived rules it targets: constant local
work is absorbed by the exchange factor (`Realizes.mono_mul`), giving
`bind₀`, `branch₀` and `pure₀`, plus `Realizes.congr` and the
`WordEncoding` class for intermediate answers.

Refs cslib-community#2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): loops whose body issues a query in realize

Generalize `Realizes.mono_mul` to local work dominated by the memory charge,
and add `Realizes.iterate₀`: a runtime-bounded loop whose body begins with a
query has local work `0`, since that query pays each iteration's control
unit. `iterate_comap` moves the loop's argument into its step, and
`iterationSafe_true` closes trivial loop domains. `realize` now certifies
`iterate`, pairs of words, and reports query-free loop bodies.

Refs cslib-community#2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* test(WordRAM): a whole stack client to a flat program via realize

Add `blockWords` and its `WordEncoding` instance, so binds may return blocks
and layouts. `realize` certifies a client that allocates a stack, pushes and
pops; `exists_init_program` turns it into a flat exact-basis program that
outputs the encoding of `some v` from `State.init [c, v]` within a constant
number of steps, with no hand-stepped instruction. Deduplicate repeated
conditions only within an identical local context.

Refs cslib-community#2205.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): migrate the stack to its realized implementation

Delete the hand-stepped `Stack/WordRAM/{Basic,Controller}` and re-derive their
statements from `Stack.Memory`, C2's `MemoryStack.realizes_*` and `realize`:

- `Stack.Spec`: the bounded stack, moved from `Stack.WordRAM.spec`.
- `Stack.Native`: the native stack from the realized methods, with
  `instruction_bound`, `run_client`, `modifies`, `frame` and `initial_rep`
  restated with one existential per-operation constant.
- `Stack.Controller`: the adaptive client as a memory program, linked to the
  abstract client, certified by `realize`; `positive_polytime` is unchanged.
- Chan–He traversal keeps the stepped dispatcher it uses as
  `Traversal.WordStack` (push and nonempty pop, exact counts unchanged).
- The controller and dynamic-program tests move to the exchange cell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* fix(WordRAM): destructure the loop argument in Realizes.iterate₀

cslib-community#2246's iterateRuntime now binds its argument by a destructuring lambda,
so iterate₀ matches the components before omega.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): native backends for memory refinements, one realized body per constructor

Realization.Backend generalizes MemoryBackend: from a Refinement D (Memory.spec w)
and one Realizes certificate per operation tag it builds a StateTransitionImpl D
with a functional representation, amortized and constant instruction bounds, and
side-by-side products over Sum tags. Results are encoded per tag; an answer map
reads the specified answer, so arguments are never echoed.

Realizes.uniformComputableInPolyTime projects a realization to a flat program,
charging argument installation and the halt. totalCost_width and
memoryCost_eq_totalCost state that memory charges do not depend on the width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* style(tests): wrap long lines in the backend test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): Backend.data, rep_data and fits_appendWords

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* test(WordRAM): backend test uses fits_appendWords and Backend.data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): run the native stack on Realization.Backend

Adopts worker-claude-015dlg8k-adapter's drop-in for cslib-community#2277: Stack.Native
instantiates Realization.Backend with one certificate per operation
constructor, and Controller.positive_polytime comes from
Realizes.uniformComputableInPolyTime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* perf(WordRAM): state realize certificates per form in the client's terms

`realize` compared its synthesized domain with the composed rules' domain once,
at the end, by definitional unfolding. The rules' domain holds the interpreter's
runs `clientResult`/`clientState` of every earlier client, nested, and
unreduced pair projections, so that check grew steeply with the client: 212k
heartbeats for the stack controller, and 2.5M when a bind's first client ends
in a `match`.

Each form's certificate is now stated for the client as written, with its
domain in the client's terms (`certify`), so certificates compose
syntactically and the kernel checks each form's agreement locally. A bind's
continuation domain is stated at the first client's reply and next memory in
closed form (`Realizes.bind₀_of_run`). Result encodings are proved by
`Fin.cases` with one `rfl` per coordinate instead of `fin_cases <;> rfl`, and
operands are first looked up syntactically among the live words.

Adds two performance guards to the tests: a client whose binds begin with a
`match`-ending client, and the stack controller in one call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): keep only consumed native API; fold the traversal word stack into TraversalStack

Stack.Native keeps the backend, implementation and instruction_bound.
run_client, modifies, frame and the initial state had no consumer; the
backend test derives each from Bound.exists_executes_const,
Backend.exec_memoryState with Stack.Memory.modifies_methods, and
Backend.rep_data. The backend test now uses Stack.Native instead of its own
copy, and absorbs DataStructureStack. Traversal.WordStack moves into
TraversalStack.lean, its only importer, unchanged. Stack.Controller uses
memoryCost_eq_totalCost and drops unused imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* refactor(Stack): realize the controller in one call

With cslib-community#2280, realize certifies the whole controller program directly, so
the split through realizes_alloc, realizes_run and Realizes.bind goes.
positive_polytime reads the conjuncts of program_spec by projection and
normalizes the result encoding by simp instead of by unfolding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* perf(Stack): simplify only the controller's side goals

The side goals after realize need no hypothesis rewriting; simp on the
goal alone saves about 0.15 s and three simp arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* chore: drop imports the merge duplicated in Complexity.lean

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): framed backends - frames, products over one memory, allocation

A backend of a framed refinement carries its frame over: a native
operation writes only the footprint and the reserved room
(Backend.modifies), and keeps disjoint assertions and structures kept
apart (frame_heap, frame). Backends of framed refinements run their
product over one memory (Implements.prod_framed), each side within its
own region (modifies_inl, modifies_inr). Backend.Allocation names the
tag that runs a Memory.Allocator's program; Allocation.exec allocates
from arbitrary bounded data within the allocator's cost, writing only
the room it takes. Backend.extend adds such tags; install and
exists_exec run any tag's body.

The memory side is a new leaf, Memory/Region. The stack test restores
modifies/frame, constant-time allocation and allocate-then-run, and two
stacks over one memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* test(WordRAM): allocate a pair of stacks in one body

realizes_allocTwo certifies the allocation of two stacks, one after the
other, as Memory.Allocator.prod does; with Backend.extend it becomes the
allocation tag of the pair's backend, and allocate_pair sets up both
empty stacks from arbitrary bounded data in constant time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

* feat(WordRAM): retain Backend register frames for live-input execution

Expose existing shared packing facts and install identity under actual live words; derive a full-frame execution result and raw-live corollary from the same Realizes code_spec. Existing definitions and all previous theorem types are unchanged; exists_exec projects the stronger proof. Tests exercise different result widths, paid zero staging, zero/max-word inputs and a genuine memory-read provider. Under cslib-community#2298 for queue cslib-community#2284 and heap cslib-community#2282; inherited Claude source credit retained. Strict focused3628 and hygiene pass; full-six/outside review pending.

* fix(WordRAM): expose Backend extension and preparation metadata

Expose only the existing pure extend record and prepare alias so real heap bounds and conditional already-live entry elaborate without local record copies or dependent observation wrappers. All definition bodies/types, code/arg/rep/resource meanings are unchanged. Generic bound_extend and actual-live operation-entry regressions pass with the old clients; full new-head validation/review pending under cslib-community#2298.

* Fix Stack migration name resolution and framed proof view

Append only to frozen cslib-community#2272 head97bd. Explicitly qualify Doubling's eighty
Memory.spec references shadowed by the relocated bounded Stack.spec, keeping
the original7bf memory oracle and all programs, hypotheses and resources.
Wrap four newly long lines. Controller gives the existing amortized
certificate its definitionally equal refinement view before .client.
No public lemma, definition, capacity premise, program or bound is added.

Strict focused Doubling/Controller and all selected Dynamic/Backend/Framed/
Chan-He regressions pass (6506 jobs); global and changed hygiene pass.
Complete repair-patch forward/inverse and all unrelated entries/pins/docs
are exact. Full-six and independent delta review remain before publication.
Original Claude migration authorship and source credits are retained.

* refactor(WordRAM): realize the queue with resident register metadata

Use Memory.Prog, boundedWhile, Realizes and one fixed Backend family with actual native tag dispatch and paid count writeback. Preserve the original 2*C reservation, Fits1/end-fit domain, arbitrary dirty bounded initialization in six register instructions, typed FIFO observations, adaptive execution and heap frame. Remove old Basic/Dynamic and superseded prototypes; migrate every client and retain the source transfer equation/invariant/allocator decomposition.

Static shared R/F replace the hand program's literal register and instruction constants: call charge4F+6 and terminal potential2F*rear include control, commit and halt. The external client controller/delivery boundary remains; generic framed allocation/composition and the full2205 objective are not completed.

Default scripts/check.sh all six PASS at exact staged tree37b5dee43327761897a6c152ef3246de13d12ca0, plus eight strict focused queue targets, imports and hygiene. Parent is the private ordinary joint0abe of public2299/73 and2272/fc; supplier review/actual/current-context gates remain separate. This own layer changes exactly21 paths.

Source credit Samuel Schlesinger retained. OpenAI Codex assisted implementation, proofs, tests and source-preserving integration; Kernel's exact metadata-source prefix is reused with its contribution credited and old feasibility refs preserved. Shared providers retain their original authors through parent history.

Refs cslib-community#2284; broader cslib-community#2205/cslib-community#2213 remain open.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants