LogRel.Substitution.Introductions.SimpleArr

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 Escape Reflexivity Neutral Weakening Irrelevance.
From LogRel.Substitution Require Import Irrelevance Properties Conversion.
From LogRel.Substitution.Introductions Require Import Universe Pi Application Lambda Var.

Set Universe Polymorphism.

Section SimpleArrValidity.

  Context `{GenericTypingProperties}.

  Lemma simpleArrValid {l Γ F G} ( : [||-v Γ])
    (VF : [Γ ||-v< l > F | ])
    (VG : [Γ ||-v< l > G | ]) :
    [Γ ||-v<l> arr F G | ].
  Proof.
    unshelve eapply PiValid; tea.
    replace G with G@wk1 Γ F by now bsimpl.
    now eapply wk1ValidTy.
  Qed.

  Lemma simpleArrCongValid {l Γ F F' G G'} ( : [||-v Γ])
    (VF : [Γ ||-v< l > F | ])
    (VF' : [Γ ||-v< l > F' | ])
    (VeqF : [Γ ||-v< l > F F' | | VF])
    (VG : [Γ ||-v< l > G | ])
    (VG' : [Γ ||-v< l > G' | ])
    (VeqG : [Γ ||-v< l > G G' | | VG]) :
    [Γ ||-v<l> arr F G arr F' G' | | simpleArrValid _ VF VG].
  Proof.
    eapply irrelevanceTyEq.
    unshelve eapply PiCong; tea.
    + replace G with G@wk1 Γ F by now bsimpl.
      now eapply wk1ValidTy.
    + replace G' with G'@wk1 Γ F' by now bsimpl.
      now eapply wk1ValidTy.
    + replace G' with G'@wk1 Γ F by now bsimpl.
      eapply irrelevanceTyEq'.
      2: now eapply wk1ValidTyEq.
      now bsimpl.
    Unshelve. 2: tea.
  Qed.

  Lemma simple_appValid {Γ t u F G l}
    ( : [||-v Γ])
    {VF : [Γ ||-v<l> F | ]}
    (VG : [Γ ||-v<l> G | ])
    ( : [Γ ||-v<l> arr F G | ])
    (Vt : [Γ ||-v<l> t : arr F G | _ | ])
    (Vu : [Γ ||-v<l> u : F | _ | VF]) :
    [Γ ||-v<l> tApp t u : G| _ | VG].
  Proof.
    eapply irrelevanceTm'.
    2: eapply appValid; tea.
    now bsimpl.
  Unshelve. all: tea.
  Qed.

  Lemma simple_idValid {Γ A l}
    ( : [||-v Γ])
    {VF : [Γ ||-v<l> A | ]}
    ( : [Γ ||-v<l> arr A A | ]) :
    [Γ ||-v<l> idterm A : arr A A | _ | ].
  Proof.
    eapply irrelevanceTm'.
    2: unshelve eapply lamValid.
    5: unshelve eapply var0Valid.
    - now rewrite wk1_ren_on.
    - tea.
  Qed.

  Lemma simple_compValid {Γ A B C f g l}
    ( : [||-v Γ])
    {VA : [Γ ||-v<l> A | ]}
    (VB : [Γ ||-v<l> B | ])
    (VC : [Γ ||-v<l> C | ])
    (VAB : [Γ ||-v<l> arr A B | ])
    (VBC : [Γ ||-v<l> arr B C | ])
    (VAC : [Γ ||-v<l> arr A C | ])
    (Vf : [Γ ||-v<l> f : arr A B | _ | VAB])
    (Vg : [Γ ||-v<l> g : arr B C | _ | VBC]) :
    [Γ ||-v<l> comp A g f : arr A C | _ | VAC].
  Proof.
    eapply irrelevanceTm'.
    2: unshelve eapply lamValid.
    5: unshelve eapply simple_appValid.
    9: unshelve eapply simple_appValid.
    13: eapply var0Valid.
    4: eapply wk1ValidTy; exact VC.
    4: eapply wk1ValidTy; exact VB.
    - now rewrite wk1_ren_on.
    - eassumption.
    - do 2 erewrite wk1_ren_on. rewrite<- arr_ren1.
      erewrite<- wk1_ren_on.
      now eapply wk1ValidTy.
    - eapply irrelevanceTm'. 2: erewrite<- wk1_ren_on;now eapply wk1ValidTm.
      rewrite wk1_ren_on. rewrite arr_ren1.
      do 2 rewrite wk1_ren_on. reflexivity.
    - do 2 erewrite wk1_ren_on. rewrite<- arr_ren1.
      erewrite<- wk1_ren_on.
      now eapply wk1ValidTy.
    - eapply irrelevanceTm'. 2: erewrite<- wk1_ren_on;now eapply wk1ValidTm.
      rewrite wk1_ren_on. rewrite arr_ren1.
      do 2 rewrite wk1_ren_on. reflexivity.

      Unshelve. all: tea.
  Qed.

End SimpleArrValidity.