src/HOL/Tools/Nitpick/nitpick_isar.ML
author wenzelm
Thu, 15 Mar 2012 20:07:00 +0100
changeset 46949 94aa7b81bcf6
parent 43032 f617a5323d07
child 46961 5c6955f487e5
permissions -rw-r--r--
prefer formally checked @{keyword} parser;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33982
1ae222745c4a fixed paths in Nitpick's ML file headers
blanchet
parents: 33699
diff changeset
     1
(*  Title:      HOL/Tools/Nitpick/nitpick_isar.ML
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     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
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     4
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     5
Adds the "nitpick" and "nitpick_params" commands to Isabelle/Isar's outer
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     6
syntax.
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     7
*)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     8
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     9
signature NITPICK_ISAR =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    10
sig
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    11
  type params = Nitpick.params
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    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
39316
b6c4385ab400 change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents: 39155
diff changeset
    15
  val auto : bool Unsynchronized.ref
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    16
  val default_params : theory -> (string * string) list -> params
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
    17
  val setup : theory -> theory
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents: 35665
diff changeset
    18
end;
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    19
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33220
diff changeset
    20
structure Nitpick_Isar : NITPICK_ISAR =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    21
struct
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    22
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33220
diff changeset
    23
open Nitpick_Util
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33220
diff changeset
    24
open Nitpick_HOL
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33220
diff changeset
    25
open Nitpick_Rep
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33220
diff changeset
    26
open Nitpick_Nut
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    27
open Nitpick
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    28
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
    29
val nitpickN = "nitpick"
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
    30
val nitpick_paramsN = "nitpick_params"
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
    31
39316
b6c4385ab400 change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents: 39155
diff changeset
    32
val auto = Unsynchronized.ref false
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
    33
39344
9de74cdcd833 make Auto Nitpick go through fewer scopes
blanchet
parents: 39328
diff changeset
    34
(* Maximum number of scopes for Auto Nitpick. Be frugal since it has to share
9de74cdcd833 make Auto Nitpick go through fewer scopes
blanchet
parents: 39328
diff changeset
    35
   its time slot with several other automatic tools. *)
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
    36
val auto_try_max_scopes = 6
39344
9de74cdcd833 make Auto Nitpick go through fewer scopes
blanchet
parents: 39328
diff changeset
    37
33601
4608243edcfc plain add_preference, no setmp_CRITICAL required;
wenzelm
parents: 33599
diff changeset
    38
