366 fun add_type_constraint (false, cl, TFree (a ,_)) = add_var ((a, ~1), cl) |
366 fun add_type_constraint (false, cl, TFree (a ,_)) = add_var ((a, ~1), cl) |
367 | add_type_constraint (false, cl, TVar (ix, _)) = add_var (ix, cl) |
367 | add_type_constraint (false, cl, TVar (ix, _)) = add_var (ix, cl) |
368 | add_type_constraint _ = I |
368 | add_type_constraint _ = I |
369 |
369 |
370 fun is_positive_literal (@{const Not} $ _) = false |
370 fun is_positive_literal (@{const Not} $ _) = false |
371 | is_positive_literal t = true |
371 | is_positive_literal _ = true |
372 |
372 |
373 fun negate_term thy (Const (@{const_name All}, T) $ Abs (s, T', t')) = |
373 fun negate_term thy (Const (@{const_name All}, T) $ Abs (s, T', t')) = |
374 Const (@{const_name Ex}, T) $ Abs (s, T', negate_term thy t') |
374 Const (@{const_name Ex}, T) $ Abs (s, T', negate_term thy t') |
375 | negate_term thy (Const (@{const_name Ex}, T) $ Abs (s, T', t')) = |
375 | negate_term thy (Const (@{const_name Ex}, T) $ Abs (s, T', t')) = |
376 Const (@{const_name All}, T) $ Abs (s, T', negate_term thy t') |
376 Const (@{const_name All}, T) $ Abs (s, T', negate_term thy t') |
549 | is_bad_free _ _ = false |
549 | is_bad_free _ _ = false |
550 |
550 |
551 (* Vampire is keen on producing these. *) |
551 (* Vampire is keen on producing these. *) |
552 fun is_trivial_formula (@{const Not} $ (Const (@{const_name "op ="}, _) |
552 fun is_trivial_formula (@{const Not} $ (Const (@{const_name "op ="}, _) |
553 $ t1 $ t2)) = (t1 aconv t2) |
553 $ t1 $ t2)) = (t1 aconv t2) |
554 | is_trivial_formula t = false |
554 | is_trivial_formula _ = false |
555 |
555 |
556 fun add_desired_line _ _ _ _ _ (line as Definition (num, _, _)) (j, lines) = |
556 fun add_desired_line _ _ _ _ (line as Definition (num, _, _)) (j, lines) = |
557 (j, line :: map (replace_deps_in_line (num, [])) lines) |
557 (j, line :: map (replace_deps_in_line (num, [])) lines) |
558 | add_desired_line ctxt isar_shrink_factor conjecture_shape thm_names frees |
558 | add_desired_line isar_shrink_factor conjecture_shape thm_names frees |
559 (Inference (num, t, deps)) (j, lines) = |
559 (Inference (num, t, deps)) (j, lines) = |
560 (j + 1, |
560 (j + 1, |
561 if is_axiom_clause_number thm_names num orelse |
561 if is_axiom_clause_number thm_names num orelse |
562 is_conjecture_clause_number conjecture_shape num orelse |
562 is_conjecture_clause_number conjecture_shape num orelse |
563 (not (is_only_type_information t) andalso |
563 (not (is_only_type_information t) andalso |
665 else |
665 else |
666 apfst (insert (op =) (raw_prefix, num)) |
666 apfst (insert (op =) (raw_prefix, num)) |
667 |
667 |
668 fun forall_vars t = fold_rev forall_of (map Var (Term.add_vars t [])) t |
668 fun forall_vars t = fold_rev forall_of (map Var (Term.add_vars t [])) t |
669 |
669 |
670 fun step_for_line _ _ (Definition (num, t1, t2)) = Let (t1, t2) |
670 fun step_for_line _ _ (Definition (_, t1, t2)) = Let (t1, t2) |
671 | step_for_line _ _ (Inference (num, t, [])) = Assume ((raw_prefix, num), t) |
671 | step_for_line _ _ (Inference (num, t, [])) = Assume ((raw_prefix, num), t) |
672 | step_for_line thm_names j (Inference (num, t, deps)) = |
672 | step_for_line thm_names j (Inference (num, t, deps)) = |
673 Have (if j = 1 then [Show] else [], (raw_prefix, num), |
673 Have (if j = 1 then [Show] else [], (raw_prefix, num), |
674 forall_vars t, |
674 forall_vars t, |
675 ByMetis (fold (add_fact_from_dep thm_names) deps ([], []))) |
675 ByMetis (fold (add_fact_from_dep thm_names) deps ([], []))) |
681 atp_proof ^ "$" (* the $ sign acts as a sentinel *) |
681 atp_proof ^ "$" (* the $ sign acts as a sentinel *) |
682 |> parse_proof pool |
682 |> parse_proof pool |
683 |> decode_lines ctxt full_types tfrees |
683 |> decode_lines ctxt full_types tfrees |
684 |> rpair [] |-> fold_rev (add_line conjecture_shape thm_names) |
684 |> rpair [] |-> fold_rev (add_line conjecture_shape thm_names) |
685 |> rpair [] |-> fold_rev add_nontrivial_line |
685 |> rpair [] |-> fold_rev add_nontrivial_line |
686 |> rpair (0, []) |-> fold_rev (add_desired_line ctxt isar_shrink_factor |
686 |> rpair (0, []) |-> fold_rev (add_desired_line isar_shrink_factor |
687 conjecture_shape thm_names frees) |
687 conjecture_shape thm_names frees) |
688 |> snd |
688 |> snd |
689 in |
689 in |
690 (if null params then [] else [Fix params]) @ |
690 (if null params then [] else [Fix params]) @ |
691 map2 (step_for_line thm_names) (length lines downto 1) lines |
691 map2 (step_for_line thm_names) (length lines downto 1) lines |
720 if exists null proofs then |
720 if exists null proofs then |
721 NONE |
721 NONE |
722 else if forall (curry (op =) (hd proof1) o hd) (tl proofs) then |
722 else if forall (curry (op =) (hd proof1) o hd) (tl proofs) then |
723 aux (hd proof1 :: proof_tail) (map tl proofs) |
723 aux (hd proof1 :: proof_tail) (map tl proofs) |
724 else case hd proof1 of |
724 else case hd proof1 of |
725 Have ([], l, t, by) => |
725 Have ([], l, t, _) => (* FIXME: should we really ignore the "by"? *) |
726 if forall (fn Have ([], l', t', _) :: _ => (l, t) = (l', t') |
726 if forall (fn Have ([], l', t', _) :: _ => (l, t) = (l', t') |
727 | _ => false) (tl proofs) andalso |
727 | _ => false) (tl proofs) andalso |
728 not (exists (member (op =) (maps new_labels_of proofs)) |
728 not (exists (member (op =) (maps new_labels_of proofs)) |
729 (used_labels_of proof_tail)) then |
729 (used_labels_of proof_tail)) then |
730 SOME (l, t, map rev proofs, proof_tail) |
730 SOME (l, t, map rev proofs, proof_tail) |
753 fun first_pass ([], contra) = ([], contra) |
753 fun first_pass ([], contra) = ([], contra) |
754 | first_pass ((step as Fix _) :: proof, contra) = |
754 | first_pass ((step as Fix _) :: proof, contra) = |
755 first_pass (proof, contra) |>> cons step |
755 first_pass (proof, contra) |>> cons step |
756 | first_pass ((step as Let _) :: proof, contra) = |
756 | first_pass ((step as Let _) :: proof, contra) = |
757 first_pass (proof, contra) |>> cons step |
757 first_pass (proof, contra) |>> cons step |
758 | first_pass ((step as Assume (l as (_, num), t)) :: proof, contra) = |
758 | first_pass ((step as Assume (l as (_, num), _)) :: proof, contra) = |
759 if member (op =) concl_ls l then |
759 if member (op =) concl_ls l then |
760 first_pass (proof, contra ||> l = hd concl_ls ? cons step) |
760 first_pass (proof, contra ||> l = hd concl_ls ? cons step) |
761 else |
761 else |
762 first_pass (proof, contra) |>> cons (Assume (l, find_hyp num)) |
762 first_pass (proof, contra) |>> cons (Assume (l, find_hyp num)) |
763 | first_pass (Have (qs, l, t, ByMetis (ls, ss)) :: proof, contra) = |
763 | first_pass (Have (qs, l, t, ByMetis (ls, ss)) :: proof, contra) = |
990 do_indent 0 ^ "proof -\n" ^ |
990 do_indent 0 ^ "proof -\n" ^ |
991 do_steps "" "" 1 proof ^ |
991 do_steps "" "" 1 proof ^ |
992 do_indent 0 ^ (if n <> 1 then "next" else "qed") ^ "\n" |
992 do_indent 0 ^ (if n <> 1 then "next" else "qed") ^ "\n" |
993 in do_proof end |
993 in do_proof end |
994 |
994 |
|
995 fun strip_subgoal goal i = |
|
996 let |
|
997 val (t, frees) = Logic.goal_params (prop_of goal) i |
|
998 val hyp_ts = t |> Logic.strip_assums_hyp |> map (curry subst_bounds frees) |
|
999 val concl_t = t |> Logic.strip_assums_concl |> curry subst_bounds frees |
|
1000 in (rev (map dest_Free frees), hyp_ts, concl_t) end |
|
1001 |
995 fun isar_proof_text (pool, debug, isar_shrink_factor, ctxt, conjecture_shape) |
1002 fun isar_proof_text (pool, debug, isar_shrink_factor, ctxt, conjecture_shape) |
996 (other_params as (full_types, _, atp_proof, thm_names, goal, |
1003 (other_params as (full_types, _, atp_proof, thm_names, goal, |
997 i)) = |
1004 i)) = |
998 let |
1005 let |
999 val thy = ProofContext.theory_of ctxt |
1006 val thy = ProofContext.theory_of ctxt |