Documentation

GaudisCrypt.Logic.ECIf

EasyCrypt's if on the first statement #

stmt_if          -- EC's `if`: the first statements, conditionals (on both sides of `equiv`)
stmt_if{i}       -- EC's `if{i}`: side `i`'s first statement, a conditional
stmt_rcondt{i} n -- EC's `rcondt{i} n`: statement `n` a conditional whose test holds there
stmt_rcondf{i} n -- EC's `rcondf{i} n`: … whose test fails there

EC's if works on the first statement of the code, the rest following each branch. Here the conditional takes the rest into its branches (StmtWithHoles.Equiv.ifThenElse_seq, an equivalence, for any judgment), then the judgment's rule for a conditional applies: hoareStmt_if, phoareStmt_if (any relation to the bound), prhlStmt_if (the guard goal: the tests agree), or prhlStmt_if_left/_right. Goals in EC's order: guard for the two-sided rule (the tests agree), then then, else (the precondition with the test true, false).

theorem GaudisCrypt.StmtWithHoles.Equiv.ifThenElse_seq {hCtx : HoleSigs} (c : Getter Bool ProgramState) (t e r : StmtWithHoles hCtx) :
GaudiProg[ if (§c) { stmt t; } else { stmt e; } stmt r; ].Equiv (GaudiProg[ if (§c) { stmt t; stmt r; } else { stmt e; stmt r; } ])

A conditional followed by r: r in both branches.

theorem GaudisCrypt.hoareStmt_if {A B : ProgramState → Prop} {c : Getter Bool ProgramState} {t e : Stmt} (ht : hoare[ A CurrentState.state ∧ c.get CurrentState.state = true ==> B CurrentState.state ] { stmt t; }) (he : hoare[ A CurrentState.state ∧ c.get CurrentState.state = false ==> B CurrentState.state ] { stmt e; }) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { if (§c) { stmt t; } else { stmt e; } }

EC's if on a Hoare triple whose statement is a conditional.

theorem GaudisCrypt.phoareStmt_if {A : ProgramState → Prop} {c : Getter Bool ProgramState} {t e : Stmt} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (ht : phoareStmt (fun (σ : ProgramState) => A σ ∧ c.get σ = true) t g ρ r) (he : phoareStmt (fun (σ : ProgramState) => A σ ∧ c.get σ = false) e g ρ r) :
phoareStmt A (GaudiProg[ if (§c) { stmt t; } else { stmt e; } ]) g ρ r

EC's if on a phoare judgment whose statement is a conditional (any relation ρ to the bound).

rcondt, rcondf: a conditional whose test is known #

EC's rcondt n (rcondf n): the statement at position n is a conditional whose test holds (fails) wherever the code before it ends, from the precondition (a Hoare triple on that code); the conditional is replaced by its branch. On a loop (EC's rcondt/rcondf on a while), the loop unrolled first (Stmt.Equiv.unroll): rcondt leaves its body before the loop, rcondf nothing.

theorem GaudisCrypt.programDenotation_ifThenElse_of {c : Getter Bool ProgramState} {t e : Stmt} {τ : ProgramState} {b : Bool} (hc : c.get τ = b) :
programDenotation (GaudiProg[ if (§c) { stmt t; } else { stmt e; } ]) τ = programDenotation (if b = true then t else e) τ

A conditional run where its test is b: the branch b selects.

theorem GaudisCrypt.programDenotation_rcond {p t e r : Stmt} {c : Getter Bool ProgramState} {P : ProgramState → Prop} (b : Bool) (hp : hoare[ P CurrentState.state ==> c.get CurrentState.state = b ] { stmt p; }) {σ : ProgramState} (hσ : P σ) :
programDenotation (GaudiProg[ stmt p; if (§c) { stmt t; } else { stmt e; } stmt r; ]) σ = programDenotation (StmtWithHoles.seq p (StmtWithHoles.seq (if b = true then t else e) r)) σ

The core of rcondt/rcondf: from states where p's runs end with the test b, p; (if c then t else e); r runs as p; (branch b); r.

theorem GaudisCrypt.hoareStmt_rcond {A B : ProgramState → Prop} {p t e r : Stmt} {c : Getter Bool ProgramState} (b : Bool) (hp : hoare[ A CurrentState.state ==> c.get CurrentState.state = b ] { stmt p; }) (h : hoareStmt A (StmtWithHoles.seq p (StmtWithHoles.seq (if b = true then t else e) r)) B) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt p; if (§c) { stmt t; } else { stmt e; } stmt r; }

EC's rcondt/rcondf on a Hoare triple.

theorem GaudisCrypt.phoareStmt_rcond {A : ProgramState → Prop} {p t e r : Stmt} {c : Getter Bool ProgramState} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {rb : ProgramState → ENNReal} (b : Bool) (hp : hoare[ A CurrentState.state ==> c.get CurrentState.state = b ] { stmt p; }) (h : phoareStmt A (StmtWithHoles.seq p (StmtWithHoles.seq (if b = true then t else e) r)) g ρ rb) :
phoareStmt A (GaudiProg[ stmt p; if (§c) { stmt t; } else { stmt e; } stmt r; ]) g ρ rb

EC's rcondt/rcondf on a phoare judgment.

The first statement of s, a conditional followed by more code, with that code in its branches; s itself if it is a conditional, or not one (a proof of s.Equiv s').

EC's if: see the module docstring.

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

    The statement s as p; (if …); r around its statement at our position k (from 0): p the code before (skip if none), r the code after (skip if none); and a proof of s.Equiv it.

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

      EC's rcondt{i} n (b = true) and rcondf{i} n (b = false).

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

        EC's rcondt{i} n: see the module docstring.

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

          EC's rcondf{i} n: see the module docstring.

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