(*! Indexed version of safety (not needed here) *)
Definition safe_ n {X} (R : Rel X) x := forall y m, m < n -> iter R m x y -> exists z, R y z.

(* Specifications: *)
Lemma safe_safe_ {X} (R : Rel X) x : safe R x <-> forall n, safe_ n R x.
Lemma safe__det {X} (R : Rel X) n x y : safe_ n R y -> R x y -> (forall y', R x y' -> y = y') -> safe_ (S n) R x.
Lemma safe__R {X} (R : Rel X) n x y : safe_ (S n) R x -> R x y -> safe_ n R y.
Lemma safe_S {X} (R : Rel X) n x : safe_ (S n) R x -> safe_ n R x.
Fixpoint nth {A} (l : list A) i :=
match l with
| nil => None
| x :: l =>
match i with
| O => Some x
| S i => nth l i
end
end.
Lemma safe_safe_ {X} (R : Rel X) x : safe R x <-> forall n, safe_ n R x.
Lemma safe__det {X} (R : Rel X) n x y : safe_ n R y -> R x y -> (forall y', R x y' -> y = y') -> safe_ (S n) R x.
Lemma safe__R {X} (R : Rel X) n x y : safe_ (S n) R x -> R x y -> safe_ n R y.
Lemma safe_S {X} (R : Rel X) n x : safe_ (S n) R x -> safe_ n R x.
Fixpoint nth {A} (l : list A) i :=
match l with
| nil => None
| x :: l =>
match i with
| O => Some x
| S i => nth l i
end
end.