author | Fabian Huch <huch@in.tum.de> |
Thu, 24 Oct 2024 16:45:09 +0200 | |
changeset 81368 | 5dbe1a269999 |
parent 81367 | 6b724cf59eed |
child 81369 | 0677712016b5 |
permissions | -rw-r--r-- |
46641 | 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 | 7 |
signature TRY0 = |
38942
e10c11971fa7
"try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff
changeset
|
8 |
sig |
43020
abb5d1f907e4
added "try" command, to launch Solve Direct, Quickcheck, Nitpick, Sledgehammer, and Try Methods
blanchet
parents:
43018
diff
changeset
|
9 |
val noneN : string |
55177 | 10 |
val silence_methods : bool -> Proof.context -> Proof.context |
81366 | 11 |
datatype modifier = Simp | Intro | Elim | Dest |
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
12 |
type result = {name: string, command: string, time: int, state: Proof.state} |
81367
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
13 |
val try0 : Time.time option -> ((Facts.ref * Token.src list) * modifier list) list -> |
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
14 |
Proof.state -> result list |
81365 | 15 |
end |
38942
e10c11971fa7
"try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff
changeset
|
16 |
|
46641 | 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 |
|
81365 | 20 |
val noneN = "none" |
43026
0f15575a6465
handle non-auto try cases gracefully in Try Methods
blanchet
parents:
43024
diff
changeset
|
21 |
|
81365 | 22 |
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
|
23 |
|
81365 | 24 |
val default_timeout = seconds 5.0 |
38944 | 25 |
|
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
26 |
fun run_tac timeout_opt tac st = |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
27 |
let val with_timeout = |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
28 |
(case timeout_opt of SOME timeout => Timeout.apply_physical timeout | NONE => I) |
81365 | 29 |
in with_timeout (Seq.pull o tac) st |> Option.map fst end |
38942
e10c11971fa7
"try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff
changeset
|
30 |
|
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
31 |
fun apply_recursive recurse elapsed0 timeout_opt post apply st = |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
32 |
(case Timing.timing (Option.join o try (run_tac timeout_opt apply)) st of |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
33 |
({elapsed, ...}, SOME st') => |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
34 |
if recurse andalso (st' |> Thm.nprems_of o #goal o Proof.goal) > 0 then |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
35 |
let val timeout_opt1 = (Option.map (fn timeout => timeout - elapsed) timeout_opt) |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
36 |
in apply_recursive recurse (elapsed0 + elapsed) timeout_opt1 post apply st' end |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
37 |
else (elapsed0 + elapsed, st') |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
38 |
|_ => (elapsed0, st)) |
38942
e10c11971fa7
"try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff
changeset
|
39 |
|
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
40 |
fun parse_method ctxt s = |
57918
f5d73caba4e5
tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents:
56982
diff
changeset
|
41 |
enclose "(" ")" s |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
42 |
|> Token.explode (Thy_Header.get_keywords' ctxt) Position.start |
57918
f5d73caba4e5
tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents:
56982
diff
changeset
|
43 |
|> filter Token.is_proper |
f5d73caba4e5
tuned signature according to Scala version -- prefer explicit argument;
wenzelm
parents:
56982
diff
changeset
|
44 |
|> Scan.read Token.stopper Method.parse |
81365 | 45 |
|> (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
|
46 |
|
81366 | 47 |
datatype modifier = Simp | Intro | Elim | Dest |
48 |
||
81367
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
49 |
fun string_of_xthm (xref, args) = |
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
50 |
Facts.string_of_ref xref ^ |
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
51 |
implode (map (enclose "[" "]" o Pretty.unformatted_string_of o Token.pretty_src \<^context>) args) |
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
52 |
|
81364 | 53 |
fun add_attr_text tagged (tag, src) s = |
81367
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
54 |
let |
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
55 |
val fs = tagged |> filter (fn (_, tags) => member (op =) tags tag) |> map (string_of_xthm o fst) |
81365 | 56 |
in if null fs then s else s ^ " " ^ (if src = "" then "" else src ^ ": ") ^ implode_space fs end |
55179 | 57 |
|
81364 | 58 |
fun attrs_text tags tagged = |
81365 | 59 |
"" |> fold (add_attr_text tagged) tags |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
60 |
|
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
61 |
type result = {name: string, command: string, time: int, state: Proof.state} |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
62 |
|
81363
fec95447c5bd
try0: pass tagged thms for better control;
Fabian Huch <huch@in.tum.de>
parents:
81362
diff
changeset
|
63 |
fun apply_named_method (name, ((all_goals, run_if_auto_try), attrs)) mode timeout_opt tagged st = |
43026
0f15575a6465
handle non-auto try cases gracefully in Try Methods
blanchet
parents:
43024
diff
changeset
|
64 |
if mode <> Auto_Try orelse run_if_auto_try then |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
65 |
let |
81368
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
66 |
val unused = |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
67 |
tagged |> filter (fn (_, tags) => null (inter (op =) tags (attrs |> map fst))) |> map fst |
81363
fec95447c5bd
try0: pass tagged thms for better control;
Fabian Huch <huch@in.tum.de>
parents:
81362
diff
changeset
|
68 |
val attrs = attrs_text attrs tagged |
81368
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
69 |
|
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
70 |
val ctxt = Proof.context_of st |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
71 |
|
81368
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
72 |
val using_text = |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
73 |
(K (Method.insert (Attrib.eval_thms ctxt unused))) |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
74 |
|> Method.Basic |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
75 |
|
81368
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
76 |
val text = |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
77 |
name ^ attrs |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
78 |
|> parse_method ctxt |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
79 |
|> Method.method_cmd ctxt |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
80 |
|> Method.Basic |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
81 |
|> (fn m => Method.Combinator (Method.no_combinator_info, Method.Select_Goals 1, [m])) |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
82 |
|> (fn m => Method.Combinator (Method.no_combinator_info, Method.Then, [using_text, m])) |
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
83 |
|
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
84 |
val apply = text |> Proof.refine #> Seq.filter_results |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
85 |
val the_goal = #goal o Proof.goal |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
86 |
val num_before = Thm.nprems_of (the_goal st) |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
87 |
val multiple_goals = all_goals andalso num_before > 1 |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
88 |
val (time, st') = apply_recursive multiple_goals Time.zeroTime timeout_opt the_goal apply st |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
89 |
val num_after = Thm.nprems_of (the_goal st') |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
90 |
val select = "[" ^ string_of_int (num_before - num_after) ^ "]" |
81368
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
91 |
val unused = implode_space (unused |> map string_of_xthm) |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
92 |
val command = |
81368
5dbe1a269999
try0: use extra thms via insert;
Fabian Huch <huch@in.tum.de>
parents:
81367
diff
changeset
|
93 |
(if unused <> "" then "using " ^ unused ^ " " else "") ^ |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
94 |
(if num_after = 0 then "by " else "apply ") ^ |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
95 |
(name ^ attrs |> attrs <> "" ? enclose "(" ")") ^ |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
96 |
(if multiple_goals andalso num_after > 0 then select else "") |
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
97 |
in |
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
98 |
if num_before > num_after then |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
99 |
SOME {name = name, command = command, time = Time.toMilliseconds time, state = st'} |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
100 |
else NONE |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
101 |
end |
81365 | 102 |
else NONE |
38942
e10c11971fa7
"try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff
changeset
|
103 |
|
81366 | 104 |
val full_attrs = [(Simp, "simp"), (Intro, "intro"), (Elim, "elim"), (Dest, "dest")] |
105 |
val clas_attrs = [(Intro, "intro"), (Elim, "elim"), (Dest, "dest")] |
|
106 |
val simp_attrs = [(Simp, "add")] |
|
107 |
val metis_attrs = [(Simp, ""), (Intro, ""), (Elim, ""), (Dest, "")] |
|
81365 | 108 |
val no_attrs = [] |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
109 |
|
81364 | 110 |
(* name * ((all_goals, run_if_auto_try), tags *) |
39547 | 111 |
val named_methods = |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
112 |
[("simp", ((false, true), simp_attrs)), |
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
113 |
("auto", ((true, true), full_attrs)), |
55178 | 114 |
("blast", ((false, true), clas_attrs)), |
115 |
("metis", ((false, true), metis_attrs)), |
|
63961
2fd9656c4c82
invoke argo as part of the tried automatic proof methods
boehmes
parents:
63690
diff
changeset
|
116 |
("argo", ((false, true), no_attrs)), |
55178 | 117 |
("linarith", ((false, true), no_attrs)), |
118 |
("presburger", ((false, true), no_attrs)), |
|
119 |
("algebra", ((false, true), no_attrs)), |
|
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
120 |
("fast", ((false, false), clas_attrs)), |
44890
22f665a2e91c
new fastforce replacing fastsimp - less confusing name
nipkow
parents:
44651
diff
changeset
|
121 |
("fastforce", ((false, false), full_attrs)), |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
122 |
("force", ((false, false), full_attrs)), |
56850 | 123 |
("meson", ((false, false), metis_attrs)), |
78239 | 124 |
("satx", ((false, false), no_attrs)), |
81365 | 125 |
("order", ((false, true), no_attrs))] |
55179 | 126 |
|
81365 | 127 |
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
|
128 |
|
81365 | 129 |
fun time_string ms = string_of_int ms ^ " ms" |
130 |
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
|
131 |
|
55177 | 132 |
(* Makes reconstructor tools as silent as possible. The "set_visible" calls suppresses "Unification |
133 |
bound exceeded" warnings and the like. *) |
|
134 |
fun silence_methods debug = |
|
135 |
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
|
136 |
#> 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
|
137 |
ctxt |
62984 | 138 |
|> Simplifier_Trace.disable |
60275
d8a4fe35da00
silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents:
60190
diff
changeset
|
139 |
|> Context_Position.set_visible false |
79743
3648e9c88d0c
add option for unify trace (now disabled by default as printing is excessive and rarely used);
Fabian Huch <huch@in.tum.de>
parents:
79742
diff
changeset
|
140 |
|> Config.put Unify.unify_trace false |
63961
2fd9656c4c82
invoke argo as part of the tried automatic proof methods
boehmes
parents:
63690
diff
changeset
|
141 |
|> Config.put Argo_Tactic.trace "none" |
60275
d8a4fe35da00
silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents:
60190
diff
changeset
|
142 |
|> 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
|
143 |
thy |
d8a4fe35da00
silence local Unify.trace_bound as well: existing tools either refer to Proof.context or theory;
wenzelm
parents:
60190
diff
changeset
|
144 |
|> Context_Position.set_visible_global false |
81365 | 145 |
|> Config.put_global Unify.unify_trace false)) |
55177 | 146 |
|
81363
fec95447c5bd
try0: pass tagged thms for better control;
Fabian Huch <huch@in.tum.de>
parents:
81362
diff
changeset
|
147 |
fun generic_try0 mode timeout_opt tagged st = |
41038 | 148 |
let |
81365 | 149 |
val st = Proof.map_contexts (silence_methods false) st |
150 |
fun try_method method = method mode timeout_opt tagged st |
|
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
151 |
fun get_message {command, time, ...} = "Found proof: " ^ Active.sendback_markup_command |
81365 | 152 |
command ^ " (" ^ time_string time ^ ")" |
153 |
val print_step = Option.map (tap (writeln o get_message)) |
|
67225 | 154 |
val get_results = |
155 |
if mode = Normal |
|
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
156 |
then Par_List.map (try_method #> print_step) #> map_filter I #> sort (int_ord o apply2 #time) |
81365 | 157 |
else Par_List.get_some try_method #> the_list |
41038 | 158 |
in |
43026
0f15575a6465
handle non-auto try cases gracefully in Try Methods
blanchet
parents:
43024
diff
changeset
|
159 |
if mode = Normal then |
80910 | 160 |
"Trying " ^ implode_space (Try.serial_commas "and" (map (quote o fst) named_methods)) ^ |
55179 | 161 |
"..." |
58843 | 162 |
|> writeln |
43026
0f15575a6465
handle non-auto try cases gracefully in Try Methods
blanchet
parents:
43024
diff
changeset
|
163 |
else |
0f15575a6465
handle non-auto try cases gracefully in Try Methods
blanchet
parents:
43024
diff
changeset
|
164 |
(); |
67225 | 165 |
(case get_results apply_methods of |
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
166 |
[] => (if mode = Normal then writeln "No proof found" else (); ((false, (noneN, [])), [])) |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
167 |
| results as {name, command, ...} :: _ => |
41038 | 168 |
let |
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
169 |
val method_times = |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
170 |
results |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
171 |
|> map (fn {name, time, ...} => (time, name)) |
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
172 |
|> AList.coalesce (op =) |
81365 | 173 |
|> map (swap o apsnd commas) |
41038 | 174 |
val message = |
43026
0f15575a6465
handle non-auto try cases gracefully in Try Methods
blanchet
parents:
43024
diff
changeset
|
175 |
(case mode of |
52970 | 176 |
Auto_Try => "Auto Try0 found a proof" |
177 |
| Try => "Try0 found a proof" |
|
43031 | 178 |
| Normal => "Try this") ^ ": " ^ |
81361
6c0f8a16784d
improve try0: solve multiple subgoals at once, if possible;
Fabian Huch <huch@in.tum.de>
parents:
81360
diff
changeset
|
179 |
Active.sendback_markup_command command ^ |
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
180 |
(case method_times of |
63690
48a2c88091d7
tuning punctuation in messages output by Isabelle
blanchet
parents:
63518
diff
changeset
|
181 |
[(_, ms)] => " (" ^ time_string ms ^ ")" |
81365 | 182 |
| method_times => "\n(" ^ space_implode "; " (map tool_time_string method_times) ^ ")") |
41038 | 183 |
in |
81362
f586fdabe670
clarified: proper return type;
Fabian Huch <huch@in.tum.de>
parents:
81361
diff
changeset
|
184 |
((true, (name, if mode = Auto_Try then [message] else (writeln message; []))), results) |
54291 | 185 |
end) |
81365 | 186 |
end |
39331 | 187 |
|
81365 | 188 |
fun try0 timeout_opt = snd 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
|
189 |
|
81363
fec95447c5bd
try0: pass tagged thms for better control;
Fabian Huch <huch@in.tum.de>
parents:
81362
diff
changeset
|
190 |
fun try0_trans tagged = |
60190
906de96ba68a
allow diagnostic proof commands with skip_proofs;
wenzelm
parents:
60094
diff
changeset
|
191 |
Toplevel.keep_proof |
81365 | 192 |
(ignore o generic_try0 Normal (SOME default_timeout) tagged o Toplevel.proof_of) |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
193 |
|
81367
6b724cf59eed
clarified: proper type for facts;
Fabian Huch <huch@in.tum.de>
parents:
81366
diff
changeset
|
194 |
val parse_fact_refs = Scan.repeat1 (Scan.unless (Parse.name -- Args.colon) Parse.thm) |
55179 | 195 |
|
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
196 |
val parse_attr = |
81366 | 197 |
Args.$$$ "simp" |-- Args.colon |-- parse_fact_refs >> (map (rpair [Simp])) |
198 |
|| Args.$$$ "intro" |-- Args.colon |-- parse_fact_refs >> (map (rpair [Intro])) |
|
199 |
|| Args.$$$ "elim" |-- Args.colon |-- parse_fact_refs >> (map (rpair [Elim])) |
|
200 |
|| Args.$$$ "dest" |-- Args.colon |-- parse_fact_refs >> (map (rpair [Dest])) |
|
55179 | 201 |
|
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
202 |
fun parse_attrs x = |
55179 | 203 |
(Args.parens parse_attrs |
81365 | 204 |
|| Scan.repeat parse_attr >> (fn tagged => fold (curry (op @)) tagged [])) x |
41999
3c029ef9e0f2
added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents:
41038
diff
changeset
|
205 |
|
38942
e10c11971fa7
"try" -- a new diagnosis tool that tries to apply several methods in parallel
blanchet
parents:
diff
changeset
|
206 |
val _ = |
67149 | 207 |
Outer_Syntax.command \<^command_keyword>\<open>try0\<close> "try a combination of proof methods" |
81365 | 208 |
(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
|
209 |
|
74508 | 210 |
val _ = |
211 |
Try.tool_setup |
|
212 |
{name = "try0", weight = 30, auto_option = \<^system_option>\<open>auto_methods\<close>, |
|
81365 | 213 |
body = fn auto => fst o generic_try0 (if auto then Auto_Try else Try) NONE []} |
39331 | 214 |
|
81365 | 215 |
end |