src/Pure/pure_thy.ML
author wenzelm
Sat Jan 21 23:02:14 2006 +0100 (2006-01-21)
changeset 18728 6790126ab5f6
parent 18713 cf777b9788b5
child 18778 f623f7a35ced
permissions -rw-r--r--
simplified type attribute;
     1 (*  Title:      Pure/pure_thy.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Theorem storage.  The ProtoPure theory.
     6 *)
     7 
     8 signature BASIC_PURE_THY =
     9 sig
    10   datatype interval = FromTo of int * int | From of int | Single of int
    11   datatype thmref =
    12     Name of string |
    13     NameSelection of string * interval list |
    14     Fact of string
    15   val print_theorems: theory -> unit
    16   val print_theory: theory -> unit
    17   val get_thm: theory -> thmref -> thm
    18   val get_thms: theory -> thmref -> thm list
    19   val get_thmss: theory -> thmref list -> thm list
    20   val thm: xstring -> thm
    21   val thms: xstring -> thm list
    22   structure ProtoPure:
    23     sig
    24       val thy: theory
    25       val prop_def: thm
    26     end
    27 end;
    28 
    29 signature PURE_THY =
    30 sig
    31   include BASIC_PURE_THY
    32   val string_of_thmref: thmref -> string
    33   val print_theorems_diff: theory -> theory -> unit
    34   val get_thm_closure: theory -> thmref -> thm
    35   val get_thms_closure: theory -> thmref -> thm list
    36   val single_thm: string -> thm list -> thm
    37   val name_of_thmref: thmref -> string
    38   val map_name_of_thmref: (string -> string) -> thmref -> thmref
    39   val select_thm: thmref -> thm list -> thm list
    40   val selections: string * thm list -> (thmref * thm) list
    41   val theorems_of: theory -> thm list NameSpace.table
    42   val theorem_space: theory -> NameSpace.T
    43   val fact_index_of: theory -> FactIndex.T
    44   val valid_thms: theory -> thmref * thm list -> bool
    45   val thms_containing: theory -> FactIndex.spec -> (string * thm list) list
    46   val thms_containing_consts: theory -> string list -> (string * thm) list
    47   val thms_of: theory -> (string * thm) list
    48   val all_thms_of: theory -> (string * thm) list
    49   val hide_thms: bool -> string list -> theory -> theory
    50   val store_thm: (bstring * thm) * attribute list -> theory -> thm * theory
    51   val smart_store_thms: (bstring * thm list) -> thm list
    52   val smart_store_thms_open: (bstring * thm list) -> thm list
    53   val forall_elim_var: int -> thm -> thm
    54   val forall_elim_vars: int -> thm -> thm
    55   val add_thms: ((bstring * thm) * attribute list) list -> theory -> thm list * theory
    56   val add_thmss: ((bstring * thm list) * attribute list) list -> theory -> thm list list * theory 
    57   val note_thmss: attribute -> ((bstring * attribute list) *
    58     (thmref * attribute list) list) list -> theory -> (bstring * thm list) list * theory
    59   val note_thmss_i: attribute -> ((bstring * attribute list) *
    60     (thm list * attribute list) list) list -> theory -> (bstring * thm list) list * theory
    61   val add_axioms: ((bstring * string) * attribute list) list -> theory -> thm list * theory
    62   val add_axioms_i: ((bstring * term) * attribute list) list -> theory -> thm list * theory
    63   val add_axiomss: ((bstring * string list) * attribute list) list ->
    64     theory -> thm list list * theory
    65   val add_axiomss_i: ((bstring * term list) * attribute list) list ->
    66     theory -> thm list list * theory
    67   val add_defs: bool -> ((bstring * string) * attribute list) list ->
    68     theory -> thm list * theory
    69   val add_defs_i: bool -> ((bstring * term) * attribute list) list ->
    70     theory -> thm list * theory
    71   val add_defss: bool -> ((bstring * string list) * attribute list) list ->
    72     theory -> thm list list * theory
    73   val add_defss_i: bool -> ((bstring * term list) * attribute list) list ->
    74     theory -> thm list list * theory
    75   val generic_setup: string option -> theory -> theory
    76   val add_oracle: bstring * string * string -> theory -> theory
    77 end;
    78 
    79 structure PureThy: PURE_THY =
    80 struct
    81 
    82 
    83 (*** theorem database ***)
    84 
    85 (** dataype theorems **)
    86 
    87 fun pretty_theorems_diff thy prev_thms (space, thms) =
    88   let
    89     val prt_thm = Display.pretty_thm_sg thy;
    90     fun prt_thms (name, [th]) =
    91           Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt_thm th]
    92       | prt_thms (name, ths) = Pretty.big_list (name ^ ":") (map prt_thm ths);
    93 
    94     val diff_thmss = Symtab.fold (fn fact =>
    95       if not (Symtab.member eq_thms prev_thms fact) then cons fact else I) thms [];
    96     val thmss = diff_thmss |> map (apfst (NameSpace.extern space)) |> Library.sort_wrt #1;
    97   in Pretty.big_list "theorems:" (map prt_thms thmss) end;
    98 
    99 fun pretty_theorems thy = pretty_theorems_diff thy Symtab.empty;
   100 
   101 structure TheoremsData = TheoryDataFun
   102 (struct
   103   val name = "Pure/theorems";
   104   type T =
   105    {theorems: thm list NameSpace.table,
   106     index: FactIndex.T} ref;
   107 
   108   fun mk_empty _ =
   109     ref {theorems = NameSpace.empty_table, index = FactIndex.empty}: T;
   110 
   111   val empty = mk_empty ();
   112   fun copy (ref x) = ref x;
   113   val extend = mk_empty;
   114   fun merge _ = mk_empty;
   115   fun print thy (ref {theorems, index}) = Pretty.writeln (pretty_theorems thy theorems);
   116 end);
   117 
   118 val get_theorems_ref = TheoremsData.get;
   119 val get_theorems = ! o get_theorems_ref;
   120 val theorems_of = #theorems o get_theorems;
   121 val theorem_space = #1 o theorems_of;
   122 val fact_index_of = #index o get_theorems;
   123 
   124 
   125 (* print theory *)
   126 
   127 val print_theorems = TheoremsData.print;
   128 
   129 fun print_theorems_diff prev_thy thy =
   130   Pretty.writeln (pretty_theorems_diff thy
   131     (#2 (theorems_of prev_thy)) (#theorems (get_theorems thy)));
   132 
   133 fun print_theory thy =
   134   Display.pretty_full_theory thy @
   135     [pretty_theorems thy (#theorems (get_theorems thy))]
   136   |> Pretty.chunks |> Pretty.writeln;
   137 
   138 
   139 
   140 (** retrieve theorems **)
   141 
   142 fun the_thms _ (SOME thms) = thms
   143   | the_thms name NONE = error ("Unknown theorem(s) " ^ quote name);
   144 
   145 fun single_thm _ [thm] = thm
   146   | single_thm name _ = error ("Single theorem expected " ^ quote name);
   147 
   148 
   149 (* datatype interval *)
   150 
   151 datatype interval =
   152   FromTo of int * int |
   153   From of int |
   154   Single of int;
   155 
   156 fun interval _ (FromTo (i, j)) = i upto j
   157   | interval n (From i) = i upto n
   158   | interval _ (Single i) = [i];
   159 
   160 fun string_of_interval (FromTo (i, j)) = string_of_int i ^ "-" ^ string_of_int j
   161   | string_of_interval (From i) = string_of_int i ^ "-"
   162   | string_of_interval (Single i) = string_of_int i;
   163 
   164 
   165 (* datatype thmref *)
   166 
   167 datatype thmref =
   168   Name of string |
   169   NameSelection of string * interval list |
   170   Fact of string;
   171 
   172 fun name_of_thmref (Name name) = name
   173   | name_of_thmref (NameSelection (name, _)) = name
   174   | name_of_thmref (Fact _) = error "Illegal literal fact";
   175 
   176 fun map_name_of_thmref f (Name name) = Name (f name)
   177   | map_name_of_thmref f (NameSelection (name, is)) = NameSelection (f name, is)
   178   | map_name_of_thmref _ thmref = thmref;
   179 
   180 fun string_of_thmref (Name name) = name
   181   | string_of_thmref (NameSelection (name, is)) =
   182       name ^ enclose "(" ")" (commas (map string_of_interval is))
   183   | string_of_thmref (Fact _) = error "Illegal literal fact";
   184 
   185 
   186 (* select_thm *)
   187 
   188 fun select_thm (Name _) thms = thms
   189   | select_thm (Fact _) thms = thms
   190   | select_thm (NameSelection (name, is)) thms =
   191       let
   192         val n = length thms;
   193         fun select i =
   194           if i < 1 orelse i > n then
   195             error ("Bad subscript " ^ string_of_int i ^ " for " ^
   196               quote name ^ " (length " ^ string_of_int n ^ ")")
   197           else List.nth (thms, i - 1);
   198       in map select (List.concat (map (interval n) is)) end;
   199 
   200 
   201 (* selections *)
   202 
   203 fun selections (name, [thm]) = [(Name name, thm)]
   204   | selections (name, thms) = (1 upto length thms, thms) |> ListPair.map (fn (i, thm) =>
   205       (NameSelection (name, [Single i]), thm));
   206 
   207 
   208 (* get_thm(s)_closure -- statically scoped versions *)
   209 
   210 (*beware of proper order of evaluation!*)
   211 
   212 fun lookup_thms thy =
   213   let
   214     val thy_ref = Theory.self_ref thy;
   215     val (space, thms) = #theorems (get_theorems thy);
   216   in
   217     fn name =>
   218       Option.map (map (Thm.transfer (Theory.deref thy_ref)))     (*dynamic identity*)
   219       (Symtab.lookup thms (NameSpace.intern space name)) (*static content*)
   220   end;
   221 
   222 fun get_thms_closure thy =
   223   let val closures = map lookup_thms (thy :: Theory.ancestors_of thy) in
   224     fn thmref =>
   225       let val name = name_of_thmref thmref;
   226       in select_thm thmref (the_thms name (get_first (fn f => f name) closures)) end
   227   end;
   228 
   229 fun get_thm_closure thy =
   230   let val get = get_thms_closure thy
   231   in fn thmref => single_thm (name_of_thmref thmref) (get thmref) end;
   232 
   233 
   234 (* get_thms etc. *)
   235 
   236 fun get_thms theory thmref =
   237   let val name = name_of_thmref thmref in
   238     get_first (fn thy => lookup_thms thy name) (theory :: Theory.ancestors_of theory)
   239     |> the_thms name |> select_thm thmref |> map (Thm.transfer theory)
   240   end;
   241 
   242 fun get_thmss thy thmrefs = List.concat (map (get_thms thy) thmrefs);
   243 fun get_thm thy thmref = single_thm (name_of_thmref thmref) (get_thms thy thmref);
   244 
   245 fun thm name = get_thm (the_context ()) (Name name);
   246 fun thms name = get_thms (the_context ()) (Name name);
   247 
   248 
   249 (* thms_containing etc. *)
   250 
   251 fun valid_thms thy (thmref, ths) =
   252   (case try (get_thms thy) thmref of
   253     NONE => false
   254   | SOME ths' => Thm.eq_thms (ths, ths'));
   255 
   256 fun thms_containing theory spec =
   257   (theory :: Theory.ancestors_of theory)
   258   |> map (fn thy =>
   259       FactIndex.find (fact_index_of thy) spec
   260       |> List.filter (fn (name, ths) => valid_thms theory (Name name, ths))
   261       |> gen_distinct (eq_fst (op =)))
   262   |> List.concat;
   263 
   264 fun thms_containing_consts thy consts =
   265   thms_containing thy (consts, []) |> map #2 |> List.concat
   266   |> map (fn th => (Thm.name_of_thm th, th));
   267 
   268 
   269 (* thms_of etc. *)
   270 
   271 fun thms_of thy =
   272   let val thms = #2 (theorems_of thy)
   273   in map (fn th => (Thm.name_of_thm th, th)) (List.concat (map snd (Symtab.dest thms))) end;
   274 
   275 fun all_thms_of thy = List.concat (map thms_of (thy :: Theory.ancestors_of thy));
   276 
   277 
   278 
   279 (** store theorems **)                    (*DESTRUCTIVE*)
   280 
   281 (* hiding -- affects current theory node only *)
   282 
   283 fun hide_thms fully names thy =
   284   let
   285     val r as ref {theorems = (space, thms), index} = get_theorems_ref thy;
   286     val space' = fold (NameSpace.hide fully) names space;
   287   in r := {theorems = (space', thms), index = index}; thy end;
   288 
   289 
   290 (* naming *)
   291 
   292 fun gen_names _ len "" = replicate len ""
   293   | gen_names j len name = map (fn i => name ^ "_" ^ string_of_int i) (j + 1 upto j + len);
   294 
   295 fun name_multi name xs = gen_names 0 (length xs) name ~~ xs;
   296 
   297 fun name_thm pre (name, thm) =
   298   if Thm.name_of_thm thm <> "" andalso pre then thm else Thm.name_thm (name, thm);
   299 
   300 fun name_thms pre name [x] = [name_thm pre (name, x)]
   301   | name_thms pre name xs = map (name_thm pre) (name_multi name xs);
   302 
   303 fun name_thmss name xs =
   304   (case filter_out (null o fst) xs of
   305     [([x], z)] => [([name_thm true (name, x)], z)]
   306   | _ => fst (fold_map (fn (ys, z) => fn i =>
   307     ((map (name_thm true) (gen_names i (length ys) name ~~ ys), z), i + length ys)) xs 0));
   308 
   309 
   310 (* enter_thms *)
   311 
   312 fun warn_overwrite name = warning ("Replaced old copy of theorems " ^ quote name);
   313 fun warn_same name = warning ("Theorem database already contains a copy of " ^ quote name);
   314 
   315 fun enter_thms _ _ app_att ("", thms) thy = app_att (thy, thms) |> swap
   316   | enter_thms pre_name post_name app_att (bname, thms) thy =
   317       let
   318         val name = Sign.full_name thy bname;
   319         val (thy', thms') = apsnd (post_name name) (app_att (thy, pre_name name thms));
   320         val r as ref {theorems = (space, theorems), index} = get_theorems_ref thy';
   321         val space' = Sign.declare_name thy' name space;
   322         val theorems' = Symtab.update (name, thms') theorems;
   323         val index' = FactIndex.add_global (name, thms') index;
   324       in
   325         (case Symtab.lookup theorems name of
   326           NONE => ()
   327         | SOME thms'' =>
   328             if Thm.eq_thms (thms', thms'') then warn_same name
   329             else warn_overwrite name);
   330         r := {theorems = (space', theorems'), index = index'};
   331         (thms', thy')
   332       end;
   333 
   334 
   335 (* add_thms(s) *)
   336 
   337 fun add_thms_atts pre_name ((bname, thms), atts) =
   338   enter_thms pre_name (name_thms false) (foldl_map (Thm.theory_attributes atts)) (bname, thms);
   339 
   340 fun gen_add_thmss pre_name =
   341   fold_map (add_thms_atts pre_name);
   342 
   343 fun gen_add_thms pre_name args =
   344   apfst (map hd) o gen_add_thmss pre_name (map (apfst (apsnd single)) args);
   345 
   346 val add_thmss = gen_add_thmss (name_thms true);
   347 val add_thms = gen_add_thms (name_thms true);
   348 
   349 
   350 (* note_thmss(_i) *)
   351 
   352 local
   353 
   354 fun gen_note_thss get kind_att ((bname, more_atts), ths_atts) thy =
   355   let
   356     fun app (x, (ths, atts)) = foldl_map (Thm.theory_attributes atts) (x, ths);
   357     val (thms, thy') = thy |> enter_thms
   358       name_thmss (name_thms false) (apsnd List.concat o foldl_map app)
   359       (bname, map (fn (ths, atts) => (get thy ths, atts @ more_atts @ [kind_att])) ths_atts);
   360   in ((bname, thms), thy') end;
   361 
   362 fun gen_note_thmss get kind_att =
   363   fold_map (gen_note_thss get kind_att);
   364 
   365 in
   366 
   367 val note_thmss = gen_note_thmss get_thms;
   368 val note_thmss_i = gen_note_thmss (K I);
   369 
   370 end;
   371 
   372 
   373 (* store_thm *)
   374 
   375 fun store_thm ((bname, thm), atts) thy =
   376   let val ([th'], thy') = add_thms_atts (name_thms true) ((bname, [thm]), atts) thy
   377   in (th', thy') end;
   378 
   379 
   380 (* smart_store_thms(_open) *)
   381 
   382 local
   383 
   384 fun smart_store _ (name, []) =
   385       error ("Cannot store empty list of theorems: " ^ quote name)
   386   | smart_store name_thm (name, [thm]) =
   387       fst (enter_thms (name_thm true) (name_thm false) I (name, [thm]) (Thm.theory_of_thm thm))
   388   | smart_store name_thm (name, thms) =
   389       let
   390         fun merge (thy, th) = Theory.merge (thy, Thm.theory_of_thm th);
   391         val thy = Library.foldl merge (Thm.theory_of_thm (hd thms), tl thms);
   392       in fst (enter_thms (name_thm true) (name_thm false) I (name, thms) thy) end;
   393 
   394 in
   395 
   396 val smart_store_thms = smart_store name_thms;
   397 val smart_store_thms_open = smart_store (K (K I));
   398 
   399 end;
   400 
   401 
   402 (* forall_elim_var(s) -- belongs to drule.ML *)
   403 
   404 fun forall_elim_vars_aux strip_vars i th =
   405   let
   406     val {thy, tpairs, prop, ...} = Thm.rep_thm th;
   407     val add_used = Term.fold_aterms
   408       (fn Var ((x, j), _) => if i = j then curry (op ins_string) x else I | _ => I);
   409     val used = fold (fn (t, u) => add_used t o add_used u) tpairs (add_used prop []);
   410     val vars = strip_vars prop;
   411     val cvars = (Term.variantlist (map #1 vars, used), vars)
   412       |> ListPair.map (fn (x, (_, T)) => Thm.cterm_of thy (Var ((x, i), T)));
   413   in fold Thm.forall_elim cvars th end;
   414 
   415 val forall_elim_vars = forall_elim_vars_aux Term.strip_all_vars;
   416 
   417 fun forall_elim_var i th = forall_elim_vars_aux
   418   (fn Const ("all", _) $ Abs (a, T, _) => [(a, T)]
   419   | _ => raise THM ("forall_elim_vars", i, [th])) i th;
   420 
   421 
   422 (* store axioms as theorems *)
   423 
   424 local
   425   fun get_ax thy (name, _) = Thm.get_axiom_i thy (Sign.full_name thy name);
   426   fun get_axs thy named_axs = map (forall_elim_vars 0 o get_ax thy) named_axs;
   427   fun add_single add ((name, ax), atts) thy =
   428     let
   429       val named_ax = [(name, ax)];
   430       val thy' = add named_ax thy;
   431       val thm = hd (get_axs thy' named_ax);
   432     in apfst hd (gen_add_thms (K I) [((name, thm), atts)] thy') end;
   433   fun add_multi add ((name, axs), atts) thy =
   434     let
   435       val named_axs = name_multi name axs;
   436       val thy' = add named_axs thy;
   437       val thms = get_axs thy' named_axs;
   438     in apfst hd (gen_add_thmss (K I) [((name, thms), atts)] thy') end;
   439   fun add_singles add = fold_map (add_single add);
   440   fun add_multis add = fold_map (add_multi add);
   441 in
   442   val add_axioms    = add_singles Theory.add_axioms;
   443   val add_axioms_i  = add_singles Theory.add_axioms_i;
   444   val add_axiomss   = add_multis Theory.add_axioms;
   445   val add_axiomss_i = add_multis Theory.add_axioms_i;
   446   val add_defs      = add_singles o Theory.add_defs;
   447   val add_defs_i    = add_singles o Theory.add_defs_i;
   448   val add_defss     = add_multis o Theory.add_defs;
   449   val add_defss_i   = add_multis o Theory.add_defs_i;
   450 end;
   451 
   452 
   453 
   454 (*** ML setup ***)
   455 
   456 (* generic_setup *)
   457 
   458 fun generic_setup NONE = (fn thy => thy |> Context.setup ())
   459   | generic_setup (SOME txt) = Context.use_let "val setup: theory -> theory" "setup" txt;
   460 
   461 
   462 (* add_oracle *)
   463 
   464 fun add_oracle (name, T, oracle) =
   465   let val txt =
   466     "local\n\
   467     \  type T = " ^ T ^ ";\n\
   468     \  val oracle: theory -> T -> term = " ^ oracle ^ ";\n\
   469     \  val name = " ^ quote name ^ ";\n\
   470     \  exception Arg of T;\n\
   471     \  val _ = Context.>> (Theory.add_oracle (name, fn (thy, Arg x) => oracle thy x));\n\
   472     \  val thy = Context.the_context ();\n\
   473     \  val invoke_" ^ name ^ " = Thm.invoke_oracle_i thy (Sign.full_name thy name);\n\
   474     \in\n\
   475     \  fun " ^ name ^ " thy x = invoke_" ^ name ^ " (thy, Arg x);\n\
   476     \end;\n";
   477   in Context.use_mltext_theory txt false end;
   478 
   479 
   480 
   481 (*** the ProtoPure theory ***)
   482 
   483 val aT = TFree ("'a", []);
   484 val A = Free ("A", propT);
   485 
   486 val proto_pure =
   487   Context.pre_pure_thy
   488   |> Compress.init_data
   489   |> Sign.init_data
   490   |> Theory.init_data
   491   |> Proofterm.init_data
   492   |> TheoremsData.init
   493   |> Theory.add_types
   494    [("fun", 2, NoSyn),
   495     ("prop", 0, NoSyn),
   496     ("itself", 1, NoSyn),
   497     ("dummy", 0, NoSyn)]
   498   |> Theory.add_nonterminals Syntax.basic_nonterms
   499   |> Theory.add_syntax
   500    [("_lambda",     "[pttrns, 'a] => logic",     Mixfix ("(3%_./ _)", [0, 3], 3)),
   501     ("_abs",        "'a",                        NoSyn),
   502     ("",            "'a => args",                Delimfix "_"),
   503     ("_args",       "['a, args] => args",        Delimfix "_,/ _"),
   504     ("",            "id => idt",                 Delimfix "_"),
   505     ("_idtdummy",   "idt",                       Delimfix "'_"),
   506     ("_idtyp",      "[id, type] => idt",         Mixfix ("_::_", [], 0)),
   507     ("_idtypdummy", "type => idt",               Mixfix ("'_()::_", [], 0)),
   508     ("",            "idt => idt",                Delimfix "'(_')"),
   509     ("",            "idt => idts",               Delimfix "_"),
   510     ("_idts",       "[idt, idts] => idts",       Mixfix ("_/ _", [1, 0], 0)),
   511     ("",            "idt => pttrn",              Delimfix "_"),
   512     ("",            "pttrn => pttrns",           Delimfix "_"),
   513     ("_pttrns",     "[pttrn, pttrns] => pttrns", Mixfix ("_/ _", [1, 0], 0)),
   514     ("",            "id => aprop",               Delimfix "_"),
   515     ("",            "longid => aprop",           Delimfix "_"),
   516     ("",            "var => aprop",              Delimfix "_"),
   517     ("_DDDOT",      "aprop",                     Delimfix "..."),
   518     ("_aprop",      "aprop => prop",             Delimfix "PROP _"),
   519     ("_asm",        "prop => asms",              Delimfix "_"),
   520     ("_asms",       "[prop, asms] => asms",      Delimfix "_;/ _"),
   521     ("_bigimpl",    "[asms, prop] => prop",      Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
   522     ("_ofclass",    "[type, logic] => prop",     Delimfix "(1OFCLASS/(1'(_,/ _')))"),
   523     ("_mk_ofclass", "_",                         NoSyn),
   524     ("_TYPE",       "type => logic",             Delimfix "(1TYPE/(1'(_')))"),
   525     ("",            "id => logic",               Delimfix "_"),
   526     ("",            "longid => logic",           Delimfix "_"),
   527     ("",            "var => logic",              Delimfix "_"),
   528     ("_DDDOT",      "logic",                     Delimfix "..."),
   529     ("_constify",   "num => num_const",          Delimfix "_"),
   530     ("_indexnum",   "num_const => index",        Delimfix "\\<^sub>_"),
   531     ("_index",      "logic => index",            Delimfix "(00\\<^bsub>_\\<^esub>)"),
   532     ("_indexdefault", "index",                   Delimfix ""),
   533     ("_indexvar",   "index",                     Delimfix "'\\<index>"),
   534     ("_struct",     "index => logic",            Mixfix ("\\<struct>_", [1000], 1000)),
   535     ("==>",         "prop => prop => prop",      Delimfix "op ==>"),
   536     (Term.dummy_patternN, "aprop",               Delimfix "'_")]
   537   |> Theory.add_syntax Syntax.appl_syntax
   538   |> Theory.add_modesyntax (Symbol.xsymbolsN, true)
   539    [("fun",      "[type, type] => type",  Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
   540     ("_bracket", "[types, type] => type", Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
   541     ("_ofsort",  "[tid, sort] => type",   Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
   542     ("_constrain", "['a, type] => 'a",    Mixfix ("_\\<Colon>_", [4, 0], 3)),
   543     ("_idtyp",   "[id, type] => idt",     Mixfix ("_\\<Colon>_", [], 0)),
   544     ("_idtypdummy", "type => idt",        Mixfix ("'_()\\<Colon>_", [], 0)),
   545     ("_lambda",  "[pttrns, 'a] => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
   546     ("==",       "['a, 'a] => prop",      InfixrName ("\\<equiv>", 2)),
   547     ("!!",       "[idts, prop] => prop",  Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
   548     ("==>",      "[prop, prop] => prop",  InfixrName ("\\<Longrightarrow>", 1)),
   549     ("_DDDOT",   "aprop",                 Delimfix "\\<dots>"),
   550     ("_bigimpl", "[asms, prop] => prop",  Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
   551     ("_DDDOT",   "logic",                 Delimfix "\\<dots>")]
   552   |> Theory.add_modesyntax ("", false)
   553    [("prop", "prop => prop", Mixfix ("_", [0], 0)),
   554     ("_meta_conjunction", "prop => prop => prop", InfixrName ("&&", 2))]
   555   |> Theory.add_modesyntax ("HTML", false)
   556    [("_lambda",  "[pttrns, 'a] => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
   557   |> Theory.add_trfuns Syntax.pure_trfuns
   558   |> Theory.add_trfunsT Syntax.pure_trfunsT
   559   |> Theory.add_consts
   560    [("==", "'a => 'a => prop", InfixrName ("==", 2)),
   561     ("==>", "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   562     ("all", "('a => prop) => prop", Binder ("!!", 0, 0)),
   563     ("prop", "prop => prop", NoSyn),
   564     ("TYPE", "'a itself", NoSyn),
   565     (Term.dummy_patternN, "'a", Delimfix "'_")]
   566   |> Theory.add_finals_i false
   567     [Const ("==", [aT, aT] ---> propT),
   568      Const ("==>", [propT, propT] ---> propT),
   569      Const ("all", (aT --> propT) --> propT),
   570      Const ("TYPE", a_itselfT),
   571      Const (Term.dummy_patternN, aT)]
   572   |> Theory.add_syntax
   573    []
   574   |> Sign.local_path
   575   |> (add_defs_i false o map Thm.no_attributes)
   576        [("prop_def", Logic.mk_equals (Logic.protect A, A))] |> snd
   577   |> add_thmss [(("nothing", []), [])] |> snd
   578   |> Theory.add_axioms_i Proofterm.equality_axms
   579   |> Theory.end_theory;
   580 
   581 structure ProtoPure =
   582 struct
   583   val thy = proto_pure;
   584   val prop_def = get_axiom thy "prop_def";
   585 end;
   586 
   587 end;
   588 
   589 structure BasicPureThy: BASIC_PURE_THY = PureThy;
   590 open BasicPureThy;