Fixpoint weight_tree (t : btree A) : nat :=
  match t with
  | leaf n => 0
  | node t1 t2 =>
      sum_leaves t1 + weight_tree t1 + (sum_leaves t2 + weight_tree t2)
  end.Definition weight_tree_list : list (btree A) -> nat :=
  fold_right (fun x : btree A => plus (weight_tree x)) 0.

Theorem ordered_sum_leaves_eq : forall (A : Type) (f : A -> nat) (l1 l2 : list (btree A)), permutation l1 l2 -> ordered (sum_order f) l1 -> ordered (sum_order f) l2 -> map (sum_leaves f) l1 = map (sum_leaves f) l2.