754
+ − 1
(*<*)
+ − 2
theory Paper
2330
+ − 3
imports "../Nominal/NewParser" "LaTeXsugar"
754
+ − 4
begin
1493
+ − 5
1657
+ − 6
consts
+ − 7
fv :: "'a \<Rightarrow> 'b"
1728
+ − 8
abs_set :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
+ − 9
alpha_bn :: "'a \<Rightarrow> 'a \<Rightarrow> bool"
1763
+ − 10
abs_set2 :: "'a \<Rightarrow> perm \<Rightarrow> 'b \<Rightarrow> 'c"
1796
5165c350ee1a
clarified comment about distinct lists in th efuture work section
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 11
Abs_dist :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
2163
+ − 12
Abs_print :: "'a \<Rightarrow> 'b \<Rightarrow> 'c"
1657
+ − 13
+ − 14
definition
+ − 15
"equal \<equiv> (op =)"
+ − 16
1493
+ − 17
notation (latex output)
+ − 18
swap ("'(_ _')" [1000, 1000] 1000) and
+ − 19
fresh ("_ # _" [51, 51] 50) and
1694
+ − 20
fresh_star ("_ #\<^sup>* _" [51, 51] 50) and
1493
+ − 21
supp ("supp _" [78] 73) and
+ − 22
uminus ("-_" [78] 73) and
1657
+ − 23
If ("if _ then _ else _" 10) and
2341
+ − 24
alpha_gen ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{set}}$}}>\<^bsup>_, _, _\<^esup> _") and
+ − 25
alpha_lst ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{list}}$}}>\<^bsup>_, _, _\<^esup> _") and
+ − 26
alpha_res ("_ \<approx>\<^raw:\,\raisebox{-1pt}{\makebox[0mm][l]{$_{\textit{res}}$}}>\<^bsup>_, _, _\<^esup> _") and
1657
+ − 27
abs_set ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and
1763
+ − 28
abs_set2 ("_ \<approx>\<^raw:\raisebox{-1pt}{\makebox[0mm][l]{$\,_{\textit{list}}$}}>\<^bsup>_\<^esup> _") and
2347
+ − 29
fv ("fa'(_')" [100] 100) and
1657
+ − 30
equal ("=") and
+ − 31
alpha_abs ("_ \<approx>\<^raw:{$\,_{\textit{abs\_set}}$}> _") and
2331
+ − 32
Abs ("[_]\<^bsub>set\<^esub>._" [20, 101] 999) and
+ − 33
Abs_lst ("[_]\<^bsub>list\<^esub>._") and
+ − 34
Abs_dist ("[_]\<^bsub>#list\<^esub>._") and
+ − 35
Abs_res ("[_]\<^bsub>res\<^esub>._") and
+ − 36
Abs_print ("_\<^bsub>set\<^esub>._") and
1703
+ − 37
Cons ("_::_" [78,77] 73) and
1728
+ − 38
supp_gen ("aux _" [1000] 10) and
+ − 39
alpha_bn ("_ \<approx>bn _")
754
+ − 40
(*>*)
+ − 41
1657
+ − 42
754
+ − 43
section {* Introduction *}
+ − 44
+ − 45
text {*
1739
+ − 46
2345
+ − 47
So far, Nominal Isabelle provided a mechanism for constructing
2343
+ − 48
$\alpha$-equated terms, for example lambda-terms
1485
+ − 49
1520
+ − 50
\begin{center}
1657
+ − 51
@{text "t ::= x | t t | \<lambda>x. t"}
1520
+ − 52
\end{center}
+ − 53
+ − 54
\noindent
2341
+ − 55
where free and bound variables have names. For such $\alpha$-equated terms,
2163
+ − 56
Nominal Isabelle derives automatically a reasoning infrastructure that has
+ − 57
been used successfully in formalisations of an equivalence checking
+ − 58
algorithm for LF \cite{UrbanCheneyBerghofer08}, Typed
1520
+ − 59
Scheme~\cite{TobinHochstadtFelleisen08}, several calculi for concurrency
2163
+ − 60
\cite{BengtsonParow09} and a strong normalisation result for cut-elimination
+ − 61
in classical logic \cite{UrbanZhu08}. It has also been used by Pollack for
+ − 62
formalisations in the locally-nameless approach to binding
+ − 63
\cite{SatoPollack10}.
1520
+ − 64
1535
+ − 65
However, Nominal Isabelle has fared less well in a formalisation of
1690
+ − 66
the algorithm W \cite{UrbanNipkow09}, where types and type-schemes are,
+ − 67
respectively, of the form
1570
+ − 68
%
+ − 69
\begin{equation}\label{tysch}
+ − 70
\begin{array}{l}
1657
+ − 71
@{text "T ::= x | T \<rightarrow> T"}\hspace{5mm}
+ − 72
@{text "S ::= \<forall>{x\<^isub>1,\<dots>, x\<^isub>n}. T"}
1570
+ − 73
\end{array}
+ − 74
\end{equation}
1520
+ − 75
+ − 76
\noindent
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 77
and the @{text "\<forall>"}-quantification binds a finite (possibly empty) set of
1550
+ − 78
type-variables. While it is possible to implement this kind of more general
+ − 79
binders by iterating single binders, this leads to a rather clumsy
+ − 80
formalisation of W. The need of iterating single binders is also one reason
+ − 81
why Nominal Isabelle and similar theorem provers that only provide
+ − 82
mechanisms for binding single variables have not fared extremely well with the
+ − 83
more advanced tasks in the POPLmark challenge \cite{challenge05}, because
+ − 84
also there one would like to bind multiple variables at once.
1520
+ − 85
1577
+ − 86
Binding multiple variables has interesting properties that cannot be captured
2176
+ − 87
easily by iterating single binders. For example in the case of type-schemes we do not
1587
+ − 88
want to make a distinction about the order of the bound variables. Therefore
2341
+ − 89
we would like to regard the following two type-schemes as $\alpha$-equivalent
1572
+ − 90
%
+ − 91
\begin{equation}\label{ex1}
2346
+ − 92
@{text "\<forall>{x, y}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{y, x}. x \<rightarrow> y"}
1572
+ − 93
\end{equation}
1520
+ − 94
+ − 95
\noindent
1657
+ − 96
but assuming that @{text x}, @{text y} and @{text z} are distinct variables,
2341
+ − 97
the following two should \emph{not} be $\alpha$-equivalent
1572
+ − 98
%
+ − 99
\begin{equation}\label{ex2}
1667
+ − 100
@{text "\<forall>{x, y}. x \<rightarrow> y \<notapprox>\<^isub>\<alpha> \<forall>{z}. z \<rightarrow> z"}
1572
+ − 101
\end{equation}
1520
+ − 102
+ − 103
\noindent
2341
+ − 104
Moreover, we like to regard type-schemes as $\alpha$-equivalent, if they differ
1657
+ − 105
only on \emph{vacuous} binders, such as
1572
+ − 106
%
+ − 107
\begin{equation}\label{ex3}
1667
+ − 108
@{text "\<forall>{x}. x \<rightarrow> y \<approx>\<^isub>\<alpha> \<forall>{x, z}. x \<rightarrow> y"}
1572
+ − 109
\end{equation}
1485
+ − 110
1520
+ − 111
\noindent
1657
+ − 112
where @{text z} does not occur freely in the type. In this paper we will
2341
+ − 113
give a general binding mechanism and associated notion of $\alpha$-equivalence
1657
+ − 114
that can be used to faithfully represent this kind of binding in Nominal
2341
+ − 115
Isabelle. The difficulty of finding the right notion for $\alpha$-equivalence
1657
+ − 116
can be appreciated in this case by considering that the definition given by
2331
+ − 117
Leroy in \cite{Leroy92} is incorrect (it omits a side-condition).
1524
+ − 118
2341
+ − 119
However, the notion of $\alpha$-equivalence that is preserved by vacuous
1657
+ − 120
binders is not always wanted. For example in terms like
1587
+ − 121
%
1535
+ − 122
\begin{equation}\label{one}
1657
+ − 123
@{text "\<LET> x = 3 \<AND> y = 2 \<IN> x - y \<END>"}
1535
+ − 124
\end{equation}
1520
+ − 125
+ − 126
\noindent
2341
+ − 127
we might not care in which order the assignments @{text "x = 3"} and
+ − 128
\mbox{@{text "y = 2"}} are given, but it would be unusual to regard
+ − 129
\eqref{one} as $\alpha$-equivalent with
1587
+ − 130
%
1520
+ − 131
\begin{center}
1657
+ − 132
@{text "\<LET> x = 3 \<AND> y = 2 \<AND> z = loop \<IN> x - y \<END>"}
1520
+ − 133
\end{center}
+ − 134
+ − 135
\noindent
1550
+ − 136
Therefore we will also provide a separate binding mechanism for cases in
+ − 137
which the order of binders does not matter, but the ``cardinality'' of the
1535
+ − 138
binders has to agree.
1520
+ − 139
1550
+ − 140
However, we found that this is still not sufficient for dealing with
+ − 141
language constructs frequently occurring in programming language
1690
+ − 142
research. For example in @{text "\<LET>"}s containing patterns like
1587
+ − 143
%
1535
+ − 144
\begin{equation}\label{two}
1657
+ − 145
@{text "\<LET> (x, y) = (3, 2) \<IN> x - y \<END>"}
1535
+ − 146
\end{equation}
1520
+ − 147
+ − 148
\noindent
1535
+ − 149
we want to bind all variables from the pattern inside the body of the
+ − 150
$\mathtt{let}$, but we also care about the order of these variables, since
2341
+ − 151
we do not want to regard \eqref{two} as $\alpha$-equivalent with
1587
+ − 152
%
1520
+ − 153
\begin{center}
1657
+ − 154
@{text "\<LET> (y, x) = (3, 2) \<IN> x - y \<END>"}
1520
+ − 155
\end{center}
2218
+ − 156
%
1520
+ − 157
\noindent
1657
+ − 158
As a result, we provide three general binding mechanisms each of which binds
+ − 159
multiple variables at once, and let the user chose which one is intended
1711
+ − 160
when formalising a term-calculus.
1485
+ − 161
1657
+ − 162
By providing these general binding mechanisms, however, we have to work
+ − 163
around a problem that has been pointed out by Pottier \cite{Pottier06} and
+ − 164
Cheney \cite{Cheney05}: in @{text "\<LET>"}-constructs of the form
1587
+ − 165
%
1520
+ − 166
\begin{center}
1657
+ − 167
@{text "\<LET> x\<^isub>1 = t\<^isub>1 \<AND> \<dots> \<AND> x\<^isub>n = t\<^isub>n \<IN> s \<END>"}
1520
+ − 168
\end{center}
+ − 169
+ − 170
\noindent
1657
+ − 171
which bind all the @{text "x\<^isub>i"} in @{text s}, we might not care
+ − 172
about the order in which the @{text "x\<^isub>i = t\<^isub>i"} are given,
+ − 173
but we do care about the information that there are as many @{text
+ − 174
"x\<^isub>i"} as there are @{text "t\<^isub>i"}. We lose this information if
+ − 175
we represent the @{text "\<LET>"}-constructor by something like
1587
+ − 176
%
1523
+ − 177
\begin{center}
2341
+ − 178
@{text "\<LET> (\<lambda>x\<^isub>1\<dots>x\<^isub>n . s) [t\<^isub>1,\<dots>,t\<^isub>n]"}
1523
+ − 179
\end{center}
1520
+ − 180
1523
+ − 181
\noindent
2341
+ − 182
where the notation @{text "\<lambda>_ . _"} indicates that the list of @{text
+ − 183
"x\<^isub>i"} becomes bound in @{text s}. In this representation the term
+ − 184
\mbox{@{text "\<LET> (\<lambda>x . s) [t\<^isub>1, t\<^isub>2]"}} is a perfectly legal
+ − 185
instance, but the lengths of the two lists do not agree. To exclude such
+ − 186
terms, additional predicates about well-formed terms are needed in order to
+ − 187
ensure that the two lists are of equal length. This can result in very messy
+ − 188
reasoning (see for example~\cite{BengtsonParow09}). To avoid this, we will
+ − 189
allow type specifications for @{text "\<LET>"}s as follows
1587
+ − 190
%
1528
+ − 191
\begin{center}
+ − 192
\begin{tabular}{r@ {\hspace{2mm}}r@ {\hspace{2mm}}l}
1657
+ − 193
@{text trm} & @{text "::="} & @{text "\<dots>"}\\
2341
+ − 194
& @{text "|"} & @{text "\<LET> as::assn s::trm"}\hspace{4mm}
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 195
\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}\\[1mm]
1657
+ − 196
@{text assn} & @{text "::="} & @{text "\<ANIL>"}\\
2341
+ − 197
& @{text "|"} & @{text "\<ACONS> name trm assn"}
1528
+ − 198
\end{tabular}
+ − 199
\end{center}
+ − 200
+ − 201
\noindent
1657
+ − 202
where @{text assn} is an auxiliary type representing a list of assignments
+ − 203
and @{text bn} an auxiliary function identifying the variables to be bound
1687
+ − 204
by the @{text "\<LET>"}. This function can be defined by recursion over @{text
1657
+ − 205
assn} as follows
1528
+ − 206
+ − 207
\begin{center}
1657
+ − 208
@{text "bn(\<ANIL>) ="} @{term "{}"} \hspace{5mm}
+ − 209
@{text "bn(\<ACONS> x t as) = {x} \<union> bn(as)"}
1528
+ − 210
\end{center}
1523
+ − 211
1528
+ − 212
\noindent
1550
+ − 213
The scope of the binding is indicated by labels given to the types, for
1657
+ − 214
example @{text "s::trm"}, and a binding clause, in this case
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 215
\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "s"}. This binding
2346
+ − 216
clause states that all the names the function @{text
+ − 217
"bn(as)"} returns should be bound in @{text s}. This style of specifying terms and bindings is heavily
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 218
inspired by the syntax of the Ott-tool \cite{ott-jfp}.
1657
+ − 219
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 220
However, we will not be able to cope with all specifications that are
2176
+ − 221
allowed by Ott. One reason is that Ott lets the user specify ``empty''
1617
+ − 222
types like
1570
+ − 223
+ − 224
\begin{center}
1657
+ − 225
@{text "t ::= t t | \<lambda>x. t"}
1570
+ − 226
\end{center}
+ − 227
+ − 228
\noindent
1617
+ − 229
where no clause for variables is given. Arguably, such specifications make
+ − 230
some sense in the context of Coq's type theory (which Ott supports), but not
+ − 231
at all in a HOL-based environment where every datatype must have a non-empty
1719
+ − 232
set-theoretic model \cite{Berghofer99}.
1570
+ − 233
+ − 234
Another reason is that we establish the reasoning infrastructure
2341
+ − 235
for $\alpha$-\emph{equated} terms. In contrast, Ott produces a reasoning
1570
+ − 236
infrastructure in Isabelle/HOL for
2341
+ − 237
\emph{non}-$\alpha$-equated, or ``raw'', terms. While our $\alpha$-equated terms
1556
+ − 238
and the raw terms produced by Ott use names for bound variables,
2341
+ − 239
there is a key difference: working with $\alpha$-equated terms means, for example,
1693
+ − 240
that the two type-schemes
1528
+ − 241
+ − 242
\begin{center}
1667
+ − 243
@{text "\<forall>{x}. x \<rightarrow> y = \<forall>{x, z}. x \<rightarrow> y"}
1528
+ − 244
\end{center}
+ − 245
+ − 246
\noindent
2341
+ − 247
are not just $\alpha$-equal, but actually \emph{equal}! As a result, we can
+ − 248
only support specifications that make sense on the level of $\alpha$-equated
1657
+ − 249
terms (offending specifications, which for example bind a variable according
+ − 250
to a variable bound somewhere else, are not excluded by Ott, but we have
1687
+ − 251
to).
+ − 252
2341
+ − 253
Our insistence on reasoning with $\alpha$-equated terms comes from the
1657
+ − 254
wealth of experience we gained with the older version of Nominal Isabelle:
2341
+ − 255
for non-trivial properties, reasoning with $\alpha$-equated terms is much
1657
+ − 256
easier than reasoning with raw terms. The fundamental reason for this is
+ − 257
that the HOL-logic underlying Nominal Isabelle allows us to replace
+ − 258
``equals-by-equals''. In contrast, replacing
2341
+ − 259
``$\alpha$-equals-by-$\alpha$-equals'' in a representation based on raw terms
1657
+ − 260
requires a lot of extra reasoning work.
1535
+ − 261
2341
+ − 262
Although in informal settings a reasoning infrastructure for $\alpha$-equated
1657
+ − 263
terms is nearly always taken for granted, establishing it automatically in
+ − 264
the Isabelle/HOL theorem prover is a rather non-trivial task. For every
+ − 265
specification we will need to construct a type containing as elements the
2341
+ − 266
$\alpha$-equated terms. To do so, we use the standard HOL-technique of defining
1657
+ − 267
a new type by identifying a non-empty subset of an existing type. The
1667
+ − 268
construction we perform in Isabelle/HOL can be illustrated by the following picture:
1657
+ − 269
1528
+ − 270
\begin{center}
1552
+ − 271
\begin{tikzpicture}
+ − 272
%\draw[step=2mm] (-4,-1) grid (4,1);
+ − 273
+ − 274
\draw[very thick] (0.7,0.4) circle (4.25mm);
+ − 275
\draw[rounded corners=1mm, very thick] ( 0.0,-0.8) rectangle ( 1.8, 0.9);
+ − 276
\draw[rounded corners=1mm, very thick] (-1.95,0.85) rectangle (-2.85,-0.05);
+ − 277
+ − 278
\draw (-2.0, 0.845) -- (0.7,0.845);
+ − 279
\draw (-2.0,-0.045) -- (0.7,-0.045);
+ − 280
+ − 281
\draw ( 0.7, 0.4) node {\begin{tabular}{@ {}c@ {}}$\alpha$-\\[-1mm]clas.\end{tabular}};
+ − 282
\draw (-2.4, 0.4) node {\begin{tabular}{@ {}c@ {}}$\alpha$-eq.\\[-1mm]terms\end{tabular}};
+ − 283
\draw (1.8, 0.48) node[right=-0.1mm]
+ − 284
{\begin{tabular}{@ {}l@ {}}existing\\[-1mm] type\\ (sets of raw terms)\end{tabular}};
+ − 285
\draw (0.9, -0.35) node {\begin{tabular}{@ {}l@ {}}non-empty\\[-1mm]subset\end{tabular}};
+ − 286
\draw (-3.25, 0.55) node {\begin{tabular}{@ {}l@ {}}new\\[-1mm]type\end{tabular}};
+ − 287
+ − 288
\draw[<->, very thick] (-1.8, 0.3) -- (-0.1,0.3);
+ − 289
\draw (-0.95, 0.3) node[above=0mm] {isomorphism};
+ − 290
+ − 291
\end{tikzpicture}
1528
+ − 292
\end{center}
+ − 293
+ − 294
\noindent
1657
+ − 295
We take as the starting point a definition of raw terms (defined as a
2341
+ − 296
datatype in Isabelle/HOL); identify then the $\alpha$-equivalence classes in
+ − 297
the type of sets of raw terms according to our $\alpha$-equivalence relation,
+ − 298
and finally define the new type as these $\alpha$-equivalence classes
1657
+ − 299
(non-emptiness is satisfied whenever the raw terms are definable as datatype
2341
+ − 300
in Isabelle/HOL and the property that our relation for $\alpha$-equivalence is
1657
+ − 301
indeed an equivalence relation).
1556
+ − 302
1657
+ − 303
The fact that we obtain an isomorphism between the new type and the
+ − 304
non-empty subset shows that the new type is a faithful representation of
2341
+ − 305
$\alpha$-equated terms. That is not the case for example for terms using the
1657
+ − 306
locally nameless representation of binders \cite{McKinnaPollack99}: in this
+ − 307
representation there are ``junk'' terms that need to be excluded by
+ − 308
reasoning about a well-formedness predicate.
1556
+ − 309
1657
+ − 310
The problem with introducing a new type in Isabelle/HOL is that in order to
+ − 311
be useful, a reasoning infrastructure needs to be ``lifted'' from the
+ − 312
underlying subset to the new type. This is usually a tricky and arduous
+ − 313
task. To ease it, we re-implemented in Isabelle/HOL the quotient package
+ − 314
described by Homeier \cite{Homeier05} for the HOL4 system. This package
+ − 315
allows us to lift definitions and theorems involving raw terms to
2341
+ − 316
definitions and theorems involving $\alpha$-equated terms. For example if we
1657
+ − 317
define the free-variable function over raw lambda-terms
1577
+ − 318
+ − 319
\begin{center}
1657
+ − 320
@{text "fv(x) = {x}"}\hspace{10mm}
+ − 321
@{text "fv(t\<^isub>1 t\<^isub>2) = fv(t\<^isub>1) \<union> fv(t\<^isub>2)"}\\[1mm]
+ − 322
@{text "fv(\<lambda>x.t) = fv(t) - {x}"}
1577
+ − 323
\end{center}
+ − 324
+ − 325
\noindent
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 326
then with the help of the quotient package we can obtain a function @{text "fv\<^sup>\<alpha>"}
2341
+ − 327
operating on quotients, or $\alpha$-equivalence classes of lambda-terms. This
1628
+ − 328
lifted function is characterised by the equations
1577
+ − 329
+ − 330
\begin{center}
1657
+ − 331
@{text "fv\<^sup>\<alpha>(x) = {x}"}\hspace{10mm}
+ − 332
@{text "fv\<^sup>\<alpha>(t\<^isub>1 t\<^isub>2) = fv\<^sup>\<alpha>(t\<^isub>1) \<union> fv\<^sup>\<alpha>(t\<^isub>2)"}\\[1mm]
+ − 333
@{text "fv\<^sup>\<alpha>(\<lambda>x.t) = fv\<^sup>\<alpha>(t) - {x}"}
1577
+ − 334
\end{center}
+ − 335
+ − 336
\noindent
+ − 337
(Note that this means also the term-constructors for variables, applications
+ − 338
and lambda are lifted to the quotient level.) This construction, of course,
2341
+ − 339
only works if $\alpha$-equivalence is indeed an equivalence relation, and the
+ − 340
``raw'' definitions and theorems are respectful w.r.t.~$\alpha$-equivalence.
1694
+ − 341
For example, we will not be able to lift a bound-variable function. Although
+ − 342
this function can be defined for raw terms, it does not respect
2341
+ − 343
$\alpha$-equivalence and therefore cannot be lifted. To sum up, every lifting
1694
+ − 344
of theorems to the quotient level needs proofs of some respectfulness
+ − 345
properties (see \cite{Homeier05}). In the paper we show that we are able to
2128
+ − 346
automate these proofs and as a result can automatically establish a reasoning
2341
+ − 347
infrastructure for $\alpha$-equated terms.
1667
+ − 348
+ − 349
The examples we have in mind where our reasoning infrastructure will be
1694
+ − 350
helpful includes the term language of System @{text "F\<^isub>C"}, also
+ − 351
known as Core-Haskell (see Figure~\ref{corehas}). This term language
1711
+ − 352
involves patterns that have lists of type-, coercion- and term-variables,
1703
+ − 353
all of which are bound in @{text "\<CASE>"}-expressions. One
1926
+ − 354
feature is that we do not know in advance how many variables need to
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 355
be bound. Another is that each bound variable comes with a kind or type
1694
+ − 356
annotation. Representing such binders with single binders and reasoning
+ − 357
about them in a theorem prover would be a major pain. \medskip
1506
+ − 358
1528
+ − 359
\noindent
2347
+ − 360
{\bf Contributions:} We provide three novel definitions for when terms
2341
+ − 361
involving general binders are $\alpha$-equivalent. These definitions are
1607
+ − 362
inspired by earlier work of Pitts \cite{Pitts04}. By means of automatic
2341
+ − 363
proofs, we establish a reasoning infrastructure for $\alpha$-equated
1528
+ − 364
terms, including properties about support, freshness and equality
2341
+ − 365
conditions for $\alpha$-equated terms. We are also able to derive strong
2218
+ − 366
induction principles that have the variable convention already built in.
2343
+ − 367
The method behind our specification of general binders is taken
2346
+ − 368
from the Ott-tool, but we introduce crucial restrictions, and also extensions, so
2343
+ − 369
that our specifications make sense for reasoning about $\alpha$-equated terms.
2341
+ − 370
1667
+ − 371
+ − 372
\begin{figure}
1687
+ − 373
\begin{boxedminipage}{\linewidth}
+ − 374
\begin{center}
1699
+ − 375
\begin{tabular}{r@ {\hspace{1mm}}r@ {\hspace{2mm}}l}
1690
+ − 376
\multicolumn{3}{@ {}l}{Type Kinds}\\
1699
+ − 377
@{text "\<kappa>"} & @{text "::="} & @{text "\<star> | \<kappa>\<^isub>1 \<rightarrow> \<kappa>\<^isub>2"}\smallskip\\
1690
+ − 378
\multicolumn{3}{@ {}l}{Coercion Kinds}\\
1699
+ − 379
@{text "\<iota>"} & @{text "::="} & @{text "\<sigma>\<^isub>1 \<sim> \<sigma>\<^isub>2"}\smallskip\\
1690
+ − 380
\multicolumn{3}{@ {}l}{Types}\\
1694
+ − 381
@{text "\<sigma>"} & @{text "::="} & @{text "a | T | \<sigma>\<^isub>1 \<sigma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<sigma>"}}$@{text "\<^sup>n"}
1699
+ − 382
@{text "| \<forall>a:\<kappa>. \<sigma> | \<iota> \<Rightarrow> \<sigma>"}\smallskip\\
1690
+ − 383
\multicolumn{3}{@ {}l}{Coercion Types}\\
1694
+ − 384
@{text "\<gamma>"} & @{text "::="} & @{text "c | C | \<gamma>\<^isub>1 \<gamma>\<^isub>2 | S\<^isub>n"}$\;\overline{@{text "\<gamma>"}}$@{text "\<^sup>n"}
1699
+ − 385
@{text "| \<forall>c:\<iota>. \<gamma> | \<iota> \<Rightarrow> \<gamma> "}\\
+ − 386
& @{text "|"} & @{text "refl \<sigma> | sym \<gamma> | \<gamma>\<^isub>1 \<circ> \<gamma>\<^isub>2 | \<gamma> @ \<sigma> | left \<gamma> | right \<gamma>"}\\
+ − 387
& @{text "|"} & @{text "\<gamma>\<^isub>1 \<sim> \<gamma>\<^isub>2 | rightc \<gamma> | leftc \<gamma> | \<gamma>\<^isub>1 \<triangleright> \<gamma>\<^isub>2"}\smallskip\\
1690
+ − 388
\multicolumn{3}{@ {}l}{Terms}\\
1699
+ − 389
@{text "e"} & @{text "::="} & @{text "x | K | \<Lambda>a:\<kappa>. e | \<Lambda>c:\<iota>. e | e \<sigma> | e \<gamma>"}\\
+ − 390
& @{text "|"} & @{text "\<lambda>x:\<sigma>. e | e\<^isub>1 e\<^isub>2 | \<LET> x:\<sigma> = e\<^isub>1 \<IN> e\<^isub>2"}\\
+ − 391
& @{text "|"} & @{text "\<CASE> e\<^isub>1 \<OF>"}$\;\overline{@{text "p \<rightarrow> e\<^isub>2"}}$ @{text "| e \<triangleright> \<gamma>"}\smallskip\\
1690
+ − 392
\multicolumn{3}{@ {}l}{Patterns}\\
1699
+ − 393
@{text "p"} & @{text "::="} & @{text "K"}$\;\overline{@{text "a:\<kappa>"}}\;\overline{@{text "c:\<iota>"}}\;\overline{@{text "x:\<sigma>"}}$\smallskip\\
1690
+ − 394
\multicolumn{3}{@ {}l}{Constants}\\
1699
+ − 395
& @{text C} & coercion constants\\
+ − 396
& @{text T} & value type constructors\\
+ − 397
& @{text "S\<^isub>n"} & n-ary type functions (which need to be fully applied)\\
+ − 398
& @{text K} & data constructors\smallskip\\
1690
+ − 399
\multicolumn{3}{@ {}l}{Variables}\\
1699
+ − 400
& @{text a} & type variables\\
+ − 401
& @{text c} & coercion variables\\
+ − 402
& @{text x} & term variables\\
1687
+ − 403
\end{tabular}
+ − 404
\end{center}
+ − 405
\end{boxedminipage}
2345
+ − 406
\caption{The System @{text "F\<^isub>C"}
1699
+ − 407
\cite{CoreHaskell}, also often referred to as \emph{Core-Haskell}. In this
2345
+ − 408
version of @{text "F\<^isub>C"} we made a modification by separating the
1711
+ − 409
grammars for type kinds and coercion kinds, as well as for types and coercion
1702
+ − 410
types. For this paper the interesting term-constructor is @{text "\<CASE>"},
+ − 411
which binds multiple type-, coercion- and term-variables.\label{corehas}}
1667
+ − 412
\end{figure}
1485
+ − 413
*}
+ − 414
1493
+ − 415
section {* A Short Review of the Nominal Logic Work *}
+ − 416
+ − 417
text {*
1556
+ − 418
At its core, Nominal Isabelle is an adaption of the nominal logic work by
+ − 419
Pitts \cite{Pitts03}. This adaptation for Isabelle/HOL is described in
1694
+ − 420
\cite{HuffmanUrban10} (including proofs). We shall briefly review this work
+ − 421
to aid the description of what follows.
+ − 422
1711
+ − 423
Two central notions in the nominal logic work are sorted atoms and
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 424
sort-respecting permutations of atoms. We will use the letters @{text "a,
1711
+ − 425
b, c, \<dots>"} to stand for atoms and @{text "p, q, \<dots>"} to stand for
2347
+ − 426
permutations. The purpose of atoms is to represent variables, be they bound or free.
+ − 427
The sorts of atoms can be used to represent different kinds of
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 428
variables, such as the term-, coercion- and type-variables in Core-Haskell.
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 429
It is assumed that there is an infinite supply of atoms for each
1847
+ − 430
sort. However, in the interest of brevity, we shall restrict ourselves
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 431
in what follows to only one sort of atoms.
1493
+ − 432
+ − 433
Permutations are bijective functions from atoms to atoms that are
+ − 434
the identity everywhere except on a finite number of atoms. There is a
+ − 435
two-place permutation operation written
1617
+ − 436
%
1703
+ − 437
\begin{center}
+ − 438
@{text "_ \<bullet> _ :: perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
+ − 439
\end{center}
1493
+ − 440
+ − 441
\noindent
1628
+ − 442
in which the generic type @{text "\<beta>"} stands for the type of the object
1694
+ − 443
over which the permutation
1617
+ − 444
acts. In Nominal Isabelle, the identity permutation is written as @{term "0::perm"},
1690
+ − 445
the composition of two permutations @{term p} and @{term q} as \mbox{@{term "p + q"}},
1570
+ − 446
and the inverse permutation of @{term p} as @{text "- p"}. The permutation
1890
+ − 447
operation is defined by induction over the type-hierarchy \cite{HuffmanUrban10};
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 448
for example permutations acting on products, lists, sets, functions and booleans is
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 449
given by:
1702
+ − 450
%
1703
+ − 451
\begin{equation}\label{permute}
1694
+ − 452
\mbox{\begin{tabular}{@ {}cc@ {}}
1690
+ − 453
\begin{tabular}{@ {}l@ {}}
+ − 454
@{thm permute_prod.simps[no_vars, THEN eq_reflection]}\\[2mm]
+ − 455
@{thm permute_list.simps(1)[no_vars, THEN eq_reflection]}\\
+ − 456
@{thm permute_list.simps(2)[no_vars, THEN eq_reflection]}\\
+ − 457
\end{tabular} &
+ − 458
\begin{tabular}{@ {}l@ {}}
+ − 459
@{thm permute_set_eq[no_vars, THEN eq_reflection]}\\
1694
+ − 460
@{text "p \<bullet> f \<equiv> \<lambda>x. p \<bullet> (f (- p \<bullet> x))"}\\
1690
+ − 461
@{thm permute_bool_def[no_vars, THEN eq_reflection]}\\
+ − 462
\end{tabular}
1694
+ − 463
\end{tabular}}
+ − 464
\end{equation}
1690
+ − 465
+ − 466
\noindent
1730
+ − 467
Concrete permutations in Nominal Isabelle are built up from swappings,
+ − 468
written as \mbox{@{text "(a b)"}}, which are permutations that behave
+ − 469
as follows:
1617
+ − 470
%
1703
+ − 471
\begin{center}
+ − 472
@{text "(a b) = \<lambda>c. if a = c then b else if b = c then a else c"}
+ − 473
\end{center}
+ − 474
1570
+ − 475
The most original aspect of the nominal logic work of Pitts is a general
1703
+ − 476
definition for the notion of the ``set of free variables of an object @{text
1570
+ − 477
"x"}''. This notion, written @{term "supp x"}, is general in the sense that
2341
+ − 478
it applies not only to lambda-terms ($\alpha$-equated or not), but also to lists,
1570
+ − 479
products, sets and even functions. The definition depends only on the
+ − 480
permutation operation and on the notion of equality defined for the type of
+ − 481
@{text x}, namely:
1617
+ − 482
%
1703
+ − 483
\begin{equation}\label{suppdef}
+ − 484
@{thm supp_def[no_vars, THEN eq_reflection]}
+ − 485
\end{equation}
1493
+ − 486
+ − 487
\noindent
+ − 488
There is also the derived notion for when an atom @{text a} is \emph{fresh}
+ − 489
for an @{text x}, defined as
1617
+ − 490
%
1703
+ − 491
\begin{center}
+ − 492
@{thm fresh_def[no_vars]}
+ − 493
\end{center}
1493
+ − 494
+ − 495
\noindent
1954
+ − 496
We use for sets of atoms the abbreviation
1703
+ − 497
@{thm (lhs) fresh_star_def[no_vars]}, defined as
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 498
@{thm (rhs) fresh_star_def[no_vars]}.
1493
+ − 499
A striking consequence of these definitions is that we can prove
+ − 500
without knowing anything about the structure of @{term x} that
2140
+ − 501
swapping two fresh atoms, say @{text a} and @{text b}, leaves
+ − 502
@{text x} unchanged:
1506
+ − 503
1711
+ − 504
\begin{property}\label{swapfreshfresh}
1506
+ − 505
@{thm[mode=IfThen] swap_fresh_fresh[no_vars]}
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 506
\end{property}
1506
+ − 507
1711
+ − 508
While often the support of an object can be relatively easily
1730
+ − 509
described, for example for atoms, products, lists, function applications,
2341
+ − 510
booleans and permutations as follows
1690
+ − 511
%
+ − 512
\begin{eqnarray}
1703
+ − 513
@{term "supp a"} & = & @{term "{a}"}\\
1690
+ − 514
@{term "supp (x, y)"} & = & @{term "supp x \<union> supp y"}\\
+ − 515
@{term "supp []"} & = & @{term "{}"}\\
1711
+ − 516
@{term "supp (x#xs)"} & = & @{term "supp x \<union> supp xs"}\\
1730
+ − 517
@{text "supp (f x)"} & @{text "\<subseteq>"} & @{term "supp f \<union> supp x"}\label{suppfun}\\
1703
+ − 518
@{term "supp b"} & = & @{term "{}"}\\
+ − 519
@{term "supp p"} & = & @{term "{a. p \<bullet> a \<noteq> a}"}
1690
+ − 520
\end{eqnarray}
+ − 521
+ − 522
\noindent
2347
+ − 523
in some cases it can be difficult to characterise the support precisely, and
1730
+ − 524
only an approximation can be established (see \eqref{suppfun} above). Reasoning about
+ − 525
such approximations can be simplified with the notion \emph{supports}, defined
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 526
as follows:
1693
+ − 527
+ − 528
\begin{defn}
+ − 529
A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b}
+ − 530
not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
+ − 531
\end{defn}
1690
+ − 532
1693
+ − 533
\noindent
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 534
The main point of @{text supports} is that we can establish the following
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 535
two properties.
1693
+ − 536
1703
+ − 537
\begin{property}\label{supportsprop}
2341
+ − 538
Given a set @{text "as"} of atoms.
+ − 539
{\it i)} @{thm[mode=IfThen] supp_is_subset[where S="as", no_vars]}
1693
+ − 540
{\it ii)} @{thm supp_supports[no_vars]}.
+ − 541
\end{property}
+ − 542
+ − 543
Another important notion in the nominal logic work is \emph{equivariance}.
1703
+ − 544
For a function @{text f}, say of type @{text "\<alpha> \<Rightarrow> \<beta>"}, to be equivariant
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 545
it is required that every permutation leaves @{text f} unchanged, that is
1711
+ − 546
%
+ − 547
\begin{equation}\label{equivariancedef}
+ − 548
@{term "\<forall>p. p \<bullet> f = f"}
+ − 549
\end{equation}
+ − 550
+ − 551
\noindent or equivalently that a permutation applied to the application
1730
+ − 552
@{text "f x"} can be moved to the argument @{text x}. That means for equivariant
2341
+ − 553
functions @{text f}, we have for all permutations @{text p}:
1703
+ − 554
%
+ − 555
\begin{equation}\label{equivariance}
1711
+ − 556
@{text "p \<bullet> f = f"} \;\;\;\textit{if and only if}\;\;\;
+ − 557
@{text "p \<bullet> (f x) = f (p \<bullet> x)"}
1703
+ − 558
\end{equation}
1694
+ − 559
+ − 560
\noindent
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 561
From property \eqref{equivariancedef} and the definition of @{text supp}, we
2175
+ − 562
can easily deduce that equivariant functions have empty support. There is
1771
+ − 563
also a similar notion for equivariant relations, say @{text R}, namely the property
+ − 564
that
+ − 565
%
+ − 566
\begin{center}
2341
+ − 567
@{text "x R y"} \;\;\textit{implies}\;\; @{text "(p \<bullet> x) R (p \<bullet> y)"}
1771
+ − 568
\end{center}
1711
+ − 569
2343
+ − 570
Finally, the nominal logic work provides us with general means for renaming
1711
+ − 571
binders. While in the older version of Nominal Isabelle, we used extensively
2343
+ − 572
Property~\ref{swapfreshfresh} to rename single binders, this property
2341
+ − 573
proved too unwieldy for dealing with multiple binders. For such binders the
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 574
following generalisations turned out to be easier to use.
1711
+ − 575
+ − 576
\begin{property}\label{supppermeq}
+ − 577
@{thm[mode=IfThen] supp_perm_eq[no_vars]}
+ − 578
\end{property}
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 579
1747
+ − 580
\begin{property}\label{avoiding}
1716
+ − 581
For a finite set @{text as} and a finitely supported @{text x} with
+ − 582
@{term "as \<sharp>* x"} and also a finitely supported @{text c}, there
+ − 583
exists a permutation @{text p} such that @{term "(p \<bullet> as) \<sharp>* c"} and
1711
+ − 584
@{term "supp x \<sharp>* p"}.
+ − 585
\end{property}
+ − 586
+ − 587
\noindent
1716
+ − 588
The idea behind the second property is that given a finite set @{text as}
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 589
of binders (being bound, or fresh, in @{text x} is ensured by the
1716
+ − 590
assumption @{term "as \<sharp>* x"}), then there exists a permutation @{text p} such that
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 591
the renamed binders @{term "p \<bullet> as"} avoid @{text c} (which can be arbitrarily chosen
1730
+ − 592
as long as it is finitely supported) and also @{text "p"} does not affect anything
1711
+ − 593
in the support of @{text x} (that is @{term "supp x \<sharp>* p"}). The last
+ − 594
fact and Property~\ref{supppermeq} allow us to ``rename'' just the binders
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 595
@{text as} in @{text x}, because @{term "p \<bullet> x = x"}.
1711
+ − 596
2128
+ − 597
Most properties given in this section are described in detail in \cite{HuffmanUrban10}
1737
+ − 598
and of course all are formalised in Isabelle/HOL. In the next sections we will make
2341
+ − 599
extensive use of these properties in order to define $\alpha$-equivalence in
1737
+ − 600
the presence of multiple binders.
1493
+ − 601
*}
+ − 602
1485
+ − 603
2345
+ − 604
section {* General Bindings\label{sec:binders} *}
1485
+ − 605
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 606
text {*
1587
+ − 607
In Nominal Isabelle, the user is expected to write down a specification of a
+ − 608
term-calculus and then a reasoning infrastructure is automatically derived
1617
+ − 609
from this specification (remember that Nominal Isabelle is a definitional
1587
+ − 610
extension of Isabelle/HOL, which does not introduce any new axioms).
1579
+ − 611
1657
+ − 612
In order to keep our work with deriving the reasoning infrastructure
+ − 613
manageable, we will wherever possible state definitions and perform proofs
2341
+ − 614
on the ``user-level'' of Isabelle/HOL, as opposed to write custom ML-code that
1657
+ − 615
generates them anew for each specification. To that end, we will consider
+ − 616
first pairs @{text "(as, x)"} of type @{text "(atom set) \<times> \<beta>"}. These pairs
2128
+ − 617
are intended to represent the abstraction, or binding, of the set of atoms @{text
1657
+ − 618
"as"} in the body @{text "x"}.
1570
+ − 619
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 620
The first question we have to answer is when two pairs @{text "(as, x)"} and
2341
+ − 621
@{text "(bs, y)"} are $\alpha$-equivalent? (For the moment we are interested in
+ − 622
the notion of $\alpha$-equivalence that is \emph{not} preserved by adding
+ − 623
vacuous binders.) To answer this question, we identify four conditions: {\it (i)}
2347
+ − 624
given a free-atom function @{text "fa"} of type \mbox{@{text "\<beta> \<Rightarrow> atom
1657
+ − 625
set"}}, then @{text x} and @{text y} need to have the same set of free
2347
+ − 626
atomss; moreover there must be a permutation @{text p} such that {\it
+ − 627
(ii)} @{text p} leaves the free atoms of @{text x} and @{text y} unchanged, but
2341
+ − 628
{\it (iii)} ``moves'' their bound names so that we obtain modulo a relation,
+ − 629
say \mbox{@{text "_ R _"}}, two equivalent terms. We also require that {\it (iv)}
1662
+ − 630
@{text p} makes the sets of abstracted atoms @{text as} and @{text bs} equal. The
2343
+ − 631
requirements {\it (i)} to {\it (iv)} can be stated formally as follows:
1556
+ − 632
%
1572
+ − 633
\begin{equation}\label{alphaset}
2341
+ − 634
\begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
2347
+ − 635
\multicolumn{3}{l}{@{term "(as, x) \<approx>gen R fa p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
+ − 636
& @{term "fa(x) - as = fa(y) - bs"} & \mbox{\it (i)}\\
+ − 637
@{text "\<and>"} & @{term "(fa(x) - as) \<sharp>* p"} & \mbox{\it (ii)}\\
2341
+ − 638
@{text "\<and>"} & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
+ − 639
@{text "\<and>"} & @{term "(p \<bullet> as) = bs"} & \mbox{\it (iv)}\\
1572
+ − 640
\end{array}
1556
+ − 641
\end{equation}
+ − 642
+ − 643
\noindent
2175
+ − 644
Note that this relation depends on the permutation @{text
2341
+ − 645
"p"}; $\alpha$-equivalence between two pairs is then the relation where we
1657
+ − 646
existentially quantify over this @{text "p"}. Also note that the relation is
2347
+ − 647
dependent on a free-atom function @{text "fa"} and a relation @{text
1657
+ − 648
"R"}. The reason for this extra generality is that we will use
2341
+ − 649
$\approx_{\,\textit{set}}$ for both ``raw'' terms and $\alpha$-equated terms. In
+ − 650
the latter case, @{text R} will be replaced by equality @{text "="} and we
2347
+ − 651
will prove that @{text "fa"} is equal to @{text "supp"}.
1572
+ − 652
+ − 653
The definition in \eqref{alphaset} does not make any distinction between the
2347
+ − 654
order of abstracted atoms. If we want this, then we can define $\alpha$-equivalence
1579
+ − 655
for pairs of the form \mbox{@{text "(as, x)"}} with type @{text "(atom list) \<times> \<beta>"}
+ − 656
as follows
1572
+ − 657
%
+ − 658
\begin{equation}\label{alphalist}
2341
+ − 659
\begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
2347
+ − 660
\multicolumn{2}{l}{@{term "(as, x) \<approx>lst R fa p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
+ − 661
& @{term "fa(x) - (set as) = fa(y) - (set bs)"} & \mbox{\it (i)}\\
+ − 662
\wedge & @{term "(fa(x) - set as) \<sharp>* p"} & \mbox{\it (ii)}\\
2341
+ − 663
\wedge & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
+ − 664
\wedge & @{term "(p \<bullet> as) = bs"} & \mbox{\it (iv)}\\
1572
+ − 665
\end{array}
+ − 666
\end{equation}
+ − 667
+ − 668
\noindent
2341
+ − 669
where @{term set} is the function that coerces a list of atoms into a set of atoms.
1752
+ − 670
Now the last clause ensures that the order of the binders matters (since @{text as}
+ − 671
and @{text bs} are lists of atoms).
1556
+ − 672
1657
+ − 673
If we do not want to make any difference between the order of binders \emph{and}
1579
+ − 674
also allow vacuous binders, then we keep sets of binders, but drop the fourth
+ − 675
condition in \eqref{alphaset}:
1572
+ − 676
%
1579
+ − 677
\begin{equation}\label{alphares}
2341
+ − 678
\begin{array}{@ {\hspace{10mm}}r@ {\hspace{2mm}}l@ {\hspace{4mm}}r}
2347
+ − 679
\multicolumn{2}{l}{@{term "(as, x) \<approx>res R fa p (bs, y)"}\hspace{2mm}@{text "\<equiv>"}}\\[1mm]
+ − 680
& @{term "fa(x) - as = fa(y) - bs"} & \mbox{\it (i)}\\
+ − 681
\wedge & @{term "(fa(x) - as) \<sharp>* p"} & \mbox{\it (ii)}\\
2341
+ − 682
\wedge & @{text "(p \<bullet> x) R y"} & \mbox{\it (iii)}\\
1572
+ − 683
\end{array}
+ − 684
\end{equation}
1556
+ − 685
2345
+ − 686
It might be useful to consider first some examples about how these definitions
2341
+ − 687
of $\alpha$-equivalence pan out in practice. For this consider the case of
2347
+ − 688
abstracting a set of atoms over types (as in type-schemes). We set
+ − 689
@{text R} to be the usual equality @{text "="} and for @{text "fa(T)"} we
2341
+ − 690
define
1572
+ − 691
+ − 692
\begin{center}
2347
+ − 693
@{text "fa(x) = {x}"} \hspace{5mm} @{text "fa(T\<^isub>1 \<rightarrow> T\<^isub>2) = fa(T\<^isub>1) \<union> fa(T\<^isub>2)"}
1572
+ − 694
\end{center}
+ − 695
+ − 696
\noindent
1657
+ − 697
Now recall the examples shown in \eqref{ex1}, \eqref{ex2} and
1687
+ − 698
\eqref{ex3}. It can be easily checked that @{text "({x, y}, x \<rightarrow> y)"} and
2341
+ − 699
@{text "({y, x}, y \<rightarrow> x)"} are $\alpha$-equivalent according to
+ − 700
$\approx_{\,\textit{set}}$ and $\approx_{\,\textit{res}}$ by taking @{text p} to
2175
+ − 701
be the swapping @{term "(x \<rightleftharpoons> y)"}. In case of @{text "x \<noteq> y"}, then @{text
2341
+ − 702
"([x, y], x \<rightarrow> y)"} $\not\approx_{\,\textit{list}}$ @{text "([y, x], x \<rightarrow> y)"}
2175
+ − 703
since there is no permutation that makes the lists @{text "[x, y]"} and
+ − 704
@{text "[y, x]"} equal, and also leaves the type \mbox{@{text "x \<rightarrow> y"}}
2341
+ − 705
unchanged. Another example is @{text "({x}, x)"} $\approx_{\,\textit{res}}$
2175
+ − 706
@{text "({x, y}, x)"} which holds by taking @{text p} to be the identity
+ − 707
permutation. However, if @{text "x \<noteq> y"}, then @{text "({x}, x)"}
2341
+ − 708
$\not\approx_{\,\textit{set}}$ @{text "({x, y}, x)"} since there is no
2175
+ − 709
permutation that makes the sets @{text "{x}"} and @{text "{x, y}"} equal
2341
+ − 710
(similarly for $\approx_{\,\textit{list}}$). It can also relatively easily be
+ − 711
shown that all three notions of $\alpha$-equivalence coincide, if we only
2175
+ − 712
abstract a single atom.
1579
+ − 713
1730
+ − 714
In the rest of this section we are going to introduce three abstraction
+ − 715
types. For this we define
1657
+ − 716
%
+ − 717
\begin{equation}
+ − 718
@{term "abs_set (as, x) (bs, x) \<equiv> \<exists>p. alpha_gen (as, x) equal supp p (bs, x)"}
+ − 719
\end{equation}
+ − 720
1579
+ − 721
\noindent
2341
+ − 722
(similarly for $\approx_{\,\textit{abs\_res}}$
+ − 723
and $\approx_{\,\textit{abs\_list}}$). We can show that these relations are equivalence
1687
+ − 724
relations and equivariant.
1579
+ − 725
1739
+ − 726
\begin{lemma}\label{alphaeq}
2341
+ − 727
The relations $\approx_{\,\textit{abs\_set}}$, $\approx_{\,\textit{abs\_list}}$
+ − 728
and $\approx_{\,\textit{abs\_res}}$ are equivalence relations, and if @{term
1739
+ − 729
"abs_set (as, x) (bs, y)"} then also @{term "abs_set (p \<bullet> as, p \<bullet> x) (p \<bullet>
+ − 730
bs, p \<bullet> y)"} (similarly for the other two relations).
1657
+ − 731
\end{lemma}
+ − 732
+ − 733
\begin{proof}
+ − 734
Reflexivity is by taking @{text "p"} to be @{text "0"}. For symmetry we have
+ − 735
a permutation @{text p} and for the proof obligation take @{term "-p"}. In case
1662
+ − 736
of transitivity, we have two permutations @{text p} and @{text q}, and for the
+ − 737
proof obligation use @{text "q + p"}. All conditions are then by simple
1657
+ − 738
calculations.
+ − 739
\end{proof}
+ − 740
+ − 741
\noindent
2343
+ − 742
This lemma allows us to use our quotient package for introducing
1662
+ − 743
new types @{text "\<beta> abs_set"}, @{text "\<beta> abs_res"} and @{text "\<beta> abs_list"}
2341
+ − 744
representing $\alpha$-equivalence classes of pairs of type
2128
+ − 745
@{text "(atom set) \<times> \<beta>"} (in the first two cases) and of type @{text "(atom list) \<times> \<beta>"}
+ − 746
(in the third case).
1954
+ − 747
The elements in these types will be, respectively, written as:
1657
+ − 748
+ − 749
\begin{center}
+ − 750
@{term "Abs as x"} \hspace{5mm}
1954
+ − 751
@{term "Abs_res as x"} \hspace{5mm}
+ − 752
@{term "Abs_lst as x"}
1657
+ − 753
\end{center}
+ − 754
1662
+ − 755
\noindent
1859
+ − 756
indicating that a set (or list) of atoms @{text as} is abstracted in @{text x}. We will
1716
+ − 757
call the types \emph{abstraction types} and their elements
1752
+ − 758
\emph{abstractions}. The important property we need to derive is the support of
1737
+ − 759
abstractions, namely:
1662
+ − 760
1687
+ − 761
\begin{thm}[Support of Abstractions]\label{suppabs}
1703
+ − 762
Assuming @{text x} has finite support, then\\[-6mm]
1662
+ − 763
\begin{center}
1687
+ − 764
\begin{tabular}{l@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
+ − 765
@{thm (lhs) supp_abs(1)[no_vars]} & $=$ & @{thm (rhs) supp_abs(1)[no_vars]}\\
1954
+ − 766
@{thm (lhs) supp_abs(2)[no_vars]} & $=$ & @{thm (rhs) supp_abs(2)[no_vars]}\\
+ − 767
@{thm (lhs) supp_abs(3)[where bs="as", no_vars]} & $=$ & @{thm (rhs) supp_abs(3)[where bs="as", no_vars]}
1687
+ − 768
\end{tabular}
1662
+ − 769
\end{center}
1687
+ − 770
\end{thm}
1662
+ − 771
+ − 772
\noindent
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 773
Below we will show the first equation. The others
1730
+ − 774
follow by similar arguments. By definition of the abstraction type @{text "abs_set"}
1687
+ − 775
we have
+ − 776
%
+ − 777
\begin{equation}\label{abseqiff}
1703
+ − 778
@{thm (lhs) abs_eq_iff(1)[where bs="as" and cs="bs", no_vars]} \;\;\text{if and only if}\;\;
1687
+ − 779
@{thm (rhs) abs_eq_iff(1)[where bs="as" and cs="bs", no_vars]}
+ − 780
\end{equation}
+ − 781
+ − 782
\noindent
1703
+ − 783
and also
+ − 784
%
2128
+ − 785
\begin{equation}\label{absperm}
1703
+ − 786
@{thm permute_Abs[no_vars]}
+ − 787
\end{equation}
1662
+ − 788
1703
+ − 789
\noindent
1716
+ − 790
The second fact derives from the definition of permutations acting on pairs
2341
+ − 791
\eqref{permute} and $\alpha$-equivalence being equivariant
1716
+ − 792
(see Lemma~\ref{alphaeq}). With these two facts at our disposal, we can show
2341
+ − 793
the following lemma about swapping two atoms in an abstraction.
1703
+ − 794
1662
+ − 795
\begin{lemma}
1716
+ − 796
@{thm[mode=IfThen] abs_swap1(1)[where bs="as", no_vars]}
1662
+ − 797
\end{lemma}
+ − 798
+ − 799
\begin{proof}
1730
+ − 800
This lemma is straightforward using \eqref{abseqiff} and observing that
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 801
the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) = (supp x - as)"}.
1730
+ − 802
Moreover @{text supp} and set difference are equivariant (see \cite{HuffmanUrban10}).
1662
+ − 803
\end{proof}
1587
+ − 804
1687
+ − 805
\noindent
2163
+ − 806
Assuming that @{text "x"} has finite support, this lemma together
+ − 807
with \eqref{absperm} allows us to show
1687
+ − 808
%
+ − 809
\begin{equation}\label{halfone}
+ − 810
@{thm abs_supports(1)[no_vars]}
+ − 811
\end{equation}
+ − 812
+ − 813
\noindent
1716
+ − 814
which by Property~\ref{supportsprop} gives us ``one half'' of
1752
+ − 815
Theorem~\ref{suppabs}. The ``other half'' is a bit more involved. To establish
1716
+ − 816
it, we use a trick from \cite{Pitts04} and first define an auxiliary
1737
+ − 817
function @{text aux}, taking an abstraction as argument:
1687
+ − 818
%
+ − 819
\begin{center}
1703
+ − 820
@{thm supp_gen.simps[THEN eq_reflection, no_vars]}
1687
+ − 821
\end{center}
+ − 822
1703
+ − 823
\noindent
+ − 824
Using the second equation in \eqref{equivariance}, we can show that
1716
+ − 825
@{text "aux"} is equivariant (since @{term "p \<bullet> (supp x - as) =
+ − 826
(supp (p \<bullet> x)) - (p \<bullet> as)"}) and therefore has empty support.
+ − 827
This in turn means
1703
+ − 828
%
+ − 829
\begin{center}
1716
+ − 830
@{term "supp (supp_gen (Abs as x)) \<subseteq> supp (Abs as x)"}
1703
+ − 831
\end{center}
1687
+ − 832
+ − 833
\noindent
1954
+ − 834
using \eqref{suppfun}. Assuming @{term "supp x - as"} is a finite set,
1716
+ − 835
we further obtain
1703
+ − 836
%
+ − 837
\begin{equation}\label{halftwo}
+ − 838
@{thm (concl) supp_abs_subset1(1)[no_vars]}
+ − 839
\end{equation}
+ − 840
+ − 841
\noindent
1737
+ − 842
since for finite sets of atoms, @{text "bs"}, we have
+ − 843
@{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}.
+ − 844
Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes
+ − 845
Theorem~\ref{suppabs}.
1703
+ − 846
1737
+ − 847
The method of first considering abstractions of the
1956
+ − 848
form @{term "Abs as x"} etc is motivated by the fact that
+ − 849
we can conveniently establish at the Isabelle/HOL level
+ − 850
properties about them. It would be
+ − 851
laborious to write custom ML-code that derives automatically such properties
1730
+ − 852
for every term-constructor that binds some atoms. Also the generality of
2341
+ − 853
the definitions for $\alpha$-equivalence will help us in the next section.
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 854
*}
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 855
2345
+ − 856
section {* Specifying General Bindings\label{sec:spec} *}
1491
+ − 857
1520
+ − 858
text {*
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 859
Our choice of syntax for specifications is influenced by the existing
1765
+ − 860
datatype package of Isabelle/HOL \cite{Berghofer99} and by the syntax of the
+ − 861
Ott-tool \cite{ott-jfp}. For us a specification of a term-calculus is a
+ − 862
collection of (possibly mutual recursive) type declarations, say @{text
+ − 863
"ty\<AL>\<^isub>1, \<dots>, ty\<AL>\<^isub>n"}, and an associated collection of
+ − 864
binding functions, say @{text "bn\<AL>\<^isub>1, \<dots>, bn\<AL>\<^isub>m"}. The
+ − 865
syntax in Nominal Isabelle for such specifications is roughly as follows:
1628
+ − 866
%
1619
+ − 867
\begin{equation}\label{scheme}
1636
+ − 868
\mbox{\begin{tabular}{@ {\hspace{-5mm}}p{1.8cm}l}
1617
+ − 869
type \mbox{declaration part} &
1611
+ − 870
$\begin{cases}
+ − 871
\mbox{\begin{tabular}{l}
1765
+ − 872
\isacommand{nominal\_datatype} @{text "ty\<AL>\<^isub>1 = \<dots>"}\\
+ − 873
\isacommand{and} @{text "ty\<AL>\<^isub>2 = \<dots>"}\\
1587
+ − 874
$\ldots$\\
1765
+ − 875
\isacommand{and} @{text "ty\<AL>\<^isub>n = \<dots>"}\\
1611
+ − 876
\end{tabular}}
+ − 877
\end{cases}$\\
1617
+ − 878
binding \mbox{function part} &
1611
+ − 879
$\begin{cases}
+ − 880
\mbox{\begin{tabular}{l}
1954
+ − 881
\isacommand{binder} @{text "bn\<AL>\<^isub>1"} \isacommand{and} \ldots \isacommand{and} @{text "bn\<AL>\<^isub>m"}\\
1611
+ − 882
\isacommand{where}\\
1587
+ − 883
$\ldots$\\
1611
+ − 884
\end{tabular}}
+ − 885
\end{cases}$\\
1619
+ − 886
\end{tabular}}
+ − 887
\end{equation}
1587
+ − 888
+ − 889
\noindent
1637
+ − 890
Every type declaration @{text ty}$^\alpha_{1..n}$ consists of a collection of
2341
+ − 891
term-constructors, each of which comes with a list of labelled
1620
+ − 892
types that stand for the types of the arguments of the term-constructor.
1765
+ − 893
For example a term-constructor @{text "C\<^sup>\<alpha>"} might be specified with
1611
+ − 894
+ − 895
\begin{center}
1637
+ − 896
@{text "C\<^sup>\<alpha> label\<^isub>1::ty"}$'_1$ @{text "\<dots> label\<^isub>l::ty"}$'_l\;\;$ @{text "binding_clauses"}
1611
+ − 897
\end{center}
1587
+ − 898
1611
+ − 899
\noindent
2128
+ − 900
whereby some of the @{text ty}$'_{1..l}$ (or their components) can be contained
1730
+ − 901
in the collection of @{text ty}$^\alpha_{1..n}$ declared in
1737
+ − 902
\eqref{scheme}.
1765
+ − 903
In this case we will call the corresponding argument a
+ − 904
\emph{recursive argument} of @{text "C\<^sup>\<alpha>"}.
+ − 905
%The types of such recursive
1737
+ − 906
%arguments need to satisfy a ``positivity''
+ − 907
%restriction, which ensures that the type has a set-theoretic semantics
+ − 908
%\cite{Berghofer99}.
+ − 909
The labels
1730
+ − 910
annotated on the types are optional. Their purpose is to be used in the
+ − 911
(possibly empty) list of \emph{binding clauses}, which indicate the binders
+ − 912
and their scope in a term-constructor. They come in three \emph{modes}:
1587
+ − 913
1611
+ − 914
\begin{center}
1617
+ − 915
\begin{tabular}{l}
2343
+ − 916
\isacommand{bind}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
+ − 917
\isacommand{bind\_set}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
+ − 918
\isacommand{bind\_res}\; {\it binders}\; \isacommand{in}\; {\it bodies}\\
1617
+ − 919
\end{tabular}
1611
+ − 920
\end{center}
+ − 921
+ − 922
\noindent
1730
+ − 923
The first mode is for binding lists of atoms (the order of binders matters);
+ − 924
the second is for sets of binders (the order does not matter, but the
+ − 925
cardinality does) and the last is for sets of binders (with vacuous binders
2343
+ − 926
preserving $\alpha$-equivalence). As indicated, the ``\isacommand{in}-part'' of a binding
+ − 927
clause will be called \emph{bodies}; the
2163
+ − 928
``\isacommand{bind}-part'' will be called \emph{binders}. In contrast to
+ − 929
Ott, we allow multiple labels in binders and bodies. For example we allow
+ − 930
binding clauses of the form:
1956
+ − 931
+ − 932
\begin{center}
2156
+ − 933
\begin{tabular}{@ {}ll@ {}}
2341
+ − 934
@{text "Foo\<^isub>1 x::name y::name t::trm s::trm"} &
2156
+ − 935
\isacommand{bind} @{text "x y"} \isacommand{in} @{text "t s"}\\
2341
+ − 936
@{text "Foo\<^isub>2 x::name y::name t::trm s::trm"} &
2156
+ − 937
\isacommand{bind} @{text "x y"} \isacommand{in} @{text "t"},
+ − 938
\isacommand{bind} @{text "x y"} \isacommand{in} @{text "s"}\\
1956
+ − 939
\end{tabular}
+ − 940
\end{center}
+ − 941
+ − 942
\noindent
2343
+ − 943
Similarly for the other binding modes.
+ − 944
%Interestingly, in case of \isacommand{bind\_set}
+ − 945
%and \isacommand{bind\_res} the binding clauses above will make a difference to the semantics
+ − 946
%of the specifications (the corresponding $\alpha$-equivalence will differ). We will
+ − 947
%show this later with an example.
2140
+ − 948
2347
+ − 949
There are also some restrictions we need to impose on our binding clauses in comparison to
+ − 950
the ones of Ott. The
2343
+ − 951
main idea behind these restrictions is that we obtain a sensible notion of
2347
+ − 952
$\alpha$-equivalence where it is ensured that within a given scope an
+ − 953
atom occurence cannot be both bound and free at the same time. The first
2344
+ − 954
restriction is that a body can only occur in
2343
+ − 955
\emph{one} binding clause of a term constructor (this ensures that the bound
2347
+ − 956
atoms of a body cannot be free at the same time by specifying an
2344
+ − 957
alternative binder for the same body). For binders we distinguish between
2343
+ − 958
\emph{shallow} and \emph{deep} binders. Shallow binders are just
+ − 959
labels. The restriction we need to impose on them is that in case of
+ − 960
\isacommand{bind\_set} and \isacommand{bind\_res} the labels must either
+ − 961
refer to atom types or to sets of atom types; in case of \isacommand{bind}
+ − 962
the labels must refer to atom types or lists of atom types. Two examples for
+ − 963
the use of shallow binders are the specification of lambda-terms, where a
+ − 964
single name is bound, and type-schemes, where a finite set of names is
+ − 965
bound:
+ − 966
1611
+ − 967
+ − 968
\begin{center}
1612
+ − 969
\begin{tabular}{@ {}cc@ {}}
+ − 970
\begin{tabular}{@ {}l@ {\hspace{-1mm}}}
2341
+ − 971
\isacommand{nominal\_datatype} @{text lam} $=$\\
1719
+ − 972
\hspace{5mm}\phantom{$\mid$}~@{text "Var name"}\\
+ − 973
\hspace{5mm}$\mid$~@{text "App lam lam"}\\
+ − 974
\hspace{5mm}$\mid$~@{text "Lam x::name t::lam"}\\
+ − 975
\hspace{21mm}\isacommand{bind} @{text x} \isacommand{in} @{text t}\\
1611
+ − 976
\end{tabular} &
1612
+ − 977
\begin{tabular}{@ {}l@ {}}
2341
+ − 978
\isacommand{nominal\_datatype}~@{text ty} $=$\\
1719
+ − 979
\hspace{5mm}\phantom{$\mid$}~@{text "TVar name"}\\
+ − 980
\hspace{5mm}$\mid$~@{text "TFun ty ty"}\\
+ − 981
\isacommand{and}~@{text "tsc = All xs::(name fset) T::ty"}\\
+ − 982
\hspace{24mm}\isacommand{bind\_res} @{text xs} \isacommand{in} @{text T}\\
1611
+ − 983
\end{tabular}
+ − 984
\end{tabular}
+ − 985
\end{center}
1587
+ − 986
1612
+ − 987
\noindent
2341
+ − 988
In these specifications @{text "name"} refers to an atom type, and @{text
+ − 989
"fset"} to the type of finite sets.
2156
+ − 990
Note that for @{text lam} it does not matter which binding mode we use. The
+ − 991
reason is that we bind only a single @{text name}. However, having
2175
+ − 992
\isacommand{bind\_set} or \isacommand{bind} in the second case makes a
2345
+ − 993
difference to the semantics of the specification (which we will define in the next section).
2156
+ − 994
2128
+ − 995
2134
+ − 996
A \emph{deep} binder uses an auxiliary binding function that ``picks'' out
2156
+ − 997
the atoms in one argument of the term-constructor, which can be bound in
+ − 998
other arguments and also in the same argument (we will call such binders
2341
+ − 999
\emph{recursive}, see below). The binding functions are
2156
+ − 1000
expected to return either a set of atoms (for \isacommand{bind\_set} and
+ − 1001
\isacommand{bind\_res}) or a list of atoms (for \isacommand{bind}). They can
2343
+ − 1002
be defined by recursion over the corresponding type; the equations
2156
+ − 1003
must be given in the binding function part of the scheme shown in
+ − 1004
\eqref{scheme}. For example a term-calculus containing @{text "Let"}s with
+ − 1005
tuple patterns might be specified as:
1764
+ − 1006
%
+ − 1007
\begin{equation}\label{letpat}
+ − 1008
\mbox{%
1619
+ − 1009
\begin{tabular}{l}
1719
+ − 1010
\isacommand{nominal\_datatype} @{text trm} =\\
+ − 1011
\hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\
+ − 1012
\hspace{5mm}$\mid$~@{term "App trm trm"}\\
+ − 1013
\hspace{5mm}$\mid$~@{text "Lam x::name t::trm"}
+ − 1014
\;\;\isacommand{bind} @{text x} \isacommand{in} @{text t}\\
+ − 1015
\hspace{5mm}$\mid$~@{text "Let p::pat trm t::trm"}
+ − 1016
\;\;\isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text t}\\
+ − 1017
\isacommand{and} @{text pat} =\\
+ − 1018
\hspace{5mm}\phantom{$\mid$}~@{text PNil}\\
+ − 1019
\hspace{5mm}$\mid$~@{text "PVar name"}\\
+ − 1020
\hspace{5mm}$\mid$~@{text "PTup pat pat"}\\
1954
+ − 1021
\isacommand{binder}~@{text "bn::pat \<Rightarrow> atom list"}\\
1719
+ − 1022
\isacommand{where}~@{text "bn(PNil) = []"}\\
+ − 1023
\hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\
2341
+ − 1024
\hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\
1764
+ − 1025
\end{tabular}}
+ − 1026
\end{equation}
1617
+ − 1027
1619
+ − 1028
\noindent
2140
+ − 1029
In this specification the function @{text "bn"} determines which atoms of
2346
+ − 1030
the pattern @{text p} are bound in the argument @{text "t"}. Note that in the
2140
+ − 1031
second-last @{text bn}-clause the function @{text "atom"} coerces a name
+ − 1032
into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This
+ − 1033
allows us to treat binders of different atom type uniformly.
1637
+ − 1034
2140
+ − 1035
As said above, for deep binders we allow binding clauses such as
+ − 1036
%
1620
+ − 1037
\begin{center}
+ − 1038
\begin{tabular}{ll}
2140
+ − 1039
@{text "Bar p::pat t::trm"} &
1954
+ − 1040
\isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p t"}\\
1620
+ − 1041
\end{tabular}
+ − 1042
\end{center}
+ − 1043
+ − 1044
\noindent
2344
+ − 1045
where the argument of the deep binder also occurs in the body. We call such
2140
+ − 1046
binders \emph{recursive}. To see the purpose of such recursive binders,
+ − 1047
compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following
+ − 1048
specification:
2343
+ − 1049
%
1725
+ − 1050
\begin{equation}\label{letrecs}
+ − 1051
\mbox{%
1637
+ − 1052
\begin{tabular}{@ {}l@ {}}
1725
+ − 1053
\isacommand{nominal\_datatype}~@{text "trm ="}\\
1636
+ − 1054
\hspace{5mm}\phantom{$\mid$}\ldots\\
1725
+ − 1055
\hspace{5mm}$\mid$~@{text "Let as::assn t::trm"}
+ − 1056
\;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text t}\\
1954
+ − 1057
\hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"}
+ − 1058
\;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\
+ − 1059
\isacommand{and} @{text "ass"} =\\
1725
+ − 1060
\hspace{5mm}\phantom{$\mid$}~@{text "ANil"}\\
+ − 1061
\hspace{5mm}$\mid$~@{text "ACons name trm assn"}\\
1954
+ − 1062
\isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\
1725
+ − 1063
\isacommand{where}~@{text "bn(ANil) = []"}\\
+ − 1064
\hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\
+ − 1065
\end{tabular}}
+ − 1066
\end{equation}
1636
+ − 1067
+ − 1068
\noindent
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1069
The difference is that with @{text Let} we only want to bind the atoms @{text
1730
+ − 1070
"bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms
2346
+ − 1071
inside the assignment. This difference has consequences for the associated
2347
+ − 1072
notions of free-atoms and $\alpha$-equivalence.
2341
+ − 1073
2347
+ − 1074
To make sure that atoms bound by deep binders cannot be free at the
2346
+ − 1075
same time, we cannot have more than one binding function for a deep binder.
2344
+ − 1076
Consequently we exclude specifications such as
2140
+ − 1077
+ − 1078
\begin{center}
2341
+ − 1079
\begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
+ − 1080
@{text "Baz\<^isub>1 p::pat t::trm"} &
2140
+ − 1081
\isacommand{bind} @{text "bn\<^isub>1(p) bn\<^isub>2(p)"} \isacommand{in} @{text t}\\
2341
+ − 1082
@{text "Baz\<^isub>2 p::pat t\<^isub>1::trm t\<^isub>2::trm"} &
+ − 1083
\isacommand{bind} @{text "bn\<^isub>1(p)"} \isacommand{in} @{text "t\<^isub>1"},
+ − 1084
\isacommand{bind} @{text "bn\<^isub>2(p)"} \isacommand{in} @{text "t\<^isub>2"}\\
2140
+ − 1085
\end{tabular}
+ − 1086
\end{center}
+ − 1087
+ − 1088
\noindent
2344
+ − 1089
Otherwise it is possible that @{text "bn\<^isub>1"} and @{text "bn\<^isub>2"} pick
2347
+ − 1090
out different atoms to become bound, respectively be free, in @{text "p"}
+ − 1091
(since the Ott-tool does not derive a reasoning for $\alpha$-equated terms, it can permit
+ − 1092
such specifications).
2343
+ − 1093
2344
+ − 1094
We also need to restrict the form of the binding functions in order
2345
+ − 1095
to ensure the @{text "bn"}-functions can be defined for $\alpha$-equated
2346
+ − 1096
terms. The main restriction is that we cannot return an atom in a binding function that is also
+ − 1097
bound in the corresponding term-constructor. That means in \eqref{letpat}
+ − 1098
that the term-constructors @{text PVar} and @{text PTup} may
1961
+ − 1099
not have a binding clause (all arguments are used to define @{text "bn"}).
+ − 1100
In contrast, in case of \eqref{letrecs} the term-constructor @{text ACons}
2341
+ − 1101
may have a binding clause involving the argument @{text t} (the only one that
2343
+ − 1102
is \emph{not} used in the definition of the binding function). This restriction
2345
+ − 1103
is sufficient for defining the binding function over $\alpha$-equated terms.
2341
+ − 1104
+ − 1105
In the version of
1961
+ − 1106
Nominal Isabelle described here, we also adopted the restriction from the
+ − 1107
Ott-tool that binding functions can only return: the empty set or empty list
+ − 1108
(as in case @{text PNil}), a singleton set or singleton list containing an
+ − 1109
atom (case @{text PVar}), or unions of atom sets or appended atom lists
2341
+ − 1110
(case @{text PTup}). This restriction will simplify some automatic definitions and proofs
1961
+ − 1111
later on.
+ − 1112
2347
+ − 1113
In order to simplify our definitions of free atoms and $\alpha$-equivalence,
2343
+ − 1114
we shall assume specifications
2341
+ − 1115
of term-calculi are implicitly \emph{completed}. By this we mean that
1954
+ − 1116
for every argument of a term-constructor that is \emph{not}
2163
+ − 1117
already part of a binding clause given by the user, we add implicitly a special \emph{empty} binding
+ − 1118
clause, written \isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "labels"}. In case
1956
+ − 1119
of the lambda-calculus, the completion produces
1954
+ − 1120
+ − 1121
\begin{center}
+ − 1122
\begin{tabular}{@ {}l@ {\hspace{-1mm}}}
+ − 1123
\isacommand{nominal\_datatype} @{text lam} =\\
+ − 1124
\hspace{5mm}\phantom{$\mid$}~@{text "Var x::name"}
+ − 1125
\;\;\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "x"}\\
+ − 1126
\hspace{5mm}$\mid$~@{text "App t\<^isub>1::lam t\<^isub>2::lam"}
2163
+ − 1127
\;\;\isacommand{bind}~@{term "{}"}~\isacommand{in}~@{text "t\<^isub>1 t\<^isub>2"}\\
1954
+ − 1128
\hspace{5mm}$\mid$~@{text "Lam x::name t::lam"}
+ − 1129
\;\;\isacommand{bind}~@{text x} \isacommand{in} @{text t}\\
+ − 1130
\end{tabular}
+ − 1131
\end{center}
+ − 1132
+ − 1133
\noindent
+ − 1134
The point of completion is that we can make definitions over the binding
1961
+ − 1135
clauses and be sure to have captured all arguments of a term constructor.
2342
+ − 1136
*}
1954
+ − 1137
2347
+ − 1138
section {* Alpha-Equivalence and Free Atoms\label{sec:alpha} *}
2342
+ − 1139
+ − 1140
text {*
1637
+ − 1141
Having dealt with all syntax matters, the problem now is how we can turn
+ − 1142
specifications into actual type definitions in Isabelle/HOL and then
1926
+ − 1143
establish a reasoning infrastructure for them. As
1956
+ − 1144
Pottier and Cheney pointed out \cite{Pottier06,Cheney05}, just
1954
+ − 1145
re-arranging the arguments of
1956
+ − 1146
term-constructors so that binders and their bodies are next to each other will
2347
+ − 1147
result in inadequate representations in cases like @{text "Let x\<^isub>1 = t\<^isub>1\<dots>x\<^isub>n = t\<^isub>n in s"}.
2343
+ − 1148
Therefore we will first
2346
+ − 1149
extract ``raw'' datatype definitions from the specification and then define
2343
+ − 1150
explicitly an $\alpha$-equivalence relation over them. We subsequently
+ − 1151
quotient the datatypes according to our $\alpha$-equivalence.
1637
+ − 1152
+ − 1153
2346
+ − 1154
The ``raw'' datatype definition can be obtained by stripping off the
1771
+ − 1155
binding clauses and the labels from the types. We also have to invent
1637
+ − 1156
new names for the types @{text "ty\<^sup>\<alpha>"} and term-constructors @{text "C\<^sup>\<alpha>"}
1756
+ − 1157
given by the user. In our implementation we just use the affix ``@{text "_raw"}''.
1771
+ − 1158
But for the purpose of this paper, we use the superscript @{text "_\<^sup>\<alpha>"} to indicate
2341
+ − 1159
that a notion is defined over $\alpha$-equivalence classes and leave it out
1724
+ − 1160
for the corresponding notion defined on the ``raw'' level. So for example
+ − 1161
we have
+ − 1162
1636
+ − 1163
\begin{center}
1723
+ − 1164
@{text "ty\<^sup>\<alpha> \<mapsto> ty"} \hspace{2mm}and\hspace{2mm} @{text "C\<^sup>\<alpha> \<mapsto> C"}
1636
+ − 1165
\end{center}
+ − 1166
+ − 1167
\noindent
1730
+ − 1168
where @{term ty} is the type used in the quotient construction for
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1169
@{text "ty\<^sup>\<alpha>"} and @{text "C"} is the term-constructor on the ``raw'' type @{text "ty"}.
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1170
1637
+ − 1171
The resulting datatype definition is legal in Isabelle/HOL provided the datatypes are
+ − 1172
non-empty and the types in the constructors only occur in positive
1724
+ − 1173
position (see \cite{Berghofer99} for an indepth description of the datatype package
2347
+ − 1174
in Isabelle/HOL). We then define each of the user-specified binding
+ − 1175
function @{term "bn\<^isub>i"} by recursion over the corresponding
1730
+ − 1176
raw datatype. We can also easily define permutation operations by
2345
+ − 1177
recursion so that for each term constructor @{text "C"} we have that
1766
+ − 1178
%
+ − 1179
\begin{equation}\label{ceqvt}
1961
+ − 1180
@{text "p \<bullet> (C z\<^isub>1 \<dots> z\<^isub>n) = C (p \<bullet> z\<^isub>1) \<dots> (p \<bullet> z\<^isub>n)"}
1766
+ − 1181
\end{equation}
2343
+ − 1182
2341
+ − 1183
The first non-trivial step we have to perform is the generation of
2347
+ − 1184
free-atom functions from the specifications. For the
+ − 1185
\emph{raw} types @{text "ty"}$_{1..n}$ we define the free-atom functions
2343
+ − 1186
%
+ − 1187
\begin{equation}\label{fvars}
2347
+ − 1188
@{text "fa_ty\<^isub>1, \<dots>, fa_ty\<^isub>n"}
2343
+ − 1189
\end{equation}
2341
+ − 1190
+ − 1191
\noindent
2346
+ − 1192
by mutual recursion.
2347
+ − 1193
We define these functions together with auxiliary free-atom functions for
2343
+ − 1194
the binding functions. Given raw binding functions @{text "bn"}$_{1..m}$
+ − 1195
we define
+ − 1196
%
2341
+ − 1197
\begin{center}
2347
+ − 1198
@{text "fa_bn\<^isub>1, \<dots>, fa_bn\<^isub>m"}
2341
+ − 1199
\end{center}
+ − 1200
+ − 1201
\noindent
+ − 1202
The reason for this setup is that in a deep binder not all atoms have to be
+ − 1203
bound, as we saw in the example with ``plain'' @{text Let}s. We need therefore a function
2343
+ − 1204
that calculates those unbound atoms in a deep binder.
+ − 1205
2347
+ − 1206
While the idea behind these free-atom functions is clear (they just
2343
+ − 1207
collect all atoms that are not bound), because of our rather complicated
2345
+ − 1208
binding mechanisms their definitions are somewhat involved. Given
2346
+ − 1209
a term-constructor @{text "C"} of type @{text ty} and some associated
2344
+ − 1210
binding clauses @{text "bc\<^isub>1\<dots>bc\<^isub>k"}, the result of @{text
2347
+ − 1211
"fa_ty (C z\<^isub>1 \<dots> z\<^isub>n)"} will be the union @{text
+ − 1212
"fa(bc\<^isub>1) \<union> \<dots> \<union> fa(bc\<^isub>k)"} where we define below what @{text "fa"} for a binding
+ − 1213
clause means. We only show the details for the mode \isacommand{bind\_set} (the other modes are similar).
2345
+ − 1214
Suppose the binding clause @{text bc\<^isub>i} is of the form
2343
+ − 1215
%
+ − 1216
\begin{equation}
2344
+ − 1217
\mbox{\isacommand{bind\_set} @{text "b\<^isub>1\<dots>b\<^isub>p"} \isacommand{in} @{text "d\<^isub>1\<dots>d\<^isub>q"}}
2343
+ − 1218
\end{equation}
2341
+ − 1219
2343
+ − 1220
\noindent
2344
+ − 1221
in which the body-labels @{text "d"}$_{1..q}$ refer to types @{text ty}$_{1..q}$,
+ − 1222
and the binders @{text b}$_{1..p}$
2343
+ − 1223
either refer to labels of atom types (in case of shallow binders) or to binding
+ − 1224
functions taking a single label as argument (in case of deep binders). Assuming the
2345
+ − 1225
set @{text "D"} stands for the free atoms in the bodies, the set @{text B} for the
2344
+ − 1226
binding atoms in the binders and @{text "B'"} for the free atoms in
+ − 1227
non-recursive deep binders,
+ − 1228
then the free atoms of the binding clause @{text bc\<^isub>i} are given by
2343
+ − 1229
%
+ − 1230
\begin{center}
2347
+ − 1231
@{text "fa(bc\<^isub>i) \<equiv> (D - B) \<union> B'"}
2343
+ − 1232
\end{center}
+ − 1233
+ − 1234
\noindent
2347
+ − 1235
whereby the set @{text D} is formally defined as
2343
+ − 1236
%
+ − 1237
\begin{center}
2347
+ − 1238
@{text "D \<equiv> fa_ty\<^isub>1 d\<^isub>1 \<union> ... \<union> fa_ty\<^isub>q d\<^isub>q"}
2343
+ − 1239
\end{center}
+ − 1240
+ − 1241
\noindent
2347
+ − 1242
The functions @{text "fa_ty\<^isub>i"} are the ones we are defining by recursion
+ − 1243
(see \eqref{fvars}) in case the @{text "d\<^isub>i"} refers to one of the raw types
+ − 1244
@{text "ty"}$_{1..n}$ from the specification; otherwise we set @{text "fa_ty\<^isub>i d\<^isub>i = supp d\<^isub>i"}.
2345
+ − 1245
In order to define the set @{text B} we use the following auxiliary @{text "bn"}-functions
2344
+ − 1246
for atom types to which shallow binders have to refer
+ − 1247
%
1954
+ − 1248
\begin{center}
+ − 1249
\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
2345
+ − 1250
@{text "bn_atom a"} & @{text "\<equiv>"} & @{text "{atom a}"}\\
+ − 1251
@{text "bn_atom_set as"} & @{text "\<equiv>"} & @{text "atoms as"}\\
+ − 1252
@{text "bn_atom_list as"} & @{text "\<equiv>"} & @{text "atoms (set as)"}
1954
+ − 1253
\end{tabular}
+ − 1254
\end{center}
+ − 1255
+ − 1256
\noindent
2345
+ − 1257
The function @{text "atoms"} coerces
2344
+ − 1258
the set of atoms to a set of the generic atom type. It is defined as
+ − 1259
@{text "atoms as \<equiv> {atom a | a \<in> as}"}.
2345
+ − 1260
The set @{text B} is then formally defined as
2344
+ − 1261
%
+ − 1262
\begin{center}
+ − 1263
@{text "B \<equiv> bn_ty\<^isub>1 b\<^isub>1 \<union> ... \<union> bn_ty\<^isub>p b\<^isub>p"}
+ − 1264
\end{center}
1954
+ − 1265
2344
+ − 1266
\noindent
+ − 1267
The set @{text "B'"} collects all free atoms in non-recursive deep
2347
+ − 1268
binders. Let us assume these binders in @{text "bc\<^isub>i"} are
1956
+ − 1269
%
2344
+ − 1270
\begin{center}
+ − 1271
@{text "bn\<^isub>1 a\<^isub>1, \<dots>, bn\<^isub>r a\<^isub>r"}
+ − 1272
\end{center}
+ − 1273
+ − 1274
\noindent
+ − 1275
with none of the @{text "a"}$_{1..r}$ being among the bodies @{text
2345
+ − 1276
"d"}$_{1..q}$. The set @{text "B'"} is defined as
2344
+ − 1277
%
+ − 1278
\begin{center}
2347
+ − 1279
@{text "B' \<equiv> fa_bn\<^isub>1 a\<^isub>1 \<union> ... \<union> fa_bn\<^isub>r a\<^isub>r"}
2344
+ − 1280
\end{center}
1628
+ − 1281
1636
+ − 1282
\noindent
2347
+ − 1283
This completes the definition of the free-atom functions.
2344
+ − 1284
+ − 1285
Note that for non-recursive deep binders, we have to add all atoms that are left
2347
+ − 1286
unbound by the binding function @{text "bn"} (the set @{text "B'"}). We use for this
+ − 1287
the functions @{text "fa_bn"}, also defined by recursion. Assume the user specified
2344
+ − 1288
a @{text bn}-clause of the form
1956
+ − 1289
%
2344
+ − 1290
\begin{center}
2347
+ − 1291
@{text "bn (C z\<^isub>1 \<dots> z\<^isub>s) = rhs"}
2344
+ − 1292
\end{center}
1628
+ − 1293
1954
+ − 1294
\noindent
2347
+ − 1295
where the @{text "z"}$_{1..s}$ are of types @{text "ty"}$_{1..s}$. For each of
2345
+ − 1296
the arguments we calculate the free atoms as follows:
2344
+ − 1297
%
+ − 1298
\begin{center}
+ − 1299
\begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
2347
+ − 1300
$\bullet$ & @{term "fa_ty\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} does not occur in @{text "rhs"}
+ − 1301
(that means nothing is bound in @{text "z\<^isub>i"}),\\
+ − 1302
$\bullet$ & @{term "fa_bn\<^isub>i z\<^isub>i"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"}
2345
+ − 1303
with the recursive call @{text "bn\<^isub>i z\<^isub>i"}, and\\
2344
+ − 1304
$\bullet$ & @{term "{}"} provided @{text "z\<^isub>i"} occurs in @{text "rhs"},
2347
+ − 1305
but without a recursive call.
2344
+ − 1306
\end{tabular}
+ − 1307
\end{center}
1758
731d39fb26b7
Update fv_bn definition for bindings allowed in types for which bn is present.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 1308
2344
+ − 1309
\noindent
2347
+ − 1310
For defining @{text "fa_bn (C z\<^isub>1 \<dots> z\<^isub>n)"} we just union up all these values.
2344
+ − 1311
1890
+ − 1312
To see how these definitions work in practice, let us reconsider the term-constructors
2345
+ − 1313
@{text "Let"} and @{text "Let_rec"}, as well as @{text "ANil"} and @{text "ACons"}
+ − 1314
from the example shown in \eqref{letrecs}.
2347
+ − 1315
For them we define three free-atom functions, namely
+ − 1316
@{text "fa\<^bsub>trm\<^esub>"}, @{text "fa\<^bsub>assn\<^esub>"} and @{text "fa\<^bsub>bn\<^esub>"} as follows:
1725
+ − 1317
%
+ − 1318
\begin{center}
+ − 1319
\begin{tabular}{@ {}l@ {\hspace{1mm}}c@ {\hspace{1mm}}l@ {}}
2347
+ − 1320
@{text "fa\<^bsub>trm\<^esub> (Let as t)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t - set (bn as)) \<union> fa\<^bsub>bn\<^esub> as"}\\
+ − 1321
@{text "fa\<^bsub>trm\<^esub> (Let_rec as t)"} & @{text "="} & @{text "(fa\<^bsub>assn\<^esub> as \<union> fa\<^bsub>trm\<^esub> t) - set (bn as)"}\\[1mm]
1725
+ − 1322
2347
+ − 1323
@{text "fa\<^bsub>assn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\
+ − 1324
@{text "fa\<^bsub>assn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(supp a) \<union> (fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>assn\<^esub> as)"}\\[1mm]
1725
+ − 1325
2347
+ − 1326
@{text "fa\<^bsub>bn\<^esub> (ANil)"} & @{text "="} & @{term "{}"}\\
+ − 1327
@{text "fa\<^bsub>bn\<^esub> (ACons a t as)"} & @{text "="} & @{text "(fa\<^bsub>trm\<^esub> t) \<union> (fa\<^bsub>bn\<^esub> as)"}
1725
+ − 1328
\end{tabular}
+ − 1329
\end{center}
+ − 1330
+ − 1331
\noindent
2347
+ − 1332
To see the pattern, recall that @{text ANil} and @{text "ACons"} have no
+ − 1333
binding clause in the specification. The corresponding free-atom
+ − 1334
function @{text "fa\<^bsub>assn\<^esub>"} therefore returns all atoms
2345
+ − 1335
occurring in an assignment. The binding only takes place in @{text Let} and
+ − 1336
@{text "Let_rec"}. In the @{text "Let"}-clause, the binding clause specifies
+ − 1337
that all atoms given by @{text "set (bn as)"} have to be bound in @{text
+ − 1338
t}. Therefore we have to subtract @{text "set (bn as)"} from @{text
2347
+ − 1339
"fa\<^bsub>trm\<^esub> t"}. However, we also need to add all atoms that are
2345
+ − 1340
free in @{text "as"}. In contrast, in @{text "Let_rec"} we have a recursive
+ − 1341
binder where we want to also bind all occurrences of the atoms in @{text
+ − 1342
"set (bn as)"} also inside @{text "as"}. Therefore we have to subtract
2347
+ − 1343
@{text "set (bn as)"} from the union @{text "fa\<^bsub>trm\<^esub> t"} and @{text "fa\<^bsub>assn\<^esub> as"}.
2345
+ − 1344
+ − 1345
An interesting point in this
+ − 1346
example is that a ``naked'' assignment does not bind any
+ − 1347
atoms. Only in the context of a @{text Let} or @{text "Let_rec"} will
+ − 1348
some atoms from an assignment become bound. This is a phenomenon that has also been pointed
+ − 1349
out in \cite{ott-jfp}. For us this observation is crucial, because we would
+ − 1350
not be able to lift the @{text "bn"}-function if it was defined over assignments
+ − 1351
where some atoms are bound. In that case @{text "bn"} would \emph{not} respect
+ − 1352
$\alpha$-equivalence.
+ − 1353
+ − 1354
Next we define $\alpha$-equivalence relations for the raw types @{text
2347
+ − 1355
"ty"}$_{1..n}$. We write them
1733
+ − 1356
%
2345
+ − 1357
\begin{center}
+ − 1358
@{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"}.
+ − 1359
\end{center}
1725
+ − 1360
1764
+ − 1361
\noindent
2347
+ − 1362
Like with the free-atom functions, we also need to
2345
+ − 1363
define auxiliary $\alpha$-equivalence relations
+ − 1364
%
+ − 1365
\begin{center}
+ − 1366
@{text "\<approx>bn\<^isub>1, \<dots>, \<approx>bn\<^isub>m"}
+ − 1367
\end{center}
2344
+ − 1368
2345
+ − 1369
\noindent
+ − 1370
for the binding functions @{text "bn"}$_{1..m}$,
+ − 1371
To simplify our definitions we will use the following abbreviations for
2347
+ − 1372
equivalence relations and free-atom functions acting on pairs
2345
+ − 1373
1733
+ − 1374
%
+ − 1375
\begin{center}
1737
+ − 1376
\begin{tabular}{r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
1735
+ − 1377
@{text "(x\<^isub>1, y\<^isub>1) (R\<^isub>1 \<otimes> R\<^isub>2) (x\<^isub>2, y\<^isub>2)"} & @{text "\<equiv>"} & @{text "x\<^isub>1 R\<^isub>1 y\<^isub>1 \<and> x\<^isub>2 R\<^isub>2 y\<^isub>2"}\\
2347
+ − 1378
@{text "(fa\<^isub>1 \<oplus> fa\<^isub>2) (x, y)"} & @{text "\<equiv>"} & @{text "fa\<^isub>1 x \<union> fa\<^isub>2 y"}\\
1733
+ − 1379
\end{tabular}
+ − 1380
\end{center}
+ − 1381
1727
fd2913415a73
started to polish alpha-equivalence section, but needs more work
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1382
2345
+ − 1383
The relations for $\alpha$-equivalence are inductively defined
+ − 1384
predicates, whose clauses have the form
1737
+ − 1385
%
+ − 1386
\begin{center}
2345
+ − 1387
\mbox{\infer{@{text "C z\<^isub>1 \<dots> z\<^isub>n \<approx>ty C z\<PRIME>\<^isub>1 \<dots> z\<PRIME>\<^isub>n"}}
+ − 1388
{@{text "prems(bc\<^isub>1) \<and> \<dots> \<and> prems(bc\<^isub>k)"}}}
1737
+ − 1389
\end{center}
+ − 1390
+ − 1391
\noindent
2345
+ − 1392
assuming the term-constructor @{text C} is of type @{text ty} and has
+ − 1393
the binding clauses @{term "bc"}$_{1..k}$. The task
1954
+ − 1394
is to specify what the premises of these clauses are. Again for this we
+ − 1395
analyse the binding clauses and produce a corresponding premise.
1735
+ − 1396
*}
+ − 1397
(*<*)
+ − 1398
consts alpha_ty ::'a
1739
+ − 1399
consts alpha_trm ::'a
2347
+ − 1400
consts fa_trm :: 'a
1739
+ − 1401
consts alpha_trm2 ::'a
2347
+ − 1402
consts fa_trm2 :: 'a
1739
+ − 1403
notation (latex output)
+ − 1404
alpha_ty ("\<approx>ty") and
+ − 1405
alpha_trm ("\<approx>\<^bsub>trm\<^esub>") and
2347
+ − 1406
fa_trm ("fa\<^bsub>trm\<^esub>") and
1739
+ − 1407
alpha_trm2 ("\<approx>\<^bsub>assn\<^esub> \<otimes> \<approx>\<^bsub>trm\<^esub>") and
2347
+ − 1408
fa_trm2 ("fa\<^bsub>assn\<^esub> \<oplus> fa\<^bsub>trm\<^esub>")
1735
+ − 1409
(*>*)
+ − 1410
text {*
2345
+ − 1411
*TBD below *
+ − 1412
1954
+ − 1413
\begin{equation}\label{alpha}
+ − 1414
\mbox{%
+ − 1415
\begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
+ − 1416
\multicolumn{2}{@ {}l}{Empty binding clauses of the form
+ − 1417
\isacommand{bind\_set}~@{term "{}"}~\isacommand{in}~@{text "x\<^isub>i"}:}\\
+ − 1418
$\bullet$ & @{text "x\<^isub>i \<approx>ty y\<^isub>i"} provided @{text "x\<^isub>i"} and @{text "y\<^isub>i"}
+ − 1419
are recursive arguments of @{text "C"}\\
+ − 1420
$\bullet$ & @{term "x\<^isub>i = y\<^isub>i"} provided @{text "x\<^isub>i"} and @{text "y\<^isub>i"} are
+ − 1421
non-recursive arguments\smallskip\\
+ − 1422
\multicolumn{2}{@ {}l}{Shallow binders of the form
+ − 1423
\isacommand{bind\_set}~@{text "x\<^isub>1\<dots>x\<^isub>n"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\
+ − 1424
$\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"},
2347
+ − 1425
@{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fa} is
+ − 1426
@{text "fa_ty\<^isub>1 \<oplus> ... \<oplus> fa_ty\<^isub>m"}, then
1705
+ − 1427
\begin{center}
2347
+ − 1428
@{term "\<exists>p. (x\<^isub>1 \<union> \<xi> \<union> x\<^isub>n, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fa p (y\<^isub>1 \<union> \<xi> \<union> y\<^isub>n, (y'\<^isub>1,\<xi>,y'\<^isub>m))"}
1954
+ − 1429
\end{center}\\
+ − 1430
\multicolumn{2}{@ {}l}{Deep binders of the form
+ − 1431
\isacommand{bind\_set}~@{text "bn x"}~\isacommand{in}~@{text "x'\<^isub>1\<dots>x'\<^isub>m"}:}\\
+ − 1432
$\bullet$ & Assume the bodies @{text "x'\<^isub>1\<dots>x'\<^isub>m"} are of type @{text "ty\<^isub>1\<dots>ty\<^isub>m"},
2347
+ − 1433
@{text "R"} is @{text "\<approx>ty\<^isub>1 \<otimes> ... \<otimes> \<approx>ty\<^isub>m"} and @{text fa} is
+ − 1434
@{text "fa_ty\<^isub>1 \<oplus> ... \<oplus> fa_ty\<^isub>m"}, then for recursive deep binders
1705
+ − 1435
\begin{center}
2347
+ − 1436
@{term "\<exists>p. (bn x, (x'\<^isub>1,\<xi>,x'\<^isub>m)) \<approx>gen R fa p (bn y, (y'\<^isub>1,\<xi>,y'\<^isub>m))"}
1954
+ − 1437
\end{center}\\
+ − 1438
$\bullet$ & for non-recursive binders we generate in addition @{text "x \<approx>bn y"}\\
+ − 1439
\end{tabular}}
+ − 1440
\end{equation}
1705
+ − 1441
1735
+ − 1442
\noindent
1954
+ − 1443
Similarly for the other binding modes.
+ − 1444
From this definition it is clear why we have to impose the restriction
+ − 1445
of excluding overlapping deep binders, as these would need to be translated into separate
1737
+ − 1446
abstractions.
+ − 1447
+ − 1448
1752
+ − 1449
2341
+ − 1450
The $\alpha$-equivalence relations @{text "\<approx>bn\<^isub>j"} for binding functions
1755
+ − 1451
are similar. We again have conclusions of the form \mbox{@{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>bn C y\<^isub>1 \<dots> y\<^isub>n"}}
+ − 1452
and need to generate appropriate premises. We generate first premises according to the first three
+ − 1453
rules given above. Only the ``left-over'' pairs @{text "(x\<^isub>i, y\<^isub>i)"} need to be treated
+ − 1454
differently. They depend on whether @{text "x\<^isub>i"} occurs in @{text "rhs"} of the
+ − 1455
clause @{text "bn (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}:
1705
+ − 1456
1708
+ − 1457
\begin{center}
1752
+ − 1458
\begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
+ − 1459
$\bullet$ & @{text "x\<^isub>i \<approx>ty y\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text rhs}
1755
+ − 1460
and the type of @{text "x\<^isub>i"} is @{text ty} and @{text "x\<^isub>i"} is a recursive argument
+ − 1461
in the term-constructor\\
+ − 1462
$\bullet$ & @{text "x\<^isub>i = y\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text rhs}
+ − 1463
and @{text "x\<^isub>i"} is not a recursive argument in the term-constructor\\
1752
+ − 1464
$\bullet$ & @{text "x\<^isub>i \<approx>bn y\<^isub>i"} provided @{text "x\<^isub>i"} occurs in @{text rhs}
+ − 1465
with the recursive call @{text "bn x\<^isub>i"}\\
+ − 1466
$\bullet$ & none provided @{text "x\<^isub>i"} occurs in @{text rhs} but it is not
+ − 1467
in a recursive call involving a @{text "bn"}
1708
+ − 1468
\end{tabular}
+ − 1469
\end{center}
+ − 1470
1765
+ − 1471
Again lets take a look at a concrete example for these definitions. For \eqref{letrecs}
1739
+ − 1472
we have three relations, namely $\approx_{\textit{trm}}$, $\approx_{\textit{assn}}$ and
+ − 1473
$\approx_{\textit{bn}}$, with the clauses as follows:
+ − 1474
+ − 1475
\begin{center}
+ − 1476
\begin{tabular}{@ {}c @ {}}
+ − 1477
\infer{@{text "Let as t \<approx>\<^bsub>trm\<^esub> Let as' t'"}}
2347
+ − 1478
{@{text "as \<approx>\<^bsub>bn\<^esub> as'"} & @{term "\<exists>p. (bn as, t) \<approx>lst alpha_trm fa_trm p (bn as', t')"}}\smallskip\\
1739
+ − 1479
\infer{@{text "Let_rec as t \<approx>\<^bsub>trm\<^esub> Let_rec as' t'"}}
2347
+ − 1480
{@{term "\<exists>p. (bn as, (as, t)) \<approx>lst alpha_trm2 fa_trm2 p (bn as', (as', t'))"}}
1739
+ − 1481
\end{tabular}
+ − 1482
\end{center}
+ − 1483
+ − 1484
\begin{center}
+ − 1485
\begin{tabular}{@ {}c @ {}}
+ − 1486
\infer{@{text "ANil \<approx>\<^bsub>assn\<^esub> ANil"}}{}\\
+ − 1487
\infer{@{text "ACons a t as \<approx>\<^bsub>assn\<^esub> ACons a' t' as"}}
1771
+ − 1488
{@{text "a = a'"} & @{text "t \<approx>\<^bsub>trm\<^esub> t'"} & @{text "as \<approx>\<^bsub>assn\<^esub> as'"}}
1739
+ − 1489
\end{tabular}
+ − 1490
\end{center}
+ − 1491
+ − 1492
\begin{center}
+ − 1493
\begin{tabular}{@ {}c @ {}}
+ − 1494
\infer{@{text "ANil \<approx>\<^bsub>bn\<^esub> ANil"}}{}\\
+ − 1495
\infer{@{text "ACons a t as \<approx>\<^bsub>bn\<^esub> ACons a' t' as"}}
1771
+ − 1496
{@{text "t \<approx>\<^bsub>trm\<^esub> t'"} & @{text "as \<approx>\<^bsub>bn\<^esub> as'"}}
1739
+ − 1497
\end{tabular}
+ − 1498
\end{center}
+ − 1499
+ − 1500
\noindent
+ − 1501
Note the difference between $\approx_{\textit{assn}}$ and
2341
+ − 1502
$\approx_{\textit{bn}}$: the latter only ``tracks'' $\alpha$-equivalence of
1739
+ − 1503
the components in an assignment that are \emph{not} bound. Therefore we have
+ − 1504
a $\approx_{\textit{bn}}$-premise in the clause for @{text "Let"} (which is
1771
+ − 1505
a non-recursive binder). The underlying reason is that the terms inside an assignment are not meant
1765
+ − 1506
to be ``under'' the binder. Such a premise is \emph{not} needed in @{text "Let_rec"},
1739
+ − 1507
because there everything from the assignment is under the binder.
1587
+ − 1508
*}
+ − 1509
1739
+ − 1510
section {* Establishing the Reasoning Infrastructure *}
1717
+ − 1511
+ − 1512
text {*
1766
+ − 1513
Having made all necessary definitions for raw terms, we can start
2341
+ − 1514
introducing the reasoning infrastructure for the $\alpha$-equated types the
1767
+ − 1515
user originally specified. We sketch in this section the facts we need for establishing
+ − 1516
this reasoning infrastructure. First we have to show that the
2341
+ − 1517
$\alpha$-equivalence relations defined in the previous section are indeed
1766
+ − 1518
equivalence relations.
1717
+ − 1519
1766
+ − 1520
\begin{lemma}\label{equiv}
1739
+ − 1521
Given the raw types @{text "ty\<^isub>1, \<dots>, ty\<^isub>n"} and binding functions
+ − 1522
@{text "bn\<^isub>1, \<dots>, bn\<^isub>m"}, the relations @{text "\<approx>ty\<^isub>1, \<dots>, \<approx>ty\<^isub>n"} and
+ − 1523
@{text "\<approx>bn\<^isub>1 \<dots> \<approx>bn\<^isub>m"} are equivalence relations and equivariant.
1717
+ − 1524
\end{lemma}
1739
+ − 1525
+ − 1526
\begin{proof}
1752
+ − 1527
The proof is by mutual induction over the definitions. The non-trivial
2176
+ − 1528
cases involve premises built up by $\approx_{\textit{set}}$,
1739
+ − 1529
$\approx_{\textit{res}}$ and $\approx_{\textit{list}}$. They
1752
+ − 1530
can be dealt with as in Lemma~\ref{alphaeq}.
1739
+ − 1531
\end{proof}
1718
+ − 1532
1739
+ − 1533
\noindent
+ − 1534
We can feed this lemma into our quotient package and obtain new types @{text
2341
+ − 1535
"ty\<AL>\<^bsub>1..n\<^esub>"} representing $\alpha$-equated terms of types @{text "ty\<^bsub>1..n\<^esub>"}. We also obtain
1767
+ − 1536
definitions for the term-constructors @{text
1739
+ − 1537
"C"}$^\alpha_{1..m}$ from the raw term-constructors @{text
2347
+ − 1538
"C"}$_{1..m}$, and similar definitions for the free-atom functions @{text
+ − 1539
"fa_ty"}$^\alpha_{1..n}$ and the binding functions @{text
1767
+ − 1540
"bn"}$^\alpha_{1..k}$. However, these definitions are not really useful to the
1775
+ − 1541
user, since they are given in terms of the isomorphisms we obtained by
1754
+ − 1542
creating new types in Isabelle/HOL (recall the picture shown in the
1739
+ − 1543
Introduction).
+ − 1544
1767
+ − 1545
The first useful property to the user is the fact that term-constructors are
+ − 1546
distinct, that is
1760
+ − 1547
%
+ − 1548
\begin{equation}\label{distinctalpha}
+ − 1549
\mbox{@{text "C"}$^\alpha_i$@{text "x\<^isub>1 \<dots> x\<^isub>n"} @{text "\<noteq>"}
+ − 1550
@{text "C"}$^\alpha_j$@{text "y\<^isub>1 \<dots> y\<^isub>m"} holds for @{text "i \<noteq> j"}.}
+ − 1551
\end{equation}
+ − 1552
+ − 1553
\noindent
2341
+ − 1554
By definition of $\alpha$-equivalence we can show that
1760
+ − 1555
for the raw term-constructors
1765
+ − 1556
%
+ − 1557
\begin{equation}\label{distinctraw}
1767
+ − 1558
\mbox{@{text "C\<^isub>i x\<^isub>1 \<dots> x\<^isub>n"}\;$\not\approx$@{text ty}\;@{text "C\<^isub>j y\<^isub>1 \<dots> y\<^isub>m"} holds for @{text "i \<noteq> j"}.}
1765
+ − 1559
\end{equation}
1760
+ − 1560
+ − 1561
\noindent
1767
+ − 1562
In order to generate \eqref{distinctalpha} from \eqref{distinctraw}, the quotient
1760
+ − 1563
package needs to know that the term-constructors @{text "C\<^isub>i"} and @{text "C\<^isub>j"}
2341
+ − 1564
are \emph{respectful} w.r.t.~the $\alpha$-equivalence relations (see \cite{Homeier05}).
1767
+ − 1565
Assuming @{text "C\<^isub>i"} is of type @{text "ty"} with argument types
1770
+ − 1566
@{text "ty\<^isub>1, \<dots>, ty\<^isub>n"}, then respectfulness amounts to showing that
1760
+ − 1567
1765
+ − 1568
\begin{center}
1770
+ − 1569
@{text "C\<^isub>i x\<^isub>1 \<dots> x\<^isub>n \<approx>ty C\<^isub>i y\<^isub>1 \<dots> y\<^isub>n"}
1765
+ − 1570
\end{center}
+ − 1571
+ − 1572
\noindent
2341
+ − 1573
are $\alpha$-equivalent under the assumption that @{text "x\<^isub>i \<approx>ty\<^isub>i y\<^isub>i"} holds for all recursive arguments
1770
+ − 1574
and @{text "x\<^isub>i = y\<^isub>i"} holds for all non-recursive arguments of @{text "C\<^isub>i"}. We can prove this by
+ − 1575
analysing the definition of @{text "\<approx>ty"}. For this proof to succeed we have to establish
1767
+ − 1576
the following auxiliary fact about binding functions. Given a binding function @{text bn\<^isub>i} defined
+ − 1577
for the type @{text ty\<^isub>i}, we have that
+ − 1578
%
1760
+ − 1579
\begin{center}
1767
+ − 1580
@{text "x \<approx>ty\<^isub>i y"} implies @{text "x \<approx>bn\<^isub>i y"}
1760
+ − 1581
\end{center}
1765
+ − 1582
+ − 1583
\noindent
1767
+ − 1584
This can be established by induction on the definition of @{text "\<approx>ty\<^isub>i"}.
1760
+ − 1585
1766
+ − 1586
Having established respectfulness for every raw term-constructor, the
1767
+ − 1587
quotient package is able to automatically deduce \eqref{distinctalpha} from \eqref{distinctraw}.
2341
+ − 1588
In fact we can from now on lift facts from the raw level to the $\alpha$-equated level
1770
+ − 1589
as long as they contain raw term-constructors only. The
+ − 1590
induction principles derived by the datatype package in Isabelle/HOL for the types @{text
1771
+ − 1591
"ty\<^bsub>1..n\<^esub>"} fall into this category. So we can also add to our infrastructure
1765
+ − 1592
induction principles that establish
1760
+ − 1593
1765
+ − 1594
\begin{center}
2134
+ − 1595
@{text "P\<^bsub>ty\<AL>\<^esub>\<^isub>1 y\<^isub>1 \<dots> P\<^bsub>ty\<AL>\<^esub>\<^isub>n y\<^isub>n "}
1765
+ − 1596
\end{center}
+ − 1597
+ − 1598
\noindent
2176
+ − 1599
for all @{text "y\<^isub>i"} whereby the variables @{text "P\<^bsub>ty\<AL>\<^esub>\<^isub>i"} stand for properties
1770
+ − 1600
defined over the types @{text "ty\<AL>\<^isub>1 \<dots> ty\<AL>\<^isub>n"}. The premises of
1767
+ − 1601
these induction principles look
1765
+ − 1602
as follows
+ − 1603
+ − 1604
\begin{center}
2134
+ − 1605
@{text "\<forall>x\<^isub>1\<dots>x\<^isub>n. P\<^bsub>ty\<AL>\<^esub>\<^isub>i x\<^isub>i \<and> \<dots> \<and> P\<^bsub>ty\<AL>\<^esub>\<^isub>j x\<^isub>j \<Rightarrow> P\<^bsub>ty\<AL>\<^esub> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n)"}
1765
+ − 1606
\end{center}
+ − 1607
+ − 1608
\noindent
+ − 1609
where the @{text "x\<^isub>i, \<dots>, x\<^isub>j"} are the recursive arguments of @{text "C\<^sup>\<alpha>"}.
1766
+ − 1610
Next we lift the permutation operations defined in \eqref{ceqvt} for
+ − 1611
the raw term-constructors @{text "C"}. These facts contain, in addition
1775
+ − 1612
to the term-constructors, also permutation operations. In order to make the
2176
+ − 1613
lifting go through,
1767
+ − 1614
we have to know that the permutation operations are respectful
2341
+ − 1615
w.r.t.~$\alpha$-equivalence. This amounts to showing that the
+ − 1616
$\alpha$-equivalence relations are equivariant, which we already established
1770
+ − 1617
in Lemma~\ref{equiv}. As a result we can establish the equations
1766
+ − 1618
1956
+ − 1619
\begin{equation}\label{calphaeqvt}
1766
+ − 1620
@{text "p \<bullet> (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n) = C\<^sup>\<alpha> (p \<bullet> x\<^isub>1) \<dots> (p \<bullet> x\<^isub>n)"}
+ − 1621
\end{equation}
1717
+ − 1622
1766
+ − 1623
\noindent
1770
+ − 1624
for our infrastructure. In a similar fashion we can lift the equations
2347
+ − 1625
characterising the free-atom functions @{text "fn_ty\<AL>\<^isub>j"} and @{text "fa_bn\<AL>\<^isub>k"}, and the
1775
+ − 1626
binding functions @{text "bn\<AL>\<^isub>k"}. The necessary respectfulness lemmas for these
1770
+ − 1627
lifting are the properties:
1766
+ − 1628
%
+ − 1629
\begin{equation}\label{fnresp}
+ − 1630
\mbox{%
+ − 1631
\begin{tabular}{l}
2347
+ − 1632
@{text "x \<approx>ty\<^isub>j y"} implies @{text "fa_ty\<^isub>j x = fa_ty\<^isub>j y"}\\
+ − 1633
@{text "x \<approx>ty\<^isub>k y"} implies @{text "fa_bn\<^isub>k x = fa_bn\<^isub>k y"}\\
1770
+ − 1634
@{text "x \<approx>ty\<^isub>k y"} implies @{text "bn\<^isub>k x = bn\<^isub>k y"}
1766
+ − 1635
\end{tabular}}
+ − 1636
\end{equation}
1717
+ − 1637
1766
+ − 1638
\noindent
1767
+ − 1639
which can be established by induction on @{text "\<approx>ty"}. Whereas the first
2347
+ − 1640
property is always true by the way we defined the free-atom
1770
+ − 1641
functions for types, the second and third do \emph{not} hold in general. There is, in principle,
1767
+ − 1642
the possibility that the user defines @{text "bn\<^isub>k"} so that it returns an already bound
2347
+ − 1643
atom. Then the third property is just not true. However, our
1767
+ − 1644
restrictions imposed on the binding functions
+ − 1645
exclude this possibility.
1766
+ − 1646
1767
+ − 1647
Having the facts \eqref{fnresp} at our disposal, we can lift the
1766
+ − 1648
definitions that characterise when two terms of the form
1717
+ − 1649
1718
+ − 1650
\begin{center}
1766
+ − 1651
@{text "C x\<^isub>1 \<dots> x\<^isub>n \<approx>ty C y\<^isub>1 \<dots> y\<^isub>n"}
+ − 1652
\end{center}
+ − 1653
+ − 1654
\noindent
2341
+ − 1655
are $\alpha$-equivalent. This gives us conditions when the corresponding
+ − 1656
$\alpha$-equated terms are \emph{equal}, namely
1766
+ − 1657
+ − 1658
\begin{center}
+ − 1659
@{text "C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n = C\<^sup>\<alpha> y\<^isub>1 \<dots> y\<^isub>n"}
+ − 1660
\end{center}
+ − 1661
+ − 1662
\noindent
1767
+ − 1663
We call these conditions as \emph{quasi-injectivity}. Except for one function, which
1770
+ − 1664
we have to lift in the next section, we completed
+ − 1665
the lifting part of establishing the reasoning infrastructure.
1766
+ − 1666
2341
+ − 1667
By working now completely on the $\alpha$-equated level, we can first show that
2347
+ − 1668
the free-atom functions and binding functions
1766
+ − 1669
are equivariant, namely
+ − 1670
+ − 1671
\begin{center}
+ − 1672
\begin{tabular}{rcl}
2347
+ − 1673
@{text "p \<bullet> (fa_ty\<^sup>\<alpha> x)"} & $=$ & @{text "fa_ty\<^sup>\<alpha> (p \<bullet> x)"}\\
+ − 1674
@{text "p \<bullet> (fa_bn\<^sup>\<alpha> x)"} & $=$ & @{text "fa_bn\<^sup>\<alpha> (p \<bullet> x)"}\\
1766
+ − 1675
@{text "p \<bullet> (bn\<^sup>\<alpha> x)"} & $=$ & @{text "bn\<^sup>\<alpha> (p \<bullet> x)"}
1718
+ − 1676
\end{tabular}
+ − 1677
\end{center}
1717
+ − 1678
1766
+ − 1679
\noindent
1770
+ − 1680
These properties can be established by structural induction over the @{text x}
+ − 1681
(using the induction principles we lifted above for the types @{text "ty\<AL>\<^bsub>1..n\<^esub>"}).
1766
+ − 1682
1770
+ − 1683
Until now we have not yet derived anything about the support of the
2341
+ − 1684
$\alpha$-equated terms. This however will be necessary in order to derive
1770
+ − 1685
the strong induction principles in the next section.
+ − 1686
Using the equivariance properties in \eqref{ceqvt} we can
1766
+ − 1687
show for every term-constructor @{text "C\<^sup>\<alpha>"} that
+ − 1688
+ − 1689
\begin{center}
1770
+ − 1690
@{text "(supp x\<^isub>1 \<union> \<dots> supp x\<^isub>n) supports (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n)"}
1766
+ − 1691
\end{center}
+ − 1692
+ − 1693
\noindent
1770
+ − 1694
holds. This together with Property~\ref{supportsprop} allows us to show
1766
+ − 1695
+ − 1696
\begin{center}
+ − 1697
@{text "finite (supp x\<^isub>i)"}
+ − 1698
\end{center}
1721
+ − 1699
1766
+ − 1700
\noindent
1767
+ − 1701
by a structural induction over @{text "x\<^isub>1, \<dots>, x\<^isub>n"} (whereby @{text "x\<^isub>i"} ranges over the types
1766
+ − 1702
@{text "ty\<AL>\<^isub>1 \<dots> ty\<AL>\<^isub>n"}). Lastly, we can show that the support of elements in
2347
+ − 1703
@{text "ty\<AL>\<^bsub>1..n\<^esub>"} coincides with @{text "fa_ty\<AL>\<^bsub>1..n\<^esub>"}.
1766
+ − 1704
1767
+ − 1705
\begin{lemma}
+ − 1706
For every @{text "x\<^isub>i"} of type @{text "ty\<AL>\<^bsub>1..n\<^esub>"}, we have that
2347
+ − 1707
@{text "supp x\<^isub>i = fa_ty\<AL>\<^isub>i x\<^isub>i"} holds.
1722
+ − 1708
\end{lemma}
1766
+ − 1709
1722
+ − 1710
\begin{proof}
1766
+ − 1711
The proof proceeds by structural induction over the @{text "x\<^isub>i"}. In each case
+ − 1712
we unfold the definition of @{text "supp"}, move the swapping inside the
1770
+ − 1713
term-constructors and the use then quasi-injectivity lemmas in order to complete the
+ − 1714
proof. For the abstraction cases we use the facts derived in Theorem~\ref{suppabs}.
1722
+ − 1715
\end{proof}
1721
+ − 1716
1766
+ − 1717
\noindent
1770
+ − 1718
To sum up, we can established automatically a reasoning infrastructure
1768
+ − 1719
for the types @{text "ty\<AL>\<^isub>1, \<dots>, ty\<AL>\<^isub>n"}
1766
+ − 1720
by first lifting definitions from the raw level to the quotient level and
+ − 1721
then establish facts about these lifted definitions. All necessary proofs
1770
+ − 1722
are generated automatically by custom ML-code. This code can deal with
1768
+ − 1723
specifications like the one shown in Figure~\ref{nominalcorehas} for Core-Haskell.
1728
+ − 1724
1766
+ − 1725
\begin{figure}[t!]
+ − 1726
\begin{boxedminipage}{\linewidth}
+ − 1727
\small
+ − 1728
\begin{tabular}{l}
+ − 1729
\isacommand{atom\_decl}~@{text "var"}\\
+ − 1730
\isacommand{atom\_decl}~@{text "cvar"}\\
+ − 1731
\isacommand{atom\_decl}~@{text "tvar"}\\[1mm]
+ − 1732
\isacommand{nominal\_datatype}~@{text "tkind ="}\\
+ − 1733
\phantom{$|$}~@{text "KStar"}~$|$~@{text "KFun tkind tkind"}\\
+ − 1734
\isacommand{and}~@{text "ckind ="}\\
+ − 1735
\phantom{$|$}~@{text "CKSim ty ty"}\\
+ − 1736
\isacommand{and}~@{text "ty ="}\\
+ − 1737
\phantom{$|$}~@{text "TVar tvar"}~$|$~@{text "T string"}~$|$~@{text "TApp ty ty"}\\
+ − 1738
$|$~@{text "TFun string ty_list"}~%
+ − 1739
$|$~@{text "TAll tv::tvar tkind ty::ty"} \isacommand{bind}~@{text "tv"}~\isacommand{in}~@{text ty}\\
+ − 1740
$|$~@{text "TArr ckind ty"}\\
+ − 1741
\isacommand{and}~@{text "ty_lst ="}\\
+ − 1742
\phantom{$|$}~@{text "TNil"}~$|$~@{text "TCons ty ty_lst"}\\
+ − 1743
\isacommand{and}~@{text "cty ="}\\
+ − 1744
\phantom{$|$}~@{text "CVar cvar"}~%
+ − 1745
$|$~@{text "C string"}~$|$~@{text "CApp cty cty"}~$|$~@{text "CFun string co_lst"}\\
+ − 1746
$|$~@{text "CAll cv::cvar ckind cty::cty"} \isacommand{bind}~@{text "cv"}~\isacommand{in}~@{text cty}\\
+ − 1747
$|$~@{text "CArr ckind cty"}~$|$~@{text "CRefl ty"}~$|$~@{text "CSym cty"}~$|$~@{text "CCirc cty cty"}\\
+ − 1748
$|$~@{text "CAt cty ty"}~$|$~@{text "CLeft cty"}~$|$~@{text "CRight cty"}~$|$~@{text "CSim cty cty"}\\
+ − 1749
$|$~@{text "CRightc cty"}~$|$~@{text "CLeftc cty"}~$|$~@{text "Coerce cty cty"}\\
+ − 1750
\isacommand{and}~@{text "co_lst ="}\\
+ − 1751
\phantom{$|$}@{text "CNil"}~$|$~@{text "CCons cty co_lst"}\\
+ − 1752
\isacommand{and}~@{text "trm ="}\\
+ − 1753
\phantom{$|$}~@{text "Var var"}~$|$~@{text "K string"}\\
+ − 1754
$|$~@{text "LAM_ty tv::tvar tkind t::trm"} \isacommand{bind}~@{text "tv"}~\isacommand{in}~@{text t}\\
+ − 1755
$|$~@{text "LAM_cty cv::cvar ckind t::trm"} \isacommand{bind}~@{text "cv"}~\isacommand{in}~@{text t}\\
+ − 1756
$|$~@{text "App_ty trm ty"}~$|$~@{text "App_cty trm cty"}~$|$~@{text "App trm trm"}\\
+ − 1757
$|$~@{text "Lam v::var ty t::trm"} \isacommand{bind}~@{text "v"}~\isacommand{in}~@{text t}\\
+ − 1758
$|$~@{text "Let x::var ty trm t::trm"} \isacommand{bind}~@{text x}~\isacommand{in}~@{text t}\\
+ − 1759
$|$~@{text "Case trm assoc_lst"}~$|$~@{text "Cast trm co"}\\
+ − 1760
\isacommand{and}~@{text "assoc_lst ="}\\
+ − 1761
\phantom{$|$}~@{text ANil}~%
+ − 1762
$|$~@{text "ACons p::pat t::trm assoc_lst"} \isacommand{bind}~@{text "bv p"}~\isacommand{in}~@{text t}\\
+ − 1763
\isacommand{and}~@{text "pat ="}\\
+ − 1764
\phantom{$|$}~@{text "Kpat string tvtk_lst tvck_lst vt_lst"}\\
+ − 1765
\isacommand{and}~@{text "vt_lst ="}\\
+ − 1766
\phantom{$|$}~@{text VTNil}~$|$~@{text "VTCons var ty vt_lst"}\\
+ − 1767
\isacommand{and}~@{text "tvtk_lst ="}\\
+ − 1768
\phantom{$|$}~@{text TVTKNil}~$|$~@{text "TVTKCons tvar tkind tvtk_lst"}\\
+ − 1769
\isacommand{and}~@{text "tvck_lst ="}\\
+ − 1770
\phantom{$|$}~@{text TVCKNil}~$|$ @{text "TVCKCons cvar ckind tvck_lst"}\\
+ − 1771
\isacommand{binder}\\
+ − 1772
@{text "bv :: pat \<Rightarrow> atom list"}~\isacommand{and}~%
+ − 1773
@{text "bv1 :: vt_lst \<Rightarrow> atom list"}~\isacommand{and}\\
+ − 1774
@{text "bv2 :: tvtk_lst \<Rightarrow> atom list"}~\isacommand{and}~%
+ − 1775
@{text "bv3 :: tvck_lst \<Rightarrow> atom list"}\\
+ − 1776
\isacommand{where}\\
+ − 1777
\phantom{$|$}~@{text "bv (K s tvts tvcs vs) = (bv3 tvts) @ (bv2 tvcs) @ (bv1 vs)"}\\
+ − 1778
$|$~@{text "bv1 VTNil = []"}\\
+ − 1779
$|$~@{text "bv1 (VTCons x ty tl) = (atom x)::(bv1 tl)"}\\
+ − 1780
$|$~@{text "bv2 TVTKNil = []"}\\
+ − 1781
$|$~@{text "bv2 (TVTKCons a ty tl) = (atom a)::(bv2 tl)"}\\
+ − 1782
$|$~@{text "bv3 TVCKNil = []"}\\
+ − 1783
$|$~@{text "bv3 (TVCKCons c cty tl) = (atom c)::(bv3 tl)"}\\
+ − 1784
\end{tabular}
+ − 1785
\end{boxedminipage}
1890
+ − 1786
\caption{The nominal datatype declaration for Core-Haskell. For the moment we
1766
+ − 1787
do not support nested types; therefore we explicitly have to unfold the
+ − 1788
lists @{text "co_lst"}, @{text "assoc_lst"} and so on. This will be improved
+ − 1789
in a future version of Nominal Isabelle. Apart from that, the
+ − 1790
declaration follows closely the original in Figure~\ref{corehas}. The
+ − 1791
point of our work is that having made such a declaration in Nominal Isabelle,
+ − 1792
one obtains automatically a reasoning infrastructure for Core-Haskell.
+ − 1793
\label{nominalcorehas}}
+ − 1794
\end{figure}
+ − 1795
*}
1728
+ − 1796
1587
+ − 1797
1747
+ − 1798
section {* Strong Induction Principles *}
+ − 1799
+ − 1800
text {*
1764
+ − 1801
In the previous section we were able to provide induction principles that
2341
+ − 1802
allow us to perform structural inductions over $\alpha$-equated terms.
1770
+ − 1803
We call such induction principles \emph{weak}, because in case of a term-constructor @{text "C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n"},
1764
+ − 1804
the induction hypothesis requires us to establish the implication
+ − 1805
%
+ − 1806
\begin{equation}\label{weakprem}
+ − 1807
@{text "\<forall>x\<^isub>1\<dots>x\<^isub>n. P\<^isub>i x\<^isub>i \<and> \<dots> \<and> P\<^isub>j x\<^isub>j \<Rightarrow> P (C\<^sup>\<alpha> x\<^isub>1 \<dots> x\<^isub>n)"}
+ − 1808
\end{equation}
+ − 1809
+ − 1810
\noindent
+ − 1811
where the @{text "x\<^isub>i, \<dots>, x\<^isub>j"} are the recursive arguments of @{text "C\<^sup>\<alpha>"}.
1770
+ − 1812
The problem with this implication is that in general it is not easy to establish it.
1771
+ − 1813
The reason is that we cannot make any assumption about the binders that might be in @{text "C\<^sup>\<alpha>"}
1770
+ − 1814
(for example we cannot assume the variable convention for them).
1764
+ − 1815
+ − 1816
In \cite{UrbanTasson05} we introduced a method for automatically
+ − 1817
strengthening weak induction principles for terms containing single
1768
+ − 1818
binders. These stronger induction principles allow the user to make additional
1771
+ − 1819
assumptions about binders.
1768
+ − 1820
These additional assumptions amount to a formal
+ − 1821
version of the informal variable convention for binders. A natural question is
+ − 1822
whether we can also strengthen the weak induction principles involving
1771
+ − 1823
the general binders presented here. We will indeed be able to so, but for this we need an
1770
+ − 1824
additional notion for permuting deep binders.
1764
+ − 1825
1768
+ − 1826
Given a binding function @{text "bn"} we define an auxiliary permutation
1764
+ − 1827
operation @{text "_ \<bullet>\<^bsub>bn\<^esub> _"} which permutes only bound arguments in a deep binder.
1770
+ − 1828
Assuming a clause of @{text bn} is defined as @{text "bn (C x\<^isub>1 \<dots> x\<^isub>n) = rhs"}, then
+ − 1829
we define %
1764
+ − 1830
\begin{center}
+ − 1831
@{text "p \<bullet>\<^bsub>bn\<^esub> (C x\<^isub>1 \<dots> x\<^isub>n) \<equiv> C y\<^isub>1 \<dots> y\<^isub>n"}
+ − 1832
\end{center}
+ − 1833
+ − 1834
\noindent
+ − 1835
with @{text "y\<^isub>i"} determined as follows:
+ − 1836
%
+ − 1837
\begin{center}
+ − 1838
\begin{tabular}{c@ {\hspace{2mm}}p{7cm}}
+ − 1839
$\bullet$ & @{text "y\<^isub>i \<equiv> x\<^isub>i"} provided @{text "x\<^isub>i"} does not occur in @{text "rhs"}\\
+ − 1840
$\bullet$ & @{text "y\<^isub>i \<equiv> p \<bullet>\<^bsub>bn'\<^esub> x\<^isub>i"} provided @{text "bn' x\<^isub>i"} is in @{text "rhs"}\\
+ − 1841
$\bullet$ & @{text "y\<^isub>i \<equiv> p \<bullet> x\<^isub>i"} otherwise
+ − 1842
\end{tabular}
+ − 1843
\end{center}
+ − 1844
+ − 1845
\noindent
1771
+ − 1846
Using again the quotient package we can lift the @{text "_ \<bullet>\<^bsub>bn\<^esub> _"} function to
2341
+ − 1847
$\alpha$-equated terms. We can then prove the following two facts
1764
+ − 1848
1770
+ − 1849
\begin{lemma}\label{permutebn}
+ − 1850
Given a binding function @{text "bn\<^sup>\<alpha>"} then for all @{text p}
2134
+ − 1851
{\it i)} @{text "p \<bullet> (bn\<^sup>\<alpha> x) = bn\<^sup>\<alpha> (p \<bullet>\<^bsub>bn\<^esub>\<^sup>\<alpha> x)"} and {\it ii)}
2347
+ − 1852
@{text "fa_bn\<^isup>\<alpha> x = fa_bn\<^isup>\<alpha> (p \<bullet>\<^bsub>bn\<^esub>\<^sup>\<alpha> x)"}.
1764
+ − 1853
\end{lemma}
+ − 1854
+ − 1855
\begin{proof}
1771
+ − 1856
By induction on @{text x}. The equations follow by simple unfolding
1764
+ − 1857
of the definitions.
+ − 1858
\end{proof}
+ − 1859
1769
+ − 1860
\noindent
1768
+ − 1861
The first property states that a permutation applied to a binding function is
+ − 1862
equivalent to first permuting the binders and then calculating the bound
2347
+ − 1863
atoms. The second amounts to the fact that permuting the binders has no
+ − 1864
effect on the free-atom function. The main point of this permutation
1769
+ − 1865
function, however, is that if we have a permutation that is fresh
+ − 1866
for the support of an object @{text x}, then we can use this permutation
1770
+ − 1867
to rename the binders in @{text x}, without ``changing'' @{text x}. In case of the
1769
+ − 1868
@{text "Let"} term-constructor from the example shown
1770
+ − 1869
\eqref{letpat} this means for a permutation @{text "r"}:
+ − 1870
%
+ − 1871
\begin{equation}\label{renaming}
1771
+ − 1872
\begin{array}{l}
+ − 1873
\mbox{if @{term "supp (Abs_lst (bn p) t\<^isub>2) \<sharp>* r"}}\\
2134
+ − 1874
\qquad\mbox{then @{text "Let p t\<^isub>1 t\<^isub>2 = Let (r \<bullet>\<^bsub>bnpat\<^esub> p) t\<^isub>1 (r \<bullet> t\<^isub>2)"}}
1771
+ − 1875
\end{array}
1770
+ − 1876
\end{equation}
1769
+ − 1877
+ − 1878
\noindent
1771
+ − 1879
This fact will be crucial when establishing the strong induction principles.
1770
+ − 1880
In our running example about @{text "Let"}, they state that instead
+ − 1881
of establishing the implication
1764
+ − 1882
+ − 1883
\begin{center}
1771
+ − 1884
@{text "\<forall>p t\<^isub>1 t\<^isub>2. P\<^bsub>pat\<^esub> p \<and> P\<^bsub>trm\<^esub> t\<^isub>1 \<and> P\<^bsub>trm\<^esub> t\<^isub>2 \<Rightarrow> P\<^bsub>trm\<^esub> (Let p t\<^isub>1 t\<^isub>2)"}
1764
+ − 1885
\end{center}
+ − 1886
+ − 1887
\noindent
1769
+ − 1888
it is sufficient to establish the following implication
1770
+ − 1889
%
+ − 1890
\begin{equation}\label{strong}
+ − 1891
\mbox{\begin{tabular}{l}
1771
+ − 1892
@{text "\<forall>p t\<^isub>1 t\<^isub>2 c."}\\
+ − 1893
\hspace{5mm}@{text "set (bn p) #\<^sup>* c \<and>"}\\
+ − 1894
\hspace{5mm}@{text "(\<forall>d. P\<^bsub>pat\<^esub> d p) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t\<^isub>1) \<and> (\<forall>d. P\<^bsub>trm\<^esub> d t\<^isub>2)"}\\
+ − 1895
\hspace{15mm}@{text "\<Rightarrow> P\<^bsub>trm\<^esub> c (Let p t\<^isub>1 t\<^isub>2)"}
1770
+ − 1896
\end{tabular}}
+ − 1897
\end{equation}
+ − 1898
+ − 1899
\noindent
+ − 1900
While this implication contains an additional argument, namely @{text c}, and
+ − 1901
also additional universal quantifications, it is usually easier to establish.
+ − 1902
The reason is that we can make the freshness
+ − 1903
assumption @{text "set (bn\<^sup>\<alpha> p) #\<^sup>* c"}, whereby @{text c} can be arbitrarily
+ − 1904
chosen by the user as long as it has finite support.
+ − 1905
+ − 1906
Let us now show how we derive the strong induction principles from the
+ − 1907
weak ones. In case of the @{text "Let"}-example we derive by the weak
+ − 1908
induction the following two properties
+ − 1909
%
+ − 1910
\begin{equation}\label{hyps}
+ − 1911
@{text "\<forall>q c. P\<^bsub>trm\<^esub> c (q \<bullet> t)"} \hspace{4mm}
+ − 1912
@{text "\<forall>q\<^isub>1 q\<^isub>2 c. P\<^bsub>pat\<^esub> (q\<^isub>1 \<bullet>\<^bsub>bn\<^esub> (q\<^isub>2 \<bullet> p))"}
+ − 1913
\end{equation}
+ − 1914
+ − 1915
\noindent
1771
+ − 1916
For the @{text Let} term-constructor we therefore have to establish @{text "P\<^bsub>trm\<^esub> c (q \<bullet> Let p t\<^isub>1 t\<^isub>2)"}
+ − 1917
assuming \eqref{hyps} as induction hypotheses (the first for @{text t\<^isub>1} and @{text t\<^isub>2}).
+ − 1918
By Property~\ref{avoiding} we
1770
+ − 1919
obtain a permutation @{text "r"} such that
+ − 1920
%
+ − 1921
\begin{equation}\label{rprops}
+ − 1922
@{term "(r \<bullet> set (bn (q \<bullet> p))) \<sharp>* c "}\hspace{4mm}
1771
+ − 1923
@{term "supp (Abs_lst (bn (q \<bullet> p)) (q \<bullet> t\<^isub>2)) \<sharp>* r"}
1770
+ − 1924
\end{equation}
+ − 1925
+ − 1926
\noindent
+ − 1927
hold. The latter fact and \eqref{renaming} give us
+ − 1928
1765
+ − 1929
\begin{center}
1771
+ − 1930
\begin{tabular}{l}
+ − 1931
@{text "Let (q \<bullet> p) (q \<bullet> t\<^isub>1) (q \<bullet> t\<^isub>2) ="} \\
+ − 1932
\hspace{15mm}@{text "Let (r \<bullet>\<^bsub>bn\<^esub> (q \<bullet> p)) (q \<bullet> t\<^isub>1) (r \<bullet> (q \<bullet> t\<^isub>2))"}
+ − 1933
\end{tabular}
1770
+ − 1934
\end{center}
+ − 1935
+ − 1936
\noindent
2176
+ − 1937
So instead of proving @{text "P\<^bsub>trm\<^esub> c (q \<bullet> Let p t\<^isub>1 t\<^isub>2)"}, we can equally
1770
+ − 1938
establish
+ − 1939
+ − 1940
\begin{center}
1771
+ − 1941
@{text "P\<^bsub>trm\<^esub> c (Let (r \<bullet>\<^bsub>bn\<^esub> (q \<bullet> p)) (q \<bullet> t\<^isub>1) (r \<bullet> (q \<bullet> t\<^isub>2)))"}
1770
+ − 1942
\end{center}
+ − 1943
+ − 1944
\noindent
+ − 1945
To do so, we will use the implication \eqref{strong} of the strong induction
+ − 1946
principle, which requires us to discharge
1771
+ − 1947
the following four proof obligations:
1770
+ − 1948
+ − 1949
\begin{center}
+ − 1950
\begin{tabular}{rl}
+ − 1951
{\it i)} & @{text "set (bn (r \<bullet>\<^bsub>bn\<^esub> (q \<bullet> p))) #\<^sup>* c"}\\
+ − 1952
{\it ii)} & @{text "\<forall>d. P\<^bsub>pat\<^esub> d (r \<bullet>\<^bsub>bn\<^esub> (q \<bullet> p))"}\\
1771
+ − 1953
{\it iii)} & @{text "\<forall>d. P\<^bsub>trm\<^esub> d (q \<bullet> t\<^isub>1)"}\\
+ − 1954
{\it iv)} & @{text "\<forall>d. P\<^bsub>trm\<^esub> d (r \<bullet> (q \<bullet> t\<^isub>2))"}\\
1765
+ − 1955
\end{tabular}
+ − 1956
\end{center}
1764
+ − 1957
1770
+ − 1958
\noindent
+ − 1959
The first follows from \eqref{rprops} and Lemma~\ref{permutebn}.{\it i)}; the
1771
+ − 1960
others from the induction hypotheses in \eqref{hyps} (in the fourth case
+ − 1961
we have to use the fact that @{term "(r \<bullet> (q \<bullet> t\<^isub>2)) = (r + q) \<bullet> t\<^isub>2"}).
1748
+ − 1962
1770
+ − 1963
Taking now the identity permutation @{text 0} for the permutations in \eqref{hyps},
+ − 1964
we can establish our original goals, namely @{text "P\<^bsub>trm\<^esub> c t"} and \mbox{@{text "P\<^bsub>pat\<^esub> c p"}}.
+ − 1965
This completes the proof showing that the strong induction principle derives from
1890
+ − 1966
the weak induction principle. For the moment we can derive the difficult cases of
2176
+ − 1967
the strong induction principles only by hand, but they are very schematic
1771
+ − 1968
so that with little effort we can even derive them for
1770
+ − 1969
Core-Haskell given in Figure~\ref{nominalcorehas}.
1747
+ − 1970
*}
+ − 1971
1702
+ − 1972
1517
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1973
section {* Related Work *}
62d6f7acc110
corrected the strong induction principle in the lambda-calculus case; gave a second (oartial) version that is more elegant
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 1974
1570
+ − 1975
text {*
2342
+ − 1976
To our knowledge the earliest usage of general binders in a theorem prover
1760
+ − 1977
is described in \cite{NaraschewskiNipkow99} about a formalisation of the
+ − 1978
algorithm W. This formalisation implements binding in type schemes using a
1764
+ − 1979
de-Bruijn indices representation. Since type schemes of W contain only a single
1760
+ − 1980
binder, different indices do not refer to different binders (as in the usual
+ − 1981
de-Bruijn representation), but to different bound variables. A similar idea
+ − 1982
has been recently explored for general binders in the locally nameless
1764
+ − 1983
approach to binding \cite{chargueraud09}. There, de-Bruijn indices consist
1760
+ − 1984
of two numbers, one referring to the place where a variable is bound and the
+ − 1985
other to which variable is bound. The reasoning infrastructure for both
2163
+ − 1986
representations of bindings comes for free in theorem provers like Isabelle/HOL or
2342
+ − 1987
Coq, since the corresponding term-calculi can be implemented as ``normal''
1764
+ − 1988
datatypes. However, in both approaches it seems difficult to achieve our
+ − 1989
fine-grained control over the ``semantics'' of bindings (i.e.~whether the
+ − 1990
order of binders should matter, or vacuous binders should be taken into
+ − 1991
account). To do so, one would require additional predicates that filter out
2163
+ − 1992
unwanted terms. Our guess is that such predicates result in rather
1764
+ − 1993
intricate formal reasoning.
1740
+ − 1994
+ − 1995
Another representation technique for binding is higher-order abstract syntax
1764
+ − 1996
(HOAS), which for example is implemented in the Twelf system. This representation
1760
+ − 1997
technique supports very elegantly many aspects of \emph{single} binding, and
2342
+ − 1998
impressive work has been done that uses HOAS for mechanising the metatheory
1764
+ − 1999
of SML~\cite{LeeCraryHarper07}. We are, however, not aware how multiple
+ − 2000
binders of SML are represented in this work. Judging from the submitted
+ − 2001
Twelf-solution for the POPLmark challenge, HOAS cannot easily deal with
+ − 2002
binding constructs where the number of bound variables is not fixed. For
+ − 2003
example in the second part of this challenge, @{text "Let"}s involve
+ − 2004
patterns that bind multiple variables at once. In such situations, HOAS
+ − 2005
representations have to resort to the iterated-single-binders-approach with
+ − 2006
all the unwanted consequences when reasoning about the resulting terms.
1740
+ − 2007
1764
+ − 2008
Two formalisations involving general binders have also been performed in older
2342
+ − 2009
versions of Nominal Isabelle (one about Psi-calculi and one about algorithm W
2163
+ − 2010
\cite{BengtsonParow09, UrbanNipkow09}). Both
1764
+ − 2011
use the approach based on iterated single binders. Our experience with
+ − 2012
the latter formalisation has been disappointing. The major pain arose from
+ − 2013
the need to ``unbind'' variables. This can be done in one step with our
2163
+ − 2014
general binders, but needs a cumbersome
1764
+ − 2015
iteration with single binders. The resulting formal reasoning turned out to
+ − 2016
be rather unpleasant. The hope is that the extension presented in this paper
+ − 2017
is a substantial improvement.
1726
+ − 2018
2163
+ − 2019
The most closely related work to the one presented here is the Ott-tool
+ − 2020
\cite{ott-jfp} and the C$\alpha$ml language \cite{Pottier06}. Ott is a nifty
+ − 2021
front-end for creating \LaTeX{} documents from specifications of
2343
+ − 2022
term-calculi involving general binders. For a subset of the specifications
2163
+ − 2023
Ott can also generate theorem prover code using a raw representation of
+ − 2024
terms, and in Coq also a locally nameless representation. The developers of
+ − 2025
this tool have also put forward (on paper) a definition for
2341
+ − 2026
$\alpha$-equivalence of terms that can be specified in Ott. This definition is
2163
+ − 2027
rather different from ours, not using any nominal techniques. To our
+ − 2028
knowledge there is also no concrete mathematical result concerning this
2341
+ − 2029
notion of $\alpha$-equivalence. A definition for the notion of free variables
2163
+ − 2030
in a term are work in progress in Ott.
+ − 2031
+ − 2032
Although we were heavily inspired by their syntax,
2341
+ − 2033
their definition of $\alpha$-equivalence is unsuitable for our extension of
1760
+ − 2034
Nominal Isabelle. First, it is far too complicated to be a basis for
+ − 2035
automated proofs implemented on the ML-level of Isabelle/HOL. Second, it
+ − 2036
covers cases of binders depending on other binders, which just do not make
2341
+ − 2037
sense for our $\alpha$-equated terms. Third, it allows empty types that have no
2163
+ − 2038
meaning in a HOL-based theorem prover. We also had to generalise slightly their
+ − 2039
binding clauses. In Ott you specify binding clauses with a single body; we
+ − 2040
allow more than one. We have to do this, because this makes a difference
2341
+ − 2041
for our notion of $\alpha$-equivalence in case of \isacommand{bind\_set} and
2163
+ − 2042
\isacommand{bind\_res}. This makes
+ − 2043
+ − 2044
\begin{center}
2341
+ − 2045
\begin{tabular}{@ {}l@ {\hspace{2mm}}l@ {}}
+ − 2046
@{text "Foo\<^isub>1 xs::name fset t::trm s::trm"} &
+ − 2047
\isacommand{bind\_set} @{text "xs"} \isacommand{in} @{text "t s"}\\
+ − 2048
@{text "Foo\<^isub>2 xs::name fset t::trm s::trm"} &
+ − 2049
\isacommand{bind\_set} @{text "xs"} \isacommand{in} @{text "t"},
+ − 2050
\isacommand{bind\_set} @{text "xs"} \isacommand{in} @{text "s"}\\
2163
+ − 2051
\end{tabular}
+ − 2052
\end{center}
+ − 2053
+ − 2054
\noindent
2341
+ − 2055
behave differently. In the first term-constructor, we essentially have a single
+ − 2056
body, which happens to be ``spread'' over two arguments; in the second we have
+ − 2057
two independent bodies, in which the same variables are bound. As a result we
+ − 2058
have
+ − 2059
+ − 2060
\begin{center}
+ − 2061
\begin{tabular}{r@ {\hspace{1.5mm}}c@ {\hspace{1.5mm}}l}
+ − 2062
@{text "Foo\<^isub>1 {a, b} (a, b) (a, b)"} & $\not=$ &
+ − 2063
@{text "Foo\<^isub>1 {a, b} (a, b) (b, a)"}\\
+ − 2064
@{text "Foo\<^isub>2 {a, b} (a, b) (a, b)"} & $=$ &
+ − 2065
@{text "Foo\<^isub>2 {a, b} (a, b) (b, a)"}\\
+ − 2066
\end{tabular}
+ − 2067
\end{center}
+ − 2068
1764
+ − 2069
Because of how we set up our definitions, we had to impose restrictions,
2163
+ − 2070
like a single binding function for a deep binder, that are not present in Ott. Our
1764
+ − 2071
expectation is that we can still cover many interesting term-calculi from
1771
+ − 2072
programming language research, for example Core-Haskell. For providing support
1764
+ − 2073
of neat features in Ott, such as subgrammars, the existing datatype
+ − 2074
infrastructure in Isabelle/HOL is unfortunately not powerful enough. On the
+ − 2075
other hand, we are not aware that Ott can make the distinction between our
2163
+ − 2076
three different binding modes.
+ − 2077
+ − 2078
Pottier presents in \cite{Pottier06} a language, called C$\alpha$ml, for
+ − 2079
representing terms with general binders inside OCaml. This language is
+ − 2080
implemented as a front-end that can be translated to OCaml with a help of
+ − 2081
a library. He presents a type-system in which the scope of general binders
2343
+ − 2082
can be indicated with some special markers, written @{text "inner"} and
2163
+ − 2083
@{text "outer"}. With this, it seems, our and his specifications can be
+ − 2084
inter-translated, but we have not proved this. However, we believe the
+ − 2085
binding specifications in the style of Ott are a more natural way for
+ − 2086
representing terms involving bindings. Pottier gives a definition for
2341
+ − 2087
$\alpha$-equivalence, which is similar to our binding mode \isacommand{bind}.
2163
+ − 2088
Although he uses also a permutation in case of abstractions, his
+ − 2089
definition is rather different from ours. He proves that his notion
2341
+ − 2090
of $\alpha$-equivalence is indeed a equivalence relation, but a complete
2163
+ − 2091
reasoning infrastructure is well beyond the purposes of his language.
2218
+ − 2092
In a slightly different domain (programming with dependent types), the
+ − 2093
paper \cite{Altenkirch10} presents a calculus with a notion of
2341
+ − 2094
$\alpha$-equivalence related to our binding mode \isacommand{bind\_res}.
2218
+ − 2095
This definition is similar to the one by Pottier, except that it
+ − 2096
has a more operational flavour and calculates a partial (renaming) map.
2342
+ − 2097
In this way they can handle vacuous binders. However, their notion of
2218
+ − 2098
equality between terms also includes rules for $\beta$ and to our
+ − 2099
knowledge no concrete mathematical result concerning their notion
+ − 2100
of equality has been proved.
1739
+ − 2101
*}
+ − 2102
1493
+ − 2103
section {* Conclusion *}
1485
+ − 2104
+ − 2105
text {*
2345
+ − 2106
We can also see that
+ − 2107
%
+ − 2108
\begin{equation}\label{bnprop}
2347
+ − 2109
@{text "fa_ty x = bn x \<union> fa_bn x"}.
2345
+ − 2110
\end{equation}
+ − 2111
+ − 2112
\noindent
+ − 2113
holds for any @{text "bn"}-function defined for the type @{text "ty"}.
+ − 2114
+ − 2115
*}
+ − 2116
+ − 2117
+ − 2118
text {*
1764
+ − 2119
We have presented an extension of Nominal Isabelle for deriving
+ − 2120
automatically a convenient reasoning infrastructure that can deal with
+ − 2121
general binders, that is term-constructors binding multiple variables at
+ − 2122
once. This extension has been tried out with the Core-Haskell
+ − 2123
term-calculus. For such general binders, we can also extend
+ − 2124
earlier work that derives strong induction principles which have the usual
1890
+ − 2125
variable convention already built in. For the moment we can do so only with manual help,
1764
+ − 2126
but future work will automate them completely. The code underlying the presented
+ − 2127
extension will become part of the Isabelle distribution, but for the moment
+ − 2128
it can be downloaded from the Mercurial repository linked at
1741
+ − 2129
\href{http://isabelle.in.tum.de/nominal/download}
+ − 2130
{http://isabelle.in.tum.de/nominal/download}.
+ − 2131
1764
+ − 2132
We have left out a discussion about how functions can be defined over
2341
+ − 2133
$\alpha$-equated terms that involve general binders. In earlier versions of Nominal
1764
+ − 2134
Isabelle \cite{UrbanBerghofer06} this turned out to be a thorny issue. We
+ − 2135
hope to do better this time by using the function package that has recently
+ − 2136
been implemented in Isabelle/HOL and also by restricting function
+ − 2137
definitions to equivariant functions (for such functions it is possible to
+ − 2138
provide more automation).
1741
+ − 2139
1847
+ − 2140
There are some restrictions we imposed in this paper, that we would like to lift in
1764
+ − 2141
future work. One is the exclusion of nested datatype definitions. Nested
+ − 2142
datatype definitions allow one to specify, for instance, the function kinds
+ − 2143
in Core-Haskell as @{text "TFun string (ty list)"} instead of the unfolded
+ − 2144
version @{text "TFun string ty_list"} in Figure~\ref{nominalcorehas}. For
+ − 2145
them we need a more clever implementation than we have at the moment.
+ − 2146
2163
+ − 2147
More interesting line of investigation is whether we can go beyond the
1771
+ − 2148
simple-minded form for binding functions that we adopted from Ott. At the moment, binding
1764
+ − 2149
functions can only return the empty set, a singleton atom set or unions
+ − 2150
of atom sets (similarly for lists). It remains to be seen whether
+ − 2151
properties like \eqref{bnprop} provide us with means to support more interesting
+ − 2152
binding functions.
+ − 2153
1726
+ − 2154
1763
+ − 2155
We have also not yet played with other binding modes. For example we can
1796
5165c350ee1a
clarified comment about distinct lists in th efuture work section
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2156
imagine that there is need for a binding mode \isacommand{bind\_\#list} with
5165c350ee1a
clarified comment about distinct lists in th efuture work section
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2157
an associated abstraction of the form
1763
+ − 2158
%
+ − 2159
\begin{center}
1796
5165c350ee1a
clarified comment about distinct lists in th efuture work section
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2160
@{term "Abs_dist as x"}
1763
+ − 2161
\end{center}
+ − 2162
+ − 2163
\noindent
1796
5165c350ee1a
clarified comment about distinct lists in th efuture work section
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2164
where instead of lists, we abstract lists of distinct elements.
5165c350ee1a
clarified comment about distinct lists in th efuture work section
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 2165
Once we feel confident about such binding modes, our implementation
1764
+ − 2166
can be easily extended to accommodate them.
1763
+ − 2167
+ − 2168
\medskip
1493
+ − 2169
\noindent
1528
+ − 2170
{\bf Acknowledgements:} We are very grateful to Andrew Pitts for
2342
+ − 2171
many discussions about Nominal Isabelle. We also thank Peter Sewell for
1506
+ − 2172
making the informal notes \cite{SewellBestiary} available to us and
2342
+ − 2173
also for patiently explaining some of the finer points of the work on the Ott-tool.
+ − 2174
Stephanie Weirich suggested to separate the subgrammars
1739
+ − 2175
of kinds and types in our Core-Haskell example.
2341
+ − 2176
754
+ − 2177
*}
+ − 2178
+ − 2179
(*<*)
+ − 2180
end
1704
+ − 2181
(*>*)