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