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