src/HOL/Nominal/Nominal.thy
author haftmann
Sat Sep 03 23:59:36 2011 +0200 (2011-09-03)
changeset 44689 f247fc952f31
parent 44683 daeb538c57bf
child 44696 4e99277c81f2
permissions -rw-r--r--
tuned specifications
     1 theory Nominal 
     2 imports Main "~~/src/HOL/Library/Infinite_Set"
     3 uses
     4   ("nominal_thmdecls.ML")
     5   ("nominal_atoms.ML")
     6   ("nominal_datatype.ML")
     7   ("nominal_induct.ML") 
     8   ("nominal_permeq.ML")
     9   ("nominal_fresh_fun.ML")
    10   ("nominal_primrec.ML")
    11   ("nominal_inductive.ML")
    12   ("nominal_inductive2.ML")
    13 begin
    14 
    15 section {* Permutations *}
    16 (*======================*)
    17 
    18 type_synonym 
    19   'x prm = "('x \<times> 'x) list"
    20 
    21 (* polymorphic constants for permutation and swapping *)
    22 consts 
    23   perm :: "'x prm \<Rightarrow> 'a \<Rightarrow> 'a"     (infixr "\<bullet>" 80)
    24   swap :: "('x \<times> 'x) \<Rightarrow> 'x \<Rightarrow> 'x"
    25 
    26 (* a "private" copy of the option type used in the abstraction function *)
    27 datatype 'a noption = nSome 'a | nNone
    28 
    29 (* a "private" copy of the product type used in the nominal induct method *)
    30 datatype ('a, 'b) nprod = nPair 'a 'b
    31 
    32 (* an auxiliary constant for the decision procedure involving *) 
    33 (* permutations (to avoid loops when using perm-compositions)  *)
    34 definition
    35   "perm_aux pi x = pi\<bullet>x"
    36 
    37 (* overloaded permutation operations *)
    38 overloading
    39   perm_fun    \<equiv> "perm :: 'x prm \<Rightarrow> ('a\<Rightarrow>'b) \<Rightarrow> ('a\<Rightarrow>'b)"   (unchecked)
    40   perm_bool   \<equiv> "perm :: 'x prm \<Rightarrow> bool \<Rightarrow> bool"           (unchecked)
    41   perm_unit   \<equiv> "perm :: 'x prm \<Rightarrow> unit \<Rightarrow> unit"           (unchecked)
    42   perm_prod   \<equiv> "perm :: 'x prm \<Rightarrow> ('a\<times>'b) \<Rightarrow> ('a\<times>'b)"    (unchecked)
    43   perm_list   \<equiv> "perm :: 'x prm \<Rightarrow> 'a list \<Rightarrow> 'a list"     (unchecked)
    44   perm_option \<equiv> "perm :: 'x prm \<Rightarrow> 'a option \<Rightarrow> 'a option" (unchecked)
    45   perm_char   \<equiv> "perm :: 'x prm \<Rightarrow> char \<Rightarrow> char"           (unchecked)
    46   perm_nat    \<equiv> "perm :: 'x prm \<Rightarrow> nat \<Rightarrow> nat"             (unchecked)
    47   perm_int    \<equiv> "perm :: 'x prm \<Rightarrow> int \<Rightarrow> int"             (unchecked)
    48 
    49   perm_noption \<equiv> "perm :: 'x prm \<Rightarrow> 'a noption \<Rightarrow> 'a noption"   (unchecked)
    50   perm_nprod   \<equiv> "perm :: 'x prm \<Rightarrow> ('a, 'b) nprod \<Rightarrow> ('a, 'b) nprod" (unchecked)
    51 begin
    52 
    53 definition
    54   perm_fun_def: "perm_fun pi (f::'a\<Rightarrow>'b) = (\<lambda>x. pi\<bullet>f((rev pi)\<bullet>x))"
    55 
    56 definition perm_bool :: "'x prm \<Rightarrow> bool \<Rightarrow> bool" where
    57   perm_bool_def: "perm_bool pi b = b"
    58 
    59 primrec perm_unit :: "'x prm \<Rightarrow> unit \<Rightarrow> unit"  where 
    60   "perm_unit pi () = ()"
    61   
    62 primrec perm_prod :: "'x prm \<Rightarrow> ('a\<times>'b) \<Rightarrow> ('a\<times>'b)" where
    63   "perm_prod pi (x,y) = (pi\<bullet>x,pi\<bullet>y)"
    64 
    65 primrec perm_list :: "'x prm \<Rightarrow> 'a list \<Rightarrow> 'a list" where
    66   nil_eqvt:  "perm_list pi []     = []"
    67 | cons_eqvt: "perm_list pi (x#xs) = (pi\<bullet>x)#(pi\<bullet>xs)"
    68 
    69 primrec perm_option :: "'x prm \<Rightarrow> 'a option \<Rightarrow> 'a option" where
    70   some_eqvt:  "perm_option pi (Some x) = Some (pi\<bullet>x)"
    71 | none_eqvt:  "perm_option pi None     = None"
    72 
    73 definition perm_char :: "'x prm \<Rightarrow> char \<Rightarrow> char" where
    74   perm_char_def: "perm_char pi c = c"
    75 
    76 definition perm_nat :: "'x prm \<Rightarrow> nat \<Rightarrow> nat" where
    77   perm_nat_def: "perm_nat pi i = i"
    78 
    79 definition perm_int :: "'x prm \<Rightarrow> int \<Rightarrow> int" where
    80   perm_int_def: "perm_int pi i = i"
    81 
    82 primrec perm_noption :: "'x prm \<Rightarrow> 'a noption \<Rightarrow> 'a noption" where
    83   nsome_eqvt:  "perm_noption pi (nSome x) = nSome (pi\<bullet>x)"
    84 | nnone_eqvt:  "perm_noption pi nNone     = nNone"
    85 
    86 primrec perm_nprod :: "'x prm \<Rightarrow> ('a, 'b) nprod \<Rightarrow> ('a, 'b) nprod" where
    87   "perm_nprod pi (nPair x y) = nPair (pi\<bullet>x) (pi\<bullet>y)"
    88 
    89 end
    90 
    91 (* permutations on booleans *)
    92 lemmas perm_bool = perm_bool_def
    93 
    94 lemma true_eqvt [simp]:
    95   "pi \<bullet> True \<longleftrightarrow> True"
    96   by (simp add: perm_bool_def)
    97 
    98 lemma false_eqvt [simp]:
    99   "pi \<bullet> False \<longleftrightarrow> False"
   100   by (simp add: perm_bool_def)
   101 
   102 lemma perm_boolI:
   103   assumes a: "P"
   104   shows "pi\<bullet>P"
   105   using a by (simp add: perm_bool)
   106 
   107 lemma perm_boolE:
   108   assumes a: "pi\<bullet>P"
   109   shows "P"
   110   using a by (simp add: perm_bool)
   111 
   112 lemma if_eqvt:
   113   fixes pi::"'a prm"
   114   shows "pi\<bullet>(if b then c1 else c2) = (if (pi\<bullet>b) then (pi\<bullet>c1) else (pi\<bullet>c2))"
   115   by (simp add: perm_fun_def)
   116 
   117 lemma imp_eqvt:
   118   shows "pi\<bullet>(A\<longrightarrow>B) = ((pi\<bullet>A)\<longrightarrow>(pi\<bullet>B))"
   119   by (simp add: perm_bool)
   120 
   121 lemma conj_eqvt:
   122   shows "pi\<bullet>(A\<and>B) = ((pi\<bullet>A)\<and>(pi\<bullet>B))"
   123   by (simp add: perm_bool)
   124 
   125 lemma disj_eqvt:
   126   shows "pi\<bullet>(A\<or>B) = ((pi\<bullet>A)\<or>(pi\<bullet>B))"
   127   by (simp add: perm_bool)
   128 
   129 lemma neg_eqvt:
   130   shows "pi\<bullet>(\<not> A) = (\<not> (pi\<bullet>A))"
   131   by (simp add: perm_bool)
   132 
   133 (* permutation on sets *)
   134 lemma empty_eqvt:
   135   shows "pi\<bullet>{} = {}"
   136   by (simp add: perm_fun_def perm_bool empty_iff [unfolded mem_def] fun_eq_iff)
   137 
   138 lemma union_eqvt:
   139   shows "(pi\<bullet>(X\<union>Y)) = (pi\<bullet>X) \<union> (pi\<bullet>Y)"
   140   by (simp add: perm_fun_def perm_bool Un_iff [unfolded mem_def] fun_eq_iff)
   141 
   142 (* permutations on products *)
   143 lemma fst_eqvt:
   144   "pi\<bullet>(fst x) = fst (pi\<bullet>x)"
   145  by (cases x) simp
   146 
   147 lemma snd_eqvt:
   148   "pi\<bullet>(snd x) = snd (pi\<bullet>x)"
   149  by (cases x) simp
   150 
   151 (* permutation on lists *)
   152 lemma append_eqvt:
   153   fixes pi :: "'x prm"
   154   and   l1 :: "'a list"
   155   and   l2 :: "'a list"
   156   shows "pi\<bullet>(l1@l2) = (pi\<bullet>l1)@(pi\<bullet>l2)"
   157   by (induct l1) auto
   158 
   159 lemma rev_eqvt:
   160   fixes pi :: "'x prm"
   161   and   l  :: "'a list"
   162   shows "pi\<bullet>(rev l) = rev (pi\<bullet>l)"
   163   by (induct l) (simp_all add: append_eqvt)
   164 
   165 (* permutation on characters and strings *)
   166 lemma perm_string:
   167   fixes s::"string"
   168   shows "pi\<bullet>s = s"
   169   by (induct s)(auto simp add: perm_char_def)
   170 
   171 
   172 section {* permutation equality *}
   173 (*==============================*)
   174 
   175 definition prm_eq :: "'x prm \<Rightarrow> 'x prm \<Rightarrow> bool" (" _ \<triangleq> _ " [80,80] 80) where
   176   "pi1 \<triangleq> pi2 \<longleftrightarrow> (\<forall>a::'x. pi1\<bullet>a = pi2\<bullet>a)"
   177 
   178 section {* Support, Freshness and Supports*}
   179 (*========================================*)
   180 definition supp :: "'a \<Rightarrow> ('x set)" where  
   181    "supp x = {a . (infinite {b . [(a,b)]\<bullet>x \<noteq> x})}"
   182 
   183 definition fresh :: "'x \<Rightarrow> 'a \<Rightarrow> bool" ("_ \<sharp> _" [80,80] 80) where
   184    "a \<sharp> x \<longleftrightarrow> a \<notin> supp x"
   185 
   186 definition supports :: "'x set \<Rightarrow> 'a \<Rightarrow> bool" (infixl "supports" 80) where
   187    "S supports x \<longleftrightarrow> (\<forall>a b. (a\<notin>S \<and> b\<notin>S \<longrightarrow> [(a,b)]\<bullet>x=x))"
   188 
   189 (* lemmas about supp *)
   190 lemma supp_fresh_iff: 
   191   fixes x :: "'a"
   192   shows "(supp x) = {a::'x. \<not>a\<sharp>x}"
   193   by (simp add: fresh_def)
   194 
   195 
   196 lemma supp_unit:
   197   shows "supp () = {}"
   198   by (simp add: supp_def)
   199 
   200 lemma supp_set_empty:
   201   shows "supp {} = {}"
   202   by (force simp add: supp_def empty_eqvt)
   203 
   204 lemma supp_prod: 
   205   fixes x :: "'a"
   206   and   y :: "'b"
   207   shows "(supp (x,y)) = (supp x)\<union>(supp y)"
   208   by  (force simp add: supp_def Collect_imp_eq Collect_neg_eq)
   209 
   210 lemma supp_nprod: 
   211   fixes x :: "'a"
   212   and   y :: "'b"
   213   shows "(supp (nPair x y)) = (supp x)\<union>(supp y)"
   214   by  (force simp add: supp_def Collect_imp_eq Collect_neg_eq)
   215 
   216 lemma supp_list_nil:
   217   shows "supp [] = {}"
   218 apply(simp add: supp_def)
   219 done
   220 
   221 lemma supp_list_cons:
   222   fixes x  :: "'a"
   223   and   xs :: "'a list"
   224   shows "supp (x#xs) = (supp x)\<union>(supp xs)"
   225   by (auto simp add: supp_def Collect_imp_eq Collect_neg_eq)
   226 
   227 lemma supp_list_append:
   228   fixes xs :: "'a list"
   229   and   ys :: "'a list"
   230   shows "supp (xs@ys) = (supp xs)\<union>(supp ys)"
   231   by (induct xs) (auto simp add: supp_list_nil supp_list_cons)
   232 
   233 lemma supp_list_rev:
   234   fixes xs :: "'a list"
   235   shows "supp (rev xs) = (supp xs)"
   236   by (induct xs, auto simp add: supp_list_append supp_list_cons supp_list_nil)
   237 
   238 lemma supp_bool:
   239   fixes x  :: "bool"
   240   shows "supp x = {}"
   241   by (cases "x") (simp_all add: supp_def)
   242 
   243 lemma supp_some:
   244   fixes x :: "'a"
   245   shows "supp (Some x) = (supp x)"
   246   by (simp add: supp_def)
   247 
   248 lemma supp_none:
   249   fixes x :: "'a"
   250   shows "supp (None) = {}"
   251   by (simp add: supp_def)
   252 
   253 lemma supp_int:
   254   fixes i::"int"
   255   shows "supp (i) = {}"
   256   by (simp add: supp_def perm_int_def)
   257 
   258 lemma supp_nat:
   259   fixes n::"nat"
   260   shows "(supp n) = {}"
   261   by (simp add: supp_def perm_nat_def)
   262 
   263 lemma supp_char:
   264   fixes c::"char"
   265   shows "(supp c) = {}"
   266   by (simp add: supp_def perm_char_def)
   267   
   268 lemma supp_string:
   269   fixes s::"string"
   270   shows "(supp s) = {}"
   271   by (simp add: supp_def perm_string)
   272 
   273 (* lemmas about freshness *)
   274 lemma fresh_set_empty:
   275   shows "a\<sharp>{}"
   276   by (simp add: fresh_def supp_set_empty)
   277 
   278 lemma fresh_unit:
   279   shows "a\<sharp>()"
   280   by (simp add: fresh_def supp_unit)
   281 
   282 lemma fresh_prod:
   283   fixes a :: "'x"
   284   and   x :: "'a"
   285   and   y :: "'b"
   286   shows "a\<sharp>(x,y) = (a\<sharp>x \<and> a\<sharp>y)"
   287   by (simp add: fresh_def supp_prod)
   288 
   289 lemma fresh_list_nil:
   290   fixes a :: "'x"
   291   shows "a\<sharp>[]"
   292   by (simp add: fresh_def supp_list_nil) 
   293 
   294 lemma fresh_list_cons:
   295   fixes a :: "'x"
   296   and   x :: "'a"
   297   and   xs :: "'a list"
   298   shows "a\<sharp>(x#xs) = (a\<sharp>x \<and> a\<sharp>xs)"
   299   by (simp add: fresh_def supp_list_cons)
   300 
   301 lemma fresh_list_append:
   302   fixes a :: "'x"
   303   and   xs :: "'a list"
   304   and   ys :: "'a list"
   305   shows "a\<sharp>(xs@ys) = (a\<sharp>xs \<and> a\<sharp>ys)"
   306   by (simp add: fresh_def supp_list_append)
   307 
   308 lemma fresh_list_rev:
   309   fixes a :: "'x"
   310   and   xs :: "'a list"
   311   shows "a\<sharp>(rev xs) = a\<sharp>xs"
   312   by (simp add: fresh_def supp_list_rev)
   313 
   314 lemma fresh_none:
   315   fixes a :: "'x"
   316   shows "a\<sharp>None"
   317   by (simp add: fresh_def supp_none)
   318 
   319 lemma fresh_some:
   320   fixes a :: "'x"
   321   and   x :: "'a"
   322   shows "a\<sharp>(Some x) = a\<sharp>x"
   323   by (simp add: fresh_def supp_some)
   324 
   325 lemma fresh_int:
   326   fixes a :: "'x"
   327   and   i :: "int"
   328   shows "a\<sharp>i"
   329   by (simp add: fresh_def supp_int)
   330 
   331 lemma fresh_nat:
   332   fixes a :: "'x"
   333   and   n :: "nat"
   334   shows "a\<sharp>n"
   335   by (simp add: fresh_def supp_nat)
   336 
   337 lemma fresh_char:
   338   fixes a :: "'x"
   339   and   c :: "char"
   340   shows "a\<sharp>c"
   341   by (simp add: fresh_def supp_char)
   342 
   343 lemma fresh_string:
   344   fixes a :: "'x"
   345   and   s :: "string"
   346   shows "a\<sharp>s"
   347   by (simp add: fresh_def supp_string)
   348 
   349 lemma fresh_bool:
   350   fixes a :: "'x"
   351   and   b :: "bool"
   352   shows "a\<sharp>b"
   353   by (simp add: fresh_def supp_bool)
   354 
   355 text {* Normalization of freshness results; cf.\ @{text nominal_induct} *}
   356 lemma fresh_unit_elim: 
   357   shows "(a\<sharp>() \<Longrightarrow> PROP C) \<equiv> PROP C"
   358   by (simp add: fresh_def supp_unit)
   359 
   360 lemma fresh_prod_elim: 
   361   shows "(a\<sharp>(x,y) \<Longrightarrow> PROP C) \<equiv> (a\<sharp>x \<Longrightarrow> a\<sharp>y \<Longrightarrow> PROP C)"
   362   by rule (simp_all add: fresh_prod)
   363 
   364 (* this rule needs to be added before the fresh_prodD is *)
   365 (* added to the simplifier with mksimps                  *) 
   366 lemma [simp]:
   367   shows "a\<sharp>x1 \<Longrightarrow> a\<sharp>x2 \<Longrightarrow> a\<sharp>(x1,x2)"
   368   by (simp add: fresh_prod)
   369 
   370 lemma fresh_prodD:
   371   shows "a\<sharp>(x,y) \<Longrightarrow> a\<sharp>x"
   372   and   "a\<sharp>(x,y) \<Longrightarrow> a\<sharp>y"
   373   by (simp_all add: fresh_prod)
   374 
   375 ML {*
   376   val mksimps_pairs = (@{const_name Nominal.fresh}, @{thms fresh_prodD}) :: mksimps_pairs;
   377 *}
   378 declaration {* fn _ =>
   379   Simplifier.map_ss (fn ss => ss setmksimps (mksimps mksimps_pairs))
   380 *}
   381 
   382 section {* Abstract Properties for Permutations and  Atoms *}
   383 (*=========================================================*)
   384 
   385 (* properties for being a permutation type *)
   386 definition
   387   "pt TYPE('a) TYPE('x) \<equiv> 
   388      (\<forall>(x::'a). ([]::'x prm)\<bullet>x = x) \<and> 
   389      (\<forall>(pi1::'x prm) (pi2::'x prm) (x::'a). (pi1@pi2)\<bullet>x = pi1\<bullet>(pi2\<bullet>x)) \<and> 
   390      (\<forall>(pi1::'x prm) (pi2::'x prm) (x::'a). pi1 \<triangleq> pi2 \<longrightarrow> pi1\<bullet>x = pi2\<bullet>x)"
   391 
   392 (* properties for being an atom type *)
   393 definition
   394   "at TYPE('x) \<equiv> 
   395      (\<forall>(x::'x). ([]::'x prm)\<bullet>x = x) \<and>
   396      (\<forall>(a::'x) (b::'x) (pi::'x prm) (x::'x). ((a,b)#(pi::'x prm))\<bullet>x = swap (a,b) (pi\<bullet>x)) \<and> 
   397      (\<forall>(a::'x) (b::'x) (c::'x). swap (a,b) c = (if a=c then b else (if b=c then a else c))) \<and> 
   398      (infinite (UNIV::'x set))"
   399 
   400 (* property of two atom-types being disjoint *)
   401 definition
   402   "disjoint TYPE('x) TYPE('y) \<equiv> 
   403        (\<forall>(pi::'x prm)(x::'y). pi\<bullet>x = x) \<and> 
   404        (\<forall>(pi::'y prm)(x::'x). pi\<bullet>x = x)"
   405 
   406 (* composition property of two permutation on a type 'a *)
   407 definition
   408   "cp TYPE ('a) TYPE('x) TYPE('y) \<equiv> 
   409       (\<forall>(pi2::'y prm) (pi1::'x prm) (x::'a) . pi1\<bullet>(pi2\<bullet>x) = (pi1\<bullet>pi2)\<bullet>(pi1\<bullet>x))" 
   410 
   411 (* property of having finite support *)
   412 definition
   413   "fs TYPE('a) TYPE('x) \<equiv> \<forall>(x::'a). finite ((supp x)::'x set)"
   414 
   415 section {* Lemmas about the atom-type properties*}
   416 (*==============================================*)
   417 
   418 lemma at1: 
   419   fixes x::"'x"
   420   assumes a: "at TYPE('x)"
   421   shows "([]::'x prm)\<bullet>x = x"
   422   using a by (simp add: at_def)
   423 
   424 lemma at2: 
   425   fixes a ::"'x"
   426   and   b ::"'x"
   427   and   x ::"'x"
   428   and   pi::"'x prm"
   429   assumes a: "at TYPE('x)"
   430   shows "((a,b)#pi)\<bullet>x = swap (a,b) (pi\<bullet>x)"
   431   using a by (simp only: at_def)
   432 
   433 lemma at3: 
   434   fixes a ::"'x"
   435   and   b ::"'x"
   436   and   c ::"'x"
   437   assumes a: "at TYPE('x)"
   438   shows "swap (a,b) c = (if a=c then b else (if b=c then a else c))"
   439   using a by (simp only: at_def)
   440 
   441 (* rules to calculate simple permutations *)
   442 lemmas at_calc = at2 at1 at3
   443 
   444 lemma at_swap_simps:
   445   fixes a ::"'x"
   446   and   b ::"'x"
   447   assumes a: "at TYPE('x)"
   448   shows "[(a,b)]\<bullet>a = b"
   449   and   "[(a,b)]\<bullet>b = a"
   450   and   "\<lbrakk>a\<noteq>c; b\<noteq>c\<rbrakk> \<Longrightarrow> [(a,b)]\<bullet>c = c"
   451   using a by (simp_all add: at_calc)
   452 
   453 lemma at4: 
   454   assumes a: "at TYPE('x)"
   455   shows "infinite (UNIV::'x set)"
   456   using a by (simp add: at_def)
   457 
   458 lemma at_append:
   459   fixes pi1 :: "'x prm"
   460   and   pi2 :: "'x prm"
   461   and   c   :: "'x"
   462   assumes at: "at TYPE('x)" 
   463   shows "(pi1@pi2)\<bullet>c = pi1\<bullet>(pi2\<bullet>c)"
   464 proof (induct pi1)
   465   case Nil show ?case by (simp add: at1[OF at])
   466 next
   467   case (Cons x xs)
   468   have "(xs@pi2)\<bullet>c  =  xs\<bullet>(pi2\<bullet>c)" by fact
   469   also have "(x#xs)@pi2 = x#(xs@pi2)" by simp
   470   ultimately show ?case by (cases "x", simp add:  at2[OF at])
   471 qed
   472  
   473 lemma at_swap:
   474   fixes a :: "'x"
   475   and   b :: "'x"
   476   and   c :: "'x"
   477   assumes at: "at TYPE('x)" 
   478   shows "swap (a,b) (swap (a,b) c) = c"
   479   by (auto simp add: at3[OF at])
   480 
   481 lemma at_rev_pi:
   482   fixes pi :: "'x prm"
   483   and   c  :: "'x"
   484   assumes at: "at TYPE('x)"
   485   shows "(rev pi)\<bullet>(pi\<bullet>c) = c"
   486 proof(induct pi)
   487   case Nil show ?case by (simp add: at1[OF at])
   488 next
   489   case (Cons x xs) thus ?case 
   490     by (cases "x", simp add: at2[OF at] at_append[OF at] at1[OF at] at_swap[OF at])
   491 qed
   492 
   493 lemma at_pi_rev:
   494   fixes pi :: "'x prm"
   495   and   x  :: "'x"
   496   assumes at: "at TYPE('x)"
   497   shows "pi\<bullet>((rev pi)\<bullet>x) = x"
   498   by (rule at_rev_pi[OF at, of "rev pi" _,simplified])
   499 
   500 lemma at_bij1: 
   501   fixes pi :: "'x prm"
   502   and   x  :: "'x"
   503   and   y  :: "'x"
   504   assumes at: "at TYPE('x)"
   505   and     a:  "(pi\<bullet>x) = y"
   506   shows   "x=(rev pi)\<bullet>y"
   507 proof -
   508   from a have "y=(pi\<bullet>x)" by (rule sym)
   509   thus ?thesis by (simp only: at_rev_pi[OF at])
   510 qed
   511 
   512 lemma at_bij2: 
   513   fixes pi :: "'x prm"
   514   and   x  :: "'x"
   515   and   y  :: "'x"
   516   assumes at: "at TYPE('x)"
   517   and     a:  "((rev pi)\<bullet>x) = y"
   518   shows   "x=pi\<bullet>y"
   519 proof -
   520   from a have "y=((rev pi)\<bullet>x)" by (rule sym)
   521   thus ?thesis by (simp only: at_pi_rev[OF at])
   522 qed
   523 
   524 lemma at_bij:
   525   fixes pi :: "'x prm"
   526   and   x  :: "'x"
   527   and   y  :: "'x"
   528   assumes at: "at TYPE('x)"
   529   shows "(pi\<bullet>x = pi\<bullet>y) = (x=y)"
   530 proof 
   531   assume "pi\<bullet>x = pi\<bullet>y" 
   532   hence  "x=(rev pi)\<bullet>(pi\<bullet>y)" by (rule at_bij1[OF at]) 
   533   thus "x=y" by (simp only: at_rev_pi[OF at])
   534 next
   535   assume "x=y"
   536   thus "pi\<bullet>x = pi\<bullet>y" by simp
   537 qed
   538 
   539 lemma at_supp:
   540   fixes x :: "'x"
   541   assumes at: "at TYPE('x)"
   542   shows "supp x = {x}"
   543 by(auto simp: supp_def Collect_conj_eq Collect_imp_eq at_calc[OF at] at4[OF at])
   544 
   545 lemma at_fresh:
   546   fixes a :: "'x"
   547   and   b :: "'x"
   548   assumes at: "at TYPE('x)"
   549   shows "(a\<sharp>b) = (a\<noteq>b)" 
   550   by (simp add: at_supp[OF at] fresh_def)
   551 
   552 lemma at_prm_fresh1:
   553   fixes c :: "'x"
   554   and   pi:: "'x prm"
   555   assumes at: "at TYPE('x)"
   556   and     a: "c\<sharp>pi" 
   557   shows "\<forall>(a,b)\<in>set pi. c\<noteq>a \<and> c\<noteq>b"
   558 using a by (induct pi) (auto simp add: fresh_list_cons fresh_prod at_fresh[OF at])
   559 
   560 lemma at_prm_fresh2:
   561   fixes c :: "'x"
   562   and   pi:: "'x prm"
   563   assumes at: "at TYPE('x)"
   564   and     a: "\<forall>(a,b)\<in>set pi. c\<noteq>a \<and> c\<noteq>b" 
   565   shows "pi\<bullet>c = c"
   566 using a  by(induct pi) (auto simp add: at1[OF at] at2[OF at] at3[OF at])
   567 
   568 lemma at_prm_fresh:
   569   fixes c :: "'x"
   570   and   pi:: "'x prm"
   571   assumes at: "at TYPE('x)"
   572   and     a: "c\<sharp>pi" 
   573   shows "pi\<bullet>c = c"
   574 by (rule at_prm_fresh2[OF at], rule at_prm_fresh1[OF at, OF a])
   575 
   576 lemma at_prm_rev_eq:
   577   fixes pi1 :: "'x prm"
   578   and   pi2 :: "'x prm"
   579   assumes at: "at TYPE('x)"
   580   shows "((rev pi1) \<triangleq> (rev pi2)) = (pi1 \<triangleq> pi2)"
   581 proof (simp add: prm_eq_def, auto)
   582   fix x
   583   assume "\<forall>x::'x. (rev pi1)\<bullet>x = (rev pi2)\<bullet>x"
   584   hence "(rev (pi1::'x prm))\<bullet>(pi2\<bullet>(x::'x)) = (rev (pi2::'x prm))\<bullet>(pi2\<bullet>x)" by simp
   585   hence "(rev (pi1::'x prm))\<bullet>((pi2::'x prm)\<bullet>x) = (x::'x)" by (simp add: at_rev_pi[OF at])
   586   hence "(pi2::'x prm)\<bullet>x = (pi1::'x prm)\<bullet>x" by (simp add: at_bij2[OF at])
   587   thus "pi1\<bullet>x  =  pi2\<bullet>x" by simp
   588 next
   589   fix x
   590   assume "\<forall>x::'x. pi1\<bullet>x = pi2\<bullet>x"
   591   hence "(pi1::'x prm)\<bullet>((rev pi2)\<bullet>x) = (pi2::'x prm)\<bullet>((rev pi2)\<bullet>(x::'x))" by simp
   592   hence "(pi1::'x prm)\<bullet>((rev pi2)\<bullet>(x::'x)) = x" by (simp add: at_pi_rev[OF at])
   593   hence "(rev pi2)\<bullet>x = (rev pi1)\<bullet>(x::'x)" by (simp add: at_bij1[OF at])
   594   thus "(rev pi1)\<bullet>x = (rev pi2)\<bullet>(x::'x)" by simp
   595 qed
   596 
   597 lemma at_prm_eq_append:
   598   fixes pi1 :: "'x prm"
   599   and   pi2 :: "'x prm"
   600   and   pi3 :: "'x prm"
   601   assumes at: "at TYPE('x)"
   602   and     a: "pi1 \<triangleq> pi2"
   603   shows "(pi3@pi1) \<triangleq> (pi3@pi2)"
   604 using a by (simp add: prm_eq_def at_append[OF at] at_bij[OF at])
   605 
   606 lemma at_prm_eq_append':
   607   fixes pi1 :: "'x prm"
   608   and   pi2 :: "'x prm"
   609   and   pi3 :: "'x prm"
   610   assumes at: "at TYPE('x)"
   611   and     a: "pi1 \<triangleq> pi2"
   612   shows "(pi1@pi3) \<triangleq> (pi2@pi3)"
   613 using a by (simp add: prm_eq_def at_append[OF at])
   614 
   615 lemma at_prm_eq_trans:
   616   fixes pi1 :: "'x prm"
   617   and   pi2 :: "'x prm"
   618   and   pi3 :: "'x prm"
   619   assumes a1: "pi1 \<triangleq> pi2"
   620   and     a2: "pi2 \<triangleq> pi3"  
   621   shows "pi1 \<triangleq> pi3"
   622 using a1 a2 by (auto simp add: prm_eq_def)
   623   
   624 lemma at_prm_eq_refl:
   625   fixes pi :: "'x prm"
   626   shows "pi \<triangleq> pi"
   627 by (simp add: prm_eq_def)
   628 
   629 lemma at_prm_rev_eq1:
   630   fixes pi1 :: "'x prm"
   631   and   pi2 :: "'x prm"
   632   assumes at: "at TYPE('x)"
   633   shows "pi1 \<triangleq> pi2 \<Longrightarrow> (rev pi1) \<triangleq> (rev pi2)"
   634   by (simp add: at_prm_rev_eq[OF at])
   635 
   636 lemma at_ds1:
   637   fixes a  :: "'x"
   638   assumes at: "at TYPE('x)"
   639   shows "[(a,a)] \<triangleq> []"
   640   by (force simp add: prm_eq_def at_calc[OF at])
   641 
   642 lemma at_ds2: 
   643   fixes pi :: "'x prm"
   644   and   a  :: "'x"
   645   and   b  :: "'x"
   646   assumes at: "at TYPE('x)"
   647   shows "([(a,b)]@pi) \<triangleq> (pi@[((rev pi)\<bullet>a,(rev pi)\<bullet>b)])"
   648   by (force simp add: prm_eq_def at_append[OF at] at_bij[OF at] at_pi_rev[OF at] 
   649       at_rev_pi[OF at] at_calc[OF at])
   650 
   651 lemma at_ds3: 
   652   fixes a  :: "'x"
   653   and   b  :: "'x"
   654   and   c  :: "'x"
   655   assumes at: "at TYPE('x)"
   656   and     a:  "distinct [a,b,c]"
   657   shows "[(a,c),(b,c),(a,c)] \<triangleq> [(a,b)]"
   658   using a by (force simp add: prm_eq_def at_calc[OF at])
   659 
   660 lemma at_ds4: 
   661   fixes a  :: "'x"
   662   and   b  :: "'x"
   663   and   pi  :: "'x prm"
   664   assumes at: "at TYPE('x)"
   665   shows "(pi@[(a,(rev pi)\<bullet>b)]) \<triangleq> ([(pi\<bullet>a,b)]@pi)"
   666   by (force simp add: prm_eq_def at_append[OF at] at_calc[OF at] at_bij[OF at] 
   667       at_pi_rev[OF at] at_rev_pi[OF at])
   668 
   669 lemma at_ds5: 
   670   fixes a  :: "'x"
   671   and   b  :: "'x"
   672   assumes at: "at TYPE('x)"
   673   shows "[(a,b)] \<triangleq> [(b,a)]"
   674   by (force simp add: prm_eq_def at_calc[OF at])
   675 
   676 lemma at_ds5': 
   677   fixes a  :: "'x"
   678   and   b  :: "'x"
   679   assumes at: "at TYPE('x)"
   680   shows "[(a,b),(b,a)] \<triangleq> []"
   681   by (force simp add: prm_eq_def at_calc[OF at])
   682 
   683 lemma at_ds6: 
   684   fixes a  :: "'x"
   685   and   b  :: "'x"
   686   and   c  :: "'x"
   687   assumes at: "at TYPE('x)"
   688   and     a: "distinct [a,b,c]"
   689   shows "[(a,c),(a,b)] \<triangleq> [(b,c),(a,c)]"
   690   using a by (force simp add: prm_eq_def at_calc[OF at])
   691 
   692 lemma at_ds7:
   693   fixes pi :: "'x prm"
   694   assumes at: "at TYPE('x)"
   695   shows "((rev pi)@pi) \<triangleq> []"
   696   by (simp add: prm_eq_def at1[OF at] at_append[OF at] at_rev_pi[OF at])
   697 
   698 lemma at_ds8_aux:
   699   fixes pi :: "'x prm"
   700   and   a  :: "'x"
   701   and   b  :: "'x"
   702   and   c  :: "'x"
   703   assumes at: "at TYPE('x)"
   704   shows "pi\<bullet>(swap (a,b) c) = swap (pi\<bullet>a,pi\<bullet>b) (pi\<bullet>c)"
   705   by (force simp add: at_calc[OF at] at_bij[OF at])
   706 
   707 lemma at_ds8: 
   708   fixes pi1 :: "'x prm"
   709   and   pi2 :: "'x prm"
   710   and   a  :: "'x"
   711   and   b  :: "'x"
   712   assumes at: "at TYPE('x)"
   713   shows "(pi1@pi2) \<triangleq> ((pi1\<bullet>pi2)@pi1)"
   714 apply(induct_tac pi2)
   715 apply(simp add: prm_eq_def)
   716 apply(auto simp add: prm_eq_def)
   717 apply(simp add: at2[OF at])
   718 apply(drule_tac x="aa" in spec)
   719 apply(drule sym)
   720 apply(simp)
   721 apply(simp add: at_append[OF at])
   722 apply(simp add: at2[OF at])
   723 apply(simp add: at_ds8_aux[OF at])
   724 done
   725 
   726 lemma at_ds9: 
   727   fixes pi1 :: "'x prm"
   728   and   pi2 :: "'x prm"
   729   and   a  :: "'x"
   730   and   b  :: "'x"
   731   assumes at: "at TYPE('x)"
   732   shows " ((rev pi2)@(rev pi1)) \<triangleq> ((rev pi1)@(rev (pi1\<bullet>pi2)))"
   733 apply(induct_tac pi2)
   734 apply(simp add: prm_eq_def)
   735 apply(auto simp add: prm_eq_def)
   736 apply(simp add: at_append[OF at])
   737 apply(simp add: at2[OF at] at1[OF at])
   738 apply(drule_tac x="swap(pi1\<bullet>a,pi1\<bullet>b) aa" in spec)
   739 apply(drule sym)
   740 apply(simp)
   741 apply(simp add: at_ds8_aux[OF at])
   742 apply(simp add: at_rev_pi[OF at])
   743 done
   744 
   745 lemma at_ds10:
   746   fixes pi :: "'x prm"
   747   and   a  :: "'x"
   748   and   b  :: "'x"
   749   assumes at: "at TYPE('x)"
   750   and     a:  "b\<sharp>(rev pi)"
   751   shows "([(pi\<bullet>a,b)]@pi) \<triangleq> (pi@[(a,b)])"
   752 using a
   753 apply -
   754 apply(rule at_prm_eq_trans)
   755 apply(rule at_ds2[OF at])
   756 apply(simp add: at_prm_fresh[OF at] at_rev_pi[OF at])
   757 apply(rule at_prm_eq_refl)
   758 done
   759 
   760 --"there always exists an atom that is not being in a finite set"
   761 lemma ex_in_inf:
   762   fixes   A::"'x set"
   763   assumes at: "at TYPE('x)"
   764   and     fs: "finite A"
   765   obtains c::"'x" where "c\<notin>A"
   766 proof -
   767   from  fs at4[OF at] have "infinite ((UNIV::'x set) - A)" 
   768     by (simp add: Diff_infinite_finite)
   769   hence "((UNIV::'x set) - A) \<noteq> ({}::'x set)" by (force simp only:)
   770   then obtain c::"'x" where "c\<in>((UNIV::'x set) - A)" by force
   771   then have "c\<notin>A" by simp
   772   then show ?thesis ..
   773 qed
   774 
   775 text {* there always exists a fresh name for an object with finite support *}
   776 lemma at_exists_fresh': 
   777   fixes  x :: "'a"
   778   assumes at: "at TYPE('x)"
   779   and     fs: "finite ((supp x)::'x set)"
   780   shows "\<exists>c::'x. c\<sharp>x"
   781   by (auto simp add: fresh_def intro: ex_in_inf[OF at, OF fs])
   782 
   783 lemma at_exists_fresh: 
   784   fixes  x :: "'a"
   785   assumes at: "at TYPE('x)"
   786   and     fs: "finite ((supp x)::'x set)"
   787   obtains c::"'x" where  "c\<sharp>x"
   788   by (auto intro: ex_in_inf[OF at, OF fs] simp add: fresh_def)
   789 
   790 lemma at_finite_select: 
   791   fixes S::"'a set"
   792   assumes a: "at TYPE('a)"
   793   and     b: "finite S" 
   794   shows "\<exists>x. x \<notin> S" 
   795   using a b
   796   apply(drule_tac S="UNIV::'a set" in Diff_infinite_finite)
   797   apply(simp add: at_def)
   798   apply(subgoal_tac "UNIV - S \<noteq> {}")
   799   apply(simp only: ex_in_conv [symmetric])
   800   apply(blast)
   801   apply(rule notI)
   802   apply(simp)
   803   done
   804 
   805 lemma at_different:
   806   assumes at: "at TYPE('x)"
   807   shows "\<exists>(b::'x). a\<noteq>b"
   808 proof -
   809   have "infinite (UNIV::'x set)" by (rule at4[OF at])
   810   hence inf2: "infinite (UNIV-{a})" by (rule infinite_remove)
   811   have "(UNIV-{a}) \<noteq> ({}::'x set)" 
   812   proof (rule_tac ccontr, drule_tac notnotD)
   813     assume "UNIV-{a} = ({}::'x set)"
   814     with inf2 have "infinite ({}::'x set)" by simp
   815     then show "False" by auto
   816   qed
   817   hence "\<exists>(b::'x). b\<in>(UNIV-{a})" by blast
   818   then obtain b::"'x" where mem2: "b\<in>(UNIV-{a})" by blast
   819   from mem2 have "a\<noteq>b" by blast
   820   then show "\<exists>(b::'x). a\<noteq>b" by blast
   821 qed
   822 
   823 --"the at-props imply the pt-props"
   824 lemma at_pt_inst:
   825   assumes at: "at TYPE('x)"
   826   shows "pt TYPE('x) TYPE('x)"
   827 apply(auto simp only: pt_def)
   828 apply(simp only: at1[OF at])
   829 apply(simp only: at_append[OF at]) 
   830 apply(simp only: prm_eq_def)
   831 done
   832 
   833 section {* finite support properties *}
   834 (*===================================*)
   835 
   836 lemma fs1:
   837   fixes x :: "'a"
   838   assumes a: "fs TYPE('a) TYPE('x)"
   839   shows "finite ((supp x)::'x set)"
   840   using a by (simp add: fs_def)
   841 
   842 lemma fs_at_inst:
   843   fixes a :: "'x"
   844   assumes at: "at TYPE('x)"
   845   shows "fs TYPE('x) TYPE('x)"
   846 apply(simp add: fs_def) 
   847 apply(simp add: at_supp[OF at])
   848 done
   849 
   850 lemma fs_unit_inst:
   851   shows "fs TYPE(unit) TYPE('x)"
   852 apply(simp add: fs_def)
   853 apply(simp add: supp_unit)
   854 done
   855 
   856 lemma fs_prod_inst:
   857   assumes fsa: "fs TYPE('a) TYPE('x)"
   858   and     fsb: "fs TYPE('b) TYPE('x)"
   859   shows "fs TYPE('a\<times>'b) TYPE('x)"
   860 apply(unfold fs_def)
   861 apply(auto simp add: supp_prod)
   862 apply(rule fs1[OF fsa])
   863 apply(rule fs1[OF fsb])
   864 done
   865 
   866 lemma fs_nprod_inst:
   867   assumes fsa: "fs TYPE('a) TYPE('x)"
   868   and     fsb: "fs TYPE('b) TYPE('x)"
   869   shows "fs TYPE(('a,'b) nprod) TYPE('x)"
   870 apply(unfold fs_def, rule allI)
   871 apply(case_tac x)
   872 apply(auto simp add: supp_nprod)
   873 apply(rule fs1[OF fsa])
   874 apply(rule fs1[OF fsb])
   875 done
   876 
   877 lemma fs_list_inst:
   878   assumes fs: "fs TYPE('a) TYPE('x)"
   879   shows "fs TYPE('a list) TYPE('x)"
   880 apply(simp add: fs_def, rule allI)
   881 apply(induct_tac x)
   882 apply(simp add: supp_list_nil)
   883 apply(simp add: supp_list_cons)
   884 apply(rule fs1[OF fs])
   885 done
   886 
   887 lemma fs_option_inst:
   888   assumes fs: "fs TYPE('a) TYPE('x)"
   889   shows "fs TYPE('a option) TYPE('x)"
   890 apply(simp add: fs_def, rule allI)
   891 apply(case_tac x)
   892 apply(simp add: supp_none)
   893 apply(simp add: supp_some)
   894 apply(rule fs1[OF fs])
   895 done
   896 
   897 section {* Lemmas about the permutation properties *}
   898 (*=================================================*)
   899 
   900 lemma pt1:
   901   fixes x::"'a"
   902   assumes a: "pt TYPE('a) TYPE('x)"
   903   shows "([]::'x prm)\<bullet>x = x"
   904   using a by (simp add: pt_def)
   905 
   906 lemma pt2: 
   907   fixes pi1::"'x prm"
   908   and   pi2::"'x prm"
   909   and   x  ::"'a"
   910   assumes a: "pt TYPE('a) TYPE('x)"
   911   shows "(pi1@pi2)\<bullet>x = pi1\<bullet>(pi2\<bullet>x)"
   912   using a by (simp add: pt_def)
   913 
   914 lemma pt3:
   915   fixes pi1::"'x prm"
   916   and   pi2::"'x prm"
   917   and   x  ::"'a"
   918   assumes a: "pt TYPE('a) TYPE('x)"
   919   shows "pi1 \<triangleq> pi2 \<Longrightarrow> pi1\<bullet>x = pi2\<bullet>x"
   920   using a by (simp add: pt_def)
   921 
   922 lemma pt3_rev:
   923   fixes pi1::"'x prm"
   924   and   pi2::"'x prm"
   925   and   x  ::"'a"
   926   assumes pt: "pt TYPE('a) TYPE('x)"
   927   and     at: "at TYPE('x)"
   928   shows "pi1 \<triangleq> pi2 \<Longrightarrow> (rev pi1)\<bullet>x = (rev pi2)\<bullet>x"
   929   by (rule pt3[OF pt], simp add: at_prm_rev_eq[OF at])
   930 
   931 section {* composition properties *}
   932 (* ============================== *)
   933 lemma cp1:
   934   fixes pi1::"'x prm"
   935   and   pi2::"'y prm"
   936   and   x  ::"'a"
   937   assumes cp: "cp TYPE ('a) TYPE('x) TYPE('y)"
   938   shows "pi1\<bullet>(pi2\<bullet>x) = (pi1\<bullet>pi2)\<bullet>(pi1\<bullet>x)"
   939   using cp by (simp add: cp_def)
   940 
   941 lemma cp_pt_inst:
   942   assumes pt: "pt TYPE('a) TYPE('x)"
   943   and     at: "at TYPE('x)"
   944   shows "cp TYPE('a) TYPE('x) TYPE('x)"
   945 apply(auto simp add: cp_def pt2[OF pt,symmetric])
   946 apply(rule pt3[OF pt])
   947 apply(rule at_ds8[OF at])
   948 done
   949 
   950 section {* disjointness properties *}
   951 (*=================================*)
   952 lemma dj_perm_forget:
   953   fixes pi::"'y prm"
   954   and   x ::"'x"
   955   assumes dj: "disjoint TYPE('x) TYPE('y)"
   956   shows "pi\<bullet>x=x" 
   957   using dj by (simp_all add: disjoint_def)
   958 
   959 lemma dj_perm_set_forget:
   960   fixes pi::"'y prm"
   961   and   x ::"'x set"
   962   assumes dj: "disjoint TYPE('x) TYPE('y)"
   963   shows "(pi\<bullet>x)=x" 
   964   using dj by (simp_all add: perm_fun_def disjoint_def perm_bool)
   965 
   966 lemma dj_perm_perm_forget:
   967   fixes pi1::"'x prm"
   968   and   pi2::"'y prm"
   969   assumes dj: "disjoint TYPE('x) TYPE('y)"
   970   shows "pi2\<bullet>pi1=pi1"
   971   using dj by (induct pi1, auto simp add: disjoint_def)
   972 
   973 lemma dj_cp:
   974   fixes pi1::"'x prm"
   975   and   pi2::"'y prm"
   976   and   x  ::"'a"
   977   assumes cp: "cp TYPE ('a) TYPE('x) TYPE('y)"
   978   and     dj: "disjoint TYPE('y) TYPE('x)"
   979   shows "pi1\<bullet>(pi2\<bullet>x) = (pi2)\<bullet>(pi1\<bullet>x)"
   980   by (simp add: cp1[OF cp] dj_perm_perm_forget[OF dj])
   981 
   982 lemma dj_supp:
   983   fixes a::"'x"
   984   assumes dj: "disjoint TYPE('x) TYPE('y)"
   985   shows "(supp a) = ({}::'y set)"
   986 apply(simp add: supp_def dj_perm_forget[OF dj])
   987 done
   988 
   989 lemma at_fresh_ineq:
   990   fixes a :: "'x"
   991   and   b :: "'y"
   992   assumes dj: "disjoint TYPE('y) TYPE('x)"
   993   shows "a\<sharp>b" 
   994   by (simp add: fresh_def dj_supp[OF dj])
   995 
   996 section {* permutation type instances *}
   997 (* ===================================*)
   998 
   999 lemma pt_list_nil: 
  1000   fixes xs :: "'a list"
  1001   assumes pt: "pt TYPE('a) TYPE ('x)"
  1002   shows "([]::'x prm)\<bullet>xs = xs" 
  1003 apply(induct_tac xs)
  1004 apply(simp_all add: pt1[OF pt])
  1005 done
  1006 
  1007 lemma pt_list_append: 
  1008   fixes pi1 :: "'x prm"
  1009   and   pi2 :: "'x prm"
  1010   and   xs  :: "'a list"
  1011   assumes pt: "pt TYPE('a) TYPE ('x)"
  1012   shows "(pi1@pi2)\<bullet>xs = pi1\<bullet>(pi2\<bullet>xs)"
  1013 apply(induct_tac xs)
  1014 apply(simp_all add: pt2[OF pt])
  1015 done
  1016 
  1017 lemma pt_list_prm_eq: 
  1018   fixes pi1 :: "'x prm"
  1019   and   pi2 :: "'x prm"
  1020   and   xs  :: "'a list"
  1021   assumes pt: "pt TYPE('a) TYPE ('x)"
  1022   shows "pi1 \<triangleq> pi2  \<Longrightarrow> pi1\<bullet>xs = pi2\<bullet>xs"
  1023 apply(induct_tac xs)
  1024 apply(simp_all add: prm_eq_def pt3[OF pt])
  1025 done
  1026 
  1027 lemma pt_list_inst:
  1028   assumes pt: "pt TYPE('a) TYPE('x)"
  1029   shows  "pt TYPE('a list) TYPE('x)"
  1030 apply(auto simp only: pt_def)
  1031 apply(rule pt_list_nil[OF pt])
  1032 apply(rule pt_list_append[OF pt])
  1033 apply(rule pt_list_prm_eq[OF pt],assumption)
  1034 done
  1035 
  1036 lemma pt_unit_inst:
  1037   shows  "pt TYPE(unit) TYPE('x)"
  1038   by (simp add: pt_def)
  1039 
  1040 lemma pt_prod_inst:
  1041   assumes pta: "pt TYPE('a) TYPE('x)"
  1042   and     ptb: "pt TYPE('b) TYPE('x)"
  1043   shows  "pt TYPE('a \<times> 'b) TYPE('x)"
  1044   apply(auto simp add: pt_def)
  1045   apply(rule pt1[OF pta])
  1046   apply(rule pt1[OF ptb])
  1047   apply(rule pt2[OF pta])
  1048   apply(rule pt2[OF ptb])
  1049   apply(rule pt3[OF pta],assumption)
  1050   apply(rule pt3[OF ptb],assumption)
  1051   done
  1052 
  1053 lemma pt_nprod_inst:
  1054   assumes pta: "pt TYPE('a) TYPE('x)"
  1055   and     ptb: "pt TYPE('b) TYPE('x)"
  1056   shows  "pt TYPE(('a,'b) nprod) TYPE('x)"
  1057   apply(auto simp add: pt_def)
  1058   apply(case_tac x)
  1059   apply(simp add: pt1[OF pta] pt1[OF ptb])
  1060   apply(case_tac x)
  1061   apply(simp add: pt2[OF pta] pt2[OF ptb])
  1062   apply(case_tac x)
  1063   apply(simp add: pt3[OF pta] pt3[OF ptb])
  1064   done
  1065 
  1066 lemma pt_fun_inst:
  1067   assumes pta: "pt TYPE('a) TYPE('x)"
  1068   and     ptb: "pt TYPE('b) TYPE('x)"
  1069   and     at:  "at TYPE('x)"
  1070   shows  "pt TYPE('a\<Rightarrow>'b) TYPE('x)"
  1071 apply(auto simp only: pt_def)
  1072 apply(simp_all add: perm_fun_def)
  1073 apply(simp add: pt1[OF pta] pt1[OF ptb])
  1074 apply(simp add: pt2[OF pta] pt2[OF ptb])
  1075 apply(subgoal_tac "(rev pi1) \<triangleq> (rev pi2)")(*A*)
  1076 apply(simp add: pt3[OF pta] pt3[OF ptb])
  1077 (*A*)
  1078 apply(simp add: at_prm_rev_eq[OF at])
  1079 done
  1080 
  1081 lemma pt_option_inst:
  1082   assumes pta: "pt TYPE('a) TYPE('x)"
  1083   shows  "pt TYPE('a option) TYPE('x)"
  1084 apply(auto simp only: pt_def)
  1085 apply(case_tac "x")
  1086 apply(simp_all add: pt1[OF pta])
  1087 apply(case_tac "x")
  1088 apply(simp_all add: pt2[OF pta])
  1089 apply(case_tac "x")
  1090 apply(simp_all add: pt3[OF pta])
  1091 done
  1092 
  1093 lemma pt_noption_inst:
  1094   assumes pta: "pt TYPE('a) TYPE('x)"
  1095   shows  "pt TYPE('a noption) TYPE('x)"
  1096 apply(auto simp only: pt_def)
  1097 apply(case_tac "x")
  1098 apply(simp_all add: pt1[OF pta])
  1099 apply(case_tac "x")
  1100 apply(simp_all add: pt2[OF pta])
  1101 apply(case_tac "x")
  1102 apply(simp_all add: pt3[OF pta])
  1103 done
  1104 
  1105 lemma pt_bool_inst:
  1106   shows  "pt TYPE(bool) TYPE('x)"
  1107   by (simp add: pt_def perm_bool)
  1108 
  1109 section {* further lemmas for permutation types *}
  1110 (*==============================================*)
  1111 
  1112 lemma pt_rev_pi:
  1113   fixes pi :: "'x prm"
  1114   and   x  :: "'a"
  1115   assumes pt: "pt TYPE('a) TYPE('x)"
  1116   and     at: "at TYPE('x)"
  1117   shows "(rev pi)\<bullet>(pi\<bullet>x) = x"
  1118 proof -
  1119   have "((rev pi)@pi) \<triangleq> ([]::'x prm)" by (simp add: at_ds7[OF at])
  1120   hence "((rev pi)@pi)\<bullet>(x::'a) = ([]::'x prm)\<bullet>x" by (simp add: pt3[OF pt]) 
  1121   thus ?thesis by (simp add: pt1[OF pt] pt2[OF pt])
  1122 qed
  1123 
  1124 lemma pt_pi_rev:
  1125   fixes pi :: "'x prm"
  1126   and   x  :: "'a"
  1127   assumes pt: "pt TYPE('a) TYPE('x)"
  1128   and     at: "at TYPE('x)"
  1129   shows "pi\<bullet>((rev pi)\<bullet>x) = x"
  1130   by (simp add: pt_rev_pi[OF pt, OF at,of "rev pi" "x",simplified])
  1131 
  1132 lemma pt_bij1: 
  1133   fixes pi :: "'x prm"
  1134   and   x  :: "'a"
  1135   and   y  :: "'a"
  1136   assumes pt: "pt TYPE('a) TYPE('x)"
  1137   and     at: "at TYPE('x)"
  1138   and     a:  "(pi\<bullet>x) = y"
  1139   shows   "x=(rev pi)\<bullet>y"
  1140 proof -
  1141   from a have "y=(pi\<bullet>x)" by (rule sym)
  1142   thus ?thesis by (simp only: pt_rev_pi[OF pt, OF at])
  1143 qed
  1144 
  1145 lemma pt_bij2: 
  1146   fixes pi :: "'x prm"
  1147   and   x  :: "'a"
  1148   and   y  :: "'a"
  1149   assumes pt: "pt TYPE('a) TYPE('x)"
  1150   and     at: "at TYPE('x)"
  1151   and     a:  "x = (rev pi)\<bullet>y"
  1152   shows   "(pi\<bullet>x)=y"
  1153   using a by (simp add: pt_pi_rev[OF pt, OF at])
  1154 
  1155 lemma pt_bij:
  1156   fixes pi :: "'x prm"
  1157   and   x  :: "'a"
  1158   and   y  :: "'a"
  1159   assumes pt: "pt TYPE('a) TYPE('x)"
  1160   and     at: "at TYPE('x)"
  1161   shows "(pi\<bullet>x = pi\<bullet>y) = (x=y)"
  1162 proof 
  1163   assume "pi\<bullet>x = pi\<bullet>y" 
  1164   hence  "x=(rev pi)\<bullet>(pi\<bullet>y)" by (rule pt_bij1[OF pt, OF at]) 
  1165   thus "x=y" by (simp only: pt_rev_pi[OF pt, OF at])
  1166 next
  1167   assume "x=y"
  1168   thus "pi\<bullet>x = pi\<bullet>y" by simp
  1169 qed
  1170 
  1171 lemma pt_eq_eqvt:
  1172   fixes pi :: "'x prm"
  1173   and   x  :: "'a"
  1174   and   y  :: "'a"
  1175   assumes pt: "pt TYPE('a) TYPE('x)"
  1176   and     at: "at TYPE('x)"
  1177   shows "pi\<bullet>(x=y) = (pi\<bullet>x = pi\<bullet>y)"
  1178   using pt at
  1179   by (auto simp add: pt_bij perm_bool)
  1180 
  1181 lemma pt_bij3:
  1182   fixes pi :: "'x prm"
  1183   and   x  :: "'a"
  1184   and   y  :: "'a"
  1185   assumes a:  "x=y"
  1186   shows "(pi\<bullet>x = pi\<bullet>y)"
  1187   using a by simp 
  1188 
  1189 lemma pt_bij4:
  1190   fixes pi :: "'x prm"
  1191   and   x  :: "'a"
  1192   and   y  :: "'a"
  1193   assumes pt: "pt TYPE('a) TYPE('x)"
  1194   and     at: "at TYPE('x)"
  1195   and     a:  "pi\<bullet>x = pi\<bullet>y"
  1196   shows "x = y"
  1197   using a by (simp add: pt_bij[OF pt, OF at])
  1198 
  1199 lemma pt_swap_bij:
  1200   fixes a  :: "'x"
  1201   and   b  :: "'x"
  1202   and   x  :: "'a"
  1203   assumes pt: "pt TYPE('a) TYPE('x)"
  1204   and     at: "at TYPE('x)"
  1205   shows "[(a,b)]\<bullet>([(a,b)]\<bullet>x) = x"
  1206   by (rule pt_bij2[OF pt, OF at], simp)
  1207 
  1208 lemma pt_swap_bij':
  1209   fixes a  :: "'x"
  1210   and   b  :: "'x"
  1211   and   x  :: "'a"
  1212   assumes pt: "pt TYPE('a) TYPE('x)"
  1213   and     at: "at TYPE('x)"
  1214   shows "[(a,b)]\<bullet>([(b,a)]\<bullet>x) = x"
  1215 apply(simp add: pt2[OF pt,symmetric])
  1216 apply(rule trans)
  1217 apply(rule pt3[OF pt])
  1218 apply(rule at_ds5'[OF at])
  1219 apply(rule pt1[OF pt])
  1220 done
  1221 
  1222 lemma pt_swap_bij'':
  1223   fixes a  :: "'x"
  1224   and   x  :: "'a"
  1225   assumes pt: "pt TYPE('a) TYPE('x)"
  1226   and     at: "at TYPE('x)"
  1227   shows "[(a,a)]\<bullet>x = x"
  1228 apply(rule trans)
  1229 apply(rule pt3[OF pt])
  1230 apply(rule at_ds1[OF at])
  1231 apply(rule pt1[OF pt])
  1232 done
  1233 
  1234 lemma perm_set_eq:
  1235   assumes pt: "pt TYPE('a) TYPE('x)"
  1236   and at: "at TYPE('x)" 
  1237   shows "(pi::'x prm)\<bullet>(X::'a set) = {pi\<bullet>x | x. x\<in>X}"
  1238   apply (auto simp add: perm_fun_def perm_bool mem_def)
  1239   apply (rule_tac x="rev pi \<bullet> x" in exI)
  1240   apply (simp add: pt_pi_rev [OF pt at])
  1241   apply (simp add: pt_rev_pi [OF pt at])
  1242   done
  1243 
  1244 lemma pt_insert_eqvt:
  1245   fixes pi::"'x prm"
  1246   and   x::"'a"
  1247   assumes pt: "pt TYPE('a) TYPE('x)"
  1248   and at: "at TYPE('x)" 
  1249   shows "(pi\<bullet>(insert x X)) = insert (pi\<bullet>x) (pi\<bullet>X)"
  1250   by (auto simp add: perm_set_eq [OF pt at])
  1251 
  1252 lemma pt_set_eqvt:
  1253   fixes pi :: "'x prm"
  1254   and   xs :: "'a list"
  1255   assumes pt: "pt TYPE('a) TYPE('x)"
  1256   and at: "at TYPE('x)" 
  1257   shows "pi\<bullet>(set xs) = set (pi\<bullet>xs)"
  1258 by (induct xs) (auto simp add: empty_eqvt pt_insert_eqvt [OF pt at])
  1259 
  1260 lemma supp_singleton:
  1261   assumes pt: "pt TYPE('a) TYPE('x)"
  1262   and at: "at TYPE('x)" 
  1263   shows "(supp {x::'a} :: 'x set) = supp x"
  1264   by (force simp add: supp_def perm_set_eq [OF pt at])
  1265 
  1266 lemma fresh_singleton:
  1267   assumes pt: "pt TYPE('a) TYPE('x)"
  1268   and at: "at TYPE('x)" 
  1269   shows "(a::'x)\<sharp>{x::'a} = a\<sharp>x"
  1270   by (simp add: fresh_def supp_singleton [OF pt at])
  1271 
  1272 lemma pt_set_bij1:
  1273   fixes pi :: "'x prm"
  1274   and   x  :: "'a"
  1275   and   X  :: "'a set"
  1276   assumes pt: "pt TYPE('a) TYPE('x)"
  1277   and     at: "at TYPE('x)"
  1278   shows "((pi\<bullet>x)\<in>X) = (x\<in>((rev pi)\<bullet>X))"
  1279   by (force simp add: perm_set_eq [OF pt at] pt_rev_pi[OF pt, OF at] pt_pi_rev[OF pt, OF at])
  1280 
  1281 lemma pt_set_bij1a:
  1282   fixes pi :: "'x prm"
  1283   and   x  :: "'a"
  1284   and   X  :: "'a set"
  1285   assumes pt: "pt TYPE('a) TYPE('x)"
  1286   and     at: "at TYPE('x)"
  1287   shows "(x\<in>(pi\<bullet>X)) = (((rev pi)\<bullet>x)\<in>X)"
  1288   by (force simp add: perm_set_eq [OF pt at] pt_rev_pi[OF pt, OF at] pt_pi_rev[OF pt, OF at])
  1289 
  1290 lemma pt_set_bij:
  1291   fixes pi :: "'x prm"
  1292   and   x  :: "'a"
  1293   and   X  :: "'a set"
  1294   assumes pt: "pt TYPE('a) TYPE('x)"
  1295   and     at: "at TYPE('x)"
  1296   shows "((pi\<bullet>x)\<in>(pi\<bullet>X)) = (x\<in>X)"
  1297   by (simp add: perm_set_eq [OF pt at] pt_bij[OF pt, OF at])
  1298 
  1299 lemma pt_in_eqvt:
  1300   fixes pi :: "'x prm"
  1301   and   x  :: "'a"
  1302   and   X  :: "'a set"
  1303   assumes pt: "pt TYPE('a) TYPE('x)"
  1304   and     at: "at TYPE('x)"
  1305   shows "pi\<bullet>(x\<in>X)=((pi\<bullet>x)\<in>(pi\<bullet>X))"
  1306 using assms
  1307 by (auto simp add:  pt_set_bij perm_bool)
  1308 
  1309 lemma pt_set_bij2:
  1310   fixes pi :: "'x prm"
  1311   and   x  :: "'a"
  1312   and   X  :: "'a set"
  1313   assumes pt: "pt TYPE('a) TYPE('x)"
  1314   and     at: "at TYPE('x)"
  1315   and     a:  "x\<in>X"
  1316   shows "(pi\<bullet>x)\<in>(pi\<bullet>X)"
  1317   using a by (simp add: pt_set_bij[OF pt, OF at])
  1318 
  1319 lemma pt_set_bij2a:
  1320   fixes pi :: "'x prm"
  1321   and   x  :: "'a"
  1322   and   X  :: "'a set"
  1323   assumes pt: "pt TYPE('a) TYPE('x)"
  1324   and     at: "at TYPE('x)"
  1325   and     a:  "x\<in>((rev pi)\<bullet>X)"
  1326   shows "(pi\<bullet>x)\<in>X"
  1327   using a by (simp add: pt_set_bij1[OF pt, OF at])
  1328 
  1329 (* FIXME: is this lemma needed anywhere? *)
  1330 lemma pt_set_bij3:
  1331   fixes pi :: "'x prm"
  1332   and   x  :: "'a"
  1333   and   X  :: "'a set"
  1334   shows "pi\<bullet>(x\<in>X) = (x\<in>X)"
  1335 by (simp add: perm_bool)
  1336 
  1337 lemma pt_subseteq_eqvt:
  1338   fixes pi :: "'x prm"
  1339   and   Y  :: "'a set"
  1340   and   X  :: "'a set"
  1341   assumes pt: "pt TYPE('a) TYPE('x)"
  1342   and     at: "at TYPE('x)"
  1343   shows "(pi\<bullet>(X\<subseteq>Y)) = ((pi\<bullet>X)\<subseteq>(pi\<bullet>Y))"
  1344 by (auto simp add: perm_set_eq [OF pt at] perm_bool pt_bij[OF pt, OF at])
  1345 
  1346 lemma pt_set_diff_eqvt:
  1347   fixes X::"'a set"
  1348   and   Y::"'a set"
  1349   and   pi::"'x prm"
  1350   assumes pt: "pt TYPE('a) TYPE('x)"
  1351   and     at: "at TYPE('x)"
  1352   shows "pi\<bullet>(X - Y) = (pi\<bullet>X) - (pi\<bullet>Y)"
  1353   by (auto simp add: perm_set_eq [OF pt at] pt_bij[OF pt, OF at])
  1354 
  1355 lemma pt_Collect_eqvt:
  1356   fixes pi::"'x prm"
  1357   assumes pt: "pt TYPE('a) TYPE('x)"
  1358   and     at: "at TYPE('x)"
  1359   shows "pi\<bullet>{x::'a. P x} = {x. P ((rev pi)\<bullet>x)}"
  1360 apply(auto simp add: perm_set_eq [OF pt at] pt_rev_pi[OF pt, OF at])
  1361 apply(rule_tac x="(rev pi)\<bullet>x" in exI)
  1362 apply(simp add: pt_pi_rev[OF pt, OF at])
  1363 done
  1364 
  1365 -- "some helper lemmas for the pt_perm_supp_ineq lemma"
  1366 lemma Collect_permI: 
  1367   fixes pi :: "'x prm"
  1368   and   x  :: "'a"
  1369   assumes a: "\<forall>x. (P1 x = P2 x)" 
  1370   shows "{pi\<bullet>x| x. P1 x} = {pi\<bullet>x| x. P2 x}"
  1371   using a by force
  1372 
  1373 lemma Infinite_cong:
  1374   assumes a: "X = Y"
  1375   shows "infinite X = infinite Y"
  1376   using a by (simp)
  1377 
  1378 lemma pt_set_eq_ineq:
  1379   fixes pi :: "'y prm"
  1380   assumes pt: "pt TYPE('x) TYPE('y)"
  1381   and     at: "at TYPE('y)"
  1382   shows "{pi\<bullet>x| x::'x. P x} = {x::'x. P ((rev pi)\<bullet>x)}"
  1383   by (force simp only: pt_rev_pi[OF pt, OF at] pt_pi_rev[OF pt, OF at])
  1384 
  1385 lemma pt_inject_on_ineq:
  1386   fixes X  :: "'y set"
  1387   and   pi :: "'x prm"
  1388   assumes pt: "pt TYPE('y) TYPE('x)"
  1389   and     at: "at TYPE('x)"
  1390   shows "inj_on (perm pi) X"
  1391 proof (unfold inj_on_def, intro strip)
  1392   fix x::"'y" and y::"'y"
  1393   assume "pi\<bullet>x = pi\<bullet>y"
  1394   thus "x=y" by (simp add: pt_bij[OF pt, OF at])
  1395 qed
  1396 
  1397 lemma pt_set_finite_ineq: 
  1398   fixes X  :: "'x set"
  1399   and   pi :: "'y prm"
  1400   assumes pt: "pt TYPE('x) TYPE('y)"
  1401   and     at: "at TYPE('y)"
  1402   shows "finite (pi\<bullet>X) = finite X"
  1403 proof -
  1404   have image: "(pi\<bullet>X) = (perm pi ` X)" by (force simp only: perm_set_eq [OF pt at])
  1405   show ?thesis
  1406   proof (rule iffI)
  1407     assume "finite (pi\<bullet>X)"
  1408     hence "finite (perm pi ` X)" using image by (simp)
  1409     thus "finite X" using pt_inject_on_ineq[OF pt, OF at] by (rule finite_imageD)
  1410   next
  1411     assume "finite X"
  1412     hence "finite (perm pi ` X)" by (rule finite_imageI)
  1413     thus "finite (pi\<bullet>X)" using image by (simp)
  1414   qed
  1415 qed
  1416 
  1417 lemma pt_set_infinite_ineq: 
  1418   fixes X  :: "'x set"
  1419   and   pi :: "'y prm"
  1420   assumes pt: "pt TYPE('x) TYPE('y)"
  1421   and     at: "at TYPE('y)"
  1422   shows "infinite (pi\<bullet>X) = infinite X"
  1423 using pt at by (simp add: pt_set_finite_ineq)
  1424 
  1425 lemma pt_perm_supp_ineq:
  1426   fixes  pi  :: "'x prm"
  1427   and    x   :: "'a"
  1428   assumes pta: "pt TYPE('a) TYPE('x)"
  1429   and     ptb: "pt TYPE('y) TYPE('x)"
  1430   and     at:  "at TYPE('x)"
  1431   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  1432   shows "(pi\<bullet>((supp x)::'y set)) = supp (pi\<bullet>x)" (is "?LHS = ?RHS")
  1433 proof -
  1434   have "?LHS = {pi\<bullet>a | a. infinite {b. [(a,b)]\<bullet>x \<noteq> x}}" by (simp add: supp_def perm_set_eq [OF ptb at])
  1435   also have "\<dots> = {pi\<bullet>a | a. infinite {pi\<bullet>b | b. [(a,b)]\<bullet>x \<noteq> x}}" 
  1436   proof (rule Collect_permI, rule allI, rule iffI)
  1437     fix a
  1438     assume "infinite {b::'y. [(a,b)]\<bullet>x  \<noteq> x}"
  1439     hence "infinite (pi\<bullet>{b::'y. [(a,b)]\<bullet>x \<noteq> x})" by (simp add: pt_set_infinite_ineq[OF ptb, OF at])
  1440     thus "infinite {pi\<bullet>b |b::'y. [(a,b)]\<bullet>x  \<noteq> x}" by (simp add: perm_set_eq [OF ptb at])
  1441   next
  1442     fix a
  1443     assume "infinite {pi\<bullet>b |b::'y. [(a,b)]\<bullet>x \<noteq> x}"
  1444     hence "infinite (pi\<bullet>{b::'y. [(a,b)]\<bullet>x \<noteq> x})" by (simp add: perm_set_eq [OF ptb at])
  1445     thus "infinite {b::'y. [(a,b)]\<bullet>x  \<noteq> x}" 
  1446       by (simp add: pt_set_infinite_ineq[OF ptb, OF at])
  1447   qed
  1448   also have "\<dots> = {a. infinite {b::'y. [((rev pi)\<bullet>a,(rev pi)\<bullet>b)]\<bullet>x \<noteq> x}}" 
  1449     by (simp add: pt_set_eq_ineq[OF ptb, OF at])
  1450   also have "\<dots> = {a. infinite {b. pi\<bullet>([((rev pi)\<bullet>a,(rev pi)\<bullet>b)]\<bullet>x) \<noteq> (pi\<bullet>x)}}"
  1451     by (simp add: pt_bij[OF pta, OF at])
  1452   also have "\<dots> = {a. infinite {b. [(a,b)]\<bullet>(pi\<bullet>x) \<noteq> (pi\<bullet>x)}}"
  1453   proof (rule Collect_cong, rule Infinite_cong, rule Collect_cong)
  1454     fix a::"'y" and b::"'y"
  1455     have "pi\<bullet>(([((rev pi)\<bullet>a,(rev pi)\<bullet>b)])\<bullet>x) = [(a,b)]\<bullet>(pi\<bullet>x)"
  1456       by (simp add: cp1[OF cp] pt_pi_rev[OF ptb, OF at])
  1457     thus "(pi\<bullet>([((rev pi)\<bullet>a,(rev pi)\<bullet>b)]\<bullet>x) \<noteq>  pi\<bullet>x) = ([(a,b)]\<bullet>(pi\<bullet>x) \<noteq> pi\<bullet>x)" by simp
  1458   qed
  1459   finally show "?LHS = ?RHS" by (simp add: supp_def) 
  1460 qed
  1461 
  1462 lemma pt_perm_supp:
  1463   fixes  pi  :: "'x prm"
  1464   and    x   :: "'a"
  1465   assumes pt: "pt TYPE('a) TYPE('x)"
  1466   and     at: "at TYPE('x)"
  1467   shows "(pi\<bullet>((supp x)::'x set)) = supp (pi\<bullet>x)"
  1468 apply(rule pt_perm_supp_ineq)
  1469 apply(rule pt)
  1470 apply(rule at_pt_inst)
  1471 apply(rule at)+
  1472 apply(rule cp_pt_inst)
  1473 apply(rule pt)
  1474 apply(rule at)
  1475 done
  1476 
  1477 lemma pt_supp_finite_pi:
  1478   fixes  pi  :: "'x prm"
  1479   and    x   :: "'a"
  1480   assumes pt: "pt TYPE('a) TYPE('x)"
  1481   and     at: "at TYPE('x)"
  1482   and     f: "finite ((supp x)::'x set)"
  1483   shows "finite ((supp (pi\<bullet>x))::'x set)"
  1484 apply(simp add: pt_perm_supp[OF pt, OF at, symmetric])
  1485 apply(simp add: pt_set_finite_ineq[OF at_pt_inst[OF at], OF at])
  1486 apply(rule f)
  1487 done
  1488 
  1489 lemma pt_fresh_left_ineq:  
  1490   fixes  pi :: "'x prm"
  1491   and     x :: "'a"
  1492   and     a :: "'y"
  1493   assumes pta: "pt TYPE('a) TYPE('x)"
  1494   and     ptb: "pt TYPE('y) TYPE('x)"
  1495   and     at:  "at TYPE('x)"
  1496   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  1497   shows "a\<sharp>(pi\<bullet>x) = ((rev pi)\<bullet>a)\<sharp>x"
  1498 apply(simp add: fresh_def)
  1499 apply(simp add: pt_set_bij1[OF ptb, OF at])
  1500 apply(simp add: pt_perm_supp_ineq[OF pta, OF ptb, OF at, OF cp])
  1501 done
  1502 
  1503 lemma pt_fresh_right_ineq:  
  1504   fixes  pi :: "'x prm"
  1505   and     x :: "'a"
  1506   and     a :: "'y"
  1507   assumes pta: "pt TYPE('a) TYPE('x)"
  1508   and     ptb: "pt TYPE('y) TYPE('x)"
  1509   and     at:  "at TYPE('x)"
  1510   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  1511   shows "(pi\<bullet>a)\<sharp>x = a\<sharp>((rev pi)\<bullet>x)"
  1512 apply(simp add: fresh_def)
  1513 apply(simp add: pt_set_bij1[OF ptb, OF at])
  1514 apply(simp add: pt_perm_supp_ineq[OF pta, OF ptb, OF at, OF cp])
  1515 done
  1516 
  1517 lemma pt_fresh_bij_ineq:
  1518   fixes  pi :: "'x prm"
  1519   and     x :: "'a"
  1520   and     a :: "'y"
  1521   assumes pta: "pt TYPE('a) TYPE('x)"
  1522   and     ptb: "pt TYPE('y) TYPE('x)"
  1523   and     at:  "at TYPE('x)"
  1524   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  1525   shows "(pi\<bullet>a)\<sharp>(pi\<bullet>x) = a\<sharp>x"
  1526 apply(simp add: pt_fresh_left_ineq[OF pta, OF ptb, OF at, OF cp])
  1527 apply(simp add: pt_rev_pi[OF ptb, OF at])
  1528 done
  1529 
  1530 lemma pt_fresh_left:  
  1531   fixes  pi :: "'x prm"
  1532   and     x :: "'a"
  1533   and     a :: "'x"
  1534   assumes pt: "pt TYPE('a) TYPE('x)"
  1535   and     at: "at TYPE('x)"
  1536   shows "a\<sharp>(pi\<bullet>x) = ((rev pi)\<bullet>a)\<sharp>x"
  1537 apply(rule pt_fresh_left_ineq)
  1538 apply(rule pt)
  1539 apply(rule at_pt_inst)
  1540 apply(rule at)+
  1541 apply(rule cp_pt_inst)
  1542 apply(rule pt)
  1543 apply(rule at)
  1544 done
  1545 
  1546 lemma pt_fresh_right:  
  1547   fixes  pi :: "'x prm"
  1548   and     x :: "'a"
  1549   and     a :: "'x"
  1550   assumes pt: "pt TYPE('a) TYPE('x)"
  1551   and     at: "at TYPE('x)"
  1552   shows "(pi\<bullet>a)\<sharp>x = a\<sharp>((rev pi)\<bullet>x)"
  1553 apply(rule pt_fresh_right_ineq)
  1554 apply(rule pt)
  1555 apply(rule at_pt_inst)
  1556 apply(rule at)+
  1557 apply(rule cp_pt_inst)
  1558 apply(rule pt)
  1559 apply(rule at)
  1560 done
  1561 
  1562 lemma pt_fresh_bij:
  1563   fixes  pi :: "'x prm"
  1564   and     x :: "'a"
  1565   and     a :: "'x"
  1566   assumes pt: "pt TYPE('a) TYPE('x)"
  1567   and     at: "at TYPE('x)"
  1568   shows "(pi\<bullet>a)\<sharp>(pi\<bullet>x) = a\<sharp>x"
  1569 apply(rule pt_fresh_bij_ineq)
  1570 apply(rule pt)
  1571 apply(rule at_pt_inst)
  1572 apply(rule at)+
  1573 apply(rule cp_pt_inst)
  1574 apply(rule pt)
  1575 apply(rule at)
  1576 done
  1577 
  1578 lemma pt_fresh_bij1:
  1579   fixes  pi :: "'x prm"
  1580   and     x :: "'a"
  1581   and     a :: "'x"
  1582   assumes pt: "pt TYPE('a) TYPE('x)"
  1583   and     at: "at TYPE('x)"
  1584   and     a:  "a\<sharp>x"
  1585   shows "(pi\<bullet>a)\<sharp>(pi\<bullet>x)"
  1586 using a by (simp add: pt_fresh_bij[OF pt, OF at])
  1587 
  1588 lemma pt_fresh_bij2:
  1589   fixes  pi :: "'x prm"
  1590   and     x :: "'a"
  1591   and     a :: "'x"
  1592   assumes pt: "pt TYPE('a) TYPE('x)"
  1593   and     at: "at TYPE('x)"
  1594   and     a:  "(pi\<bullet>a)\<sharp>(pi\<bullet>x)"
  1595   shows  "a\<sharp>x"
  1596 using a by (simp add: pt_fresh_bij[OF pt, OF at])
  1597 
  1598 lemma pt_fresh_eqvt:
  1599   fixes  pi :: "'x prm"
  1600   and     x :: "'a"
  1601   and     a :: "'x"
  1602   assumes pt: "pt TYPE('a) TYPE('x)"
  1603   and     at: "at TYPE('x)"
  1604   shows "pi\<bullet>(a\<sharp>x) = (pi\<bullet>a)\<sharp>(pi\<bullet>x)"
  1605   by (simp add: perm_bool pt_fresh_bij[OF pt, OF at])
  1606 
  1607 lemma pt_perm_fresh1:
  1608   fixes a :: "'x"
  1609   and   b :: "'x"
  1610   and   x :: "'a"
  1611   assumes pt: "pt TYPE('a) TYPE('x)"
  1612   and     at: "at TYPE ('x)"
  1613   and     a1: "\<not>(a\<sharp>x)"
  1614   and     a2: "b\<sharp>x"
  1615   shows "[(a,b)]\<bullet>x \<noteq> x"
  1616 proof
  1617   assume neg: "[(a,b)]\<bullet>x = x"
  1618   from a1 have a1':"a\<in>(supp x)" by (simp add: fresh_def) 
  1619   from a2 have a2':"b\<notin>(supp x)" by (simp add: fresh_def) 
  1620   from a1' a2' have a3: "a\<noteq>b" by force
  1621   from a1' have "([(a,b)]\<bullet>a)\<in>([(a,b)]\<bullet>(supp x))" 
  1622     by (simp only: pt_set_bij[OF at_pt_inst[OF at], OF at])
  1623   hence "b\<in>([(a,b)]\<bullet>(supp x))" by (simp add: at_calc[OF at])
  1624   hence "b\<in>(supp ([(a,b)]\<bullet>x))" by (simp add: pt_perm_supp[OF pt,OF at])
  1625   with a2' neg show False by simp
  1626 qed
  1627 
  1628 (* the next two lemmas are needed in the proof *)
  1629 (* of the structural induction principle       *)
  1630 lemma pt_fresh_aux:
  1631   fixes a::"'x"
  1632   and   b::"'x"
  1633   and   c::"'x"
  1634   and   x::"'a"
  1635   assumes pt: "pt TYPE('a) TYPE('x)"
  1636   and     at: "at TYPE ('x)"
  1637   assumes a1: "c\<noteq>a" and  a2: "a\<sharp>x" and a3: "c\<sharp>x"
  1638   shows "c\<sharp>([(a,b)]\<bullet>x)"
  1639 using a1 a2 a3 by (simp_all add: pt_fresh_left[OF pt, OF at] at_calc[OF at])
  1640 
  1641 lemma pt_fresh_perm_app:
  1642   fixes pi :: "'x prm" 
  1643   and   a  :: "'x"
  1644   and   x  :: "'y"
  1645   assumes pt: "pt TYPE('y) TYPE('x)"
  1646   and     at: "at TYPE('x)"
  1647   and     h1: "a\<sharp>pi"
  1648   and     h2: "a\<sharp>x"
  1649   shows "a\<sharp>(pi\<bullet>x)"
  1650 using assms
  1651 proof -
  1652   have "a\<sharp>(rev pi)"using h1 by (simp add: fresh_list_rev)
  1653   then have "(rev pi)\<bullet>a = a" by (simp add: at_prm_fresh[OF at])
  1654   then have "((rev pi)\<bullet>a)\<sharp>x" using h2 by simp
  1655   thus "a\<sharp>(pi\<bullet>x)"  by (simp add: pt_fresh_right[OF pt, OF at])
  1656 qed
  1657 
  1658 lemma pt_fresh_perm_app_ineq:
  1659   fixes pi::"'x prm"
  1660   and   c::"'y"
  1661   and   x::"'a"
  1662   assumes pta: "pt TYPE('a) TYPE('x)"
  1663   and     ptb: "pt TYPE('y) TYPE('x)"
  1664   and     at:  "at TYPE('x)"
  1665   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  1666   and     dj:  "disjoint TYPE('y) TYPE('x)"
  1667   assumes a: "c\<sharp>x"
  1668   shows "c\<sharp>(pi\<bullet>x)"
  1669 using a by (simp add: pt_fresh_left_ineq[OF pta, OF ptb, OF at, OF cp] dj_perm_forget[OF dj])
  1670 
  1671 lemma pt_fresh_eqvt_ineq:
  1672   fixes pi::"'x prm"
  1673   and   c::"'y"
  1674   and   x::"'a"
  1675   assumes pta: "pt TYPE('a) TYPE('x)"
  1676   and     ptb: "pt TYPE('y) TYPE('x)"
  1677   and     at:  "at TYPE('x)"
  1678   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  1679   and     dj:  "disjoint TYPE('y) TYPE('x)"
  1680   shows "pi\<bullet>(c\<sharp>x) = (pi\<bullet>c)\<sharp>(pi\<bullet>x)"
  1681 by (simp add: pt_fresh_left_ineq[OF pta, OF ptb, OF at, OF cp] dj_perm_forget[OF dj] perm_bool)
  1682 
  1683 --"the co-set of a finite set is infinte"
  1684 lemma finite_infinite:
  1685   assumes a: "finite {b::'x. P b}"
  1686   and     b: "infinite (UNIV::'x set)"        
  1687   shows "infinite {b. \<not>P b}"
  1688 proof -
  1689   from a b have "infinite (UNIV - {b::'x. P b})" by (simp add: Diff_infinite_finite)
  1690   moreover 
  1691   have "{b::'x. \<not>P b} = UNIV - {b::'x. P b}" by auto
  1692   ultimately show "infinite {b::'x. \<not>P b}" by simp
  1693 qed 
  1694 
  1695 lemma pt_fresh_fresh:
  1696   fixes   x :: "'a"
  1697   and     a :: "'x"
  1698   and     b :: "'x"
  1699   assumes pt: "pt TYPE('a) TYPE('x)"
  1700   and     at: "at TYPE ('x)"
  1701   and     a1: "a\<sharp>x" and a2: "b\<sharp>x" 
  1702   shows "[(a,b)]\<bullet>x=x"
  1703 proof (cases "a=b")
  1704   assume "a=b"
  1705   hence "[(a,b)] \<triangleq> []" by (simp add: at_ds1[OF at])
  1706   hence "[(a,b)]\<bullet>x=([]::'x prm)\<bullet>x" by (rule pt3[OF pt])
  1707   thus ?thesis by (simp only: pt1[OF pt])
  1708 next
  1709   assume c2: "a\<noteq>b"
  1710   from a1 have f1: "finite {c. [(a,c)]\<bullet>x \<noteq> x}" by (simp add: fresh_def supp_def)
  1711   from a2 have f2: "finite {c. [(b,c)]\<bullet>x \<noteq> x}" by (simp add: fresh_def supp_def)
  1712   from f1 and f2 have f3: "finite {c. perm [(a,c)] x \<noteq> x \<or> perm [(b,c)] x \<noteq> x}" 
  1713     by (force simp only: Collect_disj_eq)
  1714   have "infinite {c. [(a,c)]\<bullet>x = x \<and> [(b,c)]\<bullet>x = x}" 
  1715     by (simp add: finite_infinite[OF f3,OF at4[OF at], simplified])
  1716   hence "infinite ({c. [(a,c)]\<bullet>x = x \<and> [(b,c)]\<bullet>x = x}-{a,b})" 
  1717     by (force dest: Diff_infinite_finite)
  1718   hence "({c. [(a,c)]\<bullet>x = x \<and> [(b,c)]\<bullet>x = x}-{a,b}) \<noteq> {}"
  1719     by (metis finite_set set_empty2)
  1720   hence "\<exists>c. c\<in>({c. [(a,c)]\<bullet>x = x \<and> [(b,c)]\<bullet>x = x}-{a,b})" by (force)
  1721   then obtain c 
  1722     where eq1: "[(a,c)]\<bullet>x = x" 
  1723       and eq2: "[(b,c)]\<bullet>x = x" 
  1724       and ineq: "a\<noteq>c \<and> b\<noteq>c"
  1725     by (force)
  1726   hence "[(a,c)]\<bullet>([(b,c)]\<bullet>([(a,c)]\<bullet>x)) = x" by simp 
  1727   hence eq3: "[(a,c),(b,c),(a,c)]\<bullet>x = x" by (simp add: pt2[OF pt,symmetric])
  1728   from c2 ineq have "[(a,c),(b,c),(a,c)] \<triangleq> [(a,b)]" by (simp add: at_ds3[OF at])
  1729   hence "[(a,c),(b,c),(a,c)]\<bullet>x = [(a,b)]\<bullet>x" by (rule pt3[OF pt])
  1730   thus ?thesis using eq3 by simp
  1731 qed
  1732 
  1733 lemma pt_pi_fresh_fresh:
  1734   fixes   x :: "'a"
  1735   and     pi :: "'x prm"
  1736   assumes pt: "pt TYPE('a) TYPE('x)"
  1737   and     at: "at TYPE ('x)"
  1738   and     a:  "\<forall>(a,b)\<in>set pi. a\<sharp>x \<and> b\<sharp>x" 
  1739   shows "pi\<bullet>x=x"
  1740 using a
  1741 proof (induct pi)
  1742   case Nil
  1743   show "([]::'x prm)\<bullet>x = x" by (rule pt1[OF pt])
  1744 next
  1745   case (Cons ab pi)
  1746   have a: "\<forall>(a,b)\<in>set (ab#pi). a\<sharp>x \<and> b\<sharp>x" by fact
  1747   have ih: "(\<forall>(a,b)\<in>set pi. a\<sharp>x \<and> b\<sharp>x) \<Longrightarrow> pi\<bullet>x=x" by fact
  1748   obtain a b where e: "ab=(a,b)" by (cases ab) (auto)
  1749   from a have a': "a\<sharp>x" "b\<sharp>x" using e by auto
  1750   have "(ab#pi)\<bullet>x = ([(a,b)]@pi)\<bullet>x" using e by simp
  1751   also have "\<dots> = [(a,b)]\<bullet>(pi\<bullet>x)" by (simp only: pt2[OF pt])
  1752   also have "\<dots> = [(a,b)]\<bullet>x" using ih a by simp
  1753   also have "\<dots> = x" using a' by (simp add: pt_fresh_fresh[OF pt, OF at])
  1754   finally show "(ab#pi)\<bullet>x = x" by simp
  1755 qed
  1756 
  1757 lemma pt_perm_compose:
  1758   fixes pi1 :: "'x prm"
  1759   and   pi2 :: "'x prm"
  1760   and   x  :: "'a"
  1761   assumes pt: "pt TYPE('a) TYPE('x)"
  1762   and     at: "at TYPE('x)"
  1763   shows "pi2\<bullet>(pi1\<bullet>x) = (pi2\<bullet>pi1)\<bullet>(pi2\<bullet>x)" 
  1764 proof -
  1765   have "(pi2@pi1) \<triangleq> ((pi2\<bullet>pi1)@pi2)" by (rule at_ds8 [OF at])
  1766   hence "(pi2@pi1)\<bullet>x = ((pi2\<bullet>pi1)@pi2)\<bullet>x" by (rule pt3[OF pt])
  1767   thus ?thesis by (simp add: pt2[OF pt])
  1768 qed
  1769 
  1770 lemma pt_perm_compose':
  1771   fixes pi1 :: "'x prm"
  1772   and   pi2 :: "'x prm"
  1773   and   x  :: "'a"
  1774   assumes pt: "pt TYPE('a) TYPE('x)"
  1775   and     at: "at TYPE('x)"
  1776   shows "(pi2\<bullet>pi1)\<bullet>x = pi2\<bullet>(pi1\<bullet>((rev pi2)\<bullet>x))" 
  1777 proof -
  1778   have "pi2\<bullet>(pi1\<bullet>((rev pi2)\<bullet>x)) = (pi2\<bullet>pi1)\<bullet>(pi2\<bullet>((rev pi2)\<bullet>x))"
  1779     by (rule pt_perm_compose[OF pt, OF at])
  1780   also have "\<dots> = (pi2\<bullet>pi1)\<bullet>x" by (simp add: pt_pi_rev[OF pt, OF at])
  1781   finally have "pi2\<bullet>(pi1\<bullet>((rev pi2)\<bullet>x)) = (pi2\<bullet>pi1)\<bullet>x" by simp
  1782   thus ?thesis by simp
  1783 qed
  1784 
  1785 lemma pt_perm_compose_rev:
  1786   fixes pi1 :: "'x prm"
  1787   and   pi2 :: "'x prm"
  1788   and   x  :: "'a"
  1789   assumes pt: "pt TYPE('a) TYPE('x)"
  1790   and     at: "at TYPE('x)"
  1791   shows "(rev pi2)\<bullet>((rev pi1)\<bullet>x) = (rev pi1)\<bullet>(rev (pi1\<bullet>pi2)\<bullet>x)" 
  1792 proof -
  1793   have "((rev pi2)@(rev pi1)) \<triangleq> ((rev pi1)@(rev (pi1\<bullet>pi2)))" by (rule at_ds9[OF at])
  1794   hence "((rev pi2)@(rev pi1))\<bullet>x = ((rev pi1)@(rev (pi1\<bullet>pi2)))\<bullet>x" by (rule pt3[OF pt])
  1795   thus ?thesis by (simp add: pt2[OF pt])
  1796 qed
  1797 
  1798 section {* equivariance for some connectives *}
  1799 lemma pt_all_eqvt:
  1800   fixes  pi :: "'x prm"
  1801   and     x :: "'a"
  1802   assumes pt: "pt TYPE('a) TYPE('x)"
  1803   and     at: "at TYPE('x)"
  1804   shows "pi\<bullet>(\<forall>(x::'a). P x) = (\<forall>(x::'a). pi\<bullet>(P ((rev pi)\<bullet>x)))"
  1805 apply(auto simp add: perm_bool perm_fun_def)
  1806 apply(drule_tac x="pi\<bullet>x" in spec)
  1807 apply(simp add: pt_rev_pi[OF pt, OF at])
  1808 done
  1809 
  1810 lemma pt_ex_eqvt:
  1811   fixes  pi :: "'x prm"
  1812   and     x :: "'a"
  1813   assumes pt: "pt TYPE('a) TYPE('x)"
  1814   and     at: "at TYPE('x)"
  1815   shows "pi\<bullet>(\<exists>(x::'a). P x) = (\<exists>(x::'a). pi\<bullet>(P ((rev pi)\<bullet>x)))"
  1816 apply(auto simp add: perm_bool perm_fun_def)
  1817 apply(rule_tac x="pi\<bullet>x" in exI) 
  1818 apply(simp add: pt_rev_pi[OF pt, OF at])
  1819 done
  1820 
  1821 lemma pt_ex1_eqvt:
  1822   fixes  pi :: "'x prm"
  1823   and     x :: "'a"
  1824   assumes pt: "pt TYPE('a) TYPE('x)"
  1825   and     at: "at TYPE('x)"
  1826   shows  "(pi\<bullet>(\<exists>!x. P (x::'a))) = (\<exists>!x. pi\<bullet>(P (rev pi\<bullet>x)))"
  1827 unfolding Ex1_def
  1828 by (simp add: pt_ex_eqvt[OF pt at] conj_eqvt pt_all_eqvt[OF pt at] 
  1829               imp_eqvt pt_eq_eqvt[OF pt at] pt_pi_rev[OF pt at])
  1830 
  1831 lemma pt_the_eqvt:
  1832   fixes  pi :: "'x prm"
  1833   assumes pt: "pt TYPE('a) TYPE('x)"
  1834   and     at: "at TYPE('x)"
  1835   and     unique: "\<exists>!x. P x"
  1836   shows "pi\<bullet>(THE(x::'a). P x) = (THE(x::'a). pi\<bullet>(P ((rev pi)\<bullet>x)))"
  1837   apply(rule the1_equality [symmetric])
  1838   apply(simp add: pt_ex1_eqvt[OF pt at,symmetric])
  1839   apply(simp add: perm_bool unique)
  1840   apply(simp add: perm_bool pt_rev_pi [OF pt at])
  1841   apply(rule theI'[OF unique])
  1842   done
  1843 
  1844 section {* facts about supports *}
  1845 (*==============================*)
  1846 
  1847 lemma supports_subset:
  1848   fixes x  :: "'a"
  1849   and   S1 :: "'x set"
  1850   and   S2 :: "'x set"
  1851   assumes  a: "S1 supports x"
  1852   and      b: "S1 \<subseteq> S2"
  1853   shows "S2 supports x"
  1854   using a b
  1855   by (force simp add: supports_def)
  1856 
  1857 lemma supp_is_subset:
  1858   fixes S :: "'x set"
  1859   and   x :: "'a"
  1860   assumes a1: "S supports x"
  1861   and     a2: "finite S"
  1862   shows "(supp x)\<subseteq>S"
  1863 proof (rule ccontr)
  1864   assume "\<not>(supp x \<subseteq> S)"
  1865   hence "\<exists>a. a\<in>(supp x) \<and> a\<notin>S" by force
  1866   then obtain a where b1: "a\<in>supp x" and b2: "a\<notin>S" by force
  1867   from a1 b2 have "\<forall>b. (b\<notin>S \<longrightarrow> ([(a,b)]\<bullet>x = x))" by (unfold supports_def, force)
  1868   hence "{b. [(a,b)]\<bullet>x \<noteq> x}\<subseteq>S" by force
  1869   with a2 have "finite {b. [(a,b)]\<bullet>x \<noteq> x}" by (simp add: finite_subset)
  1870   hence "a\<notin>(supp x)" by (unfold supp_def, auto)
  1871   with b1 show False by simp
  1872 qed
  1873 
  1874 lemma supp_supports:
  1875   fixes x :: "'a"
  1876   assumes  pt: "pt TYPE('a) TYPE('x)"
  1877   and      at: "at TYPE ('x)"
  1878   shows "((supp x)::'x set) supports x"
  1879 proof (unfold supports_def, intro strip)
  1880   fix a b
  1881   assume "(a::'x)\<notin>(supp x) \<and> (b::'x)\<notin>(supp x)"
  1882   hence "a\<sharp>x" and "b\<sharp>x" by (auto simp add: fresh_def)
  1883   thus "[(a,b)]\<bullet>x = x" by (rule pt_fresh_fresh[OF pt, OF at])
  1884 qed
  1885 
  1886 lemma supports_finite:
  1887   fixes S :: "'x set"
  1888   and   x :: "'a"
  1889   assumes a1: "S supports x"
  1890   and     a2: "finite S"
  1891   shows "finite ((supp x)::'x set)"
  1892 proof -
  1893   have "(supp x)\<subseteq>S" using a1 a2 by (rule supp_is_subset)
  1894   thus ?thesis using a2 by (simp add: finite_subset)
  1895 qed
  1896   
  1897 lemma supp_is_inter:
  1898   fixes  x :: "'a"
  1899   assumes  pt: "pt TYPE('a) TYPE('x)"
  1900   and      at: "at TYPE ('x)"
  1901   and      fs: "fs TYPE('a) TYPE('x)"
  1902   shows "((supp x)::'x set) = (\<Inter> {S. finite S \<and> S supports x})"
  1903 proof (rule equalityI)
  1904   show "((supp x)::'x set) \<subseteq> (\<Inter> {S. finite S \<and> S supports x})"
  1905   proof (clarify)
  1906     fix S c
  1907     assume b: "c\<in>((supp x)::'x set)" and "finite (S::'x set)" and "S supports x"
  1908     hence  "((supp x)::'x set)\<subseteq>S" by (simp add: supp_is_subset) 
  1909     with b show "c\<in>S" by force
  1910   qed
  1911 next
  1912   show "(\<Inter> {S. finite S \<and> S supports x}) \<subseteq> ((supp x)::'x set)"
  1913   proof (clarify, simp)
  1914     fix c
  1915     assume d: "\<forall>(S::'x set). finite S \<and> S supports x \<longrightarrow> c\<in>S"
  1916     have "((supp x)::'x set) supports x" by (rule supp_supports[OF pt, OF at])
  1917     with d fs1[OF fs] show "c\<in>supp x" by force
  1918   qed
  1919 qed
  1920     
  1921 lemma supp_is_least_supports:
  1922   fixes S :: "'x set"
  1923   and   x :: "'a"
  1924   assumes  pt: "pt TYPE('a) TYPE('x)"
  1925   and      at: "at TYPE ('x)"
  1926   and      a1: "S supports x"
  1927   and      a2: "finite S"
  1928   and      a3: "\<forall>S'. (S' supports x) \<longrightarrow> S\<subseteq>S'"
  1929   shows "S = (supp x)"
  1930 proof (rule equalityI)
  1931   show "((supp x)::'x set)\<subseteq>S" using a1 a2 by (rule supp_is_subset)
  1932 next
  1933   have "((supp x)::'x set) supports x" by (rule supp_supports[OF pt, OF at])
  1934   with a3 show "S\<subseteq>supp x" by force
  1935 qed
  1936 
  1937 lemma supports_set:
  1938   fixes S :: "'x set"
  1939   and   X :: "'a set"
  1940   assumes  pt: "pt TYPE('a) TYPE('x)"
  1941   and      at: "at TYPE ('x)"
  1942   and      a: "\<forall>x\<in>X. (\<forall>(a::'x) (b::'x). a\<notin>S\<and>b\<notin>S \<longrightarrow> ([(a,b)]\<bullet>x)\<in>X)"
  1943   shows  "S supports X"
  1944 using a
  1945 apply(auto simp add: supports_def)
  1946 apply(simp add: pt_set_bij1a[OF pt, OF at])
  1947 apply(force simp add: pt_swap_bij[OF pt, OF at])
  1948 apply(simp add: pt_set_bij1a[OF pt, OF at])
  1949 done
  1950 
  1951 lemma supports_fresh:
  1952   fixes S :: "'x set"
  1953   and   a :: "'x"
  1954   and   x :: "'a"
  1955   assumes a1: "S supports x"
  1956   and     a2: "finite S"
  1957   and     a3: "a\<notin>S"
  1958   shows "a\<sharp>x"
  1959 proof (simp add: fresh_def)
  1960   have "(supp x)\<subseteq>S" using a1 a2 by (rule supp_is_subset)
  1961   thus "a\<notin>(supp x)" using a3 by force
  1962 qed
  1963 
  1964 lemma at_fin_set_supports:
  1965   fixes X::"'x set"
  1966   assumes at: "at TYPE('x)"
  1967   shows "X supports X"
  1968 proof -
  1969   have "\<forall>a b. a\<notin>X \<and> b\<notin>X \<longrightarrow> [(a,b)]\<bullet>X = X"
  1970     by (auto simp add: perm_set_eq [OF at_pt_inst [OF at] at] at_calc[OF at])
  1971   then show ?thesis by (simp add: supports_def)
  1972 qed
  1973 
  1974 lemma infinite_Collection:
  1975   assumes a1:"infinite X"
  1976   and     a2:"\<forall>b\<in>X. P(b)"
  1977   shows "infinite {b\<in>X. P(b)}"
  1978   using a1 a2 
  1979   apply auto
  1980   apply (subgoal_tac "infinite (X - {b\<in>X. P b})")
  1981   apply (simp add: set_diff_eq)
  1982   apply (simp add: Diff_infinite_finite)
  1983   done
  1984 
  1985 lemma at_fin_set_supp:
  1986   fixes X::"'x set" 
  1987   assumes at: "at TYPE('x)"
  1988   and     fs: "finite X"
  1989   shows "(supp X) = X"
  1990 proof (rule subset_antisym)
  1991   show "(supp X) \<subseteq> X" using at_fin_set_supports[OF at] using fs by (simp add: supp_is_subset)
  1992 next
  1993   have inf: "infinite (UNIV-X)" using at4[OF at] fs by (auto simp add: Diff_infinite_finite)
  1994   { fix a::"'x"
  1995     assume asm: "a\<in>X"
  1996     hence "\<forall>b\<in>(UNIV-X). [(a,b)]\<bullet>X\<noteq>X"
  1997       by (auto simp add: perm_set_eq [OF at_pt_inst [OF at] at] at_calc[OF at])
  1998     with inf have "infinite {b\<in>(UNIV-X). [(a,b)]\<bullet>X\<noteq>X}" by (rule infinite_Collection)
  1999     hence "infinite {b. [(a,b)]\<bullet>X\<noteq>X}" by (rule_tac infinite_super, auto)
  2000     hence "a\<in>(supp X)" by (simp add: supp_def)
  2001   }
  2002   then show "X\<subseteq>(supp X)" by blast
  2003 qed
  2004 
  2005 lemma at_fin_set_fresh:
  2006   fixes X::"'x set" 
  2007   assumes at: "at TYPE('x)"
  2008   and     fs: "finite X"
  2009   shows "(x \<sharp> X) = (x \<notin> X)"
  2010   by (simp add: at_fin_set_supp fresh_def at fs)
  2011 
  2012 
  2013 section {* Permutations acting on Functions *}
  2014 (*==========================================*)
  2015 
  2016 lemma pt_fun_app_eq:
  2017   fixes f  :: "'a\<Rightarrow>'b"
  2018   and   x  :: "'a"
  2019   and   pi :: "'x prm"
  2020   assumes pt: "pt TYPE('a) TYPE('x)"
  2021   and     at: "at TYPE('x)"
  2022   shows "pi\<bullet>(f x) = (pi\<bullet>f)(pi\<bullet>x)"
  2023   by (simp add: perm_fun_def pt_rev_pi[OF pt, OF at])
  2024 
  2025 
  2026 --"sometimes pt_fun_app_eq does too much; this lemma 'corrects it'"
  2027 lemma pt_perm:
  2028   fixes x  :: "'a"
  2029   and   pi1 :: "'x prm"
  2030   and   pi2 :: "'x prm"
  2031   assumes pt: "pt TYPE('a) TYPE('x)"
  2032   and     at: "at TYPE ('x)"
  2033   shows "(pi1\<bullet>perm pi2)(pi1\<bullet>x) = pi1\<bullet>(pi2\<bullet>x)" 
  2034   by (simp add: pt_fun_app_eq[OF pt, OF at])
  2035 
  2036 
  2037 lemma pt_fun_eq:
  2038   fixes f  :: "'a\<Rightarrow>'b"
  2039   and   pi :: "'x prm"
  2040   assumes pt: "pt TYPE('a) TYPE('x)"
  2041   and     at: "at TYPE('x)"
  2042   shows "(pi\<bullet>f = f) = (\<forall> x. pi\<bullet>(f x) = f (pi\<bullet>x))" (is "?LHS = ?RHS")
  2043 proof
  2044   assume a: "?LHS"
  2045   show "?RHS"
  2046   proof
  2047     fix x
  2048     have "pi\<bullet>(f x) = (pi\<bullet>f)(pi\<bullet>x)" by (simp add: pt_fun_app_eq[OF pt, OF at])
  2049     also have "\<dots> = f (pi\<bullet>x)" using a by simp
  2050     finally show "pi\<bullet>(f x) = f (pi\<bullet>x)" by simp
  2051   qed
  2052 next
  2053   assume b: "?RHS"
  2054   show "?LHS"
  2055   proof (rule ccontr)
  2056     assume "(pi\<bullet>f) \<noteq> f"
  2057     hence "\<exists>x. (pi\<bullet>f) x \<noteq> f x" by (simp add: fun_eq_iff)
  2058     then obtain x where b1: "(pi\<bullet>f) x \<noteq> f x" by force
  2059     from b have "pi\<bullet>(f ((rev pi)\<bullet>x)) = f (pi\<bullet>((rev pi)\<bullet>x))" by force
  2060     hence "(pi\<bullet>f)(pi\<bullet>((rev pi)\<bullet>x)) = f (pi\<bullet>((rev pi)\<bullet>x))" 
  2061       by (simp add: pt_fun_app_eq[OF pt, OF at])
  2062     hence "(pi\<bullet>f) x = f x" by (simp add: pt_pi_rev[OF pt, OF at])
  2063     with b1 show "False" by simp
  2064   qed
  2065 qed
  2066 
  2067 -- "two helper lemmas for the equivariance of functions"
  2068 lemma pt_swap_eq_aux:
  2069   fixes   y :: "'a"
  2070   and    pi :: "'x prm"
  2071   assumes pt: "pt TYPE('a) TYPE('x)"
  2072   and     a: "\<forall>(a::'x) (b::'x). [(a,b)]\<bullet>y = y"
  2073   shows "pi\<bullet>y = y"
  2074 proof(induct pi)
  2075   case Nil show ?case by (simp add: pt1[OF pt])
  2076 next
  2077   case (Cons x xs)
  2078   have ih: "xs\<bullet>y = y" by fact
  2079   obtain a b where p: "x=(a,b)" by force
  2080   have "((a,b)#xs)\<bullet>y = ([(a,b)]@xs)\<bullet>y" by simp
  2081   also have "\<dots> = [(a,b)]\<bullet>(xs\<bullet>y)" by (simp only: pt2[OF pt])
  2082   finally show ?case using a ih p by simp
  2083 qed
  2084 
  2085 lemma pt_swap_eq:
  2086   fixes   y :: "'a"
  2087   assumes pt: "pt TYPE('a) TYPE('x)"
  2088   shows "(\<forall>(a::'x) (b::'x). [(a,b)]\<bullet>y = y) = (\<forall>pi::'x prm. pi\<bullet>y = y)"
  2089   by (force intro: pt_swap_eq_aux[OF pt])
  2090 
  2091 lemma pt_eqvt_fun1a:
  2092   fixes f     :: "'a\<Rightarrow>'b"
  2093   assumes pta: "pt TYPE('a) TYPE('x)"
  2094   and     ptb: "pt TYPE('b) TYPE('x)"
  2095   and     at:  "at TYPE('x)"
  2096   and     a:   "((supp f)::'x set)={}"
  2097   shows "\<forall>(pi::'x prm). pi\<bullet>f = f" 
  2098 proof (intro strip)
  2099   fix pi
  2100   have "\<forall>a b. a\<notin>((supp f)::'x set) \<and> b\<notin>((supp f)::'x set) \<longrightarrow> (([(a,b)]\<bullet>f) = f)" 
  2101     by (intro strip, fold fresh_def, 
  2102       simp add: pt_fresh_fresh[OF pt_fun_inst[OF pta, OF ptb, OF at],OF at])
  2103   with a have "\<forall>(a::'x) (b::'x). ([(a,b)]\<bullet>f) = f" by force
  2104   hence "\<forall>(pi::'x prm). pi\<bullet>f = f" 
  2105     by (simp add: pt_swap_eq[OF pt_fun_inst[OF pta, OF ptb, OF at]])
  2106   thus "(pi::'x prm)\<bullet>f = f" by simp
  2107 qed
  2108 
  2109 lemma pt_eqvt_fun1b:
  2110   fixes f     :: "'a\<Rightarrow>'b"
  2111   assumes a: "\<forall>(pi::'x prm). pi\<bullet>f = f"
  2112   shows "((supp f)::'x set)={}"
  2113 using a by (simp add: supp_def)
  2114 
  2115 lemma pt_eqvt_fun1:
  2116   fixes f     :: "'a\<Rightarrow>'b"
  2117   assumes pta: "pt TYPE('a) TYPE('x)"
  2118   and     ptb: "pt TYPE('b) TYPE('x)"
  2119   and     at: "at TYPE('x)"
  2120   shows "(((supp f)::'x set)={}) = (\<forall>(pi::'x prm). pi\<bullet>f = f)" (is "?LHS = ?RHS")
  2121 by (rule iffI, simp add: pt_eqvt_fun1a[OF pta, OF ptb, OF at], simp add: pt_eqvt_fun1b)
  2122 
  2123 lemma pt_eqvt_fun2a:
  2124   fixes f     :: "'a\<Rightarrow>'b"
  2125   assumes pta: "pt TYPE('a) TYPE('x)"
  2126   and     ptb: "pt TYPE('b) TYPE('x)"
  2127   and     at: "at TYPE('x)"
  2128   assumes a: "((supp f)::'x set)={}"
  2129   shows "\<forall>(pi::'x prm) (x::'a). pi\<bullet>(f x) = f(pi\<bullet>x)" 
  2130 proof (intro strip)
  2131   fix pi x
  2132   from a have b: "\<forall>(pi::'x prm). pi\<bullet>f = f" by (simp add: pt_eqvt_fun1[OF pta, OF ptb, OF at]) 
  2133   have "(pi::'x prm)\<bullet>(f x) = (pi\<bullet>f)(pi\<bullet>x)" by (simp add: pt_fun_app_eq[OF pta, OF at]) 
  2134   with b show "(pi::'x prm)\<bullet>(f x) = f (pi\<bullet>x)" by force 
  2135 qed
  2136 
  2137 lemma pt_eqvt_fun2b:
  2138   fixes f     :: "'a\<Rightarrow>'b"
  2139   assumes pt1: "pt TYPE('a) TYPE('x)"
  2140   and     pt2: "pt TYPE('b) TYPE('x)"
  2141   and     at: "at TYPE('x)"
  2142   assumes a: "\<forall>(pi::'x prm) (x::'a). pi\<bullet>(f x) = f(pi\<bullet>x)"
  2143   shows "((supp f)::'x set)={}"
  2144 proof -
  2145   from a have "\<forall>(pi::'x prm). pi\<bullet>f = f" by (simp add: pt_fun_eq[OF pt1, OF at, symmetric])
  2146   thus ?thesis by (simp add: supp_def)
  2147 qed
  2148 
  2149 lemma pt_eqvt_fun2:
  2150   fixes f     :: "'a\<Rightarrow>'b"
  2151   assumes pta: "pt TYPE('a) TYPE('x)"
  2152   and     ptb: "pt TYPE('b) TYPE('x)"
  2153   and     at: "at TYPE('x)"
  2154   shows "(((supp f)::'x set)={}) = (\<forall>(pi::'x prm) (x::'a). pi\<bullet>(f x) = f(pi\<bullet>x))" 
  2155 by (rule iffI, 
  2156     simp add: pt_eqvt_fun2a[OF pta, OF ptb, OF at], 
  2157     simp add: pt_eqvt_fun2b[OF pta, OF ptb, OF at])
  2158 
  2159 lemma pt_supp_fun_subset:
  2160   fixes f :: "'a\<Rightarrow>'b"
  2161   assumes pta: "pt TYPE('a) TYPE('x)"
  2162   and     ptb: "pt TYPE('b) TYPE('x)"
  2163   and     at: "at TYPE('x)" 
  2164   and     f1: "finite ((supp f)::'x set)"
  2165   and     f2: "finite ((supp x)::'x set)"
  2166   shows "supp (f x) \<subseteq> (((supp f)\<union>(supp x))::'x set)"
  2167 proof -
  2168   have s1: "((supp f)\<union>((supp x)::'x set)) supports (f x)"
  2169   proof (simp add: supports_def, fold fresh_def, auto)
  2170     fix a::"'x" and b::"'x"
  2171     assume "a\<sharp>f" and "b\<sharp>f"
  2172     hence a1: "[(a,b)]\<bullet>f = f" 
  2173       by (rule pt_fresh_fresh[OF pt_fun_inst[OF pta, OF ptb, OF at], OF at])
  2174     assume "a\<sharp>x" and "b\<sharp>x"
  2175     hence a2: "[(a,b)]\<bullet>x = x" by (rule pt_fresh_fresh[OF pta, OF at])
  2176     from a1 a2 show "[(a,b)]\<bullet>(f x) = (f x)" by (simp add: pt_fun_app_eq[OF pta, OF at])
  2177   qed
  2178   from f1 f2 have "finite ((supp f)\<union>((supp x)::'x set))" by force
  2179   with s1 show ?thesis by (rule supp_is_subset)
  2180 qed
  2181       
  2182 lemma pt_empty_supp_fun_subset:
  2183   fixes f :: "'a\<Rightarrow>'b"
  2184   assumes pta: "pt TYPE('a) TYPE('x)"
  2185   and     ptb: "pt TYPE('b) TYPE('x)"
  2186   and     at:  "at TYPE('x)" 
  2187   and     e:   "(supp f)=({}::'x set)"
  2188   shows "supp (f x) \<subseteq> ((supp x)::'x set)"
  2189 proof (unfold supp_def, auto)
  2190   fix a::"'x"
  2191   assume a1: "finite {b. [(a, b)]\<bullet>x \<noteq> x}"
  2192   assume "infinite {b. [(a, b)]\<bullet>(f x) \<noteq> f x}"
  2193   hence a2: "infinite {b. f ([(a, b)]\<bullet>x) \<noteq> f x}" using e
  2194     by (simp add: pt_eqvt_fun2[OF pta, OF ptb, OF at])
  2195   have a3: "{b. f ([(a,b)]\<bullet>x) \<noteq> f x}\<subseteq>{b. [(a,b)]\<bullet>x \<noteq> x}" by force
  2196   from a1 a2 a3 show False by (force dest: finite_subset)
  2197 qed
  2198 
  2199 section {* Facts about the support of finite sets of finitely supported things *}
  2200 (*=============================================================================*)
  2201 
  2202 definition X_to_Un_supp :: "('a set) \<Rightarrow> 'x set" where
  2203   "X_to_Un_supp X \<equiv> \<Union>x\<in>X. ((supp x)::'x set)"
  2204 
  2205 lemma UNION_f_eqvt:
  2206   fixes X::"('a set)"
  2207   and   f::"'a \<Rightarrow> 'x set"
  2208   and   pi::"'x prm"
  2209   assumes pt: "pt TYPE('a) TYPE('x)"
  2210   and     at: "at TYPE('x)"
  2211   shows "pi\<bullet>(\<Union>x\<in>X. f x) = (\<Union>x\<in>(pi\<bullet>X). (pi\<bullet>f) x)"
  2212 proof -
  2213   have pt_x: "pt TYPE('x) TYPE('x)" by (force intro: at_pt_inst at)
  2214   show ?thesis
  2215   proof (rule equalityI)
  2216     case goal1
  2217     show "pi\<bullet>(\<Union>x\<in>X. f x) \<subseteq> (\<Union>x\<in>(pi\<bullet>X). (pi\<bullet>f) x)"
  2218       apply(auto simp add: perm_set_eq [OF pt at] perm_set_eq [OF at_pt_inst [OF at] at])
  2219       apply(rule_tac x="pi\<bullet>xb" in exI)
  2220       apply(rule conjI)
  2221       apply(rule_tac x="xb" in exI)
  2222       apply(simp)
  2223       apply(subgoal_tac "(pi\<bullet>f) (pi\<bullet>xb) = pi\<bullet>(f xb)")(*A*)
  2224       apply(simp)
  2225       apply(rule pt_set_bij2[OF pt_x, OF at])
  2226       apply(assumption)
  2227       (*A*)
  2228       apply(rule sym)
  2229       apply(rule pt_fun_app_eq[OF pt, OF at])
  2230       done
  2231   next
  2232     case goal2
  2233     show "(\<Union>x\<in>(pi\<bullet>X). (pi\<bullet>f) x) \<subseteq> pi\<bullet>(\<Union>x\<in>X. f x)"
  2234       apply(auto simp add: perm_set_eq [OF pt at] perm_set_eq [OF at_pt_inst [OF at] at])
  2235       apply(rule_tac x="(rev pi)\<bullet>x" in exI)
  2236       apply(rule conjI)
  2237       apply(simp add: pt_pi_rev[OF pt_x, OF at])
  2238       apply(rule_tac x="xb" in bexI)
  2239       apply(simp add: pt_set_bij1[OF pt_x, OF at])
  2240       apply(simp add: pt_fun_app_eq[OF pt, OF at])
  2241       apply(assumption)
  2242       done
  2243   qed
  2244 qed
  2245 
  2246 lemma X_to_Un_supp_eqvt:
  2247   fixes X::"('a set)"
  2248   and   pi::"'x prm"
  2249   assumes pt: "pt TYPE('a) TYPE('x)"
  2250   and     at: "at TYPE('x)"
  2251   shows "pi\<bullet>(X_to_Un_supp X) = ((X_to_Un_supp (pi\<bullet>X))::'x set)"
  2252   apply(simp add: X_to_Un_supp_def)
  2253   apply(simp add: UNION_f_eqvt[OF pt, OF at] perm_fun_def [where 'b="'x set"])
  2254   apply(simp add: pt_perm_supp[OF pt, OF at])
  2255   apply(simp add: pt_pi_rev[OF pt, OF at])
  2256   done
  2257 
  2258 lemma Union_supports_set:
  2259   fixes X::"('a set)"
  2260   assumes pt: "pt TYPE('a) TYPE('x)"
  2261   and     at: "at TYPE('x)"
  2262   shows "(\<Union>x\<in>X. ((supp x)::'x set)) supports X"
  2263   apply(simp add: supports_def fresh_def[symmetric])
  2264   apply(rule allI)+
  2265   apply(rule impI)
  2266   apply(erule conjE)
  2267   apply(simp add: perm_set_eq [OF pt at])
  2268   apply(auto)
  2269   apply(subgoal_tac "[(a,b)]\<bullet>xa = xa")(*A*)
  2270   apply(simp)
  2271   apply(rule pt_fresh_fresh[OF pt, OF at])
  2272   apply(force)
  2273   apply(force)
  2274   apply(rule_tac x="x" in exI)
  2275   apply(simp)
  2276   apply(rule sym)
  2277   apply(rule pt_fresh_fresh[OF pt, OF at])
  2278   apply(force)+
  2279   done
  2280 
  2281 lemma Union_of_fin_supp_sets:
  2282   fixes X::"('a set)"
  2283   assumes fs: "fs TYPE('a) TYPE('x)" 
  2284   and     fi: "finite X"   
  2285   shows "finite (\<Union>x\<in>X. ((supp x)::'x set))"
  2286 using fi by (induct, auto simp add: fs1[OF fs])
  2287 
  2288 lemma Union_included_in_supp:
  2289   fixes X::"('a set)"
  2290   assumes pt: "pt TYPE('a) TYPE('x)"
  2291   and     at: "at TYPE('x)"
  2292   and     fs: "fs TYPE('a) TYPE('x)" 
  2293   and     fi: "finite X"
  2294   shows "(\<Union>x\<in>X. ((supp x)::'x set)) \<subseteq> supp X"
  2295 proof -
  2296   have "supp ((X_to_Un_supp X)::'x set) \<subseteq> ((supp X)::'x set)"  
  2297     apply(rule pt_empty_supp_fun_subset)
  2298     apply(force intro: pt_fun_inst pt_bool_inst at_pt_inst pt at)+
  2299     apply(rule pt_eqvt_fun2b)
  2300     apply(force intro: pt_fun_inst pt_bool_inst at_pt_inst pt at)+
  2301     apply(rule allI)+
  2302     apply(rule X_to_Un_supp_eqvt[OF pt, OF at])
  2303     done
  2304   hence "supp (\<Union>x\<in>X. ((supp x)::'x set)) \<subseteq> ((supp X)::'x set)" by (simp add: X_to_Un_supp_def)
  2305   moreover
  2306   have "supp (\<Union>x\<in>X. ((supp x)::'x set)) = (\<Union>x\<in>X. ((supp x)::'x set))"
  2307     apply(rule at_fin_set_supp[OF at])
  2308     apply(rule Union_of_fin_supp_sets[OF fs, OF fi])
  2309     done
  2310   ultimately show ?thesis by force
  2311 qed
  2312 
  2313 lemma supp_of_fin_sets:
  2314   fixes X::"('a set)"
  2315   assumes pt: "pt TYPE('a) TYPE('x)"
  2316   and     at: "at TYPE('x)"
  2317   and     fs: "fs TYPE('a) TYPE('x)" 
  2318   and     fi: "finite X"
  2319   shows "(supp X) = (\<Union>x\<in>X. ((supp x)::'x set))"
  2320 apply(rule equalityI)
  2321 apply(rule supp_is_subset)
  2322 apply(rule Union_supports_set[OF pt, OF at])
  2323 apply(rule Union_of_fin_supp_sets[OF fs, OF fi])
  2324 apply(rule Union_included_in_supp[OF pt, OF at, OF fs, OF fi])
  2325 done
  2326 
  2327 lemma supp_fin_union:
  2328   fixes X::"('a set)"
  2329   and   Y::"('a set)"
  2330   assumes pt: "pt TYPE('a) TYPE('x)"
  2331   and     at: "at TYPE('x)"
  2332   and     fs: "fs TYPE('a) TYPE('x)" 
  2333   and     f1: "finite X"
  2334   and     f2: "finite Y"
  2335   shows "(supp (X\<union>Y)) = (supp X)\<union>((supp Y)::'x set)"
  2336 using f1 f2 by (force simp add: supp_of_fin_sets[OF pt, OF at, OF fs])
  2337 
  2338 lemma supp_fin_insert:
  2339   fixes X::"('a set)"
  2340   and   x::"'a"
  2341   assumes pt: "pt TYPE('a) TYPE('x)"
  2342   and     at: "at TYPE('x)"
  2343   and     fs: "fs TYPE('a) TYPE('x)" 
  2344   and     f:  "finite X"
  2345   shows "(supp (insert x X)) = (supp x)\<union>((supp X)::'x set)"
  2346 proof -
  2347   have "(supp (insert x X)) = ((supp ({x}\<union>(X::'a set)))::'x set)" by simp
  2348   also have "\<dots> = (supp {x})\<union>(supp X)"
  2349     by (rule supp_fin_union[OF pt, OF at, OF fs], simp_all add: f)
  2350   finally show "(supp (insert x X)) = (supp x)\<union>((supp X)::'x set)" 
  2351     by (simp add: supp_singleton [OF pt at])
  2352 qed
  2353 
  2354 lemma fresh_fin_union:
  2355   fixes X::"('a set)"
  2356   and   Y::"('a set)"
  2357   and   a::"'x"
  2358   assumes pt: "pt TYPE('a) TYPE('x)"
  2359   and     at: "at TYPE('x)"
  2360   and     fs: "fs TYPE('a) TYPE('x)" 
  2361   and     f1: "finite X"
  2362   and     f2: "finite Y"
  2363   shows "a\<sharp>(X\<union>Y) = (a\<sharp>X \<and> a\<sharp>Y)"
  2364 apply(simp add: fresh_def)
  2365 apply(simp add: supp_fin_union[OF pt, OF at, OF fs, OF f1, OF f2])
  2366 done
  2367 
  2368 lemma fresh_fin_insert:
  2369   fixes X::"('a set)"
  2370   and   x::"'a"
  2371   and   a::"'x"
  2372   assumes pt: "pt TYPE('a) TYPE('x)"
  2373   and     at: "at TYPE('x)"
  2374   and     fs: "fs TYPE('a) TYPE('x)" 
  2375   and     f:  "finite X"
  2376   shows "a\<sharp>(insert x X) = (a\<sharp>x \<and> a\<sharp>X)"
  2377 apply(simp add: fresh_def)
  2378 apply(simp add: supp_fin_insert[OF pt, OF at, OF fs, OF f])
  2379 done
  2380 
  2381 lemma fresh_fin_insert1:
  2382   fixes X::"('a set)"
  2383   and   x::"'a"
  2384   and   a::"'x"
  2385   assumes pt: "pt TYPE('a) TYPE('x)"
  2386   and     at: "at TYPE('x)"
  2387   and     fs: "fs TYPE('a) TYPE('x)" 
  2388   and     f:  "finite X"
  2389   and     a1:  "a\<sharp>x"
  2390   and     a2:  "a\<sharp>X"
  2391   shows "a\<sharp>(insert x X)"
  2392   using a1 a2
  2393   by (simp add: fresh_fin_insert[OF pt, OF at, OF fs, OF f])
  2394 
  2395 lemma pt_list_set_supp:
  2396   fixes xs :: "'a list"
  2397   assumes pt: "pt TYPE('a) TYPE('x)"
  2398   and     at: "at TYPE('x)"
  2399   and     fs: "fs TYPE('a) TYPE('x)"
  2400   shows "supp (set xs) = ((supp xs)::'x set)"
  2401 proof -
  2402   have "supp (set xs) = (\<Union>x\<in>(set xs). ((supp x)::'x set))"
  2403     by (rule supp_of_fin_sets[OF pt, OF at, OF fs], rule finite_set)
  2404   also have "(\<Union>x\<in>(set xs). ((supp x)::'x set)) = (supp xs)"
  2405   proof(induct xs)
  2406     case Nil show ?case by (simp add: supp_list_nil)
  2407   next
  2408     case (Cons h t) thus ?case by (simp add: supp_list_cons)
  2409   qed
  2410   finally show ?thesis by simp
  2411 qed
  2412     
  2413 lemma pt_list_set_fresh:
  2414   fixes a :: "'x"
  2415   and   xs :: "'a list"
  2416   assumes pt: "pt TYPE('a) TYPE('x)"
  2417   and     at: "at TYPE('x)"
  2418   and     fs: "fs TYPE('a) TYPE('x)"
  2419   shows "a\<sharp>(set xs) = a\<sharp>xs"
  2420 by (simp add: fresh_def pt_list_set_supp[OF pt, OF at, OF fs])
  2421 
  2422 
  2423 section {* generalisation of freshness to lists and sets of atoms *}
  2424 (*================================================================*)
  2425  
  2426 consts
  2427   fresh_star :: "'b \<Rightarrow> 'a \<Rightarrow> bool" ("_ \<sharp>* _" [100,100] 100)
  2428 
  2429 defs (overloaded)
  2430   fresh_star_set: "xs\<sharp>*c \<equiv> \<forall>x\<in>xs. x\<sharp>c"
  2431 
  2432 defs (overloaded)
  2433   fresh_star_list: "xs\<sharp>*c \<equiv> \<forall>x\<in>set xs. x\<sharp>c"
  2434 
  2435 lemmas fresh_star_def = fresh_star_list fresh_star_set
  2436 
  2437 lemma fresh_star_prod_set:
  2438   fixes xs::"'a set"
  2439   shows "xs\<sharp>*(a,b) = (xs\<sharp>*a \<and> xs\<sharp>*b)"
  2440 by (auto simp add: fresh_star_def fresh_prod)
  2441 
  2442 lemma fresh_star_prod_list:
  2443   fixes xs::"'a list"
  2444   shows "xs\<sharp>*(a,b) = (xs\<sharp>*a \<and> xs\<sharp>*b)"
  2445   by (auto simp add: fresh_star_def fresh_prod)
  2446 
  2447 lemmas fresh_star_prod = fresh_star_prod_list fresh_star_prod_set
  2448 
  2449 lemma fresh_star_set_eq: "set xs \<sharp>* c = xs \<sharp>* c"
  2450   by (simp add: fresh_star_def)
  2451 
  2452 lemma fresh_star_Un_elim:
  2453   "((S \<union> T) \<sharp>* c \<Longrightarrow> PROP C) \<equiv> (S \<sharp>* c \<Longrightarrow> T \<sharp>* c \<Longrightarrow> PROP C)"
  2454   apply rule
  2455   apply (simp_all add: fresh_star_def)
  2456   apply (erule meta_mp)
  2457   apply blast
  2458   done
  2459 
  2460 lemma fresh_star_insert_elim:
  2461   "(insert x S \<sharp>* c \<Longrightarrow> PROP C) \<equiv> (x \<sharp> c \<Longrightarrow> S \<sharp>* c \<Longrightarrow> PROP C)"
  2462   by rule (simp_all add: fresh_star_def)
  2463 
  2464 lemma fresh_star_empty_elim:
  2465   "({} \<sharp>* c \<Longrightarrow> PROP C) \<equiv> PROP C"
  2466   by (simp add: fresh_star_def)
  2467 
  2468 text {* Normalization of freshness results; see \ @{text nominal_induct} *}
  2469 
  2470 lemma fresh_star_unit_elim: 
  2471   shows "((a::'a set)\<sharp>*() \<Longrightarrow> PROP C) \<equiv> PROP C"
  2472   and "((b::'a list)\<sharp>*() \<Longrightarrow> PROP C) \<equiv> PROP C"
  2473   by (simp_all add: fresh_star_def fresh_def supp_unit)
  2474 
  2475 lemma fresh_star_prod_elim: 
  2476   shows "((a::'a set)\<sharp>*(x,y) \<Longrightarrow> PROP C) \<equiv> (a\<sharp>*x \<Longrightarrow> a\<sharp>*y \<Longrightarrow> PROP C)"
  2477   and "((b::'a list)\<sharp>*(x,y) \<Longrightarrow> PROP C) \<equiv> (b\<sharp>*x \<Longrightarrow> b\<sharp>*y \<Longrightarrow> PROP C)"
  2478   by (rule, simp_all add: fresh_star_prod)+
  2479 
  2480 
  2481 lemma pt_fresh_star_bij_ineq:
  2482   fixes  pi :: "'x prm"
  2483   and     x :: "'a"
  2484   and     a :: "'y set"
  2485   and     b :: "'y list"
  2486   assumes pta: "pt TYPE('a) TYPE('x)"
  2487   and     ptb: "pt TYPE('y) TYPE('x)"
  2488   and     at:  "at TYPE('x)"
  2489   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  2490   shows "(pi\<bullet>a)\<sharp>*(pi\<bullet>x) = a\<sharp>*x"
  2491   and   "(pi\<bullet>b)\<sharp>*(pi\<bullet>x) = b\<sharp>*x"
  2492 apply(unfold fresh_star_def)
  2493 apply(auto)
  2494 apply(drule_tac x="pi\<bullet>xa" in bspec)
  2495 apply(erule pt_set_bij2[OF ptb, OF at])
  2496 apply(simp add: fresh_star_def pt_fresh_bij_ineq[OF pta, OF ptb, OF at, OF cp])
  2497 apply(drule_tac x="(rev pi)\<bullet>xa" in bspec)
  2498 apply(simp add: pt_set_bij1[OF ptb, OF at])
  2499 apply(simp add: pt_fresh_left_ineq[OF pta, OF ptb, OF at, OF cp])
  2500 apply(drule_tac x="pi\<bullet>xa" in bspec)
  2501 apply(simp add: pt_set_bij1[OF ptb, OF at])
  2502 apply(simp add: pt_set_eqvt [OF ptb at] pt_rev_pi[OF pt_list_inst[OF ptb], OF at])
  2503 apply(simp add: pt_fresh_bij_ineq[OF pta, OF ptb, OF at, OF cp])
  2504 apply(drule_tac x="(rev pi)\<bullet>xa" in bspec)
  2505 apply(simp add: pt_set_bij1[OF ptb, OF at] pt_set_eqvt [OF ptb at])
  2506 apply(simp add: pt_fresh_left_ineq[OF pta, OF ptb, OF at, OF cp])
  2507 done
  2508 
  2509 lemma pt_fresh_star_bij:
  2510   fixes  pi :: "'x prm"
  2511   and     x :: "'a"
  2512   and     a :: "'x set"
  2513   and     b :: "'x list"
  2514   assumes pt: "pt TYPE('a) TYPE('x)"
  2515   and     at: "at TYPE('x)"
  2516   shows "(pi\<bullet>a)\<sharp>*(pi\<bullet>x) = a\<sharp>*x"
  2517   and   "(pi\<bullet>b)\<sharp>*(pi\<bullet>x) = b\<sharp>*x"
  2518 apply(rule pt_fresh_star_bij_ineq(1))
  2519 apply(rule pt)
  2520 apply(rule at_pt_inst)
  2521 apply(rule at)+
  2522 apply(rule cp_pt_inst)
  2523 apply(rule pt)
  2524 apply(rule at)
  2525 apply(rule pt_fresh_star_bij_ineq(2))
  2526 apply(rule pt)
  2527 apply(rule at_pt_inst)
  2528 apply(rule at)+
  2529 apply(rule cp_pt_inst)
  2530 apply(rule pt)
  2531 apply(rule at)
  2532 done
  2533 
  2534 lemma pt_fresh_star_eqvt:
  2535   fixes  pi :: "'x prm"
  2536   and     x :: "'a"
  2537   and     a :: "'x set"
  2538   and     b :: "'x list"
  2539   assumes pt: "pt TYPE('a) TYPE('x)"
  2540   and     at: "at TYPE('x)"
  2541   shows "pi\<bullet>(a\<sharp>*x) = (pi\<bullet>a)\<sharp>*(pi\<bullet>x)"
  2542   and   "pi\<bullet>(b\<sharp>*x) = (pi\<bullet>b)\<sharp>*(pi\<bullet>x)"
  2543   by (simp_all add: perm_bool pt_fresh_star_bij[OF pt, OF at])
  2544 
  2545 lemma pt_fresh_star_eqvt_ineq:
  2546   fixes pi::"'x prm"
  2547   and   a::"'y set"
  2548   and   b::"'y list"
  2549   and   x::"'a"
  2550   assumes pta: "pt TYPE('a) TYPE('x)"
  2551   and     ptb: "pt TYPE('y) TYPE('x)"
  2552   and     at:  "at TYPE('x)"
  2553   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  2554   and     dj:  "disjoint TYPE('y) TYPE('x)"
  2555   shows "pi\<bullet>(a\<sharp>*x) = (pi\<bullet>a)\<sharp>*(pi\<bullet>x)"
  2556   and   "pi\<bullet>(b\<sharp>*x) = (pi\<bullet>b)\<sharp>*(pi\<bullet>x)"
  2557   by (simp_all add: pt_fresh_star_bij_ineq[OF pta, OF ptb, OF at, OF cp] dj_perm_forget[OF dj] perm_bool)
  2558 
  2559 lemma pt_freshs_freshs:
  2560   assumes pt: "pt TYPE('a) TYPE('x)"
  2561   and at: "at TYPE ('x)"
  2562   and pi: "set (pi::'x prm) \<subseteq> Xs \<times> Ys"
  2563   and Xs: "Xs \<sharp>* (x::'a)"
  2564   and Ys: "Ys \<sharp>* x"
  2565   shows "pi\<bullet>x = x"
  2566   using pi
  2567 proof (induct pi)
  2568   case Nil
  2569   show ?case by (simp add: pt1 [OF pt])
  2570 next
  2571   case (Cons p pi)
  2572   obtain a b where p: "p = (a, b)" by (cases p)
  2573   with Cons Xs Ys have "a \<sharp> x" "b \<sharp> x"
  2574     by (simp_all add: fresh_star_def)
  2575   with Cons p show ?case
  2576     by (simp add: pt_fresh_fresh [OF pt at]
  2577       pt2 [OF pt, of "[(a, b)]" pi, simplified])
  2578 qed
  2579 
  2580 lemma pt_fresh_star_pi: 
  2581   fixes x::"'a"
  2582   and   pi::"'x prm"
  2583   assumes pt: "pt TYPE('a) TYPE('x)"
  2584   and     at: "at TYPE('x)"
  2585   and     a: "((supp x)::'x set)\<sharp>* pi"
  2586   shows "pi\<bullet>x = x"
  2587 using a
  2588 apply(induct pi)
  2589 apply(auto simp add: fresh_star_def fresh_list_cons fresh_prod pt1[OF pt])
  2590 apply(subgoal_tac "((a,b)#pi)\<bullet>x = ([(a,b)]@pi)\<bullet>x")
  2591 apply(simp only: pt2[OF pt])
  2592 apply(rule pt_fresh_fresh[OF pt at])
  2593 apply(simp add: fresh_def at_supp[OF at])
  2594 apply(blast)
  2595 apply(simp add: fresh_def at_supp[OF at])
  2596 apply(blast)
  2597 apply(simp add: pt2[OF pt])
  2598 done
  2599 
  2600 section {* Infrastructure lemmas for strong rule inductions *}
  2601 (*==========================================================*)
  2602 
  2603 text {* 
  2604   For every set of atoms, there is another set of atoms
  2605   avoiding a finitely supported c and there is a permutation
  2606   which 'translates' between both sets.
  2607 *}
  2608 
  2609 lemma at_set_avoiding_aux:
  2610   fixes Xs::"'a set"
  2611   and   As::"'a set"
  2612   assumes at: "at TYPE('a)"
  2613   and     b: "Xs \<subseteq> As"
  2614   and     c: "finite As"
  2615   and     d: "finite ((supp c)::'a set)"
  2616   shows "\<exists>(pi::'a prm). (pi\<bullet>Xs)\<sharp>*c \<and> (pi\<bullet>Xs) \<inter> As = {} \<and> set pi \<subseteq> Xs \<times> (pi\<bullet>Xs)"
  2617 proof -
  2618   from b c have "finite Xs" by (simp add: finite_subset)
  2619   then show ?thesis using b 
  2620   proof (induct)
  2621     case empty
  2622     have "({}::'a set)\<sharp>*c" by (simp add: fresh_star_def)
  2623     moreover
  2624     have "({}::'a set) \<inter> As = {}" by simp
  2625     moreover
  2626     have "set ([]::'a prm) \<subseteq> {} \<times> {}" by simp
  2627     moreover
  2628     have "([]::'a prm)\<bullet>{} = ({}::'a set)" 
  2629       by (rule pt1[OF pt_fun_inst, OF at_pt_inst[OF at] pt_bool_inst at])
  2630     ultimately show ?case by simp
  2631   next
  2632     case (insert x Xs)
  2633     then have ih: "\<exists>pi. (pi\<bullet>Xs)\<sharp>*c \<and> (pi\<bullet>Xs) \<inter> As = {} \<and> set pi \<subseteq> Xs \<times> (pi\<bullet>Xs)" by simp
  2634     then obtain pi where a1: "(pi\<bullet>Xs)\<sharp>*c" and a2: "(pi\<bullet>Xs) \<inter> As = {}" and 
  2635       a4: "set pi \<subseteq> Xs \<times> (pi\<bullet>Xs)" by blast
  2636     have b: "x\<notin>Xs" by fact
  2637     have d1: "finite As" by fact
  2638     have d2: "finite Xs" by fact
  2639     have d3: "({x} \<union> Xs) \<subseteq> As" using insert(4) by simp
  2640     from d d1 d2
  2641     obtain y::"'a" where fr: "y\<sharp>(c,pi\<bullet>Xs,As)" 
  2642       apply(rule_tac at_exists_fresh[OF at, where x="(c,pi\<bullet>Xs,As)"])
  2643       apply(auto simp add: supp_prod at_supp[OF at] at_fin_set_supp[OF at]
  2644         pt_supp_finite_pi[OF pt_fun_inst[OF at_pt_inst[OF at] pt_bool_inst at] at])
  2645       done
  2646     have "({y}\<union>(pi\<bullet>Xs))\<sharp>*c" using a1 fr by (simp add: fresh_star_def)
  2647     moreover
  2648     have "({y}\<union>(pi\<bullet>Xs))\<inter>As = {}" using a2 d1 fr 
  2649       by (simp add: fresh_prod at_fin_set_fresh[OF at])
  2650     moreover
  2651     have "pi\<bullet>x=x" using a4 b a2 d3 
  2652       by (rule_tac at_prm_fresh2[OF at]) (auto)
  2653     then have "set ((pi\<bullet>x,y)#pi) \<subseteq> ({x} \<union> Xs) \<times> ({y}\<union>(pi\<bullet>Xs))" using a4 by auto
  2654     moreover
  2655     have "(((pi\<bullet>x,y)#pi)\<bullet>({x} \<union> Xs)) = {y}\<union>(pi\<bullet>Xs)"
  2656     proof -
  2657       have eq: "[(pi\<bullet>x,y)]\<bullet>(pi\<bullet>Xs) = (pi\<bullet>Xs)" 
  2658       proof -
  2659         have "(pi\<bullet>x)\<sharp>(pi\<bullet>Xs)" using b d2 
  2660           by(simp add: pt_fresh_bij[OF pt_fun_inst, OF at_pt_inst[OF at], 
  2661             OF pt_bool_inst, OF at, OF at]
  2662             at_fin_set_fresh[OF at])
  2663         moreover
  2664         have "y\<sharp>(pi\<bullet>Xs)" using fr by simp
  2665         ultimately show "[(pi\<bullet>x,y)]\<bullet>(pi\<bullet>Xs) = (pi\<bullet>Xs)" 
  2666           by (simp add: pt_fresh_fresh[OF pt_fun_inst, 
  2667             OF at_pt_inst[OF at], OF pt_bool_inst, OF at, OF at])
  2668       qed
  2669       have "(((pi\<bullet>x,y)#pi)\<bullet>({x}\<union>Xs)) = ([(pi\<bullet>x,y)]\<bullet>(pi\<bullet>({x}\<union>Xs)))"
  2670         by (simp add: pt2[symmetric, OF pt_fun_inst, OF at_pt_inst[OF at], 
  2671           OF pt_bool_inst, OF at])
  2672       also have "\<dots> = {y}\<union>([(pi\<bullet>x,y)]\<bullet>(pi\<bullet>Xs))" 
  2673         by (simp only: union_eqvt perm_set_eq[OF at_pt_inst[OF at], OF at] at_calc[OF at])(auto)
  2674       finally show "(((pi\<bullet>x,y)#pi)\<bullet>({x} \<union> Xs)) = {y}\<union>(pi\<bullet>Xs)" using eq by simp
  2675     qed
  2676     ultimately 
  2677     show ?case by (rule_tac x="(pi\<bullet>x,y)#pi" in exI) (auto)
  2678   qed
  2679 qed
  2680 
  2681 lemma at_set_avoiding:
  2682   fixes Xs::"'a set"
  2683   assumes at: "at TYPE('a)"
  2684   and     a: "finite Xs"
  2685   and     b: "finite ((supp c)::'a set)"
  2686   obtains pi::"'a prm" where "(pi\<bullet>Xs)\<sharp>*c" and "set pi \<subseteq> Xs \<times> (pi\<bullet>Xs)"
  2687 using a b at_set_avoiding_aux[OF at, where Xs="Xs" and As="Xs" and c="c"]
  2688 by (blast)
  2689 
  2690 section {* composition instances *}
  2691 (* ============================= *)
  2692 
  2693 lemma cp_list_inst:
  2694   assumes c1: "cp TYPE ('a) TYPE('x) TYPE('y)"
  2695   shows "cp TYPE ('a list) TYPE('x) TYPE('y)"
  2696 using c1
  2697 apply(simp add: cp_def)
  2698 apply(auto)
  2699 apply(induct_tac x)
  2700 apply(auto)
  2701 done
  2702 
  2703 lemma cp_option_inst:
  2704   assumes c1: "cp TYPE ('a) TYPE('x) TYPE('y)"
  2705   shows "cp TYPE ('a option) TYPE('x) TYPE('y)"
  2706 using c1
  2707 apply(simp add: cp_def)
  2708 apply(auto)
  2709 apply(case_tac x)
  2710 apply(auto)
  2711 done
  2712 
  2713 lemma cp_noption_inst:
  2714   assumes c1: "cp TYPE ('a) TYPE('x) TYPE('y)"
  2715   shows "cp TYPE ('a noption) TYPE('x) TYPE('y)"
  2716 using c1
  2717 apply(simp add: cp_def)
  2718 apply(auto)
  2719 apply(case_tac x)
  2720 apply(auto)
  2721 done
  2722 
  2723 lemma cp_unit_inst:
  2724   shows "cp TYPE (unit) TYPE('x) TYPE('y)"
  2725 apply(simp add: cp_def)
  2726 done
  2727 
  2728 lemma cp_bool_inst:
  2729   shows "cp TYPE (bool) TYPE('x) TYPE('y)"
  2730 apply(simp add: cp_def)
  2731 apply(rule allI)+
  2732 apply(induct_tac x)
  2733 apply(simp_all)
  2734 done
  2735 
  2736 lemma cp_prod_inst:
  2737   assumes c1: "cp TYPE ('a) TYPE('x) TYPE('y)"
  2738   and     c2: "cp TYPE ('b) TYPE('x) TYPE('y)"
  2739   shows "cp TYPE ('a\<times>'b) TYPE('x) TYPE('y)"
  2740 using c1 c2
  2741 apply(simp add: cp_def)
  2742 done
  2743 
  2744 lemma cp_fun_inst:
  2745   assumes c1: "cp TYPE ('a) TYPE('x) TYPE('y)"
  2746   and     c2: "cp TYPE ('b) TYPE('x) TYPE('y)"
  2747   and     pt: "pt TYPE ('y) TYPE('x)"
  2748   and     at: "at TYPE ('x)"
  2749   shows "cp TYPE ('a\<Rightarrow>'b) TYPE('x) TYPE('y)"
  2750 using c1 c2
  2751 apply(auto simp add: cp_def perm_fun_def fun_eq_iff)
  2752 apply(simp add: rev_eqvt[symmetric])
  2753 apply(simp add: pt_rev_pi[OF pt_list_inst[OF pt_prod_inst[OF pt, OF pt]], OF at])
  2754 done
  2755 
  2756 
  2757 section {* Andy's freshness lemma *}
  2758 (*================================*)
  2759 
  2760 lemma freshness_lemma:
  2761   fixes h :: "'x\<Rightarrow>'a"
  2762   assumes pta: "pt TYPE('a) TYPE('x)"
  2763   and     at:  "at TYPE('x)" 
  2764   and     f1:  "finite ((supp h)::'x set)"
  2765   and     a: "\<exists>a::'x. a\<sharp>(h,h a)"
  2766   shows  "\<exists>fr::'a. \<forall>a::'x. a\<sharp>h \<longrightarrow> (h a) = fr"
  2767 proof -
  2768   have ptb: "pt TYPE('x) TYPE('x)" by (simp add: at_pt_inst[OF at]) 
  2769   have ptc: "pt TYPE('x\<Rightarrow>'a) TYPE('x)" by (simp add: pt_fun_inst[OF ptb, OF pta, OF at]) 
  2770   from a obtain a0 where a1: "a0\<sharp>h" and a2: "a0\<sharp>(h a0)" by (force simp add: fresh_prod)
  2771   show ?thesis
  2772   proof
  2773     let ?fr = "h (a0::'x)"
  2774     show "\<forall>(a::'x). (a\<sharp>h \<longrightarrow> ((h a) = ?fr))" 
  2775     proof (intro strip)
  2776       fix a
  2777       assume a3: "(a::'x)\<sharp>h"
  2778       show "h (a::'x) = h a0"
  2779       proof (cases "a=a0")
  2780         case True thus "h (a::'x) = h a0" by simp
  2781       next
  2782         case False 
  2783         assume "a\<noteq>a0"
  2784         hence c1: "a\<notin>((supp a0)::'x set)" by  (simp add: fresh_def[symmetric] at_fresh[OF at])
  2785         have c2: "a\<notin>((supp h)::'x set)" using a3 by (simp add: fresh_def)
  2786         from c1 c2 have c3: "a\<notin>((supp h)\<union>((supp a0)::'x set))" by force
  2787         have f2: "finite ((supp a0)::'x set)" by (simp add: at_supp[OF at])
  2788         from f1 f2 have "((supp (h a0))::'x set)\<subseteq>((supp h)\<union>(supp a0))"
  2789           by (simp add: pt_supp_fun_subset[OF ptb, OF pta, OF at])
  2790         hence "a\<notin>((supp (h a0))::'x set)" using c3 by force
  2791         hence "a\<sharp>(h a0)" by (simp add: fresh_def) 
  2792         with a2 have d1: "[(a0,a)]\<bullet>(h a0) = (h a0)" by (rule pt_fresh_fresh[OF pta, OF at])
  2793         from a1 a3 have d2: "[(a0,a)]\<bullet>h = h" by (rule pt_fresh_fresh[OF ptc, OF at])
  2794         from d1 have "h a0 = [(a0,a)]\<bullet>(h a0)" by simp
  2795         also have "\<dots>= ([(a0,a)]\<bullet>h)([(a0,a)]\<bullet>a0)" by (simp add: pt_fun_app_eq[OF ptb, OF at])
  2796         also have "\<dots> = h ([(a0,a)]\<bullet>a0)" using d2 by simp
  2797         also have "\<dots> = h a" by (simp add: at_calc[OF at])
  2798         finally show "h a = h a0" by simp
  2799       qed
  2800     qed
  2801   qed
  2802 qed
  2803 
  2804 lemma freshness_lemma_unique:
  2805   fixes h :: "'x\<Rightarrow>'a"
  2806   assumes pt: "pt TYPE('a) TYPE('x)"
  2807   and     at: "at TYPE('x)" 
  2808   and     f1: "finite ((supp h)::'x set)"
  2809   and     a: "\<exists>(a::'x). a\<sharp>(h,h a)"
  2810   shows  "\<exists>!(fr::'a). \<forall>(a::'x). a\<sharp>h \<longrightarrow> (h a) = fr"
  2811 proof (rule ex_ex1I)
  2812   from pt at f1 a show "\<exists>fr::'a. \<forall>a::'x. a\<sharp>h \<longrightarrow> h a = fr" by (simp add: freshness_lemma)
  2813 next
  2814   fix fr1 fr2
  2815   assume b1: "\<forall>a::'x. a\<sharp>h \<longrightarrow> h a = fr1"
  2816   assume b2: "\<forall>a::'x. a\<sharp>h \<longrightarrow> h a = fr2"
  2817   from a obtain a where "(a::'x)\<sharp>h" by (force simp add: fresh_prod) 
  2818   with b1 b2 have "h a = fr1 \<and> h a = fr2" by force
  2819   thus "fr1 = fr2" by force
  2820 qed
  2821 
  2822 -- "packaging the freshness lemma into a function"
  2823 definition fresh_fun :: "('x\<Rightarrow>'a)\<Rightarrow>'a" where
  2824   "fresh_fun (h) \<equiv> THE fr. (\<forall>(a::'x). a\<sharp>h \<longrightarrow> (h a) = fr)"
  2825 
  2826 lemma fresh_fun_app:
  2827   fixes h :: "'x\<Rightarrow>'a"
  2828   and   a :: "'x"
  2829   assumes pt: "pt TYPE('a) TYPE('x)"
  2830   and     at: "at TYPE('x)" 
  2831   and     f1: "finite ((supp h)::'x set)"
  2832   and     a: "\<exists>(a::'x). a\<sharp>(h,h a)"
  2833   and     b: "a\<sharp>h"
  2834   shows "(fresh_fun h) = (h a)"
  2835 proof (unfold fresh_fun_def, rule the_equality)
  2836   show "\<forall>(a'::'x). a'\<sharp>h \<longrightarrow> h a' = h a"
  2837   proof (intro strip)
  2838     fix a'::"'x"
  2839     assume c: "a'\<sharp>h"
  2840     from pt at f1 a have "\<exists>(fr::'a). \<forall>(a::'x). a\<sharp>h \<longrightarrow> (h a) = fr" by (rule freshness_lemma)
  2841     with b c show "h a' = h a" by force
  2842   qed
  2843 next
  2844   fix fr::"'a"
  2845   assume "\<forall>a. a\<sharp>h \<longrightarrow> h a = fr"
  2846   with b show "fr = h a" by force
  2847 qed
  2848 
  2849 lemma fresh_fun_app':
  2850   fixes h :: "'x\<Rightarrow>'a"
  2851   and   a :: "'x"
  2852   assumes pt: "pt TYPE('a) TYPE('x)"
  2853   and     at: "at TYPE('x)" 
  2854   and     f1: "finite ((supp h)::'x set)"
  2855   and     a: "a\<sharp>h" "a\<sharp>h a"
  2856   shows "(fresh_fun h) = (h a)"
  2857 apply(rule fresh_fun_app[OF pt, OF at, OF f1])
  2858 apply(auto simp add: fresh_prod intro: a)
  2859 done
  2860 
  2861 lemma fresh_fun_equiv_ineq:
  2862   fixes h :: "'y\<Rightarrow>'a"
  2863   and   pi:: "'x prm"
  2864   assumes pta: "pt TYPE('a) TYPE('x)"
  2865   and     ptb: "pt TYPE('y) TYPE('x)"
  2866   and     ptb':"pt TYPE('a) TYPE('y)"
  2867   and     at:  "at TYPE('x)" 
  2868   and     at': "at TYPE('y)"
  2869   and     cpa: "cp TYPE('a) TYPE('x) TYPE('y)"
  2870   and     cpb: "cp TYPE('y) TYPE('x) TYPE('y)"
  2871   and     f1: "finite ((supp h)::'y set)"
  2872   and     a1: "\<exists>(a::'y). a\<sharp>(h,h a)"
  2873   shows "pi\<bullet>(fresh_fun h) = fresh_fun(pi\<bullet>h)" (is "?LHS = ?RHS")
  2874 proof -
  2875   have ptd: "pt TYPE('y) TYPE('y)" by (simp add: at_pt_inst[OF at']) 
  2876   have ptc: "pt TYPE('y\<Rightarrow>'a) TYPE('x)" by (simp add: pt_fun_inst[OF ptb, OF pta, OF at]) 
  2877   have cpc: "cp TYPE('y\<Rightarrow>'a) TYPE ('x) TYPE ('y)" by (rule cp_fun_inst[OF cpb cpa ptb at])
  2878   have f2: "finite ((supp (pi\<bullet>h))::'y set)"
  2879   proof -
  2880     from f1 have "finite (pi\<bullet>((supp h)::'y set))"
  2881       by (simp add: pt_set_finite_ineq[OF ptb, OF at])
  2882     thus ?thesis
  2883       by (simp add: pt_perm_supp_ineq[OF ptc, OF ptb, OF at, OF cpc])
  2884   qed
  2885   from a1 obtain a' where c0: "a'\<sharp>(h,h a')" by force
  2886   hence c1: "a'\<sharp>h" and c2: "a'\<sharp>(h a')" by (simp_all add: fresh_prod)
  2887   have c3: "(pi\<bullet>a')\<sharp>(pi\<bullet>h)" using c1
  2888   by (simp add: pt_fresh_bij_ineq[OF ptc, OF ptb, OF at, OF cpc])
  2889   have c4: "(pi\<bullet>a')\<sharp>(pi\<bullet>h) (pi\<bullet>a')"
  2890   proof -
  2891     from c2 have "(pi\<bullet>a')\<sharp>(pi\<bullet>(h a'))"
  2892       by (simp add: pt_fresh_bij_ineq[OF pta, OF ptb, OF at,OF cpa])
  2893     thus ?thesis by (simp add: pt_fun_app_eq[OF ptb, OF at])
  2894   qed
  2895   have a2: "\<exists>(a::'y). a\<sharp>(pi\<bullet>h,(pi\<bullet>h) a)" using c3 c4 by (force simp add: fresh_prod)
  2896   have d1: "?LHS = pi\<bullet>(h a')" using c1 a1 by (simp add: fresh_fun_app[OF ptb', OF at', OF f1])
  2897   have d2: "?RHS = (pi\<bullet>h) (pi\<bullet>a')" using c3 a2 
  2898     by (simp add: fresh_fun_app[OF ptb', OF at', OF f2])
  2899   show ?thesis using d1 d2 by (simp add: pt_fun_app_eq[OF ptb, OF at])
  2900 qed
  2901 
  2902 lemma fresh_fun_equiv:
  2903   fixes h :: "'x\<Rightarrow>'a"
  2904   and   pi:: "'x prm"
  2905   assumes pta: "pt TYPE('a) TYPE('x)"
  2906   and     at:  "at TYPE('x)" 
  2907   and     f1:  "finite ((supp h)::'x set)"
  2908   and     a1: "\<exists>(a::'x). a\<sharp>(h,h a)"
  2909   shows "pi\<bullet>(fresh_fun h) = fresh_fun(pi\<bullet>h)" (is "?LHS = ?RHS")
  2910 proof -
  2911   have ptb: "pt TYPE('x) TYPE('x)" by (simp add: at_pt_inst[OF at]) 
  2912   have ptc: "pt TYPE('x\<Rightarrow>'a) TYPE('x)" by (simp add: pt_fun_inst[OF ptb, OF pta, OF at]) 
  2913   have f2: "finite ((supp (pi\<bullet>h))::'x set)"
  2914   proof -
  2915     from f1 have "finite (pi\<bullet>((supp h)::'x set))" by (simp add: pt_set_finite_ineq[OF ptb, OF at])
  2916     thus ?thesis by (simp add: pt_perm_supp[OF ptc, OF at])
  2917   qed
  2918   from a1 obtain a' where c0: "a'\<sharp>(h,h a')" by force
  2919   hence c1: "a'\<sharp>h" and c2: "a'\<sharp>(h a')" by (simp_all add: fresh_prod)
  2920   have c3: "(pi\<bullet>a')\<sharp>(pi\<bullet>h)" using c1 by (simp add: pt_fresh_bij[OF ptc, OF at])
  2921   have c4: "(pi\<bullet>a')\<sharp>(pi\<bullet>h) (pi\<bullet>a')"
  2922   proof -
  2923     from c2 have "(pi\<bullet>a')\<sharp>(pi\<bullet>(h a'))" by (simp add: pt_fresh_bij[OF pta, OF at])
  2924     thus ?thesis by (simp add: pt_fun_app_eq[OF ptb, OF at])
  2925   qed
  2926   have a2: "\<exists>(a::'x). a\<sharp>(pi\<bullet>h,(pi\<bullet>h) a)" using c3 c4 by (force simp add: fresh_prod)
  2927   have d1: "?LHS = pi\<bullet>(h a')" using c1 a1 by (simp add: fresh_fun_app[OF pta, OF at, OF f1])
  2928   have d2: "?RHS = (pi\<bullet>h) (pi\<bullet>a')" using c3 a2 by (simp add: fresh_fun_app[OF pta, OF at, OF f2])
  2929   show ?thesis using d1 d2 by (simp add: pt_fun_app_eq[OF ptb, OF at])
  2930 qed
  2931 
  2932 lemma fresh_fun_supports:
  2933   fixes h :: "'x\<Rightarrow>'a"
  2934   assumes pt: "pt TYPE('a) TYPE('x)"
  2935   and     at: "at TYPE('x)" 
  2936   and     f1: "finite ((supp h)::'x set)"
  2937   and     a: "\<exists>(a::'x). a\<sharp>(h,h a)"
  2938   shows "((supp h)::'x set) supports (fresh_fun h)"
  2939   apply(simp add: supports_def fresh_def[symmetric])
  2940   apply(auto)
  2941   apply(simp add: fresh_fun_equiv[OF pt, OF at, OF f1, OF a])
  2942   apply(simp add: pt_fresh_fresh[OF pt_fun_inst[OF at_pt_inst[OF at], OF pt], OF at, OF at])
  2943   done
  2944   
  2945 section {* Abstraction function *}
  2946 (*==============================*)
  2947 
  2948 lemma pt_abs_fun_inst:
  2949   assumes pt: "pt TYPE('a) TYPE('x)"
  2950   and     at: "at TYPE('x)"
  2951   shows "pt TYPE('x\<Rightarrow>('a noption)) TYPE('x)"
  2952   by (rule pt_fun_inst[OF at_pt_inst[OF at],OF pt_noption_inst[OF pt],OF at])
  2953 
  2954 definition abs_fun :: "'x\<Rightarrow>'a\<Rightarrow>('x\<Rightarrow>('a noption))" ("[_]._" [100,100] 100) where 
  2955   "[a].x \<equiv> (\<lambda>b. (if b=a then nSome(x) else (if b\<sharp>x then nSome([(a,b)]\<bullet>x) else nNone)))"
  2956 
  2957 (* FIXME: should be called perm_if and placed close to the definition of permutations on bools *)
  2958 lemma abs_fun_if: 
  2959   fixes pi :: "'x prm"
  2960   and   x  :: "'a"
  2961   and   y  :: "'a"
  2962   and   c  :: "bool"
  2963   shows "pi\<bullet>(if c then x else y) = (if c then (pi\<bullet>x) else (pi\<bullet>y))"   
  2964   by force
  2965 
  2966 lemma abs_fun_pi_ineq:
  2967   fixes a  :: "'y"
  2968   and   x  :: "'a"
  2969   and   pi :: "'x prm"
  2970   assumes pta: "pt TYPE('a) TYPE('x)"
  2971   and     ptb: "pt TYPE('y) TYPE('x)"
  2972   and     at:  "at TYPE('x)"
  2973   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  2974   shows "pi\<bullet>([a].x) = [(pi\<bullet>a)].(pi\<bullet>x)"
  2975   apply(simp add: abs_fun_def perm_fun_def abs_fun_if)
  2976   apply(simp only: fun_eq_iff)
  2977   apply(rule allI)
  2978   apply(subgoal_tac "(((rev pi)\<bullet>(xa::'y)) = (a::'y)) = (xa = pi\<bullet>a)")(*A*)
  2979   apply(subgoal_tac "(((rev pi)\<bullet>xa)\<sharp>x) = (xa\<sharp>(pi\<bullet>x))")(*B*)
  2980   apply(subgoal_tac "pi\<bullet>([(a,(rev pi)\<bullet>xa)]\<bullet>x) = [(pi\<bullet>a,xa)]\<bullet>(pi\<bullet>x)")(*C*)
  2981   apply(simp)
  2982 (*C*)
  2983   apply(simp add: cp1[OF cp])
  2984   apply(simp add: pt_pi_rev[OF ptb, OF at])
  2985 (*B*)
  2986   apply(simp add: pt_fresh_left_ineq[OF pta, OF ptb, OF at, OF cp])
  2987 (*A*)
  2988   apply(rule iffI)
  2989   apply(rule pt_bij2[OF ptb, OF at, THEN sym])
  2990   apply(simp)
  2991   apply(rule pt_bij2[OF ptb, OF at])
  2992   apply(simp)
  2993 done
  2994 
  2995 lemma abs_fun_pi:
  2996   fixes a  :: "'x"
  2997   and   x  :: "'a"
  2998   and   pi :: "'x prm"
  2999   assumes pt: "pt TYPE('a) TYPE('x)"
  3000   and     at: "at TYPE('x)"
  3001   shows "pi\<bullet>([a].x) = [(pi\<bullet>a)].(pi\<bullet>x)"
  3002 apply(rule abs_fun_pi_ineq)
  3003 apply(rule pt)
  3004 apply(rule at_pt_inst)
  3005 apply(rule at)+
  3006 apply(rule cp_pt_inst)
  3007 apply(rule pt)
  3008 apply(rule at)
  3009 done
  3010 
  3011 lemma abs_fun_eq1: 
  3012   fixes x  :: "'a"
  3013   and   y  :: "'a"
  3014   and   a  :: "'x"
  3015   shows "([a].x = [a].y) = (x = y)"
  3016 apply(auto simp add: abs_fun_def)
  3017 apply(auto simp add: fun_eq_iff)
  3018 apply(drule_tac x="a" in spec)
  3019 apply(simp)
  3020 done
  3021 
  3022 lemma abs_fun_eq2:
  3023   fixes x  :: "'a"
  3024   and   y  :: "'a"
  3025   and   a  :: "'x"
  3026   and   b  :: "'x"
  3027   assumes pt: "pt TYPE('a) TYPE('x)"
  3028       and at: "at TYPE('x)"
  3029       and a1: "a\<noteq>b" 
  3030       and a2: "[a].x = [b].y" 
  3031   shows "x=[(a,b)]\<bullet>y \<and> a\<sharp>y"
  3032 proof -
  3033   from a2 have "\<forall>c::'x. ([a].x) c = ([b].y) c" by (force simp add: fun_eq_iff)
  3034   hence "([a].x) a = ([b].y) a" by simp
  3035   hence a3: "nSome(x) = ([b].y) a" by (simp add: abs_fun_def)
  3036   show "x=[(a,b)]\<bullet>y \<and> a\<sharp>y"
  3037   proof (cases "a\<sharp>y")
  3038     assume a4: "a\<sharp>y"
  3039     hence "x=[(b,a)]\<bullet>y" using a3 a1 by (simp add: abs_fun_def)
  3040     moreover
  3041     have "[(a,b)]\<bullet>y = [(b,a)]\<bullet>y" by (rule pt3[OF pt], rule at_ds5[OF at])
  3042     ultimately show ?thesis using a4 by simp
  3043   next
  3044     assume "\<not>a\<sharp>y"
  3045     hence "nSome(x) = nNone" using a1 a3 by (simp add: abs_fun_def)
  3046     hence False by simp
  3047     thus ?thesis by simp
  3048   qed
  3049 qed
  3050 
  3051 lemma abs_fun_eq3: 
  3052   fixes x  :: "'a"
  3053   and   y  :: "'a"
  3054   and   a   :: "'x"
  3055   and   b   :: "'x"
  3056   assumes pt: "pt TYPE('a) TYPE('x)"
  3057       and at: "at TYPE('x)"
  3058       and a1: "a\<noteq>b" 
  3059       and a2: "x=[(a,b)]\<bullet>y" 
  3060       and a3: "a\<sharp>y" 
  3061   shows "[a].x =[b].y"
  3062 proof -
  3063   show ?thesis 
  3064   proof (simp only: abs_fun_def fun_eq_iff, intro strip)
  3065     fix c::"'x"
  3066     let ?LHS = "if c=a then nSome(x) else if c\<sharp>x then nSome([(a,c)]\<bullet>x) else nNone"
  3067     and ?RHS = "if c=b then nSome(y) else if c\<sharp>y then nSome([(b,c)]\<bullet>y) else nNone"
  3068     show "?LHS=?RHS"
  3069     proof -
  3070       have "(c=a) \<or> (c=b) \<or> (c\<noteq>a \<and> c\<noteq>b)" by blast
  3071       moreover  --"case c=a"
  3072       { have "nSome(x) = nSome([(a,b)]\<bullet>y)" using a2 by simp
  3073         also have "\<dots> = nSome([(b,a)]\<bullet>y)" by (simp, rule pt3[OF pt], rule at_ds5[OF at])
  3074         finally have "nSome(x) = nSome([(b,a)]\<bullet>y)" by simp
  3075         moreover
  3076         assume "c=a"
  3077         ultimately have "?LHS=?RHS" using a1 a3 by simp
  3078       }
  3079       moreover  -- "case c=b"
  3080       { have a4: "y=[(a,b)]\<bullet>x" using a2 by (simp only: pt_swap_bij[OF pt, OF at])
  3081         hence "a\<sharp>([(a,b)]\<bullet>x)" using a3 by simp
  3082         hence "b\<sharp>x" by (simp add: at_calc[OF at] pt_fresh_left[OF pt, OF at])
  3083         moreover
  3084         assume "c=b"
  3085         ultimately have "?LHS=?RHS" using a1 a4 by simp
  3086       }
  3087       moreover  -- "case c\<noteq>a \<and> c\<noteq>b"
  3088       { assume a5: "c\<noteq>a \<and> c\<noteq>b"
  3089         moreover 
  3090         have "c\<sharp>x = c\<sharp>y" using a2 a5 by (force simp add: at_calc[OF at] pt_fresh_left[OF pt, OF at])
  3091         moreover 
  3092         have "c\<sharp>y \<longrightarrow> [(a,c)]\<bullet>x = [(b,c)]\<bullet>y" 
  3093         proof (intro strip)
  3094           assume a6: "c\<sharp>y"
  3095           have "[(a,c),(b,c),(a,c)] \<triangleq> [(a,b)]" using a1 a5 by (force intro: at_ds3[OF at])
  3096           hence "[(a,c)]\<bullet>([(b,c)]\<bullet>([(a,c)]\<bullet>y)) = [(a,b)]\<bullet>y" 
  3097             by (simp add: pt2[OF pt, symmetric] pt3[OF pt])
  3098           hence "[(a,c)]\<bullet>([(b,c)]\<bullet>y) = [(a,b)]\<bullet>y" using a3 a6 
  3099             by (simp add: pt_fresh_fresh[OF pt, OF at])
  3100           hence "[(a,c)]\<bullet>([(b,c)]\<bullet>y) = x" using a2 by simp
  3101           hence "[(b,c)]\<bullet>y = [(a,c)]\<bullet>x" by (drule_tac pt_bij1[OF pt, OF at], simp)
  3102           thus "[(a,c)]\<bullet>x = [(b,c)]\<bullet>y" by simp
  3103         qed
  3104         ultimately have "?LHS=?RHS" by simp
  3105       }
  3106       ultimately show "?LHS = ?RHS" by blast
  3107     qed
  3108   qed
  3109 qed
  3110         
  3111 (* alpha equivalence *)
  3112 lemma abs_fun_eq: 
  3113   fixes x  :: "'a"
  3114   and   y  :: "'a"
  3115   and   a  :: "'x"
  3116   and   b  :: "'x"
  3117   assumes pt: "pt TYPE('a) TYPE('x)"
  3118       and at: "at TYPE('x)"
  3119   shows "([a].x = [b].y) = ((a=b \<and> x=y)\<or>(a\<noteq>b \<and> x=[(a,b)]\<bullet>y \<and> a\<sharp>y))"
  3120 proof (rule iffI)
  3121   assume b: "[a].x = [b].y"
  3122   show "(a=b \<and> x=y)\<or>(a\<noteq>b \<and> x=[(a,b)]\<bullet>y \<and> a\<sharp>y)"
  3123   proof (cases "a=b")
  3124     case True with b show ?thesis by (simp add: abs_fun_eq1)
  3125   next
  3126     case False with b show ?thesis by (simp add: abs_fun_eq2[OF pt, OF at])
  3127   qed
  3128 next
  3129   assume "(a=b \<and> x=y)\<or>(a\<noteq>b \<and> x=[(a,b)]\<bullet>y \<and> a\<sharp>y)"
  3130   thus "[a].x = [b].y"
  3131   proof
  3132     assume "a=b \<and> x=y" thus ?thesis by simp
  3133   next
  3134     assume "a\<noteq>b \<and> x=[(a,b)]\<bullet>y \<and> a\<sharp>y" 
  3135     thus ?thesis by (simp add: abs_fun_eq3[OF pt, OF at])
  3136   qed
  3137 qed
  3138 
  3139 (* symmetric version of alpha-equivalence *)
  3140 lemma abs_fun_eq': 
  3141   fixes x  :: "'a"
  3142   and   y  :: "'a"
  3143   and   a  :: "'x"
  3144   and   b  :: "'x"
  3145   assumes pt: "pt TYPE('a) TYPE('x)"
  3146       and at: "at TYPE('x)"
  3147   shows "([a].x = [b].y) = ((a=b \<and> x=y)\<or>(a\<noteq>b \<and> [(b,a)]\<bullet>x=y \<and> b\<sharp>x))"
  3148 by (auto simp add: abs_fun_eq[OF pt, OF at] pt_swap_bij'[OF pt, OF at] 
  3149                    pt_fresh_left[OF pt, OF at] 
  3150                    at_calc[OF at])
  3151 
  3152 (* alpha_equivalence with a fresh name *)
  3153 lemma abs_fun_fresh: 
  3154   fixes x :: "'a"
  3155   and   y :: "'a"
  3156   and   c :: "'x"
  3157   and   a :: "'x"
  3158   and   b :: "'x"
  3159   assumes pt: "pt TYPE('a) TYPE('x)"
  3160       and at: "at TYPE('x)"
  3161       and fr: "c\<noteq>a" "c\<noteq>b" "c\<sharp>x" "c\<sharp>y" 
  3162   shows "([a].x = [b].y) = ([(a,c)]\<bullet>x = [(b,c)]\<bullet>y)"
  3163 proof (rule iffI)
  3164   assume eq0: "[a].x = [b].y"
  3165   show "[(a,c)]\<bullet>x = [(b,c)]\<bullet>y"
  3166   proof (cases "a=b")
  3167     case True then show ?thesis using eq0 by (simp add: pt_bij[OF pt, OF at] abs_fun_eq[OF pt, OF at])
  3168   next
  3169     case False 
  3170     have ineq: "a\<noteq>b" by fact
  3171     with eq0 have eq: "x=[(a,b)]\<bullet>y" and fr': "a\<sharp>y" by (simp_all add: abs_fun_eq[OF pt, OF at])
  3172     from eq have "[(a,c)]\<bullet>x = [(a,c)]\<bullet>[(a,b)]\<bullet>y" by (simp add: pt_bij[OF pt, OF at])
  3173     also have "\<dots> = ([(a,c)]\<bullet>[(a,b)])\<bullet>([(a,c)]\<bullet>y)" by (rule pt_perm_compose[OF pt, OF at])
  3174     also have "\<dots> = [(c,b)]\<bullet>y" using ineq fr fr' 
  3175       by (simp add: pt_fresh_fresh[OF pt, OF at] at_calc[OF at])
  3176     also have "\<dots> = [(b,c)]\<bullet>y" by (rule pt3[OF pt], rule at_ds5[OF at])
  3177     finally show ?thesis by simp
  3178   qed
  3179 next
  3180   assume eq: "[(a,c)]\<bullet>x = [(b,c)]\<bullet>y"
  3181   thus "[a].x = [b].y"
  3182   proof (cases "a=b")
  3183     case True then show ?thesis using eq by (simp add: pt_bij[OF pt, OF at] abs_fun_eq[OF pt, OF at])
  3184   next
  3185     case False
  3186     have ineq: "a\<noteq>b" by fact
  3187     from fr have "([(a,c)]\<bullet>c)\<sharp>([(a,c)]\<bullet>x)" by (simp add: pt_fresh_bij[OF pt, OF at])
  3188     hence "a\<sharp>([(b,c)]\<bullet>y)" using eq fr by (simp add: at_calc[OF at])
  3189     hence fr0: "a\<sharp>y" using ineq fr by (simp add: pt_fresh_left[OF pt, OF at] at_calc[OF at])
  3190     from eq have "x = (rev [(a,c)])\<bullet>([(b,c)]\<bullet>y)" by (rule pt_bij1[OF pt, OF at])
  3191     also have "\<dots> = [(a,c)]\<bullet>([(b,c)]\<bullet>y)" by simp
  3192     also have "\<dots> = ([(a,c)]\<bullet>[(b,c)])\<bullet>([(a,c)]\<bullet>y)" by (rule pt_perm_compose[OF pt, OF at])
  3193     also have "\<dots> = [(b,a)]\<bullet>y" using ineq fr fr0  
  3194       by (simp add: pt_fresh_fresh[OF pt, OF at] at_calc[OF at])
  3195     also have "\<dots> = [(a,b)]\<bullet>y" by (rule pt3[OF pt], rule at_ds5[OF at])
  3196     finally show ?thesis using ineq fr0 by (simp add: abs_fun_eq[OF pt, OF at])
  3197   qed
  3198 qed
  3199 
  3200 lemma abs_fun_fresh': 
  3201   fixes x :: "'a"
  3202   and   y :: "'a"
  3203   and   c :: "'x"
  3204   and   a :: "'x"
  3205   and   b :: "'x"
  3206   assumes pt: "pt TYPE('a) TYPE('x)"
  3207       and at: "at TYPE('x)"
  3208       and as: "[a].x = [b].y"
  3209       and fr: "c\<noteq>a" "c\<noteq>b" "c\<sharp>x" "c\<sharp>y" 
  3210   shows "x = [(a,c)]\<bullet>[(b,c)]\<bullet>y"
  3211 using as fr
  3212 apply(drule_tac sym)
  3213 apply(simp add: abs_fun_fresh[OF pt, OF at] pt_swap_bij[OF pt, OF at])
  3214 done
  3215 
  3216 lemma abs_fun_supp_approx:
  3217   fixes x :: "'a"
  3218   and   a :: "'x"
  3219   assumes pt: "pt TYPE('a) TYPE('x)"
  3220   and     at: "at TYPE('x)"
  3221   shows "((supp ([a].x))::'x set) \<subseteq> (supp (x,a))"
  3222 proof 
  3223   fix c
  3224   assume "c\<in>((supp ([a].x))::'x set)"
  3225   hence "infinite {b. [(c,b)]\<bullet>([a].x) \<noteq> [a].x}" by (simp add: supp_def)
  3226   hence "infinite {b. [([(c,b)]\<bullet>a)].([(c,b)]\<bullet>x) \<noteq> [a].x}" by (simp add: abs_fun_pi[OF pt, OF at])
  3227   moreover
  3228   have "{b. [([(c,b)]\<bullet>a)].([(c,b)]\<bullet>x) \<noteq> [a].x} \<subseteq> {b. ([(c,b)]\<bullet>x,[(c,b)]\<bullet>a) \<noteq> (x, a)}" by force
  3229   ultimately have "infinite {b. ([(c,b)]\<bullet>x,[(c,b)]\<bullet>a) \<noteq> (x, a)}" by (simp add: infinite_super)
  3230   thus "c\<in>(supp (x,a))" by (simp add: supp_def)
  3231 qed
  3232 
  3233 lemma abs_fun_finite_supp:
  3234   fixes x :: "'a"
  3235   and   a :: "'x"
  3236   assumes pt: "pt TYPE('a) TYPE('x)"
  3237   and     at: "at TYPE('x)"
  3238   and     f:  "finite ((supp x)::'x set)"
  3239   shows "finite ((supp ([a].x))::'x set)"
  3240 proof -
  3241   from f have "finite ((supp (x,a))::'x set)" by (simp add: supp_prod at_supp[OF at])
  3242   moreover
  3243   have "((supp ([a].x))::'x set) \<subseteq> (supp (x,a))" by (rule abs_fun_supp_approx[OF pt, OF at])
  3244   ultimately show ?thesis by (simp add: finite_subset)
  3245 qed
  3246 
  3247 lemma fresh_abs_funI1:
  3248   fixes  x :: "'a"
  3249   and    a :: "'x"
  3250   and    b :: "'x"
  3251   assumes pt:  "pt TYPE('a) TYPE('x)"
  3252   and     at:   "at TYPE('x)"
  3253   and f:  "finite ((supp x)::'x set)"
  3254   and a1: "b\<sharp>x" 
  3255   and a2: "a\<noteq>b"
  3256   shows "b\<sharp>([a].x)"
  3257   proof -
  3258     have "\<exists>c::'x. c\<sharp>(b,a,x,[a].x)" 
  3259     proof (rule at_exists_fresh'[OF at], auto simp add: supp_prod at_supp[OF at] f)
  3260       show "finite ((supp ([a].x))::'x set)" using f
  3261         by (simp add: abs_fun_finite_supp[OF pt, OF at])        
  3262     qed
  3263     then obtain c where fr1: "c\<noteq>b"
  3264                   and   fr2: "c\<noteq>a"
  3265                   and   fr3: "c\<sharp>x"
  3266                   and   fr4: "c\<sharp>([a].x)"
  3267                   by (force simp add: fresh_prod at_fresh[OF at])
  3268     have e: "[(c,b)]\<bullet>([a].x) = [a].([(c,b)]\<bullet>x)" using a2 fr1 fr2 
  3269       by (force simp add: abs_fun_pi[OF pt, OF at] at_calc[OF at])
  3270     from fr4 have "([(c,b)]\<bullet>c)\<sharp> ([(c,b)]\<bullet>([a].x))"
  3271       by (simp add: pt_fresh_bij[OF pt_abs_fun_inst[OF pt, OF at], OF at])
  3272     hence "b\<sharp>([a].([(c,b)]\<bullet>x))" using fr1 fr2 e  
  3273       by (simp add: at_calc[OF at])
  3274     thus ?thesis using a1 fr3 
  3275       by (simp add: pt_fresh_fresh[OF pt, OF at])
  3276 qed
  3277 
  3278 lemma fresh_abs_funE:
  3279   fixes a :: "'x"
  3280   and   b :: "'x"
  3281   and   x :: "'a"
  3282   assumes pt:  "pt TYPE('a) TYPE('x)"
  3283   and     at:  "at TYPE('x)"
  3284   and     f:  "finite ((supp x)::'x set)"
  3285   and     a1: "b\<sharp>([a].x)" 
  3286   and     a2: "b\<noteq>a" 
  3287   shows "b\<sharp>x"
  3288 proof -
  3289   have "\<exists>c::'x. c\<sharp>(b,a,x,[a].x)"
  3290   proof (rule at_exists_fresh'[OF at], auto simp add: supp_prod at_supp[OF at] f)
  3291     show "finite ((supp ([a].x))::'x set)" using f
  3292       by (simp add: abs_fun_finite_supp[OF pt, OF at])  
  3293   qed
  3294   then obtain c where fr1: "b\<noteq>c"
  3295                 and   fr2: "c\<noteq>a"
  3296                 and   fr3: "c\<sharp>x"
  3297                 and   fr4: "c\<sharp>([a].x)" by (force simp add: fresh_prod at_fresh[OF at])
  3298   have "[a].x = [(b,c)]\<bullet>([a].x)" using a1 fr4 
  3299     by (simp add: pt_fresh_fresh[OF pt_abs_fun_inst[OF pt, OF at], OF at])
  3300   hence "[a].x = [a].([(b,c)]\<bullet>x)" using fr2 a2 
  3301     by (force simp add: abs_fun_pi[OF pt, OF at] at_calc[OF at])
  3302   hence b: "([(b,c)]\<bullet>x) = x" by (simp add: abs_fun_eq1)
  3303   from fr3 have "([(b,c)]\<bullet>c)\<sharp>([(b,c)]\<bullet>x)" 
  3304     by (simp add: pt_fresh_bij[OF pt, OF at]) 
  3305   thus ?thesis using b fr1 by (simp add: at_calc[OF at])
  3306 qed
  3307 
  3308 lemma fresh_abs_funI2:
  3309   fixes a :: "'x"
  3310   and   x :: "'a"
  3311   assumes pt: "pt TYPE('a) TYPE('x)"
  3312   and     at: "at TYPE('x)"
  3313   and     f: "finite ((supp x)::'x set)"
  3314   shows "a\<sharp>([a].x)"
  3315 proof -
  3316   have "\<exists>c::'x. c\<sharp>(a,x)"
  3317     by  (rule at_exists_fresh'[OF at], auto simp add: supp_prod at_supp[OF at] f) 
  3318   then obtain c where fr1: "a\<noteq>c" and fr1_sym: "c\<noteq>a" 
  3319                 and   fr2: "c\<sharp>x" by (force simp add: fresh_prod at_fresh[OF at])
  3320   have "c\<sharp>([a].x)" using f fr1 fr2 by (simp add: fresh_abs_funI1[OF pt, OF at])
  3321   hence "([(c,a)]\<bullet>c)\<sharp>([(c,a)]\<bullet>([a].x))" using fr1  
  3322     by (simp only: pt_fresh_bij[OF pt_abs_fun_inst[OF pt, OF at], OF at])
  3323   hence a: "a\<sharp>([c].([(c,a)]\<bullet>x))" using fr1_sym 
  3324     by (simp add: abs_fun_pi[OF pt, OF at] at_calc[OF at])
  3325   have "[c].([(c,a)]\<bullet>x) = ([a].x)" using fr1_sym fr2 
  3326     by (simp add: abs_fun_eq[OF pt, OF at])
  3327   thus ?thesis using a by simp
  3328 qed
  3329 
  3330 lemma fresh_abs_fun_iff: 
  3331   fixes a :: "'x"
  3332   and   b :: "'x"
  3333   and   x :: "'a"
  3334   assumes pt: "pt TYPE('a) TYPE('x)"
  3335   and     at: "at TYPE('x)"
  3336   and     f: "finite ((supp x)::'x set)"
  3337   shows "(b\<sharp>([a].x)) = (b=a \<or> b\<sharp>x)" 
  3338   by (auto  dest: fresh_abs_funE[OF pt, OF at,OF f] 
  3339            intro: fresh_abs_funI1[OF pt, OF at,OF f] 
  3340                   fresh_abs_funI2[OF pt, OF at,OF f])
  3341 
  3342 lemma abs_fun_supp: 
  3343   fixes a :: "'x"
  3344   and   x :: "'a"
  3345   assumes pt: "pt TYPE('a) TYPE('x)"
  3346   and     at: "at TYPE('x)"
  3347   and     f: "finite ((supp x)::'x set)"
  3348   shows "supp ([a].x) = (supp x)-{a}"
  3349  by (force simp add: supp_fresh_iff fresh_abs_fun_iff[OF pt, OF at, OF f])
  3350 
  3351 (* maybe needs to be better stated as supp intersection supp *)
  3352 lemma abs_fun_supp_ineq: 
  3353   fixes a :: "'y"
  3354   and   x :: "'a"
  3355   assumes pta: "pt TYPE('a) TYPE('x)"
  3356   and     ptb: "pt TYPE('y) TYPE('x)"
  3357   and     at:  "at TYPE('x)"
  3358   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  3359   and     dj:  "disjoint TYPE('y) TYPE('x)"
  3360   shows "((supp ([a].x))::'x set) = (supp x)"
  3361 apply(auto simp add: supp_def)
  3362 apply(auto simp add: abs_fun_pi_ineq[OF pta, OF ptb, OF at, OF cp])
  3363 apply(auto simp add: dj_perm_forget[OF dj])
  3364 apply(auto simp add: abs_fun_eq1) 
  3365 done
  3366 
  3367 lemma fresh_abs_fun_iff_ineq: 
  3368   fixes a :: "'y"
  3369   and   b :: "'x"
  3370   and   x :: "'a"
  3371   assumes pta: "pt TYPE('a) TYPE('x)"
  3372   and     ptb: "pt TYPE('y) TYPE('x)"
  3373   and     at:  "at TYPE('x)"
  3374   and     cp:  "cp TYPE('a) TYPE('x) TYPE('y)"
  3375   and     dj:  "disjoint TYPE('y) TYPE('x)"
  3376   shows "b\<sharp>([a].x) = b\<sharp>x" 
  3377   by (simp add: fresh_def abs_fun_supp_ineq[OF pta, OF ptb, OF at, OF cp, OF dj])
  3378 
  3379 section {* abstraction type for the parsing in nominal datatype *}
  3380 (*==============================================================*)
  3381 
  3382 inductive_set ABS_set :: "('x\<Rightarrow>('a noption)) set"
  3383   where
  3384   ABS_in: "(abs_fun a x)\<in>ABS_set"
  3385 
  3386 typedef (ABS) ('x,'a) ABS ("\<guillemotleft>_\<guillemotright>_" [1000,1000] 1000) =
  3387   "ABS_set::('x\<Rightarrow>('a noption)) set"
  3388 proof 
  3389   fix x::"'a" and a::"'x"
  3390   show "(abs_fun a x)\<in> ABS_set" by (rule ABS_in)
  3391 qed
  3392 
  3393 
  3394 section {* lemmas for deciding permutation equations *}
  3395 (*===================================================*)
  3396 
  3397 lemma perm_aux_fold:
  3398   shows "perm_aux pi x = pi\<bullet>x" by (simp only: perm_aux_def)
  3399 
  3400 lemma pt_perm_compose_aux:
  3401   fixes pi1 :: "'x prm"
  3402   and   pi2 :: "'x prm"
  3403   and   x  :: "'a"
  3404   assumes pt: "pt TYPE('a) TYPE('x)"
  3405   and     at: "at TYPE('x)"
  3406   shows "pi2\<bullet>(pi1\<bullet>x) = perm_aux (pi2\<bullet>pi1) (pi2\<bullet>x)" 
  3407 proof -
  3408   have "(pi2@pi1) \<triangleq> ((pi2\<bullet>pi1)@pi2)" by (rule at_ds8[OF at])
  3409   hence "(pi2@pi1)\<bullet>x = ((pi2\<bullet>pi1)@pi2)\<bullet>x" by (rule pt3[OF pt])
  3410   thus ?thesis by (simp add: pt2[OF pt] perm_aux_def)
  3411 qed  
  3412 
  3413 lemma cp1_aux:
  3414   fixes pi1::"'x prm"
  3415   and   pi2::"'y prm"
  3416   and   x  ::"'a"
  3417   assumes cp: "cp TYPE ('a) TYPE('x) TYPE('y)"
  3418   shows "pi1\<bullet>(pi2\<bullet>x) = perm_aux (pi1\<bullet>pi2) (pi1\<bullet>x)"
  3419   using cp by (simp add: cp_def perm_aux_def)
  3420 
  3421 lemma perm_eq_app:
  3422   fixes f  :: "'a\<Rightarrow>'b"
  3423   and   x  :: "'a"
  3424   and   pi :: "'x prm"
  3425   assumes pt: "pt TYPE('a) TYPE('x)"
  3426   and     at: "at TYPE('x)"
  3427   shows "(pi\<bullet>(f x)=y) = ((pi\<bullet>f)(pi\<bullet>x)=y)"
  3428   by (simp add: pt_fun_app_eq[OF pt, OF at])
  3429 
  3430 lemma perm_eq_lam:
  3431   fixes f  :: "'a\<Rightarrow>'b"
  3432   and   x  :: "'a"
  3433   and   pi :: "'x prm"
  3434   shows "((pi\<bullet>(\<lambda>x. f x))=y) = ((\<lambda>x. (pi\<bullet>(f ((rev pi)\<bullet>x))))=y)"
  3435   by (simp add: perm_fun_def)
  3436 
  3437 section {* test *}
  3438 lemma at_prm_eq_compose:
  3439   fixes pi1 :: "'x prm"
  3440   and   pi2 :: "'x prm"
  3441   and   pi3 :: "'x prm"
  3442   assumes at: "at TYPE('x)"
  3443   and     a: "pi1 \<triangleq> pi2"
  3444   shows "(pi3\<bullet>pi1) \<triangleq> (pi3\<bullet>pi2)"
  3445 proof -
  3446   have pt: "pt TYPE('x) TYPE('x)" by (rule at_pt_inst[OF at])
  3447   have pt_prm: "pt TYPE('x prm) TYPE('x)" 
  3448     by (rule pt_list_inst[OF pt_prod_inst[OF pt, OF pt]])  
  3449   from a show ?thesis
  3450     apply -
  3451     apply(auto simp add: prm_eq_def)
  3452     apply(rule_tac pi="rev pi3" in pt_bij4[OF pt, OF at])
  3453     apply(rule trans)
  3454     apply(rule pt_perm_compose[OF pt, OF at])
  3455     apply(simp add: pt_rev_pi[OF pt_prm, OF at])
  3456     apply(rule sym)
  3457     apply(rule trans)
  3458     apply(rule pt_perm_compose[OF pt, OF at])
  3459     apply(simp add: pt_rev_pi[OF pt_prm, OF at])
  3460     done
  3461 qed
  3462 
  3463 (************************)
  3464 (* Various eqvt-lemmas  *)
  3465 
  3466 lemma Zero_nat_eqvt:
  3467   shows "pi\<bullet>(0::nat) = 0" 
  3468 by (auto simp add: perm_nat_def)
  3469 
  3470 lemma One_nat_eqvt:
  3471   shows "pi\<bullet>(1::nat) = 1"
  3472 by (simp add: perm_nat_def)
  3473 
  3474 lemma Suc_eqvt:
  3475   shows "pi\<bullet>(Suc x) = Suc (pi\<bullet>x)" 
  3476 by (auto simp add: perm_nat_def)
  3477 
  3478 lemma numeral_nat_eqvt: 
  3479  shows "pi\<bullet>((number_of n)::nat) = number_of n" 
  3480 by (simp add: perm_nat_def perm_int_def)
  3481 
  3482 lemma max_nat_eqvt:
  3483   fixes x::"nat"
  3484   shows "pi\<bullet>(max x y) = max (pi\<bullet>x) (pi\<bullet>y)" 
  3485 by (simp add:perm_nat_def) 
  3486 
  3487 lemma min_nat_eqvt:
  3488   fixes x::"nat"
  3489   shows "pi\<bullet>(min x y) = min (pi\<bullet>x) (pi\<bullet>y)" 
  3490 by (simp add:perm_nat_def) 
  3491 
  3492 lemma plus_nat_eqvt:
  3493   fixes x::"nat"
  3494   shows "pi\<bullet>(x + y) = (pi\<bullet>x) + (pi\<bullet>y)" 
  3495 by (simp add:perm_nat_def) 
  3496 
  3497 lemma minus_nat_eqvt:
  3498   fixes x::"nat"
  3499   shows "pi\<bullet>(x - y) = (pi\<bullet>x) - (pi\<bullet>y)" 
  3500 by (simp add:perm_nat_def) 
  3501 
  3502 lemma mult_nat_eqvt:
  3503   fixes x::"nat"
  3504   shows "pi\<bullet>(x * y) = (pi\<bullet>x) * (pi\<bullet>y)" 
  3505 by (simp add:perm_nat_def) 
  3506 
  3507 lemma div_nat_eqvt:
  3508   fixes x::"nat"
  3509   shows "pi\<bullet>(x div y) = (pi\<bullet>x) div (pi\<bullet>y)" 
  3510 by (simp add:perm_nat_def) 
  3511 
  3512 lemma Zero_int_eqvt:
  3513   shows "pi\<bullet>(0::int) = 0" 
  3514 by (auto simp add: perm_int_def)
  3515 
  3516 lemma One_int_eqvt:
  3517   shows "pi\<bullet>(1::int) = 1"
  3518 by (simp add: perm_int_def)
  3519 
  3520 lemma numeral_int_eqvt: 
  3521  shows "pi\<bullet>((number_of n)::int) = number_of n" 
  3522 by (simp add: perm_int_def perm_int_def)
  3523 
  3524 lemma max_int_eqvt:
  3525   fixes x::"int"
  3526   shows "pi\<bullet>(max (x::int) y) = max (pi\<bullet>x) (pi\<bullet>y)" 
  3527 by (simp add:perm_int_def) 
  3528 
  3529 lemma min_int_eqvt:
  3530   fixes x::"int"
  3531   shows "pi\<bullet>(min x y) = min (pi\<bullet>x) (pi\<bullet>y)" 
  3532 by (simp add:perm_int_def) 
  3533 
  3534 lemma plus_int_eqvt:
  3535   fixes x::"int"
  3536   shows "pi\<bullet>(x + y) = (pi\<bullet>x) + (pi\<bullet>y)" 
  3537 by (simp add:perm_int_def) 
  3538 
  3539 lemma minus_int_eqvt:
  3540   fixes x::"int"
  3541   shows "pi\<bullet>(x - y) = (pi\<bullet>x) - (pi\<bullet>y)" 
  3542 by (simp add:perm_int_def) 
  3543 
  3544 lemma mult_int_eqvt:
  3545   fixes x::"int"
  3546   shows "pi\<bullet>(x * y) = (pi\<bullet>x) * (pi\<bullet>y)" 
  3547 by (simp add:perm_int_def) 
  3548 
  3549 lemma div_int_eqvt:
  3550   fixes x::"int"
  3551   shows "pi\<bullet>(x div y) = (pi\<bullet>x) div (pi\<bullet>y)" 
  3552 by (simp add:perm_int_def) 
  3553 
  3554 (*******************************************************)
  3555 (* Setup of the theorem attributes eqvt and eqvt_force *)
  3556 use "nominal_thmdecls.ML"
  3557 setup "NominalThmDecls.setup"
  3558 
  3559 lemmas [eqvt] = 
  3560   (* connectives *)
  3561   if_eqvt imp_eqvt disj_eqvt conj_eqvt neg_eqvt 
  3562   true_eqvt false_eqvt
  3563   imp_eqvt [folded induct_implies_def]
  3564   
  3565   (* datatypes *)
  3566   perm_unit.simps
  3567   perm_list.simps append_eqvt
  3568   perm_prod.simps
  3569   fst_eqvt snd_eqvt
  3570   perm_option.simps
  3571 
  3572   (* nats *)
  3573   Suc_eqvt Zero_nat_eqvt One_nat_eqvt min_nat_eqvt max_nat_eqvt
  3574   plus_nat_eqvt minus_nat_eqvt mult_nat_eqvt div_nat_eqvt
  3575   
  3576   (* ints *)
  3577   Zero_int_eqvt One_int_eqvt min_int_eqvt max_int_eqvt
  3578   plus_int_eqvt minus_int_eqvt mult_int_eqvt div_int_eqvt
  3579   
  3580   (* sets *)
  3581   union_eqvt empty_eqvt
  3582   
  3583  
  3584 (* the lemmas numeral_nat_eqvt numeral_int_eqvt do not conform with the *)
  3585 (* usual form of an eqvt-lemma, but they are needed for analysing       *)
  3586 (* permutations on nats and ints *)
  3587 lemmas [eqvt_force] = numeral_nat_eqvt numeral_int_eqvt
  3588 
  3589 (***************************************)
  3590 (* setup for the individial atom-kinds *)
  3591 (* and nominal datatypes               *)
  3592 use "nominal_atoms.ML"
  3593 
  3594 (************************************************************)
  3595 (* various tactics for analysing permutations, supports etc *)
  3596 use "nominal_permeq.ML"
  3597 
  3598 method_setup perm_simp =
  3599   {* NominalPermeq.perm_simp_meth *}
  3600   {* simp rules and simprocs for analysing permutations *}
  3601 
  3602 method_setup perm_simp_debug =
  3603   {* NominalPermeq.perm_simp_meth_debug *}
  3604   {* simp rules and simprocs for analysing permutations including debugging facilities *}
  3605 
  3606 method_setup perm_extend_simp =
  3607   {* NominalPermeq.perm_extend_simp_meth *}
  3608   {* tactic for deciding equalities involving permutations *}
  3609 
  3610 method_setup perm_extend_simp_debug =
  3611   {* NominalPermeq.perm_extend_simp_meth_debug *}
  3612   {* tactic for deciding equalities involving permutations including debugging facilities *}
  3613 
  3614 method_setup supports_simp =
  3615   {* NominalPermeq.supports_meth *}
  3616   {* tactic for deciding whether something supports something else *}
  3617 
  3618 method_setup supports_simp_debug =
  3619   {* NominalPermeq.supports_meth_debug *}
  3620   {* tactic for deciding whether something supports something else including debugging facilities *}
  3621 
  3622 method_setup finite_guess =
  3623   {* NominalPermeq.finite_guess_meth *}
  3624   {* tactic for deciding whether something has finite support *}
  3625 
  3626 method_setup finite_guess_debug =
  3627   {* NominalPermeq.finite_guess_meth_debug *}
  3628   {* tactic for deciding whether something has finite support including debugging facilities *}
  3629 
  3630 method_setup fresh_guess =
  3631   {* NominalPermeq.fresh_guess_meth *}
  3632   {* tactic for deciding whether an atom is fresh for something*}
  3633 
  3634 method_setup fresh_guess_debug =
  3635   {* NominalPermeq.fresh_guess_meth_debug *}
  3636   {* tactic for deciding whether an atom is fresh for something including debugging facilities *}
  3637 
  3638 (*****************************************************************)
  3639 (* tactics for generating fresh names and simplifying fresh_funs *)
  3640 use "nominal_fresh_fun.ML"
  3641 
  3642 method_setup generate_fresh = 
  3643   {* setup_generate_fresh *} 
  3644   {* tactic to generate a name fresh for all the variables in the goal *}
  3645 
  3646 method_setup fresh_fun_simp = 
  3647   {* setup_fresh_fun_simp *} 
  3648   {* tactic to delete one inner occurence of fresh_fun *}
  3649 
  3650 
  3651 (************************************************)
  3652 (* main file for constructing nominal datatypes *)
  3653 lemma allE_Nil: assumes "\<forall>x. P x" obtains "P []"
  3654   using assms ..
  3655 
  3656 use "nominal_datatype.ML"
  3657 
  3658 (******************************************************)
  3659 (* primitive recursive functions on nominal datatypes *)
  3660 use "nominal_primrec.ML"
  3661 
  3662 (****************************************************)
  3663 (* inductive definition involving nominal datatypes *)
  3664 use "nominal_inductive.ML"
  3665 use "nominal_inductive2.ML"
  3666 
  3667 (*****************************************)
  3668 (* setup for induction principles method *)
  3669 use "nominal_induct.ML"
  3670 method_setup nominal_induct =
  3671   {* NominalInduct.nominal_induct_method *}
  3672   {* nominal induction *}
  3673 
  3674 end