(* Restrict the code putting only codes of element in the frequency list *)
Definition restrict_code (m : list A) (c : code A) : 
  code A :=
  map (fun x => (fst x, find_code eqA_dec (fst x) c))
    (frequency_list eqA_dec m).

Theorem restrict_code_pbbuild : forall c : code A, not_null c -> unique_prefix c -> in_alphabet m c -> m <> nil -> permutation (map fst (frequency_list eqA_dec m)) (all_pbleaves (pbbuild empty (restrict_code m c))).