-
Notifications
You must be signed in to change notification settings - Fork 10
/
systemt_finite.ott
289 lines (211 loc) · 6.13 KB
/
systemt_finite.ott
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
metavar tmvar, x, y ::= {{ repr-locally-nameless }}
{{ com variables }}
metavar label, l ::= {{ coq nat }}
indexvar index, i, n ::= {{ coq nat }}
grammar
typ, t {{ tex \tau }} :: 'typ_' ::= {{ com types }}
| nat :: :: nat {{ com Natural numbers }}
| t1 -> t2 :: :: arr {{ com Function types }}
| unit :: :: unit {{ com Unit type }}
| t1 * t2 :: :: prod {{ com Product types }}
| void :: :: void {{ com Void types }}
| t1 + t2 :: :: sum {{ com Sum types }}
exp, e :: '' ::= {{ com expressions }}
| x :: :: var {{ com Variables }}
| z :: :: z {{ com Zero }}
| s e :: :: s {{ com Successor }}
| rec e { z -> e0 ; s x -> e1 } :: :: rec
(+ bind x in e1 +)
{{ com Primitive recursion over nats }}
| \ ( x : t ) e :: :: abs
(+ bind x in e +)
{{ com Functions }}
{{ tex [[\]]([[x]]\!:\![[t]])[[e]] }}
| e1 e2 :: :: fapp
{{ com Application }}
| ( e ) :: M :: Paren {{ coq ([[e]]) }}
| e1 { e2 / x } :: M :: Subst {{ coq (open_exp_wrt_exp [[x e1]] [[e2]]) }}
| triv :: :: null {{ com Null tuple }}
| < e1 ; e2 > :: :: pair {{ com Ordered pair }}
| fst e :: :: fst {{ com Left projection }}
| snd e :: :: snd {{ com Right projection }}
| abort { t } ( e ) :: :: abort {{ com Abort }}
| inl { t } ( e ) :: :: inl {{ com Left injection }}
| inr { t } ( e ) :: :: inr {{ com Right injection }}
| case e { inl x1 -> e1 | inr x2 -> e2 } :: :: scase
(+ bind x1 in e1 +) (+ bind x2 in e2 +)
{{ com Case analysis }}
substitutions
single e x :: subst
freevars
e x :: fv
grammar
env, G {{ tex \Gamma }} :: '' ::= {{ com typing environment }} {{ coq list ( atom * typ ) }}
| empty :: :: Empty {{ coq nil }}
{{ com empty }}
| G , x : t :: :: Cons {{ coq (([[x]] ~ [[t]]) ++ [[G]]) }}
{{ com cons }}
| G ++ G' :: M :: Append {{ coq ([[G']] ++ [[G]]) }}
{{ tex [[G]] \mathop{++} [[G']] }}
terminals :: 'terminals_' ::=
| \ :: :: lam {{ tex \mathrm{\lambda} }}
| ~> :: :: produce {{ tex \leadsto }}
| |- :: :: entails {{ tex \vdash }}
| -> :: :: arrow {{ tex \to }}
| ++ :: :: concat {{ tex \mathop{++} }}
| empty :: :: empty {{ tex \emptyset }}
| * :: :: prod {{ tex \times }}
| + :: :: sum
formula :: 'formula_' ::=
| judgement :: :: judgement
| x : t in G :: :: inG
{{ coq binds [[x]] [[t]] [[G]] }}
| ( formula ) :: :: Paren
{{ coq ([[formula]]) }}
| uniq G :: :: uniq
{{ coq uniq [[G]] }}
| formula1 .. formulan :: :: dots
defns
JValue :: '' ::=
defn
e val :: :: value :: 'val_'
by
------- :: z
z val
e val
-------- :: s
s e val
---------------- :: abs
\ (x :t) e val
---------- :: null
triv val
e1 val
e2 val
------------ :: prod
<e1;e2> val
e val
------------- :: inl
inl{t}(e) val
e val
------------- :: inr
inr{t}(e) val
defns
JTyping :: '' ::=
defn
G |- e : t :: :: typing :: 'typing_'
by
uniq G
x : t in G
----------- :: var
G |- x : t
uniq G
------------- :: z
G |- z : nat
G |- e : nat
---------------- :: s
G |- s e : nat
G |- e : nat
G |- e0 : t
G , x : nat |- e1 : t -> t
e1 val
----------------------------------------- :: rec
G |- rec e { z -> e0 ; s x -> e1 } : t
G, x:t1 |- e : t2
-------------------------- :: abs
G |- \ (x :t1) e : t1 -> t2
G |- e1 : t1 -> t2
G |- e2 : t1
------------------------- :: fapp
G |- e1 e2 : t2
uniq G
------------------------- :: null
G |- triv : unit
G |- e1 : t1
G |- e2 : t2
------------------------ :: pair
G |- <e1;e2> : t1 * t2
G |- e : t1 * t2
------------------------ :: fst
G |- fst e : t1
G |- e : t1 * t2
------------------------ :: snd
G |- snd e : t2
G |- e : void
------------------------ :: abort
G |- abort{t}(e) : t
G |- e : t1
--------------------------- :: inl
G |- inl{t2}(e) : t1 + t2
G |- e : t2
--------------------------- :: inr
G |- inr{t1}(e) : t1 + t2
G |- e : t1 + t2
G, x:t1 |- e1 : t
G, x:t2 |- e2 : t
--------------------------------------------------- :: case
G |- case e {inl x -> e1 | inr x -> e2} : t
defns
JDyn :: '' ::=
defn
e ~> e' :: :: eval :: 'eval_'
by
e ~> e'
----------- :: s
s e ~> s e'
e1 ~> e1'
--------------- :: fapp_left
e1 e2 ~> e1' e2
e1 val
e2 ~> e2'
--------------- :: fapp_right
e1 e2 ~> e1 e2'
e2 val
------------------------------- :: beta
(\(x:t) e1) e2 ~> e1 { e2 / x}
e ~> e'
-------------------------------------------------------------- :: rec_scrut
rec e { z -> e0 ; s x -> e1 } ~> rec e' { z -> e0 ; s x -> e1 }
----------------------------------- :: rec_z
rec z { z -> e0 ; s x -> e1 } ~> e0
(s e) val
----------------------------------------------------------------------- :: rec_s
rec (s e) { z -> e0 ; s x -> e1 } ~> e1 { e / x } (rec e { z -> e0 ; s x -> e1})
e1 ~> e1'
--------------------- :: pair_left
<e1;e2> ~> <e1';e2>
e1 val
e2 ~> e2'
--------------------- :: pair_right
<e1;e2> ~> <e1;e2'>
e ~> e'
------------------ :: fst
fst e ~> fst e'
e ~> e'
------------------ :: snd
snd e ~> snd e'
e1 val
e2 val
-------------------- :: fst_val
fst <e1;e2> ~> e1
e1 val
e2 val
-------------------- :: snd_val
snd <e1;e2> ~> e2
e ~> e'
---------------------------- :: abort
abort{t}(e) ~> abort{t}(e')
e ~> e'
------------------------- :: inl
inl{t}(e) ~> inl{t}(e')
e ~> e'
------------------------- :: inr
inr{t}(e) ~> inr{t}(e')
e ~> e'
--------------------------------------------------------------------------------------------- :: case
case e {inl x1 -> e1 | inr x2 -> e2} ~> case e' {inl x1 -> e1 | inr x2 -> e2}
e val
--------------------------------------------------------------------- :: casel
case inl{t2}(e) {inl x1 -> e1 | inr x2 -> e2 } ~> e1{e/x1}
e val
--------------------------------------------------------------------- :: caser
case inr{t1}(e) {inl x1 -> e1 | inr x2 -> e2 } ~> e2{e/x2}