(** * Step-indexed interpreter and modesty *)

(** ** Step-indexed interpreter *)

Fixpoint eval (n : nat) (u : term) :=
  match u with
  | var n => None
  | lambda s => Some (lambda s)
  | app s t => match n with 
           | 0   => None
           | S n => match eval n s, eval n t with
                    | Some (lambda s), Some t => eval n (subst s 0 t)
                    |   _ , _ => None
                    end
            end
  end.

(* Specifications: *)
Lemma eval_S n s t : eval n s = Some t -> eval (S n) s = Some t.
Lemma evaluates_eval s t : evaluates s t -> exists n, eval n s = Some t.
Lemma eval_evaluates n s t : eval n s = Some t -> evaluates s t.
Lemma eval_lambda n s t : eval n s = Some t -> lam t.