(* Turn a partial tree into a binary tree *)
Fixpoint to_btree (a : pbtree A) : btree A :=
  match a with
  | pbleaf b => leaf b
  | pbleft l1 => to_btree l1
  | pbright l1 => to_btree l1
  | pbnode l1 l2 => node (to_btree l1) (to_btree l2)
  end.

(* Specifications: *)
Theorem to_btree_inb : forall a b, inpb (pbleaf a) b -> inb (leaf a) (to_btree b).
Theorem to_btree_inpb : forall a b, inb (leaf a) (to_btree b) -> inpb (pbleaf a) b.
Theorem to_btree_all_leaves : forall t, all_leaves (to_btree t) = all_pbleaves t.
Theorem to_btree_distinct_leaves : forall a : pbtree A, distinct_pbleaves a -> distinct_leaves (to_btree a).
Theorem to_btree_distinct_pbleaves : forall a : pbtree A, distinct_leaves (to_btree a) -> distinct_pbleaves a.
Theorem to_btree_smaller : forall t a, length (find_code eqA_dec a (compute_code (to_btree t))) <= length (find_code eqA_dec a (compute_pbcode t)).