Construct a sorted list from a finset. #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
sort #
sort s
constructs a sorted list from the unordered set s
.
(Uses merge sort algorithm.)
Equations
- finset.sort r s = multiset.sort r s.val
Given a finset s
of cardinality k
in a linear order α
, the map order_iso_of_fin s h
is the increasing bijection between fin k
and s
as an order_iso
. Here, h
is a proof that
the cardinality of s
is k
. We use this instead of an iso fin s.card ≃o s
to avoid
casting issues in further uses of this function.
Equations
- s.order_iso_of_fin h = (fin.cast _).trans ((list.sorted.nth_le_iso (finset.sort has_le.le s) _).trans (order_iso.set_congr (λ (x : α), list.mem x (finset.sort has_le.le s)) (λ (x : α), x ∈ s.val) _))
Given a finset s
of cardinality k
in a linear order α
, the map order_emb_of_fin s h
is
the increasing bijection between fin k
and s
as an order embedding into α
. Here, h
is a
proof that the cardinality of s
is k
. We use this instead of an embedding fin s.card ↪o α
to
avoid casting issues in further uses of this function.
Equations
- s.order_emb_of_fin h = rel_embedding.trans (s.order_iso_of_fin h).to_order_embedding (order_embedding.subtype (λ (x : α), x ∈ s))
The bijection order_emb_of_fin s h
sends 0
to the minimum of s
.
The bijection order_emb_of_fin s h
sends k-1
to the maximum of s
.
order_emb_of_fin {a} h
sends any argument to a
.
Any increasing map f
from fin k
to a finset of cardinality k
has to coincide with
the increasing bijection order_emb_of_fin s h
.
An order embedding f
from fin k
to a finset of cardinality k
has to coincide with
the increasing bijection order_emb_of_fin s h
.
Two parametrizations order_emb_of_fin
of the same set take the same value on i
and j
if
and only if i = j
. Since they can be defined on a priori not defeq types fin k
and fin l
(although necessarily k = l
), the conclusion is rather written (i : ℕ) = (j : ℕ)
.
Given a finset s
of size at least k
in a linear order α
, the map order_emb_of_card_le
is an order embedding from fin k
to α
whose image is contained in s
. Specifically, it maps
fin k
to an initial segment of s
.
Equations
- s.order_emb_of_card_le h = rel_embedding.trans (fin.cast_le h) (s.order_emb_of_fin _)