Noncomputable Set Cardinality #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
We define the cardinality set.ncard s of a set s as a natural number. This function is
noncomputable (being defined in terms of nat.card) and takes the value 0 if s is infinite.
This can be seen as an API for nat.card α in the special case where α is a subtype arising from
a set. It is intended as an alternative to finset.card and fintype.card, both of which contain
data in their definition that can cause awkwardness when using set.to_finset. Using set.ncard
allows cardinality computations to avoid finset/fintype completely, staying in set and letting
finiteness be handled explicitly, or (where a finite α instance is present and the sets are
in set α) via auto_params.
Main Definitions #
set.ncard sis the cardinality of the setsas a natural number, providedsis finite. Ifsis infinite, thenset.ncard s = 0.to_finite_tacis a tactic that tries to synthesize anset.finite sargument withset.to_finite. This will work fors : set αwhere there is afinite αinstance.
Implementation Notes #
The lemmas in this file are very similar to those in data.finset.card, but with set operations
instead of finset; most of the proofs invoke their finset analogues. Nearly all the lemmas
require finiteness of one or more of their arguments. We provide this assumption with an
auto_param argument of the form (hs : s.finite . to_finite_tac), where to_finite_tac will find
a finite s term in the cases where s is a set in a finite type.
Often, where there are two set arguments s and t, the finiteness of one follows from the other
in the context of the lemma, in which case we only include the ones that are needed, and derive the
other inside the proof. A few of the lemmas, such as ncard_union_le do not require finiteness
arguments; they are are true by coincidence due to junk values.
Explicit description of a set from its cardinality #
A set of a subsingleton type has cardinality at most one.