src/HOL/Nominal/nominal_atoms.ML
author wenzelm
Mon Apr 06 23:14:05 2015 +0200 (2015-04-06)
changeset 59940 087d81f5213e
parent 59936 b8ffc3dc9e24
child 60003 ba8fa0c38d66
permissions -rw-r--r--
local setup of induction tools, with restricted access to auxiliary consts;
proper antiquotations for formerly inaccessible consts;
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,
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) = 
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@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
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,
urbanc@24677
   152
                                          dtac @{thm range_inj_infinite} 1,
wenzelm@51717
   153
                                          asm_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps simp2) 1,
wenzelm@51717
   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@58225
   193
        BNF_LFP_Compat.add_primrec_global
berghofe@41562
   194
          [(Binding.name swap_name, SOME swapT, NoSyn)]
berghofe@41562
   195
          [(Attrib.empty_binding, 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@58225
   227
        BNF_LFP_Compat.add_primrec_global
berghofe@41562
   228
          [(Binding.name prm_name, SOME prmT, NoSyn)]
berghofe@41562
   229
          [(Attrib.empty_binding, def1), (Attrib.empty_binding, 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@51717
   440
                THEN EVERY [rtac allI 1, rtac allI 1, rtac allI 1, rtac cp1 1];
wenzelm@26337
   441
           in
haftmann@29585
   442
             yield_singleton add_thms_string ((name,
wenzelm@51717
   443
               Goal.prove_global thy' [] [] statement (proof o #context)), []) thy'
wenzelm@26337
   444
           end) 
urbanc@18381
   445
           ak_names_types thy) ak_names_types thy12b;
berghofe@18068
   446
       
berghofe@18068
   447
        (* proves for every non-trivial <ak>-combination a disjointness   *)
berghofe@18068
   448
        (* theorem; i.e. <ak1> != <ak2>                                   *)
berghofe@18068
   449
        (* lemma ds_<ak1>_<ak2>:                                          *)
berghofe@18068
   450
        (* dj TYPE(<ak1>) TYPE(<ak2>)                                     *)
urbanc@18381
   451
        val (dj_thms, thy12d) = fold_map (fn (ak_name,T) => fn thy =>
wenzelm@26337
   452
          fold_map (fn (ak_name',T') => fn thy' =>
berghofe@18068
   453
          (if not (ak_name = ak_name') 
berghofe@18068
   454
           then 
wenzelm@26337
   455
               let
haftmann@28965
   456
                 val ak_name_qu  = Sign.full_bname thy' ak_name;
haftmann@28965
   457
                 val ak_name_qu' = Sign.full_bname thy' ak_name';
berghofe@18068
   458
                 val i_type1 = Type(ak_name_qu,[]);
berghofe@18068
   459
                 val i_type2 = Type(ak_name_qu',[]);
wenzelm@56253
   460
                 val cdj = Const (@{const_name Nominal.disjoint},
berghofe@18068
   461
                           (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
berghofe@18068
   462
                 val at_type  = Logic.mk_type i_type1;
berghofe@18068
   463
                 val at_type' = Logic.mk_type i_type2;
wenzelm@51717
   464
                 fun proof ctxt =
wenzelm@51717
   465
                  simp_tac (put_simpset HOL_ss ctxt
wenzelm@51717
   466
                    addsimps maps (Global_Theory.get_thms thy')
wenzelm@26337
   467
                                           ["disjoint_def",
wenzelm@26337
   468
                                            ak_name ^ "_prm_" ^ ak_name' ^ "_def",
wenzelm@51717
   469
                                            ak_name' ^ "_prm_" ^ ak_name ^ "_def"]) 1;
berghofe@18068
   470
wenzelm@26337
   471
                 val name = "dj_"^ak_name^"_"^ak_name';
berghofe@18068
   472
                 val statement = HOLogic.mk_Trueprop (cdj $ at_type $ at_type');
wenzelm@26337
   473
               in
wenzelm@51717
   474
                add_thms_string [((name, Goal.prove_global thy' [] [] statement (proof o #context)), [])] thy'
wenzelm@26337
   475
               end
berghofe@18068
   476
           else 
urbanc@18381
   477
            ([],thy')))  (* do nothing branch, if ak_name = ak_name' *) 
wenzelm@26337
   478
            ak_names_types thy) ak_names_types thy12c;
berghofe@18068
   479
webertj@20097
   480
     (********  pt_<ak> class instances  ********)
berghofe@18068
   481
     (*=========================================*)
urbanc@18279
   482
     (* some abbreviations for theorems *)
wenzelm@23894
   483
      val pt1           = @{thm "pt1"};
wenzelm@23894
   484
      val pt2           = @{thm "pt2"};
wenzelm@23894
   485
      val pt3           = @{thm "pt3"};
wenzelm@23894
   486
      val at_pt_inst    = @{thm "at_pt_inst"};
wenzelm@23894
   487
      val pt_unit_inst  = @{thm "pt_unit_inst"};
wenzelm@23894
   488
      val pt_prod_inst  = @{thm "pt_prod_inst"}; 
wenzelm@23894
   489
      val pt_nprod_inst = @{thm "pt_nprod_inst"}; 
wenzelm@23894
   490
      val pt_list_inst  = @{thm "pt_list_inst"};
wenzelm@23894
   491
      val pt_optn_inst  = @{thm "pt_option_inst"};
wenzelm@23894
   492
      val pt_noptn_inst = @{thm "pt_noption_inst"};
wenzelm@23894
   493
      val pt_fun_inst   = @{thm "pt_fun_inst"};
haftmann@45979
   494
      val pt_set_inst   = @{thm "pt_set_inst"};
berghofe@18068
   495
urbanc@18435
   496
     (* for all atom-kind combinations <ak>/<ak'> show that        *)
urbanc@18435
   497
     (* every <ak> is an instance of pt_<ak'>; the proof for       *)
urbanc@18435
   498
     (* ak!=ak' is by definition; the case ak=ak' uses at_pt_inst. *)
urbanc@18431
   499
     val thy13 = fold (fn ak_name => fn thy =>
wenzelm@26337
   500
        fold (fn ak_name' => fn thy' =>
urbanc@18431
   501
         let
haftmann@28965
   502
           val qu_name =  Sign.full_bname thy' ak_name';
haftmann@28965
   503
           val cls_name = Sign.full_bname thy' ("pt_"^ak_name);
wenzelm@39557
   504
           val at_inst  = Global_Theory.get_thm thy' ("at_" ^ ak_name' ^ "_inst");
urbanc@18431
   505
wenzelm@59498
   506
           fun proof1 ctxt = EVERY [Class.intro_classes_tac ctxt [],
berghofe@18068
   507
                                 rtac ((at_inst RS at_pt_inst) RS pt1) 1,
berghofe@18068
   508
                                 rtac ((at_inst RS at_pt_inst) RS pt2) 1,
berghofe@18068
   509
                                 rtac ((at_inst RS at_pt_inst) RS pt3) 1,
berghofe@18068
   510
                                 atac 1];
wenzelm@51717
   511
           fun proof2 ctxt =
wenzelm@59498
   512
             Class.intro_classes_tac ctxt [] THEN
wenzelm@51717
   513
             REPEAT (asm_simp_tac
wenzelm@51717
   514
              (put_simpset HOL_basic_ss ctxt addsimps
wenzelm@51717
   515
                maps (Global_Theory.get_thms thy') [ak_name ^ "_prm_" ^ ak_name' ^ "_def"]) 1);
urbanc@18431
   516
         in
urbanc@18431
   517
           thy'
wenzelm@51685
   518
           |> Axclass.prove_arity (qu_name,[],[cls_name])
wenzelm@59498
   519
              (fn ctxt => if ak_name = ak_name' then proof1 ctxt else proof2 ctxt)
wenzelm@26484
   520
         end) ak_names thy) ak_names thy12d;
berghofe@18068
   521
urbanc@18430
   522
     (* show that                       *)
urbanc@18430
   523
     (*      fun(pt_<ak>,pt_<ak>)       *)
urbanc@18579
   524
     (*      noption(pt_<ak>)           *)
urbanc@18430
   525
     (*      option(pt_<ak>)            *)
urbanc@18430
   526
     (*      list(pt_<ak>)              *)
urbanc@18430
   527
     (*      *(pt_<ak>,pt_<ak>)         *)
urbanc@18600
   528
     (*      nprod(pt_<ak>,pt_<ak>)     *)
urbanc@18430
   529
     (*      unit                       *)
urbanc@18430
   530
     (*      set(pt_<ak>)               *)
urbanc@18430
   531
     (* are instances of pt_<ak>        *)
urbanc@18431
   532
     val thy18 = fold (fn ak_name => fn thy =>
berghofe@18068
   533
       let
haftmann@28965
   534
          val cls_name = Sign.full_bname thy ("pt_"^ak_name);
wenzelm@39557
   535
          val at_thm   = Global_Theory.get_thm thy ("at_"^ak_name^"_inst");
wenzelm@39557
   536
          val pt_inst  = Global_Theory.get_thm thy ("pt_"^ak_name^"_inst");
webertj@20097
   537
wenzelm@51671
   538
          fun pt_proof thm ctxt =
wenzelm@59498
   539
              EVERY [Class.intro_classes_tac ctxt [],
urbanc@18430
   540
                     rtac (thm RS pt1) 1, rtac (thm RS pt2) 1, rtac (thm RS pt3) 1, atac 1];
urbanc@18430
   541
urbanc@18430
   542
          val pt_thm_fun   = at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst));
berghofe@46180
   543
          val pt_thm_set   = pt_inst RS pt_set_inst;
urbanc@18430
   544
          val pt_thm_noptn = pt_inst RS pt_noptn_inst; 
urbanc@18430
   545
          val pt_thm_optn  = pt_inst RS pt_optn_inst; 
urbanc@18430
   546
          val pt_thm_list  = pt_inst RS pt_list_inst;
urbanc@18430
   547
          val pt_thm_prod  = pt_inst RS (pt_inst RS pt_prod_inst);
urbanc@18600
   548
          val pt_thm_nprod = pt_inst RS (pt_inst RS pt_nprod_inst);
urbanc@18430
   549
          val pt_thm_unit  = pt_unit_inst;
webertj@20097
   550
       in
webertj@20097
   551
        thy
wenzelm@56253
   552
        |> Axclass.prove_arity (@{type_name fun},[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_fun)
wenzelm@56253
   553
        |> Axclass.prove_arity (@{type_name set},[[cls_name]],[cls_name]) (pt_proof pt_thm_set)
wenzelm@56253
   554
        |> Axclass.prove_arity (@{type_name noption},[[cls_name]],[cls_name]) (pt_proof pt_thm_noptn) 
wenzelm@56253
   555
        |> Axclass.prove_arity (@{type_name option},[[cls_name]],[cls_name]) (pt_proof pt_thm_optn)
wenzelm@56253
   556
        |> Axclass.prove_arity (@{type_name list},[[cls_name]],[cls_name]) (pt_proof pt_thm_list)
wenzelm@56253
   557
        |> Axclass.prove_arity (@{type_name prod},[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_prod)
wenzelm@56253
   558
        |> Axclass.prove_arity (@{type_name nprod},[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_nprod)
wenzelm@56253
   559
        |> Axclass.prove_arity (@{type_name unit},[],[cls_name]) (pt_proof pt_thm_unit)
urbanc@18430
   560
     end) ak_names thy13; 
berghofe@18068
   561
webertj@20097
   562
       (********  fs_<ak> class instances  ********)
berghofe@18068
   563
       (*=========================================*)
urbanc@18279
   564
       (* abbreviations for some lemmas *)
wenzelm@23894
   565
       val fs1            = @{thm "fs1"};
wenzelm@23894
   566
       val fs_at_inst     = @{thm "fs_at_inst"};
wenzelm@23894
   567
       val fs_unit_inst   = @{thm "fs_unit_inst"};
wenzelm@23894
   568
       val fs_prod_inst   = @{thm "fs_prod_inst"};
wenzelm@23894
   569
       val fs_nprod_inst  = @{thm "fs_nprod_inst"};
wenzelm@23894
   570
       val fs_list_inst   = @{thm "fs_list_inst"};
wenzelm@23894
   571
       val fs_option_inst = @{thm "fs_option_inst"};
wenzelm@23894
   572
       val dj_supp        = @{thm "dj_supp"};
berghofe@18068
   573
berghofe@18068
   574
       (* shows that <ak> is an instance of fs_<ak>     *)
berghofe@18068
   575
       (* uses the theorem at_<ak>_inst                 *)
urbanc@18431
   576
       val thy20 = fold (fn ak_name => fn thy =>
webertj@20097
   577
        fold (fn ak_name' => fn thy' =>
urbanc@18437
   578
        let
haftmann@28965
   579
           val qu_name =  Sign.full_bname thy' ak_name';
haftmann@28965
   580
           val qu_class = Sign.full_bname thy' ("fs_"^ak_name);
wenzelm@51717
   581
           fun proof ctxt =
webertj@20097
   582
               (if ak_name = ak_name'
webertj@20097
   583
                then
wenzelm@39557
   584
                  let val at_thm = Global_Theory.get_thm thy' ("at_"^ak_name^"_inst");
wenzelm@59498
   585
                  in  EVERY [Class.intro_classes_tac ctxt [],
urbanc@18437
   586
                             rtac ((at_thm RS fs_at_inst) RS fs1) 1] end
urbanc@18437
   587
                else
wenzelm@39557
   588
                  let val dj_inst = Global_Theory.get_thm thy' ("dj_"^ak_name'^"_"^ak_name);
wenzelm@51717
   589
                      val simp_s =
wenzelm@51717
   590
                        put_simpset HOL_basic_ss ctxt addsimps [dj_inst RS dj_supp, finite_emptyI];
wenzelm@59498
   591
                  in EVERY [Class.intro_classes_tac ctxt [], asm_simp_tac simp_s 1] end)
webertj@20097
   592
        in
wenzelm@51717
   593
         Axclass.prove_arity (qu_name,[],[qu_class]) proof thy'
urbanc@18437
   594
        end) ak_names thy) ak_names thy18;
berghofe@18068
   595
urbanc@18431
   596
       (* shows that                  *)
urbanc@18431
   597
       (*    unit                     *)
urbanc@18431
   598
       (*    *(fs_<ak>,fs_<ak>)       *)
urbanc@18600
   599
       (*    nprod(fs_<ak>,fs_<ak>)   *)
urbanc@18431
   600
       (*    list(fs_<ak>)            *)
urbanc@18431
   601
       (*    option(fs_<ak>)          *) 
urbanc@18431
   602
       (* are instances of fs_<ak>    *)
berghofe@18068
   603
urbanc@18431
   604
       val thy24 = fold (fn ak_name => fn thy => 
urbanc@18431
   605
        let
haftmann@28965
   606
          val cls_name = Sign.full_bname thy ("fs_"^ak_name);
wenzelm@39557
   607
          val fs_inst  = Global_Theory.get_thm thy ("fs_"^ak_name^"_inst");
wenzelm@59498
   608
          fun fs_proof thm ctxt = EVERY [Class.intro_classes_tac ctxt [], rtac (thm RS fs1) 1];
berghofe@18068
   609
urbanc@18600
   610
          val fs_thm_unit  = fs_unit_inst;
urbanc@18600
   611
          val fs_thm_prod  = fs_inst RS (fs_inst RS fs_prod_inst);
urbanc@18600
   612
          val fs_thm_nprod = fs_inst RS (fs_inst RS fs_nprod_inst);
urbanc@18600
   613
          val fs_thm_list  = fs_inst RS fs_list_inst;
urbanc@18600
   614
          val fs_thm_optn  = fs_inst RS fs_option_inst;
urbanc@18431
   615
        in 
webertj@20097
   616
         thy
wenzelm@56253
   617
         |> Axclass.prove_arity (@{type_name unit},[],[cls_name]) (fs_proof fs_thm_unit) 
wenzelm@56253
   618
         |> Axclass.prove_arity (@{type_name prod},[[cls_name],[cls_name]],[cls_name]) (fs_proof fs_thm_prod) 
wenzelm@56253
   619
         |> Axclass.prove_arity (@{type_name nprod},[[cls_name],[cls_name]],[cls_name]) (fs_proof fs_thm_nprod)
wenzelm@56253
   620
         |> Axclass.prove_arity (@{type_name list},[[cls_name]],[cls_name]) (fs_proof fs_thm_list)
wenzelm@56253
   621
         |> Axclass.prove_arity (@{type_name option},[[cls_name]],[cls_name]) (fs_proof fs_thm_optn)
webertj@20097
   622
        end) ak_names thy20;
urbanc@18431
   623
webertj@20097
   624
       (********  cp_<ak>_<ai> class instances  ********)
berghofe@18068
   625
       (*==============================================*)
urbanc@18279
   626
       (* abbreviations for some lemmas *)
wenzelm@23894
   627
       val cp1             = @{thm "cp1"};
wenzelm@23894
   628
       val cp_unit_inst    = @{thm "cp_unit_inst"};
wenzelm@23894
   629
       val cp_bool_inst    = @{thm "cp_bool_inst"};
wenzelm@23894
   630
       val cp_prod_inst    = @{thm "cp_prod_inst"};
wenzelm@23894
   631
       val cp_list_inst    = @{thm "cp_list_inst"};
wenzelm@23894
   632
       val cp_fun_inst     = @{thm "cp_fun_inst"};
wenzelm@23894
   633
       val cp_option_inst  = @{thm "cp_option_inst"};
wenzelm@23894
   634
       val cp_noption_inst = @{thm "cp_noption_inst"};
berghofe@46180
   635
       val cp_set_inst     = @{thm "cp_set_inst"};
wenzelm@23894
   636
       val pt_perm_compose = @{thm "pt_perm_compose"};
webertj@20097
   637
wenzelm@23894
   638
       val dj_pp_forget    = @{thm "dj_perm_perm_forget"};
berghofe@18068
   639
berghofe@18068
   640
       (* shows that <aj> is an instance of cp_<ak>_<ai>  *)
urbanc@18432
   641
       (* for every  <ak>/<ai>-combination                *)
webertj@20097
   642
       val thy25 = fold (fn ak_name => fn thy =>
webertj@20097
   643
         fold (fn ak_name' => fn thy' =>
webertj@20097
   644
          fold (fn ak_name'' => fn thy'' =>
berghofe@18068
   645
            let
haftmann@28965
   646
              val name =  Sign.full_bname thy'' ak_name;
haftmann@28965
   647
              val cls_name = Sign.full_bname thy'' ("cp_"^ak_name'^"_"^ak_name'');
wenzelm@51717
   648
              fun proof ctxt =
berghofe@18068
   649
                (if (ak_name'=ak_name'') then 
webertj@20097
   650
                  (let
wenzelm@39557
   651
                    val pt_inst  = Global_Theory.get_thm thy'' ("pt_"^ak_name''^"_inst");
wenzelm@39557
   652
                    val at_inst  = Global_Theory.get_thm thy'' ("at_"^ak_name''^"_inst");
webertj@20097
   653
                  in
wenzelm@59498
   654
                   EVERY [Class.intro_classes_tac ctxt [],
berghofe@18068
   655
                          rtac (at_inst RS (pt_inst RS pt_perm_compose)) 1]
berghofe@18068
   656
                  end)
wenzelm@26337
   657
                else
wenzelm@26337
   658
                  (let
wenzelm@39557
   659
                     val dj_inst  = Global_Theory.get_thm thy'' ("dj_"^ak_name''^"_"^ak_name');
wenzelm@51717
   660
                     val simp_s = put_simpset HOL_basic_ss ctxt addsimps
berghofe@18068
   661
                                        ((dj_inst RS dj_pp_forget)::
wenzelm@39557
   662
                                         (maps (Global_Theory.get_thms thy'')
wenzelm@26337
   663
                                           [ak_name' ^"_prm_"^ak_name^"_def",
wenzelm@26337
   664
                                            ak_name''^"_prm_"^ak_name^"_def"]));
webertj@20097
   665
                  in
wenzelm@59498
   666
                    EVERY [Class.intro_classes_tac ctxt [], simp_tac simp_s 1]
berghofe@18068
   667
                  end))
webertj@20097
   668
              in
wenzelm@51717
   669
                Axclass.prove_arity (name,[],[cls_name]) proof thy''
webertj@20097
   670
              end) ak_names thy') ak_names thy) ak_names thy24;
webertj@20097
   671
urbanc@18432
   672
       (* shows that                                                    *) 
urbanc@18432
   673
       (*      units                                                    *) 
urbanc@18432
   674
       (*      products                                                 *)
urbanc@18432
   675
       (*      lists                                                    *)
urbanc@18432
   676
       (*      functions                                                *)
urbanc@18432
   677
       (*      options                                                  *)
urbanc@18432
   678
       (*      noptions                                                 *)
urbanc@22536
   679
       (*      sets                                                     *)
urbanc@18432
   680
       (* are instances of cp_<ak>_<ai> for every <ak>/<ai>-combination *)
urbanc@18432
   681
       val thy26 = fold (fn ak_name => fn thy =>
wenzelm@26337
   682
        fold (fn ak_name' => fn thy' =>
urbanc@18432
   683
        let
haftmann@28965
   684
            val cls_name = Sign.full_bname thy' ("cp_"^ak_name^"_"^ak_name');
wenzelm@39557
   685
            val cp_inst  = Global_Theory.get_thm thy' ("cp_"^ak_name^"_"^ak_name'^"_inst");
wenzelm@39557
   686
            val pt_inst  = Global_Theory.get_thm thy' ("pt_"^ak_name^"_inst");
wenzelm@39557
   687
            val at_inst  = Global_Theory.get_thm thy' ("at_"^ak_name^"_inst");
urbanc@18432
   688
wenzelm@59498
   689
            fun cp_proof thm ctxt = EVERY [Class.intro_classes_tac ctxt [], rtac (thm RS cp1) 1];
wenzelm@26337
   690
          
urbanc@18432
   691
            val cp_thm_unit = cp_unit_inst;
urbanc@18432
   692
            val cp_thm_prod = cp_inst RS (cp_inst RS cp_prod_inst);
urbanc@18432
   693
            val cp_thm_list = cp_inst RS cp_list_inst;
urbanc@18432
   694
            val cp_thm_fun  = at_inst RS (pt_inst RS (cp_inst RS (cp_inst RS cp_fun_inst)));
urbanc@18432
   695
            val cp_thm_optn = cp_inst RS cp_option_inst;
urbanc@18432
   696
            val cp_thm_noptn = cp_inst RS cp_noption_inst;
berghofe@46180
   697
            val cp_thm_set = cp_inst RS cp_set_inst;
urbanc@18432
   698
        in
urbanc@18432
   699
         thy'
wenzelm@56253
   700
         |> Axclass.prove_arity (@{type_name unit},[],[cls_name]) (cp_proof cp_thm_unit)
wenzelm@51685
   701
         |> Axclass.prove_arity (@{type_name Product_Type.prod}, [[cls_name],[cls_name]],[cls_name]) (cp_proof cp_thm_prod)
wenzelm@56253
   702
         |> Axclass.prove_arity (@{type_name list},[[cls_name]],[cls_name]) (cp_proof cp_thm_list)
wenzelm@56253
   703
         |> Axclass.prove_arity (@{type_name fun},[[cls_name],[cls_name]],[cls_name]) (cp_proof cp_thm_fun)
wenzelm@56253
   704
         |> Axclass.prove_arity (@{type_name option},[[cls_name]],[cls_name]) (cp_proof cp_thm_optn)
wenzelm@56253
   705
         |> Axclass.prove_arity (@{type_name noption},[[cls_name]],[cls_name]) (cp_proof cp_thm_noptn)
wenzelm@56253
   706
         |> Axclass.prove_arity (@{type_name set},[[cls_name]],[cls_name]) (cp_proof cp_thm_set)
urbanc@18432
   707
        end) ak_names thy) ak_names thy25;
webertj@20097
   708
webertj@20097
   709
     (* show that discrete nominal types are permutation types, finitely     *)
urbanc@18432
   710
     (* supported and have the commutation property                          *)
urbanc@18432
   711
     (* discrete types have a permutation operation defined as pi o x = x;   *)
webertj@20097
   712
     (* which renders the proofs to be simple "simp_all"-proofs.             *)
urbanc@18432
   713
     val thy32 =
webertj@20097
   714
        let
wenzelm@26337
   715
          fun discrete_pt_inst discrete_ty defn =
wenzelm@26337
   716
             fold (fn ak_name => fn thy =>
wenzelm@26337
   717
             let
haftmann@28965
   718
               val qu_class = Sign.full_bname thy ("pt_"^ak_name);
wenzelm@51717
   719
               fun proof ctxt =
wenzelm@59498
   720
                Class.intro_classes_tac ctxt [] THEN
wenzelm@51717
   721
                REPEAT (asm_simp_tac (put_simpset HOL_basic_ss ctxt addsimps [Simpdata.mk_eq defn]) 1);
webertj@20097
   722
             in 
wenzelm@51717
   723
               Axclass.prove_arity (discrete_ty, [], [qu_class]) proof thy
urbanc@18432
   724
             end) ak_names;
berghofe@18068
   725
urbanc@18432
   726
          fun discrete_fs_inst discrete_ty defn = 
wenzelm@26337
   727
             fold (fn ak_name => fn thy =>
wenzelm@26337
   728
             let
haftmann@28965
   729
               val qu_class = Sign.full_bname thy ("fs_"^ak_name);
haftmann@44684
   730
               val supp_def = Simpdata.mk_eq @{thm "Nominal.supp_def"};
wenzelm@51717
   731
               fun proof ctxt =
wenzelm@59498
   732
                Class.intro_classes_tac ctxt [] THEN
wenzelm@51717
   733
                asm_simp_tac (put_simpset HOL_ss ctxt
wenzelm@51717
   734
                  addsimps [supp_def, Collect_const, finite_emptyI, Simpdata.mk_eq defn]) 1;
webertj@20097
   735
             in 
wenzelm@51717
   736
               Axclass.prove_arity (discrete_ty, [], [qu_class]) proof thy
webertj@20097
   737
             end) ak_names;
berghofe@18068
   738
urbanc@18432
   739
          fun discrete_cp_inst discrete_ty defn = 
wenzelm@26337
   740
             fold (fn ak_name' => (fold (fn ak_name => fn thy =>
wenzelm@26337
   741
             let
haftmann@28965
   742
               val qu_class = Sign.full_bname thy ("cp_"^ak_name^"_"^ak_name');
haftmann@44684
   743
               val supp_def = Simpdata.mk_eq @{thm "Nominal.supp_def"};
wenzelm@51717
   744
               fun proof ctxt =
wenzelm@59498
   745
                Class.intro_classes_tac ctxt [] THEN
wenzelm@51717
   746
                asm_simp_tac (put_simpset HOL_ss ctxt addsimps [Simpdata.mk_eq defn]) 1;
webertj@20097
   747
             in
wenzelm@51717
   748
               Axclass.prove_arity (discrete_ty, [], [qu_class]) proof thy
webertj@20097
   749
             end) ak_names)) ak_names;
webertj@20097
   750
urbanc@18432
   751
        in
urbanc@18432
   752
         thy26
haftmann@44684
   753
         |> discrete_pt_inst @{type_name nat} @{thm perm_nat_def}
haftmann@44684
   754
         |> discrete_fs_inst @{type_name nat} @{thm perm_nat_def}
haftmann@44684
   755
         |> discrete_cp_inst @{type_name nat} @{thm perm_nat_def}
haftmann@44689
   756
         |> discrete_pt_inst @{type_name bool} @{thm perm_bool_def}
haftmann@44689
   757
         |> discrete_fs_inst @{type_name bool} @{thm perm_bool_def}
haftmann@44689
   758
         |> discrete_cp_inst @{type_name bool} @{thm perm_bool_def}
haftmann@44684
   759
         |> discrete_pt_inst @{type_name int} @{thm perm_int_def}
haftmann@44684
   760
         |> discrete_fs_inst @{type_name int} @{thm perm_int_def}
haftmann@44684
   761
         |> discrete_cp_inst @{type_name int} @{thm perm_int_def}
haftmann@44684
   762
         |> discrete_pt_inst @{type_name char} @{thm perm_char_def}
haftmann@44684
   763
         |> discrete_fs_inst @{type_name char} @{thm perm_char_def}
haftmann@44684
   764
         |> discrete_cp_inst @{type_name char} @{thm perm_char_def}
urbanc@18432
   765
        end;
urbanc@18432
   766
webertj@20097
   767
urbanc@18262
   768
       (* abbreviations for some lemmas *)
urbanc@18262
   769
       (*===============================*)
wenzelm@23894
   770
       val abs_fun_pi          = @{thm "Nominal.abs_fun_pi"};
wenzelm@23894
   771
       val abs_fun_pi_ineq     = @{thm "Nominal.abs_fun_pi_ineq"};
wenzelm@23894
   772
       val abs_fun_eq          = @{thm "Nominal.abs_fun_eq"};
wenzelm@23894
   773
       val abs_fun_eq'         = @{thm "Nominal.abs_fun_eq'"};
wenzelm@23894
   774
       val abs_fun_fresh       = @{thm "Nominal.abs_fun_fresh"};
wenzelm@23894
   775
       val abs_fun_fresh'      = @{thm "Nominal.abs_fun_fresh'"};
wenzelm@23894
   776
       val dj_perm_forget      = @{thm "Nominal.dj_perm_forget"};
wenzelm@23894
   777
       val dj_pp_forget        = @{thm "Nominal.dj_perm_perm_forget"};
wenzelm@23894
   778
       val fresh_iff           = @{thm "Nominal.fresh_abs_fun_iff"};
wenzelm@23894
   779
       val fresh_iff_ineq      = @{thm "Nominal.fresh_abs_fun_iff_ineq"};
wenzelm@23894
   780
       val abs_fun_supp        = @{thm "Nominal.abs_fun_supp"};
wenzelm@23894
   781
       val abs_fun_supp_ineq   = @{thm "Nominal.abs_fun_supp_ineq"};
wenzelm@23894
   782
       val pt_swap_bij         = @{thm "Nominal.pt_swap_bij"};
wenzelm@23894
   783
       val pt_swap_bij'        = @{thm "Nominal.pt_swap_bij'"};
wenzelm@23894
   784
       val pt_fresh_fresh      = @{thm "Nominal.pt_fresh_fresh"};
wenzelm@23894
   785
       val pt_bij              = @{thm "Nominal.pt_bij"};
wenzelm@23894
   786
       val pt_perm_compose     = @{thm "Nominal.pt_perm_compose"};
wenzelm@23894
   787
       val pt_perm_compose'    = @{thm "Nominal.pt_perm_compose'"};
wenzelm@23894
   788
       val perm_app            = @{thm "Nominal.pt_fun_app_eq"};
wenzelm@23894
   789
       val at_fresh            = @{thm "Nominal.at_fresh"};
wenzelm@23894
   790
       val at_fresh_ineq       = @{thm "Nominal.at_fresh_ineq"};
wenzelm@23894
   791
       val at_calc             = @{thms "Nominal.at_calc"};
wenzelm@23894
   792
       val at_swap_simps       = @{thms "Nominal.at_swap_simps"};
wenzelm@23894
   793
       val at_supp             = @{thm "Nominal.at_supp"};
wenzelm@23894
   794
       val dj_supp             = @{thm "Nominal.dj_supp"};
wenzelm@23894
   795
       val fresh_left_ineq     = @{thm "Nominal.pt_fresh_left_ineq"};
wenzelm@23894
   796
       val fresh_left          = @{thm "Nominal.pt_fresh_left"};
wenzelm@23894
   797
       val fresh_right_ineq    = @{thm "Nominal.pt_fresh_right_ineq"};
wenzelm@23894
   798
       val fresh_right         = @{thm "Nominal.pt_fresh_right"};
wenzelm@23894
   799
       val fresh_bij_ineq      = @{thm "Nominal.pt_fresh_bij_ineq"};
wenzelm@23894
   800
       val fresh_bij           = @{thm "Nominal.pt_fresh_bij"};
urbanc@26773
   801
       val fresh_star_bij_ineq = @{thms "Nominal.pt_fresh_star_bij_ineq"};
urbanc@26773
   802
       val fresh_star_bij      = @{thms "Nominal.pt_fresh_star_bij"};
wenzelm@23894
   803
       val fresh_eqvt          = @{thm "Nominal.pt_fresh_eqvt"};
wenzelm@23894
   804
       val fresh_eqvt_ineq     = @{thm "Nominal.pt_fresh_eqvt_ineq"};
berghofe@30086
   805
       val fresh_star_eqvt     = @{thms "Nominal.pt_fresh_star_eqvt"};
berghofe@30086
   806
       val fresh_star_eqvt_ineq= @{thms "Nominal.pt_fresh_star_eqvt_ineq"};
wenzelm@23894
   807
       val set_diff_eqvt       = @{thm "Nominal.pt_set_diff_eqvt"};
wenzelm@23894
   808
       val in_eqvt             = @{thm "Nominal.pt_in_eqvt"};
wenzelm@23894
   809
       val eq_eqvt             = @{thm "Nominal.pt_eq_eqvt"};
wenzelm@23894
   810
       val all_eqvt            = @{thm "Nominal.pt_all_eqvt"};
wenzelm@23894
   811
       val ex_eqvt             = @{thm "Nominal.pt_ex_eqvt"};
urbanc@28011
   812
       val ex1_eqvt            = @{thm "Nominal.pt_ex1_eqvt"};
urbanc@28011
   813
       val the_eqvt            = @{thm "Nominal.pt_the_eqvt"};
wenzelm@23894
   814
       val pt_pi_rev           = @{thm "Nominal.pt_pi_rev"};
wenzelm@23894
   815
       val pt_rev_pi           = @{thm "Nominal.pt_rev_pi"};
wenzelm@23894
   816
       val at_exists_fresh     = @{thm "Nominal.at_exists_fresh"};
wenzelm@23894
   817
       val at_exists_fresh'    = @{thm "Nominal.at_exists_fresh'"};
wenzelm@23894
   818
       val fresh_perm_app_ineq = @{thm "Nominal.pt_fresh_perm_app_ineq"};
wenzelm@26337
   819
       val fresh_perm_app      = @{thm "Nominal.pt_fresh_perm_app"};    
wenzelm@23894
   820
       val fresh_aux           = @{thm "Nominal.pt_fresh_aux"};  
wenzelm@23894
   821
       val pt_perm_supp_ineq   = @{thm "Nominal.pt_perm_supp_ineq"};
wenzelm@23894
   822
       val pt_perm_supp        = @{thm "Nominal.pt_perm_supp"};
urbanc@26090
   823
       val subseteq_eqvt       = @{thm "Nominal.pt_subseteq_eqvt"};
narboux@22786
   824
urbanc@18262
   825
       (* Now we collect and instantiate some lemmas w.r.t. all atom      *)
urbanc@18262
   826
       (* types; this allows for example to use abs_perm (which is a      *)
urbanc@18262
   827
       (* collection of theorems) instead of thm abs_fun_pi with explicit *)
urbanc@18262
   828
       (* instantiations.                                                 *)
webertj@20097
   829
       val (_, thy33) =
webertj@20097
   830
         let
wenzelm@54742
   831
             val ctxt32 = Proof_Context.init_global thy32;
urbanc@18651
   832
urbanc@18279
   833
             (* takes a theorem thm and a list of theorems [t1,..,tn]            *)
urbanc@18279
   834
             (* produces a list of theorems of the form [t1 RS thm,..,tn RS thm] *) 
urbanc@18262
   835
             fun instR thm thms = map (fn ti => ti RS thm) thms;
berghofe@18068
   836
wenzelm@32960
   837
             (* takes a theorem thm and a list of theorems [(t1,m1),..,(tn,mn)]  *)
urbanc@26773
   838
             (* produces a list of theorems of the form [[t1,m1] MRS thm,..,[tn,mn] MRS thm] *) 
urbanc@26773
   839
             fun instRR thm thms = map (fn (ti,mi) => [ti,mi] MRS thm) thms;
urbanc@26773
   840
urbanc@18262
   841
             (* takes two theorem lists (hopefully of the same length ;o)                *)
urbanc@18262
   842
             (* produces a list of theorems of the form                                  *)
urbanc@18262
   843
             (* [t1 RS m1,..,tn RS mn] where [t1,..,tn] is thms1 and [m1,..,mn] is thms2 *) 
urbanc@18279
   844
             fun inst_zip thms1 thms2 = map (fn (t1,t2) => t1 RS t2) (thms1 ~~ thms2);
berghofe@18068
   845
urbanc@18262
   846
             (* takes a theorem list of the form [l1,...,ln]              *)
urbanc@18262
   847
             (* and a list of theorem lists of the form                   *)
urbanc@18262
   848
             (* [[h11,...,h1m],....,[hk1,....,hkm]                        *)
urbanc@18262
   849
             (* produces the list of theorem lists                        *)
urbanc@18262
   850
             (* [[l1 RS h11,...,l1 RS h1m],...,[ln RS hk1,...,ln RS hkm]] *)
urbanc@18279
   851
             fun inst_mult thms thmss = map (fn (t,ts) => instR t ts) (thms ~~ thmss);
urbanc@18279
   852
urbanc@18279
   853
             (* FIXME: these lists do not need to be created dynamically again *)
urbanc@18262
   854
urbanc@22418
   855
             
berghofe@18068
   856
             (* list of all at_inst-theorems *)
wenzelm@39557
   857
             val ats = map (fn ak => Global_Theory.get_thm thy32 ("at_"^ak^"_inst")) ak_names
berghofe@18068
   858
             (* list of all pt_inst-theorems *)
wenzelm@39557
   859
             val pts = map (fn ak => Global_Theory.get_thm thy32 ("pt_"^ak^"_inst")) ak_names
urbanc@18262
   860
             (* list of all cp_inst-theorems as a collection of lists*)
berghofe@18068
   861
             val cps = 
wenzelm@39557
   862
                 let fun cps_fun ak1 ak2 =  Global_Theory.get_thm thy32 ("cp_"^ak1^"_"^ak2^"_inst")
wenzelm@26337
   863
                 in map (fn aki => (map (cps_fun aki) ak_names)) ak_names end; 
urbanc@18262
   864
             (* list of all cp_inst-theorems that have different atom types *)
urbanc@18262
   865
             val cps' = 
wenzelm@26337
   866
                let fun cps'_fun ak1 ak2 = 
wenzelm@39557
   867
                if ak1=ak2 then NONE else SOME (Global_Theory.get_thm thy32 ("cp_"^ak1^"_"^ak2^"_inst"))
wenzelm@32952
   868
                in map (fn aki => (map_filter I (map (cps'_fun aki) ak_names))) ak_names end;
berghofe@18068
   869
             (* list of all dj_inst-theorems *)
berghofe@18068
   870
             val djs = 
wenzelm@26337
   871
               let fun djs_fun ak1 ak2 = 
wenzelm@39557
   872
                     if ak1=ak2 then NONE else SOME(Global_Theory.get_thm thy32 ("dj_"^ak2^"_"^ak1))
wenzelm@26337
   873
               in map_filter I (map_product djs_fun ak_names ak_names) end;
urbanc@18262
   874
             (* list of all fs_inst-theorems *)
wenzelm@39557
   875
             val fss = map (fn ak => Global_Theory.get_thm thy32 ("fs_"^ak^"_inst")) ak_names
urbanc@22418
   876
             (* list of all at_inst-theorems *)
wenzelm@39557
   877
             val fs_axs = map (fn ak => Global_Theory.get_thm thy32 ("fs_"^ak^"1")) ak_names
webertj@20097
   878
haftmann@25538
   879
             fun inst_pt thms = maps (fn ti => instR ti pts) thms;
haftmann@25538
   880
             fun inst_at thms = maps (fn ti => instR ti ats) thms;
haftmann@25538
   881
             fun inst_fs thms = maps (fn ti => instR ti fss) thms;
haftmann@25538
   882
             fun inst_cp thms cps = flat (inst_mult thms cps);
urbanc@26773
   883
             fun inst_pt_at thms = maps (fn ti => instRR ti (pts ~~ ats)) thms;
haftmann@25538
   884
             fun inst_dj thms = maps (fn ti => instR ti djs) thms;
wenzelm@26337
   885
             fun inst_pt_pt_at_cp thms = inst_cp (inst_zip ats (inst_zip pts (inst_pt thms))) cps;
urbanc@18262
   886
             fun inst_pt_at_fs thms = inst_zip (inst_fs [fs1]) (inst_zip ats (inst_pt thms));
wenzelm@26337
   887
             fun inst_pt_pt_at_cp thms =
wenzelm@26337
   888
                 let val i_pt_pt_at = inst_zip ats (inst_zip pts (inst_pt thms));
urbanc@18436
   889
                     val i_pt_pt_at_cp = inst_cp i_pt_pt_at cps';
wenzelm@26337
   890
                 in i_pt_pt_at_cp end;
urbanc@18396
   891
             fun inst_pt_pt_at_cp_dj thms = inst_zip djs (inst_pt_pt_at_cp thms);
berghofe@18068
   892
           in
urbanc@18262
   893
            thy32 
haftmann@29585
   894
            |>   add_thmss_string [(("alpha", inst_pt_at [abs_fun_eq]),[])]
haftmann@29585
   895
            ||>> add_thmss_string [(("alpha'", inst_pt_at [abs_fun_eq']),[])]
haftmann@29585
   896
            ||>> add_thmss_string [(("alpha_fresh", inst_pt_at [abs_fun_fresh]),[])]
haftmann@29585
   897
            ||>> add_thmss_string [(("alpha_fresh'", inst_pt_at [abs_fun_fresh']),[])]
haftmann@29585
   898
            ||>> add_thmss_string [(("perm_swap", inst_pt_at [pt_swap_bij] @ inst_pt_at [pt_swap_bij']),[])]
haftmann@29585
   899
            ||>> add_thmss_string 
wenzelm@32960
   900
              let val thms1 = inst_at at_swap_simps
urbanc@27399
   901
                  and thms2 = inst_dj [dj_perm_forget]
urbanc@27399
   902
              in [(("swap_simps", thms1 @ thms2),[])] end 
haftmann@29585
   903
            ||>> add_thmss_string 
wenzelm@26337
   904
              let val thms1 = inst_pt_at [pt_pi_rev];
wenzelm@26337
   905
                  val thms2 = inst_pt_at [pt_rev_pi];
urbanc@19139
   906
              in [(("perm_pi_simp",thms1 @ thms2),[])] end
haftmann@29585
   907
            ||>> add_thmss_string [(("perm_fresh_fresh", inst_pt_at [pt_fresh_fresh]),[])]
haftmann@29585
   908
            ||>> add_thmss_string [(("perm_bij", inst_pt_at [pt_bij]),[])]
haftmann@29585
   909
            ||>> add_thmss_string 
wenzelm@26337
   910
              let val thms1 = inst_pt_at [pt_perm_compose];
wenzelm@26337
   911
                  val thms2 = instR cp1 (Library.flat cps');
urbanc@18436
   912
              in [(("perm_compose",thms1 @ thms2),[])] end
haftmann@29585
   913
            ||>> add_thmss_string [(("perm_compose'",inst_pt_at [pt_perm_compose']),[])] 
haftmann@29585
   914
            ||>> add_thmss_string [(("perm_app", inst_pt_at [perm_app]),[])]
haftmann@29585
   915
            ||>> add_thmss_string [(("supp_atm", (inst_at [at_supp]) @ (inst_dj [dj_supp])),[])]
haftmann@29585
   916
            ||>> add_thmss_string [(("exists_fresh", inst_at [at_exists_fresh]),[])]
haftmann@29585
   917
            ||>> add_thmss_string [(("exists_fresh'", inst_at [at_exists_fresh']),[])]
haftmann@29585
   918
            ||>> add_thmss_string
berghofe@24569
   919
              let
berghofe@24569
   920
                val thms1 = inst_pt_at [all_eqvt];
wenzelm@54742
   921
                val thms2 = map (fold_rule ctxt32 [inductive_forall_def]) thms1
berghofe@24569
   922
              in
berghofe@24569
   923
                [(("all_eqvt", thms1 @ thms2), [NominalThmDecls.eqvt_force_add])]
berghofe@24569
   924
              end
haftmann@29585
   925
            ||>> add_thmss_string [(("ex_eqvt", inst_pt_at [ex_eqvt]),[NominalThmDecls.eqvt_force_add])]
haftmann@29585
   926
            ||>> add_thmss_string [(("ex1_eqvt", inst_pt_at [ex1_eqvt]),[NominalThmDecls.eqvt_force_add])]
haftmann@29585
   927
            ||>> add_thmss_string [(("the_eqvt", inst_pt_at [the_eqvt]),[NominalThmDecls.eqvt_force_add])]
haftmann@29585
   928
            ||>> add_thmss_string 
wenzelm@26337
   929
              let val thms1 = inst_at [at_fresh]
wenzelm@26337
   930
                  val thms2 = inst_dj [at_fresh_ineq]
wenzelm@26337
   931
              in [(("fresh_atm", thms1 @ thms2),[])] end
haftmann@29585
   932
            ||>> add_thmss_string
urbanc@27399
   933
              let val thms1 = inst_at at_calc
urbanc@27399
   934
                  and thms2 = inst_dj [dj_perm_forget]
urbanc@27399
   935
              in [(("calc_atm", thms1 @ thms2),[])] end
haftmann@29585
   936
            ||>> add_thmss_string
wenzelm@26337
   937
              let val thms1 = inst_pt_at [abs_fun_pi]
wenzelm@26337
   938
                  and thms2 = inst_pt_pt_at_cp [abs_fun_pi_ineq]
wenzelm@26337
   939
              in [(("abs_perm", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end
haftmann@29585
   940
            ||>> add_thmss_string
wenzelm@26337
   941
              let val thms1 = inst_dj [dj_perm_forget]
wenzelm@26337
   942
                  and thms2 = inst_dj [dj_pp_forget]
urbanc@18279
   943
              in [(("perm_dj", thms1 @ thms2),[])] end
haftmann@29585
   944
            ||>> add_thmss_string
wenzelm@26337
   945
              let val thms1 = inst_pt_at_fs [fresh_iff]
urbanc@18626
   946
                  and thms2 = inst_pt_at [fresh_iff]
wenzelm@26337
   947
                  and thms3 = inst_pt_pt_at_cp_dj [fresh_iff_ineq]
wenzelm@26337
   948
            in [(("abs_fresh", thms1 @ thms2 @ thms3),[])] end
haftmann@29585
   949
            ||>> add_thmss_string
wenzelm@26337
   950
              let val thms1 = inst_pt_at [abs_fun_supp]
wenzelm@26337
   951
                  and thms2 = inst_pt_at_fs [abs_fun_supp]
wenzelm@26337
   952
                  and thms3 = inst_pt_pt_at_cp_dj [abs_fun_supp_ineq]
wenzelm@26337
   953
              in [(("abs_supp", thms1 @ thms2 @ thms3),[])] end
haftmann@29585
   954
            ||>> add_thmss_string
wenzelm@26337
   955
              let val thms1 = inst_pt_at [fresh_left]
wenzelm@26337
   956
                  and thms2 = inst_pt_pt_at_cp [fresh_left_ineq]
wenzelm@26337
   957
              in [(("fresh_left", thms1 @ thms2),[])] end
haftmann@29585
   958
            ||>> add_thmss_string
wenzelm@26337
   959
              let val thms1 = inst_pt_at [fresh_right]
wenzelm@26337
   960
                  and thms2 = inst_pt_pt_at_cp [fresh_right_ineq]
wenzelm@26337
   961
              in [(("fresh_right", thms1 @ thms2),[])] end
haftmann@29585
   962
            ||>> add_thmss_string
wenzelm@26337
   963
              let val thms1 = inst_pt_at [fresh_bij]
wenzelm@26337
   964
                  and thms2 = inst_pt_pt_at_cp [fresh_bij_ineq]
wenzelm@26337
   965
              in [(("fresh_bij", thms1 @ thms2),[])] end
haftmann@29585
   966
            ||>> add_thmss_string
urbanc@26773
   967
              let val thms1 = inst_pt_at fresh_star_bij
berghofe@30086
   968
                  and thms2 = maps (fn ti => inst_pt_pt_at_cp [ti]) fresh_star_bij_ineq
urbanc@26773
   969
              in [(("fresh_star_bij", thms1 @ thms2),[])] end
haftmann@29585
   970
            ||>> add_thmss_string
wenzelm@26337
   971
              let val thms1 = inst_pt_at [fresh_eqvt]
urbanc@22535
   972
                  and thms2 = inst_pt_pt_at_cp_dj [fresh_eqvt_ineq]
wenzelm@26337
   973
              in [(("fresh_eqvt", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end
haftmann@29585
   974
            ||>> add_thmss_string
berghofe@30086
   975
              let val thms1 = inst_pt_at fresh_star_eqvt
berghofe@30086
   976
                  and thms2 = maps (fn ti => inst_pt_pt_at_cp_dj [ti]) fresh_star_eqvt_ineq
berghofe@30086
   977
              in [(("fresh_star_eqvt", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end
berghofe@30086
   978
            ||>> add_thmss_string
wenzelm@26337
   979
              let val thms1 = inst_pt_at [in_eqvt]
wenzelm@26337
   980
              in [(("in_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
haftmann@29585
   981
            ||>> add_thmss_string
wenzelm@26337
   982
              let val thms1 = inst_pt_at [eq_eqvt]
wenzelm@26337
   983
              in [(("eq_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
haftmann@29585
   984
            ||>> add_thmss_string
wenzelm@26337
   985
              let val thms1 = inst_pt_at [set_diff_eqvt]
wenzelm@26337
   986
              in [(("set_diff_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
haftmann@29585
   987
            ||>> add_thmss_string
wenzelm@26337
   988
              let val thms1 = inst_pt_at [subseteq_eqvt]
wenzelm@26337
   989
              in [(("subseteq_eqvt", thms1),[NominalThmDecls.eqvt_add])] end
haftmann@29585
   990
            ||>> add_thmss_string
wenzelm@26337
   991
              let val thms1 = inst_pt_at [fresh_aux]
wenzelm@26337
   992
                  and thms2 = inst_pt_pt_at_cp_dj [fresh_perm_app_ineq] 
wenzelm@26337
   993
              in  [(("fresh_aux", thms1 @ thms2),[])] end  
haftmann@29585
   994
            ||>> add_thmss_string
wenzelm@26337
   995
              let val thms1 = inst_pt_at [fresh_perm_app]
wenzelm@26337
   996
                  and thms2 = inst_pt_pt_at_cp_dj [fresh_perm_app_ineq] 
wenzelm@26337
   997
              in  [(("fresh_perm_app", thms1 @ thms2),[])] end 
haftmann@29585
   998
            ||>> add_thmss_string
wenzelm@26337
   999
              let val thms1 = inst_pt_at [pt_perm_supp]
wenzelm@26337
  1000
                  and thms2 = inst_pt_pt_at_cp [pt_perm_supp_ineq] 
wenzelm@26337
  1001
              in  [(("supp_eqvt", thms1 @ thms2),[NominalThmDecls.eqvt_add])] end  
haftmann@29585
  1002
            ||>> add_thmss_string [(("fin_supp",fs_axs),[])]
wenzelm@26337
  1003
           end;
berghofe@18068
  1004
urbanc@22418
  1005
    in 
urbanc@22418
  1006
      NominalData.map (fold Symtab.update (full_ak_names ~~ map make_atom_info
urbanc@22418
  1007
        (pt_ax_classes ~~
urbanc@22418
  1008
         fs_ax_classes ~~
berghofe@28729
  1009
         map (fn cls => Symtab.make (full_ak_names ~~ cls)) cp_ax_classes ~~
berghofe@28372
  1010
         prm_cons_thms ~~ prm_inst_thms ~~
berghofe@28729
  1011
         map (fn ths => Symtab.make (full_ak_names ~~ ths)) cp_thms ~~
berghofe@28729
  1012
         map (fn thss => Symtab.make
wenzelm@32952
  1013
           (map_filter (fn (s, [th]) => SOME (s, th) | _ => NONE)
berghofe@28729
  1014
              (full_ak_names ~~ thss))) dj_thms))) thy33
berghofe@18068
  1015
    end;
berghofe@18068
  1016
berghofe@18068
  1017
berghofe@18068
  1018
(* syntax und parsing *)
berghofe@18068
  1019
wenzelm@24867
  1020
val _ =
wenzelm@59936
  1021
  Outer_Syntax.command @{command_keyword atom_decl} "declare new kinds of atoms"
wenzelm@36960
  1022
    (Scan.repeat1 Parse.name >> (Toplevel.theory o create_nom_typedecls));
berghofe@18068
  1023
berghofe@18068
  1024
end;