Paper/Paper.thy
changeset 1545 f32981105089
parent 1535 a37c65fe10de
child 1550 66d388a84e3c
equal deleted inserted replaced
1541:2789dd26171a 1545:f32981105089
    23   \end{center}
    23   \end{center}
    24 
    24 
    25   \noindent
    25   \noindent
    26   where free and bound variables have names.
    26   where free and bound variables have names.
    27   For such terms Nominal Isabelle derives automatically a reasoning
    27   For such terms Nominal Isabelle derives automatically a reasoning
    28   infrastructure, which has been used in formalisations of an equivalence
    28   infrastructure, which has been used successfully in formalisations of an equivalence
    29   checking algorithm for LF \cite{UrbanCheneyBerghofer08}, Typed
    29   checking algorithm for LF \cite{UrbanCheneyBerghofer08}, Typed
    30   Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
    30   Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
    31   \cite{BengtsonParrow07,BengtsonParow09} and a strong normalisation result
    31   \cite{BengtsonParrow07,BengtsonParow09} and a strong normalisation result
    32   for cut-elimination in classical logic \cite{UrbanZhu08}. It has also been
    32   for cut-elimination in classical logic \cite{UrbanZhu08}. It has also been
    33   used by Pollack for formalisations in the locally-nameless approach to
    33   used by Pollack for formalisations in the locally-nameless approach to
    42   $T ::= x \mid T \rightarrow T$ \hspace{5mm} $S ::= \forall \{x_1,\ldots, x_n\}. T$
    42   $T ::= x \mid T \rightarrow T$ \hspace{5mm} $S ::= \forall \{x_1,\ldots, x_n\}. T$
    43   \end{tabular}
    43   \end{tabular}
    44   \end{center}
    44   \end{center}
    45 
    45 
    46   \noindent
    46   \noindent
    47   and the quantification binds a finite (possibly empty) set of type-variables.
    47   and the quantification binds at once a finite (possibly empty) set of type-variables.
    48   While it is possible to formalise such abstractions by iterating single bindings, 
    48   While it is possible to implement this kind of more general binders by iterating single binders, 
    49   this leads to a rather clumsy formalisation of W. This need of iterating single binders 
    49   this leads to a rather clumsy formalisation of W. The need of iterating single binders 
    50   in order to representing multiple binders is also one reason why Nominal Isabelle and other 
    50   is also one reason why Nominal Isabelle and similar 
    51   theorem provers have not fared extremely well with the more advanced tasks 
    51   theorem provers have not fared extremely well with the more advanced tasks 
    52   in the POPLmark challenge \cite{challenge05}, because also there one would like 
    52   in the POPLmark challenge \cite{challenge05}, because also there one would like 
    53   to bind multiple variables at once.
    53   to bind multiple variables at once.
    54 
    54 
    55   Binding multiple variables in a single abstraction has interesting properties that are not
    55   Binding multiple variables has interesting properties that are not
    56   captured by iterating single binders. First, 
    56   captured by iterating single binders. First, 
    57   in the case of type-schemes, we do not like to make a distinction
    57   in the case of type-schemes, we do not like to make a distinction
    58   about the order of the bound variables. Therefore we would like to regard the following two
    58   about the order of the bound variables. Therefore we would like to regard the following two
    59   type-schemes as alpha-equivalent
    59   type-schemes as alpha-equivalent
    60 
    60 
    77   $\forall \{x\}. x \rightarrow y  \;\approx_\alpha\; \forall \{x, z\}. x \rightarrow y$ 
    77   $\forall \{x\}. x \rightarrow y  \;\approx_\alpha\; \forall \{x, z\}. x \rightarrow y$ 
    78   \end{center}
    78   \end{center}
    79 
    79 
    80   \noindent
    80   \noindent
    81   where $z$ does not occur freely in the type.
    81   where $z$ does not occur freely in the type.
    82   In this paper we will give a general abstraction mechanism and associated
    82   In this paper we will give a general binding mechanism and associated
    83   notion of alpha-equivalence that can be used to faithfully represent
    83   notion of alpha-equivalence that can be used to faithfully represent
    84   type-schemes in Nominal Isabelle.  The difficulty of finding the right notion 
    84   this kind of binding in Nominal Isabelle.  The difficulty of finding the right notion 
    85   for alpha-equivalence in this case can be appreciated by considering that the 
    85   for alpha-equivalence in this case can be appreciated by considering that the 
    86   definition given by Leroy in \cite{Leroy92} is incorrect (it omits a side-condition).
    86   definition given by Leroy in \cite{Leroy92} is incorrect (it omits a side-condition).
    87 
       
    88 
       
    89 
    87 
    90   However, the notion of alpha-equivalence that is preserved by vacuous binders is not
    88   However, the notion of alpha-equivalence that is preserved by vacuous binders is not
    91   alway wanted. For example in terms like
    89   alway wanted. For example in terms like
    92 
    90 
    93   \begin{equation}\label{one}
    91   \begin{equation}\label{one}
   102   \begin{center}
   100   \begin{center}
   103   $\LET x = 3 \AND y = 2 \AND z = loop \IN x\,\backslash\,y \END$
   101   $\LET x = 3 \AND y = 2 \AND z = loop \IN x\,\backslash\,y \END$
   104   \end{center}
   102   \end{center}
   105 
   103 
   106   \noindent
   104   \noindent
   107   Therefore we will also provide a separate abstraction mechanism for cases 
   105   Therefore we will also provide a separate binding mechanism for cases 
   108   in which the order of binders does not matter, but the ``cardinality'' of the 
   106   in which the order of binders does not matter, but the ``cardinality'' of the 
   109   binders has to agree.
   107   binders has to agree.
   110 
   108 
   111   However, we found that this is still not sufficient for covering language 
   109   However, we found that this is still not sufficient for dealing with language 
   112   constructs frequently occuring in programming language research. For example 
   110   constructs frequently occurring in programming language research. For example 
   113   in $\mathtt{let}$s involving patterns 
   111   in $\mathtt{let}$s involving patterns 
   114 
   112 
   115   \begin{equation}\label{two}
   113   \begin{equation}\label{two}
   116   \LET (x, y) = (3, 2) \IN x\,\backslash\,y \END
   114   \LET (x, y) = (3, 2) \IN x\,\backslash\,y \END
   117   \end{equation}
   115   \end{equation}
   124   \begin{center}
   122   \begin{center}
   125   $\LET (y, x) = (3, 2) \IN x\,\backslash y\,\END$
   123   $\LET (y, x) = (3, 2) \IN x\,\backslash y\,\END$
   126   \end{center}
   124   \end{center}
   127 
   125 
   128   \noindent
   126   \noindent
   129   As a result, we provide three general abstraction mechanisms for binding multiple
   127   As a result, we provide three general binding mechanisms each of which binds multiple
   130   variables and allow the user to chose which one is intended when formalising a
   128   variables at once, and we let the user chose which one is intended when formalising a
   131   programming language calculus.
   129   programming language calculus.
   132 
   130 
   133   By providing these general abstraction mechanisms, however, we have to work around 
   131   By providing these general binding mechanisms, however, we have to work around 
   134   a problem that has been pointed out by Pottier in \cite{Pottier06}: in 
   132   a problem that has been pointed out by Pottier in \cite{Pottier06}: in 
   135   $\mathtt{let}$-constructs of the form
   133   $\mathtt{let}$-constructs of the form
   136 
   134 
   137   \begin{center}
   135   \begin{center}
   138   $\LET x_1 = t_1 \AND \ldots \AND x_n = t_n \IN s \END$
   136   $\LET x_1 = t_1 \AND \ldots \AND x_n = t_n \IN s \END$
   147   \begin{center}
   145   \begin{center}
   148   $\LET [x_1,\ldots,x_n].s\;\; [t_1,\ldots,t_n]$
   146   $\LET [x_1,\ldots,x_n].s\;\; [t_1,\ldots,t_n]$
   149   \end{center}
   147   \end{center}
   150 
   148 
   151   \noindent
   149   \noindent
   152   where the notation $[\_\!\_].\_\!\_$ indicates that a set of variables becomes 
   150   where the notation $[\_\!\_].\_\!\_$ indicates that the $x_i$ become 
   153   bound in $s$. In this representation we need additional predicates about terms 
   151   bound in $s$. In this representation we need additional predicates about terms 
   154   to ensure that the two lists are of equal length. This can result into very 
   152   to ensure that the two lists are of equal length. This can result into very 
   155   unintelligible reasoning (see for example~\cite{BengtsonParow09}). 
   153   unintelligible reasoning (see for example~\cite{BengtsonParow09}). 
   156   To avoid this, we will allow for example specifications of $\mathtt{let}$s 
   154   To avoid this, we will allow to specify $\mathtt{let}$s 
   157   as follows
   155   as follows
   158 
   156 
   159   \begin{center}
   157   \begin{center}
   160   \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
   158   \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
   161   $trm$ & $::=$  & \ldots\\ 
   159   $trm$ & $::=$  & \ldots\\ 
   162         & $\mid$ & $\mathtt{let}\;a\!::\!assn\;\;t\!::\!trm\quad\mathtt{bind}\;bn\,(a) \IN t$\\[1mm]
   160         & $\mid$ & $\mathtt{let}\;a\!::\!assn\;\;s\!::\!trm\quad\mathtt{bind}\;bn\,(a) \IN s$\\[1mm]
   163   $assn$ & $::=$  & $\mathtt{anil}$\\
   161   $assn$ & $::=$  & $\mathtt{anil}$\\
   164          & $\mid$ & $\mathtt{acons}\;\;name\;\;trm\;\;assn$
   162          & $\mid$ & $\mathtt{acons}\;\;name\;\;trm\;\;assn$
   165   \end{tabular}
   163   \end{tabular}
   166   \end{center}
   164   \end{center}
   167 
   165 
   168   \noindent
   166   \noindent
   169   where $assn$ is an auxiliary type representing a list of assignments
   167   where $assn$ is an auxiliary type representing a list of assignments
   170   and $bn$ an auxilary function identifying the variables to be bound by 
   168   and $bn$ an auxiliary function identifying the variables to be bound by 
   171   the $\mathtt{let}$. This function can be defined as 
   169   the $\mathtt{let}$. This function can be defined as 
   172 
   170 
   173   \begin{center}
   171   \begin{center}
   174   $bn\,(\mathtt{anil}) = \varnothing \qquad bn\,(\mathtt{acons}\;x\;t\;as) = \{x\} \cup bn\,(as)$ 
   172   $bn\,(\mathtt{anil}) = \varnothing \qquad bn\,(\mathtt{acons}\;x\;t\;as) = \{x\} \cup bn\,(as)$ 
   175   \end{center}
   173   \end{center}
   176   
   174   
   177   \noindent
   175   \noindent
       
   176   The scope of the binding is indicated by labels given to the types, for example
       
   177   $s\!::\!trm$, and a binding clause $\mathtt{bind}\;bn\,(a) \IN s$.
   178   This style of specifying terms and bindings is heavily 
   178   This style of specifying terms and bindings is heavily 
   179   inspired by the syntax of the Ott-tool \cite{ott-jfp}.
   179   inspired by the syntax of the Ott-tool \cite{ott-jfp}.
   180 
   180 
   181   However, we will not be able to deal with all specifications that are allowed by
   181   However, we will not be able to deal with all specifications that are
   182   Ott. One reason is that we establish the reasoning infrastructure for
   182   allowed by Ott. One reason is that we establish the reasoning infrastructure
   183   alpha-\emph{equated} terms. In contrast, Ott produces for a subset of its
   183   for alpha-\emph{equated} terms. In contrast, Ott produces for a subset of
   184   specifiactions a reasoning infrastructure for terms that have names for
   184   its specifications a reasoning infrastructure in Isabelle for
   185   bound variables, but these terms are concrete, \emph{non}-alpha-equated terms. To see 
   185   \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms
   186   the difference, note that working
   186   and the concrete terms produced by Ott use names for the bound variables,
   187   with alpha-equated terms means that the two type-schemes with $x$, $y$ and
   187   there is a key difference: working with alpha-equated terms means that the
   188   $z$ being distinct
   188   two type-schemes with $x$, $y$ and $z$ being distinct
   189 
   189 
   190   \begin{center}
   190   \begin{center}
   191   $\forall \{x\}. x \rightarrow y  \;=\; \forall \{x, z\}. x \rightarrow y$ 
   191   $\forall \{x\}. x \rightarrow y  \;=\; \forall \{x, z\}. x \rightarrow y$ 
   192   \end{center}
   192   \end{center}
   193   
   193   
   194   \noindent
   194   \noindent
   195   are not just alpha-equal, but actually equal. Our insistence on reasoning
   195   are not just alpha-equal, but actually equal (note the ``=''-sign). Our insistence 
   196   with alpha-equated terms comes from the wealth of experience we gained with
   196   on reasoning with alpha-equated terms comes from the wealth of experience we gained with
   197   the older version of Nominal Isabelle: for non-trivial properties, reasoning
   197   the older version of Nominal Isabelle: for non-trivial properties, reasoning
   198   about alpha-equated terms is much easier than reasoning with concrete
   198   about alpha-equated terms is much easier than reasoning with concrete
   199   terms. The fundamental reason for this is that the HOL-logic underlying
   199   terms. The fundamental reason is that the HOL-logic underlying
   200   Nominal Isabelle allows us to replace ``equals-by-equals''. In contrast,
   200   Nominal Isabelle allows us to replace ``equals-by-equals''. In contrast replacing 
   201   replacing ``alpha-equals-by-alpha-equals'' requires a lot of extra work.
   201   ``alpha-equals-by-alpha-equals'' in a term calculus requires a lot of extra reasoning work.
   202 
   202 
   203   
   203   
   204   Although in informal settings a reasoning infrastructure for alpha-equated 
   204   Although in informal settings a reasoning infrastructure for alpha-equated 
   205   terms that have names is nearly always taken for granted, establishing 
   205   terms (that have names for bound variables) is nearly always taken for granted, establishing 
   206   it automatically in a theorem prover is a rather non-trivial task. 
   206   it automatically in a theorem prover is a rather non-trivial task. 
   207   For every specification we will need to construct a type containing as 
   207   For every specification we will need to construct a type containing as 
   208   elements exactly those sets containing alpha-equal terms. To do so we use 
   208   elements the alpha-equated terms. To do so we use 
   209   the standard HOL-technique of defining a new type by  
   209   the standard HOL-technique of defining a new type by  
   210   identifying a non-empty subset of an existing type. In our 
   210   identifying a non-empty subset of an existing type. In our 
   211    we take as the starting point the type of sets of concrete
   211   case  we take as the starting point the type of sets of concrete
   212   terms (the latter being defined as datatypes). Then quotient these
   212   terms (the latter being defined as a datatype). Then identify the 
   213   sets according to our alpha-equivalence relation and then identifying
   213   alpha-equivalence classes according to our alpha-equivalence relation and 
   214   the new type as these alpha-equivalence classes.  The construction we 
   214   then identify the new type as these alpha-equivalence classes.  The construction we 
   215   can perform in HOL is illustrated by the following picture:
   215   can perform in HOL is illustrated by the following picture:
   216 
   216  
   217   
       
   218 
       
   219   Contributions:  We provide definitions for when terms
       
   220   involving general bindings are alpha-equivelent.
       
   221 
       
   222   \begin{center}
   217   \begin{center}
   223   figure
   218   figure
   224   %\begin{pspicture}(0.5,0.0)(8,2.5)
   219   %\begin{pspicture}(0.5,0.0)(8,2.5)
   225   %%\showgrid
   220   %%\showgrid
   226   %\psframe[linewidth=0.4mm,framearc=0.2](5,0.0)(7.7,2.5)
   221   %\psframe[linewidth=0.4mm,framearc=0.2](5,0.0)(7.7,2.5)
   368   \noindent
   363   \noindent
   369   {\bf Acknowledgements:} We are very grateful to Andrew Pitts for  
   364   {\bf Acknowledgements:} We are very grateful to Andrew Pitts for  
   370   many discussions about Nominal Isabelle. We thank Peter Sewell for 
   365   many discussions about Nominal Isabelle. We thank Peter Sewell for 
   371   making the informal notes \cite{SewellBestiary} available to us and 
   366   making the informal notes \cite{SewellBestiary} available to us and 
   372   also for explaining some of the finer points about the abstract 
   367   also for explaining some of the finer points about the abstract 
   373   definitions and about the implmentation of the Ott-tool.
   368   definitions and about the implementation of the Ott-tool.
   374 
   369 
   375 
   370 
   376 *}
   371 *}
   377 
   372 
   378 
   373