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