754
|
1 |
(*<*)
|
|
2 |
theory Paper
|
1506
|
3 |
imports "../Nominal/Test" "LaTeXsugar"
|
754
|
4 |
begin
|
1493
|
5 |
|
|
6 |
notation (latex output)
|
|
7 |
swap ("'(_ _')" [1000, 1000] 1000) and
|
|
8 |
fresh ("_ # _" [51, 51] 50) and
|
1506
|
9 |
fresh_star ("_ #* _" [51, 51] 50) and
|
1493
|
10 |
supp ("supp _" [78] 73) and
|
|
11 |
uminus ("-_" [78] 73) and
|
|
12 |
If ("if _ then _ else _" 10)
|
754
|
13 |
(*>*)
|
|
14 |
|
|
15 |
section {* Introduction *}
|
|
16 |
|
|
17 |
text {*
|
1524
|
18 |
So far, Nominal Isabelle provides a mechanism for constructing
|
1607
|
19 |
alpha-equated terms, for example
|
1485
|
20 |
|
1520
|
21 |
\begin{center}
|
|
22 |
$t ::= x \mid t\;t \mid \lambda x. t$
|
|
23 |
\end{center}
|
|
24 |
|
|
25 |
\noindent
|
1550
|
26 |
where free and bound variables have names. For such terms Nominal Isabelle
|
1607
|
27 |
derives automatically a reasoning infrastructure that has been used
|
1550
|
28 |
successfully in formalisations of an equivalence checking algorithm for LF
|
|
29 |
\cite{UrbanCheneyBerghofer08}, Typed
|
1520
|
30 |
Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
|
|
31 |
\cite{BengtsonParrow07,BengtsonParow09} and a strong normalisation result
|
|
32 |
for cut-elimination in classical logic \cite{UrbanZhu08}. It has also been
|
|
33 |
used by Pollack for formalisations in the locally-nameless approach to
|
|
34 |
binding \cite{SatoPollack10}.
|
|
35 |
|
1535
|
36 |
However, Nominal Isabelle has fared less well in a formalisation of
|
1524
|
37 |
the algorithm W \cite{UrbanNipkow09}, where types and type-schemes
|
|
38 |
are of the form
|
1570
|
39 |
%
|
|
40 |
\begin{equation}\label{tysch}
|
|
41 |
\begin{array}{l}
|
|
42 |
T ::= x \mid T \rightarrow T \hspace{5mm} S ::= \forall \{x_1,\ldots, x_n\}. T
|
|
43 |
\end{array}
|
|
44 |
\end{equation}
|
1520
|
45 |
|
|
46 |
\noindent
|
1566
|
47 |
and the quantification $\forall$ binds a finite (possibly empty) set of
|
1550
|
48 |
type-variables. While it is possible to implement this kind of more general
|
|
49 |
binders by iterating single binders, this leads to a rather clumsy
|
|
50 |
formalisation of W. The need of iterating single binders is also one reason
|
|
51 |
why Nominal Isabelle and similar theorem provers that only provide
|
|
52 |
mechanisms for binding single variables have not fared extremely well with the
|
|
53 |
more advanced tasks in the POPLmark challenge \cite{challenge05}, because
|
|
54 |
also there one would like to bind multiple variables at once.
|
1520
|
55 |
|
1577
|
56 |
Binding multiple variables has interesting properties that cannot be captured
|
1587
|
57 |
easily by iterating single binders. For example in case of type-schemes we do not
|
|
58 |
want to make a distinction about the order of the bound variables. Therefore
|
1550
|
59 |
we would like to regard the following two type-schemes as alpha-equivalent
|
1572
|
60 |
%
|
|
61 |
\begin{equation}\label{ex1}
|
|
62 |
\forall \{x, y\}. x \rightarrow y \;\approx_\alpha\; \forall \{y, x\}. y \rightarrow x
|
|
63 |
\end{equation}
|
1520
|
64 |
|
|
65 |
\noindent
|
1587
|
66 |
but assuming that $x$, $y$ and $z$ are distinct variables,
|
|
67 |
the following two should \emph{not} be alpha-equivalent
|
1572
|
68 |
%
|
|
69 |
\begin{equation}\label{ex2}
|
|
70 |
\forall \{x, y\}. x \rightarrow y \;\not\approx_\alpha\; \forall \{z\}. z \rightarrow z
|
|
71 |
\end{equation}
|
1520
|
72 |
|
|
73 |
\noindent
|
1587
|
74 |
Moreover, we like to regard type-schemes as
|
1524
|
75 |
alpha-equivalent, if they differ only on \emph{vacuous} binders, such as
|
1572
|
76 |
%
|
|
77 |
\begin{equation}\label{ex3}
|
|
78 |
\forall \{x\}. x \rightarrow y \;\approx_\alpha\; \forall \{x, z\}. x \rightarrow y
|
|
79 |
\end{equation}
|
1485
|
80 |
|
1520
|
81 |
\noindent
|
1535
|
82 |
where $z$ does not occur freely in the type.
|
1545
|
83 |
In this paper we will give a general binding mechanism and associated
|
1524
|
84 |
notion of alpha-equivalence that can be used to faithfully represent
|
1545
|
85 |
this kind of binding in Nominal Isabelle. The difficulty of finding the right notion
|
1607
|
86 |
for alpha-equivalence can be appreciated in this case by considering that the
|
1524
|
87 |
definition given by Leroy in \cite{Leroy92} is incorrect (it omits a side-condition).
|
|
88 |
|
1520
|
89 |
However, the notion of alpha-equivalence that is preserved by vacuous binders is not
|
1566
|
90 |
always wanted. For example in terms like
|
1587
|
91 |
%
|
1535
|
92 |
\begin{equation}\label{one}
|
1550
|
93 |
\LET x = 3 \AND y = 2 \IN x\,-\,y \END
|
1535
|
94 |
\end{equation}
|
1520
|
95 |
|
|
96 |
\noindent
|
1524
|
97 |
we might not care in which order the assignments $x = 3$ and $y = 2$ are
|
1535
|
98 |
given, but it would be unusual to regard \eqref{one} as alpha-equivalent
|
1524
|
99 |
with
|
1587
|
100 |
%
|
1520
|
101 |
\begin{center}
|
1550
|
102 |
$\LET x = 3 \AND y = 2 \AND z = loop \IN x\,-\,y \END$
|
1520
|
103 |
\end{center}
|
|
104 |
|
|
105 |
\noindent
|
1550
|
106 |
Therefore we will also provide a separate binding mechanism for cases in
|
|
107 |
which the order of binders does not matter, but the ``cardinality'' of the
|
1535
|
108 |
binders has to agree.
|
1520
|
109 |
|
1550
|
110 |
However, we found that this is still not sufficient for dealing with
|
|
111 |
language constructs frequently occurring in programming language
|
|
112 |
research. For example in $\mathtt{let}$s containing patterns
|
1587
|
113 |
%
|
1535
|
114 |
\begin{equation}\label{two}
|
1550
|
115 |
\LET (x, y) = (3, 2) \IN x\,-\,y \END
|
1535
|
116 |
\end{equation}
|
1520
|
117 |
|
|
118 |
\noindent
|
1535
|
119 |
we want to bind all variables from the pattern inside the body of the
|
|
120 |
$\mathtt{let}$, but we also care about the order of these variables, since
|
1566
|
121 |
we do not want to regard \eqref{two} as alpha-equivalent with
|
1587
|
122 |
%
|
1520
|
123 |
\begin{center}
|
1550
|
124 |
$\LET (y, x) = (3, 2) \IN x\,- y\,\END$
|
1520
|
125 |
\end{center}
|
|
126 |
|
|
127 |
\noindent
|
1545
|
128 |
As a result, we provide three general binding mechanisms each of which binds multiple
|
1566
|
129 |
variables at once, and let the user chose which one is intended when formalising a
|
1524
|
130 |
programming language calculus.
|
1485
|
131 |
|
1545
|
132 |
By providing these general binding mechanisms, however, we have to work around
|
1617
|
133 |
a problem that has been pointed out by Pottier in \cite{Pottier06} and Cheney in
|
|
134 |
\cite{Cheney05}: in
|
1524
|
135 |
$\mathtt{let}$-constructs of the form
|
1587
|
136 |
%
|
1520
|
137 |
\begin{center}
|
|
138 |
$\LET x_1 = t_1 \AND \ldots \AND x_n = t_n \IN s \END$
|
|
139 |
\end{center}
|
|
140 |
|
|
141 |
\noindent
|
1524
|
142 |
which bind all the $x_i$ in $s$, we might not care about the order in
|
1520
|
143 |
which the $x_i = t_i$ are given, but we do care about the information that there are
|
1524
|
144 |
as many $x_i$ as there are $t_i$. We lose this information if we represent the
|
1550
|
145 |
$\mathtt{let}$-constructor by something like
|
1587
|
146 |
%
|
1523
|
147 |
\begin{center}
|
1524
|
148 |
$\LET [x_1,\ldots,x_n].s\;\; [t_1,\ldots,t_n]$
|
1523
|
149 |
\end{center}
|
1520
|
150 |
|
1523
|
151 |
\noindent
|
1566
|
152 |
where the notation $[\_\!\_].\_\!\_$ indicates that the $x_i$ become bound
|
|
153 |
in $s$. In this representation the term \mbox{$\LET [x].s\;\;[t_1,t_2]$}
|
1628
|
154 |
would be a perfectly legal instance. To exclude such terms, additional
|
|
155 |
predicates about well-formed terms are needed in order to ensure that the two
|
1566
|
156 |
lists are of equal length. This can result into very messy reasoning (see
|
1577
|
157 |
for example~\cite{BengtsonParow09}). To avoid this, we will allow type specifications
|
1566
|
158 |
for $\mathtt{let}$s as follows
|
1587
|
159 |
%
|
1528
|
160 |
\begin{center}
|
|
161 |
\begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
|
1570
|
162 |
$trm$ & $::=$ & \ldots\\
|
1545
|
163 |
& $\mid$ & $\mathtt{let}\;a\!::\!assn\;\;s\!::\!trm\quad\mathtt{bind}\;bn\,(a) \IN s$\\[1mm]
|
1570
|
164 |
$assn$ & $::=$ & $\mathtt{anil}$\\
|
1528
|
165 |
& $\mid$ & $\mathtt{acons}\;\;name\;\;trm\;\;assn$
|
|
166 |
\end{tabular}
|
|
167 |
\end{center}
|
|
168 |
|
|
169 |
\noindent
|
1577
|
170 |
where $assn$ is an auxiliary type representing a list of assignments
|
1545
|
171 |
and $bn$ an auxiliary function identifying the variables to be bound by
|
1566
|
172 |
the $\mathtt{let}$. This function is defined by recursion over $assn$ as follows
|
1528
|
173 |
|
|
174 |
\begin{center}
|
|
175 |
$bn\,(\mathtt{anil}) = \varnothing \qquad bn\,(\mathtt{acons}\;x\;t\;as) = \{x\} \cup bn\,(as)$
|
|
176 |
\end{center}
|
1523
|
177 |
|
1528
|
178 |
\noindent
|
1550
|
179 |
The scope of the binding is indicated by labels given to the types, for
|
|
180 |
example \mbox{$s\!::\!trm$}, and a binding clause, in this case
|
1577
|
181 |
$\mathtt{bind}\;bn\,(a) \IN s$, that states to bind in $s$ all the names the
|
1607
|
182 |
function call $bn\,(a)$ returns. This style of specifying terms and bindings is
|
1577
|
183 |
heavily inspired by the syntax of the Ott-tool \cite{ott-jfp}.
|
1528
|
184 |
|
1545
|
185 |
However, we will not be able to deal with all specifications that are
|
1617
|
186 |
allowed by Ott. One reason is that Ott lets the user to specify ``empty''
|
|
187 |
types like
|
1570
|
188 |
|
|
189 |
\begin{center}
|
|
190 |
$t ::= t\;t \mid \lambda x. t$
|
|
191 |
\end{center}
|
|
192 |
|
|
193 |
\noindent
|
1617
|
194 |
where no clause for variables is given. Arguably, such specifications make
|
|
195 |
some sense in the context of Coq's type theory (which Ott supports), but not
|
|
196 |
at all in a HOL-based environment where every datatype must have a non-empty
|
|
197 |
set-theoretic model.
|
1570
|
198 |
|
|
199 |
Another reason is that we establish the reasoning infrastructure
|
|
200 |
for alpha-\emph{equated} terms. In contrast, Ott produces a reasoning
|
|
201 |
infrastructure in Isabelle/HOL for
|
1545
|
202 |
\emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms
|
1556
|
203 |
and the raw terms produced by Ott use names for bound variables,
|
1545
|
204 |
there is a key difference: working with alpha-equated terms means that the
|
1617
|
205 |
two type-schemes (with $x$, $y$ and $z$ being distinct)
|
1528
|
206 |
|
|
207 |
\begin{center}
|
|
208 |
$\forall \{x\}. x \rightarrow y \;=\; \forall \{x, z\}. x \rightarrow y$
|
|
209 |
\end{center}
|
|
210 |
|
|
211 |
\noindent
|
1617
|
212 |
are not just alpha-equal, but actually \emph{equal}. As a
|
1550
|
213 |
result, we can only support specifications that make sense on the level of
|
|
214 |
alpha-equated terms (offending specifications, which for example bind a variable
|
1556
|
215 |
according to a variable bound somewhere else, are not excluded by Ott, but we
|
|
216 |
have to). Our
|
1550
|
217 |
insistence on reasoning with alpha-equated terms comes from the wealth of
|
|
218 |
experience we gained with the older version of Nominal Isabelle: for
|
|
219 |
non-trivial properties, reasoning about alpha-equated terms is much easier
|
1556
|
220 |
than reasoning with raw terms. The fundamental reason for this is that the
|
1550
|
221 |
HOL-logic underlying Nominal Isabelle allows us to replace
|
1628
|
222 |
``equals-by-equals''. In contrast, replacing ``alpha-equals-by-alpha-equals''
|
1550
|
223 |
in a representation based on raw terms requires a lot of extra reasoning work.
|
1535
|
224 |
|
|
225 |
Although in informal settings a reasoning infrastructure for alpha-equated
|
1607
|
226 |
terms is nearly always taken for granted, establishing
|
1550
|
227 |
it automatically in the Isabelle/HOL theorem prover is a rather non-trivial task.
|
1535
|
228 |
For every specification we will need to construct a type containing as
|
1556
|
229 |
elements the alpha-equated terms. To do so, we use
|
1535
|
230 |
the standard HOL-technique of defining a new type by
|
1556
|
231 |
identifying a non-empty subset of an existing type. The construction we
|
1607
|
232 |
perform in HOL can be illustrated by the following picture:
|
1545
|
233 |
|
1528
|
234 |
\begin{center}
|
1552
|
235 |
\begin{tikzpicture}
|
|
236 |
%\draw[step=2mm] (-4,-1) grid (4,1);
|
|
237 |
|
|
238 |
\draw[very thick] (0.7,0.4) circle (4.25mm);
|
|
239 |
\draw[rounded corners=1mm, very thick] ( 0.0,-0.8) rectangle ( 1.8, 0.9);
|
|
240 |
\draw[rounded corners=1mm, very thick] (-1.95,0.85) rectangle (-2.85,-0.05);
|
|
241 |
|
|
242 |
\draw (-2.0, 0.845) -- (0.7,0.845);
|
|
243 |
\draw (-2.0,-0.045) -- (0.7,-0.045);
|
|
244 |
|
|
245 |
\draw ( 0.7, 0.4) node {\begin{tabular}{@ {}c@ {}}$\alpha$-\\[-1mm]clas.\end{tabular}};
|
|
246 |
\draw (-2.4, 0.4) node {\begin{tabular}{@ {}c@ {}}$\alpha$-eq.\\[-1mm]terms\end{tabular}};
|
|
247 |
\draw (1.8, 0.48) node[right=-0.1mm]
|
|
248 |
{\begin{tabular}{@ {}l@ {}}existing\\[-1mm] type\\ (sets of raw terms)\end{tabular}};
|
|
249 |
\draw (0.9, -0.35) node {\begin{tabular}{@ {}l@ {}}non-empty\\[-1mm]subset\end{tabular}};
|
|
250 |
\draw (-3.25, 0.55) node {\begin{tabular}{@ {}l@ {}}new\\[-1mm]type\end{tabular}};
|
|
251 |
|
|
252 |
\draw[<->, very thick] (-1.8, 0.3) -- (-0.1,0.3);
|
|
253 |
\draw (-0.95, 0.3) node[above=0mm] {isomorphism};
|
|
254 |
|
|
255 |
\end{tikzpicture}
|
1528
|
256 |
\end{center}
|
|
257 |
|
|
258 |
\noindent
|
1577
|
259 |
We take as the starting point a definition of raw terms (defined as a
|
1556
|
260 |
datatype in Isabelle/HOL); identify then the
|
1607
|
261 |
alpha-equivalence classes in the type of sets of raw terms according to our
|
1556
|
262 |
alpha-equivalence relation and finally define the new type as these
|
|
263 |
alpha-equivalence classes (non-emptiness is satisfied whenever the raw terms are
|
1607
|
264 |
definable as datatype in Isabelle/HOL and the fact that our relation for
|
|
265 |
alpha-equivalence is indeed an equivalence relation).
|
1556
|
266 |
|
1607
|
267 |
The fact that we obtain an isomorphism between the new type and the non-empty
|
1556
|
268 |
subset shows that the new type is a faithful representation of alpha-equated terms.
|
1617
|
269 |
That is not the case for example for terms using the locally
|
1607
|
270 |
nameless representation of binders \cite{McKinnaPollack99}: in this representation
|
|
271 |
there are ``junk'' terms that need to
|
1556
|
272 |
be excluded by reasoning about a well-formedness predicate.
|
|
273 |
|
1577
|
274 |
The problem with introducing a new type in Isabelle/HOL is that in order to be useful,
|
1572
|
275 |
a reasoning infrastructure needs to be ``lifted'' from the underlying subset to
|
1607
|
276 |
the new type. This is usually a tricky and arduous task. To ease it,
|
1577
|
277 |
we re-implemented in Isabelle/HOL the quotient package described by Homeier
|
1617
|
278 |
\cite{Homeier05} for the HOL4 system. This package
|
1577
|
279 |
allows us to lift definitions and theorems involving raw terms
|
1617
|
280 |
to definitions and theorems involving alpha-equated terms. For example
|
|
281 |
if we define the free-variable function over raw lambda-terms
|
1577
|
282 |
|
|
283 |
\begin{center}
|
|
284 |
$\fv(x) = \{x\}$\hspace{10mm}
|
|
285 |
$\fv(t_1\;t_2) = \fv(t_1) \cup \fv(t_2)$\\[1mm]
|
|
286 |
$\fv(\lambda x.t) = \fv(t) - \{x\}$
|
|
287 |
\end{center}
|
|
288 |
|
|
289 |
\noindent
|
1620
|
290 |
then with not too great effort we obtain a function $\fv^\alpha$
|
1617
|
291 |
operating on quotients, or alpha-equivalence classes of lambda-terms. This
|
1628
|
292 |
lifted function is characterised by the equations
|
1577
|
293 |
|
|
294 |
\begin{center}
|
1620
|
295 |
$\fv^\alpha(x) = \{x\}$\hspace{10mm}
|
|
296 |
$\fv^\alpha(t_1\;t_2) = \fv^\alpha(t_1) \cup \fv^\alpha(t_2)$\\[1mm]
|
|
297 |
$\fv^\alpha(\lambda x.t) = \fv^\alpha(t) - \{x\}$
|
1577
|
298 |
\end{center}
|
|
299 |
|
|
300 |
\noindent
|
|
301 |
(Note that this means also the term-constructors for variables, applications
|
|
302 |
and lambda are lifted to the quotient level.) This construction, of course,
|
1628
|
303 |
only works if alpha-equivalence is indeed an equivalence relation, and the lifted
|
1617
|
304 |
definitions and theorems are respectful w.r.t.~alpha-equivalence. Accordingly, we
|
1607
|
305 |
will not be able to lift a bound-variable function to alpha-equated terms
|
|
306 |
(since it does not respect alpha-equivalence). To sum up, every lifting of
|
|
307 |
theorems to the quotient level needs proofs of some respectfulness
|
|
308 |
properties. In the paper we show that we are able to automate these
|
|
309 |
proofs and therefore can establish a reasoning infrastructure for
|
|
310 |
alpha-equated terms.\medskip
|
1577
|
311 |
|
1506
|
312 |
|
1528
|
313 |
\noindent
|
|
314 |
{\bf Contributions:} We provide new definitions for when terms
|
|
315 |
involving multiple binders are alpha-equivalent. These definitions are
|
1607
|
316 |
inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
|
1528
|
317 |
proofs, we establish a reasoning infrastructure for alpha-equated
|
|
318 |
terms, including properties about support, freshness and equality
|
1607
|
319 |
conditions for alpha-equated terms. We are also able to derive, at the moment
|
|
320 |
only manually, strong induction principles that
|
|
321 |
have the variable convention already built in.
|
1485
|
322 |
*}
|
|
323 |
|
1493
|
324 |
section {* A Short Review of the Nominal Logic Work *}
|
|
325 |
|
|
326 |
text {*
|
1556
|
327 |
At its core, Nominal Isabelle is an adaption of the nominal logic work by
|
|
328 |
Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
329 |
\cite{HuffmanUrban10}, which we review here briefly to aid the description
|
1556
|
330 |
of what follows. Two central notions in the nominal logic work are sorted
|
1570
|
331 |
atoms and sort-respecting permutations of atoms. The sorts can be used to
|
|
332 |
represent different kinds of variables, such as term- and type-variables in
|
|
333 |
Core-Haskell, and it is assumed that there is an infinite supply of atoms
|
|
334 |
for each sort. However, in order to simplify the description, we shall
|
1617
|
335 |
assume in what follows that there is only one sort of atoms.
|
1493
|
336 |
|
|
337 |
Permutations are bijective functions from atoms to atoms that are
|
|
338 |
the identity everywhere except on a finite number of atoms. There is a
|
|
339 |
two-place permutation operation written
|
1617
|
340 |
%
|
|
341 |
@{text[display,indent=5] "_ \<bullet> _ :: perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
|
1493
|
342 |
|
|
343 |
\noindent
|
1628
|
344 |
in which the generic type @{text "\<beta>"} stands for the type of the object
|
1617
|
345 |
on which the permutation
|
|
346 |
acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
|
1493
|
347 |
the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}}
|
1570
|
348 |
and the inverse permutation of @{term p} as @{text "- p"}. The permutation
|
1493
|
349 |
operation is defined for products, lists, sets, functions, booleans etc
|
1628
|
350 |
(see \cite{HuffmanUrban10}). Concrete permutations are build up from
|
|
351 |
swappings, written as @{text "(a b)"},
|
1617
|
352 |
which are permutations that behave as follows:
|
|
353 |
%
|
|
354 |
@{text[display,indent=5] "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
|
|
355 |
|
1493
|
356 |
|
1570
|
357 |
The most original aspect of the nominal logic work of Pitts is a general
|
|
358 |
definition for the notion of ``the set of free variables of an object @{text
|
|
359 |
"x"}''. This notion, written @{term "supp x"}, is general in the sense that
|
1628
|
360 |
it applies not only to lambda-terms (alpha-equated or not), but also to lists,
|
1570
|
361 |
products, sets and even functions. The definition depends only on the
|
|
362 |
permutation operation and on the notion of equality defined for the type of
|
|
363 |
@{text x}, namely:
|
1617
|
364 |
%
|
1506
|
365 |
@{thm[display,indent=5] supp_def[no_vars, THEN eq_reflection]}
|
1493
|
366 |
|
|
367 |
\noindent
|
|
368 |
There is also the derived notion for when an atom @{text a} is \emph{fresh}
|
|
369 |
for an @{text x}, defined as
|
1617
|
370 |
%
|
1506
|
371 |
@{thm[display,indent=5] fresh_def[no_vars]}
|
1493
|
372 |
|
|
373 |
\noindent
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
374 |
We also use for sets of atoms the abbreviation
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
375 |
@{thm (lhs) fresh_star_def[no_vars]} defined as
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
376 |
@{thm (rhs) fresh_star_def[no_vars]}.
|
1493
|
377 |
A striking consequence of these definitions is that we can prove
|
|
378 |
without knowing anything about the structure of @{term x} that
|
|
379 |
swapping two fresh atoms, say @{text a} and @{text b}, leave
|
1506
|
380 |
@{text x} unchanged.
|
|
381 |
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
382 |
\begin{property}
|
1506
|
383 |
@{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
384 |
\end{property}
|
1506
|
385 |
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
386 |
\noindent
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
387 |
For a proof see \cite{HuffmanUrban10}.
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
388 |
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
389 |
\begin{property}
|
1506
|
390 |
@{thm[mode=IfThen] at_set_avoiding[no_vars]}
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
391 |
\end{property}
|
1493
|
392 |
|
|
393 |
*}
|
|
394 |
|
1485
|
395 |
|
1620
|
396 |
section {* General Binders\label{sec:binders} *}
|
1485
|
397 |
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
398 |
text {*
|
1587
|
399 |
In Nominal Isabelle, the user is expected to write down a specification of a
|
|
400 |
term-calculus and then a reasoning infrastructure is automatically derived
|
1617
|
401 |
from this specification (remember that Nominal Isabelle is a definitional
|
1587
|
402 |
extension of Isabelle/HOL, which does not introduce any new axioms).
|
1579
|
403 |
|
1556
|
404 |
|
1579
|
405 |
In order to keep our work manageable, we will wherever possible state
|
|
406 |
definitions and perform proofs inside Isabelle, as opposed to write custom
|
1617
|
407 |
ML-code that generates them anew for each specification. To that
|
1579
|
408 |
end, we will consider pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.
|
1617
|
409 |
These pairs are intended to represent the abstraction, or binding, of the set @{text "as"}
|
|
410 |
in the body @{text "x"}.
|
1570
|
411 |
|
1579
|
412 |
The first question we have to answer is when the pairs $(as, x)$ and $(bs, y)$ are
|
|
413 |
alpha-equivalent? (At the moment we are interested in
|
1570
|
414 |
the notion of alpha-equivalence that is \emph{not} preserved by adding
|
1579
|
415 |
vacuous binders.) To answer this, we identify four conditions: {\it i)} given
|
1617
|
416 |
a free-variable function $\fv$ of type \mbox{@{text "\<beta> \<Rightarrow> atom set"}}, then @{text x} and @{text y}
|
|
417 |
need to have the same set of free variables; moreover there must be a permutation
|
|
418 |
@{text p} such that {\it ii)} it leaves the free variables of @{text x} and @{text y} unchanged,
|
|
419 |
but {\it iii)} ``moves'' their bound names so that we obtain modulo a relation,
|
|
420 |
say \mbox{@{text "_ R _"}}, two equal terms. We also require {\it iv)} that @{text p} makes
|
|
421 |
the abstracted sets @{text as} and @{text bs} equal. The requirements {\it i)} to {\it iv)} can
|
1579
|
422 |
be stated formally as follows:
|
1556
|
423 |
%
|
1572
|
424 |
\begin{equation}\label{alphaset}
|
|
425 |
\begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
|
1579
|
426 |
\multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{set}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
|
1572
|
427 |
& @{text "fv(x) - as = fv(y) - bs"}\\
|
1617
|
428 |
\wedge & @{text "(fv(x) - as) #* p"}\\
|
1572
|
429 |
\wedge & @{text "(p \<bullet> x) R y"}\\
|
|
430 |
\wedge & @{text "(p \<bullet> as) = bs"}\\
|
|
431 |
\end{array}
|
1556
|
432 |
\end{equation}
|
|
433 |
|
|
434 |
\noindent
|
1579
|
435 |
Note that this relation is dependent on $p$. Alpha-equivalence is then the relation where
|
|
436 |
we existentially quantify over this $p$.
|
|
437 |
Also note that the relation is dependent on a free-variable function $\fv$ and a relation
|
|
438 |
$R$. The reason for this extra generality is that we will use $\approx_{set}$ for both
|
|
439 |
``raw'' terms and alpha-equated terms. In the latter case, $R$ will be replaced by
|
|
440 |
equality $(op =)$ and we are going to prove that $\fv$ will be equal to the support
|
1617
|
441 |
of $x$ and $y$.
|
1572
|
442 |
|
|
443 |
The definition in \eqref{alphaset} does not make any distinction between the
|
1579
|
444 |
order of abstracted variables. If we want this, then we can define alpha-equivalence
|
|
445 |
for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"}
|
|
446 |
as follows
|
1572
|
447 |
%
|
|
448 |
\begin{equation}\label{alphalist}
|
|
449 |
\begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
|
1579
|
450 |
\multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{list}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
|
1572
|
451 |
& @{text "fv(x) - (set as) = fv(y) - (set bs)"}\\
|
1617
|
452 |
\wedge & @{text "(fv(x) - set as) #* p"}\\
|
1572
|
453 |
\wedge & @{text "(p \<bullet> x) R y"}\\
|
|
454 |
\wedge & @{text "(p \<bullet> as) = bs"}\\
|
|
455 |
\end{array}
|
|
456 |
\end{equation}
|
|
457 |
|
|
458 |
\noindent
|
1617
|
459 |
where $set$ is the function that coerces a list of atoms into a set of atoms.
|
1556
|
460 |
|
1572
|
461 |
If we do not want to make any difference between the order of binders and
|
1579
|
462 |
also allow vacuous binders, then we keep sets of binders, but drop the fourth
|
|
463 |
condition in \eqref{alphaset}:
|
1572
|
464 |
%
|
1579
|
465 |
\begin{equation}\label{alphares}
|
1572
|
466 |
\begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
|
1579
|
467 |
\multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{res}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
|
1572
|
468 |
& @{text "fv(x) - as = fv(y) - bs"}\\
|
1617
|
469 |
\wedge & @{text "(fv(x) - as) #* p"}\\
|
1572
|
470 |
\wedge & @{text "(p \<bullet> x) R y"}\\
|
|
471 |
\end{array}
|
|
472 |
\end{equation}
|
1556
|
473 |
|
1579
|
474 |
\begin{exmple}\rm
|
|
475 |
It might be useful to consider some examples for how these definitions pan out in practise.
|
|
476 |
For this consider the case of abstracting a set of variables over types (as in type-schemes).
|
|
477 |
We set $R$ to be the equality and for $\fv(T)$ we define
|
1572
|
478 |
|
|
479 |
\begin{center}
|
|
480 |
$\fv(x) = \{x\} \qquad \fv(T_1 \rightarrow T_2) = \fv(T_1) \cup \fv(T_2)$
|
|
481 |
\end{center}
|
|
482 |
|
|
483 |
\noindent
|
1579
|
484 |
Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and \eqref{ex3}. It can be easily
|
|
485 |
checked that @{text "({x, y}, x \<rightarrow> y)"} and
|
|
486 |
@{text "({y, x}, y \<rightarrow> x)"} are equal according to $\approx_{set}$ and $\approx_{res}$ by taking $p$ to
|
1617
|
487 |
be the swapping @{term "(x \<rightleftharpoons> y)"}. In case of @{text "x \<noteq> y"}, then
|
1579
|
488 |
$([x, y], x \rightarrow y) \not\approx_{list} ([y,x], x \rightarrow y)$ since there is no permutation that
|
1617
|
489 |
makes the lists @{text "[x, y]"} and @{text "[y, x]"} equal, and also leaves the
|
|
490 |
type \mbox{@{text "x \<rightarrow> y"}} unchanged. Another examples is
|
|
491 |
$(\{x\}, x) \approx_{res} (\{x,y\}, x)$ which holds by taking $p$ to be the identity permutation.
|
|
492 |
However, if @{text "x \<noteq> y"}, then
|
|
493 |
$(\{x\}, x) \not\approx_{set} (\{x,y\}, x)$ since there is no permutation that makes
|
1579
|
494 |
the sets $\{x\}$ and $\{x,y\}$ equal (similarly for $\approx_{list}$).
|
|
495 |
\end{exmple}
|
|
496 |
|
|
497 |
\noindent
|
|
498 |
Let $\star$ range over $\{set, res, list\}$. We prove next under which
|
|
499 |
conditions the $\approx\hspace{0.05mm}_\star^{\fv, R, p}$ are equivalence
|
|
500 |
relations and equivariant:
|
|
501 |
|
|
502 |
\begin{lemma}
|
|
503 |
{\it i)} Given the fact that $x\;R\;x$ holds, then
|
|
504 |
$(as, x) \approx\hspace{0.05mm}^{\fv, R, 0}_\star (as, x)$. {\it ii)} Given
|
|
505 |
that @{text "(p \<bullet> x) R y"} implies @{text "(-p \<bullet> y) R x"}, then
|
|
506 |
$(as, x) \approx\hspace{0.05mm}^{\fv, R, p}_\star (bs, y)$ implies
|
|
507 |
$(bs, y) \approx\hspace{0.05mm}^{\fv, R, - p}_\star (as, x)$. {\it iii)} Given
|
|
508 |
that @{text "(p \<bullet> x) R y"} and @{text "(q \<bullet> y) R z"} implies
|
|
509 |
@{text "((q + p) \<bullet> x) R z"}, then $(as, x) \approx\hspace{0.05mm}^{\fv, R, p}_\star (bs, y)$
|
|
510 |
and $(bs, y) \approx\hspace{0.05mm}^{\fv, R, q}_\star (cs, z)$ implies
|
|
511 |
$(as, x) \approx\hspace{0.05mm}^{\fv, R, q + p}_\star (cs, z)$. Given
|
|
512 |
@{text "(q \<bullet> x) R y"} implies @{text "(p \<bullet> (q \<bullet> x)) R (p \<bullet> y)"} and
|
|
513 |
@{text "p \<bullet> (fv x) = fv (p \<bullet> x)"} then @{text "p \<bullet> (fv y) = fv (p \<bullet> y)"}, then
|
|
514 |
$(as, x) \approx\hspace{0.05mm}^{\fv, R, q}_\star (bs, y)$ implies
|
|
515 |
$(p \;\isasymbullet\; as, p \;\isasymbullet\; x) \approx\hspace{0.05mm}^{\fv, R, q}_\star
|
|
516 |
(p \;\isasymbullet\; bs, p \;\isasymbullet\; y)$.
|
|
517 |
\end{lemma}
|
|
518 |
|
|
519 |
\begin{proof}
|
|
520 |
All properties are by unfolding the definitions and simple calculations.
|
|
521 |
\end{proof}
|
1587
|
522 |
|
|
523 |
|
|
524 |
\begin{lemma}
|
|
525 |
$supp ([as]set. x) = supp x - as$
|
|
526 |
\end{lemma}
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
527 |
*}
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
528 |
|
1491
|
529 |
section {* Alpha-Equivalence and Free Variables *}
|
|
530 |
|
1520
|
531 |
text {*
|
1617
|
532 |
Our specifications for term-calculi are heavily
|
|
533 |
inspired by the syntax of the Ott-tool \cite{ott-jfp}. A specification is
|
|
534 |
a collection of (possibly mutual recursive) type declarations, say
|
1620
|
535 |
$ty^\alpha_1$, $ty^\alpha_2$, \ldots $ty^\alpha_n$, and an
|
1617
|
536 |
associated collection of binding function declarations, say
|
1628
|
537 |
$bn^\alpha_1$, \ldots $bn^\alpha_m$. The syntax in Nominal Isabelle
|
|
538 |
for such specifications is rougly as follows:
|
|
539 |
%
|
1619
|
540 |
\begin{equation}\label{scheme}
|
|
541 |
\mbox{\begin{tabular}{@ {\hspace{-9mm}}p{1.8cm}l}
|
1617
|
542 |
type \mbox{declaration part} &
|
1611
|
543 |
$\begin{cases}
|
|
544 |
\mbox{\begin{tabular}{l}
|
1620
|
545 |
\isacommand{nominal\_datatype} $ty^\alpha_1 = \ldots$\\
|
|
546 |
\isacommand{and} $ty^\alpha_2 = \ldots$\\
|
1587
|
547 |
$\ldots$\\
|
1620
|
548 |
\isacommand{and} $ty^\alpha_n = \ldots$\\
|
1611
|
549 |
\end{tabular}}
|
|
550 |
\end{cases}$\\
|
1617
|
551 |
binding \mbox{function part} &
|
1611
|
552 |
$\begin{cases}
|
|
553 |
\mbox{\begin{tabular}{l}
|
1620
|
554 |
\isacommand{with} $bn^\alpha_1$ \isacommand{and} \ldots \isacommand{and} $bn^\alpha_m$
|
1587
|
555 |
$\ldots$\\
|
1611
|
556 |
\isacommand{where}\\
|
1587
|
557 |
$\ldots$\\
|
1611
|
558 |
\end{tabular}}
|
|
559 |
\end{cases}$\\
|
1619
|
560 |
\end{tabular}}
|
|
561 |
\end{equation}
|
1587
|
562 |
|
|
563 |
\noindent
|
1620
|
564 |
Every type declaration $ty^\alpha_i$ consists of a collection of
|
1611
|
565 |
term-constructors, each of which comes with a list of labelled
|
1620
|
566 |
types that stand for the types of the arguments of the term-constructor.
|
|
567 |
For example for a term-constructor $C^\alpha$ we might have
|
1611
|
568 |
|
|
569 |
\begin{center}
|
1620
|
570 |
$C^\alpha\;label_1\!::\!ty'_1\;\ldots label_l\!::\!ty'_l\;\;\textit{binding\_clauses}$
|
1611
|
571 |
\end{center}
|
1587
|
572 |
|
1611
|
573 |
\noindent
|
1628
|
574 |
whereby some of the $ty'_k$ (or their type components) are contained in the
|
|
575 |
set of $ty^\alpha_i$
|
1620
|
576 |
declared in \eqref{scheme}. In this case we will call
|
|
577 |
the corresponding argument a \emph{recursive argument}. The labels
|
|
578 |
annotated on the types are optional and can be used in the (possibly empty)
|
|
579 |
list of \emph{binding clauses}. These clauses indicate the binders and the
|
|
580 |
scope of the binders in a term-constructor. They come in three \emph{modes}
|
1587
|
581 |
|
1611
|
582 |
\begin{center}
|
1617
|
583 |
\begin{tabular}{l}
|
|
584 |
\isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it label}\\
|
|
585 |
\isacommand{bind\_set}\; {\it binders}\; \isacommand{in}\; {\it label}\\
|
|
586 |
\isacommand{bind\_res}\; {\it binders}\; \isacommand{in}\; {\it label}\\
|
|
587 |
\end{tabular}
|
1611
|
588 |
\end{center}
|
|
589 |
|
|
590 |
\noindent
|
1628
|
591 |
The first mode is for binding lists of atoms (the order matters); the second is for sets
|
|
592 |
of binders (the order does not matter, but cardinality does) and the last is for
|
1620
|
593 |
sets of binders (with vacuous binders preserving alpha-equivalence).
|
|
594 |
|
|
595 |
In addition we distinguish between \emph{shallow} binders and \emph{deep}
|
|
596 |
binders. Shallow binders are of the form \isacommand{bind}\; {\it label}\;
|
1628
|
597 |
\isacommand{in}\; {\it another\_label} (similar for the other two modes). The
|
1620
|
598 |
restriction we impose on shallow binders is that the {\it label} must either
|
|
599 |
refer to a type that is an atom type or to a type that is a finite set or
|
|
600 |
list of an atom type. For example the specifications of lambda-terms, where
|
|
601 |
a single name is bound, and type-schemes, where a finite set of names is
|
|
602 |
bound, use shallow binders (the type \emph{name} is an atom type):
|
1611
|
603 |
|
|
604 |
\begin{center}
|
1612
|
605 |
\begin{tabular}{@ {}cc@ {}}
|
|
606 |
\begin{tabular}{@ {}l@ {\hspace{-1mm}}}
|
|
607 |
\isacommand{nominal\_datatype} {\it lam} =\\
|
|
608 |
\hspace{5mm}\phantom{$\mid$} Var\;{\it name}\\
|
|
609 |
\hspace{5mm}$\mid$ App\;{\it lam}\;{\it lam}\\
|
|
610 |
\hspace{5mm}$\mid$ Lam\;{\it x::name}\;{\it t::lam}\\
|
1617
|
611 |
\hspace{21mm}\isacommand{bind} {\it x} \isacommand{in} {\it t}\\
|
1611
|
612 |
\end{tabular} &
|
1612
|
613 |
\begin{tabular}{@ {}l@ {}}
|
|
614 |
\isacommand{nominal\_datatype} {\it ty} =\\
|
|
615 |
\hspace{5mm}\phantom{$\mid$} TVar\;{\it name}\\
|
|
616 |
\hspace{5mm}$\mid$ TFun\;{\it ty}\;{\it ty}\\
|
1617
|
617 |
\isacommand{and} {\it tsc} = All\;{\it xs::(name fset)}\;{\it T::ty}\\
|
1619
|
618 |
\hspace{24mm}\isacommand{bind\_res} {\it xs} \isacommand{in} {\it T}\\
|
1611
|
619 |
\end{tabular}
|
|
620 |
\end{tabular}
|
|
621 |
\end{center}
|
1587
|
622 |
|
1612
|
623 |
\noindent
|
1628
|
624 |
If we have shallow binders that ``share'' a body, for instance $t$ in
|
|
625 |
the term-constructor Foo$_0$
|
1620
|
626 |
|
|
627 |
\begin{center}
|
|
628 |
\begin{tabular}{ll}
|
|
629 |
\it {\rm Foo}$_0$ x::name y::name t::lam & \it
|
|
630 |
\isacommand{bind}\;x\;\isacommand{in}\;t,\;
|
|
631 |
\isacommand{bind}\;y\;\isacommand{in}\;t
|
|
632 |
\end{tabular}
|
|
633 |
\end{center}
|
|
634 |
|
|
635 |
\noindent
|
1628
|
636 |
then we have to make sure the modes of the binders agree. We cannot
|
1620
|
637 |
have in the first binding clause the mode \isacommand{bind} and in the second
|
|
638 |
\isacommand{bind\_set}.
|
|
639 |
|
|
640 |
A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
|
1628
|
641 |
the atoms in one argument of the term-constructor that can be bound in
|
|
642 |
other arguments and also in the same argument (we will
|
1620
|
643 |
call such binders \emph{recursive}).
|
|
644 |
The binding functions are expected to return either a set of atoms
|
|
645 |
(for \isacommand{bind\_set} and \isacommand{bind\_res}) or a list of atoms
|
|
646 |
(for \isacommand{bind}). They can be defined by primitive recursion over the
|
|
647 |
corresponding type; the equations must be given in the binding function part of
|
1628
|
648 |
the scheme shown in \eqref{scheme}. For example for a calculus containing lets
|
|
649 |
with tuple patterns, you might declare
|
1617
|
650 |
|
1619
|
651 |
\begin{center}
|
|
652 |
\begin{tabular}{l}
|
|
653 |
\isacommand{nominal\_datatype} {\it trm} =\\
|
|
654 |
\hspace{5mm}\phantom{$\mid$} Var\;{\it name}\\
|
|
655 |
\hspace{5mm}$\mid$ App\;{\it trm}\;{\it trm}\\
|
|
656 |
\hspace{5mm}$\mid$ Lam\;{\it x::name}\;{\it t::trm}
|
|
657 |
\;\;\isacommand{bind} {\it x} \isacommand{in} {\it t}\\
|
|
658 |
\hspace{5mm}$\mid$ Let\;{\it p::pat}\;{\it trm}\; {\it t::trm}
|
1628
|
659 |
\;\;\isacommand{bind\_set} {\it bn(p)} \isacommand{in} {\it t}\\
|
1619
|
660 |
\isacommand{and} {\it pat} =\\
|
|
661 |
\hspace{5mm}\phantom{$\mid$} PNo\\
|
|
662 |
\hspace{5mm}$\mid$ PVr\;{\it name}\\
|
|
663 |
\hspace{5mm}$\mid$ PPr\;{\it pat}\;{\it pat}\\
|
|
664 |
\isacommand{with} {\it bn::pat $\Rightarrow$ atom set}\\
|
1628
|
665 |
\isacommand{where} $bn(\textrm{PNil}) = \varnothing$\\
|
|
666 |
\hspace{5mm}$\mid$ $bn(\textrm{PVar}\;x) = \{atom\; x\}$\\
|
|
667 |
\hspace{5mm}$\mid$ $bn(\textrm{PPrd}\;p_1\;p_2) = bn(p_1) \cup bn(p_2)$\\
|
1619
|
668 |
\end{tabular}
|
|
669 |
\end{center}
|
1617
|
670 |
|
1619
|
671 |
\noindent
|
1628
|
672 |
In this specification the function $atom$ coerces a name into the generic
|
1620
|
673 |
atom type of Nominal Isabelle. This allows us to treat binders of different
|
1628
|
674 |
atom type uniformly. As will shortly become clear, we cannot return an atom in a
|
|
675 |
binding function that also is bound in the term-constructor. In the present
|
|
676 |
version of Nominal Isabelle, we adopted the restriction the Ott-tool imposes
|
|
677 |
on the binding functions, namely a binding function can only return the
|
|
678 |
empty set (case PNil), a singleton set containing an atom (case PVar) or
|
|
679 |
unions of atom sets (case PPrd). Moreover, as with shallow binders, deep
|
|
680 |
binders with shared body need to have the same binding mode. Finally, the
|
|
681 |
most drastic restriction we have to impose on deep binders is that we cannot
|
|
682 |
have ``overlapping'' deep binders. Consider for example the term-constructors:
|
1617
|
683 |
|
1620
|
684 |
\begin{center}
|
|
685 |
\begin{tabular}{ll}
|
|
686 |
\it {\rm Foo}$_1$ p::pat q::pat t::trm & \it \isacommand{bind}\;bn(p)\;\isacommand{in}\;t,\;
|
|
687 |
\isacommand{bind}\;bn(q)\;\isacommand{in}\;t\\
|
|
688 |
\it {\rm Foo}$_2$ x::name p::pat t::trm & \it \it \isacommand{bind}\;x\;\isacommand{in}\;t,\;
|
|
689 |
\isacommand{bind}\;bn(p)\;\isacommand{in}\;t
|
|
690 |
|
|
691 |
\end{tabular}
|
|
692 |
\end{center}
|
|
693 |
|
|
694 |
\noindent
|
|
695 |
In the first case we bind all atoms from the pattern $p$ in $t$ and also all atoms
|
1628
|
696 |
from $q$ in $t$. As a result we have no way to determine whether the binder came from the
|
|
697 |
binding function in $p$ or $q$. Similarly in the second case:
|
|
698 |
the binder $bn(p)$ overlaps with the shallow binder $x$. We must exclude such specifiactions,
|
1620
|
699 |
as we will not be able to represent them using the general binders described in
|
|
700 |
Section \ref{sec:binders}. However the following two term-constructors are allowed:
|
|
701 |
|
|
702 |
\begin{center}
|
|
703 |
\begin{tabular}{ll}
|
|
704 |
\it {\rm Bar}$_1$ p::pat t::trm s::trm & \it \isacommand{bind}\;bn(p)\;\isacommand{in}\;t,\;
|
|
705 |
\isacommand{bind}\;bn(p)\;\isacommand{in}\;s\\
|
|
706 |
\it {\rm Bar}$_2$ p::pat t::trm & \it \isacommand{bind}\;bn(p)\;\isacommand{in}\;p,\;
|
|
707 |
\isacommand{bind}\;bn(p)\;\isacommand{in}\;t\\
|
|
708 |
\end{tabular}
|
|
709 |
\end{center}
|
|
710 |
|
|
711 |
\noindent
|
1628
|
712 |
since there is no overlap of binders.
|
1619
|
713 |
|
1628
|
714 |
Now the question is how we can turn specifications into actual type
|
|
715 |
definitions in Isabelle/HOL and then establish a reasoning infrastructure
|
|
716 |
for them? Because of the problem Pottier and Cheney pointed out, we cannot
|
|
717 |
in general re-arrange arguments of term-constructors so that binders and
|
|
718 |
their scopes next to each other, an then use the type constructors
|
|
719 |
@{text "abs_set"}, @{text "abs_res"} and @{text "abs_list"}. Therefore
|
|
720 |
we will first extract datatype definitions from the specification and
|
|
721 |
then define an alpha-equiavlence relation over them.
|
|
722 |
|
|
723 |
The datatype definition can be obtained by just stripping of the
|
|
724 |
binding clauses and the labels on the types. We also have to invent
|
|
725 |
new names for the types, $ty^\alpha$ and term-constructors $C^\alpha$
|
|
726 |
given by user. We just use an affix:
|
1587
|
727 |
|
1628
|
728 |
\begin{center}
|
|
729 |
$ty^\alpha \mapsto ty\_raw \qquad C^\alpha \mapsto C\_raw$
|
|
730 |
\end{center}
|
|
731 |
|
|
732 |
\noindent
|
|
733 |
This definition can be made, provided the usual conditions hold: the
|
|
734 |
types must be non-empty and the types in the term-constructors need to
|
|
735 |
be, what is called, positive position (see \cite{}). We then take the binding
|
|
736 |
functions and define them by primitive recursion over the raw datatypes.
|
|
737 |
binding function.
|
|
738 |
|
|
739 |
The first non-trivial step is to read off from the specification free-variable
|
|
740 |
functions. There are two kinds: free-variable functions corresponding to types,
|
|
741 |
written $\fv\_ty$, and free-variable functions corresponding to binding functions,
|
|
742 |
written $\fv\_bn$. They have to be defined at the same time since there can
|
|
743 |
be interdependencies. Given a term-constructor $C ty_1 \ldots ty_n$ and some binding
|
|
744 |
clauses, the function $\fv (C x_1 \ldots x_n)$ will be the union of the values
|
|
745 |
generated for each argument, say $x_i$, as follows:
|
|
746 |
|
|
747 |
\begin{center}
|
|
748 |
\begin{tabular}{cp{8cm}}
|
|
749 |
$\bullet$ & if it is a shallow binder, then $\varnothing$\\
|
|
750 |
$\bullet$ & if it is a deep binder, then $\fv_bn x_i$\\
|
|
751 |
$\bullet$ & if
|
|
752 |
\end{tabular}
|
|
753 |
\end{center}
|
|
754 |
|
|
755 |
|
|
756 |
|
1587
|
757 |
*}
|
|
758 |
|
|
759 |
|
|
760 |
|
|
761 |
text {*
|
1520
|
762 |
Restrictions
|
|
763 |
|
|
764 |
\begin{itemize}
|
1572
|
765 |
\item non-emptiness
|
1520
|
766 |
\item positive datatype definitions
|
|
767 |
\item finitely supported abstractions
|
|
768 |
\item respectfulness of the bn-functions\bigskip
|
|
769 |
\item binders can only have a ``single scope''
|
1577
|
770 |
\item all bindings must have the same mode
|
1520
|
771 |
\end{itemize}
|
|
772 |
*}
|
|
773 |
|
1493
|
774 |
section {* Examples *}
|
1485
|
775 |
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
776 |
section {* Adequacy *}
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
777 |
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
778 |
section {* Related Work *}
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
779 |
|
1570
|
780 |
text {*
|
|
781 |
Ott is better with list dot specifications; subgrammars
|
|
782 |
|
|
783 |
untyped;
|
|
784 |
|
|
785 |
*}
|
|
786 |
|
|
787 |
|
1493
|
788 |
section {* Conclusion *}
|
1485
|
789 |
|
|
790 |
text {*
|
1520
|
791 |
Complication when the single scopedness restriction is lifted (two
|
|
792 |
overlapping permutations)
|
|
793 |
*}
|
|
794 |
|
|
795 |
text {*
|
1493
|
796 |
|
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
797 |
TODO: function definitions:
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
798 |
\medskip
|
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
799 |
|
1493
|
800 |
\noindent
|
1528
|
801 |
{\bf Acknowledgements:} We are very grateful to Andrew Pitts for
|
1506
|
802 |
many discussions about Nominal Isabelle. We thank Peter Sewell for
|
|
803 |
making the informal notes \cite{SewellBestiary} available to us and
|
1556
|
804 |
also for patiently explaining some of the finer points about the abstract
|
1545
|
805 |
definitions and about the implementation of the Ott-tool.
|
1485
|
806 |
|
1577
|
807 |
Lookup: Merlin paper by James Cheney; Mark Shinwell PhD
|
754
|
808 |
|
1577
|
809 |
Future work: distinct list abstraction
|
|
810 |
|
|
811 |
|
754
|
812 |
*}
|
|
813 |
|
1484
|
814 |
|
|
815 |
|
754
|
816 |
(*<*)
|
|
817 |
end
|
|
818 |
(*>*) |