1785
|
1 |
(*<*)
|
|
2 |
theory Paper
|
|
3 |
imports "../Nominal-General/Nominal2_Base"
|
|
4 |
"../Nominal-General/Nominal2_Atoms"
|
2033
|
5 |
"../Nominal-General/Nominal2_Eqvt"
|
|
6 |
"../Nominal-General/Nominal2_Supp"
|
1785
|
7 |
"../Nominal-General/Atoms"
|
|
8 |
"LaTeXsugar"
|
|
9 |
begin
|
|
10 |
|
|
11 |
notation (latex output)
|
|
12 |
sort_of ("sort _" [1000] 100) and
|
|
13 |
Abs_perm ("_") and
|
|
14 |
Rep_perm ("_") and
|
|
15 |
swap ("'(_ _')" [1000, 1000] 1000) and
|
|
16 |
fresh ("_ # _" [51, 51] 50) and
|
|
17 |
Cons ("_::_" [78,77] 73) and
|
|
18 |
supp ("supp _" [78] 73) and
|
|
19 |
uminus ("-_" [78] 73) and
|
|
20 |
atom ("|_|") and
|
|
21 |
If ("if _ then _ else _" 10) and
|
|
22 |
Rep_name ("\<lfloor>_\<rfloor>") and
|
|
23 |
Abs_name ("\<lceil>_\<rceil>") and
|
|
24 |
Rep_var ("\<lfloor>_\<rfloor>") and
|
|
25 |
Abs_var ("\<lceil>_\<rceil>") and
|
|
26 |
sort_of_ty ("sort'_ty _")
|
|
27 |
|
|
28 |
(* BH: uncomment if you really prefer the dot notation
|
|
29 |
syntax (latex output)
|
|
30 |
"_Collect" :: "pttrn => bool => 'a set" ("(1{_ . _})")
|
|
31 |
*)
|
|
32 |
|
|
33 |
(* sort is used in Lists for sorting *)
|
2005
|
34 |
hide_const sort
|
1785
|
35 |
|
|
36 |
abbreviation
|
|
37 |
"sort \<equiv> sort_of"
|
|
38 |
|
|
39 |
abbreviation
|
|
40 |
"sort_ty \<equiv> sort_of_ty"
|
|
41 |
|
|
42 |
(*>*)
|
|
43 |
|
|
44 |
section {* Introduction *}
|
|
45 |
|
|
46 |
text {*
|
2065
|
47 |
Nominal Isabelle provides a proving infratructure for
|
|
48 |
convenient reasoning about programming languages. At its core Nominal
|
|
49 |
Isabelle is based on the nominal logic work by Pitts at al
|
|
50 |
\cite{GabbayPitts02,Pitts03}. The most basic notion in this work
|
|
51 |
is a sort-respecting permutation operation defined over a countably infinite
|
|
52 |
collection of sorted atoms. The atoms are used for representing variables
|
|
53 |
that might be bound. Multiple sorts are necessary for being able to
|
|
54 |
represent different kinds of variables. For example, in the language Mini-ML
|
|
55 |
there are bound term variables and bound type variables; each kind needs to
|
|
56 |
be represented by a different sort of atoms.
|
1785
|
57 |
|
|
58 |
Unfortunately, the type system of Isabelle/HOL is not a good fit for the way
|
|
59 |
atoms and sorts are used in the original formulation of the nominal logic work.
|
2065
|
60 |
The reason is that one has to ensure that permutations are sort-respecting.
|
|
61 |
This was done implicitly in the original nominal logic work \cite{Pitts03}.
|
|
62 |
|
|
63 |
|
1785
|
64 |
Isabelle used the two-place permutation operation with the generic type
|
|
65 |
|
|
66 |
@{text [display,indent=10] "_ \<bullet> _ :: (\<alpha> \<times> \<alpha>) list \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
|
|
67 |
|
|
68 |
\noindent
|
|
69 |
where @{text "\<alpha>"} stands for the type of atoms and @{text "\<beta>"} for the type
|
|
70 |
of the objects on which the permutation acts. For atoms of type @{text "\<alpha>"}
|
|
71 |
the permutation operation is defined over the length of lists as follows
|
|
72 |
|
|
73 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
74 |
\begin{tabular}{@ {}r@ {\hspace{2mm}}c@ {\hspace{2mm}}l}
|
|
75 |
@{text "[] \<bullet> c"} & @{text "="} & @{text c}\\
|
|
76 |
@{text "(a b)::\<pi> \<bullet> c"} & @{text "="} &
|
|
77 |
$\begin{cases} @{text a} & \textrm{if}~@{text "\<pi> \<bullet> c = b"}\\
|
|
78 |
@{text b} & \textrm{if}~@{text "\<pi> \<bullet> c = a"}\\
|
|
79 |
@{text "\<pi> \<bullet> c"} & \textrm{otherwise}\end{cases}$
|
|
80 |
\end{tabular}\hfill\numbered{atomperm}
|
|
81 |
\end{isabelle}
|
|
82 |
|
|
83 |
\noindent
|
|
84 |
where we write @{text "(a b)"} for a swapping of atoms @{text "a"} and
|
|
85 |
@{text "b"}. For atoms of different type, the permutation operation
|
|
86 |
is defined as @{text "\<pi> \<bullet> c \<equiv> c"}.
|
|
87 |
|
|
88 |
With the list representation of permutations it is impossible to state an
|
|
89 |
``ill-sorted'' permutation, since the type system excludes lists containing
|
|
90 |
atoms of different type. Another advantage of the list representation is that
|
|
91 |
the basic operations on permutations are already defined in the list library:
|
|
92 |
composition of two permutations (written @{text "_ @ _"}) is just list append,
|
|
93 |
and inversion of a permutation (written @{text "_\<^sup>-\<^sup>1"}) is just
|
|
94 |
list reversal. A disadvantage is that permutations do not have unique
|
|
95 |
representations as lists; we had to explicitly identify permutations according
|
|
96 |
to the relation
|
|
97 |
|
|
98 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
99 |
\begin{tabular}{@ {}l}
|
|
100 |
@{text "\<pi>\<^isub>1 \<sim> \<pi>\<^isub>2 \<equiv> \<forall>a. \<pi>\<^isub>1 \<bullet> a = \<pi>\<^isub>2 \<bullet> a"}
|
|
101 |
\end{tabular}\hfill\numbered{permequ}
|
|
102 |
\end{isabelle}
|
|
103 |
|
|
104 |
When lifting the permutation operation to other types, for example sets,
|
|
105 |
functions and so on, we needed to ensure that every definition is
|
|
106 |
well-behaved in the sense that it satisfies the following three
|
|
107 |
\emph{permutation properties}:
|
|
108 |
|
|
109 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
110 |
\begin{tabular}{@ {}r@ {\hspace{4mm}}p{10cm}}
|
|
111 |
i) & @{text "[] \<bullet> x = x"}\\
|
|
112 |
ii) & @{text "(\<pi>\<^isub>1 @ \<pi>\<^isub>2) \<bullet> x = \<pi>\<^isub>1 \<bullet> (\<pi>\<^isub>2 \<bullet> x)"}\\
|
|
113 |
iii) & if @{text "\<pi>\<^isub>1 \<sim> \<pi>\<^isub>2"} then @{text "\<pi>\<^isub>1 \<bullet> x = \<pi>\<^isub>2 \<bullet> x"}
|
|
114 |
\end{tabular}\hfill\numbered{permprops}
|
|
115 |
\end{isabelle}
|
|
116 |
|
|
117 |
\noindent
|
|
118 |
From these properties we were able to derive most facts about permutations, and
|
|
119 |
the type classes of Isabelle/HOL allowed us to reason abstractly about these
|
|
120 |
three properties, and then let the type system automatically enforce these
|
|
121 |
properties for each type.
|
|
122 |
|
|
123 |
The major problem with Isabelle/HOL's type classes, however, is that they
|
|
124 |
support operations with only a single type parameter and the permutation
|
|
125 |
operations @{text "_ \<bullet> _"} used above in the permutation properties
|
|
126 |
contain two! To work around this obstacle, Nominal Isabelle
|
|
127 |
required the user to
|
|
128 |
declare up-front the collection of \emph{all} atom types, say @{text
|
|
129 |
"\<alpha>\<^isub>1,\<dots>,\<alpha>\<^isub>n"}. From this collection it used custom ML-code to
|
|
130 |
generate @{text n} type classes corresponding to the permutation properties,
|
|
131 |
whereby in these type classes the permutation operation is restricted to
|
|
132 |
|
|
133 |
@{text [display,indent=10] "_ \<bullet> _ :: (\<alpha>\<^isub>i \<times> \<alpha>\<^isub>i) list \<Rightarrow> \<beta> \<Rightarrow> \<beta>"}
|
|
134 |
|
|
135 |
\noindent
|
|
136 |
This operation has only a single type parameter @{text "\<beta>"} (the @{text "\<alpha>\<^isub>i"} are the
|
|
137 |
atom types given by the user).
|
|
138 |
|
|
139 |
While the representation of permutations-as-lists solved the
|
|
140 |
``sort-respecting'' requirement and the declaration of all atom types
|
|
141 |
up-front solved the problem with Isabelle/HOL's type classes, this setup
|
|
142 |
caused several problems for formalising the nominal logic work: First,
|
|
143 |
Nominal Isabelle had to generate @{text "n\<^sup>2"} definitions for the
|
|
144 |
permutation operation over @{text "n"} types of atoms. Second, whenever we
|
|
145 |
need to generalise induction hypotheses by quantifying over permutations, we
|
|
146 |
have to build cumbersome quantifications like
|
|
147 |
|
|
148 |
@{text [display,indent=10] "\<forall>\<pi>\<^isub>1 \<dots> \<forall>\<pi>\<^isub>n. \<dots>"}
|
|
149 |
|
|
150 |
\noindent
|
|
151 |
where the @{text "\<pi>\<^isub>i"} are of type @{text "(\<alpha>\<^isub>i \<times> \<alpha>\<^isub>i) list"}.
|
|
152 |
The reason is that the permutation operation behaves differently for
|
|
153 |
every @{text "\<alpha>\<^isub>i"}. Third, although the notion of support
|
|
154 |
|
|
155 |
@{text [display,indent=10] "supp _ :: \<beta> \<Rightarrow> \<alpha> set"}
|
|
156 |
|
|
157 |
\noindent
|
|
158 |
which we will define later, has a generic type @{text "\<alpha> set"}, it cannot be
|
|
159 |
used to express the support of an object over \emph{all} atoms. The reason
|
|
160 |
is again that support can behave differently for each @{text
|
|
161 |
"\<alpha>\<^isub>i"}. This problem is annoying, because if we need to know in
|
|
162 |
a statement that an object, say @{text "x"}, is finitely supported we end up
|
|
163 |
with having to state premises of the form
|
|
164 |
|
|
165 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
166 |
\begin{tabular}{@ {}l}
|
|
167 |
@{text "finite ((supp x) :: \<alpha>\<^isub>1 set) , \<dots>, finite ((supp x) :: \<alpha>\<^isub>n set)"}
|
|
168 |
\end{tabular}\hfill\numbered{fssequence}
|
|
169 |
\end{isabelle}
|
|
170 |
|
|
171 |
\noindent
|
|
172 |
Sometimes we can avoid such premises completely, if @{text x} is a member of a
|
|
173 |
\emph{finitely supported type}. However, keeping track of finitely supported
|
|
174 |
types requires another @{text n} type classes, and for technical reasons not
|
|
175 |
all types can be shown to be finitely supported.
|
|
176 |
|
|
177 |
The real pain of having a separate type for each atom sort arises, however,
|
|
178 |
from another permutation property
|
|
179 |
|
|
180 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
181 |
\begin{tabular}{@ {}r@ {\hspace{4mm}}p{10cm}}
|
|
182 |
iv) & @{text "\<pi>\<^isub>1 \<bullet> (\<pi>\<^isub>2 \<bullet> x) = (\<pi>\<^isub>1 \<bullet> \<pi>\<^isub>2) \<bullet> (\<pi>\<^isub>1 \<bullet> x)"}
|
|
183 |
\end{tabular}
|
|
184 |
\end{isabelle}
|
|
185 |
|
|
186 |
\noindent
|
|
187 |
where permutation @{text "\<pi>\<^isub>1"} has type @{text "(\<alpha> \<times> \<alpha>) list"},
|
|
188 |
@{text "\<pi>\<^isub>2"} type @{text "(\<alpha>' \<times> \<alpha>') list"} and @{text x} type @{text
|
|
189 |
"\<beta>"}. This property is needed in order to derive facts about how
|
|
190 |
permutations of different types interact, which is not covered by the
|
|
191 |
permutation properties @{text "i"}-@{text "iii"} shown in
|
|
192 |
\eqref{permprops}. The problem is that this property involves three type
|
|
193 |
parameters. In order to use again Isabelle/HOL's type class mechanism with
|
|
194 |
only permitting a single type parameter, we have to instantiate the atom
|
|
195 |
types. Consequently we end up with an additional @{text "n\<^sup>2"}
|
|
196 |
slightly different type classes for this permutation property.
|
|
197 |
|
|
198 |
While the problems and pain can be almost completely hidden from the user in
|
|
199 |
the existing implementation of Nominal Isabelle, the work is \emph{not}
|
|
200 |
pretty. It requires a large amount of custom ML-code and also forces the
|
|
201 |
user to declare up-front all atom-types that are ever going to be used in a
|
|
202 |
formalisation. In this paper we set out to solve the problems with multiple
|
|
203 |
type parameters in the permutation operation, and in this way can dispense
|
|
204 |
with the large amounts of custom ML-code for generating multiple variants
|
|
205 |
for some basic definitions. The result is that we can implement a pleasingly
|
|
206 |
simple formalisation of the nominal logic work.\smallskip
|
|
207 |
|
|
208 |
\noindent
|
1809
|
209 |
{\bf Contributions of the paper:} Using a single atom type to represent
|
|
210 |
atoms of different sorts and representing permutations as functions are not
|
|
211 |
new ideas. The main contribution of this paper is to show an example of how
|
|
212 |
to make better theorem proving tools by choosing the right level of
|
|
213 |
abstraction for the underlying theory---our design choices take advantage of
|
|
214 |
Isabelle's type system, type classes, and reasoning infrastructure.
|
|
215 |
The novel
|
|
216 |
technical contribution is a mechanism for dealing with
|
1785
|
217 |
``Church-style'' lambda-terms \cite{Church40} and HOL-based languages
|
|
218 |
\cite{PittsHOL4} where variables and variable binding depend on type
|
|
219 |
annotations.
|
1809
|
220 |
|
2065
|
221 |
Therefore it was decided in earlier versions of Nominal Isabelle to use a
|
|
222 |
separate type for each sort of atoms and let the type system enforce the
|
|
223 |
sort-respecting property of permutations. Inspired by the work on nominal
|
|
224 |
unification \cite{UrbanPittsGabbay04}, it seemed best at the time to also
|
|
225 |
implement permutations concretely as lists of pairs of atoms.
|
|
226 |
|
|
227 |
|
1785
|
228 |
*}
|
|
229 |
|
|
230 |
section {* Sorted Atoms and Sort-Respecting Permutations *}
|
|
231 |
|
|
232 |
text {*
|
|
233 |
In the nominal logic work of Pitts, binders and bound variables are
|
|
234 |
represented by \emph{atoms}. As stated above, we need to have different
|
|
235 |
\emph{sorts} of atoms to be able to bind different kinds of variables. A
|
|
236 |
basic requirement is that there must be a countably infinite number of atoms
|
|
237 |
of each sort. Unlike in our earlier work, where we identified each sort with
|
|
238 |
a separate type, we implement here atoms to be
|
|
239 |
*}
|
|
240 |
|
|
241 |
datatype atom\<iota> = Atom\<iota> string nat
|
|
242 |
|
|
243 |
text {*
|
|
244 |
\noindent
|
|
245 |
whereby the string argument specifies the sort of the atom.\footnote{A similar
|
|
246 |
design choice was made by Gunter et al \cite{GunterOsbornPopescu09}
|
|
247 |
for their variables.} (The use type
|
|
248 |
\emph{string} is merely for convenience; any countably infinite type would work
|
|
249 |
as well.)
|
|
250 |
We have an auxiliary function @{text sort} that is defined as @{thm
|
|
251 |
sort_of.simps[no_vars]}, and we clearly have for every finite set @{text X} of
|
|
252 |
atoms and every sort @{text s} the property:
|
|
253 |
|
|
254 |
\begin{proposition}\label{choosefresh}
|
|
255 |
@{text "If finite X then there exists an atom a such that
|
|
256 |
sort a = s and a \<notin> X"}.
|
|
257 |
\end{proposition}
|
|
258 |
|
|
259 |
For implementing sort-respecting permutations, we use functions of type @{typ
|
|
260 |
"atom => atom"} that @{text "i)"} are bijective; @{text "ii)"} are the
|
|
261 |
identity on all atoms, except a finite number of them; and @{text "iii)"} map
|
|
262 |
each atom to one of the same sort. These properties can be conveniently stated
|
|
263 |
for a function @{text \<pi>} as follows:
|
|
264 |
|
|
265 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
266 |
\begin{tabular}{r@ {\hspace{4mm}}l}
|
|
267 |
i) & @{term "bij \<pi>"}\\
|
|
268 |
ii) & @{term "finite {a. \<pi> a \<noteq> a}"}\\
|
|
269 |
iii) & @{term "\<forall>a. sort (\<pi> a) = sort a"}
|
|
270 |
\end{tabular}\hfill\numbered{permtype}
|
|
271 |
\end{isabelle}
|
|
272 |
|
|
273 |
\noindent
|
|
274 |
Like all HOL-based theorem provers, Isabelle/HOL allows us to
|
|
275 |
introduce a new type @{typ perm} that includes just those functions
|
|
276 |
satisfying all three properties. For example the identity function,
|
|
277 |
written @{term id}, is included in @{typ perm}. Also function composition,
|
|
278 |
written \mbox{@{text "_ \<circ> _"}}, and function inversion, given by Isabelle/HOL's
|
|
279 |
inverse operator and written \mbox{@{text "inv _"}}, preserve the properties
|
|
280 |
@{text "i"}-@{text "iii"}.
|
|
281 |
|
|
282 |
However, a moment of thought is needed about how to construct non-trivial
|
|
283 |
permutations. In the nominal logic work it turned out to be most convenient
|
|
284 |
to work with swappings, written @{text "(a b)"}. In our setting the
|
|
285 |
type of swappings must be
|
|
286 |
|
|
287 |
@{text [display,indent=10] "(_ _) :: atom \<Rightarrow> atom \<Rightarrow> perm"}
|
|
288 |
|
|
289 |
\noindent
|
|
290 |
but since permutations are required to respect sorts, we must carefully
|
|
291 |
consider what happens if a user states a swapping of atoms with different
|
|
292 |
sorts. In earlier versions of Nominal Isabelle, we avoided this problem by
|
|
293 |
using different types for different sorts; the type system prevented users
|
|
294 |
from stating ill-sorted swappings. Here, however, definitions such
|
|
295 |
as\footnote{To increase legibility, we omit here and in what follows the
|
|
296 |
@{term Rep_perm} and @{term "Abs_perm"} wrappers that are needed in our
|
|
297 |
implementation since we defined permutation not to be the full function space,
|
|
298 |
but only those functions of type @{typ perm} satisfying properties @{text
|
|
299 |
i}-@{text "iii"}.}
|
|
300 |
|
|
301 |
@{text [display,indent=10] "(a b) \<equiv> \<lambda>c. if a = c then b else (if b = c then a else c)"}
|
|
302 |
|
|
303 |
\noindent
|
|
304 |
do not work in general, because the type system does not prevent @{text a}
|
|
305 |
and @{text b} from having different sorts---in which case the function would
|
|
306 |
violate property @{text iii}. We could make the definition of swappings
|
|
307 |
partial by adding the precondition @{term "sort a = sort b"},
|
|
308 |
which would mean that in case @{text a} and @{text b} have different sorts,
|
|
309 |
the value of @{text "(a b)"} is unspecified. However, this looked like a
|
|
310 |
cumbersome solution, since sort-related side conditions would be required
|
|
311 |
everywhere, even to unfold the definition. It turned out to be more
|
|
312 |
convenient to actually allow the user to state ``ill-sorted'' swappings but
|
|
313 |
limit their ``damage'' by defaulting to the identity permutation in the
|
|
314 |
ill-sorted case:
|
|
315 |
|
|
316 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
317 |
\begin{tabular}{@ {}rl}
|
|
318 |
@{text "(a b) \<equiv>"} & @{text "if (sort a = sort b)"}\\
|
|
319 |
& \hspace{3mm}@{text "then \<lambda>c. if a = c then b else (if b = c then a else c)"}\\
|
|
320 |
& \hspace{3mm}@{text "else id"}
|
|
321 |
\end{tabular}\hfill\numbered{swapdef}
|
|
322 |
\end{isabelle}
|
|
323 |
|
|
324 |
\noindent
|
|
325 |
This function is bijective, the identity on all atoms except
|
|
326 |
@{text a} and @{text b}, and sort respecting. Therefore it is
|
|
327 |
a function in @{typ perm}.
|
|
328 |
|
|
329 |
One advantage of using functions instead of lists as a representation for
|
|
330 |
permutations is that for example the swappings
|
|
331 |
|
|
332 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
333 |
\begin{tabular}{@ {}l}
|
|
334 |
@{thm swap_commute[no_vars]}\hspace{10mm}
|
|
335 |
@{text "(a a) = id"}
|
|
336 |
\end{tabular}\hfill\numbered{swapeqs}
|
|
337 |
\end{isabelle}
|
|
338 |
|
|
339 |
\noindent
|
|
340 |
are \emph{equal}. We do not have to use the equivalence relation shown
|
|
341 |
in~\eqref{permequ} to identify them, as we would if they had been represented
|
|
342 |
as lists of pairs. Another advantage of the function representation is that
|
1809
|
343 |
they form a (non-commutative) group provided we define
|
1785
|
344 |
|
|
345 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
346 |
\begin{tabular}{@ {}l}
|
|
347 |
@{thm zero_perm_def[no_vars, THEN eq_reflection]} \hspace{4mm}
|
|
348 |
@{thm plus_perm_def[where p="\<pi>\<^isub>1" and q="\<pi>\<^isub>2", THEN eq_reflection]} \hspace{4mm}
|
|
349 |
@{thm uminus_perm_def[where p="\<pi>", THEN eq_reflection]} \hspace{4mm}
|
|
350 |
@{thm diff_def[where x="\<pi>\<^isub>1" and y="\<pi>\<^isub>2"]}
|
|
351 |
\end{tabular}
|
|
352 |
\end{isabelle}
|
|
353 |
|
|
354 |
\noindent
|
|
355 |
and verify the simple properties
|
|
356 |
|
|
357 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
358 |
\begin{tabular}{@ {}l}
|
|
359 |
@{thm add_assoc[where a="\<pi>\<^isub>1" and b="\<pi>\<^isub>2" and c="\<pi>\<^isub>3"]} \hspace{3mm}
|
|
360 |
@{thm monoid_add_class.add_0_left[where a="\<pi>::perm"]} \hspace{3mm}
|
|
361 |
@{thm monoid_add_class.add_0_right[where a="\<pi>::perm"]} \hspace{3mm}
|
|
362 |
@{thm group_add_class.left_minus[where a="\<pi>::perm"]}
|
|
363 |
\end{tabular}
|
|
364 |
\end{isabelle}
|
|
365 |
|
|
366 |
\noindent
|
|
367 |
Again this is in contrast to the list-of-pairs representation which does not
|
1809
|
368 |
form a group. The technical importance of this fact is that we can rely on
|
|
369 |
Isabelle/HOL's existing simplification infrastructure for groups, which will
|
|
370 |
come in handy when we have to do calculations with permutations.
|
1790
|
371 |
Note that Isabelle/HOL defies standard conventions of mathematical notation
|
|
372 |
by using additive syntax even for non-commutative groups. Obviously,
|
|
373 |
composition of permutations is not commutative in general, because @{text
|
|
374 |
"\<pi>\<^sub>1 + \<pi>\<^sub>2 \<noteq> \<pi>\<^sub>2 + \<pi>\<^sub>1"}. But since the point of this paper is to implement the
|
|
375 |
nominal theory as smoothly as possible in Isabelle/HOL, we tolerate
|
|
376 |
the non-standard notation in order to reuse the existing libraries.
|
1785
|
377 |
|
|
378 |
By formalising permutations abstractly as functions, and using a single type
|
|
379 |
for all atoms, we can now restate the \emph{permutation properties} from
|
|
380 |
\eqref{permprops} as just the two equations
|
|
381 |
|
|
382 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
383 |
\begin{tabular}{@ {}r@ {\hspace{4mm}}p{10cm}}
|
|
384 |
i) & @{thm permute_zero[no_vars]}\\
|
|
385 |
ii) & @{thm permute_plus[where p="\<pi>\<^isub>1" and q="\<pi>\<^isub>2",no_vars]}
|
|
386 |
\end{tabular}\hfill\numbered{newpermprops}
|
|
387 |
\end{isabelle}
|
|
388 |
|
|
389 |
\noindent
|
|
390 |
in which the permutation operations are of type @{text "perm \<Rightarrow> \<beta> \<Rightarrow> \<beta>"} and so
|
|
391 |
have only a single type parameter. Consequently, these properties are
|
|
392 |
compatible with the one-parameter restriction of Isabelle/HOL's type classes.
|
|
393 |
There is no need to introduce a separate type class instantiated for each
|
|
394 |
sort, like in the old approach.
|
|
395 |
|
|
396 |
The next notion allows us to establish generic lemmas involving the
|
|
397 |
permutation operation.
|
|
398 |
|
|
399 |
\begin{definition}
|
|
400 |
A type @{text "\<beta>"} is a \emph{permutation type} if the permutation
|
|
401 |
properties in \eqref{newpermprops} are satisfied for every @{text "x"} of type
|
|
402 |
@{text "\<beta>"}.
|
|
403 |
\end{definition}
|
|
404 |
|
|
405 |
\noindent
|
|
406 |
First, it follows from the laws governing
|
|
407 |
groups that a permutation and its inverse cancel each other. That is, for any
|
|
408 |
@{text "x"} of a permutation type:
|
|
409 |
|
|
410 |
|
|
411 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
412 |
\begin{tabular}{@ {}l}
|
|
413 |
@{thm permute_minus_cancel(1)[where p="\<pi>", no_vars]}\hspace{10mm}
|
|
414 |
@{thm permute_minus_cancel(2)[where p="\<pi>", no_vars]}
|
|
415 |
\end{tabular}\hfill\numbered{cancel}
|
|
416 |
\end{isabelle}
|
|
417 |
|
|
418 |
\noindent
|
|
419 |
Consequently, in a permutation type the permutation operation @{text "\<pi> \<bullet> _"} is bijective,
|
|
420 |
which in turn implies the property
|
|
421 |
|
|
422 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
423 |
\begin{tabular}{@ {}l}
|
|
424 |
@{thm (lhs) permute_eq_iff[where p="\<pi>", no_vars]}
|
|
425 |
$\;$if and only if$\;$
|
|
426 |
@{thm (rhs) permute_eq_iff[where p="\<pi>", no_vars]}.
|
|
427 |
\end{tabular}\hfill\numbered{permuteequ}
|
|
428 |
\end{isabelle}
|
|
429 |
|
|
430 |
\noindent
|
|
431 |
In order to lift the permutation operation to other types, we can define for:
|
|
432 |
|
|
433 |
\begin{isabelle}
|
|
434 |
\begin{tabular}{@ {}c@ {\hspace{-1mm}}c@ {}}
|
|
435 |
\begin{tabular}{@ {}r@ {\hspace{2mm}}l@ {}}
|
|
436 |
atoms: & @{thm permute_atom_def[where p="\<pi>",no_vars, THEN eq_reflection]}\\
|
|
437 |
functions: & @{text "\<pi> \<bullet> f \<equiv> \<lambda>x. \<pi> \<bullet> (f ((-\<pi>) \<bullet> x))"}\\
|
|
438 |
permutations: & @{thm permute_perm_def[where p="\<pi>" and q="\<pi>'", THEN eq_reflection]}\\
|
|
439 |
sets: & @{thm permute_set_eq[where p="\<pi>", no_vars, THEN eq_reflection]}\\
|
|
440 |
booleans: & @{thm permute_bool_def[where p="\<pi>", no_vars, THEN eq_reflection]}\\
|
|
441 |
\end{tabular} &
|
|
442 |
\begin{tabular}{@ {}r@ {\hspace{2mm}}l@ {}}
|
|
443 |
lists: & @{thm permute_list.simps(1)[where p="\<pi>", no_vars, THEN eq_reflection]}\\
|
|
444 |
& @{thm permute_list.simps(2)[where p="\<pi>", no_vars, THEN eq_reflection]}\\[2mm]
|
|
445 |
products: & @{thm permute_prod.simps[where p="\<pi>", no_vars, THEN eq_reflection]}\\
|
|
446 |
nats: & @{thm permute_nat_def[where p="\<pi>", no_vars, THEN eq_reflection]}\\
|
|
447 |
\end{tabular}
|
|
448 |
\end{tabular}
|
|
449 |
\end{isabelle}
|
|
450 |
|
|
451 |
\noindent
|
|
452 |
and then establish:
|
|
453 |
|
|
454 |
\begin{theorem}
|
|
455 |
If @{text \<beta>}, @{text "\<beta>\<^isub>1"} and @{text "\<beta>\<^isub>2"} are permutation types,
|
|
456 |
then so are @{text "atom"}, @{text "\<beta>\<^isub>1 \<Rightarrow> \<beta>\<^isub>2"},
|
|
457 |
@{text perm}, @{term "\<beta> set"}, @{term "\<beta> list"}, @{term "\<beta>\<^isub>1 \<times> \<beta>\<^isub>2"},
|
|
458 |
@{text bool} and @{text "nat"}.
|
|
459 |
\end{theorem}
|
|
460 |
|
|
461 |
\begin{proof}
|
|
462 |
All statements are by unfolding the definitions of the permutation operations and simple
|
|
463 |
calculations involving addition and minus. With permutations for example we
|
|
464 |
have
|
|
465 |
|
|
466 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
467 |
\begin{tabular}[b]{@ {}rcl}
|
|
468 |
@{text "0 \<bullet> \<pi>'"} & @{text "\<equiv>"} & @{text "0 + \<pi>' - 0 = \<pi>'"}\\
|
|
469 |
@{text "(\<pi>\<^isub>1 + \<pi>\<^isub>2) \<bullet> \<pi>'"} & @{text "\<equiv>"} & @{text "(\<pi>\<^isub>1 + \<pi>\<^isub>2) + \<pi>' - (\<pi>\<^isub>1 + \<pi>\<^isub>2)"}\\
|
|
470 |
& @{text "="} & @{text "(\<pi>\<^isub>1 + \<pi>\<^isub>2) + \<pi>' - \<pi>\<^isub>2 - \<pi>\<^isub>1"}\\
|
|
471 |
& @{text "="} & @{text "\<pi>\<^isub>1 + (\<pi>\<^isub>2 + \<pi>' - \<pi>\<^isub>2) - \<pi>\<^isub>1"} @{text "\<equiv>"} @{text "\<pi>\<^isub>1 \<bullet> \<pi>\<^isub>2 \<bullet> \<pi>'"}
|
|
472 |
\end{tabular}\hfill\qed
|
|
473 |
\end{isabelle}
|
|
474 |
\end{proof}
|
|
475 |
|
|
476 |
\noindent
|
|
477 |
The main point is that the above reasoning blends smoothly with the reasoning
|
|
478 |
infrastructure of Isabelle/HOL; no custom ML-code is necessary and a single
|
|
479 |
type class suffices. We can also show once and for all that the following
|
|
480 |
property---which caused so many headaches in our earlier setup---holds for any
|
|
481 |
permutation type.
|
|
482 |
|
|
483 |
\begin{lemma}\label{permutecompose}
|
|
484 |
Given @{term x} is of permutation type, then
|
|
485 |
@{text "\<pi>\<^isub>1 \<bullet> (\<pi>\<^isub>2 \<bullet> x) = (\<pi>\<^isub>1 \<bullet> \<pi>\<^isub>2) \<bullet> (\<pi>\<^isub>1 \<bullet> x)"}.
|
|
486 |
\end{lemma}
|
|
487 |
|
|
488 |
\begin{proof} The proof is as follows:
|
|
489 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
490 |
\begin{tabular}[b]{@ {}rcl@ {\hspace{8mm}}l}
|
|
491 |
@{text "\<pi>\<^isub>1 \<bullet> \<pi>\<^isub>2 \<bullet> x"}
|
|
492 |
& @{text "="} & @{text "\<pi>\<^isub>1 \<bullet> \<pi>\<^isub>2 \<bullet> (-\<pi>\<^isub>1) \<bullet> \<pi>\<^isub>1 \<bullet> x"} & by \eqref{cancel}\\
|
|
493 |
& @{text "="} & @{text "(\<pi>\<^isub>1 + \<pi>\<^isub>2 - \<pi>\<^isub>1) \<bullet> \<pi>\<^isub>1 \<bullet> x"} & by {\rm(\ref{newpermprops}.@{text "ii"})}\\
|
|
494 |
& @{text "\<equiv>"} & @{text "(\<pi>\<^isub>1 \<bullet> \<pi>\<^isub>2) \<bullet> (\<pi>\<^isub>1 \<bullet> x)"}\\
|
|
495 |
\end{tabular}\hfill\qed
|
|
496 |
\end{isabelle}
|
|
497 |
\end{proof}
|
|
498 |
|
|
499 |
*}
|
|
500 |
|
|
501 |
section {* Equivariance *}
|
|
502 |
|
|
503 |
text {*
|
|
504 |
|
1809
|
505 |
An \emph{equivariant} function or predicate is one that is invariant under
|
|
506 |
the swapping of atoms. Having a notion of equivariance with nice logical
|
|
507 |
properties is a major advantage of bijective permutations over traditional
|
|
508 |
renaming substitutions \cite[\S2]{Pitts03}. Equivariance can be defined
|
|
509 |
uniformly for all permutation types, and it is satisfied by most HOL
|
|
510 |
functions and constants.
|
|
511 |
|
1785
|
512 |
|
|
513 |
\begin{definition}\label{equivariance}
|
|
514 |
A function @{text f} is \emph{equivariant} if @{term "\<forall>\<pi>. \<pi> \<bullet> f = f"}.
|
|
515 |
\end{definition}
|
|
516 |
|
|
517 |
\noindent
|
|
518 |
There are a number of equivalent formulations for the equivariance property.
|
|
519 |
For example, assuming @{text f} is of type @{text "\<alpha> \<Rightarrow> \<beta>"}, then equivariance
|
|
520 |
can also be stated as
|
|
521 |
|
|
522 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
523 |
\begin{tabular}{@ {}l}
|
|
524 |
@{text "\<forall>\<pi> x. \<pi> \<bullet> (f x) = f (\<pi> \<bullet> x)"}
|
|
525 |
\end{tabular}\hfill\numbered{altequivariance}
|
|
526 |
\end{isabelle}
|
|
527 |
|
|
528 |
\noindent
|
|
529 |
To see that this formulation implies the definition, we just unfold the
|
|
530 |
definition of the permutation operation for functions and simplify with the equation
|
|
531 |
and the cancellation property shown in \eqref{cancel}. To see the other direction, we use
|
|
532 |
the fact
|
|
533 |
|
|
534 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
535 |
\begin{tabular}{@ {}l}
|
|
536 |
@{text "\<pi> \<bullet> (f x) = (\<pi> \<bullet> f) (\<pi> \<bullet> x)"}
|
|
537 |
\end{tabular}\hfill\numbered{permutefunapp}
|
|
538 |
\end{isabelle}
|
|
539 |
|
|
540 |
\noindent
|
|
541 |
which follows again directly
|
|
542 |
from the definition of the permutation operation for functions and the cancellation
|
|
543 |
property. Similarly for functions with more than one argument.
|
|
544 |
|
|
545 |
Both formulations of equivariance have their advantages and disadvantages:
|
|
546 |
\eqref{altequivariance} is often easier to establish. For example we
|
|
547 |
can easily show that equality is equivariant
|
|
548 |
|
|
549 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
550 |
\begin{tabular}{@ {}l}
|
|
551 |
@{thm eq_eqvt[where p="\<pi>", no_vars]}
|
|
552 |
\end{tabular}
|
|
553 |
\end{isabelle}
|
|
554 |
|
|
555 |
\noindent
|
|
556 |
using the permutation operation on booleans and property \eqref{permuteequ}.
|
|
557 |
Lemma~\ref{permutecompose} establishes that the permutation operation is
|
|
558 |
equivariant. It is also easy to see that the boolean operators, like
|
|
559 |
@{text "\<and>"}, @{text "\<or>"} and @{text "\<longrightarrow>"} are all equivariant. Furthermore
|
|
560 |
a simple calculation will show that our swapping functions are equivariant, that is
|
|
561 |
|
|
562 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
563 |
\begin{tabular}{@ {}l}
|
|
564 |
@{thm swap_eqvt[where p="\<pi>", no_vars]}
|
|
565 |
\end{tabular}\hfill\numbered{swapeqvt}
|
|
566 |
\end{isabelle}
|
|
567 |
|
|
568 |
\noindent
|
|
569 |
for all @{text a}, @{text b} and @{text \<pi>}. These equivariance properties
|
|
570 |
are tremendously helpful later on when we have to push permutations inside
|
|
571 |
terms.
|
|
572 |
*}
|
|
573 |
|
|
574 |
|
|
575 |
section {* Support and Freshness *}
|
|
576 |
|
|
577 |
text {*
|
|
578 |
The most original aspect of the nominal logic work of Pitts et al is a general
|
|
579 |
definition for ``the set of free variables of an object @{text "x"}''. This
|
|
580 |
definition is general in the sense that it applies not only to lambda-terms,
|
|
581 |
but also to lists, products, sets and even functions. The definition depends
|
|
582 |
only on the permutation operation and on the notion of equality defined for
|
|
583 |
the type of @{text x}, namely:
|
|
584 |
|
|
585 |
@{thm [display,indent=10] supp_def[no_vars, THEN eq_reflection]}
|
|
586 |
|
|
587 |
\noindent
|
|
588 |
(Note that due to the definition of swapping in \eqref{swapdef}, we do not
|
|
589 |
need to explicitly restrict @{text a} and @{text b} to have the same sort.)
|
|
590 |
There is also the derived notion for when an atom @{text a} is \emph{fresh}
|
|
591 |
for an @{text x}, defined as
|
|
592 |
|
|
593 |
@{thm [display,indent=10] fresh_def[no_vars]}
|
|
594 |
|
|
595 |
\noindent
|
|
596 |
A striking consequence of these definitions is that we can prove
|
|
597 |
without knowing anything about the structure of @{term x} that
|
|
598 |
swapping two fresh atoms, say @{text a} and @{text b}, leave
|
|
599 |
@{text x} unchanged. For the proof we use the following lemma
|
|
600 |
about swappings applied to an @{text x}:
|
|
601 |
|
|
602 |
\begin{lemma}\label{swaptriple}
|
|
603 |
Assuming @{text x} is of permutation type, and @{text a}, @{text b} and @{text c}
|
|
604 |
have the same sort, then @{thm (prem 3) swap_rel_trans[no_vars]} and
|
|
605 |
@{thm (prem 4) swap_rel_trans[no_vars]} imply @{thm (concl) swap_rel_trans[no_vars]}.
|
|
606 |
\end{lemma}
|
|
607 |
|
|
608 |
\begin{proof}
|
|
609 |
The cases where @{text "a = c"} and @{text "b = c"} are immediate.
|
|
610 |
For the remaining case it is, given our assumptions, easy to calculate
|
|
611 |
that the permutations
|
|
612 |
|
|
613 |
@{thm [display,indent=10] (concl) swap_triple[no_vars]}
|
|
614 |
|
|
615 |
\noindent
|
|
616 |
are equal. The lemma is then by application of the second permutation
|
|
617 |
property shown in \eqref{newpermprops}.\hfill\qed
|
|
618 |
\end{proof}
|
|
619 |
|
|
620 |
\begin{theorem}\label{swapfreshfresh}
|
|
621 |
Let @{text x} be of permutation type.
|
|
622 |
@{thm [mode=IfThen] swap_fresh_fresh[no_vars]}
|
|
623 |
\end{theorem}
|
|
624 |
|
|
625 |
\begin{proof}
|
|
626 |
If @{text a} and @{text b} have different sort, then the swapping is the identity.
|
|
627 |
If they have the same sort, we know by definition of support that both
|
|
628 |
@{term "finite {c. (a \<rightleftharpoons> c) \<bullet> x \<noteq> x}"} and @{term "finite {c. (b \<rightleftharpoons> c) \<bullet> x \<noteq> x}"}
|
|
629 |
hold. So the union of these sets is finite too, and we know by Proposition~\ref{choosefresh}
|
|
630 |
that there is an atom @{term c}, with the same sort as @{term a} and @{term b},
|
|
631 |
that satisfies \mbox{@{term "(a \<rightleftharpoons> c) \<bullet> x = x"}} and @{term "(b \<rightleftharpoons> c) \<bullet> x = x"}.
|
|
632 |
Now the theorem follows from Lemma~\ref{swaptriple}.\hfill\qed
|
|
633 |
\end{proof}
|
|
634 |
|
|
635 |
\noindent
|
|
636 |
Two important properties that need to be established for later calculations is
|
|
637 |
that @{text "supp"} and freshness are equivariant. For this we first show that:
|
|
638 |
|
|
639 |
\begin{lemma}\label{half}
|
|
640 |
If @{term x} is a permutation type, then @{thm (lhs) fresh_permute_iff[where p="\<pi>",no_vars]}
|
|
641 |
if and only if @{thm (rhs) fresh_permute_iff[where p="\<pi>",no_vars]}.
|
|
642 |
\end{lemma}
|
|
643 |
|
|
644 |
\begin{proof}
|
|
645 |
\begin{isabelle}
|
|
646 |
\begin{tabular}[t]{c@ {\hspace{2mm}}l@ {\hspace{5mm}}l}
|
|
647 |
& \multicolumn{2}{@ {}l}{@{thm (lhs) fresh_permute_iff[where p="\<pi>",no_vars]} @{text "\<equiv>"}
|
|
648 |
@{term "finite {b. (\<pi> \<bullet> a \<rightleftharpoons> b) \<bullet> \<pi> \<bullet> x \<noteq> \<pi> \<bullet> x}"}}\\
|
|
649 |
@{text "\<Leftrightarrow>"}
|
|
650 |
& @{term "finite {b. (\<pi> \<bullet> a \<rightleftharpoons> \<pi> \<bullet> b) \<bullet> \<pi> \<bullet> x \<noteq> \<pi> \<bullet> x}"}
|
|
651 |
& since @{text "\<pi> \<bullet> _"} is bijective\\
|
|
652 |
@{text "\<Leftrightarrow>"}
|
|
653 |
& @{term "finite {b. \<pi> \<bullet> (a \<rightleftharpoons> b) \<bullet> x \<noteq> \<pi> \<bullet> x}"}
|
|
654 |
& by \eqref{permutecompose} and \eqref{swapeqvt}\\
|
|
655 |
@{text "\<Leftrightarrow>"}
|
|
656 |
& @{term "finite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}"} @{text "\<equiv>"}
|
|
657 |
@{thm (rhs) fresh_permute_iff[where p="\<pi>",no_vars]}
|
|
658 |
& by \eqref{permuteequ}\\
|
|
659 |
\end{tabular}
|
|
660 |
\end{isabelle}\hfill\qed
|
|
661 |
\end{proof}
|
|
662 |
|
|
663 |
\noindent
|
|
664 |
Together with the definition of the permutation operation on booleans,
|
|
665 |
we can immediately infer equivariance of freshness:
|
|
666 |
|
|
667 |
@{thm [display,indent=10] fresh_eqvt[where p="\<pi>",no_vars]}
|
|
668 |
|
|
669 |
\noindent
|
|
670 |
Now equivariance of @{text "supp"}, namely
|
|
671 |
|
|
672 |
@{thm [display,indent=10] supp_eqvt[where p="\<pi>",no_vars]}
|
|
673 |
|
|
674 |
\noindent
|
|
675 |
is by noting that @{thm supp_conv_fresh[no_vars]} and that freshness and
|
|
676 |
the logical connectives are equivariant.
|
|
677 |
|
|
678 |
While the abstract properties of support and freshness, particularly
|
|
679 |
Theorem~\ref{swapfreshfresh}, are useful for developing Nominal Isabelle,
|
|
680 |
one often has to calculate the support of some concrete object. This is
|
|
681 |
straightforward for example for booleans, nats, products and lists:
|
|
682 |
|
|
683 |
\begin{center}
|
|
684 |
\begin{tabular}{@ {}c@ {\hspace{2mm}}c@ {}}
|
|
685 |
\begin{tabular}{@ {}r@ {\hspace{2mm}}l}
|
|
686 |
@{text "booleans"}: & @{term "supp b = {}"}\\
|
|
687 |
@{text "nats"}: & @{term "supp n = {}"}\\
|
|
688 |
@{text "products"}: & @{thm supp_Pair[no_vars]}\\
|
|
689 |
\end{tabular} &
|
|
690 |
\begin{tabular}{r@ {\hspace{2mm}}l@ {}}
|
|
691 |
@{text "lists:"} & @{thm supp_Nil[no_vars]}\\
|
|
692 |
& @{thm supp_Cons[no_vars]}\\
|
|
693 |
\end{tabular}
|
|
694 |
\end{tabular}
|
|
695 |
\end{center}
|
|
696 |
|
|
697 |
\noindent
|
|
698 |
But establishing the support of atoms and permutations in our setup here is a bit
|
|
699 |
trickier. To do so we will use the following notion about a \emph{supporting set}.
|
|
700 |
|
|
701 |
\begin{definition}
|
|
702 |
A set @{text S} \emph{supports} @{text x} if for all atoms @{text a} and @{text b}
|
|
703 |
not in @{text S} we have @{term "(a \<rightleftharpoons> b) \<bullet> x = x"}.
|
|
704 |
\end{definition}
|
|
705 |
|
|
706 |
\noindent
|
|
707 |
The main motivation for this notion is that we can characterise @{text "supp x"}
|
|
708 |
as the smallest finite set that supports @{text "x"}. For this we prove:
|
|
709 |
|
|
710 |
\begin{lemma}\label{supports} Let @{text x} be of permutation type.
|
|
711 |
\begin{isabelle}
|
|
712 |
\begin{tabular}{r@ {\hspace{4mm}}p{10cm}}
|
|
713 |
i) & @{thm[mode=IfThen] supp_is_subset[no_vars]}\\
|
|
714 |
ii) & @{thm[mode=IfThen] supp_supports[no_vars]}\\
|
|
715 |
iii) & @{thm (concl) supp_is_least_supports[no_vars]}
|
|
716 |
provided @{thm (prem 1) supp_is_least_supports[no_vars]},
|
|
717 |
@{thm (prem 2) supp_is_least_supports[no_vars]}
|
|
718 |
and @{text "S"} is the least such set, that means formally,
|
|
719 |
for all @{text "S'"}, if @{term "finite S'"} and
|
|
720 |
@{term "S' supports x"} then @{text "S \<subseteq> S'"}.
|
|
721 |
\end{tabular}
|
|
722 |
\end{isabelle}
|
|
723 |
\end{lemma}
|
|
724 |
|
|
725 |
\begin{proof}
|
|
726 |
For @{text "i)"} we derive a contradiction by assuming there is an atom @{text a}
|
|
727 |
with @{term "a \<in> supp x"} and @{text "a \<notin> S"}. Using the second fact, the
|
|
728 |
assumption that @{term "S supports x"} gives us that @{text S} is a superset of
|
|
729 |
@{term "{b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}"}, which is finite by the assumption of @{text S}
|
|
730 |
being finite. But this means @{term "a \<notin> supp x"}, contradicting our assumption.
|
|
731 |
Property @{text "ii)"} is by a direct application of
|
|
732 |
Theorem~\ref{swapfreshfresh}. For the last property, part @{text "i)"} proves
|
|
733 |
one ``half'' of the claimed equation. The other ``half'' is by property
|
|
734 |
@{text "ii)"} and the fact that @{term "supp x"} is finite by @{text "i)"}.\hfill\qed
|
|
735 |
\end{proof}
|
|
736 |
|
|
737 |
\noindent
|
|
738 |
These are all relatively straightforward proofs adapted from the existing
|
|
739 |
nominal logic work. However for establishing the support of atoms and
|
|
740 |
permutations we found the following ``optimised'' variant of @{text "iii)"}
|
|
741 |
more useful:
|
|
742 |
|
|
743 |
\begin{lemma}\label{optimised} Let @{text x} be of permutation type.
|
|
744 |
We have that @{thm (concl) finite_supp_unique[no_vars]}
|
|
745 |
provided @{thm (prem 1) finite_supp_unique[no_vars]},
|
|
746 |
@{thm (prem 2) finite_supp_unique[no_vars]}, and for
|
|
747 |
all @{text "a \<in> S"} and all @{text "b \<notin> S"}, with @{text a}
|
1809
|
748 |
and @{text b} having the same sort, \mbox{@{term "(a \<rightleftharpoons> b) \<bullet> x \<noteq> x"}}
|
1785
|
749 |
\end{lemma}
|
|
750 |
|
|
751 |
\begin{proof}
|
|
752 |
By Lemma \ref{supports}@{text ".iii)"} we have to show that for every finite
|
|
753 |
set @{text S'} that supports @{text x}, \mbox{@{text "S \<subseteq> S'"}} holds. We will
|
|
754 |
assume that there is an atom @{text "a"} that is element of @{text S}, but
|
|
755 |
not @{text "S'"} and derive a contradiction. Since both @{text S} and
|
|
756 |
@{text S'} are finite, we can by Proposition \ref{choosefresh} obtain an atom
|
|
757 |
@{text b}, which has the same sort as @{text "a"} and for which we know
|
|
758 |
@{text "b \<notin> S"} and @{text "b \<notin> S'"}. Since we assumed @{text "a \<notin> S'"} and
|
|
759 |
we have that @{text "S' supports x"}, we have on one hand @{term "(a \<rightleftharpoons> b) \<bullet> x
|
|
760 |
= x"}. On the other hand, the fact @{text "a \<in> S"} and @{text "b \<notin> S"} imply
|
|
761 |
@{term "(a \<rightleftharpoons> b) \<bullet> x \<noteq> x"} using the assumed implication. This gives us the
|
|
762 |
contradiction.\hfill\qed
|
|
763 |
\end{proof}
|
|
764 |
|
|
765 |
\noindent
|
|
766 |
Using this lemma we only have to show the following three proof-obligations
|
|
767 |
|
|
768 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
769 |
\begin{tabular}{@ {}r@ {\hspace{4mm}}l}
|
|
770 |
i) & @{term "{c} supports c"}\\
|
|
771 |
ii) & @{term "finite {c}"}\\
|
|
772 |
iii) & @{text "\<forall>a \<in> {c} b \<notin> {c}. sort a = sort b \<longrightarrow> (a b) \<bullet> c \<noteq> c"}
|
|
773 |
\end{tabular}
|
|
774 |
\end{isabelle}
|
|
775 |
|
|
776 |
\noindent
|
|
777 |
in order to establish that @{thm supp_atom[where a="c", no_vars]} holds. In
|
|
778 |
Isabelle/HOL these proof-obligations can be discharged by easy
|
|
779 |
simplifications. Similar proof-obligations arise for the support of
|
|
780 |
permutations, which is
|
|
781 |
|
|
782 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
783 |
\begin{tabular}{@ {}l}
|
|
784 |
@{thm supp_perm[where p="\<pi>", no_vars]}
|
|
785 |
\end{tabular}
|
|
786 |
\end{isabelle}
|
|
787 |
|
|
788 |
\noindent
|
|
789 |
The only proof-obligation that is
|
|
790 |
interesting is the one where we have to show that
|
|
791 |
|
|
792 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
793 |
\begin{tabular}{@ {}l}
|
|
794 |
@{text "If \<pi> \<bullet> a \<noteq> a, \<pi> \<bullet> b = b and sort a = sort b, then (a b) \<bullet> \<pi> \<noteq> \<pi>"}.
|
|
795 |
\end{tabular}
|
|
796 |
\end{isabelle}
|
|
797 |
|
|
798 |
\noindent
|
|
799 |
For this we observe that
|
|
800 |
|
|
801 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
802 |
\begin{tabular}{@ {}rcl}
|
|
803 |
@{thm (lhs) perm_swap_eq[where p="\<pi>", no_vars]} &
|
|
804 |
if and only if &
|
|
805 |
@{thm (rhs) perm_swap_eq[where p="\<pi>", no_vars]}
|
|
806 |
\end{tabular}
|
|
807 |
\end{isabelle}
|
|
808 |
|
|
809 |
\noindent
|
|
810 |
holds by a simple calculation using the group properties of permutations.
|
|
811 |
The proof-obligation can then be discharged by analysing the inequality
|
|
812 |
between the permutations @{term "(\<pi> \<bullet> a \<rightleftharpoons> b)"} and @{term "(a \<rightleftharpoons> b)"}.
|
|
813 |
|
|
814 |
The main point about support is that whenever an object @{text x} has finite
|
|
815 |
support, then Proposition~\ref{choosefresh} allows us to choose for @{text x} a
|
|
816 |
fresh atom with arbitrary sort. This is an important operation in Nominal
|
|
817 |
Isabelle in situations where, for example, a bound variable needs to be
|
|
818 |
renamed. To allow such a choice, we only have to assume \emph{one} premise
|
|
819 |
of the form @{text "finite (supp x)"}
|
|
820 |
for each @{text x}. Compare that with the sequence of premises in our earlier
|
|
821 |
version of Nominal Isabelle (see~\eqref{fssequence}). For more convenience we
|
|
822 |
can define a type class for types where every element has finite support, and
|
|
823 |
prove that the types @{term "atom"}, @{term "perm"}, lists, products and
|
|
824 |
booleans are instances of this type class. Then \emph{no} premise is needed,
|
|
825 |
as the type system of Isabelle/HOL can figure out automatically when an object
|
|
826 |
is finitely supported.
|
|
827 |
|
|
828 |
Unfortunately, this does not work for sets or Isabelle/HOL's function type.
|
|
829 |
There are functions and sets definable in Isabelle/HOL for which the finite
|
|
830 |
support property does not hold. A simple example of a function with
|
|
831 |
infinite support is the function that returns the natural number of an atom
|
|
832 |
|
|
833 |
@{text [display, indent=10] "nat_of (Atom s i) \<equiv> i"}
|
|
834 |
|
|
835 |
\noindent
|
|
836 |
This function's support is the set of \emph{all} atoms. To establish this we show @{term "\<not> a \<sharp> nat_of"}.
|
|
837 |
This is equivalent to assuming the set @{term "{b. (a \<rightleftharpoons> b) \<bullet> nat_of \<noteq> nat_of}"} is finite
|
|
838 |
and deriving a contradiction. From the assumption we also know that
|
|
839 |
@{term "{a} \<union> {b. (a \<rightleftharpoons> b) \<bullet> nat_of \<noteq> nat_of}"} is finite. Then we can use
|
|
840 |
Proposition~\ref{choosefresh} to choose an atom @{text c} such that
|
|
841 |
@{term "c \<noteq> a"}, @{term "sort_of c = sort_of a"} and @{term "(a \<rightleftharpoons> c) \<bullet> nat_of = nat_of"}.
|
|
842 |
Now we can reason as follows:
|
|
843 |
|
|
844 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
845 |
\begin{tabular}[b]{@ {}rcl@ {\hspace{5mm}}l}
|
|
846 |
@{text "nat_of a"} & @{text "="} & @{text "(a \<rightleftharpoons> c) \<bullet> (nat_of a)"} & by def.~of permutations on nats\\
|
|
847 |
& @{text "="} & @{term "((a \<rightleftharpoons> c) \<bullet> nat_of) ((a \<rightleftharpoons> c) \<bullet> a)"} & by \eqref{permutefunapp}\\
|
|
848 |
& @{text "="} & @{term "nat_of c"} & by assumptions on @{text c}\\
|
|
849 |
\end{tabular}
|
|
850 |
\end{isabelle}
|
|
851 |
|
|
852 |
|
|
853 |
\noindent
|
|
854 |
But this means we have that @{term "nat_of a = nat_of c"} and @{term "sort_of a = sort_of c"}.
|
|
855 |
This implies that atoms @{term a} and @{term c} must be equal, which clashes with our
|
|
856 |
assumption @{term "c \<noteq> a"} about how we chose @{text c}.
|
|
857 |
Cheney \cite{Cheney06} gives similar examples for constructions that have infinite support.
|
|
858 |
*}
|
|
859 |
|
2033
|
860 |
section {* Support of Finite Sets *}
|
|
861 |
|
|
862 |
text {*
|
|
863 |
Sets is one instance of a type that is not generally finitely supported.
|
|
864 |
However, it can be easily derived that finite sets of atoms are finitely
|
|
865 |
supported, because their support can be characterised as:
|
|
866 |
|
|
867 |
\begin{lemma}\label{finatomsets}
|
|
868 |
If @{text S} is a finite set of atoms, then @{thm (concl) supp_finite_atom_set[no_vars]}.
|
|
869 |
\end{lemma}
|
|
870 |
|
|
871 |
\begin{proof}
|
|
872 |
finite-supp-unique
|
|
873 |
\end{proof}
|
|
874 |
|
|
875 |
More difficult is it to establish that finite sets of finitely
|
|
876 |
supported objects are finitely supported.
|
|
877 |
*}
|
|
878 |
|
|
879 |
|
1785
|
880 |
section {* Induction Principles *}
|
|
881 |
|
2033
|
882 |
text {*
|
|
883 |
While the use of functions as permutation provides us with a unique
|
|
884 |
representation for permutations (for example @{term "(a \<rightleftharpoons> b)"} and
|
|
885 |
@{term "(b \<rightleftharpoons> a)"} are equal permutations), this representation has
|
|
886 |
one draw back: it does not come readily with an induction principle.
|
|
887 |
Such an induction principle is handy for deriving properties like
|
|
888 |
|
|
889 |
@{thm [display, indent=10] supp_perm_eq}
|
1785
|
890 |
|
2033
|
891 |
\noindent
|
|
892 |
However, it is not too difficult to derive an induction principle,
|
|
893 |
given the fact that we allow only permutations with a finite domain.
|
|
894 |
*}
|
1785
|
895 |
|
|
896 |
|
|
897 |
section {* Concrete Atom Types *}
|
|
898 |
|
|
899 |
text {*
|
|
900 |
|
|
901 |
So far, we have presented a system that uses only a single multi-sorted atom
|
|
902 |
type. This design gives us the flexibility to define operations and prove
|
|
903 |
theorems that are generic with respect to atom sorts. For example, as
|
|
904 |
illustrated above the @{term supp} function returns a set that includes the
|
|
905 |
free atoms of \emph{all} sorts together; the flexibility offered by the new
|
|
906 |
atom type makes this possible.
|
|
907 |
|
|
908 |
However, the single multi-sorted atom type does not make an ideal interface
|
|
909 |
for end-users of Nominal Isabelle. If sorts are not distinguished by
|
|
910 |
Isabelle's type system, users must reason about atom sorts manually. That
|
|
911 |
means subgoals involving sorts must be discharged explicitly within proof
|
|
912 |
scripts, instead of being inferred by Isabelle/HOL's type checker. In other
|
|
913 |
cases, lemmas might require additional side conditions about sorts to be true.
|
|
914 |
For example, swapping @{text a} and @{text b} in the pair \mbox{@{term "(a,
|
|
915 |
b)"}} will only produce the expected result if we state the lemma in
|
|
916 |
Isabelle/HOL as:
|
|
917 |
*}
|
|
918 |
|
|
919 |
lemma
|
|
920 |
fixes a b :: "atom"
|
|
921 |
assumes asm: "sort a = sort b"
|
|
922 |
shows "(a \<rightleftharpoons> b) \<bullet> (a, b) = (b, a)"
|
|
923 |
using asm by simp
|
|
924 |
|
|
925 |
text {*
|
|
926 |
\noindent
|
|
927 |
Fortunately, it is possible to regain most of the type-checking automation
|
|
928 |
that is lost by moving to a single atom type. We accomplish this by defining
|
|
929 |
\emph{subtypes} of the generic atom type that only include atoms of a single
|
|
930 |
specific sort. We call such subtypes \emph{concrete atom types}.
|
|
931 |
|
|
932 |
The following Isabelle/HOL command defines a concrete atom type called
|
|
933 |
\emph{name}, which consists of atoms whose sort equals the string @{term
|
|
934 |
"''name''"}.
|
|
935 |
|
|
936 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
937 |
\isacommand{typedef}\ \ @{typ name} = @{term "{a. sort\<iota> a = ''name''}"}
|
|
938 |
\end{isabelle}
|
|
939 |
|
|
940 |
\noindent
|
|
941 |
This command automatically generates injective functions that map from the
|
|
942 |
concrete atom type into the generic atom type and back, called
|
|
943 |
representation and abstraction functions, respectively. We will write these
|
|
944 |
functions as follows:
|
|
945 |
|
|
946 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
947 |
\begin{tabular}{@ {}l@ {\hspace{10mm}}l}
|
|
948 |
@{text "\<lfloor>_\<rfloor> :: name \<Rightarrow> atom"} &
|
|
949 |
@{text "\<lceil>_\<rceil> :: atom \<Rightarrow> name"}
|
|
950 |
\end{tabular}
|
|
951 |
\end{isabelle}
|
|
952 |
|
|
953 |
\noindent
|
|
954 |
With the definition @{thm permute_name_def [where p="\<pi>", THEN
|
|
955 |
eq_reflection, no_vars]}, it is straightforward to verify that the type
|
|
956 |
@{typ name} is a permutation type.
|
|
957 |
|
|
958 |
In order to reason uniformly about arbitrary concrete atom types, we define a
|
|
959 |
type class that characterises type @{typ name} and other similarly-defined
|
|
960 |
types. The definition of the concrete atom type class is as follows: First,
|
|
961 |
every concrete atom type must be a permutation type. In addition, the class
|
|
962 |
defines an overloaded function that maps from the concrete type into the
|
|
963 |
generic atom type, which we will write @{text "|_|"}. For each class
|
|
964 |
instance, this function must be injective and equivariant, and its outputs
|
|
965 |
must all have the same sort, that is
|
|
966 |
|
|
967 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
968 |
\begin{tabular}{r@ {\hspace{3mm}}l}
|
|
969 |
i) if @{thm (lhs) atom_eq_iff [no_vars]} then @{thm (rhs) atom_eq_iff [no_vars]}\\
|
|
970 |
ii) @{thm atom_eqvt[where p="\<pi>", no_vars]}\\
|
|
971 |
iii) @{thm sort_of_atom_eq [no_vars]}
|
|
972 |
\end{tabular}\hfill\numbered{atomprops}
|
|
973 |
\end{isabelle}
|
|
974 |
|
|
975 |
\noindent
|
|
976 |
With the definition @{thm atom_name_def [THEN eq_reflection, no_vars]} we can
|
|
977 |
show that @{typ name} satisfies all the above requirements of a concrete atom
|
|
978 |
type.
|
|
979 |
|
|
980 |
The whole point of defining the concrete atom type class was to let users
|
|
981 |
avoid explicit reasoning about sorts. This benefit is realised by defining a
|
|
982 |
special swapping operation of type @{text "\<alpha> \<Rightarrow> \<alpha>
|
|
983 |
\<Rightarrow> perm"}, where @{text "\<alpha>"} is a concrete atom type:
|
|
984 |
|
|
985 |
@{thm [display,indent=10] flip_def [THEN eq_reflection, no_vars]}
|
|
986 |
|
|
987 |
\noindent
|
|
988 |
As a consequence of its type, the @{text "\<leftrightarrow>"}-swapping
|
|
989 |
operation works just like the generic swapping operation, but it does not
|
|
990 |
require any sort-checking side conditions---the sort-correctness is ensured by
|
|
991 |
the types! For @{text "\<leftrightarrow>"} we can establish the following
|
|
992 |
simplification rule:
|
|
993 |
|
|
994 |
@{thm [display,indent=10] permute_flip_at[no_vars]}
|
|
995 |
|
|
996 |
\noindent
|
|
997 |
If we now want to swap the \emph{concrete} atoms @{text a} and @{text b}
|
|
998 |
in the pair @{term "(a, b)"} we can establish the lemma as follows:
|
|
999 |
*}
|
|
1000 |
|
|
1001 |
lemma
|
|
1002 |
fixes a b :: "name"
|
|
1003 |
shows "(a \<leftrightarrow> b) \<bullet> (a, b) = (b, a)"
|
|
1004 |
by simp
|
|
1005 |
|
|
1006 |
text {*
|
|
1007 |
\noindent
|
|
1008 |
There is no need to state an explicit premise involving sorts.
|
|
1009 |
|
|
1010 |
We can automate the process of creating concrete atom types, so that users
|
|
1011 |
can define a new one simply by issuing the command
|
|
1012 |
|
|
1013 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
1014 |
\begin{tabular}{@ {}l}
|
|
1015 |
\isacommand{atom\_decl}~~@{text "name"}
|
|
1016 |
\end{tabular}
|
|
1017 |
\end{isabelle}
|
|
1018 |
|
|
1019 |
\noindent
|
|
1020 |
This command can be implemented using less than 100 lines of custom ML-code.
|
|
1021 |
In comparison, the old version of Nominal Isabelle included more than 1000
|
|
1022 |
lines of ML-code for creating concrete atom types, and for defining various
|
|
1023 |
type classes and instantiating generic lemmas for them. In addition to
|
|
1024 |
simplifying the ML-code, the setup here also offers user-visible improvements:
|
|
1025 |
Now concrete atoms can be declared at any point of a formalisation, and
|
|
1026 |
theories that separately declare different atom types can be merged
|
|
1027 |
together---it is no longer required to collect all atom declarations in one
|
|
1028 |
place.
|
|
1029 |
*}
|
|
1030 |
|
|
1031 |
|
|
1032 |
section {* Multi-Sorted Concrete Atoms *}
|
|
1033 |
|
|
1034 |
(*<*)
|
|
1035 |
datatype ty = TVar string | Fun ty ty ("_ \<rightarrow> _")
|
|
1036 |
(*>*)
|
|
1037 |
|
|
1038 |
text {*
|
|
1039 |
The formalisation presented so far allows us to streamline proofs and reduce
|
|
1040 |
the amount of custom ML-code in the existing implementation of Nominal
|
|
1041 |
Isabelle. In this section we describe a mechanism that extends the
|
|
1042 |
capabilities of Nominal Isabelle. This mechanism is about variables with
|
|
1043 |
additional information, for example typing constraints.
|
|
1044 |
While we leave a detailed treatment of binders and binding of variables for a
|
|
1045 |
later paper, we will have a look here at how such variables can be
|
|
1046 |
represented by concrete atoms.
|
|
1047 |
|
|
1048 |
In the previous section we considered concrete atoms that can be used in
|
|
1049 |
simple binders like \emph{@{text "\<lambda>x. x"}}. Such concrete atoms do
|
|
1050 |
not carry any information beyond their identities---comparing for equality
|
|
1051 |
is really the only way to analyse ordinary concrete atoms.
|
|
1052 |
However, in ``Church-style'' lambda-terms \cite{Church40} and in the terms
|
|
1053 |
underlying HOL-systems \cite{PittsHOL4} binders and bound variables have a
|
|
1054 |
more complicated structure. For example in the ``Church-style'' lambda-term
|
|
1055 |
|
|
1056 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
1057 |
\begin{tabular}{@ {}l}
|
|
1058 |
@{text "\<lambda>x\<^isub>\<alpha>. x\<^isub>\<alpha> x\<^isub>\<beta>"}
|
|
1059 |
\end{tabular}\hfill\numbered{church}
|
|
1060 |
\end{isabelle}
|
|
1061 |
|
|
1062 |
\noindent
|
|
1063 |
both variables and binders include typing information indicated by @{text \<alpha>}
|
|
1064 |
and @{text \<beta>}. In this setting, we treat @{text "x\<^isub>\<alpha>"} and @{text
|
|
1065 |
"x\<^isub>\<beta>"} as distinct variables (assuming @{term "\<alpha>\<noteq>\<beta>"}) so that the
|
|
1066 |
variable @{text "x\<^isub>\<alpha>"} is bound by the lambda-abstraction, but not
|
|
1067 |
@{text "x\<^isub>\<beta>"}.
|
|
1068 |
|
|
1069 |
To illustrate how we can deal with this phenomenon, let us represent object
|
|
1070 |
types like @{text \<alpha>} and @{text \<beta>} by the datatype
|
|
1071 |
|
|
1072 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
1073 |
\begin{tabular}{@ {}l}
|
|
1074 |
\isacommand{datatype}~~@{text "ty = TVar string | ty \<rightarrow> ty"}
|
|
1075 |
\end{tabular}
|
|
1076 |
\end{isabelle}
|
|
1077 |
|
|
1078 |
\noindent
|
|
1079 |
If we attempt to encode a variable naively as a pair of a @{text name} and a @{text ty}, we have the
|
|
1080 |
problem that a swapping, say @{term "(x \<leftrightarrow> y)"}, applied to the pair @{text "((x, \<alpha>), (x, \<beta>))"}
|
|
1081 |
will always permute \emph{both} occurrences of @{text x}, even if the types
|
|
1082 |
@{text "\<alpha>"} and @{text "\<beta>"} are different. This is unwanted, because it will
|
|
1083 |
eventually mean that both occurrences of @{text x} will become bound by a
|
|
1084 |
corresponding binder.
|
|
1085 |
|
|
1086 |
Another attempt might be to define variables as an instance of the concrete
|
|
1087 |
atom type class, where a @{text ty} is somehow encoded within each variable.
|
|
1088 |
Remember we defined atoms as the datatype:
|
|
1089 |
*}
|
|
1090 |
|
|
1091 |
datatype atom\<iota>\<iota> = Atom\<iota>\<iota> string nat
|
|
1092 |
|
|
1093 |
text {*
|
|
1094 |
\noindent
|
|
1095 |
Considering our method of defining concrete atom types, the usage of a string
|
|
1096 |
for the sort of atoms seems a natural choice. However, none of the results so
|
|
1097 |
far depend on this choice and we are free to change it.
|
|
1098 |
One possibility is to encode types or any other information by making the sort
|
|
1099 |
argument parametric as follows:
|
|
1100 |
*}
|
|
1101 |
|
|
1102 |
datatype 'a \<iota>atom\<iota>\<iota>\<iota> = \<iota>Atom\<iota>\<iota> 'a nat
|
|
1103 |
|
|
1104 |
text {*
|
|
1105 |
\noindent
|
|
1106 |
The problem with this possibility is that we are then back in the old
|
|
1107 |
situation where our permutation operation is parametric in two types and
|
|
1108 |
this would require to work around Isabelle/HOL's restriction on type
|
|
1109 |
classes. Fortunately, encoding the types in a separate parameter is not
|
|
1110 |
necessary for what we want to achieve, as we only have to know when two
|
|
1111 |
types are equal or not. The solution is to use a different sort for each
|
|
1112 |
object type. Then we can use the fact that permutations respect \emph{sorts} to
|
|
1113 |
ensure that permutations also respect \emph{object types}. In order to do
|
|
1114 |
this, we must define an injective function @{text "sort_ty"} mapping from
|
|
1115 |
object types to sorts. For defining functions like @{text "sort_ty"}, it is
|
|
1116 |
more convenient to use a tree datatype for sorts. Therefore we define
|
|
1117 |
*}
|
|
1118 |
|
|
1119 |
datatype sort = Sort string "(sort list)"
|
|
1120 |
datatype atom\<iota>\<iota>\<iota>\<iota> = Atom\<iota>\<iota>\<iota>\<iota> sort nat
|
|
1121 |
|
|
1122 |
text {*
|
|
1123 |
\noindent
|
|
1124 |
With this definition,
|
|
1125 |
the sorts we considered so far can be encoded just as \mbox{@{text "Sort s []"}}.
|
|
1126 |
The point, however, is that we can now define the function @{text sort_ty} simply as
|
|
1127 |
|
|
1128 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
1129 |
\begin{tabular}{@ {}l}
|
|
1130 |
@{text "sort_ty (TVar s) = Sort ''TVar'' [Sort s []]"}\\
|
|
1131 |
@{text "sort_ty (\<tau>\<^isub>1 \<rightarrow> \<tau>\<^isub>2) = Sort ''Fun'' [sort_ty \<tau>\<^isub>1, sort_ty \<tau>\<^isub>2]"}
|
|
1132 |
\end{tabular}\hfill\numbered{sortty}
|
|
1133 |
\end{isabelle}
|
|
1134 |
|
|
1135 |
\noindent
|
|
1136 |
which can easily be shown to be injective.
|
|
1137 |
|
|
1138 |
Having settled on what the sorts should be for ``Church-like'' atoms, we have to
|
|
1139 |
give a subtype definition for concrete atoms. Previously we identified a subtype consisting
|
|
1140 |
of atoms of only one specified sort. This must be generalised to all sorts the
|
|
1141 |
function @{text "sort_ty"} might produce, i.e.~the
|
|
1142 |
range of @{text "sort_ty"}. Therefore we define
|
|
1143 |
|
|
1144 |
\begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%%
|
|
1145 |
\isacommand{typedef}\ \ @{text var} = @{term "{a. sort a : range sort_ty}"}
|
|
1146 |
\end{isabelle}
|
|
1147 |
|
|
1148 |
\noindent
|
|
1149 |
This command gives us again injective representation and abstraction
|
|
1150 |
functions. We will write them also as \mbox{@{text "\<lfloor>_\<rfloor> :: var \<Rightarrow> atom"}} and
|
|
1151 |
@{text "\<lceil>_\<rceil> :: atom \<Rightarrow> var"}, respectively.
|
|
1152 |
|
|
1153 |
We can define the permutation operation for @{text var} as @{thm
|
|
1154 |
permute_var_def[where p="\<pi>", THEN eq_reflection, no_vars]} and the
|
|
1155 |
injective function to type @{typ atom} as @{thm atom_var_def[THEN
|
|
1156 |
eq_reflection, no_vars]}. Finally, we can define a constructor function that
|
|
1157 |
makes a @{text var} from a variable name and an object type:
|
|
1158 |
|
|
1159 |
@{thm [display,indent=10] Var_def[where t="\<alpha>", THEN eq_reflection, no_vars]}
|
|
1160 |
|
|
1161 |
\noindent
|
|
1162 |
With these definitions we can verify all the properties for concrete atom
|
|
1163 |
types except Property \ref{atomprops}@{text ".iii)"}, which requires every
|
|
1164 |
atom to have the same sort. This last property is clearly not true for type
|
|
1165 |
@{text "var"}.
|
|
1166 |
This fact is slightly unfortunate since this
|
|
1167 |
property allowed us to use the type-checker in order to shield the user from
|
|
1168 |
all sort-constraints. But this failure is expected here, because we cannot
|
|
1169 |
burden the type-system of Isabelle/HOL with the task of deciding when two
|
|
1170 |
object types are equal. This means we sometimes need to explicitly state sort
|
|
1171 |
constraints or explicitly discharge them, but as we will see in the lemma
|
|
1172 |
below this seems a natural price to pay in these circumstances.
|
|
1173 |
|
|
1174 |
To sum up this section, the encoding of type-information into atoms allows us
|
|
1175 |
to form the swapping @{term "(Var x \<alpha> \<leftrightarrow> Var y \<alpha>)"} and to prove the following
|
|
1176 |
lemma
|
|
1177 |
*}
|
|
1178 |
|
|
1179 |
lemma
|
|
1180 |
assumes asm: "\<alpha> \<noteq> \<beta>"
|
|
1181 |
shows "(Var x \<alpha> \<leftrightarrow> Var y \<alpha>) \<bullet> (Var x \<alpha>, Var x \<beta>) = (Var y \<alpha>, Var x \<beta>)"
|
|
1182 |
using asm by simp
|
|
1183 |
|
|
1184 |
text {*
|
|
1185 |
\noindent
|
|
1186 |
As we expect, the atom @{term "Var x \<beta>"} is left unchanged by the
|
|
1187 |
swapping. With this we can faithfully represent bindings in languages
|
|
1188 |
involving ``Church-style'' terms and bindings as shown in \eqref{church}. We
|
|
1189 |
expect that the creation of such atoms can be easily automated so that the
|
|
1190 |
user just needs to specify \isacommand{atom\_decl}~~@{text "var (ty)"}
|
|
1191 |
where the argument, or arguments, are datatypes for which we can automatically
|
|
1192 |
define an injective function like @{text "sort_ty"} (see \eqref{sortty}).
|
1809
|
1193 |
Our hope is that with this approach Benzmueller and Paulson can make
|
|
1194 |
headway with formalising their results
|
|
1195 |
about simple type theory \cite{PaulsonBenzmueller}.
|
1785
|
1196 |
Because of its limitations, they did not attempt this with the old version
|
|
1197 |
of Nominal Isabelle. We also hope we can make progress with formalisations of
|
|
1198 |
HOL-based languages.
|
|
1199 |
*}
|
|
1200 |
|
2033
|
1201 |
section {* Related Work *}
|
|
1202 |
|
|
1203 |
text {*
|
|
1204 |
Add here comparison with old work.
|
|
1205 |
*}
|
|
1206 |
|
1785
|
1207 |
|
|
1208 |
section {* Conclusion *}
|
|
1209 |
|
|
1210 |
text {*
|
|
1211 |
This proof pearl describes a new formalisation of the nominal logic work by
|
|
1212 |
Pitts et al. With the definitions we presented here, the formal reasoning blends
|
|
1213 |
smoothly with the infrastructure of the Isabelle/HOL theorem prover.
|
|
1214 |
Therefore the formalisation will be the underlying theory for a
|
|
1215 |
new version of Nominal Isabelle.
|
|
1216 |
|
|
1217 |
The main difference of this paper with respect to existing work on Nominal
|
|
1218 |
Isabelle is the representation of atoms and permutations. First, we used a
|
|
1219 |
single type for sorted atoms. This design choice means for a term @{term t},
|
|
1220 |
say, that its support is completely characterised by @{term "supp t"}, even
|
|
1221 |
if the term contains different kinds of atoms. Also, whenever we have to
|
|
1222 |
generalise an induction so that a property @{text P} is not just established
|
|
1223 |
for all @{text t}, but for all @{text t} \emph{and} under all permutations
|
|
1224 |
@{text \<pi>}, then we only have to state @{term "\<forall>\<pi>. P (\<pi> \<bullet> t)"}. The reason is
|
|
1225 |
that permutations can now consist of multiple swapping each of which can
|
|
1226 |
swap different kinds of atoms. This simplifies considerably the reasoning
|
|
1227 |
involved in building Nominal Isabelle.
|
|
1228 |
|
|
1229 |
Second, we represented permutations as functions so that the associated
|
|
1230 |
permutation operation has only a single type parameter. This is very convenient
|
|
1231 |
because the abstract reasoning about permutations fits cleanly
|
|
1232 |
with Isabelle/HOL's type classes. No custom ML-code is required to work
|
|
1233 |
around rough edges. Moreover, by establishing that our permutations-as-functions
|
|
1234 |
representation satisfy the group properties, we were able to use extensively
|
|
1235 |
Isabelle/HOL's reasoning infrastructure for groups. This often reduced proofs
|
|
1236 |
to simple calculations over @{text "+"}, @{text "-"} and @{text "0"}.
|
|
1237 |
An interesting point is that we defined the swapping operation so that a
|
|
1238 |
swapping of two atoms with different sorts is \emph{not} excluded, like
|
|
1239 |
in our older work on Nominal Isabelle, but there is no ``effect'' of such
|
|
1240 |
a swapping (it is defined as the identity). This is a crucial insight
|
|
1241 |
in order to make the approach based on a single type of sorted atoms to work.
|
|
1242 |
But of course it is analogous to the well-known trick of defining division by
|
|
1243 |
zero to return zero.
|
|
1244 |
|
|
1245 |
We noticed only one disadvantage of the permutations-as-functions: Over
|
1809
|
1246 |
lists we can easily perform inductions. For permutations made up from
|
1785
|
1247 |
functions, we have to manually derive an appropriate induction principle. We
|
|
1248 |
can establish such a principle, but we have no real experience yet whether ours
|
|
1249 |
is the most useful principle: such an induction principle was not needed in
|
|
1250 |
any of the reasoning we ported from the old Nominal Isabelle, except
|
|
1251 |
when showing that if @{term "\<forall>a \<in> supp x. a \<sharp> p"} implies @{term "p \<bullet> x = x"}.
|
|
1252 |
|
|
1253 |
Finally, our implementation of sorted atoms turned out powerful enough to
|
|
1254 |
use it for representing variables that carry on additional information, for
|
|
1255 |
example typing annotations. This information is encoded into the sorts. With
|
|
1256 |
this we can represent conveniently binding in ``Church-style'' lambda-terms
|
|
1257 |
and HOL-based languages. While dealing with such additional information in
|
|
1258 |
dependent type-theories, such as LF or Coq, is straightforward, we are not
|
|
1259 |
aware of any other approach in a non-dependent HOL-setting that can deal
|
|
1260 |
conveniently with such binders.
|
|
1261 |
|
|
1262 |
The formalisation presented here will eventually become part of the Isabelle
|
|
1263 |
distribution, but for the moment it can be downloaded from the
|
|
1264 |
Mercurial repository linked at
|
|
1265 |
\href{http://isabelle.in.tum.de/nominal/download}
|
|
1266 |
{http://isabelle.in.tum.de/nominal/download}.\smallskip
|
|
1267 |
|
|
1268 |
\noindent
|
|
1269 |
{\bf Acknowledgements:} We are very grateful to Jesper Bengtson, Stefan
|
|
1270 |
Berghofer and Cezary Kaliszyk for their comments on earlier versions
|
|
1271 |
of this paper. We are also grateful to the anonymous referee who helped us to
|
|
1272 |
put the work into the right context.
|
|
1273 |
*}
|
|
1274 |
|
|
1275 |
|
|
1276 |
(*<*)
|
|
1277 |
end
|
|
1278 |
(*>*) |