Paper/Paper.thy
changeset 1694 3bf0fddb7d44
parent 1693 3668b389edf3
child 1699 2dca07aca287
equal deleted inserted replaced
1693:3668b389edf3 1694:3bf0fddb7d44
    11  "equal \<equiv> (op =)" 
    11  "equal \<equiv> (op =)" 
    12 
    12 
    13 notation (latex output)
    13 notation (latex output)
    14   swap ("'(_ _')" [1000, 1000] 1000) and
    14   swap ("'(_ _')" [1000, 1000] 1000) and
    15   fresh ("_ # _" [51, 51] 50) and
    15   fresh ("_ # _" [51, 51] 50) and
    16   fresh_star ("_ #* _" [51, 51] 50) and
    16   fresh_star ("_ #\<^sup>* _" [51, 51] 50) and
    17   supp ("supp _" [78] 73) and
    17   supp ("supp _" [78] 73) and
    18   uminus ("-_" [78] 73) and
    18   uminus ("-_" [78] 73) and
    19   If  ("if _ then _ else _" 10) and
    19   If  ("if _ then _ else _" 10) and
    20   alpha_gen ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{set}}$}}>\<^bsup>_,_,_\<^esup> _") and
    20   alpha_gen ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{set}}$}}>\<^bsup>_,_,_\<^esup> _") and
    21   alpha_lst ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{list}}$}}>\<^bsup>_,_,_\<^esup> _") and
    21   alpha_lst ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{list}}$}}>\<^bsup>_,_,_\<^esup> _") and
    45   where free and bound variables have names.  For such alpha-equated terms,  Nominal Isabelle
    45   where free and bound variables have names.  For such alpha-equated terms,  Nominal Isabelle
    46   derives automatically a reasoning infrastructure that has been used
    46   derives automatically a reasoning infrastructure that has been used
    47   successfully in formalisations of an equivalence checking algorithm for LF
    47   successfully in formalisations of an equivalence checking algorithm for LF
    48   \cite{UrbanCheneyBerghofer08}, Typed
    48   \cite{UrbanCheneyBerghofer08}, Typed
    49   Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
    49   Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
    50   \cite{BengtsonParrow07,BengtsonParow09} and a strong normalisation result
    50   \cite{BengtsonParow09} and a strong normalisation result
    51   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
    52   used by Pollack for formalisations in the locally-nameless approach to
    52   used by Pollack for formalisations in the locally-nameless approach to
    53   binding \cite{SatoPollack10}.
    53   binding \cite{SatoPollack10}.
    54 
    54 
    55   However, Nominal Isabelle has fared less well in a formalisation of
    55   However, Nominal Isabelle has fared less well in a formalisation of
   326   \end{center}
   326   \end{center}
   327 
   327 
   328   \noindent
   328   \noindent
   329   (Note that this means also the term-constructors for variables, applications
   329   (Note that this means also the term-constructors for variables, applications
   330   and lambda are lifted to the quotient level.)  This construction, of course,
   330   and lambda are lifted to the quotient level.)  This construction, of course,
   331   only works if alpha-equivalence is indeed an equivalence relation, and the lifted
   331   only works if alpha-equivalence is indeed an equivalence relation, and the
   332   definitions and theorems are respectful w.r.t.~alpha-equivalence.  For example, we
   332   lifted definitions and theorems are respectful w.r.t.~alpha-equivalence.
   333   will not be able to lift a bound-variable function, which can be defined for
   333   For example, we will not be able to lift a bound-variable function. Although
   334   raw terms. The reason is that this function does not respect alpha-equivalence. 
   334   this function can be defined for raw terms, it does not respect
   335   To sum up, every lifting of
   335   alpha-equivalence and therefore cannot be lifted. To sum up, every lifting
   336   theorems to the quotient level needs proofs of some respectfulness
   336   of theorems to the quotient level needs proofs of some respectfulness
   337   properties (see \cite{Homeier05}). In the paper we show that we are able to 
   337   properties (see \cite{Homeier05}). In the paper we show that we are able to
   338   automate these
   338   automate these proofs and therefore can establish a reasoning infrastructure
   339   proofs and therefore can establish a reasoning infrastructure for
   339   for alpha-equated terms.
   340   alpha-equated terms.
       
   341 
   340 
   342   The examples we have in mind where our reasoning infrastructure will be
   341   The examples we have in mind where our reasoning infrastructure will be
   343   helpful includes the term language of System @{text "F\<^isub>C"}, also known as 
   342   helpful includes the term language of System @{text "F\<^isub>C"}, also
   344   Core-Haskell (see Figure~\ref{corehas}). This term language involves patterns 
   343   known as Core-Haskell (see Figure~\ref{corehas}). This term language
   345   that include lists of
   344   involves patterns that have lists of type- and term-variables (the
   346   type- and term- variables (the arguments of constructors) all of which are
   345   arguments of constructors) all of which are bound in case expressions. One
   347   bound in case expressions. One difficulty is that each of these variables
   346   difficulty is that each of these variables come with a kind or type
   348   come with a kind or type annotation. Representing such binders with single
   347   annotation. Representing such binders with single binders and reasoning
   349   binders and reasoning about them in a theorem prover would be a major pain.
   348   about them in a theorem prover would be a major pain.  \medskip
   350   \medskip
       
   351 
       
   352 
   349 
   353   \noindent
   350   \noindent
   354   {\bf Contributions:}  We provide new definitions for when terms
   351   {\bf Contributions:}  We provide new definitions for when terms
   355   involving multiple binders are alpha-equivalent. These definitions are
   352   involving multiple binders are alpha-equivalent. These definitions are
   356   inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
   353   inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
   367   \multicolumn{3}{@ {}l}{Type Kinds}\\
   364   \multicolumn{3}{@ {}l}{Type Kinds}\\
   368   @{text "\<kappa>"} & @{text "::="} & @{text "\<star> | \<kappa>\<^isub>1 \<rightarrow> \<kappa>\<^isub>2"}\medskip\\
   365   @{text "\<kappa>"} & @{text "::="} & @{text "\<star> | \<kappa>\<^isub>1 \<rightarrow> \<kappa>\<^isub>2"}\medskip\\
   369   \multicolumn{3}{@ {}l}{Coercion Kinds}\\
   366   \multicolumn{3}{@ {}l}{Coercion Kinds}\\
   370   @{text "\<iota>"} & @{text "::="} & @{text "\<sigma>\<^isub>1 \<sim> \<sigma>\<^isub>2"}\medskip\\
   367   @{text "\<iota>"} & @{text "::="} & @{text "\<sigma>\<^isub>1 \<sim> \<sigma>\<^isub>2"}\medskip\\
   371   \multicolumn{3}{@ {}l}{Types}\\
   368   \multicolumn{3}{@ {}l}{Types}\\
   372   @{text "\<sigma>"} & @{text "::="} & @{text "a | T | \<sigma>\<^isub>1 \<sigma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<sigma>"}}$@{text "\<^sup>n"}\\
   369   @{text "\<sigma>"} & @{text "::="} & @{text "a | T | \<sigma>\<^isub>1 \<sigma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<sigma>"}}$@{text "\<^sup>n"} 
   373               & & @{text "| \<forall>a:\<kappa>. \<sigma> "}\\
   370   @{text "| \<forall>a:\<kappa>. \<sigma> | \<iota> \<Rightarrow> \<sigma>"}\medskip\\
   374               & & ??? Type equality\medskip\\
       
   375   \multicolumn{3}{@ {}l}{Coercion Types}\\
   371   \multicolumn{3}{@ {}l}{Coercion Types}\\
   376   @{text "\<gamma>"} & @{text "::="} & @{text "a | C | S\<^isub>n"}$\;\overline{@{text "\<gamma>"}}$@{text "\<^sup>n"}\\
   372   @{text "\<gamma>"} & @{text "::="} & @{text "c | C | \<gamma>\<^isub>1 \<gamma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<gamma>"}}$@{text "\<^sup>n"}
   377   & & @{text "| \<forall>a:\<iota>. \<gamma>"}\\
   373   @{text "| \<forall>c:\<iota>. \<gamma> | \<iota> \<Rightarrow> \<gamma> |"}\\
   378   & & ??? Coercion Type equality\\
   374   & & @{text "refl \<sigma> | sym \<gamma> | \<gamma>\<^isub>1 \<circ> \<gamma>\<^isub>2 | \<gamma> @ \<sigma> |"}\\
   379   & & @{text "| sym \<gamma> | \<gamma>\<^isub>1 \<circ> \<gamma>\<^isub>2 | left \<gamma> | right \<gamma> | \<gamma>\<^isub>1 \<sim> \<gamma>\<^isub>2 "}\\
   375   & & @{text "left \<gamma> | right \<gamma> | \<gamma>\<^isub>1 \<sim> \<gamma>\<^isub>2 |"}\\
   380   & & @{text "| rightc \<gamma> | leftc \<gamma> | \<gamma>\<^isub>1 \<triangleright> \<gamma>\<^isub>2"}\medskip\\
   376   & & @{text "rightc \<gamma> | leftc \<gamma> | \<gamma>\<^isub>1 \<triangleright> \<gamma>\<^isub>2"}\medskip\\
   381   \multicolumn{3}{@ {}l}{Terms}\\
   377   \multicolumn{3}{@ {}l}{Terms}\\
   382   @{text "e"} & @{text "::="} & @{text "x | K | \<Lambda>a:\<kappa>. e | \<Lambda>a:\<iota>. e | e \<sigma> | e \<gamma> |"}\\
   378   @{text "e"} & @{text "::="} & @{text "x | K | \<Lambda>a:\<kappa>. e | \<Lambda>c:\<iota>. e | e \<sigma> | e \<gamma> |"}\\
   383   & & @{text "\<lambda>x:\<sigma>.e | e\<^isub>1 e\<^isub>2 | \<LET> x:\<sigma> = e\<^isub>1 \<IN> e\<^isub>2 |"}\\
   379   & & @{text "\<lambda>x:\<sigma>. e | e\<^isub>1 e\<^isub>2 | \<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\\
   380   & & @{text "\<CASE> e\<^isub>1 \<OF>"}$\;\overline{@{text "p \<rightarrow> e\<^isub>2"}}$ @{text "| e \<triangleright> \<gamma>"}\medskip\\
   385   \multicolumn{3}{@ {}l}{Patterns}\\
   381   \multicolumn{3}{@ {}l}{Patterns}\\
   386   @{text "p"} & @{text "::="} & @{text "K"}$\;\overline{@{text "a:\<kappa>"}}\;\overline{@{text "a:\<iota>"}}\;\overline{@{text "x:\<sigma>"}}$\medskip\\
   382   @{text "p"} & @{text "::="} & @{text "K"}$\;\overline{@{text "a:\<kappa>"}}\;\overline{@{text "c:\<iota>"}}\;\overline{@{text "x:\<sigma>"}}$\medskip\\
   387   \multicolumn{3}{@ {}l}{Constants}\\
   383   \multicolumn{3}{@ {}l}{Constants}\\
   388   @{text C} & & coercion constant\\
   384   @{text C} & & coercion constants\\
   389   @{text T} & & value type constructor\\
   385   @{text T} & & value type constructors\\
   390   @{text "S\<^isub>n"} & & n-ary type function\\
   386   @{text "S\<^isub>n"} & & n-ary type functions\\
   391   @{text K} & & data constructor\medskip\\
   387   @{text K} & & data constructors\medskip\\
   392   \multicolumn{3}{@ {}l}{Variables}\\
   388   \multicolumn{3}{@ {}l}{Variables}\\
   393   @{text a} & & type variable\\
   389   @{text a} & & type variables\\
   394   @{text x} & & term variable\\
   390   @{text c} & & coercion variables\\
       
   391   @{text x} & & term variables\\
   395   \end{tabular}
   392   \end{tabular}
   396   \end{center}
   393   \end{center}
   397   \end{boxedminipage}
   394   \end{boxedminipage}
   398   \caption{The term-language of System @{text "F\<^isub>C"}, also often referred to as Core-Haskell, 
   395   \caption{The term-language of System @{text "F\<^isub>C"}, also often referred to as \emph{Core-Haskell}
   399   according to \cite{CoreHaskell}. We only made an inessential modification by 
   396    \cite{CoreHaskell}. In this version of Core-Haskell we made a modification by 
   400   separating the grammars for type kinds and coercion types.\label{corehas}}
   397   separating completely the grammars for type kinds and coercion types.\label{corehas}}
   401   \end{figure}
   398   \end{figure}
   402 *}
   399 *}
   403 
   400 
   404 section {* A Short Review of the Nominal Logic Work *}
   401 section {* A Short Review of the Nominal Logic Work *}
   405 
   402 
   406 text {*
   403 text {*
   407   At its core, Nominal Isabelle is an adaption of the nominal logic work by
   404   At its core, Nominal Isabelle is an adaption of the nominal logic work by
   408   Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
   405   Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
   409   \cite{HuffmanUrban10} (including proofs), which we review here briefly to aid the description
   406   \cite{HuffmanUrban10} (including proofs). We shall briefly review this work
   410   of what follows. Two central notions in the nominal logic work are sorted
   407   to aid the description of what follows. 
   411   atoms and sort-respecting permutations of atoms. The sorts can be used to
   408 
   412   represent different kinds of variables, such as the term- and type-variables in
   409   Two central notions in the nominal
   413   Core-Haskell, and it is assumed that there is an infinite supply of atoms
   410   logic work are sorted atoms and sort-respecting permutations of atoms. The
   414   for each sort. However, in order to simplify the description, we shall
   411   sorts can be used to represent different kinds of variables, such as the
   415   assume in what follows that there is only one sort of atoms.
   412   term- and type-variables in Core-Haskell, and it is assumed that there is an
       
   413   infinite supply of atoms for each sort. However, in order to simplify the
       
   414   description, we shall assume in what follows that there is only one sort of
       
   415   atoms.
   416 
   416 
   417   Permutations are bijective functions from atoms to atoms that are 
   417   Permutations are bijective functions from atoms to atoms that are 
   418   the identity everywhere except on a finite number of atoms. There is a 
   418   the identity everywhere except on a finite number of atoms. There is a 
   419   two-place permutation operation written
   419   two-place permutation operation written
   420   %
   420   %
   421   @{text[display,indent=5] "_ \<bullet> _  ::  perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
   421   @{text[display,indent=5] "_ \<bullet> _  ::  perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
   422 
   422 
   423   \noindent 
   423   \noindent 
   424   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 
   425   on which the permutation 
   425   over which the permutation 
   426   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"},
   427   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"}}, 
   428   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
   429   operation is defined for products, lists, sets, functions, booleans etc (see \cite{HuffmanUrban10})
   429   operation is defined by induction over the type-hierarchy, for example as follows 
   430   
   430   for products, lists, sets, functions and booleans (see \cite{HuffmanUrban10}):
   431   \begin{center}
   431   
   432   \begin{tabular}{@ {}cc@ {}}
   432   \begin{equation}
       
   433   \mbox{\begin{tabular}{@ {}cc@ {}}
   433   \begin{tabular}{@ {}l@ {}}
   434   \begin{tabular}{@ {}l@ {}}
   434   @{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
   435   @{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(1)[no_vars, THEN eq_reflection]}\\
   436   @{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
   437   @{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
   437   \end{tabular} &
   438   \end{tabular} &
   438   \begin{tabular}{@ {}l@ {}}
   439   \begin{tabular}{@ {}l@ {}}
   439   @{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
   440   @{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
   440   @{text "p \<bullet> (f x) \<equiv> (p \<bullet> f) (p \<bullet> x)"}\\
   441   @{text "p \<bullet> f \<equiv> \<lambda>x. p \<bullet> (f (- p \<bullet> x))"}\\
   441   @{thm permute_bool_def[no_vars, THEN eq_reflection]}\\
   442   @{thm permute_bool_def[no_vars, THEN eq_reflection]}\\
   442   \end{tabular}
   443   \end{tabular}
   443   \end{tabular}
   444   \end{tabular}}
   444   \end{center}
   445   \end{equation}
   445 
   446 
   446   \noindent
   447   \noindent
   447   Concrete  permutations are build up from 
   448   Concrete permutations are build up from swappings, written as @{text "(a
   448   swappings, written as @{text "(a b)"},
   449   b)"}, which are permutations that behave as follows:
   449   which are permutations that behave as follows:
       
   450   %
   450   %
   451   @{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"}
   452   
   452   
   453   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
   454   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
   491   @{term "supp b"} & = & @{term "{}"}
   491   @{term "supp b"} & = & @{term "{}"}
   492   \end{eqnarray}
   492   \end{eqnarray}
   493   
   493   
   494   \noindent 
   494   \noindent 
   495   it can sometimes be difficult to establish the support precisely,
   495   it can sometimes be difficult to establish the support precisely,
   496   and only give an over approximation (see functions above). This
   496   and only give an approximation (see functions above). Such approximations can 
   497   over approximation can be formalised with the notions \emph{supports},
   497   be formalised with the notion \emph{supports}, defined as follows.
   498   defined as follows.
       
   499 
   498 
   500   \begin{defn}
   499   \begin{defn}
   501   A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b}
   500   A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b}
   502   not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
   501   not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
   503   \end{defn}
   502   \end{defn}
   504 
   503 
   505   \noindent
   504   \noindent
   506   The point of this definitions is that we can show:
   505   The point of this definition is that we can show:
   507 
   506 
   508   \begin{property}
   507   \begin{property}
   509   {\it i)} @{thm[mode=IfThen] supp_is_subset[no_vars]} 
   508   {\it i)} @{thm[mode=IfThen] supp_is_subset[no_vars]} 
   510   {\it ii)} @{thm supp_supports[no_vars]}.
   509   {\it ii)} @{thm supp_supports[no_vars]}.
   511   \end{property}
   510   \end{property}
   512 
   511 
   513   \noindent
   512   \noindent
   514   Another important notion in the nominal logic work is \emph{equivariance}.
   513   Another important notion in the nominal logic work is \emph{equivariance}.
       
   514   For a function @{text f}, lets say of type @{text "\<alpha> \<Rightarrow> \<beta>"}, to be equivariant 
       
   515   means that every permutation leaves @{text f} unchanged, or equivalently that
       
   516   a permutation applied to an application @{text "f x"} can be moved to its 
       
   517   arguments. That is
       
   518 
       
   519   \begin{center}
       
   520   @{text "\<forall>p. p \<bullet> f = f"} \hspace{5mm}
       
   521   @{text "\<forall>p. p \<bullet> (f x) = f (p \<bullet> x)"}
       
   522   \end{center}
       
   523  
       
   524   \noindent
       
   525   From the first equation we can be easily deduce that an equivariant function has
       
   526   empty support.
   515 
   527 
   516   %\begin{property}
   528   %\begin{property}
   517   %@{thm[mode=IfThen] at_set_avoiding[no_vars]}
   529   %@{thm[mode=IfThen] at_set_avoiding[no_vars]}
   518   %\end{property}
   530   %\end{property}
   519 
   531