(*************************************************************************)
(** * Regularity                                                         *)
(*************************************************************************)
(** To be fully confident about the exist-fresh rules, we can show their "regularity" --- that these relations only include locally closed terms. (For the exists-fresh definition of local closure.) *)

(* Specifications: *)
(** Importantly: to prove regularity, we need to know subst_lc, and that we most directly prove by using the connection between lc and lc_c. *)
Lemma subst_lc : forall (x : atom) u e,
lc e ->
lc u ->
lc ([x ~> u] e).
(** Take-home exercise. [open_abs] is the analogue of subst_lc for bound variable substitution. HINT: use inversion, subst_intro and subst_lc to prove this lemma. **)
Lemma open_abs : forall e u T1,
lc (abs T1 e) ->
lc u ->
lc (open e u).
(** Importantly: to prove regularity, we need to know subst_lc, and that we most directly prove by using the connection between lc and lc_c. *)
Lemma subst_lc : forall (x : atom) u e,
lc e ->
lc u ->
lc ([x ~> u] e).
(** Take-home exercise. [open_abs] is the analogue of subst_lc for bound variable substitution. HINT: use inversion, subst_intro and subst_lc to prove this lemma. **)
Lemma open_abs : forall e u T1,
lc (abs T1 e) ->
lc u ->
lc (open e u).
(** Take-home exercise.  To prove that ill-formed terms cannot be typechecked, we will need an auxiliary lemma that says that each term only has a single type.  HINT: to prove this lemma you will need to generalize the induction hypothesis for T2 and use the lemma [binds_unique] from [AtomEnv.v]. *)
Lemma typing_c_unique : forall E e T1 T2,
typing_c E e T1 ->
typing_c E e T2 ->
T1 = T2.