| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Many properties which hold for `∼` also hold for `flip ∼`. Unlike |
| 5 |
-- the module `Relation.Binary.Construct.Flip.Ord` this module does not |
| 6 |
-- flip the underlying equality. |
| 7 |
------------------------------------------------------------------------ |
| 8 |
|
| 9 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 10 |
|
| 11 |
module Relation.Binary.Construct.Flip.EqAndOrd where |
| 12 |
|
| 13 |
open import Data.Product.Base using (_,_) |
| 14 |
open import Function.Base using (flip; _∘_) |
| 15 |
open import Level using (Level) |
| 16 |
open import Relation.Binary.Core using (Rel; REL; _⇒_) |
| 17 |
open import Relation.Binary.Bundles |
| 18 |
using (Setoid; DecSetoid; Preorder; Poset; TotalOrder; DecTotalOrder |
| 19 |
; StrictPartialOrder; StrictTotalOrder; TotalPreorder) |
| 20 |
open import Relation.Binary.Structures |
| 21 |
using (IsEquivalence; IsDecEquivalence; IsPreorder; IsPartialOrder |
| 22 |
; IsTotalOrder; IsDecTotalOrder; IsStrictPartialOrder |
| 23 |
; IsStrictTotalOrder; IsTotalPreorder) |
| 24 |
open import Relation.Binary.Definitions |
| 25 |
using (Reflexive; Symmetric; Transitive; Asymmetric; Total; _Respects_ |
| 26 |
; _Respects₂_; Minimum; Maximum; Irreflexive; Antisymmetric |
| 27 |
; Trichotomous; Decidable; tri<; tri>; tri≈) |
| 28 |
|
| 29 |
private |
| 30 |
variable |
| 31 |
a b p ℓ ℓ₁ ℓ₂ : Level |
| 32 |
A B : Set a |
| 33 |
≈ ∼ ≤ < : Rel A ℓ |
| 34 |
|
| 35 |
------------------------------------------------------------------------ |
| 36 |
-- Properties |
| 37 |
|
| 38 |
module _ (∼ : Rel A ℓ) where |
| 39 |
|
| 40 |
refl : Reflexive ∼ → Reflexive (flip ∼) |
| 41 |
refl refl = refl |
| 42 |
|
| 43 |
sym : Symmetric ∼ → Symmetric (flip ∼) |
| 44 |
sym sym = sym |
| 45 |
|
| 46 |
trans : Transitive ∼ → Transitive (flip ∼) |
| 47 |
trans trans = flip trans |
| 48 |
|
| 49 |
asym : Asymmetric ∼ → Asymmetric (flip ∼) |
| 50 |
asym asym = asym |
| 51 |
|
| 52 |
total : Total ∼ → Total (flip ∼) |
| 53 |
total total x y = total y x |
| 54 |
|
| 55 |
resp : ∀ {p} (P : A → Set p) → Symmetric ∼ → |
| 56 |
P Respects ∼ → P Respects (flip ∼) |
| 57 |
resp _ sym resp ∼ = resp (sym ∼) |
| 58 |
|
| 59 |
max : ∀ {⊥} → Minimum ∼ ⊥ → Maximum (flip ∼) ⊥ |
| 60 |
max min = min |
| 61 |
|
| 62 |
min : ∀ {⊤} → Maximum ∼ ⊤ → Minimum (flip ∼) ⊤ |
| 63 |
min max = max |
| 64 |
|
| 65 |
module _ {≈ : Rel A ℓ₁} (∼ : Rel A ℓ₂) where |
| 66 |
|
| 67 |
reflexive : Symmetric ≈ → (≈ ⇒ ∼) → (≈ ⇒ flip ∼) |
| 68 |
reflexive sym impl = impl ∘ sym |
| 69 |
|
| 70 |
irrefl : Symmetric ≈ → Irreflexive ≈ ∼ → Irreflexive ≈ (flip ∼) |
| 71 |
irrefl sym irrefl x≈y y∼x = irrefl (sym x≈y) y∼x |
| 72 |
|
| 73 |
antisym : Antisymmetric ≈ ∼ → Antisymmetric ≈ (flip ∼) |
| 74 |
antisym antisym = flip antisym |
| 75 |
|
| 76 |
compare : Trichotomous ≈ ∼ → Trichotomous ≈ (flip ∼) |
| 77 |
compare cmp x y with cmp x y |
| 78 |
... | tri< x<y x≉y y≮x = tri> y≮x x≉y x<y |
| 79 |
... | tri≈ x≮y x≈y y≮x = tri≈ y≮x x≈y x≮y |
| 80 |
... | tri> x≮y x≉y y<x = tri< y<x x≉y x≮y |
| 81 |
|
| 82 |
module _ (∼₁ : Rel A ℓ₁) (∼₂ : Rel A ℓ₂) where |
| 83 |
|
| 84 |
resp₂ : ∼₁ Respects₂ ∼₂ → (flip ∼₁) Respects₂ ∼₂ |
| 85 |
resp₂ (resp₁ , resp₂) = resp₂ , resp₁ |
| 86 |
|
| 87 |
module _ (∼ : REL A B ℓ) where |
| 88 |
|
| 89 |
dec : Decidable ∼ → Decidable (flip ∼) |
| 90 |
dec dec = flip dec |
| 91 |
|
| 92 |
------------------------------------------------------------------------ |
| 93 |
-- Structures |
| 94 |
|
| 95 |
isEquivalence : IsEquivalence ≈ → IsEquivalence (flip ≈) |
| 96 |
isEquivalence {≈ = ≈} eq = record |
| 97 |
{ refl = refl ≈ Eq.refl |
| 98 |
; sym = sym ≈ Eq.sym |
| 99 |
; trans = trans ≈ Eq.trans |
| 100 |
} where module Eq = IsEquivalence eq |
| 101 |
|
| 102 |
isDecEquivalence : IsDecEquivalence ≈ → IsDecEquivalence (flip ≈) |
| 103 |
isDecEquivalence {≈ = ≈} eq = record |
| 104 |
{ isEquivalence = isEquivalence Dec.isEquivalence |
| 105 |
; _≟_ = dec ≈ Dec._≟_ |
| 106 |
} where module Dec = IsDecEquivalence eq |
| 107 |
|
| 108 |
isPreorder : IsPreorder ≈ ∼ → IsPreorder ≈ (flip ∼) |
| 109 |
isPreorder {≈ = ≈} {∼ = ∼} O = record |
| 110 |
{ isEquivalence = O.isEquivalence |
| 111 |
; reflexive = reflexive ∼ O.Eq.sym O.reflexive |
| 112 |
; trans = trans ∼ O.trans |
| 113 |
} where module O = IsPreorder O |
| 114 |
|
| 115 |
isTotalPreorder : IsTotalPreorder ≈ ∼ → IsTotalPreorder ≈ (flip ∼) |
| 116 |
isTotalPreorder O = record |
| 117 |
{ isPreorder = isPreorder O.isPreorder |
| 118 |
; total = total _ O.total |
| 119 |
} where module O = IsTotalPreorder O |
| 120 |
|
| 121 |
isPartialOrder : IsPartialOrder ≈ ≤ → IsPartialOrder ≈ (flip ≤) |
| 122 |
isPartialOrder {≤ = ≤} O = record |
| 123 |
{ isPreorder = isPreorder O.isPreorder |
| 124 |
; antisym = antisym ≤ O.antisym |
| 125 |
} where module O = IsPartialOrder O |
| 126 |
|
| 127 |
isTotalOrder : IsTotalOrder ≈ ≤ → IsTotalOrder ≈ (flip ≤) |
| 128 |
isTotalOrder O = record |
| 129 |
{ isPartialOrder = isPartialOrder O.isPartialOrder |
| 130 |
; total = total _ O.total |
| 131 |
} where module O = IsTotalOrder O |
| 132 |
|
| 133 |
isDecTotalOrder : IsDecTotalOrder ≈ ≤ → IsDecTotalOrder ≈ (flip ≤) |
| 134 |
isDecTotalOrder O = record |
| 135 |
{ isTotalOrder = isTotalOrder O.isTotalOrder |
| 136 |
; _≟_ = O._≟_ |
| 137 |
; _≤?_ = dec _ O._≤?_ |
| 138 |
} where module O = IsDecTotalOrder O |
| 139 |
|
| 140 |
isStrictPartialOrder : IsStrictPartialOrder ≈ < → |
| 141 |
IsStrictPartialOrder ≈ (flip <) |
| 142 |
isStrictPartialOrder {< = <} O = record |
| 143 |
{ isEquivalence = O.isEquivalence |
| 144 |
; irrefl = irrefl < O.Eq.sym O.irrefl |
| 145 |
; trans = trans < O.trans |
| 146 |
; <-resp-≈ = resp₂ _ _ O.<-resp-≈ |
| 147 |
} where module O = IsStrictPartialOrder O |
| 148 |
|
| 149 |
isStrictTotalOrder : IsStrictTotalOrder ≈ < → |
| 150 |
IsStrictTotalOrder ≈ (flip <) |
| 151 |
isStrictTotalOrder {< = <} O = record |
| 152 |
{ isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder |
| 153 |
; compare = compare _ O.compare |
| 154 |
} where module O = IsStrictTotalOrder O |
| 155 |
|
| 156 |
------------------------------------------------------------------------ |
| 157 |
-- Bundles |
| 158 |
|
| 159 |
setoid : Setoid a ℓ → Setoid a ℓ |
| 160 |
setoid S = record |
| 161 |
{ isEquivalence = isEquivalence S.isEquivalence |
| 162 |
} where module S = Setoid S |
| 163 |
|
| 164 |
decSetoid : DecSetoid a ℓ → DecSetoid a ℓ |
| 165 |
decSetoid S = record |
| 166 |
{ isDecEquivalence = isDecEquivalence S.isDecEquivalence |
| 167 |
} where module S = DecSetoid S |
| 168 |
|
| 169 |
preorder : Preorder a ℓ₁ ℓ₂ → Preorder a ℓ₁ ℓ₂ |
| 170 |
preorder O = record |
| 171 |
{ isPreorder = isPreorder O.isPreorder |
| 172 |
} where module O = Preorder O |
| 173 |
|
| 174 |
totalPreorder : TotalPreorder a ℓ₁ ℓ₂ → TotalPreorder a ℓ₁ ℓ₂ |
| 175 |
totalPreorder O = record |
| 176 |
{ isTotalPreorder = isTotalPreorder O.isTotalPreorder |
| 177 |
} where module O = TotalPreorder O |
| 178 |
|
| 179 |
poset : Poset a ℓ₁ ℓ₂ → Poset a ℓ₁ ℓ₂ |
| 180 |
poset O = record |
| 181 |
{ isPartialOrder = isPartialOrder O.isPartialOrder |
| 182 |
} where module O = Poset O |
| 183 |
|
| 184 |
totalOrder : TotalOrder a ℓ₁ ℓ₂ → TotalOrder a ℓ₁ ℓ₂ |
| 185 |
totalOrder O = record |
| 186 |
{ isTotalOrder = isTotalOrder O.isTotalOrder |
| 187 |
} where module O = TotalOrder O |
| 188 |
|
| 189 |
decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ → DecTotalOrder a ℓ₁ ℓ₂ |
| 190 |
decTotalOrder O = record |
| 191 |
{ isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder |
| 192 |
} where module O = DecTotalOrder O |
| 193 |
|
| 194 |
strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ → |
| 195 |
StrictPartialOrder a ℓ₁ ℓ₂ |
| 196 |
strictPartialOrder O = record |
| 197 |
{ isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder |
| 198 |
} where module O = StrictPartialOrder O |
| 199 |
|
| 200 |
strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂ → |
| 201 |
StrictTotalOrder a ℓ₁ ℓ₂ |
| 202 |
strictTotalOrder O = record |
| 203 |
{ isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder |
| 204 |
} where module O = StrictTotalOrder O |