Module ext_weak (wf: ext_wf_sig).
Include wf.
Set Bullet Behavior "Strict Subproofs".
Set Implicit Arguments.
(* TODO: this tactic is not so "automated" (e.g. has to link a_Pi to E_Pi), but it is hard to make it more "searchy" without trying extensively all the lemmas. We could probably work something out, though *)
(* 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 _ _ ] => let v := match shape with | a_Pi _ _ _ => E_PiCong | a_UAbs _ _ => E_AbsCong | a_CPi _ _  => E_CPiCong | a_CAbs _ _ => E_CAbsCong | a_UCAbs _  => E_CAbsCong end in pick fresh x and apply v | [ |- Par _ _ ?shape _ ] => let v := match shape with | a_Pi _ _ _ => Par_Pi | a_UAbs _ _ => Par_Abs | a_CPi _ _  => Par_CPi | a_CAbs _ _ => Par_CAbs | a_UCAbs _  => Par_CAbs end in pick fresh x and apply v end. *)
(* ------------------------------------------------------------------- *)
(* Weakening Lemmas for the available set *)
Definition Iso_respects_atoms_eq   := third  respects_atoms_eq_mutual.
Definition DefEq_respects_atoms_eq := fourth respects_atoms_eq_mutual.
(* Instance Iso_atoms_eq_mor : Morphisms.Proper (eq ==> AtomSetImpl.Equal ==> eq ==> eq ==> iff) Iso.  Instance DefEq_atoms_eq_mor : Morphisms.Proper (eq ==> AtomSetImpl.Equal ==> eq ==> eq ==> eq ==> iff) DefEq.  *)
(* ----- *)
Ltac binds_cons :=
let H5 := fresh in
match goal with
[
H4 : (∃ phi : constraint, binds ?x (Co phi) ?G) → False
|- ((exists phi, binds ?x (Co phi) ([(?y, ?s)] ++ ?G)) -> False) ] =>
intro H5; destruct H5; apply H4; simpl in H5;
destruct (binds_cons_1 _ x y _ s G H5); split_hyp; subst;
try done; eauto
end.
(* ----- *)
(* Instance Iso_atoms_sub_mor : Morphisms.Proper (eq ==> AtomSetImpl.Subset ==> eq ==> eq ==> impl) Iso.  Instance DefEq_atoms_sub_mor : Morphisms.Proper (eq ==> AtomSetImpl.Subset ==> eq ==> eq ==> eq ==> impl) DefEq. *)
Hint Resolve DefEq_weaken_available Iso_weaken_available.

Lemma typing_weakening_mutual:
(forall G0 a A,     Typing G0 a A ->
forall E F G, (G0 = F ++ G) -> Ctx (F ++ E ++ G) -> Typing (F ++ E ++ G) a A) /\
(forall G0 phi,     PropWff G0 phi ->
forall E F G, (G0 = F ++ G) -> Ctx (F ++ E ++ G) -> PropWff (F ++ E ++ G) phi) /\
(forall G0 D p1 p2, Iso G0 D p1 p2 ->
forall E F G, (G0 = F ++ G) -> Ctx (F ++ E ++ G) -> Iso (F ++ E ++ G) D p1 p2) /\
(forall G0 D A B T, DefEq G0 D A B T ->
forall E F G, (G0 = F ++ G) -> Ctx (F ++ E ++ G) -> DefEq (F ++ E ++ G) D A B T) /\
(forall G0,         Ctx G0 ->
forall E F G, (G0 = F ++ G) -> Ctx (F ++ E ++ G) -> Ctx (F ++ E ++ G)).