src/HOL/Tools/Sledgehammer/sledgehammer_isar.ML
author wenzelm
Mon, 17 May 2010 23:54:15 +0200
changeset 36960 01594f816e3a
parent 36924 ff01d3ae9ad4
child 37171 fc1e20373e6a
permissions -rw-r--r--
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax; eliminated old-style structure aliases K = Keyword, P = Parse;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36375
2482446a604c move the minimizer to the Sledgehammer directory
blanchet
parents: 36373
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_isar.ML
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     3
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     4
Adds "sledgehammer" and related commands to Isabelle/Isar's outer syntax.
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     5
*)
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
     6
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
     7
signature SLEDGEHAMMER_ISAR =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
     8
sig
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
     9
  type params = ATP_Manager.params
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    10
36371
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    11
  val atps: string Unsynchronized.ref
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    12
  val timeout: int Unsynchronized.ref
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    13
  val full_types: bool Unsynchronized.ref
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    14
  val default_params : theory -> (string * string) list -> params
36394
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    15
  val setup: theory -> theory
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    16
end;
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    17
35971
4f24a4e9af4a make Mirabelle happy again
blanchet
parents: 35970
diff changeset
    18
structure Sledgehammer_Isar : SLEDGEHAMMER_ISAR =
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    19
struct
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    20
35971
4f24a4e9af4a make Mirabelle happy again
blanchet
parents: 35970
diff changeset
    21
open Sledgehammer_Util
36394
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    22
open Sledgehammer_Fact_Preprocessor
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    23
open ATP_Manager
36376
e83d52a52449 renamed module "ATP_Wrapper" to "ATP_Systems"
blanchet
parents: 36375
diff changeset
    24
open ATP_Systems
36375
2482446a604c move the minimizer to the Sledgehammer directory
blanchet
parents: 36373
diff changeset
    25
open Sledgehammer_Fact_Minimizer
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
    26
