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