30 |
30 |
31 datatype tptp_polymorphism = TPTP_Monomorphic | TPTP_Polymorphic |
31 datatype tptp_polymorphism = TPTP_Monomorphic | TPTP_Polymorphic |
32 datatype tptp_explicitness = TPTP_Implicit | TPTP_Explicit |
32 datatype tptp_explicitness = TPTP_Implicit | TPTP_Explicit |
33 datatype thf_choice = THF_Without_Choice | THF_With_Choice |
33 datatype thf_choice = THF_Without_Choice | THF_With_Choice |
34 datatype thf_defs = THF_Without_Defs | THF_With_Defs |
34 datatype thf_defs = THF_Without_Defs | THF_With_Defs |
35 datatype dfg_flavor = DFG_Unsorted | DFG_Sorted |
|
36 |
35 |
37 datatype atp_format = |
36 datatype atp_format = |
38 CNF | |
37 CNF | |
39 CNF_UEQ | |
38 CNF_UEQ | |
40 FOF | |
39 FOF | |
41 TFF of tptp_polymorphism * tptp_explicitness | |
40 TFF of tptp_polymorphism * tptp_explicitness | |
42 THF of tptp_polymorphism * tptp_explicitness * thf_choice * thf_defs | |
41 THF of tptp_polymorphism * tptp_explicitness * thf_choice * thf_defs | |
43 DFG of dfg_flavor |
42 DFG |
44 |
43 |
45 datatype formula_role = Axiom | Definition | Lemma | Hypothesis | Conjecture |
44 datatype formula_role = Axiom | Definition | Lemma | Hypothesis | Conjecture |
46 datatype 'a problem_line = |
45 datatype 'a problem_line = |
47 Decl of string * 'a * 'a ho_type | |
46 Decl of string * 'a * 'a ho_type | |
48 Formula of string * formula_role |
47 Formula of string * formula_role |
163 |
162 |
164 datatype tptp_polymorphism = TPTP_Monomorphic | TPTP_Polymorphic |
163 datatype tptp_polymorphism = TPTP_Monomorphic | TPTP_Polymorphic |
165 datatype tptp_explicitness = TPTP_Implicit | TPTP_Explicit |
164 datatype tptp_explicitness = TPTP_Implicit | TPTP_Explicit |
166 datatype thf_choice = THF_Without_Choice | THF_With_Choice |
165 datatype thf_choice = THF_Without_Choice | THF_With_Choice |
167 datatype thf_defs = THF_Without_Defs | THF_With_Defs |
166 datatype thf_defs = THF_Without_Defs | THF_With_Defs |
168 datatype dfg_flavor = DFG_Unsorted | DFG_Sorted |
|
169 |
167 |
170 datatype atp_format = |
168 datatype atp_format = |
171 CNF | |
169 CNF | |
172 CNF_UEQ | |
170 CNF_UEQ | |
173 FOF | |
171 FOF | |
174 TFF of tptp_polymorphism * tptp_explicitness | |
172 TFF of tptp_polymorphism * tptp_explicitness | |
175 THF of tptp_polymorphism * tptp_explicitness * thf_choice * thf_defs | |
173 THF of tptp_polymorphism * tptp_explicitness * thf_choice * thf_defs | |
176 DFG of dfg_flavor |
174 DFG |
177 |
175 |
178 datatype formula_role = Axiom | Definition | Lemma | Hypothesis | Conjecture |
176 datatype formula_role = Axiom | Definition | Lemma | Hypothesis | Conjecture |
179 datatype 'a problem_line = |
177 datatype 'a problem_line = |
180 Decl of string * 'a * 'a ho_type | |
178 Decl of string * 'a * 'a ho_type | |
181 Formula of string * formula_role |
179 Formula of string * formula_role |
227 |
225 |
228 val minimum_rank = 0 |
226 val minimum_rank = 0 |
229 val default_rank = 1000 |
227 val default_rank = 1000 |
230 val default_term_order_weight = 1 |
228 val default_term_order_weight = 1 |
231 |
229 |
232 (* Currently, only newer versions of SPASS, with sorted DFG format support, can |
230 (* Currently, only SPASS 3.8ds can process Isabelle metainformation. *) |
233 process Isabelle metainformation. *) |
|
234 fun isabelle_info status rank = |
231 fun isabelle_info status rank = |
235 [] |> rank <> default_rank |
232 [] |> rank <> default_rank |
236 ? cons (ATerm (isabelle_info_prefix ^ rankN, |
233 ? cons (ATerm (isabelle_info_prefix ^ rankN, |
237 [ATerm (string_of_int rank, [])])) |
234 [ATerm (string_of_int rank, [])])) |
238 |> status <> "" ? cons (ATerm (isabelle_info_prefix ^ status, [])) |
235 |> status <> "" ? cons (ATerm (isabelle_info_prefix ^ status, [])) |
307 |
304 |
308 fun is_format_higher_order (THF _) = true |
305 fun is_format_higher_order (THF _) = true |
309 | is_format_higher_order _ = false |
306 | is_format_higher_order _ = false |
310 fun is_format_typed (TFF _) = true |
307 fun is_format_typed (TFF _) = true |
311 | is_format_typed (THF _) = true |
308 | is_format_typed (THF _) = true |
312 | is_format_typed (DFG DFG_Sorted) = true |
309 | is_format_typed DFG = true |
313 | is_format_typed _ = false |
310 | is_format_typed _ = false |
314 |
311 |
315 fun tptp_string_for_role Axiom = "axiom" |
312 fun tptp_string_for_role Axiom = "axiom" |
316 | tptp_string_for_role Definition = "definition" |
313 | tptp_string_for_role Definition = "definition" |
317 | tptp_string_for_role Lemma = "lemma" |
314 | tptp_string_for_role Lemma = "lemma" |
337 |
334 |
338 val dfg_individual_type = "iii" (* cannot clash *) |
335 val dfg_individual_type = "iii" (* cannot clash *) |
339 |
336 |
340 fun str_for_type format ty = |
337 fun str_for_type format ty = |
341 let |
338 let |
342 val dfg = (format = DFG DFG_Sorted) |
339 val dfg = (format = DFG) |
343 fun str _ (AType (s, [])) = |
340 fun str _ (AType (s, [])) = |
344 if dfg andalso s = tptp_individual_type then dfg_individual_type else s |
341 if dfg andalso s = tptp_individual_type then dfg_individual_type else s |
345 | str _ (AType (s, tys)) = |
342 | str _ (AType (s, tys)) = |
346 let val ss = tys |> map (str false) in |
343 let val ss = tys |> map (str false) in |
347 if s = tptp_product_type then |
344 if s = tptp_product_type then |
439 fun tptp_string_for_format CNF = tptp_cnf |
436 fun tptp_string_for_format CNF = tptp_cnf |
440 | tptp_string_for_format CNF_UEQ = tptp_cnf |
437 | tptp_string_for_format CNF_UEQ = tptp_cnf |
441 | tptp_string_for_format FOF = tptp_fof |
438 | tptp_string_for_format FOF = tptp_fof |
442 | tptp_string_for_format (TFF _) = tptp_tff |
439 | tptp_string_for_format (TFF _) = tptp_tff |
443 | tptp_string_for_format (THF _) = tptp_thf |
440 | tptp_string_for_format (THF _) = tptp_thf |
444 | tptp_string_for_format (DFG _) = raise Fail "non-TPTP format" |
441 | tptp_string_for_format DFG = raise Fail "non-TPTP format" |
445 |
442 |
446 fun tptp_string_for_problem_line format (Decl (ident, sym, ty)) = |
443 fun tptp_string_for_problem_line format (Decl (ident, sym, ty)) = |
447 tptp_string_for_format format ^ "(" ^ ident ^ ", type,\n " ^ sym ^ |
444 tptp_string_for_format format ^ "(" ^ ident ^ ", type,\n " ^ sym ^ |
448 " : " ^ string_for_type format ty ^ ").\n" |
445 " : " ^ string_for_type format ty ^ ").\n" |
449 | tptp_string_for_problem_line format |
446 | tptp_string_for_problem_line format |
465 | arity_of_type _ = 0 |
462 | arity_of_type _ = 0 |
466 |
463 |
467 fun binder_atypes (AFun (ty1, ty2)) = ty1 :: binder_atypes ty2 |
464 fun binder_atypes (AFun (ty1, ty2)) = ty1 :: binder_atypes ty2 |
468 | binder_atypes _ = [] |
465 | binder_atypes _ = [] |
469 |
466 |
470 fun dfg_string_for_formula gen_simp flavor info = |
467 fun dfg_string_for_formula gen_simp info = |
471 let |
468 let |
472 fun suffix_tag top_level s = |
469 fun suffix_tag top_level s = |
473 if flavor = DFG_Sorted andalso top_level then |
470 if top_level then |
474 case extract_isabelle_status info of |
471 case extract_isabelle_status info of |
475 SOME s' => if s' = defN then s ^ ":lt" |
472 SOME s' => if s' = defN then s ^ ":lt" |
476 else if s' = simpN andalso gen_simp then s ^ ":lr" |
473 else if s' = simpN andalso gen_simp then s ^ ":lr" |
477 else s |
474 else s |
478 | NONE => s |
475 | NONE => s |
493 | str_for_conn _ AOr = "or" |
490 | str_for_conn _ AOr = "or" |
494 | str_for_conn _ AImplies = "implies" |
491 | str_for_conn _ AImplies = "implies" |
495 | str_for_conn top_level AIff = "equiv" |> suffix_tag top_level |
492 | str_for_conn top_level AIff = "equiv" |> suffix_tag top_level |
496 fun str_for_formula top_level (AQuant (q, xs, phi)) = |
493 fun str_for_formula top_level (AQuant (q, xs, phi)) = |
497 str_for_quant q ^ "(" ^ "[" ^ |
494 str_for_quant q ^ "(" ^ "[" ^ |
498 commas (map (string_for_bound_var (DFG flavor)) xs) ^ "], " ^ |
495 commas (map (string_for_bound_var DFG) xs) ^ "], " ^ |
499 str_for_formula top_level phi ^ ")" |
496 str_for_formula top_level phi ^ ")" |
500 | str_for_formula top_level (AConn (c, phis)) = |
497 | str_for_formula top_level (AConn (c, phis)) = |
501 str_for_conn top_level c ^ "(" ^ |
498 str_for_conn top_level c ^ "(" ^ |
502 commas (map (str_for_formula false) phis) ^ ")" |
499 commas (map (str_for_formula false) phis) ^ ")" |
503 | str_for_formula top_level (AAtom tm) = str_for_term top_level tm |
500 | str_for_formula top_level (AAtom tm) = str_for_term top_level tm |
504 in str_for_formula true end |
501 in str_for_formula true end |
505 |
502 |
506 fun maybe_enclose bef aft "" = "% " ^ bef ^ aft |
503 fun maybe_enclose bef aft "" = "% " ^ bef ^ aft |
507 | maybe_enclose bef aft s = bef ^ s ^ aft |
504 | maybe_enclose bef aft s = bef ^ s ^ aft |
508 |
505 |
509 fun dfg_lines flavor {is_lpo, gen_weights, gen_prec, gen_simp} ord_info |
506 fun dfg_lines {is_lpo, gen_weights, gen_prec, gen_simp} ord_info problem = |
510 problem = |
|
511 let |
507 let |
512 val sorted = (flavor = DFG_Sorted) |
|
513 val format = DFG flavor |
|
514 fun spair (sym, k) = "(" ^ sym ^ ", " ^ string_of_int k ^ ")" |
508 fun spair (sym, k) = "(" ^ sym ^ ", " ^ string_of_int k ^ ")" |
515 fun ary sym = curry spair sym o arity_of_type |
509 fun ary sym = curry spair sym o arity_of_type |
516 fun fun_typ sym ty = |
510 fun fun_typ sym ty = |
517 "function(" ^ sym ^ ", " ^ string_for_type format ty ^ ")." |
511 "function(" ^ sym ^ ", " ^ string_for_type DFG ty ^ ")." |
518 fun pred_typ sym ty = |
512 fun pred_typ sym ty = |
519 "predicate(" ^ |
513 "predicate(" ^ |
520 commas (sym :: map (string_for_type format) (binder_atypes ty)) ^ ")." |
514 commas (sym :: map (string_for_type DFG) (binder_atypes ty)) ^ ")." |
521 fun formula pred (Formula (ident, kind, phi, _, info)) = |
515 fun formula pred (Formula (ident, kind, phi, _, info)) = |
522 if pred kind then |
516 if pred kind then |
523 let |
517 let val rank = extract_isabelle_rank info in |
524 val rank = |
518 "formula(" ^ dfg_string_for_formula gen_simp info phi ^ |
525 if flavor = DFG_Sorted then extract_isabelle_rank info |
|
526 else default_rank |
|
527 in |
|
528 "formula(" ^ dfg_string_for_formula gen_simp flavor info phi ^ |
|
529 ", " ^ ident ^ |
519 ", " ^ ident ^ |
530 (if rank = default_rank then "" else ", " ^ string_of_int rank) ^ |
520 (if rank = default_rank then "" else ", " ^ string_of_int rank) ^ |
531 ")." |> SOME |
521 ")." |> SOME |
532 end |
522 end |
533 else |
523 else |
542 val pred_aries = |
532 val pred_aries = |
543 filt (fn Decl (_, sym, ty) => |
533 filt (fn Decl (_, sym, ty) => |
544 if is_predicate_type ty then SOME (ary sym ty) else NONE |
534 if is_predicate_type ty then SOME (ary sym ty) else NONE |
545 | _ => NONE) |
535 | _ => NONE) |
546 |> flat |> commas |> maybe_enclose "predicates [" "]." |
536 |> flat |> commas |> maybe_enclose "predicates [" "]." |
547 fun sorts () = |
537 val sorts = |
548 filt (fn Decl (_, sym, AType (s, [])) => |
538 filt (fn Decl (_, sym, AType (s, [])) => |
549 if s = tptp_type_of_types then SOME sym else NONE |
539 if s = tptp_type_of_types then SOME sym else NONE |
550 | _ => NONE) @ [[dfg_individual_type]] |
540 | _ => NONE) @ [[dfg_individual_type]] |
551 |> flat |> commas |> maybe_enclose "sorts [" "]." |
541 |> flat |> commas |> maybe_enclose "sorts [" "]." |
552 val ord_info = |
542 val ord_info = if gen_weights orelse gen_prec then ord_info () else [] |
553 if sorted andalso (gen_weights orelse gen_prec) then ord_info () else [] |
543 val do_term_order_weights = |
554 fun do_term_order_weights () = |
|
555 (if gen_weights then ord_info else []) |
544 (if gen_weights then ord_info else []) |
556 |> map spair |> commas |> maybe_enclose "weights [" "]." |
545 |> map spair |> commas |> maybe_enclose "weights [" "]." |
557 val syms = |
546 val syms = [func_aries, pred_aries, do_term_order_weights, sorts] |
558 [func_aries, pred_aries] @ |
547 val func_sigs = |
559 (if sorted then [do_term_order_weights (), sorts ()] else []) |
|
560 fun func_sigs () = |
|
561 filt (fn Decl (_, sym, ty) => |
548 filt (fn Decl (_, sym, ty) => |
562 if is_function_type ty then SOME (fun_typ sym ty) else NONE |
549 if is_function_type ty then SOME (fun_typ sym ty) else NONE |
563 | _ => NONE) |
550 | _ => NONE) |
564 |> flat |
551 |> flat |
565 fun pred_sigs () = |
552 val pred_sigs = |
566 filt (fn Decl (_, sym, ty) => |
553 filt (fn Decl (_, sym, ty) => |
567 if is_nontrivial_predicate_type ty then SOME (pred_typ sym ty) |
554 if is_nontrivial_predicate_type ty then SOME (pred_typ sym ty) |
568 else NONE |
555 else NONE |
569 | _ => NONE) |
556 | _ => NONE) |
570 |> flat |
557 |> flat |
571 val decls = if sorted then func_sigs () @ pred_sigs () else [] |
558 val decls = func_sigs @ pred_sigs |
572 val axioms = |
559 val axioms = |
573 filt (formula (curry (op <>) Conjecture)) |> separate [""] |> flat |
560 filt (formula (curry (op <>) Conjecture)) |> separate [""] |> flat |
574 val conjs = |
561 val conjs = |
575 filt (formula (curry (op =) Conjecture)) |> separate [""] |> flat |
562 filt (formula (curry (op =) Conjecture)) |> separate [""] |> flat |
576 val settings = |
563 val settings = |
598 end |
585 end |
599 |
586 |
600 fun lines_for_atp_problem format ord ord_info problem = |
587 fun lines_for_atp_problem format ord ord_info problem = |
601 "% This file was generated by Isabelle (most likely Sledgehammer)\n\ |
588 "% This file was generated by Isabelle (most likely Sledgehammer)\n\ |
602 \% " ^ timestamp () ^ "\n" :: |
589 \% " ^ timestamp () ^ "\n" :: |
603 (case format of |
590 (if format = DFG then dfg_lines ord ord_info else tptp_lines format) problem |
604 DFG flavor => dfg_lines flavor ord ord_info |
|
605 | _ => tptp_lines format) problem |
|
606 |
591 |
607 |
592 |
608 (** CNF (Metis) and CNF UEQ (Waldmeister) **) |
593 (** CNF (Metis) and CNF UEQ (Waldmeister) **) |
609 |
594 |
610 fun is_problem_line_negated (Formula (_, _, AConn (ANot, _), _, _)) = true |
595 fun is_problem_line_negated (Formula (_, _, AConn (ANot, _), _, _)) = true |
800 val empty_pool = |
785 val empty_pool = |
801 if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
786 if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
802 val avoid_clash = |
787 val avoid_clash = |
803 case format of |
788 case format of |
804 TFF (TPTP_Polymorphic, _) => avoid_clash_with_alt_ergo_type_vars |
789 TFF (TPTP_Polymorphic, _) => avoid_clash_with_alt_ergo_type_vars |
805 | DFG _ => avoid_clash_with_dfg_keywords |
790 | DFG => avoid_clash_with_dfg_keywords |
806 | _ => I |
791 | _ => I |
807 val nice_name = nice_name avoid_clash |
792 val nice_name = nice_name avoid_clash |
808 fun nice_type (AType (name, tys)) = |
793 fun nice_type (AType (name, tys)) = |
809 nice_name name ##>> pool_map nice_type tys #>> AType |
794 nice_name name ##>> pool_map nice_type tys #>> AType |
810 | nice_type (AFun (ty1, ty2)) = nice_type ty1 ##>> nice_type ty2 #>> AFun |
795 | nice_type (AFun (ty1, ty2)) = nice_type ty1 ##>> nice_type ty2 #>> AFun |