src/HOL/Tools/Sledgehammer/sledgehammer.ML
changeset 57774 d2ad1320c770
parent 57755 e081db351356
child 57776 1111a9a328fe
equal deleted inserted replaced
57773:2719eb9d40fe 57774:d2ad1320c770
    18   val someN : string
    18   val someN : string
    19   val noneN : string
    19   val noneN : string
    20   val timeoutN : string
    20   val timeoutN : string
    21   val unknownN : string
    21   val unknownN : string
    22 
    22 
    23   val play_one_line_proof : Time.time -> (string * 'a) list -> Proof.state -> int ->
    23   val play_one_line_proof : bool -> Time.time -> (string * 'a) list -> Proof.state -> int ->
    24     proof_method * proof_method list list -> (string * 'a) list * (proof_method * play_outcome)
    24     proof_method * proof_method list list -> (string * 'a) list * (proof_method * play_outcome)
    25   val string_of_factss : (string * fact list) list -> string
    25   val string_of_factss : (string * fact list) list -> string
    26   val run_sledgehammer : params -> mode -> (string -> unit) option -> int -> fact_override ->
    26   val run_sledgehammer : params -> mode -> (string -> unit) option -> int -> fact_override ->
    27     Proof.state -> bool * (string * Proof.state)
    27     Proof.state -> bool * (string * Proof.state)
    28 end;
    28 end;
    61 
    61 
    62 fun prover_description verbose name num_facts =
    62 fun prover_description verbose name num_facts =
    63   (quote name,
    63   (quote name,
    64    if verbose then " with " ^ string_of_int num_facts ^ " fact" ^ plural_s num_facts else "")
    64    if verbose then " with " ^ string_of_int num_facts ^ " fact" ^ plural_s num_facts else "")
    65 
    65 
    66 fun play_one_line_proof timeout used_facts state i (preferred, methss as (meth :: _) :: _) =
    66 fun is_metis_method (Metis_Method _) = true
       
    67   | is_metis_method _ = false
       
    68 
       
    69 fun play_one_line_proof minimize timeout used_facts state i
       
    70     (preferred, methss as (meth :: _) :: _) =
    67   let
    71   let
    68     fun dont_know () =
    72     fun dont_know () =
    69       (used_facts,
    73       (used_facts,
    70        (if exists (fn meths => member (op =) meths preferred) methss then preferred else meth,
    74        (if exists (fn meths => member (op =) meths preferred) methss then preferred else meth,
    71         Play_Timed_Out Time.zeroTime))
    75         Play_Timed_Out Time.zeroTime))
    85             let
    89             let
    86               fun mk_step fact_names meths =
    90               fun mk_step fact_names meths =
    87                 Prove ([], [], ("", 0), goal_t, [], ([], fact_names), meths, "")
    91                 Prove ([], [], ("", 0), goal_t, [], ([], fact_names), meths, "")
    88             in
    92             in
    89               (case preplay_isar_step ctxt timeout [] (mk_step fact_names meths) of
    93               (case preplay_isar_step ctxt timeout [] (mk_step fact_names meths) of
    90                 (res as (Metis_Method _, Played _)) :: _ =>
    94                 (res as (meth, Played time)) :: _ =>
    91                 (used_facts, res) (* if a fact is needed by an ATP, it will be needed by "metis" *)
    95                 (* if a fact is needed by an ATP, it will be needed by "metis" *)
    92               | (meth, Played time) :: _ =>
    96                 if not minimize orelse is_metis_method meth then
    93                 let
    97                   (used_facts, res)
    94                   val (time', used_names') =
    98                 else
    95                     minimized_isar_step ctxt time (mk_step fact_names [meth])
    99                   let
    96                     ||> (facts_of_isar_step #> snd)
   100                     val (time', used_names') =
    97                   val used_facts' = filter (member (op =) used_names' o fst) used_facts
   101                       minimized_isar_step ctxt time (mk_step fact_names [meth])
    98                 in
   102                       ||> (facts_of_isar_step #> snd)
    99                   (used_facts', (meth, Played time'))
   103                     val used_facts' = filter (member (op =) used_names' o fst) used_facts
   100                 end
   104                   in
       
   105                     (used_facts', (meth, Played time'))
       
   106                   end
   101               | _ => try_methss methss)
   107               | _ => try_methss methss)
   102             end
   108             end
   103       in
   109       in
   104         try_methss methss
   110         try_methss methss
   105       end
   111       end
   106   end
   112   end
   107 
   113 
   108 fun launch_prover (params as {debug, verbose, spy, blocking, max_facts, timeout, preplay_timeout,
   114 fun launch_prover (params as {debug, verbose, spy, blocking, max_facts, minimize, timeout,
   109       expect, ...}) mode output_result only learn
   115       preplay_timeout, expect, ...}) mode output_result only learn
   110     {comment, state, goal, subgoal, subgoal_count, factss as (_, facts) :: _} name =
   116     {comment, state, goal, subgoal, subgoal_count, factss as (_, facts) :: _} name =
   111   let
   117   let
   112     val ctxt = Proof.context_of state
   118     val ctxt = Proof.context_of state
   113 
   119 
   114     val hard_timeout = time_mult 3.0 timeout
   120     val hard_timeout = time_mult 3.0 timeout
   177       |> spy ? tap (fn res => spying spy (fn () => (state, subgoal, name, spying_str_of_res res)))
   183       |> spy ? tap (fn res => spying spy (fn () => (state, subgoal, name, spying_str_of_res res)))
   178       |> (fn {outcome, used_facts, preferred_methss, message, ...} =>
   184       |> (fn {outcome, used_facts, preferred_methss, message, ...} =>
   179         (if outcome = SOME ATP_Proof.TimedOut then timeoutN
   185         (if outcome = SOME ATP_Proof.TimedOut then timeoutN
   180          else if is_some outcome then noneN
   186          else if is_some outcome then noneN
   181          else someN,
   187          else someN,
   182          fn () => message (fn () => play_one_line_proof preplay_timeout used_facts state subgoal
   188          fn () => message (fn () => play_one_line_proof minimize preplay_timeout used_facts state
   183            preferred_methss)))
   189            subgoal preferred_methss)))
   184 
   190 
   185     fun go () =
   191     fun go () =
   186       let
   192       let
   187         val (outcome_code, message) =
   193         val (outcome_code, message) =
   188           if debug then
   194           if debug then