48 |
48 |
49 datatype 'a problem_line = |
49 datatype 'a problem_line = |
50 Class_Decl of string * 'a * 'a list | |
50 Class_Decl of string * 'a * 'a list | |
51 Type_Decl of string * 'a * int | |
51 Type_Decl of string * 'a * int | |
52 Sym_Decl of string * 'a * 'a ho_type | |
52 Sym_Decl of string * 'a * 'a ho_type | |
|
53 Datatype_Decl of string * ('a * 'a list) list * 'a ho_type |
|
54 * ('a, 'a ho_type) ho_term list | |
53 Class_Memb of string * ('a * 'a list) list * 'a ho_type * 'a | |
55 Class_Memb of string * ('a * 'a list) list * 'a ho_type * 'a | |
54 Formula of (string * string) * formula_role |
56 Formula of (string * string) * formula_role |
55 * ('a, 'a ho_type, ('a, 'a ho_type) ho_term, 'a) formula |
57 * ('a, 'a ho_type, ('a, 'a ho_type) ho_term, 'a) formula |
56 * (string, string ho_type) ho_term option |
58 * (string, string ho_type) ho_term option |
57 * (string, string ho_type) ho_term list |
59 * (string, string ho_type) ho_term list |
188 |
190 |
189 datatype 'a problem_line = |
191 datatype 'a problem_line = |
190 Class_Decl of string * 'a * 'a list | |
192 Class_Decl of string * 'a * 'a list | |
191 Type_Decl of string * 'a * int | |
193 Type_Decl of string * 'a * int | |
192 Sym_Decl of string * 'a * 'a ho_type | |
194 Sym_Decl of string * 'a * 'a ho_type | |
|
195 Datatype_Decl of string * ('a * 'a list) list * 'a ho_type |
|
196 * ('a, 'a ho_type) ho_term list | |
193 Class_Memb of string * ('a * 'a list) list * 'a ho_type * 'a | |
197 Class_Memb of string * ('a * 'a list) list * 'a ho_type * 'a | |
194 Formula of (string * string) * formula_role |
198 Formula of (string * string) * formula_role |
195 * ('a, 'a ho_type, ('a, 'a ho_type) ho_term, 'a) formula |
199 * ('a, 'a ho_type, ('a, 'a ho_type) ho_term, 'a) formula |
196 * (string, string ho_type) ho_term option |
200 * (string, string ho_type) ho_term option |
197 * (string, string ho_type) ho_term list |
201 * (string, string ho_type) ho_term list |
510 fun string_of_arity (0, n) = string_of_int n |
514 fun string_of_arity (0, n) = string_of_int n |
511 | string_of_arity (m, n) = string_of_int m ^ "+" ^ string_of_int n |
515 | string_of_arity (m, n) = string_of_int m ^ "+" ^ string_of_int n |
512 |
516 |
513 val dfg_class_inter = space_implode " & " |
517 val dfg_class_inter = space_implode " & " |
514 |
518 |
|
519 fun dfg_string_for_term (ATerm ((s, tys), tms)) = |
|
520 s ^ |
|
521 (if null tys then "" |
|
522 else "<" ^ commas (map (string_for_type (DFG Polymorphic)) tys) ^ ">") ^ |
|
523 (if null tms then "" |
|
524 else "(" ^ commas (map dfg_string_for_term tms) ^ ")") |
|
525 | dfg_string_for_term _ = raise Fail "unexpected atom in first-order format" |
|
526 |
515 fun dfg_string_for_formula poly gen_simp info = |
527 fun dfg_string_for_formula poly gen_simp info = |
516 let |
528 let |
517 val str_for_typ = string_for_type (DFG poly) |
529 val str_for_typ = string_for_type (DFG poly) |
518 fun str_for_bound_typ (ty, []) = str_for_typ ty |
530 fun str_for_bound_typ (ty, []) = str_for_typ ty |
519 | str_for_bound_typ (ty, cls) = |
531 | str_for_bound_typ (ty, cls) = |
529 else |
541 else |
530 s |
542 s |
531 | NONE => s |
543 | NONE => s |
532 else |
544 else |
533 s |
545 s |
534 fun str_for_term top_level (ATerm ((s, tys), tms)) = |
546 fun str_for_atom top_level (ATerm ((s, tys), tms)) = |
535 (if is_tptp_equal s then "equal" |> suffix_tag top_level |
547 let |
536 else if s = tptp_true then "true" |
548 val s' = |
537 else if s = tptp_false then "false" |
549 if is_tptp_equal s then "equal" |> suffix_tag top_level |
538 else s) ^ |
550 else if s = tptp_true then "true" |
539 (if null tys then "" |
551 else if s = tptp_false then "false" |
540 else "<" ^ commas (map (string_for_type (DFG poly)) tys) ^ ">") ^ |
552 else s |
541 (if null tms then "" |
553 in dfg_string_for_term (ATerm ((s', tys), tms)) end |
542 else "(" ^ commas (map (str_for_term false) tms) ^ ")") |
554 | str_for_atom _ _ = raise Fail "unexpected atom in first-order format" |
543 | str_for_term _ _ = raise Fail "unexpected term in first-order format" |
|
544 fun str_for_quant AForall = "forall" |
555 fun str_for_quant AForall = "forall" |
545 | str_for_quant AExists = "exists" |
556 | str_for_quant AExists = "exists" |
546 fun str_for_conn _ ANot = "not" |
557 fun str_for_conn _ ANot = "not" |
547 | str_for_conn _ AAnd = "and" |
558 | str_for_conn _ AAnd = "and" |
548 | str_for_conn _ AOr = "or" |
559 | str_for_conn _ AOr = "or" |
556 commas (map (string_for_bound_var (DFG poly)) xs) ^ "], " ^ |
567 commas (map (string_for_bound_var (DFG poly)) xs) ^ "], " ^ |
557 str_for_formula top_level phi ^ ")" |
568 str_for_formula top_level phi ^ ")" |
558 | str_for_formula top_level (AConn (c, phis)) = |
569 | str_for_formula top_level (AConn (c, phis)) = |
559 str_for_conn top_level c ^ "(" ^ |
570 str_for_conn top_level c ^ "(" ^ |
560 commas (map (str_for_formula false) phis) ^ ")" |
571 commas (map (str_for_formula false) phis) ^ ")" |
561 | str_for_formula top_level (AAtom tm) = str_for_term top_level tm |
572 | str_for_formula top_level (AAtom tm) = str_for_atom top_level tm |
562 in str_for_formula true end |
573 in str_for_formula true end |
563 |
574 |
564 fun maybe_enclose bef aft "" = "% " ^ bef ^ aft |
575 fun maybe_enclose bef aft "" = "% " ^ bef ^ aft |
565 | maybe_enclose bef aft s = bef ^ s ^ aft |
576 | maybe_enclose bef aft s = bef ^ s ^ aft |
566 |
577 |
567 fun dfg_lines poly {is_lpo, gen_weights, gen_prec, gen_simp} ord_info problem = |
578 fun dfg_lines poly {is_lpo, gen_weights, gen_prec, gen_simp} ord_info problem = |
568 let |
579 let |
569 val str_for_typ = string_for_type (DFG poly) |
580 val typ = string_for_type (DFG poly) |
|
581 val term = dfg_string_for_term |
570 fun spair (s, s') = "(" ^ s ^ ", " ^ s' ^ ")" |
582 fun spair (s, s') = "(" ^ s ^ ", " ^ s' ^ ")" |
571 fun tm_ary sym ty = spair (sym, string_of_arity (arity_of_type ty)) |
583 fun tm_ary sym ty = spair (sym, string_of_arity (arity_of_type ty)) |
572 fun ty_ary 0 ty = ty |
584 fun ty_ary 0 ty = ty |
573 | ty_ary n ty = "(" ^ ty ^ ", " ^ string_of_int n ^ ")" |
585 | ty_ary n ty = "(" ^ ty ^ ", " ^ string_of_int n ^ ")" |
574 fun fun_typ sym ty = "function(" ^ sym ^ ", " ^ str_for_typ ty ^ ")." |
586 fun fun_typ sym ty = "function(" ^ sym ^ ", " ^ typ ty ^ ")." |
575 fun pred_typ sym ty = |
587 fun pred_typ sym ty = |
576 let |
588 let |
577 val (ty_vars, tys) = |
589 val (ty_vars, tys) = |
578 strip_atype ty |> fst |
590 strip_atype ty |> fst |
579 |>> (fn [] => [] | ty_vars => ["[" ^ commas ty_vars ^ "]"]) |
591 |>> (fn [] => [] | ty_vars => ["[" ^ commas ty_vars ^ "]"]) |
580 in "predicate(" ^ commas (sym :: ty_vars @ map str_for_typ tys) ^ ")." end |
592 in "predicate(" ^ commas (sym :: ty_vars @ map typ tys) ^ ")." end |
581 fun str_for_bound_tvar (ty, []) = ty |
593 fun bound_tvar (ty, []) = ty |
582 | str_for_bound_tvar (ty, cls) = ty ^ " : " ^ dfg_class_inter cls |
594 | bound_tvar (ty, cls) = ty ^ " : " ^ dfg_class_inter cls |
583 fun sort_decl xs ty cl = |
595 fun foo xs ty = |
584 "sort(" ^ |
596 (if null xs then "" else "[" ^ commas (map bound_tvar xs) ^ "], ") ^ |
585 (if null xs then "" |
597 typ ty |
586 else "[" ^ commas (map str_for_bound_tvar xs) ^ "], ") ^ |
598 fun sort_decl xs ty cl = "sort(" ^ foo xs ty ^ ", " ^ cl ^ ")." |
587 str_for_typ ty ^ ", " ^ cl ^ ")." |
599 fun datatype_decl xs ty tms = |
|
600 "datatype(" ^ foo xs ty ^ ", " ^ commas (map term tms) ^ ")." |
588 fun subclass_of sub super = "subclass(" ^ sub ^ ", " ^ super ^ ")." |
601 fun subclass_of sub super = "subclass(" ^ sub ^ ", " ^ super ^ ")." |
589 fun formula pred (Formula ((ident, alt), kind, phi, _, info)) = |
602 fun formula pred (Formula ((ident, alt), kind, phi, _, info)) = |
590 if pred kind then |
603 if pred kind then |
591 let val rank = extract_isabelle_rank info in |
604 let val rank = extract_isabelle_rank info in |
592 "formula(" ^ dfg_string_for_formula poly gen_simp info phi ^ |
605 "formula(" ^ dfg_string_for_formula poly gen_simp info phi ^ |
629 val pred_decls = |
642 val pred_decls = |
630 filt (fn Sym_Decl (_, sym, ty) => |
643 filt (fn Sym_Decl (_, sym, ty) => |
631 if is_nontrivial_predicate_atype ty then SOME (pred_typ sym ty) |
644 if is_nontrivial_predicate_atype ty then SOME (pred_typ sym ty) |
632 else NONE |
645 else NONE |
633 | _ => NONE) |> flat |
646 | _ => NONE) |> flat |
|
647 val datatype_decls = |
|
648 filt (fn Datatype_Decl (_, xs, ty, tms) => SOME (datatype_decl xs ty tms) |
|
649 | _ => NONE) |> flat |
634 val sort_decls = |
650 val sort_decls = |
635 filt (fn Class_Memb (_, xs, ty, cl) => SOME (sort_decl xs ty cl) |
651 filt (fn Class_Memb (_, xs, ty, cl) => SOME (sort_decl xs ty cl) |
636 | _ => NONE) |> flat |
652 | _ => NONE) |> flat |
637 val subclass_decls = |
653 val subclass_decls = |
638 filt (fn Class_Decl (_, sub, supers) => |
654 filt (fn Class_Decl (_, sub, supers) => |
639 SOME (map (subclass_of sub) supers) |
655 SOME (map (subclass_of sub) supers) |
640 | _ => NONE) |> flat |> flat |
656 | _ => NONE) |> flat |> flat |
641 val decls = func_decls @ pred_decls @ sort_decls @ subclass_decls |
657 val decls = |
|
658 func_decls @ pred_decls @ datatype_decls @ sort_decls @ subclass_decls |
642 val axioms = |
659 val axioms = |
643 filt (formula (curry (op <>) Conjecture)) |> separate [""] |> flat |
660 filt (formula (curry (op <>) Conjecture)) |> separate [""] |> flat |
644 val conjs = |
661 val conjs = |
645 filt (formula (curry (op =) Conjecture)) |> separate [""] |> flat |
662 filt (formula (curry (op =) Conjecture)) |> separate [""] |> flat |
646 val settings = |
663 val settings = |