50 val is_typed_helper_used_in_atp_proof : string proof -> bool |
50 val is_typed_helper_used_in_atp_proof : string proof -> bool |
51 val used_facts_in_unsound_atp_proof : |
51 val used_facts_in_unsound_atp_proof : |
52 Proof.context -> (string * stature) list vector -> 'a proof |
52 Proof.context -> (string * stature) list vector -> 'a proof |
53 -> string list option |
53 -> string list option |
54 val unalias_type_enc : string -> string list |
54 val unalias_type_enc : string -> string list |
55 val one_line_proof_text : one_line_params -> string |
55 val one_line_proof_text : int -> one_line_params -> string |
56 val make_tvar : string -> typ |
56 val make_tvar : string -> typ |
57 val make_tfree : Proof.context -> string -> typ |
57 val make_tfree : Proof.context -> string -> typ |
58 val term_from_atp : |
58 val term_from_atp : |
59 Proof.context -> bool -> int Symtab.table -> typ option |
59 Proof.context -> bool -> int Symtab.table -> typ option |
60 -> (string, string) ho_term -> term |
60 -> (string, string) ho_term -> term |
62 Proof.context -> bool -> int Symtab.table |
62 Proof.context -> bool -> int Symtab.table |
63 -> (string, string, (string, string) ho_term, string) formula -> term |
63 -> (string, string, (string, string) ho_term, string) formula -> term |
64 val isar_proof_text : |
64 val isar_proof_text : |
65 Proof.context -> bool -> isar_params -> one_line_params -> string |
65 Proof.context -> bool -> isar_params -> one_line_params -> string |
66 val proof_text : |
66 val proof_text : |
67 Proof.context -> bool -> isar_params -> one_line_params -> string |
67 Proof.context -> bool -> isar_params -> int -> one_line_params -> string |
68 end; |
68 end; |
69 |
69 |
70 structure ATP_Proof_Reconstruct : ATP_PROOF_RECONSTRUCT = |
70 structure ATP_Proof_Reconstruct : ATP_PROOF_RECONSTRUCT = |
71 struct |
71 struct |
72 |
72 |
248 fun string_for_label (s, num) = s ^ string_of_int num |
248 fun string_for_label (s, num) = s ^ string_of_int num |
249 |
249 |
250 fun show_time NONE = "" |
250 fun show_time NONE = "" |
251 | show_time (SOME ext_time) = " (" ^ string_from_ext_time ext_time ^ ")" |
251 | show_time (SOME ext_time) = " (" ^ string_from_ext_time ext_time ^ ")" |
252 |
252 |
|
253 fun unusing_chained_facts _ 0 = "" |
|
254 | unusing_chained_facts used_chaineds num_chained = |
|
255 if length used_chaineds = num_chained then "" |
|
256 else if null used_chaineds then "(* using no facts *) " |
|
257 else "(* using only " ^ space_implode " " used_chaineds ^ " *) " |
|
258 |
253 fun apply_on_subgoal _ 1 = "by " |
259 fun apply_on_subgoal _ 1 = "by " |
254 | apply_on_subgoal 1 _ = "apply " |
260 | apply_on_subgoal 1 _ = "apply " |
255 | apply_on_subgoal i n = |
261 | apply_on_subgoal i n = |
256 "prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n |
262 "prefer " ^ string_of_int i ^ " " ^ apply_on_subgoal 1 n |
|
263 |
257 fun command_call name [] = |
264 fun command_call name [] = |
258 name |> not (Lexicon.is_identifier name) ? enclose "(" ")" |
265 name |> not (Lexicon.is_identifier name) ? enclose "(" ")" |
259 | command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")" |
266 | command_call name args = "(" ^ name ^ " " ^ space_implode " " args ^ ")" |
|
267 |
260 fun try_command_line banner time command = |
268 fun try_command_line banner time command = |
261 banner ^ ": " ^ Markup.markup Isabelle_Markup.sendback command ^ show_time time ^ "." |
269 banner ^ ": " ^ Markup.markup Isabelle_Markup.sendback command ^ show_time time ^ "." |
|
270 |
262 fun using_labels [] = "" |
271 fun using_labels [] = "" |
263 | using_labels ls = |
272 | using_labels ls = |
264 "using " ^ space_implode " " (map string_for_label ls) ^ " " |
273 "using " ^ space_implode " " (map string_for_label ls) ^ " " |
265 fun reconstructor_command reconstr i n (ls, ss) = |
274 |
|
275 fun reconstructor_command reconstr i n used_chaineds num_chained (ls, ss) = |
|
276 unusing_chained_facts used_chaineds num_chained ^ |
266 using_labels ls ^ apply_on_subgoal i n ^ |
277 using_labels ls ^ apply_on_subgoal i n ^ |
267 command_call (string_for_reconstructor reconstr) ss |
278 command_call (string_for_reconstructor reconstr) ss |
|
279 |
268 fun minimize_line _ [] = "" |
280 fun minimize_line _ [] = "" |
269 | minimize_line minimize_command ss = |
281 | minimize_line minimize_command ss = |
270 case minimize_command ss of |
282 case minimize_command ss of |
271 "" => "" |
283 "" => "" |
272 | command => |
284 | command => |
274 |
286 |
275 fun split_used_facts facts = |
287 fun split_used_facts facts = |
276 facts |> List.partition (fn (_, (sc, _)) => sc = Chained) |
288 facts |> List.partition (fn (_, (sc, _)) => sc = Chained) |
277 |> pairself (sort_distinct (string_ord o pairself fst)) |
289 |> pairself (sort_distinct (string_ord o pairself fst)) |
278 |
290 |
279 fun one_line_proof_text (preplay, banner, used_facts, minimize_command, |
291 fun one_line_proof_text num_chained |
280 subgoal, subgoal_count) = |
292 (preplay, banner, used_facts, minimize_command, subgoal, |
|
293 subgoal_count) = |
281 let |
294 let |
282 val (chained, extra) = split_used_facts used_facts |
295 val (chained, extra) = split_used_facts used_facts |
283 val (failed, reconstr, ext_time) = |
296 val (failed, reconstr, ext_time) = |
284 case preplay of |
297 case preplay of |
285 Played (reconstr, time) => (false, reconstr, (SOME (false, time))) |
298 Played (reconstr, time) => (false, reconstr, (SOME (false, time))) |
290 | SOME time => |
303 | SOME time => |
291 if time = Time.zeroTime then NONE else SOME (true, time)) |
304 if time = Time.zeroTime then NONE else SOME (true, time)) |
292 | Failed_to_Play reconstr => (true, reconstr, NONE) |
305 | Failed_to_Play reconstr => (true, reconstr, NONE) |
293 val try_line = |
306 val try_line = |
294 ([], map fst extra) |
307 ([], map fst extra) |
295 |> reconstructor_command reconstr subgoal subgoal_count |
308 |> reconstructor_command reconstr subgoal subgoal_count (map fst chained) |
|
309 num_chained |
296 |> (if failed then |
310 |> (if failed then |
297 enclose "One-line proof reconstruction failed: " |
311 enclose "One-line proof reconstruction failed: " |
298 ".\n(Invoking \"sledgehammer\" with \"[strict]\" might \ |
312 ".\n(Invoking \"sledgehammer\" with \"[strict]\" might \ |
299 \solve this.)" |
313 \solve this.)" |
300 else |
314 else |
843 else |
857 else |
844 if member (op =) qs Show then "show" else "have") |
858 if member (op =) qs Show then "show" else "have") |
845 val do_term = maybe_quote o fix_print_mode (Syntax.string_of_term ctxt) |
859 val do_term = maybe_quote o fix_print_mode (Syntax.string_of_term ctxt) |
846 val reconstr = Metis (type_enc, lam_trans) |
860 val reconstr = Metis (type_enc, lam_trans) |
847 fun do_facts (ls, ss) = |
861 fun do_facts (ls, ss) = |
848 reconstructor_command reconstr 1 1 |
862 reconstructor_command reconstr 1 1 [] 0 |
849 (ls |> sort_distinct (prod_ord string_ord int_ord), |
863 (ls |> sort_distinct (prod_ord string_ord int_ord), |
850 ss |> sort_distinct string_ord) |
864 ss |> sort_distinct string_ord) |
851 and do_step ind (Fix xs) = |
865 and do_step ind (Fix xs) = |
852 do_indent ind ^ "fix " ^ space_implode " and " (map do_free xs) ^ "\n" |
866 do_indent ind ^ "fix " ^ space_implode " and " (map do_free xs) ^ "\n" |
853 | do_step ind (Let (t1, t2)) = |
867 | do_step ind (Let (t1, t2)) = |
885 let |
899 let |
886 val isar_shrink_factor = |
900 val isar_shrink_factor = |
887 (if isar_proof_requested then 1 else 2) * isar_shrink_factor |
901 (if isar_proof_requested then 1 else 2) * isar_shrink_factor |
888 val (params, hyp_ts, concl_t) = strip_subgoal ctxt goal subgoal |
902 val (params, hyp_ts, concl_t) = strip_subgoal ctxt goal subgoal |
889 val frees = fold Term.add_frees (concl_t :: hyp_ts) [] |
903 val frees = fold Term.add_frees (concl_t :: hyp_ts) [] |
890 val one_line_proof = one_line_proof_text one_line_params |
904 val one_line_proof = one_line_proof_text 0 one_line_params |
891 val type_enc = |
905 val type_enc = |
892 if is_typed_helper_used_in_atp_proof atp_proof then full_typesN |
906 if is_typed_helper_used_in_atp_proof atp_proof then full_typesN |
893 else partial_typesN |
907 else partial_typesN |
894 val lam_trans = lam_trans_from_atp_proof atp_proof metis_default_lam_trans |
908 val lam_trans = lam_trans_from_atp_proof atp_proof metis_default_lam_trans |
895 |
909 |
980 "\nWarning: The Isar proof construction failed." |
994 "\nWarning: The Isar proof construction failed." |
981 else |
995 else |
982 "" |
996 "" |
983 in one_line_proof ^ isar_proof end |
997 in one_line_proof ^ isar_proof end |
984 |
998 |
985 fun proof_text ctxt isar_proof isar_params |
999 fun proof_text ctxt isar_proof isar_params num_chained |
986 (one_line_params as (preplay, _, _, _, _, _)) = |
1000 (one_line_params as (preplay, _, _, _, _, _)) = |
987 (if case preplay of Failed_to_Play _ => true | _ => isar_proof then |
1001 (if case preplay of Failed_to_Play _ => true | _ => isar_proof then |
988 isar_proof_text ctxt isar_proof isar_params |
1002 isar_proof_text ctxt isar_proof isar_params |
989 else |
1003 else |
990 one_line_proof_text) one_line_params |
1004 one_line_proof_text num_chained) one_line_params |
991 |
1005 |
992 end; |
1006 end; |