Paper/Paper.thy
changeset 1690 44a5edac90ad
parent 1687 51bc795b81fd
child 1693 3668b389edf3
equal deleted inserted replaced
1689:8c0eef2b84e7 1690:44a5edac90ad
    24   fv ("fv'(_')" [100] 100) and
    24   fv ("fv'(_')" [100] 100) and
    25   equal ("=") and
    25   equal ("=") and
    26   alpha_abs ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and 
    26   alpha_abs ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and 
    27   Abs ("[_]\<^raw:$\!$>\<^bsub>set\<^esub>._") and
    27   Abs ("[_]\<^raw:$\!$>\<^bsub>set\<^esub>._") and
    28   Abs_lst ("[_]\<^raw:$\!$>\<^bsub>list\<^esub>._") and
    28   Abs_lst ("[_]\<^raw:$\!$>\<^bsub>list\<^esub>._") and
    29   Abs_res ("[_]\<^raw:$\!$>\<^bsub>res\<^esub>._") 
    29   Abs_res ("[_]\<^raw:$\!$>\<^bsub>res\<^esub>._") and
       
    30   Cons ("_::_" [78,77] 73)
    30 (*>*)
    31 (*>*)
    31 
    32 
    32 
    33 
    33 section {* Introduction *}
    34 section {* Introduction *}
    34 
    35 
    50   for cut-elimination in classical logic \cite{UrbanZhu08}. It has also been
    51   for cut-elimination in classical logic \cite{UrbanZhu08}. It has also been
    51   used by Pollack for formalisations in the locally-nameless approach to
    52   used by Pollack for formalisations in the locally-nameless approach to
    52   binding \cite{SatoPollack10}.
    53   binding \cite{SatoPollack10}.
    53 
    54 
    54   However, Nominal Isabelle has fared less well in a formalisation of
    55   However, Nominal Isabelle has fared less well in a formalisation of
    55   the algorithm W \cite{UrbanNipkow09}, where types and type-schemes,
    56   the algorithm W \cite{UrbanNipkow09}, where types and type-schemes are,
    56   respectively, are of the form
    57   respectively, of the form
    57   %
    58   %
    58   \begin{equation}\label{tysch}
    59   \begin{equation}\label{tysch}
    59   \begin{array}{l}
    60   \begin{array}{l}
    60   @{text "T ::= x | T \<rightarrow> T"}\hspace{5mm}
    61   @{text "T ::= x | T \<rightarrow> T"}\hspace{5mm}
    61   @{text "S ::= \<forall>{x\<^isub>1,\<dots>, x\<^isub>n}. T"}
    62   @{text "S ::= \<forall>{x\<^isub>1,\<dots>, x\<^isub>n}. T"}
   126   which the order of binders does not matter, but the ``cardinality'' of the
   127   which the order of binders does not matter, but the ``cardinality'' of the
   127   binders has to agree.
   128   binders has to agree.
   128 
   129 
   129   However, we found that this is still not sufficient for dealing with
   130   However, we found that this is still not sufficient for dealing with
   130   language constructs frequently occurring in programming language
   131   language constructs frequently occurring in programming language
   131   research. For example in @{text "\<LET>"}s containing patterns
   132   research. For example in @{text "\<LET>"}s containing patterns like
   132   %
   133   %
   133   \begin{equation}\label{two}
   134   \begin{equation}\label{two}
   134   @{text "\<LET> (x, y) = (3, 2) \<IN> x - y \<END>"}
   135   @{text "\<LET> (x, y) = (3, 2) \<IN> x - y \<END>"}
   135   \end{equation}
   136   \end{equation}
   136 
   137 
   168   \end{center}
   169   \end{center}
   169 
   170 
   170   \noindent
   171   \noindent
   171   where the notation @{text "[_]._"} indicates that the @{text "x\<^isub>i"}
   172   where the notation @{text "[_]._"} indicates that the @{text "x\<^isub>i"}
   172   become bound in @{text s}. In this representation the term 
   173   become bound in @{text s}. In this representation the term 
   173   \mbox{@{text "\<LET> [x].s [t\<^isub>1, t\<^isub>2]"}} would be a perfectly legal
   174   \mbox{@{text "\<LET> [x].s [t\<^isub>1, t\<^isub>2]"}} is a perfectly legal
   174   instance, but the lengths of two lists do not agree. To exclude such terms, 
   175   instance, but the lengths of two lists do not agree. To exclude such terms, 
   175   additional predicates about well-formed
   176   additional predicates about well-formed
   176   terms are needed in order to ensure that the two lists are of equal
   177   terms are needed in order to ensure that the two lists are of equal
   177   length. This can result into very messy reasoning (see for
   178   length. This can result into very messy reasoning (see for
   178   example~\cite{BengtsonParow09}). To avoid this, we will allow type
   179   example~\cite{BengtsonParow09}). To avoid this, we will allow type
   225   Another reason is that we establish the reasoning infrastructure
   226   Another reason is that we establish the reasoning infrastructure
   226   for alpha-\emph{equated} terms. In contrast, Ott produces  a reasoning 
   227   for alpha-\emph{equated} terms. In contrast, Ott produces  a reasoning 
   227   infrastructure in Isabelle/HOL for
   228   infrastructure in Isabelle/HOL for
   228   \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms
   229   \emph{non}-alpha-equated, or ``raw'', terms. While our alpha-equated terms
   229   and the raw terms produced by Ott use names for bound variables,
   230   and the raw terms produced by Ott use names for bound variables,
   230   there is a key difference: working with alpha-equated terms means that the
   231   there is a key difference: working with alpha-equated terms means, for example,  
   231   two type-schemes (with $x$, $y$ and $z$ being distinct)
   232   that the two type-schemes (with $x$, $y$ and $z$ being distinct)
   232 
   233 
   233   \begin{center}
   234   \begin{center}
   234   @{text "\<forall>{x}. x \<rightarrow> y  = \<forall>{x, z}. x \<rightarrow> y"} 
   235   @{text "\<forall>{x}. x \<rightarrow> y  = \<forall>{x, z}. x \<rightarrow> y"} 
   235   \end{center}
   236   \end{center}
   236   
   237   
   286   We take as the starting point a definition of raw terms (defined as a
   287   We take as the starting point a definition of raw terms (defined as a
   287   datatype in Isabelle/HOL); identify then the alpha-equivalence classes in
   288   datatype in Isabelle/HOL); identify then the alpha-equivalence classes in
   288   the type of sets of raw terms according to our alpha-equivalence relation
   289   the type of sets of raw terms according to our alpha-equivalence relation
   289   and finally define the new type as these alpha-equivalence classes
   290   and finally define the new type as these alpha-equivalence classes
   290   (non-emptiness is satisfied whenever the raw terms are definable as datatype
   291   (non-emptiness is satisfied whenever the raw terms are definable as datatype
   291   in Isabelle/HOL and the fact that our relation for alpha-equivalence is
   292   in Isabelle/HOL and the property that our relation for alpha-equivalence is
   292   indeed an equivalence relation).
   293   indeed an equivalence relation).
   293 
   294 
   294   The fact that we obtain an isomorphism between the new type and the
   295   The fact that we obtain an isomorphism between the new type and the
   295   non-empty subset shows that the new type is a faithful representation of
   296   non-empty subset shows that the new type is a faithful representation of
   296   alpha-equated terms. That is not the case for example for terms using the
   297   alpha-equated terms. That is not the case for example for terms using the
   312   @{text "fv(t\<^isub>1 t\<^isub>2) = fv(t\<^isub>1) \<union> fv(t\<^isub>2)"}\\[1mm]
   313   @{text "fv(t\<^isub>1 t\<^isub>2) = fv(t\<^isub>1) \<union> fv(t\<^isub>2)"}\\[1mm]
   313   @{text "fv(\<lambda>x.t) = fv(t) - {x}"}
   314   @{text "fv(\<lambda>x.t) = fv(t) - {x}"}
   314   \end{center}
   315   \end{center}
   315   
   316   
   316   \noindent
   317   \noindent
   317   then with the help of te quotient package we obtain a function @{text "fv\<^sup>\<alpha>"}
   318   then with the help of the quotient package we obtain a function @{text "fv\<^sup>\<alpha>"}
   318   operating on quotients, or alpha-equivalence classes of lambda-terms. This
   319   operating on quotients, or alpha-equivalence classes of lambda-terms. This
   319   lifted function is characterised by the equations
   320   lifted function is characterised by the equations
   320 
   321 
   321   \begin{center}
   322   \begin{center}
   322   @{text "fv\<^sup>\<alpha>(x) = {x}"}\hspace{10mm}
   323   @{text "fv\<^sup>\<alpha>(x) = {x}"}\hspace{10mm}
   337   automate these
   338   automate these
   338   proofs and therefore can establish a reasoning infrastructure for
   339   proofs and therefore can establish a reasoning infrastructure for
   339   alpha-equated terms.
   340   alpha-equated terms.
   340 
   341 
   341   The examples we have in mind where our reasoning infrastructure will be
   342   The examples we have in mind where our reasoning infrastructure will be
   342   helpful is the term language of System @{text "F\<^isub>C"}, also known as 
   343   helpful includes the term language of System @{text "F\<^isub>C"}, also known as 
   343   Core-Haskell (see Figure~\ref{corehas}). This term language has patterns 
   344   Core-Haskell (see Figure~\ref{corehas}). This term language involves patterns 
   344   which include lists of
   345   that include lists of
   345   type- and term- variables (the arguments of constructors) all of which are
   346   type- and term- variables (the arguments of constructors) all of which are
   346   bound in case expressions. One difficulty is that each of these variables
   347   bound in case expressions. One difficulty is that each of these variables
   347   come with a kind or type annotation. Representing such binders with single
   348   come with a kind or type annotation. Representing such binders with single
   348   binders and reasoning about them in a theorem prover would be a major pain.
   349   binders and reasoning about them in a theorem prover would be a major pain.
   349   \medskip
   350   \medskip
   360   have the variable convention already built in.
   361   have the variable convention already built in.
   361 
   362 
   362   \begin{figure}
   363   \begin{figure}
   363   \begin{boxedminipage}{\linewidth}
   364   \begin{boxedminipage}{\linewidth}
   364   \begin{center}
   365   \begin{center}
   365   \begin{tabular}{l}
   366   \begin{tabular}{rcl}
   366   Type Kinds\\
   367   \multicolumn{3}{@ {}l}{Type Kinds}\\
   367   @{text "\<kappa> ::= \<star> | \<kappa>\<^isub>1 \<rightarrow> \<kappa>\<^isub>2"}\\
   368   @{text "\<kappa>"} & @{text "::="} & @{text "\<star> | \<kappa>\<^isub>1 \<rightarrow> \<kappa>\<^isub>2"}\medskip\\
   368   Coercion Kinds\\
   369   \multicolumn{3}{@ {}l}{Coercion Kinds}\\
   369   @{text "\<iota> ::= \<sigma>\<^isub>1 \<sim> \<sigma>\<^isub>2"}\\
   370   @{text "\<iota>"} & @{text "::="} & @{text "\<sigma>\<^isub>1 \<sim> \<sigma>\<^isub>2"}\medskip\\
   370   Types\\
   371   \multicolumn{3}{@ {}l}{Types}\\
   371   @{text "\<sigma> ::= a | T | \<sigma>\<^isub>1 \<sigma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<sigma>"}}$@{text "\<^sup>n"}\\
   372   @{text "\<sigma>"} & @{text "::="} & @{text "a | T | \<sigma>\<^isub>1 \<sigma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<sigma>"}}$@{text "\<^sup>n"}\\
   372   @{text "| \<forall>a:\<kappa>. \<sigma> "}\\
   373               & & @{text "| \<forall>a:\<kappa>. \<sigma> "}\\
   373   ??? Type equality\\
   374               & & ??? Type equality\medskip\\
   374   Coercion Types\\
   375   \multicolumn{3}{@ {}l}{Coercion Types}\\
   375   @{text "\<gamma> ::= a | C | S\<^isub>n"}$\;\overline{@{text "\<gamma>"}}$@{text "\<^sup>n"}\\
   376   @{text "\<gamma>"} & @{text "::="} & @{text "a | C | S\<^isub>n"}$\;\overline{@{text "\<gamma>"}}$@{text "\<^sup>n"}\\
   376   @{text "| \<forall>a:\<iota>. \<gamma>"}\\
   377   & & @{text "| \<forall>a:\<iota>. \<gamma>"}\\
   377   ??? Coercion Type equality\\
   378   & & ??? Coercion Type equality\\
   378   @{text "| sym \<gamma> | \<gamma>\<^isub>1 \<circ> \<gamma>\<^isub>2 | left \<gamma> | right \<gamma> | \<gamma>\<^isub>1 \<sim> \<gamma>\<^isub>2 "}\\
   379   & & @{text "| sym \<gamma> | \<gamma>\<^isub>1 \<circ> \<gamma>\<^isub>2 | left \<gamma> | right \<gamma> | \<gamma>\<^isub>1 \<sim> \<gamma>\<^isub>2 "}\\
   379   @{text "| rightc \<gamma> | leftc \<gamma> | \<gamma>\<^isub>1 \<triangleright> \<gamma>\<^isub>2"}\\
   380   & & @{text "| rightc \<gamma> | leftc \<gamma> | \<gamma>\<^isub>1 \<triangleright> \<gamma>\<^isub>2"}\medskip\\
   380   Terms\\
   381   \multicolumn{3}{@ {}l}{Terms}\\
   381   @{text "e ::= x | K | \<Lambda>a:\<kappa>. e | \<Lambda>a:\<iota>. e | e \<sigma> | e \<gamma>"}\\
   382   @{text "e"} & @{text "::="} & @{text "x | K | \<Lambda>a:\<kappa>. e | \<Lambda>a:\<iota>. e | e \<sigma> | e \<gamma> |"}\\
   382   @{text "| \<lambda>x:\<sigma>.e | e\<^isub>1 e\<^isub>2"}\\
   383   & & @{text "\<lambda>x:\<sigma>.e | e\<^isub>1 e\<^isub>2 | \<LET> x:\<sigma> = e\<^isub>1 \<IN> e\<^isub>2 |"}\\
   383   @{text "| \<LET> x:\<sigma> = e\<^isub>1 \<IN> e\<^isub>2"}\\
   384   & & @{text "\<CASE> e\<^isub>1 \<OF>"}$\;\overline{@{text "p \<rightarrow> e\<^isub>2"}}$ @{text "| e \<triangleright> \<gamma>"}\medskip\\
   384   @{text "| \<CASE> e\<^isub>1 \<OF>"}$\;\overline{@{text "p \<rightarrow> e\<^isub>2"}}$\\
   385   \multicolumn{3}{@ {}l}{Patterns}\\
   385   @{text "| e \<triangleright> \<gamma>"}\\
   386   @{text "p"} & @{text "::="} & @{text "K"}$\;\overline{@{text "a:\<kappa>"}}\;\overline{@{text "x:\<sigma>"}}$\medskip\\
   386   Patterns\\
   387   \multicolumn{3}{@ {}l}{Constants}\\
   387   @{text "p ::= K"}$\;\overline{@{text "a:\<kappa>"}}\;\overline{@{text "x:\<sigma>"}}$\\
   388   @{text C} & & coercion constant\\
   388   Constants\\
   389   @{text T} & & value type constructor\\
   389   @{text C} coercion constant\\
   390   @{text "S\<^isub>n"} & & n-ary type function\\
   390   @{text T} value type constructor\\
   391   @{text K} & & data constructor\medskip\\
   391   @{text "S\<^isub>n"} n-ary type function\\
   392   \multicolumn{3}{@ {}l}{Variables}\\
   392   @{text K} data constructor\\
   393   @{text a} & & type variable\\
   393   Variables\\
   394   @{text x} & & term variable\\
   394   @{text a} type variable\\
       
   395   @{text x} term variable\\
       
   396   \end{tabular}
   395   \end{tabular}
   397   \end{center}
   396   \end{center}
   398   \end{boxedminipage}
   397   \end{boxedminipage}
   399   \caption{The term-language of System @{text "F\<^isub>C"}, also often referred to as Core-Haskell, 
   398   \caption{The term-language of System @{text "F\<^isub>C"}, also often referred to as Core-Haskell, 
   400   according to \cite{CoreHaskell}. We only made an issential modification by 
   399   according to \cite{CoreHaskell}. We only made an issential modification by 
   405 section {* A Short Review of the Nominal Logic Work *}
   404 section {* A Short Review of the Nominal Logic Work *}
   406 
   405 
   407 text {*
   406 text {*
   408   At its core, Nominal Isabelle is an adaption of the nominal logic work by
   407   At its core, Nominal Isabelle is an adaption of the nominal logic work by
   409   Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
   408   Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
   410   \cite{HuffmanUrban10}, which we review here briefly to aid the description
   409   \cite{HuffmanUrban10} (including proofs), which we review here briefly to aid the description
   411   of what follows. Two central notions in the nominal logic work are sorted
   410   of what follows. Two central notions in the nominal logic work are sorted
   412   atoms and sort-respecting permutations of atoms. The sorts can be used to
   411   atoms and sort-respecting permutations of atoms. The sorts can be used to
   413   represent different kinds of variables, such as term- and type-variables in
   412   represent different kinds of variables, such as the term- and type-variables in
   414   Core-Haskell, and it is assumed that there is an infinite supply of atoms
   413   Core-Haskell, and it is assumed that there is an infinite supply of atoms
   415   for each sort. However, in order to simplify the description, we shall
   414   for each sort. However, in order to simplify the description, we shall
   416   assume in what follows that there is only one sort of atoms.
   415   assume in what follows that there is only one sort of atoms.
   417 
   416 
   418   Permutations are bijective functions from atoms to atoms that are 
   417   Permutations are bijective functions from atoms to atoms that are 
   423 
   422 
   424   \noindent 
   423   \noindent 
   425   in which the generic type @{text "\<beta>"} stands for the type of the object 
   424   in which the generic type @{text "\<beta>"} stands for the type of the object 
   426   on which the permutation 
   425   on which the permutation 
   427   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   426   acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
   428   the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}} 
   427   the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}}, 
   429   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   428   and the inverse permutation of @{term p} as @{text "- p"}. The permutation
   430   operation is defined for products, lists, sets, functions, booleans etc 
   429   operation is defined for products, lists, sets, functions, booleans etc (see \cite{HuffmanUrban10})
   431   (see \cite{HuffmanUrban10}). Concrete  permutations are build up from 
   430   
       
   431   \begin{center}
       
   432   \begin{tabular}{@ {}cc@ {}}
       
   433   \begin{tabular}{@ {}l@ {}}
       
   434   @{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
       
   435   @{thm permute_list.simps(1)[no_vars, THEN eq_reflection]}\\
       
   436   @{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
       
   437   \end{tabular} &
       
   438   \begin{tabular}{@ {}l@ {}}
       
   439   @{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
       
   440   @{text "p \<bullet> (f x) \<equiv> (p \<bullet> f) (p \<bullet> x)"}\\
       
   441   @{thm permute_bool_def[no_vars, THEN eq_reflection]}\\
       
   442   \end{tabular}
       
   443   \end{tabular}
       
   444   \end{center}
       
   445 
       
   446   \noindent
       
   447   Concrete  permutations are build up from 
   432   swappings, written as @{text "(a b)"},
   448   swappings, written as @{text "(a b)"},
   433   which are permutations that behave as follows:
   449   which are permutations that behave as follows:
   434   %
   450   %
   435   @{text[display,indent=5] "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
   451   @{text[display,indent=5] "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
   436   
   452   
   437 
       
   438   The most original aspect of the nominal logic work of Pitts is a general
   453   The most original aspect of the nominal logic work of Pitts is a general
   439   definition for the notion of ``the set of free variables of an object @{text
   454   definition for the notion of ``the set of free variables of an object @{text
   440   "x"}''.  This notion, written @{term "supp x"}, is general in the sense that
   455   "x"}''.  This notion, written @{term "supp x"}, is general in the sense that
   441   it applies not only to lambda-terms (alpha-equated or not), but also to lists,
   456   it applies not only to lambda-terms (alpha-equated or not), but also to lists,
   442   products, sets and even functions. The definition depends only on the
   457   products, sets and even functions. The definition depends only on the
   463   \begin{property}
   478   \begin{property}
   464   @{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
   479   @{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
   465   \end{property}
   480   \end{property}
   466 
   481 
   467   \noindent
   482   \noindent
   468   For a proof see \cite{HuffmanUrban10}.
   483   While it is often clear what the support for a construction is, for
       
   484   example
       
   485   %
       
   486   \begin{eqnarray}
       
   487   @{term "supp (x, y)"} & = & @{term "supp x \<union> supp y"}\\
       
   488   @{term "supp []"} & = & @{term "{}"}\\
       
   489   @{term "supp (x#xs)"} & = & @{term "supp (x, xs)"}\\
       
   490   @{text "supp (f x)"} & @{text "\<subseteq>"} & @{term "supp (f, x)"}\\
       
   491   @{term "supp b"} & = & @{term "{}"}
       
   492   \end{eqnarray}
       
   493   
       
   494   \noindent 
       
   495   it can sometimes be difficult to establish the support precisely,
       
   496   and only give an over approximation (see functions above). This
       
   497   over approximation can be formalised with the notions \emph{supports},
       
   498   defined as follows:
       
   499   
       
   500 
   469 
   501 
   470   %\begin{property}
   502   %\begin{property}
   471   %@{thm[mode=IfThen] at_set_avoiding[no_vars]}
   503   %@{thm[mode=IfThen] at_set_avoiding[no_vars]}
   472   %\end{property}
   504   %\end{property}
   473 
   505