2575 fun do_type (AType ((name, _), tys)) = |
2575 fun do_type (AType ((name, _), tys)) = |
2576 apfst (apsnd (do_sym name (length tys))) #> fold do_type tys |
2576 apfst (apsnd (do_sym name (length tys))) #> fold do_type tys |
2577 | do_type (AFun (ty1, ty2)) = do_type ty1 #> do_type ty2 |
2577 | do_type (AFun (ty1, ty2)) = do_type ty1 #> do_type ty2 |
2578 | do_type (APi (_, ty)) = do_type ty |
2578 | do_type (APi (_, ty)) = do_type ty |
2579 fun do_term pred_sym (ATerm ((name, tys), tms)) = |
2579 fun do_term pred_sym (ATerm ((name, tys), tms)) = |
2580 apsnd (do_sym name |
2580 apsnd (do_sym name (fn _ => default_type pred_sym (length tys) (length tms))) |
2581 (fn _ => default_type pred_sym (length tys) (length tms))) |
|
2582 #> fold do_type tys #> fold (do_term false) tms |
2581 #> fold do_type tys #> fold (do_term false) tms |
2583 | do_term _ (AAbs (((_, ty), tm), args)) = |
2582 | do_term _ (AAbs (((_, ty), tm), args)) = |
2584 do_type ty #> do_term false tm #> fold (do_term false) args |
2583 do_type ty #> do_term false tm #> fold (do_term false) args |
2585 fun do_formula (ATyQuant (_, xs, phi)) = |
2584 fun do_formula (ATyQuant (_, xs, phi)) = |
2586 fold (do_type o fst) xs #> fold (fold do_class o snd) xs #> do_formula phi |
2585 fold (do_type o fst) xs #> fold (fold do_class o snd) xs #> do_formula phi |
2606 fun declare_undeclared_in_problem heading problem = |
2605 fun declare_undeclared_in_problem heading problem = |
2607 let |
2606 let |
2608 val ((cls, tys), syms) = undeclared_in_problem problem |
2607 val ((cls, tys), syms) = undeclared_in_problem problem |
2609 val decls = |
2608 val decls = |
2610 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2609 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2611 | (s, (cls, ())) => |
2610 | (s, (cls, ())) => cons (Class_Decl (class_decl_prefix ^ s, cls, []))) cls [] @ |
2612 cons (Class_Decl (class_decl_prefix ^ s, cls, []))) |
|
2613 cls [] @ |
|
2614 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2611 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2615 | (s, (ty, ary)) => |
2612 | (s, (ty, ary)) => cons (Type_Decl (type_decl_prefix ^ s, ty, ary))) tys [] @ |
2616 cons (Type_Decl (type_decl_prefix ^ s, ty, ary))) |
|
2617 tys [] @ |
|
2618 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2613 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2619 | (s, (sym, ty)) => |
2614 | (s, (sym, ty)) => cons (Sym_Decl (sym_decl_prefix ^ s, sym, ty ()))) syms [] |
2620 cons (Sym_Decl (sym_decl_prefix ^ s, sym, ty ()))) |
|
2621 syms [] |
|
2622 in (heading, decls) :: problem end |
2615 in (heading, decls) :: problem end |
2623 |
2616 |
2624 fun all_ctrss_of_datatypes ctxt = |
2617 fun all_ctrss_of_datatypes ctxt = |
2625 map (map_filter (try dest_Const) o #ctrs) (Ctr_Sugar.ctr_sugars_of ctxt) |
2618 map (map_filter (try dest_Const) o #ctrs) (Ctr_Sugar.ctr_sugars_of ctxt) |
2626 |
2619 |
2651 translate_formulas ctxt prem_role format type_enc lam_trans presimp hyp_ts concl_t facts |
2644 translate_formulas ctxt prem_role format type_enc lam_trans presimp hyp_ts concl_t facts |
2652 val (_, sym_tab0) = sym_table_of_facts ctxt type_enc app_op_level conjs facts |
2645 val (_, sym_tab0) = sym_table_of_facts ctxt type_enc app_op_level conjs facts |
2653 val mono = conjs @ facts |> mononotonicity_info_of_facts ctxt type_enc completish |
2646 val mono = conjs @ facts |> mononotonicity_info_of_facts ctxt type_enc completish |
2654 val ctrss = all_ctrss_of_datatypes ctxt |
2647 val ctrss = all_ctrss_of_datatypes ctxt |
2655 fun firstorderize in_helper = |
2648 fun firstorderize in_helper = |
2656 firstorderize_fact thy ctrss type_enc |
2649 firstorderize_fact thy ctrss type_enc (uncurried_aliases andalso not in_helper) completish |
2657 (uncurried_aliases andalso not in_helper) completish sym_tab0 |
2650 sym_tab0 |
2658 val (conjs, facts) = (conjs, facts) |> pairself (map (firstorderize false)) |
2651 val (conjs, facts) = (conjs, facts) |> pairself (map (firstorderize false)) |
2659 val (ho_stuff, sym_tab) = |
2652 val (ho_stuff, sym_tab) = |
2660 sym_table_of_facts ctxt type_enc Min_App_Op conjs facts |
2653 sym_table_of_facts ctxt type_enc Min_App_Op conjs facts |
2661 val (uncurried_alias_eq_tms, uncurried_alias_eq_lines) = |
2654 val (uncurried_alias_eq_tms, uncurried_alias_eq_lines) = |
2662 uncurried_alias_lines_of_sym_table ctxt ctrss mono type_enc |
2655 uncurried_alias_lines_of_sym_table ctxt ctrss mono type_enc uncurried_aliases sym_tab0 sym_tab |
2663 uncurried_aliases sym_tab0 sym_tab |
|
2664 val (_, sym_tab) = |
2656 val (_, sym_tab) = |
2665 (ho_stuff, sym_tab) |
2657 (ho_stuff, sym_tab) |
2666 |> fold (add_iterm_syms_to_sym_table ctxt Min_App_Op false false) |
2658 |> fold (add_iterm_syms_to_sym_table ctxt Min_App_Op false false) |
2667 uncurried_alias_eq_tms |
2659 uncurried_alias_eq_tms |
2668 val helpers = |
2660 val helpers = |
2669 sym_tab |> helper_facts_of_sym_table ctxt format type_enc completish |
2661 sym_tab |> helper_facts_of_sym_table ctxt format type_enc completish |
2670 |> map (firstorderize true) |
2662 |> map (firstorderize true) |
2671 val all_facts = helpers @ conjs @ facts |
2663 val all_facts = helpers @ conjs @ facts |
2672 val mono_Ts = monotonic_types_of_facts ctxt mono type_enc all_facts |
2664 val mono_Ts = monotonic_types_of_facts ctxt mono type_enc all_facts |
2673 val datatypes = |
2665 val datatypes = datatypes_of_sym_table ctxt ctrss format type_enc uncurried_aliases sym_tab |
2674 datatypes_of_sym_table ctxt ctrss format type_enc uncurried_aliases |
|
2675 sym_tab |
|
2676 val class_decl_lines = decl_lines_of_classes type_enc classes |
2666 val class_decl_lines = decl_lines_of_classes type_enc classes |
2677 val sym_decl_lines = |
2667 val sym_decl_lines = |
2678 (conjs, helpers @ facts, uncurried_alias_eq_tms) |
2668 (conjs, helpers @ facts, uncurried_alias_eq_tms) |
2679 |> sym_decl_table_of_facts thy type_enc sym_tab |
2669 |> sym_decl_table_of_facts thy type_enc sym_tab |
2680 |> lines_of_sym_decl_table ctxt mono type_enc mono_Ts |
2670 |> lines_of_sym_decl_table ctxt mono type_enc mono_Ts |
2689 (0 upto num_facts - 1 ~~ facts) |
2679 (0 upto num_facts - 1 ~~ facts) |
2690 val subclass_lines = maps (lines_of_subclass_pair type_enc) subclass_pairs |
2680 val subclass_lines = maps (lines_of_subclass_pair type_enc) subclass_pairs |
2691 val tcon_lines = map (line_of_tcon_clause type_enc) tcon_clauses |
2681 val tcon_lines = map (line_of_tcon_clause type_enc) tcon_clauses |
2692 val helper_lines = |
2682 val helper_lines = |
2693 0 upto length helpers - 1 ~~ helpers |
2683 0 upto length helpers - 1 ~~ helpers |
2694 |> map (line_of_fact ctxt helper_prefix I (K "") false true mono type_enc |
2684 |> map (line_of_fact ctxt helper_prefix I (K "") false true mono type_enc (K default_rank)) |
2695 (K default_rank)) |
|
2696 val free_type_lines = lines_of_free_types type_enc (facts @ conjs) |
2685 val free_type_lines = lines_of_free_types type_enc (facts @ conjs) |
2697 val conj_lines = map (line_of_conjecture ctxt mono type_enc) conjs |
2686 val conj_lines = map (line_of_conjecture ctxt mono type_enc) conjs |
2698 (* Reordering these might confuse the proof reconstruction code. *) |
2687 (* Reordering these might confuse the proof reconstruction code. *) |
2699 val problem = |
2688 val problem = |
2700 [(explicit_declsN, decl_lines), |
2689 [(explicit_declsN, decl_lines), |
2704 (tconsN, tcon_lines), |
2693 (tconsN, tcon_lines), |
2705 (helpersN, helper_lines), |
2694 (helpersN, helper_lines), |
2706 (free_typesN, free_type_lines), |
2695 (free_typesN, free_type_lines), |
2707 (conjsN, conj_lines)] |
2696 (conjsN, conj_lines)] |
2708 val problem = |
2697 val problem = |
2709 problem |> (case format of |
2698 problem |
2710 CNF => ensure_cnf_problem |
2699 |> (case format of |
2711 | CNF_UEQ => filter_cnf_ueq_problem |
2700 CNF => ensure_cnf_problem |
2712 | FOF => I |
2701 | CNF_UEQ => filter_cnf_ueq_problem |
2713 | _ => declare_undeclared_in_problem implicit_declsN) |
2702 | FOF => I |
|
2703 | _ => declare_undeclared_in_problem implicit_declsN) |
2714 val (problem, pool) = problem |> nice_atp_problem readable_names format |
2704 val (problem, pool) = problem |> nice_atp_problem readable_names format |
2715 fun add_sym_ary (s, {min_ary, ...} : sym_info) = |
2705 fun add_sym_ary (s, {min_ary, ...} : sym_info) = min_ary > 0 ? Symtab.insert (op =) (s, min_ary) |
2716 min_ary > 0 ? Symtab.insert (op =) (s, min_ary) |
|
2717 in |
2706 in |
2718 (problem, pool |> Option.map snd |> the_default Symtab.empty, |
2707 (problem, pool |> Option.map snd |> the_default Symtab.empty, fact_names |> Vector.fromList, |
2719 fact_names |> Vector.fromList, lifted, |
2708 lifted, Symtab.empty |> Symtab.fold add_sym_ary sym_tab) |
2720 Symtab.empty |> Symtab.fold add_sym_ary sym_tab) |
|
2721 end |
2709 end |
2722 |
2710 |
2723 (* FUDGE *) |
2711 (* FUDGE *) |
2724 val conj_weight = 0.0 |
2712 val conj_weight = 0.0 |
2725 val hyp_weight = 0.1 |
2713 val hyp_weight = 0.1 |
2729 |
2717 |
2730 (* Weights are from 0.0 (most important) to 1.0 (least important). *) |
2718 (* Weights are from 0.0 (most important) to 1.0 (least important). *) |
2731 fun atp_problem_selection_weights problem = |
2719 fun atp_problem_selection_weights problem = |
2732 let |
2720 let |
2733 fun add_term_weights weight (ATerm ((s, _), tms)) = |
2721 fun add_term_weights weight (ATerm ((s, _), tms)) = |
2734 is_tptp_user_symbol s ? Symtab.default (s, weight) |
2722 is_tptp_user_symbol s ? Symtab.default (s, weight) #> fold (add_term_weights weight) tms |
2735 #> fold (add_term_weights weight) tms |
|
2736 | add_term_weights weight (AAbs ((_, tm), args)) = |
2723 | add_term_weights weight (AAbs ((_, tm), args)) = |
2737 add_term_weights weight tm #> fold (add_term_weights weight) args |
2724 add_term_weights weight tm #> fold (add_term_weights weight) args |
2738 fun add_line_weights weight (Formula (_, _, phi, _, _)) = |
2725 fun add_line_weights weight (Formula (_, _, phi, _, _)) = |
2739 formula_fold NONE (K (add_term_weights weight)) phi |
2726 formula_fold NONE (K (add_term_weights weight)) phi |
2740 | add_line_weights _ _ = I |
2727 | add_line_weights _ _ = I |
2768 (* Ugly hack: may make innocent victims (collateral damage) *) |
2755 (* Ugly hack: may make innocent victims (collateral damage) *) |
2769 fun may_be_app s args = String.isPrefix app_op_name s andalso length args = 2 |
2756 fun may_be_app s args = String.isPrefix app_op_name s andalso length args = 2 |
2770 fun may_be_predicator s = |
2757 fun may_be_predicator s = |
2771 member (op =) [predicator_name, prefixed_predicator_name] s |
2758 member (op =) [predicator_name, prefixed_predicator_name] s |
2772 |
2759 |
2773 fun strip_predicator (tm as ATerm ((s, _), [tm'])) = |
2760 fun strip_predicator (tm as ATerm ((s, _), [tm'])) = if may_be_predicator s then tm' else tm |
2774 if may_be_predicator s then tm' else tm |
|
2775 | strip_predicator tm = tm |
2761 | strip_predicator tm = tm |
2776 |
2762 |
2777 fun make_head_roll (ATerm ((s, _), tms)) = |
2763 fun make_head_roll (ATerm ((s, _), tms)) = |
2778 if may_be_app s tms then make_head_roll (hd tms) ||> append (tl tms) |
2764 if may_be_app s tms then make_head_roll (hd tms) ||> append (tl tms) else (s, tms) |
2779 else (s, tms) |
|
2780 | make_head_roll _ = ("", []) |
2765 | make_head_roll _ = ("", []) |
2781 |
2766 |
2782 fun strip_up_to_predicator (ATyQuant (_, _, phi)) = strip_up_to_predicator phi |
2767 fun strip_up_to_predicator (ATyQuant (_, _, phi)) = strip_up_to_predicator phi |
2783 | strip_up_to_predicator (AQuant (_, _, phi)) = strip_up_to_predicator phi |
2768 | strip_up_to_predicator (AQuant (_, _, phi)) = strip_up_to_predicator phi |
2784 | strip_up_to_predicator (AConn (_, phis)) = maps strip_up_to_predicator phis |
2769 | strip_up_to_predicator (AConn (_, phis)) = maps strip_up_to_predicator phis |