author | wenzelm |
Fri, 30 Jul 1999 13:43:26 +0200 | |
changeset 7132 | 5c31d06ead04 |
parent 6994 | f22a51ed9f11 |
child 7177 | 6bb7ad30f3da |
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 |
|
4795 | 5 |
Generic simplifier, suitable for most logics. See Pure/thm.ML for the |
6 |
actual meta-level rewriting engine. |
|
1 | 7 |
*) |
1260 | 8 |
|
3551 | 9 |
infix 4 |
4682 | 10 |
setsubgoaler setloop addloop delloop setSSolver addSSolver setSolver |
4677 | 11 |
addSolver addsimps delsimps addeqcongs deleqcongs |
12 |
setmksimps setmkeqTrue setmksym settermless addsimprocs delsimprocs; |
|
2567 | 13 |
|
4795 | 14 |
signature BASIC_SIMPLIFIER = |
0 | 15 |
sig |
2509 | 16 |
type simproc |
3577
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
17 |
val mk_simproc: string -> cterm list |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
18 |
-> (Sign.sg -> thm list -> term -> thm option) -> simproc |
0 | 19 |
type simpset |
2503 | 20 |
val empty_ss: simpset |
3551 | 21 |
val rep_ss: simpset -> |
22 |
{mss: meta_simpset, |
|
23 |
subgoal_tac: simpset -> int -> tactic, |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
24 |
loop_tacs: (string * (int -> tactic))list, |
3551 | 25 |
finish_tac: thm list -> int -> tactic, |
26 |
unsafe_finish_tac: thm list -> int -> tactic}; |
|
27 |
val print_ss: simpset -> unit |
|
4366 | 28 |
val print_simpset: theory -> unit |
2629 | 29 |
val setsubgoaler: simpset * (simpset -> int -> tactic) -> simpset |
30 |
val setloop: simpset * (int -> tactic) -> simpset |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
31 |
val addloop: simpset * (string * (int -> tactic)) -> simpset |
4682 | 32 |
val delloop: simpset * string -> simpset |
2629 | 33 |
val setSSolver: simpset * (thm list -> int -> tactic) -> simpset |
34 |
val addSSolver: simpset * (thm list -> int -> tactic) -> simpset |
|
35 |
val setSolver: simpset * (thm list -> int -> tactic) -> simpset |
|
36 |
val addSolver: simpset * (thm list -> int -> tactic) -> simpset |
|
3577
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
37 |
val setmksimps: simpset * (thm -> thm list) -> simpset |
4677 | 38 |
val setmkeqTrue: simpset * (thm -> thm option) -> simpset |
39 |
val setmksym: simpset * (thm -> thm option) -> simpset |
|
3577
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
40 |
val settermless: simpset * (term * term -> bool) -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
41 |
val addsimps: simpset * thm list -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
42 |
val delsimps: simpset * thm list -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
43 |
val addeqcongs: simpset * thm list -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
44 |
val deleqcongs: simpset * thm list -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
45 |
val addsimprocs: simpset * simproc list -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
46 |
val delsimprocs: simpset * simproc list -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
47 |
val merge_ss: simpset * simpset -> simpset |
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
48 |
val prems_of_ss: simpset -> thm list |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
49 |
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
|
50 |
val simpset_ref_of: theory -> simpset ref |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
51 |
val simpset_of_sg: Sign.sg -> simpset |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
52 |
val simpset_of: theory -> simpset |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
53 |
val SIMPSET: (simpset -> tactic) -> tactic |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
54 |
val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
55 |
val simpset: unit -> simpset |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
56 |
val simpset_ref: unit -> simpset ref |
1243 | 57 |
val Addsimps: thm list -> unit |
58 |
val Delsimps: thm list -> unit |
|
2509 | 59 |
val Addsimprocs: simproc list -> unit |
60 |
val Delsimprocs: simproc list -> unit |
|
2629 | 61 |
val simp_tac: simpset -> int -> tactic |
62 |
val asm_simp_tac: simpset -> int -> tactic |
|
63 |
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
|
64 |
val asm_lr_simp_tac: simpset -> int -> tactic |
2629 | 65 |
val asm_full_simp_tac: simpset -> int -> tactic |
66 |
val safe_asm_full_simp_tac: simpset -> int -> tactic |
|
67 |
val Simp_tac: int -> tactic |
|
68 |
val Asm_simp_tac: int -> tactic |
|
69 |
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
|
70 |
val Asm_lr_simp_tac: int -> tactic |
2629 | 71 |
val Asm_full_simp_tac: int -> tactic |
3557 | 72 |
val simplify: simpset -> thm -> thm |
73 |
val asm_simplify: simpset -> thm -> thm |
|
74 |
val full_simplify: simpset -> thm -> thm |
|
75 |
val asm_full_simplify: simpset -> thm -> thm |
|
0 | 76 |
end; |
77 |
||
4795 | 78 |
signature SIMPLIFIER = |
79 |
sig |
|
80 |
include BASIC_SIMPLIFIER |
|
5082 | 81 |
val rewrite: simpset -> cterm -> thm |
82 |
val asm_rewrite: simpset -> cterm -> thm |
|
83 |
val full_rewrite: simpset -> cterm -> thm |
|
84 |
val asm_full_rewrite: simpset -> cterm -> thm |
|
5842 | 85 |
val print_local_simpset: Proof.context -> unit |
86 |
val get_local_simpset: Proof.context -> simpset |
|
87 |
val put_local_simpset: simpset -> Proof.context -> Proof.context |
|
4855 | 88 |
val simp_add_global: theory attribute |
89 |
val simp_del_global: theory attribute |
|
6911 | 90 |
val simp_only_global: theory attribute |
5842 | 91 |
val simp_add_local: Proof.context attribute |
92 |
val simp_del_local: Proof.context attribute |
|
6911 | 93 |
val simp_only_local: Proof.context attribute |
5928 | 94 |
val simp_modifiers: (Args.T list -> (Proof.context attribute * Args.T list)) list |
5842 | 95 |
val setup: (theory -> theory) list |
4795 | 96 |
end; |
2503 | 97 |
|
98 |
structure Simplifier: SIMPLIFIER = |
|
0 | 99 |
struct |
100 |
||
2509 | 101 |
|
102 |
(** simplification procedures **) |
|
103 |
||
104 |
(* datatype simproc *) |
|
105 |
||
106 |
datatype simproc = |
|
3577
9715b6e3ec5f
added prems argument to simplification procedures;
wenzelm
parents:
3557
diff
changeset
|
107 |
Simproc of string * cterm list * (Sign.sg -> thm list -> term -> thm option) * stamp; |
2509 | 108 |
|
3557 | 109 |
fun mk_simproc name lhss proc = |
110 |
Simproc (name, map (Thm.cterm_fun Logic.varify) lhss, proc, stamp ()); |
|
111 |
||
3551 | 112 |
fun rep_simproc (Simproc args) = args; |
2509 | 113 |
|
114 |
||
115 |
||
2503 | 116 |
(** simplification sets **) |
117 |
||
118 |
(* type simpset *) |
|
119 |
||
0 | 120 |
datatype simpset = |
2503 | 121 |
Simpset of { |
122 |
mss: meta_simpset, |
|
2629 | 123 |
subgoal_tac: simpset -> int -> tactic, |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
124 |
loop_tacs: (string * (int -> tactic))list, |
2629 | 125 |
finish_tac: thm list -> int -> tactic, |
126 |
unsafe_finish_tac: thm list -> int -> tactic}; |
|
2503 | 127 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
128 |
fun make_ss (mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac) = |
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
129 |
Simpset {mss = mss, subgoal_tac = subgoal_tac, loop_tacs = loop_tacs, |
2629 | 130 |
finish_tac = finish_tac, unsafe_finish_tac = unsafe_finish_tac}; |
0 | 131 |
|
132 |
val empty_ss = |
|
6911 | 133 |
let val mss = Thm.set_mk_sym (Thm.empty_mss, Some o symmetric_fun) |
4677 | 134 |
in make_ss (mss, K (K no_tac), [], K (K no_tac), K (K no_tac)) end; |
3551 | 135 |
|
136 |
fun rep_ss (Simpset args) = args; |
|
137 |
fun prems_of_ss (Simpset {mss, ...}) = Thm.prems_of_mss mss; |
|
138 |
||
139 |
||
140 |
(* print simpsets *) |
|
2503 | 141 |
|
3551 | 142 |
fun print_ss ss = |
143 |
let |
|
144 |
val Simpset {mss, ...} = ss; |
|
145 |
val {simps, procs, congs} = Thm.dest_mss mss; |
|
2503 | 146 |
|
3551 | 147 |
val pretty_thms = map Display.pretty_thm; |
148 |
fun pretty_proc (name, lhss) = |
|
149 |
Pretty.big_list (name ^ ":") (map Display.pretty_cterm lhss); |
|
150 |
in |
|
151 |
Pretty.writeln (Pretty.big_list "simplification rules:" (pretty_thms simps)); |
|
152 |
Pretty.writeln (Pretty.big_list "simplification procedures:" (map pretty_proc procs)); |
|
153 |
Pretty.writeln (Pretty.big_list "congruences:" (pretty_thms congs)) |
|
154 |
end; |
|
2503 | 155 |
|
156 |
||
157 |
(* extend simpsets *) |
|
158 |
||
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
159 |
fun (Simpset {mss, subgoal_tac = _, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 160 |
setsubgoaler subgoal_tac = |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
161 |
make_ss (mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2629 | 162 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
163 |
fun (Simpset {mss, subgoal_tac, loop_tacs = _, finish_tac, unsafe_finish_tac}) |
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
164 |
setloop tac = |
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
165 |
make_ss (mss, subgoal_tac, [("",tac)], finish_tac, unsafe_finish_tac); |
2503 | 166 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
167 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
4741
7fcd106cb0ed
addloop: added warning in case of overwriting a looper
oheimb
parents:
4739
diff
changeset
|
168 |
addloop tac = make_ss (mss, subgoal_tac, |
5886 | 169 |
(case assoc_string (loop_tacs,(fst tac)) of None => () | Some x => |
170 |
warning ("overwriting looper "^fst tac); overwrite(loop_tacs,tac)), |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
171 |
finish_tac, unsafe_finish_tac); |
2567 | 172 |
|
6911 | 173 |
fun (ss as Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) delloop name = |
174 |
let val (del, rest) = partition (fn (n, _) => n = name) loop_tacs in |
|
175 |
if null del then (warning ("No such looper in simpset: " ^ name); ss) |
|
176 |
else make_ss (mss, subgoal_tac, rest, finish_tac, unsafe_finish_tac) |
|
4682 | 177 |
end; |
178 |
||
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
179 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac = _, unsafe_finish_tac}) |
3551 | 180 |
setSSolver finish_tac = |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
181 |
make_ss (mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2503 | 182 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
183 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 184 |
addSSolver tac = |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
185 |
make_ss (mss, subgoal_tac, loop_tacs, fn hyps => finish_tac hyps ORELSE' tac hyps, |
3551 | 186 |
unsafe_finish_tac); |
2503 | 187 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
188 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac = _}) |
3551 | 189 |
setSolver unsafe_finish_tac = |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
190 |
make_ss (mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2503 | 191 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
192 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 193 |
addSolver tac = |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
194 |
make_ss (mss, subgoal_tac, loop_tacs, finish_tac, |
3551 | 195 |
fn hyps => unsafe_finish_tac hyps ORELSE' tac hyps); |
2503 | 196 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
197 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 198 |
setmksimps mk_simps = |
2645
9d3a3e62bf34
mk_rews: automatically includes strip_shyps, zero_var_indexes;
wenzelm
parents:
2629
diff
changeset
|
199 |
make_ss (Thm.set_mk_rews (mss, map (Thm.strip_shyps o Drule.zero_var_indexes) o mk_simps), |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
200 |
subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2509 | 201 |
|
4677 | 202 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
203 |
setmkeqTrue mk_eq_True = |
|
204 |
make_ss (Thm.set_mk_eq_True (mss, mk_eq_True), |
|
205 |
subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
|
206 |
||
207 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
|
208 |
setmksym mksym = |
|
209 |
make_ss (Thm.set_mk_sym (mss, mksym), |
|
210 |
subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
|
211 |
||
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
212 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 213 |
settermless termless = |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
214 |
make_ss (Thm.set_termless (mss, termless), subgoal_tac, loop_tacs, |
3551 | 215 |
finish_tac, unsafe_finish_tac); |
216 |
||
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
217 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 218 |
addsimps rews = |
6911 | 219 |
make_ss (Thm.add_simps (mss, rews), subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2503 | 220 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
221 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 222 |
delsimps rews = |
6911 | 223 |
make_ss (Thm.del_simps (mss, rews), subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2503 | 224 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
225 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 226 |
addeqcongs newcongs = |
6911 | 227 |
make_ss (Thm.add_congs (mss, newcongs), subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2509 | 228 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
229 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 230 |
deleqcongs oldcongs = |
6911 | 231 |
make_ss (Thm.del_congs (mss, oldcongs), subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2629 | 232 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
233 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 234 |
addsimprocs simprocs = |
235 |
make_ss |
|
236 |
(Thm.add_simprocs (mss, map rep_simproc simprocs), |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
237 |
subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2509 | 238 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
239 |
fun (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) |
3551 | 240 |
delsimprocs simprocs = |
241 |
make_ss |
|
242 |
(Thm.del_simprocs (mss, map rep_simproc simprocs), |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
243 |
subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
2503 | 244 |
|
6911 | 245 |
fun onlysimps (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}, rews) = |
246 |
make_ss (Thm.clear_mss mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac) |
|
247 |
addsimps rews; |
|
248 |
||
2503 | 249 |
|
5886 | 250 |
(* merge simpsets *) (*NOTE: ignores tactics of 2nd simpset (except loopers)*) |
2503 | 251 |
|
3551 | 252 |
fun merge_ss |
4795 | 253 |
(Simpset {mss = mss1, loop_tacs = loop_tacs1, subgoal_tac, finish_tac, unsafe_finish_tac}, |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
254 |
Simpset {mss = mss2, loop_tacs = loop_tacs2, ...}) = |
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
255 |
make_ss (Thm.merge_mss (mss1, mss2), subgoal_tac, |
4795 | 256 |
merge_alists loop_tacs1 loop_tacs2, finish_tac, unsafe_finish_tac); |
2503 | 257 |
|
258 |
||
3557 | 259 |
|
5024 | 260 |
(** global and local simpset data **) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
261 |
|
5842 | 262 |
(* theory data kind 'Provers/simpset' *) |
4795 | 263 |
|
5842 | 264 |
structure GlobalSimpsetArgs = |
5024 | 265 |
struct |
5842 | 266 |
val name = "Provers/simpset"; |
5024 | 267 |
type T = simpset ref; |
0 | 268 |
|
5024 | 269 |
val empty = ref empty_ss; |
6556 | 270 |
fun copy (ref ss) = (ref ss): T; (*create new reference!*) |
271 |
val prep_ext = copy; |
|
5024 | 272 |
fun merge (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2)); |
273 |
fun print _ (ref ss) = print_ss ss; |
|
274 |
end; |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
275 |
|
5842 | 276 |
structure GlobalSimpset = TheoryDataFun(GlobalSimpsetArgs); |
277 |
val print_simpset = GlobalSimpset.print; |
|
278 |
val simpset_ref_of_sg = GlobalSimpset.get_sg; |
|
279 |
val simpset_ref_of = GlobalSimpset.get; |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
280 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
281 |
|
4795 | 282 |
(* access global simpset *) |
0 | 283 |
|
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
284 |
val simpset_of_sg = ! o simpset_ref_of_sg; |
6391 | 285 |
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
|
286 |
|
6391 | 287 |
fun SIMPSET tacf state = tacf (simpset_of_sg (Thm.sign_of_thm state)) state; |
288 |
fun SIMPSET' tacf i state = tacf (simpset_of_sg (Thm.sign_of_thm state)) i state; |
|
0 | 289 |
|
5028 | 290 |
val simpset = simpset_of o Context.the_context; |
6391 | 291 |
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
|
292 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
293 |
|
4795 | 294 |
(* change global simpset *) |
4080
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
295 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
296 |
fun change_simpset f x = simpset_ref () := (f (simpset (), x)); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
297 |
|
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
298 |
val Addsimps = change_simpset (op addsimps); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
299 |
val Delsimps = change_simpset (op delsimps); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
300 |
val Addsimprocs = change_simpset (op addsimprocs); |
7dce11095b0a
new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents:
3728
diff
changeset
|
301 |
val Delsimprocs = change_simpset (op delsimprocs); |
2509 | 302 |
|
0 | 303 |
|
5842 | 304 |
(* proof data kind 'Provers/simpset' *) |
4795 | 305 |
|
5842 | 306 |
structure LocalSimpsetArgs = |
307 |
struct |
|
308 |
val name = "Provers/simpset"; |
|
309 |
type T = simpset; |
|
310 |
val init = simpset_of; |
|
311 |
fun print _ ss = print_ss ss; |
|
312 |
end; |
|
4795 | 313 |
|
5842 | 314 |
structure LocalSimpset = ProofDataFun(LocalSimpsetArgs); |
315 |
val print_local_simpset = LocalSimpset.print; |
|
316 |
val get_local_simpset = LocalSimpset.get; |
|
317 |
val put_local_simpset = LocalSimpset.put; |
|
4795 | 318 |
|
319 |
||
5886 | 320 |
(* attributes *) |
321 |
||
322 |
fun change_global_ss f (thy, th) = |
|
323 |
let val r = simpset_ref_of thy |
|
6096 | 324 |
in r := f (! r, [th]); (thy, th) end; |
5886 | 325 |
|
326 |
fun change_local_ss f (ctxt, th) = |
|
6096 | 327 |
let val ss = f (get_local_simpset ctxt, [th]) |
5886 | 328 |
in (put_local_simpset ss ctxt, th) end; |
329 |
||
330 |
val simp_add_global = change_global_ss (op addsimps); |
|
331 |
val simp_del_global = change_global_ss (op delsimps); |
|
6911 | 332 |
val simp_only_global = change_global_ss onlysimps; |
5886 | 333 |
val simp_add_local = change_local_ss (op addsimps); |
334 |
val simp_del_local = change_local_ss (op delsimps); |
|
6911 | 335 |
val simp_only_local = change_local_ss onlysimps; |
5886 | 336 |
|
337 |
||
3557 | 338 |
|
2503 | 339 |
(** simplification tactics **) |
0 | 340 |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
341 |
fun solve_all_tac (subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac) mss = |
3557 | 342 |
let |
343 |
val ss = |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
344 |
make_ss (mss, subgoal_tac, loop_tacs, unsafe_finish_tac, unsafe_finish_tac); |
4612 | 345 |
val solve1_tac = (subgoal_tac ss THEN_ALL_NEW (K no_tac)) 1 |
3557 | 346 |
in DEPTH_SOLVE solve1_tac end; |
347 |
||
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
348 |
fun loop_tac loop_tacs = FIRST'(map snd loop_tacs); |
3557 | 349 |
|
2629 | 350 |
(*not totally safe: may instantiate unknowns that appear also in other subgoals*) |
351 |
fun basic_gen_simp_tac mode = |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
352 |
fn (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) => |
3551 | 353 |
let |
4612 | 354 |
fun simp_loop_tac i = |
355 |
asm_rewrite_goal_tac mode |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
356 |
(solve_all_tac (subgoal_tac,loop_tacs,finish_tac,unsafe_finish_tac)) |
4612 | 357 |
mss i |
358 |
THEN (finish_tac (prems_of_mss mss) i ORELSE |
|
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
359 |
TRY ((loop_tac loop_tacs THEN_ALL_NEW simp_loop_tac) i)) |
4612 | 360 |
in simp_loop_tac end; |
0 | 361 |
|
3551 | 362 |
fun gen_simp_tac mode (ss as Simpset {unsafe_finish_tac, ...}) = |
363 |
basic_gen_simp_tac mode (ss setSSolver unsafe_finish_tac); |
|
364 |
||
4713 | 365 |
val simp_tac = gen_simp_tac (false, false, false); |
366 |
val asm_simp_tac = gen_simp_tac (false, true, false); |
|
367 |
val full_simp_tac = gen_simp_tac (true, false, false); |
|
4722
d2e44673c21e
The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents:
4713
diff
changeset
|
368 |
val asm_lr_simp_tac = gen_simp_tac (true, true, false); |
d2e44673c21e
The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents:
4713
diff
changeset
|
369 |
val asm_full_simp_tac = gen_simp_tac (true, true, true); |
0 | 370 |
|
2629 | 371 |
(*not totally safe: may instantiate unknowns that appear also in other subgoals*) |
4713 | 372 |
val safe_asm_full_simp_tac = basic_gen_simp_tac (true, true, false); |
2629 | 373 |
|
4795 | 374 |
(*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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st; |
406 | 380 |
|
3557 | 381 |
|
4795 | 382 |
|
5082 | 383 |
(** simplification rules and conversions **) |
3557 | 384 |
|
5082 | 385 |
fun simp rew mode (Simpset {mss, subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac}) thm = |
3557 | 386 |
let |
4668
131989b78417
Little reorganization. Loop tactics have names now.
nipkow
parents:
4612
diff
changeset
|
387 |
val tacf = solve_all_tac (subgoal_tac, loop_tacs, finish_tac, unsafe_finish_tac); |
4271
3a82492e70c5
changed Pure/Sequence interface -- isatool fixseq;
wenzelm
parents:
4259
diff
changeset
|
388 |
fun prover m th = apsome fst (Seq.pull (tacf m th)); |
5082 | 389 |
in rew mode prover mss thm end; |
390 |
||
391 |
val simp_thm = simp Drule.rewrite_thm; |
|
392 |
val simp_cterm = simp Drule.rewrite_cterm; |
|
3557 | 393 |
|
5082 | 394 |
val simplify = simp_thm (false, false, false); |
395 |
val asm_simplify = simp_thm (false, true, false); |
|
396 |
val full_simplify = simp_thm (true, false, false); |
|
397 |
val asm_full_simplify = simp_thm (true, true, false); |
|
398 |
||
399 |
val rewrite = simp_cterm (false, false, false); |
|
400 |
val asm_rewrite = simp_cterm (false, true, false); |
|
401 |
val full_rewrite = simp_cterm (true, false, false); |
|
402 |
val asm_full_rewrite = simp_cterm (true, true, false); |
|
3557 | 403 |
|
404 |
||
4795 | 405 |
|
5886 | 406 |
(** concrete syntax of attributes **) |
5842 | 407 |
|
5886 | 408 |
(* add / del *) |
5842 | 409 |
|
5928 | 410 |
val simpN = "simp"; |
6911 | 411 |
val asm_simpN = "asm_simp"; |
5928 | 412 |
val addN = "add"; |
413 |
val delN = "del"; |
|
6911 | 414 |
val onlyN = "only"; |
5928 | 415 |
val otherN = "other"; |
5842 | 416 |
|
5886 | 417 |
fun simp_att change = |
5928 | 418 |
(Args.$$$ addN >> K (op addsimps) || |
419 |
Args.$$$ delN >> K (op delsimps) || |
|
6911 | 420 |
Args.$$$ onlyN >> K onlysimps || |
5886 | 421 |
Scan.succeed (op addsimps)) |
422 |
>> change |
|
423 |
|> Scan.lift |
|
424 |
|> Attrib.syntax; |
|
5842 | 425 |
|
5886 | 426 |
val simp_attr = (simp_att change_global_ss, simp_att change_local_ss); |
5842 | 427 |
|
428 |
||
429 |
(* conversions *) |
|
430 |
||
431 |
fun conv_attr f = |
|
6096 | 432 |
(Attrib.no_args (Drule.rule_attribute (f o simpset_of)), |
433 |
Attrib.no_args (Drule.rule_attribute (f o get_local_simpset))); |
|
5842 | 434 |
|
435 |
||
436 |
(* setup_attrs *) |
|
437 |
||
438 |
val setup_attrs = Attrib.add_attributes |
|
5928 | 439 |
[(simpN, simp_attr, "simplification rule"), |
5842 | 440 |
("simplify", conv_attr simplify, "simplify rule"), |
441 |
("asm_simplify", conv_attr asm_simplify, "simplify rule, using assumptions"), |
|
442 |
("full_simplify", conv_attr full_simplify, "fully simplify rule"), |
|
443 |
("asm_full_simplify", conv_attr asm_full_simplify, "fully simplify rule, using assumptions")]; |
|
444 |
||
445 |
||
446 |
||
447 |
(** proof methods **) |
|
448 |
||
449 |
(* simplification *) |
|
450 |
||
5928 | 451 |
val simp_modifiers = |
452 |
[Args.$$$ simpN -- Args.$$$ addN >> K simp_add_local, |
|
453 |
Args.$$$ simpN -- Args.$$$ delN >> K simp_del_local, |
|
6911 | 454 |
Args.$$$ simpN -- Args.$$$ onlyN >> K simp_only_local, |
455 |
Args.$$$ otherN >> K I]; |
|
5928 | 456 |
|
457 |
val simp_modifiers' = |
|
458 |
[Args.$$$ addN >> K simp_add_local, |
|
459 |
Args.$$$ delN >> K simp_del_local, |
|
6911 | 460 |
Args.$$$ onlyN >> K simp_only_local, |
5928 | 461 |
Args.$$$ otherN >> K I]; |
462 |
||
463 |
val simp_args = Method.only_sectioned_args simp_modifiers'; |
|
5842 | 464 |
|
6911 | 465 |
fun simp_meth thin cut tac ctxt = Method.METHOD (fn facts => |
6534 | 466 |
FIRSTGOAL |
6911 | 467 |
((if thin then REPEAT_DETERM o etac Drule.thin_rl else K all_tac) |
6994 | 468 |
THEN' (if cut then Method.same_tac facts else K all_tac) |
6534 | 469 |
THEN' tac (get_local_simpset ctxt))); |
5842 | 470 |
|
6911 | 471 |
val simp_method = simp_args ooo simp_meth; |
5842 | 472 |
|
473 |
||
474 |
(* setup_methods *) |
|
475 |
||
476 |
val setup_methods = Method.add_methods |
|
6911 | 477 |
[(simpN, simp_method true true asm_full_simp_tac, "simplification"), |
478 |
(asm_simpN, simp_method false true asm_full_simp_tac, |
|
479 |
"simplification (including assumption)"), |
|
7132 | 480 |
("simp_tac", simp_method false false simp_tac, "simp_tac (improper!)"), |
481 |
("asm_simp_tac", simp_method false false asm_simp_tac, "asm_simp_tac (improper!)"), |
|
482 |
("full_simp_tac", simp_method false false full_simp_tac, "full_simp_tac (improper!)"), |
|
483 |
("asm_full_simp_tac", simp_method false false asm_full_simp_tac, "asm_full_simp_tac (improper!)"), |
|
484 |
("asm_lr_simp_tac", simp_method false false asm_lr_simp_tac, "asm_lr_simp_tac (improper!)")]; |
|
5842 | 485 |
|
486 |
||
487 |
||
4795 | 488 |
(** theory setup **) |
489 |
||
5842 | 490 |
val setup = [GlobalSimpset.init, LocalSimpset.init, setup_attrs, setup_methods]; |
4795 | 491 |
|
492 |
||
1243 | 493 |
end; |
4795 | 494 |
|
495 |
||
496 |
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier; |
|
497 |
open BasicSimplifier; |