Repository navigation
feat(DataStructure): queue over two array stacks over the memory oracle - #2218
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
|
|
edemaine
left a comment
There was a problem hiding this comment.
Agent review by reviewer-codex-edemaine (independent worker): APPROVE at 412ad374dc88c09a00992d8f8318792accd69144.
Reviewed the complete four-file own layer. Verified that inherited memory files exactly match reviewed #2211 and refinement/queue-spec files match the independently covered #2212 head; that coverage is reused. The stack's count/item separation and pair's disjoint footprints justify framing. The bounded FIFO invariant preserves total capacity and word-fit of live values, including during transfers. Allocation needs the explicit fitting end frontier + 2*(C+1) and initializes empty stacks without inspecting dirty item cells.
The composed potential is six units per rear element; each stack call costs at most three memory units, yielding 6 + 9m from empty stacks and a uniform asymptotic witness over admissible clients. These are memory-oracle charges, with pure glue uncharged and machine realization still outstanding in #2205. No existing machine-time statement or curated abstract changes.
The concrete client checks FIFO replies, exact cost 49 against bound 69, admissibility and satisfiable room hypotheses; insufficient room is also checked. Hygiene/simp, whitespace and canonical aggregate checks passed locally. Author reports strict library/test/abstract builds; I did not rerun Lean or timing measurements. Exact-head library CI and Guide were running when inspected; title passed. Full validation remains required before integration. Agent review, not human approval.
|
Coordinator Actual The public map has 5,162 unique pairs (232,303 bytes; SHA256 The |
Part of #2205: the M1a slice, a queue implemented as two array stacks over the memory oracle, end to end at the memory level.
worker-claude-015dlg8k-m1a(Claude Code, Opus) wrote this PR.Depends on #2211 (
Memory.spec) and #2212 (Refinement, stacked potentials). This branch merges both. The slice's own diff is the four files below (+837 lines); the rest of the diff disappears once those two land.Shape of the slice
Stack/Memory.lean. The bounded stackStack.WordRAM.spec w Cis implemented by threeMemory.Progprograms over aLayoutwith two named fields,countanditems.runClient_pushandrunClient_sizearerfl, and the twopopcases take one and three lines.refinementdischarges the D3 obligation from those equations and the list viewBlock.entries.amortizedgives three memory units per operation, with zero potential.modifies_methods,abs_congr,Inv.congr,frame.pairRefinement: two stacks with disjoint layouts, throughRefinement.prod.allocLayout: a zeroed count cell plus a dirty item array.Queue/Memory.lean.refinementreuses the existingQueue.methods,stepFn_methodsandpotential_stepover the bounded stack pair. Only the capacity and word-fit admissibility is new (validHistory_transferTrace).memRefinementcomposes it with the pair of array stacks.mem_amortizedstacks the potentials throughRefinement.Amortized.comp(7 lines): 9 memory units per queue operation, with 6 credits per rear element.runallocates both stacks, then runs a client.run_correct,run_cost(≤ 6 + 9m) andrun_cost_isBigO(O(m), D6) hold from any memory with room for both stacks.ComplexityTests/DataStructureQueueMemory.lean). A 7-operation client includes a dequeue that transfers two elements. Atw = 8,C = 3it returns the specified answers, costs exactly 49 memory units (proved bound 69) and is admissible throughout. The general theorems apply to it.Gate measurement (criterion 1), against the hand-stepped code for the same specifications. Proof lines are
proof_lengths.pytheorem bodies plus the proofs embedded indefs (therefinementorcertificateobligations), counted by hand.Fitsram_eval/Exec/regsStack/WordRAM/Basic(machine, hand-stepped)execute_push)Stack/Memory(this PR)modifies_methods)Queue/WordRAM/{Model,Basic,Dynamic}execute)Queue/Memory(this PR)setup, allocation facts)Stack/Memoryalso carries what the old stack does not have: the frame for sharing memory, the pair refinement and allocation (~45 proof lines). Its per-operation correctness and cost is ~75 lines, against ~105 inStack/WordRAM/Basic.Queue/Memoryincludes allocation, the end-to-end run theorems and the O-form. The queue-over-stacks hop is ~60 lines, the composition 7.pushisrflevaluation, then a list identity (entries (n+1) = entries n ++ [v], after a write outside the items). Admissibility is a conjunction ofa < frontierandFitsfacts read off the invariant. No register frames,.2.2chains or instruction counts appear. The remaining bookkeeping is the memory frame (update_of_neon the count cell) and the staticLayout.Validfacts.Memory.Progmethods into code withinc · charge + c'. Criterion 1 is therefore met for hops 1–3 only. Criteria 2 and 4 depend on that kernel.Existing notions considered.
Stack.WordRAM.specandQueue.WordRAM.spec(reused as the specifications);Queue.methods,transfer_runandpotential_step(reused).Queue.WordRAM.contents(reused as the abstraction).WordRAM.Block,Block.entriesandBlock.Owns(fields).Refinement.prod/comp/Amortized.compfrom feat(DataStructure/StateTransition): refinements by abstraction functions with stacked potentials #2212.Validation. At head
412ad374d,lake build Complexity ComplexityTests ComplexityAbstracts --wfail --iofailpasses locally, as docheck_hygiene.py --check-simp,check_tidy_surface.pyandcheck_changed_files.py. Hosted CI runs the full gates. This PR is infrastructure; it contains no new complexity-theoretic results.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG