author  oheimb 
Sat, 15 Feb 1997 17:48:19 +0100  
changeset 2636  4b30dbe4a020 
parent 2595  548f8ed89a80 
child 2718  460fd0f8d478 
permissions  rwrr 
1465  1 
(* Title: HOL/simpdata.ML 
923  2 
ID: $Id$ 
1465  3 
Author: Tobias Nipkow 
923  4 
Copyright 1991 University of Cambridge 
5 

6 
Instantiation of the generic simplifier 

7 
*) 

8 

1984  9 
section "Simplifier"; 
10 

923  11 
open Simplifier; 
12 

1984  13 
(*** Addition of rules to simpsets and clasets simultaneously ***) 
14 

15 
(*Takes UNCONDITIONAL theorems of the form A<>B to 

2031  16 
the Safe Intr rule B==>A and 
17 
the Safe Destruct rule A==>B. 

1984  18 
Also ~A goes to the Safe Elim rule A ==> ?R 
19 
Failing other cases, A is added as a Safe Intr rule*) 

20 
local 

21 
val iff_const = HOLogic.eq_const HOLogic.boolT; 

22 

23 
fun addIff th = 

24 
(case HOLogic.dest_Trueprop (#prop(rep_thm th)) of 

2031  25 
(Const("not",_) $ A) => 
26 
AddSEs [zero_var_indexes (th RS notE)] 

27 
 (con $ _ $ _) => 

28 
if con=iff_const 

29 
then (AddSIs [zero_var_indexes (th RS iffD2)]; 

30 
AddSDs [zero_var_indexes (th RS iffD1)]) 

31 
else AddSIs [th] 

32 
 _ => AddSIs [th]; 

1984  33 
Addsimps [th]) 
34 
handle _ => error ("AddIffs: theorem must be unconditional\n" ^ 

2031  35 
string_of_thm th) 
1984  36 

37 
fun delIff th = 

38 
(case HOLogic.dest_Trueprop (#prop(rep_thm th)) of 

2031  39 
(Const("not",_) $ A) => 
40 
Delrules [zero_var_indexes (th RS notE)] 

41 
 (con $ _ $ _) => 

42 
if con=iff_const 

43 
then Delrules [zero_var_indexes (th RS iffD2), 

44 
zero_var_indexes (th RS iffD1)] 

45 
else Delrules [th] 

46 
 _ => Delrules [th]; 

1984  47 
Delsimps [th]) 
48 
handle _ => warning("DelIffs: ignoring conditional theorem\n" ^ 

2031  49 
string_of_thm th) 
1984  50 
in 
51 
val AddIffs = seq addIff 

52 
val DelIffs = seq delIff 

53 
end; 

54 

55 

923  56 
local 
57 

1922  58 
fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]); 
923  59 

1922  60 
val P_imp_P_iff_True = prover "P > (P = True)" RS mp; 
61 
val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection; 

923  62 

1922  63 
val not_P_imp_P_iff_F = prover "~P > (P = False)" RS mp; 
64 
val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection; 

923  65 

1922  66 
fun atomize pairs = 
67 
let fun atoms th = 

2031  68 
(case concl_of th of 
69 
Const("Trueprop",_) $ p => 

70 
(case head_of p of 

71 
Const(a,_) => 

72 
(case assoc(pairs,a) of 

73 
Some(rls) => flat (map atoms ([th] RL rls)) 

74 
 None => [th]) 

75 
 _ => [th]) 

76 
 _ => [th]) 

1922  77 
in atoms end; 
923  78 

2134  79 
fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th; 
80 

81 
in 

82 

1922  83 
fun mk_meta_eq r = case concl_of r of 
2031  84 
Const("==",_)$_$_ => r 
1922  85 
 _$(Const("op =",_)$_$_) => r RS eq_reflection 
86 
 _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False 

87 
 _ => r RS P_imp_P_eq_True; 

88 
(* last 2 lines requires all formulae to be of the from Trueprop(.) *) 

923  89 

