Section LT_WF_REL.
(* This Section is copied from the Coq library, which unfortunately uses Set instead of Type for Variable A, so just modified the one word. *)
Variable A : Type.
Variable R : A -> A -> Prop.
(* Relational form of inversion *)
Variable F : A -> nat -> Prop.
Definition inv_lt_rel x y := exists2 n, F x n & (forall m, F y m -> n < m).
Hypothesis F_compat : forall x y:A, R x y -> inv_lt_rel x y.
Remark acc_lt_rel : forall x:A, (exists n, F x n) -> Acc R x.
End LT_WF_REL.
Definition lex_pair {A B} (Ra: A -> A -> Prop) (Rb: B -> B -> Prop)
(x: A*B) (y: A*B) : Prop :=
Ra (fst x) (fst y) \/ (fst x = fst y /\ Rb (snd x) (snd y)).
(* Lemma lex_pair_eqv: forall A B Ra Rb, lex_pair Ra Rb = (fun x y => lexprod A (fun _ => B) Ra (fun _ => Rb) (existT (fun _:A => B) (fst x) (snd x)) (existT (fun _:A => B) (fst y) (snd y))). *)
Definition lexprodx {B A : Type} (f: A -> B) (R1: B -> B -> Prop)
(R2: B -> A -> A -> Prop)
(x y : A) : Prop :=
R1 (f x) (f y) \/ f x = f y /\ R2 (f x) x y.

Lemma lexprodx_eq: forall B A f R1 R2 x y,
lexprodx f R1 R2 x y <->
lexprod B (fun _ => A) R1 R2 (existT (fun _:B => A) (f x) x)
(existT (fun _:B => A) (f y) y).