src/HOL/Nominal/nominal_atoms.ML
author berghofe
Wed Nov 02 16:37:39 2005 +0100 (2005-11-02 ago)
changeset 18068 e8c3d371594e
child 18100 193c3382bbfe
permissions -rw-r--r--
Moved atom stuff to new file nominal_atoms.ML
berghofe@18068
     1
(* $Id$ *)
berghofe@18068
     2
berghofe@18068
     3
signature NOMINAL_ATOMS =
berghofe@18068
     4
sig
berghofe@18068
     5
  val create_nom_typedecls : string list -> theory -> theory
berghofe@18068
     6
  val atoms_of : theory -> string list
berghofe@18068
     7
  val mk_permT : typ -> typ
berghofe@18068
     8
  val setup : (theory -> theory) list
berghofe@18068
     9
end
berghofe@18068
    10
berghofe@18068
    11
structure NominalAtoms : NOMINAL_ATOMS =
berghofe@18068
    12
struct
berghofe@18068
    13
berghofe@18068
    14
(* data kind 'HOL/nominal' *)
berghofe@18068
    15
berghofe@18068
    16
structure NominalArgs =
berghofe@18068
    17
struct
berghofe@18068
    18
  val name = "HOL/nominal";
berghofe@18068
    19
  type T = unit Symtab.table;
berghofe@18068
    20
berghofe@18068
    21
  val empty = Symtab.empty;
berghofe@18068
    22
  val copy = I;
berghofe@18068
    23
  val extend = I;
berghofe@18068
    24
  fun merge _ x = Symtab.merge (K true) x;
berghofe@18068
    25
berghofe@18068
    26
  fun print sg tab = ();
berghofe@18068
    27
end;
berghofe@18068
    28
berghofe@18068
    29
structure NominalData = TheoryDataFun(NominalArgs);
berghofe@18068
    30
berghofe@18068
    31
fun atoms_of thy = map fst (Symtab.dest (NominalData.get thy));
berghofe@18068
    32
berghofe@18068
    33
(* FIXME: add to hologic.ML ? *)
berghofe@18068
    34
fun mk_listT T = Type ("List.list", [T]);
berghofe@18068
    35
fun mk_permT T = mk_listT (HOLogic.mk_prodT (T, T));
berghofe@18068
    36
berghofe@18068
    37
fun mk_Cons x xs =
berghofe@18068
    38
  let val T = fastype_of x
berghofe@18068
    39
  in Const ("List.list.Cons", T --> mk_listT T --> mk_listT T) $ x $ xs end;
berghofe@18068
    40
berghofe@18068
    41
(* FIXME: should be a library function *)
berghofe@18068
    42
fun cprod ([], ys) = []
berghofe@18068
    43
  | cprod (x :: xs, ys) = map (pair x) ys @ cprod (xs, ys);
berghofe@18068
    44
berghofe@18068
    45
(* this function sets up all matters related to atom-  *)
berghofe@18068
    46
(* kinds; the user specifies a list of atom-kind names *)
berghofe@18068
    47
(* atom_decl <ak1> ... <akn>                           *)
berghofe@18068
    48
fun create_nom_typedecls ak_names thy =
berghofe@18068
    49
  let
berghofe@18068
    50
    (* declares a type-decl for every atom-kind: *) 
berghofe@18068
    51
    (* that is typedecl <ak>                     *)
berghofe@18068
    52
    val thy1 = TypedefPackage.add_typedecls (map (fn x => (x,[],NoSyn)) ak_names) thy;
berghofe@18068
    53
    
berghofe@18068
    54
    (* produces a list consisting of pairs:         *)
berghofe@18068
    55
    (*  fst component is the atom-kind name         *)
berghofe@18068
    56
    (*  snd component is its type                   *)
berghofe@18068
    57
    val full_ak_names = map (Sign.intern_type (sign_of thy1)) ak_names;
berghofe@18068
    58
    val ak_names_types = ak_names ~~ map (Type o rpair []) full_ak_names;
berghofe@18068
    59
     
berghofe@18068
    60
    (* adds for every atom-kind an axiom             *)
berghofe@18068
    61
    (* <ak>_infinite: infinite (UNIV::<ak_type> set) *)
berghofe@18068
    62
    val (thy2,inf_axs) = PureThy.add_axioms_i (map (fn (ak_name, T) =>
berghofe@18068
    63
      let 
berghofe@18068
    64
	val name = ak_name ^ "_infinite"
berghofe@18068
    65
        val axiom = HOLogic.mk_Trueprop (HOLogic.mk_not
berghofe@18068
    66
                    (HOLogic.mk_mem (HOLogic.mk_UNIV T,
berghofe@18068
    67
                     Const ("Finite_Set.Finites", HOLogic.mk_setT (HOLogic.mk_setT T)))))
berghofe@18068
    68
      in
berghofe@18068
    69
	((name, axiom), []) 
berghofe@18068
    70
      end) ak_names_types) thy1;
berghofe@18068
    71
    
berghofe@18068
    72
    (* declares a swapping function for every atom-kind, it is         *)
berghofe@18068
    73
    (* const swap_<ak> :: <akT> * <akT> => <akT> => <akT>              *)
berghofe@18068
    74
    (* swap_<ak> (a,b) c = (if a=c then b (else if b=c then a else c)) *)
berghofe@18068
    75
    (* overloades then the general swap-function                       *) 
berghofe@18068
    76
    val (thy3, swap_eqs) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
    77
      let
berghofe@18068
    78
        val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
berghofe@18068
    79
        val swap_name = Sign.full_name (sign_of thy) ("swap_" ^ ak_name);
berghofe@18068
    80
        val a = Free ("a", T);
berghofe@18068
    81
        val b = Free ("b", T);
berghofe@18068
    82
        val c = Free ("c", T);
berghofe@18068
    83
        val ab = Free ("ab", HOLogic.mk_prodT (T, T))
berghofe@18068
    84
        val cif = Const ("HOL.If", HOLogic.boolT --> T --> T --> T);
berghofe@18068
    85
        val cswap_akname = Const (swap_name, swapT);
berghofe@18068
    86
        val cswap = Const ("nominal.swap", swapT)
berghofe@18068
    87
berghofe@18068
    88
        val name = "swap_"^ak_name^"_def";
berghofe@18068
    89
        val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq
berghofe@18068
    90
		   (cswap_akname $ HOLogic.mk_prod (a,b) $ c,
berghofe@18068
    91
                    cif $ HOLogic.mk_eq (a,c) $ b $ (cif $ HOLogic.mk_eq (b,c) $ a $ c)))
berghofe@18068
    92
        val def2 = Logic.mk_equals (cswap $ ab $ c, cswap_akname $ ab $ c)
berghofe@18068
    93
      in
berghofe@18068
    94
        thy |> Theory.add_consts_i [("swap_" ^ ak_name, swapT, NoSyn)] 
berghofe@18068
    95
            |> (#1 o PureThy.add_defs_i true [((name, def2),[])])
berghofe@18068
    96
            |> PrimrecPackage.add_primrec_i "" [(("", def1),[])]            
berghofe@18068
    97
      end) (thy2, ak_names_types);
berghofe@18068
    98
    
berghofe@18068
    99
    (* declares a permutation function for every atom-kind acting  *)
berghofe@18068
   100
    (* on such atoms                                               *)
berghofe@18068
   101
    (* const <ak>_prm_<ak> :: (<akT> * <akT>)list => akT => akT    *)
berghofe@18068
   102
    (* <ak>_prm_<ak> []     a = a                                  *)
berghofe@18068
   103
    (* <ak>_prm_<ak> (x#xs) a = swap_<ak> x (perm xs a)            *)
berghofe@18068
   104
    val (thy4, prm_eqs) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   105
      let
berghofe@18068
   106
        val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
berghofe@18068
   107
        val swap_name = Sign.full_name (sign_of thy) ("swap_" ^ ak_name)
berghofe@18068
   108
        val prmT = mk_permT T --> T --> T;
berghofe@18068
   109
        val prm_name = ak_name ^ "_prm_" ^ ak_name;
berghofe@18068
   110
        val qu_prm_name = Sign.full_name (sign_of thy) prm_name;
berghofe@18068
   111
        val x  = Free ("x", HOLogic.mk_prodT (T, T));
berghofe@18068
   112
        val xs = Free ("xs", mk_permT T);
berghofe@18068
   113
        val a  = Free ("a", T) ;
berghofe@18068
   114
berghofe@18068
   115
        val cnil  = Const ("List.list.Nil", mk_permT T);
berghofe@18068
   116
        
berghofe@18068
   117
        val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq (Const (qu_prm_name, prmT) $ cnil $ a, a));
berghofe@18068
   118
berghofe@18068
   119
        val def2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
berghofe@18068
   120
                   (Const (qu_prm_name, prmT) $ mk_Cons x xs $ a,
berghofe@18068
   121
                    Const (swap_name, swapT) $ x $ (Const (qu_prm_name, prmT) $ xs $ a)));
