author | blanchet |
Wed, 18 Jul 2012 08:44:03 +0200 | |
changeset 48292 | 7fcee834c7f5 |
parent 48251 | 6cdcfbddc077 |
child 48316 | 252f45c04042 |
permissions | -rw-r--r-- |
36062 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_util.ML |
35963 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
3 |
||
4 |
General-purpose functions used by the Sledgehammer modules. |
|
5 |
*) |
|
6 |
||
7 |
signature SLEDGEHAMMER_UTIL = |
|
8 |
sig |
|
36142
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36062
diff
changeset
|
9 |
val plural_s : int -> string |
35963 | 10 |
val serial_commas : string -> string list -> string list |
38738
0ce517c1970f
make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents:
38698
diff
changeset
|
11 |
val simplify_spaces : string -> string |
35963 | 12 |
val parse_bool_option : bool -> string -> string -> bool option |
13 |
val parse_time_option : string -> string -> Time.time option |
|
38044 | 14 |
val subgoal_count : Proof.state -> int |
38696
4c6b65d6a135
quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents:
38652
diff
changeset
|
15 |
val reserved_isar_keyword_table : unit -> unit Symtab.table |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
16 |
val thms_in_proof : string list option -> thm -> string list |
35963 | 17 |
end; |
39318 | 18 |
|
35963 | 19 |
structure Sledgehammer_Util : SLEDGEHAMMER_UTIL = |
20 |
struct |
|
21 |
||
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43043
diff
changeset
|
22 |
open ATP_Util |
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43043
diff
changeset
|
23 |
|
36142
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36062
diff
changeset
|
24 |
fun plural_s n = if n = 1 then "" else "s" |
36062 | 25 |
|
43029
3e060b1c844b
use helpers and tweak Quickcheck's priority to it comes second (to give Solve Direct slightly more time before another prover runs)
blanchet
parents:
43005
diff
changeset
|
26 |
val serial_commas = Try.serial_commas |
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43043
diff
changeset
|
27 |
val simplify_spaces = strip_spaces false (K true) |
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37575
diff
changeset
|
28 |
|
35963 | 29 |
fun parse_bool_option option name s = |
30 |
(case s of |
|
31 |
"smart" => if option then NONE else raise Option |
|
32 |
| "false" => SOME false |
|
33 |
| "true" => SOME true |
|
34 |
| "" => SOME true |
|
35 |
| _ => raise Option) |
|
36 |
handle Option.Option => |
|
37 |
let val ss = map quote ((option ? cons "smart") ["true", "false"]) in |
|
38 |
error ("Parameter " ^ quote name ^ " must be assigned " ^ |
|
39 |
space_implode " " (serial_commas "or" ss) ^ ".") |
|
40 |
end |
|
41 |
||
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39890
diff
changeset
|
42 |
val has_junk = |
40627
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
wenzelm
parents:
40341
diff
changeset
|
43 |
exists (fn s => not (Symbol.is_digit s) andalso s <> ".") o raw_explode (* FIXME Symbol.explode (?) *) |
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39890
diff
changeset
|
44 |
|
35963 | 45 |
fun parse_time_option _ "none" = NONE |
46 |
| parse_time_option name s = |
|
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39890
diff
changeset
|
47 |
let val secs = if has_junk s then NONE else Real.fromString s in |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
43033
diff
changeset
|
48 |
if is_none secs orelse Real.< (the secs, 0.0) then |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
43033
diff
changeset
|
49 |
error ("Parameter " ^ quote name ^ " must be assigned a nonnegative \ |
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39890
diff
changeset
|
50 |
\number of seconds (e.g., \"60\", \"0.5\") or \"none\".") |
35963 | 51 |
else |
40341
03156257040f
standardize on seconds for Nitpick and Sledgehammer timeouts
blanchet
parents:
39890
diff
changeset
|
52 |
SOME (seconds (the secs)) |
35963 | 53 |
end |
54 |
||
43029
3e060b1c844b
use helpers and tweak Quickcheck's priority to it comes second (to give Solve Direct slightly more time before another prover runs)
blanchet
parents:
43005
diff
changeset
|
55 |
val subgoal_count = Try.subgoal_count |
38044 | 56 |
|
38696
4c6b65d6a135
quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents:
38652
diff
changeset
|
57 |
fun reserved_isar_keyword_table () = |
48292 | 58 |
Keyword.dest () |-> union (op =) |> map (rpair ()) |> Symtab.make |
38696
4c6b65d6a135
quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents:
38652
diff
changeset
|
59 |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
60 |
(* FIXME: Similar yet different code in "mirabelle.ML". The code here has a few |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
61 |
fixes that seem to be missing over there; or maybe the two code portions are |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
62 |
not doing the same? *) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
63 |
fun fold_body_thms thm_name f = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
64 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
65 |
fun app n (PBody {thms, ...}) = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
66 |
thms |> fold (fn (_, (name, prop, body)) => fn x => |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
67 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
68 |
val body' = Future.join body |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
69 |
val n' = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
70 |
n + (if name = "" orelse |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
71 |
(* uncommon case where the proved theorem occurs twice |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
72 |
(e.g., "Transitive_Closure.trancl_into_trancl") *) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
73 |
(n = 1 andalso name = thm_name) then |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
74 |
0 |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
75 |
else |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
76 |
1) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
77 |
val x' = x |> n' <= 1 ? app n' body' |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
78 |
in (x' |> n = 1 ? f (name, prop, body')) end) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
79 |
in fold (app 0) end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
80 |
|
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
81 |
fun thms_in_proof all_names th = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
82 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
83 |
val is_name_ok = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
84 |
case all_names of |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
85 |
SOME names => member (op =) names |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
86 |
| NONE => (fn s => s <> "" andalso not (String.isPrefix "Pure." s)) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
87 |
fun collect (s, _, _) = is_name_ok s ? insert (op =) s |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
88 |
val names = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
89 |
[] |> fold_body_thms (Thm.get_name_hint th) collect [Thm.proof_body_of th] |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
90 |
in names end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
46957
diff
changeset
|
91 |
|
35963 | 92 |
end; |