Quantitative Hoare triples for OracleComp #
The user-facing wp_* and triple_* lemma library for the quantitative
(ℝ≥0∞) program logic on OracleComp spec. After the Loom2 cutover the
canonical heads are Std.Do'.wp and Std.Do'.Triple, both with the
exception postcondition fixed to Lean.Order.bot on the empty
Std.Do'.EPost.nil carrier (which we equip with a Lean.Order.CCPO
instance in Loom/Quantitative.lean). All lemmas are stated against
those canonical heads, exactly the shape that:
- the user-facing notation
wp⟦c⟧ post(inNotationCore.lean) elaborates to, - Loom2's
⦃ pre ⦄ c ⦃ post ⦄notation (inLoom.Triple.Basic) elaborates to, - the
vcgen/vcsteptactic infrastructure recognises after the cutover.
The keystone definitional alignment lives in Loom/Quantitative.lean:
wp _ _ = MAlgOrdered.wp _ _ is rfl for
OracleComp, so existing MAlgOrdered.wp_* machinery transports
directly into the Std.Do' shape. The Std.Do'.Triple analogue is
inductive (not definitional) and bridged via Std.Do'.Triple.iff
(pre ⊑ wp …) and triple_ofLE.
API contract #
- This unary quantitative interface is instantiated for
OracleComp spec. - Probability/evaluation assumptions are
[spec.Fintype]and[spec.Inhabited]. - The quantitative codomain is fixed to
ℝ≥0∞. - Every
wp_*lemma is stated aswp oa post = …, everytriple_*lemma asTriple pre oa post. - For ergonomic call-site syntax, the abbreviations
wpandTriplereduce to the canonical heads withepost :=. They are pure notation: every theorem is stated against the canonical forms, and tactics (vcgen,vcstep,@[wpStep], …) match on the canonical heads after abbrev unfolding.
Quantitative weakest-precondition for OracleComp spec, fixing the
exception postcondition to Lean.Order.bot. Definitionally equal to
Std.Do'.wp oa post Lean.Order.bot; see the API contract for details.
Instances For
Quantitative Hoare triple for OracleComp spec, fixing the exception
postcondition to Lean.Order.bot. Definitionally equal to
Std.Do'.Triple pre oa post Lean.Order.bot; see the API contract for
details.
Instances For
Internal alias #
MAlgOrdered.wp is rfl-equal to wp _ _ on
OracleComp via the Loom.instWP instance. The bridge wp_eq_mAlgOrdered_wp
re-exposes this so existing MAlgOrdered.wp_* lemmas can be applied with
a single rewrite.
Bridge between Loom2's inductive Std.Do'.Triple and Mathlib's ≤ on
ℝ≥0∞. Loom2 defines Std.Do'.Triple.iff against
Lean.Order.PartialOrder.rel; on ℝ≥0∞ our Lean.Order.PartialOrder
instance defines rel as Mathlib's ≤, so the two coincide. The
explicit Iff.rfl re-exposes the equivalence in ≤-form, which is what
all the downstream triple_* proofs are stated against.
Construct a Triple … from a ≤-form proof
pre ≤ wp oa post. Companion to
triple_iff_le_wp.mpr; preferred as the constructor in concrete proofs
because it avoids Lean's typeclass-projection unification failures
that arise when calling Std.Do'.Triple.intro directly with a ≤
proof.
Extract the ≤-form pre ≤ wp oa post from a
Triple …. Companion to triple_iff_le_wp.mp.
Triple lemmas (against Triple _ _ _) #
Std.Do'.Triple is an inductive wrapper around pre ⊑ wp …. The
accessor Std.Do'.Triple.iff exchanges between the inductive form and
the ≤-form; triple_ofLE packages a ≤-proof into the
constructor; pattern matching match h with | .intro h => h extracts
the underlying inequality.
A quantitative triple with precondition 0 is always true.
probEvent as a WP of an indicator postcondition.
probOutput as a WP of a singleton-indicator postcondition.
Quantitative WP rule for a uniform oracle query.
HasQuery.query form of wp_query: after the HasQuery ergonomic
cutover, the bare query t : OracleComp spec _ in user code elaborates to
HasQuery.query t. This restates the rule with that head so the
@[game_rule] registry can dispatch on user-facing goals without unfolding.
Indicator-event probability as an exact quantitative triple.
Singleton-output probability as an exact quantitative triple.
Lower bounds on probEvent are exactly indicator-postcondition triples.
Lower bounds on probOutput are exactly singleton-indicator triples.
The support event of an OracleComp occurs almost surely.
Exact probability-1 events are exact quantitative triples.
Exact probability-1 singleton outputs are exact quantitative triples.
Pr[= x | oa] = 1 ↔ Triple 1 oa (indicator). Bridge for vcgen probability lowering.
Support membership is a useful default cut function for support-sensitive bind proofs.
Loop stepping rules (Triple-level) #
Loop invariant rules #
Constant invariant through bounded iteration via replicate.
Indexed invariant through List.foldlM.
Constant invariant through List.mapM.
replicate invariant with consequence: bridges arbitrary pre/post to the invariant.
List.foldlM invariant with consequence.
List.mapM invariant with consequence.