38 |> sort_distinct string_ord |> space_implode " ") |
38 |> sort_distinct string_ord |> space_implode " ") |
39 else |
39 else |
40 "") |
40 "") |
41 end |
41 end |
42 |
42 |
43 fun test_theorems ({debug, verbose, overlord, atps, full_types, |
43 fun test_theorems ({debug, verbose, overlord, atps, full_types, isar_proof, |
44 relevance_threshold, relevance_decay, isar_proof, |
|
45 isar_shrink_factor, ...} : params) |
44 isar_shrink_factor, ...} : params) |
46 (prover : prover) explicit_apply timeout subgoal state |
45 (prover : prover) explicit_apply timeout subgoal state |
47 name_thms_pairs = |
46 axioms = |
48 let |
47 let |
49 val _ = |
48 val _ = |
50 priority ("Testing " ^ n_theorems (map fst name_thms_pairs) ^ "...") |
49 priority ("Testing " ^ n_theorems (map fst axioms) ^ "...") |
51 val params = |
50 val params = |
52 {debug = debug, verbose = verbose, overlord = overlord, atps = atps, |
51 {debug = debug, verbose = verbose, overlord = overlord, atps = atps, |
53 full_types = full_types, explicit_apply = explicit_apply, |
52 full_types = full_types, explicit_apply = explicit_apply, |
54 relevance_threshold = relevance_threshold, |
53 relevance_threshold = 1.1, relevance_decay = NONE, max_relevant = NONE, |
55 relevance_decay = relevance_decay, max_relevant_per_iter = NONE, |
|
56 theory_relevant = NONE, isar_proof = isar_proof, |
54 theory_relevant = NONE, isar_proof = isar_proof, |
57 isar_shrink_factor = isar_shrink_factor, timeout = timeout} |
55 isar_shrink_factor = isar_shrink_factor, timeout = timeout} |
58 val axioms = maps (fn (n, ths) => map (pair n) ths) name_thms_pairs |
56 val axioms = maps (fn (n, ths) => map (pair n) ths) axioms |
59 val {context = ctxt, facts, goal} = Proof.goal state |
57 val {context = ctxt, facts, goal} = Proof.goal state |
60 val problem = |
58 val problem = |
61 {subgoal = subgoal, goal = (ctxt, (facts, goal)), |
59 {subgoal = subgoal, goal = (ctxt, (facts, goal)), |
62 relevance_override = {add = [], del = [], only = false}, |
60 relevance_override = {add = [], del = [], only = false}, |
63 axioms = SOME axioms} |
61 axioms = SOME axioms} |
64 val result as {outcome, used_thm_names, ...} = prover params (K "") problem |
62 val result as {outcome, used_thm_names, ...} = prover params (K "") problem |
65 in |
63 in |
66 priority (case outcome of |
64 priority (case outcome of |
67 NONE => |
65 NONE => |
68 if length used_thm_names = length name_thms_pairs then |
66 if length used_thm_names = length axioms then |
69 "Found proof." |
67 "Found proof." |
70 else |
68 else |
71 "Found proof with " ^ n_theorems used_thm_names ^ "." |
69 "Found proof with " ^ n_theorems used_thm_names ^ "." |
72 | SOME failure => string_for_failure failure); |
70 | SOME failure => string_for_failure failure); |
73 result |
71 result |
89 preprocessing time is included in the estimate below but isn't part of the |
87 preprocessing time is included in the estimate below but isn't part of the |
90 timeout. *) |
88 timeout. *) |
91 val fudge_msecs = 1000 |
89 val fudge_msecs = 1000 |
92 |
90 |
93 fun minimize_theorems {atps = [], ...} _ _ _ _ = error "No ATP is set." |
91 fun minimize_theorems {atps = [], ...} _ _ _ _ = error "No ATP is set." |
94 | minimize_theorems |
92 | minimize_theorems (params as {debug, atps = atp :: _, full_types, |
95 (params as {debug, atps = atp :: _, full_types, isar_proof, |
93 isar_proof, isar_shrink_factor, timeout, ...}) |
96 isar_shrink_factor, timeout, ...}) |
94 i n state axioms = |
97 i n state name_thms_pairs = |
|
98 let |
95 let |
99 val thy = Proof.theory_of state |
96 val thy = Proof.theory_of state |
100 val prover = get_prover_fun thy atp |
97 val prover = get_prover_fun thy atp |
101 val msecs = Time.toMilliseconds timeout |
98 val msecs = Time.toMilliseconds timeout |
102 val _ = priority ("Sledgehammer minimize: ATP " ^ quote atp ^ ".") |
99 val _ = priority ("Sledgehammer minimize: ATP " ^ quote atp ^ ".") |
103 val {context = ctxt, goal, ...} = Proof.goal state |
100 val {context = ctxt, goal, ...} = Proof.goal state |
104 val (_, hyp_ts, concl_t) = strip_subgoal goal i |
101 val (_, hyp_ts, concl_t) = strip_subgoal goal i |
105 val explicit_apply = |
102 val explicit_apply = |
106 not (forall (Meson.is_fol_term thy) |
103 not (forall (Meson.is_fol_term thy) |
107 (concl_t :: hyp_ts @ |
104 (concl_t :: hyp_ts @ maps (map prop_of o snd) axioms)) |
108 maps (map prop_of o snd) name_thms_pairs)) |
|
109 fun do_test timeout = |
105 fun do_test timeout = |
110 test_theorems params prover explicit_apply timeout i state |
106 test_theorems params prover explicit_apply timeout i state |
111 val timer = Timer.startRealTimer () |
107 val timer = Timer.startRealTimer () |
112 in |
108 in |
113 (case do_test timeout name_thms_pairs of |
109 (case do_test timeout axioms of |
114 result as {outcome = NONE, pool, used_thm_names, |
110 result as {outcome = NONE, pool, used_thm_names, |
115 conjecture_shape, ...} => |
111 conjecture_shape, ...} => |
116 let |
112 let |
117 val time = Timer.checkRealTimer timer |
113 val time = Timer.checkRealTimer timer |
118 val new_timeout = |
114 val new_timeout = |
119 Int.min (msecs, Time.toMilliseconds time + fudge_msecs) |
115 Int.min (msecs, Time.toMilliseconds time + fudge_msecs) |
120 |> Time.fromMilliseconds |
116 |> Time.fromMilliseconds |
121 val (min_thms, {proof, axiom_names, ...}) = |
117 val (min_thms, {proof, axiom_names, ...}) = |
122 sublinear_minimize (do_test new_timeout) |
118 sublinear_minimize (do_test new_timeout) |
123 (filter_used_facts used_thm_names name_thms_pairs) ([], result) |
119 (filter_used_facts used_thm_names axioms) ([], result) |
124 val n = length min_thms |
120 val n = length min_thms |
125 val _ = priority (cat_lines |
121 val _ = priority (cat_lines |
126 ["Minimized: " ^ string_of_int n ^ " theorem" ^ plural_s n] ^ |
122 ["Minimized: " ^ string_of_int n ^ " theorem" ^ plural_s n] ^ |
127 (case length (filter (snd o fst) min_thms) of |
123 (case length (filter (snd o fst) min_thms) of |
128 0 => "" |
124 0 => "" |
150 fun run_minimize params i refs state = |
146 fun run_minimize params i refs state = |
151 let |
147 let |
152 val ctxt = Proof.context_of state |
148 val ctxt = Proof.context_of state |
153 val reserved = reserved_isar_keyword_table () |
149 val reserved = reserved_isar_keyword_table () |
154 val chained_ths = #facts (Proof.goal state) |
150 val chained_ths = #facts (Proof.goal state) |
155 val name_thms_pairs = |
151 val axioms = |
156 map (apfst (fn f => f ()) |
152 maps (map (fn (name, (_, th)) => (name (), [th])) |
157 o name_thms_pair_from_ref ctxt reserved chained_ths) refs |
153 o name_thm_pairs_from_ref ctxt reserved chained_ths) refs |
158 in |
154 in |
159 case subgoal_count state of |
155 case subgoal_count state of |
160 0 => priority "No subgoal!" |
156 0 => priority "No subgoal!" |
161 | n => |
157 | n => |
162 (kill_atps (); |
158 (kill_atps (); priority (#2 (minimize_theorems params i n state axioms))) |
163 priority (#2 (minimize_theorems params i n state name_thms_pairs))) |
|
164 end |
159 end |
165 |
160 |
166 end; |
161 end; |