LMCS-Paper/Paper.thy
changeset 3023 a5a6aebec1fb
parent 3022 4de1d6ab04f7
child 3024 10e476d6f4b8
equal deleted inserted replaced
3022:4de1d6ab04f7 3023:a5a6aebec1fb
   164   @{text "\<LET> x = 3 \<AND> y = 2 \<AND> z = foo \<IN> x - y \<END>"}
   164   @{text "\<LET> x = 3 \<AND> y = 2 \<AND> z = foo \<IN> x - y \<END>"}
   165   \]\smallskip
   165   \]\smallskip
   166 
   166 
   167   \noindent
   167   \noindent
   168   Therefore we will also provide a separate binding mechanism for cases in
   168   Therefore we will also provide a separate binding mechanism for cases in
   169   which the order of binders does not matter, but the ``cardinality'' of the
   169   which the order of binders does not matter, but the `cardinality' of the
   170   binders has to agree.
   170   binders has to agree.
   171 
   171 
   172   However, we found that this is still not sufficient for dealing with
   172   However, we found that this is still not sufficient for dealing with
   173   language constructs frequently occurring in programming language
   173   language constructs frequently occurring in programming language
   174   research. For example in @{text "\<LET>"}s containing patterns like
   174   research. For example in @{text "\<LET>"}s containing patterns like
   251   Another is that our reasoning infrastructure, like strong induction principles
   251   Another is that our reasoning infrastructure, like strong induction principles
   252   and the notion of free variables, is derived from first principles within 
   252   and the notion of free variables, is derived from first principles within 
   253   the Isabelle/HOL theorem prover.
   253   the Isabelle/HOL theorem prover.
   254 
   254 
   255   However, we will not be able to cope with all specifications that are
   255   However, we will not be able to cope with all specifications that are
   256   allowed by Ott. One reason is that Ott lets the user specify ``empty'' types
   256   allowed by Ott. One reason is that Ott lets the user specify `empty' types
   257   like \mbox{@{text "t ::= t t | \<lambda>x. t"}} where no clause for variables is
   257   like \mbox{@{text "t ::= t t | \<lambda>x. t"}} where no clause for variables is
   258   given. Arguably, such specifications make some sense in the context of Coq's
   258   given. Arguably, such specifications make some sense in the context of Coq's
   259   type theory (which Ott supports), but not at all in a HOL-based environment
   259   type theory (which Ott supports), but not at all in a HOL-based environment
   260   where every datatype must have a non-empty set-theoretic model
   260   where every datatype must have a non-empty set-theoretic model
   261   \cite{Berghofer99}.  Another reason is that we establish the reasoning
   261   \cite{Berghofer99}.  Another reason is that we establish the reasoning
   262   infrastructure for alpha-\emph{equated} terms. In contrast, Ott produces a
   262   infrastructure for alpha-\emph{equated} terms. In contrast, Ott produces a
   263   reasoning infrastructure in Isabelle/HOL for \emph{non}-alpha-equated, or
   263   reasoning infrastructure in Isabelle/HOL for \emph{non}-alpha-equated, or
   264   ``raw'', terms. While our alpha-equated terms and the raw terms produced by
   264   `raw', terms. While our alpha-equated terms and the raw terms produced by
   265   Ott use names for bound variables, there is a key difference: working with
   265   Ott use names for bound variables, there is a key difference: working with
   266   alpha-equated terms means, for example, that the two type-schemes
   266   alpha-equated terms means, for example, that the two type-schemes
   267 
   267 
   268   \[
   268   \[
   269   @{text "\<forall>{x}. x \<rightarrow> y  = \<forall>{x, z}. x \<rightarrow> y"} 
   269   @{text "\<forall>{x}. x \<rightarrow> y  = \<forall>{x, z}. x \<rightarrow> y"} 
   279   Our insistence on reasoning with alpha-equated terms comes from the
   279   Our insistence on reasoning with alpha-equated terms comes from the
   280   wealth of experience we gained with the older version of Nominal Isabelle:
   280   wealth of experience we gained with the older version of Nominal Isabelle:
   281   for non-trivial properties, reasoning with alpha-equated terms is much
   281   for non-trivial properties, reasoning with alpha-equated terms is much
   282   easier than reasoning with raw terms. The fundamental reason for this is
   282   easier than reasoning with raw terms. The fundamental reason for this is
   283   that the HOL-logic underlying Nominal Isabelle allows us to replace
   283   that the HOL-logic underlying Nominal Isabelle allows us to replace
   284   ``equals-by-equals''. In contrast, replacing
   284   `equals-by-equals'. In contrast, replacing
   285   ``alpha-equals-by-alpha-equals'' in a representation based on ``raw'' terms
   285   `alpha-equals-by-alpha-equals' in a representation based on `raw' terms
   286   requires a lot of extra reasoning work.
   286   requires a lot of extra reasoning work.
   287 
   287 
   288   Although in informal settings a reasoning infrastructure for alpha-equated
   288   Although in informal settings a reasoning infrastructure for alpha-equated
   289   terms is nearly always taken for granted, establishing it automatically in
   289   terms is nearly always taken for granted, establishing it automatically in
   290   Isabelle/HOL is a rather non-trivial task. For every
   290   Isabelle/HOL is a rather non-trivial task. For every
   328 
   328 
   329   The fact that we obtain an isomorphism between the new type and the
   329   The fact that we obtain an isomorphism between the new type and the
   330   non-empty subset shows that the new type is a faithful representation of
   330   non-empty subset shows that the new type is a faithful representation of
   331   alpha-equated terms. That is not the case for example for terms using the
   331   alpha-equated terms. That is not the case for example for terms using the
   332   locally nameless representation of binders \cite{McKinnaPollack99}: in this
   332   locally nameless representation of binders \cite{McKinnaPollack99}: in this
   333   representation there are ``junk'' terms that need to be excluded by
   333   representation there are `junk' terms that need to be excluded by
   334   reasoning about a well-formedness predicate.
   334   reasoning about a well-formedness predicate.
   335 
   335 
   336   The problem with introducing a new type in Isabelle/HOL is that in order to
   336   The problem with introducing a new type in Isabelle/HOL is that in order to
   337   be useful, a reasoning infrastructure needs to be ``lifted'' from the
   337   be useful, a reasoning infrastructure needs to be `lifted' from the
   338   underlying subset to the new type. This is usually a tricky and arduous
   338   underlying subset to the new type. This is usually a tricky and arduous
   339   task. To ease it, we re-implemented in Isabelle/HOL \cite{KaliszykUrban11}
   339   task. To ease it, we re-implemented in Isabelle/HOL \cite{KaliszykUrban11}
   340   the quotient package described by Homeier \cite{Homeier05} for the HOL4
   340   the quotient package described by Homeier \cite{Homeier05} for the HOL4
   341   system. This package allows us to lift definitions and theorems involving
   341   system. This package allows us to lift definitions and theorems involving
   342   raw terms to definitions and theorems involving alpha-equated terms. For
   342   raw terms to definitions and theorems involving alpha-equated terms. For
   366 
   366 
   367   \noindent
   367   \noindent
   368   (Note that this means also the term-constructors for variables, applications
   368   (Note that this means also the term-constructors for variables, applications
   369   and lambda are lifted to the quotient level.)  This construction, of course,
   369   and lambda are lifted to the quotient level.)  This construction, of course,
   370   only works if alpha-equivalence is indeed an equivalence relation, and the
   370   only works if alpha-equivalence is indeed an equivalence relation, and the
   371   ``raw'' definitions and theorems are respectful w.r.t.~alpha-equivalence.
   371   `raw' definitions and theorems are respectful w.r.t.~alpha-equivalence.
   372   For example, we will not be able to lift a bound-variable function. Although
   372   For example, we will not be able to lift a bound-variable function. Although
   373   this function can be defined for raw terms, it does not respect
   373   this function can be defined for raw terms, it does not respect
   374   alpha-equivalence and therefore cannot be lifted. 
   374   alpha-equivalence and therefore cannot be lifted. 
   375   To sum up, every lifting
   375   To sum up, every lifting
   376   of theorems to the quotient level needs proofs of some respectfulness
   376   of theorems to the quotient level needs proofs of some respectfulness
   400   we introduce crucial restrictions, and also extensions, so that our
   400   we introduce crucial restrictions, and also extensions, so that our
   401   specifications make sense for reasoning about alpha-equated terms.  The main
   401   specifications make sense for reasoning about alpha-equated terms.  The main
   402   improvement over Ott is that we introduce three binding modes (only one is
   402   improvement over Ott is that we introduce three binding modes (only one is
   403   present in Ott), provide formalised definitions for alpha-equivalence and
   403   present in Ott), provide formalised definitions for alpha-equivalence and
   404   for free variables of our terms, and also derive a reasoning infrastructure
   404   for free variables of our terms, and also derive a reasoning infrastructure
   405   for our specifications from ``first principles'' inside a theorem prover.
   405   for our specifications from `first principles' inside a theorem prover.
   406 
   406 
   407 
   407 
   408   \begin{figure}[t]
   408   \begin{figure}[t]
   409   \begin{boxedminipage}{\linewidth}
   409   \begin{boxedminipage}{\linewidth}
   410   \begin{center}
   410   \begin{center}
   502   \[
   502   \[
   503   @{text "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
   503   @{text "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
   504   \]\smallskip
   504   \]\smallskip
   505 
   505 
   506   The most original aspect of the nominal logic work of Pitts is a general
   506   The most original aspect of the nominal logic work of Pitts is a general
   507   definition for the notion of the ``set of free variables of an object @{text
   507   definition for the notion of the `set of free variables of an object @{text
   508   "x"}''.  This notion, written @{term "supp x"}, is general in the sense that
   508   "x"}'.  This notion, written @{term "supp x"}, is general in the sense that
   509   it applies not only to lambda-terms (alpha-equated or not), but also to lists,
   509   it applies not only to lambda-terms (alpha-equated or not), but also to lists,
   510   products, sets and even functions. Its definition depends only on the
   510   products, sets and even functions. Its definition depends only on the
   511   permutation operation and on the notion of equality defined for the type of
   511   permutation operation and on the notion of equality defined for the type of
   512   @{text x}, namely:
   512   @{text x}, namely:
   513   
   513   
   633   of binders (being bound, or fresh, in @{text x} is ensured by the
   633   of binders (being bound, or fresh, in @{text x} is ensured by the
   634   assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text "\<pi>"} such that
   634   assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text "\<pi>"} such that
   635   the renamed binders @{term "\<pi> \<bullet> as"} avoid @{text c} (which can be arbitrarily chosen
   635   the renamed binders @{term "\<pi> \<bullet> as"} avoid @{text c} (which can be arbitrarily chosen
   636   as long as it is finitely supported) and also @{text "\<pi>"} does not affect anything
   636   as long as it is finitely supported) and also @{text "\<pi>"} does not affect anything
   637   in the support of @{text x} (that is @{term "supp x \<sharp>* \<pi>"}). The last 
   637   in the support of @{text x} (that is @{term "supp x \<sharp>* \<pi>"}). The last 
   638   fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders 
   638   fact and Property~\ref{supppermeq} allow us to `rename' just the binders 
   639   @{text as} in @{text x}, because @{term "\<pi> \<bullet> x = x"}. 
   639   @{text as} in @{text x}, because @{term "\<pi> \<bullet> x = x"}. 
   640 
   640 
   641   Note that @{term "supp x \<sharp>* \<pi>"}
   641   Note that @{term "supp x \<sharp>* \<pi>"}
   642   is equivalent with @{term "supp \<pi> \<sharp>* x"}, which means we could also formulate 
   642   is equivalent with @{term "supp \<pi> \<sharp>* x"}, which means we could also formulate 
   643   Propositions \ref{supppermeq} and \ref{avoiding} in the other `direction'; however the 
   643   Propositions \ref{supppermeq} and \ref{avoiding} in the other `direction'; however the 
   659   from this specification (remember that Nominal Isabelle is a definitional
   659   from this specification (remember that Nominal Isabelle is a definitional
   660   extension of Isabelle/HOL, which does not introduce any new axioms).
   660   extension of Isabelle/HOL, which does not introduce any new axioms).
   661 
   661 
   662   In order to keep our work with deriving the reasoning infrastructure
   662   In order to keep our work with deriving the reasoning infrastructure
   663   manageable, we will wherever possible state definitions and perform proofs
   663   manageable, we will wherever possible state definitions and perform proofs
   664   on the ``user-level'' of Isabelle/HOL, as opposed to writing custom ML-code that
   664   on the `user-level' of Isabelle/HOL, as opposed to writing custom ML-code that
   665   generates them anew for each specification. 
   665   generates them anew for each specification. 
   666   To that end, we will consider
   666   To that end, we will consider
   667   first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.  These pairs
   667   first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}.  These pairs
   668   are intended to represent the abstraction, or binding, of the set of atoms @{text
   668   are intended to represent the abstraction, or binding, of the set of atoms @{text
   669   "as"} in the body @{text "x"}.
   669   "as"} in the body @{text "x"}.
   674   vacuous binders.) To answer this question, we identify four conditions: {\it (i)}
   674   vacuous binders.) To answer this question, we identify four conditions: {\it (i)}
   675   given a free-atom function @{text "fa"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
   675   given a free-atom function @{text "fa"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
   676   set"}}, then @{text x} and @{text y} need to have the same set of free
   676   set"}}, then @{text x} and @{text y} need to have the same set of free
   677   atoms; moreover there must be a permutation @{text \<pi>} such that {\it
   677   atoms; moreover there must be a permutation @{text \<pi>} such that {\it
   678   (ii)} @{text \<pi>} leaves the free atoms of @{text x} and @{text y} unchanged, but
   678   (ii)} @{text \<pi>} leaves the free atoms of @{text x} and @{text y} unchanged, but
   679   {\it (iii)} ``moves'' their bound names so that we obtain modulo a relation,
   679   {\it (iii)} `moves' their bound names so that we obtain modulo a relation,
   680   say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
   680   say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
   681   @{text \<pi>} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
   681   @{text \<pi>} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
   682   requirements {\it (i)} to {\it (iv)} can be stated formally as:
   682   requirements {\it (i)} to {\it (iv)} can be stated formally as:
   683 
   683 
   684   \begin{defi}[Alpha-Equivalence for Set-Bindings]\label{alphaset}\mbox{}\\
   684   \begin{defi}[Alpha-Equivalence for Set-Bindings]\label{alphaset}\mbox{}\\
   694  
   694  
   695   \noindent
   695   \noindent
   696   Note that the relation is
   696   Note that the relation is
   697   dependent on a free-atom function @{text "fa"} and a relation @{text
   697   dependent on a free-atom function @{text "fa"} and a relation @{text
   698   "R"}. The reason for this extra generality is that we will use
   698   "R"}. The reason for this extra generality is that we will use
   699   $\approx_{\,\textit{set}}^{\textit{R}, \textit{fa}}$ for both ``raw'' terms and 
   699   $\approx_{\,\textit{set}}^{\textit{R}, \textit{fa}}$ for both `raw' terms and 
   700   alpha-equated terms. In
   700   alpha-equated terms. In
   701   the latter case, @{text R} will be replaced by equality @{text "="} and we
   701   the latter case, @{text R} will be replaced by equality @{text "="} and we
   702   will prove that @{text "fa"} is equal to @{text "supp"}.
   702   will prove that @{text "fa"} is equal to @{text "supp"}.
   703 
   703 
   704   Definition \ref{alphaset} does not make any distinction between the
   704   Definition \ref{alphaset} does not make any distinction between the
   889   \begin{equation}\label{halfone}
   889   \begin{equation}\label{halfone}
   890   @{thm Abs_supports(1)[no_vars]}
   890   @{thm Abs_supports(1)[no_vars]}
   891   \end{equation}\smallskip
   891   \end{equation}\smallskip
   892   
   892   
   893   \noindent
   893   \noindent
   894   which by Property~\ref{supportsprop} gives us ``one half'' of
   894   which by Property~\ref{supportsprop} gives us `one half' of
   895   Theorem~\ref{suppabs}. The ``other half'' is a bit more involved. To establish 
   895   Theorem~\ref{suppabs}. The `other half' is a bit more involved. To establish 
   896   it, we use a trick from \cite{Pitts04} and first define an auxiliary 
   896   it, we use a trick from \cite{Pitts04} and first define an auxiliary 
   897   function @{text aux}, taking an abstraction as argument
   897   function @{text aux}, taking an abstraction as argument
   898 
   898 
   899   \[
   899   \[
   900   @{thm supp_set.simps[THEN eq_reflection, no_vars]}
   900   @{thm supp_set.simps[THEN eq_reflection, no_vars]}
   923   @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}.
   923   @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}.
   924   Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes 
   924   Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes 
   925   the first equation of Theorem~\ref{suppabs}. 
   925   the first equation of Theorem~\ref{suppabs}. 
   926 
   926 
   927   Recall the definition of support given in \eqref{suppdef}, and note the difference between 
   927   Recall the definition of support given in \eqref{suppdef}, and note the difference between 
   928   the support of a ``raw'' pair and an abstraction
   928   the support of a `raw' pair and an abstraction
   929 
   929 
   930   \[
   930   \[
   931   @{term "supp (as, x) = supp as \<union> supp x"}\hspace{15mm}
   931   @{term "supp (as, x) = supp as \<union> supp x"}\hspace{15mm}
   932   @{term "supp (Abs_set as x) = supp x - as"}
   932   @{term "supp (Abs_set as x) = supp x - as"}
   933   \]\smallskip
   933   \]\smallskip
   934 
   934 
   935   \noindent
   935   \noindent
   936   While the permutation operations behave in both cases the same (a permutation
   936   While the permutation operations behave in both cases the same (a permutation
   937   is just moved to the arguments), the notion of equality is different for pairs and
   937   is just moved to the arguments), the notion of equality is different for pairs and
   938   abstractions. Therefore we have different supports. In case of abstractions,
   938   abstractions. Therefore we have different supports. In case of abstractions,
   939   we have established that bound atoms are removed from the support of the
   939   we have established in Theorem~\ref{suppabs} that bound atoms are removed from 
   940   abstractions' bodies.
   940   the support of the abstractions' bodies.
   941 
   941 
   942   The method of first considering abstractions of the form @{term "Abs_set as
   942   The method of first considering abstractions of the form @{term "Abs_set as
   943   x"} etc is motivated by the fact that we can conveniently establish at the
   943   x"} etc is motivated by the fact that we can conveniently establish at the
   944   Isabelle/HOL level properties about them.  It would be extremely laborious
   944   Isabelle/HOL level properties about them.  It would be extremely laborious
   945   to write custom ML-code that derives automatically such properties for every
   945   to write custom ML-code that derives automatically such properties for every
   995   \noindent
   995   \noindent
   996   whereby some of the @{text ty}$'_{1..l}$ (or their components) can be
   996   whereby some of the @{text ty}$'_{1..l}$ (or their components) can be
   997   contained in the collection of @{text ty}$^\alpha_{1..n}$ declared in
   997   contained in the collection of @{text ty}$^\alpha_{1..n}$ declared in
   998   \eqref{scheme}. In this case we will call the corresponding argument a
   998   \eqref{scheme}. In this case we will call the corresponding argument a
   999   \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such
   999   \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such
  1000   recursive arguments need to satisfy a ``positivity'' restriction, which
  1000   recursive arguments need to satisfy a `positivity' restriction, which
  1001   ensures that the type has a set-theoretic semantics (see
  1001   ensures that the type has a set-theoretic semantics (see
  1002   \cite{Berghofer99}).  The labels annotated on the types are optional. Their
  1002   \cite{Berghofer99}).  The labels annotated on the types are optional. Their
  1003   purpose is to be used in the (possibly empty) list of \emph{binding
  1003   purpose is to be used in the (possibly empty) list of \emph{binding
  1004   clauses}, which indicate the binders and their scope in a term-constructor.
  1004   clauses}, which indicate the binders and their scope in a term-constructor.
  1005   They come in three \emph{modes}:
  1005   They come in three \emph{modes}:
  1016   \noindent
  1016   \noindent
  1017   The first mode is for binding lists of atoms (the order of bound atoms
  1017   The first mode is for binding lists of atoms (the order of bound atoms
  1018   matters); the second is for sets of binders (the order does not matter, but
  1018   matters); the second is for sets of binders (the order does not matter, but
  1019   the cardinality does) and the last is for sets of binders (with vacuous
  1019   the cardinality does) and the last is for sets of binders (with vacuous
  1020   binders preserving alpha-equivalence). As indicated, the labels in the
  1020   binders preserving alpha-equivalence). As indicated, the labels in the
  1021   ``\isacommand{in}-part'' of a binding clause will be called \emph{bodies};
  1021   `\isacommand{in}-part' of a binding clause will be called \emph{bodies};
  1022   the ``\isacommand{binds}-part'' will be called \emph{binders}. In contrast to
  1022   the `\isacommand{binds}-part' will be called \emph{binders}. In contrast to
  1023   Ott, we allow multiple labels in binders and bodies.  For example we allow
  1023   Ott, we allow multiple labels in binders and bodies.  For example we allow
  1024   binding clauses of the form:
  1024   binding clauses of the form:
  1025  
  1025  
  1026   \[\mbox{
  1026   \[\mbox{
  1027   \begin{tabular}{@ {}ll@ {}}
  1027   \begin{tabular}{@ {}ll@ {}}
  1096   @{text name}, in which case all three binding modes coincide. However, having 
  1096   @{text name}, in which case all three binding modes coincide. However, having 
  1097   \isacommand{binds (set)} or just \isacommand{binds}
  1097   \isacommand{binds (set)} or just \isacommand{binds}
  1098   in the second case makes a difference to the semantics of the specification
  1098   in the second case makes a difference to the semantics of the specification
  1099   (which we will define in the next section).
  1099   (which we will define in the next section).
  1100 
  1100 
  1101   A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
  1101   A \emph{deep} binder uses an auxiliary binding function that `picks' out
  1102   the atoms in one argument of the term-constructor, which can be bound in
  1102   the atoms in one argument of the term-constructor, which can be bound in
  1103   other arguments and also in the same argument (we will call such binders
  1103   other arguments and also in the same argument (we will call such binders
  1104   \emph{recursive}, see below). The binding functions are
  1104   \emph{recursive}, see below). The binding functions are
  1105   expected to return either a set of atoms (for \isacommand{binds (set)} and
  1105   expected to return either a set of atoms (for \isacommand{binds (set)} and
  1106   \isacommand{binds (set+)}) or a list of atoms (for \isacommand{binds}). They need
  1106   \isacommand{binds (set+)}) or a list of atoms (for \isacommand{binds}). They need
  1148 
  1148 
  1149   
  1149   
  1150   \noindent
  1150   \noindent
  1151   where the argument of the deep binder also occurs in the body. We call such
  1151   where the argument of the deep binder also occurs in the body. We call such
  1152   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1152   binders \emph{recursive}.  To see the purpose of such recursive binders,
  1153   compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
  1153   compare `plain' @{text "Let"}s and @{text "Let_rec"}s in the following
  1154   specification:
  1154   specification:
  1155  
  1155  
  1156   \begin{equation}\label{letrecs}
  1156   \begin{equation}\label{letrecs}
  1157   \mbox{%
  1157   \mbox{%
  1158   \begin{tabular}{@ {}l@ {}}
  1158   \begin{tabular}{@ {}l@ {}}
  1270   establish a reasoning infrastructure for them. As Pottier and Cheney pointed
  1270   establish a reasoning infrastructure for them. As Pottier and Cheney pointed
  1271   out \cite{Cheney05,Pottier06}, just re-arranging the arguments of
  1271   out \cite{Cheney05,Pottier06}, just re-arranging the arguments of
  1272   term-constructors so that binders and their bodies are next to each other
  1272   term-constructors so that binders and their bodies are next to each other
  1273   will result in inadequate representations in cases like \mbox{@{text "Let
  1273   will result in inadequate representations in cases like \mbox{@{text "Let
  1274   x\<^isub>1 = t\<^isub>1\<dots>x\<^isub>n = t\<^isub>n in s"}}. Therefore we will
  1274   x\<^isub>1 = t\<^isub>1\<dots>x\<^isub>n = t\<^isub>n in s"}}. Therefore we will
  1275   first extract ``raw'' datatype definitions from the specification and then
  1275   first extract `raw' datatype definitions from the specification and then
  1276   define explicitly an alpha-equivalence relation over them. We subsequently
  1276   define explicitly an alpha-equivalence relation over them. We subsequently
  1277   construct the quotient of the datatypes according to our alpha-equivalence.
  1277   construct the quotient of the datatypes according to our alpha-equivalence.
  1278 
  1278 
  1279 
  1279 
  1280   The ``raw'' datatype definition can be obtained by stripping off the 
  1280   The `raw' datatype definition can be obtained by stripping off the 
  1281   binding clauses and the labels from the types. We also have to invent
  1281   binding clauses and the labels from the types. We also have to invent
  1282   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1282   new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
  1283   given by the user. In our implementation we just use the affix ``@{text "_raw"}''.
  1283   given by the user. In our implementation we just use the affix `@{text "_raw"}'.
  1284   But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1284   But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1285   that a notion is given for alpha-equivalence classes and leave it out 
  1285   that a notion is given for alpha-equivalence classes and leave it out 
  1286   for the corresponding notion given on the ``raw'' level. So for example 
  1286   for the corresponding notion given on the `raw' level. So for example 
  1287   we have @{text "ty\<^sup>\<alpha> / ty"} and @{text "C\<^sup>\<alpha> / C"}
  1287   we have @{text "ty\<^sup>\<alpha> / ty"} and @{text "C\<^sup>\<alpha> / C"}
  1288   where @{term ty} is the type used in the quotient construction for 
  1288   where @{term ty} is the type used in the quotient construction for 
  1289   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor of the ``raw'' type @{text "ty"},
  1289   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor of the `raw' type @{text "ty"},
  1290   respectively @{text "C\<^sup>\<alpha>"} is the corresponding term-constructor of @{text "ty\<^sup>\<alpha>"}. 
  1290   respectively @{text "C\<^sup>\<alpha>"} is the corresponding term-constructor of @{text "ty\<^sup>\<alpha>"}. 
  1291 
  1291 
  1292   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1292   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1293   non-empty and the types in the constructors only occur in positive 
  1293   non-empty and the types in the constructors only occur in positive 
  1294   position (see \cite{Berghofer99} for an in-depth description of the datatype package
  1294   position (see \cite{Berghofer99} for an in-depth description of the datatype package
  1295   in Isabelle/HOL). 
  1295   in Isabelle/HOL). 
  1296   We subsequently define each of the user-specified binding 
  1296   We subsequently define each of the user-specified binding 
  1297   functions @{term "bn"}$_{1..m}$ by recursion over the corresponding 
  1297   functions @{term "bn"}$_{1..m}$ by recursion over the corresponding 
  1298   ``raw'' datatype. We also define permutation operations by 
  1298   `raw' datatype. We also define permutation operations by 
  1299   recursion so that for each term constructor @{text "C"} we have that
  1299   recursion so that for each term constructor @{text "C"} we have that
  1300   
  1300   
  1301   \begin{equation}\label{ceqvt}
  1301   \begin{equation}\label{ceqvt}
  1302   @{text "\<pi> \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (\<pi> \<bullet> z\<^isub>1) \<dots> (\<pi> \<bullet> z\<^isub>n)"}
  1302   @{text "\<pi> \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (\<pi> \<bullet> z\<^isub>1) \<dots> (\<pi> \<bullet> z\<^isub>n)"}
  1303   \end{equation}\smallskip
  1303   \end{equation}\smallskip
  1306   We will need this operation later when we define the notion of alpha-equivalence.
  1306   We will need this operation later when we define the notion of alpha-equivalence.
  1307 
  1307 
  1308   The first non-trivial step we have to perform is the generation of
  1308   The first non-trivial step we have to perform is the generation of
  1309   \emph{free-atom functions} from the specifications.\footnote{Admittedly, the
  1309   \emph{free-atom functions} from the specifications.\footnote{Admittedly, the
  1310   details of our definitions will be somewhat involved. However they are still
  1310   details of our definitions will be somewhat involved. However they are still
  1311   conceptually simple in comparison with the ``positional'' approach taken in
  1311   conceptually simple in comparison with the `positional' approach taken in
  1312   Ott \cite[Pages 88--95]{ott-jfp}, which uses the notions of \emph{occurrences} and
  1312   Ott \cite[Pages 88--95]{ott-jfp}, which uses the notions of \emph{occurrences} and
  1313   \emph{partial equivalence relations} over sets of occurrences.} For the
  1313   \emph{partial equivalence relations} over sets of occurrences.} For the
  1314   \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions
  1314   \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions
  1315 
  1315 
  1316   \begin{equation}\label{fvars}
  1316   \begin{equation}\label{fvars}
  1327   @{text "fa_bn"}\mbox{$_{1..m}$}.
  1327   @{text "fa_bn"}\mbox{$_{1..m}$}.
  1328   \]\smallskip
  1328   \]\smallskip
  1329   
  1329   
  1330   \noindent
  1330   \noindent
  1331   The reason for this setup is that in a deep binder not all atoms have to be
  1331   The reason for this setup is that in a deep binder not all atoms have to be
  1332   bound, as we saw in \eqref{letrecs} with the example of ``plain'' @{text Let}s. We need
  1332   bound, as we saw in \eqref{letrecs} with the example of `plain' @{text Let}s. We need
  1333   therefore functions that calculate those free atoms in deep binders.
  1333   therefore functions that calculate those free atoms in deep binders.
  1334 
  1334 
  1335   While the idea behind these free-atom functions is simple (they just
  1335   While the idea behind these free-atom functions is simple (they just
  1336   collect all atoms that are not bound), because of our rather complicated
  1336   collect all atoms that are not bound), because of our rather complicated
  1337   binding mechanisms their definitions are somewhat involved.  Given
  1337   binding mechanisms their definitions are somewhat involved.  Given
  1338   a ``raw'' term-constructor @{text "C"} of type @{text ty} and some associated
  1338   a `raw' term-constructor @{text "C"} of type @{text ty} and some associated
  1339   binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
  1339   binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
  1340   "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
  1340   "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
  1341   "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we will define below what @{text "fa"} for a binding
  1341   "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we will define below what @{text "fa"} for a binding
  1342   clause means. We only show the details for the mode \isacommand{binds (set)} (the other modes are similar). 
  1342   clause means. We only show the details for the mode \isacommand{binds (set)} (the other modes are similar). 
  1343   Suppose the binding clause @{text bc\<^isub>i} is of the form 
  1343   Suppose the binding clause @{text bc\<^isub>i} is of the form 
  1442   \begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
  1442   \begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
  1443   $\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"}\\ 
  1443   $\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"}\\ 
  1444   & (that means nothing is bound in @{text "z\<^isub>i"} by the binding function),\smallskip\\
  1444   & (that means nothing is bound in @{text "z\<^isub>i"} by the binding function),\smallskip\\
  1445   $\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"}
  1445   $\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"}
  1446   with the recursive call @{text "bn\<^isub>i z\<^isub>i"}\\
  1446   with the recursive call @{text "bn\<^isub>i z\<^isub>i"}\\
  1447   & (that means whatever is ``left over'' from the @{text "bn"}-function is free)\smallskip\\
  1447   & (that means whatever is `left over' from the @{text "bn"}-function is free)\smallskip\\
  1448   $\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"},
  1448   $\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in  @{text "rhs"},
  1449   but without a recursive call\\
  1449   but without a recursive call\\
  1450   & (that means @{text "z\<^isub>i"} is supposed to become bound by the binding function)\\
  1450   & (that means @{text "z\<^isub>i"} is supposed to become bound by the binding function)\\
  1451   \end{tabular}}
  1451   \end{tabular}}
  1452   \]\smallskip
  1452   \]\smallskip
  1494   function @{text "bn"}, the function @{text "fa\<^bsub>bn\<^esub>"} traverses
  1494   function @{text "bn"}, the function @{text "fa\<^bsub>bn\<^esub>"} traverses
  1495   the list of assignments, but instead returns the free atoms, which means in
  1495   the list of assignments, but instead returns the free atoms, which means in
  1496   this example the free atoms in the argument @{text "t"}.
  1496   this example the free atoms in the argument @{text "t"}.
  1497 
  1497 
  1498 
  1498 
  1499   An interesting point in this example is that a ``naked'' assignment (@{text
  1499   An interesting point in this example is that a `naked' assignment (@{text
  1500   "ANil"} or @{text "ACons"}) does not bind any atoms, even if the binding
  1500   "ANil"} or @{text "ACons"}) does not bind any atoms, even if the binding
  1501   function is specified over assignments. Only in the context of a @{text Let}
  1501   function is specified over assignments. Only in the context of a @{text Let}
  1502   or @{text "Let_rec"}, where the binding clauses are given, will some atoms
  1502   or @{text "Let_rec"}, where the binding clauses are given, will some atoms
  1503   actually become bound.  This is a phenomenon that has also been pointed out
  1503   actually become bound.  This is a phenomenon that has also been pointed out
  1504   in \cite{ott-jfp}. For us this observation is crucial, because we would not
  1504   in \cite{ott-jfp}. For us this observation is crucial, because we would not
  1505   be able to lift the @{text "bn"}-functions to alpha-equated terms if they
  1505   be able to lift the @{text "bn"}-functions to alpha-equated terms if they
  1506   act on atoms that are bound. In that case, these functions would \emph{not}
  1506   act on atoms that are bound. In that case, these functions would \emph{not}
  1507   respect alpha-equivalence.
  1507   respect alpha-equivalence.
  1508 
  1508 
  1509   Having the free atom functions at our disposal, we can next define the 
  1509   Having the free-atom functions at our disposal, we can next define the 
  1510   alpha-equivalence relations for the raw types @{text
  1510   alpha-equivalence relations for the raw types @{text
  1511   "ty"}$_{1..n}$. We write them as
  1511   "ty"}$_{1..n}$. We write them as
  1512   
  1512   
  1513   \[
  1513   \[
  1514   \mbox{@{text "\<approx>ty"}$_{1..n}$}.
  1514   \mbox{@{text "\<approx>ty"}$_{1..n}$}.
  1627   \]\smallskip
  1627   \]\smallskip
  1628 
  1628 
  1629   \noindent
  1629   \noindent
  1630   This premise accounts for alpha-equivalence of the bodies of the binding
  1630   This premise accounts for alpha-equivalence of the bodies of the binding
  1631   clause. However, in case the binders have non-recursive deep binders, this
  1631   clause. However, in case the binders have non-recursive deep binders, this
  1632   premise is not enough: we also have to ``propagate'' alpha-equivalence
  1632   premise is not enough: we also have to `propagate' alpha-equivalence
  1633   inside the structure of these binders. An example is @{text "Let"} where we
  1633   inside the structure of these binders. An example is @{text "Let"} where we
  1634   have to make sure the right-hand sides of assignments are
  1634   have to make sure the right-hand sides of assignments are
  1635   alpha-equivalent. For this we use relations @{text "\<approx>bn"}$_{1..m}$ (which we
  1635   alpha-equivalent. For this we use relations @{text "\<approx>bn"}$_{1..m}$ (which we
  1636   will define shortly).  Let us assume the non-recursive deep binders
  1636   will define shortly).  Let us assume the non-recursive deep binders
  1637   in @{text "bc\<^isub>i"} are
  1637   in @{text "bc\<^isub>i"} are
  1719   \end{tabular}}
  1719   \end{tabular}}
  1720   \end{equation}\smallskip
  1720   \end{equation}\smallskip
  1721 
  1721 
  1722   \noindent
  1722   \noindent
  1723   Notice the difference between  $\approx_{\textit{assn}}$ and
  1723   Notice the difference between  $\approx_{\textit{assn}}$ and
  1724   $\approx_{\textit{bn}}$: the latter only ``tracks'' alpha-equivalence of 
  1724   $\approx_{\textit{bn}}$: the latter only `tracks' alpha-equivalence of 
  1725   the components in an assignment that are \emph{not} bound. This is needed in the 
  1725   the components in an assignment that are \emph{not} bound. This is needed in the 
  1726   clause for @{text "Let"} (which has
  1726   clause for @{text "Let"} (which has
  1727   a non-recursive binder). 
  1727   a non-recursive binder). 
  1728   The underlying reason is that the terms inside an assignment are not meant 
  1728   The underlying reason is that the terms inside an assignment are not meant 
  1729   to be ``under'' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"}, 
  1729   to be `under' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"}, 
  1730   because there all components of an assignment are ``under'' the binder. 
  1730   because there all components of an assignment are `under' the binder. 
  1731   Note also that in case of more than one body (that is in the @{text "Let_rec"}-case above)
  1731   Note also that in case of more than one body (that is in the @{text "Let_rec"}-case above)
  1732   we need to parametrise the relation $\approx_{\textit{list}}$ with a compound
  1732   we need to parametrise the relation $\approx_{\textit{list}}$ with a compound
  1733   equivalence relation and a compound free-atom function. This is because the
  1733   equivalence relation and a compound free-atom function. This is because the
  1734   corresponding binding clause specifies a binder with two bodies, namely
  1734   corresponding binding clause specifies a binder with two bodies, namely
  1735   @{text "as"} and @{text "t"}.
  1735   @{text "as"} and @{text "t"}.
  1756   \end{lem}
  1756   \end{lem}
  1757 
  1757 
  1758   \begin{proof}
  1758   \begin{proof}
  1759   The function package of Isabelle/HOL allows us to prove the first part by
  1759   The function package of Isabelle/HOL allows us to prove the first part by
  1760   mutual induction over the definitions of the functions.\footnote{We have
  1760   mutual induction over the definitions of the functions.\footnote{We have
  1761   that they are terminating functions. From this an induction principle is
  1761   that the free-atom functions are terminating. From this the function
  1762   derived by the function package \cite{Krauss09}.} The second is by a
  1762   package derives an induction principle \cite{Krauss09}.} The second is by a
  1763   straightforward induction over the rules of @{text "\<approx>ty"}$_{1..n}$ and
  1763   straightforward induction over the rules of @{text "\<approx>ty"}$_{1..n}$ and
  1764   @{text "\<approx>bn"}$_{1..m}$ using the first part.
  1764   @{text "\<approx>bn"}$_{1..m}$ using the first part.
  1765   \end{proof}
  1765   \end{proof}
  1766 
  1766 
  1767   \noindent
  1767   \noindent
  1783 
  1783 
  1784   \noindent 
  1784   \noindent 
  1785   We can feed the last lemma into our quotient package and obtain new types
  1785   We can feed the last lemma into our quotient package and obtain new types
  1786   @{text "ty"}$^\alpha_{1..n}$ representing alpha-equated terms of types
  1786   @{text "ty"}$^\alpha_{1..n}$ representing alpha-equated terms of types
  1787   @{text "ty"}$_{1..n}$. We also obtain definitions for the term-constructors
  1787   @{text "ty"}$_{1..n}$. We also obtain definitions for the term-constructors
  1788   @{text "C"}$^\alpha_{1..k}$ from the ``raw'' term-constructors @{text
  1788   @{text "C"}$^\alpha_{1..k}$ from the `raw' term-constructors @{text
  1789   "C"}$_{1..k}$, and similar definitions for the free-atom functions @{text
  1789   "C"}$_{1..k}$, and similar definitions for the free-atom functions @{text
  1790   "fa_ty"}$^\alpha_{1..n}$ and @{text "fa_bn"}$^\alpha_{1..m}$ as well as the
  1790   "fa_ty"}$^\alpha_{1..n}$ and @{text "fa_bn"}$^\alpha_{1..m}$ as well as the
  1791   binding functions @{text "bn"}$^\alpha_{1..m}$. However, these definitions
  1791   binding functions @{text "bn"}$^\alpha_{1..m}$. However, these definitions
  1792   are not really useful to the user, since they are given in terms of the
  1792   are not really useful to the user, since they are given in terms of the
  1793   isomorphisms we obtained by creating new types in Isabelle/HOL (recall the
  1793   isomorphisms we obtained by creating new types in Isabelle/HOL (recall the
  1809   \begin{equation}\label{distinctraw}
  1809   \begin{equation}\label{distinctraw}
  1810   \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r"}\;$\not\approx$@{text ty}\;@{text "D y\<^isub>1 \<dots> y\<^isub>s"}}
  1810   \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r"}\;$\not\approx$@{text ty}\;@{text "D y\<^isub>1 \<dots> y\<^isub>s"}}
  1811   \end{equation}\smallskip
  1811   \end{equation}\smallskip
  1812 
  1812 
  1813   \noindent
  1813   \noindent
  1814   holds for the corresponding ``raw'' term-constructors.
  1814   holds for the corresponding `raw' term-constructors.
  1815   In order to deduce \eqref{distinctalpha} from \eqref{distinctraw}, our quotient
  1815   In order to deduce \eqref{distinctalpha} from \eqref{distinctraw}, our quotient
  1816   package needs to know that the ``raw'' term-constructors @{text "C"} and @{text "D"} 
  1816   package needs to know that the `raw' term-constructors @{text "C"} and @{text "D"} 
  1817   are \emph{respectful} w.r.t.~the alpha-equivalence relations (see \cite{Homeier05}).
  1817   are \emph{respectful} w.r.t.~the alpha-equivalence relations (see \cite{Homeier05}).
  1818   Given, for example, @{text "C"} is of type @{text "ty"} with argument types
  1818   Given, for example, @{text "C"} is of type @{text "ty"} with argument types
  1819   @{text "ty"}$_{1..r}$, respectfulness amounts to showing that
  1819   @{text "ty"}$_{1..r}$, respectfulness amounts to showing that
  1820   
  1820   
  1821   \[\mbox{
  1821   \[\mbox{
  1847   restriction imposed on the form of the binding functions---namely \emph{not}
  1847   restriction imposed on the form of the binding functions---namely \emph{not}
  1848   to return any bound atoms. In Ott, in contrast, the user may define @{text
  1848   to return any bound atoms. In Ott, in contrast, the user may define @{text
  1849   "bn"}$_{1..m}$ so that they return bound atoms and in this case the third
  1849   "bn"}$_{1..m}$ so that they return bound atoms and in this case the third
  1850   implication is \emph{not} true. A result is that in general the lifting of the
  1850   implication is \emph{not} true. A result is that in general the lifting of the
  1851   corresponding binding functions in Ott to alpha-equated terms is impossible.
  1851   corresponding binding functions in Ott to alpha-equated terms is impossible.
  1852   Having established respectfulness for the ``raw'' term-constructors, the 
  1852   Having established respectfulness for the `raw' term-constructors, the 
  1853   quotient package is able to automatically deduce \eqref{distinctalpha} from 
  1853   quotient package is able to automatically deduce \eqref{distinctalpha} from 
  1854   \eqref{distinctraw}.
  1854   \eqref{distinctraw}.
  1855 
  1855 
  1856   Next we can lift the permutation operations defined in \eqref{ceqvt}. In
  1856   Next we can lift the permutation operations defined in \eqref{ceqvt}. In
  1857   order to make this lifting to go through, we have to show that the
  1857   order to make this lifting to go through, we have to show that the
  1867   \noindent
  1867   \noindent
  1868   to our infrastructure. In a similar fashion we can lift the defining equations
  1868   to our infrastructure. In a similar fashion we can lift the defining equations
  1869   of the free-atom functions @{text "fa_ty\<AL>"}$_{1..n}$ and
  1869   of the free-atom functions @{text "fa_ty\<AL>"}$_{1..n}$ and
  1870   @{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text
  1870   @{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text
  1871   "bn\<AL>"}$_{1..m}$ and size functions @{text "size_ty\<AL>"}$_{1..n}$.
  1871   "bn\<AL>"}$_{1..m}$ and size functions @{text "size_ty\<AL>"}$_{1..n}$.
  1872   The latter are defined automatically for the ``raw'' types @{text "ty"}$_{1..n}$
  1872   The latter are defined automatically for the `raw' types @{text "ty"}$_{1..n}$
  1873   by the datatype package of Isabelle/HOL.
  1873   by the datatype package of Isabelle/HOL.
  1874 
  1874 
  1875   We also need to lift the properties that characterise when two ``raw'' terms of the form
  1875   We also need to lift the properties that characterise when two `raw' terms of the form
  1876   
  1876   
  1877   \[
  1877   \[
  1878   \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r \<approx>ty C x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}}
  1878   \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r \<approx>ty C x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}}
  1879   \]\smallskip
  1879   \]\smallskip
  1880 
  1880 
  1953   recursive arguments of this term constructor (similarly for the other
  1953   recursive arguments of this term constructor (similarly for the other
  1954   term-constructors). 
  1954   term-constructors). 
  1955 
  1955 
  1956   Recall the lambda-calculus with @{text "Let"}-patterns shown in
  1956   Recall the lambda-calculus with @{text "Let"}-patterns shown in
  1957   \eqref{letpat}. The cases lemmas and the induction principle shown in
  1957   \eqref{letpat}. The cases lemmas and the induction principle shown in
  1958   \eqref{cases} and \eqref{induct} boil down in this example to the following three inference
  1958   \eqref{cases} and \eqref{induct} boil down in that example to the following three inference
  1959   rules (the cases lemmas are on the left-hand side; the induction principle
  1959   rules (the cases lemmas are on the left-hand side; the induction principle
  1960   on the right):
  1960   on the right):
  1961 
  1961 
  1962   \begin{equation}\label{inductex}\mbox{
  1962   \begin{equation}\label{inductex}\mbox{
  1963   \begin{tabular}{c}
  1963   \begin{tabular}{c}
  2017   \]\smallskip
  2017   \]\smallskip
  2018 
  2018 
  2019   
  2019   
  2020   \noindent
  2020   \noindent
  2021   Lastly, we can show that the support of elements in @{text
  2021   Lastly, we can show that the support of elements in @{text
  2022   "ty\<AL>"}$_{1..n}$ is the same as the free atom functions @{text
  2022   "ty\<AL>"}$_{1..n}$ is the same as the free-atom functions @{text
  2023   "fa_ty\<AL>"}$_{1..n}$.  This fact is important in the nominal setting where
  2023   "fa_ty\<AL>"}$_{1..n}$.  This fact is important in the nominal setting where
  2024   the general theory is formulated in terms of support and freshness, but also
  2024   the general theory is formulated in terms of support and freshness, but also
  2025   provides evidence that our notions of free-atoms and alpha-equivalence
  2025   provides evidence that our notions of free-atoms and alpha-equivalence
  2026   ``match up'' correctly.
  2026   `match up' correctly.
  2027 
  2027 
  2028   \begin{thm}\label{suppfa} 
  2028   \begin{thm}\label{suppfa} 
  2029   For @{text "x"}$_{1..n}$ with type @{text "ty\<AL>"}$_{1..n}$, we have
  2029   For @{text "x"}$_{1..n}$ with type @{text "ty\<AL>"}$_{1..n}$, we have
  2030   @{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"}.
  2030   @{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"}.
  2031   \end{thm}
  2031   \end{thm}
  2038   for which we have to know that every body of an abstraction is finitely supported.
  2038   for which we have to know that every body of an abstraction is finitely supported.
  2039   This, we have proved earlier.
  2039   This, we have proved earlier.
  2040   \end{proof}
  2040   \end{proof}
  2041 
  2041 
  2042   \noindent
  2042   \noindent
  2043   Consequently, we can replace the free atom functions by @{text "supp"} in  
  2043   Consequently, we can replace the free-atom functions by @{text "supp"} in  
  2044   our quasi-injection lemmas. In the examples shown in \eqref{alphalift}, for instance,
  2044   our quasi-injection lemmas. In the examples shown in \eqref{alphalift}, for instance,
  2045   we obtain for @{text "Let\<^sup>\<alpha>"} and @{text "Let_rec\<^sup>\<alpha>"} 
  2045   we obtain for @{text "Let\<^sup>\<alpha>"} and @{text "Let_rec\<^sup>\<alpha>"} 
  2046 
  2046 
  2047   \[\mbox{
  2047   \[\mbox{
  2048   \begin{tabular}{@ {}c @ {}}
  2048   \begin{tabular}{@ {}c @ {}}
  2089   \noindent
  2089   \noindent
  2090   using the support of abstractions derived in Theorem~\ref{suppabs}.
  2090   using the support of abstractions derived in Theorem~\ref{suppabs}.
  2091 
  2091 
  2092   To sum up this section, we have established a reasoning infrastructure for the
  2092   To sum up this section, we have established a reasoning infrastructure for the
  2093   types @{text "ty\<AL>"}$_{1..n}$ by first lifting definitions from the
  2093   types @{text "ty\<AL>"}$_{1..n}$ by first lifting definitions from the
  2094   ``raw'' level to the quotient level and then by proving facts about
  2094   `raw' level to the quotient level and then by proving facts about
  2095   these lifted definitions. All necessary proofs are generated automatically
  2095   these lifted definitions. All necessary proofs are generated automatically
  2096   by custom ML-code.
  2096   by custom ML-code.
  2097 *}
  2097 *}
  2098 
  2098 
  2099 
  2099 
  2101 
  2101 
  2102 text {*
  2102 text {*
  2103   In the previous section we derived induction principles for alpha-equated
  2103   In the previous section we derived induction principles for alpha-equated
  2104   terms (see \eqref{induct} for the general form and \eqref{inductex} for an
  2104   terms (see \eqref{induct} for the general form and \eqref{inductex} for an
  2105   example). This was done by lifting the corresponding inductions principles
  2105   example). This was done by lifting the corresponding inductions principles
  2106   for ``raw'' terms.  We already employed these induction principles for
  2106   for `raw' terms.  We already employed these induction principles for
  2107   deriving several facts about alpha-equated terms, including the property that
  2107   deriving several facts about alpha-equated terms, including the property that
  2108   the free-variable functions and the notion of support coincide. Still, we
  2108   the free-atom functions and the notion of support coincide. Still, we
  2109   call these induction principles \emph{weak}, because for a term-constructor,
  2109   call these induction principles \emph{weak}, because for a term-constructor,
  2110   say \mbox{@{text "C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r"}}, the induction
  2110   say \mbox{@{text "C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r"}}, the induction
  2111   hypothesis requires us to establish (under some assumptions) a property
  2111   hypothesis requires us to establish (under some assumptions) a property
  2112   @{text "P (C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r)"} for \emph{all} @{text
  2112   @{text "P (C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r)"} for \emph{all} @{text
  2113   "x"}$_{1..r}$. The problem with this is that in the presence of binders we cannot make
  2113   "x"}$_{1..r}$. The problem with this is that in the presence of binders we cannot make
  2149   P\<^bsub>trm\<^esub> y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}, as the
  2149   P\<^bsub>trm\<^esub> y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}, as the
  2150   weak one does, the stronger induction principle establishes the properties
  2150   weak one does, the stronger induction principle establishes the properties
  2151   of the form @{text " P\<^bsub>trm\<^esub> c y\<^isub>1 \<and>
  2151   of the form @{text " P\<^bsub>trm\<^esub> c y\<^isub>1 \<and>
  2152   P\<^bsub>pat\<^esub> c y\<^isub>2"} in which the additional parameter @{text
  2152   P\<^bsub>pat\<^esub> c y\<^isub>2"} in which the additional parameter @{text
  2153   c} is assumed to be of finite support. The purpose of @{text "c"} is to
  2153   c} is assumed to be of finite support. The purpose of @{text "c"} is to
  2154   ``control'' which freshness assumptions the binders should satisfy in the
  2154   `control' which freshness assumptions the binders should satisfy in the
  2155   @{text "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"} cases: for @{text
  2155   @{text "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"} cases: for @{text
  2156   "Lam\<^sup>\<alpha>"} we can assume the bound atom @{text "x\<^isub>1"} is fresh
  2156   "Lam\<^sup>\<alpha>"} we can assume the bound atom @{text "x\<^isub>1"} is fresh
  2157   for @{text "c"} (third line); for @{text "Let_pat\<^sup>\<alpha>"} we can assume
  2157   for @{text "c"} (third line); for @{text "Let_pat\<^sup>\<alpha>"} we can assume
  2158   all bound atoms from an assignment are fresh for @{text "c"} (fourth
  2158   all bound atoms from an assignment are fresh for @{text "c"} (fourth
  2159   line). If @{text "c"} is instantiated appropriately in the strong induction
  2159   line). If @{text "c"} is instantiated appropriately in the strong induction
  2160   principle, the user can mimic the usual ``pencil-and-paper'' reasoning
  2160   principle, then the user can mimic the usual `pencil-and-paper' reasoning
  2161   employing the variable convention about bound and free variables being
  2161   employing the variable convention about bound and free variables being
  2162   distinct \cite{Urban08}.
  2162   distinct \cite{Urban08}.
  2163 
  2163 
  2164   In what follows we will show that the weak induction principle in
  2164   In what follows we will show that the weak induction principle in
  2165   \eqref{inductex} implies the strong one \eqref{stronginduct}. This fact was established for
  2165   \eqref{inductex} implies the strong one \eqref{stronginduct}. This fact was established for
  2166   single binders in \cite{Urban08} by some quite involved, nevertheless
  2166   single binders in \cite{Urban08} by some quite involved, nevertheless
  2167   automated, induction proof. In this paper we simplify the proof by
  2167   automated, induction proof. In this paper we simplify the proof by
  2168   leveraging the automated proving methods from the function package of
  2168   leveraging the automated proving tools from the function package of
  2169   Isabelle/HOL \cite{Krauss09}. The reasoning principle behind these methods
  2169   Isabelle/HOL \cite{Krauss09}. The reasoning principle behind these tools
  2170   is well-founded induction. To use them in our setting, we have to discharge
  2170   is well-founded induction. To use them in our setting, we have to discharge
  2171   two proof obligations: one is that we have well-founded measures (one for
  2171   two proof obligations: one is that we have well-founded measures (one for
  2172   each type @{text "ty"}$^\alpha_{1..n}$) that decrease in every induction
  2172   each type @{text "ty"}$^\alpha_{1..n}$) that decrease in every induction
  2173   step and the other is that we have covered all cases in the induction
  2173   step and the other is that we have covered all cases in the induction
  2174   principle. Once these two proof obligations are discharged, the reasoning
  2174   principle. Once these two proof obligations are discharged, the reasoning
  2175   infrastructure in the function package will automatically derive the
  2175   infrastructure in the function package will automatically derive the
  2176   stronger induction principle. This way of establishing the stronger induction
  2176   stronger induction principle. This way of establishing the stronger induction
  2177   principle is considerably simpler than the work presented \cite{Urban08}.
  2177   principle is considerably simpler than the earlier work presented \cite{Urban08}.
  2178 
  2178 
  2179   As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
  2179   As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
  2180   which we lifted in the previous section and which are all well-founded. It
  2180   which we lifted in the previous section and which are all well-founded. It
  2181   is straightforward to establish that the sizes decrease in every
  2181   is straightforward to establish that the sizes decrease in every
  2182   induction step. What is left to show is that we covered all cases. 
  2182   induction step. What is left to show is that we covered all cases. 
  2205   \noindent
  2205   \noindent
  2206   They are stronger in the sense that they allow us to assume in the @{text
  2206   They are stronger in the sense that they allow us to assume in the @{text
  2207   "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"} cases that the bound atoms
  2207   "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"} cases that the bound atoms
  2208   avoid a context @{text "c"} (which is assumed to be finitely supported).
  2208   avoid a context @{text "c"} (which is assumed to be finitely supported).
  2209   
  2209   
  2210   These stronger cases lemmas need to be derived from the `weak' cases lemmas
  2210   These stronger cases lemmas can be derived from the `weak' cases lemmas
  2211   given in \eqref{inductex}. This is trivial in case of patterns (the one on
  2211   given in \eqref{inductex}. This is trivial in case of patterns (the one on
  2212   the right-hand side) since the weak and strong cases lemma coincide (there
  2212   the right-hand side) since the weak and strong cases lemma coincide (there
  2213   is no binding in patterns).  Interesting are only the cases for @{text
  2213   is no binding in patterns).  Interesting are only the cases for @{text
  2214   "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"}, where we have some binders and
  2214   "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"}, where we have some binders and
  2215   therefore have an addition assumption about avoiding @{text "c"}.  Let us
  2215   therefore have an addition assumption about avoiding @{text "c"}.  Let us
  2228   @{text "\<forall>x\<^isub>1 x\<^isub>2. atom x\<^isub>1 # c \<and> y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  2228   @{text "\<forall>x\<^isub>1 x\<^isub>2. atom x\<^isub>1 # c \<and> y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  2229   \end{equation}\smallskip
  2229   \end{equation}\smallskip
  2230 
  2230 
  2231   \noindent
  2231   \noindent
  2232   which we must use to infer @{text "P\<^bsub>trm\<^esub>"}. Clearly, we cannot
  2232   which we must use to infer @{text "P\<^bsub>trm\<^esub>"}. Clearly, we cannot
  2233   use this implication directly, because we have no information whether @{text
  2233   use this implication directly, because we have no information whether or not @{text
  2234   "x\<^isub>1"} is fresh for @{text "c"}.  However, we can use Properties
  2234   "x\<^isub>1"} is fresh for @{text "c"}.  However, we can use Properties
  2235   \ref{supppermeq} and \ref{avoiding} to rename @{text "x\<^isub>1"}: we know
  2235   \ref{supppermeq} and \ref{avoiding} to rename @{text "x\<^isub>1"}: we know
  2236   by Theorem~\ref{suppfa} that @{text "{atom x\<^isub>1} #\<^sup>* Lam\<^sup>\<alpha>
  2236   by Theorem~\ref{suppfa} that @{text "{atom x\<^isub>1} #\<^sup>* Lam\<^sup>\<alpha>
  2237   x\<^isub>1 x\<^isub>2"} (since its support is @{text "supp x\<^isub>2 -
  2237   x\<^isub>1 x\<^isub>2"} (since its support is @{text "supp x\<^isub>2 -
  2238   {atom x\<^isub>1}"}). Property \ref{avoiding} provides us then with a
  2238   {atom x\<^isub>1}"}). Property \ref{avoiding} provides us then with a
  2262   \begin{equation}\label{impletpat}
  2262   \begin{equation}\label{impletpat}
  2263   @{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. set (bn\<^sup>\<alpha> x\<^isub>1) #\<^sup>* c \<and> y = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  2263   @{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. set (bn\<^sup>\<alpha> x\<^isub>1) #\<^sup>* c \<and> y = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  2264   \end{equation}\smallskip
  2264   \end{equation}\smallskip
  2265 
  2265 
  2266   \noindent
  2266   \noindent
  2267   The reason that this case is more complicated is that we cannot apply directly Property 
  2267   The reason that this case is more complicated is that we cannot directly apply Property 
  2268   \ref{avoiding} for obtaining a renaming permutation. Property \ref{avoiding} requires
  2268   \ref{avoiding} for obtaining a renaming permutation. Property \ref{avoiding} requires
  2269   that the binders are fresh for the term in which we want to perform the renaming. But
  2269   that the binders are fresh for the term in which we want to perform the renaming. But
  2270   this is not true in cases like (using informal notation)
  2270   this is not true in terms such as (using an informal notation)
  2271 
  2271 
  2272   \[
  2272   \[
  2273   @{text "Let (x, y) := (x, y) in (x, y)"}
  2273   @{text "Let (x, y) := (x, y) in (x, y)"}
  2274   \]\smallskip
  2274   \]\smallskip
  2275 
  2275 
  2276   \noindent
  2276   \noindent
  2277   where @{text x} and @{text y} are bound in the term, but they are also free
  2277   where @{text x} and @{text y} are bound in the term, but they are also free
  2278   in the assignment. We can, however, obtain such a renaming permutation, say
  2278   in the right-hand side of the assignment. We can, however, obtain such a renaming permutation, say
  2279   @{text "\<pi>"}, for the abstraction @{term "Abs_lst (bn_al x\<^isub>1)
  2279   @{text "\<pi>"}, for the abstraction @{term "Abs_lst (bn_al x\<^isub>1)
  2280   x\<^isub>3"}. As a result we have \mbox{@{term "set (bn_al (\<pi> \<bullet> x\<^isub>1))
  2280   x\<^isub>3"}. As a result we have \mbox{@{term "set (bn_al (\<pi> \<bullet> x\<^isub>1))
  2281   \<sharp>* c"}} and @{term "Abs_lst (bn_al (\<pi> \<bullet> x\<^isub>1)) (\<pi> \<bullet> x\<^isub>3) =
  2281   \<sharp>* c"}} and @{term "Abs_lst (bn_al (\<pi> \<bullet> x\<^isub>1)) (\<pi> \<bullet> x\<^isub>3) =
  2282   Abs_lst (bn_al x\<^isub>1) x\<^isub>3"} (remember @{text "set"} and @{text
  2282   Abs_lst (bn_al x\<^isub>1) x\<^isub>3"} (remember @{text "set"} and @{text
  2283   "bn\<^sup>\<alpha>"} are equivariant).  Now the quasi-injective property for @{text
  2283   "bn\<^sup>\<alpha>"} are equivariant).  Now the quasi-injective property for @{text
  2289   @{text "p \<approx>\<AL>\<^bsub>bn\<^esub> p\<PRIME>"}\;\; & @{text "t\<^isub>1 = t\<PRIME>\<^isub>1"}}
  2289   @{text "p \<approx>\<AL>\<^bsub>bn\<^esub> p\<PRIME>"}\;\; & @{text "t\<^isub>1 = t\<PRIME>\<^isub>1"}}
  2290   \]\smallskip
  2290   \]\smallskip
  2291 
  2291 
  2292   \noindent
  2292   \noindent
  2293   Since all atoms in a pattern are bound by @{text "Let_pat\<^sup>\<alpha>"}, we can infer
  2293   Since all atoms in a pattern are bound by @{text "Let_pat\<^sup>\<alpha>"}, we can infer
  2294   @{text "(\<pi> \<bullet> x\<^isub>1) \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} holds for every @{text "\<pi>"}. Therefore we have that
  2294   that @{text "(\<pi> \<bullet> x\<^isub>1) \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} holds for every @{text "\<pi>"}. Therefore we have that
  2295 
  2295 
  2296   \[
  2296   \[
  2297   @{text "Let_pat\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) x\<^isub>2 (\<pi> \<bullet> x\<^isub>3) = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3"}  
  2297   @{text "Let_pat\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) x\<^isub>2 (\<pi> \<bullet> x\<^isub>3) = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3"}  
  2298   \]\smallskip
  2298   \]\smallskip
  2299   
  2299   
  2300   \noindent
  2300   \noindent
  2301   Taking the left-hand side in the assumption from \eqref{assmtwo}, we can use
  2301   Taking the left-hand side in the assumption shown in \eqref{assmtwo}, we can use
  2302   the implication \eqref{impletpat} from the stronger cases lemma to infer @{text "P\<^bsub>trm\<^esub>"}, as needed.
  2302   the implication \eqref{impletpat} from the stronger cases lemma to infer @{text "P\<^bsub>trm\<^esub>"}, as needed.
  2303 
  2303 
  2304   The remaining difficulty is when a deep binder contains atoms that are
  2304   The remaining difficulty is when a deep binder contains some atoms that are
  2305   bound, but also some that are free. An example is @{text "Let\<^sup>\<alpha>"} in
  2305   bound and some that are free. An example is @{text "Let\<^sup>\<alpha>"} in
  2306   the example \eqref{letrecs}.  In such cases @{text "(\<pi> \<bullet> x\<^isub>1)
  2306   the example \eqref{letrecs}.  In such cases @{text "(\<pi> \<bullet> x\<^isub>1)
  2307   \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} does not hold in general. The idea is
  2307   \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} does not hold in general. The idea however is
  2308   that we only want to rename binders that will become bound. This does not
  2308   that @{text "\<pi>"} only renames atoms that become bound. In this way @{text "\<pi>"}
  2309   affect @{text "\<approx>\<AL>\<^bsub>bn\<^esub>"}. However, the problem is that the
  2309   does not affect @{text "\<approx>\<AL>\<^bsub>bn\<^esub>"}. However, the problem is that the
  2310   permutation operation @{text "_ \<bullet> _"} applies to all of them. To avoid this
  2310   permutation operation @{text "\<pi> \<bullet> x\<^isub>1"} applies to all attoms in @{text "x\<^isub>1"}. To avoid this
  2311   we introduce an auxiliary permutation operations, written @{text "_
  2311   we introduce an auxiliary permutation operations, written @{text "_
  2312   \<bullet>\<^bsub>bn\<^esub> _"}, for deep binders that only permutes bound atoms (or
  2312   \<bullet>\<^bsub>bn\<^esub> _"}, for deep binders that only permutes bound atoms (or
  2313   more precisely the atoms specified by the @{text "bn"}-functions) and leaves
  2313   more precisely the atoms specified by the @{text "bn"}-functions) and leaves
  2314   the other atoms unchanged. Like the @{text "fa_bn"}$_{1..m}$-functions, we
  2314   the other atoms unchanged. Like the functions @{text "fa_bn"}$_{1..m}$, we
  2315   can define these operations over raw terms analysing how the @{text
  2315   can define these operations over raw terms analysing how the functions @{text
  2316   "bn"}$_{1..m}$-functions are defined. Assuming the user specified a clause
  2316   "bn"}$_{1..m}$ are defined. Assuming the user specified a clause
  2317 
  2317 
  2318   \[  
  2318   \[  
  2319   @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}
  2319   @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}
  2320   \]\smallskip
  2320   \]\smallskip
  2321 
  2321 
  2333   \noindent
  2333   \noindent
  2334   Using again the quotient package  we can lift the @{text "_ \<bullet>\<^bsub>bn\<^esub> _"} functions to 
  2334   Using again the quotient package  we can lift the @{text "_ \<bullet>\<^bsub>bn\<^esub> _"} functions to 
  2335   alpha-equated terms. Moreover we can prove the following two properties
  2335   alpha-equated terms. Moreover we can prove the following two properties
  2336 
  2336 
  2337   \begin{lem}\label{permutebn} 
  2337   \begin{lem}\label{permutebn} 
  2338   Given a binding function @{text "bn\<^sup>\<alpha>"} then for all @{text "\<pi>"}\smallskip\\
  2338   Given a binding function @{text "bn\<^sup>\<alpha>"} and auxiliary equivalence @{text "\<approx>\<AL>\<^bsub>bn\<^esub>"} 
       
  2339   then for all @{text "\<pi>"}\smallskip\\
  2339   {\it (i)} @{text "\<pi> \<bullet> (bn\<^sup>\<alpha> x) = bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x)"} and\\ 
  2340   {\it (i)} @{text "\<pi> \<bullet> (bn\<^sup>\<alpha> x) = bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x)"} and\\ 
  2340   {\it (ii)} @{text "(\<pi>  \<bullet>\<AL>\<^bsub>bn\<^esub> x) \<approx>\<AL>\<^bsub>bn\<^esub> x"}.
  2341   {\it (ii)} @{text "(\<pi>  \<bullet>\<AL>\<^bsub>bn\<^esub> x) \<approx>\<AL>\<^bsub>bn\<^esub> x"}.
  2341   \end{lem}
  2342   \end{lem}
  2342 
  2343 
  2343   \begin{proof} 
  2344   \begin{proof} 
  2361   @{text "(\<pi> \<bullet> (set (bn\<^sup>\<alpha> x\<^isub>1)) #\<^sup>* c"} \hspace{10mm}
  2362   @{text "(\<pi> \<bullet> (set (bn\<^sup>\<alpha> x\<^isub>1)) #\<^sup>* c"} \hspace{10mm}
  2362   @{text "\<pi> \<bullet> [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2 = [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2"} 
  2363   @{text "\<pi> \<bullet> [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2 = [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2"} 
  2363   \]\smallskip
  2364   \]\smallskip
  2364 
  2365 
  2365   \noindent
  2366   \noindent
  2366   hold. Using Lemma \ref{permutebn}{\it (i)} we can simplify this
  2367   hold. Using the first part of Lemma \ref{permutebn}, we can simplify this
  2367   to @{text "set (bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1)) #\<^sup>* c"} and 
  2368   to @{text "set (bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1)) #\<^sup>* c"} and 
  2368   @{text "[bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1)]\<^bsub>list\<^esub>. (\<pi> \<bullet> x\<^isub>2) = [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2"}. Since
  2369   @{text "[bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1)]\<^bsub>list\<^esub>. (\<pi> \<bullet> x\<^isub>2) = [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2"}. Since
  2369   @{text "(\<pi>  \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1) \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} holds by Lemma \ref{permutebn}{\it (ii)},
  2370   @{text "(\<pi>  \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1) \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} holds by teh second part,
  2370   we can infer that
  2371   we can infer that
  2371 
  2372 
  2372   \[
  2373   \[
  2373   @{text "Let\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1) (\<pi> \<bullet> x\<^isub>2) = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}  
  2374   @{text "Let\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1) (\<pi> \<bullet> x\<^isub>2) = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}  
  2374   \]\smallskip
  2375   \]\smallskip
  2375 
  2376 
  2376   \noindent
  2377   \noindent
  2377   holds. This allows us to use the implication from the strong cases
  2378   holds. This allows us to use the implication from the strong cases
  2378   lemma.
  2379   lemma.
  2379 
  2380 
  2380   Conseqently,  we can discharge all proof-obligations to do with having covered all
  2381   Conseqently,  we can discharge all proof-obligations about having covered all
  2381   cases. This completes the proof showing that the weak induction principles imply 
  2382   cases. This completes the proof establishing that the weak induction principles imply 
  2382   the strong induction principles.
  2383   the strong induction principles. These strong induction principles have proved 
       
  2384   already to be very useful in practice, particularly for proving properties about 
       
  2385   capture-avoiding substitution. 
  2383 *}
  2386 *}
  2384 
  2387 
  2385 
  2388 
  2386 section {* Related Work\label{related} *}
  2389 section {* Related Work\label{related} *}
  2387 
  2390 
  2391   formalisation of the algorithm W. This formalisation implements binding in
  2394   formalisation of the algorithm W. This formalisation implements binding in
  2392   type-schemes using a de-Bruijn indices representation. Since type-schemes in
  2395   type-schemes using a de-Bruijn indices representation. Since type-schemes in
  2393   W contain only a single place where variables are bound, different indices
  2396   W contain only a single place where variables are bound, different indices
  2394   do not refer to different binders (as in the usual de-Bruijn
  2397   do not refer to different binders (as in the usual de-Bruijn
  2395   representation), but to different bound variables. A similar idea has been
  2398   representation), but to different bound variables. A similar idea has been
  2396   recently explored for general binders by Chargu\'eraud in the locally nameless 
  2399   recently explored for general binders by Chargu\'eraud \cite{chargueraud09}
  2397   approach to
  2400   in the locally nameless approach to
  2398   binding \cite{chargueraud09}.  There, de-Bruijn indices consist of two
  2401   binding.  There, de-Bruijn indices consist of two
  2399   numbers, one referring to the place where a variable is bound, and the other
  2402   numbers, one referring to the place where a variable is bound, and the other
  2400   to which variable is bound. The reasoning infrastructure for both
  2403   to which variable is bound. The reasoning infrastructure for both
  2401   representations of bindings comes for free in theorem provers like
  2404   representations of bindings comes for free in theorem provers like
  2402   Isabelle/HOL and Coq, since the corresponding term-calculi can be implemented
  2405   Isabelle/HOL and Coq, since the corresponding term-calculi can be implemented
  2403   as ``normal'' datatypes.  However, in both approaches it seems difficult to
  2406   as `normal' datatypes.  However, in both approaches it seems difficult to
  2404   achieve our fine-grained control over the ``semantics'' of bindings
  2407   achieve our fine-grained control over the `semantics' of bindings
  2405   (i.e.~whether the order of binders should matter, or vacuous binders should
  2408   (i.e.~whether the order of binders should matter, or vacuous binders should
  2406   be taken into account). To do so, one would require additional predicates
  2409   be taken into account). To do so, one would require additional predicates
  2407   that filter out unwanted terms. Our guess is that such predicates result in
  2410   that filter out unwanted terms. Our guess is that such predicates result in
  2408   rather intricate formal reasoning. We are not aware of any formalisation of 
  2411   rather intricate formal reasoning. We are not aware of any formalisation of 
  2409   a non-trivial language that uses Chargu\'eraud's idea.
  2412   a non-trivial language that uses Chargu\'eraud's idea.
  2410 
  2413 
  2411   Another technique for representing binding is higher-order abstract syntax
  2414   Another technique for representing binding is higher-order abstract syntax
  2412   (HOAS), which for example is implemented in the Twelf system. This
  2415   (HOAS), which for example is implemented in the Twelf system \cite{pfenningsystem}. 
  2413   representation technique supports very elegantly many aspects of
  2416   This representation technique supports very elegantly many aspects of
  2414   \emph{single} binding, and impressive work by Lee et al has been done that
  2417   \emph{single} binding, and impressive work by Lee et al ~\cite{LeeCraryHarper07} 
  2415   uses HOAS for mechanising the metatheory of SML~\cite{LeeCraryHarper07}. We
  2418   has been done that uses HOAS for mechanising the metatheory of SML. We
  2416   are, however, not aware how multiple binders of SML are represented in this
  2419   are, however, not aware how multiple binders of SML are represented in this
  2417   work. Judging from the submitted Twelf-solution for the POPLmark challenge,
  2420   work. Judging from the submitted Twelf-solution for the POPLmark challenge,
  2418   HOAS cannot easily deal with binding constructs where the number of bound
  2421   HOAS cannot easily deal with binding constructs where the number of bound
  2419   variables is not fixed. For example In the second part of this challenge,
  2422   variables is not fixed. For example, in the second part of this challenge,
  2420   @{text "Let"}s involve patterns that bind multiple variables at once. In
  2423   @{text "Let"}s involve patterns that bind multiple variables at once. In
  2421   such situations, HOAS seems to have to resort to the
  2424   such situations, HOAS seems to have to resort to the
  2422   iterated-single-binders-approach with all the unwanted consequences when
  2425   iterated-single-binders-approach with all the unwanted consequences when
  2423   reasoning about the resulting terms.
  2426   reasoning about the resulting terms.
  2424 
  2427 
  2427   performed in older
  2430   performed in older
  2428   versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W 
  2431   versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W 
  2429   \cite{BengtsonParow09,UrbanNipkow09}).  Both
  2432   \cite{BengtsonParow09,UrbanNipkow09}).  Both
  2430   use the approach based on iterated single binders. Our experience with
  2433   use the approach based on iterated single binders. Our experience with
  2431   the latter formalisation has been disappointing. The major pain arose from
  2434   the latter formalisation has been disappointing. The major pain arose from
  2432   the need to ``unbind'' variables. This can be done in one step with our
  2435   the need to `unbind' variables. This can be done in one step with our
  2433   general binders described in this paper, but needs a cumbersome
  2436   general binders described in this paper, but needs a cumbersome
  2434   iteration with single binders. The resulting formal reasoning turned out to
  2437   iteration with single binders. The resulting formal reasoning turned out to
  2435   be rather unpleasant. 
  2438   be rather unpleasant. 
  2436  
  2439  
  2437   The most closely related work to the one presented here is the Ott-tool by
  2440   The most closely related work to the one presented here is the Ott-tool by
  2438   Sewell et al \cite{ott-jfp} and the C$\alpha$ml language by Pottier
  2441   Sewell et al \cite{ott-jfp} and the C$\alpha$ml language by Pottier
  2439   \cite{Pottier06}. Ott is a nifty front-end for creating \LaTeX{} documents
  2442   \cite{Pottier06}. Ott is a nifty front-end for creating \LaTeX{} documents
  2440   from specifications of term-calculi involving general binders. For a subset
  2443   from specifications of term-calculi involving general binders. For a subset
  2441   of the specifications Ott can also generate theorem prover code using a ``raw''
  2444   of the specifications Ott can also generate theorem prover code using a `raw'
  2442   representation of terms, and in Coq also a locally nameless
  2445   representation of terms, and in Coq also a locally nameless
  2443   representation. The developers of this tool have also put forward (on paper)
  2446   representation. The developers of this tool have also put forward (on paper)
  2444   a definition for alpha-equivalence and free variables for terms that can be
  2447   a definition for alpha-equivalence and free variables for terms that can be
  2445   specified in Ott.  This definition is rather different from ours, not using
  2448   specified in Ott.  This definition is rather different from ours, not using
  2446   any nominal techniques.  To our knowledge there is no concrete mathematical
  2449   any nominal techniques.  To our knowledge there is no concrete mathematical
  2447   result concerning this notion of alpha-equivalence and free variables. We
  2450   result concerning this notion of alpha-equivalence and free variables. We
  2448   have proved that our definitions lead to alpha-equated terms, whose support
  2451   have proved that our definitions lead to alpha-equated terms, whose support
  2449   is as expected (that means bound names are removed from the support). We
  2452   is as expected (that means bound names are removed from the support). We
  2450   also showed that our specifications lift from ``raw'' types to types of
  2453   also showed that our specifications lift from `raw' types to types of
  2451   alpha-equivalence classes. For this we had to establish (automatically) that every
  2454   alpha-equivalence classes. For this we had to establish (automatically) that every
  2452   term-constructor and function is respectful w.r.t.~alpha-equivalence.
  2455   term-constructor and function defined for `raw' types 
       
  2456   is respectful w.r.t.~alpha-equivalence.
  2453 
  2457 
  2454   Although we were heavily inspired by the syntax of Ott, its definition of
  2458   Although we were heavily inspired by the syntax of Ott, its definition of
  2455   alpha-equi\-valence is unsuitable for our extension of Nominal
  2459   alpha-equi\-valence is unsuitable for our extension of Nominal
  2456   Isabelle. First, it is far too complicated to be a basis for automated
  2460   Isabelle. First, it is far too complicated to be a basis for automated
  2457   proofs implemented on the ML-level of Isabelle/HOL. Second, it covers cases
  2461   proofs implemented on the ML-level of Isabelle/HOL. Second, it covers cases
  2473   \end{tabular}}
  2477   \end{tabular}}
  2474   \]\smallskip
  2478   \]\smallskip
  2475   
  2479   
  2476   \noindent
  2480   \noindent
  2477   In the first term-constructor we have a single body that happens to be
  2481   In the first term-constructor we have a single body that happens to be
  2478   ``spread'' over two arguments; in the second term-constructor we have two
  2482   `spread' over two arguments; in the second term-constructor we have two
  2479   independent bodies in which the same variables are bound. As a result we
  2483   independent bodies in which the same variables are bound. As a result we
  2480   have\footnote{Assuming @{term "a \<noteq> b"}, there is no permutation that can
  2484   have\footnote{Assuming @{term "a \<noteq> b"}, there is no permutation that can
  2481   make @{text "(a, b)"} equal with both @{text "(a, b)"} and @{text "(b, a)"}, but
  2485   make @{text "(a, b)"} equal with both @{text "(a, b)"} and @{text "(b, a)"}, but
  2482   there are two permutations so that we can make @{text "(a, b)"} and @{text
  2486   there are two permutations so that we can make @{text "(a, b)"} and @{text
  2483   "(a, b)"} equal with one permutation, and @{text "(a, b)"} and @{text "(b,
  2487   "(a, b)"} equal with one permutation, and @{text "(a, b)"} and @{text "(b,
  2505   and therefore need the extra generality to be able to distinguish between
  2509   and therefore need the extra generality to be able to distinguish between
  2506   both specifications.  Because of how we set up our definitions, we also had
  2510   both specifications.  Because of how we set up our definitions, we also had
  2507   to impose some restrictions (like a single binding function for a deep
  2511   to impose some restrictions (like a single binding function for a deep
  2508   binder) that are not present in Ott. Our expectation is that we can still
  2512   binder) that are not present in Ott. Our expectation is that we can still
  2509   cover many interesting term-calculi from programming language research, for
  2513   cover many interesting term-calculi from programming language research, for
  2510   example Core-Haskell (see Figure~\ref{nominalcorehas}).
  2514   example the Core-Haskell language from the Introduction. With the work
  2511 
  2515   presented in this paper we can define formally this language as shown in 
  2512   \begin{figure}[t]
  2516   Figure~\ref{nominalcorehas} and then Nominal Isabelle derives automatically
       
  2517   a corresponding reasoning infrastructure.
       
  2518 
       
  2519   \begin{figure}[p]
  2513   \begin{boxedminipage}{\linewidth}
  2520   \begin{boxedminipage}{\linewidth}
  2514   \small
  2521   \small
  2515   \begin{tabular}{l}
  2522   \begin{tabular}{l}
  2516   \isacommand{atom\_decl}~@{text "var cvar tvar"}\\[1mm]
  2523   \isacommand{atom\_decl}~@{text "var cvar tvar"}\\[1mm]
  2517   \isacommand{nominal\_datatype}~@{text "tkind ="}~@{text "KStar"}~$|$~@{text "KFun tkind tkind"}\\ 
  2524   \isacommand{nominal\_datatype}~@{text "tkind ="}~@{text "KStar"}~$|$~@{text "KFun tkind tkind"}\\ 
  2554   $|$~@{text "bv\<^isub>2 (TVTKCons a ty tl) = (atom a)::(bv\<^isub>2 tl)"}\\
  2561   $|$~@{text "bv\<^isub>2 (TVTKCons a ty tl) = (atom a)::(bv\<^isub>2 tl)"}\\
  2555   $|$~@{text "bv\<^isub>3 TVCKNil = []"}\\
  2562   $|$~@{text "bv\<^isub>3 TVCKNil = []"}\\
  2556   $|$~@{text "bv\<^isub>3 (TVCKCons c cty tl) = (atom c)::(bv\<^isub>3 tl)"}\\
  2563   $|$~@{text "bv\<^isub>3 (TVCKCons c cty tl) = (atom c)::(bv\<^isub>3 tl)"}\\
  2557   \end{tabular}
  2564   \end{tabular}
  2558   \end{boxedminipage}
  2565   \end{boxedminipage}
  2559   \caption{The nominal datatype declaration for Core-Haskell. For the moment we
  2566   \caption{A definition for Core-Haskell in Nominal Isabelle. For the moment we
  2560   do not support nested types; therefore we explicitly have to unfold the 
  2567   do not support nested types; therefore we explicitly have to unfold the 
  2561   lists @{text "co_lst"}, @{text "assoc_lst"} and so on. Apart from that, the 
  2568   lists @{text "co_lst"}, @{text "assoc_lst"} and so on. Apart from that, the 
  2562   declaration follows closely the original in Figure~\ref{corehas}. The
  2569   definition follows closely the original shown in Figure~\ref{corehas}. The
  2563   point of our work is that having made such a declaration in Nominal Isabelle,
  2570   point of our work is that having made such a definition in Nominal Isabelle,
  2564   one obtains automatically a reasoning infrastructure for Core-Haskell.\bigskip\bigskip
  2571   one obtains automatically a reasoning infrastructure for Core-Haskell.
  2565   \label{nominalcorehas}}
  2572   \label{nominalcorehas}}
  2566   \end{figure}
  2573   \end{figure}
  2567 
  2574   \afterpage{\clearpage}
  2568 
  2575 
  2569   Pottier presents a programming language, called C$\alpha$ml, for
  2576   Pottier presents a programming language, called C$\alpha$ml, for
  2570   representing terms with general binders inside OCaml \cite{Pottier06}. This
  2577   representing terms with general binders inside OCaml \cite{Pottier06}. This
  2571   language is implemented as a front-end that can be translated to OCaml with
  2578   language is implemented as a front-end that can be translated to OCaml with
  2572   the help of a library. He presents a type-system in which the scope of
  2579   the help of a library. He presents a type-system in which the scope of
  2594 section {* Conclusion *}
  2601 section {* Conclusion *}
  2595 
  2602 
  2596 text {*
  2603 text {*
  2597 
  2604 
  2598   We have presented an extension of Nominal Isabelle for dealing with general
  2605   We have presented an extension of Nominal Isabelle for dealing with general
  2599   binders, that is term-constructors having multiple bound variables. For this
  2606   binders, that is where term-constructors have multiple bound atoms. For this
  2600   extension we introduced new definitions of alpha-equivalence and automated
  2607   extension we introduced new definitions of alpha-equivalence and automated
  2601   all necessary proofs in Isabelle/HOL.  To specify general binders we used
  2608   all necessary proofs in Isabelle/HOL.  To specify general binders we used
  2602   the syntax from Ott, but extended it in some places and restricted
  2609   the syntax from Ott, but extended it in some places and restricted
  2603   it in others so that they make sense in the context of alpha-equated
  2610   it in others so that the definitions make sense in the context of alpha-equated
  2604   terms. We also introduced two binding modes (set and set+) that do not exist
  2611   terms. We also introduced two binding modes (set and set+) that do not exist
  2605   in Ott. We have tried out the extension with calculi such as Core-Haskell,
  2612   in Ott. We have tried out the extension with calculi such as Core-Haskell,
  2606   type-schemes and approximately a dozen of other typical examples from
  2613   type-schemes and approximately a dozen of other typical examples from
  2607   programming language research~\cite{SewellBestiary}. The code will
  2614   programming language research~\cite{SewellBestiary}. The code will
  2608   eventually become part of the next Isabelle distribution.\footnote{It 
  2615   eventually become part of the next Isabelle distribution.\footnote{It 
  2609   can be downloaded from \href{http://isabelle.in.tum.de/nominal/download}
  2616   can be downloaded already from \href{http://isabelle.in.tum.de/nominal/download}
  2610   {http://isabelle.in.tum.de/nominal/download}.}
  2617   {http://isabelle.in.tum.de/nominal/download}.}
  2611 
  2618 
  2612   We have left out a discussion about how functions can be defined over
  2619   We have left out a discussion about how functions can be defined over
  2613   alpha-equated terms involving general binders. In earlier versions of
  2620   alpha-equated terms involving general binders. In earlier versions of
  2614   Nominal Isabelle this turned out to be a thorny issue.  We hope to do better
  2621   Nominal Isabelle this turned out to be a thorny issue.  We hope to do better
  2622   datatype definitions allow one to specify, for instance, the function kinds
  2629   datatype definitions allow one to specify, for instance, the function kinds
  2623   in Core-Haskell as @{text "TFun string (ty list)"} instead of the unfolded
  2630   in Core-Haskell as @{text "TFun string (ty list)"} instead of the unfolded
  2624   version @{text "TFun string ty_list"} (see Figure~\ref{nominalcorehas}). To
  2631   version @{text "TFun string ty_list"} (see Figure~\ref{nominalcorehas}). To
  2625   achieve this, we need more clever implementation than we have 
  2632   achieve this, we need more clever implementation than we have 
  2626   at the moment. However, really lifting this restriction will involve major
  2633   at the moment. However, really lifting this restriction will involve major
  2627   work on the datatype package of Isabelle/HOL.
  2634   work on the underlying datatype package of Isabelle/HOL.
  2628 
  2635 
  2629   A more interesting line of investigation is whether we can go beyond the 
  2636   A more interesting line of investigation is whether we can go beyond the 
  2630   simple-minded form of binding functions that we adopted from Ott. At the moment, binding
  2637   simple-minded form of binding functions that we adopted from Ott. At the moment, binding
  2631   functions can only return the empty set, a singleton atom set or unions
  2638   functions can only return the empty set, a singleton atom set or unions
  2632   of atom sets (similarly for lists). It remains to be seen whether 
  2639   of atom sets (similarly for lists). It remains to be seen whether 
  2641   
  2648   
  2642   We have also not yet played with other binding modes. For example we can
  2649   We have also not yet played with other binding modes. For example we can
  2643   imagine that there is need for a binding mode where instead of usual lists,
  2650   imagine that there is need for a binding mode where instead of usual lists,
  2644   we abstract lists of distinct elements (the corresponding type @{text
  2651   we abstract lists of distinct elements (the corresponding type @{text
  2645   "dlist"} already exists in the library of Isabelle/HOL). We expect the
  2652   "dlist"} already exists in the library of Isabelle/HOL). We expect the
  2646   presented work can be easily extended to accommodate them.\medskip
  2653   presented work can be easily extended to accommodate such binding modes.\medskip
  2647   
  2654   
  2648   \noindent
  2655   \noindent
  2649   {\bf Acknowledgements:} We are very grateful to Andrew Pitts for many
  2656   {\bf Acknowledgements:} We are very grateful to Andrew Pitts for many
  2650   discussions about Nominal Isabelle. We thank Peter Sewell for making the
  2657   discussions about Nominal Isabelle. We thank Peter Sewell for making the
  2651   informal notes \cite{SewellBestiary} available to us and also for patiently
  2658   informal notes \cite{SewellBestiary} available to us and also for patiently