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