(** Succeed iff [x] is in the list [ls], represented with left-associated nested tuples. *)
Ltac inList x ls :=
  match ls with
    | x => idtac
    | (_, x) => idtac
    | (?LS, _) => inList x LS
  end.(** Try calling tactic function [f] on every element of tupled list [ls], keeping the first call not to fail. *)
Ltac app f ls :=
  match ls with
    | (?LS, ?X) => f X || app f LS || fail 1
    | _ => f ls
  end.(** Run [f] on every element of [ls], not just the first that doesn't fail. *)
Ltac all f ls :=
  match ls with
    | (?LS, ?X) => f X; all f LS
    | (_, _) => fail 1
    | _ => f ls
  end.

Lemma term_ne_in_l2 : forall l e e' l1 l2, sorted l -> In e l -> (forall e', In e' l -> eTerm e' <= eTerm e) -> removeAfterIndex l (eIndex e) = l1 ++ l2 -> (forall e', In e' l1 -> eTerm e' = eTerm e) -> In e' l -> eTerm e' <> eTerm e -> In e' l2.