Finite sets #
This file provides Fintype
instances for many set constructions. It also proves basic facts about
finite sets and gives ways to manipulate Set.Finite
expressions.
Note that the instances in this file are selected somewhat arbitrarily on the basis of them not
needing any imports beyond Data.Fintype.Card
(which is required by Finite.ofFinset
); they can
certainly be organized better.
Main definitions #
Set.Finite.toFinset
to noncomputably produce aFinset
from aSet.Finite
proof. (SeeSet.toFinset
for a computable version.)
Implementation #
A finite set is defined to be a set whose coercion to a type has a Finite
instance.
There are two components to finiteness constructions. The first is Fintype
instances for each
construction. This gives a way to actually compute a Finset
that represents the set, and these
may be accessed using set.toFinset
. This gets the Finset
in the correct form, since otherwise
Finset.univ : Finset s
is a Finset
for the subtype for s
. The second component is
"constructors" for Set.Finite
that give proofs that Fintype
instances exist classically given
other Set.Finite
proofs. Unlike the Fintype
instances, these do not use any decidability
instances since they do not compute anything.
Tags #
finite sets
Alias of the forward direction of Set.finite_def
.
A finite set coerced to a type is a Fintype
.
This is the Fintype
projection for a Set.Finite
.
Note that because Finite
isn't a typeclass, this definition will not fire if it
is made into an instance
Equations
- h.fintype = ⋯.some
Instances For
Basic properties of Set.Finite.toFinset
#
The identity map, bundled as an equivalence between the subtypes of s : Set α
and of
h.toFinset : Finset α
, where h
is a proof of finiteness of s
.
Equations
- hs.subtypeEquivToFinset = (Equiv.refl α).subtypeEquiv ⋯
Instances For
Alias of the reverse direction of Set.Finite.toFinset_subset_toFinset
.
Alias of the reverse direction of Set.Finite.toFinset_ssubset_toFinset
.
Fintype instances #
Every instance here should have a corresponding Set.Finite
constructor in the next section.
Equations
- Set.fintypeUniv = Fintype.ofEquiv α (Equiv.Set.univ α).symm
Equations
- Set.fintypeTop = inferInstanceAs (Fintype ↑Set.univ)
If (Set.univ : Set α)
is finite then α
is a finite type.
Equations
- Set.fintypeOfFiniteUniv H = Fintype.ofEquiv (↑Set.univ) (Equiv.Set.univ α)
Instances For
Equations
- s.fintypeUnion t = Fintype.ofFinset (s.toFinset ∪ t.toFinset) ⋯
Equations
- s.fintypeSep p = Fintype.ofFinset (Finset.filter p s.toFinset) ⋯
Equations
- s.fintypeInter t = Fintype.ofFinset (s.toFinset ∩ t.toFinset) ⋯
A Fintype
instance for set intersection where the left set has a Fintype
instance.
Equations
- s.fintypeInterOfLeft t = Fintype.ofFinset (Finset.filter (fun (x : α) => x ∈ t) s.toFinset) ⋯
A Fintype
instance for set intersection where the right set has a Fintype
instance.
Equations
- s.fintypeInterOfRight t = Fintype.ofFinset (Finset.filter (fun (x : α) => x ∈ s) t.toFinset) ⋯
Equations
- s.fintypeDiff t = Fintype.ofFinset (s.toFinset \ t.toFinset) ⋯
A union of sets with Fintype
structure over a set with Fintype
structure has a Fintype
structure.
Equations
- s.fintypeBiUnion t H = Fintype.ofFinset (s.toFinset.attach.biUnion fun (x : { x : ι // x ∈ s.toFinset }) => (t ↑x).toFinset) ⋯
Instances For
Equations
- s.fintypeBiUnion' t = Fintype.ofFinset (s.toFinset.biUnion fun (x : ι) => (t x).toFinset) ⋯
Equations
- Set.fintypeEmpty = Fintype.ofFinset ∅ ⋯
Equations
- Set.fintypeSingleton a = Fintype.ofFinset {a} ⋯
A Fintype
instance for inserting an element into a Set
using the
corresponding insert
function on Finset
. This requires DecidableEq α
.
There is also Set.fintypeInsert'
when a ∈ s
is decidable.
Equations
- Set.fintypeInsert a s = Fintype.ofFinset (insert a s.toFinset) ⋯
The Set.fintypeInsert
instance requires decidable equality, but when a ∈ s
is decidable for this particular a
we can still get a Fintype
instance by using
Set.fintypeInsertOfNotMem
or Set.fintypeInsertOfMem
.
This instance pre-dates Set.fintypeInsert
, and it is less efficient.
When Set.decidableMemOfFintype
is made a local instance, then this instance would
override Set.fintypeInsert
if not for the fact that its priority has been
adjusted. See Note [lower instance priority].
Equations
- Set.fintypeInsert' a s = if h : a ∈ s then s.fintypeInsertOfMem h else s.fintypeInsertOfNotMem h
Equations
- s.fintypeImage f = Fintype.ofFinset (Finset.image f s.toFinset) ⋯
If a function f
has a partial inverse g
and the image of s
under f
is a set with
a Fintype
instance, then s
has a Fintype
structure as well.
Equations
- s.fintypeOfFintypeImage I = Fintype.ofFinset { val := Multiset.filterMap g (f '' s).toFinset.val, nodup := ⋯ } ⋯
Instances For
Equations
- Set.fintypeMap = Set.fintypeImage
Equations
Equations
- Set.fintypeLENat n = id (⋯.mp (Set.fintypeLTNat (n + 1)))
This is not an instance so that it does not conflict with the one
in Mathlib/Order/LocallyFinite.lean
.
Equations
Instances For
Equations
- Set.fintypeMemFinset s = s.fintypeCoeSort
Finset #
Gives a Set.Finite
for the Finset
coerced to a Set
.
This is a wrapper around Set.toFinite
.
Finite instances #
There is seemingly some overlap between the following instances and the Fintype
instances
in Data.Set.Finite
. While every Fintype
instance gives a Finite
instance, those
instances that depend on Fintype
or Decidable
instances need an additional Finite
instance
to be able to generally apply.
Some set instances do not appear here since they are consequences of others, for example
Subtype.Finite
for subsets of a finite type.
Constructors for Set.Finite
#
Every constructor here should have a corresponding Fintype
instance in the previous section
(or in the Fintype
module).
The implementation of these constructors ideally should be no more than Set.toFinite
,
after possibly setting up some Fintype
and classical Decidable
instances.
Alias of the forward direction of Set.finite_univ_iff
.
Properties #
If P
is some relation between terms of γ
and sets in γ
, such that every finite set
t : Set γ
has some c : γ
related to it, then there is a recursively defined sequence u
in γ
so u n
is related to the image of {0, 1, ..., n-1}
under u
.
(We use this later to show sequentially compact sets are totally bounded.)
Cardinality #
Infinite sets #
Embedding of ℕ
into an infinite set.
Equations
Instances For
Alias of the reverse direction of Set.infinite_image_iff
.
Order properties #
A version of Finite.exists_maximal_wrt
with the (weaker) hypothesis that the image of s
is finite rather than s
itself.
A version of Finite.exists_minimal_wrt
with the (weaker) hypothesis that the image of s
is finite rather than s
itself.
If a linear order does not contain any triple of elements x < y < z
, then this type
is finite.
If a set s
does not contain any triple of elements x < y < z
, then s
is finite.