| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- The lifting of a non-strict order to incorporate a new infimum |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
-- This module is designed to be used with |
| 10 |
-- Relation.Nullary.Construct.Add.Infimum |
| 11 |
|
| 12 |
open import Relation.Binary.Core using (Rel; _⇒_) |
| 13 |
|
| 14 |
|
| 15 |
module Relation.Binary.Construct.Add.Infimum.NonStrict |
| 16 |
{a ℓ} {A : Set a} (_≤_ : Rel A ℓ) where |
| 17 |
|
| 18 |
open import Level using (_⊔_) |
| 19 |
open import Data.Sum.Base as Sum using (inj₁; inj₂) |
| 20 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; cong) |
| 21 |
import Relation.Binary.PropositionalEquality.Properties as ≡ |
| 22 |
using (isEquivalence) |
| 23 |
import Relation.Binary.Construct.Add.Infimum.Equality as Equality |
| 24 |
using (_≈₋_; ⊥₋≈⊥₋; ≈₋-isEquivalence; ≈₋-isDecEquivalence; ≈₋-refl; ≈₋-dec |
| 25 |
; [_]) |
| 26 |
open import Relation.Binary.Structures |
| 27 |
using (IsPreorder; IsPartialOrder; IsDecPartialOrder; IsTotalOrder |
| 28 |
; IsDecTotalOrder) |
| 29 |
open import Relation.Binary.Definitions |
| 30 |
using (Minimum; Transitive; Total; Decidable; Irrelevant; Antisymmetric) |
| 31 |
open import Relation.Nullary.Construct.Add.Infimum using (⊥₋; [_]; _₋; ≡-dec) |
| 32 |
open import Relation.Nullary.Decidable.Core using (yes; no; map′) |
| 33 |
import Relation.Nullary.Decidable.Core as Dec using (map′) |
| 34 |
|
| 35 |
------------------------------------------------------------------------ |
| 36 |
-- Definition |
| 37 |
|
| 38 |
infix 5 _≤₋_ |
| 39 |
data _≤₋_ : Rel (A ₋) (a ⊔ ℓ) where |
| 40 |
⊥₋≤_ : (l : A ₋) → ⊥₋ ≤₋ l |
| 41 |
[_] : {k l : A} → k ≤ l → [ k ] ≤₋ [ l ] |
| 42 |
|
| 43 |
------------------------------------------------------------------------ |
| 44 |
-- Relational properties |
| 45 |
|
| 46 |
[≤]-injective : ∀ {k l} → [ k ] ≤₋ [ l ] → k ≤ l |
| 47 |
[≤]-injective [ p ] = p |
| 48 |
|
| 49 |
≤₋-trans : Transitive _≤_ → Transitive _≤₋_ |
| 50 |
≤₋-trans ≤-trans (⊥₋≤ l) q = ⊥₋≤ _ |
| 51 |
≤₋-trans ≤-trans [ p ] [ q ] = [ ≤-trans p q ] |
| 52 |
|
| 53 |
≤₋-minimum : Minimum _≤₋_ ⊥₋ |
| 54 |
≤₋-minimum = ⊥₋≤_ |
| 55 |
|
| 56 |
≤₋-dec : Decidable _≤_ → Decidable _≤₋_ |
| 57 |
≤₋-dec _≤?_ ⊥₋ l = yes (⊥₋≤ l) |
| 58 |
≤₋-dec _≤?_ [ k ] ⊥₋ = no (λ ()) |
| 59 |
≤₋-dec _≤?_ [ k ] [ l ] = Dec.map′ [_] [≤]-injective (k ≤? l) |
| 60 |
|
| 61 |
≤₋-total : Total _≤_ → Total _≤₋_ |
| 62 |
≤₋-total ≤-total ⊥₋ l = inj₁ (⊥₋≤ l) |
| 63 |
≤₋-total ≤-total k ⊥₋ = inj₂ (⊥₋≤ k) |
| 64 |
≤₋-total ≤-total [ k ] [ l ] = Sum.map [_] [_] (≤-total k l) |
| 65 |
|
| 66 |
≤₋-irrelevant : Irrelevant _≤_ → Irrelevant _≤₋_ |
| 67 |
≤₋-irrelevant ≤-irr (⊥₋≤ k) (⊥₋≤ k) = refl |
| 68 |
≤₋-irrelevant ≤-irr [ p ] [ q ] = cong _ (≤-irr p q) |
| 69 |
|
| 70 |
------------------------------------------------------------------------ |
| 71 |
-- Relational properties + propositional equality |
| 72 |
|
| 73 |
≤₋-reflexive-≡ : (_≡_ ⇒ _≤_) → (_≡_ ⇒ _≤₋_) |
| 74 |
≤₋-reflexive-≡ ≤-reflexive {[ x ]} refl = [ ≤-reflexive refl ] |
| 75 |
≤₋-reflexive-≡ ≤-reflexive {⊥₋} refl = ⊥₋≤ ⊥₋ |
| 76 |
|
| 77 |
≤₋-antisym-≡ : Antisymmetric _≡_ _≤_ → Antisymmetric _≡_ _≤₋_ |
| 78 |
≤₋-antisym-≡ antisym (⊥₋≤ _) (⊥₋≤ _) = refl |
| 79 |
≤₋-antisym-≡ antisym [ p ] [ q ] = cong [_] (antisym p q) |
| 80 |
|
| 81 |
------------------------------------------------------------------------ |
| 82 |
-- Relational properties + setoid equality |
| 83 |
|
| 84 |
module _ {e} {_≈_ : Rel A e} where |
| 85 |
|
| 86 |
open Equality _≈_ |
| 87 |
|
| 88 |
≤₋-reflexive : (_≈_ ⇒ _≤_) → (_≈₋_ ⇒ _≤₋_) |
| 89 |
≤₋-reflexive ≤-reflexive ⊥₋≈⊥₋ = ⊥₋≤ ⊥₋ |
| 90 |
≤₋-reflexive ≤-reflexive [ p ] = [ ≤-reflexive p ] |
| 91 |
|
| 92 |
≤₋-antisym : Antisymmetric _≈_ _≤_ → Antisymmetric _≈₋_ _≤₋_ |
| 93 |
≤₋-antisym ≤≥⇒≈ (⊥₋≤ _) (⊥₋≤ _) = ⊥₋≈⊥₋ |
| 94 |
≤₋-antisym ≤≥⇒≈ [ p ] [ q ] = [ ≤≥⇒≈ p q ] |
| 95 |
|
| 96 |
------------------------------------------------------------------------ |
| 97 |
-- Structures + propositional equality |
| 98 |
|
| 99 |
≤₋-isPreorder-≡ : IsPreorder _≡_ _≤_ → IsPreorder _≡_ _≤₋_ |
| 100 |
≤₋-isPreorder-≡ ≤-isPreorder = record |
| 101 |
{ isEquivalence = ≡.isEquivalence |
| 102 |
; reflexive = ≤₋-reflexive-≡ reflexive |
| 103 |
; trans = ≤₋-trans trans |
| 104 |
} where open IsPreorder ≤-isPreorder |
| 105 |
|
| 106 |
≤₋-isPartialOrder-≡ : IsPartialOrder _≡_ _≤_ → IsPartialOrder _≡_ _≤₋_ |
| 107 |
≤₋-isPartialOrder-≡ ≤-isPartialOrder = record |
| 108 |
{ isPreorder = ≤₋-isPreorder-≡ isPreorder |
| 109 |
; antisym = ≤₋-antisym-≡ antisym |
| 110 |
} where open IsPartialOrder ≤-isPartialOrder |
| 111 |
|
| 112 |
≤₋-isDecPartialOrder-≡ : IsDecPartialOrder _≡_ _≤_ → IsDecPartialOrder _≡_ _≤₋_ |
| 113 |
≤₋-isDecPartialOrder-≡ ≤-isDecPartialOrder = record |
| 114 |
{ isPartialOrder = ≤₋-isPartialOrder-≡ isPartialOrder |
| 115 |
; _≟_ = ≡-dec _≟_ |
| 116 |
; _≤?_ = ≤₋-dec _≤?_ |
| 117 |
} where open IsDecPartialOrder ≤-isDecPartialOrder |
| 118 |
|
| 119 |
≤₋-isTotalOrder-≡ : IsTotalOrder _≡_ _≤_ → IsTotalOrder _≡_ _≤₋_ |
| 120 |
≤₋-isTotalOrder-≡ ≤-isTotalOrder = record |
| 121 |
{ isPartialOrder = ≤₋-isPartialOrder-≡ isPartialOrder |
| 122 |
; total = ≤₋-total total |
| 123 |
} where open IsTotalOrder ≤-isTotalOrder |
| 124 |
|
| 125 |
≤₋-isDecTotalOrder-≡ : IsDecTotalOrder _≡_ _≤_ → IsDecTotalOrder _≡_ _≤₋_ |
| 126 |
≤₋-isDecTotalOrder-≡ ≤-isDecTotalOrder = record |
| 127 |
{ isTotalOrder = ≤₋-isTotalOrder-≡ isTotalOrder |
| 128 |
; _≟_ = ≡-dec _≟_ |
| 129 |
; _≤?_ = ≤₋-dec _≤?_ |
| 130 |
} where open IsDecTotalOrder ≤-isDecTotalOrder |
| 131 |
|
| 132 |
------------------------------------------------------------------------ |
| 133 |
-- Structures + setoid equality |
| 134 |
|
| 135 |
module _ {e} {_≈_ : Rel A e} where |
| 136 |
|
| 137 |
open Equality _≈_ |
| 138 |
|
| 139 |
≤₋-isPreorder : IsPreorder _≈_ _≤_ → IsPreorder _≈₋_ _≤₋_ |
| 140 |
≤₋-isPreorder ≤-isPreorder = record |
| 141 |
{ isEquivalence = ≈₋-isEquivalence isEquivalence |
| 142 |
; reflexive = ≤₋-reflexive reflexive |
| 143 |
; trans = ≤₋-trans trans |
| 144 |
} where open IsPreorder ≤-isPreorder |
| 145 |
|
| 146 |
≤₋-isPartialOrder : IsPartialOrder _≈_ _≤_ → IsPartialOrder _≈₋_ _≤₋_ |
| 147 |
≤₋-isPartialOrder ≤-isPartialOrder = record |
| 148 |
{ isPreorder = ≤₋-isPreorder isPreorder |
| 149 |
; antisym = ≤₋-antisym antisym |
| 150 |
} where open IsPartialOrder ≤-isPartialOrder |
| 151 |
|
| 152 |
≤₋-isDecPartialOrder : IsDecPartialOrder _≈_ _≤_ → IsDecPartialOrder _≈₋_ _≤₋_ |
| 153 |
≤₋-isDecPartialOrder ≤-isDecPartialOrder = record |
| 154 |
{ isPartialOrder = ≤₋-isPartialOrder isPartialOrder |
| 155 |
; _≟_ = ≈₋-dec _≟_ |
| 156 |
; _≤?_ = ≤₋-dec _≤?_ |
| 157 |
} where open IsDecPartialOrder ≤-isDecPartialOrder |
| 158 |
|
| 159 |
≤₋-isTotalOrder : IsTotalOrder _≈_ _≤_ → IsTotalOrder _≈₋_ _≤₋_ |
| 160 |
≤₋-isTotalOrder ≤-isTotalOrder = record |
| 161 |
{ isPartialOrder = ≤₋-isPartialOrder isPartialOrder |
| 162 |
; total = ≤₋-total total |
| 163 |
} where open IsTotalOrder ≤-isTotalOrder |
| 164 |
|
| 165 |
≤₋-isDecTotalOrder : IsDecTotalOrder _≈_ _≤_ → IsDecTotalOrder _≈₋_ _≤₋_ |
| 166 |
≤₋-isDecTotalOrder ≤-isDecTotalOrder = record |
| 167 |
{ isTotalOrder = ≤₋-isTotalOrder isTotalOrder |
| 168 |
; _≟_ = ≈₋-dec _≟_ |
| 169 |
; _≤?_ = ≤₋-dec _≤?_ |
| 170 |
} where open IsDecTotalOrder ≤-isDecTotalOrder |