408 Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in |
408 Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in |
409 \cite{HuffmanUrban10} (including proofs). We shall briefly review this work |
409 \cite{HuffmanUrban10} (including proofs). We shall briefly review this work |
410 to aid the description of what follows. |
410 to aid the description of what follows. |
411 |
411 |
412 Two central notions in the nominal logic work are sorted atoms and |
412 Two central notions in the nominal logic work are sorted atoms and |
413 sort-respecting permutations of atoms. We will use the variables @{text "a, |
413 sort-respecting permutations of atoms. We will use the letters @{text "a, |
414 b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for |
414 b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for |
415 permutations. The sorts of atoms can be used to represent different kinds of |
415 permutations. The sorts of atoms can be used to represent different kinds of |
416 variables, such as the term-, coercion- and type-variables in Core-Haskell, |
416 variables, such as the term-, coercion- and type-variables in Core-Haskell. |
417 and it is assumed that there is an infinite supply of atoms for each |
417 It is assumed that there is an infinite supply of atoms for each |
418 sort. However, in order to simplify the description, we shall assume in what |
418 sort. However, in order to simplify the description, we shall restrict ourselves |
419 follows that there is only one sort of atoms. |
419 in what follows to only one sort of atoms. |
420 |
420 |
421 Permutations are bijective functions from atoms to atoms that are |
421 Permutations are bijective functions from atoms to atoms that are |
422 the identity everywhere except on a finite number of atoms. There is a |
422 the identity everywhere except on a finite number of atoms. There is a |
423 two-place permutation operation written |
423 two-place permutation operation written |
424 % |
424 % |
504 @{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"} |
505 @{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"} |
505 \end{eqnarray} |
506 \end{eqnarray} |
506 |
507 |
507 \noindent |
508 \noindent |
508 in some cases it can be difficult to establish the support precisely, and |
509 in some cases it can be difficult to establish the support precisely, and |
509 only give an approximation (see the case for function applications |
510 only give an approximation (see \eqref{suppfun} above). Reasoning about |
510 above). Such approximations can be calculated with the notion |
511 such approximations can be made precise with the notion \emph{supports}, defined |
511 \emph{supports}, defined as follows |
512 as follows: |
512 |
513 |
513 \begin{defn} |
514 \begin{defn} |
514 A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b} |
515 A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b} |
515 not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}. |
516 not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}. |
516 \end{defn} |
517 \end{defn} |
517 |
518 |
518 \noindent |
519 \noindent |
519 The main point of this definition is that we can show the following two properties. |
520 The main point of @{text supports} is that we can establish the following |
|
521 two properties. |
520 |
522 |
521 \begin{property}\label{supportsprop} |
523 \begin{property}\label{supportsprop} |
522 {\it i)} @{thm[mode=IfThen] supp_is_subset[no_vars]}\\ |
524 {\it i)} @{thm[mode=IfThen] supp_is_subset[no_vars]}\\ |
523 {\it ii)} @{thm supp_supports[no_vars]}. |
525 {\it ii)} @{thm supp_supports[no_vars]}. |
524 \end{property} |
526 \end{property} |
525 |
527 |
526 Another important notion in the nominal logic work is \emph{equivariance}. |
528 Another important notion in the nominal logic work is \emph{equivariance}. |
527 For a function @{text f}, say of type @{text "\<alpha> \<Rightarrow> \<beta>"}, to be equivariant |
529 For a function @{text f}, say of type @{text "\<alpha> \<Rightarrow> \<beta>"}, to be equivariant |
528 requires that every permutation leaves @{text f} unchanged, that is |
530 it is required that every permutation leaves @{text f} unchanged, that is |
529 % |
531 % |
530 \begin{equation}\label{equivariancedef} |
532 \begin{equation}\label{equivariancedef} |
531 @{term "\<forall>p. p \<bullet> f = f"} |
533 @{term "\<forall>p. p \<bullet> f = f"} |
532 \end{equation} |
534 \end{equation} |
533 |
535 |
562 @{term "supp x \<sharp>* p"}. |
563 @{term "supp x \<sharp>* p"}. |
563 \end{property} |
564 \end{property} |
564 |
565 |
565 \noindent |
566 \noindent |
566 The idea behind the second property is that given a finite set @{text as} |
567 The idea behind the second property is that given a finite set @{text as} |
567 of binders (being bound in @{text x} which is ensured by the |
568 of binders (being bound, or fresh, in @{text x} is ensured by the |
568 assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text p} such that |
569 assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text p} such that |
569 the renamed binders @{term "p \<bullet> as"} avoid the @{text c} (which can be arbitrarily chosen |
570 the renamed binders @{term "p \<bullet> as"} avoid @{text c} (which can be arbitrarily chosen |
570 as long as it is finitely supported) and also does not affect anything |
571 as long as it is finitely supported) and also it does not affect anything |
571 in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last |
572 in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last |
572 fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders |
573 fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders |
573 in @{text x}, because @{term "p \<bullet> x = x"}. |
574 @{text as} in @{text x}, because @{term "p \<bullet> x = x"}. |
574 |
575 |
575 All properties given in this section are formalised in Isabelle/HOL and also |
576 All properties given in this section are formalised in Isabelle/HOL and also |
576 most of them are described with proofs in \cite{HuffmanUrban10}. In the next |
577 most of proofs are described in \cite{HuffmanUrban10} to which we refer the |
577 sections we will make extensively use of these properties for characterising |
578 reader. In the next sections we will make extensively use of these |
578 alpha-equivalence in the presence of multiple binders. |
579 properties in order to define alpha-equivalence in the presence of multiple |
|
580 binders. |
579 *} |
581 *} |
580 |
582 |
581 |
583 |
582 section {* General Binders\label{sec:binders} *} |
584 section {* General Binders\label{sec:binders} *} |
583 |
585 |
748 |
749 |
749 \noindent |
750 \noindent |
750 This lemma allows us to use our quotient package and introduce |
751 This lemma allows us to use our quotient package and introduce |
751 new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"} |
752 new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"} |
752 representing alpha-equivalence classes of pairs. The elements in these types |
753 representing alpha-equivalence classes of pairs. The elements in these types |
753 we will, respectively, write as: |
754 will be, respectively, written as: |
754 |
755 |
755 \begin{center} |
756 \begin{center} |
756 @{term "Abs as x"} \hspace{5mm} |
757 @{term "Abs as x"} \hspace{5mm} |
757 @{term "Abs_lst as x"} \hspace{5mm} |
758 @{term "Abs_lst as x"} \hspace{5mm} |
758 @{term "Abs_res as x"} |
759 @{term "Abs_res as x"} |
759 \end{center} |
760 \end{center} |
760 |
761 |
761 \noindent |
762 \noindent |
762 indicating that a set or list @{text as} is abstracted in @{text x}. We will |
763 indicating that a set or list @{text as} is abstracted in @{text x}. We will |
763 call the types \emph{abstraction types} and their elements |
764 call the types \emph{abstraction types} and their elements |
764 \emph{abstractions}. The important property we need is a characterisation |
765 \emph{abstractions}. The important property we need to know is what the |
765 for the support of abstractions, namely: |
766 support of abstractions is, namely: |
766 |
767 |
767 \begin{thm}[Support of Abstractions]\label{suppabs} |
768 \begin{thm}[Support of Abstractions]\label{suppabs} |
768 Assuming @{text x} has finite support, then\\[-6mm] |
769 Assuming @{text x} has finite support, then\\[-6mm] |
769 \begin{center} |
770 \begin{center} |
770 \begin{tabular}{l@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
771 \begin{tabular}{l@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
844 \end{equation} |
845 \end{equation} |
845 |
846 |
846 \noindent |
847 \noindent |
847 since for finite sets, @{text "S"}, we have @{thm (concl) supp_finite_atom_set[no_vars]}. |
848 since for finite sets, @{text "S"}, we have @{thm (concl) supp_finite_atom_set[no_vars]}. |
848 |
849 |
849 Finally taking \eqref{halfone} and \eqref{halftwo} together provides us with a proof |
850 Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes of |
850 of Theorem~\ref{suppabs}. The point of these properties of abstractions is that we |
851 Theorem~\ref{suppabs}. This theorem gives us confidence that our |
851 can define and prove them aconveniently on the Isabelle/HOL level, |
852 abstractions behave as one expects. To consider first abstractions of the |
852 but also use them in what follows next when we deal with binding in |
853 form @{term "Abs as x"} is motivated by the fact that properties about them |
853 specifications of term-calculi. |
854 can be conveninetly established at the Isabelle/HOL level. But we can also |
|
855 use when we deal with binding in our term-calculi specifications. |
854 *} |
856 *} |
855 |
857 |
856 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *} |
858 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *} |
857 |
859 |
858 text {* |
860 text {* |
859 Our choice of syntax for specifications of term-calculi is influenced by the existing |
861 Our choice of syntax for specifications is influenced by the existing |
860 datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the Ott-tool |
862 datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the Ott-tool |
861 \cite{ott-jfp}. A specification is a collection of (possibly mutual |
863 \cite{ott-jfp}. For us a specification of a term-calculus is a collection of (possibly mutual |
862 recursive) type declarations, say @{text "ty"}$^\alpha_1$, \ldots, |
864 recursive) type declarations, say @{text "ty"}$^\alpha_1$, \ldots, |
863 @{text ty}$^\alpha_n$, and an associated collection |
865 @{text ty}$^\alpha_n$, and an associated collection |
864 of binding functions, say @{text bn}$^\alpha_1$, \ldots, @{text |
866 of binding functions, say @{text bn}$^\alpha_1$, \ldots, @{text |
865 bn}$^\alpha_m$. The syntax in Nominal Isabelle for such specifications is |
867 bn}$^\alpha_m$. The syntax in Nominal Isabelle for such specifications is |
866 roughly as follows: |
868 roughly as follows: |
997 \end{center} |
999 \end{center} |
998 |
1000 |
999 \noindent |
1001 \noindent |
1000 In this specification the function @{text "bn"} determines which atoms of @{text p} are |
1002 In this specification the function @{text "bn"} determines which atoms of @{text p} are |
1001 bound in the argument @{text "t"}. Note that in the second last clause the function @{text "atom"} |
1003 bound in the argument @{text "t"}. Note that in the second last clause the function @{text "atom"} |
1002 coerces a name into the generic atom type of Nominal Isabelle. This allows |
1004 coerces a name into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This allows |
1003 us to treat binders of different atom type uniformly. |
1005 us to treat binders of different atom type uniformly. |
1004 |
1006 |
1005 As will shortly become clear, we cannot return an atom in a binding function |
1007 As will shortly become clear, we cannot return an atom in a binding function |
1006 that is also bound in the corresponding term-constructor. That means in the |
1008 that is also bound in the corresponding term-constructor. That means in the |
1007 example above that the term-constructors @{text PVar} and @{text PTup} must not have a |
1009 example above that the term-constructors @{text PVar} and @{text PTup} must not have a |
1008 binding clause. In the present version of Nominal Isabelle, we also adopted |
1010 binding clause. In the version of Nominal Isabelle described here, we also adopted |
1009 the restriction from the Ott-tool that binding functions can only return: |
1011 the restriction from the Ott-tool that binding functions can only return: |
1010 the empty set or empty list (as in case @{text PNil}), a singleton set or singleton |
1012 the empty set or empty list (as in case @{text PNil}), a singleton set or singleton |
1011 list containing an atom (case @{text PVar}), or unions of atom sets or appended atom |
1013 list containing an atom (case @{text PVar}), or unions of atom sets or appended atom |
1012 lists (case @{text PTup}). This restriction will simplify proofs later on. |
1014 lists (case @{text PTup}). This restriction will simplify definitions and |
|
1015 proofs later on. |
1013 |
1016 |
1014 The most drastic restriction we have to impose on deep binders is that |
1017 The most drastic restriction we have to impose on deep binders is that |
1015 we cannot have ``overlapping'' deep binders. Consider for example the |
1018 we cannot have ``overlapping'' deep binders. Consider for example the |
1016 term-constructors: |
1019 term-constructors: |
1017 |
1020 |
1093 |
1095 |
1094 |
1096 |
1095 The datatype definition can be obtained by stripping off the |
1097 The datatype definition can be obtained by stripping off the |
1096 binding clauses and the labels on the types. We also have to invent |
1098 binding clauses and the labels on the types. We also have to invent |
1097 new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"} |
1099 new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"} |
1098 given by user. In our implementation we just use an affix @{text "_raw"}. |
1100 given by user. In our implementation we just use the affix @{text "_raw"}. |
1099 For the purpose of the paper we just use the superscript @{text "_\<^sup>\<alpha>"} to indicate |
1101 But for the purpose of this paper, we just use the superscript @{text "_\<^sup>\<alpha>"} to indicate |
1100 that a notion is defined over alpha-equivalence classes and leave it out |
1102 that a notion is defined over alpha-equivalence classes and leave it out |
1101 for the corresponding notion defined on the ``raw'' level. So for example |
1103 for the corresponding notion defined on the ``raw'' level. So for example |
1102 we have |
1104 we have |
1103 |
1105 |
1104 \begin{center} |
1106 \begin{center} |
1105 @{text "ty\<^sup>\<alpha> \<mapsto> ty"} \hspace{2mm}and\hspace{2mm} @{text "C\<^sup>\<alpha> \<mapsto> C"} |
1107 @{text "ty\<^sup>\<alpha> \<mapsto> ty"} \hspace{2mm}and\hspace{2mm} @{text "C\<^sup>\<alpha> \<mapsto> C"} |
1106 \end{center} |
1108 \end{center} |
1107 |
1109 |
1108 \noindent |
1110 \noindent |
1109 |
1111 where the type @{term ty} is the type used in the quotient construction for |
|
1112 @{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}. |
|
1113 |
1110 The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are |
1114 The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are |
1111 non-empty and the types in the constructors only occur in positive |
1115 non-empty and the types in the constructors only occur in positive |
1112 position (see \cite{Berghofer99} for an indepth description of the datatype package |
1116 position (see \cite{Berghofer99} for an indepth description of the datatype package |
1113 in Isabelle/HOL). We then define the user-specified binding |
1117 in Isabelle/HOL). We then define the user-specified binding |
1114 functions, called @{term "bn_ty"}, by primitive recursion over the corresponding |
1118 functions, called @{term "bn_ty"}, by primitive recursion over the corresponding |
1133 \begin{center} |
1137 \begin{center} |
1134 @{text "fv_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set \<dots> fv_ty\<^isub>n :: ty\<^isub>n \<Rightarrow> atom set"} |
1138 @{text "fv_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set \<dots> fv_ty\<^isub>n :: ty\<^isub>n \<Rightarrow> atom set"} |
1135 \end{center} |
1139 \end{center} |
1136 |
1140 |
1137 \noindent |
1141 \noindent |
1138 We define them together with auxiliary free variable functions for |
1142 We define them together with auxiliary free-variable functions for |
1139 the binding functions. Given binding functions |
1143 the binding functions. Given binding functions |
1140 @{text "bn_ty\<^isub>1 \<dots> bn_ty\<^isub>m"} we need to define |
1144 @{text "bn_ty\<^isub>1 \<dots> bn_ty\<^isub>m"} we need to define |
1141 % |
1145 % |
1142 \begin{center} |
1146 \begin{center} |
1143 @{text "fv_bn_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set \<dots> fv_bn_ty\<^isub>m :: ty\<^isub>m \<Rightarrow> atom set"} |
1147 @{text "fv_bn_ty\<^isub>1 :: ty\<^isub>1 \<Rightarrow> atom set \<dots> fv_bn_ty\<^isub>m :: ty\<^isub>m \<Rightarrow> atom set"} |
1144 \end{center} |
1148 \end{center} |
1145 |
1149 |
1146 \noindent |
1150 \noindent |
1147 The reason for this setup is that in a deep binder not all atoms have to be |
1151 The reason for this setup is that in a deep binder not all atoms have to be |
1148 bound. While the idea behind these free variable functions is just to |
1152 bound, as we shall see in an example below. While the idea behind these |
1149 collect all atoms that are not bound, because of the rather complicated |
1153 free-variable functions is clear (they just collect all atoms that are not bound), |
1150 binding mechanisms their definitions are somewhat involved. |
1154 because of the rather complicated binding mechanisms their definitions are |
|
1155 somewhat involved. |
1151 |
1156 |
1152 Given a term-constructor @{text "C"} of type @{text ty} with argument types |
1157 Given a term-constructor @{text "C"} of type @{text ty} with argument types |
1153 \mbox{@{text "ty\<^isub>1 \<dots> ty\<^isub>n"}} and given some binding clauses associated with |
1158 \mbox{@{text "ty\<^isub>1 \<dots> ty\<^isub>n"}}, the function |
1154 this constructor, the function |
|
1155 @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be the union of the values |
1159 @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be the union of the values |
1156 calculated below for each argument. |
1160 calculated next for each argument. |
1157 |
1161 First we deal with the case that @{text "x\<^isub>i"} is a binder. From the binding clauses, |
1158 First we deal with the case @{text "x\<^isub>i"} is a binder. From the binding clauses, |
|
1159 we can determine whether the argument is a shallow or deep |
1162 we can determine whether the argument is a shallow or deep |
1160 binder, and in the latter case also whether it is a recursive or |
1163 binder, and in the latter case also whether it is a recursive or |
1161 non-recursive binder. |
1164 non-recursive binder. |
1162 |
1165 |
1163 \begin{center} |
1166 \begin{center} |
1170 \end{tabular} |
1173 \end{tabular} |
1171 \end{center} |
1174 \end{center} |
1172 |
1175 |
1173 \noindent |
1176 \noindent |
1174 The first clause states that shallow binders do not contribute to the |
1177 The first clause states that shallow binders do not contribute to the |
1175 free variables; in the second clause, we have to look up all |
1178 free variables; in the second clause, we have to collect all |
1176 the free variables that are left unbound by the binding function @{text "bn_ty\<^isub>i"}---this |
1179 variables that are left unbound by the binding function @{text "bn_ty\<^isub>i"}---this |
1177 is done with function @{text "fv_bn_ty\<^isub>i"}; in the third clause, since the |
1180 is done with function @{text "fv_bn_ty\<^isub>i"}; in the third clause, since the |
1178 binder is recursive, we need to bind all variables specified by |
1181 binder is recursive, we need to bind all variables specified by |
1179 @{text "bn_ty\<^isub>i"}---therefore we subtract @{text "bn_ty\<^isub>i x\<^isub>i"} from the free |
1182 @{text "bn_ty\<^isub>i"}---therefore we subtract @{text "bn_ty\<^isub>i x\<^isub>i"} from the free |
1180 variables of @{text "x\<^isub>i"}. |
1183 variables of @{text "x\<^isub>i"}. |
1181 |
1184 |
1182 In case the argument is \emph{not} a binder, we need to consider |
1185 In case the argument is \emph{not} a binder, we need to consider |
1183 whether the @{text "x\<^isub>i"} is the body of one or more binding clauses. |
1186 whether the @{text "x\<^isub>i"} is the body of one or more binding clauses. |
1184 In this case we first calculate the set @{text "bnds"} as follows: |
1187 In this case we first calculate the set @{text "bnds"} as follows: |
1185 either the binders are all shallow or there is a single deep binder. |
1188 either the corresponding binders are all shallow or there is a single deep binder. |
1186 In the former case we take @{text bnds} to be the union of all shallow |
1189 In the former case we take @{text bnds} to be the union of all shallow |
1187 binders; in the latter case, we just take the set of atoms specified by the |
1190 binders; in the latter case, we just take the set of atoms specified by the |
1188 binding function. The value for @{text "x\<^isub>i"} is then given by: |
1191 binding function. The value for @{text "x\<^isub>i"} is then given by: |
1189 |
1192 |
1190 \begin{center} |
1193 \begin{equation}\label{deepbody} |
|
1194 \mbox{% |
1191 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1195 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1192 $\bullet$ & @{text "{atom x\<^isub>i} - bnds"} provided @{term "x\<^isub>i"} is an atom\\ |
1196 $\bullet$ & @{text "{atom x\<^isub>i} - bnds"} provided @{term "x\<^isub>i"} is an atom\\ |
1193 $\bullet$ & @{text "(atoms x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a set of atoms\\ |
1197 $\bullet$ & @{text "(atoms x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a set of atoms\\ |
1194 $\bullet$ & @{text "(atoms (set x\<^isub>i)) - bnds"} provided @{term "x\<^isub>i"} is a list of atoms\\ |
1198 $\bullet$ & @{text "(atoms (set x\<^isub>i)) - bnds"} provided @{term "x\<^isub>i"} is a list of atoms\\ |
1195 $\bullet$ & @{text "(fv_ty\<^isub>i x\<^isub>i) - bnds"} provided @{term "ty\<^isub>i"} is one of the raw datatypes |
1199 $\bullet$ & @{text "(fv_ty\<^isub>i x\<^isub>i) - bnds"} provided @{term "ty\<^isub>i"} is one of the raw datatypes |
1196 corresponding to the types specified by the user\\ |
1200 corresponding to the types specified by the user\\ |
1197 % $\bullet$ & @{text "(fv\<^isup>\<alpha> x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a defined nominal datatype |
1201 % $\bullet$ & @{text "(fv\<^isup>\<alpha> x\<^isub>i) - bnds"} provided @{term "x\<^isub>i"} is a defined nominal datatype |
1198 % with a free variable function @{text "fv\<^isup>\<alpha>"}\\ |
1202 % with a free-variable function @{text "fv\<^isup>\<alpha>"}\\ |
1199 $\bullet$ & @{term "{}"} otherwise |
1203 $\bullet$ & @{term "{}"} otherwise |
1200 \end{tabular} |
1204 \end{tabular}} |
1201 \end{center} |
1205 \end{equation} |
1202 |
1206 |
1203 \noindent |
1207 \noindent |
1204 Like the function @{text atom}, @{text "atoms"} coerces a set of atoms to the generic atom type. |
1208 Like the coercion function @{text atom} used above, @{text "atoms as"} coerces |
|
1209 the set @{text as} to the generic atom type. |
1205 It is defined as @{text "atom as \<equiv> {atom a | a \<in> as}"}. |
1210 It is defined as @{text "atom as \<equiv> {atom a | a \<in> as}"}. |
1206 |
1211 |
1207 The last case we need to consider is when @{text "x\<^isub>i"} is neither |
1212 The last case we need to consider is when @{text "x\<^isub>i"} is neither |
1208 a binder nor a body of an abstraction. In this case it is defined |
1213 a binder nor a body of an abstraction. In this case it is defined |
1209 as above, except that we do not subtract the set @{text bnds}. |
1214 as in \eqref{deepbody}, except that we do not need to subtract the |
1210 |
1215 set @{text bnds}. |
1211 Next, we need to define a free variable function @{text "fv_bn_ty\<^isub>i"} for |
1216 |
|
1217 Next, we need to define a free-variable function @{text "fv_bn_ty\<^isub>i"} for |
1212 each binding function @{text "bn_ty\<^isub>i"}. The idea behind this |
1218 each binding function @{text "bn_ty\<^isub>i"}. The idea behind this |
1213 function is to compute the set of free atoms that are not bound by |
1219 function is to compute the set of free atoms that are not bound by |
1214 the binding function. Because of the restrictions we imposed on the |
1220 @{text "bn_ty\<^isub>i"}. Because of the restrictions we imposed on the |
1215 form of binding functions, this can be done automatically by recursively |
1221 form of binding functions, this can be done automatically by recursively |
1216 building up the the set of free variables from the arguments that are |
1222 building up the the set of free variables from the arguments that are |
1217 not bound. Let us assume one clause of the binding function is |
1223 not bound. Let us assume one clause of the binding function is |
1218 @{text "bn_ty\<^isub>i (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}, then @{text "fv_bn_ty\<^isub>i"} is the |
1224 @{text "bn_ty\<^isub>i (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}, then @{text "fv_bn_ty\<^isub>i"} is the |
1219 union of the values calculated for @{text "x\<^isub>j"} of type @{text "ty\<^isub>j"} |
1225 union of the values calculated for @{text "x\<^isub>j"} of type @{text "ty\<^isub>j"} |
1220 as follows: |
1226 as follows: |
1221 |
1227 |
1222 \begin{center} |
1228 \begin{center} |
1223 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1229 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1224 \multicolumn{2}{l}{@{text "x\<^isub>j"} occurs in @{text "rhs"}:}\\ |
1230 \multicolumn{2}{l}{@{text "x\<^isub>j"} occurs in @{text "rhs"}:}\\ |
1225 $\bullet$ & @{term "{}"} provided @{term "x\<^isub>j"} is an atom, |
1231 $\bullet$ & @{term "{}"} provided @{term "x\<^isub>j"} is a single atom, |
1226 atom list or atom set\\ |
1232 atom list or atom set\\ |
1227 $\bullet$ & @{text "fv_bn_ty\<^isub>j x\<^isub>j"} in case @{text "rhs"} contains the |
1233 $\bullet$ & @{text "fv_bn_ty\<^isub>j x\<^isub>j"} in case @{text "rhs"} contains the |
1228 recursive call @{text "bn_ty\<^isub>j x\<^isub>j"}\\[1mm] |
1234 recursive call @{text "bn_ty\<^isub>j x\<^isub>j"}\\[1mm] |
1229 % |
1235 % |
1230 \multicolumn{2}{l}{@{text "x\<^isub>j"} does not occur in @{text "rhs"}:}\\ |
1236 \multicolumn{2}{l}{@{text "x\<^isub>j"} does not occur in @{text "rhs"}:}\\ |
1231 $\bullet$ & @{text "atoms x\<^isub>j"} provided @{term "x\<^isub>j"} is a set of atoms\\ |
1237 $\bullet$ & @{text "atoms x\<^isub>j"} provided @{term "x\<^isub>j"} is a set of atoms\\ |
1232 $\bullet$ & @{term "atoms (set x\<^isub>j)"} provided @{term "x\<^isub>j"} is a list of atoms\\ |
1238 $\bullet$ & @{term "atoms (set x\<^isub>j)"} provided @{term "x\<^isub>j"} is a list of atoms\\ |
1233 $\bullet$ & @{text "fv_ty\<^isub>j x\<^isub>j"} provided @{term "ty\<^isub>j"} is one of the raw |
1239 $\bullet$ & @{text "fv_ty\<^isub>j x\<^isub>j"} provided @{term "ty\<^isub>j"} is one of the raw |
1234 types corresponding to the types specified by the user\\ |
1240 types corresponding to the types specified by the user\\ |
1235 % $\bullet$ & @{text "fv_ty\<^isup>\<alpha> x\<^isub>j - bnds"} provided @{term "x\<^isub>j"} is not in @{text "rhs"} |
1241 % $\bullet$ & @{text "fv_ty\<^isup>\<alpha> x\<^isub>j - bnds"} provided @{term "x\<^isub>j"} is not in @{text "rhs"} |
1236 % and is an existing nominal datatype with the free variable function @{text "fv\<^isup>\<alpha>"}\\ |
1242 % and is an existing nominal datatype with the free-variable function @{text "fv\<^isup>\<alpha>"}\\ |
1237 $\bullet$ & @{term "{}"} otherwise |
1243 $\bullet$ & @{term "{}"} otherwise |
1238 \end{tabular} |
1244 \end{tabular} |
1239 \end{center} |
1245 \end{center} |
1240 |
1246 |
1241 \noindent |
1247 \noindent |
1242 To see how these definitions work, let us consider the term-constructors |
1248 To see how these definitions work, let us consider again the term-constructors |
1243 for @{text "Let"} and @{text "Let_rec"} from example shown in \eqref{letrecs}. |
1249 @{text "Let"} and @{text "Let_rec"} from example shown in \eqref{letrecs}. |
1244 For this specification we need to define three functions, namely |
1250 For this specification we need to define three functions, namely |
1245 @{text "fv\<^bsub>trm\<^esub>"}, @{text "fv\<^bsub>assn\<^esub>"} and @{text "fv\<^bsub>bn\<^esub>"}. |
1251 @{text "fv\<^bsub>trm\<^esub>"}, @{text "fv\<^bsub>assn\<^esub>"} and @{text "fv\<^bsub>bn\<^esub>"}. They are as follows: |
1246 % |
1252 % |
1247 \begin{center} |
1253 \begin{center} |
1248 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
1254 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
1249 @{text "fv\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "fv\<^bsub>bn\<^esub> as \<union> (fv\<^bsub>trm\<^esub> t - set (bn as))"}\\ |
1255 @{text "fv\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "fv\<^bsub>bn\<^esub> as \<union> (fv\<^bsub>trm\<^esub> t - set (bn as))"}\\ |
1250 @{text "fv\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} &\\ |
1256 @{text "fv\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} &\\ |
1260 |
1266 |
1261 \noindent |
1267 \noindent |
1262 Since there are no binding clauses for the term-constructors @{text ANil} |
1268 Since there are no binding clauses for the term-constructors @{text ANil} |
1263 and @{text "ACons"}, the corresponding free-variable function @{text |
1269 and @{text "ACons"}, the corresponding free-variable function @{text |
1264 "fv\<^bsub>assn\<^esub>"} returns all atoms occuring in an assignment. The |
1270 "fv\<^bsub>assn\<^esub>"} returns all atoms occuring in an assignment. The |
1265 binding happens in @{text Let} and @{text "Let_rec"}. In the first clause we |
1271 binding only takes place in @{text Let} and @{text "Let_rec"}. In the @{text |
1266 want to bind all atoms given by @{text "set (bn as)"} in @{text |
1272 "Let"}-clause we want to bind all atoms given by @{text "set (bn as)"} in |
1267 t}. Therefore we have to subtract @{text "set (bn as)"} from @{text |
1273 @{text t}. Therefore we have to subtract @{text "set (bn as)"} from @{text |
1268 "fv\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are |
1274 "fv\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are |
1269 free in @{text "as"}. This is what the purpose of the function @{text |
1275 free in @{text "as"}. This is what the purpose of the function @{text |
1270 "fv\<^bsub>bn\<^esub>"} is. In contrast, in @{text "Let_rec"} we have a |
1276 "fv\<^bsub>bn\<^esub>"} is. In contrast, in @{text "Let_rec"} we have a |
1271 recursive binder where we want to also bind all occurences of atoms inside |
1277 recursive binder where we want to also bind all occurences of the atoms |
1272 @{text "as"}. Therefore we have to subtract @{text "set (bn as)"} from |
1278 @{text "bn as"} inside @{text "as"}. Therefore we have to subtract @{text |
1273 @{text "fv\<^bsub>assn\<^esub> as"}. Similarly for @{text |
1279 "set (bn as)"} from @{text "fv\<^bsub>assn\<^esub> as"}, as well as from |
1274 "fv\<^bsub>trm\<^esub> t - bn as"}. An interesting point in this example is |
1280 @{text "fv\<^bsub>trm\<^esub> t"}. An interesting point in this example is |
1275 that an assignment ``alone'' does not have any bound variables. Only in the |
1281 that an assignment ``alone'' does not have any bound variables. Only in the |
1276 context of a @{text Let} pr @{text "Let_rec"} will some atoms occuring in an |
1282 context of a @{text Let} or @{text "Let_rec"} will some atoms become bound |
1277 assignment become bound. This is a phenomenon that has also been pointed out |
1283 (teh term-constructors that have binding clauses). This is a phenomenon |
1278 in \cite{ott-jfp}. |
1284 that has also been pointed out in \cite{ott-jfp}. |
1279 |
1285 |
1280 We then define the alpha equivalence relations. For the types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"} |
1286 Next we define alpha-equivalence realtions for the types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"}. We call them |
1281 we need to define |
1287 @{text "\<approx>ty\<^isub>1 \<dots> \<approx>ty\<^isub>n"}. Like with the free-variable functions, |
1282 |
1288 we also need to define auxiliary alpha-equivalence relations for the binding functions. |
1283 \begin{center} |
1289 Say we have @{text "bn_ty\<^isub>1 \<dots> bn_ty\<^isub>m"}, we also define @{text "\<approx>bn_ty\<^isub>1 \<dots> \<approx>bn_ty\<^isub>n"}. |
1284 @{text "\<approx>\<^isub>1 :: ty\<^isub>1 \<Rightarrow> ty\<^isub>1 \<Rightarrow> bool \<dots> \<approx>\<^isub>n :: ty\<^isub>n \<Rightarrow> ty\<^isub>n \<Rightarrow> bool"} |
1290 |
1285 \end{center} |
1291 The relations are inductively defined predicates, whose clauses have |
1286 |
1292 conclusions of the form @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>ty C y\<^isub>1 \<dots> y\<^isub>n"} (let us assume |
1287 \noindent |
1293 @{text C} is of type @{text ty} and its arguments are specified as @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}). |
1288 together with the auxiliary equivalences for binding functions. Given binding |
1294 The task is to specify what the premises of these clauses are. For this we |
1289 functions for types @{text "bn\<^isub>1 :: ty\<^isub>i\<^isub>1 \<Rightarrow> \<dots> \<dots> bn\<^isub>m :: ty\<^isub>i\<^isub>m \<Rightarrow> \<dots>"} we need to define |
1295 consider the pairs @{text "(x\<^isub>i, y\<^isub>i)"} which necesarily must have the same type, say |
1290 \begin{center} |
1296 @{text "ty\<^isub>i"}. For each of these pairs we calculate a premise as follows. |
1291 @{text "\<approx>bn\<^isub>1 :: ty\<^isub>i\<^isub>1 \<Rightarrow> ty\<^isub>i\<^isub>1 \<Rightarrow> bool \<dots> \<approx>bn\<^isub>n :: ty\<^isub>i\<^isub>m \<Rightarrow> ty\<^isub>i\<^isub>m \<Rightarrow> bool"} |
1297 |
1292 \end{center} |
1298 \begin{center} |
1293 |
1299 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1294 Given a term-constructor @{text "C ty\<^isub>1 \<dots> ty\<^isub>n"}, of a type @{text ty}, two instances |
1300 \multicolumn{2}{l}{@{text "x\<^isub>i"} is a binder:}\\ |
|
1301 $\bullet$ & @{text "True"} provided @{text "x\<^isub>i"} is a shallow binder\\ |
|
1302 $\bullet$ & @{text "x\<^isub>i \<approx>bn_ty\<^isub>i y\<^isub>i"} provided @{text "x\<^isub>i"} is a deep |
|
1303 non-recursive binder\\ |
|
1304 $\bullet$ & @{text "True"} provided @{text "x\<^isub>i"} is a deep |
|
1305 recursive binder\\ |
|
1306 \end{tabular} |
|
1307 \end{center} |
|
1308 |
|
1309 TODO BELOW |
|
1310 |
|
1311 \begin{center} |
|
1312 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
|
1313 \multicolumn{2}{l}{@{text "x\<^isub>i"} is a body where the binding clause has mode \isacommand{bind}:}\\ |
|
1314 $\bullet$ & @{text "\<exists>p. (bnds_x\<^isub>i, x\<^isub>i) \<approx>lst (\<approx>ty\<^isub>i) fv_ty\<^isub>i p (bnds_y\<^isub>i, y\<^isub>j)"} |
|
1315 provided @{text "x\<^isub>i"} has only shallow binders; in this case @{text "bnds_x\<^isub>i"} is the |
|
1316 union of all these shallow binders (similarly for @{text "bnds_y\<^isub>i"}\\ |
|
1317 $\bullet$ & @{text "\<exists>p. (bn_ty\<^isub>j x\<^isub>j, x\<^isub>i) \<approx>lst (\<approx>ty\<^isub>i) fv_ty\<^isub>i p (bn_ty y\<^isub>j, y\<^isub>i)"} |
|
1318 provided @{text "x\<^isub>i"} is a body with a deep non-recursive binder @{text x\<^isub>j} |
|
1319 (similarly @{text "y\<^isub>j"} is the deep non-recursive binder for @{text "y\<^isub>i"})\\ |
|
1320 $\bullet$ & @{text "\<exists>p (bn_ty\<^isub>i x\<^isub>i, (x\<^isub>j, x\<^isub>n)) \<approx>lst R fvs \<pi> (bn\<^isub>m y\<^isub>j, (y\<^isub>j, y\<^isub>n))"} |
|
1321 provided @{text "x\<^isub>j"} is a deep recursive binder with the auxiliary binding |
|
1322 function @{text "bn\<^isub>m"} and permutation @{text "\<pi>"}, @{term "fvs"} is a compound |
|
1323 free variable function returning the union of appropriate @{term "fv_ty\<^isub>x"} and |
|
1324 @{term "R"} is the composition of equivalence relations @{text "\<approx>"} and @{text "\<approx>\<^isub>n"}\\ |
|
1325 $\bullet$ & @{text "x\<^isub>j"} has a deep recursive binding\\ |
|
1326 $\bullet$ & @{text "({x\<^isub>n}, x\<^isub>j) \<approx>gen R fv_ty \<pi> ({y\<^isub>n}, y\<^isub>j)"} provided @{text "x\<^isub>j"} has |
|
1327 a shallow binder @{text "x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the |
|
1328 alpha-equivalence for @{term "x\<^isub>j"} |
|
1329 and @{term "fv_ty"} is the free-variable function for @{term "x\<^isub>j"}\\ |
|
1330 $\bullet$ & @{text "(bn\<^isub>m x\<^isub>n, x\<^isub>j) \<approx>gen R fv_ty \<pi> (bn\<^isub>m y\<^isub>n, y\<^isub>j)"} provided @{text "x\<^isub>j"} |
|
1331 has a deep non-recursive binder @{text "bn\<^isub>m x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the |
|
1332 alpha-equivalence for @{term "x\<^isub>j"} |
|
1333 and @{term "fv_ty"} is the free-variable function for @{term "x\<^isub>j"}\\ |
|
1334 $\bullet$ & @{text "x\<^isub>j \<approx>\<^isub>j y\<^isub>j"} provided @{term "x\<^isub>j"} is one of the types being |
|
1335 defined\\ |
|
1336 $\bullet$ & @{text "x\<^isub>j = y\<^isub>j"} otherwise\\ |
|
1337 \end{tabular} |
|
1338 \end{center} |
|
1339 |
|
1340 , of a type @{text ty}, two instances |
1295 of this constructor are alpha-equivalent @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx> C y\<^isub>1 \<dots> y\<^isub>n"} if there |
1341 of this constructor are alpha-equivalent @{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx> C y\<^isub>1 \<dots> y\<^isub>n"} if there |
1296 exist permutations @{text "\<pi>\<^isub>1 \<dots> \<pi>\<^isub>p"} (one for each bound argument) such that |
1342 exist permutations @{text "\<pi>\<^isub>1 \<dots> \<pi>\<^isub>p"} (one for each bound argument) such that |
1297 the conjunction of equivalences defined below for each argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} holds. |
1343 the conjunction of equivalences defined below for each argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} holds. |
1298 For an argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} this holds if: |
1344 For an argument pair @{text "x\<^isub>j"}, @{text "y\<^isub>j"} this holds if: |
1299 |
1345 |
1300 \begin{center} |
1346 |
1301 \begin{tabular}{cp{7cm}} |
|
1302 $\bullet$ & @{text "x\<^isub>j"} is a shallow binder\\ |
|
1303 $\bullet$ & @{text "x\<^isub>j \<approx>bn\<^isub>m y\<^isub>j"} provided @{text "x\<^isub>j"} is a deep non-recursive binder |
|
1304 with the auxiliary binding function @{text "bn\<^isub>m"}\\ |
|
1305 $\bullet$ & @{term "(bn\<^isub>m x\<^isub>j, (x\<^isub>j, x\<^isub>n)) \<approx>gen R fvs \<pi> (bn\<^isub>m y\<^isub>j, (y\<^isub>j, y\<^isub>n))"} |
|
1306 provided @{term "x\<^isub>j"} is a deep recursive binder with the auxiliary binding |
|
1307 function @{text "bn\<^isub>m"} and permutation @{text "\<pi>"}, @{term "fvs"} is a compound |
|
1308 free variable function returning the union of appropriate @{term "fv_ty\<^isub>x"} and |
|
1309 @{term "R"} is the composition of equivalence relations @{text "\<approx>"} and @{text "\<approx>\<^isub>n"}\\ |
|
1310 $\bullet$ & @{text "x\<^isub>j"} has a deep recursive binding\\ |
|
1311 $\bullet$ & @{term "({x\<^isub>n}, x\<^isub>j) \<approx>gen R fv_ty \<pi> ({y\<^isub>n}, y\<^isub>j)"} provided @{text "x\<^isub>j"} has |
|
1312 a shallow binder @{text "x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the |
|
1313 alpha-equivalence for @{term "x\<^isub>j"} |
|
1314 and @{term "fv_ty"} is the free variable function for @{term "x\<^isub>j"}\\ |
|
1315 $\bullet$ & @{term "(bn\<^isub>m x\<^isub>n, x\<^isub>j) \<approx>gen R fv_ty \<pi> (bn\<^isub>m y\<^isub>n, y\<^isub>j)"} provided @{text "x\<^isub>j"} |
|
1316 has a deep non-recursive binder @{text "bn\<^isub>m x\<^isub>n"} with permutation @{text "\<pi>"}, @{term "R"} is the |
|
1317 alpha-equivalence for @{term "x\<^isub>j"} |
|
1318 and @{term "fv_ty"} is the free variable function for @{term "x\<^isub>j"}\\ |
|
1319 $\bullet$ & @{text "x\<^isub>j \<approx>\<^isub>j y\<^isub>j"} provided @{term "x\<^isub>j"} is one of the types being |
|
1320 defined\\ |
|
1321 $\bullet$ & @{text "x\<^isub>j = y\<^isub>j"} otherwise\\ |
|
1322 \end{tabular} |
|
1323 \end{center} |
|
1324 |
1347 |
1325 The alpha-equivalence relations for binding functions are similar to the alpha-equivalences |
1348 The alpha-equivalence relations for binding functions are similar to the alpha-equivalences |
1326 for their respective types, the difference is that they ommit checking the arguments that |
1349 for their respective types, the difference is that they ommit checking the arguments that |
1327 are bound. We assumed that there are no bindings in the type on which the binding function |
1350 are bound. We assumed that there are no bindings in the type on which the binding function |
1328 is defined so, there are no permutations involved. For a binding function clause |
1351 is defined so, there are no permutations involved. For a binding function clause |