Skip to content

Commit 5f5d3f6

Browse files
authored
List: new lemmas: nth0, nth1, map1, head_drop (#796)
1 parent ebec96e commit 5f5d3f6

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

theories/datatypes/List.ec

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ lemma onth_nth (z : 'a) xs n:
264264
0 <= n < size xs => onth xs n = Some (nth z xs n).
265265
proof. by elim: xs n => //= /#. qed.
266266

267+
lemma nth0 ['a] (x : 'a) :
268+
nth witness [x] 0 = x.
269+
proof. by done. qed.
270+
271+
lemma nth1 ['a] (x0 : 'a) (x : 'a) (i : int) :
272+
nth x0 [x] i = if i = 0 then x else x0.
273+
proof. by done. qed.
274+
267275
lemma nth0_head (z : 'a) xs: nth z xs 0 = head z xs.
268276
proof. by case: xs. qed.
269277
@@ -1000,6 +1008,10 @@ move=> n_ge0 i_ge0; case: (n < size s) => [lt_n_s|le_s_n].
10001008
- by rewrite !(nth_out, drop_oversize) //#.
10011009
qed.
10021010
1011+
lemma head_drop ['a] (x0 : 'a) (n : int) (l : 'a list) :
1012+
0 <= n => nth x0 l n = head x0 (drop n l).
1013+
proof. by move=> ge0_n; rewrite -nth0_head nth_drop. qed.
1014+
10031015
lemma nth_take (x0 : 'a) n s i:
10041016
0 <= n => i < n => nth x0 (take n s) i = nth x0 s i.
10051017
proof.
@@ -1804,6 +1816,10 @@ op map (f : 'a -> 'b) xs =
18041816
with xs = [] => []
18051817
with xs = y :: ys => (f y) :: (map f ys).
18061818

1819+
lemma map1 ['a 'b] (f: 'a -> 'b) (x : 'a) :
1820+
map f [x] = [f x].
1821+
proof. by done. qed.
1822+
18071823
lemma eq_map (f1 f2 : 'a -> 'b):
18081824
(forall x, f1 x = f2 x)
18091825
=> forall s, map f1 s = map f2 s.

0 commit comments

Comments
 (0)