author | blanchet |
Thu, 19 Dec 2013 13:43:21 +0100 | |
changeset 54816 | 10d48c2a3e32 |
parent 54546 | 8b403a7a8c44 |
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 |
||
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
13 |
val nitpickN : string |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
14 |
val nitpick_paramsN : string |
33192 | 15 |
val default_params : theory -> (string * string) list -> params |
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 |
||
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
27 |
val nitpickN = "nitpick" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
28 |
val nitpick_paramsN = "nitpick_params" |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
29 |
|
39344 | 30 |
(* Maximum number of scopes for Auto Nitpick. Be frugal since it has to share |
31 |
its time slot with several other automatic tools. *) |
|
43022 | 32 |
val auto_try_max_scopes = 6 |
39344 | 33 |
|
33601
4608243edcfc
plain add_preference, no setmp_CRITICAL required;
wenzelm
parents:
33599
diff
changeset
|
34 |
val _ = |
52639 | 35 |
ProofGeneral.preference_option ProofGeneral.category_tracing |
52017
bc0238c1f73a
clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents:
52007
diff
changeset
|
36 |
NONE |
52639 | 37 |
@{option auto_nitpick} |
52017
bc0238c1f73a
clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents:
52007
diff
changeset
|
38 |
"auto-nitpick" |
bc0238c1f73a
clarified preferences: "override" re-initialized on prover startup, and "default" sent to PG -- thus recover typical defaults like auto-quickcheck in PG 4.x;
wenzelm
parents:
52007
diff
changeset
|
39 |
"Run Nitpick automatically" |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
40 |
|
33192 | 41 |
type raw_param = string * string list |
42 |
||
43 |
val default_default_params = |
|
42959 | 44 |
[("card", "1\<emdash>10"), |
38180
7a88032f9265
bump up the max cardinalities, to use up more of the time given to us by the user
blanchet
parents:
38127
diff
changeset
|
45 |
("iter", "0,1,2,4,8,12,16,20,24,28"), |
49618
29be73b789f9
lower the defaults for the number of bits, based on an example by Lukas Bulwahn
blanchet
parents:
46961
diff
changeset
|
46 |
("bits", "1\<emdash>10"), |
38180
7a88032f9265
bump up the max cardinalities, to use up more of the time given to us by the user
blanchet
parents:
38127
diff
changeset
|
47 |
("bisim_depth", "9"), |
35964 | 48 |
("box", "smart"), |
49 |
("finitize", "smart"), |
|
50 |
("mono", "smart"), |
|
51 |
("std", "true"), |
|
52 |
("wf", "smart"), |
|
53 |
("sat_solver", "smart"), |
|
54 |
("batch_size", "smart"), |
|
55 |
("blocking", "true"), |
|
56 |
("falsify", "true"), |
|
57 |
("user_axioms", "smart"), |
|
58 |
("assms", "true"), |
|
59 |
("merge_type_vars", "false"), |
|
60 |
("binary_ints", "smart"), |
|
61 |
("destroy_constrs", "true"), |
|
62 |
("specialize", "true"), |
|
63 |
("star_linear_preds", "true"), |
|
41856 | 64 |
("total_consts", "smart"), |
35964 | 65 |
("peephole_optim", "true"), |
38127 | 66 |
("datatype_sym_break", "5"), |
67 |
("kodkod_sym_break", "15"), |
|
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39359
diff
changeset
|
68 |
("timeout", "30"), |
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39359
diff
changeset
|
69 |
("tac_timeout", "0.5"), |
35964 | 70 |
("max_threads", "0"), |
71 |
("debug", "false"), |
|
72 |
("verbose", "false"), |
|
73 |
("overlord", "false"), |
|
53802 | 74 |
("spy", "false"), |
35964 | 75 |
("show_datatypes", "false"), |
41993
bd6296de1432
reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents:
41876
diff
changeset
|
76 |
("show_skolems", "true"), |
35964 | 77 |
("show_consts", "false"), |
78 |
("format", "1"), |
|
79 |
("max_potential", "1"), |
|
80 |
("max_genuine", "1"), |
|
81 |
("check_potential", "false"), |
|
82 |
("check_genuine", "false")] |
|
33192 | 83 |
|
84 |
val negated_params = |
|
85 |
[("dont_box", "box"), |
|
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
86 |
("dont_finitize", "finitize"), |
33192 | 87 |
("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
|
88 |
("non_std", "std"), |
33192 | 89 |
("non_wf", "wf"), |
90 |
("non_blocking", "blocking"), |
|
91 |
("satisfy", "falsify"), |
|
92 |
("no_user_axioms", "user_axioms"), |
|
93 |
("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
|
94 |
("dont_merge_type_vars", "merge_type_vars"), |
34124
c4628a1dcf75
added support for binary nat/int representation to Nitpick
blanchet
parents:
34121
diff
changeset
|
95 |
("unary_ints", "binary_ints"), |
33192 | 96 |
("dont_destroy_constrs", "destroy_constrs"), |
97 |
("dont_specialize", "specialize"), |
|
98 |
("dont_star_linear_preds", "star_linear_preds"), |
|
41856 | 99 |
("partial_consts", "total_consts"), |
33192 | 100 |
("no_peephole_optim", "peephole_optim"), |
35964 | 101 |
("no_debug", "debug"), |
33192 | 102 |
("quiet", "verbose"), |
103 |
("no_overlord", "overlord"), |
|
53802 | 104 |
("dont_spy", "spy"), |
33192 | 105 |
("hide_datatypes", "show_datatypes"), |
41993
bd6296de1432
reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents:
41876
diff
changeset
|
106 |
("hide_skolems", "show_skolems"), |
33192 | 107 |
("hide_consts", "show_consts"), |
108 |
("trust_potential", "check_potential"), |
|
109 |
("trust_genuine", "check_genuine")] |
|
110 |
||
111 |
fun is_known_raw_param s = |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
112 |
AList.defined (op =) default_default_params s orelse |
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
113 |
AList.defined (op =) negated_params s orelse |
41876 | 114 |
member (op =) ["max", "show_all", "whack", "eval", "need", "atoms", |
115 |
"expect"] s orelse |
|
34936
c4f04bee79f3
some work on Nitpick's support for quotient types;
blanchet
parents:
34124
diff
changeset
|
116 |
exists (fn p => String.isPrefix (p ^ " ") s) |
35665
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents:
35280
diff
changeset
|
117 |
["card", "max", "iter", "box", "dont_box", "finitize", "dont_finitize", |
41876 | 118 |
"mono", "non_mono", "std", "non_std", "wf", "non_wf", "format", |
119 |
"atoms"] |
|
33192 | 120 |
|
121 |
fun check_raw_param (s, _) = |
|
122 |
if is_known_raw_param s then () |
|
39316
b6c4385ab400
change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents:
39155
diff
changeset
|
123 |
else error ("Unknown parameter: " ^ quote s ^ ".") |
33192 | 124 |
|
125 |
fun unnegate_param_name name = |
|
126 |
case AList.lookup (op =) negated_params name of |
|
127 |
NONE => if String.isPrefix "dont_" name then SOME (unprefix "dont_" name) |
|
128 |
else if String.isPrefix "non_" name then SOME (unprefix "non_" name) |
|
129 |
else NONE |
|
130 |
| some_name => some_name |
|
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
131 |
fun normalize_raw_param (name, value) = |
33192 | 132 |
case unnegate_param_name name of |
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
133 |
SOME name' => [(name', case value of |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
134 |
["false"] => ["true"] |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
135 |
| ["true"] => ["false"] |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
136 |
| [] => ["false"] |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
137 |
| _ => value)] |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
138 |
| NONE => if name = "show_all" then |
41993
bd6296de1432
reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents:
41876
diff
changeset
|
139 |
[("show_datatypes", value), ("show_skolems", value), |
bd6296de1432
reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents:
41876
diff
changeset
|
140 |
("show_consts", value)] |
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
141 |
else |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
142 |
[(name, value)] |
33192 | 143 |
|
41472
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents:
40931
diff
changeset
|
144 |
structure Data = Theory_Data |
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents:
40931
diff
changeset
|
145 |
( |
35964 | 146 |
type T = raw_param list |
54546
8b403a7a8c44
fixed spying so that the envirnoment variables are queried at run-time not at build-time
blanchet
parents:
53802
diff
changeset
|
147 |
val empty = default_default_params |> map (apsnd single) |
33192 | 148 |
val extend = I |
41472
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents:
40931
diff
changeset
|
149 |
fun merge data = AList.merge (op =) (K true) data |
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents:
40931
diff
changeset
|
150 |
) |
33192 | 151 |
|
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
152 |
val set_default_raw_param = |
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
153 |
Data.map o fold (AList.update (op =)) o normalize_raw_param |
35964 | 154 |
val default_raw_params = Data.get |
33192 | 155 |
|
42959 | 156 |
fun is_punctuation s = (s = "," orelse s = "-" orelse s = "\<emdash>") |
33192 | 157 |
|
158 |
fun stringify_raw_param_value [] = "" |
|
159 |
| stringify_raw_param_value [s] = s |
|
160 |
| stringify_raw_param_value (s1 :: s2 :: ss) = |
|
161 |
s1 ^ (if is_punctuation s1 orelse is_punctuation s2 then "" else " ") ^ |
|
162 |
stringify_raw_param_value (s2 :: ss) |
|
163 |
||
164 |
fun maxed_int_from_string min_int s = Int.max (min_int, the (Int.fromString s)) |
|
165 |
||
43022 | 166 |
fun extract_params ctxt mode default_params override_params = |
33192 | 167 |
let |
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
168 |
val override_params = maps normalize_raw_param override_params |
33192 | 169 |
val raw_params = rev override_params @ rev default_params |
37260
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
170 |
val raw_lookup = AList.lookup (op =) raw_params |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
171 |
val lookup = Option.map stringify_raw_param_value o raw_lookup |
35964 | 172 |
val lookup_string = the_default "" o lookup |
173 |
fun general_lookup_bool option default_value name = |
|
174 |
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
|
175 |
SOME s => parse_bool_option option name s |
35964 | 176 |
| NONE => default_value |
177 |
val lookup_bool = the o general_lookup_bool false (SOME false) |
|
178 |
val lookup_bool_option = general_lookup_bool true NONE |
|
33192 | 179 |
fun do_int name value = |
180 |
case value of |
|
181 |
SOME s => (case Int.fromString s of |
|
182 |
SOME i => i |
|
183 |
| NONE => error ("Parameter " ^ quote name ^ |
|
184 |
" must be assigned an integer value.")) |
|
185 |
| NONE => 0 |
|
186 |
fun lookup_int name = do_int name (lookup name) |
|
187 |
fun lookup_int_option name = |
|
188 |
case lookup name of |
|
189 |
SOME "smart" => NONE |
|
190 |
| value => SOME (do_int name value) |
|
191 |
fun int_range_from_string name min_int s = |
|
192 |
let |
|
193 |
val (k1, k2) = |
|
194 |
(case space_explode "-" s of |
|
42959 | 195 |
[s] => the_default (s, s) (first_field "\<emdash>" s) |
33192 | 196 |
| ["", s2] => ("-" ^ s2, "-" ^ s2) |
197 |
| [s1, s2] => (s1, s2) |
|
51930
52fd62618631
prefer explicitly qualified exceptions, which is particular important for robust handlers;
wenzelm
parents:
51557
diff
changeset
|
198 |
| _ => raise Option.Option) |
33192 | 199 |
|> pairself (maxed_int_from_string min_int) |
200 |
in if k1 <= k2 then k1 upto k2 else k1 downto k2 end |
|
201 |
handle Option.Option => |
|
202 |
error ("Parameter " ^ quote name ^ |
|
203 |
" must be assigned a sequence of integers.") |
|
204 |
fun int_seq_from_string name min_int s = |
|
205 |
maps (int_range_from_string name min_int) (space_explode "," s) |
|
206 |
fun lookup_int_seq name min_int = |
|
207 |
case lookup name of |
|
208 |
SOME s => (case int_seq_from_string name min_int s of |
|
209 |
[] => [min_int] |
|
210 |
| value => value) |
|
211 |
| NONE => [min_int] |
|
37260
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
212 |
fun lookup_assigns read prefix default convert = |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
213 |
(NONE, convert (the_default default (lookup prefix))) |
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
|
214 |
:: 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
|
215 |
(SOME (read (String.extract (name, size prefix + 1, NONE))), |
37260
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
216 |
convert (stringify_raw_param_value value))) |
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
|
217 |
(filter (String.isPrefix (prefix ^ " ") o fst) raw_params) |
37260
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
218 |
fun lookup_ints_assigns read prefix min_int = |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
219 |
lookup_assigns read prefix (signed_string_of_int min_int) |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
220 |
(int_seq_from_string prefix min_int) |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
221 |
fun lookup_bool_assigns read prefix = |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
222 |
lookup_assigns read prefix "" (the o parse_bool_option false prefix) |
33192 | 223 |
fun lookup_bool_option_assigns read prefix = |
37260
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
224 |
lookup_assigns read prefix "" (parse_bool_option true prefix) |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
225 |
fun lookup_strings_assigns read prefix = |
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
226 |
lookup_assigns read prefix "" (space_explode " ") |
33192 | 227 |
fun lookup_time name = |
228 |
case lookup name of |
|
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54546
diff
changeset
|
229 |
SOME s => parse_time name s |
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54546
diff
changeset
|
230 |
| NONE => Time.zeroTime |
33192 | 231 |
val read_type_polymorphic = |
232 |
Syntax.read_typ ctxt #> Logic.mk_type |
|
233 |
#> singleton (Variable.polymorphic ctxt) #> Logic.dest_type |
|
234 |
val read_term_polymorphic = |
|
235 |
Syntax.read_term ctxt #> singleton (Variable.polymorphic ctxt) |
|
41876 | 236 |
val lookup_term_list_option_polymorphic = |
237 |
AList.lookup (op =) raw_params #> Option.map (map read_term_polymorphic) |
|
33192 | 238 |
val read_const_polymorphic = read_term_polymorphic #> dest_Const |
43022 | 239 |
val cards_assigns = |
240 |
lookup_ints_assigns read_type_polymorphic "card" 1 |
|
241 |
|> mode = Auto_Try ? map (apsnd (take auto_try_max_scopes)) |
|
33192 | 242 |
val maxes_assigns = lookup_ints_assigns read_const_polymorphic "max" ~1 |
243 |
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
|
244 |
val bitss = lookup_int_seq "bits" 1 |
33192 | 245 |
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
|
246 |
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
|
247 |
val finitizes = lookup_bool_option_assigns read_type_polymorphic "finitize" |
43022 | 248 |
val monos = if mode = Auto_Try then [(NONE, SOME true)] |
39316
b6c4385ab400
change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents:
39155
diff
changeset
|
249 |
else 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
|
250 |
val stds = lookup_bool_assigns read_type_polymorphic "std" |
33192 | 251 |
val wfs = lookup_bool_option_assigns read_const_polymorphic "wf" |
252 |
val sat_solver = lookup_string "sat_solver" |
|
43022 | 253 |
val blocking = mode <> Normal orelse lookup_bool "blocking" |
33192 | 254 |
val falsify = lookup_bool "falsify" |
43022 | 255 |
val debug = (mode <> Auto_Try andalso lookup_bool "debug") |
256 |
val verbose = debug orelse (mode <> Auto_Try andalso lookup_bool "verbose") |
|
33192 | 257 |
val overlord = lookup_bool "overlord" |
54546
8b403a7a8c44
fixed spying so that the envirnoment variables are queried at run-time not at build-time
blanchet
parents:
53802
diff
changeset
|
258 |
val spy = getenv "NITPICK_SPY" = "yes" orelse lookup_bool "spy" |
33192 | 259 |
val user_axioms = lookup_bool_option "user_axioms" |
260 |
val assms = lookup_bool "assms" |
|
41876 | 261 |
val whacks = lookup_term_list_option_polymorphic "whack" |> these |
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
|
262 |
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
|
263 |
val binary_ints = lookup_bool_option "binary_ints" |
33192 | 264 |
val destroy_constrs = lookup_bool "destroy_constrs" |
265 |
val specialize = lookup_bool "specialize" |
|
266 |
val star_linear_preds = lookup_bool "star_linear_preds" |
|
41856 | 267 |
val total_consts = lookup_bool_option "total_consts" |
41876 | 268 |
val needs = lookup_term_list_option_polymorphic "need" |
33192 | 269 |
val peephole_optim = lookup_bool "peephole_optim" |
38124 | 270 |
val datatype_sym_break = lookup_int "datatype_sym_break" |
271 |
val kodkod_sym_break = lookup_int "kodkod_sym_break" |
|
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54546
diff
changeset
|
272 |
val timeout = lookup_time "timeout" |
33192 | 273 |
val tac_timeout = lookup_time "tac_timeout" |
43022 | 274 |
val max_threads = |
275 |
if mode = Normal then Int.max (0, lookup_int "max_threads") else 1 |
|
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
276 |
val show_datatypes = debug orelse lookup_bool "show_datatypes" |
41993
bd6296de1432
reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents:
41876
diff
changeset
|
277 |
val show_skolems = debug orelse lookup_bool "show_skolems" |
37169
f69efa106feb
make Nitpick "show_all" option behave less surprisingly
blanchet
parents:
36960
diff
changeset
|
278 |
val show_consts = debug orelse lookup_bool "show_consts" |
41876 | 279 |
val evals = lookup_term_list_option_polymorphic "eval" |> these |
33192 | 280 |
val formats = lookup_ints_assigns read_term_polymorphic "format" 0 |
37260
dde817e6dfb1
added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents:
37213
diff
changeset
|
281 |
val atomss = lookup_strings_assigns read_type_polymorphic "atoms" |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
282 |
val max_potential = |
43032 | 283 |
if mode = Normal then Int.max (0, lookup_int "max_potential") else 0 |
33192 | 284 |
val max_genuine = Int.max (0, lookup_int "max_genuine") |
285 |
val check_potential = lookup_bool "check_potential" |
|
286 |
val check_genuine = lookup_bool "check_genuine" |
|
36390
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
287 |
val batch_size = |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
288 |
case lookup_int_option "batch_size" of |
eee4ee6a5cbe
remove "show_skolems" option and change style of record declarations
blanchet
parents:
36389
diff
changeset
|
289 |
SOME n => Int.max (1, n) |
38180
7a88032f9265
bump up the max cardinalities, to use up more of the time given to us by the user
blanchet
parents:
38127
diff
changeset
|
290 |
| NONE => if debug then 1 else 50 |
33192 | 291 |
val expect = lookup_string "expect" |
292 |
in |
|
53802 | 293 |
{cards_assigns = cards_assigns, maxes_assigns = maxes_assigns, iters_assigns = iters_assigns, |
294 |
bitss = bitss, bisim_depths = bisim_depths, boxes = boxes, finitizes = finitizes, |
|
295 |
monos = monos, stds = stds, wfs = wfs, sat_solver = sat_solver, blocking = blocking, |
|
296 |
falsify = falsify, debug = debug, verbose = verbose, overlord = overlord, spy = spy, |
|
297 |
user_axioms = user_axioms, assms = assms, whacks = whacks, merge_type_vars = merge_type_vars, |
|
298 |
binary_ints = binary_ints, destroy_constrs = destroy_constrs, specialize = specialize, |
|
299 |
star_linear_preds = star_linear_preds, total_consts = total_consts, needs = needs, |
|
300 |
peephole_optim = peephole_optim, datatype_sym_break = datatype_sym_break, |
|
301 |
kodkod_sym_break = kodkod_sym_break, timeout = timeout, tac_timeout = tac_timeout, |
|
302 |
max_threads = max_threads, show_datatypes = show_datatypes, show_skolems = show_skolems, |
|
303 |
show_consts = show_consts, evals = evals, formats = formats, atomss = atomss, |
|
304 |
max_potential = max_potential, max_genuine = max_genuine, check_potential = check_potential, |
|
305 |
check_genuine = check_genuine, batch_size = batch_size, expect = expect} |
|
33192 | 306 |
end |
307 |
||
308 |
fun default_params thy = |
|
43022 | 309 |
extract_params (Proof_Context.init_global thy) Normal (default_raw_params thy) |
33192 | 310 |
o map (apsnd single) |
311 |
||
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
312 |
val parse_key = Scan.repeat1 Parse.typ_group >> space_implode " " |
35964 | 313 |
val parse_value = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36610
diff
changeset
|
314 |
Scan.repeat1 (Parse.minus >> single |
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39359
diff
changeset
|
315 |
|| Scan.repeat1 (Scan.unless Parse.minus |
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39359
diff
changeset
|
316 |
(Parse.name || Parse.float_number)) |
46949 | 317 |
|| @{keyword ","} |-- Parse.number >> prefix "," >> single) |
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39359
diff
changeset
|
318 |
>> flat |
46949 | 319 |
val parse_param = parse_key -- Scan.optional (@{keyword "="} |-- parse_value) [] |
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
320 |
val parse_params = |
46949 | 321 |
Scan.optional (@{keyword "["} |-- Parse.list parse_param --| @{keyword "]"}) [] |
33192 | 322 |
|
323 |
fun handle_exceptions ctxt f x = |
|
324 |
f x |
|
325 |
handle ARG (loc, details) => |
|
326 |
error ("Bad argument(s) to " ^ quote loc ^ ": " ^ details ^ ".") |
|
327 |
| BAD (loc, details) => |
|
328 |
error ("Internal error (" ^ quote loc ^ "): " ^ details ^ ".") |
|
329 |
| NOT_SUPPORTED details => |
|
330 |
(warning ("Unsupported case: " ^ details ^ "."); x) |
|
331 |
| NUT (loc, us) => |
|
332 |
error ("Invalid intermediate term" ^ plural_s_for_list us ^ |
|
333 |
" (" ^ quote loc ^ "): " ^ |
|
334 |
commas (map (string_for_nut ctxt) us) ^ ".") |
|
335 |
| REP (loc, Rs) => |
|
336 |
error ("Invalid representation" ^ plural_s_for_list Rs ^ |
|
337 |
" (" ^ quote loc ^ "): " ^ commas (map string_for_rep Rs) ^ ".") |
|
338 |
| TERM (loc, ts) => |
|
339 |
error ("Invalid term" ^ plural_s_for_list ts ^ |
|
340 |
" (" ^ quote loc ^ "): " ^ |
|
341 |
commas (map (Syntax.string_of_term ctxt) ts) ^ ".") |
|
342 |
| TYPE (loc, Ts, ts) => |
|
343 |
error ("Invalid type" ^ plural_s_for_list Ts ^ |
|
344 |
(if null ts then |
|
345 |
"" |
|
346 |
else |
|
347 |
" for term" ^ plural_s_for_list ts ^ " " ^ |
|
348 |
commas (map (quote o Syntax.string_of_term ctxt) ts)) ^ |
|
349 |
" (" ^ quote loc ^ "): " ^ |
|
350 |
commas (map (Syntax.string_of_typ ctxt) Ts) ^ ".") |
|
351 |
||
43022 | 352 |
fun pick_nits override_params mode i step state = |
33192 | 353 |
let |
354 |
val thy = Proof.theory_of state |
|
355 |
val ctxt = Proof.context_of state |
|
356 |
val _ = List.app check_raw_param override_params |
|
357 |
val params as {blocking, debug, ...} = |
|
43022 | 358 |
extract_params ctxt mode (default_raw_params thy) override_params |
33192 | 359 |
fun go () = |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
360 |
(unknownN, state) |
43022 | 361 |
|> (if mode = Auto_Try then perhaps o try |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
362 |
else if debug then fn f => fn x => f x |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
363 |
else handle_exceptions ctxt) |
43022 | 364 |
(fn (_, state) => pick_nits_in_subgoal state params mode i step) |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
365 |
in if blocking then go () else Future.fork (tap go) |> K (unknownN, state) end |
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
366 |
|> `(fn (outcome_code, _) => outcome_code = genuineN) |
33192 | 367 |
|
368 |
fun string_for_raw_param (name, value) = |
|
369 |
name ^ " = " ^ stringify_raw_param_value value |
|
370 |
||
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
371 |
fun nitpick_params_trans params = |
33192 | 372 |
Toplevel.theory |
35968
b7f98ff9c7d9
simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents:
35964
diff
changeset
|
373 |
(fold set_default_raw_param params |
39316
b6c4385ab400
change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents:
39155
diff
changeset
|
374 |
#> tap (fn thy => |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
375 |
writeln ("Default parameters for Nitpick:\n" ^ |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
376 |
(case rev (default_raw_params thy) of |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
377 |
[] => "none" |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
378 |
| params => |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
379 |
(map check_raw_param params; |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
380 |
params |> map string_for_raw_param |
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
381 |
|> sort_strings |> cat_lines))))) |
33192 | 382 |
|
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
383 |
val _ = |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
384 |
Outer_Syntax.improper_command @{command_spec "nitpick"} |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
385 |
"try to find a counterexample for a given subgoal using Nitpick" |
51557
4e4b56b7a3a5
more robust access Toplevel.proof_of -- prefer warning via Toplevel.unknown_proof over hard crash (notably for skipped proofs);
wenzelm
parents:
49985
diff
changeset
|
386 |
(parse_params -- Scan.optional Parse.nat 1 >> (fn (params, i) => |
4e4b56b7a3a5
more robust access Toplevel.proof_of -- prefer warning via Toplevel.unknown_proof over hard crash (notably for skipped proofs);
wenzelm
parents:
49985
diff
changeset
|
387 |
Toplevel.unknown_proof o |
4e4b56b7a3a5
more robust access Toplevel.proof_of -- prefer warning via Toplevel.unknown_proof over hard crash (notably for skipped proofs);
wenzelm
parents:
49985
diff
changeset
|
388 |
Toplevel.keep (fn state => |
4e4b56b7a3a5
more robust access Toplevel.proof_of -- prefer warning via Toplevel.unknown_proof over hard crash (notably for skipped proofs);
wenzelm
parents:
49985
diff
changeset
|
389 |
ignore (pick_nits params Normal i (Toplevel.proof_position_of state) |
4e4b56b7a3a5
more robust access Toplevel.proof_of -- prefer warning via Toplevel.unknown_proof over hard crash (notably for skipped proofs);
wenzelm
parents:
49985
diff
changeset
|
390 |
(Toplevel.proof_of state))))) |
33192 | 391 |
|
46961
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
392 |
val _ = |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
393 |
Outer_Syntax.command @{command_spec "nitpick_params"} |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
394 |
"set and display the default parameters for Nitpick" |
5c6955f487e5
outer syntax command definitions based on formal command_spec derived from theory header declarations;
wenzelm
parents:
46949
diff
changeset
|
395 |
(parse_params #>> nitpick_params_trans) |
33192 | 396 |
|
43022 | 397 |
fun try_nitpick auto = pick_nits [] (if auto then Auto_Try else Try) 1 0 |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
398 |
|
52641
c56b6fa636e8
hybrid "auto" tool setup, for TTY (within theory) and PIDE (global print function);
wenzelm
parents:
52639
diff
changeset
|
399 |
val _ = Try.tool_setup (nitpickN, (50, @{option auto_nitpick}, try_nitpick)) |
33561
ab01b72715ef
introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents:
33556
diff
changeset
|
400 |
|
33192 | 401 |
end; |