src/Pure/pure_thy.ML
author paulson
Sat, 10 Jan 1998 17:59:32 +0100
changeset 4552 bb8ff763c93d
parent 4498 a088ec3e4f5e
child 4590 9f8f931e0089
permissions -rw-r--r--
Simplified proofs by omitting PA = {|XA, ...|} from RA2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/pure_thy.ML
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     4
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     5
Init 'theorems' data.  The Pure theories.
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     6
*)
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
     7
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
     8
signature BASIC_PURE_THY =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
     9
sig
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    10
  val get_thm: theory -> xstring -> thm
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    11
  val get_thms: theory -> xstring -> thm list
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    12
  val thms_of: theory -> (string * thm) list
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    13
end
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    14
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    15
signature PURE_THY =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    16
sig
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    17
  include BASIC_PURE_THY
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    18
  val thms_containing: theory -> string list -> (string * thm) list
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    19
  val store_thms: (bstring * thm) list -> theory -> theory
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    20
  val store_thmss: (bstring * thm list) list -> theory -> theory
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    21
  val smart_store_thm: (bstring * thm) -> thm
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    22
  val add_store_axioms: (bstring * string) list -> theory -> theory
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    23
  val add_store_axioms_i: (bstring * term) list -> theory -> theory
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    24
  val add_store_defs: (bstring * string) list -> theory -> theory
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    25
  val add_store_defs_i: (bstring * term) list -> theory -> theory
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    26
  val proto_pure: theory
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    27
  val pure: theory
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    28
  val cpure: theory
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    29
end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    30
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    31
structure PureThy: PURE_THY =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    32
struct
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    33
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    34
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    35
(*** init theorems data ***)
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    36
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    37
(** data kind theorems **)
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    38
4049
b2a70d318df2 tuned thy_data;
wenzelm
parents: 4037
diff changeset
    39
val theoremsK = "theorems";
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    40
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    41
exception Theorems of
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    42
 {space: NameSpace.T,
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    43
  thms_tab: thm list Symtab.table,
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    44
  const_idx: int * (int * thm) list Symtab.table} ref;
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    45
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    46
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    47
(* methods *)
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    48
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    49
local
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    50
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    51
fun mk_empty _ =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    52
  Theorems (ref {space = NameSpace.empty,
4487
9b4c1db5aca1 renamed Symtab.null to Symtab.empty;
wenzelm
parents: 4258
diff changeset
    53
    thms_tab = Symtab.empty, const_idx = (0, Symtab.empty)});
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    54
4258
f2ca5a87f0a7 improved theorems print method: transfer_sg;
wenzelm
parents: 4124
diff changeset
    55
fun print sg (Theorems (ref {space, thms_tab, const_idx = _})) =
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    56
  let
4258
f2ca5a87f0a7 improved theorems print method: transfer_sg;
wenzelm
parents: 4124
diff changeset
    57
    val prt_thm = Pretty.quote o Display.pretty_thm o Thm.transfer_sg sg;
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    58
    fun prt_thms (name, [th]) =
4037
wenzelm
parents: 4022
diff changeset
    59
          Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, prt_thm th]
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    60
      | prt_thms (name, ths) = Pretty.big_list (name ^ ":") (map prt_thm ths);
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    61
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    62
    fun extrn name =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    63
      if ! long_names then name else NameSpace.extern space name;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    64
    val thmss = sort_wrt fst (map (apfst extrn) (Symtab.dest thms_tab));
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    65
  in
4498
a088ec3e4f5e pretty_name_space;
wenzelm
parents: 4487
diff changeset
    66
    Pretty.writeln (Display.pretty_name_space ("theorem name space", space));
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    67
    Pretty.writeln (Pretty.big_list "theorems:" (map prt_thms thmss))
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    68
  end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    69
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    70
in
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    71
4124
1af16493c57f type object = exn (enhance readability);
wenzelm
parents: 4073
diff changeset
    72
