src/HOL/ex/sledgehammer_tactics.ML
author blanchet
Mon, 02 May 2011 22:52:15 +0200
changeset 42638 a7a30721767a
parent 42589 9f7c48463645
child 42642 f5b4b9d4acda
permissions -rw-r--r--
have each ATP filter out dangerous facts for themselves, based on their type system
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42071
04577a7e0c51 move "TPTP" wrapper and "Sledgehammer as a tactic" to "HOL/ex"
blanchet
parents: 41959
diff changeset
     1
(*  Title:      HOL/ex/sledgehammer_tactics.ML
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
42071
04577a7e0c51 move "TPTP" wrapper and "Sledgehammer as a tactic" to "HOL/ex"
blanchet
parents: 41959
diff changeset
     3
    Copyright   2010, 2011
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     4
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     5
Sledgehammer as a tactic.
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     6
*)
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     7
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     8
signature SLEDGEHAMMER_TACTICS =
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
     9
sig
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    10
  val sledgehammer_with_metis_tac : Proof.context -> int -> tactic
41357
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    11
  val sledgehammer_as_unsound_oracle_tac : Proof.context -> int -> tactic
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    12
  val sledgehammer_as_oracle_tac : Proof.context -> int -> tactic
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    13
end;
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    14
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    15
structure Sledgehammer_Tactics : SLEDGEHAMMER_TACTICS =
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    16
struct
42071
04577a7e0c51 move "TPTP" wrapper and "Sledgehammer as a tactic" to "HOL/ex"
blanchet
parents: 41959
diff changeset
    17
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    18
fun run_atp force_full_types timeout i n ctxt goal name =
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    19
  let
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    20
    val chained_ths = [] (* a tactic has no chained ths *)
42443
724e612ba248 implemented general slicing for ATPs, especially E 1.2w and above
blanchet
parents: 42361
diff changeset
    21
    val params as {type_sys, relevance_thresholds, max_relevant, slicing, ...} =
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    22
      ((if force_full_types then [("full_types", "true")] else [])
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 41358
diff changeset
    23
       @ [("timeout", string_of_int (Time.toSeconds timeout))])
41357
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    24
       (* @ [("overlord", "true")] *)
40635
47004929bc71 ported sledgehammer_tactic to current development version
bulwahn
parents: 40633
diff changeset
    25
      |> Sledgehammer_Isar.default_params ctxt
42444
8e5438dc70bb cleanup: get rid of "may_slice" arguments without changing semantics
blanchet
parents: 42443
diff changeset
    26
    val prover = Sledgehammer_Provers.get_prover ctxt false name
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    27
    val default_max_relevant =
42443
724e612ba248 implemented general slicing for ATPs, especially E 1.2w and above
blanchet
parents: 42361
diff changeset
    28
      Sledgehammer_Provers.default_max_relevant_for_prover ctxt slicing name
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    29
    val is_built_in_const =
41087
d7b5fd465198 split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents: 40983
diff changeset
    30
      Sledgehammer_Provers.is_built_in_const_for_prover ctxt name
d7b5fd465198 split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents: 40983
diff changeset
    31
    val relevance_fudge =
d7b5fd465198 split "Sledgehammer" module into two parts, to resolve forthcoming dependency problems
blanchet
parents: 40983
diff changeset
    32
      Sledgehammer_Provers.relevance_fudge_for_prover ctxt name
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    33
    val relevance_override = {add = [], del = [], only = false}
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    34
    val (_, hyp_ts, concl_t) = Sledgehammer_Util.strip_subgoal goal i
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    35
    val facts =
42638
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
    36
      Sledgehammer_Filter.relevant_facts ctxt relevance_thresholds
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    37
          (the_default default_max_relevant max_relevant) is_built_in_const
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    38
          relevance_fudge relevance_override chained_ths hyp_ts concl_t
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    39
    val problem =
41090
b98fe4de1ecd renamings
blanchet
parents: 41087
diff changeset
    40
      {state = Proof.init ctxt, goal = goal, subgoal = i, subgoal_count = n,
41243
15ba335d0ba2 compile
blanchet
parents: 41138
diff changeset
    41
       facts = map Sledgehammer_Provers.Untranslated_Fact facts,
41741
839d1488045f renamed field
blanchet
parents: 41491
diff changeset
    42
       smt_filter = NONE}
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    43
  in
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    44
    (case prover params (K "") problem of
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    45
      {outcome = NONE, used_facts, ...} => used_facts |> map fst |> SOME
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    46
    | _ => NONE)
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    47
      handle ERROR message => (warning ("Error: " ^ message ^ "\n"); NONE)
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    48
  end
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    49
42071
04577a7e0c51 move "TPTP" wrapper and "Sledgehammer as a tactic" to "HOL/ex"
blanchet
parents: 41959
diff changeset
    50
val atp = "e" (* or "vampire" or "spass" etc. *)
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    51
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    52
fun thms_of_name ctxt name =
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    53
  let
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    54
    val lex = Keyword.get_lexicons
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42106
diff changeset
    55
    val get = maps (Proof_Context.get_fact ctxt o fst)
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    56
  in
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    57
    Source.of_string name
40635
47004929bc71 ported sledgehammer_tactic to current development version
bulwahn
parents: 40633
diff changeset
    58
    |> Symbol.source
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    59
    |> Token.source {do_recover=SOME false} lex Position.start
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    60
    |> Token.source_proper
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    61
    |> Source.source Token.stopper (Parse_Spec.xthms1 >> get) NONE
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    62
    |> Source.exhaust
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    63
  end
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    64
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    65
fun sledgehammer_with_metis_tac ctxt i th =
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    66
  let
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    67
    val timeout = Time.fromSeconds 30
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    68
  in
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    69
    case run_atp false timeout i i ctxt th atp of
41357
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    70
      SOME facts =>
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    71
      Metis_Tactics.metis_tac ctxt (maps (thms_of_name ctxt) facts) i th
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    72
    | NONE => Seq.empty
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    73
  end
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    74
41357
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    75
fun generic_sledgehammer_as_oracle_tac force_full_types ctxt i th =
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    76
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42106
diff changeset
    77
    val thy = Proof_Context.theory_of ctxt
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    78
    val timeout = Time.fromSeconds 30
41357
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    79
    val xs = run_atp force_full_types timeout i i ctxt th atp
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    80
  in if is_some xs then Skip_Proof.cheat_tac thy th else Seq.empty end
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    81
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    82
val sledgehammer_as_unsound_oracle_tac =
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    83
  generic_sledgehammer_as_oracle_tac false
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    84
val sledgehammer_as_oracle_tac = generic_sledgehammer_as_oracle_tac true
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    85
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    86
end;