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
.
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 := (_ : Multiset.Nodup (Multiset.map (⇑f) s.val)) }
Instances For
If the only elements outside s
are those left fixed by σ
, then mapping by σ
has no effect.
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
- Finset.mapEmbedding f = OrderEmbedding.ofMapLEIff (Finset.map f) (_ : ∀ (x x_1 : Finset α), Finset.map f x ⊆ Finset.map f x_1 ↔ x ⊆ x_1)
Instances For
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.toFinset (Multiset.map f s.val)
Instances For
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 := (_ : Multiset.Nodup (Multiset.filterMap f s.val)) }
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
- One or more equations did not get rendered due to their size.
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 (Equiv.toEmbedding Fin.equivSubtype.symm) (Finset.subtype (fun (i : ℕ) => i < n) s)
Instances For
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
.
Deprecated lemmas #
Those lemmas have been deprecated on 2023-12-27.
Alias of Finset.filter_image
.