2985
+ − 1
(*<*)
+ − 2
theory Paper
+ − 3
imports "../Nominal/Nominal2"
+ − 4
"~~/src/HOL/Library/LaTeXsugar"
+ − 5
begin
+ − 6
+ − 7
consts
+ − 8
fv :: "'a \<Rightarrow> 'b"
+ − 9
abs_set :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
+ − 10
alpha_bn :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
+ − 11
abs_set2 :: "'a \<Rightarrow> perm \<Rightarrow> 'b \<Rightarrow> 'c"
3016
+ − 12
equ2 :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
2985
+ − 13
Abs_dist :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
+ − 14
Abs_print :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
+ − 15
+ − 16
definition
+ − 17
"equal \<equiv> (op =)"
+ − 18
3006
+ − 19
fun alpha_set_ex where
+ − 20
"alpha_set_ex (bs, x) R f (cs, y) = (\<exists>pi. alpha_set (bs, x) R f pi (cs, y))"
+ − 21
+ − 22
fun alpha_res_ex where
+ − 23
"alpha_res_ex (bs, x) R f pi (cs, y) = (\<exists>pi. alpha_res (bs, x) R f pi (cs, y))"
+ − 24
+ − 25
fun alpha_lst_ex where
+ − 26
"alpha_lst_ex (bs, x) R f pi (cs, y) = (\<exists>pi. alpha_lst (bs, x) R f pi (cs, y))"
+ − 27
+ − 28
+ − 29
2985
+ − 30
notation (latex output)
+ − 31
swap ("'(_ _')" [1000, 1000] 1000) and
+ − 32
fresh ("_ # _" [51, 51] 50) and
+ − 33
fresh_star ("_ #\<^sup>* _" [51, 51] 50) and
+ − 34
supp ("supp _" [78] 73) and
+ − 35
uminus ("-_" [78] 73) and
+ − 36
If ("if _ then _ else _" 10) and
3006
+ − 37
alpha_set_ex ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{set}}$}}>\<^bsup>_, _\<^esup> _") and
+ − 38
alpha_lst_ex ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{list}}$}}>\<^bsup>_, _\<^esup> _") and
+ − 39
alpha_res_ex ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{set+}}$}}>\<^bsup>_, _\<^esup> _") and
2985
+ − 40
abs_set ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and
+ − 41
abs_set2 ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{list}}$}}>\<^bsup>_\<^esup> _") and
+ − 42
fv ("fa'(_')" [100] 100) and
+ − 43
equal ("=") and
+ − 44
alpha_abs_set ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and
3002
+ − 45
alpha_abs_lst ("_ \<approx>\<^raw:{$\,_{\textit{abs\_list}}$}> _") and
+ − 46
alpha_abs_res ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set+}}$}> _") and
2985
+ − 47
Abs_set ("[_]\<^bsub>set\<^esub>._" [20, 101] 999) and
3021
+ − 48
Abs_lst ("[_]\<^bsub>list\<^esub>._" [20, 101] 999) and
+ − 49
Abs_dist ("[_]\<^bsub>#list\<^esub>._" [20, 101] 999) and
2985
+ − 50
Abs_res ("[_]\<^bsub>set+\<^esub>._") and
+ − 51
Abs_print ("_\<^bsub>set\<^esub>._") and
+ − 52
Cons ("_::_" [78,77] 73) and
+ − 53
supp_set ("aux _" [1000] 10) and
+ − 54
alpha_bn ("_ \<approx>bn _")
+ − 55
+ − 56
consts alpha_trm ::'a
+ − 57
consts fa_trm :: 'a
3016
+ − 58
consts fa_trm_al :: 'a
2985
+ − 59
consts alpha_trm2 ::'a
+ − 60
consts fa_trm2 :: 'a
3016
+ − 61
consts fa_trm2_al :: 'a
+ − 62
consts supp2 :: 'a
2985
+ − 63
consts ast :: 'a
+ − 64
consts ast' :: 'a
3016
+ − 65
consts bn_al :: "'b \<Rightarrow> 'a"
2985
+ − 66
notation (latex output)
+ − 67
alpha_trm ("\<approx>\<^bsub>trm\<^esub>") and
+ − 68
fa_trm ("fa\<^bsub>trm\<^esub>") and
3016
+ − 69
fa_trm_al ("fa\<AL>\<^bsub>trm\<^esub>") and
2985
+ − 70
alpha_trm2 ("'(\<approx>\<^bsub>assn\<^esub>, \<approx>\<^bsub>trm\<^esub>')") and
+ − 71
fa_trm2 ("'(fa\<^bsub>assn\<^esub>, fa\<^bsub>trm\<^esub>')") and
3016
+ − 72
fa_trm2_al ("'(fa\<AL>\<^bsub>assn\<^esub>, fa\<AL>\<^bsub>trm\<^esub>')") and
2985
+ − 73
ast ("'(as, t')") and
3016
+ − 74
ast' ("'(as', t\<PRIME> ')") and
+ − 75
equ2 ("'(=, =')") and
+ − 76
supp2 ("'(supp, supp')") and
3018
+ − 77
bn_al ("bn\<^sup>\<alpha> _" [100] 100)
2985
+ − 78
(*>*)
+ − 79
+ − 80
+ − 81
section {* Introduction *}
+ − 82
+ − 83
text {*
2989
+ − 84
So far, Nominal Isabelle provided a mechanism for constructing alpha-equated
+ − 85
terms, for example lambda-terms
2985
+ − 86
2989
+ − 87
\[
+ − 88
@{text "t ::= x | t t | \<lambda>x. t"}
+ − 89
\]\smallskip
+ − 90
+ − 91
\noindent
+ − 92
where free and bound variables have names. For such alpha-equated terms,
2985
+ − 93
Nominal Isabelle derives automatically a reasoning infrastructure that has
+ − 94
been used successfully in formalisations of an equivalence checking
+ − 95
algorithm for LF \cite{UrbanCheneyBerghofer08}, Typed
+ − 96
Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
+ − 97
\cite{BengtsonParow09} and a strong normalisation result for cut-elimination
+ − 98
in classical logic \cite{UrbanZhu08}. It has also been used by Pollack for
+ − 99
formalisations in the locally-nameless approach to binding
+ − 100
\cite{SatoPollack10}.
+ − 101
2989
+ − 102
However, Nominal Isabelle has fared less well in a formalisation of the
+ − 103
algorithm W \cite{UrbanNipkow09}, where types and type-schemes are,
2985
+ − 104
respectively, of the form
2989
+ − 105
2985
+ − 106
\begin{equation}\label{tysch}
+ − 107
\begin{array}{l}
2989
+ − 108
@{text "T ::= x | T \<rightarrow> T"}\hspace{15mm}
2985
+ − 109
@{text "S ::= \<forall>{x\<^isub>1,\<dots>, x\<^isub>n}. T"}
+ − 110
\end{array}
2989
+ − 111
\end{equation}\smallskip
+ − 112
2985
+ − 113
\noindent
+ − 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
3126
+ − 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
3159
+ − 117
formalisation of W. For example, the usual definition for a
+ − 118
type being an instance of a type-scheme requires in the iterated version
+ − 119
the following auxiliary \emph{unbinding relation}:
3126
+ − 120
+ − 121
\[
+ − 122
\infer{@{text T} \hookrightarrow ([], @{text T})}{}\qquad
+ − 123
\infer{\forall @{text x.S} \hookrightarrow (@{text x}\!::\!@{text xs}, @{text T})}
+ − 124
{@{text S} \hookrightarrow (@{text xs}, @{text T})}
+ − 125
\]\smallskip
3102
5b5ade6bc889
added definition for generalisation of type schemes (for paper)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 126
3126
+ − 127
\noindent
3154
+ − 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:
3159
+ − 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 to this problem, though
3160
+ − 132
in general it will only provide \emph{a} list of type-variables together with \emph{a} type that are
3129
+ − 133
``alpha-equivalent'' to @{text S}. This is because unbinding is a relation; it cannot be a function
3160
+ − 134
for alpha-equated type-schemes. With the unbinding relation
+ − 135
in place, we can define when a type @{text T} is an instance of a type-scheme @{text S} as follows:
3102
5b5ade6bc889
added definition for generalisation of type schemes (for paper)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 136
3126
+ − 137
\[
+ − 138
@{text "T \<prec> S \<equiv> \<exists>xs T' \<sigma>. S \<hookrightarrow> (xs, T') \<and> dom \<sigma> = set xs \<and> \<sigma>(T') = T"}
+ − 139
\]\smallskip
+ − 140
+ − 141
\noindent
3154
+ − 142
This means there exists a list of type-variables @{text xs} and a type @{text T'} to which
3159
+ − 143
the type-scheme @{text S} unbinds, and there exists a substitution @{text "\<sigma>"} whose domain is
3126
+ − 144
@{text xs} (seen as set) such that @{text "\<sigma>(T') = T"}.
3128
+ − 145
The problem with this definition is that we cannot follow the usual proofs
3126
+ − 146
that are by induction on the type-part of the type-scheme (since it is under
3160
+ − 147
an existential quantifier and only an alpha-variant). The implementation of
3129
+ − 148
type-schemes using iterations of single binders
3131
+ − 149
prevents us from directly ``unbinding'' the bound type-variables and the type-part.
3160
+ − 150
Clearly, a more dignified approach for formalising algorithm W is desirable.
3129
+ − 151
The purpose of this paper is to introduce general binders, which
3128
+ − 152
allow us to represent type-schemes so that they can bind multiple variables at once
3159
+ − 153
and as a result solve this problem more straightforwardly.
3102
5b5ade6bc889
added definition for generalisation of type schemes (for paper)
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 154
The need of iterating single binders is also one reason
3160
+ − 155
why the existing Nominal Isabelle and similar theorem provers that only provide
3129
+ − 156
mechanisms for binding single variables have so far not fared very well with
2989
+ − 157
the more advanced tasks in the POPLmark challenge \cite{challenge05},
+ − 158
because also there one would like to bind multiple variables at once.
2985
+ − 159
+ − 160
Binding multiple variables has interesting properties that cannot be captured
+ − 161
easily by iterating single binders. For example in the case of type-schemes we do not
+ − 162
want to make a distinction about the order of the bound variables. Therefore
3001
+ − 163
we would like to regard in \eqref{ex1} below the first pair of type-schemes as alpha-equivalent,
2985
+ − 164
but assuming that @{text x}, @{text y} and @{text z} are distinct variables,
2989
+ − 165
the second pair should \emph{not} be alpha-equivalent:
+ − 166
2985
+ − 167
\begin{equation}\label{ex1}
3128
+ − 168
@{text "\<forall>{x, y}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{x, y}. y \<rightarrow> x"}\hspace{10mm}
2985
+ − 169
@{text "\<forall>{x, y}. x \<rightarrow> y \<notapprox>\<^isub>\<alpha> \<forall>{z}. z \<rightarrow> z"}
2989
+ − 170
\end{equation}\smallskip
+ − 171
2985
+ − 172
\noindent
2989
+ − 173
Moreover, we like to regard type-schemes as alpha-equivalent, if they differ
2985
+ − 174
only on \emph{vacuous} binders, such as
2989
+ − 175
2985
+ − 176
\begin{equation}\label{ex3}
+ − 177
@{text "\<forall>{x}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{x, z}. x \<rightarrow> y"}
2989
+ − 178
\end{equation}\smallskip
+ − 179
2985
+ − 180
\noindent
+ − 181
where @{text z} does not occur freely in the type. In this paper we will
2989
+ − 182
give a general binding mechanism and associated notion of alpha-equivalence
2985
+ − 183
that can be used to faithfully represent this kind of binding in Nominal
2989
+ − 184
Isabelle. The difficulty of finding the right notion for alpha-equivalence
3002
+ − 185
can be appreciated in this case by considering that the definition given for
+ − 186
type-schemes by Leroy in \cite[Page 18--19]{Leroy92} is incorrect (it omits a side-condition).
2985
+ − 187
2989
+ − 188
However, the notion of alpha-equivalence that is preserved by vacuous
2985
+ − 189
binders is not always wanted. For example in terms like
2989
+ − 190
2985
+ − 191
\begin{equation}\label{one}
+ − 192
@{text "\<LET> x = 3 \<AND> y = 2 \<IN> x - y \<END>"}
2989
+ − 193
\end{equation}\smallskip
2985
+ − 194
+ − 195
\noindent
+ − 196
we might not care in which order the assignments @{text "x = 3"} and
2989
+ − 197
\mbox{@{text "y = 2"}} are given, but it would be often unusual (particularly
+ − 198
in strict languages) to regard \eqref{one} as alpha-equivalent with
+ − 199
+ − 200
\[
2985
+ − 201
@{text "\<LET> x = 3 \<AND> y = 2 \<AND> z = foo \<IN> x - y \<END>"}
2989
+ − 202
\]\smallskip
+ − 203
2985
+ − 204
\noindent
+ − 205
Therefore we will also provide a separate binding mechanism for cases in
3023
+ − 206
which the order of binders does not matter, but the `cardinality' of the
2985
+ − 207
binders has to agree.
+ − 208
+ − 209
However, we found that this is still not sufficient for dealing with
+ − 210
language constructs frequently occurring in programming language
+ − 211
research. For example in @{text "\<LET>"}s containing patterns like
2989
+ − 212
2985
+ − 213
\begin{equation}\label{two}
+ − 214
@{text "\<LET> (x, y) = (3, 2) \<IN> x - y \<END>"}
2989
+ − 215
\end{equation}\smallskip
+ − 216
2985
+ − 217
\noindent
+ − 218
we want to bind all variables from the pattern inside the body of the
+ − 219
$\mathtt{let}$, but we also care about the order of these variables, since
2989
+ − 220
we do not want to regard \eqref{two} as alpha-equivalent with
+ − 221
+ − 222
\[
2985
+ − 223
@{text "\<LET> (y, x) = (3, 2) \<IN> x - y \<END>"}
2989
+ − 224
\]\smallskip
+ − 225
2985
+ − 226
\noindent
+ − 227
As a result, we provide three general binding mechanisms each of which binds
3106
+ − 228
multiple variables at once, and let the user choose which one is intended
2989
+ − 229
when formalising a term-calculus.
2985
+ − 230
+ − 231
By providing these general binding mechanisms, however, we have to work
+ − 232
around a problem that has been pointed out by Pottier \cite{Pottier06} and
+ − 233
Cheney \cite{Cheney05}: in @{text "\<LET>"}-constructs of the form
2989
+ − 234
+ − 235
\[
2985
+ − 236
@{text "\<LET> x\<^isub>1 = t\<^isub>1 \<AND> \<dots> \<AND> x\<^isub>n = t\<^isub>n \<IN> s \<END>"}
2989
+ − 237
\]\smallskip
+ − 238
2985
+ − 239
\noindent
2989
+ − 240
we care about the information that there are as many bound variables @{text
2985
+ − 241
"x\<^isub>i"} as there are @{text "t\<^isub>i"}. We lose this information if
+ − 242
we represent the @{text "\<LET>"}-constructor by something like
2989
+ − 243
+ − 244
\[
2985
+ − 245
@{text "\<LET> (\<lambda>x\<^isub>1\<dots>x\<^isub>n . s) [t\<^isub>1,\<dots>,t\<^isub>n]"}
2989
+ − 246
\]\smallskip
+ − 247
2985
+ − 248
\noindent
+ − 249
where the notation @{text "\<lambda>_ . _"} indicates that the list of @{text
+ − 250
"x\<^isub>i"} becomes bound in @{text s}. In this representation the term
2989
+ − 251
\mbox{@{text "\<LET> (\<lambda>x . s) [t\<^isub>1, t\<^isub>2]"}} is a perfectly
+ − 252
legal instance, but the lengths of the two lists do not agree. To exclude
+ − 253
such terms, additional predicates about well-formed terms are needed in
+ − 254
order to ensure that the two lists are of equal length. This can result in
+ − 255
very messy reasoning (see for example~\cite{BengtsonParow09}). To avoid
+ − 256
this, we will allow type specifications for @{text "\<LET>"}s as follows
+ − 257
+ − 258
\[
+ − 259
\mbox{\begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}ll}
+ − 260
@{text trm} & @{text "::="} & @{text "\<dots>"} \\
+ − 261
& @{text "|"} & @{text "\<LET> as::assn s::trm"}\hspace{2mm}
3004
+ − 262
\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text "s"}\\[1mm]
2989
+ − 263
@{text assn} & @{text "::="} & @{text "\<ANIL>"}\\
+ − 264
& @{text "|"} & @{text "\<ACONS> name trm assn"}
+ − 265
\end{tabular}}
+ − 266
\]\smallskip
+ − 267
2985
+ − 268
\noindent
+ − 269
where @{text assn} is an auxiliary type representing a list of assignments
+ − 270
and @{text bn} an auxiliary function identifying the variables to be bound
+ − 271
by the @{text "\<LET>"}. This function can be defined by recursion over @{text
+ − 272
assn} as follows
2989
+ − 273
+ − 274
\[
3025
+ − 275
@{text "bn(\<ANIL>) ="}~@{term "{}"} \hspace{10mm}
2985
+ − 276
@{text "bn(\<ACONS> x t as) = {x} \<union> bn(as)"}
2989
+ − 277
\]\smallskip
+ − 278
2985
+ − 279
\noindent
+ − 280
The scope of the binding is indicated by labels given to the types, for
+ − 281
example @{text "s::trm"}, and a binding clause, in this case
3004
+ − 282
\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding
2989
+ − 283
clause states that all the names the function @{text "bn(as)"} returns
+ − 284
should be bound in @{text s}. This style of specifying terms and bindings
+ − 285
is heavily inspired by the syntax of the Ott-tool \cite{ott-jfp}. Our work
+ − 286
extends Ott in several aspects: one is that we support three binding
+ − 287
modes---Ott has only one, namely the one where the order of binders matters.
3000
+ − 288
Another is that our reasoning infrastructure, like strong induction principles
+ − 289
and the notion of free variables, is derived from first principles within
+ − 290
the Isabelle/HOL theorem prover.
2985
+ − 291
+ − 292
However, we will not be able to cope with all specifications that are
3023
+ − 293
allowed by Ott. One reason is that Ott lets the user specify `empty' types
2989
+ − 294
like \mbox{@{text "t ::= t t | \<lambda>x. t"}} where no clause for variables is
+ − 295
given. Arguably, such specifications make some sense in the context of Coq's
+ − 296
type theory (which Ott supports), but not at all in a HOL-based environment
+ − 297
where every datatype must have a non-empty set-theoretic model
+ − 298
\cite{Berghofer99}. Another reason is that we establish the reasoning
+ − 299
infrastructure for alpha-\emph{equated} terms. In contrast, Ott produces a
+ − 300
reasoning infrastructure in Isabelle/HOL for \emph{non}-alpha-equated, or
3025
+ − 301
`raw', terms. While our alpha-equated terms and the `raw' terms produced by
2989
+ − 302
Ott use names for bound variables, there is a key difference: working with
+ − 303
alpha-equated terms means, for example, that the two type-schemes
2985
+ − 304
2989
+ − 305
\[
2985
+ − 306
@{text "\<forall>{x}. x \<rightarrow> y = \<forall>{x, z}. x \<rightarrow> y"}
2989
+ − 307
\]\smallskip
2985
+ − 308
+ − 309
\noindent
2989
+ − 310
are not just alpha-equal, but actually \emph{equal}! As a result, we can
+ − 311
only support specifications that make sense on the level of alpha-equated
2985
+ − 312
terms (offending specifications, which for example bind a variable according
+ − 313
to a variable bound somewhere else, are not excluded by Ott, but we have
+ − 314
to).
+ − 315
2989
+ − 316
Our insistence on reasoning with alpha-equated terms comes from the
2985
+ − 317
wealth of experience we gained with the older version of Nominal Isabelle:
2989
+ − 318
for non-trivial properties, reasoning with alpha-equated terms is much
3025
+ − 319
easier than reasoning with `raw' terms. The fundamental reason for this is
2985
+ − 320
that the HOL-logic underlying Nominal Isabelle allows us to replace
3023
+ − 321
`equals-by-equals'. In contrast, replacing
+ − 322
`alpha-equals-by-alpha-equals' in a representation based on `raw' terms
2985
+ − 323
requires a lot of extra reasoning work.
+ − 324
2989
+ − 325
Although in informal settings a reasoning infrastructure for alpha-equated
2985
+ − 326
terms is nearly always taken for granted, establishing it automatically in
+ − 327
Isabelle/HOL is a rather non-trivial task. For every
+ − 328
specification we will need to construct type(s) containing as elements the
2989
+ − 329
alpha-equated terms. To do so, we use the standard HOL-technique of defining
2985
+ − 330
a new type by identifying a non-empty subset of an existing type. The
+ − 331
construction we perform in Isabelle/HOL can be illustrated by the following picture:
2989
+ − 332
3008
+ − 333
\begin{equation}\label{picture}
2989
+ − 334
\mbox{\begin{tikzpicture}[scale=1.1]
2985
+ − 335
%\draw[step=2mm] (-4,-1) grid (4,1);
+ − 336
+ − 337
\draw[very thick] (0.7,0.4) circle (4.25mm);
+ − 338
\draw[rounded corners=1mm, very thick] ( 0.0,-0.8) rectangle ( 1.8, 0.9);
+ − 339
\draw[rounded corners=1mm, very thick] (-1.95,0.85) rectangle (-2.85,-0.05);
+ − 340
+ − 341
\draw (-2.0, 0.845) -- (0.7,0.845);
+ − 342
\draw (-2.0,-0.045) -- (0.7,-0.045);
+ − 343
3022
+ − 344
\draw ( 0.7, 0.5) node {\footnotesize\begin{tabular}{@ {}c@ {}}$\alpha$-\\[-1mm]classes\end{tabular}};
+ − 345
\draw (-2.4, 0.5) node {\footnotesize\begin{tabular}{@ {}c@ {}}$\alpha$-eq.\\[-1mm]terms\end{tabular}};
2985
+ − 346
\draw (1.8, 0.48) node[right=-0.1mm]
2989
+ − 347
{\small\begin{tabular}{@ {}l@ {}}existing\\[-1mm] type\\ (sets of raw terms)\end{tabular}};
2985
+ − 348
\draw (0.9, -0.35) node {\footnotesize\begin{tabular}{@ {}l@ {}}non-empty\\[-1mm]subset\end{tabular}};
2989
+ − 349
\draw (-3.25, 0.55) node {\small\begin{tabular}{@ {}l@ {}}new\\[-1mm]type\end{tabular}};
2985
+ − 350
+ − 351
\draw[<->, very thick] (-1.8, 0.3) -- (-0.1,0.3);
+ − 352
\draw (-0.95, 0.3) node[above=0mm] {\footnotesize{}isomorphism};
+ − 353
2989
+ − 354
\end{tikzpicture}}
3008
+ − 355
\end{equation}\smallskip
2989
+ − 356
2985
+ − 357
\noindent
+ − 358
We take as the starting point a definition of raw terms (defined as a
2989
+ − 359
datatype in Isabelle/HOL); then identify the alpha-equivalence classes in
+ − 360
the type of sets of raw terms according to our alpha-equivalence relation,
+ − 361
and finally define the new type as these alpha-equivalence classes (the
+ − 362
non-emptiness requirement is always satisfied whenever the raw terms are
+ − 363
definable as datatype in Isabelle/HOL and our relation for alpha-equivalence
+ − 364
is an equivalence relation).
2985
+ − 365
+ − 366
The fact that we obtain an isomorphism between the new type and the
+ − 367
non-empty subset shows that the new type is a faithful representation of
2989
+ − 368
alpha-equated terms. That is not the case for example for terms using the
2985
+ − 369
locally nameless representation of binders \cite{McKinnaPollack99}: in this
3023
+ − 370
representation there are `junk' terms that need to be excluded by
2985
+ − 371
reasoning about a well-formedness predicate.
+ − 372
+ − 373
The problem with introducing a new type in Isabelle/HOL is that in order to
3023
+ − 374
be useful, a reasoning infrastructure needs to be `lifted' from the
2985
+ − 375
underlying subset to the new type. This is usually a tricky and arduous
2990
+ − 376
task. To ease it, we re-implemented in Isabelle/HOL \cite{KaliszykUrban11}
+ − 377
the quotient package described by Homeier \cite{Homeier05} for the HOL4
+ − 378
system. This package allows us to lift definitions and theorems involving
+ − 379
raw terms to definitions and theorems involving alpha-equated terms. For
+ − 380
example if we define the free-variable function over raw lambda-terms
2991
+ − 381
as follows
2985
+ − 382
2990
+ − 383
\[
+ − 384
\mbox{\begin{tabular}{l@ {\hspace{1mm}}r@ {\hspace{1mm}}l}
+ − 385
@{text "fv(x)"} & @{text "\<equiv>"} & @{text "{x}"}\\
+ − 386
@{text "fv(t\<^isub>1 t\<^isub>2)"} & @{text "\<equiv>"} & @{text "fv(t\<^isub>1) \<union> fv(t\<^isub>2)"}\\
+ − 387
@{text "fv(\<lambda>x.t)"} & @{text "\<equiv>"} & @{text "fv(t) - {x}"}
+ − 388
\end{tabular}}
+ − 389
\]\smallskip
2985
+ − 390
+ − 391
\noindent
+ − 392
then with the help of the quotient package we can obtain a function @{text "fv\<^sup>\<alpha>"}
3000
+ − 393
operating on quotients, that is alpha-equivalence classes of lambda-terms. This
2985
+ − 394
lifted function is characterised by the equations
+ − 395
2990
+ − 396
\[
+ − 397
\mbox{\begin{tabular}{l@ {\hspace{1mm}}r@ {\hspace{1mm}}l}
+ − 398
@{text "fv\<^sup>\<alpha>(x)"} & @{text "="} & @{text "{x}"}\\
+ − 399
@{text "fv\<^sup>\<alpha>(t\<^isub>1 t\<^isub>2)"} & @{text "="} & @{text "fv\<^sup>\<alpha>(t\<^isub>1) \<union> fv\<^sup>\<alpha>(t\<^isub>2)"}\\
+ − 400
@{text "fv\<^sup>\<alpha>(\<lambda>x.t)"} & @{text "="} & @{text "fv\<^sup>\<alpha>(t) - {x}"}
+ − 401
\end{tabular}}
+ − 402
\]\smallskip
2985
+ − 403
+ − 404
\noindent
+ − 405
(Note that this means also the term-constructors for variables, applications
+ − 406
and lambda are lifted to the quotient level.) This construction, of course,
2989
+ − 407
only works if alpha-equivalence is indeed an equivalence relation, and the
3023
+ − 408
`raw' definitions and theorems are respectful w.r.t.~alpha-equivalence.
2985
+ − 409
For example, we will not be able to lift a bound-variable function. Although
+ − 410
this function can be defined for raw terms, it does not respect
2989
+ − 411
alpha-equivalence and therefore cannot be lifted.
2985
+ − 412
To sum up, every lifting
+ − 413
of theorems to the quotient level needs proofs of some respectfulness
+ − 414
properties (see \cite{Homeier05}). In the paper we show that we are able to
+ − 415
automate these proofs and as a result can automatically establish a reasoning
2989
+ − 416
infrastructure for alpha-equated terms.\smallskip
2985
+ − 417
+ − 418
The examples we have in mind where our reasoning infrastructure will be
3003
+ − 419
helpful include the term language of Core-Haskell (see
2991
+ − 420
Figure~\ref{corehas}). This term language involves patterns that have lists
+ − 421
of type-, coercion- and term-variables, all of which are bound in @{text
+ − 422
"\<CASE>"}-expressions. In these patterns we do not know in advance how many
3002
+ − 423
variables need to be bound. Another example is the algorithm W,
3000
+ − 424
which includes multiple binders in type-schemes.\medskip
2985
+ − 425
+ − 426
\noindent
3021
+ − 427
{\bf Contributions:} We provide three new definitions for when terms
2989
+ − 428
involving general binders are alpha-equivalent. These definitions are
3128
+ − 429
inspired by earlier work of Pitts \cite{Pitts04}. By means of automati\-cally-generated
3021
+ − 430
proofs, we establish a reasoning infrastructure for alpha-equated terms,
+ − 431
including properties about support, freshness and equality conditions for
+ − 432
alpha-equated terms. We are also able to automatically derive strong
2985
+ − 433
induction principles that have the variable convention already built in.
3025
+ − 434
For this we simplify the earlier automated proofs by using the proving tools
3021
+ − 435
from the function package~\cite{Krauss09} of Isabelle/HOL. The method
+ − 436
behind our specification of general binders is taken from the Ott-tool, but
+ − 437
we introduce crucial restrictions, and also extensions, so that our
+ − 438
specifications make sense for reasoning about alpha-equated terms. The main
+ − 439
improvement over Ott is that we introduce three binding modes (only one is
+ − 440
present in Ott), provide formalised definitions for alpha-equivalence and
2985
+ − 441
for free variables of our terms, and also derive a reasoning infrastructure
3023
+ − 442
for our specifications from `first principles' inside a theorem prover.
2985
+ − 443
+ − 444
3021
+ − 445
\begin{figure}[t]
2991
+ − 446
\begin{boxedminipage}{\linewidth}
+ − 447
\begin{center}
+ − 448
\begin{tabular}{@ {\hspace{8mm}}r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
+ − 449
\multicolumn{3}{@ {}l}{Type Kinds}\\
+ − 450
@{text "\<kappa>"} & @{text "::="} & @{text "\<star> | \<kappa>\<^isub>1 \<rightarrow> \<kappa>\<^isub>2"}\smallskip\\
+ − 451
\multicolumn{3}{@ {}l}{Coercion Kinds}\\
+ − 452
@{text "\<iota>"} & @{text "::="} & @{text "\<sigma>\<^isub>1 \<sim> \<sigma>\<^isub>2"}\smallskip\\
+ − 453
\multicolumn{3}{@ {}l}{Types}\\
+ − 454
@{text "\<sigma>"} & @{text "::="} & @{text "a | T | \<sigma>\<^isub>1 \<sigma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<sigma>"}}$@{text "\<^sup>n"}
+ − 455
@{text "| \<forall>a:\<kappa>. \<sigma> | \<iota> \<Rightarrow> \<sigma>"}\smallskip\\
+ − 456
\multicolumn{3}{@ {}l}{Coercion Types}\\
+ − 457
@{text "\<gamma>"} & @{text "::="} & @{text "c | C | \<gamma>\<^isub>1 \<gamma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<gamma>"}}$@{text "\<^sup>n"}
+ − 458
@{text "| \<forall>c:\<iota>. \<gamma> | \<iota> \<Rightarrow> \<gamma> | refl \<sigma> | sym \<gamma> | \<gamma>\<^isub>1 \<circ> \<gamma>\<^isub>2"}\\
+ − 459
& @{text "|"} & @{text "\<gamma> @ \<sigma> | left \<gamma> | right \<gamma> | \<gamma>\<^isub>1 \<sim> \<gamma>\<^isub>2 | rightc \<gamma> | leftc \<gamma> | \<gamma>\<^isub>1 \<triangleright> \<gamma>\<^isub>2"}\smallskip\\
+ − 460
\multicolumn{3}{@ {}l}{Terms}\\
+ − 461
@{text "e"} & @{text "::="} & @{text "x | K | \<Lambda>a:\<kappa>. e | \<Lambda>c:\<iota>. e | e \<sigma> | e \<gamma> | \<lambda>x:\<sigma>. e | e\<^isub>1 e\<^isub>2"}\\
+ − 462
& @{text "|"} & @{text "\<LET> x:\<sigma> = e\<^isub>1 \<IN> e\<^isub>2 | \<CASE> e\<^isub>1 \<OF>"}$\;\overline{@{text "p \<rightarrow> e\<^isub>2"}}$ @{text "| e \<triangleright> \<gamma>"}\smallskip\\
+ − 463
\multicolumn{3}{@ {}l}{Patterns}\\
+ − 464
@{text "p"} & @{text "::="} & @{text "K"}$\;\overline{@{text "a:\<kappa>"}}\;\overline{@{text "c:\<iota>"}}\;\overline{@{text "x:\<sigma>"}}$\smallskip\\
+ − 465
\multicolumn{3}{@ {}l}{Constants}\\
+ − 466
& @{text C} & coercion constants\\
+ − 467
& @{text T} & value type constructors\\
+ − 468
& @{text "S\<^isub>n"} & n-ary type functions (which need to be fully applied)\\
+ − 469
& @{text K} & data constructors\smallskip\\
+ − 470
\multicolumn{3}{@ {}l}{Variables}\\
+ − 471
& @{text a} & type variables\\
+ − 472
& @{text c} & coercion variables\\
+ − 473
& @{text x} & term variables\\
+ − 474
\end{tabular}
+ − 475
\end{center}
+ − 476
\end{boxedminipage}
+ − 477
\caption{The System @{text "F\<^isub>C"}
+ − 478
\cite{CoreHaskell}, also often referred to as \emph{Core-Haskell}. In this
+ − 479
version of @{text "F\<^isub>C"} we made a modification by separating the
+ − 480
grammars for type kinds and coercion kinds, as well as for types and coercion
+ − 481
types. For this paper the interesting term-constructor is @{text "\<CASE>"},
3041
+ − 482
which binds multiple type-, coercion- and term-variables (the overlines stand for lists).\label{corehas}}
2991
+ − 483
\end{figure}
2985
+ − 484
*}
+ − 485
+ − 486
section {* A Short Review of the Nominal Logic Work *}
+ − 487
+ − 488
text {*
3106
+ − 489
At its core, Nominal Isabelle is an adaptation of the nominal logic work by
2985
+ − 490
Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
+ − 491
\cite{HuffmanUrban10} (including proofs). We shall briefly review this work
+ − 492
to aid the description of what follows.
+ − 493
+ − 494
Two central notions in the nominal logic work are sorted atoms and
3001
+ − 495
sort-respecting permutations of atoms. We will use the letters @{text "a, b,
3002
+ − 496
c, \<dots>"} to stand for atoms and @{text "\<pi>, \<pi>\<^isub>1, \<dots>"} to stand for permutations,
3001
+ − 497
which in Nominal Isabelle have type @{typ perm}. The purpose of atoms is to
+ − 498
represent variables, be they bound or free. The sorts of atoms can be used
+ − 499
to represent different kinds of variables, such as the term-, coercion- and
+ − 500
type-variables in Core-Haskell. It is assumed that there is an infinite
+ − 501
supply of atoms for each sort. In the interest of brevity, we shall restrict
+ − 502
ourselves in what follows to only one sort of atoms.
2985
+ − 503
+ − 504
Permutations are bijective functions from atoms to atoms that are
+ − 505
the identity everywhere except on a finite number of atoms. There is a
+ − 506
two-place permutation operation written
3129
+ − 507
@{text "_ \<bullet> _ "} and having the type @{text "perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
2985
+ − 508
where the generic type @{text "\<beta>"} is the type of the object
+ − 509
over which the permutation
+ − 510
acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
3159
+ − 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),
3000
+ − 513
and the inverse permutation of @{term "\<pi>"} as @{text "- \<pi>"}. The permutation
3002
+ − 514
operation is defined over Isabelle/HOL's type-hierarchy \cite{HuffmanUrban10};
3011
+ − 515
for example permutations acting on atoms, products, lists, permutations, sets,
+ − 516
functions and booleans are given by:
2985
+ − 517
+ − 518
\begin{equation}\label{permute}
+ − 519
\mbox{\begin{tabular}{@ {}c@ {\hspace{10mm}}c@ {}}
+ − 520
\begin{tabular}{@ {}l@ {}}
3011
+ − 521
@{text "\<pi> \<bullet> a \<equiv> \<pi> a"}\\
3000
+ − 522
@{thm permute_prod.simps[where p="\<pi>", no_vars, THEN eq_reflection]}\\[2mm]
+ − 523
@{thm permute_list.simps(1)[where p="\<pi>", no_vars, THEN eq_reflection]}\\
+ − 524
@{thm permute_list.simps(2)[where p="\<pi>", no_vars, THEN eq_reflection]}\\
2985
+ − 525
\end{tabular} &
+ − 526
\begin{tabular}{@ {}l@ {}}
3011
+ − 527
@{thm permute_perm_def[where p="\<pi>" and q="\<pi>'", no_vars, THEN eq_reflection]}\\
3128
+ − 528
@{thm permute_set_def[where p="\<pi>", no_vars, THEN eq_reflection]}\\
3000
+ − 529
@{text "\<pi> \<bullet> f \<equiv> \<lambda>x. \<pi> \<bullet> (f (- \<pi> \<bullet> x))"}\\
+ − 530
@{thm permute_bool_def[where p="\<pi>", no_vars, THEN eq_reflection]}
2985
+ − 531
\end{tabular}
+ − 532
\end{tabular}}
3000
+ − 533
\end{equation}\smallskip
2985
+ − 534
+ − 535
\noindent
+ − 536
Concrete permutations in Nominal Isabelle are built up from swappings,
+ − 537
written as \mbox{@{text "(a b)"}}, which are permutations that behave
+ − 538
as follows:
2991
+ − 539
3000
+ − 540
\[
2985
+ − 541
@{text "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
3000
+ − 542
\]\smallskip
2985
+ − 543
+ − 544
The most original aspect of the nominal logic work of Pitts is a general
3023
+ − 545
definition for the notion of the `set of free variables of an object @{text
+ − 546
"x"}'. This notion, written @{term "supp x"}, is general in the sense that
2989
+ − 547
it applies not only to lambda-terms (alpha-equated or not), but also to lists,
3008
+ − 548
products, sets and even functions. Its definition depends only on the
2985
+ − 549
permutation operation and on the notion of equality defined for the type of
+ − 550
@{text x}, namely:
2991
+ − 551
2985
+ − 552
\begin{equation}\label{suppdef}
+ − 553
@{thm supp_def[no_vars, THEN eq_reflection]}
3001
+ − 554
\end{equation}\smallskip
2985
+ − 555
+ − 556
\noindent
+ − 557
There is also the derived notion for when an atom @{text a} is \emph{fresh}
3000
+ − 558
for an @{text x}, defined as
+ − 559
+ − 560
\[
+ − 561
@{thm fresh_def[no_vars]}
+ − 562
\]\smallskip
+ − 563
+ − 564
\noindent
2985
+ − 565
We use for sets of atoms the abbreviation
+ − 566
@{thm (lhs) fresh_star_def[no_vars]}, defined as
+ − 567
@{thm (rhs) fresh_star_def[no_vars]}.
+ − 568
A striking consequence of these definitions is that we can prove
+ − 569
without knowing anything about the structure of @{term x} that
+ − 570
swapping two fresh atoms, say @{text a} and @{text b}, leaves
3000
+ − 571
@{text x} unchanged, namely
2985
+ − 572
2989
+ − 573
\begin{prop}\label{swapfreshfresh}
3000
+ − 574
If @{thm (prem 1) swap_fresh_fresh[no_vars]} and @{thm (prem 2) swap_fresh_fresh[no_vars]}
3001
+ − 575
then @{thm (concl) swap_fresh_fresh[no_vars]}.
2989
+ − 576
\end{prop}
2985
+ − 577
+ − 578
While often the support of an object can be relatively easily
+ − 579
described, for example for atoms, products, lists, function applications,
+ − 580
booleans and permutations as follows
+ − 581
3004
+ − 582
\begin{equation}\label{supps}\mbox{
2985
+ − 583
\begin{tabular}{c@ {\hspace{10mm}}c}
+ − 584
\begin{tabular}{rcl}
+ − 585
@{term "supp a"} & $=$ & @{term "{a}"}\\
+ − 586
@{term "supp (x, y)"} & $=$ & @{term "supp x \<union> supp y"}\\
+ − 587
@{term "supp []"} & $=$ & @{term "{}"}\\
+ − 588
@{term "supp (x#xs)"} & $=$ & @{term "supp x \<union> supp xs"}\\
+ − 589
\end{tabular}
+ − 590
&
+ − 591
\begin{tabular}{rcl}
+ − 592
@{text "supp (f x)"} & @{text "\<subseteq>"} & @{term "supp f \<union> supp x"}\\
+ − 593
@{term "supp b"} & $=$ & @{term "{}"}\\
3000
+ − 594
@{term "supp \<pi>"} & $=$ & @{term "{a. \<pi> \<bullet> a \<noteq> a}"}
2985
+ − 595
\end{tabular}
3000
+ − 596
\end{tabular}}
3004
+ − 597
\end{equation}\smallskip
2985
+ − 598
+ − 599
\noindent
+ − 600
in some cases it can be difficult to characterise the support precisely, and
3000
+ − 601
only an approximation can be established (as for function applications
+ − 602
above). Reasoning about such approximations can be simplified with the
+ − 603
notion \emph{supports}, defined as follows:
2985
+ − 604
2989
+ − 605
\begin{defi}
3001
+ − 606
A set @{text S} \emph{supports} @{text x}, if for all atoms @{text a} and @{text b}
2985
+ − 607
not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
2989
+ − 608
\end{defi}
2985
+ − 609
+ − 610
\noindent
+ − 611
The main point of @{text supports} is that we can establish the following
+ − 612
two properties.
+ − 613
2989
+ − 614
\begin{prop}\label{supportsprop}
3126
+ − 615
Given a set @{text "bs"} of atoms.\\
+ − 616
{\it (i)} If @{thm (prem 1) supp_is_subset[where S="bs", no_vars]}
+ − 617
and @{thm (prem 2) supp_is_subset[where S="bs", no_vars]} then
+ − 618
@{thm (concl) supp_is_subset[where S="bs", no_vars]}.\\
2985
+ − 619
{\it (ii)} @{thm supp_supports[no_vars]}.
2989
+ − 620
\end{prop}
2985
+ − 621
+ − 622
Another important notion in the nominal logic work is \emph{equivariance}.
3126
+ − 623
For a function @{text f} to be equivariant
2985
+ − 624
it is required that every permutation leaves @{text f} unchanged, that is
+ − 625
+ − 626
\begin{equation}\label{equivariancedef}
3128
+ − 627
@{term "\<forall>\<pi>. \<pi> \<bullet> f = f"}\;.
3001
+ − 628
\end{equation}\smallskip
2985
+ − 629
3126
+ − 630
\noindent
3129
+ − 631
If a function is of type @{text "\<alpha> \<Rightarrow> \<beta>"}, say, this definition is equivalent to
3126
+ − 632
the fact that a permutation applied to the application
+ − 633
@{text "f x"} can be moved to the argument @{text x}. That means for
3128
+ − 634
such functions, we have for all permutations @{text "\<pi>"}:
2985
+ − 635
+ − 636
\begin{equation}\label{equivariance}
3001
+ − 637
@{text "\<pi> \<bullet> f = f"} \;\;\;\;\textit{if and only if}\;\;\;\;
3128
+ − 638
@{text "\<forall>x. \<pi> \<bullet> (f x) = f (\<pi> \<bullet> x)"}\;.
3001
+ − 639
\end{equation}\smallskip
2985
+ − 640
+ − 641
\noindent
3126
+ − 642
There is
+ − 643
also a similar property for relations, which are in HOL functions of type @{text "\<alpha> \<Rightarrow> \<beta> \<Rightarrow> bool"}.
3128
+ − 644
Suppose a relation @{text R}, then for all permutations @{text \<pi>}:
2985
+ − 645
3025
+ − 646
\[
3126
+ − 647
@{text "\<pi> \<bullet> R = R"} \;\;\;\;\textit{if and only if}\;\;\;\;
3128
+ − 648
@{text "\<forall>x y."}~~@{text "x R y"} \;\textit{implies}\; @{text "(\<pi> \<bullet> x) R (\<pi> \<bullet> y)"}\;.
3025
+ − 649
\]\smallskip
3126
+ − 650
+ − 651
\noindent
+ − 652
Note that from property \eqref{equivariancedef} and the definition of @{text supp}, we
3128
+ − 653
can easily deduce that for a function being equivariant is equivalent to having empty support.
3126
+ − 654
2985
+ − 655
Using freshness, the nominal logic work provides us with general means for renaming
+ − 656
binders.
+ − 657
+ − 658
\noindent
+ − 659
While in the older version of Nominal Isabelle, we used extensively
3126
+ − 660
Proposition~\ref{swapfreshfresh} to rename single binders, this property
2985
+ − 661
proved too unwieldy for dealing with multiple binders. For such binders the
+ − 662
following generalisations turned out to be easier to use.
+ − 663
2989
+ − 664
\begin{prop}\label{supppermeq}
3001
+ − 665
@{thm[mode=IfThen] supp_perm_eq[where p="\<pi>", no_vars]}
2989
+ − 666
\end{prop}
2985
+ − 667
2989
+ − 668
\begin{prop}\label{avoiding}
2985
+ − 669
For a finite set @{text as} and a finitely supported @{text x} with
+ − 670
@{term "as \<sharp>* x"} and also a finitely supported @{text c}, there
3001
+ − 671
exists a permutation @{text "\<pi>"} such that @{term "(\<pi> \<bullet> as) \<sharp>* c"} and
+ − 672
@{term "supp x \<sharp>* \<pi>"}.
2989
+ − 673
\end{prop}
2985
+ − 674
+ − 675
\noindent
+ − 676
The idea behind the second property is that given a finite set @{text as}
+ − 677
of binders (being bound, or fresh, in @{text x} is ensured by the
3001
+ − 678
assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text "\<pi>"} such that
+ − 679
the renamed binders @{term "\<pi> \<bullet> as"} avoid @{text c} (which can be arbitrarily chosen
+ − 680
as long as it is finitely supported) and also @{text "\<pi>"} does not affect anything
+ − 681
in the support of @{text x} (that is @{term "supp x \<sharp>* \<pi>"}). The last
3023
+ − 682
fact and Property~\ref{supppermeq} allow us to `rename' just the binders
3011
+ − 683
@{text as} in @{text x}, because @{term "\<pi> \<bullet> x = x"}.
+ − 684
+ − 685
Note that @{term "supp x \<sharp>* \<pi>"}
3004
+ − 686
is equivalent with @{term "supp \<pi> \<sharp>* x"}, which means we could also formulate
3021
+ − 687
Propositions \ref{supppermeq} and \ref{avoiding} in the other `direction'; however the
3004
+ − 688
reasoning infrastructure of Nominal Isabelle is set up so that it provides more
3011
+ − 689
automation for the formulation given above.
2985
+ − 690
+ − 691
Most properties given in this section are described in detail in \cite{HuffmanUrban10}
+ − 692
and all are formalised in Isabelle/HOL. In the next sections we will make
3001
+ − 693
use of these properties in order to define alpha-equivalence in
2985
+ − 694
the presence of multiple binders.
+ − 695
*}
+ − 696
+ − 697
3016
+ − 698
section {* Abstractions\label{sec:binders} *}
2985
+ − 699
+ − 700
text {*
+ − 701
In Nominal Isabelle, the user is expected to write down a specification of a
+ − 702
term-calculus and then a reasoning infrastructure is automatically derived
+ − 703
from this specification (remember that Nominal Isabelle is a definitional
+ − 704
extension of Isabelle/HOL, which does not introduce any new axioms).
+ − 705
+ − 706
In order to keep our work with deriving the reasoning infrastructure
+ − 707
manageable, we will wherever possible state definitions and perform proofs
3023
+ − 708
on the `user-level' of Isabelle/HOL, as opposed to writing custom ML-code that
2985
+ − 709
generates them anew for each specification.
+ − 710
To that end, we will consider
+ − 711
first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}. These pairs
+ − 712
are intended to represent the abstraction, or binding, of the set of atoms @{text
+ − 713
"as"} in the body @{text "x"}.
+ − 714
+ − 715
The first question we have to answer is when two pairs @{text "(as, x)"} and
2989
+ − 716
@{text "(bs, y)"} are alpha-equivalent? (For the moment we are interested in
+ − 717
the notion of alpha-equivalence that is \emph{not} preserved by adding
2985
+ − 718
vacuous binders.) To answer this question, we identify four conditions: {\it (i)}
+ − 719
given a free-atom function @{text "fa"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
3126
+ − 720
set"}}, then @{text "(as, x)"} and @{text "(bs, y)"} need to have the same set of free
3001
+ − 721
atoms; moreover there must be a permutation @{text \<pi>} such that {\it
3126
+ − 722
(ii)} @{text \<pi>} leaves the free atoms of @{text "(as, x)"} and @{text "(bs, y)"} unchanged, but
3023
+ − 723
{\it (iii)} `moves' their bound names so that we obtain modulo a relation,
2985
+ − 724
say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
3001
+ − 725
@{text \<pi>} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
3010
+ − 726
requirements {\it (i)} to {\it (iv)} can be stated formally as:
3001
+ − 727
+ − 728
\begin{defi}[Alpha-Equivalence for Set-Bindings]\label{alphaset}\mbox{}\\
+ − 729
\begin{tabular}{@ {\hspace{10mm}}l@ {\hspace{5mm}}rl}
3006
+ − 730
@{term "alpha_set_ex (as, x) R fa (bs, y)"}\hspace{2mm}@{text "\<equiv>"} &
+ − 731
\multicolumn{2}{@ {}l}{if there exists a @{text "\<pi>"} such that:}\\
3001
+ − 732
& \mbox{\it (i)} & @{term "fa(x) - as = fa(y) - bs"}\\
+ − 733
& \mbox{\it (ii)} & @{term "(fa(x) - as) \<sharp>* \<pi>"}\\
+ − 734
& \mbox{\it (iii)} & @{text "(\<pi> \<bullet> x) R y"} \\
+ − 735
& \mbox{\it (iv)} & @{term "(\<pi> \<bullet> as) = bs"} \\
+ − 736
\end{tabular}
+ − 737
\end{defi}
+ − 738
2985
+ − 739
\noindent
3006
+ − 740
Note that the relation is
2985
+ − 741
dependent on a free-atom function @{text "fa"} and a relation @{text
+ − 742
"R"}. The reason for this extra generality is that we will use
3025
+ − 743
$\approx_{\,\textit{set}}^{\textit{R}, \textit{fa}}$ for both raw terms and
3013
+ − 744
alpha-equated terms. In
2985
+ − 745
the latter case, @{text R} will be replaced by equality @{text "="} and we
+ − 746
will prove that @{text "fa"} is equal to @{text "supp"}.
+ − 747
3001
+ − 748
Definition \ref{alphaset} does not make any distinction between the
2989
+ − 749
order of abstracted atoms. If we want this, then we can define alpha-equivalence
2985
+ − 750
for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"}
+ − 751
as follows
3001
+ − 752
+ − 753
\begin{defi}[Alpha-Equivalence for List-Bindings]\label{alphalist}\mbox{}\\
+ − 754
\begin{tabular}{@ {\hspace{10mm}}l@ {\hspace{5mm}}rl}
3006
+ − 755
@{term "alpha_lst_ex (as, x) R fa (bs, y)"}\hspace{2mm}@{text "\<equiv>"} &
+ − 756
\multicolumn{2}{@ {}l}{if there exists a @{text "\<pi>"} such that:}\\
3001
+ − 757
& \mbox{\it (i)} & @{term "fa(x) - (set as) = fa(y) - (set bs)"}\\
+ − 758
& \mbox{\it (ii)} & @{term "(fa(x) - set as) \<sharp>* \<pi>"}\\
+ − 759
& \mbox{\it (iii)} & @{text "(\<pi> \<bullet> x) R y"}\\
+ − 760
& \mbox{\it (iv)} & @{term "(\<pi> \<bullet> as) = bs"}\\
+ − 761
\end{tabular}
+ − 762
\end{defi}
+ − 763
2985
+ − 764
\noindent
+ − 765
where @{term set} is the function that coerces a list of atoms into a set of atoms.
+ − 766
Now the last clause ensures that the order of the binders matters (since @{text as}
+ − 767
and @{text bs} are lists of atoms).
+ − 768
+ − 769
If we do not want to make any difference between the order of binders \emph{and}
3021
+ − 770
also allow vacuous binders, that means according to Pitts~\cite{Pitts04}
3044
+ − 771
\emph{restrict} atoms, then we keep sets of binders, but drop
3001
+ − 772
condition {\it (iv)} in Definition~\ref{alphaset}:
+ − 773
+ − 774
\begin{defi}[Alpha-Equivalence for Set+-Bindings]\label{alphares}\mbox{}\\
+ − 775
\begin{tabular}{@ {\hspace{10mm}}l@ {\hspace{5mm}}rl}
3006
+ − 776
@{term "alpha_res_ex (as, x) R fa (bs, y)"}\hspace{2mm}@{text "\<equiv>"} &
+ − 777
\multicolumn{2}{@ {}l}{if there exists a @{text "\<pi>"} such that:}\\
3001
+ − 778
& \mbox{\it (i)} & @{term "fa(x) - as = fa(y) - bs"}\\
+ − 779
& \mbox{\it (ii)} & @{term "(fa(x) - as) \<sharp>* \<pi>"}\\
+ − 780
& \mbox{\it (iii)} & @{text "(\<pi> \<bullet> x) R y"}\\
+ − 781
\end{tabular}
+ − 782
\end{defi}
+ − 783
2985
+ − 784
+ − 785
It might be useful to consider first some examples how these definitions
2989
+ − 786
of alpha-equivalence pan out in practice. For this consider the case of
2985
+ − 787
abstracting a set of atoms over types (as in type-schemes). We set
+ − 788
@{text R} to be the usual equality @{text "="} and for @{text "fa(T)"} we
+ − 789
define
3001
+ − 790
+ − 791
\[
3044
+ − 792
@{text "fa(x) \<equiv> {x}"} \hspace{10mm} @{text "fa(T\<^isub>1 \<rightarrow> T\<^isub>2) \<equiv> fa(T\<^isub>1) \<union> fa(T\<^isub>2)"}
3001
+ − 793
\]\smallskip
2985
+ − 794
+ − 795
\noindent
+ − 796
Now recall the examples shown in \eqref{ex1} and
+ − 797
\eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and
3126
+ − 798
@{text "({x, y}, y \<rightarrow> x)"} are alpha-equivalent according to
3001
+ − 799
$\approx_{\,\textit{set}}$ and $\approx_{\,\textit{set+}}$ by taking @{text "\<pi>"} to
2985
+ − 800
be the swapping @{term "(x \<rightleftharpoons> y)"}. In case of @{text "x \<noteq> y"}, then @{text
+ − 801
"([x, y], x \<rightarrow> y)"} $\not\approx_{\,\textit{list}}$ @{text "([y, x], x \<rightarrow> y)"}
+ − 802
since there is no permutation that makes the lists @{text "[x, y]"} and
+ − 803
@{text "[y, x]"} equal, and also leaves the type \mbox{@{text "x \<rightarrow> y"}}
+ − 804
unchanged. Another example is @{text "({x}, x)"} $\approx_{\,\textit{set+}}$
3001
+ − 805
@{text "({x, y}, x)"} which holds by taking @{text "\<pi>"} to be the identity
2985
+ − 806
permutation. However, if @{text "x \<noteq> y"}, then @{text "({x}, x)"}
+ − 807
$\not\approx_{\,\textit{set}}$ @{text "({x, y}, x)"} since there is no
+ − 808
permutation that makes the sets @{text "{x}"} and @{text "{x, y}"} equal
+ − 809
(similarly for $\approx_{\,\textit{list}}$). It can also relatively easily be
2989
+ − 810
shown that all three notions of alpha-equivalence coincide, if we only
3037
+ − 811
abstract a single atom. In this case they also agree with the alpha-equivalence
3038
+ − 812
used in older versions of Nominal Isabelle \cite{Urban08}.\footnote{We omit a
+ − 813
proof of this fact since the details are hairy and not really important for the
+ − 814
purpose of this paper.}
2985
+ − 815
3021
+ − 816
In the rest of this section we are going to show that the alpha-equivalences
3025
+ − 817
really lead to abstractions where some atoms are bound (or more precisely
3021
+ − 818
removed from the support). For this we will consider three abstraction
+ − 819
types that are quotients of the relations
3001
+ − 820
2985
+ − 821
\begin{equation}
3002
+ − 822
\begin{array}{r}
3011
+ − 823
@{term "alpha_set_ex (as, x) equal supp (bs, y)"}\smallskip\\
+ − 824
@{term "alpha_res_ex (as, x) equal supp (bs, y)"}\smallskip\\
+ − 825
@{term "alpha_lst_ex (as, x) equal supp (bs, y)"}\\
3001
+ − 826
\end{array}
3002
+ − 827
\end{equation}\smallskip
2985
+ − 828
+ − 829
\noindent
3106
+ − 830
Note that in these relations we replaced the free-atom function @{text "fa"}
3007
+ − 831
with @{term "supp"} and the relation @{text R} with equality. We can show
3013
+ − 832
the following two properties:
3007
+ − 833
2989
+ − 834
\begin{lem}\label{alphaeq}
3011
+ − 835
The relations $\approx_{\,\textit{set}}^{=, \textit{supp}}$,
+ − 836
$\approx_{\,\textit{set+}}^{=, \textit{supp}}$
+ − 837
and $\approx_{\,\textit{list}}^{=, \textit{supp}}$ are
+ − 838
equivalence relations and equivariant.
2989
+ − 839
\end{lem}
2985
+ − 840
+ − 841
\begin{proof}
3001
+ − 842
Reflexivity is by taking @{text "\<pi>"} to be @{text "0"}. For symmetry we have
3011
+ − 843
a permutation @{text "\<pi>"} and for the proof obligation take @{term "-
+ − 844
\<pi>"}. In case of transitivity, we have two permutations @{text "\<pi>\<^isub>1"}
+ − 845
and @{text "\<pi>\<^isub>2"}, and for the proof obligation use @{text
+ − 846
"\<pi>\<^isub>1 + \<pi>\<^isub>2"}. Equivariance means @{term "alpha_set_ex (\<pi> \<bullet> as,
+ − 847
\<pi> \<bullet> x) equal supp (\<pi> \<bullet> bs, \<pi> \<bullet> y)"} holds provided \mbox{@{term
3013
+ − 848
"alpha_set_ex (as, x) equal supp(bs, y)"}} holds. From the assumption we
+ − 849
have a permutation @{text "\<pi>'"} and for the proof obligation use @{text "\<pi> \<bullet>
3044
+ − 850
\<pi>'"}. To show equivariance, we need to `pull out' the permutations,
3013
+ − 851
which is possible since all operators, namely as @{text "#\<^sup>*, -, =, \<bullet>,
+ − 852
set"} and @{text "supp"}, are equivariant (see
+ − 853
\cite{HuffmanUrban10}). Finally, we apply the permutation operation on
+ − 854
booleans.
2985
+ − 855
\end{proof}
+ − 856
+ − 857
\noindent
3008
+ − 858
Recall the picture shown in \eqref{picture} about new types in HOL.
+ − 859
The lemma above allows us to use our quotient package for introducing
3002
+ − 860
new types @{text "\<beta> abs\<^bsub>set\<^esub>"}, @{text "\<beta> abs\<^bsub>set+\<^esub>"} and @{text "\<beta> abs\<^bsub>list\<^esub>"}
2989
+ − 861
representing alpha-equivalence classes of pairs of type
2985
+ − 862
@{text "(atom set) \<times> \<beta>"} (in the first two cases) and of type @{text "(atom list) \<times> \<beta>"}
+ − 863
(in the third case).
+ − 864
The elements in these types will be, respectively, written as
+ − 865
3002
+ − 866
\[
+ − 867
@{term "Abs_set as x"} \hspace{10mm}
+ − 868
@{term "Abs_res as x"} \hspace{10mm}
+ − 869
@{term "Abs_lst as x"}
+ − 870
\]\smallskip
2985
+ − 871
+ − 872
\noindent
+ − 873
indicating that a set (or list) of atoms @{text as} is abstracted in @{text x}. We will
+ − 874
call the types \emph{abstraction types} and their elements
+ − 875
\emph{abstractions}. The important property we need to derive is the support of
+ − 876
abstractions, namely:
+ − 877
2989
+ − 878
\begin{thm}[Support of Abstractions]\label{suppabs}
2985
+ − 879
Assuming @{text x} has finite support, then
+ − 880
3002
+ − 881
\[
+ − 882
\begin{array}{l@ {\;=\;}l}
+ − 883
@{thm (lhs) supp_Abs(1)[no_vars]} & @{thm (rhs) supp_Abs(1)[no_vars]}\\
+ − 884
@{thm (lhs) supp_Abs(2)[no_vars]} & @{thm (rhs) supp_Abs(2)[no_vars]}\\
+ − 885
@{thm (lhs) supp_Abs(3)[where bs="as", no_vars]} &
+ − 886
@{thm (rhs) supp_Abs(3)[where bs="as", no_vars]}\\
+ − 887
\end{array}
+ − 888
\]\smallskip
2989
+ − 889
\end{thm}
2985
+ − 890
+ − 891
\noindent
3006
+ − 892
In effect, this theorem states that the atoms @{text "as"} are bound in the
3025
+ − 893
abstraction. As stated earlier, this can be seen as a litmus test that our
3006
+ − 894
Definitions \ref{alphaset}, \ref{alphalist} and \ref{alphares} capture the
+ − 895
idea of alpha-equivalence relations. Below we will give the proof for the
+ − 896
first equation of Theorem \ref{suppabs}. The others follow by similar
+ − 897
arguments. By definition of the abstraction type @{text
+ − 898
"abs\<^bsub>set\<^esub>"} we have
2985
+ − 899
+ − 900
\begin{equation}\label{abseqiff}
3098
+ − 901
@{thm (lhs) Abs_eq_iff(1)[where bs="as" and bs'="bs", no_vars]} \;\;\;\text{if and only if}\;\;\;
3006
+ − 902
@{term "alpha_set_ex (as, x) equal supp (bs, y)"}
3002
+ − 903
\end{equation}\smallskip
2985
+ − 904
+ − 905
\noindent
3129
+ − 906
and also set
2985
+ − 907
+ − 908
\begin{equation}\label{absperm}
3129
+ − 909
@{thm permute_Abs(1)[where p="\<pi>", no_vars, THEN eq_reflection]}
3002
+ − 910
\end{equation}\smallskip
2985
+ − 911
+ − 912
\noindent
3129
+ − 913
With this at our disposal, we can show
2985
+ − 914
the following lemma about swapping two atoms in an abstraction.
+ − 915
2989
+ − 916
\begin{lem}
3004
+ − 917
If @{thm (prem 1) Abs_swap1(1)[where bs="as", no_vars]} and
+ − 918
@{thm (prem 2) Abs_swap1(1)[where bs="as", no_vars]} then
+ − 919
@{thm (concl) Abs_swap1(1)[where bs="as", no_vars]}
2989
+ − 920
\end{lem}
2985
+ − 921
+ − 922
\begin{proof}
3025
+ − 923
If @{term "a = b"} the lemma is immediate, since @{term "(a \<rightleftharpoons> b)"} is then
+ − 924
the identity permutation.
3021
+ − 925
Also in the other case the lemma is straightforward using \eqref{abseqiff}
+ − 926
and observing that the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) =
3025
+ − 927
(supp x - as)"}. We therefore can use the swapping @{term "(a \<rightleftharpoons> b)"} as
+ − 928
the permutation for the proof obligation.
2985
+ − 929
\end{proof}
+ − 930
+ − 931
\noindent
3126
+ − 932
This lemma together
2985
+ − 933
with \eqref{absperm} allows us to show
+ − 934
+ − 935
\begin{equation}\label{halfone}
+ − 936
@{thm Abs_supports(1)[no_vars]}
3004
+ − 937
\end{equation}\smallskip
2985
+ − 938
+ − 939
\noindent
3023
+ − 940
which by Property~\ref{supportsprop} gives us `one half' of
3126
+ − 941
Theorem~\ref{suppabs}. To establish the `other half', we
+ − 942
use a trick from \cite{Pitts04} and first define an auxiliary
3004
+ − 943
function @{text aux}, taking an abstraction as argument
+ − 944
+ − 945
\[
+ − 946
@{thm supp_set.simps[THEN eq_reflection, no_vars]}
+ − 947
\]\smallskip
+ − 948
+ − 949
\noindent
2985
+ − 950
Using the second equation in \eqref{equivariance}, we can show that
3004
+ − 951
@{text "aux"} is equivariant (since @{term "\<pi> \<bullet> (supp x - as) = (supp (\<pi> \<bullet> x)) - (\<pi> \<bullet> as)"})
2985
+ − 952
and therefore has empty support.
+ − 953
This in turn means
+ − 954
3004
+ − 955
\[
+ − 956
@{term "supp (supp_set (Abs_set as x)) \<subseteq> supp (Abs_set as x)"}
+ − 957
\]\smallskip
2985
+ − 958
+ − 959
\noindent
3006
+ − 960
using the fact about the support of function applications in \eqref{supps}. Assuming
3004
+ − 961
@{term "supp x - as"} is a finite set, we further obtain
2985
+ − 962
+ − 963
\begin{equation}\label{halftwo}
+ − 964
@{thm (concl) Abs_supp_subset1(1)[no_vars]}
3004
+ − 965
\end{equation}\smallskip
2985
+ − 966
+ − 967
\noindent
3044
+ − 968
This is because for every finite set of atoms, say @{text "bs"}, we have
3129
+ − 969
@{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}.\footnote{Note that this is not
+ − 970
the case for infinite sets.}
2985
+ − 971
Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes
3025
+ − 972
the first equation of Theorem~\ref{suppabs}. The others are similar.
2985
+ − 973
3021
+ − 974
Recall the definition of support given in \eqref{suppdef}, and note the difference between
3025
+ − 975
the support of a raw pair and an abstraction
3010
+ − 976
+ − 977
\[
+ − 978
@{term "supp (as, x) = supp as \<union> supp x"}\hspace{15mm}
+ − 979
@{term "supp (Abs_set as x) = supp x - as"}
+ − 980
\]\smallskip
+ − 981
+ − 982
\noindent
3013
+ − 983
While the permutation operations behave in both cases the same (a permutation
3010
+ − 984
is just moved to the arguments), the notion of equality is different for pairs and
3021
+ − 985
abstractions. Therefore we have different supports. In case of abstractions,
3023
+ − 986
we have established in Theorem~\ref{suppabs} that bound atoms are removed from
+ − 987
the support of the abstractions' bodies.
3010
+ − 988
3004
+ − 989
The method of first considering abstractions of the form @{term "Abs_set as
+ − 990
x"} etc is motivated by the fact that we can conveniently establish at the
+ − 991
Isabelle/HOL level properties about them. It would be extremely laborious
+ − 992
to write custom ML-code that derives automatically such properties for every
+ − 993
term-constructor that binds some atoms. Also the generality of the
+ − 994
definitions for alpha-equivalence will help us in the next sections.
2985
+ − 995
*}
+ − 996
+ − 997
section {* Specifying General Bindings\label{sec:spec} *}
+ − 998
+ − 999
text {*
+ − 1000
Our choice of syntax for specifications is influenced by the existing
+ − 1001
datatype package of Isabelle/HOL \cite{Berghofer99}
+ − 1002
and by the syntax of the
+ − 1003
Ott-tool \cite{ott-jfp}. For us a specification of a term-calculus is a
3106
+ − 1004
collection of (possibly mutually recursive) type declarations, say @{text
2985
+ − 1005
"ty\<AL>\<^isub>1, \<dots>, ty\<AL>\<^isub>n"}, and an associated collection of
+ − 1006
binding functions, say @{text "bn\<AL>\<^isub>1, \<dots>, bn\<AL>\<^isub>m"}. The
3006
+ − 1007
syntax in Nominal Isabelle for such specifications is schematically as follows:
2985
+ − 1008
+ − 1009
\begin{equation}\label{scheme}
+ − 1010
\mbox{\begin{tabular}{@ {}p{2.5cm}l}
+ − 1011
type \mbox{declaration part} &
+ − 1012
$\begin{cases}
2989
+ − 1013
\mbox{\begin{tabular}{l}
2985
+ − 1014
\isacommand{nominal\_datatype} @{text "ty\<AL>\<^isub>1 = \<dots>"}\\
+ − 1015
\isacommand{and} @{text "ty\<AL>\<^isub>2 = \<dots>"}\\
+ − 1016
\raisebox{2mm}{$\ldots$}\\[-2mm]
+ − 1017
\isacommand{and} @{text "ty\<AL>\<^isub>n = \<dots>"}\\
+ − 1018
\end{tabular}}
3006
+ − 1019
\end{cases}$\\[2mm]
2985
+ − 1020
binding \mbox{function part} &
+ − 1021
$\begin{cases}
2989
+ − 1022
\mbox{\begin{tabular}{l}
2985
+ − 1023
\isacommand{binder} @{text "bn\<AL>\<^isub>1"} \isacommand{and} \ldots \isacommand{and} @{text "bn\<AL>\<^isub>m"}\\
+ − 1024
\isacommand{where}\\
+ − 1025
\raisebox{2mm}{$\ldots$}\\[-2mm]
+ − 1026
\end{tabular}}
+ − 1027
\end{cases}$\\
+ − 1028
\end{tabular}}
3004
+ − 1029
\end{equation}\smallskip
2985
+ − 1030
+ − 1031
\noindent
3004
+ − 1032
Every type declaration @{text ty}$^\alpha_{1..n}$ consists of a collection
+ − 1033
of term-constructors, each of which comes with a list of labelled types that
+ − 1034
stand for the types of the arguments of the term-constructor. For example a
+ − 1035
term-constructor @{text "C\<^sup>\<alpha>"} might be specified with
2985
+ − 1036
3004
+ − 1037
\[
3008
+ − 1038
@{text "C\<^sup>\<alpha> label\<^isub>1::ty"}\mbox{$'_1$} @{text "\<dots> label\<^isub>l::ty"}\mbox{$'_l\;\;\;\;\;$}
+ − 1039
@{text "binding_clauses"}
3004
+ − 1040
\]\smallskip
+ − 1041
+ − 1042
\noindent
+ − 1043
whereby some of the @{text ty}$'_{1..l}$ (or their components) can be
+ − 1044
contained in the collection of @{text ty}$^\alpha_{1..n}$ declared in
+ − 1045
\eqref{scheme}. In this case we will call the corresponding argument a
+ − 1046
\emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such
3023
+ − 1047
recursive arguments need to satisfy a `positivity' restriction, which
3004
+ − 1048
ensures that the type has a set-theoretic semantics (see
3126
+ − 1049
\cite{Berghofer99}). If the types are polymorphic, we require the
3129
+ − 1050
type variables to stand for types that are finitely supported and over which
3128
+ − 1051
a permutation operation is defined.
+ − 1052
The labels @{text "label"}$_{1..l}$ annotated on the types are optional. Their
3004
+ − 1053
purpose is to be used in the (possibly empty) list of \emph{binding
+ − 1054
clauses}, which indicate the binders and their scope in a term-constructor.
+ − 1055
They come in three \emph{modes}:
+ − 1056
+ − 1057
+ − 1058
\[\mbox{
+ − 1059
\begin{tabular}{@ {}l@ {}}
+ − 1060
\isacommand{binds} {\it binders} \isacommand{in} {\it bodies}\\
+ − 1061
\isacommand{binds (set)} {\it binders} \isacommand{in} {\it bodies}\\
+ − 1062
\isacommand{binds (set+)} {\it binders} \isacommand{in} {\it bodies}
+ − 1063
\end{tabular}}
+ − 1064
\]\smallskip
2985
+ − 1065
+ − 1066
\noindent
3004
+ − 1067
The first mode is for binding lists of atoms (the order of bound atoms
+ − 1068
matters); the second is for sets of binders (the order does not matter, but
+ − 1069
the cardinality does) and the last is for sets of binders (with vacuous
+ − 1070
binders preserving alpha-equivalence). As indicated, the labels in the
3023
+ − 1071
`\isacommand{in}-part' of a binding clause will be called \emph{bodies};
+ − 1072
the `\isacommand{binds}-part' will be called \emph{binders}. In contrast to
3004
+ − 1073
Ott, we allow multiple labels in binders and bodies. For example we allow
2985
+ − 1074
binding clauses of the form:
3004
+ − 1075
+ − 1076
\[\mbox{
2985
+ − 1077
\begin{tabular}{@ {}ll@ {}}
+ − 1078
@{text "Foo\<^isub>1 x::name y::name t::trm s::trm"} &
3004
+ − 1079
\isacommand{binds} @{text "x y"} \isacommand{in} @{text "t s"}\\
2985
+ − 1080
@{text "Foo\<^isub>2 x::name y::name t::trm s::trm"} &
3004
+ − 1081
\isacommand{binds} @{text "x y"} \isacommand{in} @{text "t"},
+ − 1082
\isacommand{binds} @{text "x y"} \isacommand{in} @{text "s"}\\
+ − 1083
\end{tabular}}
+ − 1084
\]\smallskip
2985
+ − 1085
+ − 1086
\noindent
3004
+ − 1087
Similarly for the other binding modes. Interestingly, in case of
+ − 1088
\isacommand{binds (set)} and \isacommand{binds (set+)} the binding clauses
+ − 1089
above will make a difference to the semantics of the specifications (the
+ − 1090
corresponding alpha-equivalence will differ). We will show this later with
+ − 1091
an example.
+ − 1092
2985
+ − 1093
3004
+ − 1094
There are also some restrictions we need to impose on our binding clauses in
3018
+ − 1095
comparison to Ott. The main idea behind these restrictions is
3017
+ − 1096
that we obtain a notion of alpha-equivalence where it is ensured
3004
+ − 1097
that within a given scope an atom occurrence cannot be both bound and free
+ − 1098
at the same time. The first restriction is that a body can only occur in
3006
+ − 1099
\emph{one} binding clause of a term constructor. So for example
+ − 1100
+ − 1101
\[\mbox{
+ − 1102
@{text "Foo x::name y::name t::trm"}\hspace{3mm}
+ − 1103
\isacommand{binds} @{text "x"} \isacommand{in} @{text "t"},
+ − 1104
\isacommand{binds} @{text "y"} \isacommand{in} @{text "t"}}
+ − 1105
\]\smallskip
+ − 1106
+ − 1107
\noindent
+ − 1108
is not allowed. This ensures that the bound atoms of a body cannot be free
+ − 1109
at the same time by specifying an alternative binder for the same body.
2985
+ − 1110
3004
+ − 1111
For binders we distinguish between \emph{shallow} and \emph{deep} binders.
+ − 1112
Shallow binders are just labels. The restriction we need to impose on them
+ − 1113
is that in case of \isacommand{binds (set)} and \isacommand{binds (set+)} the
+ − 1114
labels must either refer to atom types or to sets of atom types; in case of
3010
+ − 1115
\isacommand{binds} the labels must refer to atom types or to lists of atom
3004
+ − 1116
types. Two examples for the use of shallow binders are the specification of
+ − 1117
lambda-terms, where a single name is bound, and type-schemes, where a finite
+ − 1118
set of names is bound:
2985
+ − 1119
3004
+ − 1120
\[\mbox{
3010
+ − 1121
\begin{tabular}{@ {}c@ {\hspace{8mm}}c@ {}}
2985
+ − 1122
\begin{tabular}{@ {}l}
+ − 1123
\isacommand{nominal\_datatype} @{text lam} $=$\\
+ − 1124
\hspace{2mm}\phantom{$\mid$}~@{text "Var name"}\\
+ − 1125
\hspace{2mm}$\mid$~@{text "App lam lam"}\\
3004
+ − 1126
\hspace{2mm}$\mid$~@{text "Lam x::name t::lam"}\hspace{3mm}%
+ − 1127
\isacommand{binds} @{text x} \isacommand{in} @{text t}\\
3010
+ − 1128
\\
2985
+ − 1129
\end{tabular} &
+ − 1130
\begin{tabular}{@ {}l@ {}}
+ − 1131
\isacommand{nominal\_datatype}~@{text ty} $=$\\
3010
+ − 1132
\hspace{2mm}\phantom{$\mid$}~@{text "TVar name"}\\
+ − 1133
\hspace{2mm}$\mid$~@{text "TFun ty ty"}\\
+ − 1134
\isacommand{and}~@{text "tsc ="}\\
+ − 1135
\hspace{2mm}\phantom{$\mid$}~@{text "TAll xs::(name fset) T::ty"}\hspace{3mm}%
3004
+ − 1136
\isacommand{binds (set+)} @{text xs} \isacommand{in} @{text T}\\
2985
+ − 1137
\end{tabular}
3004
+ − 1138
\end{tabular}}
+ − 1139
\]\smallskip
+ − 1140
2985
+ − 1141
+ − 1142
\noindent
3018
+ − 1143
In these specifications @{text "name"} refers to a (concrete) atom type, and @{text
3006
+ − 1144
"fset"} to the type of finite sets. Note that for @{text Lam} it does not
3004
+ − 1145
matter which binding mode we use. The reason is that we bind only a single
3009
+ − 1146
@{text name}, in which case all three binding modes coincide. However, having
+ − 1147
\isacommand{binds (set)} or just \isacommand{binds}
3004
+ − 1148
in the second case makes a difference to the semantics of the specification
+ − 1149
(which we will define in the next section).
2985
+ − 1150
3023
+ − 1151
A \emph{deep} binder uses an auxiliary binding function that `picks' out
2985
+ − 1152
the atoms in one argument of the term-constructor, which can be bound in
+ − 1153
other arguments and also in the same argument (we will call such binders
+ − 1154
\emph{recursive}, see below). The binding functions are
3004
+ − 1155
expected to return either a set of atoms (for \isacommand{binds (set)} and
+ − 1156
\isacommand{binds (set+)}) or a list of atoms (for \isacommand{binds}). They need
+ − 1157
to be defined by recursion over the corresponding type; the equations
2985
+ − 1158
must be given in the binding function part of the scheme shown in
+ − 1159
\eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
3011
+ − 1160
tuple patterns may be specified as:
3004
+ − 1161
2985
+ − 1162
\begin{equation}\label{letpat}
2989
+ − 1163
\mbox{%
2985
+ − 1164
\begin{tabular}{l}
+ − 1165
\isacommand{nominal\_datatype} @{text trm} $=$\\
+ − 1166
\hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\
+ − 1167
\hspace{5mm}$\mid$~@{term "App trm trm"}\\
+ − 1168
\hspace{5mm}$\mid$~@{text "Lam x::name t::trm"}
3004
+ − 1169
\;\;\isacommand{binds} @{text x} \isacommand{in} @{text t}\\
3018
+ − 1170
\hspace{5mm}$\mid$~@{text "Let_pat p::pat trm t::trm"}
3004
+ − 1171
\;\;\isacommand{binds} @{text "bn(p)"} \isacommand{in} @{text t}\\
+ − 1172
\isacommand{and} @{text pat} $=$\\
3029
+ − 1173
\hspace{5mm}\phantom{$\mid$}~@{text "PVar name"}\\
3004
+ − 1174
\hspace{5mm}$\mid$~@{text "PTup pat pat"}\\
2985
+ − 1175
\isacommand{binder}~@{text "bn::pat \<Rightarrow> atom list"}\\
3029
+ − 1176
\isacommand{where}~@{text "bn(PVar x) = [atom x]"}\\
2985
+ − 1177
\hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\
+ − 1178
\end{tabular}}
3004
+ − 1179
\end{equation}\smallskip
+ − 1180
2985
+ − 1181
\noindent
+ − 1182
In this specification the function @{text "bn"} determines which atoms of
3011
+ − 1183
the pattern @{text p} (fifth line) are bound in the argument @{text "t"}. Note that in the
2985
+ − 1184
second-last @{text bn}-clause the function @{text "atom"} coerces a name
+ − 1185
into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This
+ − 1186
allows us to treat binders of different atom type uniformly.
+ − 1187
3008
+ − 1188
For deep binders we allow binding clauses such as
2985
+ − 1189
3004
+ − 1190
\[\mbox{
2985
+ − 1191
\begin{tabular}{ll}
+ − 1192
@{text "Bar p::pat t::trm"} &
3004
+ − 1193
\isacommand{binds} @{text "bn(p)"} \isacommand{in} @{text "p t"} \\
+ − 1194
\end{tabular}}
+ − 1195
\]\smallskip
+ − 1196
2985
+ − 1197
+ − 1198
\noindent
+ − 1199
where the argument of the deep binder also occurs in the body. We call such
+ − 1200
binders \emph{recursive}. To see the purpose of such recursive binders,
3023
+ − 1201
compare `plain' @{text "Let"}s and @{text "Let_rec"}s in the following
2985
+ − 1202
specification:
3004
+ − 1203
2985
+ − 1204
\begin{equation}\label{letrecs}
2989
+ − 1205
\mbox{%
3031
+ − 1206
\begin{tabular}{@ {}l@ {}l}
3129
+ − 1207
\isacommand{nominal\_datatype}~@{text "trm ="}\\
+ − 1208
\hspace{5mm}\phantom{$\mid$}~\ldots\\
2985
+ − 1209
\hspace{5mm}$\mid$~@{text "Let as::assn t::trm"}
3031
+ − 1210
& \hspace{-19mm}\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text t}\\
2985
+ − 1211
\hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"}
3031
+ − 1212
& \hspace{-19mm}\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\
3004
+ − 1213
\isacommand{and} @{text "assn"} $=$\\
+ − 1214
\hspace{5mm}\phantom{$\mid$}~@{text "ANil"}\\
+ − 1215
\hspace{5mm}$\mid$~@{text "ACons name trm assn"}\\
2985
+ − 1216
\isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\
+ − 1217
\isacommand{where}~@{text "bn(ANil) = []"}\\
+ − 1218
\hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\
+ − 1219
\end{tabular}}
3004
+ − 1220
\end{equation}\smallskip
+ − 1221
2985
+ − 1222
\noindent
+ − 1223
The difference is that with @{text Let} we only want to bind the atoms @{text
+ − 1224
"bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
+ − 1225
inside the assignment. This difference has consequences for the associated
2989
+ − 1226
notions of free-atoms and alpha-equivalence.
2985
+ − 1227
+ − 1228
To make sure that atoms bound by deep binders cannot be free at the
+ − 1229
same time, we cannot have more than one binding function for a deep binder.
+ − 1230
Consequently we exclude specifications such as
3006
+ − 1231
+ − 1232
\[\mbox{
2985
+ − 1233
\begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
+ − 1234
@{text "Baz\<^isub>1 p::pat t::trm"} &
3159
+ − 1235
\isacommand{binds} @{text "bn\<^isub>1(p) bn\<^isub>2(p)"} \isacommand{in} @{text "p t"}\\
2985
+ − 1236
@{text "Baz\<^isub>2 p::pat t\<^isub>1::trm t\<^isub>2::trm"} &
3159
+ − 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 "p t\<^isub>2"}\\
3006
+ − 1239
\end{tabular}}
+ − 1240
\]\smallskip
2985
+ − 1241
+ − 1242
\noindent
+ − 1243
Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} pick
3129
+ − 1244
out different atoms to become bound, respectively be free,
3159
+ − 1245
in @{text "p"}.\footnote{Since the Ott-tool does not derive a reasoning
3129
+ − 1246
infrastructure for
+ − 1247
alpha-equated terms with deep binders, it can permit such specifications.}
+ − 1248
3128
+ − 1249
3006
+ − 1250
We also need to restrict the form of the binding functions in order to
+ − 1251
ensure the @{text "bn"}-functions can be defined for alpha-equated
+ − 1252
terms. The main restriction is that we cannot return an atom in a binding
+ − 1253
function that is also bound in the corresponding term-constructor.
+ − 1254
Consider again the specification for @{text "trm"} and a contrived
3008
+ − 1255
version for assignments @{text "assn"}:
2985
+ − 1256
3006
+ − 1257
\begin{equation}\label{bnexp}
+ − 1258
\mbox{%
+ − 1259
\begin{tabular}{@ {}l@ {}}
+ − 1260
\isacommand{nominal\_datatype}~@{text "trm ="}~\ldots\\
+ − 1261
\isacommand{and} @{text "assn"} $=$\\
3008
+ − 1262
\hspace{5mm}\phantom{$\mid$}~@{text "ANil'"}\\
+ − 1263
\hspace{5mm}$\mid$~@{text "ACons' x::name y::name t::trm assn"}
3006
+ − 1264
\;\;\isacommand{binds} @{text "y"} \isacommand{in} @{text t}\\
+ − 1265
\isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\
3008
+ − 1266
\isacommand{where}~@{text "bn(ANil') = []"}\\
+ − 1267
\hspace{5mm}$\mid$~@{text "bn(ACons' x y t as) = [atom x] @ bn(as)"}\\
3006
+ − 1268
\end{tabular}}
+ − 1269
\end{equation}\smallskip
+ − 1270
+ − 1271
\noindent
3011
+ − 1272
In this example the term constructor @{text "ACons'"} has four arguments with
3017
+ − 1273
a binding clause involving two of them. This constructor is also used in the definition
3010
+ − 1274
of the binding function. The restriction we have to impose is that the
3017
+ − 1275
binding function can only return free atoms, that is the ones that are \emph{not}
3010
+ − 1276
mentioned in a binding clause. Therefore @{text "y"} cannot be used in the
+ − 1277
binding function @{text "bn"} (since it is bound in @{text "ACons'"} by the
+ − 1278
binding clause), but @{text x} can (since it is a free atom). This
+ − 1279
restriction is sufficient for lifting the binding function to alpha-equated
3017
+ − 1280
terms. If we would permit @{text "bn"} to return @{text "y"},
+ − 1281
then it would not be respectful and therefore cannot be lifted to
+ − 1282
alpha-equated lambda-terms.
3006
+ − 1283
+ − 1284
In the version of Nominal Isabelle described here, we also adopted the
+ − 1285
restriction from the Ott-tool that binding functions can only return: the
3008
+ − 1286
empty set or empty list (as in case @{text ANil'}), a singleton set or
3006
+ − 1287
singleton list containing an atom (case @{text PVar} in \eqref{letpat}), or
3008
+ − 1288
unions of atom sets or appended atom lists (case @{text ACons'}). This
3006
+ − 1289
restriction will simplify some automatic definitions and proofs later on.
2985
+ − 1290
3159
+ − 1291
To sum up this section, we introduced nominal datatype
+ − 1292
specifications, which are like standard datatype specifications in
3160
+ − 1293
Isabelle/HOL but extended with binding clauses and specifications for binding
3159
+ − 1294
functions. Each constructor argument in our specification can also
+ − 1295
have an optional label. These labels are used in the binding clauses
+ − 1296
of a constructor; there can be several binding clauses for each
+ − 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
3160
+ − 1306
are defined by recursion over a nominal datatype. They can
3159
+ − 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
3160
+ − 1311
atoms that are not mentioned in any binding clause.
+ − 1312
+ − 1313
In order to
+ − 1314
simplify our definitions of free atoms and alpha-equivalence we define next, we
3159
+ − 1315
shall assume specifications of term-calculi are implicitly
+ − 1316
\emph{completed}. By this we mean that for every argument of a
+ − 1317
term-constructor that is \emph{not} already part of a binding clause
+ − 1318
given by the user, we add implicitly a special \emph{empty} binding
+ − 1319
clause, written \isacommand{binds}~@{term
+ − 1320
"{}"}~\isacommand{in}~@{text "labels"}. In case of the lambda-terms,
+ − 1321
the completion produces
2985
+ − 1322
3006
+ − 1323
\[\mbox{
2985
+ − 1324
\begin{tabular}{@ {}l@ {\hspace{-1mm}}}
+ − 1325
\isacommand{nominal\_datatype} @{text lam} =\\
+ − 1326
\hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"}
3004
+ − 1327
\;\;\isacommand{binds}~@{term "{}"}~\isacommand{in}~@{text "x"}\\
2985
+ − 1328
\hspace{5mm}$\mid$~@{text "App t\<^isub>1::lam t\<^isub>2::lam"}
3004
+ − 1329
\;\;\isacommand{binds}~@{term "{}"}~\isacommand{in}~@{text "t\<^isub>1 t\<^isub>2"}\\
2985
+ − 1330
\hspace{5mm}$\mid$~@{text "Lam x::name t::lam"}
3004
+ − 1331
\;\;\isacommand{binds}~@{text x} \isacommand{in} @{text t}\\
3006
+ − 1332
\end{tabular}}
+ − 1333
\]\smallskip
2985
+ − 1334
+ − 1335
\noindent
+ − 1336
The point of completion is that we can make definitions over the binding
+ − 1337
clauses and be sure to have captured all arguments of a term constructor.
+ − 1338
*}
+ − 1339
+ − 1340
section {* Alpha-Equivalence and Free Atoms\label{sec:alpha} *}
+ − 1341
+ − 1342
text {*
+ − 1343
Having dealt with all syntax matters, the problem now is how we can turn
+ − 1344
specifications into actual type definitions in Isabelle/HOL and then
3006
+ − 1345
establish a reasoning infrastructure for them. As Pottier and Cheney pointed
+ − 1346
out \cite{Cheney05,Pottier06}, just re-arranging the arguments of
+ − 1347
term-constructors so that binders and their bodies are next to each other
+ − 1348
will result in inadequate representations in cases like \mbox{@{text "Let
+ − 1349
x\<^isub>1 = t\<^isub>1\<dots>x\<^isub>n = t\<^isub>n in s"}}. Therefore we will
3023
+ − 1350
first extract `raw' datatype definitions from the specification and then
3006
+ − 1351
define explicitly an alpha-equivalence relation over them. We subsequently
2989
+ − 1352
construct the quotient of the datatypes according to our alpha-equivalence.
2985
+ − 1353
3006
+ − 1354
3023
+ − 1355
The `raw' datatype definition can be obtained by stripping off the
3025
+ − 1356
binding clauses and the labels from the types given by the user. We also have to invent
+ − 1357
new names for the types @{text "ty\<^sup>\<alpha>"} and the term-constructors @{text "C\<^sup>\<alpha>"}.
+ − 1358
In our implementation we just use the affix ``@{text "_raw"}''.
2985
+ − 1359
But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate
2989
+ − 1360
that a notion is given for alpha-equivalence classes and leave it out
3025
+ − 1361
for the corresponding notion given on the raw level. So for example
3022
+ − 1362
we have @{text "ty\<^sup>\<alpha> / ty"} and @{text "C\<^sup>\<alpha> / C"}
2985
+ − 1363
where @{term ty} is the type used in the quotient construction for
3025
+ − 1364
@{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor of the raw type @{text "ty"},
3021
+ − 1365
respectively @{text "C\<^sup>\<alpha>"} is the corresponding term-constructor of @{text "ty\<^sup>\<alpha>"}.
2985
+ − 1366
+ − 1367
The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are
+ − 1368
non-empty and the types in the constructors only occur in positive
+ − 1369
position (see \cite{Berghofer99} for an in-depth description of the datatype package
+ − 1370
in Isabelle/HOL).
+ − 1371
We subsequently define each of the user-specified binding
+ − 1372
functions @{term "bn"}$_{1..m}$ by recursion over the corresponding
3025
+ − 1373
raw datatype. We also define permutation operations by
2985
+ − 1374
recursion so that for each term constructor @{text "C"} we have that
3006
+ − 1375
2985
+ − 1376
\begin{equation}\label{ceqvt}
3006
+ − 1377
@{text "\<pi> \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (\<pi> \<bullet> z\<^isub>1) \<dots> (\<pi> \<bullet> z\<^isub>n)"}
+ − 1378
\end{equation}\smallskip
2985
+ − 1379
3013
+ − 1380
\noindent
3021
+ − 1381
We will need this operation later when we define the notion of alpha-equivalence.
3013
+ − 1382
2985
+ − 1383
The first non-trivial step we have to perform is the generation of
3011
+ − 1384
\emph{free-atom functions} from the specifications.\footnote{Admittedly, the
3008
+ − 1385
details of our definitions will be somewhat involved. However they are still
3023
+ − 1386
conceptually simple in comparison with the `positional' approach taken in
3014
+ − 1387
Ott \cite[Pages 88--95]{ott-jfp}, which uses the notions of \emph{occurrences} and
+ − 1388
\emph{partial equivalence relations} over sets of occurrences.} For the
2985
+ − 1389
\emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions
3006
+ − 1390
2985
+ − 1391
\begin{equation}\label{fvars}
+ − 1392
\mbox{@{text "fa_ty"}$_{1..n}$}
3006
+ − 1393
\end{equation}\smallskip
2985
+ − 1394
+ − 1395
\noindent
+ − 1396
by recursion.
+ − 1397
We define these functions together with auxiliary free-atom functions for
+ − 1398
the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$
+ − 1399
we define
+ − 1400
3006
+ − 1401
\[
+ − 1402
@{text "fa_bn"}\mbox{$_{1..m}$}.
+ − 1403
\]\smallskip
2985
+ − 1404
+ − 1405
\noindent
+ − 1406
The reason for this setup is that in a deep binder not all atoms have to be
3023
+ − 1407
bound, as we saw in \eqref{letrecs} with the example of `plain' @{text Let}s. We need
3013
+ − 1408
therefore functions that calculate those free atoms in deep binders.
2985
+ − 1409
3013
+ − 1410
While the idea behind these free-atom functions is simple (they just
2985
+ − 1411
collect all atoms that are not bound), because of our rather complicated
+ − 1412
binding mechanisms their definitions are somewhat involved. Given
3025
+ − 1413
a raw term-constructor @{text "C"} of type @{text ty} and some associated
2985
+ − 1414
binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
+ − 1415
"fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
+ − 1416
"fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we will define below what @{text "fa"} for a binding
3004
+ − 1417
clause means. We only show the details for the mode \isacommand{binds (set)} (the other modes are similar).
3160
+ − 1418
Suppose a binding clause @{text bc\<^isub>i} is of the form
2985
+ − 1419
3006
+ − 1420
\[
3004
+ − 1421
\mbox{\isacommand{binds (set)} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
3006
+ − 1422
\]\smallskip
2985
+ − 1423
+ − 1424
\noindent
3006
+ − 1425
in which the body-labels @{text "d"}$_{1..q}$ refer to types @{text
+ − 1426
ty}$_{1..q}$, and the binders @{text b}$_{1..p}$ either refer to labels of
+ − 1427
atom types (in case of shallow binders) or to binding functions taking a
+ − 1428
single label as argument (in case of deep binders). Assuming @{text "D"}
+ − 1429
stands for the set of free atoms of the bodies, @{text B} for the set of
+ − 1430
binding atoms in the binders and @{text "B'"} for the set of free atoms in
+ − 1431
non-recursive deep binders, then the free atoms of the binding clause @{text
+ − 1432
bc\<^isub>i} are
+ − 1433
2985
+ − 1434
\begin{equation}\label{fadef}
+ − 1435
\mbox{@{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}}.
3006
+ − 1436
\end{equation}\smallskip
+ − 1437
2985
+ − 1438
\noindent
+ − 1439
The set @{text D} is formally defined as
+ − 1440
3006
+ − 1441
\[
2985
+ − 1442
@{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"}
3006
+ − 1443
\]\smallskip
2985
+ − 1444
+ − 1445
\noindent
+ − 1446
where in case @{text "d\<^isub>i"} refers to one of the raw types @{text "ty"}$_{1..n}$ from the
+ − 1447
specification, the function @{text "fa_ty\<^isub>i"} is the corresponding free-atom function
3021
+ − 1448
we are defining by recursion; otherwise we set \mbox{@{text "fa_ty\<^isub>i \<equiv> supp"}}. The reason
3008
+ − 1449
for the latter is that @{text "ty"}$_i$ is not a type that is part of the specification, and
3021
+ − 1450
we assume @{text supp} is the generic function that characterises the free variables of
3006
+ − 1451
a type (in fact in the next section we will show that the free-variable functions we
+ − 1452
define here, are equal to the support once lifted to alpha-equivalence classes).
2985
+ − 1453
+ − 1454
In order to formally define the set @{text B} we use the following auxiliary @{text "bn"}-functions
+ − 1455
for atom types to which shallow binders may refer\\[-4mm]
+ − 1456
3008
+ − 1457
\begin{equation}\label{bnaux}\mbox{
2985
+ − 1458
\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
3006
+ − 1459
@{text "bn\<^bsub>atom\<^esup> a"} & @{text "\<equiv>"} & @{text "{atom a}"}\\
+ − 1460
@{text "bn\<^bsub>atom_set\<^esup> as"} & @{text "\<equiv>"} & @{text "atoms as"}\\
+ − 1461
@{text "bn\<^bsub>atom_list\<^esub> as"} & @{text "\<equiv>"} & @{text "atoms (set as)"}
+ − 1462
\end{tabular}}
3008
+ − 1463
\end{equation}\smallskip
2985
+ − 1464
+ − 1465
\noindent
+ − 1466
Like the function @{text atom}, the function @{text "atoms"} coerces
+ − 1467
a set of atoms to a set of the generic atom type.
+ − 1468
It is defined as @{text "atoms as \<equiv> {atom a | a \<in> as}"}.
3008
+ − 1469
The set @{text B} in \eqref{fadef} is then formally defined as
3006
+ − 1470
+ − 1471
\begin{equation}\label{bdef}
2985
+ − 1472
@{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"}
3006
+ − 1473
\end{equation}\smallskip
+ − 1474
2985
+ − 1475
\noindent
3008
+ − 1476
where we use the auxiliary binding functions from \eqref{bnaux} for shallow
+ − 1477
binders (that means when @{text "ty"}$_i$ is of type @{text "atom"}, @{text "atom set"} or
3013
+ − 1478
@{text "atom list"}).
+ − 1479
+ − 1480
The set @{text "B'"} in \eqref{fadef} collects all free atoms in
3006
+ − 1481
non-recursive deep binders. Let us assume these binders in the binding
+ − 1482
clause @{text "bc\<^isub>i"} are
+ − 1483
+ − 1484
\[
2985
+ − 1485
\mbox{@{text "bn\<^isub>1 l\<^isub>1, \<dots>, bn\<^isub>r l\<^isub>r"}}
3006
+ − 1486
\]\smallskip
2985
+ − 1487
+ − 1488
\noindent
3008
+ − 1489
with @{text "l"}$_{1..r}$ $\subseteq$ @{text "b"}$_{1..p}$ and
+ − 1490
none of the @{text "l"}$_{1..r}$ being among the bodies
3006
+ − 1491
@{text "d"}$_{1..q}$. The set @{text "B'"} is defined as
+ − 1492
+ − 1493
\begin{equation}\label{bprimedef}
+ − 1494
@{text "B' \<equiv> fa_bn\<^isub>1 l\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r l\<^isub>r"}
+ − 1495
\end{equation}\smallskip
+ − 1496
2985
+ − 1497
\noindent
3008
+ − 1498
This completes all clauses for the free-atom functions @{text "fa_ty"}$_{1..n}$.
2985
+ − 1499
+ − 1500
Note that for non-recursive deep binders, we have to add in \eqref{fadef}
+ − 1501
the set of atoms that are left unbound by the binding functions @{text
3008
+ − 1502
"bn"}$_{1..m}$. We used for
3006
+ − 1503
the definition of this set the functions @{text "fa_bn"}$_{1..m}$. The
+ − 1504
definition for those functions needs to be extracted from the clauses the
+ − 1505
user provided for @{text "bn"}$_{1..m}$ Assume the user specified a @{text
+ − 1506
bn}-clause of the form
2985
+ − 1507
3006
+ − 1508
\[
2985
+ − 1509
@{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"}
3006
+ − 1510
\]\smallskip
2985
+ − 1511
+ − 1512
\noindent
3006
+ − 1513
where the @{text "z"}$_{1..s}$ are of types @{text "ty"}$_{1..s}$. For
+ − 1514
each of the arguments we calculate the free atoms as follows:
2985
+ − 1515
3006
+ − 1516
\[\mbox{
2985
+ − 1517
\begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
3006
+ − 1518
$\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"}\\
+ − 1519
& (that means nothing is bound in @{text "z\<^isub>i"} by the binding function),\smallskip\\
2985
+ − 1520
$\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"}
3008
+ − 1521
with the recursive call @{text "bn\<^isub>i z\<^isub>i"}\\
3023
+ − 1522
& (that means whatever is `left over' from the @{text "bn"}-function is free)\smallskip\\
2985
+ − 1523
$\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"},
3006
+ − 1524
but without a recursive call\\
+ − 1525
& (that means @{text "z\<^isub>i"} is supposed to become bound by the binding function)\\
+ − 1526
\end{tabular}}
+ − 1527
\]\smallskip
2985
+ − 1528
+ − 1529
\noindent
+ − 1530
For defining @{text "fa_bn (C z\<^isub>1 \<dots> z\<^isub>n)"} we just union up all these sets.
+ − 1531
+ − 1532
To see how these definitions work in practice, let us reconsider the
+ − 1533
term-constructors @{text "Let"} and @{text "Let_rec"} shown in
+ − 1534
\eqref{letrecs} together with the term-constructors for assignments @{text
+ − 1535
"ANil"} and @{text "ACons"}. Since there is a binding function defined for
+ − 1536
assignments, we have three free-atom functions, namely @{text
+ − 1537
"fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text
+ − 1538
"fa\<^bsub>bn\<^esub>"} as follows:
3006
+ − 1539
+ − 1540
\[\mbox{
2985
+ − 1541
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
3009
+ − 1542
@{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "\<equiv>"} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\
+ − 1543
@{text "fa\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "\<equiv>"} & @{text "(fa\<^bsub>assn\<^esub> as \<union> fa\<^bsub>trm\<^esub> t) - set (bn as)"}\smallskip\\
2985
+ − 1544
3009
+ − 1545
@{text "fa\<^bsub>assn\<^esub> (ANil)"} & @{text "\<equiv>"} & @{term "{}"}\\
+ − 1546
@{text "fa\<^bsub>assn\<^esub> (ACons a t as)"} & @{text "\<equiv>"} & @{text "(supp a) \<union> (fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>assn\<^esub> as)"}\smallskip\\
2985
+ − 1547
3009
+ − 1548
@{text "fa\<^bsub>bn\<^esub> (ANil)"} & @{text "\<equiv>"} & @{term "{}"}\\
+ − 1549
@{text "fa\<^bsub>bn\<^esub> (ACons a t as)"} & @{text "\<equiv>"} & @{text "(fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>bn\<^esub> as)"}
3006
+ − 1550
\end{tabular}}
+ − 1551
\]\smallskip
+ − 1552
2985
+ − 1553
+ − 1554
\noindent
3006
+ − 1555
Recall that @{text ANil} and @{text "ACons"} have no binding clause in the
+ − 1556
specification. The corresponding free-atom function @{text
+ − 1557
"fa\<^bsub>assn\<^esub>"} therefore returns all free atoms of an assignment
+ − 1558
(in case of @{text "ACons"}, they are given in terms of @{text supp}, @{text
+ − 1559
"fa\<^bsub>trm\<^esub>"} and @{text "fa\<^bsub>assn\<^esub>"}). The binding
+ − 1560
only takes place in @{text Let} and @{text "Let_rec"}. In case of @{text
+ − 1561
"Let"}, the binding clause specifies that all atoms given by @{text "set (bn
+ − 1562
as)"} have to be bound in @{text t}. Therefore we have to subtract @{text
+ − 1563
"set (bn as)"} from @{text "fa\<^bsub>trm\<^esub> t"}. However, we also need
+ − 1564
to add all atoms that are free in @{text "as"}. This is in contrast with
+ − 1565
@{text "Let_rec"} where we have a recursive binder to bind all occurrences
+ − 1566
of the atoms in @{text "set (bn as)"} also inside @{text "as"}. Therefore we
+ − 1567
have to subtract @{text "set (bn as)"} from both @{text
+ − 1568
"fa\<^bsub>trm\<^esub> t"} and @{text "fa\<^bsub>assn\<^esub> as"}. Like the
+ − 1569
function @{text "bn"}, the function @{text "fa\<^bsub>bn\<^esub>"} traverses
+ − 1570
the list of assignments, but instead returns the free atoms, which means in
+ − 1571
this example the free atoms in the argument @{text "t"}.
2985
+ − 1572
+ − 1573
3023
+ − 1574
An interesting point in this example is that a `naked' assignment (@{text
3006
+ − 1575
"ANil"} or @{text "ACons"}) does not bind any atoms, even if the binding
+ − 1576
function is specified over assignments. Only in the context of a @{text Let}
+ − 1577
or @{text "Let_rec"}, where the binding clauses are given, will some atoms
+ − 1578
actually become bound. This is a phenomenon that has also been pointed out
+ − 1579
in \cite{ott-jfp}. For us this observation is crucial, because we would not
+ − 1580
be able to lift the @{text "bn"}-functions to alpha-equated terms if they
+ − 1581
act on atoms that are bound. In that case, these functions would \emph{not}
+ − 1582
respect alpha-equivalence.
+ − 1583
3023
+ − 1584
Having the free-atom functions at our disposal, we can next define the
3006
+ − 1585
alpha-equivalence relations for the raw types @{text
+ − 1586
"ty"}$_{1..n}$. We write them as
2985
+ − 1587
3006
+ − 1588
\[
+ − 1589
\mbox{@{text "\<approx>ty"}$_{1..n}$}.
+ − 1590
\]\smallskip
2985
+ − 1591
+ − 1592
\noindent
+ − 1593
Like with the free-atom functions, we also need to
2989
+ − 1594
define auxiliary alpha-equivalence relations
2985
+ − 1595
3006
+ − 1596
\[
+ − 1597
\mbox{@{text "\<approx>bn\<^isub>"}$_{1..m}$}
+ − 1598
\]\smallskip
2985
+ − 1599
+ − 1600
\noindent
+ − 1601
for the binding functions @{text "bn"}$_{1..m}$,
+ − 1602
To simplify our definitions we will use the following abbreviations for
+ − 1603
\emph{compound equivalence relations} and \emph{compound free-atom functions} acting on tuples.
+ − 1604
3006
+ − 1605
\[\mbox{
2985
+ − 1606
\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
3006
+ − 1607
@{text "(x\<^isub>1,\<dots>, x\<^isub>n) (R\<^isub>1,\<dots>, R\<^isub>n) (y\<^isub>1,\<dots>, y\<^isub>n)"} & @{text "\<equiv>"} &
+ − 1608
@{text "x\<^isub>1 R\<^isub>1 y\<^isub>1 \<and> \<dots> \<and> x\<^isub>n R\<^isub>n y\<^isub>n"}\\
2985
+ − 1609
@{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"}\\
3006
+ − 1610
\end{tabular}}
+ − 1611
\]\smallskip
2985
+ − 1612
+ − 1613
2989
+ − 1614
The alpha-equivalence relations are defined as inductive predicates
2985
+ − 1615
having a single clause for each term-constructor. Assuming a
+ − 1616
term-constructor @{text C} is of type @{text ty} and has the binding clauses
2989
+ − 1617
@{term "bc"}$_{1..k}$, then the alpha-equivalence clause has the form
2985
+ − 1618
3160
+ − 1619
\begin{equation}\label{gform}
2985
+ − 1620
\mbox{\infer{@{text "C z\<^isub>1 \<dots> z\<^isub>n \<approx>ty C z\<PRIME>\<^isub>1 \<dots> z\<PRIME>\<^isub>n"}}
+ − 1621
{@{text "prems(bc\<^isub>1) \<dots> prems(bc\<^isub>k)"}}}
3160
+ − 1622
\end{equation}\smallskip
2985
+ − 1623
+ − 1624
\noindent
3006
+ − 1625
The task below is to specify what the premises corresponding to a binding
3010
+ − 1626
clause are. To understand better what the general pattern is, let us first
3006
+ − 1627
treat the special instance where @{text "bc\<^isub>i"} is the empty binding clause
+ − 1628
of the form
+ − 1629
+ − 1630
\[
3004
+ − 1631
\mbox{\isacommand{binds (set)} @{term "{}"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.}
3006
+ − 1632
\]\smallskip
2985
+ − 1633
+ − 1634
\noindent
3010
+ − 1635
In this binding clause no atom is bound and we only have to `alpha-relate'
+ − 1636
the bodies. For this we build first the tuples @{text "D \<equiv> (d\<^isub>1,\<dots>,
+ − 1637
d\<^isub>q)"} and @{text "D' \<equiv> (d\<PRIME>\<^isub>1,\<dots>, d\<PRIME>\<^isub>q)"}
3034
+ − 1638
whereby the labels @{text "d"}$_{1..q}$ refer to some of the arguments @{text
3160
+ − 1639
"z"}$_{1..n}$ and respectively @{text "d\<PRIME>"}$_{1..q}$ to some of the @{text
+ − 1640
"z\<PRIME>"}$_{1..n}$ in \eqref{gform}. In order to relate two such
3010
+ − 1641
tuples we define the compound alpha-equivalence relation @{text "R"} as
+ − 1642
follows
+ − 1643
2985
+ − 1644
\begin{equation}\label{rempty}
+ − 1645
\mbox{@{text "R \<equiv> (R\<^isub>1,\<dots>, R\<^isub>q)"}}
3010
+ − 1646
\end{equation}\smallskip
2985
+ − 1647
+ − 1648
\noindent
3010
+ − 1649
with @{text "R\<^isub>i"} being @{text "\<approx>ty\<^isub>i"} if the corresponding
+ − 1650
labels @{text "d\<^isub>i"} and @{text "d\<PRIME>\<^isub>i"} refer to a
3034
+ − 1651
recursive argument of @{text C} and have type @{text "ty\<^isub>i"}; otherwise
3010
+ − 1652
we take @{text "R\<^isub>i"} to be the equality @{text "="}. Again the
3160
+ − 1653
latter is because @{text "ty\<^isub>i"} is then not part of the specified types
3010
+ − 1654
and alpha-equivalence of any previously defined type is supposed to coincide
+ − 1655
with equality. This lets us now define the premise for an empty binding
+ − 1656
clause succinctly as @{text "prems(bc\<^isub>i) \<equiv> D R D'"}, which can be
+ − 1657
unfolded to the series of premises
2985
+ − 1658
3010
+ − 1659
\[
2985
+ − 1660
@{text "d\<^isub>1 R\<^isub>1 d\<PRIME>\<^isub>1 \<dots> d\<^isub>q R\<^isub>q d\<PRIME>\<^isub>q"}.
3010
+ − 1661
\]\smallskip
2985
+ − 1662
+ − 1663
\noindent
+ − 1664
We will use the unfolded version in the examples below.
+ − 1665
+ − 1666
Now suppose the binding clause @{text "bc\<^isub>i"} is of the general form
+ − 1667
+ − 1668
\begin{equation}\label{nonempty}
3004
+ − 1669
\mbox{\isacommand{binds (set)} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}.}
3010
+ − 1670
\end{equation}\smallskip
2985
+ − 1671
+ − 1672
\noindent
+ − 1673
In this case we define a premise @{text P} using the relation
3011
+ − 1674
$\approx_{\,\textit{set}}^{\textit{R}, \textit{fa}}$ given in Section~\ref{sec:binders} (similarly
+ − 1675
$\approx_{\,\textit{set+}}^{\textit{R}, \textit{fa}}$ and
+ − 1676
$\approx_{\,\textit{list}}^{\textit{R}, \textit{fa}}$ for the other
3021
+ − 1677
binding modes). As above, we first build the tuples @{text "D"} and
2985
+ − 1678
@{text "D'"} for the bodies @{text "d"}$_{1..q}$, and the corresponding
2989
+ − 1679
compound alpha-relation @{text "R"} (shown in \eqref{rempty}).
3013
+ − 1680
For $\approx_{\,\textit{set}}^{\textit{R}, \textit{fa}}$ we also need
2985
+ − 1681
a compound free-atom function for the bodies defined as
+ − 1682
3010
+ − 1683
\[
2985
+ − 1684
\mbox{@{text "fa \<equiv> (fa_ty\<^isub>1,\<dots>, fa_ty\<^isub>q)"}}
3010
+ − 1685
\]\smallskip
2985
+ − 1686
+ − 1687
\noindent
+ − 1688
with the assumption that the @{text "d"}$_{1..q}$ refer to arguments of types @{text "ty"}$_{1..q}$.
+ − 1689
The last ingredient we need are the sets of atoms bound in the bodies.
+ − 1690
For this we take
+ − 1691
3010
+ − 1692
\[
2985
+ − 1693
@{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> \<dots> \<union> bn_ty\<^isub>p b\<^isub>p"}\;.\\
3010
+ − 1694
\]\smallskip
2985
+ − 1695
+ − 1696
\noindent
+ − 1697
Similarly for @{text "B'"} using the labels @{text "b\<PRIME>"}$_{1..p}$. This
+ − 1698
lets us formally define the premise @{text P} for a non-empty binding clause as:
+ − 1699
3010
+ − 1700
\[
3006
+ − 1701
\mbox{@{term "P \<equiv> alpha_set_ex (B, D) R fa (B', D')"}}\;.
3010
+ − 1702
\]\smallskip
2985
+ − 1703
+ − 1704
\noindent
2989
+ − 1705
This premise accounts for alpha-equivalence of the bodies of the binding
3010
+ − 1706
clause. However, in case the binders have non-recursive deep binders, this
3023
+ − 1707
premise is not enough: we also have to `propagate' alpha-equivalence
3010
+ − 1708
inside the structure of these binders. An example is @{text "Let"} where we
+ − 1709
have to make sure the right-hand sides of assignments are
+ − 1710
alpha-equivalent. For this we use relations @{text "\<approx>bn"}$_{1..m}$ (which we
3021
+ − 1711
will define shortly). Let us assume the non-recursive deep binders
3010
+ − 1712
in @{text "bc\<^isub>i"} are
2985
+ − 1713
3010
+ − 1714
\[
2985
+ − 1715
@{text "bn\<^isub>1 l\<^isub>1, \<dots>, bn\<^isub>r l\<^isub>r"}.
3010
+ − 1716
\]\smallskip
2985
+ − 1717
+ − 1718
\noindent
3010
+ − 1719
The tuple @{text L} consists then of all these binders @{text "(l\<^isub>1,\<dots>,l\<^isub>r)"}
+ − 1720
(similarly @{text "L'"}) and the compound equivalence relation @{text "R'"}
+ − 1721
is @{text "(\<approx>bn\<^isub>1,\<dots>,\<approx>bn\<^isub>r)"}. All premises for @{text "bc\<^isub>i"} are then given by
2985
+ − 1722
3010
+ − 1723
\[
2985
+ − 1724
@{text "prems(bc\<^isub>i) \<equiv> P \<and> L R' L'"}
3010
+ − 1725
\]\smallskip
2985
+ − 1726
+ − 1727
\noindent
2989
+ − 1728
The auxiliary alpha-equivalence relations @{text "\<approx>bn"}$_{1..m}$
2985
+ − 1729
in @{text "R'"} are defined as follows: assuming a @{text bn}-clause is of the form
+ − 1730
3010
+ − 1731
\[
2985
+ − 1732
@{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"}
3010
+ − 1733
\]\smallskip
2985
+ − 1734
+ − 1735
\noindent
+ − 1736
where the @{text "z"}$_{1..s}$ are of types @{text "ty"}$_{1..s}$,
2989
+ − 1737
then the corresponding alpha-equivalence clause for @{text "\<approx>bn"} has the form
2985
+ − 1738
3010
+ − 1739
\[
2985
+ − 1740
\mbox{\infer{@{text "C z\<^isub>1 \<dots> z\<^isub>s \<approx>bn C z\<PRIME>\<^isub>1 \<dots> z\<PRIME>\<^isub>s"}}
+ − 1741
{@{text "z\<^isub>1 R\<^isub>1 z\<PRIME>\<^isub>1 \<dots> z\<^isub>s R\<^isub>s z\<PRIME>\<^isub>s"}}}
3010
+ − 1742
\]\smallskip
2985
+ − 1743
+ − 1744
\noindent
+ − 1745
In this clause the relations @{text "R"}$_{1..s}$ are given by
+ − 1746
3010
+ − 1747
\[\mbox{
2985
+ − 1748
\begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
+ − 1749
$\bullet$ & @{text "z\<^isub>i \<approx>ty z\<PRIME>\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text rhs} and
3010
+ − 1750
is a recursive argument of @{text C},\smallskip\\
2985
+ − 1751
$\bullet$ & @{text "z\<^isub>i = z\<PRIME>\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text rhs}
3010
+ − 1752
and is a non-recursive argument of @{text C},\smallskip\\
2985
+ − 1753
$\bullet$ & @{text "z\<^isub>i \<approx>bn\<^isub>i z\<PRIME>\<^isub>i"} provided @{text "z\<^isub>i"} occurs in @{text rhs}
3010
+ − 1754
with the recursive call @{text "bn\<^isub>i x\<^isub>i"} and\smallskip\\
2985
+ − 1755
$\bullet$ & @{text True} provided @{text "z\<^isub>i"} occurs in @{text rhs} but without a
+ − 1756
recursive call.
3010
+ − 1757
\end{tabular}}
+ − 1758
\]\smallskip
2985
+ − 1759
+ − 1760
\noindent
2989
+ − 1761
This completes the definition of alpha-equivalence. As a sanity check, we can show
2985
+ − 1762
that the premises of empty binding clauses are a special case of the clauses for
3011
+ − 1763
non-empty ones (we just have to unfold the definition of
+ − 1764
$\approx_{\,\textit{set}}^{\textit{R}, \textit{fa}}$ and take @{text "0"}
2985
+ − 1765
for the existentially quantified permutation).
+ − 1766
3011
+ − 1767
Again let us take a look at a concrete example for these definitions. For
3021
+ − 1768
the specification shown in \eqref{letrecs}
2985
+ − 1769
we have three relations $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and
3017
+ − 1770
$\approx_{\textit{bn}}$ with the following rules:
2985
+ − 1771
3016
+ − 1772
\begin{equation}\label{rawalpha}\mbox{
2985
+ − 1773
\begin{tabular}{@ {}c @ {}}
+ − 1774
\infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}}
3010
+ − 1775
{@{term "alpha_lst_ex (bn as, t) alpha_trm fa_trm (bn as', t')"} &
+ − 1776
\hspace{5mm}@{text "as \<approx>\<^bsub>bn\<^esub> as'"}}\\
+ − 1777
\\
2985
+ − 1778
\makebox[0mm]{\infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}}
3010
+ − 1779
{@{term "alpha_lst_ex (bn as, ast) alpha_trm2 fa_trm2 (bn as', ast')"}}}\\
+ − 1780
\\
2985
+ − 1781
+ − 1782
\begin{tabular}{@ {}c @ {}}
+ − 1783
\infer{@{text "ANil \<approx>\<^bsub>assn\<^esub> ANil"}}{}\hspace{9mm}
+ − 1784
\infer{@{text "ACons a t as \<approx>\<^bsub>assn\<^esub> ACons a' t' as"}}
3010
+ − 1785
{@{text "a = a'"} & \hspace{5mm}@{text "t \<approx>\<^bsub>trm\<^esub> t'"} & \hspace{5mm}@{text "as \<approx>\<^bsub>assn\<^esub> as'"}}
+ − 1786
\end{tabular}\\
+ − 1787
\\
2985
+ − 1788
+ − 1789
\begin{tabular}{@ {}c @ {}}
+ − 1790
\infer{@{text "ANil \<approx>\<^bsub>bn\<^esub> ANil"}}{}\hspace{9mm}
+ − 1791
\infer{@{text "ACons a t as \<approx>\<^bsub>bn\<^esub> ACons a' t' as"}}
3010
+ − 1792
{@{text "t \<approx>\<^bsub>trm\<^esub> t'"} & \hspace{5mm}@{text "as \<approx>\<^bsub>bn\<^esub> as'"}}
2985
+ − 1793
\end{tabular}
3010
+ − 1794
\end{tabular}}
3016
+ − 1795
\end{equation}\smallskip
2985
+ − 1796
+ − 1797
\noindent
3011
+ − 1798
Notice the difference between $\approx_{\textit{assn}}$ and
3023
+ − 1799
$\approx_{\textit{bn}}$: the latter only `tracks' alpha-equivalence of
2985
+ − 1800
the components in an assignment that are \emph{not} bound. This is needed in the
+ − 1801
clause for @{text "Let"} (which has
+ − 1802
a non-recursive binder).
+ − 1803
The underlying reason is that the terms inside an assignment are not meant
3023
+ − 1804
to be `under' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"},
+ − 1805
because there all components of an assignment are `under' the binder.
3021
+ − 1806
Note also that in case of more than one body (that is in the @{text "Let_rec"}-case above)
3013
+ − 1807
we need to parametrise the relation $\approx_{\textit{list}}$ with a compound
+ − 1808
equivalence relation and a compound free-atom function. This is because the
3017
+ − 1809
corresponding binding clause specifies a binder with two bodies, namely
+ − 1810
@{text "as"} and @{text "t"}.
2985
+ − 1811
*}
+ − 1812
+ − 1813
section {* Establishing the Reasoning Infrastructure *}
+ − 1814
+ − 1815
text {*
3010
+ − 1816
Having made all necessary definitions for raw terms, we can start with
+ − 1817
establishing the reasoning infrastructure for the alpha-equated types @{text
+ − 1818
"ty\<AL>"}$_{1..n}$, that is the types the user originally specified. We
+ − 1819
give in this section and the next the proofs we need for establishing this
3012
+ − 1820
infrastructure. One point of our work is that we have completely
3010
+ − 1821
automated these proofs in Isabelle/HOL.
+ − 1822
+ − 1823
First we establish that the free-variable functions, the binding functions and the
3012
+ − 1824
alpha-equi\-va\-lences are equivariant.
2985
+ − 1825
3010
+ − 1826
\begin{lem}\mbox{}\\
+ − 1827
@{text "(i)"} The functions @{text "fa_ty"}$_{1..n}$, @{text "fa_bn"}$_{1..m}$ and
+ − 1828
@{text "bn"}$_{1..m}$ are equivariant.\\
+ − 1829
@{text "(ii)"} The relations @{text "\<approx>ty"}$_{1..n}$ and
+ − 1830
@{text "\<approx>bn"}$_{1..m}$ are equivariant.
+ − 1831
\end{lem}
+ − 1832
+ − 1833
\begin{proof}
3015
+ − 1834
The function package of Isabelle/HOL allows us to prove the first part by
+ − 1835
mutual induction over the definitions of the functions.\footnote{We have
3023
+ − 1836
that the free-atom functions are terminating. From this the function
3025
+ − 1837
package derives an induction principle~\cite{Krauss09}.} The second is by a
3015
+ − 1838
straightforward induction over the rules of @{text "\<approx>ty"}$_{1..n}$ and
+ − 1839
@{text "\<approx>bn"}$_{1..m}$ using the first part.
3010
+ − 1840
\end{proof}
+ − 1841
+ − 1842
\noindent
+ − 1843
Next we establish that the alpha-equivalence relations defined in the
3012
+ − 1844
previous section are indeed equivalence relations.
2985
+ − 1845
2989
+ − 1846
\begin{lem}\label{equiv}
3010
+ − 1847
The relations @{text "\<approx>ty"}$_{1..n}$ and @{text "\<approx>bn"}$_{1..m}$ are
+ − 1848
equivalence relations.
2989
+ − 1849
\end{lem}
2985
+ − 1850
+ − 1851
\begin{proof}
3017
+ − 1852
The proofs are by induction. The non-trivial
2985
+ − 1853
cases involve premises built up by $\approx_{\textit{set}}$,
+ − 1854
$\approx_{\textit{set+}}$ and $\approx_{\textit{list}}$. They
3010
+ − 1855
can be dealt with as in Lemma~\ref{alphaeq}. However, the transitivity
+ − 1856
case needs in addition the fact that the relations are equivariant.
2985
+ − 1857
\end{proof}
+ − 1858
+ − 1859
\noindent
3012
+ − 1860
We can feed the last lemma into our quotient package and obtain new types
+ − 1861
@{text "ty"}$^\alpha_{1..n}$ representing alpha-equated terms of types
+ − 1862
@{text "ty"}$_{1..n}$. We also obtain definitions for the term-constructors
3025
+ − 1863
@{text "C"}$^\alpha_{1..k}$ from the raw term-constructors @{text
3012
+ − 1864
"C"}$_{1..k}$, and similar definitions for the free-atom functions @{text
3010
+ − 1865
"fa_ty"}$^\alpha_{1..n}$ and @{text "fa_bn"}$^\alpha_{1..m}$ as well as the
3012
+ − 1866
binding functions @{text "bn"}$^\alpha_{1..m}$. However, these definitions
+ − 1867
are not really useful to the user, since they are given in terms of the
+ − 1868
isomorphisms we obtained by creating new types in Isabelle/HOL (recall the
+ − 1869
picture shown in the Introduction).
2985
+ − 1870
+ − 1871
The first useful property for the user is the fact that distinct
3012
+ − 1872
term-constructors are not equal, that is the property
2985
+ − 1873
3012
+ − 1874
\begin{equation}\label{distinctalpha}
2985
+ − 1875
\mbox{@{text "C"}$^\alpha$~@{text "x\<^isub>1 \<dots> x\<^isub>r"}~@{text "\<noteq>"}~%
+ − 1876
@{text "D"}$^\alpha$~@{text "y\<^isub>1 \<dots> y\<^isub>s"}}
3012
+ − 1877
\end{equation}\smallskip
2985
+ − 1878
+ − 1879
\noindent
+ − 1880
whenever @{text "C"}$^\alpha$~@{text "\<noteq>"}~@{text "D"}$^\alpha$.
3012
+ − 1881
In order to derive this property, we use the definition of alpha-equivalence
2985
+ − 1882
and establish that
+ − 1883
3012
+ − 1884
\begin{equation}\label{distinctraw}
2985
+ − 1885
\mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r"}\;$\not\approx$@{text ty}\;@{text "D y\<^isub>1 \<dots> y\<^isub>s"}}
3012
+ − 1886
\end{equation}\smallskip
2985
+ − 1887
+ − 1888
\noindent
3025
+ − 1889
holds for the corresponding raw term-constructors.
2985
+ − 1890
In order to deduce \eqref{distinctalpha} from \eqref{distinctraw}, our quotient
3025
+ − 1891
package needs to know that the raw term-constructors @{text "C"} and @{text "D"}
2989
+ − 1892
are \emph{respectful} w.r.t.~the alpha-equivalence relations (see \cite{Homeier05}).
3012
+ − 1893
Given, for example, @{text "C"} is of type @{text "ty"} with argument types
2985
+ − 1894
@{text "ty"}$_{1..r}$, respectfulness amounts to showing that
+ − 1895
3012
+ − 1896
\[\mbox{
2985
+ − 1897
@{text "C x\<^isub>1 \<dots> x\<^isub>r \<approx>ty C x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}
3012
+ − 1898
}\]\smallskip
2985
+ − 1899
+ − 1900
\noindent
3012
+ − 1901
holds under the assumptions \mbox{@{text
2985
+ − 1902
"x\<^isub>i \<approx>ty\<^isub>i x\<PRIME>\<^isub>i"}} whenever @{text "x\<^isub>i"}
3013
+ − 1903
and @{text "x\<PRIME>\<^isub>i"} are recursive arguments of @{text C}, and
3012
+ − 1904
@{text "x\<^isub>i = x\<PRIME>\<^isub>i"} whenever they are non-recursive arguments
+ − 1905
(similarly for @{text "D"}). For this we have to show
+ − 1906
by induction over the definitions of alpha-equivalences the following
+ − 1907
auxiliary implications
2985
+ − 1908
3012
+ − 1909
\begin{equation}\label{fnresp}\mbox{
+ − 1910
\begin{tabular}{lll}
+ − 1911
@{text "x \<approx>ty\<^isub>i x'"} & implies & @{text "fa_ty\<^isub>i x = fa_ty\<^isub>i x'"}\\
+ − 1912
@{text "x \<approx>ty\<^isub>l x'"} & implies & @{text "fa_bn\<^isub>j x = fa_bn\<^isub>j x'"}\\
+ − 1913
@{text "x \<approx>ty\<^isub>l x'"} & implies & @{text "bn\<^isub>j x = bn\<^isub>j x'"}\\
+ − 1914
@{text "x \<approx>ty\<^isub>l x'"} & implies & @{text "x \<approx>bn\<^isub>j x'"}\\
+ − 1915
\end{tabular}
+ − 1916
}\end{equation}\smallskip
+ − 1917
2985
+ − 1918
\noindent
3012
+ − 1919
whereby @{text "ty\<^isub>l"} is the type over which @{text "bn\<^isub>j"}
3013
+ − 1920
is defined. Whereas the first, second and last implication are true by
3012
+ − 1921
how we stated our definitions, the third \emph{only} holds because of our
+ − 1922
restriction imposed on the form of the binding functions---namely \emph{not}
3013
+ − 1923
to return any bound atoms. In Ott, in contrast, the user may define @{text
3012
+ − 1924
"bn"}$_{1..m}$ so that they return bound atoms and in this case the third
3013
+ − 1925
implication is \emph{not} true. A result is that in general the lifting of the
3012
+ − 1926
corresponding binding functions in Ott to alpha-equated terms is impossible.
3025
+ − 1927
Having established respectfulness for the raw term-constructors, the
2985
+ − 1928
quotient package is able to automatically deduce \eqref{distinctalpha} from
3017
+ − 1929
\eqref{distinctraw}.
+ − 1930
+ − 1931
Next we can lift the permutation operations defined in \eqref{ceqvt}. In
+ − 1932
order to make this lifting to go through, we have to show that the
+ − 1933
permutation operations are respectful. This amounts to showing that the
+ − 1934
alpha-equivalence relations are equivariant, which
+ − 1935
we already established in Lemma~\ref{equiv}. As a result we can add the
+ − 1936
equations
+ − 1937
+ − 1938
\begin{equation}\label{calphaeqvt}
+ − 1939
@{text "\<pi> \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r) = C\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) \<dots> (\<pi> \<bullet> x\<^isub>r)"}
+ − 1940
\end{equation}\smallskip
+ − 1941
+ − 1942
\noindent
+ − 1943
to our infrastructure. In a similar fashion we can lift the defining equations
+ − 1944
of the free-atom functions @{text "fa_ty\<AL>"}$_{1..n}$ and
+ − 1945
@{text "fa_bn\<AL>"}$_{1..m}$ as well as of the binding functions @{text
+ − 1946
"bn\<AL>"}$_{1..m}$ and size functions @{text "size_ty\<AL>"}$_{1..n}$.
3025
+ − 1947
The latter are defined automatically for the raw types @{text "ty"}$_{1..n}$
3017
+ − 1948
by the datatype package of Isabelle/HOL.
+ − 1949
3025
+ − 1950
We also need to lift the properties that characterise when two raw terms of the form
3010
+ − 1951
+ − 1952
\[
+ − 1953
\mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>r \<approx>ty C x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}}
+ − 1954
\]\smallskip
2985
+ − 1955
+ − 1956
\noindent
2989
+ − 1957
are alpha-equivalent. This gives us conditions when the corresponding
+ − 1958
alpha-equated terms are \emph{equal}, namely
2985
+ − 1959
3010
+ − 1960
\[
2985
+ − 1961
@{text "C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r = C\<^sup>\<alpha> x\<PRIME>\<^isub>1 \<dots> x\<PRIME>\<^isub>r"}.
3010
+ − 1962
\]\smallskip
2985
+ − 1963
+ − 1964
\noindent
3106
+ − 1965
We call these conditions \emph{quasi-injectivity}. They correspond to the
3021
+ − 1966
premises in our alpha-equiva\-lence relations, except that the
3017
+ − 1967
relations @{text "\<approx>ty"}$_{1..n}$ are all replaced by equality (and similarly
+ − 1968
the free-atom and binding functions are replaced by their lifted
+ − 1969
counterparts). Recall the alpha-equivalence rules for @{text "Let"} and
+ − 1970
@{text "Let_rec"} shown in \eqref{rawalpha}. For @{text "Let\<^sup>\<alpha>"} and
+ − 1971
@{text "Let_rec\<^sup>\<alpha>"} we have
3016
+ − 1972
+ − 1973
\begin{equation}\label{alphalift}\mbox{
+ − 1974
\begin{tabular}{@ {}c @ {}}
+ − 1975
\infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
+ − 1976
{@{term "alpha_lst_ex (bn_al as, t) equal fa_trm_al (bn as', t')"} &
+ − 1977
\hspace{5mm}@{text "as \<approx>\<AL>\<^bsub>bn\<^esub> as'"}}\\
+ − 1978
\\
+ − 1979
\makebox[0mm]{\infer{@{text "Let_rec\<^sup>\<alpha> as t = Let_rec\<^sup>\<alpha> as' t'"}}
+ − 1980
{@{term "alpha_lst_ex (bn_al as, ast) equ2 fa_trm2_al (bn_al as', ast')"}}}\\
+ − 1981
\end{tabular}}
+ − 1982
\end{equation}\smallskip
+ − 1983
3017
+ − 1984
We can also add to our infrastructure cases lemmas and a (mutual)
3012
+ − 1985
induction principle for the types @{text "ty\<AL>"}$_{1..n}$. The cases
3015
+ − 1986
lemmas allow the user to deduce a property @{text "P"} by exhaustively
3025
+ − 1987
analysing how an element of a type, say @{text "ty\<AL>"}$_i$, can be
3015
+ − 1988
constructed (that means one case for each of the term-constructors in @{text
3160
+ − 1989
"ty\<AL>"}$_i\,$). The lifted cases lemma for a type @{text
3015
+ − 1990
"ty\<AL>"}$_i\,$ looks as follows
3012
+ − 1991
3015
+ − 1992
\begin{equation}\label{cases}
3012
+ − 1993
\infer{P}
+ − 1994
{\begin{array}{l}
+ − 1995
@{text "\<forall>x\<^isub>1\<dots>x\<^isub>k. y = C\<AL>\<^isub>1 x\<^isub>1 \<dots> x\<^isub>k \<Rightarrow> P"}\\
3030
+ − 1996
\hspace{5mm}\vdots\\
3012
+ − 1997
@{text "\<forall>x\<^isub>1\<dots>x\<^isub>l. y = C\<AL>\<^isub>m x\<^isub>1 \<dots> x\<^isub>l \<Rightarrow> P"}\\
+ − 1998
\end{array}}
3015
+ − 1999
\end{equation}\smallskip
3012
+ − 2000
2985
+ − 2001
\noindent
3044
+ − 2002
where @{text "y"} is a variable of type @{text "ty\<AL>"}$_i$ and @{text "P"} is the
3013
+ − 2003
property that is established by the case analysis. Similarly, we have a (mutual)
+ − 2004
induction principle for the types @{text "ty\<AL>"}$_{1..n}$, which is of the
+ − 2005
form
3012
+ − 2006
3015
+ − 2007
\begin{equation}\label{induct}
3012
+ − 2008
\infer{@{text "P\<^isub>1 y\<^isub>1 \<and> \<dots> \<and> P\<^isub>n y\<^isub>n "}}
+ − 2009
{\begin{array}{l}
+ − 2010
@{text "\<forall>x\<^isub>1\<dots>x\<^isub>k. P\<^isub>i x\<^isub>i \<and> \<dots> \<and> P\<^isub>j x\<^isub>j \<Rightarrow> P (C\<AL>\<^isub>1 x\<^isub>1 \<dots> x\<^isub>k)"}\\
3030
+ − 2011
\hspace{5mm}\vdots\\
3012
+ − 2012
@{text "\<forall>x\<^isub>1\<dots>x\<^isub>l. P\<^isub>r x\<^isub>r \<and> \<dots> \<and> P\<^isub>s x\<^isub>s \<Rightarrow> P (C\<AL>\<^isub>m x\<^isub>1 \<dots> x\<^isub>l)"}\\
+ − 2013
\end{array}}
3015
+ − 2014
\end{equation}\smallskip
+ − 2015
+ − 2016
\noindent
3021
+ − 2017
whereby the @{text P}$_{1..n}$ are the properties established by the
+ − 2018
induction, and the @{text y}$_{1..n}$ are of type @{text
3106
+ − 2019
"ty\<AL>"}$_{1..n}$. Note that for the term constructor @{text
3021
+ − 2020
"C"}$^\alpha_1$ the induction principle has a hypothesis of the form
3015
+ − 2021
+ − 2022
\[
+ − 2023
\mbox{@{text "\<forall>x\<^isub>1\<dots>x\<^isub>k. P\<^isub>i x\<^isub>i \<and> \<dots> \<and> P\<^isub>j x\<^isub>j \<Rightarrow> P (C\<AL>\<^sub>1 x\<^isub>1 \<dots> x\<^isub>k)"}}
+ − 2024
\]\smallskip
+ − 2025
+ − 2026
\noindent
+ − 2027
in which the @{text "x"}$_{i..j}$ @{text "\<subseteq>"} @{text "x"}$_{1..k}$ are the
+ − 2028
recursive arguments of this term constructor (similarly for the other
+ − 2029
term-constructors).
+ − 2030
+ − 2031
Recall the lambda-calculus with @{text "Let"}-patterns shown in
+ − 2032
\eqref{letpat}. The cases lemmas and the induction principle shown in
3023
+ − 2033
\eqref{cases} and \eqref{induct} boil down in that example to the following three inference
3025
+ − 2034
rules:
3015
+ − 2035
+ − 2036
\begin{equation}\label{inductex}\mbox{
3018
+ − 2037
\begin{tabular}{c}
+ − 2038
\multicolumn{1}{@ {\hspace{-5mm}}l}{cases lemmas:}\smallskip\\
3015
+ − 2039
\infer{@{text "P\<^bsub>trm\<^esub>"}}
3017
+ − 2040
{\begin{array}{@ {}l@ {}}
3015
+ − 2041
@{text "\<forall>x. y = Var\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
+ − 2042
@{text "\<forall>x\<^isub>1 x\<^isub>2. y = App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
+ − 2043
@{text "\<forall>x\<^isub>1 x\<^isub>2. y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
3018
+ − 2044
@{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. y = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
+ − 2045
\end{array}}\hspace{10mm}
3015
+ − 2046
+ − 2047
\infer{@{text "P\<^bsub>pat\<^esub>"}}
3017
+ − 2048
{\begin{array}{@ {}l@ {}}
3015
+ − 2049
@{text "\<forall>x. y = PVar\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
+ − 2050
@{text "\<forall>x\<^isub>1 x\<^isub>2. y = PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub>"}
3018
+ − 2051
\end{array}}\medskip\\
+ − 2052
+ − 2053
\multicolumn{1}{@ {\hspace{-5mm}}l}{induction principle:}\smallskip\\
3015
+ − 2054
+ − 2055
\infer{@{text "P\<^bsub>trm\<^esub> y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}}
3017
+ − 2056
{\begin{array}{@ {}l@ {}}
3015
+ − 2057
@{text "\<forall>x. P\<^bsub>trm\<^esub> (Var\<^sup>\<alpha> x)"}\\
+ − 2058
@{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>trm\<^esub> x\<^isub>1 \<and> P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
+ − 2059
@{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>trm\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
3018
+ − 2060
@{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. P\<^bsub>pat\<^esub> x\<^isub>1 \<and> P\<^bsub>trm\<^esub> x\<^isub>2 \<and> P\<^bsub>trm\<^esub> x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub> (Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3)"}\\
3015
+ − 2061
@{text "\<forall>x. P\<^bsub>pat\<^esub> (PVar\<^sup>\<alpha> x)"}\\
+ − 2062
@{text "\<forall>x\<^isub>1 x\<^isub>2. P\<^bsub>pat\<^esub> x\<^isub>1 \<and> P\<^bsub>pat\<^esub> x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub> (PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}
+ − 2063
\end{array}}
+ − 2064
\end{tabular}}
+ − 2065
\end{equation}\smallskip
+ − 2066
+ − 2067
By working now completely on the alpha-equated level, we
3044
+ − 2068
can first show using \eqref{calphaeqvt} and Property~\ref{swapfreshfresh} that the support of each term
3015
+ − 2069
constructor is included in the support of its arguments,
+ − 2070
namely
+ − 2071
+ − 2072
\[
+ − 2073
@{text "(supp x\<^isub>1 \<union> \<dots> \<union> supp x\<^isub>r) supports (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>r)"}
3012
+ − 2074
\]\smallskip
+ − 2075
+ − 2076
\noindent
3015
+ − 2077
This allows us to prove using the induction principle for @{text "ty\<AL>"}$_{1..n}$
+ − 2078
that every element of type @{text "ty\<AL>"}$_{1..n}$ is finitely supported
3021
+ − 2079
(using Proposition~\ref{supportsprop}{\it (i)}).
3015
+ − 2080
Similarly, we can establish by induction that the free-atom functions and binding
+ − 2081
functions are equivariant, namely
2985
+ − 2082
3010
+ − 2083
\[\mbox{
+ − 2084
\begin{tabular}{rcl}
+ − 2085
@{text "\<pi> \<bullet> (fa_ty\<AL>\<^isub>i x)"} & $=$ & @{text "fa_ty\<AL>\<^isub>i (\<pi> \<bullet> x)"}\\
+ − 2086
@{text "\<pi> \<bullet> (fa_bn\<AL>\<^isub>j x)"} & $=$ & @{text "fa_bn\<AL>\<^isub>j (\<pi> \<bullet> x)"}\\
+ − 2087
@{text "\<pi> \<bullet> (bn\<AL>\<^isub>j x)"} & $=$ & @{text "bn\<AL>\<^isub>j (\<pi> \<bullet> x)"}\\
+ − 2088
\end{tabular}}
3012
+ − 2089
\]\smallskip
3010
+ − 2090
2985
+ − 2091
+ − 2092
\noindent
3015
+ − 2093
Lastly, we can show that the support of elements in @{text
3023
+ − 2094
"ty\<AL>"}$_{1..n}$ is the same as the free-atom functions @{text
3021
+ − 2095
"fa_ty\<AL>"}$_{1..n}$. This fact is important in the nominal setting where
+ − 2096
the general theory is formulated in terms of support and freshness, but also
+ − 2097
provides evidence that our notions of free-atoms and alpha-equivalence
3023
+ − 2098
`match up' correctly.
2985
+ − 2099
3017
+ − 2100
\begin{thm}\label{suppfa}
2985
+ − 2101
For @{text "x"}$_{1..n}$ with type @{text "ty\<AL>"}$_{1..n}$, we have
+ − 2102
@{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"}.
2989
+ − 2103
\end{thm}
2985
+ − 2104
+ − 2105
\begin{proof}
3017
+ − 2106
The proof is by induction on @{text "x"}$_{1..n}$. In each case
2985
+ − 2107
we unfold the definition of @{text "supp"}, move the swapping inside the
+ − 2108
term-constructors and then use the quasi-injectivity lemmas in order to complete the
3015
+ − 2109
proof. For the abstraction cases we use then the facts derived in Theorem~\ref{suppabs},
+ − 2110
for which we have to know that every body of an abstraction is finitely supported.
3016
+ − 2111
This, we have proved earlier.
2985
+ − 2112
\end{proof}
+ − 2113
+ − 2114
\noindent
3023
+ − 2115
Consequently, we can replace the free-atom functions by @{text "supp"} in
3021
+ − 2116
our quasi-injection lemmas. In the examples shown in \eqref{alphalift}, for instance,
+ − 2117
we obtain for @{text "Let\<^sup>\<alpha>"} and @{text "Let_rec\<^sup>\<alpha>"}
3016
+ − 2118
+ − 2119
\[\mbox{
+ − 2120
\begin{tabular}{@ {}c @ {}}
+ − 2121
\infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
+ − 2122
{@{term "alpha_lst_ex (bn_al as, t) equal supp (bn_al as', t')"} &
+ − 2123
\hspace{5mm}@{text "as \<approx>\<AL>\<^bsub>bn\<^esub> as'"}}\\
+ − 2124
\\
+ − 2125
\makebox[0mm]{\infer{@{text "Let_rec\<^sup>\<alpha> as t = Let_rec\<^sup>\<alpha> as' t'"}}
+ − 2126
{@{term "alpha_lst_ex (bn_al as, ast) equ2 supp2 (bn_al as', ast')"}}}\\
+ − 2127
\end{tabular}}
+ − 2128
\]\smallskip
+ − 2129
+ − 2130
\noindent
3021
+ − 2131
Taking into account that the compound equivalence relation @{term
3017
+ − 2132
"equ2"} and the compound free-atom function @{term "supp2"} are by
+ − 2133
definition equal to @{term "equal"} and @{term "supp"}, respectively, the
3021
+ − 2134
above rules simplify further to
3016
+ − 2135
+ − 2136
\[\mbox{
+ − 2137
\begin{tabular}{@ {}c @ {}}
+ − 2138
\infer{@{text "Let\<^sup>\<alpha> as t = Let\<^sup>\<alpha> as' t'"}}
+ − 2139
{@{term "Abs_lst (bn_al as) t = Abs_lst (bn_al as') t'"} &
+ − 2140
\hspace{5mm}@{text "as \<approx>\<AL>\<^bsub>bn\<^esub> as'"}}\\
+ − 2141
\\
+ − 2142
\makebox[0mm]{\infer{@{text "Let_rec\<^sup>\<alpha> as t = Let_rec\<^sup>\<alpha> as' t'"}}
+ − 2143
{@{term "Abs_lst (bn_al as) ast = Abs_lst (bn_al as') ast'"}}}\\
+ − 2144
\end{tabular}}
+ − 2145
\]\smallskip
+ − 2146
+ − 2147
\noindent
3017
+ − 2148
which means we can characterise equality between term-constructors (on the
+ − 2149
alpha-equated level) in terms of equality between the abstractions defined
+ − 2150
in Section~\ref{sec:binders}. From this we can deduce the support for @{text
+ − 2151
"Let\<^sup>\<alpha>"} and @{text "Let_rec\<^sup>\<alpha>"}, namely
+ − 2152
3016
+ − 2153
+ − 2154
\[\mbox{
+ − 2155
\begin{tabular}{l@ {\hspace{2mm}}l@ {\hspace{2mm}}l}
+ − 2156
@{text "supp (Let\<^sup>\<alpha> as t)"} & @{text "="} & @{text "(supp t - set (bn\<^sup>\<alpha> as)) \<union> fa\<AL>\<^bsub>bn\<^esub> as"}\\
+ − 2157
@{text "supp (Let_rec\<^sup>\<alpha> as t)"} & @{text "="} & @{text "(supp t \<union> supp as) - set (bn\<^sup>\<alpha> as)"}\\
+ − 2158
\end{tabular}}
+ − 2159
\]\smallskip
+ − 2160
+ − 2161
\noindent
+ − 2162
using the support of abstractions derived in Theorem~\ref{suppabs}.
+ − 2163
3021
+ − 2164
To sum up this section, we have established a reasoning infrastructure for the
3015
+ − 2165
types @{text "ty\<AL>"}$_{1..n}$ by first lifting definitions from the
3023
+ − 2166
`raw' level to the quotient level and then by proving facts about
3015
+ − 2167
these lifted definitions. All necessary proofs are generated automatically
+ − 2168
by custom ML-code.
2985
+ − 2169
*}
+ − 2170
+ − 2171
+ − 2172
section {* Strong Induction Principles *}
+ − 2173
+ − 2174
text {*
3015
+ − 2175
In the previous section we derived induction principles for alpha-equated
3017
+ − 2176
terms (see \eqref{induct} for the general form and \eqref{inductex} for an
3021
+ − 2177
example). This was done by lifting the corresponding inductions principles
3023
+ − 2178
for `raw' terms. We already employed these induction principles for
3021
+ − 2179
deriving several facts about alpha-equated terms, including the property that
3023
+ − 2180
the free-atom functions and the notion of support coincide. Still, we
3017
+ − 2181
call these induction principles \emph{weak}, because for a term-constructor,
+ − 2182
say \mbox{@{text "C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r"}}, the induction
+ − 2183
hypothesis requires us to establish (under some assumptions) a property
+ − 2184
@{text "P (C\<^sup>\<alpha> x\<^isub>1\<dots>x\<^isub>r)"} for \emph{all} @{text
3021
+ − 2185
"x"}$_{1..r}$. The problem with this is that in the presence of binders we cannot make
3025
+ − 2186
any assumptions about the atoms that are bound---for example assuming the variable convention.
+ − 2187
One obvious way around this
3044
+ − 2188
problem is to rename bound atoms. Unfortunately, this leads to very clunky proofs
3021
+ − 2189
and makes formalisations grievous experiences (especially in the context of
3015
+ − 2190
multiple bound atoms).
+ − 2191
3021
+ − 2192
For the older versions of Nominal Isabelle we described in \cite{Urban08} a
+ − 2193
method for automatically strengthening weak induction principles. These
+ − 2194
stronger induction principles allow the user to make additional assumptions
+ − 2195
about bound atoms. The advantage of these assumptions is that they make in
+ − 2196
most cases any renaming of bound atoms unnecessary. To explain how the
+ − 2197
strengthening works, we use as running example the lambda-calculus with
+ − 2198
@{text "Let"}-patterns shown in \eqref{letpat}. Its weak induction principle
+ − 2199
is given in \eqref{inductex}. The stronger induction principle is as
+ − 2200
follows:
2985
+ − 2201
3015
+ − 2202
\begin{equation}\label{stronginduct}
+ − 2203
\mbox{
+ − 2204
\begin{tabular}{@ {}c@ {}}
+ − 2205
\infer{@{text "P\<^bsub>trm\<^esub> c y\<^isub>1 \<and> P\<^bsub>pat\<^esub> c y\<^isub>2"}}
+ − 2206
{\begin{array}{l}
+ − 2207
@{text "\<forall>x c. P\<^bsub>trm\<^esub> c (Var\<^sup>\<alpha> x)"}\\
+ − 2208
@{text "\<forall>x\<^isub>1 x\<^isub>2 c. (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
3017
+ − 2209
@{text "\<forall>x\<^isub>1 x\<^isub>2 c. atom x\<^isub>1 # c \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>trm\<^esub> c (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}\\
+ − 2210
@{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3 c. (set (bn\<^sup>\<alpha> x\<^isub>1)) #\<^sup>* c \<and>"}\\
3018
+ − 2211
\hspace{10mm}@{text "(\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>2) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d x\<^isub>3) \<Rightarrow> P\<^bsub>trm\<^esub> c (Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3)"}\\
3015
+ − 2212
@{text "\<forall>x c. P\<^bsub>pat\<^esub> c (PVar\<^sup>\<alpha> x)"}\\
+ − 2213
@{text "\<forall>x\<^isub>1 x\<^isub>2 c. (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>1) \<and> (\<forall>d. P\<^bsub>pat\<^esub> d x\<^isub>2) \<Rightarrow> P\<^bsub>pat\<^esub> c (PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2)"}
+ − 2214
\end{array}}
+ − 2215
\end{tabular}}
+ − 2216
\end{equation}\smallskip
+ − 2217
2985
+ − 2218
3015
+ − 2219
\noindent
3021
+ − 2220
Notice that instead of establishing two properties of the form @{text "
+ − 2221
P\<^bsub>trm\<^esub> y\<^isub>1 \<and> P\<^bsub>pat\<^esub> y\<^isub>2"}, as the
+ − 2222
weak one does, the stronger induction principle establishes the properties
+ − 2223
of the form @{text " P\<^bsub>trm\<^esub> c y\<^isub>1 \<and>
+ − 2224
P\<^bsub>pat\<^esub> c y\<^isub>2"} in which the additional parameter @{text
+ − 2225
c} is assumed to be of finite support. The purpose of @{text "c"} is to
3023
+ − 2226
`control' which freshness assumptions the binders should satisfy in the
3021
+ − 2227
@{text "Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"} cases: for @{text
+ − 2228
"Lam\<^sup>\<alpha>"} we can assume the bound atom @{text "x\<^isub>1"} is fresh
+ − 2229
for @{text "c"} (third line); for @{text "Let_pat\<^sup>\<alpha>"} we can assume
+ − 2230
all bound atoms from an assignment are fresh for @{text "c"} (fourth
3025
+ − 2231
line). In order to see how an instantiation for @{text "c"} in the
3036
+ − 2232
conclusion `controls' the premises, one has to take into account that
3025
+ − 2233
Isabelle/HOL is a typed logic. That means if @{text "c"} is instantiated
3044
+ − 2234
with, for example, a pair, then this type-constraint will be propagated to
3025
+ − 2235
the premises. The main point is that if @{text "c"} is instantiated
3160
+ − 2236
appropriately, then the user can mimic the usual convenient `pencil-and-paper'
3025
+ − 2237
reasoning employing the variable convention about bound and free variables
+ − 2238
being distinct \cite{Urban08}.
3015
+ − 2239
3021
+ − 2240
In what follows we will show that the weak induction principle in
+ − 2241
\eqref{inductex} implies the strong one \eqref{stronginduct}. This fact was established for
3018
+ − 2242
single binders in \cite{Urban08} by some quite involved, nevertheless
3017
+ − 2243
automated, induction proof. In this paper we simplify the proof by
3023
+ − 2244
leveraging the automated proving tools from the function package of
+ − 2245
Isabelle/HOL \cite{Krauss09}. The reasoning principle behind these tools
3017
+ − 2246
is well-founded induction. To use them in our setting, we have to discharge
+ − 2247
two proof obligations: one is that we have well-founded measures (one for
+ − 2248
each type @{text "ty"}$^\alpha_{1..n}$) that decrease in every induction
3018
+ − 2249
step and the other is that we have covered all cases in the induction
+ − 2250
principle. Once these two proof obligations are discharged, the reasoning
3025
+ − 2251
infrastructure of the function package will automatically derive the
3021
+ − 2252
stronger induction principle. This way of establishing the stronger induction
3039
+ − 2253
principle is considerably simpler than the earlier work presented in \cite{Urban08}.
3015
+ − 2254
+ − 2255
As measures we can use the size functions @{text "size_ty"}$^\alpha_{1..n}$,
+ − 2256
which we lifted in the previous section and which are all well-founded. It
3017
+ − 2257
is straightforward to establish that the sizes decrease in every
3015
+ − 2258
induction step. What is left to show is that we covered all cases.
3017
+ − 2259
To do so, we have to derive stronger cases lemmas, which look in our
3129
+ − 2260
running example as follows:
3017
+ − 2261
+ − 2262
\[\mbox{
3018
+ − 2263
\begin{tabular}{@ {}c@ {\hspace{4mm}}c@ {}}
2985
+ − 2264
\infer{@{text "P\<^bsub>trm\<^esub>"}}
3017
+ − 2265
{\begin{array}{@ {}l@ {}}
+ − 2266
@{text "\<forall>x. y = Var\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
+ − 2267
@{text "\<forall>x\<^isub>1 x\<^isub>2. y = App\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
+ − 2268
@{text "\<forall>x\<^isub>1 x\<^isub>2. atom x\<^isub>1 # c \<and> y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}\\
3018
+ − 2269
@{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. set (bn\<^sup>\<alpha> x\<^isub>1) #\<^sup>* c \<and> y = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
3017
+ − 2270
\end{array}} &
+ − 2271
+ − 2272
\infer{@{text "P\<^bsub>pat\<^esub>"}}
+ − 2273
{\begin{array}{@ {}l@ {}}
+ − 2274
@{text "\<forall>x. y = PVar\<^sup>\<alpha> x \<Rightarrow> P\<^bsub>pat\<^esub>"}\\
+ − 2275
@{text "\<forall>x\<^isub>1 x\<^isub>2. y = PTup\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>pat\<^esub>"}
+ − 2276
\end{array}}
+ − 2277
\end{tabular}}
+ − 2278
\]\smallskip
+ − 2279
+ − 2280
\noindent
3021
+ − 2281
They are stronger in the sense that they allow us to assume in the @{text
+ − 2282
"Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"} cases that the bound atoms
3106
+ − 2283
avoid, or are fresh for, a context @{text "c"} (which is assumed to be finitely supported).
3018
+ − 2284
3023
+ − 2285
These stronger cases lemmas can be derived from the `weak' cases lemmas
3018
+ − 2286
given in \eqref{inductex}. This is trivial in case of patterns (the one on
+ − 2287
the right-hand side) since the weak and strong cases lemma coincide (there
+ − 2288
is no binding in patterns). Interesting are only the cases for @{text
+ − 2289
"Lam\<^sup>\<alpha>"} and @{text "Let_pat\<^sup>\<alpha>"}, where we have some binders and
3044
+ − 2290
therefore have an additional assumption about avoiding @{text "c"}. Let us
3021
+ − 2291
first establish the case for @{text "Lam\<^sup>\<alpha>"}. By the weak cases lemma
+ − 2292
\eqref{inductex} we can assume that
3017
+ − 2293
+ − 2294
\begin{equation}\label{assm}
+ − 2295
@{text "y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}
+ − 2296
\end{equation}\smallskip
+ − 2297
+ − 2298
\noindent
3021
+ − 2299
holds, and need to establish @{text "P\<^bsub>trm\<^esub>"}. The stronger cases lemma has the
3018
+ − 2300
corresponding implication
3017
+ − 2301
+ − 2302
\begin{equation}\label{imp}
+ − 2303
@{text "\<forall>x\<^isub>1 x\<^isub>2. atom x\<^isub>1 # c \<and> y = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub>"}
+ − 2304
\end{equation}\smallskip
+ − 2305
+ − 2306
\noindent
3025
+ − 2307
which we must use in order to infer @{text "P\<^bsub>trm\<^esub>"}. Clearly, we cannot
3023
+ − 2308
use this implication directly, because we have no information whether or not @{text
3017
+ − 2309
"x\<^isub>1"} is fresh for @{text "c"}. However, we can use Properties
3039
+ − 2310
\ref{supppermeq} and \ref{avoiding} to rename @{text "x\<^isub>1"}. We know
3017
+ − 2311
by Theorem~\ref{suppfa} that @{text "{atom x\<^isub>1} #\<^sup>* Lam\<^sup>\<alpha>
+ − 2312
x\<^isub>1 x\<^isub>2"} (since its support is @{text "supp x\<^isub>2 -
3021
+ − 2313
{atom x\<^isub>1}"}). Property \ref{avoiding} provides us then with a
3017
+ − 2314
permutation @{text "\<pi>"}, such that @{text "{atom (\<pi> \<bullet> x\<^isub>1)} #\<^sup>*
+ − 2315
c"} and \mbox{@{text "supp (Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2) #\<^sup>* \<pi>"}} hold.
3021
+ − 2316
By using Property \ref{supppermeq}, we can infer from the latter that
+ − 2317
+ − 2318
\[
+ − 2319
@{text "Lam\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) (\<pi> \<bullet> x\<^isub>2) = Lam\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}
+ − 2320
\]\smallskip
+ − 2321
+ − 2322
\noindent
+ − 2323
holds. We can use this equation in the assumption \eqref{assm}, and hence
+ − 2324
use the implication \eqref{imp} with the renamed @{text "\<pi> \<bullet> x\<^isub>1"}
+ − 2325
and @{text "\<pi> \<bullet> x\<^isub>2"} for concluding this case.
3017
+ − 2326
3018
+ − 2327
The @{text "Let_pat\<^sup>\<alpha>"}-case involving a deep binder is slightly more complicated.
3017
+ − 2328
We have the assumption
+ − 2329
3018
+ − 2330
\begin{equation}\label{assmtwo}
+ − 2331
@{text "y = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3"}
3017
+ − 2332
\end{equation}\smallskip
+ − 2333
+ − 2334
\noindent
3021
+ − 2335
and the implication from the stronger cases lemma
3018
+ − 2336
3021
+ − 2337
\begin{equation}\label{impletpat}
3018
+ − 2338
@{text "\<forall>x\<^isub>1 x\<^isub>2 x\<^isub>3. set (bn\<^sup>\<alpha> x\<^isub>1) #\<^sup>* c \<and> y = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3 \<Rightarrow> P\<^bsub>trm\<^esub>"}
3021
+ − 2339
\end{equation}\smallskip
3018
+ − 2340
+ − 2341
\noindent
3023
+ − 2342
The reason that this case is more complicated is that we cannot directly apply Property
3018
+ − 2343
\ref{avoiding} for obtaining a renaming permutation. Property \ref{avoiding} requires
+ − 2344
that the binders are fresh for the term in which we want to perform the renaming. But
3023
+ − 2345
this is not true in terms such as (using an informal notation)
3017
+ − 2346
+ − 2347
\[
3018
+ − 2348
@{text "Let (x, y) := (x, y) in (x, y)"}
+ − 2349
\]\smallskip
3017
+ − 2350
3018
+ − 2351
\noindent
3025
+ − 2352
where @{text x} and @{text y} are bound in the term, but are also free
3023
+ − 2353
in the right-hand side of the assignment. We can, however, obtain such a renaming permutation, say
3021
+ − 2354
@{text "\<pi>"}, for the abstraction @{term "Abs_lst (bn_al x\<^isub>1)
+ − 2355
x\<^isub>3"}. As a result we have \mbox{@{term "set (bn_al (\<pi> \<bullet> x\<^isub>1))
+ − 2356
\<sharp>* c"}} and @{term "Abs_lst (bn_al (\<pi> \<bullet> x\<^isub>1)) (\<pi> \<bullet> x\<^isub>3) =
+ − 2357
Abs_lst (bn_al x\<^isub>1) x\<^isub>3"} (remember @{text "set"} and @{text
+ − 2358
"bn\<^sup>\<alpha>"} are equivariant). Now the quasi-injective property for @{text
+ − 2359
"Let_pat\<^sup>\<alpha>"} states that
3018
+ − 2360
+ − 2361
\[
+ − 2362
\infer{@{text "Let_pat\<^sup>\<alpha> p t\<^isub>1 t\<^isub>2 = Let_pat\<^sup>\<alpha> p\<PRIME> t\<PRIME>\<^isub>1 t\<PRIME>\<^isub>2"}}
+ − 2363
{@{text "[bn\<^sup>\<alpha> p]\<^bsub>list\<^esub>. t\<^isub>2 = [bn\<^sup>\<alpha> p']\<^bsub>list\<^esub>. t\<PRIME>\<^isub>2"}\;\; &
+ − 2364
@{text "p \<approx>\<AL>\<^bsub>bn\<^esub> p\<PRIME>"}\;\; & @{text "t\<^isub>1 = t\<PRIME>\<^isub>1"}}
3017
+ − 2365
\]\smallskip
+ − 2366
3018
+ − 2367
\noindent
3021
+ − 2368
Since all atoms in a pattern are bound by @{text "Let_pat\<^sup>\<alpha>"}, we can infer
3023
+ − 2369
that @{text "(\<pi> \<bullet> x\<^isub>1) \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} holds for every @{text "\<pi>"}. Therefore we have that
3017
+ − 2370
3018
+ − 2371
\[
+ − 2372
@{text "Let_pat\<^sup>\<alpha> (\<pi> \<bullet> x\<^isub>1) x\<^isub>2 (\<pi> \<bullet> x\<^isub>3) = Let_pat\<^sup>\<alpha> x\<^isub>1 x\<^isub>2 x\<^isub>3"}
+ − 2373
\]\smallskip
+ − 2374
+ − 2375
\noindent
3023
+ − 2376
Taking the left-hand side in the assumption shown in \eqref{assmtwo}, we can use
3021
+ − 2377
the implication \eqref{impletpat} from the stronger cases lemma to infer @{text "P\<^bsub>trm\<^esub>"}, as needed.
3018
+ − 2378
3023
+ − 2379
The remaining difficulty is when a deep binder contains some atoms that are
+ − 2380
bound and some that are free. An example is @{text "Let\<^sup>\<alpha>"} in
3025
+ − 2381
\eqref{letrecs}. In such cases @{text "(\<pi> \<bullet> x\<^isub>1)
3023
+ − 2382
\<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} does not hold in general. The idea however is
+ − 2383
that @{text "\<pi>"} only renames atoms that become bound. In this way @{text "\<pi>"}
3025
+ − 2384
does not affect @{text "\<approx>\<AL>\<^bsub>bn\<^esub>"} (which only tracks alpha-equivalence of terms that are not
+ − 2385
under the binder). However, the problem is that the
3039
+ − 2386
permutation operation @{text "\<pi> \<bullet> x\<^isub>1"} applies to all atoms in @{text "x\<^isub>1"}. To avoid this
3021
+ − 2387
we introduce an auxiliary permutation operations, written @{text "_
+ − 2388
\<bullet>\<^bsub>bn\<^esub> _"}, for deep binders that only permutes bound atoms (or
+ − 2389
more precisely the atoms specified by the @{text "bn"}-functions) and leaves
3023
+ − 2390
the other atoms unchanged. Like the functions @{text "fa_bn"}$_{1..m}$, we
3025
+ − 2391
can define these permutation operations over raw terms analysing how the functions @{text
3023
+ − 2392
"bn"}$_{1..m}$ are defined. Assuming the user specified a clause
3017
+ − 2393
3019
+ − 2394
\[
+ − 2395
@{text "bn (C x\<^isub>1 \<dots> x\<^isub>r) = rhs"}
+ − 2396
\]\smallskip
3017
+ − 2397
2985
+ − 2398
\noindent
3019
+ − 2399
we define @{text "\<pi> \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>r) \<equiv> C y\<^isub>1 \<dots> y\<^isub>r"} with @{text "y\<^isub>i"} determined as follows:
+ − 2400
+ − 2401
\[\mbox{
2985
+ − 2402
\begin{tabular}{c@ {\hspace{2mm}}p{0.9\textwidth}}
+ − 2403
$\bullet$ & @{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}\\
3044
+ − 2404
$\bullet$ & @{text "y\<^isub>i \<equiv> \<pi> \<bullet>\<^bsub>bn\<^esub> x\<^isub>i"} provided @{text "bn x\<^isub>i"} is in @{text "rhs"}\\
3019
+ − 2405
$\bullet$ & @{text "y\<^isub>i \<equiv> \<pi> \<bullet> x\<^isub>i"} otherwise
+ − 2406
\end{tabular}}
+ − 2407
\]\smallskip
2985
+ − 2408
+ − 2409
\noindent
3025
+ − 2410
Using again the quotient package we can lift the auxiliary permutation operations
+ − 2411
@{text "_ \<bullet>\<^bsub>bn\<^esub> _"}
3044
+ − 2412
to alpha-equated terms. Moreover we can prove the following two properties:
2985
+ − 2413
2989
+ − 2414
\begin{lem}\label{permutebn}
3023
+ − 2415
Given a binding function @{text "bn\<^sup>\<alpha>"} and auxiliary equivalence @{text "\<approx>\<AL>\<^bsub>bn\<^esub>"}
+ − 2416
then for all @{text "\<pi>"}\smallskip\\
3019
+ − 2417
{\it (i)} @{text "\<pi> \<bullet> (bn\<^sup>\<alpha> x) = bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x)"} and\\
+ − 2418
{\it (ii)} @{text "(\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x) \<approx>\<AL>\<^bsub>bn\<^esub> x"}.
2989
+ − 2419
\end{lem}
2985
+ − 2420
+ − 2421
\begin{proof}
3021
+ − 2422
By induction on @{text x}. The properties follow by unfolding of the
+ − 2423
definitions.
2985
+ − 2424
\end{proof}
+ − 2425
+ − 2426
\noindent
3021
+ − 2427
The first property states that a permutation applied to a binding function
+ − 2428
is equivalent to first permuting the binders and then calculating the bound
3025
+ − 2429
atoms. The second states that @{text "_ \<bullet>\<AL>\<^bsub>bn\<^esub> _"} preserves
3021
+ − 2430
@{text "\<approx>\<AL>\<^bsub>bn\<^esub>"}. The main point of the auxiliary
3039
+ − 2431
permutation functions is that they allow us to rename just the bound atoms in a
3021
+ − 2432
term, without changing anything else.
2985
+ − 2433
3019
+ − 2434
Having the auxiliary permutation function in place, we can now solve all remaining cases.
3021
+ − 2435
For the @{text "Let\<^sup>\<alpha>"} term-constructor, for example, we can by Property \ref{avoiding}
3019
+ − 2436
obtain a @{text "\<pi>"} such that
+ − 2437
+ − 2438
\[
+ − 2439
@{text "(\<pi> \<bullet> (set (bn\<^sup>\<alpha> x\<^isub>1)) #\<^sup>* c"} \hspace{10mm}
+ − 2440
@{text "\<pi> \<bullet> [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2 = [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2"}
+ − 2441
\]\smallskip
2985
+ − 2442
+ − 2443
\noindent
3023
+ − 2444
hold. Using the first part of Lemma \ref{permutebn}, we can simplify this
3019
+ − 2445
to @{text "set (bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1)) #\<^sup>* c"} and
3025
+ − 2446
\mbox{@{text "[bn\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1)]\<^bsub>list\<^esub>. (\<pi> \<bullet> x\<^isub>2) = [bn\<^sup>\<alpha> x\<^isub>1]\<^bsub>list\<^esub>. x\<^isub>2"}}. Since
+ − 2447
@{text "(\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1) \<approx>\<AL>\<^bsub>bn\<^esub> x\<^isub>1"} holds by the second part,
3019
+ − 2448
we can infer that
2985
+ − 2449
3019
+ − 2450
\[
+ − 2451
@{text "Let\<^sup>\<alpha> (\<pi> \<bullet>\<AL>\<^bsub>bn\<^esub> x\<^isub>1) (\<pi> \<bullet> x\<^isub>2) = Let\<^sup>\<alpha> x\<^isub>1 x\<^isub>2"}
+ − 2452
\]\smallskip
+ − 2453
+ − 2454
\noindent
3021
+ − 2455
holds. This allows us to use the implication from the strong cases
3025
+ − 2456
lemma, and we are done.
3017
+ − 2457
3160
+ − 2458
Consequently, we can discharge all proof-obligations about having `covered all
+ − 2459
cases'. This completes the proof establishing that the weak induction principles imply
3044
+ − 2460
the strong induction principles. These strong induction principles have already proved
+ − 2461
being very useful in practice, particularly for proving properties about
+ − 2462
capture-avoiding substitution \cite{Urban08}.
2985
+ − 2463
*}
+ − 2464
+ − 2465
+ − 2466
section {* Related Work\label{related} *}
+ − 2467
+ − 2468
text {*
+ − 2469
To our knowledge the earliest usage of general binders in a theorem prover
3010
+ − 2470
is described by Nara\-schew\-ski and Nipkow \cite{NaraschewskiNipkow99} with a
+ − 2471
formalisation of the algorithm W. This formalisation implements binding in
+ − 2472
type-schemes using a de-Bruijn indices representation. Since type-schemes in
+ − 2473
W contain only a single place where variables are bound, different indices
+ − 2474
do not refer to different binders (as in the usual de-Bruijn
+ − 2475
representation), but to different bound variables. A similar idea has been
3023
+ − 2476
recently explored for general binders by Chargu\'eraud \cite{chargueraud09}
+ − 2477
in the locally nameless approach to
+ − 2478
binding. There, de-Bruijn indices consist of two
3010
+ − 2479
numbers, one referring to the place where a variable is bound, and the other
+ − 2480
to which variable is bound. The reasoning infrastructure for both
+ − 2481
representations of bindings comes for free in theorem provers like
3013
+ − 2482
Isabelle/HOL and Coq, since the corresponding term-calculi can be implemented
3023
+ − 2483
as `normal' datatypes. However, in both approaches it seems difficult to
+ − 2484
achieve our fine-grained control over the `semantics' of bindings
3010
+ − 2485
(i.e.~whether the order of binders should matter, or vacuous binders should
+ − 2486
be taken into account). To do so, one would require additional predicates
+ − 2487
that filter out unwanted terms. Our guess is that such predicates result in
3013
+ − 2488
rather intricate formal reasoning. We are not aware of any formalisation of
+ − 2489
a non-trivial language that uses Chargu\'eraud's idea.
2985
+ − 2490
+ − 2491
Another technique for representing binding is higher-order abstract syntax
3023
+ − 2492
(HOAS), which for example is implemented in the Twelf system \cite{pfenningsystem}.
+ − 2493
This representation technique supports very elegantly many aspects of
3024
+ − 2494
\emph{single} binding, and impressive work by Lee et al~\cite{LeeCraryHarper07}
3023
+ − 2495
has been done that uses HOAS for mechanising the metatheory of SML. We
3010
+ − 2496
are, however, not aware how multiple binders of SML are represented in this
+ − 2497
work. Judging from the submitted Twelf-solution for the POPLmark challenge,
+ − 2498
HOAS cannot easily deal with binding constructs where the number of bound
3023
+ − 2499
variables is not fixed. For example, in the second part of this challenge,
3010
+ − 2500
@{text "Let"}s involve patterns that bind multiple variables at once. In
+ − 2501
such situations, HOAS seems to have to resort to the
+ − 2502
iterated-single-binders-approach with all the unwanted consequences when
+ − 2503
reasoning about the resulting terms.
+ − 2504
2985
+ − 2505
+ − 2506
Two formalisations involving general binders have been
+ − 2507
performed in older
+ − 2508
versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W
+ − 2509
\cite{BengtsonParow09,UrbanNipkow09}). Both
+ − 2510
use the approach based on iterated single binders. Our experience with
+ − 2511
the latter formalisation has been disappointing. The major pain arose from
3160
+ − 2512
the need to `unbind' bound variables and the resulting formal reasoning turned out to
+ − 2513
be rather unpleasant. In contrast, the unbinding can be
+ − 2514
done in one step with our
+ − 2515
general binders described in this paper.
+ − 2516
3010
+ − 2517
The most closely related work to the one presented here is the Ott-tool by
+ − 2518
Sewell et al \cite{ott-jfp} and the C$\alpha$ml language by Pottier
+ − 2519
\cite{Pottier06}. Ott is a nifty front-end for creating \LaTeX{} documents
+ − 2520
from specifications of term-calculi involving general binders. For a subset
3023
+ − 2521
of the specifications Ott can also generate theorem prover code using a `raw'
3010
+ − 2522
representation of terms, and in Coq also a locally nameless
+ − 2523
representation. The developers of this tool have also put forward (on paper)
+ − 2524
a definition for alpha-equivalence and free variables for terms that can be
+ − 2525
specified in Ott. This definition is rather different from ours, not using
+ − 2526
any nominal techniques. To our knowledge there is no concrete mathematical
+ − 2527
result concerning this notion of alpha-equivalence and free variables. We
+ − 2528
have proved that our definitions lead to alpha-equated terms, whose support
3025
+ − 2529
is as expected (that means bound atoms are removed from the support). We
3160
+ − 2530
also showed that our specifications lift from `raw' terms to
3044
+ − 2531
alpha-equivalence classes. For this we have established (automatically) that every
3160
+ − 2532
term-constructor and function defined for `raw' terms
3023
+ − 2533
is respectful w.r.t.~alpha-equivalence.
2985
+ − 2534
3010
+ − 2535
Although we were heavily inspired by the syntax of Ott, its definition of
+ − 2536
alpha-equi\-valence is unsuitable for our extension of Nominal
+ − 2537
Isabelle. First, it is far too complicated to be a basis for automated
+ − 2538
proofs implemented on the ML-level of Isabelle/HOL. Second, it covers cases
+ − 2539
of binders depending on other binders, which just do not make sense for our
3126
+ − 2540
alpha-equated terms (the corresponding @{text "fa"}-functions would not lift).
+ − 2541
Third, it allows empty types that have no meaning in a
3010
+ − 2542
HOL-based theorem prover. We also had to generalise slightly Ott's binding
+ − 2543
clauses. In Ott one specifies binding clauses with a single body; we allow
+ − 2544
more than one. We have to do this, because this makes a difference for our
+ − 2545
notion of alpha-equivalence in case of \isacommand{binds (set)} and
+ − 2546
\isacommand{binds (set+)}. Consider the examples
2985
+ − 2547
3010
+ − 2548
\[\mbox{
2985
+ − 2549
\begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
+ − 2550
@{text "Foo\<^isub>1 xs::name fset t::trm s::trm"} &
3004
+ − 2551
\isacommand{binds (set)} @{text "xs"} \isacommand{in} @{text "t s"}\\
2985
+ − 2552
@{text "Foo\<^isub>2 xs::name fset t::trm s::trm"} &
3004
+ − 2553
\isacommand{binds (set)} @{text "xs"} \isacommand{in} @{text "t"},
+ − 2554
\isacommand{binds (set)} @{text "xs"} \isacommand{in} @{text "s"}\\
3010
+ − 2555
\end{tabular}}
+ − 2556
\]\smallskip
2985
+ − 2557
+ − 2558
\noindent
3010
+ − 2559
In the first term-constructor we have a single body that happens to be
3023
+ − 2560
`spread' over two arguments; in the second term-constructor we have two
3010
+ − 2561
independent bodies in which the same variables are bound. As a result we
+ − 2562
have\footnote{Assuming @{term "a \<noteq> b"}, there is no permutation that can
3011
+ − 2563
make @{text "(a, b)"} equal with both @{text "(a, b)"} and @{text "(b, a)"}, but
3010
+ − 2564
there are two permutations so that we can make @{text "(a, b)"} and @{text
+ − 2565
"(a, b)"} equal with one permutation, and @{text "(a, b)"} and @{text "(b,
+ − 2566
a)"} with the other.}
+ − 2567
+ − 2568
+ − 2569
\[\mbox{
+ − 2570
\begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}l}
+ − 2571
@{text "Foo\<^isub>1 {a, b} (a, b) (a, b)"} & $\not=$ &
+ − 2572
@{text "Foo\<^isub>1 {a, b} (a, b) (b, a)"}
+ − 2573
\end{tabular}}
+ − 2574
\]\smallskip
+ − 2575
+ − 2576
\noindent
+ − 2577
but
2985
+ − 2578
3010
+ − 2579
\[\mbox{
+ − 2580
\begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}l}
+ − 2581
@{text "Foo\<^isub>2 {a, b} (a, b) (a, b)"} & $=$ &
+ − 2582
@{text "Foo\<^isub>2 {a, b} (a, b) (b, a)"}\\
+ − 2583
\end{tabular}}
+ − 2584
\]\smallskip
+ − 2585
+ − 2586
\noindent
3160
+ − 2587
and therefore need the extra generality to be able to distinguish
+ − 2588
between both specifications. Because of how we set up our
+ − 2589
definitions, we also had to impose some restrictions (like a single
+ − 2590
binding function for a deep binder) that are not present in Ott. Our
+ − 2591
expectation is that we can still cover many interesting term-calculi
+ − 2592
from programming language research, for example the Core-Haskell
+ − 2593
language from the Introduction. With the work presented in this
+ − 2594
paper we can define it formally as shown in
+ − 2595
Figure~\ref{nominalcorehas} and then Nominal Isabelle derives
+ − 2596
automatically a corresponding reasoning infrastructure. However we
+ − 2597
have found out that telescopes seem to not easily be representable
+ − 2598
in our framework. The reason is that we need to be able to lift our
+ − 2599
@{text bn}-functions to alpha-equated lambda-terms and therefore
+ − 2600
need to restrict what these @{text bn}-functions can return.
+ − 2601
Telescopes can be represented in the framework described in
+ − 2602
\cite{WeirichYorgeySheard11} using an extension of the usual
+ − 2603
locally-nameless representation.
3013
+ − 2604
3023
+ − 2605
\begin{figure}[p]
3013
+ − 2606
\begin{boxedminipage}{\linewidth}
+ − 2607
\small
+ − 2608
\begin{tabular}{l}
+ − 2609
\isacommand{atom\_decl}~@{text "var cvar tvar"}\\[1mm]
+ − 2610
\isacommand{nominal\_datatype}~@{text "tkind ="}~@{text "KStar"}~$|$~@{text "KFun tkind tkind"}\\
+ − 2611
\isacommand{and}~@{text "ckind ="}~@{text "CKSim ty ty"}\\
+ − 2612
\isacommand{and}~@{text "ty ="}~@{text "TVar tvar"}~$|$~@{text "T string"}~$|$~@{text "TApp ty ty"}\\
+ − 2613
$|$~@{text "TFun string ty_list"}~%
+ − 2614
$|$~@{text "TAll tv::tvar tkind ty::ty"}\hspace{3mm}\isacommand{binds}~@{text "tv"}~\isacommand{in}~@{text ty}\\
+ − 2615
$|$~@{text "TArr ckind ty"}\\
+ − 2616
\isacommand{and}~@{text "ty_lst ="}~@{text "TNil"}~$|$~@{text "TCons ty ty_lst"}\\
+ − 2617
\isacommand{and}~@{text "cty ="}~@{text "CVar cvar"}~%
+ − 2618
$|$~@{text "C string"}~$|$~@{text "CApp cty cty"}~$|$~@{text "CFun string co_lst"}\\
+ − 2619
$|$~@{text "CAll cv::cvar ckind cty::cty"}\hspace{3mm}\isacommand{binds}~@{text "cv"}~\isacommand{in}~@{text cty}\\
+ − 2620
$|$~@{text "CArr ckind cty"}~$|$~@{text "CRefl ty"}~$|$~@{text "CSym cty"}~$|$~@{text "CCirc cty cty"}\\
+ − 2621
$|$~@{text "CAt cty ty"}~$|$~@{text "CLeft cty"}~$|$~@{text "CRight cty"}~$|$~@{text "CSim cty cty"}\\
+ − 2622
$|$~@{text "CRightc cty"}~$|$~@{text "CLeftc cty"}~$|$~@{text "Coerce cty cty"}\\
+ − 2623
\isacommand{and}~@{text "co_lst ="}~@{text "CNil"}~$|$~@{text "CCons cty co_lst"}\\
+ − 2624
\isacommand{and}~@{text "trm ="}~@{text "Var var"}~$|$~@{text "K string"}\\
+ − 2625
$|$~@{text "LAM_ty tv::tvar tkind t::trm"}\hspace{3mm}\isacommand{binds}~@{text "tv"}~\isacommand{in}~@{text t}\\
+ − 2626
$|$~@{text "LAM_cty cv::cvar ckind t::trm"}\hspace{3mm}\isacommand{binds}~@{text "cv"}~\isacommand{in}~@{text t}\\
+ − 2627
$|$~@{text "App_ty trm ty"}~$|$~@{text "App_cty trm cty"}~$|$~@{text "App trm trm"}\\
+ − 2628
$|$~@{text "Lam v::var ty t::trm"}\hspace{3mm}\isacommand{binds}~@{text "v"}~\isacommand{in}~@{text t}\\
+ − 2629
$|$~@{text "Let x::var ty trm t::trm"}\hspace{3mm}\isacommand{binds}~@{text x}~\isacommand{in}~@{text t}\\
+ − 2630
$|$~@{text "Case trm assoc_lst"}~$|$~@{text "Cast trm co"}\\
+ − 2631
\isacommand{and}~@{text "assoc_lst ="}~@{text ANil}~%
+ − 2632
$|$~@{text "ACons p::pat t::trm assoc_lst"}\hspace{3mm}\isacommand{binds}~@{text "bv p"}~\isacommand{in}~@{text t}\\
+ − 2633
\isacommand{and}~@{text "pat ="}~@{text "Kpat string tvtk_lst tvck_lst vt_lst"}\\
+ − 2634
\isacommand{and}~@{text "vt_lst ="}~@{text VTNil}~$|$~@{text "VTCons var ty vt_lst"}\\
+ − 2635
\isacommand{and}~@{text "tvtk_lst ="}~@{text TVTKNil}~$|$~@{text "TVTKCons tvar tkind tvtk_lst"}\\
+ − 2636
\isacommand{and}~@{text "tvck_lst ="}~@{text TVCKNil}~$|$ @{text "TVCKCons cvar ckind tvck_lst"}\\
+ − 2637
\isacommand{binder}\\
3160
+ − 2638
\;@{text "bv :: pat \<Rightarrow> atom list"}~\isacommand{and}\\
+ − 2639
\;@{text "bv\<^isub>1 :: vt_lst \<Rightarrow> atom list"}~\isacommand{and}\\
+ − 2640
\;@{text "bv\<^isub>2 :: tvtk_lst \<Rightarrow> atom list"}~\isacommand{and}\\
+ − 2641
\;@{text "bv\<^isub>3 :: tvck_lst \<Rightarrow> atom list"}\\
3013
+ − 2642
\isacommand{where}\\
+ − 2643
\phantom{$|$}~@{text "bv (K s tvts tvcs vs) = (bv\<^isub>3 tvts) @ (bv\<^isub>2 tvcs) @ (bv\<^isub>1 vs)"}\\
+ − 2644
$|$~@{text "bv\<^isub>1 VTNil = []"}\\
+ − 2645
$|$~@{text "bv\<^isub>1 (VTCons x ty tl) = (atom x)::(bv\<^isub>1 tl)"}\\
+ − 2646
$|$~@{text "bv\<^isub>2 TVTKNil = []"}\\
+ − 2647
$|$~@{text "bv\<^isub>2 (TVTKCons a ty tl) = (atom a)::(bv\<^isub>2 tl)"}\\
+ − 2648
$|$~@{text "bv\<^isub>3 TVCKNil = []"}\\
+ − 2649
$|$~@{text "bv\<^isub>3 (TVCKCons c cty tl) = (atom c)::(bv\<^isub>3 tl)"}\\
+ − 2650
\end{tabular}
+ − 2651
\end{boxedminipage}
3023
+ − 2652
\caption{A definition for Core-Haskell in Nominal Isabelle. For the moment we
3013
+ − 2653
do not support nested types; therefore we explicitly have to unfold the
3025
+ − 2654
lists @{text "co_lst"}, @{text "assoc_lst"} and so on. Apart from that limitation, the
3023
+ − 2655
definition follows closely the original shown in Figure~\ref{corehas}. The
+ − 2656
point of our work is that having made such a definition in Nominal Isabelle,
+ − 2657
one obtains automatically a reasoning infrastructure for Core-Haskell.
3013
+ − 2658
\label{nominalcorehas}}
+ − 2659
\end{figure}
3023
+ − 2660
\afterpage{\clearpage}
3010
+ − 2661
+ − 2662
Pottier presents a programming language, called C$\alpha$ml, for
+ − 2663
representing terms with general binders inside OCaml \cite{Pottier06}. This
+ − 2664
language is implemented as a front-end that can be translated to OCaml with
+ − 2665
the help of a library. He presents a type-system in which the scope of
+ − 2666
general binders can be specified using special markers, written @{text
+ − 2667
"inner"} and @{text "outer"}. It seems our and his specifications can be
+ − 2668
inter-translated as long as ours use the binding mode \isacommand{binds}
+ − 2669
only. However, we have not proved this. Pottier gives a definition for
2989
+ − 2670
alpha-equivalence, which also uses a permutation operation (like ours).
2985
+ − 2671
Still, this definition is rather different from ours and he only proves that
3010
+ − 2672
it defines an equivalence relation. A complete reasoning infrastructure is
+ − 2673
well beyond the purposes of his language. Similar work for Haskell with
+ − 2674
similar results was reported by Cheney \cite{Cheney05a} and more recently
3011
+ − 2675
by Weirich et al \cite{WeirichYorgeySheard11}.
3010
+ − 2676
+ − 2677
In a slightly different domain (programming with dependent types),
3011
+ − 2678
Altenkirch et al \cite{Altenkirch10} present a calculus with a notion of
+ − 2679
alpha-equivalence related to our binding mode \isacommand{binds (set+)}.
3010
+ − 2680
Their definition is similar to the one by Pottier, except that it has a more
+ − 2681
operational flavour and calculates a partial (renaming) map. In this way,
+ − 2682
the definition can deal with vacuous binders. However, to our best
+ − 2683
knowledge, no concrete mathematical result concerning this definition of
+ − 2684
alpha-equivalence has been proved.
2985
+ − 2685
*}
+ − 2686
+ − 2687
section {* Conclusion *}
+ − 2688
+ − 2689
text {*
2989
+ − 2690
3010
+ − 2691
We have presented an extension of Nominal Isabelle for dealing with general
3023
+ − 2692
binders, that is where term-constructors have multiple bound atoms. For this
3010
+ − 2693
extension we introduced new definitions of alpha-equivalence and automated
+ − 2694
all necessary proofs in Isabelle/HOL. To specify general binders we used
+ − 2695
the syntax from Ott, but extended it in some places and restricted
3023
+ − 2696
it in others so that the definitions make sense in the context of alpha-equated
3010
+ − 2697
terms. We also introduced two binding modes (set and set+) that do not exist
+ − 2698
in Ott. We have tried out the extension with calculi such as Core-Haskell,
+ − 2699
type-schemes and approximately a dozen of other typical examples from
+ − 2700
programming language research~\cite{SewellBestiary}. The code will
3044
+ − 2701
eventually become part of the Isabelle distribution.\footnote{It
3023
+ − 2702
can be downloaded already from \href{http://isabelle.in.tum.de/nominal/download}
2985
+ − 2703
{http://isabelle.in.tum.de/nominal/download}.}
+ − 2704
+ − 2705
We have left out a discussion about how functions can be defined over
3013
+ − 2706
alpha-equated terms involving general binders. In earlier versions of
+ − 2707
Nominal Isabelle this turned out to be a thorny issue. We hope to do better
+ − 2708
this time by using the function package \cite{Krauss09} that has recently
2985
+ − 2709
been implemented in Isabelle/HOL and also by restricting function
3013
+ − 2710
definitions to equivariant functions (for them we can provide more
+ − 2711
automation).
2985
+ − 2712
3160
+ − 2713
There are some restrictions we had
+ − 2714
to impose in this paper that can be lifted using
3130
+ − 2715
a recent reimplementation \cite{Traytel12} of the datatype package for Isabelle/HOL, which
3160
+ − 2716
however is not yet part of the stable distribution.
3130
+ − 2717
This reimplementation allows nested
3160
+ − 2718
datatype definitions and would allow one to specify, for instance, the function kinds
2985
+ − 2719
in Core-Haskell as @{text "TFun string (ty list)"} instead of the unfolded
3130
+ − 2720
version @{text "TFun string ty_list"} (see Figure~\ref{nominalcorehas}). We can
+ − 2721
also use it to represent the @{text "Let"}-terms from the Introduction where
+ − 2722
the order of @{text "let"}-assignments does not matter. This means we can represent @{text "Let"}s
+ − 2723
such that the following two terms are equal
2985
+ − 2724
3130
+ − 2725
\[
+ − 2726
@{text "Let x\<^isub>1 = t\<^isub>1 and x\<^isub>2 = t\<^isub>2 in s"} \;\;=\;\;
+ − 2727
@{text "Let x\<^isub>2 = t\<^isub>2 and x\<^isub>1 = t\<^isub>1 in s"}
+ − 2728
\]\smallskip
+ − 2729
+ − 2730
\noindent
3160
+ − 2731
For this we have to represent the @{text "Let"}-assignments as finite sets
3130
+ − 2732
of pair and a binding function that picks out the left components to be bound in @{text s}.
+ − 2733
3160
+ − 2734
One line of future investigation is whether we can go beyond the
2985
+ − 2735
simple-minded form of binding functions that we adopted from Ott. At the moment, binding
+ − 2736
functions can only return the empty set, a singleton atom set or unions
+ − 2737
of atom sets (similarly for lists). It remains to be seen whether
+ − 2738
properties like
+ − 2739
3010
+ − 2740
\[
+ − 2741
\mbox{@{text "fa_ty x = bn x \<union> fa_bn x"}}
+ − 2742
\]\smallskip
2985
+ − 2743
+ − 2744
\noindent
+ − 2745
allow us to support more interesting binding functions.
+ − 2746
+ − 2747
We have also not yet played with other binding modes. For example we can
3010
+ − 2748
imagine that there is need for a binding mode where instead of usual lists,
+ − 2749
we abstract lists of distinct elements (the corresponding type @{text
+ − 2750
"dlist"} already exists in the library of Isabelle/HOL). We expect the
3039
+ − 2751
presented work can be extended to accommodate such binding modes.\medskip
2985
+ − 2752
+ − 2753
\noindent
2989
+ − 2754
{\bf Acknowledgements:} We are very grateful to Andrew Pitts for many
+ − 2755
discussions about Nominal Isabelle. We thank Peter Sewell for making the
+ − 2756
informal notes \cite{SewellBestiary} available to us and also for patiently
+ − 2757
explaining some of the finer points of the Ott-tool. Stephanie Weirich
+ − 2758
suggested to separate the subgrammars of kinds and types in our Core-Haskell
3130
+ − 2759
example. Ramana Kumar and Andrei Popescu helped us with comments for
3041
+ − 2760
an earlier version of this paper.
2985
+ − 2761
*}
+ − 2762
+ − 2763
+ − 2764
(*<*)
+ − 2765
end
+ − 2766
(*>*)