author  paulson 
Wed, 03 Dec 1997 10:50:02 +0100  
changeset 4351  36b28f78ed1b 
parent 4327  2335f6584a1b 
child 4477  b3e5857d8d99 
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 

2718  25 
(Const("Not",_) $ A) => 
2031  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 

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

42 
if con=iff_const 

43 
then Delrules [zero_var_indexes (th RS iffD2), 

3518  44 
make_elim (zero_var_indexes (th RS iffD1))] 
2031  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 

923  55 
local 
56 

2935  57 
fun prover s = prove_goal HOL.thy s (fn _ => [blast_tac HOL_cs 1]); 
923  58 

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

923  61 

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

923  64 

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

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

69 
(case head_of p of 

70 
Const(a,_) => 

71 
(case assoc(pairs,a) of 

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

73 
 None => [th]) 

74 
 _ => [th]) 

75 
 _ => [th]) 

1922  76 
in atoms end; 
923  77 

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

80 
in 

81 

3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

82 
fun mk_meta_eq r = r RS eq_reflection; 
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

83 

ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

84 
fun mk_meta_eq_simp r = case concl_of r of 
2031  85 
Const("==",_)$_$_ => r 
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

86 
 _$(Const("op =",_)$lhs$rhs) => 
4117  87 
(case fst(Logic.rewrite_rule_ok (#sign(rep_thm r)) (prems_of r) lhs rhs) of 
3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

88 
None => mk_meta_eq r 
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

89 
 Some _ => r RS P_imp_P_eq_True) 
2718  90 
 _$(Const("Not",_)$_) => r RS not_P_imp_P_eq_False 
1922  91 
 _ => r RS P_imp_P_eq_True; 
92 
(* last 2 lines requires all formulae to be of the from Trueprop(.) *) 

923  93 

2082  94 
val simp_thms = map prover 
95 
[ "(x=x) = True", 

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

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

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

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

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

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

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

2800  103 
"(P & False) = False", "(False & P) = False", 
104 
"(P & P) = P", "(P & (P & Q)) = (P & Q)", 

3913  105 
"(P & ~P) = False", "(~P & P) = False", 
2082  106 
"(P  True) = True", "(True  P) = True", 
2800  107 
"(P  False) = P", "(False  P) = P", 
108 
"(P  P) = P", "(P  (P  Q)) = (P  Q)", 

3913  109 
"(P  ~P) = True", "(~P  P) = True", 
2082  110 
"((~P) = (~Q)) = (P=Q)", 
3842  111 
"(!x. P) = P", "(? x. P) = P", "? x. x=t", "? x. t=x", 
4351  112 
(*two needed for the onepointrule quantifier simplification procs*) 
113 
"(? x. x=t & P(x)) = P(t)", (*essential for termination!!*) 

114 
"(! x. t=x > P(x)) = P(t)" ]; (*covers a stray case*) 

923  115 

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

117 
infix 4 addcongs delcongs; 
4351  118 
fun ss addcongs congs = ss addeqcongs 
119 
(map standard (congs RL [eq_reflection])); 

120 

121 
fun ss delcongs congs = ss deleqcongs 

122 
(map standard (congs RL [eq_reflection])); 

923  123 

4086  124 
fun Addcongs congs = (simpset_ref() := simpset() addcongs congs); 
125 
fun Delcongs congs = (simpset_ref() := simpset() delcongs congs); 

1264  126 

3896
ee8ebb74ec00
Various new lemmas. Improved conversion of equations to rewrite rules:
nipkow
parents:
3842
diff
changeset

127 
fun mksimps pairs = map mk_meta_eq_simp o atomize pairs o gen_all; 
923  128 

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

2935  131 
(fn _=> [blast_tac HOL_cs 1]) RS mp RS mp); 
1922  132 

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

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

134 
val ex_simps = map prover 
3842  135 
["(EX x. P x & Q) = ((EX x. P x) & Q)", 
136 
"(EX x. P & Q x) = (P & (EX x. Q x))", 

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

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

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

140 
"(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

141 

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

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

143 
val all_simps = map prover 
3842  144 
["(ALL x. P x & Q) = ((ALL x. P x) & Q)", 
145 
"(ALL x. P & Q x) = (P & (ALL x. Q x))", 

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

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

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

149 
"(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

150 

923  151 

2022  152 
(* elimination of existential quantifiers in assumptions *) 
923  153 

154 
val ex_all_equiv = 

155 
let val lemma1 = prove_goal HOL.thy 

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

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

158 
val lemma2 = prove_goalw HOL.thy [Ex_def] 

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

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

161 
in equal_intr lemma1 lemma2 end; 

162 

163 
end; 

164 

3654  165 
(* Elimination of True from asumptions: *) 
166 

167 
val True_implies_equals = prove_goal HOL.thy 

168 
"(True ==> PROP P) == PROP P" 

169 
(fn _ => [rtac equal_intr_rule 1, atac 2, 

170 
METAHYPS (fn prems => resolve_tac prems 1) 1, 

171 
rtac TrueI 1]); 

172 

2935  173 
fun prove nm thm = qed_goal nm HOL.thy thm (fn _ => [blast_tac HOL_cs 1]); 
923  174 

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

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

177 
val conj_comms = [conj_commute, conj_left_commute]; 

2134  178 
prove "conj_assoc" "((P&Q)&R) = (P&(Q&R))"; 
923  179 

1922  180 
prove "disj_commute" "(PQ) = (QP)"; 
181 
prove "disj_left_commute" "(P(QR)) = (Q(PR))"; 

182 
val disj_comms = [disj_commute, disj_left_commute]; 

2134  183 
prove "disj_assoc" "((PQ)R) = (P(QR))"; 
1922  184 

923  185 
prove "conj_disj_distribL" "(P&(QR)) = (P&Q  P&R)"; 
186 
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

187 

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

190 

2134  191 
prove "imp_conjR" "(P > (Q&R)) = ((P>Q) & (P>R))"; 
192 
prove "imp_conjL" "((P&Q) >R) = (P > (Q > R))"; 

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

1892  194 

3448  195 
(*These two are specialized, but imp_disj_not1 is useful in Auth/Yahalom.ML*) 
196 
prove "imp_disj_not1" "((P > Q  R)) = (~Q > P > R)"; 

197 
prove "imp_disj_not2" "((P > Q  R)) = (~R > P > Q)"; 

198 

3904  199 
prove "imp_disj1" "((P>Q)R) = (P> QR)"; 
200 
prove "imp_disj2" "(Q(P>R)) = (P> QR)"; 

201 

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

202 
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

203 
prove "de_Morgan_conj" "(~(P & Q)) = (~P  ~Q)"; 
3446
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

204 
prove "not_imp" "(~(P > Q)) = (P & ~Q)"; 
1922  205 
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

206 

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

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

210 

3842  211 
prove "not_all" "(~ (! x. P(x))) = (? x.~P(x))"; 
1922  212 
prove "imp_all" "((! x. P x) > Q) = (? x. P x > Q)"; 
3842  213 
prove "not_ex" "(~ (? x. P(x))) = (! x.~P(x))"; 
1922  214 
prove "imp_ex" "((? x. P x) > Q) = (! x. P x > Q)"; 
1660  215 

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

218 

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

221 

222 
let val th = prove_goal HOL.thy 

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

2935  224 
(fn _=> [blast_tac HOL_cs 1]) 
2134  225 
in bind_thm("conj_cong",standard (impI RSN (2, th RS mp RS mp))) end; 
226 

227 
let val th = prove_goal HOL.thy 

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

2935  229 
(fn _=> [blast_tac HOL_cs 1]) 
2134  230 
in bind_thm("rev_conj_cong",standard (impI RSN (2, th RS mp RS mp))) end; 
231 

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

233 

234 
let val th = prove_goal HOL.thy 

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

2935  236 
(fn _=> [blast_tac HOL_cs 1]) 
2134  237 
in bind_thm("disj_cong",standard (impI RSN (2, th RS mp RS mp))) end; 
238 

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

240 

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

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

243 

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

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

246 

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

2935  248 
(fn _=>[blast_tac (HOL_cs addIs [select_equality]) 1]); 
2134  249 

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

2935  251 
(fn _=>[blast_tac (HOL_cs addIs [select_equality]) 1]); 
2134  252 

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

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

255 
(* 

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

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

258 
*) 

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

2935  260 
(fn _ => [blast_tac (HOL_cs addIs [select_equality]) 1]); 
2134  261 

262 
qed_goal "expand_if" HOL.thy 

4205
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

263 
"P(if Q then x else y) = ((Q > P(x)) & (~Q > P(y)))" (K [ 
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

264 
res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1, 
2134  265 
stac if_P 2, 
266 
stac if_not_P 1, 

4205
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

267 
ALLGOALS (blast_tac HOL_cs)]); 
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

268 

96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

269 
qed_goal "split_if_asm" HOL.thy 
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

270 
"P(if Q then x else y) = (~((Q & ~P x)  (~Q & ~P y)))" (K [ 
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

271 
stac expand_if 1, 
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

272 
blast_tac HOL_cs 1]); 
2134  273 

274 
qed_goal "if_bool_eq" HOL.thy 

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

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

277 

4351  278 

279 
(*** make simplification procedures for quantifier elimination ***) 

280 

281 
structure Quantifier1 = Quantifier1Fun( 

282 
struct 

283 
(*abstract syntax*) 

284 
fun dest_eq((c as Const("op =",_)) $ s $ t) = Some(c,s,t) 

285 
 dest_eq _ = None; 

286 
fun dest_conj((c as Const("op &",_)) $ s $ t) = Some(c,s,t) 

287 
 dest_conj _ = None; 

288 
val conj = HOLogic.conj 

289 
val imp = HOLogic.imp 

290 
(*rules*) 

291 
val iff_reflection = eq_reflection 

292 
val iffI = iffI 

293 
val sym = sym 

294 
val conjI= conjI 

295 
val conjE= conjE 

296 
val impI = impI 

297 
val impE = impE 

298 
val mp = mp 

299 
val exI = exI 

300 
val exE = exE 

301 
val allI = allI 

302 
val allE = allE 

303 
end); 

304 

4320
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

305 
local 
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

306 
val ex_pattern = 
4351  307 
read_cterm (sign_of HOL.thy) ("EX x. P(x) & Q(x)",HOLogic.boolT) 
3913  308 

4320
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

309 
val all_pattern = 
4351  310 
read_cterm (sign_of HOL.thy) ("ALL x. P(x) & P'(x) > Q(x)",HOLogic.boolT) 
4320
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

311 

24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

312 
in 
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

313 
val defEX_regroup = 
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

314 
mk_simproc "defined EX" [ex_pattern] Quantifier1.rearrange_ex; 
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

315 
val defALL_regroup = 
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

316 
mk_simproc "defined ALL" [all_pattern] Quantifier1.rearrange_all; 
24d9e6639cd4
Moved the quantifier elimination simp procs into Provers.
nipkow
parents:
4205
diff
changeset

317 
end; 
3913  318 

4351  319 

320 
(*** Case splitting ***) 

3913  321 

2263  322 
local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2) 
323 
in 

324 
fun split_tac splits = mktac (map mk_meta_eq splits) 

325 
end; 

326 

327 
local val mktac = mk_case_split_inside_tac (meta_eq_to_obj_eq RS iffD2) 

328 
in 

329 
fun split_inside_tac splits = mktac (map mk_meta_eq splits) 

330 
end; 

331 

4205
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

332 
val split_asm_tac = mk_case_split_asm_tac split_tac 
96632970d203
simpdata.ML: renamed split_prem_tac to split_asm_tac, added split_if_asm
oheimb
parents:
4189
diff
changeset

333 
(disjE,conjE,exE,contrapos,contrapos2,notnotD); 
4189  334 

3919  335 
infix 4 addsplits; 
336 
fun ss addsplits splits = ss addloop (split_tac splits); 

337 

2263  338 

2251  339 
qed_goal "if_cancel" HOL.thy "(if c then x else x) = x" 
2935  340 
(fn _ => [split_tac [expand_if] 1, blast_tac HOL_cs 1]); 
2251  341 

2134  342 
(** 'if' congruence rules: neither included by default! *) 
343 

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

345 
qed_goal "if_cong" HOL.thy 

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

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

348 
(fn rew::prems => 

349 
[stac rew 1, stac expand_if 1, stac expand_if 1, 

2935  350 
blast_tac (HOL_cs addDs prems) 1]); 
2134  351 

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

353 
qed_goal "if_weak_cong" HOL.thy 

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

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

356 

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

358 
qed_goal "let_weak_cong" HOL.thy 

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

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

361 

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

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

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

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

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

367 

368 
val mksimps_pairs = 

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

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

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

1758  372 

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

373 
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

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

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

376 
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

377 
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

378 

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

379 
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

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

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

382 
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

383 

3446
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

384 
val HOL_ss = 
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

385 
HOL_basic_ss addsimps 
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

386 
([triv_forall_equality, (* prunes params *) 
3654  387 
True_implies_equals, (* prune asms `True' *) 
3446
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

388 
if_True, if_False, if_cancel, 
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

389 
o_apply, imp_disjL, conj_assoc, disj_assoc, 
3904  390 
de_Morgan_conj, de_Morgan_disj, imp_disj1, imp_disj2, not_imp, 
3446
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

391 
not_all, not_ex, cases_simp] 
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

392 
@ ex_simps @ all_simps @ simp_thms) 
4032
4b1c69d8b767
For each datatype `t' there is now a theorem `split_t_case' of the form
nipkow
parents:
3919
diff
changeset

393 
addsimprocs [defALL_regroup,defEX_regroup] 
3446
a14e5451f613
Addition of not_imp (which pushes negation into implication) as a default
paulson
parents:
3282
diff
changeset

394 
addcongs [imp_cong]; 
2082  395 

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

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

399 

2097  400 
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

401 
(fn _ => [rtac ext 1, rtac refl 1]); 
1984  402 

403 

4327  404 
(*For expand_case_tac*) 
2948
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

405 
val prems = goal HOL.thy "[ P ==> Q(True); ~P ==> Q(False) ] ==> Q(P)"; 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

406 
by (case_tac "P" 1); 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

407 
by (ALLGOALS (asm_simp_tac (HOL_ss addsimps prems))); 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

408 
val expand_case = result(); 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

409 

4327  410 
(*Used in Auth proofs. Typically P contains Vars that become instantiated 
411 
during unification.*) 

2948
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

412 
fun expand_case_tac P i = 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

413 
res_inst_tac [("P",P)] expand_case i THEN 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

414 
Simp_tac (i+1) THEN 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

415 
Simp_tac i; 
f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

416 

f18035b1d531
Moved expand_case_tac from Auth/Message.ML to simpdata.ML
paulson
parents:
2935
diff
changeset

417 

4119  418 
(* install implicit simpset *) 
1984  419 

4086  420 
simpset_ref() := HOL_ss; 
1984  421 

3615
e5322197cfea
Moved some functions which used to be part of thy_data.ML
berghofe
parents:
3577
diff
changeset

422 

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

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

424 

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

425 
(* 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

426 
fails if there is no equaliy or if an equality is already at the front *) 
3538  427 
local 
428 
fun is_eq (Const ("Trueprop", _) $ (Const("op =" ,_) $ _ $ _)) = true 

429 
 is_eq _ = false; 

4188
1025a27b08f9
changed libraray function find to find_index_eq, currying it
oheimb
parents:
4119
diff
changeset

430 
val find_eq = find_index is_eq; 
3538  431 
in 
432 
val rot_eq_tac = 

4188
1025a27b08f9
changed libraray function find to find_index_eq, currying it
oheimb
parents:
4119
diff
changeset

433 
SUBGOAL (fn (Bi,i) => let val n = find_eq (Logic.strip_assums_hyp Bi) in 
1025a27b08f9
changed libraray function find to find_index_eq, currying it
oheimb
parents:
4119
diff
changeset

434 
if n>0 then rotate_tac n i else no_tac end) 
3538  435 
end; 
2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

436 

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

437 
(*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

438 
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

439 
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

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

441 
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

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

443 

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

444 
(*Add a simpset to a classical set!*) 
3206
a3de7f32728c
renamed addss to addSss, unsafe_addss to addss, extended auto_tac
oheimb
parents:
3040
diff
changeset

445 
infix 4 addSss addss; 
a3de7f32728c
renamed addss to addSss, unsafe_addss to addss, extended auto_tac
oheimb
parents:
3040
diff
changeset

446 
fun cs addSss ss = cs addSaltern (CHANGED o (safe_asm_more_full_simp_tac ss)); 
a3de7f32728c
renamed addss to addSss, unsafe_addss to addss, extended auto_tac
oheimb
parents:
3040
diff
changeset

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

448 

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

450 

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

451 
(*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

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

453 

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

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

455 

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

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

457 

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

458 
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

459 
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

460 

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

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

462 
addsimps2 delsimps2 addcongs2 delcongs2; 
2748
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

463 
fun op addSIs2 arg = pair_upd1 (op addSIs) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

464 
fun op addSEs2 arg = pair_upd1 (op addSEs) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

465 
fun op addSDs2 arg = pair_upd1 (op addSDs) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

466 
fun op addIs2 arg = pair_upd1 (op addIs ) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

467 
fun op addEs2 arg = pair_upd1 (op addEs ) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

468 
fun op addDs2 arg = pair_upd1 (op addDs ) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

469 
fun op addsimps2 arg = pair_upd2 (op addsimps) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

470 
fun op delsimps2 arg = pair_upd2 (op delsimps) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

471 
fun op addcongs2 arg = pair_upd2 (op addcongs) arg; 
3ae9ccdd701e
Etaexpanded some declarations for compatibility with value polymorphism
paulson
parents:
2718
diff
changeset

472 
fun op delcongs2 arg = pair_upd2 (op delcongs) arg; 
2636
4b30dbe4a020
added delcongs, Delcongs, unsafe_solver, safe_solver, HOL_basic_ss,
oheimb
parents:
2595
diff
changeset

473 

2805  474 
fun auto_tac (cs,ss) = 
475 
let val cs' = cs addss ss 

476 
in EVERY [TRY (safe_tac cs'), 

477 
REPEAT (FIRSTGOAL (fast_tac cs')), 

3206
a3de7f32728c
renamed addss to addSss, unsafe_addss to addss, extended auto_tac
oheimb
parents:
3040
diff
changeset

478 
TRY (safe_tac (cs addSss ss)), 
2805  479 
prune_params_tac] 
480 
end; 

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

481 

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

483 

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

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