src/HOL/Nominal/nominal_package.ML
author urbanc
Sat, 29 Oct 2005 14:37:32 +0200
changeset 18045 6d69a4190eb2
parent 18017 f6abeac6dcb5
child 18054 2493cb9f5ede
permissions -rw-r--r--
1) have adjusted the swapping of the result type in add_datatype_i 2) have replaced map_nth_elem by Library.nth_map (there seems to be a clash with an existing nth_map somewhere - therefore the "Library")
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     1
(* $Id$ *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     2
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     3
signature NOMINAL_PACKAGE =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     4
sig
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     5
  val create_nom_typedecls : string list -> theory -> theory
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     6
  val add_nominal_datatype : bool -> string list -> (string list * bstring * mixfix *
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     7
    (bstring * string list * mixfix) list) list -> theory -> theory *
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     8
      {distinct : thm list list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
     9
       inject : thm list list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    10
       exhaustion : thm list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    11
       rec_thms : thm list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    12
       case_thms : thm list list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    13
       split_thms : (thm * thm) list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    14
       induction : thm,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    15
       size : thm list,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    16
       simps : thm list}
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    17
  val setup : (theory -> theory) list
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    18
end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    19
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    20
structure NominalPackage (*: NOMINAL_PACKAGE *) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    21
struct
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    22
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    23
open DatatypeAux;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    24
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    25
(* data kind 'HOL/nominal' *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    26
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    27
structure NominalArgs =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    28
struct
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    29
  val name = "HOL/nominal";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    30
  type T = unit Symtab.table;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    31
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    32
  val empty = Symtab.empty;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    33
  val copy = I;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    34
  val extend = I;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    35
  fun merge _ x = Symtab.merge (K true) x;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    36
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    37
  fun print sg tab = ();
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    38
end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    39
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    40
structure NominalData = TheoryDataFun(NominalArgs);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    41
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    42
fun atoms_of thy = map fst (Symtab.dest (NominalData.get thy));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    43
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    44
(* FIXME: add to hologic.ML ? *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    45
fun mk_listT T = Type ("List.list", [T]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    46
fun mk_permT T = mk_listT (HOLogic.mk_prodT (T, T));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    47
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    48
fun mk_Cons x xs =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    49
  let val T = fastype_of x
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    50
  in Const ("List.list.Cons", T --> mk_listT T --> mk_listT T) $ x $ xs end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    51
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    52
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    53
(* this function sets up all matters related to atom-  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    54
(* kinds; the user specifies a list of atom-kind names *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    55
(* atom_decl <ak1> ... <akn>                           *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    56
fun create_nom_typedecls ak_names thy =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    57
  let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    58
    (* declares a type-decl for every atom-kind: *) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    59
    (* that is typedecl <ak>                     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    60
    val thy1 = TypedefPackage.add_typedecls (map (fn x => (x,[],NoSyn)) ak_names) thy;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    61
    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    62
    (* produces a list consisting of pairs:         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    63
    (*  fst component is the atom-kind name         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    64
    (*  snd component is its type                   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    65
    val full_ak_names = map (Sign.intern_type (sign_of thy1)) ak_names;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    66
    val ak_names_types = ak_names ~~ map (Type o rpair []) full_ak_names;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    67
     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    68
    (* adds for every atom-kind an axiom             *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    69
    (* <ak>_infinite: infinite (UNIV::<ak_type> set) *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    70
    val (thy2,inf_axs) = PureThy.add_axioms_i (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    71
      let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    72
	val name = ak_name ^ "_infinite"
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    73
        val axiom = HOLogic.mk_Trueprop (HOLogic.mk_not
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    74
                    (HOLogic.mk_mem (HOLogic.mk_UNIV T,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    75
                     Const ("Finite_Set.Finites", HOLogic.mk_setT (HOLogic.mk_setT T)))))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    76
      in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    77
	((name, axiom), []) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    78
      end) ak_names_types) thy1;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    79
    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    80
    (* declares a swapping function for every atom-kind, it is         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    81
    (* const swap_<ak> :: <akT> * <akT> => <akT> => <akT>              *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    82
    (* swap_<ak> (a,b) c = (if a=c then b (else if b=c then a else c)) *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    83
    (* overloades then the general swap-function                       *) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    84
    val (thy3, swap_eqs) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    85
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    86
        val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    87
        val swap_name = Sign.full_name (sign_of thy) ("swap_" ^ ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    88
        val a = Free ("a", T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    89
        val b = Free ("b", T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    90
        val c = Free ("c", T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    91
        val ab = Free ("ab", HOLogic.mk_prodT (T, T))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    92
        val cif = Const ("HOL.If", HOLogic.boolT --> T --> T --> T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    93
        val cswap_akname = Const (swap_name, swapT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    94
        val cswap = Const ("nominal.swap", swapT)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    95
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    96
        val name = "swap_"^ak_name^"_def";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    97
        val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    98
		   (cswap_akname $ HOLogic.mk_prod (a,b) $ c,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
    99
                    cif $ HOLogic.mk_eq (a,c) $ b $ (cif $ HOLogic.mk_eq (b,c) $ a $ c)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   100
        val def2 = Logic.mk_equals (cswap $ ab $ c, cswap_akname $ ab $ c)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   101
      in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   102
        thy |> Theory.add_consts_i [("swap_" ^ ak_name, swapT, NoSyn)] 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   103
            |> (#1 o PureThy.add_defs_i true [((name, def2),[])])
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   104
            |> PrimrecPackage.add_primrec_i "" [(("", def1),[])]            
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   105
      end) (thy2, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   106
    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   107
    (* declares a permutation function for every atom-kind acting  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   108
    (* on such atoms                                               *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   109
    (* const <ak>_prm_<ak> :: (<akT> * <akT>)list => akT => akT    *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   110
    (* <ak>_prm_<ak> []     a = a                                  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   111
    (* <ak>_prm_<ak> (x#xs) a = swap_<ak> x (perm xs a)            *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   112
    val (thy4, prm_eqs) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   113
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   114
        val swapT = HOLogic.mk_prodT (T, T) --> T --> T;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   115
        val swap_name = Sign.full_name (sign_of thy) ("swap_" ^ ak_name)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   116
        val prmT = mk_permT T --> T --> T;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   117
        val prm_name = ak_name ^ "_prm_" ^ ak_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   118
        val qu_prm_name = Sign.full_name (sign_of thy) prm_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   119
        val x  = Free ("x", HOLogic.mk_prodT (T, T));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   120
        val xs = Free ("xs", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   121
        val a  = Free ("a", T) ;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   122
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   123
        val cnil  = Const ("List.list.Nil", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   124
        
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   125
        val def1 = HOLogic.mk_Trueprop (HOLogic.mk_eq (Const (qu_prm_name, prmT) $ cnil $ a, a));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   126
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   127
        val def2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   128
                   (Const (qu_prm_name, prmT) $ mk_Cons x xs $ a,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   129
                    Const (swap_name, swapT) $ x $ (Const (qu_prm_name, prmT) $ xs $ a)));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   130
      in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   131
        thy |> Theory.add_consts_i [(prm_name, mk_permT T --> T --> T, NoSyn)] 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   132
            |> PrimrecPackage.add_primrec_i "" [(("", def1), []),(("", def2), [])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   133
      end) (thy3, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   134
    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   135
    (* defines permutation functions for all combinations of atom-kinds; *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   136
    (* there are a trivial cases and non-trivial cases                   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   137
    (* non-trivial case:                                                 *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   138
    (* <ak>_prm_<ak>_def:  perm pi a == <ak>_prm_<ak> pi a               *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   139
    (* trivial case with <ak> != <ak'>                                   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   140
    (* <ak>_prm<ak'>_def[simp]:  perm pi a == a                          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   141
    (*                                                                   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   142
    (* the trivial cases are added to the simplifier, while the non-     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   143
    (* have their own rules proved below                                 *)  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   144
    val (thy5, perm_defs) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   145
      foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   146
        let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   147
          val perm_def_name = ak_name ^ "_prm_" ^ ak_name';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   148
          val pi = Free ("pi", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   149
          val a  = Free ("a", T');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   150
          val cperm = Const ("nominal.perm", mk_permT T --> T' --> T');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   151
          val cperm_def = Const (Sign.full_name (sign_of thy') perm_def_name, mk_permT T --> T' --> T');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   152
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   153
          val name = ak_name ^ "_prm_" ^ ak_name' ^ "_def";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   154
          val def = Logic.mk_equals
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   155
                    (cperm $ pi $ a, if ak_name = ak_name' then cperm_def $ pi $ a else a)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   156
        in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   157
          thy' |> PureThy.add_defs_i true [((name, def),[])] 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   158
        end) (thy, ak_names_types)) (thy4, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   159
    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   160
    (* proves that every atom-kind is an instance of at *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   161
    (* lemma at_<ak>_inst:                              *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   162
    (* at TYPE(<ak>)                                    *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   163
    val (thy6, prm_cons_thms) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   164
      thy5 |> PureThy.add_thms (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   165
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   166
        val ak_name_qu = Sign.full_name (sign_of thy5) (ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   167
        val i_type = Type(ak_name_qu,[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   168
	val cat = Const ("nominal.at",(Term.itselfT i_type)  --> HOLogic.boolT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   169
        val at_type = Logic.mk_type i_type;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   170
        val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy5
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   171
                                  [Name "at_def",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   172
                                   Name (ak_name ^ "_prm_" ^ ak_name ^ "_def"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   173
                                   Name (ak_name ^ "_prm_" ^ ak_name ^ ".simps"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   174
                                   Name ("swap_" ^ ak_name ^ "_def"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   175
                                   Name ("swap_" ^ ak_name ^ ".simps"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   176
                                   Name (ak_name ^ "_infinite")]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   177
	    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   178
	val name = "at_"^ak_name^ "_inst";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   179
        val statement = HOLogic.mk_Trueprop (cat $ at_type);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   180
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   181
        val proof = fn _ => auto_tac (claset(),simp_s);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   182
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   183
      in 
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   184
        ((name, standard (Goal.prove thy5 [] [] statement proof)), []) 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   185
      end) ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   186
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   187
    (* declares a perm-axclass for every atom-kind               *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   188
    (* axclass pt_<ak>                                           *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   189
    (* pt_<ak>1[simp]: perm [] x = x                             *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   190
    (* pt_<ak>2:       perm (pi1@pi2) x = perm pi1 (perm pi2 x)  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   191
    (* pt_<ak>3:       pi1 ~ pi2 ==> perm pi1 x = perm pi2 x     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   192
     val (thy7, pt_ax_classes) =  foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   193
      let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   194
	  val cl_name = "pt_"^ak_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   195
          val ty = TFree("'a",["HOL.type"]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   196
          val x   = Free ("x", ty);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   197
          val pi1 = Free ("pi1", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   198
          val pi2 = Free ("pi2", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   199
          val cperm = Const ("nominal.perm", mk_permT T --> ty --> ty);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   200
          val cnil  = Const ("List.list.Nil", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   201
          val cappend = Const ("List.op @",mk_permT T --> mk_permT T --> mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   202
          val cprm_eq = Const ("nominal.prm_eq",mk_permT T --> mk_permT T --> HOLogic.boolT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   203
          (* nil axiom *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   204
          val axiom1 = HOLogic.mk_Trueprop (HOLogic.mk_eq 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   205
                       (cperm $ cnil $ x, x));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   206
          (* append axiom *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   207
          val axiom2 = HOLogic.mk_Trueprop (HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   208
                       (cperm $ (cappend $ pi1 $ pi2) $ x, cperm $ pi1 $ (cperm $ pi2 $ x)));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   209
          (* perm-eq axiom *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   210
          val axiom3 = Logic.mk_implies
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   211
                       (HOLogic.mk_Trueprop (cprm_eq $ pi1 $ pi2),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   212
                        HOLogic.mk_Trueprop (HOLogic.mk_eq (cperm $ pi1 $ x, cperm $ pi2 $ x)));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   213
      in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   214
        thy |> AxClass.add_axclass_i (cl_name, ["HOL.type"])
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   215
                [((cl_name^"1", axiom1),[Simplifier.simp_add_global]), 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   216
                 ((cl_name^"2", axiom2),[]),                           
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   217
                 ((cl_name^"3", axiom3),[])]                          
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   218
      end) (thy6,ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   219
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   220
    (* proves that every pt_<ak>-type together with <ak>-type *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   221
    (* instance of pt                                         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   222
    (* lemma pt_<ak>_inst:                                    *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   223
    (* pt TYPE('x::pt_<ak>) TYPE(<ak>)                        *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   224
    val (thy8, prm_inst_thms) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   225
      thy7 |> PureThy.add_thms (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   226
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   227
        val ak_name_qu = Sign.full_name (sign_of thy7) (ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   228
        val pt_name_qu = Sign.full_name (sign_of thy7) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   229
        val i_type1 = TFree("'x",[pt_name_qu]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   230
        val i_type2 = Type(ak_name_qu,[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   231
	val cpt = Const ("nominal.pt",(Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   232
        val pt_type = Logic.mk_type i_type1;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   233
        val at_type = Logic.mk_type i_type2;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   234
        val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy7
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   235
                                  [Name "pt_def",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   236
                                   Name ("pt_" ^ ak_name ^ "1"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   237
                                   Name ("pt_" ^ ak_name ^ "2"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   238
                                   Name ("pt_" ^ ak_name ^ "3")];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   239
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   240
	val name = "pt_"^ak_name^ "_inst";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   241
        val statement = HOLogic.mk_Trueprop (cpt $ pt_type $ at_type);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   242
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   243
        val proof = fn _ => auto_tac (claset(),simp_s);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   244
      in 
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   245
        ((name, standard (Goal.prove thy7 [] [] statement proof)), []) 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   246
      end) ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   247
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   248
     (* declares an fs-axclass for every atom-kind       *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   249
     (* axclass fs_<ak>                                  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   250
     (* fs_<ak>1: finite ((supp x)::<ak> set)            *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   251
     val (thy11, fs_ax_classes) =  foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   252
       let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   253
	  val cl_name = "fs_"^ak_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   254
	  val pt_name = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   255
          val ty = TFree("'a",["HOL.type"]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   256
          val x   = Free ("x", ty);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   257
          val csupp    = Const ("nominal.supp", ty --> HOLogic.mk_setT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   258
          val cfinites = Const ("Finite_Set.Finites", HOLogic.mk_setT (HOLogic.mk_setT T))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   259
          
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   260
          val axiom1   = HOLogic.mk_Trueprop (HOLogic.mk_mem (csupp $ x, cfinites));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   261
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   262
       in  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   263
        thy |> AxClass.add_axclass_i (cl_name, [pt_name]) [((cl_name^"1", axiom1),[])]            
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   264
       end) (thy8,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   265
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   266
     (* proves that every fs_<ak>-type together with <ak>-type   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   267
     (* instance of fs-type                                      *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   268
     (* lemma abst_<ak>_inst:                                    *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   269
     (* fs TYPE('x::pt_<ak>) TYPE (<ak>)                         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   270
     val (thy12, fs_inst_thms) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   271
       thy11 |> PureThy.add_thms (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   272
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   273
         val ak_name_qu = Sign.full_name (sign_of thy11) (ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   274
         val fs_name_qu = Sign.full_name (sign_of thy11) ("fs_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   275
         val i_type1 = TFree("'x",[fs_name_qu]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   276
         val i_type2 = Type(ak_name_qu,[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   277
 	 val cfs = Const ("nominal.fs", 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   278
                                 (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   279
         val fs_type = Logic.mk_type i_type1;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   280
         val at_type = Logic.mk_type i_type2;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   281
	 val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy11
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   282
                                   [Name "fs_def",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   283
                                    Name ("fs_" ^ ak_name ^ "1")];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   284
    
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   285
	 val name = "fs_"^ak_name^ "_inst";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   286
         val statement = HOLogic.mk_Trueprop (cfs $ fs_type $ at_type);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   287
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   288
         val proof = fn _ => auto_tac (claset(),simp_s);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   289
       in 
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   290
         ((name, standard (Goal.prove thy11 [] [] statement proof)), []) 
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   291
       end) ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   292
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   293
       (* declares for every atom-kind combination an axclass            *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   294
       (* cp_<ak1>_<ak2> giving a composition property                   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   295
       (* cp_<ak1>_<ak2>1: pi1 o pi2 o x = (pi1 o pi2) o (pi1 o x)       *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   296
        val (thy12b,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   297
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   298
	     let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   299
	       val cl_name = "cp_"^ak_name^"_"^ak_name';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   300
	       val ty = TFree("'a",["HOL.type"]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   301
               val x   = Free ("x", ty);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   302
               val pi1 = Free ("pi1", mk_permT T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   303
	       val pi2 = Free ("pi2", mk_permT T');                  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   304
	       val cperm1 = Const ("nominal.perm", mk_permT T  --> ty --> ty);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   305
               val cperm2 = Const ("nominal.perm", mk_permT T' --> ty --> ty);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   306
               val cperm3 = Const ("nominal.perm", mk_permT T  --> mk_permT T' --> mk_permT T');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   307
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   308
               val ax1   = HOLogic.mk_Trueprop 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   309
			   (HOLogic.mk_eq (cperm1 $ pi1 $ (cperm2 $ pi2 $ x), 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   310
                                           cperm2 $ (cperm3 $ pi1 $ pi2) $ (cperm1 $ pi1 $ x)));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   311
	       in  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   312
	       (fst (AxClass.add_axclass_i (cl_name, ["HOL.type"]) [((cl_name^"1", ax1),[])] thy'),())  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   313
	       end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   314
	   (thy, ak_names_types)) (thy12, ak_names_types)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   315
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   316
        (* proves for every <ak>-combination a cp_<ak1>_<ak2>_inst theorem;     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   317
        (* lemma cp_<ak1>_<ak2>_inst:                                           *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   318
        (* cp TYPE('a::cp_<ak1>_<ak2>) TYPE(<ak1>) TYPE(<ak2>)                  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   319
        val (thy12c, cp_thms) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   320
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   321
           let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   322
             val ak_name_qu  = Sign.full_name (sign_of thy') (ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   323
	     val ak_name_qu' = Sign.full_name (sign_of thy') (ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   324
             val cp_name_qu  = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   325
             val i_type0 = TFree("'a",[cp_name_qu]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   326
             val i_type1 = Type(ak_name_qu,[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   327
             val i_type2 = Type(ak_name_qu',[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   328
	     val ccp = Const ("nominal.cp",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   329
                             (Term.itselfT i_type0)-->(Term.itselfT i_type1)-->
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   330
                                                      (Term.itselfT i_type2)-->HOLogic.boolT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   331
             val at_type  = Logic.mk_type i_type1;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   332
             val at_type' = Logic.mk_type i_type2;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   333
	     val cp_type  = Logic.mk_type i_type0;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   334
             val simp_s   = HOL_basic_ss addsimps PureThy.get_thmss thy' [(Name "cp_def")];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   335
	     val cp1      = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"1"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   336
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   337
	     val name = "cp_"^ak_name^ "_"^ak_name'^"_inst";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   338
             val statement = HOLogic.mk_Trueprop (ccp $ cp_type $ at_type $ at_type');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   339
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   340
             val proof = fn _ => EVERY [auto_tac (claset(),simp_s), rtac cp1 1];
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   341
	   in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   342
	     thy' |> PureThy.add_thms 
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   343
                    [((name, standard (Goal.prove thy' [] [] statement proof)), [])]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   344
	   end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   345
	   (thy, ak_names_types)) (thy12b, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   346
       
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   347
        (* proves for every non-trivial <ak>-combination a disjointness   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   348
        (* theorem; i.e. <ak1> != <ak2>                                   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   349
        (* lemma ds_<ak1>_<ak2>:                                          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   350
        (* dj TYPE(<ak1>) TYPE(<ak2>)                                     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   351
        val (thy12d, dj_thms) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   352
	  foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   353
          (if not (ak_name = ak_name') 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   354
           then 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   355
	       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   356
		 val ak_name_qu  = Sign.full_name (sign_of thy') (ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   357
	         val ak_name_qu' = Sign.full_name (sign_of thy') (ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   358
                 val i_type1 = Type(ak_name_qu,[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   359
                 val i_type2 = Type(ak_name_qu',[]);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   360
	         val cdj = Const ("nominal.disjoint",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   361
                           (Term.itselfT i_type1)-->(Term.itselfT i_type2)-->HOLogic.boolT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   362
                 val at_type  = Logic.mk_type i_type1;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   363
                 val at_type' = Logic.mk_type i_type2;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   364
                 val simp_s = HOL_basic_ss addsimps PureThy.get_thmss thy' 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   365
					   [Name "disjoint_def",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   366
                                            Name (ak_name^"_prm_"^ak_name'^"_def"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   367
                                            Name (ak_name'^"_prm_"^ak_name^"_def")];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   368
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   369
	         val name = "dj_"^ak_name^"_"^ak_name';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   370
                 val statement = HOLogic.mk_Trueprop (cdj $ at_type $ at_type');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   371
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   372
                 val proof = fn _ => auto_tac (claset(),simp_s);
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   373
	       in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   374
		   thy' |> PureThy.add_thms 
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
   375
                        [((name, standard (Goal.prove thy' [] [] statement proof)), []) ]
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   376
	       end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   377
           else 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   378
            (thy',[])))  (* do nothing branch, if ak_name = ak_name' *) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   379
	   (thy, ak_names_types)) (thy12c, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   380
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   381
     (*<<<<<<<  pt_<ak> class instances  >>>>>>>*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   382
     (*=========================================*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   383
     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   384
     (* some frequently used theorems *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   385
      val pt1 = PureThy.get_thm thy12c (Name "pt1");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   386
      val pt2 = PureThy.get_thm thy12c (Name "pt2");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   387
      val pt3 = PureThy.get_thm thy12c (Name "pt3");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   388
      val at_pt_inst    = PureThy.get_thm thy12c (Name "at_pt_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   389
      val pt_bool_inst  = PureThy.get_thm thy12c (Name "pt_bool_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   390
      val pt_set_inst   = PureThy.get_thm thy12c (Name "pt_set_inst"); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   391
      val pt_unit_inst  = PureThy.get_thm thy12c (Name "pt_unit_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   392
      val pt_prod_inst  = PureThy.get_thm thy12c (Name "pt_prod_inst"); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   393
      val pt_list_inst  = PureThy.get_thm thy12c (Name "pt_list_inst");   
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   394
      val pt_optn_inst  = PureThy.get_thm thy12c (Name "pt_option_inst");   
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   395
      val pt_noptn_inst = PureThy.get_thm thy12c (Name "pt_noption_inst");   
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   396
      val pt_fun_inst   = PureThy.get_thm thy12c (Name "pt_fun_inst");     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   397
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   398
     (* for all atom-kind combination shows that         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   399
     (* every <ak> is an instance of pt_<ai>             *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   400
     val (thy13,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   401
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   402
          (if ak_name = ak_name'
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   403
	   then
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   404
	     let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   405
	      val qu_name =  Sign.full_name (sign_of thy') ak_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   406
              val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   407
              val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name ^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   408
              val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   409
                                 rtac ((at_inst RS at_pt_inst) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   410
                                 rtac ((at_inst RS at_pt_inst) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   411
                                 rtac ((at_inst RS at_pt_inst) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   412
                                 atac 1];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   413
             in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   414
	      (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy',()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   415
             end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   416
           else 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   417
             let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   418
	      val qu_name' = Sign.full_name (sign_of thy') ak_name';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   419
              val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   420
              val simp_s = HOL_basic_ss addsimps 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   421
                           PureThy.get_thmss thy' [Name (ak_name^"_prm_"^ak_name'^"_def")];  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   422
              val proof = EVERY [AxClass.intro_classes_tac [], auto_tac (claset(),simp_s)];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   423
             in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   424
	      (AxClass.add_inst_arity_i (qu_name',[],[qu_class]) proof thy',()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   425
             end)) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   426
	     (thy, ak_names_types)) (thy12c, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   427
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   428
     (* shows that bool is an instance of pt_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   429
     (* uses the theorem pt_bool_inst                 *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   430
     val (thy14,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   431
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   432
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   433
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   434
                             rtac (pt_bool_inst RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   435
                             rtac (pt_bool_inst RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   436
                             rtac (pt_bool_inst RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   437
                             atac 1];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   438
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   439
	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   440
       end) (thy13,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   441
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   442
     (* shows that set(pt_<ak>) is an instance of pt_<ak>          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   443
     (* unfolds the permutation definition and applies pt_<ak>i    *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   444
     val (thy15,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   445
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   446
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   447
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   448
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   449
                             rtac ((pt_inst RS pt_set_inst) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   450
                             rtac ((pt_inst RS pt_set_inst) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   451
                             rtac ((pt_inst RS pt_set_inst) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   452
                             atac 1];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   453
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   454
	 (AxClass.add_inst_arity_i ("set",[[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   455
       end) (thy14,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   456
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   457
     (* shows that unit is an instance of pt_<ak>          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   458
     val (thy16,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   459
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   460
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   461
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   462
                             rtac (pt_unit_inst RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   463
                             rtac (pt_unit_inst RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   464
                             rtac (pt_unit_inst RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   465
                             atac 1];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   466
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   467
	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   468
       end) (thy15,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   469
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   470
     (* shows that *(pt_<ak>,pt_<ak>) is an instance of pt_<ak> *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   471
     (* uses the theorem pt_prod_inst and pt_<ak>_inst          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   472
     val (thy17,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   473
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   474
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   475
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   476
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   477
                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   478
                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   479
                             rtac ((pt_inst RS (pt_inst RS pt_prod_inst)) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   480
                             atac 1];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   481
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   482
          (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   483
       end) (thy16,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   484
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   485
     (* shows that list(pt_<ak>) is an instance of pt_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   486
     (* uses the theorem pt_list_inst and pt_<ak>_inst         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   487
     val (thy18,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   488
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   489
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   490
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   491
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   492
                             rtac ((pt_inst RS pt_list_inst) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   493
                             rtac ((pt_inst RS pt_list_inst) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   494
                             rtac ((pt_inst RS pt_list_inst) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   495
                             atac 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   496
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   497
	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   498
       end) (thy17,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   499
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   500
     (* shows that option(pt_<ak>) is an instance of pt_<ak>   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   501
     (* uses the theorem pt_option_inst and pt_<ak>_inst       *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   502
     val (thy18a,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   503
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   504
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   505
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   506
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   507
                             rtac ((pt_inst RS pt_optn_inst) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   508
                             rtac ((pt_inst RS pt_optn_inst) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   509
                             rtac ((pt_inst RS pt_optn_inst) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   510
                             atac 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   511
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   512
	 (AxClass.add_inst_arity_i ("Datatype.option",[[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   513
       end) (thy18,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   514
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   515
     (* shows that nOption(pt_<ak>) is an instance of pt_<ak>   *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   516
     (* uses the theorem pt_option_inst and pt_<ak>_inst       *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   517
     val (thy18b,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   518
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   519
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   520
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   521
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   522
                             rtac ((pt_inst RS pt_noptn_inst) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   523
                             rtac ((pt_inst RS pt_noptn_inst) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   524
                             rtac ((pt_inst RS pt_noptn_inst) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   525
                             atac 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   526
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   527
	 (AxClass.add_inst_arity_i ("nominal.nOption",[[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   528
       end) (thy18a,ak_names_types); 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   529
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   530
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   531
     (* shows that fun(pt_<ak>,pt_<ak>) is an instance of pt_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   532
     (* uses the theorem pt_list_inst and pt_<ak>_inst                *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   533
     val (thy19,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   534
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   535
          val qu_class = Sign.full_name (sign_of thy) ("pt_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   536
          val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   537
          val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   538
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   539
                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt1) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   540
                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt2) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   541
                             rtac ((at_thm RS (pt_inst RS (pt_inst RS pt_fun_inst))) RS pt3) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   542
                             atac 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   543
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   544
	 (AxClass.add_inst_arity_i ("fun",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   545
       end) (thy18b,ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   546
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   547
       (*<<<<<<<  fs_<ak> class instances  >>>>>>>*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   548
       (*=========================================*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   549
       val fs1          = PureThy.get_thm thy19 (Name "fs1");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   550
       val fs_at_inst   = PureThy.get_thm thy19 (Name "fs_at_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   551
       val fs_unit_inst = PureThy.get_thm thy19 (Name "fs_unit_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   552
       val fs_bool_inst = PureThy.get_thm thy19 (Name "fs_bool_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   553
       val fs_prod_inst = PureThy.get_thm thy19 (Name "fs_prod_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   554
       val fs_list_inst = PureThy.get_thm thy19 (Name "fs_list_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   555
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   556
       (* shows that <ak> is an instance of fs_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   557
       (* uses the theorem at_<ak>_inst                 *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   558
       val (thy20,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   559
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   560
          val qu_name =  Sign.full_name (sign_of thy) ak_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   561
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   562
          val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   563
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   564
                             rtac ((at_thm RS fs_at_inst) RS fs1) 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   565
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   566
	 (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   567
       end) (thy19,ak_names_types);  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   568
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   569
       (* shows that unit is an instance of fs_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   570
       (* uses the theorem fs_unit_inst                 *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   571
       val (thy21,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   572
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   573
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   574
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   575
                             rtac (fs_unit_inst RS fs1) 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   576
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   577
	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   578
       end) (thy20,ak_names_types);  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   579
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   580
       (* shows that bool is an instance of fs_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   581
       (* uses the theorem fs_bool_inst                 *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   582
       val (thy22,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   583
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   584
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   585
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   586
                             rtac (fs_bool_inst RS fs1) 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   587
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   588
	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   589
       end) (thy21,ak_names_types);  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   590
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   591
       (* shows that *(fs_<ak>,fs_<ak>) is an instance of fs_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   592
       (* uses the theorem fs_prod_inst                               *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   593
       val (thy23,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   594
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   595
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   596
          val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   597
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   598
                             rtac ((fs_inst RS (fs_inst RS fs_prod_inst)) RS fs1) 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   599
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   600
	 (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   601
       end) (thy22,ak_names_types);  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   602
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   603
       (* shows that list(fs_<ak>) is an instance of fs_<ak>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   604
       (* uses the theorem fs_list_inst                          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   605
       val (thy24,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   606
       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   607
          val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   608
          val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   609
          val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   610
                              rtac ((fs_inst RS fs_list_inst) RS fs1) 1];      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   611
       in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   612
	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   613
       end) (thy23,ak_names_types);  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   614
	   
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   615
       (*<<<<<<<  cp_<ak>_<ai> class instances  >>>>>>>*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   616
       (*==============================================*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   617
       val cp1             = PureThy.get_thm thy24 (Name "cp1");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   618
       val cp_unit_inst    = PureThy.get_thm thy24 (Name "cp_unit_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   619
       val cp_bool_inst    = PureThy.get_thm thy24 (Name "cp_bool_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   620
       val cp_prod_inst    = PureThy.get_thm thy24 (Name "cp_prod_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   621
       val cp_list_inst    = PureThy.get_thm thy24 (Name "cp_list_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   622
       val cp_fun_inst     = PureThy.get_thm thy24 (Name "cp_fun_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   623
       val cp_option_inst  = PureThy.get_thm thy24 (Name "cp_option_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   624
       val cp_noption_inst = PureThy.get_thm thy24 (Name "cp_noption_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   625
       val pt_perm_compose = PureThy.get_thm thy24 (Name "pt_perm_compose");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   626
       val dj_pp_forget    = PureThy.get_thm thy24 (Name "dj_perm_perm_forget");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   627
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   628
       (* shows that <aj> is an instance of cp_<ak>_<ai>  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   629
       (* that needs a three-nested loop *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   630
       val (thy25,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   631
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   632
          foldl_map (fn (thy'', (ak_name'', T'')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   633
            let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   634
              val qu_name =  Sign.full_name (sign_of thy'') ak_name;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   635
              val qu_class = Sign.full_name (sign_of thy'') ("cp_"^ak_name'^"_"^ak_name'');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   636
              val proof =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   637
                (if (ak_name'=ak_name'') then 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   638
		  (let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   639
                    val pt_inst  = PureThy.get_thm thy'' (Name ("pt_"^ak_name''^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   640
		    val at_inst  = PureThy.get_thm thy'' (Name ("at_"^ak_name''^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   641
                  in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   642
		   EVERY [AxClass.intro_classes_tac [], 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   643
                          rtac (at_inst RS (pt_inst RS pt_perm_compose)) 1]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   644
                  end)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   645
		else
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   646
		  (let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   647
                     val dj_inst  = PureThy.get_thm thy'' (Name ("dj_"^ak_name''^"_"^ak_name'));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   648
		     val simp_s = HOL_basic_ss addsimps 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   649
                                        ((dj_inst RS dj_pp_forget)::
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   650
                                         (PureThy.get_thmss thy'' 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   651
					   [Name (ak_name' ^"_prm_"^ak_name^"_def"),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   652
                                            Name (ak_name''^"_prm_"^ak_name^"_def")]));  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   653
		  in 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   654
                    EVERY [AxClass.intro_classes_tac [], simp_tac simp_s 1]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   655
                  end))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   656
	      in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   657
                (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy'',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   658
	      end)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   659
	   (thy', ak_names_types)) (thy, ak_names_types)) (thy24, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   660
      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   661
       (* shows that unit is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   662
       (* for every <ak>-combination                         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   663
       val (thy26,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   664
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   665
          let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   666
            val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   667
            val proof = EVERY [AxClass.intro_classes_tac [],rtac (cp_unit_inst RS cp1) 1];     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   668
	  in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   669
            (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   670
	  end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   671
	   (thy, ak_names_types)) (thy25, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   672
       
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   673
       (* shows that bool is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   674
       (* for every <ak>-combination                         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   675
       val (thy27,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   676
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   677
           let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   678
	     val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   679
             val proof = EVERY [AxClass.intro_classes_tac [], rtac (cp_bool_inst RS cp1) 1];     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   680
	   in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   681
             (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   682
	   end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   683
	   (thy, ak_names_types)) (thy26, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   684
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   685
       (* shows that prod is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   686
       (* for every <ak>-combination                         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   687
       val (thy28,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   688
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   689
          let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   690
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   691
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   692
            val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   693
                               rtac ((cp_inst RS (cp_inst RS cp_prod_inst)) RS cp1) 1];     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   694
	  in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   695
            (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   696
	  end)  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   697
	  (thy, ak_names_types)) (thy27, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   698
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   699
       (* shows that list is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   700
       (* for every <ak>-combination                         *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   701
       val (thy29,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   702
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   703
           let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   704
	     val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   705
             val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   706
             val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   707
                                rtac ((cp_inst RS cp_list_inst) RS cp1) 1];     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   708
	   in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   709
            (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   710
	   end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   711
	   (thy, ak_names_types)) (thy28, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   712
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   713
       (* shows that function is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   714
       (* for every <ak>-combination                             *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   715
       val (thy30,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   716
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   717
          let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   718
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   719
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   720
            val pt_inst  = PureThy.get_thm thy' (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   721
            val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   722
            val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   723
                    rtac ((at_inst RS (pt_inst RS (cp_inst RS (cp_inst RS cp_fun_inst)))) RS cp1) 1];  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   724
	  in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   725
            (AxClass.add_inst_arity_i ("fun",[[qu_class],[qu_class]],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   726
	  end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   727
	  (thy, ak_names_types)) (thy29, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   728
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   729
       (* shows that option is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   730
       (* for every <ak>-combination                           *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   731
       val (thy31,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   732
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   733
          let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   734
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   735
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   736
            val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   737
                               rtac ((cp_inst RS cp_option_inst) RS cp1) 1];     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   738
	  in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   739
            (AxClass.add_inst_arity_i ("Datatype.option",[[qu_class]],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   740
	  end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   741
	  (thy, ak_names_types)) (thy30, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   742
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   743
       (* shows that nOption is an instance of cp_<ak>_<ai>     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   744
       (* for every <ak>-combination                            *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   745
       val (thy32,_) = foldl_map (fn (thy, (ak_name, T)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   746
	 foldl_map (fn (thy', (ak_name', T')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   747
          let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   748
	    val qu_class = Sign.full_name (sign_of thy') ("cp_"^ak_name^"_"^ak_name');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   749
            val cp_inst  = PureThy.get_thm thy' (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   750
            val proof = EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   751
                               rtac ((cp_inst RS cp_noption_inst) RS cp1) 1];     
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   752
	  in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   753
           (AxClass.add_inst_arity_i ("nominal.nOption",[[qu_class]],[qu_class]) proof thy',())
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   754
	  end) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   755
	  (thy, ak_names_types)) (thy31, ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   756
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   757
       (* abbreviations for some collection of rules *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   758
       (*============================================*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   759
       val abs_fun_pi        = PureThy.get_thm thy32 (Name ("nominal.abs_fun_pi"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   760
       val abs_fun_pi_ineq   = PureThy.get_thm thy32 (Name ("nominal.abs_fun_pi_ineq"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   761
       val abs_fun_eq        = PureThy.get_thm thy32 (Name ("nominal.abs_fun_eq"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   762
       val dj_perm_forget    = PureThy.get_thm thy32 (Name ("nominal.dj_perm_forget"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   763
       val dj_pp_forget      = PureThy.get_thm thy32 (Name ("nominal.dj_perm_perm_forget"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   764
       val fresh_iff         = PureThy.get_thm thy32 (Name ("nominal.fresh_abs_fun_iff"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   765
       val fresh_iff_ineq    = PureThy.get_thm thy32 (Name ("nominal.fresh_abs_fun_iff_ineq"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   766
       val abs_fun_supp      = PureThy.get_thm thy32 (Name ("nominal.abs_fun_supp"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   767
       val abs_fun_supp_ineq = PureThy.get_thm thy32 (Name ("nominal.abs_fun_supp_ineq"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   768
       val pt_swap_bij       = PureThy.get_thm thy32 (Name ("nominal.pt_swap_bij"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   769
       val pt_fresh_fresh    = PureThy.get_thm thy32 (Name ("nominal.pt_fresh_fresh"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   770
       val pt_bij            = PureThy.get_thm thy32 (Name ("nominal.pt_bij"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   771
       val pt_perm_compose   = PureThy.get_thm thy32 (Name ("nominal.pt_perm_compose"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   772
       val perm_eq_app       = PureThy.get_thm thy32 (Name ("nominal.perm_eq_app"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   773
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   774
       (* abs_perm collects all lemmas for simplifying a permutation *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   775
       (* in front of an abs_fun                                     *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   776
       val (thy33,_) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   777
	   let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   778
	     val name = "abs_perm"
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   779
             val thm_list = Library.flat (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   780
	        let	
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   781
		  val at_inst = PureThy.get_thm thy32 (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   782
		  val pt_inst = PureThy.get_thm thy32 (Name ("pt_"^ak_name^"_inst"));	      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   783
	          val thm = [pt_inst, at_inst] MRS abs_fun_pi
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   784
                  val thm_list = map (fn (ak_name', T') =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   785
                     let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   786
                      val cp_inst = PureThy.get_thm thy32 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   787
	             in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   788
                     [pt_inst, pt_inst, at_inst, cp_inst] MRS abs_fun_pi_ineq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   789
	             end) ak_names_types;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   790
                 in thm::thm_list end) (ak_names_types))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   791
           in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   792
             (PureThy.add_thmss [((name, thm_list),[])] thy32)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   793
           end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   794
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   795
        (* alpha collects all lemmas analysing an equation *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   796
        (* between abs_funs                                *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   797
        (*val (thy34,_) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   798
	   let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   799
	     val name = "alpha"
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   800
             val thm_list = map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   801
	        let	
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   802
		  val at_inst = PureThy.get_thm thy33 (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   803
		  val pt_inst = PureThy.get_thm thy33 (Name ("pt_"^ak_name^"_inst"));	      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   804
	        in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   805
                  [pt_inst, at_inst] MRS abs_fun_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   806
	        end) ak_names_types
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   807
           in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   808
             (PureThy.add_thmss [((name, thm_list),[])] thy33)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   809
           end;*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   810
 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   811
          val (thy34,_) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   812
	   let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   813
	     fun inst_pt_at thm ak_name =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   814
		 let	
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   815
		   val at_inst = PureThy.get_thm thy33 (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   816
		   val pt_inst = PureThy.get_thm thy33 (Name ("pt_"^ak_name^"_inst"));	      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   817
	         in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   818
                     [pt_inst, at_inst] MRS thm
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   819
	         end	 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   820
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   821
           in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   822
            thy33 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   823
	    |> PureThy.add_thmss   [(("alpha", map (inst_pt_at abs_fun_eq) ak_names),[])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   824
            |>>> PureThy.add_thmss [(("perm_swap", map (inst_pt_at pt_swap_bij) ak_names),[])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   825
            |>>> PureThy.add_thmss [(("perm_fresh_fresh", map (inst_pt_at pt_fresh_fresh) ak_names),[])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   826
            |>>> PureThy.add_thmss [(("perm_bij", map (inst_pt_at pt_bij) ak_names),[])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   827
            |>>> PureThy.add_thmss [(("perm_compose", map (inst_pt_at pt_perm_compose) ak_names),[])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   828
            |>>> PureThy.add_thmss [(("perm_app_eq", map (inst_pt_at perm_eq_app) ak_names),[])]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   829
	   end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   830
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   831
         (* perm_dj collects all lemmas that forget an permutation *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   832
         (* when it acts on an atom of different type              *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   833
         val (thy35,_) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   834
	   let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   835
	     val name = "perm_dj"
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   836
             val thm_list = Library.flat (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   837
	        Library.flat (map (fn (ak_name', T') => 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   838
                 if not (ak_name = ak_name') 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   839
                 then 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   840
		    let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   841
                      val dj_inst = PureThy.get_thm thy34 (Name ("dj_"^ak_name^"_"^ak_name'));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   842
                    in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   843
                      [dj_inst RS dj_perm_forget, dj_inst RS dj_pp_forget]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   844
                    end 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   845
                 else []) ak_names_types)) ak_names_types)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   846
           in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   847
             (PureThy.add_thmss [((name, thm_list),[])] thy34)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   848
           end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   849
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   850
         (* abs_fresh collects all lemmas for simplifying a freshness *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   851
         (* proposition involving an abs_fun                          *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   852
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   853
         val (thy36,_) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   854
	   let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   855
	     val name = "abs_fresh"
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   856
             val thm_list = Library.flat (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   857
	        let	
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   858
		  val at_inst = PureThy.get_thm thy35 (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   859
		  val pt_inst = PureThy.get_thm thy35 (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   860
                  val fs_inst = PureThy.get_thm thy35 (Name ("fs_"^ak_name^"_inst"));	      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   861
	          val thm = [pt_inst, at_inst, (fs_inst RS fs1)] MRS fresh_iff
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   862
                  val thm_list = Library.flat (map (fn (ak_name', T') =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   863
                     (if (not (ak_name = ak_name')) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   864
                     then
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   865
                       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   866
                        val cp_inst = PureThy.get_thm thy35 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   867
	                val dj_inst = PureThy.get_thm thy35 (Name ("dj_"^ak_name'^"_"^ak_name));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   868
                       in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   869
                        [[pt_inst, pt_inst, at_inst, cp_inst, dj_inst] MRS fresh_iff_ineq]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   870
	               end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   871
                     else [])) ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   872
                 in thm::thm_list end) (ak_names_types))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   873
           in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   874
             (PureThy.add_thmss [((name, thm_list),[])] thy35)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   875
           end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   876
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   877
         (* abs_supp collects all lemmas for simplifying  *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   878
         (* support proposition involving an abs_fun      *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   879
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   880
         val (thy37,_) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   881
	   let 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   882
	     val name = "abs_supp"
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   883
             val thm_list = Library.flat (map (fn (ak_name, T) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   884
	        let	
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   885
		  val at_inst = PureThy.get_thm thy36 (Name ("at_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   886
		  val pt_inst = PureThy.get_thm thy36 (Name ("pt_"^ak_name^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   887
                  val fs_inst = PureThy.get_thm thy36 (Name ("fs_"^ak_name^"_inst"));	      
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   888
	          val thm1 = [pt_inst, at_inst, (fs_inst RS fs1)] MRS abs_fun_supp
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   889
                  val thm2 = [pt_inst, at_inst] MRS abs_fun_supp
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   890
                  val thm_list = Library.flat (map (fn (ak_name', T') =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   891
                     (if (not (ak_name = ak_name')) 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   892
                     then
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   893
                       let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   894
                        val cp_inst = PureThy.get_thm thy36 (Name ("cp_"^ak_name^"_"^ak_name'^"_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   895
	                val dj_inst = PureThy.get_thm thy36 (Name ("dj_"^ak_name'^"_"^ak_name));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   896
                       in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   897
                        [[pt_inst, pt_inst, at_inst, cp_inst, dj_inst] MRS abs_fun_supp_ineq]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   898
	               end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   899
                     else [])) ak_names_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   900
                 in thm1::thm2::thm_list end) (ak_names_types))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   901
           in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   902
             (PureThy.add_thmss [((name, thm_list),[])] thy36)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   903
           end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   904
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   905
    in NominalData.put (fold Symtab.update (map (rpair ()) full_ak_names)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   906
      (NominalData.get thy11)) thy37
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   907
    end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   908
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   909
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   910
(* syntax und parsing *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   911
structure P = OuterParse and K = OuterKeyword;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   912
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   913
val atom_declP =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   914
  OuterSyntax.command "atom_decl" "Declare new kinds of atoms" K.thy_decl
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   915
    (Scan.repeat1 P.name >> (Toplevel.theory o create_nom_typedecls));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   916
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   917
val _ = OuterSyntax.add_parsers [atom_declP];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   918
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   919
val setup = [NominalData.init];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   920
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   921
(*=======================================================================*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   922
18016
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   923
(** FIXME: DatatypePackage should export this function **)
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   924
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   925
local
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   926
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   927
fun dt_recs (DtTFree _) = []
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   928
  | dt_recs (DtType (_, dts)) = List.concat (map dt_recs dts)
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   929
  | dt_recs (DtRec i) = [i];
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   930
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   931
fun dt_cases (descr: descr) (_, args, constrs) =
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   932
  let
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   933
    fun the_bname i = Sign.base_name (#1 (valOf (AList.lookup (op =) descr i)));
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   934
    val bnames = map the_bname (distinct (List.concat (map dt_recs args)));
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   935
  in map (fn (c, _) => space_implode "_" (Sign.base_name c :: bnames)) constrs end;
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   936
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   937
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   938
fun induct_cases descr =
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   939
  DatatypeProp.indexify_names (List.concat (map (dt_cases descr) (map #2 descr)));
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   940
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   941
fun exhaust_cases descr i = dt_cases descr (valOf (AList.lookup (op =) descr i));
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   942
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   943
in
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   944
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   945
fun mk_case_names_induct descr = RuleCases.case_names (induct_cases descr);
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   946
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   947
fun mk_case_names_exhausts descr new =
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   948
  map (RuleCases.case_names o exhaust_cases descr o #1)
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   949
    (List.filter (fn ((_, (name, _, _))) => name mem_string new) descr);
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   950
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   951
end;
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   952
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   953
(*******************************)
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
   954
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   955
val (_ $ (_ $ (_ $ (distinct_f $ _) $ _))) = hd (prems_of distinct_lemma);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   956
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   957
fun read_typ sign ((Ts, sorts), str) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   958
  let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   959
    val T = Type.no_tvars (Sign.read_typ (sign, (AList.lookup op =)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   960
      (map (apfst (rpair ~1)) sorts)) str) handle TYPE (msg, _, _) => error msg
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   961
  in (Ts @ [T], add_typ_tfrees (T, sorts)) end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   962
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   963
(** taken from HOL/Tools/datatype_aux.ML **)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   964
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   965
fun indtac indrule indnames i st =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   966
  let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   967
    val ts = HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of indrule));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   968
    val ts' = HOLogic.dest_conj (HOLogic.dest_Trueprop
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   969
      (Logic.strip_imp_concl (List.nth (prems_of st, i - 1))));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   970
    val getP = if can HOLogic.dest_imp (hd ts) then
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   971
      (apfst SOME) o HOLogic.dest_imp else pair NONE;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   972
    fun abstr (t1, t2) = (case t1 of
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   973
        NONE => (case filter (fn Free (s, _) => s mem indnames | _ => false)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   974
              (term_frees t2) of
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   975
            [Free (s, T)] => absfree (s, T, t2)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   976
          | _ => sys_error "indtac")
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   977
      | SOME (_ $ t' $ _) => Abs ("x", fastype_of t', abstract_over (t', t2)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   978
    val cert = cterm_of (Thm.sign_of_thm st);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   979
    val Ps = map (cert o head_of o snd o getP) ts;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   980
    val indrule' = cterm_instantiate (Ps ~~
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   981
      (map (cert o abstr o getP) ts')) indrule
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   982
  in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   983
    rtac indrule' i st
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   984
  end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   985
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   986
fun gen_add_nominal_datatype prep_typ err flat_names new_type_names dts thy =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   987
  let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   988
    (* this theory is used just for parsing *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   989
  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   990
    val tmp_thy = thy |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   991
      Theory.copy |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   992
      Theory.add_types (map (fn (tvs, tname, mx, _) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   993
        (tname, length tvs, mx)) dts);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   994
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   995
    val sign = Theory.sign_of tmp_thy;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   996
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   997
    val atoms = atoms_of thy;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   998
    val classes = map (NameSpace.map_base (fn s => "pt_" ^ s)) atoms;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
   999
    val cp_classes = List.concat (map (fn atom1 => map (fn atom2 =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1000
      Sign.intern_class thy ("cp_" ^ Sign.base_name atom1 ^ "_" ^
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1001
        Sign.base_name atom2)) atoms) atoms);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1002
    fun augment_sort S = S union classes;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1003
    val augment_sort_typ = map_type_tfree (fn (s, S) => TFree (s, augment_sort S));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1004
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1005
    fun prep_constr ((constrs, sorts), (cname, cargs, mx)) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1006
      let val (cargs', sorts') = Library.foldl (prep_typ sign) (([], sorts), cargs)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1007
      in (constrs @ [(cname, cargs', mx)], sorts') end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1008
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1009
    fun prep_dt_spec ((dts, sorts), (tvs, tname, mx, constrs)) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1010
      let val (constrs', sorts') = Library.foldl prep_constr (([], sorts), constrs)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1011
      in (dts @ [(tvs, tname, mx, constrs')], sorts') end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1012
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1013
    val (dts', sorts) = Library.foldl prep_dt_spec (([], []), dts);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1014
    val sorts' = map (apsnd augment_sort) sorts;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1015
    val tyvars = map #1 dts';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1016
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1017
    val types_syntax = map (fn (tvs, tname, mx, constrs) => (tname, mx)) dts';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1018
    val constr_syntax = map (fn (tvs, tname, mx, constrs) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1019
      map (fn (cname, cargs, mx) => (cname, mx)) constrs) dts';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1020
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1021
    val ps = map (fn (_, n, _, _) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1022
      (Sign.full_name sign n, Sign.full_name sign (n ^ "_Rep"))) dts;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1023
    val rps = map Library.swap ps;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1024
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1025
    fun replace_types (Type ("nominal.ABS", [T, U])) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1026
          Type ("fun", [T, Type ("nominal.nOption", [replace_types U])])
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1027
      | replace_types (Type (s, Ts)) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1028
          Type (getOpt (AList.lookup op = ps s, s), map replace_types Ts)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1029
      | replace_types T = T;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1030
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1031
    fun replace_types' (Type (s, Ts)) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1032
          Type (getOpt (AList.lookup op = rps s, s), map replace_types' Ts)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1033
      | replace_types' T = T;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1034
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1035
    val dts'' = map (fn (tvs, tname, mx, constrs) => (tvs, tname ^ "_Rep", NoSyn,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1036
      map (fn (cname, cargs, mx) => (cname,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1037
        map (augment_sort_typ o replace_types) cargs, NoSyn)) constrs)) dts';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1038
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1039
    val new_type_names' = map (fn n => n ^ "_Rep") new_type_names;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1040
    val full_new_type_names' = map (Sign.full_name (sign_of thy)) new_type_names';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1041
18045
6d69a4190eb2 1) have adjusted the swapping of the result type
urbanc
parents: 18017
diff changeset
  1042
    val ({induction, ...},thy1) =
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1043
      DatatypePackage.add_datatype_i err flat_names new_type_names' dts'' thy;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1044
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1045
    val SOME {descr, ...} = Symtab.lookup
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1046
      (DatatypePackage.get_datatypes thy1) (hd full_new_type_names');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1047
    val typ_of_dtyp = typ_of_dtyp descr sorts';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1048
    fun nth_dtyp i = typ_of_dtyp (DtRec i);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1049
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1050
    (**** define permutation functions ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1051
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1052
    val permT = mk_permT (TFree ("'x", HOLogic.typeS));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1053
    val pi = Free ("pi", permT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1054
    val perm_types = map (fn (i, _) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1055
      let val T = nth_dtyp i
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1056
      in permT --> T --> T end) descr;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1057
    val perm_names = replicate (length new_type_names) "nominal.perm" @
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1058
      DatatypeProp.indexify_names (map (fn i => Sign.full_name (sign_of thy1)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1059
        ("perm_" ^ name_of_typ (nth_dtyp i)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1060
          (length new_type_names upto length descr - 1));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1061
    val perm_names_types = perm_names ~~ perm_types;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1062
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1063
    val perm_eqs = List.concat (map (fn (i, (_, _, constrs)) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1064
      let val T = nth_dtyp i
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1065
      in map (fn (cname, dts) => 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1066
        let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1067
          val Ts = map typ_of_dtyp dts;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1068
          val names = DatatypeProp.make_tnames Ts;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1069
          val args = map Free (names ~~ Ts);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1070
          val c = Const (cname, Ts ---> T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1071
          fun perm_arg (dt, x) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1072
            let val T = type_of x
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1073
            in if is_rec_type dt then
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1074
                let val (Us, _) = strip_type T
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1075
                in list_abs (map (pair "x") Us,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1076
                  Const (List.nth (perm_names_types, body_index dt)) $ pi $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1077
                    list_comb (x, map (fn (i, U) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1078
                      Const ("nominal.perm", permT --> U --> U) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1079
                        (Const ("List.rev", permT --> permT) $ pi) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1080
                        Bound i) ((length Us - 1 downto 0) ~~ Us)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1081
                end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1082
              else Const ("nominal.perm", permT --> T --> T) $ pi $ x
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1083
            end;  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1084
        in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1085
          (("", HOLogic.mk_Trueprop (HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1086
            (Const (List.nth (perm_names_types, i)) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1087
               Free ("pi", mk_permT (TFree ("'x", HOLogic.typeS))) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1088
               list_comb (c, args),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1089
             list_comb (c, map perm_arg (dts ~~ args))))), [])
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1090
        end) constrs
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1091
      end) descr);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1092
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1093
    val (thy2, perm_simps) = thy1 |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1094
      Theory.add_consts_i (map (fn (s, T) => (Sign.base_name s, T, NoSyn))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1095
        (List.drop (perm_names_types, length new_type_names))) |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1096
      PrimrecPackage.add_primrec_i "" perm_eqs;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1097
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1098
    (**** prove that permutation functions introduced by unfolding are ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1099
    (**** equivalent to already existing permutation functions         ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1100
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1101
    val _ = warning ("length descr: " ^ string_of_int (length descr));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1102
    val _ = warning ("length new_type_names: " ^ string_of_int (length new_type_names));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1103
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1104
    val perm_indnames = DatatypeProp.make_tnames (map body_type perm_types);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1105
    val perm_fun_def = PureThy.get_thm thy2 (Name "perm_fun_def");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1106
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1107
    val unfolded_perm_eq_thms =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1108
      if length descr = length new_type_names then []
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1109
      else map standard (List.drop (split_conj_thm
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1110
        (Goal.prove thy2 [] []
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1111
          (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1112
            (map (fn (c as (s, T), x) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1113
               let val [T1, T2] = binder_types T
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1114
               in HOLogic.mk_eq (Const c $ pi $ Free (x, T2),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1115
                 Const ("nominal.perm", T) $ pi $ Free (x, T2))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1116
               end)
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1117
             (perm_names_types ~~ perm_indnames))))
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1118
          (fn _ => EVERY [indtac induction perm_indnames 1,
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1119
            ALLGOALS (asm_full_simp_tac
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1120
              (simpset_of thy2 addsimps [perm_fun_def]))])),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1121
        length new_type_names));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1122
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1123
    (**** prove [] \<bullet> t = t ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1124
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1125
    val _ = warning "perm_empty_thms";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1126
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1127
    val perm_empty_thms = List.concat (map (fn a =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1128
      let val permT = mk_permT (Type (a, []))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1129
      in map standard (List.take (split_conj_thm
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1130
        (Goal.prove thy2 [] []
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1131
          (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1132
            (map (fn ((s, T), x) => HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1133
                (Const (s, permT --> T --> T) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1134
                   Const ("List.list.Nil", permT) $ Free (x, T),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1135
                 Free (x, T)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1136
             (perm_names ~~
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1137
              map body_type perm_types ~~ perm_indnames))))
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1138
          (fn _ => EVERY [indtac induction perm_indnames 1,
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1139
            ALLGOALS (asm_full_simp_tac (simpset_of thy2))])),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1140
        length new_type_names))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1141
      end)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1142
      atoms);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1143
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1144
    (**** prove (pi1 @ pi2) \<bullet> t = pi1 \<bullet> (pi2 \<bullet> t) ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1145
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1146
    val _ = warning "perm_append_thms";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1147
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1148
    (*FIXME: these should be looked up statically*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1149
    val at_pt_inst = PureThy.get_thm thy2 (Name "at_pt_inst");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1150
    val pt2 = PureThy.get_thm thy2 (Name "pt2");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1151
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1152
    val perm_append_thms = List.concat (map (fn a =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1153
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1154
        val permT = mk_permT (Type (a, []));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1155
        val pi1 = Free ("pi1", permT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1156
        val pi2 = Free ("pi2", permT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1157
        val pt_inst = PureThy.get_thm thy2 (Name ("pt_" ^ Sign.base_name a ^ "_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1158
        val pt2' = pt_inst RS pt2;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1159
        val pt2_ax = PureThy.get_thm thy2
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1160
          (Name (NameSpace.map_base (fn s => "pt_" ^ s ^ "2") a));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1161
      in List.take (map standard (split_conj_thm
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1162
        (Goal.prove thy2 [] []
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1163
             (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1164
                (map (fn ((s, T), x) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1165
                    let val perm = Const (s, permT --> T --> T)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1166
                    in HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1167
                      (perm $ (Const ("List.op @", permT --> permT --> permT) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1168
                         pi1 $ pi2) $ Free (x, T),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1169
                       perm $ pi1 $ (perm $ pi2 $ Free (x, T)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1170
                    end)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1171
                  (perm_names ~~
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1172
                   map body_type perm_types ~~ perm_indnames))))
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1173
           (fn _ => EVERY [indtac induction perm_indnames 1,
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1174
              ALLGOALS (asm_full_simp_tac (simpset_of thy2 addsimps [pt2', pt2_ax]))]))),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1175
         length new_type_names)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1176
      end) atoms);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1177
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1178
    (**** prove pi1 ~ pi2 ==> pi1 \<bullet> t = pi2 \<bullet> t ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1179
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1180
    val _ = warning "perm_eq_thms";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1181
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1182
    val pt3 = PureThy.get_thm thy2 (Name "pt3");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1183
    val pt3_rev = PureThy.get_thm thy2 (Name "pt3_rev");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1184
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1185
    val perm_eq_thms = List.concat (map (fn a =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1186
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1187
        val permT = mk_permT (Type (a, []));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1188
        val pi1 = Free ("pi1", permT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1189
        val pi2 = Free ("pi2", permT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1190
        (*FIXME: not robust - better access these theorems using NominalData?*)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1191
        val at_inst = PureThy.get_thm thy2 (Name ("at_" ^ Sign.base_name a ^ "_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1192
        val pt_inst = PureThy.get_thm thy2 (Name ("pt_" ^ Sign.base_name a ^ "_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1193
        val pt3' = pt_inst RS pt3;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1194
        val pt3_rev' = at_inst RS (pt_inst RS pt3_rev);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1195
        val pt3_ax = PureThy.get_thm thy2
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1196
          (Name (NameSpace.map_base (fn s => "pt_" ^ s ^ "3") a));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1197
      in List.take (map standard (split_conj_thm
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1198
        (Goal.prove thy2 [] [] (Logic.mk_implies
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1199
             (HOLogic.mk_Trueprop (Const ("nominal.prm_eq",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1200
                permT --> permT --> HOLogic.boolT) $ pi1 $ pi2),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1201
              HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1202
                (map (fn ((s, T), x) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1203
                    let val perm = Const (s, permT --> T --> T)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1204
                    in HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1205
                      (perm $ pi1 $ Free (x, T),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1206
                       perm $ pi2 $ Free (x, T))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1207
                    end)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1208
                  (perm_names ~~
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1209
                   map body_type perm_types ~~ perm_indnames)))))
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1210
           (fn _ => EVERY [indtac induction perm_indnames 1,
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1211
              ALLGOALS (asm_full_simp_tac (simpset_of thy2 addsimps [pt3', pt3_rev', pt3_ax]))]))),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1212
         length new_type_names)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1213
      end) atoms);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1214
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1215
    (**** prove pi1 \<bullet> (pi2 \<bullet> t) = (pi1 \<bullet> pi2) \<bullet> (pi1 \<bullet> t) ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1216
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1217
    val cp1 = PureThy.get_thm thy2 (Name "cp1");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1218
    val dj_cp = PureThy.get_thm thy2 (Name "dj_cp");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1219
    val pt_perm_compose = PureThy.get_thm thy2 (Name "pt_perm_compose");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1220
    val pt_perm_compose_rev = PureThy.get_thm thy2 (Name "pt_perm_compose_rev");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1221
    val dj_perm_perm_forget = PureThy.get_thm thy2 (Name "dj_perm_perm_forget");
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1222
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1223
    fun composition_instance name1 name2 thy =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1224
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1225
        val name1' = Sign.base_name name1;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1226
        val name2' = Sign.base_name name2;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1227
        val cp_class = Sign.intern_class thy ("cp_" ^ name1' ^ "_" ^ name2');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1228
        val permT1 = mk_permT (Type (name1, []));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1229
        val permT2 = mk_permT (Type (name2, []));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1230
        val augment = map_type_tfree
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1231
          (fn (x, S) => TFree (x, cp_class :: S));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1232
        val Ts = map (augment o body_type) perm_types;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1233
        val cp_inst = PureThy.get_thm thy
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1234
          (Name ("cp_" ^ name1' ^ "_" ^ name2' ^ "_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1235
        val simps = simpset_of thy addsimps (perm_fun_def ::
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1236
          (if name1 <> name2 then
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1237
             let val dj = PureThy.get_thm thy (Name ("dj_" ^ name2' ^ "_" ^ name1'))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1238
             in [dj RS (cp_inst RS dj_cp), dj RS dj_perm_perm_forget] end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1239
           else
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1240
             let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1241
               val at_inst = PureThy.get_thm thy (Name ("at_" ^ name1' ^ "_inst"));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1242
               val pt_inst = PureThy.get_thm thy (Name ("pt_" ^ name1' ^ "_inst"))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1243
             in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1244
               [cp_inst RS cp1 RS sym,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1245
                at_inst RS (pt_inst RS pt_perm_compose) RS sym,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1246
                at_inst RS (pt_inst RS pt_perm_compose_rev) RS sym]
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1247
            end))
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1248
        val thms = split_conj_thm (standard (Goal.prove thy [] []
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1249
            (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1250
              (map (fn ((s, T), x) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1251
                  let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1252
                    val pi1 = Free ("pi1", permT1);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1253
                    val pi2 = Free ("pi2", permT2);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1254
                    val perm1 = Const (s, permT1 --> T --> T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1255
                    val perm2 = Const (s, permT2 --> T --> T);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1256
                    val perm3 = Const ("nominal.perm", permT1 --> permT2 --> permT2)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1257
                  in HOLogic.mk_eq
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1258
                    (perm1 $ pi1 $ (perm2 $ pi2 $ Free (x, T)),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1259
                     perm2 $ (perm3 $ pi1 $ pi2) $ (perm1 $ pi1 $ Free (x, T)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1260
                  end)
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1261
                (perm_names ~~ Ts ~~ perm_indnames))))
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1262
          (fn _ => EVERY [indtac induction perm_indnames 1,
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1263
             ALLGOALS (asm_full_simp_tac simps)])))
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1264
      in
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1265
        foldl (fn ((s, tvs), thy) => AxClass.add_inst_arity_i
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1266
            (s, replicate (length tvs) (cp_class :: classes), [cp_class])
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1267
            (AxClass.intro_classes_tac [] THEN ALLGOALS (resolve_tac thms)) thy)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1268
          thy (full_new_type_names' ~~ tyvars)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1269
      end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1270
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1271
    val (thy3, perm_thmss) = thy2 |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1272
      fold (fn name1 => fold (composition_instance name1) atoms) atoms |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1273
      curry (Library.foldr (fn ((i, (tyname, args, _)), thy) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1274
        AxClass.add_inst_arity_i (tyname, replicate (length args) classes, classes)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1275
        (AxClass.intro_classes_tac [] THEN REPEAT (EVERY
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1276
           [resolve_tac perm_empty_thms 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1277
            resolve_tac perm_append_thms 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1278
            resolve_tac perm_eq_thms 1, assume_tac 1])) thy))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1279
        (List.take (descr, length new_type_names)) |>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1280
      PureThy.add_thmss
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1281
        [((space_implode "_" new_type_names ^ "_unfolded_perm_eq",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1282
          unfolded_perm_eq_thms), [Simplifier.simp_add_global]),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1283
         ((space_implode "_" new_type_names ^ "_perm_empty",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1284
          perm_empty_thms), [Simplifier.simp_add_global]),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1285
         ((space_implode "_" new_type_names ^ "_perm_append",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1286
          perm_append_thms), [Simplifier.simp_add_global]),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1287
         ((space_implode "_" new_type_names ^ "_perm_eq",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1288
          perm_eq_thms), [Simplifier.simp_add_global])];
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1289
  
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1290
    (**** Define representing sets ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1291
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1292
    val _ = warning "representing sets";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1293
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1294
    val rep_set_names = map (Sign.full_name thy3) (DatatypeProp.indexify_names
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1295
      (map (fn (i, _) => name_of_typ (nth_dtyp i) ^ "_set") descr));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1296
    val big_rep_name =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1297
      space_implode "_" (DatatypeProp.indexify_names (List.mapPartial
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1298
        (fn (i, ("nominal.nOption", _, _)) => NONE
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1299
          | (i, _) => SOME (name_of_typ (nth_dtyp i))) descr)) ^ "_set";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1300
    val _ = warning ("big_rep_name: " ^ big_rep_name);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1301
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1302
    fun strip_option (dtf as DtType ("fun", [dt, DtRec i])) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1303
          (case AList.lookup op = descr i of
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1304
             SOME ("nominal.nOption", _, [(_, [dt']), _]) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1305
               apfst (cons dt) (strip_option dt')
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1306
           | _ => ([], dtf))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1307
      | strip_option dt = ([], dt);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1308
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1309
    fun make_intr s T (cname, cargs) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1310
      let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1311
        fun mk_prem (dt, (j, j', prems, ts)) = 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1312
          let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1313
            val (dts, dt') = strip_option dt;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1314
            val (dts', dt'') = strip_dtyp dt';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1315
            val Ts = map typ_of_dtyp dts;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1316
            val Us = map typ_of_dtyp dts';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1317
            val T = typ_of_dtyp dt'';
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1318
            val free = mk_Free "x" (Us ---> T) j;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1319
            val free' = app_bnds free (length Us);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1320
            fun mk_abs_fun (T, (i, t)) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1321
              let val U = fastype_of t
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1322
              in (i + 1, Const ("nominal.abs_fun", [T, U, T] --->
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1323
                Type ("nominal.nOption", [U])) $ mk_Free "y" T i $ t)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1324
              end
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1325
          in (j + 1, j' + length Ts,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1326
            case dt'' of
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1327
                DtRec k => list_all (map (pair "x") Us,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1328
                  HOLogic.mk_Trueprop (HOLogic.mk_mem (free',
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1329
                    Const (List.nth (rep_set_names, k),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1330
                      HOLogic.mk_setT T)))) :: prems
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1331
              | _ => prems,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1332
            snd (foldr mk_abs_fun (j', free) Ts) :: ts)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1333
          end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1334
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1335
        val (_, _, prems, ts) = foldr mk_prem (1, 1, [], []) cargs;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1336
        val concl = HOLogic.mk_Trueprop (HOLogic.mk_mem
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1337
          (list_comb (Const (cname, map fastype_of ts ---> T), ts),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1338
           Const (s, HOLogic.mk_setT T)))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1339
      in Logic.list_implies (prems, concl)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1340
      end;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1341
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1342
    val (intr_ts, ind_consts) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1343
      apfst List.concat (ListPair.unzip (List.mapPartial
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1344
        (fn ((_, ("nominal.nOption", _, _)), _) => NONE
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1345
          | ((i, (_, _, constrs)), rep_set_name) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1346
              let val T = nth_dtyp i
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1347
              in SOME (map (make_intr rep_set_name T) constrs,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1348
                Const (rep_set_name, HOLogic.mk_setT T))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1349
              end)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1350
                (descr ~~ rep_set_names)));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1351
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1352
    val (thy4, {raw_induct = rep_induct, intrs = rep_intrs, ...}) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1353
      setmp InductivePackage.quiet_mode false
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1354
        (InductivePackage.add_inductive_i false true big_rep_name false true false
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1355
           ind_consts (map (fn x => (("", x), [])) intr_ts) []) thy3;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1356
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1357
    (**** Prove that representing set is closed under permutation ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1358
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1359
    val _ = warning "proving closure under permutation...";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1360
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1361
    val perm_indnames' = List.mapPartial
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1362
      (fn (x, (_, ("nominal.nOption", _, _))) => NONE | (x, _) => SOME x)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1363
      (perm_indnames ~~ descr);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1364
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1365
    fun mk_perm_closed name = map (fn th => standard (th RS mp))
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1366
      (List.take (split_conj_thm (Goal.prove thy4 [] []
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1367
        (HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj (map
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1368
           (fn (S, x) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1369
              let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1370
                val S = map_term_types (map_type_tfree
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1371
                  (fn (s, cs) => TFree (s, cs union cp_classes))) S;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1372
                val T = HOLogic.dest_setT (fastype_of S);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1373
                val permT = mk_permT (Type (name, []))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1374
              in HOLogic.mk_imp (HOLogic.mk_mem (Free (x, T), S),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1375
                HOLogic.mk_mem (Const ("nominal.perm", permT --> T --> T) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1376
                  Free ("pi", permT) $ Free (x, T), S))
18010
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1377
              end) (ind_consts ~~ perm_indnames'))))
c885c93a9324 Removed legacy prove_goalw_cterm command.
berghofe
parents: 17874
diff changeset
  1378
        (fn _ => EVERY (* CU: added perm_fun_def in the final tactic in order to deal with funs *)
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1379
           [indtac rep_induct [] 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1380
            ALLGOALS (simp_tac (simpset_of thy4 addsimps
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1381
              (symmetric perm_fun_def :: PureThy.get_thms thy4 (Name ("abs_perm"))))),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1382
            ALLGOALS (resolve_tac rep_intrs 
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1383
               THEN_ALL_NEW (asm_full_simp_tac (simpset_of thy4 addsimps [perm_fun_def])))])),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1384
        length new_type_names));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1385
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1386
    (* FIXME: theorems are stored in database for testing only *)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1387
    val perm_closed_thmss = map mk_perm_closed atoms;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1388
    val (thy5, _) = PureThy.add_thmss [(("perm_closed",
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1389
      List.concat perm_closed_thmss), [])] thy4;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1390
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1391
    (**** typedef ****)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1392
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1393
    val _ = warning "defining type...";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1394
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1395
    val (thy6, typedefs) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1396
      foldl_map (fn (thy, ((((name, mx), tvs), c), name')) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1397
        setmp TypedefPackage.quiet_mode true
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1398
          (TypedefPackage.add_typedef_i false (SOME name') (name, tvs, mx) c NONE
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1399
            (rtac exI 1 THEN
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1400
              QUIET_BREADTH_FIRST (has_fewer_prems 1)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1401
              (resolve_tac rep_intrs 1))) thy |> (fn (thy, r) =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1402
        let
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1403
          val permT = mk_permT (TFree (variant tvs "'a", HOLogic.typeS));
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1404
          val pi = Free ("pi", permT);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1405
          val tvs' = map (fn s => TFree (s, the (AList.lookup op = sorts' s))) tvs;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1406
          val T = Type (Sign.intern_type thy name, tvs');
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1407
          val Const (_, Type (_, [U])) = c
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1408
        in apsnd (pair r o hd)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1409
          (PureThy.add_defs_i true [(("prm_" ^ name ^ "_def", Logic.mk_equals
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1410
            (Const ("nominal.perm", permT --> T --> T) $ pi $ Free ("x", T),
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1411
             Const (Sign.intern_const thy ("Abs_" ^ name), U --> T) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1412
               (Const ("nominal.perm", permT --> U --> U) $ pi $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1413
                 (Const (Sign.intern_const thy ("Rep_" ^ name), T --> U) $
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1414
                   Free ("x", T))))), [])] thy)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1415
        end))
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1416
          (thy5, types_syntax ~~ tyvars ~~
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1417
            (List.take (ind_consts, length new_type_names)) ~~ new_type_names);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1418
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1419
    val perm_defs = map snd typedefs;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1420
    val Abs_inverse_thms = map (#Abs_inverse o fst) typedefs;
18016
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
  1421
    val Rep_inverse_thms = map (#Rep_inverse o fst) typedefs;
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1422
    val Rep_thms = map (#Rep o fst) typedefs;
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1423
18016
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
  1424
    val big_name = space_implode "_" new_type_names;
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
  1425
8f3a80033ba4 Implemented proof of weak induction theorem.
berghofe
parents: 18010
diff changeset
  1426
17870
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1427
    (** prove that new types are in class pt_<name> **)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1428
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1429
    val _ = warning "prove that new types are in class pt_<name> ...";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1430
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1431
    fun pt_instance ((class, atom), perm_closed_thms) =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1432
      fold (fn (((({Abs_inverse, Rep_inverse, Rep, ...},
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1433
        perm_def), name), tvs), perm_closed) => fn thy =>
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1434
          AxClass.add_inst_arity_i
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1435
            (Sign.intern_type thy name,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1436
              replicate (length tvs) (classes @ cp_classes), [class])
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1437
            (EVERY [AxClass.intro_classes_tac [],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1438
              rewrite_goals_tac [perm_def],
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1439
              asm_full_simp_tac (simpset_of thy addsimps [Rep_inverse]) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1440
              asm_full_simp_tac (simpset_of thy addsimps
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1441
                [Rep RS perm_closed RS Abs_inverse]) 1,
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1442
              asm_full_simp_tac (HOL_basic_ss addsimps [PureThy.get_thm thy
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1443
                (Name ("pt_" ^ Sign.base_name atom ^ "3"))]) 1]) thy)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1444
        (typedefs ~~ new_type_names ~~ tyvars ~~ perm_closed_thms);
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1445
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1446
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1447
    (** prove that new types are in class cp_<name1>_<name2> **)
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1448
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1449
    val _ = warning "prove that new types are in class cp_<name1>_<name2> ...";
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1450
c35381811d5c Initial revision.
berghofe
parents:
diff changeset
  1451
    fun cp_instance (atom1, perm_closed_thms1) (atom2, perm_closed_thms2) thy =
c35381811d5c Initial revision.
berghofe
parents:
diff changeset