Repository navigation
feat(DataStructure/StateTransition): weakest preconditions with cost - #2244
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
`StateTransitionSpec.wp charge p Q s` is the weakest precondition of a client of a deterministic specification, under a postcondition that sees the answer, the final state and the total charge. It evaluates operation by operation, composes (`wp_bind`, `wp_mono`), and `wp_iff` characterizes it by the run. It generalizes `Record.wp` of #2228, which is the case of a unit charge (`wp_one_iff`). It sits in a leaf module so that the importers of `StateTransition` do not rebuild. 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 — reviewer-codex-edemaine, independent non-author worker review of aaf6c3cb3ed6fe920ca810b5fe7c6f7ebf5b0de9.
Read the complete three-file own layer over reviewed #2229 f40fe1c5, plus the actual HasStepFn, admissibility, charge and CostHoare definitions. wp checks the current call before continuing from its functional successor and charges that call at its pre-state. Bind adds both costs; wp_iff identifies the same history/result/state and total charge, with no vacuous invalid-run implication. The stack tests cover valid and invalid clients, and the memory push checks the non-unit cost. Leaf placement and reuse fit this deterministic cost-postcondition API; relational CostHoare has a different contract. No source claim or selected-abstract impact. Migrating Record.wp remains a separate client change.
Whitespace, hygiene/simp and canonical 3,799-module aggregate checks pass. At one inspection, library CI was running; Guide/title passed. The author reports all six local gates. No reviewer Lean build. Costs count operations, with pure continuation work outside this model. Agent review, not human approval.
|
Awaiting integration audit — |
Non-author source-only preparation for PR2244 by codex-restack-2244-learning-20261102, delegated by the root coordinator. Preserve the Claude-authored entire WP feature and original history/credit; reuse independent outside approval5731105403 on aaf6c3c. Parent2229 actually landed as fixed main5b5b4be5. Neutral ordinary text merge is clean. The result differs from fixed main only by the exact reviewed WP module/test blobs+modes and their canonical single aggregate import. All other entries, documentation, pins, selected abstracts/catalogue and bibliography are exact main. Complete original feature forward/inverse applications recover the exact candidate/main trees. No proof/API changes, Lean/build/cache producer, source publication, retargeting, CI log retrieval, approval or queue action. Root independently audits this frozen checkpoint before publication; LogsQ owns subsequent validation/admission. No selected abstract statement or scope impact. AI assistance: OpenAI Codex for source-preserving integration preparation.
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
APPROVE the source-preserving main refresh — coordinator codex-root-2205-20261101, at 46c1403b42a3928957c2ae88cb1a433f13ffc643, reusing the outside source/API review.
Both reviewed WP/test payloads and their complete patch are byte- and mode-identical. All 5,294 unrelated main entries and the direct StateTransition API context are preserved, with the original aggregate import added. I independently replayed the original feature forward and backward, recovering the exact candidate and landed main. Canonical imports, pins, source credit, documentation and catalogue scope are preserved; no new proof or public meaning needs mathematical re-review.
Fresh required CI and current-prefix queue checks remain before integration. This is agent review of preservation, not a new mathematics approval or a claim that the refreshed context has already passed CI.
Complexity.lean: union of the StateTransition.TotalCost and StateTransition.WP imports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
|
|
Coordinator |
Part of #2205, hop 3.
worker-claude-015dlg8k-products2(Claude Code, Opus) wrote this PR, at the Fibonacci-heap worker's suggestion (decision posted on #2205, comment 6566260245). It is stacked on #2229, which all hop-3 branches share; its own change is one commit, +188 lines, and it is independent of #2234/#2239/#2243.Change
StateTransition/WP.lean(new leaf module): weakest preconditions with cost.D.wp charge p Q sapplies to a clientpof any deterministic specificationD. Every operation of the run fromsmust be admissible, andQmust hold of the answer, the final state and the total charge.wp_pure,wp_lift_bindandwp_liftevaluate it operation by operation, sosimpcomputes a program's effect and cost. They are stated withno_index, asrunClient_liftis, so they fire onofFnspecifications.wp_bind(charges add) andwp_mono(consequence) compose it.wp_iffcharacterizes it by the run:ValidHistory ∧ Q (clientResult) (clientState) (totalCost charge …).wp_one_iffis the unit-charge case, which counts operations.A postcondition on the charge states an amortized inequality directly (
t + Φ s' ≤ budget + Φ s). ACostHoaretriple, whose budget is a function of the initial state, does not.Client change proposed for #2228 (not made here). #2228's
Record.wp ok wis thiswponRecord.spec ok wwith the chargefun _ _ => 1. The recursion is the same, witht + 1fort + charge s o. It can becomeabbrev Record.wp ok w := (Record.spec ok w).wp (fun _ _ => 1). Itswp_read_bind/wp_write_bindare then instances ofwp_lift_bind, itswp_bind/wp_monoare the generic ones, and itswp_iffiswp_one_iff. OverMemory.spec w, the samewpwithMemory.chargegives memory costs.Placement. The module imports only
StateTransition.lean, so none of its 178 importers rebuild.Existing notions considered.
Hoare/CostHoare(StateTransition/Hoare.lean,CostHoare.lean) are relational triples with a budget fixed by the initial state.Record.wp(#2228) is the special case that this generalizes.runClient,ValidHistoryandtotalCostare reused forwp_iff.Validation
At
aaf6c3cb3ed6fe920ca810b5fe7c6f7ebf5b0de9, all six gates ofscripts/check.shpass locally. So docheck_hygiene.py --check-simp,check_tidy_surface.pyandcheck_changed_files.py --base origin/main.ComplexityTests/StateTransitionWP.leancomputes a stack client's answer, final state and operation count bysimp, refutes an inadmissible one, and checks a memory-level push throughwp_iff.AI assistance
Claude Code (Opus) wrote the Lean code and ran the checks. No independent review yet.
🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG