author | noschinl |
Wed, 23 Feb 2011 11:23:26 +0100 | |
changeset 41827 | 98eda7ffde79 |
parent 41779 | a68f503805ed |
child 42453 | cd5005020f4e |
permissions | -rw-r--r-- |
9487 | 1 |
(* Title: FOL/FOL.thy |
2 |
Author: Lawrence C Paulson and Markus Wenzel |
|
11678 | 3 |
*) |
9487 | 4 |
|
11678 | 5 |
header {* Classical first-order logic *} |
4093 | 6 |
|
18456 | 7 |
theory FOL |
15481 | 8 |
imports IFOL |
23154 | 9 |
uses |
24097 | 10 |
"~~/src/Provers/classical.ML" |
11 |
"~~/src/Provers/blast.ML" |
|
12 |
"~~/src/Provers/clasimp.ML" |
|
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24097
diff
changeset
|
13 |
"~~/src/Tools/induct.ML" |
41827 | 14 |
"~~/src/Tools/case_product.ML" |
23154 | 15 |
("cladata.ML") |
16 |
("simpdata.ML") |
|
18456 | 17 |
begin |
9487 | 18 |
|
19 |
||
20 |
subsection {* The classical axiom *} |
|
4093 | 21 |
|
41779 | 22 |
axiomatization where |
7355
4c43090659ca
proper bootstrap of IFOL/FOL theories and packages;
wenzelm
parents:
5887
diff
changeset
|
23 |
classical: "(~P ==> P) ==> P" |
4093 | 24 |
|
9487 | 25 |
|
11678 | 26 |
subsection {* Lemmas and proof tools *} |
9487 | 27 |
|
21539 | 28 |
lemma ccontr: "(\<not> P \<Longrightarrow> False) \<Longrightarrow> P" |
29 |
by (erule FalseE [THEN classical]) |
|
30 |
||
31 |
(*** Classical introduction rules for | and EX ***) |
|
32 |
||
33 |
lemma disjCI: "(~Q ==> P) ==> P|Q" |
|
34 |
apply (rule classical) |
|
35 |
apply (assumption | erule meta_mp | rule disjI1 notI)+ |
|
36 |
apply (erule notE disjI2)+ |
|
37 |
done |
|
38 |
||
39 |
(*introduction rule involving only EX*) |
|
40 |
lemma ex_classical: |
|
41 |
assumes r: "~(EX x. P(x)) ==> P(a)" |
|
42 |
shows "EX x. P(x)" |
|
43 |
apply (rule classical) |
|
44 |
apply (rule exI, erule r) |
|
45 |
done |
|
46 |
||
47 |
(*version of above, simplifying ~EX to ALL~ *) |
|
48 |
lemma exCI: |
|
49 |
assumes r: "ALL x. ~P(x) ==> P(a)" |
|
50 |
shows "EX x. P(x)" |
|
51 |
apply (rule ex_classical) |
|
52 |
apply (rule notI [THEN allI, THEN r]) |
|
53 |
apply (erule notE) |
|
54 |
apply (erule exI) |
|
55 |
done |
|
56 |
||
57 |
lemma excluded_middle: "~P | P" |
|
58 |
apply (rule disjCI) |
|
59 |
apply assumption |
|
60 |
done |
|
61 |
||
27115
0dcafa5c9e3f
eliminated obsolete case_split_thm -- use case_split;
wenzelm
parents:
26496
diff
changeset
|
62 |
lemma case_split [case_names True False]: |
21539 | 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 |
ML {* |
|
27239 | 72 |
fun case_tac ctxt a = res_inst_tac ctxt [(("P", 0), a)] @{thm case_split} |
21539 | 73 |
*} |
74 |
||
30549 | 75 |
method_setup case_tac = {* |
76 |
Args.goal_spec -- Scan.lift Args.name_source >> |
|
77 |
(fn (quant, s) => fn ctxt => SIMPLE_METHOD'' quant (case_tac ctxt s)) |
|
78 |
*} "case_tac emulation (dynamic instantiation!)" |
|
27211 | 79 |
|
21539 | 80 |
|
81 |
(*** Special elimination rules *) |
|
82 |
||
83 |
||
84 |
(*Classical implies (-->) elimination. *) |
|
85 |
lemma impCE: |
|
86 |
assumes major: "P-->Q" |
|
87 |
and r1: "~P ==> R" |
|
88 |
and r2: "Q ==> R" |
|
89 |
shows R |
|
90 |
apply (rule excluded_middle [THEN disjE]) |
|
91 |
apply (erule r1) |
|
92 |
apply (rule r2) |
|
93 |
apply (erule major [THEN mp]) |
|
94 |
done |
|
95 |
||
96 |
(*This version of --> elimination works on Q before P. It works best for |
|
97 |
those cases in which P holds "almost everywhere". Can't install as |
|
98 |
default: would break old proofs.*) |
|
99 |
lemma impCE': |
|
100 |
assumes major: "P-->Q" |
|
101 |
and r1: "Q ==> R" |
|
102 |
and r2: "~P ==> R" |
|
103 |
shows R |
|
104 |
apply (rule excluded_middle [THEN disjE]) |
|
105 |
apply (erule r2) |
|
106 |
apply (rule r1) |
|
107 |
apply (erule major [THEN mp]) |
|
108 |
done |
|
109 |
||
110 |
(*Double negation law*) |
|
111 |
lemma notnotD: "~~P ==> P" |
|
112 |
apply (rule classical) |
|
113 |
apply (erule notE) |
|
114 |
apply assumption |
|
115 |
done |
|
116 |
||
117 |
lemma contrapos2: "[| Q; ~ P ==> ~ Q |] ==> P" |
|
118 |
apply (rule classical) |
|
119 |
apply (drule (1) meta_mp) |
|
120 |
apply (erule (1) notE) |
|
121 |
done |
|
122 |
||
123 |
(*** Tactics for implication and contradiction ***) |
|
124 |
||
125 |
(*Classical <-> elimination. Proof substitutes P=Q in |
|
126 |
~P ==> ~Q and P ==> Q *) |
|
127 |
lemma iffCE: |
|
128 |
assumes major: "P<->Q" |
|
129 |
and r1: "[| P; Q |] ==> R" |
|
130 |
and r2: "[| ~P; ~Q |] ==> R" |
|
131 |
shows R |
|
132 |
apply (rule major [unfolded iff_def, THEN conjE]) |
|
133 |
apply (elim impCE) |
|
134 |
apply (erule (1) r2) |
|
135 |
apply (erule (1) notE)+ |
|
136 |
apply (erule (1) r1) |
|
137 |
done |
|
138 |
||
139 |
||
140 |
(*Better for fast_tac: needs no quantifier duplication!*) |
|
141 |
lemma alt_ex1E: |
|
142 |
assumes major: "EX! x. P(x)" |
|
143 |
and r: "!!x. [| P(x); ALL y y'. P(y) & P(y') --> y=y' |] ==> R" |
|
144 |
shows R |
|
145 |
using major |
|
146 |
proof (rule ex1E) |
|
147 |
fix x |
|
148 |
assume * : "\<forall>y. P(y) \<longrightarrow> y = x" |
|
149 |
assume "P(x)" |
|
150 |
then show R |
|
151 |
proof (rule r) |
|
152 |
{ fix y y' |
|
153 |
assume "P(y)" and "P(y')" |
|
154 |
with * have "x = y" and "x = y'" by - (tactic "IntPr.fast_tac 1")+ |
|
155 |
then have "y = y'" by (rule subst) |
|
156 |
} note r' = this |
|
157 |
show "\<forall>y y'. P(y) \<and> P(y') \<longrightarrow> y = y'" by (intro strip, elim conjE) (rule r') |
|
158 |
qed |
|
159 |
qed |
|
9525 | 160 |
|
26411 | 161 |
lemma imp_elim: "P --> Q ==> (~ R ==> P) ==> (Q ==> R) ==> R" |
162 |
by (rule classical) iprover |
|
163 |
||
164 |
lemma swap: "~ P ==> (~ R ==> P) ==> R" |
|
165 |
by (rule classical) iprover |
|
166 |
||
27849 | 167 |
|
168 |
section {* Classical Reasoner *} |
|
169 |
||
10383 | 170 |
use "cladata.ML" |
171 |
setup Cla.setup |
|
32261 | 172 |
ML {* Context.>> (Cla.map_cs (K FOL_cs)) *} |
10383 | 173 |
|
32176
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
174 |
ML {* |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
175 |
structure Blast = Blast |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
176 |
( |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
177 |
val thy = @{theory} |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32261
diff
changeset
|
178 |
type claset = Cla.claset |
41310 | 179 |
val equality_name = @{const_name eq} |
32176
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
180 |
val not_name = @{const_name Not} |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32261
diff
changeset
|
181 |
val notE = @{thm notE} |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32261
diff
changeset
|
182 |
val ccontr = @{thm ccontr} |
32176
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
183 |
val contr_tac = Cla.contr_tac |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32261
diff
changeset
|
184 |
val dup_intr = Cla.dup_intr |
32176
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
185 |
val hyp_subst_tac = Hypsubst.blast_hyp_subst_tac |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
186 |
val rep_cs = Cla.rep_cs |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
187 |
val cla_modifiers = Cla.cla_modifiers |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
188 |
val cla_meth' = Cla.cla_meth' |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
189 |
); |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
190 |
val blast_tac = Blast.blast_tac; |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
191 |
*} |
893614e2c35c
renamed functor BlastFun to Blast, require explicit theory;
wenzelm
parents:
32171
diff
changeset
|
192 |
|
9487 | 193 |
setup Blast.setup |
13550 | 194 |
|
195 |
||
196 |
lemma ex1_functional: "[| EX! z. P(a,z); P(a,b); P(a,c) |] ==> b = c" |
|
21539 | 197 |
by blast |
20223 | 198 |
|
199 |
(* Elimination of True from asumptions: *) |
|
200 |
lemma True_implies_equals: "(True ==> PROP P) == PROP P" |
|
201 |
proof |
|
202 |
assume "True \<Longrightarrow> PROP P" |
|
203 |
from this and TrueI show "PROP P" . |
|
204 |
next |
|
205 |
assume "PROP P" |
|
206 |
then show "PROP P" . |
|
207 |
qed |
|
9487 | 208 |
|
21539 | 209 |
lemma uncurry: "P --> Q --> R ==> P & Q --> R" |
210 |
by blast |
|
211 |
||
212 |
lemma iff_allI: "(!!x. P(x) <-> Q(x)) ==> (ALL x. P(x)) <-> (ALL x. Q(x))" |
|
213 |
by blast |
|
214 |
||
215 |
lemma iff_exI: "(!!x. P(x) <-> Q(x)) ==> (EX x. P(x)) <-> (EX x. Q(x))" |
|
216 |
by blast |
|
217 |
||
218 |
lemma all_comm: "(ALL x y. P(x,y)) <-> (ALL y x. P(x,y))" by blast |
|
219 |
||
220 |
lemma ex_comm: "(EX x y. P(x,y)) <-> (EX y x. P(x,y))" by blast |
|
221 |
||
26286 | 222 |
|
223 |
||
224 |
(*** Classical simplification rules ***) |
|
225 |
||
226 |
(*Avoids duplication of subgoals after expand_if, when the true and false |
|
227 |
cases boil down to the same thing.*) |
|
228 |
lemma cases_simp: "(P --> Q) & (~P --> Q) <-> Q" by blast |
|
229 |
||
230 |
||
231 |
(*** Miniscoping: pushing quantifiers in |
|
232 |
We do NOT distribute of ALL over &, or dually that of EX over | |
|
233 |
Baaz and Leitsch, On Skolemization and Proof Complexity (1994) |
|
234 |
show that this step can increase proof length! |
|
235 |
***) |
|
236 |
||
237 |
(*existential miniscoping*) |
|
238 |
lemma int_ex_simps: |
|
239 |
"!!P Q. (EX x. P(x) & Q) <-> (EX x. P(x)) & Q" |
|
240 |
"!!P Q. (EX x. P & Q(x)) <-> P & (EX x. Q(x))" |
|
241 |
"!!P Q. (EX x. P(x) | Q) <-> (EX x. P(x)) | Q" |
|
242 |
"!!P Q. (EX x. P | Q(x)) <-> P | (EX x. Q(x))" |
|
243 |
by iprover+ |
|
244 |
||
245 |
(*classical rules*) |
|
246 |
lemma cla_ex_simps: |
|
247 |
"!!P Q. (EX x. P(x) --> Q) <-> (ALL x. P(x)) --> Q" |
|
248 |
"!!P Q. (EX x. P --> Q(x)) <-> P --> (EX x. Q(x))" |
|
249 |
by blast+ |
|
250 |
||
251 |
lemmas ex_simps = int_ex_simps cla_ex_simps |
|
252 |
||
253 |
(*universal miniscoping*) |
|
254 |
lemma int_all_simps: |
|
255 |
"!!P Q. (ALL x. P(x) & Q) <-> (ALL x. P(x)) & Q" |
|
256 |
"!!P Q. (ALL x. P & Q(x)) <-> P & (ALL x. Q(x))" |
|
257 |
"!!P Q. (ALL x. P(x) --> Q) <-> (EX x. P(x)) --> Q" |
|
258 |
"!!P Q. (ALL x. P --> Q(x)) <-> P --> (ALL x. Q(x))" |
|
259 |
by iprover+ |
|
260 |
||
261 |
(*classical rules*) |
|
262 |
lemma cla_all_simps: |
|
263 |
"!!P Q. (ALL x. P(x) | Q) <-> (ALL x. P(x)) | Q" |
|
264 |
"!!P Q. (ALL x. P | Q(x)) <-> P | (ALL x. Q(x))" |
|
265 |
by blast+ |
|
266 |
||
267 |
lemmas all_simps = int_all_simps cla_all_simps |
|
268 |
||
269 |
||
270 |
(*** Named rewrite rules proved for IFOL ***) |
|
271 |
||
272 |
lemma imp_disj1: "(P-->Q) | R <-> (P-->Q | R)" by blast |
|
273 |
lemma imp_disj2: "Q | (P-->R) <-> (P-->Q | R)" by blast |
|
274 |
||
275 |
lemma de_Morgan_conj: "(~(P & Q)) <-> (~P | ~Q)" by blast |
|
276 |
||
277 |
lemma not_imp: "~(P --> Q) <-> (P & ~Q)" by blast |
|
278 |
lemma not_iff: "~(P <-> Q) <-> (P <-> ~Q)" by blast |
|
279 |
||
280 |
lemma not_all: "(~ (ALL x. P(x))) <-> (EX x.~P(x))" by blast |
|
281 |
lemma imp_all: "((ALL x. P(x)) --> Q) <-> (EX x. P(x) --> Q)" by blast |
|
282 |
||
283 |
||
284 |
lemmas meta_simps = |
|
285 |
triv_forall_equality (* prunes params *) |
|
286 |
True_implies_equals (* prune asms `True' *) |
|
287 |
||
288 |
lemmas IFOL_simps = |
|
289 |
refl [THEN P_iff_T] conj_simps disj_simps not_simps |
|
290 |
imp_simps iff_simps quant_simps |
|
291 |
||
292 |
lemma notFalseI: "~False" by iprover |
|
293 |
||
294 |
lemma cla_simps_misc: |
|
295 |
"~(P&Q) <-> ~P | ~Q" |
|
296 |
"P | ~P" |
|
297 |
"~P | P" |
|
298 |
"~ ~ P <-> P" |
|
299 |
"(~P --> P) <-> P" |
|
300 |
"(~P <-> ~Q) <-> (P<->Q)" by blast+ |
|
301 |
||
302 |
lemmas cla_simps = |
|
303 |
de_Morgan_conj de_Morgan_disj imp_disj1 imp_disj2 |
|
304 |
not_imp not_all not_ex cases_simp cla_simps_misc |
|
305 |
||
306 |
||
9487 | 307 |
use "simpdata.ML" |
308 |
setup simpsetup |
|
309 |
setup "Simplifier.method_setup Splitter.split_modifiers" |
|
310 |
setup Splitter.setup |
|
26496
49ae9456eba9
purely functional setup of claset/simpset/clasimpset;
wenzelm
parents:
26411
diff
changeset
|
311 |
setup clasimp_setup |
18591 | 312 |
setup EqSubst.setup |
15481 | 313 |
|
314 |
||
14085 | 315 |
subsection {* Other simple lemmas *} |
316 |
||
317 |
lemma [simp]: "((P-->R) <-> (Q-->R)) <-> ((P<->Q) | R)" |
|
318 |
by blast |
|
319 |
||
320 |
lemma [simp]: "((P-->Q) <-> (P-->R)) <-> (P --> (Q<->R))" |
|
321 |
by blast |
|
322 |
||
323 |
lemma not_disj_iff_imp: "~P | Q <-> (P-->Q)" |
|
324 |
by blast |
|
325 |
||
326 |
(** Monotonicity of implications **) |
|
327 |
||
328 |
lemma conj_mono: "[| P1-->Q1; P2-->Q2 |] ==> (P1&P2) --> (Q1&Q2)" |
|
329 |
by fast (*or (IntPr.fast_tac 1)*) |
|
330 |
||
331 |
lemma disj_mono: "[| P1-->Q1; P2-->Q2 |] ==> (P1|P2) --> (Q1|Q2)" |
|
332 |
by fast (*or (IntPr.fast_tac 1)*) |
|
333 |
||
334 |
lemma imp_mono: "[| Q1-->P1; P2-->Q2 |] ==> (P1-->P2)-->(Q1-->Q2)" |
|
335 |
by fast (*or (IntPr.fast_tac 1)*) |
|
336 |
||
337 |
lemma imp_refl: "P-->P" |
|
338 |
by (rule impI, assumption) |
|
339 |
||
340 |
(*The quantifier monotonicity rules are also intuitionistically valid*) |
|
341 |
lemma ex_mono: "(!!x. P(x) --> Q(x)) ==> (EX x. P(x)) --> (EX x. Q(x))" |
|
342 |
by blast |
|
343 |
||
344 |
lemma all_mono: "(!!x. P(x) --> Q(x)) ==> (ALL x. P(x)) --> (ALL x. Q(x))" |
|
345 |
by blast |
|
346 |
||
11678 | 347 |
|
348 |
subsection {* Proof by cases and induction *} |
|
349 |
||
350 |
text {* Proper handling of non-atomic rule statements. *} |
|
351 |
||
36866 | 352 |
definition "induct_forall(P) == \<forall>x. P(x)" |
353 |
definition "induct_implies(A, B) == A \<longrightarrow> B" |
|
354 |
definition "induct_equal(x, y) == x = y" |
|
355 |
definition "induct_conj(A, B) == A \<and> B" |
|
11678 | 356 |
|
357 |
lemma induct_forall_eq: "(!!x. P(x)) == Trueprop(induct_forall(\<lambda>x. P(x)))" |
|
18816 | 358 |
unfolding atomize_all induct_forall_def . |
11678 | 359 |
|
360 |
lemma induct_implies_eq: "(A ==> B) == Trueprop(induct_implies(A, B))" |
|
18816 | 361 |
unfolding atomize_imp induct_implies_def . |
11678 | 362 |
|
363 |
lemma induct_equal_eq: "(x == y) == Trueprop(induct_equal(x, y))" |
|
18816 | 364 |
unfolding atomize_eq induct_equal_def . |
11678 | 365 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28699
diff
changeset
|
366 |
lemma induct_conj_eq: "(A &&& B) == Trueprop(induct_conj(A, B))" |
18816 | 367 |
unfolding atomize_conj induct_conj_def . |
11988 | 368 |
|
18456 | 369 |
lemmas induct_atomize = induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq |
370 |
lemmas induct_rulify [symmetric, standard] = induct_atomize |
|
371 |
lemmas induct_rulify_fallback = |
|
372 |
induct_forall_def induct_implies_def induct_equal_def induct_conj_def |
|
11678 | 373 |
|
36176
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
34989
diff
changeset
|
374 |
hide_const induct_forall induct_implies induct_equal induct_conj |
11678 | 375 |
|
376 |
||
377 |
text {* Method setup. *} |
|
378 |
||
379 |
ML {* |
|
32171 | 380 |
structure Induct = Induct |
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24097
diff
changeset
|
381 |
( |
22139 | 382 |
val cases_default = @{thm case_split} |
383 |
val atomize = @{thms induct_atomize} |
|
384 |
val rulify = @{thms induct_rulify} |
|
385 |
val rulify_fallback = @{thms induct_rulify_fallback} |
|
34989 | 386 |
val equal_def = @{thm induct_equal_def} |
34914 | 387 |
fun dest_def _ = NONE |
388 |
fun trivial_tac _ = no_tac |
|
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24097
diff
changeset
|
389 |
); |
11678 | 390 |
*} |
391 |
||
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24097
diff
changeset
|
392 |
setup Induct.setup |
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
24097
diff
changeset
|
393 |
declare case_split [cases type: o] |
11678 | 394 |
|
41827 | 395 |
setup Case_Product.setup |
396 |
||
41310 | 397 |
|
398 |
hide_const (open) eq |
|
399 |
||
4854 | 400 |
end |