src/HOL/TPTP/sledgehammer_tactics.ML
author haftmann
Fri, 15 Feb 2013 08:31:31 +0100
changeset 51143 0a2371e7ced3
parent 51010 afd0213a3dab
child 51552 c713c9505f68
permissions -rw-r--r--
two target language numeral types: integer and natural, as replacement for code_numeral; former theory HOL/Library/Code_Numeral_Types replaces HOL/Code_Numeral; refined stack of theories implementing int and/or nat by target language numerals; reduced number of target language numeral types to exactly one
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47790
2e1636e45770 move file to where it belongs
blanchet
parents: 47773
diff changeset
     1
(*  Title:      HOL/TPTP/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
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    10
  type fact_override = Sledgehammer_Fact.fact_override
44462
d9a657c44380 more reliable "sledgehammer\_tac" reconstruction, by avoiding "insert_tac"
blanchet
parents: 44429
diff changeset
    11
44429
e5506cfe1b5a clean up Sledgehammer tactic
blanchet
parents: 44390
diff changeset
    12
  val sledgehammer_with_metis_tac :
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    13
    Proof.context -> (string * string) list -> fact_override -> int -> tactic
44429
e5506cfe1b5a clean up Sledgehammer tactic
blanchet
parents: 44390
diff changeset
    14
  val sledgehammer_as_oracle_tac :
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    15
    Proof.context -> (string * string) list -> fact_override -> int -> tactic
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    16
end;
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    17
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    18
structure Sledgehammer_Tactics : SLEDGEHAMMER_TACTICS =
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    19
struct
42071
04577a7e0c51 move "TPTP" wrapper and "Sledgehammer as a tactic" to "HOL/ex"
blanchet
parents: 41959
diff changeset
    20
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    21
open Sledgehammer_Util
48287
61acb731b4a2 killed one file
blanchet
parents: 48250
diff changeset
    22
open Sledgehammer_Fact
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    23
open Sledgehammer_Provers
48381
1b7d798460bb renamed ML structures
blanchet
parents: 48299
diff changeset
    24
open Sledgehammer_MaSh
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    25
open Sledgehammer_Isar
44462
d9a657c44380 more reliable "sledgehammer\_tac" reconstruction, by avoiding "insert_tac"
blanchet
parents: 44429
diff changeset
    26
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    27
fun run_prover override_params fact_override i n ctxt goal =
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    28
  let
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    29
    val mode = Normal
48293
914ca0827804 renamed Sledgehammer options
blanchet
parents: 48292
diff changeset
    30
    val params as {provers, max_facts, slice, ...} =
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    31
      default_params ctxt override_params
44429
e5506cfe1b5a clean up Sledgehammer tactic
blanchet
parents: 44390
diff changeset
    32
    val name = hd provers
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    33
    val prover = get_prover ctxt mode name
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    34
    val default_max_facts = default_max_facts_for_prover ctxt slice name
43088
0a97f3295642 compile
blanchet
parents: 43051
diff changeset
    35
    val (_, hyp_ts, concl_t) = ATP_Util.strip_subgoal ctxt goal i
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    36
    val ho_atp = exists (is_ho_atp ctxt) provers
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    37
    val reserved = reserved_isar_keyword_table ()
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    38
    val css_table = clasimpset_rule_table_of ctxt
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    39
    val facts =
48299
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    40
      nearly_all_facts ctxt ho_atp fact_override reserved css_table [] hyp_ts
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    41
                       concl_t
5e5c6616f0fe centrally construct expensive data structures
blanchet
parents: 48293
diff changeset
    42
      |> relevant_facts ctxt params name
48293
914ca0827804 renamed Sledgehammer options
blanchet
parents: 48292
diff changeset
    43
             (the_default default_max_facts max_facts) fact_override hyp_ts
914ca0827804 renamed Sledgehammer options
blanchet
parents: 48292
diff changeset
    44
             concl_t
51010
afd0213a3dab tuned data structure
blanchet
parents: 51007
diff changeset
    45
      |> hd |> snd
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    46
    val problem =
41090
b98fe4de1ecd renamings
blanchet
parents: 41087
diff changeset
    47
      {state = Proof.init ctxt, goal = goal, subgoal = i, subgoal_count = n,
51010
afd0213a3dab tuned data structure
blanchet
parents: 51007
diff changeset
    48
       factss = [("", facts)]}
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    49
  in
45520
2b1dde0b1c30 thread in additional options to minimizer
blanchet
parents: 45514
diff changeset
    50
    (case prover params (K (K (K ""))) problem of
40921
a516fbdd9931 improving sledgehammer_tactic and adding relevance filtering to the tactic
bulwahn
parents: 40635
diff changeset
    51
      {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
    52
    | _ => NONE)
51010
afd0213a3dab tuned data structure
blanchet
parents: 51007
diff changeset
    53
    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
    54
  end
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    55
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    56
fun sledgehammer_with_metis_tac ctxt override_params fact_override i th =
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    57
  let val override_params = override_params @ [("preplay_timeout", "0")] in
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    58
    case run_prover override_params fact_override i i ctxt th of
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    59
      SOME facts =>
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    60
      Metis_Tactic.metis_tac [] ATP_Problem_Generate.combs_or_liftingN ctxt
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    61
          (maps (thms_of_name ctxt) facts) i th
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    62
    | NONE => Seq.empty
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    63
  end
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    64
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    65
fun sledgehammer_as_oracle_tac ctxt override_params fact_override i th =
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    66
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42106
diff changeset
    67
    val thy = Proof_Context.theory_of ctxt
47766
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    68
    val override_params =
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    69
      override_params @
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    70
      [("preplay_timeout", "0"),
9f7cdd5fff7c more work on TPTP Isabelle and Sledgehammer tactics
blanchet
parents: 47532
diff changeset
    71
       ("minimize", "false")]
48292
7fcee834c7f5 more code rationalization in relevance filter
blanchet
parents: 48289
diff changeset
    72
    val xs = run_prover override_params fact_override i i ctxt th
41357
ae76960d86a2 added "sledgehammer_tac" as possible reconstructor in Mirabelle
blanchet
parents: 41243
diff changeset
    73
  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
    74
40633
6cd611ceb64e adding files to use sledgehammer as a tactic for non-interactive use
bulwahn
parents:
diff changeset
    75
end;