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