(* File: Trees.v  (last edited on 25/10/2000) (c) Klaus Weich  *)
Require Export My_Arith.
(******   Tree stuff  ********************************************)
Section Trees.
Variable A : Set.
Inductive Tree : Set :=
node : A -> Forest -> Tree
with Forest : Set :=
| Nil_Forest : Forest
| Cons_Forest : Tree -> Forest -> Forest.
Fixpoint height_tree (t : Tree) : nat :=
match t with
| node a succs => S (height_forest succs)
end
with height_forest (succs : Forest) : nat :=
match succs with
| Nil_Forest => 0
| Cons_Forest t0 succs => max (height_tree t0) (height_forest succs)
end.
(* Inductive Tree : Set := | node : A -> (list Tree) -> Tree.  Fixpoint height_tree [t:Tree] : nat := Cases t of | (node a succs) => (S (height_forest succs)) end with height_forest[succs:(list Tree)] : nat := Cases succs of | nil => O | (cons t0 succs) => (max (height_tree t0) (height_forest succs)) end. Does not work!! *)
Definition root (t : Tree) := match t with
| node a _ => a
end.
Definition successors (t : Tree) := match t with
| node _ succs => succs
end.
Inductive In_Forest (t0 : Tree) : Forest -> Prop :=
| in_forest_head :
forall succs : Forest, In_Forest t0 (Cons_Forest t0 succs)
| in_forest_tail :
forall (t1 : Tree) (succs : Forest),
In_Forest t0 succs -> In_Forest t0 (Cons_Forest t1 succs).

Lemma height_in_le :
forall (t : Tree) (succs : Forest),
In_Forest t succs -> height_tree t <= height_forest succs.