berghofe@18068
   122
      in
berghofe@18068
   123
        thy |> Theory.add_consts_i [(prm_name, mk_permT T --> T --> T, NoSyn)] 
berghofe@18068
   124
            |> PrimrecPackage.add_primrec_i "" [(("", def1), []),(("", def2), [])]
berghofe@18068
   125
      end) (thy3, ak_names_types);
berghofe@18068
   126
    
berghofe@18068
   127
    (* defines permutation functions for all combinations of atom-kinds; *)
berghofe@18068
   128
    (* there are a trivial cases and non-trivial cases                   *)
berghofe@18068
   129
    (* non-trivial case:                                                 *)
berghofe@18068
   130
    (* <ak>_prm_<ak>_def:  perm pi a == <ak>_prm_<ak> pi a               *)
berghofe@18068
   131
    (* trivial case with <ak> != <ak'>                                   *)
berghofe@18068
   132
    (* <ak>_prm<ak'>_def[simp]:  perm pi a == a                          *)
berghofe@18068
   133
    (*                                                                   *)
berghofe@18068
   134
    (* the trivial cases are added to the simplifier, while the non-     *)
berghofe@18068
   135
    (* have their own rules proved below                                 *)  
berghofe@18068
   136
    val (thy5, perm_defs) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   137
      foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   138
        let
berghofe@18068
   139
          val perm_def_name = ak_name ^ "_prm_" ^ ak_name';
berghofe@18068
   140
          val pi = Free ("pi", mk_permT T);
berghofe@18068
   141
          val a  = Free ("a", T');
berghofe@18068
   142
          val cperm = Const ("nominal.perm", mk_permT T --> T' --> T');
berghofe@18068
   143
          val cperm_def = Const (Sign.full_name (sign_of thy') perm_def_name, mk_permT T --> T' --> T');
berghofe@18068
   144
berghofe@18068
   145
          val name = ak_name ^ "_prm_" ^ ak_name' ^ "_def";
berghofe@18068
   146
          val def = Logic.mk_equals
berghofe@18068
   147
                    (cperm $ pi $ a, if ak_name = ak_name' then cperm_def $ pi $ a else a)
berghofe@18068
   148
        in
berghofe@18068
   149
          thy' |> PureThy.add_defs_i true [((name, def),[])] 
berghofe@18068
   150
        end) (thy, ak_names_types)) (thy4, ak_names_types);
berghofe@18068
   151
    
berghofe@18068
   152
    (* proves that every atom-kind is an instance of at *)
berghofe@18068
   153
    (* lemma at_<ak>_inst:                              *)
berghofe@18068
   154
    (* at TYPE(<ak>)                                    *)
berghofe@18068
   155
    val (thy6, prm_cons_thms) = 
berghofe@18068
   156
      thy5 |> PureThy.add_thms (map (fn (ak_name, T) =>
berghofe@18068
   157
      let
berghofe@18068
   158
        val ak_name_qu = Sign.full_name (sign_of thy5) (ak_name);
berghofe@18068
   159
        val i_type = Type(ak_name_qu,[]);
berghofe@18068
   160
	val cat = Const ("nominal.at",(Term.itselfT i_type)  --> HOLogic.boolT);
berghofe@18068
   161
        val at_type = Logic.mk_type i_type;
berghofe@18068
   162
        val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy5
berghofe@18068
   163
                                  [Name "at_def",
berghofe@18068
   164
                                   Name (ak_name ^ "_prm_" ^ ak_name ^ "_def"),
berghofe@18068
   165
                                   Name (ak_name ^ "_prm_" ^ ak_name ^ ".simps"),
berghofe@18068
   166
                                   Name ("swap_" ^ ak_name ^ "_def"),
berghofe@18068
   167
                                   Name ("swap_" ^ ak_name ^ ".simps"),
berghofe@18068
   168
                                   Name (ak_name ^ "_infinite")]
berghofe@18068
   169
	    
berghofe@18068
   170
	val name = "at_"^ak_name^ "_inst";
berghofe@18068
   171
        val statement = HOLogic.mk_Trueprop (cat $ at_type);
berghofe@18068
   172
berghofe@18068
   173
        val proof = fn _ => auto_tac (claset(),simp_s);
berghofe@18068
   174
berghofe@18068
   175
      in 
berghofe@18068
   176
        ((name, standard (Goal.prove thy5 [] [] statement proof)), []) 
berghofe@18068
   177
      end) ak_names_types);
berghofe@18068
   178
berghofe@18068
   179
    (* declares a perm-axclass for every atom-kind               *)
berghofe@18068
   180
    (* axclass pt_<ak>                                           *)
berghofe@18068
   181
    (* pt_<ak>1[simp]: perm [] x = x                             *)
berghofe@18068
   182
    (* pt_<ak>2:       perm (pi1@pi2) x = perm pi1 (perm pi2 x)  *)
berghofe@18068
   183
    (* pt_<ak>3:       pi1 ~ pi2 ==> perm pi1 x = perm pi2 x     *)
berghofe@18068
   184
     val (thy7, pt_ax_classes) =  foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   185
      let 
berghofe@18068
   186
	  val cl_name = "pt_"^ak_name;
berghofe@18068
   187
          val ty = TFree("'a",["HOL.type"]);
berghofe@18068
   188
          val x   = Free ("x", ty);
berghofe@18068
   189
          val pi1 = Free ("pi1", mk_permT T);
berghofe@18068
   190
          val pi2 = Free ("pi2", mk_permT T);
berghofe@18068
   191
          val cperm = Const ("nominal.perm", mk_permT T --> ty --> ty);
berghofe@18068
   192
          val cnil  = Const ("List.list.Nil", mk_permT T);
berghofe@18068
   193
          val cappend = Const ("List.op @",mk_permT T --> mk_permT T --> mk_permT T);
berghofe@18068
   194
          val cprm_eq = Const ("nominal.prm_eq",mk_permT T --> mk_permT T --> HOLogic.boolT);
berghofe@18068
   195
          (* nil axiom *)
berghofe@18068
   196
          val axiom1 = HOLogic.mk_Trueprop (HOLogic.mk_eq 
berghofe@18068
   197
                       (cperm $ cnil $ x, x));
berghofe@18068
   198
          (* append axiom *)
berghofe@18068
   199
          val axiom2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
berghofe@18068
   200
                       (cperm $ (cappend $ pi1 $ pi2) $ x, cperm $ pi1 $ (cperm $ pi2 $ x)));
berghofe@18068
   201
          (* perm-eq axiom *)
berghofe@18068
   202
          val axiom3 = Logic.mk_implies
berghofe@18068
   203
                       (HOLogic.mk_Trueprop (cprm_eq $ pi1 $ pi2),
berghofe@18068
   204
                        HOLogic.mk_Trueprop (HOLogic.mk_eq (cperm $ pi1 $ x, cperm $ pi2 $ x)));
berghofe@18068
   205
      in
berghofe@18068
   206
        thy |> AxClass.add_axclass_i (cl_name, ["HOL.type"])
berghofe@18068
   207
                [((cl_name^"1", axiom1),[Simplifier.simp_add_global]), 
berghofe@18068
   208
                 ((cl_name^"2", axiom2),[]),                           
berghofe@18068
   209
                 ((cl_name^"3", axiom3),[])]                          
berghofe@18068
   210
      end) (thy6,ak_names_types);
berghofe@18068
   211
berghofe@18068
   212
    (* proves that every pt_<ak>-type together with <ak>-type *)
berghofe@18068
   213
    (* instance of pt                                         *)
berghofe@18068
   214
    (* lemma pt_<ak>_inst:                                    *)
berghofe@18068
   215
    (* pt TYPE('x::pt_<ak>) TYPE(<ak>)                        *)
berghofe@18068
   216
    val (thy8, prm_inst_thms) = 
berghofe@18068
   217
      thy7 |> PureThy.add_thms (map (fn (ak_name, T) =>
berghofe@18068
   218
      let
berghofe@18068
   219
        val ak_name_qu = Sign.full_name (sign_of thy7) (ak_name);
berghofe@18068
   220
        val pt_name_qu = Sign.full_name (sign_of thy7) ("pt_"^ak_name);
berghofe@18068
   221
        val i_type1 = TFree("'x",[pt_name_qu]);
berghofe@18068
   222
        val i_type2 = Type(ak_name_qu,[]);
berghofe@18068
   223
	val cpt = Const ("nominal.pt",(Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
berghofe@18068
   224
        val pt_type = Logic.mk_type i_type1;
berghofe@18068
   225
        val at_type = Logic.mk_type i_type2;
berghofe@18068
   226
        val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy7
berghofe@18068
   227
                                  [Name "pt_def",
berghofe@18068
   228
                                   Name ("pt_" ^ ak_name ^ "1"),
berghofe@18068
   229
                                   Name ("pt_" ^ ak_name ^ "2"),
berghofe@18068
   230
                                   Name ("pt_" ^ ak_name ^ "3")];
berghofe@18068
   231
berghofe@18068
   232
	val name = "pt_"^ak_name^ "_inst";
berghofe@18068
   233
        val statement = HOLogic.mk_Trueprop (cpt $ pt_type $ at_type);
berghofe@18068
   234
berghofe@18068
   235
        val proof = fn _ => auto_tac (claset(),simp_s);
berghofe@18068
   236
      in 
berghofe@18068
   237
        ((name, standard (Goal.prove thy7 [] [] statement proof)), []) 
berghofe@18068
   238
      end) ak_names_types);
berghofe@18068
   239
berghofe@18068
   240
     (* declares an fs-axclass for every atom-kind       *)
berghofe@18068
   241
     (* axclass fs_<ak>                                  *)
berghofe@18068
   242
     (* fs_<ak>1: finite ((supp x)::<ak> set)            *)
berghofe@18068
   243
     val (thy11, fs_ax_classes) =  foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   244
       let 
berghofe@18068
   245
	  val cl_name = "fs_"^ak_name;
berghofe@18068
   246
	  val pt_name = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   247
          val ty = TFree("'a",["HOL.type"]);
berghofe@18068
   248
          val x   = Free ("x", ty);
berghofe@18068
   249
          val csupp    = Const ("nominal.supp", ty --> HOLogic.mk_setT T);
berghofe@18068
   250
          val cfinites = Const ("Finite_Set.Finites", HOLogic.mk_setT (HOLogic.mk_setT T))
berghofe@18068
   251
          
berghofe@18068
   252
          val axiom1   = HOLogic.mk_Trueprop (HOLogic.mk_mem (csupp $ x, cfinites));
berghofe@18068
   253
berghofe@18068
   254
       in  
berghofe@18068
   255
        thy |> AxClass.add_axclass_i (cl_name, [pt_name]) [((cl_name^"1", axiom1),[])]            
berghofe@18068
   256
       end) (thy8,ak_names_types); 
berghofe@18068
   257
berghofe@18068
   258
     (* proves that every fs_<ak>-type together with <ak>-type   *)
berghofe@18068
   259
     (* instance of fs-type                                      *)
berghofe@18068
   260
     (* lemma abst_<ak>_inst:                                    *)
berghofe@18068
   261
     (* fs TYPE('x::pt_<ak>) TYPE (<ak>)                         *)
berghofe@18068
   262
     val (thy12, fs_inst_thms) = 
berghofe@18068
   263
       thy11 |> PureThy.add_thms (map (fn (ak_name, T) =>
berghofe@18068
   264
       let
berghofe@18068
   265
         val ak_name_qu = Sign.full_name (sign_of thy11) (ak_name);
berghofe@18068
   266
         val fs_name_qu = Sign.full_name (sign_of thy11) ("fs_"^ak_name);
berghofe@18068
   267
         val i_type1 = TFree("'x",[fs_name_qu]);
berghofe@18068
   268
         val i_type2 = Type(ak_name_qu,[]);
berghofe@18068
   269
 	 val cfs = Const ("nominal.fs", 
berghofe@18068
   270
                                 (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
berghofe@18068
   271
         val fs_type = Logic.mk_type i_type1;
berghofe@18068
   272
         val at_type = Logic.mk_type i_type2;
berghofe@18068
   273
	 val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy11
berghofe@18068
   274
                                   [Name "fs_def",
berghofe@18068
   275
                                    Name ("fs_" ^ ak_name ^ "1")];
berghofe@18068
   276
    
berghofe@18068
   277
	 val name = "fs_"^ak_name^ "_inst";
berghofe@18068
   278
         val statement = HOLogic.mk_Trueprop (cfs $ fs_type $ at_type);
berghofe@18068
   279
berghofe@18068
   280
         val proof = fn _ => auto_tac (claset(),simp_s);
berghofe@18068
   281
       in 
berghofe@18068
   282
         ((name, standard (Goal.prove thy11 [] [] statement proof)), []) 
berghofe@18068
   283
       end) ak_names_types);
berghofe@18068
   284
berghofe@18068
   285
       (* declares for every atom-kind combination an axclass            *)
berghofe@18068
   286
       (* cp_<ak1>_<ak2> giving a composition property                   *)
berghofe@18068
   287
       (* cp_<ak1>_<ak2>1: pi1 o pi2 o x = (pi1 o pi2) o (pi1 o x)       *)
berghofe@18068
   288
        val (thy12b,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   289
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   290
	     let
berghofe@18068
   291
	       val cl_name = "cp_"^ak_name^"_"^ak_name';
berghofe@18068
   292
	       val ty = TFree("'a",["HOL.type"]);
berghofe@18068
   293
               val x   = Free ("x", ty);
berghofe@18068
   294
               val pi1 = Free ("pi1", mk_permT T);
berghofe@18068
   295
	       val pi2 = Free ("pi2", mk_permT T');                  
berghofe@18068
   296
	       val cperm1 = Const ("nominal.perm", mk_permT T  --> ty --> ty);
berghofe@18068
   297
               val cperm2 = Const ("nominal.perm", mk_permT T' --> ty --> ty);
berghofe@18068
   298
               val cperm3 = Const ("nominal.perm", mk_permT T  --> mk_permT T' --> mk_permT T');
berghofe@18068
   299
berghofe@18068
   300
               val ax1   = HOLogic.mk_Trueprop 
berghofe@18068
   301
			   (HOLogic.mk_eq (cperm1 $ pi1 $ (cperm2 $ pi2 $ x), 
berghofe@18068
   302
                                           cperm2 $ (cperm3 $ pi1 $ pi2) $ (cperm1 $ pi1 $ x)));
berghofe@18068
   303
	       in  
berghofe@18068
   304
	       (fst (AxClass.add_axclass_i (cl_name, ["HOL.type"]) [((cl_name^"1", ax1),[])] thy'),())  
berghofe@18068
   305
	       end) 
berghofe@18068
   306
	   (thy, ak_names_types)) (thy12, ak_names_types)
berghofe@18068
   307
berghofe@18068
   308
        (* proves for every <ak>-combination a cp_<ak1>_<ak2>_inst theorem;     *)
berghofe@18068
   309
        (* lemma cp_<ak1>_<ak2>_inst:                                           *)
berghofe@18068
   310
        (* cp TYPE('a::cp_<ak1>_<ak2>) TYPE(<ak1>) TYPE(<ak2>)                  *)
berghofe@18068
   311
        val (thy12c, cp_thms) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   312
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   313
           let
berghofe@18068
   314
             val ak_name_qu  = Sign.full_name (sign_of thy') (ak_name);
berghofe@18068
   315
	     val ak_name_qu' = Sign.full_name (sign_of thy') (ak_name');
berghofe@18068
   316
             val cp_name_qu  = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   317
             val i_type0 = TFree("'a",[cp_name_qu]);
berghofe@18068
   318
             val i_type1 = Type(ak_name_qu,[]);
berghofe@18068
   319
             val i_type2 = Type(ak_name_qu',[]);
berghofe@18068
   320
	     val ccp = Const ("nominal.cp",
berghofe@18068
   321
                             (Term.itselfT i_type0)-->(Term.itselfT i_type1)-->
berghofe@18068
   322
                                                      (Term.itselfT i_type2)-->HOLogic.boolT);
berghofe@18068
   323
             val at_type  = Logic.mk_type i_type1;
berghofe@18068
   324
             val at_type' = Logic.mk_type i_type2;
berghofe@18068
   325
	     val cp_type  = Logic.mk_type i_type0;
berghofe@18068
   326
             val simp_s   = HOL_basic_ss addsimps PureThy.get_thmss thy' [(Name "cp_def")];
berghofe@18068
   327
	     val cp1      = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"1"));
berghofe@18068
   328
berghofe@18068
   329
	     val name = "cp_"^ak_name^ "_"^ak_name'^"_inst";
berghofe@18068
   330
             val statement = HOLogic.mk_Trueprop (ccp $ cp_type $ at_type $ at_type');
berghofe@18068
   331
berghofe@18068
   332
             val proof = fn _ => EVERY [auto_tac (claset(),simp_s), rtac cp1 1];
berghofe@18068
   333
	   in
berghofe@18068
   334
	     thy' |> PureThy.add_thms 
berghofe@18068
   335
                    [((name, standard (Goal.prove thy' [] [] statement proof)), [])]
berghofe@18068
   336
	   end) 
berghofe@18068
   337
	   (thy, ak_names_types)) (thy12b, ak_names_types);
berghofe@18068
   338
       
berghofe@18068
   339
        (* proves for every non-trivial <ak>-combination a disjointness   *)
berghofe@18068
   340
        (* theorem; i.e. <ak1> != <ak2>                                   *)
berghofe@18068
   341
        (* lemma ds_<ak1>_<ak2>:                                          *)
berghofe@18068
   342
        (* dj TYPE(<ak1>) TYPE(<ak2>)                                     *)
berghofe@18068
   343
        val (thy12d, dj_thms) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   344
	  foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   345
          (if not (ak_name = ak_name') 
berghofe@18068
   346
           then 
berghofe@18068
   347
	       let
berghofe@18068
   348
		 val ak_name_qu  = Sign.full_name (sign_of thy') (ak_name);
berghofe@18068
   349
	         val ak_name_qu' = Sign.full_name (sign_of thy') (ak_name');
berghofe@18068
   350
                 val i_type1 = Type(ak_name_qu,[]);
berghofe@18068
   351
                 val i_type2 = Type(ak_name_qu',[]);
berghofe@18068
   352
	         val cdj = Const ("nominal.disjoint",
berghofe@18068
   353
                           (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
berghofe@18068
   354
                 val at_type  = Logic.mk_type i_type1;
berghofe@18068
   355
                 val at_type' = Logic.mk_type i_type2;
berghofe@18068
   356
                 val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy' 
berghofe@18068
   357
					   [Name "disjoint_def",
berghofe@18068
   358
                                            Name (ak_name^"_prm_"^ak_name'^"_def"),
berghofe@18068
   359
                                            Name (ak_name'^"_prm_"^ak_name^"_def")];
berghofe@18068
   360
berghofe@18068
   361
	         val name = "dj_"^ak_name^"_"^ak_name';
berghofe@18068
   362
                 val statement = HOLogic.mk_Trueprop (cdj $ at_type $ at_type');
berghofe@18068
   363
berghofe@18068
   364
                 val proof = fn _ => auto_tac (claset(),simp_s);
berghofe@18068
   365
	       in
berghofe@18068
   366
		   thy' |> PureThy.add_thms 
berghofe@18068
   367
                        [((name, standard (Goal.prove thy' [] [] statement proof)), []) ]
berghofe@18068
   368
	       end
berghofe@18068
   369
           else 
berghofe@18068
   370
            (thy',[])))  (* do nothing branch, if ak_name = ak_name' *) 
berghofe@18068
   371
	   (thy, ak_names_types)) (thy12c, ak_names_types);
berghofe@18068
   372
berghofe@18068
   373
     (*<<<<<<<  pt_<ak> class instances  >>>>>>>*)
berghofe@18068
   374
     (*=========================================*)
berghofe@18068
   375
     
berghofe@18068
   376
     (* some frequently used theorems *)
berghofe@18068
   377
      val pt1 = PureThy.get_thm thy12c (Name "pt1");
berghofe@18068
   378
      val pt2 = PureThy.get_thm thy12c (Name "pt2");
berghofe@18068
   379
      val pt3 = PureThy.get_thm thy12c (Name "pt3");
berghofe@18068
   380
      val at_pt_inst    = PureThy.get_thm thy12c (Name "at_pt_inst");
berghofe@18068
   381
      val pt_bool_inst  = PureThy.get_thm thy12c (Name "pt_bool_inst");
berghofe@18068
   382
      val pt_set_inst   = PureThy.get_thm thy12c (Name "pt_set_inst"); 
berghofe@18068
   383
      val pt_unit_inst  = PureThy.get_thm thy12c (Name "pt_unit_inst");
berghofe@18068
   384
      val pt_prod_inst  = PureThy.get_thm thy12c (Name "pt_prod_inst"); 
berghofe@18068
   385
      val pt_list_inst  = PureThy.get_thm thy12c (Name "pt_list_inst");   
berghofe@18068
   386
      val pt_optn_inst  = PureThy.get_thm thy12c (Name "pt_option_inst");   
berghofe@18068
   387
      val pt_noptn_inst = PureThy.get_thm thy12c (Name "pt_noption_inst");   
berghofe@18068
   388
      val pt_fun_inst   = PureThy.get_thm thy12c (Name "pt_fun_inst");     
berghofe@18068
   389
berghofe@18068
   390
     (* for all atom-kind combination shows that         *)
berghofe@18068
   391
     (* every <ak> is an instance of pt_<ai>             *)
berghofe@18068
   392
     val (thy13,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   393
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   394
          (if ak_name = ak_name'
berghofe@18068
   395
	   then
berghofe@18068
   396
	     let
berghofe@18068
   397
	      val qu_name =  Sign.full_name (sign_of thy') ak_name;
berghofe@18068
   398
              val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
berghofe@18068
   399
              val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name ^"_inst"));
berghofe@18068
   400
              val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   401
                                 rtac ((at_inst RS at_pt_inst) RS pt1) 1,
berghofe@18068
   402
                                 rtac ((at_inst RS at_pt_inst) RS pt2) 1,
berghofe@18068
   403
                                 rtac ((at_inst RS at_pt_inst) RS pt3) 1,
berghofe@18068
   404
                                 atac 1];
berghofe@18068
   405
             in 
berghofe@18068
   406
	      (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy',()) 
berghofe@18068
   407
             end
berghofe@18068
   408
           else 
berghofe@18068
   409
             let
berghofe@18068
   410
	      val qu_name' = Sign.full_name (sign_of thy') ak_name';
berghofe@18068
   411
              val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
berghofe@18068
   412
              val simp_s = HOL_basic_ss addsimps 
berghofe@18068
   413
                           PureThy.get_thmss thy' [Name (ak_name^"_prm_"^ak_name'^"_def")];  
berghofe@18068
   414
              val proof = EVERY [AxClass.intro_classes_tac [], auto_tac (claset(),simp_s)];
berghofe@18068
   415
             in 
berghofe@18068
   416
	      (AxClass.add_inst_arity_i (qu_name',[],[qu_class]) proof thy',()) 
berghofe@18068
   417
             end)) 
berghofe@18068
   418
	     (thy, ak_names_types)) (thy12c, ak_names_types);
berghofe@18068
   419
berghofe@18068
   420
     (* shows that bool is an instance of pt_<ak>     *)
berghofe@18068
   421
     (* uses the theorem pt_bool_inst                 *)
berghofe@18068
   422
     val (thy14,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   423
       let
berghofe@18068
   424
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   425
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   426
                             rtac (pt_bool_inst RS pt1) 1,
berghofe@18068
   427
                             rtac (pt_bool_inst RS pt2) 1,
berghofe@18068
   428
                             rtac (pt_bool_inst RS pt3) 1,
berghofe@18068
   429
                             atac 1];
berghofe@18068
   430
       in 
berghofe@18068
   431
	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
berghofe@18068
   432
       end) (thy13,ak_names_types); 
berghofe@18068
   433
berghofe@18068
   434
     (* shows that set(pt_<ak>) is an instance of pt_<ak>          *)
berghofe@18068
   435
     (* unfolds the permutation definition and applies pt_<ak>i    *)
berghofe@18068
   436
     val (thy15,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   437
       let
berghofe@18068
   438
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   439
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));  
berghofe@18068
   440
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   441
                             rtac ((pt_inst RS pt_set_inst) RS pt1) 1,
berghofe@18068
   442
                             rtac ((pt_inst RS pt_set_inst) RS pt2) 1,
berghofe@18068
   443
                             rtac ((pt_inst RS pt_set_inst) RS pt3) 1,
berghofe@18068
   444
                             atac 1];
berghofe@18068
   445
       in 
berghofe@18068
   446
	 (AxClass.add_inst_arity_i ("set",[[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   447
       end) (thy14,ak_names_types); 
berghofe@18068
   448
berghofe@18068
   449
     (* shows that unit is an instance of pt_<ak>          *)
berghofe@18068
   450
     val (thy16,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   451
       let
berghofe@18068
   452
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   453
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   454
                             rtac (pt_unit_inst RS pt1) 1,
berghofe@18068
   455
                             rtac (pt_unit_inst RS pt2) 1,
berghofe@18068
   456
                             rtac (pt_unit_inst RS pt3) 1,
berghofe@18068
   457
                             atac 1];
berghofe@18068
   458
       in 
berghofe@18068
   459
	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
berghofe@18068
   460
       end) (thy15,ak_names_types); 
berghofe@18068
   461
berghofe@18068
   462
     (* shows that *(pt_<ak>,pt_<ak>) is an instance of pt_<ak> *)
berghofe@18068
   463
     (* uses the theorem pt_prod_inst and pt_<ak>_inst          *)
berghofe@18068
   464
     val (thy17,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   465
       let
berghofe@18068
   466
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   467
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));  
berghofe@18068
   468
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   469
                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt1) 1,
berghofe@18068
   470
                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt2) 1,
berghofe@18068
   471
                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt3) 1,
berghofe@18068
   472
                             atac 1];
berghofe@18068
   473
       in 
berghofe@18068
   474
          (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   475
       end) (thy16,ak_names_types); 
berghofe@18068
   476
berghofe@18068
   477
     (* shows that list(pt_<ak>) is an instance of pt_<ak>     *)
berghofe@18068
   478
     (* uses the theorem pt_list_inst and pt_<ak>_inst         *)
berghofe@18068
   479
     val (thy18,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   480
       let
berghofe@18068
   481
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   482
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   483
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   484
                             rtac ((pt_inst RS pt_list_inst) RS pt1) 1,
berghofe@18068
   485
                             rtac ((pt_inst RS pt_list_inst) RS pt2) 1,
berghofe@18068
   486
                             rtac ((pt_inst RS pt_list_inst) RS pt3) 1,
berghofe@18068
   487
                             atac 1];      
berghofe@18068
   488
       in 
berghofe@18068
   489
	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   490
       end) (thy17,ak_names_types); 
berghofe@18068
   491
berghofe@18068
   492
     (* shows that option(pt_<ak>) is an instance of pt_<ak>   *)
berghofe@18068
   493
     (* uses the theorem pt_option_inst and pt_<ak>_inst       *)
berghofe@18068
   494
     val (thy18a,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   495
       let
berghofe@18068
   496
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   497
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   498
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   499
                             rtac ((pt_inst RS pt_optn_inst) RS pt1) 1,
berghofe@18068
   500
                             rtac ((pt_inst RS pt_optn_inst) RS pt2) 1,
berghofe@18068
   501
                             rtac ((pt_inst RS pt_optn_inst) RS pt3) 1,
berghofe@18068
   502
                             atac 1];      
berghofe@18068
   503
       in 
berghofe@18068
   504
	 (AxClass.add_inst_arity_i ("Datatype.option",[[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   505
       end) (thy18,ak_names_types); 
berghofe@18068
   506
berghofe@18068
   507
     (* shows that nOption(pt_<ak>) is an instance of pt_<ak>   *)
berghofe@18068
   508
     (* uses the theorem pt_option_inst and pt_<ak>_inst       *)
berghofe@18068
   509
     val (thy18b,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   510
       let
berghofe@18068
   511
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   512
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   513
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   514
                             rtac ((pt_inst RS pt_noptn_inst) RS pt1) 1,
berghofe@18068
   515
                             rtac ((pt_inst RS pt_noptn_inst) RS pt2) 1,
berghofe@18068
   516
                             rtac ((pt_inst RS pt_noptn_inst) RS pt3) 1,
berghofe@18068
   517
                             atac 1];      
berghofe@18068
   518
       in 
berghofe@18068
   519
	 (AxClass.add_inst_arity_i ("nominal.nOption",[[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   520
       end) (thy18a,ak_names_types); 
berghofe@18068
   521
berghofe@18068
   522
berghofe@18068
   523
     (* shows that fun(pt_<ak>,pt_<ak>) is an instance of pt_<ak>     *)
berghofe@18068
   524
     (* uses the theorem pt_list_inst and pt_<ak>_inst                *)
berghofe@18068
   525
     val (thy19,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   526
       let
berghofe@18068
   527
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
berghofe@18068
   528
          val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
berghofe@18068
   529
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   530
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   531
                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt1) 1,
berghofe@18068
   532
                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt2) 1,
berghofe@18068
   533
                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt3) 1,
berghofe@18068
   534
                             atac 1];      
berghofe@18068
   535
       in 
berghofe@18068
   536
	 (AxClass.add_inst_arity_i ("fun",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   537
       end) (thy18b,ak_names_types);
berghofe@18068
   538
berghofe@18068
   539
       (*<<<<<<<  fs_<ak> class instances  >>>>>>>*)
berghofe@18068
   540
       (*=========================================*)
berghofe@18068
   541
       val fs1          = PureThy.get_thm thy19 (Name "fs1");
berghofe@18068
   542
       val fs_at_inst   = PureThy.get_thm thy19 (Name "fs_at_inst");
berghofe@18068
   543
       val fs_unit_inst = PureThy.get_thm thy19 (Name "fs_unit_inst");
berghofe@18068
   544
       val fs_bool_inst = PureThy.get_thm thy19 (Name "fs_bool_inst");
berghofe@18068
   545
       val fs_prod_inst = PureThy.get_thm thy19 (Name "fs_prod_inst");
berghofe@18068
   546
       val fs_list_inst = PureThy.get_thm thy19 (Name "fs_list_inst");
berghofe@18068
   547
berghofe@18068
   548
       (* shows that <ak> is an instance of fs_<ak>     *)
berghofe@18068
   549
       (* uses the theorem at_<ak>_inst                 *)
berghofe@18068
   550
       val (thy20,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   551
       let
berghofe@18068
   552
          val qu_name =  Sign.full_name (sign_of thy) ak_name;
berghofe@18068
   553
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
berghofe@18068
   554
          val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
berghofe@18068
   555
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   556
                             rtac ((at_thm RS fs_at_inst) RS fs1) 1];      
berghofe@18068
   557
       in 
berghofe@18068
   558
	 (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy,()) 
berghofe@18068
   559
       end) (thy19,ak_names_types);  
berghofe@18068
   560
berghofe@18068
   561
       (* shows that unit is an instance of fs_<ak>     *)
berghofe@18068
   562
       (* uses the theorem fs_unit_inst                 *)
berghofe@18068
   563
       val (thy21,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   564
       let
berghofe@18068
   565
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
berghofe@18068
   566
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   567
                             rtac (fs_unit_inst RS fs1) 1];      
berghofe@18068
   568
       in 
berghofe@18068
   569
	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
berghofe@18068
   570
       end) (thy20,ak_names_types);  
berghofe@18068
   571
berghofe@18068
   572
       (* shows that bool is an instance of fs_<ak>     *)
berghofe@18068
   573
       (* uses the theorem fs_bool_inst                 *)
berghofe@18068
   574
       val (thy22,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   575
       let
berghofe@18068
   576
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
berghofe@18068
   577
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   578
                             rtac (fs_bool_inst RS fs1) 1];      
berghofe@18068
   579
       in 
berghofe@18068
   580
	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
berghofe@18068
   581
       end) (thy21,ak_names_types);  
berghofe@18068
   582
berghofe@18068
   583
       (* shows that *(fs_<ak>,fs_<ak>) is an instance of fs_<ak>     *)
berghofe@18068
   584
       (* uses the theorem fs_prod_inst                               *)
berghofe@18068
   585
       val (thy23,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   586
       let
berghofe@18068
   587
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
berghofe@18068
   588
          val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
berghofe@18068
   589
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   590
                             rtac ((fs_inst RS (fs_inst RS fs_prod_inst)) RS fs1) 1];      
berghofe@18068
   591
       in 
berghofe@18068
   592
	 (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   593
       end) (thy22,ak_names_types);  
berghofe@18068
   594
berghofe@18068
   595
       (* shows that list(fs_<ak>) is an instance of fs_<ak>     *)
berghofe@18068
   596
       (* uses the theorem fs_list_inst                          *)
berghofe@18068
   597
       val (thy24,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   598
       let
berghofe@18068
   599
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
berghofe@18068
   600
          val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
berghofe@18068
   601
          val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   602
                              rtac ((fs_inst RS fs_list_inst) RS fs1) 1];      
berghofe@18068
   603
       in 
berghofe@18068
   604
	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
berghofe@18068
   605
       end) (thy23,ak_names_types);  
berghofe@18068
   606
	   
berghofe@18068
   607
       (*<<<<<<<  cp_<ak>_<ai> class instances  >>>>>>>*)
berghofe@18068
   608
       (*==============================================*)
berghofe@18068
   609
       val cp1             = PureThy.get_thm thy24 (Name "cp1");
berghofe@18068
   610
       val cp_unit_inst    = PureThy.get_thm thy24 (Name "cp_unit_inst");
berghofe@18068
   611
       val cp_bool_inst    = PureThy.get_thm thy24 (Name "cp_bool_inst");
berghofe@18068
   612
       val cp_prod_inst    = PureThy.get_thm thy24 (Name "cp_prod_inst");
berghofe@18068
   613
       val cp_list_inst    = PureThy.get_thm thy24 (Name "cp_list_inst");
berghofe@18068
   614
       val cp_fun_inst     = PureThy.get_thm thy24 (Name "cp_fun_inst");
berghofe@18068
   615
       val cp_option_inst  = PureThy.get_thm thy24 (Name "cp_option_inst");
berghofe@18068
   616
       val cp_noption_inst = PureThy.get_thm thy24 (Name "cp_noption_inst");
berghofe@18068
   617
       val pt_perm_compose = PureThy.get_thm thy24 (Name "pt_perm_compose");
berghofe@18068
   618
       val dj_pp_forget    = PureThy.get_thm thy24 (Name "dj_perm_perm_forget");
berghofe@18068
   619
berghofe@18068
   620
       (* shows that <aj> is an instance of cp_<ak>_<ai>  *)
berghofe@18068
   621
       (* that needs a three-nested loop *)
berghofe@18068
   622
       val (thy25,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   623
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   624
          foldl_map (fn (thy'', (ak_name'', T'')) =>
berghofe@18068
   625
            let
berghofe@18068
   626
              val qu_name =  Sign.full_name (sign_of thy'') ak_name;
berghofe@18068
   627
              val qu_class = Sign.full_name (sign_of thy'') ("cp_"^ak_name'^"_"^ak_name'');
berghofe@18068
   628
              val proof =
berghofe@18068
   629
                (if (ak_name'=ak_name'') then 
berghofe@18068
   630
		  (let
berghofe@18068
   631
                    val pt_inst  = PureThy.get_thm thy'' (Name ("pt_"^ak_name''^"_inst"));
berghofe@18068
   632
		    val at_inst  = PureThy.get_thm thy'' (Name ("at_"^ak_name''^"_inst"));
berghofe@18068
   633
                  in 
berghofe@18068
   634
		   EVERY [AxClass.intro_classes_tac [], 
berghofe@18068
   635
                          rtac (at_inst RS (pt_inst RS pt_perm_compose)) 1]
berghofe@18068
   636
                  end)
berghofe@18068
   637
		else
berghofe@18068
   638
		  (let 
berghofe@18068
   639
                     val dj_inst  = PureThy.get_thm thy'' (Name ("dj_"^ak_name''^"_"^ak_name'));
berghofe@18068
   640
		     val simp_s = HOL_basic_ss addsimps 
berghofe@18068
   641
                                        ((dj_inst RS dj_pp_forget)::
berghofe@18068
   642
                                         (PureThy.get_thmss thy'' 
berghofe@18068
   643
					   [Name (ak_name' ^"_prm_"^ak_name^"_def"),
berghofe@18068
   644
                                            Name (ak_name''^"_prm_"^ak_name^"_def")]));  
berghofe@18068
   645
		  in 
berghofe@18068
   646
                    EVERY [AxClass.intro_classes_tac [], simp_tac simp_s 1]
berghofe@18068
   647
                  end))
berghofe@18068
   648
	      in
berghofe@18068
   649
                (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy'',())
berghofe@18068
   650
	      end)
berghofe@18068
   651
	   (thy', ak_names_types)) (thy, ak_names_types)) (thy24, ak_names_types);
berghofe@18068
   652
      
berghofe@18068
   653
       (* shows that unit is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   654
       (* for every <ak>-combination                         *)
berghofe@18068
   655
       val (thy26,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   656
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   657
          let
berghofe@18068
   658
            val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   659
            val proof = EVERY [AxClass.intro_classes_tac [],rtac (cp_unit_inst RS cp1) 1];     
berghofe@18068
   660
	  in
berghofe@18068
   661
            (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy',())
berghofe@18068
   662
	  end) 
berghofe@18068
   663
	   (thy, ak_names_types)) (thy25, ak_names_types);
berghofe@18068
   664
       
berghofe@18068
   665
       (* shows that bool is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   666
       (* for every <ak>-combination                         *)
berghofe@18068
   667
       val (thy27,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   668
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   669
           let
berghofe@18068
   670
	     val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   671
             val proof = EVERY [AxClass.intro_classes_tac [], rtac (cp_bool_inst RS cp1) 1];     
berghofe@18068
   672
	   in
berghofe@18068
   673
             (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy',())
berghofe@18068
   674
	   end) 
berghofe@18068
   675
	   (thy, ak_names_types)) (thy26, ak_names_types);
berghofe@18068
   676
berghofe@18068
   677
       (* shows that prod is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   678
       (* for every <ak>-combination                         *)
berghofe@18068
   679
       val (thy28,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   680
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   681
          let
berghofe@18068
   682
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   683
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   684
            val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   685
                               rtac ((cp_inst RS (cp_inst RS cp_prod_inst)) RS cp1) 1];     
berghofe@18068
   686
	  in
berghofe@18068
   687
            (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy',())
berghofe@18068
   688
	  end)  
berghofe@18068
   689
	  (thy, ak_names_types)) (thy27, ak_names_types);
berghofe@18068
   690
berghofe@18068
   691
       (* shows that list is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   692
       (* for every <ak>-combination                         *)
berghofe@18068
   693
       val (thy29,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   694
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   695
           let
berghofe@18068
   696
	     val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   697
             val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   698
             val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   699
                                rtac ((cp_inst RS cp_list_inst) RS cp1) 1];     
berghofe@18068
   700
	   in
berghofe@18068
   701
            (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy',())
berghofe@18068
   702
	   end) 
berghofe@18068
   703
	   (thy, ak_names_types)) (thy28, ak_names_types);
berghofe@18068
   704
berghofe@18068
   705
       (* shows that function is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   706
       (* for every <ak>-combination                             *)
berghofe@18068
   707
       val (thy30,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   708
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   709
          let
berghofe@18068
   710
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   711
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   712
            val pt_inst  = PureThy.get_thm thy' (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   713
            val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name^"_inst"));
berghofe@18068
   714
            val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   715
                    rtac ((at_inst RS (pt_inst RS (cp_inst RS (cp_inst RS cp_fun_inst)))) RS cp1) 1];  
berghofe@18068
   716
	  in
berghofe@18068
   717
            (AxClass.add_inst_arity_i ("fun",[[qu_class],[qu_class]],[qu_class]) proof thy',())
berghofe@18068
   718
	  end) 
berghofe@18068
   719
	  (thy, ak_names_types)) (thy29, ak_names_types);
berghofe@18068
   720
berghofe@18068
   721
       (* shows that option is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   722
       (* for every <ak>-combination                           *)
berghofe@18068
   723
       val (thy31,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   724
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   725
          let
berghofe@18068
   726
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   727
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   728
            val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   729
                               rtac ((cp_inst RS cp_option_inst) RS cp1) 1];     
berghofe@18068
   730
	  in
berghofe@18068
   731
            (AxClass.add_inst_arity_i ("Datatype.option",[[qu_class]],[qu_class]) proof thy',())
berghofe@18068
   732
	  end) 
berghofe@18068
   733
	  (thy, ak_names_types)) (thy30, ak_names_types);
berghofe@18068
   734
berghofe@18068
   735
       (* shows that nOption is an instance of cp_<ak>_<ai>     *)
berghofe@18068
   736
       (* for every <ak>-combination                            *)
berghofe@18068
   737
       val (thy32,_) = foldl_map (fn (thy, (ak_name, T)) =>
berghofe@18068
   738
	 foldl_map (fn (thy', (ak_name', T')) =>
berghofe@18068
   739
          let
berghofe@18068
   740
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
berghofe@18068
   741
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   742
            val proof = EVERY [AxClass.intro_classes_tac [],
berghofe@18068
   743
                               rtac ((cp_inst RS cp_noption_inst) RS cp1) 1];     
berghofe@18068
   744
	  in
berghofe@18068
   745
           (AxClass.add_inst_arity_i ("nominal.nOption",[[qu_class]],[qu_class]) proof thy',())
berghofe@18068
   746
	  end) 
berghofe@18068
   747
	  (thy, ak_names_types)) (thy31, ak_names_types);
berghofe@18068
   748
berghofe@18068
   749
       (* abbreviations for some collection of rules *)
berghofe@18068
   750
       (*============================================*)
berghofe@18068
   751
       val abs_fun_pi        = PureThy.get_thm thy32 (Name ("nominal.abs_fun_pi"));
berghofe@18068
   752
       val abs_fun_pi_ineq   = PureThy.get_thm thy32 (Name ("nominal.abs_fun_pi_ineq"));
berghofe@18068
   753
       val abs_fun_eq        = PureThy.get_thm thy32 (Name ("nominal.abs_fun_eq"));
berghofe@18068
   754
       val dj_perm_forget    = PureThy.get_thm thy32 (Name ("nominal.dj_perm_forget"));
berghofe@18068
   755
       val dj_pp_forget      = PureThy.get_thm thy32 (Name ("nominal.dj_perm_perm_forget"));
berghofe@18068
   756
       val fresh_iff         = PureThy.get_thm thy32 (Name ("nominal.fresh_abs_fun_iff"));
berghofe@18068
   757
       val fresh_iff_ineq    = PureThy.get_thm thy32 (Name ("nominal.fresh_abs_fun_iff_ineq"));
berghofe@18068
   758
       val abs_fun_supp      = PureThy.get_thm thy32 (Name ("nominal.abs_fun_supp"));
berghofe@18068
   759
       val abs_fun_supp_ineq = PureThy.get_thm thy32 (Name ("nominal.abs_fun_supp_ineq"));
berghofe@18068
   760
       val pt_swap_bij       = PureThy.get_thm thy32 (Name ("nominal.pt_swap_bij"));
berghofe@18068
   761
       val pt_fresh_fresh    = PureThy.get_thm thy32 (Name ("nominal.pt_fresh_fresh"));
berghofe@18068
   762
       val pt_bij            = PureThy.get_thm thy32 (Name ("nominal.pt_bij"));
berghofe@18068
   763
       val pt_perm_compose   = PureThy.get_thm thy32 (Name ("nominal.pt_perm_compose"));
berghofe@18068
   764
       val perm_eq_app       = PureThy.get_thm thy32 (Name ("nominal.perm_eq_app"));
berghofe@18068
   765
       val at_fresh          = PureThy.get_thm thy32 (Name ("nominal.at_fresh"));
berghofe@18068
   766
       val at_calc           = PureThy.get_thms thy32 (Name ("nominal.at_calc"));
berghofe@18068
   767
       val at_supp           = PureThy.get_thm thy32 (Name ("nominal.at_supp"));
berghofe@18068
   768
       val dj_supp           = PureThy.get_thm thy32 (Name ("nominal.dj_supp"));
berghofe@18068
   769
berghofe@18068
   770
       (* abs_perm collects all lemmas for simplifying a permutation *)
berghofe@18068
   771
       (* in front of an abs_fun                                     *)
berghofe@18068
   772
       val (thy33,_) = 
berghofe@18068
   773
	   let 
berghofe@18068
   774
	     val name = "abs_perm"
berghofe@18068
   775
             val thm_list = Library.flat (map (fn (ak_name, T) =>
berghofe@18068
   776
	        let	
berghofe@18068
   777
		  val at_inst = PureThy.get_thm thy32 (Name ("at_"^ak_name^"_inst"));
berghofe@18068
   778
		  val pt_inst = PureThy.get_thm thy32 (Name ("pt_"^ak_name^"_inst"));	      
berghofe@18068
   779
	          val thm = [pt_inst, at_inst] MRS abs_fun_pi
berghofe@18068
   780
                  val thm_list = map (fn (ak_name', T') =>
berghofe@18068
   781
                     let
berghofe@18068
   782
                      val cp_inst = PureThy.get_thm thy32 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   783
	             in
berghofe@18068
   784
                     [pt_inst, pt_inst, at_inst, cp_inst] MRS abs_fun_pi_ineq
berghofe@18068
   785
	             end) ak_names_types;
berghofe@18068
   786
                 in thm::thm_list end) (ak_names_types))
berghofe@18068
   787
           in
berghofe@18068
   788
             (PureThy.add_thmss [((name, thm_list),[])] thy32)
berghofe@18068
   789
           end;
berghofe@18068
   790
berghofe@18068
   791
       val (thy34,_) = 
berghofe@18068
   792
	 let 
berghofe@18068
   793
             (* takes a theorem and a list of theorems        *)
berghofe@18068
   794
             (* produces a list of theorems of the form       *)
berghofe@18068
   795
             (* [t1 RS thm,..,tn RS thm] where t1..tn in thms *) 
berghofe@18068
   796
             fun instantiate thm thms = map (fn ti => ti RS thm) thms;
berghofe@18068
   797
               
berghofe@18068
   798
             (* takes two theorem lists (hopefully of the same length)           *)
berghofe@18068
   799
             (* produces a list of theorems of the form                          *)
berghofe@18068
   800
             (* [t1 RS m1,..,tn RS mn] where t1..tn in thms1 and m1..mn in thms2 *) 
berghofe@18068
   801
             fun instantiate_zip thms1 thms2 = 
berghofe@18068
   802
		 map (fn (t1,t2) => t1 RS t2) (thms1 ~~ thms2);
berghofe@18068
   803
berghofe@18068
   804
             (* list of all at_inst-theorems *)
berghofe@18068
   805
             val ats = map (fn ak => PureThy.get_thm thy33 (Name ("at_"^ak^"_inst"))) ak_names
berghofe@18068
   806
             (* list of all pt_inst-theorems *)
berghofe@18068
   807
             val pts = map (fn ak => PureThy.get_thm thy33 (Name ("pt_"^ak^"_inst"))) ak_names
berghofe@18068
   808
             (* list of all cp_inst-theorems *)
berghofe@18068
   809
             val cps = 
berghofe@18068
   810
	       let fun cps_fun (ak1,ak2) = PureThy.get_thm thy33 (Name ("cp_"^ak1^"_"^ak2^"_inst"))
berghofe@18068
   811
	       in map cps_fun (cprod (ak_names,ak_names)) end;	
berghofe@18068
   812
             (* list of all dj_inst-theorems *)
berghofe@18068
   813
             val djs = 
berghofe@18068
   814
	       let fun djs_fun (ak1,ak2) = 
berghofe@18068
   815
		    if ak1=ak2 
berghofe@18068
   816
		    then NONE
berghofe@18068
   817
		    else SOME(PureThy.get_thm thy33 (Name ("dj_"^ak1^"_"^ak2)))
berghofe@18068
   818
	       in List.mapPartial I (map djs_fun (cprod (ak_names,ak_names))) end;	
berghofe@18068
   819
berghofe@18068
   820
             fun inst_pt thms = Library.flat (map (fn ti => instantiate ti pts) thms); 
berghofe@18068
   821
             fun inst_at thms = Library.flat (map (fn ti => instantiate ti ats) thms);               
berghofe@18068
   822
	     fun inst_pt_at thms = instantiate_zip ats (inst_pt thms);			
berghofe@18068
   823
             fun inst_dj thms = Library.flat (map (fn ti => instantiate ti djs) thms);  
berghofe@18068
   824
berghofe@18068
   825
           in
berghofe@18068
   826
            thy33 
berghofe@18068
   827
	    |>   PureThy.add_thmss [(("alpha", inst_pt_at [abs_fun_eq]),[])]
berghofe@18068
   828
            |>>> PureThy.add_thmss [(("perm_swap", inst_pt_at [pt_swap_bij]),[])]
berghofe@18068
   829
            |>>> PureThy.add_thmss [(("perm_fresh_fresh", inst_pt_at [pt_fresh_fresh]),[])]
berghofe@18068
   830
            |>>> PureThy.add_thmss [(("perm_bij", inst_pt_at [pt_bij]),[])]
berghofe@18068
   831
            |>>> PureThy.add_thmss [(("perm_compose", inst_pt_at [pt_perm_compose]),[])]
berghofe@18068
   832
            |>>> PureThy.add_thmss [(("perm_app_eq", inst_pt_at [perm_eq_app]),[])]
berghofe@18068
   833
            |>>> PureThy.add_thmss [(("supp_atm", (inst_at [at_supp]) @ (inst_dj [dj_supp])),[])]
berghofe@18068
   834
            |>>> PureThy.add_thmss [(("fresh_atm", inst_at [at_fresh]),[])]
berghofe@18068
   835
            |>>> PureThy.add_thmss [(("calc_atm", inst_at at_calc),[])]
berghofe@18068
   836
            
berghofe@18068
   837
	   end;
berghofe@18068
   838
berghofe@18068
   839
         (* perm_dj collects all lemmas that forget an permutation *)
berghofe@18068
   840
         (* when it acts on an atom of different type              *)
berghofe@18068
   841
         val (thy35,_) = 
berghofe@18068
   842
	   let 
berghofe@18068
   843
	     val name = "perm_dj"
berghofe@18068
   844
             val thm_list = Library.flat (map (fn (ak_name, T) =>
berghofe@18068
   845
	        Library.flat (map (fn (ak_name', T') => 
berghofe@18068
   846
                 if not (ak_name = ak_name') 
berghofe@18068
   847
                 then 
berghofe@18068
   848
		    let
berghofe@18068
   849
                      val dj_inst = PureThy.get_thm thy34 (Name ("dj_"^ak_name^"_"^ak_name'));
berghofe@18068
   850
                    in
berghofe@18068
   851
                      [dj_inst RS dj_perm_forget, dj_inst RS dj_pp_forget]
berghofe@18068
   852
                    end 
berghofe@18068
   853
                 else []) ak_names_types)) ak_names_types)
berghofe@18068
   854
           in
berghofe@18068
   855
             (PureThy.add_thmss [((name, thm_list),[])] thy34)
berghofe@18068
   856
           end;
berghofe@18068
   857
berghofe@18068
   858
         (* abs_fresh collects all lemmas for simplifying a freshness *)
berghofe@18068
   859
         (* proposition involving an abs_fun                          *)
berghofe@18068
   860
berghofe@18068
   861
         val (thy36,_) = 
berghofe@18068
   862
	   let 
berghofe@18068
   863
	     val name = "abs_fresh"
berghofe@18068
   864
             val thm_list = Library.flat (map (fn (ak_name, T) =>
berghofe@18068
   865
	        let	
berghofe@18068
   866
		  val at_inst = PureThy.get_thm thy35 (Name ("at_"^ak_name^"_inst"));
berghofe@18068
   867
		  val pt_inst = PureThy.get_thm thy35 (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   868
                  val fs_inst = PureThy.get_thm thy35 (Name ("fs_"^ak_name^"_inst"));	      
berghofe@18068
   869
	          val thm = [pt_inst, at_inst, (fs_inst RS fs1)] MRS fresh_iff
berghofe@18068
   870
                  val thm_list = Library.flat (map (fn (ak_name', T') =>
berghofe@18068
   871
                     (if (not (ak_name = ak_name')) 
berghofe@18068
   872
                     then
berghofe@18068
   873
                       let
berghofe@18068
   874
                        val cp_inst = PureThy.get_thm thy35 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   875
	                val dj_inst = PureThy.get_thm thy35 (Name ("dj_"^ak_name'^"_"^ak_name));
berghofe@18068
   876
                       in
berghofe@18068
   877
                        [[pt_inst, pt_inst, at_inst, cp_inst, dj_inst] MRS fresh_iff_ineq]
berghofe@18068
   878
	               end
berghofe@18068
   879
                     else [])) ak_names_types);
berghofe@18068
   880
                 in thm::thm_list end) (ak_names_types))
berghofe@18068
   881
           in
berghofe@18068
   882
             (PureThy.add_thmss [((name, thm_list),[])] thy35)
berghofe@18068
   883
           end;
berghofe@18068
   884
berghofe@18068
   885
         (* abs_supp collects all lemmas for simplifying  *)
berghofe@18068
   886
         (* support proposition involving an abs_fun      *)
berghofe@18068
   887
berghofe@18068
   888
         val (thy37,_) = 
berghofe@18068
   889
	   let 
berghofe@18068
   890
	     val name = "abs_supp"
berghofe@18068
   891
             val thm_list = Library.flat (map (fn (ak_name, T) =>
berghofe@18068
   892
	        let	
berghofe@18068
   893
		  val at_inst = PureThy.get_thm thy36 (Name ("at_"^ak_name^"_inst"));
berghofe@18068
   894
		  val pt_inst = PureThy.get_thm thy36 (Name ("pt_"^ak_name^"_inst"));
berghofe@18068
   895
                  val fs_inst = PureThy.get_thm thy36 (Name ("fs_"^ak_name^"_inst"));	      
berghofe@18068
   896
	          val thm1 = [pt_inst, at_inst, (fs_inst RS fs1)] MRS abs_fun_supp
berghofe@18068
   897
                  val thm2 = [pt_inst, at_inst] MRS abs_fun_supp
berghofe@18068
   898
                  val thm_list = Library.flat (map (fn (ak_name', T') =>
berghofe@18068
   899
                     (if (not (ak_name = ak_name')) 
berghofe@18068
   900
                     then
berghofe@18068
   901
                       let
berghofe@18068
   902
                        val cp_inst = PureThy.get_thm thy36 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
berghofe@18068
   903
	                val dj_inst = PureThy.get_thm thy36 (Name ("dj_"^ak_name'^"_"^ak_name));
berghofe@18068
   904
                       in
berghofe@18068
   905
                        [[pt_inst, pt_inst, at_inst, cp_inst, dj_inst] MRS abs_fun_supp_ineq]
berghofe@18068
   906
	               end
berghofe@18068
   907
                     else [])) ak_names_types);
berghofe@18068
   908
                 in thm1::thm2::thm_list end) (ak_names_types))
berghofe@18068
   909
           in
berghofe@18068
   910
             (PureThy.add_thmss [((name, thm_list),[])] thy36)
berghofe@18068
   911
           end;
berghofe@18068
   912
berghofe@18068
   913
    in NominalData.put (fold Symtab.update (map (rpair ()) full_ak_names)
berghofe@18068
   914
      (NominalData.get thy11)) thy37
berghofe@18068
   915
    end;
berghofe@18068
   916
berghofe@18068
   917
berghofe@18068
   918
(* syntax und parsing *)
berghofe@18068
   919
structure P = OuterParse and K = OuterKeyword;
berghofe@18068
   920
berghofe@18068
   921
val atom_declP =
berghofe@18068
   922
  OuterSyntax.command "atom_decl" "Declare new kinds of atoms" K.thy_decl
berghofe@18068
   923
    (Scan.repeat1 P.name >> (Toplevel.theory o create_nom_typedecls));
berghofe@18068
   924
berghofe@18068
   925
val _ = OuterSyntax.add_parsers [atom_declP];
berghofe@18068
   926
berghofe@18068
   927
val setup = [NominalData.init];
berghofe@18068
   928
berghofe@18068
   929
end;