Documentation

Std.Internal.Do.WP.Lemmas

Simp lemmas for weakest preconditions #

This module provides simp lemmas for simplifying weakest precondition expressions. Unlike Std.Do, we use direct function application wp x post epost without notation.

Some lemmas prove only one direction (⊑) instead of equality because our wp_bind axiom only provides one direction.

MonadReaderOf simp lemmas #

theorem Std.Internal.Do.WPMonad.read_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ : Type u} (post : ρ → ρ → Pred) (epost : EPred) :
Lean.Order.PartialOrder.rel (fun (r : ρ) => post r r) (wp MonadReaderOf.read post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.adapt_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ ρ' α : Type u} {post : α → ρ → Pred} {epost : EPred} (f : ρ → ρ') (x : ReaderT ρ' m α) :
wp (ReaderT.adapt f x) post epost = fun (r : ρ) => wp x (fun (a : α) (x : ρ') => post a r) epost (f r)

MonadStateOf simp lemmas #

theorem Std.Internal.Do.WPMonad.get_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} (post : σ → σ → Pred) (epost : EPred) :
Lean.Order.PartialOrder.rel (fun (s : σ) => post s s) (wp MonadStateOf.get post epost)
theorem Std.Internal.Do.WPMonad.set_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} (x : σ) (post : PUnit → σ → Pred) (epost : EPred) :
Lean.Order.PartialOrder.rel (fun (x_1 : σ) => post PUnit.unit x) (wp (set x) post epost)
theorem Std.Internal.Do.WPMonad.modifyGet_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ α : Type u} (f : σ → α × σ) (post : α → σ → Pred) (epost : EPred) :
Lean.Order.PartialOrder.rel (fun (s : σ) => post (f s).fst (f s).snd) (wp (MonadStateOf.modifyGet f) post epost)
theorem Std.Internal.Do.WPMonad.get_EStateM_wp {ε σ : Type u_1} {post : σ → σ → Prop} {epost : ε → σ → Prop} :
wp MonadStateOf.get post epost = fun (s : σ) => post s s
theorem Std.Internal.Do.WPMonad.set_EStateM_wp {σ ε : Type u_1} {post : PUnit → σ → Prop} {epost : ε → σ → Prop} (x : σ) :
wp (set x) post epost = fun (x_1 : σ) => post PUnit.unit x
theorem Std.Internal.Do.WPMonad.modifyGet_EStateM_wp {σ α ε : Type u_1} {post : α → σ → Prop} {epost : ε → σ → Prop} (f : σ → α × σ) :
wp (MonadStateOf.modifyGet f) post epost = fun (s : σ) => post (f s).fst (f s).snd
@[simp]
theorem Std.Internal.Do.WPMonad.modify_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} {post : PUnit → σ → Pred} {epost : EPred} (f : σ → σ) :
wp (modify f) post epost = wp (MonadStateOf.modifyGet fun (s : σ) => (PUnit.unit, f s)) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.getModify_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} {post : σ → σ → Pred} {epost : EPred} (f : σ → σ) :
wp (getModify f) post epost = wp (MonadStateOf.modifyGet fun (s : σ) => (s, f s)) post epost
theorem Std.Internal.Do.WPMonad.modify_EStateM_wp {σ ε : Type u_1} {post : PUnit → σ → Prop} {epost : ε → σ → Prop} (f : σ → σ) :
wp (modify f) post epost = wp (MonadStateOf.modifyGet fun (s : σ) => (PUnit.unit, f s)) post epost
theorem Std.Internal.Do.WPMonad.getModify_EStateM_wp {σ ε : Type u_1} {post : σ → σ → Prop} {epost : ε → σ → Prop} (f : σ → σ) :
wp (getModify f) post epost = wp (MonadStateOf.modifyGet fun (s : σ) => (s, f s)) post epost

MonadExceptOf simp lemmas #

