make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
(* Title: HOL/Tools/Sledgehammer/sledgehammer_util.ML
Author: Jasmin Blanchette, TU Muenchen
General-purpose functions used by the Sledgehammer modules.
*)
signature SLEDGEHAMMER_UTIL =
sig
val plural_s : int -> string
val serial_commas : string -> string list -> string list
val parse_bool_option : bool -> string -> string -> bool option
val parse_time_option : string -> string -> Time.time option
val hashw : word * word -> word
val hashw_char : Char.char * word -> word
val hashw_string : string * word -> word
end;
structure Sledgehammer_Util : SLEDGEHAMMER_UTIL =
struct
fun plural_s n = if n = 1 then "" else "s"
fun serial_commas _ [] = ["??"]
| serial_commas _ [s] = [s]
| serial_commas conj [s1, s2] = [s1, conj, s2]
| serial_commas conj [s1, s2, s3] = [s1 ^ ",", s2 ^ ",", conj, s3]
| serial_commas conj (s :: ss) = s ^ "," :: serial_commas conj ss
fun parse_bool_option option name s =
(case s of
"smart" => if option then NONE else raise Option
| "false" => SOME false
| "true" => SOME true
| "" => SOME true
| _ => raise Option)
handle Option.Option =>
let val ss = map quote ((option ? cons "smart") ["true", "false"]) in
error ("Parameter " ^ quote name ^ " must be assigned " ^
space_implode " " (serial_commas "or" ss) ^ ".")
end
fun parse_time_option _ "none" = NONE
| parse_time_option name s =
let
val msecs =
case space_explode " " s of
[s1, "min"] => 60000 * the (Int.fromString s1)
| [s1, "s"] => 1000 * the (Int.fromString s1)
| [s1, "ms"] => the (Int.fromString s1)
| _ => 0
in
if msecs <= 0 then
error ("Parameter " ^ quote name ^ " must be assigned a positive time \
\value (e.g., \"60 s\", \"200 ms\") or \"none\".")
else
SOME (Time.fromMilliseconds msecs)
end
(* This hash function is recommended in Compilers: Principles, Techniques, and
Tools, by Aho, Sethi and Ullman. The hashpjw function, which they
particularly recommend, triggers a bug in versions of Poly/ML up to 4.2.0. *)
fun hashw (u, w) = Word.+ (u, Word.* (0w65599, w))
fun hashw_char (c, w) = hashw (Word.fromInt (Char.ord c), w)
fun hashw_string (s:string, w) = CharVector.foldl hashw_char w s
end;