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