equal
deleted
inserted
replaced
881 else |
881 else |
882 T_args |
882 T_args |
883 end) |
883 end) |
884 end |
884 end |
885 |
885 |
886 val fused_infinite_type_name = "ATP.fused_inf" (* shouldn't clash *) |
|
887 val fused_infinite_type = Type (fused_infinite_type_name, []) |
|
888 |
|
889 fun raw_atp_type_of_typ type_enc = |
886 fun raw_atp_type_of_typ type_enc = |
890 let |
887 let |
891 fun term (Type (s, Ts)) = |
888 fun term (Type (s, Ts)) = |
892 AType |
889 AType |
893 ((if s = \<^type_name>\<open>fun\<close> andalso is_type_enc_higher_order type_enc then |
890 ((if s = \<^type_name>\<open>fun\<close> andalso is_type_enc_higher_order type_enc then |
894 `I tptp_fun_type |
891 `I tptp_fun_type |
895 else if s = \<^type_name>\<open>bool\<close> andalso is_type_enc_full_higher_order type_enc then |
892 else if s = \<^type_name>\<open>bool\<close> andalso is_type_enc_full_higher_order type_enc then |
896 `I tptp_bool_type |
893 `I tptp_bool_type |
897 else if s = fused_infinite_type_name andalso is_type_enc_native type_enc then |
|
898 `I tptp_individual_type |
|
899 else |
894 else |
900 `make_fixed_type_const s, []), map term Ts) |
895 `make_fixed_type_const s, []), map term Ts) |
901 | term (TFree (s, _)) = AType ((`make_tfree s, []), []) |
896 | term (TFree (s, _)) = AType ((`make_tfree s, []), []) |
902 | term (TVar z) = AType ((tvar_name z, []), []) |
897 | term (TVar z) = AType ((tvar_name z, []), []) |
903 in term end |
898 in term end |
1386 | (Arg (s, j, ary), true) => member (op =) (type_arg_cover thy NONE s ary) j |
1381 | (Arg (s, j, ary), true) => member (op =) (type_arg_cover thy NONE s ary) j |
1387 | _ => false) |
1382 | _ => false) |
1388 | _ => should_encode_type ctxt mono level T) |
1383 | _ => should_encode_type ctxt mono level T) |
1389 end |
1384 end |
1390 | should_tag_with_type _ _ _ _ _ _ = false |
1385 | should_tag_with_type _ _ _ _ _ _ = false |
1391 |
|
1392 fun fused_type ctxt mono level = |
|
1393 let |
|
1394 val should_encode = should_encode_type ctxt mono level |
|
1395 fun fuse 0 T = if should_encode T then T else fused_infinite_type |
|
1396 | fuse ary (Type (\<^type_name>\<open>fun\<close>, [T1, T2])) = |
|
1397 fuse 0 T1 --> fuse (ary - 1) T2 |
|
1398 | fuse _ _ = raise Fail "expected function type" |
|
1399 in fuse end |
|
1400 |
1386 |
1401 (** predicators and application operators **) |
1387 (** predicators and application operators **) |
1402 |
1388 |
1403 type sym_info = |
1389 type sym_info = |
1404 {pred_sym : bool, min_ary : int, max_ary : int, types : typ list, |
1390 {pred_sym : bool, min_ary : int, max_ary : int, types : typ list, |
1944 fun mk_aterm type_enc name T_args args = |
1930 fun mk_aterm type_enc name T_args args = |
1945 let val (ty_args, tm_args) = process_type_args type_enc T_args in |
1931 let val (ty_args, tm_args) = process_type_args type_enc T_args in |
1946 ATerm ((name, ty_args), tm_args @ args) |
1932 ATerm ((name, ty_args), tm_args @ args) |
1947 end |
1933 end |
1948 |
1934 |
1949 fun do_bound_type ctxt mono type_enc = |
1935 fun do_bound_type type_enc = |
1950 (case type_enc of |
1936 (case type_enc of |
1951 Native (_, _, level) => |
1937 Native _ => native_atp_type_of_typ type_enc false 0 #> SOME |
1952 fused_type ctxt mono level 0 #> native_atp_type_of_typ type_enc false 0 #> SOME |
|
1953 | _ => K NONE) |
1938 | _ => K NONE) |
1954 |
1939 |
1955 fun tag_with_type ctxt mono type_enc pos T tm = |
1940 fun tag_with_type ctxt mono type_enc pos T tm = |
1956 IConst (type_tag, T --> T, [T]) |
1941 IConst (type_tag, T --> T, [T]) |
1957 |> mangle_type_args_in_iterm type_enc |
1942 |> mangle_type_args_in_iterm type_enc |
2009 ATyQuant (q, map (apfst (native_atp_type_of_typ type_enc false 0)) xs, do_formula pos phi) |
1994 ATyQuant (q, map (apfst (native_atp_type_of_typ type_enc false 0)) xs, do_formula pos phi) |
2010 | do_formula pos (AQuant (q, xs, phi)) = |
1995 | do_formula pos (AQuant (q, xs, phi)) = |
2011 let |
1996 let |
2012 val phi = phi |> do_formula pos |
1997 val phi = phi |> do_formula pos |
2013 val universal = Option.map (q = AExists ? not) pos |
1998 val universal = Option.map (q = AExists ? not) pos |
2014 val do_bound_type = do_bound_type ctxt mono type_enc |
|
2015 in |
1999 in |
2016 AQuant (q, xs |> map (apsnd (fn NONE => NONE |
2000 AQuant (q, xs |> map (apsnd (fn NONE => NONE |
2017 | SOME T => do_bound_type T)), |
2001 | SOME T => do_bound_type type_enc T)), |
2018 (if q = AForall then mk_ahorn else fold_rev (mk_aconn AAnd)) |
2002 (if q = AForall then mk_ahorn else fold_rev (mk_aconn AAnd)) |
2019 (map_filter |
2003 (map_filter |
2020 (fn (_, NONE) => NONE |
2004 (fn (_, NONE) => NONE |
2021 | (s, SOME T) => |
2005 | (s, SOME T) => |
2022 do_out_of_bound_type pos phi universal (s, T)) |
2006 do_out_of_bound_type pos phi universal (s, T)) |
2284 (case type_enc of |
2268 (case type_enc of |
2285 Native _ => K [] |
2269 Native _ => K [] |
2286 | Guards _ => map (line_of_guards_mono_type ctxt generate_info mono type_enc) |
2270 | Guards _ => map (line_of_guards_mono_type ctxt generate_info mono type_enc) |
2287 | Tags _ => map (line_of_tags_mono_type ctxt generate_info mono type_enc)) |
2271 | Tags _ => map (line_of_tags_mono_type ctxt generate_info mono type_enc)) |
2288 |
2272 |
2289 fun decl_line_of_sym ctxt mono type_enc s (s', T_args, T, pred_sym, ary, _) = |
2273 fun decl_line_of_sym ctxt type_enc s (s', T_args, T, pred_sym, ary, _) = |
2290 let |
2274 let |
2291 val thy = Proof_Context.theory_of ctxt |
2275 val thy = Proof_Context.theory_of ctxt |
2292 val (T, T_args) = |
2276 val (T, T_args) = |
2293 if null T_args then |
2277 if null T_args then |
2294 (T, []) |
2278 (T, []) |
2300 val T = s' |> robust_const_type thy |
2284 val T = s' |> robust_const_type thy |
2301 in (T, robust_const_type_args thy (s', T)) end |
2285 in (T, robust_const_type_args thy (s', T)) end |
2302 | NONE => raise Fail "unexpected type arguments") |
2286 | NONE => raise Fail "unexpected type arguments") |
2303 in |
2287 in |
2304 Sym_Decl (sym_decl_prefix ^ s, (s, s'), |
2288 Sym_Decl (sym_decl_prefix ^ s, (s, s'), |
2305 T |> fused_type ctxt mono (level_of_type_enc type_enc) ary |
2289 T |> native_atp_type_of_typ type_enc pred_sym ary |
2306 |> native_atp_type_of_typ type_enc pred_sym ary |
2290 |> not (null T_args) ? curry APi (map (tvar_name o dest_TVar) T_args)) |
2307 |> not (null T_args) |
|
2308 ? curry APi (map (tvar_name o dest_TVar) T_args)) |
|
2309 end |
2291 end |
2310 |
2292 |
2311 fun honor_conj_sym_role in_conj = (if in_conj then Hypothesis else Axiom, I) |
2293 fun honor_conj_sym_role in_conj = (if in_conj then Hypothesis else Axiom, I) |
2312 |
2294 |
2313 fun line_of_guards_sym_decl ctxt generate_info mono type_enc n s j |
2295 fun line_of_guards_sym_decl ctxt generate_info mono type_enc n s j |
2385 end |
2367 end |
2386 | rationalize_decls _ decls = decls |
2368 | rationalize_decls _ decls = decls |
2387 |
2369 |
2388 fun lines_of_sym_decls ctxt generate_info mono type_enc (s, decls) = |
2370 fun lines_of_sym_decls ctxt generate_info mono type_enc (s, decls) = |
2389 (case type_enc of |
2371 (case type_enc of |
2390 Native _ => [decl_line_of_sym ctxt mono type_enc s (hd decls)] |
2372 Native _ => [decl_line_of_sym ctxt type_enc s (hd decls)] |
2391 | Guards (_, level) => |
2373 | Guards (_, level) => |
2392 let |
2374 let |
2393 val thy = Proof_Context.theory_of ctxt |
2375 val thy = Proof_Context.theory_of ctxt |
2394 val decls = decls |> rationalize_decls thy |
2376 val decls = decls |> rationalize_decls thy |
2395 val n = length decls |
2377 val n = length decls |
2487 mk_app_op type_enc (list_app (do_const name1) first_bounds) last_bound |
2469 mk_app_op type_enc (list_app (do_const name1) first_bounds) last_bound |
2488 |> filter_ty_args |
2470 |> filter_ty_args |
2489 val tm2 = |
2471 val tm2 = |
2490 list_app (do_const name2) (first_bounds @ [last_bound]) |
2472 list_app (do_const name2) (first_bounds @ [last_bound]) |
2491 |> filter_ty_args |
2473 |> filter_ty_args |
2492 val do_bound_type = do_bound_type ctxt mono type_enc |
|
2493 val eq = |
2474 val eq = |
2494 eq_formula type_enc (atomic_types_of T) (map (apsnd do_bound_type) bounds) false |
2475 eq_formula type_enc (atomic_types_of T) |
2495 (atp_term_of tm1) (atp_term_of tm2) |
2476 (map (apsnd (do_bound_type type_enc)) bounds) false (atp_term_of tm1) (atp_term_of tm2) |
2496 in |
2477 in |
2497 ([tm1, tm2], |
2478 ([tm1, tm2], |
2498 [Formula ((uncurried_alias_eq_prefix ^ s2, ""), role, eq |> maybe_negate, NONE, |
2479 [Formula ((uncurried_alias_eq_prefix ^ s2, ""), role, eq |> maybe_negate, NONE, |
2499 isabelle_info generate_info non_rec_defN helper_rank)]) |
2480 isabelle_info generate_info non_rec_defN helper_rank)]) |
2500 |> (if ary - 1 = base_ary orelse Symtab.defined sym_tab s1 then I |
2481 |> (if ary - 1 = base_ary orelse Symtab.defined sym_tab s1 then I |