src/HOL/ex/sledgehammer_tactics.ML
author blanchet
Tue Aug 23 18:42:05 2011 +0200 (2011-08-23)
changeset 44429 e5506cfe1b5a
parent 44390 99ef9fd7341b
child 44462 d9a657c44380
permissions -rw-r--r--
clean up Sledgehammer tactic
blanchet@42071
     1
(*  Title:      HOL/ex/sledgehammer_tactics.ML
bulwahn@40633
     2
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@42071
     3
    Copyright   2010, 2011
bulwahn@40633
     4
bulwahn@40633
     5
Sledgehammer as a tactic.
bulwahn@40633
     6
*)
bulwahn@40633
     7
bulwahn@40633
     8
signature SLEDGEHAMMER_TACTICS =
bulwahn@40633
     9
sig
blanchet@44429
    10
  val sledgehammer_with_metis_tac :
blanchet@44429
    11
    Proof.context -> (string * string) list -> int -> tactic
blanchet@44429
    12
  val sledgehammer_as_oracle_tac :
blanchet@44429
    13
    Proof.context -> (string * string) list -> int -> tactic
bulwahn@40633
    14
end;
bulwahn@40633
    15
bulwahn@40633
    16
structure Sledgehammer_Tactics : SLEDGEHAMMER_TACTICS =
bulwahn@40633
    17
struct
blanchet@42071
    18
blanchet@44429
    19
fun run_atp override_params i n ctxt goal =
bulwahn@40633
    20
  let
bulwahn@40921
    21
    val chained_ths = [] (* a tactic has no chained ths *)
blanchet@44429
    22
    val params as {provers, relevance_thresholds, max_relevant, slicing, ...} =
blanchet@44429
    23
      Sledgehammer_Isar.default_params ctxt override_params
blanchet@44429
    24
    val name = hd provers
blanchet@43021
    25
    val prover =
blanchet@43021
    26
      Sledgehammer_Provers.get_prover ctxt Sledgehammer_Provers.Normal name
bulwahn@40921
    27
    val default_max_relevant =
blanchet@42443
    28
      Sledgehammer_Provers.default_max_relevant_for_prover ctxt slicing name
bulwahn@40921
    29
    val is_built_in_const =
blanchet@41087
    30
      Sledgehammer_Provers.is_built_in_const_for_prover ctxt name
blanchet@41087
    31
    val relevance_fudge =
blanchet@41087
    32
      Sledgehammer_Provers.relevance_fudge_for_prover ctxt name
bulwahn@40921
    33
    val relevance_override = {add = [], del = [], only = false}
blanchet@43088
    34
    val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal i
bulwahn@40921
    35
    val facts =
blanchet@43351
    36
      Sledgehammer_Filter.nearly_all_facts ctxt relevance_override chained_ths
blanchet@43351
    37
                                           hyp_ts concl_t
blanchet@43351
    38
      |> Sledgehammer_Filter.relevant_facts ctxt relevance_thresholds
blanchet@43351
    39
             (the_default default_max_relevant max_relevant) is_built_in_const
blanchet@43351
    40
             relevance_fudge relevance_override chained_ths hyp_ts concl_t
bulwahn@40633
    41
    val problem =
blanchet@41090
    42
      {state = Proof.init ctxt, goal = goal, subgoal = i, subgoal_count = n,
blanchet@41243
    43
       facts = map Sledgehammer_Provers.Untranslated_Fact facts,
blanchet@41741
    44
       smt_filter = NONE}
bulwahn@40633
    45
  in
blanchet@43051
    46
    (case prover params (K (K "")) problem of
bulwahn@40921
    47
      {outcome = NONE, used_facts, ...} => used_facts |> map fst |> SOME
bulwahn@40921
    48
    | _ => NONE)
bulwahn@40921
    49
      handle ERROR message => (warning ("Error: " ^ message ^ "\n"); NONE)
bulwahn@40633
    50
  end
bulwahn@40633
    51
bulwahn@40633
    52
fun thms_of_name ctxt name =
bulwahn@40633
    53
  let
bulwahn@40633
    54
    val lex = Keyword.get_lexicons
wenzelm@42361
    55
    val get = maps (Proof_Context.get_fact ctxt o fst)
bulwahn@40633
    56
  in
bulwahn@40633
    57
    Source.of_string name
bulwahn@40635
    58
    |> Symbol.source
bulwahn@40633
    59
    |> Token.source {do_recover=SOME false} lex Position.start
bulwahn@40633
    60
    |> Token.source_proper
bulwahn@40633
    61
    |> Source.source Token.stopper (Parse_Spec.xthms1 >> get) NONE
bulwahn@40633
    62
    |> Source.exhaust
bulwahn@40633
    63
  end
bulwahn@40633
    64
blanchet@44429
    65
fun sledgehammer_with_metis_tac ctxt override_params i th =
blanchet@44429
    66
  case run_atp override_params i i ctxt th of
blanchet@44429
    67
    SOME facts =>
blanchet@44429
    68
    Metis_Tactics.metis_tac [] ctxt (maps (thms_of_name ctxt) facts) i th
blanchet@44429
    69
  | NONE => Seq.empty
bulwahn@40633
    70
blanchet@44429
    71
fun sledgehammer_as_oracle_tac ctxt override_params i th =
bulwahn@40633
    72
  let
wenzelm@42361
    73
    val thy = Proof_Context.theory_of ctxt
blanchet@44429
    74
    val xs = run_atp (override_params @ [("sound", "true")]) i i ctxt th
blanchet@41357
    75
  in if is_some xs then Skip_Proof.cheat_tac thy th else Seq.empty end
blanchet@41357
    76
bulwahn@40633
    77
end;