Skip to content

Commit 6db08b3

Browse files
authored
Add properties of zipWith to Pointwise (#2703)
1 parent 8c5dee3 commit 6db08b3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ Additions to existing modules
232232
filter-↭ : ∀ (P? : Pred.Decidable P) → xs ↭ ys → filter P? xs ↭ filter P? ys
233233
```
234234

235+
* In `Data.Vec.Relation.Binary.Pointwise.Inductive`:
236+
```agda
237+
zipWith-assoc : Associative _∼_ f → Associative (Pointwise _∼_) (zipWith {n = n} f)
238+
zipWith-identityˡ: LeftIdentity _∼_ e f → LeftIdentity (Pointwise _∼_) (replicate n e) (zipWith f)
239+
zipWith-identityʳ: RightIdentity _∼_ e f → RightIdentity (Pointwise _∼_) (replicate n e) (zipWith f)
240+
zipWith-comm : Commutative _∼_ f → Commutative (Pointwise _∼_) (zipWith {n = n} f)
241+
zipWith-cong : Congruent₂ _∼_ f → Pointwise _∼_ ws xs → Pointwise _∼_ ys zs → Pointwise _∼_ (zipWith f ws ys) (zipWith f xs zs)
242+
```
243+
235244
* In `Relation.Binary.Construct.Add.Infimum.Strict`:
236245
```agda
237246
<₋-accessible-⊥₋ : Acc _<₋_ ⊥₋

src/Data/Vec/Relation/Binary/Pointwise/Inductive.agda

+39
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
module Data.Vec.Relation.Binary.Pointwise.Inductive where
1010

11+
open import Algebra.Definitions
12+
using (Associative; Commutative; LeftIdentity; RightIdentity; Congruent₂)
1113
open import Data.Fin.Base using (Fin; zero; suc)
1214
open import Data.Nat.Base using (ℕ; zero; suc)
1315
open 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

Comments
 (0)