(* There is nth_error in the Coq library, but it seems to return something in Type. *)
Fixpoint nth_option(A : Set)(ls : list A)(i : nat) :=
  match ls with 
    | nil => None
    | a :: ls' =>
      match i with
        | O => Some a
        | S i' =>
          nth_option ls' i'
          end
  end.

Theorem list_pred_fst_split_flatten_eq_l : forall (A B : Set)(a : list (list (A * B)))(b : list (list A)), list_pred (list_pred (fun a0 b0 => fst a0 = b0)) a b -> flatten b = fst (split (flatten a)).