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 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
.
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
- h.fintype = ⋯.some
Instances For
Alias of the reverse direction of Set.not_infinite
.
See also finite_or_infinite
, fintypeOrInfinite
.
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) ⋯
Equations
- Set.fintypeiUnion f = Fintype.ofFinset (Finset.univ.biUnion fun (i : PLift ι) => (f i.down).toFinset) ⋯
Equations
- Set.fintypesUnion = ⋯.mpr (Set.fintypeiUnion Subtype.val)
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) ⋯
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
- s.fintypeBind f H = s.fintypeBiUnion f H
Instances For
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 and sends a set s
to a set with [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.fintypeRange f = Fintype.ofFinset (Finset.image (f ∘ PLift.down) Finset.univ) ⋯
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
- s.fintypeOffDiag = Fintype.ofFinset s.toFinset.offDiag ⋯
image2 f s t
is Fintype
if s
and t
are.
Equations
- Set.fintypeImage2 f s t = ⋯.mpr ((s ×ˢ t).fintypeImage fun (x : α × β) => f x.1 x.2)
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.
Example: Finite (⋃ (i < n), f i)
where f : ℕ → Set α
and [∀ i, Finite (f i)]
(when given instances from Order.Interval.Finset.Nat
).
Equations
- ⋯ = ⋯
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
.
Finite product of finite sets is finite. Note this is a variant of Set.Finite.pi
without the
extra i ∈ univ
binder.
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 #
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.