Paper/Paper.thy
changeset 2511 2ccf3086142b
parent 2510 734341a79028
child 2512 b5cb3183409e
equal deleted inserted replaced
2510:734341a79028 2511:2ccf3086142b
    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. The need of iterating single binders is also one reason
    91   why Nominal Isabelle and similar theorem provers that only provide
    91   why Nominal Isabelle 
    92   mechanisms for binding single variables have not fared extremely well with the
    92   % and similar theorem provers that only provide
       
    93   %mechanisms for binding single variables 
       
    94   has not fared extremely well with the
    93   more advanced tasks in the POPLmark challenge \cite{challenge05}, because
    95   more advanced tasks in the POPLmark challenge \cite{challenge05}, because
    94   also there one would like to bind multiple variables at once. 
    96   also there one would like to bind multiple variables at once. 
    95 
    97 
    96   Binding multiple variables has interesting properties that cannot be captured
    98   Binding multiple variables has interesting properties that cannot be captured
    97   easily by iterating single binders. For example in the case of type-schemes we do not
    99   easily by iterating single binders. For example in the case of type-schemes we do not
   200   %
   202   %
   201   \begin{center}
   203   \begin{center}
   202   \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}cl}
   204   \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}cl}
   203   @{text trm} & @{text "::="}  & @{text "\<dots>"} 
   205   @{text trm} & @{text "::="}  & @{text "\<dots>"} 
   204               & @{text "|"}  @{text "\<LET>  as::assn  s::trm"}\hspace{2mm} 
   206               & @{text "|"}  @{text "\<LET>  as::assn  s::trm"}\hspace{2mm} 
   205                                  \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}\\[1mm]
   207                                  \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}\\%%%[1mm]
   206   @{text assn} & @{text "::="} & @{text "\<ANIL>"}
   208   @{text assn} & @{text "::="} & @{text "\<ANIL>"}
   207                &  @{text "|"}  @{text "\<ACONS>  name  trm  assn"}
   209                &  @{text "|"}  @{text "\<ACONS>  name  trm  assn"}
   208   \end{tabular}
   210   \end{tabular}
   209   \end{center}
   211   \end{center}
   210   %
   212   %
   275   $\alpha$-equated terms. To do so, we use the standard HOL-technique of defining
   277   $\alpha$-equated terms. To do so, we use the standard HOL-technique of defining
   276   a new type by identifying a non-empty subset of an existing type.  The
   278   a new type by identifying a non-empty subset of an existing type.  The
   277   construction we perform in Isabelle/HOL can be illustrated by the following picture:
   279   construction we perform in Isabelle/HOL can be illustrated by the following picture:
   278   %
   280   %
   279   \begin{center}
   281   \begin{center}
   280   \begin{tikzpicture}[scale=0.9]
   282   \begin{tikzpicture}[scale=0.89]
   281   %\draw[step=2mm] (-4,-1) grid (4,1);
   283   %\draw[step=2mm] (-4,-1) grid (4,1);
   282   
   284   
   283   \draw[very thick] (0.7,0.4) circle (4.25mm);
   285   \draw[very thick] (0.7,0.4) circle (4.25mm);
   284   \draw[rounded corners=1mm, very thick] ( 0.0,-0.8) rectangle ( 1.8, 0.9);
   286   \draw[rounded corners=1mm, very thick] ( 0.0,-0.8) rectangle ( 1.8, 0.9);
   285   \draw[rounded corners=1mm, very thick] (-1.95,0.85) rectangle (-2.85,-0.05);
   287   \draw[rounded corners=1mm, very thick] (-1.95,0.85) rectangle (-2.85,-0.05);
   504 
   506 
   505   \begin{property}\label{swapfreshfresh}
   507   \begin{property}\label{swapfreshfresh}
   506   @{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
   508   @{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
   507   \end{property}
   509   \end{property}
   508 
   510 
   509   While often the support of an object can be relatively easily 
   511   %While often the support of an object can be relatively easily 
   510   described, for example for atoms, products, lists, function applications, 
   512   %described, for example for atoms, products, lists, function applications, 
   511   booleans and permutations as follows
   513   %booleans and permutations as follows
   512   %
   514   %%
   513   \begin{center}
   515   %\begin{center}
   514   \begin{tabular}{c@ {\hspace{10mm}}c}
   516   %\begin{tabular}{c@ {\hspace{10mm}}c}
   515   \begin{tabular}{rcl}
   517   %\begin{tabular}{rcl}
   516   @{term "supp a"} & $=$ & @{term "{a}"}\\
   518   %@{term "supp a"} & $=$ & @{term "{a}"}\\
   517   @{term "supp (x, y)"} & $=$ & @{term "supp x \<union> supp y"}\\
   519   %@{term "supp (x, y)"} & $=$ & @{term "supp x \<union> supp y"}\\
   518   @{term "supp []"} & $=$ & @{term "{}"}\\
   520   %@{term "supp []"} & $=$ & @{term "{}"}\\
   519   @{term "supp (x#xs)"} & $=$ & @{term "supp x \<union> supp xs"}\\
   521   %@{term "supp (x#xs)"} & $=$ & @{term "supp x \<union> supp xs"}\\
   520   \end{tabular}
   522   %\end{tabular}
   521   &
   523   %&
   522   \begin{tabular}{rcl}
   524   %\begin{tabular}{rcl}
   523   @{text "supp (f x)"} & @{text "\<subseteq>"} & @{term "supp f \<union> supp x"}\\
   525   %@{text "supp (f x)"} & @{text "\<subseteq>"} & @{term "supp f \<union> supp x"}\\
   524   @{term "supp b"} & $=$ & @{term "{}"}\\
   526   %@{term "supp b"} & $=$ & @{term "{}"}\\
   525   @{term "supp p"} & $=$ & @{term "{a. p \<bullet> a \<noteq> a}"}
   527   %@{term "supp p"} & $=$ & @{term "{a. p \<bullet> a \<noteq> a}"}
   526   \end{tabular}
   528   %\end{tabular}
   527   \end{tabular}
   529   %\end{tabular}
   528   \end{center}
   530   %\end{center}
   529   
   531   %
   530   \noindent 
   532   %\noindent 
   531   in some cases it can be difficult to characterise the support precisely, and
   533   %in some cases it can be difficult to characterise the support precisely, and
   532   only an approximation can be established (as for functions above). 
   534   %only an approximation can be established (as for functions above). 
   533 
   535 
   534   %Reasoning about
   536   %Reasoning about
   535   %such approximations can be simplified with the notion \emph{supports}, defined 
   537   %such approximations can be simplified with the notion \emph{supports}, defined 
   536   %as follows:
   538   %as follows:
   537   %
   539   %
   574   %that
   576   %that
   575   %%
   577   %%
   576   %\begin{center}
   578   %\begin{center}
   577   %@{text "x R y"} \;\;\textit{implies}\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"}
   579   %@{text "x R y"} \;\;\textit{implies}\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"}
   578   %\end{center}
   580   %\end{center}
   579 
   581   %
   580   Using support and freshness, the nominal logic work provides us with general means for renaming 
   582   %Using freshness, the nominal logic work provides us with general means for renaming 
   581   binders. While in the older version of Nominal Isabelle, we used extensively 
   583   %binders. 
   582   Property~\ref{swapfreshfresh} to rename single binders, this property 
   584   %
       
   585   \noindent
       
   586   While in the older version of Nominal Isabelle, we used extensively 
       
   587   %Property~\ref{swapfreshfresh}
       
   588   this property to rename single binders, it %%this property 
   583   proved too unwieldy for dealing with multiple binders. For such binders the 
   589   proved too unwieldy for dealing with multiple binders. For such binders the 
   584   following generalisations turned out to be easier to use.
   590   following generalisations turned out to be easier to use.
   585 
   591 
   586   \begin{property}\label{supppermeq}
   592   \begin{property}\label{supppermeq}
   587   @{thm[mode=IfThen] supp_perm_eq[no_vars]}
   593   @{thm[mode=IfThen] supp_perm_eq[no_vars]}
   878   %
   884   %
   879   \begin{equation}\label{scheme}
   885   \begin{equation}\label{scheme}
   880   \mbox{\begin{tabular}{@ {}p{2.5cm}l}
   886   \mbox{\begin{tabular}{@ {}p{2.5cm}l}
   881   type \mbox{declaration part} &
   887   type \mbox{declaration part} &
   882   $\begin{cases}
   888   $\begin{cases}
   883   \mbox{\begin{tabular}{l}
   889   \mbox{\small\begin{tabular}{l}
   884   \isacommand{nominal\_datatype} @{text "ty\<AL>\<^isub>1 = \<dots>"}\\
   890   \isacommand{nominal\_datatype} @{text "ty\<AL>\<^isub>1 = \<dots>"}\\
   885   \isacommand{and} @{text "ty\<AL>\<^isub>2 = \<dots>"}\\
   891   \isacommand{and} @{text "ty\<AL>\<^isub>2 = \<dots>"}\\
   886   \raisebox{2mm}{$\ldots$}\\[-2mm] 
   892   \raisebox{2mm}{$\ldots$}\\[-2mm] 
   887   \isacommand{and} @{text "ty\<AL>\<^isub>n = \<dots>"}\\ 
   893   \isacommand{and} @{text "ty\<AL>\<^isub>n = \<dots>"}\\ 
   888   \end{tabular}}
   894   \end{tabular}}
   889   \end{cases}$\\
   895   \end{cases}$\\
   890   binding \mbox{function part} &
   896   binding \mbox{function part} &
   891   $\begin{cases}
   897   $\begin{cases}
   892   \mbox{\begin{tabular}{l}
   898   \mbox{\small\begin{tabular}{l}
   893   \isacommand{binder} @{text "bn\<AL>\<^isub>1"} \isacommand{and} \ldots \isacommand{and} @{text "bn\<AL>\<^isub>m"}\\
   899   \isacommand{binder} @{text "bn\<AL>\<^isub>1"} \isacommand{and} \ldots \isacommand{and} @{text "bn\<AL>\<^isub>m"}\\
   894   \isacommand{where}\\
   900   \isacommand{where}\\
   895   \raisebox{2mm}{$\ldots$}\\[-2mm]
   901   \raisebox{2mm}{$\ldots$}\\[-2mm]
   896   \end{tabular}}
   902   \end{tabular}}
   897   \end{cases}$\\
   903   \end{cases}$\\
   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   \begin{center}\small
   983   \begin{center}
       
   984   \begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}}
   989   \begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}}
   985   \begin{tabular}{@ {}l}
   990   \begin{tabular}{@ {}l}
   986   \isacommand{nominal\_datatype} @{text lam} $=$\\
   991   \isacommand{nominal\_datatype} @{text lam} $=$\\
   987   \hspace{5mm}\phantom{$\mid$}~@{text "Var name"}\\
   992   \hspace{5mm}\phantom{$\mid$}~@{text "Var name"}\\
   988   \hspace{5mm}$\mid$~@{text "App lam lam"}\\
   993   \hspace{5mm}$\mid$~@{text "App lam lam"}\\
  1018   must be given in the binding function part of the scheme shown in
  1023   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
  1024   \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
  1020   tuple patterns might be specified as:
  1025   tuple patterns might be specified as:
  1021   %
  1026   %
  1022   \begin{equation}\label{letpat}
  1027   \begin{equation}\label{letpat}
  1023   \mbox{%
  1028   \mbox{\small%
  1024   \begin{tabular}{l}
  1029   \begin{tabular}{l}
  1025   \isacommand{nominal\_datatype} @{text trm} =\\
  1030   \isacommand{nominal\_datatype} @{text trm} =\\
  1026   \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\
  1031   \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\
  1027   \hspace{5mm}$\mid$~@{term "App trm trm"}\\
  1032   \hspace{5mm}$\mid$~@{term "App trm trm"}\\
  1028   \hspace{5mm}$\mid$~@{text "Lam x::name t::trm"} 
  1033   \hspace{5mm}$\mid$~@{text "Lam x::name t::trm"} 
  1061   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1066   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1062   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1067   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1063   specification:
  1068   specification:
  1064   %
  1069   %
  1065   \begin{equation}\label{letrecs}
  1070   \begin{equation}\label{letrecs}
  1066   \mbox{%
  1071   \mbox{\small%
  1067   \begin{tabular}{@ {}l@ {}}
  1072   \begin{tabular}{@ {}l@ {}}
  1068   \isacommand{nominal\_datatype}~@{text "trm ="}\ldots\\
  1073   \isacommand{nominal\_datatype}~@{text "trm ="}\ldots\\
  1069   \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} 
  1074   \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} 
  1070      \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text t}\\
  1075      \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text t}\\
  1071   \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"}
  1076   \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"}
  1130   for every argument of a term-constructor that is \emph{not} 
  1135   for every argument of a term-constructor that is \emph{not} 
  1131   already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
  1136   already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
  1132   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
  1137   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
  1133   of the lambda-terms, the completion produces
  1138   of the lambda-terms, the completion produces
  1134 
  1139 
  1135   \begin{center}
  1140   \begin{center}\small
  1136   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
  1141   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
  1137   \isacommand{nominal\_datatype} @{text lam} =\\
  1142   \isacommand{nominal\_datatype} @{text lam} =\\
  1138   \hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"}
  1143   \hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"}
  1139     \;\;\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "x"}\\
  1144     \;\;\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "x"}\\
  1140   \hspace{5mm}$\mid$~@{text "App t\<^isub>1::lam t\<^isub>2::lam"}
  1145   \hspace{5mm}$\mid$~@{text "App t\<^isub>1::lam t\<^isub>2::lam"}
  1170   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1175   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1171   given by the user. In our implementation we just use the affix ``@{text "_raw"}''.
  1176   given by the user. In our implementation we just use the affix ``@{text "_raw"}''.
  1172   But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1177   But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1173   that a notion is given for $\alpha$-equivalence classes and leave it out 
  1178   that a notion is given for $\alpha$-equivalence classes and leave it out 
  1174   for the corresponding notion given on the ``raw'' level. So for example 
  1179   for the corresponding notion given on the ``raw'' level. So for example 
  1175   we have
  1180   we have @{text "ty\<^sup>\<alpha> \<mapsto> ty"} and @{text "C\<^sup>\<alpha> \<mapsto> C"}
  1176   
       
  1177   \begin{center}
       
  1178   @{text "ty\<^sup>\<alpha> \<mapsto> ty"} \hspace{2mm}and\hspace{2mm} @{text "C\<^sup>\<alpha> \<mapsto> C"}
       
  1179   \end{center}
       
  1180   
       
  1181   \noindent
       
  1182   where @{term ty} is the type used in the quotient construction for 
  1181   where @{term ty} is the type used in the quotient construction for 
  1183   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. 
  1182   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. 
  1184 
  1183 
  1185   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1184   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1186   non-empty and the types in the constructors only occur in positive 
  1185   non-empty and the types in the constructors only occur in positive 
  2231   Once we feel confident about such binding modes, our implementation 
  2230   Once we feel confident about such binding modes, our implementation 
  2232   can be easily extended to accommodate them.
  2231   can be easily extended to accommodate them.
  2233 
  2232 
  2234   \medskip
  2233   \medskip
  2235   \noindent
  2234   \noindent
  2236   {\bf Acknowledgements:} We are very grateful to Andrew Pitts for  
  2235   {\bf Acknowledgements:} %We are very grateful to Andrew Pitts for  
  2237   many discussions about Nominal Isabelle. We also thank Peter Sewell for 
  2236   %many discussions about Nominal Isabelle. 
       
  2237   We thank Peter Sewell for 
  2238   making the informal notes \cite{SewellBestiary} available to us and 
  2238   making the informal notes \cite{SewellBestiary} available to us and 
  2239   also for patiently explaining some of the finer points of the work on the Ott-tool.
  2239   also for patiently explaining some of the finer points of the work on the Ott-tool.
  2240   Stephanie Weirich suggested to separate the subgrammars
  2240   %Stephanie Weirich suggested to separate the subgrammars
  2241   of kinds and types in our Core-Haskell example.  
  2241   %of kinds and types in our Core-Haskell example.  
  2242 
  2242 
  2243 *}
  2243 *}
  2244 
  2244 
  2245 (*<*)
  2245 (*<*)
  2246 end
  2246 end