Proof using.
intros n t; generalize n; elim t; clear t n; simpl in |- *; auto.
intros b H b0 H0 n.
repeat rewrite map_app.
cut
(forall (b : bool) l,
map (fun x : A * list bool => length (snd x) + n)
(map (fun v : A * list bool => let (a1, b1) := v in (a1, b :: b1)) l) =
map (fun x : A * list bool => length (snd x) + S n) l);
[ intros E1 | idtac ].
cut
(forall b l,
map (fun x : A * list bool => leaf (fst x))
(map (fun v : A * list bool => let (a1, b1) := v in (a1, b :: b1)) l) =
map (fun x : A * list bool => leaf (fst x)) l); [ intros E2 | idtac ].
apply height_pred_node; repeat rewrite E1; repeat rewrite E2; auto.
intros b1 l; elim l; simpl in |- *; auto.
intros a; case a; simpl in |- *; auto.
intros a0 l0 l1 H1; apply f_equal2 with (f := cons (A:=btree A)); auto.
intros b1 l; elim l; simpl in |- *; auto.
intros a; case a; simpl in |- *; auto.
intros a0 l0 l1 H1; apply f_equal2 with (f := cons (A:=nat)); auto.
Qed.

(* Specifications: *)
(* A consequence of the previous theorem, the weight of the tree is exactly the encoding of the message of the corresponding code *)
Theorem weight_tree_compute :
forall (m : list A) t,
distinct_leaves t ->
(forall a : A, f a = number_of_occurrences eqA_dec a m) ->
length (encode eqA_dec (compute_code t) m) = weight_tree f t.