36394
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    27
(** Proof method used in Isar proofs **)
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    28
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    29
val neg_clausify_setup =
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    30
  Method.setup @{binding neg_clausify}
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    31
               (Scan.succeed (SIMPLE_METHOD' o neg_clausify_tac))
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    32
               "conversion of goal to negated conjecture clauses"
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    33
36395
e73923451f6f cosmetics
blanchet
parents: 36394
diff changeset
    34
(** Attribute for converting a theorem into clauses **)
e73923451f6f cosmetics
blanchet
parents: 36394
diff changeset
    35
36607
e5f7235f39c5 made sml/nj happy about Sledgehammer and Nitpick (cf. 6f11c9b1fb3e, 3c2438efe224)
krauss
parents: 36488
diff changeset
    36
val parse_clausify_attribute : attribute context_parser =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
    37
  Scan.lift Parse.nat
36394
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    38
  >> (fn i => Thm.rule_attribute (fn context => fn th =>
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    39
                  let val thy = Context.theory_of context in
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    40
                    Meson.make_meta_clause (nth (cnf_axiom thy th) i)
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    41
                  end))
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    42
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    43
val clausify_setup =
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    44
  Attrib.setup @{binding clausify} parse_clausify_attribute
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    45
               "conversion of theorem to clauses"
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    46
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    47
(** Sledgehammer commands **)
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
    48
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    49
fun add_to_relevance_override ns : relevance_override =
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    50
  {add = ns, del = [], only = false}
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    51
fun del_from_relevance_override ns : relevance_override =
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    52
  {add = [], del = ns, only = false}
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    53
fun only_relevance_override ns : relevance_override =
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    54
  {add = ns, del = [], only = true}
36188
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
    55
val no_relevance_override = add_to_relevance_override []
36003
eb44a5d40b9e make SML/NJ happy
blanchet
parents: 35971
diff changeset
    56
fun merge_relevance_override_pairwise (r1 : relevance_override)
eb44a5d40b9e make SML/NJ happy
blanchet
parents: 35971
diff changeset
    57
                                      (r2 : relevance_override) =
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    58
  {add = #add r1 @ #add r2, del = #del r1 @ #del r2,
36183
f723348b2231 Sledgehammer: the empty set of fact () should mean nothing, not unchanged
blanchet
parents: 36143
diff changeset
    59
   only = #only r1 andalso #only r2}
36188
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
    60
fun merge_relevance_overrides rs =
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
    61
  fold merge_relevance_override_pairwise rs (only_relevance_override [])
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
    62
36371
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    63
(*** parameters ***)
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    64
36908
fb18db78be80 delect installed ATPs dynamically, _not_ at image built time
blanchet
parents: 36607
diff changeset
    65
val atps = Unsynchronized.ref ""
36371
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    66
val timeout = Unsynchronized.ref 60
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    67
val full_types = Unsynchronized.ref false
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    68
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    69
val _ =
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    70
  ProofGeneralPgip.add_preference Preferences.category_proof
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    71
      (Preferences.string_pref atps
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    72
          "Sledgehammer: ATPs"
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    73
          "Default automatic provers (separated by whitespace)")
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    74
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    75
val _ =
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    76
  ProofGeneralPgip.add_preference Preferences.category_proof
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    77
      (Preferences.int_pref timeout
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
    78
          "Sledgehammer: Time Limit"
36371
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    79
          "ATPs will be interrupted after this time (in seconds)")
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    80
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    81
val _ =
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    82
  ProofGeneralPgip.add_preference Preferences.category_proof
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    83
      (Preferences.bool_pref full_types
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
    84
          "Sledgehammer: Full Types" "ATPs will use full type information")
36371
8c83ea1a7740 move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents: 36290
diff changeset
    85
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    86
type raw_param = string * string list
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    87
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    88
val default_default_params =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    89
  [("debug", "false"),
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    90
   ("verbose", "false"),
36143
6490319b1703 added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents: 36142
diff changeset
    91
   ("overlord", "false"),
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36223
diff changeset
    92
   ("explicit_apply", "false"),
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 36003
diff changeset
    93
   ("respect_no_atp", "true"),
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
    94
   ("relevance_threshold", "50"),
36922
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
    95
   ("relevance_convergence", "320"),
36220
f3655a3ae1ab rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents: 36189
diff changeset
    96
   ("theory_relevant", "smart"),
36922
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
    97
   ("defs_relevant", "false"),
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
    98
   ("isar_proof", "false"),
36924
ff01d3ae9ad4 renamed options
blanchet
parents: 36922
diff changeset
    99
   ("isar_shrink_factor", "1"),
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   100
   ("minimize_timeout", "5 s")]
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   101
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   102
val alias_params =
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   103
  [("atp", "atps")]
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   104
val negated_alias_params =
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   105
  [("no_debug", "debug"),
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   106
   ("quiet", "verbose"),
36143
6490319b1703 added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents: 36142
diff changeset
   107
   ("no_overlord", "overlord"),
36399
f2d83794333c rename options
blanchet
parents: 36395
diff changeset
   108
   ("partial_types", "full_types"),
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36223
diff changeset
   109
   ("implicit_apply", "explicit_apply"),
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 36003
diff changeset
   110
   ("ignore_no_atp", "respect_no_atp"),
36220
f3655a3ae1ab rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents: 36189
diff changeset
   111
   ("theory_irrelevant", "theory_relevant"),
36922
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
   112
   ("defs_irrelevant", "defs_relevant"),
36908
fb18db78be80 delect installed ATPs dynamically, _not_ at image built time
blanchet
parents: 36607
diff changeset
   113
   ("no_isar_proof", "isar_proof")]
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   114
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   115
val params_for_minimize =
36399
f2d83794333c rename options
blanchet
parents: 36395
diff changeset
   116
  ["debug", "verbose", "overlord", "full_types", "explicit_apply",
36924
ff01d3ae9ad4 renamed options
blanchet
parents: 36922
diff changeset
   117
   "isar_proof", "isar_shrink_factor", "minimize_timeout"]
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   118
35971
4f24a4e9af4a make Mirabelle happy again
blanchet
parents: 35970
diff changeset
   119
val property_dependent_params = ["atps", "full_types", "timeout"]
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   120
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   121
fun is_known_raw_param s =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   122
  AList.defined (op =) default_default_params s orelse
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   123
  AList.defined (op =) alias_params s orelse
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   124
  AList.defined (op =) negated_alias_params s orelse
35971
4f24a4e9af4a make Mirabelle happy again
blanchet
parents: 35970
diff changeset
   125
  member (op =) property_dependent_params s
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   126
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   127
fun check_raw_param (s, _) =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   128
  if is_known_raw_param s then ()
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   129
  else error ("Unknown parameter: " ^ quote s ^ ".")
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   130
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   131
fun unalias_raw_param (name, value) =
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   132
  case AList.lookup (op =) alias_params name of
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   133
    SOME name' => (name', value)
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   134
  | NONE =>
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   135
    case AList.lookup (op =) negated_alias_params name of
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   136
      SOME name' => (name', case value of
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   137
                              ["false"] => ["true"]
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   138
                            | ["true"] => ["false"]
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   139
                            | [] => ["false"]
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   140
                            | _ => value)
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   141
    | NONE => (name, value)
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   142
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   143
structure Data = Theory_Data(
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   144
  type T = raw_param list
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   145
  val empty = default_default_params |> map (apsnd single)
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   146
  val extend = I
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   147
  fun merge p : T = AList.merge (op =) (K true) p)
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   148
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   149
val set_default_raw_param = Data.map o AList.update (op =) o unalias_raw_param
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   150
fun default_raw_params thy =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   151
  Data.get thy
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   152
  |> fold (AList.default (op =))
36908
fb18db78be80 delect installed ATPs dynamically, _not_ at image built time
blanchet
parents: 36607
diff changeset
   153
          [("atps", [case !atps of "" => default_atps_param_value () | s => s]),
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   154
           ("full_types", [if !full_types then "true" else "false"]),
36142
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36141
diff changeset
   155
           ("timeout", let val timeout = !timeout in
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36141
diff changeset
   156
                         [if timeout <= 0 then "none"
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36141
diff changeset
   157
                          else string_of_int timeout ^ " s"]
f5e15e9aae10 make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents: 36141
diff changeset
   158
                       end)]
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   159
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   160
val infinity_time_in_secs = 60 * 60 * 24 * 365
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   161
val the_timeout = the_default (Time.fromSeconds infinity_time_in_secs)
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   162
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   163
fun extract_params thy default_params override_params =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   164
  let
36140
08b2a7ecb6c3 fixed handling of "sledgehammer_params" that get a default value from Isabelle menu;
blanchet
parents: 36064
diff changeset
   165
    val override_params = map unalias_raw_param override_params
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   166
    val raw_params = rev override_params @ rev default_params
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   167
    val lookup = Option.map (space_implode " ") o AList.lookup (op =) raw_params
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   168
    val lookup_string = the_default "" o lookup
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   169
    fun general_lookup_bool option default_value name =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   170
      case lookup name of
35970
3d41a2a490f0 revert debugging output that shouldn't have been submitted in the first place
blanchet
parents: 35966
diff changeset
   171
        SOME s => parse_bool_option option name s
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   172
      | NONE => default_value
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   173
    val lookup_bool = the o general_lookup_bool false (SOME false)
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   174
    val lookup_bool_option = general_lookup_bool true NONE
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   175
    fun lookup_time name =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   176
      the_timeout (case lookup name of
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   177
                     NONE => NONE
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   178
                   | SOME s => parse_time_option name s)
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   179
    fun lookup_int name =
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   180
      case lookup name of
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   181
        NONE => 0
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   182
      | SOME s => case Int.fromString s of
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   183
                    SOME n => n
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   184
                  | NONE => error ("Parameter " ^ quote name ^
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   185
                                   " must be assigned an integer value.")
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   186
    val debug = lookup_bool "debug"
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   187
    val verbose = debug orelse lookup_bool "verbose"
36143
6490319b1703 added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents: 36142
diff changeset
   188
    val overlord = lookup_bool "overlord"
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   189
    val atps = lookup_string "atps" |> space_explode " "
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   190
    val full_types = lookup_bool "full_types"
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36223
diff changeset
   191
    val explicit_apply = lookup_bool "explicit_apply"
36058
8256d5a185bd added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents: 36003
diff changeset
   192
    val respect_no_atp = lookup_bool "respect_no_atp"
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   193
    val relevance_threshold =
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   194
      0.01 * Real.fromInt (lookup_int "relevance_threshold")
36922
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
   195
    val relevance_convergence =
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
   196
      0.01 * Real.fromInt (lookup_int "relevance_convergence")
36220
f3655a3ae1ab rename Sledgehammer "theory_const" option to "theory_relevant", now that I understand better what it does
blanchet
parents: 36189
diff changeset
   197
    val theory_relevant = lookup_bool_option "theory_relevant"
36922
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
   198
    val defs_relevant = lookup_bool "defs_relevant"
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   199
    val isar_proof = lookup_bool "isar_proof"
36924
ff01d3ae9ad4 renamed options
blanchet
parents: 36922
diff changeset
   200
    val isar_shrink_factor = Int.max (1, lookup_int "isar_shrink_factor")
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   201
    val timeout = lookup_time "timeout"
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   202
    val minimize_timeout = lookup_time "minimize_timeout"
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   203
  in
36143
6490319b1703 added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents: 36142
diff changeset
   204
    {debug = debug, verbose = verbose, overlord = overlord, atps = atps,
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36223
diff changeset
   205
     full_types = full_types, explicit_apply = explicit_apply,
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36223
diff changeset
   206
     respect_no_atp = respect_no_atp, relevance_threshold = relevance_threshold,
36922
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
   207
     relevance_convergence = relevance_convergence,
12f87df9c1a5 renamed two Sledgehammer options
blanchet
parents: 36908
diff changeset
   208
     theory_relevant = theory_relevant, defs_relevant = defs_relevant,
36924
ff01d3ae9ad4 renamed options
blanchet
parents: 36922
diff changeset
   209
     isar_proof = isar_proof, isar_shrink_factor = isar_shrink_factor,
ff01d3ae9ad4 renamed options
blanchet
parents: 36922
diff changeset
   210
     timeout = timeout, minimize_timeout = minimize_timeout}
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   211
  end
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   212
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   213
fun get_params thy = extract_params thy (default_raw_params thy)
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   214
fun default_params thy = get_params thy o map (apsnd single)
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   215
36481
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   216
val subgoal_count = Logic.count_prems o prop_of o #goal o Proof.goal
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   217
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   218
(* Sledgehammer the given subgoal *)
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   219
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   220
fun run {atps = [], ...} _ _ _ _ = error "No ATP is set."
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   221
  | run (params as {atps, timeout, ...}) i relevance_override minimize_command
36481
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   222
        state =
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   223
    case subgoal_count state of
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   224
      0 => priority "No subgoal!"
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   225
    | n =>
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   226
      let
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   227
        val birth_time = Time.now ()
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   228
        val death_time = Time.+ (birth_time, timeout)
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   229
        val _ = kill_atps ()  (* race w.r.t. other Sledgehammer invocations *)
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   230
        val _ = priority "Sledgehammering..."
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   231
        val _ = app (start_prover_thread params birth_time death_time i n
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   232
                                         relevance_override minimize_command
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   233
                                         state) atps
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   234
      in () end
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   235
36378
f32c567dbcaa remove some bloat
blanchet
parents: 36376
diff changeset
   236
fun minimize override_params i fact_refs state =
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   237
  let
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   238
    val thy = Proof.theory_of state
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   239
    val ctxt = Proof.context_of state
36378
f32c567dbcaa remove some bloat
blanchet
parents: 36376
diff changeset
   240
    val theorems_from_refs =
f32c567dbcaa remove some bloat
blanchet
parents: 36376
diff changeset
   241
      map o pairf Facts.string_of_ref o ProofContext.get_fact
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   242
    val name_thms_pairs = theorems_from_refs ctxt fact_refs
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   243
  in
36481
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   244
    case subgoal_count state of
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   245
      0 => priority "No subgoal!"
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   246
    | n => priority (#2 (minimize_theorems (get_params thy override_params) i n
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   247
                                           state name_thms_pairs))
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   248
  end
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   249
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   250
val sledgehammerN = "sledgehammer"
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   251
val sledgehammer_paramsN = "sledgehammer_params"
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   252
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   253
val runN = "run"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   254
val minimizeN = "minimize"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   255
val messagesN = "messages"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   256
val available_atpsN = "available_atps"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   257
val running_atpsN = "running_atps"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   258
val kill_atpsN = "kill_atps"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   259
val refresh_tptpN = "refresh_tptp"
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   260
val helpN = "help"
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   261
36141
c31602d268be make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents: 36140
diff changeset
   262