val theorems_data: string * (object * (object -> object) *
4258
f2ca5a87f0a7 improved theorems print method: transfer_sg;
wenzelm
parents: 4124
diff changeset
    73
  (object * object -> object) * (Sign.sg -> object -> unit)) =
4073
d16ff2cc1089 made SML/97 happy;
wenzelm
parents: 4049
diff changeset
    74
    (theoremsK, (mk_empty (), mk_empty, mk_empty, print));
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    75
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    76
end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    77
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    78
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    79
(* get data record *)
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    80
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    81
fun get_theorems_sg sg =
4049
b2a70d318df2 tuned thy_data;
wenzelm
parents: 4037
diff changeset
    82
  (case Sign.get_data sg theoremsK of
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    83
    Theorems r => r
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    84
  | _ => sys_error "get_theorems_sg");
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    85
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    86
val get_theorems = get_theorems_sg o sign_of;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    87
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    88
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    89
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    90
(** retrieve theorems **)
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    91
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    92
fun local_thms thy name =
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
    93
  let
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    94
    val ref {space, thms_tab, ...} = get_theorems thy;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    95
    val full_name = NameSpace.intern space name;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    96
  in Symtab.lookup (thms_tab, full_name) end;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    97
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    98
fun all_local_thms [] _ = None
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
    99
  | all_local_thms (thy :: thys) name =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   100
      (case local_thms thy name of
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   101
        None => all_local_thms thys name
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   102
      | some => some);
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   103
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   104
4037
wenzelm
parents: 4022
diff changeset
   105
(* get_thm(s) *)
wenzelm
parents: 4022
diff changeset
   106
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   107
fun get_thms thy name =
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   108
  (case all_local_thms (thy :: Theory.ancestors_of thy) name of
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   109
    None => raise THEORY ("Theorems " ^ quote name ^ " not stored in theory", [thy])
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   110
  | Some thms => thms);
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   111
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   112
fun get_thm thy name =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   113
  (case get_thms thy name of
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   114
    [thm] => thm
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   115
  | _ => raise THEORY ("Singleton list of theorems expected " ^ quote name, [thy]));
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   116
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   117
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   118
(* thms_of *)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   119
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   120
fun attach_name thm = (Thm.name_of_thm thm, thm);
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   121
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   122
fun thms_of thy =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   123
  let val ref {thms_tab, ...} = get_theorems thy in
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   124
    map attach_name (flat (map snd (Symtab.dest thms_tab)))
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   125
  end;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   126
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   127
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   128
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   129
(** theorems indexed by constants **)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   130
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   131
(* make index *)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   132
4037
wenzelm
parents: 4022
diff changeset
   133
val ignore = ["Trueprop", "all", "==>", "=="];
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   134
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   135
fun add_const_idx ((next, table), thm) =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   136
  let
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   137
    val {hyps, prop, ...} = Thm.rep_thm thm;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   138
    val consts =
4037
wenzelm
parents: 4022
diff changeset
   139
      foldr add_term_consts (hyps, add_term_consts (prop, [])) \\ ignore;
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   140
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   141
    fun add (tab, c) =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   142
      Symtab.update ((c, (next, thm) :: Symtab.lookup_multi (tab, c)), tab);
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   143
  in (next + 1, foldl add (table, consts)) end;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   144
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   145
fun make_const_idx thm_tab =
4487
9b4c1db5aca1 renamed Symtab.null to Symtab.empty;
wenzelm
parents: 4258
diff changeset
   146
  foldl (foldl add_const_idx) ((0, Symtab.empty), map snd (Symtab.dest thm_tab));
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   147
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   148
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   149
(* lookup index *)
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   150
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   151
(*search locally*)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   152
fun containing [] thy = thms_of thy
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   153
  | containing consts thy =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   154
      let
4037
wenzelm
parents: 4022
diff changeset
   155
        fun int ([], _) = []
wenzelm
parents: 4022
diff changeset
   156
          | int (_, []) = []
wenzelm
parents: 4022
diff changeset
   157
          | int (xxs as ((x as (i:int, _)) :: xs), yys as ((y as (j, _)) :: ys)) =
