431 | is_bad_free _ _ = false |
431 | is_bad_free _ _ = false |
432 |
432 |
433 val e_skolemize_rule = "skolemize" |
433 val e_skolemize_rule = "skolemize" |
434 val vampire_skolemisation_rule = "skolemisation" |
434 val vampire_skolemisation_rule = "skolemisation" |
435 |
435 |
|
436 val is_skolemize_rule = |
|
437 member (op =) [e_skolemize_rule, vampire_skolemisation_rule] |
|
438 |
436 fun add_desired_line _ _ (line as Definition_Step (name, _, _)) (j, lines) = |
439 fun add_desired_line _ _ (line as Definition_Step (name, _, _)) (j, lines) = |
437 (j, line :: map (replace_dependencies_in_line (name, [])) lines) |
440 (j, line :: map (replace_dependencies_in_line (name, [])) lines) |
438 | add_desired_line fact_names frees |
441 | add_desired_line fact_names frees |
439 (Inference_Step (name as (_, ss), role, t, rule, deps)) (j, lines) = |
442 (Inference_Step (name as (_, ss), role, t, rule, deps)) (j, lines) = |
440 (j + 1, |
443 (j + 1, |
441 if is_fact fact_names ss orelse |
444 if is_fact fact_names ss orelse |
442 is_conjecture ss orelse |
445 is_conjecture ss orelse |
443 rule = vampire_skolemisation_rule orelse |
446 is_skolemize_rule rule orelse |
444 rule = e_skolemize_rule orelse |
|
445 (* the last line must be kept *) |
447 (* the last line must be kept *) |
446 j = 0 orelse |
448 j = 0 orelse |
447 (not (is_only_type_information t) andalso |
449 (not (is_only_type_information t) andalso |
448 null (Term.add_tvars t []) andalso |
450 null (Term.add_tvars t []) andalso |
449 not (exists_subterm (is_bad_free frees) t) andalso |
451 not (exists_subterm (is_bad_free frees) t) andalso |
671 | dep_of_step (Inference_Step (name, _, _, _, from)) = |
673 | dep_of_step (Inference_Step (name, _, _, _, from)) = |
672 SOME (from, name) |
674 SOME (from, name) |
673 val ref_graph = atp_proof |> map_filter dep_of_step |> make_ref_graph |
675 val ref_graph = atp_proof |> map_filter dep_of_step |> make_ref_graph |
674 val axioms = axioms_of_ref_graph ref_graph conjs |
676 val axioms = axioms_of_ref_graph ref_graph conjs |
675 val tainted = tainted_atoms_of_ref_graph ref_graph conjs |
677 val tainted = tainted_atoms_of_ref_graph ref_graph conjs |
676 val is_skolem = can (apfst (apfst Name.dest_skolem)) |
678 val steps = |
677 val props = |
|
678 Symtab.empty |
679 Symtab.empty |
679 |> fold (fn Definition_Step _ => I (* FIXME *) |
680 |> fold (fn Definition_Step _ => I (* FIXME *) |
680 | Inference_Step (name as (s, ss), role, t, _, _) => |
681 | Inference_Step (name as (s, ss), role, t, rule, _) => |
681 Symtab.update_new (s, |
682 Symtab.update_new (s, (rule, |
682 if member (op = o apsnd fst) tainted s then |
683 t |> (if member (op = o apsnd fst) tainted s then |
683 t |> role <> Conjecture ? s_not |
684 (role <> Conjecture ? s_not) |
684 |> fold exists_of (map Var (Term.add_vars t [])) |
685 #> fold exists_of (map Var (Term.add_vars t [])) |
685 else |
686 else |
686 t |> fold exists_of (map Var (filter is_skolem |
687 I)))) |
687 (Term.add_vars t []))))) |
|
688 atp_proof |
688 atp_proof |
|
689 fun is_clause_skolemize_rule [(s, _)] = |
|
690 Option.map (is_skolemize_rule o fst) (Symtab.lookup steps s) = |
|
691 SOME true |
|
692 | is_clause_skolemize_rule _ = false |
689 (* The assumptions and conjecture are "prop"s; the other formulas are |
693 (* The assumptions and conjecture are "prop"s; the other formulas are |
690 "bool"s. *) |
694 "bool"s. *) |
691 fun prop_of_clause [name as (s, ss)] = |
695 fun prop_of_clause [name as (s, ss)] = |
692 (case resolve_conjecture ss of |
696 (case resolve_conjecture ss of |
693 [j] => if j = length hyp_ts then concl_t else nth hyp_ts j |
697 [j] => if j = length hyp_ts then concl_t else nth hyp_ts j |
694 | _ => the_default @{term False} (Symtab.lookup props s) |
698 | _ => the_default ("", @{term False}) (Symtab.lookup steps s) |
695 |> HOLogic.mk_Trueprop |> close_form) |
699 |> snd |> HOLogic.mk_Trueprop |> close_form) |
696 | prop_of_clause names = |
700 | prop_of_clause names = |
697 let val lits = map_filter (Symtab.lookup props o fst) names in |
701 let |
|
702 val lits = map snd (map_filter (Symtab.lookup steps o fst) names) |
|
703 in |
698 case List.partition (can HOLogic.dest_not) lits of |
704 case List.partition (can HOLogic.dest_not) lits of |
699 (negs as _ :: _, pos as _ :: _) => |
705 (negs as _ :: _, pos as _ :: _) => |
700 HOLogic.mk_imp |
706 HOLogic.mk_imp |
701 (Library.foldr1 s_conj (map HOLogic.dest_not negs), |
707 (Library.foldr1 s_conj (map HOLogic.dest_not negs), |
702 Library.foldr1 s_disj pos) |
708 Library.foldr1 s_disj pos) |
705 |> HOLogic.mk_Trueprop |> close_form |
711 |> HOLogic.mk_Trueprop |> close_form |
706 fun maybe_show outer c = |
712 fun maybe_show outer c = |
707 (outer andalso length c = 1 andalso subset (op =) (c, conjs)) |
713 (outer andalso length c = 1 andalso subset (op =) (c, conjs)) |
708 ? cons Show |
714 ? cons Show |
709 fun isar_step_of_direct_inf outer (Have (gamma, c)) = |
715 fun isar_step_of_direct_inf outer (Have (gamma, c)) = |
710 Prove (maybe_show outer c [], label_of_clause c, prop_of_clause c, |
716 let |
711 By_Metis (fold (add_fact_from_dependencies fact_names) gamma |
717 val l = label_of_clause c |
712 ([], []))) |
718 val t = prop_of_clause c |
|
719 val by = |
|
720 By_Metis (fold (add_fact_from_dependencies fact_names) gamma |
|
721 ([], [])) |
|
722 in |
|
723 if is_clause_skolemize_rule c then |
|
724 let |
|
725 val xs = |
|
726 Term.add_frees t [] |
|
727 |> filter_out (Variable.is_declared ctxt o fst) |
|
728 in Obtain ([], xs, l, t, by) end |
|
729 else |
|
730 Prove (maybe_show outer c [], l, t, by) |
|
731 end |
713 | isar_step_of_direct_inf outer (Cases cases) = |
732 | isar_step_of_direct_inf outer (Cases cases) = |
714 let val c = succedent_of_cases cases in |
733 let val c = succedent_of_cases cases in |
715 Prove (maybe_show outer c [Ultimately], label_of_clause c, |
734 Prove (maybe_show outer c [Ultimately], label_of_clause c, |
716 prop_of_clause c, |
735 prop_of_clause c, |
717 Case_Split (map (do_case false) cases, ([], []))) |
736 Case_Split (map (do_case false) cases, ([], []))) |