LogRel.Substitution.Reduction

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 Reduction Transitivity.

Set Universe Polymorphism.

Section Reduction.
Context `{GenericTypingProperties}.

Set Printing Primitive Projection Parameters.

Lemma redwfSubstValid {Γ A t u l}
  ( : [||-v Γ])
  (red : [Γ ||-v t :⤳*: u : A | ])
  (VA : [Γ ||-v<l> A | ])
  (Vu : [Γ ||-v<l> u : A | | VA]) :
  [Γ ||-v<l> t : A | | VA] × [Γ ||-v<l> t u : A | | VA].
Proof.
  assert (Veq : [Γ ||-v<l> t u : A | | VA]).
  {
    constructor; intros; eapply redwfSubstTerm.
    1: now eapply validTm.
    now eapply validRed.
  }
  split; tea; constructor; intros.
  - eapply redwfSubstTerm.
    1: now eapply validTm.
    now eapply validRed.
  - eapply transEqTerm. 2: eapply transEqTerm.
    + now eapply validTmEq.
    + now eapply validTmExt.
    + eapply LRTmEqSym. eapply LRTmEqRedConv.
      1: eapply LRTyEqSym; now eapply validTyExt.
      now eapply validTmEq.
      Unshelve. all: tea.
Qed.

End Reduction.