Proof using.
cut
(forall b l,
map (fst (B:=_))
(map (fun v : A * list bool => let (a1, b1) := v in (a1, b :: b1)) l) =
map (fst (B:=_)) l); [ intros HH | idtac ].
intros t; elim t; simpl in |- *; auto.
intros p H; rewrite HH; auto.
intros p H; rewrite HH; auto.
intros p H p0 H0; rewrite map_app; apply permutation_app_comp; auto.
repeat rewrite HH; auto.
repeat rewrite HH; auto.
intros b l; elim l; simpl in |- *; auto.
intros a l0 H1; apply f_equal2 with (f := cons (A:=A)); auto.
case a; simpl in |- *; auto.
Qed.

(* Specifications: *)
(* Taking a code, turning it in a tree, then computing a code gives a permutation of the initial code *)
Theorem pbbuild_compute_perm :
forall c,
c <> nil -> unique_prefix c -> permutation (compute_pbcode (pbbuild c)) c.