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 ulist_unique_key : forall (A B : Type) (l : list (A * B)), ulist (map (fst (B:=_)) l) -> unique_key l.
Theorem restrict_code_unique_key : forall (m : list A) (c : code A), unique_key (restrict_code m c).
Theorem restrict_code_in : forall (m : list A) (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_length_inc : forall (m 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_length : forall (m : list A) (c : code A), encode eqA_dec c m = encode eqA_dec (restrict_code m c) m.