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