Paper/Paper.thy
changeset 1727 fd2913415a73
parent 1726 2eafd8ed4bbf
child 1728 9bbf2a1f9b3f
equal deleted inserted replaced
1726:2eafd8ed4bbf 1727:fd2913415a73
    63   @{text "S ::= \<forall>{x\<^isub>1,\<dots>, x\<^isub>n}. T"}
    63   @{text "S ::= \<forall>{x\<^isub>1,\<dots>, x\<^isub>n}. T"}
    64   \end{array}
    64   \end{array}
    65   \end{equation}
    65   \end{equation}
    66 
    66 
    67   \noindent
    67   \noindent
    68   and the quantification $\forall$ binds a finite (possibly empty) set of
    68   and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of
    69   type-variables.  While it is possible to implement this kind of more general
    69   type-variables.  While it is possible to implement this kind of more general
    70   binders by iterating single binders, this leads to a rather clumsy
    70   binders by iterating single binders, this leads to a rather clumsy
    71   formalisation of W. The need of iterating single binders is also one reason
    71   formalisation of W. The need of iterating single binders is also one reason
    72   why Nominal Isabelle and similar theorem provers that only provide
    72   why Nominal Isabelle and similar theorem provers that only provide
    73   mechanisms for binding single variables have not fared extremely well with the
    73   mechanisms for binding single variables have not fared extremely well with the
   181   specifications for $\mathtt{let}$s as follows
   181   specifications for $\mathtt{let}$s as follows
   182   %
   182   %
   183   \begin{center}
   183   \begin{center}
   184   \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
   184   \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
   185   @{text trm} & @{text "::="}  & @{text "\<dots>"}\\ 
   185   @{text trm} & @{text "::="}  & @{text "\<dots>"}\\ 
   186               & @{text "|"}    & @{text "\<LET> a::assn s::trm"}\hspace{4mm} 
   186               & @{text "|"}    & @{text "\<LET> as::assn s::trm"}\hspace{4mm} 
   187                                  \isacommand{bind} @{text "bn(a)"} \isacommand{in} @{text "s"}\\[1mm]
   187                                  \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}\\[1mm]
   188   @{text assn} & @{text "::="} & @{text "\<ANIL>"}\\
   188   @{text assn} & @{text "::="} & @{text "\<ANIL>"}\\
   189                & @{text "|"}   & @{text "\<ACONS> name trm assn"}
   189                & @{text "|"}   & @{text "\<ACONS> name trm assn"}
   190   \end{tabular}
   190   \end{tabular}
   191   \end{center}
   191   \end{center}
   192 
   192 
   202   \end{center}
   202   \end{center}
   203   
   203   
   204   \noindent
   204   \noindent
   205   The scope of the binding is indicated by labels given to the types, for
   205   The scope of the binding is indicated by labels given to the types, for
   206   example @{text "s::trm"}, and a binding clause, in this case
   206   example @{text "s::trm"}, and a binding clause, in this case
   207   \isacommand{bind} @{text "bn(a)"} \isacommand{in} @{text "s"}, that states
   207   \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding
   208   to bind in @{text s} all the names the function call @{text "bn(a)"} returns.
   208   clause states to bind in @{text s} all the names the function call @{text
   209   This style of specifying terms and bindings is heavily inspired by the
   209   "bn(as)"} returns.  This style of specifying terms and bindings is heavily
   210   syntax of the Ott-tool \cite{ott-jfp}.
   210   inspired by the syntax of the Ott-tool \cite{ott-jfp}.
   211 
   211 
   212 
   212   However, we will not be able to cope with all specifications that are
   213   However, we will not be able to deal with all specifications that are
       
   214   allowed by Ott. One reason is that Ott lets the user to specify ``empty'' 
   213   allowed by Ott. One reason is that Ott lets the user to specify ``empty'' 
   215   types like
   214   types like
   216 
   215 
   217   \begin{center}
   216   \begin{center}
   218   @{text "t ::= t t | \<lambda>x. t"}
   217   @{text "t ::= t t | \<lambda>x. t"}
   314   @{text "fv(t\<^isub>1 t\<^isub>2) = fv(t\<^isub>1) \<union> fv(t\<^isub>2)"}\\[1mm]
   313   @{text "fv(t\<^isub>1 t\<^isub>2) = fv(t\<^isub>1) \<union> fv(t\<^isub>2)"}\\[1mm]
   315   @{text "fv(\<lambda>x.t) = fv(t) - {x}"}
   314   @{text "fv(\<lambda>x.t) = fv(t) - {x}"}
   316   \end{center}
   315   \end{center}
   317   
   316   
   318   \noindent
   317   \noindent
   319   then with the help of the quotient package we obtain a function @{text "fv\<^sup>\<alpha>"}
   318   then with the help of the quotient package we can obtain a function @{text "fv\<^sup>\<alpha>"}
   320   operating on quotients, or alpha-equivalence classes of lambda-terms. This
   319   operating on quotients, or alpha-equivalence classes of lambda-terms. This
   321   lifted function is characterised by the equations
   320   lifted function is characterised by the equations
   322 
   321 
   323   \begin{center}
   322   \begin{center}
   324   @{text "fv\<^sup>\<alpha>(x) = {x}"}\hspace{10mm}
   323   @{text "fv\<^sup>\<alpha>(x) = {x}"}\hspace{10mm}
   342   The examples we have in mind where our reasoning infrastructure will be
   341   The examples we have in mind where our reasoning infrastructure will be
   343   helpful includes the term language of System @{text "F\<^isub>C"}, also
   342   helpful includes the term language of System @{text "F\<^isub>C"}, also
   344   known as Core-Haskell (see Figure~\ref{corehas}). This term language
   343   known as Core-Haskell (see Figure~\ref{corehas}). This term language
   345   involves patterns that have lists of type-, coercion- and term-variables,
   344   involves patterns that have lists of type-, coercion- and term-variables,
   346   all of which are bound in @{text "\<CASE>"}-expressions. One
   345   all of which are bound in @{text "\<CASE>"}-expressions. One
   347   difficulty is that each of these variables come with a kind or type
   346   difficulty is that we do not know in advance how many variables need to
       
   347   be bound. Another is that each bound variable comes with a kind or type
   348   annotation. Representing such binders with single binders and reasoning
   348   annotation. Representing such binders with single binders and reasoning
   349   about them in a theorem prover would be a major pain.  \medskip
   349   about them in a theorem prover would be a major pain.  \medskip
   350 
   350 
   351   \noindent
   351   \noindent
   352   {\bf Contributions:}  We provide new definitions for when terms
   352   {\bf Contributions:}  We provide new definitions for when terms
   408   Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
   408   Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
   409   \cite{HuffmanUrban10} (including proofs). We shall briefly review this work
   409   \cite{HuffmanUrban10} (including proofs). We shall briefly review this work
   410   to aid the description of what follows. 
   410   to aid the description of what follows. 
   411 
   411 
   412   Two central notions in the nominal logic work are sorted atoms and
   412   Two central notions in the nominal logic work are sorted atoms and
   413   sort-respecting permutations of atoms. We will use the variables @{text "a,
   413   sort-respecting permutations of atoms. We will use the letters @{text "a,
   414   b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for
   414   b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for
   415   permutations.  The sorts of atoms can be used to represent different kinds of
   415   permutations.  The sorts of atoms can be used to represent different kinds of
   416   variables, such as the term-, coercion- and type-variables in Core-Haskell,
   416   variables, such as the term-, coercion- and type-variables in Core-Haskell.
   417   and it is assumed that there is an infinite supply of atoms for each
   417   It is assumed that there is an infinite supply of atoms for each
   418   sort. However, in order to simplify the description, we shall assume in what
   418   sort. However, in order to simplify the description, we shall restrict ourselves 
   419   follows that there is only one sort of atoms.
   419   in what follows to only one sort of atoms.
   420 
   420 
   421   Permutations are bijective functions from atoms to atoms that are 
   421   Permutations are bijective functions from atoms to atoms that are 
   422   the identity everywhere except on a finite number of atoms. There is a 
   422   the identity everywhere except on a finite number of atoms. There is a 
   423   two-place permutation operation written
   423   two-place permutation operation written
   424   %
   424   %
   431   over which the permutation 
   431   over which the permutation 
   432   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   432   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   433   the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}}, 
   433   the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}}, 
   434   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   434   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   435   operation is defined by induction over the type-hierarchy (see \cite{HuffmanUrban10});
   435   operation is defined by induction over the type-hierarchy (see \cite{HuffmanUrban10});
   436   for example as follows for products, lists, sets, functions and booleans:
   436   for example permutations acting on products, lists, sets, functions and booleans is
       
   437   given by:
   437   %
   438   %
   438   \begin{equation}\label{permute}
   439   \begin{equation}\label{permute}
   439   \mbox{\begin{tabular}{@ {}cc@ {}}
   440   \mbox{\begin{tabular}{@ {}cc@ {}}
   440   \begin{tabular}{@ {}l@ {}}
   441   \begin{tabular}{@ {}l@ {}}
   441   @{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
   442   @{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
   504   @{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"}
   505   @{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"}
   505   \end{eqnarray}
   506   \end{eqnarray}
   506   
   507   
   507   \noindent 
   508   \noindent 
   508   in some cases it can be difficult to establish the support precisely, and
   509   in some cases it can be difficult to establish the support precisely, and
   509   only give an approximation (see the case for function applications
   510   only give an approximation (see \eqref{suppfun} above). Reasoning about
   510   above). Such approximations can be calculated with the notion
   511   such approximations can be made precise with the notion \emph{supports}, defined 
   511   \emph{supports}, defined as follows
   512   as follows:
   512 
   513 
   513   \begin{defn}
   514   \begin{defn}
   514   A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b}
   515   A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b}
   515   not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
   516   not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
   516   \end{defn}
   517   \end{defn}
   517 
   518 
   518   \noindent
   519   \noindent
   519   The main point of this definition is that we can show the following two properties.
   520   The main point of @{text supports} is that we can establish the following 
       
   521   two properties.
   520 
   522 
   521   \begin{property}\label{supportsprop}
   523   \begin{property}\label{supportsprop}
   522   {\it i)} @{thm[mode=IfThen] supp_is_subset[no_vars]}\\ 
   524   {\it i)} @{thm[mode=IfThen] supp_is_subset[no_vars]}\\ 
   523   {\it ii)} @{thm supp_supports[no_vars]}.
   525   {\it ii)} @{thm supp_supports[no_vars]}.
   524   \end{property}
   526   \end{property}
   525 
   527 
   526   Another important notion in the nominal logic work is \emph{equivariance}.
   528   Another important notion in the nominal logic work is \emph{equivariance}.
   527   For a function @{text f}, say of type @{text "\<alpha> \<Rightarrow> \<beta>"}, to be equivariant 
   529   For a function @{text f}, say of type @{text "\<alpha> \<Rightarrow> \<beta>"}, to be equivariant 
   528   requires that every permutation leaves @{text f} unchanged, that is
   530   it is required that every permutation leaves @{text f} unchanged, that is
   529   %
   531   %
   530   \begin{equation}\label{equivariancedef}
   532   \begin{equation}\label{equivariancedef}
   531   @{term "\<forall>p. p \<bullet> f = f"}
   533   @{term "\<forall>p. p \<bullet> f = f"}
   532   \end{equation}
   534   \end{equation}
   533 
   535 
   539   @{text "p \<bullet> f = f"} \;\;\;\textit{if and only if}\;\;\;
   541   @{text "p \<bullet> f = f"} \;\;\;\textit{if and only if}\;\;\;
   540   @{text "p \<bullet> (f x) = f (p \<bullet> x)"}
   542   @{text "p \<bullet> (f x) = f (p \<bullet> x)"}
   541   \end{equation}
   543   \end{equation}
   542  
   544  
   543   \noindent
   545   \noindent
   544   From equation \eqref{equivariancedef} and the definition of support shown in
   546   From property \eqref{equivariancedef} and the definition of @{text supp}, we 
   545   \eqref{suppdef}, we can be easily deduce that an equivariant function has
   547   can be easily deduce that an equivariant function has empty support.
   546   empty support.
   548 
   547 
   549   Finally, the nominal logic work provides us with convenient means to rename 
   548   Finally, the nominal logic work provides us with elegant means to rename 
       
   549   binders. While in the older version of Nominal Isabelle, we used extensively 
   550   binders. While in the older version of Nominal Isabelle, we used extensively 
   550   Property~\ref{swapfreshfresh} for renaming single binders, this property 
   551   Property~\ref{swapfreshfresh} for renaming single binders, this property 
   551   proved unwieldy for dealing with multiple binders. For this the following
   552   proved unwieldy for dealing with multiple binders. For such pinders the 
   552   generalisations turned out to be easier to use.
   553   following generalisations turned out to be easier to use.
   553 
   554 
   554   \begin{property}\label{supppermeq}
   555   \begin{property}\label{supppermeq}
   555   @{thm[mode=IfThen] supp_perm_eq[no_vars]}
   556   @{thm[mode=IfThen] supp_perm_eq[no_vars]}
   556   \end{property}
   557   \end{property}
   557 
   558 
   562   @{term "supp x \<sharp>* p"}.
   563   @{term "supp x \<sharp>* p"}.
   563   \end{property}
   564   \end{property}
   564 
   565 
   565   \noindent
   566   \noindent
   566   The idea behind the second property is that given a finite set @{text as}
   567   The idea behind the second property is that given a finite set @{text as}
   567   of binders (being bound in @{text x} which is ensured by the
   568   of binders (being bound, or fresh, in @{text x} is ensured by the
   568   assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text p} such that
   569   assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text p} such that
   569   the renamed binders @{term "p \<bullet> as"} avoid the @{text c} (which can be arbitrarily chosen
   570   the renamed binders @{term "p \<bullet> as"} avoid @{text c} (which can be arbitrarily chosen
   570   as long as it is finitely supported) and also does not affect anything
   571   as long as it is finitely supported) and also it does not affect anything
   571   in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last 
   572   in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last 
   572   fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders 
   573   fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders 
   573   in @{text x}, because @{term "p \<bullet> x = x"}.
   574   @{text as} in @{text x}, because @{term "p \<bullet> x = x"}.
   574 
   575 
   575   All properties given in this section are formalised in Isabelle/HOL and also
   576   All properties given in this section are formalised in Isabelle/HOL and also
   576   most of them are described with proofs in \cite{HuffmanUrban10}. In the next
   577   most of proofs are described in \cite{HuffmanUrban10} to which we refer the
   577   sections we will make extensively use of these properties for characterising
   578   reader. In the next sections we will make extensively use of these
   578   alpha-equivalence in the presence of multiple binders.
   579   properties in order to define alpha-equivalence in the presence of multiple
       
   580   binders.
   579 *}
   581 *}
   580 
   582 
   581 
   583 
   582 section {* General Binders\label{sec:binders} *}
   584 section {* General Binders\label{sec:binders} *}
   583 
   585 
   593   generates them anew for each specification. To that end, we will consider
   595   generates them anew for each specification. To that end, we will consider
   594   first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.  These pairs
   596   first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.  These pairs
   595   are intended to represent the abstraction, or binding, of the set @{text
   597   are intended to represent the abstraction, or binding, of the set @{text
   596   "as"} in the body @{text "x"}.
   598   "as"} in the body @{text "x"}.
   597 
   599 
   598   The first question we have to answer is when the pairs @{text "(as, x)"} and
   600   The first question we have to answer is when two pairs @{text "(as, x)"} and
   599   @{text "(bs, y)"} are alpha-equivalent? (At the moment we are interested in
   601   @{text "(bs, y)"} are alpha-equivalent? (At the moment we are interested in
   600   the notion of alpha-equivalence that is \emph{not} preserved by adding
   602   the notion of alpha-equivalence that is \emph{not} preserved by adding
   601   vacuous binders.) To answer this, we identify four conditions: {\it i)}
   603   vacuous binders.) To answer this, we identify four conditions: {\it i)}
   602   given a free-variable function @{text "fv"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
   604   given a free-variable function @{text "fv"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
   603   set"}}, then @{text x} and @{text y} need to have the same set of free
   605   set"}}, then @{text x} and @{text y} need to have the same set of free
   624   existentially quantify over this @{text "p"}. Also note that the relation is
   626   existentially quantify over this @{text "p"}. Also note that the relation is
   625   dependent on a free-variable function @{text "fv"} and a relation @{text
   627   dependent on a free-variable function @{text "fv"} and a relation @{text
   626   "R"}. The reason for this extra generality is that we will use
   628   "R"}. The reason for this extra generality is that we will use
   627   $\approx_{\textit{set}}$ for both ``raw'' terms and alpha-equated terms. In
   629   $\approx_{\textit{set}}$ for both ``raw'' terms and alpha-equated terms. In
   628   the latter case, $R$ will be replaced by equality @{text "="} and we
   630   the latter case, $R$ will be replaced by equality @{text "="} and we
   629   will prove that @{text "fv"} is equal to the support of @{text
   631   will prove that @{text "fv"} is equal to @{text "supp"}.
   630   x} and @{text y}.
       
   631 
   632 
   632   The definition in \eqref{alphaset} does not make any distinction between the
   633   The definition in \eqref{alphaset} does not make any distinction between the
   633   order of abstracted variables. If we want this, then we can define alpha-equivalence 
   634   order of abstracted variables. If we want this, then we can define alpha-equivalence 
   634   for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"} 
   635   for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"} 
   635   as follows
   636   as follows
   671   \end{center}
   672   \end{center}
   672 
   673 
   673   \noindent
   674   \noindent
   674   Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and
   675   Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and
   675   \eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and
   676   \eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and
   676   @{text "({y, x}, y \<rightarrow> x)"} are equal according to $\approx_{\textit{set}}$ and
   677   @{text "({y, x}, y \<rightarrow> x)"} are alpha-equivalent according to $\approx_{\textit{set}}$ and
   677   $\approx_{\textit{res}}$ by taking @{text p} to be the swapping @{term "(x \<rightleftharpoons>
   678   $\approx_{\textit{res}}$ by taking @{text p} to be the swapping @{term "(x \<rightleftharpoons>
   678   y)"}. In case of @{text "x \<noteq> y"}, then @{text "([x, y], x \<rightarrow> y)"}
   679   y)"}. In case of @{text "x \<noteq> y"}, then @{text "([x, y], x \<rightarrow> y)"}
   679   $\not\approx_{\textit{list}}$ @{text "([y, x], x \<rightarrow> y)"} since there is no permutation
   680   $\not\approx_{\textit{list}}$ @{text "([y, x], x \<rightarrow> y)"} since there is no permutation
   680   that makes the lists @{text "[x, y]"} and @{text "[y, x]"} equal, and also
   681   that makes the lists @{text "[x, y]"} and @{text "[y, x]"} equal, and also
   681   leaves the type \mbox{@{text "x \<rightarrow> y"}} unchanged. Another example is
   682   leaves the type \mbox{@{text "x \<rightarrow> y"}} unchanged. Another example is
   748 
   749 
   749   \noindent
   750   \noindent
   750   This lemma allows us to use our quotient package and introduce 
   751   This lemma allows us to use our quotient package and introduce 
   751   new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"}
   752   new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"}
   752   representing alpha-equivalence classes of pairs. The elements in these types 
   753   representing alpha-equivalence classes of pairs. The elements in these types 
   753   we will, respectively, write as:
   754   will be, respectively, written as:
   754 
   755 
   755   \begin{center}
   756   \begin{center}
   756   @{term "Abs as x"} \hspace{5mm} 
   757   @{term "Abs as x"} \hspace{5mm} 
   757   @{term "Abs_lst as x"} \hspace{5mm}
   758   @{term "Abs_lst as x"} \hspace{5mm}
   758   @{term "Abs_res as x"}
   759   @{term "Abs_res as x"}
   759   \end{center}
   760   \end{center}
   760 
   761 
   761   \noindent
   762   \noindent
   762   indicating that a set or list @{text as} is abstracted in @{text x}. We will
   763   indicating that a set or list @{text as} is abstracted in @{text x}. We will
   763   call the types \emph{abstraction types} and their elements
   764   call the types \emph{abstraction types} and their elements
   764   \emph{abstractions}. The important property we need is a characterisation
   765   \emph{abstractions}. The important property we need to know is what the 
   765   for the support of abstractions, namely:
   766   support of abstractions is, namely:
   766 
   767 
   767   \begin{thm}[Support of Abstractions]\label{suppabs} 
   768   \begin{thm}[Support of Abstractions]\label{suppabs} 
   768   Assuming @{text x} has finite support, then\\[-6mm] 
   769   Assuming @{text x} has finite support, then\\[-6mm] 
   769   \begin{center}
   770   \begin{center}
   770   \begin{tabular}{l@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
   771   \begin{tabular}{l@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
   774   \end{tabular}
   775   \end{tabular}
   775   \end{center}
   776   \end{center}
   776   \end{thm}
   777   \end{thm}
   777 
   778 
   778   \noindent
   779   \noindent
   779   We will show below the first equation as the others 
   780   Below we will show the first equation. The others 
   780   follow similar arguments. By definition of the abstraction type @{text "abs_set"} 
   781   follow similar arguments. By definition of the abstraction type @{text "abs_set"} 
   781   we have 
   782   we have 
   782   %
   783   %
   783   \begin{equation}\label{abseqiff}
   784   \begin{equation}\label{abseqiff}
   784   @{thm (lhs) abs_eq_iff(1)[where bs="as" and cs="bs", no_vars]} \;\;\text{if and only if}\;\; 
   785   @{thm (lhs) abs_eq_iff(1)[where bs="as" and cs="bs", no_vars]} \;\;\text{if and only if}\;\; 
   801   \begin{lemma}
   802   \begin{lemma}
   802   @{thm[mode=IfThen] abs_swap1(1)[where bs="as", no_vars]}
   803   @{thm[mode=IfThen] abs_swap1(1)[where bs="as", no_vars]}
   803   \end{lemma}
   804   \end{lemma}
   804 
   805 
   805   \begin{proof}
   806   \begin{proof}
   806   By using \eqref{abseqiff}, this lemma is straightforward when observing that
   807   This lemma is straightforward by using \eqref{abseqiff} and observing that
   807   the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) = (supp x - as)"}
   808   the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) = (supp x - as)"}.
   808   and that @{text supp} and set difference are equivariant.
   809   Moreover @{text supp} and set difference are equivariant \cite{HuffmanUrban10}.
   809   \end{proof}
   810   \end{proof}
   810 
   811 
   811   \noindent
   812   \noindent
   812   This lemma allows us to show
   813   This lemma allows us to show
   813   %
   814   %
   817   
   818   
   818   \noindent
   819   \noindent
   819   which by Property~\ref{supportsprop} gives us ``one half'' of
   820   which by Property~\ref{supportsprop} gives us ``one half'' of
   820   Thm~\ref{suppabs}. The ``other half'' is a bit more involved. To establish 
   821   Thm~\ref{suppabs}. The ``other half'' is a bit more involved. To establish 
   821   it, we use a trick from \cite{Pitts04} and first define an auxiliary 
   822   it, we use a trick from \cite{Pitts04} and first define an auxiliary 
   822   function taking an abstraction as argument
   823   function taking an abstraction as argument:
   823   %
   824   %
   824   \begin{center}
   825   \begin{center}
   825   @{thm supp_gen.simps[THEN eq_reflection, no_vars]}
   826   @{thm supp_gen.simps[THEN eq_reflection, no_vars]}
   826   \end{center}
   827   \end{center}
   827   
   828   
   844   \end{equation}
   845   \end{equation}
   845 
   846 
   846   \noindent
   847   \noindent
   847   since for finite sets, @{text "S"}, we have @{thm (concl) supp_finite_atom_set[no_vars]}.
   848   since for finite sets, @{text "S"}, we have @{thm (concl) supp_finite_atom_set[no_vars]}.
   848 
   849 
   849   Finally taking \eqref{halfone} and \eqref{halftwo} together provides us with a proof
   850   Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes of
   850   of Theorem~\ref{suppabs}. The point of these properties of abstractions is that we 
   851   Theorem~\ref{suppabs}. This theorem gives us confidence that our
   851   can define and prove them aconveniently on the Isabelle/HOL level,
   852   abstractions behave as one expects. To consider first abstractions of the
   852   but also use them in what follows next when we deal with binding in 
   853   form @{term "Abs as x"} is motivated by the fact that properties about them
   853   specifications of term-calculi. 
   854   can be conveninetly established at the Isabelle/HOL level.  But we can also
       
   855   use when we deal with binding in our term-calculi specifications.
   854 *}
   856 *}
   855 
   857 
   856 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *}
   858 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *}
   857 
   859 
   858 text {*
   860 text {*
   859   Our choice of syntax for specifications of term-calculi is influenced by the existing
   861   Our choice of syntax for specifications is influenced by the existing
   860   datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the Ott-tool
   862   datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the Ott-tool
   861   \cite{ott-jfp}. A specification is a collection of (possibly mutual
   863   \cite{ott-jfp}. For us a specification of a term-calculus is a collection of (possibly mutual
   862   recursive) type declarations, say @{text "ty"}$^\alpha_1$, \ldots, 
   864   recursive) type declarations, say @{text "ty"}$^\alpha_1$, \ldots, 
   863   @{text ty}$^\alpha_n$, and an associated collection
   865   @{text ty}$^\alpha_n$, and an associated collection
   864   of binding functions, say @{text bn}$^\alpha_1$, \ldots, @{text
   866   of binding functions, say @{text bn}$^\alpha_1$, \ldots, @{text
   865   bn}$^\alpha_m$. The syntax in Nominal Isabelle for such specifications is
   867   bn}$^\alpha_m$. The syntax in Nominal Isabelle for such specifications is
   866   roughly as follows:
   868   roughly as follows:
   898   \end{center}
   900   \end{center}
   899   
   901   
   900   \noindent
   902   \noindent
   901   whereby some of the @{text ty}$'_{1..l}$ (or their components) are contained in the collection
   903   whereby some of the @{text ty}$'_{1..l}$ (or their components) are contained in the collection
   902   of @{text ty}$^\alpha_{1..n}$ declared in \eqref{scheme}. In this case we will call the
   904   of @{text ty}$^\alpha_{1..n}$ declared in \eqref{scheme}. In this case we will call the
   903   corresponding argument a \emph{recursive argument}.  The labels annotated on
   905   corresponding argument a \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}.  The labels annotated on
   904   the types are optional. Their purpose is to be used in the (possibly empty) list of
   906   the types are optional. Their purpose is to be used in the (possibly empty) list of
   905   \emph{binding clauses}, which indicate the binders and their scope
   907   \emph{binding clauses}, which indicate the binders and their scope
   906   in a term-constructor.  They come in three \emph{modes}:
   908   in a term-constructor.  They come in three \emph{modes}:
   907 
   909 
   908 
   910 
   923   binders.  Shallow binders are of the form \isacommand{bind}\; {\it label}\;
   925   binders.  Shallow binders are of the form \isacommand{bind}\; {\it label}\;
   924   \isacommand{in}\; {\it label'} (similar for the other two modes). The
   926   \isacommand{in}\; {\it label'} (similar for the other two modes). The
   925   restriction we impose on shallow binders is that the {\it label} must either
   927   restriction we impose on shallow binders is that the {\it label} must either
   926   refer to a type that is an atom type or to a type that is a finite set or
   928   refer to a type that is an atom type or to a type that is a finite set or
   927   list of an atom type. Two examples for the use of shallow binders are the
   929   list of an atom type. Two examples for the use of shallow binders are the
   928   specification of lambda-terms, where a single name is bound, and of
   930   specification of lambda-terms, where a single name is bound, and 
   929   type-schemes, where a finite set of names is bound:
   931   type-schemes, where a finite set of names is bound:
   930 
   932 
   931   \begin{center}
   933   \begin{center}
   932   \begin{tabular}{@ {}cc@ {}}
   934   \begin{tabular}{@ {}cc@ {}}
   933   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   935   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   967 
   969 
   968   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
   970   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
   969   the atoms in one argument of the term-constructor, which can be bound in  
   971   the atoms in one argument of the term-constructor, which can be bound in  
   970   other arguments and also in the same argument (we will
   972   other arguments and also in the same argument (we will
   971   call such binders \emph{recursive}, see below). 
   973   call such binders \emph{recursive}, see below). 
   972   The binding functions are expected to return either a set of atoms
   974   The corresponding binding functions are expected to return either a set of atoms
   973   (for \isacommand{bind\_set} and \isacommand{bind\_res}) or a list of atoms
   975   (for \isacommand{bind\_set} and \isacommand{bind\_res}) or a list of atoms
   974   (for \isacommand{bind}). They can be defined by primitive recursion over the
   976   (for \isacommand{bind}). They can be defined by primitive recursion over the
   975   corresponding type; the equations must be given in the binding function part of
   977   corresponding type; the equations must be given in the binding function part of
   976   the scheme shown in \eqref{scheme}. For example for a calculus containing lets 
   978   the scheme shown in \eqref{scheme}. For example a term-calculus containing lets 
   977   with tuple patterns, you might specify
   979   with tuple patterns might be specified as:
   978 
   980 
   979   \begin{center}
   981   \begin{center}
   980   \begin{tabular}{l}
   982   \begin{tabular}{l}
   981   \isacommand{nominal\_datatype} @{text trm} =\\
   983   \isacommand{nominal\_datatype} @{text trm} =\\
   982   \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\
   984   \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\
   997   \end{center}
   999   \end{center}
   998   
  1000   
   999   \noindent
  1001   \noindent
  1000   In this specification the function @{text "bn"} determines which atoms of @{text  p} are
  1002   In this specification the function @{text "bn"} determines which atoms of @{text  p} are
  1001   bound in the argument @{text "t"}. Note that in the second last clause the function @{text "atom"}
  1003   bound in the argument @{text "t"}. Note that in the second last clause the function @{text "atom"}
  1002   coerces a name into the generic atom type of Nominal Isabelle. This allows
  1004   coerces a name into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This allows
  1003   us to treat binders of different atom type uniformly. 
  1005   us to treat binders of different atom type uniformly. 
  1004 
  1006 
  1005   As will shortly become clear, we cannot return an atom in a binding function
  1007   As will shortly become clear, we cannot return an atom in a binding function
  1006   that is also bound in the corresponding term-constructor. That means in the
  1008   that is also bound in the corresponding term-constructor. That means in the
  1007   example above that the term-constructors @{text PVar} and @{text PTup} must not have a
  1009   example above that the term-constructors @{text PVar} and @{text PTup} must not have a
  1008   binding clause.  In the present version of Nominal Isabelle, we also adopted
  1010   binding clause.  In the version of Nominal Isabelle described here, we also adopted
  1009   the restriction from the Ott-tool that binding functions can only return:
  1011   the restriction from the Ott-tool that binding functions can only return:
  1010   the empty set or empty list (as in case @{text PNil}), a singleton set or singleton
  1012   the empty set or empty list (as in case @{text PNil}), a singleton set or singleton
  1011   list containing an atom (case @{text PVar}), or unions of atom sets or appended atom
  1013   list containing an atom (case @{text PVar}), or unions of atom sets or appended atom
  1012   lists (case @{text PTup}). This restriction will simplify proofs later on.
  1014   lists (case @{text PTup}). This restriction will simplify definitions and 
       
  1015   proofs later on.
  1013   
  1016   
  1014   The most drastic restriction we have to impose on deep binders is that 
  1017   The most drastic restriction we have to impose on deep binders is that 
  1015   we cannot have ``overlapping'' deep binders. Consider for example the 
  1018   we cannot have ``overlapping'' deep binders. Consider for example the 
  1016   term-constructors:
  1019   term-constructors:
  1017 
  1020 
  1029 
  1032 
  1030   \noindent
  1033   \noindent
  1031   In the first case we bind all atoms from the pattern @{text p} in @{text t}
  1034   In the first case we bind all atoms from the pattern @{text p} in @{text t}
  1032   and also all atoms from @{text q} in @{text t}. As a result we have no way
  1035   and also all atoms from @{text q} in @{text t}. As a result we have no way
  1033   to determine whether the binder came from the binding function @{text
  1036   to determine whether the binder came from the binding function @{text
  1034   "bn(p)"} or @{text "bn(q)"}. Similarly in the second case. There the binder
  1037   "bn(p)"} or @{text "bn(q)"}. Similarly in the second case. The reason why
  1035   @{text "bn(p)"} overlaps with the shallow binder @{text x}. The reason why
       
  1036   we must exclude such specifications is that they cannot be represent by
  1038   we must exclude such specifications is that they cannot be represent by
  1037   the general binders described in Section \ref{sec:binders}. However
  1039   the general binders described in Section \ref{sec:binders}. However
  1038   the following two term-constructors are allowed
  1040   the following two term-constructors are allowed
  1039 
  1041 
  1040   \begin{center}
  1042   \begin{center}
  1051   \noindent
  1053   \noindent
  1052   since there is no overlap of binders.
  1054   since there is no overlap of binders.
  1053   
  1055   
  1054   Note that in the last example we wrote {\it\isacommand{bind}\;bn(p)\;\isacommand{in}\;p}.
  1056   Note that in the last example we wrote {\it\isacommand{bind}\;bn(p)\;\isacommand{in}\;p}.
  1055   Whenever such a binding clause is present, we will call the binder \emph{recursive}.
  1057   Whenever such a binding clause is present, we will call the binder \emph{recursive}.
  1056   To see the purpose for this, compare ``plain'' Lets and Let\_recs:
  1058   To see the purpose for such recursive binders, compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s:
  1057   %
  1059   %
  1058   \begin{equation}\label{letrecs}
  1060   \begin{equation}\label{letrecs}
  1059   \mbox{%
  1061   \mbox{%
  1060   \begin{tabular}{@ {}l@ {}}
  1062   \begin{tabular}{@ {}l@ {}}
  1061   \isacommand{nominal\_datatype}~@{text "trm ="}\\
  1063   \isacommand{nominal\_datatype}~@{text "trm ="}\\
  1073   \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\
  1075   \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\
  1074   \end{tabular}}
  1076   \end{tabular}}
  1075   \end{equation}
  1077   \end{equation}
  1076 
  1078 
  1077   \noindent
  1079   \noindent
  1078   The difference is that with Let we only want to bind the atoms @{text
  1080   The difference is that with @{text Let} we only want to bind the atoms @{text
  1079   "bn(a)"} in the term @{text t}, but with Let\_rec we also want to bind the atoms
  1081   "bn(a)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1080   inside the assignment. This requires recursive binders and also has
  1082   inside the assignment. This difference has consequences for the free-variable 
  1081   consequences for the free variable function and alpha-equivalence relation,
  1083   function and alpha-equivalence relation, which we are going to describe in the 
  1082   which we are going to explain in the rest of this section.
  1084   rest of this section.
  1083  
  1085  
  1084   Having dealt with all syntax matters, the problem now is how we can turn
  1086   Having dealt with all syntax matters, the problem now is how we can turn
  1085   specifications into actual type definitions in Isabelle/HOL and then
  1087   specifications into actual type definitions in Isabelle/HOL and then
  1086   establish a reasoning infrastructure for them. Because of the problem
  1088   establish a reasoning infrastructure for them. Because of the problem
  1087   Pottier and Cheney pointed out, we cannot in general re-arrange arguments of
  1089   Pottier and Cheney pointed out, we cannot in general re-arrange arguments of
  1093 
  1095 
  1094 
  1096 
  1095   The datatype definition can be obtained by stripping off the 
  1097   The datatype definition can be obtained by stripping off the 
  1096   binding clauses and the labels on the types. We also have to invent
  1098   binding clauses and the labels on the types. We also have to invent
  1097   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1099   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1098   given by user. In our implementation we just use an affix @{text "_raw"}.
  1100   given by user. In our implementation we just use the affix @{text "_raw"}.
  1099   For the purpose of the paper we just use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1101   But for the purpose of this paper, we just use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1100   that a notion is defined over alpha-equivalence classes and leave it out 
  1102   that a notion is defined over alpha-equivalence classes and leave it out 
  1101   for the corresponding notion defined on the ``raw'' level. So for example 
  1103   for the corresponding notion defined on the ``raw'' level. So for example 
  1102   we have
  1104   we have
  1103   
  1105   
  1104   \begin{center}
  1106   \begin{center}
  1105   @{text "ty\<^sup>\<alpha> \<mapsto> ty"} \hspace{2mm}and\hspace{2mm} @{text "C\<^sup>\<alpha> \<mapsto> C"}
  1107   @{text "ty\<^sup>\<alpha> \<mapsto> ty"} \hspace{2mm}and\hspace{2mm} @{text "C\<^sup>\<alpha> \<mapsto> C"}
  1106   \end{center}
  1108   \end{center}
  1107   
  1109   
  1108   \noindent
  1110   \noindent
  1109   
  1111   where the type @{term ty} is the type used in the quotient construction for 
       
  1112   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. 
       
  1113 
  1110   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1114   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1111   non-empty and the types in the constructors only occur in positive 
  1115   non-empty and the types in the constructors only occur in positive 
  1112   position (see \cite{Berghofer99} for an indepth description of the datatype package
  1116   position (see \cite{Berghofer99} for an indepth description of the datatype package
  1113   in Isabelle/HOL). We then define the user-specified binding 
  1117   in Isabelle/HOL). We then define the user-specified binding 
  1114   functions, called @{term "bn_ty"}, by primitive recursion over the corresponding 
  1118   functions, called @{term "bn_ty"}, by primitive recursion over the corresponding 
  1133   \begin{center}
  1137   \begin{center}
  1134   @{text "fv_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set    \<dots>    fv_ty\<^isub>n :: ty\<^isub>n \<Rightarrow> atom set"}
  1138   @{text "fv_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set    \<dots>    fv_ty\<^isub>n :: ty\<^isub>n \<Rightarrow> atom set"}
  1135   \end{center}
  1139   \end{center}
  1136 
  1140 
  1137   \noindent
  1141   \noindent
  1138   We define them together with auxiliary free variable functions for
  1142   We define them together with auxiliary free-variable functions for
  1139   the binding functions. Given binding functions 
  1143   the binding functions. Given binding functions 
  1140   @{text "bn_ty\<^isub>1 \<dots> bn_ty\<^isub>m"} we need to define
  1144   @{text "bn_ty\<^isub>1 \<dots> bn_ty\<^isub>m"} we need to define
  1141   %
  1145   %
  1142   \begin{center}
  1146   \begin{center}
  1143   @{text "fv_bn_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set  \<dots>  fv_bn_ty\<^isub>m :: ty\<^isub>m \<Rightarrow> atom set"}
  1147   @{text "fv_bn_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set  \<dots>  fv_bn_ty\<^isub>m :: ty\<^isub>m \<Rightarrow> atom set"}
  1144   \end{center}
  1148   \end{center}
  1145 
  1149 
  1146   \noindent
  1150   \noindent
  1147   The reason for this setup is that in a deep binder not all atoms have to be
  1151   The reason for this setup is that in a deep binder not all atoms have to be
  1148   bound. While the idea behind these free variable functions is just to
  1152   bound, as we shall see in an example below. While the idea behind these
  1149   collect all atoms that are not bound, because of the rather complicated
  1153   free-variable functions is clear (they just collect all atoms that are not bound),
  1150   binding mechanisms their definitions are somewhat involved.
  1154   because of the rather complicated binding mechanisms their definitions are
       
  1155   somewhat involved.
  1151 
  1156 
  1152   Given a term-constructor @{text "C"} of type @{text ty} with argument types
  1157   Given a term-constructor @{text "C"} of type @{text ty} with argument types
  1153   \mbox{@{text "ty\<^isub>1 \<dots> ty\<^isub>n"}} and given some binding clauses associated with 
  1158   \mbox{@{text "ty\<^isub>1 \<dots> ty\<^isub>n"}}, the function
  1154   this constructor, the function
       
  1155   @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be the union of the values
  1159   @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be the union of the values
  1156   calculated below for each argument. 
  1160   calculated next for each argument. 
  1157 
  1161   First we deal with the case that @{text "x\<^isub>i"} is a binder. From the binding clauses, 
  1158   First we deal with the case @{text "x\<^isub>i"} is a binder. From the binding clauses, 
       
  1159   we can determine whether the argument is a shallow or deep
  1162   we can determine whether the argument is a shallow or deep
  1160   binder, and in the latter case also whether it is a recursive or
  1163   binder, and in the latter case also whether it is a recursive or
  1161   non-recursive binder. 
  1164   non-recursive binder. 
  1162 
  1165 
  1163   \begin{center}
  1166   \begin{center}
  1170   \end{tabular}
  1173   \end{tabular}
  1171   \end{center}
  1174   \end{center}
  1172 
  1175 
  1173   \noindent
  1176   \noindent
  1174   The first clause states that shallow binders do not contribute to the
  1177   The first clause states that shallow binders do not contribute to the
  1175   free variables; in the second clause, we have to look up all
  1178   free variables; in the second clause, we have to collect all
  1176   the free variables that are left unbound by the binding function @{text "bn_ty\<^isub>i"}---this
  1179   variables that are left unbound by the binding function @{text "bn_ty\<^isub>i"}---this
  1177   is done with function @{text "fv_bn_ty\<^isub>i"}; in the third clause, since the 
  1180   is done with function @{text "fv_bn_ty\<^isub>i"}; in the third clause, since the 
  1178   binder is recursive, we need to bind all variables specified by 
  1181   binder is recursive, we need to bind all variables specified by 
  1179   @{text "bn_ty\<^isub>i"}---therefore we subtract @{text "bn_ty\<^isub>i x\<^isub>i"} from the free
  1182   @{text "bn_ty\<^isub>i"}---therefore we subtract @{text "bn_ty\<^isub>i x\<^isub>i"} from the free
  1180   variables of @{text "x\<^isub>i"}.
  1183   variables of @{text "x\<^isub>i"}.
  1181 
  1184 
  1182   In case the argument is \emph{not} a binder, we need to consider 
  1185   In case the argument is \emph{not} a binder, we need to consider 
  1183   whether the @{text "x\<^isub>i"} is the body of one or more binding clauses. 
  1186   whether the @{text "x\<^isub>i"} is the body of one or more binding clauses. 
  1184   In this case we first calculate the set @{text "bnds"} as follows: 
  1187   In this case we first calculate the set @{text "bnds"} as follows: 
  1185   either the binders are all shallow or there is a single deep binder.
  1188   either the corresponding binders are all shallow or there is a single deep binder.
  1186   In the former case we take @{text bnds} to be the union of all shallow 
  1189   In the former case we take @{text bnds} to be the union of all shallow 
  1187   binders; in the latter case, we just take the set of atoms specified by the 
  1190   binders; in the latter case, we just take the set of atoms specified by the 
  1188   binding function. The value for @{text "x\<^isub>i"} is then given by:
  1191   binding function. The value for @{text "x\<^isub>i"} is then given by:
  1189 
  1192 
  1190   \begin{center}
  1193   \begin{equation}\label{deepbody}
       
  1194   \mbox{%
  1191   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1195   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1192   $\bullet$ & @{text "{atom x\<^isub>i} - bnds"} provided @{term "x\<^isub>i"} is an atom\\
  1196   $\bullet$ & @{text "{atom x\<^isub>i} - bnds"} provided @{term "x\<^isub>i"} is an atom\\
  1193   $\bullet$ & @{text "(atoms x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a set of atoms\\
  1197   $\bullet$ & @{text "(atoms x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a set of atoms\\
  1194   $\bullet$ & @{text "(atoms (set x\<^isub>i)) - bnds"} provided @{term "x\<^isub>i"} is a list of atoms\\
  1198   $\bullet$ & @{text "(atoms (set x\<^isub>i)) - bnds"} provided @{term "x\<^isub>i"} is a list of atoms\\
  1195   $\bullet$ & @{text "(fv_ty\<^isub>i x\<^isub>i) - bnds"} provided @{term "ty\<^isub>i"} is one of the raw datatypes
  1199   $\bullet$ & @{text "(fv_ty\<^isub>i x\<^isub>i) - bnds"} provided @{term "ty\<^isub>i"} is one of the raw datatypes
  1196      corresponding to the types specified by the user\\
  1200      corresponding to the types specified by the user\\
  1197 %  $\bullet$ & @{text "(fv\<^isup>\<alpha> x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a defined nominal datatype
  1201 %  $\bullet$ & @{text "(fv\<^isup>\<alpha> x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a defined nominal datatype
  1198 %     with a free variable function @{text "fv\<^isup>\<alpha>"}\\
  1202 %     with a free-variable function @{text "fv\<^isup>\<alpha>"}\\
  1199   $\bullet$ & @{term "{}"} otherwise
  1203   $\bullet$ & @{term "{}"} otherwise
  1200   \end{tabular}
  1204   \end{tabular}}
  1201   \end{center}
  1205   \end{equation}
  1202 
  1206 
  1203   \noindent 
  1207   \noindent 
  1204   Like the function @{text atom}, @{text "atoms"} coerces a set of atoms to the generic atom type.
  1208   Like the coercion function @{text atom} used above, @{text "atoms as"} coerces 
       
  1209   the set @{text as} to the generic atom type.
  1205   It is defined as @{text "atom as \<equiv> {atom a | a \<in> as}"}.
  1210   It is defined as @{text "atom as \<equiv> {atom a | a \<in> as}"}.
  1206 
  1211 
  1207   The last case we need to consider is when @{text "x\<^isub>i"} is neither
  1212   The last case we need to consider is when @{text "x\<^isub>i"} is neither
  1208   a binder nor a body of an abstraction. In this case it is defined 
  1213   a binder nor a body of an abstraction. In this case it is defined 
  1209   as above, except that we do not subtract the set @{text bnds}.
  1214   as in \eqref{deepbody}, except that we do not need to subtract the 
  1210   
  1215   set @{text bnds}.
  1211   Next, we need to define a free variable function @{text "fv_bn_ty\<^isub>i"} for 
  1216   
       
  1217   Next, we need to define a free-variable function @{text "fv_bn_ty\<^isub>i"} for 
  1212   each binding function @{text "bn_ty\<^isub>i"}. The idea behind this
  1218   each binding function @{text "bn_ty\<^isub>i"}. The idea behind this
  1213   function is to compute the set of free atoms that are not bound by 
  1219   function is to compute the set of free atoms that are not bound by 
  1214   the binding function. Because of the restrictions we imposed on the 
  1220   @{text "bn_ty\<^isub>i"}. Because of the restrictions we imposed on the 
  1215   form of binding functions, this can be done automatically by recursively 
  1221   form of binding functions, this can be done automatically by recursively 
  1216   building up the the set of free variables from the arguments that are 
  1222   building up the the set of free variables from the arguments that are 
  1217   not bound. Let us assume one clause of the binding function is 
  1223   not bound. Let us assume one clause of the binding function is 
  1218   @{text "bn_ty\<^isub>i (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}, then @{text "fv_bn_ty\<^isub>i"} is the 
  1224   @{text "bn_ty\<^isub>i (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}, then @{text "fv_bn_ty\<^isub>i"} is the 
  1219   union of the values calculated for @{text "x\<^isub>j"} of type @{text "ty\<^isub>j"}
  1225   union of the values calculated for @{text "x\<^isub>j"} of type @{text "ty\<^isub>j"}
  1220   as follows:
  1226   as follows:
  1221 
  1227 
  1222   \begin{center}
  1228   \begin{center}
  1223   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1229   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1224   \multicolumn{2}{l}{@{text "x\<^isub>j"} occurs in @{text "rhs"}:}\\ 
  1230   \multicolumn{2}{l}{@{text "x\<^isub>j"} occurs in @{text "rhs"}:}\\ 
  1225   $\bullet$ & @{term "{}"} provided @{term "x\<^isub>j"} is an atom,
  1231   $\bullet$ & @{term "{}"} provided @{term "x\<^isub>j"} is a single atom,
  1226      atom list or atom set\\
  1232      atom list or atom set\\
  1227   $\bullet$ & @{text "fv_bn_ty\<^isub>j x\<^isub>j"} in case @{text "rhs"} contains the 
  1233   $\bullet$ & @{text "fv_bn_ty\<^isub>j x\<^isub>j"} in case @{text "rhs"} contains the 
  1228   recursive call @{text "bn_ty\<^isub>j x\<^isub>j"}\\[1mm]
  1234   recursive call @{text "bn_ty\<^isub>j x\<^isub>j"}\\[1mm]
  1229   %
  1235   %
  1230   \multicolumn{2}{l}{@{text "x\<^isub>j"} does not occur in @{text "rhs"}:}\\ 
  1236   \multicolumn{2}{l}{@{text "x\<^isub>j"} does not occur in @{text "rhs"}:}\\ 
  1231   $\bullet$ & @{text "atoms x\<^isub>j"} provided @{term "x\<^isub>j"} is a set of atoms\\
  1237   $\bullet$ & @{text "atoms x\<^isub>j"} provided @{term "x\<^isub>j"} is a set of atoms\\
  1232   $\bullet$ & @{term "atoms (set x\<^isub>j)"} provided @{term "x\<^isub>j"} is a list of atoms\\
  1238   $\bullet$ & @{term "atoms (set x\<^isub>j)"} provided @{term "x\<^isub>j"} is a list of atoms\\
  1233   $\bullet$ & @{text "fv_ty\<^isub>j x\<^isub>j"} provided @{term "ty\<^isub>j"} is one of the raw
  1239   $\bullet$ & @{text "fv_ty\<^isub>j x\<^isub>j"} provided @{term "ty\<^isub>j"} is one of the raw
  1234      types corresponding to the types specified by the user\\
  1240      types corresponding to the types specified by the user\\
  1235 %  $\bullet$ & @{text "fv_ty\<^isup>\<alpha> x\<^isub>j - bnds"} provided @{term "x\<^isub>j"}  is not in @{text "rhs"}
  1241 %  $\bullet$ & @{text "fv_ty\<^isup>\<alpha> x\<^isub>j - bnds"} provided @{term "x\<^isub>j"}  is not in @{text "rhs"}
  1236 %     and is an existing nominal datatype with the free variable function @{text "fv\<^isup>\<alpha>"}\\
  1242 %     and is an existing nominal datatype with the free-variable function @{text "fv\<^isup>\<alpha>"}\\
  1237   $\bullet$ & @{term "{}"} otherwise
  1243   $\bullet$ & @{term "{}"} otherwise
  1238   \end{tabular}
  1244   \end{tabular}
  1239   \end{center}
  1245   \end{center}
  1240 
  1246 
  1241   \noindent
  1247   \noindent
  1242   To see how these definitions work, let us consider the term-constructors 
  1248   To see how these definitions work, let us consider again the term-constructors 
  1243   for @{text "Let"} and @{text "Let_rec"} from example shown in \eqref{letrecs}. 
  1249   @{text "Let"} and @{text "Let_rec"} from example shown in \eqref{letrecs}. 
  1244   For this specification we need to define three functions, namely
  1250   For this specification we need to define three functions, namely
  1245   @{text "fv\<^bsub>trm\<^esub>"}, @{text "fv\<^bsub>assn\<^esub>"} and @{text "fv\<^bsub>bn\<^esub>"}. 
  1251   @{text "fv\<^bsub>trm\<^esub>"}, @{text "fv\<^bsub>assn\<^esub>"} and @{text "fv\<^bsub>bn\<^esub>"}. They are as follows:
  1246   %
  1252   %
  1247   \begin{center}
  1253   \begin{center}
  1248   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
  1254   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
  1249   @{text "fv\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "fv\<^bsub>bn\<^esub> as \<union> (fv\<^bsub>trm\<^esub> t - set (bn as))"}\\
  1255   @{text "fv\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "fv\<^bsub>bn\<^esub> as \<union> (fv\<^bsub>trm\<^esub> t - set (bn as))"}\\
  1250   @{text "fv\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} &\\
  1256   @{text "fv\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} &\\
  1260 
  1266 
  1261   \noindent
  1267   \noindent
  1262   Since there are no binding clauses for the term-constructors @{text ANil}
  1268   Since there are no binding clauses for the term-constructors @{text ANil}
  1263   and @{text "ACons"}, the corresponding free-variable function @{text
  1269   and @{text "ACons"}, the corresponding free-variable function @{text
  1264   "fv\<^bsub>assn\<^esub>"} returns all atoms occuring in an assignment. The
  1270   "fv\<^bsub>assn\<^esub>"} returns all atoms occuring in an assignment. The
  1265   binding happens in @{text Let} and @{text "Let_rec"}. In the first clause we
  1271   binding only takes place in @{text Let} and @{text "Let_rec"}. In the @{text
  1266   want to bind all atoms given by @{text "set (bn as)"} in @{text
  1272   "Let"}-clause we want to bind all atoms given by @{text "set (bn as)"} in
  1267   t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
  1273   @{text t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
  1268   "fv\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are
  1274   "fv\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are
  1269   free in @{text "as"}. This is what the purpose of the function @{text
  1275   free in @{text "as"}. This is what the purpose of the function @{text
  1270   "fv\<^bsub>bn\<^esub>"} is.  In contrast, in @{text "Let_rec"} we have a
  1276   "fv\<^bsub>bn\<^esub>"} is.  In contrast, in @{text "Let_rec"} we have a
  1271   recursive binder where we want to also bind all occurences of atoms inside
  1277   recursive binder where we want to also bind all occurences of the atoms
  1272   @{text "as"}. Therefore we have to subtract @{text "set (bn as)"} from
  1278   @{text "bn as"} inside @{text "as"}. Therefore we have to subtract @{text
  1273   @{text "fv\<^bsub>assn\<^esub> as"}. Similarly for @{text
  1279   "set (bn as)"} from @{text "fv\<^bsub>assn\<^esub> as"}, as well as from
  1274   "fv\<^bsub>trm\<^esub> t - bn as"}. An interesting point in this example is
  1280   @{text "fv\<^bsub>trm\<^esub> t"}. An interesting point in this example is
  1275   that an assignment ``alone'' does not have any bound variables. Only in the
  1281   that an assignment ``alone'' does not have any bound variables. Only in the
  1276   context of a @{text Let} pr @{text "Let_rec"} will some atoms occuring in an
  1282   context of a @{text Let} or @{text "Let_rec"} will some atoms become bound
  1277   assignment become bound. This is a phenomenon that has also been pointed out
  1283   (teh term-constructors that have binding clauses).  This is a phenomenon 
  1278   in \cite{ott-jfp}.
  1284   that has also been pointed out in \cite{ott-jfp}.
  1279 
  1285 
  1280   We then define the alpha equivalence relations. For the types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"}
  1286   Next we define alpha-equivalence realtions for the types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"}. We call them
  1281   we need to define
  1287   @{text "\<approx>ty\<^isub>1 \<dots> \<approx>ty\<^isub>n"}. Like with the free-variable functions, 
  1282 
  1288   we also need to  define auxiliary alpha-equivalence relations for the binding functions. 
  1283   \begin{center}
  1289   Say we have @{text "bn_ty\<^isub>1 \<dots> bn_ty\<^isub>m"}, we also define @{text "\<approx>bn_ty\<^isub>1 \<dots> \<approx>bn_ty\<^isub>n"}.
  1284   @{text "\<approx>\<^isub>1 :: ty\<^isub>1 \<Rightarrow> ty\<^isub>1 \<Rightarrow> bool \<dots> \<approx>\<^isub>n :: ty\<^isub>n \<Rightarrow> ty\<^isub>n \<Rightarrow> bool"}
  1290 
  1285   \end{center}
  1291   The relations are inductively defined predicates, whose clauses have
  1286 
  1292   conclusions of the form  @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>ty C y\<^isub>1 \<dots> y\<^isub>n"} (let us assume 
  1287   \noindent
  1293   @{text C} is of type @{text ty} and its arguments are specified as @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}).
  1288   together with the auxiliary equivalences for binding functions. Given binding
  1294   The task is to specify what the premises of these clauses are. For this we
  1289   functions for types @{text "bn\<^isub>1 :: ty\<^isub>i\<^isub>1 \<Rightarrow> \<dots> \<dots> bn\<^isub>m :: ty\<^isub>i\<^isub>m \<Rightarrow> \<dots>"} we need to define
  1295   consider the pairs @{text "(x\<^isub>i, y\<^isub>i)"} which necesarily must have the same type, say
  1290   \begin{center}
  1296   @{text "ty\<^isub>i"}. For each of these pairs we calculate a premise as follows. 
  1291   @{text "\<approx>bn\<^isub>1 :: ty\<^isub>i\<^isub>1 \<Rightarrow> ty\<^isub>i\<^isub>1 \<Rightarrow> bool \<dots> \<approx>bn\<^isub>n :: ty\<^isub>i\<^isub>m \<Rightarrow> ty\<^isub>i\<^isub>m \<Rightarrow> bool"}
  1297 
  1292   \end{center}
  1298   \begin{center}
  1293 
  1299   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1294   Given a term-constructor @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}, of a type @{text ty}, two instances
  1300   \multicolumn{2}{l}{@{text "x\<^isub>i"} is a binder:}\\
       
  1301   $\bullet$ & @{text "True"} provided @{text "x\<^isub>i"} is a shallow binder\\
       
  1302   $\bullet$ & @{text "x\<^isub>i \<approx>bn_ty\<^isub>i y\<^isub>i"} provided @{text "x\<^isub>i"} is a deep 
       
  1303      non-recursive binder\\
       
  1304   $\bullet$ & @{text "True"} provided @{text "x\<^isub>i"} is a deep 
       
  1305      recursive binder\\
       
  1306   \end{tabular}
       
  1307   \end{center}
       
  1308 
       
  1309   TODO BELOW
       
  1310 
       
  1311   \begin{center}
       
  1312   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
       
  1313   \multicolumn{2}{l}{@{text "x\<^isub>i"} is a body where the binding clause has mode \isacommand{bind}:}\\
       
  1314   $\bullet$ & @{text "\<exists>p. (bnds_x\<^isub>i, x\<^isub>i) \<approx>lst (\<approx>ty\<^isub>i) fv_ty\<^isub>i p (bnds_y\<^isub>i, y\<^isub>j)"} 
       
  1315      provided @{text "x\<^isub>i"} has only shallow binders; in this case @{text "bnds_x\<^isub>i"} is the
       
  1316      union of all these shallow binders (similarly for @{text "bnds_y\<^isub>i"}\\
       
  1317   $\bullet$ & @{text "\<exists>p. (bn_ty\<^isub>j x\<^isub>j, x\<^isub>i) \<approx>lst (\<approx>ty\<^isub>i) fv_ty\<^isub>i p (bn_ty y\<^isub>j, y\<^isub>i)"} 
       
  1318      provided @{text "x\<^isub>i"} is a body with a deep non-recursive binder @{text x\<^isub>j}
       
  1319      (similarly @{text "y\<^isub>j"} is the deep non-recursive binder for @{text "y\<^isub>i"})\\ 
       
  1320   $\bullet$ & @{text "\<exists>p (bn_ty\<^isub>i x\<^isub>i, (x\<^isub>j, x\<^isub>n)) \<approx>lst R fvs \<pi> (bn\<^isub>m y\<^isub>j, (y\<^isub>j, y\<^isub>n))"}
       
  1321      provided @{text "x\<^isub>j"} is a deep recursive binder with the auxiliary binding
       
  1322      function @{text "bn\<^isub>m"} and permutation @{text "\<pi>"}, @{term "fvs"} is a compound
       
  1323      free variable function returning the union of appropriate @{term "fv_ty\<^isub>x"} and
       
  1324      @{term "R"} is the composition of equivalence relations @{text "\<approx>"} and @{text "\<approx>\<^isub>n"}\\
       
  1325   $\bullet$ & @{text "x\<^isub>j"} has a deep recursive binding\\
       
  1326   $\bullet$ & @{text "({x\<^isub>n}, x\<^isub>j) \<approx>gen R fv_ty \<pi> ({y\<^isub>n}, y\<^isub>j)"} provided @{text "x\<^isub>j"} has
       
  1327      a shallow binder @{text "x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the
       
  1328      alpha-equivalence for @{term "x\<^isub>j"}
       
  1329      and @{term "fv_ty"} is the free-variable function for @{term "x\<^isub>j"}\\
       
  1330   $\bullet$ & @{text "(bn\<^isub>m x\<^isub>n, x\<^isub>j) \<approx>gen R fv_ty \<pi> (bn\<^isub>m y\<^isub>n, y\<^isub>j)"} provided @{text "x\<^isub>j"}
       
  1331      has a deep non-recursive binder @{text "bn\<^isub>m x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the
       
  1332      alpha-equivalence for @{term "x\<^isub>j"}
       
  1333      and @{term "fv_ty"} is the free-variable function for @{term "x\<^isub>j"}\\
       
  1334   $\bullet$ & @{text "x\<^isub>j \<approx>\<^isub>j y\<^isub>j"} provided @{term "x\<^isub>j"} is one of the types being
       
  1335      defined\\
       
  1336   $\bullet$ & @{text "x\<^isub>j = y\<^isub>j"} otherwise\\
       
  1337   \end{tabular}
       
  1338   \end{center}
       
  1339 
       
  1340   , of a type @{text ty}, two instances
  1295   of this constructor are alpha-equivalent @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx> C y\<^isub>1 \<dots> y\<^isub>n"} if there
  1341   of this constructor are alpha-equivalent @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx> C y\<^isub>1 \<dots> y\<^isub>n"} if there
  1296   exist permutations @{text "\<pi>\<^isub>1 \<dots> \<pi>\<^isub>p"} (one for each bound argument) such that
  1342   exist permutations @{text "\<pi>\<^isub>1 \<dots> \<pi>\<^isub>p"} (one for each bound argument) such that
  1297   the conjunction of equivalences defined below for each argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} holds.
  1343   the conjunction of equivalences defined below for each argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} holds.
  1298   For an argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} this holds if:
  1344   For an argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} this holds if:
  1299 
  1345 
  1300   \begin{center}
  1346   
  1301   \begin{tabular}{cp{7cm}}
       
  1302   $\bullet$ & @{text "x\<^isub>j"} is a shallow binder\\
       
  1303   $\bullet$ & @{text "x\<^isub>j \<approx>bn\<^isub>m y\<^isub>j"} provided @{text "x\<^isub>j"} is a deep non-recursive binder
       
  1304      with the auxiliary binding function @{text "bn\<^isub>m"}\\
       
  1305   $\bullet$ & @{term "(bn\<^isub>m x\<^isub>j, (x\<^isub>j, x\<^isub>n)) \<approx>gen R fvs \<pi> (bn\<^isub>m y\<^isub>j, (y\<^isub>j, y\<^isub>n))"}
       
  1306      provided @{term "x\<^isub>j"} is a deep recursive binder with the auxiliary binding
       
  1307      function @{text "bn\<^isub>m"} and permutation @{text "\<pi>"}, @{term "fvs"} is a compound
       
  1308      free variable function returning the union of appropriate @{term "fv_ty\<^isub>x"} and
       
  1309      @{term "R"} is the composition of equivalence relations @{text "\<approx>"} and @{text "\<approx>\<^isub>n"}\\
       
  1310   $\bullet$ & @{text "x\<^isub>j"} has a deep recursive binding\\
       
  1311   $\bullet$ & @{term "({x\<^isub>n}, x\<^isub>j) \<approx>gen R fv_ty \<pi> ({y\<^isub>n}, y\<^isub>j)"} provided @{text "x\<^isub>j"} has
       
  1312      a shallow binder @{text "x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the
       
  1313      alpha-equivalence for @{term "x\<^isub>j"}
       
  1314      and @{term "fv_ty"} is the free variable function for @{term "x\<^isub>j"}\\
       
  1315   $\bullet$ & @{term "(bn\<^isub>m x\<^isub>n, x\<^isub>j) \<approx>gen R fv_ty \<pi> (bn\<^isub>m y\<^isub>n, y\<^isub>j)"} provided @{text "x\<^isub>j"}
       
  1316      has a deep non-recursive binder @{text "bn\<^isub>m x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the
       
  1317      alpha-equivalence for @{term "x\<^isub>j"}
       
  1318      and @{term "fv_ty"} is the free variable function for @{term "x\<^isub>j"}\\
       
  1319   $\bullet$ & @{text "x\<^isub>j \<approx>\<^isub>j y\<^isub>j"} provided @{term "x\<^isub>j"} is one of the types being
       
  1320      defined\\
       
  1321   $\bullet$ & @{text "x\<^isub>j = y\<^isub>j"} otherwise\\
       
  1322   \end{tabular}
       
  1323   \end{center}
       
  1324 
  1347 
  1325   The alpha-equivalence relations for binding functions are similar to the alpha-equivalences
  1348   The alpha-equivalence relations for binding functions are similar to the alpha-equivalences
  1326   for their respective types, the difference is that they ommit checking the arguments that
  1349   for their respective types, the difference is that they ommit checking the arguments that
  1327   are bound. We assumed that there are no bindings in the type on which the binding function
  1350   are bound. We assumed that there are no bindings in the type on which the binding function
  1328   is defined so, there are no permutations involved. For a binding function clause 
  1351   is defined so, there are no permutations involved. For a binding function clause