Paper/Paper.thy
changeset 2488 1c18f2cf3923
parent 2471 894599a50af3
child 2502 074304d56eb2
equal deleted inserted replaced
2487:fbdaaa20396b 2488:1c18f2cf3923
   228   The scope of the binding is indicated by labels given to the types, for
   228   The scope of the binding is indicated by labels given to the types, for
   229   example @{text "s::trm"}, and a binding clause, in this case
   229   example @{text "s::trm"}, and a binding clause, in this case
   230   \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding
   230   \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding
   231   clause states that all the names the function @{text
   231   clause states that all the names the function @{text
   232   "bn(as)"} returns should be bound in @{text s}.  This style of specifying terms and bindings is heavily
   232   "bn(as)"} returns should be bound in @{text s}.  This style of specifying terms and bindings is heavily
   233   inspired by the syntax of the Ott-tool \cite{ott-jfp}.
   233   inspired by the syntax of the Ott-tool \cite{ott-jfp}. Though, Ott
       
   234   has only one binding mode, namely the one where the order of
       
   235   binders matters. Consequently, type-schemes with binding sets
       
   236   of names cannot be modelled in Ott.
   234 
   237 
   235   However, we will not be able to cope with all specifications that are
   238   However, we will not be able to cope with all specifications that are
   236   allowed by Ott. One reason is that Ott lets the user specify ``empty'' 
   239   allowed by Ott. One reason is that Ott lets the user specify ``empty'' 
   237   types like
   240   types like
   238 
   241 
   379   terms, including properties about support, freshness and equality
   382   terms, including properties about support, freshness and equality
   380   conditions for $\alpha$-equated terms. We are also able to derive strong 
   383   conditions for $\alpha$-equated terms. We are also able to derive strong 
   381   induction principles that have the variable convention already built in.
   384   induction principles that have the variable convention already built in.
   382   The method behind our specification of general binders is taken 
   385   The method behind our specification of general binders is taken 
   383   from the Ott-tool, but we introduce crucial restrictions, and also extensions, so 
   386   from the Ott-tool, but we introduce crucial restrictions, and also extensions, so 
   384   that our specifications make sense for reasoning about $\alpha$-equated terms. 
   387   that our specifications make sense for reasoning about $\alpha$-equated terms.  The main improvement over Ott is that we introduce three binding modes,
       
   388    provide precise definitions for $\alpha$-equivalence and for free
       
   389    variables of our terms, and provide automated proofs inside the
       
   390    Isabelle theorem prover.
   385 
   391 
   386 
   392 
   387   \begin{figure}
   393   \begin{figure}
   388   \begin{boxedminipage}{\linewidth}
   394   \begin{boxedminipage}{\linewidth}
   389   \begin{center}
   395   \begin{center}
   927   and their scope in a term-constructor.  They come in three \emph{modes}:
   933   and their scope in a term-constructor.  They come in three \emph{modes}:
   928 
   934 
   929   \begin{center}
   935   \begin{center}
   930   \begin{tabular}{l}
   936   \begin{tabular}{l}
   931   \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   937   \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   932   \isacommand{bind\_set}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   938   \isacommand{bind (set)}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   933   \isacommand{bind\_res}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   939   \isacommand{bind (res)}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
   934   \end{tabular}
   940   \end{tabular}
   935   \end{center}
   941   \end{center}
   936 
   942 
   937   \noindent
   943   \noindent
   938   The first mode is for binding lists of atoms (the order of binders matters);
   944   The first mode is for binding lists of atoms (the order of binders matters);
   954   \end{tabular}
   960   \end{tabular}
   955   \end{center}
   961   \end{center}
   956 
   962 
   957   \noindent
   963   \noindent
   958   Similarly for the other binding modes. 
   964   Similarly for the other binding modes. 
   959   %Interestingly, in case of \isacommand{bind\_set}
   965   %Interestingly, in case of \isacommand{bind (set)}
   960   %and \isacommand{bind\_res} the binding clauses above will make a difference to the semantics
   966   %and \isacommand{bind (res)} the binding clauses above will make a difference to the semantics
   961   %of the specifications (the corresponding $\alpha$-equivalence will differ). We will 
   967   %of the specifications (the corresponding $\alpha$-equivalence will differ). We will 
   962   %show this later with an example.
   968   %show this later with an example.
   963   
   969   
   964   There are also some restrictions we need to impose on our binding clauses in comparison to
   970   There are also some restrictions we need to impose on our binding clauses in comparison to
   965   the ones of Ott. The
   971   the ones of Ott. The
   970   \emph{one} binding clause of a term constructor (this ensures that the bound
   976   \emph{one} binding clause of a term constructor (this ensures that the bound
   971   atoms of a body cannot be free at the same time by specifying an
   977   atoms of a body cannot be free at the same time by specifying an
   972   alternative binder for the same body). For binders we distinguish between
   978   alternative binder for the same body). For binders we distinguish between
   973   \emph{shallow} and \emph{deep} binders.  Shallow binders are just
   979   \emph{shallow} and \emph{deep} binders.  Shallow binders are just
   974   labels. The restriction we need to impose on them is that in case of
   980   labels. The restriction we need to impose on them is that in case of
   975   \isacommand{bind\_set} and \isacommand{bind\_res} the labels must either
   981   \isacommand{bind (set)} and \isacommand{bind (res)} the labels must either
   976   refer to atom types or to sets of atom types; in case of \isacommand{bind}
   982   refer to atom types or to sets of atom types; in case of \isacommand{bind}
   977   the labels must refer to atom types or lists of atom types. Two examples for
   983   the labels must refer to atom types or lists of atom types. Two examples for
   978   the use of shallow binders are the specification of lambda-terms, where a
   984   the use of shallow binders are the specification of lambda-terms, where a
   979   single name is bound, and type-schemes, where a finite set of names is
   985   single name is bound, and type-schemes, where a finite set of names is
   980   bound:
   986   bound:
   981 
   987 
   982 
   988 
   983   \begin{center}
   989   \begin{center}
   984   \begin{tabular}{@ {}cc@ {}}
   990   \begin{tabular}{@ {}cc@ {}}
   985   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   991   \begin{tabular}{@ {}l@ {\hspace{-2mm}}}
   986   \isacommand{nominal\_datatype} @{text lam} $=$\\
   992   \isacommand{nominal\_datatype} @{text lam} $=$\\
   987   \hspace{5mm}\phantom{$\mid$}~@{text "Var name"}\\
   993   \hspace{5mm}\phantom{$\mid$}~@{text "Var name"}\\
   988   \hspace{5mm}$\mid$~@{text "App lam lam"}\\
   994   \hspace{5mm}$\mid$~@{text "App lam lam"}\\
   989   \hspace{5mm}$\mid$~@{text "Lam x::name t::lam"}\\
   995   \hspace{5mm}$\mid$~@{text "Lam x::name t::lam"}\\
   990   \hspace{21mm}\isacommand{bind} @{text x} \isacommand{in} @{text t}\\
   996   \hspace{21mm}\isacommand{bind} @{text x} \isacommand{in} @{text t}\\
   992   \begin{tabular}{@ {}l@ {}}
   998   \begin{tabular}{@ {}l@ {}}
   993   \isacommand{nominal\_datatype}~@{text ty} $=$\\
   999   \isacommand{nominal\_datatype}~@{text ty} $=$\\
   994   \hspace{5mm}\phantom{$\mid$}~@{text "TVar name"}\\
  1000   \hspace{5mm}\phantom{$\mid$}~@{text "TVar name"}\\
   995   \hspace{5mm}$\mid$~@{text "TFun ty ty"}\\
  1001   \hspace{5mm}$\mid$~@{text "TFun ty ty"}\\
   996   \isacommand{and}~@{text "tsc = All xs::(name fset) T::ty"}\\
  1002   \isacommand{and}~@{text "tsc = All xs::(name fset) T::ty"}\\
   997   \hspace{24mm}\isacommand{bind\_res} @{text xs} \isacommand{in} @{text T}\\
  1003   \hspace{21mm}\isacommand{bind (res)} @{text xs} \isacommand{in} @{text T}\\
   998   \end{tabular}
  1004   \end{tabular}
   999   \end{tabular}
  1005   \end{tabular}
  1000   \end{center}
  1006   \end{center}
  1001 
  1007 
  1002   \noindent
  1008   \noindent
  1003   In these specifications @{text "name"} refers to an atom type, and @{text
  1009   In these specifications @{text "name"} refers to an atom type, and @{text
  1004   "fset"} to the type of finite sets.
  1010   "fset"} to the type of finite sets.
  1005   Note that for @{text lam} it does not matter which binding mode we use. The
  1011   Note that for @{text lam} it does not matter which binding mode we use. The
  1006   reason is that we bind only a single @{text name}. However, having
  1012   reason is that we bind only a single @{text name}. However, having
  1007   \isacommand{bind\_set} or \isacommand{bind} in the second case makes a
  1013   \isacommand{bind (set)} or \isacommand{bind} in the second case makes a
  1008   difference to the semantics of the specification (which we will define in the next section).
  1014   difference to the semantics of the specification (which we will define in the next section).
  1009 
  1015 
  1010 
  1016 
  1011   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
  1017   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
  1012   the atoms in one argument of the term-constructor, which can be bound in
  1018   the atoms in one argument of the term-constructor, which can be bound in
  1013   other arguments and also in the same argument (we will call such binders
  1019   other arguments and also in the same argument (we will call such binders
  1014   \emph{recursive}, see below). The binding functions are
  1020   \emph{recursive}, see below). The binding functions are
  1015   expected to return either a set of atoms (for \isacommand{bind\_set} and
  1021   expected to return either a set of atoms (for \isacommand{bind (set)} and
  1016   \isacommand{bind\_res}) or a list of atoms (for \isacommand{bind}). They can
  1022   \isacommand{bind (res)}) or a list of atoms (for \isacommand{bind}). They can
  1017   be defined by recursion over the corresponding type; the equations
  1023   be defined by recursion over the corresponding type; the equations
  1018   must be given in the binding function part of the scheme shown in
  1024   must be given in the binding function part of the scheme shown in
  1019   \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
  1025   \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
  1020   tuple patterns might be specified as:
  1026   tuple patterns might be specified as:
  1021   %
  1027   %
  1223   binding mechanisms their definitions are somewhat involved.  Given
  1229   binding mechanisms their definitions are somewhat involved.  Given
  1224   a term-constructor @{text "C"} of type @{text ty} and some associated
  1230   a term-constructor @{text "C"} of type @{text ty} and some associated
  1225   binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
  1231   binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
  1226   "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
  1232   "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
  1227   "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we will define below what @{text "fa"} for a binding
  1233   "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we will define below what @{text "fa"} for a binding
  1228   clause means. We only show the details for the mode \isacommand{bind\_set} (the other modes are similar). 
  1234   clause means. We only show the details for the mode \isacommand{bind (set)} (the other modes are similar). 
  1229   Suppose the binding clause @{text bc\<^isub>i} is of the form 
  1235   Suppose the binding clause @{text bc\<^isub>i} is of the form 
  1230   %
  1236   %
  1231   \begin{center}
  1237   \begin{center}
  1232   \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
  1238   \mbox{\isacommand{bind (set)} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
  1233   \end{center}
  1239   \end{center}
  1234 
  1240 
  1235   \noindent
  1241   \noindent
  1236   in which the body-labels @{text "d"}$_{1..q}$ refer to types @{text ty}$_{1..q}$,
  1242   in which the body-labels @{text "d"}$_{1..q}$ refer to types @{text ty}$_{1..q}$,
  1237   and the binders @{text b}$_{1..p}$
  1243   and the binders @{text b}$_{1..p}$
  1423   The task below is to specify what the premises of a binding clause are. As a
  1429   The task below is to specify what the premises of a binding clause are. As a
  1424   special instance, we first treat the case where @{text "bc\<^isub>i"} is the
  1430   special instance, we first treat the case where @{text "bc\<^isub>i"} is the
  1425   empty binding clause of the form
  1431   empty binding clause of the form
  1426   %
  1432   %
  1427   \begin{center}
  1433   \begin{center}
  1428   \mbox{\isacommand{bind\_set} @{term "{}"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.}
  1434   \mbox{\isacommand{bind (set)} @{term "{}"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.}
  1429   \end{center}
  1435   \end{center}
  1430 
  1436 
  1431   \noindent
  1437   \noindent
  1432   In this binding clause no atom is bound and we only have to $\alpha$-relate the bodies. For this
  1438   In this binding clause no atom is bound and we only have to $\alpha$-relate the bodies. For this
  1433   we build first the tuples @{text "D \<equiv> (d\<^isub>1,\<dots>, d\<^isub>q)"} and @{text "D' \<equiv> (d\<PRIME>\<^isub>1,\<dots>, d\<PRIME>\<^isub>q)"}  
  1439   we build first the tuples @{text "D \<equiv> (d\<^isub>1,\<dots>, d\<^isub>q)"} and @{text "D' \<equiv> (d\<PRIME>\<^isub>1,\<dots>, d\<PRIME>\<^isub>q)"}  
  1455   We will use the unfolded version in the examples below.
  1461   We will use the unfolded version in the examples below.
  1456 
  1462 
  1457   Now suppose the binding clause @{text "bc\<^isub>i"} is of the general form 
  1463   Now suppose the binding clause @{text "bc\<^isub>i"} is of the general form 
  1458   %
  1464   %
  1459   \begin{equation}\label{nonempty}
  1465   \begin{equation}\label{nonempty}
  1460   \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.}
  1466   \mbox{\isacommand{bind (set)} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.}
  1461   \end{equation}
  1467   \end{equation}
  1462 
  1468 
  1463   \noindent
  1469   \noindent
  1464   In this case we define a premise @{text P} using the relation
  1470   In this case we define a premise @{text P} using the relation
  1465   $\approx_{\,\textit{set}}$ given in Section~\ref{sec:binders} (similarly
  1471   $\approx_{\,\textit{set}}$ given in Section~\ref{sec:binders} (similarly
  2111   covers cases of binders depending on other binders, which just do not make
  2117   covers cases of binders depending on other binders, which just do not make
  2112   sense for our $\alpha$-equated terms. Third, it allows empty types that have no
  2118   sense for our $\alpha$-equated terms. Third, it allows empty types that have no
  2113   meaning in a HOL-based theorem prover. We also had to generalise slightly Ott's 
  2119   meaning in a HOL-based theorem prover. We also had to generalise slightly Ott's 
  2114   binding clauses. In Ott you specify binding clauses with a single body; we 
  2120   binding clauses. In Ott you specify binding clauses with a single body; we 
  2115   allow more than one. We have to do this, because this makes a difference 
  2121   allow more than one. We have to do this, because this makes a difference 
  2116   for our notion of $\alpha$-equivalence in case of \isacommand{bind\_set} and 
  2122   for our notion of $\alpha$-equivalence in case of \isacommand{bind (set)} and 
  2117   \isacommand{bind\_res}. Consider the examples
  2123   \isacommand{bind (res)}. Consider the examples
  2118 
  2124 
  2119   \begin{center}
  2125   \begin{center}
  2120   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  2126   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  2121   @{text "Foo\<^isub>1 xs::name fset t::trm s::trm"} &  
  2127   @{text "Foo\<^isub>1 xs::name fset t::trm s::trm"} &  
  2122       \isacommand{bind\_set} @{text "xs"} \isacommand{in} @{text "t s"}\\
  2128       \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "t s"}\\
  2123   @{text "Foo\<^isub>2 xs::name fset t::trm s::trm"} &  
  2129   @{text "Foo\<^isub>2 xs::name fset t::trm s::trm"} &  
  2124       \isacommand{bind\_set} @{text "xs"} \isacommand{in} @{text "t"}, 
  2130       \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "t"}, 
  2125       \isacommand{bind\_set} @{text "xs"} \isacommand{in} @{text "s"}\\
  2131       \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "s"}\\
  2126   \end{tabular}
  2132   \end{tabular}
  2127   \end{center}
  2133   \end{center}
  2128 
  2134 
  2129   \noindent
  2135   \noindent
  2130   In the first term-constructor we have a single
  2136   In the first term-constructor we have a single
  2163   it defines an equivalence relation. A complete
  2169   it defines an equivalence relation. A complete
  2164   reasoning infrastructure is well beyond the purposes of his language. 
  2170   reasoning infrastructure is well beyond the purposes of his language. 
  2165   
  2171   
  2166   In a slightly different domain (programming with dependent types), the 
  2172   In a slightly different domain (programming with dependent types), the 
  2167   paper \cite{Altenkirch10} presents a calculus with a notion of 
  2173   paper \cite{Altenkirch10} presents a calculus with a notion of 
  2168   $\alpha$-equivalence related to our binding mode \isacommand{bind\_res}.
  2174   $\alpha$-equivalence related to our binding mode \isacommand{bind (res)}.
  2169   The definition in \cite{Altenkirch10} is similar to the one by Pottier, except that it
  2175   The definition in \cite{Altenkirch10} is similar to the one by Pottier, except that it
  2170   has a more operational flavour and calculates a partial (renaming) map. 
  2176   has a more operational flavour and calculates a partial (renaming) map. 
  2171   In this way, the definition can deal with vacuous binders. However, to our
  2177   In this way, the definition can deal with vacuous binders. However, to our
  2172   best knowledge, no concrete mathematical result concerning this
  2178   best knowledge, no concrete mathematical result concerning this
  2173   definition of $\alpha$-equivalence has been proved.    
  2179   definition of $\alpha$-equivalence has been proved.    
  2180   general binders, that is term-constructors having multiple bound 
  2186   general binders, that is term-constructors having multiple bound 
  2181   variables. For this extension we introduced new definitions of 
  2187   variables. For this extension we introduced new definitions of 
  2182   $\alpha$-equivalence and automated all necessary proofs in Isabelle/HOL.
  2188   $\alpha$-equivalence and automated all necessary proofs in Isabelle/HOL.
  2183   To specify general binders we used the specifications from Ott, but extended them 
  2189   To specify general binders we used the specifications from Ott, but extended them 
  2184   in some places and restricted
  2190   in some places and restricted
  2185   them in others so that they make sense in the context of $\alpha$-equated terms.
  2191   them in others so that they make sense in the context of $\alpha$-equated terms. We also introduced two binding modes (set and res) that do not 
       
  2192   exist in Ott. 
  2186   We have tried out the extension with terms from Core-Haskell, type-schemes 
  2193   We have tried out the extension with terms from Core-Haskell, type-schemes 
  2187   and the lambda-calculus, and our code
  2194   and the lambda-calculus, and our code
  2188   will eventually become part of the next Isabelle distribution.\footnote{For the moment
  2195   will eventually become part of the next Isabelle distribution.\footnote{For the moment
  2189   it can be downloaded from the Mercurial repository linked at
  2196   it can be downloaded from the Mercurial repository linked at
  2190   \href{http://isabelle.in.tum.de/nominal/download}
  2197   \href{http://isabelle.in.tum.de/nominal/download}