Debian Codegraph @

src/Data/Product/Relation/Binary/Lex/NonStrict.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Lexicographic products of binary relations
5 ------------------------------------------------------------------------
6
7 -- The definition of lexicographic product used here is suitable if
8 -- the left-hand relation is a (non-strict) partial order.
9
10 {-# OPTIONS --cubical-compatible --safe #-}
11
12 module Data.Product.Relation.Binary.Lex.NonStrict where
13
14 open import Data.Product.Base using (_×_; _,_; proj₁; proj₂)
15 open import Data.Product.Relation.Binary.Pointwise.NonDependent as Pointwise
16 using (Pointwise)
17 import Data.Product.Relation.Binary.Lex.Strict as Strict
18 open import Data.Sum.Base using (inj₁; inj₂)
19 open import Level using (Level)
20 open import Relation.Binary.Core using (Rel; _⇒_)
21 open import Relation.Binary.Bundles
22 using (Poset; DecTotalOrder; TotalOrder)
23 open import Relation.Binary.Structures
24 using (IsPartialOrder; IsEquivalence; IsTotalOrder; IsDecTotalOrder)
25 open import Relation.Binary.Definitions
26 using (Transitive; Symmetric; Decidable; Antisymmetric; Total; Trichotomous
27 ; Irreflexive; Asymmetric; _Respects₂_; tri<; tri>; tri≈)
28 open import Relation.Binary.Consequences
29 import Relation.Binary.Construct.NonStrictToStrict as Conv
30
31
32 private
33 variable
34 a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level
35 A : Set a
36 B : Set b
37
38 ------------------------------------------------------------------------
39 -- Definition
40
41 ×-Lex : (_≈₁_ : Rel A ℓ₁) (_≤₁_ : Rel A ℓ₂) (_≤₂_ : Rel B ℓ₃) →
42 Rel (A × B) _
43 ×-Lex _≈₁_ _≤₁_ _≤₂_ = Strict.×-Lex _≈₁_ (Conv._<_ _≈₁_ _≤₁_) _≤₂_
44
45 ------------------------------------------------------------------------
46 -- Properties
47
48 ×-reflexive : (_≈₁_ : Rel A ℓ₁) (_≤₁_ : Rel A ℓ₂)
49 {_≈₂_ : Rel B ℓ₃} (_≤₂_ : Rel B ℓ₄) →
50 _≈₂_ ⇒ _≤₂_ →
51 (Pointwise _≈₁_ _≈₂_) ⇒ (×-Lex _≈₁_ _≤₁_ _≤₂_)
52 ×-reflexive _≈₁_ _≤₁_ _≤₂_ refl₂ =
53 Strict.×-reflexive _≈₁_ (Conv._<_ _≈₁_ _≤₁_) _≤₂_ refl₂
54
55 module _ {_≈₁_ : Rel A ℓ₁} {_≤₁_ : Rel A ℓ₂} {_≤₂_ : Rel B ℓ₃} where
56
57 private
58 _≤ₗₑₓ_ = ×-Lex _≈₁_ _≤₁_ _≤₂_
59
60 ×-transitive : IsPartialOrder _≈₁_ _≤₁_ → Transitive _≤₂_ →
61 Transitive _≤ₗₑₓ_
62 ×-transitive po₁ trans₂ =
63 Strict.×-transitive {_≈₁_ = _≈₁_} {_<₂_ = _≤₂_}
64 isEquivalence (Conv.<-resp-≈ _ _ isEquivalence ≤-resp-≈)
65 (Conv.<-trans _ _ po₁)
66 trans₂
67 where open IsPartialOrder po₁
68
69 ×-total : Symmetric _≈₁_ → Decidable _≈₁_ → Antisymmetric _≈₁_ _≤₁_ →
70 Total _≤₁_ → Total _≤₂_ → Total _≤ₗₑₓ_
71 ×-total sym₁ dec₁ antisym₁ total₁ total₂ =
72 total
73 where
74 tri₁ : Trichotomous _≈₁_ (Conv._<_ _≈₁_ _≤₁_)
75 tri₁ = Conv.<-trichotomous _ _ sym₁ dec₁ antisym₁ total₁
76
77 total : Total _≤ₗₑₓ_
78 total x y with tri₁ (proj₁ x) (proj₁ y)
79 ... | tri< x₁<y₁ x₁≉y₁ x₁≯y₁ = inj₁ (inj₁ x₁<y₁)
80 ... | tri> x₁≮y₁ x₁≉y₁ x₁>y₁ = inj₂ (inj₁ x₁>y₁)
81 ... | tri≈ x₁≮y₁ x₁≈y₁ x₁≯y₁ with total₂ (proj₂ x) (proj₂ y)
82 ... | inj₁ x₂≤y₂ = inj₁ (inj₂ (x₁≈y₁ , x₂≤y₂))
83 ... | inj₂ x₂≥y₂ = inj₂ (inj₂ (sym₁ x₁≈y₁ , x₂≥y₂))
84
85 ×-decidable : Decidable _≈₁_ → Decidable _≤₁_ → Decidable _≤₂_ →
86 Decidable _≤ₗₑₓ_
87 ×-decidable dec-≈₁ dec-≤₁ dec-≤₂ =
88 Strict.×-decidable dec-≈₁ (Conv.<-decidable _ _ dec-≈₁ dec-≤₁)
89 dec-≤₂
90
91 module _ {_≈₁_ : Rel A ℓ₁} {_≤₁_ : Rel A ℓ₂}
92 {_≈₂_ : Rel B ℓ₃} {_≤₂_ : Rel B ℓ₄}
93 where
94
95 private
96 _≤ₗₑₓ_ = ×-Lex _≈₁_ _≤₁_ _≤₂_
97 _≋_ = Pointwise _≈₁_ _≈₂_
98
99 ×-antisymmetric : IsPartialOrder _≈₁_ _≤₁_ → Antisymmetric _≈₂_ _≤₂_ →
100 Antisymmetric _≋_ _≤ₗₑₓ_
101 ×-antisymmetric po₁ antisym₂ =
102 Strict.×-antisymmetric {_≈₁_ = _≈₁_} {_<₂_ = _≤₂_}
103 ≈-sym₁ irrefl₁ asym₁ antisym₂
104 where
105 open IsPartialOrder po₁
106 open Eq renaming (refl to ≈-refl₁; sym to ≈-sym₁)
107
108 irrefl₁ : Irreflexive _≈₁_ (Conv._<_ _≈₁_ _≤₁_)
109 irrefl₁ = Conv.<-irrefl _≈₁_ _≤₁_
110
111 asym₁ : Asymmetric (Conv._<_ _≈₁_ _≤₁_)
112 asym₁ = trans∧irr⇒asym {_≈_ = _≈₁_}
113 ≈-refl₁ (Conv.<-trans _ _ po₁) irrefl₁
114
115 ×-respects₂ : IsEquivalence _≈₁_ →
116 _≤₁_ Respects₂ _≈₁_ → _≤₂_ Respects₂ _≈₂_ →
117 _≤ₗₑₓ_ Respects₂ _≋_
118 ×-respects₂ eq₁ resp₁ resp₂ =
119 Strict.×-respects₂ eq₁ (Conv.<-resp-≈ _ _ eq₁ resp₁) resp₂
120
121
122 ------------------------------------------------------------------------
123 -- Structures
124
125 ×-isPartialOrder : IsPartialOrder _≈₁_ _≤₁_ →
126 IsPartialOrder _≈₂_ _≤₂_ →
127 IsPartialOrder _≋_ _≤ₗₑₓ_
128 ×-isPartialOrder po₁ po₂ = record
129 { isPreorder = record
130 { isEquivalence = Pointwise.×-isEquivalence
131 (isEquivalence po₁)
132 (isEquivalence po₂)
133 ; reflexive = ×-reflexive _≈₁_ _≤₁_ _≤₂_ (reflexive po₂)
134 ; trans = ×-transitive {_≤₂_ = _≤₂_} po₁ (trans po₂)
135 }
136 ; antisym = ×-antisymmetric po₁ (antisym po₂)
137 }
138 where open IsPartialOrder
139
140 ×-isTotalOrder : Decidable _≈₁_ →
141 IsTotalOrder _≈₁_ _≤₁_ →
142 IsTotalOrder _≈₂_ _≤₂_ →
143 IsTotalOrder _≋_ _≤ₗₑₓ_
144 ×-isTotalOrder ≈₁-dec to₁ to₂ = record
145 { isPartialOrder = ×-isPartialOrder
146 (isPartialOrder to₁) (isPartialOrder to₂)
147 ; total = ×-total (Eq.sym to₁) ≈₁-dec
148 (antisym to₁) (total to₁)
149 (total to₂)
150 }
151 where open IsTotalOrder
152
153 ×-isDecTotalOrder : IsDecTotalOrder _≈₁_ _≤₁_ →
154 IsDecTotalOrder _≈₂_ _≤₂_ →
155 IsDecTotalOrder _≋_ _≤ₗₑₓ_
156 ×-isDecTotalOrder to₁ to₂ = record
157 { isTotalOrder = ×-isTotalOrder (_≟_ to₁)
158 (isTotalOrder to₁)
159 (isTotalOrder to₂)
160 ; _≟_ = Pointwise.×-decidable (_≟_ to₁) (_≟_ to₂)
161 ; _≤?_ = ×-decidable (_≟_ to₁) (_≤?_ to₁) (_≤?_ to₂)
162 }
163 where open IsDecTotalOrder
164
165 ------------------------------------------------------------------------
166 -- Bundles
167
168 ×-poset : Poset a ℓ₁ ℓ₂ → Poset b ℓ₃ ℓ₄ → Poset _ _ _
169 ×-poset p₁ p₂ = record
170 { isPartialOrder = ×-isPartialOrder O₁.isPartialOrder O₂.isPartialOrder
171 } where module O₁ = Poset p₁; module O₂ = Poset p₂
172
173 ×-totalOrder : DecTotalOrder a ℓ₁ ℓ₂ →
174 TotalOrder b ℓ₃ ℓ₄ →
175 TotalOrder _ _ _
176 ×-totalOrder t₁ t₂ = record
177 { isTotalOrder = ×-isTotalOrder T₁._≟_ T₁.isTotalOrder T₂.isTotalOrder
178 } where module T₁ = DecTotalOrder t₁; module T₂ = TotalOrder t₂
179
180 ×-decTotalOrder : DecTotalOrder a ℓ₁ ℓ₂ →
181 DecTotalOrder b ℓ₃ ℓ₄ →
182 DecTotalOrder _ _ _
183 ×-decTotalOrder t₁ t₂ = record
184 { isDecTotalOrder = ×-isDecTotalOrder O₁.isDecTotalOrder O₂.isDecTotalOrder
185 } where module O₁ = DecTotalOrder t₁; module O₂ = DecTotalOrder t₂