author | huffman |
Fri, 05 Mar 2010 14:05:25 -0800 | |
changeset 35596 | 49a02dab35ed |
parent 35280 | 54ab4921f826 |
child 35665 | ff2bf50505ab |
permissions | -rw-r--r-- |
33982 | 1 |
(* Title: HOL/Tools/Nitpick/nitpick_isar.ML |
33192 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
3 |
Copyright 2008, 2009, 2010 |
33192 | 4 |
|
5 |
Adds the "nitpick" and "nitpick_params" commands to Isabelle/Isar's outer |
|
6 |
syntax. |
|
7 |
*) |
|
8 |
||
9 |
signature NITPICK_ISAR = |
|
10 |
sig |
|
11 |
type params = Nitpick.params |
|
12 |
||
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
13 |
val auto: bool Unsynchronized.ref |
33192 | 14 |
val default_params : theory -> (string * string) list -> params |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
15 |
val setup : theory -> theory |
33192 | 16 |
end |
17 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33220
diff
changeset
|
18 |
structure Nitpick_Isar : NITPICK_ISAR = |
33192 | 19 |
struct |
20 |
||
33232
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33220
diff
changeset
|
21 |
open Nitpick_Util |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33220
diff
changeset
|
22 |
open Nitpick_HOL |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33220
diff
changeset
|
23 |
open Nitpick_Rep |
f93390060bbe
internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents:
33220
diff
changeset
|
24 |
open Nitpick_Nut |
33192 | 25 |
open Nitpick |
26 |
||
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
27 |
val auto = Unsynchronized.ref false; |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
28 |
|
33601
4608243edcfc
plain add_preference, no setmp_CRITICAL required;
wenzelm
parents:
33599
diff
changeset
|
29 |
val _ = |
4608243edcfc
plain add_preference, no setmp_CRITICAL required;
wenzelm
parents:
33599
diff
changeset
|
30 |
ProofGeneralPgip.add_preference Preferences.category_tracing |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
31 |
(Preferences.bool_pref auto "auto-nitpick" |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
32 |
"Whether to run Nitpick automatically.") |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
33 |
|
33192 | 34 |
type raw_param = string * string list |
35 |
||
36 |
val default_default_params = |
|
37 |
[("card", ["1\<midarrow>8"]), |
|
38 |
("iter", ["0,1,2,4,8,12,16,24"]), |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
39 |
("bits", ["1,2,3,4,6,8,10,12"]), |
33192 | 40 |
("bisim_depth", ["7"]), |
41 |
("box", ["smart"]), |
|
42 |
("mono", ["smart"]), |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
43 |
("std", ["true"]), |
33192 | 44 |
("wf", ["smart"]), |
45 |
("sat_solver", ["smart"]), |
|
46 |
("batch_size", ["smart"]), |
|
47 |
("blocking", ["true"]), |
|
48 |
("falsify", ["true"]), |
|
49 |
("user_axioms", ["smart"]), |
|
50 |
("assms", ["true"]), |
|
33556
cba22e2999d5
renamed Nitpick option "coalesce_type_vars" to "merge_type_vars" (shorter) and cleaned up old hacks that are no longer necessary
blanchet
parents:
33232
diff
changeset
|
51 |
("merge_type_vars", ["false"]), |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
52 |
("binary_ints", ["smart"]), |
33192 | 53 |
("destroy_constrs", ["true"]), |
54 |
("specialize", ["true"]), |
|
55 |
("skolemize", ["true"]), |
|
56 |
("star_linear_preds", ["true"]), |
|
57 |
("uncurry", ["true"]), |
|
58 |
("fast_descrs", ["true"]), |
|
59 |
("peephole_optim", ["true"]), |
|
60 |
("timeout", ["30 s"]), |
|
61 |
("tac_timeout", ["500 ms"]), |
|
62 |
("sym_break", ["20"]), |
|
63 |
("sharing_depth", ["3"]), |
|
64 |
("flatten_props", ["false"]), |
|
65 |
("max_threads", ["0"]), |
|
66 |
("verbose", ["false"]), |
|
67 |
("debug", ["false"]), |
|
33197
de6285ebcc05
continuation of Nitpick's integration into Isabelle;
blanchet
parents:
33192
diff
changeset
|
68 |
("overlord", ["false"]), |
33192 | 69 |
("show_all", ["false"]), |
70 |
("show_skolems", ["true"]), |
|
71 |
("show_datatypes", ["false"]), |
|
72 |
("show_consts", ["false"]), |
|
73 |
("format", ["1"]), |
|
74 |
("max_potential", ["1"]), |
|
75 |
("max_genuine", ["1"]), |
|
76 |
("check_potential", ["false"]), |
|
77 |
("check_genuine", ["false"])] |
|
78 |
||
79 |
val negated_params = |
|
80 |
[("dont_box", "box"), |
|
81 |
("non_mono", "mono"), |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
82 |
("non_std", "std"), |
33192 | 83 |
("non_wf", "wf"), |
84 |
("non_blocking", "blocking"), |
|
85 |
("satisfy", "falsify"), |
|
86 |
("no_user_axioms", "user_axioms"), |
|
87 |
("no_assms", "assms"), |
|
33556
cba22e2999d5
renamed Nitpick option "coalesce_type_vars" to "merge_type_vars" (shorter) and cleaned up old hacks that are no longer necessary
blanchet
parents:
33232
diff
changeset
|
88 |
("dont_merge_type_vars", "merge_type_vars"), |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
89 |
("unary_ints", "binary_ints"), |
33192 | 90 |
("dont_destroy_constrs", "destroy_constrs"), |
91 |
("dont_specialize", "specialize"), |
|
92 |
("dont_skolemize", "skolemize"), |
|
93 |
("dont_star_linear_preds", "star_linear_preds"), |
|
94 |
("dont_uncurry", "uncurry"), |
|
95 |
("full_descrs", "fast_descrs"), |
|
96 |
("no_peephole_optim", "peephole_optim"), |
|
97 |
("dont_flatten_props", "flatten_props"), |
|
98 |
("quiet", "verbose"), |
|
99 |
("no_debug", "debug"), |
|
100 |
("no_overlord", "overlord"), |
|
101 |
("dont_show_all", "show_all"), |
|
102 |
("hide_skolems", "show_skolems"), |
|
103 |
("hide_datatypes", "show_datatypes"), |
|
104 |
("hide_consts", "show_consts"), |
|
105 |
("trust_potential", "check_potential"), |
|
106 |
("trust_genuine", "check_genuine")] |
|
107 |
||
108 |
(* string -> bool *) |
|
109 |
fun is_known_raw_param s = |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
110 |
AList.defined (op =) default_default_params s orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
111 |
AList.defined (op =) negated_params s orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
112 |
s = "max" orelse s = "eval" orelse s = "expect" orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
113 |
exists (fn p => String.isPrefix (p ^ " ") s) |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
114 |
["card", "max", "iter", "box", "dont_box", "mono", "non_mono", "std", |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
115 |
"non_std", "wf", "non_wf", "format"] |
33192 | 116 |
|
117 |
(* string * 'a -> unit *) |
|
118 |
fun check_raw_param (s, _) = |
|
119 |
if is_known_raw_param s then () |
|
120 |
else error ("Unknown parameter " ^ quote s ^ ".") |
|
121 |
||
122 |
(* string -> string option *) |
|
123 |
fun unnegate_param_name name = |
|
124 |
case AList.lookup (op =) negated_params name of |
|
125 |
NONE => if String.isPrefix "dont_" name then SOME (unprefix "dont_" name) |
|
126 |
else if String.isPrefix "non_" name then SOME (unprefix "non_" name) |
|
127 |
else NONE |
|
128 |
| some_name => some_name |
|
129 |
(* raw_param -> raw_param *) |
|
130 |
fun unnegate_raw_param (name, value) = |
|
131 |
case unnegate_param_name name of |
|
132 |
SOME name' => (name', case value of |
|
133 |
["false"] => ["true"] |
|
134 |
| ["true"] => ["false"] |
|
135 |
| [] => ["false"] |
|
136 |
| _ => value) |
|
137 |
| NONE => (name, value) |
|
138 |
||
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
139 |
structure Data = Theory_Data( |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
140 |
type T = {params: raw_param list} |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
141 |
val empty = {params = rev default_default_params} |
33192 | 142 |
val extend = I |
33599
89c439646960
recovered update from 7264824baf66, which got lost in 7264824baf66;
wenzelm
parents:
33584
diff
changeset
|
143 |
fun merge ({params = ps1}, {params = ps2}) : T = |
33699
f33b036ef318
permissive AList.merge -- most likely setup for theory data (beware of spurious AList.DUP);
wenzelm
parents:
33604
diff
changeset
|
144 |
{params = AList.merge (op =) (K true) (ps1, ps2)}) |
33192 | 145 |
|
146 |
(* raw_param -> theory -> theory *) |
|
147 |
fun set_default_raw_param param thy = |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
148 |
let val {params} = Data.get thy in |
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
149 |
Data.put {params = AList.update (op =) (unnegate_raw_param param) params} |
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
150 |
thy |
33192 | 151 |
end |
152 |
(* theory -> raw_param list *) |
|
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
153 |
val default_raw_params = #params o Data.get |
33192 | 154 |
|
155 |
(* string -> bool *) |
|
156 |
fun is_punctuation s = (s = "," orelse s = "-" orelse s = "\<midarrow>") |
|
157 |
||
158 |
(* string list -> string *) |
|
159 |
fun stringify_raw_param_value [] = "" |
|
160 |
| stringify_raw_param_value [s] = s |
|
161 |
| stringify_raw_param_value (s1 :: s2 :: ss) = |
|
162 |
s1 ^ (if is_punctuation s1 orelse is_punctuation s2 then "" else " ") ^ |
|
163 |
stringify_raw_param_value (s2 :: ss) |
|
164 |
||
165 |
(* bool -> string -> string -> bool option *) |
|
166 |
fun bool_option_from_string option name s = |
|
167 |
(case s of |
|
168 |
"smart" => if option then NONE else raise Option |
|
169 |
| "false" => SOME false |
|
170 |
| "true" => SOME true |
|
171 |
| "" => SOME true |
|
35280
54ab4921f826
fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents:
34982
diff
changeset
|
172 |
| _ => raise Option) |
33192 | 173 |
handle Option.Option => |
174 |
let val ss = map quote ((option ? cons "smart") ["true", "false"]) in |
|
175 |
error ("Parameter " ^ quote name ^ " must be assigned " ^ |
|
176 |
space_implode " " (serial_commas "or" ss) ^ ".") |
|
177 |
end |
|
178 |
(* bool -> raw_param list -> bool option -> string -> bool option *) |
|
179 |
fun general_lookup_bool option raw_params default_value name = |
|
180 |
case AList.lookup (op =) raw_params name of |
|
181 |
SOME s => s |> stringify_raw_param_value |
|
182 |
|> bool_option_from_string option name |
|
183 |
| NONE => default_value |
|
184 |
||
185 |
(* int -> string -> int *) |
|
186 |
fun maxed_int_from_string min_int s = Int.max (min_int, the (Int.fromString s)) |
|
187 |
||
188 |
(* Proof.context -> bool -> raw_param list -> raw_param list -> params *) |
|
189 |
fun extract_params ctxt auto default_params override_params = |
|
190 |
let |
|
191 |
val override_params = map unnegate_raw_param override_params |
|
192 |
val raw_params = rev override_params @ rev default_params |
|
193 |
val lookup = |
|
194 |
Option.map stringify_raw_param_value o AList.lookup (op =) raw_params |
|
195 |
(* string -> string *) |
|
196 |
fun lookup_string name = the_default "" (lookup name) |
|
197 |
(* string -> bool *) |
|
198 |
val lookup_bool = the o general_lookup_bool false raw_params (SOME false) |
|
199 |
(* string -> bool option *) |
|
200 |
val lookup_bool_option = general_lookup_bool true raw_params NONE |
|
201 |
(* string -> string option -> int *) |
|
202 |
fun do_int name value = |
|
203 |
case value of |
|
204 |
SOME s => (case Int.fromString s of |
|
205 |
SOME i => i |
|
206 |
| NONE => error ("Parameter " ^ quote name ^ |
|
207 |
" must be assigned an integer value.")) |
|
208 |
| NONE => 0 |
|
209 |
(* string -> int *) |
|
210 |
fun lookup_int name = do_int name (lookup name) |
|
211 |
(* string -> int option *) |
|
212 |
fun lookup_int_option name = |
|
213 |
case lookup name of |
|
214 |
SOME "smart" => NONE |
|
215 |
| value => SOME (do_int name value) |
|
216 |
(* string -> int -> string -> int list *) |
|
217 |
fun int_range_from_string name min_int s = |
|
218 |
let |
|
219 |
val (k1, k2) = |
|
220 |
(case space_explode "-" s of |
|
221 |
[s] => the_default (s, s) (first_field "\<midarrow>" s) |
|
222 |
| ["", s2] => ("-" ^ s2, "-" ^ s2) |
|
223 |
| [s1, s2] => (s1, s2) |
|
224 |
| _ => raise Option) |
|
225 |
|> pairself (maxed_int_from_string min_int) |
|
226 |
in if k1 <= k2 then k1 upto k2 else k1 downto k2 end |
|
227 |
handle Option.Option => |
|
228 |
error ("Parameter " ^ quote name ^ |
|
229 |
" must be assigned a sequence of integers.") |
|
230 |
(* string -> int -> string -> int list *) |
|
231 |
fun int_seq_from_string name min_int s = |
|
232 |
maps (int_range_from_string name min_int) (space_explode "," s) |
|
233 |
(* string -> int -> int list *) |
|
234 |
fun lookup_int_seq name min_int = |
|
235 |
case lookup name of |
|
236 |
SOME s => (case int_seq_from_string name min_int s of |
|
237 |
[] => [min_int] |
|
238 |
| value => value) |
|
239 |
| NONE => [min_int] |
|
240 |
(* (string -> 'a) -> int -> string -> ('a option * int list) list *) |
|
241 |
fun lookup_ints_assigns read prefix min_int = |
|
242 |
(NONE, lookup_int_seq prefix min_int) |
|
243 |
:: map (fn (name, value) => |
|
244 |
(SOME (read (String.extract (name, size prefix + 1, NONE))), |
|
245 |
value |> stringify_raw_param_value |
|
246 |
|> int_seq_from_string name min_int)) |
|
247 |
(filter (String.isPrefix (prefix ^ " ") o fst) raw_params) |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
248 |
(* (string -> 'a) -> string -> ('a option * bool) list *) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
249 |
fun lookup_bool_assigns read prefix = |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
250 |
(NONE, lookup_bool prefix) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
251 |
:: map (fn (name, value) => |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
252 |
(SOME (read (String.extract (name, size prefix + 1, NONE))), |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
253 |
value |> stringify_raw_param_value |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
254 |
|> bool_option_from_string false name |> the)) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
255 |
(filter (String.isPrefix (prefix ^ " ") o fst) raw_params) |
33192 | 256 |
(* (string -> 'a) -> string -> ('a option * bool option) list *) |
257 |
fun lookup_bool_option_assigns read prefix = |
|
258 |
(NONE, lookup_bool_option prefix) |
|
259 |
:: map (fn (name, value) => |
|
260 |
(SOME (read (String.extract (name, size prefix + 1, NONE))), |
|
261 |
value |> stringify_raw_param_value |
|
262 |
|> bool_option_from_string true name)) |
|
263 |
(filter (String.isPrefix (prefix ^ " ") o fst) raw_params) |
|
264 |
(* string -> Time.time option *) |
|
265 |
fun lookup_time name = |
|
266 |
case lookup name of |
|
267 |
NONE => NONE |
|
268 |
| SOME "none" => NONE |
|
269 |
| SOME s => |
|
270 |
let |
|
271 |
val msecs = |
|
272 |
case space_explode " " s of |
|
273 |
[s1, "min"] => 60000 * the (Int.fromString s1) |
|
274 |
| [s1, "s"] => 1000 * the (Int.fromString s1) |
|
275 |
| [s1, "ms"] => the (Int.fromString s1) |
|
276 |
| _ => 0 |
|
277 |
in |
|
278 |
if msecs <= 0 then |
|
279 |
error ("Parameter " ^ quote name ^ " must be assigned a positive \ |
|
280 |
\time value (e.g., \"60 s\", \"200 ms\") or \"none\".") |
|
281 |
else |
|
282 |
SOME (Time.fromMilliseconds msecs) |
|
283 |
end |
|
284 |
(* string -> term list *) |
|
285 |
val lookup_term_list = |
|
286 |
AList.lookup (op =) raw_params #> these #> Syntax.read_terms ctxt |
|
287 |
val read_type_polymorphic = |
|
288 |
Syntax.read_typ ctxt #> Logic.mk_type |
|
289 |
#> singleton (Variable.polymorphic ctxt) #> Logic.dest_type |
|
290 |
(* string -> term *) |
|
291 |
val read_term_polymorphic = |
|
292 |
Syntax.read_term ctxt #> singleton (Variable.polymorphic ctxt) |
|
293 |
(* string -> styp *) |
|
294 |
val read_const_polymorphic = read_term_polymorphic #> dest_Const |
|
295 |
val cards_assigns = lookup_ints_assigns read_type_polymorphic "card" 1 |
|
296 |
val maxes_assigns = lookup_ints_assigns read_const_polymorphic "max" ~1 |
|
297 |
val iters_assigns = lookup_ints_assigns read_const_polymorphic "iter" 0 |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
298 |
val bitss = lookup_int_seq "bits" 1 |
33192 | 299 |
val bisim_depths = lookup_int_seq "bisim_depth" ~1 |
300 |
val boxes = |
|
301 |
lookup_bool_option_assigns read_type_polymorphic "box" @ |
|
302 |
map_filter (fn (SOME T, _) => |
|
303 |
if is_fun_type T orelse is_pair_type T then |
|
304 |
SOME (SOME T, SOME true) |
|
305 |
else |
|
306 |
NONE |
|
307 |
| (NONE, _) => NONE) cards_assigns |
|
308 |
val monos = lookup_bool_option_assigns read_type_polymorphic "mono" |
|
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
309 |
val stds = lookup_bool_assigns read_type_polymorphic "std" |
33192 | 310 |
val wfs = lookup_bool_option_assigns read_const_polymorphic "wf" |
311 |
val sat_solver = lookup_string "sat_solver" |
|
312 |
val blocking = not auto andalso lookup_bool "blocking" |
|
313 |
val falsify = lookup_bool "falsify" |
|
314 |
val debug = not auto andalso lookup_bool "debug" |
|
315 |
val verbose = debug orelse (not auto andalso lookup_bool "verbose") |
|
316 |
val overlord = lookup_bool "overlord" |
|
317 |
val user_axioms = lookup_bool_option "user_axioms" |
|
318 |
val assms = lookup_bool "assms" |
|
33556
cba22e2999d5
renamed Nitpick option "coalesce_type_vars" to "merge_type_vars" (shorter) and cleaned up old hacks that are no longer necessary
blanchet
parents:
33232
diff
changeset
|
319 |
val merge_type_vars = lookup_bool "merge_type_vars" |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
320 |
val binary_ints = lookup_bool_option "binary_ints" |
33192 | 321 |
val destroy_constrs = lookup_bool "destroy_constrs" |
322 |
val specialize = lookup_bool "specialize" |
|
323 |
val skolemize = lookup_bool "skolemize" |
|
324 |
val star_linear_preds = lookup_bool "star_linear_preds" |
|
325 |
val uncurry = lookup_bool "uncurry" |
|
326 |
val fast_descrs = lookup_bool "fast_descrs" |
|
327 |
val peephole_optim = lookup_bool "peephole_optim" |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
328 |
val timeout = if auto then NONE else lookup_time "timeout" |
33192 | 329 |
val tac_timeout = lookup_time "tac_timeout" |
330 |
val sym_break = Int.max (0, lookup_int "sym_break") |
|
331 |
val sharing_depth = Int.max (1, lookup_int "sharing_depth") |
|
332 |
val flatten_props = lookup_bool "flatten_props" |
|
333 |
val max_threads = Int.max (0, lookup_int "max_threads") |
|
334 |
val show_all = debug orelse lookup_bool "show_all" |
|
335 |
val show_skolems = show_all orelse lookup_bool "show_skolems" |
|
336 |
val show_datatypes = show_all orelse lookup_bool "show_datatypes" |
|
337 |
val show_consts = show_all orelse lookup_bool "show_consts" |
|
338 |
val formats = lookup_ints_assigns read_term_polymorphic "format" 0 |
|
339 |
val evals = lookup_term_list "eval" |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
340 |
val max_potential = |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
341 |
if auto then 0 else Int.max (0, lookup_int "max_potential") |
33192 | 342 |
val max_genuine = Int.max (0, lookup_int "max_genuine") |
343 |
val check_potential = lookup_bool "check_potential" |
|
344 |
val check_genuine = lookup_bool "check_genuine" |
|
345 |
val batch_size = case lookup_int_option "batch_size" of |
|
346 |
SOME n => Int.max (1, n) |
|
347 |
| NONE => if debug then 1 else 64 |
|
348 |
val expect = lookup_string "expect" |
|
349 |
in |
|
350 |
{cards_assigns = cards_assigns, maxes_assigns = maxes_assigns, |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
351 |
iters_assigns = iters_assigns, bitss = bitss, bisim_depths = bisim_depths, |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
352 |
boxes = boxes, monos = monos, stds = stds, wfs = wfs, |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
353 |
sat_solver = sat_solver, blocking = blocking, falsify = falsify, |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
354 |
debug = debug, verbose = verbose, overlord = overlord, |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
355 |
user_axioms = user_axioms, assms = assms, |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
356 |
merge_type_vars = merge_type_vars, binary_ints = binary_ints, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
357 |
destroy_constrs = destroy_constrs, specialize = specialize, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
358 |
skolemize = skolemize, star_linear_preds = star_linear_preds, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
359 |
uncurry = uncurry, fast_descrs = fast_descrs, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
360 |
peephole_optim = peephole_optim, timeout = timeout, |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
361 |
tac_timeout = tac_timeout, sym_break = sym_break, |
33192 | 362 |
sharing_depth = sharing_depth, flatten_props = flatten_props, |
363 |
max_threads = max_threads, show_skolems = show_skolems, |
|
364 |
show_datatypes = show_datatypes, show_consts = show_consts, |
|
365 |
formats = formats, evals = evals, max_potential = max_potential, |
|
366 |
max_genuine = max_genuine, check_potential = check_potential, |
|
367 |
check_genuine = check_genuine, batch_size = batch_size, expect = expect} |
|
368 |
end |
|
369 |
||
370 |
(* theory -> (string * string) list -> params *) |
|
371 |
fun default_params thy = |
|
372 |
extract_params (ProofContext.init thy) false (default_raw_params thy) |
|
373 |
o map (apsnd single) |
|
374 |
||
375 |
(* OuterParse.token list -> string * OuterParse.token list *) |
|
376 |
val scan_key = Scan.repeat1 OuterParse.typ_group >> space_implode " " |
|
377 |
||
378 |
(* OuterParse.token list -> string list * OuterParse.token list *) |
|
379 |
val scan_value = |
|
380 |
Scan.repeat1 (OuterParse.minus >> single |
|
381 |
|| Scan.repeat1 (Scan.unless OuterParse.minus OuterParse.name) |
|
382 |
|| OuterParse.$$$ "," |-- OuterParse.number >> prefix "," |
|
383 |
>> single) >> flat |
|
384 |
||
385 |
(* OuterParse.token list -> raw_param * OuterParse.token list *) |
|
386 |
val scan_param = |
|
387 |
scan_key -- (Scan.option (OuterParse.$$$ "=" |-- scan_value) >> these) |
|
388 |
(* OuterParse.token list -> raw_param list option * OuterParse.token list *) |
|
389 |
val scan_params = Scan.option (OuterParse.$$$ "[" |-- OuterParse.list scan_param |
|
390 |
--| OuterParse.$$$ "]") |
|
391 |
||
392 |
(* Proof.context -> ('a -> 'a) -> 'a -> 'a *) |
|
393 |
fun handle_exceptions ctxt f x = |
|
394 |
f x |
|
395 |
handle ARG (loc, details) => |
|
396 |
error ("Bad argument(s) to " ^ quote loc ^ ": " ^ details ^ ".") |
|
397 |
| BAD (loc, details) => |
|
398 |
error ("Internal error (" ^ quote loc ^ "): " ^ details ^ ".") |
|
399 |
| NOT_SUPPORTED details => |
|
400 |
(warning ("Unsupported case: " ^ details ^ "."); x) |
|
401 |
| NUT (loc, us) => |
|
402 |
error ("Invalid intermediate term" ^ plural_s_for_list us ^ |
|
403 |
" (" ^ quote loc ^ "): " ^ |
|
404 |
commas (map (string_for_nut ctxt) us) ^ ".") |
|
405 |
| REP (loc, Rs) => |
|
406 |
error ("Invalid representation" ^ plural_s_for_list Rs ^ |
|
407 |
" (" ^ quote loc ^ "): " ^ commas (map string_for_rep Rs) ^ ".") |
|
408 |
| TERM (loc, ts) => |
|
409 |
error ("Invalid term" ^ plural_s_for_list ts ^ |
|
410 |
" (" ^ quote loc ^ "): " ^ |
|
411 |
commas (map (Syntax.string_of_term ctxt) ts) ^ ".") |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
412 |
| TOO_LARGE (_, details) => |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
413 |
(warning ("Limit reached: " ^ details ^ "."); x) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
414 |
| TOO_SMALL (_, details) => |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
415 |
(warning ("Limit reached: " ^ details ^ "."); x) |
33192 | 416 |
| TYPE (loc, Ts, ts) => |
417 |
error ("Invalid type" ^ plural_s_for_list Ts ^ |
|
418 |
(if null ts then |
|
419 |
"" |
|
420 |
else |
|
421 |
" for term" ^ plural_s_for_list ts ^ " " ^ |
|
422 |
commas (map (quote o Syntax.string_of_term ctxt) ts)) ^ |
|
423 |
" (" ^ quote loc ^ "): " ^ |
|
424 |
commas (map (Syntax.string_of_typ ctxt) Ts) ^ ".") |
|
425 |
| Kodkod.SYNTAX (_, details) => |
|
426 |
(warning ("Ill-formed Kodkodi output: " ^ details ^ "."); x) |
|
427 |
| Refute.REFUTE (loc, details) => |
|
428 |
error ("Unhandled Refute error (" ^ quote loc ^ "): " ^ details ^ ".") |
|
429 |
||
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
430 |
|
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
431 |
(* raw_param list -> bool -> int -> int -> Proof.state -> bool * Proof.state *) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
432 |
fun pick_nits override_params auto i step state = |
33192 | 433 |
let |
434 |
val thy = Proof.theory_of state |
|
435 |
val ctxt = Proof.context_of state |
|
436 |
val _ = List.app check_raw_param override_params |
|
437 |
val params as {blocking, debug, ...} = |
|
438 |
extract_params ctxt auto (default_raw_params thy) override_params |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
439 |
(* unit -> bool * Proof.state *) |
33192 | 440 |
fun go () = |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
441 |
(false, state) |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
442 |
|> (if auto then perhaps o try |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
443 |
else if debug then fn f => fn x => f x |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
444 |
else handle_exceptions ctxt) |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
445 |
(fn (_, state) => pick_nits_in_subgoal state params auto i step |
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
446 |
|>> curry (op =) "genuine") |
33192 | 447 |
in |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
448 |
if auto orelse blocking then go () |
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33601
diff
changeset
|
449 |
else (Toplevel.thread true (fn () => (go (); ())); (false, state)) |
33192 | 450 |
end |
451 |
||
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
452 |
(* raw_param list option * int option -> Toplevel.transition |
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
453 |
-> Toplevel.transition *) |
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
454 |
fun nitpick_trans (opt_params, opt_i) = |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
455 |
Toplevel.keep (fn st => |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
456 |
(pick_nits (these opt_params) false (the_default 1 opt_i) |
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
457 |
(Toplevel.proof_position_of st) (Toplevel.proof_of st); ())) |
33192 | 458 |
|
459 |
(* raw_param -> string *) |
|
460 |
fun string_for_raw_param (name, value) = |
|
461 |
name ^ " = " ^ stringify_raw_param_value value |
|
462 |
||
34121
5e831d805118
get rid of polymorphic equality in Nitpick's code + a few minor cleanups
blanchet
parents:
33982
diff
changeset
|
463 |
(* raw_param list option -> Toplevel.transition -> Toplevel.transition *) |
33192 | 464 |
fun nitpick_params_trans opt_params = |
465 |
Toplevel.theory |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
466 |
(fold set_default_raw_param (these opt_params) |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
467 |
#> tap (fn thy => |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
468 |
writeln ("Default parameters for Nitpick:\n" ^ |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
469 |
(case rev (default_raw_params thy) of |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
470 |
[] => "none" |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
471 |
| params => |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
472 |
(map check_raw_param params; |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
473 |
params |> map string_for_raw_param |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
474 |
|> sort_strings |> cat_lines))))) |
33192 | 475 |
|
476 |
(* OuterParse.token list |
|
477 |
-> (Toplevel.transition -> Toplevel.transition) * OuterParse.token list *) |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
478 |
val scan_nitpick_command = |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
479 |
(scan_params -- Scan.option OuterParse.nat) #>> nitpick_trans |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
480 |
val scan_nitpick_params_command = scan_params #>> nitpick_params_trans |
33192 | 481 |
|
482 |
val _ = OuterSyntax.improper_command "nitpick" |
|
483 |
"try to find a counterexample for a given subgoal using Kodkod" |
|
484 |
OuterKeyword.diag scan_nitpick_command |
|
485 |
val _ = OuterSyntax.command "nitpick_params" |
|
486 |
"set and display the default parameters for Nitpick" |
|
487 |
OuterKeyword.thy_decl scan_nitpick_params_command |
|
488 |
||
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
489 |
(* Proof.state -> bool * Proof.state *) |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
490 |
fun auto_nitpick state = |
34982
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents:
34936
diff
changeset
|
491 |
if not (!auto) then (false, state) else pick_nits [] true 1 0 state |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
492 |
|
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
493 |
val setup = Auto_Counterexample.register_tool ("nitpick", auto_nitpick) |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
494 |
|
33192 | 495 |
end; |