(* Transform a tree in a code *) 
Fixpoint compute_pbcode (a : pbtree) : code A :=
  match a with
  | pbleaf b => (b, nil) :: nil
  | pbleft l1 =>
      map
        (fun v : A * list bool =>
         match v with
         | (a1, b1) => (a1, false :: b1)
         end) (compute_pbcode l1)
  | pbright l1 =>
      map
        (fun v : A * list bool =>
         match v with
         | (a1, b1) => (a1, true :: b1)
         end) (compute_pbcode l1)
  | pbnode l1 l2 =>
      map
        (fun v : A * list bool =>
         match v with
         | (a1, b1) => (a1, false :: b1)
         end) (compute_pbcode l1) ++
      map
        (fun v : A * list bool =>
         match v with
         | (a1, b1) => (a1, true :: b1)
         end) (compute_pbcode l2)
  end.

Theorem pb_unique_key : forall t, distinct_pbleaves t -> unique_key (compute_pbcode t).