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