(** Author: Cristina Cornes  From : Constructing Recursion Operators in Type Theory L. Paulson  JSC (1986) 2, 325-355  *)
Local Open Scope list_scope.
Section Lexicographic_Exponentiation.
Variable A : Set.
Variable leA : A -> A -> Prop.
Let Nil := nil (A:=A).
Let List := list A.
Inductive Ltl : List -> List -> Prop :=
| Lt_nil (a:A) (x:List) : Ltl Nil (a :: x)
| Lt_hd (a b:A) : leA a b -> forall x y:list A, Ltl (a :: x) (b :: y)
| Lt_tl (a:A) (x y:List) : Ltl x y -> Ltl (a :: x) (a :: y).
Inductive Desc : List -> Prop :=
| d_nil : Desc Nil
| d_one (x:A) : Desc (x :: Nil)
| d_conc (x y:A) (l:List) :
leA x y -> Desc (l ++ y :: Nil) -> Desc ((l ++ y :: Nil) ++ x :: Nil).
Definition Pow : Set := sig Desc.
Definition lex_exp (a b:Pow) : Prop := Ltl (proj1_sig a) (proj1_sig b).
End Lexicographic_Exponentiation.
Section Wf_Lexicographic_Exponentiation.
Variable A : Set.
Variable leA : A -> A -> Prop.
Notation Power := (Pow A leA).
Notation Lex_Exp := (lex_exp A leA).
Notation ltl := (Ltl A leA).
Notation Descl := (Desc A leA).
Notation List := (list A).
Notation Nil := (nil (A:=A)).
(* useless but symmetric *)
Notation Cons := (cons (A:=A)).
Notation "<< x , y >>" := (exist Descl x y) (at level 0, x, y at level 100).
(* Hint Resolve d_one d_nil t_step. *)

(* Specifications: *)
Lemma left_prefix : forall x y z:List, ltl (x ++ y) z -> ltl x z.
Lemma right_prefix :
forall x y z:List,
ltl x (y ++ z) -> ltl x y \/ (exists y' : List, x = y ++ y' /\ ltl y' z).
Lemma desc_prefix : forall (x:List) (a:A), Descl (x ++ Cons a Nil) -> Descl x.
Lemma desc_tail :
forall (x:List) (a b:A),
Descl (Cons b (x ++ Cons a Nil)) -> clos_trans A leA a b.
Lemma dist_aux :
forall z:List, Descl z -> forall x y:List, z = x ++ y -> Descl x /\ Descl y.
Lemma dist_Desc_concat :
forall x y:List, Descl (x ++ y) -> Descl x /\ Descl y.
Lemma desc_end :
forall (a b:A) (x:List),
Descl (x ++ Cons a Nil) /\ ltl (x ++ Cons a Nil) (Cons b Nil) ->
clos_trans A leA a b.
Lemma ltl_unit :
forall (x:List) (a b:A),
Descl (x ++ Cons a Nil) ->
ltl (x ++ Cons a Nil) (Cons b Nil) -> ltl x (Cons b Nil).
Lemma acc_app :
forall (x1 x2:List) (y1:Descl (x1 ++ x2)),
Acc Lex_Exp << x1 ++ x2, y1 >> ->
forall (x:List) (y:Descl x), ltl x (x1 ++ x2) -> Acc Lex_Exp << x, y >>.
Theorem wf_lex_exp : well_founded leA -> well_founded Lex_Exp.
End Wf_Lexicographic_Exponentiation.