fun minimizize_raw_param_name "timeout" = "minimize_timeout"
c31602d268be make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents: 36140
diff changeset
   263
  | minimizize_raw_param_name name = name
c31602d268be make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents: 36140
diff changeset
   264
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   265
val is_raw_param_relevant_for_minimize =
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   266
  member (op =) params_for_minimize o fst o unalias_raw_param
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   267
fun string_for_raw_param (key, values) =
36481
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   268
  key ^ (case space_implode " " values of "" => "" | value => " = " ^ value)
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   269
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   270
fun minimize_command override_params i atp_name facts =
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   271
  sledgehammerN ^ " " ^ minimizeN ^ " [atp = " ^ atp_name ^
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   272
  (override_params |> filter is_raw_param_relevant_for_minimize
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   273
                   |> implode o map (prefix ", " o string_for_raw_param)) ^
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   274
  "] (" ^ space_implode " " facts ^ ")" ^
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   275
  (if i = 1 then "" else " " ^ string_of_int i)
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   276
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   277
fun hammer_away override_params subcommand opt_i relevance_override state =
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   278
  let
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   279
    val thy = Proof.theory_of state
36481
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36473
diff changeset
   280
    val _ = app check_raw_param override_params
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   281
  in
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   282
    if subcommand = runN then
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   283
      let val i = the_default 1 opt_i in
