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.toFinsetto noncomputably produce aFinsetfrom aSet.Finiteproof. (SeeSet.toFinsetfor 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
Instances For
Finite sets can be lifted to finsets.
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
Fintype instances #
Every instance here should have a corresponding Set.Finite constructor in the next section.
Equations
Equations
Equations
- s.fintypeUnion t = Fintype.ofFinset (s.toFinset ∪ t.toFinset) ⋯
Equations
- s.fintypeSep p = Fintype.ofFinset ({a ∈ s.toFinset | p a}) ⋯
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 ({a ∈ s.toFinset | a ∈ t}) ⋯
A Fintype instance for set intersection where the right set has a Fintype instance.
Equations
- s.fintypeInterOfRight t = Fintype.ofFinset ({a ∈ t.toFinset | a ∈ s}) ⋯
A Fintype structure on a set defines a Fintype structure on its subset.
Equations
- s.fintypeSubset h = ⋯.mpr (s.fintypeInterOfLeft t)
Instances For
Equations
- s.fintypeDiff t = Fintype.ofFinset (s.toFinset \ t.toFinset) ⋯
Equations
- s.fintypeDiffLeft t = s.fintypeSep fun (x : α) => x ∈ tᶜ
Equations
Equations
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) ⋯
A Fintype structure on insert a s when inserting a pre-existing element.
Equations
- s.fintypeInsertOfMem h = Fintype.ofFinset s.toFinset ⋯
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 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
Equations
This is not an instance so that it does not conflict with the one
in Mathlib/Order/Interval/Finset/Defs.lean.
Equations
Instances For
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.
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 #
Induction principle for finite sets: To prove a property motive of a finite set s, it's
enough to prove for the empty set and to prove that motive t → motive ({a} ∪ t) for all t.
See also Set.Finite.induction_on for the version requiring to check motive t → motive ({a} ∪ t)
only for t ⊆ s.
Induction principle for finite sets: To prove a property C of a finite set s, it's enough
to prove for the empty set and to prove that C t → C ({a} ∪ t) for all t ⊆ s.
This is analogous to Finset.induction_on'. See also Set.Finite.induction_on for the version
requiring C t → C ({a} ∪ t) for all t.
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 Set.Infinite.exists_notMem_finite.
Alias of Set.Infinite.exists_notMem_finset.
Alias of Set.Finite.exists_notMem.
Alias of Finset.exists_notMem.
Embedding of ℕ into an infinite set.
Equations
Instances For
Alias of the reverse direction of Set.infinite_image_iff.
Finset version of Set.SurjOn.exists_subset_injOn_image_eq.
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.