src/Pure/pure_thy.ML
author wenzelm
Wed Apr 13 18:34:22 2005 +0200 (2005-04-13)
changeset 15703 727ef1b8b3ee
parent 15696 1da4ce092c0b
child 15715 dfa913c68f9d
permissions -rw-r--r--
*** empty log message ***
     1 (*  Title:      Pure/pure_thy.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Theorem database, derived theory operations, and the ProtoPure theory.
     6 *)
     7 
     8 signature BASIC_PURE_THY =
     9 sig
    10   type thmref
    11   val print_theorems: theory -> unit
    12   val print_theory: theory -> unit
    13   val get_thm: theory -> thmref -> thm
    14   val get_thms: theory -> thmref -> thm list
    15   val get_thmss: theory -> thmref list -> thm list
    16   val thms_of: theory -> (string * thm) list
    17   structure ProtoPure:
    18     sig
    19       val thy: theory
    20       val Goal_def: thm
    21     end
    22 end;
    23 
    24 signature PURE_THY =
    25 sig
    26   include BASIC_PURE_THY
    27   datatype interval = FromTo of int * int | From of int | Single of int
    28   val get_thm_closure: theory -> thmref -> thm
    29   val get_thms_closure: theory -> thmref -> thm list
    30   val single_thm: string -> thm list -> thm
    31   val select_thm: thmref -> thm list -> thm list
    32   val cond_extern_thm_sg: Sign.sg -> string -> xstring
    33   val thms_containing: theory -> string list * string list -> (string * thm list) list
    34   val thms_containing_consts: theory -> string list -> (string * thm) list
    35   val find_matching_thms: (thm -> thm list) * (term -> term)
    36         -> theory -> term -> (string * thm) list
    37   val find_intros: theory -> term -> (string * thm) list
    38   val find_intros_goal : theory -> thm -> int -> (string * thm) list
    39   val find_elims : theory -> term -> (string * thm) list
    40   val hide_thms: bool -> string list -> theory -> theory
    41   val store_thm: (bstring * thm) * theory attribute list -> theory -> theory * thm
    42   val smart_store_thms: (bstring * thm list) -> thm list
    43   val smart_store_thms_open: (bstring * thm list) -> thm list
    44   val forall_elim_var: int -> thm -> thm
    45   val forall_elim_vars: int -> thm -> thm
    46   val add_thms: ((bstring * thm) * theory attribute list) list -> theory -> theory * thm list
    47   val add_thmss: ((bstring * thm list) * theory attribute list) list -> theory
    48     -> theory * thm list list
    49   val note_thmss:
    50     theory attribute -> ((bstring * theory attribute list) *
    51     (thmref * theory attribute list) list) list -> theory ->
    52     theory * (bstring * thm list) list
    53   val note_thmss_i:
    54     theory attribute -> ((bstring * theory attribute list) *
    55     (thm list * theory attribute list) list) list -> theory ->
    56     theory * (bstring * thm list) list
    57   val note_thmss_accesses:
    58     (string -> string list) ->
    59     theory attribute -> ((bstring * theory attribute list) *
    60     (thmref * theory attribute list) list) list -> theory ->
    61     theory * (bstring * thm list) list
    62   val note_thmss_accesses_i:
    63     (string -> string list) ->
    64     theory attribute -> ((bstring * theory attribute list) *
    65     (thm list * theory attribute list) list) list -> theory ->
    66     theory * (bstring * thm list) list
    67   val add_axioms: ((bstring * string) * theory attribute list) list -> theory -> theory * thm list
    68   val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory * thm list
    69   val add_axiomss: ((bstring * string list) * theory attribute list) list -> theory
    70     -> theory * thm list list
    71   val add_axiomss_i: ((bstring * term list) * theory attribute list) list -> theory
    72     -> theory * thm list list
    73   val add_defs: bool -> ((bstring * string) * theory attribute list) list
    74     -> theory -> theory * thm list
    75   val add_defs_i: bool -> ((bstring * term) * theory attribute list) list
    76     -> theory -> theory * thm list
    77   val add_defss: bool -> ((bstring * string list) * theory attribute list) list
    78     -> theory -> theory * thm list list
    79   val add_defss_i: bool -> ((bstring * term list) * theory attribute list) list
    80     -> theory -> theory * thm list list
    81   val get_name: theory -> string
    82   val put_name: string -> theory -> theory
    83   val global_path: theory -> theory
    84   val local_path: theory -> theory
    85   val begin_theory: string -> theory list -> theory
    86   val end_theory: theory -> theory
    87   val checkpoint: theory -> theory
    88   val add_typedecls: (bstring * string list * mixfix) list -> theory -> theory
    89 end;
    90 
    91 structure PureThy: PURE_THY =
    92 struct
    93 
    94 
    95 (*** theorem database ***)
    96 
    97 (** data kind 'Pure/theorems' **)
    98 
    99 structure TheoremsDataArgs =
   100 struct
   101   val name = "Pure/theorems";
   102 
   103   type T =
   104     {space: NameSpace.T,
   105       thms_tab: thm list Symtab.table,
   106       index: FactIndex.T} ref;
   107 
   108   fun mk_empty _ =
   109     ref {space = NameSpace.empty, thms_tab = Symtab.empty, index = FactIndex.empty}: T;
   110 
   111   val empty = mk_empty ();
   112   fun copy (ref x) = ref x;
   113   val prep_ext = mk_empty;
   114   val merge = mk_empty;
   115 
   116   fun pretty sg (ref {space, thms_tab, index = _}) =
   117     let
   118       val prt_thm = Display.pretty_thm_sg sg;
   119       fun prt_thms (name, [th]) =
   120             Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt_thm th]
   121         | prt_thms (name, ths) = Pretty.big_list (name ^ ":") (map prt_thm ths);
   122 
   123       val thmss = NameSpace.cond_extern_table space thms_tab;
   124     in Pretty.big_list "theorems:" (map prt_thms thmss) end;
   125 
   126   fun print sg data = Pretty.writeln (pretty sg data);
   127 end;
   128 
   129 structure TheoremsData = TheoryDataFun(TheoremsDataArgs);
   130 val get_theorems_sg = TheoremsData.get_sg;
   131 val get_theorems = TheoremsData.get;
   132 
   133 val cond_extern_thm_sg = NameSpace.cond_extern o #space o ! o get_theorems_sg;
   134 
   135 
   136 (* print theory *)
   137 
   138 val print_theorems = TheoremsData.print;
   139 
   140 fun print_theory thy =
   141   Display.pretty_full_theory thy @
   142   [TheoremsDataArgs.pretty (Theory.sign_of thy) (get_theorems thy)]
   143   |> Pretty.chunks |> Pretty.writeln;
   144 
   145 
   146 
   147 (** retrieve theorems **)
   148 
   149 fun the_thms _ (SOME thms) = thms
   150   | the_thms name NONE = error ("Unknown theorem(s) " ^ quote name);
   151 
   152 fun single_thm _ [thm] = thm
   153   | single_thm name _ = error ("Single theorem expected " ^ quote name);
   154 
   155 
   156 (* selections *)
   157 
   158 datatype interval =
   159   FromTo of int * int |
   160   From of int |
   161   Single of int;
   162 
   163 type thmref = xstring * interval list option;
   164 
   165 local
   166 
   167 fun interval _ (FromTo (i, j)) = i upto j
   168   | interval n (From i) = i upto n
   169   | interval _ (Single i) = [i];
   170 
   171 fun select name thms n i =
   172   if i < 1 orelse i > n then
   173     error ("Bad subscript " ^ string_of_int i ^ " for " ^
   174       quote name ^ " (length " ^ string_of_int n ^ ")")
   175   else List.nth (thms, i - 1);
   176 
   177 in
   178 
   179 fun select_thm (_, NONE) thms = thms
   180   | select_thm (name, SOME is) thms =
   181       let val n = length thms
   182       in map (select name thms n) (List.concat (map (interval n) is)) end;
   183 
   184 end;
   185 
   186 
   187 (* get_thm(s)_closure -- statically scoped versions *)
   188 
   189 (*beware of proper order of evaluation!*)
   190 
   191 fun lookup_thms thy =
   192   let
   193     val sg_ref = Sign.self_ref (Theory.sign_of thy);
   194     val ref {space, thms_tab, ...} = get_theorems thy;
   195   in
   196     fn name =>
   197       Option.map (map (Thm.transfer_sg (Sign.deref sg_ref)))        (*semi-dynamic identity*)
   198       (Symtab.lookup (thms_tab, NameSpace.intern space name))   (*static content*)
   199   end;
   200 
   201 fun get_thms_closure thy =
   202   let val closures = map lookup_thms (thy :: Theory.ancestors_of thy)
   203   in fn namei as (name, _) => select_thm namei
   204     (the_thms name (get_first (fn f => f name) closures))
   205   end;
   206 
   207 fun get_thm_closure thy =
   208   let val get = get_thms_closure thy
   209   in fn namei as (name, _) => single_thm name (get namei) end;
   210 
   211 
   212 (* get_thm etc. *)
   213 
   214 fun get_thms theory (namei as (name, _)) =
   215   get_first (fn thy => lookup_thms thy name) (theory :: Theory.ancestors_of theory)
   216   |> the_thms name |> select_thm namei |> map (Thm.transfer theory);
   217 
   218 fun get_thmss thy names = List.concat (map (get_thms thy) names);
   219 fun get_thm thy (namei as (name, _)) = single_thm name (get_thms thy namei);
   220 
   221 
   222 (* thms_of *)
   223 
   224 fun thms_of thy =
   225   let val ref {thms_tab, ...} = get_theorems thy in
   226     map (fn th => (Thm.name_of_thm th, th)) (List.concat (map snd (Symtab.dest thms_tab)))
   227   end;
   228 
   229 
   230 (* thms_containing *)
   231 
   232 fun thms_containing thy idx =
   233   let
   234     fun valid (name, ths) =
   235       (case try (transform_error (get_thms thy)) (name, NONE) of
   236         NONE => false
   237       | SOME ths' => Library.equal_lists Thm.eq_thm (ths, ths'));
   238   in
   239     (thy :: Theory.ancestors_of thy)
   240     |> map (gen_distinct eq_fst o List.filter valid o FactIndex.find idx o #index o ! o get_theorems)
   241     |> List.concat
   242   end;
   243 
   244 fun thms_containing_consts thy consts =
   245   thms_containing thy (consts, []) |> map #2 |> List.concat
   246   |> map (fn th => (Thm.name_of_thm th, th))
   247 
   248 
   249 (* intro/elim theorems *)
   250 
   251 (* intro: given a goal state, find a suitable intro rule for some subgoal *)
   252 (* elim: given a theorem thm,
   253          find a theorem whose major premise eliminates the conclusion of thm *)
   254 
   255 fun top_const t = (case head_of t of Const (c, _) => SOME c | _ => NONE);
   256 
   257 (* This is a hack to remove the Trueprop constant that most logics use *)
   258 fun rem_top (_ $ t) = t
   259   | rem_top _ = Bound 0 (* does not match anything *)
   260 
   261 (*returns all those named_thms whose subterm extracted by extract can be
   262   instantiated to obj; the list is sorted according to the number of premises
   263   and the size of the required substitution.*)
   264 fun select_match(c,obj, signobj, named_thms, (extract_thms,extract_term)) =
   265   let val tsig = Sign.tsig_of signobj
   266       fun matches prop =
   267         let val pat = extract_term prop
   268         in case head_of pat of
   269              Const(d,_) => c=d andalso Pattern.matches tsig (pat,obj)
   270            | _ => false
   271         end
   272 
   273       fun substsize prop =
   274             let val pat = extract_term prop
   275                 val (_,subst) = Pattern.match tsig (pat,obj)
   276             in Library.foldl op+ (0, map (size_of_term o snd) subst) end
   277 
   278       fun thm_ord ((p0,s0,_),(p1,s1,_)) =
   279             prod_ord (int_ord o pairself (fn 0 => 0 | x => 1)) int_ord ((p0,s0),(p1,s1));
   280 
   281       fun select((p as (_,thm))::named_thms, sels) =
   282             let
   283               fun sel(thm::thms,sels) =     
   284                     let val {prop, ...} = rep_thm thm
   285                     in if matches prop
   286                        then (nprems_of thm,substsize prop,p)::sels
   287                        else sel(thms,sels)
   288                     end
   289                 | sel([],sels) = sels
   290              val {sign, ...} = rep_thm thm
   291            in select(named_thms,if Sign.subsig(sign, signobj)
   292                                 then sel(extract_thms thm,sels)
   293                                 else sels)
   294            end
   295         | select([],sels) = sels
   296 
   297   in map (fn (_,_,t) => t) (sort thm_ord (select(named_thms, []))) end;
   298 
   299 fun find_matching_thms extract thy prop =
   300   (case top_const prop of NONE => []
   301    | SOME c => let val thms = thms_containing_consts thy [c]
   302                in select_match(c,prop,Theory.sign_of thy,thms,extract) end)
   303 
   304 val find_intros =
   305   find_matching_thms (single, rem_top o Logic.strip_imp_concl)
   306 
   307 fun find_intros_goal thy st i =
   308   find_intros thy (rem_top(Logic.concl_of_goal (prop_of st) i));
   309 
   310 val find_elims = find_matching_thms
   311   (fn thm => if Thm.no_prems thm then [] else [thm],
   312    rem_top o hd o Logic.strip_imp_prems)
   313 
   314 
   315 (** store theorems **)                    (*DESTRUCTIVE*)
   316 
   317 (* hiding -- affects current theory node only! *)
   318 
   319 fun hide_thms fully names thy =
   320   let
   321     val r as ref {space, thms_tab, index} = get_theorems thy;
   322     val space' = NameSpace.hide fully (space, names);
   323   in r := {space = space', thms_tab = thms_tab, index = index}; thy end;
   324 
   325 
   326 (* naming *)
   327 
   328 fun gen_names j len name =
   329   map (fn i => name ^ "_" ^ string_of_int i) (j+1 upto j+len);
   330 
   331 fun name_multi name xs = gen_names 0 (length xs) name ~~ xs;
   332 
   333 fun name_thm pre (p as (_, thm)) =
   334   if Thm.name_of_thm thm <> "" andalso pre then thm else Thm.name_thm p;
   335 
   336 fun name_thms pre name [x] = [name_thm pre (name, x)]
   337   | name_thms pre name xs = map (name_thm pre) (name_multi name xs);
   338 
   339 fun name_thmss name xs = (case filter_out (null o fst) xs of
   340     [([x], z)] => [([name_thm true (name, x)], z)]
   341   | _ => snd (foldl_map (fn (i, (ys, z)) => (i + length ys,
   342   (map (name_thm true) (gen_names i (length ys) name ~~ ys), z))) (0, xs)));
   343 
   344 
   345 (* enter_thms *)
   346 
   347 fun warn_overwrite name = warning ("Replaced old copy of theorems " ^ quote name);
   348 fun warn_same name = warning ("Theorem database already contains a copy of " ^ quote name);
   349 
   350 fun gen_enter_thms _ _ _ _ _ app_att thy ("", thms) = app_att (thy, thms)
   351   | gen_enter_thms full acc sg pre_name post_name app_att thy (bname, thms) =
   352       let
   353         val name = full sg bname;
   354         val (thy', thms') = app_att (thy, pre_name name thms);
   355         val named_thms = post_name name thms';
   356 
   357         val r as ref {space, thms_tab, index} = get_theorems_sg sg;
   358         val space' = NameSpace.extend' acc (space, [name]);
   359         val thms_tab' = Symtab.update ((name, named_thms), thms_tab);
   360         val index' = FactIndex.add (K false) (index, (name, named_thms));
   361       in
   362         (case Symtab.lookup (thms_tab, name) of
   363           NONE => ()
   364         | SOME thms' =>
   365             if Library.equal_lists Thm.eq_thm (thms', named_thms) then warn_same name
   366             else warn_overwrite name);
   367         r := {space = space', thms_tab = thms_tab', index = index'};
   368         (thy', named_thms)
   369       end;
   370 
   371 fun enter_thms sg = gen_enter_thms Sign.full_name NameSpace.accesses sg;
   372 
   373 (* add_thms(s) *)
   374 
   375 fun add_thms_atts pre_name ((bname, thms), atts) thy =
   376   enter_thms (Theory.sign_of thy) pre_name (name_thms false)
   377     (Thm.applys_attributes o rpair atts) thy (bname, thms);
   378 
   379 fun gen_add_thmss pre_name args theory =
   380   foldl_map (fn (thy, arg) => add_thms_atts pre_name arg thy) (theory, args);
   381 
   382 fun gen_add_thms pre_name args =
   383   apsnd (map hd) o gen_add_thmss pre_name (map (apfst (apsnd single)) args);
   384 
   385 val add_thmss = gen_add_thmss (name_thms true);
   386 val add_thms = gen_add_thms (name_thms true);
   387 
   388 
   389 (* note_thmss(_i) *)
   390 
   391 local
   392 
   393 fun gen_note_thss enter get kind_att (thy, ((bname, more_atts), ths_atts)) =
   394   let
   395     fun app (x, (ths, atts)) = Thm.applys_attributes ((x, ths), atts);
   396     val (thy', thms) = enter (Theory.sign_of thy)
   397       name_thmss (name_thms false) (apsnd List.concat o foldl_map app) thy
   398       (bname, map (fn (ths, atts) => (get thy ths, atts @ more_atts @ [kind_att])) ths_atts);
   399   in (thy', (bname, thms)) end;
   400 
   401 fun gen_note_thmss enter get kind_att args thy =
   402   foldl_map (gen_note_thss enter get kind_att) (thy, args);
   403 
   404 in
   405 
   406 (* if path is set, only permit unqualified names *)
   407 
   408 val note_thmss = gen_note_thmss enter_thms get_thms;
   409 val note_thmss_i = gen_note_thmss enter_thms (K I);
   410 
   411 (* always permit qualified names,
   412    clients may specify non-standard access policy *)
   413 
   414 fun note_thmss_accesses acc =
   415   gen_note_thmss (gen_enter_thms Sign.full_name' acc) get_thms;
   416 fun note_thmss_accesses_i acc =
   417   gen_note_thmss (gen_enter_thms Sign.full_name' acc) (K I);
   418 
   419 end;
   420 
   421 
   422 (* store_thm *)
   423 
   424 fun store_thm ((bname, thm), atts) thy =
   425   let val (thy', [th']) = add_thms_atts (name_thms true) ((bname, [thm]), atts) thy
   426   in (thy', th') end;
   427 
   428 
   429 (* smart_store_thms *)
   430 
   431 fun gen_smart_store_thms _ (name, []) =
   432       error ("Cannot store empty list of theorems: " ^ quote name)
   433   | gen_smart_store_thms name_thm (name, [thm]) =
   434       snd (enter_thms (Thm.sign_of_thm thm) (name_thm true) (name_thm false)
   435         I () (name, [thm]))
   436   | gen_smart_store_thms name_thm (name, thms) =
   437       let
   438         val merge_sg = Sign.merge_refs o apsnd (Sign.self_ref o Thm.sign_of_thm);
   439         val sg_ref = Library.foldl merge_sg (Sign.self_ref (Thm.sign_of_thm (hd thms)), tl thms);
   440       in snd (enter_thms (Sign.deref sg_ref) (name_thm true) (name_thm false)
   441         I () (name, thms))
   442       end;
   443 
   444 val smart_store_thms = gen_smart_store_thms name_thms;
   445 val smart_store_thms_open = gen_smart_store_thms (K (K I));
   446 
   447 
   448 (* forall_elim_vars (belongs to drule.ML) *)
   449 
   450 (*Replace outermost quantified variable by Var of given index.*)
   451 fun forall_elim_var i th =
   452     let val {prop,sign,...} = rep_thm th
   453     in case prop of
   454         Const ("all", _) $ Abs (a, T, _) =>
   455           let val used = map (fst o fst)
   456             (List.filter (equal i o snd o fst) (Term.add_vars ([], prop)))
   457           in forall_elim (cterm_of sign (Var ((variant used a, i), T))) th end
   458       | _ => raise THM ("forall_elim_var", i, [th])
   459     end;
   460 
   461 (*Repeat forall_elim_var until all outer quantifiers are removed*)
   462 fun forall_elim_vars i th =
   463     forall_elim_vars i (forall_elim_var i th)
   464         handle THM _ => th;
   465 
   466 
   467 (* store axioms as theorems *)
   468 
   469 local
   470   fun get_axs thy named_axs =
   471     map (forall_elim_vars 0 o Thm.get_axiom thy o fst) named_axs;
   472 
   473   fun add_single add (thy, ((name, ax), atts)) =
   474     let
   475       val named_ax = [(name, ax)];
   476       val thy' = add named_ax thy;
   477       val thm = hd (get_axs thy' named_ax);
   478     in apsnd hd (gen_add_thms (K I) [((name, thm), atts)] thy') end;
   479 
   480   fun add_multi add (thy, ((name, axs), atts)) =
   481     let
   482       val named_axs = name_multi name axs;
   483       val thy' = add named_axs thy;
   484       val thms = get_axs thy' named_axs;
   485     in apsnd hd (gen_add_thmss (K I) [((name, thms), atts)] thy') end;
   486 
   487   fun add_singles add args thy = foldl_map (add_single add) (thy, args);
   488   fun add_multis add args thy = foldl_map (add_multi add) (thy, args);
   489 in
   490   val add_axioms    = add_singles Theory.add_axioms;
   491   val add_axioms_i  = add_singles Theory.add_axioms_i;
   492   val add_axiomss   = add_multis Theory.add_axioms;
   493   val add_axiomss_i = add_multis Theory.add_axioms_i;
   494   val add_defs      = add_singles o Theory.add_defs;
   495   val add_defs_i    = add_singles o Theory.add_defs_i;
   496   val add_defss     = add_multis o Theory.add_defs;
   497   val add_defss_i   = add_multis o Theory.add_defs_i;
   498 end;
   499 
   500 
   501 
   502 (*** derived theory operations ***)
   503 
   504 (** theory management **)
   505 
   506 (* data kind 'Pure/theory_management' *)
   507 
   508 structure TheoryManagementDataArgs =
   509 struct
   510   val name = "Pure/theory_management";
   511   type T = {name: string, version: int};
   512 
   513   val empty = {name = "", version = 0};
   514   val copy = I;
   515   val prep_ext  = I;
   516   fun merge _ = empty;
   517   fun print _ _ = ();
   518 end;
   519 
   520 structure TheoryManagementData = TheoryDataFun(TheoryManagementDataArgs);
   521 val get_info = TheoryManagementData.get;
   522 val put_info = TheoryManagementData.put;
   523 
   524 
   525 (* get / put name *)
   526 
   527 val get_name = #name o get_info;
   528 fun put_name name = put_info {name = name, version = 0};
   529 
   530 
   531 (* control prefixing of theory name *)
   532 
   533 val global_path = Theory.root_path;
   534 
   535 fun local_path thy =
   536   thy |> Theory.root_path |> Theory.add_path (get_name thy);
   537 
   538 
   539 (* begin / end theory *)
   540 
   541 fun begin_theory name thys =
   542   Theory.prep_ext_merge thys
   543   |> put_name name
   544   |> local_path;
   545 
   546 fun end_theory thy =
   547   thy
   548   |> Theory.add_name (get_name thy);
   549 
   550 fun checkpoint thy =
   551   if is_draft thy then
   552     let val {name, version} = get_info thy in
   553       thy
   554       |> Theory.add_name (name ^ ":" ^ string_of_int version)
   555       |> put_info {name = name, version = version + 1}
   556     end
   557   else thy;
   558 
   559 
   560 
   561 (** add logical types **)
   562 
   563 fun add_typedecls decls thy =
   564   let
   565     val full = Sign.full_name (Theory.sign_of thy);
   566 
   567     fun type_of (raw_name, vs, mx) =
   568       if null (duplicates vs) then (raw_name, length vs, mx)
   569       else error ("Duplicate parameters in type declaration: " ^ quote raw_name);
   570   in thy |> Theory.add_types (map type_of decls) end;
   571 
   572 
   573 
   574 (*** the ProtoPure theory ***)
   575 
   576 
   577 (*It might make sense to restrict the polymorphism of the constant "==" to
   578   sort logic, instead of the universal sort, {}.  Unfortunately, this change
   579   causes HOL/Import/shuffler.ML to fail.*)
   580 
   581 val proto_pure =
   582   Theory.pre_pure
   583   |> Library.apply [TheoremsData.init, TheoryManagementData.init, Proofterm.init]
   584   |> put_name "ProtoPure"
   585   |> global_path
   586   |> Theory.add_types
   587    [("fun", 2, NoSyn),
   588     ("prop", 0, NoSyn),
   589     ("itself", 1, NoSyn),
   590     ("dummy", 0, NoSyn)]
   591   |> Theory.add_nonterminals Syntax.pure_nonterms
   592   |> Theory.add_syntax Syntax.pure_syntax
   593   |> Theory.add_modesyntax (Symbol.xsymbolsN, true) Syntax.pure_xsym_syntax
   594   |> Theory.add_syntax
   595    [("==>", "[prop, prop] => prop", Delimfix "op ==>"),
   596     (Term.dummy_patternN, "aprop", Delimfix "'_")]
   597   |> Theory.add_consts
   598    [("==", "['a, 'a] => prop", InfixrName ("==", 2)),
   599     ("==>", "[prop, prop] => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   600     ("all", "('a => prop) => prop", Binder ("!!", 0, 0)),
   601     ("Goal", "prop => prop", NoSyn),
   602     ("TYPE", "'a itself", NoSyn),
   603     (Term.dummy_patternN, "'a", Delimfix "'_")]
   604   |> Theory.add_finals_i false
   605     [Const("==", [TFree ("'a", []), TFree ("'a", [])] ---> propT),
   606      Const("==>", [propT, propT] ---> propT),
   607      Const("all", (TFree("'a", []) --> propT) --> propT),
   608      Const("TYPE", a_itselfT)]
   609   |> Theory.add_modesyntax ("", false)
   610     (Syntax.pure_syntax_output @ Syntax.pure_appl_syntax)
   611   |> Theory.add_trfuns Syntax.pure_trfuns
   612   |> Theory.add_trfunsT Syntax.pure_trfunsT
   613   |> local_path
   614   |> (#1 oo (add_defs_i false o map Thm.no_attributes))
   615    [("Goal_def", let val A = Free ("A", propT) in Logic.mk_equals (Logic.mk_goal A, A) end)]
   616   |> (#1 o add_thmss [(("nothing", []), [])])
   617   |> Theory.add_axioms_i Proofterm.equality_axms
   618   |> end_theory;
   619 
   620 structure ProtoPure =
   621 struct
   622   val thy = proto_pure;
   623   val Goal_def = get_axiom thy "Goal_def";
   624 end;
   625 
   626 
   627 end;
   628 
   629 
   630 structure BasicPureThy: BASIC_PURE_THY = PureThy;
   631 open BasicPureThy;