36373
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   284
        run (get_params thy override_params) i relevance_override
66af0a49de39 move some sledgehammer stuff out of "atp_manager.ML"
blanchet
parents: 36371
diff changeset
   285
            (minimize_command override_params i) state
36281
dbbf4d5d584d pass relevant options from "sledgehammer" to "sledgehammer minimize";
blanchet
parents: 36235
diff changeset
   286
      end
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   287
    else if subcommand = minimizeN then
36378
f32c567dbcaa remove some bloat
blanchet
parents: 36376
diff changeset
   288
      minimize (map (apfst minimizize_raw_param_name) override_params)
36141
c31602d268be make Sledgehammer's "timeout" option work for "minimize"
blanchet
parents: 36140
diff changeset
   289
               (the_default 1 opt_i) (#add relevance_override) state
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   290
    else if subcommand = messagesN then
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   291
      messages opt_i
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   292
    else if subcommand = available_atpsN then
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   293
      available_atps thy
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   294
    else if subcommand = running_atpsN then
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   295
      running_atps ()
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   296
    else if subcommand = kill_atpsN then
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   297
      kill_atps ()
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   298
    else if subcommand = refresh_tptpN then
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   299
      refresh_systems_on_tptp ()
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   300
    else
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   301
      error ("Unknown subcommand: " ^ quote subcommand ^ ".")
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   302
  end
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   303
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   304
fun sledgehammer_trans (((subcommand, params), relevance_override), opt_i) =
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   305
  Toplevel.keep (hammer_away params subcommand opt_i relevance_override
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   306
                 o Toplevel.proof_of)
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   307
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   308
fun string_for_raw_param (name, value) = name ^ " = " ^ space_implode " " value
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   309
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   310
fun sledgehammer_params_trans params =
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   311
  Toplevel.theory
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   312
      (fold set_default_raw_param params
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   313
       #> tap (fn thy => 
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   314
                  writeln ("Default parameters for Sledgehammer:\n" ^
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   315
                           (case rev (default_raw_params thy) of
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   316
                              [] => "none"
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   317
                            | params =>
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   318
                              (map check_raw_param params;
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   319
                               params |> map string_for_raw_param
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   320
                                      |> sort_strings |> cat_lines)))))
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   321
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   322
val parse_key = Scan.repeat1 Parse.typ_group >> space_implode " "
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   323
val parse_value = Scan.repeat1 Parse.xname
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   324
val parse_param = parse_key -- Scan.optional (Parse.$$$ "=" |-- parse_value) []
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   325
val parse_params = Scan.optional (Args.bracks (Parse.list parse_param)) []
35965
0fce6db7babd added a syntax for specifying facts to Sledgehammer;
blanchet
parents: 35963
diff changeset
   326