wenzelm
parents: 4022
diff changeset
   158
              if i = j then x :: int (xs, ys)
wenzelm
parents: 4022
diff changeset
   159
              else if i > j then int (xs, yys)
wenzelm
parents: 4022
diff changeset
   160
              else int (xxs, ys);
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   161
4037
wenzelm
parents: 4022
diff changeset
   162
        fun ints [xs] = xs
wenzelm
parents: 4022
diff changeset
   163
          | ints xss = if exists null xss then [] else foldl int (hd xss, tl xss);
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   164
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   165
        val ref {const_idx = (_, ctab), ...} = get_theorems thy;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   166
        val ithmss = map (fn c => Symtab.lookup_multi (ctab, c)) consts;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   167
      in
4037
wenzelm
parents: 4022
diff changeset
   168
        map (attach_name o snd) (ints ithmss)
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   169
      end;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   170
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   171
(*search globally*)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   172
fun thms_containing thy consts =
4037
wenzelm
parents: 4022
diff changeset
   173
  flat (map (containing (consts \\ ignore)) (thy :: Theory.ancestors_of thy));
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   174
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   175
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   176
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   177
(** store theorems **)                    (*DESTRUCTIVE*)
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   178
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   179
fun warn_overwrite name =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   180
  warning ("Replaced old copy of theorems " ^ quote name);
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   181
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   182
fun warn_same name =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   183
  warning ("Theorem database already contains a copy of " ^ quote name);
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   184
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   185
fun enter_thms sg single (raw_name, thms) =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   186
  let
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   187
    val len = length thms;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   188
    val name = Sign.full_name sg raw_name;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   189
    val names =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   190
      if single then replicate len name
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   191
      else map (fn i => name ^ "_" ^ string_of_int i) (0 upto (len - 1));
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   192
    val named_thms = ListPair.map Thm.name_thm (names, thms);
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   193
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   194
    val eq_thms = ListPair.all Thm.eq_thm;
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   195
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   196
    val r as ref {space, thms_tab, const_idx} = get_theorems_sg sg;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   197
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   198
    val overwrite =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   199
      (case Symtab.lookup (thms_tab, name) of
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   200
        None => false
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   201
      | Some thms' =>
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   202
          if length thms' = len andalso eq_thms (thms', named_thms) then
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   203
            (warn_same name; false)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   204
          else (warn_overwrite name; true));
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   205
4487
9b4c1db5aca1 renamed Symtab.null to Symtab.empty;
wenzelm
parents: 4258
diff changeset
   206
    val space' = NameSpace.extend (space, [name]);
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   207
    val thms_tab' = Symtab.update ((name, named_thms), thms_tab);
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   208
    val const_idx' =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   209
      if overwrite then make_const_idx thms_tab'
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   210
      else foldl add_const_idx (const_idx, named_thms);
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   211
  in
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   212
    r := {space = space', thms_tab = thms_tab', const_idx = const_idx'};
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   213
    named_thms
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   214
  end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   215
4037
wenzelm
parents: 4022
diff changeset
   216
fun do_enter_thms sg single thms = (enter_thms sg single thms; ());
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   217
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   218
4012
6adc18bd0009 renamed put_* to store_*;
wenzelm
parents: 4002
diff changeset
   219
fun store_thmss thmss thy =
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   220
  (seq (do_enter_thms (sign_of thy) false) thmss; thy);
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   221
4012
6adc18bd0009 renamed put_* to store_*;
wenzelm
parents: 4002
diff changeset
   222
fun store_thms thms thy =
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   223
  (seq (do_enter_thms (sign_of thy) true) (map (apsnd (fn th => [th])) thms); thy);
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   224
4012
6adc18bd0009 renamed put_* to store_*;
wenzelm
parents: 4002
diff changeset
   225
fun smart_store_thm (name, thm) =
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   226
  let val [named_thm] = enter_thms (Thm.sign_of_thm thm) true (name, [thm])
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   227
  in named_thm end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   228
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   229
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   230
(* store axioms as theorems *)
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   231
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   232
fun add_store add named_axs thy =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   233
  let
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   234
    val thy' = add named_axs thy;
4037
wenzelm
parents: 4022
diff changeset
   235
    val named_thms = map (fn (name, _) => (name, get_axiom thy' name)) named_axs;
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   236
  in store_thms named_thms thy' end;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   237
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   238
val add_store_axioms = add_store Theory.add_axioms;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   239
val add_store_axioms_i = add_store Theory.add_axioms_i;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   240
val add_store_defs = add_store Theory.add_defs;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   241
val add_store_defs_i = add_store Theory.add_defs_i;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   242
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   243
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   244
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   245
(** the Pure theories **)
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   246
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   247
val proto_pure =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   248
  Theory.pre_pure
4049
b2a70d318df2 tuned thy_data;
wenzelm
parents: 4037
diff changeset
   249
  |> Theory.init_data [theorems_data]
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   250
  |> Theory.add_types
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   251
   (("fun", 2, NoSyn) ::
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   252
    ("prop", 0, NoSyn) ::
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   253
    ("itself", 1, NoSyn) ::
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   254
    Syntax.pure_types)
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   255
  |> Theory.add_classes_i [(logicC, [])]
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   256
  |> Theory.add_defsort_i logicS
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   257
  |> Theory.add_arities_i
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   258
   [("fun", [logicS, logicS], logicS),
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   259
    ("prop", [], logicS),
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   260
    ("itself", [logicS], logicS)]
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   261
  |> Theory.add_syntax Syntax.pure_syntax
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   262
  |> Theory.add_modesyntax ("symbols", true) Syntax.pure_sym_syntax
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   263
  |> Theory.add_trfuns Syntax.pure_trfuns
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   264
  |> Theory.add_trfunsT Syntax.pure_trfunsT
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   265
  |> Theory.add_syntax
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   266
   [("==>", "[prop, prop] => prop", Delimfix "op ==>")]
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   267
  |> Theory.add_consts
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   268
   [("==", "['a::{}, 'a] => prop", InfixrName ("==", 2)),
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   269
    ("=?=", "['a::{}, 'a] => prop", InfixrName ("=?=", 2)),
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   270
    ("==>", "[prop, prop] => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   271
    ("all", "('a => prop) => prop", Binder ("!!", 0, 0)),
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   272
    ("TYPE", "'a itself", NoSyn)]
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   273
  |> Theory.add_path "ProtoPure"
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   274
  |> add_store_defs [("flexpair_def", "(t =?= u) == (t == u::'a::{})")]
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   275
  |> Theory.add_name "ProtoPure";
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   276
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   277
val pure =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   278
  Theory.prep_ext_merge [proto_pure]
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   279
  |> Theory.add_syntax Syntax.pure_appl_syntax
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   280
  |> Theory.add_path "Pure"
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   281
  |> Theory.add_name "Pure";
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   282
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   283
val cpure =
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   284
  Theory.prep_ext_merge [proto_pure]
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   285
  |> Theory.add_syntax Syntax.pure_applC_syntax
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   286
  |> Theory.add_path "CPure"
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   287
  |> Theory.add_name "CPure";
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   288
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   289
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   290
end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   291
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   292
4022
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   293
structure BasicPureThy: BASIC_PURE_THY = PureThy;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   294
open BasicPureThy;
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   295
0770a19c48d3 added ignored_consts, thms_containing, add_store_axioms(_i),
wenzelm
parents: 4013
diff changeset
   296
3987
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   297
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   298
(** theory structures **)
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   299
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   300
structure ProtoPure =
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   301
struct
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   302
  val thy = PureThy.proto_pure;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   303
  val flexpair_def = get_axiom thy "flexpair_def";
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   304
end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   305
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   306
structure Pure = struct val thy = PureThy.pure end;
22f5291012df Init 'theorems' data. The Pure theories.
wenzelm
parents:
diff changeset
   307
structure CPure = struct val thy = PureThy.cpure end;