Functoriality of finset
#
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 #
@[protected, instance]
Because finset.image
requires a decidable_eq
instance for the target type, we can only
construct functor finset
when working classically.
Equations
- finset.functor = {map := λ (α β : Type u_1) (f : α → β) (s : finset α), finset.image f s, map_const := λ (α β : Type u_1), (λ (f : β → α) (s : finset β), finset.image f s) ∘ function.const β}
@[protected, instance]
@[simp]
theorem
finset.fmap_def
{α β : Type u}
[Π (P : Prop), decidable P]
{s : finset α}
(f : α → β) :
f <$> s = finset.image f s
Pure #
@[protected, instance]
Equations
- finset.has_pure = {pure := λ (α : Type u_1) (x : α), {x}}
Applicative functor #
@[protected, instance]
Equations
theorem
finset.image₂_def
[Π (P : Prop), decidable P]
{α β γ : Type u_1}
(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.
@[protected, instance]
@[protected, instance]
Monad #
@[protected, instance]
Equations
@[simp]
@[protected, instance]
Alternative functor #
@[protected, instance]
Equations
- finset.alternative = {to_applicative := {to_functor := applicative.to_functor finset.applicative, to_has_pure := applicative.to_has_pure finset.applicative, to_has_seq := applicative.to_has_seq finset.applicative, to_has_seq_left := applicative.to_has_seq_left finset.applicative, to_has_seq_right := applicative.to_has_seq_right finset.applicative}, to_has_orelse := {orelse := λ (α : Type u_1), has_union.union}, failure := λ (α : Type u_1), ∅}
Traversable functor #
def
finset.traverse
{α β : Type u}
{F : Type u → Type u}
[applicative F]
[is_comm_applicative F]
[decidable_eq β]
(f : α → F β)
(s : finset α) :
F (finset β)
Traverse function for finset
.
Equations
@[simp]
theorem
finset.id_traverse
{α : Type u}
[decidable_eq α]
(s : finset α) :
finset.traverse id.mk s = s
@[simp]
theorem
finset.map_traverse
{α β γ : Type u}
{G : Type u → Type u}
[applicative G]
[is_comm_applicative G]
(g : α → G β)
(h : β → γ)
(s : finset α) :
functor.map h <$> finset.traverse g s = finset.traverse (functor.map h ∘ g) s