src/HOL/Mirabelle/Tools/mirabelle_sledgehammer.ML
changeset 46826 4c80c4034f1d
parent 46825 98300d5f9cc0
child 47030 7e80e14247fc
equal deleted inserted replaced
46825:98300d5f9cc0 46826:4c80c4034f1d
    21 val minimize_timeoutK = "minimize_timeout"
    21 val minimize_timeoutK = "minimize_timeout"
    22 val metis_ftK = "metis_ft"
    22 val metis_ftK = "metis_ft"
    23 val reconstructorK = "reconstructor"
    23 val reconstructorK = "reconstructor"
    24 val preplay_timeoutK = "preplay_timeout"
    24 val preplay_timeoutK = "preplay_timeout"
    25 val sh_minimizeK = "sh_minimize" (*refers to minimizer run within Sledgehammer*)
    25 val sh_minimizeK = "sh_minimize" (*refers to minimizer run within Sledgehammer*)
       
    26 val max_new_mono_instancesK = "max_new_mono_instances"
       
    27 val max_mono_itersK = "max_mono_iters"
    26 
    28 
    27 fun sh_tag id = "#" ^ string_of_int id ^ " sledgehammer: "
    29 fun sh_tag id = "#" ^ string_of_int id ^ " sledgehammer: "
    28 fun minimize_tag id = "#" ^ string_of_int id ^ " minimize (sledgehammer): "
    30 fun minimize_tag id = "#" ^ string_of_int id ^ " minimize (sledgehammer): "
    29 fun reconstructor_tag reconstructor id =
    31 fun reconstructor_tag reconstructor id =
    30   "#" ^ string_of_int id ^ " " ^ (!reconstructor) ^ " (sledgehammer): "
    32   "#" ^ string_of_int id ^ " " ^ (!reconstructor) ^ " (sledgehammer): "
    31 
    33 
    32 val separator = "-----"
    34 val separator = "-----"
    33 
    35 
    34 val preplay_timeout_default = "4"
    36 val preplay_timeout_default = "4"
       
    37 (*FIXME sensible to have Mirabelle-level Sledgehammer defaults?*)
       
    38 
       
    39 (*If a key is present in args then augment a list with its pair*)
       
    40 (*This is used to avoid fixing default values at the Mirabelle level, and
       
    41   instead use the default values of the tool (Sledgehammer in this case).*)
       
    42 fun available_parameter args key label list =
       
    43   let
       
    44     val value = AList.lookup (op =) args key
       
    45   in if is_some value then (label, the value) :: list else list end
       
    46 
    35 
    47 
    36 datatype sh_data = ShData of {
    48 datatype sh_data = ShData of {
    37   calls: int,
    49   calls: int,
    38   success: int,
    50   success: int,
    39   nontriv_calls: int,
    51   nontriv_calls: int,
   363   SH_FAIL of int * int |
   375   SH_FAIL of int * int |
   364   SH_ERROR
   376   SH_ERROR
   365 
   377 
   366 fun run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   378 fun run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   367         uncurried_aliases e_weight_method force_sos hard_timeout timeout
   379         uncurried_aliases e_weight_method force_sos hard_timeout timeout
   368         preplay_timeout sh_minimize dir pos st =
   380         preplay_timeout sh_minimizeLST max_new_mono_instancesLST max_mono_itersLST
       
   381         dir pos st =
   369   let
   382   let
   370     val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
   383     val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
   371     val i = 1
   384     val i = 1
   372     fun set_file_name (SOME dir) =
   385     fun set_file_name (SOME dir) =
   373         Config.put Sledgehammer_Provers.dest_dir dir
   386         Config.put Sledgehammer_Provers.dest_dir dir
   384                        e_weight_method |> the_default I)
   397                        e_weight_method |> the_default I)
   385                  #> (Option.map (Config.put ATP_Systems.force_sos)
   398                  #> (Option.map (Config.put ATP_Systems.force_sos)
   386                        force_sos |> the_default I))
   399                        force_sos |> the_default I))
   387     val params as {relevance_thresholds, max_relevant, slice, ...} =
   400     val params as {relevance_thresholds, max_relevant, slice, ...} =
   388       Sledgehammer_Isar.default_params ctxt
   401       Sledgehammer_Isar.default_params ctxt
   389           [("verbose", "true"),
   402          ([("verbose", "true"),
   390            ("type_enc", type_enc),
   403            ("type_enc", type_enc),
   391            ("strict", strict),
   404            ("strict", strict),
   392            ("lam_trans", lam_trans |> the_default "smart"),
   405            ("lam_trans", lam_trans |> the_default "smart"),
   393            ("uncurried_aliases", uncurried_aliases |> the_default "smart"),
   406            ("uncurried_aliases", uncurried_aliases |> the_default "smart"),
   394            ("max_relevant", max_relevant),
   407            ("max_relevant", max_relevant),
   395            ("slice", slice),
   408            ("slice", slice),
   396            ("timeout", string_of_int timeout),
   409            ("timeout", string_of_int timeout),
   397            ("minimize", sh_minimize), (*don't confuse the two minimization flags*)
       
   398            ("preplay_timeout", preplay_timeout)]
   410            ("preplay_timeout", preplay_timeout)]
       
   411           |> sh_minimizeLST (*don't confuse the two minimization flags*)
       
   412           |> max_new_mono_instancesLST
       
   413           |> max_mono_itersLST)
   399     val default_max_relevant =
   414     val default_max_relevant =
   400       Sledgehammer_Provers.default_max_relevant_for_prover ctxt slice
   415       Sledgehammer_Provers.default_max_relevant_for_prover ctxt slice
   401         prover_name
   416         prover_name
   402     val is_appropriate_prop =
   417     val is_appropriate_prop =
   403       Sledgehammer_Provers.is_appropriate_prop_for_prover ctxt prover_name
   418       Sledgehammer_Provers.is_appropriate_prop_for_prover ctxt prover_name
   483     val timeout = Mirabelle.get_int_setting args (prover_timeoutK, 30)
   498     val timeout = Mirabelle.get_int_setting args (prover_timeoutK, 30)
   484     (* always use a hard timeout, but give some slack so that the automatic
   499     (* always use a hard timeout, but give some slack so that the automatic
   485        minimizer has a chance to do its magic *)
   500        minimizer has a chance to do its magic *)
   486     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
   501     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
   487       |> the_default preplay_timeout_default
   502       |> the_default preplay_timeout_default
   488     val sh_minimize = AList.lookup (op =) args sh_minimizeK |> the_default "smart"
   503     val sh_minimizeLST = available_parameter args sh_minimizeK "minimize"
       
   504     val max_new_mono_instancesLST =
       
   505       available_parameter args max_new_mono_instancesK max_new_mono_instancesK
       
   506     val max_mono_itersLST = available_parameter args max_mono_itersK max_mono_itersK
   489     val hard_timeout = SOME (2 * timeout)
   507     val hard_timeout = SOME (2 * timeout)
   490     val (msg, result) =
   508     val (msg, result) =
   491       run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   509       run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   492         uncurried_aliases e_weight_method force_sos hard_timeout timeout
   510         uncurried_aliases e_weight_method force_sos hard_timeout timeout
   493         preplay_timeout sh_minimize dir pos st
   511         preplay_timeout sh_minimizeLST max_new_mono_instancesLST max_mono_itersLST
       
   512         dir pos st
   494   in
   513   in
   495     case result of
   514     case result of
   496       SH_OK (time_isa, time_prover, names) =>
   515       SH_OK (time_isa, time_prover, names) =>
   497         let
   516         let
   498           fun get_thms (name, stature) =
   517           fun get_thms (name, stature) =
   531       AList.lookup (op =) args minimize_timeoutK
   550       AList.lookup (op =) args minimize_timeoutK
   532       |> Option.map (fst o read_int o raw_explode)  (* FIXME Symbol.explode (?) *)
   551       |> Option.map (fst o read_int o raw_explode)  (* FIXME Symbol.explode (?) *)
   533       |> the_default 5
   552       |> the_default 5
   534     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
   553     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
   535       |> the_default preplay_timeout_default
   554       |> the_default preplay_timeout_default
   536     val sh_minimize = AList.lookup (op =) args sh_minimizeK |> the_default "smart"
   555     val sh_minimizeLST = available_parameter args sh_minimizeK "minimize"
       
   556     val max_new_mono_instancesLST =
       
   557       available_parameter args max_new_mono_instancesK max_new_mono_instancesK
       
   558     val max_mono_itersLST = available_parameter args max_mono_itersK max_mono_itersK
   537     val params = Sledgehammer_Isar.default_params ctxt
   559     val params = Sledgehammer_Isar.default_params ctxt
   538       [("provers", prover_name),
   560      ([("provers", prover_name),
   539        ("verbose", "true"),
   561        ("verbose", "true"),
   540        ("type_enc", type_enc),
   562        ("type_enc", type_enc),
   541        ("strict", strict),
   563        ("strict", strict),
   542        ("timeout", string_of_int timeout),
   564        ("timeout", string_of_int timeout),
   543        ("preplay_timeout", preplay_timeout),
   565        ("preplay_timeout", preplay_timeout)]
   544        ("minimize", sh_minimize)] (*don't confuse the two minimization flags*)
   566       |> sh_minimizeLST (*don't confuse the two minimization flags*)
       
   567       |> max_new_mono_instancesLST
       
   568       |> max_mono_itersLST)
   545     val minimize =
   569     val minimize =
   546       Sledgehammer_Minimize.minimize_facts prover_name params
   570       Sledgehammer_Minimize.minimize_facts prover_name params
   547           true 1 (Sledgehammer_Util.subgoal_count st)
   571           true 1 (Sledgehammer_Util.subgoal_count st)
   548     val _ = log separator
   572     val _ = log separator
   549     val (used_facts, (preplay, message, message_tail)) =
   573     val (used_facts, (preplay, message, message_tail)) =