src/HOL/Tools/try0.ML
author wenzelm
Sun, 13 Dec 2015 21:56:15 +0100
changeset 61841 4d3527b94f2a
parent 60350 9251f82337d6
child 61877 276ad4354069
permissions -rw-r--r--
more general types Proof.method / context_tactic; proper context for Method.insert_tac; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46641
8801a24f9e9a renamed 'try_methods' to 'try0'
blanchet
parents: 45666
diff changeset
     1
(*  Title:      HOL/Tools/try0.ML
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
     3
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
     4
Try a combination of proof methods.
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
     5
*)
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
     6
46641
8801a24f9e9a renamed 'try_methods' to 'try0'
blanchet
parents: 45666
diff changeset
     7
signature TRY0 =
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
     8
sig
46641
8801a24f9e9a renamed 'try_methods' to 'try0'
blanchet
parents: 45666
diff changeset
     9
  val try0N : string
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
    10
  val noneN : string
55177
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
    11
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
    12
  val silence_methods : bool -> Proof.context -> Proof.context
55179
blanchet
parents: 55178
diff changeset
    13
  val try0 : Time.time option -> string list * string list * string list * string list ->
blanchet
parents: 55178
diff changeset
    14
    Proof.state -> bool
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    15
end;
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    16
46641
8801a24f9e9a renamed 'try_methods' to 'try0'
blanchet
parents: 45666
diff changeset
    17
structure Try0 : TRY0 =
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    18
struct
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    19
55179
blanchet
parents: 55178
diff changeset
    20
val try0N = "try0";
blanchet
parents: 55178
diff changeset
    21
val noneN = "none";
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
    22
55179
blanchet
parents: 55178
diff changeset
    23
datatype mode = Auto_Try | Try | Normal;
43020
abb5d1f907e4 added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents: 43018
diff changeset
    24
55179
blanchet
parents: 55178
diff changeset
    25
val default_timeout = seconds 5.0;
38944
827c98e8ba8b fiddling with "try"
blanchet
parents: 38942
diff changeset
    26
39336
1899349a5026 change signature of "Try.invoke_try" to make it more flexible
blanchet
parents: 39334
diff changeset
    27
fun can_apply timeout_opt pre post tac st =
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    28
  let val {goal, ...} = Proof.goal st in
55182
dd1e95e67b30 more robust w.r.t. exceptions raised by proof methods
blanchet
parents: 55181
diff changeset
    29
    (case (case timeout_opt of
39336
1899349a5026 change signature of "Try.invoke_try" to make it more flexible
blanchet
parents: 39334
diff changeset
    30
            SOME timeout => TimeLimit.timeLimit timeout
1899349a5026 change signature of "Try.invoke_try" to make it more flexible
blanchet
parents: 39334
diff changeset
    31
          | NONE => fn f => fn x => f x) (Seq.pull o tac) (pre st) of
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59184
diff changeset
    32
      SOME (x, _) => Thm.nprems_of (post x) < Thm.nprems_of goal
55182
dd1e95e67b30 more robust w.r.t. exceptions raised by proof methods
blanchet
parents: 55181
diff changeset
    33
    | NONE => false)
dd1e95e67b30 more robust w.r.t. exceptions raised by proof methods
blanchet
parents: 55181
diff changeset
    34
  end;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    35
55181
blanchet
parents: 55179
diff changeset
    36
fun apply_generic timeout_opt name command pre post apply st =
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    37
  let val timer = Timer.startRealTimer () in
55182
dd1e95e67b30 more robust w.r.t. exceptions raised by proof methods
blanchet
parents: 55181
diff changeset
    38
    if try (can_apply timeout_opt pre post apply) st = SOME true then
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
    39
      SOME (name, command, Time.toMilliseconds (Timer.checkRealTimer timer))
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    40
    else
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    41
      NONE
55179
blanchet
parents: 55178
diff changeset
    42
  end;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    43
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58903
diff changeset
    44
fun parse_method keywords s =
57918
f5d73caba4e5 tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents: 56982
diff changeset
    45
  enclose "(" ")" s
