(* Turn a code into a tree *) 
Definition pbbuild (l : code A) : pbtree :=
  fold_right (fun a c => pbadd (fst a) c (snd a)) (pbleaf empty) l.

(* Specifications: *)
Theorem pbfree_pbbuild_prop1 : forall a l1 l2, l2 <> nil -> unique_prefix ((a, l1) :: l2) -> pbfree l1 (pbbuild l2).
Theorem all_pbleaves_compute_pb : forall t, permutation (map (fst (B:=_)) (compute_pbcode t)) (all_pbleaves t).
Theorem pbbuild_compute_perm : forall c, c <> nil -> unique_prefix c -> permutation (compute_pbcode (pbbuild c)) c.
Theorem all_pbleaves_pbbuild : forall c, c <> nil -> unique_prefix c -> permutation (map (fst (B:=_)) c) (all_pbleaves (pbbuild c)).
Theorem inpb_pbbuild_inv : forall a c, c <> nil -> inpb (pbleaf a) (pbbuild c) -> exists l : _, In (a, l) c.
Theorem pbbuild_distinct_pbleaves : forall c, unique_prefix c -> distinct_pbleaves (pbbuild c).
Theorem pbbuild_compute_peq : forall t, distinct_pbleaves t -> pbbuild (compute_pbcode t) = t.
Theorem pbbuild_true_pbright : forall c, c <> nil -> pbbuild (map (fun x => (fst x, true :: snd x)) c) = pbright (pbbuild c).
Theorem pbbuild_pbnode : forall c1 c2, c1 <> nil -> c2 <> nil -> pbbuild (map (fun x => (fst x, false :: snd x)) c1 ++ map (fun x => (fst x, true :: snd x)) c2) = pbnode (pbbuild c1) (pbbuild c2).