Paper/Paper.thy
changeset 1961 774d631726ad
parent 1957 47430fe78912
child 2128 abd46dfc0212
equal deleted inserted replaced
1960:47e2e91705f3 1961:774d631726ad
   919   preserving alpha-equivalence). The ``\isacommand{in}-part'' of a binding
   919   preserving alpha-equivalence). The ``\isacommand{in}-part'' of a binding
   920   clause will be called \emph{bodies} (there can be more than one); the 
   920   clause will be called \emph{bodies} (there can be more than one); the 
   921   ``\isacommand{bind}-part'' will be called \emph{binders}. 
   921   ``\isacommand{bind}-part'' will be called \emph{binders}. 
   922 
   922 
   923   In contrast to Ott, we allow multiple labels in binders and bodies. For example
   923   In contrast to Ott, we allow multiple labels in binders and bodies. For example
   924   we permit binding clauses as follows:
   924   we have binding clauses of the form:
   925 
   925 
   926   \begin{center}
   926   \begin{center}
   927   \begin{tabular}{ll}
   927   \begin{tabular}{ll}
   928   @{text "Foo x::name y::name t::lam s::lam"} &  
   928   @{text "Foo x::name y::name t::lam s::lam"} &  
   929       \isacommand{bind} @{text "x y"} \isacommand{in} @{text "t s"}  
   929       \isacommand{bind} @{text "x y"} \isacommand{in} @{text "t s"}  
   930   \end{tabular}
   930   \end{tabular}
   931   \end{center}
   931   \end{center}
   932 
   932 
   933   \noindent
   933   \noindent
       
   934   Similarly for the other binding modes.
   934   There are a few restrictions we need to impose: First, a body can only occur in
   935   There are a few restrictions we need to impose: First, a body can only occur in
   935   \emph{one} binding clause of a term constructor. A binder, in contrast, may
   936   \emph{one} binding clause of a term constructor. 
   936   occur in several binding clauses, but cannot occur as a body.
   937 
   937 
   938   For binders we distinguish between \emph{shallow} and \emph{deep} binders.
   938   In addition we distinguish between \emph{shallow} and \emph{deep}
   939   Shallow binders are of the form \isacommand{bind}\; {\it labels}\;
   939   binders.  Shallow binders are of the form \isacommand{bind}\; {\it labels}\;
       
   940   \isacommand{in}\; {\it labels'} (similar for the other two modes). The
   940   \isacommand{in}\; {\it labels'} (similar for the other two modes). The
   941   restriction we impose on shallow binders is that the {\it labels} must either
   941   restriction we impose on shallow binders is that in case of
   942   refer to atom types or to finite sets or
   942   \isacommand{bind\_set} and \isacommand{bind\_res} the {\it labels} must
   943   lists of atom types. Two examples for the use of shallow binders are the
   943   either refer to atom types or to sets of atom types; in case of
   944   specification of lambda-terms, where a single name is bound, and 
   944   \isacommand{bind} we allow labels to atom types or lists of atom types. Two
   945   type-schemes, where a finite set of names is bound:
   945   examples for the use of shallow binders are the specification of
       
   946   lambda-terms, where a single name is bound, and type-schemes, where a finite
       
   947   set of names is bound:
   946 
   948 
   947   \begin{center}
   949   \begin{center}
   948   \begin{tabular}{@ {}cc@ {}}
   950   \begin{tabular}{@ {}cc@ {}}
   949   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   951   \begin{tabular}{@ {}l@ {\hspace{-1mm}}}
   950   \isacommand{nominal\_datatype} @{text lam} =\\
   952   \isacommand{nominal\_datatype} @{text lam} =\\
   963   \end{tabular}
   965   \end{tabular}
   964   \end{center}
   966   \end{center}
   965 
   967 
   966   \noindent
   968   \noindent
   967   Note that in this specification @{text "name"} refers to an atom type, and
   969   Note that in this specification @{text "name"} refers to an atom type, and
   968   @{text "fset"} to the type of finite sets.
   970   @{text "fset"} to the type of finite sets. Shallow binders can occur in the 
       
   971   binding part of several binding clauses. 
   969  
   972  
   970   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
   973   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
   971   the atoms in one argument of the term-constructor, which can be bound in  
   974   the atoms in one argument of the term-constructor, which can be bound in  
   972   other arguments and also in the same argument (we will
   975   other arguments and also in the same argument (we will
   973   call such binders \emph{recursive}, see below). 
   976   call such binders \emph{recursive}, see below). 
  1003   In this specification the function @{text "bn"} determines which atoms of @{text  p} are
  1006   In this specification the function @{text "bn"} determines which atoms of @{text  p} are
  1004   bound in the argument @{text "t"}. Note that in the second-last clause the function @{text "atom"}
  1007   bound in the argument @{text "t"}. Note that in the second-last clause the function @{text "atom"}
  1005   coerces a name into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This allows
  1008   coerces a name into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This allows
  1006   us to treat binders of different atom type uniformly. 
  1009   us to treat binders of different atom type uniformly. 
  1007 
  1010 
  1008   As will shortly become clear, we cannot return an atom in a binding function
       
  1009   that is also bound in the corresponding term-constructor. That means in the
       
  1010   example above that the term-constructors @{text PVar} and @{text PTup} may not have a
       
  1011   binding clause.  In the version of Nominal Isabelle described here, we also adopted
       
  1012   the restriction from the Ott-tool that binding functions can only return:
       
  1013   the empty set or empty list (as in case @{text PNil}), a singleton set or singleton
       
  1014   list containing an atom (case @{text PVar}), or unions of atom sets or appended atom
       
  1015   lists (case @{text PTup}). This restriction will simplify definitions and 
       
  1016   proofs later on.
       
  1017   
       
  1018   The most drastic restriction we have to impose on deep binders is that 
  1011   The most drastic restriction we have to impose on deep binders is that 
  1019   we cannot have ``overlapping'' deep binders. Consider for example the 
  1012   we cannot have ``overlapping'' deep binders. Consider for example the 
  1020   term-constructors:
  1013   term-constructors:
  1021 
  1014 
  1022   \begin{center}
  1015   \begin{center}
  1045      \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p t"}\\
  1038      \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p t"}\\
  1046   \end{tabular}
  1039   \end{tabular}
  1047   \end{center}
  1040   \end{center}
  1048 
  1041 
  1049   \noindent
  1042   \noindent
  1050   since there is no overlap of binders.
  1043   since there is no overlap of binders. Unlike shallow binders, we restrict deep
  1051   
  1044   binders to occur in only one binding clause. Therefore @{text "Bar\<^isub>2"} cannot 
  1052   Note that in the last example we wrote \isacommand{bind}~@{text
  1045   be reformulated as
  1053   "bn(p)"}~\isacommand{in}~@{text "p.."}.  Whenever such a binding clause is
  1046 
  1054   present, we will call the corresponding binder \emph{recursive}.  To see the
  1047   \begin{center}
       
  1048   \begin{tabular}{ll}
       
  1049   @{text "Bar\<^isub>3 p::pat t::trm"} &  
       
  1050      \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p"}, 
       
  1051      \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "t"}\\
       
  1052   \end{tabular}
       
  1053   \end{center}
       
  1054   
       
  1055   Note that in the @{text "Bar\<^isub>2"}, we wrote \isacommand{bind}~@{text
       
  1056   "bn(p)"}~\isacommand{in}~@{text "p.."}.  Whenever such a binding clause 
       
  1057   is present, where the argument in the binder also occurs in the body, we will 
       
  1058   call the corresponding binder \emph{recursive}.  To see the
  1055   purpose of such recursive binders, compare ``plain'' @{text "Let"}s and
  1059   purpose of such recursive binders, compare ``plain'' @{text "Let"}s and
  1056   @{text "Let_rec"}s in the following specification:
  1060   @{text "Let_rec"}s in the following specification:
  1057   %
  1061   %
  1058   \begin{equation}\label{letrecs}
  1062   \begin{equation}\label{letrecs}
  1059   \mbox{%
  1063   \mbox{%
  1077   The difference is that with @{text Let} we only want to bind the atoms @{text
  1081   The difference is that with @{text Let} we only want to bind the atoms @{text
  1078   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1082   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1079   inside the assignment. This difference has consequences for the free-variable 
  1083   inside the assignment. This difference has consequences for the free-variable 
  1080   function and alpha-equivalence relation, which we are going to describe in the 
  1084   function and alpha-equivalence relation, which we are going to describe in the 
  1081   rest of this section.
  1085   rest of this section.
  1082  
  1086 
  1083   In order to simplify some definitions, we shall assume specifications 
  1087   We also need to restrict the form of the binding functions. As will shortly
       
  1088   become clear, we cannot return an atom in a binding function that is also
       
  1089   bound in the corresponding term-constructor. That means in the example
       
  1090   \eqref{letpat} that the term-constructors @{text PVar} and @{text PTup} may
       
  1091   not have a binding clause (all arguments are used to define @{text "bn"}).
       
  1092   In contrast, in case of \eqref{letrecs} the term-constructor @{text ACons}
       
  1093   may have binding clause involving the argument @{text t} (the only one that
       
  1094   is \emph{not} used in the definition of the binding function).  In the version of
       
  1095   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
       
  1097   (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
       
  1099   (case @{text PTup}). This restriction will simplify some automatic proofs
       
  1100   later on.
       
  1101   
       
  1102   In order to simplify some later definitions, we shall assume specifications 
  1084   of term-calculi are \emph{completed}. By this we mean that  
  1103   of term-calculi are \emph{completed}. By this we mean that  
  1085   for every argument of a term-constructor that is \emph{not} 
  1104   for every argument of a term-constructor that is \emph{not} 
  1086   already part of a binding clause, we add implicitly a special \emph{empty} binding
  1105   already part of a binding clause, we add implicitly a special \emph{empty} binding
  1087   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "label"}. In case
  1106   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "label"}. In case
  1088   of the lambda-calculus, the completion produces
  1107   of the lambda-calculus, the completion produces
  1100   \end{tabular}
  1119   \end{tabular}
  1101   \end{center}
  1120   \end{center}
  1102 
  1121 
  1103   \noindent 
  1122   \noindent 
  1104   The point of completion is that we can make definitions over the binding
  1123   The point of completion is that we can make definitions over the binding
  1105   clauses and be sure to capture all arguments of a term constructor. 
  1124   clauses and be sure to have captured all arguments of a term constructor. 
  1106 
  1125 
  1107   Having dealt with all syntax matters, the problem now is how we can turn
  1126   Having dealt with all syntax matters, the problem now is how we can turn
  1108   specifications into actual type definitions in Isabelle/HOL and then
  1127   specifications into actual type definitions in Isabelle/HOL and then
  1109   establish a reasoning infrastructure for them. As
  1128   establish a reasoning infrastructure for them. As
  1110   Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just 
  1129   Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just 
  1140   raw datatype. We can also easily define permutation operations by 
  1159   raw datatype. We can also easily define permutation operations by 
  1141   primitive recursion so that for each term constructor @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"} 
  1160   primitive recursion so that for each term constructor @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"} 
  1142   we have that
  1161   we have that
  1143   %
  1162   %
  1144   \begin{equation}\label{ceqvt}
  1163   \begin{equation}\label{ceqvt}
  1145   @{text "p \<bullet> (C x\<^isub>1 \<dots> x\<^isub>n) = C (p \<bullet> x\<^isub>1) \<dots> (p \<bullet> x\<^isub>n)"}
  1164   @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"}
  1146   \end{equation}
  1165   \end{equation}
  1147   
  1166   
  1148   The first non-trivial step we have to perform is the generation free-variable 
  1167   The first non-trivial step we have to perform is the generation free-variable 
  1149   functions from the specifications. For atomic types we define the auxilary
  1168   functions from the specifications. For atomic types we define the auxilary
  1150   free variable functions:
  1169   free variable functions:
  1185 
  1204 
  1186   While the idea behind these free-variable functions is clear (they just
  1205   While the idea behind these free-variable functions is clear (they just
  1187   collect all atoms that are not bound), because of our rather complicated
  1206   collect all atoms that are not bound), because of our rather complicated
  1188   binding mechanisms their definitions are somewhat involved.  Given a
  1207   binding mechanisms their definitions are somewhat involved.  Given a
  1189   term-constructor @{text "C"} of type @{text ty} and some associated binding
  1208   term-constructor @{text "C"} of type @{text ty} and some associated binding
  1190   clauses @{text bcs}, the result of the @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be
  1209   clauses @{text bcs}, the result of the @{text "fv_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be
  1191   the union of the values, @{text v}, calculated by the rules for empty, shallow and
  1210   the union of the values, @{text v}, calculated by the rules for empty, shallow and
  1192   deep binding clauses: 
  1211   deep binding clauses: 
  1193   %
  1212   %
  1194   \begin{equation}\label{deepbinder}
  1213   \begin{equation}\label{deepbinderA}
  1195   \mbox{%
  1214   \mbox{%
  1196   \begin{tabular}{c@ {\hspace{2mm}}p{7.4cm}}
  1215   \begin{tabular}{c@ {\hspace{2mm}}p{7.4cm}}
  1197   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ 
  1216   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ 
  1198   $\bullet$ & @{term "v = fv_ty y"} provided @{text "y"} is of type @{text "ty"}\smallskip\\
  1217   $\bullet$ & @{term "v = fv_ty y"} provided @{text "y"} is of type @{text "ty"}\smallskip\\
  1199   
  1218   % 
  1200   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "y\<^isub>1\<dots>y\<^isub>m"}:}\\ 
  1219   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "y\<^isub>1\<dots>y\<^isub>m"}:}\\ 
  1201   $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> \<dots> \<union> fv_ty\<^isub>m y\<^isub>m)"}\\ 
  1220   $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> .. \<union> fv_ty\<^isub>m y\<^isub>m)"}\\ 
  1202   & \hspace{15mm}@{text "- (fv_aty\<^isub>1 x\<^isub>1 \<union> \<dots> \<union> fv_aty\<^isub>n x\<^isub>n)"}\\ 
  1221   & \hspace{15mm}@{text "- (fv_aty\<^isub>1 x\<^isub>1 \<union> .. \<union> fv_aty\<^isub>n x\<^isub>n)"}\\ 
  1203   & provided the bodies @{text "y"}$_{1..m}$ are of type @{text "ty"}$_{1..m}$ and the 
  1222   & provided the bodies @{text "y"}$_{1..m}$ are of type @{text "ty"}$_{1..m}$ and the 
  1204   binders @{text "x"}$_{1..n}$ of atomic types @{text "aty"}$_{1..n}$\smallskip\\
  1223   binders @{text "x"}$_{1..n}$ of atomic types @{text "aty"}$_{1..n}$\smallskip\\
  1205   
  1224   \end{tabular}}
       
  1225   \end{equation}
       
  1226   \begin{equation}\label{deepbinderB}
       
  1227   \mbox{%
       
  1228   \begin{tabular}{c@ {\hspace{2mm}}p{7.4cm}}
  1206   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{text "bn x"}~\isacommand{in}~@{text "y\<^isub>1\<dots>y\<^isub>m"}:}\\ 
  1229   \multicolumn{2}{@ {}l}{\isacommand{bind}~@{text "bn x"}~\isacommand{in}~@{text "y\<^isub>1\<dots>y\<^isub>m"}:}\\ 
  1207   $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> \<dots> \<union> fv_ty\<^isub>m y\<^isub>m) - set (bn x) \<union> (fv_bn x)"}\\
  1230   $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> .. \<union> fv_ty\<^isub>m y\<^isub>m) - set (bn x) \<union> (fv_bn x)"}\\
  1208   $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> \<dots> \<union> fv_ty\<^isub>m y\<^isub>m) - set (bn x)"}\\
  1231   $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> .. \<union> fv_ty\<^isub>m y\<^isub>m) - set (bn x)"}\\
  1209      & provided the @{text "y"}$_{1..m}$ are of type @{text "ty"}$_{1..m}$; the first 
  1232      & provided the @{text "y"}$_{1..m}$ are of type @{text "ty"}$_{1..m}$; the first 
  1210     clause applies for @{text x} being a non-recursive deep binder, the 
  1233     clause applies for @{text x} being a non-recursive deep binder (that is 
  1211     second for a recursive deep binder
  1234     @{text "x \<noteq> y"}$_{1..m}$), the second for a recursive deep binder
  1212   \end{tabular}}
  1235   \end{tabular}}
  1213   \end{equation}
  1236   \end{equation}
  1214 
  1237 
  1215   \noindent
  1238   \noindent
  1216   Similarly for the other binding modes. Note that in a non-recursive deep
  1239   Similarly for the other binding modes. Note that in a non-recursive deep
  1217   binder, we have to add all atoms that are left unbound by the binding
  1240   binder, we have to add all atoms that are left unbound by the binding
  1218   function @{text "bn"}. For this we define the function @{text "fv_bn"}. Assume
  1241   function @{text "bn"}. For this we define the function @{text "fv_bn"}. Assume
  1219   for the constructor @{text "C"} the binding function is of the form @{text
  1242   for the constructor @{text "C"} the binding function is of the form @{text
  1220   "bn\<^isub>j (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}. We again define a value
  1243   "bn (C z\<^isub>1 \<dots> z\<^isub>n) = rhs"}. We again define a value
  1221   @{text v} which is exactly as in \eqref{deepbinder} for shallow and deep
  1244   @{text v} which is exactly as in \eqref{deepbinderA}/\eqref{deepbinderB} for shallow and deep
  1222   binding clauses, except for empty binding clauses are defined as follows: 
  1245   binding clauses, except for empty binding clauses are defined as follows: 
  1223   %
  1246   %
  1224   \begin{equation}\label{bnemptybinder}
  1247   \begin{equation}\label{bnemptybinder}
  1225   \mbox{%
  1248   \mbox{%
  1226   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1249   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}