Finite sets #
This file defines predicates for finite and infinite sets and provides
Fintype
instances for many set constructions. It also proves basic facts
about finite sets and gives ways to manipulate Set.Finite
expressions.
Main definitions #
Set.Finite : Set α → Prop
Set.Infinite : Set α → Prop
Set.toFinite
to proveSet.Finite
for aSet
from aFinite
instance.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 Fintype
instance.
Since Set.Finite
is Prop
-valued, this is the mere fact that the Fintype
instance
exists.
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
A set is finite if there is a Finset
with the same elements.
This is represented as there being a Fintype
instance for the set
coerced to a type.
Note: this is a custom inductive type rather than Nonempty (Fintype s)
so that it won't be frozen as a local instance.
- intro: ∀ {α : Type u} {s : Set α}, Fintype ↑s → Set.Finite s
Instances For
Alias of the forward direction of Set.finite_def
.
Constructor for Set.Finite
using a Finite
instance.
Projection of Set.Finite
to its Finite
instance.
This is intended to be used with dot notation.
See also Set.Finite.Fintype
and Set.Finite.nonempty_fintype
.
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
- Set.Finite.fintype h = Nonempty.some (_ : Nonempty (Fintype ↑s))
Instances For
A set is infinite if it is not finite.
This is protected so that it does not conflict with global Infinite
.
Equations
- Set.Infinite s = ¬Set.Finite s
Instances For
Alias of the reverse direction of Set.not_infinite
.
See also finite_or_infinite
, fintypeOrInfinite
.
Basic properties of Set.Finite.toFinset
#
Note that this is an equality of types not holding definitionally. Use wisely.
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
- Set.Finite.subtypeEquivToFinset hs = Equiv.subtypeEquiv (Equiv.refl α) (_ : ∀ (x : α), x ∈ s ↔ x ∈ Set.Finite.toFinset hs)
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
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
- Set.fintypeUnion s t = Fintype.ofFinset (Set.toFinset s ∪ Set.toFinset t) (_ : ∀ (a : α), a ∈ Set.toFinset s ∪ Set.toFinset t ↔ a ∈ s ∪ t)
Equations
- Set.fintypeSep s p = Fintype.ofFinset (Finset.filter p (Set.toFinset s)) (_ : ∀ (a : α), a ∈ Finset.filter p (Set.toFinset s) ↔ a ∈ s ∧ p a)
Equations
- Set.fintypeInter s t = Fintype.ofFinset (Set.toFinset s ∩ Set.toFinset t) (_ : ∀ (a : α), a ∈ Set.toFinset s ∩ Set.toFinset t ↔ a ∈ s ∩ t)
A Fintype
structure on a set defines a Fintype
structure on its subset.
Equations
- Set.fintypeSubset s h = Eq.mpr (_ : Fintype ↑t = Fintype ↑(s ∩ t)) (Set.fintypeInterOfLeft s t)
Instances For
Equations
- Set.fintypeDiff s t = Fintype.ofFinset (Set.toFinset s \ Set.toFinset t) (_ : ∀ (a : α), a ∈ Set.toFinset s \ Set.toFinset t ↔ a ∈ s \ t)
Equations
- Set.fintypeDiffLeft s t = Set.fintypeSep s fun (x : α) => x ∈ tᶜ
Equations
- One or more equations did not get rendered due to their size.
A union of sets with Fintype
structure over a set with Fintype
structure has a Fintype
structure.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
If s : Set α
is a set with Fintype
instance and f : α → Set β
is a function such that
each f a
, a ∈ s
, has a Fintype
structure, then s >>= f
has a Fintype
structure.
Equations
- Set.fintypeBind s f H = Set.fintypeBiUnion s f H
Instances For
Equations
- Set.fintypeBind' s f = Set.fintypeBiUnion' s f
Equations
- Set.fintypeSingleton a = Fintype.ofFinset {a} (_ : ∀ (a_1 : α), a_1 ∈ {a} ↔ a_1 ∈ {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 (Set.toFinset s)) (_ : ∀ (a_1 : α), a_1 ∈ insert a (Set.toFinset s) ↔ a_1 ∈ insert a s)
A Fintype
structure on insert a s
when inserting a pre-existing element.
Equations
- Set.fintypeInsertOfMem s h = Fintype.ofFinset (Set.toFinset s) (_ : ∀ (a_1 : α), a_1 ∈ Set.toFinset s ↔ a_1 ∈ insert a s)
Instances For
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 Set.fintypeInsertOfMem s h else Set.fintypeInsertOfNotMem s h
Equations
- Set.fintypeImage s f = Fintype.ofFinset (Finset.image f (Set.toFinset s)) (_ : ∀ (a : β), a ∈ Finset.image f (Set.toFinset s) ↔ a ∈ f '' s)
If a function f
has a partial inverse and sends a set s
to a set with [Fintype]
instance,
then s
has a Fintype
structure as well.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Set.fintypeRange f = Fintype.ofFinset (Finset.image (f ∘ PLift.down) Finset.univ) (_ : ∀ (a : α), a ∈ Finset.image (f ∘ PLift.down) Finset.univ ↔ a ∈ Set.range f)
Equations
- Set.fintypeMap = Set.fintypeImage
Equations
- Set.fintypeLTNat n = Fintype.ofFinset (Finset.range n) (_ : ∀ (a : ℕ), a ∈ Finset.range n ↔ a < n)
This is not an instance so that it does not conflict with the one
in Mathlib/Order/LocallyFinite.lean
.
Equations
Instances For
Equations
- Set.fintypeProd s t = Fintype.ofFinset (Set.toFinset s ×ˢ Set.toFinset t) (_ : ∀ (a : α × β), a ∈ Set.toFinset s ×ˢ Set.toFinset t ↔ a ∈ s ×ˢ t)
Equations
- Set.fintypeOffDiag s = Fintype.ofFinset (Finset.offDiag (Set.toFinset s)) (_ : ∀ (a : α × α), a ∈ Finset.offDiag (Set.toFinset s) ↔ a ∈ Set.offDiag s)
image2 f s t
is Fintype
if s
and t
are.
Equations
- Set.fintypeImage2 f s t = Eq.mpr (_ : Fintype ↑(Set.image2 f s t) = Fintype ↑((fun (x : α × β) => f x.1 x.2) '' s ×ˢ t)) (Set.fintypeImage (s ×ˢ t) fun (x : α × β) => f x.1 x.2)
Equations
- Set.fintypeSeq' f s = Set.fintypeSeq f s
Equations
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.
Example: Finite (⋃ (i < n), f i)
where f : ℕ → Set α
and [∀ i, Finite (f i)]
(when given instances from Data.Nat.Interval
).
Equations
- (_ : Finite ↑(Set.image2 f s t)) = (_ : Finite ↑(Set.image2 f s t))
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
.
Dependent version of Finite.biUnion
.
If sets s i
are finite for all i
from a finite set t
and are empty for i ∉ t
, then the
union ⋃ i, s i
is a finite set.
There are finitely many subsets of a given finite set
Finite product of finite sets is finite
Finite product of finite sets is finite. Note this is a variant of Set.Finite.pi
without the
extra i ∈ univ
binder.
A finite union of finsets is finite.
Properties #
Equations
- Set.Finite.inhabited = { default := { val := ∅, property := (_ : Set.Finite ∅) } }
Analogous to Finset.induction_on'
.
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 #
Alias of the reverse direction of Set.infinite_coe_iff
.
Embedding of ℕ
into an infinite set.
Equations
Instances For
Alias of the reverse direction of Set.infinite_image_iff
.
Order properties #
An increasing union distributes over finite intersection.
A decreasing union distributes over finite intersection.
An increasing intersection distributes over finite union.
A decreasing intersection distributes over finite union.
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.
A finite set is bounded above.
A finite union of sets which are all bounded above is still bounded above.
A finite set is bounded below.
A finite union of sets which are all bounded below is still bounded below.
A finset is bounded above.
A finset is bounded below.
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.