LMCS-Paper/Paper.thy
changeset 3017 014f0ea2381c
parent 3016 799769b40f0e
child 3018 65452cf6f5ae
equal deleted inserted replaced
3016:799769b40f0e 3017:014f0ea2381c
   872   @{thm (concl) Abs_swap1(1)[where bs="as", no_vars]}
   872   @{thm (concl) Abs_swap1(1)[where bs="as", no_vars]}
   873   \end{lem}
   873   \end{lem}
   874   
   874   
   875   \begin{proof}
   875   \begin{proof}
   876   If @{term "a = b"} the lemma is immediate, since @{term "(a \<rightleftharpoons> b) = 0"}.
   876   If @{term "a = b"} the lemma is immediate, since @{term "(a \<rightleftharpoons> b) = 0"}.
   877   Also in the other case, it is straightforward using \eqref{abseqiff} and
   877   Also in the other case it is straightforward using \eqref{abseqiff} and
   878   observing that the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) =
   878   observing that the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) =
   879   (supp x - as)"}.  We therefore can use as permutation the swapping @{term
   879   (supp x - as)"}.  We therefore can use as permutation the swapping @{term
   880   "(a \<rightleftharpoons> b)"}.
   880   "(a \<rightleftharpoons> b)"}.
   881   \end{proof}
   881   \end{proof}
   882   
   882   
  1037   an example.
  1037   an example.
  1038 
  1038 
  1039   
  1039   
  1040   There are also some restrictions we need to impose on our binding clauses in
  1040   There are also some restrictions we need to impose on our binding clauses in
  1041   comparison to the ones of Ott. The main idea behind these restrictions is
  1041   comparison to the ones of Ott. The main idea behind these restrictions is
  1042   that we obtain a sensible notion of alpha-equivalence where it is ensured
  1042   that we obtain a notion of alpha-equivalence where it is ensured
  1043   that within a given scope an atom occurrence cannot be both bound and free
  1043   that within a given scope an atom occurrence cannot be both bound and free
  1044   at the same time.  The first restriction is that a body can only occur in
  1044   at the same time.  The first restriction is that a body can only occur in
  1045   \emph{one} binding clause of a term constructor. So for example
  1045   \emph{one} binding clause of a term constructor. So for example
  1046 
  1046 
  1047   \[\mbox{
  1047   \[\mbox{
  1213   \end{tabular}}
  1213   \end{tabular}}
  1214   \end{equation}\smallskip
  1214   \end{equation}\smallskip
  1215 
  1215 
  1216   \noindent
  1216   \noindent
  1217   In this example the term constructor @{text "ACons'"} has four arguments with
  1217   In this example the term constructor @{text "ACons'"} has four arguments with
  1218   a binding clause for two of them. This constructor is also used in the definition
  1218   a binding clause involving two of them. This constructor is also used in the definition
  1219   of the binding function. The restriction we have to impose is that the
  1219   of the binding function. The restriction we have to impose is that the
  1220   binding function can only return free atoms, that is the ones that are not
  1220   binding function can only return free atoms, that is the ones that are \emph{not}
  1221   mentioned in a binding clause.  Therefore @{text "y"} cannot be used in the
  1221   mentioned in a binding clause.  Therefore @{text "y"} cannot be used in the
  1222   binding function @{text "bn"} (since it is bound in @{text "ACons'"} by the
  1222   binding function @{text "bn"} (since it is bound in @{text "ACons'"} by the
  1223   binding clause), but @{text x} can (since it is a free atom). This
  1223   binding clause), but @{text x} can (since it is a free atom). This
  1224   restriction is sufficient for lifting the binding function to alpha-equated
  1224   restriction is sufficient for lifting the binding function to alpha-equated
  1225   terms. If we would permit that @{text "bn"} can also return @{text "y"},
  1225   terms. If we would permit @{text "bn"} to return @{text "y"},
  1226   then it would not be respectful and therefore cannot be lifted.
  1226   then it would not be respectful and therefore cannot be lifted to
       
  1227   alpha-equated lambda-terms.
  1227 
  1228 
  1228   In the version of Nominal Isabelle described here, we also adopted the
  1229   In the version of Nominal Isabelle described here, we also adopted the
  1229   restriction from the Ott-tool that binding functions can only return: the
  1230   restriction from the Ott-tool that binding functions can only return: the
  1230   empty set or empty list (as in case @{text ANil'}), a singleton set or
  1231   empty set or empty list (as in case @{text ANil'}), a singleton set or
  1231   singleton list containing an atom (case @{text PVar} in \eqref{letpat}), or
  1232   singleton list containing an atom (case @{text PVar} in \eqref{letpat}), or
  1279   But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1280   But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate 
  1280   that a notion is given for alpha-equivalence classes and leave it out 
  1281   that a notion is given for alpha-equivalence classes and leave it out 
  1281   for the corresponding notion given on the ``raw'' level. So for example 
  1282   for the corresponding notion given on the ``raw'' level. So for example 
  1282   we have @{text "ty\<^sup>\<alpha> \<mapsto> ty"} and @{text "C\<^sup>\<alpha> \<mapsto> C"}
  1283   we have @{text "ty\<^sup>\<alpha> \<mapsto> ty"} and @{text "C\<^sup>\<alpha> \<mapsto> C"}
  1283   where @{term ty} is the type used in the quotient construction for 
  1284   where @{term ty} is the type used in the quotient construction for 
  1284   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. 
  1285   @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor in the ``raw'' type @{text "ty"},
       
  1286   respectively @{text "C\<^sup>\<alpha>"} is the corresponding term-constructor in @{text "ty\<^sup>\<alpha>"}. 
  1285 
  1287 
  1286   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1288   The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are 
  1287   non-empty and the types in the constructors only occur in positive 
  1289   non-empty and the types in the constructors only occur in positive 
  1288   position (see \cite{Berghofer99} for an in-depth description of the datatype package
  1290   position (see \cite{Berghofer99} for an in-depth description of the datatype package
  1289   in Isabelle/HOL). 
  1291   in Isabelle/HOL). 
  1321   @{text "fa_bn"}\mbox{$_{1..m}$}.
  1323   @{text "fa_bn"}\mbox{$_{1..m}$}.
  1322   \]\smallskip
  1324   \]\smallskip
  1323   
  1325   
  1324   \noindent
  1326   \noindent
  1325   The reason for this setup is that in a deep binder not all atoms have to be
  1327   The reason for this setup is that in a deep binder not all atoms have to be
  1326   bound, as we saw in the example with ``plain'' @{text Let}s. We need
  1328   bound, as we saw in \eqref{letrecs} with the example of ``plain'' @{text Let}s. We need
  1327   therefore functions that calculate those free atoms in deep binders.
  1329   therefore functions that calculate those free atoms in deep binders.
  1328 
  1330 
  1329   While the idea behind these free-atom functions is simple (they just
  1331   While the idea behind these free-atom functions is simple (they just
  1330   collect all atoms that are not bound), because of our rather complicated
  1332   collect all atoms that are not bound), because of our rather complicated
  1331   binding mechanisms their definitions are somewhat involved.  Given
  1333   binding mechanisms their definitions are somewhat involved.  Given
  1685   for the existentially quantified permutation).
  1687   for the existentially quantified permutation).
  1686 
  1688 
  1687   Again let us take a look at a concrete example for these definitions. For 
  1689   Again let us take a look at a concrete example for these definitions. For 
  1688   the specification given in \eqref{letrecs}
  1690   the specification given in \eqref{letrecs}
  1689   we have three relations $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and
  1691   we have three relations $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and
  1690   $\approx_{\textit{bn}}$ with the following clauses:
  1692   $\approx_{\textit{bn}}$ with the following rules:
  1691 
  1693 
  1692   \begin{equation}\label{rawalpha}\mbox{
  1694   \begin{equation}\label{rawalpha}\mbox{
  1693   \begin{tabular}{@ {}c @ {}}
  1695   \begin{tabular}{@ {}c @ {}}
  1694   \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}}
  1696   \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}}
  1695   {@{term "alpha_lst_ex (bn as, t) alpha_trm fa_trm (bn as', t')"} & 
  1697   {@{term "alpha_lst_ex (bn as, t) alpha_trm fa_trm (bn as', t')"} & 
  1721   clause for @{text "Let"} (which has
  1723   clause for @{text "Let"} (which has
  1722   a non-recursive binder). 
  1724   a non-recursive binder). 
  1723   The underlying reason is that the terms inside an assignment are not meant 
  1725   The underlying reason is that the terms inside an assignment are not meant 
  1724   to be ``under'' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"}, 
  1726   to be ``under'' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"}, 
  1725   because there all components of an assignment are ``under'' the binder. 
  1727   because there all components of an assignment are ``under'' the binder. 
  1726   Note also that in case of more than one body (e.g.~in the @{text "Let_rec"}-case)
  1728   Note also that in case of more than one body (that is in the @{text "Let_rec"}-case)
  1727   we need to parametrise the relation $\approx_{\textit{list}}$ with a compound
  1729   we need to parametrise the relation $\approx_{\textit{list}}$ with a compound
  1728   equivalence relation and a compound free-atom function. This is because the
  1730   equivalence relation and a compound free-atom function. This is because the
  1729   corresponding binding clause specifies a binder with two bodies.
  1731   corresponding binding clause specifies a binder with two bodies, namely
       
  1732   @{text "as"} and @{text "t"}.
  1730 *}
  1733 *}
  1731 
  1734 
  1732 section {* Establishing the Reasoning Infrastructure *}
  1735 section {* Establishing the Reasoning Infrastructure *}
  1733 
  1736 
  1734 text {*
  1737 text {*
  1766   The relations @{text "\<approx>ty"}$_{1..n}$ and @{text "\<approx>bn"}$_{1..m}$ are
  1769   The relations @{text "\<approx>ty"}$_{1..n}$ and @{text "\<approx>bn"}$_{1..m}$ are
  1767   equivalence relations.
  1770   equivalence relations.
  1768   \end{lem}
  1771   \end{lem}
  1769 
  1772 
  1770   \begin{proof} 
  1773   \begin{proof} 
  1771   The proof is by induction over the definitions. The non-trivial
  1774   The proofs are by induction. The non-trivial
  1772   cases involve premises built up by $\approx_{\textit{set}}$, 
  1775   cases involve premises built up by $\approx_{\textit{set}}$, 
  1773   $\approx_{\textit{set+}}$ and $\approx_{\textit{list}}$. They 
  1776   $\approx_{\textit{set+}}$ and $\approx_{\textit{list}}$. They 
  1774   can be dealt with as in Lemma~\ref{alphaeq}. However, the transitivity
  1777   can be dealt with as in Lemma~\ref{alphaeq}. However, the transitivity
  1775   case needs in addition the fact that the relations are equivariant. 
  1778   case needs in addition the fact that the relations are equivariant. 
  1776   \end{proof}
  1779   \end{proof}
  1841   restriction imposed on the form of the binding functions---namely \emph{not}
  1844   restriction imposed on the form of the binding functions---namely \emph{not}
  1842   to return any bound atoms. In Ott, in contrast, the user may define @{text
  1845   to return any bound atoms. In Ott, in contrast, the user may define @{text
  1843   "bn"}$_{1..m}$ so that they return bound atoms and in this case the third
  1846   "bn"}$_{1..m}$ so that they return bound atoms and in this case the third
  1844   implication is \emph{not} true. A result is that in general the lifting of the
  1847   implication is \emph{not} true. A result is that in general the lifting of the
  1845   corresponding binding functions in Ott to alpha-equated terms is impossible.
  1848   corresponding binding functions in Ott to alpha-equated terms is impossible.
  1846 
       
  1847   Having established respectfulness for the ``raw'' term-constructors, the 
  1849   Having established respectfulness for the ``raw'' term-constructors, the 
  1848   quotient package is able to automatically deduce \eqref{distinctalpha} from 
  1850   quotient package is able to automatically deduce \eqref{distinctalpha} from 
  1849   \eqref{distinctraw}. Having the facts \eqref{fnresp} at our disposal, we can 
  1851   \eqref{distinctraw}.
  1850   also lift properties that characterise when two ``raw'' terms of the form
  1852 
       
  1853   Next we can lift the permutation operations defined in \eqref{ceqvt}. In
       
  1854   order to make this lifting to go through, we have to show that the
       
  1855   permutation operations are respectful. This amounts to showing that the
       
  1856   alpha-equivalence relations are equivariant, which
       
  1857   we already established in Lemma~\ref{equiv}. As a result we can add the
       
  1858   equations
       
  1859   
       
  1860   \begin{equation}\label{calphaeqvt}
       
  1861   @{text "\<pi> \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r) = C\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) \<dots> (\<pi> \<bullet> x\<^isub>r)"}
       
  1862   \end{equation}\smallskip
       
  1863 
       
  1864   \noindent
       
  1865   to our infrastructure. In a similar fashion we can lift the defining equations
       
  1866   of the free-atom functions @{text "fa_ty\<AL>"}$_{1..n}$ and
       
  1867   @{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text
       
  1868   "bn\<AL>"}$_{1..m}$ and size functions @{text "size_ty\<AL>"}$_{1..n}$.
       
  1869   The latter are defined automatically for the ``raw'' types @{text "ty"}$_{1..n}$
       
  1870   by the datatype package of Isabelle/HOL.
       
  1871 
       
  1872   We also need to lift the properties that characterise when two ``raw'' terms of the form
  1851   
  1873   
  1852   \[
  1874   \[
  1853   \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r \<approx>ty C x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}}
  1875   \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r \<approx>ty C x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}}
  1854   \]\smallskip
  1876   \]\smallskip
  1855 
  1877 
  1860   \[
  1882   \[
  1861   @{text "C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r = C\<^sup>\<alpha> x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}.
  1883   @{text "C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r = C\<^sup>\<alpha> x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}.
  1862   \]\smallskip
  1884   \]\smallskip
  1863   
  1885   
  1864   \noindent
  1886   \noindent
  1865   We call these conditions as \emph{quasi-injectivity}. They correspond to
  1887   We call these conditions as \emph{quasi-injectivity}. They correspond to the
  1866   the premises in our alpha-equiva\-lence relations, with the exception that 
  1888   premises in our alpha-equiva\-lence relations, with the exception that the
  1867   in case of binders the relations @{text "\<approx>ty"}$_{1..n}$ are all replaced
  1889   relations @{text "\<approx>ty"}$_{1..n}$ are all replaced by equality (and similarly
  1868   by equality. Recall the alpha-equivalence rules for @{text "Let"} and @{text "Let_rec"} 
  1890   the free-atom and binding functions are replaced by their lifted
  1869   shown in \eqref{rawalpha}. For @{text "Let\<^sup>\<alpha>"} and @{text "Let_rec\<^sup>\<alpha>"} we have
  1891   counterparts). Recall the alpha-equivalence rules for @{text "Let"} and
       
  1892   @{text "Let_rec"} shown in \eqref{rawalpha}. For @{text "Let\<^sup>\<alpha>"} and
       
  1893   @{text "Let_rec\<^sup>\<alpha>"} we have
  1870 
  1894 
  1871   \begin{equation}\label{alphalift}\mbox{
  1895   \begin{equation}\label{alphalift}\mbox{
  1872   \begin{tabular}{@ {}c @ {}}
  1896   \begin{tabular}{@ {}c @ {}}
  1873   \infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
  1897   \infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
  1874   {@{term "alpha_lst_ex (bn_al as, t) equal fa_trm_al (bn as', t')"} & 
  1898   {@{term "alpha_lst_ex (bn_al as, t) equal fa_trm_al (bn as', t')"} & 
  1877   \makebox[0mm]{\infer{@{text "Let_rec\<^sup>\<alpha> as t = Let_rec\<^sup>\<alpha> as' t'"}}
  1901   \makebox[0mm]{\infer{@{text "Let_rec\<^sup>\<alpha> as t = Let_rec\<^sup>\<alpha> as' t'"}}
  1878   {@{term "alpha_lst_ex (bn_al as, ast) equ2 fa_trm2_al (bn_al as', ast')"}}}\\
  1902   {@{term "alpha_lst_ex (bn_al as, ast) equ2 fa_trm2_al (bn_al as', ast')"}}}\\
  1879   \end{tabular}}
  1903   \end{tabular}}
  1880   \end{equation}\smallskip
  1904   \end{equation}\smallskip
  1881 
  1905 
  1882   \noindent
  1906   We can also add to our infrastructure cases lemmas and a (mutual)
  1883   where @{text "\<approx>\<^bsub>trm\<^esub>"} and @{text "\<approx>\<^bsub>assn\<^esub>"} are replaced by @{text "="} (and similarly 
       
  1884   the free-atom and binding functions are replaced by their lifted counterparts). 
       
  1885 
       
  1886   Next we can lift the permutation operations defined in \eqref{ceqvt}. In
       
  1887   order to make this lifting to go through, we have to show that the
       
  1888   permutation operations are respectful. This amounts to showing that the
       
  1889   alpha-equivalence relations are equivariant, which
       
  1890   we already established in Lemma~\ref{equiv}. As a result we can add the
       
  1891   equations
       
  1892   
       
  1893   \begin{equation}\label{calphaeqvt}
       
  1894   @{text "\<pi> \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r) = C\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) \<dots> (\<pi> \<bullet> x\<^isub>r)"}
       
  1895   \end{equation}\smallskip
       
  1896 
       
  1897   \noindent
       
  1898   to our infrastructure. In a similar fashion we can lift the defining equations
       
  1899   of the free-atom functions @{text "fn_ty\<AL>"}$_{1..n}$ and
       
  1900   @{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text
       
  1901   "bn\<AL>"}$_{1..m}$ and size functions @{text "size_ty\<AL>"}$_{1..n}$.
       
  1902   The latter are defined automatically for the ``raw'' types @{text "ty"}$_{1..n}$
       
  1903   by the datatype package of Isabelle/HOL.
       
  1904 
       
  1905   Finally we can add to our infrastructure cases lemmas and a (mutual)
       
  1906   induction principle for the types @{text "ty\<AL>"}$_{1..n}$. The cases
  1907   induction principle for the types @{text "ty\<AL>"}$_{1..n}$. The cases
  1907   lemmas allow the user to deduce a property @{text "P"} by exhaustively
  1908   lemmas allow the user to deduce a property @{text "P"} by exhaustively
  1908   analysing how an element in a type, say @{text "ty\<AL>"}$_i$, can be
  1909   analysing how an element in a type, say @{text "ty\<AL>"}$_i$, can be
  1909   constructed (that means one case for each of the term-constructors in @{text
  1910   constructed (that means one case for each of the term-constructors in @{text
  1910   "ty\<AL>"}$_i\,$). The lifted cases lemma for the type @{text
  1911   "ty\<AL>"}$_i\,$). The lifted cases lemma for the type @{text
  1936 
  1937 
  1937   \noindent
  1938   \noindent
  1938   whereby the @{text P}$_{1..n}$ are the properties established by the induction
  1939   whereby the @{text P}$_{1..n}$ are the properties established by the induction
  1939   and the @{text y}$_{1..n}$ are of type @{text "ty\<AL>"}$_{1..n}$. Note that 
  1940   and the @{text y}$_{1..n}$ are of type @{text "ty\<AL>"}$_{1..n}$. Note that 
  1940   the induction principle has for the term constructors @{text "C"}$^\alpha_1$ a
  1941   the induction principle has for the term constructors @{text "C"}$^\alpha_1$ a
  1941   premise of the form
  1942   hypothesis of the form
  1942 
  1943 
  1943   \[
  1944   \[
  1944   \mbox{@{text "\<forall>x\<^isub>1\<dots>x\<^isub>k. P\<^isub>i x\<^isub>i \<and> \<dots> \<and> P\<^isub>j x\<^isub>j \<Rightarrow> P (C\<AL>\<^sub>1 x\<^isub>1 \<dots> x\<^isub>k)"}} 
  1945   \mbox{@{text "\<forall>x\<^isub>1\<dots>x\<^isub>k. P\<^isub>i x\<^isub>i \<and> \<dots> \<and> P\<^isub>j x\<^isub>j \<Rightarrow> P (C\<AL>\<^sub>1 x\<^isub>1 \<dots> x\<^isub>k)"}} 
  1945   \]\smallskip
  1946   \]\smallskip
  1946 
  1947 
  1954   \eqref{cases} and \eqref{induct} boil down to the following three inference
  1955   \eqref{cases} and \eqref{induct} boil down to the following three inference
  1955   rules (the cases lemmas are on the left-hand side; the induction principle
  1956   rules (the cases lemmas are on the left-hand side; the induction principle
  1956   on the right):
  1957   on the right):
  1957 
  1958 
  1958   \begin{equation}\label{inductex}\mbox{
  1959   \begin{equation}\label{inductex}\mbox{
  1959   \begin{tabular}{c@ {\hspace{10mm}}c}
  1960   \begin{tabular}{@ {}c@ {\hspace{3mm}}c@ {}}
  1960   \begin{tabular}{@ {}c@ {}}
  1961   \begin{tabular}{@ {}c@ {}}
  1961   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  1962   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  1962   {\begin{array}{l}
  1963   {\begin{array}{@ {}l@ {}}
  1963    @{text "\<forall>x. y = Var\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1964    @{text "\<forall>x. y = Var\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1964    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1965    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1965    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1966    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1966    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  1967    @{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. y = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  1967    \end{array}}\medskip\\
  1968    \end{array}}\medskip\\
  1968 
  1969 
  1969   \infer{@{text "P\<^bsub>pat\<^esub>"}}
  1970   \infer{@{text "P\<^bsub>pat\<^esub>"}}
  1970   {\begin{array}{l}
  1971   {\begin{array}{@ {}l@ {}}
  1971    @{text "y = PNil\<^sup>\<alpha>  \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
  1972    @{text "y = PNil\<^sup>\<alpha>  \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
  1972    @{text "\<forall>x. y = PVar\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
  1973    @{text "\<forall>x. y = PVar\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
  1973    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub>"}
  1974    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub>"}
  1974   \end{array}}
  1975   \end{array}}
  1975   \end{tabular} 
  1976   \end{tabular} 
  1976   &
  1977   &
  1977   
  1978   
  1978   \begin{tabular}{@ {}c@ {}}
  1979   \begin{tabular}{@ {}c@ {}}
  1979   \infer{@{text "P\<^bsub>trm\<^esub> y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}}
  1980   \infer{@{text "P\<^bsub>trm\<^esub> y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}}
  1980   {\begin{array}{l}
  1981   {\begin{array}{@ {}l@ {}}
  1981    @{text "\<forall>x. P\<^bsub>trm\<^esub> (Var\<^sup>\<alpha> x)"}\\
  1982    @{text "\<forall>x. P\<^bsub>trm\<^esub> (Var\<^sup>\<alpha> x)"}\\
  1982    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>trm\<^esub> x\<^isub>1 \<and> P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  1983    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>trm\<^esub> x\<^isub>1 \<and> P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  1983    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  1984    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  1984    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>pat\<^esub> x\<^isub>1 \<and> P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  1985    @{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. P\<^bsub>pat\<^esub> x\<^isub>1 \<and> P\<^bsub>trm\<^esub> x\<^isub>2 \<and> P\<^bsub>trm\<^esub> x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub> (Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3)"}\\
  1985    @{text "P\<^bsub>pat\<^esub> (PNil\<^sup>\<alpha>)"}\\
  1986    @{text "P\<^bsub>pat\<^esub> (PNil\<^sup>\<alpha>)"}\\
  1986    @{text "\<forall>x. P\<^bsub>pat\<^esub> (PVar\<^sup>\<alpha> x)"}\\
  1987    @{text "\<forall>x. P\<^bsub>pat\<^esub> (PVar\<^sup>\<alpha> x)"}\\
  1987    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>pat\<^esub> x\<^isub>1 \<and> P\<^bsub>pat\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub> (PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}
  1988    @{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>pat\<^esub> x\<^isub>1 \<and> P\<^bsub>pat\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub> (PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}
  1988   \end{array}}
  1989   \end{array}}
  1989   \end{tabular}
  1990   \end{tabular}
  2020   "ty\<AL>"}$_{1..n}$ is the same as @{text "fa_ty\<AL>"}$_{1..n}$.  This fact
  2021   "ty\<AL>"}$_{1..n}$ is the same as @{text "fa_ty\<AL>"}$_{1..n}$.  This fact
  2021   is important in the nominal setting where the general theory is formulated
  2022   is important in the nominal setting where the general theory is formulated
  2022   in terms of support and freshness, but also provides evidence that our
  2023   in terms of support and freshness, but also provides evidence that our
  2023   notions of free-atoms and alpha-equivalence ``match up''.
  2024   notions of free-atoms and alpha-equivalence ``match up''.
  2024 
  2025 
  2025   \begin{thm} 
  2026   \begin{thm}\label{suppfa} 
  2026   For @{text "x"}$_{1..n}$ with type @{text "ty\<AL>"}$_{1..n}$, we have
  2027   For @{text "x"}$_{1..n}$ with type @{text "ty\<AL>"}$_{1..n}$, we have
  2027   @{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"}.
  2028   @{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"}.
  2028   \end{thm}
  2029   \end{thm}
  2029 
  2030 
  2030   \begin{proof}
  2031   \begin{proof}
  2031   The proof is by induction. In each case
  2032   The proof is by induction on @{text "x"}$_{1..n}$. In each case
  2032   we unfold the definition of @{text "supp"}, move the swapping inside the 
  2033   we unfold the definition of @{text "supp"}, move the swapping inside the 
  2033   term-constructors and then use the quasi-injectivity lemmas in order to complete the
  2034   term-constructors and then use the quasi-injectivity lemmas in order to complete the
  2034   proof. For the abstraction cases we use then the facts derived in Theorem~\ref{suppabs},
  2035   proof. For the abstraction cases we use then the facts derived in Theorem~\ref{suppabs},
  2035   for which we have to know that every body of an abstraction is finitely supported.
  2036   for which we have to know that every body of an abstraction is finitely supported.
  2036   This, we have proved earlier.
  2037   This, we have proved earlier.
  2050   {@{term "alpha_lst_ex (bn_al as, ast) equ2 supp2 (bn_al as', ast')"}}}\\
  2051   {@{term "alpha_lst_ex (bn_al as, ast) equ2 supp2 (bn_al as', ast')"}}}\\
  2051   \end{tabular}}
  2052   \end{tabular}}
  2052   \]\smallskip
  2053   \]\smallskip
  2053 
  2054 
  2054   \noindent
  2055   \noindent
  2055   Taking the fact into account that @{term "equ2"} and @{term "supp2"} are
  2056   Taking the fact into account that the compound equivalence relation @{term
  2056   by definition equal to @{term "equal"} and @{term "supp"}, respectively, 
  2057   "equ2"} and the compound free-atom function @{term "supp2"} are by
  2057   the above rules simplify even further to
  2058   definition equal to @{term "equal"} and @{term "supp"}, respectively, the
       
  2059   above rules simplify even further to
       
  2060 
  2058 
  2061 
  2059   \[\mbox{
  2062   \[\mbox{
  2060   \begin{tabular}{@ {}c @ {}}
  2063   \begin{tabular}{@ {}c @ {}}
  2061   \infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
  2064   \infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
  2062   {@{term "Abs_lst (bn_al as) t = Abs_lst (bn_al as') t'"} & 
  2065   {@{term "Abs_lst (bn_al as) t = Abs_lst (bn_al as') t'"} & 
  2066   {@{term "Abs_lst (bn_al as) ast = Abs_lst (bn_al as') ast'"}}}\\
  2069   {@{term "Abs_lst (bn_al as) ast = Abs_lst (bn_al as') ast'"}}}\\
  2067   \end{tabular}}
  2070   \end{tabular}}
  2068   \]\smallskip
  2071   \]\smallskip
  2069 
  2072 
  2070   \noindent
  2073   \noindent
  2071   which means we can characterise equality between term-constructors in terms
  2074   which means we can characterise equality between term-constructors (on the
  2072   of equality between the abstractions defined in Section~\ref{sec:binders}. From this
  2075   alpha-equated level) in terms of equality between the abstractions defined
  2073   we can derive the support for @{text "Let\<^sup>\<alpha>"} and 
  2076   in Section~\ref{sec:binders}. From this we can deduce the support for @{text
  2074   @{text "Let_rec\<^sup>\<alpha>"}, namely
  2077   "Let\<^sup>\<alpha>"} and @{text "Let_rec\<^sup>\<alpha>"}, namely
       
  2078 
  2075 
  2079 
  2076   \[\mbox{
  2080   \[\mbox{
  2077   \begin{tabular}{l@ {\hspace{2mm}}l@ {\hspace{2mm}}l}
  2081   \begin{tabular}{l@ {\hspace{2mm}}l@ {\hspace{2mm}}l}
  2078   @{text "supp (Let\<^sup>\<alpha> as t)"} & @{text "="} & @{text "(supp t - set (bn\<^sup>\<alpha> as)) \<union> fa\<AL>\<^bsub>bn\<^esub> as"}\\
  2082   @{text "supp (Let\<^sup>\<alpha> as t)"} & @{text "="} & @{text "(supp t - set (bn\<^sup>\<alpha> as)) \<union> fa\<AL>\<^bsub>bn\<^esub> as"}\\
  2079   @{text "supp (Let_rec\<^sup>\<alpha> as t)"} & @{text "="} & @{text "(supp t \<union> supp as) - set (bn\<^sup>\<alpha> as)"}\\
  2083   @{text "supp (Let_rec\<^sup>\<alpha> as t)"} & @{text "="} & @{text "(supp t \<union> supp as) - set (bn\<^sup>\<alpha> as)"}\\
  2094 
  2098 
  2095 section {* Strong Induction Principles *}
  2099 section {* Strong Induction Principles *}
  2096 
  2100 
  2097 text {*
  2101 text {*
  2098   In the previous section we derived induction principles for alpha-equated
  2102   In the previous section we derived induction principles for alpha-equated
  2099   terms (see \eqref{induct} and \eqref{inductex}). This was done by lifting
  2103   terms (see \eqref{induct} for the general form and \eqref{inductex} for an
  2100   the corresponding inductions principles for ``raw'' terms.  We already
  2104   instance). This was done by lifting the corresponding inductions principles
  2101   employed these induction principles in order to derive several facts for
  2105   for ``raw'' terms.  We already employed these induction principles for
  2102   alpha-equated terms, including the property that the free-variable functions
  2106   deriving several facts for alpha-equated terms, including the property that
  2103   and the notion of support coincide. Still, we call these induction
  2107   the free-variable functions and the notion of support coincide. Still, we
  2104   principles \emph{weak}, because for a term-constructor, say \mbox{@{text
  2108   call these induction principles \emph{weak}, because for a term-constructor,
  2105   "C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r"}}, the induction hypothesis requires us to
  2109   say \mbox{@{text "C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r"}}, the induction
  2106   establish (under some assumptions) a property @{text "P (C\<^sup>\<alpha>
  2110   hypothesis requires us to establish (under some assumptions) a property
  2107   x\<^isub>1\<dots>x\<^isub>r)"} for \emph{all} @{text "x"}$_{1..r}$. The problem is that in the
  2111   @{text "P (C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r)"} for \emph{all} @{text
  2108   presence of binders we cannot make any assumptions about the atoms that are
  2112   "x"}$_{1..r}$. The problem is that in the presence of binders we cannot make
  2109   bound, and we have to potentially rename them. This renaming has to be
  2113   any assumptions about the atoms that are bound. One obvious way around this
  2110   done manually and is often very cumbersome (especially in the case for 
  2114   problem is to rename them. Unfortunately, this leads to very clunky proofs
       
  2115   and makes formalisations grievous experiences (especially in the case for
  2111   multiple bound atoms).
  2116   multiple bound atoms).
       
  2117 
  2112 
  2118 
  2113   For the older versions of Nominal Isabelle we introduced in
  2119   For the older versions of Nominal Isabelle we introduced in
  2114   \cite{UrbanTasson05} a method for automatically strengthening weak induction
  2120   \cite{UrbanTasson05} a method for automatically strengthening weak induction
  2115   principles in case of single binders. These stronger induction principles
  2121   principles. These stronger induction principles allow the user to make
  2116   allow the user to make additional assumptions about bound atoms. The main
  2122   additional assumptions about bound atoms. The advantage of these assumptions
  2117   point is that these additional assumptions amount to a formal version of the
  2123   is that they make in most cases any renaming of bound atoms unnecessary.  To
  2118   informal variable convention for binders and nearly always make manual
  2124   explain how the strengthening works in the presence of multiple binders, we
  2119   renaming of binders unnecessary.
  2125   use as running example the lambda-calculus with @{text "Let"}-patterns shown
  2120 
  2126   in \eqref{letpat}. Its weak induction principle is given in
  2121   To explain how the strengthening works in the presence of multiple binders,
  2127   \eqref{inductex}.  The stronger induction principle is as follows:
  2122   we use as running example the lambda-calculus with @{text "Let"}-patterns
       
  2123   shown in \eqref{letpat}. Its weak induction principle is given in \eqref{inductex}.
       
  2124   The stronger induction principle is as follows
       
  2125 
  2128 
  2126   \begin{equation}\label{stronginduct}
  2129   \begin{equation}\label{stronginduct}
  2127   \mbox{
  2130   \mbox{
  2128   \begin{tabular}{@ {}c@ {}}
  2131   \begin{tabular}{@ {}c@ {}}
  2129   \infer{@{text "P\<^bsub>trm\<^esub> c y\<^isub>1 \<and> P\<^bsub>pat\<^esub> c y\<^isub>2"}}
  2132   \infer{@{text "P\<^bsub>trm\<^esub> c y\<^isub>1 \<and> P\<^bsub>pat\<^esub> c y\<^isub>2"}}
  2130   {\begin{array}{l}
  2133   {\begin{array}{l}
  2131    @{text "\<forall>x c. P\<^bsub>trm\<^esub> c (Var\<^sup>\<alpha> x)"}\\
  2134    @{text "\<forall>x c. P\<^bsub>trm\<^esub> c (Var\<^sup>\<alpha> x)"}\\
  2132    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  2135    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  2133    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. {atom x\<^isub>1} #\<^sup>* c \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  2136    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. atom x\<^isub>1 # c \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  2134    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. (set (bn\<^sup>\<alpha> x\<^isub>1)) #\<^sup>* c \<and> (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
  2137    @{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3 c. (set (bn\<^sup>\<alpha> x\<^isub>1)) #\<^sup>* c \<and>"}\\ 
       
  2138    \hspace{10mm}@{text "(\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>3) \<Rightarrow> P\<^bsub>trm\<^esub> c (Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3)"}\\
  2135    @{text "\<forall>c. P\<^bsub>pat\<^esub> c (PNil\<^sup>\<alpha>)"}\\
  2139    @{text "\<forall>c. P\<^bsub>pat\<^esub> c (PNil\<^sup>\<alpha>)"}\\
  2136    @{text "\<forall>x c. P\<^bsub>pat\<^esub> c (PVar\<^sup>\<alpha> x)"}\\
  2140    @{text "\<forall>x c. P\<^bsub>pat\<^esub> c (PVar\<^sup>\<alpha> x)"}\\
  2137    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>pat\<^esub> c (PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}
  2141    @{text "\<forall>x\<^isub>1 x\<^isub>2 c. (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>pat\<^esub> c (PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}
  2138   \end{array}}
  2142   \end{array}}
  2139   \end{tabular}}
  2143   \end{tabular}}
  2140   \end{equation}\smallskip
  2144   \end{equation}\smallskip
  2141 
  2145 
  2142 
  2146 
  2143   \noindent
  2147   \noindent
  2144   Instead of establishing the two properties @{text " P\<^bsub>trm\<^esub> y\<^isub>1 \<and>
  2148   Instead of establishing the two properties @{text " P\<^bsub>trm\<^esub>
  2145   P\<^bsub>pat\<^esub> y\<^isub>2"}, as the weak one does, the stronger
  2149   y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}, as the weak one does, the
  2146   induction principle establishes the properties @{text " P\<^bsub>trm\<^esub> c
  2150   stronger induction principle establishes the properties @{text "
  2147   y\<^isub>1 \<and> P\<^bsub>pat\<^esub> c y\<^isub>2"} in which the additional
  2151   P\<^bsub>trm\<^esub> c y\<^isub>1 \<and> P\<^bsub>pat\<^esub> c y\<^isub>2"} in
  2148   parameter @{text c} is assumed to be of finite support. The purpose of
  2152   which the additional parameter @{text c} is assumed to be of finite
  2149   @{text "c"} is to ``control'' which freshness assumptions the binders should
  2153   support. The purpose of @{text "c"} is to ``control'' which freshness
  2150   satisfy in the @{text "Lam\<^sup>\<alpha>"} and @{text "Let\<^sup>\<alpha>"} cases (these are the cases 
  2154   assumptions the binders should satisfy in the @{text "Lam\<^sup>\<alpha>"} and
  2151   where the user specified some binding clauses).
  2155   @{text "Let\<^sup>\<alpha>"} cases: for @{text "Lam\<^sup>\<alpha>"} we can assume the
       
  2156   bound atom @{text "x\<^isub>1"} is fresh for @{text "c"}; for @{text
       
  2157   "Let\<^sup>\<alpha>"} we can assume all bound atoms from an assignment are fresh
       
  2158   for @{text "c"}. If @{text "c"} is instantiated appropriately, the user can
       
  2159   mimic the ``pencil-and-paper'' reasoning employing the usual variable
       
  2160   convention.
  2152 
  2161 
  2153   In what follows we will show that the induction principle in
  2162   In what follows we will show that the induction principle in
  2154   \eqref{inductex} implies \eqref{stronginduct}. This fact was established in
  2163   \eqref{inductex} implies \eqref{stronginduct}. This fact was established for
  2155   \cite{UrbanTasson05} by some quite involved, nevertheless automated,
  2164   single binders in \cite{UrbanTasson05} by some quite involved, nevertheless
  2156   induction proof. In this paper we simplify the proof by leveraging the
  2165   automated, induction proof. In this paper we simplify the proof by
  2157   automated proof methods from the function package of Isabelle/HOL
  2166   leveraging the automated proof methods from the function package of
  2158   \cite{Krauss09}. The reasoning principle behind these methods is
  2167   Isabelle/HOL \cite{Krauss09}. The reasoning principle behind these methods
  2159   well-founded induction. To use them in our setting, we have to discharge two
  2168   is well-founded induction. To use them in our setting, we have to discharge
  2160   proof obligations: one is that we have well-founded measures (one for each type
  2169   two proof obligations: one is that we have well-founded measures (one for
  2161   @{text "ty"}$^\alpha_{1..n}$) that decrease in every induction step and the
  2170   each type @{text "ty"}$^\alpha_{1..n}$) that decrease in every induction
  2162   other is that we have covered all cases. 
  2171   step and the other is that we have covered all cases. Once these two
       
  2172   proof obligations are discharged, the reasoning infrastructure in 
       
  2173   the function package will automatically derive the stronger induction
       
  2174   principle. This considerably simplifies the work we have to do.
  2163 
  2175 
  2164   As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
  2176   As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
  2165   which we lifted in the previous section and which are all well-founded. It
  2177   which we lifted in the previous section and which are all well-founded. It
  2166   is straightforward to establish that these measures decrease in every
  2178   is straightforward to establish that the sizes decrease in every
  2167   induction step. What is left to show is that we covered all cases. 
  2179   induction step. What is left to show is that we covered all cases. 
  2168   To do so, we use a \emph{cases lemma} derived for each type. For the terms in \eqref{letpat} 
  2180   To do so, we have to derive stronger cases lemmas, which look in our
  2169   this lemma is of the form
  2181   running example as follows:
  2170   
  2182 
  2171   \begin{equation}\label{weakcases}
  2183   \[\mbox{
       
  2184   \begin{tabular}{@ {}c@ {\hspace{6mm}}c@ {}}
  2172   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  2185   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  2173   {\begin{array}{l@ {\hspace{9mm}}l}
  2186   {\begin{array}{@ {}l@ {}}
  2174   @{text "\<forall>x. t = Var x \<Rightarrow> P\<^bsub>trm\<^esub>"} & @{text "\<forall>a t'. t = Lam a t' \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  2187    @{text "\<forall>x. y = Var\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  2175   @{text "\<forall>t\<^isub>1 t\<^isub>2. t = App t\<^isub>1 t\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"} & @{text "\<forall>p t'. t = Let p t' \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  2188    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  2176   \end{array}}\\[-1mm]
  2189    @{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>"}\\
  2177   \end{equation}
  2190    @{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. set (bn\<^sup>\<alpha> x\<^isub>1) #\<^sup>* c \<and> y = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
  2178   
  2191    \end{array}} &
  2179   where we have a premise for each term-constructor.
  2192 
  2180   The idea behind such cases lemmas is that we can conclude with a property @{text "P\<^bsub>trm\<^esub>"},
  2193   \infer{@{text "P\<^bsub>pat\<^esub>"}}
  2181   provided we can show that this property holds if we substitute for @{text "t"} all 
  2194   {\begin{array}{@ {}l@ {}}
  2182   possible term-constructors. 
  2195    @{text "y = PNil\<^sup>\<alpha>  \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
       
  2196    @{text "\<forall>x. y = PVar\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
       
  2197    @{text "\<forall>x\<^isub>1 x\<^isub>2. y = PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub>"}
       
  2198   \end{array}}
       
  2199   \end{tabular}}
       
  2200   \]\smallskip 
       
  2201 
       
  2202   \noindent
       
  2203   These stronger cases lemmas need to be derived from the `weak' cases lemmas given
       
  2204   in \eqref{inductex}. This is trivial in case of patterns (the one on the right-hand side)
       
  2205   since weak and strong cases lemma coincide (there is no binding in patterns).
       
  2206   Interesting are only the cases for @{text "Lam\<^sup>\<alpha>"} and @{text "Let\<^sup>\<alpha>"}. There the
       
  2207   stronger cases lemma allow us to assume that the bound atoms avoid the context @{text "c"}
       
  2208   (which is assumed to be finitely supported).
       
  2209  
       
  2210   Let us show first establish the simpler case for @{text "Lam\<^sup>\<alpha>"}. By the weak cases lemma 
       
  2211   \eqref{inductex} we can assume that
       
  2212 
       
  2213   \begin{equation}\label{assm}
       
  2214   @{text "y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}
       
  2215   \end{equation}\smallskip
       
  2216 
       
  2217   \noindent
       
  2218   holds and need to establish @{text "P\<^bsub>trm\<^esub>"}. The stronger cases lemma has the implication 
       
  2219 
       
  2220   \begin{equation}\label{imp}
       
  2221   @{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>"}
       
  2222   \end{equation}\smallskip
       
  2223 
       
  2224   \noindent
       
  2225   which we can use to infer @{text "P\<^bsub>trm\<^esub>"}. Clearly, we cannot
       
  2226   use this implication directly, because we have no information whether @{text
       
  2227   "x\<^isub>1"} is fresh for @{text "c"}.  However, we can use Properties
       
  2228   \ref{supppermeq} and \ref{avoiding} to rename @{text "x\<^isub>1"}. We know
       
  2229   by Theorem~\ref{suppfa} that @{text "{atom x\<^isub>1} #\<^sup>* Lam\<^sup>\<alpha>
       
  2230   x\<^isub>1 x\<^isub>2"} (since its support is @{text "supp x\<^isub>2 -
       
  2231   {atom x\<^isub>1}"}). Property \ref{avoiding} provides us therefore with a
       
  2232   permutation @{text "\<pi>"}, such that @{text "{atom (\<pi> \<bullet> x\<^isub>1)} #\<^sup>*
       
  2233   c"} and \mbox{@{text "supp (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2) #\<^sup>* \<pi>"}} hold.
       
  2234   By using Property \ref{supppermeq}, we can infer from the latter that @{text
       
  2235   "Lam\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) (\<pi> \<bullet> x\<^isub>2) = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}. We can use this in the assumption
       
  2236   \eqref{assm} and then use \eqref{imp} to conclude this case.
       
  2237 
       
  2238   The @{text "Let\<^sup>\<alpha>"}-case involving a (non-recursive) deep binder is more complicated.
       
  2239   We have the assumption
       
  2240 
       
  2241   \begin{equation}\label{assm}
       
  2242   @{text "y = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3"}
       
  2243   \end{equation}\smallskip
       
  2244 
       
  2245   \noindent
       
  2246   and as implication
       
  2247 
       
  2248   \[
       
  2249 
       
  2250   \]\smallskip
       
  2251 
       
  2252 
       
  2253   The reason is that the we cannot apply Property \ref{avoiding} to the whole term @{text "Let p t"},
       
  2254   because @{text p} might contain names bound by @{text bn}, but also some that are 
       
  2255   free. To solve this problem we have to introduce a permutation function that only
       
  2256   permutes names bound by @{text bn} and leaves the other names unchanged. We do this again
       
  2257   by lifting. For a
       
  2258   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}, we define 
       
  2259 
       
  2260 
       
  2261   {\bf NOT DONE YET}
       
  2262 
       
  2263   {\it 
  2183   
  2264   
  2184   The only remaining difficulty is that in order to derive the stronger induction
  2265   The only remaining difficulty is that in order to derive the stronger induction
  2185   principles conveniently, the cases lemma in \eqref{weakcases} is too weak. For this note that
  2266   principles conveniently, the cases lemma in \eqref{weakcases} is too weak. For this note that
  2186   in order to apply this lemma, we have to establish @{text "P\<^bsub>trm\<^esub>"} for \emph{all} @{text Lam}- and 
  2267   in order to apply this lemma, we have to establish @{text "P\<^bsub>trm\<^esub>"} for \emph{all} @{text Lam}- and 
  2187   \emph{all} @{text Let}-terms. 
  2268   \emph{all} @{text Let}-terms. 
  2188   What we need instead is a cases lemma where we only have to consider terms that have 
  2269   What we need instead is a cases lemma where we only have to consider terms that have 
  2189   binders that are fresh w.r.t.~a context @{text "c"}. This gives the implications
  2270   binders that are fresh w.r.t.~a context @{text "c"}. This gives the implications
  2190   
  2271 
  2191   \begin{center}
  2272   
  2192   \begin{tabular}{l}
       
  2193   @{text "\<forall>a t'. t = Lam a t' \<and> {atom a} \<FRESH>\<^sup>* c \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
       
  2194   @{text "\<forall>p t'. t = Let p t' \<and> (set (bn p)) \<FRESH>\<^sup>* c \<Rightarrow> P\<^bsub>trm\<^esub>"}\\[-2mm]
       
  2195   \end{tabular}
       
  2196   \end{center}
       
  2197   
       
  2198   \noindent
       
  2199   which however can be relatively easily be derived from the implications in \eqref{weakcases} 
       
  2200   by a renaming using Properties \ref{supppermeq} and \ref{avoiding}. In the first case we know
       
  2201   that @{text "{atom a} \<FRESH>\<^sup>* Lam a t"}. Property \eqref{avoiding} provides us therefore with 
       
  2202   a permutation @{text q}, such that @{text "{atom (q \<bullet> a)} \<FRESH>\<^sup>* c"} and 
       
  2203   @{text "supp (Lam a t) \<FRESH>\<^sup>* q"} hold.
       
  2204   By using Property \ref{supppermeq}, we can infer from the latter 
       
  2205   that @{text "Lam (q \<bullet> a) (q \<bullet> t) = Lam a t"}
       
  2206   and we are done with this case.
       
  2207 
       
  2208   The @{text Let}-case involving a (non-recursive) deep binder is a bit more complicated.
       
  2209   The reason is that the we cannot apply Property \ref{avoiding} to the whole term @{text "Let p t"},
       
  2210   because @{text p} might contain names bound by @{text bn}, but also some that are 
       
  2211   free. To solve this problem we have to introduce a permutation function that only
       
  2212   permutes names bound by @{text bn} and leaves the other names unchanged. We do this again
       
  2213   by lifting. For a
       
  2214   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}, we define 
       
  2215   
  2273   
  2216   \begin{center}
  2274   \begin{center}
  2217   @{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"}  with
  2275   @{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"}  with
  2218   $\begin{cases}
  2276   $\begin{cases}
  2219   \text{@{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}}\\
  2277   \text{@{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}}\\
  2239   is equal to @{text "[p]\<^bsub>list\<^esub>. t"}. We can also show that @{text "(q \<bullet>\<^bsub>bn\<^esub> p) \<approx>\<^bsub>bn\<^esub> p"}. 
  2297   is equal to @{text "[p]\<^bsub>list\<^esub>. t"}. We can also show that @{text "(q \<bullet>\<^bsub>bn\<^esub> p) \<approx>\<^bsub>bn\<^esub> p"}. 
  2240   These facts establish that @{text "Let (q \<bullet>\<^bsub>bn\<^esub> p) (p \<bullet> t) = Let p t"}, as we need. This
  2298   These facts establish that @{text "Let (q \<bullet>\<^bsub>bn\<^esub> p) (p \<bullet> t) = Let p t"}, as we need. This
  2241   completes the non-trivial cases in \eqref{letpat} for strengthening the corresponding induction
  2299   completes the non-trivial cases in \eqref{letpat} for strengthening the corresponding induction
  2242   principle.
  2300   principle.
  2243   
  2301   
  2244 
       
  2245 
       
  2246   A natural question is
       
  2247   whether we can also strengthen the weak induction principles involving
       
  2248   the general binders presented here. We will indeed be able to so, but for this we need an 
       
  2249   additional notion for permuting deep binders. 
       
  2250 
  2302 
  2251   Given a binding function @{text "bn"} we define an auxiliary permutation 
  2303   Given a binding function @{text "bn"} we define an auxiliary permutation 
  2252   operation @{text "_ \<bullet>\<^bsub>bn\<^esub> _"} which permutes only bound arguments in a deep binder.
  2304   operation @{text "_ \<bullet>\<^bsub>bn\<^esub> _"} which permutes only bound arguments in a deep binder.
  2253   Assuming a clause of @{text bn} is given as 
  2305   Assuming a clause of @{text bn} is given as 
  2254   
  2306   
  2309 
  2361 
  2310   \noindent
  2362   \noindent
  2311   This fact will be crucial when establishing the strong induction principles below.
  2363   This fact will be crucial when establishing the strong induction principles below.
  2312 
  2364 
  2313  
  2365  
  2314   In our running example about @{text "Let"}, the strong induction
  2366 
  2315   principle means that instead 
       
  2316   of establishing the implication 
       
  2317   
       
  2318   \begin{center}
       
  2319   @{text "\<forall>p t\<^isub>1 t\<^isub>2. P\<^bsub>pat\<^esub> p \<and> P\<^bsub>trm\<^esub> t\<^isub>1 \<and> P\<^bsub>trm\<^esub> t\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Let p t\<^isub>1 t\<^isub>2)"}
       
  2320   \end{center}
       
  2321   
       
  2322   \noindent
       
  2323   it is sufficient to establish the following implication
       
  2324   
       
  2325   \begin{equation}\label{strong}
       
  2326   \mbox{\begin{tabular}{l}
       
  2327   @{text "\<forall>p t\<^isub>1 t\<^isub>2 c."}\\
       
  2328   \hspace{5mm}@{text "set (bn p) #\<^sup>* c \<and>"}\\
       
  2329   \hspace{5mm}@{text "(\<forall>d. P\<^bsub>pat\<^esub> d p) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t\<^isub>2)"}\\
       
  2330   \hspace{15mm}@{text "\<Rightarrow> P\<^bsub>trm\<^esub> c (Let p t\<^isub>1 t\<^isub>2)"}
       
  2331   \end{tabular}}
       
  2332   \end{equation}
       
  2333   
       
  2334   \noindent 
       
  2335   While this implication contains an additional argument, namely @{text c}, and 
       
  2336   also additional universal quantifications, it is usually easier to establish.
       
  2337   The reason is that we have the freshness 
       
  2338   assumption @{text "set (bn\<^sup>\<alpha> p) #\<^sup>* c"}, whereby @{text c} can be arbitrarily 
       
  2339   chosen by the user as long as it has finite support.
       
  2340   
       
  2341   Let us now show how we derive the strong induction principles from the
       
  2342   weak ones. In case of the @{text "Let"}-example we derive by the weak 
       
  2343   induction the following two properties
       
  2344   
       
  2345   \begin{equation}\label{hyps}
       
  2346   @{text "\<forall>q c. P\<^bsub>trm\<^esub> c (q \<bullet> t)"} \hspace{4mm} 
       
  2347   @{text "\<forall>q\<^isub>1 q\<^isub>2 c. P\<^bsub>pat\<^esub> (q\<^isub>1 \<bullet>\<AL>\<^bsub>bn\<^esub> (q\<^isub>2 \<bullet> p))"}
       
  2348   \end{equation} 
       
  2349   
       
  2350   \noindent
       
  2351   For the @{text Let} term-constructor  we therefore have to establish @{text "P\<^bsub>trm\<^esub> c (q \<bullet> Let p t\<^isub>1 t\<^isub>2)"} 
       
  2352   assuming \eqref{hyps} as induction hypotheses (the first for @{text t\<^isub>1} and @{text t\<^isub>2}). 
       
  2353   By Property~\ref{avoiding} we
       
  2354   obtain a permutation @{text "r"} such that 
       
  2355   
       
  2356   \begin{equation}\label{rprops}
       
  2357   @{term "(r \<bullet> set (bn (q \<bullet> p))) \<sharp>* c "}\hspace{4mm}
       
  2358   @{term "supp (Abs_lst (bn (q \<bullet> p)) (q \<bullet> t\<^isub>2)) \<sharp>* r"}
       
  2359   \end{equation}
       
  2360   
       
  2361   \noindent
       
  2362   hold. The latter fact and \eqref{renaming} give us
       
  2363   
       
  2364   \begin{center}
       
  2365   \begin{tabular}{l}
       
  2366   @{text "Let (q \<bullet> p) (q \<bullet> t\<^isub>1) (q \<bullet> t\<^isub>2) ="} \\
       
  2367   \hspace{15mm}@{text "Let (r \<bullet>\<AL>\<^bsub>bn\<^esub> (q \<bullet> p)) (q \<bullet> t\<^isub>1) (r \<bullet> (q \<bullet> t\<^isub>2))"}
       
  2368   \end{tabular}
       
  2369   \end{center}
       
  2370   
       
  2371   \noindent
       
  2372   So instead of proving @{text "P\<^bsub>trm\<^esub> c (q \<bullet> Let p t\<^isub>1 t\<^isub>2)"}, we can equally
       
  2373   establish @{text "P\<^bsub>trm\<^esub> c (Let (r \<bullet>\<AL>\<^bsub>bn\<^esub> (q \<bullet> p)) (q \<bullet> t\<^isub>1) (r \<bullet> (q \<bullet> t\<^isub>2)))"}.
       
  2374   To do so, we will use the implication \eqref{strong} of the strong induction
       
  2375   principle, which requires us to discharge
       
  2376   the following four proof obligations:
       
  2377   
       
  2378   \begin{center}
       
  2379   \begin{tabular}{rl}
       
  2380   {\it (i)} &   @{text "set (bn (r \<bullet>\<AL>\<^bsub>bn\<^esub> (q \<bullet> p))) #\<^sup>* c"}\\
       
  2381   {\it (ii)} &  @{text "\<forall>d. P\<^bsub>pat\<^esub> d (r \<bullet>\<AL>\<^bsub>bn\<^esub> (q \<bullet> p))"}\\
       
  2382   {\it (iii)} & @{text "\<forall>d. P\<^bsub>trm\<^esub> d (q \<bullet> t\<^isub>1)"}\\
       
  2383   {\it (iv)} & @{text "\<forall>d. P\<^bsub>trm\<^esub> d (r \<bullet> (q \<bullet> t\<^isub>2))"}\\
       
  2384   \end{tabular}
       
  2385   \end{center}
       
  2386   
       
  2387   \noindent
       
  2388   The first follows from \eqref{rprops} and Lemma~\ref{permutebn}.{\it (i)}; the 
       
  2389   others from the induction hypotheses in \eqref{hyps} (in the fourth case
       
  2390   we have to use the fact that @{term "(r \<bullet> (q \<bullet> t\<^isub>2)) = (r + q) \<bullet> t\<^isub>2"}).
       
  2391   
       
  2392   Taking now the identity permutation @{text 0} for the permutations in \eqref{hyps},
       
  2393   we can establish our original goals, namely @{text "P\<^bsub>trm\<^esub> c t"} and \mbox{@{text "P\<^bsub>pat\<^esub> c p"}}.
       
  2394   This completes the proof showing that the weak induction principles imply 
  2367   This completes the proof showing that the weak induction principles imply 
  2395   the strong induction principles. 
  2368   the strong induction principles. 
       
  2369   }
  2396 *}
  2370 *}
  2397 
  2371 
  2398 
  2372 
  2399 section {* Related Work\label{related} *}
  2373 section {* Related Work\label{related} *}
  2400 
  2374