logic.relation

# Relation closures #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

This file defines the reflexive, transitive, and reflexive transitive closures of relations. It also proves some basic results on definitions in core, such as eqv_gen.

Note that this is about unbundled relations, that is terms of types of the form α → β → Prop. For the bundled version, see rel.

## Definitions #

• relation.refl_gen: Reflexive closure. refl_gen r relates everything r related, plus for all a it relates a with itself. So refl_gen r a b ↔ r a b ∨ a = b.
• relation.trans_gen: Transitive closure. trans_gen r relates everything r related transitively. So trans_gen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b.
• relation.refl_trans_gen: Reflexive transitive closure. refl_trans_gen r relates everything r related transitively, plus for all a it relates a with itself. So refl_trans_gen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b. It is the same as the reflexive closure of the transitive closure, or the transitive closure of the reflexive closure. In terms of rewriting systems, this means that a can be rewritten to b in a number of rewrites.
• relation.comp: Relation composition. We provide notation ∘r. For r : α → β → Prop and s : β → γ → Prop, r ∘r srelates a : α and c : γ iff there exists b : β that's related to both.
• relation.map: Image of a relation under a pair of maps. For r : α → β → Prop, f : α → γ, g : β → δ, map r f g is the relation γ → δ → Prop relating f a and g b for all a, b related by r.
• relation.join: Join of a relation. For r : α → α → Prop, join r a b ↔ ∃ c, r a c ∧ r b c. In terms of rewriting systems, this means that a and b can be rewritten to the same term.
theorem is_refl.reflexive {α : Type u_1} {r : α α Prop} [ r] :
theorem reflexive.rel_of_ne_imp {α : Type u_1} {r : α α Prop} (h : reflexive r) {x y : α} (hr : x y r x y) :
r x y

To show a reflexive relation r : α → α → Prop holds over x y : α, it suffices to show it holds when x ≠ y.

theorem reflexive.ne_imp_iff {α : Type u_1} {r : α α Prop} (h : reflexive r) {x y : α} :
x y r x y r x y

If a reflexive relation r : α → α → Prop holds over x y : α, then it holds whether or not x ≠ y.

theorem reflexive_ne_imp_iff {α : Type u_1} {r : α α Prop} [ r] {x y : α} :
x y r x y r x y

If a reflexive relation r : α → α → Prop holds over x y : α, then it holds whether or not x ≠ y. Unlike reflexive.ne_imp_iff, this uses [is_refl α r].

@[protected]
theorem symmetric.iff {α : Type u_1} {r : α α Prop} (H : symmetric r) (x y : α) :
r x y r y x
theorem symmetric.flip_eq {α : Type u_1} {r : α α Prop} (h : symmetric r) :
flip r = r
theorem symmetric.swap_eq {α : Type u_1} {r : α α Prop} :
theorem flip_eq_iff {α : Type u_1} {r : α α Prop} :
flip r = r
theorem swap_eq_iff {α : Type u_1} {r : α α Prop} :
theorem reflexive.comap {α : Type u_1} {β : Type u_2} {r : β β Prop} (h : reflexive r) (f : α β) :
theorem symmetric.comap {α : Type u_1} {β : Type u_2} {r : β β Prop} (h : symmetric r) (f : α β) :
theorem transitive.comap {α : Type u_1} {β : Type u_2} {r : β β Prop} (h : transitive r) (f : α β) :
theorem equivalence.comap {α : Type u_1} {β : Type u_2} {r : β β Prop} (h : equivalence r) (f : α β) :
def relation.comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} (r : α β Prop) (p : β γ Prop) (a : α) (c : γ) :
Prop

The composition of two relations, yielding a new relation. The result relates a term of α and a term of γ if there is an intermediate term of β related to both.

Equations
theorem relation.comp_eq {α : Type u_1} {β : Type u_2} {r : α β Prop} :
= r
theorem relation.eq_comp {α : Type u_1} {β : Type u_2} {r : α β Prop} :
= r
theorem relation.iff_comp {α : Type u_1} {r : Prop α Prop} :
theorem relation.comp_iff {α : Type u_1} {r : α Prop Prop} :
theorem relation.comp_assoc {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {r : α β Prop} {p : β γ Prop} {q : γ δ Prop} :
q = q)
theorem relation.flip_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} {r : α β Prop} {p : β γ Prop} :
flip p) = (flip r)
def relation.fibration {α : Type u_1} {β : Type u_2} (rα : α α Prop) (rβ : β β Prop) (f : α β) :
Prop

