Section well_founded_pairs.
Variables (A B: Type)
(Ra: relation A) (Rb: relation B).
Inductive pair_rel: relation (A * B) :=
| pair_rel_l a a' b: Ra a a' -> pair_rel (a, b) (a', b)
| pair_rel_r a b b': Rb b b' -> pair_rel (a, b) (a, b').
Fixpoint acc_pairs a (Aa: Acc Ra a) {struct Aa}: forall b (Ab: Acc Rb b), Acc pair_rel (a, b) :=
fix G b (Ab: Acc Rb b) {struct Ab}: Acc pair_rel _ := @Acc_intro _ pair_rel _
match Aa, Ab with
| Acc_intro x, Acc_intro y =>  fun z (za: pair_rel z (a, b)) =>
match za in pair_rel z ab return
(forall (p: A) (q: Ra p (fst ab)), Acc pair_rel (p, (snd ab))) -> (forall p, Rb p (snd ab) -> Acc pair_rel (fst ab, p)) -> Acc pair_rel z with
| pair_rel_l v w c d => fun fr gr => fr _ d
| pair_rel_r v w c d => fun fr gr => gr _ d
end
(fun (p: A) (q: Ra p (fst (a, b))) => @acc_pairs p (x p q) b Ab : Acc pair_rel (p, b))
(fun (p: B) (q: Rb p (snd (a, b))) => @G p (y p q): Acc pair_rel (a, p))
end.

Lemma well_founded_pairs (Wa: well_founded Ra) (Wb: well_founded Rb): well_founded pair_rel.
unfold well_founded.