Section Lists_field.
Variable A : Set.
Fixpoint trunc (v : list A) : nat -> list A :=
fun n : nat =>
match v return (list A) with
| nil => nil
| b :: w =>
match n return (list A) with
| O => nil
| S p => b :: trunc w p
end
end.
Definition strip (v : list A) (n : nat) :=
rev A (trunc (rev A v) (length v - n)).
(* Selection d'une sous liste commencant a la position start, de longueur lengt *)
Definition sublist (v : list A) (start lengt : nat) :=
trunc (strip v start) lengt.
(* Selection de la liste contenant le i-eme element d'une liste *)
Definition elemlist (v : list A) (i : nat) := trunc (strip v i) 1.
(****************************************************************)
(* lemmes sur trunc *)
(*****************)
simple induction v. simpl in |- *. auto with arith.
intros b b0 H. simple induction i. simpl in |- *. trivial with arith.
simpl in |- *. intros. apply eq_S. apply H. apply le_S_n. exact H1.
Qed.
(**************)
simpl in |- *. trivial with arith.
Qed.
(**************)
simple induction v. simpl in |- *. trivial with arith.
intros. rewrite length_eq2. simpl in |- *. rewrite H. trivial with arith.
Qed. Hint Resolve trunc_all.
(**************)
simple induction v. simpl in |- *. trivial with arith.
intros. inversion H0. rewrite trunc_all. trivial with arith.
simpl in |- *. rewrite H. trivial with arith.
apply le_Sn_le. generalize H1. simpl in |- *. trivial with arith.
Qed.
(************)
simple induction v; auto with arith.
Qed. Hint Resolve trunc_O.
(********************)
simple induction v. simpl in |- *. auto with arith.
intros. case i. rewrite trunc_O. auto with arith.
intro. simpl in |- *. apply le_n_S. apply H.
Qed. Hint Resolve le_length_trunc.
(**************)
simple induction v1. simpl in |- *. auto with arith.
intros. rewrite app_eq2.
rewrite length_eq2. elim i. simpl in |- *. rewrite trunc_O. trivial with arith.
intros. simpl in |- *. rewrite H. trivial with arith.
Qed. Hint Resolve trunc_app.

Lemma app_v_trunc :
forall (v1 v2 : list A) (i : nat),
v1 ++ trunc v2 i = trunc (v1 ++ v2) (length v1 + i).