14 val someN: string |
14 val someN: string |
15 val noneN: string |
15 val noneN: string |
16 val unknownN: string |
16 val unknownN: string |
17 val auto: bool Unsynchronized.ref |
17 val auto: bool Unsynchronized.ref |
18 val max_solutions: int Unsynchronized.ref |
18 val max_solutions: int Unsynchronized.ref |
19 val solve_direct: bool -> Proof.state -> bool * (string * Proof.state) |
19 val solve_direct: Proof.state -> bool * (string * Proof.state) |
20 val setup: theory -> theory |
20 val setup: theory -> theory |
21 end; |
21 end; |
22 |
22 |
23 structure Solve_Direct: SOLVE_DIRECT = |
23 structure Solve_Direct: SOLVE_DIRECT = |
24 struct |
24 struct |
|
25 |
|
26 datatype mode = Auto_Try | Try | Normal |
25 |
27 |
26 val solve_directN = "solve_direct"; |
28 val solve_directN = "solve_direct"; |
27 |
29 |
28 val someN = "some"; |
30 val someN = "some"; |
29 val noneN = "none"; |
31 val noneN = "none"; |
42 ("Run " ^ quote solve_directN ^ " automatically.")) ()); |
44 ("Run " ^ quote solve_directN ^ " automatically.")) ()); |
43 |
45 |
44 |
46 |
45 (* solve_direct command *) |
47 (* solve_direct command *) |
46 |
48 |
47 fun solve_direct auto state = |
49 fun do_solve_direct mode state = |
48 let |
50 let |
49 val ctxt = Proof.context_of state; |
51 val ctxt = Proof.context_of state; |
50 |
52 |
51 val crits = [(true, Find_Theorems.Solves)]; |
53 val crits = [(true, Find_Theorems.Solves)]; |
52 fun find g = |
54 fun find g = |
53 snd (Find_Theorems.find_theorems ctxt (SOME g) (SOME (! max_solutions)) false crits); |
55 snd (Find_Theorems.find_theorems ctxt (SOME g) (SOME (! max_solutions)) false crits); |
54 |
56 |
55 fun prt_result (goal, results) = |
57 fun prt_result (goal, results) = |
56 let |
58 let |
57 val msg = |
59 val msg = |
58 (if auto then "Auto " else "") ^ solve_directN ^ ": " ^ |
60 (if mode = Auto_Try then "Auto " else "") ^ solve_directN ^ ": " ^ |
59 (case goal of |
61 (case goal of |
60 NONE => "The current goal" |
62 NONE => "The current goal" |
61 | SOME sg => Syntax.string_of_term ctxt (Thm.term_of sg)); |
63 | SOME sg => Syntax.string_of_term ctxt (Thm.term_of sg)); |
62 in |
64 in |
63 Pretty.big_list |
65 Pretty.big_list |
81 in |
83 in |
82 (case try seek_against_goal () of |
84 (case try seek_against_goal () of |
83 SOME (SOME results) => |
85 SOME (SOME results) => |
84 (someN, |
86 (someN, |
85 state |> |
87 state |> |
86 (if auto then |
88 (if mode = Auto_Try then |
87 Proof.goal_message |
89 Proof.goal_message |
88 (fn () => |
90 (fn () => |
89 Pretty.chunks |
91 Pretty.chunks |
90 [Pretty.str "", |
92 [Pretty.str "", Pretty.markup Markup.hilite (message results)]) |
91 Pretty.markup Markup.hilite (message results)]) |
93 else |
92 else |
94 tap (fn _ => |
93 tap (fn _ => |
95 Output.urgent_message (Pretty.string_of (Pretty.chunks (message results)))))) |
94 Output.urgent_message (Pretty.string_of (Pretty.chunks (message results)))))) |
96 | SOME NONE => |
95 | SOME NONE => (noneN, state) |
97 (if mode = Normal then Output.urgent_message "No proof found." |
96 | NONE => (unknownN, state)) |
98 else (); |
|
99 (noneN, state)) |
|
100 | NONE => |
|
101 (if mode = Normal then Output.urgent_message "An error occurred." |
|
102 else (); |
|
103 (unknownN, state))) |
97 end |
104 end |
98 |> `(fn (outcome_code, _) => outcome_code = someN); |
105 |> `(fn (outcome_code, _) => outcome_code = someN); |
|
106 |
|
107 val solve_direct = do_solve_direct Normal |
99 |
108 |
100 val _ = |
109 val _ = |
101 Outer_Syntax.improper_command solve_directN |
110 Outer_Syntax.improper_command solve_directN |
102 "try to solve conjectures directly with existing theorems" Keyword.diag |
111 "try to solve conjectures directly with existing theorems" Keyword.diag |
103 (Scan.succeed |
112 (Scan.succeed |
104 (Toplevel.keep (fn state => ignore (solve_direct false (Toplevel.proof_of state))))); |
113 (Toplevel.keep (ignore o solve_direct o Toplevel.proof_of))); |
105 |
114 |
106 |
115 |
107 (* hook *) |
116 (* hook *) |
108 |
117 |
109 val setup = Try.register_tool (solve_directN, (10, auto, solve_direct)); |
118 fun try_solve_direct auto = do_solve_direct (if auto then Auto_Try else Try) |
|
119 |
|
120 val setup = Try.register_tool (solve_directN, (10, auto, try_solve_direct)); |
110 |
121 |
111 end; |
122 end; |