src/HOL/Tools/Sledgehammer/sledgehammer_prover_minimize.ML
changeset 57721 e4858f85e616
parent 57673 858c1a63967f
child 57723 668322cd58f4
equal deleted inserted replaced
57720:9df2757f5bec 57721:e4858f85e616
    18   val is_prover_installed : Proof.context -> string -> bool
    18   val is_prover_installed : Proof.context -> string -> bool
    19   val default_max_facts_of_prover : Proof.context -> string -> int
    19   val default_max_facts_of_prover : Proof.context -> string -> int
    20   val get_prover : Proof.context -> mode -> string -> prover
    20   val get_prover : Proof.context -> mode -> string -> prover
    21 
    21 
    22   val binary_min_facts : int Config.T
    22   val binary_min_facts : int Config.T
    23   val auto_minimize_min_facts : int Config.T
       
    24   val auto_minimize_max_time : real Config.T
       
    25   val minimize_facts : (thm list -> unit) -> string -> params -> bool -> int -> int ->
    23   val minimize_facts : (thm list -> unit) -> string -> params -> bool -> int -> int ->
    26     Proof.state -> thm -> (proof_method * play_outcome) Lazy.lazy option ->
    24     Proof.state -> thm -> (proof_method * play_outcome) Lazy.lazy option ->
    27     ((string * stature) * thm list) list ->
    25     ((string * stature) * thm list) list ->
    28     ((string * stature) * thm list) list option
    26     ((string * stature) * thm list) list option
    29       * ((proof_method * play_outcome) Lazy.lazy * ((proof_method * play_outcome) -> string)
    27       * ((proof_method * play_outcome) Lazy.lazy * ((proof_method * play_outcome) -> string)
   178    appropriate for provers that cannot return the list of used facts and hence
   176    appropriate for provers that cannot return the list of used facts and hence
   179    returns all facts as used. Since we cannot know in advance how many facts are
   177    returns all facts as used. Since we cannot know in advance how many facts are
   180    actually needed, we heuristically set the threshold to 10 facts. *)
   178    actually needed, we heuristically set the threshold to 10 facts. *)
   181 val binary_min_facts =
   179 val binary_min_facts =
   182   Attrib.setup_config_int @{binding sledgehammer_minimize_binary_min_facts} (K 20)
   180   Attrib.setup_config_int @{binding sledgehammer_minimize_binary_min_facts} (K 20)
   183 val auto_minimize_min_facts =
       
   184   Attrib.setup_config_int @{binding sledgehammer_auto_minimize_min_facts}
       
   185       (fn generic => Config.get_generic generic binary_min_facts)
       
   186 val auto_minimize_max_time =
       
   187   Attrib.setup_config_real @{binding sledgehammer_auto_minimize_max_time} (K 5.0)
       
   188 
   181 
   189 fun linear_minimize test timeout result xs =
   182 fun linear_minimize test timeout result xs =
   190   let
   183   let
   191     fun min _ [] p = p
   184     fun min _ [] p = p
   192       | min timeout (x :: xs) (seen, result) =
   185       | min timeout (x :: xs) (seen, result) =
   315   if is_some outcome orelse null used_facts then
   308   if is_some outcome orelse null used_facts then
   316     result
   309     result
   317   else
   310   else
   318     let
   311     let
   319       val thy = Proof_Context.theory_of ctxt
   312       val thy = Proof_Context.theory_of ctxt
   320       val num_facts = length used_facts
   313 
   321 
   314       val (minimize_name, params) =
   322       val ((perhaps_minimize, (minimize_name, params)), preplay) =
       
   323         if mode = Normal then
   315         if mode = Normal then
   324           if num_facts >= Config.get ctxt auto_minimize_min_facts then
   316           (case Lazy.force preplay of
   325             ((true, (name, params)), preplay)
   317             (meth as Metis_Method _, Played _) =>
   326           else
   318             if isar_proofs = SOME true then
   327             let
   319               (* Cheat: Assume the selected ATP is as fast as "metis" for the goal it proved
   328               fun can_min_fast_enough time =
   320                  itself. *)
   329                 0.001
   321               (isar_supported_prover_of thy name, params)
   330                 * Real.fromInt ((num_facts + 1) * Time.toMilliseconds time)
   322             else
   331                 <= Config.get ctxt auto_minimize_max_time
   323               extract_proof_method params meth
   332               fun prover_fast_enough () = can_min_fast_enough run_time
   324               ||> (fn override_params => adjust_proof_method_params override_params params)
   333             in
   325           | _ => (name, params))
   334               (case Lazy.force preplay of
       
   335                  (meth as Metis_Method _, Played timeout) =>
       
   336                  if isar_proofs = SOME true then
       
   337                    (* Cheat: Assume the selected ATP is as fast as "metis" for the goal it proved
       
   338                       itself. *)
       
   339                    (can_min_fast_enough timeout, (isar_supported_prover_of thy name, params))
       
   340                  else if can_min_fast_enough timeout then
       
   341                    (true, extract_proof_method params meth
       
   342                           ||> (fn override_params =>
       
   343                                   adjust_proof_method_params override_params params))
       
   344                  else
       
   345                    (prover_fast_enough (), (name, params))
       
   346                | (SMT2_Method, Played timeout) =>
       
   347                  (* Cheat: Assume the original prover is as fast as "smt" for the goal it proved
       
   348                     itself. *)
       
   349                  (can_min_fast_enough timeout, (name, params))
       
   350                | _ => (prover_fast_enough (), (name, params)),
       
   351                preplay)
       
   352             end
       
   353         else
   326         else
   354           ((false, (name, params)), preplay)
   327           (name, params)
   355       val minimize = minimize |> the_default perhaps_minimize
   328 
   356       val (used_facts, (preplay, message, _)) =
   329       val (used_facts, (preplay, message, _)) =
   357         if minimize then
   330         if minimize then
   358           minimize_facts do_learn minimize_name params
   331           minimize_facts do_learn minimize_name params
   359             (not verbose orelse (mode <> Normal andalso mode <> MaSh)) subgoal subgoal_count state
   332             (not verbose orelse (mode <> Normal andalso mode <> MaSh)) subgoal subgoal_count state
   360             goal (SOME preplay) (filter_used_facts true used_facts (map (apsnd single) used_from))
   333             goal (SOME preplay) (filter_used_facts true used_facts (map (apsnd single) used_from))