Skip to content

Commit 5faa158

Browse files
committed
restructure and new strong norm
1 parent 9546c6d commit 5faa158

21 files changed

Lines changed: 832 additions & 18 deletions

LeanSysF.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-- This module serves as the root of the `LeanSysf` library.
22
-- Import modules here that should be built as part of the library.
33
import LeanSysF.OneSortHomArityGen
4+
import LeanSysF.TwoSortHet

LeanSysF/OneSortHomArityGen.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22
import OneSortHomArityGen.FreeVar
3-
-- import OneSortHomArityGen.Infer
3+
import OneSortHomArityGen.Infer
44
import OneSortHomArityGen.Kinding
55
import OneSortHomArityGen.Preservation
66
import OneSortHomArityGen.Progress
77
import OneSortHomArityGen.Reduction
88
import OneSortHomArityGen.SN
9-
import OneSortHomArityGen.StrongNormalization
9+
import OneSortHomArityGen.StrongNorm1
10+
import OneSortHomArityGen.StrongNorm2
1011
import OneSortHomArityGen.Term
1112
import OneSortHomArityGen.Typing
1213
import OneSortHomArityGen.Utility

LeanSysF/TwoSortHet.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import TwoSortHet.Ty
2+
import TwoSortHet.Term

OneSortHomArityGen/FreeVar.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import LeanSubst
33
import OneSortHomArityGen.Utility
44
import OneSortHomArityGen.Term
55

6+
namespace OneSortHomArityGen
7+
68
open LeanSubst
79

810
inductive FV : Term -> Nat -> Prop
@@ -104,3 +106,5 @@ theorem FV.zero_not_in_succ {t : Term} : ¬ (0 ∈ t[+1]) := by
104106
intro j
105107
have lem := @var_not_in_one_more 0 t; simp at lem
106108
apply lem j
109+
110+
end OneSortHomArityGen

OneSortHomArityGen/Infer.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import LeanSubst
22
import OneSortHomArityGen.Typing
33

4+
namespace OneSortHomArityGen
5+
46
open LeanSubst
57

68
def Term.beq : Term -> Term -> Bool
@@ -118,7 +120,7 @@ def infer (Γ : Ctx Term) : Term -> Option Term
118120
let a := ts 1
119121
let F <- infer Γ f
120122
let P <- F.is_all
121-
if a.is_type Γ then P[su a::+0]
123+
if a.is_type Γ then return P[su a::+0]
122124
else none
123125
| .bind .lam ts t => do
124126
let A := ts 0
@@ -210,3 +212,5 @@ def ex2 : Term := ex1 :@[ex0] :@ ex1
210212

211213
#eval infer Ctx.nil ex1
212214
#eval infer Ctx.nil ex2
215+
216+
end OneSortHomArityGen

OneSortHomArityGen/Kinding.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import LeanSubst
33
import OneSortHomArityGen.Term
44
import OneSortHomArityGen.FreeVar
55

6+
namespace OneSortHomArityGen
7+
68
open LeanSubst
79

810
inductive Kinding : Ctx Term -> Term -> Prop where
@@ -182,3 +184,8 @@ theorem Kinding.injection_arrow : Γ ⊢ (A -:> B) type -> Γ ⊢ A type ∧ Γ
182184
rw [Vec.inv2] at e
183185
rcases e with ⟨e1, e2⟩; simp at e1 e2; subst e1 e2
184186
simp [*]
187+
188+
theorem Kinding.type_not_star : Γ ⊢ A type -> A ≠ ★ := by
189+
intro j h; subst h; cases j
190+
191+
end OneSortHomArityGen

