Section tree_ind.
Variable P : tree -> Prop.
Hypothesis P_atom : forall a, P (atom a).
Hypothesis P_node : forall l, List.Forall P l -> P (node l).
Definition tree_ind (t : tree) : P t :=
tree_rect P (List.Forall P)
(List.Forall_nil _)
(fun t l Pt Pl => List.Forall_cons _ Pt Pl) P_atom P_node t.
End tree_ind.
End tree.
Fixpoint rev_rec {A} (l : list A) (acc : list A) :=
match l with
| [] => acc
| a :: l => rev_rec l (a :: acc)
end.
Definition rev' {A} (l : list A) :=
rev_rec l [].
Fixpoint map_rec {A B} (f : A -> B) (l : list A) (acc : list B) :=
match l with
| [] => rev' acc
| a :: l => map_rec f l (f a :: acc)
end.

Lemma map_rec_spec : forall {A B} (f : A -> B) (l : list A) (acc : list B),
map_rec f l acc = rev acc ++ List.map f l.