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