1 (* Title: Nominal2_Base |
|
2 Authors: Brian Huffman, Christian Urban |
|
3 |
|
4 Basic definitions and lemma infrastructure for |
|
5 Nominal Isabelle. |
|
6 *) |
|
7 theory Nominal2_Base |
|
8 imports Main Infinite_Set |
|
9 begin |
|
10 |
|
11 section {* Atoms and Sorts *} |
|
12 |
|
13 text {* A simple implementation for atom_sorts is strings. *} |
|
14 (* types atom_sort = string *) |
|
15 |
|
16 text {* To deal with Church-like binding we use trees of |
|
17 strings as sorts. *} |
|
18 |
|
19 datatype atom_sort = Sort "string" "atom_sort list" |
|
20 |
|
21 datatype atom = Atom atom_sort nat |
|
22 |
|
23 |
|
24 text {* Basic projection function. *} |
|
25 |
|
26 primrec |
|
27 sort_of :: "atom \<Rightarrow> atom_sort" |
|
28 where |
|
29 "sort_of (Atom s i) = s" |
|
30 |
|
31 |
|
32 text {* There are infinitely many atoms of each sort. *} |
|
33 lemma INFM_sort_of_eq: |
|
34 shows "INFM a. sort_of a = s" |
|
35 proof - |
|
36 have "INFM i. sort_of (Atom s i) = s" by simp |
|
37 moreover have "inj (Atom s)" by (simp add: inj_on_def) |
|
38 ultimately show "INFM a. sort_of a = s" by (rule INFM_inj) |
|
39 qed |
|
40 |
|
41 lemma infinite_sort_of_eq: |
|
42 shows "infinite {a. sort_of a = s}" |
|
43 using INFM_sort_of_eq unfolding INFM_iff_infinite . |
|
44 |
|
45 lemma atom_infinite [simp]: |
|
46 shows "infinite (UNIV :: atom set)" |
|
47 using subset_UNIV infinite_sort_of_eq |
|
48 by (rule infinite_super) |
|
49 |
|
50 lemma obtain_atom: |
|
51 fixes X :: "atom set" |
|
52 assumes X: "finite X" |
|
53 obtains a where "a \<notin> X" "sort_of a = s" |
|
54 proof - |
|
55 from X have "MOST a. a \<notin> X" |
|
56 unfolding MOST_iff_cofinite by simp |
|
57 with INFM_sort_of_eq |
|
58 have "INFM a. sort_of a = s \<and> a \<notin> X" |
|
59 by (rule INFM_conjI) |
|
60 then obtain a where "a \<notin> X" "sort_of a = s" |
|
61 by (auto elim: INFM_E) |
|
62 then show ?thesis .. |
|
63 qed |
|
64 |
|
65 section {* Sort-Respecting Permutations *} |
|
66 |
|
67 typedef perm = |
|
68 "{f. bij f \<and> finite {a. f a \<noteq> a} \<and> (\<forall>a. sort_of (f a) = sort_of a)}" |
|
69 proof |
|
70 show "id \<in> ?perm" by simp |
|
71 qed |
|
72 |
|
73 lemma permI: |
|
74 assumes "bij f" and "MOST x. f x = x" and "\<And>a. sort_of (f a) = sort_of a" |
|
75 shows "f \<in> perm" |
|
76 using assms unfolding perm_def MOST_iff_cofinite by simp |
|
77 |
|
78 lemma perm_is_bij: "f \<in> perm \<Longrightarrow> bij f" |
|
79 unfolding perm_def by simp |
|
80 |
|
81 lemma perm_is_finite: "f \<in> perm \<Longrightarrow> finite {a. f a \<noteq> a}" |
|
82 unfolding perm_def by simp |
|
83 |
|
84 lemma perm_is_sort_respecting: "f \<in> perm \<Longrightarrow> sort_of (f a) = sort_of a" |
|
85 unfolding perm_def by simp |
|
86 |
|
87 lemma perm_MOST: "f \<in> perm \<Longrightarrow> MOST x. f x = x" |
|
88 unfolding perm_def MOST_iff_cofinite by simp |
|
89 |
|
90 lemma perm_id: "id \<in> perm" |
|
91 unfolding perm_def by simp |
|
92 |
|
93 lemma perm_comp: |
|
94 assumes f: "f \<in> perm" and g: "g \<in> perm" |
|
95 shows "(f \<circ> g) \<in> perm" |
|
96 apply (rule permI) |
|
97 apply (rule bij_comp) |
|
98 apply (rule perm_is_bij [OF g]) |
|
99 apply (rule perm_is_bij [OF f]) |
|
100 apply (rule MOST_rev_mp [OF perm_MOST [OF g]]) |
|
101 apply (rule MOST_rev_mp [OF perm_MOST [OF f]]) |
|
102 apply (simp) |
|
103 apply (simp add: perm_is_sort_respecting [OF f]) |
|
104 apply (simp add: perm_is_sort_respecting [OF g]) |
|
105 done |
|
106 |
|
107 lemma perm_inv: |
|
108 assumes f: "f \<in> perm" |
|
109 shows "(inv f) \<in> perm" |
|
110 apply (rule permI) |
|
111 apply (rule bij_imp_bij_inv) |
|
112 apply (rule perm_is_bij [OF f]) |
|
113 apply (rule MOST_mono [OF perm_MOST [OF f]]) |
|
114 apply (erule subst, rule inv_f_f) |
|
115 apply (rule bij_is_inj [OF perm_is_bij [OF f]]) |
|
116 apply (rule perm_is_sort_respecting [OF f, THEN sym, THEN trans]) |
|
117 apply (simp add: surj_f_inv_f [OF bij_is_surj [OF perm_is_bij [OF f]]]) |
|
118 done |
|
119 |
|
120 lemma bij_Rep_perm: "bij (Rep_perm p)" |
|
121 using Rep_perm [of p] unfolding perm_def by simp |
|
122 |
|
123 lemma finite_Rep_perm: "finite {a. Rep_perm p a \<noteq> a}" |
|
124 using Rep_perm [of p] unfolding perm_def by simp |
|
125 |
|
126 lemma sort_of_Rep_perm: "sort_of (Rep_perm p a) = sort_of a" |
|
127 using Rep_perm [of p] unfolding perm_def by simp |
|
128 |
|
129 lemma Rep_perm_ext: |
|
130 "Rep_perm p1 = Rep_perm p2 \<Longrightarrow> p1 = p2" |
|
131 by (simp add: expand_fun_eq Rep_perm_inject [symmetric]) |
|
132 |
|
133 |
|
134 subsection {* Permutations form a group *} |
|
135 |
|
136 instantiation perm :: group_add |
|
137 begin |
|
138 |
|
139 definition |
|
140 "0 = Abs_perm id" |
|
141 |
|
142 definition |
|
143 "- p = Abs_perm (inv (Rep_perm p))" |
|
144 |
|
145 definition |
|
146 "p + q = Abs_perm (Rep_perm p \<circ> Rep_perm q)" |
|
147 |
|
148 definition |
|
149 "(p1::perm) - p2 = p1 + - p2" |
|
150 |
|
151 lemma Rep_perm_0: "Rep_perm 0 = id" |
|
152 unfolding zero_perm_def |
|
153 by (simp add: Abs_perm_inverse perm_id) |
|
154 |
|
155 lemma Rep_perm_add: |
|
156 "Rep_perm (p1 + p2) = Rep_perm p1 \<circ> Rep_perm p2" |
|
157 unfolding plus_perm_def |
|
158 by (simp add: Abs_perm_inverse perm_comp Rep_perm) |
|
159 |
|
160 lemma Rep_perm_uminus: |
|
161 "Rep_perm (- p) = inv (Rep_perm p)" |
|
162 unfolding uminus_perm_def |
|
163 by (simp add: Abs_perm_inverse perm_inv Rep_perm) |
|
164 |
|
165 instance |
|
166 apply default |
|
167 unfolding Rep_perm_inject [symmetric] |
|
168 unfolding minus_perm_def |
|
169 unfolding Rep_perm_add |
|
170 unfolding Rep_perm_uminus |
|
171 unfolding Rep_perm_0 |
|
172 by (simp_all add: o_assoc inv_o_cancel [OF bij_is_inj [OF bij_Rep_perm]]) |
|
173 |
|
174 end |
|
175 |
|
176 |
|
177 section {* Implementation of swappings *} |
|
178 |
|
179 definition |
|
180 swap :: "atom \<Rightarrow> atom \<Rightarrow> perm" ("'(_ \<rightleftharpoons> _')") |
|
181 where |
|
182 "(a \<rightleftharpoons> b) = |
|
183 Abs_perm (if sort_of a = sort_of b |
|
184 then (\<lambda>c. if a = c then b else if b = c then a else c) |
|
185 else id)" |
|
186 |
|
187 lemma Rep_perm_swap: |
|
188 "Rep_perm (a \<rightleftharpoons> b) = |
|
189 (if sort_of a = sort_of b |
|
190 then (\<lambda>c. if a = c then b else if b = c then a else c) |
|
191 else id)" |
|
192 unfolding swap_def |
|
193 apply (rule Abs_perm_inverse) |
|
194 apply (rule permI) |
|
195 apply (auto simp add: bij_def inj_on_def surj_def)[1] |
|
196 apply (rule MOST_rev_mp [OF MOST_neq(1) [of a]]) |
|
197 apply (rule MOST_rev_mp [OF MOST_neq(1) [of b]]) |
|
198 apply (simp) |
|
199 apply (simp) |
|
200 done |
|
201 |
|
202 lemmas Rep_perm_simps = |
|
203 Rep_perm_0 |
|
204 Rep_perm_add |
|
205 Rep_perm_uminus |
|
206 Rep_perm_swap |
|
207 |
|
208 lemma swap_different_sorts [simp]: |
|
209 "sort_of a \<noteq> sort_of b \<Longrightarrow> (a \<rightleftharpoons> b) = 0" |
|
210 by (rule Rep_perm_ext) (simp add: Rep_perm_simps) |
|
211 |
|
212 lemma swap_cancel: |
|
213 "(a \<rightleftharpoons> b) + (a \<rightleftharpoons> b) = 0" |
|
214 by (rule Rep_perm_ext) |
|
215 (simp add: Rep_perm_simps expand_fun_eq) |
|
216 |
|
217 lemma swap_self [simp]: |
|
218 "(a \<rightleftharpoons> a) = 0" |
|
219 by (rule Rep_perm_ext, simp add: Rep_perm_simps expand_fun_eq) |
|
220 |
|
221 lemma minus_swap [simp]: |
|
222 "- (a \<rightleftharpoons> b) = (a \<rightleftharpoons> b)" |
|
223 by (rule minus_unique [OF swap_cancel]) |
|
224 |
|
225 lemma swap_commute: |
|
226 "(a \<rightleftharpoons> b) = (b \<rightleftharpoons> a)" |
|
227 by (rule Rep_perm_ext) |
|
228 (simp add: Rep_perm_swap expand_fun_eq) |
|
229 |
|
230 lemma swap_triple: |
|
231 assumes "a \<noteq> b" and "c \<noteq> b" |
|
232 assumes "sort_of a = sort_of b" "sort_of b = sort_of c" |
|
233 shows "(a \<rightleftharpoons> c) + (b \<rightleftharpoons> c) + (a \<rightleftharpoons> c) = (a \<rightleftharpoons> b)" |
|
234 using assms |
|
235 by (rule_tac Rep_perm_ext) |
|
236 (auto simp add: Rep_perm_simps expand_fun_eq) |
|
237 |
|
238 |
|
239 section {* Permutation Types *} |
|
240 |
|
241 text {* |
|
242 Infix syntax for @{text permute} has higher precedence than |
|
243 addition, but lower than unary minus. |
|
244 *} |
|
245 |
|
246 class pt = |
|
247 fixes permute :: "perm \<Rightarrow> 'a \<Rightarrow> 'a" ("_ \<bullet> _" [76, 75] 75) |
|
248 assumes permute_zero [simp]: "0 \<bullet> x = x" |
|
249 assumes permute_plus [simp]: "(p + q) \<bullet> x = p \<bullet> (q \<bullet> x)" |
|
250 begin |
|
251 |
|
252 lemma permute_diff [simp]: |
|
253 shows "(p - q) \<bullet> x = p \<bullet> - q \<bullet> x" |
|
254 unfolding diff_minus by simp |
|
255 |
|
256 lemma permute_minus_cancel [simp]: |
|
257 shows "p \<bullet> - p \<bullet> x = x" |
|
258 and "- p \<bullet> p \<bullet> x = x" |
|
259 unfolding permute_plus [symmetric] by simp_all |
|
260 |
|
261 lemma permute_swap_cancel [simp]: |
|
262 shows "(a \<rightleftharpoons> b) \<bullet> (a \<rightleftharpoons> b) \<bullet> x = x" |
|
263 unfolding permute_plus [symmetric] |
|
264 by (simp add: swap_cancel) |
|
265 |
|
266 lemma permute_swap_cancel2 [simp]: |
|
267 shows "(a \<rightleftharpoons> b) \<bullet> (b \<rightleftharpoons> a) \<bullet> x = x" |
|
268 unfolding permute_plus [symmetric] |
|
269 by (simp add: swap_commute) |
|
270 |
|
271 lemma inj_permute [simp]: |
|
272 shows "inj (permute p)" |
|
273 by (rule inj_on_inverseI) |
|
274 (rule permute_minus_cancel) |
|
275 |
|
276 lemma surj_permute [simp]: |
|
277 shows "surj (permute p)" |
|
278 by (rule surjI, rule permute_minus_cancel) |
|
279 |
|
280 lemma bij_permute [simp]: |
|
281 shows "bij (permute p)" |
|
282 by (rule bijI [OF inj_permute surj_permute]) |
|
283 |
|
284 lemma inv_permute: |
|
285 shows "inv (permute p) = permute (- p)" |
|
286 by (rule inv_equality) (simp_all) |
|
287 |
|
288 lemma permute_minus: |
|
289 shows "permute (- p) = inv (permute p)" |
|
290 by (simp add: inv_permute) |
|
291 |
|
292 lemma permute_eq_iff [simp]: |
|
293 shows "p \<bullet> x = p \<bullet> y \<longleftrightarrow> x = y" |
|
294 by (rule inj_permute [THEN inj_eq]) |
|
295 |
|
296 end |
|
297 |
|
298 subsection {* Permutations for atoms *} |
|
299 |
|
300 instantiation atom :: pt |
|
301 begin |
|
302 |
|
303 definition |
|
304 "p \<bullet> a = Rep_perm p a" |
|
305 |
|
306 instance |
|
307 apply(default) |
|
308 apply(simp_all add: permute_atom_def Rep_perm_simps) |
|
309 done |
|
310 |
|
311 end |
|
312 |
|
313 lemma sort_of_permute [simp]: |
|
314 shows "sort_of (p \<bullet> a) = sort_of a" |
|
315 unfolding permute_atom_def by (rule sort_of_Rep_perm) |
|
316 |
|
317 lemma swap_atom: |
|
318 shows "(a \<rightleftharpoons> b) \<bullet> c = |
|
319 (if sort_of a = sort_of b |
|
320 then (if c = a then b else if c = b then a else c) else c)" |
|
321 unfolding permute_atom_def |
|
322 by (simp add: Rep_perm_swap) |
|
323 |
|
324 lemma swap_atom_simps [simp]: |
|
325 "sort_of a = sort_of b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> a = b" |
|
326 "sort_of a = sort_of b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> b = a" |
|
327 "c \<noteq> a \<Longrightarrow> c \<noteq> b \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> c = c" |
|
328 unfolding swap_atom by simp_all |
|
329 |
|
330 lemma expand_perm_eq: |
|
331 fixes p q :: "perm" |
|
332 shows "p = q \<longleftrightarrow> (\<forall>a::atom. p \<bullet> a = q \<bullet> a)" |
|
333 unfolding permute_atom_def |
|
334 by (metis Rep_perm_ext ext) |
|
335 |
|
336 |
|
337 subsection {* Permutations for permutations *} |
|
338 |
|
339 instantiation perm :: pt |
|
340 begin |
|
341 |
|
342 definition |
|
343 "p \<bullet> q = p + q - p" |
|
344 |
|
345 instance |
|
346 apply default |
|
347 apply (simp add: permute_perm_def) |
|
348 apply (simp add: permute_perm_def diff_minus minus_add add_assoc) |
|
349 done |
|
350 |
|
351 end |
|
352 |
|
353 lemma permute_self: "p \<bullet> p = p" |
|
354 unfolding permute_perm_def by (simp add: diff_minus add_assoc) |
|
355 |
|
356 lemma permute_eqvt: |
|
357 shows "p \<bullet> (q \<bullet> x) = (p \<bullet> q) \<bullet> (p \<bullet> x)" |
|
358 unfolding permute_perm_def by simp |
|
359 |
|
360 lemma zero_perm_eqvt: |
|
361 shows "p \<bullet> (0::perm) = 0" |
|
362 unfolding permute_perm_def by simp |
|
363 |
|
364 lemma add_perm_eqvt: |
|
365 fixes p p1 p2 :: perm |
|
366 shows "p \<bullet> (p1 + p2) = p \<bullet> p1 + p \<bullet> p2" |
|
367 unfolding permute_perm_def |
|
368 by (simp add: expand_perm_eq) |
|
369 |
|
370 lemma swap_eqvt: |
|
371 shows "p \<bullet> (a \<rightleftharpoons> b) = (p \<bullet> a \<rightleftharpoons> p \<bullet> b)" |
|
372 unfolding permute_perm_def |
|
373 by (auto simp add: swap_atom expand_perm_eq) |
|
374 |
|
375 |
|
376 subsection {* Permutations for functions *} |
|
377 |
|
378 instantiation "fun" :: (pt, pt) pt |
|
379 begin |
|
380 |
|
381 definition |
|
382 "p \<bullet> f = (\<lambda>x. p \<bullet> (f (- p \<bullet> x)))" |
|
383 |
|
384 instance |
|
385 apply default |
|
386 apply (simp add: permute_fun_def) |
|
387 apply (simp add: permute_fun_def minus_add) |
|
388 done |
|
389 |
|
390 end |
|
391 |
|
392 lemma permute_fun_app_eq: |
|
393 shows "p \<bullet> (f x) = (p \<bullet> f) (p \<bullet> x)" |
|
394 unfolding permute_fun_def by simp |
|
395 |
|
396 |
|
397 subsection {* Permutations for booleans *} |
|
398 |
|
399 instantiation bool :: pt |
|
400 begin |
|
401 |
|
402 definition "p \<bullet> (b::bool) = b" |
|
403 |
|
404 instance |
|
405 apply(default) |
|
406 apply(simp_all add: permute_bool_def) |
|
407 done |
|
408 |
|
409 end |
|
410 |
|
411 lemma Not_eqvt: |
|
412 shows "p \<bullet> (\<not> A) = (\<not> (p \<bullet> A))" |
|
413 by (simp add: permute_bool_def) |
|
414 |
|
415 |
|
416 subsection {* Permutations for sets *} |
|
417 |
|
418 lemma permute_set_eq: |
|
419 fixes x::"'a::pt" |
|
420 and p::"perm" |
|
421 shows "(p \<bullet> X) = {p \<bullet> x | x. x \<in> X}" |
|
422 apply(auto simp add: permute_fun_def permute_bool_def mem_def) |
|
423 apply(rule_tac x="- p \<bullet> x" in exI) |
|
424 apply(simp) |
|
425 done |
|
426 |
|
427 lemma permute_set_eq_image: |
|
428 shows "p \<bullet> X = permute p ` X" |
|
429 unfolding permute_set_eq by auto |
|
430 |
|
431 lemma permute_set_eq_vimage: |
|
432 shows "p \<bullet> X = permute (- p) -` X" |
|
433 unfolding permute_fun_def permute_bool_def |
|
434 unfolding vimage_def Collect_def mem_def .. |
|
435 |
|
436 lemma swap_set_not_in: |
|
437 assumes a: "a \<notin> S" "b \<notin> S" |
|
438 shows "(a \<rightleftharpoons> b) \<bullet> S = S" |
|
439 using a by (auto simp add: permute_set_eq swap_atom) |
|
440 |
|
441 lemma swap_set_in: |
|
442 assumes a: "a \<in> S" "b \<notin> S" "sort_of a = sort_of b" |
|
443 shows "(a \<rightleftharpoons> b) \<bullet> S \<noteq> S" |
|
444 using a by (auto simp add: permute_set_eq swap_atom) |
|
445 |
|
446 |
|
447 subsection {* Permutations for units *} |
|
448 |
|
449 instantiation unit :: pt |
|
450 begin |
|
451 |
|
452 definition "p \<bullet> (u::unit) = u" |
|
453 |
|
454 instance proof |
|
455 qed (simp_all add: permute_unit_def) |
|
456 |
|
457 end |
|
458 |
|
459 |
|
460 subsection {* Permutations for products *} |
|
461 |
|
462 instantiation "*" :: (pt, pt) pt |
|
463 begin |
|
464 |
|
465 primrec |
|
466 permute_prod |
|
467 where |
|
468 Pair_eqvt: "p \<bullet> (x, y) = (p \<bullet> x, p \<bullet> y)" |
|
469 |
|
470 instance |
|
471 by default auto |
|
472 |
|
473 end |
|
474 |
|
475 subsection {* Permutations for sums *} |
|
476 |
|
477 instantiation "+" :: (pt, pt) pt |
|
478 begin |
|
479 |
|
480 primrec |
|
481 permute_sum |
|
482 where |
|
483 "p \<bullet> (Inl x) = Inl (p \<bullet> x)" |
|
484 | "p \<bullet> (Inr y) = Inr (p \<bullet> y)" |
|
485 |
|
486 instance proof |
|
487 qed (case_tac [!] x, simp_all) |
|
488 |
|
489 end |
|
490 |
|
491 subsection {* Permutations for lists *} |
|
492 |
|
493 instantiation list :: (pt) pt |
|
494 begin |
|
495 |
|
496 primrec |
|
497 permute_list |
|
498 where |
|
499 "p \<bullet> [] = []" |
|
500 | "p \<bullet> (x # xs) = p \<bullet> x # p \<bullet> xs" |
|
501 |
|
502 instance proof |
|
503 qed (induct_tac [!] x, simp_all) |
|
504 |
|
505 end |
|
506 |
|
507 subsection {* Permutations for options *} |
|
508 |
|
509 instantiation option :: (pt) pt |
|
510 begin |
|
511 |
|
512 primrec |
|
513 permute_option |
|
514 where |
|
515 "p \<bullet> None = None" |
|
516 | "p \<bullet> (Some x) = Some (p \<bullet> x)" |
|
517 |
|
518 instance proof |
|
519 qed (induct_tac [!] x, simp_all) |
|
520 |
|
521 end |
|
522 |
|
523 subsection {* Permutations for @{typ char}, @{typ nat}, and @{typ int} *} |
|
524 |
|
525 instantiation char :: pt |
|
526 begin |
|
527 |
|
528 definition "p \<bullet> (c::char) = c" |
|
529 |
|
530 instance proof |
|
531 qed (simp_all add: permute_char_def) |
|
532 |
|
533 end |
|
534 |
|
535 instantiation nat :: pt |
|
536 begin |
|
537 |
|
538 definition "p \<bullet> (n::nat) = n" |
|
539 |
|
540 instance proof |
|
541 qed (simp_all add: permute_nat_def) |
|
542 |
|
543 end |
|
544 |
|
545 instantiation int :: pt |
|
546 begin |
|
547 |
|
548 definition "p \<bullet> (i::int) = i" |
|
549 |
|
550 instance proof |
|
551 qed (simp_all add: permute_int_def) |
|
552 |
|
553 end |
|
554 |
|
555 |
|
556 section {* Pure types *} |
|
557 |
|
558 text {* Pure types will have always empty support. *} |
|
559 |
|
560 class pure = pt + |
|
561 assumes permute_pure: "p \<bullet> x = x" |
|
562 |
|
563 text {* Types @{typ unit} and @{typ bool} are pure. *} |
|
564 |
|
565 instance unit :: pure |
|
566 proof qed (rule permute_unit_def) |
|
567 |
|
568 instance bool :: pure |
|
569 proof qed (rule permute_bool_def) |
|
570 |
|
571 text {* Other type constructors preserve purity. *} |
|
572 |
|
573 instance "fun" :: (pure, pure) pure |
|
574 by default (simp add: permute_fun_def permute_pure) |
|
575 |
|
576 instance "*" :: (pure, pure) pure |
|
577 by default (induct_tac x, simp add: permute_pure) |
|
578 |
|
579 instance "+" :: (pure, pure) pure |
|
580 by default (induct_tac x, simp_all add: permute_pure) |
|
581 |
|
582 instance list :: (pure) pure |
|
583 by default (induct_tac x, simp_all add: permute_pure) |
|
584 |
|
585 instance option :: (pure) pure |
|
586 by default (induct_tac x, simp_all add: permute_pure) |
|
587 |
|
588 |
|
589 subsection {* Types @{typ char}, @{typ nat}, and @{typ int} *} |
|
590 |
|
591 instance char :: pure |
|
592 proof qed (rule permute_char_def) |
|
593 |
|
594 instance nat :: pure |
|
595 proof qed (rule permute_nat_def) |
|
596 |
|
597 instance int :: pure |
|
598 proof qed (rule permute_int_def) |
|
599 |
|
600 |
|
601 subsection {* Supp, Freshness and Supports *} |
|
602 |
|
603 context pt |
|
604 begin |
|
605 |
|
606 definition |
|
607 supp :: "'a \<Rightarrow> atom set" |
|
608 where |
|
609 "supp x = {a. infinite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}}" |
|
610 |
|
611 end |
|
612 |
|
613 definition |
|
614 fresh :: "atom \<Rightarrow> 'a::pt \<Rightarrow> bool" ("_ \<sharp> _" [55, 55] 55) |
|
615 where |
|
616 "a \<sharp> x \<equiv> a \<notin> supp x" |
|
617 |
|
618 lemma supp_conv_fresh: |
|
619 shows "supp x = {a. \<not> a \<sharp> x}" |
|
620 unfolding fresh_def by simp |
|
621 |
|
622 lemma swap_rel_trans: |
|
623 assumes "sort_of a = sort_of b" |
|
624 assumes "sort_of b = sort_of c" |
|
625 assumes "(a \<rightleftharpoons> c) \<bullet> x = x" |
|
626 assumes "(b \<rightleftharpoons> c) \<bullet> x = x" |
|
627 shows "(a \<rightleftharpoons> b) \<bullet> x = x" |
|
628 proof (cases) |
|
629 assume "a = b \<or> c = b" |
|
630 with assms show "(a \<rightleftharpoons> b) \<bullet> x = x" by auto |
|
631 next |
|
632 assume *: "\<not> (a = b \<or> c = b)" |
|
633 have "((a \<rightleftharpoons> c) + (b \<rightleftharpoons> c) + (a \<rightleftharpoons> c)) \<bullet> x = x" |
|
634 using assms by simp |
|
635 also have "(a \<rightleftharpoons> c) + (b \<rightleftharpoons> c) + (a \<rightleftharpoons> c) = (a \<rightleftharpoons> b)" |
|
636 using assms * by (simp add: swap_triple) |
|
637 finally show "(a \<rightleftharpoons> b) \<bullet> x = x" . |
|
638 qed |
|
639 |
|
640 lemma swap_fresh_fresh: |
|
641 assumes a: "a \<sharp> x" |
|
642 and b: "b \<sharp> x" |
|
643 shows "(a \<rightleftharpoons> b) \<bullet> x = x" |
|
644 proof (cases) |
|
645 assume asm: "sort_of a = sort_of b" |
|
646 have "finite {c. (a \<rightleftharpoons> c) \<bullet> x \<noteq> x}" "finite {c. (b \<rightleftharpoons> c) \<bullet> x \<noteq> x}" |
|
647 using a b unfolding fresh_def supp_def by simp_all |
|
648 then have "finite ({c. (a \<rightleftharpoons> c) \<bullet> x \<noteq> x} \<union> {c. (b \<rightleftharpoons> c) \<bullet> x \<noteq> x})" by simp |
|
649 then obtain c |
|
650 where "(a \<rightleftharpoons> c) \<bullet> x = x" "(b \<rightleftharpoons> c) \<bullet> x = x" "sort_of c = sort_of b" |
|
651 by (rule obtain_atom) (auto) |
|
652 then show "(a \<rightleftharpoons> b) \<bullet> x = x" using asm by (rule_tac swap_rel_trans) (simp_all) |
|
653 next |
|
654 assume "sort_of a \<noteq> sort_of b" |
|
655 then show "(a \<rightleftharpoons> b) \<bullet> x = x" by simp |
|
656 qed |
|
657 |
|
658 |
|
659 subsection {* supp and fresh are equivariant *} |
|
660 |
|
661 lemma finite_Collect_bij: |
|
662 assumes a: "bij f" |
|
663 shows "finite {x. P (f x)} = finite {x. P x}" |
|
664 by (metis a finite_vimage_iff vimage_Collect_eq) |
|
665 |
|
666 lemma fresh_permute_iff: |
|
667 shows "(p \<bullet> a) \<sharp> (p \<bullet> x) \<longleftrightarrow> a \<sharp> x" |
|
668 proof - |
|
669 have "(p \<bullet> a) \<sharp> (p \<bullet> x) \<longleftrightarrow> finite {b. (p \<bullet> a \<rightleftharpoons> b) \<bullet> p \<bullet> x \<noteq> p \<bullet> x}" |
|
670 unfolding fresh_def supp_def by simp |
|
671 also have "\<dots> \<longleftrightarrow> finite {b. (p \<bullet> a \<rightleftharpoons> p \<bullet> b) \<bullet> p \<bullet> x \<noteq> p \<bullet> x}" |
|
672 using bij_permute by (rule finite_Collect_bij [symmetric]) |
|
673 also have "\<dots> \<longleftrightarrow> finite {b. p \<bullet> (a \<rightleftharpoons> b) \<bullet> x \<noteq> p \<bullet> x}" |
|
674 by (simp only: permute_eqvt [of p] swap_eqvt) |
|
675 also have "\<dots> \<longleftrightarrow> finite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}" |
|
676 by (simp only: permute_eq_iff) |
|
677 also have "\<dots> \<longleftrightarrow> a \<sharp> x" |
|
678 unfolding fresh_def supp_def by simp |
|
679 finally show ?thesis . |
|
680 qed |
|
681 |
|
682 lemma fresh_eqvt: |
|
683 shows "p \<bullet> (a \<sharp> x) = (p \<bullet> a) \<sharp> (p \<bullet> x)" |
|
684 by (simp add: permute_bool_def fresh_permute_iff) |
|
685 |
|
686 lemma supp_eqvt: |
|
687 fixes p :: "perm" |
|
688 and x :: "'a::pt" |
|
689 shows "p \<bullet> (supp x) = supp (p \<bullet> x)" |
|
690 unfolding supp_conv_fresh |
|
691 unfolding permute_fun_def Collect_def |
|
692 by (simp add: Not_eqvt fresh_eqvt) |
|
693 |
|
694 subsection {* supports *} |
|
695 |
|
696 definition |
|
697 supports :: "atom set \<Rightarrow> 'a::pt \<Rightarrow> bool" (infixl "supports" 80) |
|
698 where |
|
699 "S supports x \<equiv> \<forall>a b. (a \<notin> S \<and> b \<notin> S \<longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x)" |
|
700 |
|
701 lemma supp_is_subset: |
|
702 fixes S :: "atom set" |
|
703 and x :: "'a::pt" |
|
704 assumes a1: "S supports x" |
|
705 and a2: "finite S" |
|
706 shows "(supp x) \<subseteq> S" |
|
707 proof (rule ccontr) |
|
708 assume "\<not>(supp x \<subseteq> S)" |
|
709 then obtain a where b1: "a \<in> supp x" and b2: "a \<notin> S" by auto |
|
710 from a1 b2 have "\<forall>b. b \<notin> S \<longrightarrow> (a \<rightleftharpoons> b) \<bullet> x = x" by (unfold supports_def) (auto) |
|
711 hence "{b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x} \<subseteq> S" by auto |
|
712 with a2 have "finite {b. (a \<rightleftharpoons> b)\<bullet>x \<noteq> x}" by (simp add: finite_subset) |
|
713 then have "a \<notin> (supp x)" unfolding supp_def by simp |
|
714 with b1 show False by simp |
|
715 qed |
|
716 |
|
717 lemma supports_finite: |
|
718 fixes S :: "atom set" |
|
719 and x :: "'a::pt" |
|
720 assumes a1: "S supports x" |
|
721 and a2: "finite S" |
|
722 shows "finite (supp x)" |
|
723 proof - |
|
724 have "(supp x) \<subseteq> S" using a1 a2 by (rule supp_is_subset) |
|
725 then show "finite (supp x)" using a2 by (simp add: finite_subset) |
|
726 qed |
|
727 |
|
728 lemma supp_supports: |
|
729 fixes x :: "'a::pt" |
|
730 shows "(supp x) supports x" |
|
731 proof (unfold supports_def, intro strip) |
|
732 fix a b |
|
733 assume "a \<notin> (supp x) \<and> b \<notin> (supp x)" |
|
734 then have "a \<sharp> x" and "b \<sharp> x" by (simp_all add: fresh_def) |
|
735 then show "(a \<rightleftharpoons> b) \<bullet> x = x" by (rule swap_fresh_fresh) |
|
736 qed |
|
737 |
|
738 lemma supp_is_least_supports: |
|
739 fixes S :: "atom set" |
|
740 and x :: "'a::pt" |
|
741 assumes a1: "S supports x" |
|
742 and a2: "finite S" |
|
743 and a3: "\<And>S'. finite S' \<Longrightarrow> (S' supports x) \<Longrightarrow> S \<subseteq> S'" |
|
744 shows "(supp x) = S" |
|
745 proof (rule equalityI) |
|
746 show "(supp x) \<subseteq> S" using a1 a2 by (rule supp_is_subset) |
|
747 with a2 have fin: "finite (supp x)" by (rule rev_finite_subset) |
|
748 have "(supp x) supports x" by (rule supp_supports) |
|
749 with fin a3 show "S \<subseteq> supp x" by blast |
|
750 qed |
|
751 |
|
752 lemma subsetCI: |
|
753 shows "(\<And>x. x \<in> A \<Longrightarrow> x \<notin> B \<Longrightarrow> False) \<Longrightarrow> A \<subseteq> B" |
|
754 by auto |
|
755 |
|
756 lemma finite_supp_unique: |
|
757 assumes a1: "S supports x" |
|
758 assumes a2: "finite S" |
|
759 assumes a3: "\<And>a b. \<lbrakk>a \<in> S; b \<notin> S; sort_of a = sort_of b\<rbrakk> \<Longrightarrow> (a \<rightleftharpoons> b) \<bullet> x \<noteq> x" |
|
760 shows "(supp x) = S" |
|
761 using a1 a2 |
|
762 proof (rule supp_is_least_supports) |
|
763 fix S' |
|
764 assume "finite S'" and "S' supports x" |
|
765 show "S \<subseteq> S'" |
|
766 proof (rule subsetCI) |
|
767 fix a |
|
768 assume "a \<in> S" and "a \<notin> S'" |
|
769 have "finite (S \<union> S')" |
|
770 using `finite S` `finite S'` by simp |
|
771 then obtain b where "b \<notin> S \<union> S'" and "sort_of b = sort_of a" |
|
772 by (rule obtain_atom) |
|
773 then have "b \<notin> S" and "b \<notin> S'" and "sort_of a = sort_of b" |
|
774 by simp_all |
|
775 then have "(a \<rightleftharpoons> b) \<bullet> x = x" |
|
776 using `a \<notin> S'` `S' supports x` by (simp add: supports_def) |
|
777 moreover have "(a \<rightleftharpoons> b) \<bullet> x \<noteq> x" |
|
778 using `a \<in> S` `b \<notin> S` `sort_of a = sort_of b` |
|
779 by (rule a3) |
|
780 ultimately show "False" by simp |
|
781 qed |
|
782 qed |
|
783 |
|
784 section {* Finitely-supported types *} |
|
785 |
|
786 class fs = pt + |
|
787 assumes finite_supp: "finite (supp x)" |
|
788 |
|
789 lemma pure_supp: |
|
790 shows "supp (x::'a::pure) = {}" |
|
791 unfolding supp_def by (simp add: permute_pure) |
|
792 |
|
793 lemma pure_fresh: |
|
794 fixes x::"'a::pure" |
|
795 shows "a \<sharp> x" |
|
796 unfolding fresh_def by (simp add: pure_supp) |
|
797 |
|
798 instance pure < fs |
|
799 by default (simp add: pure_supp) |
|
800 |
|
801 |
|
802 subsection {* Type @{typ atom} is finitely-supported. *} |
|
803 |
|
804 lemma supp_atom: |
|
805 shows "supp a = {a}" |
|
806 apply (rule finite_supp_unique) |
|
807 apply (clarsimp simp add: supports_def) |
|
808 apply simp |
|
809 apply simp |
|
810 done |
|
811 |
|
812 lemma fresh_atom: |
|
813 shows "a \<sharp> b \<longleftrightarrow> a \<noteq> b" |
|
814 unfolding fresh_def supp_atom by simp |
|
815 |
|
816 instance atom :: fs |
|
817 by default (simp add: supp_atom) |
|
818 |
|
819 |
|
820 section {* Type @{typ perm} is finitely-supported. *} |
|
821 |
|
822 lemma perm_swap_eq: |
|
823 shows "(a \<rightleftharpoons> b) \<bullet> p = p \<longleftrightarrow> (p \<bullet> (a \<rightleftharpoons> b)) = (a \<rightleftharpoons> b)" |
|
824 unfolding permute_perm_def |
|
825 by (metis add_diff_cancel minus_perm_def) |
|
826 |
|
827 lemma supports_perm: |
|
828 shows "{a. p \<bullet> a \<noteq> a} supports p" |
|
829 unfolding supports_def |
|
830 by (simp add: perm_swap_eq swap_eqvt) |
|
831 |
|
832 lemma finite_perm_lemma: |
|
833 shows "finite {a::atom. p \<bullet> a \<noteq> a}" |
|
834 using finite_Rep_perm [of p] |
|
835 unfolding permute_atom_def . |
|
836 |
|
837 lemma supp_perm: |
|
838 shows "supp p = {a. p \<bullet> a \<noteq> a}" |
|
839 apply (rule finite_supp_unique) |
|
840 apply (rule supports_perm) |
|
841 apply (rule finite_perm_lemma) |
|
842 apply (simp add: perm_swap_eq swap_eqvt) |
|
843 apply (auto simp add: expand_perm_eq swap_atom) |
|
844 done |
|
845 |
|
846 lemma fresh_perm: |
|
847 shows "a \<sharp> p \<longleftrightarrow> p \<bullet> a = a" |
|
848 unfolding fresh_def by (simp add: supp_perm) |
|
849 |
|
850 lemma supp_swap: |
|
851 shows "supp (a \<rightleftharpoons> b) = (if a = b \<or> sort_of a \<noteq> sort_of b then {} else {a, b})" |
|
852 by (auto simp add: supp_perm swap_atom) |
|
853 |
|
854 lemma fresh_zero_perm: |
|
855 shows "a \<sharp> (0::perm)" |
|
856 unfolding fresh_perm by simp |
|
857 |
|
858 lemma supp_zero_perm: |
|
859 shows "supp (0::perm) = {}" |
|
860 unfolding supp_perm by simp |
|
861 |
|
862 lemma fresh_plus_perm: |
|
863 fixes p q::perm |
|
864 assumes "a \<sharp> p" "a \<sharp> q" |
|
865 shows "a \<sharp> (p + q)" |
|
866 using assms |
|
867 unfolding fresh_def |
|
868 by (auto simp add: supp_perm) |
|
869 |
|
870 lemma supp_plus_perm: |
|
871 fixes p q::perm |
|
872 shows "supp (p + q) \<subseteq> supp p \<union> supp q" |
|
873 by (auto simp add: supp_perm) |
|
874 |
|
875 lemma fresh_minus_perm: |
|
876 fixes p::perm |
|
877 shows "a \<sharp> (- p) \<longleftrightarrow> a \<sharp> p" |
|
878 unfolding fresh_def |
|
879 apply(auto simp add: supp_perm) |
|
880 apply(metis permute_minus_cancel)+ |
|
881 done |
|
882 |
|
883 lemma supp_minus_perm: |
|
884 fixes p::perm |
|
885 shows "supp (- p) = supp p" |
|
886 unfolding supp_conv_fresh |
|
887 by (simp add: fresh_minus_perm) |
|
888 |
|
889 instance perm :: fs |
|
890 by default (simp add: supp_perm finite_perm_lemma) |
|
891 |
|
892 |
|
893 section {* Finite Support instances for other types *} |
|
894 |
|
895 subsection {* Type @{typ "'a \<times> 'b"} is finitely-supported. *} |
|
896 |
|
897 lemma supp_Pair: |
|
898 shows "supp (x, y) = supp x \<union> supp y" |
|
899 by (simp add: supp_def Collect_imp_eq Collect_neg_eq) |
|
900 |
|
901 lemma fresh_Pair: |
|
902 shows "a \<sharp> (x, y) \<longleftrightarrow> a \<sharp> x \<and> a \<sharp> y" |
|
903 by (simp add: fresh_def supp_Pair) |
|
904 |
|
905 instance "*" :: (fs, fs) fs |
|
906 apply default |
|
907 apply (induct_tac x) |
|
908 apply (simp add: supp_Pair finite_supp) |
|
909 done |
|
910 |
|
911 subsection {* Type @{typ "'a + 'b"} is finitely supported *} |
|
912 |
|
913 lemma supp_Inl: |
|
914 shows "supp (Inl x) = supp x" |
|
915 by (simp add: supp_def) |
|
916 |
|
917 lemma supp_Inr: |
|
918 shows "supp (Inr x) = supp x" |
|
919 by (simp add: supp_def) |
|
920 |
|
921 lemma fresh_Inl: |
|
922 shows "a \<sharp> Inl x \<longleftrightarrow> a \<sharp> x" |
|
923 by (simp add: fresh_def supp_Inl) |
|
924 |
|
925 lemma fresh_Inr: |
|
926 shows "a \<sharp> Inr y \<longleftrightarrow> a \<sharp> y" |
|
927 by (simp add: fresh_def supp_Inr) |
|
928 |
|
929 instance "+" :: (fs, fs) fs |
|
930 apply default |
|
931 apply (induct_tac x) |
|
932 apply (simp_all add: supp_Inl supp_Inr finite_supp) |
|
933 done |
|
934 |
|
935 subsection {* Type @{typ "'a option"} is finitely supported *} |
|
936 |
|
937 lemma supp_None: |
|
938 shows "supp None = {}" |
|
939 by (simp add: supp_def) |
|
940 |
|
941 lemma supp_Some: |
|
942 shows "supp (Some x) = supp x" |
|
943 by (simp add: supp_def) |
|
944 |
|
945 lemma fresh_None: |
|
946 shows "a \<sharp> None" |
|
947 by (simp add: fresh_def supp_None) |
|
948 |
|
949 lemma fresh_Some: |
|
950 shows "a \<sharp> Some x \<longleftrightarrow> a \<sharp> x" |
|
951 by (simp add: fresh_def supp_Some) |
|
952 |
|
953 instance option :: (fs) fs |
|
954 apply default |
|
955 apply (induct_tac x) |
|
956 apply (simp_all add: supp_None supp_Some finite_supp) |
|
957 done |
|
958 |
|
959 subsubsection {* Type @{typ "'a list"} is finitely supported *} |
|
960 |
|
961 lemma supp_Nil: |
|
962 shows "supp [] = {}" |
|
963 by (simp add: supp_def) |
|
964 |
|
965 lemma supp_Cons: |
|
966 shows "supp (x # xs) = supp x \<union> supp xs" |
|
967 by (simp add: supp_def Collect_imp_eq Collect_neg_eq) |
|
968 |
|
969 lemma fresh_Nil: |
|
970 shows "a \<sharp> []" |
|
971 by (simp add: fresh_def supp_Nil) |
|
972 |
|
973 lemma fresh_Cons: |
|
974 shows "a \<sharp> (x # xs) \<longleftrightarrow> a \<sharp> x \<and> a \<sharp> xs" |
|
975 by (simp add: fresh_def supp_Cons) |
|
976 |
|
977 instance list :: (fs) fs |
|
978 apply default |
|
979 apply (induct_tac x) |
|
980 apply (simp_all add: supp_Nil supp_Cons finite_supp) |
|
981 done |
|
982 |
|
983 section {* Support and freshness for applications *} |
|
984 |
|
985 lemma supp_fun_app: |
|
986 shows "supp (f x) \<subseteq> (supp f) \<union> (supp x)" |
|
987 proof (rule subsetCI) |
|
988 fix a::"atom" |
|
989 assume a: "a \<in> supp (f x)" |
|
990 assume b: "a \<notin> supp f \<union> supp x" |
|
991 then have "finite {b. (a \<rightleftharpoons> b) \<bullet> f \<noteq> f}" "finite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}" |
|
992 unfolding supp_def by auto |
|
993 then have "finite ({b. (a \<rightleftharpoons> b) \<bullet> f \<noteq> f} \<union> {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x})" by simp |
|
994 moreover |
|
995 have "{b. ((a \<rightleftharpoons> b) \<bullet> f) ((a \<rightleftharpoons> b) \<bullet> x) \<noteq> f x} \<subseteq> ({b. (a \<rightleftharpoons> b) \<bullet> f \<noteq> f} \<union> {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x})" |
|
996 by auto |
|
997 ultimately have "finite {b. ((a \<rightleftharpoons> b) \<bullet> f) ((a \<rightleftharpoons> b) \<bullet> x) \<noteq> f x}" |
|
998 using finite_subset by auto |
|
999 then have "a \<notin> supp (f x)" unfolding supp_def |
|
1000 by (simp add: permute_fun_app_eq) |
|
1001 with a show "False" by simp |
|
1002 qed |
|
1003 |
|
1004 lemma fresh_fun_app: |
|
1005 shows "a \<sharp> (f, x) \<Longrightarrow> a \<sharp> f x" |
|
1006 unfolding fresh_def |
|
1007 using supp_fun_app |
|
1008 by (auto simp add: supp_Pair) |
|
1009 |
|
1010 lemma fresh_fun_eqvt_app: |
|
1011 assumes a: "\<forall>p. p \<bullet> f = f" |
|
1012 shows "a \<sharp> x \<Longrightarrow> a \<sharp> f x" |
|
1013 proof - |
|
1014 from a have b: "supp f = {}" |
|
1015 unfolding supp_def by simp |
|
1016 show "a \<sharp> x \<Longrightarrow> a \<sharp> f x" |
|
1017 unfolding fresh_def |
|
1018 using supp_fun_app b |
|
1019 by auto |
|
1020 qed |
|
1021 |
|
1022 end |
|