(* --------------------------------------------------------------------- *)
(* This is the place for "smart constructors" and "smart inversion" lemmas. They are especialy useful for constructing derivations from a particular variable and avoiding the co-finite quantification stuff.  *)
(* In a locally nameless development, these should be stated and immediately proven after substitution. *)

Lemma An_AbsCong_exists : ∀ x1 x2 (G : context) D rho (g1 g2 : co) (A1 b1 A2 b3 b2 B : tm),
x1 `notin` (dom G \u fv_tm_tm_tm b1 \u fv_tm_tm_tm b2 \u  fv_tm_tm_co g2)
-> x2 `notin` (dom G \u fv_tm_tm_tm b2 \u fv_tm_tm_tm b3 \u  fv_tm_tm_co g1)
->  AnnDefEq G D g1 A1 A2
→ (AnnDefEq ([(x1, Tm A1)] ++ G) D  (open_co_wrt_tm g2 (a_Var_f x1))
(open_tm_wrt_tm b1 (a_Var_f x1)) (open_tm_wrt_tm b2 (a_Var_f x1)))
→ (open_tm_wrt_tm b3 (a_Var_f x2) =
open_tm_wrt_tm b2 (a_Conv (a_Var_f x2) (g_Sym g1)))
→ AnnTyping G A1 a_Star
→ AnnTyping G A2 a_Star
→ RhoCheck rho x1 (erase_tm (open_tm_wrt_tm b1 (a_Var_f x1)))
→ RhoCheck rho x2 (erase_tm (open_tm_wrt_tm b3 (a_Var_f x2)))
-> AnnTyping G (a_Abs rho A1 b2) B
→ AnnDefEq G D (g_AbsCong rho g1 g2) (a_Abs rho A1 b1) (a_Abs rho A2 b3).