Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions Capless/Inversion/Typing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ namespace Capless
theorem Typed.app_inv'
(he : t0 = Term.app x y)
(h : Typed Γ t0 E Ct0) :
∃ T Cf F E0, Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.forall T F))) {x=x}
∧ Typed Γ (Term.var y) (EType.type T) {x=y}
∃ T Cf F E0, Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.forall T F))) {}
∧ Typed Γ (Term.var y) (EType.type T) {}
∧ E0 = F.open y
∧ ESubtyp Γ E0 E := by
induction h <;> try (solve | cases he)
case app x C T F y h1 h2 _ _ =>
case app x C T F C' y h1 h2 _ _ =>
cases he
exists T, C, F, (F.open y)
repeat (constructor; trivial)
repeat (any_goals apply And.intro)
all_goals try trivial
apply Typed.precise_cv; exact h1
apply Typed.precise_cv; exact h2
apply ESubtyp.refl
case sub hsub ih =>
have ih := ih he
Expand All @@ -31,8 +34,8 @@ theorem Typed.app_inv'

theorem Typed.app_inv
(h : Typed Γ (Term.app x y) E Ct) :
∃ T Cf F E0, Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.forall T F))) {x=x}
∧ Typed Γ (Term.var y) (EType.type T) {x=y}
∃ T Cf F E0, Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.forall T F))) {}
∧ Typed Γ (Term.var y) (EType.type T) {}
∧ E0 = F.open y
∧ ESubtyp Γ E0 E :=
Typed.app_inv' rfl h
Expand All @@ -41,19 +44,19 @@ theorem Typed.tapp_inv'
(he : t0 = Term.tapp x X)
(h : Typed Γ t0 E Ct) :
∃ Cf F E0,
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.tforall (SType.tvar X) F))) {x=x}
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.tforall (SType.tvar X) F))) {}
∧ E0 = F.topen X
∧ ESubtyp Γ E0 E := by
induction h <;> try (solve | cases he)
case tapp =>
cases he
repeat (apply Exists.intro)
apply And.intro
{ trivial }
{ apply Typed.precise_cv; trivial }
apply And.intro
{ trivial }
{ apply ESubtyp.refl }
case sub ht hs ih =>
case sub hs ih =>
have ih := ih he
have ⟨Cf, F, E0, hx, he0, hs0⟩ := ih
have h := ESubtyp.trans hs0 hs
Expand All @@ -62,7 +65,7 @@ theorem Typed.tapp_inv'
theorem Typed.tapp_inv
(h : Typed Γ (Term.tapp x X) E Ct) :
∃ Cf F E0,
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.tforall (SType.tvar X) F))) {x=x}
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.tforall (SType.tvar X) F))) {}
∧ E0 = F.topen X
∧ ESubtyp Γ E0 E :=
Typed.tapp_inv' rfl h
Expand Down Expand Up @@ -180,15 +183,15 @@ theorem Typed.capp_inv'
(he : t0 = Term.capp x c)
(h : Typed Γ t0 E Ct0) :
∃ Cf F E0,
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.cforall F))) {x=x} ∧
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.cforall F))) {} ∧
E0 = F.copen c ∧
ESubtyp Γ E0 E := by
induction h <;> try (solve | cases he)
case capp =>
cases he
repeat (apply Exists.intro)
apply And.intro
{ trivial }
{ apply Typed.precise_cv; trivial }
apply And.intro
{ trivial }
{ apply ESubtyp.refl }
Expand All @@ -201,7 +204,7 @@ theorem Typed.capp_inv'
theorem Typed.capp_inv
(h : Typed Γ (Term.capp x c) E Ct0) :
∃ Cf F E0,
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.cforall F))) {x=x} ∧
Typed Γ (Term.var x) (EType.type (CType.capt Cf (SType.cforall F))) {} ∧
E0 = F.copen c ∧
ESubtyp Γ E0 E :=
Typed.capp_inv' rfl h
Expand All @@ -216,7 +219,7 @@ theorem Typed.unbox_inv'
case unbox =>
cases he
apply Exists.intro
constructor; trivial
constructor; apply Typed.precise_cv; trivial
apply ESubtyp.refl
case sub hs ih =>
have ih1 := ih he
Expand Down Expand Up @@ -411,11 +414,11 @@ theorem Typed.canonical_form_pack'
(he1 : t0 = Term.pack C x)
(he2 : E0 = EType.ex T)
(h : Typed Γ t0 E0 Ct) :
Typed (Γ.cvar (CBinding.inst C)) (Term.var x) (EType.type T) {x=x} := by
Typed (Γ.cvar (CBinding.inst C)) (Term.var x) (EType.type T) {} := by
induction h <;> try (solve | cases he1 | cases he2)
case pack =>
cases he1; cases he2
trivial
apply Typed.precise_cv; trivial
case sub hs ih =>
subst he2
cases hs
Expand All @@ -430,7 +433,7 @@ theorem Typed.canonical_form_pack'
theorem Typed.canonical_form_pack
(ht : Γ.IsTight)
(h : Typed Γ (Term.pack C x) (EType.ex T) Ct) :
Typed (Γ.cvar (CBinding.inst C)) (Term.var x) (EType.type T) {x=x} :=
Typed (Γ.cvar (CBinding.inst C)) (Term.var x) (EType.type T) {} :=
Typed.canonical_form_pack' ht rfl rfl h

