14350
|
1 |
(* Title: HOL/ex/Refute_Examples.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tjark Weber
|
|
4 |
Copyright 2003-2004
|
|
5 |
*)
|
|
6 |
|
|
7 |
(* See 'HOL/Refute.thy' for help. *)
|
|
8 |
|
|
9 |
header {* Examples for the 'refute' command *}
|
|
10 |
|
|
11 |
theory Refute_Examples = Main:
|
|
12 |
|
|
13 |
section {* 'refute': General usage *}
|
|
14 |
|
|
15 |
lemma "P"
|
|
16 |
refute
|
|
17 |
oops
|
|
18 |
|
|
19 |
lemma "P \<and> Q"
|
|
20 |
apply (rule conjI)
|
|
21 |
refute 1 -- {* refutes @{term "P"} *}
|
|
22 |
refute 2 -- {* refutes @{term "Q"} *}
|
|
23 |
refute -- {* equivalent to 'refute 1' *}
|
|
24 |
-- {* here 'refute 3' would cause an exception, since we only have 2 subgoals *}
|
|
25 |
refute [maxsize=5] -- {* we can override parameters \<dots> *}
|
|
26 |
refute [satformat="cnf"] 2 -- {* \<dots> and specify a subgoal at the same time *}
|
|
27 |
oops
|
|
28 |
|
|
29 |
section {* Examples / Test cases *}
|
|
30 |
|
|
31 |
subsection {* Propositional logic *}
|
|
32 |
|
|
33 |
lemma "True"
|
|
34 |
refute
|
|
35 |
apply auto
|
|
36 |
done
|
|
37 |
|
|
38 |
lemma "False"
|
|
39 |
refute
|
|
40 |
oops
|
|
41 |
|
|
42 |
lemma "P"
|
|
43 |
refute
|
|
44 |
oops
|
|
45 |
|
|
46 |
lemma "~ P"
|
|
47 |
refute
|
|
48 |
oops
|
|
49 |
|
|
50 |
lemma "P & Q"
|
|
51 |
refute
|
|
52 |
oops
|
|
53 |
|
|
54 |
lemma "P | Q"
|
|
55 |
refute
|
|
56 |
oops
|
|
57 |
|
|
58 |
lemma "P \<longrightarrow> Q"
|
|
59 |
refute
|
|
60 |
oops
|
|
61 |
|
|
62 |
lemma "(P::bool) = Q"
|
|
63 |
refute
|
|
64 |
oops
|
|
65 |
|
|
66 |
lemma "(P | Q) \<longrightarrow> (P & Q)"
|
|
67 |
refute
|
|
68 |
oops
|
|
69 |
|
|
70 |
subsection {* Predicate logic *}
|
|
71 |
|
|
72 |
lemma "P x"
|
|
73 |
refute
|
|
74 |
oops
|
|
75 |
|
|
76 |
lemma "P a b c d"
|
|
77 |
refute
|
|
78 |
oops
|
|
79 |
|
|
80 |
lemma "P x y \<longrightarrow> P y x"
|
|
81 |
refute
|
|
82 |
oops
|
|
83 |
|
|
84 |
subsection {* Equality *}
|
|
85 |
|
|
86 |
lemma "P = True"
|
|
87 |
refute
|
|
88 |
oops
|
|
89 |
|
|
90 |
lemma "P = False"
|
|
91 |
refute
|
|
92 |
oops
|
|
93 |
|
|
94 |
lemma "x = y"
|
|
95 |
refute
|
|
96 |
oops
|
|
97 |
|
|
98 |
lemma "f x = g x"
|
|
99 |
refute
|
|
100 |
oops
|
|
101 |
|
|
102 |
lemma "(f::'a\<Rightarrow>'b) = g"
|
|
103 |
refute
|
|
104 |
oops
|
|
105 |
|
|
106 |
lemma "(f::('d\<Rightarrow>'d)\<Rightarrow>('c\<Rightarrow>'d)) = g"
|
|
107 |
refute
|
|
108 |
oops
|
|
109 |
|
|
110 |
lemma "distinct [a,b]"
|
|
111 |
apply simp
|
|
112 |
refute
|
|
113 |
oops
|
|
114 |
|
|
115 |
subsection {* First-Order Logic *}
|
|
116 |
|
|
117 |
lemma "\<exists>x. P x"
|
|
118 |
refute
|
|
119 |
oops
|
|
120 |
|
|
121 |
lemma "\<forall>x. P x"
|
|
122 |
refute
|
|
123 |
oops
|
|
124 |
|
|
125 |
lemma "EX! x. P x"
|
|
126 |
refute
|
|
127 |
oops
|
|
128 |
|
|
129 |
lemma "Ex P"
|
|
130 |
refute
|
|
131 |
oops
|
|
132 |
|
|
133 |
lemma "All P"
|
|
134 |
refute
|
|
135 |
oops
|
|
136 |
|
|
137 |
lemma "Ex1 P"
|
|
138 |
refute
|
|
139 |
oops
|
|
140 |
|
|
141 |
lemma "(\<exists>x. P x) \<longrightarrow> (\<forall>x. P x)"
|
|
142 |
refute
|
|
143 |
oops
|
|
144 |
|
|
145 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>y. \<forall>x. P x y)"
|
|
146 |
refute
|
|
147 |
oops
|
|
148 |
|
|
149 |
lemma "(\<exists>x. P x) \<longrightarrow> (EX! x. P x)"
|
|
150 |
refute
|
|
151 |
oops
|
|
152 |
|
|
153 |
text {* A true statement (also testing names of free and bound variables being identical) *}
|
|
154 |
|
|
155 |
lemma "(\<forall>x y. P x y \<longrightarrow> P y x) \<longrightarrow> (\<forall>x. P x y) \<longrightarrow> P y x"
|
|
156 |
refute [maxsize=6]
|
|
157 |
apply fast
|
|
158 |
done
|
|
159 |
|
|
160 |
text {* "A type has at most 3 elements." *}
|
|
161 |
|
|
162 |
lemma "\<forall>a b c d. a=b | a=c | a=d | b=c | b=d | c=d"
|
|
163 |
refute
|
|
164 |
oops
|
|
165 |
|
|
166 |
text {* "Every reflexive and symmetric relation is transitive." *}
|
|
167 |
|
|
168 |
lemma "\<lbrakk> \<forall>x. P x x; \<forall>x y. P x y \<longrightarrow> P y x \<rbrakk> \<Longrightarrow> P x y \<longrightarrow> P y z \<longrightarrow> P x z"
|
|
169 |
refute
|
|
170 |
oops
|
|
171 |
|
|
172 |
text {* The "Drinker's theorem" \<dots> *}
|
|
173 |
|
|
174 |
lemma "\<exists>x. f x = g x \<longrightarrow> f = g"
|
|
175 |
refute
|
|
176 |
apply (auto simp add: ext)
|
|
177 |
done
|
|
178 |
|
|
179 |
text {* \<dots> and an incorrect version of it *}
|
|
180 |
|
|
181 |
lemma "(\<exists>x. f x = g x) \<longrightarrow> f = g"
|
|
182 |
refute
|
|
183 |
oops
|
|
184 |
|
|
185 |
text {* "Every function has a fixed point." *}
|
|
186 |
|
|
187 |
lemma "\<exists>x. f x = x"
|
|
188 |
refute
|
|
189 |
oops
|
|
190 |
|
|
191 |
text {* "Function composition is commutative." *}
|
|
192 |
|
|
193 |
lemma "f (g x) = g (f x)"
|
|
194 |
refute
|
|
195 |
oops
|
|
196 |
|
|
197 |
text {* "Two functions that are equivalent wrt.\ the same predicate 'P' are equal." *}
|
|
198 |
|
|
199 |
lemma "((P::('a\<Rightarrow>'b)\<Rightarrow>bool) f = P g) \<longrightarrow> (f x = g x)"
|
|
200 |
refute
|
|
201 |
oops
|
|
202 |
|
|
203 |
subsection {* Higher-Order Logic *}
|
|
204 |
|
|
205 |
lemma "\<exists>P. P"
|
|
206 |
refute
|
|
207 |
apply auto
|
|
208 |
done
|
|
209 |
|
|
210 |
lemma "\<forall>P. P"
|
|
211 |
refute
|
|
212 |
oops
|
|
213 |
|
|
214 |
lemma "EX! P. P"
|
|
215 |
refute
|
|
216 |
apply auto
|
|
217 |
done
|
|
218 |
|
|
219 |
lemma "EX! P. P x"
|
|
220 |
refute
|
|
221 |
oops
|
|
222 |
|
|
223 |
lemma "P Q | Q x"
|
|
224 |
refute
|
|
225 |
oops
|
|
226 |
|
|
227 |
text {* "The transitive closure 'T' of an arbitrary relation 'P' is non-empty." *}
|
|
228 |
|
|
229 |
constdefs
|
|
230 |
"trans" :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
|
|
231 |
"trans P == (ALL x y z. P x y \<longrightarrow> P y z \<longrightarrow> P x z)"
|
|
232 |
"subset" :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
|
|
233 |
"subset P Q == (ALL x y. P x y \<longrightarrow> Q x y)"
|
|
234 |
"trans_closure" :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
|
|
235 |
"trans_closure P Q == (subset Q P) & (trans P) & (ALL R. subset Q R \<longrightarrow> trans R \<longrightarrow> subset P R)"
|
|
236 |
|
|
237 |
lemma "trans_closure T P \<longrightarrow> (\<exists>x y. T x y)"
|
|
238 |
apply (unfold trans_closure_def subset_def trans_def)
|
|
239 |
refute
|
|
240 |
oops
|
|
241 |
|
|
242 |
text {* "The union of transitive closures is equal to the transitive closure of unions." *}
|
|
243 |
|
|
244 |
lemma "(\<forall>x y. (P x y | R x y) \<longrightarrow> T x y) \<longrightarrow> trans T \<longrightarrow> (\<forall>Q. (\<forall>x y. (P x y | R x y) \<longrightarrow> Q x y) \<longrightarrow> trans Q \<longrightarrow> subset T Q)
|
|
245 |
\<longrightarrow> trans_closure TP P
|
|
246 |
\<longrightarrow> trans_closure TR R
|
|
247 |
\<longrightarrow> (T x y = (TP x y | TR x y))"
|
|
248 |
apply (unfold trans_closure_def trans_def subset_def)
|
|
249 |
refute
|
|
250 |
oops
|
|
251 |
|
|
252 |
text {* "Every surjective function is invertible." *}
|
|
253 |
|
|
254 |
lemma "(\<forall>y. \<exists>x. y = f x) \<longrightarrow> (\<exists>g. \<forall>x. g (f x) = x)"
|
|
255 |
refute
|
|
256 |
oops
|
|
257 |
|
|
258 |
text {* "Every invertible function is surjective." *}
|
|
259 |
|
|
260 |
lemma "(\<exists>g. \<forall>x. g (f x) = x) \<longrightarrow> (\<forall>y. \<exists>x. y = f x)"
|
|
261 |
refute
|
|
262 |
oops
|
|
263 |
|
|
264 |
text {* Every point is a fixed point of some function. *}
|
|
265 |
|
|
266 |
lemma "\<exists>f. f x = x"
|
|
267 |
refute [maxsize=5]
|
|
268 |
apply (rule_tac x="\<lambda>x. x" in exI)
|
|
269 |
apply simp
|
|
270 |
done
|
|
271 |
|
|
272 |
text {* Axiom of Choice: first an incorrect version \<dots> *}
|
|
273 |
|
|
274 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (EX!f. \<forall>x. P x (f x))"
|
|
275 |
refute
|
|
276 |
oops
|
|
277 |
|
|
278 |
text {* \<dots> and now two correct ones *}
|
|
279 |
|
|
280 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>f. \<forall>x. P x (f x))"
|
|
281 |
refute
|
|
282 |
apply (simp add: choice)
|
|
283 |
done
|
|
284 |
|
|
285 |
lemma "(\<forall>x. EX!y. P x y) \<longrightarrow> (EX!f. \<forall>x. P x (f x))"
|
|
286 |
refute [maxsize=5]
|
|
287 |
apply auto
|
|
288 |
apply (simp add: ex1_implies_ex choice)
|
|
289 |
apply (fast intro: ext)
|
|
290 |
done
|
|
291 |
|
|
292 |
subsection {* Meta-logic *}
|
|
293 |
|
|
294 |
lemma "!!x. P x"
|
|
295 |
refute
|
|
296 |
oops
|
|
297 |
|
|
298 |
lemma "f x == g x"
|
|
299 |
refute
|
|
300 |
oops
|
|
301 |
|
|
302 |
lemma "P \<Longrightarrow> Q"
|
|
303 |
refute
|
|
304 |
oops
|
|
305 |
|
|
306 |
lemma "\<lbrakk> P; Q; R \<rbrakk> \<Longrightarrow> S"
|
|
307 |
refute
|
|
308 |
oops
|
|
309 |
|
|
310 |
subsection {* Schematic variables *}
|
|
311 |
|
|
312 |
lemma "?P"
|
|
313 |
refute
|
|
314 |
apply auto
|
|
315 |
done
|
|
316 |
|
|
317 |
lemma "x = ?y"
|
|
318 |
refute
|
|
319 |
apply auto
|
|
320 |
done
|
|
321 |
|
|
322 |
subsection {* Abstractions *}
|
|
323 |
|
|
324 |
lemma "(\<lambda>x. x) = (\<lambda>x. y)"
|
|
325 |
refute
|
|
326 |
oops
|
|
327 |
|
|
328 |
lemma "(\<lambda>f. f x) = (\<lambda>f. True)"
|
|
329 |
refute
|
|
330 |
oops
|
|
331 |
|
|
332 |
lemma "(\<lambda>x. x) = (\<lambda>y. y)"
|
|
333 |
refute
|
|
334 |
apply simp
|
|
335 |
done
|
|
336 |
|
|
337 |
subsection {* Sets *}
|
|
338 |
|
|
339 |
lemma "P (A::'a set)"
|
|
340 |
refute
|
|
341 |
oops
|
|
342 |
|
|
343 |
lemma "P (A::'a set set)"
|
|
344 |
refute
|
|
345 |
oops
|
|
346 |
|
|
347 |
lemma "{x. P x} = {y. P y}"
|
|
348 |
refute
|
|
349 |
apply simp
|
|
350 |
done
|
|
351 |
|
|
352 |
lemma "x : {x. P x}"
|
|
353 |
refute
|
|
354 |
oops
|
|
355 |
|
|
356 |
lemma "A Un B = A Int B"
|
|
357 |
apply (unfold Un_def Int_def)
|
|
358 |
refute
|
|
359 |
oops
|
|
360 |
|
|
361 |
lemma "(A Int B) Un C = (A Un C) Int B"
|
|
362 |
apply (unfold Un_def Int_def)
|
|
363 |
refute
|
|
364 |
oops
|
|
365 |
|
|
366 |
lemma "Ball A P \<longrightarrow> Bex A P"
|
|
367 |
apply (unfold Ball_def Bex_def)
|
|
368 |
refute
|
|
369 |
oops
|
|
370 |
|
|
371 |
subsection {* (Inductive) Datatypes *}
|
|
372 |
|
|
373 |
subsubsection {* unit *}
|
|
374 |
|
|
375 |
lemma "P (x::unit)"
|
|
376 |
refute
|
|
377 |
oops
|
|
378 |
|
|
379 |
lemma "\<forall>x::unit. P x"
|
|
380 |
refute
|
|
381 |
oops
|
|
382 |
|
|
383 |
lemma "P ()"
|
|
384 |
refute
|
|
385 |
oops
|
|
386 |
|
|
387 |
subsubsection {* * *}
|
|
388 |
|
|
389 |
lemma "P (x::'a*'b)"
|
|
390 |
oops
|
|
391 |
|
|
392 |
lemma "\<forall>x::'a*'b. P x"
|
|
393 |
oops
|
|
394 |
|
|
395 |
lemma "P (x,y)"
|
|
396 |
oops
|
|
397 |
|
|
398 |
lemma "P (fst x)"
|
|
399 |
oops
|
|
400 |
|
|
401 |
lemma "P (snd x)"
|
|
402 |
oops
|
|
403 |
|
|
404 |
subsubsection {* + *}
|
|
405 |
|
|
406 |
lemma "P (x::'a+'b)"
|
|
407 |
oops
|
|
408 |
|
|
409 |
lemma "\<forall>x::'a+'b. P x"
|
|
410 |
oops
|
|
411 |
|
|
412 |
lemma "P (Inl x)"
|
|
413 |
oops
|
|
414 |
|
|
415 |
lemma "P (Inr x)"
|
|
416 |
oops
|
|
417 |
|
|
418 |
subsubsection {* Non-recursive datatypes *}
|
|
419 |
|
|
420 |
datatype T1 = C1
|
|
421 |
|
|
422 |
lemma "P (x::T1)"
|
|
423 |
refute
|
|
424 |
oops
|
|
425 |
|
|
426 |
lemma "\<forall>x::T1. P x"
|
|
427 |
refute
|
|
428 |
oops
|
|
429 |
|
|
430 |
lemma "P C"
|
|
431 |
oops
|
|
432 |
|
|
433 |
datatype T2 = C2 T1
|
|
434 |
|
|
435 |
lemma "P (x::T2)"
|
|
436 |
refute
|
|
437 |
oops
|
|
438 |
|
|
439 |
lemma "\<forall>x::T2. P x"
|
|
440 |
refute
|
|
441 |
oops
|
|
442 |
|
|
443 |
lemma "P (C2 C1)"
|
|
444 |
oops
|
|
445 |
|
|
446 |
lemma "P (C2 x)"
|
|
447 |
oops
|
|
448 |
|
|
449 |
datatype 'a T3 = C3 'a
|
|
450 |
|
|
451 |
lemma "P (x::'a T3)"
|
|
452 |
refute
|
|
453 |
oops
|
|
454 |
|
|
455 |
lemma "\<forall>x::'a T3. P x"
|
|
456 |
refute
|
|
457 |
oops
|
|
458 |
|
|
459 |
lemma "P (C3 x)"
|
|
460 |
oops
|
|
461 |
|
|
462 |
subsubsection {* Recursive datatypes *}
|
|
463 |
|
|
464 |
datatype Nat = Zero | Suc Nat
|
|
465 |
|
|
466 |
lemma "P (x::Nat)"
|
|
467 |
refute
|
|
468 |
oops
|
|
469 |
|
|
470 |
lemma "\<forall>x::Nat. P x"
|
|
471 |
refute
|
|
472 |
oops
|
|
473 |
|
|
474 |
lemma "P (Suc Zero)"
|
|
475 |
oops
|
|
476 |
|
|
477 |
datatype 'a BinTree = Leaf 'a | Node "'a BinTree" "'a BinTree"
|
|
478 |
|
|
479 |
lemma "P (x::'a BinTree)"
|
|
480 |
refute
|
|
481 |
oops
|
|
482 |
|
|
483 |
lemma "\<forall>x::'a BinTree. P x"
|
|
484 |
refute
|
|
485 |
oops
|
|
486 |
|
|
487 |
subsubsection {* Mutually recursive datatypes *}
|
|
488 |
|
|
489 |
datatype 'a aexp = Number 'a | ITE "'a bexp" "'a aexp" "'a aexp"
|
|
490 |
and 'a bexp = Equal "'a aexp" "'a aexp"
|
|
491 |
|
|
492 |
lemma "P (x::'a aexp)"
|
|
493 |
refute
|
|
494 |
oops
|
|
495 |
|
|
496 |
lemma "\<forall>x::'a aexp. P x"
|
|
497 |
refute
|
|
498 |
oops
|
|
499 |
|
|
500 |
lemma "P (x::'a bexp)"
|
|
501 |
refute
|
|
502 |
oops
|
|
503 |
|
|
504 |
lemma "\<forall>x::'a bexp. P x"
|
|
505 |
refute
|
|
506 |
oops
|
|
507 |
|
|
508 |
lemma "P (ITE (Equal (Number x) (Number y)) (Number x) (Number y))"
|
|
509 |
oops
|
|
510 |
|
|
511 |
subsubsection {* Other datatype examples *}
|
|
512 |
|
|
513 |
datatype InfTree = Leaf | Node "Nat \<Rightarrow> InfTree"
|
|
514 |
|
|
515 |
lemma "P (x::InfTree)"
|
|
516 |
oops
|
|
517 |
|
|
518 |
datatype 'a lambda = Var 'a | App "'a lambda" "'a lambda" | Lam "'a \<Rightarrow> 'a lambda"
|
|
519 |
|
|
520 |
lemma "P (x::'a lambda)"
|
|
521 |
oops
|
|
522 |
|
|
523 |
end
|