368 val suffix_type_of_types = |
368 val suffix_type_of_types = |
369 suffix (" " ^ tptp_has_type ^ " " ^ tptp_type_of_types) |
369 suffix (" " ^ tptp_has_type ^ " " ^ tptp_type_of_types) |
370 |
370 |
371 fun str_of_type format ty = |
371 fun str_of_type format ty = |
372 let |
372 let |
373 val dfg = case format of DFG _ => true | _ => false |
373 val dfg = (case format of DFG _ => true | _ => false) |
374 fun str _ (AType ((s, _), [])) = |
374 fun str _ (AType ((s, _), [])) = |
375 if dfg andalso s = tptp_individual_type then dfg_individual_type else s |
375 if dfg andalso s = tptp_individual_type then dfg_individual_type else s |
376 | str _ (AType ((s, _), tys)) = |
376 | str _ (AType ((s, _), tys)) = |
377 let val ss = tys |> map (str false) in |
377 let val ss = tys |> map (str false) in |
378 if s = tptp_product_type then |
378 if s = tptp_product_type then |
428 "[" ^ commas (map of_term ts) ^ "]" |
428 "[" ^ commas (map of_term ts) ^ "]" |
429 else if is_tptp_equal s then |
429 else if is_tptp_equal s then |
430 space_implode (" " ^ tptp_equal ^ " ") (map of_term ts) |
430 space_implode (" " ^ tptp_equal ^ " ") (map of_term ts) |
431 |> is_format_higher_order format ? parens |
431 |> is_format_higher_order format ? parens |
432 else if s = tptp_ho_forall orelse s = tptp_ho_exists then |
432 else if s = tptp_ho_forall orelse s = tptp_ho_exists then |
433 case ts of |
433 (case ts of |
434 [AAbs (((s', ty), tm), [])] => |
434 [AAbs (((s', ty), tm), [])] => |
435 (* Use syntactic sugar "!" and "?" instead of "!!" and "??" whenever |
435 (* Use syntactic sugar "!" and "?" instead of "!!" and "??" whenever |
436 possible, to work around LEO-II 1.2.8 parser limitation. *) |
436 possible, to work around LEO-II 1.2.8 parser limitation. *) |
437 tptp_string_of_formula format |
437 tptp_string_of_formula format |
438 (AQuant (if s = tptp_ho_forall then AForall else AExists, |
438 (AQuant (if s = tptp_ho_forall then AForall else AExists, |
439 [(s', SOME ty)], AAtom tm)) |
439 [(s', SOME ty)], AAtom tm)) |
440 | _ => app () |
440 | _ => app ()) |
441 else if s = tptp_choice then |
441 else if s = tptp_choice then |
442 case ts of |
442 (case ts of |
443 [AAbs (((s', ty), tm), args)] => |
443 [AAbs (((s', ty), tm), args)] => |
444 (* There is code in "ATP_Problem_Generate" to ensure that "Eps" is |
444 (* There is code in "ATP_Problem_Generate" to ensure that "Eps" is |
445 always applied to an abstraction. *) |
445 always applied to an abstraction. *) |
446 tptp_string_of_app format |
446 tptp_string_of_app format |
447 (tptp_choice ^ "[" ^ s' ^ " : " ^ of_type ty ^ |
447 (tptp_choice ^ "[" ^ s' ^ " : " ^ of_type ty ^ |
448 "]: " ^ of_term tm ^ "" |
448 "]: " ^ of_term tm ^ "" |
449 |> parens) (map of_term args) |
449 |> parens) (map of_term args) |
450 | _ => app () |
450 | _ => app ()) |
451 else if s = tptp_not then |
451 else if s = tptp_not then |
452 (* agsyHOL doesn't like negations applied like this: "~ @ t". *) |
452 (* agsyHOL doesn't like negations applied like this: "~ @ t". *) |
453 case ts of |
453 (case ts of [t] => s ^ " " ^ (of_term t |> parens) |> parens | _ => s) |
454 [t] => s ^ " " ^ (of_term t |> parens) |> parens |
|
455 | _ => s |
|
456 else if member (op =) [tptp_and, tptp_or, tptp_implies, tptp_if, tptp_iff, |
454 else if member (op =) [tptp_and, tptp_or, tptp_implies, tptp_if, tptp_iff, |
457 tptp_not_iff, tptp_equal] s then |
455 tptp_not_iff, tptp_equal] s then |
458 (* agsyHOL doesn't like connectives applied like this: "& @ t1 @ t2". *) |
456 (* agsyHOL doesn't like connectives applied like this: "& @ t1 @ t2". *) |
459 case ts of |
457 (case ts of |
460 [t1, t2] => |
458 [t1, t2] => (of_term t1 |> parens) ^ " " ^ s ^ " " ^ (of_term t2 |> parens) |> parens |
461 (of_term t1 |> parens) ^ " " ^ s ^ " " ^ (of_term t2 |> parens) |
459 | _ => app ()) |
462 |> parens |
|
463 | _ => app () |
|
464 else |
460 else |
465 app () |
461 app () |
466 end |
462 end |
467 | tptp_string_of_term (format as THF _) (AAbs (((s, ty), tm), args)) = |
463 | tptp_string_of_term (format as THF _) (AAbs (((s, ty), tm), args)) = |
468 tptp_string_of_app format |
464 tptp_string_of_app format |
554 val str_of_typ = string_of_type (DFG poly) |
550 val str_of_typ = string_of_type (DFG poly) |
555 fun str_of_bound_typ (ty, []) = str_of_typ ty |
551 fun str_of_bound_typ (ty, []) = str_of_typ ty |
556 | str_of_bound_typ (ty, cls) = str_of_typ ty ^ " : " ^ dfg_class_inter cls |
552 | str_of_bound_typ (ty, cls) = str_of_typ ty ^ " : " ^ dfg_class_inter cls |
557 fun suffix_tag top_level s = |
553 fun suffix_tag top_level s = |
558 if top_level then |
554 if top_level then |
559 case extract_isabelle_status info of |
555 (case extract_isabelle_status info of |
560 SOME s' => |
556 SOME s' => |
561 if s' = non_rec_defN then |
557 if s' = non_rec_defN then s ^ ":lt" |
562 s ^ ":lt" |
558 else if (s' = simpN orelse s' = rec_defN) andalso gen_simp then s ^ ":lr" |
563 else if (s' = simpN orelse s' = rec_defN) andalso gen_simp then |
559 else s |
564 s ^ ":lr" |
560 | NONE => s) |
565 else |
|
566 s |
|
567 | NONE => s |
|
568 else |
561 else |
569 s |
562 s |
570 fun str_of_atom top_level (ATerm ((s, tys), tms)) = |
563 fun str_of_atom top_level (ATerm ((s, tys), tms)) = |
571 let |
564 let |
572 val s' = |
565 val s' = |
860 |
853 |
861 fun nice_name _ (full_name, _) NONE = (full_name, NONE) |
854 fun nice_name _ (full_name, _) NONE = (full_name, NONE) |
862 | nice_name protect (full_name, desired_name) (SOME the_pool) = |
855 | nice_name protect (full_name, desired_name) (SOME the_pool) = |
863 if is_built_in_tptp_symbol full_name then |
856 if is_built_in_tptp_symbol full_name then |
864 (full_name, SOME the_pool) |
857 (full_name, SOME the_pool) |
865 else case Symtab.lookup (fst the_pool) full_name of |
858 else |
866 SOME nice_name => (nice_name, SOME the_pool) |
859 (case Symtab.lookup (fst the_pool) full_name of |
867 | NONE => |
860 SOME nice_name => (nice_name, SOME the_pool) |
868 let |
861 | NONE => |
869 val nice_prefix = readable_name protect full_name desired_name |
862 let |
870 fun add j = |
863 val nice_prefix = readable_name protect full_name desired_name |
871 let |
864 fun add j = |
872 val nice_name = |
865 let |
873 nice_prefix ^ (if j = 1 then "" else string_of_int j) |
866 val nice_name = nice_prefix ^ (if j = 1 then "" else string_of_int j) |
874 in |
867 in |
875 case Symtab.lookup (snd the_pool) nice_name of |
868 (case Symtab.lookup (snd the_pool) nice_name of |
876 SOME full_name' => |
869 SOME full_name' => |
877 if full_name = full_name' then (nice_name, the_pool) |
870 if full_name = full_name' then (nice_name, the_pool) else add (j + 1) |
878 else add (j + 1) |
871 | NONE => |
879 | NONE => |
872 (nice_name, |
880 (nice_name, |
873 (Symtab.update_new (full_name, nice_name) (fst the_pool), |
881 (Symtab.update_new (full_name, nice_name) (fst the_pool), |
874 Symtab.update_new (nice_name, full_name) (snd the_pool)))) |
882 Symtab.update_new (nice_name, full_name) (snd the_pool))) |
875 end |
883 end |
876 in add 1 |> apsnd SOME end) |
884 in add 1 |> apsnd SOME end |
|
885 |
877 |
886 fun avoid_clash_with_alt_ergo_type_vars s = |
878 fun avoid_clash_with_alt_ergo_type_vars s = |
887 if is_tptp_variable s then s else s ^ "_" |
879 if is_tptp_variable s then s else s ^ "_" |
888 |
880 |
889 fun avoid_clash_with_dfg_keywords s = |
881 fun avoid_clash_with_dfg_keywords s = |
901 fun nice_atp_problem readable_names format problem = |
893 fun nice_atp_problem readable_names format problem = |
902 let |
894 let |
903 val empty_pool = |
895 val empty_pool = |
904 if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
896 if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
905 val avoid_clash = |
897 val avoid_clash = |
906 case format of |
898 (case format of |
907 TFF Polymorphic => avoid_clash_with_alt_ergo_type_vars |
899 TFF Polymorphic => avoid_clash_with_alt_ergo_type_vars |
908 | DFG _ => avoid_clash_with_dfg_keywords |
900 | DFG _ => avoid_clash_with_dfg_keywords |
909 | _ => I |
901 | _ => I) |
910 val nice_name = nice_name avoid_clash |
902 val nice_name = nice_name avoid_clash |
911 |
903 |
912 fun nice_bound_tvars xs = |
904 fun nice_bound_tvars xs = |
913 fold_map (nice_name o fst) xs |
905 fold_map (nice_name o fst) xs |
914 ##>> fold_map (fold_map nice_name o snd) xs |
906 ##>> fold_map (fold_map nice_name o snd) xs |