52590
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_reconstructor.ML
|
52555
|
2 |
Author: Jasmin Blanchette, TU Muenchen
|
|
3 |
Author: Steffen Juilf Smolka, TU Muenchen
|
|
4 |
|
|
5 |
Reconstructors.
|
|
6 |
*)
|
|
7 |
|
|
8 |
signature SLEDGEHAMMER_RECONSTRUCTOR =
|
|
9 |
sig
|
|
10 |
type stature = ATP_Problem_Generate.stature
|
|
11 |
|
|
12 |
datatype reconstructor =
|
|
13 |
Metis of string * string |
|
|
14 |
SMT
|
|
15 |
|
54824
|
16 |
datatype play_outcome =
|
|
17 |
Played of Time.time |
|
|
18 |
Play_Timed_Out of Time.time |
|
|
19 |
Play_Failed |
|
|
20 |
Not_Played
|
52555
|
21 |
|
|
22 |
type minimize_command = string list -> string
|
54824
|
23 |
type one_line_params =
|
|
24 |
(reconstructor * play_outcome) * string * (string * stature) list * minimize_command * int * int
|
52555
|
25 |
|
|
26 |
val smtN : string
|
55212
|
27 |
|
55211
|
28 |
val string_of_reconstructor : reconstructor -> string
|
|
29 |
val string_of_play_outcome : play_outcome -> string
|
55269
|
30 |
val play_outcome_ord : play_outcome * play_outcome -> order
|
|
31 |
|
55211
|
32 |
val one_line_proof_text : int -> one_line_params -> string
|
55170
|
33 |
val silence_reconstructors : bool -> Proof.context -> Proof.context
|
54495
|
34 |
end;
|
52555
|
35 |
|
|
36 |
structure Sledgehammer_Reconstructor : SLEDGEHAMMER_RECONSTRUCTOR =
|
|
37 |
struct
|
|
38 |
|
54828
|
39 |
open ATP_Util
|
52555
|
40 |
open ATP_Problem_Generate
|
55211
|
41 |
open ATP_Proof_Reconstruct
|
52555
|
42 |
|
|
43 |
datatype reconstructor =
|
|
44 |
Metis of string * string |
|
|
45 |
SMT
|
|
46 |
|
54824
|
47 |
datatype play_outcome =
|
|
48 |
Played of Time.time |
|
|
49 |
Play_Timed_Out of Time.time |
|
|
50 |
Play_Failed |
|
|
51 |
Not_Played
|
52555
|
52 |
|
55211
|
53 |
type minimize_command = string list -> string
|
|
54 |
type one_line_params =
|
|
55 |
(reconstructor * play_outcome) * string * (string * stature) list * minimize_command * int * int
|
|
56 |
|
|
57 |
val smtN = "smt"
|
|
58 |
|
|
59 |
fun string_of_reconstructor (Metis (type_enc, lam_trans)) = metis_call type_enc lam_trans
|
|
60 |
| string_of_reconstructor SMT = smtN
|
|
61 |
|
54828
|
62 |
fun string_of_play_outcome (Played time) = string_of_ext_time (false, time)
|
|
63 |
| string_of_play_outcome (Play_Timed_Out time) = string_of_ext_time (true, time) ^ ", timed out"
|
|
64 |
| string_of_play_outcome Play_Failed = "failed"
|
|
65 |
| string_of_play_outcome _ = "unknown"
|
|
66 |
|
55269
|
67 |
fun play_outcome_ord (Played time1, Played time2) =
|
|
68 |
int_ord (pairself Time.toMilliseconds (time1, time2))
|
|
69 |
| play_outcome_ord (Played _, _) = LESS
|
|
70 |
| play_outcome_ord (_, Played _) = GREATER
|
|
71 |
| play_outcome_ord (Not_Played, Not_Played) = EQUAL
|
|
72 |
| play_outcome_ord (Not_Played, _) = LESS
|
|
73 |
| play_outcome_ord (_, Not_Played) = GREATER
|
|
74 |
| play_outcome_ord (Play_Timed_Out time1, Play_Timed_Out time2) =
|
|
75 |
int_ord (pairself Time.toMilliseconds (time1, time2))
|
|
76 |
| play_outcome_ord (Play_Timed_Out _, _) = LESS
|
|
77 |
| play_outcome_ord (_, Play_Timed_Out _) = GREATER
|
|
78 |
| play_outcome_ord (Play_Failed, Play_Failed) = EQUAL
|
|
79 |
|
55211
|
80 |
(* FIXME: Various bugs, esp. with "unfolding"
|
|
81 |
fun unusing_chained_facts _ 0 = ""
|
|
82 |
| unusing_chained_facts used_chaineds num_chained =
|
|
83 |
if length used_chaineds = num_chained then ""
|
|
84 |
else if null used_chaineds then "(* using no facts *) "
|
|
85 |
else "(* using only " ^ space_implode " " used_chaineds ^ " *) "
|
|
86 |
*)
|
|
87 |
|
|
88 |
fun apply_on_subgoal _ 1 = "by "
|
|
89 |
| apply_on_subgoal 1 _ = "apply "
|
|
90 |
| apply_on_subgoal i n =
|
|
91 |
"prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n
|
|
92 |
|
|
93 |
fun command_call name [] =
|
|
94 |
name |> not (Symbol_Pos.is_identifier name) ? enclose "(" ")"
|
|
95 |
| command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")"
|
|
96 |
|
|
97 |
fun reconstructor_command reconstr i n used_chaineds num_chained ss =
|
|
98 |
(* unusing_chained_facts used_chaineds num_chained ^ *)
|
|
99 |
apply_on_subgoal i n ^ command_call (string_of_reconstructor reconstr) ss
|
|
100 |
|
|
101 |
fun show_time NONE = ""
|
|
102 |
| show_time (SOME ext_time) = " (" ^ string_of_ext_time ext_time ^ ")"
|
|
103 |
|
|
104 |
fun try_command_line banner time command =
|
|
105 |
banner ^ ": " ^ Active.sendback_markup [Markup.padding_command] command ^ show_time time ^ "."
|
52555
|
106 |
|
55211
|
107 |
fun minimize_line _ [] = ""
|
|
108 |
| minimize_line minimize_command ss =
|
|
109 |
(case minimize_command ss of
|
|
110 |
"" => ""
|
|
111 |
| command => "\nTo minimize: " ^ Active.sendback_markup [Markup.padding_command] command ^ ".")
|
|
112 |
|
|
113 |
fun split_used_facts facts =
|
|
114 |
facts
|
|
115 |
|> List.partition (fn (_, (sc, _)) => sc = Chained)
|
|
116 |
|> pairself (sort_distinct (string_ord o pairself fst))
|
|
117 |
|
|
118 |
fun one_line_proof_text num_chained
|
|
119 |
((reconstr, play), banner, used_facts, minimize_command, subgoal, subgoal_count) =
|
|
120 |
let
|
|
121 |
val (chained, extra) = split_used_facts used_facts
|
|
122 |
|
|
123 |
val (failed, ext_time) =
|
|
124 |
(case play of
|
|
125 |
Played time => (false, (SOME (false, time)))
|
|
126 |
| Play_Timed_Out time => (false, SOME (true, time))
|
|
127 |
| Play_Failed => (true, NONE)
|
|
128 |
| Not_Played => (false, NONE))
|
|
129 |
|
|
130 |
val try_line =
|
|
131 |
map fst extra
|
|
132 |
|> reconstructor_command reconstr subgoal subgoal_count (map fst chained) num_chained
|
|
133 |
|> (if failed then
|
|
134 |
enclose "One-line proof reconstruction failed: "
|
|
135 |
".\n(Invoking \"sledgehammer\" with \"[strict]\" might solve this.)"
|
|
136 |
else
|
|
137 |
try_command_line banner ext_time)
|
|
138 |
in
|
|
139 |
try_line ^ minimize_line minimize_command (map fst (extra @ chained))
|
|
140 |
end
|
52555
|
141 |
|
55170
|
142 |
(* Makes reconstructor tools as silent as possible. The "set_visible" calls suppresses "Unification
|
|
143 |
bound exceeded" warnings and the like. *)
|
|
144 |
fun silence_reconstructors debug =
|
55180
|
145 |
Try0.silence_methods debug
|
55170
|
146 |
#> Config.put SMT_Config.verbose debug
|
|
147 |
|
54495
|
148 |
end;
|