src/Pure/Thy/thm_database.ML
author wenzelm
Mon, 22 Oct 2001 18:04:26 +0200
changeset 11895 73b2c277974f
parent 11769 1fcf1eb51608
child 13279 8a722689a1c9
permissions -rw-r--r--
moved goal related stuff to goals.ML;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/thm_database.ML
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
     2
    ID:         $Id$
11895
73b2c277974f moved goal related stuff to goals.ML;
wenzelm
parents: 11769
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
73b2c277974f moved goal related stuff to goals.ML;
wenzelm
parents: 11769
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
     5
11895
73b2c277974f moved goal related stuff to goals.ML;
wenzelm
parents: 11769
diff changeset
     6
Interface to thm database (see also Pure/pure_thy.ML).
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
     7
*)
1262
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
     8
6204
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
     9
signature BASIC_THM_DATABASE =
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    10
sig
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    11
  val store_thm: string * thm -> thm
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    12
  val store_thms: string * thm list -> thm list
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    13
end;
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
    14
6204
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    15
signature THM_DATABASE =
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    16
sig
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    17
  include BASIC_THM_DATABASE
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    18
  val qed_thms: thm list ref
6204
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    19
  val ml_store_thm: string * thm -> unit
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    20
  val ml_store_thms: string * thm list -> unit
6204
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    21
  val is_ml_identifier: string -> bool
11529
5cb3be5fbb4c Exported ml_reserved.
berghofe
parents: 11017
diff changeset
    22
  val ml_reserved: string list
11895
73b2c277974f moved goal related stuff to goals.ML;
wenzelm
parents: 11769
diff changeset
    23
  val thms_containing: theory -> string list -> (string * thm) list
11017
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    24
  val print_thms_containing: theory -> term list -> unit
6204
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    25
end;
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
    26
3627
3d0d5f2a2e33 tuned names;
wenzelm
parents: 3601
diff changeset
    27
structure ThmDatabase: THM_DATABASE =
1221
19dde7bfcd07 Added findI, findEs, and findE.
nipkow
parents: 1141
diff changeset
    28
struct
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
    29
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    30
(** store theorems **)
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
    31
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    32
(* store in theory and generate HTML *)
1136
3910c96551d1 fixed bug in thms_containing; changed error/warning messages;
clasohm
parents: 1134
diff changeset
    33
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    34
fun store_thm (name, thm) =
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    35
  let val thm' = hd (PureThy.smart_store_thms (name, [thm]))
6327
c6abb5884fed Present.theorem;
wenzelm
parents: 6204
diff changeset
    36
  in Present.theorem name thm'; thm' end;
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
    37
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    38
fun store_thms (name, thms) =
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    39
  let val thms' = PureThy.smart_store_thms (name, thms)
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    40
  in Present.theorems name thms'; thms' end;
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    41
1262
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
    42
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    43
(* store on ML toplevel *)
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    44
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    45
val qed_thms: thm list ref = ref [];
1262
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
    46
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    47
val ml_reserved =
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    48
 ["abstype", "and", "andalso", "as", "case", "do", "datatype", "else",
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    49
  "end", "exception", "fn", "fun", "handle", "if", "in", "infix",
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    50
  "infixr", "let", "local", "nonfix", "of", "op", "open", "orelse",
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    51
  "raise", "rec", "then", "type", "val", "with", "withtype", "while",
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    52
  "eqtype", "functor", "include", "sharing", "sig", "signature",
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    53
  "struct", "structure", "where"];
1262
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
    54
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    55
fun is_ml_identifier name =
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    56
  Syntax.is_identifier name andalso not (name mem ml_reserved);
1262
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
    57
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    58
fun warn_ml name =
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    59
  if is_ml_identifier name then false
7573
aa87cf5a15f5 ml_store_thm: no warning for "";
wenzelm
parents: 7446
diff changeset
    60
  else if name = "" then true
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    61
  else (warning ("Cannot bind theorem(s) " ^ quote name ^ " as ML value"); true);
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    62
10914
aded4ba99b88 use_text etc.: proper output of error messages;
wenzelm
parents: 10894
diff changeset
    63
