src/HOL/Mirabelle/Tools/mirabelle_sledgehammer.ML
changeset 46825 98300d5f9cc0
parent 46641 8801a24f9e9a
child 46826 4c80c4034f1d
equal deleted inserted replaced
46824:1257c80988cd 46825:98300d5f9cc0
    15 val uncurried_aliasesK = "uncurried_aliases"
    15 val uncurried_aliasesK = "uncurried_aliases"
    16 val e_weight_methodK = "e_weight_method"
    16 val e_weight_methodK = "e_weight_method"
    17 val force_sosK = "force_sos"
    17 val force_sosK = "force_sos"
    18 val max_relevantK = "max_relevant"
    18 val max_relevantK = "max_relevant"
    19 val max_callsK = "max_calls"
    19 val max_callsK = "max_calls"
    20 val minimizeK = "minimize"
    20 val minimizeK = "minimize" (*refers to minimization attempted by Mirabelle*)
    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 
    24 val preplay_timeoutK = "preplay_timeout"
    25 val preplay_timeout = "4"
    25 val sh_minimizeK = "sh_minimize" (*refers to minimizer run within Sledgehammer*)
    26 
    26 
    27 fun sh_tag id = "#" ^ string_of_int id ^ " sledgehammer: "
    27 fun sh_tag id = "#" ^ string_of_int id ^ " sledgehammer: "
    28 fun minimize_tag id = "#" ^ string_of_int id ^ " minimize (sledgehammer): "
    28 fun minimize_tag id = "#" ^ string_of_int id ^ " minimize (sledgehammer): "
    29 fun reconstructor_tag reconstructor id =
    29 fun reconstructor_tag reconstructor id =
    30   "#" ^ string_of_int id ^ " " ^ (!reconstructor) ^ " (sledgehammer): "
    30   "#" ^ string_of_int id ^ " " ^ (!reconstructor) ^ " (sledgehammer): "
    31 
    31 
    32 val separator = "-----"
    32 val separator = "-----"
    33 
    33 
       
    34 val preplay_timeout_default = "4"
    34 
    35 
    35 datatype sh_data = ShData of {
    36 datatype sh_data = ShData of {
    36   calls: int,
    37   calls: int,
    37   success: int,
    38   success: int,
    38   nontriv_calls: int,
    39   nontriv_calls: int,
   361   SH_OK of int * int * (string * stature) list |
   362   SH_OK of int * int * (string * stature) list |
   362   SH_FAIL of int * int |
   363   SH_FAIL of int * int |
   363   SH_ERROR
   364   SH_ERROR
   364 
   365 
   365 fun run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   366 fun run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   366         uncurried_aliases e_weight_method force_sos hard_timeout timeout dir pos
   367         uncurried_aliases e_weight_method force_sos hard_timeout timeout
   367         st =
   368         preplay_timeout sh_minimize dir pos st =
   368   let
   369   let
   369     val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
   370     val {context = ctxt, facts = chained_ths, goal} = Proof.goal st
   370     val i = 1
   371     val i = 1
   371     fun set_file_name (SOME dir) =
   372     fun set_file_name (SOME dir) =
   372         Config.put Sledgehammer_Provers.dest_dir dir
   373         Config.put Sledgehammer_Provers.dest_dir dir
   391            ("lam_trans", lam_trans |> the_default "smart"),
   392            ("lam_trans", lam_trans |> the_default "smart"),
   392            ("uncurried_aliases", uncurried_aliases |> the_default "smart"),
   393            ("uncurried_aliases", uncurried_aliases |> the_default "smart"),
   393            ("max_relevant", max_relevant),
   394            ("max_relevant", max_relevant),
   394            ("slice", slice),
   395            ("slice", slice),
   395            ("timeout", string_of_int timeout),
   396            ("timeout", string_of_int timeout),
       
   397            ("minimize", sh_minimize), (*don't confuse the two minimization flags*)
   396            ("preplay_timeout", preplay_timeout)]
   398            ("preplay_timeout", preplay_timeout)]
   397     val default_max_relevant =
   399     val default_max_relevant =
   398       Sledgehammer_Provers.default_max_relevant_for_prover ctxt slice
   400       Sledgehammer_Provers.default_max_relevant_for_prover ctxt slice
   399         prover_name
   401         prover_name
   400     val is_appropriate_prop =
   402     val is_appropriate_prop =
   479       |> Option.map (curry (op <>) "false")
   481       |> Option.map (curry (op <>) "false")
   480     val dir = AList.lookup (op =) args keepK
   482     val dir = AList.lookup (op =) args keepK
   481     val timeout = Mirabelle.get_int_setting args (prover_timeoutK, 30)
   483     val timeout = Mirabelle.get_int_setting args (prover_timeoutK, 30)
   482     (* always use a hard timeout, but give some slack so that the automatic
   484     (* always use a hard timeout, but give some slack so that the automatic
   483        minimizer has a chance to do its magic *)
   485        minimizer has a chance to do its magic *)
       
   486     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
       
   487       |> the_default preplay_timeout_default
       
   488     val sh_minimize = AList.lookup (op =) args sh_minimizeK |> the_default "smart"
   484     val hard_timeout = SOME (2 * timeout)
   489     val hard_timeout = SOME (2 * timeout)
   485     val (msg, result) =
   490     val (msg, result) =
   486       run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   491       run_sh prover_name prover type_enc strict max_relevant slice lam_trans
   487         uncurried_aliases e_weight_method force_sos hard_timeout timeout dir pos
   492         uncurried_aliases e_weight_method force_sos hard_timeout timeout
   488         st
   493         preplay_timeout sh_minimize dir pos st
   489   in
   494   in
   490     case result of
   495     case result of
   491       SH_OK (time_isa, time_prover, names) =>
   496       SH_OK (time_isa, time_prover, names) =>
   492         let
   497         let
   493           fun get_thms (name, stature) =
   498           fun get_thms (name, stature) =
   524     val strict = AList.lookup (op =) args strictK |> the_default "false"
   529     val strict = AList.lookup (op =) args strictK |> the_default "false"
   525     val timeout =
   530     val timeout =
   526       AList.lookup (op =) args minimize_timeoutK
   531       AList.lookup (op =) args minimize_timeoutK
   527       |> Option.map (fst o read_int o raw_explode)  (* FIXME Symbol.explode (?) *)
   532       |> Option.map (fst o read_int o raw_explode)  (* FIXME Symbol.explode (?) *)
   528       |> the_default 5
   533       |> the_default 5
       
   534     val preplay_timeout = AList.lookup (op =) args preplay_timeoutK
       
   535       |> the_default preplay_timeout_default
       
   536     val sh_minimize = AList.lookup (op =) args sh_minimizeK |> the_default "smart"
   529     val params = Sledgehammer_Isar.default_params ctxt
   537     val params = Sledgehammer_Isar.default_params ctxt
   530       [("provers", prover_name),
   538       [("provers", prover_name),
   531        ("verbose", "true"),
   539        ("verbose", "true"),
   532        ("type_enc", type_enc),
   540        ("type_enc", type_enc),
   533        ("strict", strict),
   541        ("strict", strict),
   534        ("timeout", string_of_int timeout),
   542        ("timeout", string_of_int timeout),
   535        ("preplay_timeout", preplay_timeout)]
   543        ("preplay_timeout", preplay_timeout),
       
   544        ("minimize", sh_minimize)] (*don't confuse the two minimization flags*)
   536     val minimize =
   545     val minimize =
   537       Sledgehammer_Minimize.minimize_facts prover_name params
   546       Sledgehammer_Minimize.minimize_facts prover_name params
   538           true 1 (Sledgehammer_Util.subgoal_count st)
   547           true 1 (Sledgehammer_Util.subgoal_count st)
   539     val _ = log separator
   548     val _ = log separator
   540     val (used_facts, (preplay, message, message_tail)) =
   549     val (used_facts, (preplay, message, message_tail)) =