src/Pure/pure_thy.ML
author berghofe
Thu Apr 21 19:12:03 2005 +0200 (2005-04-21)
changeset 15797 a63605582573
parent 15715 dfa913c68f9d
child 15801 d2f5ca3c048d
permissions -rw-r--r--
- Eliminated nodup_vars check.
- Unification and matching functions now check types of term variables / sorts
of type variables when applying a substitution.
- Thm.instantiate now takes (ctyp * ctyp) list instead of (indexname * ctyp) list
as argument, to allow for proper instantiation of theorems containing
type variables with same name but different sorts.
     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 Vartab.foldl (op + o apsnd (size_of_term o snd o snd)) (0, subst)
   277             end
   278 
   279       fun thm_ord ((p0,s0,_),(p1,s1,_)) =
   280             prod_ord (int_ord o pairself (fn 0 => 0 | x => 1)) int_ord ((p0,s0),(p1,s1));
   281 
   282       fun select((p as (_,thm))::named_thms, sels) =
   283             let
   284               fun sel(thm::thms,sels) =     
   285                     let val {prop, ...} = rep_thm thm
   286                     in if matches prop
   287                        then (nprems_of thm,substsize prop,p)::sels
   288                        else sel(thms,sels)
   289                     end
   290                 | sel([],sels) = sels
   291              val {sign, ...} = rep_thm thm
   292            in select(named_thms,if Sign.subsig(sign, signobj)
   293                                 then sel(extract_thms thm,sels)
   294                                 else sels)
   295            end
   296         | select([],sels) = sels
   297 
   298   in map (fn (_,_,t) => t) (sort thm_ord (select(named_thms, []))) end;
   299 
   300 fun find_matching_thms extract thy prop =
   301   (case top_const prop of NONE => []
   302    | SOME c => let val thms = thms_containing_consts thy [c]
   303                in select_match(c,prop,Theory.sign_of thy,thms,extract) end)
   304 
   305 val find_intros =
   306   find_matching_thms (single, rem_top o Logic.strip_imp_concl)
   307 
   308 fun find_intros_goal thy st i =
   309   find_intros thy (rem_top(Logic.concl_of_goal (prop_of st) i));
   310 
   311 val find_elims = find_matching_thms
   312   (fn thm => if Thm.no_prems thm then [] else [thm],
   313    rem_top o hd o Logic.strip_imp_prems)
   314 
   315 
   316 (** store theorems **)                    (*DESTRUCTIVE*)
   317 
   318 (* hiding -- affects current theory node only! *)
   319 
   320 fun hide_thms fully names thy =
   321   let
   322     val r as ref {space, thms_tab, index} = get_theorems thy;
   323     val space' = NameSpace.hide fully (space, names);
   324   in r := {space = space', thms_tab = thms_tab, index = index}; thy end;
   325 
   326 
   327 (* naming *)
   328 
   329 fun gen_names j len name =
   330   map (fn i => name ^ "_" ^ string_of_int i) (j+1 upto j+len);
   331 
   332 fun name_multi name xs = gen_names 0 (length xs) name ~~ xs;
   333 
   334 fun name_thm pre (p as (_, thm)) =
   335   if Thm.name_of_thm thm <> "" andalso pre then thm else Thm.name_thm p;
   336 
   337 fun name_thms pre name [x] = [name_thm pre (name, x)]
   338   | name_thms pre name xs = map (name_thm pre) (name_multi name xs);
   339 
   340 fun name_thmss name xs = (case filter_out (null o fst) xs of
   341     [([x], z)] => [([name_thm true (name, x)], z)]
   342   | _ => snd (foldl_map (fn (i, (ys, z)) => (i + length ys,
   343   (map (name_thm true) (gen_names i (length ys) name ~~ ys), z))) (0, xs)));
   344 
   345 
   346 (* enter_thms *)
   347 
   348 fun warn_overwrite name = warning ("Replaced old copy of theorems " ^ quote name);
   349 fun warn_same name = warning ("Theorem database already contains a copy of " ^ quote name);
   350 
   351 fun gen_enter_thms _ _ _ _ _ app_att thy ("", thms) = app_att (thy, thms)
   352   | gen_enter_thms full acc sg pre_name post_name app_att thy (bname, thms) =
   353       let
   354         val name = full sg bname;
   355         val (thy', thms') = app_att (thy, pre_name name thms);
   356         val named_thms = post_name name thms';
   357 
   358         val r as ref {space, thms_tab, index} = get_theorems_sg sg;
   359         val space' = NameSpace.extend' acc (space, [name]);
   360         val thms_tab' = Symtab.update ((name, named_thms), thms_tab);
   361         val index' = FactIndex.add (K false) (index, (name, named_thms));
   362       in
   363         (case Symtab.lookup (thms_tab, name) of
   364           NONE => ()
   365         | SOME thms' =>
   366             if Library.equal_lists Thm.eq_thm (thms', named_thms) then warn_same name
   367             else warn_overwrite name);
   368         r := {space = space', thms_tab = thms_tab', index = index'};
   369         (thy', named_thms)
   370       end;
   371 
   372 fun enter_thms sg = gen_enter_thms Sign.full_name NameSpace.accesses sg;
   373 
   374 (* add_thms(s) *)
   375 
   376 fun add_thms_atts pre_name ((bname, thms), atts) thy =
   377   enter_thms (Theory.sign_of thy) pre_name (name_thms false)
   378     (Thm.applys_attributes o rpair atts) thy (bname, thms);
   379 
   380 fun gen_add_thmss pre_name args theory =
   381   foldl_map (fn (thy, arg) => add_thms_atts pre_name arg thy) (theory, args);
   382 
   383 fun gen_add_thms pre_name args =
   384   apsnd (map hd) o gen_add_thmss pre_name (map (apfst (apsnd single)) args);
   385 
   386 val add_thmss = gen_add_thmss (name_thms true);
   387 val add_thms = gen_add_thms (name_thms true);
   388 
   389 
   390 (* note_thmss(_i) *)
   391 
   392 local
   393 
   394 fun gen_note_thss enter get kind_att (thy, ((bname, more_atts), ths_atts)) =
   395   let
   396     fun app (x, (ths, atts)) = Thm.applys_attributes ((x, ths), atts);
   397     val (thy', thms) = enter (Theory.sign_of thy)
   398       name_thmss (name_thms false) (apsnd List.concat o foldl_map app) thy
   399       (bname, map (fn (ths, atts) => (get thy ths, atts @ more_atts @ [kind_att])) ths_atts);
   400   in (thy', (bname, thms)) end;
   401 
   402 fun gen_note_thmss enter get kind_att args thy =
   403   foldl_map (gen_note_thss enter get kind_att) (thy, args);
   404 
   405 in
   406 
   407 (* if path is set, only permit unqualified names *)
   408 
   409 val note_thmss = gen_note_thmss enter_thms get_thms;
   410 val note_thmss_i = gen_note_thmss enter_thms (K I);
   411 
   412 (* always permit qualified names,
   413    clients may specify non-standard access policy *)
   414 
   415 fun note_thmss_accesses acc =
   416   gen_note_thmss (gen_enter_thms Sign.full_name' acc) get_thms;
   417 fun note_thmss_accesses_i acc =
   418   gen_note_thmss (gen_enter_thms Sign.full_name' acc) (K I);
   419 
   420 end;
   421 
   422 
   423 (* store_thm *)
   424 
   425 fun store_thm ((bname, thm), atts) thy =
   426   let val (thy', [th']) = add_thms_atts (name_thms true) ((bname, [thm]), atts) thy
   427   in (thy', th') end;
   428 
   429 
   430 (* smart_store_thms *)
   431 
   432 fun gen_smart_store_thms _ (name, []) =
   433       error ("Cannot store empty list of theorems: " ^ quote name)
   434   | gen_smart_store_thms name_thm (name, [thm]) =
   435       snd (enter_thms (Thm.sign_of_thm thm) (name_thm true) (name_thm false)
   436         I () (name, [thm]))
   437   | gen_smart_store_thms name_thm (name, thms) =
   438       let
   439         val merge_sg = Sign.merge_refs o apsnd (Sign.self_ref o Thm.sign_of_thm);
   440         val sg_ref = Library.foldl merge_sg (Sign.self_ref (Thm.sign_of_thm (hd thms)), tl thms);
   441       in snd (enter_thms (Sign.deref sg_ref) (name_thm true) (name_thm false)
   442         I () (name, thms))
   443       end;
   444 
   445 val smart_store_thms = gen_smart_store_thms name_thms;
   446 val smart_store_thms_open = gen_smart_store_thms (K (K I));
   447 
   448 
   449 (* forall_elim_vars (belongs to drule.ML) *)
   450 
   451 (*Replace outermost quantified variable by Var of given index.*)
   452 fun forall_elim_var i th =
   453     let val {prop,sign,...} = rep_thm th
   454     in case prop of
   455         Const ("all", _) $ Abs (a, T, _) =>
   456           let val used = map (fst o fst)
   457             (List.filter (equal i o snd o fst) (Term.add_vars ([], prop)))
   458           in forall_elim (cterm_of sign (Var ((variant used a, i), T))) th end
   459       | _ => raise THM ("forall_elim_var", i, [th])
   460     end;
   461 
   462 (*Repeat forall_elim_var until all outer quantifiers are removed*)
   463 fun forall_elim_vars i th =
   464     forall_elim_vars i (forall_elim_var i th)
   465         handle THM _ => th;
   466 
   467 
   468 (* store axioms as theorems *)
   469 
   470 local
   471   fun get_axs thy named_axs =
   472     map (forall_elim_vars 0 o Thm.get_axiom thy o fst) named_axs;
   473 
   474   fun add_single add (thy, ((name, ax), atts)) =
   475     let
   476       val named_ax = [(name, ax)];
   477       val thy' = add named_ax thy;
   478       val thm = hd (get_axs thy' named_ax);
   479     in apsnd hd (gen_add_thms (K I) [((name, thm), atts)] thy') end;
   480 
   481   fun add_multi add (thy, ((name, axs), atts)) =
   482     let
   483       val named_axs = name_multi name axs;
   484       val thy' = add named_axs thy;
   485       val thms = get_axs thy' named_axs;
   486     in apsnd hd (gen_add_thmss (K I) [((name, thms), atts)] thy') end;
   487 
   488   fun add_singles add args thy = foldl_map (add_single add) (thy, args);
   489   fun add_multis add args thy = foldl_map (add_multi add) (thy, args);
   490 in
   491   val add_axioms    = add_singles Theory.add_axioms;
   492   val add_axioms_i  = add_singles Theory.add_axioms_i;
   493   val add_axiomss   = add_multis Theory.add_axioms;
   494   val add_axiomss_i = add_multis Theory.add_axioms_i;
   495   val add_defs      = add_singles o Theory.add_defs;
   496   val add_defs_i    = add_singles o Theory.add_defs_i;
   497   val add_defss     = add_multis o Theory.add_defs;
   498   val add_defss_i   = add_multis o Theory.add_defs_i;
   499 end;
   500 
   501 
   502 
   503 (*** derived theory operations ***)
   504 
   505 (** theory management **)
   506 
   507 (* data kind 'Pure/theory_management' *)
   508 
   509 structure TheoryManagementDataArgs =
   510 struct
   511   val name = "Pure/theory_management";
   512   type T = {name: string, version: int};
   513 
   514   val empty = {name = "", version = 0};
   515   val copy = I;
   516   val prep_ext  = I;
   517   fun merge _ = empty;
   518   fun print _ _ = ();
   519 end;
   520 
   521 structure TheoryManagementData = TheoryDataFun(TheoryManagementDataArgs);
   522 val get_info = TheoryManagementData.get;
   523 val put_info = TheoryManagementData.put;
   524 
   525 
   526 (* get / put name *)
   527 
   528 val get_name = #name o get_info;
   529 fun put_name name = put_info {name = name, version = 0};
   530 
   531 
   532 (* control prefixing of theory name *)
   533 
   534 val global_path = Theory.root_path;
   535 
   536 fun local_path thy =
   537   thy |> Theory.root_path |> Theory.add_path (get_name thy);
   538 
   539 
   540 (* begin / end theory *)
   541 
   542 fun begin_theory name thys =
   543   Theory.prep_ext_merge thys
   544   |> put_name name
   545   |> local_path;
   546 
   547 fun end_theory thy =
   548   thy
   549   |> Theory.add_name (get_name thy);
   550 
   551 fun checkpoint thy =
   552   if is_draft thy then
   553     let val {name, version} = get_info thy in
   554       thy
   555       |> Theory.add_name (name ^ ":" ^ string_of_int version)
   556       |> put_info {name = name, version = version + 1}
   557     end
   558   else thy;
   559 
   560 
   561 
   562 (** add logical types **)
   563 
   564 fun add_typedecls decls thy =
   565   let
   566     val full = Sign.full_name (Theory.sign_of thy);
   567 
   568     fun type_of (raw_name, vs, mx) =
   569       if null (duplicates vs) then (raw_name, length vs, mx)
   570       else error ("Duplicate parameters in type declaration: " ^ quote raw_name);
   571   in thy |> Theory.add_types (map type_of decls) end;
   572 
   573 
   574 
   575 (*** the ProtoPure theory ***)
   576 
   577 
   578 (*It might make sense to restrict the polymorphism of the constant "==" to
   579   sort logic, instead of the universal sort, {}.  Unfortunately, this change
   580   causes HOL/Import/shuffler.ML to fail.*)
   581 
   582 val proto_pure =
   583   Theory.pre_pure
   584   |> Library.apply [TheoremsData.init, TheoryManagementData.init, Proofterm.init]
   585   |> put_name "ProtoPure"
   586   |> global_path
   587   |> Theory.add_types
   588    [("fun", 2, NoSyn),
   589     ("prop", 0, NoSyn),
   590     ("itself", 1, NoSyn),
   591     ("dummy", 0, NoSyn)]
   592   |> Theory.add_nonterminals Syntax.pure_nonterms
   593   |> Theory.add_syntax Syntax.pure_syntax
   594   |> Theory.add_modesyntax (Symbol.xsymbolsN, true) Syntax.pure_xsym_syntax
   595   |> Theory.add_syntax
   596    [("==>", "[prop, prop] => prop", Delimfix "op ==>"),
   597     (Term.dummy_patternN, "aprop", Delimfix "'_")]
   598   |> Theory.add_consts
   599    [("==", "['a, 'a] => prop", InfixrName ("==", 2)),
   600     ("==>", "[prop, prop] => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   601     ("all", "('a => prop) => prop", Binder ("!!", 0, 0)),
   602     ("Goal", "prop => prop", NoSyn),
   603     ("TYPE", "'a itself", NoSyn),
   604     (Term.dummy_patternN, "'a", Delimfix "'_")]
   605   |> Theory.add_finals_i false
   606     [Const("==", [TFree ("'a", []), TFree ("'a", [])] ---> propT),
   607      Const("==>", [propT, propT] ---> propT),
   608      Const("all", (TFree("'a", []) --> propT) --> propT),
   609      Const("TYPE", a_itselfT)]
   610   |> Theory.add_modesyntax ("", false)
   611     (Syntax.pure_syntax_output @ Syntax.pure_appl_syntax)
   612   |> Theory.add_trfuns Syntax.pure_trfuns
   613   |> Theory.add_trfunsT Syntax.pure_trfunsT
   614   |> local_path
   615   |> (#1 oo (add_defs_i false o map Thm.no_attributes))
   616    [("Goal_def", let val A = Free ("A", propT) in Logic.mk_equals (Logic.mk_goal A, A) end)]
   617   |> (#1 o add_thmss [(("nothing", []), [])])
   618   |> Theory.add_axioms_i Proofterm.equality_axms
   619   |> end_theory;
   620 
   621 structure ProtoPure =
   622 struct
   623   val thy = proto_pure;
   624   val Goal_def = get_axiom thy "Goal_def";
   625 end;
   626 
   627 
   628 end;
   629 
   630 
   631 structure BasicPureThy: BASIC_PURE_THY = PureThy;
   632 open BasicPureThy;
   633