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 #
SetRel α β
: Type of relations betweenα
andβ
.SetRel.inv
: TurnR : SetRel α β
intoR.inv : SetRel β α
by swapping the arguments.SetRel.dom
: Domain of a relation.a ∈ R.dom
iff there existsb
such thata ~[R] b
.SetRel.cod
: Codomain of a relation.b ∈ R.cod
iff there existsa
such thata ~[R] b
.SetRel.id
: The identity relationSetRel α α
.SetRel.comp
: SetRelation composition. Note that the arguments order follows the category theory convention, namely(R ○ S) a c ↔ ∃ b, a ~[R] b ∧ b ~[S] z
.SetRel.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
.SetRel.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
.SetRel.core
: Core of a set. Fort : Set β
,a ∈ R.core t
iff allb
related toa
are int
.SetRel.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 SetRel α β
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
isSetRelation.Comp R S := fun a c ↦ ∃ b, R a b ∧ S b c
- map of a relation
R : α → β → Prop
underf : α → γ
,g : β → δ
isSetRelation.map R f g := fun c d ↦ ∃ a b, r a b ∧ f a = c ∧ g b = d
.
The latter approach is embodied by SetRel α β
, with dedicated notation like ○
for composition.
Previously, SetRel
suffered from the leakage of its definition as
def SetRel (α β : Type*) := α → β → Prop
The fact that SetRel
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 SetRel (α β : 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 SetRel
fulfills this role quite well.
A relation on α
and β
, aka a set-valued function, aka a partial multifunction.
We represent them as sets due to how relations are used in the context of uniform spaces.
Instances For
Notation for apply a relation R : SetRel α β
to a : α
, b : β
,
scoped to the SetRel
namespace.
Since SetRel α β := Set (α × β)
, a ~[R] b
is simply notation for (a, b) ∈ R
, but this should
be considered an implementation detail.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Alias of SetRel.inv_empty
.
Alias of SetRel.cod
.
Codomain of a relation, aka range.
Equations
Instances For
Alias of SetRel.cod_inv
.
Composition of relation.
Note that this follows the CategoryTheory
order of arguments.
Equations
- SetRel.«term_○_» = Lean.ParserDescr.trailingNode `SetRel.«term_○_» 62 62 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ○ ") (Lean.ParserDescr.cat `term 63))
Instances For
Alias of SetRel.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