1 (* Title: HOL/Tools/Sledgehammer/sledgehammer_reconstructor.ML
2 Author: Jasmin Blanchette, TU Muenchen
3 Author: Steffen Juilf Smolka, TU Muenchen
8 signature SLEDGEHAMMER_RECONSTRUCTOR =
10 type stature = ATP_Problem_Generate.stature
12 datatype proof_method =
13 Metis_Method of string option * string option |
25 datatype play_outcome =
27 Play_Timed_Out of Time.time |
31 type minimize_command = string list -> string
32 type one_line_params =
33 (proof_method * play_outcome) * string * (string * stature) list * minimize_command * int * int
37 val string_of_proof_method : proof_method -> string
38 val tac_of_proof_method : Proof.context -> thm list * thm list -> proof_method -> int -> tactic
39 val string_of_play_outcome : play_outcome -> string
40 val play_outcome_ord : play_outcome * play_outcome -> order
42 val one_line_proof_text : int -> one_line_params -> string
43 val silence_proof_methods : bool -> Proof.context -> Proof.context
46 structure Sledgehammer_Reconstructor : SLEDGEHAMMER_RECONSTRUCTOR =
50 open ATP_Problem_Generate
51 open ATP_Proof_Reconstruct
53 datatype proof_method =
54 Metis_Method of string option * string option |
66 datatype play_outcome =
68 Play_Timed_Out of Time.time |
72 type minimize_command = string list -> string
73 type one_line_params =
74 (proof_method * play_outcome) * string * (string * stature) list * minimize_command * int * int
78 fun string_of_proof_method meth =
80 Metis_Method (NONE, NONE) => "metis"
81 | Metis_Method (type_enc_opt, lam_trans_opt) =>
82 "metis (" ^ commas (map_filter I [type_enc_opt, lam_trans_opt]) ^ ")"
83 | Meson_Method => "meson"
85 | Simp_Method => "simp"
86 | Simp_Size_Method => "simp add: size_ne_size_imp_ne"
87 | Auto_Method => "auto"
88 | Fastforce_Method => "fastforce"
89 | Force_Method => "force"
90 | Arith_Method => "arith"
91 | Blast_Method => "blast"
92 | Algebra_Method => "algebra")
94 fun tac_of_proof_method ctxt (local_facts, global_facts) meth =
95 Method.insert_tac local_facts THEN'
97 Metis_Method (type_enc_opt, lam_trans_opt) =>
98 Metis_Tactic.metis_tac [type_enc_opt |> the_default partial_type_enc]
99 (the_default default_metis_lam_trans lam_trans_opt) ctxt global_facts
100 | SMT_Method => SMT_Solver.smt_tac ctxt global_facts
101 | Meson_Method => Meson.meson_tac ctxt global_facts
103 Method.insert_tac global_facts THEN'
105 Simp_Method => Simplifier.asm_full_simp_tac ctxt
106 | Simp_Size_Method =>
107 Simplifier.asm_full_simp_tac (Simplifier.add_simp @{thm size_ne_size_imp_ne} ctxt)
108 | Auto_Method => K (Clasimp.auto_tac ctxt)
109 | Fastforce_Method => Clasimp.fast_force_tac ctxt
110 | Force_Method => Clasimp.force_tac ctxt
111 | Arith_Method => Arith_Data.arith_tac ctxt
112 | Blast_Method => blast_tac ctxt
113 | Algebra_Method => Groebner.algebra_tac [] [] ctxt))
115 fun string_of_play_outcome (Played time) = string_of_ext_time (false, time)
116 | string_of_play_outcome (Play_Timed_Out time) = string_of_ext_time (true, time) ^ ", timed out"
117 | string_of_play_outcome Play_Failed = "failed"
118 | string_of_play_outcome _ = "unknown"
120 fun play_outcome_ord (Played time1, Played time2) =
121 int_ord (pairself Time.toMilliseconds (time1, time2))
122 | play_outcome_ord (Played _, _) = LESS
123 | play_outcome_ord (_, Played _) = GREATER
124 | play_outcome_ord (Not_Played, Not_Played) = EQUAL
125 | play_outcome_ord (Not_Played, _) = LESS
126 | play_outcome_ord (_, Not_Played) = GREATER
127 | play_outcome_ord (Play_Timed_Out time1, Play_Timed_Out time2) =
128 int_ord (pairself Time.toMilliseconds (time1, time2))
129 | play_outcome_ord (Play_Timed_Out _, _) = LESS
130 | play_outcome_ord (_, Play_Timed_Out _) = GREATER
131 | play_outcome_ord (Play_Failed, Play_Failed) = EQUAL
133 (* FIXME: Various bugs, esp. with "unfolding"
134 fun unusing_chained_facts _ 0 = ""
135 | unusing_chained_facts used_chaineds num_chained =
136 if length used_chaineds = num_chained then ""
137 else if null used_chaineds then "(* using no facts *) "
138 else "(* using only " ^ space_implode " " used_chaineds ^ " *) "
141 fun apply_on_subgoal _ 1 = "by "
142 | apply_on_subgoal 1 _ = "apply "
143 | apply_on_subgoal i n =
144 "prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n
146 fun command_call name [] =
147 name |> not (Symbol_Pos.is_identifier name) ? enclose "(" ")"
148 | command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")"
151 fun proof_method_command meth i n used_chaineds num_chained ss =
152 (* unusing_chained_facts used_chaineds num_chained ^ *)
153 apply_on_subgoal i n ^ command_call (string_of_proof_method meth) ss
155 fun show_time NONE = ""
156 | show_time (SOME ext_time) = " (" ^ string_of_ext_time ext_time ^ ")"
158 fun try_command_line banner time command =
159 banner ^ ": " ^ Active.sendback_markup [Markup.padding_command] command ^ show_time time ^ "."
161 fun minimize_line _ [] = ""
162 | minimize_line minimize_command ss =
163 (case minimize_command ss of
165 | command => "\nTo minimize: " ^ Active.sendback_markup [Markup.padding_command] command ^ ".")
167 fun split_used_facts facts =
169 |> List.partition (fn (_, (sc, _)) => sc = Chained)
170 |> pairself (sort_distinct (string_ord o pairself fst))
172 fun one_line_proof_text num_chained
173 ((meth, play), banner, used_facts, minimize_command, subgoal, subgoal_count) =
175 val (chained, extra) = split_used_facts used_facts
177 val (failed, ext_time) =
179 Played time => (false, (SOME (false, time)))
180 | Play_Timed_Out time => (false, SOME (true, time))
181 | Play_Failed => (true, NONE)
182 | Not_Played => (false, NONE))
186 |> proof_method_command meth subgoal subgoal_count (map fst chained) num_chained
188 enclose "One-line proof reconstruction failed: "
189 ".\n(Invoking \"sledgehammer\" with \"[strict]\" might solve this.)"
191 try_command_line banner ext_time)
193 try_line ^ minimize_line minimize_command (map fst (extra @ chained))
196 (* Makes proof methods as silent as possible. The "set_visible" calls suppresses "Unification bound
197 exceeded" warnings and the like. *)
198 fun silence_proof_methods debug =
199 Try0.silence_methods debug
200 #> Config.put SMT_Config.verbose debug