-- Capless/Type/Basic.lean

import Capless.Type.Core

import Capless.Type.Renaming

namespace Capless

end

end

end

end

end

-- Repository definitions used:
content: inductive SType : Nat -> Nat -> Nat -> Type where
| top : SType n m k
| tvar : Fin m -> SType n m k
| forall : CType n m k -> EType (n+1) m k -> SType n m k
| tforall : SType n m k -> EType n (m+1) k -> SType n m k
| cforall : CBound n k -> EType n m (k+1) -> SType n m k
| box : CType n m k -> SType n m k
| label : SType n m k -> SType n m k

content: def SType.trename : SType n m k -> FinFun m m' -> SType n m' k
| SType.top, _ => SType.top
| SType.tvar X, f => SType.tvar (f X)
| SType.forall E1 E2, f => SType.forall (E1.trename f) (E2.trename f)
| SType.tforall S E, f => SType.tforall (S.trename f) (E.trename f.ext)
| SType.cforall B E, f => SType.cforall B (E.trename f)
| SType.box T, f => SType.box (T.trename f)
| SType.label S, f => SType.label (S.trename f)

content: def CType.trename : CType n m k -> FinFun m m' -> CType n m' k
| CType.capt C S, f => CType.capt C (S.trename f)

content: inductive CType : Nat -> Nat -> Nat -> Type where
| capt : CaptureSet n k -> SType n m k -> CType n m k

content: def FinFun (n n' : Nat) : Type :=
  Fin n -> Fin n'

content: def EType.trename : EType n m k -> FinFun m m' -> EType n m' k
| EType.ex T, f => EType.ex (T.trename f)
| EType.type T, f => EType.type (T.trename f)

content: inductive EType : Nat -> Nat -> Nat -> Type where
| ex : CType n m (k+1) -> EType n m k
| type : CType n m k -> EType n m k

content: def FinFun.ext (f : FinFun n n') : FinFun (n+1) (n'+1) :=

content: notation "⊤" => SType.top

content: notation:50 "∀(x:" T ")" U => SType.forall T U

content: notation:50 "∀[X<:" S "]" T => SType.tforall S T

content: notation:50 "∀[c<:" B "]" T => SType.cforall B T

content: notation:max S " ^ " C => CType.capt C S

content: notation:40 "∃c." T => EType.ex T

content: notation:40 "Label[" S "]" => SType.label S

content: notation:60 "□" T => SType.box T

-- Repository lemmas used:
content: theorem FinFun.ext_comp_ext {f : FinFun n n'} {g : FinFun n' n''} :
  g.ext ∘ f.ext = FinFun.ext (g ∘ f)

-- Local definitions used:

-- Local lemmas used:
content: theorem EType.trename_trename (E : EType n m k) (f : FinFun m m') (g : FinFun m' m'') :
  (E.trename f).trename g = E.trename (g ∘ f)

content: theorem CType.trename_trename (T : CType n m k) (f : FinFun m m') (g : FinFun m' m'') :
  (T.trename f).trename g = T.trename (g ∘ f)

-- Target theorem and proof:
theorem SType.trename_trename (S : SType n m k) (f : FinFun m m') (g : FinFun m' m'') :
  (S.trename f).trename g = S.trename (g ∘ f) :=
  match S with
  | SType.top => by simp [SType.trename]
  | SType.tvar X => by simp [SType.trename]
  | SType.forall E1 E2 => by
    have ih1 := CType.trename_trename E1 f g
    have ih2 := EType.trename_trename E2 f g
    simp [SType.trename, ih1, ih2]
  | SType.tforall S E => by
    have ih1 := SType.trename_trename S f g
    have ih2 := EType.trename_trename E f.ext g.ext
    simp [SType.trename, ih1, ih2, FinFun.ext_comp_ext]
  | SType.cforall B E => by
    have ih := EType.trename_trename E f g
    simp [SType.trename, ih]
  | SType.box T => by
    have ih := CType.trename_trename T f g
    simp [SType.trename, ih]
  | SType.label S => by
    have ih := SType.trename_trename S f g
    simp [SType.trename, ih]
:=
  match S with
  | SType.top => by simp [SType.trename]
  | SType.tvar X => by simp [SType.trename]
  | SType.forall E1 E2 => by
    have ih1 := CType.trename_trename E1 f g
    have ih2 := EType.trename_trename E2 f g
    simp [SType.trename, ih1, ih2]
  | SType.tforall S E => by
    have ih1 := SType.trename_trename S f g
    have ih2 := EType.trename_trename E f.ext g.ext
    simp [SType.trename, ih1, ih2, FinFun.ext_comp_ext]
  | SType.cforall B E => by
    have ih := EType.trename_trename E f g
    simp [SType.trename, ih]
  | SType.box T => by
    have ih := CType.trename_trename T f g
    simp [SType.trename, ih]
  | SType.label S => by
    have ih := SType.trename_trename S f g
    simp [SType.trename, ih]