Proof using.
intros t l H; elim H; clear H t l; simpl in |- *; auto.
intros l1 l2 t1 t2 t3 H H0 H1.
apply trans_equal with (1 := H1).
rewrite fold_left_permutation with (2 := H); simpl in |- *; auto.
rewrite permutation_length with (1 := H); simpl in |- *; auto.
rewrite fold_left_init with (h := S); simpl in |- *; auto.
intros a b1 b2; repeat rewrite plus_assoc_reverse.
apply f_equal2 with (f := plus); auto; apply plus_comm.
Qed.
(* A local function to compute all covers of a certain length *)
Fixpoint all_cover_aux (l : list (btree A)) (n : nat) {struct n} : list (btree A) :=
match n with
| O => nil
| S n1 =>
flat_map
(fun l1 =>
match l1 with
| nil => nil
| a :: nil => a :: nil
| a :: b :: l2 => all_cover_aux (node a b :: l2) n1
end) (all_permutations l)
end.
(* A function to compute all covers *)
Definition all_cover l := all_cover_aux l (length l).

(* Specifications: *)
(* The local function generates covers of a given length *)
Theorem all_cover_aux_cover :
forall (n : nat) l t, n = length l -> In t (all_cover_aux l n) -> cover l t.