forked from AndrasKovacs/smalltt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.stt
222 lines (172 loc) · 5.12 KB
/
test.stt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
the : (A : U) → A → A
= λ A x. x
id : {A} → A → A
= λ x. x
idTest : {A} → A → A
= id id id id id id id id id id id id id id id id id id id id
id id id id id id id id id id id id id id id id id id id id
Nat : U
= (n : U) → (n → n) → n → n
zero : Nat
= λ n s z. z
suc : Nat → Nat
= λ a n s z. s (a n s z)
add : Nat → Nat → Nat
= λ a b n s z. a n s (b n s z)
mul : Nat → Nat → Nat
= λ a b n s. a n (b n s)
Eq : {A} → A → A → U
= λ {A} x y. (P : A → U) → P x → P y
refl : {A}{x : A} → Eq x x
= λ P px. px
two : Nat = λ N s z. s (s z)
five : Nat = λ N s z. s (s (s (s (s z))))
n10 = mul two five
n10b = mul five two
n20 = mul two n10
n20b = mul two n10b
n21 = suc n20
n21b = suc n20b
n22 = suc n21
n22b = suc n21b
n100 = mul n10 n10
n100b = mul n10b n10b
n10k = mul n100 n100
n10kb = mul n100b n100b
n100k = mul n10k n10
n100kb = mul n10kb n10b
n1M = mul n10k n100
n1Mb = mul n10kb n100b
n5M = mul n1M five
n5Mb = mul n1Mb five
n10M = mul n5M two
n10Mb = mul n5Mb two
Tree : U = (T : U) → (T → T → T) → T → T
leaf : Tree = λ T n l. l
node : Tree → Tree → Tree = λ t1 t2 T n l. n (t1 T n l) (t2 T n l)
fullTree : Nat → Tree = λ n. n _ (λ t. node t t) leaf
t2M = fullTree n20
t2Mb = fullTree n20b
-- convtest1 : Eq n5M n5Mb
-- = refl
-- convtest2 : Eq n10M n10Mb
-- = refl
-- convt1M : Eq t2M t2Mb
-- = refl
--------------------------------------------------------------------------------
Vec : U → Nat → U
= λ a n. (V : Nat → U) → V zero → ({n} → a → V n → V (suc n)) → V n
vnil : {a} → Vec a zero
= λ V n c. n
vcons : {a n} → a → Vec a n → Vec a (suc n)
= λ a as V n c. c a (as V n c)
vec1 = (vcons zero (vcons zero (vcons zero (vcons zero (vcons zero (vcons zero
(vcons zero (vcons zero (vcons zero (vcons zero (vcons zero (vcons zero
(vcons zero (vcons zero (vcons zero (vcons zero (vcons zero (vcons zero
(vcons zero (vcons zero (vcons zero (vcons zero (vcons zero (vcons zero
(vcons zero (vcons zero (vcons zero (vcons zero (vcons zero (vcons zero
(vcons zero (vcons zero vnil))))))))))))))))))))))))))))))))
Pair : U → U → U
= λ A B. (Pair : U)(pair : A → B → Pair) → Pair
pair : {A B} → A → B → Pair A B
= λ a b Pair pair. pair a b
proj1 : {A B} → Pair A B → A
= λ p. p _ (λ x y. x)
proj2 : {A B} → Pair A B → B
= λ p. p _ (λ x y. y)
Top : U
= (Top : U)(tt : Top) → Top
tt : Top
= λ Top tt. tt
Bot : U
= (Bot : U) → Bot
Ty : U
= (Ty : U)
(ι : Ty)
(fun : Ty → Ty → Ty)
→ Ty
ι : Ty
= λ _ ι _. ι
fun : Ty → Ty → Ty
= λ A B Ty ι fun. fun (A Ty ι fun) (B Ty ι fun)
Con : U
= (Con : U)
(nil : Con)
(cons : Con → Ty → Con)
→ Con
nil : Con
= λ Con nil cons. nil
cons : Con → Ty → Con
= λ Γ A Con nil cons. cons (Γ Con nil cons) A
Var : Con → Ty → U
= λ Γ A.
(Var : Con → Ty → U)
(vz : {Γ A} → Var (cons Γ A) A)
(vs : {Γ B A} → Var Γ A → Var (cons Γ B) A)
→ Var Γ A
vz : {Γ A} → Var (cons Γ A) A
= λ Var vz vs. vz
vs : {Γ B A} → Var Γ A → Var (cons Γ B) A
= λ x Var vz vs. vs (x Var vz vs)
Tm : Con → Ty → U
= λ Γ A.
(Tm : Con → Ty → U)
(var : {Γ A} → Var Γ A → Tm Γ A)
(lam : {Γ A B} → Tm (cons Γ A) B → Tm Γ (fun A B))
(app : {Γ A B} → Tm Γ (fun A B) → Tm Γ A → Tm Γ B)
→ Tm Γ A
var : {Γ A} → Var Γ A → Tm Γ A
= λ x Tm var lam app. var x
lam : {Γ A B} → Tm (cons Γ A) B → Tm Γ (fun A B)
= λ t Tm var lam app. lam (t Tm var lam app)
app : {Γ A B} → Tm Γ (fun A B) → Tm Γ A → Tm Γ B
= λ t u Tm var lam app. app (t Tm var lam app) (u Tm var lam app)
EvalTy : Ty → U
= λ A. A _ Bot (λ A B. A → B)
EvalCon : Con → U
= λ Γ. Γ _ Top (λ Δ A. Pair Δ (EvalTy A))
EvalVar : {Γ A} → Var Γ A → EvalCon Γ → EvalTy A
= λ x. x (λ Γ A. EvalCon Γ → EvalTy A)
(λ env. proj2 env)
(λ rec env. rec (proj1 env))
EvalTm : {Γ A} → Tm Γ A → EvalCon Γ → EvalTy A
= λ t.
t _
EvalVar
(λ t env α. t (pair env α))
(λ t u env. t env (u env))
test : Tm nil (fun (fun ι ι) (fun ι ι))
= lam (lam (app (var (vs vz)) (app (var (vs vz))
(app (var (vs vz)) (app (var (vs vz))
(app (var (vs vz)) (app (var (vs vz)) (var vz))))))))
dup : {A} → A → Pair A A
= λ x. pair x x
pairTest = λ (x : U).
let x0 = dup x;
let x1 = dup x0;
let x2 = dup x1;
let x3 = dup x2;
let x4 = dup x3;
let x5 = dup x4;
let x6 = dup x5;
let x7 = dup x6;
let x8 = dup x7;
let x9 = dup x8;
let x10 = dup x9;
let x11 = dup x10;
let x12 = dup x11;
let x13 = dup x12;
let x14 = dup x13;
let x15 = dup x14;
let x16 = dup x15;
let x17 = dup x16;
let x18 = dup x17;
let x19 = dup x18;
let x20 = dup x19;
let x21 = dup x20;
let x22 = dup x21;
let x23 = dup x22;
let x24 = dup x23;
x24
-- foo : Eq pairTest pairTest = refl
-- foo : Eq {Nat} n10M n10M = refl {Nat}