src/Pure/pure_thy.ML
author wenzelm
Tue Jan 12 13:40:08 1999 +0100 (1999-01-12)
changeset 6091 e3cdbd929a24
parent 6027 9dd06eeda95c
child 6094 fd0f737b1956
permissions -rw-r--r--
eliminated tthm type and Attribute structure;
wenzelm@3987
     1
(*  Title:      Pure/pure_thy.ML
wenzelm@3987
     2
    ID:         $Id$
wenzelm@3987
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@3987
     4
wenzelm@5091
     5
Theorem database, derived theory operations, and the ProtoPure theory.
wenzelm@3987
     6
*)
wenzelm@3987
     7
wenzelm@4022
     8
signature BASIC_PURE_THY =
wenzelm@4022
     9
sig
wenzelm@5000
    10
  val print_theorems: theory -> unit
wenzelm@5000
    11
  val print_theory: theory -> unit
wenzelm@4022
    12
  val get_thm: theory -> xstring -> thm
wenzelm@4022
    13
  val get_thms: theory -> xstring -> thm list
wenzelm@4022
    14
  val thms_of: theory -> (string * thm) list
wenzelm@5091
    15
  structure ProtoPure:
wenzelm@5091
    16
    sig
wenzelm@5091
    17
      val thy: theory
wenzelm@5091
    18
      val flexpair_def: thm
wenzelm@5091
    19
      val Goal_def: thm
wenzelm@5091
    20
    end
wenzelm@4853
    21
end;
wenzelm@4022
    22
wenzelm@3987
    23
signature PURE_THY =
wenzelm@3987
    24
sig
wenzelm@4022
    25
  include BASIC_PURE_THY
wenzelm@6091
    26
  val thms_closure: theory -> xstring -> thm list option
wenzelm@6091
    27
  val get_thmss: theory -> xstring list -> thm list
wenzelm@4022
    28
  val thms_containing: theory -> string list -> (string * thm) list
wenzelm@5907
    29
  val default_name: string -> string
wenzelm@6091
    30
  val store_thm: (bstring * thm) * theory attribute list -> theory -> theory * thm
wenzelm@4022
    31
  val smart_store_thm: (bstring * thm) -> thm
wenzelm@6091
    32
  val add_thms: ((bstring * thm) * theory attribute list) list -> theory -> theory
wenzelm@6091
    33
  val add_thmss: ((bstring * thm list) * theory attribute list) list -> theory -> theory
wenzelm@6091
    34
  val have_thmss: bstring -> theory attribute list ->
wenzelm@6091
    35
    (thm list * theory attribute list) list -> theory -> theory * thm list
wenzelm@4853
    36
  val add_axioms: ((bstring * string) * theory attribute list) list -> theory -> theory
wenzelm@4853
    37
  val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory
wenzelm@4853
    38
  val add_axiomss: ((bstring * string list) * theory attribute list) list -> theory -> theory
wenzelm@4853
    39
  val add_axiomss_i: ((bstring * term list) * theory attribute list) list -> theory -> theory
wenzelm@4853
    40
  val add_defs: ((bstring * string) * theory attribute list) list -> theory -> theory
wenzelm@4853
    41
  val add_defs_i: ((bstring * term) * theory attribute list) list -> theory -> theory
wenzelm@4853
    42
  val add_defss: ((bstring * string list) * theory attribute list) list -> theory -> theory
wenzelm@4853
    43
  val add_defss_i: ((bstring * term list) * theory attribute list) list -> theory -> theory
wenzelm@4963
    44
  val get_name: theory -> string
wenzelm@4963
    45
  val put_name: string -> theory -> theory
wenzelm@4963
    46
  val global_path: theory -> theory
wenzelm@4963
    47
  val local_path: theory -> theory
wenzelm@4963
    48
  val begin_theory: string -> theory list -> theory
wenzelm@4963
    49
  val end_theory: theory -> theory
wenzelm@5091
    50
  exception ROLLBACK of theory * exn option
wenzelm@5091
    51
  val transaction: (theory -> theory) -> theory -> theory
wenzelm@4922
    52
  val add_typedecls: (bstring * string list * mixfix) list -> theory -> theory
