Repository navigation
feat(DataStructure): compose coin-using distributional hops; deterministic hops as distributional - #2236
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
…er 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 #2205). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
…tic hops as distributional Follow-ups to #2232 for #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
|
Independent reviewer: Claude Code (Opus 5.5), thread The design is the right size:
The tests are good nonvacuity evidence: a concrete "wasteful" upper hop over the random table, stacked to one coin stream over memory, with both its law and its expected cost stated. No findings. Limits: I read the diff's statements and the new |
|
|
#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
…tion branch The merge brings feat/ram-random-hop's fix for the names #2201 retired. The only follow-up in this branch's own code is a test step that now closes by rewriting. 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.
APPROVE the delta — reviewer-codex-edemaine, independent non-author worker review of 63cf2c48270125593ba0f439c2db0b15a5828746.
Reused the independent own-layer review at 27d9b52e. The four library patches are unchanged over reviewed #2232 eb950a07; all unrelated parent entries are exact. Read the sole test-proof adjustment: removing the final rfl after the rewrite closes the same ignored-coin law, with no statement or coverage change. Handler semantics remain covered by the parent migration review; no API, resource-bound or abstract delta.
Whitespace, hygiene/simp and canonical aggregate checks passed; no local Lean run. At one inspection, title passed and library CI and Guide were running. Agent review, not human approval.
|
|
Add/add conflicts in HashFamily/Memory, StateTransition/Randomized and the HashFamily test: main's copies are byte-identical to the approved parent #2232 head eb950a0, so this branch's side is kept. Complexity.lean: union. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
|
|
…r-spec Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG
StateTransition/Randomized.lean: main's copy is byte-identical to the approved parent #2236 head 63cf2c4, 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-randhop2(Claude Code, Opus). Follow-ups to #2232 for #2205 (decision D10). Stacked on #2232; the base isfeat/ram-random-hop, so the diff shows only this change. Retarget tomainonce the stack lands.Change
Coin-using hops compose (
DataStructure/StateTransition/Randomized.lean):RandomizedRefinement.withCoins M : RandomizedRefinement D.withCoins F.withCoins. Coins pass through unchanged, calls ofDrunM's methods, and the invariant and abstraction areM's.RandomizedRefinement.mergeCoins G : RandomizedRefinement G.withCoins.withCoins G.withCoins. Two layers of coins are one, by the identity on states.M.compCoins N := M.comp (N.withCoins.comp (mergeCoins G)), forM : RandomizedRefinement D F.withCoinsandN : RandomizedRefinement F G.withCoins. Cuckoo hashing needs this: its own coins over a hash family with coins.RandomizedSpec.coinCharge coin chargecharges coins and calls separately.ExpectedAmortized.withCoins,expectedAmortized_mergeCoinsandExpectedAmortized.compCoinsgive(M.compCoins N).ExpectedAmortized (coinCharge coin lower) upper (Φ ∘ N.abs + Ψ).Deterministic hops as distributional ones.
Refinement.toRandomized : Refinement D E → RandomizedRefinement D.toRandomized E.toRandomizedkeeps the methods, invariant and abstraction.Refinement.Amortized.toRandomizedturns pathwise amortized costs into expected ones, throughStateTransitionSpec.expectedCost_toRandomized(the expected charge of a deterministic run is the total charge of its history). So a deterministic structure overMemorylifts to(Memory.spec w).toRandomized.withCoinsbyM.toRandomized.withCoins, under a randomized client.isKWiseIndependentHash_idmade public. It moves unchanged from a private lemma ofDictionary/CuckooHashing.leantoProbability/KWiseIndependent.lean, beside the definition, asCslib.Probability.isKWiseIndependentHash_id. Its one client now uses the public lemma. The random-table pilot gets its contract:RandomTable.kWiseSpec_contract_runsays that for everyk, oblivious transcripts of the run from allocation meetHashFamily.kWiseSpec. No open PR touches either file (gh pr listchecked).Smaller additions:
RandomizedSpec.run_query,expectedCost_query,withCoins_law_inl,demonicValid_coin,demonicValid_query_inr,expectedCost_liftRight,coinCharge_const, andStateTransitionSpec.toRandomized_demonicValid, whichtoRandomized_demonicValid_of_validHistorynow uses.Existing notions considered.
RandomizedRefinement.comp(reused:compCoinsis a composition),Refinement/Refinement.Amortized(reused as the source oftoRandomized),ProbOracleComp.handler,OracleComp.liftRight/sumHandler(reused for coins), andExpectedAmortized.of_isCostBounded. No existing declaration lifts a refinement through private coins or merges coin streams.Validation
ComplexityTests/HashFamilyMemory.leanchecks thekWiseSpeccontract on a concrete operation list. It also stacks a small upper hop with coins of its own (it draws a bit before each resample and ignores it) on the random table withcompCoins, then instantiatesrun_linkandExpectedAmortized.compCoinson the stack. The changed modules,Dictionary/CuckooHashing.leanand the test build locally.check_hygiene.py --check-simp,check_tidy_surface.py,check_changed_files.py --base origin/main,lint-styleandmk_all --checkpass. Hosted CI runs the six gates.AI assistance
Written by Claude Code (Opus) as worker
worker-claude-015dlg8k-randhop2; not yet reviewed.🤖 Generated with Claude Code
https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG