src/HOL/Nominal/nominal_package.ML
changeset 18068 e8c3d371594e
parent 18067 8b9848d150ba
child 18104 dbe58b104cb9
     1.1 --- a/src/HOL/Nominal/nominal_package.ML	Wed Nov 02 15:31:12 2005 +0100
     1.2 +++ b/src/HOL/Nominal/nominal_package.ML	Wed Nov 02 16:37:39 2005 +0100
     1.3 @@ -2,942 +2,15 @@
     1.4  
     1.5  signature NOMINAL_PACKAGE =
     1.6  sig
     1.7 -  val create_nom_typedecls : string list -> theory -> theory
     1.8    val add_nominal_datatype : bool -> string list -> (string list * bstring * mixfix *
     1.9 -    (bstring * string list * mixfix) list) list -> theory -> theory *
    1.10 -      {distinct : thm list list,
    1.11 -       inject : thm list list,
    1.12 -       exhaustion : thm list,
    1.13 -       rec_thms : thm list,
    1.14 -       case_thms : thm list list,
    1.15 -       split_thms : (thm * thm) list,
    1.16 -       induction : thm,
    1.17 -       size : thm list,
    1.18 -       simps : thm list}
    1.19 -  val setup : (theory -> theory) list
    1.20 +    (bstring * string list * mixfix) list) list -> theory -> theory
    1.21  end
    1.22  
    1.23 -structure NominalPackage (*: NOMINAL_PACKAGE *) =
    1.24 +structure NominalPackage : NOMINAL_PACKAGE =
    1.25  struct
    1.26  
    1.27  open DatatypeAux;
    1.28 -
    1.29 -(* data kind 'HOL/nominal' *)
    1.30 -
    1.31 -structure NominalArgs =
    1.32 -struct
    1.33 -  val name = "HOL/nominal";
    1.34 -  type T = unit Symtab.table;
    1.35 -
    1.36 -  val empty = Symtab.empty;
    1.37 -  val copy = I;
    1.38 -  val extend = I;
    1.39 -  fun merge _ x = Symtab.merge (K true) x;
    1.40 -
    1.41 -  fun print sg tab = ();
    1.42 -end;
    1.43 -
    1.44 -structure NominalData = TheoryDataFun(NominalArgs);
    1.45 -
    1.46 -fun atoms_of thy = map fst (Symtab.dest (NominalData.get thy));
    1.47 -
    1.48 -(* FIXME: add to hologic.ML ? *)
    1.49 -fun mk_listT T = Type ("List.list", [T]);
    1.50 -fun mk_permT T = mk_listT (HOLogic.mk_prodT (T, T));
    1.51 -
    1.52 -fun mk_Cons x xs =
    1.53 -  let val T = fastype_of x
    1.54 -  in Const ("List.list.Cons", T --> mk_listT T --> mk_listT T) $ x $ xs end;
    1.55 -
    1.56 -(* FIXME: should be a library function *)
    1.57 -fun cprod ([], ys) = []
    1.58 -  | cprod (x :: xs, ys) = map (pair x) ys @ cprod (xs, ys);
    1.59 -
    1.60 -(* this function sets up all matters related to atom-  *)
    1.61 -(* kinds; the user specifies a list of atom-kind names *)
    1.62 -(* atom_decl <ak1> ... <akn>                           *)
    1.63 -fun create_nom_typedecls ak_names thy =
    1.64 -  let
    1.65 -    (* declares a type-decl for every atom-kind: *) 
    1.66 -    (* that is typedecl <ak>                     *)
    1.67 -    val thy1 = TypedefPackage.add_typedecls (map (fn x => (x,[],NoSyn)) ak_names) thy;
    1.68 -    
    1.69 -    (* produces a list consisting of pairs:         *)
    1.70 -    (*  fst component is the atom-kind name         *)
    1.71 -    (*  snd component is its type                   *)
    1.72 -    val full_ak_names = map (Sign.intern_type (sign_of thy1)) ak_names;
    1.73 -    val ak_names_types = ak_names ~~ map (Type o rpair []) full_ak_names;
    1.74 -     
    1.75 -    (* adds for every atom-kind an axiom             *)
    1.76 -    (* <ak>_infinite: infinite (UNIV::<ak_type> set) *)
    1.77 -    val (thy2,inf_axs) = PureThy.add_axioms_i (map (fn (ak_name, T) =>
    1.78 -      let 
    1.79 -	val name = ak_name ^ "_infinite"
    1.80 -        val axiom = HOLogic.mk_Trueprop (HOLogic.mk_not
    1.81 -                    (HOLogic.mk_mem (HOLogic.mk_UNIV T,
    1.82 -                     Const ("Finite_Set.Finites", HOLogic.mk_setT (HOLogic.mk_setT T)))))
    1.83 -      in
    1.84 -	((name, axiom), []) 
    1.85 -      end) ak_names_types) thy1;
    1.86 -    
    1.87 -    (* declares a swapping function for every atom-kind, it is         *)
    1.88 -    (* const swap_<ak> :: <akT> * <akT> => <akT> => <akT>              *)
    1.89 -    (* swap_<ak> (a,b) c = (if a=c then b (else if b=c then a else c)) *)
    1.90 -    (* overloades then the general swap-function                       *) 
    1.91 -    val (thy3, swap_eqs) = foldl_map (fn (thy, (ak_name, T)) =>
    1.92 -      let
    1.93 -        val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
    1.94 -        val swap_name = Sign.full_name (sign_of thy) ("swap_" ^ ak_name);
    1.95 -        val a = Free ("a", T);
    1.96 -        val b = Free ("b", T);
    1.97 -        val c = Free ("c", T);
    1.98 -        val ab = Free ("ab", HOLogic.mk_prodT (T, T))
    1.99 -        val cif = Const ("HOL.If", HOLogic.boolT --> T --> T --> T);
   1.100 -        val cswap_akname = Const (swap_name, swapT);
   1.101 -        val cswap = Const ("nominal.swap", swapT)
   1.102 -
   1.103 -        val name = "swap_"^ak_name^"_def";
   1.104 -        val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq
   1.105 -		   (cswap_akname $ HOLogic.mk_prod (a,b) $ c,
   1.106 -                    cif $ HOLogic.mk_eq (a,c) $ b $ (cif $ HOLogic.mk_eq (b,c) $ a $ c)))
   1.107 -        val def2 = Logic.mk_equals (cswap $ ab $ c, cswap_akname $ ab $ c)
   1.108 -      in
   1.109 -        thy |> Theory.add_consts_i [("swap_" ^ ak_name, swapT, NoSyn)] 
   1.110 -            |> (#1 o PureThy.add_defs_i true [((name, def2),[])])
   1.111 -            |> PrimrecPackage.add_primrec_i "" [(("", def1),[])]            
   1.112 -      end) (thy2, ak_names_types);
   1.113 -    
   1.114 -    (* declares a permutation function for every atom-kind acting  *)
   1.115 -    (* on such atoms                                               *)
   1.116 -    (* const <ak>_prm_<ak> :: (<akT> * <akT>)list => akT => akT    *)
   1.117 -    (* <ak>_prm_<ak> []     a = a                                  *)
   1.118 -    (* <ak>_prm_<ak> (x#xs) a = swap_<ak> x (perm xs a)            *)
   1.119 -    val (thy4, prm_eqs) = foldl_map (fn (thy, (ak_name, T)) =>
   1.120 -      let
   1.121 -        val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
   1.122 -        val swap_name = Sign.full_name (sign_of thy) ("swap_" ^ ak_name)
   1.123 -        val prmT = mk_permT T --> T --> T;
   1.124 -        val prm_name = ak_name ^ "_prm_" ^ ak_name;
   1.125 -        val qu_prm_name = Sign.full_name (sign_of thy) prm_name;
   1.126 -        val x  = Free ("x", HOLogic.mk_prodT (T, T));
   1.127 -        val xs = Free ("xs", mk_permT T);
   1.128 -        val a  = Free ("a", T) ;
   1.129 -
   1.130 -        val cnil  = Const ("List.list.Nil", mk_permT T);
   1.131 -        
   1.132 -        val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq (Const (qu_prm_name, prmT) $ cnil $ a, a));
   1.133 -
   1.134 -        val def2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
   1.135 -                   (Const (qu_prm_name, prmT) $ mk_Cons x xs $ a,
   1.136 -                    Const (swap_name, swapT) $ x $ (Const (qu_prm_name, prmT) $ xs $ a)));
   1.137 -      in
   1.138 -        thy |> Theory.add_consts_i [(prm_name, mk_permT T --> T --> T, NoSyn)] 
   1.139 -            |> PrimrecPackage.add_primrec_i "" [(("", def1), []),(("", def2), [])]
   1.140 -      end) (thy3, ak_names_types);
   1.141 -    
   1.142 -    (* defines permutation functions for all combinations of atom-kinds; *)
   1.143 -    (* there are a trivial cases and non-trivial cases                   *)
   1.144 -    (* non-trivial case:                                                 *)
   1.145 -    (* <ak>_prm_<ak>_def:  perm pi a == <ak>_prm_<ak> pi a               *)
   1.146 -    (* trivial case with <ak> != <ak'>                                   *)
   1.147 -    (* <ak>_prm<ak'>_def[simp]:  perm pi a == a                          *)
   1.148 -    (*                                                                   *)
   1.149 -    (* the trivial cases are added to the simplifier, while the non-     *)
   1.150 -    (* have their own rules proved below                                 *)  
   1.151 -    val (thy5, perm_defs) = foldl_map (fn (thy, (ak_name, T)) =>
   1.152 -      foldl_map (fn (thy', (ak_name', T')) =>
   1.153 -        let
   1.154 -          val perm_def_name = ak_name ^ "_prm_" ^ ak_name';
   1.155 -          val pi = Free ("pi", mk_permT T);
   1.156 -          val a  = Free ("a", T');
   1.157 -          val cperm = Const ("nominal.perm", mk_permT T --> T' --> T');
   1.158 -          val cperm_def = Const (Sign.full_name (sign_of thy') perm_def_name, mk_permT T --> T' --> T');
   1.159 -
   1.160 -          val name = ak_name ^ "_prm_" ^ ak_name' ^ "_def";
   1.161 -          val def = Logic.mk_equals
   1.162 -                    (cperm $ pi $ a, if ak_name = ak_name' then cperm_def $ pi $ a else a)
   1.163 -        in
   1.164 -          thy' |> PureThy.add_defs_i true [((name, def),[])] 
   1.165 -        end) (thy, ak_names_types)) (thy4, ak_names_types);
   1.166 -    
   1.167 -    (* proves that every atom-kind is an instance of at *)
   1.168 -    (* lemma at_<ak>_inst:                              *)
   1.169 -    (* at TYPE(<ak>)                                    *)
   1.170 -    val (thy6, prm_cons_thms) = 
   1.171 -      thy5 |> PureThy.add_thms (map (fn (ak_name, T) =>
   1.172 -      let
   1.173 -        val ak_name_qu = Sign.full_name (sign_of thy5) (ak_name);
   1.174 -        val i_type = Type(ak_name_qu,[]);
   1.175 -	val cat = Const ("nominal.at",(Term.itselfT i_type)  --> HOLogic.boolT);
   1.176 -        val at_type = Logic.mk_type i_type;
   1.177 -        val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy5
   1.178 -                                  [Name "at_def",
   1.179 -                                   Name (ak_name ^ "_prm_" ^ ak_name ^ "_def"),
   1.180 -                                   Name (ak_name ^ "_prm_" ^ ak_name ^ ".simps"),
   1.181 -                                   Name ("swap_" ^ ak_name ^ "_def"),
   1.182 -                                   Name ("swap_" ^ ak_name ^ ".simps"),
   1.183 -                                   Name (ak_name ^ "_infinite")]
   1.184 -	    
   1.185 -	val name = "at_"^ak_name^ "_inst";
   1.186 -        val statement = HOLogic.mk_Trueprop (cat $ at_type);
   1.187 -
   1.188 -        val proof = fn _ => auto_tac (claset(),simp_s);
   1.189 -
   1.190 -      in 
   1.191 -        ((name, standard (Goal.prove thy5 [] [] statement proof)), []) 
   1.192 -      end) ak_names_types);
   1.193 -
   1.194 -    (* declares a perm-axclass for every atom-kind               *)
   1.195 -    (* axclass pt_<ak>                                           *)
   1.196 -    (* pt_<ak>1[simp]: perm [] x = x                             *)
   1.197 -    (* pt_<ak>2:       perm (pi1@pi2) x = perm pi1 (perm pi2 x)  *)
   1.198 -    (* pt_<ak>3:       pi1 ~ pi2 ==> perm pi1 x = perm pi2 x     *)
   1.199 -     val (thy7, pt_ax_classes) =  foldl_map (fn (thy, (ak_name, T)) =>
   1.200 -      let 
   1.201 -	  val cl_name = "pt_"^ak_name;
   1.202 -          val ty = TFree("'a",["HOL.type"]);
   1.203 -          val x   = Free ("x", ty);
   1.204 -          val pi1 = Free ("pi1", mk_permT T);
   1.205 -          val pi2 = Free ("pi2", mk_permT T);
   1.206 -          val cperm = Const ("nominal.perm", mk_permT T --> ty --> ty);
   1.207 -          val cnil  = Const ("List.list.Nil", mk_permT T);
   1.208 -          val cappend = Const ("List.op @",mk_permT T --> mk_permT T --> mk_permT T);
   1.209 -          val cprm_eq = Const ("nominal.prm_eq",mk_permT T --> mk_permT T --> HOLogic.boolT);
   1.210 -          (* nil axiom *)
   1.211 -          val axiom1 = HOLogic.mk_Trueprop (HOLogic.mk_eq 
   1.212 -                       (cperm $ cnil $ x, x));
   1.213 -          (* append axiom *)
   1.214 -          val axiom2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
   1.215 -                       (cperm $ (cappend $ pi1 $ pi2) $ x, cperm $ pi1 $ (cperm $ pi2 $ x)));
   1.216 -          (* perm-eq axiom *)
   1.217 -          val axiom3 = Logic.mk_implies
   1.218 -                       (HOLogic.mk_Trueprop (cprm_eq $ pi1 $ pi2),
   1.219 -                        HOLogic.mk_Trueprop (HOLogic.mk_eq (cperm $ pi1 $ x, cperm $ pi2 $ x)));
   1.220 -      in
   1.221 -        thy |> AxClass.add_axclass_i (cl_name, ["HOL.type"])
   1.222 -                [((cl_name^"1", axiom1),[Simplifier.simp_add_global]), 
   1.223 -                 ((cl_name^"2", axiom2),[]),                           
   1.224 -                 ((cl_name^"3", axiom3),[])]                          
   1.225 -      end) (thy6,ak_names_types);
   1.226 -
   1.227 -    (* proves that every pt_<ak>-type together with <ak>-type *)
   1.228 -    (* instance of pt                                         *)
   1.229 -    (* lemma pt_<ak>_inst:                                    *)
   1.230 -    (* pt TYPE('x::pt_<ak>) TYPE(<ak>)                        *)
   1.231 -    val (thy8, prm_inst_thms) = 
   1.232 -      thy7 |> PureThy.add_thms (map (fn (ak_name, T) =>
   1.233 -      let
   1.234 -        val ak_name_qu = Sign.full_name (sign_of thy7) (ak_name);
   1.235 -        val pt_name_qu = Sign.full_name (sign_of thy7) ("pt_"^ak_name);
   1.236 -        val i_type1 = TFree("'x",[pt_name_qu]);
   1.237 -        val i_type2 = Type(ak_name_qu,[]);
   1.238 -	val cpt = Const ("nominal.pt",(Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
   1.239 -        val pt_type = Logic.mk_type i_type1;
   1.240 -        val at_type = Logic.mk_type i_type2;
   1.241 -        val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy7
   1.242 -                                  [Name "pt_def",
   1.243 -                                   Name ("pt_" ^ ak_name ^ "1"),
   1.244 -                                   Name ("pt_" ^ ak_name ^ "2"),
   1.245 -                                   Name ("pt_" ^ ak_name ^ "3")];
   1.246 -
   1.247 -	val name = "pt_"^ak_name^ "_inst";
   1.248 -        val statement = HOLogic.mk_Trueprop (cpt $ pt_type $ at_type);
   1.249 -
   1.250 -        val proof = fn _ => auto_tac (claset(),simp_s);
   1.251 -      in 
   1.252 -        ((name, standard (Goal.prove thy7 [] [] statement proof)), []) 
   1.253 -      end) ak_names_types);
   1.254 -
   1.255 -     (* declares an fs-axclass for every atom-kind       *)
   1.256 -     (* axclass fs_<ak>                                  *)
   1.257 -     (* fs_<ak>1: finite ((supp x)::<ak> set)            *)
   1.258 -     val (thy11, fs_ax_classes) =  foldl_map (fn (thy, (ak_name, T)) =>
   1.259 -       let 
   1.260 -	  val cl_name = "fs_"^ak_name;
   1.261 -	  val pt_name = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.262 -          val ty = TFree("'a",["HOL.type"]);
   1.263 -          val x   = Free ("x", ty);
   1.264 -          val csupp    = Const ("nominal.supp", ty --> HOLogic.mk_setT T);
   1.265 -          val cfinites = Const ("Finite_Set.Finites", HOLogic.mk_setT (HOLogic.mk_setT T))
   1.266 -          
   1.267 -          val axiom1   = HOLogic.mk_Trueprop (HOLogic.mk_mem (csupp $ x, cfinites));
   1.268 -
   1.269 -       in  
   1.270 -        thy |> AxClass.add_axclass_i (cl_name, [pt_name]) [((cl_name^"1", axiom1),[])]            
   1.271 -       end) (thy8,ak_names_types); 
   1.272 -
   1.273 -     (* proves that every fs_<ak>-type together with <ak>-type   *)
   1.274 -     (* instance of fs-type                                      *)
   1.275 -     (* lemma abst_<ak>_inst:                                    *)
   1.276 -     (* fs TYPE('x::pt_<ak>) TYPE (<ak>)                         *)
   1.277 -     val (thy12, fs_inst_thms) = 
   1.278 -       thy11 |> PureThy.add_thms (map (fn (ak_name, T) =>
   1.279 -       let
   1.280 -         val ak_name_qu = Sign.full_name (sign_of thy11) (ak_name);
   1.281 -         val fs_name_qu = Sign.full_name (sign_of thy11) ("fs_"^ak_name);
   1.282 -         val i_type1 = TFree("'x",[fs_name_qu]);
   1.283 -         val i_type2 = Type(ak_name_qu,[]);
   1.284 - 	 val cfs = Const ("nominal.fs", 
   1.285 -                                 (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
   1.286 -         val fs_type = Logic.mk_type i_type1;
   1.287 -         val at_type = Logic.mk_type i_type2;
   1.288 -	 val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy11
   1.289 -                                   [Name "fs_def",
   1.290 -                                    Name ("fs_" ^ ak_name ^ "1")];
   1.291 -    
   1.292 -	 val name = "fs_"^ak_name^ "_inst";
   1.293 -         val statement = HOLogic.mk_Trueprop (cfs $ fs_type $ at_type);
   1.294 -
   1.295 -         val proof = fn _ => auto_tac (claset(),simp_s);
   1.296 -       in 
   1.297 -         ((name, standard (Goal.prove thy11 [] [] statement proof)), []) 
   1.298 -       end) ak_names_types);
   1.299 -
   1.300 -       (* declares for every atom-kind combination an axclass            *)
   1.301 -       (* cp_<ak1>_<ak2> giving a composition property                   *)
   1.302 -       (* cp_<ak1>_<ak2>1: pi1 o pi2 o x = (pi1 o pi2) o (pi1 o x)       *)
   1.303 -        val (thy12b,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.304 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.305 -	     let
   1.306 -	       val cl_name = "cp_"^ak_name^"_"^ak_name';
   1.307 -	       val ty = TFree("'a",["HOL.type"]);
   1.308 -               val x   = Free ("x", ty);
   1.309 -               val pi1 = Free ("pi1", mk_permT T);
   1.310 -	       val pi2 = Free ("pi2", mk_permT T');                  
   1.311 -	       val cperm1 = Const ("nominal.perm", mk_permT T  --> ty --> ty);
   1.312 -               val cperm2 = Const ("nominal.perm", mk_permT T' --> ty --> ty);
   1.313 -               val cperm3 = Const ("nominal.perm", mk_permT T  --> mk_permT T' --> mk_permT T');
   1.314 -
   1.315 -               val ax1   = HOLogic.mk_Trueprop 
   1.316 -			   (HOLogic.mk_eq (cperm1 $ pi1 $ (cperm2 $ pi2 $ x), 
   1.317 -                                           cperm2 $ (cperm3 $ pi1 $ pi2) $ (cperm1 $ pi1 $ x)));
   1.318 -	       in  
   1.319 -	       (fst (AxClass.add_axclass_i (cl_name, ["HOL.type"]) [((cl_name^"1", ax1),[])] thy'),())  
   1.320 -	       end) 
   1.321 -	   (thy, ak_names_types)) (thy12, ak_names_types)
   1.322 -
   1.323 -        (* proves for every <ak>-combination a cp_<ak1>_<ak2>_inst theorem;     *)
   1.324 -        (* lemma cp_<ak1>_<ak2>_inst:                                           *)
   1.325 -        (* cp TYPE('a::cp_<ak1>_<ak2>) TYPE(<ak1>) TYPE(<ak2>)                  *)
   1.326 -        val (thy12c, cp_thms) = foldl_map (fn (thy, (ak_name, T)) =>
   1.327 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.328 -           let
   1.329 -             val ak_name_qu  = Sign.full_name (sign_of thy') (ak_name);
   1.330 -	     val ak_name_qu' = Sign.full_name (sign_of thy') (ak_name');
   1.331 -             val cp_name_qu  = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.332 -             val i_type0 = TFree("'a",[cp_name_qu]);
   1.333 -             val i_type1 = Type(ak_name_qu,[]);
   1.334 -             val i_type2 = Type(ak_name_qu',[]);
   1.335 -	     val ccp = Const ("nominal.cp",
   1.336 -                             (Term.itselfT i_type0)-->(Term.itselfT i_type1)-->
   1.337 -                                                      (Term.itselfT i_type2)-->HOLogic.boolT);
   1.338 -             val at_type  = Logic.mk_type i_type1;
   1.339 -             val at_type' = Logic.mk_type i_type2;
   1.340 -	     val cp_type  = Logic.mk_type i_type0;
   1.341 -             val simp_s   = HOL_basic_ss addsimps PureThy.get_thmss thy' [(Name "cp_def")];
   1.342 -	     val cp1      = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"1"));
   1.343 -
   1.344 -	     val name = "cp_"^ak_name^ "_"^ak_name'^"_inst";
   1.345 -             val statement = HOLogic.mk_Trueprop (ccp $ cp_type $ at_type $ at_type');
   1.346 -
   1.347 -             val proof = fn _ => EVERY [auto_tac (claset(),simp_s), rtac cp1 1];
   1.348 -	   in
   1.349 -	     thy' |> PureThy.add_thms 
   1.350 -                    [((name, standard (Goal.prove thy' [] [] statement proof)), [])]
   1.351 -	   end) 
   1.352 -	   (thy, ak_names_types)) (thy12b, ak_names_types);
   1.353 -       
   1.354 -        (* proves for every non-trivial <ak>-combination a disjointness   *)
   1.355 -        (* theorem; i.e. <ak1> != <ak2>                                   *)
   1.356 -        (* lemma ds_<ak1>_<ak2>:                                          *)
   1.357 -        (* dj TYPE(<ak1>) TYPE(<ak2>)                                     *)
   1.358 -        val (thy12d, dj_thms) = foldl_map (fn (thy, (ak_name, T)) =>
   1.359 -	  foldl_map (fn (thy', (ak_name', T')) =>
   1.360 -          (if not (ak_name = ak_name') 
   1.361 -           then 
   1.362 -	       let
   1.363 -		 val ak_name_qu  = Sign.full_name (sign_of thy') (ak_name);
   1.364 -	         val ak_name_qu' = Sign.full_name (sign_of thy') (ak_name');
   1.365 -                 val i_type1 = Type(ak_name_qu,[]);
   1.366 -                 val i_type2 = Type(ak_name_qu',[]);
   1.367 -	         val cdj = Const ("nominal.disjoint",
   1.368 -                           (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
   1.369 -                 val at_type  = Logic.mk_type i_type1;
   1.370 -                 val at_type' = Logic.mk_type i_type2;
   1.371 -                 val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy' 
   1.372 -					   [Name "disjoint_def",
   1.373 -                                            Name (ak_name^"_prm_"^ak_name'^"_def"),
   1.374 -                                            Name (ak_name'^"_prm_"^ak_name^"_def")];
   1.375 -
   1.376 -	         val name = "dj_"^ak_name^"_"^ak_name';
   1.377 -                 val statement = HOLogic.mk_Trueprop (cdj $ at_type $ at_type');
   1.378 -
   1.379 -                 val proof = fn _ => auto_tac (claset(),simp_s);
   1.380 -	       in
   1.381 -		   thy' |> PureThy.add_thms 
   1.382 -                        [((name, standard (Goal.prove thy' [] [] statement proof)), []) ]
   1.383 -	       end
   1.384 -           else 
   1.385 -            (thy',[])))  (* do nothing branch, if ak_name = ak_name' *) 
   1.386 -	   (thy, ak_names_types)) (thy12c, ak_names_types);
   1.387 -
   1.388 -     (*<<<<<<<  pt_<ak> class instances  >>>>>>>*)
   1.389 -     (*=========================================*)
   1.390 -     
   1.391 -     (* some frequently used theorems *)
   1.392 -      val pt1 = PureThy.get_thm thy12c (Name "pt1");
   1.393 -      val pt2 = PureThy.get_thm thy12c (Name "pt2");
   1.394 -      val pt3 = PureThy.get_thm thy12c (Name "pt3");
   1.395 -      val at_pt_inst    = PureThy.get_thm thy12c (Name "at_pt_inst");
   1.396 -      val pt_bool_inst  = PureThy.get_thm thy12c (Name "pt_bool_inst");
   1.397 -      val pt_set_inst   = PureThy.get_thm thy12c (Name "pt_set_inst"); 
   1.398 -      val pt_unit_inst  = PureThy.get_thm thy12c (Name "pt_unit_inst");
   1.399 -      val pt_prod_inst  = PureThy.get_thm thy12c (Name "pt_prod_inst"); 
   1.400 -      val pt_list_inst  = PureThy.get_thm thy12c (Name "pt_list_inst");   
   1.401 -      val pt_optn_inst  = PureThy.get_thm thy12c (Name "pt_option_inst");   
   1.402 -      val pt_noptn_inst = PureThy.get_thm thy12c (Name "pt_noption_inst");   
   1.403 -      val pt_fun_inst   = PureThy.get_thm thy12c (Name "pt_fun_inst");     
   1.404 -
   1.405 -     (* for all atom-kind combination shows that         *)
   1.406 -     (* every <ak> is an instance of pt_<ai>             *)
   1.407 -     val (thy13,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.408 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.409 -          (if ak_name = ak_name'
   1.410 -	   then
   1.411 -	     let
   1.412 -	      val qu_name =  Sign.full_name (sign_of thy') ak_name;
   1.413 -              val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
   1.414 -              val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name ^"_inst"));
   1.415 -              val proof = EVERY [AxClass.intro_classes_tac [],
   1.416 -                                 rtac ((at_inst RS at_pt_inst) RS pt1) 1,
   1.417 -                                 rtac ((at_inst RS at_pt_inst) RS pt2) 1,
   1.418 -                                 rtac ((at_inst RS at_pt_inst) RS pt3) 1,
   1.419 -                                 atac 1];
   1.420 -             in 
   1.421 -	      (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy',()) 
   1.422 -             end
   1.423 -           else 
   1.424 -             let
   1.425 -	      val qu_name' = Sign.full_name (sign_of thy') ak_name';
   1.426 -              val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
   1.427 -              val simp_s = HOL_basic_ss addsimps 
   1.428 -                           PureThy.get_thmss thy' [Name (ak_name^"_prm_"^ak_name'^"_def")];  
   1.429 -              val proof = EVERY [AxClass.intro_classes_tac [], auto_tac (claset(),simp_s)];
   1.430 -             in 
   1.431 -	      (AxClass.add_inst_arity_i (qu_name',[],[qu_class]) proof thy',()) 
   1.432 -             end)) 
   1.433 -	     (thy, ak_names_types)) (thy12c, ak_names_types);
   1.434 -
   1.435 -     (* shows that bool is an instance of pt_<ak>     *)
   1.436 -     (* uses the theorem pt_bool_inst                 *)
   1.437 -     val (thy14,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.438 -       let
   1.439 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.440 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.441 -                             rtac (pt_bool_inst RS pt1) 1,
   1.442 -                             rtac (pt_bool_inst RS pt2) 1,
   1.443 -                             rtac (pt_bool_inst RS pt3) 1,
   1.444 -                             atac 1];
   1.445 -       in 
   1.446 -	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
   1.447 -       end) (thy13,ak_names_types); 
   1.448 -
   1.449 -     (* shows that set(pt_<ak>) is an instance of pt_<ak>          *)
   1.450 -     (* unfolds the permutation definition and applies pt_<ak>i    *)
   1.451 -     val (thy15,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.452 -       let
   1.453 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.454 -          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));  
   1.455 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.456 -                             rtac ((pt_inst RS pt_set_inst) RS pt1) 1,
   1.457 -                             rtac ((pt_inst RS pt_set_inst) RS pt2) 1,
   1.458 -                             rtac ((pt_inst RS pt_set_inst) RS pt3) 1,
   1.459 -                             atac 1];
   1.460 -       in 
   1.461 -	 (AxClass.add_inst_arity_i ("set",[[qu_class]],[qu_class]) proof thy,()) 
   1.462 -       end) (thy14,ak_names_types); 
   1.463 -
   1.464 -     (* shows that unit is an instance of pt_<ak>          *)
   1.465 -     val (thy16,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.466 -       let
   1.467 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.468 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.469 -                             rtac (pt_unit_inst RS pt1) 1,
   1.470 -                             rtac (pt_unit_inst RS pt2) 1,
   1.471 -                             rtac (pt_unit_inst RS pt3) 1,
   1.472 -                             atac 1];
   1.473 -       in 
   1.474 -	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
   1.475 -       end) (thy15,ak_names_types); 
   1.476 -
   1.477 -     (* shows that *(pt_<ak>,pt_<ak>) is an instance of pt_<ak> *)
   1.478 -     (* uses the theorem pt_prod_inst and pt_<ak>_inst          *)
   1.479 -     val (thy17,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.480 -       let
   1.481 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.482 -          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));  
   1.483 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.484 -                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt1) 1,
   1.485 -                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt2) 1,
   1.486 -                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt3) 1,
   1.487 -                             atac 1];
   1.488 -       in 
   1.489 -          (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
   1.490 -       end) (thy16,ak_names_types); 
   1.491 -
   1.492 -     (* shows that list(pt_<ak>) is an instance of pt_<ak>     *)
   1.493 -     (* uses the theorem pt_list_inst and pt_<ak>_inst         *)
   1.494 -     val (thy18,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.495 -       let
   1.496 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.497 -          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   1.498 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.499 -                             rtac ((pt_inst RS pt_list_inst) RS pt1) 1,
   1.500 -                             rtac ((pt_inst RS pt_list_inst) RS pt2) 1,
   1.501 -                             rtac ((pt_inst RS pt_list_inst) RS pt3) 1,
   1.502 -                             atac 1];      
   1.503 -       in 
   1.504 -	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
   1.505 -       end) (thy17,ak_names_types); 
   1.506 -
   1.507 -     (* shows that option(pt_<ak>) is an instance of pt_<ak>   *)
   1.508 -     (* uses the theorem pt_option_inst and pt_<ak>_inst       *)
   1.509 -     val (thy18a,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.510 -       let
   1.511 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.512 -          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   1.513 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.514 -                             rtac ((pt_inst RS pt_optn_inst) RS pt1) 1,
   1.515 -                             rtac ((pt_inst RS pt_optn_inst) RS pt2) 1,
   1.516 -                             rtac ((pt_inst RS pt_optn_inst) RS pt3) 1,
   1.517 -                             atac 1];      
   1.518 -       in 
   1.519 -	 (AxClass.add_inst_arity_i ("Datatype.option",[[qu_class]],[qu_class]) proof thy,()) 
   1.520 -       end) (thy18,ak_names_types); 
   1.521 -
   1.522 -     (* shows that nOption(pt_<ak>) is an instance of pt_<ak>   *)
   1.523 -     (* uses the theorem pt_option_inst and pt_<ak>_inst       *)
   1.524 -     val (thy18b,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.525 -       let
   1.526 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.527 -          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   1.528 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.529 -                             rtac ((pt_inst RS pt_noptn_inst) RS pt1) 1,
   1.530 -                             rtac ((pt_inst RS pt_noptn_inst) RS pt2) 1,
   1.531 -                             rtac ((pt_inst RS pt_noptn_inst) RS pt3) 1,
   1.532 -                             atac 1];      
   1.533 -       in 
   1.534 -	 (AxClass.add_inst_arity_i ("nominal.nOption",[[qu_class]],[qu_class]) proof thy,()) 
   1.535 -       end) (thy18a,ak_names_types); 
   1.536 -
   1.537 -
   1.538 -     (* shows that fun(pt_<ak>,pt_<ak>) is an instance of pt_<ak>     *)
   1.539 -     (* uses the theorem pt_list_inst and pt_<ak>_inst                *)
   1.540 -     val (thy19,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.541 -       let
   1.542 -          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   1.543 -          val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   1.544 -          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   1.545 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.546 -                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt1) 1,
   1.547 -                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt2) 1,
   1.548 -                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt3) 1,
   1.549 -                             atac 1];      
   1.550 -       in 
   1.551 -	 (AxClass.add_inst_arity_i ("fun",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
   1.552 -       end) (thy18b,ak_names_types);
   1.553 -
   1.554 -       (*<<<<<<<  fs_<ak> class instances  >>>>>>>*)
   1.555 -       (*=========================================*)
   1.556 -       val fs1          = PureThy.get_thm thy19 (Name "fs1");
   1.557 -       val fs_at_inst   = PureThy.get_thm thy19 (Name "fs_at_inst");
   1.558 -       val fs_unit_inst = PureThy.get_thm thy19 (Name "fs_unit_inst");
   1.559 -       val fs_bool_inst = PureThy.get_thm thy19 (Name "fs_bool_inst");
   1.560 -       val fs_prod_inst = PureThy.get_thm thy19 (Name "fs_prod_inst");
   1.561 -       val fs_list_inst = PureThy.get_thm thy19 (Name "fs_list_inst");
   1.562 -
   1.563 -       (* shows that <ak> is an instance of fs_<ak>     *)
   1.564 -       (* uses the theorem at_<ak>_inst                 *)
   1.565 -       val (thy20,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.566 -       let
   1.567 -          val qu_name =  Sign.full_name (sign_of thy) ak_name;
   1.568 -          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   1.569 -          val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   1.570 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.571 -                             rtac ((at_thm RS fs_at_inst) RS fs1) 1];      
   1.572 -       in 
   1.573 -	 (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy,()) 
   1.574 -       end) (thy19,ak_names_types);  
   1.575 -
   1.576 -       (* shows that unit is an instance of fs_<ak>     *)
   1.577 -       (* uses the theorem fs_unit_inst                 *)
   1.578 -       val (thy21,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.579 -       let
   1.580 -          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   1.581 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.582 -                             rtac (fs_unit_inst RS fs1) 1];      
   1.583 -       in 
   1.584 -	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
   1.585 -       end) (thy20,ak_names_types);  
   1.586 -
   1.587 -       (* shows that bool is an instance of fs_<ak>     *)
   1.588 -       (* uses the theorem fs_bool_inst                 *)
   1.589 -       val (thy22,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.590 -       let
   1.591 -          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   1.592 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.593 -                             rtac (fs_bool_inst RS fs1) 1];      
   1.594 -       in 
   1.595 -	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
   1.596 -       end) (thy21,ak_names_types);  
   1.597 -
   1.598 -       (* shows that *(fs_<ak>,fs_<ak>) is an instance of fs_<ak>     *)
   1.599 -       (* uses the theorem fs_prod_inst                               *)
   1.600 -       val (thy23,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.601 -       let
   1.602 -          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   1.603 -          val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
   1.604 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.605 -                             rtac ((fs_inst RS (fs_inst RS fs_prod_inst)) RS fs1) 1];      
   1.606 -       in 
   1.607 -	 (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
   1.608 -       end) (thy22,ak_names_types);  
   1.609 -
   1.610 -       (* shows that list(fs_<ak>) is an instance of fs_<ak>     *)
   1.611 -       (* uses the theorem fs_list_inst                          *)
   1.612 -       val (thy24,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.613 -       let
   1.614 -          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   1.615 -          val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
   1.616 -          val proof = EVERY [AxClass.intro_classes_tac [],
   1.617 -                              rtac ((fs_inst RS fs_list_inst) RS fs1) 1];      
   1.618 -       in 
   1.619 -	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
   1.620 -       end) (thy23,ak_names_types);  
   1.621 -	   
   1.622 -       (*<<<<<<<  cp_<ak>_<ai> class instances  >>>>>>>*)
   1.623 -       (*==============================================*)
   1.624 -       val cp1             = PureThy.get_thm thy24 (Name "cp1");
   1.625 -       val cp_unit_inst    = PureThy.get_thm thy24 (Name "cp_unit_inst");
   1.626 -       val cp_bool_inst    = PureThy.get_thm thy24 (Name "cp_bool_inst");
   1.627 -       val cp_prod_inst    = PureThy.get_thm thy24 (Name "cp_prod_inst");
   1.628 -       val cp_list_inst    = PureThy.get_thm thy24 (Name "cp_list_inst");
   1.629 -       val cp_fun_inst     = PureThy.get_thm thy24 (Name "cp_fun_inst");
   1.630 -       val cp_option_inst  = PureThy.get_thm thy24 (Name "cp_option_inst");
   1.631 -       val cp_noption_inst = PureThy.get_thm thy24 (Name "cp_noption_inst");
   1.632 -       val pt_perm_compose = PureThy.get_thm thy24 (Name "pt_perm_compose");
   1.633 -       val dj_pp_forget    = PureThy.get_thm thy24 (Name "dj_perm_perm_forget");
   1.634 -
   1.635 -       (* shows that <aj> is an instance of cp_<ak>_<ai>  *)
   1.636 -       (* that needs a three-nested loop *)
   1.637 -       val (thy25,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.638 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.639 -          foldl_map (fn (thy'', (ak_name'', T'')) =>
   1.640 -            let
   1.641 -              val qu_name =  Sign.full_name (sign_of thy'') ak_name;
   1.642 -              val qu_class = Sign.full_name (sign_of thy'') ("cp_"^ak_name'^"_"^ak_name'');
   1.643 -              val proof =
   1.644 -                (if (ak_name'=ak_name'') then 
   1.645 -		  (let
   1.646 -                    val pt_inst  = PureThy.get_thm thy'' (Name ("pt_"^ak_name''^"_inst"));
   1.647 -		    val at_inst  = PureThy.get_thm thy'' (Name ("at_"^ak_name''^"_inst"));
   1.648 -                  in 
   1.649 -		   EVERY [AxClass.intro_classes_tac [], 
   1.650 -                          rtac (at_inst RS (pt_inst RS pt_perm_compose)) 1]
   1.651 -                  end)
   1.652 -		else
   1.653 -		  (let 
   1.654 -                     val dj_inst  = PureThy.get_thm thy'' (Name ("dj_"^ak_name''^"_"^ak_name'));
   1.655 -		     val simp_s = HOL_basic_ss addsimps 
   1.656 -                                        ((dj_inst RS dj_pp_forget)::
   1.657 -                                         (PureThy.get_thmss thy'' 
   1.658 -					   [Name (ak_name' ^"_prm_"^ak_name^"_def"),
   1.659 -                                            Name (ak_name''^"_prm_"^ak_name^"_def")]));  
   1.660 -		  in 
   1.661 -                    EVERY [AxClass.intro_classes_tac [], simp_tac simp_s 1]
   1.662 -                  end))
   1.663 -	      in
   1.664 -                (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy'',())
   1.665 -	      end)
   1.666 -	   (thy', ak_names_types)) (thy, ak_names_types)) (thy24, ak_names_types);
   1.667 -      
   1.668 -       (* shows that unit is an instance of cp_<ak>_<ai>     *)
   1.669 -       (* for every <ak>-combination                         *)
   1.670 -       val (thy26,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.671 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.672 -          let
   1.673 -            val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.674 -            val proof = EVERY [AxClass.intro_classes_tac [],rtac (cp_unit_inst RS cp1) 1];     
   1.675 -	  in
   1.676 -            (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy',())
   1.677 -	  end) 
   1.678 -	   (thy, ak_names_types)) (thy25, ak_names_types);
   1.679 -       
   1.680 -       (* shows that bool is an instance of cp_<ak>_<ai>     *)
   1.681 -       (* for every <ak>-combination                         *)
   1.682 -       val (thy27,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.683 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.684 -           let
   1.685 -	     val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.686 -             val proof = EVERY [AxClass.intro_classes_tac [], rtac (cp_bool_inst RS cp1) 1];     
   1.687 -	   in
   1.688 -             (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy',())
   1.689 -	   end) 
   1.690 -	   (thy, ak_names_types)) (thy26, ak_names_types);
   1.691 -
   1.692 -       (* shows that prod is an instance of cp_<ak>_<ai>     *)
   1.693 -       (* for every <ak>-combination                         *)
   1.694 -       val (thy28,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.695 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.696 -          let
   1.697 -	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.698 -            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.699 -            val proof = EVERY [AxClass.intro_classes_tac [],
   1.700 -                               rtac ((cp_inst RS (cp_inst RS cp_prod_inst)) RS cp1) 1];     
   1.701 -	  in
   1.702 -            (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy',())
   1.703 -	  end)  
   1.704 -	  (thy, ak_names_types)) (thy27, ak_names_types);
   1.705 -
   1.706 -       (* shows that list is an instance of cp_<ak>_<ai>     *)
   1.707 -       (* for every <ak>-combination                         *)
   1.708 -       val (thy29,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.709 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.710 -           let
   1.711 -	     val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.712 -             val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.713 -             val proof = EVERY [AxClass.intro_classes_tac [],
   1.714 -                                rtac ((cp_inst RS cp_list_inst) RS cp1) 1];     
   1.715 -	   in
   1.716 -            (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy',())
   1.717 -	   end) 
   1.718 -	   (thy, ak_names_types)) (thy28, ak_names_types);
   1.719 -
   1.720 -       (* shows that function is an instance of cp_<ak>_<ai>     *)
   1.721 -       (* for every <ak>-combination                             *)
   1.722 -       val (thy30,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.723 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.724 -          let
   1.725 -	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.726 -            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.727 -            val pt_inst  = PureThy.get_thm thy' (Name ("pt_"^ak_name^"_inst"));
   1.728 -            val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name^"_inst"));
   1.729 -            val proof = EVERY [AxClass.intro_classes_tac [],
   1.730 -                    rtac ((at_inst RS (pt_inst RS (cp_inst RS (cp_inst RS cp_fun_inst)))) RS cp1) 1];  
   1.731 -	  in
   1.732 -            (AxClass.add_inst_arity_i ("fun",[[qu_class],[qu_class]],[qu_class]) proof thy',())
   1.733 -	  end) 
   1.734 -	  (thy, ak_names_types)) (thy29, ak_names_types);
   1.735 -
   1.736 -       (* shows that option is an instance of cp_<ak>_<ai>     *)
   1.737 -       (* for every <ak>-combination                           *)
   1.738 -       val (thy31,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.739 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.740 -          let
   1.741 -	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.742 -            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.743 -            val proof = EVERY [AxClass.intro_classes_tac [],
   1.744 -                               rtac ((cp_inst RS cp_option_inst) RS cp1) 1];     
   1.745 -	  in
   1.746 -            (AxClass.add_inst_arity_i ("Datatype.option",[[qu_class]],[qu_class]) proof thy',())
   1.747 -	  end) 
   1.748 -	  (thy, ak_names_types)) (thy30, ak_names_types);
   1.749 -
   1.750 -       (* shows that nOption is an instance of cp_<ak>_<ai>     *)
   1.751 -       (* for every <ak>-combination                            *)
   1.752 -       val (thy32,_) = foldl_map (fn (thy, (ak_name, T)) =>
   1.753 -	 foldl_map (fn (thy', (ak_name', T')) =>
   1.754 -          let
   1.755 -	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
   1.756 -            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.757 -            val proof = EVERY [AxClass.intro_classes_tac [],
   1.758 -                               rtac ((cp_inst RS cp_noption_inst) RS cp1) 1];     
   1.759 -	  in
   1.760 -           (AxClass.add_inst_arity_i ("nominal.nOption",[[qu_class]],[qu_class]) proof thy',())
   1.761 -	  end) 
   1.762 -	  (thy, ak_names_types)) (thy31, ak_names_types);
   1.763 -
   1.764 -       (* abbreviations for some collection of rules *)
   1.765 -       (*============================================*)
   1.766 -       val abs_fun_pi        = PureThy.get_thm thy32 (Name ("nominal.abs_fun_pi"));
   1.767 -       val abs_fun_pi_ineq   = PureThy.get_thm thy32 (Name ("nominal.abs_fun_pi_ineq"));
   1.768 -       val abs_fun_eq        = PureThy.get_thm thy32 (Name ("nominal.abs_fun_eq"));
   1.769 -       val dj_perm_forget    = PureThy.get_thm thy32 (Name ("nominal.dj_perm_forget"));
   1.770 -       val dj_pp_forget      = PureThy.get_thm thy32 (Name ("nominal.dj_perm_perm_forget"));
   1.771 -       val fresh_iff         = PureThy.get_thm thy32 (Name ("nominal.fresh_abs_fun_iff"));
   1.772 -       val fresh_iff_ineq    = PureThy.get_thm thy32 (Name ("nominal.fresh_abs_fun_iff_ineq"));
   1.773 -       val abs_fun_supp      = PureThy.get_thm thy32 (Name ("nominal.abs_fun_supp"));
   1.774 -       val abs_fun_supp_ineq = PureThy.get_thm thy32 (Name ("nominal.abs_fun_supp_ineq"));
   1.775 -       val pt_swap_bij       = PureThy.get_thm thy32 (Name ("nominal.pt_swap_bij"));
   1.776 -       val pt_fresh_fresh    = PureThy.get_thm thy32 (Name ("nominal.pt_fresh_fresh"));
   1.777 -       val pt_bij            = PureThy.get_thm thy32 (Name ("nominal.pt_bij"));
   1.778 -       val pt_perm_compose   = PureThy.get_thm thy32 (Name ("nominal.pt_perm_compose"));
   1.779 -       val perm_eq_app       = PureThy.get_thm thy32 (Name ("nominal.perm_eq_app"));
   1.780 -       val at_fresh          = PureThy.get_thm thy32 (Name ("nominal.at_fresh"));
   1.781 -       val at_calc           = PureThy.get_thms thy32 (Name ("nominal.at_calc"));
   1.782 -       val at_supp           = PureThy.get_thm thy32 (Name ("nominal.at_supp"));
   1.783 -       val dj_supp           = PureThy.get_thm thy32 (Name ("nominal.dj_supp"));
   1.784 -
   1.785 -       (* abs_perm collects all lemmas for simplifying a permutation *)
   1.786 -       (* in front of an abs_fun                                     *)
   1.787 -       val (thy33,_) = 
   1.788 -	   let 
   1.789 -	     val name = "abs_perm"
   1.790 -             val thm_list = Library.flat (map (fn (ak_name, T) =>
   1.791 -	        let	
   1.792 -		  val at_inst = PureThy.get_thm thy32 (Name ("at_"^ak_name^"_inst"));
   1.793 -		  val pt_inst = PureThy.get_thm thy32 (Name ("pt_"^ak_name^"_inst"));	      
   1.794 -	          val thm = [pt_inst, at_inst] MRS abs_fun_pi
   1.795 -                  val thm_list = map (fn (ak_name', T') =>
   1.796 -                     let
   1.797 -                      val cp_inst = PureThy.get_thm thy32 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.798 -	             in
   1.799 -                     [pt_inst, pt_inst, at_inst, cp_inst] MRS abs_fun_pi_ineq
   1.800 -	             end) ak_names_types;
   1.801 -                 in thm::thm_list end) (ak_names_types))
   1.802 -           in
   1.803 -             (PureThy.add_thmss [((name, thm_list),[])] thy32)
   1.804 -           end;
   1.805 -
   1.806 -       val (thy34,_) = 
   1.807 -	 let 
   1.808 -             (* takes a theorem and a list of theorems        *)
   1.809 -             (* produces a list of theorems of the form       *)
   1.810 -             (* [t1 RS thm,..,tn RS thm] where t1..tn in thms *) 
   1.811 -             fun instantiate thm thms = map (fn ti => ti RS thm) thms;
   1.812 -               
   1.813 -             (* takes two theorem lists (hopefully of the same length)           *)
   1.814 -             (* produces a list of theorems of the form                          *)
   1.815 -             (* [t1 RS m1,..,tn RS mn] where t1..tn in thms1 and m1..mn in thms2 *) 
   1.816 -             fun instantiate_zip thms1 thms2 = 
   1.817 -		 map (fn (t1,t2) => t1 RS t2) (thms1 ~~ thms2);
   1.818 -
   1.819 -             (* list of all at_inst-theorems *)
   1.820 -             val ats = map (fn ak => PureThy.get_thm thy33 (Name ("at_"^ak^"_inst"))) ak_names
   1.821 -             (* list of all pt_inst-theorems *)
   1.822 -             val pts = map (fn ak => PureThy.get_thm thy33 (Name ("pt_"^ak^"_inst"))) ak_names
   1.823 -             (* list of all cp_inst-theorems *)
   1.824 -             val cps = 
   1.825 -	       let fun cps_fun (ak1,ak2) = PureThy.get_thm thy33 (Name ("cp_"^ak1^"_"^ak2^"_inst"))
   1.826 -	       in map cps_fun (cprod (ak_names,ak_names)) end;	
   1.827 -             (* list of all dj_inst-theorems *)
   1.828 -             val djs = 
   1.829 -	       let fun djs_fun (ak1,ak2) = 
   1.830 -		    if ak1=ak2 
   1.831 -		    then NONE
   1.832 -		    else SOME(PureThy.get_thm thy33 (Name ("dj_"^ak1^"_"^ak2)))
   1.833 -	       in List.mapPartial I (map djs_fun (cprod (ak_names,ak_names))) end;	
   1.834 -
   1.835 -             fun inst_pt thms = Library.flat (map (fn ti => instantiate ti pts) thms); 
   1.836 -             fun inst_at thms = Library.flat (map (fn ti => instantiate ti ats) thms);               
   1.837 -	     fun inst_pt_at thms = instantiate_zip ats (inst_pt thms);			
   1.838 -             fun inst_dj thms = Library.flat (map (fn ti => instantiate ti djs) thms);  
   1.839 -
   1.840 -           in
   1.841 -            thy33 
   1.842 -	    |>   PureThy.add_thmss [(("alpha", inst_pt_at [abs_fun_eq]),[])]
   1.843 -            |>>> PureThy.add_thmss [(("perm_swap", inst_pt_at [pt_swap_bij]),[])]
   1.844 -            |>>> PureThy.add_thmss [(("perm_fresh_fresh", inst_pt_at [pt_fresh_fresh]),[])]
   1.845 -            |>>> PureThy.add_thmss [(("perm_bij", inst_pt_at [pt_bij]),[])]
   1.846 -            |>>> PureThy.add_thmss [(("perm_compose", inst_pt_at [pt_perm_compose]),[])]
   1.847 -            |>>> PureThy.add_thmss [(("perm_app_eq", inst_pt_at [perm_eq_app]),[])]
   1.848 -            |>>> PureThy.add_thmss [(("supp_atm", (inst_at [at_supp]) @ (inst_dj [dj_supp])),[])]
   1.849 -            |>>> PureThy.add_thmss [(("fresh_atm", inst_at [at_fresh]),[])]
   1.850 -            |>>> PureThy.add_thmss [(("calc_atm", inst_at at_calc),[])]
   1.851 -            
   1.852 -	   end;
   1.853 -
   1.854 -         (* perm_dj collects all lemmas that forget an permutation *)
   1.855 -         (* when it acts on an atom of different type              *)
   1.856 -         val (thy35,_) = 
   1.857 -	   let 
   1.858 -	     val name = "perm_dj"
   1.859 -             val thm_list = Library.flat (map (fn (ak_name, T) =>
   1.860 -	        Library.flat (map (fn (ak_name', T') => 
   1.861 -                 if not (ak_name = ak_name') 
   1.862 -                 then 
   1.863 -		    let
   1.864 -                      val dj_inst = PureThy.get_thm thy34 (Name ("dj_"^ak_name^"_"^ak_name'));
   1.865 -                    in
   1.866 -                      [dj_inst RS dj_perm_forget, dj_inst RS dj_pp_forget]
   1.867 -                    end 
   1.868 -                 else []) ak_names_types)) ak_names_types)
   1.869 -           in
   1.870 -             (PureThy.add_thmss [((name, thm_list),[])] thy34)
   1.871 -           end;
   1.872 -
   1.873 -         (* abs_fresh collects all lemmas for simplifying a freshness *)
   1.874 -         (* proposition involving an abs_fun                          *)
   1.875 -
   1.876 -         val (thy36,_) = 
   1.877 -	   let 
   1.878 -	     val name = "abs_fresh"
   1.879 -             val thm_list = Library.flat (map (fn (ak_name, T) =>
   1.880 -	        let	
   1.881 -		  val at_inst = PureThy.get_thm thy35 (Name ("at_"^ak_name^"_inst"));
   1.882 -		  val pt_inst = PureThy.get_thm thy35 (Name ("pt_"^ak_name^"_inst"));
   1.883 -                  val fs_inst = PureThy.get_thm thy35 (Name ("fs_"^ak_name^"_inst"));	      
   1.884 -	          val thm = [pt_inst, at_inst, (fs_inst RS fs1)] MRS fresh_iff
   1.885 -                  val thm_list = Library.flat (map (fn (ak_name', T') =>
   1.886 -                     (if (not (ak_name = ak_name')) 
   1.887 -                     then
   1.888 -                       let
   1.889 -                        val cp_inst = PureThy.get_thm thy35 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.890 -	                val dj_inst = PureThy.get_thm thy35 (Name ("dj_"^ak_name'^"_"^ak_name));
   1.891 -                       in
   1.892 -                        [[pt_inst, pt_inst, at_inst, cp_inst, dj_inst] MRS fresh_iff_ineq]
   1.893 -	               end
   1.894 -                     else [])) ak_names_types);
   1.895 -                 in thm::thm_list end) (ak_names_types))
   1.896 -           in
   1.897 -             (PureThy.add_thmss [((name, thm_list),[])] thy35)
   1.898 -           end;
   1.899 -
   1.900 -         (* abs_supp collects all lemmas for simplifying  *)
   1.901 -         (* support proposition involving an abs_fun      *)
   1.902 -
   1.903 -         val (thy37,_) = 
   1.904 -	   let 
   1.905 -	     val name = "abs_supp"
   1.906 -             val thm_list = Library.flat (map (fn (ak_name, T) =>
   1.907 -	        let	
   1.908 -		  val at_inst = PureThy.get_thm thy36 (Name ("at_"^ak_name^"_inst"));
   1.909 -		  val pt_inst = PureThy.get_thm thy36 (Name ("pt_"^ak_name^"_inst"));
   1.910 -                  val fs_inst = PureThy.get_thm thy36 (Name ("fs_"^ak_name^"_inst"));	      
   1.911 -	          val thm1 = [pt_inst, at_inst, (fs_inst RS fs1)] MRS abs_fun_supp
   1.912 -                  val thm2 = [pt_inst, at_inst] MRS abs_fun_supp
   1.913 -                  val thm_list = Library.flat (map (fn (ak_name', T') =>
   1.914 -                     (if (not (ak_name = ak_name')) 
   1.915 -                     then
   1.916 -                       let
   1.917 -                        val cp_inst = PureThy.get_thm thy36 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
   1.918 -	                val dj_inst = PureThy.get_thm thy36 (Name ("dj_"^ak_name'^"_"^ak_name));
   1.919 -                       in
   1.920 -                        [[pt_inst, pt_inst, at_inst, cp_inst, dj_inst] MRS abs_fun_supp_ineq]
   1.921 -	               end
   1.922 -                     else [])) ak_names_types);
   1.923 -                 in thm1::thm2::thm_list end) (ak_names_types))
   1.924 -           in
   1.925 -             (PureThy.add_thmss [((name, thm_list),[])] thy36)
   1.926 -           end;
   1.927 -
   1.928 -    in NominalData.put (fold Symtab.update (map (rpair ()) full_ak_names)
   1.929 -      (NominalData.get thy11)) thy37
   1.930 -    end;
   1.931 -
   1.932 -
   1.933 -(* syntax und parsing *)
   1.934 -structure P = OuterParse and K = OuterKeyword;
   1.935 -
   1.936 -val atom_declP =
   1.937 -  OuterSyntax.command "atom_decl" "Declare new kinds of atoms" K.thy_decl
   1.938 -    (Scan.repeat1 P.name >> (Toplevel.theory o create_nom_typedecls));
   1.939 -
   1.940 -val _ = OuterSyntax.add_parsers [atom_declP];
   1.941 -
   1.942 -val setup = [NominalData.init];
   1.943 -
   1.944 -(*=======================================================================*)
   1.945 +open NominalAtoms;
   1.946  
   1.947  (** FIXME: DatatypePackage should export this function **)
   1.948  
   1.949 @@ -1957,7 +1030,7 @@
   1.950          end) (atoms ~~ finite_supp_thms);
   1.951  
   1.952    in
   1.953 -    (thy9, perm_eq_thms)
   1.954 +    thy9
   1.955    end;
   1.956  
   1.957  val add_nominal_datatype = gen_add_nominal_datatype read_typ true;
   1.958 @@ -1976,7 +1049,7 @@
   1.959      val names = map (fn ((((NONE, _), t), _), _) => t | ((((SOME t, _), _), _), _) => t) args;
   1.960      val specs = map (fn ((((_, vs), t), mx), cons) =>
   1.961        (vs, t, mx, map (fn ((x, y), z) => (x, y, z)) cons)) args;
   1.962 -  in #1 o add_nominal_datatype false names specs end;
   1.963 +  in add_nominal_datatype false names specs end;
   1.964  
   1.965  val nominal_datatypeP =
   1.966    OuterSyntax.command "nominal_datatype" "define inductive datatypes" K.thy_decl