Functoriality of Finset
#
This file defines the functor structure of Finset
.
TODO #
Currently, all instances are classical because the functor classes want to run over all types. If instead we could state that a functor is lawful/applicative/traversable... between two given types, then we could provide the instances for types with decidable equality.
Functor #
Because Finset.image
requires a DecidableEq
instance for the target type, we can only
construct Functor Finset
when working classically.
Equations
- One or more equations did not get rendered due to their size.
Equations
- (_ : LawfulFunctor Finset) = (_ : LawfulFunctor Finset)
@[simp]
theorem
Finset.fmap_def
{α : Type u}
{β : Type u}
[(P : Prop) → Decidable P]
{s : Finset α}
(f : α → β)
:
f <$> s = Finset.image f s
Pure #
Equations
- Finset.pure = { pure := fun {α : Type u_1} (x : α) => {x} }
Applicative functor #
Equations
- Finset.applicative = let src := Finset.functor; let src_1 := Finset.pure; Applicative.mk
@[simp]
theorem
Finset.seq_def
{α : Type u}
{β : Type u}
[(P : Prop) → Decidable P]
(s : Finset α)
(t : Finset (α → β))
:
(Seq.seq t fun (x : Unit) => s) = Finset.sup t fun (f : α → β) => Finset.image f s
theorem
Finset.image₂_def
[(P : Prop) → Decidable P]
{α : Type u}
{β : Type u}
{γ : Type u}
(f : α → β → γ)
(s : Finset α)
(t : Finset β)
:
Finset.image₂ f s t = Seq.seq (f <$> s) fun (x : Unit) => t
Finset.image₂
in terms of monadic operations. Note that this can't be taken as the definition
because of the lack of universe polymorphism.
Equations
- (_ : LawfulApplicative Finset) = (_ : LawfulApplicative Finset)
Equations
- (_ : CommApplicative Finset) = (_ : CommApplicative Finset)
Monad #
Equations
- (_ : LawfulMonad Finset) = (_ : LawfulMonad Finset)
Alternative functor #
Traversable functor #
def
Finset.traverse
{α : Type u}
{β : Type u}
{F : Type u → Type u}
[Applicative F]
[CommApplicative F]
[DecidableEq β]
(f : α → F β)
(s : Finset α)
:
F (Finset β)
Traverse function for Finset
.
Equations
- Finset.traverse f s = Multiset.toFinset <$> Multiset.traverse f s.val
Instances For
@[simp]
@[simp]
theorem
Finset.map_comp_coe
{α : Type u}
{β : Type u}
(h : α → β)
:
Functor.map h ∘ Multiset.toFinset = Multiset.toFinset ∘ Functor.map h
theorem
Finset.map_traverse
{α : Type u}
{β : Type u}
{γ : Type u}
{G : Type u → Type u}
[Applicative G]
[CommApplicative G]
(g : α → G β)
(h : β → γ)
(s : Finset α)
:
Functor.map h <$> Finset.traverse g s = Finset.traverse (Functor.map h ∘ g) s