(* 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.

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)).