(* --------------------------------------------------------------------- *)
(* 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_inversion :
forall G D rho g1 g2 B1 B2,
AnnDefEq G D (g_AbsCong rho g1 g2) B1 B2 ->
exists A1 A2 b1 b2 b3 B,
B1 = (a_Abs rho A1 b1) /\
B2 = (a_Abs rho A2 b3) /\
AnnTyping G A1 a_Star  /\
AnnTyping G A2 a_Star  /\
AnnDefEq G D g1 A1 A2  /\
AnnTyping G (a_Abs rho A1 b2) B /\
(forall x, x \notin dom G ->
AnnDefEq  ((x ~ Tm A1) ++  G) D (open_co_wrt_tm g2 (a_Var_f x))
(open_tm_wrt_tm b1 (a_Var_f x))
((open_tm_wrt_tm b2 (a_Var_f x))) /\
(open_tm_wrt_tm b3 (a_Var_f x)) =
(open_tm_wrt_tm b2 (a_Conv (a_Var_f x) (g_Sym g1))) /\
(RhoCheck rho x  (erase_tm (open_tm_wrt_tm b1 (a_Var_f x)))) /\
(RhoCheck rho x  (erase_tm (open_tm_wrt_tm b3 (a_Var_f x))))).