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

(* Specifications: *)
Theorem restrict_code_unique_key : forall c : code A, unique_key (restrict_code m c).
Theorem restrict_code_in : forall (a : A) (c : code A), In a m -> find_code eqA_dec a c = find_code eqA_dec a (restrict_code m c).
Theorem restrict_code_encode_incl : forall (m1 : list A) (c : code A), incl m1 m -> encode eqA_dec c m1 = encode eqA_dec (restrict_code m c) m1.
Theorem restrict_code_encode : forall c : code A, encode eqA_dec c m = encode eqA_dec (restrict_code m c) m.
Theorem restrict_unique_prefix : forall c : code A, not_null c -> in_alphabet m c -> unique_prefix c -> unique_prefix (restrict_code m c).
Theorem frequency_list_restric_code_map : forall c, map (fst (B:=_)) (frequency_list eqA_dec m) = map (fst (B:=_)) (restrict_code m c).
Theorem restrict_not_null : forall c, m <> nil -> restrict_code m c <> nil.
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))).