The areas / V03. Sets, finite structures and big operators
Mathlib.Data.Set.Functor
28 declarations and 2 deprecated aliases. Mathlib docs · Source
Functoriality of Set
This file defines the functor structure of Set.
Monadic coercion lemmas
Coercion applying functoriality for Subtype.val
The Monad instance gives a coercion using the internal function Lean.Internal.coeM.
In practice this is only used for applying the Set functor to Subtype.val,
as was defined in Data.Set.Notation.
Wrapper to enable the Set monad
instance Set.instAlternative E0 #
Alternative Set
theorem Set.fmap_eq_image E0 #
∀ {α β : Type u} {s : Set α} (f : α → β), f <$> s = f '' s
theorem Set.seq_eq_set_seq E0 #
∀ {α β : Type u} (s : Set (α → β)) (t : Set α), s <*> t = s.seq t
theorem Set.seqLeft_def E0 #
∀ {α β : Type u} (s : Set α) (t : Set β), s <* t = {a | a ∈ s ∧ t.Nonempty}
theorem Set.seqRight_def E0 #
∀ {α β : Type u} (s : Set α) (t : Set β), s *> t = {a | s.Nonempty ∧ a ∈ t}
theorem Set.pure_def E0 #
∀ {α : Type u} (a : α), pure a = {a}
theorem Set.failure_def E0 #
∀ {α : Type u}, failure = ∅
theorem Set.orElse_def E0 #
∀ {α : Type u} (s t : Set α), (s <|> t) = s ∪ t
theorem Set.image2_def E0 #
∀ {α β γ : Type u} (f : α → β → γ) (s : Set α) (t : Set β), Set.image2 f s t = f <$> s <*> t
Set.image2 in terms of monadic operations. Note that this can't be taken as the definition
because of the lack of universe polymorphism.
instance Set.instLawfulAlternative E0 #
LawfulAlternative Set
instance Set.instCommApplicative E0 #
CommApplicative Set
def Set.monad E1 #
AlternativeMonad Set
The Set functor is a monad.
This is not a global instance because it does not have computational content,
so it does not make much sense using do notation in general.
Moreover, this would cause monad-related coercions and monad lifting logic to become activated.
Either use attribute [local instance] Set.monad to make it be a local instance
or use SetM.run do ... when do notation is wanted.
theorem Set.bind_def E0 #
∀ {α β : Type u} {s : Set α} {f : α → Set β}, s >>= f = ⋃ i ∈ s, f i
instance Set.instLawfulMonad E0 #
LawfulMonad Set
theorem Set.mem_coe_of_mem E0 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β} {a : α} (ha : a ∈ β),
⟨a, ha⟩ ∈ γ →
a ∈ do
let a ← γ
pure ↑a
theorem Set.coe_subset E0 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β},
(do
let a ← γ
pure ↑a) ⊆
β
theorem Set.mem_of_mem_coe E0 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β} {a : α}
(ha :
a ∈ do
let a ← γ
pure ↑a),
⟨a, ⋯⟩ ∈ γ
theorem Set.image_coe_eq_domRestrict_image E1 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β} {δ : Type u_1} {f : α → δ},
(f '' do
let a ← γ
pure ↑a) =
β.domRestrict f '' γ
theorem Set.coe_eq_image_val E0 #
∀ {α : Type u} {s : Set α} (t : Set ↑s), Lean.Internal.coeM t = Subtype.val '' t
The coercion from Set.monad as an instance is equal to the coercion in Data.Set.Notation.
theorem Set.mem_image_val_of_mem E0 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β} {a : α} (ha : a ∈ β), ⟨a, ha⟩ ∈ γ → a ∈ Subtype.val '' γ
theorem Set.image_val_subset E1 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β}, Subtype.val '' γ ⊆ β
theorem Set.mem_of_mem_image_val E0 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β} {a : α} (ha : a ∈ Subtype.val '' γ), ⟨a, ⋯⟩ ∈ γ
theorem Set.image_image_val_eq_domRestrict_image E1 #
∀ {α : Type u} {β : Set α} {γ : Set ↑β} {δ : Type u_1} {f : α → δ}, f '' Subtype.val '' γ = β.domRestrict f '' γ
def SetM E1 #
Type u → Type u
This is Set but with a Monad instance.
instance instAlternativeMonadSetM E0 #
AlternativeMonad SetM
instance instLawfulMonadSetM E0 #
LawfulMonad SetM
instance instLawfulAlternativeSetM E0 #
LawfulAlternative SetM
def SetM.run E1 #
{α : Type u_1} → SetM α → Set α
Evaluates the SetM monad, yielding a Set.
Implementation note: this is the identity function.
Deprecated aliases
| Name | New name | Since |
|---|---|---|
Set.image_coe_eq_restrict_image | Set.image_coe_eq_domRestrict_image | 2026-07-19 |
Set.image_image_val_eq_restrict_image | Set.image_image_val_eq_domRestrict_image | 2026-07-19 |