2082  90 
val simp_thms = map prover 
91 
[ "(x=x) = True", 

92 
"(~True) = False", "(~False) = True", "(~ ~ P) = P", 

93 
"(~P) ~= P", "P ~= (~P)", "(P ~= Q) = (P = (~Q))", 

94 
"(True=P) = P", "(P=True) = P", 

95 
"(True > P) = P", "(False > P) = True", 

96 
"(P > True) = True", "(P > P) = True", 

97 
"(P > False) = (~P)", "(P > ~P) = (~P)", 

98 
"(P & True) = P", "(True & P) = P", 

99 
"(P & False) = False", "(False & P) = False", "(P & P) = P", 

100 
"(P  True) = True", "(True  P) = True", 

101 
"(P  False) = P", "(False  P) = P", "(P  P) = P", 

102 
"((~P) = (~Q)) = (P=Q)", 

2129  103 
"(!x.P) = P", "(? x.P) = P", "? x. x=t", "? x. t=x", 
2082  104 
"(? x. x=t & P(x)) = P(t)", "(? x. t=x & P(x)) = P(t)", 
105 
"(! x. x=t > P(x)) = P(t)", "(! x. t=x > P(x)) = P(t)" ]; 

923  106 

988  107 
(*Add congruence rules for = (instead of ==) *) 
2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

108 
infix 4 addcongs delcongs; 
923  109 
fun ss addcongs congs = ss addeqcongs (congs RL [eq_reflection]); 
2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

110 
fun ss delcongs congs = ss deleqcongs (congs RL [eq_reflection]); 
923  111 

1264  112 
fun Addcongs congs = (simpset := !simpset addcongs congs); 
2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

113 
fun Delcongs congs = (simpset := !simpset delcongs congs); 
1264  114 

923  115 
fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all; 
116 

1922  117 
val imp_cong = impI RSN 
118 
(2, prove_goal HOL.thy "(P=P')> (P'> (Q=Q'))> ((P>Q) = (P'>Q'))" 

119 
(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp); 

120 

1948
78e5bfcbc1e9
Added miniscoping to the simplifier: quantifiers are now pushed in
paulson
parents:
1922
diff
changeset

121 
(*Miniscoping: pushing in existential quantifiers*) 
78e5bfcbc1e9
Added miniscoping to the simplifier: quantifiers are now pushed in
paulson
parents:
1922
diff
changeset

122 
val ex_simps = map prover 
2031  123 
["(EX x. P x & Q) = ((EX x.P x) & Q)", 
124 
"(EX x. P & Q x) = (P & (EX x.Q x))", 

125 
"(EX x. P x  Q) = ((EX x.P x)  Q)", 

126 
"(EX x. P  Q x) = (P  (EX x.Q x))", 

127 
"(EX x. P x > Q) = ((ALL x.P x) > Q)", 

128 
"(EX x. P > Q x) = (P > (EX x.Q x))"]; 

1948
78e5bfcbc1e9
Added miniscoping to the simplifier: quantifiers are now pushed in
paulson
parents:
1922
diff
changeset

129 

78e5bfcbc1e9
Added miniscoping to the simplifier: quantifiers are now pushed in
paulson
parents:
1922
diff
changeset

130 
(*Miniscoping: pushing in universal quantifiers*) 
78e5bfcbc1e9
Added miniscoping to the simplifier: quantifiers are now pushed in
paulson
parents:
1922
diff
changeset

131 
val all_simps = map prover 
2031  132 
["(ALL x. P x & Q) = ((ALL x.P x) & Q)", 
133 
"(ALL x. P & Q x) = (P & (ALL x.Q x))", 

134 
"(ALL x. P x  Q) = ((ALL x.P x)  Q)", 

135 
"(ALL x. P  Q x) = (P  (ALL x.Q x))", 

136 
"(ALL x. P x > Q) = ((EX x.P x) > Q)", 

137 
"(ALL x. P > Q x) = (P > (ALL x.Q x))"]; 

1948
78e5bfcbc1e9
Added miniscoping to the simplifier: quantifiers are now pushed in
paulson
parents:
1922
diff
changeset

138 

1722  139 

923  140 

2022  141 
(* elimination of existential quantifiers in assumptions *) 
923  142 

143 
val ex_all_equiv = 

144 
let val lemma1 = prove_goal HOL.thy 

145 
"(? x. P(x) ==> PROP Q) ==> (!!x. P(x) ==> PROP Q)" 

146 
(fn prems => [resolve_tac prems 1, etac exI 1]); 

147 
val lemma2 = prove_goalw HOL.thy [Ex_def] 

148 
"(!!x. P(x) ==> PROP Q) ==> (? x. P(x) ==> PROP Q)" 

149 
(fn prems => [REPEAT(resolve_tac prems 1)]) 

150 
in equal_intr lemma1 lemma2 end; 

151 

152 
end; 

153 

154 
fun prove nm thm = qed_goal nm HOL.thy thm (fn _ => [fast_tac HOL_cs 1]); 

155 

156 
prove "conj_commute" "(P&Q) = (Q&P)"; 

157 
prove "conj_left_commute" "(P&(Q&R)) = (Q&(P&R))"; 

158 
val conj_comms = [conj_commute, conj_left_commute]; 

2134  159 
prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))"; 
923  160 

