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