wenzelm@3987
    53
end;
wenzelm@3987
    54
wenzelm@3987
    55
structure PureThy: PURE_THY =
wenzelm@3987
    56
struct
wenzelm@3987
    57
wenzelm@3987
    58
wenzelm@4922
    59
(*** theorem database ***)
wenzelm@3987
    60
wenzelm@4922
    61
(** data kind 'Pure/theorems' **)
wenzelm@3987
    62
wenzelm@5005
    63
structure TheoremsDataArgs =
wenzelm@5005
    64
struct
wenzelm@5005
    65
  val name = "Pure/theorems";
wenzelm@3987
    66
wenzelm@5005
    67
  type T =
wenzelm@5005
    68
    {space: NameSpace.T,
wenzelm@6091
    69
      thms_tab: thm list Symtab.table,
wenzelm@6091
    70
      const_idx: int * (int * thm) list Symtab.table} ref;
wenzelm@3987
    71
wenzelm@4853
    72
  fun mk_empty _ =
wenzelm@5005
    73
    ref {space = NameSpace.empty, thms_tab = Symtab.empty, const_idx = (0, Symtab.empty)} : T;
wenzelm@3987
    74
wenzelm@5005
    75
  val empty = mk_empty ();
wenzelm@5005
    76
  val prep_ext = mk_empty;
wenzelm@5005
    77
  val merge = mk_empty;
wenzelm@5005
    78
wenzelm@5005
    79
  fun print sg (ref {space, thms_tab, const_idx = _}) =
wenzelm@4853
    80
    let
wenzelm@6091
    81
      val prt_thm = Display.pretty_thm o Thm.transfer_sg sg;
wenzelm@4853
    82
      fun prt_thms (name, [th]) =
wenzelm@4853
    83
            Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt_thm th]
wenzelm@4853
    84
        | prt_thms (name, ths) = Pretty.big_list (name ^ ":") (map prt_thm ths);
wenzelm@3987
    85
wenzelm@5175
    86
      val thmss = sort_wrt fst (map (apfst (NameSpace.cond_extern space)) (Symtab.dest thms_tab));
wenzelm@4853
    87
    in
wenzelm@4853
    88
      Pretty.writeln (Display.pretty_name_space ("theorem name space", space));
wenzelm@4853
    89
      Pretty.writeln (Pretty.big_list "theorems:" (map prt_thms thmss))
wenzelm@4853
    90
    end;
wenzelm@3987
    91
end;
wenzelm@3987
    92
wenzelm@5005
    93
structure TheoremsData = TheoryDataFun(TheoremsDataArgs);
wenzelm@5005
    94
val get_theorems_sg = TheoremsData.get_sg;
wenzelm@5005
    95
val get_theorems = TheoremsData.get;
wenzelm@5005
    96
wenzelm@3987
    97
wenzelm@5000
    98
(* print theory *)
wenzelm@3987
    99
wenzelm@5005
   100
val print_theorems = TheoremsData.print;
wenzelm@5000
   101
fun print_theory thy =
wenzelm@5000
   102
  (Display.print_theory thy; print_theorems thy);
wenzelm@4022
   103
wenzelm@3987
   104
wenzelm@3987
   105
wenzelm@4022
   106
(** retrieve theorems **)
wenzelm@3987
   107
wenzelm@4922
   108
(* thms_closure *)
wenzelm@4922
   109
wenzelm@4922
   110
(*note: we avoid life references to the theory, so users may safely
wenzelm@5000
   111
  keep thms_closure with moderate space consumption*)
wenzelm@4022
   112
wenzelm@4922
   113
fun thms_closure_aux thy =
wenzelm@4922
   114
  let val ref {space, thms_tab, ...} = get_theorems thy
wenzelm@4922
   115
  in fn name => Symtab.lookup (thms_tab, NameSpace.intern space name) end;
wenzelm@4922
   116
wenzelm@4922
   117
fun thms_closure thy =
wenzelm@4922
   118
  let val closures = map thms_closure_aux (thy :: Theory.ancestors_of thy)
wenzelm@4922
   119
  in fn name => get_first (fn f => f name) closures end;
wenzelm@4022
   120
wenzelm@3987
   121
