Programs commuting with a state update, through loops #
ProgramDenotation.CommutesU p u: running p from u st is running it from st and applying
u to the final state. It is preserved by ⊥, pure, bind and the suprema of chains, and so
by while_loop (the Kleene argument of ProgramDenotation.EquivInLens.while_loop). This is what
stmt_swap and stmt_alias need of a loop (Stmt.CommutesWith.while, Logic/StmtSwap.lean):
a loop whose guard u leaves alone and whose body commutes with u commutes with u.
def
GaudisCrypt.ProgramDenotation.CommutesU
{s : Type u}
{α : Type v}
(p : ProgramDenotation s α)
(u : s → s)
:
p commutes with the state update u.
Equations
- p.CommutesU u = ∀ (st : s), p (u st) = GaudisCrypt.SubProbability.mapState u (p st)
Instances For
theorem
GaudisCrypt.ProgramDenotation.CommutesU.bind
{s : Type u}
{u : s → s}
{α β : Type v}
{p : ProgramDenotation s α}
{q : α → ProgramDenotation s β}
(hp : p.CommutesU u)
(hq : ∀ (a : α), (q a).CommutesU u)
:
theorem
GaudisCrypt.ProgramDenotation.CommutesU.ωSup
{s : Type u}
{u : s → s}
{α : Type v}
(ch : OmegaCompletePartialOrder.Chain (ProgramDenotation s α))
(h : ∀ (n : ℕ), (ch n).CommutesU u)
:
theorem
GaudisCrypt.ProgramDenotation.CommutesU.while_loop
{s : Type u}
{u : s → s}
{cond : ProgramDenotation s Bool}
{body : ProgramDenotation s Unit}
(hc : cond.CommutesU u)
(hb : body.CommutesU u)
:
(GaudisCrypt.while_loop cond body).CommutesU u
A loop commutes with u when its guard and its body do.