src/HOL/Tools/Sledgehammer/sledgehammer_prover.ML
changeset 57723 668322cd58f4
parent 57721 e4858f85e616
child 57724 9ea51eddf81c
equal deleted inserted replaced
57722:2c2d5b7f29aa 57723:668322cd58f4
    76   val is_atp : theory -> string -> bool
    76   val is_atp : theory -> string -> bool
    77   val bunch_of_proof_methods : bool -> bool -> string -> proof_method list
    77   val bunch_of_proof_methods : bool -> bool -> string -> proof_method list
    78   val is_fact_chained : (('a * stature) * 'b) -> bool
    78   val is_fact_chained : (('a * stature) * 'b) -> bool
    79   val filter_used_facts : bool -> (''a * stature) list -> ((''a * stature) * 'b) list ->
    79   val filter_used_facts : bool -> (''a * stature) list -> ((''a * stature) * 'b) list ->
    80     ((''a * stature) * 'b) list
    80     ((''a * stature) * 'b) list
    81   val play_one_line_proof : mode -> bool -> Time.time -> ((string * 'a) * thm) list ->
    81   val play_one_line_proof : mode -> Time.time -> ((string * 'a) * thm) list -> Proof.state -> int ->
    82     Proof.state -> int -> proof_method -> proof_method list -> proof_method * play_outcome
    82     proof_method -> proof_method list -> proof_method * play_outcome
    83   val isar_supported_prover_of : theory -> string -> string
    83   val isar_supported_prover_of : theory -> string -> string
    84   val choose_minimize_command : theory -> params -> ((string * string list) list -> string -> 'a) ->
    84   val choose_minimize_command : theory -> params -> ((string * string list) list -> string -> 'a) ->
    85     string -> proof_method * play_outcome -> 'a
    85     string -> proof_method * play_outcome -> 'a
    86   val repair_monomorph_context : int option -> int -> int option -> int -> Proof.context ->
    86   val repair_monomorph_context : int option -> int -> int option -> int -> Proof.context ->
    87     Proof.context
    87     Proof.context
   102 open ATP_Problem_Generate
   102 open ATP_Problem_Generate
   103 open ATP_Proof_Reconstruct
   103 open ATP_Proof_Reconstruct
   104 open Metis_Tactic
   104 open Metis_Tactic
   105 open Sledgehammer_Fact
   105 open Sledgehammer_Fact
   106 open Sledgehammer_Proof_Methods
   106 open Sledgehammer_Proof_Methods
       
   107 open Sledgehammer_Isar_Proof
       
   108 open Sledgehammer_Isar_Preplay
   107 
   109 
   108 (* Identifier that distinguishes Sledgehammer from other tools that could use
   110 (* Identifier that distinguishes Sledgehammer from other tools that could use
   109    "Async_Manager". *)
   111    "Async_Manager". *)
   110 val SledgehammerN = "Sledgehammer"
   112 val SledgehammerN = "Sledgehammer"
   111 
   113 
   204         (if is_none lam_trans' andalso is_none lam_trans then []
   206         (if is_none lam_trans' andalso is_none lam_trans then []
   205          else [("lam_trans", [lam_trans' |> the_default default_metis_lam_trans])])
   207          else [("lam_trans", [lam_trans' |> the_default default_metis_lam_trans])])
   206     in (metisN, override_params) end
   208     in (metisN, override_params) end
   207   | extract_proof_method _ SMT2_Method = (smtN, [])
   209   | extract_proof_method _ SMT2_Method = (smtN, [])
   208 
   210 
   209 (* based on "Mirabelle.can_apply" and generalized *)
   211 fun preplay_methods timeout facts meths state i =
   210 fun timed_apply timeout tac state i =
   212   let
   211   let
   213     val {context = ctxt, facts = chained, goal} = Proof.goal state
   212     val {context = ctxt, facts, goal} = Proof.goal state
   214     val (_, hyp_ts, concl_t) = strip_subgoal goal i ctxt
   213     val full_tac = Method.insert_tac facts i THEN tac ctxt i
   215     val step =
       
   216       Prove ([], [], ("", 0), Logic.list_implies (map prop_of chained @ hyp_ts, concl_t), [],
       
   217         ([], facts), meths, "")
   214   in
   218   in
   215     TimeLimit.timeLimit timeout (try (Seq.pull o full_tac)) goal
   219     preplay_isar_step ctxt timeout [] step
   216   end
   220   end
   217 
       
   218 fun timed_proof_method timeout ths meth =
       
   219   timed_apply timeout (fn ctxt => tac_of_proof_method ctxt ([], ths) meth)
       
   220 
   221 
   221 fun is_fact_chained ((_, (sc, _)), _) = sc = Chained
   222 fun is_fact_chained ((_, (sc, _)), _) = sc = Chained
   222 
   223 
   223 fun filter_used_facts keep_chained used =
   224 fun filter_used_facts keep_chained used =
   224   filter ((member (op =) used o fst) orf (if keep_chained then is_fact_chained else K false))
   225   filter ((member (op =) used o fst) orf (if keep_chained then is_fact_chained else K false))
   225 
   226 
   226 fun play_one_line_proof mode verbose timeout pairs state i preferred (meths as meth :: _) =
   227 fun play_one_line_proof mode timeout used_facts state i preferred (meths as meth :: _) =
   227   let
   228   let
   228     val ctxt = Proof.context_of state
   229     fun dont_know () =
   229 
   230       (if member (op =) meths preferred then preferred else meth, Play_Timed_Out Time.zeroTime)
   230     fun get_preferred meths = if member (op =) meths preferred then preferred else meth
       
   231   in
   231   in
   232     if timeout = Time.zeroTime then
   232     if timeout = Time.zeroTime then
   233       (get_preferred meths, Play_Timed_Out Time.zeroTime)
   233       dont_know ()
   234     else
   234     else
   235       let
   235       let
   236         val _ = if mode = Minimize then Output.urgent_message "Preplaying proof..." else ()
   236         val _ = if mode = Minimize then Output.urgent_message "Preplaying proof..." else ()
   237         val ths = pairs |> sort_wrt (fst o fst) |> map snd
   237         val gfs = used_facts |> map (fst o fst) |> sort string_ord
   238 
       
   239         fun play [] [] = (get_preferred meths, Play_Failed)
       
   240           | play timed_outs [] = (get_preferred timed_outs, Play_Timed_Out timeout)
       
   241           | play timed_out (meth :: meths) =
       
   242             let val timer = Timer.startRealTimer () in
       
   243               (case timed_proof_method timeout ths meth state i of
       
   244                 SOME (SOME _) => (meth, Played (Timer.checkRealTimer timer))
       
   245               | _ => play timed_out meths)
       
   246             end
       
   247             handle TimeLimit.TimeOut => play (meth :: timed_out) meths
       
   248       in
   238       in
   249         play [] meths
   239         (case preplay_methods timeout gfs meths state i of
       
   240           res :: _ => res
       
   241         | [] => dont_know ())
   250       end
   242       end
   251   end
   243   end
   252 
   244 
   253 val canonical_isar_supported_prover = eN
   245 val canonical_isar_supported_prover = eN
   254 val z3N = "z3"
   246 val z3N = "z3"