@[simp]
theorem Std.Internal.Do.WPMonad.throwThe_wp {Pred : Type u_2} {EPred : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε : Type u_1} {α : Type u} {post : α → Pred} {epost : EPred} [MonadExceptOf ε m] (err : ε) :
wp (throwThe ε err) post epost = wp (MonadExceptOf.throw err) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.throw_Except_wp {ε : Type u_1} {α : Type u_2} {post : α → Prop} {epost : EPost⟨ε → Prop⟩} (e : ε) :
wp (MonadExceptOf.throw e) post epost = epost.head e
theorem Std.Internal.Do.WPMonad.throw_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε → Pred) EPred} (err : ε) :
@[simp]
theorem Std.Internal.Do.WPMonad.throw_EStateM_wp {ε σ α : Type u_1} {post : α → σ → Prop} {epost : ε → σ → Prop} (e : ε) :
wp (MonadExceptOf.throw e) post epost = epost e
@[simp]
theorem Std.Internal.Do.WPMonad.throw_Option_wp {α : Type u_1} {post : α → Prop} {epost : Prop} (e : PUnit) :
wp (MonadExceptOf.throw e) post epost = epost
theorem Std.Internal.Do.WPMonad.throw_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (err : PUnit) :
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_MonadExcept_wp {Pred : Type u_2} {EPred : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε : Type u_1} {α : Type u} {post : α → Pred} {epost : EPred} [MonadExceptOf ε m] (x : m α) (h : ε → m α) :
wp (tryCatch x h) post epost = wp (MonadExceptOf.tryCatch x h) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatchThe_wp {Pred : Type u_2} {EPred : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε : Type u_1} {α : Type u} {post : α → Pred} {epost : EPred} [MonadExceptOf ε m] (x : m α) (h : ε → m α) :
wp (tryCatchThe ε x h) post epost = wp (MonadExceptOf.tryCatch x h) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_Except_wp {ε : Type u_1} {α : Type u_2} {post : α → Prop} {epost : EPost⟨ε → Prop⟩} (x : Except ε α) (h : ε → Except ε α) :
wp (MonadExceptOf.tryCatch x h) post epost = wp x post epost⟨fun (e : ε) => wp (h e) post epost⟩
@[simp]
theorem ExceptT.run_tryCatch {m : Type u → Type v} {ε α : Type u} [Monad m] [LawfulMonad m] (x : ExceptT ε m α) (h : ε → ExceptT ε m α) :
(tryCatch x h).run = do let r ← x.run match r with | Except.ok a => pure (Except.ok a) | Except.error e => (h e).run
theorem Std.Internal.Do.WPMonad.tryCatch_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε → Pred) EPred} (x : ExceptT ε m α) (h : ε → ExceptT ε m α) :
Lean.Order.PartialOrder.rel (wp x post (EPost.cons.mk✝ (fun (e : ε) => wp (h e) post epost) epost.tail)) (wp (MonadExceptOf.tryCatch x h) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_Option_wp {α : Type u_1} {post : α → Prop} {epost : Prop} (x : Option α) (h : PUnit → Option α) :
wp (MonadExceptOf.tryCatch x h) post epost = wp x post (wp (h PUnit.unit) post epost)
theorem Std.Internal.Do.WPMonad.tryCatch_EStateM_wp {ε σ α : Type u_1} {post : α → σ → Prop} {epost : ε → σ → Prop} (x : EStateM ε σ α) (h : ε → EStateM ε σ α) :
wp (MonadExceptOf.tryCatch x h) post epost = fun (s : σ) => wp x post (fun (e : ε) (s' : σ) => wp (h e) post epost s') s
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (x : OptionT m α) (h : PUnit → OptionT m α) :
Lean.Order.PartialOrder.rel (wp x post (EPost.cons.mk✝ (wp (h PUnit.unit) post epost) epost.tail)) (wp (MonadExceptOf.tryCatch x h) post epost)

Additional state operation lemmas #

@[simp]
theorem Std.Internal.Do.WPMonad.getThe_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} {post : σ → σ → Pred} {epost : EPred} :
wp (getThe σ) post epost = wp MonadStateOf.get post epost
@[simp]
theorem Std.Internal.Do.WPMonad.modifyThe_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} {post : PUnit → σ → Pred} {epost : EPred} (f : σ → σ) :
wp (modifyThe σ f) post epost = wp (MonadStateOf.modifyGet fun (s : σ) => (PUnit.unit, f s)) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.modifyGetThe_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ α : Type u} {post : α → σ → Pred} {epost : EPred} (f : σ → α × σ) :
wp (modifyGetThe σ f) post epost = wp (MonadStateOf.modifyGet f) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.get_MonadState_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} {post : σ → Pred} {epost : EPred} [MonadStateOf σ m] :
wp get post epost = wp MonadStateOf.get post epost
@[simp]
theorem Std.Internal.Do.WPMonad.set_MonadState_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} {post : PUnit → Pred} {epost : EPred} [MonadStateOf σ m] (x : σ) :
wp (MonadState.set x) post epost = wp (set x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.modifyGet_MonadState_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ α : Type u} {post : α → Pred} {epost : EPred} [MonadStateOf σ m] (f : σ → α × σ) :
wp (modifyGet f) post epost = wp (MonadStateOf.modifyGet f) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.read_MonadReader_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ : Type u} {post : ρ → Pred} {epost : EPred} [MonadReaderOf ρ m] :
wp read post epost = wp MonadReaderOf.read post epost
@[simp]
theorem Std.Internal.Do.WPMonad.readThe_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ : Type u} {post : ρ → ρ → Pred} {epost : EPred} :
wp (readThe ρ) post epost = wp MonadReaderOf.read post epost

