| author | wenzelm |
| Tue, 24 Nov 2009 17:54:33 +0100 | |
| changeset 33890 | a87ad4be59a4 |
| parent 33737 | e441fede163d |
| child 34083 | 652719832159 |
| permissions | -rw-r--r-- |
| 33197 | 1 |
(* Title: HOL/Nitpick_Examples/Special_Nits.thy |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
3 |
Copyright 2009 |
|
4 |
||
5 |
Examples featuring Nitpick's "specialize" optimization. |
|
6 |
*) |
|
7 |
||
8 |
header {* Examples Featuring Nitpick's \textit{specialize} Optimization *}
|
|
9 |
||
10 |
theory Special_Nits |
|
11 |
imports Main |
|
12 |
begin |
|
13 |
||
14 |
nitpick_params [card = 4, debug, show_consts, timeout = 10 s] |
|
15 |
||
16 |
fun f1 :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" where |
|
17 |
"f1 a b c d e = a + b + c + d + e" |
|
18 |
||
19 |
lemma "f1 0 0 0 0 0 = f1 0 0 0 0 (1 - 1)" |
|
20 |
nitpick [expect = none] |
|
21 |
nitpick [dont_specialize, expect = none] |
|
22 |
sorry |
|
23 |
||
24 |
lemma "f1 u v w x y = f1 y x w v u" |
|
25 |
nitpick [expect = none] |
|
26 |
nitpick [dont_specialize, expect = none] |
|
27 |
sorry |
|
28 |
||
29 |
fun f2 :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" where |
|
30 |
"f2 a b c d (Suc e) = a + b + c + d + e" |
|
31 |
||
32 |
lemma "f2 0 0 0 0 0 = f2 (1 - 1) 0 0 0 0" |
|
33 |
nitpick [expect = none] |
|
34 |
nitpick [dont_specialize, expect = none] |
|
35 |
sorry |
|
36 |
||
37 |
lemma "f2 0 (v - v) 0 (x - x) 0 = f2 (u - u) 0 (w - w) 0 (y - y)" |
|
38 |
nitpick [expect = none] |
|
39 |
nitpick [dont_specialize, expect = none] |
|
40 |
sorry |
|
41 |
||
42 |
lemma "f2 1 0 0 0 0 = f2 0 1 0 0 0" |
|
43 |
nitpick [expect = genuine] |
|
44 |
nitpick [dont_specialize, expect = genuine] |
|
45 |
oops |
|
46 |
||
47 |
lemma "f2 0 0 0 0 0 = f2 0 0 0 0 0" |
|
48 |
nitpick [expect = none] |
|
49 |
nitpick [dont_specialize, expect = none] |
|
50 |
sorry |
|
51 |
||
52 |
fun f3 :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat" where |
|
53 |
"f3 (Suc a) b 0 d (Suc e) = a + b + d + e" | |
|
54 |
"f3 0 b 0 d 0 = b + d" |
|
55 |
||
56 |
lemma "f3 a b c d e = f3 e d c b a" |
|
57 |
nitpick [expect = genuine] |
|
58 |
nitpick [dont_specialize, expect = genuine] |
|
59 |
oops |
|
60 |
||
61 |
lemma "f3 a b c d a = f3 a d c d a" |
|
62 |
nitpick [expect = genuine] |
|
63 |
nitpick [dont_specialize, expect = genuine] |
|
64 |
oops |
|
65 |
||
66 |
lemma "\<lbrakk>c < 1; a \<ge> e; e \<ge> a\<rbrakk> \<Longrightarrow> f3 a b c d a = f3 e d c b e" |
|
67 |
nitpick [expect = none] |
|
68 |
nitpick [dont_specialize, expect = none] |
|
69 |
sorry |
|
70 |
||
71 |
lemma "(\<forall>u. a = u \<longrightarrow> f3 a a a a a = f3 u u u u u) |
|
72 |
\<and> (\<forall>u. b = u \<longrightarrow> f3 b b u b b = f3 u u b u u)" |
|
73 |
nitpick [expect = none] |
|
74 |
nitpick [dont_specialize, expect = none] |
|
75 |
nitpick [dont_skolemize, expect = none] |
|
76 |
nitpick [dont_specialize, dont_skolemize, expect = none] |
|
77 |
sorry |
|
78 |
||
79 |
function f4 :: "nat \<Rightarrow> nat \<Rightarrow> nat" where |
|
80 |
"f4 x x = 1" | |
|
81 |
"f4 y z = (if y = z then 1 else 0)" |
|
82 |
by auto |
|
83 |
termination by lexicographic_order |
|
84 |
||
85 |
lemma "f4 a b = f4 b a" |
|
86 |
nitpick [expect = none] |
|
87 |
nitpick [dont_specialize, expect = none] |
|
88 |
sorry |
|
89 |
||
90 |
lemma "f4 a (Suc a) = f4 a a" |
|
91 |
nitpick [expect = genuine] |
|
92 |
nitpick [dont_specialize, expect = genuine] |
|
93 |
oops |
|
94 |
||
95 |
fun f5 :: "(nat \<Rightarrow> nat) \<Rightarrow> nat \<Rightarrow> nat" where |
|
96 |
"f5 f (Suc a) = f a" |
|
97 |
||
98 |
lemma "\<exists>one \<in> {1}. \<exists>two \<in> {2}.
|
|
99 |
f5 (\<lambda>a. if a = one then 1 else if a = two then 2 else a) (Suc x) = x" |
|
100 |
nitpick [expect = none] |
|
101 |
nitpick [dont_specialize, expect = none] |
|
102 |
sorry |
|
103 |
||
104 |
lemma "\<exists>two \<in> {2}. \<exists>one \<in> {1}.
|
|
105 |
f5 (\<lambda>a. if a = one then 1 else if a = two then 2 else a) (Suc x) = x" |
|
106 |
nitpick [expect = none] |
|
107 |
nitpick [dont_specialize, expect = none] |
|
108 |
sorry |
|
109 |
||
110 |
lemma "\<exists>one \<in> {1}. \<exists>two \<in> {2}.
|
|
111 |
f5 (\<lambda>a. if a = one then 2 else if a = two then 1 else a) (Suc x) = x" |
|
|
33737
e441fede163d
fixed "expect" of Nitpick examples to reflect latest changes in Nitpick
blanchet
parents:
33197
diff
changeset
|
112 |
nitpick [expect = potential] (* unfortunate *) |
|
e441fede163d
fixed "expect" of Nitpick examples to reflect latest changes in Nitpick
blanchet
parents:
33197
diff
changeset
|
113 |
oops |
| 33197 | 114 |
|
115 |
lemma "\<exists>two \<in> {2}. \<exists>one \<in> {1}.
|
|
116 |
f5 (\<lambda>a. if a = one then 2 else if a = two then 1 else a) (Suc x) = x" |
|
|
33737
e441fede163d
fixed "expect" of Nitpick examples to reflect latest changes in Nitpick
blanchet
parents:
33197
diff
changeset
|
117 |
nitpick [expect = potential] (* unfortunate *) |
|
e441fede163d
fixed "expect" of Nitpick examples to reflect latest changes in Nitpick
blanchet
parents:
33197
diff
changeset
|
118 |
oops |
| 33197 | 119 |
|
120 |
lemma "\<forall>a. g a = a |
|
121 |
\<Longrightarrow> \<exists>one \<in> {1}. \<exists>two \<in> {2}. f5 g x =
|
|
122 |
f5 (\<lambda>a. if a = one then 1 else if a = two then 2 else a) x" |
|
123 |
nitpick [expect = none] |
|
124 |
nitpick [dont_specialize, expect = none] |
|
125 |
sorry |
|
126 |
||
127 |
lemma "\<forall>a. g a = a |
|
128 |
\<Longrightarrow> \<exists>one \<in> {2}. \<exists>two \<in> {1}. f5 g x =
|
|
129 |
f5 (\<lambda>a. if a = one then 1 else if a = two then 2 else a) x" |
|
130 |
nitpick [expect = potential] |
|
131 |
nitpick [dont_specialize, expect = potential] |
|
132 |
sorry |
|
133 |
||
134 |
lemma "\<forall>a. g a = a |
|
135 |
\<Longrightarrow> \<exists>b\<^isub>1 b\<^isub>2 b\<^isub>3 b\<^isub>4 b\<^isub>5 b\<^isub>6 b\<^isub>7 b\<^isub>8 b\<^isub>9 b\<^isub>10 (b\<^isub>11\<Colon>nat). |
|
136 |
b\<^isub>1 < b\<^isub>11 \<and> f5 g x = f5 (\<lambda>a. if b\<^isub>1 < b\<^isub>11 then a else h b\<^isub>2) x" |
|
137 |
nitpick [expect = potential] |
|
138 |
nitpick [dont_specialize, expect = none] |
|
139 |
nitpick [dont_box, expect = none] |
|
140 |
nitpick [dont_box, dont_specialize, expect = none] |
|
141 |
sorry |
|
142 |
||
143 |
lemma "\<forall>a. g a = a |
|
144 |
\<Longrightarrow> \<exists>b\<^isub>1 b\<^isub>2 b\<^isub>3 b\<^isub>4 b\<^isub>5 b\<^isub>6 b\<^isub>7 b\<^isub>8 b\<^isub>9 b\<^isub>10 (b\<^isub>11\<Colon>nat). |
|
145 |
b\<^isub>1 < b\<^isub>11 |
|
146 |
\<and> f5 g x = f5 (\<lambda>a. if b\<^isub>1 < b\<^isub>11 then |
|
147 |
a |
|
148 |
else |
|
149 |
h b\<^isub>2 + h b\<^isub>3 + h b\<^isub>4 + h b\<^isub>5 + h b\<^isub>6 + h b\<^isub>7 + h b\<^isub>8 |
|
150 |
+ h b\<^isub>9 + h b\<^isub>10) x" |
|
151 |
nitpick [card nat = 2, card 'a = 1, expect = none] |
|
152 |
nitpick [card nat = 2, card 'a = 1, dont_box, expect = none] |
|
153 |
nitpick [card nat = 2, card 'a = 1, dont_specialize, expect = none] |
|
154 |
nitpick [card nat = 2, card 'a = 1, dont_box, dont_specialize, expect = none] |
|
155 |
sorry |
|
156 |
||
157 |
lemma "\<forall>a. g a = a |
|
158 |
\<Longrightarrow> \<exists>b\<^isub>1 b\<^isub>2 b\<^isub>3 b\<^isub>4 b\<^isub>5 b\<^isub>6 b\<^isub>7 b\<^isub>8 b\<^isub>9 b\<^isub>10 (b\<^isub>11\<Colon>nat). |
|
159 |
b\<^isub>1 < b\<^isub>11 |
|
160 |
\<and> f5 g x = f5 (\<lambda>a. if b\<^isub>1 \<ge> b\<^isub>11 then |
|
161 |
a |
|
162 |
else |
|
163 |
h b\<^isub>2 + h b\<^isub>3 + h b\<^isub>4 + h b\<^isub>5 + h b\<^isub>6 + h b\<^isub>7 + h b\<^isub>8 |
|
164 |
+ h b\<^isub>9 + h b\<^isub>10) x" |
|
165 |
nitpick [card nat = 2, card 'a = 1, expect = none] |
|
166 |
nitpick [card nat = 2, card 'a = 1, dont_box, expect = potential] |
|
167 |
nitpick [card nat = 2, card 'a = 1, dont_specialize, expect = potential] |
|
168 |
nitpick [card nat = 2, card 'a = 1, dont_box, dont_specialize, |
|
169 |
expect = potential] |
|
170 |
oops |
|
171 |
||
172 |
end |