Skip to content

Commit 21c9ee9

Browse files
committed
More results on List.zip
New lemmas: `zip0l`, `zip0r`, `take_zip`, `drop_zip`.
1 parent 1a3aa22 commit 21c9ee9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

theories/datatypes/List.ec

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,6 +3356,12 @@ abbrev unzip2 ['a 'b] (s : ('a * 'b) list) = map snd s.
33563356
abbrev amap ['a 'b 'c] (f : 'a -> 'b -> 'c) (xs : ('a * 'b) list) =
33573357
map (fun xy => (fst xy, f (fst xy) (snd xy))) xs.
33583358
3359+
lemma zip0l ['a 'b] (s : 'b list): zip<:'a, 'b> [] s = [].
3360+
proof. by case: s. qed.
3361+
3362+
lemma zip0r ['a 'b] (s : 'a list): zip<:'a, 'b> s [] = [].
3363+
proof. by case: s. qed.
3364+
33593365
lemma zip_unzip ['a 'b] (s : ('a * 'b) list) :
33603366
zip (unzip1 s) (unzip2 s) = s.
33613367
proof. by elim: s => // -[x y s]. qed.
@@ -3493,6 +3499,28 @@ elim: xs ys n => [|x xs ih] [|y ys] n //=; case: xy ih => [x' y'] ih.
34933499
by case: (n = 0) => // _; apply/ih.
34943500
qed.
34953501

3502+
lemma take_zip ['a 'b] (k : int) (s1 : 'a list) (s2 : 'b list) :
3503+
take k (zip s1 s2) = zip (take k s1) (take k s2).
3504+
proof.
3505+
elim/natind: k s1 s2.
3506+
- by move=> n le0_n s1 s2; rewrite !take_le0.
3507+
move=> n ge0_h ih [|x1 s1] [|x2 s2] //=.
3508+
- by rewrite zip0l.
3509+
- by rewrite zip0r.
3510+
- by rewrite !ifF ~-1:/# /= &(ih).
3511+
qed.
3512+
3513+
lemma drop_zip ['a 'b] (k : int) (s1 : 'a list) (s2 : 'b list) :
3514+
drop k (zip s1 s2) = zip (drop k s1) (drop k s2).
3515+
proof.
3516+
elim/natind: k s1 s2.
3517+
- by move=> n le0_n s1 s2; rewrite !drop_le0.
3518+
move=> n ge0_h ih [|x1 s1] [|x2 s2] //=.
3519+
- by rewrite zip0l.
3520+
- by rewrite zip0r.
3521+
- by rewrite !ifF ~-1:/# /= &(ih).
3522+
qed.
3523+
34963524
lemma eq_keys_amap ['a, 'b1, 'b2, 'c]
34973525
(f : 'a -> 'b1 -> 'c) (g : 'a -> 'b2 -> 'c) xs ys
34983526
: amap f xs = amap g ys => unzip1 xs = unzip1 ys.

0 commit comments

Comments
 (0)