(**************************************)
(** * Cutting a list at some position *)
(**************************************)
Section Cutting.
Variable A : Type.
Local Notation firstn := (@firstn A).
Local Notation skipn := (@skipn A).

(* Specifications: *)
Lemma firstn_nil n: firstn n [] = [].
Lemma nth_firstn (n : nat) (l : list A) (i : nat) (d : A) :
nth i (firstn n l) d = if i <? n then nth i l d else d.
Lemma firstn_all l: firstn (length l) l = l.
Lemma firstn_0 l: firstn 0 l = [].
Lemma firstn_length_le: forall l:list A, forall n:nat,
n <= length l -> length (firstn n l) = n.
Lemma firstn_app n:
forall l1 l2,
firstn n (l1 ++ l2) = (firstn n l1) ++ (firstn (n - length l1) l2).
Lemma firstn_app_2 n:
forall l1 l2,
firstn ((length l1) + n) (l1 ++ l2) = l1 ++ firstn n l2.
Lemma firstn_firstn:
forall l:list A,
forall i j : nat,
firstn i (firstn j l) = firstn (min i j) l.
Lemma nth_error_skipn n l i : nth_error (skipn n l) i = nth_error l (n + i).
Lemma nth_skipn n l i d : nth i (skipn n l) d = nth (n + i) l d.
Lemma hd_error_skipn n l : hd_error (skipn n l) = nth_error l n.
Lemma skipn_all_iff n l : length l <= n <-> skipn n l = [].
Lemma skipn_skipn : forall x y l, skipn x (skipn y l) = skipn (x + y) l.
Lemma firstn_skipn : forall n l, firstn n l ++ skipn n l = l.
Lemma firstn_skipn_middle n l x :
nth_error l n = Some x ->
firstn n l ++ x :: skipn (S n) l = l.
Lemma length_firstn : forall n l, length (firstn n l) = min n (length l).
Lemma length_skipn n :
forall l, length (skipn n l) = length l - n.
Lemma skipn_app n : forall l1 l2,
skipn n (l1 ++ l2) = (skipn n l1) ++ (skipn (n - length l1) l2).
Lemma firstn_rev: forall x l,
firstn x (rev l) = rev (skipn (length l - x) l).
Lemma skipn_rev: forall x l,
skipn x (rev l) = rev (firstn (length l - x) l).
Lemma removelast_firstn : forall n l, n < length l ->
removelast (firstn (S n) l) = firstn n l.
Lemma removelast_firstn_len : forall l,
removelast l = firstn (pred (length l)) l.
Lemma firstn_removelast : forall n l, n < length l ->
firstn n (removelast l) = firstn n l.