Proof using.
intros a l1 l n; elim n; simpl in |- *; auto.
intros n0 H; case (eqA_dec a a); auto.
intros e; rewrite length_app; rewrite H; auto.
intros H1; case H1; auto.
Qed.

Theorem frequency_length :
forall (m : list A) (c : code A),
unique_key c ->
length (encode eqA_dec c m) =
fold_left
(fun a b => a + number_of_occurrences eqA_dec (fst b) m * length (snd b))
c 0.