517 add_suffix (of_indent ind ^ "let ") |
517 add_suffix (of_indent ind ^ "let ") |
518 #> add_term t1 |
518 #> add_term t1 |
519 #> add_suffix " = " |
519 #> add_suffix " = " |
520 #> add_term t2 |
520 #> add_term t2 |
521 #> add_suffix "\n" |
521 #> add_suffix "\n" |
522 | add_step ind (Prove (qs, l, t, By_Metis (subproofs, facts))) = |
522 | add_step ind (Prove (qs, Fix xs, l, t, By_Metis (subproofs, facts))) = |
523 add_step_pre ind qs subproofs |
523 (case xs of |
524 #> add_suffix (of_prove qs (length subproofs) ^ " ") |
524 [] => (* have *) |
525 #> add_step_post ind l t facts "" |
525 add_step_pre ind qs subproofs |
526 | add_step ind (Obtain (qs, Fix xs, l, t, By_Metis (subproofs, facts))) = |
526 #> add_suffix (of_prove qs (length subproofs) ^ " ") |
527 add_step_pre ind qs subproofs |
527 #> add_step_post ind l t facts "" |
528 #> add_suffix (of_obtain qs (length subproofs) ^ " ") |
528 | _ => (* obtain *) |
529 #> add_frees xs |
529 add_step_pre ind qs subproofs |
530 #> add_suffix " where " |
530 #> add_suffix (of_obtain qs (length subproofs) ^ " ") |
531 (* The new skolemizer puts the arguments in the same order as the ATPs |
531 #> add_frees xs |
532 (E and Vampire -- but see also "atp_proof_reconstruct.ML" regarding |
532 #> add_suffix " where " |
533 Vampire). *) |
533 (* The new skolemizer puts the arguments in the same order as the |
534 #> add_step_post ind l t facts |
534 ATPs (E and Vampire -- but see also "atp_proof_reconstruct.ML" |
535 (if exists (fn (_, T) => length (binder_types T) > 1) xs then |
535 regarding Vampire). *) |
536 "using [[metis_new_skolem]] " |
536 #> add_step_post ind l t facts |
537 else |
537 (if exists (fn (_, T) => length (binder_types T) > 1) xs then |
538 "") |
538 "using [[metis_new_skolem]] " |
|
539 else |
|
540 "")) |
539 and add_steps ind = fold (add_step ind) |
541 and add_steps ind = fold (add_step ind) |
540 and of_proof ind ctxt (Proof (Fix xs, Assume assms, steps)) = |
542 and of_proof ind ctxt (Proof (Fix xs, Assume assms, steps)) = |
541 ("", ctxt) |
543 ("", ctxt) |
542 |> add_fix ind xs |
544 |> add_fix ind xs |
543 |> add_assms ind assms |
545 |> add_assms ind assms |
545 |> fst |
547 |> fst |
546 in |
548 in |
547 (* One-step proofs are pointless; better use the Metis one-liner |
549 (* One-step proofs are pointless; better use the Metis one-liner |
548 directly. *) |
550 directly. *) |
549 case proof of |
551 case proof of |
550 Proof (Fix [], Assume [], [Prove (_, _, _, By_Metis ([], _))]) => "" |
552 Proof (Fix [], Assume [], [Prove (_, Fix [], _, _, By_Metis ([], _))]) => "" |
551 | _ => (if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^ |
553 | _ => (if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^ |
552 of_indent 0 ^ "proof -\n" ^ of_proof 1 ctxt proof ^ |
554 of_indent 0 ^ "proof -\n" ^ of_proof 1 ctxt proof ^ |
553 of_indent 0 ^ (if n <> 1 then "next" else "qed") |
555 of_indent 0 ^ (if n <> 1 then "next" else "qed") |
554 end |
556 end |
555 |
557 |
563 fun kill_useless_labels_in_proof proof = |
565 fun kill_useless_labels_in_proof proof = |
564 let |
566 let |
565 val used_ls = add_labels_of_proof proof [] |
567 val used_ls = add_labels_of_proof proof [] |
566 fun do_label l = if member (op =) used_ls l then l else no_label |
568 fun do_label l = if member (op =) used_ls l then l else no_label |
567 fun do_assms (Assume assms) = Assume (map (apfst do_label) assms) |
569 fun do_assms (Assume assms) = Assume (map (apfst do_label) assms) |
568 fun do_step (Obtain (qs, xs, l, t, By_Metis (subproofs, facts))) = |
570 fun do_step (Prove (qs, xs, l, t, By_Metis (subproofs, facts))) = |
569 Obtain (qs, xs, do_label l, t, By_Metis (map do_proof subproofs, facts)) |
571 Prove (qs, xs, do_label l, t, By_Metis (map do_proof subproofs, facts)) |
570 | do_step (Prove (qs, l, t, By_Metis (subproofs, facts))) = |
|
571 Prove (qs, do_label l, t, By_Metis (map do_proof subproofs, facts)) |
|
572 | do_step step = step |
572 | do_step step = step |
573 and do_proof (Proof (fix, assms, steps)) = |
573 and do_proof (Proof (fix, assms, steps)) = |
574 Proof (fix, do_assms assms, map do_step steps) |
574 Proof (fix, do_assms assms, map do_step steps) |
575 in do_proof proof end |
575 in do_proof proof end |
576 |
576 |
597 fun do_assms subst depth (Assume assms) = |
597 fun do_assms subst depth (Assume assms) = |
598 fold_map (do_assm depth) assms (subst, 1) |
598 fold_map (do_assm depth) assms (subst, 1) |
599 |> apfst Assume |
599 |> apfst Assume |
600 |> apsnd fst |
600 |> apsnd fst |
601 fun do_steps _ _ _ [] = [] |
601 fun do_steps _ _ _ [] = [] |
602 | do_steps subst depth next (Obtain (qs, xs, l, t, by) :: steps) = |
602 | do_steps subst depth next (Prove (qs, xs, l, t, by) :: steps) = |
603 let |
603 let |
604 val (l, subst, next) = |
604 val (l, subst, next) = |
605 (l, subst, next) |> fresh_label depth have_prefix |
605 (l, subst, next) |> fresh_label depth have_prefix |
606 val by = by |> do_byline subst depth |
606 val by = by |> do_byline subst depth |
607 in Obtain (qs, xs, l, t, by) :: do_steps subst depth next steps end |
607 in Prove (qs, xs, l, t, by) :: do_steps subst depth next steps end |
608 | do_steps subst depth next (Prove (qs, l, t, by) :: steps) = |
|
609 let |
|
610 val (l, subst, next) = |
|
611 (l, subst, next) |> fresh_label depth have_prefix |
|
612 val by = by |> do_byline subst depth |
|
613 in Prove (qs, l, t, by) :: do_steps subst depth next steps end |
|
614 | do_steps subst depth next (step :: steps) = |
608 | do_steps subst depth next (step :: steps) = |
615 step :: do_steps subst depth next steps |
609 step :: do_steps subst depth next steps |
616 and do_proof subst depth (Proof (fix, assms, steps)) = |
610 and do_proof subst depth (Proof (fix, assms, steps)) = |
617 let val (assms, subst) = do_assms subst depth assms in |
611 let val (assms, subst) = do_assms subst depth assms in |
618 Proof (fix, assms, do_steps subst depth 1 steps) |
612 Proof (fix, assms, do_steps subst depth 1 steps) |
626 let |
620 let |
627 fun do_qs_lfs NONE lfs = ([], lfs) |
621 fun do_qs_lfs NONE lfs = ([], lfs) |
628 | do_qs_lfs (SOME l0) lfs = |
622 | do_qs_lfs (SOME l0) lfs = |
629 if member (op =) lfs l0 then ([Then], lfs |> remove (op =) l0) |
623 if member (op =) lfs l0 then ([Then], lfs |> remove (op =) l0) |
630 else ([], lfs) |
624 else ([], lfs) |
631 fun chain_step lbl (Obtain (qs, xs, l, t, |
625 fun chain_step lbl (Prove (qs, xs, l, t, |
632 By_Metis (subproofs, (lfs, gfs)))) = |
626 By_Metis (subproofs, (lfs, gfs)))) = |
633 let val (qs', lfs) = do_qs_lfs lbl lfs in |
627 let val (qs', lfs) = do_qs_lfs lbl lfs in |
634 Obtain (qs' @ qs, xs, l, t, |
628 Prove (qs' @ qs, xs, l, t, |
635 By_Metis (chain_proofs subproofs, (lfs, gfs))) |
629 By_Metis (chain_proofs subproofs, (lfs, gfs))) |
636 end |
630 end |
637 | chain_step lbl (Prove (qs, l, t, By_Metis (subproofs, (lfs, gfs)))) = |
|
638 let val (qs', lfs) = do_qs_lfs lbl lfs in |
|
639 Prove (qs' @ qs, l, t, By_Metis (chain_proofs subproofs, (lfs, gfs))) |
|
640 end |
|
641 | chain_step _ step = step |
631 | chain_step _ step = step |
642 and chain_steps _ [] = [] |
632 and chain_steps _ [] = [] |
643 | chain_steps (prev as SOME _) (i :: is) = |
633 | chain_steps (prev as SOME _) (i :: is) = |
644 chain_step prev i :: chain_steps (label_of_step i) is |
634 chain_step prev i :: chain_steps (label_of_step i) is |
645 | chain_steps _ (i :: is) = i :: chain_steps (label_of_step i) is |
635 | chain_steps _ (i :: is) = i :: chain_steps (label_of_step i) is |
752 fun skolems_of t = |
742 fun skolems_of t = |
753 Term.add_frees t [] |> filter_out (is_fixed o fst) |> rev |
743 Term.add_frees t [] |> filter_out (is_fixed o fst) |> rev |
754 fun do_steps outer predecessor accum [] = |
744 fun do_steps outer predecessor accum [] = |
755 accum |
745 accum |
756 |> (if tainted = [] then |
746 |> (if tainted = [] then |
757 cons (Prove (if outer then [Show] else [], no_label, |
747 cons (Prove (if outer then [Show] else [], |
758 concl_t, |
748 Fix [], no_label, concl_t, |
759 By_Metis ([], ([the predecessor], [])))) |
749 By_Metis ([], ([the predecessor], [])))) |
760 else |
750 else |
761 I) |
751 I) |
762 |> rev |
752 |> rev |
763 | do_steps outer _ accum (Have (gamma, c) :: infs) = |
753 | do_steps outer _ accum (Have (gamma, c) :: infs) = |
766 val t = prop_of_clause c |
756 val t = prop_of_clause c |
767 val by = |
757 val by = |
768 By_Metis ([], |
758 By_Metis ([], |
769 (fold (add_fact_of_dependencies fact_names) |
759 (fold (add_fact_of_dependencies fact_names) |
770 gamma no_facts)) |
760 gamma no_facts)) |
771 fun prove by = Prove (maybe_show outer c [], l, t, by) |
761 fun prove by = Prove (maybe_show outer c [], Fix [], l, t, by) |
772 fun do_rest l step = |
762 fun do_rest l step = |
773 do_steps outer (SOME l) (step :: accum) infs |
763 do_steps outer (SOME l) (step :: accum) infs |
774 in |
764 in |
775 if is_clause_tainted c then |
765 if is_clause_tainted c then |
776 case gamma of |
766 case gamma of |
788 else |
778 else |
789 do_rest l (prove by) |
779 do_rest l (prove by) |
790 | _ => do_rest l (prove by) |
780 | _ => do_rest l (prove by) |
791 else |
781 else |
792 if is_clause_skolemize_rule c then |
782 if is_clause_skolemize_rule c then |
793 do_rest l (Obtain ([], Fix (skolems_of t), l, t, by)) |
783 do_rest l (Prove ([], Fix (skolems_of t), l, t, by)) |
794 else |
784 else |
795 do_rest l (prove by) |
785 do_rest l (prove by) |
796 end |
786 end |
797 | do_steps outer predecessor accum (Cases cases :: infs) = |
787 | do_steps outer predecessor accum (Cases cases :: infs) = |
798 let |
788 let |
801 infs |
791 infs |
802 val c = succedent_of_cases cases |
792 val c = succedent_of_cases cases |
803 val l = label_of_clause c |
793 val l = label_of_clause c |
804 val t = prop_of_clause c |
794 val t = prop_of_clause c |
805 val step = |
795 val step = |
806 Prove (maybe_show outer c [], l, t, |
796 Prove (maybe_show outer c [], Fix [], l, t, |
807 By_Metis (map do_case cases, (the_list predecessor, []))) |
797 By_Metis (map do_case cases, (the_list predecessor, []))) |
808 in |
798 in |
809 do_steps outer (SOME l) (step :: accum) infs |
799 do_steps outer (SOME l) (step :: accum) infs |
810 end |
800 end |
811 and do_proof outer fix assms infs = |
801 and do_proof outer fix assms infs = |