(* File: Lt_Ks.v  (last edited on 27/10/2000) (c) Klaus Weich  *)
Require Export Le.
Require Export Lt.
Require Export Le_Ks.
Fixpoint count_undecs (n : nested_imps) : nat :=
match n with
| nil => 0
| Undecorated _ :: n => S (count_undecs n)
| Decorated _ _ :: n => count_undecs n
end.
Inductive Lt_Ks (ni1 : nested_imps) (dni1 : decorated_nested_imps)
(ni2 : nested_imps) (dni2 : decorated_nested_imps) : Set :=
| lt_ks_count_undecs :
le_ni (rev_app dni1 ni1) (rev_app dni2 ni2) ->
count_undecs ni1 < count_undecs ni2 -> Lt_Ks ni1 dni1 ni2 dni2
| lt_ks_length :
le_ni (rev_app dni1 ni1) (rev_app dni2 ni2) ->
length ni1 < length ni2 -> Lt_Ks ni1 dni1 ni2 dni2.
intros ni1 ni2 le12.
elim le12; clear le12 ni1 ni2.
trivial.
intros x ni1 ni2 le ih; simpl in |- *.
apply le_n_S; assumption.
intros x k ni1 ni2 le ih; simpl in |- *.
apply le_trans with (count_undecs ni2).
assumption.
apply le_n_Sn.
intros x k ni1 ni2 le ih; simpl in |- *.
assumption.
Qed.
intros dni; elim dni; clear dni.
intros; trivial.
intros x; case x; clear x.
intros x k dni ih ni.
simpl in |- *.
apply (ih (Decorated x k :: ni)).
Qed.

Lemma le_ks_le_count_undecs :
forall (ni1 : nested_imps) (dni1 : decorated_nested_imps)
(ni2 : nested_imps) (dni2 : decorated_nested_imps),
le_ni (rev_app dni1 ni1) (rev_app dni2 ni2) ->
count_undecs ni1 <= count_undecs ni2.