1922  161 
prove "disj_commute" "(PQ) = (QP)"; 
162 
prove "disj_left_commute" "(P(QR)) = (Q(PR))"; 

163 
val disj_comms = [disj_commute, disj_left_commute]; 

2134  164 
prove "disj_assoc" "((PQ)R) = (P(QR))"; 
1922  165 

923  166 
prove "conj_disj_distribL" "(P&(QR)) = (P&Q  P&R)"; 
167 
prove "conj_disj_distribR" "((PQ)&R) = (P&R  Q&R)"; 

1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset

168 

1892  169 
prove "disj_conj_distribL" "(P(Q&R)) = ((PQ) & (PR))"; 
170 
prove "disj_conj_distribR" "((P&Q)R) = ((PR) & (QR))"; 

171 

2134  172 
prove "imp_conjR" "(P > (Q&R)) = ((P>Q) & (P>R))"; 
173 
prove "imp_conjL" "((P&Q) >R) = (P > (Q > R))"; 

174 
prove "imp_disjL" "((PQ) > R) = ((P>R)&(Q>R))"; 

1892  175 

1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset

176 
prove "de_Morgan_disj" "(~(P  Q)) = (~P & ~Q)"; 
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset

177 
prove "de_Morgan_conj" "(~(P & Q)) = (~P  ~Q)"; 
1922  178 
prove "not_iff" "(P~=Q) = (P = (~Q))"; 
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1465
diff
changeset

179 

2134  180 
(*Avoids duplication of subgoals after expand_if, when the true and false 
181 
cases boil down to the same thing.*) 

182 
prove "cases_simp" "((P > Q) & (~P > Q)) = Q"; 

183 

1660  184 
prove "not_all" "(~ (! x.P(x))) = (? x.~P(x))"; 
1922  185 
prove "imp_all" "((! x. P x) > Q) = (? x. P x > Q)"; 
1660  186 
prove "not_ex" "(~ (? x.P(x))) = (! x.~P(x))"; 
1922  187 
prove "imp_ex" "((? x. P x) > Q) = (! x. P x > Q)"; 
1660  188 

1655  189 
prove "ex_disj_distrib" "(? x. P(x)  Q(x)) = ((? x. P(x))  (? x. Q(x)))"; 
190 
prove "all_conj_distrib" "(!x. P(x) & Q(x)) = ((! x. P(x)) & (! x. Q(x)))"; 

191 

2134  192 
(* '&' congruence rule: not included by default! 
193 
May slow rewrite proofs down by as much as 50% *) 

194 

195 
let val th = prove_goal HOL.thy 

196 
"(P=P')> (P'> (Q=Q'))> ((P&Q) = (P'&Q'))" 

197 
(fn _=> [fast_tac HOL_cs 1]) 

198 
in bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp))) end; 

199 

200 
let val th = prove_goal HOL.thy 

201 
"(Q=Q')> (Q'> (P=P'))> ((P&Q) = (P'&Q'))" 

202 
(fn _=> [fast_tac HOL_cs 1]) 

