(** *** Exercise [typing_subst]  Complete the proof of the substitution lemma. The proof proceeds by induction on the typing derivation for [e].  The initial steps should use [remember as] and [generalize dependent] in a manner similar to the proof of weakening.  HINTS: - Use the lemma proved above for the [typing_var] case.  - The [typing_abs] case follows from the induction hypothesis. -- Use [simpl] to simplify the substitution.  -- In order to use the induction hypothesis, use [subst_var] to push the substitution under the opening operation.  -- Recall the lemma [typing_to_lc_c] and the [rewrite_env] and [simpl_env] tactics.  - The [typing_app] case follows from the induction hypotheses. Use [simpl] to simplify the substitution. *)

(* Specifications: *)
Lemma typing_subst : forall (E F : ctx) e u S T (z : atom),
typing (F ++ [(z,S)] ++ E) e T ->
typing E u S ->
typing (F ++ E) ([z ~> u] e) T.