1
------------------------------------------------------------------------
3
------------------------------------------------------------------------
5
{-# OPTIONS --universe-polymorphism #-}
7
module Function.LeftInverse where
9
open import Data.Product
11
import Relation.Binary.EqReasoning as EqReasoning
12
open import Relation.Binary
13
open import Function.Equality as F
14
using (_⟶_; _⟨$⟩_) renaming (_∘_ to _⟪∘⟫_)
15
open import Function.Equivalence using (Equivalent)
16
open import Function.Injection using (Injective; Injection)
18
-- Left and right inverses.
21
∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
22
To ⟶ From → From ⟶ To → Set _
23
_LeftInverseOf_ {From = From} f g = ∀ x → f ⟨$⟩ (g ⟨$⟩ x) ≈ x
24
where open Setoid From
27
∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
28
To ⟶ From → From ⟶ To → Set _
29
f RightInverseOf g = g LeftInverseOf f
31
-- The set of all left inverses between two setoids.
33
record LeftInverse {f₁ f₂ t₁ t₂}
34
(From : Setoid f₁ f₂) (To : Setoid t₁ t₂) :
35
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
39
left-inverse-of : from LeftInverseOf to
44
injective : Injective to
45
injective {x} {y} eq = begin
46
x ≈⟨ sym (left-inverse-of x) ⟩
47
from ⟨$⟩ (to ⟨$⟩ x) ≈⟨ F.cong from eq ⟩
48
from ⟨$⟩ (to ⟨$⟩ y) ≈⟨ left-inverse-of y ⟩
51
injection : Injection From To
52
injection = record { to = to; injective = injective }
54
equivalent : Equivalent From To
60
-- The set of all right inverses between two setoids.
62
RightInverse : ∀ {f₁ f₂ t₁ t₂}
63
(From : Setoid f₁ f₂) (To : Setoid t₁ t₂) → Set _
64
RightInverse From To = LeftInverse To From
66
-- Identity and composition.
68
id : ∀ {s₁ s₂} {S : Setoid s₁ s₂} → LeftInverse S S
72
; left-inverse-of = λ _ → Setoid.refl S
77
_∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂}
78
{F : Setoid f₁ f₂} {M : Setoid m₁ m₂} {T : Setoid t₁ t₂} →
79
LeftInverse M T → LeftInverse F M → LeftInverse F T
80
_∘_ {F = F} f g = record
82
; from = from g ⟪∘⟫ from f
83
; left-inverse-of = λ x → begin
84
from g ⟨$⟩ (from f ⟨$⟩ (to f ⟨$⟩ (to g ⟨$⟩ x))) ≈⟨ F.cong (from g) (left-inverse-of f (to g ⟨$⟩ x)) ⟩
85
from g ⟨$⟩ (to g ⟨$⟩ x) ≈⟨ left-inverse-of g x ⟩