author  berghofe 
Fri, 21 Jun 1996 13:34:55 +0200  
changeset 1821  bc506bcb9fe4 
parent 1758  60613b065e9b 
child 1874  35f22792aade 
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 

9 
open Simplifier; 

10 

11 
local 

12 

13 
fun prover s = prove_goal HOL.thy s (fn _ => [fast_tac HOL_cs 1]); 

14 

15 
val P_imp_P_iff_True = prover "P > (P = True)" RS mp; 

16 
val P_imp_P_eq_True = P_imp_P_iff_True RS eq_reflection; 

17 

18 
val not_P_imp_P_iff_F = prover "~P > (P = False)" RS mp; 

19 
val not_P_imp_P_eq_False = not_P_imp_P_iff_F RS eq_reflection; 

20 

21 
fun atomize pairs = 

22 
let fun atoms th = 

23 
(case concl_of th of 

24 
Const("Trueprop",_) $ p => 

25 
(case head_of p of 

26 
Const(a,_) => 

27 
(case assoc(pairs,a) of 

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

29 
 None => [th]) 

30 
 _ => [th]) 

31 
 _ => [th]) 

32 
in atoms end; 

33 

34 
fun mk_meta_eq r = case concl_of r of 

1465  35 
Const("==",_)$_$_ => r 
36 
 _$(Const("op =",_)$_$_) => r RS eq_reflection 

37 
 _$(Const("not",_)$_) => r RS not_P_imp_P_eq_False 

923  38 
 _ => r RS P_imp_P_eq_True; 
39 
(* last 2 lines requires all formulae to be of the from Trueprop(.) *) 

40 

