34 binding \cite{SatoPollack10}. |
34 binding \cite{SatoPollack10}. |
35 |
35 |
36 However, Nominal Isabelle has fared less well in a formalisation of |
36 However, Nominal Isabelle has fared less well in a formalisation of |
37 the algorithm W \cite{UrbanNipkow09}, where types and type-schemes |
37 the algorithm W \cite{UrbanNipkow09}, where types and type-schemes |
38 are of the form |
38 are of the form |
39 |
39 % |
40 \begin{center} |
40 \begin{equation}\label{tysch} |
41 \begin{tabular}{l} |
41 \begin{array}{l} |
42 $T ::= x \mid T \rightarrow T$ \hspace{5mm} $S ::= \forall \{x_1,\ldots, x_n\}. T$ |
42 T ::= x \mid T \rightarrow T \hspace{5mm} S ::= \forall \{x_1,\ldots, x_n\}. T |
43 \end{tabular} |
43 \end{array} |
44 \end{center} |
44 \end{equation} |
45 |
45 |
46 \noindent |
46 \noindent |
47 and the quantification $\forall$ binds a finite (possibly empty) set of |
47 and the quantification $\forall$ binds a finite (possibly empty) set of |
48 type-variables. While it is possible to implement this kind of more general |
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 |
49 binders by iterating single binders, this leads to a rather clumsy |
155 for example~\cite{BengtsonParow09}). To avoid this, we will allow specifications |
155 for example~\cite{BengtsonParow09}). To avoid this, we will allow specifications |
156 for $\mathtt{let}$s as follows |
156 for $\mathtt{let}$s as follows |
157 |
157 |
158 \begin{center} |
158 \begin{center} |
159 \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l} |
159 \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l} |
160 $trm$ & $=$ & \ldots\\ |
160 $trm$ & $::=$ & \ldots\\ |
161 & $\mid$ & $\mathtt{let}\;a\!::\!assn\;\;s\!::\!trm\quad\mathtt{bind}\;bn\,(a) \IN s$\\[1mm] |
161 & $\mid$ & $\mathtt{let}\;a\!::\!assn\;\;s\!::\!trm\quad\mathtt{bind}\;bn\,(a) \IN s$\\[1mm] |
162 $assn$ & $=$ & $\mathtt{anil}$\\ |
162 $assn$ & $::=$ & $\mathtt{anil}$\\ |
163 & $\mid$ & $\mathtt{acons}\;\;name\;\;trm\;\;assn$ |
163 & $\mid$ & $\mathtt{acons}\;\;name\;\;trm\;\;assn$ |
164 \end{tabular} |
164 \end{tabular} |
165 \end{center} |
165 \end{center} |
166 |
166 |
167 \noindent |
167 \noindent |
179 $\mathtt{bind}\;bn\,(a) \IN s$, that states to bind all the names the function |
179 $\mathtt{bind}\;bn\,(a) \IN s$, that states to bind all the names the function |
180 $bn$ returns in $s$. This style of specifying terms and bindings is heavily |
180 $bn$ returns in $s$. This style of specifying terms and bindings is heavily |
181 inspired by the syntax of the Ott-tool \cite{ott-jfp}. |
181 inspired by the syntax of the Ott-tool \cite{ott-jfp}. |
182 |
182 |
183 However, we will not be able to deal with all specifications that are |
183 However, we will not be able to deal with all specifications that are |
184 allowed by Ott. One reason is that we establish the reasoning infrastructure |
184 allowed by Ott. One reason is that Ott allows ``empty'' specifications |
185 for alpha-\emph{equated} terms. In contrast, Ott produces for a subset of |
185 like |
186 its specifications a reasoning infrastructure in Isabelle/HOL for |
186 |
|
187 \begin{center} |
|
188 $t ::= t\;t \mid \lambda x. t$ |
|
189 \end{center} |
|
190 |
|
191 \noindent |
|
192 where no clause for variables is given. Such specifications make sense in |
|
193 the context of Coq's type theory (which Ott supports), but not in a HOL-based |
|
194 theorem prover where every datatype must have a non-empty set-theoretic model. |
|
195 |
|
196 Another reason is that we establish the reasoning infrastructure |
|
197 for alpha-\emph{equated} terms. In contrast, Ott produces a reasoning |
|
198 infrastructure in Isabelle/HOL for |
187 \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms |
199 \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms |
188 and the raw terms produced by Ott use names for bound variables, |
200 and the raw terms produced by Ott use names for bound variables, |
189 there is a key difference: working with alpha-equated terms means that the |
201 there is a key difference: working with alpha-equated terms means that the |
190 two type-schemes with $x$, $y$ and $z$ being distinct |
202 two type-schemes with $x$, $y$ and $z$ being distinct |
191 |
203 |
245 datatype in Isabelle/HOL); identify then the |
257 datatype in Isabelle/HOL); identify then the |
246 alpha-equivalence classes in the type of sets of raw terms, according to our |
258 alpha-equivalence classes in the type of sets of raw terms, according to our |
247 alpha-equivalence relation and finally define the new type as these |
259 alpha-equivalence relation and finally define the new type as these |
248 alpha-equivalence classes (non-emptiness is satisfied whenever the raw terms are |
260 alpha-equivalence classes (non-emptiness is satisfied whenever the raw terms are |
249 definable as datatype in Isabelle/HOL and the fact that our relation for alpha is an |
261 definable as datatype in Isabelle/HOL and the fact that our relation for alpha is an |
250 equivalence relation).\marginpar{\footnotesize Does Ott allow definitions of ``strange'' types?} |
262 equivalence relation). |
251 |
263 |
252 The fact that we obtain an isomorphism between between the new type and the non-empty |
264 The fact that we obtain an isomorphism between between the new type and the non-empty |
253 subset shows that the new type is a faithful representation of alpha-equated terms. |
265 subset shows that the new type is a faithful representation of alpha-equated terms. |
254 That is different for example in the representation of terms using the locally |
266 That is different for example in the representation of terms using the locally |
255 nameless representation of binders: there are non-well-formed terms that need to |
267 nameless representation of binders: there are non-well-formed terms that need to |
256 be excluded by reasoning about a well-formedness predicate. |
268 be excluded by reasoning about a well-formedness predicate. |
257 |
269 |
258 The problem with introducing a new type is that in order to be useful |
270 The problem with introducing a new type in Isabelle/HOL is that in order to be useful |
259 a resoning infrastructure needs to be ``lifted'' from the underlying type |
271 a resoning infrastructure needs to be ``lifted'' from the underlying subset to |
260 and subset to the new type. This is usually a tricky task. To ease this task |
272 the new type. This is usually a tricky and arduous task. To ease it |
261 we reimplemented in Isabelle/HOL the quotient package described by Homeier |
273 we reimplemented in Isabelle/HOL the quotient package described by Homeier |
262 \cite{Homeier05}. Gieven that alpha is an equivalence relation, this package |
274 \cite{Homeier05}. Given that alpha is an equivalence relation, this package |
263 allows us to automatically lift definitions and theorems involving raw terms |
275 allows us to automatically lift definitions and theorems involving raw terms |
264 to definitions and theorems involving alpha-equated terms. This of course |
276 to definitions and theorems involving alpha-equated terms. This of course |
265 only works if the definitions and theorems are respectful w.r.t.~alpha-equivalence. |
277 only works if the definitions and theorems are respectful w.r.t.~alpha-equivalence. |
266 Hence we will be able to lift, for instance, the function for free |
278 Hence we will be able to lift, for instance, the function for free |
267 variables of raw terms to alpha-equated terms (since this function respects |
279 variables of raw terms to alpha-equated terms (since this function respects |
285 text {* |
297 text {* |
286 At its core, Nominal Isabelle is an adaption of the nominal logic work by |
298 At its core, Nominal Isabelle is an adaption of the nominal logic work by |
287 Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in |
299 Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in |
288 \cite{HuffmanUrban10}, which we review here briefly to aid the description |
300 \cite{HuffmanUrban10}, which we review here briefly to aid the description |
289 of what follows. Two central notions in the nominal logic work are sorted |
301 of what follows. Two central notions in the nominal logic work are sorted |
290 atoms and permutations of atoms. The sorted atoms represent different kinds |
302 atoms and sort-respecting permutations of atoms. The sorts can be used to |
291 of variables, such as term- and type-variables in Core-Haskell, and it is |
303 represent different kinds of variables, such as term- and type-variables in |
292 assumed that there is an infinite supply of atoms for each sort. However, in |
304 Core-Haskell, and it is assumed that there is an infinite supply of atoms |
293 order to simplify the description, we shall assume in what follows that |
305 for each sort. However, in order to simplify the description, we shall |
294 there is only a single sort of atoms. |
306 assume in what follows that there is only a single sort of atoms. |
295 |
307 |
296 |
308 |
297 Permutations are bijective functions from atoms to atoms that are |
309 Permutations are bijective functions from atoms to atoms that are |
298 the identity everywhere except on a finite number of atoms. There is a |
310 the identity everywhere except on a finite number of atoms. There is a |
299 two-place permutation operation written |
311 two-place permutation operation written |
300 |
312 |
301 @{text[display,indent=5] "_ \<bullet> _ :: (\<alpha> \<times> \<alpha>) list \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} |
313 @{text[display,indent=5] "_ \<bullet> _ :: (\<alpha> \<times> \<alpha>) list \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} |
302 |
314 |
303 \noindent |
315 \noindent |
304 with a generic type in which @{text "\<alpha>"} stands for the type of atoms |
316 with a generic type in which @{text "\<alpha>"} stands for the type of atoms |
305 and @{text "\<beta>"} for the type of the objects on which the permutation |
317 and @{text "\<beta>"} for the type of the object on which the permutation |
306 acts. In Nominal Isabelle the identity permutation is written as @{term "0::perm"}, |
318 acts. In Nominal Isabelle the identity permutation is written as @{term "0::perm"}, |
307 the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}} |
319 the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}} |
308 and the inverse permutation @{term p} as @{text "- p"}. The permutation |
320 and the inverse permutation of @{term p} as @{text "- p"}. The permutation |
309 operation is defined for products, lists, sets, functions, booleans etc |
321 operation is defined for products, lists, sets, functions, booleans etc |
310 (see \cite{HuffmanUrban10}). |
322 (see \cite{HuffmanUrban10}). |
311 |
323 |
312 The most original aspect of the nominal logic work of Pitts et al is a general |
324 The most original aspect of the nominal logic work of Pitts is a general |
313 definition for ``the set of free variables of an object @{text "x"}''. This |
325 definition for the notion of ``the set of free variables of an object @{text |
314 definition is general in the sense that it applies not only to lambda-terms, |
326 "x"}''. This notion, written @{term "supp x"}, is general in the sense that |
315 but also to lists, products, sets and even functions. The definition depends |
327 it applies not only to lambda-terms alpha-equated or not, but also to lists, |
316 only on the permutation operation and on the notion of equality defined for |
328 products, sets and even functions. The definition depends only on the |
317 the type of @{text x}, namely: |
329 permutation operation and on the notion of equality defined for the type of |
|
330 @{text x}, namely: |
318 |
331 |
319 @{thm[display,indent=5] supp_def[no_vars, THEN eq_reflection]} |
332 @{thm[display,indent=5] supp_def[no_vars, THEN eq_reflection]} |
320 |
333 |
321 \noindent |
334 \noindent |
322 There is also the derived notion for when an atom @{text a} is \emph{fresh} |
335 There is also the derived notion for when an atom @{text a} is \emph{fresh} |
348 |
361 |
349 |
362 |
350 section {* General Binders *} |
363 section {* General Binders *} |
351 |
364 |
352 text {* |
365 text {* |
353 In order to keep our work managable we like to state general definitions |
366 In order to keep our work managable we give need to give definitions |
354 and perform proofs inside Isabelle as much as possible, as opposed to write |
367 and perform proofs inside Isabelle whereever possible, as opposed to write |
355 custom ML-code that generates appropriate definitions and proofs for each |
368 custom ML-code that generates them for each |
356 instance of a term-calculus. For this, we like to consider pairs |
369 instance of a term-calculus. To this end we will first consider pairs |
357 |
370 |
358 \begin{equation}\label{three} |
371 \begin{equation}\label{three} |
359 \mbox{@{text "(as, x) :: atom set \<times> \<beta>"}} |
372 \mbox{@{text "(as, x) :: (atom set) \<times> \<beta>"}} |
360 \end{equation} |
373 \end{equation} |
361 |
374 |
362 \noindent |
375 \noindent |
363 consisting of a set of atoms and an object of generic type. The pairs |
376 consisting of a set of atoms and an object of generic type. These pairs |
364 are intended to be used for representing binding such as found in |
377 are intended to represent the abstraction or binding of the set $as$ |
365 type-schemes |
378 in the body $x$ (similarly to type-schemes given in \eqref{tysch}). |
366 |
379 |
367 \begin{center} |
380 The first question we have to answer is when we should consider pairs such as |
368 $\forall \{x_1,\ldots,x_n\}. T$ |
381 $(as, x)$ and $(bs, y)$ as alpha-equivelent? (At the moment we are interested in |
369 \end{center} |
|
370 |
|
371 \noindent |
|
372 where the atoms $x_1,\ldots,x_n$ is intended to be in \eqref{three} the |
|
373 set @{text as} of atoms we want to bind, and $T$, an object-level type, is |
|
374 one instance for the generic $x$. |
|
375 |
|
376 The first question we have to answer is when we should consider the pairs |
|
377 in \eqref{three} as alpha-equivelent? (At the moment we are interested in |
|
378 the notion of alpha-equivalence that is \emph{not} preserved by adding |
382 the notion of alpha-equivalence that is \emph{not} preserved by adding |
379 vacuous binders.) Assuming we are given a free-variable function, say |
383 vacuous binders.) For this we identify four conditions: i) given a free-variable function |
|
384 of type \mbox{@{text "fv :: \<beta> \<Rightarrow> atom set"}}, then $x$ and $y$ |
|
385 need to have the same set of free variables; ii) there must be a permutation, |
|
386 say $p$, that leaves the free variables $x$ and $y$ unchanged, but ``moves'' their bound names |
|
387 so that we obtain modulo a relation, say @{text "_ R _"}, |
|
388 two equal terms. We also require that $p$ makes the abstracted sets equal. These |
|
389 requirements can be stated formally as |
|
390 |
|
391 \begin{center} |
|
392 \begin{tabular}{rcl} |
|
393 a |
|
394 \end{tabular} |
|
395 \end{center} |
|
396 |
|
397 |
|
398 Assuming we are given a free-variable function, say |
380 \mbox{@{text "fv :: \<beta> \<Rightarrow> atom set"}}, then we expect for two alpha-equivelent |
399 \mbox{@{text "fv :: \<beta> \<Rightarrow> atom set"}}, then we expect for two alpha-equivelent |
381 pairs that their sets of free variables aggree. That is |
400 pairs that their sets of free variables aggree. That is |
382 % |
401 % |
383 \begin{equation}\label{four} |
402 \begin{equation}\label{four} |
384 \mbox{@{text "(as, x) \<approx> (bs, y)"} \hspace{2mm}implies\hspace{2mm} @{text "fv(x) - as = fv(y) - bs"}} |
403 \mbox{@{text "(as, x) \<approx> (bs, y)"} \hspace{2mm}implies\hspace{2mm} @{text "fv(x) - as = fv(y) - bs"}} |