author | blanchet |
Fri, 23 Apr 2010 19:12:49 +0200 | |
changeset 36378 | f32c567dbcaa |
parent 36376 | e83d52a52449 |
child 36394 | 1a48d18449d8 |
permissions | -rw-r--r-- |
36375
2482446a604c
move the minimizer to the Sledgehammer directory
blanchet
parents:
36373
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_isar.ML |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
2 |
Author: Jasmin Blanchette, TU Muenchen |
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
3 |
|
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
4 |
Adds "sledgehammer" and related commands to Isabelle/Isar's outer syntax. |
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
5 |
*) |
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
6 |
|
35963 | 7 |
signature SLEDGEHAMMER_ISAR = |
8 |
sig |
|
9 |
type params = ATP_Manager.params |
|
10 |
||
36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
11 |
val atps: string Unsynchronized.ref |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
12 |
val timeout: int Unsynchronized.ref |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
13 |
val full_types: bool Unsynchronized.ref |
35963 | 14 |
val default_params : theory -> (string * string) list -> params |
15 |
end; |
|
16 |
||
35971 | 17 |
structure Sledgehammer_Isar : SLEDGEHAMMER_ISAR = |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
18 |
struct |
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
19 |
|
35971 | 20 |
open Sledgehammer_Util |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
21 |
open ATP_Manager |
36376 | 22 |
open ATP_Systems |
36375
2482446a604c
move the minimizer to the Sledgehammer directory
blanchet
parents:
36373
diff
changeset
|
23 |
open Sledgehammer_Fact_Minimizer |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
24 |
|
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
25 |
structure K = OuterKeyword and P = OuterParse |
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
26 |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
27 |
fun add_to_relevance_override ns : relevance_override = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
28 |
{add = ns, del = [], only = false} |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
29 |
fun del_from_relevance_override ns : relevance_override = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
30 |
{add = [], del = ns, only = false} |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
31 |
fun only_relevance_override ns : relevance_override = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
32 |
{add = ns, del = [], only = true} |
36188 | 33 |
val no_relevance_override = add_to_relevance_override [] |
36003 | 34 |
fun merge_relevance_override_pairwise (r1 : relevance_override) |
35 |
(r2 : relevance_override) = |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
36 |
{add = #add r1 @ #add r2, del = #del r1 @ #del r2, |
36183
f723348b2231
Sledgehammer: the empty set of fact () should mean nothing, not unchanged
blanchet
parents:
36143
diff
changeset
|
37 |
only = #only r1 andalso #only r2} |
36188 | 38 |
fun merge_relevance_overrides rs = |
39 |
fold merge_relevance_override_pairwise rs (only_relevance_override []) |
|
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
40 |
|
36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
41 |
(*** parameters ***) |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
42 |
|
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
43 |
val atps = Unsynchronized.ref (default_atps_param_value ()) |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
44 |
val timeout = Unsynchronized.ref 60 |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
45 |
val full_types = Unsynchronized.ref false |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
46 |
|
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
47 |
val _ = |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
48 |
ProofGeneralPgip.add_preference Preferences.category_proof |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
49 |
(Preferences.string_pref atps |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
50 |
"Sledgehammer: ATPs" |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
51 |
"Default automatic provers (separated by whitespace)") |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
52 |
|
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
53 |
val _ = |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
54 |
ProofGeneralPgip.add_preference Preferences.category_proof |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
55 |
(Preferences.int_pref timeout |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
56 |
"Sledgehammer: Time Limit" |
36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
57 |
"ATPs will be interrupted after this time (in seconds)") |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
58 |
|
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
59 |
val _ = |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
60 |
ProofGeneralPgip.add_preference Preferences.category_proof |
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
61 |
(Preferences.bool_pref full_types |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
62 |
"Sledgehammer: Full Types" "ATPs will use full type information") |
36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36290
diff
changeset
|
63 |
|
35963 | 64 |
type raw_param = string * string list |
65 |
||
66 |
val default_default_params = |
|
67 |
[("debug", "false"), |
|
68 |
("verbose", "false"), |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset
|
69 |
("overlord", "false"), |
36235
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
70 |
("explicit_apply", "false"), |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
36003
diff
changeset
|
71 |
("respect_no_atp", "true"), |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
72 |
("relevance_threshold", "50"), |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
36003
diff
changeset
|
73 |
("convergence", "320"), |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36189
diff
changeset
|
74 |
("theory_relevant", "smart"), |
35963 | 75 |
("higher_order", "smart"), |
76 |
("follow_defs", "false"), |
|
77 |
("isar_proof", "false"), |
|
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
78 |
("modulus", "1"), |
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
79 |
("sorts", "false"), |
35963 | 80 |
("minimize_timeout", "5 s")] |
81 |
||
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
82 |
val alias_params = |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
83 |
[("atp", "atps")] |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
84 |
val negated_alias_params = |
35963 | 85 |
[("no_debug", "debug"), |
86 |
("quiet", "verbose"), |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset
|
87 |
("no_overlord", "overlord"), |
36235
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
88 |
("implicit_apply", "explicit_apply"), |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
36003
diff
changeset
|
89 |
("ignore_no_atp", "respect_no_atp"), |
35963 | 90 |
("partial_types", "full_types"), |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36189
diff
changeset
|
91 |
("theory_irrelevant", "theory_relevant"), |
35963 | 92 |
("first_order", "higher_order"), |
93 |
("dont_follow_defs", "follow_defs"), |
|
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
94 |
("metis_proof", "isar_proof"), |
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
95 |
("no_sorts", "sorts")] |
35963 | 96 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
97 |
val params_for_minimize = |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
98 |
["full_types", "explicit_apply", "higher_order", "isar_proof", "modulus", |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
99 |
"sorts", "minimize_timeout"] |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
100 |
|
35971 | 101 |
val property_dependent_params = ["atps", "full_types", "timeout"] |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
102 |
|
35963 | 103 |
fun is_known_raw_param s = |
104 |
AList.defined (op =) default_default_params s orelse |
|
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
105 |
AList.defined (op =) alias_params s orelse |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
106 |
AList.defined (op =) negated_alias_params s orelse |
35971 | 107 |
member (op =) property_dependent_params s |
35963 | 108 |
|
109 |
fun check_raw_param (s, _) = |
|
110 |
if is_known_raw_param s then () |
|
111 |
else error ("Unknown parameter: " ^ quote s ^ ".") |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
112 |
|
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
113 |
fun unalias_raw_param (name, value) = |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
114 |
case AList.lookup (op =) alias_params name of |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
115 |
SOME name' => (name', value) |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
116 |
| NONE => |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
117 |
case AList.lookup (op =) negated_alias_params name of |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
118 |
SOME name' => (name', case value of |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
119 |
["false"] => ["true"] |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
120 |
| ["true"] => ["false"] |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
121 |
| [] => ["false"] |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
122 |
| _ => value) |
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
123 |
| NONE => (name, value) |
35963 | 124 |
|
125 |
structure Data = Theory_Data( |
|
126 |
type T = raw_param list |
|
127 |
val empty = default_default_params |> map (apsnd single) |
|
128 |
val extend = I |
|
129 |
fun merge p : T = AList.merge (op =) (K true) p) |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
130 |
|
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
131 |
val set_default_raw_param = Data.map o AList.update (op =) o unalias_raw_param |
35963 | 132 |
fun default_raw_params thy = |
133 |
Data.get thy |
|
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
134 |
|> fold (AList.default (op =)) |
36290
c29283184c7a
remove hack that is no longer necessary now that "ATP_Wrapper" properly detects which ATPs are installed
blanchet
parents:
36281
diff
changeset
|
135 |
[("atps", [!atps]), |
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
136 |
("full_types", [if !full_types then "true" else "false"]), |
36142
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36141
diff
changeset
|
137 |
("timeout", let val timeout = !timeout in |
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36141
diff
changeset
|
138 |
[if timeout <= 0 then "none" |
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36141
diff
changeset
|
139 |
else string_of_int timeout ^ " s"] |
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36141
diff
changeset
|
140 |
end)] |
35963 | 141 |
|
142 |
val infinity_time_in_secs = 60 * 60 * 24 * 365 |
|
143 |
val the_timeout = the_default (Time.fromSeconds infinity_time_in_secs) |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
144 |
|
35963 | 145 |
fun extract_params thy default_params override_params = |
146 |
let |
|
36140
08b2a7ecb6c3
fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents:
36064
diff
changeset
|
147 |
val override_params = map unalias_raw_param override_params |
35963 | 148 |
val raw_params = rev override_params @ rev default_params |
149 |
val lookup = Option.map (space_implode " ") o AList.lookup (op =) raw_params |
|
150 |
val lookup_string = the_default "" o lookup |
|
151 |
fun general_lookup_bool option default_value name = |
|
152 |
case lookup name of |
|
35970
3d41a2a490f0
revert debugging output that shouldn't have been submitted in the first place
blanchet
parents:
35966
diff
changeset
|
153 |
SOME s => parse_bool_option option name s |
35963 | 154 |
| NONE => default_value |
155 |
val lookup_bool = the o general_lookup_bool false (SOME false) |
|
156 |
val lookup_bool_option = general_lookup_bool true NONE |
|
157 |
fun lookup_time name = |
|
158 |
the_timeout (case lookup name of |
|
159 |
NONE => NONE |
|
160 |
| SOME s => parse_time_option name s) |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
161 |
fun lookup_int name = |
35963 | 162 |
case lookup name of |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
163 |
NONE => 0 |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
164 |
| SOME s => case Int.fromString s of |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
165 |
SOME n => n |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
166 |
| NONE => error ("Parameter " ^ quote name ^ |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
167 |
" must be assigned an integer value.") |
35963 | 168 |
val debug = lookup_bool "debug" |
169 |
val verbose = debug orelse lookup_bool "verbose" |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset
|
170 |
val overlord = lookup_bool "overlord" |
35963 | 171 |
val atps = lookup_string "atps" |> space_explode " " |
172 |
val full_types = lookup_bool "full_types" |
|
36235
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
173 |
val explicit_apply = lookup_bool "explicit_apply" |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
36003
diff
changeset
|
174 |
val respect_no_atp = lookup_bool "respect_no_atp" |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
175 |
val relevance_threshold = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
176 |
0.01 * Real.fromInt (lookup_int "relevance_threshold") |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
36003
diff
changeset
|
177 |
val convergence = 0.01 * Real.fromInt (lookup_int "convergence") |
36220
f3655a3ae1ab
rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents:
36189
diff
changeset
|
178 |
val theory_relevant = lookup_bool_option "theory_relevant" |
35963 | 179 |
val higher_order = lookup_bool_option "higher_order" |
180 |
val follow_defs = lookup_bool "follow_defs" |
|
181 |
val isar_proof = lookup_bool "isar_proof" |
|
36064
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
182 |
val modulus = Int.max (1, lookup_int "modulus") |
48aec67c284f
added "modulus" and "sorts" options to control Sledgehammer's Isar proof output
blanchet
parents:
36063
diff
changeset
|
183 |
val sorts = lookup_bool "sorts" |
35963 | 184 |
val timeout = lookup_time "timeout" |
185 |
val minimize_timeout = lookup_time "minimize_timeout" |
|
186 |
in |
|
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset
|
187 |
{debug = debug, verbose = verbose, overlord = overlord, atps = atps, |
36235
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
188 |
full_types = full_types, explicit_apply = explicit_apply, |
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
189 |
respect_no_atp = respect_no_atp, relevance_threshold = relevance_threshold, |
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
190 |
convergence = convergence, theory_relevant = theory_relevant, |
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
191 |
higher_order = higher_order, follow_defs = follow_defs, |
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
192 |
isar_proof = isar_proof, modulus = modulus, sorts = sorts, |
61159615a0c5
added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents:
36223
diff
changeset
|
193 |
timeout = timeout, minimize_timeout = minimize_timeout} |
35963 | 194 |
end |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
195 |
|
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
196 |
fun get_params thy = extract_params thy (default_raw_params thy) |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
197 |
fun default_params thy = get_params thy o map (apsnd single) |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
198 |
|
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
199 |
(* Sledgehammer the given subgoal *) |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
200 |
|
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
201 |
fun run {atps = [], ...} _ _ _ _ = error "No ATP is set." |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
202 |
| run (params as {atps, timeout, ...}) i relevance_override minimize_command |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
203 |
proof_state = |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
204 |
let |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
205 |
val birth_time = Time.now () |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
206 |
val death_time = Time.+ (birth_time, timeout) |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
207 |
val _ = kill_atps () (* race w.r.t. other invocations of Sledgehammer *) |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
208 |
val _ = priority "Sledgehammering..." |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
209 |
val _ = List.app (start_prover_thread params birth_time death_time i |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
210 |
relevance_override minimize_command |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
211 |
proof_state) atps |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
212 |
in () end |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
213 |
|
36378 | 214 |
fun minimize override_params i fact_refs state = |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
215 |
let |
35963 | 216 |
val thy = Proof.theory_of state |
217 |
val ctxt = Proof.context_of state |
|
36378 | 218 |
val theorems_from_refs = |
219 |
map o pairf Facts.string_of_ref o ProofContext.get_fact |
|
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
220 |
val name_thms_pairs = theorems_from_refs ctxt fact_refs |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
221 |
in |
36378 | 222 |
priority (#2 (minimize_theorems (get_params thy override_params) i state |
223 |
name_thms_pairs)) |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
224 |
end |
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
225 |
|
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
226 |
val sledgehammerN = "sledgehammer" |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
227 |
val sledgehammer_paramsN = "sledgehammer_params" |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
228 |
|
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
229 |
val runN = "run" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
230 |
val minimizeN = "minimize" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
231 |
val messagesN = "messages" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
232 |
val available_atpsN = "available_atps" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
233 |
val running_atpsN = "running_atps" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
234 |
val kill_atpsN = "kill_atps" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
235 |
val refresh_tptpN = "refresh_tptp" |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
236 |
val helpN = "help" |
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
237 |
|
36141
c31602d268be
make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents:
36140
diff
changeset
|
238 |
fun minimizize_raw_param_name "timeout" = "minimize_timeout" |
c31602d268be
make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents:
36140
diff
changeset
|
239 |
| minimizize_raw_param_name name = name |
c31602d268be
make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents:
36140
diff
changeset
|
240 |
|
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
241 |
val is_raw_param_relevant_for_minimize = |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
242 |
member (op =) params_for_minimize o fst o unalias_raw_param |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
243 |
fun string_for_raw_param (key, values) = |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
244 |
key ^ (case space_implode " " values of |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
245 |
"" => "" |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
246 |
| value => " = " ^ value) |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
247 |
|
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
248 |
fun minimize_command override_params i atp_name facts = |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
249 |
sledgehammerN ^ " " ^ minimizeN ^ " [atp = " ^ atp_name ^ |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
250 |
(override_params |> filter is_raw_param_relevant_for_minimize |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
251 |
|> implode o map (prefix ", " o string_for_raw_param)) ^ |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
252 |
"] (" ^ space_implode " " facts ^ ")" ^ |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
253 |
(if i = 1 then "" else " " ^ string_of_int i) |
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
254 |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
255 |
fun hammer_away override_params subcommand opt_i relevance_override state = |
35963 | 256 |
let |
257 |
val thy = Proof.theory_of state |
|
258 |
val _ = List.app check_raw_param override_params |
|
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
259 |
in |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
260 |
if subcommand = runN then |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
261 |
let val i = the_default 1 opt_i in |
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
262 |
run (get_params thy override_params) i relevance_override |
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
263 |
(minimize_command override_params i) state |
36281
dbbf4d5d584d
pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents:
36235
diff
changeset
|
264 |
end |
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
265 |
else if subcommand = minimizeN then |
36378 | 266 |
minimize (map (apfst minimizize_raw_param_name) override_params) |
36141
c31602d268be
make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents:
36140
diff
changeset
|
267 |
(the_default 1 opt_i) (#add relevance_override) state |
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
268 |
else if subcommand = messagesN then |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
269 |
messages opt_i |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
270 |
else if subcommand = available_atpsN then |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
271 |
available_atps thy |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
272 |
else if subcommand = running_atpsN then |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
273 |
running_atps () |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
274 |
else if subcommand = kill_atpsN then |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
275 |
kill_atps () |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
276 |
else if subcommand = refresh_tptpN then |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
277 |
refresh_systems_on_tptp () |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
278 |
else |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
279 |
error ("Unknown subcommand: " ^ quote subcommand ^ ".") |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
280 |
end |
35963 | 281 |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
282 |
fun sledgehammer_trans (((subcommand, params), relevance_override), opt_i) = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
283 |
Toplevel.keep (hammer_away params subcommand opt_i relevance_override |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
284 |
o Toplevel.proof_of) |
35963 | 285 |
|
286 |
fun string_for_raw_param (name, value) = name ^ " = " ^ space_implode " " value |
|
287 |
||
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
288 |
fun sledgehammer_params_trans params = |
35963 | 289 |
Toplevel.theory |
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
290 |
(fold set_default_raw_param params |
35963 | 291 |
#> tap (fn thy => |
292 |
writeln ("Default parameters for Sledgehammer:\n" ^ |
|
293 |
(case rev (default_raw_params thy) of |
|
294 |
[] => "none" |
|
295 |
| params => |
|
296 |
(map check_raw_param params; |
|
297 |
params |> map string_for_raw_param |
|
298 |
|> sort_strings |> cat_lines))))) |
|
299 |
||
300 |
val parse_key = Scan.repeat1 P.typ_group >> space_implode " " |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
301 |
val parse_value = Scan.repeat1 P.xname |
35965
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
302 |
val parse_param = parse_key -- Scan.optional (P.$$$ "=" |-- parse_value) [] |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
303 |
val parse_params = Scan.optional (Args.bracks (P.list parse_param)) [] |
0fce6db7babd
added a syntax for specifying facts to Sledgehammer;
blanchet
parents:
35963
diff
changeset
|
304 |
val parse_fact_refs = |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
305 |
Scan.repeat1 (Scan.unless (P.name -- Args.colon) |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
306 |
(P.xname -- Scan.option Attrib.thm_sel) |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
307 |
>> (fn (name, interval) => |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
308 |
Facts.Named ((name, Position.none), interval))) |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
309 |
val parse_relevance_chunk = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
310 |
(Args.add |-- Args.colon |-- parse_fact_refs >> add_to_relevance_override) |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
311 |
|| (Args.del |-- Args.colon |-- parse_fact_refs |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
312 |
>> del_from_relevance_override) |
36188 | 313 |
|| (parse_fact_refs >> only_relevance_override) |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
314 |
val parse_relevance_override = |
36188 | 315 |
Scan.optional (Args.parens (Scan.repeat parse_relevance_chunk |
316 |
>> merge_relevance_overrides)) |
|
317 |
(add_to_relevance_override []) |
|
35963 | 318 |
val parse_sledgehammer_command = |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
319 |
(Scan.optional P.short_ident runN -- parse_params -- parse_relevance_override |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35965
diff
changeset
|
320 |
-- Scan.option P.nat) #>> sledgehammer_trans |
35963 | 321 |
val parse_sledgehammer_params_command = |
322 |
parse_params #>> sledgehammer_params_trans |
|
323 |
||
324 |
val _ = |
|
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
325 |
OuterSyntax.improper_command sledgehammerN |
35963 | 326 |
"search for first-order proof using automatic theorem provers" K.diag |
327 |
parse_sledgehammer_command |
|
328 |
val _ = |
|
36373
66af0a49de39
move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents:
36371
diff
changeset
|
329 |
OuterSyntax.command sledgehammer_paramsN |
35963 | 330 |
"set and display the default parameters for Sledgehammer" K.thy_decl |
331 |
parse_sledgehammer_params_command |
|
35866
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
332 |
|
513074557e06
move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff
changeset
|
333 |
end; |