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.domiff there existsbsuch thata ~[R] b.SetRel.cod: Codomain of a relation.b ∈ R.codiff there existsasuch thata ~[R] b.SetRel.id: The identity relationSetRel α α.SetRel.comp: SetRel composition. Note that the arguments order follows the category theory convention, namely(R ○ S) a c ↔ ∃ b, a ~[R] b ∧ b ~[S] c.SetRel.image: Image of a set under a relation.b ∈ image R siff there existsa ∈ ssuch thata ~[R] b. IfRis 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 tiff there existsb ∈ tsuch thata ~[R] b. IfRis 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 tiff allbrelated toaare 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 set of pairs SetRel α β with dedicated operations and API.
The function representation is lightweight and has native support from core Lean features. It is a
good fit when a relation is primarily applied to two arguments. The set-of-pairs representation is
useful when the relation itself is manipulated as a mathematical object, as R is in the examples
below, because the standard Set API applies directly. For example:
- the inverse relation is the preimage
Prod.swap ⁻¹' R; - transporting a relation along
f : α → γandg : β → δis the image(Prod.map f g) '' R; - unions, intersections, complements, and the subset order are inherited from
Set.
These operations can also be defined for α → β → Prop; the advantage of SetRel is reuse of the
existing set API and direct interoperability with objects such as filters on α × α, rather than
additional expressive power. SetRel also provides dedicated relational operations, including the
notation ○ for composition. (Note that ○ is not function 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 it as
abbrev SetRel (α β : Type*) := Set (α × β)
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
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
Reflexive relations #
Symmetric relations #
The maximal symmetric relation contained in a given relation.
Equations
- R.symmetrize = R ∩ R.inv
Instances For
Transitive relations #
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