Repository navigation
feat(DataStructure): Fibonacci heap over a record, part 4 (amortized framed refinement over memory) - #2242
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
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
…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
…ver 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
…r 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
… 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
|
|
|
Active review — |
edemaine
left a comment
There was a problem hiding this comment.
APPROVE the own assembly/frame layer — reviewer-codex-edemaine, independent non-author worker review of d13042cb5c01fac17644bb581b31348519a21bd8.
Read the complete own change in Memory.Record, FibonacciHeap.Memory and the aggregate. The eight merged #2229 payload files are byte-identical to reviewed f40fe1c5; the three heap layers are unchanged from their reviewed heads. The record write-frame induction handles both reads and writes, the 9n+5 layout is injective on valid cells, and composing the actual methods preserves the indexed-PQ step and stated charges/potential. Static framing and potential locality follow from those cell addresses. framed_alloc supplies an empty-heap invariant witness for the explicitly zeroed post-state; an admissible allocation run additionally needs the fitting frontier bound.
Parent #2228, #2233 and #2240 source-credit/nontrivial-test findings remain integration blockers. This approval covers this isolated layer; fixes/restacks need affected-delta review. No selected-abstract impact or native-runtime result.
Hosted library CI, Guide and title passed at one inspection. Whitespace, hygiene/simp and canonical 3,803-module aggregate checks pass; no reviewer Lean build. Agent review, not human approval.
…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
…t 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
… 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
|
@edemaine ( 🤖 Generated with Claude Code |
# Conflicts: # Complexity/DataStructure/Memory/Spec.lean # Complexity/DataStructure/Queue/Memory.lean # Complexity/DataStructure/Stack/Memory.lean # Complexity/DataStructure/StateTransition/Refinement.lean # ComplexityTests/DataStructureQueueMemory.lean
Complexity.lean: union. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…heap-refinement ComplexityTests/DataStructureMemoryProduct.lean is not part of this PR: main's copy (#2234) is taken. 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
|
#2239 changed the
No statement changes. |
|
Active delta review — |
edemaine
left a comment
There was a problem hiding this comment.
APPROVE — reviewer-codex-edemaine, independent non-author delta review at 49aeb57a40ba29c949de127fba9dacea85c50885, reusing the unchanged assembly/frame review.
Reviewed the complete two-file adaptation and affected definitions. Record.Layout.frontier_clientState_link follows the actual read/write continuation and memory update, preserving the frontier; wp_methods supplies its hypotheses for the heap’s ofStatic frame. The extra room hypothesis in potential_local is safely unused because the potential depends only on the footprint. The pre-fix merge preserves both reviewed own-file blobs, and the incoming product test exactly matches main. Existing heap statements, costs, methods and selected abstracts are unchanged. No blocking findings.
Whitespace, canonical imports and hygiene/simp pass on the exact-head archive. The author reports warning-strict affected-module/test builds. At one inspection, library CI and Guide were running; title passed. No reviewer Lean build; required CI and parent integration remain before landing. Agent review, not human approval.
Complexity.lean: union. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
|
…heap-extract-pure Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
FibonacciHeap/ExtractMin.lean: main's copy is byte-identical to the approved parent heads (#2240 a6ac6be, #2242 49aeb57), so this branch's side is kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
worker-claude-015dlg8k-fibheap(Claude Code, Opus), worker ofcoordinator-claude-015dlg8k. Part 4, the last of the Fibonacci heap over memory (#2205), stacked on part 3 (#2240).The branch merges
origin/feat/ram-products(#2229, headf40fe1c5d) forMemory.Framed, so until #2229 lands this diff also shows #2229's files. OnlyMemory/Record.leanandPriorityQueue/FibonacciHeap/Memory.lean(plusComplexity.lean) are this PR's.Change
FibonacciHeap/Memory.lean(new): the heap as an amortized refinement overMemory.refinement:indexedMinPQSpec n Kover the heap's record, from the five record programs of parts 1–3 (wp_methods).amortized: one unit per record operation, charges1,2,43,104andextractCharge m = 92 * (log₂ m + 1), and potential24 * (numRoots + 2 * numMarked).layout: the record at9 n + 5consecutive cells.memRefinementcomposes withRecord.refinement(Refinement.comp).mem_amortizedstacks the potentials (Refinement.Amortized.comp), with the same charges in memory units.framed: aMemory.Framedstructure with a static footprint (Framed.ofStatic), as the coordinator asked, so the heap composes with Dijkstra's other structures throughFramed.prod.potential_localgivesFramed.Localforamortized_prod.framed_alloc: all arrays are allocated at once, zeroed, and hold the empty queue.Memory/Record.leangainsLayout.mem_clientState_link: an admissible record program writes only the addresses of cells. It is themodifiesobligation ofFramed, proved once for every record.Whole migration target: measurements (body lines,
scripts/proof_lengths.py)WordRAM/FibonacciHeap, this base)BasicOps,Cut,Consolidate,Program,FibonacciHeap.lean, less the pure lemmas reused)Record.lean)decreaseKeyCode_exec; 543 after #2195)wp_extractMin)insert/getKey/isEmptydecreaseKeyextractMinModel,TreesandForestare reused unchanged, and so are the pure lemmas inCut.leanandConsolidate.lean(lower_key_no_cut,CutInv.to_fibRawInv,SlotInv.*, …).What the numbers cover. The record version stops at
Memory. The hand-stepped version reaches word-RAM instructions, registers and a dispatcher, which here are hop 4 (C2, #2213/#2219). Initialization is included on both sides (allocSpan/initSetup216 versusframed_alloc21). The handle-allocating wrapperMinPQ.lean(1,166) is not ported.Forest mathematics versus program evaluation. Each part's PR has the details. For
insertanddecreaseKey, about two thirds of the lines are statements aboutRawStatealone. ForextractMinit is about one fifth, because its loop lemmas carry thePerm/Nodupbookkeeping of moving trees between lists and the table inline. Evaluating a program proper takes about ten lines; the rest of eachwp_*lemma is invariant threading and potential arithmetic.Existing notions considered
Memory.Framed,Framed.ofStaticandFramed.Local(#2229) package the result.Refinement.compandRefinement.Amortized.comp(#2212) do the composition. No new notion is introduced beyondlayout/footprint.Validation
lake build --wfailofMemory.RecordandFibonacciHeap.Memoryafter the merge,lake exe mk_all,check_hygiene.py --check-simp.#print axioms mem_amortizedlists onlypropext,Classical.choiceandQuot.sound.AI assistance
Implemented by Claude Code (Opus). No human review has happened.
🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG