author | paulson |
Fri, 21 Jan 2005 18:00:18 +0100 | |
changeset 15452 | e2a721567f67 |
parent 15036 | cab1c1fc1851 |
child 15496 | 3263daa96167 |
permissions | -rw-r--r-- |
1243 | 1 |
(* Title: Provers/simplifier.ML |
1 | 2 |
ID: $Id$ |
3557 | 3 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
1 | 4 |
|
10412
1a1b4c1b2b7c
Moved meta simplification stuff from Thm to MetaSimplifier.
berghofe
parents:
10034
diff
changeset
|
5 |
Generic simplifier, suitable for most logics. See Pure/meta_simplifier.ML |
1a1b4c1b2b7c
Moved meta simplification stuff from Thm to MetaSimplifier.
berghofe
parents:
10034
diff
changeset
|
6 |
for the actual meta-level rewriting engine. |
1 | 7 |
*) |
1260 | 8 |
|
15452 | 9 |
(* added: put_delta_simpset, get_delta_simpset |
10 |
changed: simp_add_local |
|
11 |
07/01/05 |
|
12 |
*) |
|
13 |
||
14 |
||
4795 | 15 |
signature BASIC_SIMPLIFIER = |
0 | 16 |
sig |
15024 | 17 |
include BASIC_META_SIMPLIFIER |
15036 | 18 |
type context_solver |
19 |
val mk_context_solver: string -> (Proof.context -> thm list -> int -> tactic) |
|
20 |
-> context_solver |
|
21 |
type context_simproc |
|
22 |
val mk_context_simproc: string -> cterm list -> |
|
23 |
(Proof.context -> simpset -> term -> thm option) -> context_simproc |
|
4366 | 24 |
val print_simpset: theory -> unit |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
25 |
val simpset_ref_of_sg: Sign.sg -> simpset ref |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
26 |
val simpset_ref_of: theory -> simpset ref |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
27 |
val simpset_of_sg: Sign.sg -> simpset |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
28 |
val simpset_of: theory -> simpset |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
29 |
val SIMPSET: (simpset -> tactic) -> tactic |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
30 |
val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
31 |
val simpset: unit -> simpset |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
32 |
val simpset_ref: unit -> simpset ref |
1243 | 33 |
val Addsimps: thm list -> unit |
34 |
val Delsimps: thm list -> unit |
|
2509 | 35 |
val Addsimprocs: simproc list -> unit |
36 |
val Delsimprocs: simproc list -> unit |
|
9715 | 37 |
val Addcongs: thm list -> unit |
38 |
val Delcongs: thm list -> unit |
|
15036 | 39 |
val local_simpset_of: Proof.context -> simpset |
10004 | 40 |
val safe_asm_full_simp_tac: simpset -> int -> tactic |
2629 | 41 |
val simp_tac: simpset -> int -> tactic |
42 |
val asm_simp_tac: simpset -> int -> tactic |
|
43 |
val full_simp_tac: simpset -> int -> tactic |
|
4722
d2e44673c21e
The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents:
4713
diff
changeset
|
44 |
val asm_lr_simp_tac: simpset -> int -> tactic |
2629 | 45 |
val asm_full_simp_tac: simpset -> int -> tactic |
46 |
val Simp_tac: int -> tactic |
|
47 |
val Asm_simp_tac: int -> tactic |
|
48 |
val Full_simp_tac: int -> tactic |
|
4722
d2e44673c21e
The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents:
4713
diff
changeset
|
49 |
val Asm_lr_simp_tac: int -> tactic |
2629 | 50 |
val Asm_full_simp_tac: int -> tactic |
3557 | 51 |
val simplify: simpset -> thm -> thm |
52 |
val asm_simplify: simpset -> thm -> thm |
|
53 |
val full_simplify: simpset -> thm -> thm |
|
14814
c6b91c8aee1d
added asm_lr_simplify/asm_lr_rewrite and adapted asm_full_simplify/asm_full_rewrite to match to corresponding simp_tacs
schirmer
parents:
13605
diff
changeset
|
54 |
val asm_lr_simplify: simpset -> thm -> thm |
3557 | 55 |
val asm_full_simplify: simpset -> thm -> thm |
0 | 56 |
end; |
57 |
||
4795 | 58 |
signature SIMPLIFIER = |
59 |
sig |
|
60 |
include BASIC_SIMPLIFIER |
|
15036 | 61 |
val simproc_i: Sign.sg -> string -> term list |
62 |
-> (Sign.sg -> simpset -> term -> thm option) -> simproc |
|
63 |
val simproc: Sign.sg -> string -> string list |
|
64 |
-> (Sign.sg -> simpset -> term -> thm option) -> simproc |
|
65 |
val context_simproc_i: Sign.sg -> string -> term list |
|
66 |
-> (Proof.context -> simpset -> term -> thm option) -> context_simproc |
|
67 |
val context_simproc: Sign.sg -> string -> string list |
|
68 |
-> (Proof.context -> simpset -> term -> thm option) -> context_simproc |
|
5082 | 69 |
val rewrite: simpset -> cterm -> thm |
70 |
val asm_rewrite: simpset -> cterm -> thm |
|
71 |
val full_rewrite: simpset -> cterm -> thm |
|
14814
c6b91c8aee1d
added asm_lr_simplify/asm_lr_rewrite and adapted asm_full_simplify/asm_full_rewrite to match to corresponding simp_tacs
schirmer
parents:
13605
diff
changeset
|
72 |
val asm_lr_rewrite: simpset -> cterm -> thm |
5082 | 73 |
val asm_full_rewrite: simpset -> cterm -> thm |
15036 | 74 |
val add_context_simprocs: context_simproc list -> theory -> theory |
75 |
val del_context_simprocs: context_simproc list -> theory -> theory |
|
76 |
val set_context_subgoaler: (Proof.context -> simpset -> int -> tactic) -> theory -> theory |
|
77 |
val reset_context_subgoaler: theory -> theory |
|
78 |
val add_context_looper: string * (Proof.context -> int -> Tactical.tactic) -> |
|
79 |
theory -> theory |
|
80 |
val del_context_looper: string -> theory -> theory |
|
81 |
val add_context_unsafe_solver: context_solver -> theory -> theory |
|
82 |
val add_context_safe_solver: context_solver -> theory -> theory |
|
5842 | 83 |
val print_local_simpset: Proof.context -> unit |
84 |
val get_local_simpset: Proof.context -> simpset |
|
85 |
val put_local_simpset: simpset -> Proof.context -> Proof.context |
|
8467 | 86 |
val change_global_ss: (simpset * thm list -> simpset) -> theory attribute |
87 |
val change_local_ss: (simpset * thm list -> simpset) -> Proof.context attribute |
|
4855 | 88 |
val simp_add_global: theory attribute |
89 |
val simp_del_global: theory attribute |
|
5842 | 90 |
val simp_add_local: Proof.context attribute |
91 |
val simp_del_local: Proof.context attribute |
|
9715 | 92 |
val cong_add_global: theory attribute |
93 |
val cong_del_global: theory attribute |
|
94 |
val cong_add_local: Proof.context attribute |
|
95 |
val cong_del_local: Proof.context attribute |
|
7177 | 96 |
val change_simpset_of: (simpset * 'a -> simpset) -> 'a -> theory -> theory |
7273 | 97 |
val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list |
5842 | 98 |
val setup: (theory -> theory) list |
8467 | 99 |
val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list |
100 |
-> (theory -> theory) list |
|
8228 | 101 |
val easy_setup: thm -> thm list -> (theory -> theory) list |
15452 | 102 |
|
103 |
val get_delta_simpset: ProofContext.context -> Thm.thm list |
|
104 |
val put_delta_simpset: Thm.thm list -> ProofContext.context -> ProofContext.context |
|
105 |
||
4795 | 106 |
end; |
2503 | 107 |
|
108 |
structure Simplifier: SIMPLIFIER = |
|
0 | 109 |
struct |
110 |
||
15006
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier. Next step:
skalberg
parents:
14814
diff
changeset
|
111 |
open MetaSimplifier; |
8467 | 112 |
|
15024 | 113 |
|
15036 | 114 |
(** context dependent simpset components **) |
115 |
||
116 |
(* datatype context_solver *) |
|
117 |
||
118 |
datatype context_solver = |
|
119 |
ContextSolver of (string * (Proof.context -> thm list -> int -> tactic)) * stamp; |
|
120 |
||
121 |
fun mk_context_solver name f = ContextSolver ((name, f), stamp ()); |
|
122 |
fun eq_context_solver (ContextSolver (_, id1), ContextSolver (_, id2)) = (id1 = id2); |
|
123 |
val merge_context_solvers = gen_merge_lists eq_context_solver; |
|
124 |
||
125 |
||
126 |
(* datatype context_simproc *) |
|
127 |
||
128 |
datatype context_simproc = ContextSimproc of |
|
129 |
(string * cterm list * (Proof.context -> simpset -> term -> thm option)) * stamp; |
|
130 |
||
131 |
fun mk_context_simproc name lhss f = ContextSimproc ((name, lhss, f), stamp ()); |
|
132 |
fun eq_context_simproc (ContextSimproc (_, id1), ContextSimproc (_, id2)) = (id1 = id2); |
|
133 |
val merge_context_simprocs = gen_merge_lists eq_context_simproc; |
|
134 |
||
135 |
fun context_simproc_i sg name = |
|
136 |
mk_context_simproc name o map (Thm.cterm_of sg o Logic.varify); |
|
137 |
||
138 |
fun context_simproc sg name = |
|
139 |
context_simproc_i sg name o map (Sign.simple_read_term sg TypeInfer.logicT); |
|
140 |
||
141 |
||
142 |
(* datatype context_ss *) |
|
143 |
||
144 |
datatype context_ss = ContextSS of |
|
145 |
{simprocs: context_simproc list, |
|
146 |
subgoal_tac: (Proof.context -> simpset -> int -> tactic) option, |
|
147 |
loop_tacs: (string * (Proof.context -> int -> tactic)) list, |
|
148 |
unsafe_solvers: context_solver list, |
|
149 |
solvers: context_solver list}; |
|
150 |
||
151 |
fun context_ss ctxt ss ctxt_ss = |
|
152 |
let |
|
153 |
val ContextSS {simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers} = ctxt_ss; |
|
154 |
fun prep_simproc (ContextSimproc ((name, lhss, f), _)) = |
|
155 |
mk_simproc name lhss (K (f ctxt)); |
|
156 |
fun add_loop (name, f) simpset = simpset addloop (name, f ctxt); |
|
157 |
fun add_solver add (ContextSolver ((name, f), _)) simpset = |
|
158 |
add (simpset, mk_solver name (f ctxt)); |
|
159 |
in |
|
160 |
((case subgoal_tac of None => ss | Some tac => ss setsubgoaler tac ctxt) |
|
161 |
addsimprocs map prep_simproc simprocs) |
|
162 |
|> fold_rev add_loop loop_tacs |
|
163 |
|> fold_rev (add_solver (op addSolver)) unsafe_solvers |
|
164 |
|> fold_rev (add_solver (op addSSolver)) solvers |
|
165 |
end; |
|
166 |
||
167 |
fun make_context_ss (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) = |
|
168 |
ContextSS {simprocs = simprocs, subgoal_tac = subgoal_tac, loop_tacs = loop_tacs, |
|
169 |
unsafe_solvers = unsafe_solvers, solvers = solvers}; |
|
170 |
||
171 |
val empty_context_ss = make_context_ss ([], None, [], [], []); |
|
172 |
||
173 |
fun merge_context_ss (ctxt_ss1, ctxt_ss2) = |
|
174 |
let |
|
175 |
val ContextSS {simprocs = simprocs1, subgoal_tac = subgoal_tac1, loop_tacs = loop_tacs1, |
|
176 |
unsafe_solvers = unsafe_solvers1, solvers = solvers1} = ctxt_ss1; |
|
177 |
val ContextSS {simprocs = simprocs2, subgoal_tac = subgoal_tac2, loop_tacs = loop_tacs2, |
|
178 |
unsafe_solvers = unsafe_solvers2, solvers = solvers2} = ctxt_ss2; |
|
179 |
||
180 |
val simprocs' = merge_context_simprocs simprocs1 simprocs2; |
|
181 |
val subgoal_tac' = (case subgoal_tac1 of None => subgoal_tac2 | some => some); |
|
182 |
val loop_tacs' = merge_alists loop_tacs1 loop_tacs2; |
|
183 |
val unsafe_solvers' = merge_context_solvers unsafe_solvers1 unsafe_solvers2; |
|
184 |
val solvers' = merge_context_solvers solvers1 solvers2; |
|
185 |
in make_context_ss (simprocs', subgoal_tac', loop_tacs', unsafe_solvers', solvers') end; |
|
186 |
||
187 |
||
188 |
||
5024 | 189 |
(** global and local simpset data **) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
190 |
|
5842 | 191 |
(* theory data kind 'Provers/simpset' *) |
4795 | 192 |
|
5842 | 193 |
structure GlobalSimpsetArgs = |
5024 | 194 |
struct |
5842 | 195 |
val name = "Provers/simpset"; |
15036 | 196 |
type T = simpset ref * context_ss; |
0 | 197 |
|
15036 | 198 |
val empty = (ref empty_ss, empty_context_ss); |
199 |
fun copy (ref ss, ctxt_ss) = (ref ss, ctxt_ss): T; (*create new reference!*) |
|
6556 | 200 |
val prep_ext = copy; |
15036 | 201 |
fun merge ((ref ss1, ctxt_ss1), (ref ss2, ctxt_ss2)) = |
202 |
(ref (merge_ss (ss1, ss2)), merge_context_ss (ctxt_ss1, ctxt_ss2)); |
|
203 |
fun print _ (ref ss, _) = print_ss ss; |
|
5024 | 204 |
end; |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
205 |
|
5842 | 206 |
structure GlobalSimpset = TheoryDataFun(GlobalSimpsetArgs); |
207 |
val print_simpset = GlobalSimpset.print; |
|
15036 | 208 |
val simpset_ref_of_sg = #1 o GlobalSimpset.get_sg; |
209 |
val simpset_ref_of = #1 o GlobalSimpset.get; |
|
210 |
val get_context_ss = #2 o GlobalSimpset.get o ProofContext.theory_of; |
|
211 |
||
212 |
fun map_context_ss f = GlobalSimpset.map (apsnd |
|
213 |
(fn ContextSS {simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers} => |
|
214 |
make_context_ss (f (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers)))); |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
215 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
216 |
|
4795 | 217 |
(* access global simpset *) |
0 | 218 |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
219 |
val simpset_of_sg = ! o simpset_ref_of_sg; |
6391 | 220 |
val simpset_of = simpset_of_sg o Theory.sign_of; |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
221 |
|
6391 | 222 |
fun SIMPSET tacf state = tacf (simpset_of_sg (Thm.sign_of_thm state)) state; |
223 |
fun SIMPSET' tacf i state = tacf (simpset_of_sg (Thm.sign_of_thm state)) i state; |
|
0 | 224 |
|
5028 | 225 |
val simpset = simpset_of o Context.the_context; |
6391 | 226 |
val simpset_ref = simpset_ref_of_sg o Theory.sign_of o Context.the_context; |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
227 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
228 |
|
4795 | 229 |
(* change global simpset *) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
230 |
|
7177 | 231 |
fun change_simpset_of f x thy = |
232 |
let val r = simpset_ref_of thy |
|
233 |
in r := f (! r, x); thy end; |
|
234 |
||
235 |
fun change_simpset f x = (change_simpset_of f x (Context.the_context ()); ()); |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
236 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
237 |
val Addsimps = change_simpset (op addsimps); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
238 |
val Delsimps = change_simpset (op delsimps); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
239 |
val Addsimprocs = change_simpset (op addsimprocs); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
240 |
val Delsimprocs = change_simpset (op delsimprocs); |
9715 | 241 |
val Addcongs = change_simpset (op addcongs); |
242 |
val Delcongs = change_simpset (op delcongs); |
|
2509 | 243 |
|
0 | 244 |
|
15036 | 245 |
(* change context dependent components *) |
246 |
||
247 |
fun add_context_simprocs procs = |
|
248 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
249 |
(merge_context_simprocs procs simprocs, subgoal_tac, loop_tacs, |
|
250 |
unsafe_solvers, solvers)); |
|
251 |
||
252 |
fun del_context_simprocs procs = |
|
253 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
254 |
(gen_rems eq_context_simproc (simprocs, procs), subgoal_tac, loop_tacs, |
|
255 |
unsafe_solvers, solvers)); |
|
256 |
||
257 |
fun set_context_subgoaler tac = |
|
258 |
map_context_ss (fn (simprocs, _, loop_tacs, unsafe_solvers, solvers) => |
|
259 |
(simprocs, Some tac, loop_tacs, unsafe_solvers, solvers)); |
|
260 |
||
261 |
val reset_context_subgoaler = |
|
262 |
map_context_ss (fn (simprocs, _, loop_tacs, unsafe_solvers, solvers) => |
|
263 |
(simprocs, None, loop_tacs, unsafe_solvers, solvers)); |
|
264 |
||
265 |
fun add_context_looper (name, tac) = |
|
266 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
267 |
(simprocs, subgoal_tac, merge_alists [(name, tac)] loop_tacs, |
|
268 |
unsafe_solvers, solvers)); |
|
269 |
||
270 |
fun del_context_looper name = |
|
271 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
272 |
(simprocs, subgoal_tac, filter_out (equal name o #1) loop_tacs, |
|
273 |
unsafe_solvers, solvers)); |
|
274 |
||
275 |
fun add_context_unsafe_solver solver = |
|
276 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
277 |
(simprocs, subgoal_tac, loop_tacs, |
|
278 |
merge_context_solvers [solver] unsafe_solvers, solvers)); |
|
279 |
||
280 |
fun add_context_safe_solver solver = |
|
281 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
282 |
(simprocs, subgoal_tac, loop_tacs, unsafe_solvers, |
|
283 |
merge_context_solvers [solver] solvers)); |
|
284 |
||
285 |
||
5842 | 286 |
(* proof data kind 'Provers/simpset' *) |
4795 | 287 |
|
5842 | 288 |
structure LocalSimpsetArgs = |
289 |
struct |
|
290 |
val name = "Provers/simpset"; |
|
291 |
type T = simpset; |
|
292 |
val init = simpset_of; |
|
15036 | 293 |
fun print ctxt ss = print_ss (context_ss ctxt ss (get_context_ss ctxt)); |
5842 | 294 |
end; |
4795 | 295 |
|
5842 | 296 |
structure LocalSimpset = ProofDataFun(LocalSimpsetArgs); |
297 |
val print_local_simpset = LocalSimpset.print; |
|
298 |
val get_local_simpset = LocalSimpset.get; |
|
299 |
val put_local_simpset = LocalSimpset.put; |
|
7273 | 300 |
fun map_local_simpset f ctxt = put_local_simpset (f (get_local_simpset ctxt)) ctxt; |
4795 | 301 |
|
15036 | 302 |
fun local_simpset_of ctxt = |
303 |
context_ss ctxt (get_local_simpset ctxt) (get_context_ss ctxt); |
|
304 |
||
4795 | 305 |
|
15452 | 306 |
(* Jia: added DeltaSimpsetArgs and DeltaSimpset for delta_simpset |
307 |
also added methods to retrieve them. *) |
|
308 |
||
309 |
structure DeltaSimpsetArgs = |
|
310 |
struct |
|
311 |
val name = "delta_simpset"; |
|
312 |
type T = Thm.thm list; (*the type is thm list*) |
|
313 |
val empty = []; |
|
314 |
end; |
|
315 |
||
316 |
structure DeltaSimpset = DeltaDataFun(DeltaSimpsetArgs); |
|
317 |
val get_delta_simpset = DeltaSimpset.get; |
|
318 |
val put_delta_simpset = DeltaSimpset.put; |
|
319 |
||
320 |
val get_new_thm_id = ProofContext.get_delta_count_incr; |
|
321 |
||
322 |
(* Jia: added to rename a local thm if necessary *) |
|
323 |
local |
|
324 |
fun rename_thm' (ctxt,thm) = |
|
325 |
let val new_id = get_new_thm_id ctxt |
|
326 |
val new_name = "anon_" ^ (string_of_int new_id) |
|
327 |
in |
|
328 |
Thm.name_thm(new_name,thm) |
|
329 |
end; |
|
330 |
||
331 |
in |
|
332 |
||
333 |
fun rename_thm (ctxt,thm) = if (!Proof.call_atp) then rename_thm' (ctxt,thm) else thm; |
|
334 |
||
335 |
end |
|
336 |
||
5886 | 337 |
(* attributes *) |
338 |
||
339 |
fun change_global_ss f (thy, th) = |
|
340 |
let val r = simpset_ref_of thy |
|
6096 | 341 |
in r := f (! r, [th]); (thy, th) end; |
5886 | 342 |
|
343 |
fun change_local_ss f (ctxt, th) = |
|
6096 | 344 |
let val ss = f (get_local_simpset ctxt, [th]) |
5886 | 345 |
in (put_local_simpset ss ctxt, th) end; |
346 |
||
347 |
val simp_add_global = change_global_ss (op addsimps); |
|
348 |
val simp_del_global = change_global_ss (op delsimps); |
|
15452 | 349 |
|
350 |
||
351 |
||
352 |
||
353 |
||
354 |
(* Jia: note: when simplifier rules are added to local_simpset, they are also added to delta_simpset in ProofContext.context, but not removed if simp_del_local is called *) |
|
355 |
fun simp_add_local (ctxt,th) = |
|
356 |
let val delta_ss = get_delta_simpset ctxt |
|
357 |
val thm_name = Thm.name_of_thm th |
|
358 |
val th' = if (thm_name = "") then rename_thm (ctxt,th) else th |
|
359 |
val new_dss = th'::delta_ss |
|
360 |
val ctxt' = put_delta_simpset new_dss ctxt |
|
361 |
in |
|
362 |
change_local_ss (op addsimps) (ctxt',th) |
|
363 |
end; |
|
364 |
||
5886 | 365 |
val simp_del_local = change_local_ss (op delsimps); |
366 |
||
9715 | 367 |
val cong_add_global = change_global_ss (op addcongs); |
368 |
val cong_del_global = change_global_ss (op delcongs); |
|
369 |
val cong_add_local = change_local_ss (op addcongs); |
|
370 |
val cong_del_local = change_local_ss (op delcongs); |
|
371 |
||
5886 | 372 |
|
10004 | 373 |
val simp_tac = generic_simp_tac false (false, false, false); |
374 |
val asm_simp_tac = generic_simp_tac false (false, true, false); |
|
375 |
val full_simp_tac = generic_simp_tac false (true, false, false); |
|
376 |
val asm_lr_simp_tac = generic_simp_tac false (true, true, false); |
|
377 |
val asm_full_simp_tac = generic_simp_tac false (true, true, true); |
|
378 |
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true); |
|
0 | 379 |
|
2629 | 380 |
|
15006
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier. Next step:
skalberg
parents:
14814
diff
changeset
|
381 |
|
4795 | 382 |
(*the abstraction over the proof state delays the dereferencing*) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
383 |
fun Simp_tac i st = simp_tac (simpset ()) i st; |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
384 |
fun Asm_simp_tac i st = asm_simp_tac (simpset ()) i st; |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
385 |
fun Full_simp_tac i st = full_simp_tac (simpset ()) i st; |
4722
d2e44673c21e
The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents:
4713
diff
changeset
|
386 |
fun Asm_lr_simp_tac i st = asm_lr_simp_tac (simpset ()) i st; |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
387 |
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st; |
406 | 388 |
|
5082 | 389 |
val simplify = simp_thm (false, false, false); |
390 |
val asm_simplify = simp_thm (false, true, false); |
|
391 |
val full_simplify = simp_thm (true, false, false); |
|
14814
c6b91c8aee1d
added asm_lr_simplify/asm_lr_rewrite and adapted asm_full_simplify/asm_full_rewrite to match to corresponding simp_tacs
schirmer
parents:
13605
diff
changeset
|
392 |
val asm_lr_simplify = simp_thm (true, true, false); |
c6b91c8aee1d
added asm_lr_simplify/asm_lr_rewrite and adapted asm_full_simplify/asm_full_rewrite to match to corresponding simp_tacs
schirmer
parents:
13605
diff
changeset
|
393 |
val asm_full_simplify = simp_thm (true, true, true); |
5082 | 394 |
|
395 |
val rewrite = simp_cterm (false, false, false); |
|
396 |
val asm_rewrite = simp_cterm (false, true, false); |
|
397 |
val full_rewrite = simp_cterm (true, false, false); |
|
14814
c6b91c8aee1d
added asm_lr_simplify/asm_lr_rewrite and adapted asm_full_simplify/asm_full_rewrite to match to corresponding simp_tacs
schirmer
parents:
13605
diff
changeset
|
398 |
val asm_lr_rewrite = simp_cterm (true, true, false); |
c6b91c8aee1d
added asm_lr_simplify/asm_lr_rewrite and adapted asm_full_simplify/asm_full_rewrite to match to corresponding simp_tacs
schirmer
parents:
13605
diff
changeset
|
399 |
val asm_full_rewrite = simp_cterm (true, true, true); |
3557 | 400 |
|
401 |
||
4795 | 402 |
|
5886 | 403 |
(** concrete syntax of attributes **) |
5842 | 404 |
|
5886 | 405 |
(* add / del *) |
5842 | 406 |
|
5928 | 407 |
val simpN = "simp"; |
9715 | 408 |
val congN = "cong"; |
10412
1a1b4c1b2b7c
Moved meta simplification stuff from Thm to MetaSimplifier.
berghofe
parents:
10034
diff
changeset
|
409 |
val addN = "add"; |
1a1b4c1b2b7c
Moved meta simplification stuff from Thm to MetaSimplifier.
berghofe
parents:
10034
diff
changeset
|
410 |
val delN = "del"; |
6911 | 411 |
val onlyN = "only"; |
9899 | 412 |
val no_asmN = "no_asm"; |
413 |
val no_asm_useN = "no_asm_use"; |
|
414 |
val no_asm_simpN = "no_asm_simp"; |
|
13605 | 415 |
val asm_lrN = "asm_lr"; |
5842 | 416 |
|
8634 | 417 |
val simp_attr = |
418 |
(Attrib.add_del_args simp_add_global simp_del_global, |
|
419 |
Attrib.add_del_args simp_add_local simp_del_local); |
|
5842 | 420 |
|
9715 | 421 |
val cong_attr = |
422 |
(Attrib.add_del_args cong_add_global cong_del_global, |
|
423 |
Attrib.add_del_args cong_add_local cong_del_local); |
|
424 |
||
5842 | 425 |
|
426 |
(* conversions *) |
|
427 |
||
9899 | 428 |
local |
429 |
||
430 |
fun conv_mode x = |
|
431 |
((Args.parens (Args.$$$ no_asmN) >> K simplify || |
|
432 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify || |
|
433 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simplify || |
|
434 |
Scan.succeed asm_full_simplify) |> Scan.lift) x; |
|
435 |
||
11938 | 436 |
fun simplified_att get args = |
437 |
Attrib.syntax (conv_mode -- args >> (fn (f, ths) => |
|
438 |
Drule.rule_attribute (fn x => f ((if null ths then I else clear_ss) (get x) addsimps ths)))); |
|
9899 | 439 |
|
440 |
in |
|
441 |
||
442 |
val simplified_attr = |
|
11938 | 443 |
(simplified_att simpset_of Attrib.global_thmss, |
15036 | 444 |
simplified_att local_simpset_of Attrib.local_thmss); |
9899 | 445 |
|
446 |
end; |
|
5842 | 447 |
|
448 |
||
449 |
(* setup_attrs *) |
|
450 |
||
451 |
val setup_attrs = Attrib.add_attributes |
|
9899 | 452 |
[(simpN, simp_attr, "declaration of simplification rule"), |
453 |
(congN, cong_attr, "declaration of Simplifier congruence rule"), |
|
454 |
("simplified", simplified_attr, "simplified rule")]; |
|
5842 | 455 |
|
456 |
||
457 |
||
458 |
(** proof methods **) |
|
459 |
||
460 |
(* simplification *) |
|
461 |
||
8700 | 462 |
val simp_options = |
9899 | 463 |
(Args.parens (Args.$$$ no_asmN) >> K simp_tac || |
464 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac || |
|
465 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac || |
|
13605 | 466 |
Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac || |
8700 | 467 |
Scan.succeed asm_full_simp_tac); |
468 |
||
9715 | 469 |
val cong_modifiers = |
9720 | 470 |
[Args.$$$ congN -- Args.colon >> K ((I, cong_add_local):Method.modifier), |
10034 | 471 |
Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add_local), |
472 |
Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del_local)]; |
|
9715 | 473 |
|
5928 | 474 |
val simp_modifiers = |
8815 | 475 |
[Args.$$$ simpN -- Args.colon >> K (I, simp_add_local), |
10034 | 476 |
Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add_local), |
477 |
Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del_local), |
|
9861 | 478 |
Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)] |
479 |
@ cong_modifiers; |
|
5928 | 480 |
|
481 |
val simp_modifiers' = |
|
10034 | 482 |
[Args.add -- Args.colon >> K (I, simp_add_local), |
483 |
Args.del -- Args.colon >> K (I, simp_del_local), |
|
9861 | 484 |
Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)] |
485 |
@ cong_modifiers; |
|
5928 | 486 |
|
8700 | 487 |
fun simp_args more_mods = |
488 |
Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options) (more_mods @ simp_modifiers'); |
|
489 |
||
8170 | 490 |
|
8700 | 491 |
fun simp_method (prems, tac) ctxt = Method.METHOD (fn facts => |
492 |
ALLGOALS (Method.insert_tac (prems @ facts)) THEN |
|
15036 | 493 |
(CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt)); |
8700 | 494 |
|
495 |
fun simp_method' (prems, tac) ctxt = Method.METHOD (fn facts => |
|
10821 | 496 |
HEADGOAL (Method.insert_tac (prems @ facts) THEN' |
15036 | 497 |
(CHANGED_PROP oo tac) (local_simpset_of ctxt))); |
9715 | 498 |
|
5842 | 499 |
|
500 |
(* setup_methods *) |
|
501 |
||
8467 | 502 |
fun setup_methods more_mods = Method.add_methods |
8700 | 503 |
[(simpN, simp_args more_mods simp_method', "simplification"), |
504 |
("simp_all", simp_args more_mods simp_method, "simplification (all goals)")]; |
|
5842 | 505 |
|
506 |
||
507 |
||
4795 | 508 |
(** theory setup **) |
509 |
||
8467 | 510 |
val setup = [GlobalSimpset.init, LocalSimpset.init, setup_attrs]; |
511 |
fun method_setup mods = [setup_methods mods]; |
|
4795 | 512 |
|
8228 | 513 |
fun easy_setup reflect trivs = |
514 |
let |
|
515 |
val trivialities = Drule.reflexive_thm :: trivs; |
|
516 |
||
517 |
fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac]; |
|
518 |
val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac; |
|
519 |
||
520 |
(*no premature instantiation of variables during simplification*) |
|
521 |
fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac]; |
|
522 |
val safe_solver = mk_solver "easy safe" safe_solver_tac; |
|
523 |
||
8243 | 524 |
fun mk_eq thm = |
8228 | 525 |
if Logic.is_equals (Thm.concl_of thm) then [thm] |
526 |
else [thm RS reflect] handle THM _ => []; |
|
527 |
||
8243 | 528 |
fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm); |
529 |
||
8228 | 530 |
fun init_ss thy = |
531 |
(simpset_ref_of thy := |
|
532 |
empty_ss setsubgoaler asm_simp_tac |
|
533 |
setSSolver safe_solver |
|
534 |
setSolver unsafe_solver |
|
535 |
setmksimps mksimps; thy); |
|
8467 | 536 |
in setup @ method_setup [] @ [init_ss] end; |
8228 | 537 |
|
4795 | 538 |
|
8667 | 539 |
|
540 |
(** outer syntax **) |
|
541 |
||
542 |
val print_simpsetP = |
|
543 |
OuterSyntax.improper_command "print_simpset" "print context of Simplifier" |
|
544 |
OuterSyntax.Keyword.diag |
|
9513 | 545 |
(Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o (Toplevel.keep |
9010 | 546 |
(Toplevel.node_case print_simpset (print_local_simpset o Proof.context_of))))); |
8667 | 547 |
|
548 |
val _ = OuterSyntax.add_parsers [print_simpsetP]; |
|
549 |
||
1243 | 550 |
end; |
4795 | 551 |
|
552 |
||
553 |
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier; |
|
554 |
open BasicSimplifier; |