Paper/Paper.thy
changeset 2343 36aeb97fabb0
parent 2342 f296ef291ca9
child 2344 e90f6a26d74b
equal deleted inserted replaced
2342:f296ef291ca9 2343:36aeb97fabb0
    44 
    44 
    45 text {*
    45 text {*
    46 %%%  @{text "(1, (2, 3))"}
    46 %%%  @{text "(1, (2, 3))"}
    47 
    47 
    48   So far, Nominal Isabelle provides a mechanism for constructing
    48   So far, Nominal Isabelle provides a mechanism for constructing
    49   $\alpha$-equated terms, for example
    49   $\alpha$-equated terms, for example lambda-terms
    50 
    50 
    51   \begin{center}
    51   \begin{center}
    52   @{text "t ::= x | t t | \<lambda>x. t"}
    52   @{text "t ::= x | t t | \<lambda>x. t"}
    53   \end{center}
    53   \end{center}
    54 
    54 
   363   inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
   363   inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
   364   proofs, we establish a reasoning infrastructure for $\alpha$-equated
   364   proofs, we establish a reasoning infrastructure for $\alpha$-equated
   365   terms, including properties about support, freshness and equality
   365   terms, including properties about support, freshness and equality
   366   conditions for $\alpha$-equated terms. We are also able to derive strong 
   366   conditions for $\alpha$-equated terms. We are also able to derive strong 
   367   induction principles that have the variable convention already built in.
   367   induction principles that have the variable convention already built in.
   368   The concepts behind our specifications of general binders are taken 
   368   The method behind our specification of general binders is taken 
   369   from the Ott-tool, but we introduce restrictions, and also one extension, so 
   369   from the Ott-tool, but we introduce restrictions, and also one extension, so 
   370   that the specifications make sense for reasoning about $\alpha$-equated terms. 
   370   that our specifications make sense for reasoning about $\alpha$-equated terms. 
   371 
   371 
   372 
   372 
   373   \begin{figure}
   373   \begin{figure}
   374   \begin{boxedminipage}{\linewidth}
   374   \begin{boxedminipage}{\linewidth}
   375   \begin{center}
   375   \begin{center}
   565   %
   565   %
   566   \begin{center}
   566   \begin{center}
   567   @{text "x R y"} \;\;\textit{implies}\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"}
   567   @{text "x R y"} \;\;\textit{implies}\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"}
   568   \end{center}
   568   \end{center}
   569 
   569 
   570   Finally, the nominal logic work provides us with general means to rename 
   570   Finally, the nominal logic work provides us with general means for renaming 
   571   binders. While in the older version of Nominal Isabelle, we used extensively 
   571   binders. While in the older version of Nominal Isabelle, we used extensively 
   572   Property~\ref{swapfreshfresh} for renaming single binders, this property 
   572   Property~\ref{swapfreshfresh} to rename single binders, this property 
   573   proved too unwieldy for dealing with multiple binders. For such binders the 
   573   proved too unwieldy for dealing with multiple binders. For such binders the 
   574   following generalisations turned out to be easier to use.
   574   following generalisations turned out to be easier to use.
   575 
   575 
   576   \begin{property}\label{supppermeq}
   576   \begin{property}\label{supppermeq}
   577   @{thm[mode=IfThen] supp_perm_eq[no_vars]}
   577   @{thm[mode=IfThen] supp_perm_eq[no_vars]}
   626   variables; moreover there must be a permutation @{text p} such that {\it
   626   variables; moreover there must be a permutation @{text p} such that {\it
   627   (ii)} @{text p} leaves the free variables of @{text x} and @{text y} unchanged, but
   627   (ii)} @{text p} leaves the free variables of @{text x} and @{text y} unchanged, but
   628   {\it (iii)} ``moves'' their bound names so that we obtain modulo a relation,
   628   {\it (iii)} ``moves'' their bound names so that we obtain modulo a relation,
   629   say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
   629   say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
   630   @{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
   630   @{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
   631   requirements {\it i)} to {\it iv)} can be stated formally as follows:
   631   requirements {\it (i)} to {\it (iv)} can be stated formally as follows:
   632   %
   632   %
   633   \begin{equation}\label{alphaset}
   633   \begin{equation}\label{alphaset}
   634   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   634   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   635   \multicolumn{3}{l}{@{term "(as, x) \<approx>gen R fv p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   635   \multicolumn{3}{l}{@{term "(as, x) \<approx>gen R fv p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   636               & @{term "fv(x) - as = fv(y) - bs"} & \mbox{\it (i)}\\
   636               & @{term "fv(x) - as = fv(y) - bs"} & \mbox{\it (i)}\\
   737   proof obligation use @{text "q + p"}. All conditions are then by simple
   737   proof obligation use @{text "q + p"}. All conditions are then by simple
   738   calculations. 
   738   calculations. 
   739   \end{proof}
   739   \end{proof}
   740 
   740 
   741   \noindent
   741   \noindent
   742   This lemma allows us to use our quotient package and introduce 
   742   This lemma allows us to use our quotient package for introducing 
   743   new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"}
   743   new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"}
   744   representing $\alpha$-equivalence classes of pairs of type 
   744   representing $\alpha$-equivalence classes of pairs of type 
   745   @{text "(atom set) \<times> \<beta>"} (in the first two cases) and of type @{text "(atom list) \<times> \<beta>"}
   745   @{text "(atom set) \<times> \<beta>"} (in the first two cases) and of type @{text "(atom list) \<times> \<beta>"}
   746   (in the third case). 
   746   (in the third case). 
   747   The elements in these types will be, respectively, written as:
   747   The elements in these types will be, respectively, written as:
   911   (possibly empty) list of \emph{binding clauses}, which indicate the binders
   911   (possibly empty) list of \emph{binding clauses}, which indicate the binders
   912   and their scope in a term-constructor.  They come in three \emph{modes}:
   912   and their scope in a term-constructor.  They come in three \emph{modes}:
   913 
   913 
   914   \begin{center}
   914   \begin{center}
   915   \begin{tabular}{l}
   915   \begin{tabular}{l}
   916   \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it labels}\\
   916   \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   917   \isacommand{bind\_set}\; {\it binders}\; \isacommand{in}\; {\it labels}\\
   917   \isacommand{bind\_set}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   918   \isacommand{bind\_res}\; {\it binders}\; \isacommand{in}\; {\it labels}\\
   918   \isacommand{bind\_res}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   919   \end{tabular}
   919   \end{tabular}
   920   \end{center}
   920   \end{center}
   921 
   921 
   922   \noindent
   922   \noindent
   923   The first mode is for binding lists of atoms (the order of binders matters);
   923   The first mode is for binding lists of atoms (the order of binders matters);
   924   the second is for sets of binders (the order does not matter, but the
   924   the second is for sets of binders (the order does not matter, but the
   925   cardinality does) and the last is for sets of binders (with vacuous binders
   925   cardinality does) and the last is for sets of binders (with vacuous binders
   926   preserving $\alpha$-equivalence). The ``\isacommand{in}-part'' of a binding
   926   preserving $\alpha$-equivalence). As indicated, the ``\isacommand{in}-part'' of a binding
   927   clause will be called \emph{bodies} (there can be more than one); the
   927   clause will be called \emph{bodies}; the
   928   ``\isacommand{bind}-part'' will be called \emph{binders}. In contrast to
   928   ``\isacommand{bind}-part'' will be called \emph{binders}. In contrast to
   929   Ott, we allow multiple labels in binders and bodies. For example we allow
   929   Ott, we allow multiple labels in binders and bodies. For example we allow
   930   binding clauses of the form:
   930   binding clauses of the form:
   931 
   931 
   932   \begin{center}
   932   \begin{center}
   938       \isacommand{bind} @{text "x y"} \isacommand{in} @{text "s"}\\
   938       \isacommand{bind} @{text "x y"} \isacommand{in} @{text "s"}\\
   939   \end{tabular}
   939   \end{tabular}
   940   \end{center}
   940   \end{center}
   941 
   941 
   942   \noindent
   942   \noindent
   943   Similarly for the other binding modes. Interestingly, in case of \isacommand{bind\_set}
   943   Similarly for the other binding modes. 
   944   and \isacommand{bind\_res} the binding clauses above will make a difference to the semantics
   944   %Interestingly, in case of \isacommand{bind\_set}
   945   of the specifications (the corresponding $\alpha$-equivalence will differ). We will 
   945   %and \isacommand{bind\_res} the binding clauses above will make a difference to the semantics
   946   show this later with an example.
   946   %of the specifications (the corresponding $\alpha$-equivalence will differ). We will 
   947   
   947   %show this later with an example.
   948   There are some restrictions we need to impose on binding clauses: the main idea behind 
   948   
   949   these restrictions is that we obtain a sensible notion of $\alpha$-equivalence where
   949   There are also some restrictions we need to impose on binding clauses: the
   950   it is ensured that a bound variable cannot be free at the same time.  First, a
   950   main idea behind these restrictions is that we obtain a sensible notion of
   951   body can only occur in \emph{one} binding clause of a term constructor (this ensures
   951   $\alpha$-equivalence where it is ensured that within a given scope a 
   952   that the bound variables of a body cannot be free at the same time by specifying 
   952   variable occurence cannot be bound and free at the same time.  First, a body can only occur in
   953   an alternative binder for the body). For
   953   \emph{one} binding clause of a term constructor (this ensures that the bound
   954   binders we distinguish between \emph{shallow} and \emph{deep} binders.
   954   variables of a body cannot be free at the same time by specifying an
   955   Shallow binders are just labels. The restriction we need to impose on them
   955   alternative binder for the body). For binders we distinguish between
   956   is that in case of \isacommand{bind\_set} and \isacommand{bind\_res} the
   956   \emph{shallow} and \emph{deep} binders.  Shallow binders are just
   957   labels must either refer to atom types or to sets of atom types; in case of
   957   labels. The restriction we need to impose on them is that in case of
   958   \isacommand{bind} the labels must refer to atom types or lists of atom
   958   \isacommand{bind\_set} and \isacommand{bind\_res} the labels must either
   959   types. Two examples for the use of shallow binders are the specification of
   959   refer to atom types or to sets of atom types; in case of \isacommand{bind}
   960   lambda-terms, where a single name is bound, and type-schemes, where a finite
   960   the labels must refer to atom types or lists of atom types. Two examples for
   961   set of names is bound:
   961   the use of shallow binders are the specification of lambda-terms, where a
       
   962   single name is bound, and type-schemes, where a finite set of names is
       
   963   bound:
       
   964 
   962 
   965 
   963   \begin{center}
   966   \begin{center}
   964   \begin{tabular}{@ {}cc@ {}}
   967   \begin{tabular}{@ {}cc@ {}}
   965   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   968   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   966   \isacommand{nominal\_datatype} @{text lam} $=$\\
   969   \isacommand{nominal\_datatype} @{text lam} $=$\\
   992   the atoms in one argument of the term-constructor, which can be bound in
   995   the atoms in one argument of the term-constructor, which can be bound in
   993   other arguments and also in the same argument (we will call such binders
   996   other arguments and also in the same argument (we will call such binders
   994   \emph{recursive}, see below). The binding functions are
   997   \emph{recursive}, see below). The binding functions are
   995   expected to return either a set of atoms (for \isacommand{bind\_set} and
   998   expected to return either a set of atoms (for \isacommand{bind\_set} and
   996   \isacommand{bind\_res}) or a list of atoms (for \isacommand{bind}). They can
   999   \isacommand{bind\_res}) or a list of atoms (for \isacommand{bind}). They can
   997   be defined by primitive recursion over the corresponding type; the equations
  1000   be defined by recursion over the corresponding type; the equations
   998   must be given in the binding function part of the scheme shown in
  1001   must be given in the binding function part of the scheme shown in
   999   \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
  1002   \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
  1000   tuple patterns might be specified as:
  1003   tuple patterns might be specified as:
  1001 
       
  1002   %
  1004   %
  1003   \begin{equation}\label{letpat}
  1005   \begin{equation}\label{letpat}
  1004   \mbox{%
  1006   \mbox{%
  1005   \begin{tabular}{l}
  1007   \begin{tabular}{l}
  1006   \isacommand{nominal\_datatype} @{text trm} =\\
  1008   \isacommand{nominal\_datatype} @{text trm} =\\
  1040   \noindent
  1042   \noindent
  1041   where the argument of the deep binder is also in the body. We call such
  1043   where the argument of the deep binder is also in the body. We call such
  1042   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1044   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1043   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1045   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1044   specification:
  1046   specification:
  1045 
  1047   %
  1046   \begin{equation}\label{letrecs}
  1048   \begin{equation}\label{letrecs}
  1047   \mbox{%
  1049   \mbox{%
  1048   \begin{tabular}{@ {}l@ {}}
  1050   \begin{tabular}{@ {}l@ {}}
  1049   \isacommand{nominal\_datatype}~@{text "trm ="}\\
  1051   \isacommand{nominal\_datatype}~@{text "trm ="}\\
  1050   \hspace{5mm}\phantom{$\mid$}\ldots\\
  1052   \hspace{5mm}\phantom{$\mid$}\ldots\\
  1063 
  1065 
  1064   \noindent
  1066   \noindent
  1065   The difference is that with @{text Let} we only want to bind the atoms @{text
  1067   The difference is that with @{text Let} we only want to bind the atoms @{text
  1066   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1068   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1067   inside the assignment. This difference has consequences for the free-variable 
  1069   inside the assignment. This difference has consequences for the free-variable 
  1068   function and $\alpha$-equivalence relation, which we are going to define below.
  1070   function and $\alpha$-equivalence relation, which we are going to define later.
  1069   
  1071   
  1070   To make sure that variables bound by deep binders cannot be free at the
  1072   To make sure that variables bound by deep binders cannot be free at the
  1071   same time, we have to impose some restrictions. First,
  1073   same time, we have to impose some further restrictions. First,
  1072   we cannot have more than one binding function for one binder. So we exclude:
  1074   we cannot have more than one binding function for one binder. So we exclude:
  1073 
  1075 
  1074   \begin{center}
  1076   \begin{center}
  1075   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  1077   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  1076   @{text "Baz\<^isub>1 p::pat t::trm"} & 
  1078   @{text "Baz\<^isub>1 p::pat t::trm"} & 
  1080      \isacommand{bind} @{text "bn\<^isub>2(p)"} \isacommand{in} @{text "t\<^isub>2"}\\
  1082      \isacommand{bind} @{text "bn\<^isub>2(p)"} \isacommand{in} @{text "t\<^isub>2"}\\
  1081   \end{tabular}
  1083   \end{tabular}
  1082   \end{center}
  1084   \end{center}
  1083 
  1085 
  1084   \noindent
  1086   \noindent
       
  1087   Otherwise it is be possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"}  pick 
       
  1088   out different atoms to become bound in @{text "p"}.
       
  1089   
       
  1090 
  1085   We also need to restrict the form of the binding functions. As will shortly
  1091   We also need to restrict the form of the binding functions. As will shortly
  1086   become clear, we cannot return an atom in a binding function that is also
  1092   become clear, we cannot return an atom in a binding function that is also
  1087   bound in the corresponding term-constructor. That means in the example
  1093   bound in the corresponding term-constructor. That means in the example
  1088   \eqref{letpat} that the term-constructors @{text PVar} and @{text PTup} may
  1094   \eqref{letpat} that the term-constructors @{text PVar} and @{text PTup} may
  1089   not have a binding clause (all arguments are used to define @{text "bn"}).
  1095   not have a binding clause (all arguments are used to define @{text "bn"}).
  1090   In contrast, in case of \eqref{letrecs} the term-constructor @{text ACons}
  1096   In contrast, in case of \eqref{letrecs} the term-constructor @{text ACons}
  1091   may have a binding clause involving the argument @{text t} (the only one that
  1097   may have a binding clause involving the argument @{text t} (the only one that
  1092   is \emph{not} used in the definition of the binding function).  
  1098   is \emph{not} used in the definition of the binding function). This restriction
       
  1099   means that we can lift the binding function to $\alpha$-equated terms.
  1093 
  1100 
  1094   In the version of
  1101   In the version of
  1095   Nominal Isabelle described here, we also adopted the restriction from the
  1102   Nominal Isabelle described here, we also adopted the restriction from the
  1096   Ott-tool that binding functions can only return: the empty set or empty list
  1103   Ott-tool that binding functions can only return: the empty set or empty list
  1097   (as in case @{text PNil}), a singleton set or singleton list containing an
  1104   (as in case @{text PNil}), a singleton set or singleton list containing an
  1098   atom (case @{text PVar}), or unions of atom sets or appended atom lists
  1105   atom (case @{text PVar}), or unions of atom sets or appended atom lists
  1099   (case @{text PTup}). This restriction will simplify some automatic definitions and proofs
  1106   (case @{text PTup}). This restriction will simplify some automatic definitions and proofs
  1100   later on.
  1107   later on.
  1101   
  1108   
  1102   In order to simplify our definitions, we shall assume specifications 
  1109   In order to simplify our definitions of free variables and $\alpha$-equivalence, 
       
  1110   we shall assume specifications 
  1103   of term-calculi are implicitly \emph{completed}. By this we mean that  
  1111   of term-calculi are implicitly \emph{completed}. By this we mean that  
  1104   for every argument of a term-constructor that is \emph{not} 
  1112   for every argument of a term-constructor that is \emph{not} 
  1105   already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
  1113   already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
  1106   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
  1114   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
  1107   of the lambda-calculus, the completion produces
  1115   of the lambda-calculus, the completion produces
  1130   specifications into actual type definitions in Isabelle/HOL and then
  1138   specifications into actual type definitions in Isabelle/HOL and then
  1131   establish a reasoning infrastructure for them. As
  1139   establish a reasoning infrastructure for them. As
  1132   Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just 
  1140   Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just 
  1133   re-arranging the arguments of
  1141   re-arranging the arguments of
  1134   term-constructors so that binders and their bodies are next to each other will 
  1142   term-constructors so that binders and their bodies are next to each other will 
  1135   result in inadequate representations. Therefore we will first
  1143   result in inadequate representations in cases like @{text "Let x\<^isub>1=t\<^isub>1\<dots>x\<^isub>n=t\<^isub>n in s"}. 
       
  1144   Therefore we will first
  1136   extract datatype definitions from the specification and then define 
  1145   extract datatype definitions from the specification and then define 
  1137   explicitly an $\alpha$-equivalence relation over them.
  1146   explicitly an $\alpha$-equivalence relation over them. We subsequently
       
  1147   quotient the datatypes according to our $\alpha$-equivalence.
  1138 
  1148 
  1139 
  1149 
  1140   The datatype definition can be obtained by stripping off the 
  1150   The datatype definition can be obtained by stripping off the 
  1141   binding clauses and the labels from the types. We also have to invent
  1151   binding clauses and the labels from the types. We also have to invent
  1142   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1152   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1156 
  1166 
  1157   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1167   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1158   non-empty and the types in the constructors only occur in positive 
  1168   non-empty and the types in the constructors only occur in positive 
  1159   position (see \cite{Berghofer99} for an indepth description of the datatype package
  1169   position (see \cite{Berghofer99} for an indepth description of the datatype package
  1160   in Isabelle/HOL). We then define the user-specified binding 
  1170   in Isabelle/HOL). We then define the user-specified binding 
  1161   functions, called @{term "bn"}, by primitive recursion over the corresponding 
  1171   functions, called @{term "bn"}, by recursion over the corresponding 
  1162   raw datatype. We can also easily define permutation operations by 
  1172   raw datatype. We can also easily define permutation operations by 
  1163   primitive recursion so that for each term constructor @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"} 
  1173   recursion so that for each term constructor @{text "C"} with the 
  1164   we have that
  1174   argument types @{text "ty"}$_{1..n}$ we have that
  1165   %
  1175   %
  1166   \begin{equation}\label{ceqvt}
  1176   \begin{equation}\label{ceqvt}
  1167   @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"}
  1177   @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"}
  1168   \end{equation}
  1178   \end{equation}
       
  1179 
       
  1180   \noindent
       
  1181   where the variables @{text "z"}$_{1..n}$ are of types @{text "ty"}$_{1..n}$.
  1169   
  1182   
  1170   The first non-trivial step we have to perform is the generation of
  1183   The first non-trivial step we have to perform is the generation of
  1171   free-variable functions from the specifications. Given the raw types @{text
  1184   free-variable functions from the specifications. Given a raw term, these 
  1172   "ty\<^isub>1 \<dots> ty\<^isub>n"} derived from a specification, we define the
  1185   functions return sets of atoms. Assuming a nominal datatype
  1173   free-variable functions
  1186   specification as in \eqref{scheme} and its \emph{raw} types @{text "ty"}$_{1..n}$, 
  1174 
  1187   we define the free-variable functions
  1175   \begin{center}
  1188   %
       
  1189   \begin{equation}\label{fvars}
  1176   @{text "fv_ty\<^isub>1, \<dots>, fv_ty\<^isub>n"}
  1190   @{text "fv_ty\<^isub>1, \<dots>, fv_ty\<^isub>n"}
  1177   \end{center}
  1191   \end{equation}
  1178 
  1192 
  1179   \noindent
  1193   \noindent
  1180   We define them together with auxiliary free-variable functions for
  1194   We define them together with auxiliary free-variable functions for
  1181   the binding functions. Given raw binding functions @{text "bn\<^isub>1 \<dots> bn\<^isub>m"} we define
  1195   the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ 
  1182   
  1196   we define
       
  1197   %
  1183   \begin{center}
  1198   \begin{center}
  1184   @{text "fv_bn\<^isub>1, \<dots>, fv_bn\<^isub>m"}
  1199   @{text "fv_bn\<^isub>1, \<dots>, fv_bn\<^isub>m"}
  1185   \end{center}
  1200   \end{center}
  1186 
  1201 
  1187   \noindent
  1202   \noindent
  1188   The reason for this setup is that in a deep binder not all atoms have to be
  1203   The reason for this setup is that in a deep binder not all atoms have to be
  1189   bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function
  1204   bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function
  1190   that calculates those unbound atoms. 
  1205   that calculates those unbound atoms in a deep binder.
  1191 
       
  1192   For atomic types we define the auxiliary
       
  1193   free variable functions:
       
  1194 
       
  1195   \begin{center}
       
  1196   \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
       
  1197   @{text "fv_atom a"} & @{text "="} & @{text "atom a"}\\
       
  1198   @{text "fv_atom_set as"} & @{text "="} & @{text "atoms as"}\\
       
  1199   @{text "fv_atom_list as"} & @{text "="} & @{text "atoms (set as)"}\\
       
  1200   \end{tabular}
       
  1201   \end{center}
       
  1202 
       
  1203   \noindent 
       
  1204   Like the coercion function @{text atom}, @{text "atoms"} coerces 
       
  1205   the set of atoms to a set of the generic atom type.
       
  1206   It is defined as @{text "atoms as \<equiv> {atom a | a \<in> as}"}.
       
  1207 
       
  1208 
  1206 
  1209   While the idea behind these free-variable functions is clear (they just
  1207   While the idea behind these free-variable functions is clear (they just
  1210   collect all atoms that are not bound), because of our rather complicated
  1208   collect all atoms that are not bound), because of our rather complicated
  1211   binding mechanisms their definitions are somewhat involved.  Given a
  1209   binding mechanisms their definitions are somewhat involved.  Given a
  1212   term-constructor @{text "C"} of type @{text ty} and some associated binding
  1210   term-constructor @{text "C"} of type @{text ty} and some associated binding
  1213   clauses @{text bcs}, the result of the @{text "fv_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be
  1211   clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of the @{text "fv_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be
  1214   the union of the values, @{text v}, calculated by the rules for empty, shallow and
  1212   the union @{text "fv(bc\<^isub>1) \<union> \<dots> \<union> fv(bc\<^isub>k)"} of free variables calculated for 
  1215   deep binding clauses: 
  1213   each binding clause. Given a binding clause @{text bc} is of the form
       
  1214   %
       
  1215   \begin{equation}
       
  1216   \mbox{\isacommand{bind} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
       
  1217   \end{equation}
       
  1218 
       
  1219   \noindent
       
  1220   where the body labels @{text "d"}$_{1..q}$ refer to types @{text ty}$_{1..q}$; the binders 
       
  1221   @{text b}$_{1..p}$
       
  1222   either refer to labels of atom types (in case of shallow binders) or to binding 
       
  1223   functions taking a single label as argument (in case of deep binders). Assuming the
       
  1224   free variables of the bodies is the set @{text "D"}, the bound variables of the binders 
       
  1225   is the set @{text B} and the free variables of the non-recursive deep binders is @{text "B'"}
       
  1226   then the free variables of the binding clause @{text bc} is
       
  1227   %
       
  1228   \begin{center}
       
  1229   @{text "fv(bc) = (D - B) \<union> B'"}
       
  1230   \end{center}
       
  1231 
       
  1232   \noindent
       
  1233   Formally the set @{text D} is the union of the free variables for the bodies
       
  1234   %
       
  1235   \begin{center}
       
  1236   @{text "D = fv_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fv_ty\<^isub>q d\<^isub>q"}
       
  1237   \end{center} 
       
  1238 
       
  1239   \noindent
       
  1240   whereby the free variable functions @{text "fv_ty\<^isub>i"} are the ones in \eqref{fvars}
       
  1241   provided the @{text "d\<^isub>i"} refers to one of the types @{text "ty"}$_{1..n}$; 
       
  1242   otherwise we set @{text "fv_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}.
       
  1243 
       
  1244 
       
  1245 if @{text "d\<^isub>i"} is a label
       
  1246   for an atomic type we use the following auxiliary free variable functions
       
  1247 
       
  1248   \begin{center}
       
  1249   \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
       
  1250   @{text "fv_atom a"} & @{text "="} & @{text "{atom a}"}\\
       
  1251   @{text "fv_atom_set as"} & @{text "="} & @{text "atoms as"}\\
       
  1252   @{text "fv_atom_list as"} & @{text "="} & @{text "atoms (set as)"}\\
       
  1253   \end{tabular}
       
  1254   \end{center}
       
  1255 
       
  1256   \noindent 
       
  1257   In these functions, @{text "atoms"}, like @{text "atom"}, coerces 
       
  1258   the set of atoms to a set of the generic atom type.
       
  1259   It is defined as @{text "atoms as \<equiv> {atom a | a \<in> as}"}. Otherwise
       
  1260   
       
  1261 
       
  1262 
       
  1263 the values, @{text v}, calculated by the rules for each bining clause:
  1216   %
  1264   %
  1217   \begin{equation}\label{deepbinderA}
  1265   \begin{equation}\label{deepbinderA}
  1218   \mbox{%
  1266   \mbox{%
  1219   \begin{tabular}{c@ {\hspace{2mm}}p{7.4cm}}
  1267   \begin{tabular}{c@ {\hspace{2mm}}p{7.4cm}}
  1220   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ 
  1268   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ 
  1963   is a substantial improvement.
  2011   is a substantial improvement.
  1964  
  2012  
  1965   The most closely related work to the one presented here is the Ott-tool
  2013   The most closely related work to the one presented here is the Ott-tool
  1966   \cite{ott-jfp} and the C$\alpha$ml language \cite{Pottier06}. Ott is a nifty
  2014   \cite{ott-jfp} and the C$\alpha$ml language \cite{Pottier06}. Ott is a nifty
  1967   front-end for creating \LaTeX{} documents from specifications of
  2015   front-end for creating \LaTeX{} documents from specifications of
  1968   term-calculi involving general binders. For a subset of the specifications,
  2016   term-calculi involving general binders. For a subset of the specifications
  1969   Ott can also generate theorem prover code using a raw representation of
  2017   Ott can also generate theorem prover code using a raw representation of
  1970   terms, and in Coq also a locally nameless representation. The developers of
  2018   terms, and in Coq also a locally nameless representation. The developers of
  1971   this tool have also put forward (on paper) a definition for
  2019   this tool have also put forward (on paper) a definition for
  1972   $\alpha$-equivalence of terms that can be specified in Ott.  This definition is
  2020   $\alpha$-equivalence of terms that can be specified in Ott.  This definition is
  1973   rather different from ours, not using any nominal techniques.  To our
  2021   rather different from ours, not using any nominal techniques.  To our
  2041 
  2089 
  2042   Pottier presents in \cite{Pottier06} a language, called C$\alpha$ml, for 
  2090   Pottier presents in \cite{Pottier06} a language, called C$\alpha$ml, for 
  2043   representing terms with general binders inside OCaml. This language is
  2091   representing terms with general binders inside OCaml. This language is
  2044   implemented as a front-end that can be translated to OCaml with a help of
  2092   implemented as a front-end that can be translated to OCaml with a help of
  2045   a library. He presents a type-system in which the scope of general binders
  2093   a library. He presents a type-system in which the scope of general binders
  2046   can be indicated with some special constructs, written @{text "inner"} and 
  2094   can be indicated with some special markers, written @{text "inner"} and 
  2047   @{text "outer"}. With this, it seems, our and his specifications can be
  2095   @{text "outer"}. With this, it seems, our and his specifications can be
  2048   inter-translated, but we have not proved this. However, we believe the
  2096   inter-translated, but we have not proved this. However, we believe the
  2049   binding specifications in the style of Ott are a more natural way for 
  2097   binding specifications in the style of Ott are a more natural way for 
  2050   representing terms involving bindings. Pottier gives a definition for 
  2098   representing terms involving bindings. Pottier gives a definition for 
  2051   $\alpha$-equivalence, which is similar to our binding mode \isacommand{bind}. 
  2099   $\alpha$-equivalence, which is similar to our binding mode \isacommand{bind}.