theorem Typed.forall_inv' {v : Term n m k}
Expand Down
1 change: 1 addition & 0 deletions Capless/Renaming/Capture/Typing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ theorem Typed.crename
apply pack
have ih := ih (ρ.cext _)
simp [Term.crename, EType.crename] at ih
rw [CaptureSet.cweaken_crename]
exact ih
case sub hsc hsub ih =>
apply sub
Expand Down
2 changes: 1 addition & 1 deletion Capless/Renaming/Term/Typing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ theorem Typed.rename
apply Typed.pack
have ih := ih (ρ.cext _)
simp [Term.rename, EType.rename] at ih
rw [<- CaptureSet.cweaken_rename_comm]
exact ih
case sub hsc hs ih =>
apply Typed.sub
Expand All @@ -30,7 +31,6 @@ theorem Typed.rename
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply Typed.abs
rw [CaptureSet.weaken_rename]
rw [<- CaptureSet.ext_rename_singleton_zero (f := f)]
apply? iht
apply ρ.ext
case tabs iht =>
Expand Down
14 changes: 7 additions & 7 deletions Capless/Soundness/Preservation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ theorem preservation
have ⟨hcfs, C0, hcft⟩ := Typed.canonical_form_lam hg hv
constructor
constructor
{ trivial }
{ exact hs }
{ apply Typed.sub
{ apply Typed.open (h := hcft)
exact hy }
{ apply Subcapt.refl }
{ subst he1
trivial } }
exact hs1 } }
trivial
case tapply hl =>
cases ht
Expand All @@ -73,7 +73,7 @@ theorem preservation
have ⟨C0, hct⟩ := Typed.canonical_form_clam hg hv
constructor
constructor
{ trivial }
{ exact hs }
{ apply Typed.sub
{ apply Typed.copen hct }
{ apply Subcapt.refl }
Expand All @@ -89,7 +89,7 @@ theorem preservation
have hct := Typed.canonical_form_boxed hg hv
constructor
constructor
{ trivial }
{ exact hs }
{ apply Typed.sub
exact hct
apply Subcapt.refl
Expand All @@ -101,7 +101,7 @@ theorem preservation
have ⟨T, E0, C0, htt, htu, hsub⟩ := Typed.letin_inv ht
constructor
constructor
{ trivial }
{ exact hs }
{ exact htt }
{ constructor
apply? Typed.sub
Expand Down Expand Up @@ -179,8 +179,8 @@ theorem preservation
have ⟨E0, C0, ht, hsub⟩ := Typed.bindc_inv ht
constructor
{ constructor; exact hs }
{ apply Typed.sub
exact ht; apply Subcapt.refl
{ apply Typed.ssub
exact ht
apply ESubtyp.cweaken; exact hsub }
{ apply TypedCont.cweaken; exact hc }

Expand Down
8 changes: 4 additions & 4 deletions Capless/Soundness/Progress.lean
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ theorem progress
apply Reduce.lift
constructor
case app =>
rename_i x _ _ _ _ hx _ _ _ σ _
rename_i x _ _ _ _ _ hx _ _ _ σ _
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.lookup_exists (σ := σ) (x := x)
have ⟨Cv, Cv0, htv⟩ := Store.lookup_inv_typing hb0 hs hx
Expand All @@ -95,7 +95,7 @@ theorem progress
apply Progress.step
apply Reduce.apply
trivial
case tapp x _ _ _ hx _ σ _ =>
case tapp x _ _ _ _ hx _ σ _ =>
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.lookup_exists (σ := σ) (x := x)
have ⟨Cv, Cv0, htv⟩ := Store.lookup_inv_typing hb0 hs hx
Expand All @@ -104,7 +104,7 @@ theorem progress
apply Progress.step
apply Reduce.tapply
trivial
case capp x _ _ _ hx _ σ _ =>
case capp x _ _ _ _ hx _ σ _ =>
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.lookup_exists (σ := σ) (x := x)
have ⟨Cv, Ct0, htv⟩ := Store.lookup_inv_typing hb0 hs hx
Expand All @@ -120,7 +120,7 @@ theorem progress
apply Progress.step
apply Reduce.lift
constructor
case unbox x _ _ hx _ σ _ =>
case unbox x _ _ _ hx _ σ _ =>
have hg := TypedStore.is_tight hs
have ⟨v0, hb0, hv0⟩ := Store.lookup_exists (σ := σ) (x := x)
have ⟨Cv, Cv0, htv⟩ := Store.lookup_inv_typing hb0 hs hx
Expand Down
2 changes: 1 addition & 1 deletion Capless/Subst/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Capless.Inversion.Context
namespace Capless

structure VarSubst (Γ : Context n m k) (f : FinFun n n') (Δ : Context n' m k) where
map : ∀ x E, Γ.Bound x E -> Typed Δ (Term.var (f x)) (EType.type (E.rename f)) {x=f x}
map : ∀ x E, Γ.Bound x E -> Typed Δ (Term.var (f x)) (EType.type (E.rename f)) {}
tmap : ∀ X b, Γ.TBound X b -> Δ.TBound X (b.rename f)
cmap : ∀ c b, Γ.CBound c b -> Δ.CBound c (b.rename f)

Expand Down
5 changes: 3 additions & 2 deletions Capless/Subst/Capture/Typing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ theorem Typed.csubst
apply pack
have ih := ih σ.cext
simp [EType.crename] at ih
rw [CaptureSet.cweaken_crename]
exact ih
case sub hsc hs ih =>
apply sub
Expand All @@ -31,12 +32,12 @@ theorem Typed.csubst
{ rw [CaptureSet.weaken_crename]
apply ih
apply σ.ext }
case tabs hc ih =>
case tabs ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply tabs
{ apply ih
apply σ.text }
case cabs hc ih =>
case cabs ih =>
simp [Term.crename, EType.crename, CType.crename, SType.crename]
apply cabs
{ rw [CaptureSet.cweaken_crename]
Expand Down
2 changes: 1 addition & 1 deletion Capless/Subst/Term/Typing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ theorem Typed.subst
apply pack
have ih := ih σ.cext
simp [EType.rename] at ih
rw [<- CaptureSet.cweaken_rename_comm]
exact ih
case sub hsc hs ih =>
apply sub
Expand All @@ -31,7 +32,6 @@ theorem Typed.subst
simp [Term.rename, EType.rename, CType.rename, SType.rename]
apply abs
{ rw [CaptureSet.weaken_rename]
rw [<- CaptureSet.ext_rename_singleton_zero (f := f)]
apply ih
apply σ.ext }
case tabs hc ih =>
Expand Down
28 changes: 14 additions & 14 deletions Capless/Typing.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace Capless
inductive Typed : Context n m k -> Term n m k -> EType n m k -> CaptureSet n k -> Prop where
| var :
Context.Bound Γ x (S^C) ->
Typed Γ (Term.var x) (S^{x=x}) {x=x}
Typed Γ (Term.var x) (S^{x=x}) {}
| pack :
Typed (Γ.cvar (CBinding.inst C)) (Term.var x) (EType.type T) {x=x} ->
Typed Γ (Term.pack C x) (∃c.T) {x=x}
Typed (Γ.cvar (CBinding.inst C)) (Term.var x) (EType.type T) Cx.cweaken ->
Typed Γ (Term.pack C x) (∃c.T) Cx
| sub :
Typed Γ t E1 C1 ->
(Γ ⊢ C1 <:c C2) ->
(Γ ⊢ E1 <:e E2) ->
Typed Γ t E2 C2
| abs {C : CaptureSet n k} :
Typed (Γ,x:T) t E (C.weaken ∪ {x=0}) ->
Typed (Γ,x:T) t E C.weaken ->
Typed Γ (λ(x:T)t) ((∀(x:T)E)^C) {}
| tabs {C : CaptureSet n k} :
Typed (Γ,X<:S) t E C ->
Expand All @@ -30,18 +30,18 @@ inductive Typed : Context n m k -> Term n m k -> EType n m k -> CaptureSet n k -
Typed Γ (Term.var x) (EType.type T) {x=x} ->
Typed Γ (Term.boxed x) ((SType.box T)^{}) {}
| app :
Typed Γ (Term.var x) (EType.type (∀(x:T)E)^C) {x=x} ->
Typed Γ (Term.var y) T {x=y} ->
Typed Γ (Term.app x y) (E.open y) ({x=x}{x=y})
Typed Γ (Term.var x) (EType.type (∀(x:T)E)^C) C' ->
Typed Γ (Term.var y) T C' ->
Typed Γ (Term.app x y) (E.open y) (C'C)
| tapp :
Typed Γ (Term.var x) (EType.type (∀[X<:SType.tvar X]E)^C) {x=x} ->
Typed Γ (Term.tapp x X) (E.topen X) {x=x}
Typed Γ (Term.var x) (EType.type (∀[X<:SType.tvar X]E)^C) C' ->
Typed Γ (Term.tapp x X) (E.topen X) (C' ∪ C)
| capp :
Typed Γ (Term.var x) (EType.type (∀[c]E)^C) {x=x} ->
Typed Γ (Term.capp x c) (E.copen c) {x=x}
Typed Γ (Term.var x) (EType.type (∀[c]E)^C) C' ->
Typed Γ (Term.capp x c) (E.copen c) (C' ∪ C)
| unbox :
Typed Γ (Term.var x) (EType.type (SType.box (S^C))^{}) {} ->
Typed Γ (C o- x) (S^C) C
Typed Γ (Term.var x) (EType.type (SType.box (S^C))^{}) C' ->
Typed Γ (C o- x) (S^C) (C' ∪ C)
| letin :
Typed Γ t (EType.type T) C ->
Typed (Γ,x: T) u E.weaken C.weaken -> -- which means that x ∉ C and x ∉ fv(E)
Expand All @@ -57,6 +57,6 @@ inductive Typed : Context n m k -> Term n m k -> EType n m k -> CaptureSet n k -
Typed (Γ,c:=C) t E.cweaken C0.cweaken ->
Typed Γ (let c=C in t) E C0

notation:30 Γ " ⊢ " t " : " E " @ " C => Typed Γ t E C
notation:40 Γ:80 "[" C "]" " ⊢ " t " : " E => Typed Γ t E C

end Capless
19 changes: 14 additions & 5 deletions Capless/Typing/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ theorem Typing.inv_subcapt

theorem Typed.bound_typing
(hb : Context.Bound Γ x T) :
Typed Γ (Term.var x) (EType.type T) {x=x} := by
Typed Γ (Term.var x) (EType.type T) {} := by
cases T
apply Typed.sub
apply Typed.var hb
Expand All @@ -41,7 +41,7 @@ theorem Typed.precise_capture'
(he1 : t0 = Term.var x)
(he2 : E0 = EType.type (CType.capt C S))
(h : Typed Γ t0 E0 C0) :
Typed Γ (Term.var x) (EType.type (CType.capt {x=x} S)) {x=x} := by
Typed Γ (Term.var x) (EType.type (CType.capt {x=x} S)) {} := by
induction h <;> try (solve | cases he1 | cases he2)
case var => cases he1; cases he2; apply Typed.var; trivial
case sub hsub ih =>
Expand All @@ -61,13 +61,13 @@ theorem Typed.precise_capture'

theorem Typed.precise_capture
(h : Typed Γ (Term.var x) (EType.type (CType.capt C S)) C0) :
Typed Γ (Term.var x) (EType.type (CType.capt {x=x} S)) {x=x} :=
Typed Γ (Term.var x) (EType.type (CType.capt {x=x} S)) {} :=
Typed.precise_capture' rfl rfl h

theorem Typed.precise_cv'
(he : t0 = Term.var x)
(h : Typed Γ t0 E C0) :
Typed Γ (Term.var x) E {x=x} := by
Typed Γ (Term.var x) E {} := by
induction h <;> try (solve | cases he)
case var => cases he; apply Typed.var; trivial
case sub ih =>
Expand All @@ -78,7 +78,16 @@ theorem Typed.precise_cv'

theorem Typed.precise_cv
(h : Typed Γ (Term.var x) E C0) :
Typed Γ (Term.var x) E {x=x} :=
Typed Γ (Term.var x) E {} :=
Typed.precise_cv' rfl h

theorem Typed.ssub
(h : Γ[C] ⊢ t : E)
(hsub : Γ ⊢ E <:e E') :
Γ[C] ⊢ t : E' := by
apply Typed.sub
exact h
apply Subcapt.refl
exact hsub

end Capless