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