Skip to content

Commit 4f692f8

Browse files
amblafontandreasabel
authored andcommitted
Additional lemmas about lists and vectors (#2020)
1 parent 61531e3 commit 4f692f8

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ Other minor changes
22032203
```agda
22042204
mapWith∈-id : mapWith∈ xs (λ {x} _ → x) ≡ xs
22052205
map-mapWith∈ : map g (mapWith∈ xs f) ≡ mapWith∈ xs (g ∘′ f)
2206+
index-injective : index x₁∈xs ≡ index x₂∈xs → x₁ ≈ x₂
22062207
```
22072208

22082209
* Add new proofs in `Data.List.Properties`:
@@ -2231,6 +2232,8 @@ Other minor changes
22312232
22322233
take-[] : ∀ m → take m [] ≡ []
22332234
drop-[] : ∀ m → drop m [] ≡ []
2235+
2236+
map-replicate : map f (replicate n x) ≡ replicate n (f x)
22342237
```
22352238

22362239
* Added new patterns and definitions to `Data.Nat.Base`:
@@ -2599,6 +2602,8 @@ Other minor changes
25992602
map-∷ʳ : map f (xs ∷ʳ x) ≡ (map f xs) ∷ʳ (f x)
26002603
map-reverse : map f (reverse xs) ≡ reverse (map f xs)
26012604
map-ʳ++ : map f (xs ʳ++ ys) ≡ map f xs ʳ++ map f ys
2605+
map-insert : map f (insert xs i x) ≡ insert (map f xs) i (f x)
2606+
toList-map : toList (map f xs) ≡ List.map f (toList xs)
26022607
26032608
lookup-concat : lookup (concat xss) (combine i j) ≡ lookup (lookup xss i) j
26042609
@@ -2633,6 +2638,9 @@ Other minor changes
26332638
reverse-injective : reverse xs ≡ reverse ys → xs ≡ ys
26342639
26352640
transpose-replicate : transpose (replicate xs) ≡ map replicate xs
2641+
toList-replicate : toList (replicate {n = n} a) ≡ List.replicate n a
2642+
2643+
toList-++ : toList (xs ++ ys) ≡ toList xs List.++ toList ys
26362644
26372645
toList-cast : toList (cast eq xs) ≡ toList xs
26382646
cast-is-id : cast eq xs ≡ xs
@@ -2642,6 +2650,13 @@ Other minor changes
26422650
lookup-cast : lookup (cast eq xs) (Fin.cast eq i) ≡ lookup xs i
26432651
lookup-cast₁ : lookup (cast eq xs) i ≡ lookup xs (Fin.cast (sym eq) i)
26442652
lookup-cast₂ : lookup xs (Fin.cast eq i) ≡ lookup (cast (sym eq) xs) i
2653+
2654+
zipwith-++ : zipWith f (xs ++ ys) (xs' ++ ys') ≡ zipWith f xs xs' ++ zipWith f ys ys'
2655+
```
2656+
2657+
* Added new proofs in `Data.Vec.Membership.Propositional.Properties`:
2658+
```agda
2659+
index-∈-fromList⁺ : Any.index (∈-fromList⁺ v∈xs) ≡ indexₗ v∈xs
26452660
```
26462661

26472662
* Added new proofs in `Data.Vec.Functional.Properties`:

src/Data/List/Membership/Setoid/Properties.agda

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Data.List.Membership.Setoid.Properties where
1111
open import Algebra using (Op₂; Selective)
1212
open import Data.Bool.Base using (true; false)
1313
open import Data.Fin.Base using (Fin; zero; suc)
14+
open import Data.Fin.Properties using (suc-injective)
1415
open import Data.List.Base
1516
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
1617
open import Data.List.Relation.Unary.All as All using (All)
@@ -62,6 +63,13 @@ module _ (S : Setoid c ℓ) where
6263
∉-resp-≋ : {x} (x ∉_) Respects _≋_
6364
∉-resp-≋ xs≋ys v∉xs v∈ys = v∉xs (∈-resp-≋ (≋-sym xs≋ys) v∈ys)
6465

66+
-- index is injective in its first argument.
67+
68+
index-injective : {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs)
69+
Any.index x₁∈xs ≡ Any.index x₂∈xs x₁ ≈ x₂
70+
index-injective (here x₁≈x) (here x₂≈x) _ = trans x₁≈x (sym x₂≈x)
71+
index-injective (there x₁∈xs) (there x₂∈xs) eq = index-injective x₁∈xs x₂∈xs (suc-injective eq)
72+
6573
------------------------------------------------------------------------
6674
-- Irrelevance
6775

src/Data/List/Properties.agda

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ map-injective finj {x ∷ xs} {y ∷ ys} eq =
118118
let fx≡fy , fxs≡fys = ∷-injective eq in
119119
cong₂ _∷_ (finj fx≡fy) (map-injective finj fxs≡fys)
120120

121+
map-replicate : (f : A B) n x map f (replicate n x) ≡ replicate n (f x)
122+
map-replicate f zero x = refl
123+
map-replicate f (suc n) x = cong (_ ∷_) (map-replicate f n x)
124+
121125
------------------------------------------------------------------------
122126
-- mapMaybe
123127

src/Data/Vec/Membership/Propositional/Properties.agda

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open import Data.Product.Base using (_,_; ∃; _×_; -,_; map₁; map₂)
1313
open import Data.Vec.Base
1414
open import Data.Vec.Relation.Unary.Any using (here; there)
1515
open import Data.List.Base using ([]; _∷_)
16-
open import Data.List.Relation.Unary.Any using (here; there)
16+
open import Data.List.Relation.Unary.Any as ListAny using (here; there)
1717
open import Data.Vec.Relation.Unary.Any as Any using (Any; here; there)
1818
open import Data.Vec.Membership.Propositional
1919
open import Data.List.Membership.Propositional
@@ -102,6 +102,11 @@ index-∈-lookup (suc i) (x ∷ xs) = cong suc (index-∈-lookup i xs)
102102
∈-fromList⁻ {xs = _ ∷ _} (here refl) = here refl
103103
∈-fromList⁻ {xs = _ ∷ _} (there v∈xs) = there (∈-fromList⁻ v∈xs)
104104

105+
index-∈-fromList⁺ : {v : A} {xs} (v∈xs : v ∈ₗ xs)
106+
Any.index (∈-fromList⁺ v∈xs) ≡ ListAny.index v∈xs
107+
index-∈-fromList⁺ (here refl) = refl
108+
index-∈-fromList⁺ (there v∈xs) = cong suc (index-∈-fromList⁺ v∈xs)
109+
105110
------------------------------------------------------------------------
106111
-- Relationship to Any
107112

src/Data/Vec/Properties.agda

+30
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ map-updateAt : ∀ {f : A → B} {g : A → A} {h : B → B}
448448
map-updateAt (x ∷ xs) zero eq = cong (_∷ _) eq
449449
map-updateAt (x ∷ xs) (suc i) eq = cong (_ ∷_) (map-updateAt xs i eq)
450450

451+
map-insert : (f : A B) (x : A) (xs : Vec A n) (i : Fin (suc n))
452+
map f (insert xs i x) ≡ insert (map f xs) i (f x)
453+
map-insert f _ [] Fin.zero = refl
454+
map-insert f _ (x' ∷ xs) Fin.zero = refl
455+
map-insert f x (x' ∷ xs) (Fin.suc i) = cong (_ ∷_) (map-insert f x xs i)
456+
451457
map-[]≔ : (f : A B) (xs : Vec A n) (i : Fin n)
452458
map f (xs [ i ]≔ x) ≡ map f xs [ i ]≔ f x
453459
map-[]≔ f xs i = map-updateAt xs i refl
@@ -457,6 +463,11 @@ map-⊛ : ∀ (f : A → B → C) (g : A → B) (xs : Vec A n) →
457463
map-⊛ f g [] = refl
458464
map-⊛ f g (x ∷ xs) = cong (f x (g x) ∷_) (map-⊛ f g xs)
459465

466+
toList-map : (f : A B) (xs : Vec A n)
467+
toList (map f xs) ≡ List.map f (toList xs)
468+
toList-map f [] = refl
469+
toList-map f (x ∷ xs) = cong (f x List.∷_) (toList-map f xs)
470+
460471
------------------------------------------------------------------------
461472
-- _++_
462473

@@ -509,6 +520,11 @@ lookup-splitAt (suc m) (x ∷ xs) ys (suc i) = trans
509520
(lookup-splitAt m xs ys i)
510521
(sym ([,]-map (Fin.splitAt m i)))
511522

523+
toList-++ : (xs : Vec A n) (ys : Vec A m)
524+
toList (xs ++ ys) ≡ toList xs List.++ toList ys
525+
toList-++ [] ys = refl
526+
toList-++ (x ∷ xs) ys = cong (x List.∷_) (toList-++ xs ys)
527+
512528
------------------------------------------------------------------------
513529
-- concat
514530

@@ -645,6 +661,15 @@ lookup-zipWith : ∀ (f : A → B → C) (i : Fin n) xs ys →
645661
lookup-zipWith _ zero (x ∷ _) (y ∷ _) = refl
646662
lookup-zipWith _ (suc i) (_ ∷ xs) (_ ∷ ys) = lookup-zipWith _ i xs ys
647663

664+
zipWith-++ : (f : A B C)
665+
(xs : Vec A n) (ys : Vec A m)
666+
(xs' : Vec B n) (ys' : Vec B m)
667+
zipWith f (xs ++ ys) (xs' ++ ys') ≡
668+
zipWith f xs xs' ++ zipWith f ys ys'
669+
zipWith-++ f [] ys [] ys' = refl
670+
zipWith-++ f (x ∷ xs) ys (x' ∷ xs') ys' =
671+
cong (_ ∷_) (zipWith-++ f xs ys xs' ys')
672+
648673
------------------------------------------------------------------------
649674
-- zip
650675

@@ -1002,6 +1027,11 @@ zipWith-replicate₂ _⊕_ [] y = refl
10021027
zipWith-replicate₂ _⊕_ (x ∷ xs) y =
10031028
cong (x ⊕ y ∷_) (zipWith-replicate₂ _⊕_ xs y)
10041029

1030+
toList-replicate : (n : ℕ) (x : A)
1031+
toList (replicate {n = n} a) ≡ List.replicate n a
1032+
toList-replicate zero x = refl
1033+
toList-replicate (suc n) x = cong (_ List.∷_) (toList-replicate n x)
1034+
10051035
------------------------------------------------------------------------
10061036
-- tabulate
10071037

0 commit comments

Comments
 (0)