2565 |
2565 |
2566 (* TFF allows implicit declarations of types, function symbols, and predicate |
2566 (* TFF allows implicit declarations of types, function symbols, and predicate |
2567 symbols (with "$i" as the type of individuals), but some provers (e.g., |
2567 symbols (with "$i" as the type of individuals), but some provers (e.g., |
2568 SNARK) require explicit declarations. The situation is similar for THF. *) |
2568 SNARK) require explicit declarations. The situation is similar for THF. *) |
2569 |
2569 |
2570 fun default_type type_enc pred_sym s = |
2570 fun default_type pred_sym s = |
2571 let |
2571 let |
2572 val ind = |
2572 fun typ 0 0 = if pred_sym then bool_atype else individual_atype |
2573 case type_enc of |
2573 | typ 0 tm_ary = AFun (individual_atype, typ 0 (tm_ary - 1)) |
2574 Native _ => |
|
2575 (* ### FIXME: get rid of that, and move to "atp_problem.ML" *) |
|
2576 if String.isPrefix type_const_prefix s orelse |
|
2577 String.isPrefix tfree_prefix s then |
|
2578 atype_of_types |
|
2579 else |
|
2580 individual_atype |
|
2581 | _ => individual_atype |
|
2582 fun typ 0 0 = if pred_sym then bool_atype else ind |
|
2583 | typ 0 tm_ary = AFun (ind, typ 0 (tm_ary - 1)) |
|
2584 | typ ty_ary tm_ary = APi (replicate ty_ary tvar_a_name, typ 0 tm_ary) |
2574 | typ ty_ary tm_ary = APi (replicate ty_ary tvar_a_name, typ 0 tm_ary) |
2585 in typ end |
2575 in typ end |
2586 |
2576 |
2587 fun nary_type_constr_type n = |
2577 fun nary_type_constr_type n = |
2588 funpow n (curry AFun atype_of_types) atype_of_types |
2578 funpow n (curry AFun atype_of_types) atype_of_types |
2589 |
2579 |
2590 fun undeclared_syms_in_problem type_enc problem = |
2580 fun undeclared_syms_in_problem problem = |
2591 let |
2581 let |
2592 fun do_sym (name as (s, _)) ty = |
2582 fun do_sym (name as (s, _)) ty = |
2593 if is_tptp_user_symbol s then |
2583 if is_tptp_user_symbol s then Symtab.default (s, (name, ty)) else I |
2594 Symtab.default (s, (name, ty)) |
|
2595 else |
|
2596 I |
|
2597 fun do_type (AType (name, tys)) = |
2584 fun do_type (AType (name, tys)) = |
2598 do_sym name (fn () => nary_type_constr_type (length tys)) |
2585 do_sym name (fn () => nary_type_constr_type (length tys)) |
2599 #> fold do_type tys |
2586 #> fold do_type tys |
2600 | do_type (AFun (ty1, ty2)) = do_type ty1 #> do_type ty2 |
2587 | do_type (AFun (ty1, ty2)) = do_type ty1 #> do_type ty2 |
2601 | do_type (APi (_, ty)) = do_type ty |
2588 | do_type (APi (_, ty)) = do_type ty |
2602 fun do_term pred_sym (ATerm ((name as (s, _), tys), tms)) = |
2589 fun do_term pred_sym (ATerm ((name as (s, _), tys), tms)) = |
2603 do_sym name |
2590 do_sym name |
2604 (fn _ => default_type type_enc pred_sym s (length tys) (length tms)) |
2591 (fn _ => default_type pred_sym s (length tys) (length tms)) |
2605 #> fold do_type tys #> fold (do_term false) tms |
2592 #> fold do_type tys #> fold (do_term false) tms |
2606 | do_term _ (AAbs (((_, ty), tm), args)) = |
2593 | do_term _ (AAbs (((_, ty), tm), args)) = |
2607 do_type ty #> do_term false tm #> fold (do_term false) args |
2594 do_type ty #> do_term false tm #> fold (do_term false) args |
2608 fun do_formula (ATyQuant (_, _, phi)) = do_formula phi |
2595 fun do_formula (ATyQuant (_, _, phi)) = do_formula phi |
2609 | do_formula (AQuant (_, xs, phi)) = |
2596 | do_formula (AQuant (_, xs, phi)) = |
2617 |> fold (fn (s, _) => Symtab.default (s, (("", ""), K tvar_a_atype))) |
2604 |> fold (fn (s, _) => Symtab.default (s, (("", ""), K tvar_a_atype))) |
2618 (declared_syms_in_problem problem) |
2605 (declared_syms_in_problem problem) |
2619 |> fold (fold do_problem_line o snd) problem |
2606 |> fold (fold do_problem_line o snd) problem |
2620 end |
2607 end |
2621 |
2608 |
2622 fun declare_undeclared_syms_in_atp_problem type_enc problem = |
2609 fun declare_undeclared_syms_in_atp_problem problem = |
2623 let |
2610 let |
2624 val decls = |
2611 val decls = |
2625 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2612 Symtab.fold (fn (_, (("", ""), _)) => I (* already declared *) |
2626 | (s, (sym, ty)) => |
2613 | (s, (sym, ty)) => |
2627 cons (Decl (type_decl_prefix ^ s, sym, ty ()))) |
2614 cons (Decl (type_decl_prefix ^ s, sym, ty ()))) |
2628 (undeclared_syms_in_problem type_enc problem) [] |
2615 (undeclared_syms_in_problem problem) [] |
2629 in (implicit_declsN, decls) :: problem end |
2616 in (implicit_declsN, decls) :: problem end |
2630 |
2617 |
2631 fun exists_subdtype P = |
2618 fun exists_subdtype P = |
2632 let |
2619 let |
2633 fun ex U = P U orelse |
2620 fun ex U = P U orelse |
2724 (aritiesN, map (formula_line_for_arity_clause type_enc) arity_clauses), |
2711 (aritiesN, map (formula_line_for_arity_clause type_enc) arity_clauses), |
2725 (helpersN, helper_lines), |
2712 (helpersN, helper_lines), |
2726 (free_typesN, formula_lines_for_free_types type_enc (facts @ conjs)), |
2713 (free_typesN, formula_lines_for_free_types type_enc (facts @ conjs)), |
2727 (conjsN, map (formula_line_for_conjecture ctxt mono type_enc) conjs)] |
2714 (conjsN, map (formula_line_for_conjecture ctxt mono type_enc) conjs)] |
2728 val problem = |
2715 val problem = |
2729 problem |
2716 problem |> (case format of |
2730 |> (case format of |
2717 CNF => ensure_cnf_problem |
2731 CNF => ensure_cnf_problem |
2718 | CNF_UEQ => filter_cnf_ueq_problem |
2732 | CNF_UEQ => filter_cnf_ueq_problem |
2719 | FOF => I |
2733 | FOF => I |
2720 | TFF (_, TPTP_Implicit) => I |
2734 | TFF (_, TPTP_Implicit) => I |
2721 | THF (_, TPTP_Implicit, _, _) => I |
2735 | THF (_, TPTP_Implicit, _, _) => I |
2722 | _ => declare_undeclared_syms_in_atp_problem) |
2736 | _ => declare_undeclared_syms_in_atp_problem type_enc) |
|
2737 val (problem, pool) = problem |> nice_atp_problem readable_names format |
2723 val (problem, pool) = problem |> nice_atp_problem readable_names format |
2738 fun add_sym_ary (s, {min_ary, ...} : sym_info) = |
2724 fun add_sym_ary (s, {min_ary, ...} : sym_info) = |
2739 min_ary > 0 ? Symtab.insert (op =) (s, min_ary) |
2725 min_ary > 0 ? Symtab.insert (op =) (s, min_ary) |
2740 in |
2726 in |
2741 (problem, pool |> Option.map snd |> the_default Symtab.empty, |
2727 (problem, pool |> Option.map snd |> the_default Symtab.empty, |