203 
in bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp))) end; 

204 

205 
(* '' congruence rule: not included by default! *) 

206 

207 
let val th = prove_goal HOL.thy 

208 
"(P=P')> (~P'> (Q=Q'))> ((PQ) = (P'Q'))" 

209 
(fn _=> [fast_tac HOL_cs 1]) 

210 
in bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp))) end; 

211 

212 
prove "eq_sym_conv" "(x=y) = (y=x)"; 

213 

214 
qed_goalw "o_apply" HOL.thy [o_def] "(f o g) x = f (g x)" 

215 
(fn _ => [rtac refl 1]); 

216 

217 
qed_goal "meta_eq_to_obj_eq" HOL.thy "x==y ==> x=y" 

218 
(fn [prem] => [rewtac prem, rtac refl 1]); 

219 

220 
qed_goalw "if_True" HOL.thy [if_def] "(if True then x else y) = x" 

221 
(fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]); 

222 

223 
qed_goalw "if_False" HOL.thy [if_def] "(if False then x else y) = y" 

224 
(fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]); 

225 

226 
qed_goal "if_P" HOL.thy "P ==> (if P then x else y) = x" 

227 
(fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]); 

228 
(* 

229 
qed_goal "if_not_P" HOL.thy "~P ==> (if P then x else y) = y" 

230 
(fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]); 

231 
*) 

232 
qed_goalw "if_not_P" HOL.thy [if_def] "!!P. ~P ==> (if P then x else y) = y" 

233 
(fn _ => [fast_tac (HOL_cs addIs [select_equality]) 1]); 

234 

235 
qed_goal "expand_if" HOL.thy 

236 
"P(if Q then x else y) = ((Q > P(x)) & (~Q > P(y)))" 

237 
(fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1), 

238 
stac if_P 2, 

239 
stac if_not_P 1, 

240 
REPEAT(fast_tac HOL_cs 1) ]); 

241 

242 
qed_goal "if_bool_eq" HOL.thy 

243 
"(if P then Q else R) = ((P>Q) & (~P>R))" 

244 
(fn _ => [rtac expand_if 1]); 

245 

2263  246 
local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2) 
247 
in 

248 
fun split_tac splits = mktac (map mk_meta_eq splits) 

249 
end; 

250 

251 
local val mktac = mk_case_split_inside_tac (meta_eq_to_obj_eq RS iffD2) 

252 
in 

253 
fun split_inside_tac splits = mktac (map mk_meta_eq splits) 

254 
end; 

255 

256 

2251  257 
qed_goal "if_cancel" HOL.thy "(if c then x else x) = x" 
258 
(fn _ => [split_tac [expand_if] 1, fast_tac HOL_cs 1]); 

259 

2134  260 
(** 'if' congruence rules: neither included by default! *) 
261 

262 
(*Simplifies x assuming c and y assuming ~c*) 

263 
qed_goal "if_cong" HOL.thy 

264 
"[ b=c; c ==> x=u; ~c ==> y=v ] ==>\ 

265 
\ (if b then x else y) = (if c then u else v)" 

266 
(fn rew::prems => 

267 
[stac rew 1, stac expand_if 1, stac expand_if 1, 

268 
fast_tac (HOL_cs addDs prems) 1]); 

269 

270 
(*Prevents simplification of x and y: much faster*) 

271 
qed_goal "if_weak_cong" HOL.thy 

272 
"b=c ==> (if b then x else y) = (if c then x else y)" 

273 
(fn [prem] => [rtac (prem RS arg_cong) 1]); 

274 

275 
(*Prevents simplification of t: much faster*) 

276 
qed_goal "let_weak_cong" HOL.thy 

277 
"a = b ==> (let x=a in t(x)) = (let x=b in t(x))" 

278 
(fn [prem] => [rtac (prem RS arg_cong) 1]); 

279 

280 
(*In general it seems wrong to add distributive laws by default: they 

281 
might cause exponential blowup. But imp_disjL has been in for a while 

282 
and cannot be removed without affecting existing proofs. Moreover, 

283 
rewriting by "(PQ > R) = ((P>R)&(Q>R))" might be justified on the 

284 
grounds that it allows simplification of R in the two cases.*) 