41 
fun gen_all th = forall_elim_vars (#maxidx(rep_thm th)+1) th; 

42 

43 
val imp_cong = impI RSN 

44 
(2, prove_goal HOL.thy "(P=P')> (P'> (Q=Q'))> ((P>Q) = (P'>Q'))" 

1465  45 
(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp); 
923  46 

47 
val o_apply = prove_goalw HOL.thy [o_def] "(f o g)(x) = f(g(x))" 

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

49 

50 
val simp_thms = map prover 

51 
[ "(x=x) = True", 

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

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

54 
"(True=P) = P", "(P=True) = P", 

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

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

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

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

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

60 
"(P  True) = True", "(True  P) = True", 

61 
"(P  False) = P", "(False  P) = P", "(P  P) = P", 

62 
"(!x.P) = P", "(? x.P) = P", "? x. x=t", "(? x. x=t & P(x)) = P(t)", 

63 
"(PQ > R) = ((P>R)&(Q>R))" ]; 

64 

65 
in 

66 

67 
val meta_eq_to_obj_eq = prove_goal HOL.thy "x==y ==> x=y" 

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

69 

70 
val eq_sym_conv = prover "(x=y) = (y=x)"; 

71 

72 
val conj_assoc = prover "((P&Q)&R) = (P&(Q&R))"; 

73 

965  74 
val if_True = prove_goalw HOL.thy [if_def] "(if True then x else y) = x" 
923  75 
(fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]); 
76 

965  77 
val if_False = prove_goalw HOL.thy [if_def] "(if False then x else y) = y" 
923  78 
(fn _=>[fast_tac (HOL_cs addIs [select_equality]) 1]); 
79 

965  80 
val if_P = prove_goal HOL.thy "P ==> (if P then x else y) = x" 
923  81 
(fn [prem] => [ stac (prem RS eqTrueI) 1, rtac if_True 1 ]); 
82 

965  83 
val if_not_P = prove_goal HOL.thy "~P ==> (if P then x else y) = y" 
923  84 
(fn [prem] => [ stac (prem RS not_P_imp_P_iff_F) 1, rtac if_False 1 ]); 
85 

86 
val expand_if = prove_goal HOL.thy 

965  87 
"P(if Q then x else y) = ((Q > P(x)) & (~Q > P(y)))" 
923  88 
(fn _=> [ (res_inst_tac [("Q","Q")] (excluded_middle RS disjE) 1), 
1465  89 
rtac (if_P RS ssubst) 2, 
90 
rtac (if_not_P RS ssubst) 1, 

91 
REPEAT(fast_tac HOL_cs 1) ]); 

923  92 

965  93 
val if_bool_eq = prove_goal HOL.thy 
94 
"(if P then Q else R) = ((P>Q) & (~P>R))" 

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

923  96 

988  97 
(*Add congruence rules for = (instead of ==) *) 
98 
infix 4 addcongs; 

923  99 
fun ss addcongs congs = ss addeqcongs (congs RL [eq_reflection]); 
100 

1264  101 
fun Addcongs congs = (simpset := !simpset addcongs congs); 
102 

988  103 
(*Add a simpset to a classical set!*) 
104 
infix 4 addss; 

105 
fun cs addss ss = cs addbefore asm_full_simp_tac ss 1; 

106 

1821  107 
fun Addss ss = (claset := !claset addbefore asm_full_simp_tac ss 1); 
108 

923  109 
val mksimps_pairs = 
110 
[("op >", [mp]), ("op &", [conjunct1,conjunct2]), 

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

965  112 
("If", [if_bool_eq RS iffD1])]; 
923  113 

114 
fun mksimps pairs = map mk_meta_eq o atomize pairs o gen_all; 

115 

116 
val HOL_ss = empty_ss 

117 
setmksimps (mksimps mksimps_pairs) 

118 
setsolver (fn prems => resolve_tac (TrueI::refl::prems) ORELSE' atac 

119 
ORELSE' etac FalseE) 

120 
setsubgoaler asm_simp_tac 

121 
addsimps ([if_True, if_False, o_apply, conj_assoc] @ simp_thms) 

122 
addcongs [imp_cong]; 

123 

941  124 
local val mktac = mk_case_split_tac (meta_eq_to_obj_eq RS iffD2) 
125 
in 

126 
fun split_tac splits = mktac (map mk_meta_eq splits) 

127 
end; 

128 

1722  129 
local val mktac = mk_case_split_inside_tac (meta_eq_to_obj_eq RS iffD2) 
130 
in 

131 
fun split_inside_tac splits = mktac (map mk_meta_eq splits) 

132 
end; 

133 

923  134 

135 
(* eliminiation of existential quantifiers in assumptions *) 

136 

137 
val ex_all_equiv = 

138 
let val lemma1 = prove_goal HOL.thy 

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

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

141 
val lemma2 = prove_goalw HOL.thy [Ex_def] 

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

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

144 
in equal_intr lemma1 lemma2 end; 

145 

146 
(* '&' congruence rule: not included by default! 

147 
May slow rewrite proofs down by as much as 50% *) 

148 

149 
val conj_cong = impI RSN 

150 
(2, prove_goal HOL.thy "(P=P')> (P'> (Q=Q'))> ((P&Q) = (P'&Q'))" 

1465  151 
(fn _=> [fast_tac HOL_cs 1]) RS mp RS mp); 
923  152 

1548  153 
val rev_conj_cong = impI RSN 
154 
(2, prove_goal HOL.thy "(Q=Q')> (Q'> (P=P'))> ((P&Q) = (P'&Q'))" 

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

156 

923  157 
(** 'if' congruence rules: neither included by default! *) 
158 

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

160 
val if_cong = prove_goal HOL.thy 

965  161 
"[ b=c; c ==> x=u; ~c ==> y=v ] ==>\ 
162 
\ (if b then x else y) = (if c then u else v)" 

923  163 
(fn rew::prems => 
164 
[stac rew 1, stac expand_if 1, stac expand_if 1, 

165 
fast_tac (HOL_cs addDs prems) 1]); 

166 

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

168 
val if_weak_cong = prove_goal HOL.thy 

965  169 
"b=c ==> (if b then x else y) = (if c then x else y)" 
923  170 
(fn [prem] => [rtac (prem RS arg_cong) 1]); 
171 

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

173 
val let_weak_cong = prove_goal HOL.thy 

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

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

176 

177 
end; 

178 

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

180 

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

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

183 
val conj_comms = [conj_commute, conj_left_commute]; 

184 

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 

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

188 
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

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

190 

1660  191 
prove "not_all" "(~ (! x.P(x))) = (? x.~P(x))"; 
192 
prove "not_ex" "(~ (? x.P(x))) = (! x.~P(x))"; 

193 

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

196 

1758  197 
prove "ex_imp" "((? x. P x) > Q) = (!x. P x > Q)"; 
198 

1655  199 
qed_goal "if_cancel" HOL.thy "(if c then x else x) = x" 
200 
(fn _ => [simp_tac (HOL_ss setloop (split_tac [expand_if])) 1]); 

201 

202 
qed_goal "if_distrib" HOL.thy 

203 
"f(if c then x else y) = (if c then f x else f y)" 

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

205 

206 
qed_goalw "o_assoc" HOL.thy [o_def] "(f o g) o h = (f o g o h)" 

207 
(fn _=>[rtac ext 1, rtac refl 1]); 