-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.ott
More file actions
319 lines (248 loc) · 7.94 KB
/
rules.ott
File metadata and controls
319 lines (248 loc) · 7.94 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Entailment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defns
Qs :: '' ::=
defn
QF1 ||- QF2 :: :: Qrules :: 'Q_' {{ com Concrete constraint entailment }}
by
(UCtx1, LCtx1) ||- (UCtx2, LCtx2)
q \notin Dup
------------------------------------------:: Linear
(UCtx1, LCtx1 \u q) ||- (UCtx2, LCtx2 \u q)
(UCtx1, LCtx1 \u q) ||- (UCtx2, LCtx2)
q \in Dup
------------------------------------------:: DupOne
(UCtx1, LCtx1 \u q) ||- (UCtx2, LCtx2 \u q)
(UCtx1, LCtx1) ||- (UCtx2, LCtx2)
q \notin LCtx2
q \in Dup
------------------------------------------:: DupNone
(UCtx1, LCtx1 \u q) ||- (UCtx2, LCtx2)
UCtx1 \subseteq UCtx2
---------------------------------------:: Ur
(UCtx1, emptyset) ||- (UCtx2, emptyset)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Entailment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defns
Entail :: '' ::=
defn
QF |- CF :: :: Crules :: 'C_' {{ com Generalised constraint entailment }}
by
Q1 ||- Q2 \\\\
Q2 |- C
--------- :: Dom
Q1 |- C
--------- :: Id
Q |- Q
Q1 |- C1
Q2 |- C2
-------------- :: Tensor
Q1*Q2 |- C1*C2
Q |- C1
Q |- C2
------------- :: With
Q |- C1 & C2
Q0*Q1 |- C
------------- :: Impl
pi. Q0 |- pi.(Q1 => C)
------------- :: Top
Q |- Top
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Typing rules %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defns
Ty :: '' ::=
defn
QF ; G |- e : t :: :: Ty :: 'E_' {{ com Expression typing }}
by
G1 = x :_1 forall as. Q1 =o u
--------------------------- :: Var
Q1[ts/as];G1+omega.G2 |- x : u[ts/as]
Q;G, x:_pi t1 |- e : t2
---------------------- :: Abs
Q;G |- \x.e : t1 ->_pi t2
Q1;G1 |- e1 : t1 ->_pi t
Q2; G2 |- e2 : t1
------------------------------ :: App
Q1*pi.Q2;G1+pi.G2 |- e1 e2 : t
Q ; G |- e : t[us/as]
------------------------- :: Pack
Q * Q1[us/as];G |- pack e : exists as. t o= Q1
Q1;G1 |- e1 : exists as. t1 o= Q
as fresh
Q2 * Q;G2,x:_1 t1 |- e2 : t
------------------------------------------------- :: Unpack
Q1 * Q2;G1 + G2 |- unpack x = e1 in e2 : t
Q1*Q;G1 |- e1 : t1
Q2;G2,x:_pi Q =o t1 |- e2 : t
--------------------------- :: Let
pi.Q1*Q2 ;pi.G1+G2 |- let_pi x = e1 in e2 : t
Q1*Q;G1 |- e1 : t1
as fresh
s = forall as.Q =o t1
Q2;G2,x:_pi forall as.Q =o t1 |- e2 : t
--------------------------- :: LetSig
pi.Q1 * Q2 ;pi.G1+G2 |- let_pi x : s = e1 in e2 : t
Q1;G1 |- e : T ts
Ki : forall as. usi ->_pisi T as
Q2; G2, < xi :_(pi.pii) ui[ts/as] > |- ei : t
------------------------- :: Case
pi.Q1*Q2;pi.G1+G2 |- case_pi e of { alts } : t
Q1;G |- e : t
Q ||- Q1
------------------------- :: Sub
Q;G |- e : t
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Constraint generation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defns
Gen :: '' ::=
defn
G |-> e : t ~> CF :: :: Gen :: 'G_' {{ com Constraint generation }}
by
G1 = x :_1 forall as. Q =o u
------------------------------ :: Var
G1 + omega.G2 |-> x : u[ts/as] ~> Q[ts/as]
G, x:_pi t0 |-> e : t ~> C
------------------------------ :: Abs
G |-> \x. e : t0 ->_pi t ~> C
G1 |-> e1 : t2 ->_pi t ~> C1
G2 |-> e2 : t2 ~> C2
------------------------------ :: App
G1 + pi.G2 |-> e1 e2 : t ~> C1 * pi.C2
G |-> e : T ss ~> C
Ki : forall as. usi ->_pisi T as
D, <xi:_(pi.pii) ui[ss/as]> |-> ei : t ~> Ci
------------------------------ :: Case
pi.G + D |-> case_pi e of {alts} : t ~> pi.C * && Ci
G1 |-> e1 : exists as. t1 o= Q1 ~> C1
as fresh
G2, x:_1 t1 |-> e2 : t ~> C2
------------------------------ :: Unpack
G1+G2 |-> unpack x = e1 in e2 : t ~> C1 * 1.(Q1 => C2)
G |-> e : t[us/as] ~> C
------------------------------ :: Pack
G |-> pack e : exists as. t o= Q ~> C * Q[us/as]
G1 |-> e1 : t1 ~> C1
G2, x:_pi t1 |-> e2 : t ~> C2
------------------------------ :: Let
pi.G1+G2 |-> let_pi x = e1 in e2 : t ~> pi.C1 * C2
G1 |-> e1 : t1 ~> C1
Q_r * Q |- C1
G2, x:_pi Q =o t1 |-> e2 : t ~> C2
------------------------------ :: LetGen
pi.G1+G2 |-> let_pi x = e1 in e2 : t ~> pi.Q_r * C2
G1 |-> e1 : t1 ~> C1
as fresh
G2, x:_pi forall as. Q =o t1 |-> e2 : t ~> C2
------------------------------ :: LetSig
pi.G1+G2 |-> let_pi x : forall as. Q =o t1 = e1 in e2 : t ~> C2 * pi.(Q => C1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Constraint solver %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defns
Solve :: '' ::=
defn
|-s CF_w ~> QF :: :: Solve :: 'S_' {{ com Constraint solving }}
by
---------------------------------------------- :: Atom
|-s pi.q ~> pi.q
|-s C1 ~> Q1 |-s C2 ~> Q2
--------------------------------------------------------------- :: With
|-s C1 & C2 ~> Q1 /\ Q2
|-s C1 ~> Q1 |-s C2 ~> Q2
------------------------------------------------------------- :: Tensor
|-s C1 * C2 ~> Q1 * Q2
|-s C ~> Q_i
|-d Q_i \d Q_b ~> Q_o
---------------------------------------------- :: Impl
|-s pi . (Q_b => C) ~> pi . Q_o
defn
|-d QF1 \d QF2 ~> QF3 :: :: CheckMult :: 'D_' {{ com Constraint bounding }}
by
q \notin Dup
q \notin LCtx_b
q \notin UCtx_b
q \notin Q_o
|-d Q_i \d (UCtx_b, LCtx_b) ~> Q_o * 1.q
------------------------------------ :: Linear
|-d Q_i \d (UCtx_b, LCtx_b \u q) ~> Q_o
q \in Dup
q \notin LCtx_b
q \notin UCtx_b
q \notin Q_o
|-d Q_i \d (UCtx_b, LCtx_b) ~> Q_o * many 1.q
------------------------------------ :: Dup
|-d Q_i \d (UCtx_b, LCtx_b \u q) ~> Q_o
q \notin LCtx_b
q \notin UCtx_b
q \notin Q_o
|-d Q_i \d (UCtx_b, LCtx_b) ~> Q_o * pi_1.q * .. * pi_n.q
------------------------------------ :: Ur
|-d Q_i \d (UCtx_b \u q, LCtx_b) ~> Q_o
defn
QF1 /\ QF2 = QF3 :: :: QInf :: 'Inf_' {{ com Constraint meet }}
by
------------------------------------------------------------------- :: Ur
(UCtx1, emptyset) /\ (UCtx2, emptyset) = (UCtx1 \u UCtx2, emptyset)
(UCtx1, LCtx1) /\ (UCtx2, LCtx2) = Q
------------------------------------------------------------------- :: Match
(UCtx1, LCtx1 \u q ) /\ (UCtx2, LCtx2 \u q) = Q * 1.q
(UCtx1, LCtx1) /\ (UCtx2, LCtx2) = Q
q \notin LCtx2
q \notin Dup
------------------------------------------------------------------- :: DiffL
(UCtx1, LCtx1 \u q ) /\ (UCtx2, LCtx2) = Q * omega.q
(UCtx1, LCtx1) /\ (UCtx2, LCtx2) = Q
q \notin LCtx1
q \notin Dup
------------------------------------------------------------------- :: DiffR
(UCtx1, LCtx1 ) /\ (UCtx2, LCtx2 \u q) = Q * omega.q
(UCtx1, LCtx1) /\ (UCtx2, LCtx2) = Q
q \notin LCtx2
q \in Dup
------------------------------------------------------------------- :: DiffDL
(UCtx1, LCtx1 \u q ) /\ (UCtx2, LCtx2) = Q * 1.q
(UCtx1, LCtx1) /\ (UCtx2, LCtx2) = Q
q \notin LCtx1
q \in Dup
------------------------------------------------------------------- :: DiffDR
(UCtx1, LCtx1 ) /\ (UCtx2, LCtx2 \u q) = Q * 1.q
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Desugared expressions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defns
Core :: '' ::=
defn
G |- e : t :: :: Core :: 'L_' {{ com Core language }}
by
x :_1 forall as. u \in G
------------------------- :: Var
G |- x : u[ts/as]
G, x:_pi t1 |- e : t2
------------------------ :: Abs
G |- \x.e : t1 ->_pi t2
G1 |- e1 : t1 ->_pi t
G2 |- e1 : t1
------------------------- :: App
G1 + pi.G2 |- e1 e2 : t
G1 |- e1 : t1[us/as]
G2 |- e2 : t2[us/as]
------------------------------------------ :: Pack
G1+G2 |- pack (e1, e2) : exists as.t2 o- t1
G1 |- e1 : exists as. t2 o- t1
as fresh
G2,x:_1 t1,y:_1 t2 |- e2 : t
------------------------------------ :: Unpack
G1+G2 |- unpack (x,y) = e1 in e2 : t
G1 |- e1 : t1
G2, x:_pi s |- e2 : t
----------------------------------- :: Let
pi.G1 + G2 |- let_pi x : s = e1 in e2 : t
G1 |- e : T ts
Ki : forall as. usi ->_pisi T as
G2, < xi :_(pi.pii) ui[ts/as] > |- ei : t
------------------------------------------------ :: Case
pi.G1+G2 |- case_pi e of { alts } : t