(* --------------------------------------------------------------------- *)
(* 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_PiCong_inversion : forall (G:context) (D:available_props) (rho:relflag) (g1 g2:co) (C1 C2 :tm),
AnnDefEq G D (g_PiCong rho g1 g2) C1 C2
-> exists A1 B1 A2 B2 B3,
C1 = (a_Pi rho A1 B1) /\
C2 = (a_Pi rho A2 B3) /\
AnnTyping G (a_Pi rho A1 B1) a_Star /\
AnnTyping G (a_Pi rho A2 B3) a_Star /\
AnnTyping G (a_Pi rho A1 B2) a_Star /\
AnnDefEq G D g1 A1 A2 /\
(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))))).