112 |
112 |
113 \noindent |
113 \noindent |
114 and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of |
114 and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of |
115 type-variables. While it is possible to implement this kind of more general |
115 type-variables. While it is possible to implement this kind of more general |
116 binders by iterating single binders, like @{text "\<forall>x\<^isub>1.\<forall>x\<^isub>2...\<forall>x\<^isub>n.T"}, this leads to a rather clumsy |
116 binders by iterating single binders, like @{text "\<forall>x\<^isub>1.\<forall>x\<^isub>2...\<forall>x\<^isub>n.T"}, this leads to a rather clumsy |
117 formalisation of W. For example, the usual definition when a |
117 formalisation of W. For example, the usual definition for a |
118 type is an instance of a type-scheme requires in the iterated version |
118 type being an instance of a type-scheme requires in the iterated version |
119 the following auxiliary \emph{unbinding relation} |
119 the following auxiliary \emph{unbinding relation}: |
120 |
120 |
121 \[ |
121 \[ |
122 \infer{@{text T} \hookrightarrow ([], @{text T})}{}\qquad |
122 \infer{@{text T} \hookrightarrow ([], @{text T})}{}\qquad |
123 \infer{\forall @{text x.S} \hookrightarrow (@{text x}\!::\!@{text xs}, @{text T})} |
123 \infer{\forall @{text x.S} \hookrightarrow (@{text x}\!::\!@{text xs}, @{text T})} |
124 {@{text S} \hookrightarrow (@{text xs}, @{text T})} |
124 {@{text S} \hookrightarrow (@{text xs}, @{text T})} |
125 \]\smallskip |
125 \]\smallskip |
126 |
126 |
127 \noindent |
127 \noindent |
128 Its purpose is to relate a type-scheme with a list of type-variables and a type. It is used to |
128 Its purpose is to relate a type-scheme with a list of type-variables and a type. It is used to |
129 address the following problem: |
129 address the following problem: |
130 Given a type-scheme @{text S}, how does one get access to the bound type-variables |
130 Given a type-scheme, say @{text S}, how does one get access to the bound type-variables |
131 and the type-part of @{text S}? The unbinding relation gives an answer, though in general |
131 and the type-part of @{text S}? The unbinding relation gives an answer to this problem, though |
132 we will only get access to some type-variables and some type that are |
132 in general it will only provide some list of type-variables together with a type that are |
133 ``alpha-equivalent'' to @{text S}. This is because unbinding is a relation; it cannot be a function |
133 ``alpha-equivalent'' to @{text S}. This is because unbinding is a relation; it cannot be a function |
134 for alpha-equated type-schemes. |
134 for alpha-equated type-schemes. With this |
135 Still, with this |
135 definition in place we can formally define when a type is an instance of a type-scheme as follows: |
136 definition in place we can formally define when a type is an instance of a type-scheme |
|
137 as follows: |
|
138 |
136 |
139 \[ |
137 \[ |
140 @{text "T \<prec> S \<equiv> \<exists>xs T' \<sigma>. S \<hookrightarrow> (xs, T') \<and> dom \<sigma> = set xs \<and> \<sigma>(T') = T"} |
138 @{text "T \<prec> S \<equiv> \<exists>xs T' \<sigma>. S \<hookrightarrow> (xs, T') \<and> dom \<sigma> = set xs \<and> \<sigma>(T') = T"} |
141 \]\smallskip |
139 \]\smallskip |
142 |
140 |
143 \noindent |
141 \noindent |
144 This means there exists a list of type-variables @{text xs} and a type @{text T'} to which |
142 This means there exists a list of type-variables @{text xs} and a type @{text T'} to which |
145 the type-scheme @{text S} unbinds, and there exists a substitution whose domain is |
143 the type-scheme @{text S} unbinds, and there exists a substitution @{text "\<sigma>"} whose domain is |
146 @{text xs} (seen as set) such that @{text "\<sigma>(T') = T"}. |
144 @{text xs} (seen as set) such that @{text "\<sigma>(T') = T"}. |
147 The problem with this definition is that we cannot follow the usual proofs |
145 The problem with this definition is that we cannot follow the usual proofs |
148 that are by induction on the type-part of the type-scheme (since it is under |
146 that are by induction on the type-part of the type-scheme (since it is under |
149 an existential quantifier and only an alpha-variant). The representation of |
147 an existential quantifier and only an alpha-variant). The representation of |
150 type-schemes using iterations of single binders |
148 type-schemes using iterations of single binders |
151 prevents us from directly ``unbinding'' the bound type-variables and the type-part. |
149 prevents us from directly ``unbinding'' the bound type-variables and the type-part. |
|
150 Clearly, some more dignified approach to formalising algorithm W is desirable. |
152 The purpose of this paper is to introduce general binders, which |
151 The purpose of this paper is to introduce general binders, which |
153 allow us to represent type-schemes so that they can bind multiple variables at once |
152 allow us to represent type-schemes so that they can bind multiple variables at once |
154 and as a result solve this problem. |
153 and as a result solve this problem more straightforwardly. |
155 The need of iterating single binders is also one reason |
154 The need of iterating single binders is also one reason |
156 why Nominal Isabelle and similar theorem provers that only provide |
155 why Nominal Isabelle and similar theorem provers that only provide |
157 mechanisms for binding single variables have so far not fared very well with |
156 mechanisms for binding single variables have so far not fared very well with |
158 the more advanced tasks in the POPLmark challenge \cite{challenge05}, |
157 the more advanced tasks in the POPLmark challenge \cite{challenge05}, |
159 because also there one would like to bind multiple variables at once. |
158 because also there one would like to bind multiple variables at once. |
507 two-place permutation operation written |
506 two-place permutation operation written |
508 @{text "_ \<bullet> _ "} and having the type @{text "perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} |
507 @{text "_ \<bullet> _ "} and having the type @{text "perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} |
509 where the generic type @{text "\<beta>"} is the type of the object |
508 where the generic type @{text "\<beta>"} is the type of the object |
510 over which the permutation |
509 over which the permutation |
511 acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"}, |
510 acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"}, |
512 the composition of two permutations @{term "\<pi>\<^isub>1"} and @{term "\<pi>\<^isub>2"} as \mbox{@{term "\<pi>\<^isub>1 + \<pi>\<^isub>2"}}, |
511 the composition of two permutations @{term "\<pi>\<^isub>1"} and @{term "\<pi>\<^isub>2"} as \mbox{@{term "\<pi>\<^isub>1 + \<pi>\<^isub>2"}} |
|
512 (even if this operation is non-commutative), |
513 and the inverse permutation of @{term "\<pi>"} as @{text "- \<pi>"}. The permutation |
513 and the inverse permutation of @{term "\<pi>"} as @{text "- \<pi>"}. The permutation |
514 operation is defined over Isabelle/HOL's type-hierarchy \cite{HuffmanUrban10}; |
514 operation is defined over Isabelle/HOL's type-hierarchy \cite{HuffmanUrban10}; |
515 for example permutations acting on atoms, products, lists, permutations, sets, |
515 for example permutations acting on atoms, products, lists, permutations, sets, |
516 functions and booleans are given by: |
516 functions and booleans are given by: |
517 |
517 |
1230 Consequently we exclude specifications such as |
1230 Consequently we exclude specifications such as |
1231 |
1231 |
1232 \[\mbox{ |
1232 \[\mbox{ |
1233 \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}} |
1233 \begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}} |
1234 @{text "Baz\<^isub>1 p::pat t::trm"} & |
1234 @{text "Baz\<^isub>1 p::pat t::trm"} & |
1235 \isacommand{binds} @{text "bn\<^isub>1(p) bn\<^isub>2(p)"} \isacommand{in} @{text t}\\ |
1235 \isacommand{binds} @{text "bn\<^isub>1(p) bn\<^isub>2(p)"} \isacommand{in} @{text "p t"}\\ |
1236 @{text "Baz\<^isub>2 p::pat t\<^isub>1::trm t\<^isub>2::trm"} & |
1236 @{text "Baz\<^isub>2 p::pat t\<^isub>1::trm t\<^isub>2::trm"} & |
1237 \isacommand{binds} @{text "bn\<^isub>1(p)"} \isacommand{in} @{text "t\<^isub>1"}, |
1237 \isacommand{binds} @{text "bn\<^isub>1(p)"} \isacommand{in} @{text "p t\<^isub>1"}, |
1238 \isacommand{binds} @{text "bn\<^isub>2(p)"} \isacommand{in} @{text "t\<^isub>2"}\\ |
1238 \isacommand{binds} @{text "bn\<^isub>2(p)"} \isacommand{in} @{text "p t\<^isub>2"}\\ |
1239 \end{tabular}} |
1239 \end{tabular}} |
1240 \]\smallskip |
1240 \]\smallskip |
1241 |
1241 |
1242 \noindent |
1242 \noindent |
1243 Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} pick |
1243 Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} pick |
1244 out different atoms to become bound, respectively be free, |
1244 out different atoms to become bound, respectively be free, |
1245 in @{text "p"}.\footnote{Although harmless, in our implementation |
1245 in @{text "p"}.\footnote{Since the Ott-tool does not derive a reasoning |
1246 we exlude such specifications even |
|
1247 if @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} are the same binding |
|
1248 functions.}$^,$\footnote{Since the Ott-tool does not derive a reasoning |
|
1249 infrastructure for |
1246 infrastructure for |
1250 alpha-equated terms with deep binders, it can permit such specifications.} |
1247 alpha-equated terms with deep binders, it can permit such specifications.} |
1251 |
1248 |
1252 |
1249 |
1253 We also need to restrict the form of the binding functions in order to |
1250 We also need to restrict the form of the binding functions in order to |
1289 empty set or empty list (as in case @{text ANil'}), a singleton set or |
1286 empty set or empty list (as in case @{text ANil'}), a singleton set or |
1290 singleton list containing an atom (case @{text PVar} in \eqref{letpat}), or |
1287 singleton list containing an atom (case @{text PVar} in \eqref{letpat}), or |
1291 unions of atom sets or appended atom lists (case @{text ACons'}). This |
1288 unions of atom sets or appended atom lists (case @{text ACons'}). This |
1292 restriction will simplify some automatic definitions and proofs later on. |
1289 restriction will simplify some automatic definitions and proofs later on. |
1293 |
1290 |
1294 In order to simplify our definitions of free atoms and alpha-equivalence, |
1291 To sum up this section, we introduced nominal datatype |
1295 we shall assume specifications |
1292 specifications, which are like standard datatype specifications in |
1296 of term-calculi are implicitly \emph{completed}. By this we mean that |
1293 Isabelle/HOL extended with specifications for binding |
1297 for every argument of a term-constructor that is \emph{not} |
1294 functions. Each constructor argument in our specification can also |
1298 already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding |
1295 have an optional label. These labels are used in the binding clauses |
1299 clause, written \isacommand{binds}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case |
1296 of a constructor; there can be several binding clauses for each |
1300 of the lambda-terms, the completion produces |
1297 constructor, but bodies of binding clauses can only occur in a |
|
1298 single one. Binding clauses come in three modes: \isacommand{binds}, |
|
1299 \isacommand{binds (set)} and \isacommand{binds (set+)}. Binders |
|
1300 fall into two categories: shallow binders and deep binders. Shallow |
|
1301 binders can occur in more than one binding clause and only have to |
|
1302 respect the binding mode (i.e.~be of the right type). Deep binders |
|
1303 can also occur in more than one binding clause, unless they are |
|
1304 recursive in which case they can only occur once. Each of the deep |
|
1305 binders can only have a single binding function. Binding functions |
|
1306 are defined by recursion over a nominal datatype. They can only |
|
1307 return the empty set, singleton atoms and unions of sets of atoms |
|
1308 (for binding modes \isacommand{binds (set)} and \isacommand{binds |
|
1309 (set+)}), and the empty list, singleton atoms and appended lists of |
|
1310 atoms (for mode \isacommand{bind}). However, they can only return |
|
1311 atoms that are not mentioned in any binding clause. In order to |
|
1312 simplify our definitions of free atoms and alpha-equivalence, we |
|
1313 shall assume specifications of term-calculi are implicitly |
|
1314 \emph{completed}. By this we mean that for every argument of a |
|
1315 term-constructor that is \emph{not} already part of a binding clause |
|
1316 given by the user, we add implicitly a special \emph{empty} binding |
|
1317 clause, written \isacommand{binds}~@{term |
|
1318 "{}"}~\isacommand{in}~@{text "labels"}. In case of the lambda-terms, |
|
1319 the completion produces |
1301 |
1320 |
1302 \[\mbox{ |
1321 \[\mbox{ |
1303 \begin{tabular}{@ {}l@ {\hspace{-1mm}}} |
1322 \begin{tabular}{@ {}l@ {\hspace{-1mm}}} |
1304 \isacommand{nominal\_datatype} @{text lam} =\\ |
1323 \isacommand{nominal\_datatype} @{text lam} =\\ |
1305 \hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"} |
1324 \hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"} |