val parse_fact_refs =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   327
  Scan.repeat1 (Scan.unless (Parse.name -- Args.colon)
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   328
                            (Parse.xname -- Scan.option Attrib.thm_sel)
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   329
                >> (fn (name, interval) =>
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   330
                       Facts.Named ((name, Position.none), interval)))
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   331
val parse_relevance_chunk =
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   332
  (Args.add |-- Args.colon |-- parse_fact_refs >> add_to_relevance_override)
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   333
  || (Args.del |-- Args.colon |-- parse_fact_refs
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   334
      >> del_from_relevance_override)
36188
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
   335
  || (parse_fact_refs >> only_relevance_override)
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35965
diff changeset
   336
val parse_relevance_override =
36188
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
   337
  Scan.optional (Args.parens (Scan.repeat parse_relevance_chunk
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
   338
                              >> merge_relevance_overrides))
35b9f0db49a0 fiddle with Sledgehammer option syntax
blanchet
parents: 36183
diff changeset
   339
                (add_to_relevance_override [])
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   340
val parse_sledgehammer_command =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   341
  (Scan.optional Parse.short_ident runN -- parse_params -- parse_relevance_override
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   342
   -- Scan.option Parse.nat) #>> sledgehammer_trans
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   343
val parse_sledgehammer_params_command =
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   344
  parse_params #>> sledgehammer_params_trans
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   345
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   346
val _ =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   347
  Outer_Syntax.improper_command sledgehammerN
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   348
      "search for first-order proof using automatic theorem provers" Keyword.diag
36394
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
   349
      parse_sledgehammer_command
35963
943e2582dc87 added options to Sledgehammer;
blanchet
parents: 35962
diff changeset
   350
val _ =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   351
  Outer_Syntax.command sledgehammer_paramsN
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36924
diff changeset
   352
      "set and display the default parameters for Sledgehammer" Keyword.thy_decl
36394
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
   353
      parse_sledgehammer_params_command
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
   354
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
   355
val setup =
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
   356
  neg_clausify_setup
1a48d18449d8 move "neg_clausify" method and "clausify" attribute to "sledgehammer_isar.ML"
blanchet
parents: 36378
diff changeset
   357
  #> clausify_setup
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   358
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents:
diff changeset
   359
end;