Paper/Paper.thy
changeset 2517 e1093e680bcf
parent 2516 c86b98642013
child 2518 7044f796d8d1
equal deleted inserted replaced
2516:c86b98642013 2517:e1093e680bcf
  1932   %These additional assumptions amount to a formal
  1932   %These additional assumptions amount to a formal
  1933   %version of the informal variable convention for binders. 
  1933   %version of the informal variable convention for binders. 
  1934   To sketch how this strengthening extends to the case of multiple binders, we use as
  1934   To sketch how this strengthening extends to the case of multiple binders, we use as
  1935   running example the term-constructors @{text "Lam"} and @{text "Let"}
  1935   running example the term-constructors @{text "Lam"} and @{text "Let"}
  1936   from example \eqref{letpat}. Instead of establishing @{text " P\<^bsub>trm\<^esub> t \<and> P\<^bsub>pat\<^esub> p"},
  1936   from example \eqref{letpat}. Instead of establishing @{text " P\<^bsub>trm\<^esub> t \<and> P\<^bsub>pat\<^esub> p"},
  1937   the stronger induction principles establish properties @{text " P\<^bsub>trm\<^esub> c t \<and> P\<^bsub>pat\<^esub> c p"}
  1937   the stronger induction principle for \eqref{letpat} establishes properties @{text " P\<^bsub>trm\<^esub> c t \<and> P\<^bsub>pat\<^esub> c p"}
  1938   where the additional parameter @{text c} controls
  1938   where the additional parameter @{text c} controls
  1939   which freshness assumptions the binders should satisfy. For the two term constructors 
  1939   which freshness assumptions the binders should satisfy. For the two term constructors 
  1940   this means that the user has to establish in inductions the implications
  1940   this means that the user has to establish in inductions the implications
  1941   %
  1941   %
  1942   \begin{center}
  1942   \begin{center}
  1943   \begin{tabular}{l}
  1943   \begin{tabular}{l}
  1944   @{text "\<forall>a t c. {atom a} \<FRESH>\<^sup>* c \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t) \<Rightarrow> P\<^bsub>trm\<^esub> c (Lam a t)"}\\
  1944   @{text "\<forall>a t c. {atom a} \<FRESH>\<^sup>* c \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t) \<Rightarrow> P\<^bsub>trm\<^esub> c (Lam a t)"}\\
  1945   @{text "\<forall>p t c. (set (bn p)) \<FRESH>\<^sup>* c \<and> (\<forall>d. P\<^bsub>pat\<^esub> d p) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t) \<and> \<Rightarrow> P\<^bsub>trm\<^esub> c (Let p t)"}
  1945   @{text "\<forall>p t c. (set (bn p)) \<FRESH>\<^sup>* c \<and> (\<forall>d. P\<^bsub>pat\<^esub> d p) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t) \<and> \<Rightarrow> P\<^bsub>trm\<^esub> c (Let p t)"}\\%[-0mm]
  1946   \end{tabular}
  1946   \end{tabular}
  1947   \end{center}
  1947   \end{center}
  1948 
  1948 
  1949   In \cite{UrbanTasson05} we showed how the weaker induction principles imply
  1949   In \cite{UrbanTasson05} we showed how the weaker induction principles imply
  1950   the stronger ones. This was done by some quite complicated, nevertheless automated,
  1950   the stronger ones. This was done by some quite complicated, nevertheless automated,
  1951   induction proofs. In this paper we simplify this work by leveraging the automated proof
  1951   induction proofs. In this paper we simplify this work by leveraging the automated proof
  1952   methods from the function package of Isabelle/HOL generates. 
  1952   methods from the function package of Isabelle/HOL generates. 
  1953 
  1953   The reasoning principle these methods employ is well-founded induction. 
  1954   The reasoning principle we employ here is well-founded induction. For this we have to discharge
  1954   To use them in our setting, we have to discharge
  1955   two proof obligations: one is that we have
  1955   two proof obligations: one is that we have
  1956   well-founded measures (for each type @{text "ty"}$^\alpha_{1..n}$) that decrease in 
  1956   well-founded measures (for each type @{text "ty"}$^\alpha_{1..n}$) that decrease in 
  1957   every induction step and the other is that we have covered all cases. 
  1957   every induction step and the other is that we have covered all cases. 
  1958   As measures we use are the size functions 
  1958   As measures we use the size functions 
  1959   @{text "size_ty"}$^\alpha_{1..n}$, which we lifted in the previous section and which are 
  1959   @{text "size_ty"}$^\alpha_{1..n}$, which we lifted in the previous section and which are 
  1960   all well-founded. It is straightforward to establish that these measures decrease 
  1960   all well-founded. It is straightforward to establish that these measures decrease 
  1961   in every induction step.
  1961   in every induction step.
  1962   
  1962   
  1963   What is left to show is that we covered all cases. To do so, we use 
  1963   What is left to show is that we covered all cases. To do so, we use 
  1964   a cases lemma derived for each type, which for the terms in \eqref{letpat} 
  1964   a cases lemma derived for each type. For the terms in \eqref{letpat} 
  1965   is of the form
  1965   this lemma is of the form
  1966   %
  1966   %
  1967   \begin{equation}\label{weakcases}
  1967   \begin{equation}\label{weakcases}
  1968   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  1968   \infer{@{text "P\<^bsub>trm\<^esub>"}}
  1969   {\begin{array}{l@ {\hspace{9mm}}l}
  1969   {\begin{array}{l@ {\hspace{9mm}}l}
  1970   @{text "\<forall>x. t = Var x \<Rightarrow> P\<^bsub>trm\<^esub>"} & @{text "\<forall>a t'. t = Lam a t' \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1970   @{text "\<forall>x. t = Var x \<Rightarrow> P\<^bsub>trm\<^esub>"} & @{text "\<forall>a t'. t = Lam a t' \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1971   @{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>"}\\
  1971   @{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>"}\\
  1972   \end{array}}
  1972   \end{array}}\\[-1mm]
  1973   \end{equation}
  1973   \end{equation}
  1974   %
  1974   %
  1975   These cases lemmas have a premise for each term-constructor.
  1975   where we have a premise for each term-constructor.
  1976   The idea behind them is that we can conclude with a property @{text "P\<^bsub>trm\<^esub>"},
  1976   The idea behind such cases lemmas is that we can conclude with a property @{text "P\<^bsub>trm\<^esub>"},
  1977   provided we can show that this property holds if we substitute for @{text "t"} all 
  1977   provided we can show that this property holds if we substitute for @{text "t"} all 
  1978   possible term-constructors. 
  1978   possible term-constructors. 
  1979   
  1979   
  1980   The only remaining difficulty is that in order to derive the stronger induction
  1980   The only remaining difficulty is that in order to derive the stronger induction
  1981   principles conveniently, the cases lemma in \eqref{weakcases} is too weak. For this note that
  1981   principles conveniently, the cases lemma in \eqref{weakcases} is too weak. For this note that
  1982   in order to apply this lemma, we have to establish @{text "P\<^bsub>trm\<^esub>"} for \emph{all} @{text Lam}- and 
  1982   in order to apply this lemma, we have to establish @{text "P\<^bsub>trm\<^esub>"} for \emph{all} @{text Lam}- and 
  1983   \emph{all} @{text Let}-terms. 
  1983   \emph{all} @{text Let}-terms. 
  1984   What we need instead is a cases rule where we only have to consider terms that have 
  1984   What we need instead is a cases rule where we only have to consider terms that have 
  1985   binders being fresh w.r.t.~a context @{text "c"}, namely
  1985   binders that are fresh w.r.t.~a context @{text "c"}. This gives the implications
  1986   %
  1986   %
  1987   \begin{center}
  1987   \begin{center}
  1988   \begin{tabular}{l}
  1988   \begin{tabular}{l}
  1989   @{text "\<forall>a t'. t = Lam a t' \<and> {atom a} \<FRESH>\<^sup>* c \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1989   @{text "\<forall>a t'. t = Lam a t' \<and> {atom a} \<FRESH>\<^sup>* c \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
  1990   @{text "\<forall>p t'. t = Let p t' \<and> (set (bn p)) \<FRESH>\<^sup>* c \<Rightarrow> P\<^bsub>trm\<^esub>"}
  1990   @{text "\<forall>p t'. t = Let p t' \<and> (set (bn p)) \<FRESH>\<^sup>* c \<Rightarrow> P\<^bsub>trm\<^esub>"}\\%[-2mm]
  1991   \end{tabular}
  1991   \end{tabular}
  1992   \end{center}
  1992   \end{center}
  1993   %
  1993   %
  1994   However, this can be relatively easily be derived from the implications in \eqref{weakcases} 
  1994   \noindent
       
  1995   which however can be relatively easily be derived from the implications in \eqref{weakcases} 
  1995   by a renaming using Properties \ref{supppermeq} and \ref{avoiding}. In the first case we know
  1996   by a renaming using Properties \ref{supppermeq} and \ref{avoiding}. In the first case we know
  1996   that @{text "{atom a} \<FRESH>\<^sup>* Lam a t"}. Property \eqref{avoiding} provides us therefore with 
  1997   that @{text "{atom a} \<FRESH>\<^sup>* Lam a t"}. Property \eqref{avoiding} provides us therefore with 
  1997   a permutation @{text q}, such that @{text "{atom (q \<bullet> a)} \<FRESH>\<^sup>* c"} and 
  1998   a permutation @{text q}, such that @{text "{atom (q \<bullet> a)} \<FRESH>\<^sup>* c"} and 
  1998   @{text "supp (Lam a t) \<FRESH>\<^sup>* q"} hold.
  1999   @{text "supp (Lam a t) \<FRESH>\<^sup>* q"} hold.
  1999   By using Property \ref{supppermeq}, we can infer that @{text "Lam (q \<bullet> a) (q \<bullet> t) = Lam a t"}
  2000   By using Property \ref{supppermeq}, we can infer from the latter 
       
  2001   that @{text "Lam (q \<bullet> a) (q \<bullet> t) = Lam a t"}
  2000   and we are done with this case.
  2002   and we are done with this case.
  2001 
  2003 
  2002   The @{text Let}-case involving a (non-recursive) deep binder is a bit more complicated.
  2004   The @{text Let}-case involving a (non-recursive) deep binder is a bit more complicated.
  2003   The reason is that the we cannot apply Property \ref{avoiding} to the whole term @{text "Let p t"},
  2005   The reason is that the we cannot apply Property \ref{avoiding} to the whole term @{text "Let p t"},
  2004   because @{text p} might contain names that are bound (by @{text bn}) and that are 
  2006   because @{text p} might contain names that are bound (by @{text bn}) and so are 
  2005   free. To solve this problem we have to introduce a permutation functions that only
  2007   free. To solve this problem we have to introduce a permutation function that only
  2006   permutes names bound by @{text bn} and leaves the other names unchanged. We do this again
  2008   permutes names bound by @{text bn} and leaves the other names unchanged. We do this again
  2007   by lifting. Assuming a
  2009   by lifting. For a
  2008   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}, we define 
  2010   clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}, we define 
  2009   %
  2011   %
  2010   \begin{center}
  2012   \begin{center}
  2011   @{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"} \;\; with
  2013   @{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"} \;\; with
  2012   $\begin{cases}
  2014   $\begin{cases}
  2028   %\end{center}
  2030   %\end{center}
  2029   %
  2031   %
  2030   \noindent
  2032   \noindent
  2031   Now Properties \ref{supppermeq} and \ref{avoiding} give us a permutation @{text q} such that
  2033   Now Properties \ref{supppermeq} and \ref{avoiding} give us a permutation @{text q} such that
  2032   @{text "(set (bn (q \<bullet>\<^bsub>bn\<^esub> p)) \<FRESH>\<^sup>* c"} holds and such that @{text "[q \<bullet>\<^bsub>bn\<^esub> p]\<^bsub>list\<^esub>.(q \<bullet> t)"}
  2034   @{text "(set (bn (q \<bullet>\<^bsub>bn\<^esub> p)) \<FRESH>\<^sup>* c"} holds and such that @{text "[q \<bullet>\<^bsub>bn\<^esub> p]\<^bsub>list\<^esub>.(q \<bullet> t)"}
  2033   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"}. But
  2035   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"}. T
  2034   these facts establish that @{text "Let (q \<bullet>\<^bsub>bn\<^esub> p) (p \<bullet> t) = Let p t"}, as we need. This
  2036   hese facts establish that @{text "Let (q \<bullet>\<^bsub>bn\<^esub> p) (p \<bullet> t) = Let p t"}, as we need. This
  2035   completes the interesting cases in \eqref{letpat} for strengthening the induction
  2037   completes the non-trivial cases in \eqref{letpat} for strengthening the corresponding induction
  2036   principles.
  2038   principle.
  2037   
  2039   
  2038 
  2040 
  2039 
  2041 
  2040   %A natural question is
  2042   %A natural question is
  2041   %whether we can also strengthen the weak induction principles involving
  2043   %whether we can also strengthen the weak induction principles involving
  2218   technique supports very elegantly many aspects of \emph{single} binding, and
  2220   technique supports very elegantly many aspects of \emph{single} binding, and
  2219   impressive work has been done that uses HOAS for mechanising the metatheory
  2221   impressive work has been done that uses HOAS for mechanising the metatheory
  2220   of SML~\cite{LeeCraryHarper07}. We are, however, not aware how multiple
  2222   of SML~\cite{LeeCraryHarper07}. We are, however, not aware how multiple
  2221   binders of SML are represented in this work. Judging from the submitted
  2223   binders of SML are represented in this work. Judging from the submitted
  2222   Twelf-solution for the POPLmark challenge, HOAS cannot easily deal with
  2224   Twelf-solution for the POPLmark challenge, HOAS cannot easily deal with
  2223   binding constructs where the number of bound variables is not fixed. %For
  2225   binding constructs where the number of bound variables is not fixed. %For example 
  2224   example 
       
  2225   In the second part of this challenge, @{text "Let"}s involve
  2226   In the second part of this challenge, @{text "Let"}s involve
  2226   patterns that bind multiple variables at once. In such situations, HOAS
  2227   patterns that bind multiple variables at once. In such situations, HOAS
  2227   seems to have to resort to the iterated-single-binders-approach with
  2228   seems to have to resort to the iterated-single-binders-approach with
  2228   all the unwanted consequences when reasoning about the resulting terms.
  2229   all the unwanted consequences when reasoning about the resulting terms.
  2229 
  2230 
  2248   this tool have also put forward (on paper) a definition for
  2249   this tool have also put forward (on paper) a definition for
  2249   $\alpha$-equivalence of terms that can be specified in Ott.  This definition is
  2250   $\alpha$-equivalence of terms that can be specified in Ott.  This definition is
  2250   rather different from ours, not using any nominal techniques.  To our
  2251   rather different from ours, not using any nominal techniques.  To our
  2251   knowledge there is also no concrete mathematical result concerning this
  2252   knowledge there is also no concrete mathematical result concerning this
  2252   notion of $\alpha$-equivalence.  A definition for the notion of free variables
  2253   notion of $\alpha$-equivalence.  A definition for the notion of free variables
  2253   is work in progress in Ott.
  2254   is in Ott work in progress.
  2254 
  2255 
  2255   Although we were heavily inspired by the syntax of Ott,
  2256   Although we were heavily inspired by the syntax of Ott,
  2256   its definition of $\alpha$-equivalence is unsuitable for our extension of
  2257   its definition of $\alpha$-equivalence is unsuitable for our extension of
  2257   Nominal Isabelle. First, it is far too complicated to be a basis for
  2258   Nominal Isabelle. First, it is far too complicated to be a basis for
  2258   automated proofs implemented on the ML-level of Isabelle/HOL. Second, it
  2259   automated proofs implemented on the ML-level of Isabelle/HOL. Second, it
  2335   To specify general binders we used the specifications from Ott, but extended them 
  2336   To specify general binders we used the specifications from Ott, but extended them 
  2336   in some places and restricted
  2337   in some places and restricted
  2337   them in others so that they make sense in the context of $\alpha$-equated terms. 
  2338   them in others so that they make sense in the context of $\alpha$-equated terms. 
  2338   We also introduced two binding modes (set and res) that do not 
  2339   We also introduced two binding modes (set and res) that do not 
  2339   exist in Ott. 
  2340   exist in Ott. 
  2340   We have tried out the extension with terms from Core-Haskell, type-schemes 
  2341   We have tried out the extension with calculi such as Core-Haskell, type-schemes 
  2341   and a dozen of other calculi from programming language research. The code
  2342   and approximately a  dozen of other typical examples from programming 
       
  2343   language research \cite{SewellBestiary}. The code
  2342   will eventually become part of the next Isabelle distribution.\footnote{For the moment
  2344   will eventually become part of the next Isabelle distribution.\footnote{For the moment
  2343   it can be downloaded from the Mercurial repository linked at
  2345   it can be downloaded from the Mercurial repository linked at
  2344   \href{http://isabelle.in.tum.de/nominal/download}
  2346   \href{http://isabelle.in.tum.de/nominal/download}
  2345   {http://isabelle.in.tum.de/nominal/download}.}
  2347   {http://isabelle.in.tum.de/nominal/download}.}
  2346 
  2348