83 mechanisms for binding single variables have not fared extremely well with the |
83 mechanisms for binding single variables have not fared extremely well with the |
84 more advanced tasks in the POPLmark challenge \cite{challenge05}, because |
84 more advanced tasks in the POPLmark challenge \cite{challenge05}, because |
85 also there one would like to bind multiple variables at once. |
85 also there one would like to bind multiple variables at once. |
86 |
86 |
87 Binding multiple variables has interesting properties that cannot be captured |
87 Binding multiple variables has interesting properties that cannot be captured |
88 easily by iterating single binders. For example in case of type-schemes we do not |
88 easily by iterating single binders. For example in the case of type-schemes we do not |
89 want to make a distinction about the order of the bound variables. Therefore |
89 want to make a distinction about the order of the bound variables. Therefore |
90 we would like to regard the following two type-schemes as alpha-equivalent |
90 we would like to regard the following two type-schemes as alpha-equivalent |
91 % |
91 % |
92 \begin{equation}\label{ex1} |
92 \begin{equation}\label{ex1} |
93 @{text "\<forall>{x, y}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{y, x}. y \<rightarrow> x"} |
93 @{text "\<forall>{x, y}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{y, x}. y \<rightarrow> x"} |
181 |
181 |
182 \noindent |
182 \noindent |
183 where the notation @{text "[_]._"} indicates that the list of @{text "x\<^isub>i"} |
183 where the notation @{text "[_]._"} indicates that the list of @{text "x\<^isub>i"} |
184 becomes bound in @{text s}. In this representation the term |
184 becomes bound in @{text s}. In this representation the term |
185 \mbox{@{text "\<LET> [x].s [t\<^isub>1, t\<^isub>2]"}} is a perfectly legal |
185 \mbox{@{text "\<LET> [x].s [t\<^isub>1, t\<^isub>2]"}} is a perfectly legal |
186 instance, but the lengths of two lists do not agree. To exclude such terms, |
186 instance, but the lengths of the two lists do not agree. To exclude such terms, |
187 additional predicates about well-formed |
187 additional predicates about well-formed |
188 terms are needed in order to ensure that the two lists are of equal |
188 terms are needed in order to ensure that the two lists are of equal |
189 length. This can result into very messy reasoning (see for |
189 length. This can result in very messy reasoning (see for |
190 example~\cite{BengtsonParow09}). To avoid this, we will allow type |
190 example~\cite{BengtsonParow09}). To avoid this, we will allow type |
191 specifications for $\mathtt{let}$s as follows |
191 specifications for $\mathtt{let}$s as follows |
192 % |
192 % |
193 \begin{center} |
193 \begin{center} |
194 \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l} |
194 \begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l} |
218 clause states to bind in @{text s} all the names the function @{text |
218 clause states to bind in @{text s} all the names the function @{text |
219 "bn(as)"} returns. This style of specifying terms and bindings is heavily |
219 "bn(as)"} returns. This style of specifying terms and bindings is heavily |
220 inspired by the syntax of the Ott-tool \cite{ott-jfp}. |
220 inspired by the syntax of the Ott-tool \cite{ott-jfp}. |
221 |
221 |
222 However, we will not be able to cope with all specifications that are |
222 However, we will not be able to cope with all specifications that are |
223 allowed by Ott. One reason is that Ott lets the user to specify ``empty'' |
223 allowed by Ott. One reason is that Ott lets the user specify ``empty'' |
224 types like |
224 types like |
225 |
225 |
226 \begin{center} |
226 \begin{center} |
227 @{text "t ::= t t | \<lambda>x. t"} |
227 @{text "t ::= t t | \<lambda>x. t"} |
228 \end{center} |
228 \end{center} |
554 @{text "p \<bullet> (f x) = f (p \<bullet> x)"} |
554 @{text "p \<bullet> (f x) = f (p \<bullet> x)"} |
555 \end{equation} |
555 \end{equation} |
556 |
556 |
557 \noindent |
557 \noindent |
558 From property \eqref{equivariancedef} and the definition of @{text supp}, we |
558 From property \eqref{equivariancedef} and the definition of @{text supp}, we |
559 can be easily deduce that equivariant functions have empty support. There is |
559 can easily deduce that equivariant functions have empty support. There is |
560 also a similar notion for equivariant relations, say @{text R}, namely the property |
560 also a similar notion for equivariant relations, say @{text R}, namely the property |
561 that |
561 that |
562 % |
562 % |
563 \begin{center} |
563 \begin{center} |
564 @{text "x R y"} \;\;implies\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"} |
564 @{text "x R y"} \;\;implies\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"} |
591 fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders |
591 fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders |
592 @{text as} in @{text x}, because @{term "p \<bullet> x = x"}. |
592 @{text as} in @{text x}, because @{term "p \<bullet> x = x"}. |
593 |
593 |
594 Most properties given in this section are described in detail in \cite{HuffmanUrban10} |
594 Most properties given in this section are described in detail in \cite{HuffmanUrban10} |
595 and of course all are formalised in Isabelle/HOL. In the next sections we will make |
595 and of course all are formalised in Isabelle/HOL. In the next sections we will make |
596 extensively use of these properties in order to define alpha-equivalence in |
596 extensive use of these properties in order to define alpha-equivalence in |
597 the presence of multiple binders. |
597 the presence of multiple binders. |
598 *} |
598 *} |
599 |
599 |
600 |
600 |
601 section {* General Binders\label{sec:binders} *} |
601 section {* General Binders\label{sec:binders} *} |
621 given a free-variable function @{text "fv"} of type \mbox{@{text "\<beta> \<Rightarrow> atom |
621 given a free-variable function @{text "fv"} of type \mbox{@{text "\<beta> \<Rightarrow> atom |
622 set"}}, then @{text x} and @{text y} need to have the same set of free |
622 set"}}, then @{text x} and @{text y} need to have the same set of free |
623 variables; moreover there must be a permutation @{text p} such that {\it |
623 variables; moreover there must be a permutation @{text p} such that {\it |
624 ii)} @{text p} leaves the free variables of @{text x} and @{text y} unchanged, but |
624 ii)} @{text p} leaves the free variables of @{text x} and @{text y} unchanged, but |
625 {\it iii)} ``moves'' their bound names so that we obtain modulo a relation, |
625 {\it iii)} ``moves'' their bound names so that we obtain modulo a relation, |
626 say \mbox{@{text "_ R _"}}, two equivalent terms. We also require {\it iv)} that |
626 say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it iv)} |
627 @{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The |
627 @{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The |
628 requirements {\it i)} to {\it iv)} can be stated formally as follows: |
628 requirements {\it i)} to {\it iv)} can be stated formally as follows: |
629 % |
629 % |
630 \begin{equation}\label{alphaset} |
630 \begin{equation}\label{alphaset} |
631 \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l} |
631 \begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l} |
636 @{text "\<and>"} & @{term "(p \<bullet> as) = bs"}\\ |
636 @{text "\<and>"} & @{term "(p \<bullet> as) = bs"}\\ |
637 \end{array} |
637 \end{array} |
638 \end{equation} |
638 \end{equation} |
639 |
639 |
640 \noindent |
640 \noindent |
641 Note that this relation is dependent on the permutation @{text |
641 Note that this relation depends on the permutation @{text |
642 "p"}. Alpha-equivalence between two pairs is then the relation where we |
642 "p"}. Alpha-equivalence between two pairs is then the relation where we |
643 existentially quantify over this @{text "p"}. Also note that the relation is |
643 existentially quantify over this @{text "p"}. Also note that the relation is |
644 dependent on a free-variable function @{text "fv"} and a relation @{text |
644 dependent on a free-variable function @{text "fv"} and a relation @{text |
645 "R"}. The reason for this extra generality is that we will use |
645 "R"}. The reason for this extra generality is that we will use |
646 $\approx_{\textit{set}}$ for both ``raw'' terms and alpha-equated terms. In |
646 $\approx_{\textit{set}}$ for both ``raw'' terms and alpha-equated terms. In |
690 \end{center} |
690 \end{center} |
691 |
691 |
692 \noindent |
692 \noindent |
693 Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and |
693 Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and |
694 \eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and |
694 \eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and |
695 @{text "({y, x}, y \<rightarrow> x)"} are alpha-equivalent according to $\approx_{\textit{set}}$ and |
695 @{text "({y, x}, y \<rightarrow> x)"} are alpha-equivalent according to |
696 $\approx_{\textit{res}}$ by taking @{text p} to be the swapping @{term "(x \<rightleftharpoons> |
696 $\approx_{\textit{set}}$ and $\approx_{\textit{res}}$ by taking @{text p} to |
697 y)"}. In case of @{text "x \<noteq> y"}, then @{text "([x, y], x \<rightarrow> y)"} |
697 be the swapping @{term "(x \<rightleftharpoons> y)"}. In case of @{text "x \<noteq> y"}, then @{text |
698 $\not\approx_{\textit{list}}$ @{text "([y, x], x \<rightarrow> y)"} since there is no permutation |
698 "([x, y], x \<rightarrow> y)"} $\not\approx_{\textit{list}}$ @{text "([y, x], x \<rightarrow> y)"} |
699 that makes the lists @{text "[x, y]"} and @{text "[y, x]"} equal, and also |
699 since there is no permutation that makes the lists @{text "[x, y]"} and |
700 leaves the type \mbox{@{text "x \<rightarrow> y"}} unchanged. Another example is |
700 @{text "[y, x]"} equal, and also leaves the type \mbox{@{text "x \<rightarrow> y"}} |
701 @{text "({x}, x)"} $\approx_{\textit{res}}$ @{text "({x, y}, x)"} which holds by |
701 unchanged. Another example is @{text "({x}, x)"} $\approx_{\textit{res}}$ |
702 taking @{text p} to be the |
702 @{text "({x, y}, x)"} which holds by taking @{text p} to be the identity |
703 identity permutation. However, if @{text "x \<noteq> y"}, then @{text "({x}, x)"} |
703 permutation. However, if @{text "x \<noteq> y"}, then @{text "({x}, x)"} |
704 $\not\approx_{\textit{set}}$ @{text "({x, y}, x)"} since there is no permutation |
704 $\not\approx_{\textit{set}}$ @{text "({x, y}, x)"} since there is no |
705 that makes the |
705 permutation that makes the sets @{text "{x}"} and @{text "{x, y}"} equal |
706 sets @{text "{x}"} and @{text "{x, y}"} equal (similarly for $\approx_{\textit{list}}$). |
706 (similarly for $\approx_{\textit{list}}$). It can also relatively easily be |
707 It can also relatively easily be shown that all tree notions of alpha-equivalence |
707 shown that all three notions of alpha-equivalence coincide, if we only |
708 coincide, if we only abstract a single atom. |
708 abstract a single atom. |
709 |
709 |
710 In the rest of this section we are going to introduce three abstraction |
710 In the rest of this section we are going to introduce three abstraction |
711 types. For this we define |
711 types. For this we define |
712 % |
712 % |
713 \begin{equation} |
713 \begin{equation} |
939 Similarly for the other binding modes. Interestingly, in case of \isacommand{bind\_set} |
939 Similarly for the other binding modes. Interestingly, in case of \isacommand{bind\_set} |
940 and \isacommand{bind\_res} the binding clauses will make a difference to the semantics |
940 and \isacommand{bind\_res} the binding clauses will make a difference to the semantics |
941 of the specification (the corresponding alpha-equivalence will differ). We will |
941 of the specification (the corresponding alpha-equivalence will differ). We will |
942 show this later with an example. |
942 show this later with an example. |
943 |
943 |
944 There are some restrictions we need to impose: First, a body can only occur |
944 There are some restrictions we need to impose on binding clasues: First, a |
945 in \emph{one} binding clause of a term constructor. For binders we |
945 body can only occur in \emph{one} binding clause of a term constructor. For |
946 distinguish between \emph{shallow} and \emph{deep} binders. Shallow binders |
946 binders we distinguish between \emph{shallow} and \emph{deep} binders. |
947 are just labels. The restriction we need to impose on them is that in case |
947 Shallow binders are just labels. The restriction we need to impose on them |
948 of \isacommand{bind\_set} and \isacommand{bind\_res} the labels must either |
948 is that in case of \isacommand{bind\_set} and \isacommand{bind\_res} the |
949 refer to atom types or to sets of atom types; in case of \isacommand{bind} |
949 labels must either refer to atom types or to sets of atom types; in case of |
950 the labels must refer to atom types or lists of atom types. Two examples for |
950 \isacommand{bind} the labels must refer to atom types or lists of atom |
951 the use of shallow binders are the specification of lambda-terms, where a |
951 types. Two examples for the use of shallow binders are the specification of |
952 single name is bound, and type-schemes, where a finite set of names is |
952 lambda-terms, where a single name is bound, and type-schemes, where a finite |
953 bound: |
953 set of names is bound: |
954 |
954 |
955 \begin{center} |
955 \begin{center} |
956 \begin{tabular}{@ {}cc@ {}} |
956 \begin{tabular}{@ {}cc@ {}} |
957 \begin{tabular}{@ {}l@ {\hspace{-1mm}}} |
957 \begin{tabular}{@ {}l@ {\hspace{-1mm}}} |
958 \isacommand{nominal\_datatype} @{text lam} =\\ |
958 \isacommand{nominal\_datatype} @{text lam} =\\ |
972 \end{center} |
972 \end{center} |
973 |
973 |
974 \noindent |
974 \noindent |
975 Note that for @{text lam} it does not matter which binding mode we use. The |
975 Note that for @{text lam} it does not matter which binding mode we use. The |
976 reason is that we bind only a single @{text name}. However, having |
976 reason is that we bind only a single @{text name}. However, having |
977 \isacommand{bind\_set} or \isacommand{bind} in the second case makes again a |
977 \isacommand{bind\_set} or \isacommand{bind} in the second case makes a |
978 difference to the semantics of the specification. Note also that in |
978 difference to the semantics of the specification. Note also that in |
979 these specifications @{text "name"} refers to an atom type, and @{text |
979 these specifications @{text "name"} refers to an atom type, and @{text |
980 "fset"} to the type of finite sets. |
980 "fset"} to the type of finite sets. |
981 |
981 |
982 |
982 |
1117 Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just |
1117 Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just |
1118 re-arranging the arguments of |
1118 re-arranging the arguments of |
1119 term-constructors so that binders and their bodies are next to each other will |
1119 term-constructors so that binders and their bodies are next to each other will |
1120 result in inadequate representations. Therefore we will first |
1120 result in inadequate representations. Therefore we will first |
1121 extract datatype definitions from the specification and then define |
1121 extract datatype definitions from the specification and then define |
1122 expicitly an alpha-equivalence relation over them. |
1122 explicitly an alpha-equivalence relation over them. |
1123 |
1123 |
1124 |
1124 |
1125 The datatype definition can be obtained by stripping off the |
1125 The datatype definition can be obtained by stripping off the |
1126 binding clauses and the labels from the types. We also have to invent |
1126 binding clauses and the labels from the types. We also have to invent |
1127 new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"} |
1127 new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"} |
1150 % |
1150 % |
1151 \begin{equation}\label{ceqvt} |
1151 \begin{equation}\label{ceqvt} |
1152 @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"} |
1152 @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"} |
1153 \end{equation} |
1153 \end{equation} |
1154 |
1154 |
1155 The first non-trivial step we have to perform is the generation free-variable |
1155 The first non-trivial step we have to perform is the generation of free-variable |
1156 functions from the specifications. For atomic types we define the auxilary |
1156 functions from the specifications. For atomic types we define the auxilary |
1157 free variable functions: |
1157 free variable functions: |
1158 |
1158 |
1159 \begin{center} |
1159 \begin{center} |
1160 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1160 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1538 \noindent |
1538 \noindent |
1539 where the @{text "x\<^isub>i, \<dots>, x\<^isub>j"} are the recursive arguments of @{text "C\<^sup>\<alpha>"}. |
1539 where the @{text "x\<^isub>i, \<dots>, x\<^isub>j"} are the recursive arguments of @{text "C\<^sup>\<alpha>"}. |
1540 Next we lift the permutation operations defined in \eqref{ceqvt} for |
1540 Next we lift the permutation operations defined in \eqref{ceqvt} for |
1541 the raw term-constructors @{text "C"}. These facts contain, in addition |
1541 the raw term-constructors @{text "C"}. These facts contain, in addition |
1542 to the term-constructors, also permutation operations. In order to make the |
1542 to the term-constructors, also permutation operations. In order to make the |
1543 lifting to go through, |
1543 lifting go through, |
1544 we have to know that the permutation operations are respectful |
1544 we have to know that the permutation operations are respectful |
1545 w.r.t.~alpha-equivalence. This amounts to showing that the |
1545 w.r.t.~alpha-equivalence. This amounts to showing that the |
1546 alpha-equivalence relations are equivariant, which we already established |
1546 alpha-equivalence relations are equivariant, which we already established |
1547 in Lemma~\ref{equiv}. As a result we can establish the equations |
1547 in Lemma~\ref{equiv}. As a result we can establish the equations |
1548 |
1548 |
1565 \end{tabular}} |
1565 \end{tabular}} |
1566 \end{equation} |
1566 \end{equation} |
1567 |
1567 |
1568 \noindent |
1568 \noindent |
1569 which can be established by induction on @{text "\<approx>ty"}. Whereas the first |
1569 which can be established by induction on @{text "\<approx>ty"}. Whereas the first |
1570 property is always true by the way how we defined the free-variable |
1570 property is always true by the way we defined the free-variable |
1571 functions for types, the second and third do \emph{not} hold in general. There is, in principle, |
1571 functions for types, the second and third do \emph{not} hold in general. There is, in principle, |
1572 the possibility that the user defines @{text "bn\<^isub>k"} so that it returns an already bound |
1572 the possibility that the user defines @{text "bn\<^isub>k"} so that it returns an already bound |
1573 variable. Then the third property is just not true. However, our |
1573 variable. Then the third property is just not true. However, our |
1574 restrictions imposed on the binding functions |
1574 restrictions imposed on the binding functions |
1575 exclude this possibility. |
1575 exclude this possibility. |
1892 |
1892 |
1893 Taking now the identity permutation @{text 0} for the permutations in \eqref{hyps}, |
1893 Taking now the identity permutation @{text 0} for the permutations in \eqref{hyps}, |
1894 we can establish our original goals, namely @{text "P\<^bsub>trm\<^esub> c t"} and \mbox{@{text "P\<^bsub>pat\<^esub> c p"}}. |
1894 we can establish our original goals, namely @{text "P\<^bsub>trm\<^esub> c t"} and \mbox{@{text "P\<^bsub>pat\<^esub> c p"}}. |
1895 This completes the proof showing that the strong induction principle derives from |
1895 This completes the proof showing that the strong induction principle derives from |
1896 the weak induction principle. For the moment we can derive the difficult cases of |
1896 the weak induction principle. For the moment we can derive the difficult cases of |
1897 the strong induction principles only by hand, but they are very schematically |
1897 the strong induction principles only by hand, but they are very schematic |
1898 so that with little effort we can even derive them for |
1898 so that with little effort we can even derive them for |
1899 Core-Haskell given in Figure~\ref{nominalcorehas}. |
1899 Core-Haskell given in Figure~\ref{nominalcorehas}. |
1900 *} |
1900 *} |
1901 |
1901 |
1902 |
1902 |