The set monad under the state and reader transformers #
Membership in the computations of StateT σ Set and ReaderT σ Set, with Set.monad as the
monad: a computation run at an input is a set of results, and pure, <$>, >>= and <*>
act on it as singleton, image, indexed union and pointwise application. The statements are
about the local instance Set.monad, so they apply wherever a file enables it.
Main results #
Set.mem_stateT_bind,Set.mem_stateT_map,Set.mem_stateT_pure,Set.mem_stateT_seq: results ofStateT σ Setcomputations.Set.mk_mem_stateT_map,Set.mk_mem_stateT_map_seq: the same for a value–state pair, withf <$> m <*> nrunningmand thennfrom its output state.Set.mem_readerT_bind,Set.mem_readerT_map,Set.mem_readerT_pure: results ofReaderT σ Setcomputations.StateT.relEquiv: aStateT σ Set αcomputation is the family of relations onσit induces at each value, andStateT.rel_bind,StateT.rel_map_seqcompose these relations.StateT.rel_bind_subset,StateT.rel_map_seq_subset: a reflexive and transitive relation containing every step of the parts contains every step of the whole.
StateT σ Set #
@[simp]
theorem
Set.mem_stateT_bind
{σ α β : Type u}
(m : StateT σ Set α)
(f : α → StateT σ Set β)
(s : σ)
(r : β × σ)
:
r ∈ (m >>= f) s ↔ ∃ q ∈ m s, r ∈ f q.1 q.2
@[simp]
theorem
Set.mem_stateT_map
{σ α β : Type u}
(f : α → β)
(m : StateT σ Set α)
(s : σ)
(r : β × σ)
:
r ∈ (f <$> m) s ↔ ∃ q ∈ m s, r = (f q.1, q.2)
@[simp]
@[simp]
theorem
Set.mem_stateT_seq
{σ α β : Type u}
(m : StateT σ Set (α → β))
(n : StateT σ Set α)
(s : σ)
(r : β × σ)
:
r ∈ (m <*> n) s ↔ ∃ q ∈ m s, ∃ q' ∈ n q.2, r = (q.1 q'.1, q'.2)
theorem
Set.mk_mem_stateT_map
{σ α β : Type u}
{f : α → β}
{m : StateT σ Set α}
{s s' : σ}
{b : β}
:
(b, s') ∈ (f <$> m) s ↔ ∃ (a : α), (a, s') ∈ m s ∧ b = f a
theorem
Set.mk_mem_stateT_map_seq
{σ α β γ : Type u}
{f : α → β → γ}
{m : StateT σ Set α}
{n : StateT σ Set β}
{s s'' : σ}
{c : γ}
:
(c, s'') ∈ (f <$> m <*> n) s ↔ ∃ (a : α) (s' : σ), (a, s') ∈ m s ∧ ∃ (b : β), (b, s'') ∈ n s' ∧ c = f a b
ReaderT σ Set #
@[simp]
theorem
Set.mem_readerT_bind
{σ α β : Type u}
(m : ReaderT σ Set α)
(f : α → ReaderT σ Set β)
(s : σ)
(r : β)
:
r ∈ (m >>= f) s ↔ ∃ x ∈ m s, r ∈ f x s
@[simp]
theorem
Set.mem_readerT_map
{σ α β : Type u}
(f : α → β)
(m : ReaderT σ Set α)
(s : σ)
(r : β)
:
r ∈ (f <$> m) s ↔ ∃ x ∈ m s, r = f x
@[simp]
Graded relations #
The relation m induces at the value a, from each state to the states m reaches from it
with the value a.
Equations
- m.rel a = {p : σ × σ | (a, p.2) ∈ m p.1}
Instances For
@[simp]
theorem
StateT.mem_rel
{σ α : Type u}
{m : StateT σ Set α}
{a : α}
{s s' : σ}
:
(s, s') ∈ m.rel a ↔ (a, s') ∈ m s
A StateT σ Set α computation is the family of relations it induces at its values.
Equations
- StateT.relEquiv = { toFun := StateT.rel, invFun := fun (R : α → SetRel σ σ) (s : σ) => {q : α × σ | (s, q.2) ∈ R q.1}, left_inv := ⋯, right_inv := ⋯ }
Instances For
theorem
StateT.rel_pure_subset
{σ α : Type u}
{R : SetRel σ σ}
[R.IsRefl]
(a b : α)
:
(pure a).rel b ⊆ R
theorem
StateT.rel_map_subset
{σ α β : Type u}
{R : SetRel σ σ}
{m : StateT σ Set α}
(hm : ∀ (a : α), m.rel a ⊆ R)
(f : α → β)
(b : β)
:
(f <$> m).rel b ⊆ R