OneSortHomArityGen/Model.lean

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
import LeanSubst
3+
import OneSortHomArityGen.Term
4+
5+
namespace OneSortHomArityGen
6+
7+
open LeanSubst
8+
9+
universe u u1 u2 u3
10+
11+
class Model (D : Sort u) where
12+
A : D -> D -> D
13+
Q : (D -> D) -> D
14+
P : D -- Any model has to know what to do with junk
15+
16+
@[simp]
17+
def Model.int_term [Model D] (v : Nat -> D) : Term -> D
18+
| #x => v x
19+
| .ctor .arr ts => A (int_term v (ts 0)) (int_term v (ts 1))
20+
| .bind .all _ t => Q (λ d => int_term (d::v) t)
21+
| _ => P
22+
23+
@[simp]
24+
def Model.int_subst [Model D] (v : Nat -> D) (σ : Subst Term) : Nat -> D
25+
| i => Model.int_term v (σ i)
26+
27+
notation "⟦ " t " ⟧ " v:100 => Model.int_term v t
28+
notation "⟦ " σ " ⟧ " v:100 => Model.int_subst v σ
29+
30+
theorem Model.rename [Model D] {A : Term} {ξ : Nat -> D} (r : Ren)
31+
: ⟦ A[r] ⟧ ξ = ⟦ A ⟧ (ξ ∘ r)
32+
:= by
33+
induction A generalizing r ξ <;> simp at *
34+
case ctor v _ ih =>
35+
cases v <;> simp at *; case _ ts =>
36+
generalize Adef : ts 0 = A at *
37+
generalize Bdef : ts 1 = B at *
38+
rcases ih with ⟨ih1, ih2⟩; congr 1
39+
rw [ih1]; rw [ih2]
40+
case bind v _ _ ih1 ih2 =>
41+
cases v <;> simp at *
42+
congr; funext; case _ d =>
43+
replace ih2 := @ih2 (d::ξ) r.lift
44+
rw [Ren.to_lift (S := Term)] at ih2
45+
simp at ih2; rw [ih2]; congr
46+
funext; case _ i =>
47+
cases i <;> simp [Ren.lift]
48+
49+
@[simp]
50+
theorem Model.weaken [Model D] {A : Term} {ξ : Nat -> D}
51+
: ⟦ A[+1] ⟧ (d::ξ) = ⟦ A ⟧ ξ
52+
:= by
53+
have lem := Model.rename (A := A) (ξ := d::ξ) (· + 1)
54+
simp at lem; rw [lem]
55+
have lem : ((d::ξ) ∘ (· + 1)) = ξ := by
56+
funext; case _ i =>
57+
cases i <;> simp
58+
rw [lem]
59+
60+
theorem Model.subst [Model D] {A : Term} {σ : Subst Term} {ξ : Nat -> D}
61+
: ⟦ A[σ] ⟧ ξ = ⟦ A ⟧ (⟦ σ ⟧ ξ)
62+
:= by
63+
induction A generalizing σ ξ <;> simp
64+
case ctor v _ ih =>
65+
cases v <;> simp
66+
simp [*]
67+
case bind v _ _ ih1 ih2 =>
68+
cases v <;> simp
69+
congr; funext; case _ d =>
70+
replace ih2 := @ih2 σ.lift (d::ξ)
71+
simp at ih2; rw [ih2]; congr
72+
funext; case _ i =>
73+
cases i <;> simp [Subst.compose]
74+
case _ i =>
75+
generalize σ i = z
76+
cases z <;> simp
77+
78+
@[simp]
79+
theorem Model.beta [Model D] {A B : Term} {ξ : Nat -> D}
80+
: ⟦ A[su B::+0] ⟧ ξ = ⟦ A ⟧ (⟦ B ⟧ ξ :: ξ)
81+
:= by
82+
rw [Model.subst]; congr
83+
funext; case _ i =>
84+
cases i <;> simp
85+
86+
end OneSortHomArityGen

OneSortHomArityGen/Preservation.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import OneSortHomArityGen.Typing
55
import OneSortHomArityGen.Reduction
66
import OneSortHomArityGen.Progress
77

8+
namespace OneSortHomArityGen
9+
810
open LeanSubst
911

1012
theorem preservation_step : Γ ⊢ t : A -> t ~> t' -> Γ ⊢ t' : A := by
@@ -82,3 +84,5 @@ theorem preservation : Γ ⊢ t : A -> t ~>* t' -> Γ ⊢ t' : A := by
8284
case _ => exact j
8385
case _ y z r1 r2 ih =>
8486
apply preservation_step ih r2
87+
88+
end OneSortHomArityGen

OneSortHomArityGen/Progress.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import OneSortHomArityGen.Kinding
44
import OneSortHomArityGen.Typing
55
import OneSortHomArityGen.Reduction
66

7+
namespace OneSortHomArityGen
8+
79
open LeanSubst
810

911
@[simp]
@@ -250,3 +252,5 @@ theorem progress t : Value t ∨ (∃ t', t ~> t') := by
250252
apply Or.inr
251253
exists (:∀ t')
252254
apply Red.bind2 _ r
255+
256+
end OneSortHomArityGen

OneSortHomArityGen/Reduction.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import LeanSubst
33
import LeanSubst.Reduction
44
import OneSortHomArityGen.Term
55

6+
namespace OneSortHomArityGen
7+
68
open LeanSubst
79

810
inductive Red : Term -> Term -> Prop where
@@ -39,7 +41,7 @@ theorem Red.antirename {s t : Term} (r : Ren) :
3941
∃ z, s ~> z ∧ t = z[r]
4042
:= by
4143
intro h
42-
generalize wdef : s[r:Term] = w at *
44+
generalize wdef : s[r] = w at *
4345
induction h generalizing s r
4446
case beta A b t =>
4547
cases s <;> simp at wdef
@@ -114,7 +116,6 @@ theorem Red.antirename {s t : Term} (r : Ren) :
114116
rcases ih with ⟨z, h1, h2⟩
115117
exists (Term.bind v' ts' z); apply And.intro
116118
apply Red.bind2 _ h1; subst h2; simp
117-
rw [Ren.to_lift (S := Term)]; simp
118119

119120
theorem Red.ctor_star_lemma {ts ts'} i :
120121
(∀ j ≠ i, ts j = ts' j) ->
@@ -599,3 +600,5 @@ instance : Substitutive Red where
599600
-- instance : HasConfluence Red where
600601
-- confluence := confluence
601602
-- end Red
603+
604+
end OneSortHomArityGen

0 commit comments

Comments
 (0)