MonadLift simp lemmas #

theorem Std.Internal.Do.WPMonad.monadLift_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α σ : Type u} {epost : EPred} (x : m α) (post : α → σ → Pred) :
Lean.Order.PartialOrder.rel (fun (s : σ) => wp x (fun (a : α) => post a s) epost) (wp (MonadLift.monadLift x) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.monadLift_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α ρ : Type u} {post : α → ρ → Pred} {epost : EPred} (x : m α) :
wp (MonadLift.monadLift x) post epost = fun (r : ρ) => wp x (fun (a : α) => post a r) epost
theorem Std.Internal.Do.WPMonad.monadLift_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α ε : Type u} (x : m α) (post : α → Pred) (epost : EPost.cons✝ (ε → Pred) EPred) :
Lean.Order.PartialOrder.rel (wp x post epost.tail) (wp (MonadLift.monadLift x) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.lift_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α σ : Type u} {post : α → σ → Pred} {epost : EPred} (x : m α) :
wp (StateT.lift x) post epost = wp (MonadLift.monadLift x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.lift_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α ε : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε → Pred) EPred} (x : m α) :
wp (ExceptT.lift x) post epost = wp (MonadLift.monadLift x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.monadLift_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (x : m α) :
Lean.Order.PartialOrder.rel (wp x post epost.tail) (wp (MonadLift.monadLift x) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.lift_OptionT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} [Assertion (EPost.cons✝ Pred EPred)] [WPMonad (OptionT m) Pred (EPost.cons✝ Pred EPred)] (x : m α) :
wp (OptionT.lift x) post epost = wp (MonadLift.monadLift x) post epost

MonadFunctor simp lemmas #

@[simp]
theorem Std.Internal.Do.WPMonad.monadMap_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ : Type u} (f : {β : Type u} → m β → m β) {α : Type u} (x : StateT σ m α) (post : α → σ → Pred) (epost : EPred) :
wp (MonadFunctor.monadMap (fun {β : Type u} => f) x) post epost = fun (s : σ) => wp (f (x.run s)) (fun (x : α × σ) => match x with | (a, s') => post a s') epost
@[simp]
theorem Std.Internal.Do.WPMonad.monadMap_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ : Type u} (f : {β : Type u} → m β → m β) {α : Type u} (x : ReaderT ρ m α) (post : α → ρ → Pred) (epost : EPred) :
wp (MonadFunctor.monadMap (fun {β : Type u} => f) x) post epost = fun (r : ρ) => wp (f (x.run r)) (fun (a : α) => post a r) epost
@[simp]
theorem Std.Internal.Do.WPMonad.monadMap_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε : Type u} (f : {β : Type u} → m β → m β) {α : Type u} (x : ExceptT ε m α) (post : α → Pred) (epost : EPost.cons✝ (ε → Pred) EPred) :
wp (MonadFunctor.monadMap (fun {β : Type u} => f) x) post epost = wp (f x.run) (EPost.cons.pushExcept post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.monadMap_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] (f : {β : Type u} → m β → m β) {α : Type u} (x : OptionT m α) (post : α → Pred) (epost : EPost.cons✝ Pred EPred) :
wp (MonadFunctor.monadMap (fun {β : Type u} => f) x) post epost = wp (f x.run) (EPost.cons.pushOption post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.withReader_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ α : Type u} {post : α → ρ → Pred} {epost : EPred} (f : ρ → ρ) (x : ReaderT ρ m α) :
wp (MonadWithReaderOf.withReader f x) post epost = fun (r : ρ) => wp x (fun (a : α) (x : ρ) => post a r) epost (f r)
@[simp]
theorem Std.Internal.Do.WPMonad.withReader_MonadWithReader_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ α : Type u} {post : α → Pred} {epost : EPred} [MonadWithReaderOf ρ m] (f : ρ → ρ) (x : m α) :
wp (withReader f x) post epost = wp (MonadWithReaderOf.withReader f x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.withTheReader_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ α : Type u} {post : α → ρ → Pred} {epost : EPred} (f : ρ → ρ) (x : ReaderT ρ m α) :
wp (withTheReader ρ f x) post epost = wp (MonadWithReaderOf.withReader f x) post epost