285 

286 
val mksimps_pairs = 

287 
[("op >", [mp]), ("op &", [conjunct1,conjunct2]), 

288 
("All", [spec]), ("True", []), ("False", []), 

289 
("If", [if_bool_eq RS iffD1])]; 

1758  290 

2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

291 
fun unsafe_solver prems = FIRST'[resolve_tac (TrueI::refl::prems), 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

292 
atac, etac FalseE]; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

293 
(*No premature instantiation of variables during simplification*) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

294 
fun safe_solver prems = FIRST'[match_tac (TrueI::refl::prems), 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

295 
eq_assume_tac, ematch_tac [FalseE]]; 
2443
a81d4c219c3c
factored out HOL_base_ss and val HOL_min_ss, added HOL_safe_min_ss
oheimb
parents:
2263
diff
changeset

296 

2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

297 
val HOL_basic_ss = empty_ss setsubgoaler asm_simp_tac 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

298 
setSSolver safe_solver 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

299 
setSolver unsafe_solver 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

300 
setmksimps (mksimps mksimps_pairs); 
2443
a81d4c219c3c
factored out HOL_base_ss and val HOL_min_ss, added HOL_safe_min_ss
oheimb
parents:
2263
diff
changeset

301 

2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

302 
val HOL_ss = HOL_basic_ss addsimps ([triv_forall_equality, (* prunes params *) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

303 
if_True, if_False, if_cancel, 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

304 
o_apply, imp_disjL, conj_assoc, disj_assoc, 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

305 
de_Morgan_conj, de_Morgan_disj, 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

306 
not_all, not_ex, cases_simp] 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

307 
@ ex_simps @ all_simps @ simp_thms) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

308 
addcongs [imp_cong]; 
2082  309 

1655  310 
qed_goal "if_distrib" HOL.thy 
311 
"f(if c then x else y) = (if c then f x else f y)" 

312 
(fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]); 

313 

2097  314 
qed_goalw "o_assoc" HOL.thy [o_def] "f o (g o h) = f o g o h" 
2098
2bfc0675c92f
corrected `correction` of o_assoc (of version 1.14),
oheimb
parents:
2097
diff
changeset

315 
(fn _ => [rtac ext 1, rtac refl 1]); 
1984  316 

317 

318 

319 

320 
(*** Install simpsets and datatypes in theory structure ***) 

321 

2251  322 
simpset := HOL_ss; 
1984  323 

324 
exception SS_DATA of simpset; 

325 

326 
let fun merge [] = SS_DATA empty_ss 

327 
 merge ss = let val ss = map (fn SS_DATA x => x) ss; 

328 
in SS_DATA (foldl merge_ss (hd ss, tl ss)) end; 

329 

330 
fun put (SS_DATA ss) = simpset := ss; 

331 

332 
fun get () = SS_DATA (!simpset); 

333 
in add_thydata "HOL" 

334 
("simpset", ThyMethods {merge = merge, put = put, get = get}) 

335 
end; 

336 

337 
type dtype_info = {case_const:term, case_rewrites:thm list, 

338 
constructors:term list, nchotomy:thm, case_cong:thm}; 

339 

340 
exception DT_DATA of (string * dtype_info) list; 

341 
val datatypes = ref [] : (string * dtype_info) list ref; 

342 

343 
let fun merge [] = DT_DATA [] 

344 
 merge ds = 

345 
let val ds = map (fn DT_DATA x => x) ds; 

346 
in DT_DATA (foldl (gen_union eq_fst) (hd ds, tl ds)) end; 

347 

348 
fun put (DT_DATA ds) = datatypes := ds; 

349 

350 
fun get () = DT_DATA (!datatypes); 

351 
in add_thydata "HOL" 

352 
("datatypes", ThyMethods {merge = merge, put = put, get = get}) 

353 
end; 

354 

355 

356 
add_thy_reader_file "thy_data.ML"; 

2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

357 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

358 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

359 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

360 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

361 
(*** Integration of simplifier with classical reasoner ***) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

