Relations as sets of pairs #
This file provides API to regard relations between α
and β
as sets of pairs Set (α × β)
.
This is in particular useful in the study of uniform spaces, which are topological spaces equipped
with a uniformity, namely a filter of pairs α × α
whose elements can be viewed as "proximity"
relations.
Main declarations #
Rel α β
: Type of relations betweenα
andβ
.Rel.inv
: TurnR : Rel α β
intoR.inv : Rel β α
by swapping the arguments.Rel.dom
: Domain of a relation.a ∈ R.dom
iff there existsb
such thata ~[R] b
.Rel.cod
: Codomain of a relation.b ∈ R.cod
iff there existsa
such thata ~[R] b
.Rel.id
: The identity relationRel α α
.Rel.comp
: Relation composition. Note that the arguments order follows the category theory convention, namely(R ○ S) a c ↔ ∃ b, a ~[R] b ∧ b ~[S] z
.Rel.image
: Image of a set under a relation.b ∈ image R s
iff there existsa ∈ s
such thata ~[R] b
. IfR
is the graph off
(a ~[R] b ↔ f a = b
), thenR.image = Set.image f
.Rel.preimage
: Preimage of a set under a relation.a ∈ preimage R t
iff there existsb ∈ t
such thata ~[R] b
. IfR
is the graph off
(a ~[R] b ↔ f a = b
), thenR.preimage = Set.preimage f
.Rel.core
: Core of a set. Fort : Set β
,a ∈ R.core t
iff allb
related toa
are int
.Rel.restrictDomain
: Domain-restriction of a relation to a subtype.Function.graph
: Graph of a function as a relation.
Implementation notes #
There is tension throughout the library between considering relations between α
and β
simply as
α → β → Prop
, or as a bundled object Rel α β
with dedicated operations and API.
The former approach is used almost everywhere as it is very lightweight and has arguably native support from core Lean features, but it cracks at the seams whenever one starts talking about operations on relations. For example:
- composition of relations
R : α → β → Prop
,S : β → γ → Prop
isRelation.Comp R S := fun a c ↦ ∃ b, R a b ∧ S b c
- map of a relation
R : α → β → Prop
underf : α → γ
,g : β → δ
isRelation.map R f g := fun c d ↦ ∃ a b, r a b ∧ f a = c ∧ g b = d
.
The latter approach is embodied by Rel α β
, with dedicated notation like ○
for composition.
Previously, Rel
suffered from the leakage of its definition as
def Rel (α β : Type*) := α → β → Prop
The fact that Rel
wasn't an abbrev
confuses automation. But simply making it an abbrev
would
have killed the point of having a separate less see-through type to perform relation operations on,
so we instead redefined
def Rel (α β : Type*) := Set (α × β) → Prop
This extra level of indirection guides automation correctly and prevents (some kinds of) leakage.
Simultaneously, uniform spaces need a theory of relations on a type α
as elements of
Set (α × α)
, and the new definition of Rel
fulfills this role quite well.
Alias of Rel.inv_empty
.
Alias of Rel.cod_inv
.
Composition of relation.
Note that this follows the CategoryTheory
order of arguments.
Equations
- Rel.«term_○_» = Lean.ParserDescr.trailingNode `Rel.«term_○_» 62 62 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ○ ") (Lean.ParserDescr.cat `term 63))
Instances For
Alias of Rel.preimage_empty_left
.
A relation R
on a type α
is well-founded if all elements of α
are accessible within R
.
Equations
- R.IsWellFounded = WellFounded fun (x1 x2 : α) => (x1, x2) ∈ R
Instances For
A relation homomorphism with respect to a given pair of relations R
and S
s is a function
f : α → β
such that a ~[R] b → f a ~[s] f b
.