| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Conversion of binary operators to binary relations via the left |
| 5 |
-- natural order. |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Algebra.Core using (Op₂) |
| 11 |
open import Relation.Binary.Core using (Rel; _⇒_) |
| 12 |
|
| 13 |
module Relation.Binary.Construct.NaturalOrder.Left |
| 14 |
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) (_∙_ : Op₂ A) where |
| 15 |
|
| 16 |
open import Data.Product.Base using (_,_; _×_) |
| 17 |
open import Data.Sum.Base using (inj₁; inj₂; map) |
| 18 |
open import Relation.Binary.Bundles |
| 19 |
using (Preorder; Poset; DecPoset; TotalOrder; DecTotalOrder) |
| 20 |
open import Relation.Binary.Structures |
| 21 |
using (IsEquivalence; IsPreorder; IsPartialOrder; IsDecPartialOrder |
| 22 |
; IsTotalOrder; IsDecTotalOrder) |
| 23 |
open import Relation.Binary.Definitions |
| 24 |
using (Symmetric; Transitive; Reflexive; Antisymmetric; Total; _Respectsʳ_ |
| 25 |
; _Respectsˡ_; _Respects₂_; Decidable) |
| 26 |
open import Relation.Nullary.Negation using (¬_) |
| 27 |
import Relation.Binary.Reasoning.Setoid as ≈-Reasoning |
| 28 |
open import Relation.Binary.Lattice using (Infimum) |
| 29 |
|
| 30 |
open import Algebra.Definitions _≈_ |
| 31 |
open import Algebra.Structures _≈_ |
| 32 |
open import Algebra.Lattice.Structures _≈_ |
| 33 |
|
| 34 |
------------------------------------------------------------------------ |
| 35 |
-- Definition |
| 36 |
|
| 37 |
infix 4 _≤_ |
| 38 |
|
| 39 |
_≤_ : Rel A ℓ |
| 40 |
x ≤ y = x ≈ (x ∙ y) |
| 41 |
|
| 42 |
------------------------------------------------------------------------ |
| 43 |
-- Relational properties |
| 44 |
|
| 45 |
reflexive : IsMagma _∙_ → Idempotent _∙_ → _≈_ ⇒ _≤_ |
| 46 |
reflexive magma idem {x} {y} x≈y = begin |
| 47 |
x ≈⟨ sym (idem x) ⟩ |
| 48 |
x ∙ x ≈⟨ ∙-cong refl x≈y ⟩ |
| 49 |
x ∙ y ∎ |
| 50 |
where open IsMagma magma; open ≈-Reasoning setoid |
| 51 |
|
| 52 |
refl : Symmetric _≈_ → Idempotent _∙_ → Reflexive _≤_ |
| 53 |
refl sym idem {x} = sym (idem x) |
| 54 |
|
| 55 |
antisym : IsEquivalence _≈_ → Commutative _∙_ → Antisymmetric _≈_ _≤_ |
| 56 |
antisym isEq comm {x} {y} x≤y y≤x = begin |
| 57 |
x ≈⟨ x≤y ⟩ |
| 58 |
x ∙ y ≈⟨ comm x y ⟩ |
| 59 |
y ∙ x ≈⟨ sym y≤x ⟩ |
| 60 |
y ∎ |
| 61 |
where open IsEquivalence isEq; open ≈-Reasoning (record { isEquivalence = isEq }) |
| 62 |
|
| 63 |
total : Symmetric _≈_ → Transitive _≈_ → Selective _∙_ → Commutative _∙_ → Total _≤_ |
| 64 |
total sym trans sel comm x y = map sym (λ x∙y≈y → trans (sym x∙y≈y) (comm x y)) (sel x y) |
| 65 |
|
| 66 |
trans : IsSemigroup _∙_ → Transitive _≤_ |
| 67 |
trans semi {x} {y} {z} x≤y y≤z = begin |
| 68 |
x ≈⟨ x≤y ⟩ |
| 69 |
x ∙ y ≈⟨ ∙-cong S.refl y≤z ⟩ |
| 70 |
x ∙ (y ∙ z) ≈⟨ sym (assoc x y z) ⟩ |
| 71 |
(x ∙ y) ∙ z ≈⟨ ∙-cong (sym x≤y) S.refl ⟩ |
| 72 |
x ∙ z ∎ |
| 73 |
where open module S = IsSemigroup semi; open ≈-Reasoning S.setoid |
| 74 |
|
| 75 |
respʳ : IsMagma _∙_ → _≤_ Respectsʳ _≈_ |
| 76 |
respʳ magma {x} {y} {z} y≈z x≤y = begin |
| 77 |
x ≈⟨ x≤y ⟩ |
| 78 |
x ∙ y ≈⟨ ∙-cong M.refl y≈z ⟩ |
| 79 |
x ∙ z ∎ |
| 80 |
where open module M = IsMagma magma; open ≈-Reasoning M.setoid |
| 81 |
|
| 82 |
respˡ : IsMagma _∙_ → _≤_ Respectsˡ _≈_ |
| 83 |
respˡ magma {x} {y} {z} y≈z y≤x = begin |
| 84 |
z ≈⟨ sym y≈z ⟩ |
| 85 |
y ≈⟨ y≤x ⟩ |
| 86 |
y ∙ x ≈⟨ ∙-cong y≈z M.refl ⟩ |
| 87 |
z ∙ x ∎ |
| 88 |
where open module M = IsMagma magma; open ≈-Reasoning M.setoid |
| 89 |
|
| 90 |
resp₂ : IsMagma _∙_ → _≤_ Respects₂ _≈_ |
| 91 |
resp₂ magma = respʳ magma , respˡ magma |
| 92 |
|
| 93 |
dec : Decidable _≈_ → Decidable _≤_ |
| 94 |
dec _≟_ x y = x ≟ (x ∙ y) |
| 95 |
|
| 96 |
module _ (semi : IsSemilattice _∙_) where |
| 97 |
|
| 98 |
private open module S = IsSemilattice semi |
| 99 |
open ≈-Reasoning setoid |
| 100 |
|
| 101 |
x∙y≤x : ∀ x y → (x ∙ y) ≤ x |
| 102 |
x∙y≤x x y = begin |
| 103 |
x ∙ y ≈⟨ ∙-cong (sym (idem x)) S.refl ⟩ |
| 104 |
(x ∙ x) ∙ y ≈⟨ assoc x x y ⟩ |
| 105 |
x ∙ (x ∙ y) ≈⟨ comm x (x ∙ y) ⟩ |
| 106 |
(x ∙ y) ∙ x ∎ |
| 107 |
|
| 108 |
x∙y≤y : ∀ x y → (x ∙ y) ≤ y |
| 109 |
x∙y≤y x y = begin |
| 110 |
x ∙ y ≈⟨ ∙-cong S.refl (sym (idem y)) ⟩ |
| 111 |
x ∙ (y ∙ y) ≈⟨ sym (assoc x y y) ⟩ |
| 112 |
(x ∙ y) ∙ y ∎ |
| 113 |
|
| 114 |
∙-presʳ-≤ : ∀ {x y} z → z ≤ x → z ≤ y → z ≤ (x ∙ y) |
| 115 |
∙-presʳ-≤ {x} {y} z z≤x z≤y = begin |
| 116 |
z ≈⟨ z≤y ⟩ |
| 117 |
z ∙ y ≈⟨ ∙-cong z≤x S.refl ⟩ |
| 118 |
(z ∙ x) ∙ y ≈⟨ assoc z x y ⟩ |
| 119 |
z ∙ (x ∙ y) ∎ |
| 120 |
|
| 121 |
infimum : Infimum _≤_ _∙_ |
| 122 |
infimum x y = x∙y≤x x y , x∙y≤y x y , ∙-presʳ-≤ |
| 123 |
|
| 124 |
------------------------------------------------------------------------ |
| 125 |
-- Structures |
| 126 |
|
| 127 |
isPreorder : IsBand _∙_ → IsPreorder _≈_ _≤_ |
| 128 |
isPreorder band = record |
| 129 |
{ isEquivalence = isEquivalence |
| 130 |
; reflexive = reflexive isMagma idem |
| 131 |
; trans = trans isSemigroup |
| 132 |
} |
| 133 |
where open IsBand band hiding (reflexive; trans) |
| 134 |
|
| 135 |
isPartialOrder : IsSemilattice _∙_ → IsPartialOrder _≈_ _≤_ |
| 136 |
isPartialOrder semilattice = record |
| 137 |
{ isPreorder = isPreorder isBand |
| 138 |
; antisym = antisym isEquivalence comm |
| 139 |
} |
| 140 |
where open IsSemilattice semilattice |
| 141 |
|
| 142 |
isDecPartialOrder : IsSemilattice _∙_ → Decidable _≈_ → |
| 143 |
IsDecPartialOrder _≈_ _≤_ |
| 144 |
isDecPartialOrder semilattice _≟_ = record |
| 145 |
{ isPartialOrder = isPartialOrder semilattice |
| 146 |
; _≟_ = _≟_ |
| 147 |
; _≤?_ = dec _≟_ |
| 148 |
} |
| 149 |
|
| 150 |
isTotalOrder : IsSemilattice _∙_ → Selective _∙_ → IsTotalOrder _≈_ _≤_ |
| 151 |
isTotalOrder latt sel = record |
| 152 |
{ isPartialOrder = isPartialOrder latt |
| 153 |
; total = total sym S.trans sel comm |
| 154 |
} |
| 155 |
where open module S = IsSemilattice latt |
| 156 |
|
| 157 |
isDecTotalOrder : IsSemilattice _∙_ → Selective _∙_ → |
| 158 |
Decidable _≈_ → IsDecTotalOrder _≈_ _≤_ |
| 159 |
isDecTotalOrder latt sel _≟_ = record |
| 160 |
{ isTotalOrder = isTotalOrder latt sel |
| 161 |
; _≟_ = _≟_ |
| 162 |
; _≤?_ = dec _≟_ |
| 163 |
} |
| 164 |
|
| 165 |
------------------------------------------------------------------------ |
| 166 |
-- Bundles |
| 167 |
|
| 168 |
preorder : IsBand _∙_ → Preorder a ℓ ℓ |
| 169 |
preorder band = record |
| 170 |
{ isPreorder = isPreorder band |
| 171 |
} |
| 172 |
|
| 173 |
poset : IsSemilattice _∙_ → Poset a ℓ ℓ |
| 174 |
poset latt = record |
| 175 |
{ isPartialOrder = isPartialOrder latt |
| 176 |
} |
| 177 |
|
| 178 |
decPoset : IsSemilattice _∙_ → Decidable _≈_ → DecPoset a ℓ ℓ |
| 179 |
decPoset latt dec = record |
| 180 |
{ isDecPartialOrder = isDecPartialOrder latt dec |
| 181 |
} |
| 182 |
|
| 183 |
totalOrder : IsSemilattice _∙_ → Selective _∙_ → TotalOrder a ℓ ℓ |
| 184 |
totalOrder latt sel = record |
| 185 |
{ isTotalOrder = isTotalOrder latt sel |
| 186 |
} |
| 187 |
|
| 188 |
decTotalOrder : IsSemilattice _∙_ → Selective _∙_ → |
| 189 |
Decidable _≈_ → DecTotalOrder a ℓ ℓ |
| 190 |
decTotalOrder latt sel dec = record |
| 191 |
{ isDecTotalOrder = isDecTotalOrder latt sel dec |
| 192 |
} |