End ext_subst_sig.
(**************** Ext invert ****************)
Module Type ext_invert_sig.
Include ext_subst_sig.
(* ---------- inversion lemmas ---------------- *)

(* Specifications: *)
Axiom binds_to_Typing: forall G T A, Ctx G -> binds T (Tm A) G -> Typing G A a_Star.
Axiom invert_a_Const : forall G T A,
Typing G (a_Const T) A ->
exists B, DataTy B a_Star /\ DefEq G (dom G) A B  a_Star
/\ binds T (Cs B) toplevel.
Axiom invert_a_Pi: forall G rho A0 A B0,
Typing G (a_Pi rho A0 B0) A ->
DefEq G (dom G) A a_Star a_Star /\ (exists L, forall x, x `notin` L -> Typing ([(x, Tm A0)] ++ G) (open_tm_wrt_tm B0 (a_Var_f x)) a_Star) /\ Typing G A0 a_Star.
Axiom invert_a_CPi: forall G phi A B0,
Typing G (a_CPi phi B0) A ->
DefEq G (dom G) A a_Star a_Star /\ (exists L, forall c, c `notin` L -> Typing ([(c, Co phi)] ++ G) (open_tm_wrt_co B0 (g_Var_f c) ) a_Star) /\ PropWff G phi.
Axiom invert_a_App_Rel : forall G a b C,
Typing G (a_App a Rel b) C ->
exists A B, Typing G a (a_Pi Rel A B) /\
Typing G b A /\
DefEq G (dom G) C (open_tm_wrt_tm B b) a_Star.
Axiom invert_a_App_Irrel : forall G a b C,
Typing G (a_App a Irrel b) C ->
exists A B b0, Typing G a (a_Pi Irrel A B) /\
Typing G b0 A /\
DefEq G (dom G) C (open_tm_wrt_tm B b0) a_Star.
Axiom invert_a_CApp : forall G a g A,
Typing G (a_CApp a g) A ->
g = g_Triv /\
exists a1 b1 A1 B, Typing G a (a_CPi (Eq a1 b1 A1) B) /\
DefEq G (dom G) a1 b1 A1 /\
DefEq G (dom G) A (open_tm_wrt_co B g_Triv) a_Star.
Axiom invert_a_UAbs:
forall G rho A b0,
Typing G (a_UAbs rho b0) A
-> exists A1 B1, DefEq G (dom G) A (a_Pi rho A1 B1) a_Star
/\ (exists L, forall x, x `notin` L ->
Typing ([(x, Tm A1)] ++ G)
(open_tm_wrt_tm b0 (a_Var_f x))
(open_tm_wrt_tm B1 (a_Var_f x))
/\ Typing ([(x, Tm A1)] ++ G)
(open_tm_wrt_tm B1 (a_Var_f x)) a_Star
/\ RhoCheck rho x (open_tm_wrt_tm b0 (a_Var_f x)))
/\ Typing G A1 a_Star.
Axiom invert_a_UCAbs: forall G A b0,
Typing G (a_UCAbs b0) A ->
exists a b T B1, PropWff G (Eq a b T)
/\ DefEq G (dom G) A (a_CPi (Eq a b T) B1) a_Star /\
(exists L, forall c, c `notin` L ->
Typing ([(c, Co (Eq a b T))] ++ G)
(open_tm_wrt_co b0 (g_Var_f c))
(open_tm_wrt_co B1 (g_Var_f c)) /\
Typing ([(c, Co (Eq a b T))] ++ G)
(open_tm_wrt_co B1 (g_Var_f c)) a_Star).
Axiom invert_a_Var :
forall G x A, Typing G (a_Var_f x) A -> exists A', binds x (Tm A') G /\ DefEq G (dom G) A A' a_Star.
Axiom invert_a_Star: forall A G, Typing G a_Star A -> DefEq G (dom G) A a_Star a_Star.
Axiom invert_a_Fam : forall G F A,
Typing G (a_Fam F) A ->
exists a B, DefEq G (dom G) A B a_Star /\
binds F (Ax a B) toplevel /\ Typing nil B a_Star.