1199 \end{center} |
1199 \end{center} |
1200 |
1200 |
1201 \noindent |
1201 \noindent |
1202 The reason for this setup is that in a deep binder not all atoms have to be |
1202 The reason for this setup is that in a deep binder not all atoms have to be |
1203 bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function |
1203 bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function |
1204 that calculates those unbound atoms in a deep binder. |
1204 that calculates those free atoms in a deep binder. |
1205 |
1205 |
1206 While the idea behind these free-atom functions is clear (they just |
1206 While the idea behind these free-atom functions is clear (they just |
1207 collect all atoms that are not bound), because of our rather complicated |
1207 collect all atoms that are not bound), because of our rather complicated |
1208 binding mechanisms their definitions are somewhat involved. Given |
1208 binding mechanisms their definitions are somewhat involved. Given |
1209 a term-constructor @{text "C"} of type @{text ty} and some associated |
1209 a term-constructor @{text "C"} of type @{text ty} and some associated |
1210 binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text |
1210 binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text |
1211 "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text |
1211 "fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text |
1212 "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we define below what @{text "fa"} for a binding |
1212 "fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we will define below what @{text "fa"} for a binding |
1213 clause means. We only show the details for the mode \isacommand{bind\_set} (the other modes are similar). |
1213 clause means. We only show the details for the mode \isacommand{bind\_set} (the other modes are similar). |
1214 Suppose the binding clause @{text bc\<^isub>i} is of the form |
1214 Suppose the binding clause @{text bc\<^isub>i} is of the form |
1215 % |
1215 % |
1216 \begin{equation} |
1216 \begin{center} |
1217 \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}} |
1217 \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}} |
1218 \end{equation} |
1218 \end{center} |
1219 |
1219 |
1220 \noindent |
1220 \noindent |
1221 in which the body-labels @{text "d"}$_{1..q}$ refer to types @{text ty}$_{1..q}$, |
1221 in which the body-labels @{text "d"}$_{1..q}$ refer to types @{text ty}$_{1..q}$, |
1222 and the binders @{text b}$_{1..p}$ |
1222 and the binders @{text b}$_{1..p}$ |
1223 either refer to labels of atom types (in case of shallow binders) or to binding |
1223 either refer to labels of atom types (in case of shallow binders) or to binding |
1224 functions taking a single label as argument (in case of deep binders). Assuming the |
1224 functions taking a single label as argument (in case of deep binders). Assuming |
1225 set @{text "D"} stands for the free atoms in the bodies, the set @{text B} for the |
1225 @{text "D"} stands for the set of free atoms of the bodies, @{text B} for the |
1226 binding atoms in the binders and @{text "B'"} for the free atoms in |
1226 set of binding atoms in the binders and @{text "B'"} for the set of free atoms in |
1227 non-recursive deep binders, |
1227 non-recursive deep binders, |
1228 then the free atoms of the binding clause @{text bc\<^isub>i} are given by |
1228 then the free atoms of the binding clause @{text bc\<^isub>i} are |
1229 % |
1229 % |
1230 \begin{center} |
1230 \begin{equation}\label{fadef} |
1231 @{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"} |
1231 \mbox{@{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}}. |
1232 \end{center} |
1232 \end{equation} |
1233 |
1233 |
1234 \noindent |
1234 \noindent |
1235 whereby the set @{text D} is formally defined as |
1235 The set @{text D} is formally defined as |
1236 % |
1236 % |
1237 \begin{center} |
1237 \begin{center} |
1238 @{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"} |
1238 @{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"} |
1239 \end{center} |
1239 \end{center} |
1240 |
1240 |
1241 \noindent |
1241 \noindent |
1242 The functions @{text "fa_ty\<^isub>i"} are the ones we are defining by recursion |
1242 where in case @{text "d\<^isub>i"} refers to one of the raw types @{text "ty"}$_{1..n}$ from the |
1243 (see \eqref{fvars}) in case the @{text "d\<^isub>i"} refers to one of the raw types |
1243 specification, the function @{text "fa_ty\<^isub>i"} is the corresponding free-atom function |
1244 @{text "ty"}$_{1..n}$ from the specification; otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}. |
1244 we are defining by recursion |
1245 In order to define the set @{text B} we use the following auxiliary @{text "bn"}-functions |
1245 (see \eqref{fvars}); otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}. |
1246 for atom types to which shallow binders have to refer |
1246 |
|
1247 In order to formally define the set @{text B} we use the following auxiliary @{text "bn"}-functions |
|
1248 for atom types to which shallow binders may refer |
1247 % |
1249 % |
1248 \begin{center} |
1250 \begin{center} |
1249 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1251 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1250 @{text "bn_atom a"} & @{text "\<equiv>"} & @{text "{atom a}"}\\ |
1252 @{text "bn_atom a"} & @{text "\<equiv>"} & @{text "{atom a}"}\\ |
1251 @{text "bn_atom_set as"} & @{text "\<equiv>"} & @{text "atoms as"}\\ |
1253 @{text "bn_atom_set as"} & @{text "\<equiv>"} & @{text "atoms as"}\\ |
1252 @{text "bn_atom_list as"} & @{text "\<equiv>"} & @{text "atoms (set as)"} |
1254 @{text "bn_atom_list as"} & @{text "\<equiv>"} & @{text "atoms (set as)"} |
1253 \end{tabular} |
1255 \end{tabular} |
1254 \end{center} |
1256 \end{center} |
1255 |
1257 |
1256 \noindent |
1258 \noindent |
1257 The function @{text "atoms"} coerces |
1259 Like the function @{text atom}, the function @{text "atoms"} coerces |
1258 the set of atoms to a set of the generic atom type. It is defined as |
1260 a set of atoms to a set of the generic atom type. It is defined as |
1259 @{text "atoms as \<equiv> {atom a | a \<in> as}"}. |
1261 @{text "atoms as \<equiv> {atom a | a \<in> as}"}. |
1260 The set @{text B} is then formally defined as |
1262 The set @{text B} is then formally defined as |
1261 % |
1263 % |
1262 \begin{center} |
1264 \begin{center} |
1263 @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"} |
1265 @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"} |
1264 \end{center} |
1266 \end{center} |
1265 |
1267 |
1266 \noindent |
1268 \noindent |
|
1269 where we use the auxiliary binding functions for shallow binders. |
1267 The set @{text "B'"} collects all free atoms in non-recursive deep |
1270 The set @{text "B'"} collects all free atoms in non-recursive deep |
1268 binders. Let us assume these binders in @{text "bc\<^isub>i"} are |
1271 binders. Let us assume these binders in @{text "bc\<^isub>i"} are |
1269 % |
1272 % |
1270 \begin{center} |
1273 \begin{center} |
1271 @{text "bn\<^isub>1 a\<^isub>1, \<dots>, bn\<^isub>r a\<^isub>r"} |
1274 @{text "bn\<^isub>1 l\<^isub>1, \<dots>, bn\<^isub>r l\<^isub>r"} |
1272 \end{center} |
1275 \end{center} |
1273 |
1276 |
1274 \noindent |
1277 \noindent |
1275 with none of the @{text "a"}$_{1..r}$ being among the bodies @{text |
1278 with none of the @{text "l"}$_{1..r}$ being among the bodies @{text |
1276 "d"}$_{1..q}$. The set @{text "B'"} is defined as |
1279 "d"}$_{1..q}$. The set @{text "B'"} is defined as |
1277 % |
1280 % |
1278 \begin{center} |
1281 \begin{center} |
1279 @{text "B' \<equiv> fa_bn\<^isub>1 a\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r a\<^isub>r"} |
1282 @{text "B' \<equiv> fa_bn\<^isub>1 l\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r l\<^isub>r"} |
1280 \end{center} |
1283 \end{center} |
1281 |
1284 |
1282 \noindent |
1285 \noindent |
1283 This completes the definition of the free-atom functions. |
1286 This completes the definition of the free-atom functions @{text "fa_ty"}$_{1..n}$. |
1284 |
1287 |
1285 Note that for non-recursive deep binders, we have to add all atoms that are left |
1288 Note that for non-recursive deep binders, we have to add in \eqref{fadef} |
1286 unbound by the binding function @{text "bn"} (the set @{text "B'"}). We use for this |
1289 the set of atoms that are left unbound by the binding functions @{text |
1287 the functions @{text "fa_bn"}, also defined by recursion. Assume the user specified |
1290 "bn"}$_{1..m}$. We use for the definition of |
1288 a @{text bn}-clause of the form |
1291 this set the functions @{text "fa_bn"}$_{1..m}$, which are also defined by mutual |
|
1292 recursion. Assume the user specified a @{text bn}-clause of the form |
1289 % |
1293 % |
1290 \begin{center} |
1294 \begin{center} |
1291 @{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"} |
1295 @{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"} |
1292 \end{center} |
1296 \end{center} |
1293 |
1297 |
1296 the arguments we calculate the free atoms as follows: |
1300 the arguments we calculate the free atoms as follows: |
1297 % |
1301 % |
1298 \begin{center} |
1302 \begin{center} |
1299 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1303 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
1300 $\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"} |
1304 $\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"} |
1301 (that means nothing is bound in @{text "z\<^isub>i"}),\\ |
1305 (that means nothing is bound in @{text "z\<^isub>i"} by the binding function),\\ |
1302 $\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"} |
1306 $\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"} |
1303 with the recursive call @{text "bn\<^isub>i z\<^isub>i"}, and\\ |
1307 with the recursive call @{text "bn\<^isub>i z\<^isub>i"}, and\\ |
1304 $\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"}, |
1308 $\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"}, |
1305 but without a recursive call. |
1309 but without a recursive call. |
1306 \end{tabular} |
1310 \end{tabular} |
1307 \end{center} |
1311 \end{center} |
1308 |
1312 |
1309 \noindent |
1313 \noindent |
1310 For defining @{text "fa_bn (C z\<^isub>1 \<dots> z\<^isub>n)"} we just union up all these values. |
1314 For defining @{text "fa_bn (C z\<^isub>1 \<dots> z\<^isub>n)"} we just union up all these sets. |
1311 |
1315 |
1312 To see how these definitions work in practice, let us reconsider the term-constructors |
1316 To see how these definitions work in practice, let us reconsider the |
1313 @{text "Let"} and @{text "Let_rec"}, as well as @{text "ANil"} and @{text "ACons"} |
1317 term-constructors @{text "Let"} and @{text "Let_rec"} shown in |
1314 from the example shown in \eqref{letrecs}. |
1318 \eqref{letrecs} together with the term-constructors for assignments @{text |
1315 For them we define three free-atom functions, namely |
1319 "ANil"} and @{text "ACons"}. Since there is a binding function defined for |
1316 @{text "fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text "fa\<^bsub>bn\<^esub>"} as follows: |
1320 assignments, we have three free-atom functions, namely @{text |
|
1321 "fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text |
|
1322 "fa\<^bsub>bn\<^esub>"} as follows: |
1317 % |
1323 % |
1318 \begin{center} |
1324 \begin{center} |
1319 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
1325 \begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}} |
1320 @{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\ |
1326 @{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\ |
1321 @{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] |
1327 @{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] |
1327 @{text "fa\<^bsub>bn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>bn\<^esub> as)"} |
1333 @{text "fa\<^bsub>bn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>bn\<^esub> as)"} |
1328 \end{tabular} |
1334 \end{tabular} |
1329 \end{center} |
1335 \end{center} |
1330 |
1336 |
1331 \noindent |
1337 \noindent |
1332 To see the pattern, recall that @{text ANil} and @{text "ACons"} have no |
1338 For these definitions, recall that @{text ANil} and @{text "ACons"} have no |
1333 binding clause in the specification. The corresponding free-atom |
1339 binding clause in the specification. The corresponding free-atom |
1334 function @{text "fa\<^bsub>assn\<^esub>"} therefore returns all atoms |
1340 function @{text "fa\<^bsub>assn\<^esub>"} therefore returns all free atoms |
1335 occurring in an assignment. The binding only takes place in @{text Let} and |
1341 occurring in an assignment (in case of @{text "ACons"}, they are given by |
1336 @{text "Let_rec"}. In the @{text "Let"}-clause, the binding clause specifies |
1342 calls to @{text supp}, @{text "fa\<^bsub>trm\<^esub>"} and @{text "fa\<^bsub>assn\<^esub>"}). |
|
1343 The binding only takes place in @{text Let} and |
|
1344 @{text "Let_rec"}. In case of @{text "Let"}, the binding clause specifies |
1337 that all atoms given by @{text "set (bn as)"} have to be bound in @{text |
1345 that all atoms given by @{text "set (bn as)"} have to be bound in @{text |
1338 t}. Therefore we have to subtract @{text "set (bn as)"} from @{text |
1346 t}. Therefore we have to subtract @{text "set (bn as)"} from @{text |
1339 "fa\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are |
1347 "fa\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are |
1340 free in @{text "as"}. In contrast, in @{text "Let_rec"} we have a recursive |
1348 free in @{text "as"}. This is |
1341 binder where we want to also bind all occurrences of the atoms in @{text |
1349 in contrast with @{text "Let_rec"} where we have a recursive |
|
1350 binder to bind all occurrences of the atoms in @{text |
1342 "set (bn as)"} also inside @{text "as"}. Therefore we have to subtract |
1351 "set (bn as)"} also inside @{text "as"}. Therefore we have to subtract |
1343 @{text "set (bn as)"} from the union @{text "fa\<^bsub>trm\<^esub> t"} and @{text "fa\<^bsub>assn\<^esub> as"}. |
1352 @{text "set (bn as)"} from both @{text "fa\<^bsub>trm\<^esub> t"} and @{text "fa\<^bsub>assn\<^esub> as"}. |
1344 |
1353 Like the function @{text "bn"}, the function @{text "fa\<^bsub>bn\<^esub>"} traverses the |
|
1354 list of assignments, but instead returns the free atoms, that means in this |
|
1355 example the free atoms in the argument @{text "t"}. |
|
1356 |
1345 An interesting point in this |
1357 An interesting point in this |
1346 example is that a ``naked'' assignment does not bind any |
1358 example is that a ``naked'' assignment (@{text "ANil"} or @{text "ACons"}) does not bind any |
1347 atoms. Only in the context of a @{text Let} or @{text "Let_rec"} will |
1359 atoms, even if the binding function is specified over assignments. |
1348 some atoms from an assignment become bound. This is a phenomenon that has also been pointed |
1360 Only in the context of a @{text Let} or @{text "Let_rec"}, where the binding clauses are given, will |
|
1361 some atoms actually become bound. This is a phenomenon that has also been pointed |
1349 out in \cite{ott-jfp}. For us this observation is crucial, because we would |
1362 out in \cite{ott-jfp}. For us this observation is crucial, because we would |
1350 not be able to lift the @{text "bn"}-function if it was defined over assignments |
1363 not be able to lift the @{text "bn"}-functions to $\alpha$-equated terms if they act on |
1351 where some atoms are bound. In that case @{text "bn"} would \emph{not} respect |
1364 atoms that are bound. In that case, these functions would \emph{not} respect |
1352 $\alpha$-equivalence. |
1365 $\alpha$-equivalence. |
1353 |
1366 |
1354 Next we define $\alpha$-equivalence relations for the raw types @{text |
1367 Next we define the $\alpha$-equivalence relations for the raw types @{text |
1355 "ty"}$_{1..n}$. We write them |
1368 "ty"}$_{1..n}$ from the specification. We write them as |
1356 % |
1369 % |
1357 \begin{center} |
1370 \begin{center} |
1358 @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. |
1371 @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}. |
1359 \end{center} |
1372 \end{center} |
1360 |
1373 |
1367 \end{center} |
1380 \end{center} |
1368 |
1381 |
1369 \noindent |
1382 \noindent |
1370 for the binding functions @{text "bn"}$_{1..m}$, |
1383 for the binding functions @{text "bn"}$_{1..m}$, |
1371 To simplify our definitions we will use the following abbreviations for |
1384 To simplify our definitions we will use the following abbreviations for |
1372 equivalence relations and free-atom functions acting on pairs |
1385 \emph{compound equivalence relations} and \emph{compound free-atom functions} acting on tuples |
1373 |
|
1374 % |
1386 % |
1375 \begin{center} |
1387 \begin{center} |
1376 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1388 \begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l} |
1377 @{text "(x\<^isub>1, y\<^isub>1) (R\<^isub>1 \<otimes> R\<^isub>2) (x\<^isub>2, y\<^isub>2)"} & @{text "\<equiv>"} & @{text "x\<^isub>1 R\<^isub>1 y\<^isub>1 \<and> x\<^isub>2 R\<^isub>2 y\<^isub>2"}\\ |
1389 @{text "(x\<^isub>1,.., x\<^isub>n) (R\<^isub>1,.., R\<^isub>n) (x\<PRIME>\<^isub>1,.., x\<PRIME>\<^isub>n)"} & @{text "\<equiv>"} & \\ |
1378 @{text "(fa\<^isub>1 \<oplus> fa\<^isub>2) (x, y)"} & @{text "\<equiv>"} & @{text "fa\<^isub>1 x \<union> fa\<^isub>2 y"}\\ |
1390 \multicolumn{3}{r}{@{text "x\<^isub>1 R\<^isub>1 x\<PRIME>\<^isub>1 \<and> .. \<and> x\<^isub>n R\<^isub>n x\<PRIME>\<^isub>n"}}\\ |
1379 \end{tabular} |
1391 @{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"}\\ |
1380 \end{center} |
1392 \end{tabular} |
1381 |
1393 \end{center} |
1382 |
1394 |
1383 The relations for $\alpha$-equivalence are inductively defined |
1395 |
1384 predicates, whose clauses have the form |
1396 The $\alpha$-equivalence relations are defined as inductive predicates |
|
1397 having a single clause for each term-constructor. Assuming a |
|
1398 term-constructor @{text C} is of type @{text ty} and has the binding clauses |
|
1399 @{term "bc"}$_{1..k}$, then the $\alpha$-equivalence clause has the form |
1385 % |
1400 % |
1386 \begin{center} |
1401 \begin{center} |
1387 \mbox{\infer{@{text "C z\<^isub>1 \<dots> z\<^isub>n \<approx>ty C z\<PRIME>\<^isub>1 \<dots> z\<PRIME>\<^isub>n"}} |
1402 \mbox{\infer{@{text "C z\<^isub>1 \<dots> z\<^isub>n \<approx>ty C z\<PRIME>\<^isub>1 \<dots> z\<PRIME>\<^isub>n"}} |
1388 {@{text "prems(bc\<^isub>1) \<and> \<dots> \<and> prems(bc\<^isub>k)"}}} |
1403 {@{text "prems(bc\<^isub>1) \<dots> prems(bc\<^isub>k)"}}} |
1389 \end{center} |
1404 \end{center} |
1390 |
1405 |
1391 \noindent |
1406 \noindent |
1392 assuming the term-constructor @{text C} is of type @{text ty} and has |
1407 The task below is to specify what the premises of a binding clause are. As a |
1393 the binding clauses @{term "bc"}$_{1..k}$. The task |
1408 special instance, we first treat the case where @{text "bc\<^isub>i"} is the |
1394 is to specify what the premises of these clauses are. Again for this we |
1409 empty binding clause of the form |
1395 analyse the binding clauses and produce a corresponding premise. |
1410 % |
|
1411 \begin{center} |
|
1412 \mbox{\isacommand{bind\_set} @{term "{}"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.} |
|
1413 \end{center} |
|
1414 |
|
1415 \noindent |
|
1416 In this binding clause no atom is bound and we only have to $\alpha$-relate the bodies. For this |
|
1417 we build first the tuples @{text "D \<equiv> (d\<^isub>1,\<dots>, d\<^isub>q)"} and @{text "D' \<equiv> (d\<PRIME>\<^isub>1,\<dots>, d\<PRIME>\<^isub>q)"} |
|
1418 whereby the labels @{text "d"}$_{1..q}$ refer to arguments @{text "z"}$_{1..n}$ and |
|
1419 respectively @{text "d\<PRIME>"}$_{1..q}$ to @{text "z\<PRIME>"}$_{1..n}$. In order to relate |
|
1420 two such tuples we define the compound $\alpha$-equivalence relation @{text "R"} as follows |
|
1421 % |
|
1422 \begin{equation}\label{rempty} |
|
1423 \mbox{@{text "R \<equiv> (R\<^isub>1,\<dots>, R\<^isub>q)"}} |
|
1424 \end{equation} |
|
1425 |
|
1426 \noindent |
|
1427 with @{text "R\<^isub>i"} being @{text "\<approx>ty\<^isub>i"} if the corresponding labels @{text "d\<^isub>i"} and |
|
1428 @{text "d\<PRIME>\<^isub>i"} refer |
|
1429 to a recursive argument of @{text C} with type @{text "ty\<^isub>i"}; otherwise |
|
1430 we take @{text "R\<^isub>i"} to be the equality @{text "="}. This lets us define |
|
1431 the premise for an empty binding clause succinctly as @{text "prems(bc\<^isub>i) \<equiv> D R D'"}, |
|
1432 which can be unfolded to the series of premises |
|
1433 % |
|
1434 \begin{center} |
|
1435 @{text "d\<^isub>1 R\<^isub>1 d\<PRIME>\<^isub>1 \<dots> d\<^isub>q R\<^isub>q d\<PRIME>\<^isub>q"} |
|
1436 \end{center} |
|
1437 |
|
1438 \noindent |
|
1439 We will use the unfolded version in the examples below. |
|
1440 |
|
1441 Now suppose the binding clause @{text "bc\<^isub>i"} is of the general form |
|
1442 % |
|
1443 \begin{equation}\label{nonempty} |
|
1444 \mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.} |
|
1445 \end{equation} |
|
1446 |
|
1447 \noindent |
|
1448 In this case we define a premise @{text P} using the relation |
|
1449 $\approx_{\,\textit{set}}$ given in Section~\ref{sec:binders} (similarly |
|
1450 $\approx_{\,\textit{res}}$ and $\approx_{\,\textit{list}}$ for the other |
|
1451 binding modes). This premise defines $\alpha$-equivalence of two abstractions |
|
1452 involving multiple binders. We first define as above the tuples @{text "D"} and |
|
1453 @{text "D'"} for the bodies @{text "d"}$_{1..q}$, and the corresponding |
|
1454 compound $\alpha$-relation @{text "R"} (shown in \eqref{rempty}). |
|
1455 For $\approx_{\,\textit{set}}$ we also need |
|
1456 a compound free-atom function for the bodies defined as |
|
1457 % |
|
1458 \begin{center} |
|
1459 \mbox{@{text "fa \<equiv> (fa_ty\<^isub>1,\<dots>, fa_ty\<^isub>q)"}} |
|
1460 \end{center} |
|
1461 |
|
1462 \noindent |
|
1463 with assumption that the @{text "d"}$_{1..q}$ refer to arguments of types @{text "ty"}$_{1..q}$. |
|
1464 The last ingredient we need are the sets of atoms bound in the bodies. |
|
1465 For this we take |
|
1466 |
|
1467 \begin{center} |
|
1468 @{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> \<dots> \<union> bn_ty\<^isub>p b\<^isub>p"}\;.\\ |
|
1469 \end{center} |
|
1470 |
|
1471 \noindent |
|
1472 Similarly for @{text "B'"} using the labels @{text "b\<PRIME>"}$_{1..p}$. This |
|
1473 lets us formally define the premise @{text P} for a non-empty binding clause as: |
|
1474 % |
|
1475 \begin{equation}\label{pprem} |
|
1476 \mbox{@{term "P \<equiv> \<exists>p. (B, D) \<approx>gen R fa p (B', D')"}}\;. |
|
1477 \end{equation} |
|
1478 |
|
1479 \noindent |
|
1480 This premise accounts for $\alpha$-equivalence of the bodies of the binding |
|
1481 clause. However, in case the binders have non-recursive deep binders, then |
|
1482 we also have to ``propagate'' $\alpha$-equivalence inside the structure of |
|
1483 these binders. An example is @{text "Let"} where we have to make sure the |
|
1484 right-hand sides of assignments are $\alpha$-equivalent. For this we use the |
|
1485 relations @{text "\<approx>bn"}$_{1..m}$ (which we will formally define shortly). |
|
1486 Let us assume the non-recursive deep binders in @{text "bc\<^isub>i"} are |
|
1487 % |
|
1488 \begin{center} |
|
1489 @{text "bn\<^isub>1 l\<^isub>1, \<dots>, bn\<^isub>r l\<^isub>r"}. |
|
1490 \end{center} |
|
1491 |
|
1492 \noindent |
|
1493 The premises for @{text "bc\<^isub>i"} are then defined as |
|
1494 % |
|
1495 \begin{center} |
|
1496 @{text "prems(bc\<^isub>i) \<equiv> P \<and> l\<^isub>1 \<approx>bn\<^isub>1 l\<PRIME>\<^isub>1 \<and> ... \<and> l\<^isub>r \<approx>bn\<^isub>r l\<PRIME>\<^isub>r"} |
|
1497 \end{center} |
|
1498 |
|
1499 \noindent |
|
1500 where @{text "P"} is defined in \eqref{pprem}. |
|
1501 |
|
1502 The $\alpha$-equivalence relations @{text "\<approx>bn"}$_{1..m}$ are defined as follows: |
|
1503 given a @{text bn}-clause of the form |
|
1504 % |
|
1505 \begin{center} |
|
1506 @{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"} |
|
1507 \end{center} |
|
1508 |
|
1509 \noindent |
|
1510 where the @{text "z"}$_{1..s}$ are of types @{text "ty"}$_{1..s}$, |
|
1511 then the $\alpha$-equivalence clause for @{text "\<approx>bn"} has the form |
|
1512 % |
|
1513 \begin{center} |
|
1514 \mbox{\infer{@{text "C z\<^isub>1 \<dots> z\<^isub>s \<approx>bn C z\<PRIME>\<^isub>1 \<dots> z\<PRIME>\<^isub>s"}} |
|
1515 {@{text "z\<^isub>1 R\<^isub>1 z\<PRIME>\<^isub>1 \<dots> z\<^isub>s R\<^isub>s z\<PRIME>\<^isub>s"}}} |
|
1516 \end{center} |
|
1517 |
|
1518 \noindent |
|
1519 whereby the relations @{text "R"}$_{1..s}$ are given by |
|
1520 |
|
1521 \begin{center} |
|
1522 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
|
1523 $\bullet$ & @{text "z\<^isub>i \<approx>ty z\<PRIME>\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text rhs} and |
|
1524 is a recursive argument of @{text C},\\ |
|
1525 $\bullet$ & @{text "z\<^isub>i = z\<PRIME>\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text rhs} |
|
1526 and is a non-recursive argument of @{text C},\\ |
|
1527 $\bullet$ & @{text "z\<^isub>i \<approx>bn\<^isub>i z\<PRIME>\<^isub>i"} provided @{text "z\<^isub>i"} occurs in @{text rhs} |
|
1528 with the recursive call @{text "bn\<^isub>i x\<^isub>i"} and\\ |
|
1529 $\bullet$ & @{text True} provided @{text "z\<^isub>i"} occurs in @{text rhs} but without a |
|
1530 recursive call. |
|
1531 \end{tabular} |
|
1532 \end{center} |
|
1533 |
|
1534 \noindent |
|
1535 This completes the definition of $\alpha$-equivalence. As a sanity check, we can show |
|
1536 that the premises of empty binding clauses are a special case of the clauses for |
|
1537 non-empty ones (we just have to unfold the definition of $\approx_{\,\textit{set}}$ and take @{text "0"} |
|
1538 as the permutation). |
1396 *} |
1539 *} |
1397 (*<*) |
1540 (*<*)consts alpha_ty ::'a |
1398 consts alpha_ty ::'a |
|
1399 consts alpha_trm ::'a |
1541 consts alpha_trm ::'a |
1400 consts fa_trm :: 'a |
1542 consts fa_trm :: 'a |
1401 consts alpha_trm2 ::'a |
1543 consts alpha_trm2 ::'a |
1402 consts fa_trm2 :: 'a |
1544 consts fa_trm2 :: 'a |
1403 notation (latex output) |
1545 notation (latex output) |
1404 alpha_ty ("\<approx>ty") and |
1546 alpha_ty ("\<approx>ty") and |
1405 alpha_trm ("\<approx>\<^bsub>trm\<^esub>") and |
1547 alpha_trm ("\<approx>\<^bsub>trm\<^esub>") and |
1406 fa_trm ("fa\<^bsub>trm\<^esub>") and |
1548 fa_trm ("fa\<^bsub>trm\<^esub>") and |
1407 alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and |
1549 alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and |
1408 fa_trm2 ("fa\<^bsub>assn\<^esub> \<oplus> fa\<^bsub>trm\<^esub>") |
1550 fa_trm2 ("fa\<^bsub>assn\<^esub> \<oplus> fa\<^bsub>trm\<^esub>")(*>*) |
1409 (*>*) |
|
1410 text {* |
1551 text {* |
1411 *TBD below * |
|
1412 |
|
1413 \begin{equation}\label{alpha} |
|
1414 \mbox{% |
|
1415 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
|
1416 \multicolumn{2}{@ {}l}{Empty binding clauses of the form |
|
1417 \isacommand{bind\_set}~@{term "{}"}~\isacommand{in}~@{text "x\<^isub>i"}:}\\ |
|
1418 $\bullet$ & @{text "x\<^isub>i \<approx>ty y\<^isub>i"} provided @{text "x\<^isub>i"} and @{text "y\<^isub>i"} |
|
1419 are recursive arguments of @{text "C"}\\ |
|
1420 $\bullet$ & @{term "x\<^isub>i = y\<^isub>i"} provided @{text "x\<^isub>i"} and @{text "y\<^isub>i"} are |
|
1421 non-recursive arguments\smallskip\\ |
|
1422 \multicolumn{2}{@ {}l}{Shallow binders of the form |
|
1423 \isacommand{bind\_set}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\ |
|
1424 $\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"}, |
|
1425 @{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fa} is |
|
1426 @{text "fa_ty\<^isub>1 \<oplus> ... \<oplus> fa_ty\<^isub>m"}, then |
|
1427 \begin{center} |
|
1428 @{term "\<exists>p. (x\<^isub>1 \<union> \<xi> \<union> x\<^isub>n, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fa p (y\<^isub>1 \<union> \<xi> \<union> y\<^isub>n, (y'\<^isub>1,\<xi>,y'\<^isub>m))"} |
|
1429 \end{center}\\ |
|
1430 \multicolumn{2}{@ {}l}{Deep binders of the form |
|
1431 \isacommand{bind\_set}~@{text "bn x"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\ |
|
1432 $\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"}, |
|
1433 @{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fa} is |
|
1434 @{text "fa_ty\<^isub>1 \<oplus> ... \<oplus> fa_ty\<^isub>m"}, then for recursive deep binders |
|
1435 \begin{center} |
|
1436 @{term "\<exists>p. (bn x, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fa p (bn y, (y'\<^isub>1,\<xi>,y'\<^isub>m))"} |
|
1437 \end{center}\\ |
|
1438 $\bullet$ & for non-recursive binders we generate in addition @{text "x \<approx>bn y"}\\ |
|
1439 \end{tabular}} |
|
1440 \end{equation} |
|
1441 |
|
1442 \noindent |
|
1443 Similarly for the other binding modes. |
|
1444 From this definition it is clear why we have to impose the restriction |
|
1445 of excluding overlapping deep binders, as these would need to be translated into separate |
|
1446 abstractions. |
|
1447 |
|
1448 |
|
1449 |
|
1450 The $\alpha$-equivalence relations @{text "\<approx>bn\<^isub>j"} for binding functions |
|
1451 are similar. We again have conclusions of the form \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>bn C y\<^isub>1 \<dots> y\<^isub>n"}} |
|
1452 and need to generate appropriate premises. We generate first premises according to the first three |
|
1453 rules given above. Only the ``left-over'' pairs @{text "(x\<^isub>i, y\<^isub>i)"} need to be treated |
|
1454 differently. They depend on whether @{text "x\<^isub>i"} occurs in @{text "rhs"} of the |
|
1455 clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}: |
|
1456 |
|
1457 \begin{center} |
|
1458 \begin{tabular}{c@ {\hspace{2mm}}p{7cm}} |
|
1459 $\bullet$ & @{text "x\<^isub>i \<approx>ty y\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text rhs} |
|
1460 and the type of @{text "x\<^isub>i"} is @{text ty} and @{text "x\<^isub>i"} is a recursive argument |
|
1461 in the term-constructor\\ |
|
1462 $\bullet$ & @{text "x\<^isub>i = y\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text rhs} |
|
1463 and @{text "x\<^isub>i"} is not a recursive argument in the term-constructor\\ |
|
1464 $\bullet$ & @{text "x\<^isub>i \<approx>bn y\<^isub>i"} provided @{text "x\<^isub>i"} occurs in @{text rhs} |
|
1465 with the recursive call @{text "bn x\<^isub>i"}\\ |
|
1466 $\bullet$ & none provided @{text "x\<^isub>i"} occurs in @{text rhs} but it is not |
|
1467 in a recursive call involving a @{text "bn"} |
|
1468 \end{tabular} |
|
1469 \end{center} |
|
1470 |
|
1471 Again lets take a look at a concrete example for these definitions. For \eqref{letrecs} |
1552 Again lets take a look at a concrete example for these definitions. For \eqref{letrecs} |
1472 we have three relations, namely $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and |
1553 we have three relations $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and |
1473 $\approx_{\textit{bn}}$, with the clauses as follows: |
1554 $\approx_{\textit{bn}}$ with the following clauses: |
1474 |
1555 |
1475 \begin{center} |
1556 \begin{center} |
1476 \begin{tabular}{@ {}c @ {}} |
1557 \begin{tabular}{@ {}c @ {}} |
1477 \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}} |
1558 \infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}} |
1478 {@{text "as \<approx>\<^bsub>bn\<^esub> as'"} & @{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fa_trm p (bn as', t')"}}\smallskip\\ |
1559 {@{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fa_trm p (bn as', t')"} & @{text "as \<approx>\<^bsub>bn\<^esub> as'"}}\smallskip\\ |
1479 \infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}} |
1560 \infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}} |
1480 {@{term "\<exists>p. (bn as, (as, t)) \<approx>lst alpha_trm2 fa_trm2 p (bn as', (as', t'))"}} |
1561 {@{term "\<exists>p. (bn as, (as, t)) \<approx>lst alpha_trm2 fa_trm2 p (bn as', (as', t'))"}} |
1481 \end{tabular} |
1562 \end{tabular} |
1482 \end{center} |
1563 \end{center} |
1483 |
1564 |