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