Ltac rename_tm_Typing x0 K2 :=
let M1 := fresh in
let K1 := fresh in
match goal with
[ H0 : AnnTyping ([(?x, Tm ?A)] ++ ?G) (open_tm_wrt_tm ?B (a_Var_f ?x)) ?C |- _]
=> assert (AC : AnnCtx ([(x, Tm A)] ++ G)); eauto with ctx_wff;
inversion AC; subst;
assert (TV : AnnTyping ([(x0,Tm A)] ++ G) (a_Var_f x0) A); eauto;
assert (CTX : AnnCtx ([(x,Tm A)] ++ [(x0, Tm A)] ++ G));
[ match goal with
[ H7 : AnnTyping G A a_Star |- _] =>
econstructor; auto;
pose M1 := (AnnTyping_weakening H7 [(x0,Tm A)] nil G);
simpl_env in M1; eapply M1; eauto end |
pose K1 := AnnTyping_weakening H0 [(x0,Tm A)] [(x, Tm A)] G eq_refl CTX;
clearbody K1;
pose K2 := (first ann_tm_substitution_mutual) _ _ _ K1 _ _ _ TV nil x eq_refl;
clearbody K2; simpl_env in K2;
repeat rewrite tm_subst_tm_tm_open_tm_wrt_tm in K2; auto;
rewrite tm_subst_tm_tm_var in K2;
rewrite tm_subst_tm_tm_fresh_eq in K2]
end.

(* Specifications: *)
Lemma AnnTyping_co_swap : forall c c0 phi G a A,
c `notin` fv_co_co_tm A ->
c `notin` fv_co_co_tm a ->
c0 `notin` dom G \u {{ c }} ->
AnnTyping ([(c, Co phi)] ++ G) (open_tm_wrt_co a (g_Var_f c))
(open_tm_wrt_co A (g_Var_f c)) ->
AnnTyping ([(c0, Co phi)] ++ G) (open_tm_wrt_co a (g_Var_f c0))
(open_tm_wrt_co A (g_Var_f c0)).
Lemma AnnDefEq_tm_swap : forall x1 x G A1 D g2 b1 b2,
x1 `notin` fv_tm_tm_co g2 \u fv_tm_tm_tm b1 \u fv_tm_tm_tm b2
-> x `notin` dom G \u {{ x1 }}
-> 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))
-> 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)).
Lemma AnnDefEq_co_swap : forall c1 c phi1 G D g3 B1 B2,
c1 `notin` D \u fv_co_co_tm B1 \u fv_co_co_tm B2 \u fv_co_co_co g3 ->
c `notin` dom G \u {{ c1 }} ->
(AnnDefEq ([(c1, Co phi1)] ++ G) D (open_co_wrt_co g3 (g_Var_f c1))
(open_tm_wrt_co B1 (g_Var_f c1)) (open_tm_wrt_co B2 (g_Var_f c1)))
-> (AnnDefEq ([(c, Co phi1)] ++ G) D (open_co_wrt_co g3 (g_Var_f c))
(open_tm_wrt_co B1 (g_Var_f c)) (open_tm_wrt_co B2 (g_Var_f c))).