1620 else AAtom (ATerm (`I tptp_equal, [tm1, tm2]))) |
1620 else AAtom (ATerm (`I tptp_equal, [tm1, tm2]))) |
1621 |> mk_aquant AForall bounds |
1621 |> mk_aquant AForall bounds |
1622 |> close_formula_universally |
1622 |> close_formula_universally |
1623 |> bound_tvars type_enc true atomic_Ts |
1623 |> bound_tvars type_enc true atomic_Ts |
1624 |
1624 |
|
1625 val helper_rank = default_rank |
|
1626 val min_rank = 9 * helper_rank div 10 |
|
1627 val max_rank = 4 * min_rank |
|
1628 |
|
1629 fun rank_of_fact_num n j = min_rank + (max_rank - min_rank) * j div n |
|
1630 |
1625 val type_tag = `(make_fixed_const NONE) type_tag_name |
1631 val type_tag = `(make_fixed_const NONE) type_tag_name |
1626 |
1632 |
1627 fun type_tag_idempotence_fact format type_enc = |
1633 fun type_tag_idempotence_fact format type_enc = |
1628 let |
1634 let |
1629 fun var s = ATerm (`I s, []) |
1635 fun var s = ATerm (`I s, []) |
1630 fun tag tm = ATerm (type_tag, [var "A", tm]) |
1636 fun tag tm = ATerm (type_tag, [var "A", tm]) |
1631 val tagged_var = tag (var "X") |
1637 val tagged_var = tag (var "X") |
1632 in |
1638 in |
1633 Formula (type_tag_idempotence_helper_name, Axiom, |
1639 Formula (type_tag_idempotence_helper_name, Axiom, |
1634 eq_formula type_enc [] [] false (tag tagged_var) tagged_var, |
1640 eq_formula type_enc [] [] false (tag tagged_var) tagged_var, |
1635 NONE, isabelle_info format spec_eqN) |
1641 NONE, isabelle_info format spec_eqN helper_rank) |
1636 end |
1642 end |
1637 |
1643 |
1638 fun should_specialize_helper type_enc t = |
1644 fun should_specialize_helper type_enc t = |
1639 polymorphism_of_type_enc type_enc <> Polymorphic andalso |
1645 polymorphism_of_type_enc type_enc <> Polymorphic andalso |
1640 level_of_type_enc type_enc <> No_Types andalso |
1646 level_of_type_enc type_enc <> No_Types andalso |
1943 |
1949 |
1944 (* Each fact is given a unique fact number to avoid name clashes (e.g., because |
1950 (* Each fact is given a unique fact number to avoid name clashes (e.g., because |
1945 of monomorphization). The TPTP explicitly forbids name clashes, and some of |
1951 of monomorphization). The TPTP explicitly forbids name clashes, and some of |
1946 the remote provers might care. *) |
1952 the remote provers might care. *) |
1947 fun formula_line_for_fact ctxt polym_constrs format prefix encode freshen pos |
1953 fun formula_line_for_fact ctxt polym_constrs format prefix encode freshen pos |
1948 mono type_enc (j, {name, stature, kind, iformula, atomic_types}) = |
1954 mono type_enc rank (j, {name, stature, kind, iformula, atomic_types}) = |
1949 (prefix ^ (if freshen then string_of_int j ^ "_" else "") ^ encode name, kind, |
1955 (prefix ^ (if freshen then string_of_int j ^ "_" else "") ^ encode name, kind, |
1950 iformula |
1956 iformula |
1951 |> formula_from_iformula ctxt polym_constrs format mono type_enc |
1957 |> formula_from_iformula ctxt polym_constrs format mono type_enc |
1952 should_guard_var_in_formula (if pos then SOME true else NONE) |
1958 should_guard_var_in_formula (if pos then SOME true else NONE) |
1953 |> close_formula_universally |
1959 |> close_formula_universally |
1954 |> bound_tvars type_enc true atomic_types, |
1960 |> bound_tvars type_enc true atomic_types, |
1955 NONE, |
1961 NONE, |
1956 case snd stature of |
1962 let val rank = rank j in |
1957 Intro => isabelle_info format introN |
1963 case snd stature of |
1958 | Elim => isabelle_info format elimN |
1964 Intro => isabelle_info format introN rank |
1959 | Simp => isabelle_info format simpN |
1965 | Elim => isabelle_info format elimN rank |
1960 | Spec_Eq => isabelle_info format spec_eqN |
1966 | Simp => isabelle_info format simpN rank |
1961 | _ => NONE) |
1967 | Spec_Eq => isabelle_info format spec_eqN rank |
|
1968 | _ => isabelle_info format "" rank |
|
1969 end) |
1962 |> Formula |
1970 |> Formula |
1963 |
1971 |
1964 fun formula_line_for_class_rel_clause format type_enc |
1972 fun formula_line_for_class_rel_clause format type_enc |
1965 ({name, subclass, superclass, ...} : class_rel_clause) = |
1973 ({name, subclass, superclass, ...} : class_rel_clause) = |
1966 let val ty_arg = ATerm (tvar_a_name, []) in |
1974 let val ty_arg = ATerm (tvar_a_name, []) in |
1968 AConn (AImplies, |
1976 AConn (AImplies, |
1969 [type_class_formula type_enc subclass ty_arg, |
1977 [type_class_formula type_enc subclass ty_arg, |
1970 type_class_formula type_enc superclass ty_arg]) |
1978 type_class_formula type_enc superclass ty_arg]) |
1971 |> mk_aquant AForall |
1979 |> mk_aquant AForall |
1972 [(tvar_a_name, atype_of_type_vars type_enc)], |
1980 [(tvar_a_name, atype_of_type_vars type_enc)], |
1973 NONE, isabelle_info format introN) |
1981 NONE, isabelle_info format introN helper_rank) |
1974 end |
1982 end |
1975 |
1983 |
1976 fun formula_from_arity_atom type_enc (class, t, args) = |
1984 fun formula_from_arity_atom type_enc (class, t, args) = |
1977 ATerm (t, map (fn arg => ATerm (arg, [])) args) |
1985 ATerm (t, map (fn arg => ATerm (arg, [])) args) |
1978 |> type_class_formula type_enc class |
1986 |> type_class_formula type_enc class |
1982 Formula (arity_clause_prefix ^ name, Axiom, |
1990 Formula (arity_clause_prefix ^ name, Axiom, |
1983 mk_ahorn (map (formula_from_arity_atom type_enc) prem_atoms) |
1991 mk_ahorn (map (formula_from_arity_atom type_enc) prem_atoms) |
1984 (formula_from_arity_atom type_enc concl_atom) |
1992 (formula_from_arity_atom type_enc concl_atom) |
1985 |> mk_aquant AForall |
1993 |> mk_aquant AForall |
1986 (map (rpair (atype_of_type_vars type_enc)) (#3 concl_atom)), |
1994 (map (rpair (atype_of_type_vars type_enc)) (#3 concl_atom)), |
1987 NONE, isabelle_info format introN) |
1995 NONE, isabelle_info format introN helper_rank) |
1988 |
1996 |
1989 fun formula_line_for_conjecture ctxt polym_constrs format mono type_enc |
1997 fun formula_line_for_conjecture ctxt polym_constrs format mono type_enc |
1990 ({name, kind, iformula, atomic_types, ...} : translated_formula) = |
1998 ({name, kind, iformula, atomic_types, ...} : translated_formula) = |
1991 Formula (conjecture_prefix ^ name, kind, |
1999 Formula (conjecture_prefix ^ name, kind, |
1992 iformula |
2000 iformula |
1993 |> formula_from_iformula ctxt polym_constrs format mono type_enc |
2001 |> formula_from_iformula ctxt polym_constrs format mono type_enc |
1994 should_guard_var_in_formula (SOME false) |
2002 should_guard_var_in_formula (SOME false) |
1995 |> close_formula_universally |
2003 |> close_formula_universally |
1996 |> bound_tvars type_enc true atomic_types, NONE, NONE) |
2004 |> bound_tvars type_enc true atomic_types, NONE, []) |
1997 |
2005 |
1998 fun formula_line_for_free_type j phi = |
2006 fun formula_line_for_free_type j phi = |
1999 Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, phi, NONE, NONE) |
2007 Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, phi, NONE, []) |
2000 fun formula_lines_for_free_types type_enc (facts : translated_formula list) = |
2008 fun formula_lines_for_free_types type_enc (facts : translated_formula list) = |
2001 let |
2009 let |
2002 val phis = |
2010 val phis = |
2003 fold (union (op =)) (map #atomic_types facts) [] |
2011 fold (union (op =)) (map #atomic_types facts) [] |
2004 |> formulas_for_types type_enc add_sorts_on_tfree |
2012 |> formulas_for_types type_enc add_sorts_on_tfree |
2191 |> AAtom |
2199 |> AAtom |
2192 |> formula_from_iformula ctxt [] format mono type_enc |
2200 |> formula_from_iformula ctxt [] format mono type_enc |
2193 always_guard_var_in_formula (SOME true) |
2201 always_guard_var_in_formula (SOME true) |
2194 |> close_formula_universally |
2202 |> close_formula_universally |
2195 |> bound_tvars type_enc true (atomic_types_of T), |
2203 |> bound_tvars type_enc true (atomic_types_of T), |
2196 NONE, isabelle_info format introN) |
2204 NONE, isabelle_info format introN helper_rank) |
2197 |
2205 |
2198 fun formula_line_for_tags_mono_type ctxt format mono type_enc T = |
2206 fun formula_line_for_tags_mono_type ctxt format mono type_enc T = |
2199 let val x_var = ATerm (`make_bound_var "X", []) in |
2207 let val x_var = ATerm (`make_bound_var "X", []) in |
2200 Formula (tags_sym_formula_prefix ^ |
2208 Formula (tags_sym_formula_prefix ^ |
2201 ascii_of (mangled_type format type_enc T), |
2209 ascii_of (mangled_type format type_enc T), |
2202 Axiom, |
2210 Axiom, |
2203 eq_formula type_enc (atomic_types_of T) [] false |
2211 eq_formula type_enc (atomic_types_of T) [] false |
2204 (tag_with_type ctxt format mono type_enc NONE T x_var) x_var, |
2212 (tag_with_type ctxt format mono type_enc NONE T x_var) x_var, |
2205 NONE, isabelle_info format spec_eqN) |
2213 NONE, isabelle_info format spec_eqN helper_rank) |
2206 end |
2214 end |
2207 |
2215 |
2208 fun problem_lines_for_mono_types ctxt format mono type_enc Ts = |
2216 fun problem_lines_for_mono_types ctxt format mono type_enc Ts = |
2209 case type_enc of |
2217 case type_enc of |
2210 Simple_Types _ => [] |
2218 Simple_Types _ => [] |
2271 |> formula_from_iformula ctxt [] format mono type_enc |
2279 |> formula_from_iformula ctxt [] format mono type_enc |
2272 always_guard_var_in_formula (SOME true) |
2280 always_guard_var_in_formula (SOME true) |
2273 |> close_formula_universally |
2281 |> close_formula_universally |
2274 |> bound_tvars type_enc (n > 1) (atomic_types_of T) |
2282 |> bound_tvars type_enc (n > 1) (atomic_types_of T) |
2275 |> maybe_negate, |
2283 |> maybe_negate, |
2276 NONE, isabelle_info format introN) |
2284 NONE, isabelle_info format introN helper_rank) |
2277 end |
2285 end |
2278 |
2286 |
2279 fun formula_lines_for_tags_sym_decl ctxt format conj_sym_kind mono type_enc n s |
2287 fun formula_lines_for_tags_sym_decl ctxt format conj_sym_kind mono type_enc n s |
2280 (j, (s', T_args, T, pred_sym, ary, in_conj)) = |
2288 (j, (s', T_args, T, pred_sym, ary, in_conj)) = |
2281 let |
2289 let |
2305 else |
2313 else |
2306 bounds |
2314 bounds |
2307 in |
2315 in |
2308 cons (Formula (ident_base ^ "_res", kind, |
2316 cons (Formula (ident_base ^ "_res", kind, |
2309 eq (tag_with res_T (cst bounds)) (cst tagged_bounds), |
2317 eq (tag_with res_T (cst bounds)) (cst tagged_bounds), |
2310 NONE, isabelle_info format spec_eqN)) |
2318 NONE, isabelle_info format spec_eqN helper_rank)) |
2311 end |
2319 end |
2312 else |
2320 else |
2313 I |
2321 I |
2314 fun add_formula_for_arg k = |
2322 fun add_formula_for_arg k = |
2315 let val arg_T = nth arg_Ts k in |
2323 let val arg_T = nth arg_Ts k in |
2317 case chop k bounds of |
2325 case chop k bounds of |
2318 (bounds1, bound :: bounds2) => |
2326 (bounds1, bound :: bounds2) => |
2319 cons (Formula (ident_base ^ "_arg" ^ string_of_int (k + 1), kind, |
2327 cons (Formula (ident_base ^ "_arg" ^ string_of_int (k + 1), kind, |
2320 eq (cst (bounds1 @ tag_with arg_T bound :: bounds2)) |
2328 eq (cst (bounds1 @ tag_with arg_T bound :: bounds2)) |
2321 (cst bounds), |
2329 (cst bounds), |
2322 NONE, isabelle_info format spec_eqN)) |
2330 NONE, isabelle_info format spec_eqN helper_rank)) |
2323 | _ => raise Fail "expected nonempty tail" |
2331 | _ => raise Fail "expected nonempty tail" |
2324 else |
2332 else |
2325 I |
2333 I |
2326 end |
2334 end |
2327 in |
2335 in |
2422 (map (apsnd do_bound_type) bounds) false |
2430 (map (apsnd do_bound_type) bounds) false |
2423 (do_term tm1) (do_term tm2) |
2431 (do_term tm1) (do_term tm2) |
2424 in |
2432 in |
2425 ([tm1, tm2], |
2433 ([tm1, tm2], |
2426 [Formula (app_op_alias_eq_prefix ^ s2, kind, eq |> maybe_negate, NONE, |
2434 [Formula (app_op_alias_eq_prefix ^ s2, kind, eq |> maybe_negate, NONE, |
2427 isabelle_info format spec_eqN)]) |
2435 isabelle_info format spec_eqN helper_rank)]) |
2428 |> (if ary - 1 = base_ary orelse Symtab.defined sym_tab s1 then I |
2436 |> (if ary - 1 = base_ary orelse Symtab.defined sym_tab s1 then I |
2429 else pair_append (do_alias (ary - 1))) |
2437 else pair_append (do_alias (ary - 1))) |
2430 end |
2438 end |
2431 in do_alias end |
2439 in do_alias end |
2432 fun app_op_alias_lines_for_sym ctxt monom_constrs format conj_sym_kind mono |
2440 fun app_op_alias_lines_for_sym ctxt monom_constrs format conj_sym_kind mono |
2594 val sym_decl_lines = |
2602 val sym_decl_lines = |
2595 (conjs, helpers @ facts, app_op_alias_eq_tms) |
2603 (conjs, helpers @ facts, app_op_alias_eq_tms) |
2596 |> sym_decl_table_for_facts ctxt format type_enc sym_tab |
2604 |> sym_decl_table_for_facts ctxt format type_enc sym_tab |
2597 |> problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono |
2605 |> problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono |
2598 type_enc mono_Ts |
2606 type_enc mono_Ts |
|
2607 val num_facts = length facts |
|
2608 val fact_lines = |
|
2609 map (formula_line_for_fact ctxt polym_constrs format fact_prefix |
|
2610 ascii_of (not exporter) (not exporter) mono type_enc |
|
2611 (rank_of_fact_num num_facts)) |
|
2612 (0 upto num_facts - 1 ~~ facts) |
2599 val helper_lines = |
2613 val helper_lines = |
2600 0 upto length helpers - 1 ~~ helpers |
2614 0 upto length helpers - 1 ~~ helpers |
2601 |> map (formula_line_for_fact ctxt polym_constrs format helper_prefix I |
2615 |> map (formula_line_for_fact ctxt polym_constrs format helper_prefix I |
2602 false true mono type_enc) |
2616 false true mono type_enc (K default_rank)) |
2603 |> (if needs_type_tag_idempotence ctxt type_enc then |
2617 |> (if needs_type_tag_idempotence ctxt type_enc then |
2604 cons (type_tag_idempotence_fact format type_enc) |
2618 cons (type_tag_idempotence_fact format type_enc) |
2605 else |
2619 else |
2606 I) |
2620 I) |
2607 (* Reordering these might confuse the proof reconstruction code or the SPASS |
2621 (* Reordering these might confuse the proof reconstruction code or the SPASS |
2608 FLOTTER hack. *) |
2622 FLOTTER hack. *) |
2609 val problem = |
2623 val problem = |
2610 [(explicit_declsN, class_decl_lines @ sym_decl_lines), |
2624 [(explicit_declsN, class_decl_lines @ sym_decl_lines), |
2611 (app_op_alias_eqsN, app_op_alias_eq_lines), |
2625 (app_op_alias_eqsN, app_op_alias_eq_lines), |
2612 (factsN, |
2626 (factsN, fact_lines), |
2613 map (formula_line_for_fact ctxt polym_constrs format fact_prefix |
|
2614 ascii_of (not exporter) (not exporter) mono type_enc) |
|
2615 (0 upto length facts - 1 ~~ facts)), |
|
2616 (class_relsN, |
2627 (class_relsN, |
2617 map (formula_line_for_class_rel_clause format type_enc) |
2628 map (formula_line_for_class_rel_clause format type_enc) |
2618 class_rel_clauses), |
2629 class_rel_clauses), |
2619 (aritiesN, |
2630 (aritiesN, |
2620 map (formula_line_for_arity_clause format type_enc) arity_clauses), |
2631 map (formula_line_for_arity_clause format type_enc) arity_clauses), |