src/HOL/Tools/Sledgehammer/sledgehammer_minimize.ML
changeset 41335 66edbd0f7a2e
parent 41277 1369c27c6966
child 41491 a2ad5b824051
equal deleted inserted replaced
41334:3cb52cbf0eed 41335:66edbd0f7a2e
     8 signature SLEDGEHAMMER_MINIMIZE =
     8 signature SLEDGEHAMMER_MINIMIZE =
     9 sig
     9 sig
    10   type locality = Sledgehammer_Filter.locality
    10   type locality = Sledgehammer_Filter.locality
    11   type params = Sledgehammer_Provers.params
    11   type params = Sledgehammer_Provers.params
    12 
    12 
    13   val binary_threshold : int Unsynchronized.ref
    13   val binary_min_facts : int Unsynchronized.ref
    14   val filter_used_facts : ''a list -> (''a * 'b) list -> (''a * 'b) list
    14   val filter_used_facts : ''a list -> (''a * 'b) list -> (''a * 'b) list
    15   val minimize_facts :
    15   val minimize_facts :
    16     string -> params -> bool -> int -> int -> Proof.state
    16     string -> params -> bool -> int -> int -> Proof.state
    17     -> ((string * locality) * thm list) list
    17     -> ((string * locality) * thm list) list
    18     -> ((string * locality) * thm list) list option * string
    18     -> ((string * locality) * thm list) list option * string
    84 (* The sublinear algorithm works well in almost all situations, except when the
    84 (* The sublinear algorithm works well in almost all situations, except when the
    85    external prover cannot return the list of used facts and hence returns all
    85    external prover cannot return the list of used facts and hence returns all
    86    facts as used. In that case, the binary algorithm is much more appropriate.
    86    facts as used. In that case, the binary algorithm is much more appropriate.
    87    We can usually detect the situation by looking at the number of used facts
    87    We can usually detect the situation by looking at the number of used facts
    88    reported by the prover. *)
    88    reported by the prover. *)
    89 val binary_threshold = Unsynchronized.ref 20
    89 val binary_min_facts = Unsynchronized.ref 20
    90 
    90 
    91 fun filter_used_facts used = filter (member (op =) used o fst)
    91 fun filter_used_facts used = filter (member (op =) used o fst)
    92 
    92 
    93 fun sublinear_minimize _ [] p = p
    93 fun sublinear_minimize _ [] p = p
    94   | sublinear_minimize test (x :: xs) (seen, result) =
    94   | sublinear_minimize test (x :: xs) (seen, result) =
   154          val new_timeout =
   154          val new_timeout =
   155            Int.min (msecs, Time.toMilliseconds time + slack_msecs)
   155            Int.min (msecs, Time.toMilliseconds time + slack_msecs)
   156            |> Time.fromMilliseconds
   156            |> Time.fromMilliseconds
   157          val facts = filter_used_facts used_facts facts
   157          val facts = filter_used_facts used_facts facts
   158          val (min_thms, {message, ...}) =
   158          val (min_thms, {message, ...}) =
   159            if length facts >= !binary_threshold then
   159            if length facts >= !binary_min_facts then
   160              binary_minimize (do_test new_timeout) facts
   160              binary_minimize (do_test new_timeout) facts
   161            else
   161            else
   162              sublinear_minimize (do_test new_timeout) facts ([], result)
   162              sublinear_minimize (do_test new_timeout) facts ([], result)
   163          val n = length min_thms
   163          val n = length min_thms
   164          val _ = print silent (fn () => cat_lines
   164          val _ = print silent (fn () => cat_lines