src/Pure/pure_thy.ML
author wenzelm
Sat Mar 15 22:07:34 2008 +0100 (2008-03-15)
changeset 26292 009e56d16080
parent 26282 305d5ca4fa9d
child 26308 73d68876ba46
permissions -rw-r--r--
get_thm(s): check facts lookup vs. old thm database;
     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 get_thm: theory -> thmref -> thm
    16   val get_thms: theory -> thmref -> thm list
    17   val get_thmss: theory -> thmref list -> thm list
    18   structure ProtoPure:
    19     sig
    20       val thy: theory
    21       val prop_def: thm
    22       val term_def: thm
    23       val conjunction_def: thm
    24     end
    25 end;
    26 
    27 signature PURE_THY =
    28 sig
    29   include BASIC_PURE_THY
    30   val tag_rule: Markup.property -> thm -> thm
    31   val untag_rule: string -> thm -> thm
    32   val tag: Markup.property -> attribute
    33   val untag: string -> attribute
    34   val has_name_hint: thm -> bool
    35   val get_name_hint: thm -> string
    36   val put_name_hint: string -> thm -> thm
    37   val get_group: thm -> string option
    38   val put_group: string -> thm -> thm
    39   val group: string -> attribute
    40   val has_kind: thm -> bool
    41   val get_kind: thm -> string
    42   val kind_rule: string -> thm -> thm
    43   val kind: string -> attribute
    44   val kind_internal: attribute
    45   val has_internal: Markup.property list -> bool
    46   val is_internal: thm -> bool
    47   val string_of_thmref: thmref -> string
    48   val single_thm: string -> thm list -> thm
    49   val name_of_thmref: thmref -> string
    50   val map_name_of_thmref: (string -> string) -> thmref -> thmref
    51   val select_thm: thmref -> thm list -> thm list
    52   val selections: string * thm list -> (thmref * thm) list
    53   val theorems_of: theory -> thm list NameSpace.table
    54   val all_facts_of: theory -> Facts.T
    55   val thms_of: theory -> (string * thm) list
    56   val all_thms_of: theory -> (string * thm) list
    57   val hide_thms: bool -> string list -> theory -> theory
    58   val map_facts: ('a -> 'b) -> ('c * ('a list * 'd) list) list -> ('c * ('b list * 'd) list) list
    59   val burrow_fact: ('a list -> 'b list) -> ('a list * 'c) list -> ('b list * 'c) list
    60   val burrow_facts: ('a list -> 'b list) ->
    61     ('c * ('a list * 'd) list) list -> ('c * ('b list * 'd) list) list
    62   val name_multi: string -> 'a list -> (string * 'a) list
    63   val name_thm: bool -> bool -> string -> thm -> thm
    64   val name_thms: bool -> bool -> string -> thm list -> thm list
    65   val name_thmss: bool -> string -> (thm list * 'a) list -> (thm list * 'a) list
    66   val store_thm: (bstring * thm) * attribute list -> theory -> thm * theory
    67   val smart_store_thms: (bstring * thm list) -> thm list
    68   val smart_store_thms_open: (bstring * thm list) -> thm list
    69   val forall_elim_var: int -> thm -> thm
    70   val forall_elim_vars: int -> thm -> thm
    71   val add_thms: ((bstring * thm) * attribute list) list -> theory -> thm list * theory
    72   val add_thmss: ((bstring * thm list) * attribute list) list -> theory -> thm list list * theory
    73   val note: string -> string * thm -> theory -> thm * theory
    74   val note_thmss: string -> ((bstring * attribute list) *
    75     (thmref * attribute list) list) list -> theory -> (bstring * thm list) list * theory
    76   val note_thmss_i: string -> ((bstring * attribute list) *
    77     (thm list * attribute list) list) list -> theory -> (bstring * thm list) list * theory
    78   val note_thmss_grouped: string -> string -> ((bstring * attribute list) *
    79     (thm list * attribute list) list) list -> theory -> (bstring * thm list) list * theory
    80   val note_thmss_qualified: string -> string -> ((bstring * attribute list) *
    81     (thm list * attribute list) list) list -> theory -> (bstring * thm list) list * theory
    82   val add_axioms: ((bstring * string) * attribute list) list -> theory -> thm list * theory
    83   val add_axioms_i: ((bstring * term) * attribute list) list -> theory -> thm list * theory
    84   val add_axiomss: ((bstring * string list) * attribute list) list ->
    85     theory -> thm list list * theory
    86   val add_axiomss_i: ((bstring * term list) * attribute list) list ->
    87     theory -> thm list list * theory
    88   val add_defs: bool -> ((bstring * string) * attribute list) list ->
    89     theory -> thm list * theory
    90   val add_defs_i: bool -> ((bstring * term) * attribute list) list ->
    91     theory -> thm list * theory
    92   val add_defs_unchecked: bool -> ((bstring * string) * attribute list) list ->
    93     theory -> thm list * theory
    94   val add_defs_unchecked_i: bool -> ((bstring * term) * attribute list) list ->
    95     theory -> thm list * theory
    96   val appl_syntax: (string * typ * mixfix) list
    97   val applC_syntax: (string * typ * mixfix) list
    98 end;
    99 
   100 structure PureThy: PURE_THY =
   101 struct
   102 
   103 
   104 (*** theorem tags ***)
   105 
   106 (* add / delete tags *)
   107 
   108 fun tag_rule tg = Thm.map_tags (insert (op =) tg);
   109 fun untag_rule s = Thm.map_tags (filter_out (fn (s', _) => s = s'));
   110 
   111 fun tag tg x = Thm.rule_attribute (K (tag_rule tg)) x;
   112 fun untag s x = Thm.rule_attribute (K (untag_rule s)) x;
   113 
   114 
   115 (* unofficial theorem names *)
   116 
   117 fun the_name_hint thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.nameN);
   118 
   119 val has_name_hint = can the_name_hint;
   120 val get_name_hint = the_default "??.unknown" o try the_name_hint;
   121 
   122 fun put_name_hint name = untag_rule Markup.nameN #> tag_rule (Markup.nameN, name);
   123 
   124 
   125 (* theorem groups *)
   126 
   127 fun get_group thm = AList.lookup (op =) (Thm.get_tags thm) Markup.groupN;
   128 
   129 fun put_group name =
   130   if name = "" then I else Thm.map_tags (AList.update (op =) (Markup.groupN, name));
   131 
   132 fun group name = Thm.rule_attribute (K (put_group name));
   133 
   134 
   135 (* theorem kinds *)
   136 
   137 fun the_kind thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.kindN);
   138 
   139 val has_kind = can the_kind;
   140 val get_kind = the_default "" o try the_kind;
   141 
   142 fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN;
   143 fun kind k x = if k = "" then x else Thm.rule_attribute (K (kind_rule k)) x;
   144 fun kind_internal x = kind Thm.internalK x;
   145 fun has_internal tags = exists (fn tg => tg = (Markup.kindN, Thm.internalK)) tags;
   146 val is_internal = has_internal o Thm.get_tags;
   147 
   148 
   149 
   150 (*** theorem database ***)
   151 
   152 (** dataype theorems **)
   153 
   154 datatype thms = Thms of
   155  {theorems: thm list NameSpace.table,   (* FIXME legacy *)
   156   all_facts: Facts.T};
   157 
   158 fun make_thms theorems all_facts = Thms {theorems = theorems, all_facts = all_facts};
   159 
   160 structure TheoremsData = TheoryDataFun
   161 (
   162   type T = thms ref;   (* FIXME legacy *)
   163   val empty = ref (make_thms NameSpace.empty_table Facts.empty);
   164   fun copy (ref x) = ref x;
   165   fun extend (ref (Thms {theorems = _, all_facts})) = ref (make_thms NameSpace.empty_table all_facts);
   166   fun merge _
   167      (ref (Thms {theorems = _, all_facts = all_facts1}),
   168       ref (Thms {theorems = _, all_facts = all_facts2})) =
   169     ref (make_thms NameSpace.empty_table (Facts.merge (all_facts1, all_facts2)));
   170 );
   171 
   172 val get_theorems_ref = TheoremsData.get;
   173 val get_theorems = (fn Thms args => args) o ! o get_theorems_ref;
   174 val theorems_of = #theorems o get_theorems;
   175 val all_facts_of = #all_facts o get_theorems;
   176 
   177 
   178 
   179 (** retrieve theorems **)
   180 
   181 fun the_thms _ (SOME thms) = thms
   182   | the_thms name NONE = error ("Unknown theorem(s) " ^ quote name);
   183 
   184 fun single_thm _ [thm] = thm
   185   | single_thm name _ = error ("Single theorem expected " ^ quote name);
   186 
   187 
   188 (* datatype interval *)
   189 
   190 datatype interval =
   191   FromTo of int * int |
   192   From of int |
   193   Single of int;
   194 
   195 fun string_of_interval (FromTo (i, j)) = string_of_int i ^ "-" ^ string_of_int j
   196   | string_of_interval (From i) = string_of_int i ^ "-"
   197   | string_of_interval (Single i) = string_of_int i;
   198 
   199 fun interval n iv =
   200   let fun err () = raise Fail ("Bad interval specification " ^ string_of_interval iv) in
   201     (case iv of
   202       FromTo (i, j) => if i <= j then i upto j else err ()
   203     | From i => if i <= n then i upto n else err ()
   204     | Single i => [i])
   205   end;
   206 
   207 
   208 (* datatype thmref *)
   209 
   210 datatype thmref =
   211   Name of string |
   212   NameSelection of string * interval list |
   213   Fact of string;
   214 
   215 fun name_of_thmref (Name name) = name
   216   | name_of_thmref (NameSelection (name, _)) = name
   217   | name_of_thmref (Fact _) = error "Illegal literal fact";
   218 
   219 fun map_name_of_thmref f (Name name) = Name (f name)
   220   | map_name_of_thmref f (NameSelection (name, is)) = NameSelection (f name, is)
   221   | map_name_of_thmref _ thmref = thmref;
   222 
   223 fun string_of_thmref (Name name) = name
   224   | string_of_thmref (NameSelection (name, is)) =
   225       name ^ enclose "(" ")" (commas (map string_of_interval is))
   226   | string_of_thmref (Fact _) = error "Illegal literal fact";
   227 
   228 
   229 (* select_thm *)
   230 
   231 fun select_thm (Name _) thms = thms
   232   | select_thm (Fact _) thms = thms
   233   | select_thm (NameSelection (name, ivs)) thms =
   234       let
   235         val n = length thms;
   236         fun err msg = error (msg ^ " for " ^ quote name ^ " (length " ^ string_of_int n ^ ")");
   237         fun select i =
   238           if i < 1 orelse i > n then err ("Bad subscript " ^ string_of_int i)
   239           else nth thms (i - 1);
   240         val is = maps (interval n) ivs handle Fail msg => err msg;
   241       in map select is end;
   242 
   243 
   244 (* selections *)
   245 
   246 fun selections (name, [thm]) = [(Name name, thm)]
   247   | selections (name, thms) = (1 upto length thms, thms) |> ListPair.map (fn (i, thm) =>
   248       (NameSelection (name, [Single i]), thm));
   249 
   250 
   251 (* lookup/get thms *)
   252 
   253 local
   254 
   255 fun lookup_thms thy xname =
   256   let
   257     val (space, thms) = #theorems (get_theorems thy);
   258     val name = NameSpace.intern space xname;
   259   in Option.map (pair name) (Symtab.lookup thms name) end;
   260 
   261 fun lookup_fact thy xname =
   262   let
   263     val facts = all_facts_of thy;
   264     val name = NameSpace.intern (Facts.space_of facts) xname;
   265   in Option.map (pair name) (Facts.lookup facts name) end;
   266 
   267 fun show_result NONE = "none"
   268   | show_result (SOME (name, _)) = quote name;
   269 
   270 in
   271 
   272 fun get_thms theory thmref =
   273   let
   274     val name = name_of_thmref thmref;
   275     val new_res = lookup_fact theory name;
   276     val old_res = get_first (fn thy => lookup_thms thy name) (theory :: Theory.ancestors_of theory);
   277     val is_same =
   278       (case (new_res, old_res) of
   279         (NONE, NONE) => true
   280       | (SOME (name1, ths1), SOME (name2, ths2)) => name1 = name2 andalso Thm.eq_thms (ths1, ths2)
   281       | _ => false);
   282     val _ =
   283       if is_same then ()
   284       else legacy_feature ("Fact lookup differs from old-style thm database:\n" ^
   285         show_result new_res ^ " vs " ^ show_result old_res ^
   286         Position.str_of (Position.thread_data ()));
   287   in Option.map #2 old_res |> the_thms name |> select_thm thmref |> map (Thm.transfer theory) end;
   288 
   289 fun get_thmss thy thmrefs = maps (get_thms thy) thmrefs;
   290 fun get_thm thy thmref = single_thm (name_of_thmref thmref) (get_thms thy thmref);
   291 
   292 end;
   293 
   294 
   295 (* thms_of etc. *)
   296 
   297 fun thms_of thy =
   298   let val thms = #2 (theorems_of thy)
   299   in map (`(get_name_hint)) (maps snd (Symtab.dest thms)) end;
   300 
   301 fun all_thms_of thy = maps thms_of (thy :: Theory.ancestors_of thy);
   302 
   303 
   304 
   305 (** store theorems **)                    (*DESTRUCTIVE*)
   306 
   307 (* hiding -- affects current theory node only *)
   308 
   309 fun hide_thms fully names thy = CRITICAL (fn () =>
   310   let
   311     val r as ref (Thms {theorems = (space, thms), all_facts}) = get_theorems_ref thy;
   312     val space' = fold (NameSpace.hide fully) names space;
   313   in r := make_thms (space', thms) all_facts; thy end);
   314 
   315 
   316 (* fact specifications *)
   317 
   318 fun map_facts f = map (apsnd (map (apfst (map f))));
   319 fun burrow_fact f = split_list #>> burrow f #> op ~~;
   320 fun burrow_facts f = split_list ##> burrow (burrow_fact f) #> op ~~;
   321 
   322 
   323 (* naming *)
   324 
   325 fun gen_names _ len "" = replicate len ""
   326   | gen_names j len name = map (fn i => name ^ "_" ^ string_of_int i) (j + 1 upto j + len);
   327 
   328 fun name_multi name [x] = [(name, x)]
   329   | name_multi name xs = gen_names 0 (length xs) name ~~ xs;
   330 
   331 fun name_thm pre official name thm = thm
   332   |> (if Thm.get_name thm <> "" andalso pre orelse not official then I else Thm.put_name name)
   333   |> (if has_name_hint thm andalso pre orelse name = "" then I else put_name_hint name)
   334   |> Thm.map_tags (Position.default_properties (Position.thread_data ()));
   335 
   336 fun name_thms pre official name xs =
   337   map (uncurry (name_thm pre official)) (name_multi name xs);
   338 
   339 fun name_thmss official name fact =
   340   burrow_fact (name_thms true official name) fact;
   341 
   342 
   343 (* enter_thms *)
   344 
   345 fun warn_overwrite name = warning ("Replaced old copy of theorems " ^ quote name);
   346 fun warn_same name = warning ("Theorem database already contains a copy of " ^ quote name);
   347 
   348 fun enter_thms _ _ app_att ("", thms) thy = app_att (thy, thms) |> swap
   349   | enter_thms pre_name post_name app_att (bname, thms) thy = CRITICAL (fn () =>
   350       let
   351         val name = Sign.full_name thy bname;
   352         val (thy', thms') = apsnd (post_name name) (app_att (thy, pre_name name thms));
   353         val r as ref (Thms {theorems = (space, theorems), all_facts}) = get_theorems_ref thy';
   354         val space' = Sign.declare_name thy' name space;
   355         val theorems' = Symtab.update (name, thms') theorems;
   356         val all_facts' = Facts.add false (Sign.naming_of thy') (name, thms') all_facts;
   357       in
   358         (case Symtab.lookup theorems name of
   359           NONE => ()
   360         | SOME thms'' =>
   361             if Thm.eq_thms (thms', thms'') then warn_same name
   362             else warn_overwrite name);
   363         r := make_thms (space', theorems') all_facts';
   364         (thms', thy')
   365       end);
   366 
   367 
   368 (* add_thms(s) *)
   369 
   370 fun add_thms_atts pre_name ((bname, thms), atts) =
   371   enter_thms pre_name (name_thms false true)
   372     (foldl_map (Thm.theory_attributes atts)) (bname, thms);
   373 
   374 fun gen_add_thmss pre_name =
   375   fold_map (add_thms_atts pre_name);
   376 
   377 fun gen_add_thms pre_name args =
   378   apfst (map hd) o gen_add_thmss pre_name (map (apfst (apsnd single)) args);
   379 
   380 val add_thmss = gen_add_thmss (name_thms true true);
   381 val add_thms = gen_add_thms (name_thms true true);
   382 
   383 
   384 (* note_thmss(_i) *)
   385 
   386 local
   387 
   388 fun gen_note_thmss get tag = fold_map (fn ((bname, more_atts), ths_atts) => fn thy =>
   389   let
   390     fun app (x, (ths, atts)) = foldl_map (Thm.theory_attributes atts) (x, ths);
   391     val (thms, thy') = thy |> enter_thms
   392       (name_thmss true) (name_thms false true) (apsnd flat o foldl_map app)
   393       (bname, map (fn (ths, atts) => (get thy ths, surround tag (atts @ more_atts))) ths_atts);
   394   in ((bname, thms), thy') end);
   395 
   396 in
   397 
   398 fun note_thmss k = gen_note_thmss get_thms (kind k);
   399 fun note_thmss_i k = gen_note_thmss (K I) (kind k);
   400 fun note_thmss_grouped k g = gen_note_thmss (K I) (kind k #> group g);
   401 
   402 end;
   403 
   404 fun note kind (name, thm) =
   405   note_thmss_i kind [((name, []), [([thm], [])])]
   406   #>> (fn [(_, [thm])] => thm);
   407 
   408 fun note_thmss_qualified k path facts thy =
   409   thy
   410   |> Sign.add_path path
   411   |> Sign.no_base_names
   412   |> note_thmss_i k facts
   413   ||> Sign.restore_naming thy;
   414 
   415 
   416 (* store_thm *)
   417 
   418 fun store_thm ((bname, thm), atts) thy =
   419   let val ([th'], thy') = add_thms_atts (name_thms true true) ((bname, [thm]), atts) thy
   420   in (th', thy') end;
   421 
   422 
   423 (* smart_store_thms(_open) *)
   424 
   425 local
   426 
   427 fun smart_store _ (name, []) =
   428       error ("Cannot store empty list of theorems: " ^ quote name)
   429   | smart_store official (name, [thm]) =
   430       fst (enter_thms (name_thms true official) (name_thms false official) I (name, [thm])
   431         (Thm.theory_of_thm thm))
   432   | smart_store official (name, thms) =
   433       let val thy = Theory.merge_list (map Thm.theory_of_thm thms) in
   434         fst (enter_thms (name_thms true official) (name_thms false official) I (name, thms) thy)
   435       end;
   436 
   437 in
   438 
   439 val smart_store_thms = smart_store true;
   440 val smart_store_thms_open = smart_store false;
   441 
   442 end;
   443 
   444 
   445 (* forall_elim_var(s) -- belongs to drule.ML *)
   446 
   447 fun forall_elim_vars_aux strip_vars i th =
   448   let
   449     val {thy, tpairs, prop, ...} = Thm.rep_thm th;
   450     val add_used = Term.fold_aterms
   451       (fn Var ((x, j), _) => if i = j then insert (op =) x else I | _ => I);
   452     val used = fold (fn (t, u) => add_used t o add_used u) tpairs (add_used prop []);
   453     val vars = strip_vars prop;
   454     val cvars = (Name.variant_list used (map #1 vars), vars)
   455       |> ListPair.map (fn (x, (_, T)) => Thm.cterm_of thy (Var ((x, i), T)));
   456   in fold Thm.forall_elim cvars th end;
   457 
   458 val forall_elim_vars = forall_elim_vars_aux Term.strip_all_vars;
   459 
   460 fun forall_elim_var i th = forall_elim_vars_aux
   461   (fn Const ("all", _) $ Abs (a, T, _) => [(a, T)]
   462   | _ => raise THM ("forall_elim_vars", i, [th])) i th;
   463 
   464 
   465 (* store axioms as theorems *)
   466 
   467 local
   468   fun get_ax thy (name, _) = Thm.get_axiom_i thy (Sign.full_name thy name);
   469   fun get_axs thy named_axs = map (forall_elim_vars 0 o get_ax thy) named_axs;
   470   fun add_single add ((name, ax), atts) thy =
   471     let
   472       val named_ax = [(name, ax)];
   473       val thy' = add named_ax thy;
   474       val thm = hd (get_axs thy' named_ax);
   475     in apfst hd (gen_add_thms (K I) [((name, thm), atts)] thy') end;
   476   fun add_multi add ((name, axs), atts) thy =
   477     let
   478       val named_axs = name_multi name axs;
   479       val thy' = add named_axs thy;
   480       val thms = get_axs thy' named_axs;
   481     in apfst hd (gen_add_thmss (K I) [((name, thms), atts)] thy') end;
   482   fun add_singles add = fold_map (add_single add);
   483   fun add_multis add = fold_map (add_multi add);
   484 in
   485   val add_axioms           = add_singles Theory.add_axioms;
   486   val add_axioms_i         = add_singles Theory.add_axioms_i;
   487   val add_axiomss          = add_multis Theory.add_axioms;
   488   val add_axiomss_i        = add_multis Theory.add_axioms_i;
   489   val add_defs             = add_singles o Theory.add_defs false;
   490   val add_defs_i           = add_singles o Theory.add_defs_i false;
   491   val add_defs_unchecked   = add_singles o Theory.add_defs true;
   492   val add_defs_unchecked_i = add_singles o Theory.add_defs_i true;
   493 end;
   494 
   495 
   496 
   497 (*** the ProtoPure theory ***)
   498 
   499 val typ = SimpleSyntax.read_typ;
   500 val term = SimpleSyntax.read_term;
   501 val prop = SimpleSyntax.read_prop;
   502 
   503 val appl_syntax =
   504  [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
   505   ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
   506 
   507 val applC_syntax =
   508  [("",       typ "'a => cargs",                  Delimfix "_"),
   509   ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
   510   ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
   511   ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
   512 
   513 val proto_pure =
   514   Context.pre_pure_thy
   515   |> Compress.init_data
   516   |> TheoremsData.init
   517   |> Sign.add_types
   518    [("fun", 2, NoSyn),
   519     ("prop", 0, NoSyn),
   520     ("itself", 1, NoSyn),
   521     ("dummy", 0, NoSyn)]
   522   |> Sign.add_nonterminals Syntax.basic_nonterms
   523   |> Sign.add_syntax_i
   524    [("_lambda",     typ "pttrns => 'a => logic",     Mixfix ("(3%_./ _)", [0, 3], 3)),
   525     ("_abs",        typ "'a",                        NoSyn),
   526     ("",            typ "'a => args",                Delimfix "_"),
   527     ("_args",       typ "'a => args => args",        Delimfix "_,/ _"),
   528     ("",            typ "id => idt",                 Delimfix "_"),
   529     ("_idtdummy",   typ "idt",                       Delimfix "'_"),
   530     ("_idtyp",      typ "id => type => idt",         Mixfix ("_::_", [], 0)),
   531     ("_idtypdummy", typ "type => idt",               Mixfix ("'_()::_", [], 0)),
   532     ("",            typ "idt => idt",                Delimfix "'(_')"),
   533     ("",            typ "idt => idts",               Delimfix "_"),
   534     ("_idts",       typ "idt => idts => idts",       Mixfix ("_/ _", [1, 0], 0)),
   535     ("",            typ "idt => pttrn",              Delimfix "_"),
   536     ("",            typ "pttrn => pttrns",           Delimfix "_"),
   537     ("_pttrns",     typ "pttrn => pttrns => pttrns", Mixfix ("_/ _", [1, 0], 0)),
   538     ("",            typ "id => aprop",               Delimfix "_"),
   539     ("",            typ "longid => aprop",           Delimfix "_"),
   540     ("",            typ "var => aprop",              Delimfix "_"),
   541     ("_DDDOT",      typ "aprop",                     Delimfix "..."),
   542     ("_aprop",      typ "aprop => prop",             Delimfix "PROP _"),
   543     ("_asm",        typ "prop => asms",              Delimfix "_"),
   544     ("_asms",       typ "prop => asms => asms",      Delimfix "_;/ _"),
   545     ("_bigimpl",    typ "asms => prop => prop",      Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
   546     ("_ofclass",    typ "type => logic => prop",     Delimfix "(1OFCLASS/(1'(_,/ _')))"),
   547     ("_mk_ofclass", typ "dummy",                     NoSyn),
   548     ("_TYPE",       typ "type => logic",             Delimfix "(1TYPE/(1'(_')))"),
   549     ("",            typ "id => logic",               Delimfix "_"),
   550     ("",            typ "longid => logic",           Delimfix "_"),
   551     ("",            typ "var => logic",              Delimfix "_"),
   552     ("_DDDOT",      typ "logic",                     Delimfix "..."),
   553     ("_constify",   typ "num => num_const",          Delimfix "_"),
   554     ("_indexnum",   typ "num_const => index",        Delimfix "\\<^sub>_"),
   555     ("_index",      typ "logic => index",            Delimfix "(00\\<^bsub>_\\<^esub>)"),
   556     ("_indexdefault", typ "index",                   Delimfix ""),
   557     ("_indexvar",   typ "index",                     Delimfix "'\\<index>"),
   558     ("_struct",     typ "index => logic",            Mixfix ("\\<struct>_", [1000], 1000)),
   559     ("==>",         typ "prop => prop => prop",      Delimfix "op ==>"),
   560     (Term.dummy_patternN, typ "aprop",               Delimfix "'_")]
   561   |> Sign.add_syntax_i appl_syntax
   562   |> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
   563    [("fun",      typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
   564     ("_bracket", typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
   565     ("_ofsort",  typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
   566     ("_constrain", typ "'a => type => 'a",     Mixfix ("_\\<Colon>_", [4, 0], 3)),
   567     ("_idtyp",    typ "id => type => idt",     Mixfix ("_\\<Colon>_", [], 0)),
   568     ("_idtypdummy", typ "type => idt",         Mixfix ("'_()\\<Colon>_", [], 0)),
   569     ("_type_constraint_", typ "'a",            NoSyn),
   570     ("_lambda",  typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
   571     ("==",       typ "'a => 'a => prop",       InfixrName ("\\<equiv>", 2)),
   572     ("all_binder", typ "idts => prop => prop", Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
   573     ("==>",      typ "prop => prop => prop",   InfixrName ("\\<Longrightarrow>", 1)),
   574     ("_DDDOT",   typ "aprop",                  Delimfix "\\<dots>"),
   575     ("_bigimpl", typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
   576     ("_DDDOT",   typ "logic",                  Delimfix "\\<dots>")]
   577   |> Sign.add_modesyntax_i ("", false)
   578    [("prop", typ "prop => prop", Mixfix ("_", [0], 0)),
   579     ("ProtoPure.term", typ "'a => prop", Delimfix "TERM _"),
   580     ("ProtoPure.conjunction", typ "prop => prop => prop", InfixrName ("&&", 2))]
   581   |> Sign.add_modesyntax_i ("HTML", false)
   582    [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
   583   |> Sign.add_consts_i
   584    [("==", typ "'a => 'a => prop", InfixrName ("==", 2)),
   585     ("==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   586     ("all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
   587     ("prop", typ "prop => prop", NoSyn),
   588     ("TYPE", typ "'a itself", NoSyn),
   589     (Term.dummy_patternN, typ "'a", Delimfix "'_")]
   590   |> Theory.add_deps "==" ("==", typ "'a => 'a => prop") []
   591   |> Theory.add_deps "==>" ("==>", typ "prop => prop => prop") []
   592   |> Theory.add_deps "all" ("all", typ "('a => prop) => prop") []
   593   |> Theory.add_deps "TYPE" ("TYPE", typ "'a itself") []
   594   |> Theory.add_deps Term.dummy_patternN (Term.dummy_patternN, typ "'a") []
   595   |> Sign.add_trfuns Syntax.pure_trfuns
   596   |> Sign.add_trfunsT Syntax.pure_trfunsT
   597   |> Sign.local_path
   598   |> Sign.add_consts_i
   599    [("term", typ "'a => prop", NoSyn),
   600     ("conjunction", typ "prop => prop => prop", NoSyn)]
   601   |> (add_defs_i false o map Thm.no_attributes)
   602    [("prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
   603     ("term_def", prop "(CONST ProtoPure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
   604     ("conjunction_def", prop "(A && B) == (!!C::prop. (A ==> B ==> C) ==> C)")] |> snd
   605   |> Sign.hide_consts false ["conjunction", "term"]
   606   |> add_thmss [(("nothing", []), [])] |> snd
   607   |> Theory.add_axioms_i Proofterm.equality_axms
   608   |> Theory.end_theory;
   609 
   610 structure ProtoPure =
   611 struct
   612   val thy = proto_pure;
   613   val prop_def = get_axiom thy "prop_def";
   614   val term_def = get_axiom thy "term_def";
   615   val conjunction_def = get_axiom thy "conjunction_def";
   616 end;
   617 
   618 end;
   619 
   620 structure BasicPureThy: BASIC_PURE_THY = PureThy;
   621 open BasicPureThy;