Section Lexicographic_Product.
Variables A B : Type.
Variable ltA : A -> A -> Prop.
Variable ltB : B -> B -> Prop.
Hypothesis wf_ltA : well_founded ltA.
Hypothesis wf_ltB : well_founded ltB.
Inductive lexprod : A*B -> A*B -> Prop :=
| lex_l : forall a a' b b', ltA a a' -> lexprod (a, b) (a', b')
| lex_r : forall a    b b', ltB b b' -> lexprod (a, b) (a,  b').

(* Specifications: *)
Lemma acc_lex a b : Acc ltA a -> Acc ltB b -> Acc lexprod (a, b).
Lemma lexprod_trans :
(forall a1 a2 a3, ltA a1 a2 -> ltA a2 a3 -> ltA a1 a3) ->
(forall b1 b2 b3, ltB b1 b2 -> ltB b2 b3 -> ltB b1 b3) ->
forall x1 x2 x3, lexprod x1 x2 -> lexprod x2 x3 -> lexprod x1 x3.
Lemma wf_lexprod : well_founded lexprod.
Definition lex_prod_dec:
(forall a1 a2 : A, {a1 = a2} + {a1 <> a2}) ->
(forall a1 a2, {ltA a1 a2} + {~ltA a1 a2}) ->
(forall b1 b2, {ltB b1 b2} + {~ltB b1 b2}) ->
(forall x y, {lexprod x y} + {~ lexprod x y}).
Lemma cons_cons_last (A:Type) (a b:A) l x:
last (a::b::l) x = last (b::l) x.
Lemma last_in (A:Type) (l:list A) x:
(last l x = x) \/ (In (last l x) l).