Documentation

CslibFrontier.Foundations.Data.Option.Rel

Relating optional values #

Option.Rel r o₁ o₂ lifts a relation to optional values: both are none, or both are some with related contents. Core states only its four constructor cases. This module adds that it inherits reflexivity, symmetry and transitivity from r, is monotone in r, reduces to equality for r = (· = ·), and is preserved by Option.bind with related continuations. Observing a computation that may fail as an Option and relating results up to r uses exactly these facts.

Main results #

theorem Option.rel_refl {α : Type u_1} {r : α → α → Prop} (hr : ∀ (a : α), r a a) (o : Option α) :
Rel r o o
theorem Option.Rel.symm {α : Type u_1} {r : α → α → Prop} (hr : ∀ (a b : α), r a b → r b a) {o₁ o₂ : Option α} (h : Rel r o₁ o₂) :
Rel r o₂ o₁
theorem Option.Rel.trans {α : Type u_1} {r : α → α → Prop} (hr : ∀ (a b c : α), r a b → r b c → r a c) {o₁ o₂ o₃ : Option α} (h₁₂ : Rel r o₁ o₂) (h₂₃ : Rel r o₂ o₃) :
Rel r o₁ o₃
theorem Option.Rel.mono {α : Type u_1} {β : Type u_2} {r s : α → β → Prop} (hrs : ∀ (a : α) (b : β), r a b → s a b) {o₁ : Option α} {o₂ : Option β} (h : Rel r o₁ o₂) :
Rel s o₁ o₂
@[simp]
theorem Option.rel_eq_iff {α : Type u_1} {o₁ o₂ : Option α} :
Rel (fun (x1 x2 : α) => x1 = x2) o₁ o₂ ↔ o₁ = o₂
theorem Option.Rel.bind {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {r : α → β → Prop} {s : γ → δ → Prop} {o₁ : Option α} {o₂ : Option β} (h : Rel r o₁ o₂) {f : α → Option γ} {g : β → Option δ} (hfg : ∀ (a : α) (b : β), r a b → Rel s (f a) (g b)) :
Rel s (o₁.bind f) (o₂.bind g)

Binding related values to continuations that take related arguments to related results gives related results.