Debian Codegraph @

src/Relation/Binary/Construct/NonStrictToStrict.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Conversion of _≤_ to _<_
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 open import Relation.Binary.Core using (Rel; _⇒_)
10
11 module Relation.Binary.Construct.NonStrictToStrict
12 {a ℓ₁ ℓ₂} {A : Set a} (_≈_ : Rel A ℓ₁) (_≤_ : Rel A ℓ₂) where
13
14 open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
15 open import Data.Sum.Base using (inj₁; inj₂)
16 open import Function.Base using (_∘_; flip)
17 open import Relation.Nullary using (¬_; yes; no)
18 open import Relation.Nullary.Decidable using (¬?; _×-dec_)
19 open import Relation.Nullary.Negation using (contradiction)
20 open import Relation.Binary.Structures
21 using (IsPartialOrder; IsEquivalence; IsStrictPartialOrder; IsDecPartialOrder
22 ; IsDecStrictPartialOrder; IsTotalOrder; IsStrictTotalOrder
23 ; IsDecTotalOrder)
24 open import Relation.Binary.Definitions
25 using (Trichotomous; Antisymmetric; Symmetric; Total; Decidable; Irreflexive
26 ; Transitive; _Respectsʳ_; _Respectsˡ_; _Respects₂_; Trans; Asymmetric
27 ; tri≈; tri<; tri>)
28
29 private
30 _≉_ : Rel A ℓ₁
31 x ≉ y = ¬ (x ≈ y)
32
33 ------------------------------------------------------------------------
34 -- _≤_ can be turned into _<_ as follows:
35
36 infix 4 _<_
37
38 _<_ : Rel A _
39 x < y = x ≤ y × x ≉ y
40
41 ------------------------------------------------------------------------
42 -- Relationship between relations
43
44 <⇒≤ : _<_ ⇒ _≤_
45 <⇒≤ = proj₁
46
47 <⇒≉ : ∀ {x y} → x < y → x ≉ y
48 <⇒≉ = proj₂
49
50 ≤∧≉⇒< : ∀ {x y} → x ≤ y → x ≉ y → x < y
51 ≤∧≉⇒< = _,_
52
53 <⇒≱ : Antisymmetric _≈_ _≤_ → ∀ {x y} → x < y → ¬ (y ≤ x)
54 <⇒≱ antisym (x≤y , x≉y) y≤x = x≉y (antisym x≤y y≤x)
55
56 ≤⇒≯ : Antisymmetric _≈_ _≤_ → ∀ {x y} → x ≤ y → ¬ (y < x)
57 ≤⇒≯ antisym x≤y y<x = <⇒≱ antisym y<x x≤y
58
59 ≰⇒> : Symmetric _≈_ → (_≈_ ⇒ _≤_) → Total _≤_ →
60 ∀ {x y} → ¬ (x ≤ y) → y < x
61 ≰⇒> sym refl total {x} {y} x≰y with total x y
62 ... | inj₁ x≤y = contradiction x≤y x≰y
63 ... | inj₂ y≤x = y≤x , x≰y ∘ refl ∘ sym
64
65 ≮⇒≥ : Symmetric _≈_ → Decidable _≈_ → _≈_ ⇒ _≤_ → Total _≤_ →
66 ∀ {x y} → ¬ (x < y) → y ≤ x
67 ≮⇒≥ sym _≟_ ≤-refl _≤?_ {x} {y} x≮y with x ≟ y | y ≤? x
68 ... | yes x≈y | _ = ≤-refl (sym x≈y)
69 ... | _ | inj₁ y≤x = y≤x
70 ... | no x≉y | inj₂ x≤y = contradiction (x≤y , x≉y) x≮y
71
72 ------------------------------------------------------------------------
73 -- Relational properties
74
75 <-irrefl : Irreflexive _≈_ _<_
76 <-irrefl x≈y (_ , x≉y) = x≉y x≈y
77
78 <-trans : IsPartialOrder _≈_ _≤_ → Transitive _<_
79 <-trans po (x≤y , x≉y) (y≤z , y≉z) =
80 (trans x≤y y≤z , x≉y ∘ antisym x≤y ∘ trans y≤z ∘ reflexive ∘ Eq.sym)
81 where open IsPartialOrder po
82
83 <-≤-trans : Symmetric _≈_ → Transitive _≤_ → Antisymmetric _≈_ _≤_ →
84 _≤_ Respectsʳ _≈_ → Trans _<_ _≤_ _<_
85 <-≤-trans sym trans antisym respʳ (x≤y , x≉y) y≤z =
86 trans x≤y y≤z , (λ x≈z → x≉y (antisym x≤y (respʳ (sym x≈z) y≤z)))
87
88 ≤-<-trans : Transitive _≤_ → Antisymmetric _≈_ _≤_ →
89 _≤_ Respectsˡ _≈_ → Trans _≤_ _<_ _<_
90 ≤-<-trans trans antisym respʳ x≤y (y≤z , y≉z) =
91 trans x≤y y≤z , (λ x≈z → y≉z (antisym y≤z (respʳ x≈z x≤y)))
92
93 <-asym : Antisymmetric _≈_ _≤_ → Asymmetric _<_
94 <-asym antisym (x≤y , x≉y) (y≤x , _) = x≉y (antisym x≤y y≤x)
95
96 <-respˡ-≈ : Transitive _≈_ → _≤_ Respectsˡ _≈_ → _<_ Respectsˡ _≈_
97 <-respˡ-≈ trans respˡ y≈z (y≤x , y≉x) =
98 respˡ y≈z y≤x , y≉x ∘ trans y≈z
99
100 <-respʳ-≈ : Symmetric _≈_ → Transitive _≈_ →
101 _≤_ Respectsʳ _≈_ → _<_ Respectsʳ _≈_
102 <-respʳ-≈ sym trans respʳ y≈z (x≤y , x≉y) =
103 (respʳ y≈z x≤y) , λ x≈z → x≉y (trans x≈z (sym y≈z))
104
105 <-resp-≈ : IsEquivalence _≈_ → _≤_ Respects₂ _≈_ → _<_ Respects₂ _≈_
106 <-resp-≈ eq (respʳ , respˡ) =
107 <-respʳ-≈ sym trans respʳ , <-respˡ-≈ trans respˡ
108 where open IsEquivalence eq
109
110 <-trichotomous : Symmetric _≈_ → Decidable _≈_ →
111 Antisymmetric _≈_ _≤_ → Total _≤_ →
112 Trichotomous _≈_ _<_
113 <-trichotomous ≈-sym _≟_ antisym total x y with x ≟ y
114 ... | yes x≈y = tri≈ (<-irrefl x≈y) x≈y (<-irrefl (≈-sym x≈y))
115 ... | no x≉y with total x y
116 ... | inj₁ x≤y = tri< (x≤y , x≉y) x≉y (x≉y ∘ antisym x≤y ∘ proj₁)
117 ... | inj₂ y≤x = tri> (x≉y ∘ flip antisym y≤x ∘ proj₁) x≉y (y≤x , x≉y ∘ ≈-sym)
118
119 <-decidable : Decidable _≈_ → Decidable _≤_ → Decidable _<_
120 <-decidable _≟_ _≤?_ x y = x ≤? y ×-dec ¬? (x ≟ y)
121
122 ------------------------------------------------------------------------
123 -- Structures
124
125 <-isStrictPartialOrder : IsPartialOrder _≈_ _≤_ →
126 IsStrictPartialOrder _≈_ _<_
127 <-isStrictPartialOrder po = record
128 { isEquivalence = isEquivalence
129 ; irrefl = <-irrefl
130 ; trans = <-trans po
131 ; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
132 } where open IsPartialOrder po
133
134 <-isDecStrictPartialOrder : IsDecPartialOrder _≈_ _≤_ →
135 IsDecStrictPartialOrder _≈_ _<_
136 <-isDecStrictPartialOrder dpo = record
137 { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder
138 ; _≟_ = _≟_
139 ; _<?_ = <-decidable _≟_ _≤?_
140 } where open IsDecPartialOrder dpo
141
142 <-isStrictTotalOrder₁ : Decidable _≈_ → IsTotalOrder _≈_ _≤_ →
143 IsStrictTotalOrder _≈_ _<_
144 <-isStrictTotalOrder₁ ≟ tot = record
145 { isStrictPartialOrder = <-isStrictPartialOrder isPartialOrder
146 ; compare = <-trichotomous Eq.sym ≟ antisym total
147 } where open IsTotalOrder tot
148
149 <-isStrictTotalOrder₂ : IsDecTotalOrder _≈_ _≤_ →
150 IsStrictTotalOrder _≈_ _<_
151 <-isStrictTotalOrder₂ dtot = <-isStrictTotalOrder₁ _≟_ isTotalOrder
152 where open IsDecTotalOrder dtot