| author | wenzelm | 
| Wed, 25 Jul 2012 23:02:50 +0200 | |
| changeset 48506 | af1dabad14c0 | 
| parent 48438 | 3e45c98fe127 | 
| child 50012 | 01cb92151a53 | 
| permissions | -rw-r--r-- | 
| 38047 | 1 | (* Title: HOL/Tools/ATP/atp_problem.ML | 
| 38027 | 2 | Author: Jia Meng, Cambridge University Computer Laboratory and NICTA | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 3 | Author: Jasmin Blanchette, TU Muenchen | 
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 4 | |
| 39452 | 5 | Abstract representation of ATP problems and TPTP syntax. | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 6 | *) | 
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 7 | |
| 38019 
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
 blanchet parents: 
38018diff
changeset | 8 | signature ATP_PROBLEM = | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 9 | sig | 
| 43676 
3b0b448b4d69
add support for lambdas in TPTP THF generator + killed an unsound type encoding (because the monotonicity calculus assumes first-order)
 nik parents: 
43422diff
changeset | 10 |   datatype ('a, 'b) ho_term =
 | 
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 11 |     ATerm of ('a * 'b list) * ('a, 'b) ho_term list |
 | 
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 12 |     AAbs of (('a * 'b) * ('a, 'b) ho_term) * ('a, 'b) ho_term list
 | 
| 37992 | 13 | datatype quantifier = AForall | AExists | 
| 43163 | 14 | datatype connective = ANot | AAnd | AOr | AImplies | AIff | 
| 48135 | 15 |   datatype ('a, 'b, 'c, 'd) formula =
 | 
| 16 |     ATyQuant of quantifier * ('b * 'd list) list * ('a, 'b, 'c, 'd) formula |
 | |
| 17 |     AQuant of quantifier * ('a * 'b option) list * ('a, 'b, 'c, 'd) formula |
 | |
| 18 |     AConn of connective * ('a, 'b, 'c, 'd) formula list |
 | |
| 42531 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 19 | AAtom of 'c | 
| 37994 
b04307085a09
make TPTP generator accept full first-order formulas
 blanchet parents: 
37993diff
changeset | 20 | |
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 21 | datatype 'a ho_type = | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 22 | AType of 'a * 'a ho_type list | | 
| 44594 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 23 | AFun of 'a ho_type * 'a ho_type | | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 24 | APi of 'a list * 'a ho_type | 
| 42963 | 25 | |
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 26 | type term_order = | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 27 |     {is_lpo : bool,
 | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 28 | gen_weights : bool, | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 29 | gen_prec : bool, | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 30 | gen_simp : bool} | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 31 | |
| 48140 | 32 | datatype polymorphism = Monomorphic | Polymorphic | 
| 44754 | 33 | datatype tptp_explicitness = TPTP_Implicit | TPTP_Explicit | 
| 48004 
989a34fa72b3
don't generate definitions for LEO-II -- this cuases more harm than good
 blanchet parents: 
47976diff
changeset | 34 | datatype thf_choice = THF_Without_Choice | THF_With_Choice | 
| 
989a34fa72b3
don't generate definitions for LEO-II -- this cuases more harm than good
 blanchet parents: 
47976diff
changeset | 35 | datatype thf_defs = THF_Without_Defs | THF_With_Defs | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 36 | |
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 37 | datatype atp_format = | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 38 | CNF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 39 | CNF_UEQ | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 40 | FOF | | 
| 48130 | 41 | TFF of polymorphism * tptp_explicitness | | 
| 42 | THF of polymorphism * tptp_explicitness * thf_choice * thf_defs | | |
| 48131 | 43 | DFG of polymorphism | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 44 | |
| 47976 | 45 | datatype formula_role = Axiom | Definition | Lemma | Hypothesis | Conjecture | 
| 42527 
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
 blanchet parents: 
42526diff
changeset | 46 | datatype 'a problem_line = | 
| 48141 | 47 | Class_Decl of string * 'a * 'a list | | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 48 | Type_Decl of string * 'a * int | | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 49 | Sym_Decl of string * 'a * 'a ho_type | | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 50 |     Class_Memb of string * ('a * 'a list) list * 'a ho_type * 'a |
 | 
