Module unique := fc_unique wf subst.
Set Bullet Behavior "Strict Subproofs".
Set Implicit Arguments.
(* ------------------------------------------------------------- *)
(* -------------------------------------------------------------- *)
(*  Interlude: some lemmas about how erasure and typing interact. *)
(* -------------------------------------------------------------- *)
(* Lemma erase_abs : forall AB0 rho B, erase AB0 = (a_UAbs rho B) -> exists A1 B0, erase AB0 = erase (a_Abs rho A1 B0) /\ erase B0 = B. *)
(* Lemma erase_capp : forall AB0 A C G, erase AB0 = (a_CApp A g_Triv) -> AnnTyping G AB0 C -> exists A1 g0 g D, erase AB0 = erase (a_CApp A1 g0) /\ erase A1 = A /\ AnnTyping G (a_CApp A1 g0) D /\ AnnDefEq G (dom G) g C D. *)
(* -------------------------------------------------------------- *)
(* ------------------------------------------------------------- *)
Definition  AnnDefEq_regularity :
(forall G D g A B,   AnnDefEq G D g A B ->
exists C1 C2 g', AnnTyping G A C1 /\ AnnTyping G B C2
/\ AnnDefEq G (dom G) g' C1 C2) :=
fourth AnnDefEqAnnIso_regularity.
Definition AnnIso_regularity :
forall G D g phi1 phi2, AnnIso G D g phi1 phi2 ->
AnnPropWff G phi1 /\ AnnPropWff G phi2 :=
third AnnDefEqAnnIso_regularity.
(* --------------------------------------------------------- *)
(* Smart constructors for the annotated language *)
(* ---------------------------------------------- *)
(* ---------------------------------------------- *)

Lemma An_AbsCong_exists2
: ∀ (x1 x2 : atom) (G : context) (D : available_props) (rho : relflag) (g1 g2 : co)
(A1 b1 A2 b3 b2 B : tm),
x1 `notin` union (dom G) (union (fv_tm_tm_tm b1) (union (fv_tm_tm_tm b2) (fv_tm_tm_co g2)))
→ x2 `notin` union (dom G) (union (fv_tm_tm_tm b2) (union (fv_tm_tm_tm b3) (fv_tm_tm_co g1)))
→ AnnDefEq G D g1 A1 A2
→ 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))
→ open_tm_wrt_tm b3 (a_Var_f x2) = open_tm_wrt_tm b2 (a_Conv (a_Var_f x2) (g_Sym g1))
→ AnnTyping G A2 a_Star
→ RhoCheck rho x1 (erase_tm (open_tm_wrt_tm b1 (a_Var_f x1)))
→ RhoCheck rho x2 (erase_tm (open_tm_wrt_tm b3 (a_Var_f x2)))
→ AnnTyping G (a_Abs rho A1 b2) B
→ AnnDefEq G D (g_AbsCong rho g1 g2) (a_Abs rho A1 b1) (a_Abs rho A2 b3).