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.
@[simp]
theorem
Finset.fmap_def
{α β : Type u}
[(P : Prop) → Decidable P]
{s : Finset α}
(f : α → β)
:
f <$> s = Finset.image f s
Pure #
Equations
- Finset.pure = { pure := fun {α : Type ?u.6} (x : α) => {x} }
Applicative functor #
Equations
- Finset.applicative = Applicative.mk
@[simp]
theorem
Finset.seq_def
{α β : Type u}
[(P : Prop) → Decidable P]
(s : Finset α)
(t : Finset (α → β))
:
t <*> s = t.sup fun (f : α → β) => Finset.image f s
theorem
Finset.image₂_def
[(P : Prop) → Decidable P]
{α β γ : Type u}
(f : α → β → γ)
(s : Finset α)
(t : Finset β)
:
Finset.image₂ f s t = f <$> s <*> 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
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Monad #
Alternative functor #
Traversable functor #
def
Finset.traverse
{α β : 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}
(h : α → β)
:
Functor.map h ∘ Multiset.toFinset = Multiset.toFinset ∘ Functor.map h
@[simp]
theorem
Finset.map_comp_coe_apply
{α β : Type u}
(h : α → β)
(s : Multiset α)
:
Finset.image h s.toFinset = (h <$> s).toFinset
theorem
Finset.map_traverse
{α β γ : 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