Image and map operations on finite sets #
This file provides the finite analog of Set.image
, along with some other similar functions.
Note there are two ways to take the image over a finset; via Finset.image
which applies the
function then removes duplicates (requiring DecidableEq
), or via Finset.map
which exploits
injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to
choosing between insert
and Finset.cons
, or between Finset.union
and Finset.disjUnion
.
Main definitions #
Finset.image
: Given a functionf : α → β
,s.image f
is the image finset inβ
.Finset.map
: Given an embeddingf : α ↪ β
,s.map f
is the image finset inβ
.Finset.filterMap
Given a functionf : α → Option β
,s.filterMap f
is the image finset inβ
, filtering outnone
s.Finset.subtype
:s.subtype p
is the finset ofSubtype p
whose elements belong tos
.Finset.fin
:s.fin n
is the finset of all elements ofs
less thann
.
TODO #
Move the material about Finset.range
so that the Mathlib.Algebra.Group.Embedding
import can be
removed.
map #
When f
is an embedding of α
in β
and s
is a finset in α
, then s.map f
is the image
finset in β
. The embedding condition guarantees that there are no duplicates in the image.
Equations
- Finset.map f s = { val := Multiset.map (⇑f) s.val, nodup := ⋯ }
Instances For
If the only elements outside s
are those left fixed by σ
, then mapping by σ
has no effect.
Alias of the reverse direction of Finset.map_subset_map
.
The Finset
version of Equiv.subset_symm_image
.
The Finset
version of Equiv.symm_image_subset
.
Associate to an embedding f
from α
to β
the order embedding that maps a finset to its
image under f
.
Equations
Instances For
Alias of the reverse direction of Finset.map_ssubset_map
.
A version of Finset.map_disjUnion
for writing in the other direction.
Alias of the reverse direction of Finset.map_nonempty
.
image #
image f s
is the forward image of s
under f
.
Equations
- Finset.image f s = (Multiset.map f s.val).toFinset
Instances For
Alias of Finset.forall_mem_image
.
Alias of the forward direction of Finset.image_nonempty
.
filterMap #
filterMap f s
is a combination filter/map operation on s
.
The function f : α → Option β
is applied to each element of s
;
if f a
is some b
then b
is included in the result, otherwise
a
is excluded from the resulting finset.
In notation, filterMap f s
is the finset {b : β | ∃ a ∈ s , f a = some b}
.
Equations
- Finset.filterMap f s f_inj = { val := Multiset.filterMap f s.val, nodup := ⋯ }
Instances For
Subtype #
Given a finset s
and a predicate p
, s.subtype p
is the finset of Subtype p
whose
elements belong to s
.
Equations
- Finset.subtype p s = Finset.map { toFun := fun (x : { x : α // x ∈ Finset.filter p s }) => ⟨↑x, ⋯⟩, inj' := ⋯ } (Finset.filter p s).attach
Instances For
s.subtype p
converts back to s.filter p
with
Embedding.subtype
.
If all elements of a Finset
satisfy the predicate p
,
s.subtype p
converts back to s
with Embedding.subtype
.
If a Finset
of a subtype is converted to the main type with
Embedding.subtype
, all elements of the result have the property of
the subtype.
If a Finset
of a subtype is converted to the main type with
Embedding.subtype
, the result does not contain any value that does
not satisfy the property of the subtype.
If a Finset
of a subtype is converted to the main type with
Embedding.subtype
, the result is a subset of the set giving the
subtype.
Fin #
Given a finset s
of natural numbers and a bound n
,
s.fin n
is the finset of all elements of s
less than n
.
Equations
- Finset.fin n s = Finset.map Fin.equivSubtype.symm.toEmbedding (Finset.subtype (fun (i : ℕ) => i < n) s)
Instances For
If a finset t
is a subset of the image of another finset s
under f
, then it is equal to the
image of a subset of s
.
For the version where s
is a set, see subset_set_image_iff
.
If a Finset
is a subset of the image of a Set
under f
,
then it is equal to the Finset.image
of a Finset
subset of that Set
.
Given an equivalence α
to β
, produce an equivalence between Finset α
and Finset β
.
Equations
- e.finsetCongr = { toFun := fun (s : Finset α) => Finset.map e.toEmbedding s, invFun := fun (s : Finset β) => Finset.map e.symm.toEmbedding s, left_inv := ⋯, right_inv := ⋯ }