Transformer adapt lemmas #

theorem Std.Internal.Do.WPMonad.adapt_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε ε' α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε' → Pred) EPred} (f : ε → ε') (x : ExceptT ε m α) :
Lean.Order.PartialOrder.rel (wp x post (EPost.cons.mk✝ (fun (e : ε) => epost.head (f e)) epost.tail)) (wp (ExceptT.adapt f x) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.adaptExcept_EStateM_wp {ε ε' σ α : Type u_1} {post : α → σ → Prop} {epost : ε' → σ → Prop} (f : ε → ε') (x : EStateM ε σ α) :
wp (EStateM.adaptExcept f x) post epost = wp x post fun (e : ε) => epost (f e)

MonadControl simp lemmas #

@[simp]
theorem Std.Internal.Do.WPMonad.liftWith_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {σ α : Type u} {post : α → σ → Pred} {epost : EPred} {s : σ} (f : ({β : Type u} → StateT σ m β → m (β × σ)) → m α) :
wp (MonadControl.liftWith f) post epost s = wp ((fun (a : α) => (a, s)) <$> f fun {β : Type u} (x : StateT σ m β) => x.run s) (fun (x : α × σ) => match x with | (a, s) => post a s) epost
@[simp]
theorem Std.Internal.Do.WPMonad.liftWith_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ρ α : Type u} {post : α → ρ → Pred} {epost : EPred} {r : ρ} (f : ({β : Type u} → ReaderT ρ m β → m β) → m α) :
wp (MonadControl.liftWith f) post epost r = wp (f fun {β : Type u} (x : ReaderT ρ m β) => x.run r) (fun (a : α) => post a r) epost
@[simp]
theorem ExceptT.run_liftM {m : Type u → Type v} {α ε : Type u} [Monad m] [LawfulMonad m] (x : m α) :
@[simp]
theorem Std.Internal.Do.WPMonad.liftWith_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε → Pred) EPred} (f : ({β : Type u} → ExceptT ε m β → m (Except ε β)) → m α) :
wp (MonadControl.liftWith f) post epost = wp (Except.ok <$> f fun {β : Type u} (x : ExceptT ε m β) => x.run) (EPost.cons.pushExcept post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.liftWith_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (f : ({β : Type u} → OptionT m β → m (Option β)) → m α) :
Lean.Order.PartialOrder.rel (wp (f fun {β : Type u} (x : OptionT m β) => x.run) post epost.tail) (wp (MonadControl.liftWith f) post epost)
theorem Std.Internal.Do.WPMonad.restoreM_StateT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α σ : Type u} {epost : EPred} {post : α → σ → Pred} (x : m (α × σ)) :
Lean.Order.PartialOrder.rel (fun (x_1 : σ) => wp x (fun (x : α × σ) => match x with | (a, s) => post a s) epost) (wp (MonadControl.restoreM x) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.restoreM_ReaderT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α ρ : Type u} {post : α → ρ → Pred} {epost : EPred} (x : m α) :
wp (MonadControl.restoreM x) post epost = fun (r : ρ) => wp x (fun (a : α) => post a r) epost
@[simp]
theorem Std.Internal.Do.WPMonad.restoreM_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε → Pred) EPred} (x : m (Except ε α)) :
wp (MonadControl.restoreM x) post epost = wp x (EPost.cons.pushExcept post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.restoreM_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (x : m (Option α)) :
wp (MonadControl.restoreM x) post epost = wp x (EPost.cons.pushOption post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.controlAt_wp {n : Type u_1 → Type u_2} {m : Type u_1 → Type u_3} {Pred : Type u_4} {EPred : Type u_5} {α : Type u_1} {post : α → Pred} {epost : EPred} [Bind n] [Monad m] [Monad n] [Assertion Pred] [Assertion EPred] [WPMonad n Pred EPred] [MonadControlT m n] (f : ({β : Type u_1} → n β → m (stM m n β)) → m (stM m n α)) :
wp (controlAt m f) post epost = wp (liftWith f >>= restoreM) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.control_wp {n : Type u_1 → Type u_2} {m : Type u_1 → Type u_3} {Pred : Type u_4} {EPred : Type u_5} {α : Type u_1} {post : α → Pred} {epost : EPred} [Bind n] [Monad m] [Monad n] [Assertion Pred] [Assertion EPred] [WPMonad n Pred EPred] [MonadControlT m n] (f : ({β : Type u_1} → n β → m (stM m n β)) → m (stM m n α)) :
wp (control f) post epost = wp (liftWith f >>= restoreM) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.monadLift_refl_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPred} [Pure m] (x : m α) :
wp (monadLift x) post epost = wp x post epost
@[simp]
theorem Std.Internal.Do.WPMonad.monadMap_refl_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {f : {β : Type u} → m β → m β} {post : α → Pred} {epost : EPred} [Pure m] (x : m α) :
wp (monadMap f x) post epost = wp (f x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.liftWith_refl_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPred} [Pure m] (f : ({β : Type u} → m β → m β) → m α) :
wp (liftWith f) post epost = wp (f fun {β : Type u} (x : m β) => x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.restoreM_refl_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPred} [Pure m] (x : stM m m α) :
wp (restoreM x) post epost = wp (pure x) post epost

Transitive lift/map/control simp lemmas #

@[simp]
theorem Std.Internal.Do.WPMonad.monadLift_trans_wp {Pred : Type u_1} {EPred : Type u_2} {m n o : Type u → Type v} [Monad o] [Assertion Pred] [Assertion EPred] [WPMonad o Pred EPred] {α : Type u} {post : α → Pred} {epost : EPred} [MonadLift n o] [MonadLiftT m n] (x : m α) :
wp (monadLift x) post epost = wp (MonadLift.monadLift (monadLift x)) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.monadMap_trans_wp {Pred : Type u_1} {EPred : Type u_2} {m n o : Type u → Type v} [Monad o] [Assertion Pred] [Assertion EPred] [WPMonad o Pred EPred] {α : Type u} {f : {β : Type u} → m β → m β} {post : α → Pred} {epost : EPred} [MonadFunctor n o] [MonadFunctorT m n] (x : o α) :
wp (monadMap f x) post epost = wp (MonadFunctor.monadMap (fun {β : Type u} => monadMap fun {β : Type u} => f) x) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.liftWith_trans_wp {Pred : Type u_1} {EPred : Type u_2} {m n o : Type u → Type v} [Monad o] [Assertion Pred] [Assertion EPred] [WPMonad o Pred EPred] {α : Type u} {post : α → Pred} {epost : EPred} [MonadControl n o] [MonadControlT m n] (f : ({β : Type u} → o β → m (stM m o β)) → m α) :
wp (liftWith f) post epost = wp (MonadControl.liftWith fun (x₂ : {β : Type u} → o β → n (MonadControl.stM n o β)) => liftWith fun (x₁ : {β : Type u} → n β → m (stM m n β)) => f fun {β : Type u} => x₁ ∘ x₂) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.restoreM_trans_wp {Pred : Type u_1} {EPred : Type u_2} {m n o : Type u → Type v} [Monad o] [Assertion Pred] [Assertion EPred] [WPMonad o Pred EPred] {α : Type u} {post : α → Pred} {epost : EPred} [MonadControl n o] [MonadControlT m n] (x : stM m o α) :
wp (restoreM x) post epost = wp (MonadControl.restoreM (restoreM x)) post epost

Lifted state/reader operations #

@[simp]
theorem Std.Internal.Do.WPMonad.get_MonadStateOf_lift_wp {Pred : Type u_1} {EPred : Type u_2} {m n : Type u → Type v} [Monad n] [MonadLift m n] [Assertion Pred] [Assertion EPred] [WPMonad n Pred EPred] {σ : Type u} {post : σ → Pred} {epost : EPred} [MonadStateOf σ m] :
@[simp]
theorem Std.Internal.Do.WPMonad.set_MonadStateOf_lift_wp {Pred : Type u_1} {EPred : Type u_2} {m n : Type u → Type v} [Monad n] [MonadLift m n] [Assertion Pred] [Assertion EPred] [WPMonad n Pred EPred] {σ : Type u} {post : PUnit → Pred} {epost : EPred} [MonadStateOf σ m] (x : σ) :
wp (set x) post epost = wp (MonadLift.monadLift (set x)) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.modifyGet_MonadStateOf_lift_wp {Pred : Type u_1} {EPred : Type u_2} {m n : Type u → Type v} [Monad n] [MonadLift m n] [Assertion Pred] [Assertion EPred] [WPMonad n Pred EPred] {σ α : Type u} {post : α → Pred} {epost : EPred} [MonadStateOf σ m] (f : σ → α × σ) :
wp (MonadStateOf.modifyGet f) post epost = wp (MonadLift.monadLift (modifyGet f)) post epost
@[simp]
theorem Std.Internal.Do.WPMonad.read_MonadReaderOf_lift_wp {Pred : Type u_1} {EPred : Type u_2} {m n : Type u → Type v} [Monad n] [MonadLift m n] [Assertion Pred] [Assertion EPred] [WPMonad n Pred EPred] {ρ : Type u} {post : ρ → Pred} {epost : EPred} [MonadReaderOf ρ m] :

Lifted except operations #

@[simp]
theorem Std.Internal.Do.WPMonad.throw_lift_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {ε : Type u} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {ε' α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε' → Pred) EPred} (err : ε) :
wp (MonadExceptOf.throw err) post epost = wp (MonadExceptOf.throw err) (EPost.cons.pushExcept post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.throw_lift_OptionT_wp {Pred : Type u} {EPred : Type u_1} {ε : Type u} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (err : ε) :
wp (MonadExceptOf.throw err) post epost = wp (MonadExceptOf.throw err) (EPost.cons.pushOption post epost) epost.tail
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_lift_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {ε : Type u} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {ε' α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε' → Pred) EPred} (x : ExceptT ε' m α) (h : ε → ExceptT ε' m α) :
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_lift_OptionT_wp {Pred : Type u} {EPred : Type u_1} {ε : Type u} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (x : OptionT m α) (h : ε → OptionT m α) :
@[simp]
theorem Std.Internal.Do.WPMonad.throw_ReaderT_lift_wp {Pred : Type u_1} {EPred : Type u_2} {ε : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {ρ α : Type u} {post : α → ρ → Pred} {epost : EPred} (err : ε) :
@[simp]
theorem Std.Internal.Do.WPMonad.throw_StateT_lift_wp {Pred : Type u_1} {EPred : Type u_2} {ε : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {σ α : Type u} {post : α → σ → Pred} {epost : EPred} (err : ε) :
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_ReaderT_lift_wp {Pred : Type u_1} {EPred : Type u_2} {ε : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {ρ α : Type u} {post : α → ρ → Pred} {epost : EPred} (x : ReaderT ρ m α) (h : ε → ReaderT ρ m α) :
wp (MonadExceptOf.tryCatch x h) post epost = fun (r : ρ) => wp (MonadExceptOf.tryCatch (x.run r) fun (e : ε) => (h e).run r) (fun (a : α) => post a r) epost
@[simp]
theorem Std.Internal.Do.WPMonad.tryCatch_StateT_lift_wp {Pred : Type u_1} {EPred : Type u_2} {ε : Type u_3} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] [MonadExceptOf ε m] {σ α : Type u} {post : α → σ → Pred} {epost : EPred} (x : StateT σ m α) (h : ε → StateT σ m α) :
wp (MonadExceptOf.tryCatch x h) post epost = fun (s : σ) => wp (MonadExceptOf.tryCatch (x.run s) fun (e : ε) => (h e).run s) (fun (x : α × σ) => match x with | (a, s') => post a s') epost

OrElse simp lemmas #

@[simp]
theorem Std.Internal.Do.WPMonad.orElse_Except_wp {ε : Type u_1} {α : Type u_2} {post : α → Prop} {epost : EPost⟨ε → Prop⟩} (x : Except ε α) (h : Unit → Except ε α) :
wp (OrElse.orElse x h) post epost = wp x post epost⟨fun (x : ε) => wp (h ()) post epost⟩
@[simp]
theorem ExceptT.run_orElse {m : Type u → Type v} {ε α : Type u} [Monad m] [LawfulMonad m] (x : ExceptT ε m α) (h : Unit → ExceptT ε m α) :
(OrElse.orElse x h).run = do let r ← x.run match r with | Except.ok a => pure (Except.ok a) | Except.error a => (h ()).run
theorem Std.Internal.Do.WPMonad.orElse_ExceptT_wp {Pred : Type u_1} {EPred : Type u_2} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {ε α : Type u} {post : α → Pred} {epost : EPost.cons✝ (ε → Pred) EPred} (x : ExceptT ε m α) (h : Unit → ExceptT ε m α) :
Lean.Order.PartialOrder.rel (wp x post (EPost.cons.mk✝ (fun (x : ε) => wp (h ()) post epost) epost.tail)) (wp (OrElse.orElse x h) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.orElse_OptionT_wp {Pred : Type u} {EPred : Type u_1} {m : Type u → Type v} [Monad m] [Assertion Pred] [Assertion EPred] [WPMonad m Pred EPred] {α : Type u} {post : α → Pred} {epost : EPost.cons✝ Pred EPred} (x : OptionT m α) (h : Unit → OptionT m α) :
Lean.Order.PartialOrder.rel (wp x post (EPost.cons.mk✝ (wp (h ()) post epost) epost.tail)) (wp (OrElse.orElse x h) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.orElse_Option_wp {α : Type u_1} (x : Option α) (h : Unit → Option α) (post : α → Prop) (epost : Prop) :
wp (OrElse.orElse x h) post epost = wp x post (wp (h ()) post epost)
@[simp]
theorem Std.Internal.Do.WPMonad.orElse_EStateM_wp {ε σ α : Type u_1} {post : α → σ → Prop} {epost : ε → σ → Prop} (x : EStateM ε σ α) (h : Unit → EStateM ε σ α) :
wp (OrElse.orElse x h) post epost = fun (s : σ) => wp x post (fun (x : ε) (s' : σ) => wp (h ()) post epost s') s