8
8
9
9
module Data.Vec.Relation.Binary.Pointwise.Inductive where
10
10
11
+ open import Algebra.Definitions
12
+ using (Associative; Commutative; LeftIdentity; RightIdentity; Congruent₂)
11
13
open import Data.Fin.Base using (Fin; zero; suc)
12
14
open import Data.Nat.Base using (ℕ; zero; suc)
13
15
open import Data.Product.Base using (_×_; _,_; uncurry; <_,_>)
@@ -33,6 +35,7 @@ private
33
35
B : Set b
34
36
C : Set c
35
37
D : Set d
38
+ n : ℕ
36
39
37
40
------------------------------------------------------------------------
38
41
-- Definition
@@ -232,6 +235,42 @@ module _ {_∼_ : Rel A ℓ} (refl : Reflexive _∼_) where
232
235
cong-[ zero ]≔ p (_ ∷ eqn) = refl ∷ eqn
233
236
cong-[ suc i ]≔ p (x∼y ∷ eqn) = x∼y ∷ cong-[ i ]≔ p eqn
234
237
238
+ ------------------------------------------------------------------------
239
+ -- zipWith
240
+
241
+ module _ {_∼_ : Rel A ℓ} where
242
+ module _ {f : A → A → A} where
243
+ zipWith-assoc : Associative _∼_ f →
244
+ Associative (Pointwise _∼_) (zipWith {n = n} f)
245
+ zipWith-assoc assoc [] [] [] = []
246
+ zipWith-assoc assoc (x ∷ xs) (y ∷ ys) (z ∷ zs) = assoc x y z ∷ zipWith-assoc assoc xs ys zs
247
+
248
+ module _ {f : A → A → A} {e : A} where
249
+ zipWith-identityˡ : LeftIdentity _∼_ e f →
250
+ LeftIdentity (Pointwise _∼_) (replicate n e) (zipWith f)
251
+ zipWith-identityˡ idˡ [] = []
252
+ zipWith-identityˡ idˡ (x ∷ xs) = idˡ x ∷ zipWith-identityˡ idˡ xs
253
+
254
+ zipWith-identityʳ : RightIdentity _∼_ e f →
255
+ RightIdentity (Pointwise _∼_) (replicate n e) (zipWith f)
256
+ zipWith-identityʳ idʳ [] = []
257
+ zipWith-identityʳ idʳ (x ∷ xs) = idʳ x ∷ zipWith-identityʳ idʳ xs
258
+
259
+ module _ {f : A → A → A} where
260
+ zipWith-comm : Commutative _∼_ f →
261
+ Commutative (Pointwise _∼_) (zipWith {n = n} f)
262
+ zipWith-comm comm [] [] = []
263
+ zipWith-comm comm (x ∷ xs) (y ∷ ys) = comm x y ∷ zipWith-comm comm xs ys
264
+
265
+ module _ {f : A → A → A} where
266
+ zipWith-cong : ∀ {m n}
267
+ {ws : Vec A m} {xs : Vec A n} {ys : Vec A m} {zs : Vec A n} →
268
+ Congruent₂ _∼_ f →
269
+ Pointwise _∼_ ws xs → Pointwise _∼_ ys zs →
270
+ Pointwise _∼_ (zipWith f ws ys) (zipWith f xs zs)
271
+ zipWith-cong cong [] [] = []
272
+ zipWith-cong cong (x∼y ∷ xs) (a∼b ∷ ys) = cong x∼y a∼b ∷ zipWith-cong cong xs ys
273
+
235
274
------------------------------------------------------------------------
236
275
-- Degenerate pointwise relations
237
276
0 commit comments