1214 NONE) |
1214 NONE) |
1215 end |
1215 end |
1216 end |
1216 end |
1217 handle TYPE _ => T_args |
1217 handle TYPE _ => T_args |
1218 |
1218 |
1219 fun enforce_type_arg_policy_in_combterm ctxt format nonmono_Ts type_sys = |
1219 fun enforce_type_arg_policy_in_combterm ctxt format type_sys = |
1220 let |
1220 let |
1221 val thy = Proof_Context.theory_of ctxt |
1221 val thy = Proof_Context.theory_of ctxt |
1222 fun aux arity (CombApp (tm1, tm2)) = |
1222 fun aux arity (CombApp (tm1, tm2)) = |
1223 CombApp (aux (arity + 1) tm1, aux 0 tm2) |
1223 CombApp (aux (arity + 1) tm1, aux 0 tm2) |
1224 | aux arity (CombConst (name as (s, _), T, T_args)) = |
1224 | aux arity (CombConst (name as (s, _), T, T_args)) = |
1225 let |
1225 (case strip_prefix_and_unascii const_prefix s of |
1226 val level = level_of_type_sys type_sys |
1226 NONE => (name, T_args) |
1227 val (T, T_args) = |
1227 | SOME s'' => |
1228 (* Aggressively merge most "hAPPs" if the type system is unsound |
1228 let |
1229 anyway, by distinguishing overloads only on the homogenized |
1229 val s'' = invert_const s'' |
1230 result type. Don't do it for lightweight type systems, though, |
1230 fun filtered_T_args false = T_args |
1231 since it leads to too many unsound proofs. *) |
1231 | filtered_T_args true = filter_type_args thy s'' arity T_args |
1232 if s = prefixed_app_op_name andalso length T_args = 2 andalso |
1232 in |
1233 not (is_type_sys_virtually_sound type_sys) andalso |
1233 case type_arg_policy type_sys s'' of |
1234 heaviness_of_type_sys type_sys = Heavyweight then |
1234 Explicit_Type_Args drop_args => |
1235 T_args |> map (homogenized_type ctxt nonmono_Ts level 0) |
1235 (name, filtered_T_args drop_args) |
1236 |> (fn Ts => let val T = hd Ts --> nth Ts 1 in |
1236 | Mangled_Type_Args drop_args => |
1237 (T --> T, tl Ts) |
1237 (mangled_const_name format type_sys (filtered_T_args drop_args) |
1238 end) |
1238 name, []) |
1239 else |
1239 | No_Type_Args => (name, []) |
1240 (T, T_args) |
1240 end) |
1241 in |
1241 |> (fn (name, T_args) => CombConst (name, T, T_args)) |
1242 (case strip_prefix_and_unascii const_prefix s of |
|
1243 NONE => (name, T_args) |
|
1244 | SOME s'' => |
|
1245 let |
|
1246 val s'' = invert_const s'' |
|
1247 fun filtered_T_args false = T_args |
|
1248 | filtered_T_args true = filter_type_args thy s'' arity T_args |
|
1249 in |
|
1250 case type_arg_policy type_sys s'' of |
|
1251 Explicit_Type_Args drop_args => |
|
1252 (name, filtered_T_args drop_args) |
|
1253 | Mangled_Type_Args drop_args => |
|
1254 (mangled_const_name format type_sys (filtered_T_args drop_args) |
|
1255 name, []) |
|
1256 | No_Type_Args => (name, []) |
|
1257 end) |
|
1258 |> (fn (name, T_args) => CombConst (name, T, T_args)) |
|
1259 end |
|
1260 | aux _ tm = tm |
1242 | aux _ tm = tm |
1261 in aux 0 end |
1243 in aux 0 end |
1262 |
1244 |
1263 fun repair_combterm ctxt format nonmono_Ts type_sys sym_tab = |
1245 fun repair_combterm ctxt format type_sys sym_tab = |
1264 not (is_setting_higher_order format type_sys) |
1246 not (is_setting_higher_order format type_sys) |
1265 ? (introduce_explicit_apps_in_combterm sym_tab |
1247 ? (introduce_explicit_apps_in_combterm sym_tab |
1266 #> introduce_predicators_in_combterm sym_tab) |
1248 #> introduce_predicators_in_combterm sym_tab) |
1267 #> enforce_type_arg_policy_in_combterm ctxt format nonmono_Ts type_sys |
1249 #> enforce_type_arg_policy_in_combterm ctxt format type_sys |
1268 fun repair_fact ctxt format nonmono_Ts type_sys sym_tab = |
1250 fun repair_fact ctxt format type_sys sym_tab = |
1269 update_combformula (formula_map |
1251 update_combformula (formula_map |
1270 (repair_combterm ctxt format nonmono_Ts type_sys sym_tab)) |
1252 (repair_combterm ctxt format type_sys sym_tab)) |
1271 |
1253 |
1272 (** Helper facts **) |
1254 (** Helper facts **) |
1273 |
1255 |
1274 (* The Boolean indicates that a fairly sound type encoding is needed. |
1256 (* The Boolean indicates that a fairly sound type encoding is needed. |
1275 "false" must precede "true" to ensure consistent numbering and a correct |
1257 "false" must precede "true" to ensure consistent numbering and a correct |
1439 |
1421 |
1440 fun formula_from_fo_literal (pos, t) = AAtom t |> not pos ? mk_anot |
1422 fun formula_from_fo_literal (pos, t) = AAtom t |> not pos ? mk_anot |
1441 |
1423 |
1442 val type_pred = `make_fixed_const type_pred_name |
1424 val type_pred = `make_fixed_const type_pred_name |
1443 |
1425 |
1444 fun type_pred_combterm ctxt format nonmono_Ts type_sys T tm = |
1426 fun type_pred_combterm ctxt format type_sys T tm = |
1445 (CombConst (type_pred, T --> @{typ bool}, [T]) |
1427 CombApp (CombConst (type_pred, T --> @{typ bool}, [T]) |
1446 |> enforce_type_arg_policy_in_combterm ctxt format nonmono_Ts type_sys, tm) |
1428 |> enforce_type_arg_policy_in_combterm ctxt format type_sys, tm) |
1447 |> CombApp |
|
1448 |
1429 |
1449 fun var_occurs_positively_naked_in_term _ (SOME false) _ accum = accum |
1430 fun var_occurs_positively_naked_in_term _ (SOME false) _ accum = accum |
1450 | var_occurs_positively_naked_in_term name _ (ATerm ((s, _), tms)) accum = |
1431 | var_occurs_positively_naked_in_term name _ (ATerm ((s, _), tms)) accum = |
1451 accum orelse (is_tptp_equal s andalso member (op =) tms (ATerm (name, []))) |
1432 accum orelse (is_tptp_equal s andalso member (op =) tms (ATerm (name, []))) |
1452 fun is_var_nonmonotonic_in_formula _ _ (SOME false) _ = false |
1433 fun is_var_nonmonotonic_in_formula _ _ (SOME false) _ = false |
1456 fun mk_const_aterm format type_sys x T_args args = |
1437 fun mk_const_aterm format type_sys x T_args args = |
1457 ATerm (x, map (fo_term_from_typ format type_sys) T_args @ args) |
1438 ATerm (x, map (fo_term_from_typ format type_sys) T_args @ args) |
1458 |
1439 |
1459 fun tag_with_type ctxt format nonmono_Ts type_sys T tm = |
1440 fun tag_with_type ctxt format nonmono_Ts type_sys T tm = |
1460 CombConst (type_tag, T --> T, [T]) |
1441 CombConst (type_tag, T --> T, [T]) |
1461 |> enforce_type_arg_policy_in_combterm ctxt format nonmono_Ts type_sys |
1442 |> enforce_type_arg_policy_in_combterm ctxt format type_sys |
1462 |> term_from_combterm ctxt format nonmono_Ts type_sys Top_Level |
1443 |> term_from_combterm ctxt format nonmono_Ts type_sys Top_Level |
1463 |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm])) |
1444 |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm])) |
1464 and term_from_combterm ctxt format nonmono_Ts type_sys = |
1445 and term_from_combterm ctxt format nonmono_Ts type_sys = |
1465 let |
1446 let |
1466 fun aux site u = |
1447 fun aux site u = |
1637 |
1618 |
1638 (* This inference is described in section 2.3 of Claessen et al.'s "Sorting it |
1619 (* This inference is described in section 2.3 of Claessen et al.'s "Sorting it |
1639 out with monotonicity" paper presented at CADE 2011. *) |
1620 out with monotonicity" paper presented at CADE 2011. *) |
1640 fun add_combterm_nonmonotonic_types _ _ (SOME false) _ = I |
1621 fun add_combterm_nonmonotonic_types _ _ (SOME false) _ = I |
1641 | add_combterm_nonmonotonic_types ctxt level _ |
1622 | add_combterm_nonmonotonic_types ctxt level _ |
1642 (CombApp (CombApp (CombConst ((s, _), Type (_, [T, _]), _), tm1), tm2)) = |
1623 (CombApp (CombApp (CombConst ((s, _), Type (_, [T, _]), _), tm1), |
|
1624 tm2)) = |
1643 (is_tptp_equal s andalso exists is_var_or_bound_var [tm1, tm2] andalso |
1625 (is_tptp_equal s andalso exists is_var_or_bound_var [tm1, tm2] andalso |
1644 (case level of |
1626 (case level of |
1645 Nonmonotonic_Types => |
1627 Nonmonotonic_Types => |
1646 not (is_type_surely_infinite ctxt known_infinite_types T) |
1628 not (is_type_surely_infinite ctxt known_infinite_types T) |
1647 | Finite_Types => is_type_surely_finite ctxt T |
1629 | Finite_Types => is_type_surely_finite ctxt T |
1695 in |
1677 in |
1696 Formula (preds_sym_formula_prefix ^ s ^ |
1678 Formula (preds_sym_formula_prefix ^ s ^ |
1697 (if n > 1 then "_" ^ string_of_int j else ""), kind, |
1679 (if n > 1 then "_" ^ string_of_int j else ""), kind, |
1698 CombConst ((s, s'), T, T_args) |
1680 CombConst ((s, s'), T, T_args) |
1699 |> fold (curry (CombApp o swap)) bounds |
1681 |> fold (curry (CombApp o swap)) bounds |
1700 |> type_pred_combterm ctxt format nonmono_Ts type_sys res_T |
1682 |> type_pred_combterm ctxt format type_sys res_T |
1701 |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts) |
1683 |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts) |
1702 |> formula_from_combformula ctxt format nonmono_Ts type_sys |
1684 |> formula_from_combformula ctxt format nonmono_Ts type_sys |
1703 (K (K (K (K true)))) true |
1685 (K (K (K (K true)))) true |
1704 |> n > 1 ? bound_tvars type_sys (atyps_of T) |
1686 |> n > 1 ? bound_tvars type_sys (atyps_of T) |
1705 |> close_formula_universally |
1687 |> close_formula_universally |
1830 val (fact_names, (conjs, facts, class_rel_clauses, arity_clauses)) = |
1812 val (fact_names, (conjs, facts, class_rel_clauses, arity_clauses)) = |
1831 translate_formulas ctxt format prem_kind type_sys preproc hyp_ts concl_t |
1813 translate_formulas ctxt format prem_kind type_sys preproc hyp_ts concl_t |
1832 facts |
1814 facts |
1833 val sym_tab = conjs @ facts |> sym_table_for_facts ctxt explicit_apply |
1815 val sym_tab = conjs @ facts |> sym_table_for_facts ctxt explicit_apply |
1834 val nonmono_Ts = conjs @ facts |> nonmonotonic_types_for_facts ctxt type_sys |
1816 val nonmono_Ts = conjs @ facts |> nonmonotonic_types_for_facts ctxt type_sys |
1835 val repair = repair_fact ctxt format nonmono_Ts type_sys sym_tab |
1817 val repair = repair_fact ctxt format type_sys sym_tab |
1836 val (conjs, facts) = (conjs, facts) |> pairself (map repair) |
1818 val (conjs, facts) = (conjs, facts) |> pairself (map repair) |
1837 val repaired_sym_tab = |
1819 val repaired_sym_tab = |
1838 conjs @ facts |> sym_table_for_facts ctxt (SOME false) |
1820 conjs @ facts |> sym_table_for_facts ctxt (SOME false) |
1839 val helpers = |
1821 val helpers = |
1840 repaired_sym_tab |> helper_facts_for_sym_table ctxt format type_sys |
1822 repaired_sym_tab |> helper_facts_for_sym_table ctxt format type_sys |