Section OrderedCover.
Variable A : Type.
(* An ordered cover is a cover where the positions of the elements in the list are fixed *)
Inductive ordered_cover : list (btree A) -> btree A -> Prop :=
| ordered_cover_one :
forall (t : btree A) (l : list (btree A)), ordered_cover (t :: nil) t
| ordered_cover_node :
forall (t1 t2 : btree A) (l1 l2 l3 : list (btree A)),
ordered_cover l1 t1 ->
ordered_cover l2 t2 -> ordered_cover (l1 ++ l2) (node t1 t2).
Hint Resolve ordered_cover_one ordered_cover_node : core.
intros l t H; elim H; auto.
intros t1 t2 l1 l2 l3 H0 H1 H2 H3.
Proof using.
apply cover_app; auto.
Qed.
Proof using.
intros l1; elim l1 using list_length_ind.
intros l0 H t; case t.
intros a H1; rewrite cover_inv_leaf with (1 := H1).
exists (leaf a :: nil); auto.
intros t1 t2 H1; case cover_inv_app with (1 := H1).
intros H2; exists l0; split; auto; rewrite H2; auto.
intros (l2, (l3, ((HH1, HH2), HH3))).
case H with (2 := HH1); auto.
rewrite permutation_length with (1 := HH3).
generalize HH2; rewrite length_app; case l3; simpl in |- *; auto with arith.
intros HH4; case cover_not_nil with (1 := HH4); auto.
intros; rewrite plus_comm; simpl in |- *; auto with arith.
intros l4 (HP1, HP2).
case H with (2 := HH2); auto.
rewrite permutation_length with (1 := HH3).
generalize HH1; rewrite length_app; case l2; simpl in |- *; auto with arith.
intros HH4; case cover_not_nil with (1 := HH4); auto.
intros l5 (HP3, HP4).
exists (l4 ++ l5); split; auto.
apply permutation_trans with (1 := HH3); auto.
Qed.

(* If the ordered cover is composed of only leaves, they are the exact leaves of the tree *)
Theorem ulist_ordered_cover :
forall l1 l2 t,
ordered_cover l1 t ->
ulist l2 -> l1 = map (fun x : A => leaf x) l2 -> all_leaves t = l2.