4 Manager for tools that should be tried on conjectures. |
4 Manager for tools that should be tried on conjectures. |
5 *) |
5 *) |
6 |
6 |
7 signature TRY = |
7 signature TRY = |
8 sig |
8 sig |
|
9 type tool = |
|
10 string * (bool Unsynchronized.ref |
|
11 * (bool -> Proof.state -> bool * (string * Proof.state))) |
|
12 |
|
13 val tryN : string |
9 val auto_time_limit: real Unsynchronized.ref |
14 val auto_time_limit: real Unsynchronized.ref |
10 |
15 |
11 val register_tool : |
16 val register_tool : tool -> theory -> theory |
12 bool Unsynchronized.ref * (Proof.state -> bool * Proof.state) -> theory |
17 val get_tools : theory -> tool list |
13 -> theory |
18 val try_tools : Proof.state -> (string * string) option |
14 end; |
19 end; |
15 |
20 |
16 structure Try : TRY = |
21 structure Try : TRY = |
17 struct |
22 struct |
|
23 |
|
24 type tool = |
|
25 string * (bool Unsynchronized.ref |
|
26 * (bool -> Proof.state -> bool * (string * Proof.state))) |
|
27 |
|
28 val tryN = "try" |
|
29 |
18 |
30 |
19 (* preferences *) |
31 (* preferences *) |
20 |
32 |
21 val auto_time_limit = Unsynchronized.ref 4.0 |
33 val auto_time_limit = Unsynchronized.ref 4.0 |
22 |
34 |
29 |
41 |
30 (* configuration *) |
42 (* configuration *) |
31 |
43 |
32 structure Data = Theory_Data |
44 structure Data = Theory_Data |
33 ( |
45 ( |
34 type T = (bool Unsynchronized.ref * (Proof.state -> bool * Proof.state)) list |
46 type T = tool list |
35 val empty = [] |
47 val empty = [] |
36 val extend = I |
48 val extend = I |
37 fun merge data : T = AList.merge (op =) (K true) data |
49 fun merge data : T = AList.merge (op =) (K true) data |
38 ) |
50 ) |
39 |
51 |
|
52 val get_tools = Data.get |
|
53 |
40 val register_tool = Data.map o AList.update (op =) |
54 val register_tool = Data.map o AList.update (op =) |
41 |
55 |
|
56 (* try command *) |
42 |
57 |
43 (* automatic testing *) |
58 fun try_tools state = |
|
59 get_tools (Proof.theory_of state) |
|
60 |> Par_List.get_some |
|
61 (fn (name, (_, tool)) => |
|
62 case try (tool false) state of |
|
63 SOME (true, (outcome_code, _)) => SOME (name, outcome_code) |
|
64 | _ => NONE) |
44 |
65 |
45 fun run_tools tools state = |
66 val _ = |
46 tools |> map_filter (fn (auto, tool) => if !auto then SOME tool else NONE) |
67 Outer_Syntax.improper_command tryN |
47 |> Par_List.get_some (fn tool => |
68 "try a combination of automatic proving and disproving tools" Keyword.diag |
48 case try tool state of |
69 (Scan.succeed (Toplevel.keep (ignore o try_tools o Toplevel.proof_of))) |
49 SOME (true, state) => SOME state |
70 |
50 | _ => NONE) |
71 |
51 |> the_default state |
72 (* automatic try *) |
|
73 |
|
74 fun auto_try state = |
|
75 get_tools (Proof.theory_of state) |
|
76 |> map_filter (fn (_, (auto, tool)) => if !auto then SOME tool else NONE) |
|
77 |> Par_List.get_some (fn tool => |
|
78 case try (tool true) state of |
|
79 SOME (true, (_, state)) => SOME state |
|
80 | _ => NONE) |
|
81 |> the_default state |
52 |
82 |
53 (* Too large values are understood as milliseconds, ensuring compatibility with |
83 (* Too large values are understood as milliseconds, ensuring compatibility with |
54 old setting files. No users can possibly in their right mind want the user |
84 old setting files. No users can possibly in their right mind want the user |
55 interface to block for more than 100 seconds. *) |
85 interface to block for more than 100 seconds. *) |
56 fun smart_seconds r = |
86 fun smart_seconds r = |
60 else |
90 else |
61 r) |
91 r) |
62 |
92 |
63 val _ = Context.>> (Specification.add_theorem_hook (fn interact => fn state => |
93 val _ = Context.>> (Specification.add_theorem_hook (fn interact => fn state => |
64 if interact andalso not (!Toplevel.quiet) andalso !auto_time_limit > 0.0 then |
94 if interact andalso not (!Toplevel.quiet) andalso !auto_time_limit > 0.0 then |
65 TimeLimit.timeLimit (smart_seconds (!auto_time_limit)) |
95 TimeLimit.timeLimit (smart_seconds (!auto_time_limit)) auto_try state |
66 (run_tools (Data.get (Proof.theory_of state))) state |
|
67 handle TimeLimit.TimeOut => state |
96 handle TimeLimit.TimeOut => state |
68 else |
97 else |
69 state)) |
98 state)) |
70 |
99 |
71 end; |
100 end; |