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