LMCS-Paper/Paper.thy
changeset 3129 8be3155c014f
parent 3128 4bad521e3b9e
child 3130 8fc6b801985b
equal deleted inserted replaced
3128:4bad521e3b9e 3129:8be3155c014f
   113   \noindent
   113   \noindent
   114   and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of
   114   and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of
   115   type-variables.  While it is possible to implement this kind of more general
   115   type-variables.  While it is possible to implement this kind of more general
   116   binders by iterating single binders, like @{text "\<forall>x\<^isub>1.\<forall>x\<^isub>2...\<forall>x\<^isub>n.T"}, this leads to a rather clumsy
   116   binders by iterating single binders, like @{text "\<forall>x\<^isub>1.\<forall>x\<^isub>2...\<forall>x\<^isub>n.T"}, this leads to a rather clumsy
   117   formalisation of W. For example, the usual definition when a 
   117   formalisation of W. For example, the usual definition when a 
   118   type is an instance of a type-scheme requires the following auxiliary \emph{unbinding relation}
   118   type is an instance of a type-scheme requires in the iterated version 
       
   119   the following auxiliary \emph{unbinding relation}
   119 
   120 
   120   \[
   121   \[
   121   \infer{@{text T} \hookrightarrow ([], @{text T})}{}\qquad
   122   \infer{@{text T} \hookrightarrow ([], @{text T})}{}\qquad
   122   \infer{\forall @{text x.S} \hookrightarrow (@{text x}\!::\!@{text xs}, @{text T})}
   123   \infer{\forall @{text x.S} \hookrightarrow (@{text x}\!::\!@{text xs}, @{text T})}
   123    {@{text S} \hookrightarrow (@{text xs}, @{text T})}
   124    {@{text S} \hookrightarrow (@{text xs}, @{text T})}
   124   \]\smallskip
   125   \]\smallskip
   125 
   126 
   126   \noindent
   127   \noindent
   127   which relates a type-scheme with a list of variables and a type. The point of this
   128   which relates a type-scheme with a list of type-variables and a type. The point of this
   128   definition is to get access to the bound variables and the type-part of a type-scheme
   129   definition is: given a type-scheme @{text S}, how to get access to the bound type-variables 
   129   @{text S}, though in general 
   130   and the type-part of this type-scheme? The unbinding relation gives an answer, though in general 
   130   we will only get access to some variables and some type @{text T} that are  
   131   we will only get access to some type-variables and some type that are  
   131   ``alpha-equivalent'' to @{text S}. This is because unbinding is a relation, not a function. 
   132   ``alpha-equivalent'' to @{text S}. This is because unbinding is a relation; it cannot be a function
       
   133   for alpha-equated type-schemes. 
   132   Still, with this 
   134   Still, with this 
   133   definition in place we can formally define when a type is an instance of a type-scheme as
   135   definition in place we can formally define when a type is an instance of a type-scheme as
   134 
   136 
   135   \[
   137   \[
   136   @{text "T \<prec> S \<equiv> \<exists>xs T' \<sigma>. S \<hookrightarrow> (xs, T') \<and> dom \<sigma> = set xs \<and> \<sigma>(T') = T"}
   138   @{text "T \<prec> S \<equiv> \<exists>xs T' \<sigma>. S \<hookrightarrow> (xs, T') \<and> dom \<sigma> = set xs \<and> \<sigma>(T') = T"}
   137   \]\smallskip
   139   \]\smallskip
   138   
   140   
   139   \noindent
   141   \noindent
   140   meaning there exists a list of variables @{text xs} and a type @{text T'} to which
   142   meaning there exists a list of type-variables @{text xs} and a type @{text T'} to which
   141   the type-scheme @{text S} unbinds, and there exists a substitution whose domain is
   143   the type-scheme @{text S} unbinds, and there exists a substitution whose domain is
   142   @{text xs} (seen as set) such that @{text "\<sigma>(T') = T"}.
   144   @{text xs} (seen as set) such that @{text "\<sigma>(T') = T"}.
   143   The problem with this definition is that we cannot follow the usual proofs 
   145   The problem with this definition is that we cannot follow the usual proofs 
   144   that are by induction on the type-part of the type-scheme (since it is under
   146   that are by induction on the type-part of the type-scheme (since it is under
   145   an existential quantifier). The representation of type-schemes using iterations of single binders 
   147   an existential quantifier and only an alpha-variant). The representation of 
   146   prevents us from directly ``unbinding'' the bound variables and the type-part of 
   148   type-schemes using iterations of single binders 
   147   a type-scheme. The purpose of this paper is to introduce general binders, which 
   149   prevents us from directly ``unbinding'' the bound thye-variables and the type-part. 
       
   150   The purpose of this paper is to introduce general binders, which 
   148   allow us to represent type-schemes so that they can bind multiple variables at once
   151   allow us to represent type-schemes so that they can bind multiple variables at once
   149   and as a result solve this problem.
   152   and as a result solve this problem.
   150   The need of iterating single binders is also one reason
   153   The need of iterating single binders is also one reason
   151   why Nominal Isabelle and similar theorem provers that only provide
   154   why Nominal Isabelle and similar theorem provers that only provide
   152   mechanisms for binding single variables have not fared extremely well with
   155   mechanisms for binding single variables have so far not fared very well with
   153   the more advanced tasks in the POPLmark challenge \cite{challenge05},
   156   the more advanced tasks in the POPLmark challenge \cite{challenge05},
   154   because also there one would like to bind multiple variables at once.
   157   because also there one would like to bind multiple variables at once.
   155 
   158 
   156   Binding multiple variables has interesting properties that cannot be captured
   159   Binding multiple variables has interesting properties that cannot be captured
   157   easily by iterating single binders. For example in the case of type-schemes we do not
   160   easily by iterating single binders. For example in the case of type-schemes we do not
   498   ourselves in what follows to only one sort of atoms.
   501   ourselves in what follows to only one sort of atoms.
   499 
   502 
   500   Permutations are bijective functions from atoms to atoms that are 
   503   Permutations are bijective functions from atoms to atoms that are 
   501   the identity everywhere except on a finite number of atoms. There is a 
   504   the identity everywhere except on a finite number of atoms. There is a 
   502   two-place permutation operation written
   505   two-place permutation operation written
   503   @{text "_ \<bullet> _  ::  perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
   506   @{text "_ \<bullet> _ "} and having the type @{text "perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
   504   where the generic type @{text "\<beta>"} is the type of the object 
   507   where the generic type @{text "\<beta>"} is the type of the object 
   505   over which the permutation 
   508   over which the permutation 
   506   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   509   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   507   the composition of two permutations @{term "\<pi>\<^isub>1"} and @{term "\<pi>\<^isub>2"} as \mbox{@{term "\<pi>\<^isub>1 + \<pi>\<^isub>2"}}, 
   510   the composition of two permutations @{term "\<pi>\<^isub>1"} and @{term "\<pi>\<^isub>2"} as \mbox{@{term "\<pi>\<^isub>1 + \<pi>\<^isub>2"}}, 
   508   and the inverse permutation of @{term "\<pi>"} as @{text "- \<pi>"}. The permutation
   511   and the inverse permutation of @{term "\<pi>"} as @{text "- \<pi>"}. The permutation
   621   \begin{equation}\label{equivariancedef}
   624   \begin{equation}\label{equivariancedef}
   622   @{term "\<forall>\<pi>. \<pi> \<bullet> f = f"}\;.
   625   @{term "\<forall>\<pi>. \<pi> \<bullet> f = f"}\;.
   623   \end{equation}\smallskip
   626   \end{equation}\smallskip
   624   
   627   
   625   \noindent
   628   \noindent
   626   If a function is of type @{text "\<alpha> \<Rightarrow> \<beta>"}, this definition is equivalent to 
   629   If a function is of type @{text "\<alpha> \<Rightarrow> \<beta>"}, say, this definition is equivalent to 
   627   the fact that a permutation applied to the application
   630   the fact that a permutation applied to the application
   628   @{text "f x"} can be moved to the argument @{text x}. That means for 
   631   @{text "f x"} can be moved to the argument @{text x}. That means for 
   629   such functions, we have for all permutations @{text "\<pi>"}:
   632   such functions, we have for all permutations @{text "\<pi>"}:
   630   
   633   
   631   \begin{equation}\label{equivariance}
   634   \begin{equation}\label{equivariance}
   896   @{thm (lhs) Abs_eq_iff(1)[where bs="as" and bs'="bs", no_vars]} \;\;\;\text{if and only if}\;\;\; 
   899   @{thm (lhs) Abs_eq_iff(1)[where bs="as" and bs'="bs", no_vars]} \;\;\;\text{if and only if}\;\;\; 
   897   @{term "alpha_set_ex (as, x) equal supp (bs, y)"}
   900   @{term "alpha_set_ex (as, x) equal supp (bs, y)"}
   898   \end{equation}\smallskip
   901   \end{equation}\smallskip
   899   
   902   
   900   \noindent
   903   \noindent
   901   and also
   904   and also set
   902   
   905   
   903   \begin{equation}\label{absperm}
   906   \begin{equation}\label{absperm}
   904   @{thm permute_Abs(1)[where p="\<pi>", no_vars]}
   907   @{thm permute_Abs(1)[where p="\<pi>", no_vars, THEN eq_reflection]}
   905   \end{equation}\smallskip
   908   \end{equation}\smallskip
   906 
   909 
   907   \noindent
   910   \noindent
   908   The second fact derives from the definition of permutations acting on pairs 
   911   With this at our disposal, we can show 
   909   \eqref{permute} and alpha-equivalence being equivariant 
       
   910   (see Lemma~\ref{alphaeq}). With these two facts at our disposal, we can show 
       
   911   the following lemma about swapping two atoms in an abstraction.
   912   the following lemma about swapping two atoms in an abstraction.
   912   
   913   
   913   \begin{lem}
   914   \begin{lem}
   914   If @{thm (prem 1) Abs_swap1(1)[where bs="as", no_vars]} and
   915   If @{thm (prem 1) Abs_swap1(1)[where bs="as", no_vars]} and
   915   @{thm (prem 2) Abs_swap1(1)[where bs="as", no_vars]} then 
   916   @{thm (prem 2) Abs_swap1(1)[where bs="as", no_vars]} then 
   961   @{thm (concl) Abs_supp_subset1(1)[no_vars]}
   962   @{thm (concl) Abs_supp_subset1(1)[no_vars]}
   962   \end{equation}\smallskip
   963   \end{equation}\smallskip
   963   
   964   
   964   \noindent
   965   \noindent
   965   This is because for every finite set of atoms, say @{text "bs"}, we have 
   966   This is because for every finite set of atoms, say @{text "bs"}, we have 
   966   @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}.
   967   @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}.\footnote{Note that this is not 
       
   968   the case for infinite sets.}
   967   Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes 
   969   Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes 
   968   the first equation of Theorem~\ref{suppabs}. The others are similar.
   970   the first equation of Theorem~\ref{suppabs}. The others are similar.
   969 
   971 
   970   Recall the definition of support given in \eqref{suppdef}, and note the difference between 
   972   Recall the definition of support given in \eqref{suppdef}, and note the difference between 
   971   the support of a raw pair and an abstraction
   973   the support of a raw pair and an abstraction
  1041   \eqref{scheme}. In this case we will call the corresponding argument a
  1043   \eqref{scheme}. In this case we will call the corresponding argument a
  1042   \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such
  1044   \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such
  1043   recursive arguments need to satisfy a `positivity' restriction, which
  1045   recursive arguments need to satisfy a `positivity' restriction, which
  1044   ensures that the type has a set-theoretic semantics (see
  1046   ensures that the type has a set-theoretic semantics (see
  1045   \cite{Berghofer99}). If the types are polymorphic, we require the
  1047   \cite{Berghofer99}). If the types are polymorphic, we require the
  1046   type variables stand for types that are finitely supported and over which 
  1048   type variables to stand for types that are finitely supported and over which 
  1047   a permutation operation is defined.
  1049   a permutation operation is defined.
  1048   The labels @{text "label"}$_{1..l}$ annotated on the types are optional. Their
  1050   The labels @{text "label"}$_{1..l}$ annotated on the types are optional. Their
  1049   purpose is to be used in the (possibly empty) list of \emph{binding
  1051   purpose is to be used in the (possibly empty) list of \emph{binding
  1050   clauses}, which indicate the binders and their scope in a term-constructor.
  1052   clauses}, which indicate the binders and their scope in a term-constructor.
  1051   They come in three \emph{modes}:
  1053   They come in three \emph{modes}:
  1198   specification:
  1200   specification:
  1199  
  1201  
  1200   \begin{equation}\label{letrecs}
  1202   \begin{equation}\label{letrecs}
  1201   \mbox{%
  1203   \mbox{%
  1202   \begin{tabular}{@ {}l@ {}l}
  1204   \begin{tabular}{@ {}l@ {}l}
  1203   \isacommand{nominal\_datatype}~@{text "trm ="}~\ldots\\
  1205   \isacommand{nominal\_datatype}~@{text "trm ="}\\
       
  1206   \hspace{5mm}\phantom{$\mid$}~\ldots\\
  1204   \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} 
  1207   \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} 
  1205      & \hspace{-19mm}\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text t}\\
  1208      & \hspace{-19mm}\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text t}\\
  1206   \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"}
  1209   \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"}
  1207      & \hspace{-19mm}\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\
  1210      & \hspace{-19mm}\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\
  1208   \isacommand{and} @{text "assn"} $=$\\
  1211   \isacommand{and} @{text "assn"} $=$\\
  1234   \end{tabular}}
  1237   \end{tabular}}
  1235   \]\smallskip
  1238   \]\smallskip
  1236 
  1239 
  1237   \noindent
  1240   \noindent
  1238   Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"}  pick 
  1241   Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"}  pick 
  1239   out different atoms to become bound, respectively be free, in @{text "p"}.
  1242   out different atoms to become bound, respectively be free, 
  1240   (Since the Ott-tool does not derive a reasoning infrastructure for 
  1243   in @{text "p"}.\footnote{Although harmless, in our implementation 
  1241   alpha-equated terms with deep binders, it can permit such specifications.)
  1244   we exlude such specifications even 
  1242   For convenience we exlude such specifications even if @{text "bn\<^isub>1"} and 
  1245   if @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} are the same binding 
  1243   @{text "bn\<^isub>2"} are the same binding functions, which would otherwise be harmless.
  1246   functions.}$^,$\footnote{Since the Ott-tool does not derive a reasoning 
       
  1247   infrastructure for 
       
  1248   alpha-equated terms with deep binders, it can permit such specifications.}
       
  1249   
  1244 
  1250 
  1245   We also need to restrict the form of the binding functions in order to
  1251   We also need to restrict the form of the binding functions in order to
  1246   ensure the @{text "bn"}-functions can be defined for alpha-equated
  1252   ensure the @{text "bn"}-functions can be defined for alpha-equated
  1247   terms. The main restriction is that we cannot return an atom in a binding
  1253   terms. The main restriction is that we cannot return an atom in a binding
  1248   function that is also bound in the corresponding term-constructor.
  1254   function that is also bound in the corresponding term-constructor.
  2226   As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
  2232   As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
  2227   which we lifted in the previous section and which are all well-founded. It
  2233   which we lifted in the previous section and which are all well-founded. It
  2228   is straightforward to establish that the sizes decrease in every
  2234   is straightforward to establish that the sizes decrease in every
  2229   induction step. What is left to show is that we covered all cases. 
  2235   induction step. What is left to show is that we covered all cases. 
  2230   To do so, we have to derive stronger cases lemmas, which look in our
  2236   To do so, we have to derive stronger cases lemmas, which look in our
  2231   running example are as follows:
  2237   running example as follows:
  2232 
  2238 
  2233   \[\mbox{
  2239   \[\mbox{
  2234   \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}
  2240   \begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}
  2235   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  2241   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  2236   {\begin{array}{@ {}l@ {}}
  2242   {\begin{array}{@ {}l@ {}}