src/HOL/Nominal/nominal_atoms.ML
author urbanc
Wed Sep 05 15:46:32 2007 +0200 (2007-09-05 ago)
changeset 24527 888d56a8d9d3
parent 24218 fbf1646b267c
child 24569 c80e1871098b
permissions -rw-r--r--
modified proofs so that they are not using claset()
     1 (*  Title:      HOL/Nominal/nominal_atoms.ML
     2     ID:         $Id$
     3     Author:     Christian Urban and Stefan Berghofer, TU Muenchen
     4 
     5 Declaration of atom types to be used in nominal datatypes.
     6 *)
     7 
     8 signature NOMINAL_ATOMS =
     9 sig
    10   val create_nom_typedecls : string list -> theory -> theory
    11   type atom_info
    12   val get_atom_infos : theory -> atom_info Symtab.table
    13   val get_atom_info : theory -> string -> atom_info option
    14   val atoms_of : theory -> string list
    15   val mk_permT : typ -> typ
    16 end
    17 
    18 structure NominalAtoms : NOMINAL_ATOMS =
    19 struct
    20 
    21 val finite_emptyI = @{thm "finite.emptyI"};
    22 val Collect_const = @{thm "Collect_const"};
    23 
    24 
    25 (* theory data *)
    26 
    27 type atom_info =
    28   {pt_class : string,
    29    fs_class : string,
    30    cp_classes : (string * string) list};
    31 
    32 structure NominalData = TheoryDataFun
    33 (
    34   type T = atom_info Symtab.table;
    35   val empty = Symtab.empty;
    36   val copy = I;
    37   val extend = I;
    38   fun merge _ x = Symtab.merge (K true) x;
    39 );
    40 
    41 fun make_atom_info ((pt_class, fs_class), cp_classes) =
    42   {pt_class = pt_class,
    43    fs_class = fs_class,
    44    cp_classes = cp_classes};
    45 
    46 val get_atom_infos = NominalData.get;
    47 val get_atom_info = Symtab.lookup o NominalData.get;
    48 
    49 fun atoms_of thy = map fst (Symtab.dest (NominalData.get thy));
    50 
    51 fun mk_permT T = HOLogic.listT (HOLogic.mk_prodT (T, T));
    52 
    53 fun mk_Cons x xs =
    54   let val T = fastype_of x
    55   in Const ("List.list.Cons", T --> HOLogic.listT T --> HOLogic.listT T) $ x $ xs end;
    56 
    57 
    58 (* this function sets up all matters related to atom-  *)
    59 (* kinds; the user specifies a list of atom-kind names *)
    60 (* atom_decl <ak1> ... <akn>                           *)
    61 fun create_nom_typedecls ak_names thy =
    62   let
    63     
    64     (* declares a type-decl for every atom-kind: *) 
    65     (* that is typedecl <ak>                     *)
    66     val thy1 = TypedefPackage.add_typedecls (map (fn x => (x,[],NoSyn)) ak_names) thy;
    67     
    68     (* produces a list consisting of pairs:         *)
    69     (*  fst component is the atom-kind name         *)
    70     (*  snd component is its type                   *)
    71     val full_ak_names = map (Sign.intern_type thy1) ak_names;
    72     val ak_names_types = ak_names ~~ map (Type o rpair []) full_ak_names;
    73      
    74     (* adds for every atom-kind an axiom             *)
    75     (* <ak>_infinite: infinite (UNIV::<ak_type> set) *)
    76     val (inf_axs,thy2) = PureThy.add_axioms_i (map (fn (ak_name, T) =>
    77       let 
    78     val name = ak_name ^ "_infinite"
    79         val axiom = HOLogic.mk_Trueprop (HOLogic.mk_not
    80                     (Const ("Finite_Set.finite", HOLogic.mk_setT T --> HOLogic.boolT) $
    81                        HOLogic.mk_UNIV T))
    82       in
    83         ((name, axiom), []) 
    84       end) ak_names_types) thy1;
    85     
    86     (* declares a swapping function for every atom-kind, it is         *)
    87     (* const swap_<ak> :: <akT> * <akT> => <akT> => <akT>              *)
    88     (* swap_<ak> (a,b) c = (if a=c then b (else if b=c then a else c)) *)
    89     (* overloades then the general swap-function                       *) 
    90     val (swap_eqs, thy3) = fold_map (fn (ak_name, T) => fn thy =>
    91       let
    92         val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
    93         val swap_name = Sign.full_name thy ("swap_" ^ ak_name);
    94         val a = Free ("a", T);
    95         val b = Free ("b", T);
    96         val c = Free ("c", T);
    97         val ab = Free ("ab", HOLogic.mk_prodT (T, T))
    98         val cif = Const ("HOL.If", HOLogic.boolT --> T --> T --> T);
    99         val cswap_akname = Const (swap_name, swapT);
   100         val cswap = Const ("Nominal.swap", swapT)
   101 
   102         val name = "swap_"^ak_name^"_def";
   103         val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq
   104                 (cswap_akname $ HOLogic.mk_prod (a,b) $ c,
   105                     cif $ HOLogic.mk_eq (a,c) $ b $ (cif $ HOLogic.mk_eq (b,c) $ a $ c)))
   106         val def2 = Logic.mk_equals (cswap $ ab $ c, cswap_akname $ ab $ c)
   107       in
   108         thy |> Theory.add_consts_i [("swap_" ^ ak_name, swapT, NoSyn)] 
   109             |> PureThy.add_defs_unchecked_i true [((name, def2),[])]
   110             |> snd
   111             |> PrimrecPackage.add_primrec_unchecked_i "" [(("", def1),[])]
   112       end) ak_names_types thy2;
   113     
   114     (* declares a permutation function for every atom-kind acting  *)
   115     (* on such atoms                                               *)
   116     (* const <ak>_prm_<ak> :: (<akT> * <akT>)list => akT => akT    *)
   117     (* <ak>_prm_<ak> []     a = a                                  *)
   118     (* <ak>_prm_<ak> (x#xs) a = swap_<ak> x (perm xs a)            *)
   119     val (prm_eqs, thy4) = fold_map (fn (ak_name, T) => fn thy =>
   120       let
   121         val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
   122         val swap_name = Sign.full_name thy ("swap_" ^ ak_name)
   123         val prmT = mk_permT T --> T --> T;
   124         val prm_name = ak_name ^ "_prm_" ^ ak_name;
   125         val qu_prm_name = Sign.full_name thy prm_name;
   126         val x  = Free ("x", HOLogic.mk_prodT (T, T));
   127         val xs = Free ("xs", mk_permT T);
   128         val a  = Free ("a", T) ;
   129 
   130         val cnil  = Const ("List.list.Nil", mk_permT T);
   131         
   132         val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq (Const (qu_prm_name, prmT) $ cnil $ a, a));
   133 
   134         val def2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
   135                    (Const (qu_prm_name, prmT) $ mk_Cons x xs $ a,
   136                     Const (swap_name, swapT) $ x $ (Const (qu_prm_name, prmT) $ xs $ a)));
   137       in
   138         thy |> Theory.add_consts_i [(prm_name, mk_permT T --> T --> T, NoSyn)] 
   139             |> PrimrecPackage.add_primrec_unchecked_i "" [(("", def1), []),(("", def2), [])]
   140       end) ak_names_types thy3;
   141     
   142     (* defines permutation functions for all combinations of atom-kinds; *)
   143     (* there are a trivial cases and non-trivial cases                   *)
   144     (* non-trivial case:                                                 *)
   145     (* <ak>_prm_<ak>_def:  perm pi a == <ak>_prm_<ak> pi a               *)
   146     (* trivial case with <ak> != <ak'>                                   *)
   147     (* <ak>_prm<ak'>_def[simp]:  perm pi a == a                          *)
   148     (*                                                                   *)
   149     (* the trivial cases are added to the simplifier, while the non-     *)
   150     (* have their own rules proved below                                 *)  
   151     val (perm_defs, thy5) = fold_map (fn (ak_name, T) => fn thy =>
   152       fold_map (fn (ak_name', T') => fn thy' =>
   153         let
   154           val perm_def_name = ak_name ^ "_prm_" ^ ak_name';
   155           val pi = Free ("pi", mk_permT T);
   156           val a  = Free ("a", T');
   157           val cperm = Const ("Nominal.perm", mk_permT T --> T' --> T');
   158           val cperm_def = Const (Sign.full_name thy' perm_def_name, mk_permT T --> T' --> T');
   159 
   160           val name = ak_name ^ "_prm_" ^ ak_name' ^ "_def";
   161           val def = Logic.mk_equals
   162                     (cperm $ pi $ a, if ak_name = ak_name' then cperm_def $ pi $ a else a)
   163         in
   164           PureThy.add_defs_unchecked_i true [((name, def),[])] thy'
   165         end) ak_names_types thy) ak_names_types thy4;
   166     
   167     (* proves that every atom-kind is an instance of at *)
   168     (* lemma at_<ak>_inst:                              *)
   169     (* at TYPE(<ak>)                                    *)
   170     val (prm_cons_thms,thy6) = 
   171       thy5 |> PureThy.add_thms (map (fn (ak_name, T) =>
   172       let
   173         val ak_name_qu = Sign.full_name thy5 (ak_name);
   174         val i_type = Type(ak_name_qu,[]);
   175 	val cat = Const ("Nominal.at",(Term.itselfT i_type)  --> HOLogic.boolT);
   176         val at_type = Logic.mk_type i_type;
   177         val simp_s = HOL_ss addsimps PureThy.get_thmss thy5
   178                                   [Name "at_def",
   179                                    Name (ak_name ^ "_prm_" ^ ak_name ^ "_def"),
   180                                    Name (ak_name ^ "_prm_" ^ ak_name ^ ".simps"),
   181                                    Name ("swap_" ^ ak_name ^ "_def"),
   182                                    Name ("swap_" ^ ak_name ^ ".simps"),
   183                                    Name (ak_name ^ "_infinite")]
   184 	    
   185 	val name = "at_"^ak_name^ "_inst";
   186         val statement = HOLogic.mk_Trueprop (cat $ at_type);
   187 
   188         val proof = fn _ => simp_tac simp_s 1
   189 
   190       in 
   191         ((name, Goal.prove_global thy5 [] [] statement proof), []) 
   192       end) ak_names_types);
   193 
   194     (* declares a perm-axclass for every atom-kind               *)
   195     (* axclass pt_<ak>                                           *)
   196     (* pt_<ak>1[simp]: perm [] x = x                             *)
   197     (* pt_<ak>2:       perm (pi1@pi2) x = perm pi1 (perm pi2 x)  *)
   198     (* pt_<ak>3:       pi1 ~ pi2 ==> perm pi1 x = perm pi2 x     *)
   199      val (pt_ax_classes,thy7) =  fold_map (fn (ak_name, T) => fn thy =>
   200       let 
   201 	  val cl_name = "pt_"^ak_name;
   202           val ty = TFree("'a",["HOL.type"]);
   203           val x   = Free ("x", ty);
   204           val pi1 = Free ("pi1", mk_permT T);
   205           val pi2 = Free ("pi2", mk_permT T);
   206           val cperm = Const ("Nominal.perm", mk_permT T --> ty --> ty);
   207           val cnil  = Const ("List.list.Nil", mk_permT T);
   208           val cappend = Const ("List.append",mk_permT T --> mk_permT T --> mk_permT T);
   209           val cprm_eq = Const ("Nominal.prm_eq",mk_permT T --> mk_permT T --> HOLogic.boolT);
   210           (* nil axiom *)
   211           val axiom1 = HOLogic.mk_Trueprop (HOLogic.mk_eq 
   212                        (cperm $ cnil $ x, x));
   213           (* append axiom *)
   214           val axiom2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
   215                        (cperm $ (cappend $ pi1 $ pi2) $ x, cperm $ pi1 $ (cperm $ pi2 $ x)));
   216           (* perm-eq axiom *)
   217           val axiom3 = Logic.mk_implies
   218                        (HOLogic.mk_Trueprop (cprm_eq $ pi1 $ pi2),
   219                         HOLogic.mk_Trueprop (HOLogic.mk_eq (cperm $ pi1 $ x, cperm $ pi2 $ x)));
   220       in
   221           AxClass.define_class (cl_name, ["HOL.type"]) []
   222                 [((cl_name ^ "1", [Simplifier.simp_add]), [axiom1]),
   223                  ((cl_name ^ "2", []), [axiom2]),                           
   224                  ((cl_name ^ "3", []), [axiom3])] thy                          
   225       end) ak_names_types thy6;
   226 
   227     (* proves that every pt_<ak>-type together with <ak>-type *)
   228     (* instance of pt                                         *)
   229     (* lemma pt_<ak>_inst:                                    *)
   230     (* pt TYPE('x::pt_<ak>) TYPE(<ak>)                        *)
   231     val (prm_inst_thms,thy8) = 
   232       thy7 |> PureThy.add_thms (map (fn (ak_name, T) =>
   233       let
   234         val ak_name_qu = Sign.full_name thy7 ak_name;
   235         val pt_name_qu = Sign.full_name thy7 ("pt_"^ak_name);
   236         val i_type1 = TFree("'x",[pt_name_qu]);
   237         val i_type2 = Type(ak_name_qu,[]);
   238 	val cpt = Const ("Nominal.pt",(Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
   239         val pt_type = Logic.mk_type i_type1;
   240         val at_type = Logic.mk_type i_type2;
   241         val simp_s = HOL_ss addsimps PureThy.get_thmss thy7
   242                                   [Name "pt_def",
   243                                    Name ("pt_" ^ ak_name ^ "1"),
   244                                    Name ("pt_" ^ ak_name ^ "2"),
   245                                    Name ("pt_" ^ ak_name ^ "3")];
   246 
   247 	val name = "pt_"^ak_name^ "_inst";
   248         val statement = HOLogic.mk_Trueprop (cpt $ pt_type $ at_type);
   249 
   250         val proof = fn _ => simp_tac simp_s 1;
   251       in 
   252         ((name, Goal.prove_global thy7 [] [] statement proof), []) 
   253       end) ak_names_types);
   254 
   255      (* declares an fs-axclass for every atom-kind       *)
   256      (* axclass fs_<ak>                                  *)
   257      (* fs_<ak>1: finite ((supp x)::<ak> set)            *)
   258      val (fs_ax_classes,thy11) =  fold_map (fn (ak_name, T) => fn thy =>
   259        let 
   260 	  val cl_name = "fs_"^ak_name;
   261 	  val pt_name = Sign.full_name thy ("pt_"^ak_name);
   262           val ty = TFree("'a",["HOL.type"]);
   263           val x   = Free ("x", ty);
   264           val csupp    = Const ("Nominal.supp", ty --> HOLogic.mk_setT T);
   265           val cfinite  = Const ("Finite_Set.finite", HOLogic.mk_setT T --> HOLogic.boolT)
   266           
   267           val axiom1   = HOLogic.mk_Trueprop (cfinite $ (csupp $ x));
   268 
   269        in  
   270         AxClass.define_class (cl_name, [pt_name]) [] [((cl_name ^ "1", []), [axiom1])] thy            
   271        end) ak_names_types thy8; 
   272 	 
   273      (* proves that every fs_<ak>-type together with <ak>-type   *)
   274      (* instance of fs-type                                      *)
   275      (* lemma abst_<ak>_inst:                                    *)
   276      (* fs TYPE('x::pt_<ak>) TYPE (<ak>)                         *)
   277      val (fs_inst_thms,thy12) = 
   278        thy11 |> PureThy.add_thms (map (fn (ak_name, T) =>
   279        let
   280          val ak_name_qu = Sign.full_name thy11 ak_name;
   281          val fs_name_qu = Sign.full_name thy11 ("fs_"^ak_name);
   282          val i_type1 = TFree("'x",[fs_name_qu]);
   283          val i_type2 = Type(ak_name_qu,[]);
   284  	 val cfs = Const ("Nominal.fs", 
   285                                  (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
   286          val fs_type = Logic.mk_type i_type1;
   287          val at_type = Logic.mk_type i_type2;
   288 	 val simp_s = HOL_ss addsimps PureThy.get_thmss thy11
   289                                    [Name "fs_def",
   290                                     Name ("fs_" ^ ak_name ^ "1")];
   291     
   292 	 val name = "fs_"^ak_name^ "_inst";
   293          val statement = HOLogic.mk_Trueprop (cfs $ fs_type $ at_type);
   294 
   295          val proof = fn _ => simp_tac simp_s 1;
   296        in 
   297          ((name, Goal.prove_global thy11 [] [] statement proof), []) 
   298        end) ak_names_types);
   299 
   300        (* declares for every atom-kind combination an axclass            *)
   301        (* cp_<ak1>_<ak2> giving a composition property                   *)
   302        (* cp_<ak1>_<ak2>1: pi1 o pi2 o x = (pi1 o pi2) o (pi1 o x)       *)
   303         val (cp_ax_classes,thy12b) = fold_map (fn (ak_name, T) => fn thy =>
   304 	 fold_map (fn (ak_name', T') => fn thy' =>
   305 	     let
   306 	       val cl_name = "cp_"^ak_name^"_"^ak_name';
   307 	       val ty = TFree("'a",["HOL.type"]);
   308                val x   = Free ("x", ty);
   309                val pi1 = Free ("pi1", mk_permT T);
   310 	       val pi2 = Free ("pi2", mk_permT T');                  
   311 	       val cperm1 = Const ("Nominal.perm", mk_permT T  --> ty --> ty);
   312                val cperm2 = Const ("Nominal.perm", mk_permT T' --> ty --> ty);
   313                val cperm3 = Const ("Nominal.perm", mk_permT T  --> mk_permT T' --> mk_permT T');
   314 
   315                val ax1   = HOLogic.mk_Trueprop 
   316 			   (HOLogic.mk_eq (cperm1 $ pi1 $ (cperm2 $ pi2 $ x), 
   317                                            cperm2 $ (cperm3 $ pi1 $ pi2) $ (cperm1 $ pi1 $ x)));
   318 	       in  
   319 		 AxClass.define_class (cl_name, ["HOL.type"]) [] [((cl_name ^ "1", []), [ax1])] thy'  
   320 	       end) ak_names_types thy) ak_names_types thy12;
   321 
   322         (* proves for every <ak>-combination a cp_<ak1>_<ak2>_inst theorem;     *)
   323         (* lemma cp_<ak1>_<ak2>_inst:                                           *)
   324         (* cp TYPE('a::cp_<ak1>_<ak2>) TYPE(<ak1>) TYPE(<ak2>)                  *)
   325         val (cp_thms,thy12c) = fold_map (fn (ak_name, T) => fn thy =>
   326 	 fold_map (fn (ak_name', T') => fn thy' =>
   327            let
   328              val ak_name_qu  = Sign.full_name thy' (ak_name);
   329 	     val ak_name_qu' = Sign.full_name thy' (ak_name');
   330              val cp_name_qu  = Sign.full_name thy' ("cp_"^ak_name^"_"^ak_name');
   331              val i_type0 = TFree("'a",[cp_name_qu]);
   332              val i_type1 = Type(ak_name_qu,[]);
   333              val i_type2 = Type(ak_name_qu',[]);
   334 	     val ccp = Const ("Nominal.cp",
   335                              (Term.itselfT i_type0)-->(Term.itselfT i_type1)-->
   336                                                       (Term.itselfT i_type2)-->HOLogic.boolT);
   337              val at_type  = Logic.mk_type i_type1;
   338              val at_type' = Logic.mk_type i_type2;
   339 	     val cp_type  = Logic.mk_type i_type0;
   340              val simp_s   = HOL_basic_ss addsimps PureThy.get_thmss thy' [(Name "cp_def")];
   341 	     val cp1      = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"1"));
   342 
   343 	     val name = "cp_"^ak_name^ "_"^ak_name'^"_inst";
   344              val statement = HOLogic.mk_Trueprop (ccp $ cp_type $ at_type $ at_type');
   345 
   346              val proof = fn _ => EVERY [simp_tac simp_s 1, 
   347                                         rtac allI 1, rtac allI 1, rtac allI 1,
   348                                         rtac cp1 1];
   349 	   in
   350 	     PureThy.add_thms [((name, Goal.prove_global thy' [] [] statement proof), [])] thy'
   351 	   end) 
   352            ak_names_types thy) ak_names_types thy12b;
   353        
   354         (* proves for every non-trivial <ak>-combination a disjointness   *)
   355         (* theorem; i.e. <ak1> != <ak2>                                   *)
   356         (* lemma ds_<ak1>_<ak2>:                                          *)
   357         (* dj TYPE(<ak1>) TYPE(<ak2>)                                     *)
   358         val (dj_thms, thy12d) = fold_map (fn (ak_name,T) => fn thy =>
   359 	  fold_map (fn (ak_name',T') => fn thy' =>
   360           (if not (ak_name = ak_name') 
   361            then 
   362 	       let
   363 		 val ak_name_qu  = Sign.full_name thy' ak_name;
   364 	         val ak_name_qu' = Sign.full_name thy' ak_name';
   365                  val i_type1 = Type(ak_name_qu,[]);
   366                  val i_type2 = Type(ak_name_qu',[]);
   367 	         val cdj = Const ("Nominal.disjoint",
   368                            (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
   369                  val at_type  = Logic.mk_type i_type1;
   370                  val at_type' = Logic.mk_type i_type2;
   371                  val simp_s = HOL_ss addsimps PureThy.get_thmss thy' 
   372 					   [Name "disjoint_def",
   373                                             Name (ak_name^"_prm_"^ak_name'^"_def"),
   374                                             Name (ak_name'^"_prm_"^ak_name^"_def")];
   375 
   376 	         val name = "dj_"^ak_name^"_"^ak_name';
   377                  val statement = HOLogic.mk_Trueprop (cdj $ at_type $ at_type');
   378 
   379                  val proof = fn _ => simp_tac simp_s 1;
   380 	       in
   381 		PureThy.add_thms [((name, Goal.prove_global thy' [] [] statement proof), [])] thy'
   382 	       end
   383            else 
   384             ([],thy')))  (* do nothing branch, if ak_name = ak_name' *) 
   385 	    ak_names_types thy) ak_names_types thy12c;
   386 
   387      (********  pt_<ak> class instances  ********)
   388      (*=========================================*)
   389      (* some abbreviations for theorems *)
   390       val pt1           = @{thm "pt1"};
   391       val pt2           = @{thm "pt2"};
   392       val pt3           = @{thm "pt3"};
   393       val at_pt_inst    = @{thm "at_pt_inst"};
   394       val pt_set_inst   = @{thm "pt_set_inst"}; 
   395       val pt_unit_inst  = @{thm "pt_unit_inst"};
   396       val pt_prod_inst  = @{thm "pt_prod_inst"}; 
   397       val pt_nprod_inst = @{thm "pt_nprod_inst"}; 
   398       val pt_list_inst  = @{thm "pt_list_inst"};
   399       val pt_optn_inst  = @{thm "pt_option_inst"};
   400       val pt_noptn_inst = @{thm "pt_noption_inst"};
   401       val pt_fun_inst   = @{thm "pt_fun_inst"};
   402 
   403      (* for all atom-kind combinations <ak>/<ak'> show that        *)
   404      (* every <ak> is an instance of pt_<ak'>; the proof for       *)
   405      (* ak!=ak' is by definition; the case ak=ak' uses at_pt_inst. *)
   406      val thy13 = fold (fn ak_name => fn thy =>
   407 	fold (fn ak_name' => fn thy' =>
   408          let
   409            val qu_name =  Sign.full_name thy' ak_name';
   410            val cls_name = Sign.full_name thy' ("pt_"^ak_name);
   411            val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name'^"_inst")); 
   412 
   413            val proof1 = EVERY [Class.intro_classes_tac [],
   414                                  rtac ((at_inst RS at_pt_inst) RS pt1) 1,
   415                                  rtac ((at_inst RS at_pt_inst) RS pt2) 1,
   416                                  rtac ((at_inst RS at_pt_inst) RS pt3) 1,
   417                                  atac 1];
   418            val simp_s = HOL_basic_ss addsimps 
   419                         PureThy.get_thmss thy' [Name (ak_name^"_prm_"^ak_name'^"_def")];  
   420            val proof2 = EVERY [Class.intro_classes_tac [], REPEAT (asm_simp_tac simp_s 1)];
   421 
   422          in
   423            thy'
   424            |> AxClass.prove_arity (qu_name,[],[cls_name])
   425               (if ak_name = ak_name' then proof1 else proof2)
   426          end) ak_names thy) ak_names thy12c;
   427 
   428      (* show that                       *)
   429      (*      fun(pt_<ak>,pt_<ak>)       *)
   430      (*      noption(pt_<ak>)           *)
   431      (*      option(pt_<ak>)            *)
   432      (*      list(pt_<ak>)              *)
   433      (*      *(pt_<ak>,pt_<ak>)         *)
   434      (*      nprod(pt_<ak>,pt_<ak>)     *)
   435      (*      unit                       *)
   436      (*      set(pt_<ak>)               *)
   437      (* are instances of pt_<ak>        *)
   438      val thy18 = fold (fn ak_name => fn thy =>
   439        let
   440           val cls_name = Sign.full_name thy ("pt_"^ak_name);
   441           val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   442           val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   443 
   444           fun pt_proof thm = 
   445               EVERY [Class.intro_classes_tac [],
   446                      rtac (thm RS pt1) 1, rtac (thm RS pt2) 1, rtac (thm RS pt3) 1, atac 1];
   447 
   448           val pt_thm_fun   = at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst));
   449           val pt_thm_noptn = pt_inst RS pt_noptn_inst; 
   450           val pt_thm_optn  = pt_inst RS pt_optn_inst; 
   451           val pt_thm_list  = pt_inst RS pt_list_inst;
   452           val pt_thm_prod  = pt_inst RS (pt_inst RS pt_prod_inst);
   453           val pt_thm_nprod = pt_inst RS (pt_inst RS pt_nprod_inst);
   454           val pt_thm_unit  = pt_unit_inst;
   455           val pt_thm_set   = pt_inst RS pt_set_inst
   456        in
   457         thy
   458         |> AxClass.prove_arity ("fun",[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_fun)
   459         |> AxClass.prove_arity ("Nominal.noption",[[cls_name]],[cls_name]) (pt_proof pt_thm_noptn) 
   460         |> AxClass.prove_arity ("Datatype.option",[[cls_name]],[cls_name]) (pt_proof pt_thm_optn)
   461         |> AxClass.prove_arity ("List.list",[[cls_name]],[cls_name]) (pt_proof pt_thm_list)
   462         |> AxClass.prove_arity ("*",[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_prod)
   463         |> AxClass.prove_arity ("Nominal.nprod",[[cls_name],[cls_name]],[cls_name]) 
   464                                     (pt_proof pt_thm_nprod)
   465         |> AxClass.prove_arity ("Product_Type.unit",[],[cls_name]) (pt_proof pt_thm_unit)
   466         |> AxClass.prove_arity ("set",[[cls_name]],[cls_name]) (pt_proof pt_thm_set)
   467      end) ak_names thy13; 
   468 
   469        (********  fs_<ak> class instances  ********)
   470        (*=========================================*)
   471        (* abbreviations for some lemmas *)
   472        val fs1            = @{thm "fs1"};
   473        val fs_at_inst     = @{thm "fs_at_inst"};
   474        val fs_unit_inst   = @{thm "fs_unit_inst"};
   475        val fs_prod_inst   = @{thm "fs_prod_inst"};
   476        val fs_nprod_inst  = @{thm "fs_nprod_inst"};
   477        val fs_list_inst   = @{thm "fs_list_inst"};
   478        val fs_option_inst = @{thm "fs_option_inst"};
   479        val dj_supp        = @{thm "dj_supp"};
   480 
   481        (* shows that <ak> is an instance of fs_<ak>     *)
   482        (* uses the theorem at_<ak>_inst                 *)
   483        val thy20 = fold (fn ak_name => fn thy =>
   484         fold (fn ak_name' => fn thy' =>
   485         let
   486            val qu_name =  Sign.full_name thy' ak_name';
   487            val qu_class = Sign.full_name thy' ("fs_"^ak_name);
   488            val proof =
   489                (if ak_name = ak_name'
   490                 then
   491                   let val at_thm = PureThy.get_thm thy' (Name ("at_"^ak_name^"_inst"));
   492                   in  EVERY [Class.intro_classes_tac [],
   493                              rtac ((at_thm RS fs_at_inst) RS fs1) 1] end
   494                 else
   495                   let val dj_inst = PureThy.get_thm thy' (Name ("dj_"^ak_name'^"_"^ak_name));
   496                       val simp_s = HOL_basic_ss addsimps [dj_inst RS dj_supp, finite_emptyI];
   497                   in EVERY [Class.intro_classes_tac [], asm_simp_tac simp_s 1] end)
   498         in
   499          AxClass.prove_arity (qu_name,[],[qu_class]) proof thy'
   500         end) ak_names thy) ak_names thy18;
   501 
   502        (* shows that                  *)
   503        (*    unit                     *)
   504        (*    *(fs_<ak>,fs_<ak>)       *)
   505        (*    nprod(fs_<ak>,fs_<ak>)   *)
   506        (*    list(fs_<ak>)            *)
   507        (*    option(fs_<ak>)          *) 
   508        (* are instances of fs_<ak>    *)
   509 
   510        val thy24 = fold (fn ak_name => fn thy => 
   511         let
   512           val cls_name = Sign.full_name thy ("fs_"^ak_name);
   513           val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
   514           fun fs_proof thm = EVERY [Class.intro_classes_tac [], rtac (thm RS fs1) 1];
   515 
   516           val fs_thm_unit  = fs_unit_inst;
   517           val fs_thm_prod  = fs_inst RS (fs_inst RS fs_prod_inst);
   518           val fs_thm_nprod = fs_inst RS (fs_inst RS fs_nprod_inst);
   519           val fs_thm_list  = fs_inst RS fs_list_inst;
   520           val fs_thm_optn  = fs_inst RS fs_option_inst;
   521         in 
   522          thy
   523          |> AxClass.prove_arity ("Product_Type.unit",[],[cls_name]) (fs_proof fs_thm_unit) 
   524          |> AxClass.prove_arity ("*",[[cls_name],[cls_name]],[cls_name]) (fs_proof fs_thm_prod) 
   525          |> AxClass.prove_arity ("Nominal.nprod",[[cls_name],[cls_name]],[cls_name]) 
   526                                      (fs_proof fs_thm_nprod) 
   527          |> AxClass.prove_arity ("List.list",[[cls_name]],[cls_name]) (fs_proof fs_thm_list)
   528          |> AxClass.prove_arity ("Datatype.option",[[cls_name]],[cls_name]) (fs_proof fs_thm_optn)
   529         end) ak_names thy20;
   530 
   531        (********  cp_<ak>_<ai> class instances  ********)
   532        (*==============================================*)
   533        (* abbreviations for some lemmas *)
   534        val cp1             = @{thm "cp1"};
   535        val cp_unit_inst    = @{thm "cp_unit_inst"};
   536        val cp_bool_inst    = @{thm "cp_bool_inst"};
   537        val cp_prod_inst    = @{thm "cp_prod_inst"};
   538        val cp_list_inst    = @{thm "cp_list_inst"};
   539        val cp_fun_inst     = @{thm "cp_fun_inst"};
   540        val cp_option_inst  = @{thm "cp_option_inst"};
   541        val cp_noption_inst = @{thm "cp_noption_inst"};
   542        val cp_set_inst     = @{thm "cp_set_inst"};
   543        val pt_perm_compose = @{thm "pt_perm_compose"};
   544 
   545        val dj_pp_forget    = @{thm "dj_perm_perm_forget"};
   546 
   547        (* shows that <aj> is an instance of cp_<ak>_<ai>  *)
   548        (* for every  <ak>/<ai>-combination                *)
   549        val thy25 = fold (fn ak_name => fn thy =>
   550          fold (fn ak_name' => fn thy' =>
   551           fold (fn ak_name'' => fn thy'' =>
   552             let
   553               val name =  Sign.full_name thy'' ak_name;
   554               val cls_name = Sign.full_name thy'' ("cp_"^ak_name'^"_"^ak_name'');
   555               val proof =
   556                 (if (ak_name'=ak_name'') then 
   557                   (let
   558                     val pt_inst  = PureThy.get_thm thy'' (Name ("pt_"^ak_name''^"_inst"));
   559                     val at_inst  = PureThy.get_thm thy'' (Name ("at_"^ak_name''^"_inst"));
   560                   in
   561 		   EVERY [Class.intro_classes_tac [],
   562                           rtac (at_inst RS (pt_inst RS pt_perm_compose)) 1]
   563                   end)
   564 		else
   565 		  (let
   566                      val dj_inst  = PureThy.get_thm thy'' (Name ("dj_"^ak_name''^"_"^ak_name'));
   567 		     val simp_s = HOL_basic_ss addsimps
   568                                         ((dj_inst RS dj_pp_forget)::
   569                                          (PureThy.get_thmss thy''
   570                                            [Name (ak_name' ^"_prm_"^ak_name^"_def"),
   571                                             Name (ak_name''^"_prm_"^ak_name^"_def")]));
   572                   in
   573                     EVERY [Class.intro_classes_tac [], simp_tac simp_s 1]
   574                   end))
   575               in
   576                 AxClass.prove_arity (name,[],[cls_name]) proof thy''
   577               end) ak_names thy') ak_names thy) ak_names thy24;
   578 
   579        (* shows that                                                    *) 
   580        (*      units                                                    *) 
   581        (*      products                                                 *)
   582        (*      lists                                                    *)
   583        (*      functions                                                *)
   584        (*      options                                                  *)
   585        (*      noptions                                                 *)
   586        (*      sets                                                     *)
   587        (* are instances of cp_<ak>_<ai> for every <ak>/<ai>-combination *)
   588        val thy26 = fold (fn ak_name => fn thy =>
   589 	fold (fn ak_name' => fn thy' =>
   590         let
   591             val cls_name = Sign.full_name thy' ("cp_"^ak_name^"_"^ak_name');
   592             val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   593             val pt_inst  = PureThy.get_thm thy' (Name ("pt_"^ak_name^"_inst"));
   594             val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name^"_inst"));
   595 
   596             fun cp_proof thm  = EVERY [Class.intro_classes_tac [],rtac (thm RS cp1) 1];
   597 	  
   598             val cp_thm_unit = cp_unit_inst;
   599             val cp_thm_prod = cp_inst RS (cp_inst RS cp_prod_inst);
   600             val cp_thm_list = cp_inst RS cp_list_inst;
   601             val cp_thm_fun  = at_inst RS (pt_inst RS (cp_inst RS (cp_inst RS cp_fun_inst)));
   602             val cp_thm_optn = cp_inst RS cp_option_inst;
   603             val cp_thm_noptn = cp_inst RS cp_noption_inst;
   604             val cp_thm_set = cp_inst RS cp_set_inst;
   605         in
   606          thy'
   607          |> AxClass.prove_arity ("Product_Type.unit",[],[cls_name]) (cp_proof cp_thm_unit)
   608 	 |> AxClass.prove_arity ("*",[[cls_name],[cls_name]],[cls_name]) (cp_proof cp_thm_prod)
   609          |> AxClass.prove_arity ("List.list",[[cls_name]],[cls_name]) (cp_proof cp_thm_list)
   610          |> AxClass.prove_arity ("fun",[[cls_name],[cls_name]],[cls_name]) (cp_proof cp_thm_fun)
   611          |> AxClass.prove_arity ("Datatype.option",[[cls_name]],[cls_name]) (cp_proof cp_thm_optn)
   612          |> AxClass.prove_arity ("Nominal.noption",[[cls_name]],[cls_name]) (cp_proof cp_thm_noptn)
   613          |> AxClass.prove_arity ("set",[[cls_name]],[cls_name]) (cp_proof cp_thm_set)
   614         end) ak_names thy) ak_names thy25;
   615 
   616      (* show that discrete nominal types are permutation types, finitely     *)
   617      (* supported and have the commutation property                          *)
   618      (* discrete types have a permutation operation defined as pi o x = x;   *)
   619      (* which renders the proofs to be simple "simp_all"-proofs.             *)
   620      val thy32 =
   621         let
   622 	  fun discrete_pt_inst discrete_ty defn =
   623 	     fold (fn ak_name => fn thy =>
   624 	     let
   625 	       val qu_class = Sign.full_name thy ("pt_"^ak_name);
   626 	       val simp_s = HOL_basic_ss addsimps [defn];
   627                val proof = EVERY [Class.intro_classes_tac [], REPEAT (asm_simp_tac simp_s 1)];
   628              in 
   629 	       AxClass.prove_arity (discrete_ty,[],[qu_class]) proof thy
   630              end) ak_names;
   631 
   632           fun discrete_fs_inst discrete_ty defn = 
   633 	     fold (fn ak_name => fn thy =>
   634 	     let
   635 	       val qu_class = Sign.full_name thy ("fs_"^ak_name);
   636 	       val supp_def = @{thm "Nominal.supp_def"};
   637                val simp_s = HOL_ss addsimps [supp_def,Collect_const,finite_emptyI,defn];
   638                val proof = EVERY [Class.intro_classes_tac [], asm_simp_tac simp_s 1];
   639              in 
   640 	       AxClass.prove_arity (discrete_ty,[],[qu_class]) proof thy
   641              end) ak_names;
   642 
   643           fun discrete_cp_inst discrete_ty defn = 
   644 	     fold (fn ak_name' => (fold (fn ak_name => fn thy =>
   645 	     let
   646 	       val qu_class = Sign.full_name thy ("cp_"^ak_name^"_"^ak_name');
   647 	       val supp_def = @{thm "Nominal.supp_def"};
   648                val simp_s = HOL_ss addsimps [defn];
   649                val proof = EVERY [Class.intro_classes_tac [], asm_simp_tac simp_s 1];
   650              in
   651 	       AxClass.prove_arity (discrete_ty,[],[qu_class]) proof thy
   652              end) ak_names)) ak_names;
   653 
   654         in
   655          thy26
   656          |> discrete_pt_inst "nat"  @{thm "perm_nat_def"}
   657          |> discrete_fs_inst "nat"  @{thm "perm_nat_def"}
   658          |> discrete_cp_inst "nat"  @{thm "perm_nat_def"}
   659          |> discrete_pt_inst "bool" @{thm "perm_bool"}
   660          |> discrete_fs_inst "bool" @{thm "perm_bool"}
   661          |> discrete_cp_inst "bool" @{thm "perm_bool"}
   662          |> discrete_pt_inst "IntDef.int" @{thm "perm_int_def"}
   663          |> discrete_fs_inst "IntDef.int" @{thm "perm_int_def"}
   664          |> discrete_cp_inst "IntDef.int" @{thm "perm_int_def"}
   665          |> discrete_pt_inst "List.char" @{thm "perm_char_def"}
   666          |> discrete_fs_inst "List.char" @{thm "perm_char_def"}
   667          |> discrete_cp_inst "List.char" @{thm "perm_char_def"}
   668         end;
   669 
   670 
   671        (* abbreviations for some lemmas *)
   672        (*===============================*)
   673        val abs_fun_pi          = @{thm "Nominal.abs_fun_pi"};
   674        val abs_fun_pi_ineq     = @{thm "Nominal.abs_fun_pi_ineq"};
   675        val abs_fun_eq          = @{thm "Nominal.abs_fun_eq"};
   676        val abs_fun_eq'         = @{thm "Nominal.abs_fun_eq'"};
   677        val abs_fun_fresh       = @{thm "Nominal.abs_fun_fresh"};
   678        val abs_fun_fresh'      = @{thm "Nominal.abs_fun_fresh'"};
   679        val dj_perm_forget      = @{thm "Nominal.dj_perm_forget"};
   680        val dj_pp_forget        = @{thm "Nominal.dj_perm_perm_forget"};
   681        val fresh_iff           = @{thm "Nominal.fresh_abs_fun_iff"};
   682        val fresh_iff_ineq      = @{thm "Nominal.fresh_abs_fun_iff_ineq"};
   683        val abs_fun_supp        = @{thm "Nominal.abs_fun_supp"};
   684        val abs_fun_supp_ineq   = @{thm "Nominal.abs_fun_supp_ineq"};
   685        val pt_swap_bij         = @{thm "Nominal.pt_swap_bij"};
   686        val pt_swap_bij'        = @{thm "Nominal.pt_swap_bij'"};
   687        val pt_fresh_fresh      = @{thm "Nominal.pt_fresh_fresh"};
   688        val pt_bij              = @{thm "Nominal.pt_bij"};
   689        val pt_perm_compose     = @{thm "Nominal.pt_perm_compose"};
   690        val pt_perm_compose'    = @{thm "Nominal.pt_perm_compose'"};
   691        val perm_app            = @{thm "Nominal.pt_fun_app_eq"};
   692        val at_fresh            = @{thm "Nominal.at_fresh"};
   693        val at_fresh_ineq       = @{thm "Nominal.at_fresh_ineq"};
   694        val at_calc             = @{thms "Nominal.at_calc"};
   695        val at_swap_simps       = @{thms "Nominal.at_swap_simps"};
   696        val at_supp             = @{thm "Nominal.at_supp"};
   697        val dj_supp             = @{thm "Nominal.dj_supp"};
   698        val fresh_left_ineq     = @{thm "Nominal.pt_fresh_left_ineq"};
   699        val fresh_left          = @{thm "Nominal.pt_fresh_left"};
   700        val fresh_right_ineq    = @{thm "Nominal.pt_fresh_right_ineq"};
   701        val fresh_right         = @{thm "Nominal.pt_fresh_right"};
   702        val fresh_bij_ineq      = @{thm "Nominal.pt_fresh_bij_ineq"};
   703        val fresh_bij           = @{thm "Nominal.pt_fresh_bij"};
   704        val fresh_eqvt          = @{thm "Nominal.pt_fresh_eqvt"};
   705        val fresh_eqvt_ineq     = @{thm "Nominal.pt_fresh_eqvt_ineq"};
   706        val set_diff_eqvt       = @{thm "Nominal.pt_set_diff_eqvt"};
   707        val in_eqvt             = @{thm "Nominal.pt_in_eqvt"};
   708        val eq_eqvt             = @{thm "Nominal.pt_eq_eqvt"};
   709        val all_eqvt            = @{thm "Nominal.pt_all_eqvt"};
   710        val ex_eqvt             = @{thm "Nominal.pt_ex_eqvt"};
   711        val pt_pi_rev           = @{thm "Nominal.pt_pi_rev"};
   712        val pt_rev_pi           = @{thm "Nominal.pt_rev_pi"};
   713        val at_exists_fresh     = @{thm "Nominal.at_exists_fresh"};
   714        val at_exists_fresh'    = @{thm "Nominal.at_exists_fresh'"};
   715        val fresh_perm_app_ineq = @{thm "Nominal.pt_fresh_perm_app_ineq"};
   716        val fresh_perm_app      = @{thm "Nominal.pt_fresh_perm_app"};	
   717        val fresh_aux           = @{thm "Nominal.pt_fresh_aux"};  
   718        val pt_perm_supp_ineq   = @{thm "Nominal.pt_perm_supp_ineq"};
   719        val pt_perm_supp        = @{thm "Nominal.pt_perm_supp"};
   720 
   721        (* Now we collect and instantiate some lemmas w.r.t. all atom      *)
   722        (* types; this allows for example to use abs_perm (which is a      *)
   723        (* collection of theorems) instead of thm abs_fun_pi with explicit *)
   724        (* instantiations.                                                 *)
   725        val (_, thy33) =
   726          let
   727 
   728              (* takes a theorem thm and a list of theorems [t1,..,tn]            *)
   729              (* produces a list of theorems of the form [t1 RS thm,..,tn RS thm] *) 
   730              fun instR thm thms = map (fn ti => ti RS thm) thms;
   731 
   732              (* takes two theorem lists (hopefully of the same length ;o)                *)
   733              (* produces a list of theorems of the form                                  *)
   734              (* [t1 RS m1,..,tn RS mn] where [t1,..,tn] is thms1 and [m1,..,mn] is thms2 *) 
   735              fun inst_zip thms1 thms2 = map (fn (t1,t2) => t1 RS t2) (thms1 ~~ thms2);
   736 
   737              (* takes a theorem list of the form [l1,...,ln]              *)
   738              (* and a list of theorem lists of the form                   *)
   739              (* [[h11,...,h1m],....,[hk1,....,hkm]                        *)
   740              (* produces the list of theorem lists                        *)
   741              (* [[l1 RS h11,...,l1 RS h1m],...,[ln RS hk1,...,ln RS hkm]] *)
   742              fun inst_mult thms thmss = map (fn (t,ts) => instR t ts) (thms ~~ thmss);
   743 
   744              (* FIXME: these lists do not need to be created dynamically again *)
   745 
   746              
   747              (* list of all at_inst-theorems *)
   748              val ats = map (fn ak => PureThy.get_thm thy32 (Name ("at_"^ak^"_inst"))) ak_names
   749              (* list of all pt_inst-theorems *)
   750              val pts = map (fn ak => PureThy.get_thm thy32 (Name ("pt_"^ak^"_inst"))) ak_names
   751              (* list of all cp_inst-theorems as a collection of lists*)
   752              val cps = 
   753 		 let fun cps_fun ak1 ak2 = PureThy.get_thm thy32 (Name ("cp_"^ak1^"_"^ak2^"_inst"))
   754 		 in map (fn aki => (map (cps_fun aki) ak_names)) ak_names end; 
   755              (* list of all cp_inst-theorems that have different atom types *)
   756              val cps' = 
   757 		let fun cps'_fun ak1 ak2 = 
   758 		if ak1=ak2 then NONE else SOME(PureThy.get_thm thy32 (Name ("cp_"^ak1^"_"^ak2^"_inst")))
   759 		in map (fn aki => (List.mapPartial I (map (cps'_fun aki) ak_names))) ak_names end;
   760              (* list of all dj_inst-theorems *)
   761              val djs = 
   762 	       let fun djs_fun (ak1,ak2) = 
   763 		     if ak1=ak2 then NONE else SOME(PureThy.get_thm thy32 (Name ("dj_"^ak2^"_"^ak1)))
   764 	       in List.mapPartial I (map djs_fun (Library.product ak_names ak_names)) end;
   765              (* list of all fs_inst-theorems *)
   766              val fss = map (fn ak => PureThy.get_thm thy32 (Name ("fs_"^ak^"_inst"))) ak_names
   767              (* list of all at_inst-theorems *)
   768              val fs_axs = map (fn ak => PureThy.get_thm thy32 (Name ("fs_"^ak^"1"))) ak_names
   769 
   770              fun inst_pt thms = Library.flat (map (fn ti => instR ti pts) thms);
   771              fun inst_at thms = Library.flat (map (fn ti => instR ti ats) thms);
   772              fun inst_fs thms = Library.flat (map (fn ti => instR ti fss) thms);
   773              fun inst_cp thms cps = Library.flat (inst_mult thms cps);
   774 	     fun inst_pt_at thms = inst_zip ats (inst_pt thms);
   775              fun inst_dj thms = Library.flat (map (fn ti => instR ti djs) thms);
   776 	     fun inst_pt_pt_at_cp thms = inst_cp (inst_zip ats (inst_zip pts (inst_pt thms))) cps;
   777              fun inst_pt_at_fs thms = inst_zip (inst_fs [fs1]) (inst_zip ats (inst_pt thms));
   778 	     fun inst_pt_pt_at_cp thms =
   779 		 let val i_pt_pt_at = inst_zip ats (inst_zip pts (inst_pt thms));
   780                      val i_pt_pt_at_cp = inst_cp i_pt_pt_at cps';
   781 		 in i_pt_pt_at_cp end;
   782              fun inst_pt_pt_at_cp_dj thms = inst_zip djs (inst_pt_pt_at_cp thms);
   783            in
   784             thy32 
   785 	    |>   PureThy.add_thmss [(("alpha", inst_pt_at [abs_fun_eq]),[])]
   786             ||>> PureThy.add_thmss [(("alpha'", inst_pt_at [abs_fun_eq']),[])]
   787             ||>> PureThy.add_thmss [(("alpha_fresh", inst_pt_at [abs_fun_fresh]),[])]
   788             ||>> PureThy.add_thmss [(("alpha_fresh'", inst_pt_at [abs_fun_fresh']),[])]
   789             ||>> PureThy.add_thmss [(("perm_swap", inst_pt_at [pt_swap_bij] @ inst_pt_at [pt_swap_bij']),[])]
   790             ||>> PureThy.add_thmss [(("swap_simps", inst_at at_swap_simps),[])]	 
   791             ||>> PureThy.add_thmss 
   792 	      let val thms1 = inst_pt_at [pt_pi_rev];
   793 		  val thms2 = inst_pt_at [pt_rev_pi];
   794               in [(("perm_pi_simp",thms1 @ thms2),[])] end
   795             ||>> PureThy.add_thmss [(("perm_fresh_fresh", inst_pt_at [pt_fresh_fresh]),[])]
   796             ||>> PureThy.add_thmss [(("perm_bij", inst_pt_at [pt_bij]),[])]
   797             ||>> PureThy.add_thmss 
   798 	      let val thms1 = inst_pt_at [pt_perm_compose];
   799 		  val thms2 = instR cp1 (Library.flat cps');
   800               in [(("perm_compose",thms1 @ thms2),[])] end
   801             ||>> PureThy.add_thmss [(("perm_compose'",inst_pt_at [pt_perm_compose']),[])] 
   802             ||>> PureThy.add_thmss [(("perm_app", inst_pt_at [perm_app]),[])]
   803             ||>> PureThy.add_thmss [(("supp_atm", (inst_at [at_supp]) @ (inst_dj [dj_supp])),[])]
   804             ||>> PureThy.add_thmss [(("exists_fresh", inst_at [at_exists_fresh]),[])]
   805             ||>> PureThy.add_thmss [(("exists_fresh'", inst_at [at_exists_fresh']),[])]
   806             ||>> PureThy.add_thmss [(("all_eqvt", inst_pt_at [all_eqvt]),[NominalThmDecls.eqvt_force_add])] 
   807             ||>> PureThy.add_thmss [(("ex_eqvt", inst_pt_at [ex_eqvt]),[NominalThmDecls.eqvt_force_add])]
   808             ||>> PureThy.add_thmss 
   809 	      let val thms1 = inst_at [at_fresh]
   810 		  val thms2 = inst_dj [at_fresh_ineq]
   811 	      in [(("fresh_atm", thms1 @ thms2),[])] end
   812             ||>> PureThy.add_thmss
   813 	      let val thms1 = filter
   814                 (fn th => case prop_of th of _ $ _ $ Var _ => true | _ => false)
   815                 (List.concat (List.concat perm_defs))
   816               in [(("calc_atm", (inst_at at_calc) @ thms1),[])] end
   817             ||>> PureThy.add_thmss
   818 	      let val thms1 = inst_pt_at [abs_fun_pi]
   819 		  and thms2 = inst_pt_pt_at_cp [abs_fun_pi_ineq]
   820 	      in [(("abs_perm", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end
   821             ||>> PureThy.add_thmss
   822 	      let val thms1 = inst_dj [dj_perm_forget]
   823 		  and thms2 = inst_dj [dj_pp_forget]
   824               in [(("perm_dj", thms1 @ thms2),[])] end
   825             ||>> PureThy.add_thmss
   826 	      let val thms1 = inst_pt_at_fs [fresh_iff]
   827                   and thms2 = inst_pt_at [fresh_iff]
   828 		  and thms3 = inst_pt_pt_at_cp_dj [fresh_iff_ineq]
   829 	    in [(("abs_fresh", thms1 @ thms2 @ thms3),[])] end
   830 	    ||>> PureThy.add_thmss
   831 	      let val thms1 = inst_pt_at [abs_fun_supp]
   832 		  and thms2 = inst_pt_at_fs [abs_fun_supp]
   833 		  and thms3 = inst_pt_pt_at_cp_dj [abs_fun_supp_ineq]
   834 	      in [(("abs_supp", thms1 @ thms2 @ thms3),[])] end
   835             ||>> PureThy.add_thmss
   836 	      let val thms1 = inst_pt_at [fresh_left]
   837 		  and thms2 = inst_pt_pt_at_cp [fresh_left_ineq]
   838 	      in [(("fresh_left", thms1 @ thms2),[])] end
   839             ||>> PureThy.add_thmss
   840 	      let val thms1 = inst_pt_at [fresh_right]
   841 		  and thms2 = inst_pt_pt_at_cp [fresh_right_ineq]
   842 	      in [(("fresh_right", thms1 @ thms2),[])] end
   843             ||>> PureThy.add_thmss
   844 	      let val thms1 = inst_pt_at [fresh_bij]
   845  		  and thms2 = inst_pt_pt_at_cp [fresh_bij_ineq]
   846 	      in [(("fresh_bij", thms1 @ thms2),[])] end
   847             ||>> PureThy.add_thmss
   848 	      let val thms1 = inst_pt_at [fresh_eqvt]
   849                   and thms2 = inst_pt_pt_at_cp_dj [fresh_eqvt_ineq]
   850 	      in [(("fresh_eqvt", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end
   851             ||>> PureThy.add_thmss
   852 	      let val thms1 = inst_pt_at [in_eqvt]
   853 	      in [(("in_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
   854   	    ||>> PureThy.add_thmss
   855 	      let val thms1 = inst_pt_at [eq_eqvt]
   856 	      in [(("eq_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
   857 	    ||>> PureThy.add_thmss
   858 	      let val thms1 = inst_pt_at [set_diff_eqvt]
   859 	      in [(("set_diff_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
   860             ||>> PureThy.add_thmss
   861 	      let val thms1 = inst_pt_at [fresh_aux]
   862 		  and thms2 = inst_pt_pt_at_cp_dj [fresh_perm_app_ineq] 
   863 	      in  [(("fresh_aux", thms1 @ thms2),[])] end  
   864             ||>> PureThy.add_thmss
   865 	      let val thms1 = inst_pt_at [fresh_perm_app]
   866 		  and thms2 = inst_pt_pt_at_cp_dj [fresh_perm_app_ineq] 
   867 	      in  [(("fresh_perm_app", thms1 @ thms2),[])] end 
   868             ||>> PureThy.add_thmss
   869 	      let val thms1 = inst_pt_at [pt_perm_supp]
   870 		  and thms2 = inst_pt_pt_at_cp [pt_perm_supp_ineq] 
   871 	      in  [(("supp_eqvt", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end  
   872             ||>> PureThy.add_thmss [(("fin_supp",fs_axs),[])]
   873 	   end;
   874 
   875     in 
   876       NominalData.map (fold Symtab.update (full_ak_names ~~ map make_atom_info
   877         (pt_ax_classes ~~
   878          fs_ax_classes ~~
   879          map (fn cls => full_ak_names ~~ cls) cp_ax_classes))) thy33
   880     end;
   881 
   882 
   883 (* syntax und parsing *)
   884 structure P = OuterParse and K = OuterKeyword;
   885 
   886 val atom_declP =
   887   OuterSyntax.command "atom_decl" "Declare new kinds of atoms" K.thy_decl
   888     (Scan.repeat1 P.name >> (Toplevel.theory o create_nom_typedecls));
   889 
   890 val _ = OuterSyntax.add_parsers [atom_declP];
   891 
   892 end;