Basic properties of sets #
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type X
are thus defined as Set X := X → Prop
. Note that this function need not
be decidable. The definition is in the core library.
This file provides some basic definitions related to sets and functions not present in the core library, as well as extra lemmas for functions in the core library (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset).
Note that a set is a term, not a type. There is a coercion from Set α
to Type*
sending
s
to the corresponding subtype ↥s
.
See also the file SetTheory/ZFC.lean
, which contains an encoding of ZFC set theory in Lean.
Main definitions #
Notation used here:
Definitions in the file:
-
Nonempty s : Prop
: the predicates ≠ ∅
. Note that this is the preferred way to express the fact thats
has an element (see the Implementation Notes). -
Subsingleton s : Prop
: the predicate saying thats
has at most one element. -
Nontrivial s : Prop
: the predicate saying thats
has at least two distinct elements. -
inclusion s₁ s₂ : ↥s₁ → ↥s₂
: the map↥s₁ → ↥s₂
induced by an inclusions₁ ⊆ s₂
.
Notation #
sᶜ
for the complement ofs
Implementation notes #
-
s.Nonempty
is to be preferred tos ≠ ∅
or∃ x, x ∈ s
. It has the advantage that thes.Nonempty
dot notation can be used. -
For
s : Set α
, do not useSubtype s
. Instead use↥s
or(s : Type*)
ors
.
Tags #
set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset
Set coercion to a type #
Equations
- One or more equations did not get rendered due to their size.
Alias of the forward direction of Set.le_iff_subset
.
Alias of the reverse direction of Set.le_iff_subset
.
Alias of the forward direction of Set.lt_iff_ssubset
.
Alias of the reverse direction of Set.lt_iff_ssubset
.
Equations
- instCoeTCElem s = { coe := fun x => ↑x }
Subset and strict subset relations #
Definition of strict subsets s ⊂ t
and basic properties. #
Non-empty sets #
The property s.Nonempty
expresses the fact that the set s
is not empty. It should be used
in theorem assumptions instead of ∃ x, x ∈ s
or s ≠ ∅
as it gives access to a nice API thanks
to the dot notation.
Equations
- Set.Nonempty s = ∃ x, x ∈ s
Instances For
Alias of the reverse direction of Set.nonempty_coe_sort
.
Extract a witness from s.Nonempty
. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the Classical.choice
axiom.
Equations
Instances For
Lemmas about the empty set #
See also Set.nonempty_iff_ne_empty
.
See also Set.not_nonempty_iff_eq_empty
.
See also nonempty_iff_ne_empty'
.
See also not_nonempty_iff_eq_empty'
.
Alias of the forward direction of Set.nonempty_iff_ne_empty
.
See also Set.not_nonempty_iff_eq_empty
.
Alias of the reverse direction of Set.empty_ssubset
.
Universal set. #
In Lean @univ α
(or univ : Set α
) is the set that contains all elements of type α
.
Mathematically it is the same as α
but it has a different type.
Alias of the forward direction of Set.univ_subset_iff
.
Lemmas about union #
Equations
Lemmas about intersection #
Equations
Distributivity laws #
Lemmas about insert
#
insert α s
is the set {α} ∪ s
.
Lemmas about singletons #
Equations
- Set.uniqueSingleton a = { toInhabited := { default := { val := a, property := (_ : a ∈ {a}) } }, uniq := (_ : ∀ (x : ↑{a}), x = default) }
Lemmas about pairs #
Lemmas about sets defined as {x ∈ s | p x}
. #
Disjointness #
Alias of the reverse direction of Set.not_disjoint_iff_nonempty_inter
.
Alias of the forward direction of Set.disjoint_iff_forall_ne
.
Lemmas about complement #
Alias of the reverse direction of Set.subset_compl_iff_disjoint_right
.
Alias of the reverse direction of Set.subset_compl_iff_disjoint_left
.
Alias of the reverse direction of Set.disjoint_compl_left_iff_subset
.
Alias of the reverse direction of Set.disjoint_compl_right_iff_subset
.
Lemmas about set difference #
Symmetric difference #
Powerset #
Sets defined as an if-then-else #
If-then-else for sets #
Subsingleton #
A set s
is a Subsingleton
if it has at most one element.
Equations
- Set.Subsingleton s = ∀ ⦃x : α⦄, x ∈ s → ∀ ⦃y : α⦄, y ∈ s → x = y
Instances For
s
, coerced to a type, is a subsingleton type if and only if s
is a subsingleton set.
The coe_sort
of a set s
in a subsingleton type is a subsingleton.
For the corresponding result for Subtype
, see subtype.subsingleton
.
Nontrivial #
A set s
is Set.Nontrivial
if it has at least two distinct elements.
Instances For
Extract witnesses from s.nontrivial. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the classical.choice axiom.
Equations
- Set.Nontrivial.choose hs = (Exists.choose hs, Exists.choose (_ : ∃ y, y ∈ s ∧ Exists.choose hs ≠ y))
Instances For
s
, coerced to a type, is a nontrivial type if and only if s
is a nontrivial set.
Alias of the reverse direction of Set.nontrivial_coe_sort
.
s
, coerced to a type, is a nontrivial type if and only if s
is a nontrivial set.
A type with a set s
whose coe_sort
is a nontrivial type is nontrivial.
For the corresponding result for Subtype
, see Subtype.nontrivial_iff_exists_ne
.
Alias of the reverse direction of Set.not_nontrivial_iff
.
Alias of the reverse direction of Set.not_subsingleton_iff
.
Monotonicity on singletons #
A function between linear orders which is neither monotone nor antitone makes a dent upright or downright.
A function between linear orders which is neither monotone nor antitone makes a dent upright or downright.
inclusion
is the "identity" function between two subsets s
and t
, where s ⊆ t
Equations
- Set.inclusion h x = { val := ↑x, property := (_ : ↑x ∈ t) }
Instances For
Decidability instances for sets #
Equations
- Set.decidableUniv x = isTrue (_ : x ∈ Set.univ)
Equations
- Set.decidableSetOf a p = inst
Equations
- Set.decidableMemSingleton = Set.decidableSetOf a fun x => x = b