Paper/Paper.thy
changeset 2516 c86b98642013
parent 2515 06a8f782b2c1
child 2517 e1093e680bcf
equal deleted inserted replaced
2515:06a8f782b2c1 2516:c86b98642013
    85   %
    85   %
    86   \noindent
    86   \noindent
    87   and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of
    87   and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of
    88   type-variables.  While it is possible to implement this kind of more general
    88   type-variables.  While it is possible to implement this kind of more general
    89   binders by iterating single binders, this leads to a rather clumsy
    89   binders by iterating single binders, this leads to a rather clumsy
    90   formalisation of W. The need of iterating single binders is also one reason
    90   formalisation of W. 
    91   why Nominal Isabelle 
    91   %The need of iterating single binders is also one reason
       
    92   %why Nominal Isabelle 
    92   % and similar theorem provers that only provide
    93   % and similar theorem provers that only provide
    93   %mechanisms for binding single variables 
    94   %mechanisms for binding single variables 
    94   has not fared extremely well with the
    95   %has not fared extremely well with the
    95   more advanced tasks in the POPLmark challenge \cite{challenge05}, because
    96   %more advanced tasks in the POPLmark challenge \cite{challenge05}, because
    96   also there one would like to bind multiple variables at once. 
    97   %also there one would like to bind multiple variables at once. 
    97 
    98 
    98   Binding multiple variables has interesting properties that cannot be captured
    99   Binding multiple variables has interesting properties that cannot be captured
    99   easily by iterating single binders. For example in the case of type-schemes we do not
   100   easily by iterating single binders. For example in the case of type-schemes we do not
   100   want to make a distinction about the order of the bound variables. Therefore
   101   want to make a distinction about the order of the bound variables. Therefore
   101   we would like to regard the following two type-schemes as $\alpha$-equivalent
   102   we would like to regard the following two type-schemes as $\alpha$-equivalent
   272   %requires a lot of extra reasoning work.
   273   %requires a lot of extra reasoning work.
   273 
   274 
   274   Although in informal settings a reasoning infrastructure for $\alpha$-equated
   275   Although in informal settings a reasoning infrastructure for $\alpha$-equated
   275   terms is nearly always taken for granted, establishing it automatically in
   276   terms is nearly always taken for granted, establishing it automatically in
   276   the Isabelle/HOL is a rather non-trivial task. For every
   277   the Isabelle/HOL is a rather non-trivial task. For every
   277   specification we will need to construct a type containing as elements the
   278   specification we will need to construct type(s) containing as elements the
   278   $\alpha$-equated terms. To do so, we use the standard HOL-technique of defining
   279   $\alpha$-equated terms. To do so, we use the standard HOL-technique of defining
   279   a new type by identifying a non-empty subset of an existing type.  The
   280   a new type by identifying a non-empty subset of an existing type.  The
   280   construction we perform in Isabelle/HOL can be illustrated by the following picture:
   281   construction we perform in Isabelle/HOL can be illustrated by the following picture:
   281   %
   282   %
   282   \begin{center}
   283   \begin{center}
   307   We take as the starting point a definition of raw terms (defined as a
   308   We take as the starting point a definition of raw terms (defined as a
   308   datatype in Isabelle/HOL); then identify the $\alpha$-equivalence classes in
   309   datatype in Isabelle/HOL); then identify the $\alpha$-equivalence classes in
   309   the type of sets of raw terms according to our $\alpha$-equivalence relation,
   310   the type of sets of raw terms according to our $\alpha$-equivalence relation,
   310   and finally define the new type as these $\alpha$-equivalence classes
   311   and finally define the new type as these $\alpha$-equivalence classes
   311   (non-emptiness is satisfied whenever the raw terms are definable as datatype
   312   (non-emptiness is satisfied whenever the raw terms are definable as datatype
   312   in Isabelle/HOL and the property that our relation for $\alpha$-equivalence is
   313   in Isabelle/HOL and our relation for $\alpha$-equivalence is
   313   indeed an equivalence relation).
   314   an equivalence relation).
   314 
   315 
   315   %The fact that we obtain an isomorphism between the new type and the
   316   %The fact that we obtain an isomorphism between the new type and the
   316   %non-empty subset shows that the new type is a faithful representation of
   317   %non-empty subset shows that the new type is a faithful representation of
   317   %$\alpha$-equated terms. That is not the case for example for terms using the
   318   %$\alpha$-equated terms. That is not the case for example for terms using the
   318   %locally nameless representation of binders \cite{McKinnaPollack99}: in this
   319   %locally nameless representation of binders \cite{McKinnaPollack99}: in this
   377   induction principles that have the variable convention already built in.
   378   induction principles that have the variable convention already built in.
   378   The method behind our specification of general binders is taken 
   379   The method behind our specification of general binders is taken 
   379   from the Ott-tool, but we introduce crucial restrictions, and also extensions, so 
   380   from the Ott-tool, but we introduce crucial restrictions, and also extensions, so 
   380   that our specifications make sense for reasoning about $\alpha$-equated terms.  
   381   that our specifications make sense for reasoning about $\alpha$-equated terms.  
   381   The main improvement over Ott is that we introduce three binding modes
   382   The main improvement over Ott is that we introduce three binding modes
   382   (only one is present in Ott), provide definitions for $\alpha$-equivalence and 
   383   (only one is present in Ott), provide formalised definitions for $\alpha$-equivalence and 
   383   for free variables of our terms, and also derive a reasoning infrastructure
   384   for free variables of our terms, and also derive a reasoning infrastructure
   384   for our specifications inside Isabelle/HOL.
   385   for our specifications inside Isabelle/HOL from ``first principles''.
   385 
   386 
   386 
   387 
   387   %\begin{figure}
   388   %\begin{figure}
   388   %\begin{boxedminipage}{\linewidth}
   389   %\begin{boxedminipage}{\linewidth}
   389   %%\begin{center}
   390   %%\begin{center}
   457   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   458   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   458   operation is defined over the type-hierarchy \cite{HuffmanUrban10};
   459   operation is defined over the type-hierarchy \cite{HuffmanUrban10};
   459   for example permutations acting on products, lists, sets, functions and booleans is
   460   for example permutations acting on products, lists, sets, functions and booleans is
   460   given by:
   461   given by:
   461   %
   462   %
   462   \begin{equation}\label{permute}
   463   %\begin{equation}\label{permute}
   463   \mbox{\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}}
   464   %\mbox{\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}}
       
   465   %\begin{tabular}{@ {}l@ {}}
       
   466   %@{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
       
   467   %@{thm permute_list.simps(1)[no_vars, THEN eq_reflection]}\\
       
   468   %@{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
       
   469   %\end{tabular} &
       
   470   %\begin{tabular}{@ {}l@ {}}
       
   471   %@{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
       
   472   %@{text "p \<bullet> f \<equiv> \<lambda>x. p \<bullet> (f (- p \<bullet> x))"}\\
       
   473   %@{thm permute_bool_def[no_vars, THEN eq_reflection]}
       
   474   %\end{tabular}
       
   475   %\end{tabular}}
       
   476   %\end{equation}
       
   477   %
       
   478   \begin{center}
       
   479   \mbox{\begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {\hspace{4mm}}c@ {}}
   464   \begin{tabular}{@ {}l@ {}}
   480   \begin{tabular}{@ {}l@ {}}
   465   @{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
   481   @{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\
       
   482   @{thm permute_bool_def[no_vars, THEN eq_reflection]}
       
   483   \end{tabular} &
       
   484   \begin{tabular}{@ {}l@ {}}
   466   @{thm permute_list.simps(1)[no_vars, THEN eq_reflection]}\\
   485   @{thm permute_list.simps(1)[no_vars, THEN eq_reflection]}\\
   467   @{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
   486   @{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
   468   \end{tabular} &
   487   \end{tabular} &
   469   \begin{tabular}{@ {}l@ {}}
   488   \begin{tabular}{@ {}l@ {}}
   470   @{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
   489   @{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
   471   @{text "p \<bullet> f \<equiv> \<lambda>x. p \<bullet> (f (- p \<bullet> x))"}\\
   490   @{text "p \<bullet> f \<equiv> \<lambda>x. p \<bullet> (f (- p \<bullet> x))"}\\
   472   @{thm permute_bool_def[no_vars, THEN eq_reflection]}
       
   473   \end{tabular}
   491   \end{tabular}
   474   \end{tabular}}
   492   \end{tabular}}
   475   \end{equation}
   493   \end{center}
   476 
   494 
   477   \noindent
   495   \noindent
   478   Concrete permutations in Nominal Isabelle are built up from swappings, 
   496   Concrete permutations in Nominal Isabelle are built up from swappings, 
   479   written as \mbox{@{text "(a b)"}}, which are permutations that behave 
   497   written as \mbox{@{text "(a b)"}}, which are permutations that behave 
   480   as follows:
   498   as follows:
   502   @{thm (lhs) fresh_star_def[no_vars]}, defined as 
   520   @{thm (lhs) fresh_star_def[no_vars]}, defined as 
   503   @{thm (rhs) fresh_star_def[no_vars]}.
   521   @{thm (rhs) fresh_star_def[no_vars]}.
   504   A striking consequence of these definitions is that we can prove
   522   A striking consequence of these definitions is that we can prove
   505   without knowing anything about the structure of @{term x} that
   523   without knowing anything about the structure of @{term x} that
   506   swapping two fresh atoms, say @{text a} and @{text b}, leaves 
   524   swapping two fresh atoms, say @{text a} and @{text b}, leaves 
   507   @{text x} unchanged:
   525   @{text x} unchanged, namely if @{text "a \<FRESH> x"} and @{text "b \<FRESH> x"}
   508 
   526   then @{term "(a \<rightleftharpoons> b) \<bullet> x"}.
   509   \begin{myproperty}\label{swapfreshfresh}
   527 
   510   @{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
   528   %\begin{myproperty}\label{swapfreshfresh}
   511   \end{myproperty}
   529   %@{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
       
   530   %\end{myproperty}
   512 
   531 
   513   %While often the support of an object can be relatively easily 
   532   %While often the support of an object can be relatively easily 
   514   %described, for example for atoms, products, lists, function applications, 
   533   %described, for example for atoms, products, lists, function applications, 
   515   %booleans and permutations as follows
   534   %booleans and permutations as follows
   516   %%
   535   %%
   627   from this specification (remember that Nominal Isabelle is a definitional
   646   from this specification (remember that Nominal Isabelle is a definitional
   628   extension of Isabelle/HOL, which does not introduce any new axioms).
   647   extension of Isabelle/HOL, which does not introduce any new axioms).
   629 
   648 
   630   In order to keep our work with deriving the reasoning infrastructure
   649   In order to keep our work with deriving the reasoning infrastructure
   631   manageable, we will wherever possible state definitions and perform proofs
   650   manageable, we will wherever possible state definitions and perform proofs
   632   on the ``user-level'' of Isabelle/HOL, as opposed to write custom ML-code that
   651   on the ``user-level'' of Isabelle/HOL, as opposed to write custom ML-code. % that
   633   generates them anew for each specification. To that end, we will consider
   652   %generates them anew for each specification. 
       
   653   To that end, we will consider
   634   first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.  These pairs
   654   first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.  These pairs
   635   are intended to represent the abstraction, or binding, of the set of atoms @{text
   655   are intended to represent the abstraction, or binding, of the set of atoms @{text
   636   "as"} in the body @{text "x"}.
   656   "as"} in the body @{text "x"}.
   637 
   657 
   638   The first question we have to answer is when two pairs @{text "(as, x)"} and
   658   The first question we have to answer is when two pairs @{text "(as, x)"} and
   655        \mbox{\it (iii)} &  @{text "(p \<bullet> x) R y"} \\
   675        \mbox{\it (iii)} &  @{text "(p \<bullet> x) R y"} \\
   656        \mbox{\it (ii)}  & @{term "(fa(x) - as) \<sharp>* p"} & 
   676        \mbox{\it (ii)}  & @{term "(fa(x) - as) \<sharp>* p"} & 
   657        \mbox{\it (iv)}  & @{term "(p \<bullet> as) = bs"} \\ 
   677        \mbox{\it (iv)}  & @{term "(p \<bullet> as) = bs"} \\ 
   658   \end{array}
   678   \end{array}
   659   \end{equation}
   679   \end{equation}
   660 
   680   %
   661   \noindent
   681   \noindent
   662   Note that this relation depends on the permutation @{text
   682   Note that this relation depends on the permutation @{text
   663   "p"}; $\alpha$-equivalence between two pairs is then the relation where we
   683   "p"}; $\alpha$-equivalence between two pairs is then the relation where we
   664   existentially quantify over this @{text "p"}. Also note that the relation is
   684   existentially quantify over this @{text "p"}. Also note that the relation is
   665   dependent on a free-atom function @{text "fa"} and a relation @{text
   685   dependent on a free-atom function @{text "fa"} and a relation @{text
   680          \mbox{\it (iii)} & @{text "(p \<bullet> x) R y"}\\
   700          \mbox{\it (iii)} & @{text "(p \<bullet> x) R y"}\\
   681          \mbox{\it (ii)}  & @{term "(fa(x) - set as) \<sharp>* p"} &
   701          \mbox{\it (ii)}  & @{term "(fa(x) - set as) \<sharp>* p"} &
   682          \mbox{\it (iv)}  & @{term "(p \<bullet> as) = bs"}\\
   702          \mbox{\it (iv)}  & @{term "(p \<bullet> as) = bs"}\\
   683   \end{array}
   703   \end{array}
   684   \end{equation}
   704   \end{equation}
   685   
   705   %
   686   \noindent
   706   \noindent
   687   where @{term set} is the function that coerces a list of atoms into a set of atoms.
   707   where @{term set} is the function that coerces a list of atoms into a set of atoms.
   688   Now the last clause ensures that the order of the binders matters (since @{text as}
   708   Now the last clause ensures that the order of the binders matters (since @{text as}
   689   and @{text bs} are lists of atoms).
   709   and @{text bs} are lists of atoms).
   690 
   710 
   699              \mbox{\it (iii)} & @{text "(p \<bullet> x) R y"}\\
   719              \mbox{\it (iii)} & @{text "(p \<bullet> x) R y"}\\
   700              \mbox{\it (ii)}  & @{term "(fa(x) - as) \<sharp>* p"}\\
   720              \mbox{\it (ii)}  & @{term "(fa(x) - as) \<sharp>* p"}\\
   701   \end{array}
   721   \end{array}
   702   \end{equation}
   722   \end{equation}
   703 
   723 
   704   It might be useful to consider first some examples about how these definitions
   724   It might be useful to consider first some examples how these definitions
   705   of $\alpha$-equivalence pan out in practice.  For this consider the case of
   725   of $\alpha$-equivalence pan out in practice.  For this consider the case of
   706   abstracting a set of atoms over types (as in type-schemes). We set
   726   abstracting a set of atoms over types (as in type-schemes). We set
   707   @{text R} to be the usual equality @{text "="} and for @{text "fa(T)"} we
   727   @{text R} to be the usual equality @{text "="} and for @{text "fa(T)"} we
   708   define
   728   define
   709 
   729   %
   710   \begin{center}
   730   \begin{center}
   711   @{text "fa(x) = {x}"}  \hspace{5mm} @{text "fa(T\<^isub>1 \<rightarrow> T\<^isub>2) = fa(T\<^isub>1) \<union> fa(T\<^isub>2)"}
   731   @{text "fa(x) = {x}"}  \hspace{5mm} @{text "fa(T\<^isub>1 \<rightarrow> T\<^isub>2) = fa(T\<^isub>1) \<union> fa(T\<^isub>2)"}
   712   \end{center}
   732   \end{center}
   713 
   733 
   714   \noindent
   734   \noindent
  1047   \isacommand{where}~@{text "bn(PNil) = []"}\\
  1067   \isacommand{where}~@{text "bn(PNil) = []"}\\
  1048   \hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\
  1068   \hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\
  1049   \hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\ 
  1069   \hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\ 
  1050   \end{tabular}}
  1070   \end{tabular}}
  1051   \end{equation}
  1071   \end{equation}
  1052   
  1072   %
  1053   \noindent
  1073   \noindent
  1054   In this specification the function @{text "bn"} determines which atoms of
  1074   In this specification the function @{text "bn"} determines which atoms of
  1055   the pattern @{text p} are bound in the argument @{text "t"}. Note that in the
  1075   the pattern @{text p} are bound in the argument @{text "t"}. Note that in the
  1056   second-last @{text bn}-clause the function @{text "atom"} coerces a name
  1076   second-last @{text bn}-clause the function @{text "atom"} coerces a name
  1057   into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This
  1077   into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This
  1058   allows us to treat binders of different atom type uniformly.
  1078   allows us to treat binders of different atom type uniformly.
  1059 
  1079 
  1060   As said above, for deep binders we allow binding clauses such as
  1080   As said above, for deep binders we allow binding clauses such as
  1061   %
  1081   %
  1062   \begin{center}
  1082   %\begin{center}
  1063   \begin{tabular}{ll}
  1083   %\begin{tabular}{ll}
  1064   @{text "Bar p::pat t::trm"} &  
  1084   @{text "Bar p::pat t::trm"} %%%&  
  1065      \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p t"}\\
  1085      \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p t"} %%\\
  1066   \end{tabular}
  1086   %\end{tabular}
  1067   \end{center}
  1087   %\end{center}
  1068 
  1088   %
  1069   \noindent
  1089   %\noindent
  1070   where the argument of the deep binder also occurs in the body. We call such
  1090   where the argument of the deep binder also occurs in the body. We call such
  1071   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1091   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1072   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1092   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1073   specification:
  1093   specification:
  1074   %
  1094   %
  1086   \isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\
  1106   \isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\
  1087   \isacommand{where}~@{text "bn(ANil) = []"}\\
  1107   \isacommand{where}~@{text "bn(ANil) = []"}\\
  1088   \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\
  1108   \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\
  1089   \end{tabular}}
  1109   \end{tabular}}
  1090   \end{equation}
  1110   \end{equation}
  1091 
  1111   %
  1092   \noindent
  1112   \noindent
  1093   The difference is that with @{text Let} we only want to bind the atoms @{text
  1113   The difference is that with @{text Let} we only want to bind the atoms @{text
  1094   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1114   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1095   inside the assignment. This difference has consequences for the associated
  1115   inside the assignment. This difference has consequences for the associated
  1096   notions of free-atoms and $\alpha$-equivalence.
  1116   notions of free-atoms and $\alpha$-equivalence.
  1097   
  1117   
  1098   To make sure that atoms bound by deep binders cannot be free at the
  1118   To make sure that atoms bound by deep binders cannot be free at the
  1099   same time, we cannot have more than one binding function for a deep binder. 
  1119   same time, we cannot have more than one binding function for a deep binder. 
  1100   Consequently we exclude specifications such as
  1120   Consequently we exclude specifications such as
  1101 
  1121   %
  1102   \begin{center}
  1122   \begin{center}
  1103   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  1123   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  1104   @{text "Baz\<^isub>1 p::pat t::trm"} & 
  1124   @{text "Baz\<^isub>1 p::pat t::trm"} & 
  1105      \isacommand{bind} @{text "bn\<^isub>1(p) bn\<^isub>2(p)"} \isacommand{in} @{text t}\\
  1125      \isacommand{bind} @{text "bn\<^isub>1(p) bn\<^isub>2(p)"} \isacommand{in} @{text t}\\
  1106   @{text "Baz\<^isub>2 p::pat t\<^isub>1::trm t\<^isub>2::trm"} & 
  1126   @{text "Baz\<^isub>2 p::pat t\<^isub>1::trm t\<^isub>2::trm"} & 
  1242   either refer to labels of atom types (in case of shallow binders) or to binding 
  1262   either refer to labels of atom types (in case of shallow binders) or to binding 
  1243   functions taking a single label as argument (in case of deep binders). Assuming 
  1263   functions taking a single label as argument (in case of deep binders). Assuming 
  1244   @{text "D"} stands for the set of free atoms of the bodies, @{text B} for the 
  1264   @{text "D"} stands for the set of free atoms of the bodies, @{text B} for the 
  1245   set of binding atoms in the binders and @{text "B'"} for the set of free atoms in 
  1265   set of binding atoms in the binders and @{text "B'"} for the set of free atoms in 
  1246   non-recursive deep binders,
  1266   non-recursive deep binders,
  1247   then the free atoms of the binding clause @{text bc\<^isub>i} are
  1267   then the free atoms of the binding clause @{text bc\<^isub>i} are\\[-2mm]
  1248   %
  1268   %
  1249   \begin{equation}\label{fadef}
  1269   \begin{equation}\label{fadef}
  1250   \mbox{@{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}}.
  1270   \mbox{@{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}}.
  1251   \end{equation}
  1271   \end{equation}
  1252 
  1272   %
  1253   \noindent
  1273   \noindent
  1254   The set @{text D} is formally defined as
  1274   The set @{text D} is formally defined as
  1255   %
  1275   %
  1256   \begin{center}
  1276   %\begin{center}
  1257   @{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"}
  1277   @{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"}
  1258   \end{center} 
  1278   %\end{center} 
  1259 
  1279   %
  1260   \noindent
  1280   %\noindent
  1261   where in case @{text "d\<^isub>i"} refers to one of the raw types @{text "ty"}$_{1..n}$ from the 
  1281   where in case @{text "d\<^isub>i"} refers to one of the raw types @{text "ty"}$_{1..n}$ from the 
  1262   specification, the function @{text "fa_ty\<^isub>i"} is the corresponding free-atom function 
  1282   specification, the function @{text "fa_ty\<^isub>i"} is the corresponding free-atom function 
  1263   we are defining by recursion; 
  1283   we are defining by recursion; 
  1264   %(see \eqref{fvars}); 
  1284   %(see \eqref{fvars}); 
  1265   otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}.
  1285   otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}.
  1266   
  1286   
  1267   In order to formally define the set @{text B} we use the following auxiliary @{text "bn"}-functions
  1287   In order to formally define the set @{text B} we use the following auxiliary @{text "bn"}-functions
  1268   for atom types to which shallow binders may refer
  1288   for atom types to which shallow binders may refer\\[-4mm]
  1269   %
  1289   %
  1270   %\begin{center}
  1290   %\begin{center}
  1271   %\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1291   %\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1272   %@{text "bn_atom a"} & @{text "\<equiv>"} & @{text "{atom a}"}\\
  1292   %@{text "bn_atom a"} & @{text "\<equiv>"} & @{text "{atom a}"}\\
  1273   %@{text "bn_atom_set as"} & @{text "\<equiv>"} & @{text "atoms as"}\\
  1293   %@{text "bn_atom_set as"} & @{text "\<equiv>"} & @{text "atoms as"}\\
  1274   %@{text "bn_atom_list as"} & @{text "\<equiv>"} & @{text "atoms (set as)"}
  1294   %@{text "bn_atom_list as"} & @{text "\<equiv>"} & @{text "atoms (set as)"}
  1275   %\end{tabular}
  1295   %\end{tabular}
  1276   %\end{center}
  1296   %\end{center}
  1277   %
  1297   %
  1278   \begin{center}
  1298   \begin{center}
  1279   @{text "bn_atom a \<equiv> {atom a}"}\hspace{17mm}
  1299   @{text "bn\<^bsub>atom\<^esub> a \<equiv> {atom a}"}\hfill
  1280   @{text "bn_atom_set as \<equiv> atoms as"}\\
  1300   @{text "bn\<^bsub>atom_set\<^esub> as \<equiv> atoms as"}\hfill
  1281   @{text "bn_atom_list as \<equiv> atoms (set as)"}
  1301   @{text "bn\<^bsub>atom_list\<^esub> as \<equiv> atoms (set as)"}
  1282   \end{center}
  1302   \end{center}
  1283 
  1303   %
  1284   \noindent 
  1304   \noindent 
  1285   Like the function @{text atom}, the function @{text "atoms"} coerces 
  1305   Like the function @{text atom}, the function @{text "atoms"} coerces 
  1286   a set of atoms to a set of the generic atom type. 
  1306   a set of atoms to a set of the generic atom type. 
  1287   %It is defined as  @{text "atoms as \<equiv> {atom a | a \<in> as}"}. 
  1307   %It is defined as  @{text "atoms as \<equiv> {atom a | a \<in> as}"}. 
  1288   The set @{text B} is then formally defined as
  1308   The set @{text B} is then formally defined as\\[-4mm]
  1289   %
  1309   %
  1290   \begin{center}
  1310   \begin{center}
  1291   @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"}
  1311   @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"}
  1292   \end{center} 
  1312   \end{center} 
  1293 
  1313   %
  1294   \noindent 
  1314   \noindent 
  1295   where we use the auxiliary binding functions for shallow binders. 
  1315   where we use the auxiliary binding functions for shallow binders. 
  1296   The set @{text "B'"} collects all free atoms in non-recursive deep
  1316   The set @{text "B'"} collects all free atoms in non-recursive deep
  1297   binders. Let us assume these binders in @{text "bc\<^isub>i"} are
  1317   binders. Let us assume these binders in @{text "bc\<^isub>i"} are
  1298   %
  1318   %
  1301   %\end{center}
  1321   %\end{center}
  1302   %
  1322   %
  1303   %\noindent
  1323   %\noindent
  1304   with @{text "l"}$_{1..r}$ $\subseteq$ @{text "b"}$_{1..p}$ and none of the 
  1324   with @{text "l"}$_{1..r}$ $\subseteq$ @{text "b"}$_{1..p}$ and none of the 
  1305   @{text "l"}$_{1..r}$ being among the bodies @{text
  1325   @{text "l"}$_{1..r}$ being among the bodies @{text
  1306   "d"}$_{1..q}$. The set @{text "B'"} is defined as
  1326   "d"}$_{1..q}$. The set @{text "B'"} is defined as\\[-5mm]
  1307   %
  1327   %
  1308   \begin{center}
  1328   \begin{center}
  1309   @{text "B' \<equiv> fa_bn\<^isub>1 l\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r l\<^isub>r"}
  1329   @{text "B' \<equiv> fa_bn\<^isub>1 l\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r l\<^isub>r"}\\[-9mm]
  1310   \end{center} 
  1330   \end{center}
  1311 
  1331   %
  1312   \noindent
  1332   \noindent
  1313   This completes the definition of the free-atom functions @{text "fa_ty"}$_{1..n}$.
  1333   This completes the definition of the free-atom functions @{text "fa_ty"}$_{1..n}$.
  1314 
  1334 
  1315   Note that for non-recursive deep binders, we have to add in \eqref{fadef}
  1335   Note that for non-recursive deep binders, we have to add in \eqref{fadef}
  1316   the set of atoms that are left unbound by the binding functions @{text
  1336   the set of atoms that are left unbound by the binding functions @{text
  1363 
  1383 
  1364   \noindent
  1384   \noindent
  1365   Recall that @{text ANil} and @{text "ACons"} have no
  1385   Recall that @{text ANil} and @{text "ACons"} have no
  1366   binding clause in the specification. The corresponding free-atom
  1386   binding clause in the specification. The corresponding free-atom
  1367   function @{text "fa\<^bsub>assn\<^esub>"} therefore returns all free atoms
  1387   function @{text "fa\<^bsub>assn\<^esub>"} therefore returns all free atoms
  1368   occurring in an assignment (in case of @{text "ACons"}, they are given in
  1388   of an assignment (in case of @{text "ACons"}, they are given in
  1369   terms of @{text supp}, @{text "fa\<^bsub>trm\<^esub>"} and @{text "fa\<^bsub>assn\<^esub>"}). 
  1389   terms of @{text supp}, @{text "fa\<^bsub>trm\<^esub>"} and @{text "fa\<^bsub>assn\<^esub>"}). 
  1370   The binding only takes place in @{text Let} and
  1390   The binding only takes place in @{text Let} and
  1371   @{text "Let_rec"}. In case of @{text "Let"}, the binding clause specifies
  1391   @{text "Let_rec"}. In case of @{text "Let"}, the binding clause specifies
  1372   that all atoms given by @{text "set (bn as)"} have to be bound in @{text
  1392   that all atoms given by @{text "set (bn as)"} have to be bound in @{text
  1373   t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
  1393   t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
  1986   permutes names bound by @{text bn} and leaves the other names unchanged. We do this again
  2006   permutes names bound by @{text bn} and leaves the other names unchanged. We do this again
  1987   by lifting. Assuming a
  2007   by lifting. Assuming a
  1988   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}, we define 
  2008   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}, we define 
  1989   %
  2009   %
  1990   \begin{center}
  2010   \begin{center}
  1991   @{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"} 
  2011   @{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"} \;\; with
  1992   \end{center}
  2012   $\begin{cases}
  1993   %
  2013   \text{@{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}}\\
  1994   \noindent
  2014   \text{@{text "y\<^isub>i \<equiv> p \<bullet>\<^bsub>bn'\<^esub> x\<^isub>i"} provided @{text "bn' x\<^isub>i"} is in @{text "rhs"}}\\
  1995   with @{text "y\<^isub>i"} determined as follows:
  2015   \text{@{text "y\<^isub>i \<equiv> p \<bullet> x\<^isub>i"} otherwise}  
  1996   %
  2016   \end{cases}$
  1997   \begin{center}
  2017   \end{center}
  1998   \begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
  2018   %
  1999   $\bullet$ & @{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}\\
  2019   %\noindent
  2000   $\bullet$ & @{text "y\<^isub>i \<equiv> p \<bullet>\<^bsub>bn'\<^esub> x\<^isub>i"} provided @{text "bn' x\<^isub>i"} is in @{text "rhs"}\\
  2020   %with @{text "y\<^isub>i"} determined as follows:
  2001   $\bullet$ & @{text "y\<^isub>i \<equiv> p \<bullet> x\<^isub>i"} otherwise
  2021   %
  2002   \end{tabular}
  2022   %\begin{center}
  2003   \end{center}
  2023   %\begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
  2004   %
  2024   %$\bullet$ & @{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}\\
       
  2025   %$\bullet$ & @{text "y\<^isub>i \<equiv> p \<bullet>\<^bsub>bn'\<^esub> x\<^isub>i"} provided @{text "bn' x\<^isub>i"} is in @{text "rhs"}\\
       
  2026   %$\bullet$ & @{text "y\<^isub>i \<equiv> p \<bullet> x\<^isub>i"} otherwise
       
  2027   %\end{tabular}
       
  2028   %\end{center}
       
  2029   %
       
  2030   \noindent
  2005   Now Properties \ref{supppermeq} and \ref{avoiding} give us a permutation @{text q} such that
  2031   Now Properties \ref{supppermeq} and \ref{avoiding} give us a permutation @{text q} such that
  2006   @{text "(set (bn (q \<bullet>\<^bsub>bn\<^esub> p)) \<FRESH>\<^sup>* c"} holds and such that @{text "[q \<bullet>\<^bsub>bn\<^esub> p]\<^bsub>list\<^esub>.(q \<bullet> t)"}
  2032   @{text "(set (bn (q \<bullet>\<^bsub>bn\<^esub> p)) \<FRESH>\<^sup>* c"} holds and such that @{text "[q \<bullet>\<^bsub>bn\<^esub> p]\<^bsub>list\<^esub>.(q \<bullet> t)"}
  2007   is equal to @{text "[p]\<^bsub>list\<^esub>. t"}. We can also show that @{text "(q \<bullet>\<^bsub>bn\<^esub> p) \<approx>\<^bsub>bn\<^esub> p"}. But
  2033   is equal to @{text "[p]\<^bsub>list\<^esub>. t"}. We can also show that @{text "(q \<bullet>\<^bsub>bn\<^esub> p) \<approx>\<^bsub>bn\<^esub> p"}. But
  2008   these facts establish that @{text "Let (q \<bullet>\<^bsub>bn\<^esub> p) (p \<bullet> t) = Let p t"}, as we need. This
  2034   these facts establish that @{text "Let (q \<bullet>\<^bsub>bn\<^esub> p) (p \<bullet> t) = Let p t"}, as we need. This
  2009   completes the interesting cases in \eqref{letpat} for strengthening the induction
  2035   completes the interesting cases in \eqref{letpat} for strengthening the induction
  2184   order of binders should matter, or vacuous binders should be taken into
  2210   order of binders should matter, or vacuous binders should be taken into
  2185   account). %To do so, one would require additional predicates that filter out
  2211   account). %To do so, one would require additional predicates that filter out
  2186   %unwanted terms. Our guess is that such predicates result in rather
  2212   %unwanted terms. Our guess is that such predicates result in rather
  2187   %intricate formal reasoning.
  2213   %intricate formal reasoning.
  2188 
  2214 
  2189   Another representation technique for binding is higher-order abstract syntax
  2215   Another technique for representing binding is higher-order abstract syntax
  2190   (HOAS), which for example is implemented in the Twelf system. This representation
  2216   (HOAS). %, which for example is implemented in the Twelf system. 
       
  2217   This %%representation
  2191   technique supports very elegantly many aspects of \emph{single} binding, and
  2218   technique supports very elegantly many aspects of \emph{single} binding, and
  2192   impressive work has been done that uses HOAS for mechanising the metatheory
  2219   impressive work has been done that uses HOAS for mechanising the metatheory
  2193   of SML~\cite{LeeCraryHarper07}. We are, however, not aware how multiple
  2220   of SML~\cite{LeeCraryHarper07}. We are, however, not aware how multiple
  2194   binders of SML are represented in this work. Judging from the submitted
  2221   binders of SML are represented in this work. Judging from the submitted
  2195   Twelf-solution for the POPLmark challenge, HOAS cannot easily deal with
  2222   Twelf-solution for the POPLmark challenge, HOAS cannot easily deal with
  2196   binding constructs where the number of bound variables is not fixed. For
  2223   binding constructs where the number of bound variables is not fixed. %For
  2197   example in the second part of this challenge, @{text "Let"}s involve
  2224   example 
       
  2225   In the second part of this challenge, @{text "Let"}s involve
  2198   patterns that bind multiple variables at once. In such situations, HOAS
  2226   patterns that bind multiple variables at once. In such situations, HOAS
  2199   representations have to resort to the iterated-single-binders-approach with
  2227   seems to have to resort to the iterated-single-binders-approach with
  2200   all the unwanted consequences when reasoning about the resulting terms.
  2228   all the unwanted consequences when reasoning about the resulting terms.
  2201 
  2229 
  2202   %Two formalisations involving general binders have been 
  2230   %Two formalisations involving general binders have been 
  2203   %performed in older
  2231   %performed in older
  2204   %versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W 
  2232   %versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W 
  2222   rather different from ours, not using any nominal techniques.  To our
  2250   rather different from ours, not using any nominal techniques.  To our
  2223   knowledge there is also no concrete mathematical result concerning this
  2251   knowledge there is also no concrete mathematical result concerning this
  2224   notion of $\alpha$-equivalence.  A definition for the notion of free variables
  2252   notion of $\alpha$-equivalence.  A definition for the notion of free variables
  2225   is work in progress in Ott.
  2253   is work in progress in Ott.
  2226 
  2254 
  2227   Although we were heavily inspired by the syntax in Ott,
  2255   Although we were heavily inspired by the syntax of Ott,
  2228   its definition of $\alpha$-equivalence is unsuitable for our extension of
  2256   its definition of $\alpha$-equivalence is unsuitable for our extension of
  2229   Nominal Isabelle. First, it is far too complicated to be a basis for
  2257   Nominal Isabelle. First, it is far too complicated to be a basis for
  2230   automated proofs implemented on the ML-level of Isabelle/HOL. Second, it
  2258   automated proofs implemented on the ML-level of Isabelle/HOL. Second, it
  2231   covers cases of binders depending on other binders, which just do not make
  2259   covers cases of binders depending on other binders, which just do not make
  2232   sense for our $\alpha$-equated terms. Third, it allows empty types that have no
  2260   sense for our $\alpha$-equated terms. Third, it allows empty types that have no
  2292   $\alpha$-equivalence related to our binding mode \isacommand{bind (res)}.
  2320   $\alpha$-equivalence related to our binding mode \isacommand{bind (res)}.
  2293   The definition in \cite{Altenkirch10} is similar to the one by Pottier, except that it
  2321   The definition in \cite{Altenkirch10} is similar to the one by Pottier, except that it
  2294   has a more operational flavour and calculates a partial (renaming) map. 
  2322   has a more operational flavour and calculates a partial (renaming) map. 
  2295   In this way, the definition can deal with vacuous binders. However, to our
  2323   In this way, the definition can deal with vacuous binders. However, to our
  2296   best knowledge, no concrete mathematical result concerning this
  2324   best knowledge, no concrete mathematical result concerning this
  2297   definition of $\alpha$-equivalence has been proved.    
  2325   definition of $\alpha$-equivalence has been proved.\\[-7mm]    
  2298 *}
  2326 *}
  2299 
  2327 
  2300 section {* Conclusion *}
  2328 section {* Conclusion *}
  2301 
  2329 
  2302 text {*
  2330 text {*
  2319   We have left out a discussion about how functions can be defined over
  2347   We have left out a discussion about how functions can be defined over
  2320   $\alpha$-equated terms involving general binders. In earlier versions of Nominal
  2348   $\alpha$-equated terms involving general binders. In earlier versions of Nominal
  2321   Isabelle \cite{UrbanBerghofer06} this turned out to be a thorny issue.  We
  2349   Isabelle \cite{UrbanBerghofer06} this turned out to be a thorny issue.  We
  2322   hope to do better this time by using the function package that has recently
  2350   hope to do better this time by using the function package that has recently
  2323   been implemented in Isabelle/HOL and also by restricting function
  2351   been implemented in Isabelle/HOL and also by restricting function
  2324   definitions to equivariant functions (for such functions it is possible to
  2352   definitions to equivariant functions (for such functions we can
  2325   provide more automation).
  2353   provide more automation).
  2326 
  2354 
  2327   %There are some restrictions we imposed in this paper that we would like to lift in
  2355   %There are some restrictions we imposed in this paper that we would like to lift in
  2328   %future work. One is the exclusion of nested datatype definitions. Nested
  2356   %future work. One is the exclusion of nested datatype definitions. Nested
  2329   %datatype definitions allow one to specify, for instance, the function kinds
  2357   %datatype definitions allow one to specify, for instance, the function kinds
  2347   %We have also not yet played with other binding modes. For example we can
  2375   %We have also not yet played with other binding modes. For example we can
  2348   %imagine that there is need for a binding mode 
  2376   %imagine that there is need for a binding mode 
  2349   %where instead of lists, we abstract lists of distinct elements.
  2377   %where instead of lists, we abstract lists of distinct elements.
  2350   %Once we feel confident about such binding modes, our implementation 
  2378   %Once we feel confident about such binding modes, our implementation 
  2351   %can be easily extended to accommodate them.
  2379   %can be easily extended to accommodate them.
  2352 
  2380   %
  2353   \medskip
  2381   \smallskip
  2354   \noindent
  2382   \noindent
  2355   {\bf Acknowledgements:} %We are very grateful to Andrew Pitts for  
  2383   {\bf Acknowledgements:} %We are very grateful to Andrew Pitts for  
  2356   %many discussions about Nominal Isabelle. 
  2384   %many discussions about Nominal Isabelle. 
  2357   We thank Peter Sewell for 
  2385   We thank Peter Sewell for 
  2358   making the informal notes \cite{SewellBestiary} available to us and 
  2386   making the informal notes \cite{SewellBestiary} available to us and 
  2359   also for patiently explaining some of the finer points of the work on the Ott-tool.
  2387   also for patiently explaining some of the finer points of the work on the Ott-tool.
  2360   %Stephanie Weirich suggested to separate the subgrammars
  2388   %Stephanie Weirich suggested to separate the subgrammars
  2361   %of kinds and types in our Core-Haskell example.  
  2389   %of kinds and types in our Core-Haskell example. \\[-6mm] 
  2362 
  2390 
  2363 *}
  2391 *}
  2364 
  2392 
  2365 (*<*)
  2393 (*<*)
  2366 end
  2394 end