59083
88b0b1f28adc tuned signature;
wenzelm
parents: 59058
diff changeset
    46
  |> Token.explode keywords Position.start
57918
f5d73caba4e5 tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents: 56982
diff changeset
    47
  |> filter Token.is_proper
f5d73caba4e5 tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents: 56982
diff changeset
    48
  |> Scan.read Token.stopper Method.parse
f5d73caba4e5 tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents: 56982
diff changeset
    49
  |> (fn SOME (Method.Source src, _) => src | _ => raise Fail "expected Source");
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    50
55742
a989bdaf8121 modernized Method.check_name/check_source (with reports) vs. strict Method.the_method (without interning nor reports), e.g. relevant for semantic completion;
wenzelm
parents: 55182
diff changeset
    51
fun apply_named_method_on_first_goal ctxt =
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58903
diff changeset
    52
  parse_method (Thy_Header.get_keywords' ctxt)
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55765
diff changeset
    53
  #> Method.method_cmd ctxt
55182
dd1e95e67b30 more robust w.r.t. exceptions raised by proof methods
blanchet
parents: 55181
diff changeset
    54
  #> Method.Basic
58005
c28e6bc6635d more compact datatypes;
wenzelm
parents: 57918
diff changeset
    55
  #> (fn m => Method.Combinator (Method.no_combinator_info, Method.Select_Goals 1, [m]))
55182
dd1e95e67b30 more robust w.r.t. exceptions raised by proof methods
blanchet
parents: 55181
diff changeset
    56
  #> Proof.refine;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    57
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    58
fun add_attr_text (NONE, _) s = s
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    59
  | add_attr_text (_, []) s = s
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    60
  | add_attr_text (SOME x, fs) s =
55179
blanchet
parents: 55178
diff changeset
    61
    s ^ " " ^ (if x = "" then "" else x ^ ": ") ^ space_implode " " fs;
blanchet
parents: 55178
diff changeset
    62
42179
24662b614fd4 added support for "dest:" to "try"
blanchet
parents: 41999
diff changeset
    63
fun attrs_text (sx, ix, ex, dx) (ss, is, es, ds) =
55179
blanchet
parents: 55178
diff changeset
    64
  "" |> fold add_attr_text [(sx, ss), (ix, is), (ex, es), (dx, ds)];
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    65
55181
blanchet
parents: 55179
diff changeset
    66
fun apply_named_method (name, ((all_goals, run_if_auto_try), attrs)) mode timeout_opt quad st =
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
    67
  if mode <> Auto_Try orelse run_if_auto_try then
42179
24662b614fd4 added support for "dest:" to "try"
blanchet
parents: 41999
diff changeset
    68
    let val attrs = attrs_text attrs quad in
55181
blanchet
parents: 55179
diff changeset
    69
      apply_generic timeout_opt name
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
    70
        ((name ^ attrs |> attrs <> "" ? enclose "(" ")") ^
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59184
diff changeset
    71
         (if all_goals andalso Thm.nprems_of (#goal (Proof.goal st)) > 1 then "[1]" else ""))
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
    72
        I (#goal o Proof.goal)
61841
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 60350
diff changeset
    73
        (apply_named_method_on_first_goal (Proof.context_of st) (name ^ attrs)
4d3527b94f2a more general types Proof.method / context_tactic;
wenzelm
parents: 60350
diff changeset
    74
          #> Seq.filter_results) st
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    75
    end
40222
cd6d2b0a4096 reintroduced Auto Try, but this time really off by default -- and leave some classical+simp reasoners out for Auto Try (but keep them for Try)
blanchet
parents: 40132
diff changeset
    76
  else
55179
blanchet
parents: 55178
diff changeset
    77
    NONE;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
    78
55179
blanchet
parents: 55178
diff changeset
    79
val full_attrs = (SOME "simp", SOME "intro", SOME "elim", SOME "dest");
blanchet
parents: 55178
diff changeset
    80
val clas_attrs = (NONE, SOME "intro", SOME "elim", SOME "dest");
blanchet
parents: 55178
diff changeset
    81
val simp_attrs = (SOME "add", NONE, NONE, NONE);
blanchet
parents: 55178
diff changeset
    82
val metis_attrs = (SOME "", SOME "", SOME "", SOME "");
blanchet
parents: 55178
diff changeset
    83
val no_attrs = (NONE, NONE, NONE, NONE);
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    84
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
    85
(* name * ((all_goals, run_if_auto_try), (simp, intro, elim, dest) *)
39547
5df45da44bfb reorder proof methods and take out "best";
blanchet
parents: 39336
diff changeset
    86
val named_methods =
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    87
  [("simp", ((false, true), simp_attrs)),
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    88
   ("auto", ((true, true), full_attrs)),
55178
318cd8ac1817 added 'algebra' and 'meson' to 'try0'
blanchet
parents: 55177
diff changeset
    89
   ("blast", ((false, true), clas_attrs)),
318cd8ac1817 added 'algebra' and 'meson' to 'try0'
blanchet
parents: 55177
diff changeset
    90
   ("metis", ((false, true), metis_attrs)),
318cd8ac1817 added 'algebra' and 'meson' to 'try0'
blanchet
parents: 55177
diff changeset
    91
   ("linarith", ((false, true), no_attrs)),
318cd8ac1817 added 'algebra' and 'meson' to 'try0'
blanchet
parents: 55177
diff changeset
    92
   ("presburger", ((false, true), no_attrs)),
318cd8ac1817 added 'algebra' and 'meson' to 'try0'
blanchet
parents: 55177
diff changeset
    93
   ("algebra", ((false, true), no_attrs)),
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    94
   ("fast", ((false, false), clas_attrs)),
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44651
diff changeset
    95
   ("fastforce", ((false, false), full_attrs)),
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
    96
   ("force", ((false, false), full_attrs)),
56850
13a7bca533a3 added 'satx' proof method to Try0
blanchet
parents: 56467
diff changeset
    97
   ("meson", ((false, false), metis_attrs)),
13a7bca533a3 added 'satx' proof method to Try0
blanchet
parents: 56467
diff changeset
    98
   ("satx", ((false, false), no_attrs))];
55179
blanchet
parents: 55178
diff changeset
    99
55181
blanchet
parents: 55179
diff changeset
   100
val apply_methods = map apply_named_method named_methods;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
   101
55179
blanchet
parents: 55178
diff changeset
   102
fun time_string ms = string_of_int ms ^ " ms";
blanchet
parents: 55178
diff changeset
   103
fun tool_time_string (s, ms) = s ^ ": " ^ time_string ms;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
   104
55177
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
   105
(* Makes reconstructor tools as silent as possible. The "set_visible" calls suppresses "Unification
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
   106
   bound exceeded" warnings and the like. *)
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
   107
fun silence_methods debug =
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
   108
  Config.put Metis_Tactic.verbose debug
60275
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   109
  #> not debug ? (fn ctxt =>
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   110
      ctxt
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   111
      |> Context_Position.set_visible false
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   112
      |> Config.put Unify.trace_bound (Config.get ctxt Unify.search_bound)
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   113
      |> Proof_Context.background_theory (fn thy =>
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   114
          thy
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   115
          |> Context_Position.set_visible_global false
d8a4fe35da00 silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents: 60190
diff changeset
   116
          |> Config.put_global Unify.trace_bound (Config.get_global thy Unify.search_bound)));
55177
b7ca9f98faca made 'try0' (more) silent
blanchet
parents: 54431
diff changeset
   117
55181
blanchet
parents: 55179
diff changeset
   118
fun generic_try0 mode timeout_opt quad st =
41038
9592334001d5 quiet Metis in "try"
blanchet
parents: 40931
diff changeset
   119
  let
56982
51d4189d95cf silence methods even better
blanchet
parents: 56850
diff changeset
   120
    val st = Proof.map_contexts (silence_methods false) st;
55179
blanchet
parents: 55178
diff changeset
   121
    fun trd (_, _, t) = t;
54248
c7af3d651658 make 'try0' return faster when invoked as part of 'try'
blanchet
parents: 53052
diff changeset
   122
    fun par_map f =
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58928
diff changeset
   123
      if mode = Normal then Par_List.map f #> map_filter I #> sort (int_ord o apply2 trd)
55179
blanchet
parents: 55178
diff changeset
   124
      else Par_List.get_some f #> the_list;
41038
9592334001d5 quiet Metis in "try"
blanchet
parents: 40931
diff changeset
   125
  in
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
   126
    if mode = Normal then
55179
blanchet
parents: 55178
diff changeset
   127
      "Trying " ^ space_implode " " (Try.serial_commas "and" (map (quote o fst) named_methods)) ^
blanchet
parents: 55178
diff changeset
   128
      "..."
58843
521cea5fa777 discontinued obsolete Output.urgent_message;
wenzelm
parents: 58842
diff changeset
   129
      |> writeln
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
   130
    else
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
   131
      ();
55181
blanchet
parents: 55179
diff changeset
   132
    (case par_map (fn f => f mode timeout_opt quad st) apply_methods of
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
   133
      [] =>
58892
20aa19ecf2cc eliminated obsolete Proof.goal_message -- print outcome more directly;
wenzelm
parents: 58843
diff changeset
   134
      (if mode = Normal then writeln "No proof found." else (); (false, (noneN, [])))
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
   135
    | xs as (name, command, _) :: _ =>
41038
9592334001d5 quiet Metis in "try"
blanchet
parents: 40931
diff changeset
   136
      let
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
   137
        val xs = xs |> map (fn (name, _, n) => (n, name))
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   138
                    |> AList.coalesce (op =)
41038
9592334001d5 quiet Metis in "try"
blanchet
parents: 40931
diff changeset
   139
                    |> map (swap o apsnd commas)
9592334001d5 quiet Metis in "try"
blanchet
parents: 40931
diff changeset
   140
        val message =
43026
0f15575a6465 handle non-auto try cases gracefully in Try Methods
blanchet
parents: 43024
diff changeset
   141
          (case mode of
52970
3e0fe71f3ce1 tuned messages
blanchet
parents: 52717
diff changeset
   142
             Auto_Try => "Auto Try0 found a proof"
3e0fe71f3ce1 tuned messages
blanchet
parents: 52717
diff changeset
   143
           | Try => "Try0 found a proof"
43031
e437d47f419f more concise output
blanchet
parents: 43026
diff changeset
   144
           | Normal => "Try this") ^ ": " ^
53052
a0db255af8c5 sledgehammer sendback always uses Markup.padding_command: sensible default for most practical applications -- old-style in-line replacement is superseded by auto mode or panel;
wenzelm
parents: 52970
diff changeset
   145
          Active.sendback_markup [Markup.padding_command]
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59184
diff changeset
   146
              ((if Thm.nprems_of (#goal (Proof.goal st)) = 1 then "by"
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
   147
                else "apply") ^ " " ^ command) ^
54248
c7af3d651658 make 'try0' return faster when invoked as part of 'try'
blanchet
parents: 53052
diff changeset
   148
          (case xs of
c7af3d651658 make 'try0' return faster when invoked as part of 'try'
blanchet
parents: 53052
diff changeset
   149
            [(_, ms)] => " (" ^ time_string ms ^ ")."
c7af3d651658 make 'try0' return faster when invoked as part of 'try'
blanchet
parents: 53052
diff changeset
   150
          | xs => "\n(" ^ space_implode "; " (map tool_time_string xs) ^ ").")
41038
9592334001d5 quiet Metis in "try"
blanchet
parents: 40931
diff changeset
   151
      in
59184
830bb7ddb3ab explicit message channels for "state", "information";
wenzelm
parents: 59083
diff changeset
   152
        (true, (name, if mode = Auto_Try then [message] else (writeln message; [])))
54291
709a2bbd7638 by (auto ...)[1] not by (auto [1])
blanchet
parents: 54248
diff changeset
   153
      end)
55179
blanchet
parents: 55178
diff changeset
   154
  end;
39331
8b1969d603c0 added Auto Try to the mix of automatic tools
blanchet
parents: 39222
diff changeset
   155
55181
blanchet
parents: 55179
diff changeset
   156
fun try0 timeout_opt = fst oo generic_try0 Normal timeout_opt;
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
   157
46641
8801a24f9e9a renamed 'try_methods' to 'try0'
blanchet
parents: 45666
diff changeset
   158
fun try0_trans quad =
60190
906de96ba68a allow diagnostic proof commands with skip_proofs;
wenzelm
parents: 60094
diff changeset
   159
  Toplevel.keep_proof
906de96ba68a allow diagnostic proof commands with skip_proofs;
wenzelm
parents: 60094
diff changeset
   160
    (ignore o generic_try0 Normal (SOME default_timeout) quad o Toplevel.proof_of);
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   161
55179
blanchet
parents: 55178
diff changeset
   162
fun merge_attrs (s1, i1, e1, d1) (s2, i2, e2, d2) = (s1 @ s2, i1 @ i2, e1 @ e2, d1 @ d2);
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   163
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   164
fun string_of_xthm (xref, args) =
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   165
  Facts.string_of_ref xref ^
58011
bc6bced136e5 tuned signature -- moved type src to Token, without aliases;
wenzelm
parents: 58005
diff changeset
   166
  implode (map (enclose "[" "]" o Pretty.str_of o Token.pretty_src @{context}) args);
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   167
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   168
val parse_fact_refs =
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   169
  Scan.repeat1 (Scan.unless (Parse.name -- Args.colon) (Parse.xthm >> string_of_xthm));
55179
blanchet
parents: 55178
diff changeset
   170
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   171
val parse_attr =
55179
blanchet
parents: 55178
diff changeset
   172
  Args.$$$ "simp" |-- Args.colon |-- parse_fact_refs >> (fn ss => (ss, [], [], []))
blanchet
parents: 55178
diff changeset
   173
  || Args.$$$ "intro" |-- Args.colon |-- parse_fact_refs >> (fn is => ([], is, [], []))
blanchet
parents: 55178
diff changeset
   174
  || Args.$$$ "elim" |-- Args.colon |-- parse_fact_refs >> (fn es => ([], [], es, []))
blanchet
parents: 55178
diff changeset
   175
  || Args.$$$ "dest" |-- Args.colon |-- parse_fact_refs >> (fn ds => ([], [], [], ds));
blanchet
parents: 55178
diff changeset
   176
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   177
fun parse_attrs x =
55179
blanchet
parents: 55178
diff changeset
   178
  (Args.parens parse_attrs
blanchet
parents: 55178
diff changeset
   179
   || Scan.repeat parse_attr >> (fn quad => fold merge_attrs quad ([], [], [], []))) x;
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41038
diff changeset
   180
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
   181
val _ =
59936
b8ffc3dc9e24 @{command_spec} is superseded by @{command_keyword};
wenzelm
parents: 59582
diff changeset
   182
  Outer_Syntax.command @{command_keyword try0} "try a combination of proof methods"
55179
blanchet
parents: 55178
diff changeset
   183
    (Scan.optional parse_attrs ([], [], [], []) #>> try0_trans);
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
   184
55181
blanchet
parents: 55179
diff changeset
   185
fun try_try0 auto = generic_try0 (if auto then Auto_Try else Try) NONE ([], [], [], []);
39331
8b1969d603c0 added Auto Try to the mix of automatic tools
blanchet
parents: 39222
diff changeset
   186
56467
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56032
diff changeset
   187
val _ = Try.tool_setup (try0N, (30, @{system_option auto_methods}, try_try0));
39331
8b1969d603c0 added Auto Try to the mix of automatic tools
blanchet
parents: 39222
diff changeset
   188
38942
e10c11971fa7 "try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff changeset
   189
end;