Image and map operations on finite sets #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Thie 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 decidable_eq
), 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.disj_union
.
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.subtype
:s.subtype p
is the the finset ofsubtype p
whose elements belong tos
.finset.fin
:s.fin n
is the finset of all elements ofs
less thann
.
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 := _}
If the only elements outside s
are those left fixed by σ
, then mapping by σ
has no effect.
Associate to an embedding f
from α
to β
the order embedding that maps a finset to its
image under f
.
Equations
A version of finset.map_disj_union
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).to_finset
Instances for finset.image
Equations
- finset.can_lift c p = {prf := _}
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 {to_fun := λ (x : {x // x ∈ finset.filter p s}), ⟨x.val, _⟩, inj' := _} (finset.filter p s).attach
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.equiv_subtype.symm.to_embedding (finset.subtype (λ (i : ℕ), i < n) s)
Given an equivalence α
to β
, produce an equivalence between finset α
and finset β
.
Equations
- e.finset_congr = {to_fun := λ (s : finset α), finset.map e.to_embedding s, inv_fun := λ (s : finset β), finset.map e.symm.to_embedding s, left_inv := _, right_inv := _}