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