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