(* Uniqueleaf is decidable *)
Definition distinct_leaves_dec :
  forall a, {distinct_leaves a} + {~ distinct_leaves a}.(* Compute the code associated with a binary tree *)
Fixpoint compute_code (a : btree) : list (A * list bool) :=
  match a with
  | leaf b => (b, nil) :: nil
  | node l1 l2 =>
      map
        (fun v : A * list bool =>
         match v with
         | (a1, b1) => (a1, false :: b1)
         end) (compute_code l1) ++
      map
        (fun v : A * list bool =>
         match v with
         | (a1, b1) => (a1, true :: b1)
         end) (compute_code l2)
  end.

(* Specifications: *)
Theorem length_compute_lt_O : forall t, 0 < length (compute_code t).
Theorem inCompute_inb : forall (t : btree) (a : A) (l : list bool), In (a, l) (compute_code t) -> inb (leaf a) t.
Theorem inb_compute_ex : forall a p, inb (leaf a) p -> exists l : _, In (a, l) (compute_code p).
Theorem in_alphabet_compute_code : forall m t, (forall a : A, In a m -> inb (leaf a) t) -> in_alphabet m (compute_code t).
Theorem btree_unique_prefix1 : forall (t : btree) (a1 a2 : A) (lb1 lb2 : list bool), In (a1, lb1) (compute_code t) -> In (a2, lb2) (compute_code t) -> is_prefix lb1 lb2 -> a1 = a2.
Theorem btree_unique_prefix2 : forall t : btree, distinct_leaves t -> unique_key (compute_code t).
Theorem btree_unique_prefix : forall t : btree, distinct_leaves t -> unique_prefix (compute_code t).