Documentation

GaudisCrypt.Logic.ECWhile

EasyCrypt's while I V on a phoare … = 1 judgment #

phoare_while I V        -- EC's `while I V`: the loop runs out with probability 1

On a goal phoare[ … ==> E ] = 1 { s; while c body } (EC proves a loop lossless, or that it ends in E, with an invariant I and a variant V): the body, from I, the test and V = k, ends in I with V < k with probability 1 (body, for every k); the code before the loop ends in I with probability 1. The side conditions — E holds on leaving the loop from I (exit), the expectation is at most 1 (bound) — are closed when simp can.

EC's while (true) (size p - i): I is True, the variant size p - i (here a natural number, (size p - i).toNat).

theorem GaudisCrypt.SubProbability.expected_le_one {γ : Type u_1} (μ : SubProbability γ) {f : γ → ENNReal} (h : ∀ (a : γ), f a ≤ 1) :
μ.expected f ≤ 1

An expectation of a function at most 1 is at most 1.

e ≤ 1 for an expectation built from indicators, products, conditionals and expected (what the side condition bound of phoare_while is about).

Equations
Instances For
    theorem GaudisCrypt.Stmt.ewp_while_eq_one_of_phoare {c : Getter Bool ProgramState} {body : Stmt} (I : ProgramState → Prop) (V : ProgramState → ℕ) {g : ProgramState → ENNReal} (hbody : ∀ (k : ℕ) (σ : ProgramState), I σ → c.get σ = true → V σ = k → body.ewp (fun (τ : ProgramState) => indicatorE (I τ ∧ V τ < k)) σ = 1) (hexit : ∀ (σ : ProgramState), I σ → c.get σ = false → g σ = 1) (hg : ∀ (σ : ProgramState), g σ ≤ 1) (σ : ProgramState) (hI : I σ) :
    ewp (GaudiProg[ while (§c) { stmt body; } ]) g σ = 1

    A loop with a variant runs out: from I, if every round from I and the test ends in I with a smaller variant with probability 1, the loop's expectation of g (at most 1, and 1 on leaving the loop from I) is 1.

    theorem GaudisCrypt.phoareStmt_while_eq_one {A : ProgramState → Prop} {pre body : Stmt} {c : Getter Bool ProgramState} {g : ProgramState → ENNReal} (I : ProgramState → Prop) (V : ProgramState → ℕ) (hbody : ∀ (k : ℕ), phoareStmt (fun (σ : ProgramState) => I σ ∧ c.get σ = true ∧ V σ = k) body (fun (τ : ProgramState) => indicatorE (I τ ∧ V τ < k)) Eq fun (x : ProgramState) => 1) (hexit : ∀ (σ : ProgramState), I σ → c.get σ = false → g σ = 1) (hg : ∀ (σ : ProgramState), g σ ≤ 1) (hpre : phoareStmt A pre (fun (σ : ProgramState) => indicatorE (I σ)) Eq fun (x : ProgramState) => 1) :
    phoareStmt A (GaudiProg[ stmt pre; while (§c) { stmt body; } ]) g Eq fun (x : ProgramState) => 1

    EC's while I V on a trailing loop, for phoare[ … ] = 1: the body (for every k, from I, the test and V = k, to I and V < k), the code before the loop (to I), both with probability 1.

    EC's while I V on phoareStmt A {…; while c body} g = 1 (phoareStmt_while_eq_one): goals body, then the code before the loop; exit and bound when simp does not close them.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      EC's while I V on phoare[ … ] = 1 (see the module docstring): I a condition, V a natural number, written like the judgment's conditions.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For