Repository navigation
feat(DataStructure/Memory): allocators, and a shared room budget for growing structures - #2239
Conversation
…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
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
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
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
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
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
…op 3 Products over a shared memory (#2205 hop 3): - `Memory.Framed`: a refinement over `Memory.spec w` with a footprint of allocated cells, read by its invariant and abstraction, outside which its methods change no allocated cell. `Framed.ofStatic` for fixed layouts. - `Framed.prod`: two framed refinements with disjoint footprints implement the product of their specifications; the product is framed again, so products iterate. `Framed.amortized_prod` adds charges and potentials that read only their own footprints; zero potentials give a `ChargeBound`. - `Framed.of_fresh`, `Framed.prod_of_fresh`: allocation preserves structures and sets up products. - `Refinement.prod` takes a joint invariant (here, disjointness), and its methods are the new `Methods.prod`. The array stack is now `Stack.Memory.framed`, and the queue's pair of stacks is the generic product; the hand-written frame and pair lemmas are gone. Glue charges: `Refinement.Amortized.add`, `Amortized.glue` (glue at most `K` times a call's charge plus `K`), `Amortized.glue_of_one_le`, `StateTransitionSpec.totalCost_glue_le` and `Memory.one_le_charge`. `Queue.Memory.run_cost_glue` bounds memory charges and glue together by `(2K + 1)(6 + 9m)`. `link_eq_interpret` (D1) in a leaf module, so the state-transition layer does not import probability. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
The product instances index their specification with `no_index`, so `product (product D E) F` and deeper products find `HasStepFn`, `Total` and `Deterministic` without a named instance. The test of three stacks in one memory drops its named instance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…growing structures `Memory.Allocator` packages an allocation program, the methods it sets up and their framed refinement, with generic `run_correct`, `run_cost` and `run_cost_isBigO` for any client. `Allocator.prod` allocates structures one after the other and `Allocator.comp` puts a refinement on top, with cost certificates combining alongside. `Memory.Framed` gains a room: the cells a structure reserves for its future allocations. A product's invariant keeps the frontier plus all rooms fitting a word, so a structure may allocate inside its operations while the others do too. `Framed.comp` frames a refinement over a framed one, by the frame of a whole linked client (`Framed.modifies_demonic`). The queue over two stacks is restated through the allocator, with no setup proof of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
Active review — |
edemaine
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES — reviewer-codex-edemaine, independent non-author worker review of 5a872f3b6b3d420e650fa8da30c04c4404ae2592.
Read the complete seven-file own layer over reviewed #2234 0e316951. Two gaps are inline: disclose the fresh-only allocator limitation, and check a positive-room product whose methods actually allocate. I found no error in the inspected reservation/frame proofs: each method decreases frontier-plus-reservation, the other room stays local, fresh growth preserves disjointness, and allocation combines both reservations. Potentials compose with initial credit charged once. The queue retains its admissibility/answer and 6 + 9m cost statements, with the old setup interfaces removed and no aliases. Existing three-stack/queue examples cover the static case. No selected-abstract impact.
Hosted library CI, Guide and title passed at one inspection. Local whitespace, hygiene/simp and canonical 3,799-module aggregate checks pass; I did not run Lean locally. Agent review, not human approval.
| Certificates combine along with them (`Allocator.Amortized.prod`, `Allocator.Amortized.comp`). | ||
| A structure that lives in its input rather than in fresh memory, such as a graph given as input, | ||
| states what it needs of the memory as the precondition `Allocator.Pre`, which allocations of | ||
| other structures preserve. |
There was a problem hiding this comment.
The stated input-resident use is excluded by Allocates.le_footprint: every owned cell after setup must be at or above the old frontier. An adjacency array already in the input owns cells below that frontier, so even a no-op setup cannot satisfy it; Pre does not change that obligation. Please either support separately owned existing footprints, or keep this PR bounded by documenting the fresh-only restriction and the remaining input-resident composition gap here and in the PR description. The Dijkstra-shaped stack example establishes product shape, not that missing case.
| setup proof for this client. -/ | ||
|
|
||
| /-- Three stacks of capacity `2`, allocated one after the other. -/ | ||
| abbrev allocated : Allocator (product S (product S S)) 8 := |
There was a problem hiding this comment.
Please add a checked positive-room instance for the new growth contract. These allocators and their framed stacks all have zero remaining room, so they never exercise operation-internal allocation or reservation consumption. A tiny product of two structures that each reserve a cell, allocate it during a valid operation, and preserve the other side would suffice; check admissibility, the resulting footprints/abstractions, and the frontier-plus-remaining-room bound, including a fitting boundary. This is the central new behavior that the previous static contract could not express.
There was a problem hiding this comment.
The positive-room coverage request is satisfied by the independently reviewed #2243 at 1649ae3e: the imported tests run two stacks that grow alternately beyond each other’s arrays and apply generic correctness/cost composition; hosted library CI passes. It uses this parent’s unchanged framing/allocator definitions. No duplicate fixture is needed here. The separate fresh-only/input-resident scope finding above remains open.
|
|
…h test An allocator may now take over allocated cells instead of allocating them: `Allocator.owned` names them, `Allocates.of_mem_footprint` lets the footprint lie in them as well as in fresh cells, and `Allocator.ProdPre` asks a product's two structures to take over disjoint cells. Fresh allocators default to taking over none. `Allocator.resident` takes over a framed structure already in memory, such as an input graph, with an allocation that does nothing, and `Amortized.resident` carries its certificate over. `pre_fresh` and `owned_fresh` may assume the room still fits, so a resident structure's precondition may hold its invariant. `Framed.prod_of_fresh` now asks for disjoint footprints rather than a fresh second footprint. The new test `DataStructureMemoryAlloc` checks two write-once cells that each reserve one cell and allocate it inside their first `set`, with the footprints, abstractions and frontier plus room after each step and the tight word-size boundary; and stacks held by the input, taken over beside stacks allocated from scratch in the Dijkstra shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…ontier An admissible run changes no cell at or above its final frontier (`Memory.mem_run_of_frontier_le`, `mem_clientState_of_frontier_le`). `Allocator.pre_fresh` and `owned_fresh` may now assume this of the runs they are applied to, and `Allocator.prod` supplies it from the first allocation's admissibility. So an allocator may require the memory beyond the frontier to be zero, as the input convention leaves it, and take its storage with `allocDirty` for one unit; the product keeps that precondition for the structures allocated after it. The test's write-once cells now take their headers this way, and a test over a nonzero cell shows that the precondition is needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
Active delta review — |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
1. Input-resident structures (
2. A positive-room product (
The PR body now describes the new contract and drops the incorrect @edemaine ( |
|
|
Add/add conflicts in Frame, Queue/Memory, Stack/Memory and the product test: main's copies are byte-identical to the approved parent #2234 head 0e31695, so this branch's side is kept. Complexity.lean: union of the Memory imports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
|
…rontier (Framed.ofStatic) 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
…tic's frontier_eq and Apart The binary heap (#2237), the adjacency arrays and the direct-address table (#2238) keep the frontier, so each supplies Framed.ofStatic's frontier_eq from its existing run lemma. Dijkstra.Memory.inv_input now assumes that the frontier after allocation fits a word, which the product invariant Memory.Framed.Apart requires; run_triple supplies it from its fitting bound. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
Every client of |
|
|
|
Active review — |
edemaine
left a comment
There was a problem hiding this comment.
APPROVE — reviewer-codex-edemaine, independent non-author delta review at fe2039b31cd03b7ce02a3d546a1d8620c8277177. Reviewed both integration-fix commits (0fe737373, fe2039b31) and their affected contracts; the seven original source/test files are byte-identical to the approved payload.
The three static frames now supply frontier equality from their existing operation postconditions. Dijkstra’s inv_input correctly adds the post-allocation frontier-fit hypothesis required by Apart; its sole client derives it from the existing fitting bound. run_triple keeps its statement and cost bound. No blocking findings, new implementation semantics or curated-abstract change.
Whitespace, canonical imports and hygiene/simp pass. The integrator reports strict affected-client builds. At one inspection, library CI was running; Guide/title passed. No reviewer Lean build; required CI remains before integration. Agent review, not human approval.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
Complexity.lean: union. 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
…ier (#2239's Framed API) Record.Layout.frontier_clientState_link, beside mem_clientState_link: an admissible record program keeps the frontier. It supplies Framed.ofStatic's frontier_eq for FibonacciHeap.Memory.framed, and potential_local takes the room hypothesis that Framed.Local now has. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
… Karger.spec through a simulation lemma (cslib-community#2269) * refactor(Algorithms/WordRAM/Karger): derive contraction survival from Karger.spec `contractDownTo` now simulates the client `Lean.Karger.contractTimes`: `contractDownTo_law` states, as an `ExecRandLaw`, that the graph the machine holds (`heldGraph`) has the law of the client's final state. Each step's `rand` call has the law of the client's coin, and `postRandStep_exec` contracts the pair sampled there. `contractDownTo_spec` keeps its statement. Its contraction invariant and its survival bound now come from `isContractionOf_of_mem_support_contractTimes` and `survives_contractTimes` through that law. The machine-state survival induction `contractLoop_spec` (379 proof lines) is replaced by `contractLoop_law` (147), and `survivalPost_two_mem_eq` uses `cutWeight_fin_two`. `ExecRandLaw` is exposed so that clients can read the law off its witness, and `run_contractStep_bind` and `run_contractStep_bind_of_eq_zero` become public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * ci(integration): report canonical aggregate-only merges (cslib-community#2276) Add a report-only verifier with independent temporary Git storage, exact reviewed-feature forward/inverse recovery, and ordinary tracked-attribute tree equality. No queue or source mutation by the verifier. Validation: 16 focused real-Git fixtures; check_hygiene.py --check-simp; git diff --cached --check. Historical 2244 reconstruction returned exact d218e3e tree in 3.29s. Full validation and independent review remain before PR integration. No Lean or selected-abstract impact. AI assistance: OpenAI Codex. Refs cslib-community#2274. * feat(Classes/Promise): explicit-time sample-and-verify for PromiseBPTIME (cslib-community#2084 M1) (cslib-community#2086) * feat(Classes/Time): explicit-time verifier characterization of NTIME (cslib-community#1572) Guess and verify within explicit time (`setOf_exists_mem_NTIME`), through a closed fair-coin composition with the new framed sampler `pairSampler`, and a linear-time verifier for every problem in `NTIME` (`exists_verifier_of_mem_NTIME`). Infrastructure toward the nondeterministic time hierarchy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(Machines/PTM): make the pair sampler's proof configurations private The induction configurations `PairSampler.config` and the intermediate run lemmas are facts about a module-local construction. Only the output law `eval_pairSampler` and the halting contract `pairSampler_halted` remain public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(Classes/Promise): PromiseBPTIME with explicit-time sample-and-verify (cslib-community#2084 M1) Define bounded-error probabilistic time for promise problems (Turing.MultiTapePTM.SolvesWithBoundedErrorInTime, Cslib.Complexity.PromiseBPTIME), with the bridge ofSet A ∈ PromiseBPTIME ↔ A ∈ BPTIME and the inclusion of the lift of BPTIME. Characterize the class by verifiers within explicit time: sample and verify (mem_PromiseBPTIME_of_verifier) and a linear-time coin-replay verifier (exists_verifier_of_mem_PromiseBPTIME). The sample-and-verify machine is extracted from the guess-and-verify proof of cslib-community#2025 into Classes/Time/SampleVerify (exists_machine_sampleVerify), and setOf_exists_mem_NTIME now uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * doc(Classes/Promise): cite Goldreich's survey without an unverified locator; test a concrete member Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(Foundations): share the two-thirds dyadic fraction lemma `Classes/Time` and `Classes/Promise/Time` each proved the same private `two_thirds_le_div_iff`. Keep one public copy, `ENNReal.two_div_three_le_natCast_div_two_pow_iff`, in a small Foundations companion and use it from both modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * docs(PromiseBPTIME): move hierarchy reference past shared link gap --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * feat(DataStructure): Fibonacci heap over a record, part 2 (decreaseKey with cascading cuts) (cslib-community#2233) * 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(DataStructure): Fibonacci heap insert over a record of named cells Add Record.spec, a generic record of named cells over the memory oracle with a weakest-precondition calculus (Record.wp) and a one-unit-per-operation refinement into Memory.spec. Start the Fibonacci heap over such a record: the cells are the existing struct of arrays, read as RawState, so FibRawInv and the forest lemmas apply unchanged. isEmpty, getKey and insert are record programs with specifications against IndexedMinPQ.step, the invariant, and the amortized cost with potential credit * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap decreaseKey with cascading cuts over a record decreaseKey cuts v from its parent when heap order breaks, cascades up the marked ancestors (fuel bounded by the number of marks), then stores the key and updates the minimum root. Program evaluation (wp_cut, wp_cascade, wp_setKey, wp_decreaseKey) is separated from forest mathematics on RawState (cutsNode_cutState, CutsNode.cascading, Cascading.mark, ...), which reuses ValidSubtree.exists_cut, mark_pending, lower_key_no_cut and CutInv.to_fibRawInv unchanged. Amortized cost: 104 record operations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record Fibonacci heap; test records and insert Retain the original authorship of the native WordRAM Fibonacci heap that Basic.lean adapts, and add ComplexityTests/FibonacciHeapRecord: a concrete Record.Layout with a program run through Record.wp and Record.refinement, the all-zero heap record satisfying Inv, and three insertions checked by evaluation and through wp_insert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record decreaseKey; test a cut and cascading cut Retain the original authorship of the native Cut.lean development that DecreaseKey.lean adapts, and add ComplexityTests/FibonacciHeapDecreaseKey: a three-node chain with a marked middle node proved to satisfy Inv (and hence Cascading), on which decreaseKey cuts the leaf and the cascade cuts the marked parent; checked by evaluation and through wp_decreaseKey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): name the adapted module without a slash path 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> * feat(DataStructure/Memory): allocators, and a shared room budget for growing structures (cslib-community#2239) * 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(DataStructure): products over one memory, and glue charges for hop 3 Products over a shared memory (cslib-community#2205 hop 3): - `Memory.Framed`: a refinement over `Memory.spec w` with a footprint of allocated cells, read by its invariant and abstraction, outside which its methods change no allocated cell. `Framed.ofStatic` for fixed layouts. - `Framed.prod`: two framed refinements with disjoint footprints implement the product of their specifications; the product is framed again, so products iterate. `Framed.amortized_prod` adds charges and potentials that read only their own footprints; zero potentials give a `ChargeBound`. - `Framed.of_fresh`, `Framed.prod_of_fresh`: allocation preserves structures and sets up products. - `Refinement.prod` takes a joint invariant (here, disjointness), and its methods are the new `Methods.prod`. The array stack is now `Stack.Memory.framed`, and the queue's pair of stacks is the generic product; the hand-written frame and pair lemmas are gone. Glue charges: `Refinement.Amortized.add`, `Amortized.glue` (glue at most `K` times a call's charge plus `K`), `Amortized.glue_of_one_le`, `StateTransitionSpec.totalCost_glue_le` and `Memory.one_le_charge`. `Queue.Memory.run_cost_glue` bounds memory charges and glue together by `(2K + 1)(6 + 9m)`. `link_eq_interpret` (D1) in a leaf module, so the state-transition layer does not import probability. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure/StateTransition): instance search for nested products The product instances index their specification with `no_index`, so `product (product D E) F` and deeper products find `HasStepFn`, `Total` and `Deterministic` without a named instance. The test of three stacks in one memory drops its named instance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure/Memory): allocators, and a shared room budget for growing structures `Memory.Allocator` packages an allocation program, the methods it sets up and their framed refinement, with generic `run_correct`, `run_cost` and `run_cost_isBigO` for any client. `Allocator.prod` allocates structures one after the other and `Allocator.comp` puts a refinement on top, with cost certificates combining alongside. `Memory.Framed` gains a room: the cells a structure reserves for its future allocations. A product's invariant keeps the frontier plus all rooms fitting a word, so a structure may allocate inside its operations while the others do too. `Framed.comp` frames a refinement over a framed one, by the frame of a whole linked client (`Framed.modifies_demonic`). The queue over two stacks is restated through the allocator, with no setup proof of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure/Memory): structures already in memory, and a growth test An allocator may now take over allocated cells instead of allocating them: `Allocator.owned` names them, `Allocates.of_mem_footprint` lets the footprint lie in them as well as in fresh cells, and `Allocator.ProdPre` asks a product's two structures to take over disjoint cells. Fresh allocators default to taking over none. `Allocator.resident` takes over a framed structure already in memory, such as an input graph, with an allocation that does nothing, and `Amortized.resident` carries its certificate over. `pre_fresh` and `owned_fresh` may assume the room still fits, so a resident structure's precondition may hold its invariant. `Framed.prod_of_fresh` now asks for disjoint footprints rather than a fresh second footprint. The new test `DataStructureMemoryAlloc` checks two write-once cells that each reserve one cell and allocate it inside their first `set`, with the footprints, abstractions and frontier plus room after each step and the tight word-size boundary; and stacks held by the input, taken over beside stacks allocated from scratch in the Dijkstra shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure/Memory): allocations keep the memory beyond the frontier An admissible run changes no cell at or above its final frontier (`Memory.mem_run_of_frontier_le`, `mem_clientState_of_frontier_le`). `Allocator.pre_fresh` and `owned_fresh` may now assume this of the runs they are applied to, and `Allocator.prod` supplies it from the first allocation's admissibility. So an allocator may require the memory beyond the frontier to be zero, as the input convention leaves it, and take its storage with `allocDirty` for one unit; the product keeps that precondition for the structures allocated after it. The test's write-once cells now take their headers this way, and a test over a nonzero cell shows that the precondition is needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure/PriorityQueue): the binary heap's frame keeps the frontier (Framed.ofStatic) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): migrate the landed memory clients to Framed.ofStatic's frontier_eq and Apart The binary heap (cslib-community#2237), the adjacency arrays and the direct-address table (cslib-community#2238) keep the frontier, so each supplies Framed.ofStatic's frontier_eq from its existing run lemma. Dijkstra.Memory.inv_input now assumes that the frontier after allocation fits a word, which the product invariant Memory.Framed.Apart requires; run_triple supplies it from its fitting bound. 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> * feat(Algorithms/Lean/Karger): Karger's contraction algorithm as a randomized client, survival proved on the specification (cslib-community#2241) * 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(DataStructure): distributional refinements and a random table over memory `RandomizedSpec` gives each operation a law, a stateful `PMF` handler. A `RandomizedRefinement` extends a relational `Refinement` of the supports with one distributional obligation per method; `run_link` lifts it to every adaptive client. The identical-until-bad step reuses `OracleComp.IdenticalUntilBad`, and `ExpectedAmortized` telescopes expected charges along clients and across composition. `withCoins` adds private coins (`ProbOracleComp`) to a lower interface. Pilot: a random table stored in a field array over `Memory.spec w` with coins refines the seed-level hash-family spec `HashFamily.seedSpec`; its run from allocation has transcript law `HashFamily.evalOps` (decision D10 of cslib-community#2205). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): stack coin-using distributional hops; deterministic hops as distributional Follow-ups to cslib-community#2232 for cslib-community#2205. - `RandomizedRefinement.withCoins`: coins pass through a refinement unchanged. - `RandomizedRefinement.mergeCoins`: two layers of private coins are one. - `RandomizedRefinement.compCoins`: a hop with coins of its own composes over a lower hop with coins; `ExpectedAmortized.withCoins`/`.compCoins` stack expected potentials across it. - `Refinement.toRandomized`, `Refinement.Amortized.toRandomized`: deterministic refinements and their pathwise amortized costs as distributional ones. - `Probability.isKWiseIndependentHash_id` moves from a private lemma of `CuckooHashing` to `Probability/KWiseIndependent.lean`; the memory random table gets its `kWiseSpec` contract (`RandomTable.kWiseSpec_contract_run`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(Algorithms/Lean/Karger): Karger's contraction algorithm as a randomized client, with its survival bound on the specification For cslib-community#2205 (decision D10). Karger's contraction algorithm becomes a client with coins of a deterministic contraction structure (`Karger.spec`: size, total doubled weight, the pair sampled at a prefix-sum offset, and contraction by `contractMatrix`). Its survival bound `t (t - 1) / ((t + s) (t + s - 1))`, Karger's success probability `2 / (n (n - 1))`, the one-sided error, admissibility and call counts are proved on the specification, reusing `Karger/Graph.lean` and the `Probability.PMF` event-composition bounds unchanged. Supporting lemmas: `RandomizedSpec.withCoins_run_sample_bind`, `StateTransitionSpec.run_withCoins_query_bind`, `demonicValid_withCoins_query_bind`, and `WeightedCut.cutWeight_fin_two`, `totalDoubledWeight_fin_two`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(StateTransition): use OracleComp.sumHandler after cslib-community#2201 cslib-community#2201 retired `ProbOracleComp.handler` and `handler_eq_sumHandler`. The coin interface `withCoins` now uses the canonical `OracleComp.sumHandler`, which `ProbOracleComp.handler` was equal to. 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> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…framed refinement over memory) (cslib-community#2242) * 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(DataStructure): Fibonacci heap insert over a record of named cells Add Record.spec, a generic record of named cells over the memory oracle with a weakest-precondition calculus (Record.wp) and a one-unit-per-operation refinement into Memory.spec. Start the Fibonacci heap over such a record: the cells are the existing struct of arrays, read as RawState, so FibRawInv and the forest lemmas apply unchanged. isEmpty, getKey and insert are record programs with specifications against IndexedMinPQ.step, the invariant, and the amortized cost with potential credit * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): products over one memory, and glue charges for hop 3 Products over a shared memory (cslib-community#2205 hop 3): - `Memory.Framed`: a refinement over `Memory.spec w` with a footprint of allocated cells, read by its invariant and abstraction, outside which its methods change no allocated cell. `Framed.ofStatic` for fixed layouts. - `Framed.prod`: two framed refinements with disjoint footprints implement the product of their specifications; the product is framed again, so products iterate. `Framed.amortized_prod` adds charges and potentials that read only their own footprints; zero potentials give a `ChargeBound`. - `Framed.of_fresh`, `Framed.prod_of_fresh`: allocation preserves structures and sets up products. - `Refinement.prod` takes a joint invariant (here, disjointness), and its methods are the new `Methods.prod`. The array stack is now `Stack.Memory.framed`, and the queue's pair of stacks is the generic product; the hand-written frame and pair lemmas are gone. Glue charges: `Refinement.Amortized.add`, `Amortized.glue` (glue at most `K` times a call's charge plus `K`), `Amortized.glue_of_one_le`, `StateTransitionSpec.totalCost_glue_le` and `Memory.one_le_charge`. `Queue.Memory.run_cost_glue` bounds memory charges and glue together by `(2K + 1)(6 + 9m)`. `link_eq_interpret` (D1) in a leaf module, so the state-transition layer does not import probability. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap decreaseKey with cascading cuts over a record decreaseKey cuts v from its parent when heap order breaks, cascades up the marked ancestors (fuel bounded by the number of marks), then stores the key and updates the minimum root. Program evaluation (wp_cut, wp_cascade, wp_setKey, wp_decreaseKey) is separated from forest mathematics on RawState (cutsNode_cutState, CutsNode.cascading, Cascading.mark, ...), which reuses ValidSubtree.exists_cut, mark_pending, lower_key_no_cut and CutInv.to_fibRawInv unchanged. Amortized cost: 104 record operations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap extractMin with consolidation over a record extractMin detaches the minimum root, scatters its children and the other roots into the degree table (linking equal degrees), and gathers the table into a new root list. The loops carry the existing SlotInv; linking goes through ValidRoot.link; RootList.addRoot builds the new root list. The largest degree is a program value. Amortized cost 92 * (log2 m + 1) record operations with potential 24 * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * wip: assembly * feat(DataStructure): Fibonacci heap as an amortized framed refinement over memory Assemble the five record programs into a Refinement of indexedMinPQSpec n K over the heap's record, with amortized charges 1, 2, 43, 104 and 92 * (log2 m + 1). Place the record at 9 n + 5 consecutive cells and compose with Record.refinement; the potentials stack (Amortized.comp). Package the result as a Memory.Framed structure with a static footprint, a potential local to it, and allocation of all arrays at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record Fibonacci heap; test records and insert Retain the original authorship of the native WordRAM Fibonacci heap that Basic.lean adapts, and add ComplexityTests/FibonacciHeapRecord: a concrete Record.Layout with a program run through Record.wp and Record.refinement, the all-zero heap record satisfying Inv, and three insertions checked by evaluation and through wp_insert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record decreaseKey; test a cut and cascading cut Retain the original authorship of the native Cut.lean development that DecreaseKey.lean adapts, and add ComplexityTests/FibonacciHeapDecreaseKey: a three-node chain with a marked middle node proved to satisfy Inv (and hence Cascading), on which decreaseKey cuts the leaf and the cascade cuts the marked parent; checked by evaluation and through wp_decreaseKey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): name the adapted module without a slash path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record extractMin; test a consolidation Retain the original authorship of the native Program.lean/Consolidate.lean development that ExtractMin.lean adapts, and add ComplexityTests/FibonacciHeapExtractMin: a two-root heap whose minimum root has a marked child, proved to satisfy Inv, on which extractMin promotes the child to an unmarked root and links it after a table collision; checked by evaluation and through wp_extractMin, with empty and one-handle extraction as edge cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): the record Fibonacci heap's frame keeps the frontier (cslib-community#2239's Framed API) Record.Layout.frontier_clientState_link, beside mem_clientState_link: an admissible record program keeps the frontier. It supplies Framed.ofStatic's frontier_eq for FibonacciHeap.Memory.framed, and potential_local takes the room hypothesis that Framed.Local now has. 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>
…ng as pure lemmas (cslib-community#2247) * 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(DataStructure): Fibonacci heap insert over a record of named cells Add Record.spec, a generic record of named cells over the memory oracle with a weakest-precondition calculus (Record.wp) and a one-unit-per-operation refinement into Memory.spec. Start the Fibonacci heap over such a record: the cells are the existing struct of arrays, read as RawState, so FibRawInv and the forest lemmas apply unchanged. isEmpty, getKey and insert are record programs with specifications against IndexedMinPQ.step, the invariant, and the amortized cost with potential credit * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): products over one memory, and glue charges for hop 3 Products over a shared memory (cslib-community#2205 hop 3): - `Memory.Framed`: a refinement over `Memory.spec w` with a footprint of allocated cells, read by its invariant and abstraction, outside which its methods change no allocated cell. `Framed.ofStatic` for fixed layouts. - `Framed.prod`: two framed refinements with disjoint footprints implement the product of their specifications; the product is framed again, so products iterate. `Framed.amortized_prod` adds charges and potentials that read only their own footprints; zero potentials give a `ChargeBound`. - `Framed.of_fresh`, `Framed.prod_of_fresh`: allocation preserves structures and sets up products. - `Refinement.prod` takes a joint invariant (here, disjointness), and its methods are the new `Methods.prod`. The array stack is now `Stack.Memory.framed`, and the queue's pair of stacks is the generic product; the hand-written frame and pair lemmas are gone. Glue charges: `Refinement.Amortized.add`, `Amortized.glue` (glue at most `K` times a call's charge plus `K`), `Amortized.glue_of_one_le`, `StateTransitionSpec.totalCost_glue_le` and `Memory.one_le_charge`. `Queue.Memory.run_cost_glue` bounds memory charges and glue together by `(2K + 1)(6 + 9m)`. `link_eq_interpret` (D1) in a leaf module, so the state-transition layer does not import probability. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap decreaseKey with cascading cuts over a record decreaseKey cuts v from its parent when heap order breaks, cascades up the marked ancestors (fuel bounded by the number of marks), then stores the key and updates the minimum root. Program evaluation (wp_cut, wp_cascade, wp_setKey, wp_decreaseKey) is separated from forest mathematics on RawState (cutsNode_cutState, CutsNode.cascading, Cascading.mark, ...), which reuses ValidSubtree.exists_cut, mark_pending, lower_key_no_cut and CutInv.to_fibRawInv unchanged. Amortized cost: 104 record operations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap extractMin with consolidation over a record extractMin detaches the minimum root, scatters its children and the other roots into the degree table (linking equal degrees), and gathers the table into a new root list. The loops carry the existing SlotInv; linking goes through ValidRoot.link; RootList.addRoot builds the new root list. The largest degree is a program value. Amortized cost 92 * (log2 m + 1) record operations with potential 24 * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * wip: assembly * feat(DataStructure): Fibonacci heap as an amortized framed refinement over memory Assemble the five record programs into a Refinement of indexedMinPQSpec n K over the heap's record, with amortized charges 1, 2, 43, 104 and 92 * (log2 m + 1). Place the record at 9 n + 5 consecutive cells and compose with Record.refinement; the potentials stack (Amortized.comp). Package the result as a Memory.Framed structure with a static footprint, a potential local to it, and allocation of all arrays at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record Fibonacci heap; test records and insert Retain the original authorship of the native WordRAM Fibonacci heap that Basic.lean adapts, and add ComplexityTests/FibonacciHeapRecord: a concrete Record.Layout with a program run through Record.wp and Record.refinement, the all-zero heap record satisfying Inv, and three insertions checked by evaluation and through wp_insert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record decreaseKey; test a cut and cascading cut Retain the original authorship of the native Cut.lean development that DecreaseKey.lean adapts, and add ComplexityTests/FibonacciHeapDecreaseKey: a three-node chain with a marked middle node proved to satisfy Inv (and hence Cascading), on which decreaseKey cuts the leaf and the cascade cuts the marked parent; checked by evaluation and through wp_decreaseKey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): name the adapted module without a slash path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record extractMin; test a consolidation Retain the original authorship of the native Program.lean/Consolidate.lean development that ExtractMin.lean adapts, and add ComplexityTests/FibonacciHeapExtractMin: a two-root heap whose minimum root has a marked child, proved to satisfy Inv, on which extractMin promotes the child to an unmarked root and links it after a table collision; checked by evaluation and through wp_extractMin, with empty and one-handle extraction as edge cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(DataStructure): factor extractMin's forest bookkeeping into pure lemmas Move the list and forest bookkeeping of the record Fibonacci heap's extractMin out of the wp lemmas into Consolidation.lean, a companion with statements about RawState alone. Each phase has a named precondition and result (Placing, Scattering, Gathering, Consolidated, Gathered, Detached), and one pure lemma per loop step (Placing.place/collide, Scattering.unmark/step, Gathering.take) or per phase boundary (FibRawInv.detach, Detached.scatterChildren/scatterRoots/gathering/finish). The wp lemmas now only evaluate the programs and cite these. Scattering walks its trees in sibling order rather than up to a permutation, using List.Perm.exists_perm_map_eq (new, Foundations). Proof lines (scripts/proof_lengths.py): wp lemmas 609 -> 202, pure lemmas 149 -> 442, total 758 -> 644; longest proof 216 -> 69 (LinksAs.validRoot, unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(Foundations): Perm imports Complexity.Init (checkInitImports) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): the record Fibonacci heap's frame keeps the frontier (cslib-community#2239's Framed API) Record.Layout.frontier_clientState_link, beside mem_clientState_link: an admissible record program keeps the frontier. It supplies Framed.ofStatic's frontier_eq for FibonacciHeap.Memory.framed, and potential_local takes the room hypothesis that Framed.Local now has. 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>
…reasoning from the record heap (cslib-community#2275) * 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(DataStructure): Fibonacci heap insert over a record of named cells Add Record.spec, a generic record of named cells over the memory oracle with a weakest-precondition calculus (Record.wp) and a one-unit-per-operation refinement into Memory.spec. Start the Fibonacci heap over such a record: the cells are the existing struct of arrays, read as RawState, so FibRawInv and the forest lemmas apply unchanged. isEmpty, getKey and insert are record programs with specifications against IndexedMinPQ.step, the invariant, and the amortized cost with potential credit * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): products over one memory, and glue charges for hop 3 Products over a shared memory (cslib-community#2205 hop 3): - `Memory.Framed`: a refinement over `Memory.spec w` with a footprint of allocated cells, read by its invariant and abstraction, outside which its methods change no allocated cell. `Framed.ofStatic` for fixed layouts. - `Framed.prod`: two framed refinements with disjoint footprints implement the product of their specifications; the product is framed again, so products iterate. `Framed.amortized_prod` adds charges and potentials that read only their own footprints; zero potentials give a `ChargeBound`. - `Framed.of_fresh`, `Framed.prod_of_fresh`: allocation preserves structures and sets up products. - `Refinement.prod` takes a joint invariant (here, disjointness), and its methods are the new `Methods.prod`. The array stack is now `Stack.Memory.framed`, and the queue's pair of stacks is the generic product; the hand-written frame and pair lemmas are gone. Glue charges: `Refinement.Amortized.add`, `Amortized.glue` (glue at most `K` times a call's charge plus `K`), `Amortized.glue_of_one_le`, `StateTransitionSpec.totalCost_glue_le` and `Memory.one_le_charge`. `Queue.Memory.run_cost_glue` bounds memory charges and glue together by `(2K + 1)(6 + 9m)`. `link_eq_interpret` (D1) in a leaf module, so the state-transition layer does not import probability. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap decreaseKey with cascading cuts over a record decreaseKey cuts v from its parent when heap order breaks, cascades up the marked ancestors (fuel bounded by the number of marks), then stores the key and updates the minimum root. Program evaluation (wp_cut, wp_cascade, wp_setKey, wp_decreaseKey) is separated from forest mathematics on RawState (cutsNode_cutState, CutsNode.cascading, Cascading.mark, ...), which reuses ValidSubtree.exists_cut, mark_pending, lower_key_no_cut and CutInv.to_fibRawInv unchanged. Amortized cost: 104 record operations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap extractMin with consolidation over a record extractMin detaches the minimum root, scatters its children and the other roots into the degree table (linking equal degrees), and gathers the table into a new root list. The loops carry the existing SlotInv; linking goes through ValidRoot.link; RootList.addRoot builds the new root list. The largest degree is a program value. Amortized cost 92 * (log2 m + 1) record operations with potential 24 * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * wip: assembly * feat(DataStructure): Fibonacci heap as an amortized framed refinement over memory Assemble the five record programs into a Refinement of indexedMinPQSpec n K over the heap's record, with amortized charges 1, 2, 43, 104 and 92 * (log2 m + 1). Place the record at 9 n + 5 consecutive cells and compose with Record.refinement; the potentials stack (Amortized.comp). Package the result as a Memory.Framed structure with a static footprint, a potential local to it, and allocation of all arrays at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record Fibonacci heap; test records and insert Retain the original authorship of the native WordRAM Fibonacci heap that Basic.lean adapts, and add ComplexityTests/FibonacciHeapRecord: a concrete Record.Layout with a program run through Record.wp and Record.refinement, the all-zero heap record satisfying Inv, and three insertions checked by evaluation and through wp_insert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record decreaseKey; test a cut and cascading cut Retain the original authorship of the native Cut.lean development that DecreaseKey.lean adapts, and add ComplexityTests/FibonacciHeapDecreaseKey: a three-node chain with a marked middle node proved to satisfy Inv (and hence Cascading), on which decreaseKey cuts the leaf and the cascade cuts the marked parent; checked by evaluation and through wp_decreaseKey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): name the adapted module without a slash path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record extractMin; test a consolidation Retain the original authorship of the native Program.lean/Consolidate.lean development that ExtractMin.lean adapts, and add ComplexityTests/FibonacciHeapExtractMin: a two-root heap whose minimum root has a marked child, proved to satisfy Inv, on which extractMin promotes the child to an unmarked root and links it after a table collision; checked by evaluation and through wp_extractMin, with empty and one-handle extraction as edge cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(DataStructure): factor extractMin's forest bookkeeping into pure lemmas Move the list and forest bookkeeping of the record Fibonacci heap's extractMin out of the wp lemmas into Consolidation.lean, a companion with statements about RawState alone. Each phase has a named precondition and result (Placing, Scattering, Gathering, Consolidated, Gathered, Detached), and one pure lemma per loop step (Placing.place/collide, Scattering.unmark/step, Gathering.take) or per phase boundary (FibRawInv.detach, Detached.scatterChildren/scatterRoots/gathering/finish). The wp lemmas now only evaluate the programs and cite these. Scattering walks its trees in sibling order rather than up to a permutation, using List.Perm.exists_perm_map_eq (new, Foundations). Proof lines (scripts/proof_lengths.py): wp lemmas 609 -> 202, pure lemmas 149 -> 442, total 758 -> 644; longest proof 216 -> 69 (LinksAs.validRoot, unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(Foundations): Perm imports Complexity.Init (checkInitImports) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(FibonacciHeap): move the machine-free forest lemmas into Forest.lean The record heap's pure lemmas (`FibonacciHeap/Basic.lean`, `Consolidation.lean`) imported the hand-stepped `WordRAM/FibonacciHeap/Consolidate.lean` and `Cut.lean` only for machine-free lemmas. Move those from `Consolidate.lean` (`ValidRoot.frame_tree`, `frame_nodes`, `deg_bounds_of_extra`, `SlotInv` and its lemmas, `FHTree.eta`) and from `BasicOps.lean` (`descendant_ne_root_of_nodup`) into `Forest.lean`, unchanged, so that `Basic.lean` imports `Forest.lean` and no machine code. `DecreaseKey.lean` imports `Cut.lean` directly for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(WordRAM/FibonacciHeap): derive extractMin and insert forest reasoning from the record heap The hand-stepped proofs of `extractMinCode`, `scatterRootCode` and `insertCode` re-proved, on machine states, the forest bookkeeping that `FibonacciHeap/Consolidation.lean` and `Basic.lean` prove on `RawState n`. They now state their invariants with the pure phase predicates, applied to `RawState.ofData n base x`, and cite the pure lemmas; the instruction stepping is unchanged. * `scatterBody_exec`/`scatterLoop_exec`/`scatterRootCode_exec`: `Placing` in, `Consolidated` out; a collision is `Placing.collide`, the machine link is `LinksAs`, closed by `LinksAs.linked`. * `scatterChildrenLoop_exec`/`scatterRootsLoop_exec`: `Scattering` in, `Consolidated` out, via `Scattering.unmark`/`placing`/`step`. * `gatherSlotsLoop_exec`: `Gathering` in, `Gathered` out, via `Gathering.take`/`done`. * `extractMinCode_exec` (statement unchanged): `FibRawInv.detach`, `Detached.scatterChildren`, `scatterRoots`, `gathering` and `finish`. * `addRootAndUpdateMin_exec` now concludes `AddsRoot`, and `insertCode_exec` (statement unchanged) closes with `FibRawInv.insert`. * `insertIntoNonEmptyList_exec` takes the right neighbour `r` directly and returns the state equation only; its one other client in `Cut.lean` derives the circular list itself. * `Detached.child` records `st.child m = y + 1` (was `st.child m - 1 = y`). Deleted: `addRootIterCur_lr_frame`, `NoStore`, `mem_eq_of_noStore`, `extract_tree_by_root`, `perm_reassoc_mid`, `perm_move_to_acc`, and the inline frame, permutation and `SlotInv` bookkeeping of the loops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): the record Fibonacci heap's frame keeps the frontier (cslib-community#2239's Framed API) Record.Layout.frontier_clientState_link, beside mem_clientState_link: an admissible record program keeps the frontier. It supplies Framed.ofStatic's frontier_eq for FibonacciHeap.Memory.framed, and potential_local takes the room hypothesis that Framed.Local now has. 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>
…from the record heap (cslib-community#2278) * 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(DataStructure): Fibonacci heap insert over a record of named cells Add Record.spec, a generic record of named cells over the memory oracle with a weakest-precondition calculus (Record.wp) and a one-unit-per-operation refinement into Memory.spec. Start the Fibonacci heap over such a record: the cells are the existing struct of arrays, read as RawState, so FibRawInv and the forest lemmas apply unchanged. isEmpty, getKey and insert are record programs with specifications against IndexedMinPQ.step, the invariant, and the amortized cost with potential credit * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): products over one memory, and glue charges for hop 3 Products over a shared memory (cslib-community#2205 hop 3): - `Memory.Framed`: a refinement over `Memory.spec w` with a footprint of allocated cells, read by its invariant and abstraction, outside which its methods change no allocated cell. `Framed.ofStatic` for fixed layouts. - `Framed.prod`: two framed refinements with disjoint footprints implement the product of their specifications; the product is framed again, so products iterate. `Framed.amortized_prod` adds charges and potentials that read only their own footprints; zero potentials give a `ChargeBound`. - `Framed.of_fresh`, `Framed.prod_of_fresh`: allocation preserves structures and sets up products. - `Refinement.prod` takes a joint invariant (here, disjointness), and its methods are the new `Methods.prod`. The array stack is now `Stack.Memory.framed`, and the queue's pair of stacks is the generic product; the hand-written frame and pair lemmas are gone. Glue charges: `Refinement.Amortized.add`, `Amortized.glue` (glue at most `K` times a call's charge plus `K`), `Amortized.glue_of_one_le`, `StateTransitionSpec.totalCost_glue_le` and `Memory.one_le_charge`. `Queue.Memory.run_cost_glue` bounds memory charges and glue together by `(2K + 1)(6 + 9m)`. `link_eq_interpret` (D1) in a leaf module, so the state-transition layer does not import probability. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap decreaseKey with cascading cuts over a record decreaseKey cuts v from its parent when heap order breaks, cascades up the marked ancestors (fuel bounded by the number of marks), then stores the key and updates the minimum root. Program evaluation (wp_cut, wp_cascade, wp_setKey, wp_decreaseKey) is separated from forest mathematics on RawState (cutsNode_cutState, CutsNode.cascading, Cascading.mark, ...), which reuses ValidSubtree.exists_cut, mark_pending, lower_key_no_cut and CutInv.to_fibRawInv unchanged. Amortized cost: 104 record operations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * feat(DataStructure): Fibonacci heap extractMin with consolidation over a record extractMin detaches the minimum root, scatters its children and the other roots into the degree table (linking equal degrees), and gathers the table into a new root list. The loops carry the existing SlotInv; linking goes through ValidRoot.link; RootList.addRoot builds the new root list. The largest degree is a program value. Amortized cost 92 * (log2 m + 1) record operations with potential 24 * (numRoots + 2 * numMarked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * wip: assembly * feat(DataStructure): Fibonacci heap as an amortized framed refinement over memory Assemble the five record programs into a Refinement of indexedMinPQSpec n K over the heap's record, with amortized charges 1, 2, 43, 104 and 92 * (log2 m + 1). Place the record at 9 n + 5 consecutive cells and compose with Record.refinement; the potentials stack (Amortized.comp). Package the result as a Memory.Framed structure with a static footprint, a potential local to it, and allocation of all arrays at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record Fibonacci heap; test records and insert Retain the original authorship of the native WordRAM Fibonacci heap that Basic.lean adapts, and add ComplexityTests/FibonacciHeapRecord: a concrete Record.Layout with a program run through Record.wp and Record.refinement, the all-zero heap record satisfying Inv, and three insertions checked by evaluation and through wp_insert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record decreaseKey; test a cut and cascading cut Retain the original authorship of the native Cut.lean development that DecreaseKey.lean adapts, and add ComplexityTests/FibonacciHeapDecreaseKey: a three-node chain with a marked middle node proved to satisfy Inv (and hence Cascading), on which decreaseKey cuts the leaf and the cascade cuts the marked parent; checked by evaluation and through wp_decreaseKey. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): name the adapted module without a slash path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): credit Renfei Zhou in the record extractMin; test a consolidation Retain the original authorship of the native Program.lean/Consolidate.lean development that ExtractMin.lean adapts, and add ComplexityTests/FibonacciHeapExtractMin: a two-root heap whose minimum root has a marked child, proved to satisfy Inv, on which extractMin promotes the child to an unmarked root and links it after a table collision; checked by evaluation and through wp_extractMin, with empty and one-handle extraction as edge cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(DataStructure): factor extractMin's forest bookkeeping into pure lemmas Move the list and forest bookkeeping of the record Fibonacci heap's extractMin out of the wp lemmas into Consolidation.lean, a companion with statements about RawState alone. Each phase has a named precondition and result (Placing, Scattering, Gathering, Consolidated, Gathered, Detached), and one pure lemma per loop step (Placing.place/collide, Scattering.unmark/step, Gathering.take) or per phase boundary (FibRawInv.detach, Detached.scatterChildren/scatterRoots/gathering/finish). The wp lemmas now only evaluate the programs and cite these. Scattering walks its trees in sibling order rather than up to a permutation, using List.Perm.exists_perm_map_eq (new, Foundations). Proof lines (scripts/proof_lengths.py): wp lemmas 609 -> 202, pure lemmas 149 -> 442, total 758 -> 644; longest proof 216 -> 69 (LinksAs.validRoot, unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(Foundations): Perm imports Complexity.Init (checkInitImports) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(FibonacciHeap): move the machine-free forest lemmas into Forest.lean The record heap's pure lemmas (`FibonacciHeap/Basic.lean`, `Consolidation.lean`) imported the hand-stepped `WordRAM/FibonacciHeap/Consolidate.lean` and `Cut.lean` only for machine-free lemmas. Move those from `Consolidate.lean` (`ValidRoot.frame_tree`, `frame_nodes`, `deg_bounds_of_extra`, `SlotInv` and its lemmas, `FHTree.eta`) and from `BasicOps.lean` (`descendant_ne_root_of_nodup`) into `Forest.lean`, unchanged, so that `Basic.lean` imports `Forest.lean` and no machine code. `DecreaseKey.lean` imports `Cut.lean` directly for now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(WordRAM/FibonacciHeap): derive extractMin and insert forest reasoning from the record heap The hand-stepped proofs of `extractMinCode`, `scatterRootCode` and `insertCode` re-proved, on machine states, the forest bookkeeping that `FibonacciHeap/Consolidation.lean` and `Basic.lean` prove on `RawState n`. They now state their invariants with the pure phase predicates, applied to `RawState.ofData n base x`, and cite the pure lemmas; the instruction stepping is unchanged. * `scatterBody_exec`/`scatterLoop_exec`/`scatterRootCode_exec`: `Placing` in, `Consolidated` out; a collision is `Placing.collide`, the machine link is `LinksAs`, closed by `LinksAs.linked`. * `scatterChildrenLoop_exec`/`scatterRootsLoop_exec`: `Scattering` in, `Consolidated` out, via `Scattering.unmark`/`placing`/`step`. * `gatherSlotsLoop_exec`: `Gathering` in, `Gathered` out, via `Gathering.take`/`done`. * `extractMinCode_exec` (statement unchanged): `FibRawInv.detach`, `Detached.scatterChildren`, `scatterRoots`, `gathering` and `finish`. * `addRootAndUpdateMin_exec` now concludes `AddsRoot`, and `insertCode_exec` (statement unchanged) closes with `FibRawInv.insert`. * `insertIntoNonEmptyList_exec` takes the right neighbour `r` directly and returns the state equation only; its one other client in `Cut.lean` derives the circular list itself. * `Detached.child` records `st.child m = y + 1` (was `st.child m - 1 = y`). Deleted: `addRootIterCur_lr_frame`, `NoStore`, `mem_eq_of_noStore`, `extract_tree_by_root`, `perm_reassoc_mid`, `perm_move_to_acc`, and the inline frame, permutation and `SlotInv` bookkeeping of the loops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(FibonacciHeap): move the decreaseKey forest lemmas into Forest.lean `FibonacciHeap/DecreaseKey.lean` imported the hand-stepped `WordRAM/FibonacciHeap/Cut.lean` only for machine-free lemmas. Move `ValidRoot.par_eq_zero_iff_root`, `ValidSubtree.par_ne_self`, `ValidSubtree.lower_key_no_cut` and `CutInv.to_fibRawInv` unchanged into `Forest.lean`, and delete the unused `CutInv.bounds`, so that `DecreaseKey.lean` imports no machine code. `Memory.lean` and the record `decreaseKey` test import the Mathlib modules they had reached through `Cut.lean`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * refactor(WordRAM/FibonacciHeap): derive decreaseKey forest reasoning from the record heap The hand-stepped `cutNodeCode_raw`, `cutNode_forest` and `decreaseKeyCode_exec` re-proved, on machine states, the cut and cascade reasoning that `FibonacciHeap/DecreaseKey.lean` proves on `RawState n`. They now cite the pure lemmas; the instruction stepping is unchanged. * `cutNodeCode_raw` shows that the state after the cut is `cutState`, and concludes `CutsNode` through `cutsNode_cutState` (it now also takes `mark cur ≤ 1`). * `cutNode_forest` is deleted: its content is `CutsNode.cascading`. * `decreaseKeyCode_exec` (statement unchanged): the machine writes the new key first, so the forest is read with the old keys, `{ st with key := st₀.key }`, as `Cascading`; each cut is `CutsNode.cascading` (through the new `CutsNode.withKey`), the cascade ends with `Cascading.clear_root` or `Cascading.mark`, and `Cascading.lowerRootKey` or `FibRawInv.lowerKey_noCut` stores the key. * `exists_right_min_of_unlink` (new, in `DecreaseKey.lean`) is the step of `wp_cut` that both cuts need; `wp_cut` now cites it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG * fix(DataStructure): the record Fibonacci heap's frame keeps the frontier (cslib-community#2239's Framed API) Record.Layout.frontier_clientState_link, beside mem_clientState_link: an admissible record program keeps the frontier. It supplies Framed.ofStatic's frontier_eq for FibonacciHeap.Memory.framed, and potential_local takes the room hypothesis that Framed.Local now has. 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>
Part of #2205, hop 3.
worker-claude-015dlg8k-products2(Claude Code, Opus) wrote this PR;worker-claude-015dlg8k-products3(Claude Code, Opus) addressed the first review. It is stacked on #2234, which is stacked on #2229.Change
1. Allocators (
DataStructure/Memory/Alloc.lean, new). A client program first allocates its structures, then runs.Memory.Allocator D wpackages the first half:init, theroomthe allocation needs and itscost;Preand the allocated cellsownedthat the structure takes over instead of allocating (none, by default);Memory.Allocates). Its footprint lies in the cells taken over and in fresh cells (Allocates.of_mem_footprint).For any allocator and client:
Allocator.run pallocates, then runsplinked through the methods.run_correct: the memory operations are admissible, the answer is the specification's frominit, and the structure holds at the specified final state.run_cost: the memory cost is at mostcost + Φ₀ + Σ upper, given a certificateA.Amortized upper Φ₀.run_cost_leandrun_cost_isBigO: for a constant per-operation charge,cost + Φ₀ + K·m, exported asO(m).Allocators combine the way their structures do:
Allocator.prodallocates two structures one after the other. Room and cost add, and the cells taken over unite. Its preconditionAllocator.ProdPreasks for both preconditions and for disjoint cells taken over.Allocator.comp R Aputs a refinement on top.Allocator.resident M init roomtakes over a framed structureMalready in memory, with an allocation that does nothing. Its precondition is thatMholds and representsinit.Amortized.prod,Amortized.compandAmortized.residentcombine the certificates.Structures already in memory, and zeroed memory. An allocation changes no allocated cell, and, being admissible, no cell beyond its new frontier (
Memory.mem_clientState_of_frontier_le). So it keeps the other structures' preconditions and the cells they take over (pre_fresh,owned_fresh, which may assume both facts and that the reserved room still fits). A product may therefore mix structures allocated from scratch with structures the input holds, and a fresh allocator may require the memory beyond the frontier to be zero and take its storage withallocDirtyfor one unit. Dijkstra (#2220/#2238) would allocate aspq.prod (dict.prod (resident adj …)): the heap and the distance table on zeroed memory, the adjacency arrays taken over in place.Restated on the queue.
Queue.Memory.allocator = ((stack.prod stack).comp (refinement w C) _).run,run_correct,run_costandrun_cost_isBigOare one-line instances of the generic theorems. The hand-writtensetup,runClient_run,memRefinement,memMethods,mem_amortized,frontLayout,rearLayoutandallocatedare deleted.Stack.Memory.allocatorandamortized_allocatorare the stack's allocator.2. A shared room budget (
Memory.Framed.room). This lets structures allocate inside operations.Memory.validasks an allocation's new frontier to fit a word, and every structure in a product moves the frontier. So each framed structure has aroom : State → ℕ, the cells it has reserved for its future allocations:congr: the room reads only the footprint, like the abstraction. The invariant need only survive frontier growth that leavesfrontier + roomfitting a word.modifies: a method run advances the frontier by at most the room it gives up,s'.frontier + room s' ≤ s.frontier + room s.Framed.Apartkeeps the footprints disjoint andfrontier + room₁ + room₂fitting. One side's run keeps the other's room and the budget, so both may allocate. The product's room is the sum.Framed.Local).Fits w (frontier + room)in its invariant, which discharges its allocations' admissibility.Allocator.roomcovers the allocated cells plus the initial reservation, soprodreserves everybody's growth up front.0. Breaking:Framed.ofStatictakes one more hypothesis, that methods keep the frontier.Stack.Memory.modifies_methodsalready provided it.3. Composition.
Framed.modifies_demonicis the frame of a whole linked client. With it,Framed.comp R Mframes a refinement over a framed one by the same footprint and room. So a structure built on others, such as the queue, joins a product like any other.Framed.amortized_compstacks potentials.Framed.prod_of_freshsets up a product from structures allocated one after the other, given disjoint footprints.Small additions.
StateTransitionSpec.clientResult_bind,clientState_bindandclientHistory_bind(for>>=) sit besiderunClient_bind.Memory.frontier_le_clientStateis also new.Tests
ComplexityTests/DataStructureMemoryProduct.lean: three stacks laid out by hand, and three stacks allocated asA.prod (A.prod A), through the generic theorems.ComplexityTests/DataStructureMemoryAlloc.lean(new).allocDirtyon zeroed memory, reserves one more cell, and allocates it inside its firstset. Two such cells share one memory and are set alternately. The test checks the run's admissibility and answers throughAllocator.run_correct, the memory history (eachallocDirty 1sits inside itsset), and after allocation and after eachsetthe footprints, the abstractions, the frontier and the remaining room:2 + 2, then3 + 1, then4 + 0. At the boundary, from frontier251(251 + 4fits a byte) the run is admissible; from252it is not, and only the rightsetfails. Over a nonzero cell the precondition fails, and an unset cell then reads as set.Allocator.resident. The generic theorems give the answer and the cost6 + 0 + 3·6, and evaluation confirms that the input's stack is popped in place. Two stacks that the input holds in disjoint cells combine too. One stack taken over twice is rejected: no memory satisfies the product's precondition.Size. The own layer is +1701/−263 lines over #2234, of which 592 are the new test file; the library part is about 1.1k lines.
Existing notions considered
Refinement.comp/Amortized.comp,Refinement.prod,Refinement.simulates_client,Amortized.client,CostIsBigO.of_le_add_mulandrunClient_bind.Cslib.WordRAM.allocand theDynamicProgram/DynamicCertificatemachinery serve allocation at machine level.Allocatoris the oracle-level counterpart, needed so that structures overMemory.speccompose without registers.WordRAM.Modifiesis the machine-level frame.roomhas no machine-level counterpart: the WordRAM structures assume they are the only allocator, for example the doubling array'sFits w (8·|vs| + 4)validity.ownedis the oracle-level form of a footprint handed to a structure. The WordRAM input-reading routines take their input block as a parameter instead, with no product to keep apart.ZeroAbove(feat(DataStructure/PriorityQueue): indexed binary heap over the memory oracle #2237, not yet on this stack) names the zeroed-memory precondition; the test spells it out instead of duplicating the definition.Validation
At
73ca9900d93fd98fa502c0075bdc0543fa7479fc, all six gates ofscripts/check.shpass locally, and so docheck_hygiene.py --check-simp,check_tidy_surface.pyandcheck_changed_files.py --base origin/main. No abstract is affected.AI assistance
Claude Code (Opus) designed the API, wrote the Lean code and ran the checks. Outside review:
reviewer-codex-edemainerequested changes at5a872f3b6; this head addresses them.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG