author | wenzelm |
Tue, 17 Mar 2009 12:09:43 +0100 | |
changeset 30555 | 5925cd6671d5 |
parent 30528 | 7173bf123335 |
child 30609 | 983e8b6e4e69 |
permissions | -rw-r--r-- |
16014 | 1 |
(* Title: Pure/simplifier.ML |
2 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
|
3 |
||
4 |
Generic simplifier, suitable for most logics (see also |
|
5 |
meta_simplifier.ML for the actual meta-level rewriting engine). |
|
6 |
*) |
|
7 |
||
8 |
signature BASIC_SIMPLIFIER = |
|
9 |
sig |
|
10 |
include BASIC_META_SIMPLIFIER |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
11 |
val change_simpset: (simpset -> simpset) -> unit |
16014 | 12 |
val simpset_of: theory -> simpset |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
13 |
val simpset: unit -> simpset |
16014 | 14 |
val SIMPSET: (simpset -> tactic) -> tactic |
15 |
val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic |
|
16 |
val Addsimps: thm list -> unit |
|
17 |
val Delsimps: thm list -> unit |
|
18 |
val Addsimprocs: simproc list -> unit |
|
19 |
val Delsimprocs: simproc list -> unit |
|
20 |
val Addcongs: thm list -> unit |
|
21 |
val Delcongs: thm list -> unit |
|
22 |
val local_simpset_of: Proof.context -> simpset |
|
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
23 |
val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic |
16014 | 24 |
val safe_asm_full_simp_tac: simpset -> int -> tactic |
25 |
val simp_tac: simpset -> int -> tactic |
|
26 |
val asm_simp_tac: simpset -> int -> tactic |
|
27 |
val full_simp_tac: simpset -> int -> tactic |
|
28 |
val asm_lr_simp_tac: simpset -> int -> tactic |
|
29 |
val asm_full_simp_tac: simpset -> int -> tactic |
|
30 |
val Simp_tac: int -> tactic |
|
31 |
val Asm_simp_tac: int -> tactic |
|
32 |
val Full_simp_tac: int -> tactic |
|
33 |
val Asm_lr_simp_tac: int -> tactic |
|
34 |
val Asm_full_simp_tac: int -> tactic |
|
35 |
val simplify: simpset -> thm -> thm |
|
36 |
val asm_simplify: simpset -> thm -> thm |
|
37 |
val full_simplify: simpset -> thm -> thm |
|
38 |
val asm_lr_simplify: simpset -> thm -> thm |
|
39 |
val asm_full_simplify: simpset -> thm -> thm |
|
40 |
end; |
|
41 |
||
42 |
signature SIMPLIFIER = |
|
43 |
sig |
|
44 |
include BASIC_SIMPLIFIER |
|
30356 | 45 |
val pretty_ss: Proof.context -> simpset -> Pretty.T |
17004 | 46 |
val clear_ss: simpset -> simpset |
17723 | 47 |
val debug_bounds: bool ref |
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
48 |
val inherit_context: simpset -> simpset -> simpset |
17898 | 49 |
val the_context: simpset -> Proof.context |
50 |
val context: Proof.context -> simpset -> simpset |
|
51 |
val theory_context: theory -> simpset -> simpset |
|
16458 | 52 |
val simproc_i: theory -> string -> term list |
53 |
-> (theory -> simpset -> term -> thm option) -> simproc |
|
54 |
val simproc: theory -> string -> string list |
|
55 |
-> (theory -> simpset -> term -> thm option) -> simproc |
|
23598 | 56 |
val rewrite: simpset -> conv |
57 |
val asm_rewrite: simpset -> conv |
|
58 |
val full_rewrite: simpset -> conv |
|
59 |
val asm_lr_rewrite: simpset -> conv |
|
60 |
val asm_full_rewrite: simpset -> conv |
|
22379 | 61 |
val get_ss: Context.generic -> simpset |
62 |
val map_ss: (simpset -> simpset) -> Context.generic -> Context.generic |
|
18728 | 63 |
val attrib: (simpset * thm list -> simpset) -> attribute |
64 |
val simp_add: attribute |
|
65 |
val simp_del: attribute |
|
66 |
val cong_add: attribute |
|
67 |
val cong_del: attribute |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
68 |
val map_simpset: (simpset -> simpset) -> theory -> theory |
24024 | 69 |
val get_simproc: Context.generic -> xstring -> simproc |
22236 | 70 |
val def_simproc: {name: string, lhss: string list, |
71 |
proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} -> |
|
22201 | 72 |
local_theory -> local_theory |
22236 | 73 |
val def_simproc_i: {name: string, lhss: term list, |
74 |
proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} -> |
|
22201 | 75 |
local_theory -> local_theory |
30513 | 76 |
val cong_modifiers: Method.modifier parser list |
77 |
val simp_modifiers': Method.modifier parser list |
|
78 |
val simp_modifiers: Method.modifier parser list |
|
79 |
val method_setup: Method.modifier parser list -> theory -> theory |
|
18708 | 80 |
val easy_setup: thm -> thm list -> theory -> theory |
16014 | 81 |
end; |
82 |
||
83 |
structure Simplifier: SIMPLIFIER = |
|
84 |
struct |
|
85 |
||
21708 | 86 |
open MetaSimplifier; |
87 |
||
88 |
||
30356 | 89 |
(** pretty printing **) |
90 |
||
91 |
fun pretty_ss ctxt ss = |
|
92 |
let |
|
93 |
val pretty_cterm = Syntax.pretty_term ctxt o Thm.term_of; |
|
94 |
val pretty_thm = ProofContext.pretty_thm ctxt; |
|
95 |
fun pretty_proc (name, lhss) = Pretty.big_list (name ^ ":") (map pretty_cterm lhss); |
|
96 |
fun pretty_cong (name, thm) = |
|
97 |
Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, pretty_thm thm]; |
|
98 |
||
99 |
val {simps, procs, congs, loopers, unsafe_solvers, safe_solvers, ...} = dest_ss ss; |
|
100 |
in |
|
101 |
[Pretty.big_list "simplification rules:" (map (pretty_thm o #2) simps), |
|
102 |
Pretty.big_list "simplification procedures:" (map pretty_proc (sort_wrt #1 procs)), |
|
103 |
Pretty.big_list "congruences:" (map pretty_cong congs), |
|
104 |
Pretty.strs ("loopers:" :: map quote loopers), |
|
105 |
Pretty.strs ("unsafe solvers:" :: map quote unsafe_solvers), |
|
106 |
Pretty.strs ("safe solvers:" :: map quote safe_solvers)] |
|
107 |
|> Pretty.chunks |
|
108 |
end; |
|
109 |
||
110 |
||
111 |
||
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
112 |
(** simpset data **) |
16014 | 113 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
114 |
structure SimpsetData = GenericDataFun |
22846 | 115 |
( |
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
116 |
type T = simpset; |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
117 |
val empty = empty_ss; |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
118 |
fun extend ss = MetaSimplifier.inherit_context empty_ss ss; |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
119 |
fun merge _ = merge_ss; |
22846 | 120 |
); |
16014 | 121 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
122 |
val get_ss = SimpsetData.get; |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
123 |
val map_ss = SimpsetData.map; |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
124 |
|
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
125 |
|
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
126 |
(* attributes *) |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
127 |
|
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
128 |
fun attrib f = Thm.declaration_attribute (fn th => map_ss (fn ss => f (ss, [th]))); |
16014 | 129 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
130 |
val simp_add = attrib (op addsimps); |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
131 |
val simp_del = attrib (op delsimps); |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
132 |
val cong_add = attrib (op addcongs); |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
133 |
val cong_del = attrib (op delcongs); |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
134 |
|
16014 | 135 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
136 |
(* global simpset *) |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
137 |
|
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
138 |
fun map_simpset f = Context.theory_map (map_ss f); |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
139 |
fun change_simpset f = Context.>> (Context.map_theory (map_simpset f)); |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
140 |
fun simpset_of thy = MetaSimplifier.context (ProofContext.init thy) (get_ss (Context.Theory thy)); |
26425
6561665c5cb1
renamed ML_Context.the_context to ML_Context.the_global_context;
wenzelm
parents:
24509
diff
changeset
|
141 |
val simpset = simpset_of o ML_Context.the_global_context; |
16014 | 142 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
143 |
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
|
144 |
fun SIMPSET' tacf i st = tacf (simpset_of (Thm.theory_of_thm st)) i st; |
16014 | 145 |
|
17883
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents:
17723
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
fun Delcongs args = change_simpset (fn ss => ss delcongs args); |
16014 | 152 |
|
153 |
||
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
154 |
(* local simpset *) |
16014 | 155 |
|
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
156 |
fun local_simpset_of ctxt = MetaSimplifier.context ctxt (get_ss (Context.Proof ctxt)); |
16014 | 157 |
|
27338 | 158 |
val _ = ML_Antiquote.value "simpset" |
159 |
(Scan.succeed "Simplifier.local_simpset_of (ML_Context.the_local_context ())"); |
|
22132 | 160 |
|
16014 | 161 |
|
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
162 |
|
22201 | 163 |
(** named simprocs **) |
164 |
||
23655
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23598
diff
changeset
|
165 |
fun err_dup_simproc name = error ("Duplicate simproc: " ^ quote name); |
22201 | 166 |
|
22236 | 167 |
|
22204 | 168 |
(* data *) |
169 |
||
22201 | 170 |
structure Simprocs = GenericDataFun |
171 |
( |
|
22236 | 172 |
type T = simproc NameSpace.table; |
22201 | 173 |
val empty = NameSpace.empty_table; |
174 |
val extend = I; |
|
22236 | 175 |
fun merge _ simprocs = NameSpace.merge_tables eq_simproc simprocs |
23655
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
wenzelm
parents:
23598
diff
changeset
|
176 |
handle Symtab.DUP dup => err_dup_simproc dup; |
22201 | 177 |
); |
178 |
||
22204 | 179 |
|
180 |
(* get simprocs *) |
|
181 |
||
24024 | 182 |
fun get_simproc context xname = |
22204 | 183 |
let |
24024 | 184 |
val (space, tab) = Simprocs.get context; |
22204 | 185 |
val name = NameSpace.intern space xname; |
186 |
in |
|
187 |
(case Symtab.lookup tab name of |
|
22236 | 188 |
SOME proc => proc |
22204 | 189 |
| NONE => error ("Undefined simplification procedure: " ^ quote name)) |
190 |
end; |
|
191 |
||
27338 | 192 |
val _ = ML_Antiquote.value "simproc" (Scan.lift Args.name >> (fn name => |
193 |
"Simplifier.get_simproc (ML_Context.the_generic_context ()) " ^ ML_Syntax.print_string name)); |
|
22204 | 194 |
|
195 |
||
196 |
(* define simprocs *) |
|
22201 | 197 |
|
198 |
local |
|
199 |
||
22236 | 200 |
fun gen_simproc prep {name, lhss, proc, identifier} lthy = |
22201 | 201 |
let |
28991 | 202 |
val b = Binding.name name; |
22236 | 203 |
val naming = LocalTheory.full_naming lthy; |
204 |
val simproc = make_simproc |
|
28991 | 205 |
{name = LocalTheory.full_name lthy b, |
22236 | 206 |
lhss = |
207 |
let |
|
208 |
val lhss' = prep lthy lhss; |
|
209 |
val ctxt' = lthy |
|
210 |
|> fold Variable.declare_term lhss' |
|
211 |
|> fold Variable.auto_fixes lhss'; |
|
212 |
in Variable.export_terms ctxt' lthy lhss' end |
|
213 |
|> map (Thm.cterm_of (ProofContext.theory_of lthy)), |
|
214 |
proc = proc, |
|
215 |
identifier = identifier} |
|
216 |
|> morph_simproc (LocalTheory.target_morphism lthy); |
|
22201 | 217 |
in |
24024 | 218 |
lthy |> LocalTheory.declaration (fn phi => |
22201 | 219 |
let |
28991 | 220 |
val b' = Morphism.binding phi b; |
22236 | 221 |
val simproc' = morph_simproc phi simproc; |
22201 | 222 |
in |
24024 | 223 |
Simprocs.map (fn simprocs => |
30466 | 224 |
NameSpace.define naming (b', simproc') simprocs |> snd |
28863 | 225 |
handle Symtab.DUP dup => err_dup_simproc dup) |
24024 | 226 |
#> map_ss (fn ss => ss addsimprocs [simproc']) |
22201 | 227 |
end) |
228 |
end; |
|
229 |
||
230 |
in |
|
231 |
||
24509
23ee6b7788c2
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24124
diff
changeset
|
232 |
val def_simproc = gen_simproc Syntax.read_terms; |
23ee6b7788c2
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24124
diff
changeset
|
233 |
val def_simproc_i = gen_simproc Syntax.check_terms; |
22201 | 234 |
|
235 |
end; |
|
236 |
||
237 |
||
238 |
||
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
239 |
(** simplification tactics and rules **) |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
240 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
241 |
fun solve_all_tac solvers ss = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
242 |
let |
30336 | 243 |
val (_, {subgoal_tac, ...}) = MetaSimplifier.internal_ss ss; |
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
244 |
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
|
245 |
in DEPTH_SOLVE (solve_tac 1) end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
246 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
247 |
(*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
|
248 |
fun generic_simp_tac safe mode ss = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
249 |
let |
30336 | 250 |
val (_, {loop_tacs, solvers = (unsafe_solvers, solvers), ...}) = MetaSimplifier.internal_ss ss; |
21286
b5e7b80caa6a
introduces canonical AList functions for loop_tacs
haftmann
parents:
20872
diff
changeset
|
251 |
val loop_tac = FIRST' (map (fn (_, tac) => tac ss) (rev loop_tacs)); |
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
252 |
val solve_tac = FIRST' (map (MetaSimplifier.solver ss) |
22717 | 253 |
(rev (if safe then solvers else unsafe_solvers))); |
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
254 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
255 |
fun simp_loop_tac i = |
23536
60a1672e298e
moved (asm_)rewrite_goal_tac from goal.ML to meta_simplifier.ML (no longer depends on SELECT_GOAL);
wenzelm
parents:
23086
diff
changeset
|
256 |
asm_rewrite_goal_tac mode (solve_all_tac unsafe_solvers) ss i THEN |
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
257 |
(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
|
258 |
in simp_loop_tac end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
259 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
260 |
local |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
261 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
262 |
fun simp rew mode ss thm = |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
263 |
let |
30336 | 264 |
val (_, {solvers = (unsafe_solvers, _), ...}) = MetaSimplifier.internal_ss ss; |
22717 | 265 |
val tacf = solve_all_tac (rev unsafe_solvers); |
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
266 |
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
|
267 |
in rew mode prover ss thm end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
268 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
269 |
in |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
270 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
271 |
val simp_thm = simp MetaSimplifier.rewrite_thm; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
272 |
val simp_cterm = simp MetaSimplifier.rewrite_cterm; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
273 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
274 |
end; |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
275 |
|
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
276 |
|
16806 | 277 |
(* tactics *) |
278 |
||
16014 | 279 |
val simp_tac = generic_simp_tac false (false, false, false); |
280 |
val asm_simp_tac = generic_simp_tac false (false, true, false); |
|
281 |
val full_simp_tac = generic_simp_tac false (true, false, false); |
|
282 |
val asm_lr_simp_tac = generic_simp_tac false (true, true, false); |
|
283 |
val asm_full_simp_tac = generic_simp_tac false (true, true, true); |
|
284 |
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true); |
|
285 |
||
286 |
(*the abstraction over the proof state delays the dereferencing*) |
|
287 |
fun Simp_tac i st = simp_tac (simpset ()) i st; |
|
288 |
fun Asm_simp_tac i st = asm_simp_tac (simpset ()) i st; |
|
289 |
fun Full_simp_tac i st = full_simp_tac (simpset ()) i st; |
|
290 |
fun Asm_lr_simp_tac i st = asm_lr_simp_tac (simpset ()) i st; |
|
291 |
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st; |
|
292 |
||
16806 | 293 |
|
294 |
(* conversions *) |
|
295 |
||
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
296 |
val simplify = simp_thm (false, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
297 |
val asm_simplify = simp_thm (false, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
298 |
val full_simplify = simp_thm (true, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
299 |
val asm_lr_simplify = simp_thm (true, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
300 |
val asm_full_simplify = simp_thm (true, true, true); |
16014 | 301 |
|
17967
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
302 |
val rewrite = simp_cterm (false, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
303 |
val asm_rewrite = simp_cterm (false, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
304 |
val full_rewrite = simp_cterm (true, false, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
305 |
val asm_lr_rewrite = simp_cterm (true, true, false); |
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents:
17898
diff
changeset
|
306 |
val asm_full_rewrite = simp_cterm (true, true, true); |
16014 | 307 |
|
308 |
||
309 |
||
310 |
(** concrete syntax of attributes **) |
|
311 |
||
312 |
(* add / del *) |
|
313 |
||
314 |
val simpN = "simp"; |
|
315 |
val congN = "cong"; |
|
316 |
val addN = "add"; |
|
317 |
val delN = "del"; |
|
318 |
val onlyN = "only"; |
|
319 |
val no_asmN = "no_asm"; |
|
320 |
val no_asm_useN = "no_asm_use"; |
|
321 |
val no_asm_simpN = "no_asm_simp"; |
|
322 |
val asm_lrN = "asm_lr"; |
|
323 |
||
324 |
||
24024 | 325 |
(* simprocs *) |
326 |
||
327 |
local |
|
328 |
||
329 |
val add_del = |
|
330 |
(Args.del -- Args.colon >> K (op delsimprocs) || |
|
331 |
Scan.option (Args.add -- Args.colon) >> K (op addsimprocs)) |
|
332 |
>> (fn f => fn simproc => fn phi => Thm.declaration_attribute |
|
333 |
(K (map_ss (fn ss => f (ss, [morph_simproc phi simproc]))))); |
|
334 |
||
335 |
in |
|
336 |
||
30528 | 337 |
val simproc_att = |
338 |
Scan.peek (fn context => |
|
24024 | 339 |
add_del :|-- (fn decl => |
340 |
Scan.repeat1 (Args.named_attribute (decl o get_simproc context)) |
|
30528 | 341 |
>> (Library.apply o map Morphism.form))); |
24024 | 342 |
|
343 |
end; |
|
24124
4399175e3014
turned simp_depth_limit into configuration option;
wenzelm
parents:
24024
diff
changeset
|
344 |
|
24024 | 345 |
|
16014 | 346 |
(* conversions *) |
347 |
||
348 |
local |
|
349 |
||
350 |
fun conv_mode x = |
|
351 |
((Args.parens (Args.$$$ no_asmN) >> K simplify || |
|
352 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify || |
|
353 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simplify || |
|
354 |
Scan.succeed asm_full_simplify) |> Scan.lift) x; |
|
355 |
||
356 |
in |
|
357 |
||
30528 | 358 |
val simplified = conv_mode -- Attrib.thms >> |
359 |
(fn (f, ths) => Thm.rule_attribute (fn context => |
|
27021 | 360 |
f ((if null ths then I else MetaSimplifier.clear_ss) |
30528 | 361 |
(local_simpset_of (Context.proof_of context)) addsimps ths))); |
16014 | 362 |
|
363 |
end; |
|
364 |
||
365 |
||
366 |
(* setup attributes *) |
|
367 |
||
26463 | 368 |
val _ = Context.>> (Context.map_theory |
30528 | 369 |
(Attrib.setup (Binding.name simpN) (Attrib.add_del simp_add simp_del) |
370 |
"declaration of Simplifier rewrite rule" #> |
|
371 |
Attrib.setup (Binding.name congN) (Attrib.add_del cong_add cong_del) |
|
372 |
"declaration of Simplifier congruence rule" #> |
|
373 |
Attrib.setup (Binding.name "simproc") simproc_att "declaration of simplification procedures" #> |
|
374 |
Attrib.setup (Binding.name "simplified") simplified "simplified rule")); |
|
16014 | 375 |
|
376 |
||
377 |
||
378 |
(** proof methods **) |
|
379 |
||
380 |
(* simplification *) |
|
381 |
||
382 |
val simp_options = |
|
383 |
(Args.parens (Args.$$$ no_asmN) >> K simp_tac || |
|
384 |
Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac || |
|
385 |
Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac || |
|
386 |
Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac || |
|
387 |
Scan.succeed asm_full_simp_tac); |
|
388 |
||
389 |
val cong_modifiers = |
|
18728 | 390 |
[Args.$$$ congN -- Args.colon >> K ((I, cong_add): Method.modifier), |
391 |
Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add), |
|
392 |
Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del)]; |
|
16014 | 393 |
|
394 |
val simp_modifiers = |
|
18728 | 395 |
[Args.$$$ simpN -- Args.colon >> K (I, simp_add), |
396 |
Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add), |
|
397 |
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
|
398 |
Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon |
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
399 |
>> K (Context.proof_map (map_ss MetaSimplifier.clear_ss), simp_add)] |
16014 | 400 |
@ cong_modifiers; |
401 |
||
402 |
val simp_modifiers' = |
|
18728 | 403 |
[Args.add -- Args.colon >> K (I, simp_add), |
404 |
Args.del -- Args.colon >> K (I, simp_del), |
|
18688 | 405 |
Args.$$$ onlyN -- Args.colon |
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
406 |
>> K (Context.proof_map (map_ss MetaSimplifier.clear_ss), simp_add)] |
16014 | 407 |
@ cong_modifiers; |
408 |
||
409 |
fun simp_args more_mods = |
|
24124
4399175e3014
turned simp_depth_limit into configuration option;
wenzelm
parents:
24024
diff
changeset
|
410 |
Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options) |
16684
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents:
16458
diff
changeset
|
411 |
(more_mods @ simp_modifiers'); |
16014 | 412 |
|
30510
4120fc59dd85
unified type Proof.method and pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
413 |
fun simp_method (prems, tac) ctxt = METHOD (fn facts => |
16014 | 414 |
ALLGOALS (Method.insert_tac (prems @ facts)) THEN |
24124
4399175e3014
turned simp_depth_limit into configuration option;
wenzelm
parents:
24024
diff
changeset
|
415 |
(CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt)); |
16014 | 416 |
|
30510
4120fc59dd85
unified type Proof.method and pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
417 |
fun simp_method' (prems, tac) ctxt = METHOD (fn facts => |
16014 | 418 |
HEADGOAL (Method.insert_tac (prems @ facts) THEN' |
24124
4399175e3014
turned simp_depth_limit into configuration option;
wenzelm
parents:
24024
diff
changeset
|
419 |
((CHANGED_PROP) oo tac) (local_simpset_of ctxt))); |
16014 | 420 |
|
421 |
||
422 |
||
18708 | 423 |
(** setup **) |
424 |
||
425 |
fun method_setup more_mods = Method.add_methods |
|
16014 | 426 |
[(simpN, simp_args more_mods simp_method', "simplification"), |
427 |
("simp_all", simp_args more_mods simp_method, "simplification (all goals)")]; |
|
428 |
||
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
429 |
fun easy_setup reflect trivs = method_setup [] #> Context.theory_map (map_ss (fn _ => |
16014 | 430 |
let |
431 |
val trivialities = Drule.reflexive_thm :: trivs; |
|
432 |
||
433 |
fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac]; |
|
434 |
val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac; |
|
435 |
||
436 |
(*no premature instantiation of variables during simplification*) |
|
437 |
fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac]; |
|
438 |
val safe_solver = mk_solver "easy safe" safe_solver_tac; |
|
439 |
||
440 |
fun mk_eq thm = |
|
20872 | 441 |
if can Logic.dest_equals (Thm.concl_of thm) then [thm] |
16014 | 442 |
else [thm RS reflect] handle THM _ => []; |
443 |
||
26653 | 444 |
fun mksimps thm = mk_eq (Thm.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm); |
26497
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
445 |
in |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
446 |
empty_ss setsubgoaler asm_simp_tac |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
447 |
setSSolver safe_solver |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
448 |
setSolver unsafe_solver |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
449 |
setmksimps mksimps |
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26463
diff
changeset
|
450 |
end)); |
16014 | 451 |
|
452 |
end; |
|
453 |
||
454 |
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier; |
|
455 |
open BasicSimplifier; |