val _ =
4608243edcfc plain add_preference, no setmp_CRITICAL required;
wenzelm
parents: 33599
diff changeset
    39
  ProofGeneralPgip.add_preference Preferences.category_tracing
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
    40
      (Preferences.bool_pref auto "auto-nitpick" "Run Nitpick automatically.")
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
    41
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    42
type raw_param = string * string list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    43
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    44
val default_default_params =
42959
ee829022381d use \<emdash> rather than \<midarrow>
blanchet
parents: 42361
diff changeset
    45
  [("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
    46
   ("iter", "0,1,2,4,8,12,16,20,24,28"),
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
   ("bits", "1,2,3,4,6,8,10,12,14,16"),
7a88032f9265 bump up the max cardinalities, to use up more of the time given to us by the user
blanchet
parents: 38127
diff changeset
    48
   ("bisim_depth", "9"),
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    49
   ("box", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    50
   ("finitize", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    51
   ("mono", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    52
   ("std", "true"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    53
   ("wf", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    54
   ("sat_solver", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    55
   ("batch_size", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    56
   ("blocking", "true"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    57
   ("falsify", "true"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    58
   ("user_axioms", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    59
   ("assms", "true"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    60
   ("merge_type_vars", "false"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    61
   ("binary_ints", "smart"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    62
   ("destroy_constrs", "true"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    63
   ("specialize", "true"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    64
   ("star_linear_preds", "true"),
41856
7244589c8ccc added "total_consts" option
blanchet
parents: 41803
diff changeset
    65
   ("total_consts", "smart"),
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    66
   ("peephole_optim", "true"),
38127
9f9f696fc4e8 tweak datatype sym break code
blanchet
parents: 38124
diff changeset
    67
   ("datatype_sym_break", "5"),
9f9f696fc4e8 tweak datatype sym break code
blanchet
parents: 38124
diff changeset
    68
   ("kodkod_sym_break", "15"),
40341
03156257040f standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents: 39359
diff changeset
    69
   ("timeout", "30"),
03156257040f standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents: 39359
diff changeset
    70
   ("tac_timeout", "0.5"),
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    71
   ("max_threads", "0"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    72
   ("debug", "false"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    73
   ("verbose", "false"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    74
   ("overlord", "false"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    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
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    77
   ("show_consts", "false"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    78
   ("format", "1"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    79
   ("max_potential", "1"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    80
   ("max_genuine", "1"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    81
   ("check_potential", "false"),
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
    82
   ("check_genuine", "false")]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    83
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    84
val negated_params =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    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
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    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
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    89
   ("non_wf", "wf"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    90
   ("non_blocking", "blocking"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    91
   ("satisfy", "falsify"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    92
   ("no_user_axioms", "user_axioms"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    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
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    96
   ("dont_destroy_constrs", "destroy_constrs"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    97
   ("dont_specialize", "specialize"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    98
   ("dont_star_linear_preds", "star_linear_preds"),
41856
7244589c8ccc added "total_consts" option
blanchet
parents: 41803
diff changeset
    99
   ("partial_consts", "total_consts"),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   100
   ("no_peephole_optim", "peephole_optim"),
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   101
   ("no_debug", "debug"),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   102
   ("quiet", "verbose"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   103
   ("no_overlord", "overlord"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   104
   ("hide_datatypes", "show_datatypes"),
41993
bd6296de1432 reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents: 41876
diff changeset
   105
   ("hide_skolems", "show_skolems"),
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   106
   ("hide_consts", "show_consts"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   107
   ("trust_potential", "check_potential"),
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   108
   ("trust_genuine", "check_genuine")]
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   109
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   110
fun is_known_raw_param s =
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34124
diff changeset
   111
  AList.defined (op =) default_default_params s orelse
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34124
diff changeset
   112
  AList.defined (op =) negated_params s orelse
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   113
  member (op =) ["max", "show_all", "whack", "eval", "need", "atoms",
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   114
                 "expect"] s orelse
34936
c4f04bee79f3 some work on Nitpick's support for quotient types;
blanchet
parents: 34124
diff changeset
   115
  exists (fn p => String.isPrefix (p ^ " ") s)
35665
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35280
diff changeset
   116
         ["card", "max", "iter", "box", "dont_box", "finitize", "dont_finitize",
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   117
          "mono", "non_mono", "std", "non_std", "wf", "non_wf", "format",
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   118
          "atoms"]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   119
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   120
fun check_raw_param (s, _) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   121
  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
   122
  else error ("Unknown parameter: " ^ quote s ^ ".")
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   123
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   124
fun unnegate_param_name name =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   125
  case AList.lookup (op =) negated_params name of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   126
    NONE => if String.isPrefix "dont_" name then SOME (unprefix "dont_" name)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   127
            else if String.isPrefix "non_" name then SOME (unprefix "non_" name)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   128
            else NONE
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   129
  | some_name => some_name
37169
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   130
fun normalize_raw_param (name, value) =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   131
  case unnegate_param_name name of
37169
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   132
    SOME name' => [(name', case value of
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   133
                             ["false"] => ["true"]
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   134
                           | ["true"] => ["false"]
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   135
                           | [] => ["false"]
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   136
                           | _ => value)]
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   137
  | NONE => if name = "show_all" then
41993
bd6296de1432 reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents: 41876
diff changeset
   138
              [("show_datatypes", value), ("show_skolems", value),
bd6296de1432 reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents: 41876
diff changeset
   139
               ("show_consts", value)]
37169
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   140
            else
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   141
              [(name, value)]
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   142
41472
f6ab14e61604 misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents: 40931
diff changeset
   143
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
   144
(
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   145
  type T = raw_param list
36391
8f81c060cf12 cosmetics
blanchet
parents: 36390
diff changeset
   146
  val empty = map (apsnd single) default_default_params
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   147
  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
   148
  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
   149
)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   150
37169
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   151
val set_default_raw_param =
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   152
  Data.map o fold (AList.update (op =)) o normalize_raw_param
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   153
val default_raw_params = Data.get
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   154
42959
ee829022381d use \<emdash> rather than \<midarrow>
blanchet
parents: 42361
diff changeset
   155
fun is_punctuation s = (s = "," orelse s = "-" orelse s = "\<emdash>")
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   156
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   157
fun stringify_raw_param_value [] = ""
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   158
  | stringify_raw_param_value [s] = s
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   159
  | stringify_raw_param_value (s1 :: s2 :: ss) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   160
    s1 ^ (if is_punctuation s1 orelse is_punctuation s2 then "" else " ") ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   161
    stringify_raw_param_value (s2 :: ss)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   162
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   163
fun maxed_int_from_string min_int s = Int.max (min_int, the (Int.fromString s))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   164
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   165
fun extract_params ctxt mode default_params override_params =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   166
  let
37169
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   167
    val override_params = maps normalize_raw_param override_params
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   168
    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
   169
    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
   170
    val lookup = Option.map stringify_raw_param_value o raw_lookup
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   171
    val lookup_string = the_default "" o lookup
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   172
    fun general_lookup_bool option default_value name =
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   173
      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
   174
        SOME s => parse_bool_option option name s
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   175
      | NONE => default_value
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   176
    val lookup_bool = the o general_lookup_bool false (SOME false)
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   177
    val lookup_bool_option = general_lookup_bool true NONE
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   178
    fun do_int name value =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   179
      case value of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   180
        SOME s => (case Int.fromString s of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   181
                     SOME i => i
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   182
                   | NONE => error ("Parameter " ^ quote name ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   183
                                    " must be assigned an integer value."))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   184
      | NONE => 0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   185
    fun lookup_int name = do_int name (lookup name)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   186
    fun lookup_int_option name =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   187
      case lookup name of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   188
        SOME "smart" => NONE
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   189
      | value => SOME (do_int name value)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   190
    fun int_range_from_string name min_int s =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   191
      let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   192
        val (k1, k2) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   193
          (case space_explode "-" s of
42959
ee829022381d use \<emdash> rather than \<midarrow>
blanchet
parents: 42361
diff changeset
   194
             [s] => the_default (s, s) (first_field "\<emdash>" s)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   195
           | ["", s2] => ("-" ^ s2, "-" ^ s2)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   196
           | [s1, s2] => (s1, s2)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   197
           | _ => raise Option)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   198
          |> pairself (maxed_int_from_string min_int)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   199
      in if k1 <= k2 then k1 upto k2 else k1 downto k2 end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   200
      handle Option.Option =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   201
             error ("Parameter " ^ quote name ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   202
                    " must be assigned a sequence of integers.")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   203
    fun int_seq_from_string name min_int s =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   204
      maps (int_range_from_string name min_int) (space_explode "," s)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   205
    fun lookup_int_seq name min_int =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   206
      case lookup name of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   207
        SOME s => (case int_seq_from_string name min_int s of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   208
                     [] => [min_int]
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   209
                   | value => value)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   210
      | 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
   211
    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
   212
      (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
   213
      :: 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
   214
                 (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
   215
                  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
   216
             (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
   217
    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
   218
      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
   219
                     (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
   220
    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
   221
      lookup_assigns read prefix "" (the o parse_bool_option false prefix)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   222
    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
   223
      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
   224
    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
   225
      lookup_assigns read prefix "" (space_explode " ")
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   226
    fun lookup_time name =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   227
      case lookup name of
39316
b6c4385ab400 change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents: 39155
diff changeset
   228
        SOME s => parse_time_option name s
b6c4385ab400 change defaults of Auto Nitpick so that it consumes less resources (time and Kodkod threads)
blanchet
parents: 39155
diff changeset
   229
      | NONE => NONE
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   230
    val read_type_polymorphic =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   231
      Syntax.read_typ ctxt #> Logic.mk_type
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   232
      #> singleton (Variable.polymorphic ctxt) #> Logic.dest_type
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   233
    val read_term_polymorphic =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   234
      Syntax.read_term ctxt #> singleton (Variable.polymorphic ctxt)
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   235
    val lookup_term_list_option_polymorphic =
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   236
      AList.lookup (op =) raw_params #> Option.map (map read_term_polymorphic)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   237
    val read_const_polymorphic = read_term_polymorphic #> dest_Const
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   238
    val cards_assigns =
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   239
      lookup_ints_assigns read_type_polymorphic "card" 1
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   240
      |> mode = Auto_Try ? map (apsnd (take auto_try_max_scopes))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   241
    val maxes_assigns = lookup_ints_assigns read_const_polymorphic "max" ~1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   242
    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
   243
    val bitss = lookup_int_seq "bits" 1
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   244
    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
   245
    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
   246
    val finitizes = lookup_bool_option_assigns read_type_polymorphic "finitize"
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   247
    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
   248
                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
   249
    val stds = lookup_bool_assigns read_type_polymorphic "std"
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   250
    val wfs = lookup_bool_option_assigns read_const_polymorphic "wf"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   251
    val sat_solver = lookup_string "sat_solver"
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   252
    val blocking = mode <> Normal orelse lookup_bool "blocking"
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   253
    val falsify = lookup_bool "falsify"
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   254
    val debug = (mode <> Auto_Try andalso lookup_bool "debug")
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   255
    val verbose = debug orelse (mode <> Auto_Try andalso lookup_bool "verbose")
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   256
    val overlord = lookup_bool "overlord"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   257
    val user_axioms = lookup_bool_option "user_axioms"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   258
    val assms = lookup_bool "assms"
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   259
    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
   260
    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
   261
    val binary_ints = lookup_bool_option "binary_ints"
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   262
    val destroy_constrs = lookup_bool "destroy_constrs"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   263
    val specialize = lookup_bool "specialize"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   264
    val star_linear_preds = lookup_bool "star_linear_preds"
41856
7244589c8ccc added "total_consts" option
blanchet
parents: 41803
diff changeset
   265
    val total_consts = lookup_bool_option "total_consts"
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   266
    val needs = lookup_term_list_option_polymorphic "need"
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   267
    val peephole_optim = lookup_bool "peephole_optim"
38124
6538e25cf5dd started implementation of custom sym break
blanchet
parents: 37260
diff changeset
   268
    val datatype_sym_break = lookup_int "datatype_sym_break"
6538e25cf5dd started implementation of custom sym break
blanchet
parents: 37260
diff changeset
   269
    val kodkod_sym_break = lookup_int "kodkod_sym_break"
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   270
    val timeout = if mode = Auto_Try then NONE else lookup_time "timeout"
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   271
    val tac_timeout = lookup_time "tac_timeout"
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   272
    val max_threads =
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   273
      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
   274
    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
   275
    val show_skolems = debug orelse lookup_bool "show_skolems"
37169
f69efa106feb make Nitpick "show_all" option behave less surprisingly
blanchet
parents: 36960
diff changeset
   276
    val show_consts = debug orelse lookup_bool "show_consts"
41876
03f699556955 simplify "need" option's syntax
blanchet
parents: 41875
diff changeset
   277
    val evals = lookup_term_list_option_polymorphic "eval" |> these
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   278
    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
   279
    val atomss = lookup_strings_assigns read_type_polymorphic "atoms"
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   280
    val max_potential =
43032
f617a5323d07 unbreak "max_potential" logic
blanchet
parents: 43024
diff changeset
   281
      if mode = Normal then Int.max (0, lookup_int "max_potential") else 0
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   282
    val max_genuine = Int.max (0, lookup_int "max_genuine")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   283
    val check_potential = lookup_bool "check_potential"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   284
    val check_genuine = lookup_bool "check_genuine"
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   285
    val batch_size =
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   286
      case lookup_int_option "batch_size" of
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   287
        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
   288
      | NONE => if debug then 1 else 50
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   289
    val expect = lookup_string "expect"
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   290
  in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   291
    {cards_assigns = cards_assigns, maxes_assigns = maxes_assigns,
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34121
diff changeset
   292
     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
   293
     boxes = boxes, finitizes = finitizes, monos = monos, stds = stds,
ff2bf50505ab added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
blanchet
parents: 35280
diff changeset
   294
     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
   295
     debug = debug, verbose = verbose, overlord = overlord,
38209
3d1d928dce50 added "whack"
blanchet
parents: 38180
diff changeset
   296
     user_axioms = user_axioms, assms = assms, whacks = whacks,
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34121
diff changeset
   297
     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
   298
     destroy_constrs = destroy_constrs, specialize = specialize,
41856
7244589c8ccc added "total_consts" option
blanchet
parents: 41803
diff changeset
   299
     star_linear_preds = star_linear_preds, total_consts = total_consts,
41875
e3cd0dce9b1a renamed "preconstr" option "need"
blanchet
parents: 41856
diff changeset
   300
     needs = needs, peephole_optim = peephole_optim,
41856
7244589c8ccc added "total_consts" option
blanchet
parents: 41803
diff changeset
   301
     datatype_sym_break = datatype_sym_break,
38124
6538e25cf5dd started implementation of custom sym break
blanchet
parents: 37260
diff changeset
   302
     kodkod_sym_break = kodkod_sym_break, timeout = timeout,
36389
8228b3a4a2ba remove "skolemize" option from Nitpick, since Skolemization is always useful
blanchet
parents: 36388
diff changeset
   303
     tac_timeout = tac_timeout, max_threads = max_threads,
41993
bd6296de1432 reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents: 41876
diff changeset
   304
     show_datatypes = show_datatypes, show_skolems = show_skolems,
bd6296de1432 reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents: 41876
diff changeset
   305
     show_consts = show_consts, evals = evals, formats = formats,
bd6296de1432 reintroduced "show_skolems" option -- useful when too many Skolems are displayed
blanchet
parents: 41876
diff changeset
   306
     atomss = atomss, max_potential = max_potential, max_genuine = max_genuine,
37260
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 37213
diff changeset
   307
     check_potential = check_potential, check_genuine = check_genuine,
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 37213
diff changeset
   308
     batch_size = batch_size, expect = expect}
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   309
  end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   310
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   311
fun default_params thy =
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   312
  extract_params (Proof_Context.init_global thy) Normal (default_raw_params thy)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   313
  o map (apsnd single)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   314
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   315
val parse_key = Scan.repeat1 Parse.typ_group >> space_implode " "
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   316
val parse_value =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   317
  Scan.repeat1 (Parse.minus >> single
40341
03156257040f standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents: 39359
diff changeset
   318
                || Scan.repeat1 (Scan.unless Parse.minus
03156257040f standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents: 39359
diff changeset
   319
                                             (Parse.name || Parse.float_number))
46949
94aa7b81bcf6 prefer formally checked @{keyword} parser;
wenzelm
parents: 43032
diff changeset
   320
                || @{keyword ","} |-- Parse.number >> prefix "," >> single)
40341
03156257040f standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents: 39359
diff changeset
   321
  >> flat
46949
94aa7b81bcf6 prefer formally checked @{keyword} parser;
wenzelm
parents: 43032
diff changeset
   322
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
   323
val parse_params =
46949
94aa7b81bcf6 prefer formally checked @{keyword} parser;
wenzelm
parents: 43032
diff changeset
   324
  Scan.optional (@{keyword "["} |-- Parse.list parse_param --| @{keyword "]"}) []
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   325
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   326
fun handle_exceptions ctxt f x =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   327
  f x
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   328
  handle ARG (loc, details) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   329
         error ("Bad argument(s) to " ^ quote loc ^ ": " ^ details ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   330
       | BAD (loc, details) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   331
         error ("Internal error (" ^ quote loc ^ "): " ^ details ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   332
       | NOT_SUPPORTED details =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   333
         (warning ("Unsupported case: " ^ details ^ "."); x)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   334
       | NUT (loc, us) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   335
         error ("Invalid intermediate term" ^ plural_s_for_list us ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   336
                " (" ^ quote loc ^ "): " ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   337
                commas (map (string_for_nut ctxt) us) ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   338
       | REP (loc, Rs) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   339
         error ("Invalid representation" ^ plural_s_for_list Rs ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   340
                " (" ^ quote loc ^ "): " ^ commas (map string_for_rep Rs) ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   341
       | TERM (loc, ts) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   342
         error ("Invalid term" ^ plural_s_for_list ts ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   343
                " (" ^ quote loc ^ "): " ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   344
                commas (map (Syntax.string_of_term ctxt) ts) ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   345
       | TYPE (loc, Ts, ts) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   346
         error ("Invalid type" ^ plural_s_for_list Ts ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   347
                (if null ts then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   348
                   ""
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   349
                 else
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   350
                   " for term" ^ plural_s_for_list ts ^ " " ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   351
                   commas (map (quote o Syntax.string_of_term ctxt) ts)) ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   352
                " (" ^ quote loc ^ "): " ^
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   353
                commas (map (Syntax.string_of_typ ctxt) Ts) ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   354
       | Refute.REFUTE (loc, details) =>
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   355
         error ("Unhandled Refute error (" ^ quote loc ^ "): " ^ details ^ ".")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   356
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   357
fun pick_nits override_params mode i step state =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   358
  let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   359
    val thy = Proof.theory_of state
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   360
    val ctxt = Proof.context_of state
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   361
    val _ = List.app check_raw_param override_params
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   362
    val params as {blocking, debug, ...} =
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   363
      extract_params ctxt mode (default_raw_params thy) override_params
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   364
    fun go () =
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
   365
      (unknownN, state)
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   366
      |> (if mode = Auto_Try then perhaps o try
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   367
          else if debug then fn f => fn x => f x
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   368
          else handle_exceptions ctxt)
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   369
         (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
   370
  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
   371
  |> `(fn (outcome_code, _) => outcome_code = genuineN)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   372
35968
b7f98ff9c7d9 simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents: 35964
diff changeset
   373
fun nitpick_trans (params, i) =
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
   374
  Toplevel.keep (fn state =>
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   375
      pick_nits params Normal i (Toplevel.proof_position_of state)
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
   376
                (Toplevel.proof_of state) |> K ())
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   377
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   378
fun string_for_raw_param (name, value) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   379
  name ^ " = " ^ stringify_raw_param_value value
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   380
35968
b7f98ff9c7d9 simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents: 35964
diff changeset
   381
fun nitpick_params_trans params =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   382
  Toplevel.theory
35968
b7f98ff9c7d9 simplify Nitpick parameter parsing code a little bit + make compile
blanchet
parents: 35964
diff changeset
   383
      (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
   384
       #> tap (fn thy =>
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   385
                  writeln ("Default parameters for Nitpick:\n" ^
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   386
                           (case rev (default_raw_params thy) of
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   387
                              [] => "none"
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   388
                            | params =>
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   389
                              (map check_raw_param params;
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   390
                               params |> map string_for_raw_param
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   391
                                      |> sort_strings |> cat_lines)))))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   392
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   393
val parse_nitpick_command =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   394
  (parse_params -- Scan.optional Parse.nat 1) #>> nitpick_trans
35964
77f2cb359b49 leverage code now in Sledgehammer
blanchet
parents: 35866
diff changeset
   395
val parse_nitpick_params_command = parse_params #>> nitpick_params_trans
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   396
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
   397
val _ = Outer_Syntax.improper_command nitpickN
36390
eee4ee6a5cbe remove "show_skolems" option and change style of record declarations
blanchet
parents: 36389
diff changeset
   398
            "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
   399
            Keyword.diag parse_nitpick_command
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
   400
val _ = Outer_Syntax.command nitpick_paramsN
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   401
            "set and display the default parameters for Nitpick"
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36610
diff changeset
   402
            Keyword.thy_decl parse_nitpick_params_command
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   403
43022
7d3ce43d9464 handle non-auto try case gracefully in Nitpick
blanchet
parents: 43020
diff changeset
   404
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
   405
43024
58150aa44941 prioritize try and auto try's tools, with fast ones first, with a slight preference for provers vs. counterexample generators
blanchet
parents: 43022
diff changeset
   406
val setup = Try.register_tool (nitpickN, (50, auto, try_nitpick))
33561
ab01b72715ef introduced Auto Nitpick in addition to Auto Quickcheck;
blanchet
parents: 33556
diff changeset
   407
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   408
end;