Paper/Paper.thy
changeset 2347 9807d30c0e54
parent 2346 4c5881455923
child 2348 09b476c20fe1
equal deleted inserted replaced
2346:4c5881455923 2347:9807d30c0e54
    24   alpha_gen ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{set}}$}}>\<^bsup>_, _, _\<^esup> _") and
    24   alpha_gen ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{set}}$}}>\<^bsup>_, _, _\<^esup> _") and
    25   alpha_lst ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{list}}$}}>\<^bsup>_, _, _\<^esup> _") and
    25   alpha_lst ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{list}}$}}>\<^bsup>_, _, _\<^esup> _") and
    26   alpha_res ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{res}}$}}>\<^bsup>_, _, _\<^esup> _") and
    26   alpha_res ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{res}}$}}>\<^bsup>_, _, _\<^esup> _") and
    27   abs_set ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and
    27   abs_set ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and
    28   abs_set2 ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{list}}$}}>\<^bsup>_\<^esup>  _") and
    28   abs_set2 ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{list}}$}}>\<^bsup>_\<^esup>  _") and
    29   fv ("fv'(_')" [100] 100) and
    29   fv ("fa'(_')" [100] 100) and
    30   equal ("=") and
    30   equal ("=") and
    31   alpha_abs ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and 
    31   alpha_abs ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and 
    32   Abs ("[_]\<^bsub>set\<^esub>._" [20, 101] 999) and
    32   Abs ("[_]\<^bsub>set\<^esub>._" [20, 101] 999) and
    33   Abs_lst ("[_]\<^bsub>list\<^esub>._") and
    33   Abs_lst ("[_]\<^bsub>list\<^esub>._") and
    34   Abs_dist ("[_]\<^bsub>#list\<^esub>._") and
    34   Abs_dist ("[_]\<^bsub>#list\<^esub>._") and
    41 
    41 
    42 
    42 
    43 section {* Introduction *}
    43 section {* Introduction *}
    44 
    44 
    45 text {*
    45 text {*
    46 %%%  @{text "(1, (2, 3))"}
       
    47 
    46 
    48   So far, Nominal Isabelle provided a mechanism for constructing
    47   So far, Nominal Isabelle provided a mechanism for constructing
    49   $\alpha$-equated terms, for example lambda-terms
    48   $\alpha$-equated terms, for example lambda-terms
    50 
    49 
    51   \begin{center}
    50   \begin{center}
   356   be bound. Another is that each bound variable comes with a kind or type
   355   be bound. Another is that each bound variable comes with a kind or type
   357   annotation. Representing such binders with single binders and reasoning
   356   annotation. Representing such binders with single binders and reasoning
   358   about them in a theorem prover would be a major pain.  \medskip
   357   about them in a theorem prover would be a major pain.  \medskip
   359 
   358 
   360   \noindent
   359   \noindent
   361   {\bf Contributions:}  We provide novel three definitions for when terms
   360   {\bf Contributions:}  We provide three novel definitions for when terms
   362   involving general binders are $\alpha$-equivalent. These definitions are
   361   involving general binders are $\alpha$-equivalent. These definitions are
   363   inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
   362   inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
   364   proofs, we establish a reasoning infrastructure for $\alpha$-equated
   363   proofs, we establish a reasoning infrastructure for $\alpha$-equated
   365   terms, including properties about support, freshness and equality
   364   terms, including properties about support, freshness and equality
   366   conditions for $\alpha$-equated terms. We are also able to derive strong 
   365   conditions for $\alpha$-equated terms. We are also able to derive strong 
   422   to aid the description of what follows. 
   421   to aid the description of what follows. 
   423 
   422 
   424   Two central notions in the nominal logic work are sorted atoms and
   423   Two central notions in the nominal logic work are sorted atoms and
   425   sort-respecting permutations of atoms. We will use the letters @{text "a,
   424   sort-respecting permutations of atoms. We will use the letters @{text "a,
   426   b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for
   425   b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for
   427   permutations.  The sorts of atoms can be used to represent different kinds of
   426   permutations. The purpose of atoms is to represent variables, be they bound or free. 
       
   427   The sorts of atoms can be used to represent different kinds of
   428   variables, such as the term-, coercion- and type-variables in Core-Haskell.
   428   variables, such as the term-, coercion- and type-variables in Core-Haskell.
   429   It is assumed that there is an infinite supply of atoms for each
   429   It is assumed that there is an infinite supply of atoms for each
   430   sort. However, in the interest of brevity, we shall restrict ourselves 
   430   sort. However, in the interest of brevity, we shall restrict ourselves 
   431   in what follows to only one sort of atoms.
   431   in what follows to only one sort of atoms.
   432 
   432 
   518   @{term "supp b"} & = & @{term "{}"}\\
   518   @{term "supp b"} & = & @{term "{}"}\\
   519   @{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"}
   519   @{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"}
   520   \end{eqnarray}
   520   \end{eqnarray}
   521   
   521   
   522   \noindent 
   522   \noindent 
   523   In some cases it can be difficult to characterise the support precisely, and
   523   in some cases it can be difficult to characterise the support precisely, and
   524   only an approximation can be established (see \eqref{suppfun} above). Reasoning about
   524   only an approximation can be established (see \eqref{suppfun} above). Reasoning about
   525   such approximations can be simplified with the notion \emph{supports}, defined 
   525   such approximations can be simplified with the notion \emph{supports}, defined 
   526   as follows:
   526   as follows:
   527 
   527 
   528   \begin{defn}
   528   \begin{defn}
   619 
   619 
   620   The first question we have to answer is when two pairs @{text "(as, x)"} and
   620   The first question we have to answer is when two pairs @{text "(as, x)"} and
   621   @{text "(bs, y)"} are $\alpha$-equivalent? (For the moment we are interested in
   621   @{text "(bs, y)"} are $\alpha$-equivalent? (For the moment we are interested in
   622   the notion of $\alpha$-equivalence that is \emph{not} preserved by adding
   622   the notion of $\alpha$-equivalence that is \emph{not} preserved by adding
   623   vacuous binders.) To answer this question, we identify four conditions: {\it (i)}
   623   vacuous binders.) To answer this question, we identify four conditions: {\it (i)}
   624   given a free-variable function @{text "fv"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
   624   given a free-atom function @{text "fa"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
   625   set"}}, then @{text x} and @{text y} need to have the same set of free
   625   set"}}, then @{text x} and @{text y} need to have the same set of free
   626   variables; moreover there must be a permutation @{text p} such that {\it
   626   atomss; moreover there must be a permutation @{text p} such that {\it
   627   (ii)} @{text p} leaves the free variables of @{text x} and @{text y} unchanged, but
   627   (ii)} @{text p} leaves the free atoms of @{text x} and @{text y} unchanged, but
   628   {\it (iii)} ``moves'' their bound names so that we obtain modulo a relation,
   628   {\it (iii)} ``moves'' their bound names so that we obtain modulo a relation,
   629   say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
   629   say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
   630   @{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
   630   @{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
   631   requirements {\it (i)} to {\it (iv)} can be stated formally as follows:
   631   requirements {\it (i)} to {\it (iv)} can be stated formally as follows:
   632   %
   632   %
   633   \begin{equation}\label{alphaset}
   633   \begin{equation}\label{alphaset}
   634   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   634   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   635   \multicolumn{3}{l}{@{term "(as, x) \<approx>gen R fv p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   635   \multicolumn{3}{l}{@{term "(as, x) \<approx>gen R fa p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   636               & @{term "fv(x) - as = fv(y) - bs"} & \mbox{\it (i)}\\
   636               & @{term "fa(x) - as = fa(y) - bs"} & \mbox{\it (i)}\\
   637   @{text "\<and>"} & @{term "(fv(x) - as) \<sharp>* p"} & \mbox{\it (ii)}\\
   637   @{text "\<and>"} & @{term "(fa(x) - as) \<sharp>* p"} & \mbox{\it (ii)}\\
   638   @{text "\<and>"} & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
   638   @{text "\<and>"} & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
   639   @{text "\<and>"} & @{term "(p \<bullet> as) = bs"} & \mbox{\it (iv)}\\ 
   639   @{text "\<and>"} & @{term "(p \<bullet> as) = bs"} & \mbox{\it (iv)}\\ 
   640   \end{array}
   640   \end{array}
   641   \end{equation}
   641   \end{equation}
   642 
   642 
   643   \noindent
   643   \noindent
   644   Note that this relation depends on the permutation @{text
   644   Note that this relation depends on the permutation @{text
   645   "p"}; $\alpha$-equivalence between two pairs is then the relation where we
   645   "p"}; $\alpha$-equivalence between two pairs is then the relation where we
   646   existentially quantify over this @{text "p"}. Also note that the relation is
   646   existentially quantify over this @{text "p"}. Also note that the relation is
   647   dependent on a free-variable function @{text "fv"} and a relation @{text
   647   dependent on a free-atom function @{text "fa"} and a relation @{text
   648   "R"}. The reason for this extra generality is that we will use
   648   "R"}. The reason for this extra generality is that we will use
   649   $\approx_{\,\textit{set}}$ for both ``raw'' terms and $\alpha$-equated terms. In
   649   $\approx_{\,\textit{set}}$ for both ``raw'' terms and $\alpha$-equated terms. In
   650   the latter case, @{text R} will be replaced by equality @{text "="} and we
   650   the latter case, @{text R} will be replaced by equality @{text "="} and we
   651   will prove that @{text "fv"} is equal to @{text "supp"}.
   651   will prove that @{text "fa"} is equal to @{text "supp"}.
   652 
   652 
   653   The definition in \eqref{alphaset} does not make any distinction between the
   653   The definition in \eqref{alphaset} does not make any distinction between the
   654   order of abstracted variables. If we want this, then we can define $\alpha$-equivalence 
   654   order of abstracted atoms. If we want this, then we can define $\alpha$-equivalence 
   655   for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"} 
   655   for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"} 
   656   as follows
   656   as follows
   657   %
   657   %
   658   \begin{equation}\label{alphalist}
   658   \begin{equation}\label{alphalist}
   659   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   659   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   660   \multicolumn{2}{l}{@{term "(as, x) \<approx>lst R fv p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   660   \multicolumn{2}{l}{@{term "(as, x) \<approx>lst R fa p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   661              & @{term "fv(x) - (set as) = fv(y) - (set bs)"} & \mbox{\it (i)}\\
   661              & @{term "fa(x) - (set as) = fa(y) - (set bs)"} & \mbox{\it (i)}\\
   662   \wedge     & @{term "(fv(x) - set as) \<sharp>* p"} & \mbox{\it (ii)}\\
   662   \wedge     & @{term "(fa(x) - set as) \<sharp>* p"} & \mbox{\it (ii)}\\
   663   \wedge     & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
   663   \wedge     & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
   664   \wedge     & @{term "(p \<bullet> as) = bs"} & \mbox{\it (iv)}\\ 
   664   \wedge     & @{term "(p \<bullet> as) = bs"} & \mbox{\it (iv)}\\ 
   665   \end{array}
   665   \end{array}
   666   \end{equation}
   666   \end{equation}
   667   
   667   
   674   also allow vacuous binders, then we keep sets of binders, but drop the fourth 
   674   also allow vacuous binders, then we keep sets of binders, but drop the fourth 
   675   condition in \eqref{alphaset}:
   675   condition in \eqref{alphaset}:
   676   %
   676   %
   677   \begin{equation}\label{alphares}
   677   \begin{equation}\label{alphares}
   678   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   678   \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
   679   \multicolumn{2}{l}{@{term "(as, x) \<approx>res R fv p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   679   \multicolumn{2}{l}{@{term "(as, x) \<approx>res R fa p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
   680              & @{term "fv(x) - as = fv(y) - bs"} & \mbox{\it (i)}\\
   680              & @{term "fa(x) - as = fa(y) - bs"} & \mbox{\it (i)}\\
   681   \wedge     & @{term "(fv(x) - as) \<sharp>* p"} & \mbox{\it (ii)}\\
   681   \wedge     & @{term "(fa(x) - as) \<sharp>* p"} & \mbox{\it (ii)}\\
   682   \wedge     & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
   682   \wedge     & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
   683   \end{array}
   683   \end{array}
   684   \end{equation}
   684   \end{equation}
   685 
   685 
   686   It might be useful to consider first some examples about how these definitions
   686   It might be useful to consider first some examples about how these definitions
   687   of $\alpha$-equivalence pan out in practice.  For this consider the case of
   687   of $\alpha$-equivalence pan out in practice.  For this consider the case of
   688   abstracting a set of variables over types (as in type-schemes). We set
   688   abstracting a set of atoms over types (as in type-schemes). We set
   689   @{text R} to be the usual equality @{text "="} and for @{text "fv(T)"} we
   689   @{text R} to be the usual equality @{text "="} and for @{text "fa(T)"} we
   690   define
   690   define
   691 
   691 
   692   \begin{center}
   692   \begin{center}
   693   @{text "fv(x) = {x}"}  \hspace{5mm} @{text "fv(T\<^isub>1 \<rightarrow> T\<^isub>2) = fv(T\<^isub>1) \<union> fv(T\<^isub>2)"}
   693   @{text "fa(x) = {x}"}  \hspace{5mm} @{text "fa(T\<^isub>1 \<rightarrow> T\<^isub>2) = fa(T\<^isub>1) \<union> fa(T\<^isub>2)"}
   694   \end{center}
   694   \end{center}
   695 
   695 
   696   \noindent
   696   \noindent
   697   Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and
   697   Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and
   698   \eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and
   698   \eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and
   944   %Interestingly, in case of \isacommand{bind\_set}
   944   %Interestingly, in case of \isacommand{bind\_set}
   945   %and \isacommand{bind\_res} the binding clauses above will make a difference to the semantics
   945   %and \isacommand{bind\_res} the binding clauses above will make a difference to the semantics
   946   %of the specifications (the corresponding $\alpha$-equivalence will differ). We will 
   946   %of the specifications (the corresponding $\alpha$-equivalence will differ). We will 
   947   %show this later with an example.
   947   %show this later with an example.
   948   
   948   
   949   There are also some restrictions we need to impose on binding clauses. The
   949   There are also some restrictions we need to impose on our binding clauses in comparison to
       
   950   the ones of Ott. The
   950   main idea behind these restrictions is that we obtain a sensible notion of
   951   main idea behind these restrictions is that we obtain a sensible notion of
   951   $\alpha$-equivalence where it is ensured that within a given scope a 
   952   $\alpha$-equivalence where it is ensured that within a given scope an 
   952   variable occurence cannot be both bound and free at the same time.  The first
   953   atom occurence cannot be both bound and free at the same time.  The first
   953   restriction is that a body can only occur in
   954   restriction is that a body can only occur in
   954   \emph{one} binding clause of a term constructor (this ensures that the bound
   955   \emph{one} binding clause of a term constructor (this ensures that the bound
   955   variables of a body cannot be free at the same time by specifying an
   956   atoms of a body cannot be free at the same time by specifying an
   956   alternative binder for the same body). For binders we distinguish between
   957   alternative binder for the same body). For binders we distinguish between
   957   \emph{shallow} and \emph{deep} binders.  Shallow binders are just
   958   \emph{shallow} and \emph{deep} binders.  Shallow binders are just
   958   labels. The restriction we need to impose on them is that in case of
   959   labels. The restriction we need to impose on them is that in case of
   959   \isacommand{bind\_set} and \isacommand{bind\_res} the labels must either
   960   \isacommand{bind\_set} and \isacommand{bind\_res} the labels must either
   960   refer to atom types or to sets of atom types; in case of \isacommand{bind}
   961   refer to atom types or to sets of atom types; in case of \isacommand{bind}
  1066 
  1067 
  1067   \noindent
  1068   \noindent
  1068   The difference is that with @{text Let} we only want to bind the atoms @{text
  1069   The difference is that with @{text Let} we only want to bind the atoms @{text
  1069   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1070   "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
  1070   inside the assignment. This difference has consequences for the associated
  1071   inside the assignment. This difference has consequences for the associated
  1071   notions of free-variables and $\alpha$-equivalence.
  1072   notions of free-atoms and $\alpha$-equivalence.
  1072   
  1073   
  1073   To make sure that variables bound by deep binders cannot be free at the
  1074   To make sure that atoms bound by deep binders cannot be free at the
  1074   same time, we cannot have more than one binding function for a deep binder. 
  1075   same time, we cannot have more than one binding function for a deep binder. 
  1075   Consequently we exclude specifications such as
  1076   Consequently we exclude specifications such as
  1076 
  1077 
  1077   \begin{center}
  1078   \begin{center}
  1078   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  1079   \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
  1084   \end{tabular}
  1085   \end{tabular}
  1085   \end{center}
  1086   \end{center}
  1086 
  1087 
  1087   \noindent
  1088   \noindent
  1088   Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"}  pick 
  1089   Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"}  pick 
  1089   out different atoms to become bound, respectively be free, in @{text "p"}.
  1090   out different atoms to become bound, respectively be free, in @{text "p"}
       
  1091   (since the Ott-tool does not derive a reasoning for $\alpha$-equated terms, it can permit 
       
  1092   such specifications).
  1090   
  1093   
  1091   We also need to restrict the form of the binding functions in order 
  1094   We also need to restrict the form of the binding functions in order 
  1092   to ensure the @{text "bn"}-functions can be defined for $\alpha$-equated 
  1095   to ensure the @{text "bn"}-functions can be defined for $\alpha$-equated 
  1093   terms. The main restriction is that we cannot return an atom in a binding function that is also
  1096   terms. The main restriction is that we cannot return an atom in a binding function that is also
  1094   bound in the corresponding term-constructor. That means in \eqref{letpat} 
  1097   bound in the corresponding term-constructor. That means in \eqref{letpat} 
  1105   (as in case @{text PNil}), a singleton set or singleton list containing an
  1108   (as in case @{text PNil}), a singleton set or singleton list containing an
  1106   atom (case @{text PVar}), or unions of atom sets or appended atom lists
  1109   atom (case @{text PVar}), or unions of atom sets or appended atom lists
  1107   (case @{text PTup}). This restriction will simplify some automatic definitions and proofs
  1110   (case @{text PTup}). This restriction will simplify some automatic definitions and proofs
  1108   later on.
  1111   later on.
  1109   
  1112   
  1110   In order to simplify our definitions of free variables and $\alpha$-equivalence, 
  1113   In order to simplify our definitions of free atoms and $\alpha$-equivalence, 
  1111   we shall assume specifications 
  1114   we shall assume specifications 
  1112   of term-calculi are implicitly \emph{completed}. By this we mean that  
  1115   of term-calculi are implicitly \emph{completed}. By this we mean that  
  1113   for every argument of a term-constructor that is \emph{not} 
  1116   for every argument of a term-constructor that is \emph{not} 
  1114   already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
  1117   already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
  1115   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
  1118   clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
  1130   \noindent 
  1133   \noindent 
  1131   The point of completion is that we can make definitions over the binding
  1134   The point of completion is that we can make definitions over the binding
  1132   clauses and be sure to have captured all arguments of a term constructor. 
  1135   clauses and be sure to have captured all arguments of a term constructor. 
  1133 *}
  1136 *}
  1134 
  1137 
  1135 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *}
  1138 section {* Alpha-Equivalence and Free Atoms\label{sec:alpha} *}
  1136 
  1139 
  1137 text {*
  1140 text {*
  1138   Having dealt with all syntax matters, the problem now is how we can turn
  1141   Having dealt with all syntax matters, the problem now is how we can turn
  1139   specifications into actual type definitions in Isabelle/HOL and then
  1142   specifications into actual type definitions in Isabelle/HOL and then
  1140   establish a reasoning infrastructure for them. As
  1143   establish a reasoning infrastructure for them. As
  1141   Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just 
  1144   Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just 
  1142   re-arranging the arguments of
  1145   re-arranging the arguments of
  1143   term-constructors so that binders and their bodies are next to each other will 
  1146   term-constructors so that binders and their bodies are next to each other will 
  1144   result in inadequate representations in cases like @{text "Let x\<^isub>1=t\<^isub>1\<dots>x\<^isub>n=t\<^isub>n in s"}. 
  1147   result in inadequate representations in cases like @{text "Let x\<^isub>1 = t\<^isub>1\<dots>x\<^isub>n = t\<^isub>n in s"}. 
  1145   Therefore we will first
  1148   Therefore we will first
  1146   extract ``raw'' datatype definitions from the specification and then define 
  1149   extract ``raw'' datatype definitions from the specification and then define 
  1147   explicitly an $\alpha$-equivalence relation over them. We subsequently
  1150   explicitly an $\alpha$-equivalence relation over them. We subsequently
  1148   quotient the datatypes according to our $\alpha$-equivalence.
  1151   quotient the datatypes according to our $\alpha$-equivalence.
  1149 
  1152 
  1166   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. 
  1169   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. 
  1167 
  1170 
  1168   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1171   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1169   non-empty and the types in the constructors only occur in positive 
  1172   non-empty and the types in the constructors only occur in positive 
  1170   position (see \cite{Berghofer99} for an indepth description of the datatype package
  1173   position (see \cite{Berghofer99} for an indepth description of the datatype package
  1171   in Isabelle/HOL). We then define the user-specified binding 
  1174   in Isabelle/HOL). We then define each of the user-specified binding 
  1172   functions @{term "bn"} by recursion over the corresponding 
  1175   function @{term "bn\<^isub>i"} by recursion over the corresponding 
  1173   raw datatype. We can also easily define permutation operations by 
  1176   raw datatype. We can also easily define permutation operations by 
  1174   recursion so that for each term constructor @{text "C"} we have that
  1177   recursion so that for each term constructor @{text "C"} we have that
  1175   %
  1178   %
  1176   \begin{equation}\label{ceqvt}
  1179   \begin{equation}\label{ceqvt}
  1177   @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"}
  1180   @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"}
  1178   \end{equation}
  1181   \end{equation}
  1179 
  1182 
  1180   The first non-trivial step we have to perform is the generation of
  1183   The first non-trivial step we have to perform is the generation of
  1181   free-variable functions from the specifications. For the 
  1184   free-atom functions from the specifications. For the 
  1182   \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-variable functions
  1185   \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions
  1183   %
  1186   %
  1184   \begin{equation}\label{fvars}
  1187   \begin{equation}\label{fvars}
  1185   @{text "fv_ty\<^isub>1, \<dots>, fv_ty\<^isub>n"}
  1188   @{text "fa_ty\<^isub>1, \<dots>, fa_ty\<^isub>n"}
  1186   \end{equation}
  1189   \end{equation}
  1187 
  1190 
  1188   \noindent
  1191   \noindent
  1189   by mutual recursion.
  1192   by mutual recursion.
  1190   We define these functions together with auxiliary free-variable functions for
  1193   We define these functions together with auxiliary free-atom functions for
  1191   the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ 
  1194   the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ 
  1192   we define
  1195   we define
  1193   %
  1196   %
  1194   \begin{center}
  1197   \begin{center}
  1195   @{text "fv_bn\<^isub>1, \<dots>, fv_bn\<^isub>m"}
  1198   @{text "fa_bn\<^isub>1, \<dots>, fa_bn\<^isub>m"}
  1196   \end{center}
  1199   \end{center}
  1197 
  1200 
  1198   \noindent
  1201   \noindent
  1199   The reason for this setup is that in a deep binder not all atoms have to be
  1202   The reason for this setup is that in a deep binder not all atoms have to be
  1200   bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function
  1203   bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function
  1201   that calculates those unbound atoms in a deep binder.
  1204   that calculates those unbound atoms in a deep binder.
  1202 
  1205 
  1203   While the idea behind these free-variable functions is clear (they just
  1206   While the idea behind these free-atom functions is clear (they just
  1204   collect all atoms that are not bound), because of our rather complicated
  1207   collect all atoms that are not bound), because of our rather complicated
  1205   binding mechanisms their definitions are somewhat involved.  Given
  1208   binding mechanisms their definitions are somewhat involved.  Given
  1206   a term-constructor @{text "C"} of type @{text ty} and some associated
  1209   a term-constructor @{text "C"} of type @{text ty} and some associated
  1207   binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
  1210   binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
  1208   "fv_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
  1211   "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
  1209   "fv(bc\<^isub>1) \<union> \<dots> \<union> fv(bc\<^isub>k)"} where we define below what @{text "fv"} of a binding
  1212   "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we define below what @{text "fa"} for a binding
  1210   clause means. We only show the mode \isacommand{bind\_set} (the other modes are similar). 
  1213   clause means. We only show the details for the mode \isacommand{bind\_set} (the other modes are similar). 
  1211   Suppose the binding clause @{text bc\<^isub>i} is of the form 
  1214   Suppose the binding clause @{text bc\<^isub>i} is of the form 
  1212   %
  1215   %
  1213   \begin{equation}
  1216   \begin{equation}
  1214   \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
  1217   \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
  1215   \end{equation}
  1218   \end{equation}
  1223   binding atoms in the binders and @{text "B'"} for the free atoms in 
  1226   binding atoms in the binders and @{text "B'"} for the free atoms in 
  1224   non-recursive deep binders,
  1227   non-recursive deep binders,
  1225   then the free atoms of the binding clause @{text bc\<^isub>i} are given by
  1228   then the free atoms of the binding clause @{text bc\<^isub>i} are given by
  1226   %
  1229   %
  1227   \begin{center}
  1230   \begin{center}
  1228   @{text "fv(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}
  1231   @{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}
  1229   \end{center}
  1232   \end{center}
  1230 
  1233 
  1231   \noindent
  1234   \noindent
  1232   The set @{text D} is formally defined as
  1235   whereby the set @{text D} is formally defined as
  1233   %
  1236   %
  1234   \begin{center}
  1237   \begin{center}
  1235   @{text "D \<equiv> fv_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fv_ty\<^isub>q d\<^isub>q"}
  1238   @{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"}
  1236   \end{center} 
  1239   \end{center} 
  1237 
  1240 
  1238   \noindent
  1241   \noindent
  1239   whereby the functions @{text "fv_ty\<^isub>i"} are the ones we are defining by recursion 
  1242   The functions @{text "fa_ty\<^isub>i"} are the ones we are defining by recursion 
  1240   (see \eqref{fvars}) provided the @{text "d\<^isub>i"} refers to one of the raw types 
  1243   (see \eqref{fvars}) in case the @{text "d\<^isub>i"} refers to one of the raw types 
  1241   @{text "ty"}$_{1..n}$ from the specification; otherwise we set @{text "fv_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}.
  1244   @{text "ty"}$_{1..n}$ from the specification; otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}.
  1242   In order to define the set @{text B} we use the following auxiliary @{text "bn"}-functions
  1245   In order to define the set @{text B} we use the following auxiliary @{text "bn"}-functions
  1243   for atom types to which shallow binders have to refer
  1246   for atom types to which shallow binders have to refer
  1244   %
  1247   %
  1245   \begin{center}
  1248   \begin{center}
  1246   \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1249   \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1260   @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"}
  1263   @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"}
  1261   \end{center} 
  1264   \end{center} 
  1262 
  1265 
  1263   \noindent 
  1266   \noindent 
  1264   The set @{text "B'"} collects all free atoms in non-recursive deep
  1267   The set @{text "B'"} collects all free atoms in non-recursive deep
  1265   binders. Lets assume these binders in @{text "bc\<^isub>i"} are
  1268   binders. Let us assume these binders in @{text "bc\<^isub>i"} are
  1266   %
  1269   %
  1267   \begin{center}
  1270   \begin{center}
  1268   @{text "bn\<^isub>1 a\<^isub>1, \<dots>, bn\<^isub>r a\<^isub>r"}
  1271   @{text "bn\<^isub>1 a\<^isub>1, \<dots>, bn\<^isub>r a\<^isub>r"}
  1269   \end{center}
  1272   \end{center}
  1270 
  1273 
  1271   \noindent
  1274   \noindent
  1272   with none of the @{text "a"}$_{1..r}$ being among the bodies @{text
  1275   with none of the @{text "a"}$_{1..r}$ being among the bodies @{text
  1273   "d"}$_{1..q}$. The set @{text "B'"} is defined as
  1276   "d"}$_{1..q}$. The set @{text "B'"} is defined as
  1274   %
  1277   %
  1275   \begin{center}
  1278   \begin{center}
  1276   @{text "B' \<equiv> fv_bn\<^isub>1 a\<^isub>1 \<union> ... \<union> fv_bn\<^isub>r a\<^isub>r"}
  1279   @{text "B' \<equiv> fa_bn\<^isub>1 a\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r a\<^isub>r"}
  1277   \end{center} 
  1280   \end{center} 
  1278 
  1281 
  1279   \noindent
  1282   \noindent
  1280   This completes the definition of the free-variable functions.
  1283   This completes the definition of the free-atom functions.
  1281 
  1284 
  1282   Note that for non-recursive deep binders, we have to add all atoms that are left 
  1285   Note that for non-recursive deep binders, we have to add all atoms that are left 
  1283   unbound by the binding function @{text "bn"}. This is the purpose of the functions 
  1286   unbound by the binding function @{text "bn"} (the set @{text "B'"}). We use for this 
  1284   @{text "fv_bn"}, also defined by recursion. Assume the user specified 
  1287   the functions @{text "fa_bn"}, also defined by recursion. Assume the user specified 
  1285   a @{text bn}-clause of the form
  1288   a @{text bn}-clause of the form
  1286   %
  1289   %
  1287   \begin{center}
  1290   \begin{center}
  1288   @{text "bn (C z\<^isub>1 \<dots> z\<^isub>n) = rhs"}
  1291   @{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"}
  1289   \end{center}
  1292   \end{center}
  1290 
  1293 
  1291   \noindent
  1294   \noindent
  1292   where the @{text "z"}$_{1..n}$ are of types @{text "ty"}$_{1..n}$. For each of
  1295   where the @{text "z"}$_{1..s}$ are of types @{text "ty"}$_{1..s}$. For each of
  1293   the arguments we calculate the free atoms as follows:
  1296   the arguments we calculate the free atoms as follows:
  1294   %
  1297   %
  1295   \begin{center}
  1298   \begin{center}
  1296   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1299   \begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
  1297   $\bullet$ & @{term "fv_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"} 
  1300   $\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"} 
  1298   (nothing gets bound in @{text "z\<^isub>i"}),\\
  1301   (that means nothing is bound in @{text "z\<^isub>i"}),\\
  1299   $\bullet$ & @{term "fv_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"}
  1302   $\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"}
  1300   with the recursive call @{text "bn\<^isub>i z\<^isub>i"}, and\\
  1303   with the recursive call @{text "bn\<^isub>i z\<^isub>i"}, and\\
  1301   $\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"},
  1304   $\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"},
  1302   but without a recursive call
  1305   but without a recursive call.
  1303   \end{tabular}
  1306   \end{tabular}
  1304   \end{center}
  1307   \end{center}
  1305 
  1308 
  1306   \noindent
  1309   \noindent
  1307   For defining @{text "fv_bn (C z\<^isub>1 \<dots> z\<^isub>n)"} we just union up all these values.
  1310   For defining @{text "fa_bn (C z\<^isub>1 \<dots> z\<^isub>n)"} we just union up all these values.
  1308  
  1311  
  1309   To see how these definitions work in practice, let us reconsider the term-constructors 
  1312   To see how these definitions work in practice, let us reconsider the term-constructors 
  1310   @{text "Let"} and @{text "Let_rec"}, as well as @{text "ANil"} and @{text "ACons"} 
  1313   @{text "Let"} and @{text "Let_rec"}, as well as @{text "ANil"} and @{text "ACons"} 
  1311   from the example shown in \eqref{letrecs}. 
  1314   from the example shown in \eqref{letrecs}. 
  1312   For them we define three free-variable functions, namely
  1315   For them we define three free-atom functions, namely
  1313   @{text "fv\<^bsub>trm\<^esub>"}, @{text "fv\<^bsub>assn\<^esub>"} and @{text "fv\<^bsub>bn\<^esub>"} as follows:
  1316   @{text "fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text "fa\<^bsub>bn\<^esub>"} as follows:
  1314   %
  1317   %
  1315   \begin{center}
  1318   \begin{center}
  1316   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
  1319   \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
  1317   @{text "fv\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fv\<^bsub>trm\<^esub> t - set (bn as)) \<union> fv\<^bsub>bn\<^esub> as"}\\
  1320   @{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\
  1318   @{text "fv\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} & @{text "(fv\<^bsub>assn\<^esub> as \<union> fv\<^bsub>trm\<^esub> t) - set (bn as)"}\\[1mm]
  1321   @{text "fa\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} & @{text "(fa\<^bsub>assn\<^esub> as \<union> fa\<^bsub>trm\<^esub> t) - set (bn as)"}\\[1mm]
  1319 
  1322 
  1320   @{text "fv\<^bsub>assn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\
  1323   @{text "fa\<^bsub>assn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\
  1321   @{text "fv\<^bsub>assn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(supp a) \<union> (fv\<^bsub>trm\<^esub> t) \<union> (fv\<^bsub>assn\<^esub> as)"}\\[1mm]
  1324   @{text "fa\<^bsub>assn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(supp a) \<union> (fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>assn\<^esub> as)"}\\[1mm]
  1322 
  1325 
  1323   @{text "fv\<^bsub>bn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\
  1326   @{text "fa\<^bsub>bn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\
  1324   @{text "fv\<^bsub>bn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(fv\<^bsub>trm\<^esub> t) \<union> (fv\<^bsub>bn\<^esub> as)"}
  1327   @{text "fa\<^bsub>bn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>bn\<^esub> as)"}
  1325   \end{tabular}
  1328   \end{tabular}
  1326   \end{center}
  1329   \end{center}
  1327 
  1330 
  1328   \noindent
  1331   \noindent
  1329   To see the ``pattern'', recall that @{text ANil} and @{text "ACons"} have no
  1332   To see the pattern, recall that @{text ANil} and @{text "ACons"} have no
  1330   binding clause in the specification. The corresponding free-variable
  1333   binding clause in the specification. The corresponding free-atom
  1331   function @{text "fv\<^bsub>assn\<^esub>"} therefore returns all atoms
  1334   function @{text "fa\<^bsub>assn\<^esub>"} therefore returns all atoms
  1332   occurring in an assignment. The binding only takes place in @{text Let} and
  1335   occurring in an assignment. The binding only takes place in @{text Let} and
  1333   @{text "Let_rec"}. In the @{text "Let"}-clause, the binding clause specifies
  1336   @{text "Let_rec"}. In the @{text "Let"}-clause, the binding clause specifies
  1334   that all atoms given by @{text "set (bn as)"} have to be bound in @{text
  1337   that all atoms given by @{text "set (bn as)"} have to be bound in @{text
  1335   t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
  1338   t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
  1336   "fv\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are
  1339   "fa\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are
  1337   free in @{text "as"}.  In contrast, in @{text "Let_rec"} we have a recursive
  1340   free in @{text "as"}.  In contrast, in @{text "Let_rec"} we have a recursive
  1338   binder where we want to also bind all occurrences of the atoms in @{text
  1341   binder where we want to also bind all occurrences of the atoms in @{text
  1339   "set (bn as)"} also inside @{text "as"}. Therefore we have to subtract
  1342   "set (bn as)"} also inside @{text "as"}. Therefore we have to subtract
  1340   @{text "set (bn as)"} from the union @{text "fv\<^bsub>trm\<^esub> t"} and @{text "fv\<^bsub>assn\<^esub> as"}. 
  1343   @{text "set (bn as)"} from the union @{text "fa\<^bsub>trm\<^esub> t"} and @{text "fa\<^bsub>assn\<^esub> as"}. 
  1341   
  1344   
  1342   An interesting point in this
  1345   An interesting point in this
  1343   example is that a ``naked'' assignment does not bind any
  1346   example is that a ``naked'' assignment does not bind any
  1344   atoms. Only in the context of a @{text Let} or @{text "Let_rec"} will
  1347   atoms. Only in the context of a @{text Let} or @{text "Let_rec"} will
  1345   some atoms from an assignment become bound.  This is a phenomenon that has also been pointed
  1348   some atoms from an assignment become bound.  This is a phenomenon that has also been pointed
  1347   not be able to lift the @{text "bn"}-function if it was defined over assignments 
  1350   not be able to lift the @{text "bn"}-function if it was defined over assignments 
  1348   where some atoms are bound. In that case @{text "bn"} would \emph{not} respect
  1351   where some atoms are bound. In that case @{text "bn"} would \emph{not} respect
  1349   $\alpha$-equivalence.
  1352   $\alpha$-equivalence.
  1350 
  1353 
  1351   Next we define $\alpha$-equivalence relations for the raw types @{text
  1354   Next we define $\alpha$-equivalence relations for the raw types @{text
  1352   "ty"}$_{1..n}$. We call them 
  1355   "ty"}$_{1..n}$. We write them 
  1353   %
  1356   %
  1354   \begin{center}
  1357   \begin{center}
  1355   @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. 
  1358   @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. 
  1356   \end{center}
  1359   \end{center}
  1357 
  1360 
  1358   \noindent
  1361   \noindent
  1359   Like with the free-variable functions, we also need to
  1362   Like with the free-atom functions, we also need to
  1360   define auxiliary $\alpha$-equivalence relations 
  1363   define auxiliary $\alpha$-equivalence relations 
  1361   %
  1364   %
  1362   \begin{center}
  1365   \begin{center}
  1363   @{text "\<approx>bn\<^isub>1, \<dots>, \<approx>bn\<^isub>m"}
  1366   @{text "\<approx>bn\<^isub>1, \<dots>, \<approx>bn\<^isub>m"}
  1364   \end{center}
  1367   \end{center}
  1365 
  1368 
  1366   \noindent
  1369   \noindent
  1367   for the binding functions @{text "bn"}$_{1..m}$, 
  1370   for the binding functions @{text "bn"}$_{1..m}$, 
  1368   To simplify our definitions we will use the following abbreviations for
  1371   To simplify our definitions we will use the following abbreviations for
  1369   equivalence relations and free-variable functions acting on pairs
  1372   equivalence relations and free-atom functions acting on pairs
  1370 
  1373 
  1371   %
  1374   %
  1372   \begin{center}
  1375   \begin{center}
  1373   \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1376   \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
  1374   @{text "(x\<^isub>1, y\<^isub>1) (R\<^isub>1 \<otimes> R\<^isub>2) (x\<^isub>2, y\<^isub>2)"} & @{text "\<equiv>"} & @{text "x\<^isub>1 R\<^isub>1 y\<^isub>1 \<and> x\<^isub>2 R\<^isub>2 y\<^isub>2"}\\
  1377   @{text "(x\<^isub>1, y\<^isub>1) (R\<^isub>1 \<otimes> R\<^isub>2) (x\<^isub>2, y\<^isub>2)"} & @{text "\<equiv>"} & @{text "x\<^isub>1 R\<^isub>1 y\<^isub>1 \<and> x\<^isub>2 R\<^isub>2 y\<^isub>2"}\\
  1375   @{text "(fv\<^isub>1 \<oplus> fv\<^isub>2) (x, y)"} & @{text "\<equiv>"} & @{text "fv\<^isub>1 x \<union> fv\<^isub>2 y"}\\
  1378   @{text "(fa\<^isub>1 \<oplus> fa\<^isub>2) (x, y)"} & @{text "\<equiv>"} & @{text "fa\<^isub>1 x \<union> fa\<^isub>2 y"}\\
  1376   \end{tabular}
  1379   \end{tabular}
  1377   \end{center}
  1380   \end{center}
  1378 
  1381 
  1379 
  1382 
  1380   The relations for $\alpha$-equivalence are inductively defined 
  1383   The relations for $\alpha$-equivalence are inductively defined 
  1392   analyse the binding clauses and produce a corresponding premise.
  1395   analyse the binding clauses and produce a corresponding premise.
  1393 *}
  1396 *}
  1394 (*<*)
  1397 (*<*)
  1395 consts alpha_ty ::'a
  1398 consts alpha_ty ::'a
  1396 consts alpha_trm ::'a
  1399 consts alpha_trm ::'a
  1397 consts fv_trm :: 'a
  1400 consts fa_trm :: 'a
  1398 consts alpha_trm2 ::'a
  1401 consts alpha_trm2 ::'a
  1399 consts fv_trm2 :: 'a
  1402 consts fa_trm2 :: 'a
  1400 notation (latex output) 
  1403 notation (latex output) 
  1401   alpha_ty ("\<approx>ty") and
  1404   alpha_ty ("\<approx>ty") and
  1402   alpha_trm ("\<approx>\<^bsub>trm\<^esub>") and
  1405   alpha_trm ("\<approx>\<^bsub>trm\<^esub>") and
  1403   fv_trm ("fv\<^bsub>trm\<^esub>") and
  1406   fa_trm ("fa\<^bsub>trm\<^esub>") and
  1404   alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and
  1407   alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and
  1405   fv_trm2 ("fv\<^bsub>assn\<^esub> \<oplus> fv\<^bsub>trm\<^esub>") 
  1408   fa_trm2 ("fa\<^bsub>assn\<^esub> \<oplus> fa\<^bsub>trm\<^esub>") 
  1406 (*>*)
  1409 (*>*)
  1407 text {*
  1410 text {*
  1408   *TBD below *
  1411   *TBD below *
  1409 
  1412 
  1410   \begin{equation}\label{alpha}
  1413   \begin{equation}\label{alpha}
  1417   $\bullet$ & @{term "x\<^isub>i = y\<^isub>i"} provided @{text "x\<^isub>i"} and @{text "y\<^isub>i"} are 
  1420   $\bullet$ & @{term "x\<^isub>i = y\<^isub>i"} provided @{text "x\<^isub>i"} and @{text "y\<^isub>i"} are 
  1418   non-recursive arguments\smallskip\\
  1421   non-recursive arguments\smallskip\\
  1419   \multicolumn{2}{@ {}l}{Shallow binders of the form 
  1422   \multicolumn{2}{@ {}l}{Shallow binders of the form 
  1420   \isacommand{bind\_set}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\ 
  1423   \isacommand{bind\_set}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\ 
  1421   $\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"},
  1424   $\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"},
  1422   @{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fv} is
  1425   @{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fa} is
  1423   @{text "fv_ty\<^isub>1 \<oplus> ... \<oplus> fv_ty\<^isub>m"}, then
  1426   @{text "fa_ty\<^isub>1 \<oplus> ... \<oplus> fa_ty\<^isub>m"}, then
  1424   \begin{center}
  1427   \begin{center}
  1425   @{term "\<exists>p. (x\<^isub>1 \<union> \<xi> \<union> x\<^isub>n, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fv p (y\<^isub>1 \<union> \<xi> \<union> y\<^isub>n, (y'\<^isub>1,\<xi>,y'\<^isub>m))"}
  1428   @{term "\<exists>p. (x\<^isub>1 \<union> \<xi> \<union> x\<^isub>n, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fa p (y\<^isub>1 \<union> \<xi> \<union> y\<^isub>n, (y'\<^isub>1,\<xi>,y'\<^isub>m))"}
  1426   \end{center}\\
  1429   \end{center}\\
  1427   \multicolumn{2}{@ {}l}{Deep binders of the form 
  1430   \multicolumn{2}{@ {}l}{Deep binders of the form 
  1428   \isacommand{bind\_set}~@{text "bn x"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\ 
  1431   \isacommand{bind\_set}~@{text "bn x"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\ 
  1429   $\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"},
  1432   $\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"},
  1430   @{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fv} is
  1433   @{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fa} is
  1431   @{text "fv_ty\<^isub>1 \<oplus> ... \<oplus> fv_ty\<^isub>m"}, then for recursive deep binders
  1434   @{text "fa_ty\<^isub>1 \<oplus> ... \<oplus> fa_ty\<^isub>m"}, then for recursive deep binders
  1432   \begin{center}
  1435   \begin{center}
  1433   @{term "\<exists>p. (bn x, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fv p (bn y, (y'\<^isub>1,\<xi>,y'\<^isub>m))"}
  1436   @{term "\<exists>p. (bn x, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fa p (bn y, (y'\<^isub>1,\<xi>,y'\<^isub>m))"}
  1434   \end{center}\\
  1437   \end{center}\\
  1435   $\bullet$ & for non-recursive binders we generate in addition @{text "x \<approx>bn y"}\\
  1438   $\bullet$ & for non-recursive binders we generate in addition @{text "x \<approx>bn y"}\\
  1436   \end{tabular}}
  1439   \end{tabular}}
  1437   \end{equation}
  1440   \end{equation}
  1438 
  1441 
  1470   $\approx_{\textit{bn}}$, with the clauses as follows:
  1473   $\approx_{\textit{bn}}$, with the clauses as follows:
  1471 
  1474 
  1472   \begin{center}
  1475   \begin{center}
  1473   \begin{tabular}{@ {}c @ {}}
  1476   \begin{tabular}{@ {}c @ {}}
  1474   \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}}
  1477   \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}}
  1475   {@{text "as \<approx>\<^bsub>bn\<^esub> as'"} & @{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fv_trm p (bn as', t')"}}\smallskip\\
  1478   {@{text "as \<approx>\<^bsub>bn\<^esub> as'"} & @{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fa_trm p (bn as', t')"}}\smallskip\\
  1476   \infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}}
  1479   \infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}}
  1477   {@{term "\<exists>p. (bn as, (as, t)) \<approx>lst alpha_trm2 fv_trm2 p (bn as', (as', t'))"}}
  1480   {@{term "\<exists>p. (bn as, (as, t)) \<approx>lst alpha_trm2 fa_trm2 p (bn as', (as', t'))"}}
  1478   \end{tabular}
  1481   \end{tabular}
  1479   \end{center}
  1482   \end{center}
  1480 
  1483 
  1481   \begin{center}
  1484   \begin{center}
  1482   \begin{tabular}{@ {}c @ {}}
  1485   \begin{tabular}{@ {}c @ {}}
  1530   \noindent 
  1533   \noindent 
  1531   We can feed this lemma into our quotient package and obtain new types @{text
  1534   We can feed this lemma into our quotient package and obtain new types @{text
  1532   "ty\<AL>\<^bsub>1..n\<^esub>"} representing $\alpha$-equated terms of types @{text "ty\<^bsub>1..n\<^esub>"}. We also obtain 
  1535   "ty\<AL>\<^bsub>1..n\<^esub>"} representing $\alpha$-equated terms of types @{text "ty\<^bsub>1..n\<^esub>"}. We also obtain 
  1533   definitions for the term-constructors @{text
  1536   definitions for the term-constructors @{text
  1534   "C"}$^\alpha_{1..m}$ from the raw term-constructors @{text
  1537   "C"}$^\alpha_{1..m}$ from the raw term-constructors @{text
  1535   "C"}$_{1..m}$, and similar definitions for the free-variable functions @{text
  1538   "C"}$_{1..m}$, and similar definitions for the free-atom functions @{text
  1536   "fv_ty"}$^\alpha_{1..n}$ and the binding functions @{text
  1539   "fa_ty"}$^\alpha_{1..n}$ and the binding functions @{text
  1537   "bn"}$^\alpha_{1..k}$. However, these definitions are not really useful to the 
  1540   "bn"}$^\alpha_{1..k}$. However, these definitions are not really useful to the 
  1538   user, since they are given in terms of the isomorphisms we obtained by 
  1541   user, since they are given in terms of the isomorphisms we obtained by 
  1539   creating new types in Isabelle/HOL (recall the picture shown in the 
  1542   creating new types in Isabelle/HOL (recall the picture shown in the 
  1540   Introduction).
  1543   Introduction).
  1541 
  1544 
  1617   @{text "p \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n) = C\<^sup>\<alpha> (p \<bullet> x\<^isub>1) \<dots> (p \<bullet> x\<^isub>n)"}
  1620   @{text "p \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n) = C\<^sup>\<alpha> (p \<bullet> x\<^isub>1) \<dots> (p \<bullet> x\<^isub>n)"}
  1618   \end{equation}
  1621   \end{equation}
  1619 
  1622 
  1620   \noindent
  1623   \noindent
  1621   for our infrastructure. In a similar fashion we can lift the equations
  1624   for our infrastructure. In a similar fashion we can lift the equations
  1622   characterising the free-variable functions @{text "fn_ty\<AL>\<^isub>j"} and @{text "fv_bn\<AL>\<^isub>k"}, and the 
  1625   characterising the free-atom functions @{text "fn_ty\<AL>\<^isub>j"} and @{text "fa_bn\<AL>\<^isub>k"}, and the 
  1623   binding functions @{text "bn\<AL>\<^isub>k"}. The necessary respectfulness lemmas for these
  1626   binding functions @{text "bn\<AL>\<^isub>k"}. The necessary respectfulness lemmas for these
  1624   lifting are the properties:
  1627   lifting are the properties:
  1625   %
  1628   %
  1626   \begin{equation}\label{fnresp}
  1629   \begin{equation}\label{fnresp}
  1627   \mbox{%
  1630   \mbox{%
  1628   \begin{tabular}{l}
  1631   \begin{tabular}{l}
  1629   @{text "x \<approx>ty\<^isub>j y"} implies @{text "fv_ty\<^isub>j x = fv_ty\<^isub>j y"}\\
  1632   @{text "x \<approx>ty\<^isub>j y"} implies @{text "fa_ty\<^isub>j x = fa_ty\<^isub>j y"}\\
  1630   @{text "x \<approx>ty\<^isub>k y"} implies @{text "fv_bn\<^isub>k x = fv_bn\<^isub>k y"}\\
  1633   @{text "x \<approx>ty\<^isub>k y"} implies @{text "fa_bn\<^isub>k x = fa_bn\<^isub>k y"}\\
  1631   @{text "x \<approx>ty\<^isub>k y"} implies @{text "bn\<^isub>k x = bn\<^isub>k y"}
  1634   @{text "x \<approx>ty\<^isub>k y"} implies @{text "bn\<^isub>k x = bn\<^isub>k y"}
  1632   \end{tabular}}
  1635   \end{tabular}}
  1633   \end{equation}
  1636   \end{equation}
  1634 
  1637 
  1635   \noindent
  1638   \noindent
  1636   which can be established by induction on @{text "\<approx>ty"}. Whereas the first
  1639   which can be established by induction on @{text "\<approx>ty"}. Whereas the first
  1637   property is always true by the way we defined the free-variable
  1640   property is always true by the way we defined the free-atom
  1638   functions for types, the second and third do \emph{not} hold in general. There is, in principle, 
  1641   functions for types, the second and third do \emph{not} hold in general. There is, in principle, 
  1639   the possibility that the user defines @{text "bn\<^isub>k"} so that it returns an already bound
  1642   the possibility that the user defines @{text "bn\<^isub>k"} so that it returns an already bound
  1640   variable. Then the third property is just not true. However, our 
  1643   atom. Then the third property is just not true. However, our 
  1641   restrictions imposed on the binding functions
  1644   restrictions imposed on the binding functions
  1642   exclude this possibility.
  1645   exclude this possibility.
  1643 
  1646 
  1644   Having the facts \eqref{fnresp} at our disposal, we can lift the
  1647   Having the facts \eqref{fnresp} at our disposal, we can lift the
  1645   definitions that characterise when two terms of the form
  1648   definitions that characterise when two terms of the form
  1660   We call these conditions as \emph{quasi-injectivity}. Except for one function, which
  1663   We call these conditions as \emph{quasi-injectivity}. Except for one function, which
  1661   we have to lift in the next section, we completed
  1664   we have to lift in the next section, we completed
  1662   the lifting part of establishing the reasoning infrastructure. 
  1665   the lifting part of establishing the reasoning infrastructure. 
  1663 
  1666 
  1664   By working now completely on the $\alpha$-equated level, we can first show that 
  1667   By working now completely on the $\alpha$-equated level, we can first show that 
  1665   the free-variable functions and binding functions
  1668   the free-atom functions and binding functions
  1666   are equivariant, namely
  1669   are equivariant, namely
  1667 
  1670 
  1668   \begin{center}
  1671   \begin{center}
  1669   \begin{tabular}{rcl}
  1672   \begin{tabular}{rcl}
  1670   @{text "p \<bullet> (fv_ty\<^sup>\<alpha> x)"} & $=$ & @{text "fv_ty\<^sup>\<alpha> (p \<bullet> x)"}\\
  1673   @{text "p \<bullet> (fa_ty\<^sup>\<alpha> x)"} & $=$ & @{text "fa_ty\<^sup>\<alpha> (p \<bullet> x)"}\\
  1671   @{text "p \<bullet> (fv_bn\<^sup>\<alpha> x)"} & $=$ & @{text "fv_bn\<^sup>\<alpha> (p \<bullet> x)"}\\
  1674   @{text "p \<bullet> (fa_bn\<^sup>\<alpha> x)"} & $=$ & @{text "fa_bn\<^sup>\<alpha> (p \<bullet> x)"}\\
  1672   @{text "p \<bullet> (bn\<^sup>\<alpha> x)"}    & $=$ & @{text "bn\<^sup>\<alpha> (p \<bullet> x)"}
  1675   @{text "p \<bullet> (bn\<^sup>\<alpha> x)"}    & $=$ & @{text "bn\<^sup>\<alpha> (p \<bullet> x)"}
  1673   \end{tabular}
  1676   \end{tabular}
  1674   \end{center}
  1677   \end{center}
  1675 
  1678 
  1676   \noindent
  1679   \noindent
  1695   \end{center}
  1698   \end{center}
  1696 
  1699 
  1697   \noindent
  1700   \noindent
  1698   by a structural induction over @{text "x\<^isub>1, \<dots>, x\<^isub>n"} (whereby @{text "x\<^isub>i"} ranges over the types 
  1701   by a structural induction over @{text "x\<^isub>1, \<dots>, x\<^isub>n"} (whereby @{text "x\<^isub>i"} ranges over the types 
  1699   @{text "ty\<AL>\<^isub>1 \<dots> ty\<AL>\<^isub>n"}). Lastly, we can show that the support of elements in 
  1702   @{text "ty\<AL>\<^isub>1 \<dots> ty\<AL>\<^isub>n"}). Lastly, we can show that the support of elements in 
  1700   @{text "ty\<AL>\<^bsub>1..n\<^esub>"} coincides with @{text "fv_ty\<AL>\<^bsub>1..n\<^esub>"}.
  1703   @{text "ty\<AL>\<^bsub>1..n\<^esub>"} coincides with @{text "fa_ty\<AL>\<^bsub>1..n\<^esub>"}.
  1701 
  1704 
  1702   \begin{lemma} 
  1705   \begin{lemma} 
  1703   For every @{text "x\<^isub>i"} of type @{text "ty\<AL>\<^bsub>1..n\<^esub>"}, we have that 
  1706   For every @{text "x\<^isub>i"} of type @{text "ty\<AL>\<^bsub>1..n\<^esub>"}, we have that 
  1704   @{text "supp x\<^isub>i = fv_ty\<AL>\<^isub>i x\<^isub>i"} holds.
  1707   @{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"} holds.
  1705   \end{lemma}
  1708   \end{lemma}
  1706 
  1709 
  1707   \begin{proof}
  1710   \begin{proof}
  1708   The proof proceeds by structural induction over the @{text "x\<^isub>i"}. In each case
  1711   The proof proceeds by structural induction over the @{text "x\<^isub>i"}. In each case
  1709   we unfold the definition of @{text "supp"}, move the swapping inside the 
  1712   we unfold the definition of @{text "supp"}, move the swapping inside the 
  1844   $\alpha$-equated terms. We can then prove the following two facts
  1847   $\alpha$-equated terms. We can then prove the following two facts
  1845 
  1848 
  1846   \begin{lemma}\label{permutebn} 
  1849   \begin{lemma}\label{permutebn} 
  1847   Given a binding function @{text "bn\<^sup>\<alpha>"} then for all @{text p}
  1850   Given a binding function @{text "bn\<^sup>\<alpha>"} then for all @{text p}
  1848   {\it i)} @{text "p \<bullet> (bn\<^sup>\<alpha> x) = bn\<^sup>\<alpha> (p \<bullet>\<^bsub>bn\<^esub>\<^sup>\<alpha> x)"} and {\it ii)}
  1851   {\it i)} @{text "p \<bullet> (bn\<^sup>\<alpha> x) = bn\<^sup>\<alpha> (p \<bullet>\<^bsub>bn\<^esub>\<^sup>\<alpha> x)"} and {\it ii)}
  1849     @{text "fv_bn\<^isup>\<alpha> x = fv_bn\<^isup>\<alpha> (p \<bullet>\<^bsub>bn\<^esub>\<^sup>\<alpha> x)"}.
  1852     @{text "fa_bn\<^isup>\<alpha> x = fa_bn\<^isup>\<alpha> (p \<bullet>\<^bsub>bn\<^esub>\<^sup>\<alpha> x)"}.
  1850   \end{lemma}
  1853   \end{lemma}
  1851 
  1854 
  1852   \begin{proof} 
  1855   \begin{proof} 
  1853   By induction on @{text x}. The equations follow by simple unfolding 
  1856   By induction on @{text x}. The equations follow by simple unfolding 
  1854   of the definitions. 
  1857   of the definitions. 
  1855   \end{proof}
  1858   \end{proof}
  1856 
  1859 
  1857   \noindent
  1860   \noindent
  1858   The first property states that a permutation applied to a binding function is
  1861   The first property states that a permutation applied to a binding function is
  1859   equivalent to first permuting the binders and then calculating the bound
  1862   equivalent to first permuting the binders and then calculating the bound
  1860   variables. The second amounts to the fact that permuting the binders has no 
  1863   atoms. The second amounts to the fact that permuting the binders has no 
  1861   effect on the free-variable function. The main point of this permutation
  1864   effect on the free-atom function. The main point of this permutation
  1862   function, however, is that if we have a permutation that is fresh 
  1865   function, however, is that if we have a permutation that is fresh 
  1863   for the support of an object @{text x}, then we can use this permutation 
  1866   for the support of an object @{text x}, then we can use this permutation 
  1864   to rename the binders in @{text x}, without ``changing'' @{text x}. In case of the 
  1867   to rename the binders in @{text x}, without ``changing'' @{text x}. In case of the 
  1865   @{text "Let"} term-constructor from the example shown 
  1868   @{text "Let"} term-constructor from the example shown 
  1866   \eqref{letpat} this means for a permutation @{text "r"}:
  1869   \eqref{letpat} this means for a permutation @{text "r"}:
  2101 
  2104 
  2102 text {*
  2105 text {*
  2103 We can also see that
  2106 We can also see that
  2104   %
  2107   %
  2105   \begin{equation}\label{bnprop}
  2108   \begin{equation}\label{bnprop}
  2106   @{text "fv_ty x  =  bn x \<union> fv_bn x"}.
  2109   @{text "fa_ty x  =  bn x \<union> fa_bn x"}.
  2107   \end{equation}
  2110   \end{equation}
  2108 
  2111 
  2109   \noindent
  2112   \noindent
  2110   holds for any @{text "bn"}-function defined for the type @{text "ty"}.
  2113   holds for any @{text "bn"}-function defined for the type @{text "ty"}.
  2111 
  2114