(* Compute the number of occurrences of an element in a message *)
Fixpoint number_of_occurrences (a : A) (l : list A) {struct l} : nat :=
  match l with
  | nil => 0
  | b :: l1 =>
      match eqA_dec a b with
      | left _ => S (number_of_occurrences a l1)
      | right _ => number_of_occurrences a l1
      end
  end.

(* Specifications: *)
Theorem number_of_occurrences_O : forall a l, ~ In a l -> number_of_occurrences a l = 0.
Theorem number_of_occurrences_permutation_ex : forall (m : list A) (a : A), exists m1 : list A, permutation m (id_list a (number_of_occurrences a m) ++ m1) /\ ~ In a m1.
Theorem number_of_occurrences_app : forall l1 l2 a, number_of_occurrences a (l1 ++ l2) = number_of_occurrences a l1 + number_of_occurrences a l2.
Theorem number_of_occurrences_permutation : forall l1 l2 a, permutation l1 l2 -> number_of_occurrences a l1 = number_of_occurrences a l2.
Theorem frequency_number_of_occurrences : forall a m, In a m -> In (a, number_of_occurrences a m) (frequency_list m).