Debian Codegraph @

src/Data/Product/Relation/Binary/Pointwise/NonDependent.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Pointwise products of binary relations
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.Product.Relation.Binary.Pointwise.NonDependent where
10
11 open import Data.Product.Base as Product
12 open import Data.Sum.Base using (inj₁; inj₂)
13 open import Level using (Level; _⊔_; 0ℓ)
14 open import Function.Base using (id)
15 open import Function.Bundles using (Inverse)
16 open import Relation.Nullary.Decidable using (_×-dec_)
17 open import Relation.Binary.Core using (REL; Rel; _⇒_)
18 open import Relation.Binary.Bundles
19 using (Setoid; DecSetoid; Preorder; Poset; StrictPartialOrder)
20 open import Relation.Binary.Definitions
21 open import Relation.Binary.Structures
22 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
23 import Relation.Binary.PropositionalEquality.Properties as ≡
24
25 private
26 variable
27 a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level
28 A B C D : Set a
29 R S ≈₁ ≈₂ : Rel A ℓ₁
30
31 ------------------------------------------------------------------------
32 -- Definition
33
34 Pointwise : REL A B ℓ₁ → REL C D ℓ₂ → REL (A × C) (B × D) (ℓ₁ ⊔ ℓ₂)
35 Pointwise R S (a , c) (b , d) = (R a b) × (S c d)
36
37 ------------------------------------------------------------------------
38 -- Pointwise preserves many relational properties
39
40 ×-reflexive : ≈₁ ⇒ R → ≈₂ ⇒ S → Pointwise ≈₁ ≈₂ ⇒ Pointwise R S
41 ×-reflexive refl₁ refl₂ = Product.map refl₁ refl₂
42
43 ×-refl : Reflexive R → Reflexive S → Reflexive (Pointwise R S)
44 ×-refl refl₁ refl₂ = refl₁ , refl₂
45
46 ×-irreflexive₁ : Irreflexive ≈₁ R →
47 Irreflexive (Pointwise ≈₁ ≈₂) (Pointwise R S)
48 ×-irreflexive₁ ir x≈y x<y = ir (proj₁ x≈y) (proj₁ x<y)
49
50 ×-irreflexive₂ : Irreflexive ≈₂ S →
51 Irreflexive (Pointwise ≈₁ ≈₂) (Pointwise R S)
52 ×-irreflexive₂ ir x≈y x<y = ir (proj₂ x≈y) (proj₂ x<y)
53
54 ×-symmetric : Symmetric R → Symmetric S → Symmetric (Pointwise R S)
55 ×-symmetric sym₁ sym₂ = Product.map sym₁ sym₂
56
57 ×-transitive : Transitive R → Transitive S → Transitive (Pointwise R S)
58 ×-transitive trans₁ trans₂ = Product.zip trans₁ trans₂
59
60 ×-antisymmetric : Antisymmetric ≈₁ R → Antisymmetric ≈₂ S →
61 Antisymmetric (Pointwise ≈₁ ≈₂) (Pointwise R S)
62 ×-antisymmetric antisym₁ antisym₂ = Product.zip antisym₁ antisym₂
63
64 ×-asymmetric₁ : Asymmetric R → Asymmetric (Pointwise R S)
65 ×-asymmetric₁ asym₁ x<y y<x = asym₁ (proj₁ x<y) (proj₁ y<x)
66
67 ×-asymmetric₂ : Asymmetric S → Asymmetric (Pointwise R S)
68 ×-asymmetric₂ asym₂ x<y y<x = asym₂ (proj₂ x<y) (proj₂ y<x)
69
70 ×-respectsʳ : R Respectsʳ ≈₁ → S Respectsʳ ≈₂ →
71 (Pointwise R S) Respectsʳ (Pointwise ≈₁ ≈₂)
72 ×-respectsʳ resp₁ resp₂ = Product.zip resp₁ resp₂
73
74 ×-respectsˡ : R Respectsˡ ≈₁ → S Respectsˡ ≈₂ →
75 (Pointwise R S) Respectsˡ (Pointwise ≈₁ ≈₂)
76 ×-respectsˡ resp₁ resp₂ = Product.zip resp₁ resp₂
77
78 ×-respects₂ : R Respects₂ ≈₁ → S Respects₂ ≈₂ →
79 (Pointwise R S) Respects₂ (Pointwise ≈₁ ≈₂)
80 ×-respects₂ = Product.zip ×-respectsʳ ×-respectsˡ
81
82 ×-total : Symmetric R → Total R → Total S → Total (Pointwise R S)
83 ×-total sym₁ total₁ total₂ (x₁ , x₂) (y₁ , y₂)
84 with total₁ x₁ y₁ | total₂ x₂ y₂
85 ... | inj₁ x₁∼y₁ | inj₁ x₂∼y₂ = inj₁ ( x₁∼y₁ , x₂∼y₂)
86 ... | inj₁ x₁∼y₁ | inj₂ y₂∼x₂ = inj₂ (sym₁ x₁∼y₁ , y₂∼x₂)
87 ... | inj₂ y₁∼x₁ | inj₂ y₂∼x₂ = inj₂ ( y₁∼x₁ , y₂∼x₂)
88 ... | inj₂ y₁∼x₁ | inj₁ x₂∼y₂ = inj₁ (sym₁ y₁∼x₁ , x₂∼y₂)
89
90 ×-decidable : Decidable R → Decidable S → Decidable (Pointwise R S)
91 ×-decidable _≟₁_ _≟₂_ (x₁ , x₂) (y₁ , y₂) = (x₁ ≟₁ y₁) ×-dec (x₂ ≟₂ y₂)
92
93 ------------------------------------------------------------------------
94 -- Structures can also be combined.
95
96 -- Some collections of properties which are preserved by ×-Rel.
97
98 ×-isEquivalence : IsEquivalence R → IsEquivalence S →
99 IsEquivalence (Pointwise R S)
100 ×-isEquivalence {R = R} {S = S} eq₁ eq₂ = record
101 { refl = ×-refl {R = R} {S = S} (refl eq₁) (refl eq₂)
102 ; sym = ×-symmetric {R = R} {S = S} (sym eq₁) (sym eq₂)
103 ; trans = ×-transitive {R = R} {S = S} (trans eq₁) (trans eq₂)
104 } where open IsEquivalence
105
106 ×-isDecEquivalence : IsDecEquivalence R → IsDecEquivalence S →
107 IsDecEquivalence (Pointwise R S)
108 ×-isDecEquivalence eq₁ eq₂ = record
109 { isEquivalence = ×-isEquivalence
110 (isEquivalence eq₁) (isEquivalence eq₂)
111 ; _≟_ = ×-decidable (_≟_ eq₁) (_≟_ eq₂)
112 } where open IsDecEquivalence
113
114 ×-isPreorder : IsPreorder ≈₁ R → IsPreorder ≈₂ S →
115 IsPreorder (Pointwise ≈₁ ≈₂) (Pointwise R S)
116 ×-isPreorder {R = R} {S = S} pre₁ pre₂ = record
117 { isEquivalence = ×-isEquivalence
118 (isEquivalence pre₁) (isEquivalence pre₂)
119 ; reflexive = ×-reflexive {R = R} {S = S}
120 (reflexive pre₁) (reflexive pre₂)
121 ; trans = ×-transitive {R = R} {S = S}
122 (trans pre₁) (trans pre₂)
123 } where open IsPreorder
124
125 ×-isPartialOrder : IsPartialOrder ≈₁ R → IsPartialOrder ≈₂ S →
126 IsPartialOrder (Pointwise ≈₁ ≈₂) (Pointwise R S)
127 ×-isPartialOrder {R = R} {S = S} po₁ po₂ = record
128 { isPreorder = ×-isPreorder (isPreorder po₁) (isPreorder po₂)
129 ; antisym = ×-antisymmetric {R = R} {S = S}
130 (antisym po₁) (antisym po₂)
131 } where open IsPartialOrder
132
133 ×-isStrictPartialOrder : IsStrictPartialOrder ≈₁ R →
134 IsStrictPartialOrder ≈₂ S →
135 IsStrictPartialOrder (Pointwise ≈₁ ≈₂) (Pointwise R S)
136 ×-isStrictPartialOrder {R = R} {≈₂ = ≈₂} {S = S} spo₁ spo₂ = record
137 { isEquivalence = ×-isEquivalence
138 (isEquivalence spo₁) (isEquivalence spo₂)
139 ; irrefl = ×-irreflexive₁ {R = R} {≈₂ = ≈₂} {S = S}
140 (irrefl spo₁)
141 ; trans = ×-transitive {R = R} {S = S}
142 (trans spo₁) (trans spo₂)
143 ; <-resp-≈ = ×-respects₂ (<-resp-≈ spo₁) (<-resp-≈ spo₂)
144 } where open IsStrictPartialOrder
145
146 ------------------------------------------------------------------------
147 -- Bundles
148
149 ×-setoid : Setoid a ℓ₁ → Setoid b ℓ₂ → Setoid _ _
150 ×-setoid s₁ s₂ = record
151 { isEquivalence =
152 ×-isEquivalence (isEquivalence s₁) (isEquivalence s₂)
153 } where open Setoid
154
155 ×-decSetoid : DecSetoid a ℓ₁ → DecSetoid b ℓ₂ → DecSetoid _ _
156 ×-decSetoid s₁ s₂ = record
157 { isDecEquivalence =
158 ×-isDecEquivalence (isDecEquivalence s₁) (isDecEquivalence s₂)
159 } where open DecSetoid
160
161 ×-preorder : Preorder a ℓ₁ ℓ₂ → Preorder b ℓ₃ ℓ₄ → Preorder _ _ _
162 ×-preorder p₁ p₂ = record
163 { isPreorder = ×-isPreorder (isPreorder p₁) (isPreorder p₂)
164 } where open Preorder
165
166 ×-poset : Poset a ℓ₁ ℓ₂ → Poset b ℓ₃ ℓ₄ → Poset _ _ _
167 ×-poset s₁ s₂ = record
168 { isPartialOrder = ×-isPartialOrder (isPartialOrder s₁)
169 (isPartialOrder s₂)
170 } where open Poset
171
172 ×-strictPartialOrder : StrictPartialOrder a ℓ₁ ℓ₂ →
173 StrictPartialOrder b ℓ₃ ℓ₄ →
174 StrictPartialOrder _ _ _
175 ×-strictPartialOrder s₁ s₂ = record
176 { isStrictPartialOrder = ×-isStrictPartialOrder
177 (isStrictPartialOrder s₁)
178 (isStrictPartialOrder s₂)
179 } where open StrictPartialOrder
180
181 ------------------------------------------------------------------------
182 -- Additional notation
183
184 -- Infix combining setoids
185 infix 4 _×ₛ_
186 _×ₛ_ : Setoid a ℓ₁ → Setoid b ℓ₂ → Setoid _ _
187 _×ₛ_ = ×-setoid
188
189 ------------------------------------------------------------------------
190 -- The propositional equality setoid over products can be
191 -- decomposed using ×-Rel
192
193 ≡×≡⇒≡ : Pointwise _≡_ _≡_ ⇒ _≡_ {A = A × B}
194 ≡×≡⇒≡ (≡.refl , ≡.refl) = ≡.refl
195
196 ≡⇒≡×≡ : _≡_ {A = A × B} ⇒ Pointwise _≡_ _≡_
197 ≡⇒≡×≡ ≡.refl = (≡.refl , ≡.refl)
198
199 Pointwise-≡↔≡ : Inverse (≡.setoid A ×ₛ ≡.setoid B) (≡.setoid (A × B))
200 Pointwise-≡↔≡ = record
201 { to = id
202 ; from = id
203 ; to-cong = ≡×≡⇒≡
204 ; from-cong = ≡⇒≡×≡
205 ; inverse = ≡×≡⇒≡ , ≡⇒≡×≡
206 }