(***************************************************)
(** * Applying functions to the elements of a list *)
(***************************************************)
(************)
(** ** Map  *)
(************)
Section Map.
Variables (A : Type) (B : Type).
Variable f : A -> B.
Local Notation map := (@map A B f).

(* Specifications: *)
Lemma map_cons (x:A)(l:list A) : map (x::l) = (f x) :: (map l).
Lemma in_map :
forall (l:list A) (x:A), In x l -> In (f x) (map l).
Lemma in_map_iff : forall l y, In y (map l) <-> exists x, f x = y /\ In x l.
Lemma length_map : forall l, length (map l) = length l.
Lemma map_nth : forall l d n,
nth n (map l) (f d) = f (nth n l d).
Lemma nth_error_map : forall n l,
nth_error (map l) n = option_map f (nth_error l n).
Lemma map_nth_error : forall n l d,
nth_error l n = Some d -> nth_error (map l) n = Some (f d).
Lemma tl_map l : tl (map l) = map (tl l).
Lemma map_last : forall l a,
map (l ++ [a]) = (map l) ++ [f a].
Lemma map_rev : forall l, map (rev l) = rev (map l).
Lemma map_eq_nil : forall l, map l = [] -> l = [].
Lemma map_eq_cons : forall l l' b,
map l = b :: l' -> exists a tl, l = a :: tl /\ f a = b /\ map tl = l'.
Lemma map_eq_app  : forall l l1 l2,
map l = l1 ++ l2 -> exists l1' l2', l = l1' ++ l2' /\ map l1' = l1 /\ map l2' = l2.