A function f : α → β is a fibration between the relation rα and rβ if for all a : α and b : β, whenever b : β and f a are related by rβ, b is the image of some a' : α under f, and a' and a are related by rα.

Equations
• f = ⦃a : α⦄ ⦃b : β⦄, rβ b (f a) ( (a' : α), rα a' a f a' = b)
theorem acc.of_fibration {α : Type u_1} {β : Type u_2} {rα : α α Prop} {rβ : β β Prop} (f : α β) (fib : f) {a : α} (ha : acc a) :
acc (f a)

If f : α → β is a fibration between relations rα and rβ, and a : α is accessible under rα, then f a is accessible under rβ.

theorem acc.of_downward_closed {α : Type u_1} {β : Type u_2} {rβ : β β Prop} (f : α β) (dc : {a : α} {b : β}, rβ b (f a) ( (c : α), f c = b)) (a : α) (ha : acc (inv_image f) a) :
acc (f a)
@[protected]
def relation.map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} (r : α β Prop) (f : α γ) (g : β δ) :
γ δ Prop

The map of a relation r through a pair of functions pushes the relation to the codomains of the functions. The resulting relation is defined by having pairs of terms related if they have preimages related by r.

Equations
• f g = λ (c : γ) (d : δ), (a : α) (b : β), r a b f a = c g b = d
Instances for relation.map
theorem relation.map_apply {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {r : α β Prop} {f : α γ} {g : β δ} {c : γ} {d : δ} :
f g c d (a : α) (b : β), r a b f a = c g b = d
@[simp]
theorem relation.map_id_id {α : Type u_1} {β : Type u_2} (r : α β Prop) :
= r
@[simp]
theorem relation.map_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {ε : Type u_5} {κ : Type u_6} (r : α β Prop) (f₁ : α γ) (g₁ : β δ) (f₂ : γ ε) (g₂ : δ κ) :
relation.map f₁ g₁) f₂ g₂ = (f₂ f₁) (g₂ g₁)
@[protected, instance]
def relation.map.decidable {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {r : α β Prop} {f : α γ} {g : β δ} {c : γ} {d : δ} [decidable ( (a : α) (b : β), r a b f a = c g b = d)] :
decidable f g c d)
Equations
inductive relation.refl_trans_gen {α : Type u_1} (r : α α Prop) (a : α) :
α Prop

refl_trans_gen r: reflexive transitive closure of r

Instances for relation.refl_trans_gen
theorem relation.refl_trans_gen.cases_tail_iff {α : Type u_1} (r : α α Prop) (a ᾰ : α) :
= a {b : α}, r b
inductive relation.refl_gen {α : Type u_1} (r : α α Prop) (a : α) :
α Prop

refl_gen r: reflexive closure of r

Instances for relation.refl_gen
theorem relation.refl_gen_iff {α : Type u_1} (r : α α Prop) (a ᾰ : α) :
= a r a
inductive relation.trans_gen {α : Type u_1} (r : α α Prop) (a : α) :
α Prop

trans_gen r: transitive closure of r

Instances for relation.trans_gen
theorem relation.trans_gen_iff {α : Type u_1} (r : α α Prop) (a ᾰ : α) :
r a {b : α}, b r b
theorem relation.refl_gen.to_refl_trans_gen {α : Type u_1} {r : α α Prop} {a b : α} :
b
theorem relation.refl_gen.mono {α : Type u_1} {r p : α α Prop} (hp : (a b : α), r a b p a b) {a b : α} :
b b
@[protected, instance]
def relation.refl_gen.is_refl {α : Type u_1} {r : α α Prop} :
@[trans]
theorem relation.refl_trans_gen.trans {α : Type u_1} {r : α α Prop} {a b c : α} (hab : b) (hbc : c) :
theorem relation.refl_trans_gen.single {α : Type u_1} {r : α α Prop} {a b : α} (hab : r a b) :
theorem relation.refl_trans_gen.head {α : Type u_1} {r : α α Prop} {a b c : α} (hab : r a b) (hbc : c) :
theorem relation.refl_trans_gen.symmetric {α : Type u_1} {r : α α Prop} (h : symmetric r) :
theorem relation.refl_trans_gen.cases_tail {α : Type u_1} {r : α α Prop} {a b : α} :
(b = a (c : α), r c b)
theorem relation.refl_trans_gen.head_induction_on {α : Type u_1} {r : α α Prop} {b : α} {P : Π (a : α), Prop} {a : α} (h : b) (refl : P b relation.refl_trans_gen.refl) (head : {a c : α} (h' : r a c) (h : b), P c h P a _) :
P a h
theorem relation.refl_trans_gen.trans_induction_on {α : Type u_1} {r : α α Prop} {P : Π {a b : α}, Prop} {a b : α} (h : b) (ih₁ : (a : α), ) (ih₂ : {a b : α} (h : r a b), P _) (ih₃ : {a b c : α} (h₁ : b) (h₂ : c), P h₁ P h₂ P _) :
P h
theorem relation.refl_trans_gen.cases_head {α : Type u_1} {r : α α Prop} {a b : α} (h : b) :
a = b (c : α), r a c
theorem relation.refl_trans_gen.cases_head_iff {α : Type u_1} {r : α α Prop} {a b : α} :
a = b (c : α), r a c
theorem relation.refl_trans_gen.total_of_right_unique {α : Type u_1} {r : α α Prop} {a b c : α} (U : relator.right_unique r) (ab : b) (ac : c) :
theorem relation.trans_gen.to_refl {α : Type u_1} {r : α α Prop} {a b : α} (h : b) :
@[trans]
theorem relation.trans_gen.trans_left {α : Type u_1} {r : α α Prop} {a b c : α} (hab : b) (hbc : c) :
c
@[trans]
theorem relation.trans_gen.trans {α : Type u_1} {r : α α Prop} {a b c : α} (hab : b) (hbc : c) :
c
theorem relation.trans_gen.head' {α : Type u_1} {r : α α Prop} {a b c : α} (hab : r a b) (hbc : c) :
c
theorem relation.trans_gen.tail' {α : Type u_1} {r : α α Prop} {a b c : α} (hab : b) (hbc : r b c) :
c
theorem relation.trans_gen.head {α : Type u_1} {r : α α Prop} {a b c : α} (hab : r a b) (hbc : c) :
c
theorem relation.trans_gen.head_induction_on {α : Type u_1} {r : α α Prop} {b : α} {P : Π (a : α), b Prop} {a : α} (h : b) (base : {a : α} (h : r a b), P a _) (ih : {a c : α} (h' : r a c) (h : b), P c h P a _) :
P a h
theorem relation.trans_gen.trans_induction_on {α : Type u_1} {r : α α Prop} {P : Π {a b : α}, b Prop} {a b : α} (h : b) (base : {a b : α} (h : r a b), P _) (ih : {a b c : α} (h₁ : b) (h₂ : c), P h₁ P h₂ P _) :
P h
@[trans]
theorem relation.trans_gen.trans_right {α : Type u_1} {r : α α Prop} {a b c : α} (hab : b) (hbc : c) :
c
theorem relation.trans_gen.tail'_iff {α : Type u_1} {r : α α Prop} {a c : α} :
c (b : α), r b c
theorem relation.trans_gen.head'_iff {α : Type u_1} {r : α α Prop} {a c : α} :
c (b : α), r a b
theorem acc.trans_gen {α : Type u_1} {r : α α Prop} {a : α} (h : acc r a) :
a
theorem acc_trans_gen_iff {α : Type u_1} {r : α α Prop} {a : α} :
a acc r a
theorem well_founded.trans_gen {α : Type u_1} {r : α α Prop} (h : well_founded r) :
theorem relation.trans_gen_eq_self {α : Type u_1} {r : α α Prop} (trans : transitive r) :
theorem relation.transitive_trans_gen {α : Type u_1} {r : α α Prop} :
@[protected, instance]
def relation.trans_gen.is_trans {α : Type u_1} {r : α α Prop} :
theorem relation.trans_gen_idem {α : Type u_1} {r : α α Prop} :
theorem relation.trans_gen.lift {α : Type u_1} {β : Type u_2} {r : α α Prop} {p : β β Prop} {a b : α} (f : α β) (h : (a b : α), r a b p (f a) (f b)) (hab : b) :
(f a) (f b)
theorem relation.trans_gen.lift' {α : Type u_1} {β : Type u_2} {r : α α Prop} {p : β β Prop} {a b : α} (f : α β) (h : (a b : α), r a b (f a) (f b)) (hab : b) :
(f a) (f b)
theorem relation.trans_gen.closed {α : Type u_1} {r : α α Prop} {a b : α} {p : α α Prop} :
( (a b : α), r a b b) b b
theorem relation.trans_gen.mono {α : Type u_1} {r : α α Prop} {a b : α} {p : α α Prop} :
( (a b : α), r a b p a b) b b
theorem relation.trans_gen.swap {α : Type u_1} {r : α α Prop} {a b : α} (h : a) :
b
theorem relation.trans_gen_swap {α : Type u_1} {r : α α Prop} {a b : α} :
b a
theorem relation.refl_trans_gen_iff_eq {α : Type u_1} {r : α α Prop} {a b : α} (h : (b : α), ¬r a b) :
b = a
theorem relation.refl_trans_gen_iff_eq_or_trans_gen {α : Type u_1} {r : α α Prop} {a b : α} :
b = a b
theorem relation.refl_trans_gen.lift {α : Type u_1} {β : Type u_2} {r : α α Prop} {p : β β Prop} {a b : α} (f : α β) (h : (a b : α), r a b p (f a) (f b)) (hab : b) :
(f a) (f b)
theorem relation.refl_trans_gen.mono {α : Type u_1} {r : α α Prop} {a b : α} {p : α α Prop} :
( (a b : α), r a b p a b)
theorem relation.refl_trans_gen_eq_self {α : Type u_1} {r : α α Prop} (refl : reflexive r) (trans : transitive r) :
theorem relation.reflexive_refl_trans_gen {α : Type u_1} {r : α α Prop} :
theorem relation.transitive_refl_trans_gen {α : Type u_1} {r : α α Prop} :
@[protected, instance]
def relation.refl_trans_gen.is_refl {α : Type u_1} {r : α α Prop} :
@[protected, instance]
def relation.refl_trans_gen.is_trans {α : Type u_1} {r : α α Prop} :
theorem relation.refl_trans_gen_idem {α : Type u_1} {r : α α Prop} :
theorem relation.refl_trans_gen.lift' {α : Type u_1} {β : Type u_2} {r : α α Prop} {p : β β Prop} {a b : α} (f : α β) (h : (a b : α), r a b (f a) (f b)) (hab : b) :
(f a) (f b)
theorem relation.refl_trans_gen_closed {α : Type u_1} {r : α α Prop} {a b : α} {p : α α Prop} :
( (a b : α), r a b b)
theorem relation.refl_trans_gen.swap {α : Type u_1} {r : α α Prop} {a b : α} (h : a) :
theorem relation.refl_trans_gen_swap {α : Type u_1} {r : α α Prop} {a b : α} :
def relation.join {α : Type u_1} (r : α α Prop) :
α α Prop

The join of a relation on a single type is a new relation for which pairs of terms are related if there is a third term they are both related to. For example, if r is a relation representing rewrites in a term rewriting system, then confluence is the property that if a rewrites to both b and c, then join r relates b and c (see relation.church_rosser).

Equations
• = λ (a b : α), (c : α), r a c r b c
theorem relation.church_rosser {α : Type u_1} {r : α α Prop} {a b c : α} (h : (a b c : α), r a b r a c ( (d : α), d d)) (hab : b) (hac : c) :

A sufficient condition for the Church-Rosser property.

theorem relation.join_of_single {α : Type u_1} {r : α α Prop} {a b : α} (h : reflexive r) (hab : r a b) :
b
theorem relation.symmetric_join {α : Type u_1} {r : α α Prop} :
theorem relation.reflexive_join {α : Type u_1} {r : α α Prop} (h : reflexive r) :
theorem relation.transitive_join {α : Type u_1} {r : α α Prop} (ht : transitive r) (h : (a b c : α), r a b r a c c) :
theorem relation.equivalence_join {α : Type u_1} {r : α α Prop} (hr : reflexive r) (ht : transitive r) (h : (a b c : α), r a b r a c c) :
theorem relation.equivalence_join_refl_trans_gen {α : Type u_1} {r : α α Prop} (h : (a b c : α), r a b r a c ( (d : α), d d)) :
theorem relation.join_of_equivalence {α : Type u_1} {r : α α Prop} {a b : α} {r' : α α Prop} (hr : equivalence r) (h : (a b : α), r' a b r a b) :
a b r a b
theorem relation.refl_trans_gen_of_transitive_reflexive {α : Type u_1} {r : α α Prop} {a b : α} {r' : α α Prop} (hr : reflexive r) (ht : transitive r) (h : (a b : α), r' a b r a b) (h' : b) :
r a b
theorem relation.refl_trans_gen_of_equivalence {α : Type u_1} {r : α α Prop} {a b : α} {r' : α α Prop} (hr : equivalence r) :
( (a b : α), r' a b r a b) b r a b
theorem equivalence.eqv_gen_iff {α : Type u_1} {r : α α Prop} {a b : α} (h : equivalence r) :
a b r a b
theorem equivalence.eqv_gen_eq {α : Type u_1} {r : α α Prop} (h : equivalence r) :
= r
theorem eqv_gen.mono {α : Type u_1} {a b : α} {r p : α α Prop} (hrp : (a b : α), r a b p a b) (h : a b) :
a b