equal
deleted
inserted
replaced
12 signature AUTO_SOLVE = |
12 signature AUTO_SOLVE = |
13 sig |
13 sig |
14 val auto : bool ref |
14 val auto : bool ref |
15 val auto_time_limit : int ref |
15 val auto_time_limit : int ref |
16 val limit : int ref |
16 val limit : int ref |
17 |
|
18 val seek_solution : bool -> Proof.state -> Proof.state |
|
19 end; |
17 end; |
20 |
18 |
21 structure AutoSolve : AUTO_SOLVE = |
19 structure AutoSolve : AUTO_SOLVE = |
22 struct |
20 struct |
23 |
21 |
|
22 (* preferences *) |
|
23 |
24 val auto = ref false; |
24 val auto = ref false; |
25 val auto_time_limit = ref 2500; |
25 val auto_time_limit = ref 2500; |
26 val limit = ref 5; |
26 val limit = ref 5; |
27 |
27 |
28 fun seek_solution int state = |
28 val _ = |
|
29 ProofGeneralPgip.add_preference Preferences.category_tracing |
|
30 (setmp auto true (fn () => |
|
31 Preferences.bool_pref auto |
|
32 "auto-solve" |
|
33 "Try to solve newly declared lemmas with existing theorems.") ()); |
|
34 |
|
35 val _ = |
|
36 ProofGeneralPgip.add_preference Preferences.category_tracing |
|
37 (Preferences.nat_pref auto_time_limit |
|
38 "auto-solve-time-limit" |
|
39 "Time limit for seeking automatic solutions (in milliseconds)."); |
|
40 |
|
41 |
|
42 (* hook *) |
|
43 |
|
44 val _ = Context.>> (Specification.add_theorem_hook (fn int => fn state => |
29 let |
45 let |
30 val ctxt = Proof.context_of state; |
46 val ctxt = Proof.context_of state; |
31 |
47 |
32 val crits = [(true, FindTheorems.Solves)]; |
48 val crits = [(true, FindTheorems.Solves)]; |
33 fun find g = snd (FindTheorems.find_theorems ctxt (SOME g) (SOME (! limit)) false crits); |
49 fun find g = snd (FindTheorems.find_theorems ctxt (SOME g) (SOME (! limit)) false crits); |
74 end handle TimeLimit.TimeOut => (warning "AutoSolve: timeout."; state); |
90 end handle TimeLimit.TimeOut => (warning "AutoSolve: timeout."; state); |
75 in |
91 in |
76 if int andalso ! auto andalso not (! Toplevel.quiet) |
92 if int andalso ! auto andalso not (! Toplevel.quiet) |
77 then go () |
93 then go () |
78 else state |
94 else state |
79 end; |
95 end)); |
80 |
96 |
81 end; |
97 end; |
82 |
|
83 val _ = Context.>> (Specification.add_theorem_hook AutoSolve.seek_solution); |
|
84 |
98 |
85 val auto_solve = AutoSolve.auto; |
99 val auto_solve = AutoSolve.auto; |
86 val auto_solve_time_limit = AutoSolve.auto_time_limit; |
100 val auto_solve_time_limit = AutoSolve.auto_time_limit; |
87 |
101 |