author | dixon |
Sun, 27 Feb 2005 00:00:40 +0100 | |
changeset 15550 | 806214035275 |
parent 15531 | 08c8dad8e399 |
child 15735 | 953f188e16c6 |
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 |
||
15496 | 106 |
val find_rewrites: string -> Toplevel.transition -> Toplevel.transition |
4795 | 107 |
end; |
2503 | 108 |
|
109 |
structure Simplifier: SIMPLIFIER = |
|
0 | 110 |
struct |
111 |
||
15006
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier. Next step:
skalberg
parents:
14814
diff
changeset
|
112 |
open MetaSimplifier; |
8467 | 113 |
|
15024 | 114 |
|
15036 | 115 |
(** context dependent simpset components **) |
116 |
||
117 |
(* datatype context_solver *) |
|
118 |
||
119 |
datatype context_solver = |
|
120 |
ContextSolver of (string * (Proof.context -> thm list -> int -> tactic)) * stamp; |
|
121 |
||
122 |
fun mk_context_solver name f = ContextSolver ((name, f), stamp ()); |
|
123 |
fun eq_context_solver (ContextSolver (_, id1), ContextSolver (_, id2)) = (id1 = id2); |
|
124 |
val merge_context_solvers = gen_merge_lists eq_context_solver; |
|
125 |
||
126 |
||
127 |
(* datatype context_simproc *) |
|
128 |
||
129 |
datatype context_simproc = ContextSimproc of |
|
130 |
(string * cterm list * (Proof.context -> simpset -> term -> thm option)) * stamp; |
|
131 |
||
132 |
fun mk_context_simproc name lhss f = ContextSimproc ((name, lhss, f), stamp ()); |
|
133 |
fun eq_context_simproc (ContextSimproc (_, id1), ContextSimproc (_, id2)) = (id1 = id2); |
|
134 |
val merge_context_simprocs = gen_merge_lists eq_context_simproc; |
|
135 |
||
136 |
fun context_simproc_i sg name = |
|
137 |
mk_context_simproc name o map (Thm.cterm_of sg o Logic.varify); |
|
138 |
||
139 |
fun context_simproc sg name = |
|
140 |
context_simproc_i sg name o map (Sign.simple_read_term sg TypeInfer.logicT); |
|
141 |
||
142 |
||
143 |
(* datatype context_ss *) |
|
144 |
||
145 |
datatype context_ss = ContextSS of |
|
146 |
{simprocs: context_simproc list, |
|
147 |
subgoal_tac: (Proof.context -> simpset -> int -> tactic) option, |
|
148 |
loop_tacs: (string * (Proof.context -> int -> tactic)) list, |
|
149 |
unsafe_solvers: context_solver list, |
|
150 |
solvers: context_solver list}; |
|
151 |
||
152 |
fun context_ss ctxt ss ctxt_ss = |
|
153 |
let |
|
154 |
val ContextSS {simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers} = ctxt_ss; |
|
155 |
fun prep_simproc (ContextSimproc ((name, lhss, f), _)) = |
|
156 |
mk_simproc name lhss (K (f ctxt)); |
|
157 |
fun add_loop (name, f) simpset = simpset addloop (name, f ctxt); |
|
158 |
fun add_solver add (ContextSolver ((name, f), _)) simpset = |
|
159 |
add (simpset, mk_solver name (f ctxt)); |
|
160 |
in |
|
15531 | 161 |
((case subgoal_tac of NONE => ss | SOME tac => ss setsubgoaler tac ctxt) |
15036 | 162 |
addsimprocs map prep_simproc simprocs) |
163 |
|> fold_rev add_loop loop_tacs |
|
164 |
|> fold_rev (add_solver (op addSolver)) unsafe_solvers |
|
165 |
|> fold_rev (add_solver (op addSSolver)) solvers |
|
166 |
end; |
|
167 |
||
168 |
fun make_context_ss (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) = |
|
169 |
ContextSS {simprocs = simprocs, subgoal_tac = subgoal_tac, loop_tacs = loop_tacs, |
|
170 |
unsafe_solvers = unsafe_solvers, solvers = solvers}; |
|
171 |
||
15531 | 172 |
val empty_context_ss = make_context_ss ([], NONE, [], [], []); |
15036 | 173 |
|
174 |
fun merge_context_ss (ctxt_ss1, ctxt_ss2) = |
|
175 |
let |
|
176 |
val ContextSS {simprocs = simprocs1, subgoal_tac = subgoal_tac1, loop_tacs = loop_tacs1, |
|
177 |
unsafe_solvers = unsafe_solvers1, solvers = solvers1} = ctxt_ss1; |
|
178 |
val ContextSS {simprocs = simprocs2, subgoal_tac = subgoal_tac2, loop_tacs = loop_tacs2, |
|
179 |
unsafe_solvers = unsafe_solvers2, solvers = solvers2} = ctxt_ss2; |
|
180 |
||
181 |
val simprocs' = merge_context_simprocs simprocs1 simprocs2; |
|
15531 | 182 |
val subgoal_tac' = (case subgoal_tac1 of NONE => subgoal_tac2 | some => some); |
15036 | 183 |
val loop_tacs' = merge_alists loop_tacs1 loop_tacs2; |
184 |
val unsafe_solvers' = merge_context_solvers unsafe_solvers1 unsafe_solvers2; |
|
185 |
val solvers' = merge_context_solvers solvers1 solvers2; |
|
186 |
in make_context_ss (simprocs', subgoal_tac', loop_tacs', unsafe_solvers', solvers') end; |
|
187 |
||
188 |
||
189 |
||
5024 | 190 |
(** global and local simpset data **) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
191 |
|
5842 | 192 |
(* theory data kind 'Provers/simpset' *) |
4795 | 193 |
|
5842 | 194 |
structure GlobalSimpsetArgs = |
5024 | 195 |
struct |
5842 | 196 |
val name = "Provers/simpset"; |
15036 | 197 |
type T = simpset ref * context_ss; |
0 | 198 |
|
15036 | 199 |
val empty = (ref empty_ss, empty_context_ss); |
200 |
fun copy (ref ss, ctxt_ss) = (ref ss, ctxt_ss): T; (*create new reference!*) |
|
6556 | 201 |
val prep_ext = copy; |
15036 | 202 |
fun merge ((ref ss1, ctxt_ss1), (ref ss2, ctxt_ss2)) = |
203 |
(ref (merge_ss (ss1, ss2)), merge_context_ss (ctxt_ss1, ctxt_ss2)); |
|
204 |
fun print _ (ref ss, _) = print_ss ss; |
|
5024 | 205 |
end; |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
206 |
|
5842 | 207 |
structure GlobalSimpset = TheoryDataFun(GlobalSimpsetArgs); |
208 |
val print_simpset = GlobalSimpset.print; |
|
15036 | 209 |
val simpset_ref_of_sg = #1 o GlobalSimpset.get_sg; |
210 |
val simpset_ref_of = #1 o GlobalSimpset.get; |
|
211 |
val get_context_ss = #2 o GlobalSimpset.get o ProofContext.theory_of; |
|
212 |
||
213 |
fun map_context_ss f = GlobalSimpset.map (apsnd |
|
214 |
(fn ContextSS {simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers} => |
|
215 |
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
|
216 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
217 |
|
4795 | 218 |
(* access global simpset *) |
0 | 219 |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
220 |
val simpset_of_sg = ! o simpset_ref_of_sg; |
6391 | 221 |
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
|
222 |
|
6391 | 223 |
fun SIMPSET tacf state = tacf (simpset_of_sg (Thm.sign_of_thm state)) state; |
224 |
fun SIMPSET' tacf i state = tacf (simpset_of_sg (Thm.sign_of_thm state)) i state; |
|
0 | 225 |
|
5028 | 226 |
val simpset = simpset_of o Context.the_context; |
6391 | 227 |
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
|
228 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
229 |
|
15496 | 230 |
(* find rewrites *) |
231 |
||
232 |
fun find_rewrites s = Toplevel.keep (fn state => |
|
233 |
let |
|
234 |
val pstate = Toplevel.enter_forward_proof state |
|
235 |
val ctxt = Proof.context_of pstate; |
|
236 |
val prt_fact = ProofContext.pretty_fact ctxt |
|
237 |
val thy = ProofContext.theory_of ctxt |
|
238 |
val t = ProofContext.read_term ctxt s; |
|
239 |
val (_, {mk_rews = {mk,...}, ...}) = rep_ss (simpset_of thy) |
|
240 |
val lhs = fst o Logic.dest_equals o Logic.strip_imp_concl |
|
241 |
val rews = map (apsnd single) (PureThy.find_matching_thms (mk,lhs) thy t) |
|
242 |
in map prt_fact (rev rews) |> Pretty.chunks |> Pretty.writeln end); |
|
243 |
||
244 |
||
4795 | 245 |
(* change global simpset *) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
246 |
|
7177 | 247 |
fun change_simpset_of f x thy = |
248 |
let val r = simpset_ref_of thy |
|
249 |
in r := f (! r, x); thy end; |
|
250 |
||
251 |
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
|
252 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
253 |
val Addsimps = change_simpset (op addsimps); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
254 |
val Delsimps = change_simpset (op delsimps); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
255 |
val Addsimprocs = change_simpset (op addsimprocs); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
256 |
val Delsimprocs = change_simpset (op delsimprocs); |
9715 | 257 |
val Addcongs = change_simpset (op addcongs); |
258 |
val Delcongs = change_simpset (op delcongs); |
|
2509 | 259 |
|
0 | 260 |
|
15036 | 261 |
(* change context dependent components *) |
262 |
||
263 |
fun add_context_simprocs procs = |
|
264 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
265 |
(merge_context_simprocs procs simprocs, subgoal_tac, loop_tacs, |
|
266 |
unsafe_solvers, solvers)); |
|
267 |
||
268 |
fun del_context_simprocs procs = |
|
269 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
270 |
(gen_rems eq_context_simproc (simprocs, procs), subgoal_tac, loop_tacs, |
|
271 |
unsafe_solvers, solvers)); |
|
272 |
||
273 |
fun set_context_subgoaler tac = |
|
274 |
map_context_ss (fn (simprocs, _, loop_tacs, unsafe_solvers, solvers) => |
|
15531 | 275 |
(simprocs, SOME tac, loop_tacs, unsafe_solvers, solvers)); |
15036 | 276 |
|
277 |
val reset_context_subgoaler = |
|
278 |
map_context_ss (fn (simprocs, _, loop_tacs, unsafe_solvers, solvers) => |
|
15531 | 279 |
(simprocs, NONE, loop_tacs, unsafe_solvers, solvers)); |
15036 | 280 |
|
281 |
fun add_context_looper (name, tac) = |
|
282 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
283 |
(simprocs, subgoal_tac, merge_alists [(name, tac)] loop_tacs, |
|
284 |
unsafe_solvers, solvers)); |
|
285 |
||
286 |
fun del_context_looper name = |
|
287 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
288 |
(simprocs, subgoal_tac, filter_out (equal name o #1) loop_tacs, |
|
289 |
unsafe_solvers, solvers)); |
|
290 |
||
291 |
fun add_context_unsafe_solver solver = |
|
292 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
293 |
(simprocs, subgoal_tac, loop_tacs, |
|
294 |
merge_context_solvers [solver] unsafe_solvers, solvers)); |
|
295 |
||
296 |
fun add_context_safe_solver solver = |
|
297 |
map_context_ss (fn (simprocs, subgoal_tac, loop_tacs, unsafe_solvers, solvers) => |
|
298 |
(simprocs, subgoal_tac, loop_tacs, unsafe_solvers, |
|
299 |
merge_context_solvers [solver] solvers)); |
|
300 |
||
301 |
||
5842 | 302 |
(* proof data kind 'Provers/simpset' *) |
4795 | 303 |
|
5842 | 304 |
structure LocalSimpsetArgs = |
305 |
struct |
|
306 |
val name = "Provers/simpset"; |
|
307 |
type T = simpset; |
|
308 |
val init = simpset_of; |
|
15036 | 309 |
fun print ctxt ss = print_ss (context_ss ctxt ss (get_context_ss ctxt)); |
5842 | 310 |
end; |
4795 | 311 |
|
5842 | 312 |
structure LocalSimpset = ProofDataFun(LocalSimpsetArgs); |
313 |
val print_local_simpset = LocalSimpset.print; |
|
314 |
val get_local_simpset = LocalSimpset.get; |
|
315 |
val put_local_simpset = LocalSimpset.put; |
|
7273 | 316 |
fun map_local_simpset f ctxt = put_local_simpset (f (get_local_simpset ctxt)) ctxt; |
4795 | 317 |
|
15036 | 318 |
fun local_simpset_of ctxt = |
319 |
context_ss ctxt (get_local_simpset ctxt) (get_context_ss ctxt); |
|
320 |
||
4795 | 321 |
|
15452 | 322 |
(* Jia: added DeltaSimpsetArgs and DeltaSimpset for delta_simpset |
323 |
also added methods to retrieve them. *) |
|
324 |
||
325 |
structure DeltaSimpsetArgs = |
|
326 |
struct |
|
327 |
val name = "delta_simpset"; |
|
328 |
type T = Thm.thm list; (*the type is thm list*) |
|
329 |
val empty = []; |
|
330 |
end; |
|
331 |
||
332 |
structure DeltaSimpset = DeltaDataFun(DeltaSimpsetArgs); |
|
333 |
val get_delta_simpset = DeltaSimpset.get; |
|
334 |
val put_delta_simpset = DeltaSimpset.put; |
|
335 |
||
336 |
val get_new_thm_id = ProofContext.get_delta_count_incr; |
|
337 |
||
338 |
(* Jia: added to rename a local thm if necessary *) |
|
339 |
local |
|
340 |
fun rename_thm' (ctxt,thm) = |
|
341 |
let val new_id = get_new_thm_id ctxt |
|
342 |
val new_name = "anon_" ^ (string_of_int new_id) |
|
343 |
in |
|
344 |
Thm.name_thm(new_name,thm) |
|
345 |
end; |
|
346 |
||
347 |
in |
|
348 |
||
349 |
fun rename_thm (ctxt,thm) = if (!Proof.call_atp) then rename_thm' (ctxt,thm) else thm; |
|
350 |
||
351 |
end |
|
352 |
||
5886 | 353 |
(* attributes *) |
354 |
||
355 |
fun change_global_ss f (thy, th) = |
|
356 |
let val r = simpset_ref_of thy |
|
6096 | 357 |
in r := f (! r, [th]); (thy, th) end; |
5886 | 358 |
|
359 |
fun change_local_ss f (ctxt, th) = |
|
6096 | 360 |
let val ss = f (get_local_simpset ctxt, [th]) |
5886 | 361 |
in (put_local_simpset ss ctxt, th) end; |
362 |
||
363 |
val simp_add_global = change_global_ss (op addsimps); |
|
364 |
val simp_del_global = change_global_ss (op delsimps); |
|
15452 | 365 |
|
366 |
||
367 |
||
368 |
||
369 |
||
370 |
(* 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 *) |
|
371 |
fun simp_add_local (ctxt,th) = |
|
372 |
let val delta_ss = get_delta_simpset ctxt |
|
373 |
val thm_name = Thm.name_of_thm th |
|
374 |
val th' = if (thm_name = "") then rename_thm (ctxt,th) else th |
|
375 |
val new_dss = th'::delta_ss |
|
376 |
val ctxt' = put_delta_simpset new_dss ctxt |
|
377 |
in |
|
378 |
change_local_ss (op addsimps) (ctxt',th) |
|
379 |
end; |
|
380 |
||
5886 | 381 |
val simp_del_local = change_local_ss (op delsimps); |
382 |
||
9715 | 383 |
val cong_add_global = change_global_ss (op addcongs); |
384 |
val cong_del_global = change_global_ss (op delcongs); |
|
385 |
val cong_add_local = change_local_ss (op addcongs); |
|
386 |
val cong_del_local = change_local_ss (op delcongs); |
|
387 |
||
5886 | 388 |
|
10004 | 389 |
val simp_tac = generic_simp_tac false (false, false, false); |
390 |
val asm_simp_tac = generic_simp_tac false (false, true, false); |
|
391 |
val full_simp_tac = generic_simp_tac false (true, false, false); |
|
392 |
val asm_lr_simp_tac = generic_simp_tac false (true, true, false); |
|
393 |
val asm_full_simp_tac = generic_simp_tac false (true, true, true); |
|
394 |
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true); |
|
0 | 395 |
|
2629 | 396 |
|
15006
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier. Next step:
skalberg
parents:
14814
diff
changeset
|
397 |
|
4795 | 398 |
(*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
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
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
|
403 |
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st; |
406 | 404 |
|
5082 | 405 |
val simplify = simp_thm (false, false, false); |
406 |
val asm_simplify = simp_thm (false, true, false); |
|
407 |
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
|
408 |
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
|
409 |
val asm_full_simplify = simp_thm (true, true, true); |
5082 | 410 |
|
411 |
val rewrite = simp_cterm (false, false, false); |
|
412 |
val asm_rewrite = simp_cterm (false, true, false); |
|
413 |
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
|
414 |
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
|
415 |
val asm_full_rewrite = simp_cterm (true, true, true); |
3557 | 416 |
|
417 |
||
4795 | 418 |
|
5886 | 419 |
(** concrete syntax of attributes **) |
5842 | 420 |
|
5886 | 421 |
(* add / del *) |
5842 | 422 |
|
5928 | 423 |
val simpN = "simp"; |
9715 | 424 |
val congN = "cong"; |
10412
1a1b4c1b2b7c
Moved meta simplification stuff from Thm to MetaSimplifier.
berghofe
parents:
10034
diff
changeset
|
425 |
val addN = "add"; |
1a1b4c1b2b7c
Moved meta simplification stuff from Thm to MetaSimplifier.
berghofe
parents:
10034
diff
changeset
|
426 |
val delN = "del"; |
6911 | 427 |
val onlyN = "only"; |
9899 | 428 |
val no_asmN = "no_asm"; |
429 |
val no_asm_useN = "no_asm_use"; |
|
430 |
val no_asm_simpN = "no_asm_simp"; |
|
13605 | 431 |
val asm_lrN = "asm_lr"; |
5842 | 432 |
|
8634 | 433 |
val simp_attr = |
434 |
(Attrib.add_del_args simp_add_global simp_del_global, |
|
435 |
Attrib.add_del_args simp_add_local simp_del_local); |
|
5842 | 436 |
|
9715 | 437 |
val cong_attr = |
438 |
(Attrib.add_del_args cong_add_global cong_del_global, |
|
439 |
Attrib.add_del_args cong_add_local cong_del_local); |
|
440 |
||
5842 | 441 |
|
442 |
(* conversions *) |
|
443 |
||
9899 | 444 |
local |
445 |
||
446 |
fun conv_mode x = |
|
447 |
((Args.parens (Args.$$$ no_asmN) >> K simplify || |
|
448 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify || |
|
449 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simplify || |
|
450 |
Scan.succeed asm_full_simplify) |> Scan.lift) x; |
|
451 |
||
11938 | 452 |
fun simplified_att get args = |
453 |
Attrib.syntax (conv_mode -- args >> (fn (f, ths) => |
|
454 |
Drule.rule_attribute (fn x => f ((if null ths then I else clear_ss) (get x) addsimps ths)))); |
|
9899 | 455 |
|
456 |
in |
|
457 |
||
458 |
val simplified_attr = |
|
11938 | 459 |
(simplified_att simpset_of Attrib.global_thmss, |
15036 | 460 |
simplified_att local_simpset_of Attrib.local_thmss); |
9899 | 461 |
|
462 |
end; |
|
5842 | 463 |
|
464 |
||
465 |
(* setup_attrs *) |
|
466 |
||
467 |
val setup_attrs = Attrib.add_attributes |
|
9899 | 468 |
[(simpN, simp_attr, "declaration of simplification rule"), |
469 |
(congN, cong_attr, "declaration of Simplifier congruence rule"), |
|
470 |
("simplified", simplified_attr, "simplified rule")]; |
|
5842 | 471 |
|
472 |
||
473 |
||
474 |
(** proof methods **) |
|
475 |
||
476 |
(* simplification *) |
|
477 |
||
8700 | 478 |
val simp_options = |
9899 | 479 |
(Args.parens (Args.$$$ no_asmN) >> K simp_tac || |
480 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac || |
|
481 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac || |
|
13605 | 482 |
Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac || |
8700 | 483 |
Scan.succeed asm_full_simp_tac); |
484 |
||
9715 | 485 |
val cong_modifiers = |
9720 | 486 |
[Args.$$$ congN -- Args.colon >> K ((I, cong_add_local):Method.modifier), |
10034 | 487 |
Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add_local), |
488 |
Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del_local)]; |
|
9715 | 489 |
|
5928 | 490 |
val simp_modifiers = |
8815 | 491 |
[Args.$$$ simpN -- Args.colon >> K (I, simp_add_local), |
10034 | 492 |
Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add_local), |
493 |
Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del_local), |
|
9861 | 494 |
Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)] |
495 |
@ cong_modifiers; |
|
5928 | 496 |
|
497 |
val simp_modifiers' = |
|
10034 | 498 |
[Args.add -- Args.colon >> K (I, simp_add_local), |
499 |
Args.del -- Args.colon >> K (I, simp_del_local), |
|
9861 | 500 |
Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)] |
501 |
@ cong_modifiers; |
|
5928 | 502 |
|
8700 | 503 |
fun simp_args more_mods = |
504 |
Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options) (more_mods @ simp_modifiers'); |
|
505 |
||
8170 | 506 |
|
8700 | 507 |
fun simp_method (prems, tac) ctxt = Method.METHOD (fn facts => |
508 |
ALLGOALS (Method.insert_tac (prems @ facts)) THEN |
|
15036 | 509 |
(CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt)); |
8700 | 510 |
|
511 |
fun simp_method' (prems, tac) ctxt = Method.METHOD (fn facts => |
|
10821 | 512 |
HEADGOAL (Method.insert_tac (prems @ facts) THEN' |
15036 | 513 |
(CHANGED_PROP oo tac) (local_simpset_of ctxt))); |
9715 | 514 |
|
5842 | 515 |
|
516 |
(* setup_methods *) |
|
517 |
||
8467 | 518 |
fun setup_methods more_mods = Method.add_methods |
8700 | 519 |
[(simpN, simp_args more_mods simp_method', "simplification"), |
520 |
("simp_all", simp_args more_mods simp_method, "simplification (all goals)")]; |
|
5842 | 521 |
|
522 |
||
523 |
||
4795 | 524 |
(** theory setup **) |
525 |
||
8467 | 526 |
val setup = [GlobalSimpset.init, LocalSimpset.init, setup_attrs]; |
527 |
fun method_setup mods = [setup_methods mods]; |
|
4795 | 528 |
|
8228 | 529 |
fun easy_setup reflect trivs = |
530 |
let |
|
531 |
val trivialities = Drule.reflexive_thm :: trivs; |
|
532 |
||
533 |
fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac]; |
|
534 |
val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac; |
|
535 |
||
536 |
(*no premature instantiation of variables during simplification*) |
|
537 |
fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac]; |
|
538 |
val safe_solver = mk_solver "easy safe" safe_solver_tac; |
|
539 |
||
8243 | 540 |
fun mk_eq thm = |
8228 | 541 |
if Logic.is_equals (Thm.concl_of thm) then [thm] |
542 |
else [thm RS reflect] handle THM _ => []; |
|
543 |
||
8243 | 544 |
fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm); |
545 |
||
8228 | 546 |
fun init_ss thy = |
547 |
(simpset_ref_of thy := |
|
548 |
empty_ss setsubgoaler asm_simp_tac |
|
549 |
setSSolver safe_solver |
|
550 |
setSolver unsafe_solver |
|
551 |
setmksimps mksimps; thy); |
|
8467 | 552 |
in setup @ method_setup [] @ [init_ss] end; |
8228 | 553 |
|
4795 | 554 |
|
8667 | 555 |
|
556 |
(** outer syntax **) |
|
557 |
||
558 |
val print_simpsetP = |
|
559 |
OuterSyntax.improper_command "print_simpset" "print context of Simplifier" |
|
560 |
OuterSyntax.Keyword.diag |
|
9513 | 561 |
(Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o (Toplevel.keep |
9010 | 562 |
(Toplevel.node_case print_simpset (print_local_simpset o Proof.context_of))))); |
8667 | 563 |
|
15496 | 564 |
val find_rewritesP = |
565 |
OuterSyntax.improper_command "find_rewrites" "find and print rewrites" OuterSyntax.Keyword.diag |
|
566 |
(OuterParse.term >> (Toplevel.no_timing oo find_rewrites)); |
|
567 |
||
568 |
val _ = OuterSyntax.add_parsers [print_simpsetP,find_rewritesP]; |
|
8667 | 569 |
|
1243 | 570 |
end; |
4795 | 571 |
|
572 |
||
573 |
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier; |
|
574 |
open BasicSimplifier; |