Std.Do / mvcgen bridge for OracleComp #
This module provides a proposition-level bridge on top of the quantitative WP in
ProgramLogic.Unary.HoareTriple, with a Std.Do.WPMonad instance for .pure post-shape.
The bridge is scoped to almost-sure correctness (= 1).
Proposition-level bridge from quantitative WP (= 1 threshold).
Instances For
Proposition-style triple alias used by the Std.Do bridge.
Instances For
Adequacy bridge between wpProp and event probability = 1.
Support-based characterization of almost-sure postconditions for OracleComp.
wpProp rule for bind.
Std.Do WP instance for OracleComp, scoped to almost-sure correctness.
Std.Do WPMonad instance for OracleComp under wpProp.
Support-based bridge for stateful transformers over OracleComp #
The two lemmas below reduce Std.Do.Triple for StateT σ (OracleComp spec) and
WriterT ω (OracleComp spec) to support-based statements about the underlying
OracleComp distribution. They are the canonical "escape hatch" used whenever a
handler proof needs to leave mvcgen (e.g. to perform a structural induction on
OracleComp) without abandoning the Std.Do proof mode entirely.
Support characterization of Std.Do.Triple on StateT σ (OracleComp spec).
A triple ⦃P⦄ mx ⦃Q⦄ holds iff every outcome (a, s') in the support of
mx.run s satisfies the postcondition Q.1 a s', whenever the starting state
s satisfies the precondition P.
Support characterization of Std.Do.Triple on WriterT ω (OracleComp spec).
A triple ⦃P⦄ mx ⦃Q⦄ over the writer log holds iff every outcome (a, w) in
the support of mx.run satisfies Q.1 a (s ++ w) for every starting log s
satisfying P. The starting log s threads through the WP interpretation
itself, not through mx: WriterT.run mx always begins from ∅ and produces
pairs (a, w), and the WP transformer defined in
VCVio.ProgramLogic.Unary.WriterTBridge then prepends s via s ++ _ before
applying the postcondition. This is why s appears only in Q.1 a (s ++ w)
on the right-hand side.
Monoid-variant of triple_writerT_iff_forall_support.
For WriterT ω (OracleComp spec) where the log ω is a (multiplicative)
monoid, a triple ⦃P⦄ mx ⦃Q⦄ holds iff every outcome (a, w) in the support
of mx.run satisfies Q.1 a (s * w) for every starting log s satisfying
P. As in the Append-based variant, the starting log s threads through
the WP interpretation (s * _), not through mx. This is the dual of the
Append-based characterization and is what countingOracle / costOracle
proofs use (where QueryCount ι = ι → ℕ has a Monoid instance but no
Append).
Query specification for mspec/mvcgen in the .pure Std.Do view.
The bare query here resolves to HasQuery.query (m := OracleComp spec), which
unfolds to liftM (OracleSpec.query t).
Bind-chain specification shape for mspec/mvcgen in OracleComp do-blocks.
Explicit-head spec for the MonadLift OracleQuery OracleComp-form of query.
When query t appears inside a do block via MonadLift, Lean's elaborator
inserts a single MonadLift.monadLift _ (OracleSpec.query t) (no MonadLiftT
wrapper). The HasQuery.query form (the bare query after the ergonomic
cutover) instead elaborates via MonadLiftT. The two are definitionally
equal but syntactically distinct, and
Lean.Elab.Tactic.Do.Spec.findSpec matches keys syntactically against a
DiscrTree. This lemma re-states the content of Spec.query with the
explicit MonadLift.monadLift head so mvcgen finds a match in do-block
contexts.
Architectural note: mvcgen for stateful handlers over OracleComp #
Stateful handlers like cachingOracle (StateT) and loggingOracle
(WriterT) are defined as QueryImpl spec (T (OracleComp spec)) for some
state-tracking transformer T. mvcgen walks their bodies cleanly thanks
to:
The low-priority
MonadLift (OracleComp spec) (OracleComp superSpec)instance inCoercions/SubSpec.lean. By being lower priority than Lean's built-in reflexiveMonadLiftT.refl, the self-lift case (spec = superSpec) is solved byMonadLiftT.reflrather than this parametric instance, andmonadLift mx : OracleComp spec αreduces toid mx = mxdefinitionally. This is whatStd.Do.Spec.UnfoldLift.monadLift_refl(arfl-based lemma) needs in order to peel off the spurious self-lifts the parametric instance would otherwise leave behind around every nested oracle query. By being lower priority than the built-inMonadLift (OracleQuery superSpec) (OracleComp superSpec), single-query lifts also resolve via the standard "lift query then embed" path and avoid spurious walks throughliftComp.The
Spec.monadLift_querylemma below, which provides aDiscrTree-friendly@[spec]keyed by the explicitMonadLift.monadLift _ (OracleSpec.query t)head thatdo-block elaboration produces. The plainSpec.queryabove keys on a different syntactic head and doesn't fire insidedoblocks.
The first is now structural in VCVio with no special override needed. The
second is a workaround for a discrimination-tree-key normalisation gap in
upstream mvcgen and can be removed once
Lean.Elab.Tactic.Do.Spec.findSpec and Lean.Elab.Tactic.Do.Attr.mkSpecTheorem
canonicalise liftM/MonadLiftT chains.