wenzelm@4783
   122
(* get_thms etc. *)
wenzelm@4037
   123
wenzelm@4922
   124
fun lookup_thms name thy = thms_closure_aux thy name;
wenzelm@4922
   125
wenzelm@6091
   126
fun get_thms thy name =
wenzelm@4922
   127
  (case get_first (lookup_thms name) (thy :: Theory.ancestors_of thy) of
wenzelm@4590
   128
    None => raise THEORY ("Unknown theorem(s) " ^ quote name, [thy])
wenzelm@4022
   129
  | Some thms => thms);
wenzelm@3987
   130
wenzelm@6091
   131
fun get_thm thy name =
wenzelm@6091
   132
  (case get_thms thy name of
wenzelm@3987
   133
    [thm] => thm
wenzelm@4590
   134
  | _ => raise THEORY ("Single theorem expected " ^ quote name, [thy]));
wenzelm@4022
   135
wenzelm@6091
   136
fun get_thmss thy names = flat (map (get_thms thy) names);
wenzelm@4783
   137
wenzelm@4022
   138
wenzelm@4022
   139
(* thms_of *)
wenzelm@4022
   140
wenzelm@6091
   141
fun attach_name thm = (Thm.name_of_thm thm, thm);
wenzelm@4022
   142
wenzelm@4022
   143
fun thms_of thy =
wenzelm@4022
   144
  let val ref {thms_tab, ...} = get_theorems thy in
wenzelm@4022
   145
    map attach_name (flat (map snd (Symtab.dest thms_tab)))
wenzelm@4022
   146
  end;
wenzelm@4022
   147
wenzelm@3987
   148
wenzelm@3987
   149
wenzelm@4022
   150
(** theorems indexed by constants **)
wenzelm@4022
   151
wenzelm@4022
   152
(* make index *)
wenzelm@4022
   153
wenzelm@4037
   154
val ignore = ["Trueprop", "all", "==>", "=="];
wenzelm@4022
   155
wenzelm@6091
   156
fun add_const_idx ((next, table), thm) =
wenzelm@4022
   157
  let
wenzelm@4022
   158
    val {hyps, prop, ...} = Thm.rep_thm thm;
wenzelm@4022
   159
    val consts =
wenzelm@4037
   160
      foldr add_term_consts (hyps, add_term_consts (prop, [])) \\ ignore;
wenzelm@4022
   161
wenzelm@4022
   162
    fun add (tab, c) =
wenzelm@6091
   163
      Symtab.update ((c, (next, thm) :: Symtab.lookup_multi (tab, c)), tab);
wenzelm@4022
   164
  in (next + 1, foldl add (table, consts)) end;
wenzelm@4022
   165
wenzelm@4022
   166
fun make_const_idx thm_tab =
wenzelm@5686
   167
  Symtab.foldl (fn (x, (_, ths)) => foldl add_const_idx (x, ths)) ((0, Symtab.empty), thm_tab);
wenzelm@4022
   168
wenzelm@4022
   169
wenzelm@4022
   170
(* lookup index *)
wenzelm@3987
   171
wenzelm@4022
   172
(*search locally*)
wenzelm@4022
   173
fun containing [] thy = thms_of thy
wenzelm@4022
   174
  | containing consts thy =
wenzelm@4022
   175
      let
wenzelm@4037
   176
        fun int ([], _) = []
wenzelm@4037
   177
          | int (_, []) = []
wenzelm@4037
   178
          | int (xxs as ((x as (i:int, _)) :: xs), yys as ((y as (j, _)) :: ys)) =
wenzelm@4037
   179
              if i = j then x :: int (xs, ys)
wenzelm@4037
   180
              else if i > j then int (xs, yys)
wenzelm@4037
   181
              else int (xxs, ys);
wenzelm@4022
   182
wenzelm@4037
   183
        fun ints [xs] = xs
wenzelm@4037
   184
          | ints xss = if exists null xss then [] else foldl int (hd xss, tl xss);
wenzelm@4022
   185
wenzelm@4022
   186
        val ref {const_idx = (_, ctab), ...} = get_theorems thy;
wenzelm@4022
   187
        val ithmss = map (fn c => Symtab.lookup_multi (ctab, c)) consts;
