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 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). -
preimage f t : set α
: the preimage f⁻¹(t) (writtenf ⁻¹' t
in Lean) of a subset of β. -
subsingleton s : Prop
: the predicate saying thats
has at most one element. -
range f : set β
: the image ofuniv
underf
. Also works for{p : Prop} (f : p → α)
(unlikeimage
) -
inclusion s₁ s₂ : ↥s₁ → ↥s₂
: the map↥s₁ → ↥s₂
induced by an inclusions₁ ⊆ s₂
.
Notation #
-
f ⁻¹' t
forpreimage f t
-
f '' s
forimage f s
-
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, image, preimage, pre-image, range, union, intersection, insert, singleton, complement, powerset
Set coercion to a type #
Equations
Equations
- set.boolean_algebra = {sup := has_union.union set.has_union, le := has_le.le set.has_le, lt := has_lt.lt set.has_lt, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_sup_left := _, le_sup_right := _, sup_le := _, inf := has_inter.inter set.has_inter, inf_le_left := _, inf_le_right := _, le_inf := _, le_sup_inf := _, sdiff := sdiff set.has_sdiff, bot := ∅, sup_inf_sdiff := _, inf_inf_sdiff := _, compl := set.compl α, top := set.univ α, inf_compl_le_bot := _, top_le_sup_compl := _, le_top := _, bot_le := _, sdiff_eq := _}
set.lt_eq_ssubset
is defined further down
Coercion from a set to the corresponding subtype.
Equations
- set.pi_set_coe.can_lift ι α s = {coe := λ (f : Π (i : ι), α i) (i : ↥s), f ↑i, cond := can_lift.cond (Π (i : ι), α i) (pi_subtype.can_lift ι α s), prf := _}
Equations
- set.pi_set_coe.can_lift' ι α s = set.pi_set_coe.can_lift ι (λ (_x : ι), α) s
Equations
- set.set_coe.can_lift s = {coe := coe coe_to_lift, cond := λ (a : α), a ∈ s, prf := _}
Equations
- set.inhabited = {default := ∅}
Equations
Lemmas about subsets #
Definition of strict subsets s ⊂ t
and basic properties. #
Equations
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.
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 := _}
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.
Equations
- set.univ_decidable = λ (x : α), is_true trivial
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 sets defined as {x ∈ s | p x}
. #
Lemmas about complement #
Lemmas about set difference #
Powerset #
If-then-else for sets #
Inverse image #
Image of a set under a function #
Image is monotone with respect to ⊆
. See set.monotone_image
for the statement in
terms of ≤
.
A variant of image_id
Subsingleton #
A set s
is a subsingleton
, if it has at most one element.
Equations
- s.subsingleton = ∀ ⦃x : α⦄, x ∈ s → ∀ ⦃y : α⦄, y ∈ s → x = y
s
, coerced to a type, is a subsingleton type if and only if s
is a subsingleton set.
The preimage of a subsingleton under an injective map is a subsingleton.
s
is a subsingleton, if its image of an injective function is.
Lemmas about range of a function. #
Alias of range_iff_surjective
.
Equations
- set.set.can_lift = {coe := λ (s : set β), can_lift.coe '' s, cond := λ (s : set α), ∀ (x : α), x ∈ s → can_lift.cond β x, prf := _}
Any map f : ι → β
factors through a map range_factorization f : ι → range f
.
Equations
- set.range_factorization f = λ (i : ι), ⟨f i, _⟩
We can use the axiom of choice to pick a preimage for every element of range f
.
Equations
- set.range_splitting f = λ (x : ↥(set.range f)), Exists.some _
Image and preimage on subtypes #
A variant of range_coe
. Try to use range_coe
if possible.
This version is useful when defining a new type that is defined as the subtype of something.
In that case, the coercion doesn't fire anymore.
Lemmas about inclusion
, the injection of subtypes induced by ⊆
#
Injectivity and surjectivity lemmas for image and preimage #
Lemmas about images of binary and ternary functions #
image2 is monotone with respect to ⊆
.
A common special case of image2_congr
The image of a ternary function f : α → β → γ → δ
as a function
set α → set β → set γ → set δ
. Mathematically this should be thought of as the image of the
corresponding function α × β × γ → δ
.
A common special case of image3_congr