aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Sébastien Hinderer <Sebastien.Hinderer@inria.fr>2015-01-09 17:30:32 +0100
committerGravatar Pierre Letouzey <pierre.letouzey@inria.fr>2015-01-16 14:58:43 +0100
commitf00d64c419351ec25fe84050d233c651bd0c76a0 (patch)
tree64e3556a6d821ccaa06465b1cdfa3e4448960ace
parent5118952ff4eeb0e4c1c24274167614584012c348 (diff)
Add two lemmas about firstn to the List standard library.
-rw-r--r--theories/Lists/List.v22
1 files changed, 22 insertions, 0 deletions
diff --git a/theories/Lists/List.v b/theories/Lists/List.v
index 940b2f1e4..85e364c01 100644
--- a/theories/Lists/List.v
+++ b/theories/Lists/List.v
@@ -1655,6 +1655,15 @@ Section Cutting.
- apply Peano.le_n_S, iHk.
Qed.
+ Lemma firstn_length_le: forall l:list A, forall n:nat,
+ n <= length l -> length (firstn n l) = n.
+ Proof. induction l as [|x xs Hrec].
+ - simpl. intros n H. apply le_n_0_eq in H. rewrite <- H. now simpl.
+ - destruct n.
+ * now simpl.
+ * simpl. intro H. apply le_S_n in H. now rewrite (Hrec n H).
+ Qed.
+
Lemma firstn_app n:
forall l1 l2,
firstn n (l1 ++ l2) = (firstn n l1) ++ (firstn (n - length l1) l2).
@@ -1679,6 +1688,19 @@ Section Cutting.
rewrite H0, firstn_all2; [reflexivity | auto with arith].
Qed.
+ Lemma firstn_firstn:
+ forall l:list A,
+ forall i j : nat,
+ firstn i (firstn j l) = firstn (min i j) l.
+ Proof. induction l as [|x xs Hl].
+ - intros. simpl. now rewrite ?firstn_nil.
+ - destruct i.
+ * intro. now simpl.
+ * destruct j.
+ + now simpl.
+ + simpl. f_equal. apply Hl.
+ Qed.
+
Fixpoint skipn (n:nat)(l:list A) : list A :=
match n with
| 0 => l