val use_text_verbose = use_text Context.ml_output true;
7854
fe7b7e3c3ddc use_text_verbose;
wenzelm
parents: 7738
diff changeset
    64
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    65
fun ml_store_thm (name, thm) =
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    66
  let val thm' = store_thm (name, thm) in
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    67
    if warn_ml name then ()
7854
fe7b7e3c3ddc use_text_verbose;
wenzelm
parents: 7738
diff changeset
    68
    else (qed_thms := [thm']; use_text_verbose ("val " ^ name ^ " = hd (! ThmDatabase.qed_thms);"))
7410
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    69
  end;
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    70
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    71
fun ml_store_thms (name, thms) =
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    72
  let val thms' = store_thms (name, thms) in
7369a35fb3c2 added store/bind_thms;
wenzelm
parents: 7182
diff changeset
    73
    if warn_ml name then ()
7854
fe7b7e3c3ddc use_text_verbose;
wenzelm
parents: 7738
diff changeset
    74
    else (qed_thms := thms'; use_text_verbose ("val " ^ name ^ " = ! ThmDatabase.qed_thms;"))
1262
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
    75
  end;
8f40ff1299d8 added removal of theorems if theory is to be reloaded; changed functions for
clasohm
parents: 1245
diff changeset
    76
4023
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    77
a9dc0484c903 restructured -- uses PureThy storage facilities;
wenzelm
parents: 3999
diff changeset
    78
4037
wenzelm
parents: 4023
diff changeset
    79
(** retrieve theorems **)
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
    80
11895
73b2c277974f moved goal related stuff to goals.ML;
wenzelm
parents: 11769
diff changeset
    81
fun thms_containing thy consts = PureThy.thms_containing thy consts
11017
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    82
  handle THEORY (msg, _) => error msg | THM (msg, _, _) => error msg;
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    83
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    84
fun print_thms_containing thy ts =
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    85
  let
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    86
    val prt_const =
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    87
      Pretty.quote o Pretty.str o Sign.cond_extern (Theory.sign_of thy) Sign.constK;
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    88
    fun prt_thm (a, th) = Pretty.block [Pretty.str (a ^ ":"),
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    89
      Pretty.brk 1, Display.pretty_thm_no_quote (#1 (Drule.freeze_thaw th))];
7609
1acbed762fc6 added print_thms_containing;
wenzelm
parents: 7573
diff changeset
    90
11017
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    91
    val cs = foldr Term.add_term_consts (ts, []);
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    92
    val header =
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    93
      if Library.null cs then []
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    94
      else [Pretty.block (Pretty.breaks (Pretty.str "theorems containing constants:" ::
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    95
          map prt_const cs)), Pretty.str ""];
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    96
  in
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    97
    if Library.null cs andalso not (Library.null ts) then
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
    98
      warning "thms_containing: no constants in specification"
11895
73b2c277974f moved goal related stuff to goals.ML;
wenzelm
parents: 11769
diff changeset
    99
    else (header @ map prt_thm (thms_containing thy cs)) |> Pretty.chunks |> Pretty.writeln
11017
241cbdf4134e thms_containing: term args;
wenzelm
parents: 10914
diff changeset
   100
  end;
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
   101
3601
43c7912aac8d Moved "qed" - functions etc. from thy_read.ML to thm_database.ML.
berghofe
parents: 2150
diff changeset
   102
1132
dfb29abcf3c2 added theorem database which contains axioms and theorems indexed by the
clasohm
parents:
diff changeset
   103
end;
6204
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
   104
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
   105
structure BasicThmDatabase: BASIC_THM_DATABASE = ThmDatabase;
c7ad5b27894f open BasicThmDatabase;
wenzelm
parents: 5744
diff changeset
   106
open BasicThmDatabase;