(* ---------------------------------- *)
(* Lemma close_tm_fresh : forall x a, x `notin` fv_tm_tm_tm (close_tm_wrt_tm x a).  Lemma close_co_fresh : forall x a, x `notin` fv_tm_tm_co (close_co_wrt_tm x a).  Lemma close_co_fresh_co : forall x a, x `notin` fv_co_co_co (close_co_wrt_co x a). *)
(* ----------------------------------------------------- *)
(* Tactics for working with context in weakening proof *)
Ltac auto_rew_env :=
multimatch goal with
| [ |- context [([(?x, ?T)] ++ ?G1 ++ ?G2 ++ ?G3)] ] => rewrite_env (((x ~ (T)) ++ G1) ++ G2 ++ G3)
end.
(* -------------- Pick fresh and apply for judgements with binding ----- *)
Ltac E_pick_fresh x :=
match goal with
| [ |- Typing _ ?shape _ ] =>
let v := match shape with
| a_Pi _ _ _ => E_Pi
| a_UAbs _ _ => E_Abs
| a_CPi _ _  => E_CPi
| a_CAbs _ _ => E_CAbs
| a_UCAbs _  => E_CAbs
end
in pick fresh x and apply v
| [ |- DefEq _ _ ?shape ?s2 _ ] =>
let v := match shape with
| a_Pi _ _ _ => E_PiCong
| a_UAbs Rel _ => match s2 with
| a_UAbs _ _ => E_AbsCong
| _ => E_EtaRel
end
| a_UAbs Irrel _ => match s2 with
| a_UAbs _ _ =>  E_AbsCong
| _ => E_EtaIrrel
end
| a_CPi _ _  => E_CPiCong
| a_CAbs _ _ => E_CAbsCong
| a_UCAbs _  => match s2 with
| a_UCAbs _ =>  E_CAbsCong
| _ => E_EtaC
end
end
in pick fresh x and apply v
end.
Ltac Par_pick_fresh x :=
match goal with
| [ |- Par _ _ ?shape ?s2 ] =>
let v := match shape with
| a_Pi _ _ _ => Par_Pi
| a_UAbs Rel _ =>  match s2 with
| a_UAbs _ _ => Par_Abs
| _ => Par_Eta
end
| a_UAbs Irrel _ =>  match s2 with
| a_UAbs _ _ => Par_Abs
| _ => Par_EtaIrrel
end
| a_UAbs _ _ =>  Par_Abs
| a_CPi _ _  => Par_CPi
| a_CAbs _ _ => Par_CAbs
| a_UCAbs _  => match s2 with
| a_UCAbs _ => Par_CAbs
| _ => Par_EtaC
end
end
in pick fresh x and apply v
end.
Ltac An_pick_fresh x :=
let shape := match goal with
| [ |- AnnTyping _   ?shape _    ] => shape
| [ |- AnnDefEq  _ _ ?shape _  _ ] => shape
end in
let ctor  := match shape with
| a_Pi     _ _ _ => An_Pi
| a_Abs    _ _ _ => An_Abs
| a_CPi      _ _ => An_CPi
| a_CAbs     _ _ => An_CAbs
| g_PiCong _ _ _ => An_PiCong
| g_AbsCong _ _ _  => An_AbsCong
| g_CPiCong  _ _   => An_CPiCong
| g_CAbsCong _ _ _ => An_CAbsCong
| g_Eta _          => An_Eta
end in
pick fresh x and apply ctor.
(* --------------------------------------------------------- *)
Ltac RhoCheck_inversion y :=
match goal with
| [ K : ∀ x : atom, x `notin` ?L → RhoCheck ?rho x ?b |- _ ] =>
move: (K y ltac:(auto)); inversion 1; subst; clear K
| [ K : ∀ x : atom, (x `in` ?L -> False) → RhoCheck ?rho x ?b |- _ ] =>
move: (K y ltac:(auto)); inversion 1; subst; clear K
end.
(* --------------------------------------------------------- *)

Lemma lc_open_switch_co :
forall g t, lc_co g ->
lc_tm (open_tm_wrt_co t g_Triv) ->
lc_tm (open_tm_wrt_co t g).