wenzelm@4022
   188
      in
wenzelm@4037
   189
        map (attach_name o snd) (ints ithmss)
wenzelm@4022
   190
      end;
wenzelm@4022
   191
wenzelm@4022
   192
(*search globally*)
wenzelm@4022
   193
fun thms_containing thy consts =
wenzelm@4037
   194
  flat (map (containing (consts \\ ignore)) (thy :: Theory.ancestors_of thy));
wenzelm@4022
   195
wenzelm@4022
   196
wenzelm@4022
   197
wenzelm@4022
   198
(** store theorems **)                    (*DESTRUCTIVE*)
wenzelm@3987
   199
wenzelm@4853
   200
(* naming *)
wenzelm@4853
   201
wenzelm@5933
   202
val defaultN = "it";
wenzelm@5933
   203
val default_name = fn "" => defaultN | name => name;
wenzelm@5907
   204
wenzelm@4853
   205
fun gen_names len name =
wenzelm@4853
   206
  map (fn i => name ^ "_" ^ string_of_int i) (1 upto len);
wenzelm@4853
   207
wenzelm@5907
   208
fun name_single name x = [(default_name name, x)];
wenzelm@5907
   209
fun name_multi name xs = gen_names (length xs) (default_name name) ~~ xs;
wenzelm@4853
   210
wenzelm@4853
   211
wenzelm@6091
   212
(* enter_thmx *)
wenzelm@4853
   213
wenzelm@5933
   214
fun cond_warning name msg = if Sign.base_name name = defaultN then () else warning msg;
wenzelm@5933
   215
wenzelm@3987
   216
fun warn_overwrite name =
wenzelm@5933
   217
  cond_warning name ("Replaced old copy of theorems " ^ quote name);
wenzelm@3987
   218
wenzelm@3987
   219
fun warn_same name =
wenzelm@5933
   220
  cond_warning name ("Theorem database already contains a copy of " ^ quote name);
wenzelm@3987
   221
wenzelm@6091
   222
fun enter_thmx sg app_name (bname, thmx) =
wenzelm@3987
   223
  let
wenzelm@4853
   224
    val name = Sign.full_name sg bname;
wenzelm@6091
   225
    val named_thms = map Thm.name_thm (app_name name thmx);
wenzelm@4022
   226
wenzelm@4022
   227
    val r as ref {space, thms_tab, const_idx} = get_theorems_sg sg;
wenzelm@4022
   228
wenzelm@4022
   229
    val overwrite =
wenzelm@4022
   230
      (case Symtab.lookup (thms_tab, name) of
wenzelm@4022
   231
        None => false
wenzelm@6091
   232
      | Some thms' =>
wenzelm@6091
   233
          if length thms' = length named_thms andalso forall2 Thm.eq_thm (thms', named_thms) then
wenzelm@4022
   234
            (warn_same name; false)
wenzelm@4022
   235
          else (warn_overwrite name; true));
wenzelm@4022
   236
wenzelm@4487
   237
    val space' = NameSpace.extend (space, [name]);
wenzelm@6091
   238
    val thms_tab' = Symtab.update ((name, named_thms), thms_tab);
wenzelm@4022
   239
    val const_idx' =
wenzelm@4022
   240
      if overwrite then make_const_idx thms_tab'
wenzelm@6091
   241
      else foldl add_const_idx (const_idx, named_thms);
wenzelm@3987
   242
  in
