446 |
446 |
447 Permutations are bijective functions from atoms to atoms that are |
447 Permutations are bijective functions from atoms to atoms that are |
448 the identity everywhere except on a finite number of atoms. There is a |
448 the identity everywhere except on a finite number of atoms. There is a |
449 two-place permutation operation written |
449 two-place permutation operation written |
450 @{text "_ \<bullet> _ :: perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} |
450 @{text "_ \<bullet> _ :: perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} |
451 in which the generic type @{text "\<beta>"} stands for the type of the object |
451 where the generic type @{text "\<beta>"} stands for the type of the object |
452 over which the permutation |
452 over which the permutation |
453 acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"}, |
453 acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"}, |
454 the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}}, |
454 the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}}, |
455 and the inverse permutation of @{term p} as @{text "- p"}. The permutation |
455 and the inverse permutation of @{term p} as @{text "- p"}. The permutation |
456 operation is defined by induction over the type-hierarchy \cite{HuffmanUrban10}; |
456 operation is defined over the type-hierarchy \cite{HuffmanUrban10}; |
457 for example permutations acting on products, lists, sets, functions and booleans is |
457 for example permutations acting on products, lists, sets, functions and booleans is |
458 given by: |
458 given by: |
459 % |
459 % |
460 \begin{equation}\label{permute} |
460 \begin{equation}\label{permute} |
461 \mbox{\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}} |
461 \mbox{\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}} |
609 in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last |
609 in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last |
610 fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders |
610 fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders |
611 @{text as} in @{text x}, because @{term "p \<bullet> x = x"}. |
611 @{text as} in @{text x}, because @{term "p \<bullet> x = x"}. |
612 |
612 |
613 Most properties given in this section are described in detail in \cite{HuffmanUrban10} |
613 Most properties given in this section are described in detail in \cite{HuffmanUrban10} |
614 and of course all are formalised in Isabelle/HOL. In the next sections we will make |
614 and all are formalised in Isabelle/HOL. In the next sections we will make |
615 extensive use of these properties in order to define $\alpha$-equivalence in |
615 extensive use of these properties in order to define $\alpha$-equivalence in |
616 the presence of multiple binders. |
616 the presence of multiple binders. |
617 *} |
617 *} |
618 |
618 |
619 |
619 |
735 \end{equation} |
735 \end{equation} |
736 |
736 |
737 \noindent |
737 \noindent |
738 (similarly for $\approx_{\,\textit{abs\_res}}$ |
738 (similarly for $\approx_{\,\textit{abs\_res}}$ |
739 and $\approx_{\,\textit{abs\_list}}$). We can show that these relations are equivalence |
739 and $\approx_{\,\textit{abs\_list}}$). We can show that these relations are equivalence |
740 relations and equivariant. |
740 relations. %% and equivariant. |
741 |
741 |
742 \begin{lemma}\label{alphaeq} |
742 \begin{lemma}\label{alphaeq} |
743 The relations $\approx_{\,\textit{abs\_set}}$, $\approx_{\,\textit{abs\_list}}$ |
743 The relations $\approx_{\,\textit{abs\_set}}$, $\approx_{\,\textit{abs\_list}}$ |
744 and $\approx_{\,\textit{abs\_res}}$ are equivalence relations, and if @{term |
744 and $\approx_{\,\textit{abs\_res}}$ are equivalence relations. %, and if |
745 "abs_set (as, x) (bs, y)"} then also @{term "abs_set (p \<bullet> as, p \<bullet> x) (p \<bullet> |
745 %@{term "abs_set (as, x) (bs, y)"} then also |
746 bs, p \<bullet> y)"} (similarly for the other two relations). |
746 %@{term "abs_set (p \<bullet> as, p \<bullet> x) (p \<bullet> bs, p \<bullet> y)"} (similarly for the other two relations). |
747 \end{lemma} |
747 \end{lemma} |
748 |
748 |
749 \begin{proof} |
749 \begin{proof} |
750 Reflexivity is by taking @{text "p"} to be @{text "0"}. For symmetry we have |
750 Reflexivity is by taking @{text "p"} to be @{text "0"}. For symmetry we have |
751 a permutation @{text p} and for the proof obligation take @{term "-p"}. In case |
751 a permutation @{text p} and for the proof obligation take @{term "-p"}. In case |
927 %\cite{Berghofer99}. |
927 %\cite{Berghofer99}. |
928 The labels |
928 The labels |
929 annotated on the types are optional. Their purpose is to be used in the |
929 annotated on the types are optional. Their purpose is to be used in the |
930 (possibly empty) list of \emph{binding clauses}, which indicate the binders |
930 (possibly empty) list of \emph{binding clauses}, which indicate the binders |
931 and their scope in a term-constructor. They come in three \emph{modes}: |
931 and their scope in a term-constructor. They come in three \emph{modes}: |
932 |
932 % |
933 \begin{center} |
933 \begin{center} |
934 \begin{tabular}{l} |
934 \begin{tabular}{@ {}l@ {}} |
935 \isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\ |
935 \isacommand{bind} {\it binders} \isacommand{in} {\it bodies}\;\;\;\; |
936 \isacommand{bind (set)}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\ |
936 \isacommand{bind (set)} {\it binders} \isacommand{in} {\it bodies}\;\;\;\; |
937 \isacommand{bind (res)}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\ |
937 \isacommand{bind (res)} {\it binders} \isacommand{in} {\it bodies} |
938 \end{tabular} |
938 \end{tabular} |
939 \end{center} |
939 \end{center} |
940 |
940 % |
941 \noindent |
941 \noindent |
942 The first mode is for binding lists of atoms (the order of binders matters); |
942 The first mode is for binding lists of atoms (the order of binders matters); |
943 the second is for sets of binders (the order does not matter, but the |
943 the second is for sets of binders (the order does not matter, but the |
944 cardinality does) and the last is for sets of binders (with vacuous binders |
944 cardinality does) and the last is for sets of binders (with vacuous binders |
945 preserving $\alpha$-equivalence). As indicated, the labels in the ``\isacommand{in}-part'' of a binding |
945 preserving $\alpha$-equivalence). As indicated, the labels in the ``\isacommand{in}-part'' of a binding |
1025 tuple patterns might be specified as: |
1025 tuple patterns might be specified as: |
1026 % |
1026 % |
1027 \begin{equation}\label{letpat} |
1027 \begin{equation}\label{letpat} |
1028 \mbox{\small% |
1028 \mbox{\small% |
1029 \begin{tabular}{l} |
1029 \begin{tabular}{l} |
1030 \isacommand{nominal\_datatype} @{text trm} =\\ |
1030 \isacommand{nominal\_datatype} @{text trm} $=$\\ |
1031 \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\ |
1031 \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\ |
1032 \hspace{5mm}$\mid$~@{term "App trm trm"}\\ |
1032 \hspace{5mm}$\mid$~@{term "App trm trm"}\\ |
1033 \hspace{5mm}$\mid$~@{text "Lam x::name t::trm"} |
1033 \hspace{5mm}$\mid$~@{text "Lam x::name t::trm"} |
1034 \;\;\isacommand{bind} @{text x} \isacommand{in} @{text t}\\ |
1034 \;\;\isacommand{bind} @{text x} \isacommand{in} @{text t}\\ |
1035 \hspace{5mm}$\mid$~@{text "Let p::pat trm t::trm"} |
1035 \hspace{5mm}$\mid$~@{text "Let p::pat trm t::trm"} |
1036 \;\;\isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text t}\\ |
1036 \;\;\isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text t}\\ |
1037 \isacommand{and} @{text pat} =\\ |
1037 \isacommand{and} @{text pat} $=$ |
1038 \hspace{5mm}\phantom{$\mid$}~@{text PNil}\\ |
1038 @{text PNil} |
1039 \hspace{5mm}$\mid$~@{text "PVar name"}\\ |
1039 $\mid$~@{text "PVar name"} |
1040 \hspace{5mm}$\mid$~@{text "PTup pat pat"}\\ |
1040 $\mid$~@{text "PTup pat pat"}\\ |
1041 \isacommand{binder}~@{text "bn::pat \<Rightarrow> atom list"}\\ |
1041 \isacommand{binder}~@{text "bn::pat \<Rightarrow> atom list"}\\ |
1042 \isacommand{where}~@{text "bn(PNil) = []"}\\ |
1042 \isacommand{where}~@{text "bn(PNil) = []"}\\ |
1043 \hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\ |
1043 \hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\ |
1044 \hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\ |
1044 \hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\ |
1045 \end{tabular}} |
1045 \end{tabular}} |
1068 specification: |
1068 specification: |
1069 % |
1069 % |
1070 \begin{equation}\label{letrecs} |
1070 \begin{equation}\label{letrecs} |
1071 \mbox{\small% |
1071 \mbox{\small% |
1072 \begin{tabular}{@ {}l@ {}} |
1072 \begin{tabular}{@ {}l@ {}} |
1073 \isacommand{nominal\_datatype}~@{text "trm ="}\ldots\\ |
1073 \isacommand{nominal\_datatype}~@{text "trm ="}~\ldots\\ |
1074 \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} |
1074 \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} |
1075 \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text t}\\ |
1075 \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text t}\\ |
1076 \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"} |
1076 \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"} |
1077 \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\ |
1077 \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\ |
1078 \isacommand{and} @{text "ass"} =\\ |
1078 \isacommand{and} @{text "assn"} $=$ |
1079 \hspace{5mm}\phantom{$\mid$}~@{text "ANil"}\\ |
1079 @{text "ANil"} |
1080 \hspace{5mm}$\mid$~@{text "ACons name trm assn"}\\ |
1080 $\mid$~@{text "ACons name trm assn"}\\ |
1081 \isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\ |
1081 \isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\ |
1082 \isacommand{where}~@{text "bn(ANil) = []"}\\ |
1082 \isacommand{where}~@{text "bn(ANil) = []"}\\ |
1083 \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\ |
1083 \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\ |
1084 \end{tabular}} |
1084 \end{tabular}} |
1085 \end{equation} |
1085 \end{equation} |
1195 |
1195 |
1196 The first non-trivial step we have to perform is the generation of |
1196 The first non-trivial step we have to perform is the generation of |
1197 free-atom functions from the specification. For the |
1197 free-atom functions from the specification. For the |
1198 \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions |
1198 \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions |
1199 % |
1199 % |
1200 \begin{equation}\label{fvars} |
1200 %\begin{equation}\label{fvars} |
1201 @{text "fa_ty\<^isub>1, \<dots>, fa_ty\<^isub>n"} |
1201 @{text "fa_ty\<^isub>"}$_{1..n}$ |
1202 \end{equation} |
1202 %\end{equation} |
1203 |
1203 % |
1204 \noindent |
1204 %\noindent |
1205 by recursion. |
1205 by recursion. |
1206 We define these functions together with auxiliary free-atom functions for |
1206 We define these functions together with auxiliary free-atom functions for |
1207 the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ |
1207 the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ |
1208 we define |
1208 we define |
1209 % |
1209 % |
1210 \begin{center} |
1210 %\begin{center} |
1211 @{text "fa_bn\<^isub>1, \<dots>, fa_bn\<^isub>m"} |
1211 @{text "fa_bn\<^isub>"}$_{1..m}$. |
1212 \end{center} |
1212 %\end{center} |
1213 |
1213 % |
1214 \noindent |
1214 %\noindent |
1215 The reason for this setup is that in a deep binder not all atoms have to be |
1215 The reason for this setup is that in a deep binder not all atoms have to be |
1216 bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function |
1216 bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function |
1217 that calculates those free atoms in a deep binder. |
1217 that calculates those free atoms in a deep binder. |
1218 |
1218 |
1219 While the idea behind these free-atom functions is clear (they just |
1219 While the idea behind these free-atom functions is clear (they just |
1252 \end{center} |
1252 \end{center} |
1253 |
1253 |
1254 \noindent |
1254 \noindent |
1255 where in case @{text "d\<^isub>i"} refers to one of the raw types @{text "ty"}$_{1..n}$ from the |
1255 where in case @{text "d\<^isub>i"} refers to one of the raw types @{text "ty"}$_{1..n}$ from the |
1256 specification, the function @{text "fa_ty\<^isub>i"} is the corresponding free-atom function |
1256 specification, the function @{text "fa_ty\<^isub>i"} is the corresponding free-atom function |
1257 we are defining by recursion |
1257 we are defining by recursion; |
1258 (see \eqref{fvars}); otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}. |
1258 %(see \eqref{fvars}); |
|
1259 otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}. |
1259 |
1260 |
1260 In order to formally define the set @{text B} we use the following auxiliary @{text "bn"}-functions |
1261 In order to formally define the set @{text B} we use the following auxiliary @{text "bn"}-functions |
1261 for atom types to which shallow binders may refer |
1262 for atom types to which shallow binders may refer |
1262 % |
1263 % |
1263 %\begin{center} |
1264 %\begin{center} |
1339 "ANil"} and @{text "ACons"}. Since there is a binding function defined for |
1340 "ANil"} and @{text "ACons"}. Since there is a binding function defined for |
1340 assignments, we have three free-atom functions, namely @{text |
1341 assignments, we have three free-atom functions, namely @{text |
1341 "fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text |
1342 "fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text |
1342 "fa\<^bsub>bn\<^esub>"} as follows: |
1343 "fa\<^bsub>bn\<^esub>"} as follows: |
1343 % |
1344 % |
1344 \begin{center} |
1345 \begin{center}\small |
1345 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
1346 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
1346 @{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\ |
1347 @{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\ |
1347 @{text "fa\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} & @{text "(fa\<^bsub>assn\<^esub> as \<union> fa\<^bsub>trm\<^esub> t) - set (bn as)"}\\[1mm] |
1348 @{text "fa\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} & @{text "(fa\<^bsub>assn\<^esub> as \<union> fa\<^bsub>trm\<^esub> t) - set (bn as)"}\\[1mm] |
1348 |
1349 |
1349 @{text "fa\<^bsub>assn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\ |
1350 @{text "fa\<^bsub>assn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\ |
1386 |
1387 |
1387 Next we define the $\alpha$-equivalence relations for the raw types @{text |
1388 Next we define the $\alpha$-equivalence relations for the raw types @{text |
1388 "ty"}$_{1..n}$ from the specification. We write them as |
1389 "ty"}$_{1..n}$ from the specification. We write them as |
1389 % |
1390 % |
1390 %\begin{center} |
1391 %\begin{center} |
1391 @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. |
1392 @{text "\<approx>ty"}$_{1..n}$. |
1392 %\end{center} |
1393 %\end{center} |
1393 % |
1394 % |
1394 %\noindent |
1395 %\noindent |
1395 Like with the free-atom functions, we also need to |
1396 Like with the free-atom functions, we also need to |
1396 define auxiliary $\alpha$-equivalence relations |
1397 define auxiliary $\alpha$-equivalence relations |
1397 % |
1398 % |
1398 %\begin{center} |
1399 %\begin{center} |
1399 @{text "\<approx>bn\<^isub>1, \<dots>, \<approx>bn\<^isub>m"} |
1400 @{text "\<approx>bn\<^isub>"}$_{1..m}$ |
1400 %\end{center} |
1401 %\end{center} |
1401 % |
1402 % |
1402 %\noindent |
1403 %\noindent |
1403 for the binding functions @{text "bn"}$_{1..m}$, |
1404 for the binding functions @{text "bn"}$_{1..m}$, |
1404 To simplify our definitions we will use the following abbreviations for |
1405 To simplify our definitions we will use the following abbreviations for |
1405 \emph{compound equivalence relations} and \emph{compound free-atom functions} acting on tuples |
1406 \emph{compound equivalence relations} and \emph{compound free-atom functions} acting on tuples |
1406 % |
1407 % |
1407 \begin{center} |
1408 \begin{center} |
1408 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1409 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1409 @{text "(x\<^isub>1,.., x\<^isub>n) (R\<^isub>1,.., R\<^isub>n) (x\<PRIME>\<^isub>1,.., x\<PRIME>\<^isub>n)"} & @{text "\<equiv>"} & |
1410 @{text "(x\<^isub>1,\<dots>, x\<^isub>n) (R\<^isub>1,\<dots>, R\<^isub>n) (x\<PRIME>\<^isub>1,\<dots>, x\<PRIME>\<^isub>n)"} & @{text "\<equiv>"} & |
1410 @{text "x\<^isub>1 R\<^isub>1 x\<PRIME>\<^isub>1 \<and> .. \<and> x\<^isub>n R\<^isub>n x\<PRIME>\<^isub>n"}\\ |
1411 @{text "x\<^isub>1 R\<^isub>1 x\<PRIME>\<^isub>1 \<and> \<dots> \<and> x\<^isub>n R\<^isub>n x\<PRIME>\<^isub>n"}\\ |
1411 @{text "(fa\<^isub>1,.., fa\<^isub>n) (x\<^isub>1,.., x\<^isub>n)"} & @{text "\<equiv>"} & @{text "fa\<^isub>1 x\<^isub>1 \<union> .. \<union> fa\<^isub>n x\<^isub>n"}\\ |
1412 @{text "(fa\<^isub>1,\<dots>, fa\<^isub>n) (x\<^isub>1,\<dots>, x\<^isub>n)"} & @{text "\<equiv>"} & @{text "fa\<^isub>1 x\<^isub>1 \<union> \<dots> \<union> fa\<^isub>n x\<^isub>n"}\\ |
1412 \end{tabular} |
1413 \end{tabular} |
1413 \end{center} |
1414 \end{center} |
1414 |
1415 |
1415 |
1416 |
1416 The $\alpha$-equivalence relations are defined as inductive predicates |
1417 The $\alpha$-equivalence relations are defined as inductive predicates |
1561 |
1562 |
1562 Again let us take a look at a concrete example for these definitions. For \eqref{letrecs} |
1563 Again let us take a look at a concrete example for these definitions. For \eqref{letrecs} |
1563 we have three relations $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and |
1564 we have three relations $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and |
1564 $\approx_{\textit{bn}}$ with the following clauses: |
1565 $\approx_{\textit{bn}}$ with the following clauses: |
1565 |
1566 |
1566 \begin{center} |
1567 \begin{center}\small |
1567 \begin{tabular}{@ {}c @ {}} |
1568 \begin{tabular}{@ {}c @ {}} |
1568 \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}} |
1569 \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}} |
1569 {@{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fa_trm p (bn as', t')"} & @{text "as \<approx>\<^bsub>bn\<^esub> as'"}}\smallskip\\ |
1570 {@{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fa_trm p (bn as', t')"} & @{text "as \<approx>\<^bsub>bn\<^esub> as'"}}\smallskip\\ |
1570 \makebox[0mm]{\infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}} |
1571 \makebox[0mm]{\infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}} |
1571 {@{term "\<exists>p. (bn as, ast) \<approx>lst alpha_trm2 fa_trm2 p (bn as', ast')"}}} |
1572 {@{term "\<exists>p. (bn as, ast) \<approx>lst alpha_trm2 fa_trm2 p (bn as', ast')"}}} |
1572 \end{tabular} |
1573 \end{tabular} |
1573 \end{center} |
1574 \end{center} |
1574 |
1575 |
1575 \begin{center} |
1576 \begin{center}\small |
1576 \begin{tabular}{@ {}c @ {}} |
1577 \begin{tabular}{@ {}c @ {}} |
1577 \infer{@{text "ANil \<approx>\<^bsub>assn\<^esub> ANil"}}{}\hspace{9mm} |
1578 \infer{@{text "ANil \<approx>\<^bsub>assn\<^esub> ANil"}}{}\hspace{9mm} |
1578 \infer{@{text "ACons a t as \<approx>\<^bsub>assn\<^esub> ACons a' t' as"}} |
1579 \infer{@{text "ACons a t as \<approx>\<^bsub>assn\<^esub> ACons a' t' as"}} |
1579 {@{text "a = a'"} & @{text "t \<approx>\<^bsub>trm\<^esub> t'"} & @{text "as \<approx>\<^bsub>assn\<^esub> as'"}} |
1580 {@{text "a = a'"} & @{text "t \<approx>\<^bsub>trm\<^esub> t'"} & @{text "as \<approx>\<^bsub>assn\<^esub> as'"}} |
1580 \end{tabular} |
1581 \end{tabular} |
1581 \end{center} |
1582 \end{center} |
1582 |
1583 |
1583 \begin{center} |
1584 \begin{center}\small |
1584 \begin{tabular}{@ {}c @ {}} |
1585 \begin{tabular}{@ {}c @ {}} |
1585 \infer{@{text "ANil \<approx>\<^bsub>bn\<^esub> ANil"}}{}\hspace{9mm} |
1586 \infer{@{text "ANil \<approx>\<^bsub>bn\<^esub> ANil"}}{}\hspace{9mm} |
1586 \infer{@{text "ACons a t as \<approx>\<^bsub>bn\<^esub> ACons a' t' as"}} |
1587 \infer{@{text "ACons a t as \<approx>\<^bsub>bn\<^esub> ACons a' t' as"}} |
1587 {@{text "t \<approx>\<^bsub>trm\<^esub> t'"} & @{text "as \<approx>\<^bsub>bn\<^esub> as'"}} |
1588 {@{text "t \<approx>\<^bsub>trm\<^esub> t'"} & @{text "as \<approx>\<^bsub>bn\<^esub> as'"}} |
1588 \end{tabular} |
1589 \end{tabular} |
1613 equivalence relations. |
1614 equivalence relations. |
1614 |
1615 |
1615 \begin{lemma}\label{equiv} |
1616 \begin{lemma}\label{equiv} |
1616 Given the raw types @{text "ty"}$_{1..n}$ and binding functions |
1617 Given the raw types @{text "ty"}$_{1..n}$ and binding functions |
1617 @{text "bn"}$_{1..m}$, the relations @{text "\<approx>ty"}$_{1..n}$ and |
1618 @{text "bn"}$_{1..m}$, the relations @{text "\<approx>ty"}$_{1..n}$ and |
1618 @{text "\<approx>bn"}$_{1..m}$ are equivalence relations and equivariant. |
1619 @{text "\<approx>bn"}$_{1..m}$ are equivalence relations.%% and equivariant. |
1619 \end{lemma} |
1620 \end{lemma} |
1620 |
1621 |
1621 \begin{proof} |
1622 \begin{proof} |
1622 The proof is by mutual induction over the definitions. The non-trivial |
1623 The proof is by mutual induction over the definitions. The non-trivial |
1623 cases involve premises built up by $\approx_{\textit{set}}$, |
1624 cases involve premises built up by $\approx_{\textit{set}}$, |
1719 |
1720 |
1720 Next we can lift the permutation |
1721 Next we can lift the permutation |
1721 operations defined in \eqref{ceqvt}. In order to make this |
1722 operations defined in \eqref{ceqvt}. In order to make this |
1722 lifting to go through, we have to show that the permutation operations are respectful. |
1723 lifting to go through, we have to show that the permutation operations are respectful. |
1723 This amounts to showing that the |
1724 This amounts to showing that the |
1724 $\alpha$-equivalence relations are equivariant, which we already established |
1725 $\alpha$-equivalence relations are equivariant \cite{HuffmanUrban10}. |
1725 in Lemma~\ref{equiv}. As a result we can add the equations |
1726 %, which we already established |
|
1727 %in Lemma~\ref{equiv}. |
|
1728 As a result we can add the equations |
1726 % |
1729 % |
1727 \begin{equation}\label{calphaeqvt} |
1730 \begin{equation}\label{calphaeqvt} |
1728 @{text "p \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r) = C\<^sup>\<alpha> (p \<bullet> x\<^isub>1) \<dots> (p \<bullet> x\<^isub>r)"} |
1731 @{text "p \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r) = C\<^sup>\<alpha> (p \<bullet> x\<^isub>1) \<dots> (p \<bullet> x\<^isub>r)"} |
1729 \end{equation} |
1732 \end{equation} |
1730 |
1733 |
1734 @{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text |
1737 @{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text |
1735 "bn\<AL>"}$_{1..m}$ and the size functions @{text "size_ty\<AL>"}$_{1..n}$. |
1738 "bn\<AL>"}$_{1..m}$ and the size functions @{text "size_ty\<AL>"}$_{1..n}$. |
1736 The latter are defined automatically for the raw types @{text "ty"}$_{1..n}$ |
1739 The latter are defined automatically for the raw types @{text "ty"}$_{1..n}$ |
1737 by the datatype package of Isabelle/HOL. |
1740 by the datatype package of Isabelle/HOL. |
1738 |
1741 |
1739 Finally we can add to our infrastructure a structural induction principle |
1742 Finally we can add to our infrastructure a cases lemma (explained in the next section) |
1740 for the types @{text "ty\<AL>"}$_{i..n}$ whose |
1743 and a structural induction principle |
1741 conclusion of the form |
1744 for the types @{text "ty\<AL>"}$_{i..n}$. The conclusion of the induction principle is |
|
1745 of the form |
1742 % |
1746 % |
1743 \begin{equation}\label{weakinduct} |
1747 \begin{equation}\label{weakinduct} |
1744 \mbox{@{text "P\<^isub>1 x\<^isub>1 \<and> \<dots> \<and> P\<^isub>n x\<^isub>n "}} |
1748 \mbox{@{text "P\<^isub>1 x\<^isub>1 \<and> \<dots> \<and> P\<^isub>n x\<^isub>n "}} |
1745 \end{equation} |
1749 \end{equation} |
1746 |
1750 |
1803 \noindent |
1807 \noindent |
1804 To sum up this section, we can established automatically a reasoning infrastructure |
1808 To sum up this section, we can established automatically a reasoning infrastructure |
1805 for the types @{text "ty\<AL>"}$_{1..n}$ |
1809 for the types @{text "ty\<AL>"}$_{1..n}$ |
1806 by first lifting definitions from the raw level to the quotient level and |
1810 by first lifting definitions from the raw level to the quotient level and |
1807 then by establishing facts about these lifted definitions. All necessary proofs |
1811 then by establishing facts about these lifted definitions. All necessary proofs |
1808 are generated automatically by custom ML-code. This code can deal with |
1812 are generated automatically by custom ML-code. |
1809 specifications such as the one shown in Figure~\ref{nominalcorehas} for Core-Haskell. |
1813 |
|
1814 %This code can deal with |
|
1815 %specifications such as the one shown in Figure~\ref{nominalcorehas} for Core-Haskell. |
1810 |
1816 |
1811 %\begin{figure}[t!] |
1817 %\begin{figure}[t!] |
1812 %\begin{boxedminipage}{\linewidth} |
1818 %\begin{boxedminipage}{\linewidth} |
1813 %\small |
1819 %\small |
1814 %\begin{tabular}{l} |
1820 %\begin{tabular}{l} |
2082 example in the second part of this challenge, @{text "Let"}s involve |
2088 example in the second part of this challenge, @{text "Let"}s involve |
2083 patterns that bind multiple variables at once. In such situations, HOAS |
2089 patterns that bind multiple variables at once. In such situations, HOAS |
2084 representations have to resort to the iterated-single-binders-approach with |
2090 representations have to resort to the iterated-single-binders-approach with |
2085 all the unwanted consequences when reasoning about the resulting terms. |
2091 all the unwanted consequences when reasoning about the resulting terms. |
2086 |
2092 |
2087 Two formalisations involving general binders have been |
2093 %Two formalisations involving general binders have been |
2088 performed in older |
2094 %performed in older |
2089 versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W |
2095 %versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W |
2090 \cite{BengtsonParow09,UrbanNipkow09}). Both |
2096 %\cite{BengtsonParow09,UrbanNipkow09}). Both |
2091 use the approach based on iterated single binders. Our experience with |
2097 %use the approach based on iterated single binders. Our experience with |
2092 the latter formalisation has been disappointing. The major pain arose from |
2098 %the latter formalisation has been disappointing. The major pain arose from |
2093 the need to ``unbind'' variables. This can be done in one step with our |
2099 %the need to ``unbind'' variables. This can be done in one step with our |
2094 general binders described in this paper, but needs a cumbersome |
2100 %general binders described in this paper, but needs a cumbersome |
2095 iteration with single binders. The resulting formal reasoning turned out to |
2101 %iteration with single binders. The resulting formal reasoning turned out to |
2096 be rather unpleasant. The hope is that the extension presented in this paper |
2102 %be rather unpleasant. The hope is that the extension presented in this paper |
2097 is a substantial improvement. |
2103 %is a substantial improvement. |
2098 |
2104 |
2099 The most closely related work to the one presented here is the Ott-tool |
2105 The most closely related work to the one presented here is the Ott-tool |
2100 \cite{ott-jfp} and the C$\alpha$ml language \cite{Pottier06}. Ott is a nifty |
2106 \cite{ott-jfp} and the C$\alpha$ml language \cite{Pottier06}. Ott is a nifty |
2101 front-end for creating \LaTeX{} documents from specifications of |
2107 front-end for creating \LaTeX{} documents from specifications of |
2102 term-calculi involving general binders. For a subset of the specifications |
2108 term-calculi involving general binders. For a subset of the specifications |
2117 sense for our $\alpha$-equated terms. Third, it allows empty types that have no |
2123 sense for our $\alpha$-equated terms. Third, it allows empty types that have no |
2118 meaning in a HOL-based theorem prover. We also had to generalise slightly Ott's |
2124 meaning in a HOL-based theorem prover. We also had to generalise slightly Ott's |
2119 binding clauses. In Ott you specify binding clauses with a single body; we |
2125 binding clauses. In Ott you specify binding clauses with a single body; we |
2120 allow more than one. We have to do this, because this makes a difference |
2126 allow more than one. We have to do this, because this makes a difference |
2121 for our notion of $\alpha$-equivalence in case of \isacommand{bind (set)} and |
2127 for our notion of $\alpha$-equivalence in case of \isacommand{bind (set)} and |
2122 \isacommand{bind (res)}. Consider the examples |
2128 \isacommand{bind (res)}. |
2123 |
2129 |
2124 \begin{center} |
2130 %Consider the examples |
2125 \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}} |
2131 % |
2126 @{text "Foo\<^isub>1 xs::name fset t::trm s::trm"} & |
2132 %\begin{center} |
2127 \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "t s"}\\ |
2133 %\begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}} |
2128 @{text "Foo\<^isub>2 xs::name fset t::trm s::trm"} & |
2134 %@{text "Foo\<^isub>1 xs::name fset t::trm s::trm"} & |
2129 \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "t"}, |
2135 % \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "t s"}\\ |
2130 \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "s"}\\ |
2136 %@{text "Foo\<^isub>2 xs::name fset t::trm s::trm"} & |
2131 \end{tabular} |
2137 % \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "t"}, |
2132 \end{center} |
2138 % \isacommand{bind (set)} @{text "xs"} \isacommand{in} @{text "s"}\\ |
2133 |
2139 %\end{tabular} |
2134 \noindent |
2140 %\end{center} |
2135 In the first term-constructor we have a single |
2141 % |
2136 body that happens to be ``spread'' over two arguments; in the second term-constructor we have |
2142 %\noindent |
2137 two independent bodies in which the same variables are bound. As a result we |
2143 %In the first term-constructor we have a single |
2138 have |
2144 %body that happens to be ``spread'' over two arguments; in the second term-constructor we have |
2139 |
2145 %two independent bodies in which the same variables are bound. As a result we |
2140 \begin{center} |
2146 %have |
2141 \begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}l} |
2147 % |
2142 @{text "Foo\<^isub>1 {a, b} (a, b) (a, b)"} & $\not=$ & |
2148 %\begin{center} |
2143 @{text "Foo\<^isub>1 {a, b} (a, b) (b, a)"}\\ |
2149 %\begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}l} |
2144 @{text "Foo\<^isub>2 {a, b} (a, b) (a, b)"} & $=$ & |
2150 %@{text "Foo\<^isub>1 {a, b} (a, b) (a, b)"} & $\not=$ & |
2145 @{text "Foo\<^isub>2 {a, b} (a, b) (b, a)"}\\ |
2151 %@{text "Foo\<^isub>1 {a, b} (a, b) (b, a)"}\\ |
2146 \end{tabular} |
2152 %@{text "Foo\<^isub>2 {a, b} (a, b) (a, b)"} & $=$ & |
2147 \end{center} |
2153 %@{text "Foo\<^isub>2 {a, b} (a, b) (b, a)"}\\ |
2148 |
2154 %\end{tabular} |
2149 \noindent |
2155 %\end{center} |
2150 and therefore need the extra generality to be able to distinguish between |
2156 |
2151 both specifications. |
2157 \noindent |
|
2158 %and therefore need the extra generality to be able to distinguish between |
|
2159 %both specifications. |
2152 Because of how we set up our definitions, we also had to impose some restrictions |
2160 Because of how we set up our definitions, we also had to impose some restrictions |
2153 (like a single binding function for a deep binder) that are not present in Ott. Our |
2161 (like a single binding function for a deep binder) that are not present in Ott. Our |
2154 expectation is that we can still cover many interesting term-calculi from |
2162 expectation is that we can still cover many interesting term-calculi from |
2155 programming language research, for example Core-Haskell. |
2163 programming language research, for example Core-Haskell. |
2156 |
2164 |
2185 general binders, that is term-constructors having multiple bound |
2193 general binders, that is term-constructors having multiple bound |
2186 variables. For this extension we introduced new definitions of |
2194 variables. For this extension we introduced new definitions of |
2187 $\alpha$-equivalence and automated all necessary proofs in Isabelle/HOL. |
2195 $\alpha$-equivalence and automated all necessary proofs in Isabelle/HOL. |
2188 To specify general binders we used the specifications from Ott, but extended them |
2196 To specify general binders we used the specifications from Ott, but extended them |
2189 in some places and restricted |
2197 in some places and restricted |
2190 them in others so that they make sense in the context of $\alpha$-equated terms. We also introduced two binding modes (set and res) that do not |
2198 them in others so that they make sense in the context of $\alpha$-equated terms. |
|
2199 We also introduced two binding modes (set and res) that do not |
2191 exist in Ott. |
2200 exist in Ott. |
2192 We have tried out the extension with terms from Core-Haskell, type-schemes |
2201 We have tried out the extension with terms from Core-Haskell, type-schemes |
2193 and the lambda-calculus, and our code |
2202 and a dozen of other calculi from programming language research. The code |
2194 will eventually become part of the next Isabelle distribution.\footnote{For the moment |
2203 will eventually become part of the next Isabelle distribution.\footnote{For the moment |
2195 it can be downloaded from the Mercurial repository linked at |
2204 it can be downloaded from the Mercurial repository linked at |
2196 \href{http://isabelle.in.tum.de/nominal/download} |
2205 \href{http://isabelle.in.tum.de/nominal/download} |
2197 {http://isabelle.in.tum.de/nominal/download}.} |
2206 {http://isabelle.in.tum.de/nominal/download}.} |
2198 |
2207 |
2202 hope to do better this time by using the function package that has recently |
2211 hope to do better this time by using the function package that has recently |
2203 been implemented in Isabelle/HOL and also by restricting function |
2212 been implemented in Isabelle/HOL and also by restricting function |
2204 definitions to equivariant functions (for such functions it is possible to |
2213 definitions to equivariant functions (for such functions it is possible to |
2205 provide more automation). |
2214 provide more automation). |
2206 |
2215 |
2207 There are some restrictions we imposed in this paper that we would like to lift in |
2216 %There are some restrictions we imposed in this paper that we would like to lift in |
2208 future work. One is the exclusion of nested datatype definitions. Nested |
2217 %future work. One is the exclusion of nested datatype definitions. Nested |
2209 datatype definitions allow one to specify, for instance, the function kinds |
2218 %datatype definitions allow one to specify, for instance, the function kinds |
2210 in Core-Haskell as @{text "TFun string (ty list)"} instead of the unfolded |
2219 %in Core-Haskell as @{text "TFun string (ty list)"} instead of the unfolded |
2211 version @{text "TFun string ty_list"} (see Figure~\ref{nominalcorehas}). To |
2220 %version @{text "TFun string ty_list"} (see Figure~\ref{nominalcorehas}). To |
2212 achieve this, we need a slightly more clever implementation than we have at the moment. |
2221 %achieve this, we need a slightly more clever implementation than we have at the moment. |
2213 |
2222 |
2214 A more interesting line of investigation is whether we can go beyond the |
2223 %A more interesting line of investigation is whether we can go beyond the |
2215 simple-minded form of binding functions that we adopted from Ott. At the moment, binding |
2224 %simple-minded form of binding functions that we adopted from Ott. At the moment, binding |
2216 functions can only return the empty set, a singleton atom set or unions |
2225 %functions can only return the empty set, a singleton atom set or unions |
2217 of atom sets (similarly for lists). It remains to be seen whether |
2226 %of atom sets (similarly for lists). It remains to be seen whether |
2218 properties like |
2227 %properties like |
2219 % |
2228 %% |
2220 \begin{center} |
2229 %\begin{center} |
2221 @{text "fa_ty x = bn x \<union> fa_bn x"}. |
2230 %@{text "fa_ty x = bn x \<union> fa_bn x"}. |
2222 \end{center} |
2231 %\end{center} |
2223 |
2232 % |
2224 \noindent |
2233 %\noindent |
2225 allow us to support more interesting binding functions. |
2234 %allow us to support more interesting binding functions. |
2226 |
2235 % |
2227 We have also not yet played with other binding modes. For example we can |
2236 %We have also not yet played with other binding modes. For example we can |
2228 imagine that there is need for a binding mode |
2237 %imagine that there is need for a binding mode |
2229 where instead of lists, we abstract lists of distinct elements. |
2238 %where instead of lists, we abstract lists of distinct elements. |
2230 Once we feel confident about such binding modes, our implementation |
2239 %Once we feel confident about such binding modes, our implementation |
2231 can be easily extended to accommodate them. |
2240 %can be easily extended to accommodate them. |
2232 |
2241 |
2233 \medskip |
2242 \medskip |
2234 \noindent |
2243 \noindent |
2235 {\bf Acknowledgements:} %We are very grateful to Andrew Pitts for |
2244 {\bf Acknowledgements:} %We are very grateful to Andrew Pitts for |
2236 %many discussions about Nominal Isabelle. |
2245 %many discussions about Nominal Isabelle. |