End Positions.
Notation nthe n A := (nth_error A n).

(* Specifications: *)
Lemma pos_nth X d (x : X) l n def : pos d x l = Some n -> nth n l def = x.
Lemma pos_length X d (x : X) l n : pos d x l = Some n -> n < | l |.
Fixpoint omap X Y (f : X -> option Y) l :=
match l with
| nil => nil
| x :: l => match f x with Some y => y :: omap f l | None => omap f l end
end.
Lemma in_omap_iff X Y (f : X -> option Y) l y : y el omap f l <-> exists x, x el l /\ f x = Some y.
Section neList.
Lemma pos_nth X d (x : X) l n def : pos d x l = Some n -> nth n l def = x.
Lemma pos_length X d (x : X) l n : pos d x l = Some n -> n < | l |.
Fixpoint omap X Y (f : X -> option Y) l :=
match l with
| nil => nil
| x :: l => match f x with Some y => y :: omap f l | None => omap f l end
end.
Lemma in_omap_iff X Y (f : X -> option Y) l y : y el omap f l <-> exists x, x el l /\ f x = Some y.
Section neList.