Paper/Paper.thy
changeset 1765 9a894c42e80e
parent 1764 9f55d7927e5b
child 1766 a2d5f9ea17ad
equal deleted inserted replaced
1764:9f55d7927e5b 1765:9a894c42e80e
   867 
   867 
   868 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *}
   868 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *}
   869 
   869 
   870 text {*
   870 text {*
   871   Our choice of syntax for specifications is influenced by the existing
   871   Our choice of syntax for specifications is influenced by the existing
   872   datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the Ott-tool
   872   datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the
   873   \cite{ott-jfp}. For us a specification of a term-calculus is a collection of (possibly mutual
   873   Ott-tool \cite{ott-jfp}. For us a specification of a term-calculus is a
   874   recursive) type declarations, say @{text "ty"}$^\alpha_1$, \ldots, 
   874   collection of (possibly mutual recursive) type declarations, say @{text
   875   @{text ty}$^\alpha_n$, and an associated collection
   875   "ty\<AL>\<^isub>1, \<dots>, ty\<AL>\<^isub>n"}, and an associated collection of
   876   of binding functions, say @{text bn}$^\alpha_1$, \ldots, @{text
   876   binding functions, say @{text "bn\<AL>\<^isub>1, \<dots>, bn\<AL>\<^isub>m"}. The
   877   bn}$^\alpha_m$. The syntax in Nominal Isabelle for such specifications is
   877   syntax in Nominal Isabelle for such specifications is roughly as follows:
   878   roughly as follows:
       
   879   %
   878   %
   880   \begin{equation}\label{scheme}
   879   \begin{equation}\label{scheme}
   881   \mbox{\begin{tabular}{@ {\hspace{-5mm}}p{1.8cm}l}
   880   \mbox{\begin{tabular}{@ {\hspace{-5mm}}p{1.8cm}l}
   882   type \mbox{declaration part} &
   881   type \mbox{declaration part} &
   883   $\begin{cases}
   882   $\begin{cases}
   884   \mbox{\begin{tabular}{l}
   883   \mbox{\begin{tabular}{l}
   885   \isacommand{nominal\_datatype} @{text ty}$^\alpha_1 = \ldots$\\
   884   \isacommand{nominal\_datatype} @{text "ty\<AL>\<^isub>1 = \<dots>"}\\
   886   \isacommand{and} @{text ty}$^\alpha_2 = \ldots$\\
   885   \isacommand{and} @{text "ty\<AL>\<^isub>2 = \<dots>"}\\
   887   $\ldots$\\ 
   886   $\ldots$\\ 
   888   \isacommand{and} @{text ty}$^\alpha_n = \ldots$\\ 
   887   \isacommand{and} @{text "ty\<AL>\<^isub>n = \<dots>"}\\ 
   889   \end{tabular}}
   888   \end{tabular}}
   890   \end{cases}$\\
   889   \end{cases}$\\
   891   binding \mbox{function part} &
   890   binding \mbox{function part} &
   892   $\begin{cases}
   891   $\begin{cases}
   893   \mbox{\begin{tabular}{l}
   892   \mbox{\begin{tabular}{l}
   894   \isacommand{with} @{text bn}$^\alpha_1$ \isacommand{and} \ldots \isacommand{and} @{text bn}$^\alpha_m$\\
   893   \isacommand{with} @{text "bn\<AL>\<^isub>1"} \isacommand{and} \ldots \isacommand{and} @{text "bn\<AL>\<^isub>m"}\\
   895   \isacommand{where}\\
   894   \isacommand{where}\\
   896   $\ldots$\\
   895   $\ldots$\\
   897   \end{tabular}}
   896   \end{tabular}}
   898   \end{cases}$\\
   897   \end{cases}$\\
   899   \end{tabular}}
   898   \end{tabular}}
   900   \end{equation}
   899   \end{equation}
   901 
   900 
   902   \noindent
   901   \noindent
   903   Every type declaration @{text ty}$^\alpha_{1..n}$ consists of a collection of 
   902   Every type declaration @{text ty}$^\alpha_{1..n}$ consists of a collection of 
   904   term-constructors, each of which comes with a list of labelled 
   903   term-constructors, each of which come with a list of labelled 
   905   types that stand for the types of the arguments of the term-constructor.
   904   types that stand for the types of the arguments of the term-constructor.
   906   For example a term-constructor @{text "C\<^sup>\<alpha>"} might have
   905   For example a term-constructor @{text "C\<^sup>\<alpha>"} might be specified with
   907 
   906 
   908   \begin{center}
   907   \begin{center}
   909   @{text "C\<^sup>\<alpha> label\<^isub>1::ty"}$'_1$ @{text "\<dots> label\<^isub>l::ty"}$'_l\;\;$  @{text "binding_clauses"} 
   908   @{text "C\<^sup>\<alpha> label\<^isub>1::ty"}$'_1$ @{text "\<dots> label\<^isub>l::ty"}$'_l\;\;$  @{text "binding_clauses"} 
   910   \end{center}
   909   \end{center}
   911   
   910   
   912   \noindent
   911   \noindent
   913   whereby some of the @{text ty}$'_{1..l}$ (or their components) might be contained
   912   whereby some of the @{text ty}$'_{1..l}$ (or their components) might be contained
   914   in the collection of @{text ty}$^\alpha_{1..n}$ declared in
   913   in the collection of @{text ty}$^\alpha_{1..n}$ declared in
   915   \eqref{scheme}. 
   914   \eqref{scheme}. 
   916   %In this case we will call the corresponding argument a
   915   In this case we will call the corresponding argument a
   917   %\emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such recursive 
   916   \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. 
       
   917   %The types of such recursive 
   918   %arguments need to satisfy a  ``positivity''
   918   %arguments need to satisfy a  ``positivity''
   919   %restriction, which ensures that the type has a set-theoretic semantics 
   919   %restriction, which ensures that the type has a set-theoretic semantics 
   920   %\cite{Berghofer99}.  
   920   %\cite{Berghofer99}.  
   921   The labels
   921   The labels
   922   annotated on the types are optional. Their purpose is to be used in the
   922   annotated on the types are optional. Their purpose is to be used in the
   934   \noindent
   934   \noindent
   935   The first mode is for binding lists of atoms (the order of binders matters);
   935   The first mode is for binding lists of atoms (the order of binders matters);
   936   the second is for sets of binders (the order does not matter, but the
   936   the second is for sets of binders (the order does not matter, but the
   937   cardinality does) and the last is for sets of binders (with vacuous binders
   937   cardinality does) and the last is for sets of binders (with vacuous binders
   938   preserving alpha-equivalence). The ``\isacommand{in}-part'' of a binding
   938   preserving alpha-equivalence). The ``\isacommand{in}-part'' of a binding
   939   clause will be called the \emph{body}; the
   939   clause will be called the \emph{body}; the ``\isacommand{bind}-part'' will
   940   ``\isacommand{bind}-part'' will be the \emph{binder}.
   940   be called the \emph{binder}.
   941 
   941 
   942   In addition we distinguish between \emph{shallow} and \emph{deep}
   942   In addition we distinguish between \emph{shallow} and \emph{deep}
   943   binders.  Shallow binders are of the form \isacommand{bind}\; {\it label}\;
   943   binders.  Shallow binders are of the form \isacommand{bind}\; {\it label}\;
   944   \isacommand{in}\; {\it label'} (similar for the other two modes). The
   944   \isacommand{in}\; {\it label'} (similar for the other two modes). The
   945   restriction we impose on shallow binders is that the {\it label} must either
   945   restriction we impose on shallow binders is that the {\it label} must either
  1152   The first non-trivial step we have to perform is the generation free-variable 
  1152   The first non-trivial step we have to perform is the generation free-variable 
  1153   functions from the specifications. Given the raw types @{text "ty\<^isub>1 \<dots> ty\<^isub>n"}
  1153   functions from the specifications. Given the raw types @{text "ty\<^isub>1 \<dots> ty\<^isub>n"}
  1154   we need to define free-variable functions
  1154   we need to define free-variable functions
  1155 
  1155 
  1156   \begin{center}
  1156   \begin{center}
  1157   @{text "fv_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set    \<dots>    fv_ty\<^isub>n :: ty\<^isub>n \<Rightarrow> atom set"}
  1157   @{text "fv_ty\<^isub>1, \<dots>, fv_ty\<^isub>n"}
  1158   \end{center}
  1158   \end{center}
  1159 
  1159 
  1160   \noindent
  1160   \noindent
  1161   We define them together with auxiliary free-variable functions for
  1161   We define them together with auxiliary free-variable functions for
  1162   the binding functions. Given binding functions 
  1162   the binding functions. Given binding functions 
  1163   @{text "bn\<^isub>1 \<dots> bn\<^isub>m"} we need to define
  1163   @{text "bn\<^isub>1 \<dots> bn\<^isub>m"} we need to define
  1164   %
  1164   %
  1165   \begin{center}
  1165   \begin{center}
  1166   @{text "fv_bn\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set  \<dots>  fv_bn\<^isub>m :: ty\<^isub>m \<Rightarrow> atom set"}
  1166   @{text "fv_bn\<^isub>1, \<dots>, fv_bn\<^isub>m"}
  1167   \end{center}
  1167   \end{center}
  1168 
  1168 
  1169   \noindent
  1169   \noindent
  1170   The reason for this setup is that in a deep binder not all atoms have to be
  1170   The reason for this setup is that in a deep binder not all atoms have to be
  1171   bound, as we shall see in an example below. We need therefore a function
  1171   bound, as we shall see in an example below. We need therefore a function
  1250   \begin{center}
  1250   \begin{center}
  1251   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1251   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1252    $\bullet$ & @{text "fv_bn x\<^isub>i"} provided @{text "rhs"} contains the
  1252    $\bullet$ & @{text "fv_bn x\<^isub>i"} provided @{text "rhs"} contains the
  1253     recursive call @{text "bn x\<^isub>i"}\medskip\\
  1253     recursive call @{text "bn x\<^isub>i"}\medskip\\
  1254   $\bullet$ & @{term "{}"} provided @{text "rhs"} contains
  1254   $\bullet$ & @{term "{}"} provided @{text "rhs"} contains
  1255     @{term "x\<^isub>i"} without a recursive call.
  1255     @{term "x\<^isub>i"} and @{term "x\<^isub>i"} is of atom type.
  1256   \end{tabular}
  1256   \end{tabular}
  1257   \end{center}
  1257   \end{center}
  1258 
  1258 
  1259   \noindent
  1259   \noindent
  1260   To see how these definitions work in practise, let us reconsider the term-constructors 
  1260   To see how these definitions work in practise, let us reconsider the term-constructors 
  1294   context of a @{text Let} or @{text "Let_rec"} will some atoms become bound.  
  1294   context of a @{text Let} or @{text "Let_rec"} will some atoms become bound.  
  1295   This is a phenomenon 
  1295   This is a phenomenon 
  1296   that has also been pointed out in \cite{ott-jfp}. We can also see that
  1296   that has also been pointed out in \cite{ott-jfp}. We can also see that
  1297   %
  1297   %
  1298   \begin{equation}\label{bnprop}
  1298   \begin{equation}\label{bnprop}
  1299   @{text "fv_ty x = bn x \<union> fv_bn x"}.
  1299   @{text "fv_ty x  =  bn x \<union> fv_bn x"}.
  1300   \end{equation}
  1300   \end{equation}
  1301 
  1301 
  1302   \noindent
  1302   \noindent
  1303   holds for any @{text "bn"}-function of type @{text "ty"}.
  1303   holds for any @{text "bn"}-function defined for the type @{text "ty"}.
  1304 
  1304 
  1305   Next we define alpha-equivalence for the types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"}. We call them
  1305   Next we define alpha-equivalence relations for the types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"}. We call them
  1306   @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. Like with the free-variable functions, 
  1306   @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. Like with the free-variable functions, 
  1307   we also need to  define auxiliary alpha-equivalence relations for the binding functions. 
  1307   we also need to  define auxiliary alpha-equivalence relations for the binding functions. 
  1308   Say we have @{text "bn\<^isub>1, \<dots>, bn\<^isub>m"}, then we also define @{text "\<approx>bn\<^isub>1, \<dots>, \<approx>bn\<^isub>m"}.
  1308   Say we have @{text "bn\<^isub>1, \<dots>, bn\<^isub>m"}, then we also define @{text "\<approx>bn\<^isub>1, \<dots>, \<approx>bn\<^isub>m"}.
  1309   To simplify our definitions we will use the following abbreviations for 
  1309   To simplify our definitions we will use the following abbreviations for 
  1310   relations and free-variable acting on products.
  1310   relations and free-variable acting on products.
  1325   \end{center}
  1325   \end{center}
  1326 
  1326 
  1327   \noindent
  1327   \noindent
  1328   For what follows, let us assume 
  1328   For what follows, let us assume 
  1329   @{text C} is of type @{text ty} and its arguments are given by @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}.
  1329   @{text C} is of type @{text ty} and its arguments are given by @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}.
  1330   The task now is to specify what the premises of these clauses are. For this we
  1330   The task is to specify what the premises of these clauses are. For this we
  1331   consider the pairs \mbox{@{text "(x\<^isub>i, y\<^isub>i)"}}, but instead of considering them in turn, it will 
  1331   consider the pairs \mbox{@{text "(x\<^isub>i, y\<^isub>i)"}}, but instead of considering them in turn, it will 
  1332   be easier to analyse these pairs according to  ``clusters'' of the binding clauses. 
  1332   be easier to analyse these pairs according to  ``clusters'' of the binding clauses. 
  1333   Therefore we distinguish the following cases:
  1333   Therefore we distinguish the following cases:
  1334 *}
  1334 *}
  1335 (*<*)
  1335 (*<*)
  1345   alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and
  1345   alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and
  1346   fv_trm2 ("fv\<^bsub>assn\<^esub> \<oplus> fv\<^bsub>trm\<^esub>") 
  1346   fv_trm2 ("fv\<^bsub>assn\<^esub> \<oplus> fv\<^bsub>trm\<^esub>") 
  1347 (*>*)
  1347 (*>*)
  1348 text {*
  1348 text {*
  1349   \begin{itemize}
  1349   \begin{itemize}
  1350   \item The @{text "(x\<^isub>i, y\<^isub>i)"} are bodies of shallow binders with type @{text "ty"}. We assume the 
  1350   \item The @{text "(x\<^isub>i, y\<^isub>i)"} is a body of shallow binder with type @{text "ty"}. We assume the 
  1351   \mbox{@{text "(u\<^isub>1, v\<^isub>1),\<dots>,(u\<^isub>m, v\<^isub>m)"}} are the corresponding binders. For the binding mode
  1351   \mbox{@{text "(u\<^isub>1, v\<^isub>1),\<dots>,(u\<^isub>m, v\<^isub>m)"}} are the corresponding binders. For the binding mode
  1352   \isacommand{bind\_set} we generate the premise
  1352   \isacommand{bind\_set} we generate the premise
  1353   \begin{center}
  1353   \begin{center}
  1354    @{term "\<exists>p. (u\<^isub>1 \<union> \<xi> \<union> u\<^isub>m, x\<^isub>i) \<approx>gen alpha_ty fv_ty p (v\<^isub>1 \<union> \<xi> \<union> v\<^isub>m, y\<^isub>i)"}
  1354    @{term "\<exists>p. (u\<^isub>1 \<union> \<xi> \<union> u\<^isub>m, x\<^isub>i) \<approx>gen alpha_ty fv_ty p (v\<^isub>1 \<union> \<xi> \<union> v\<^isub>m, y\<^isub>i)"}
  1355   \end{center}
  1355   \end{center}
  1356 
  1356 
  1357   For the binding mode \isacommand{bind}, we use $\approx_{\textit{list}}$, and for
  1357   For the binding mode \isacommand{bind}, we use $\approx_{\textit{list}}$, and for
  1358   binding mode \isacommand{bind\_res} we use $\approx_{\textit{res}}$ instead. 
  1358   binding mode \isacommand{bind\_res} we use $\approx_{\textit{res}}$ instead. 
  1359 
  1359 
  1360   \item The @{text "(x\<^isub>i, y\<^isub>i)"} are deep non-recursive binders with type @{text "ty"}
  1360   \item The @{text "(x\<^isub>i, y\<^isub>i)"} is a deep non-recursive binder with type @{text "ty"}
  1361   and @{text bn} being the auxiliary binding function. We assume 
  1361   and @{text bn} is corresponding the binding function. We assume 
  1362   @{text "(u\<^isub>1, v\<^isub>1),\<dots>,(u\<^isub>m, v\<^isub>m)"} are the corresponding bodies with types @{text "ty\<^isub>1,\<dots>, ty\<^isub>m"}. 
  1362   @{text "(u\<^isub>1, v\<^isub>1),\<dots>,(u\<^isub>m, v\<^isub>m)"} are the corresponding bodies with types @{text "ty\<^isub>1,\<dots>, ty\<^isub>m"}. 
  1363   For the binding mode \isacommand{bind\_set} we generate two premises
  1363   For the binding mode \isacommand{bind\_set} we generate two premises
  1364   %
  1364   %
  1365   \begin{center}
  1365   \begin{center}
  1366    @{text "x\<^isub>i \<approx>bn y\<^isub>i"}\hfill
  1366    @{text "x\<^isub>i \<approx>bn y\<^isub>i"}\hfill
  1369 
  1369 
  1370   \noindent
  1370   \noindent
  1371   where @{text R} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fv} is
  1371   where @{text R} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fv} is
  1372   @{text "fv_ty\<^isub>1 \<oplus> ... \<oplus> fv_ty\<^isub>m"}. Similarly for the other binding modes.
  1372   @{text "fv_ty\<^isub>1 \<oplus> ... \<oplus> fv_ty\<^isub>m"}. Similarly for the other binding modes.
  1373 
  1373 
  1374   \item The @{text "(x\<^isub>i, y\<^isub>i)"} are deep recursive binders with type @{text "ty"}
  1374   \item The @{text "(x\<^isub>i, y\<^isub>i)"} is a deep recursive binders with type @{text "ty"}
  1375   and with @{text bn} being the auxiliary binding function. We assume 
  1375   and  @{text bn} is the corresponding binding function. We assume 
  1376   @{text "(u\<^isub>1, v\<^isub>1),\<dots>,(u\<^isub>m, v\<^isub>m)"} are the corresponding bodies with types @{text "ty\<^isub>1,\<dots>, ty\<^isub>m"}. 
  1376   @{text "(u\<^isub>1, v\<^isub>1),\<dots>,(u\<^isub>m, v\<^isub>m)"} are the corresponding bodies with types @{text "ty\<^isub>1,\<dots>, ty\<^isub>m"}. 
  1377   For the binding mode \isacommand{bind\_set} we generate the premise
  1377   For the binding mode \isacommand{bind\_set} we generate the premise
  1378   %
  1378   %
  1379   \begin{center}
  1379   \begin{center}
  1380   @{term "\<exists>p. (bn x\<^isub>i, (x\<^isub>i, u\<^isub>1,\<xi>,u\<^isub>m)) \<approx>gen R fv p (bn y\<^isub>i, (y\<^isub>i, v\<^isub>1,\<xi>,v\<^isub>m))"}
  1380   @{term "\<exists>p. (bn x\<^isub>i, (x\<^isub>i, u\<^isub>1,\<xi>,u\<^isub>m)) \<approx>gen R fv p (bn y\<^isub>i, (y\<^isub>i, v\<^isub>1,\<xi>,v\<^isub>m))"}
  1384   where @{text R} is @{text "\<approx>ty \<otimes> \<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fv} is
  1384   where @{text R} is @{text "\<approx>ty \<otimes> \<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fv} is
  1385   @{text "fv_ty \<oplus> fv_ty\<^isub>1 \<oplus> ... \<oplus> fv_ty\<^isub>m"}. Similarly for the other modes.
  1385   @{text "fv_ty \<oplus> fv_ty\<^isub>1 \<oplus> ... \<oplus> fv_ty\<^isub>m"}. Similarly for the other modes.
  1386   \end{itemize}
  1386   \end{itemize}
  1387 
  1387 
  1388   \noindent
  1388   \noindent
  1389   From these definition it is clear why we can only support one binding mode per binder
  1389   From this definition it is clear why we can only support one binding mode per binder
  1390   and body, as we cannot mix the relations $\approx_{\textit{set}}$, $\approx_{\textit{list}}$
  1390   and body, as we cannot mix the relations $\approx_{\textit{set}}$, $\approx_{\textit{list}}$
  1391   and $\approx_{\textit{res}}$. It is also clear why we had to impose the restriction
  1391   and $\approx_{\textit{res}}$. It is also clear why we have to impose the restriction
  1392   of excluding overlapping binders, as these would need to be translated into separate
  1392   of excluding overlapping binders, as these would need to be translated into separate
  1393   abstractions.
  1393   abstractions.
  1394 
  1394 
  1395 
  1395 
  1396   The only cases that are not covered by the rules above are the cases where @{text "(x\<^isub>i, y\<^isub>i)"} is
  1396   The only cases that are not covered by the rules above are the cases where @{text "(x\<^isub>i, y\<^isub>i)"} is
  1397   neither a binder nor a body in a binding clause. Then we just generate @{text "x\<^isub>i \<approx>ty y\<^isub>i"}  provided
  1397   neither a binder nor a body in a binding clause. Then we just generate @{text "x\<^isub>i \<approx>ty y\<^isub>i"}  provided
  1398   the type of @{text "x\<^isub>i"} and @{text "y\<^isub>i"} is @{text ty} and the arguments are 
  1398   the type of @{text "x\<^isub>i"} and @{text "y\<^isub>i"} is @{text ty} and the arguments are 
  1399   recursive arguments of the term-constructor. If they are non-recursive arguments,
  1399   recursive arguments of the term-constructor. If they are non-recursive arguments,
  1400   then we generate just @{text "x\<^isub>i = y\<^isub>i"}.
  1400   then we generate the premise @{text "x\<^isub>i = y\<^isub>i"}.
  1401 
  1401 
  1402 
  1402 
  1403   The definitions of the alpha-equivalence relations @{text "\<approx>bn"} for binding functions 
  1403   The alpha-equivalence relations @{text "\<approx>bn\<^isub>j"} for binding functions 
  1404   are similar. We again have conclusions of the form \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>bn C y\<^isub>1 \<dots> y\<^isub>n"}}
  1404   are similar. We again have conclusions of the form \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>bn C y\<^isub>1 \<dots> y\<^isub>n"}}
  1405   and need to generate appropriate premises. We generate first premises according to the first three
  1405   and need to generate appropriate premises. We generate first premises according to the first three
  1406   rules given above. Only the ``left-over'' pairs  @{text "(x\<^isub>i, y\<^isub>i)"} need to be treated 
  1406   rules given above. Only the ``left-over'' pairs  @{text "(x\<^isub>i, y\<^isub>i)"} need to be treated 
  1407   differently. They depend on whether @{text "x\<^isub>i"}  occurs in @{text "rhs"} of  the 
  1407   differently. They depend on whether @{text "x\<^isub>i"}  occurs in @{text "rhs"} of  the 
  1408   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}:
  1408   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}:
  1419   $\bullet$ & none provided @{text "x\<^isub>i"} occurs in @{text rhs} but it is not
  1419   $\bullet$ & none provided @{text "x\<^isub>i"} occurs in @{text rhs} but it is not
  1420   in a recursive call involving a @{text "bn"}
  1420   in a recursive call involving a @{text "bn"}
  1421   \end{tabular}
  1421   \end{tabular}
  1422   \end{center}
  1422   \end{center}
  1423 
  1423 
  1424   Again lets take a look at an example for these definitions. For \eqref{letrecs}
  1424   Again lets take a look at a concrete example for these definitions. For \eqref{letrecs}
  1425   we have three relations, namely $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and
  1425   we have three relations, namely $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and
  1426   $\approx_{\textit{bn}}$, with the clauses as follows:
  1426   $\approx_{\textit{bn}}$, with the clauses as follows:
  1427 
  1427 
  1428   \begin{center}
  1428   \begin{center}
  1429   \begin{tabular}{@ {}c @ {}}
  1429   \begin{tabular}{@ {}c @ {}}
  1454   Note the difference between  $\approx_{\textit{assn}}$ and
  1454   Note the difference between  $\approx_{\textit{assn}}$ and
  1455   $\approx_{\textit{bn}}$: the latter only ``tracks'' alpha-equivalence of 
  1455   $\approx_{\textit{bn}}$: the latter only ``tracks'' alpha-equivalence of 
  1456   the components in an assignment that are \emph{not} bound. Therefore we have
  1456   the components in an assignment that are \emph{not} bound. Therefore we have
  1457   a $\approx_{\textit{bn}}$-premise in the clause for @{text "Let"} (which is 
  1457   a $\approx_{\textit{bn}}$-premise in the clause for @{text "Let"} (which is 
  1458   a non-recursive binder). The reason is that the terms inside an assignment are not meant 
  1458   a non-recursive binder). The reason is that the terms inside an assignment are not meant 
  1459   to be under the binder. Such a premise is not needed in @{text "Let_rec"}, 
  1459   to be ``under'' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"}, 
  1460   because there everything from the assignment is under the binder. 
  1460   because there everything from the assignment is under the binder. 
  1461 *}
  1461 *}
  1462 
  1462 
  1463 section {* Establishing the Reasoning Infrastructure *}
  1463 section {* Establishing the Reasoning Infrastructure *}
  1464 
  1464 
  1465 text {*
  1465 text {*
  1466   Having made all crucial definitions for raw terms, we can start introducing
  1466   Having made all necessary definitions for raw terms, we can start introducing
  1467   the resoning infrastructure for the types the user specified. For this we first
  1467   the reasoning infrastructure for the types the user specified. For this we first
  1468   have to show that the alpha-equivalence relations defined in the previous
  1468   have to show that the alpha-equivalence relations defined in the previous
  1469   section are indeed equivalence relations. 
  1469   section are indeed equivalence relations. 
  1470 
  1470 
  1471   \begin{lemma} 
  1471   \begin{lemma} 
  1472   Given the raw types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"} and binding functions
  1472   Given the raw types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"} and binding functions
  1500   \mbox{@{text "C"}$^\alpha_i$@{text "x\<^isub>1 \<dots> x\<^isub>n"} @{text "\<noteq>"} 
  1500   \mbox{@{text "C"}$^\alpha_i$@{text "x\<^isub>1 \<dots> x\<^isub>n"} @{text "\<noteq>"} 
  1501   @{text "C"}$^\alpha_j$@{text "y\<^isub>1 \<dots> y\<^isub>m"} holds for @{text "i \<noteq> j"}.} 
  1501   @{text "C"}$^\alpha_j$@{text "y\<^isub>1 \<dots> y\<^isub>m"} holds for @{text "i \<noteq> j"}.} 
  1502   \end{equation}
  1502   \end{equation}
  1503   
  1503   
  1504   \noindent
  1504   \noindent
  1505   By definition of alpha-equivalence on raw terms we can show that
  1505   By definition of alpha-equivalence we can show that
  1506   for the raw term-constructors
  1506   for the raw term-constructors
  1507 
  1507   %
  1508   \begin{center}
  1508   \begin{equation}\label{distinctraw}
  1509   @{text "C\<^isub>i x\<^isub>1 \<dots> x\<^isub>n"}$\;\not\approx@{text ty}\;$@{text "C\<^isub>j y\<^isub>1 \<dots> y\<^isub>m"} holds for @{text "i \<noteq> j"}.
  1509   @{text "C\<^isub>i x\<^isub>1 \<dots> x\<^isub>n"}\;\not\approx@{text ty}\;@{text "C\<^isub>j y\<^isub>1 \<dots> y\<^isub>m"} holds for @{text "i \<noteq> j"}.
  1510   \end{center}
  1510   \end{equation}
  1511 
  1511 
  1512   \noindent
  1512   \noindent
  1513   In order to generate \eqref{distinctalpha} from this fact, the quotient
  1513   In order to generate \eqref{distinctalpha} from this fact, the quotient
  1514   package needs to know that the term-constructors @{text "C\<^isub>i"} and @{text "C\<^isub>j"} 
  1514   package needs to know that the term-constructors @{text "C\<^isub>i"} and @{text "C\<^isub>j"} 
  1515   are \emph{respectful} w.r.t.~the alpha-equivalence relations \cite{Homeier05}.
  1515   are \emph{respectful} w.r.t.~the alpha-equivalence relations \cite{Homeier05}.
  1516   
  1516   This means, given @{text "C\<^isub>i"} is of type @{text "ty"} with argument types
  1517   Given a term-constructor @{text C} of type @{text ty} and argument
  1517   @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}, we have to show that
  1518   types @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}, respectfullness means that
  1518   
  1519   %
  1519   \begin{center}
  1520   \begin{center}
  1520   @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>ty C y\<^isub>1 \<dots> y\<^isub>n"}
  1521   aa
  1521   \end{center}  
  1522   \end{center}
  1522 
       
  1523   \noindent
       
  1524   under the assumption that @{text "x\<^isub>i \<approx>ty\<^isub>i y\<^isub>i"} holds for all recursive arguments
       
  1525   and  @{text "x\<^isub>i = y\<^isub>i"} for all non-recursive arguments. We can prove this by 
       
  1526   analysing the definition of @{text "\<approx>ty"}. For this to succed we have to establish an
       
  1527   auxiliary fact: given a binding function @{text bn} defined for the type @{text ty}
       
  1528   we have that
       
  1529 
       
  1530   \begin{center}
       
  1531   @{text "x \<approx>ty y"} implies @{text "x \<approx>bn y"}
       
  1532   \end{center}
       
  1533 
       
  1534   \noindent
       
  1535   This can be established by induction on the definition of @{text "\<approx>ty"}. 
  1523    
  1536    
  1524 
  1537   Having established respectfullness for every raw term-constructor, the 
  1525   \mbox{}\bigskip\bigskip
  1538   quotient package will automaticaly deduce \eqref{distinctalpha} from \eqref{distinctraw}.
  1526   then define the quotient types @{text "ty\<^isub>1\<^isup>\<alpha> \<dots> ty\<^isub>n\<^isup>\<alpha>"}.  To lift
  1539   In fact we can lift any fact from the raw level to the alpha-equated level that
       
  1540   apart from variables only contains the raw term-constructors @{text "C\<^isub>i"}. The 
       
  1541   induction principles derived by the datatype package of Isabelle/HOL for @{text
       
  1542   "ty"}$^\alpha_{1..n}$ fall into this category. So we can also add to our infrastructure
       
  1543   induction principles that establish
       
  1544 
       
  1545   \begin{center}
       
  1546   @{text "P\<^bsub>ty\<^isub>1\<^esub> y\<^isub>1 \<dots> P\<^bsub>ty\<^isub>n\<^esub> y\<^isub>n "}
       
  1547   \end{center} 
       
  1548 
       
  1549   \noindent
       
  1550   for every @{text "y\<^isub>i"} under the assumption we specified the types
       
  1551   @{text "ty\<^isub>1\<^isup>\<alpha> \<dots> ty\<^isub>n\<^isup>\<alpha>"}. The premises of these induction principles look
       
  1552   as follows
       
  1553 
       
  1554   \begin{center}
       
  1555   @{text "\<forall>x\<^isub>1\<dots>x\<^isub>n. P\<^bsub>ty\<^isub>i\<^esub> x\<^isub>i \<and> \<dots> \<and> P\<^bsub>ty\<^isub>j\<^esub> x\<^isub>j \<Rightarrow> P\<^bsub>ty\<^esub> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n)"} 
       
  1556   \end{center}
       
  1557 
       
  1558   \noindent
       
  1559   where the @{text "x\<^isub>i, \<dots>, x\<^isub>j"} are the recursive arguments of @{text "C\<^sup>\<alpha>"}. 
       
  1560 
       
  1561 
       
  1562 To lift
  1527   the raw definitions to the quotient type, we need to prove that they
  1563   the raw definitions to the quotient type, we need to prove that they
  1528   \emph{respect} the relation. We follow the definition of respectfullness given
  1564   \emph{respect} the relation. We follow the definition of respectfullness given
  1529   by Homeier~\cite{Homeier05}. The intuition behind a respectfullness condition
  1565   by Homeier~\cite{Homeier05}. The intuition behind a respectfullness condition
  1530   is that when a function (or constructor) is given arguments that are
  1566   is that when a function (or constructor) is given arguments that are
  1531   alpha-equivalent the results are also alpha equivalent. For arguments that are
  1567   alpha-equivalent the results are also alpha equivalent. For arguments that are
  1698   This allows is to strengthen the induction principles. We will explain
  1734   This allows is to strengthen the induction principles. We will explain
  1699   the details with the @{text "Let"} term-constructor from \eqref{letpat}.
  1735   the details with the @{text "Let"} term-constructor from \eqref{letpat}.
  1700   Instead of establishing the implication 
  1736   Instead of establishing the implication 
  1701 
  1737 
  1702   \begin{center}
  1738   \begin{center}
  1703   a
  1739   @{text "\<forall>p t\<^isub>1 t\<^isub>2. P\<^bsub>pat\<^esub> p \<and> P\<^bsub>trm\<^esub> t\<^isub>1 \<and> P\<^bsub>trm\<^esub> t\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Let p t\<^isub>1 t\<^isub>2)"}
  1704   \end{center}
  1740   \end{center}
  1705 
  1741 
  1706   \noindent
  1742   \noindent
  1707   from the weak induction principle. 
  1743   from the weak induction principle, we will show that it is sufficient
       
  1744   to establish
       
  1745   
       
  1746   \begin{center}
       
  1747   \begin{tabular}{l}
       
  1748   @{text "\<forall>p t\<^isub>1 t\<^isub>2 c."}\\
       
  1749   \hspace{5mm}@{text "set (bn\<^sup>\<alpha> p) #\<^sup>* c \<and>"}\\
       
  1750   \hspace{5mm}@{text "(\<forall>d. P\<^bsub>pat\<^esub> d p) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t\<^isub>2)"}\\
       
  1751   \hspace{15mm}@{text "\<Rightarrow> P\<^bsub>trm\<^esub> c (Let p t\<^isub>1 t\<^isub>2)"}
       
  1752   \end{tabular}
       
  1753   \end{center}
  1708 
  1754 
  1709 
  1755 
  1710   With the help of @{text "\<bullet>bn"} functions defined in the previous section
  1756   With the help of @{text "\<bullet>bn"} functions defined in the previous section
  1711   we can show that binders can be substituted in term constructors. We show
  1757   we can show that binders can be substituted in term constructors. We show
  1712   this only for the specification from Figure~\ref{nominalcorehas}. The only
  1758   this only for the specification from Figure~\ref{nominalcorehas}. The only