src/HOL/Mirabelle/Tools/mirabelle_sledgehammer.ML
changeset 58473 d919cde25691
parent 58061 3d060f43accb
child 58843 521cea5fa777
equal deleted inserted replaced
58472:4d00caa0e4d7 58473:d919cde25691
    21 val max_factsK = "max_facts" (*=NUM: max. relevant clauses to use*)
    21 val max_factsK = "max_facts" (*=NUM: max. relevant clauses to use*)
    22 val max_relevantK = "max_relevant" (*=NUM: max. relevant clauses to use*)
    22 val max_relevantK = "max_relevant" (*=NUM: max. relevant clauses to use*)
    23 val max_callsK = "max_calls" (*=NUM: max. no. of calls to sledgehammer*)
    23 val max_callsK = "max_calls" (*=NUM: max. no. of calls to sledgehammer*)
    24 val preplay_timeoutK = "preplay_timeout" (*=TIME: timeout for finding reconstructed proof*)
    24 val preplay_timeoutK = "preplay_timeout" (*=TIME: timeout for finding reconstructed proof*)
    25 val isar_proofsK = "isar_proofs" (*: enable Isar proof generation*)
    25 val isar_proofsK = "isar_proofs" (*: enable Isar proof generation*)
       
    26 val smt_proofsK = "smt_proofs" (*: enable SMT proof generation*)
    26 val minimizeK = "minimize" (*: instruct sledgehammer to run its minimizer*)
    27 val minimizeK = "minimize" (*: instruct sledgehammer to run its minimizer*)
    27 
    28 
    28 val check_trivialK = "check_trivial" (*: check if goals are "trivial" (false by default)*)
    29 val check_trivialK = "check_trivial" (*: check if goals are "trivial" (false by default)*)
    29 val fact_filterK = "fact_filter" (*=STRING: fact filter*)
    30 val fact_filterK = "fact_filter" (*=STRING: fact filter*)
    30 val type_encK = "type_enc" (*=STRING: type encoding scheme*)
    31 val type_encK = "type_enc" (*=STRING: type encoding scheme*)
   314     Sledgehammer_Prover_Minimize.get_minimizing_prover ctxt Sledgehammer_Prover.Normal learn name
   315     Sledgehammer_Prover_Minimize.get_minimizing_prover ctxt Sledgehammer_Prover.Normal learn name
   315   end
   316   end
   316 
   317 
   317 type stature = ATP_Problem_Generate.stature
   318 type stature = ATP_Problem_Generate.stature
   318 
   319 
   319 fun good_line s =
   320 fun is_good_line s =
   320   (String.isSubstring " ms)" s orelse String.isSubstring " s)" s)
   321   (String.isSubstring " ms)" s orelse String.isSubstring " s)" s)
   321   andalso not (String.isSubstring "(> " s)
   322   andalso not (String.isSubstring "(> " s)
   322   andalso not (String.isSubstring ", > " s)
   323   andalso not (String.isSubstring ", > " s)
   323   andalso not (String.isSubstring "may fail" s)
   324   andalso not (String.isSubstring "may fail" s)
   324 
   325 
   325 (* Fragile hack *)
   326 (* Fragile hack *)
   326 fun proof_method_from_msg args msg =
   327 fun proof_method_from_msg args msg =
   327   (case AList.lookup (op =) args proof_methodK of
   328   (case AList.lookup (op =) args proof_methodK of
   328     SOME name => name
   329     SOME name =>
       
   330     if name = "smart" then
       
   331       if exists is_good_line (split_lines msg) then
       
   332         "none"
       
   333       else
       
   334         "fail"
       
   335     else
       
   336       name
   329   | NONE =>
   337   | NONE =>
   330     if exists good_line (split_lines msg) then
   338     if exists is_good_line (split_lines msg) then
   331       "none" (* trust the preplayed proof *)
   339       "none" (* trust the preplayed proof *)
   332     else if String.isSubstring "metis (" msg then
   340     else if String.isSubstring "metis (" msg then
   333       msg |> Substring.full
   341       msg |> Substring.full
   334           |> Substring.position "metis ("
   342           |> Substring.position "metis ("
   335           |> snd |> Substring.position ")"
   343           |> snd |> Substring.position ")"
   347   SH_FAIL of int * int |
   355   SH_FAIL of int * int |
   348   SH_ERROR
   356   SH_ERROR
   349 
   357 
   350 fun run_sh prover_name fact_filter type_enc strict max_facts slice
   358 fun run_sh prover_name fact_filter type_enc strict max_facts slice
   351       lam_trans uncurried_aliases e_selection_heuristic term_order force_sos
   359       lam_trans uncurried_aliases e_selection_heuristic term_order force_sos
   352       hard_timeout timeout preplay_timeout isar_proofsLST minimizeLST
   360       hard_timeout timeout preplay_timeout isar_proofsLST smt_proofsLST
   353       max_new_mono_instancesLST max_mono_itersLST dir pos st =
   361       minimizeLST max_new_mono_instancesLST max_mono_itersLST dir pos st =
   354   let
   362   let
   355     val thy = Proof.theory_of st
   363     val thy = Proof.theory_of st
   356     val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
   364     val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
   357     val i = 1
   365     val i = 1
   358     fun set_file_name (SOME dir) =
   366     fun set_file_name (SOME dir) =
   373                   term_order |> the_default I)
   381                   term_order |> the_default I)
   374             #> (Option.map (Config.put ATP_Systems.force_sos)
   382             #> (Option.map (Config.put ATP_Systems.force_sos)
   375                   force_sos |> the_default I))
   383                   force_sos |> the_default I))
   376     val params as {max_facts, minimize, preplay_timeout, ...} =
   384     val params as {max_facts, minimize, preplay_timeout, ...} =
   377       Sledgehammer_Commands.default_params thy
   385       Sledgehammer_Commands.default_params thy
   378          ([("verbose", "true"),
   386          ([(* ("verbose", "true"), *)
   379            ("fact_filter", fact_filter),
   387            ("fact_filter", fact_filter),
   380            ("type_enc", type_enc),
   388            ("type_enc", type_enc),
   381            ("strict", strict),
   389            ("strict", strict),
   382            ("lam_trans", lam_trans |> the_default lam_trans_default),
   390            ("lam_trans", lam_trans |> the_default lam_trans_default),
   383            ("uncurried_aliases", uncurried_aliases |> the_default uncurried_aliases_default),
   391            ("uncurried_aliases", uncurried_aliases |> the_default uncurried_aliases_default),
   384            ("max_facts", max_facts),
   392            ("max_facts", max_facts),
   385            ("slice", slice),
   393            ("slice", slice),
   386            ("timeout", string_of_int timeout),
   394            ("timeout", string_of_int timeout),
   387            ("preplay_timeout", preplay_timeout)]
   395            ("preplay_timeout", preplay_timeout)]
   388           |> isar_proofsLST
   396           |> isar_proofsLST
       
   397           |> smt_proofsLST
   389           |> minimizeLST (*don't confuse the two minimization flags*)
   398           |> minimizeLST (*don't confuse the two minimization flags*)
   390           |> max_new_mono_instancesLST
   399           |> max_new_mono_instancesLST
   391           |> max_mono_itersLST)
   400           |> max_mono_itersLST)
   392     val default_max_facts =
   401     val default_max_facts =
   393       Sledgehammer_Prover_Minimize.default_max_facts_of_prover ctxt prover_name
   402       Sledgehammer_Prover_Minimize.default_max_facts_of_prover ctxt prover_name
   469     (* always use a hard timeout, but give some slack so that the automatic
   478     (* always use a hard timeout, but give some slack so that the automatic
   470        minimizer has a chance to do its magic *)
   479        minimizer has a chance to do its magic *)
   471     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
   480     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
   472       |> the_default preplay_timeout_default
   481       |> the_default preplay_timeout_default
   473     val isar_proofsLST = available_parameter args isar_proofsK "isar_proofs"
   482     val isar_proofsLST = available_parameter args isar_proofsK "isar_proofs"
       
   483     val smt_proofsLST = available_parameter args smt_proofsK "smt_proofs"
   474     val minimizeLST = available_parameter args minimizeK "minimize"
   484     val minimizeLST = available_parameter args minimizeK "minimize"
   475     val max_new_mono_instancesLST =
   485     val max_new_mono_instancesLST =
   476       available_parameter args max_new_mono_instancesK max_new_mono_instancesK
   486       available_parameter args max_new_mono_instancesK max_new_mono_instancesK
   477     val max_mono_itersLST = available_parameter args max_mono_itersK max_mono_itersK
   487     val max_mono_itersLST = available_parameter args max_mono_itersK max_mono_itersK
   478     val hard_timeout = SOME (4 * timeout)
   488     val hard_timeout = SOME (4 * timeout)
   479     val (msg, result) =
   489     val (msg, result) =
   480       run_sh prover_name fact_filter type_enc strict max_facts slice lam_trans
   490       run_sh prover_name fact_filter type_enc strict max_facts slice lam_trans
   481         uncurried_aliases e_selection_heuristic term_order force_sos
   491         uncurried_aliases e_selection_heuristic term_order force_sos
   482         hard_timeout timeout preplay_timeout isar_proofsLST minimizeLST
   492         hard_timeout timeout preplay_timeout isar_proofsLST smt_proofsLST
   483         max_new_mono_instancesLST max_mono_itersLST dir pos st
   493         minimizeLST max_new_mono_instancesLST max_mono_itersLST dir pos st
   484   in
   494   in
   485     (case result of
   495     (case result of
   486       SH_OK (time_isa, time_prover, names) =>
   496       SH_OK (time_isa, time_prover, names) =>
   487         let
   497         let
   488           fun get_thms (name, stature) =
   498           fun get_thms (name, stature) =
   557               |>> the_default [ATP_Proof_Reconstruct.partial_typesN]
   567               |>> the_default [ATP_Proof_Reconstruct.partial_typesN]
   558               ||> the_default ATP_Proof_Reconstruct.default_metis_lam_trans
   568               ||> the_default ATP_Proof_Reconstruct.default_metis_lam_trans
   559           in Metis_Tactic.metis_tac type_encs lam_trans ctxt thms end
   569           in Metis_Tactic.metis_tac type_encs lam_trans ctxt thms end
   560         else if !meth = "metis" then
   570         else if !meth = "metis" then
   561           Metis_Tactic.metis_tac [] ATP_Proof_Reconstruct.default_metis_lam_trans ctxt thms
   571           Metis_Tactic.metis_tac [] ATP_Proof_Reconstruct.default_metis_lam_trans ctxt thms
       
   572         else if !meth = "none" then
       
   573           K all_tac
       
   574         else if !meth = "fail" then
       
   575           K no_tac
   562         else
   576         else
   563           K all_tac
   577           (warning ("Unknown method " ^ quote (!meth)); K no_tac)
   564       end
   578       end
   565     fun apply_method named_thms =
   579     fun apply_method named_thms =
   566       Mirabelle.can_apply timeout (do_method named_thms) st
   580       Mirabelle.can_apply timeout (do_method named_thms) st
   567 
   581 
   568     fun with_time (false, t) = "failed (" ^ string_of_int t ^ ")"
   582     fun with_time (false, t) = "failed (" ^ string_of_int t ^ ")"