Fixpoint delta (m n : nat) (l1 l2 al1 al2 al3: line) :
option (line * line * line) :=
match l1 with
| nil => match natc n (length l2) with
| Eq => Some (lrev al1 nil, lrev al2 l2, lrev al3 nil)
| _ => None
end
| t1 :: l3 =>
(fix delta1 n (l2 : list tuple) al2 :=
match  l2 with
| nil =>
match natc m (length l1) with
| Eq => Some (lrev al1 l1, lrev al2 nil, lrev al3 nil)
| _ => None
end
| t2 :: l4 =>
match tcompare t1 t2 with
| Eq => delta m n l3 l4 al1 al2 (t1 ::al3)
| Lt => match m with
|    O => None
| S m1 => delta m1 n l3 l2 (t1 ::al1) al2 al3
end
| Gt => match n with
|    O => None
| S n1 => delta1 n1 l4 (t2 ::al2)
end
end
end) n l2 al2
end.

Lemma delta_c m n l1 l2 al1 al2 al3 :
match delta m n l1 l2 al1 al2 al3 with
| None => True
| Some (l3,l4,l5) =>
({l[l1]} * {l[al1]} * {l[al3]} = {l[l3]} * {l[l5]} /\
{l[l2]} * {l[al2]} * {l[al3]} = {l[l4]} * {l[l5]})%f
end.