Documentation

GaudisCrypt.Logic.PHoare

Probabilistic Hoare logic #

EasyCrypt's phoare[ c : P ==> Q ] ⋈ r (⋈ one of =, ≤, ≥): from every state satisfying P, the probability that c ends in a state satisfying Q is ⋈ r.

The judgment is stated for an expectation g rather than an event: Stmt.ewp c g σ is the expected value of g after running c from σ, and an event Q is its indicator if Q then 1 else 0. The reason is the sequencing law phoareStmt_seq_iff, which is exact, for all three relations: the judgment about p; q is the one about p with the expectation g replaced by q.ewp g. So backwards reasoning only ever rewrites the expectation, as long as the code has an exact wp (everything but loops, including calls to abstract procedures, whose wp stays a symbolic term).

The relation ρ is Eq, LE.le or GE.ge (the constants, not lambdas, so that rules and the printer can match on them); the bound r may depend on the initial state.

noncomputable def GaudisCrypt.Stmt.ewp (c : Stmt) (g : ProgramState → ENNReal) :

The expected value of g after running c from σ.

Equations
Instances For
    noncomputable def GaudisCrypt.Procedure.ewp {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (G : sig.ret → VariableAssignment → ENNReal) :

    The expected value of G (of the result and the globals) after running the procedure p on args from the globals σ.

    Equations
    Instances For

      phoare[ A ==> g ] ρ r { c }: from every state satisfying A, the expected value of g after c is in the relation ρ to r.

      Equations
      Instances For

        phoare[ p : A ==> G ] ρ r: on all arguments and globals satisfying A, the expected value of G after p is in the relation ρ to r.

        Equations
        Instances For

          Events and probabilities #

          noncomputable def GaudisCrypt.indicatorE (Q : Prop) :

          The indicator of a proposition, as an expectation: 1 if it holds, else 0 (EC's b2r).

          Equations
          Instances For
            noncomputable def GaudisCrypt.Procedure.Pr {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (σ : VariableAssignment) (E : sig.ret → VariableAssignment → Prop) :

            The probability that the procedure p, run on args from the globals σ, ends with a result and globals satisfying E — EC's Pr[p(args) @ &σ : E].

            Equations
            Instances For
              theorem GaudisCrypt.Procedure.Pr_eq_ewp {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (σ : VariableAssignment) (E : sig.ret → VariableAssignment → Prop) :
              ↑(p.Pr args σ E) = p.ewp args (fun (v : sig.ret) (g : VariableAssignment) => indicatorE (E v g)) σ

              A probability is the expectation of the event's indicator.

              theorem GaudisCrypt.Procedure.Pr_of_phoareProc {sig : ProcedureSignature} {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {E : sig.ret → VariableAssignment → Prop} {ρ : ENNReal → ENNReal → Prop} {r : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc A p (fun (v : sig.ret) (g : VariableAssignment) => indicatorE (E v g)) ρ r) {args : sig.ParamType} {σ : VariableAssignment} (hA : A args σ) :
              ρ (↑(p.Pr args σ E)) (r args σ)

              EC's byphoare: a probability, from a procedure judgment about the event.

              EC's islossless p: p terminates with probability 1, on all arguments and globals.

              Equations
              Instances For
                theorem GaudisCrypt.Procedure.isLossless_iff_phoareProc {sig : ProcedureSignature} (p : Procedure sig) :
                p.IsLossless ↔ phoareProc (fun (x : sig.ParamType) (x_1 : VariableAssignment) => True) p (fun (x : sig.ret) (x_1 : VariableAssignment) => 1) Eq fun (x : sig.ParamType) (x_1 : VariableAssignment) => 1

                Hoare triples as probability-0 judgments #

                theorem GaudisCrypt.hoareStmt_iff_phoareStmt {A : ProgramState → Prop} {c : Stmt} {B : ProgramState → Prop} :
                hoareStmt A c B ↔ phoareStmt A c (fun (σ : ProgramState) => indicatorE ¬B σ) Eq fun (x : ProgramState) => 0

                hoare[ A ==> B ] { c } is phoare[ A ==> ¬B ] = 0 { c }.

                theorem GaudisCrypt.hoareProc_iff_phoareProc {sig : ProcedureSignature} {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {B : sig.ret → VariableAssignment → Prop} :
                hoareProc A p B ↔ phoareProc A p (fun (v : sig.ret) (g : VariableAssignment) => indicatorE ¬B v g) Eq fun (x : sig.ParamType) (x_1 : VariableAssignment) => 0

                The same for procedures.

                Structural rules #

                theorem GaudisCrypt.phoareStmt_seq_iff {A : ProgramState → Prop} {p q : Stmt} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} :
                phoareStmt A (StmtWithHoles.seq p q) g ρ r ↔ phoareStmt A p (q.ewp g) ρ r

                Sequencing is exact: the judgment about p; q is the one about p, with q's expected value of g in place of g.

                theorem GaudisCrypt.phoareStmt_pre {A A' : ProgramState → Prop} {c : Stmt} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (h : phoareStmt A' c g ρ r) (hA : ∀ (σ : ProgramState), A σ → A' σ) :
                phoareStmt A c g ρ r

                Strengthening the precondition.

                theorem GaudisCrypt.phoareStmt_le_of_le {A : ProgramState → Prop} {c : Stmt} {g g' r : ProgramState → ENNReal} (h : phoareStmt A c g' LE.le r) (hg : ∀ (σ : ProgramState), g σ ≤ g' σ) :

                An upper bound is monotone in the expectation, downwards.

                theorem GaudisCrypt.phoareStmt_ge_of_ge {A : ProgramState → Prop} {c : Stmt} {g g' r : ProgramState → ENNReal} (h : phoareStmt A c g' GE.ge r) (hg : ∀ (σ : ProgramState), g' σ ≤ g σ) :

                A lower bound is monotone in the expectation, upwards.

                theorem GaudisCrypt.phoareStmt_le_of_eq {A : ProgramState → Prop} {c : Stmt} {g r : ProgramState → ENNReal} (h : phoareStmt A c g Eq r) :

                An exact judgment gives both bounds.

                theorem GaudisCrypt.phoareStmt_eq_of_le_ge {A : ProgramState → Prop} {c : Stmt} {g r : ProgramState → ENNReal} (h₁ : phoareStmt A c g LE.le r) (h₂ : phoareStmt A c g GE.ge r) :
                phoareStmt A c g Eq r

                Two bounds give an exact judgment.

                theorem GaudisCrypt.phoareStmt_skip_iff {A : ProgramState → Prop} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} :
                phoareStmt A StmtWithHoles.skip g ρ r ↔ ∀ (σ : ProgramState), A σ → ρ (g σ) (r σ)

                At skip, the judgment is about g itself.

                Exact expectations of the statements #

                theorem GaudisCrypt.Stmt.ewp_assign {α : Type} (x : Setter α ProgramState) (e : Getter α ProgramState) (g : ProgramState → ENNReal) :
                ewp (StmtWithHoles.assign x e) g = fun (σ : ProgramState) => g (x.set (e.get σ) σ)
                theorem GaudisCrypt.Stmt.ewp_sample {α : Type} (x : Setter α ProgramState) (e : Getter (SubProbability α) ProgramState) (g : ProgramState → ENNReal) :
                ewp (StmtWithHoles.sample x e) g = fun (σ : ProgramState) => (e.get σ).expected fun (a : α) => g (x.set a σ)
                theorem GaudisCrypt.Stmt.ewp_call {sig : ProcedureSignature} (x : Setter sig.ret ProgramState) (p : Procedure sig) (args : Getter sig.ParamType ProgramState) (g : ProgramState → ENNReal) :
                (call x p args).ewp g = fun (σ : ProgramState) => p.ewp (args.get σ) (fun (v : sig.ret) (gl : VariableAssignment) => g (x.set v (ProgramState.globalL.set gl σ))) σ.globals

                A call's expectation is the callee's, at the arguments, of g after writing the result and the globals back. For an abstract callee this stays a symbolic term.

                Expectation algebra #

                What is left of a judgment once phoare_wp has run: sums and quotients of symbolic procedure expectations. Linearity, losslessness, and the arithmetic of averages.

                theorem GaudisCrypt.Procedure.ewp_add {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (F G : sig.ret → VariableAssignment → ENNReal) (σ : VariableAssignment) :
                p.ewp args (fun (v : sig.ret) (g : VariableAssignment) => F v g + G v g) σ = p.ewp args F σ + p.ewp args G σ
                theorem GaudisCrypt.Procedure.ewp_const_mul {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (c : ENNReal) (F : sig.ret → VariableAssignment → ENNReal) (σ : VariableAssignment) :
                p.ewp args (fun (v : sig.ret) (g : VariableAssignment) => c * F v g) σ = c * p.ewp args F σ
                theorem GaudisCrypt.Procedure.ewp_finset_sum {sig : ProcedureSignature} {β : Type u_1} [Fintype β] (p : Procedure sig) (args : sig.ParamType) (F : β → sig.ret → VariableAssignment → ENNReal) (σ : VariableAssignment) :
                p.ewp args (fun (v : sig.ret) (g : VariableAssignment) => ∑ b : β, F b v g) σ = ∑ b : β, p.ewp args (F b) σ
                theorem GaudisCrypt.Procedure.ewp_mono {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) {F G : sig.ret → VariableAssignment → ENNReal} (h : ∀ (v : sig.ret) (g : VariableAssignment), F v g ≤ G v g) (σ : VariableAssignment) :
                p.ewp args F σ ≤ p.ewp args G σ
                theorem GaudisCrypt.Procedure.IsLossless.ewp_const {sig : ProcedureSignature} {p : Procedure sig} (h : p.IsLossless) (args : sig.ParamType) (c : ENNReal) (σ : VariableAssignment) :
                p.ewp args (fun (x : sig.ret) (x_1 : VariableAssignment) => c) σ = c

                A lossless procedure's expectation of a constant is the constant.

                theorem GaudisCrypt.Procedure.ewp_const_le {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (c : ENNReal) (σ : VariableAssignment) :
                p.ewp args (fun (x : sig.ret) (x_1 : VariableAssignment) => c) σ ≤ c

                The expectation of a constant is at most the constant (any procedure).

                An event and its negation partition.

                The union bound for two events.

                theorem GaudisCrypt.ENNReal.sum_indicatorE_eq_div_card {α : Type u_1} [Fintype α] (v : α) :
                ∑ x : α, indicatorE (v = x) / ↑(Fintype.card α) = 1 / ↑(Fintype.card α)

                A uniform draw hits a given point with chance 1 / |α|.

                theorem GaudisCrypt.SubProbability.expected_eq_sum {α : Type u_1} [Fintype α] (μ : SubProbability α) (f : α → ENNReal) :
                μ.expected f = ∑ a : α, ↑μ {a} * f a

                On a finite type, an expectation is the weighted sum over the points.

                theorem GaudisCrypt.ENNReal.sum_div_card {α : Type u_1} [Fintype α] [Nonempty α] (c : ENNReal) :
                ∑ _x : α, c / ↑(Fintype.card α) = c

                The average of a constant over a nonempty finite type is the constant.

                Calls with a specification #

                EC's call (_ : P ==> Q) for phoare: a trailing call x <- p(a) is closed by a judgment about p, and the expectation before it becomes the judgment's bound — under the side condition that the precondition holds at the arguments and the expectation after the call (the continuation fun v gl => g (x.set v (globalL.set gl σ))) is related to the judgment's postcondition as the relation needs. Where the condition fails, the bound is the trivial one (⊤ for ≤, 0 for ≥), or for = the call's own symbolic expectation, so that the = rule is exact.

                theorem GaudisCrypt.phoareStmt_call_le {sig : ProcedureSignature} {A : ProgramState → Prop} {pre : Stmt} {x : Setter sig.ret ProgramState} {p : Procedure sig} {a : Getter sig.ParamType ProgramState} {g r : ProgramState → ENNReal} {P : sig.ParamType → VariableAssignment → Prop} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc P p G LE.le R) (h' : phoareStmt A pre (fun (σ : ProgramState) => if P (a.get σ) σ.globals ∧ ∀ (v : sig.ret) (gl : VariableAssignment), g (x.set v (ProgramState.globalL.set gl σ)) ≤ G v gl then R (a.get σ) σ.globals else ⊤) LE.le r) :

                The call rule for upper bounds.

                theorem GaudisCrypt.phoareStmt_call_ge {sig : ProcedureSignature} {A : ProgramState → Prop} {pre : Stmt} {x : Setter sig.ret ProgramState} {p : Procedure sig} {a : Getter sig.ParamType ProgramState} {g r : ProgramState → ENNReal} {P : sig.ParamType → VariableAssignment → Prop} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc P p G GE.ge R) (h' : phoareStmt A pre (fun (σ : ProgramState) => if P (a.get σ) σ.globals ∧ ∀ (v : sig.ret) (gl : VariableAssignment), G v gl ≤ g (x.set v (ProgramState.globalL.set gl σ)) then R (a.get σ) σ.globals else 0) GE.ge r) :

                The call rule for lower bounds.

                theorem GaudisCrypt.phoareStmt_call_eq {sig : ProcedureSignature} {A : ProgramState → Prop} {pre : Stmt} {x : Setter sig.ret ProgramState} {p : Procedure sig} {a : Getter sig.ParamType ProgramState} {g r : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {P : sig.ParamType → VariableAssignment → Prop} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc P p G Eq R) (h' : phoareStmt A pre (fun (σ : ProgramState) => if P (a.get σ) σ.globals ∧ ∀ (v : sig.ret) (gl : VariableAssignment), g (x.set v (ProgramState.globalL.set gl σ)) = G v gl then R (a.get σ) σ.globals else (Stmt.call x p a).ewp g σ) ρ r) :
                phoareStmt A (StmtWithHoles.seq pre (Stmt.call x p a)) g ρ r

                The call rule for exact values: where the condition holds the call's expectation is the bound, elsewhere it stays as it was.

                An exact procedure judgment gives both bounds.

                theorem GaudisCrypt.phoareProc.ewp_eq {sig : ProcedureSignature} {P : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc P p G Eq R) {args : sig.ParamType} {σ : VariableAssignment} (hP : P args σ) :
                p.ewp args G σ = R args σ

                A procedure judgment as a rewrite rule for the callee's expectation.

                theorem GaudisCrypt.phoareProc.ewp_le {sig : ProcedureSignature} {P : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc P p G LE.le R) {args : sig.ParamType} {σ : VariableAssignment} (hP : P args σ) :
                p.ewp args G σ ≤ R args σ
                theorem GaudisCrypt.phoareProc.ewp_ge {sig : ProcedureSignature} {P : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h : phoareProc P p G GE.ge R) {args : sig.ParamType} {σ : VariableAssignment} (hP : P args σ) :
                R args σ ≤ p.ewp args G σ
                theorem GaudisCrypt.Procedure.ewp_mul_const {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (c : ENNReal) (F : sig.ret → VariableAssignment → ENNReal) (σ : VariableAssignment) :
                p.ewp args (fun (v : sig.ret) (g : VariableAssignment) => F v g * c) σ = p.ewp args F σ * c

                A conjunction of events is the product of their indicators.

                Loops #

                The rule for upper bounds: an expectation invariant I bounds a loop's expectation of g if one iteration (from a state where the test passes) does not increase it, and g is below it where the test fails — I is a pre-fixed point of the loop's wp functional (wp_while_invariant). A qualitative invariant inv is folded in as if inv then ‹potential› else ⊤.

                theorem GaudisCrypt.Stmt.ewp_while_le {c : Getter Bool ProgramState} {body : Stmt} (I g : ProgramState → ENNReal) (hbody : ∀ (σ : ProgramState), c.get σ = true → body.ewp I σ ≤ I σ) (hexit : ∀ (σ : ProgramState), c.get σ = false → g σ ≤ I σ) (σ : ProgramState) :
                ewp (StmtWithHoles.while c body) g σ ≤ I σ

                The loop's expectation of g is below the invariant I.

                theorem GaudisCrypt.phoareStmt_while_le {A : ProgramState → Prop} {pre body : Stmt} {c : Getter Bool ProgramState} {g r : ProgramState → ENNReal} (I : ProgramState → ENNReal) (hbody : phoareStmt (fun (σ : ProgramState) => c.get σ = true) body I LE.le I) (hexit : ∀ (σ : ProgramState), c.get σ = false → g σ ≤ I σ) (hpre : phoareStmt A pre I LE.le r) :

                The loop rule for upper bounds, for a trailing loop: the body preserves the invariant I (as an upper bound, from the states where the test passes), the expectation is below I where the test fails, and the code before the loop is judged with I as its expectation.

                Loops: termination and lower bounds #

                An upper-bound invariant cannot see that a loop terminates — a loop that never does has expectation 0, below everything. Lower bounds need termination: Stmt.ewp_while_one is the zero-one argument (if every iteration exits with probability at least ε > 0, the loop terminates almost surely), and Stmt.ewp_while_ge the lower-bound rule built on it, by complement: with mass 1, Pr[g] = 1 − Pr[¬g], and 1 − I is an upper invariant for 1 − g.

                theorem GaudisCrypt.Stmt.ewp_add (s : Stmt) (F G : ProgramState → ENNReal) (σ : ProgramState) :
                s.ewp (fun (τ : ProgramState) => F τ + G τ) σ = s.ewp F σ + s.ewp G σ
                theorem GaudisCrypt.Stmt.ewp_const_mul (s : Stmt) (c : ENNReal) (F : ProgramState → ENNReal) (σ : ProgramState) :
                s.ewp (fun (τ : ProgramState) => c * F τ) σ = c * s.ewp F σ
                theorem GaudisCrypt.Stmt.ewp_mono (s : Stmt) {F G : ProgramState → ENNReal} (h : ∀ (τ : ProgramState), F τ ≤ G τ) (σ : ProgramState) :
                s.ewp F σ ≤ s.ewp G σ
                theorem GaudisCrypt.Stmt.ewp_const_le (s : Stmt) (c : ENNReal) (σ : ProgramState) :
                s.ewp (fun (x : ProgramState) => c) σ ≤ c
                theorem GaudisCrypt.Stmt.ewp_while_unfold (c : Getter Bool ProgramState) (body : Stmt) (g : ProgramState → ENNReal) (σ : ProgramState) :
                ewp (StmtWithHoles.while c body) g σ = if c.get σ = true then body.ewp (ewp (StmtWithHoles.while c body) g) σ else g σ

                The fixed-point equation of a loop.

                theorem GaudisCrypt.Stmt.ewp_while_one {c : Getter Bool ProgramState} {body : Stmt} (ε : ENNReal) (hε0 : ε ≠ 0) (hε1 : ε ≤ 1) (hll : ∀ (σ : ProgramState), c.get σ = true → body.ewp (fun (x : ProgramState) => 1) σ = 1) (hprog : ∀ (σ : ProgramState), c.get σ = true → ε ≤ body.ewp (fun (τ : ProgramState) => indicatorE (c.get τ = false)) σ) (σ : ProgramState) :
                ewp (StmtWithHoles.while c body) (fun (x : ProgramState) => 1) σ = 1

                Almost-sure termination (the zero-one argument): if the body is lossless and exits the loop with probability at least ε > 0 from every state where the test passes, the loop terminates with probability 1.

                theorem GaudisCrypt.Stmt.ewp_one_sub (s : Stmt) {g : ProgramState → ENNReal} (hg : ∀ (τ : ProgramState), g τ ≤ 1) {σ : ProgramState} (h1 : s.ewp (fun (x : ProgramState) => 1) σ = 1) :
                s.ewp (fun (τ : ProgramState) => 1 - g τ) σ = 1 - s.ewp g σ

                With mass 1, the expectation of 1 − g is 1 minus that of g (for g ≤ 1).

                theorem GaudisCrypt.Stmt.ewp_while_ge {c : Getter Bool ProgramState} {body : Stmt} (I g : ProgramState → ENNReal) (hI1 : ∀ (τ : ProgramState), I τ ≤ 1) (hg1 : ∀ (τ : ProgramState), g τ ≤ 1) (hll : ∀ (σ : ProgramState), c.get σ = true → body.ewp (fun (x : ProgramState) => 1) σ = 1) (hterm : ∀ (σ : ProgramState), ewp (StmtWithHoles.while c body) (fun (x : ProgramState) => 1) σ = 1) (hbody : ∀ (σ : ProgramState), c.get σ = true → I σ ≤ body.ewp I σ) (hexit : ∀ (σ : ProgramState), c.get σ = false → I σ ≤ g σ) (σ : ProgramState) :
                I σ ≤ ewp (StmtWithHoles.while c body) g σ

                The lower-bound rule for a loop: an invariant I ≤ 1 that one iteration does not decrease (where the test passes) and that is below g where the test fails is a lower bound for the loop's expectation of g ≤ 1, provided the loop terminates almost surely (Stmt.ewp_while_one).

                @[simp]

                An indicator is at most 1.

                theorem GaudisCrypt.phoareStmt_while_ge {A : ProgramState → Prop} {pre body : Stmt} {c : Getter Bool ProgramState} {g r : ProgramState → ENNReal} (I : ProgramState → ENNReal) (ε : ENNReal) (hbody : phoareStmt (fun (σ : ProgramState) => c.get σ = true) body I GE.ge I) (hexit : ∀ (σ : ProgramState), c.get σ = false → I σ ≤ g σ) (hpre : phoareStmt A pre I GE.ge r) (hll : phoareStmt (fun (σ : ProgramState) => c.get σ = true) body (fun (x : ProgramState) => 1) Eq fun (x : ProgramState) => 1) (hprog : phoareStmt (fun (σ : ProgramState) => c.get σ = true) body (fun (τ : ProgramState) => indicatorE (c.get τ = false)) GE.ge fun (x : ProgramState) => ε) (hI1 : ∀ (τ : ProgramState), I τ ≤ 1) (hg1 : ∀ (τ : ProgramState), g τ ≤ 1) (hε0 : ε ≠ 0) (hε1 : ε ≤ 1) :

                The loop rule for lower bounds, for a trailing loop: an invariant I ≤ 1 that the body does not decrease (from the states where the test passes) and that is below g ≤ 1 where the test fails, and almost-sure termination — the body is lossless and exits the loop with probability at least ε > 0 (Stmt.ewp_while_one). The code before the loop is judged with I as its expectation.

                Lower bounds with a variant #

                A counted loop (while (j < N)) exits with probability 0 in every round but the last, so the exit-probability argument above does not apply. A variant does: a natural number that every round strictly decreases, on every outcome of the body. Then the loop is lower-bounded by a sub-invariant by well-founded induction on the variant — the body need not even be lossless (the sub-invariant then accounts for the mass it loses). EC's while I V for phoare.

                theorem GaudisCrypt.SubProbability.expected_mono_of_null {α : Type u_1} {μ : SubProbability α} {E : Set α} (hE : μ.ofEvent E = 0) {F G : α → ENNReal} (h : ∀ a ∉ E, F a ≤ G a) :

                An expectation is monotone in the function off a null event.

                theorem GaudisCrypt.Stmt.ewp_mono_of_hoare {s : Stmt} {B : ProgramState → Prop} {σ : ProgramState} (h : hoareStmt (fun (τ : ProgramState) => τ = σ) s B) {F G : ProgramState → ENNReal} (hFG : ∀ (τ : ProgramState), B τ → F τ ≤ G τ) :
                s.ewp F σ ≤ s.ewp G σ

                A statement's expectation is monotone in the function on the outcomes a Hoare triple allows.

                theorem GaudisCrypt.Stmt.ewp_while_ge_variant {c : Getter Bool ProgramState} {body : Stmt} (I g : ProgramState → ENNReal) (V : ProgramState → ℕ) (hvar : ∀ (k : ℕ), hoareStmt (fun (σ : ProgramState) => c.get σ = true ∧ V σ = k) body fun (τ : ProgramState) => V τ < k) (hbody : ∀ (σ : ProgramState), c.get σ = true → I σ ≤ body.ewp I σ) (hexit : ∀ (σ : ProgramState), c.get σ = false → I σ ≤ g σ) (σ : ProgramState) :
                I σ ≤ ewp (StmtWithHoles.while c body) g σ

                Lower bounds with a variant: if every round strictly decreases the variant V (on every outcome of the body), an I that the body does not decrease (from the states where the test passes) and that is below g where it fails bounds the loop from below.

                theorem GaudisCrypt.phoareStmt_while_ge_variant {A : ProgramState → Prop} {pre body : Stmt} {c : Getter Bool ProgramState} {g r : ProgramState → ENNReal} (I : ProgramState → ENNReal) (V : ProgramState → ℕ) (hbody : phoareStmt (fun (σ : ProgramState) => c.get σ = true) body I GE.ge I) (hexit : ∀ (σ : ProgramState), c.get σ = false → I σ ≤ g σ) (hpre : phoareStmt A pre I GE.ge r) (hvar : ∀ (k : ℕ), hoareStmt (fun (σ : ProgramState) => c.get σ = true ∧ V σ = k) body fun (τ : ProgramState) => V τ < k) :

                The loop rule for lower bounds, with a variant (Stmt.ewp_while_ge_variant), for a trailing loop. The code before the loop is judged with I as its expectation.

                theorem GaudisCrypt.phoareProc_eq_of_le_ge {sig : ProcedureSignature} {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {G : sig.ret → VariableAssignment → ENNReal} {R : sig.ParamType → VariableAssignment → ENNReal} (h₁ : phoareProc A p G LE.le R) (h₂ : phoareProc A p G GE.ge R) :
                phoareProc A p G Eq R

                Two procedure bounds give an exact judgment.

                Procedure judgments as statement judgments #

                theorem GaudisCrypt.phoareProc_as_phoareStmt {sig : ProcedureSignature} (resL : Lens sig.ret VariableAssignment) (argsL : Lens sig.ParamType VariableAssignment) (A : sig.ParamType → VariableAssignment → Prop) (p : Procedure sig) (G : sig.ret → VariableAssignment → ENNReal) (ρ : ENNReal → ENNReal → Prop) (r : sig.ParamType → VariableAssignment → ENNReal) :
                phoareProc A p G ρ r ↔ phoareStmt (fun (σ : ProgramState) => A (argsL.get σ.locals) σ.globals) (Stmt.call resL.intoLocal.toSetter p argsL.intoLocal.toGetter) (fun (σ : ProgramState) => G (resL.get σ.locals) σ.globals) ρ fun (σ : ProgramState) => r (argsL.get σ.locals) σ.globals

                A procedure judgment is the statement judgment about the one-line body res <- p(args);, as for Hoare triples (hoareProc_as_hoareStmt).