(** * Addendum to the standard library of Coq *)
Require Export Omega.
Global Obligation Tactic := idtac.
Notation "[ x ; .. ; y ]" := (cons x .. (cons y nil) .. ).
Definition andl {A} (P:A->Prop)(l:list A) : Prop :=
fold_right (fun a res => P a /\ res) True l.
Fixpoint fun_power {A:Type}(n:nat)(f:A->A)(x:A) : A :=
match n with
| 0 => x
| S n' => f (fun_power n' f x)
end.
Definition mod2 (n : nat) : nat :=
n - 2 * div2 n.
Fixpoint power (m n:nat) : nat :=
match n with
| 0 => 1
| S n' => m * power m n'
end.
Definition plusl (l:list nat) : nat :=
fold_right plus 0 l.
Definition multl (l:list nat) : nat :=
fold_right mult 1 l.
Fixpoint maxl l :=
match l with
| nil => 0
| a :: l' => max a (maxl l')
end.
Fixpoint repeat {A:Type}(n:nat)(x:A) : list A :=
match n with
| 0 => nil
| S n' => x :: repeat n' x
end.
Definition move_forward {A}(i j:nat)(l:list A)(d:A) : list A :=
firstn i l ++ firstn j (skipn (S i) l) ++ (nth i l d :: skipn (S (i+j)) l).

Lemma move_forward_map A B d1 d2 i j (f:A->B) l :
f d1 = d2 ->
move_forward i j (map f l) d2 = map f (move_forward i j l d1).