88 easily by iterating single binders. For example in the case of type-schemes we do not |
88 easily by iterating single binders. For example in the case of type-schemes we do not |
89 want to make a distinction about the order of the bound variables. Therefore |
89 want to make a distinction about the order of the bound variables. Therefore |
90 we would like to regard the following two type-schemes as $\alpha$-equivalent |
90 we would like to regard the following two type-schemes as $\alpha$-equivalent |
91 % |
91 % |
92 \begin{equation}\label{ex1} |
92 \begin{equation}\label{ex1} |
93 @{text "\<forall>{x, y}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{y, x}. y \<rightarrow> x"} |
93 @{text "\<forall>{x, y}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{y, x}. x \<rightarrow> y"} |
94 \end{equation} |
94 \end{equation} |
95 |
95 |
96 \noindent |
96 \noindent |
97 but assuming that @{text x}, @{text y} and @{text z} are distinct variables, |
97 but assuming that @{text x}, @{text y} and @{text z} are distinct variables, |
98 the following two should \emph{not} be $\alpha$-equivalent |
98 the following two should \emph{not} be $\alpha$-equivalent |
212 |
212 |
213 \noindent |
213 \noindent |
214 The scope of the binding is indicated by labels given to the types, for |
214 The scope of the binding is indicated by labels given to the types, for |
215 example @{text "s::trm"}, and a binding clause, in this case |
215 example @{text "s::trm"}, and a binding clause, in this case |
216 \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding |
216 \isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding |
217 clause states to bind in @{text s} all the names the function @{text |
217 clause states that all the names the function @{text |
218 "bn(as)"} returns. This style of specifying terms and bindings is heavily |
218 "bn(as)"} returns should be bound in @{text s}. This style of specifying terms and bindings is heavily |
219 inspired by the syntax of the Ott-tool \cite{ott-jfp}. |
219 inspired by the syntax of the Ott-tool \cite{ott-jfp}. |
220 |
220 |
221 However, we will not be able to cope with all specifications that are |
221 However, we will not be able to cope with all specifications that are |
222 allowed by Ott. One reason is that Ott lets the user specify ``empty'' |
222 allowed by Ott. One reason is that Ott lets the user specify ``empty'' |
223 types like |
223 types like |
356 be bound. Another is that each bound variable comes with a kind or type |
356 be bound. Another is that each bound variable comes with a kind or type |
357 annotation. Representing such binders with single binders and reasoning |
357 annotation. Representing such binders with single binders and reasoning |
358 about them in a theorem prover would be a major pain. \medskip |
358 about them in a theorem prover would be a major pain. \medskip |
359 |
359 |
360 \noindent |
360 \noindent |
361 {\bf Contributions:} We provide novel definitions for when terms |
361 {\bf Contributions:} We provide novel three definitions for when terms |
362 involving general binders are $\alpha$-equivalent. These definitions are |
362 involving general binders are $\alpha$-equivalent. These definitions are |
363 inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic |
363 inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic |
364 proofs, we establish a reasoning infrastructure for $\alpha$-equated |
364 proofs, we establish a reasoning infrastructure for $\alpha$-equated |
365 terms, including properties about support, freshness and equality |
365 terms, including properties about support, freshness and equality |
366 conditions for $\alpha$-equated terms. We are also able to derive strong |
366 conditions for $\alpha$-equated terms. We are also able to derive strong |
367 induction principles that have the variable convention already built in. |
367 induction principles that have the variable convention already built in. |
368 The method behind our specification of general binders is taken |
368 The method behind our specification of general binders is taken |
369 from the Ott-tool, but we introduce crucial restrictions, and also one extension, so |
369 from the Ott-tool, but we introduce crucial restrictions, and also extensions, so |
370 that our specifications make sense for reasoning about $\alpha$-equated terms. |
370 that our specifications make sense for reasoning about $\alpha$-equated terms. |
371 |
371 |
372 |
372 |
373 \begin{figure} |
373 \begin{figure} |
374 \begin{boxedminipage}{\linewidth} |
374 \begin{boxedminipage}{\linewidth} |
1024 \end{tabular}} |
1024 \end{tabular}} |
1025 \end{equation} |
1025 \end{equation} |
1026 |
1026 |
1027 \noindent |
1027 \noindent |
1028 In this specification the function @{text "bn"} determines which atoms of |
1028 In this specification the function @{text "bn"} determines which atoms of |
1029 @{text p} are bound in the argument @{text "t"}. Note that in the |
1029 the pattern @{text p} are bound in the argument @{text "t"}. Note that in the |
1030 second-last @{text bn}-clause the function @{text "atom"} coerces a name |
1030 second-last @{text bn}-clause the function @{text "atom"} coerces a name |
1031 into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This |
1031 into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This |
1032 allows us to treat binders of different atom type uniformly. |
1032 allows us to treat binders of different atom type uniformly. |
1033 |
1033 |
1034 As said above, for deep binders we allow binding clauses such as |
1034 As said above, for deep binders we allow binding clauses such as |
1065 \end{equation} |
1065 \end{equation} |
1066 |
1066 |
1067 \noindent |
1067 \noindent |
1068 The difference is that with @{text Let} we only want to bind the atoms @{text |
1068 The difference is that with @{text Let} we only want to bind the atoms @{text |
1069 "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms |
1069 "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms |
1070 inside the assignment. This difference has consequences for the free-variable |
1070 inside the assignment. This difference has consequences for the associated |
1071 function and $\alpha$-equivalence relation. |
1071 notions of free-variables and $\alpha$-equivalence. |
1072 |
1072 |
1073 To make sure that variables bound by deep binders cannot be free at the |
1073 To make sure that variables bound by deep binders cannot be free at the |
1074 same time, we cannot have more than one binding function for one deep binder. |
1074 same time, we cannot have more than one binding function for a deep binder. |
1075 Consequently we exclude specifications such as |
1075 Consequently we exclude specifications such as |
1076 |
1076 |
1077 \begin{center} |
1077 \begin{center} |
1078 \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}} |
1078 \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}} |
1079 @{text "Baz\<^isub>1 p::pat t::trm"} & |
1079 @{text "Baz\<^isub>1 p::pat t::trm"} & |
1088 Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} pick |
1088 Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} pick |
1089 out different atoms to become bound, respectively be free, in @{text "p"}. |
1089 out different atoms to become bound, respectively be free, in @{text "p"}. |
1090 |
1090 |
1091 We also need to restrict the form of the binding functions in order |
1091 We also need to restrict the form of the binding functions in order |
1092 to ensure the @{text "bn"}-functions can be defined for $\alpha$-equated |
1092 to ensure the @{text "bn"}-functions can be defined for $\alpha$-equated |
1093 terms. As a result we cannot return an atom in a binding function that is also |
1093 terms. The main restriction is that we cannot return an atom in a binding function that is also |
1094 bound in the corresponding term-constructor. That means in the example |
1094 bound in the corresponding term-constructor. That means in \eqref{letpat} |
1095 \eqref{letpat} that the term-constructors @{text PVar} and @{text PTup} may |
1095 that the term-constructors @{text PVar} and @{text PTup} may |
1096 not have a binding clause (all arguments are used to define @{text "bn"}). |
1096 not have a binding clause (all arguments are used to define @{text "bn"}). |
1097 In contrast, in case of \eqref{letrecs} the term-constructor @{text ACons} |
1097 In contrast, in case of \eqref{letrecs} the term-constructor @{text ACons} |
1098 may have a binding clause involving the argument @{text t} (the only one that |
1098 may have a binding clause involving the argument @{text t} (the only one that |
1099 is \emph{not} used in the definition of the binding function). This restriction |
1099 is \emph{not} used in the definition of the binding function). This restriction |
1100 is sufficient for defining the binding function over $\alpha$-equated terms. |
1100 is sufficient for defining the binding function over $\alpha$-equated terms. |
1141 Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just |
1141 Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just |
1142 re-arranging the arguments of |
1142 re-arranging the arguments of |
1143 term-constructors so that binders and their bodies are next to each other will |
1143 term-constructors so that binders and their bodies are next to each other will |
1144 result in inadequate representations in cases like @{text "Let x\<^isub>1=t\<^isub>1\<dots>x\<^isub>n=t\<^isub>n in s"}. |
1144 result in inadequate representations in cases like @{text "Let x\<^isub>1=t\<^isub>1\<dots>x\<^isub>n=t\<^isub>n in s"}. |
1145 Therefore we will first |
1145 Therefore we will first |
1146 extract datatype definitions from the specification and then define |
1146 extract ``raw'' datatype definitions from the specification and then define |
1147 explicitly an $\alpha$-equivalence relation over them. We subsequently |
1147 explicitly an $\alpha$-equivalence relation over them. We subsequently |
1148 quotient the datatypes according to our $\alpha$-equivalence. |
1148 quotient the datatypes according to our $\alpha$-equivalence. |
1149 |
1149 |
1150 |
1150 |
1151 The datatype definition can be obtained by stripping off the |
1151 The ``raw'' datatype definition can be obtained by stripping off the |
1152 binding clauses and the labels from the types. We also have to invent |
1152 binding clauses and the labels from the types. We also have to invent |
1153 new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"} |
1153 new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"} |
1154 given by the user. In our implementation we just use the affix ``@{text "_raw"}''. |
1154 given by the user. In our implementation we just use the affix ``@{text "_raw"}''. |
1155 But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate |
1155 But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate |
1156 that a notion is defined over $\alpha$-equivalence classes and leave it out |
1156 that a notion is defined over $\alpha$-equivalence classes and leave it out |
1177 @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"} |
1177 @{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"} |
1178 \end{equation} |
1178 \end{equation} |
1179 |
1179 |
1180 The first non-trivial step we have to perform is the generation of |
1180 The first non-trivial step we have to perform is the generation of |
1181 free-variable functions from the specifications. For the |
1181 free-variable functions from the specifications. For the |
1182 \emph{raw} types @{text "ty"}$_{1..n}$ extracted from a specification, |
1182 \emph{raw} types @{text "ty"}$_{1..n}$ we define the free-variable functions |
1183 we define the free-variable functions |
|
1184 % |
1183 % |
1185 \begin{equation}\label{fvars} |
1184 \begin{equation}\label{fvars} |
1186 @{text "fv_ty\<^isub>1, \<dots>, fv_ty\<^isub>n"} |
1185 @{text "fv_ty\<^isub>1, \<dots>, fv_ty\<^isub>n"} |
1187 \end{equation} |
1186 \end{equation} |
1188 |
1187 |
1189 \noindent |
1188 \noindent |
1190 by recursion over the types @{text "ty"}$_{1..n}$. |
1189 by mutual recursion. |
1191 We define these functions together with auxiliary free-variable functions for |
1190 We define these functions together with auxiliary free-variable functions for |
1192 the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ |
1191 the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$ |
1193 we define |
1192 we define |
1194 % |
1193 % |
1195 \begin{center} |
1194 \begin{center} |
1202 that calculates those unbound atoms in a deep binder. |
1201 that calculates those unbound atoms in a deep binder. |
1203 |
1202 |
1204 While the idea behind these free-variable functions is clear (they just |
1203 While the idea behind these free-variable functions is clear (they just |
1205 collect all atoms that are not bound), because of our rather complicated |
1204 collect all atoms that are not bound), because of our rather complicated |
1206 binding mechanisms their definitions are somewhat involved. Given |
1205 binding mechanisms their definitions are somewhat involved. Given |
1207 the term-constructor @{text "C"} of type @{text ty} and some associated |
1206 a term-constructor @{text "C"} of type @{text ty} and some associated |
1208 binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text |
1207 binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text |
1209 "fv_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text |
1208 "fv_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text |
1210 "fv(bc\<^isub>1) \<union> \<dots> \<union> fv(bc\<^isub>k)"} where we define below what @{text "fv"} of a binding |
1209 "fv(bc\<^isub>1) \<union> \<dots> \<union> fv(bc\<^isub>k)"} where we define below what @{text "fv"} of a binding |
1211 clause with mode \isacommand{bin\_set} means (similarly for the other modes). |
1210 clause means. We only show the mode \isacommand{bind\_set} (the other modes are similar). |
1212 Suppose the binding clause @{text bc\<^isub>i} is of the form |
1211 Suppose the binding clause @{text bc\<^isub>i} is of the form |
1213 % |
1212 % |
1214 \begin{equation} |
1213 \begin{equation} |
1215 \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}} |
1214 \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}} |
1216 \end{equation} |
1215 \end{equation} |
1237 \end{center} |
1236 \end{center} |
1238 |
1237 |
1239 \noindent |
1238 \noindent |
1240 whereby the functions @{text "fv_ty\<^isub>i"} are the ones we are defining by recursion |
1239 whereby the functions @{text "fv_ty\<^isub>i"} are the ones we are defining by recursion |
1241 (see \eqref{fvars}) provided the @{text "d\<^isub>i"} refers to one of the raw types |
1240 (see \eqref{fvars}) provided the @{text "d\<^isub>i"} refers to one of the raw types |
1242 @{text "ty"}$_{1..n}$ from a specification; otherwise we set @{text "fv_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}. |
1241 @{text "ty"}$_{1..n}$ from the specification; otherwise we set @{text "fv_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}. |
1243 In order to define the set @{text B} we use the following auxiliary @{text "bn"}-functions |
1242 In order to define the set @{text B} we use the following auxiliary @{text "bn"}-functions |
1244 for atom types to which shallow binders have to refer |
1243 for atom types to which shallow binders have to refer |
1245 % |
1244 % |
1246 \begin{center} |
1245 \begin{center} |
1247 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1246 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |