387 let |
392 let |
388 val tvars = map (prefix tvar_prefix o string_of_int) (1 upto length args) |
393 val tvars = map (prefix tvar_prefix o string_of_int) (1 upto length args) |
389 val tvars_srts = ListPair.zip (tvars, args) |
394 val tvars_srts = ListPair.zip (tvars, args) |
390 in |
395 in |
391 {name = name, |
396 {name = name, |
392 prem_lits = [] |> fold (uncurry add_packed_sort) tvars_srts |> map TVarLit, |
397 prem_lits = |
393 concl_lits = TConsLit (`make_type_class cls, `make_fixed_type_const tcons, |
398 [] |> fold (uncurry add_packed_sort) tvars_srts |> map AryLitVar, |
394 tvars ~~ tvars)} |
399 concl_lits = |
|
400 AryLitConst (`make_type_class cls, `make_fixed_type_const tcons, |
|
401 tvars ~~ tvars)} |
395 end |
402 end |
396 |
403 |
397 fun arity_clause _ _ (_, []) = [] |
404 fun arity_clause _ _ (_, []) = [] |
398 | arity_clause seen n (tcons, ("HOL.type", _) :: ars) = (* ignore *) |
405 | arity_clause seen n (tcons, ("HOL.type", _) :: ars) = (* ignore *) |
399 arity_clause seen n (tcons, ars) |
406 arity_clause seen n (tcons, ars) |
1274 in add true end |
1281 in add true end |
1275 fun add_fact_syms_to_table ctxt explicit_apply = |
1282 fun add_fact_syms_to_table ctxt explicit_apply = |
1276 K (add_iterm_syms_to_table ctxt explicit_apply) |
1283 K (add_iterm_syms_to_table ctxt explicit_apply) |
1277 |> formula_fold NONE |> fact_lift |
1284 |> formula_fold NONE |> fact_lift |
1278 |
1285 |
1279 val tvar_a = TVar (("'a", 0), HOLogic.typeS) |
1286 val tvar_a_str = "'a" |
|
1287 val tvar_a = TVar ((tvar_a_str, 0), HOLogic.typeS) |
|
1288 val tvar_a_name = (make_schematic_type_var (tvar_a_str, 0), tvar_a_str) |
|
1289 val itself_name = `make_fixed_type_const @{type_name itself} |
|
1290 val TYPE_name = `(make_fixed_const NONE) @{const_name TYPE} |
|
1291 val tvar_a_atype = AType (tvar_a_name, []) |
|
1292 val a_itself_atype = AType (itself_name, [tvar_a_atype]) |
1280 |
1293 |
1281 val default_sym_tab_entries : (string * sym_info) list = |
1294 val default_sym_tab_entries : (string * sym_info) list = |
1282 (prefixed_predicator_name, |
1295 (prefixed_predicator_name, |
1283 {pred_sym = true, min_ary = 1, max_ary = 1, types = []}) |
1296 {pred_sym = true, min_ary = 1, max_ary = 1, types = []}) |
1284 (* FIXME: needed? *) :: |
1297 (* FIXME: needed? *) :: |
1448 (("fAll", false), [@{lemma "~ fAll P | P x" by (auto simp: fAll_def)}]), |
1461 (("fAll", false), [@{lemma "~ fAll P | P x" by (auto simp: fAll_def)}]), |
1449 (("fEx", false), [@{lemma "~ P x | fEx P" by (auto simp: fEx_def)}]), |
1462 (("fEx", false), [@{lemma "~ P x | fEx P" by (auto simp: fEx_def)}]), |
1450 (("If", true), @{thms if_True if_False True_or_False})] |
1463 (("If", true), @{thms if_True if_False True_or_False})] |
1451 |> map (apsnd (map zero_var_indexes)) |
1464 |> map (apsnd (map zero_var_indexes)) |
1452 |
1465 |
1453 fun fo_literal_from_type_literal (TyLitVar (class, name)) = |
1466 fun type_class_aterm type_enc class arg = |
1454 (true, ATerm (class, [ATerm (name, [])])) |
1467 case type_enc of |
1455 | fo_literal_from_type_literal (TyLitFree (class, name)) = |
1468 Simple_Types (_, Polymorphic, _) => |
1456 (true, ATerm (class, [ATerm (name, [])])) |
1469 if exploit_tff1_dummy_type_vars then ATerm (class, [arg]) |
|
1470 else ATerm (class, [arg, ATerm (TYPE_name, [arg])]) |
|
1471 | _ => ATerm (class, [arg]) |
|
1472 |
|
1473 fun fo_literal_from_type_literal type_enc (TyLitVar (class, name)) = |
|
1474 (true, type_class_aterm type_enc class (ATerm (name, []))) |
|
1475 | fo_literal_from_type_literal type_enc (TyLitFree (class, name)) = |
|
1476 (true, type_class_aterm type_enc class (ATerm (name, []))) |
|
1477 (* FIXME: Really "true" in both cases? If so, merge "TyLitVar" and |
|
1478 "TyLitFree". *) |
1457 |
1479 |
1458 fun formula_from_fo_literal (pos, t) = AAtom t |> not pos ? mk_anot |
1480 fun formula_from_fo_literal (pos, t) = AAtom t |> not pos ? mk_anot |
1459 |
1481 |
1460 fun bound_tvars type_enc Ts = |
1482 fun bound_tvars type_enc Ts = |
1461 mk_ahorn (map (formula_from_fo_literal o fo_literal_from_type_literal) |
1483 mk_ahorn (map (formula_from_fo_literal |
|
1484 o fo_literal_from_type_literal type_enc) |
1462 (type_literals_for_types type_enc add_sorts_on_tvar Ts)) |
1485 (type_literals_for_types type_enc add_sorts_on_tvar Ts)) |
1463 |
1486 |
1464 fun eq_formula type_enc atomic_Ts pred_sym tm1 tm2 = |
1487 fun eq_formula type_enc atomic_Ts pred_sym tm1 tm2 = |
1465 (if pred_sym then AConn (AIff, [AAtom tm1, AAtom tm2]) |
1488 (if pred_sym then AConn (AIff, [AAtom tm1, AAtom tm2]) |
1466 else AAtom (ATerm (`I tptp_equal, [tm1, tm2]))) |
1489 else AAtom (ATerm (`I tptp_equal, [tm1, tm2]))) |
1736 | _ => NONE) |
1759 | _ => NONE) |
1737 |> Formula |
1760 |> Formula |
1738 |
1761 |
1739 fun formula_line_for_class_rel_clause type_enc |
1762 fun formula_line_for_class_rel_clause type_enc |
1740 ({name, subclass, superclass, ...} : class_rel_clause) = |
1763 ({name, subclass, superclass, ...} : class_rel_clause) = |
1741 let val ty_arg = ATerm ((make_schematic_type_var ("'a", 0), "'a"), []) in |
1764 let val ty_arg = ATerm (tvar_a_name, []) in |
1742 Formula (class_rel_clause_prefix ^ ascii_of name, Axiom, |
1765 Formula (class_rel_clause_prefix ^ ascii_of name, Axiom, |
1743 AConn (AImplies, [AAtom (ATerm (subclass, [ty_arg])), |
1766 AConn (AImplies, |
1744 AAtom (ATerm (superclass, [ty_arg]))]) |
1767 [AAtom (type_class_aterm type_enc subclass ty_arg), |
|
1768 AAtom (type_class_aterm type_enc superclass ty_arg)]) |
1745 |> close_formula_universally type_enc, isabelle_info introN, NONE) |
1769 |> close_formula_universally type_enc, isabelle_info introN, NONE) |
1746 end |
1770 end |
1747 |
1771 |
1748 fun fo_literal_from_arity_literal (TConsLit (c, t, args)) = |
1772 fun fo_literal_from_arity_literal type_enc (AryLitConst (class, t, args)) = |
1749 (true, ATerm (c, [ATerm (t, map (fn arg => ATerm (arg, [])) args)])) |
1773 (true, type_class_aterm type_enc class |
1750 | fo_literal_from_arity_literal (TVarLit (c, sort)) = |
1774 (ATerm (t, map (fn arg => ATerm (arg, [])) args))) |
1751 (false, ATerm (c, [ATerm (sort, [])])) |
1775 | fo_literal_from_arity_literal type_enc (AryLitVar (class, var)) = |
|
1776 (false, type_class_aterm type_enc class (ATerm (var, []))) |
1752 |
1777 |
1753 fun formula_line_for_arity_clause type_enc |
1778 fun formula_line_for_arity_clause type_enc |
1754 ({name, prem_lits, concl_lits, ...} : arity_clause) = |
1779 ({name, prem_lits, concl_lits, ...} : arity_clause) = |
1755 Formula (arity_clause_prefix ^ name, Axiom, |
1780 Formula (arity_clause_prefix ^ name, Axiom, |
1756 mk_ahorn (map (formula_from_fo_literal o apfst not |
1781 mk_ahorn (map (formula_from_fo_literal o apfst not |
1757 o fo_literal_from_arity_literal) prem_lits) |
1782 o fo_literal_from_arity_literal type_enc) prem_lits) |
1758 (formula_from_fo_literal |
1783 (formula_from_fo_literal |
1759 (fo_literal_from_arity_literal concl_lits)) |
1784 (fo_literal_from_arity_literal type_enc concl_lits)) |
1760 |> close_formula_universally type_enc, isabelle_info introN, NONE) |
1785 |> close_formula_universally type_enc, isabelle_info introN, NONE) |
1761 |
1786 |
1762 fun formula_line_for_conjecture ctxt format mono type_enc |
1787 fun formula_line_for_conjecture ctxt format mono type_enc |
1763 ({name, kind, iformula, atomic_types, ...} : translated_formula) = |
1788 ({name, kind, iformula, atomic_types, ...} : translated_formula) = |
1764 Formula (conjecture_prefix ^ name, kind, |
1789 Formula (conjecture_prefix ^ name, kind, |
1768 |> bound_tvars type_enc atomic_types |
1793 |> bound_tvars type_enc atomic_types |
1769 |> close_formula_universally type_enc, NONE, NONE) |
1794 |> close_formula_universally type_enc, NONE, NONE) |
1770 |
1795 |
1771 fun free_type_literals type_enc ({atomic_types, ...} : translated_formula) = |
1796 fun free_type_literals type_enc ({atomic_types, ...} : translated_formula) = |
1772 atomic_types |> type_literals_for_types type_enc add_sorts_on_tfree |
1797 atomic_types |> type_literals_for_types type_enc add_sorts_on_tfree |
1773 |> map fo_literal_from_type_literal |
1798 |> map (fo_literal_from_type_literal type_enc) |
1774 |
1799 |
1775 fun formula_line_for_free_type j lit = |
1800 fun formula_line_for_free_type j lit = |
1776 Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, |
1801 Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, |
1777 formula_from_fo_literal lit, NONE, NONE) |
1802 formula_from_fo_literal lit, NONE, NONE) |
1778 fun formula_lines_for_free_types type_enc facts = |
1803 fun formula_lines_for_free_types type_enc facts = |
1783 |
1808 |
1784 (** Symbol declarations **) |
1809 (** Symbol declarations **) |
1785 |
1810 |
1786 fun decl_line_for_class s = |
1811 fun decl_line_for_class s = |
1787 let val name as (s, _) = `make_type_class s in |
1812 let val name as (s, _) = `make_type_class s in |
1788 Decl (sym_decl_prefix ^ s, name, AFun (atype_of_types, bool_atype)) |
1813 Decl (sym_decl_prefix ^ s, name, |
|
1814 if exploit_tff1_dummy_type_vars then |
|
1815 AFun (atype_of_types, bool_atype) |
|
1816 else |
|
1817 ATyAbs ([tvar_a_name], AFun (a_itself_atype, bool_atype))) |
1789 end |
1818 end |
1790 |
1819 |
1791 fun decl_lines_for_classes type_enc classes = |
1820 fun decl_lines_for_classes type_enc classes = |
1792 case type_enc of |
1821 case type_enc of |
1793 Simple_Types (_, Polymorphic, _) => map decl_line_for_class classes |
1822 Simple_Types (_, Polymorphic, _) => map decl_line_for_class classes |
1831 if polymorphism_of_type_enc type_enc = Polymorphic then [tvar_a] |
1860 if polymorphism_of_type_enc type_enc = Polymorphic then [tvar_a] |
1832 else fold (fact_lift add_formula_var_types) (conjs @ facts) [] |
1861 else fold (fact_lift add_formula_var_types) (conjs @ facts) [] |
1833 fun add_undefined_const T = |
1862 fun add_undefined_const T = |
1834 let |
1863 let |
1835 val (s, s') = |
1864 val (s, s') = |
1836 `(make_fixed_const (SOME format)) @{const_name undefined} |
1865 `(make_fixed_const NONE) @{const_name undefined} |
1837 |> (case type_arg_policy type_enc @{const_name undefined} of |
1866 |> (case type_arg_policy type_enc @{const_name undefined} of |
1838 Mangled_Type_Args _ => mangled_const_name format type_enc [T] |
1867 Mangled_Type_Args _ => mangled_const_name format type_enc [T] |
1839 | _ => I) |
1868 | _ => I) |
1840 in |
1869 in |
1841 Symtab.map_default (s, []) |
1870 Symtab.map_default (s, []) |
1842 (insert_type ctxt #3 (s', [T], T, false, 0, false)) |
1871 (insert_type ctxt #3 (s', [T], T, false, 0, false)) |
1843 end |
1872 end |
|
1873 fun add_TYPE_const () = |
|
1874 let val (s, s') = TYPE_name in |
|
1875 Symtab.map_default (s, []) |
|
1876 (insert_type ctxt #3 |
|
1877 (s', [tvar_a], @{typ "'a itself"}, false, 0, false)) |
|
1878 end |
1844 in |
1879 in |
1845 Symtab.empty |
1880 Symtab.empty |
1846 |> is_type_enc_fairly_sound type_enc |
1881 |> is_type_enc_fairly_sound type_enc |
1847 ? (fold (add_fact_syms true) conjs |
1882 ? (fold (add_fact_syms true) conjs |
1848 #> fold (add_fact_syms false) facts |
1883 #> fold (add_fact_syms false) facts |
1849 #> (case type_enc of |
1884 #> (case type_enc of |
1850 Simple_Types _ => I |
1885 Simple_Types (_, poly, _) => |
|
1886 if poly = Polymorphic then add_TYPE_const () else I |
1851 | _ => fold add_undefined_const (var_types ()))) |
1887 | _ => fold add_undefined_const (var_types ()))) |
1852 end |
1888 end |
1853 |
1889 |
1854 (* We add "bool" in case the helper "True_or_False" is included later. *) |
1890 (* We add "bool" in case the helper "True_or_False" is included later. *) |
1855 val default_mono = |
1891 val default_mono = |