(* Create a list of a given length with a given element  *)
Fixpoint id_list (a : A) (n : nat) {struct n} : list A :=
  match n with
  | O => nil
  | S n1 => a :: id_list a n1
  end.(* An element in a frequency list *)
Fixpoint add_frequency_list (a : A) (l : list (A * nat)) {struct l} :
 list (A * nat) :=
  match l with
  | nil => (a, 1) :: nil
  | (b, n) :: l1 =>
      match eqA_dec a b with
      | left _ => (a, S n) :: l1
      | right _ => (b, n) :: add_frequency_list a l1
      end
  end.

(* Specifications: *)
Theorem add_frequency_list_perm : forall (a : A) l, permutation (a :: flat_map (fun p => id_list (fst p) (snd p)) l) (flat_map (fun p => id_list (fst p) (snd p)) (add_frequency_list a l)).
Theorem add_frequency_list_in_inv : forall (a1 a2 : A) (b1 : nat) l, In (a1, b1) (add_frequency_list a2 l) -> a1 = a2 \/ In (a1, b1) l.
Theorem add_frequency_list_unique_key : forall (a : A) l, unique_key l -> unique_key (add_frequency_list a l).
Theorem add_frequency_list_1 : forall a l, (forall ca, ~ In (a, ca) l) -> In (a, 1) (add_frequency_list a l).
Theorem add_frequency_list_in : forall m a n, unique_key m -> In (a, n) m -> In (a, S n) (add_frequency_list a m).
Theorem add_frequency_list_not_in : forall m a b n, a <> b -> In (a, n) m -> In (a, n) (add_frequency_list b m).