author  wenzelm 
Sat, 20 Jan 2007 14:09:27 +0100  
changeset 22139  539a63b98f76 
parent 21539  c5cf9243ad62 
child 23154  5126551e378b 
permissions  rwrr 
9487  1 
(* Title: FOL/FOL.thy 
2 
ID: $Id$ 

3 
Author: Lawrence C Paulson and Markus Wenzel 

11678  4 
*) 
9487  5 

11678  6 
header {* Classical firstorder logic *} 
4093  7 

18456  8 
theory FOL 
15481  9 
imports IFOL 
21539  10 
uses ("cladata.ML") ("blastdata.ML") ("simpdata.ML") 
18456  11 
begin 
9487  12 

13 

14 
subsection {* The classical axiom *} 

4093  15 

7355
4c43090659ca
proper bootstrap of IFOL/FOL theories and packages;
wenzelm
parents:
5887
diff
changeset

16 
axioms 
4c43090659ca
proper bootstrap of IFOL/FOL theories and packages;
wenzelm
parents:
5887
diff
changeset

17 
classical: "(~P ==> P) ==> P" 
4093  18 

9487  19 

11678  20 
subsection {* Lemmas and proof tools *} 
9487  21 

21539  22 
lemma ccontr: "(\<not> P \<Longrightarrow> False) \<Longrightarrow> P" 
23 
by (erule FalseE [THEN classical]) 

24 

25 
(*** Classical introduction rules for  and EX ***) 

26 

27 
lemma disjCI: "(~Q ==> P) ==> PQ" 

28 
apply (rule classical) 

29 
apply (assumption  erule meta_mp  rule disjI1 notI)+ 

30 
apply (erule notE disjI2)+ 

31 
done 

32 

33 
(*introduction rule involving only EX*) 

34 
lemma ex_classical: 

35 
assumes r: "~(EX x. P(x)) ==> P(a)" 

36 
shows "EX x. P(x)" 

37 
apply (rule classical) 

38 
apply (rule exI, erule r) 

39 
done 

40 

41 
(*version of above, simplifying ~EX to ALL~ *) 

42 
lemma exCI: 

43 
assumes r: "ALL x. ~P(x) ==> P(a)" 

44 
shows "EX x. P(x)" 

45 
apply (rule ex_classical) 

46 
apply (rule notI [THEN allI, THEN r]) 

47 
apply (erule notE) 

48 
apply (erule exI) 

49 
done 

50 

51 
lemma excluded_middle: "~P  P" 

52 
apply (rule disjCI) 

53 
apply assumption 

54 
done 

55 

56 
(*For disjunctive case analysis*) 

57 
ML {* 

22139  58 
fun excluded_middle_tac sP = 
59 
res_inst_tac [("Q",sP)] (@{thm excluded_middle} RS @{thm disjE}) 

21539  60 
*} 
61 

62 
lemma case_split_thm: 

63 
assumes r1: "P ==> Q" 

64 
and r2: "~P ==> Q" 

65 
shows Q 

66 
apply (rule excluded_middle [THEN disjE]) 

67 
apply (erule r2) 

68 
apply (erule r1) 

69 
done 

70 

71 
lemmas case_split = case_split_thm [case_names True False, cases type: o] 

72 

