(* the sum leaves are the same upto permutation *)
Definition same_sum_leaves (l1 l2 : list (btree A)) : Prop :=
  exists l3 : list (btree A),
    (exists l4 : list (btree A),
       permutation l1 l3 /\
       permutation l2 l4 /\ map (sum_leaves f) l3 = map (sum_leaves f) l4).

Theorem same_sum_leaves_length : forall l1 l2 : list (btree A), same_sum_leaves l1 l2 -> length l1 = length l2.