14 val make_tvar: string -> typ |
14 val make_tvar: string -> typ |
15 val strip_prefix: string -> string -> string option |
15 val strip_prefix: string -> string -> string option |
16 val setup: Context.theory -> Context.theory |
16 val setup: Context.theory -> Context.theory |
17 (* extracting lemma list*) |
17 (* extracting lemma list*) |
18 val find_failure: string -> string option |
18 val find_failure: string -> string option |
19 val lemma_list_dfg: string * string vector * Proof.context * Thm.thm * int -> string |
19 val lemma_list_dfg: string -> string * string vector * Proof.context * Thm.thm * int -> string |
20 val lemma_list_tstp: string * string vector * Proof.context * Thm.thm * int -> string |
20 val lemma_list_tstp: string -> string * string vector * Proof.context * Thm.thm * int -> string |
21 (* structured proofs *) |
21 (* structured proofs *) |
22 val structured_proof: string * string vector * Proof.context * Thm.thm * int -> string |
22 val structured_proof: string -> string * string vector * Proof.context * Thm.thm * int -> string |
23 end; |
23 end; |
24 |
24 |
25 structure ResReconstruct : RES_RECONSTRUCT = |
25 structure ResReconstruct : RES_RECONSTRUCT = |
26 struct |
26 struct |
27 |
27 |
512 | inputno _ = NONE |
512 | inputno _ = NONE |
513 val lines = split_lines proofextract |
513 val lines = split_lines proofextract |
514 in List.mapPartial (inputno o toks) lines end |
514 in List.mapPartial (inputno o toks) lines end |
515 |
515 |
516 (*extracting lemmas from tstp-output between the lines from above*) |
516 (*extracting lemmas from tstp-output between the lines from above*) |
517 fun extract_lemmas get_step_nums (proof, thm_names, _, _, _) = |
517 fun extract_lemmas get_step_nums (proof, thm_names, _, _, _) = |
518 let |
518 let |
519 (* get the names of axioms from their numbers*) |
519 (* get the names of axioms from their numbers*) |
520 fun get_axiom_names thm_names step_nums = |
520 fun get_axiom_names thm_names step_nums = |
521 let |
521 let |
522 fun is_axiom n = n <= Vector.length thm_names |
522 fun is_axiom n = n <= Vector.length thm_names |
530 end; |
530 end; |
531 |
531 |
532 (* metis-command *) |
532 (* metis-command *) |
533 fun metis_line [] = "apply metis" |
533 fun metis_line [] = "apply metis" |
534 | metis_line xs = "apply (metis " ^ space_implode " " xs ^ ")" |
534 | metis_line xs = "apply (metis " ^ space_implode " " xs ^ ")" |
|
535 |
|
536 (* atp_minimize [atp=<prover>] <lemmas> *) |
|
537 fun minimize_line _ [] = "" |
|
538 | minimize_line name lemmas = "For minimizing the number of lemmas try this command:\n" ^ |
|
539 (Markup.markup Markup.sendback) ("atp_minimize [atp=" ^ name ^ "] " ^ space_implode " " lemmas) |
535 |
540 |
536 (*Used to label theorems chained into the sledgehammer call*) |
541 (*Used to label theorems chained into the sledgehammer call*) |
537 val chained_hint = "CHAINED"; |
542 val chained_hint = "CHAINED"; |
538 fun sendback_metis_nochained lemmas = |
543 fun sendback_metis_nochained lemmas = |
539 let val nochained = filter_out (fn y => y = chained_hint) |
544 let val nochained = filter_out (fn y => y = chained_hint) |
540 in (Markup.markup Markup.sendback o metis_line) (nochained lemmas) end |
545 in (Markup.markup Markup.sendback o metis_line) (nochained lemmas) end |
541 fun lemma_list_tstp result = sendback_metis_nochained (extract_lemmas get_step_nums_tstp result); |
546 fun lemma_list_tstp name result = |
542 fun lemma_list_dfg result = sendback_metis_nochained (extract_lemmas get_step_nums_dfg result); |
547 let val lemmas = extract_lemmas get_step_nums_tstp result |
543 |
548 in sendback_metis_nochained lemmas ^ "\n" ^ minimize_line name lemmas end; |
|
549 fun lemma_list_dfg name result = |
|
550 let val lemmas = extract_lemmas get_step_nums_dfg result |
|
551 in sendback_metis_nochained lemmas ^ "\n" ^ minimize_line name lemmas end; |
|
552 |
544 (* === Extracting structured Isar-proof === *) |
553 (* === Extracting structured Isar-proof === *) |
545 fun structured_proof (result as (proof, thm_names, ctxt, goal, subgoalno)) = |
554 fun structured_proof name (result as (proof, thm_names, ctxt, goal, subgoalno)) = |
546 let |
555 let |
547 (*Could use split_lines, but it can return blank lines...*) |
556 (*Could use split_lines, but it can return blank lines...*) |
548 val lines = String.tokens (equal #"\n"); |
557 val lines = String.tokens (equal #"\n"); |
549 val nospaces = String.translate (fn c => if Char.isSpace c then "" else str c) |
558 val nospaces = String.translate (fn c => if Char.isSpace c then "" else str c) |
550 val proofextract = get_proof_extract proof |
559 val proofextract = get_proof_extract proof |
551 val cnfs = filter (String.isPrefix "cnf(") (map nospaces (lines proofextract)) |
560 val cnfs = filter (String.isPrefix "cnf(") (map nospaces (lines proofextract)) |
552 val one_line_proof = lemma_list_tstp result |
561 val one_line_proof = lemma_list_tstp name result |
553 val structured = if chained_hint mem_string (String.tokens (fn c => c = #" ") one_line_proof) then "" |
562 val structured = if chained_hint mem_string (String.tokens (fn c => c = #" ") one_line_proof) then "" |
554 else decode_tstp_file cnfs ctxt goal subgoalno thm_names |
563 else decode_tstp_file cnfs ctxt goal subgoalno thm_names |
555 in |
564 in |
556 one_line_proof ^ "\n\n" ^ (Markup.markup Markup.sendback) structured |
565 one_line_proof ^ "\n\n" ^ (Markup.markup Markup.sendback) structured |
557 end |
566 end |