Section through_is_insert.
Variable P : list (list A) -> Tree -> Prop.
Definition P_on_tree (ws : list (list A)) (t : Tree) : Prop := forall t', subtree t' t -> P ws t'.
Definition P_on_forest (ws : list (list A)) (f : list Tree) : Prop :=
forall t, tree_in_forest t f -> P ws t.
Fact P_on_node : forall a ts ws, P_on_tree ws (node a ts) ->
forall t, In t ts -> P_on_tree ws t.
Definition from_insert_forest (t : Tree) (a : A) : Prop :=
forall a' l vs ts, t = node (vs, a'::l) ts -> leA a' a.
Hypothesis P_added_node : forall ws w vs a l ts, from_insert_forest (node (vs,l) ts) a ->
P ws (node (vs,l) ts) ->
P ((a::w)::ws) (node (w::vs, a::l) ts).
Hypothesis P_added_node_base : forall ws w a f, P_on_forest ws f ->
P ((a::w)::ws) (node (w::ws,a::nil) f).
Hypothesis P_split : forall ws a t f, P ws (node a (t::f)) -> P ws t -> P ws (node a f).
Hypothesis P_merge : forall ws a t f, P ws (node a f) -> P ws t -> P ws (node a (t::f)).
Hypothesis P_add : forall w ws t, P ws t -> P (w::ws) t.
End through_is_insert.
Definition no_nil (t : Tree) : Prop := forall vs l ts, t = node (vs,l) ts -> l <> nil.
Fact in_is_forest_no_nil : forall f ws, is_forest ws f ->
forall t, tree_in_forest t f -> no_nil t.
Fact is_insert_tree_same_root : forall t t' w a,
is_insert_tree t w a t' -> root_label t = root_label t'.
Fact is_insert_forest_same_roots : forall f f' w a,
is_insert_forest f w a f' -> roots_labels f = roots_labels f'.
Fact roots_labels_exist : forall ts, (forall t, In t ts ->  no_nil t) ->
exists rrts, roots_labels ts = Some rrts.
Fact insert_forest_aux_get : forall f a w,
(forall t, In t f -> no_nil t /\ exists t', is_insert_tree t w a t') ->
exists f', is_insert_forest f w a f'.
Fact insert_tree_get : forall t w a,
(forall t', subtree t' t -> no_nil t') ->
exists t', is_insert_tree t w a t'.
Fact insert_forest_get : forall f a w ws, is_forest ws f -> exists f', is_insert_forest f w a f'.
Fact nil_forest : forall ws, is_forest ws nil -> ws = nil.
Fact roots_labels_greater_get_tree :
forall ts rrts, roots_labels ts = Some rrts ->
forall a, greater leA a rrts -> exists vs, exists b, exists bs, exists ts',
leA b a /\ In (node (vs, b::bs) ts') ts.
Fact is_insert_tree_neq : forall t,
forall w a t', is_insert_tree t w a t' -> t <> t'.

Lemma is_insert_forest_neq_aux : forall f a w f',
(exists vs, exists a', exists l, exists ts, In (node (vs,a'::l) ts) f /\ leA a' a) ->
is_insert_forest f w a f' -> f <> f'.