88
99module Data.Vec.Relation.Binary.Pointwise.Inductive where
1010
11+ open import Algebra.Definitions
12+ using (Associative; Commutative; LeftIdentity; RightIdentity; Congruent₂)
1113open import Data.Fin.Base using (Fin; zero; suc)
1214open import Data.Nat.Base using (ℕ; zero; suc)
1315open import Data.Product.Base using (_×_; _,_; uncurry; <_,_>)
@@ -33,6 +35,7 @@ private
3335 B : Set b
3436 C : Set c
3537 D : Set d
38+ n : ℕ
3639
3740------------------------------------------------------------------------
3841-- Definition
@@ -232,6 +235,42 @@ module _ {_∼_ : Rel A ℓ} (refl : Reflexive _∼_) where
232235 cong-[ zero ]≔ p (_ ∷ eqn) = refl ∷ eqn
233236 cong-[ suc i ]≔ p (x∼y ∷ eqn) = x∼y ∷ cong-[ i ]≔ p eqn
234237
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+
235274------------------------------------------------------------------------
236275-- Degenerate pointwise relations
237276
0 commit comments