| 47976 | 51 | Formula of string * formula_role | 
| 48135 | 52 |                * ('a, 'a ho_type, ('a, 'a ho_type) ho_term, 'a) formula
 | 
| 44402 | 53 | * (string, string ho_type) ho_term option | 
| 46406 | 54 | * (string, string ho_type) ho_term list | 
| 38017 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 55 | type 'a problem = (string * 'a problem_line list) list | 
| 37992 | 56 | |
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 57 | val tptp_cnf : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 58 | val tptp_fof : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 59 | val tptp_tff : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 60 | val tptp_thf : string | 
| 42967 | 61 | val tptp_has_type : string | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 62 | val tptp_type_of_types : string | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 63 | val tptp_bool_type : string | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 64 | val tptp_individual_type : string | 
| 42963 | 65 | val tptp_fun_type : string | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 66 | val tptp_product_type : string | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 67 | val tptp_forall : string | 
| 43678 | 68 | val tptp_ho_forall : string | 
| 44650 | 69 | val tptp_pi_binder : string | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 70 | val tptp_exists : string | 
| 43678 | 71 | val tptp_ho_exists : string | 
| 44495 | 72 | val tptp_choice : string | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 73 | val tptp_not : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 74 | val tptp_and : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 75 | val tptp_or : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 76 | val tptp_implies : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 77 | val tptp_if : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 78 | val tptp_iff : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 79 | val tptp_not_iff : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 80 | val tptp_app : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 81 | val tptp_not_infix : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 82 | val tptp_equal : string | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 83 | val tptp_old_equal : string | 
| 42966 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 84 | val tptp_false : string | 
| 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 85 | val tptp_true : string | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 86 | val tptp_empty_list : string | 
| 46406 | 87 | val isabelle_info_prefix : string | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 88 | val isabelle_info : string -> int -> (string, 'a) ho_term list | 
| 46442 
1e07620d724c
added possibility of generating KBO weights to DFG problems
 blanchet parents: 
46414diff
changeset | 89 | val extract_isabelle_status : (string, 'a) ho_term list -> string option | 
| 
1e07620d724c
added possibility of generating KBO weights to DFG problems
 blanchet parents: 
46414diff
changeset | 90 | val extract_isabelle_rank : (string, 'a) ho_term list -> int | 
| 48438 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 91 | val inductionN : string | 
| 46406 | 92 | val introN : string | 
| 47148 
7b5846065c1b
be less forceful about ":lt" to make infinite loops less likely (could still fail with mutually recursive tail rec functions)
 blanchet parents: 
47146diff
changeset | 93 | val inductiveN : string | 
| 46406 | 94 | val elimN : string | 
| 95 | val simpN : string | |
| 48438 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 96 | val non_rec_defN : string | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 97 | val rec_defN : string | 
| 46406 | 98 | val rankN : string | 
| 99 | val minimum_rank : int | |
| 100 | val default_rank : int | |
| 47030 | 101 | val default_term_order_weight : int | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 102 | val is_tptp_equal : string -> bool | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 103 | val is_built_in_tptp_symbol : string -> bool | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 104 | val is_tptp_variable : string -> bool | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 105 | val is_tptp_user_symbol : string -> bool | 
| 44595 
444d111bde7d
generate properly typed TFF1 (PFF) problems in the presence of type class predicates
 blanchet parents: 
44594diff
changeset | 106 | val bool_atype : (string * string) ho_type | 
| 
444d111bde7d
generate properly typed TFF1 (PFF) problems in the presence of type class predicates
 blanchet parents: 
44594diff
changeset | 107 | val individual_atype : (string * string) ho_type | 
| 48135 | 108 |   val mk_anot : ('a, 'b, 'c, 'd) formula -> ('a, 'b, 'c, 'd) formula
 | 
| 42942 | 109 | val mk_aconn : | 
| 48135 | 110 |     connective -> ('a, 'b, 'c, 'd) formula -> ('a, 'b, 'c, 'd) formula
 | 
| 111 |     -> ('a, 'b, 'c, 'd) formula
 | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 112 | val aconn_fold : | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 113 | bool option -> (bool option -> 'a -> 'b -> 'b) -> connective * 'a list | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 114 | -> 'b -> 'b | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 115 | val aconn_map : | 
| 48135 | 116 |     bool option -> (bool option -> 'a -> ('b, 'c, 'd, 'e) formula)
 | 
| 117 |     -> connective * 'a list -> ('b, 'c, 'd, 'e) formula
 | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 118 | val formula_fold : | 
| 48135 | 119 |     bool option -> (bool option -> 'c -> 'e -> 'e) -> ('a, 'b, 'c, 'd) formula
 | 
| 120 | -> 'e -> 'e | |
| 121 | val formula_map : | |
| 122 |     ('c -> 'e) -> ('a, 'b, 'c, 'd) formula -> ('a, 'b, 'e, 'd) formula
 | |
| 45303 
bd03b08161ac
added DFG unsorted support (like in the old days)
 blanchet parents: 
45301diff
changeset | 123 | val is_format_higher_order : atp_format -> bool | 
| 46442 
1e07620d724c
added possibility of generating KBO weights to DFG problems
 blanchet parents: 
46414diff
changeset | 124 | val lines_for_atp_problem : | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 125 | atp_format -> term_order -> (unit -> (string * int) list) -> string problem | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 126 | -> string list | 
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 127 | val ensure_cnf_problem : | 
| 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 128 | (string * string) problem -> (string * string) problem | 
| 42939 | 129 | val filter_cnf_ueq_problem : | 
| 130 | (string * string) problem -> (string * string) problem | |
| 48141 | 131 |   val declared_in_atp_problem : 'a problem -> ('a list * 'a list) * 'a list
 | 
| 39452 | 132 | val nice_atp_problem : | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 133 |     bool -> atp_format -> ('a * (string * string) problem_line list) list
 | 
| 38017 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 134 |     -> ('a * string problem_line list) list
 | 
| 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 135 | * (string Symtab.table * string Symtab.table) option | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 136 | end; | 
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 137 | |
| 38019 
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
 blanchet parents: 
38018diff
changeset | 138 | structure ATP_Problem : ATP_PROBLEM = | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 139 | struct | 
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 140 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43000diff
changeset | 141 | open ATP_Util | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43000diff
changeset | 142 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43000diff
changeset | 143 | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 144 | (** ATP problem **) | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 145 | |
| 43676 
3b0b448b4d69
add support for lambdas in TPTP THF generator + killed an unsound type encoding (because the monotonicity calculus assumes first-order)
 nik parents: 
43422diff
changeset | 146 | datatype ('a, 'b) ho_term =
 | 
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 147 |   ATerm of ('a * 'b list) * ('a, 'b) ho_term list |
 | 
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 148 |   AAbs of (('a * 'b) * ('a, 'b) ho_term) * ('a, 'b) ho_term list
 | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 149 | datatype quantifier = AForall | AExists | 
| 43163 | 150 | datatype connective = ANot | AAnd | AOr | AImplies | AIff | 
| 48135 | 151 | datatype ('a, 'b, 'c, 'd) formula =
 | 
| 152 |   ATyQuant of quantifier * ('b * 'd list) list * ('a, 'b, 'c, 'd) formula |
 | |
| 153 |   AQuant of quantifier * ('a * 'b option) list * ('a, 'b, 'c, 'd) formula |
 | |
| 154 |   AConn of connective * ('a, 'b, 'c, 'd) formula list |
 | |
| 42531 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 155 | AAtom of 'c | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 156 | |
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 157 | datatype 'a ho_type = | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 158 | AType of 'a * 'a ho_type list | | 
| 44594 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 159 | AFun of 'a ho_type * 'a ho_type | | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 160 | APi of 'a list * 'a ho_type | 
| 42963 | 161 | |
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 162 | type term_order = | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 163 |   {is_lpo : bool,
 | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 164 | gen_weights : bool, | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 165 | gen_prec : bool, | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 166 | gen_simp : bool} | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 167 | |
| 48140 | 168 | datatype polymorphism = Monomorphic | Polymorphic | 
| 44754 | 169 | datatype tptp_explicitness = TPTP_Implicit | TPTP_Explicit | 
| 48004 
989a34fa72b3
don't generate definitions for LEO-II -- this cuases more harm than good
 blanchet parents: 
47976diff
changeset | 170 | datatype thf_choice = THF_Without_Choice | THF_With_Choice | 
| 
989a34fa72b3
don't generate definitions for LEO-II -- this cuases more harm than good
 blanchet parents: 
47976diff
changeset | 171 | datatype thf_defs = THF_Without_Defs | THF_With_Defs | 
| 44499 | 172 | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 173 | datatype atp_format = | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 174 | CNF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 175 | CNF_UEQ | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 176 | FOF | | 
| 48130 | 177 | TFF of polymorphism * tptp_explicitness | | 
| 178 | THF of polymorphism * tptp_explicitness * thf_choice * thf_defs | | |
| 48131 | 179 | DFG of polymorphism | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 180 | |
| 47976 | 181 | datatype formula_role = Axiom | Definition | Lemma | Hypothesis | Conjecture | 
| 42527 
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
 blanchet parents: 
42526diff
changeset | 182 | datatype 'a problem_line = | 
| 48141 | 183 | Class_Decl of string * 'a * 'a list | | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 184 | Type_Decl of string * 'a * int | | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 185 | Sym_Decl of string * 'a * 'a ho_type | | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 186 |   Class_Memb of string * ('a * 'a list) list * 'a ho_type * 'a |
 | 
| 47976 | 187 | Formula of string * formula_role | 
| 48135 | 188 |              * ('a, 'a ho_type, ('a, 'a ho_type) ho_term, 'a) formula
 | 
| 46406 | 189 | * (string, string ho_type) ho_term option | 
| 190 | * (string, string ho_type) ho_term list | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 191 | type 'a problem = (string * 'a problem_line list) list | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 192 | |
| 42722 | 193 | (* official TPTP syntax *) | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 194 | val tptp_cnf = "cnf" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 195 | val tptp_fof = "fof" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 196 | val tptp_tff = "tff" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 197 | val tptp_thf = "thf" | 
| 42967 | 198 | val tptp_has_type = ":" | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 199 | val tptp_type_of_types = "$tType" | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 200 | val tptp_bool_type = "$o" | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 201 | val tptp_individual_type = "$i" | 
| 42963 | 202 | val tptp_fun_type = ">" | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 203 | val tptp_product_type = "*" | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 204 | val tptp_forall = "!" | 
| 43678 | 205 | val tptp_ho_forall = "!!" | 
| 44650 | 206 | val tptp_pi_binder = "!>" | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 207 | val tptp_exists = "?" | 
| 43678 | 208 | val tptp_ho_exists = "??" | 
| 44495 | 209 | val tptp_choice = "@+" | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 210 | val tptp_not = "~" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 211 | val tptp_and = "&" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 212 | val tptp_or = "|" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 213 | val tptp_implies = "=>" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 214 | val tptp_if = "<=" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 215 | val tptp_iff = "<=>" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 216 | val tptp_not_iff = "<~>" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 217 | val tptp_app = "@" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 218 | val tptp_not_infix = "!" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 219 | val tptp_equal = "=" | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 220 | val tptp_old_equal = "equal" | 
| 42966 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 221 | val tptp_false = "$false" | 
| 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 222 | val tptp_true = "$true" | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 223 | val tptp_empty_list = "[]" | 
| 42722 | 224 | |
| 46406 | 225 | val isabelle_info_prefix = "isabelle_" | 
| 226 | ||
| 48438 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 227 | val inductionN = "induction" | 
| 46406 | 228 | val introN = "intro" | 
| 47148 
7b5846065c1b
be less forceful about ":lt" to make infinite loops less likely (could still fail with mutually recursive tail rec functions)
 blanchet parents: 
47146diff
changeset | 229 | val inductiveN = "inductive" | 
| 46406 | 230 | val elimN = "elim" | 
| 231 | val simpN = "simp" | |
| 48438 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 232 | val non_rec_defN = "non_rec_def" | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 233 | val rec_defN = "rec_def" | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 234 | |
| 46406 | 235 | val rankN = "rank" | 
| 236 | ||
| 237 | val minimum_rank = 0 | |
| 238 | val default_rank = 1000 | |
| 47030 | 239 | val default_term_order_weight = 1 | 
| 46406 | 240 | |
| 48129 
933d43c31689
removed support for unsorted DFG, now that SPASS 3.7 is no longer supported
 blanchet parents: 
48004diff
changeset | 241 | (* Currently, only SPASS 3.8ds can process Isabelle metainformation. *) | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 242 | fun isabelle_info status rank = | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 243 | [] |> rank <> default_rank | 
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 244 | ? cons (ATerm ((isabelle_info_prefix ^ rankN, []), | 
| 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 245 | [ATerm ((string_of_int rank, []), [])])) | 
| 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 246 | |> status <> "" ? cons (ATerm ((isabelle_info_prefix ^ status, []), [])) | 
| 46406 | 247 | |
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 248 | fun extract_isabelle_status (ATerm ((s, []), []) :: _) = | 
| 46406 | 249 | try (unprefix isabelle_info_prefix) s | 
| 250 | | extract_isabelle_status _ = NONE | |
| 251 | ||
| 252 | fun extract_isabelle_rank (tms as _ :: _) = | |
| 253 | (case List.last tms of | |
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 254 | ATerm ((_, []), [ATerm ((rank, []), [])]) => the (Int.fromString rank) | 
| 46406 | 255 | | _ => default_rank) | 
| 256 | | extract_isabelle_rank _ = default_rank | |
| 257 | ||
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 258 | fun is_tptp_equal s = (s = tptp_equal orelse s = tptp_old_equal) | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 259 | fun is_built_in_tptp_symbol s = | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 260 | s = tptp_old_equal orelse not (Char.isAlpha (String.sub (s, 0))) | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 261 | fun is_tptp_variable s = Char.isUpper (String.sub (s, 0)) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 262 | val is_tptp_user_symbol = not o (is_tptp_variable orf is_built_in_tptp_symbol) | 
| 42939 | 263 | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 264 | val bool_atype = AType (`I tptp_bool_type, []) | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 265 | val individual_atype = AType (`I tptp_individual_type, []) | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 266 | |
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 267 | fun raw_polarities_of_conn ANot = (SOME false, NONE) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 268 | | raw_polarities_of_conn AAnd = (SOME true, SOME true) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 269 | | raw_polarities_of_conn AOr = (SOME true, SOME true) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 270 | | raw_polarities_of_conn AImplies = (SOME false, SOME true) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 271 | | raw_polarities_of_conn AIff = (NONE, NONE) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 272 | fun polarities_of_conn NONE = K (NONE, NONE) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 273 | | polarities_of_conn (SOME pos) = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 274 | raw_polarities_of_conn #> not pos ? pairself (Option.map not) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 275 | |
| 42942 | 276 | fun mk_anot (AConn (ANot, [phi])) = phi | 
| 277 | | mk_anot phi = AConn (ANot, [phi]) | |
| 278 | fun mk_aconn c phi1 phi2 = AConn (c, [phi1, phi2]) | |
| 279 | ||
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 280 | fun aconn_fold pos f (ANot, [phi]) = f (Option.map not pos) phi | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 281 | | aconn_fold pos f (AImplies, [phi1, phi2]) = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 282 | f (Option.map not pos) phi1 #> f pos phi2 | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 283 | | aconn_fold pos f (AAnd, phis) = fold (f pos) phis | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 284 | | aconn_fold pos f (AOr, phis) = fold (f pos) phis | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 285 | | aconn_fold _ f (_, phis) = fold (f NONE) phis | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 286 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 287 | fun aconn_map pos f (ANot, [phi]) = AConn (ANot, [f (Option.map not pos) phi]) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 288 | | aconn_map pos f (AImplies, [phi1, phi2]) = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 289 | AConn (AImplies, [f (Option.map not pos) phi1, f pos phi2]) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 290 | | aconn_map pos f (AAnd, phis) = AConn (AAnd, map (f pos) phis) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 291 | | aconn_map pos f (AOr, phis) = AConn (AOr, map (f pos) phis) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 292 | | aconn_map _ f (c, phis) = AConn (c, map (f NONE) phis) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 293 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 294 | fun formula_fold pos f = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 295 | let | 
| 44501 | 296 | fun fld pos (AQuant (_, _, phi)) = fld pos phi | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 297 | | fld pos (ATyQuant (_, _, phi)) = fld pos phi | 
| 44501 | 298 | | fld pos (AConn conn) = aconn_fold pos fld conn | 
| 299 | | fld pos (AAtom tm) = f pos tm | |
| 300 | in fld pos end | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 301 | |
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 302 | fun formula_map f (AQuant (q, xs, phi)) = AQuant (q, xs, formula_map f phi) | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 303 | | formula_map f (ATyQuant (q, xs, phi)) = ATyQuant (q, xs, formula_map f phi) | 
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 304 | | formula_map f (AConn (c, phis)) = AConn (c, map (formula_map f) phis) | 
| 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 305 | | formula_map f (AAtom tm) = AAtom (f tm) | 
| 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 306 | |
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 307 | fun strip_atype (APi (tys, ty)) = strip_atype ty |>> apfst (append tys) | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 308 | | strip_atype (AFun (ty1, ty2)) = strip_atype ty2 |>> apsnd (cons ty1) | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 309 | | strip_atype ty = (([], []), ty) | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 310 | |
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 311 | fun is_function_atype ty = snd (strip_atype ty) <> AType (tptp_bool_type, []) | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 312 | fun is_predicate_atype ty = not (is_function_atype ty) | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 313 | fun is_nontrivial_predicate_atype (AType _) = false | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 314 | | is_nontrivial_predicate_atype ty = is_predicate_atype ty | 
| 46442 
1e07620d724c
added possibility of generating KBO weights to DFG problems
 blanchet parents: 
46414diff
changeset | 315 | |
| 45303 
bd03b08161ac
added DFG unsorted support (like in the old days)
 blanchet parents: 
45301diff
changeset | 316 | fun is_format_higher_order (THF _) = true | 
| 
bd03b08161ac
added DFG unsorted support (like in the old days)
 blanchet parents: 
45301diff
changeset | 317 | | is_format_higher_order _ = false | 
| 44499 | 318 | fun is_format_typed (TFF _) = true | 
| 44754 | 319 | | is_format_typed (THF _) = true | 
| 48131 | 320 | | is_format_typed (DFG _) = true | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 321 | | is_format_typed _ = false | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 322 | |
| 47976 | 323 | fun tptp_string_for_role Axiom = "axiom" | 
| 324 | | tptp_string_for_role Definition = "definition" | |
| 325 | | tptp_string_for_role Lemma = "lemma" | |
| 326 | | tptp_string_for_role Hypothesis = "hypothesis" | |
| 327 | | tptp_string_for_role Conjecture = "conjecture" | |
| 38631 
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
 blanchet parents: 
38613diff
changeset | 328 | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 329 | fun tptp_string_for_app _ func [] = func | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 330 | | tptp_string_for_app format func args = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 331 | if is_format_higher_order format then | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 332 |       "(" ^ space_implode (" " ^ tptp_app ^ " ") (func :: args) ^ ")"
 | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 333 | else | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 334 |       func ^ "(" ^ commas args ^ ")"
 | 
| 44787 | 335 | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 336 | fun flatten_type (APi (tys, ty)) = APi (tys, flatten_type ty) | 
| 44594 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 337 | | flatten_type (ty as AFun (ty1 as AType _, ty2)) = | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 338 | (case flatten_type ty2 of | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 339 | AFun (ty' as AType (s, tys), ty) => | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 340 | AFun (AType (tptp_product_type, | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 341 | ty1 :: (if s = tptp_product_type then tys else [ty'])), ty) | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 342 | | _ => ty) | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 343 | | flatten_type (ty as AType _) = ty | 
| 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 344 | | flatten_type _ = | 
| 42963 | 345 | raise Fail "unexpected higher-order type in first-order format" | 
| 346 | ||
| 46445 | 347 | val dfg_individual_type = "iii" (* cannot clash *) | 
| 46338 
b02ff6b17599
better handling of individual type for DFG format (SPASS)
 blanchet parents: 
46320diff
changeset | 348 | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 349 | val suffix_type_of_types = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 350 |   suffix (" " ^ tptp_has_type ^ " " ^ tptp_type_of_types)
 | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 351 | |
| 44787 | 352 | fun str_for_type format ty = | 
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 353 | let | 
| 48131 | 354 | val dfg = case format of DFG _ => true | _ => false | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 355 | fun str _ (AType (s, [])) = | 
| 46338 
b02ff6b17599
better handling of individual type for DFG format (SPASS)
 blanchet parents: 
46320diff
changeset | 356 | if dfg andalso s = tptp_individual_type then dfg_individual_type else s | 
| 44594 
ae82943481e9
added type abstractions (for declaring polymorphic constants) to TFF syntax
 blanchet parents: 
44593diff
changeset | 357 | | str _ (AType (s, tys)) = | 
| 44787 | 358 | let val ss = tys |> map (str false) in | 
| 359 | if s = tptp_product_type then | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 360 | ss |> space_implode | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 361 | (if dfg then ", " else " " ^ tptp_product_type ^ " ") | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 362 |                |> (not dfg andalso length ss > 1) ? enclose "(" ")"
 | 
| 44787 | 363 | else | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 364 | tptp_string_for_app format s ss | 
| 44787 | 365 | end | 
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 366 | | str rhs (AFun (ty1, ty2)) = | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 367 |         (str false ty1 |> dfg ? enclose "(" ")") ^ " " ^
 | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 368 | (if dfg then "" else tptp_fun_type ^ " ") ^ str true ty2 | 
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 369 |         |> not rhs ? enclose "(" ")"
 | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 370 | | str _ (APi (ss, ty)) = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 371 | if dfg then | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 372 | "[" ^ commas ss ^ "], " ^ str true ty | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 373 | else | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 374 | tptp_pi_binder ^ "[" ^ commas (map suffix_type_of_types ss) ^ "]: " ^ | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 375 | str false ty | 
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 376 | in str true ty end | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 377 | |
| 44787 | 378 | fun string_for_type (format as THF _) ty = str_for_type format ty | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 379 | | string_for_type format ty = str_for_type format (flatten_type ty) | 
| 42963 | 380 | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 381 | fun tptp_string_for_quantifier AForall = tptp_forall | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 382 | | tptp_string_for_quantifier AExists = tptp_exists | 
| 42963 | 383 | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 384 | fun tptp_string_for_connective ANot = tptp_not | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 385 | | tptp_string_for_connective AAnd = tptp_and | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 386 | | tptp_string_for_connective AOr = tptp_or | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 387 | | tptp_string_for_connective AImplies = tptp_implies | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 388 | | tptp_string_for_connective AIff = tptp_iff | 
| 42963 | 389 | |
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 390 | fun string_for_bound_var format (s, ty) = | 
| 44593 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 391 | s ^ | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 392 | (if is_format_typed format then | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 393 | " " ^ tptp_has_type ^ " " ^ | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 394 | (ty |> the_default (AType (tptp_individual_type, [])) | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 395 | |> string_for_type format) | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 396 | else | 
| 
ccf40af26ae9
implement more of the polymorphic simply typed format TFF(1)
 blanchet parents: 
44589diff
changeset | 397 | "") | 
| 42963 | 398 | |
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 399 | fun tptp_string_for_term _ (ATerm ((s, []), [])) = s | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 400 | | tptp_string_for_term format (ATerm ((s, tys), ts)) = | 
| 44787 | 401 | (if s = tptp_empty_list then | 
| 402 | (* used for lists in the optional "source" field of a derivation *) | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 403 | "[" ^ commas (map (tptp_string_for_term format) ts) ^ "]" | 
| 44787 | 404 | else if is_tptp_equal s then | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 405 |        space_implode (" " ^ tptp_equal ^ " ")
 | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 406 | (map (tptp_string_for_term format) ts) | 
| 45303 
bd03b08161ac
added DFG unsorted support (like in the old days)
 blanchet parents: 
45301diff
changeset | 407 |        |> is_format_higher_order format ? enclose "(" ")"
 | 
| 48004 
989a34fa72b3
don't generate definitions for LEO-II -- this cuases more harm than good
 blanchet parents: 
47976diff
changeset | 408 | else case (s = tptp_ho_forall orelse s = tptp_ho_exists, s = tptp_choice, | 
| 
989a34fa72b3
don't generate definitions for LEO-II -- this cuases more harm than good
 blanchet parents: 
47976diff
changeset | 409 | ts) of | 
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 410 | (true, _, [AAbs (((s', ty), tm), [])]) => | 
| 44787 | 411 | (* Use syntactic sugar "!" and "?" instead of "!!" and "??" whenever | 
| 412 | possible, to work around LEO-II 1.2.8 parser limitation. *) | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 413 | tptp_string_for_formula format | 
| 44787 | 414 | (AQuant (if s = tptp_ho_forall then AForall else AExists, | 
| 415 | [(s', SOME ty)], AAtom tm)) | |
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 416 | | (_, true, [AAbs (((s', ty), tm), args)]) => | 
| 46320 | 417 | (* There is code in "ATP_Problem_Generate" to ensure that "Eps" is always | 
| 44787 | 418 | applied to an abstraction. *) | 
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 419 | tptp_string_for_app format | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 420 | (tptp_choice ^ "[" ^ s' ^ " : " ^ string_for_type format ty ^ "]: " ^ | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 421 | tptp_string_for_term format tm ^ "" | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 422 |             |> enclose "(" ")")
 | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 423 | (map (tptp_string_for_term format) args) | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 424 | | _ => | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 425 | tptp_string_for_app format s | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 426 | (map (string_for_type format) tys | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 427 | @ map (tptp_string_for_term format) ts)) | 
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 428 | | tptp_string_for_term (format as THF _) (AAbs (((s, ty), tm), args)) = | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 429 | tptp_string_for_app format | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 430 |         ("(^[" ^ s ^ " : " ^ string_for_type format ty ^ "]: " ^
 | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 431 | tptp_string_for_term format tm ^ ")") | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 432 | (map (tptp_string_for_term format) args) | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 433 | | tptp_string_for_term _ _ = | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 434 | raise Fail "unexpected term in first-order format" | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 435 | and tptp_string_for_formula format (ATyQuant (q, xs, phi)) = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 436 | tptp_string_for_quantifier q ^ | 
| 48135 | 437 | "[" ^ | 
| 438 | commas (map (suffix_type_of_types o string_for_type format o fst) xs) ^ | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 439 | "]: " ^ tptp_string_for_formula format phi | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 440 |     |> enclose "(" ")"
 | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 441 | | tptp_string_for_formula format (AQuant (q, xs, phi)) = | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 442 | tptp_string_for_quantifier q ^ | 
| 44739 | 443 | "[" ^ commas (map (string_for_bound_var format) xs) ^ "]: " ^ | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 444 | tptp_string_for_formula format phi | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 445 |     |> enclose "(" ")"
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 446 | | tptp_string_for_formula format | 
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 447 |         (AConn (ANot, [AAtom (ATerm (("=" (* tptp_equal *), []), ts))])) =
 | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 448 |     space_implode (" " ^ tptp_not_infix ^ tptp_equal ^ " ")
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 449 | (map (tptp_string_for_term format) ts) | 
| 45303 
bd03b08161ac
added DFG unsorted support (like in the old days)
 blanchet parents: 
45301diff
changeset | 450 |     |> is_format_higher_order format ? enclose "(" ")"
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 451 | | tptp_string_for_formula format (AConn (c, [phi])) = | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 452 | tptp_string_for_connective c ^ " " ^ | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 453 | (tptp_string_for_formula format phi | 
| 45303 
bd03b08161ac
added DFG unsorted support (like in the old days)
 blanchet parents: 
45301diff
changeset | 454 |      |> is_format_higher_order format ? enclose "(" ")")
 | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 455 |     |> enclose "(" ")"
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 456 | | tptp_string_for_formula format (AConn (c, phis)) = | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 457 |     space_implode (" " ^ tptp_string_for_connective c ^ " ")
 | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 458 | (map (tptp_string_for_formula format) phis) | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 459 |     |> enclose "(" ")"
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 460 | | tptp_string_for_formula format (AAtom tm) = tptp_string_for_term format tm | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 461 | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 462 | fun tptp_string_for_format CNF = tptp_cnf | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 463 | | tptp_string_for_format CNF_UEQ = tptp_cnf | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 464 | | tptp_string_for_format FOF = tptp_fof | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 465 | | tptp_string_for_format (TFF _) = tptp_tff | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 466 | | tptp_string_for_format (THF _) = tptp_thf | 
| 48131 | 467 | | tptp_string_for_format (DFG _) = raise Fail "non-TPTP format" | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 468 | |
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 469 | val atype_of_types = AType (tptp_type_of_types, []) | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 470 | |
| 48141 | 471 | fun nary_type_decl_type n = funpow n (curry AFun atype_of_types) atype_of_types | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 472 | |
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 473 | fun tptp_string_for_line format (Type_Decl (ident, ty, ary)) = | 
| 48141 | 474 | tptp_string_for_line format (Sym_Decl (ident, ty, nary_type_decl_type ary)) | 
| 48140 | 475 | | tptp_string_for_line format (Sym_Decl (ident, sym, ty)) = | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 476 |     tptp_string_for_format format ^ "(" ^ ident ^ ", type,\n    " ^ sym ^
 | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 477 | " : " ^ string_for_type format ty ^ ").\n" | 
| 48140 | 478 | | tptp_string_for_line format (Formula (ident, kind, phi, source, _)) = | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 479 |     tptp_string_for_format format ^ "(" ^ ident ^ ", " ^
 | 
| 47976 | 480 |     tptp_string_for_role kind ^ ",\n    (" ^
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 481 | tptp_string_for_formula format phi ^ ")" ^ | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 482 | (case source of | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 483 | SOME tm => ", " ^ tptp_string_for_term format tm | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 484 | | NONE => "") ^ ").\n" | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 485 | |
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 486 | fun tptp_lines format = | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 487 | maps (fn (_, []) => [] | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 488 | | (heading, lines) => | 
| 41491 | 489 |            "\n% " ^ heading ^ " (" ^ string_of_int (length lines) ^ ")\n" ::
 | 
| 48140 | 490 | map (tptp_string_for_line format) lines) | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 491 | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 492 | fun arity_of_type (APi (tys, ty)) = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 493 | arity_of_type ty |>> Integer.add (length tys) | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 494 | | arity_of_type (AFun (_, ty)) = arity_of_type ty ||> Integer.add 1 | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 495 | | arity_of_type _ = (0, 0) | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 496 | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 497 | fun string_of_arity (0, n) = string_of_int n | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 498 | | string_of_arity (m, n) = string_of_int m ^ "+" ^ string_of_int n | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 499 | |
| 48143 | 500 | val dfg_class_inter = space_implode " & " | 
| 501 | ||
| 48131 | 502 | fun dfg_string_for_formula poly gen_simp info = | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 503 | let | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 504 | val str_for_typ = string_for_type (DFG poly) | 
| 48139 
b755096701ec
generate type classes for polymorphic DFG format (SPASS)
 blanchet parents: 
48137diff
changeset | 505 | fun str_for_bound_typ (ty, []) = str_for_typ ty | 
| 48143 | 506 | | str_for_bound_typ (ty, cls) = | 
| 507 | str_for_typ ty ^ " : " ^ dfg_class_inter cls | |
| 46379 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 508 | fun suffix_tag top_level s = | 
| 48129 
933d43c31689
removed support for unsorted DFG, now that SPASS 3.7 is no longer supported
 blanchet parents: 
48004diff
changeset | 509 | if top_level then | 
| 46406 | 510 | case extract_isabelle_status info of | 
| 48438 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 511 | SOME s' => | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 512 | if s' = non_rec_defN then | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 513 | s ^ ":lt" | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 514 | else if (s' = simpN orelse s' = rec_defN) andalso gen_simp then | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 515 | s ^ ":lr" | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 516 | else | 
| 
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
 blanchet parents: 
48143diff
changeset | 517 | s | 
| 46379 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 518 | | NONE => s | 
| 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 519 | else | 
| 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 520 | s | 
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 521 | fun str_for_term top_level (ATerm ((s, tys), tms)) = | 
| 46379 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 522 | (if is_tptp_equal s then "equal" |> suffix_tag top_level | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 523 | else if s = tptp_true then "true" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 524 | else if s = tptp_false then "false" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 525 | else s) ^ | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 526 | (if null tys then "" | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 527 | else "<" ^ commas (map (string_for_type (DFG poly)) tys) ^ ">") ^ | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 528 | (if null tms then "" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 529 |          else "(" ^ commas (map (str_for_term false) tms) ^ ")")
 | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 530 | | str_for_term _ _ = raise Fail "unexpected term in first-order format" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 531 | fun str_for_quant AForall = "forall" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 532 | | str_for_quant AExists = "exists" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 533 | fun str_for_conn _ ANot = "not" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 534 | | str_for_conn _ AAnd = "and" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 535 | | str_for_conn _ AOr = "or" | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 536 | | str_for_conn _ AImplies = "implies" | 
| 46379 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 537 | | str_for_conn top_level AIff = "equiv" |> suffix_tag top_level | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 538 | fun str_for_formula top_level (ATyQuant (q, xs, phi)) = | 
| 48139 
b755096701ec
generate type classes for polymorphic DFG format (SPASS)
 blanchet parents: 
48137diff
changeset | 539 | str_for_quant q ^ "_sorts([" ^ commas (map str_for_bound_typ xs) ^ | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 540 | "], " ^ str_for_formula top_level phi ^ ")" | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 541 | | str_for_formula top_level (AQuant (q, xs, phi)) = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 542 | str_for_quant q ^ "([" ^ | 
| 48131 | 543 | commas (map (string_for_bound_var (DFG poly)) xs) ^ "], " ^ | 
| 46379 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 544 | str_for_formula top_level phi ^ ")" | 
| 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 545 | | str_for_formula top_level (AConn (c, phis)) = | 
| 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 546 |         str_for_conn top_level c ^ "(" ^
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 547 | commas (map (str_for_formula false) phis) ^ ")" | 
| 46379 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 548 | | str_for_formula top_level (AAtom tm) = str_for_term top_level tm | 
| 
de5dd84717c1
distinguish between ":lr" and ":lt" (terminating) in DFG format
 blanchet parents: 
46378diff
changeset | 549 | in str_for_formula true end | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 550 | |
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 551 | fun maybe_enclose bef aft "" = "% " ^ bef ^ aft | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 552 | | maybe_enclose bef aft s = bef ^ s ^ aft | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 553 | |
| 48131 | 554 | fun dfg_lines poly {is_lpo, gen_weights, gen_prec, gen_simp} ord_info problem =
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 555 | let | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 556 | val str_for_typ = string_for_type (DFG poly) | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 557 |     fun spair (s, s') = "(" ^ s ^ ", " ^ s' ^ ")"
 | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 558 | fun tm_ary sym ty = spair (sym, string_of_arity (arity_of_type ty)) | 
| 48141 | 559 | fun ty_ary 0 ty = ty | 
| 560 |       | ty_ary n ty = "(" ^ ty ^ ", " ^ string_of_int n ^ ")"
 | |
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 561 |     fun fun_typ sym ty = "function(" ^ sym ^ ", " ^ str_for_typ ty ^ ")."
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 562 | fun pred_typ sym ty = | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 563 | let | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 564 | val (ty_vars, tys) = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 565 | strip_atype ty |> fst | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 566 | |>> (fn [] => [] | ty_vars => ["[" ^ commas ty_vars ^ "]"]) | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 567 |       in "predicate(" ^ commas (sym :: ty_vars @ map str_for_typ tys) ^ ")." end
 | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 568 | fun str_for_bound_tvar (ty, []) = ty | 
| 48143 | 569 | | str_for_bound_tvar (ty, cls) = ty ^ " : " ^ dfg_class_inter cls | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 570 | fun sort_decl xs ty cl = | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 571 |       "sort(" ^
 | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 572 | (if null xs then "" | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 573 | else "[" ^ commas (map str_for_bound_tvar xs) ^ "], ") ^ | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 574 | str_for_typ ty ^ ", " ^ cl ^ ")." | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 575 |     fun subclass_of sub super = "subclass(" ^ sub ^ ", " ^ super ^ ")."
 | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 576 | fun formula pred (Formula (ident, kind, phi, _, info)) = | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 577 | if pred kind then | 
| 48129 
933d43c31689
removed support for unsorted DFG, now that SPASS 3.7 is no longer supported
 blanchet parents: 
48004diff
changeset | 578 | let val rank = extract_isabelle_rank info in | 
| 48131 | 579 |             "formula(" ^ dfg_string_for_formula poly gen_simp info phi ^
 | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 580 | ", " ^ ident ^ | 
| 46406 | 581 | (if rank = default_rank then "" else ", " ^ string_of_int rank) ^ | 
| 582 | ")." |> SOME | |
| 583 | end | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 584 | else | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 585 | NONE | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 586 | | formula _ _ = NONE | 
| 46413 | 587 | fun filt f = problem |> map (map_filter f o snd) |> filter_out null | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 588 | val func_aries = | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 589 | filt (fn Sym_Decl (_, sym, ty) => | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 590 | if is_function_atype ty then SOME (tm_ary sym ty) else NONE | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 591 | | _ => NONE) | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 592 | |> flat |> commas |> maybe_enclose "functions [" "]." | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 593 | val pred_aries = | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 594 | filt (fn Sym_Decl (_, sym, ty) => | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 595 | if is_predicate_atype ty then SOME (tm_ary sym ty) else NONE | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 596 | | _ => NONE) | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 597 | |> flat |> commas |> maybe_enclose "predicates [" "]." | 
| 48129 
933d43c31689
removed support for unsorted DFG, now that SPASS 3.7 is no longer supported
 blanchet parents: 
48004diff
changeset | 598 | val sorts = | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 599 | filt (fn Type_Decl (_, ty, ary) => SOME (ty_ary ary ty) | _ => NONE) @ | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 600 | [[ty_ary 0 dfg_individual_type]] | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 601 | |> flat |> commas |> maybe_enclose "sorts [" "]." | 
| 48141 | 602 | val classes = | 
| 603 | filt (fn Class_Decl (_, cl, _) => SOME cl | _ => NONE) | |
| 604 | |> flat |> commas |> maybe_enclose "classes [" "]." | |
| 48129 
933d43c31689
removed support for unsorted DFG, now that SPASS 3.7 is no longer supported
 blanchet parents: 
48004diff
changeset | 605 | val ord_info = if gen_weights orelse gen_prec then ord_info () else [] | 
| 
933d43c31689
removed support for unsorted DFG, now that SPASS 3.7 is no longer supported
 blanchet parents: 
48004diff
changeset | 606 | val do_term_order_weights = | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 607 | (if gen_weights then ord_info else []) | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 608 | |> map (spair o apsnd string_of_int) |> commas | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 609 | |> maybe_enclose "weights [" "]." | 
| 48141 | 610 | val syms = [func_aries, pred_aries, do_term_order_weights, sorts, classes] | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 611 | val func_decls = | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 612 | filt (fn Sym_Decl (_, sym, ty) => | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 613 | if is_function_atype ty then SOME (fun_typ sym ty) else NONE | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 614 | | _ => NONE) |> flat | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 615 | val pred_decls = | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 616 | filt (fn Sym_Decl (_, sym, ty) => | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 617 | if is_nontrivial_predicate_atype ty then SOME (pred_typ sym ty) | 
| 46391 
8d8d3c1f1854
really fixed syntax bug in DFG output (cf. ef62c2fafa9e)
 blanchet parents: 
46382diff
changeset | 618 | else NONE | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 619 | | _ => NONE) |> flat | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 620 | val sort_decls = | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 621 | filt (fn Class_Memb (_, xs, ty, cl) => SOME (sort_decl xs ty cl) | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 622 | | _ => NONE) |> flat | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 623 | val subclass_decls = | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 624 | filt (fn Class_Decl (_, sub, supers) => | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 625 | SOME (map (subclass_of sub) supers) | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 626 | | _ => NONE) |> flat |> flat | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 627 | val decls = func_decls @ pred_decls @ sort_decls @ subclass_decls | 
| 46413 | 628 | val axioms = | 
| 629 | filt (formula (curry (op <>) Conjecture)) |> separate [""] |> flat | |
| 630 | val conjs = | |
| 631 | filt (formula (curry (op =) Conjecture)) |> separate [""] |> flat | |
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 632 | val settings = | 
| 47054 | 633 | (if is_lpo then ["set_flag(Ordering, 1)."] else []) @ | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 634 | (if gen_prec then | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 635 | [ord_info |> map fst |> rev |> commas | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 636 |                    |> maybe_enclose "set_precedence(" ")."]
 | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 637 | else | 
| 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 638 | []) | 
| 47053 | 639 | fun list_of _ [] = [] | 
| 640 | | list_of heading ss = | |
| 641 | "list_of_" ^ heading ^ ".\n" :: map (suffix "\n") ss @ | |
| 642 | ["end_of_list.\n\n"] | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 643 | in | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 644 | "\nbegin_problem(isabelle).\n\n" :: | 
| 47053 | 645 | list_of "descriptions" | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 646 |             ["name({**}).", "author({**}).", "status(unknown).",
 | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 647 |              "description({**})."] @
 | 
| 47053 | 648 | list_of "symbols" syms @ | 
| 649 | list_of "declarations" decls @ | |
| 650 | list_of "formulae(axioms)" axioms @ | |
| 651 | list_of "formulae(conjectures)" conjs @ | |
| 652 | list_of "settings(SPASS)" settings @ | |
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 653 | ["end_problem.\n"] | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 654 | end | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 655 | |
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 656 | fun lines_for_atp_problem format ord ord_info problem = | 
| 45301 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 657 | "% This file was generated by Isabelle (most likely Sledgehammer)\n\ | 
| 
866b075aa99b
added sorted DFG output for coming version of SPASS
 blanchet parents: 
44787diff
changeset | 658 | \% " ^ timestamp () ^ "\n" :: | 
| 48131 | 659 | (case format of | 
| 660 | DFG poly => dfg_lines poly ord ord_info | |
| 661 | | _ => tptp_lines format) problem | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 662 | |
| 42939 | 663 | |
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 664 | (** CNF (Metis) and CNF UEQ (Waldmeister) **) | 
| 42939 | 665 | |
| 48140 | 666 | fun is_line_negated (Formula (_, _, AConn (ANot, _), _, _)) = true | 
| 667 | | is_line_negated _ = false | |
| 42939 | 668 | |
| 48140 | 669 | fun is_line_cnf_ueq (Formula (_, _, AAtom (ATerm (((s, _), _), _)), _, _)) = | 
| 43193 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 670 | is_tptp_equal s | 
| 48140 | 671 | | is_line_cnf_ueq _ = false | 
| 42939 | 672 | |
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 673 | fun open_conjecture_term (ATerm (((s, s'), tys), tms)) = | 
| 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 674 | ATerm ((if is_tptp_variable s then (s |> Name.desymbolize false, s') | 
| 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 675 | else (s, s'), tys), tms |> map open_conjecture_term) | 
| 43676 
3b0b448b4d69
add support for lambdas in TPTP THF generator + killed an unsound type encoding (because the monotonicity calculus assumes first-order)
 nik parents: 
43422diff
changeset | 676 | | open_conjecture_term _ = raise Fail "unexpected higher-order term" | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 677 | fun open_formula conj = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 678 | let | 
| 43193 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 679 | (* We are conveniently assuming that all bound variable names are | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 680 | distinct, which should be the case for the formulas we generate. *) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 681 | fun opn (pos as SOME true) (AQuant (AForall, _, phi)) = opn pos phi | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 682 | | opn (pos as SOME false) (AQuant (AExists, _, phi)) = opn pos phi | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 683 | | opn pos (AConn (ANot, [phi])) = mk_anot (opn (Option.map not pos) phi) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 684 | | opn pos (AConn (c, [phi1, phi2])) = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 685 | let val (pos1, pos2) = polarities_of_conn pos c in | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 686 | AConn (c, [opn pos1 phi1, opn pos2 phi2]) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 687 | end | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 688 | | opn _ (AAtom t) = AAtom (t |> conj ? open_conjecture_term) | 
| 43422 
dcbedaf6f80c
added missing case in pattern matching -- solves Waldmeister "Match" exceptions that have been plaguing some users
 blanchet parents: 
43295diff
changeset | 689 | | opn _ phi = phi | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 690 | in opn (SOME (not conj)) end | 
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 691 | fun open_formula_line (Formula (ident, kind, phi, source, info)) = | 
| 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 692 | Formula (ident, kind, open_formula (kind = Conjecture) phi, source, info) | 
| 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 693 | | open_formula_line line = line | 
| 42939 | 694 | |
| 695 | fun negate_conjecture_line (Formula (ident, Conjecture, phi, source, info)) = | |
| 42942 | 696 | Formula (ident, Hypothesis, mk_anot phi, source, info) | 
| 42939 | 697 | | negate_conjecture_line line = line | 
| 698 | ||
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 699 | exception CLAUSIFY of unit | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 700 | |
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 701 | (* This "clausification" only expands syntactic sugar, such as "phi => psi" to | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 702 | "~ phi | psi" and "phi <=> psi" to "~ phi | psi" and "~ psi | phi". We don't | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 703 | attempt to distribute conjunctions over disjunctions. *) | 
| 43193 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 704 | fun clausify_formula pos (phi as AAtom _) = [phi |> not pos ? mk_anot] | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 705 | | clausify_formula pos (AConn (ANot, [phi])) = clausify_formula (not pos) phi | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 706 | | clausify_formula true (AConn (AOr, [phi1, phi2])) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 707 | (phi1, phi2) |> pairself (clausify_formula true) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 708 | |> uncurry (map_product (mk_aconn AOr)) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 709 | | clausify_formula false (AConn (AAnd, [phi1, phi2])) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 710 | (phi1, phi2) |> pairself (clausify_formula false) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 711 | |> uncurry (map_product (mk_aconn AOr)) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 712 | | clausify_formula true (AConn (AImplies, [phi1, phi2])) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 713 | clausify_formula true (AConn (AOr, [mk_anot phi1, phi2])) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 714 | | clausify_formula true (AConn (AIff, phis)) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 715 | clausify_formula true (AConn (AImplies, phis)) @ | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 716 | clausify_formula true (AConn (AImplies, rev phis)) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 717 | | clausify_formula _ _ = raise CLAUSIFY () | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 718 | |
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 719 | fun clausify_formula_line (Formula (ident, kind, phi, source, info)) = | 
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 720 | let | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 721 | val (n, phis) = phi |> try (clausify_formula true) |> these |> `length | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 722 | in | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 723 | map2 (fn phi => fn j => | 
| 43295 
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
 blanchet parents: 
43224diff
changeset | 724 | Formula (ident ^ replicate_string (j - 1) "x", kind, phi, source, | 
| 
30aaab778416
pass Metis facts and negated conjecture as facts, with (almost) correctly set localities, so that the correct encoding is used for nonmonotonic occurrences of infinite types
 blanchet parents: 
43224diff
changeset | 725 | info)) | 
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 726 | phis (1 upto n) | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 727 | end | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 728 | | clausify_formula_line _ = [] | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 729 | |
| 48140 | 730 | fun ensure_cnf_line line = | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 731 | line |> open_formula_line |> negate_conjecture_line |> clausify_formula_line | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 732 | |
| 48140 | 733 | fun ensure_cnf_problem problem = problem |> map (apsnd (maps ensure_cnf_line)) | 
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 734 | |
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 735 | fun filter_cnf_ueq_problem problem = | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 736 | problem | 
| 48140 | 737 | |> map (apsnd (map open_formula_line #> filter is_line_cnf_ueq | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 738 | #> map negate_conjecture_line)) | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 739 | |> (fn problem => | 
| 42939 | 740 | let | 
| 43824 
0234156d3fbe
don't generate Waldmeister problems with only a conjecture, since it makes it crash sometimes
 blanchet parents: 
43692diff
changeset | 741 | val lines = problem |> maps snd | 
| 48140 | 742 | val conjs = lines |> filter is_line_negated | 
| 43824 
0234156d3fbe
don't generate Waldmeister problems with only a conjecture, since it makes it crash sometimes
 blanchet parents: 
43692diff
changeset | 743 | in if length conjs = 1 andalso conjs <> lines then problem else [] end) | 
| 38017 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 744 | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 745 | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 746 | (** Symbol declarations **) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 747 | |
| 48141 | 748 | fun add_declared_in_line (Class_Decl (_, cl, _)) = apfst (apfst (cons cl)) | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 749 | | add_declared_in_line (Type_Decl (_, ty, _)) = apfst (apsnd (cons ty)) | 
| 48140 | 750 | | add_declared_in_line (Sym_Decl (_, sym, _)) = apsnd (cons sym) | 
| 751 | | add_declared_in_line _ = I | |
| 48141 | 752 | fun declared_in_atp_problem problem = | 
| 753 | fold (fold add_declared_in_line o snd) problem (([], []), []) | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 754 | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 755 | (** Nice names **) | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 756 | |
| 37624 | 757 | fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs | 
| 758 | fun pool_map f xs = | |
| 759 | pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs [] | |
| 760 | ||
| 42227 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 761 | val no_qualifiers = | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 762 | let | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 763 | fun skip [] = [] | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 764 | | skip (#"." :: cs) = skip cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 765 | | skip (c :: cs) = if Char.isAlphaNum c then skip cs else c :: keep cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 766 | and keep [] = [] | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 767 | | keep (#"." :: cs) = skip cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 768 | | keep (c :: cs) = c :: keep cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 769 | in String.explode #> rev #> keep #> rev #> String.implode end | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 770 | |
| 42761 
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
 blanchet parents: 
42752diff
changeset | 771 | (* Long names can slow down the ATPs. *) | 
| 42724 
4d6bcf846759
added "max_mono_instances" option to Sledgehammer and renamed old "monomorphize_limit" option
 blanchet parents: 
42722diff
changeset | 772 | val max_readable_name_size = 20 | 
| 42567 
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
 blanchet parents: 
42543diff
changeset | 773 | |
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 774 | (* "equal" is reserved by some ATPs. "op" is also reserved, to avoid the | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 775 | unreadable "op_1", "op_2", etc., in the problem files. "eq" is reserved to | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 776 | ensure that "HOL.eq" is correctly mapped to equality (not clear whether this | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 777 | is still necessary). *) | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 778 | val reserved_nice_names = [tptp_old_equal, "op", "eq"] | 
| 42939 | 779 | |
| 46414 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 780 | (* hack to get the same hashing across Mirabelle runs (see "mirabelle.pl") *) | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 781 | fun cleanup_mirabelle_name s = | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 782 | let | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 783 | val mirabelle_infix = "_Mirabelle_" | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 784 | val random_suffix_len = 10 | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 785 | val (s1, s2) = Substring.position mirabelle_infix (Substring.full s) | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 786 | in | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 787 | if Substring.isEmpty s2 then | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 788 | s | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 789 | else | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 790 | Substring.string s1 ^ | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 791 | Substring.string (Substring.triml (size mirabelle_infix + random_suffix_len) s2) | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 792 | end | 
| 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 793 | |
| 46378 | 794 | fun readable_name protect full_name s = | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 795 | (if s = full_name then | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 796 | s | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 797 | else | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 798 | s |> no_qualifiers | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 799 | |> perhaps (try (unprefix "'")) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 800 | |> Name.desymbolize (Char.isUpper (String.sub (full_name, 0))) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 801 | |> (fn s => | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 802 | if size s > max_readable_name_size then | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 803 | String.substring (s, 0, max_readable_name_size div 2 - 4) ^ | 
| 46414 
4ed12518fb81
improved hashing w.r.t. Mirabelle, to help debugging
 blanchet parents: 
46413diff
changeset | 804 | string_of_int (hash_string (cleanup_mirabelle_name full_name)) ^ | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 805 | String.extract (s, size s - max_readable_name_size div 2 + 4, | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 806 | NONE) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 807 | else | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 808 | s) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 809 | |> (fn s => | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 810 | if member (op =) reserved_nice_names s then full_name else s)) | 
| 46378 | 811 | |> protect | 
| 37624 | 812 | |
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 813 | fun nice_name _ (full_name, _) NONE = (full_name, NONE) | 
| 46378 | 814 | | nice_name protect (full_name, desired_name) (SOME the_pool) = | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 815 | if is_built_in_tptp_symbol full_name then | 
| 39384 | 816 | (full_name, SOME the_pool) | 
| 817 | else case Symtab.lookup (fst the_pool) full_name of | |
| 37624 | 818 | SOME nice_name => (nice_name, SOME the_pool) | 
| 819 | | NONE => | |
| 820 | let | |
| 46378 | 821 | val nice_prefix = readable_name protect full_name desired_name | 
| 37624 | 822 | fun add j = | 
| 823 | let | |
| 42644 | 824 | val nice_name = | 
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 825 | nice_prefix ^ (if j = 1 then "" else string_of_int j) | 
| 37624 | 826 | in | 
| 827 | case Symtab.lookup (snd the_pool) nice_name of | |
| 828 | SOME full_name' => | |
| 829 | if full_name = full_name' then (nice_name, the_pool) | |
| 830 | else add (j + 1) | |
| 831 | | NONE => | |
| 832 | (nice_name, | |
| 833 | (Symtab.update_new (full_name, nice_name) (fst the_pool), | |
| 834 | Symtab.update_new (nice_name, full_name) (snd the_pool))) | |
| 835 | end | |
| 47038 
2409b484e1cc
continued implementation of term ordering attributes
 blanchet parents: 
47030diff
changeset | 836 | in add 1 |> apsnd SOME end | 
| 37624 | 837 | |
| 46643 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 838 | fun avoid_clash_with_alt_ergo_type_vars s = | 
| 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 839 | if is_tptp_variable s then s else s ^ "_" | 
| 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 840 | |
| 46378 | 841 | fun avoid_clash_with_dfg_keywords s = | 
| 842 | let val n = String.size s in | |
| 46443 
c86276014571
improved KBO weights -- beware of explicit applications
 blanchet parents: 
46442diff
changeset | 843 | if n < 2 orelse (n = 2 andalso String.sub (s, 0) = String.sub (s, 1)) orelse | 
| 
c86276014571
improved KBO weights -- beware of explicit applications
 blanchet parents: 
46442diff
changeset | 844 | String.isSubstring "_" s then | 
| 46378 | 845 | s | 
| 47150 | 846 | else if is_tptp_variable s then | 
| 47146 | 847 | (* "DL" appears to be a SPASS 3.7 keyword *) | 
| 47150 | 848 | if s = "DL" then s ^ "_" else s | 
| 46378 | 849 | else | 
| 850 | String.substring (s, 0, n - 1) ^ | |
| 851 | String.str (Char.toUpper (String.sub (s, n - 1))) | |
| 852 | end | |
| 853 | ||
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 854 | fun nice_atp_problem readable_names format problem = | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 855 | let | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 856 | val empty_pool = | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 857 | if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE | 
| 46643 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 858 | val avoid_clash = | 
| 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 859 | case format of | 
| 48130 | 860 | TFF (Polymorphic, _) => avoid_clash_with_alt_ergo_type_vars | 
| 48131 | 861 | | DFG _ => avoid_clash_with_dfg_keywords | 
| 46643 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 862 | | _ => I | 
| 
a88bccd2b567
added support for Alt-Ergo through Why3 (mostly for experimental purposes, e.g. polymorphism vs. monomorphization)
 blanchet parents: 
46445diff
changeset | 863 | val nice_name = nice_name avoid_clash | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 864 | fun nice_type (AType (name, tys)) = | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 865 | nice_name name ##>> pool_map nice_type tys #>> AType | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 866 | | nice_type (AFun (ty1, ty2)) = nice_type ty1 ##>> nice_type ty2 #>> AFun | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 867 | | nice_type (APi (names, ty)) = | 
| 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 868 | pool_map nice_name names ##>> nice_type ty #>> APi | 
| 48132 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 869 | fun nice_term (ATerm ((name, tys), ts)) = | 
| 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 870 | nice_name name ##>> pool_map nice_type tys ##>> pool_map nice_term ts | 
| 
9aa0fad4e864
added type arguments to "ATerm" constructor -- but don't use them yet
 blanchet parents: 
48131diff
changeset | 871 | #>> ATerm | 
| 47911 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 872 | | nice_term (AAbs (((name, ty), tm), args)) = | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 873 | nice_name name ##>> nice_type ty ##>> nice_term tm | 
| 
2168126446bb
extend ATP data structure to avoid having to perform ((non-)capture avoiding) beta reduction -- fixes a bug in the THF translation of "is_measure.simps"
 blanchet parents: 
47768diff
changeset | 874 | ##>> pool_map nice_term args #>> AAbs | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 875 | fun nice_formula (ATyQuant (q, xs, phi)) = | 
| 48135 | 876 | pool_map nice_type (map fst xs) | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 877 | ##>> pool_map (pool_map nice_name) (map snd xs) | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 878 | ##>> nice_formula phi | 
| 48141 | 879 | #>> (fn ((tys, cls), phi) => ATyQuant (q, tys ~~ cls, phi)) | 
| 48133 
a5ab5964065f
implement polymorphic DFG output, without type classes for now
 blanchet parents: 
48132diff
changeset | 880 | | nice_formula (AQuant (q, xs, phi)) = | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 881 | pool_map nice_name (map fst xs) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 882 | ##>> pool_map (fn NONE => pair NONE | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 883 | | SOME ty => nice_type ty #>> SOME) (map snd xs) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 884 | ##>> nice_formula phi | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 885 | #>> (fn ((ss, ts), phi) => AQuant (q, ss ~~ ts, phi)) | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 886 | | nice_formula (AConn (c, phis)) = | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 887 | pool_map nice_formula phis #>> curry AConn c | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 888 | | nice_formula (AAtom tm) = nice_term tm #>> AAtom | 
| 48141 | 889 | fun nice_line (Class_Decl (ident, cl, cls)) = | 
| 890 | nice_name cl ##>> pool_map nice_name cls | |
| 891 | #>> (fn (cl, cls) => Class_Decl (ident, cl, cls)) | |
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 892 | | nice_line (Type_Decl (ident, ty, ary)) = | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 893 | nice_name ty #>> (fn ty => Type_Decl (ident, ty, ary)) | 
| 48140 | 894 | | nice_line (Sym_Decl (ident, sym, ty)) = | 
| 48137 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 895 | nice_name sym ##>> nice_type ty | 
| 
6f524f2066e3
cleanly distinguish between type declarations and symbol declarations
 blanchet parents: 
48135diff
changeset | 896 | #>> (fn (sym, ty) => Sym_Decl (ident, sym, ty)) | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 897 | | nice_line (Class_Memb (ident, xs, ty, cl)) = | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 898 | pool_map nice_name (map fst xs) | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 899 | ##>> pool_map (pool_map nice_name) (map snd xs) | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 900 | ##>> nice_type ty ##>> nice_name cl | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 901 | #>> (fn (((tys, cls), ty), cl) => | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 902 | Class_Memb (ident, tys ~~ cls, ty, cl)) | 
| 48140 | 903 | | nice_line (Formula (ident, kind, phi, source, info)) = | 
| 48142 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 904 | nice_formula phi | 
| 
efaff8206967
finished implementation of DFG type class output
 blanchet parents: 
48141diff
changeset | 905 | #>> (fn phi => Formula (ident, kind, phi, source, info)) | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 906 | fun nice_problem problem = | 
| 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 907 | pool_map (fn (heading, lines) => | 
| 48140 | 908 | pool_map nice_line lines #>> pair heading) problem | 
| 45939 
711fec5b4f61
don't try to avoid SPASS keywords; instead, just suffix an underscore to all generated identifiers
 blanchet parents: 
45938diff
changeset | 909 | in nice_problem problem empty_pool end | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 910 | |
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 911 | end; |