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