| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- The lifting of a 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 |
module Relation.Binary.Construct.Add.Infimum.Strict |
| 15 |
{a ℓ} {A : Set a} (_<_ : Rel A ℓ) where |
| 16 |
|
| 17 |
open import Level using (_⊔_) |
| 18 |
open import Data.Product.Base using (_,_; map) |
| 19 |
open import Function.Base using (_∘_) |
| 20 |
open import Induction.WellFounded using (WfRec; Acc; acc; WellFounded) |
| 21 |
open import Relation.Binary.PropositionalEquality.Core |
| 22 |
using (_≡_; refl; cong; subst) |
| 23 |
import Relation.Binary.PropositionalEquality.Properties as ≡ |
| 24 |
using (isEquivalence) |
| 25 |
import Relation.Binary.Construct.Add.Infimum.Equality as Equality |
| 26 |
using (_≈₋_; ⊥₋≈⊥₋; ≈₋-isEquivalence; ≈₋-isDecEquivalence; ≈₋-refl; ≈₋-dec |
| 27 |
; [_]; [≈]-injective) |
| 28 |
import Relation.Binary.Construct.Add.Infimum.NonStrict as NonStrict |
| 29 |
open import Relation.Binary.Structures |
| 30 |
using (IsStrictPartialOrder; IsDecStrictPartialOrder; IsStrictTotalOrder) |
| 31 |
open import Relation.Binary.Definitions |
| 32 |
using (Asymmetric; Transitive; Decidable; Irrelevant; Irreflexive; Trans |
| 33 |
; Trichotomous; tri≈; tri<; tri>; _Respectsˡ_; _Respectsʳ_; _Respects₂_) |
| 34 |
open import Relation.Nullary.Construct.Add.Infimum |
| 35 |
using (⊥₋; [_]; _₋; ≡-dec; []-injective) |
| 36 |
open import Relation.Nullary.Decidable.Core as Dec using (yes; no; map′) |
| 37 |
|
| 38 |
|
| 39 |
------------------------------------------------------------------------ |
| 40 |
-- Definition |
| 41 |
|
| 42 |
infix 4 _<₋_ |
| 43 |
|
| 44 |
data _<₋_ : Rel (A ₋) (a ⊔ ℓ) where |
| 45 |
⊥₋<[_] : (l : A) → ⊥₋ <₋ [ l ] |
| 46 |
[_] : {k l : A} → k < l → [ k ] <₋ [ l ] |
| 47 |
|
| 48 |
------------------------------------------------------------------------ |
| 49 |
-- Relational properties |
| 50 |
|
| 51 |
[<]-injective : ∀ {k l} → [ k ] <₋ [ l ] → k < l |
| 52 |
[<]-injective [ p ] = p |
| 53 |
|
| 54 |
<₋-asym : Asymmetric _<_ → Asymmetric _<₋_ |
| 55 |
<₋-asym <-asym [ p ] [ q ] = <-asym p q |
| 56 |
|
| 57 |
<₋-trans : Transitive _<_ → Transitive _<₋_ |
| 58 |
<₋-trans <-trans ⊥₋<[ l ] [ q ] = ⊥₋<[ _ ] |
| 59 |
<₋-trans <-trans [ p ] [ q ] = [ <-trans p q ] |
| 60 |
|
| 61 |
<₋-dec : Decidable _<_ → Decidable _<₋_ |
| 62 |
<₋-dec _<?_ ⊥₋ ⊥₋ = no (λ ()) |
| 63 |
<₋-dec _<?_ ⊥₋ [ l ] = yes ⊥₋<[ l ] |
| 64 |
<₋-dec _<?_ [ k ] ⊥₋ = no (λ ()) |
| 65 |
<₋-dec _<?_ [ k ] [ l ] = Dec.map′ [_] [<]-injective (k <? l) |
| 66 |
|
| 67 |
<₋-irrelevant : Irrelevant _<_ → Irrelevant _<₋_ |
| 68 |
<₋-irrelevant <-irr ⊥₋<[ l ] ⊥₋<[ l ] = refl |
| 69 |
<₋-irrelevant <-irr [ p ] [ q ] = cong _ (<-irr p q) |
| 70 |
|
| 71 |
module _ {r} {_≤_ : Rel A r} where |
| 72 |
|
| 73 |
open NonStrict _≤_ |
| 74 |
|
| 75 |
<₋-transʳ : Trans _≤_ _<_ _<_ → Trans _≤₋_ _<₋_ _<₋_ |
| 76 |
<₋-transʳ <-transʳ (⊥₋≤ ⊥₋) q = q |
| 77 |
<₋-transʳ <-transʳ (⊥₋≤ _) [ q ] = ⊥₋<[ _ ] |
| 78 |
<₋-transʳ <-transʳ [ p ] [ q ] = [ <-transʳ p q ] |
| 79 |
|
| 80 |
<₋-transˡ : Trans _<_ _≤_ _<_ → Trans _<₋_ _≤₋_ _<₋_ |
| 81 |
<₋-transˡ <-transˡ ⊥₋<[ _ ] [ q ] = ⊥₋<[ _ ] |
| 82 |
<₋-transˡ <-transˡ [ p ] [ q ] = [ <-transˡ p q ] |
| 83 |
|
| 84 |
<₋-accessible-⊥₋ : Acc _<₋_ ⊥₋ |
| 85 |
<₋-accessible-⊥₋ = acc λ() |
| 86 |
|
| 87 |
<₋-accessible[_] : ∀ {x} → Acc _<_ x → Acc _<₋_ [ x ] |
| 88 |
<₋-accessible[_] = acc ∘ wf-acc |
| 89 |
where |
| 90 |
wf-acc : ∀ {x} → Acc _<_ x → WfRec _<₋_ (Acc _<₋_) [ x ] |
| 91 |
wf-acc _ ⊥₋<[ _ ] = <₋-accessible-⊥₋ |
| 92 |
wf-acc (acc ih) [ y<x ] = <₋-accessible[ ih y<x ] |
| 93 |
|
| 94 |
<₋-wellFounded : WellFounded _<_ → WellFounded _<₋_ |
| 95 |
<₋-wellFounded wf ⊥₋ = <₋-accessible-⊥₋ |
| 96 |
<₋-wellFounded wf [ x ] = <₋-accessible[ wf x ] |
| 97 |
|
| 98 |
------------------------------------------------------------------------ |
| 99 |
-- Relational properties + propositional equality |
| 100 |
|
| 101 |
<₋-cmp-≡ : Trichotomous _≡_ _<_ → Trichotomous _≡_ _<₋_ |
| 102 |
<₋-cmp-≡ <-cmp ⊥₋ ⊥₋ = tri≈ (λ ()) refl (λ ()) |
| 103 |
<₋-cmp-≡ <-cmp ⊥₋ [ l ] = tri< ⊥₋<[ l ] (λ ()) (λ ()) |
| 104 |
<₋-cmp-≡ <-cmp [ k ] ⊥₋ = tri> (λ ()) (λ ()) ⊥₋<[ k ] |
| 105 |
<₋-cmp-≡ <-cmp [ k ] [ l ] with <-cmp k l |
| 106 |
... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ []-injective) (¬c ∘ [<]-injective) |
| 107 |
... | tri≈ ¬a refl ¬c = tri≈ (¬a ∘ [<]-injective) refl (¬c ∘ [<]-injective) |
| 108 |
... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ []-injective) [ c ] |
| 109 |
|
| 110 |
<₋-irrefl-≡ : Irreflexive _≡_ _<_ → Irreflexive _≡_ _<₋_ |
| 111 |
<₋-irrefl-≡ <-irrefl refl [ x ] = <-irrefl refl x |
| 112 |
|
| 113 |
<₋-respˡ-≡ : _<₋_ Respectsˡ _≡_ |
| 114 |
<₋-respˡ-≡ = subst (_<₋ _) |
| 115 |
|
| 116 |
<₋-respʳ-≡ : _<₋_ Respectsʳ _≡_ |
| 117 |
<₋-respʳ-≡ = subst (_ <₋_) |
| 118 |
|
| 119 |
<₋-resp-≡ : _<₋_ Respects₂ _≡_ |
| 120 |
<₋-resp-≡ = <₋-respʳ-≡ , <₋-respˡ-≡ |
| 121 |
|
| 122 |
------------------------------------------------------------------------ |
| 123 |
-- Relational properties + setoid equality |
| 124 |
|
| 125 |
module _ {e} {_≈_ : Rel A e} where |
| 126 |
|
| 127 |
open Equality _≈_ |
| 128 |
|
| 129 |
<₋-cmp : Trichotomous _≈_ _<_ → Trichotomous _≈₋_ _<₋_ |
| 130 |
<₋-cmp <-cmp ⊥₋ ⊥₋ = tri≈ (λ ()) ⊥₋≈⊥₋ (λ ()) |
| 131 |
<₋-cmp <-cmp ⊥₋ [ l ] = tri< ⊥₋<[ l ] (λ ()) (λ ()) |
| 132 |
<₋-cmp <-cmp [ k ] ⊥₋ = tri> (λ ()) (λ ()) ⊥₋<[ k ] |
| 133 |
<₋-cmp <-cmp [ k ] [ l ] with <-cmp k l |
| 134 |
... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ [≈]-injective) (¬c ∘ [<]-injective) |
| 135 |
... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ [<]-injective) [ b ] (¬c ∘ [<]-injective) |
| 136 |
... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ [≈]-injective) [ c ] |
| 137 |
|
| 138 |
<₋-irrefl : Irreflexive _≈_ _<_ → Irreflexive _≈₋_ _<₋_ |
| 139 |
<₋-irrefl <-irrefl [ p ] [ q ] = <-irrefl p q |
| 140 |
|
| 141 |
<₋-respˡ-≈₋ : _<_ Respectsˡ _≈_ → _<₋_ Respectsˡ _≈₋_ |
| 142 |
<₋-respˡ-≈₋ <-respˡ-≈ ⊥₋≈⊥₋ q = q |
| 143 |
<₋-respˡ-≈₋ <-respˡ-≈ [ p ] [ q ] = [ <-respˡ-≈ p q ] |
| 144 |
|
| 145 |
<₋-respʳ-≈₋ : _<_ Respectsʳ _≈_ → _<₋_ Respectsʳ _≈₋_ |
| 146 |
<₋-respʳ-≈₋ <-respʳ-≈ ⊥₋≈⊥₋ q = q |
| 147 |
<₋-respʳ-≈₋ <-respʳ-≈ [ p ] ⊥₋<[ l ] = ⊥₋<[ _ ] |
| 148 |
<₋-respʳ-≈₋ <-respʳ-≈ [ p ] [ q ] = [ <-respʳ-≈ p q ] |
| 149 |
|
| 150 |
<₋-resp-≈₋ : _<_ Respects₂ _≈_ → _<₋_ Respects₂ _≈₋_ |
| 151 |
<₋-resp-≈₋ = map <₋-respʳ-≈₋ <₋-respˡ-≈₋ |
| 152 |
|
| 153 |
------------------------------------------------------------------------ |
| 154 |
-- Structures + propositional equality |
| 155 |
|
| 156 |
<₋-isStrictPartialOrder-≡ : IsStrictPartialOrder _≡_ _<_ → |
| 157 |
IsStrictPartialOrder _≡_ _<₋_ |
| 158 |
<₋-isStrictPartialOrder-≡ strict = record |
| 159 |
{ isEquivalence = ≡.isEquivalence |
| 160 |
; irrefl = <₋-irrefl-≡ irrefl |
| 161 |
; trans = <₋-trans trans |
| 162 |
; <-resp-≈ = <₋-resp-≡ |
| 163 |
} where open IsStrictPartialOrder strict |
| 164 |
|
| 165 |
<₋-isDecStrictPartialOrder-≡ : IsDecStrictPartialOrder _≡_ _<_ → |
| 166 |
IsDecStrictPartialOrder _≡_ _<₋_ |
| 167 |
<₋-isDecStrictPartialOrder-≡ dectot = record |
| 168 |
{ isStrictPartialOrder = <₋-isStrictPartialOrder-≡ isStrictPartialOrder |
| 169 |
; _≟_ = ≡-dec _≟_ |
| 170 |
; _<?_ = <₋-dec _<?_ |
| 171 |
} where open IsDecStrictPartialOrder dectot |
| 172 |
|
| 173 |
<₋-isStrictTotalOrder-≡ : IsStrictTotalOrder _≡_ _<_ → |
| 174 |
IsStrictTotalOrder _≡_ _<₋_ |
| 175 |
<₋-isStrictTotalOrder-≡ strictot = record |
| 176 |
{ isStrictPartialOrder = <₋-isStrictPartialOrder-≡ isStrictPartialOrder |
| 177 |
; compare = <₋-cmp-≡ compare |
| 178 |
} where open IsStrictTotalOrder strictot |
| 179 |
|
| 180 |
------------------------------------------------------------------------ |
| 181 |
-- Structures + setoid equality |
| 182 |
|
| 183 |
module _ {e} {_≈_ : Rel A e} where |
| 184 |
|
| 185 |
open Equality _≈_ |
| 186 |
|
| 187 |
<₋-isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_ → |
| 188 |
IsStrictPartialOrder _≈₋_ _<₋_ |
| 189 |
<₋-isStrictPartialOrder strict = record |
| 190 |
{ isEquivalence = ≈₋-isEquivalence isEquivalence |
| 191 |
; irrefl = <₋-irrefl irrefl |
| 192 |
; trans = <₋-trans trans |
| 193 |
; <-resp-≈ = <₋-resp-≈₋ <-resp-≈ |
| 194 |
} where open IsStrictPartialOrder strict |
| 195 |
|
| 196 |
<₋-isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_ → |
| 197 |
IsDecStrictPartialOrder _≈₋_ _<₋_ |
| 198 |
<₋-isDecStrictPartialOrder dectot = record |
| 199 |
{ isStrictPartialOrder = <₋-isStrictPartialOrder isStrictPartialOrder |
| 200 |
; _≟_ = ≈₋-dec _≟_ |
| 201 |
; _<?_ = <₋-dec _<?_ |
| 202 |
} where open IsDecStrictPartialOrder dectot |
| 203 |
|
| 204 |
<₋-isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_ → |
| 205 |
IsStrictTotalOrder _≈₋_ _<₋_ |
| 206 |
<₋-isStrictTotalOrder strictot = record |
| 207 |
{ isStrictPartialOrder = <₋-isStrictPartialOrder isStrictPartialOrder |
| 208 |
; compare = <₋-cmp compare |
| 209 |
} where open IsStrictTotalOrder strictot |