pHL on an exact bound: EC's rnd E, conseq, islossless #
EC proves phoare[ c; x <$ d : P ==> Q ] = r by
rnd E. (* c : P ==> mu d E = r /\ forall v, v \in d => (E v <=> Q v) *)
conseq (: _ ==> true). (* the condition holds in every state *)
islossless. (* c is lossless *)
The judgments of Logic/PHoare.lean are about expectations, and their rules for a sampling
(phoare_auto, rnd_pred1) work on the expectation it leaves, for upper bounds. Here are EC's
three steps for an exact bound, on the judgment itself.
An expectation that is r on an event of probability 1 (and at most 1 elsewhere) has
expected value r.
EC's pHL rnd E on an exact bound: the code before the sampling reaches, with
probability 1, a state in which E has probability r under the distribution and, on its
support, E is the postcondition.
EC's conseq (: _ ==> Q') on phoare[ … ] = 1: a weaker condition that is still reached
with probability 1.
EC's mu d E: the probability of the event E under d, a real.
Equations
- GaudisCrypt.EC.mu d E = (d.expected fun (v : α) => GaudisCrypt.indicatorE (E v)).toReal
Instances For
EC's mu1 d c is mu d (pred1 c).
phoareStmt_rnd_eq for a real bound (Pr[ … ] = r): the event's probability as EC's
mu d E.
EC's pHL rnd E on a lower bound, phoare[ c; x <$ d : P ==> Q ] ≥ r: the code before
the sampling reaches, with probability 1, a state in which E has probability at least r
and, on the distribution's support, implies the postcondition.
phoareStmt_rnd_ge_ofReal with the postcondition itself as the event (EC's rnd on a
lower bound).
Events reached with probability 1 #
phoare[ c : P ==> Q ] = 1 with Q an event: EC's rules keep it an event (a lossless call
leaves ∀ result, Q, a sampling is_lossless d ∧ ∀ v ∈ d, Q), where the rules on expectations
(Logic/PHoareWp.lean) would leave a product of indicators, a sum, or a callee's expectation.
EC's call H with H : islossless f, on phoare[ c; x <@ f(a) : P ==> Q ] = 1: the
code before the call reaches, with probability 1, a state from which Q holds whatever the
call returns (and whatever globals it leaves).
EC's pHL rnd (rnd predT) on phoare[ c; x <$ d : P ==> Q ] = 1: the distribution is
lossless and Q holds on its support.
The end of a proof of phoare[ skip : P ==> Q ] = 1: P implies Q.
The expectation 1 is the event True.
The expectation of the phoare judgment g as one event, fun τ => indicatorE (Q τ)
(the rules on expectations split a conjunction into a product, a conditional into two
indicators); with one, the expectation 1 is the event True. none if it is not an
event.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Is the judgment g an exact one with the bound 1 (ENNReal.ofReal 1, as byphoare
leaves it, is rewritten to 1)? none, the state restored, if not.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The event of the judgment m (fun τ => indicatorE (P τ)) simplified under the indicator
(ewpDecls: the reads through the last statement's write), so that it stays one event; keep,
if given, is abstracted meanwhile (a bound, kept as it is written).
Equations
- One or more equations did not get rendered due to their size.
Instances For
A rule about c; s (its hypothesis h the judgment about c) matched with a goal: the
goal split before its last statement, the rule applied to metavariables, and those by name.
- goal : Lean.MVarId
- proof : Lean.Expr
- arg : Lean.Name → Lean.MetaM Lean.Expr
Instances For
Match the rule lem with the goal g, split before its last statement. Nothing is
assigned yet but the split (EventRule.close); none, the state restored, if the rule does not
fit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Apply the matched rule: the new goal is its hypothesis h, tagged judgment.
Equations
Instances For
EC's call H, H : islossless f, on an event reached with probability 1
(phoareStmt_call_lossless_eq_one).
Equations
- One or more equations did not get rendered due to their size.
Instances For
EC's pHL rnd on an event reached with probability 1
(phoareStmt_rnd_lossless_eq_one).
Equations
- One or more equations did not get rendered due to their size.
Instances For
EC's auto on phoare[ c : P ==> Q ] = 1, Q an event: backwards over the code to the
last call (an assignment or a conditional by wp, a sampling by rnd), the judgment an event
throughout; skip when the code is used up. false if the goal is not such a judgment.
Equations
- One or more equations did not get rendered due to their size.
Instances For
EC's pHL rnd E on an exact bound, phoare[ c; x <$ d : P ==> Q ] = r: the goal becomes
phoare[ c : P ==> mu d E = r ∧ ∀ v ∈ d, (E v ↔ Q v) ] = 1 (phoareStmt_rnd_eq). E is a
predicate on the sampled value and may read the program's variables (pred1 §b').
EC's rnd (no event: rnd predT), on phoare[ c; x <$ d : P ==> Q ] = 1: the goal becomes
phoare[ c : P ==> is_lossless d ∧ ∀ v ∈ d, Q v ] = 1 (phoareStmt_rnd_lossless_eq_one).
Equations
- One or more equations did not get rendered due to their size.
Instances For
EC's conseq (: P' ==> Q') on a lower bound phoare[ c : P ==> Q ] ≥ r: a weaker
precondition and a stronger event; what the precondition says may be used for the events.
EC's conseq (: _ ==> true) (: _ ==> Q) on phoare[ c : P ==> Q ] = 1: the code is
lossless, and Q holds after it (a Hoare triple).
A side condition about two states, ∀ σ, A σ → ∀ τ, B τ: over values, the reads of σ
generalized first, then those of τ.
Equations
- One or more equations did not get rendered due to their size.
Instances For
EC's conseq (: _ ==> true) (: _ ==> Q) on phoare[ c : P ==> Q ] = 1
(phoareStmt_eq_one_of_hoare_lossless): goals hoare (the triple hoare[ c : P ==> Q ]), then
lossless (phoare[ c : P ==> true ] = 1) — EC's order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The uniform distribution on a finite nonempty type is lossless, as the sum phoare_auto
leaves at a sampling from it.
The procedure the last statement of s calls, if it is a call.
The number of statements of s (under the lets of its local variables).
EC's islossless on phoare[ c : P ==> 1 ] = 1: the code statement by statement from the
end (phoare_seq_lossless … : True), an assignment or a sampling by phoare_auto, a call by a
new goal islossless p (phoare_call). The calls' goals, the last call first.
EC's islossless: a statement without loops is lossless when its samplings and the
procedures it calls are. On phoare[ c : P ==> true ] = 1 (and on islossless M.f): a call of
a concrete procedure is opened in turn; one goal islossless p per call of an abstract one, the
last call first (EC's order).
Equations
- GaudisCrypt.islosslessTac = Lean.ParserDescr.node `GaudisCrypt.islosslessTac 1024 (Lean.ParserDescr.nonReservedSymbol "islossless" false)