author | wenzelm |
Mon, 17 May 2010 23:54:15 +0200 | |
changeset 36960 | 01594f816e3a |
parent 36610 | bafd82950e24 |
child 37169 | f69efa106feb |
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 |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
35665
diff
changeset
|
16 |
end; |
33192 | 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 = |
|
35964 | 37 |
[("card", "1\<midarrow>8"), |
38 |
("iter", "0,1,2,4,8,12,16,24"), |
|
39 |
("bits", "1,2,3,4,6,8,10,12"), |
|
40 |
("bisim_depth", "7"), |
|
41 |
("box", "smart"), |
|
42 |
("finitize", "smart"), |
|
43 |
("mono", "smart"), |
|
44 |
("std", "true"), |
|
45 |
("wf", "smart"), |
|
46 |
("sat_solver", "smart"), |
|
47 |
("batch_size", "smart"), |
|
48 |
("blocking", "true"), |
|
49 |
("falsify", "true"), |
|
50 |
("user_axioms", "smart"), |
|
51 |
("assms", "true"), |
|
52 |
("merge_type_vars", "false"), |
|
53 |
("binary_ints", "smart"), |
|
54 |
("destroy_constrs", "true"), |
|
55 |
("specialize", "true"), |
|
56 |
("star_linear_preds", "true"), |
|
57 |
("fast_descrs", "true"), |
|
58 |
("peephole_optim", "true"), |
|
59 |
("timeout", "30 s"), |
|
60 |
("tac_timeout", "500 ms"), |
|
61 |
("max_threads", "0"), |
|
62 |
("debug", "false"), |
|
63 |
("verbose", "false"), |
|
64 |
("overlord", "false"), |
|
65 |
("show_all", "false"), |
|
66 |
("show_datatypes", "false"), |
|
67 |
("show_consts", "false"), |
|
68 |
("format", "1"), |
|
69 |
("max_potential", "1"), |
|
70 |
("max_genuine", "1"), |
|
71 |
("check_potential", "false"), |
|
72 |
("check_genuine", "false")] |
|
33192 | 73 |
|
74 |
val negated_params = |
|
75 |
[("dont_box", "box"), |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
76 |
("dont_finitize", "finitize"), |
33192 | 77 |
("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
|
78 |
("non_std", "std"), |
33192 | 79 |
("non_wf", "wf"), |
80 |
("non_blocking", "blocking"), |
|
81 |
("satisfy", "falsify"), |
|
82 |
("no_user_axioms", "user_axioms"), |
|
83 |
("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
|
84 |
("dont_merge_type_vars", "merge_type_vars"), |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
85 |
("unary_ints", "binary_ints"), |
33192 | 86 |
("dont_destroy_constrs", "destroy_constrs"), |
87 |
("dont_specialize", "specialize"), |
|
88 |
("dont_star_linear_preds", "star_linear_preds"), |
|
89 |
("full_descrs", "fast_descrs"), |
|
90 |
("no_peephole_optim", "peephole_optim"), |
|
35964 | 91 |
("no_debug", "debug"), |
33192 | 92 |
("quiet", "verbose"), |
93 |
("no_overlord", "overlord"), |
|
94 |
("dont_show_all", "show_all"), |
|
95 |
("hide_datatypes", "show_datatypes"), |
|
96 |
("hide_consts", "show_consts"), |
|
97 |
("trust_potential", "check_potential"), |
|
98 |
("trust_genuine", "check_genuine")] |
|
99 |
||
100 |
fun is_known_raw_param s = |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
101 |
AList.defined (op =) default_default_params s orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
102 |
AList.defined (op =) negated_params s orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
103 |
s = "max" orelse s = "eval" orelse s = "expect" orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
104 |
exists (fn p => String.isPrefix (p ^ " ") s) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
105 |
["card", "max", "iter", "box", "dont_box", "finitize", "dont_finitize", |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
106 |
"mono", "non_mono", "std", "non_std", "wf", "non_wf", "format"] |
33192 | 107 |
|
108 |
fun check_raw_param (s, _) = |
|
109 |
if is_known_raw_param s then () |
|
35964 | 110 |
else error ("Unknown parameter: " ^ quote s ^ ".") |
33192 | 111 |
|
112 |
fun unnegate_param_name name = |
|
113 |
case AList.lookup (op =) negated_params name of |
|
114 |
NONE => if String.isPrefix "dont_" name then SOME (unprefix "dont_" name) |
|
115 |
else if String.isPrefix "non_" name then SOME (unprefix "non_" name) |
|
116 |
else NONE |
|
117 |
| some_name => some_name |
|
118 |
fun unnegate_raw_param (name, value) = |
|
119 |
case unnegate_param_name name of |
|
120 |
SOME name' => (name', case value of |
|
121 |
["false"] => ["true"] |
|
122 |
| ["true"] => ["false"] |
|
123 |
| [] => ["false"] |
|
124 |
| _ => value) |
|
125 |
| NONE => (name, value) |
|
126 |
||
33583
b5e0909cd5ea
merged, and renamed local "TheoryData" to "Data" (following common Isabelle conventions)
blanchet
diff
changeset
|
127 |
structure Data = Theory_Data( |
35964 | 128 |
type T = raw_param list |
36391 | 129 |
val empty = map (apsnd single) default_default_params |
33192 | 130 |
val extend = I |
36607
e5f7235f39c5
made sml/nj happy about Sledgehammer and Nitpick (cf. 6f11c9b1fb3e, 3c2438efe224)
krauss
parents:
36391
diff
changeset
|
131 |
fun merge (x, y) = AList.merge (op =) (K true) (x, y)) |
33192 | 132 |
|
35964 | 133 |
val set_default_raw_param = Data.map o AList.update (op =) o unnegate_raw_param |
134 |
val default_raw_params = Data.get |
|
33192 | 135 |
|
136 |
fun is_punctuation s = (s = "," orelse s = "-" orelse s = "\<midarrow>") |
|
137 |
||
138 |
fun stringify_raw_param_value [] = "" |
|
139 |
| stringify_raw_param_value [s] = s |
|
140 |
| stringify_raw_param_value (s1 :: s2 :: ss) = |
|
141 |
s1 ^ (if is_punctuation s1 orelse is_punctuation s2 then "" else " ") ^ |
|
142 |
stringify_raw_param_value (s2 :: ss) |
|
143 |
||
144 |
fun maxed_int_from_string min_int s = Int.max (min_int, the (Int.fromString s)) |
|
145 |
||
146 |
fun extract_params ctxt auto default_params override_params = |
|
147 |
let |
|
148 |
val override_params = map unnegate_raw_param override_params |
|
149 |
val raw_params = rev override_params @ rev default_params |
|
150 |
val lookup = |
|
151 |
Option.map stringify_raw_param_value o AList.lookup (op =) raw_params |
|
35964 | 152 |
val lookup_string = the_default "" o lookup |
153 |
fun general_lookup_bool option default_value name = |
|
154 |
case lookup name of |
|
36380
1e8fcaccb3e8
stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents:
35968
diff
changeset
|
155 |
SOME s => parse_bool_option option name s |
35964 | 156 |
| NONE => default_value |
157 |
val lookup_bool = the o general_lookup_bool false (SOME false) |
|
158 |
val lookup_bool_option = general_lookup_bool true NONE |
|
33192 | 159 |
fun do_int name value = |
160 |
case value of |
|
161 |
SOME s => (case Int.fromString s of |
|
162 |
SOME i => i |
|
163 |
| NONE => error ("Parameter " ^ quote name ^ |
|
164 |
" must be assigned an integer value.")) |
|
165 |
| NONE => 0 |
|
166 |
fun lookup_int name = do_int name (lookup name) |
|
167 |
fun lookup_int_option name = |
|
168 |
case lookup name of |
|
169 |
SOME "smart" => NONE |
|
170 |
| value => SOME (do_int name value) |
|
171 |
fun int_range_from_string name min_int s = |
|
172 |
let |
|
173 |
val (k1, k2) = |
|
174 |
(case space_explode "-" s of |
|
175 |
[s] => the_default (s, s) (first_field "\<midarrow>" s) |
|
176 |
| ["", s2] => ("-" ^ s2, "-" ^ s2) |
|
177 |
| [s1, s2] => (s1, s2) |
|
178 |
| _ => raise Option) |
|
179 |
|> pairself (maxed_int_from_string min_int) |
|
180 |
in if k1 <= k2 then k1 upto k2 else k1 downto k2 end |
|
181 |
handle Option.Option => |
|
182 |
error ("Parameter " ^ quote name ^ |
|
183 |
" must be assigned a sequence of integers.") |
|
184 |
fun int_seq_from_string name min_int s = |
|
185 |
maps (int_range_from_string name min_int) (space_explode "," s) |
|
186 |
fun lookup_int_seq name min_int = |
|
187 |
case lookup name of |
|
188 |
SOME s => (case int_seq_from_string name min_int s of |
|
189 |
[] => [min_int] |
|
190 |
| value => value) |
|
191 |
| NONE => [min_int] |
|
192 |
fun lookup_ints_assigns read prefix min_int = |
|
193 |
(NONE, lookup_int_seq prefix min_int) |
|
194 |
:: map (fn (name, value) => |
|
195 |
(SOME (read (String.extract (name, size prefix + 1, NONE))), |
|
196 |
value |> stringify_raw_param_value |
|
197 |
|> int_seq_from_string name min_int)) |
|
198 |
(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
|
199 |
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
|
200 |
(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
|
201 |
:: 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
|
202 |
(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
|
203 |
value |> stringify_raw_param_value |
36380
1e8fcaccb3e8
stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents:
35968
diff
changeset
|
204 |
|> parse_bool_option false name |> the)) |
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
|
205 |
(filter (String.isPrefix (prefix ^ " ") o fst) raw_params) |
33192 | 206 |
fun lookup_bool_option_assigns read prefix = |
207 |
(NONE, lookup_bool_option prefix) |
|
208 |
:: map (fn (name, value) => |
|
209 |
(SOME (read (String.extract (name, size prefix + 1, NONE))), |
|
210 |
value |> stringify_raw_param_value |
|
36380
1e8fcaccb3e8
stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents:
35968
diff
changeset
|
211 |
|> parse_bool_option true name)) |
33192 | 212 |
(filter (String.isPrefix (prefix ^ " ") o fst) raw_params) |
213 |
fun lookup_time name = |
|
214 |
case lookup name of |
|
215 |
NONE => NONE |
|
36380
1e8fcaccb3e8
stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents:
35968
diff
changeset
|
216 |
| SOME s => parse_time_option name s |
33192 | 217 |
val lookup_term_list = |
218 |
AList.lookup (op =) raw_params #> these #> Syntax.read_terms ctxt |
|
219 |
val read_type_polymorphic = |
|
220 |
Syntax.read_typ ctxt #> Logic.mk_type |
|
221 |
#> singleton (Variable.polymorphic ctxt) #> Logic.dest_type |
|
222 |
val read_term_polymorphic = |
|
223 |
Syntax.read_term ctxt #> singleton (Variable.polymorphic ctxt) |
|
224 |
val read_const_polymorphic = read_term_polymorphic #> dest_Const |
|
225 |
val cards_assigns = lookup_ints_assigns read_type_polymorphic "card" 1 |
|
226 |
val maxes_assigns = lookup_ints_assigns read_const_polymorphic "max" ~1 |
|
227 |
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
|
228 |
val bitss = lookup_int_seq "bits" 1 |
33192 | 229 |
val bisim_depths = lookup_int_seq "bisim_depth" ~1 |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
230 |
val boxes = lookup_bool_option_assigns read_type_polymorphic "box" |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
231 |
val finitizes = lookup_bool_option_assigns read_type_polymorphic "finitize" |
33192 | 232 |
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
|
233 |
val stds = lookup_bool_assigns read_type_polymorphic "std" |
33192 | 234 |
val wfs = lookup_bool_option_assigns read_const_polymorphic "wf" |
235 |
val sat_solver = lookup_string "sat_solver" |
|
236 |
val blocking = not auto andalso lookup_bool "blocking" |
|
237 |
val falsify = lookup_bool "falsify" |
|
238 |
val debug = not auto andalso lookup_bool "debug" |
|
239 |
val verbose = debug orelse (not auto andalso lookup_bool "verbose") |
|
240 |
val overlord = lookup_bool "overlord" |
|
241 |
val user_axioms = lookup_bool_option "user_axioms" |
|
242 |
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
|
243 |
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
|
244 |
val binary_ints = lookup_bool_option "binary_ints" |
33192 | 245 |
val destroy_constrs = lookup_bool "destroy_constrs" |
246 |
val specialize = lookup_bool "specialize" |
|
247 |
val star_linear_preds = lookup_bool "star_linear_preds" |
|
248 |
val fast_descrs = lookup_bool "fast_descrs" |
|
249 |
val peephole_optim = lookup_bool "peephole_optim" |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
250 |
val timeout = if auto then NONE else lookup_time "timeout" |
33192 | 251 |
val tac_timeout = lookup_time "tac_timeout" |
252 |
val max_threads = Int.max (0, lookup_int "max_threads") |
|
253 |
val show_all = debug orelse lookup_bool "show_all" |
|
254 |
val show_datatypes = show_all orelse lookup_bool "show_datatypes" |
|
255 |
val show_consts = show_all orelse lookup_bool "show_consts" |
|
256 |
val formats = lookup_ints_assigns read_term_polymorphic "format" 0 |
|
257 |
val evals = lookup_term_list "eval" |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
258 |
val max_potential = |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
259 |
if auto then 0 else Int.max (0, lookup_int "max_potential") |
33192 | 260 |
val max_genuine = Int.max (0, lookup_int "max_genuine") |
261 |
val check_potential = lookup_bool "check_potential" |
|
262 |
val check_genuine = lookup_bool "check_genuine" |
|
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
263 |
val batch_size = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
264 |
case lookup_int_option "batch_size" of |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
265 |
SOME n => Int.max (1, n) |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
266 |
| NONE => if debug then 1 else 64 |
33192 | 267 |
val expect = lookup_string "expect" |
268 |
in |
|
269 |
{cards_assigns = cards_assigns, maxes_assigns = maxes_assigns, |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
270 |
iters_assigns = iters_assigns, bitss = bitss, bisim_depths = bisim_depths, |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
271 |
boxes = boxes, finitizes = finitizes, monos = monos, stds = stds, |
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
272 |
wfs = wfs, sat_solver = sat_solver, blocking = blocking, falsify = falsify, |
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
|
273 |
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
|
274 |
user_axioms = user_axioms, assms = assms, |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
275 |
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
|
276 |
destroy_constrs = destroy_constrs, specialize = specialize, |
36389
8228b3a4a2ba
remove "skolemize" option from Nitpick, since Skolemization is always useful
blanchet
parents:
36388
diff
changeset
|
277 |
star_linear_preds = star_linear_preds, fast_descrs = fast_descrs, |
8228b3a4a2ba
remove "skolemize" option from Nitpick, since Skolemization is always useful
blanchet
parents:
36388
diff
changeset
|
278 |
peephole_optim = peephole_optim, timeout = timeout, |
8228b3a4a2ba
remove "skolemize" option from Nitpick, since Skolemization is always useful
blanchet
parents:
36388
diff
changeset
|
279 |
tac_timeout = tac_timeout, max_threads = max_threads, |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
280 |
show_datatypes = show_datatypes, show_consts = show_consts, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
281 |
formats = formats, evals = evals, max_potential = max_potential, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
282 |
max_genuine = max_genuine, check_potential = check_potential, |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
283 |
check_genuine = check_genuine, batch_size = batch_size, expect = expect} |
33192 | 284 |
end |
285 |
||
286 |
fun default_params thy = |
|
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36607
diff
changeset
|
287 |
extract_params (ProofContext.init_global thy) false (default_raw_params thy) |
33192 | 288 |
o map (apsnd single) |
289 |
||
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
290 |
val parse_key = Scan.repeat1 Parse.typ_group >> space_implode " " |
35964 | 291 |
val parse_value = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
292 |
Scan.repeat1 (Parse.minus >> single |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
293 |
|| Scan.repeat1 (Scan.unless Parse.minus Parse.name) |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
294 |
|| Parse.$$$ "," |-- Parse.number >> prefix "," >> single) >> flat |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
295 |
val parse_param = parse_key -- Scan.optional (Parse.$$$ "=" |-- parse_value) [] |
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
296 |
val parse_params = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
297 |
Scan.optional (Parse.$$$ "[" |-- Parse.list parse_param --| Parse.$$$ "]") [] |
33192 | 298 |
|
299 |
fun handle_exceptions ctxt f x = |
|
300 |
f x |
|
301 |
handle ARG (loc, details) => |
|
302 |
error ("Bad argument(s) to " ^ quote loc ^ ": " ^ details ^ ".") |
|
303 |
| BAD (loc, details) => |
|
304 |
error ("Internal error (" ^ quote loc ^ "): " ^ details ^ ".") |
|
305 |
| NOT_SUPPORTED details => |
|
306 |
(warning ("Unsupported case: " ^ details ^ "."); x) |
|
307 |
| NUT (loc, us) => |
|
308 |
error ("Invalid intermediate term" ^ plural_s_for_list us ^ |
|
309 |
" (" ^ quote loc ^ "): " ^ |
|
310 |
commas (map (string_for_nut ctxt) us) ^ ".") |
|
311 |
| REP (loc, Rs) => |
|
312 |
error ("Invalid representation" ^ plural_s_for_list Rs ^ |
|
313 |
" (" ^ quote loc ^ "): " ^ commas (map string_for_rep Rs) ^ ".") |
|
314 |
| TERM (loc, ts) => |
|
315 |
error ("Invalid term" ^ plural_s_for_list ts ^ |
|
316 |
" (" ^ quote loc ^ "): " ^ |
|
317 |
commas (map (Syntax.string_of_term ctxt) ts) ^ ".") |
|
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
318 |
| TOO_LARGE (_, details) => |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
319 |
(warning ("Limit reached: " ^ details ^ "."); x) |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
320 |
| TOO_SMALL (_, details) => |
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
321 |
(warning ("Limit reached: " ^ details ^ "."); x) |
33192 | 322 |
| TYPE (loc, Ts, ts) => |
323 |
error ("Invalid type" ^ plural_s_for_list Ts ^ |
|
324 |
(if null ts then |
|
325 |
"" |
|
326 |
else |
|
327 |
" for term" ^ plural_s_for_list ts ^ " " ^ |
|
328 |
commas (map (quote o Syntax.string_of_term ctxt) ts)) ^ |
|
329 |
" (" ^ quote loc ^ "): " ^ |
|
330 |
commas (map (Syntax.string_of_typ ctxt) Ts) ^ ".") |
|
331 |
| Kodkod.SYNTAX (_, details) => |
|
332 |
(warning ("Ill-formed Kodkodi output: " ^ details ^ "."); x) |
|
333 |
| Refute.REFUTE (loc, details) => |
|
334 |
error ("Unhandled Refute error (" ^ quote loc ^ "): " ^ details ^ ".") |
|
335 |
||
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
|
336 |
fun pick_nits override_params auto i step state = |
33192 | 337 |
let |
338 |
val thy = Proof.theory_of state |
|
339 |
val ctxt = Proof.context_of state |
|
340 |
val _ = List.app check_raw_param override_params |
|
341 |
val params as {blocking, debug, ...} = |
|
342 |
extract_params ctxt auto (default_raw_params thy) override_params |
|
343 |
fun go () = |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
344 |
(false, state) |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
345 |
|> (if auto then perhaps o try |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
346 |
else if debug then fn f => fn x => f x |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
347 |
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
|
348 |
(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
|
349 |
|>> curry (op =) "genuine") |
33192 | 350 |
in |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
351 |
if auto orelse blocking then go () |
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33601
diff
changeset
|
352 |
else (Toplevel.thread true (fn () => (go (); ())); (false, state)) |
33192 | 353 |
end |
354 |
||
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
355 |
fun nitpick_trans (params, 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
|
356 |
Toplevel.keep (fn st => |
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
357 |
(pick_nits params false i (Toplevel.proof_position_of st) |
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
358 |
(Toplevel.proof_of st); ())) |
33192 | 359 |
|
360 |
fun string_for_raw_param (name, value) = |
|
361 |
name ^ " = " ^ stringify_raw_param_value value |
|
362 |
||
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
363 |
fun nitpick_params_trans params = |
33192 | 364 |
Toplevel.theory |
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
365 |
(fold set_default_raw_param params |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
366 |
#> tap (fn thy => |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
367 |
writeln ("Default parameters for Nitpick:\n" ^ |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
368 |
(case rev (default_raw_params thy) of |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
369 |
[] => "none" |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
370 |
| params => |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
371 |
(map check_raw_param params; |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
372 |
params |> map string_for_raw_param |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
373 |
|> sort_strings |> cat_lines))))) |
33192 | 374 |
|
35964 | 375 |
val parse_nitpick_command = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
376 |
(parse_params -- Scan.optional Parse.nat 1) #>> nitpick_trans |
35964 | 377 |
val parse_nitpick_params_command = parse_params #>> nitpick_params_trans |
33192 | 378 |
|
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
379 |
val _ = Outer_Syntax.improper_command "nitpick" |
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
380 |
"try to find a counterexample for a given subgoal using Nitpick" |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
381 |
Keyword.diag parse_nitpick_command |
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
382 |
val _ = Outer_Syntax.command "nitpick_params" |
33192 | 383 |
"set and display the default parameters for Nitpick" |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
384 |
Keyword.thy_decl parse_nitpick_params_command |
33192 | 385 |
|
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
386 |
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
|
387 |
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
|
388 |
|
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
389 |
val setup = Auto_Counterexample.register_tool ("nitpick", auto_nitpick) |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
390 |
|
33192 | 391 |
end; |