Basic properties of sets #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 set_theory/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
Equations
- set.boolean_algebra = {sup := λ (s t : set α), {x : α | x ∈ s ∨ x ∈ t}, le := has_le.le set.has_le, lt := λ (s t : set α), s ⊆ t ∧ ¬t ⊆ s, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_sup_left := _, le_sup_right := _, sup_le := _, inf := λ (s t : set α), {x : α | x ∈ s ∧ x ∈ t}, inf_le_left := _, inf_le_right := _, le_inf := _, le_sup_inf := _, compl := λ (s : set α), {x : α | x ∉ s}, sdiff := λ (s t : set α), {x : α | x ∈ s ∧ x ∉ t}, himp := boolean_algebra.himp infer_instance, top := set.univ α, bot := ∅, inf_compl_le_bot := _, top_le_sup_compl := _, le_top := _, bot_le := _, sdiff_eq := _, himp_eq := _}
Equations
- set.has_ssubset = {ssubset := has_lt.lt (preorder.to_has_lt (set α))}
Equations
- set.has_union = {union := has_sup.sup (semilattice_sup.to_has_sup (set α))}
Equations
- set.has_inter = {inter := has_inf.inf (semilattice_inf.to_has_inf (set α))}
Alias of the forward direction of set.le_iff_subset
.
Alias of the reverse direction of set.le_iff_subset
.
Alias of the reverse direction of set.lt_iff_ssubset
.
Alias of the forward direction of set.lt_iff_ssubset
.
Coercion from a set to the corresponding subtype.
Equations
- set.pi_set_coe.can_lift ι α s = pi_subtype.can_lift ι α s
Equations
- set.inhabited = {default := ∅}
If h : a ∈ {x | p x}
then h.out : p x
. These are definitionally equal, but this can
nevertheless be useful for various reasons, e.g. to apply further projection notation or in an
argument to simp
.
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.
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
- h.some = classical.some h
Lemmas about the empty set #
There is exactly one set of a type that is empty.
Equations
- set.unique_empty = {to_inhabited := {default := ∅}, uniq := _}
See also set.nonempty_iff_ne_empty
.
See also set.not_nonempty_iff_eq_empty
.
Alias of the forward direction of set.nonempty_iff_ne_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 #
Lemmas about intersection #
Distributivity laws #
Lemmas about insert
#
insert α s
is the set {α} ∪ s
.
Lemmas about singletons #
Equations
- set.unique_singleton a = {to_inhabited := {default := ⟨a, _⟩}, uniq := _}
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
.
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.
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 nontrivial
if it has at least two distinct elements.
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
- hs.some = (Exists.some hs, Exists.some _)
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
.
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.
Lemmas about inclusion
, the injection of subtypes induced by ⊆
#
Decidability instances for sets #
Equations
- s.decidable_sdiff t a = and.decidable
Equations
- s.decidable_inter t a = and.decidable
Equations
- s.decidable_union t a = or.decidable
Equations
Equations
- set.decidable_emptyset = λ (_x : α), decidable.is_false _
Equations
- set.decidable_univ = λ (_x : α), decidable.is_true _
Equations
- set.decidable_set_of a p = _inst_1