author | wenzelm |
Thu, 27 Jul 2006 13:43:03 +0200 | |
changeset 20225 | 4b8e42490e58 |
parent 18988 | d6e5fa2ba8b8 |
child 20872 | 528054ca23e3 |
permissions | -rw-r--r-- |
16014 | 1 |
(* Title: Pure/simplifier.ML |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
|
4 |
||
5 |
Generic simplifier, suitable for most logics (see also |
|
6 |
meta_simplifier.ML for the actual meta-level rewriting engine). |
|
7 |
*) |
|
8 |
||
9 |
signature BASIC_SIMPLIFIER = |
|
10 |
sig |
|
11 |
include BASIC_META_SIMPLIFIER |
|
12 |
val print_simpset: theory -> unit |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
13 |
val change_simpset_of: theory -> (simpset -> simpset) -> unit |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
14 |
val change_simpset: (simpset -> simpset) -> unit |
16014 | 15 |
val simpset_of: theory -> simpset |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
16 |
val simpset: unit -> simpset |
16014 | 17 |
val SIMPSET: (simpset -> tactic) -> tactic |
18 |
val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic |
|
19 |
val Addsimps: thm list -> unit |
|
20 |
val Delsimps: thm list -> unit |
|
21 |
val Addsimprocs: simproc list -> unit |
|
22 |
val Delsimprocs: simproc list -> unit |
|
23 |
val Addcongs: thm list -> unit |
|
24 |
val Delcongs: thm list -> unit |
|
25 |
val local_simpset_of: Proof.context -> simpset |
|
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
26 |
val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic |
16014 | 27 |
val safe_asm_full_simp_tac: simpset -> int -> tactic |
28 |
val simp_tac: simpset -> int -> tactic |
|
29 |
val asm_simp_tac: simpset -> int -> tactic |
|
30 |
val full_simp_tac: simpset -> int -> tactic |
|
31 |
val asm_lr_simp_tac: simpset -> int -> tactic |
|
32 |
val asm_full_simp_tac: simpset -> int -> tactic |
|
33 |
val Simp_tac: int -> tactic |
|
34 |
val Asm_simp_tac: int -> tactic |
|
35 |
val Full_simp_tac: int -> tactic |
|
36 |
val Asm_lr_simp_tac: int -> tactic |
|
37 |
val Asm_full_simp_tac: int -> tactic |
|
38 |
val simplify: simpset -> thm -> thm |
|
39 |
val asm_simplify: simpset -> thm -> thm |
|
40 |
val full_simplify: simpset -> thm -> thm |
|
41 |
val asm_lr_simplify: simpset -> thm -> thm |
|
42 |
val asm_full_simplify: simpset -> thm -> thm |
|
43 |
end; |
|
44 |
||
45 |
signature SIMPLIFIER = |
|
46 |
sig |
|
47 |
include BASIC_SIMPLIFIER |
|
17004 | 48 |
val clear_ss: simpset -> simpset |
17723 | 49 |
val debug_bounds: bool ref |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
50 |
val inherit_context: simpset -> simpset -> simpset |
17898 | 51 |
val the_context: simpset -> Proof.context |
52 |
val context: Proof.context -> simpset -> simpset |
|
53 |
val theory_context: theory -> simpset -> simpset |
|
16458 | 54 |
val simproc_i: theory -> string -> term list |
55 |
-> (theory -> simpset -> term -> thm option) -> simproc |
|
56 |
val simproc: theory -> string -> string list |
|
57 |
-> (theory -> simpset -> term -> thm option) -> simproc |
|
16014 | 58 |
val rewrite: simpset -> cterm -> thm |
59 |
val asm_rewrite: simpset -> cterm -> thm |
|
60 |
val full_rewrite: simpset -> cterm -> thm |
|
61 |
val asm_lr_rewrite: simpset -> cterm -> thm |
|
62 |
val asm_full_rewrite: simpset -> cterm -> thm |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
63 |
val get_simpset: theory -> simpset |
16014 | 64 |
val print_local_simpset: Proof.context -> unit |
65 |
val get_local_simpset: Proof.context -> simpset |
|
66 |
val put_local_simpset: simpset -> Proof.context -> Proof.context |
|
18728 | 67 |
val attrib: (simpset * thm list -> simpset) -> attribute |
68 |
val simp_add: attribute |
|
69 |
val simp_del: attribute |
|
70 |
val cong_add: attribute |
|
71 |
val cong_del: attribute |
|
18033 | 72 |
val cong_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list |
73 |
val simp_modifiers': (Args.T list -> (Method.modifier * Args.T list)) list |
|
16014 | 74 |
val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list |
75 |
val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list |
|
18708 | 76 |
-> theory -> theory |
77 |
val easy_setup: thm -> thm list -> theory -> theory |
|
16014 | 78 |
end; |
79 |
||
80 |
structure Simplifier: SIMPLIFIER = |
|
81 |
struct |
|
82 |
||
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
83 |
(** simpset data **) |
16014 | 84 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
85 |
(* global simpsets *) |
16014 | 86 |
|
16458 | 87 |
structure GlobalSimpset = TheoryDataFun |
88 |
(struct |
|
16014 | 89 |
val name = "Pure/simpset"; |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
90 |
type T = simpset ref; |
16014 | 91 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
92 |
val empty = ref empty_ss; |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
93 |
fun copy (ref ss) = ref ss: T; (*create new reference!*) |
17898 | 94 |
fun extend (ref ss) = ref (MetaSimplifier.inherit_context empty_ss ss); |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
95 |
fun merge _ (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2)); |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
96 |
fun print _ (ref ss) = print_ss ss; |
16458 | 97 |
end); |
16014 | 98 |
|
18708 | 99 |
val _ = Context.add_setup GlobalSimpset.init; |
16014 | 100 |
val print_simpset = GlobalSimpset.print; |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
101 |
val get_simpset = ! o GlobalSimpset.get; |
16014 | 102 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
103 |
val change_simpset_of = change o GlobalSimpset.get; |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
104 |
fun change_simpset f = change_simpset_of (Context.the_context ()) f; |
16014 | 105 |
|
17898 | 106 |
fun simpset_of thy = MetaSimplifier.context (ProofContext.init thy) (get_simpset thy); |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
107 |
val simpset = simpset_of o Context.the_context; |
16014 | 108 |
|
109 |
||
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
110 |
fun SIMPSET tacf st = tacf (simpset_of (Thm.theory_of_thm st)) st; |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
111 |
fun SIMPSET' tacf i st = tacf (simpset_of (Thm.theory_of_thm st)) i st; |
16014 | 112 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
113 |
fun Addsimps args = change_simpset (fn ss => ss addsimps args); |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
114 |
fun Delsimps args = change_simpset (fn ss => ss delsimps args); |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
115 |
fun Addsimprocs args = change_simpset (fn ss => ss addsimprocs args); |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
116 |
fun Delsimprocs args = change_simpset (fn ss => ss delsimprocs args); |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
117 |
fun Addcongs args = change_simpset (fn ss => ss addcongs args); |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
118 |
fun Delcongs args = change_simpset (fn ss => ss delcongs args); |
16014 | 119 |
|
120 |
||
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
121 |
(* local simpsets *) |
16014 | 122 |
|
16458 | 123 |
structure LocalSimpset = ProofDataFun |
124 |
(struct |
|
16014 | 125 |
val name = "Pure/simpset"; |
126 |
type T = simpset; |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
127 |
val init = get_simpset; |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
128 |
fun print _ ss = print_ss ss; |
16458 | 129 |
end); |
16014 | 130 |
|
18708 | 131 |
val _ = Context.add_setup LocalSimpset.init; |
16014 | 132 |
val print_local_simpset = LocalSimpset.print; |
133 |
val get_local_simpset = LocalSimpset.get; |
|
134 |
val put_local_simpset = LocalSimpset.put; |
|
135 |
||
17898 | 136 |
fun local_simpset_of ctxt = MetaSimplifier.context ctxt (get_local_simpset ctxt); |
16014 | 137 |
|
138 |
||
139 |
(* attributes *) |
|
140 |
||
18728 | 141 |
fun attrib f = Thm.declaration_attribute (fn th => |
18688 | 142 |
fn Context.Theory thy => (change_simpset_of thy (fn ss => f (ss, [th])); Context.Theory thy) |
143 |
| Context.Proof ctxt => Context.Proof (LocalSimpset.map (fn ss => f (ss, [th])) ctxt)); |
|
16014 | 144 |
|
18688 | 145 |
val simp_add = attrib (op addsimps); |
146 |
val simp_del = attrib (op delsimps); |
|
147 |
val cong_add = attrib (op addcongs); |
|
148 |
val cong_del = attrib (op delcongs); |
|
16014 | 149 |
|
150 |
||
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
151 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
152 |
(** simplification tactics and rules **) |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
153 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
154 |
fun solve_all_tac solvers ss = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
155 |
let |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
156 |
val (_, {subgoal_tac, ...}) = MetaSimplifier.rep_ss ss; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
157 |
val solve_tac = subgoal_tac (MetaSimplifier.set_solvers solvers ss) THEN_ALL_NEW (K no_tac); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
158 |
in DEPTH_SOLVE (solve_tac 1) end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
159 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
160 |
(*NOTE: may instantiate unknowns that appear also in other subgoals*) |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
161 |
fun generic_simp_tac safe mode ss = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
162 |
let |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
163 |
val (_, {loop_tacs, solvers = (unsafe_solvers, solvers), ...}) = MetaSimplifier.rep_ss ss; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
164 |
val loop_tac = FIRST' (map (fn (_, tac) => tac ss) loop_tacs); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
165 |
val solve_tac = FIRST' (map (MetaSimplifier.solver ss) |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
166 |
(if safe then solvers else unsafe_solvers)); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
167 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
168 |
fun simp_loop_tac i = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
169 |
asm_rewrite_goal_tac mode (solve_all_tac unsafe_solvers) ss i THEN |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
170 |
(solve_tac i ORELSE TRY ((loop_tac THEN_ALL_NEW simp_loop_tac) i)); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
171 |
in simp_loop_tac end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
172 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
173 |
local |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
174 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
175 |
fun simp rew mode ss thm = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
176 |
let |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
177 |
val (_, {solvers = (unsafe_solvers, _), ...}) = MetaSimplifier.rep_ss ss; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
178 |
val tacf = solve_all_tac unsafe_solvers; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
179 |
fun prover s th = Option.map #1 (Seq.pull (tacf s th)); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
180 |
in rew mode prover ss thm end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
181 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
182 |
in |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
183 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
184 |
val simp_thm = simp MetaSimplifier.rewrite_thm; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
185 |
val simp_cterm = simp MetaSimplifier.rewrite_cterm; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
186 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
187 |
end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
188 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
189 |
|
16806 | 190 |
(* tactics *) |
191 |
||
16014 | 192 |
val simp_tac = generic_simp_tac false (false, false, false); |
193 |
val asm_simp_tac = generic_simp_tac false (false, true, false); |
|
194 |
val full_simp_tac = generic_simp_tac false (true, false, false); |
|
195 |
val asm_lr_simp_tac = generic_simp_tac false (true, true, false); |
|
196 |
val asm_full_simp_tac = generic_simp_tac false (true, true, true); |
|
197 |
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true); |
|
198 |
||
199 |
(*the abstraction over the proof state delays the dereferencing*) |
|
200 |
fun Simp_tac i st = simp_tac (simpset ()) i st; |
|
201 |
fun Asm_simp_tac i st = asm_simp_tac (simpset ()) i st; |
|
202 |
fun Full_simp_tac i st = full_simp_tac (simpset ()) i st; |
|
203 |
fun Asm_lr_simp_tac i st = asm_lr_simp_tac (simpset ()) i st; |
|
204 |
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st; |
|
205 |
||
16806 | 206 |
|
207 |
(* conversions *) |
|
208 |
||
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
209 |
val simplify = simp_thm (false, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
210 |
val asm_simplify = simp_thm (false, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
211 |
val full_simplify = simp_thm (true, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
212 |
val asm_lr_simplify = simp_thm (true, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
213 |
val asm_full_simplify = simp_thm (true, true, true); |
16014 | 214 |
|
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
215 |
val rewrite = simp_cterm (false, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
216 |
val asm_rewrite = simp_cterm (false, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
217 |
val full_rewrite = simp_cterm (true, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
218 |
val asm_lr_rewrite = simp_cterm (true, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
219 |
val asm_full_rewrite = simp_cterm (true, true, true); |
16014 | 220 |
|
221 |
||
222 |
||
223 |
(** concrete syntax of attributes **) |
|
224 |
||
225 |
(* add / del *) |
|
226 |
||
227 |
val simpN = "simp"; |
|
228 |
val congN = "cong"; |
|
229 |
val addN = "add"; |
|
230 |
val delN = "del"; |
|
231 |
val onlyN = "only"; |
|
232 |
val no_asmN = "no_asm"; |
|
233 |
val no_asm_useN = "no_asm_use"; |
|
234 |
val no_asm_simpN = "no_asm_simp"; |
|
235 |
val asm_lrN = "asm_lr"; |
|
236 |
||
237 |
||
238 |
(* conversions *) |
|
239 |
||
240 |
local |
|
241 |
||
242 |
fun conv_mode x = |
|
243 |
((Args.parens (Args.$$$ no_asmN) >> K simplify || |
|
244 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify || |
|
245 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simplify || |
|
246 |
Scan.succeed asm_full_simplify) |> Scan.lift) x; |
|
247 |
||
18688 | 248 |
fun get_ss (Context.Theory thy) = simpset_of thy |
249 |
| get_ss (Context.Proof ctxt) = local_simpset_of ctxt; |
|
16014 | 250 |
|
251 |
in |
|
252 |
||
18688 | 253 |
val simplified = |
18988 | 254 |
Attrib.syntax (conv_mode -- Attrib.thms >> (fn (f, ths) => Thm.rule_attribute (fn x => |
18688 | 255 |
f ((if null ths then I else MetaSimplifier.clear_ss) (get_ss x) addsimps ths)))); |
16014 | 256 |
|
257 |
end; |
|
258 |
||
259 |
||
260 |
(* setup attributes *) |
|
261 |
||
262 |
val _ = Context.add_setup |
|
18708 | 263 |
(Attrib.add_attributes |
18728 | 264 |
[(simpN, Attrib.add_del_args simp_add simp_del, "declaration of Simplifier rule"), |
265 |
(congN, Attrib.add_del_args cong_add cong_del, "declaration of Simplifier congruence rule"), |
|
266 |
("simplified", simplified, "simplified rule")]); |
|
16014 | 267 |
|
268 |
||
269 |
||
270 |
(** proof methods **) |
|
271 |
||
272 |
(* simplification *) |
|
273 |
||
274 |
val simp_options = |
|
275 |
(Args.parens (Args.$$$ no_asmN) >> K simp_tac || |
|
276 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac || |
|
277 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac || |
|
278 |
Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac || |
|
279 |
Scan.succeed asm_full_simp_tac); |
|
280 |
||
16685 | 281 |
fun simp_flags x = (Scan.repeat |
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
282 |
(Args.parens (Args.$$$ "depth_limit" -- Args.colon |-- Args.nat) |
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
283 |
>> setmp MetaSimplifier.simp_depth_limit) |
16709 | 284 |
>> (curry (Library.foldl op o) I o rev)) x; |
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
285 |
|
16014 | 286 |
val cong_modifiers = |
18728 | 287 |
[Args.$$$ congN -- Args.colon >> K ((I, cong_add): Method.modifier), |
288 |
Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add), |
|
289 |
Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del)]; |
|
16014 | 290 |
|
291 |
val simp_modifiers = |
|
18728 | 292 |
[Args.$$$ simpN -- Args.colon >> K (I, simp_add), |
293 |
Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add), |
|
294 |
Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del), |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
295 |
Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon |
18728 | 296 |
>> K (LocalSimpset.map MetaSimplifier.clear_ss, simp_add)] |
16014 | 297 |
@ cong_modifiers; |
298 |
||
299 |
val simp_modifiers' = |
|
18728 | 300 |
[Args.add -- Args.colon >> K (I, simp_add), |
301 |
Args.del -- Args.colon >> K (I, simp_del), |
|
18688 | 302 |
Args.$$$ onlyN -- Args.colon |
18728 | 303 |
>> K (LocalSimpset.map MetaSimplifier.clear_ss, simp_add)] |
16014 | 304 |
@ cong_modifiers; |
305 |
||
306 |
fun simp_args more_mods = |
|
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
307 |
Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options -- Scan.lift simp_flags) |
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
308 |
(more_mods @ simp_modifiers'); |
16014 | 309 |
|
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
310 |
fun simp_method ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts => |
16014 | 311 |
ALLGOALS (Method.insert_tac (prems @ facts)) THEN |
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
312 |
(FLAGS o CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt)); |
16014 | 313 |
|
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
314 |
fun simp_method' ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts => |
16014 | 315 |
HEADGOAL (Method.insert_tac (prems @ facts) THEN' |
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
316 |
((FLAGS o CHANGED_PROP) oo tac) (local_simpset_of ctxt))); |
16014 | 317 |
|
318 |
||
319 |
||
18708 | 320 |
(** setup **) |
321 |
||
322 |
fun method_setup more_mods = Method.add_methods |
|
16014 | 323 |
[(simpN, simp_args more_mods simp_method', "simplification"), |
324 |
("simp_all", simp_args more_mods simp_method, "simplification (all goals)")]; |
|
325 |
||
18708 | 326 |
fun easy_setup reflect trivs = method_setup [] #> (fn thy => |
16014 | 327 |
let |
328 |
val trivialities = Drule.reflexive_thm :: trivs; |
|
329 |
||
330 |
fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac]; |
|
331 |
val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac; |
|
332 |
||
333 |
(*no premature instantiation of variables during simplification*) |
|
334 |
fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac]; |
|
335 |
val safe_solver = mk_solver "easy safe" safe_solver_tac; |
|
336 |
||
337 |
fun mk_eq thm = |
|
338 |
if Logic.is_equals (Thm.concl_of thm) then [thm] |
|
339 |
else [thm RS reflect] handle THM _ => []; |
|
340 |
||
341 |
fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm); |
|
18708 | 342 |
in |
343 |
GlobalSimpset.get thy := |
|
344 |
empty_ss setsubgoaler asm_simp_tac |
|
345 |
setSSolver safe_solver |
|
346 |
setSolver unsafe_solver |
|
347 |
setmksimps mksimps; |
|
348 |
thy |
|
349 |
end); |
|
16014 | 350 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
351 |
|
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
352 |
open MetaSimplifier; |
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
353 |
|
16014 | 354 |
end; |
355 |
||
356 |
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier; |
|
357 |
open BasicSimplifier; |