author | blanchet |
Mon, 22 Feb 2010 19:31:00 +0100 | |
changeset 35284 | 9edc2bd6d2bd |
parent 35185 | 9b8f351cced6 |
child 35309 | 997aa3a3e4bb |
permissions | -rw-r--r-- |
33197 | 1 |
(* Title: HOL/Nitpick_Examples/Manual_Nits.thy |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
34982
diff
changeset
|
3 |
Copyright 2009, 2010 |
33197 | 4 |
|
5 |
Examples from the Nitpick manual. |
|
6 |
*) |
|
7 |
||
8 |
header {* Examples from the Nitpick Manual *} |
|
9 |
||
10 |
theory Manual_Nits |
|
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
11 |
imports Main Coinductive_List Quotient_Product RealDef |
33197 | 12 |
begin |
13 |
||
14 |
chapter {* 3. First Steps *} |
|
15 |
||
35078
6fd1052fe463
optimization to quantifiers in Nitpick's handling of simp rules + renamed some SAT solvers
blanchet
parents:
35076
diff
changeset
|
16 |
nitpick_params [sat_solver = MiniSat_JNI, max_threads = 1] |
33197 | 17 |
|
18 |
subsection {* 3.1. Propositional Logic *} |
|
19 |
||
20 |
lemma "P \<longleftrightarrow> Q" |
|
21 |
nitpick |
|
22 |
apply auto |
|
23 |
nitpick 1 |
|
24 |
nitpick 2 |
|
25 |
oops |
|
26 |
||
27 |
subsection {* 3.2. Type Variables *} |
|
28 |
||
29 |
lemma "P x \<Longrightarrow> P (THE y. P y)" |
|
30 |
nitpick [verbose] |
|
31 |
oops |
|
32 |
||
33 |
subsection {* 3.3. Constants *} |
|
34 |
||
35 |
lemma "P x \<Longrightarrow> P (THE y. P y)" |
|
36 |
nitpick [show_consts] |
|
37 |
nitpick [full_descrs, show_consts] |
|
38 |
nitpick [dont_specialize, full_descrs, show_consts] |
|
39 |
oops |
|
40 |
||
41 |
lemma "\<exists>!x. P x \<Longrightarrow> P (THE y. P y)" |
|
42 |
nitpick |
|
43 |
nitpick [card 'a = 1-50] |
|
44 |
(* sledgehammer *) |
|
45 |
apply (metis the_equality) |
|
46 |
done |
|
47 |
||
48 |
subsection {* 3.4. Skolemization *} |
|
49 |
||
50 |
lemma "\<exists>g. \<forall>x. g (f x) = x \<Longrightarrow> \<forall>y. \<exists>x. y = f x" |
|
51 |
nitpick |
|
52 |
oops |
|
53 |
||
54 |
lemma "\<exists>x. \<forall>f. f x = x" |
|
55 |
nitpick |
|
56 |
oops |
|
57 |
||
58 |
lemma "refl r \<Longrightarrow> sym r" |
|
59 |
nitpick |
|
60 |
oops |
|
61 |
||
34126 | 62 |
subsection {* 3.5. Natural Numbers and Integers *} |
33197 | 63 |
|
64 |
lemma "\<lbrakk>i \<le> j; n \<le> (m\<Colon>int)\<rbrakk> \<Longrightarrow> i * n + j * m \<le> i * m + j * n" |
|
65 |
nitpick |
|
66 |
oops |
|
67 |
||
68 |
lemma "\<forall>n. Suc n \<noteq> n \<Longrightarrow> P" |
|
69 |
nitpick [card nat = 100, check_potential] |
|
70 |
oops |
|
71 |
||
72 |
lemma "P Suc" |
|
73 |
nitpick [card = 1-6] |
|
74 |
oops |
|
75 |
||
76 |
lemma "P (op +\<Colon>nat\<Rightarrow>nat\<Rightarrow>nat)" |
|
77 |
nitpick [card nat = 1] |
|
78 |
nitpick [card nat = 2] |
|
79 |
oops |
|
80 |
||
81 |
subsection {* 3.6. Inductive Datatypes *} |
|
82 |
||
83 |
lemma "hd (xs @ [y, y]) = hd xs" |
|
84 |
nitpick |
|
85 |
nitpick [show_consts, show_datatypes] |
|
86 |
oops |
|
87 |
||
88 |
lemma "\<lbrakk>length xs = 1; length ys = 1\<rbrakk> \<Longrightarrow> xs = ys" |
|
89 |
nitpick [show_datatypes] |
|
90 |
oops |
|
91 |
||
92 |
subsection {* 3.7. Typedefs, Records, Rationals, and Reals *} |
|
93 |
||
94 |
typedef three = "{0\<Colon>nat, 1, 2}" |
|
95 |
by blast |
|
96 |
||
97 |
definition A :: three where "A \<equiv> Abs_three 0" |
|
98 |
definition B :: three where "B \<equiv> Abs_three 1" |
|
99 |
definition C :: three where "C \<equiv> Abs_three 2" |
|
100 |
||
101 |
lemma "\<lbrakk>P A; P B\<rbrakk> \<Longrightarrow> P x" |
|
102 |
nitpick [show_datatypes] |
|
103 |
oops |
|
104 |
||
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
105 |
fun my_int_rel where |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
106 |
"my_int_rel (x, y) (u, v) = (x + v = u + y)" |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
107 |
|
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
108 |
quotient_type my_int = "nat \<times> nat" / my_int_rel |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
109 |
by (auto simp add: equivp_def expand_fun_eq) |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
110 |
|
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
111 |
definition add_raw where |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
112 |
"add_raw \<equiv> \<lambda>(x, y) (u, v). (x + (u\<Colon>nat), y + (v\<Colon>nat))" |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
113 |
|
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
114 |
quotient_definition "add\<Colon>my_int \<Rightarrow> my_int \<Rightarrow> my_int" is add_raw |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
115 |
|
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
116 |
lemma "add x y = add x x" |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
117 |
nitpick [show_datatypes] |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
118 |
oops |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35185
diff
changeset
|
119 |
|
33197 | 120 |
record point = |
121 |
Xcoord :: int |
|
122 |
Ycoord :: int |
|
123 |
||
124 |
lemma "Xcoord (p\<Colon>point) = Xcoord (q\<Colon>point)" |
|
125 |
nitpick [show_datatypes] |
|
126 |
oops |
|
127 |
||
128 |
lemma "4 * x + 3 * (y\<Colon>real) \<noteq> 1 / 2" |
|
129 |
nitpick [show_datatypes] |
|
130 |
oops |
|
131 |
||
132 |
subsection {* 3.8. Inductive and Coinductive Predicates *} |
|
133 |
||
134 |
inductive even where |
|
135 |
"even 0" | |
|
136 |
"even n \<Longrightarrow> even (Suc (Suc n))" |
|
137 |
||
138 |
lemma "\<exists>n. even n \<and> even (Suc n)" |
|
34126 | 139 |
nitpick [card nat = 100, unary_ints, verbose] |
33197 | 140 |
oops |
141 |
||
142 |
lemma "\<exists>n \<le> 99. even n \<and> even (Suc n)" |
|
34126 | 143 |
nitpick [card nat = 100, unary_ints, verbose] |
33197 | 144 |
oops |
145 |
||
146 |
inductive even' where |
|
147 |
"even' (0\<Colon>nat)" | |
|
148 |
"even' 2" | |
|
149 |
"\<lbrakk>even' m; even' n\<rbrakk> \<Longrightarrow> even' (m + n)" |
|
150 |
||
151 |
lemma "\<exists>n \<in> {0, 2, 4, 6, 8}. \<not> even' n" |
|
34126 | 152 |
nitpick [card nat = 10, unary_ints, verbose, show_consts] (* FIXME: should be genuine *) |
33197 | 153 |
oops |
154 |
||
155 |
lemma "even' (n - 2) \<Longrightarrow> even' n" |
|
156 |
nitpick [card nat = 10, show_consts] |
|
157 |
oops |
|
158 |
||
159 |
coinductive nats where |
|
160 |
"nats (x\<Colon>nat) \<Longrightarrow> nats x" |
|
161 |
||
162 |
lemma "nats = {0, 1, 2, 3, 4}" |
|
163 |
nitpick [card nat = 10, show_consts] |
|
164 |
oops |
|
165 |
||
166 |
inductive odd where |
|
167 |
"odd 1" | |
|
168 |
"\<lbrakk>odd m; even n\<rbrakk> \<Longrightarrow> odd (m + n)" |
|
169 |
||
170 |
lemma "odd n \<Longrightarrow> odd (n - 2)" |
|
171 |
nitpick [card nat = 10, show_consts] |
|
172 |
oops |
|
173 |
||
174 |
subsection {* 3.9. Coinductive Datatypes *} |
|
175 |
||
176 |
lemma "xs \<noteq> LCons a xs" |
|
177 |
nitpick |
|
178 |
oops |
|
179 |
||
180 |
lemma "\<lbrakk>xs = LCons a xs; ys = iterates (\<lambda>b. a) b\<rbrakk> \<Longrightarrow> xs = ys" |
|
181 |
nitpick [verbose] |
|
182 |
nitpick [bisim_depth = -1, verbose] |
|
183 |
oops |
|
184 |
||
185 |
lemma "\<lbrakk>xs = LCons a xs; ys = LCons a ys\<rbrakk> \<Longrightarrow> xs = ys" |
|
186 |
nitpick [bisim_depth = -1, show_datatypes] |
|
187 |
nitpick |
|
188 |
sorry |
|
189 |
||
190 |
subsection {* 3.10. Boxing *} |
|
191 |
||
192 |
datatype tm = Var nat | Lam tm | App tm tm |
|
193 |
||
194 |
primrec lift where |
|
195 |
"lift (Var j) k = Var (if j < k then j else j + 1)" | |
|
196 |
"lift (Lam t) k = Lam (lift t (k + 1))" | |
|
197 |
"lift (App t u) k = App (lift t k) (lift u k)" |
|
198 |
||
199 |
primrec loose where |
|
200 |
"loose (Var j) k = (j \<ge> k)" | |
|
201 |
"loose (Lam t) k = loose t (Suc k)" | |
|
202 |
"loose (App t u) k = (loose t k \<or> loose u k)" |
|
203 |
||
204 |
primrec subst\<^isub>1 where |
|
205 |
"subst\<^isub>1 \<sigma> (Var j) = \<sigma> j" | |
|
206 |
"subst\<^isub>1 \<sigma> (Lam t) = |
|
207 |
Lam (subst\<^isub>1 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 1) t)" | |
|
208 |
"subst\<^isub>1 \<sigma> (App t u) = App (subst\<^isub>1 \<sigma> t) (subst\<^isub>1 \<sigma> u)" |
|
209 |
||
210 |
lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>1 \<sigma> t = t" |
|
211 |
nitpick [verbose] |
|
212 |
nitpick [eval = "subst\<^isub>1 \<sigma> t"] |
|
213 |
nitpick [dont_box] |
|
214 |
oops |
|
215 |
||
216 |
primrec subst\<^isub>2 where |
|
217 |
"subst\<^isub>2 \<sigma> (Var j) = \<sigma> j" | |
|
218 |
"subst\<^isub>2 \<sigma> (Lam t) = |
|
219 |
Lam (subst\<^isub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" | |
|
220 |
"subst\<^isub>2 \<sigma> (App t u) = App (subst\<^isub>2 \<sigma> t) (subst\<^isub>2 \<sigma> u)" |
|
221 |
||
222 |
lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>2 \<sigma> t = t" |
|
223 |
nitpick |
|
224 |
sorry |
|
225 |
||
226 |
subsection {* 3.11. Scope Monotonicity *} |
|
227 |
||
228 |
lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)" |
|
229 |
nitpick [verbose] |
|
230 |
nitpick [card = 8, verbose] |
|
231 |
oops |
|
232 |
||
233 |
lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x" |
|
234 |
nitpick [mono] |
|
235 |
nitpick |
|
236 |
oops |
|
237 |
||
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
238 |
subsection {* 3.12. Inductive Properties *} |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
239 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
240 |
inductive_set reach where |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
241 |
"(4\<Colon>nat) \<in> reach" | |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
242 |
"n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" | |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
243 |
"n \<in> reach \<Longrightarrow> n + 2 \<in> reach" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
244 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
245 |
lemma "n \<in> reach \<Longrightarrow> 2 dvd n" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
246 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
247 |
apply (induct set: reach) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
248 |
apply auto |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
249 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
250 |
apply (thin_tac "n \<in> reach") |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
251 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
252 |
oops |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
253 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
254 |
lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
255 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
256 |
apply (induct set: reach) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
257 |
apply auto |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
258 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
259 |
apply (thin_tac "n \<in> reach") |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
260 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
261 |
oops |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
262 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
263 |
lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<ge> 4" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
264 |
by (induct set: reach) arith+ |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
265 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
266 |
datatype 'a bin_tree = Leaf 'a | Branch "'a bin_tree" "'a bin_tree" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
267 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
268 |
primrec labels where |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
269 |
"labels (Leaf a) = {a}" | |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
270 |
"labels (Branch t u) = labels t \<union> labels u" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
271 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
272 |
primrec swap where |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
273 |
"swap (Leaf c) a b = |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
274 |
(if c = a then Leaf b else if c = b then Leaf a else Leaf c)" | |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
275 |
"swap (Branch t u) a b = Branch (swap t a b) (swap u a b)" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
276 |
|
35180
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
blanchet
parents:
35078
diff
changeset
|
277 |
lemma "{a, b} \<subseteq> labels t \<Longrightarrow> labels (swap t a b) = labels t" |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
278 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
279 |
proof (induct t) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
280 |
case Leaf thus ?case by simp |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
281 |
next |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
282 |
case (Branch t u) thus ?case |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
283 |
nitpick |
35185
9b8f351cced6
added yet another hint to Nitpick's output, this time warning about problems for which nothing was effectively tested
blanchet
parents:
35180
diff
changeset
|
284 |
nitpick [non_std, show_all] |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
285 |
oops |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
286 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
287 |
lemma "labels (swap t a b) = |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
288 |
(if a \<in> labels t then |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
289 |
if b \<in> labels t then labels t else (labels t - {a}) \<union> {b} |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
290 |
else |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
291 |
if b \<in> labels t then (labels t - {b}) \<union> {a} else labels t)" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
292 |
nitpick |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
293 |
proof (induct t) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
294 |
case Leaf thus ?case by simp |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
295 |
next |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
296 |
case (Branch t u) thus ?case |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
297 |
nitpick [non_std "'a bin_tree", show_consts] |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
298 |
by auto |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
299 |
qed |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
300 |
|
33197 | 301 |
section {* 4. Case Studies *} |
302 |
||
303 |
nitpick_params [max_potential = 0, max_threads = 2] |
|
304 |
||
305 |
subsection {* 4.1. A Context-Free Grammar *} |
|
306 |
||
307 |
datatype alphabet = a | b |
|
308 |
||
309 |
inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where |
|
310 |
"[] \<in> S\<^isub>1" |
|
311 |
| "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1" |
|
312 |
| "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1" |
|
313 |
| "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1" |
|
314 |
| "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1" |
|
315 |
| "\<lbrakk>v \<in> B\<^isub>1; v \<in> B\<^isub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>1" |
|
316 |
||
317 |
theorem S\<^isub>1_sound: |
|
318 |
"w \<in> S\<^isub>1 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
|
319 |
nitpick |
|
320 |
oops |
|
321 |
||
322 |
inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where |
|
323 |
"[] \<in> S\<^isub>2" |
|
324 |
| "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2" |
|
325 |
| "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2" |
|
326 |
| "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2" |
|
327 |
| "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2" |
|
328 |
| "\<lbrakk>v \<in> B\<^isub>2; v \<in> B\<^isub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>2" |
|
329 |
||
330 |
theorem S\<^isub>2_sound: |
|
331 |
"w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
|
332 |
nitpick |
|
333 |
oops |
|
334 |
||
335 |
inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where |
|
336 |
"[] \<in> S\<^isub>3" |
|
337 |
| "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3" |
|
338 |
| "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3" |
|
339 |
| "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3" |
|
340 |
| "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3" |
|
341 |
| "\<lbrakk>v \<in> B\<^isub>3; w \<in> B\<^isub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>3" |
|
342 |
||
343 |
theorem S\<^isub>3_sound: |
|
344 |
"w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
|
345 |
nitpick |
|
346 |
sorry |
|
347 |
||
348 |
theorem S\<^isub>3_complete: |
|
349 |
"length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>3" |
|
350 |
nitpick |
|
351 |
oops |
|
352 |
||
353 |
inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where |
|
354 |
"[] \<in> S\<^isub>4" |
|
355 |
| "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4" |
|
356 |
| "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4" |
|
357 |
| "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4" |
|
358 |
| "\<lbrakk>v \<in> A\<^isub>4; w \<in> A\<^isub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^isub>4" |
|
359 |
| "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4" |
|
360 |
| "\<lbrakk>v \<in> B\<^isub>4; w \<in> B\<^isub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>4" |
|
361 |
||
362 |
theorem S\<^isub>4_sound: |
|
363 |
"w \<in> S\<^isub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
|
364 |
nitpick |
|
365 |
sorry |
|
366 |
||
367 |
theorem S\<^isub>4_complete: |
|
368 |
"length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>4" |
|
369 |
nitpick |
|
370 |
sorry |
|
371 |
||
372 |
theorem S\<^isub>4_A\<^isub>4_B\<^isub>4_sound_and_complete: |
|
373 |
"w \<in> S\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
|
374 |
"w \<in> A\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] + 1" |
|
375 |
"w \<in> B\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = b] = length [x \<leftarrow> w. x = a] + 1" |
|
376 |
nitpick |
|
377 |
sorry |
|
378 |
||
379 |
subsection {* 4.2. AA Trees *} |
|
380 |
||
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34126
diff
changeset
|
381 |
datatype 'a aa_tree = \<Lambda> | N "'a\<Colon>linorder" nat "'a aa_tree" "'a aa_tree" |
33197 | 382 |
|
383 |
primrec data where |
|
384 |
"data \<Lambda> = undefined" | |
|
385 |
"data (N x _ _ _) = x" |
|
386 |
||
387 |
primrec dataset where |
|
388 |
"dataset \<Lambda> = {}" | |
|
389 |
"dataset (N x _ t u) = {x} \<union> dataset t \<union> dataset u" |
|
390 |
||
391 |
primrec level where |
|
392 |
"level \<Lambda> = 0" | |
|
393 |
"level (N _ k _ _) = k" |
|
394 |
||
395 |
primrec left where |
|
396 |
"left \<Lambda> = \<Lambda>" | |
|
397 |
"left (N _ _ t\<^isub>1 _) = t\<^isub>1" |
|
398 |
||
399 |
primrec right where |
|
400 |
"right \<Lambda> = \<Lambda>" | |
|
401 |
"right (N _ _ _ t\<^isub>2) = t\<^isub>2" |
|
402 |
||
403 |
fun wf where |
|
404 |
"wf \<Lambda> = True" | |
|
405 |
"wf (N _ k t u) = |
|
406 |
(if t = \<Lambda> then |
|
407 |
k = 1 \<and> (u = \<Lambda> \<or> (level u = 1 \<and> left u = \<Lambda> \<and> right u = \<Lambda>)) |
|
408 |
else |
|
409 |
wf t \<and> wf u \<and> u \<noteq> \<Lambda> \<and> level t < k \<and> level u \<le> k \<and> level (right u) < k)" |
|
410 |
||
411 |
fun skew where |
|
412 |
"skew \<Lambda> = \<Lambda>" | |
|
413 |
"skew (N x k t u) = |
|
414 |
(if t \<noteq> \<Lambda> \<and> k = level t then |
|
415 |
N (data t) k (left t) (N x k (right t) u) |
|
416 |
else |
|
417 |
N x k t u)" |
|
418 |
||
419 |
fun split where |
|
420 |
"split \<Lambda> = \<Lambda>" | |
|
421 |
"split (N x k t u) = |
|
422 |
(if u \<noteq> \<Lambda> \<and> k = level (right u) then |
|
423 |
N (data u) (Suc k) (N x k t (left u)) (right u) |
|
424 |
else |
|
425 |
N x k t u)" |
|
426 |
||
427 |
theorem dataset_skew_split: |
|
428 |
"dataset (skew t) = dataset t" |
|
429 |
"dataset (split t) = dataset t" |
|
430 |
nitpick |
|
431 |
sorry |
|
432 |
||
433 |
theorem wf_skew_split: |
|
434 |
"wf t \<Longrightarrow> skew t = t" |
|
435 |
"wf t \<Longrightarrow> split t = t" |
|
436 |
nitpick |
|
437 |
sorry |
|
438 |
||
439 |
primrec insort\<^isub>1 where |
|
440 |
"insort\<^isub>1 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | |
|
441 |
"insort\<^isub>1 (N y k t u) x = |
|
442 |
(* (split \<circ> skew) *) (N y k (if x < y then insort\<^isub>1 t x else t) |
|
443 |
(if x > y then insort\<^isub>1 u x else u))" |
|
444 |
||
445 |
theorem wf_insort\<^isub>1: "wf t \<Longrightarrow> wf (insort\<^isub>1 t x)" |
|
446 |
nitpick |
|
447 |
oops |
|
448 |
||
449 |
theorem wf_insort\<^isub>1_nat: "wf t \<Longrightarrow> wf (insort\<^isub>1 t (x\<Colon>nat))" |
|
450 |
nitpick [eval = "insort\<^isub>1 t x"] |
|
451 |
oops |
|
452 |
||
453 |
primrec insort\<^isub>2 where |
|
454 |
"insort\<^isub>2 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | |
|
455 |
"insort\<^isub>2 (N y k t u) x = |
|
456 |
(split \<circ> skew) (N y k (if x < y then insort\<^isub>2 t x else t) |
|
457 |
(if x > y then insort\<^isub>2 u x else u))" |
|
458 |
||
459 |
theorem wf_insort\<^isub>2: "wf t \<Longrightarrow> wf (insort\<^isub>2 t x)" |
|
460 |
nitpick |
|
461 |
sorry |
|
462 |
||
463 |
theorem dataset_insort\<^isub>2: "dataset (insort\<^isub>2 t x) = {x} \<union> dataset t" |
|
464 |
nitpick |
|
465 |
sorry |
|
466 |
||
467 |
end |