Section Huffman.
Variable A : Type.
Variable empty : A.
Variable eqA_dec : forall a b : A, {a = b} + {a <> b}.
Variable m : list A.
Hypothesis frequency_more_than_one : 1 < length (frequency_list eqA_dec m).
Proof using A eqA_dec frequency_more_than_one m.
generalize frequency_more_than_one; case m; simpl in |- *; auto.
intros H; Contradict H; auto with arith.
intros; discriminate.
Qed.

(* Every tree that is built is of minimum weight *)
Theorem huffman_build_minimun :
forall (c : code A) (t : btree A),
unique_prefix c ->
in_alphabet m c ->
build (fun x => number_of_occurrences eqA_dec x m)
(map (fun x => leaf (fst x)) (frequency_list eqA_dec m)) t ->
weight eqA_dec m (compute_code t) <= weight eqA_dec m c.