Fixpoint extendr {A} (l : list A) ls :=
match l, ls with
| x :: xs, y :: ys => (y ++ [x]) :: extendr xs ys
| _, _ => ls
end.

Lemma extend_cons : forall {A} (l : list A) l1 ls, extend l (l1 :: ls) =
match l with [] => l1 :: ls | a :: l' => (a :: l1) :: extend l' ls end.