(* 
  A list of trees is a cover of a tree if all the trees in the
  list delimit a frontier in the tree
*)
Inductive cover : list (btree A) -> btree A -> Prop :=
  | cover_one : forall t, cover (t :: nil) t
  | cover_node :
      forall l1 l2 t1 t2 t3,
      permutation l1 (t1 :: t2 :: l2) ->
      cover (node t1 t2 :: l2) t3 -> cover l1 t3.(* 
  A list of trees is a cover of a tree if all the trees in the
  list delimit a frontier in the tree
*)
Inductive cover : list (btree A) -> btree A -> Prop :=
  | cover_one : forall t, cover (t :: nil) t
  | cover_node :
      forall l1 l2 t1 t2 t3,
      permutation l1 (t1 :: t2 :: l2) ->
      cover (node t1 t2 :: l2) t3 -> cover l1 t3.(* 
  A list of trees is a cover of a tree if all the trees in the
  list delimit a frontier in the tree
*)
Inductive cover : list (btree A) -> btree A -> Prop :=
  | cover_one : forall t, cover (t :: nil) t
  | cover_node :
      forall l1 l2 t1 t2 t3,
      permutation l1 (t1 :: t2 :: l2) ->
      cover (node t1 t2 :: l2) t3 -> cover l1 t3.

(* Specifications: *)
Theorem cover_permutation : forall t l1 l2, cover l1 t -> permutation l1 l2 -> cover l2 t.
Theorem cover_cons_l : forall t1 t2 l1, cover l1 t1 -> cover (t2 :: l1) (node t2 t1).
Theorem cover_not_nil : forall l t, cover l t -> l <> nil.
Theorem one_cover_ex : forall l : list (btree A), l <> nil -> exists t : btree A, cover l t.
Theorem cover_in_inb_inb : forall l t1 t2 t3, cover l t1 -> In t2 l -> inb t3 t2 -> inb t3 t1.
Theorem cover_in_inb : forall l t1 t2, cover l t1 -> In t2 l -> inb t2 t1.
Theorem cover_inv_leaf : forall (a : A) l, cover l (leaf a) -> l = leaf a :: nil.
Theorem cover_one_inv : forall t1 t2, cover (t1 :: nil) t2 -> t1 = t2.
Lemma cover_inv_app_aux : forall t t1 t2 l, cover l t -> t = node t1 t2 -> l = node t1 t2 :: nil \/ (exists l1 : _, (exists l2 : _, (cover l1 t1 /\ cover l2 t2) /\ permutation l (l1 ++ l2))).
Theorem cover_inv_app : forall t1 t2 l, cover l (node t1 t2) -> l = node t1 t2 :: nil \/ (exists l1 : _, (exists l2 : _, (cover l1 t1 /\ cover l2 t2) /\ permutation l (l1 ++ l2))).
Theorem cover_app : forall t1 t2 l1 l2, cover l1 t1 -> cover l2 t2 -> cover (l1 ++ l2) (node t1 t2).
Theorem cover_number_of_nodes : forall t l, cover l t -> number_of_nodes t = fold_left (fun x y => x + number_of_nodes y) l 0 + pred (length l).