LogRel.Substitution.Escape


From LogRel.AutoSubst Require Import core unscoped Ast Extra.
From LogRel Require Import Utils BasicAst Notations Context NormalForms Weakening GenericTyping LogicalRelation Validity.
From LogRel.LogicalRelation Require Import Irrelevance Escape Reflexivity Weakening Neutral.
From LogRel.Substitution Require Import Irrelevance Properties.

Set Universe Polymorphism.

Section Escape.
Context `{GenericTypingProperties}.

Lemma reducibleTy {Γ l A} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) : [Γ ||-<l> A].
Proof.
  replace A with A[tRel] by now asimpl.
  eapply validTy; tea.
  apply idSubstS.
Qed.

Lemma reducibleTyEq {Γ l A B} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) :
  [Γ ||-v<l> A B | | VA] -> [Γ ||-<l> A B | reducibleTy VA].
Proof.
  intros.
  replace A with A[tRel] by now asimpl.
  replace B with B[tRel] by now asimpl.
  unshelve epose proof (validTyEq X _ (idSubstS )).
  irrelevance.
Qed.

Lemma reducibleTm {Γ l A t} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) :
  [Γ ||-v<l> t : A | | VA] -> [Γ ||-<l> t : A | reducibleTy VA].
Proof.
  intros.
  replace A with A[tRel] by now asimpl.
  replace t with t[tRel] by now asimpl.
  unshelve epose proof (validTm X _ (idSubstS )).
  irrelevance.
Qed.

Lemma reducibleTmEq {Γ l A t u} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) :
  [Γ ||-v<l> t u : A | | VA] -> [Γ ||-<l> t u : A | reducibleTy VA].
Proof.
  intros.
  replace A with A[tRel] by now asimpl.
  replace t with t[tRel] by now asimpl.
  replace u with u[tRel] by now asimpl.
  unshelve epose proof (validTmEq X _ (idSubstS )).
  irrelevance.
Qed.

Lemma escapeTy {Γ l A} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) : [Γ |- A].
Proof. eapply escape; now eapply reducibleTy. Qed.

Lemma escapeEq {Γ l A B} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) :
  [Γ ||-v<l> A B | | VA] -> [Γ |- A B].
Proof.
  intros; unshelve eapply escapeEq; tea.
  1: now eapply reducibleTy.
  now eapply reducibleTyEq.
Qed.

Lemma escapeTm {Γ l A t} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) :
  [Γ ||-v<l> t : A | | VA] -> [Γ |- t : A].
Proof.
  intros; unshelve eapply escapeTerm; tea.
  1: now eapply reducibleTy.
  now eapply reducibleTm.
Qed.

Lemma escapeTmEq {Γ l A t u} ( : [||-v Γ]) (VA : [Γ ||-v<l> A | ]) :
  [Γ ||-v<l> t u : A | | VA] -> [Γ |- t u : A].
Proof.
  intros; unshelve eapply escapeEqTerm; tea.
  1: now eapply reducibleTy.
  now eapply reducibleTmEq.
Qed.

End Escape.