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