(** *** Exercise  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_c] case.  - The [typing_abs_c] case follows from the induction hypothesis. -- Use [simpl] to simplify the substitution.  -- Recall the tactic [pick fresh and apply].  -- In order to use the induction hypothesis, use [subst_open_var_c] to push the substitution under the opening operation.  -- Recall the lemma [typing_c_to_lc_c] and the [rewrite_env] and [simpl_env] tactics.  - The [typing_app_c] case follows from the induction hypotheses. Use [simpl] to simplify the substitution. *)

Lemma typing_c_subst : forall (E F : env) e u S T (z : atom),
typing_c (F ++ (z ~ S) ++ E) e T ->
typing_c E u S ->
typing_c (F ++ E) ([z ~> u] e) T.