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 coersion 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:
strict_subset s₁ s₂ : Prop
: the predicates₁ ⊆ s₂
buts₁ ≠ s₂
.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 := _, top := set.univ α, le_top := _, bot := ∅, bot_le := _, compl := set.compl α, sdiff := has_sdiff.sdiff set.has_sdiff, inf_compl_le_bot := _, top_le_sup_compl := _, sdiff_eq := _}
Coercion from a set to the corresponding subtype.
Equations
- set.inhabited = {default := ∅}
Lemmas about mem
and set_of
Equations
- s.decidable_mem = H
Equations
Lemmas about subsets
Definition of strict subsets s ⊂ t
and basic properties.
Equations
Non-empty sets
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
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 : α), decidable.is_true trivial
diagonal α
is the subset of α × α
consisting of all pairs of the form (a, a)
.
Lemmas about union
Equations
Equations
Lemmas about intersection
Equations
Equations
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
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
Lemmas about range of a function.
Any map f : ι → β
factors through a map range_factorization f : ι → range f
.
Equations
- set.range_factorization f = λ (i : ι), ⟨f i, _⟩
The range of a function from a unique
type contains just the
function applied to its single value.
The set s
is pairwise r
if r x y
for all distinct x y ∈ s
.
Equations
- s.pairwise_on r = ∀ (x : α), x ∈ s → ∀ (y : α), y ∈ s → x ≠ y → r x y
If and only if f
takes pairwise equal values on s
, there is
some value it takes everywhere on s
.
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 cartesian product of sets
Lemmas about set-indexed products of sets
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