73 
(*HOL's more natural case analysis tactic*) 

74 
ML {* 

22139  75 
fun case_tac a = res_inst_tac [("P",a)] @{thm case_split_thm} 
21539  76 
*} 
77 

78 

79 
(*** Special elimination rules *) 

80 

81 

82 
(*Classical implies (>) elimination. *) 

83 
lemma impCE: 

84 
assumes major: "P>Q" 

85 
and r1: "~P ==> R" 

86 
and r2: "Q ==> R" 

87 
shows R 

88 
apply (rule excluded_middle [THEN disjE]) 

89 
apply (erule r1) 

90 
apply (rule r2) 

91 
apply (erule major [THEN mp]) 

92 
done 

93 

94 
(*This version of > elimination works on Q before P. It works best for 

95 
those cases in which P holds "almost everywhere". Can't install as 

96 
default: would break old proofs.*) 

97 
lemma impCE': 

98 
assumes major: "P>Q" 

99 
and r1: "Q ==> R" 

100 
and r2: "~P ==> R" 

101 
shows R 

102 
apply (rule excluded_middle [THEN disjE]) 

103 
apply (erule r2) 

104 
apply (rule r1) 

105 
apply (erule major [THEN mp]) 

106 
done 

107 

108 
(*Double negation law*) 

109 
lemma notnotD: "~~P ==> P" 

110 
apply (rule classical) 

111 
apply (erule notE) 

112 
apply assumption 

113 
done 

114 

115 
lemma contrapos2: "[ Q; ~ P ==> ~ Q ] ==> P" 

116 
apply (rule classical) 

117 
apply (drule (1) meta_mp) 

118 
apply (erule (1) notE) 

119 
done 

120 

121 
(*** Tactics for implication and contradiction ***) 

122 

123 
(*Classical <> elimination. Proof substitutes P=Q in 

124 
~P ==> ~Q and P ==> Q *) 

125 
lemma iffCE: 

126 
assumes major: "P<>Q" 

127 
and r1: "[ P; Q ] ==> R" 

128 
and r2: "[ ~P; ~Q ] ==> R" 

129 
shows R 

130 
apply (rule major [unfolded iff_def, THEN conjE]) 

131 
apply (elim impCE) 

132 
apply (erule (1) r2) 

133 
apply (erule (1) notE)+ 

134 
apply (erule (1) r1) 

135 
done 

136 

137 

138 
(*Better for fast_tac: needs no quantifier duplication!*) 

139 
lemma alt_ex1E: 

140 
assumes major: "EX! x. P(x)" 

141 
and r: "!!x. [ P(x); ALL y y'. P(y) & P(y') > y=y' ] ==> R" 

142 
shows R 

143 
using major 

144 
proof (rule ex1E) 

145 
fix x 

146 
assume * : "\<forall>y. P(y) \<longrightarrow> y = x" 

147 
assume "P(x)" 

148 
then show R 

149 
proof (rule r) 

150 
{ fix y y' 

151 
assume "P(y)" and "P(y')" 

152 
with * have "x = y" and "x = y'" by  (tactic "IntPr.fast_tac 1")+ 

153 
then have "y = y'" by (rule subst) 

154 
} note r' = this 

155 
show "\<forall>y y'. P(y) \<and> P(y') \<longrightarrow> y = y'" by (intro strip, elim conjE) (rule r') 

156 
qed 

157 
qed 

9525  158 

10383  159 
use "cladata.ML" 
160 
setup Cla.setup 

14156  161 
setup cla_setup 
162 
setup case_setup 

10383  163 

9487  164 
use "blastdata.ML" 
165 
setup Blast.setup 

13550  166 

167 

168 
lemma ex1_functional: "[ EX! z. P(a,z); P(a,b); P(a,c) ] ==> b = c" 

21539  169 
by blast 
20223  170 

171 
(* Elimination of True from asumptions: *) 

172 
lemma True_implies_equals: "(True ==> PROP P) == PROP P" 

173 
proof 

174 
assume "True \<Longrightarrow> PROP P" 

175 
from this and TrueI show "PROP P" . 

176 
next 

177 
assume "PROP P" 

178 
then show "PROP P" . 

179 
qed 

9487  180 

21539  181 
lemma uncurry: "P > Q > R ==> P & Q > R" 
182 
by blast 

183 

184 
lemma iff_allI: "(!!x. P(x) <> Q(x)) ==> (ALL x. P(x)) <> (ALL x. Q(x))" 

185 
by blast 

186 

187 
lemma iff_exI: "(!!x. P(x) <> Q(x)) ==> (EX x. P(x)) <> (EX x. Q(x))" 

188 
by blast 

189 

190 
lemma all_comm: "(ALL x y. P(x,y)) <> (ALL y x. P(x,y))" by blast 

191 

192 
lemma ex_comm: "(EX x y. P(x,y)) <> (EX y x. P(x,y))" by blast 

193 

9487  194 
use "simpdata.ML" 
195 
setup simpsetup 

196 
setup "Simplifier.method_setup Splitter.split_modifiers" 

197 
setup Splitter.setup 

198 
setup Clasimp.setup 

18591  199 
setup EqSubst.setup 
15481  200 

201 

14085  202 
subsection {* Other simple lemmas *} 
203 

204 
lemma [simp]: "((P>R) <> (Q>R)) <> ((P<>Q)  R)" 

205 
by blast 

206 

207 
lemma [simp]: "((P>Q) <> (P>R)) <> (P > (Q<>R))" 

208 
by blast 

209 

210 
lemma not_disj_iff_imp: "~P  Q <> (P>Q)" 

211 
by blast 

212 

213 
(** Monotonicity of implications **) 

214 

215 
lemma conj_mono: "[ P1>Q1; P2>Q2 ] ==> (P1&P2) > (Q1&Q2)" 

216 
by fast (*or (IntPr.fast_tac 1)*) 

217 

218 
lemma disj_mono: "[ P1>Q1; P2>Q2 ] ==> (P1P2) > (Q1Q2)" 

219 
by fast (*or (IntPr.fast_tac 1)*) 

220 

221 
lemma imp_mono: "[ Q1>P1; P2>Q2 ] ==> (P1>P2)>(Q1>Q2)" 

222 
by fast (*or (IntPr.fast_tac 1)*) 

223 

224 
lemma imp_refl: "P>P" 

225 
by (rule impI, assumption) 

226 

227 
(*The quantifier monotonicity rules are also intuitionistically valid*) 

228 
lemma ex_mono: "(!!x. P(x) > Q(x)) ==> (EX x. P(x)) > (EX x. Q(x))" 

229 
by blast 

230 

231 
lemma all_mono: "(!!x. P(x) > Q(x)) ==> (ALL x. P(x)) > (ALL x. Q(x))" 

232 
by blast 

233 

11678  234 

235 
subsection {* Proof by cases and induction *} 

236 

237 
text {* Proper handling of nonatomic rule statements. *} 

238 

239 
constdefs 

18456  240 
induct_forall where "induct_forall(P) == \<forall>x. P(x)" 
241 
induct_implies where "induct_implies(A, B) == A \<longrightarrow> B" 

242 
induct_equal where "induct_equal(x, y) == x = y" 

243 
induct_conj where "induct_conj(A, B) == A \<and> B" 

11678  244 

245 
lemma induct_forall_eq: "(!!x. P(x)) == Trueprop(induct_forall(\<lambda>x. P(x)))" 

18816  246 
unfolding atomize_all induct_forall_def . 
11678  247 

248 
lemma induct_implies_eq: "(A ==> B) == Trueprop(induct_implies(A, B))" 

18816  249 
unfolding atomize_imp induct_implies_def . 
11678  250 

251 
lemma induct_equal_eq: "(x == y) == Trueprop(induct_equal(x, y))" 

18816  252 
unfolding atomize_eq induct_equal_def . 
11678  253 

18456  254 
lemma induct_conj_eq: 
255 
includes meta_conjunction_syntax 

256 
shows "(A && B) == Trueprop(induct_conj(A, B))" 

18816  257 
unfolding atomize_conj induct_conj_def . 
11988  258 

18456  259 
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq 
260 
lemmas induct_rulify [symmetric, standard] = induct_atomize 

261 
lemmas induct_rulify_fallback = 

262 
induct_forall_def induct_implies_def induct_equal_def induct_conj_def 

11678  263 

18456  264 
hide const induct_forall induct_implies induct_equal induct_conj 
11678  265 

266 

267 
text {* Method setup. *} 

268 

269 
ML {* 

270 
structure InductMethod = InductMethodFun 

271 
(struct 

22139  272 
val cases_default = @{thm case_split} 
273 
val atomize = @{thms induct_atomize} 

274 
val rulify = @{thms induct_rulify} 

275 
val rulify_fallback = @{thms induct_rulify_fallback} 

11678  276 
end); 
277 
*} 

278 

279 
setup InductMethod.setup 

280 

4854  281 
end 