wenzelm@4022
   243
    r := {space = space', thms_tab = thms_tab', const_idx = const_idx'};
wenzelm@6091
   244
    named_thms
wenzelm@3987
   245
  end;
wenzelm@3987
   246
wenzelm@4853
   247
wenzelm@6091
   248
(* add_thms(s) *)
wenzelm@4853
   249
wenzelm@6091
   250
fun add_thmx app_name app_att ((bname, thmx), atts) thy =
wenzelm@5280
   251
  let
wenzelm@6091
   252
    val (thy', thmx') = app_att ((thy, thmx), atts);
wenzelm@6091
   253
    val thms'' = enter_thmx (Theory.sign_of thy') app_name (bname, thmx');
wenzelm@6091
   254
  in (thy', thms'') end;
wenzelm@4853
   255
wenzelm@6091
   256
fun add_thmxs name app = Library.apply o map (fst oo add_thmx name app);
wenzelm@5907
   257
wenzelm@6091
   258
val add_thms = add_thmxs name_single Thm.apply_attributes;
wenzelm@6091
   259
val add_thmss = add_thmxs name_multi Thm.applys_attributes;
wenzelm@5907
   260
wenzelm@5907
   261
wenzelm@6091
   262
(* have_thmss *)
wenzelm@5907
   263
wenzelm@6091
   264
fun have_thmss bname more_atts ths_atts thy =
wenzelm@5907
   265
  let
wenzelm@6091
   266
    fun app (x, (ths, atts)) = Thm.applys_attributes ((x, ths), atts);
wenzelm@6091
   267
    val (thy', thmss') =
wenzelm@5907
   268
      foldl_map app (thy, map (fn (ths, atts) => (ths, atts @ more_atts)) ths_atts);
wenzelm@6091
   269
    val thms'' = enter_thmx (Theory.sign_of thy') name_multi (bname, flat thmss');
wenzelm@6091
   270
  in (thy, thms'') end;
wenzelm@5280
   271
wenzelm@5280
   272
wenzelm@6091
   273
(* store_thm *)
wenzelm@5280
   274
wenzelm@6091
   275
fun store_thm th_atts thy =
wenzelm@6091
   276
  let val (thy', [th']) = add_thmx name_single Thm.apply_attributes th_atts thy
wenzelm@5280
   277
  in (thy', th') end;
wenzelm@3987
   278
wenzelm@3987
   279
wenzelm@4853
   280
(* smart_store_thm *)
wenzelm@3987
   281
wenzelm@4012
   282
fun smart_store_thm (name, thm) =
wenzelm@6091
   283
  hd (enter_thmx (Thm.sign_of_thm thm) name_single (name, thm));
wenzelm@3987
   284
wenzelm@3987
   285
wenzelm@4022
   286
(* store axioms as theorems *)
wenzelm@4022
   287
wenzelm@4853
   288
local
wenzelm@4853
   289
  fun add_ax app_name add ((name, axs), atts) thy =
wenzelm@4853
   290
    let
wenzelm@4853
   291
      val named_axs = app_name name axs;
wenzelm@4853
   292
      val thy' = add named_axs thy;
wenzelm@6091
   293
      val thms = map (Thm.get_axiom thy' o fst) named_axs;
wenzelm@6091
   294
    in add_thmss [((name, thms), atts)] thy' end;
wenzelm@4022
   295
wenzelm@5907
   296
  fun add_axs app_name add = Library.apply o map (add_ax app_name add);
wenzelm@4853
   297
in
wenzelm@4853
   298
  val add_axioms    = add_axs name_single Theory.add_axioms;
wenzelm@4853
   299
  val add_axioms_i  = add_axs name_single Theory.add_axioms_i;
wenzelm@4853
   300
  val add_axiomss   = add_axs name_multi Theory.add_axioms;
wenzelm@4853
   301
  val add_axiomss_i = add_axs name_multi Theory.add_axioms_i;
wenzelm@4853
   302
  val add_defs      = add_axs name_single Theory.add_defs;
wenzelm@4853
   303
  val add_defs_i    = add_axs name_single Theory.add_defs_i;
wenzelm@4853
   304
  val add_defss     = add_axs name_multi Theory.add_defs;
wenzelm@4853
   305
  val add_defss_i   = add_axs name_multi Theory.add_defs_i;
wenzelm@4853
   306
end;
wenzelm@4022
   307
wenzelm@4022
   308
wenzelm@3987
   309
wenzelm@4963
   310
(*** derived theory operations ***)
wenzelm@4963
   311
wenzelm@4963
   312
(** theory management **)
wenzelm@4963
   313
wenzelm@5005
   314
(* data kind 'Pure/theory_management' *)
wenzelm@4963
   315
wenzelm@5005
   316
structure TheoryManagementDataArgs =
wenzelm@5005
   317
struct
wenzelm@5005
   318
  val name = "Pure/theory_management";
wenzelm@5005
   319
  type T = {name: string, generation: int};
wenzelm@5000
   320
wenzelm@5005
   321
  val empty = {name = "", generation = 0};
wenzelm@5005
   322
  val prep_ext  = I;
wenzelm@5000
   323
  fun merge _ = empty;
wenzelm@5005
   324
  fun print _ _ = ();
wenzelm@4963
   325
end;
wenzelm@4963
   326
wenzelm@5005
   327
structure TheoryManagementData = TheoryDataFun(TheoryManagementDataArgs);
wenzelm@5005
   328
val get_info = TheoryManagementData.get;
wenzelm@5005
   329
val put_info = TheoryManagementData.put;
wenzelm@5005
   330
wenzelm@4963
   331
wenzelm@4963
   332
(* get / put name *)
wenzelm@4963
   333
wenzelm@5000
   334
val get_name = #name o get_info;
wenzelm@5000
   335
fun put_name name = put_info {name = name, generation = 0};
wenzelm@4963
   336
wenzelm@4963
   337
wenzelm@4963
   338
(* control prefixing of theory name *)
wenzelm@4963
   339
wenzelm@5210
   340
val global_path = Theory.root_path;
wenzelm@4963
   341
wenzelm@4963
   342
fun local_path thy =
wenzelm@5210
   343
  thy |> Theory.root_path |> Theory.add_path (get_name thy);
wenzelm@4963
   344
wenzelm@4963
   345
wenzelm@4963
   346
(* begin / end theory *)
wenzelm@4963
   347
wenzelm@4963
   348
fun begin_theory name thys =
wenzelm@4963
   349
  Theory.prep_ext_merge thys
wenzelm@4963
   350
  |> put_name name
wenzelm@4963
   351
  |> local_path;
wenzelm@4963
   352
wenzelm@4963
   353
fun end_theory thy = Theory.add_name (get_name thy) thy;
wenzelm@4963
   354
wenzelm@4963
   355
wenzelm@5000
   356
(* atomic transactions *)
wenzelm@5000
   357
wenzelm@5091
   358
exception ROLLBACK of theory * exn option;
wenzelm@5091
   359
wenzelm@5000
   360
fun transaction f thy =
wenzelm@5000
   361
  let
wenzelm@5000
   362
    val {name, generation} = get_info thy;
wenzelm@5000
   363
    val copy_thy =
wenzelm@5000
   364
      thy
wenzelm@5000
   365
      |> Theory.prep_ext
wenzelm@5005
   366
      |> Theory.add_name ("#" ^ name ^ ":" ^ string_of_int generation)  (* FIXME !!?? *)
wenzelm@5000
   367
      |> put_info {name = name, generation = generation + 1};
wenzelm@5026
   368
    val (thy', opt_exn) = (transform_error f thy, None) handle exn => (thy, Some exn);
wenzelm@5000
   369
  in
wenzelm@5091
   370
    if Sign.is_stale (Theory.sign_of thy') then raise ROLLBACK (copy_thy, opt_exn)
wenzelm@5091
   371
    else (case opt_exn of Some exn => raise exn | _ => thy')
wenzelm@5000
   372
  end;
wenzelm@5000
   373
wenzelm@5000
   374
wenzelm@4963
   375
wenzelm@4963
   376
(** add logical types **)
wenzelm@4922
   377
wenzelm@4922
   378
fun add_typedecls decls thy =
wenzelm@4922
   379
  let
wenzelm@4922
   380
    val full = Sign.full_name (Theory.sign_of thy);
wenzelm@4922
   381
wenzelm@4922
   382
    fun type_of (raw_name, vs, mx) =
wenzelm@4922
   383
      if null (duplicates vs) then (raw_name, length vs, mx)
wenzelm@4922
   384
      else error ("Duplicate parameters in type declaration: " ^ quote raw_name);
wenzelm@4922
   385
wenzelm@4922
   386
    fun arity_of (raw_name, len, mx) =
wenzelm@4922
   387
      (full (Syntax.type_name raw_name mx), replicate len logicS, logicS);
wenzelm@4922
   388
wenzelm@4922
   389
    val types = map type_of decls;
wenzelm@4922
   390
    val arities = map arity_of types;
wenzelm@4922
   391
  in
wenzelm@4922
   392
    thy
wenzelm@4922
   393
    |> Theory.add_types types
wenzelm@4922
   394
    |> Theory.add_arities_i arities
wenzelm@4922
   395
  end;
wenzelm@4922
   396
wenzelm@4922
   397
wenzelm@4922
   398
wenzelm@5091
   399
(*** the ProtoPure theory ***)
wenzelm@3987
   400
wenzelm@3987
   401
val proto_pure =
wenzelm@3987
   402
  Theory.pre_pure
wenzelm@5907
   403
  |> Library.apply [TheoremsData.init, TheoryManagementData.init]
wenzelm@4963
   404
  |> put_name "ProtoPure"
wenzelm@4963
   405
  |> global_path
wenzelm@3987
   406
  |> Theory.add_types
wenzelm@4922
   407
   [("fun", 2, NoSyn),
wenzelm@4922
   408
    ("prop", 0, NoSyn),
wenzelm@4922
   409
    ("itself", 1, NoSyn),
wenzelm@4922
   410
    ("dummy", 0, NoSyn)]
wenzelm@3987
   411
  |> Theory.add_classes_i [(logicC, [])]
wenzelm@3987
   412
  |> Theory.add_defsort_i logicS
wenzelm@3987
   413
  |> Theory.add_arities_i
wenzelm@3987
   414
   [("fun", [logicS, logicS], logicS),
wenzelm@3987
   415
    ("prop", [], logicS),
wenzelm@3987
   416
    ("itself", [logicS], logicS)]
wenzelm@4922
   417
  |> Theory.add_nonterminals Syntax.pure_nonterms
wenzelm@3987
   418
  |> Theory.add_syntax Syntax.pure_syntax
oheimb@6027
   419
  |> Theory.add_modesyntax ("symbols" , true) Syntax.pure_sym_syntax
oheimb@6027
   420
  |> Theory.add_modesyntax ("xsymbols", true) Syntax.pure_xsym_syntax
wenzelm@3987
   421
  |> Theory.add_trfuns Syntax.pure_trfuns
wenzelm@3987
   422
  |> Theory.add_trfunsT Syntax.pure_trfunsT
wenzelm@3987
   423
  |> Theory.add_syntax
wenzelm@3987
   424
   [("==>", "[prop, prop] => prop", Delimfix "op ==>")]
wenzelm@3987
   425
  |> Theory.add_consts
wenzelm@3987
   426
   [("==", "['a::{}, 'a] => prop", InfixrName ("==", 2)),
wenzelm@3987
   427
    ("=?=", "['a::{}, 'a] => prop", InfixrName ("=?=", 2)),
wenzelm@3987
   428
    ("==>", "[prop, prop] => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@3987
   429
    ("all", "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@4788
   430
    ("Goal", "prop => prop", Mixfix ("GOAL _", [999], 1000)),
wenzelm@3987
   431
    ("TYPE", "'a itself", NoSyn)]
nipkow@5041
   432
  |> Theory.add_modesyntax ("", false)
nipkow@5041
   433
    [("Goal", "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@4963
   434
  |> local_path
wenzelm@6091
   435
  |> (add_defs o map Thm.no_attributes)
wenzelm@4788
   436
   [("flexpair_def", "(t =?= u) == (t == u::'a::{})"),
wenzelm@4788
   437
    ("Goal_def", "GOAL (PROP A) == PROP A")]
wenzelm@4963
   438
  |> end_theory;
wenzelm@3987
   439
wenzelm@5091
   440
structure ProtoPure =
wenzelm@5091
   441
struct
wenzelm@5091
   442
  val thy = proto_pure;
wenzelm@5091
   443
  val flexpair_def = get_axiom thy "flexpair_def";
wenzelm@5091
   444
  val Goal_def = get_axiom thy "Goal_def";
wenzelm@5091
   445
end;
wenzelm@3987
   446
wenzelm@3987
   447
wenzelm@3987
   448
end;
wenzelm@3987
   449
wenzelm@3987
   450
wenzelm@4022
   451
structure BasicPureThy: BASIC_PURE_THY = PureThy;
wenzelm@4022
   452
open BasicPureThy;