delayed construction of command (and of noncommercial check) + tuning
authorblanchet
Fri Mar 14 12:09:51 2014 +0100 (2014-03-14 ago)
changeset 5613264eeda68e693
parent 56131 836b47c6531d
child 56133 304e37faf1ac
child 56148 d94d6a9178b5
child 56152 2a31945b9a58
delayed construction of command (and of noncommercial check) + tuning
src/HOL/Tools/SMT2/smt2_solver.ML
src/HOL/Tools/Sledgehammer/sledgehammer_prover.ML
src/HOL/Tools/Sledgehammer/sledgehammer_prover_smt2.ML
     1.1 --- a/src/HOL/Tools/SMT2/smt2_solver.ML	Fri Mar 14 11:52:03 2014 +0100
     1.2 +++ b/src/HOL/Tools/SMT2/smt2_solver.ML	Fri Mar 14 12:09:51 2014 +0100
     1.3 @@ -24,8 +24,6 @@
     1.4  
     1.5    (*registry*)
     1.6    val add_solver: solver_config -> theory -> theory
     1.7 -  val solver_name_of: Proof.context -> string
     1.8 -  val available_solvers_of: Proof.context -> string list
     1.9    val default_max_relevant: Proof.context -> string -> int
    1.10  
    1.11    (*filter*)
    1.12 @@ -47,11 +45,12 @@
    1.13  
    1.14  local
    1.15  
    1.16 -fun make_cmd command options problem_path proof_path = space_implode " " (
    1.17 -  "(exec 2>&1;" :: map File.shell_quote (command @ options) @
    1.18 -  [File.shell_path problem_path, ")", ">", File.shell_path proof_path])
    1.19 +fun make_command command options problem_path proof_path =
    1.20 +  "(exec 2>&1;" :: map File.shell_quote (command () @ options) @
    1.21 +  [File.shell_path problem_path, ")", ">", File.shell_path proof_path]
    1.22 +  |> space_implode " "
    1.23  
    1.24 -fun trace_and ctxt msg f x =
    1.25 +fun with_trace ctxt msg f x =
    1.26    let val _ = SMT2_Config.trace_msg ctxt (fn () => msg) ()
    1.27    in f x end
    1.28  
    1.29 @@ -61,7 +60,7 @@
    1.30        if not (SMT2_Config.is_available ctxt name) then
    1.31          error ("The SMT solver " ^ quote name ^ " is not installed")
    1.32        else if Config.get ctxt SMT2_Config.debug_files = "" then
    1.33 -        trace_and ctxt ("Invoking SMT solver " ^ quote name ^ " ...") (Cache_IO.run mk_cmd) input
    1.34 +        with_trace ctxt ("Invoking SMT solver " ^ quote name ^ " ...") (Cache_IO.run mk_cmd) input
    1.35        else
    1.36          let
    1.37            val base_path = Path.explode (Config.get ctxt SMT2_Config.debug_files)
    1.38 @@ -76,9 +75,8 @@
    1.39            else
    1.40              Cache_IO.run_and_cache certs key mk_cmd input
    1.41        | (SOME output, _) =>
    1.42 -          trace_and ctxt ("Using cached certificate from " ^
    1.43 -            File.shell_path (Cache_IO.cache_path_of certs) ^ " ...")
    1.44 -            I output))
    1.45 +          with_trace ctxt ("Using cached certificate from " ^
    1.46 +            File.shell_path (Cache_IO.cache_path_of certs) ^ " ...") I output))
    1.47  
    1.48  (* Z3 returns 1 if "get-model" or "get-model" fails *)
    1.49  val normal_return_codes = [0, 1]
    1.50 @@ -89,7 +87,7 @@
    1.51  
    1.52      val _ = SMT2_Config.trace_msg ctxt (pretty "Problem:" o split_lines) input
    1.53  
    1.54 -    val {redirected_output=res, output=err, return_code} =
    1.55 +    val {redirected_output = res, output = err, return_code} =
    1.56        SMT2_Config.with_timeout ctxt (run ctxt name mk_cmd) input
    1.57      val _ = SMT2_Config.trace_msg ctxt (pretty "Solver:") err
    1.58  
    1.59 @@ -104,7 +102,7 @@
    1.60    SMT2_Config.trace_msg ctxt (Pretty.string_of o
    1.61      Pretty.big_list "Assertions:" o map (Display.pretty_thm ctxt o snd))
    1.62  
    1.63 -fun trace_replay_data ({context=ctxt, typs, terms, ...} : SMT2_Translate.replay_data) =
    1.64 +fun trace_replay_data ({context = ctxt, typs, terms, ...} : SMT2_Translate.replay_data) =
    1.65    let
    1.66      fun pretty_eq n p = Pretty.block [Pretty.str n, Pretty.str " = ", p]
    1.67      fun p_typ (n, T) = pretty_eq n (Syntax.pretty_typ ctxt T)
    1.68 @@ -121,15 +119,14 @@
    1.69  fun invoke name command ithms ctxt =
    1.70    let
    1.71      val options = SMT2_Config.solver_options_of ctxt
    1.72 -    val cmd = command ()
    1.73      val comments = [space_implode " " options]
    1.74  
    1.75 -    val (str, replay_data as {context=ctxt', ...}) =
    1.76 +    val (str, replay_data as {context = ctxt', ...}) =
    1.77        ithms
    1.78        |> tap (trace_assms ctxt)
    1.79        |> SMT2_Translate.translate ctxt comments
    1.80        ||> tap trace_replay_data
    1.81 -  in (run_solver ctxt' name (make_cmd cmd options) str, replay_data) end
    1.82 +  in (run_solver ctxt' name (make_command command options) str, replay_data) end
    1.83  
    1.84  end
    1.85  
    1.86 @@ -184,16 +181,14 @@
    1.87  
    1.88  local
    1.89    fun finish outcome cex_parser replay ocl outer_ctxt
    1.90 -      (replay_data as {context=ctxt, ...} : SMT2_Translate.replay_data) output =
    1.91 +      (replay_data as {context = ctxt, ...} : SMT2_Translate.replay_data) output =
    1.92      (case outcome output of
    1.93        (Unsat, ls) =>
    1.94          if not (Config.get ctxt SMT2_Config.oracle) andalso is_some replay
    1.95          then the replay outer_ctxt replay_data ls
    1.96          else (([], []), ocl ())
    1.97      | (result, ls) =>
    1.98 -        let
    1.99 -          val (ts, us) =
   1.100 -            (case cex_parser of SOME f => f ctxt replay_data ls | _ => ([], []))
   1.101 +        let val (ts, us) = (case cex_parser of SOME f => f ctxt replay_data ls | _ => ([], []))
   1.102          in
   1.103            raise SMT2_Failure.SMT (SMT2_Failure.Counterexample {
   1.104              is_real_cex = (result = Sat),
   1.105 @@ -213,7 +208,7 @@
   1.106        can_filter = can_filter,
   1.107        finish = finish (outcome name) cex_parser replay ocl}
   1.108  
   1.109 -    val info = {name=name, class=class, avail=avail, options=options}
   1.110 +    val info = {name = name, class = class, avail = avail, options = options}
   1.111    in
   1.112      Thm.add_oracle (Binding.name name, K cfalse) #-> (fn (_, ocl) =>
   1.113      Context.theory_map (Solvers.map (Symtab.update_new (name, solver ocl)))) #>
   1.114 @@ -224,12 +219,8 @@
   1.115  
   1.116  fun get_info ctxt name = the (Symtab.lookup (Solvers.get (Context.Proof ctxt)) name)
   1.117  
   1.118 -val solver_name_of = SMT2_Config.solver_of
   1.119 -
   1.120 -val available_solvers_of = SMT2_Config.available_solvers_of
   1.121 -
   1.122  fun name_and_info_of ctxt =
   1.123 -  let val name = solver_name_of ctxt
   1.124 +  let val name = SMT2_Config.solver_of ctxt
   1.125    in (name, get_info ctxt name) end
   1.126  
   1.127  fun apply_solver ctxt wthms0 =
   1.128 @@ -255,7 +246,7 @@
   1.129        |> Config.put SMT2_Config.filter_only_facts true
   1.130        |> Config.put SMT2_Config.timeout (Time.toReal time_limit)
   1.131  
   1.132 -    val ({context=ctxt, prems, concl, ...}, _) = Subgoal.focus ctxt i goal
   1.133 +    val ({context = ctxt, prems, concl, ...}, _) = Subgoal.focus ctxt i goal
   1.134      fun negate ct = Thm.dest_comb ct ||> Thm.apply @{cterm Not} |-> Thm.apply
   1.135      val cprop =
   1.136        (case try negate (Thm.rhs_of (SMT2_Normalize.atomize_conv ctxt concl)) of
   1.137 @@ -309,8 +300,7 @@
   1.138      |> snd
   1.139  
   1.140    fun str_of ctxt fail =
   1.141 -    SMT2_Failure.string_of_failure ctxt fail
   1.142 -    |> prefix ("Solver " ^ SMT2_Config.solver_of ctxt ^ ": ")
   1.143 +    "Solver " ^ SMT2_Config.solver_of ctxt ^ ": " ^ SMT2_Failure.string_of_failure ctxt fail
   1.144  
   1.145    fun safe_solve ctxt wfacts = SOME (solve ctxt wfacts)
   1.146      handle
     2.1 --- a/src/HOL/Tools/Sledgehammer/sledgehammer_prover.ML	Fri Mar 14 11:52:03 2014 +0100
     2.2 +++ b/src/HOL/Tools/Sledgehammer/sledgehammer_prover.ML	Fri Mar 14 12:09:51 2014 +0100
     2.3 @@ -281,7 +281,7 @@
     2.4        proof_method_names @
     2.5        sort_strings (supported_atps thy) @
     2.6        sort_strings (SMT_Solver.available_solvers_of ctxt) @
     2.7 -      sort_strings (SMT2_Solver.available_solvers_of ctxt)
     2.8 +      sort_strings (SMT2_Config.available_solvers_of ctxt)
     2.9        |> List.partition (String.isPrefix remote_prefix)
    2.10    in
    2.11      Output.urgent_message ("Supported provers: " ^
     3.1 --- a/src/HOL/Tools/Sledgehammer/sledgehammer_prover_smt2.ML	Fri Mar 14 11:52:03 2014 +0100
     3.2 +++ b/src/HOL/Tools/Sledgehammer/sledgehammer_prover_smt2.ML	Fri Mar 14 12:09:51 2014 +0100
     3.3 @@ -48,7 +48,7 @@
     3.4  val smt2_weight_min_facts =
     3.5    Attrib.setup_config_int @{binding sledgehammer_smt2_weight_min_facts} (K 20)
     3.6  
     3.7 -fun is_smt2_prover ctxt = member (op =) (SMT2_Solver.available_solvers_of ctxt)
     3.8 +val is_smt2_prover = member (op =) o SMT2_Config.available_solvers_of
     3.9  
    3.10  (* FUDGE *)
    3.11  val smt2_min_weight = Attrib.setup_config_int @{binding sledgehammer_smt2_min_weight} (K 0)