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