1062
+ − 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 supp_plus_perm:
+ − 863
fixes p q::perm
+ − 864
shows "supp (p + q) \<subseteq> supp p \<union> supp q"
+ − 865
by (auto simp add: supp_perm)
+ − 866
+ − 867
lemma supp_minus_perm:
+ − 868
fixes p::perm
+ − 869
shows "supp (- p) = supp p"
+ − 870
apply(auto simp add: supp_perm)
+ − 871
apply(metis permute_minus_cancel)+
+ − 872
done
+ − 873
+ − 874
instance perm :: fs
+ − 875
by default (simp add: supp_perm finite_perm_lemma)
+ − 876
+ − 877
+ − 878
section {* Finite Support instances for other types *}
+ − 879
+ − 880
subsection {* Type @{typ "'a \<times> 'b"} is finitely-supported. *}
+ − 881
+ − 882
lemma supp_Pair:
+ − 883
shows "supp (x, y) = supp x \<union> supp y"
+ − 884
by (simp add: supp_def Collect_imp_eq Collect_neg_eq)
+ − 885
+ − 886
lemma fresh_Pair:
+ − 887
shows "a \<sharp> (x, y) \<longleftrightarrow> a \<sharp> x \<and> a \<sharp> y"
+ − 888
by (simp add: fresh_def supp_Pair)
+ − 889
+ − 890
instance "*" :: (fs, fs) fs
+ − 891
apply default
+ − 892
apply (induct_tac x)
+ − 893
apply (simp add: supp_Pair finite_supp)
+ − 894
done
+ − 895
+ − 896
subsection {* Type @{typ "'a + 'b"} is finitely supported *}
+ − 897
+ − 898
lemma supp_Inl:
+ − 899
shows "supp (Inl x) = supp x"
+ − 900
by (simp add: supp_def)
+ − 901
+ − 902
lemma supp_Inr:
+ − 903
shows "supp (Inr x) = supp x"
+ − 904
by (simp add: supp_def)
+ − 905
+ − 906
lemma fresh_Inl:
+ − 907
shows "a \<sharp> Inl x \<longleftrightarrow> a \<sharp> x"
+ − 908
by (simp add: fresh_def supp_Inl)
+ − 909
+ − 910
lemma fresh_Inr:
+ − 911
shows "a \<sharp> Inr y \<longleftrightarrow> a \<sharp> y"
+ − 912
by (simp add: fresh_def supp_Inr)
+ − 913
+ − 914
instance "+" :: (fs, fs) fs
+ − 915
apply default
+ − 916
apply (induct_tac x)
+ − 917
apply (simp_all add: supp_Inl supp_Inr finite_supp)
+ − 918
done
+ − 919
+ − 920
subsection {* Type @{typ "'a option"} is finitely supported *}
+ − 921
+ − 922
lemma supp_None:
+ − 923
shows "supp None = {}"
+ − 924
by (simp add: supp_def)
+ − 925
+ − 926
lemma supp_Some:
+ − 927
shows "supp (Some x) = supp x"
+ − 928
by (simp add: supp_def)
+ − 929
+ − 930
lemma fresh_None:
+ − 931
shows "a \<sharp> None"
+ − 932
by (simp add: fresh_def supp_None)
+ − 933
+ − 934
lemma fresh_Some:
+ − 935
shows "a \<sharp> Some x \<longleftrightarrow> a \<sharp> x"
+ − 936
by (simp add: fresh_def supp_Some)
+ − 937
+ − 938
instance option :: (fs) fs
+ − 939
apply default
+ − 940
apply (induct_tac x)
+ − 941
apply (simp_all add: supp_None supp_Some finite_supp)
+ − 942
done
+ − 943
+ − 944
subsubsection {* Type @{typ "'a list"} is finitely supported *}
+ − 945
+ − 946
lemma supp_Nil:
+ − 947
shows "supp [] = {}"
+ − 948
by (simp add: supp_def)
+ − 949
+ − 950
lemma supp_Cons:
+ − 951
shows "supp (x # xs) = supp x \<union> supp xs"
+ − 952
by (simp add: supp_def Collect_imp_eq Collect_neg_eq)
+ − 953
+ − 954
lemma fresh_Nil:
+ − 955
shows "a \<sharp> []"
+ − 956
by (simp add: fresh_def supp_Nil)
+ − 957
+ − 958
lemma fresh_Cons:
+ − 959
shows "a \<sharp> (x # xs) \<longleftrightarrow> a \<sharp> x \<and> a \<sharp> xs"
+ − 960
by (simp add: fresh_def supp_Cons)
+ − 961
+ − 962
instance list :: (fs) fs
+ − 963
apply default
+ − 964
apply (induct_tac x)
+ − 965
apply (simp_all add: supp_Nil supp_Cons finite_supp)
+ − 966
done
+ − 967
+ − 968
section {* Support and freshness for applications *}
+ − 969
+ − 970
lemma supp_fun_app:
+ − 971
shows "supp (f x) \<subseteq> (supp f) \<union> (supp x)"
+ − 972
proof (rule subsetCI)
+ − 973
fix a::"atom"
+ − 974
assume a: "a \<in> supp (f x)"
+ − 975
assume b: "a \<notin> supp f \<union> supp x"
+ − 976
then have "finite {b. (a \<rightleftharpoons> b) \<bullet> f \<noteq> f}" "finite {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x}"
+ − 977
unfolding supp_def by auto
+ − 978
then have "finite ({b. (a \<rightleftharpoons> b) \<bullet> f \<noteq> f} \<union> {b. (a \<rightleftharpoons> b) \<bullet> x \<noteq> x})" by simp
+ − 979
moreover
+ − 980
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})"
+ − 981
by auto
+ − 982
ultimately have "finite {b. ((a \<rightleftharpoons> b) \<bullet> f) ((a \<rightleftharpoons> b) \<bullet> x) \<noteq> f x}"
+ − 983
using finite_subset by auto
+ − 984
then have "a \<notin> supp (f x)" unfolding supp_def
+ − 985
by (simp add: permute_fun_app_eq)
+ − 986
with a show "False" by simp
+ − 987
qed
+ − 988
+ − 989
lemma fresh_fun_app:
+ − 990
shows "a \<sharp> (f, x) \<Longrightarrow> a \<sharp> f x"
+ − 991
unfolding fresh_def
+ − 992
using supp_fun_app
+ − 993
by (auto simp add: supp_Pair)
+ − 994
+ − 995
lemma fresh_fun_eqvt_app:
+ − 996
assumes a: "\<forall>p. p \<bullet> f = f"
+ − 997
shows "a \<sharp> x \<Longrightarrow> a \<sharp> f x"
+ − 998
proof -
+ − 999
from a have b: "supp f = {}"
+ − 1000
unfolding supp_def by simp
+ − 1001
show "a \<sharp> x \<Longrightarrow> a \<sharp> f x"
+ − 1002
unfolding fresh_def
+ − 1003
using supp_fun_app b
+ − 1004
by auto
+ − 1005
qed
+ − 1006
+ − 1007
end