Newer
Older
\usepackage{tikz-cd}
\usepackage{mathpartir}
\newtheorem{theorem}{Theorem}
\newtheorem{definition}{Definition}
\newcommand{\type}{\,\,\text{type}}
\newcommand{\ctx}{\,\,\text{ctx}}
\newcommand{\ltdyn}{\sqsubseteq}
\newcommand{\gtdyn}{\sqsupseteq}
\newcommand{\equidyn}{\mathrel{\gtdyn\ltdyn}}
\newcommand{\ltdynv}{\mathrel{\sqsubseteq_V}}
\newcommand{\ltdynt}{\mathrel{\sqsubseteq_T}}
\newcommand{\upcast}[2]{\langle #2 \leftarrowtail #1 \rangle}
\newcommand{\dncast}[2]{\langle #1 \twoheadleftarrow #2 \rangle}
\newcommand{\Set}{\text{Set}}
\newcommand{\relto}{\to}
\newcommand{\M}{\mathcal{M}}
\newcommand{\sq}{\square}
\newcommand{\lett}{\text{let}\,\,}
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
\begin{document}
\title{Call-by-value Gradual Type Theory}
\author{Max S. New, Daniel R. Licata and Amal Ahmed}
\maketitle
\begin{figure}
\begin{mathpar}
A \type \and
\Gamma \ctx\\
\inferrule
{A \type \and A' \type}
{A \ltdynv A'}
\inferrule
{A \type \and A' \type}
{A \ltdynt A'}\\
\inferrule
{\Gamma \ctx \and A \type}
{\Gamma \vdash^v v : A}
\inferrule
{\Gamma \ctx \and A \type}
{\Gamma \vdash^T t : A}\\
\inferrule
{\Gamma \ctx\and \Gamma' \ctx}
{\Phi_v : \Gamma \ltdynv \Gamma'}
\inferrule
{\Gamma \ctx\and \Gamma' \ctx}
{\Phi_t : \Gamma \ltdyn \Gamma'}\\
\inferrule
{\Phi_v : \Gamma \ltdyn \Gamma'\and
\Gamma \vdash^v v : A \and
\Gamma' \vdash^v v' : A'
}
{\Phi_v \vdash^v v \ltdynv v' : A \ltdynv A'}
\inferrule
{\Phi : \Gamma \ltdyn \Gamma'\and
\Gamma \vdash^T t : A \and
\Gamma' \vdash^T t' : A'
}
{\Phi \vdash^T t \ltdyn t' : A \ltdyn A'}
\end{mathpar}
\caption{GTTv Judgments and their Pressupositions}
\end{figure}
\begin{figure}
\begin{mathpar}
\inferrule{x:A \in \Gamma}
{\Gamma \vdash^v x : A}
\inferrule{\gamma : \prod_{x:A \in \Gamma} \Delta \vdash \gamma(x) : A\and
\Gamma \vdash v : B
}{\Delta \vdash v[\gamma] : B}
\inferrule{\gamma : \prod_{x:A \in \Gamma} \Delta \vdash \gamma(x) : A\and
\Gamma \vdash t : B
}{\Delta \vdash t[\gamma] : B}
\inferrule{\Gamma \vdash v : A}
{\Gamma \vdash \ret v : A}
\inferrule{\Gamma \vdash t : A\and \Gamma, x : A \vdash u : B}
{\Gamma \vdash \lett x = t; u : B}
\lett x = \ret v; t \cong t[v/x]\\
v[\gamma][\delta] = v[\delta \circ \gamma]\\
t[\gamma][\delta] = t[\delta \circ \gamma]\
v[x/x,\ldots] = v\\
t[x/x,\ldots] = t\\
\lett x = (\lett y = r; s); t \cong \lett y = r; \lett x = s; t\\
\end{mathpar}
\caption{GTTv Judgmental Term, Value Rules}
\end{figure}
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
\begin{mathpar}
\inferrule
{}
{\Phi, x \ltdyn x' : A \ltdyn A' \vdash \ret x \ltdyn \ret x' : A \ltdyn A'}
\inferrule
{\Phi \vdash t \ltdyn t' : A \ltdyn A'\and
\Phi, x \ltdyn x' : A \ltdyn A' \vdash u \ltdyn u' : C \ltdyn C'}
{\Phi \vdash \lett x = t; u \ltdyn \lett x' = t'; u' : C \ltdyn C'}
\end{mathpar}
\begin{mathpar}
\inferrule
{\Gamma \vdash^v v : A \and A \ltdyn A'}
{\Gamma \vdash^T \upcast{A}{A'}v : A'}
\inferrule
{\Gamma \vdash^v v : A' \and A \ltdyn A'}
{\Gamma \vdash^T \dncast{A}{A'}v : A}
\inferrule
{}
{x \ltdyn x' : A \ltdyn A' \vdash \upcast{A}{A'}x \ltdyn \ret x' : A'}
\inferrule
{}
{x : A \vdash \ret x \ltdyn \upcast{A}{A'}x : A \ltdyn A'}
\inferrule
{}
{x \ltdyn x' : A \ltdyn A' \vdash \ret x \ltdyn \dncast{A}{A'}x' : A'}
\inferrule
{}
{x' : A' \vdash \dncast{A}{A'}x' \ltdyn x' : A \ltdyn A'}
\end{mathpar}
\begin{mathpar}
\inferrule{A \type \and B \type}{A \times B \type}
\inferrule
{\Gamma \vdash v_1 : A_1 \and \Gamma \vdash v_2 : A_2}
{\Gamma \vdash^{V} (v_1, v_2) : A_1 \times A_2}
\inferrule
{\Gamma \vdash t : A_1 \times A_2\and
\Gamma, x_1 : A_1, x_2 : A_2 \vdash u : C}
{\Gamma \vdash \lett (x,x') = t; u : C}
\inferrule
{}
{x \ltdyn x' : A \ltdyn A', y \ltdyn y' : B \ltdyn B' \vdash \ret (x,y) \ltdyn \ret (x',y') : A \times B \ltdyn A' \times B'}
\inferrule
{\Phi \vdash t \ltdyn t' : A \times B \ltdyn A' \times B'\and
\Phi, x \ltdyn x' : A \ltdyn A', y \ltdyn y' : B \ltdyn B' \vdash u \ltdyn u' : C \ltdyn C'}
{\Phi \vdash \lett (x,y) = t; u \ltdyn \lett (x',y') = t'; u' : C \ltdyn C'}
\inferrule
{}
{\Gamma \vdash \lett (x_1,x_2) = (v_1,v_2); t \equidyn t[v_1/x_1,v_2/x_2] : C}
\inferrule
{}
{\Gamma \vdash t \equidyn \lett (x_1,x_2) = t; \ret (x_1,x_2) : A_1 \times A_2}
\end{mathpar}
\begin{theorem}[Product Contract]
If $A_1 \ltdyn A_1'$ and $A_2 \ltdyn A_2'$ then
\begin{align*}
x' : A_1' \times A_2' \vdash
\dncast{A_1\times A_2}{A_1'\times A_2'}x'
&\equidyn\\
\lett (x_1', x_2') = x'; \lett y_1 = \dncast{A_1}{A_1'}x_1'; \lett y_2 = \dncast{A_2}{A_2'}x_2'; \ret (y_1,y_2)&\equidyn\\
\lett (x_1', x_2') = x'; \lett y_2 = \dncast{A_2}{A_2'}x_2'; \lett y_1 = \dncast{A_1}{A_1'}x_1'; \ret (y_1,y_2)\\
\end{align*}
\end{theorem}
\begin{proof}
First, we show the direction that requires $\eta$ expansion.
\begin{mathpar}
\inferrule{}
{
\dncast{A_1\times A_2}{A_1'\times A_2'}x'
\ltdyn
\lett (x_1', x_2') = x'; \lett y_1 = \dncast{A_1}{A_1'}x_1'; \lett y_2 = \dncast{A_2}{A_2'}x_2'; \ret (y_1,y_2)}
\end{mathpar}
By the Down-Left rule, it is sufficient to prove that under $x \ltdyn x' : (A_1 \times A_2) \ltdyn (A_1' \times A_2')$,
\begin{mathpar}
{x \ltdyn
\lett (x_1', x_2') = x'; \lett y_1 = \dncast{A_1}{A_1'}x_1'; \lett y_2 = \dncast{A_2}{A_2'}x_2'; \ret (y_1,y_2)}
\end{mathpar}
By the $\eta$ rule for products and the let-rule for values, $x :
A_1 \times A_2$ can be expanded as follows:
\begin{align*}
x &\equidyn
\lett (x_1,x_2) = x; \ret (x_1,x_2)\\
&\equidyn
\lett (x_1,x_2) = x; \lett y_1 =\ret x_1; \ret (y_1,x_2)\\
&\equidyn
\lett (x_1,x_2) = x; \lett y_1 = \ret x_1; \lett y_2 = \ret x_2; \ret (y_1,y_2)
\end{align*}
Now that we have the two sides with the same structre, we use the
congruence rules for product pattern matching and we have to use the
Down-Right rule twice:
\begin{mathpar}
x_1 \ltdyn x_1' : A_1 \ltdyn A_1' \vdash \ret x_1 \ltdyn \dncast{A_1}{A_1'}{x_1'} : A_1
x_2 \ltdyn x_2' : A_2 \ltdyn A_2' \vdash \ret x_2 \ltdyn \dncast{A_2}{A_2'}{x_2'} : A_2
\end{mathpar}
Next, we show the reverse inequality using $\eta$ contraction
\begin{mathpar}
{
\lett (x_1', x_2') = x'; \lett y_1 = \dncast{A_1}{A_1'}x_1'; \lett y_2 = \dncast{A_2}{A_2'}x_2'; \ret (y_1,y_2)\ltdyn \dncast{A_1\times A_2}{A_1'\times A_2'}x' }
\end{mathpar}
This time, we need to use congruence \emph{first}, because the
downcast is on the right, we can't use the Down-Right rule unless
the left side is already at the less dynamic type.
So we rewrite the right side as
\begin{align*}
\dncast{A_1\times A_2}{A_1'\times A_2'}x'
&\ltdyn
\lett (x_1',x_2') = x'; \dncast{A_1\times A_2}{A_1'\times A_2'}(x_1',x_2')\\
&\ltdyn
\lett (x_1',x_2') = x'; \lett y_1' = x_1'; \dncast{A_1\times A_2}{A_1'\times A_2'}(x_1',x_2')\\
&\ltdyn
\lett (x_1',x_2') = x'; \lett y_1' = x_1'; \lett y_2' = x_2'; \dncast{A_1\times A_2}{A_1'\times A_2'}(x_1',x_2')
\end{align*}
\end{proof}
Then the proof is again by the congruence rules, using Down-Left twice
and Down-Right once:
\begin{mathpar}
x_1' : A_1' \vdash \dncast{A_1}{A_1'}x_1' \ltdyn \ret x_1'
x_2' : A_2' \vdash \dncast{A_2}{A_2'}x_2' \ltdyn \ret x_2'
x_1 \ltdyn x_1', x_2 \ltdyn x_2' \vdash (x_1,x_2) \ltdyn \dncast{A_1\times A_2}{A_1'\times A_2'}(x_1',x_2')
\end{mathpar}
\begin{corollary}[Projections commute]
For any $A \ltdyn A', B \ltdyn B'$ and $\Gamma, x:A, y : B \vdash t : C$,
\[
\lett x = \dncast{A}{A'}x'; \lett y = \dncast B {B'} y'; t
\equidyn
\lett y = \dncast B {B'} y'; \lett x = \dncast{A}{A'}x'; t
\]
\end{corollary}
\begin{proof}
By the previous theorem, both are equivalent to
\[
\lett z = \dncast{A\times B}{A' \times B'}(x',y');
\lett (x,y) = z;
t
\]
\end{proof}