Paper/Paper.thy
changeset 1617 99cee15cb5ff
parent 1613 98b53cd05deb
child 1619 373cd788d327
equal deleted inserted replaced
1614:b7e19f16bcd0 1617:99cee15cb5ff
   128   As a result, we provide three general binding mechanisms each of which binds multiple
   128   As a result, we provide three general binding mechanisms each of which binds multiple
   129   variables at once, and let the user chose which one is intended when formalising a
   129   variables at once, and let the user chose which one is intended when formalising a
   130   programming language calculus.
   130   programming language calculus.
   131 
   131 
   132   By providing these general binding mechanisms, however, we have to work around 
   132   By providing these general binding mechanisms, however, we have to work around 
   133   a problem that has been pointed out by Pottier in \cite{Pottier06}: in 
   133   a problem that has been pointed out by Pottier in \cite{Pottier06} and Cheney in
       
   134   \cite{Cheney05}: in 
   134   $\mathtt{let}$-constructs of the form
   135   $\mathtt{let}$-constructs of the form
   135   %
   136   %
   136   \begin{center}
   137   \begin{center}
   137   $\LET x_1 = t_1 \AND \ldots \AND x_n = t_n \IN s \END$
   138   $\LET x_1 = t_1 \AND \ldots \AND x_n = t_n \IN s \END$
   138   \end{center}
   139   \end{center}
   148   \end{center}
   149   \end{center}
   149 
   150 
   150   \noindent
   151   \noindent
   151   where the notation $[\_\!\_].\_\!\_$ indicates that the $x_i$ become bound
   152   where the notation $[\_\!\_].\_\!\_$ indicates that the $x_i$ become bound
   152   in $s$. In this representation the term \mbox{$\LET [x].s\;\;[t_1,t_2]$}
   153   in $s$. In this representation the term \mbox{$\LET [x].s\;\;[t_1,t_2]$}
   153   would be a perfectly legal instance. To exclude such terms an additional
   154   would be a perfectly legal instance. To exclude such terms, an additional
   154   predicate about well-formed terms is needed in order to ensure that the two
   155   predicate about well-formed terms is needed in order to ensure that the two
   155   lists are of equal length. This can result into very messy reasoning (see
   156   lists are of equal length. This can result into very messy reasoning (see
   156   for example~\cite{BengtsonParow09}). To avoid this, we will allow type specifications
   157   for example~\cite{BengtsonParow09}). To avoid this, we will allow type specifications
   157   for $\mathtt{let}$s as follows
   158   for $\mathtt{let}$s as follows
   158   %
   159   %
   180   $\mathtt{bind}\;bn\,(a) \IN s$, that states to bind in $s$ all the names the
   181   $\mathtt{bind}\;bn\,(a) \IN s$, that states to bind in $s$ all the names the
   181   function call $bn\,(a)$ returns.  This style of specifying terms and bindings is
   182   function call $bn\,(a)$ returns.  This style of specifying terms and bindings is
   182   heavily inspired by the syntax of the Ott-tool \cite{ott-jfp}.
   183   heavily inspired by the syntax of the Ott-tool \cite{ott-jfp}.
   183 
   184 
   184   However, we will not be able to deal with all specifications that are
   185   However, we will not be able to deal with all specifications that are
   185   allowed by Ott. One reason is that Ott allows ``empty'' specifications
   186   allowed by Ott. One reason is that Ott lets the user to specify ``empty'' 
   186   like
   187   types like
   187 
   188 
   188   \begin{center}
   189   \begin{center}
   189   $t ::= t\;t \mid \lambda x. t$
   190   $t ::= t\;t \mid \lambda x. t$
   190   \end{center}
   191   \end{center}
   191 
   192 
   192   \noindent
   193   \noindent
   193   where no clause for variables is given. Such specifications make some sense in
   194   where no clause for variables is given. Arguably, such specifications make
   194   the context of Coq's type theory (which Ott supports), but not at all in a HOL-based 
   195   some sense in the context of Coq's type theory (which Ott supports), but not
   195   environment where every datatype must have a non-empty set-theoretic model.
   196   at all in a HOL-based environment where every datatype must have a non-empty
       
   197   set-theoretic model.
   196 
   198 
   197   Another reason is that we establish the reasoning infrastructure
   199   Another reason is that we establish the reasoning infrastructure
   198   for alpha-\emph{equated} terms. In contrast, Ott produces  a reasoning 
   200   for alpha-\emph{equated} terms. In contrast, Ott produces  a reasoning 
   199   infrastructure in Isabelle/HOL for
   201   infrastructure in Isabelle/HOL for
   200   \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms
   202   \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms
   201   and the raw terms produced by Ott use names for bound variables,
   203   and the raw terms produced by Ott use names for bound variables,
   202   there is a key difference: working with alpha-equated terms means that the
   204   there is a key difference: working with alpha-equated terms means that the
   203   two type-schemes with $x$, $y$ and $z$ being distinct
   205   two type-schemes (with $x$, $y$ and $z$ being distinct)
   204 
   206 
   205   \begin{center}
   207   \begin{center}
   206   $\forall \{x\}. x \rightarrow y  \;=\; \forall \{x, z\}. x \rightarrow y$ 
   208   $\forall \{x\}. x \rightarrow y  \;=\; \forall \{x, z\}. x \rightarrow y$ 
   207   \end{center}
   209   \end{center}
   208   
   210   
   209   \noindent
   211   \noindent
   210   are not just alpha-equal, but actually equal. As a
   212   are not just alpha-equal, but actually \emph{equal}. As a
   211   result, we can only support specifications that make sense on the level of
   213   result, we can only support specifications that make sense on the level of
   212   alpha-equated terms (offending specifications, which for example bind a variable
   214   alpha-equated terms (offending specifications, which for example bind a variable
   213   according to a variable bound somewhere else, are not excluded by Ott, but we 
   215   according to a variable bound somewhere else, are not excluded by Ott, but we 
   214   have to).  Our
   216   have to).  Our
   215   insistence on reasoning with alpha-equated terms comes from the wealth of
   217   insistence on reasoning with alpha-equated terms comes from the wealth of
   262   definable as datatype in Isabelle/HOL and the fact that our relation for 
   264   definable as datatype in Isabelle/HOL and the fact that our relation for 
   263   alpha-equivalence is indeed an equivalence relation).
   265   alpha-equivalence is indeed an equivalence relation).
   264 
   266 
   265   The fact that we obtain an isomorphism between the new type and the non-empty 
   267   The fact that we obtain an isomorphism between the new type and the non-empty 
   266   subset shows that the new type is a faithful representation of alpha-equated terms. 
   268   subset shows that the new type is a faithful representation of alpha-equated terms. 
   267   That is not the case for example in the representation of terms using the locally 
   269   That is not the case for example for terms using the locally 
   268   nameless representation of binders \cite{McKinnaPollack99}: in this representation 
   270   nameless representation of binders \cite{McKinnaPollack99}: in this representation 
   269   there are ``junk'' terms that need to
   271   there are ``junk'' terms that need to
   270   be excluded by reasoning about a well-formedness predicate.
   272   be excluded by reasoning about a well-formedness predicate.
   271 
   273 
   272   The problem with introducing a new type in Isabelle/HOL is that in order to be useful, 
   274   The problem with introducing a new type in Isabelle/HOL is that in order to be useful, 
   273   a reasoning infrastructure needs to be ``lifted'' from the underlying subset to 
   275   a reasoning infrastructure needs to be ``lifted'' from the underlying subset to 
   274   the new type. This is usually a tricky and arduous task. To ease it,
   276   the new type. This is usually a tricky and arduous task. To ease it,
   275   we re-implemented in Isabelle/HOL the quotient package described by Homeier 
   277   we re-implemented in Isabelle/HOL the quotient package described by Homeier 
   276   \cite{Homeier05}. This package 
   278   \cite{Homeier05} for the HOL4 system. This package 
   277   allows us to  lift definitions and theorems involving raw terms
   279   allows us to  lift definitions and theorems involving raw terms
   278   to definitions and theorems involving alpha-equated, terms. For example
   280   to definitions and theorems involving alpha-equated terms. For example
   279   if we define the free-variable function over lambda terms
   281   if we define the free-variable function over raw lambda-terms
   280 
   282 
   281   \begin{center}
   283   \begin{center}
   282   $\fv(x) = \{x\}$\hspace{10mm}
   284   $\fv(x) = \{x\}$\hspace{10mm}
   283   $\fv(t_1\;t_2) = \fv(t_1) \cup \fv(t_2)$\\[1mm]
   285   $\fv(t_1\;t_2) = \fv(t_1) \cup \fv(t_2)$\\[1mm]
   284   $\fv(\lambda x.t) = \fv(t) - \{x\}$
   286   $\fv(\lambda x.t) = \fv(t) - \{x\}$
   285   \end{center}
   287   \end{center}
   286   
   288   
   287   \noindent
   289   \noindent
   288   then with not too great effort we obtain a function $\fv_\alpha$
   290   then with not too great effort we obtain a function $\fv_\alpha$
   289   operating on quotients, or alpha-equivalence classes of terms, as follows
   291   operating on quotients, or alpha-equivalence classes of lambda-terms. This
       
   292   function is characterised by the equations
   290 
   293 
   291   \begin{center}
   294   \begin{center}
   292   $\fv_\alpha(x) = \{x\}$\hspace{10mm}
   295   $\fv_\alpha(x) = \{x\}$\hspace{10mm}
   293   $\fv_\alpha(t_1\;t_2) = \fv_\alpha(t_1) \cup \fv_\alpha(t_2)$\\[1mm]
   296   $\fv_\alpha(t_1\;t_2) = \fv_\alpha(t_1) \cup \fv_\alpha(t_2)$\\[1mm]
   294   $\fv_\alpha(\lambda x.t) = \fv_\alpha(t) - \{x\}$
   297   $\fv_\alpha(\lambda x.t) = \fv_\alpha(t) - \{x\}$
   295   \end{center}
   298   \end{center}
   296 
   299 
   297   \noindent
   300   \noindent
   298   (Note that this means also the term-constructors for variables, applications
   301   (Note that this means also the term-constructors for variables, applications
   299   and lambda are lifted to the quotient level.)  This construction, of course,
   302   and lambda are lifted to the quotient level.)  This construction, of course,
   300   only works if alpha-equivalence is an equivalence relation, and the
   303   only works if alpha-equivalence is an equivalence relation, and the lifted
   301   definitions and theorems are respectful w.r.t.~alpha-equivalence.  Hence we
   304   definitions and theorems are respectful w.r.t.~alpha-equivalence.  Accordingly, we
   302   will not be able to lift a bound-variable function to alpha-equated terms
   305   will not be able to lift a bound-variable function to alpha-equated terms
   303   (since it does not respect alpha-equivalence). To sum up, every lifting of
   306   (since it does not respect alpha-equivalence). To sum up, every lifting of
   304   theorems to the quotient level needs proofs of some respectfulness
   307   theorems to the quotient level needs proofs of some respectfulness
   305   properties. In the paper we show that we are able to automate these
   308   properties. In the paper we show that we are able to automate these
   306   proofs and therefore can establish a reasoning infrastructure for
   309   proofs and therefore can establish a reasoning infrastructure for
   327   of what follows. Two central notions in the nominal logic work are sorted
   330   of what follows. Two central notions in the nominal logic work are sorted
   328   atoms and sort-respecting permutations of atoms. The sorts can be used to
   331   atoms and sort-respecting permutations of atoms. The sorts can be used to
   329   represent different kinds of variables, such as term- and type-variables in
   332   represent different kinds of variables, such as term- and type-variables in
   330   Core-Haskell, and it is assumed that there is an infinite supply of atoms
   333   Core-Haskell, and it is assumed that there is an infinite supply of atoms
   331   for each sort. However, in order to simplify the description, we shall
   334   for each sort. However, in order to simplify the description, we shall
   332   assume in what follows that there is only a single sort of atoms.
   335   assume in what follows that there is only one sort of atoms.
   333 
       
   334 
   336 
   335   Permutations are bijective functions from atoms to atoms that are 
   337   Permutations are bijective functions from atoms to atoms that are 
   336   the identity everywhere except on a finite number of atoms. There is a 
   338   the identity everywhere except on a finite number of atoms. There is a 
   337   two-place permutation operation written
   339   two-place permutation operation written
   338 
   340   %
   339   @{text[display,indent=5] "_ \<bullet> _  ::  (\<alpha> \<times> \<alpha>) list \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
   341   @{text[display,indent=5] "_ \<bullet> _  ::  perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
   340 
   342 
   341   \noindent 
   343   \noindent 
   342   with a generic type in which @{text "\<alpha>"} stands for the type of atoms 
   344   with a generic type in which @{text "\<beta>"} stands for the type of the object 
   343   and @{text "\<beta>"} for the type of the object on which the permutation 
   345   on which the permutation 
   344   acts. In Nominal Isabelle the identity permutation is written as @{term "0::perm"},
   346   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   345   the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}} 
   347   the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}} 
   346   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   348   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   347   operation is defined for products, lists, sets, functions, booleans etc 
   349   operation is defined for products, lists, sets, functions, booleans etc 
   348   (see \cite{HuffmanUrban10}).
   350   (see \cite{HuffmanUrban10}). In the nominal logic work, concrete 
       
   351   permutations are usually build up from swappings, written as @{text "(a b)"},
       
   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   
   349 
   356 
   350   The most original aspect of the nominal logic work of Pitts is a general
   357   The most original aspect of the nominal logic work of Pitts is a general
   351   definition for the notion of ``the set of free variables of an object @{text
   358   definition for the notion of ``the set of free variables of an object @{text
   352   "x"}''.  This notion, written @{term "supp x"}, is general in the sense that
   359   "x"}''.  This notion, written @{term "supp x"}, is general in the sense that
   353   it applies not only to lambda-terms alpha-equated or not, but also to lists,
   360   it applies not only to lambda-terms alpha-equated or not, but also to lists,
   354   products, sets and even functions. The definition depends only on the
   361   products, sets and even functions. The definition depends only on the
   355   permutation operation and on the notion of equality defined for the type of
   362   permutation operation and on the notion of equality defined for the type of
   356   @{text x}, namely:
   363   @{text x}, namely:
   357 
   364   %
   358   @{thm[display,indent=5] supp_def[no_vars, THEN eq_reflection]}
   365   @{thm[display,indent=5] supp_def[no_vars, THEN eq_reflection]}
   359 
   366 
   360   \noindent
   367   \noindent
   361   There is also the derived notion for when an atom @{text a} is \emph{fresh}
   368   There is also the derived notion for when an atom @{text a} is \emph{fresh}
   362   for an @{text x}, defined as
   369   for an @{text x}, defined as
   363   
   370   %
   364   @{thm[display,indent=5] fresh_def[no_vars]}
   371   @{thm[display,indent=5] fresh_def[no_vars]}
   365 
   372 
   366   \noindent
   373   \noindent
   367   We also use for sets of atoms the abbreviation 
   374   We also use for sets of atoms the abbreviation 
   368   @{thm (lhs) fresh_star_def[no_vars]} defined as 
   375   @{thm (lhs) fresh_star_def[no_vars]} defined as 
   389 section {* General Binders *}
   396 section {* General Binders *}
   390 
   397 
   391 text {*
   398 text {*
   392   In Nominal Isabelle, the user is expected to write down a specification of a
   399   In Nominal Isabelle, the user is expected to write down a specification of a
   393   term-calculus and then a reasoning infrastructure is automatically derived
   400   term-calculus and then a reasoning infrastructure is automatically derived
   394   from this specifcation (remember that Nominal Isabelle is a definitional
   401   from this specification (remember that Nominal Isabelle is a definitional
   395   extension of Isabelle/HOL, which does not introduce any new axioms).
   402   extension of Isabelle/HOL, which does not introduce any new axioms).
   396 
   403 
   397 
   404 
   398   In order to keep our work manageable, we will wherever possible state
   405   In order to keep our work manageable, we will wherever possible state
   399   definitions and perform proofs inside Isabelle, as opposed to write custom
   406   definitions and perform proofs inside Isabelle, as opposed to write custom
   400   ML-code that generates them for each instance of a term-calculus. To that
   407   ML-code that generates them anew for each specification. To that
   401   end, we will consider pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.
   408   end, we will consider pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.
   402   These pairs are intended to represent the abstraction, or binding, of the set $as$ 
   409   These pairs are intended to represent the abstraction, or binding, of the set @{text "as"} 
   403   in the body $x$.
   410   in the body @{text "x"}.
   404 
   411 
   405   The first question we have to answer is when the pairs $(as, x)$ and $(bs, y)$ are
   412   The first question we have to answer is when the pairs $(as, x)$ and $(bs, y)$ are
   406   alpha-equivalent? (At the moment we are interested in
   413   alpha-equivalent? (At the moment we are interested in
   407   the notion of alpha-equivalence that is \emph{not} preserved by adding 
   414   the notion of alpha-equivalence that is \emph{not} preserved by adding 
   408   vacuous binders.) To answer this, we identify four conditions: {\it i)} given 
   415   vacuous binders.) To answer this, we identify four conditions: {\it i)} given 
   409   a free-variable function $\fv$ of type \mbox{@{text "\<beta> \<Rightarrow> atom set"}}, then $x$ and $y$ 
   416   a free-variable function $\fv$ of type \mbox{@{text "\<beta> \<Rightarrow> atom set"}}, then @{text x} and @{text y} 
   410   need to have the same set of free variables; moreover there must be a permutation,
   417   need to have the same set of free variables; moreover there must be a permutation
   411   $p$ so that {\it ii)} it leaves the free variables $x$ and $y$ unchanged, 
   418   @{text p}  such that {\it ii)} it leaves the free variables of @{text x} and @{text y} unchanged, 
   412   but {\it iii)} ``moves'' their bound names such that we obtain modulo a relation, 
   419   but {\it iii)} ``moves'' their bound names so that we obtain modulo a relation, 
   413   say \mbox{@{text "_ R _"}}, two equal terms. We also require {\it iv)} that $p$ makes 
   420   say \mbox{@{text "_ R _"}}, two equal terms. We also require {\it iv)} that @{text p} makes 
   414   the abstracted sets $as$ and $bs$ equal. The requirements {\it i)} to {\it iv)} can 
   421   the abstracted sets @{text as} and @{text bs} equal. The requirements {\it i)} to {\it iv)} can 
   415   be stated formally as follows:
   422   be stated formally as follows:
   416   %
   423   %
   417   \begin{equation}\label{alphaset}
   424   \begin{equation}\label{alphaset}
   418   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
   425   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
   419   \multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{set}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
   426   \multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{set}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
   420              & @{text "fv(x) - as = fv(y) - bs"}\\
   427              & @{text "fv(x) - as = fv(y) - bs"}\\
   421   \wedge     & @{text "fv(x) - as #* p"}\\
   428   \wedge     & @{text "(fv(x) - as) #* p"}\\
   422   \wedge     & @{text "(p \<bullet> x) R y"}\\
   429   \wedge     & @{text "(p \<bullet> x) R y"}\\
   423   \wedge     & @{text "(p \<bullet> as) = bs"}\\ 
   430   \wedge     & @{text "(p \<bullet> as) = bs"}\\ 
   424   \end{array}
   431   \end{array}
   425   \end{equation}
   432   \end{equation}
   426 
   433 
   429   we existentially quantify over this $p$. 
   436   we existentially quantify over this $p$. 
   430   Also note that the relation is dependent on a free-variable function $\fv$ and a relation 
   437   Also note that the relation is dependent on a free-variable function $\fv$ and a relation 
   431   $R$. The reason for this extra generality is that we will use $\approx_{set}$ for both 
   438   $R$. The reason for this extra generality is that we will use $\approx_{set}$ for both 
   432   ``raw'' terms and alpha-equated terms. In the latter case, $R$ will be replaced by 
   439   ``raw'' terms and alpha-equated terms. In the latter case, $R$ will be replaced by 
   433   equality $(op =)$ and we are going to prove that $\fv$ will be equal to the support 
   440   equality $(op =)$ and we are going to prove that $\fv$ will be equal to the support 
   434   of $x$ and $y$. To have these parameters means, however, we can derive properties about 
   441   of $x$ and $y$. 
   435   them generically.
       
   436 
   442 
   437   The definition in \eqref{alphaset} does not make any distinction between the
   443   The definition in \eqref{alphaset} does not make any distinction between the
   438   order of abstracted variables. If we want this, then we can define alpha-equivalence 
   444   order of abstracted variables. If we want this, then we can define alpha-equivalence 
   439   for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"} 
   445   for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"} 
   440   as follows
   446   as follows
   441   %
   447   %
   442   \begin{equation}\label{alphalist}
   448   \begin{equation}\label{alphalist}
   443   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
   449   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
   444   \multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{list}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
   450   \multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{list}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
   445              & @{text "fv(x) - (set as) = fv(y) - (set bs)"}\\
   451              & @{text "fv(x) - (set as) = fv(y) - (set bs)"}\\
   446   \wedge     & @{text "fv(x) - (set as) #* p"}\\
   452   \wedge     & @{text "(fv(x) - set as) #* p"}\\
   447   \wedge     & @{text "(p \<bullet> x) R y"}\\
   453   \wedge     & @{text "(p \<bullet> x) R y"}\\
   448   \wedge     & @{text "(p \<bullet> as) = bs"}\\ 
   454   \wedge     & @{text "(p \<bullet> as) = bs"}\\ 
   449   \end{array}
   455   \end{array}
   450   \end{equation}
   456   \end{equation}
   451   
   457   
   452   \noindent
   458   \noindent
   453   where $set$ is just the function that coerces a list of atoms into a set of atoms.
   459   where $set$ is the function that coerces a list of atoms into a set of atoms.
   454 
   460 
   455   If we do not want to make any difference between the order of binders and
   461   If we do not want to make any difference between the order of binders and
   456   also allow vacuous binders, then we keep sets of binders, but drop the fourth 
   462   also allow vacuous binders, then we keep sets of binders, but drop the fourth 
   457   condition in \eqref{alphaset}:
   463   condition in \eqref{alphaset}:
   458   %
   464   %
   459   \begin{equation}\label{alphares}
   465   \begin{equation}\label{alphares}
   460   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
   466   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l}
   461   \multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{res}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
   467   \multicolumn{2}{l}{(as, x) \approx\hspace{0.05mm}_{res}^{\fv, R, p} (bs, y) \;\dn\hspace{30mm}\;}\\[1mm]
   462              & @{text "fv(x) - as = fv(y) - bs"}\\
   468              & @{text "fv(x) - as = fv(y) - bs"}\\
   463   \wedge     & @{text "fv(x) - as #* p"}\\
   469   \wedge     & @{text "(fv(x) - as) #* p"}\\
   464   \wedge     & @{text "(p \<bullet> x) R y"}\\
   470   \wedge     & @{text "(p \<bullet> x) R y"}\\
   465   \end{array}
   471   \end{array}
   466   \end{equation}
   472   \end{equation}
   467 
   473 
   468   \begin{exmple}\rm
   474   \begin{exmple}\rm
   476 
   482 
   477   \noindent
   483   \noindent
   478   Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and \eqref{ex3}. It can be easily 
   484   Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and \eqref{ex3}. It can be easily 
   479   checked that @{text "({x, y}, x \<rightarrow> y)"} and
   485   checked that @{text "({x, y}, x \<rightarrow> y)"} and
   480   @{text "({y, x}, y \<rightarrow> x)"} are equal according to $\approx_{set}$ and $\approx_{res}$ by taking $p$ to
   486   @{text "({y, x}, y \<rightarrow> x)"} are equal according to $\approx_{set}$ and $\approx_{res}$ by taking $p$ to
   481   be the swapping @{term "(x \<rightleftharpoons> y)"}. In case of @{text "x \<noteq> y"} then 
   487   be the swapping @{term "(x \<rightleftharpoons> y)"}. In case of @{text "x \<noteq> y"}, then 
   482   $([x, y], x \rightarrow y) \not\approx_{list} ([y,x], x \rightarrow y)$ since there is no permutation that 
   488   $([x, y], x \rightarrow y) \not\approx_{list} ([y,x], x \rightarrow y)$ since there is no permutation that 
   483   makes the lists @{text "[x, y]"} and @{text "[y, x]"} equal, and in addition leaves the 
   489   makes the lists @{text "[x, y]"} and @{text "[y, x]"} equal, and also leaves the 
   484   type \mbox{@{text "x \<rightarrow> y"}} unchanged. Again if @{text "x \<noteq> y"}, we have that
   490   type \mbox{@{text "x \<rightarrow> y"}} unchanged. Another examples is 
   485    $(\{x\}, x) \approx_{res} (\{x,y\}, x)$ by taking $p$ to be the identity permutation.
   491    $(\{x\}, x) \approx_{res} (\{x,y\}, x)$ which holds by taking $p$ to be the identity permutation.
   486   However $(\{x\}, x) \not\approx_{set} (\{x,y\}, x)$ since there is no permutation that makes
   492   However, if @{text "x \<noteq> y"}, then  
       
   493   $(\{x\}, x) \not\approx_{set} (\{x,y\}, x)$ since there is no permutation that makes
   487   the sets $\{x\}$ and $\{x,y\}$ equal (similarly for $\approx_{list}$).
   494   the sets $\{x\}$ and $\{x,y\}$ equal (similarly for $\approx_{list}$).
   488   \end{exmple}
   495   \end{exmple}
   489 
   496 
   490   \noindent
   497   \noindent
   491   Let $\star$ range over $\{set, res, list\}$. We prove next under which 
   498   Let $\star$ range over $\{set, res, list\}$. We prove next under which 
   520 *}
   527 *}
   521 
   528 
   522 section {* Alpha-Equivalence and Free Variables *}
   529 section {* Alpha-Equivalence and Free Variables *}
   523 
   530 
   524 text {*
   531 text {*
   525   The syntax of a specification for a term-calculus in Nominal Isabelle is
   532   Our specifications for term-calculi are heavily
   526   heavily inspired by the syntax of the Ott-tool \cite{ott-jfp}. It is a
   533   inspired by the syntax of the Ott-tool \cite{ott-jfp}. A specification is
   527   collection of (possibly mutual recursive) type declarations, say
   534   a collection of (possibly mutual recursive) type declarations, say
   528   $ty_{\alpha{}1}$, $ty_{\alpha{}2}$, \ldots $ty_{\alpha{}n}$, and a
   535   $ty_{\alpha{}1}$, $ty_{\alpha{}2}$, \ldots $ty_{\alpha{}n}$, and an
   529   collection of associated binding function declarations, say
   536   associated collection of binding function declarations, say
   530   $bn_{\alpha{}1}$, \ldots $bn_{\alpha{}m}$. They are schematically 
   537   $bn_{\alpha{}1}$, \ldots $bn_{\alpha{}m}$. They are schematically written as
   531   written as follows:
   538   follows:
   532 
   539 
   533   \begin{center}
   540   \begin{center}
   534   \begin{tabular}{@ {\hspace{-9mm}}p{1.8cm}l}
   541   \begin{tabular}{@ {\hspace{-9mm}}p{1.8cm}l}
   535   types \mbox{declaration part} &
   542   type \mbox{declaration part} &
   536   $\begin{cases}
   543   $\begin{cases}
   537   \mbox{\begin{tabular}{l}
   544   \mbox{\begin{tabular}{l}
   538   \isacommand{nominal\_datatype} $ty_{\alpha{}1} = \ldots$\\
   545   \isacommand{nominal\_datatype} $ty_{\alpha{}1} = \ldots$\\
   539   \isacommand{and} $ty_{\alpha{}2} = \ldots$\\
   546   \isacommand{and} $ty_{\alpha{}2} = \ldots$\\
   540   $\ldots$\\ 
   547   $\ldots$\\ 
   541   \isacommand{and} $ty_{\alpha{}n} = \ldots$\\ 
   548   \isacommand{and} $ty_{\alpha{}n} = \ldots$\\ 
   542   \end{tabular}}
   549   \end{tabular}}
   543   \end{cases}$\\
   550   \end{cases}$\\
   544   binding \mbox{functions part} &
   551   binding \mbox{function part} &
   545   $\begin{cases}
   552   $\begin{cases}
   546   \mbox{\begin{tabular}{l}
   553   \mbox{\begin{tabular}{l}
   547   \isacommand{with} $bn_{\alpha{}1}$ \isacommand{and} \ldots \isacommand{and} $bn_{\alpha{}m}$
   554   \isacommand{with} $bn_{\alpha{}1}$ \isacommand{and} \ldots \isacommand{and} $bn_{\alpha{}m}$
   548   $\ldots$\\
   555   $\ldots$\\
   549   \isacommand{where}\\
   556   \isacommand{where}\\
   552   \end{cases}$\\
   559   \end{cases}$\\
   553   \end{tabular}
   560   \end{tabular}
   554   \end{center}
   561   \end{center}
   555 
   562 
   556   \noindent
   563   \noindent
   557   Each type declaration $ty_{\alpha{}i}$ consists of a collection of 
   564   Every type declaration $ty_{\alpha{}i}$ consists of a collection of 
   558   term-constructors, each of which comes with a list of labelled 
   565   term-constructors, each of which comes with a list of labelled 
   559   types that indicate the types of the arguments of the term-constructor,
   566   types that indicate the types of the arguments of the term-constructor.
   560   like 
   567   For example for a term-constructor $C_{\alpha}$ we might have
   561 
   568 
   562   \begin{center}
   569   \begin{center}
   563   $C_\alpha\;label_1\!::\!ty'_1\;\ldots label_j\!::\!ty'_j\;\;\textit{binding\_clauses}$ 
   570   $C_\alpha\;label_1\!::\!ty'_1\;\ldots label_j\!::\!ty'_j\;\;\textit{binding\_clauses}$ 
   564   \end{center}
   571   \end{center}
   565   
   572   
   566   \noindent
   573   \noindent
   567   The labels are optional and can be used in the (possibly empty) list of binding clauses.
   574   The labels are optional and can be used in the (possibly empty) list of \emph{binding clauses}.
   568   These clauses indicate the binders and the scope of the binders in a term-constructor. They
   575   These clauses indicate  the binders and the scope of the binders in a term-constructor.
   569   are of the form
   576   They come in three forms
   570 
   577 
   571   \begin{center}
   578   \begin{center}
   572   \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it label} 
   579   \begin{tabular}{l}
   573   \end{center}
   580   \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it label}\\
   574 
   581   \isacommand{bind\_set}\; {\it binders}\; \isacommand{in}\; {\it label}\\
   575   \noindent
   582   \isacommand{bind\_res}\; {\it binders}\; \isacommand{in}\; {\it label}\\
   576   whereby we distinguish between \emph{shallow} binders and \emph{deep} binders.
   583   \end{tabular}
   577   Shallow binders are just of the form \isacommand{bind}\; {\it label}\; 
   584   \end{center}
   578   \isacommand{in}\; {\it another\_label}. The only restriction on shallow binders
   585 
   579   is that the {\it label} must refer to either a type which is single atom or
   586   \noindent
   580   to a type which is a finite set of atoms. For example the specification of 
   587   whereby we also distinguish between \emph{shallow} binders and \emph{deep} binders.
   581   lambda-terms and type-schemes use them:
   588   Shallow binders are of the form \isacommand{bind}\; {\it label}\; 
       
   589   \isacommand{in}\; {\it another\_label} (similar the other forms). The restriction 
       
   590   we impose on shallow binders
       
   591   is that the {\it label} must either refer to a type that is an atom type or
       
   592   to a type that is a finite set or list of an atom type. For example the specifications of 
       
   593   lambda-terms and type-schemes use shallow binders (where \emph{name} is an atom type):
   582 
   594 
   583   \begin{center}
   595   \begin{center}
   584   \begin{tabular}{@ {}cc@ {}}
   596   \begin{tabular}{@ {}cc@ {}}
   585   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   597   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   586   \isacommand{nominal\_datatype} {\it lam} =\\
   598   \isacommand{nominal\_datatype} {\it lam} =\\
   587   \hspace{5mm}\phantom{$\mid$} Var\;{\it name}\\
   599   \hspace{5mm}\phantom{$\mid$} Var\;{\it name}\\
   588   \hspace{5mm}$\mid$ App\;{\it lam}\;{\it lam}\\
   600   \hspace{5mm}$\mid$ App\;{\it lam}\;{\it lam}\\
   589   \hspace{5mm}$\mid$ Lam\;{\it x::name}\;{\it t::lam}\\
   601   \hspace{5mm}$\mid$ Lam\;{\it x::name}\;{\it t::lam}\\
   590   \hspace{22mm}\isacommand{bind} {\it x} \isacommand{in} {\it t}\\
   602   \hspace{21mm}\isacommand{bind} {\it x} \isacommand{in} {\it t}\\
   591   \end{tabular} &
   603   \end{tabular} &
   592   \begin{tabular}{@ {}l@ {}}
   604   \begin{tabular}{@ {}l@ {}}
   593   \isacommand{nominal\_datatype} {\it ty} =\\
   605   \isacommand{nominal\_datatype} {\it ty} =\\
   594   \hspace{5mm}\phantom{$\mid$} TVar\;{\it name}\\
   606   \hspace{5mm}\phantom{$\mid$} TVar\;{\it name}\\
   595   \hspace{5mm}$\mid$ TFun\;{\it ty}\;{\it ty}\\
   607   \hspace{5mm}$\mid$ TFun\;{\it ty}\;{\it ty}\\
   596   \isacommand{and} {\it S} = All\;{\it xs::(name fset)}\;{\it T::ty}\\
   608   \isacommand{and} {\it tsc} = All\;{\it xs::(name fset)}\;{\it T::ty}\\
   597   \hspace{27mm}\isacommand{bind} {\it xs} \isacommand{in} {\it T}\\
   609   \hspace{22mm}\isacommand{bind\_res} {\it xs} \isacommand{in} {\it T}\\
   598   \end{tabular}
   610   \end{tabular}
   599   \end{tabular}
   611   \end{tabular}
   600   \end{center}
   612   \end{center}
   601 
   613 
   602   \noindent
   614   \noindent
   603   A specification of a term-calculus in Nominal Isabell is very similar to 
   615   A \emph{deep} binder uses an auxiliary binding function that picks out the atoms
       
   616   that are bound in one or more arguments. This binding function returns either 
       
   617   a set of atoms (for \isacommand{bind\_set} and \isacommand{bind\_res}) or a 
       
   618   list of atoms (for \isacommand{bind}). Such binding functions can be defined 
       
   619   by primitive recursion over the corresponding type. They are defined by equations
       
   620   included in the binding function part of the scheme given above. 
       
   621 
       
   622   For the moment we
       
   623   adopt the restriction of the Ott-tool that binding functions can only return
       
   624   the empty set, a singleton set of atoms or unions of atom sets. For example
       
   625   
       
   626   over the type for which they specify the bound atoms. 
       
   627   
       
   628 
       
   629 
       
   630   \noindent
       
   631   A specification of a term-calculus in Nominal Isabelle is very similar to 
   604   the usual datatype definition of Isabelle/HOL: 
   632   the usual datatype definition of Isabelle/HOL: 
   605 
   633 
   606 
   634 
   607   Because of the problem Pottier pointed out in \cite{Pottier06}, the general 
   635   Because of the problem Pottier pointed out in \cite{Pottier06}, the general 
   608   binders from the previous section cannot be used directly to represent w 
   636   binders from the previous section cannot be used directly to represent w