Backwards reasoning for probabilistic Hoare judgments #
The tactics of Logic/HoareWp.lean and Logic/Inline.lean, for phoareStmt:
phoare_inline n— inline call siten(the inliner ofhoare_inline);phoare_split k— regroup the statement, the lastkstatements in a block of their own;phoare_wp k— replace the expectation by the exact expectation of the lastkstatements (phoareStmt_seq_iff). Exact for every statement but a loop: an abstract call stays a symbolicProcedure.ewpterm, a conditional with calls in its branches becomes anifof the branches' expectations (phoareStmt_seq_if);phoare_skip— atskip, the inequality or equation itself, reads generalized.
Judgments about equivalent statements #
A judgment about an equivalent statement: along s.EquivInLens s' l, the judgment about
s is the one about s' with the conditions, the expectation and the bound read through l.
phoareStmt_iff_of_equivInLens, backwards, with the conditions given up to an equation:
what phoare_inline applies.
A judgment about an equivalent statement, without renaming.
Stmt.ewp_call, at the spelling the statements carry.
wp rules for the generic driver (Logic/JudgmentWp.lean) #
Trailing deterministic code (Stmt.Det): the expectation after the update.
A trailing sampling: the average over the distribution.
A trailing call, without a specification: the callee's expectation, symbolically.
A trailing conditional with calls or samplings in its branches: the branches' expectations,
by cases on the condition (postSimp then computes them).
Conditionals with samplings or calls in Hoare triples #
A Hoare triple is a pHL judgment with bound 0 (hoareStmt_iff_phoareStmt), so a conditional
whose branches sample or call gets its wp from the expectation calculus: each branch's
outcomes off the postcondition have probability 0, an expectation postSimp computes with the
Stmt.ewp lemmas and turns back into a condition on the support (expected_eq_zero_iff).
An expectation is 0 iff the function vanishes on the support (the measure is discrete).
The wp rule for a trailing conditional with samplings or calls in its branches, for Hoare
triples: in each branch, the outcomes off B have probability 0.
What postSimp adds for Hoare triples, to compute a branch's expectation (hoare_seq_if): the
Stmt.ewp lemmas, and back from an expectation = 0 to a condition.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the right-to-left direction of the equivalence lem, its arguments by unification.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The parts of a goal phoareStmt A s g ρ r.
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoareOnStmt is the generic Judgment.onStmt (kept for the name).
Equations
Instances For
phoare_split k: regroup the statement as {x₁; …; xₙ₋ₖ}; {xₙ₋ₖ₊₁; …; xₙ} — the generic
HoareSplit.hoareSplit, as for every registered judgment.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The simp set computing an expectation: the exact expectations of the statements, the reads of
simpReads, and the uniform distribution's average.
Equations
- One or more equations did not get rendered due to their size.
Instances For
M.procedure for a procedure module M that evaluates to Module.proc q (the inliner's
module evaluation, Flatten.moduleStep?) ↦ q, the spelling call sites carry after inlining
(FairCoin.flip.procedure, say). Anything else, an abstract module say, is left as it is.
Equations
- One or more equations did not get rendered due to their size.
Instances For
M.procedure ↦ q where the procedure module M evaluates to Module.proc q
(procedureConst): one spelling for a callee, whether it came from the notation or from
inlining (where it is often a moduletype accessor applied to a record).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The default simprocs, and reduceProcedureConst.
Equations
- GaudisCrypt.PHoareWp.ewpSimprocs = do let __do_lift ← liftM Lean.Meta.Simp.getSimprocs liftM (__do_lift.add `GaudisCrypt.PHoareWp.reduceProcedureConst true)
Instances For
Simplify e with simp only over decls (theorems rewritten with, definitions unfolded)
and the default simprocs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simplify the expectation of a goal phoareStmt A s g ρ r (ewpDecls, ewpSimprocs).
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoareInline is the generic Flatten.judgmentInline: the conditions and the bound are
read through the renaming, cleaned by the inliner, then simplified like an expectation (the
condSimp this file registers for phoareStmt).
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoare_wp k's step: the last k statements by wp — the judgment-generic Judgment.wpStep,
with the phoare rules registered above (deterministic code, an exact average for a sampling, a
symbolic expectation for a call), the expectation simplified by ewpDecls after each step.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
h : f a₀ … aₙ with argument i replaced by the result r of simplifying it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A procedure judgment phoareProc P p G ρ R with its conditions P, G, R in the normal
form phoare_wp leaves expectations in (ewpDecls): the phoare[ ] notation wraps them in
lets and GaudiExpr getters. The procedure is left as it is, so that the judgment still
unifies with a call statement.
Equations
- One or more equations did not get rendered due to their size.
Instances For
One backwards step over a call, on a goal phoareStmt A {x₁; …; xₙ₋₁; x <- call p (a)} g ρ r
and a judgment h about p: close the call by phoareStmt_call_le/_ge/_eq (by the goal's
relation; an exact h serves for all three), and continue with the judgment about
x₁; …; xₙ₋₁, its expectation the bound of h under the side condition, simplified
(ewpDecls). When the continuation is literally h's postcondition and h's precondition
simplifies to True, the condition disappears.
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoare_call h: phoareCallStep h on the main goal — the last statement is a call, closed by
the procedure judgment h about the callee (EC's call (_ : P ==> Q)), or by its losslessness
h : islossless M.f (EC's call H).
Equations
- One or more equations did not get rendered due to their size.
Instances For
A procedure judgment phoareProc P p G Eq R as a conditional rewrite rule
∀ args σ, P args σ → p.ewp args G σ = R args σ, normalized like the goal (ewpDecls,
ewpSimprocs). Bounds (≤,
≥) are not rewrite rules and are rejected.
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoare_simp [h₁, …]: simplify with the simp set of phoare_wp (ewpDecls) and the exact
procedure judgments hᵢ as rewrite rules for their callees' expectations (specRewrite). On a
goal phoareStmt A s g ρ r only the expectation g is simplified; on any other goal (what
phoare_skip leaves, say) the whole goal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A loop step, on a goal phoareStmt A {x₁; …; xₙ₋₁; while c body} g ≤ r and an expectation
invariant I: phoareStmt_while_le closes the loop, leaving three goals, in order: body (one
iteration does not increase I, from the states where the test passes), exit (g ≤ I where
the test fails, simplified, reads generalized), and the judgment about x₁; …; xₙ₋₁ with I as
its expectation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoare_while_le I: phoareWhileLeStep on the main goal, with the expectation invariant I
written like a condition of a phoare[ ] judgment (an ENNReal expression; §x reads the
program variable x, or a global). Goals: body, exit, then the code before the loop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Elaborate a function of the state with values in T, written like a condition of a
phoare[ ] judgment about the goal's program (elabGoalExpectation at any type).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Elaborate an expectation written like a condition of a phoare[ ] judgment about the goal's
program: §x reads the program variable x (bound to its slot, as the notation binds it) or a
global.
Equations
Instances For
A goal ∀ σ, … about conditions and expectations: β-reduced, simplified like an expectation
(ewpDecls), reads generalized.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A loop step for a lower bound, on phoareStmt A {x₁; …; xₙ₋₁; while c body} g ≥ r, with the
invariant I and the exit probability ε (phoareStmt_while_ge). Goals, in order: body,
exit, the code before the loop, lossless, progress, and whichever of I ≤ 1, g ≤ 1,
ε ≠ 0, ε ≤ 1 simp does not close.
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoare_while_le I for lower bounds: phoare_while_ge I using ε (phoareWhileGeStep), I
written like a condition of a phoare[ ] judgment, ε a plain ENNReal.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A loop step for a lower bound with a variant, on phoareStmt A {x₁; …; xₙ₋₁; while c body} g ≥ r, with the invariant I and the variant V : ProgramState → ℕ
(phoareStmt_while_ge_variant). Goals, in order: body (the body does not decrease I),
exit, the code before the loop, and decreases (∀ k, a Hoare triple: from the test and
V = k, the body ends with V < k).
Equations
- One or more equations did not get rendered due to their size.
Instances For
phoare_while_ge I variant V: the lower-bound loop rule with a variant
(phoareWhileGeVariantStep) — for counted loops, which exit with probability 0 in all rounds
but the last. I and V written like conditions of a phoare[ ] judgment, V natural.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The end of a backwards proof, on a goal phoareStmt A skip g ρ r: the relation itself,
∀ σ, A σ → ρ (g σ) (r σ) (phoareStmt_skip_iff), β-reduced, with the reads of the state
generalized to plain values (generalizeReads).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- GaudisCrypt.PHoareWp.tacticPhoare_skip = Lean.ParserDescr.node `GaudisCrypt.PHoareWp.tacticPhoare_skip 1024 (Lean.ParserDescr.nonReservedSymbol "phoare_skip" false)