362 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

363 
(* rot_eq_tac rotates the first equality premise of subgoal i to the front, 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

364 
fails if there is no equaliy or if an equality is already at the front *) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

365 
fun rot_eq_tac i = let 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

366 
fun is_eq (Const ("Trueprop", _) $ (Const("op =",_) $ _ $ _)) = true 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

367 
 is_eq _ = false; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

368 
fun find_eq n [] = None 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

369 
 find_eq n (t :: ts) = if (is_eq t) then Some n else find_eq (n + 1) ts; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

370 
fun rot_eq state = let val (_, _, Bi, _) = dest_state (state, i) in 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

371 
(case find_eq 0 (Logic.strip_assums_hyp Bi) of 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

372 
None => no_tac 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

373 
 Some 0 => no_tac 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

374 
 Some n => rotate_tac n i) end; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

375 
in STATE rot_eq end; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

376 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

377 
(*an unsatisfactory fix for the incomplete asm_full_simp_tac! 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

378 
better: asm_really_full_simp_tac, a yet to be implemented version of 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

379 
asm_full_simp_tac that applies all equalities in the 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

380 
premises to all the premises *) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

381 
fun safe_asm_more_full_simp_tac ss = TRY o rot_eq_tac THEN' 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

382 
safe_asm_full_simp_tac ss; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

383 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

384 
(*Add a simpset to a classical set!*) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

385 
infix 4 addss; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

386 
fun cs addss ss = cs addSaltern (CHANGED o (safe_asm_more_full_simp_tac ss)); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

387 
(*old version, for compatibility with unstable old proofs*) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

388 
infix 4 unsafe_addss; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

389 
fun cs unsafe_addss ss = cs addbefore asm_full_simp_tac ss; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

390 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

391 
fun Addss ss = (claset := !claset addss ss); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

392 
(*old version, for compatibility with unstable old proofs*) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

393 
fun Unsafe_Addss ss = (claset := !claset unsafe_addss ss); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

394 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

395 
(*Designed to be idempotent, except if best_tac instantiates variables 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

396 
in some of the subgoals*) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

397 
(*old version, for compatibility with unstable old proofs*) 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

398 
fun unsafe_auto_tac (cs,ss) = 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

399 
ALLGOALS (asm_full_simp_tac ss) THEN 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

400 
REPEAT (safe_tac cs THEN ALLGOALS (asm_full_simp_tac ss)) THEN 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

401 
REPEAT (FIRSTGOAL (best_tac (cs addss ss))) THEN 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

402 
prune_params_tac; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

403 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

404 
type clasimpset = (claset * simpset); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

405 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

406 
val HOL_css = (HOL_cs, HOL_ss); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

407 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

408 
fun pair_upd1 f ((a,b),x) = (f(a,x), b); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

409 
fun pair_upd2 f ((a,b),x) = (a, f(b,x)); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

410 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

411 
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

412 
addsimps2 delsimps2 addcongs2 delcongs2; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

413 
val op addSIs2 = pair_upd1 (op addSIs); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

414 
val op addSEs2 = pair_upd1 (op addSEs); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

415 
val op addSDs2 = pair_upd1 (op addSDs); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

416 
val op addIs2 = pair_upd1 (op addIs ); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

417 
val op addEs2 = pair_upd1 (op addEs ); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

418 
val op addDs2 = pair_upd1 (op addDs ); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

419 
val op addsimps2 = pair_upd2 (op addsimps); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

420 
val op delsimps2 = pair_upd2 (op delsimps); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

421 
val op addcongs2 = pair_upd2 (op addcongs); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

422 
val op delcongs2 = pair_upd2 (op delcongs); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

423 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

424 
fun auto_tac (cs,ss) = let val cs' = cs addss ss in 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

425 
EVERY [ TRY (safe_tac cs'), 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

426 
REPEAT (FIRSTGOAL (fast_tac cs')), 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

427 
prune_params_tac] end; 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

428 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

429 
fun Auto_tac () = auto_tac (!claset, !simpset); 
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

430 

4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

431 
fun auto () = by (Auto_tac ()); 