1018 val introduce_combinators = simple_translate_lambdas do_introduce_combinators |
1018 val introduce_combinators = simple_translate_lambdas do_introduce_combinators |
1019 |
1019 |
1020 fun preprocess_abstractions_in_terms trans_lambdas facts = |
1020 fun preprocess_abstractions_in_terms trans_lambdas facts = |
1021 let |
1021 let |
1022 val (facts, lambda_ts) = |
1022 val (facts, lambda_ts) = |
1023 facts |> map (snd o snd) |> trans_lambdas |
1023 facts |> map (snd o snd) |> trans_lambdas |
1024 |>> map2 (fn (name, (kind, _)) => fn t => (name, (kind, t))) facts |
1024 |>> map2 (fn (name, (kind, _)) => fn t => (name, (kind, t))) facts |
1025 val lambda_facts = |
1025 val lambda_facts = |
1026 map2 (fn t => fn j => |
1026 map2 (fn t => fn j => |
1027 ((lambda_fact_prefix ^ Int.toString j, Helper), (Axiom, t))) |
1027 ((lambda_fact_prefix ^ Int.toString j, Helper), (Axiom, t))) |
1028 lambda_ts (1 upto length lambda_ts) |
1028 lambda_ts (1 upto length lambda_ts) |
1244 | _ => accum) |
1244 | _ => accum) |
1245 |> fold (add false) args |
1245 |> fold (add false) args |
1246 end |
1246 end |
1247 in add true end |
1247 in add true end |
1248 fun add_fact_syms_to_table ctxt explicit_apply = |
1248 fun add_fact_syms_to_table ctxt explicit_apply = |
1249 formula_fold NONE (K (add_iterm_syms_to_table ctxt explicit_apply)) |
1249 K (add_iterm_syms_to_table ctxt explicit_apply) |
1250 |> fact_lift |
1250 |> formula_fold NONE |> fact_lift |
1251 |
1251 |
1252 val tvar_a = TVar (("'a", 0), HOLogic.typeS) |
1252 val tvar_a = TVar (("'a", 0), HOLogic.typeS) |
1253 |
1253 |
1254 val default_sym_tab_entries : (string * sym_info) list = |
1254 val default_sym_tab_entries : (string * sym_info) list = |
1255 (prefixed_predicator_name, |
1255 (prefixed_predicator_name, |
1787 | IAbs (_, tm) => add_iterm_syms in_conj tm |
1787 | IAbs (_, tm) => add_iterm_syms in_conj tm |
1788 | _ => I) |
1788 | _ => I) |
1789 #> fold (add_iterm_syms in_conj) args |
1789 #> fold (add_iterm_syms in_conj) args |
1790 end |
1790 end |
1791 fun add_fact_syms in_conj = |
1791 fun add_fact_syms in_conj = |
1792 fact_lift (formula_fold NONE (K (add_iterm_syms in_conj))) |
1792 K (add_iterm_syms in_conj) |> formula_fold NONE |> fact_lift |
1793 fun add_formula_var_types (AQuant (_, xs, phi)) = |
1793 fun add_formula_var_types (AQuant (_, xs, phi)) = |
1794 fold (fn (_, SOME T) => insert_type ctxt I T | _ => I) xs |
1794 fold (fn (_, SOME T) => insert_type ctxt I T | _ => I) xs |
1795 #> add_formula_var_types phi |
1795 #> add_formula_var_types phi |
1796 | add_formula_var_types (AConn (_, phis)) = |
1796 | add_formula_var_types (AConn (_, phis)) = |
1797 fold add_formula_var_types phis |
1797 fold add_formula_var_types phis |
1883 default_mono |
1883 default_mono |
1884 |> is_type_level_monotonicity_based level |
1884 |> is_type_level_monotonicity_based level |
1885 ? fold (add_fact_mononotonicity_info ctxt level) facts |
1885 ? fold (add_fact_mononotonicity_info ctxt level) facts |
1886 end |
1886 end |
1887 |
1887 |
|
1888 fun add_iformula_monotonic_types ctxt mono type_enc = |
|
1889 let |
|
1890 val level = level_of_type_enc type_enc |
|
1891 val should_encode = should_encode_type ctxt mono level |
|
1892 fun add_type T = should_encode T ? insert_type ctxt I T |
|
1893 fun add_term (tm as IApp (tm1, tm2)) = |
|
1894 add_type (ityp_of tm) #> add_term tm1 #> add_term tm2 |
|
1895 | add_term tm = add_type (ityp_of tm) |
|
1896 in formula_fold NONE (K add_term) end |
|
1897 fun add_fact_monotonic_types ctxt mono type_enc = |
|
1898 add_iformula_monotonic_types ctxt mono type_enc |> fact_lift |
|
1899 fun monotonic_types_for_facts ctxt mono type_enc facts = |
|
1900 [] |> (polymorphism_of_type_enc type_enc = Polymorphic andalso |
|
1901 is_type_level_monotonicity_based (level_of_type_enc type_enc)) |
|
1902 ? fold (add_fact_monotonic_types ctxt mono type_enc) facts |
|
1903 |
1888 fun formula_line_for_guards_mono_type ctxt format mono type_enc T = |
1904 fun formula_line_for_guards_mono_type ctxt format mono type_enc T = |
1889 Formula (guards_sym_formula_prefix ^ |
1905 Formula (guards_sym_formula_prefix ^ |
1890 ascii_of (mangled_type format type_enc T), |
1906 ascii_of (mangled_type format type_enc T), |
1891 Axiom, |
1907 Axiom, |
1892 IConst (`make_bound_var "X", T, []) |
1908 IConst (`make_bound_var "X", T, []) |
2044 |> maps (formula_lines_for_nonuniform_tags_sym_decl ctxt format |
2060 |> maps (formula_lines_for_nonuniform_tags_sym_decl ctxt format |
2045 conj_sym_kind mono type_enc n s) |
2061 conj_sym_kind mono type_enc n s) |
2046 end) |
2062 end) |
2047 |
2063 |
2048 fun problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono type_enc |
2064 fun problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono type_enc |
2049 sym_decl_tab = |
2065 mono_Ts sym_decl_tab = |
2050 let |
2066 let |
2051 val syms = sym_decl_tab |> Symtab.dest |> sort_wrt fst |
2067 val syms = sym_decl_tab |> Symtab.dest |> sort_wrt fst |
2052 val mono_Ts = |
|
2053 if polymorphism_of_type_enc type_enc = Polymorphic then |
|
2054 syms |> maps (map result_type_of_decl o snd) |
|
2055 |> filter_out (should_encode_type ctxt mono |
|
2056 (level_of_type_enc type_enc)) |
|
2057 |> rpair [] |-> fold (insert_type ctxt I) |
|
2058 else |
|
2059 [] |
|
2060 val mono_lines = |
2068 val mono_lines = |
2061 problem_lines_for_mono_types ctxt format mono type_enc mono_Ts |
2069 problem_lines_for_mono_types ctxt format mono type_enc mono_Ts |
2062 val decl_lines = |
2070 val decl_lines = |
2063 fold_rev (append o problem_lines_for_sym_decls ctxt format conj_sym_kind |
2071 fold_rev (append o problem_lines_for_sym_decls ctxt format conj_sym_kind |
2064 mono type_enc) |
2072 mono type_enc) |
2129 val repaired_sym_tab = |
2137 val repaired_sym_tab = |
2130 conjs @ facts |> sym_table_for_facts ctxt (SOME false) |
2138 conjs @ facts |> sym_table_for_facts ctxt (SOME false) |
2131 val helpers = |
2139 val helpers = |
2132 repaired_sym_tab |> helper_facts_for_sym_table ctxt format type_enc |
2140 repaired_sym_tab |> helper_facts_for_sym_table ctxt format type_enc |
2133 |> map repair |
2141 |> map repair |
|
2142 val mono_Ts = |
|
2143 helpers @ conjs @ facts |
|
2144 |> monotonic_types_for_facts ctxt mono type_enc |
2134 val sym_decl_lines = |
2145 val sym_decl_lines = |
2135 (conjs, helpers @ facts) |
2146 (conjs, helpers @ facts) |
2136 |> sym_decl_table_for_facts ctxt format type_enc repaired_sym_tab |
2147 |> sym_decl_table_for_facts ctxt format type_enc repaired_sym_tab |
2137 |> problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono |
2148 |> problem_lines_for_sym_decl_table ctxt format conj_sym_kind mono |
2138 type_enc |
2149 type_enc mono_Ts |
2139 val helper_lines = |
2150 val helper_lines = |
2140 0 upto length helpers - 1 ~~ helpers |
2151 0 upto length helpers - 1 ~~ helpers |
2141 |> map (formula_line_for_fact ctxt format helper_prefix I false true mono |
2152 |> map (formula_line_for_fact ctxt format helper_prefix I false true mono |
2142 type_enc) |
2153 type_enc) |
2143 |> (if needs_type_tag_idempotence ctxt type_enc then |
2154 |> (if needs_type_tag_idempotence ctxt type_enc then |