author  haftmann 
Tue, 10 Jul 2007 17:30:50 +0200  
changeset 23709  fd31da8f752a 
parent 23154  5126551e378b 
child 24097  86734ba03ca2 
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 
23154  10 
uses 
11 
("cladata.ML") 

12 
("blastdata.ML") 

13 
("simpdata.ML") 

18456  14 
begin 
9487  15 

16 

17 
subsection {* The classical axiom *} 

4093  18 

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

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

20 
classical: "(~P ==> P) ==> P" 
4093  21 

9487  22 

11678  23 
subsection {* Lemmas and proof tools *} 
9487  24 

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

27 

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

29 

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

31 
apply (rule classical) 

32 
apply (assumption  erule meta_mp  rule disjI1 notI)+ 

33 
apply (erule notE disjI2)+ 

34 
done 

35 

36 
(*introduction rule involving only EX*) 

37 
lemma ex_classical: 

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

39 
shows "EX x. P(x)" 

40 
apply (rule classical) 

41 
apply (rule exI, erule r) 

42 
done 

43 

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

45 
lemma exCI: 

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

47 
shows "EX x. P(x)" 

48 
apply (rule ex_classical) 

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

50 
apply (erule notE) 

51 
apply (erule exI) 

52 
done 

53 

54 
lemma excluded_middle: "~P  P" 

55 
apply (rule disjCI) 

56 
apply assumption 

57 
done 

58 

59 
(*For disjunctive case analysis*) 

60 
ML {* 

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

21539  63 
*} 
64 

65 
lemma case_split_thm: 

66 
assumes r1: "P ==> Q" 

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

68 
shows Q 

69 
apply (rule excluded_middle [THEN disjE]) 

70 
apply (erule r2) 

71 
apply (erule r1) 

72 
done 

73 

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

75 

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

77 
ML {* 

22139  78 
fun case_tac a = res_inst_tac [("P",a)] @{thm case_split_thm} 
21539  79 
*} 
80 

81 

82 
(*** Special elimination rules *) 

83 

84 

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

86 
lemma impCE: 

87 
assumes major: "P>Q" 

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

89 
and r2: "Q ==> R" 

90 
shows R 

91 
apply (rule excluded_middle [THEN disjE]) 

92 
apply (erule r1) 

93 
apply (rule r2) 

94 
apply (erule major [THEN mp]) 

95 
done 

96 

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

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

99 
default: would break old proofs.*) 

100 
lemma impCE': 

101 
assumes major: "P>Q" 

102 
and r1: "Q ==> R" 

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

104 
shows R 

105 
apply (rule excluded_middle [THEN disjE]) 

106 
apply (erule r2) 

107 
apply (rule r1) 

108 
apply (erule major [THEN mp]) 

109 
done 

110 

111 
(*Double negation law*) 

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

113 
apply (rule classical) 

114 
apply (erule notE) 

115 
apply assumption 

116 
done 

117 

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

119 
apply (rule classical) 

120 
apply (drule (1) meta_mp) 

121 
apply (erule (1) notE) 

122 
done 

123 

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

125 

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

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

128 
lemma iffCE: 

129 
assumes major: "P<>Q" 

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

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

132 
shows R 

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

134 
apply (elim impCE) 

135 
apply (erule (1) r2) 

136 
apply (erule (1) notE)+ 

137 
apply (erule (1) r1) 

138 
done 

139 

140 

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

142 
lemma alt_ex1E: 

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

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

145 
shows R 

146 
using major 

147 
proof (rule ex1E) 

148 
fix x 

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

150 
assume "P(x)" 

151 
then show R 

152 
proof (rule r) 

153 
{ fix y y' 

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

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

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

157 
} note r' = this 

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

159 
qed 

160 
qed 

9525  161 

10383  162 
use "cladata.ML" 
163 
setup Cla.setup 

14156  164 
setup cla_setup 
165 
setup case_setup 

10383  166 

9487  167 
use "blastdata.ML" 
168 
setup Blast.setup 

13550  169 

170 

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

21539  172 
by blast 
20223  173 

174 
(* Elimination of True from asumptions: *) 

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

176 
proof 

177 
assume "True \<Longrightarrow> PROP P" 

178 
from this and TrueI show "PROP P" . 

179 
next 

180 
assume "PROP P" 

181 
then show "PROP P" . 

182 
qed 

9487  183 

21539  184 
lemma uncurry: "P > Q > R ==> P & Q > R" 
185 
by blast 

186 

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

188 
by blast 

189 

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

191 
by blast 

192 

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

194 

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

196 

9487  197 
use "simpdata.ML" 
198 
setup simpsetup 

199 
setup "Simplifier.method_setup Splitter.split_modifiers" 

200 
setup Splitter.setup 

201 
setup Clasimp.setup 

18591  202 
setup EqSubst.setup 
15481  203 

204 

14085  205 
subsection {* Other simple lemmas *} 
206 

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

208 
by blast 

209 

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

211 
by blast 

212 

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

214 
by blast 

215 

216 
(** Monotonicity of implications **) 

217 

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

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

220 

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

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

223 

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

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

226 

227 
lemma imp_refl: "P>P" 

228 
by (rule impI, assumption) 

229 

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

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

232 
by blast 

233 

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

235 
by blast 

236 

11678  237 

238 
subsection {* Proof by cases and induction *} 

239 

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

241 

242 
constdefs 

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

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

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

11678  247 

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

18816  249 
unfolding atomize_all induct_forall_def . 
11678  250 

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

18816  252 
unfolding atomize_imp induct_implies_def . 
11678  253 

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

18816  255 
unfolding atomize_eq induct_equal_def . 
11678  256 

18456  257 
lemma induct_conj_eq: 
258 
includes meta_conjunction_syntax 

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

18816  260 
unfolding atomize_conj induct_conj_def . 
11988  261 

18456  262 
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq 
263 
lemmas induct_rulify [symmetric, standard] = induct_atomize 

264 
lemmas induct_rulify_fallback = 

265 
induct_forall_def induct_implies_def induct_equal_def induct_conj_def 

11678  266 

18456  267 
hide const induct_forall induct_implies induct_equal induct_conj 
11678  268 

269 

270 
text {* Method setup. *} 

271 

272 
ML {* 

273 
structure InductMethod = InductMethodFun 

274 
(struct 

22139  275 
val cases_default = @{thm case_split} 
276 
val atomize = @{thms induct_atomize} 

277 
val rulify = @{thms induct_rulify} 

278 
val rulify_fallback = @{thms induct_rulify_fallback} 

11678  279 
end); 
280 
*} 

281 

282 
setup InductMethod.setup 

283 

4854  284 
end 