616 No_Type_Args |
616 No_Type_Args |
617 else |
617 else |
618 general_type_arg_policy type_sys |
618 general_type_arg_policy type_sys |
619 |
619 |
620 (*Make literals for sorted type variables*) |
620 (*Make literals for sorted type variables*) |
621 fun sorts_on_typs_aux (_, []) = [] |
621 fun generic_sorts_on_type (_, []) = [] |
622 | sorts_on_typs_aux ((x, i), s :: ss) = |
622 | generic_sorts_on_type ((x, i), s :: ss) = |
623 sorts_on_typs_aux ((x, i), ss) |
623 generic_sorts_on_type ((x, i), ss) |
624 |> (if s = the_single @{sort HOL.type} then |
624 |> (if s = the_single @{sort HOL.type} then |
625 I |
625 I |
626 else if i = ~1 then |
626 else if i = ~1 then |
627 cons (TyLitFree (`make_type_class s, `make_fixed_type_var x)) |
627 cons (TyLitFree (`make_type_class s, `make_fixed_type_var x)) |
628 else |
628 else |
629 cons (TyLitVar (`make_type_class s, |
629 cons (TyLitVar (`make_type_class s, |
630 (make_schematic_type_var (x, i), x)))) |
630 (make_schematic_type_var (x, i), x)))) |
631 |
631 fun sorts_on_tfree (TFree (s, S)) = generic_sorts_on_type ((s, ~1), S) |
632 fun sorts_on_typs (TFree (a, s)) = sorts_on_typs_aux ((a, ~1), s) |
632 | sorts_on_tfree _ = [] |
633 | sorts_on_typs (TVar (v, s)) = sorts_on_typs_aux (v, s) |
633 fun sorts_on_tvar (TVar z) = generic_sorts_on_type z |
634 | sorts_on_typs _ = raise Fail "expected \"TVar\" or \"TFree\"" |
634 | sorts_on_tvar _ = [] |
635 |
635 |
636 (*Given a list of sorted type variables, return a list of type literals.*) |
636 (* Given a list of sorted type variables, return a list of type literals. *) |
637 val raw_type_literals_for_types = union_all o map sorts_on_typs |
637 fun raw_type_literals_for_types Ts = |
638 |
638 union_all (map sorts_on_tfree Ts @ map sorts_on_tvar Ts) |
639 fun type_literals_for_types format type_sys kind Ts = |
639 |
640 if level_of_type_sys type_sys = No_Types orelse format = CNF_UEQ then |
640 fun type_literals_for_types type_sys sorts_on_typ Ts = |
641 [] |
641 if level_of_type_sys type_sys = No_Types then [] |
642 else |
642 else union_all (map sorts_on_typ Ts) |
643 Ts |> raw_type_literals_for_types |
|
644 |> filter (fn TyLitVar _ => kind <> Conjecture |
|
645 | TyLitFree _ => kind = Conjecture) |
|
646 |
643 |
647 fun mk_aconns c phis = |
644 fun mk_aconns c phis = |
648 let val (phis', phi') = split_last phis in |
645 let val (phis', phi') = split_last phis in |
649 fold_rev (mk_aconn c) phis' phi' |
646 fold_rev (mk_aconn c) phis' phi' |
650 end |
647 end |
891 t |> need_trueprop ? HOLogic.mk_Trueprop |
888 t |> need_trueprop ? HOLogic.mk_Trueprop |
892 |> Raw_Simplifier.rewrite_term thy (Meson.unfold_set_const_simps ctxt) [] |
889 |> Raw_Simplifier.rewrite_term thy (Meson.unfold_set_const_simps ctxt) [] |
893 |> extensionalize_term ctxt |
890 |> extensionalize_term ctxt |
894 |> presimp ? presimplify_term ctxt |
891 |> presimp ? presimplify_term ctxt |
895 |> introduce_combinators_in_term ctxt kind |
892 |> introduce_combinators_in_term ctxt kind |
896 |> kind <> Axiom ? freeze_term |
|
897 end |
893 end |
898 |
894 |
899 (* making fact and conjecture formulas *) |
895 (* making fact and conjecture formulas *) |
900 fun make_formula thy format type_sys eq_as_iff name loc kind t = |
896 fun make_formula thy format type_sys eq_as_iff name loc kind t = |
901 let |
897 let |
1456 end |
1452 end |
1457 | do_formula pos (AConn conn) = aconn_map pos do_formula conn |
1453 | do_formula pos (AConn conn) = aconn_map pos do_formula conn |
1458 | do_formula _ (AAtom tm) = AAtom (do_term tm) |
1454 | do_formula _ (AAtom tm) = AAtom (do_term tm) |
1459 in do_formula o SOME end |
1455 in do_formula o SOME end |
1460 |
1456 |
1461 fun bound_atomic_types format type_sys Ts = |
1457 fun bound_tvars type_sys Ts = |
1462 mk_ahorn (map (formula_from_fo_literal o fo_literal_from_type_literal) |
1458 mk_ahorn (map (formula_from_fo_literal o fo_literal_from_type_literal) |
1463 (type_literals_for_types format type_sys Axiom Ts)) |
1459 (type_literals_for_types type_sys sorts_on_tvar Ts)) |
1464 |
1460 |
1465 fun formula_for_fact ctxt format nonmono_Ts type_sys |
1461 fun formula_for_fact ctxt format nonmono_Ts type_sys |
1466 ({combformula, atomic_types, ...} : translated_formula) = |
1462 ({combformula, atomic_types, ...} : translated_formula) = |
1467 combformula |
1463 combformula |
1468 |> close_combformula_universally |
1464 |> close_combformula_universally |
1469 |> formula_from_combformula ctxt format nonmono_Ts type_sys |
1465 |> formula_from_combformula ctxt format nonmono_Ts type_sys |
1470 is_var_nonmonotonic_in_formula true |
1466 is_var_nonmonotonic_in_formula true |
1471 |> bound_atomic_types format type_sys atomic_types |
1467 |> bound_tvars type_sys atomic_types |
1472 |> close_formula_universally |
1468 |> close_formula_universally |
1473 |
1469 |
1474 (* Each fact is given a unique fact number to avoid name clashes (e.g., because |
1470 (* Each fact is given a unique fact number to avoid name clashes (e.g., because |
1475 of monomorphization). The TPTP explicitly forbids name clashes, and some of |
1471 of monomorphization). The TPTP explicitly forbids name clashes, and some of |
1476 the remote provers might care. *) |
1472 the remote provers might care. *) |
1508 (formula_from_fo_literal |
1504 (formula_from_fo_literal |
1509 (fo_literal_from_arity_literal concl_lits)) |
1505 (fo_literal_from_arity_literal concl_lits)) |
1510 |> close_formula_universally, intro_info, NONE) |
1506 |> close_formula_universally, intro_info, NONE) |
1511 |
1507 |
1512 fun formula_line_for_conjecture ctxt format nonmono_Ts type_sys |
1508 fun formula_line_for_conjecture ctxt format nonmono_Ts type_sys |
1513 ({name, kind, combformula, ...} : translated_formula) = |
1509 ({name, kind, combformula, atomic_types, ...} : translated_formula) = |
1514 Formula (conjecture_prefix ^ name, kind, |
1510 Formula (conjecture_prefix ^ name, kind, |
1515 formula_from_combformula ctxt format nonmono_Ts type_sys |
1511 formula_from_combformula ctxt format nonmono_Ts type_sys |
1516 is_var_nonmonotonic_in_formula false |
1512 is_var_nonmonotonic_in_formula false |
1517 (close_combformula_universally combformula) |
1513 (close_combformula_universally combformula) |
|
1514 |> bound_tvars type_sys atomic_types |
1518 |> close_formula_universally, NONE, NONE) |
1515 |> close_formula_universally, NONE, NONE) |
1519 |
1516 |
1520 fun free_type_literals format type_sys |
1517 fun free_type_literals type_sys ({atomic_types, ...} : translated_formula) = |
1521 ({atomic_types, ...} : translated_formula) = |
1518 atomic_types |> type_literals_for_types type_sys sorts_on_tfree |
1522 atomic_types |> type_literals_for_types format type_sys Conjecture |
|
1523 |> map fo_literal_from_type_literal |
1519 |> map fo_literal_from_type_literal |
1524 |
1520 |
1525 fun formula_line_for_free_type j lit = |
1521 fun formula_line_for_free_type j lit = |
1526 Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, |
1522 Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, |
1527 formula_from_fo_literal lit, NONE, NONE) |
1523 formula_from_fo_literal lit, NONE, NONE) |
1528 fun formula_lines_for_free_types format type_sys facts = |
1524 fun formula_lines_for_free_types type_sys facts = |
1529 let |
1525 let |
1530 val litss = map (free_type_literals format type_sys) facts |
1526 val litss = map (free_type_literals type_sys) facts |
1531 val lits = fold (union (op =)) litss [] |
1527 val lits = fold (union (op =)) litss [] |
1532 in map2 formula_line_for_free_type (0 upto length lits - 1) lits end |
1528 in map2 formula_line_for_free_type (0 upto length lits - 1) lits end |
1533 |
1529 |
1534 (** Symbol declarations **) |
1530 (** Symbol declarations **) |
1535 |
1531 |
1634 |> fold (curry (CombApp o swap)) bounds |
1630 |> fold (curry (CombApp o swap)) bounds |
1635 |> type_pred_combterm ctxt nonmono_Ts type_sys res_T |
1631 |> type_pred_combterm ctxt nonmono_Ts type_sys res_T |
1636 |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts) |
1632 |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts) |
1637 |> formula_from_combformula ctxt format nonmono_Ts type_sys |
1633 |> formula_from_combformula ctxt format nonmono_Ts type_sys |
1638 (K (K (K (K true)))) true |
1634 (K (K (K (K true)))) true |
1639 |> n > 1 ? bound_atomic_types format type_sys (atyps_of T) |
1635 |> n > 1 ? bound_tvars type_sys (atyps_of T) |
1640 |> close_formula_universally |
1636 |> close_formula_universally |
1641 |> maybe_negate, |
1637 |> maybe_negate, |
1642 intro_info, NONE) |
1638 intro_info, NONE) |
1643 end |
1639 end |
1644 |
1640 |
1657 val cst = mk_const_aterm (s, s') T_args |
1653 val cst = mk_const_aterm (s, s') T_args |
1658 val atomic_Ts = atyps_of T |
1654 val atomic_Ts = atyps_of T |
1659 fun eq tms = |
1655 fun eq tms = |
1660 (if pred_sym then AConn (AIff, map AAtom tms) |
1656 (if pred_sym then AConn (AIff, map AAtom tms) |
1661 else AAtom (ATerm (`I tptp_equal, tms))) |
1657 else AAtom (ATerm (`I tptp_equal, tms))) |
1662 |> bound_atomic_types format type_sys atomic_Ts |
1658 |> bound_tvars type_sys atomic_Ts |
1663 |> close_formula_universally |
1659 |> close_formula_universally |
1664 |> maybe_negate |
1660 |> maybe_negate |
1665 val should_encode = should_encode_type ctxt nonmono_Ts All_Types |
1661 val should_encode = should_encode_type ctxt nonmono_Ts All_Types |
1666 val tag_with = tag_with_type ctxt format nonmono_Ts type_sys |
1662 val tag_with = tag_with_type ctxt format nonmono_Ts type_sys |
1667 val add_formula_for_res = |
1663 val add_formula_for_res = |
1800 (aritiesN, map formula_line_for_arity_clause arity_clauses), |
1796 (aritiesN, map formula_line_for_arity_clause arity_clauses), |
1801 (helpersN, helper_lines), |
1797 (helpersN, helper_lines), |
1802 (conjsN, |
1798 (conjsN, |
1803 map (formula_line_for_conjecture ctxt format nonmono_Ts type_sys) |
1799 map (formula_line_for_conjecture ctxt format nonmono_Ts type_sys) |
1804 conjs), |
1800 conjs), |
1805 (free_typesN, |
1801 (free_typesN, formula_lines_for_free_types type_sys (facts @ conjs))] |
1806 formula_lines_for_free_types format type_sys (facts @ conjs))] |
|
1807 val problem = |
1802 val problem = |
1808 problem |
1803 problem |
1809 |> (case format of |
1804 |> (case format of |
1810 CNF => ensure_cnf_problem |
1805 CNF => ensure_cnf_problem |
1811 | CNF_UEQ => filter_cnf_ueq_problem |
1806 | CNF_UEQ => filter_cnf_ueq_problem |