33197
|
1 |
(* Title: HOL/Nitpick_Examples/Refute_Nits.thy
|
|
2 |
Author: Jasmin Blanchette, TU Muenchen
|
|
3 |
Copyright 2009
|
|
4 |
|
|
5 |
Refute examples adapted to Nitpick.
|
|
6 |
*)
|
|
7 |
|
|
8 |
header {* Refute Examples Adapted to Nitpick *}
|
|
9 |
|
|
10 |
theory Refute_Nits
|
|
11 |
imports Main
|
|
12 |
begin
|
|
13 |
|
|
14 |
lemma "P \<and> Q"
|
|
15 |
apply (rule conjI)
|
|
16 |
nitpick [expect = genuine] 1
|
|
17 |
nitpick [expect = genuine] 2
|
|
18 |
nitpick [expect = genuine]
|
|
19 |
nitpick [card = 5, expect = genuine]
|
|
20 |
nitpick [sat_solver = MiniSat, expect = genuine] 2
|
|
21 |
oops
|
|
22 |
|
|
23 |
subsection {* Examples and Test Cases *}
|
|
24 |
|
|
25 |
subsubsection {* Propositional logic *}
|
|
26 |
|
|
27 |
lemma "True"
|
|
28 |
nitpick [expect = none]
|
|
29 |
apply auto
|
|
30 |
done
|
|
31 |
|
|
32 |
lemma "False"
|
|
33 |
nitpick [expect = genuine]
|
|
34 |
oops
|
|
35 |
|
|
36 |
lemma "P"
|
|
37 |
nitpick [expect = genuine]
|
|
38 |
oops
|
|
39 |
|
|
40 |
lemma "\<not> P"
|
|
41 |
nitpick [expect = genuine]
|
|
42 |
oops
|
|
43 |
|
|
44 |
lemma "P \<and> Q"
|
|
45 |
nitpick [expect = genuine]
|
|
46 |
oops
|
|
47 |
|
|
48 |
lemma "P \<or> Q"
|
|
49 |
nitpick [expect = genuine]
|
|
50 |
oops
|
|
51 |
|
|
52 |
lemma "P \<longrightarrow> Q"
|
|
53 |
nitpick [expect = genuine]
|
|
54 |
oops
|
|
55 |
|
|
56 |
lemma "(P\<Colon>bool) = Q"
|
|
57 |
nitpick [expect = genuine]
|
|
58 |
oops
|
|
59 |
|
|
60 |
lemma "(P \<or> Q) \<longrightarrow> (P \<and> Q)"
|
|
61 |
nitpick [expect = genuine]
|
|
62 |
oops
|
|
63 |
|
|
64 |
subsubsection {* Predicate logic *}
|
|
65 |
|
|
66 |
lemma "P x y z"
|
|
67 |
nitpick [expect = genuine]
|
|
68 |
oops
|
|
69 |
|
|
70 |
lemma "P x y \<longrightarrow> P y x"
|
|
71 |
nitpick [expect = genuine]
|
|
72 |
oops
|
|
73 |
|
|
74 |
lemma "P (f (f x)) \<longrightarrow> P x \<longrightarrow> P (f x)"
|
|
75 |
nitpick [expect = genuine]
|
|
76 |
oops
|
|
77 |
|
|
78 |
subsubsection {* Equality *}
|
|
79 |
|
|
80 |
lemma "P = True"
|
|
81 |
nitpick [expect = genuine]
|
|
82 |
oops
|
|
83 |
|
|
84 |
lemma "P = False"
|
|
85 |
nitpick [expect = genuine]
|
|
86 |
oops
|
|
87 |
|
|
88 |
lemma "x = y"
|
|
89 |
nitpick [expect = genuine]
|
|
90 |
oops
|
|
91 |
|
|
92 |
lemma "f x = g x"
|
|
93 |
nitpick [expect = genuine]
|
|
94 |
oops
|
|
95 |
|
|
96 |
lemma "(f\<Colon>'a\<Rightarrow>'b) = g"
|
|
97 |
nitpick [expect = genuine]
|
|
98 |
oops
|
|
99 |
|
|
100 |
lemma "(f\<Colon>('d\<Rightarrow>'d)\<Rightarrow>('c\<Rightarrow>'d)) = g"
|
|
101 |
nitpick [expect = genuine]
|
|
102 |
oops
|
|
103 |
|
|
104 |
lemma "distinct [a, b]"
|
|
105 |
nitpick [expect = genuine]
|
|
106 |
apply simp
|
|
107 |
nitpick [expect = genuine]
|
|
108 |
oops
|
|
109 |
|
|
110 |
subsubsection {* First-Order Logic *}
|
|
111 |
|
|
112 |
lemma "\<exists>x. P x"
|
|
113 |
nitpick [expect = genuine]
|
|
114 |
oops
|
|
115 |
|
|
116 |
lemma "\<forall>x. P x"
|
|
117 |
nitpick [expect = genuine]
|
|
118 |
oops
|
|
119 |
|
|
120 |
lemma "\<exists>!x. P x"
|
|
121 |
nitpick [expect = genuine]
|
|
122 |
oops
|
|
123 |
|
|
124 |
lemma "Ex P"
|
|
125 |
nitpick [expect = genuine]
|
|
126 |
oops
|
|
127 |
|
|
128 |
lemma "All P"
|
|
129 |
nitpick [expect = genuine]
|
|
130 |
oops
|
|
131 |
|
|
132 |
lemma "Ex1 P"
|
|
133 |
nitpick [expect = genuine]
|
|
134 |
oops
|
|
135 |
|
|
136 |
lemma "(\<exists>x. P x) \<longrightarrow> (\<forall>x. P x)"
|
|
137 |
nitpick [expect = genuine]
|
|
138 |
oops
|
|
139 |
|
|
140 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>y. \<forall>x. P x y)"
|
|
141 |
nitpick [expect = genuine]
|
|
142 |
oops
|
|
143 |
|
|
144 |
lemma "(\<exists>x. P x) \<longrightarrow> (\<exists>!x. P x)"
|
|
145 |
nitpick [expect = genuine]
|
|
146 |
oops
|
|
147 |
|
|
148 |
text {* A true statement (also testing names of free and bound variables being identical) *}
|
|
149 |
|
|
150 |
lemma "(\<forall>x y. P x y \<longrightarrow> P y x) \<longrightarrow> (\<forall>x. P x y) \<longrightarrow> P y x"
|
|
151 |
nitpick [expect = none]
|
|
152 |
apply fast
|
|
153 |
done
|
|
154 |
|
|
155 |
text {* "A type has at most 4 elements." *}
|
|
156 |
|
|
157 |
lemma "\<not> distinct [a, b, c, d, e]"
|
|
158 |
nitpick [expect = genuine]
|
|
159 |
apply simp
|
|
160 |
nitpick [expect = genuine]
|
|
161 |
oops
|
|
162 |
|
|
163 |
lemma "distinct [a, b, c, d]"
|
|
164 |
nitpick [expect = genuine]
|
|
165 |
apply simp
|
|
166 |
nitpick [expect = genuine]
|
|
167 |
oops
|
|
168 |
|
|
169 |
text {* "Every reflexive and symmetric relation is transitive." *}
|
|
170 |
|
|
171 |
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"
|
|
172 |
nitpick [expect = genuine]
|
|
173 |
oops
|
|
174 |
|
|
175 |
text {* The "Drinker's theorem" ... *}
|
|
176 |
|
|
177 |
lemma "\<exists>x. f x = g x \<longrightarrow> f = g"
|
|
178 |
nitpick [expect = none]
|
|
179 |
apply (auto simp add: ext)
|
|
180 |
done
|
|
181 |
|
|
182 |
text {* ... and an incorrect version of it *}
|
|
183 |
|
|
184 |
lemma "(\<exists>x. f x = g x) \<longrightarrow> f = g"
|
|
185 |
nitpick [expect = genuine]
|
|
186 |
oops
|
|
187 |
|
|
188 |
text {* "Every function has a fixed point." *}
|
|
189 |
|
|
190 |
lemma "\<exists>x. f x = x"
|
|
191 |
nitpick [expect = genuine]
|
|
192 |
oops
|
|
193 |
|
|
194 |
text {* "Function composition is commutative." *}
|
|
195 |
|
|
196 |
lemma "f (g x) = g (f x)"
|
|
197 |
nitpick [expect = genuine]
|
|
198 |
oops
|
|
199 |
|
|
200 |
text {* "Two functions that are equivalent wrt.\ the same predicate 'P' are equal." *}
|
|
201 |
|
|
202 |
lemma "((P\<Colon>('a\<Rightarrow>'b)\<Rightarrow>bool) f = P g) \<longrightarrow> (f x = g x)"
|
|
203 |
nitpick [expect = genuine]
|
|
204 |
oops
|
|
205 |
|
|
206 |
subsubsection {* Higher-Order Logic *}
|
|
207 |
|
|
208 |
lemma "\<exists>P. P"
|
|
209 |
nitpick [expect = none]
|
|
210 |
apply auto
|
|
211 |
done
|
|
212 |
|
|
213 |
lemma "\<forall>P. P"
|
|
214 |
nitpick [expect = genuine]
|
|
215 |
oops
|
|
216 |
|
|
217 |
lemma "\<exists>!P. P"
|
|
218 |
nitpick [expect = none]
|
|
219 |
apply auto
|
|
220 |
done
|
|
221 |
|
|
222 |
lemma "\<exists>!P. P x"
|
|
223 |
nitpick [expect = genuine]
|
|
224 |
oops
|
|
225 |
|
|
226 |
lemma "P Q \<or> Q x"
|
|
227 |
nitpick [expect = genuine]
|
|
228 |
oops
|
|
229 |
|
|
230 |
lemma "x \<noteq> All"
|
|
231 |
nitpick [expect = genuine]
|
|
232 |
oops
|
|
233 |
|
|
234 |
lemma "x \<noteq> Ex"
|
|
235 |
nitpick [expect = genuine]
|
|
236 |
oops
|
|
237 |
|
|
238 |
lemma "x \<noteq> Ex1"
|
|
239 |
nitpick [expect = genuine]
|
|
240 |
oops
|
|
241 |
|
|
242 |
text {* "The transitive closure 'T' of an arbitrary relation 'P' is non-empty." *}
|
|
243 |
|
|
244 |
constdefs
|
|
245 |
"trans" :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
|
|
246 |
"trans P \<equiv> (ALL x y z. P x y \<longrightarrow> P y z \<longrightarrow> P x z)"
|
|
247 |
"subset" :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
|
|
248 |
"subset P Q \<equiv> (ALL x y. P x y \<longrightarrow> Q x y)"
|
|
249 |
"trans_closure" :: "('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'a \<Rightarrow> bool) \<Rightarrow> bool"
|
|
250 |
"trans_closure P Q \<equiv> (subset Q P) \<and> (trans P) \<and> (ALL R. subset Q R \<longrightarrow> trans R \<longrightarrow> subset P R)"
|
|
251 |
|
|
252 |
lemma "trans_closure T P \<longrightarrow> (\<exists>x y. T x y)"
|
|
253 |
nitpick [expect = genuine]
|
|
254 |
oops
|
|
255 |
|
|
256 |
text {* "The union of transitive closures is equal to the transitive closure of unions." *}
|
|
257 |
|
|
258 |
lemma "(\<forall>x y. (P x y \<or> R x y) \<longrightarrow> T x y) \<longrightarrow> trans T \<longrightarrow> (\<forall>Q. (\<forall>x y. (P x y \<or> R x y) \<longrightarrow> Q x y) \<longrightarrow> trans Q \<longrightarrow> subset T Q)
|
|
259 |
\<longrightarrow> trans_closure TP P
|
|
260 |
\<longrightarrow> trans_closure TR R
|
|
261 |
\<longrightarrow> (T x y = (TP x y \<or> TR x y))"
|
|
262 |
nitpick [expect = genuine]
|
|
263 |
oops
|
|
264 |
|
|
265 |
text {* "Every surjective function is invertible." *}
|
|
266 |
|
|
267 |
lemma "(\<forall>y. \<exists>x. y = f x) \<longrightarrow> (\<exists>g. \<forall>x. g (f x) = x)"
|
|
268 |
nitpick [expect = genuine]
|
|
269 |
oops
|
|
270 |
|
|
271 |
text {* "Every invertible function is surjective." *}
|
|
272 |
|
|
273 |
lemma "(\<exists>g. \<forall>x. g (f x) = x) \<longrightarrow> (\<forall>y. \<exists>x. y = f x)"
|
|
274 |
nitpick [expect = genuine]
|
|
275 |
oops
|
|
276 |
|
|
277 |
text {* Every point is a fixed point of some function. *}
|
|
278 |
|
|
279 |
lemma "\<exists>f. f x = x"
|
|
280 |
nitpick [card = 1\<midarrow>7, expect = none]
|
|
281 |
apply (rule_tac x = "\<lambda>x. x" in exI)
|
|
282 |
apply simp
|
|
283 |
done
|
|
284 |
|
|
285 |
text {* Axiom of Choice: first an incorrect version ... *}
|
|
286 |
|
|
287 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>!f. \<forall>x. P x (f x))"
|
|
288 |
nitpick [expect = genuine]
|
|
289 |
oops
|
|
290 |
|
|
291 |
text {* ... and now two correct ones *}
|
|
292 |
|
|
293 |
lemma "(\<forall>x. \<exists>y. P x y) \<longrightarrow> (\<exists>f. \<forall>x. P x (f x))"
|
|
294 |
nitpick [card = 1-5, expect = none]
|
|
295 |
apply (simp add: choice)
|
|
296 |
done
|
|
297 |
|
|
298 |
lemma "(\<forall>x. \<exists>!y. P x y) \<longrightarrow> (\<exists>!f. \<forall>x. P x (f x))"
|
|
299 |
nitpick [card = 1-4, expect = none]
|
|
300 |
apply auto
|
|
301 |
apply (simp add: ex1_implies_ex choice)
|
|
302 |
apply (fast intro: ext)
|
|
303 |
done
|
|
304 |
|
|
305 |
subsubsection {* Metalogic *}
|
|
306 |
|
|
307 |
lemma "\<And>x. P x"
|
|
308 |
nitpick [expect = genuine]
|
|
309 |
oops
|
|
310 |
|
|
311 |
lemma "f x \<equiv> g x"
|
|
312 |
nitpick [expect = genuine]
|
|
313 |
oops
|
|
314 |
|
|
315 |
lemma "P \<Longrightarrow> Q"
|
|
316 |
nitpick [expect = genuine]
|
|
317 |
oops
|
|
318 |
|
|
319 |
lemma "\<lbrakk>P; Q; R\<rbrakk> \<Longrightarrow> S"
|
|
320 |
nitpick [expect = genuine]
|
|
321 |
oops
|
|
322 |
|
|
323 |
lemma "(x \<equiv> all) \<Longrightarrow> False"
|
|
324 |
nitpick [expect = genuine]
|
|
325 |
oops
|
|
326 |
|
|
327 |
lemma "(x \<equiv> (op \<equiv>)) \<Longrightarrow> False"
|
|
328 |
nitpick [expect = genuine]
|
|
329 |
oops
|
|
330 |
|
|
331 |
lemma "(x \<equiv> (op \<Longrightarrow>)) \<Longrightarrow> False"
|
|
332 |
nitpick [expect = genuine]
|
|
333 |
oops
|
|
334 |
|
|
335 |
subsubsection {* Schematic Variables *}
|
|
336 |
|
|
337 |
lemma "?P"
|
|
338 |
nitpick [expect = none]
|
|
339 |
apply auto
|
|
340 |
done
|
|
341 |
|
|
342 |
lemma "x = ?y"
|
|
343 |
nitpick [expect = none]
|
|
344 |
apply auto
|
|
345 |
done
|
|
346 |
|
|
347 |
subsubsection {* Abstractions *}
|
|
348 |
|
|
349 |
lemma "(\<lambda>x. x) = (\<lambda>x. y)"
|
|
350 |
nitpick [expect = genuine]
|
|
351 |
oops
|
|
352 |
|
|
353 |
lemma "(\<lambda>f. f x) = (\<lambda>f. True)"
|
|
354 |
nitpick [expect = genuine]
|
|
355 |
oops
|
|
356 |
|
|
357 |
lemma "(\<lambda>x. x) = (\<lambda>y. y)"
|
|
358 |
nitpick [expect = none]
|
|
359 |
apply simp
|
|
360 |
done
|
|
361 |
|
|
362 |
subsubsection {* Sets *}
|
|
363 |
|
|
364 |
lemma "P (A\<Colon>'a set)"
|
|
365 |
nitpick [expect = genuine]
|
|
366 |
oops
|
|
367 |
|
|
368 |
lemma "P (A\<Colon>'a set set)"
|
|
369 |
nitpick [expect = genuine]
|
|
370 |
oops
|
|
371 |
|
|
372 |
lemma "{x. P x} = {y. P y}"
|
|
373 |
nitpick [expect = none]
|
|
374 |
apply simp
|
|
375 |
done
|
|
376 |
|
|
377 |
lemma "x \<in> {x. P x}"
|
|
378 |
nitpick [expect = genuine]
|
|
379 |
oops
|
|
380 |
|
|
381 |
lemma "P (op \<in>)"
|
|
382 |
nitpick [expect = genuine]
|
|
383 |
oops
|
|
384 |
|
|
385 |
lemma "P (op \<in> x)"
|
|
386 |
nitpick [expect = genuine]
|
|
387 |
oops
|
|
388 |
|
|
389 |
lemma "P Collect"
|
|
390 |
nitpick [expect = genuine]
|
|
391 |
oops
|
|
392 |
|
|
393 |
lemma "A Un B = A Int B"
|
|
394 |
nitpick [expect = genuine]
|
|
395 |
oops
|
|
396 |
|
|
397 |
lemma "(A Int B) Un C = (A Un C) Int B"
|
|
398 |
nitpick [expect = genuine]
|
|
399 |
oops
|
|
400 |
|
|
401 |
lemma "Ball A P \<longrightarrow> Bex A P"
|
|
402 |
nitpick [expect = genuine]
|
|
403 |
oops
|
|
404 |
|
|
405 |
subsubsection {* @{const undefined} *}
|
|
406 |
|
|
407 |
lemma "undefined"
|
|
408 |
nitpick [expect = genuine]
|
|
409 |
oops
|
|
410 |
|
|
411 |
lemma "P undefined"
|
|
412 |
nitpick [expect = genuine]
|
|
413 |
oops
|
|
414 |
|
|
415 |
lemma "undefined x"
|
|
416 |
nitpick [expect = genuine]
|
|
417 |
oops
|
|
418 |
|
|
419 |
lemma "undefined undefined"
|
|
420 |
nitpick [expect = genuine]
|
|
421 |
oops
|
|
422 |
|
|
423 |
subsubsection {* @{const The} *}
|
|
424 |
|
|
425 |
lemma "The P"
|
|
426 |
nitpick [expect = genuine]
|
|
427 |
oops
|
|
428 |
|
|
429 |
lemma "P The"
|
|
430 |
nitpick [expect = genuine]
|
|
431 |
oops
|
|
432 |
|
|
433 |
lemma "P (The P)"
|
|
434 |
nitpick [expect = genuine]
|
|
435 |
oops
|
|
436 |
|
|
437 |
lemma "(THE x. x=y) = z"
|
|
438 |
nitpick [expect = genuine]
|
|
439 |
oops
|
|
440 |
|
|
441 |
lemma "Ex P \<longrightarrow> P (The P)"
|
|
442 |
nitpick [expect = genuine]
|
|
443 |
oops
|
|
444 |
|
|
445 |
subsubsection {* @{const Eps} *}
|
|
446 |
|
|
447 |
lemma "Eps P"
|
|
448 |
nitpick [expect = genuine]
|
|
449 |
oops
|
|
450 |
|
|
451 |
lemma "P Eps"
|
|
452 |
nitpick [expect = genuine]
|
|
453 |
oops
|
|
454 |
|
|
455 |
lemma "P (Eps P)"
|
|
456 |
nitpick [expect = genuine]
|
|
457 |
oops
|
|
458 |
|
|
459 |
lemma "(SOME x. x=y) = z"
|
|
460 |
nitpick [expect = genuine]
|
|
461 |
oops
|
|
462 |
|
|
463 |
lemma "Ex P \<longrightarrow> P (Eps P)"
|
|
464 |
nitpick [expect = none]
|
|
465 |
apply (auto simp add: someI)
|
|
466 |
done
|
|
467 |
|
|
468 |
subsubsection {* Operations on Natural Numbers *}
|
|
469 |
|
|
470 |
lemma "(x\<Colon>nat) + y = 0"
|
|
471 |
nitpick [expect = genuine]
|
|
472 |
oops
|
|
473 |
|
|
474 |
lemma "(x\<Colon>nat) = x + x"
|
|
475 |
nitpick [expect = genuine]
|
|
476 |
oops
|
|
477 |
|
|
478 |
lemma "(x\<Colon>nat) - y + y = x"
|
|
479 |
nitpick [expect = genuine]
|
|
480 |
oops
|
|
481 |
|
|
482 |
lemma "(x\<Colon>nat) = x * x"
|
|
483 |
nitpick [expect = genuine]
|
|
484 |
oops
|
|
485 |
|
|
486 |
lemma "(x\<Colon>nat) < x + y"
|
|
487 |
nitpick [card = 1, expect = genuine]
|
|
488 |
nitpick [card = 2-5, expect = genuine]
|
|
489 |
oops
|
|
490 |
|
|
491 |
text {* \<times> *}
|
|
492 |
|
|
493 |
lemma "P (x\<Colon>'a\<times>'b)"
|
|
494 |
nitpick [expect = genuine]
|
|
495 |
oops
|
|
496 |
|
|
497 |
lemma "\<forall>x\<Colon>'a\<times>'b. P x"
|
|
498 |
nitpick [expect = genuine]
|
|
499 |
oops
|
|
500 |
|
|
501 |
lemma "P (x, y)"
|
|
502 |
nitpick [expect = genuine]
|
|
503 |
oops
|
|
504 |
|
|
505 |
lemma "P (fst x)"
|
|
506 |
nitpick [expect = genuine]
|
|
507 |
oops
|
|
508 |
|
|
509 |
lemma "P (snd x)"
|
|
510 |
nitpick [expect = genuine]
|
|
511 |
oops
|
|
512 |
|
|
513 |
lemma "P Pair"
|
|
514 |
nitpick [expect = genuine]
|
|
515 |
oops
|
|
516 |
|
|
517 |
lemma "prod_rec f p = f (fst p) (snd p)"
|
|
518 |
nitpick [expect = none]
|
|
519 |
by (case_tac p) auto
|
|
520 |
|
|
521 |
lemma "prod_rec f (a, b) = f a b"
|
|
522 |
nitpick [expect = none]
|
|
523 |
by auto
|
|
524 |
|
|
525 |
lemma "P (prod_rec f x)"
|
|
526 |
nitpick [expect = genuine]
|
|
527 |
oops
|
|
528 |
|
|
529 |
lemma "P (case x of Pair a b \<Rightarrow> f a b)"
|
|
530 |
nitpick [expect = genuine]
|
|
531 |
oops
|
|
532 |
|
|
533 |
subsubsection {* Subtypes (typedef), typedecl *}
|
|
534 |
|
|
535 |
text {* A completely unspecified non-empty subset of @{typ "'a"}: *}
|
|
536 |
|
|
537 |
typedef 'a myTdef = "insert (undefined\<Colon>'a) (undefined\<Colon>'a set)"
|
|
538 |
by auto
|
|
539 |
|
|
540 |
lemma "(x\<Colon>'a myTdef) = y"
|
|
541 |
nitpick [expect = genuine]
|
|
542 |
oops
|
|
543 |
|
|
544 |
typedecl myTdecl
|
|
545 |
|
|
546 |
typedef 'a T_bij = "{(f\<Colon>'a\<Rightarrow>'a). \<forall>y. \<exists>!x. f x = y}"
|
|
547 |
by auto
|
|
548 |
|
|
549 |
lemma "P (f\<Colon>(myTdecl myTdef) T_bij)"
|
|
550 |
nitpick [expect = genuine]
|
|
551 |
oops
|
|
552 |
|
|
553 |
subsubsection {* Inductive Datatypes *}
|
|
554 |
|
|
555 |
text {* unit *}
|
|
556 |
|
|
557 |
lemma "P (x\<Colon>unit)"
|
|
558 |
nitpick [expect = genuine]
|
|
559 |
oops
|
|
560 |
|
|
561 |
lemma "\<forall>x\<Colon>unit. P x"
|
|
562 |
nitpick [expect = genuine]
|
|
563 |
oops
|
|
564 |
|
|
565 |
lemma "P ()"
|
|
566 |
nitpick [expect = genuine]
|
|
567 |
oops
|
|
568 |
|
|
569 |
lemma "unit_rec u x = u"
|
|
570 |
nitpick [expect = none]
|
|
571 |
apply simp
|
|
572 |
done
|
|
573 |
|
|
574 |
lemma "P (unit_rec u x)"
|
|
575 |
nitpick [expect = genuine]
|
|
576 |
oops
|
|
577 |
|
|
578 |
lemma "P (case x of () \<Rightarrow> u)"
|
|
579 |
nitpick [expect = genuine]
|
|
580 |
oops
|
|
581 |
|
|
582 |
text {* option *}
|
|
583 |
|
|
584 |
lemma "P (x\<Colon>'a option)"
|
|
585 |
nitpick [expect = genuine]
|
|
586 |
oops
|
|
587 |
|
|
588 |
lemma "\<forall>x\<Colon>'a option. P x"
|
|
589 |
nitpick [expect = genuine]
|
|
590 |
oops
|
|
591 |
|
|
592 |
lemma "P None"
|
|
593 |
nitpick [expect = genuine]
|
|
594 |
oops
|
|
595 |
|
|
596 |
lemma "P (Some x)"
|
|
597 |
nitpick [expect = genuine]
|
|
598 |
oops
|
|
599 |
|
|
600 |
lemma "option_rec n s None = n"
|
|
601 |
nitpick [expect = none]
|
|
602 |
apply simp
|
|
603 |
done
|
|
604 |
|
|
605 |
lemma "option_rec n s (Some x) = s x"
|
|
606 |
nitpick [expect = none]
|
|
607 |
apply simp
|
|
608 |
done
|
|
609 |
|
|
610 |
lemma "P (option_rec n s x)"
|
|
611 |
nitpick [expect = genuine]
|
|
612 |
oops
|
|
613 |
|
|
614 |
lemma "P (case x of None \<Rightarrow> n | Some u \<Rightarrow> s u)"
|
|
615 |
nitpick [expect = genuine]
|
|
616 |
oops
|
|
617 |
|
|
618 |
text {* + *}
|
|
619 |
|
|
620 |
lemma "P (x\<Colon>'a+'b)"
|
|
621 |
nitpick [expect = genuine]
|
|
622 |
oops
|
|
623 |
|
|
624 |
lemma "\<forall>x\<Colon>'a+'b. P x"
|
|
625 |
nitpick [expect = genuine]
|
|
626 |
oops
|
|
627 |
|
|
628 |
lemma "P (Inl x)"
|
|
629 |
nitpick [expect = genuine]
|
|
630 |
oops
|
|
631 |
|
|
632 |
lemma "P (Inr x)"
|
|
633 |
nitpick [expect = genuine]
|
|
634 |
oops
|
|
635 |
|
|
636 |
lemma "P Inl"
|
|
637 |
nitpick [expect = genuine]
|
|
638 |
oops
|
|
639 |
|
|
640 |
lemma "sum_rec l r (Inl x) = l x"
|
|
641 |
nitpick [expect = none]
|
|
642 |
apply simp
|
|
643 |
done
|
|
644 |
|
|
645 |
lemma "sum_rec l r (Inr x) = r x"
|
|
646 |
nitpick [expect = none]
|
|
647 |
apply simp
|
|
648 |
done
|
|
649 |
|
|
650 |
lemma "P (sum_rec l r x)"
|
|
651 |
nitpick [expect = genuine]
|
|
652 |
oops
|
|
653 |
|
|
654 |
lemma "P (case x of Inl a \<Rightarrow> l a | Inr b \<Rightarrow> r b)"
|
|
655 |
nitpick [expect = genuine]
|
|
656 |
oops
|
|
657 |
|
|
658 |
text {* Non-recursive datatypes *}
|
|
659 |
|
|
660 |
datatype T1 = A | B
|
|
661 |
|
|
662 |
lemma "P (x\<Colon>T1)"
|
|
663 |
nitpick [expect = genuine]
|
|
664 |
oops
|
|
665 |
|
|
666 |
lemma "\<forall>x\<Colon>T1. P x"
|
|
667 |
nitpick [expect = genuine]
|
|
668 |
oops
|
|
669 |
|
|
670 |
lemma "P A"
|
|
671 |
nitpick [expect = genuine]
|
|
672 |
oops
|
|
673 |
|
|
674 |
lemma "P B"
|
|
675 |
nitpick [expect = genuine]
|
|
676 |
oops
|
|
677 |
|
|
678 |
lemma "T1_rec a b A = a"
|
|
679 |
nitpick [expect = none]
|
|
680 |
apply simp
|
|
681 |
done
|
|
682 |
|
|
683 |
lemma "T1_rec a b B = b"
|
|
684 |
nitpick [expect = none]
|
|
685 |
apply simp
|
|
686 |
done
|
|
687 |
|
|
688 |
lemma "P (T1_rec a b x)"
|
|
689 |
nitpick [expect = genuine]
|
|
690 |
oops
|
|
691 |
|
|
692 |
lemma "P (case x of A \<Rightarrow> a | B \<Rightarrow> b)"
|
|
693 |
nitpick [expect = genuine]
|
|
694 |
oops
|
|
695 |
|
|
696 |
datatype 'a T2 = C T1 | D 'a
|
|
697 |
|
|
698 |
lemma "P (x\<Colon>'a T2)"
|
|
699 |
nitpick [expect = genuine]
|
|
700 |
oops
|
|
701 |
|
|
702 |
lemma "\<forall>x\<Colon>'a T2. P x"
|
|
703 |
nitpick [expect = genuine]
|
|
704 |
oops
|
|
705 |
|
|
706 |
lemma "P D"
|
|
707 |
nitpick [expect = genuine]
|
|
708 |
oops
|
|
709 |
|
|
710 |
lemma "T2_rec c d (C x) = c x"
|
|
711 |
nitpick [expect = none]
|
|
712 |
apply simp
|
|
713 |
done
|
|
714 |
|
|
715 |
lemma "T2_rec c d (D x) = d x"
|
|
716 |
nitpick [expect = none]
|
|
717 |
apply simp
|
|
718 |
done
|
|
719 |
|
|
720 |
lemma "P (T2_rec c d x)"
|
|
721 |
nitpick [expect = genuine]
|
|
722 |
oops
|
|
723 |
|
|
724 |
lemma "P (case x of C u \<Rightarrow> c u | D v \<Rightarrow> d v)"
|
|
725 |
nitpick [expect = genuine]
|
|
726 |
oops
|
|
727 |
|
|
728 |
datatype ('a, 'b) T3 = E "'a \<Rightarrow> 'b"
|
|
729 |
|
|
730 |
lemma "P (x\<Colon>('a, 'b) T3)"
|
|
731 |
nitpick [expect = genuine]
|
|
732 |
oops
|
|
733 |
|
|
734 |
lemma "\<forall>x\<Colon>('a, 'b) T3. P x"
|
|
735 |
nitpick [expect = genuine]
|
|
736 |
oops
|
|
737 |
|
|
738 |
lemma "P E"
|
|
739 |
nitpick [expect = genuine]
|
|
740 |
oops
|
|
741 |
|
|
742 |
lemma "T3_rec e (E x) = e x"
|
|
743 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
744 |
apply simp
|
|
745 |
done
|
|
746 |
|
|
747 |
lemma "P (T3_rec e x)"
|
|
748 |
nitpick [expect = genuine]
|
|
749 |
oops
|
|
750 |
|
|
751 |
lemma "P (case x of E f \<Rightarrow> e f)"
|
|
752 |
nitpick [expect = genuine]
|
|
753 |
oops
|
|
754 |
|
|
755 |
text {* Recursive datatypes *}
|
|
756 |
|
|
757 |
text {* nat *}
|
|
758 |
|
|
759 |
lemma "P (x\<Colon>nat)"
|
|
760 |
nitpick [expect = genuine]
|
|
761 |
oops
|
|
762 |
|
|
763 |
lemma "\<forall>x\<Colon>nat. P x"
|
|
764 |
nitpick [expect = genuine]
|
|
765 |
oops
|
|
766 |
|
|
767 |
lemma "P (Suc 0)"
|
|
768 |
nitpick [expect = genuine]
|
|
769 |
oops
|
|
770 |
|
|
771 |
lemma "P Suc"
|
|
772 |
nitpick [card = 1\<midarrow>7, expect = none]
|
|
773 |
oops
|
|
774 |
|
|
775 |
lemma "nat_rec zero suc 0 = zero"
|
|
776 |
nitpick [expect = none]
|
|
777 |
apply simp
|
|
778 |
done
|
|
779 |
|
|
780 |
lemma "nat_rec zero suc (Suc x) = suc x (nat_rec zero suc x)"
|
|
781 |
nitpick [expect = none]
|
|
782 |
apply simp
|
|
783 |
done
|
|
784 |
|
|
785 |
lemma "P (nat_rec zero suc x)"
|
|
786 |
nitpick [expect = genuine]
|
|
787 |
oops
|
|
788 |
|
|
789 |
lemma "P (case x of 0 \<Rightarrow> zero | Suc n \<Rightarrow> suc n)"
|
|
790 |
nitpick [expect = genuine]
|
|
791 |
oops
|
|
792 |
|
|
793 |
text {* 'a list *}
|
|
794 |
|
|
795 |
lemma "P (xs\<Colon>'a list)"
|
|
796 |
nitpick [expect = genuine]
|
|
797 |
oops
|
|
798 |
|
|
799 |
lemma "\<forall>xs\<Colon>'a list. P xs"
|
|
800 |
nitpick [expect = genuine]
|
|
801 |
oops
|
|
802 |
|
|
803 |
lemma "P [x, y]"
|
|
804 |
nitpick [expect = genuine]
|
|
805 |
oops
|
|
806 |
|
|
807 |
lemma "list_rec nil cons [] = nil"
|
|
808 |
nitpick [expect = none]
|
|
809 |
apply simp
|
|
810 |
done
|
|
811 |
|
|
812 |
lemma "list_rec nil cons (x#xs) = cons x xs (list_rec nil cons xs)"
|
|
813 |
nitpick [expect = none]
|
|
814 |
apply simp
|
|
815 |
done
|
|
816 |
|
|
817 |
lemma "P (list_rec nil cons xs)"
|
|
818 |
nitpick [expect = genuine]
|
|
819 |
oops
|
|
820 |
|
|
821 |
lemma "P (case x of Nil \<Rightarrow> nil | Cons a b \<Rightarrow> cons a b)"
|
|
822 |
nitpick [expect = genuine]
|
|
823 |
oops
|
|
824 |
|
|
825 |
lemma "(xs\<Colon>'a list) = ys"
|
|
826 |
nitpick [expect = genuine]
|
|
827 |
oops
|
|
828 |
|
|
829 |
lemma "a # xs = b # xs"
|
|
830 |
nitpick [expect = genuine]
|
|
831 |
oops
|
|
832 |
|
|
833 |
datatype BitList = BitListNil | Bit0 BitList | Bit1 BitList
|
|
834 |
|
|
835 |
lemma "P (x\<Colon>BitList)"
|
|
836 |
nitpick [expect = genuine]
|
|
837 |
oops
|
|
838 |
|
|
839 |
lemma "\<forall>x\<Colon>BitList. P x"
|
|
840 |
nitpick [expect = genuine]
|
|
841 |
oops
|
|
842 |
|
|
843 |
lemma "P (Bit0 (Bit1 BitListNil))"
|
|
844 |
nitpick [expect = genuine]
|
|
845 |
oops
|
|
846 |
|
|
847 |
lemma "BitList_rec nil bit0 bit1 BitListNil = nil"
|
|
848 |
nitpick [expect = none]
|
|
849 |
apply simp
|
|
850 |
done
|
|
851 |
|
|
852 |
lemma "BitList_rec nil bit0 bit1 (Bit0 xs) = bit0 xs (BitList_rec nil bit0 bit1 xs)"
|
|
853 |
nitpick [expect = none]
|
|
854 |
apply simp
|
|
855 |
done
|
|
856 |
|
|
857 |
lemma "BitList_rec nil bit0 bit1 (Bit1 xs) = bit1 xs (BitList_rec nil bit0 bit1 xs)"
|
|
858 |
nitpick [expect = none]
|
|
859 |
apply simp
|
|
860 |
done
|
|
861 |
|
|
862 |
lemma "P (BitList_rec nil bit0 bit1 x)"
|
|
863 |
nitpick [expect = genuine]
|
|
864 |
oops
|
|
865 |
|
|
866 |
datatype 'a BinTree = Leaf 'a | Node "'a BinTree" "'a BinTree"
|
|
867 |
|
|
868 |
lemma "P (x\<Colon>'a BinTree)"
|
|
869 |
nitpick [expect = genuine]
|
|
870 |
oops
|
|
871 |
|
|
872 |
lemma "\<forall>x\<Colon>'a BinTree. P x"
|
|
873 |
nitpick [expect = genuine]
|
|
874 |
oops
|
|
875 |
|
|
876 |
lemma "P (Node (Leaf x) (Leaf y))"
|
|
877 |
nitpick [expect = genuine]
|
|
878 |
oops
|
|
879 |
|
|
880 |
lemma "BinTree_rec l n (Leaf x) = l x"
|
|
881 |
nitpick [expect = none]
|
|
882 |
apply simp
|
|
883 |
done
|
|
884 |
|
|
885 |
lemma "BinTree_rec l n (Node x y) = n x y (BinTree_rec l n x) (BinTree_rec l n y)"
|
|
886 |
nitpick [card = 1\<midarrow>6, expect = none]
|
|
887 |
apply simp
|
|
888 |
done
|
|
889 |
|
|
890 |
lemma "P (BinTree_rec l n x)"
|
|
891 |
nitpick [expect = genuine]
|
|
892 |
oops
|
|
893 |
|
|
894 |
lemma "P (case x of Leaf a \<Rightarrow> l a | Node a b \<Rightarrow> n a b)"
|
|
895 |
nitpick [expect = genuine]
|
|
896 |
oops
|
|
897 |
|
|
898 |
text {* Mutually recursive datatypes *}
|
|
899 |
|
|
900 |
datatype 'a aexp = Number 'a | ITE "'a bexp" "'a aexp" "'a aexp"
|
|
901 |
and 'a bexp = Equal "'a aexp" "'a aexp"
|
|
902 |
|
|
903 |
lemma "P (x\<Colon>'a aexp)"
|
|
904 |
nitpick [expect = genuine]
|
|
905 |
oops
|
|
906 |
|
|
907 |
lemma "\<forall>x\<Colon>'a aexp. P x"
|
|
908 |
nitpick [expect = genuine]
|
|
909 |
oops
|
|
910 |
|
|
911 |
lemma "P (ITE (Equal (Number x) (Number y)) (Number x) (Number y))"
|
|
912 |
nitpick [expect = genuine]
|
|
913 |
oops
|
|
914 |
|
|
915 |
lemma "P (x\<Colon>'a bexp)"
|
|
916 |
nitpick [expect = genuine]
|
|
917 |
oops
|
|
918 |
|
|
919 |
lemma "\<forall>x\<Colon>'a bexp. P x"
|
|
920 |
nitpick [expect = genuine]
|
|
921 |
oops
|
|
922 |
|
|
923 |
lemma "aexp_bexp_rec_1 number ite equal (Number x) = number x"
|
|
924 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
925 |
apply simp
|
|
926 |
done
|
|
927 |
|
|
928 |
lemma "aexp_bexp_rec_1 number ite equal (ITE x y z) = ite x y z (aexp_bexp_rec_2 number ite equal x) (aexp_bexp_rec_1 number ite equal y) (aexp_bexp_rec_1 number ite equal z)"
|
|
929 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
930 |
apply simp
|
|
931 |
done
|
|
932 |
|
|
933 |
lemma "P (aexp_bexp_rec_1 number ite equal x)"
|
|
934 |
nitpick [expect = genuine]
|
|
935 |
oops
|
|
936 |
|
|
937 |
lemma "P (case x of Number a \<Rightarrow> number a | ITE b a1 a2 \<Rightarrow> ite b a1 a2)"
|
|
938 |
nitpick [expect = genuine]
|
|
939 |
oops
|
|
940 |
|
|
941 |
lemma "aexp_bexp_rec_2 number ite equal (Equal x y) = equal x y (aexp_bexp_rec_1 number ite equal x) (aexp_bexp_rec_1 number ite equal y)"
|
|
942 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
943 |
apply simp
|
|
944 |
done
|
|
945 |
|
|
946 |
lemma "P (aexp_bexp_rec_2 number ite equal x)"
|
|
947 |
nitpick [expect = genuine]
|
|
948 |
oops
|
|
949 |
|
|
950 |
lemma "P (case x of Equal a1 a2 \<Rightarrow> equal a1 a2)"
|
|
951 |
nitpick [expect = genuine]
|
|
952 |
oops
|
|
953 |
|
|
954 |
datatype X = A | B X | C Y
|
|
955 |
and Y = D X | E Y | F
|
|
956 |
|
|
957 |
lemma "P (x\<Colon>X)"
|
|
958 |
nitpick [expect = genuine]
|
|
959 |
oops
|
|
960 |
|
|
961 |
lemma "P (y\<Colon>Y)"
|
|
962 |
nitpick [expect = genuine]
|
|
963 |
oops
|
|
964 |
|
|
965 |
lemma "P (B (B A))"
|
|
966 |
nitpick [expect = genuine]
|
|
967 |
oops
|
|
968 |
|
|
969 |
lemma "P (B (C F))"
|
|
970 |
nitpick [expect = genuine]
|
|
971 |
oops
|
|
972 |
|
|
973 |
lemma "P (C (D A))"
|
|
974 |
nitpick [expect = genuine]
|
|
975 |
oops
|
|
976 |
|
|
977 |
lemma "P (C (E F))"
|
|
978 |
nitpick [expect = genuine]
|
|
979 |
oops
|
|
980 |
|
|
981 |
lemma "P (D (B A))"
|
|
982 |
nitpick [expect = genuine]
|
|
983 |
oops
|
|
984 |
|
|
985 |
lemma "P (D (C F))"
|
|
986 |
nitpick [expect = genuine]
|
|
987 |
oops
|
|
988 |
|
|
989 |
lemma "P (E (D A))"
|
|
990 |
nitpick [expect = genuine]
|
|
991 |
oops
|
|
992 |
|
|
993 |
lemma "P (E (E F))"
|
|
994 |
nitpick [expect = genuine]
|
|
995 |
oops
|
|
996 |
|
|
997 |
lemma "P (C (D (C F)))"
|
|
998 |
nitpick [expect = genuine]
|
|
999 |
oops
|
|
1000 |
|
|
1001 |
lemma "X_Y_rec_1 a b c d e f A = a"
|
|
1002 |
nitpick [expect = none]
|
|
1003 |
apply simp
|
|
1004 |
done
|
|
1005 |
|
|
1006 |
lemma "X_Y_rec_1 a b c d e f (B x) = b x (X_Y_rec_1 a b c d e f x)"
|
|
1007 |
nitpick [expect = none]
|
|
1008 |
apply simp
|
|
1009 |
done
|
|
1010 |
|
|
1011 |
lemma "X_Y_rec_1 a b c d e f (C y) = c y (X_Y_rec_2 a b c d e f y)"
|
|
1012 |
nitpick [expect = none]
|
|
1013 |
apply simp
|
|
1014 |
done
|
|
1015 |
|
|
1016 |
lemma "X_Y_rec_2 a b c d e f (D x) = d x (X_Y_rec_1 a b c d e f x)"
|
|
1017 |
nitpick [expect = none]
|
|
1018 |
apply simp
|
|
1019 |
done
|
|
1020 |
|
|
1021 |
lemma "X_Y_rec_2 a b c d e f (E y) = e y (X_Y_rec_2 a b c d e f y)"
|
|
1022 |
nitpick [expect = none]
|
|
1023 |
apply simp
|
|
1024 |
done
|
|
1025 |
|
|
1026 |
lemma "X_Y_rec_2 a b c d e f F = f"
|
|
1027 |
nitpick [expect = none]
|
|
1028 |
apply simp
|
|
1029 |
done
|
|
1030 |
|
|
1031 |
lemma "P (X_Y_rec_1 a b c d e f x)"
|
|
1032 |
nitpick [expect = genuine]
|
|
1033 |
oops
|
|
1034 |
|
|
1035 |
lemma "P (X_Y_rec_2 a b c d e f y)"
|
|
1036 |
nitpick [expect = genuine]
|
|
1037 |
oops
|
|
1038 |
|
|
1039 |
text {* Other datatype examples *}
|
|
1040 |
|
|
1041 |
text {* Indirect recursion is implemented via mutual recursion. *}
|
|
1042 |
|
|
1043 |
datatype XOpt = CX "XOpt option" | DX "bool \<Rightarrow> XOpt option"
|
|
1044 |
|
|
1045 |
lemma "P (x\<Colon>XOpt)"
|
|
1046 |
nitpick [expect = genuine]
|
|
1047 |
oops
|
|
1048 |
|
|
1049 |
lemma "P (CX None)"
|
|
1050 |
nitpick [expect = genuine]
|
|
1051 |
oops
|
|
1052 |
|
|
1053 |
lemma "P (CX (Some (CX None)))"
|
|
1054 |
nitpick [expect = genuine]
|
|
1055 |
oops
|
|
1056 |
|
|
1057 |
lemma "XOpt_rec_1 cx dx n1 s1 n2 s2 (CX x) = cx x (XOpt_rec_2 cx dx n1 s1 n2 s2 x)"
|
|
1058 |
nitpick [card = 1\<midarrow>6, expect = none]
|
|
1059 |
apply simp
|
|
1060 |
done
|
|
1061 |
|
|
1062 |
lemma "XOpt_rec_1 cx dx n1 s1 n2 s2 (DX x) = dx x (\<lambda>b. XOpt_rec_3 cx dx n1 s1 n2 s2 (x b))"
|
|
1063 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
1064 |
apply simp
|
|
1065 |
done
|
|
1066 |
|
|
1067 |
lemma "XOpt_rec_2 cx dx n1 s1 n2 s2 None = n1"
|
|
1068 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
1069 |
apply simp
|
|
1070 |
done
|
|
1071 |
|
|
1072 |
lemma "XOpt_rec_2 cx dx n1 s1 n2 s2 (Some x) = s1 x (XOpt_rec_1 cx dx n1 s1 n2 s2 x)"
|
|
1073 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
1074 |
apply simp
|
|
1075 |
done
|
|
1076 |
|
|
1077 |
lemma "XOpt_rec_3 cx dx n1 s1 n2 s2 None = n2"
|
|
1078 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
1079 |
apply simp
|
|
1080 |
done
|
|
1081 |
|
|
1082 |
lemma "XOpt_rec_3 cx dx n1 s1 n2 s2 (Some x) = s2 x (XOpt_rec_1 cx dx n1 s1 n2 s2 x)"
|
|
1083 |
nitpick [card = 1\<midarrow>4, expect = none]
|
|
1084 |
apply simp
|
|
1085 |
done
|
|
1086 |
|
|
1087 |
lemma "P (XOpt_rec_1 cx dx n1 s1 n2 s2 x)"
|
|
1088 |
nitpick [expect = genuine]
|
|
1089 |
oops
|
|
1090 |
|
|
1091 |
lemma "P (XOpt_rec_2 cx dx n1 s1 n2 s2 x)"
|
|
1092 |
nitpick [expect = genuine]
|
|
1093 |
oops
|
|
1094 |
|
|
1095 |
lemma "P (XOpt_rec_3 cx dx n1 s1 n2 s2 x)"
|
|
1096 |
nitpick [expect = genuine]
|
|
1097 |
oops
|
|
1098 |
|
|
1099 |
datatype 'a YOpt = CY "('a \<Rightarrow> 'a YOpt) option"
|
|
1100 |
|
|
1101 |
lemma "P (x\<Colon>'a YOpt)"
|
|
1102 |
nitpick [expect = genuine]
|
|
1103 |
oops
|
|
1104 |
|
|
1105 |
lemma "P (CY None)"
|
|
1106 |
nitpick [expect = genuine]
|
|
1107 |
oops
|
|
1108 |
|
|
1109 |
lemma "P (CY (Some (\<lambda>a. CY None)))"
|
|
1110 |
nitpick [expect = genuine]
|
|
1111 |
oops
|
|
1112 |
|
|
1113 |
lemma "YOpt_rec_1 cy n s (CY x) = cy x (YOpt_rec_2 cy n s x)"
|
|
1114 |
nitpick [card = 1\<midarrow>2, expect = none]
|
|
1115 |
apply simp
|
|
1116 |
done
|
|
1117 |
|
|
1118 |
lemma "YOpt_rec_2 cy n s None = n"
|
|
1119 |
nitpick [card = 1\<midarrow>2, expect = none]
|
|
1120 |
apply simp
|
|
1121 |
done
|
|
1122 |
|
|
1123 |
lemma "YOpt_rec_2 cy n s (Some x) = s x (\<lambda>a. YOpt_rec_1 cy n s (x a))"
|
|
1124 |
nitpick [card = 1\<midarrow>2, expect = none]
|
|
1125 |
apply simp
|
|
1126 |
done
|
|
1127 |
|
|
1128 |
lemma "P (YOpt_rec_1 cy n s x)"
|
|
1129 |
nitpick [expect = genuine]
|
|
1130 |
oops
|
|
1131 |
|
|
1132 |
lemma "P (YOpt_rec_2 cy n s x)"
|
|
1133 |
nitpick [expect = genuine]
|
|
1134 |
oops
|
|
1135 |
|
|
1136 |
datatype Trie = TR "Trie list"
|
|
1137 |
|
|
1138 |
lemma "P (x\<Colon>Trie)"
|
|
1139 |
nitpick [expect = genuine]
|
|
1140 |
oops
|
|
1141 |
|
|
1142 |
lemma "\<forall>x\<Colon>Trie. P x"
|
|
1143 |
nitpick [expect = genuine]
|
|
1144 |
oops
|
|
1145 |
|
|
1146 |
lemma "P (TR [TR []])"
|
|
1147 |
nitpick [expect = genuine]
|
|
1148 |
oops
|
|
1149 |
|
|
1150 |
lemma "Trie_rec_1 tr nil cons (TR x) = tr x (Trie_rec_2 tr nil cons x)"
|
|
1151 |
nitpick [card = 1\<midarrow>6, expect = none]
|
|
1152 |
apply simp
|
|
1153 |
done
|
|
1154 |
|
|
1155 |
lemma "Trie_rec_2 tr nil cons [] = nil"
|
|
1156 |
nitpick [card = 1\<midarrow>6, expect = none]
|
|
1157 |
apply simp
|
|
1158 |
done
|
|
1159 |
|
|
1160 |
lemma "Trie_rec_2 tr nil cons (x#xs) = cons x xs (Trie_rec_1 tr nil cons x) (Trie_rec_2 tr nil cons xs)"
|
|
1161 |
nitpick [card = 1\<midarrow>6, expect = none]
|
|
1162 |
apply simp
|
|
1163 |
done
|
|
1164 |
|
|
1165 |
lemma "P (Trie_rec_1 tr nil cons x)"
|
|
1166 |
nitpick [card = 1, expect = genuine]
|
|
1167 |
oops
|
|
1168 |
|
|
1169 |
lemma "P (Trie_rec_2 tr nil cons x)"
|
|
1170 |
nitpick [card = 1, expect = genuine]
|
|
1171 |
oops
|
|
1172 |
|
|
1173 |
datatype InfTree = Leaf | Node "nat \<Rightarrow> InfTree"
|
|
1174 |
|
|
1175 |
lemma "P (x\<Colon>InfTree)"
|
|
1176 |
nitpick [expect = genuine]
|
|
1177 |
oops
|
|
1178 |
|
|
1179 |
lemma "\<forall>x\<Colon>InfTree. P x"
|
|
1180 |
nitpick [expect = genuine]
|
|
1181 |
oops
|
|
1182 |
|
|
1183 |
lemma "P (Node (\<lambda>n. Leaf))"
|
|
1184 |
nitpick [expect = genuine]
|
|
1185 |
oops
|
|
1186 |
|
|
1187 |
lemma "InfTree_rec leaf node Leaf = leaf"
|
|
1188 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1189 |
apply simp
|
|
1190 |
done
|
|
1191 |
|
|
1192 |
lemma "InfTree_rec leaf node (Node x) = node x (\<lambda>n. InfTree_rec leaf node (x n))"
|
|
1193 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1194 |
apply simp
|
|
1195 |
done
|
|
1196 |
|
|
1197 |
lemma "P (InfTree_rec leaf node x)"
|
|
1198 |
nitpick [expect = genuine]
|
|
1199 |
oops
|
|
1200 |
|
|
1201 |
datatype 'a lambda = Var 'a | App "'a lambda" "'a lambda" | Lam "'a \<Rightarrow> 'a lambda"
|
|
1202 |
|
|
1203 |
lemma "P (x\<Colon>'a lambda)"
|
|
1204 |
nitpick [expect = genuine]
|
|
1205 |
oops
|
|
1206 |
|
|
1207 |
lemma "\<forall>x\<Colon>'a lambda. P x"
|
|
1208 |
nitpick [expect = genuine]
|
|
1209 |
oops
|
|
1210 |
|
|
1211 |
lemma "P (Lam (\<lambda>a. Var a))"
|
|
1212 |
nitpick [card = 1\<midarrow>5, expect = none]
|
|
1213 |
nitpick [card 'a = 4, card "'a lambda" = 5, expect = genuine]
|
|
1214 |
oops
|
|
1215 |
|
|
1216 |
lemma "lambda_rec var app lam (Var x) = var x"
|
|
1217 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1218 |
apply simp
|
|
1219 |
done
|
|
1220 |
|
|
1221 |
lemma "lambda_rec var app lam (App x y) = app x y (lambda_rec var app lam x) (lambda_rec var app lam y)"
|
|
1222 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1223 |
apply simp
|
|
1224 |
done
|
|
1225 |
|
|
1226 |
lemma "lambda_rec var app lam (Lam x) = lam x (\<lambda>a. lambda_rec var app lam (x a))"
|
|
1227 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1228 |
apply simp
|
|
1229 |
done
|
|
1230 |
|
|
1231 |
lemma "P (lambda_rec v a l x)"
|
|
1232 |
nitpick [expect = genuine]
|
|
1233 |
oops
|
|
1234 |
|
|
1235 |
text {* Taken from "Inductive datatypes in HOL", p. 8: *}
|
|
1236 |
|
|
1237 |
datatype ('a, 'b) T = C "'a \<Rightarrow> bool" | D "'b list"
|
|
1238 |
datatype 'c U = E "('c, 'c U) T"
|
|
1239 |
|
|
1240 |
lemma "P (x\<Colon>'c U)"
|
|
1241 |
nitpick [expect = genuine]
|
|
1242 |
oops
|
|
1243 |
|
|
1244 |
lemma "\<forall>x\<Colon>'c U. P x"
|
|
1245 |
nitpick [expect = genuine]
|
|
1246 |
oops
|
|
1247 |
|
|
1248 |
lemma "P (E (C (\<lambda>a. True)))"
|
|
1249 |
nitpick [expect = genuine]
|
|
1250 |
oops
|
|
1251 |
|
|
1252 |
lemma "U_rec_1 e c d nil cons (E x) = e x (U_rec_2 e c d nil cons x)"
|
|
1253 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1254 |
apply simp
|
|
1255 |
done
|
|
1256 |
|
|
1257 |
lemma "U_rec_2 e c d nil cons (C x) = c x"
|
|
1258 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1259 |
apply simp
|
|
1260 |
done
|
|
1261 |
|
|
1262 |
lemma "U_rec_2 e c d nil cons (D x) = d x (U_rec_3 e c d nil cons x)"
|
|
1263 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1264 |
apply simp
|
|
1265 |
done
|
|
1266 |
|
|
1267 |
lemma "U_rec_3 e c d nil cons [] = nil"
|
|
1268 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1269 |
apply simp
|
|
1270 |
done
|
|
1271 |
|
|
1272 |
lemma "U_rec_3 e c d nil cons (x#xs) = cons x xs (U_rec_1 e c d nil cons x) (U_rec_3 e c d nil cons xs)"
|
|
1273 |
nitpick [card = 1\<midarrow>3, expect = none]
|
|
1274 |
apply simp
|
|
1275 |
done
|
|
1276 |
|
|
1277 |
lemma "P (U_rec_1 e c d nil cons x)"
|
|
1278 |
nitpick [expect = genuine]
|
|
1279 |
oops
|
|
1280 |
|
|
1281 |
lemma "P (U_rec_2 e c d nil cons x)"
|
|
1282 |
nitpick [card = 1, expect = genuine]
|
|
1283 |
oops
|
|
1284 |
|
|
1285 |
lemma "P (U_rec_3 e c d nil cons x)"
|
|
1286 |
nitpick [card = 1, expect = genuine]
|
|
1287 |
oops
|
|
1288 |
|
|
1289 |
subsubsection {* Records *}
|
|
1290 |
|
|
1291 |
record ('a, 'b) point =
|
|
1292 |
xpos :: 'a
|
|
1293 |
ypos :: 'b
|
|
1294 |
|
|
1295 |
lemma "(x\<Colon>('a, 'b) point) = y"
|
|
1296 |
nitpick [expect = genuine]
|
|
1297 |
oops
|
|
1298 |
|
|
1299 |
record ('a, 'b, 'c) extpoint = "('a, 'b) point" +
|
|
1300 |
ext :: 'c
|
|
1301 |
|
|
1302 |
lemma "(x\<Colon>('a, 'b, 'c) extpoint) = y"
|
|
1303 |
nitpick [expect = genuine]
|
|
1304 |
oops
|
|
1305 |
|
|
1306 |
subsubsection {* Inductively Defined Sets *}
|
|
1307 |
|
|
1308 |
inductive_set undefinedSet :: "'a set" where
|
|
1309 |
"undefined \<in> undefinedSet"
|
|
1310 |
|
|
1311 |
lemma "x \<in> undefinedSet"
|
|
1312 |
nitpick [expect = genuine]
|
|
1313 |
oops
|
|
1314 |
|
|
1315 |
inductive_set evenCard :: "'a set set"
|
|
1316 |
where
|
|
1317 |
"{} \<in> evenCard" |
|
|
1318 |
"\<lbrakk>S \<in> evenCard; x \<notin> S; y \<notin> S; x \<noteq> y\<rbrakk> \<Longrightarrow> S \<union> {x, y} \<in> evenCard"
|
|
1319 |
|
|
1320 |
lemma "S \<in> evenCard"
|
|
1321 |
nitpick [expect = genuine]
|
|
1322 |
oops
|
|
1323 |
|
|
1324 |
inductive_set
|
|
1325 |
even :: "nat set"
|
|
1326 |
and odd :: "nat set"
|
|
1327 |
where
|
|
1328 |
"0 \<in> even" |
|
|
1329 |
"n \<in> even \<Longrightarrow> Suc n \<in> odd" |
|
|
1330 |
"n \<in> odd \<Longrightarrow> Suc n \<in> even"
|
|
1331 |
|
|
1332 |
lemma "n \<in> odd"
|
|
1333 |
nitpick [expect = genuine]
|
|
1334 |
oops
|
|
1335 |
|
|
1336 |
consts f :: "'a \<Rightarrow> 'a"
|
|
1337 |
|
|
1338 |
inductive_set a_even :: "'a set" and a_odd :: "'a set" where
|
|
1339 |
"undefined \<in> a_even" |
|
|
1340 |
"x \<in> a_even \<Longrightarrow> f x \<in> a_odd" |
|
|
1341 |
"x \<in> a_odd \<Longrightarrow> f x \<in> a_even"
|
|
1342 |
|
|
1343 |
lemma "x \<in> a_odd"
|
|
1344 |
nitpick [expect = genuine]
|
|
1345 |
oops
|
|
1346 |
|
|
1347 |
subsubsection {* Examples Involving Special Functions *}
|
|
1348 |
|
|
1349 |
lemma "card x = 0"
|
|
1350 |
nitpick [expect = genuine]
|
|
1351 |
oops
|
|
1352 |
|
|
1353 |
lemma "finite x"
|
|
1354 |
nitpick [expect = none]
|
|
1355 |
oops
|
|
1356 |
|
|
1357 |
lemma "xs @ [] = ys @ []"
|
|
1358 |
nitpick [expect = genuine]
|
|
1359 |
oops
|
|
1360 |
|
|
1361 |
lemma "xs @ ys = ys @ xs"
|
|
1362 |
nitpick [expect = genuine]
|
|
1363 |
oops
|
|
1364 |
|
|
1365 |
lemma "f (lfp f) = lfp f"
|
|
1366 |
nitpick [expect = genuine]
|
|
1367 |
oops
|
|
1368 |
|
|
1369 |
lemma "f (gfp f) = gfp f"
|
|
1370 |
nitpick [expect = genuine]
|
|
1371 |
oops
|
|
1372 |
|
|
1373 |
lemma "lfp f = gfp f"
|
|
1374 |
nitpick [expect = genuine]
|
|
1375 |
oops
|
|
1376 |
|
|
1377 |
subsubsection {* Axiomatic Type Classes and Overloading *}
|
|
1378 |
|
|
1379 |
text {* A type class without axioms: *}
|
|
1380 |
|
|
1381 |
axclass classA
|
|
1382 |
|
|
1383 |
lemma "P (x\<Colon>'a\<Colon>classA)"
|
|
1384 |
nitpick [expect = genuine]
|
|
1385 |
oops
|
|
1386 |
|
|
1387 |
text {* The axiom of this type class does not contain any type variables: *}
|
|
1388 |
|
|
1389 |
axclass classB
|
|
1390 |
classB_ax: "P \<or> \<not> P"
|
|
1391 |
|
|
1392 |
lemma "P (x\<Colon>'a\<Colon>classB)"
|
|
1393 |
nitpick [expect = genuine]
|
|
1394 |
oops
|
|
1395 |
|
|
1396 |
text {* An axiom with a type variable (denoting types which have at least two elements): *}
|
|
1397 |
|
|
1398 |
axclass classC < type
|
|
1399 |
classC_ax: "\<exists>x y. x \<noteq> y"
|
|
1400 |
|
|
1401 |
lemma "P (x\<Colon>'a\<Colon>classC)"
|
|
1402 |
nitpick [expect = genuine]
|
|
1403 |
oops
|
|
1404 |
|
|
1405 |
lemma "\<exists>x y. (x\<Colon>'a\<Colon>classC) \<noteq> y"
|
|
1406 |
nitpick [expect = none]
|
|
1407 |
sorry
|
|
1408 |
|
|
1409 |
text {* A type class for which a constant is defined: *}
|
|
1410 |
|
|
1411 |
consts
|
|
1412 |
classD_const :: "'a \<Rightarrow> 'a"
|
|
1413 |
|
|
1414 |
axclass classD < type
|
|
1415 |
classD_ax: "classD_const (classD_const x) = classD_const x"
|
|
1416 |
|
|
1417 |
lemma "P (x\<Colon>'a\<Colon>classD)"
|
|
1418 |
nitpick [expect = genuine]
|
|
1419 |
oops
|
|
1420 |
|
|
1421 |
text {* A type class with multiple superclasses: *}
|
|
1422 |
|
|
1423 |
axclass classE < classC, classD
|
|
1424 |
|
|
1425 |
lemma "P (x\<Colon>'a\<Colon>classE)"
|
|
1426 |
nitpick [expect = genuine]
|
|
1427 |
oops
|
|
1428 |
|
|
1429 |
lemma "P (x\<Colon>'a\<Colon>{classB, classE})"
|
|
1430 |
nitpick [expect = genuine]
|
|
1431 |
oops
|
|
1432 |
|
|
1433 |
text {* OFCLASS: *}
|
|
1434 |
|
|
1435 |
lemma "OFCLASS('a\<Colon>type, type_class)"
|
|
1436 |
nitpick [expect = none]
|
|
1437 |
apply intro_classes
|
|
1438 |
done
|
|
1439 |
|
|
1440 |
lemma "OFCLASS('a\<Colon>classC, type_class)"
|
|
1441 |
nitpick [expect = none]
|
|
1442 |
apply intro_classes
|
|
1443 |
done
|
|
1444 |
|
|
1445 |
lemma "OFCLASS('a, classB_class)"
|
|
1446 |
nitpick [expect = none]
|
|
1447 |
apply intro_classes
|
|
1448 |
apply simp
|
|
1449 |
done
|
|
1450 |
|
|
1451 |
lemma "OFCLASS('a\<Colon>type, classC_class)"
|
|
1452 |
nitpick [expect = genuine]
|
|
1453 |
oops
|
|
1454 |
|
|
1455 |
text {* Overloading: *}
|
|
1456 |
|
|
1457 |
consts inverse :: "'a \<Rightarrow> 'a"
|
|
1458 |
|
|
1459 |
defs (overloaded)
|
|
1460 |
inverse_bool: "inverse (b\<Colon>bool) \<equiv> \<not> b"
|
|
1461 |
inverse_set: "inverse (S\<Colon>'a set) \<equiv> -S"
|
|
1462 |
inverse_pair: "inverse p \<equiv> (inverse (fst p), inverse (snd p))"
|
|
1463 |
|
|
1464 |
lemma "inverse b"
|
|
1465 |
nitpick [expect = genuine]
|
|
1466 |
oops
|
|
1467 |
|
|
1468 |
lemma "P (inverse (S\<Colon>'a set))"
|
|
1469 |
nitpick [expect = genuine]
|
|
1470 |
oops
|
|
1471 |
|
|
1472 |
lemma "P (inverse (p\<Colon>'a\<times>'b))"
|
|
1473 |
nitpick [expect = genuine]
|
|
1474 |
oops
|
|
1475 |
|
|
1476 |
end
|