704 that makes the |
704 that makes the |
705 sets @{text "{x}"} and @{text "{x, y}"} equal (similarly for $\approx_{\textit{list}}$). |
705 sets @{text "{x}"} and @{text "{x, y}"} equal (similarly for $\approx_{\textit{list}}$). |
706 It can also relatively easily be shown that all tree notions of alpha-equivalence |
706 It can also relatively easily be shown that all tree notions of alpha-equivalence |
707 coincide, if we only abstract a single atom. |
707 coincide, if we only abstract a single atom. |
708 |
708 |
709 % looks too ugly |
|
710 %\noindent |
|
711 %Let $\star$ range over $\{set, res, list\}$. We prove next under which |
|
712 %conditions the $\approx\hspace{0.05mm}_\star^{\fv, R, p}$ are equivalence |
|
713 %relations and equivariant: |
|
714 % |
|
715 %\begin{lemma} |
|
716 %{\it i)} Given the fact that $x\;R\;x$ holds, then |
|
717 %$(as, x) \approx\hspace{0.05mm}^{\fv, R, 0}_\star (as, x)$. {\it ii)} Given |
|
718 %that @{text "(p \<bullet> x) R y"} implies @{text "(-p \<bullet> y) R x"}, then |
|
719 %$(as, x) \approx\hspace{0.05mm}^{\fv, R, p}_\star (bs, y)$ implies |
|
720 %$(bs, y) \approx\hspace{0.05mm}^{\fv, R, - p}_\star (as, x)$. {\it iii)} Given |
|
721 %that @{text "(p \<bullet> x) R y"} and @{text "(q \<bullet> y) R z"} implies |
|
722 %@{text "((q + p) \<bullet> x) R z"}, then $(as, x) \approx\hspace{0.05mm}^{\fv, R, p}_\star (bs, y)$ |
|
723 %and $(bs, y) \approx\hspace{0.05mm}^{\fv, R, q}_\star (cs, z)$ implies |
|
724 %$(as, x) \approx\hspace{0.05mm}^{\fv, R, q + p}_\star (cs, z)$. Given |
|
725 %@{text "(q \<bullet> x) R y"} implies @{text "(p \<bullet> (q \<bullet> x)) R (p \<bullet> y)"} and |
|
726 %@{text "p \<bullet> (fv x) = fv (p \<bullet> x)"} then @{text "p \<bullet> (fv y) = fv (p \<bullet> y)"}, then |
|
727 %$(as, x) \approx\hspace{0.05mm}^{\fv, R, q}_\star (bs, y)$ implies |
|
728 %$(p \;\isasymbullet\; as, p \;\isasymbullet\; x) \approx\hspace{0.05mm}^{\fv, R, q}_\star |
|
729 %(p \;\isasymbullet\; bs, p \;\isasymbullet\; y)$. |
|
730 %\end{lemma} |
|
731 |
|
732 %\begin{proof} |
|
733 %All properties are by unfolding the definitions and simple calculations. |
|
734 %\end{proof} |
|
735 |
|
736 |
|
737 In the rest of this section we are going to introduce three abstraction |
709 In the rest of this section we are going to introduce three abstraction |
738 types. For this we define |
710 types. For this we define |
739 % |
711 % |
740 \begin{equation} |
712 \begin{equation} |
741 @{term "abs_set (as, x) (bs, x) \<equiv> \<exists>p. alpha_gen (as, x) equal supp p (bs, x)"} |
713 @{term "abs_set (as, x) (bs, x) \<equiv> \<exists>p. alpha_gen (as, x) equal supp p (bs, x)"} |
742 \end{equation} |
714 \end{equation} |
743 |
715 |
744 \noindent |
716 \noindent |
745 (similarly for $\approx_{\textit{abs\_list}}$ |
717 (similarly for $\approx_{\textit{abs\_res}}$ |
746 and $\approx_{\textit{abs\_res}}$). We can show that these relations are equivalence |
718 and $\approx_{\textit{abs\_list}}$). We can show that these relations are equivalence |
747 relations and equivariant. |
719 relations and equivariant. |
748 |
720 |
749 \begin{lemma}\label{alphaeq} |
721 \begin{lemma}\label{alphaeq} |
750 The relations $\approx_{\textit{abs\_set}}$, $\approx_{\textit{abs\_list}}$ |
722 The relations $\approx_{\textit{abs\_set}}$, $\approx_{\textit{abs\_list}}$ |
751 and $\approx_{\textit{abs\_res}}$ are equivalence relations, and if @{term |
723 and $\approx_{\textit{abs\_res}}$ are equivalence relations, and if @{term |
864 @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}. |
836 @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}. |
865 Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes |
837 Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes |
866 Theorem~\ref{suppabs}. |
838 Theorem~\ref{suppabs}. |
867 |
839 |
868 The method of first considering abstractions of the |
840 The method of first considering abstractions of the |
869 form @{term "Abs as x"} etc is motivated by the fact that properties about them |
841 form @{term "Abs as x"} etc is motivated by the fact that |
870 can be conveninetly established at the Isabelle/HOL level. It would be |
842 we can conveniently establish at the Isabelle/HOL level |
871 difficult to write custom ML-code that derives automatically such properties |
843 properties about them. It would be |
|
844 laborious to write custom ML-code that derives automatically such properties |
872 for every term-constructor that binds some atoms. Also the generality of |
845 for every term-constructor that binds some atoms. Also the generality of |
873 the definitions for alpha-equivalence will help us in definitions in the next section. |
846 the definitions for alpha-equivalence will help us in the next section. |
874 *} |
847 *} |
875 |
848 |
876 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *} |
849 section {* Alpha-Equivalence and Free Variables\label{sec:alpha} *} |
877 |
850 |
878 text {* |
851 text {* |
943 The first mode is for binding lists of atoms (the order of binders matters); |
916 The first mode is for binding lists of atoms (the order of binders matters); |
944 the second is for sets of binders (the order does not matter, but the |
917 the second is for sets of binders (the order does not matter, but the |
945 cardinality does) and the last is for sets of binders (with vacuous binders |
918 cardinality does) and the last is for sets of binders (with vacuous binders |
946 preserving alpha-equivalence). The ``\isacommand{in}-part'' of a binding |
919 preserving alpha-equivalence). The ``\isacommand{in}-part'' of a binding |
947 clause will be called \emph{bodies} (there can be more than one); the |
920 clause will be called \emph{bodies} (there can be more than one); the |
948 ``\isacommand{bind}-part'' will be called \emph{binders}. A body can only occur |
921 ``\isacommand{bind}-part'' will be called \emph{binders}. |
949 in \emph{one} binding clause. A binder, in contrast, may occur in several binding |
922 |
950 clauses, but cannot occur as a body. |
923 In contrast to Ott, we allow multiple labels in binders and bodies. For example |
|
924 we permit binding clauses as follows: |
|
925 |
|
926 \begin{center} |
|
927 \begin{tabular}{ll} |
|
928 @{text "Foo x::name y::name t::lam s::lam"} & |
|
929 \isacommand{bind} @{text "x y"} \isacommand{in} @{text "t s"} |
|
930 \end{tabular} |
|
931 \end{center} |
|
932 |
|
933 \noindent |
|
934 There are a few restrictions we need to impose: First, a body can only occur in |
|
935 \emph{one} binding clause of a term constructor. A binder, in contrast, may |
|
936 occur in several binding clauses, but cannot occur as a body. |
951 |
937 |
952 In addition we distinguish between \emph{shallow} and \emph{deep} |
938 In addition we distinguish between \emph{shallow} and \emph{deep} |
953 binders. Shallow binders are of the form \isacommand{bind}\; {\it labels}\; |
939 binders. Shallow binders are of the form \isacommand{bind}\; {\it labels}\; |
954 \isacommand{in}\; {\it labels'} (similar for the other two modes). The |
940 \isacommand{in}\; {\it labels'} (similar for the other two modes). The |
955 restriction we impose on shallow binders is that the {\it labels} must either |
941 restriction we impose on shallow binders is that the {\it labels} must either |
976 \end{tabular} |
962 \end{tabular} |
977 \end{tabular} |
963 \end{tabular} |
978 \end{center} |
964 \end{center} |
979 |
965 |
980 \noindent |
966 \noindent |
981 Note that in this specification \emph{name} refers to an atom type. |
967 Note that in this specification @{text "name"} refers to an atom type, and |
982 Shallow binders may also ``share'' several bodies, for instance @{text t} |
968 @{text "fset"} to the type of finite sets. |
983 and @{text s} in the following term-constructor |
969 |
984 |
|
985 \begin{center} |
|
986 \begin{tabular}{ll} |
|
987 @{text "Foo x::name y::name t::lam s::lam"} & |
|
988 \isacommand{bind} @{text "x y"} \isacommand{in} @{text "t s"} |
|
989 \end{tabular} |
|
990 \end{center} |
|
991 |
|
992 A \emph{deep} binder uses an auxiliary binding function that ``picks'' out |
970 A \emph{deep} binder uses an auxiliary binding function that ``picks'' out |
993 the atoms in one argument of the term-constructor, which can be bound in |
971 the atoms in one argument of the term-constructor, which can be bound in |
994 other arguments and also in the same argument (we will |
972 other arguments and also in the same argument (we will |
995 call such binders \emph{recursive}, see below). |
973 call such binders \emph{recursive}, see below). |
996 The corresponding binding functions are expected to return either a set of atoms |
974 The corresponding binding functions are expected to return either a set of atoms |
1069 \end{center} |
1047 \end{center} |
1070 |
1048 |
1071 \noindent |
1049 \noindent |
1072 since there is no overlap of binders. |
1050 since there is no overlap of binders. |
1073 |
1051 |
1074 Note that in the last example we wrote \isacommand{bind}~@{text "bn(p)"}~\isacommand{in}~@{text "p.."}. |
1052 Note that in the last example we wrote \isacommand{bind}~@{text |
1075 Whenever such a binding clause is present, we will call the corresponding binder \emph{recursive}. |
1053 "bn(p)"}~\isacommand{in}~@{text "p.."}. Whenever such a binding clause is |
1076 To see the purpose of such recursive binders, compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s |
1054 present, we will call the corresponding binder \emph{recursive}. To see the |
1077 in the following specification: |
1055 purpose of such recursive binders, compare ``plain'' @{text "Let"}s and |
|
1056 @{text "Let_rec"}s in the following specification: |
1078 % |
1057 % |
1079 \begin{equation}\label{letrecs} |
1058 \begin{equation}\label{letrecs} |
1080 \mbox{% |
1059 \mbox{% |
1081 \begin{tabular}{@ {}l@ {}} |
1060 \begin{tabular}{@ {}l@ {}} |
1082 \isacommand{nominal\_datatype}~@{text "trm ="}\\ |
1061 \isacommand{nominal\_datatype}~@{text "trm ="}\\ |
1099 "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms |
1078 "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms |
1100 inside the assignment. This difference has consequences for the free-variable |
1079 inside the assignment. This difference has consequences for the free-variable |
1101 function and alpha-equivalence relation, which we are going to describe in the |
1080 function and alpha-equivalence relation, which we are going to describe in the |
1102 rest of this section. |
1081 rest of this section. |
1103 |
1082 |
1104 In order to simplify matters below, we shall assume specifications |
1083 In order to simplify some definitions, we shall assume specifications |
1105 of term-calculi are \emph{completed}. By this we mean that |
1084 of term-calculi are \emph{completed}. By this we mean that |
1106 for every argument of a term-constructor that is \emph{not} |
1085 for every argument of a term-constructor that is \emph{not} |
1107 already part of a binding clause, we add implicitly a special \emph{empty} binding |
1086 already part of a binding clause, we add implicitly a special \emph{empty} binding |
1108 clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "\<dots>"}. In case |
1087 clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "label"}. In case |
1109 of the lambda-calculus, the comletion is as follows: |
1088 of the lambda-calculus, the completion produces |
1110 |
1089 |
1111 \begin{center} |
1090 \begin{center} |
1112 \begin{tabular}{@ {}l@ {\hspace{-1mm}}} |
1091 \begin{tabular}{@ {}l@ {\hspace{-1mm}}} |
1113 \isacommand{nominal\_datatype} @{text lam} =\\ |
1092 \isacommand{nominal\_datatype} @{text lam} =\\ |
1114 \hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"} |
1093 \hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"} |
1121 \end{tabular} |
1100 \end{tabular} |
1122 \end{center} |
1101 \end{center} |
1123 |
1102 |
1124 \noindent |
1103 \noindent |
1125 The point of completion is that we can make definitions over the binding |
1104 The point of completion is that we can make definitions over the binding |
1126 clauses, which defined purely over arguments, turned out to be unwieldy. |
1105 clauses and be sure to capture all arguments of a term constructor. |
1127 |
1106 |
1128 Having dealt with all syntax matters, the problem now is how we can turn |
1107 Having dealt with all syntax matters, the problem now is how we can turn |
1129 specifications into actual type definitions in Isabelle/HOL and then |
1108 specifications into actual type definitions in Isabelle/HOL and then |
1130 establish a reasoning infrastructure for them. As |
1109 establish a reasoning infrastructure for them. As |
1131 Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, by just |
1110 Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just |
1132 re-arranging the arguments of |
1111 re-arranging the arguments of |
1133 term-constructors so that binders and their bodies are next to each other, and |
1112 term-constructors so that binders and their bodies are next to each other will |
1134 then use directly the type constructors @{text "abs_set"}, @{text "abs_res"} and |
1113 result in inadequate representations. Therefore we will first |
1135 @{text "abs_list"} from Section \ref{sec:binders}, will result in an inadequate |
|
1136 representatation. Therefore we will first |
|
1137 extract datatype definitions from the specification and then define |
1114 extract datatype definitions from the specification and then define |
1138 expicitly an alpha-equivalence relation over them. |
1115 expicitly an alpha-equivalence relation over them. |
1139 |
1116 |
1140 |
1117 |
1141 The datatype definition can be obtained by stripping off the |
1118 The datatype definition can be obtained by stripping off the |
1208 |
1185 |
1209 While the idea behind these free-variable functions is clear (they just |
1186 While the idea behind these free-variable functions is clear (they just |
1210 collect all atoms that are not bound), because of our rather complicated |
1187 collect all atoms that are not bound), because of our rather complicated |
1211 binding mechanisms their definitions are somewhat involved. Given a |
1188 binding mechanisms their definitions are somewhat involved. Given a |
1212 term-constructor @{text "C"} of type @{text ty} and some associated binding |
1189 term-constructor @{text "C"} of type @{text ty} and some associated binding |
1213 clauses, the function @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be |
1190 clauses @{text bcs}, the result of the @{text "fv_ty (C x\<^isub>1 \<dots> x\<^isub>n)"} will be |
1214 the union of the values, @{text v}, calculated below for each binding |
1191 the union of the values, @{text v}, calculated by the rules for empty, shallow and |
1215 clause. |
1192 deep binding clauses: |
1216 |
1193 % |
1217 \begin{equation}\label{deepbinder} |
1194 \begin{equation}\label{deepbinder} |
1218 \mbox{% |
1195 \mbox{% |
1219 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1196 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1220 \multicolumn{2}{@ {}l}{Empty binding clauses of the form |
1197 \multicolumn{2}{@ {}l}{\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ |
1221 \isacommand{bind\_set}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ |
|
1222 $\bullet$ & @{term "v = fv_ty y"} provided @{text "y"} is of type @{text "ty"}\smallskip\\ |
1198 $\bullet$ & @{term "v = fv_ty y"} provided @{text "y"} is of type @{text "ty"}\smallskip\\ |
1223 \multicolumn{2}{@ {}l}{Shallow binders of the form |
1199 |
1224 \isacommand{bind\_set}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "y\<^isub>1\<dots>y\<^isub>m"}:}\\ |
1200 \multicolumn{2}{@ {}l}{\isacommand{bind}~@{text "x\<^isub>1..x\<^isub>n"}~\isacommand{in}~@{text "y\<^isub>1..y\<^isub>m"}:}\\ |
1225 $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> fv_ty\<^isub>m y\<^isub>m) - (x\<^isub>1 \<union> \<dots> \<union> x\<^isub>n)"} |
1201 $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> .. \<union> fv_ty\<^isub>m y\<^isub>m)"}\\ |
1226 provided the @{text "y\<^isub>i"} are of type @{text "ty\<^isub>i"}\smallskip\\ |
1202 & \hspace{10mm}@{text "- (fv_aty\<^isub>1 x\<^isub>1 \<union> .. \<union> fv_aty\<^isub>n x\<^isub>n)"}\\ |
1227 \multicolumn{2}{@ {}l}{Deep binders of the form |
1203 & provided the bodies @{text "y"}$_{1..m}$ are of type @{text "ty"}$_{1..m}$ and the |
1228 \isacommand{bind\_set}~@{text "bn x"}~\isacommand{in}~@{text "y\<^isub>1\<dots>y\<^isub>m"}:}\\ |
1204 binders @{text "x"}$_{1..n}$ of atomic types @{text "aty"}$_{1..n}$\smallskip\\ |
1229 $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> fv_ty\<^isub>m y\<^isub>m) - (bn x) \<union> (fv_bn x)"}\\ |
1205 |
1230 $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> fv_ty\<^isub>m y\<^isub>m) - (bn x)"}\\ |
1206 \multicolumn{2}{@ {}l}{\isacommand{bind}~@{text "bn x"}~\isacommand{in}~@{text "y\<^isub>1..y\<^isub>m"}:}\\ |
|
1207 $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> .. \<union> fv_ty\<^isub>m y\<^isub>m) - (bn x) \<union> (fv_bn x)"}\\ |
|
1208 $\bullet$ & @{text "v = (fv_ty\<^isub>1 y\<^isub>1 \<union> .. \<union> fv_ty\<^isub>m y\<^isub>m) - (bn x)"}\\ |
1231 & provided the @{text "y\<^isub>i"} are of type @{text "ty\<^isub>i"}; the first |
1209 & provided the @{text "y\<^isub>i"} are of type @{text "ty\<^isub>i"}; the first |
1232 clause applies for @{text x} being a non-recursive deep binder, the |
1210 clause applies for @{text x} being a non-recursive deep binder, the |
1233 second for a recursive deep binder |
1211 second for a recursive deep binder |
1234 \end{tabular}} |
1212 \end{tabular}} |
1235 \end{equation} |
1213 \end{equation} |
1236 |
1214 |
1237 \noindent |
1215 \noindent |
1238 Similarly for the other binding modes. Note that in a non-recursive deep |
1216 Similarly for the other binding modes. Note that in a non-recursive deep |
1239 binder, we have to add all atoms that are left unbound by the binding |
1217 binder, we have to add all atoms that are left unbound by the binding |
1240 function @{text "bn"}. For this we use the function @{text "fv_bn"}. Assume |
1218 function @{text "bn"}. For this we define the function @{text "fv_bn"}. Assume |
1241 for the constructor @{text "C"} the binding function equation is of the form @{text |
1219 for the constructor @{text "C"} the binding function is of the form @{text |
1242 "bn\<^isub>j (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}. We again define a value |
1220 "bn\<^isub>j (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}. We again define a value |
1243 @{text v} which is exactly as in \eqref{deepbinder} for shallow and deep |
1221 @{text v} which is exactly as in \eqref{deepbinder} for shallow and deep |
1244 binders. We only modify the clause for empty binding clauses as follows: |
1222 binding clauses, except for empty binding clauses are defined as follows: |
1245 |
1223 % |
1246 |
|
1247 \begin{equation}\label{bnemptybinder} |
1224 \begin{equation}\label{bnemptybinder} |
1248 \mbox{% |
1225 \mbox{% |
1249 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1226 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1250 \multicolumn{2}{@ {}l}{Empty binding clauses of the form |
1227 \multicolumn{2}{@ {}l}{\isacommand{bind\_set}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ |
1251 \isacommand{bind\_set}~@{term "{}"}~\isacommand{in}~@{text "y"}:}\\ |
1228 $\bullet$ & @{term "v = fv_ty y"} provided @{text "y"} does not occur in @{text "rhs"} |
1252 $\bullet$ & @{term "v = fv_ty\<^isub>i y"} provided @{text "y"} does not occur in @{text "rhs"} |
1229 and the free-variable function for the type of @{text "y"} is @{text "fv_ty"}\\ |
1253 and the free-variable function for the type of @{text "y"} is @{text "fv_ty\<^isub>i"}\\ |
1230 $\bullet$ & @{term "v = fv_bn y"} provided @{text "y"} occurs in @{text "rhs"} |
1254 $\bullet$ & @{term "v = fv_bn\<^isub>i y"} provided @{text "y"} occurs in @{text "rhs"} |
1231 with a recursive call @{text "bn y"}\\ |
1255 with a recursive call @{text "bn\<^isub>i y"}\\ |
|
1256 $\bullet$ & @{term "v = {}"} provided @{text "y"} occurs in @{text "rhs"}, |
1232 $\bullet$ & @{term "v = {}"} provided @{text "y"} occurs in @{text "rhs"}, |
1257 but without a recursive call\\ |
1233 but without a recursive call\\ |
1258 \end{tabular}} |
1234 \end{tabular}} |
1259 \end{equation} |
1235 \end{equation} |
1260 |
1236 |