| author | huffman | 
| Tue, 23 Aug 2011 14:11:02 -0700 | |
| changeset 44457 | d366fa5551ef | 
| parent 44407 | 7b6629037127 | 
| child 44495 | 4c2242c8a96c | 
| 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 =
 | 
| 
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 | 11 |     ATerm of 'a * ('a, 'b) ho_term list |
 | 
| 
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 | 12 |     AAbs of ('a * 'b) * ('a, 'b) ho_term
 | 
| 37992 | 13 | datatype quantifier = AForall | AExists | 
| 43163 | 14 | datatype connective = ANot | AAnd | AOr | AImplies | AIff | 
| 42531 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 15 |   datatype ('a, 'b, 'c) formula =
 | 
| 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 16 |     AQuant of quantifier * ('a * 'b option) list * ('a, 'b, 'c) formula |
 | 
| 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 17 |     AConn of connective * ('a, 'b, 'c) formula list |
 | 
| 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 18 | AAtom of 'c | 
| 37994 
b04307085a09
make TPTP generator accept full first-order formulas
 blanchet parents: 
37993diff
changeset | 19 | |
| 42963 | 20 | datatype 'a ho_type = AType of 'a | AFun of 'a ho_type * 'a ho_type | 
| 21 | ||
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 22 | datatype thf_flavor = Without_Choice | With_Choice | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 23 | datatype format = | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 24 | CNF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 25 | CNF_UEQ | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 26 | FOF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 27 | TFF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 28 | THF of thf_flavor | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 29 | |
| 42525 
7a506b0b644f
distinguish FOF and TFF (typed first-order) in ATP abstract syntax tree
 blanchet parents: 
42449diff
changeset | 30 | datatype formula_kind = 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 | 31 | datatype 'a problem_line = | 
| 42963 | 32 | Decl of string * 'a * 'a ho_type | | 
| 44402 | 33 | Formula of string * formula_kind | 
| 34 |                * ('a, 'a ho_type, ('a, 'a ho_type) ho_term) formula
 | |
| 35 | * (string, string ho_type) ho_term option | |
| 36 | * (string, string ho_type) ho_term option | |
| 38017 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 37 | type 'a problem = (string * 'a problem_line list) list | 
| 37992 | 38 | |
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 39 | val tptp_cnf : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 40 | val tptp_fof : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 41 | val tptp_tff : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 42 | val tptp_thf : string | 
| 42967 | 43 | val tptp_has_type : string | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 44 | val tptp_type_of_types : string | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 45 | val tptp_bool_type : string | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 46 | val tptp_individual_type : string | 
| 42963 | 47 | val tptp_fun_type : string | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 48 | val tptp_product_type : string | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 49 | val tptp_forall : string | 
| 43678 | 50 | val tptp_ho_forall : string | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 51 | val tptp_exists : string | 
| 43678 | 52 | val tptp_ho_exists : string | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 53 | val tptp_not : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 54 | val tptp_and : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 55 | val tptp_or : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 56 | val tptp_implies : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 57 | val tptp_if : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 58 | val tptp_iff : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 59 | val tptp_not_iff : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 60 | val tptp_app : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 61 | val tptp_not_infix : string | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 62 | val tptp_equal : string | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 63 | val tptp_old_equal : string | 
| 42966 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 64 | val tptp_false : string | 
| 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 65 | val tptp_true : string | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 66 | val tptp_empty_list : string | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 67 | val is_tptp_equal : string -> bool | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 68 | val is_built_in_tptp_symbol : string -> bool | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 69 | val is_tptp_variable : string -> bool | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 70 | val is_tptp_user_symbol : string -> bool | 
| 42942 | 71 |   val mk_anot : ('a, 'b, 'c) formula -> ('a, 'b, 'c) formula
 | 
| 72 | val mk_aconn : | |
| 73 |     connective -> ('a, 'b, 'c) formula -> ('a, 'b, 'c) formula
 | |
| 74 |     -> ('a, 'b, 'c) formula
 | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 75 | val aconn_fold : | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 76 | 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 | 77 | -> 'b -> 'b | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 78 | val aconn_map : | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 79 |     bool option -> (bool option -> 'a -> ('b, 'c, 'd) formula)
 | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 80 |     -> connective * 'a list -> ('b, 'c, 'd) formula
 | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 81 | val formula_fold : | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 82 |     bool option -> (bool option -> 'c -> 'd -> 'd) -> ('a, 'b, 'c) formula
 | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 83 | -> 'd -> 'd | 
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 84 |   val formula_map : ('c -> 'd) -> ('a, 'b, 'c) formula -> ('a, 'b, 'd) formula
 | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 85 | val is_format_thf : format -> bool | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 86 | val is_format_typed : format -> bool | 
| 43224 | 87 | val tptp_lines_for_atp_problem : format -> string problem -> string list | 
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 88 | val ensure_cnf_problem : | 
| 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 89 | (string * string) problem -> (string * string) problem | 
| 42939 | 90 | val filter_cnf_ueq_problem : | 
| 91 | (string * string) problem -> (string * string) problem | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 92 | val declare_undeclared_syms_in_atp_problem : | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 93 | string -> string -> (string * string) problem -> (string * string) problem | 
| 39452 | 94 | val nice_atp_problem : | 
| 38017 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 95 |     bool -> ('a * (string * string) problem_line list) list
 | 
| 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 96 |     -> ('a * string problem_line list) list
 | 
| 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 97 | * (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 | 98 | end; | 
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 99 | |
| 38019 
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
 blanchet parents: 
38018diff
changeset | 100 | 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 | 101 | struct | 
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 102 | |
| 43085 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43000diff
changeset | 103 | open ATP_Util | 
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43000diff
changeset | 104 | |
| 
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
 blanchet parents: 
43000diff
changeset | 105 | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 106 | (** ATP problem **) | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 107 | |
| 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 | 108 | datatype ('a, 'b) ho_term =
 | 
| 
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 | 109 |   ATerm of 'a * ('a, 'b) ho_term list |
 | 
| 
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 | 110 |   AAbs of ('a * 'b) * ('a, 'b) ho_term
 | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 111 | datatype quantifier = AForall | AExists | 
| 43163 | 112 | datatype connective = ANot | AAnd | AOr | AImplies | AIff | 
| 42531 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 113 | datatype ('a, 'b, 'c) formula =
 | 
| 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 114 |   AQuant of quantifier * ('a * 'b option) list * ('a, 'b, 'c) formula |
 | 
| 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 115 |   AConn of connective * ('a, 'b, 'c) formula list |
 | 
| 
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
 blanchet parents: 
42530diff
changeset | 116 | AAtom of 'c | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 117 | |
| 42963 | 118 | datatype 'a ho_type = AType of 'a | AFun of 'a ho_type * 'a ho_type | 
| 119 | ||
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 120 | datatype thf_flavor = Without_Choice | With_Choice | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 121 | datatype format = | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 122 | CNF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 123 | CNF_UEQ | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 124 | FOF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 125 | TFF | | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 126 | THF of thf_flavor | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 127 | |
| 42525 
7a506b0b644f
distinguish FOF and TFF (typed first-order) in ATP abstract syntax tree
 blanchet parents: 
42449diff
changeset | 128 | datatype formula_kind = 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 | 129 | datatype 'a problem_line = | 
| 42963 | 130 | Decl of string * 'a * 'a ho_type | | 
| 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 | 131 |   Formula of string * formula_kind * ('a, 'a ho_type, ('a, 'a ho_type) ho_term) formula
 | 
| 
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 | 132 | * (string, string ho_type) ho_term option * (string, string ho_type) ho_term option | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 133 | 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 | 134 | |
| 42722 | 135 | (* official TPTP syntax *) | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 136 | val tptp_cnf = "cnf" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 137 | val tptp_fof = "fof" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 138 | val tptp_tff = "tff" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 139 | val tptp_thf = "thf" | 
| 42967 | 140 | val tptp_has_type = ":" | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 141 | val tptp_type_of_types = "$tType" | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 142 | val tptp_bool_type = "$o" | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 143 | val tptp_individual_type = "$i" | 
| 42963 | 144 | val tptp_fun_type = ">" | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 145 | val tptp_product_type = "*" | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 146 | val tptp_forall = "!" | 
| 43678 | 147 | val tptp_ho_forall = "!!" | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 148 | val tptp_exists = "?" | 
| 43678 | 149 | val tptp_ho_exists = "??" | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 150 | val tptp_not = "~" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 151 | val tptp_and = "&" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 152 | val tptp_or = "|" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 153 | val tptp_implies = "=>" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 154 | val tptp_if = "<=" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 155 | val tptp_iff = "<=>" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 156 | val tptp_not_iff = "<~>" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 157 | val tptp_app = "@" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 158 | val tptp_not_infix = "!" | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 159 | val tptp_equal = "=" | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 160 | val tptp_old_equal = "equal" | 
| 42966 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 161 | val tptp_false = "$false" | 
| 
4e2d6c1e5392
more work on parsing LEO-II proofs without lambdas
 blanchet parents: 
42963diff
changeset | 162 | val tptp_true = "$true" | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 163 | val tptp_empty_list = "[]" | 
| 42722 | 164 | |
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 165 | 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 | 166 | fun is_built_in_tptp_symbol s = | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 167 | 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 | 168 | 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 | 169 | val is_tptp_user_symbol = not o (is_tptp_variable orf is_built_in_tptp_symbol) | 
| 42939 | 170 | |
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 171 | fun raw_polarities_of_conn ANot = (SOME false, NONE) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 172 | | raw_polarities_of_conn AAnd = (SOME true, SOME true) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 173 | | raw_polarities_of_conn AOr = (SOME true, SOME true) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 174 | | raw_polarities_of_conn AImplies = (SOME false, SOME true) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 175 | | raw_polarities_of_conn AIff = (NONE, NONE) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 176 | fun polarities_of_conn NONE = K (NONE, NONE) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 177 | | polarities_of_conn (SOME pos) = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 178 | raw_polarities_of_conn #> not pos ? pairself (Option.map not) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 179 | |
| 42942 | 180 | fun mk_anot (AConn (ANot, [phi])) = phi | 
| 181 | | mk_anot phi = AConn (ANot, [phi]) | |
| 182 | fun mk_aconn c phi1 phi2 = AConn (c, [phi1, phi2]) | |
| 183 | ||
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 184 | 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 | 185 | | aconn_fold pos f (AImplies, [phi1, phi2]) = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 186 | 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 | 187 | | 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 | 188 | | 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 | 189 | | aconn_fold _ f (_, phis) = fold (f NONE) phis | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 190 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 191 | 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 | 192 | | aconn_map pos f (AImplies, [phi1, phi2]) = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 193 | 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 | 194 | | 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 | 195 | | 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 | 196 | | 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 | 197 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 198 | fun formula_fold pos f = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 199 | let | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 200 | fun aux pos (AQuant (_, _, phi)) = aux pos phi | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 201 | | aux pos (AConn conn) = aconn_fold pos aux conn | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 202 | | aux pos (AAtom tm) = f pos tm | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 203 | in aux pos end | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 204 | |
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 205 | fun formula_map f (AQuant (q, xs, phi)) = AQuant (q, xs, formula_map f phi) | 
| 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 206 | | 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 | 207 | | 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 | 208 | |
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 209 | fun is_format_thf (THF _) = true | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 210 | | is_format_thf _ = false | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 211 | fun is_format_typed TFF = true | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 212 | | is_format_typed (THF _) = true | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 213 | | is_format_typed _ = false | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 214 | |
| 38631 
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
 blanchet parents: 
38613diff
changeset | 215 | fun string_for_kind Axiom = "axiom" | 
| 41769 
eb2e39555f98
extended ATP problem syntax to support other applications than Sledgehammer, e.g. experiments with ATPs
 blanchet parents: 
41491diff
changeset | 216 | | string_for_kind Definition = "definition" | 
| 
eb2e39555f98
extended ATP problem syntax to support other applications than Sledgehammer, e.g. experiments with ATPs
 blanchet parents: 
41491diff
changeset | 217 | | string_for_kind Lemma = "lemma" | 
| 38631 
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
 blanchet parents: 
38613diff
changeset | 218 | | string_for_kind Hypothesis = "hypothesis" | 
| 
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
 blanchet parents: 
38613diff
changeset | 219 | | string_for_kind Conjecture = "conjecture" | 
| 
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
 blanchet parents: 
38613diff
changeset | 220 | |
| 42963 | 221 | fun strip_tff_type (AFun (AType s, ty)) = strip_tff_type ty |>> cons s | 
| 222 | | strip_tff_type (AFun (AFun _, _)) = | |
| 223 | raise Fail "unexpected higher-order type in first-order format" | |
| 224 | | strip_tff_type (AType s) = ([], s) | |
| 225 | ||
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 226 | fun string_for_type (THF _) ty = | 
| 42963 | 227 | let | 
| 228 | fun aux _ (AType s) = s | |
| 229 | | aux rhs (AFun (ty1, ty2)) = | |
| 230 | aux false ty1 ^ " " ^ tptp_fun_type ^ " " ^ aux true ty2 | |
| 231 |           |> not rhs ? enclose "(" ")"
 | |
| 232 | in aux true ty end | |
| 233 | | string_for_type TFF ty = | |
| 234 | (case strip_tff_type ty of | |
| 235 | ([], s) => s | |
| 236 | | ([s'], s) => s' ^ " " ^ tptp_fun_type ^ " " ^ s | |
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 237 | | (ss, s) => | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 238 |        "(" ^ space_implode (" " ^ tptp_product_type ^ " ") ss ^ ") " ^
 | 
| 42994 
fe291ab75eb5
towards supporting non-simply-typed encodings for TFF and THF (for orthogonality and experiments)
 blanchet parents: 
42974diff
changeset | 239 | tptp_fun_type ^ " " ^ s) | 
| 42963 | 240 | | string_for_type _ _ = raise Fail "unexpected type in untyped format" | 
| 241 | ||
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 242 | fun string_for_quantifier AForall = tptp_forall | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 243 | | string_for_quantifier AExists = tptp_exists | 
| 42963 | 244 | |
| 42967 | 245 | fun string_for_connective ANot = tptp_not | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 246 | | string_for_connective AAnd = tptp_and | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 247 | | string_for_connective AOr = tptp_or | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 248 | | string_for_connective AImplies = tptp_implies | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 249 | | string_for_connective AIff = tptp_iff | 
| 42963 | 250 | |
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 251 | fun string_for_bound_var format (s, ty) = | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 252 | s ^ (if is_format_typed format then | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 253 | " " ^ tptp_has_type ^ " " ^ | 
| 42963 | 254 | string_for_type format (ty |> the_default (AType tptp_individual_type)) | 
| 255 | else | |
| 256 | "") | |
| 257 | ||
| 43986 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 258 | fun string_for_term _ (ATerm (s, [])) = s | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 259 | | string_for_term format (ATerm (s, ts)) = | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 260 | if s = tptp_empty_list then | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 261 | (* used for lists in the optional "source" field of a derivation *) | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 262 | "[" ^ commas (map (string_for_term format) ts) ^ "]" | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 263 | else if is_tptp_equal s then | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 264 |       space_implode (" " ^ tptp_equal ^ " ") (map (string_for_term format) ts)
 | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 265 |       |> is_format_thf format ? enclose "(" ")"
 | 
| 43986 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 266 | else | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 267 | (case (s = tptp_ho_forall orelse s = tptp_ho_exists, ts) of | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 268 | (true, [AAbs ((s', ty), tm)]) => | 
| 43987 
2850b7dc27a4
further worked around LEO-II parser limitation, with eta-expansion
 blanchet parents: 
43986diff
changeset | 269 | (* Use syntactic sugar "!" and "?" instead of "!!" and "??" whenever | 
| 
2850b7dc27a4
further worked around LEO-II parser limitation, with eta-expansion
 blanchet parents: 
43986diff
changeset | 270 | possible, to work around LEO-II 1.2.8 parser limitation. *) | 
| 43986 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 271 | string_for_formula format | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 272 | (AQuant (if s = tptp_ho_forall then AForall else AExists, | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 273 | [(s', SOME ty)], AAtom tm)) | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 274 | | _ => | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 275 | let val ss = map (string_for_term format) ts in | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 276 | if is_format_thf format then | 
| 43986 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 277 |              "(" ^ space_implode (" " ^ tptp_app ^ " ") (s :: ss) ^ ")"
 | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 278 | else | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 279 |              s ^ "(" ^ commas ss ^ ")"
 | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 280 | end) | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 281 | | string_for_term (format as THF _) (AAbs ((s, ty), tm)) = | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 282 | "(^[" ^ s ^ " : " ^ string_for_type format ty ^ "] : " ^ | 
| 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 283 | string_for_term format tm ^ ")" | 
| 43986 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 284 | | string_for_term _ _ = raise Fail "unexpected term in first-order format" | 
| 
85c91284ed94
use syntactic sugar whenever possible in THF problems, to work around current LEO-II parser limitation (bang bang and query query are not handled correctly)
 blanchet parents: 
43827diff
changeset | 285 | and string_for_formula format (AQuant (q, xs, phi)) = | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 286 | string_for_quantifier q ^ | 
| 42722 | 287 | "[" ^ commas (map (string_for_bound_var format) xs) ^ "] : " ^ | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 288 | string_for_formula format phi | 
| 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 289 |     |> enclose "(" ")"
 | 
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 290 | | string_for_formula format | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 291 |         (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 | 292 |     space_implode (" " ^ tptp_not_infix ^ tptp_equal ^ " ")
 | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 293 | (map (string_for_term format) ts) | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 294 |     |> is_format_thf format ? enclose "(" ")"
 | 
| 42722 | 295 | | string_for_formula format (AConn (c, [phi])) = | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 296 | string_for_connective c ^ " " ^ | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 297 |     (string_for_formula format phi |> is_format_thf format ? enclose "(" ")")
 | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 298 |     |> enclose "(" ")"
 | 
| 42722 | 299 | | string_for_formula format (AConn (c, phis)) = | 
| 42974 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 300 |     space_implode (" " ^ string_for_connective c ^ " ")
 | 
| 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 301 | (map (string_for_formula format) phis) | 
| 
347d5197896e
ensure that the argument of logical negation is enclosed in parentheses in THF mode
 blanchet parents: 
42968diff
changeset | 302 |     |> enclose "(" ")"
 | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 303 | | string_for_formula format (AAtom tm) = string_for_term format tm | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 304 | |
| 43692 | 305 | fun the_source (SOME source) = source | 
| 306 | | the_source NONE = | |
| 307 |     ATerm ("inference",
 | |
| 308 |            ATerm ("isabelle", []) :: replicate 2 (ATerm ("[]", [])))
 | |
| 42639 | 309 | |
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 310 | fun string_for_format CNF = tptp_cnf | 
| 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 311 | | string_for_format CNF_UEQ = tptp_cnf | 
| 42968 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 312 | | string_for_format FOF = tptp_fof | 
| 
74415622d293
more work on parsing LEO-II proofs and extracting uses of extensionality
 blanchet parents: 
42967diff
changeset | 313 | | string_for_format TFF = tptp_tff | 
| 44235 
85e9dad3c187
distinguish THF syntax with and without choice (Satallax vs. LEO-II)
 blanchet parents: 
43987diff
changeset | 314 | | string_for_format (THF _) = tptp_thf | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 315 | |
| 42963 | 316 | fun string_for_problem_line format (Decl (ident, sym, ty)) = | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 317 |     string_for_format format ^ "(" ^ ident ^ ", type,\n    " ^ sym ^ " : " ^
 | 
| 42963 | 318 | string_for_type format ty ^ ").\n" | 
| 42939 | 319 | | string_for_problem_line format (Formula (ident, kind, phi, source, info)) = | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 320 |     string_for_format format ^ "(" ^ ident ^ ", " ^ string_for_kind kind ^
 | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 321 |     ",\n    (" ^ string_for_formula format phi ^ ")" ^
 | 
| 42939 | 322 | (case (source, info) of | 
| 42709 
e7af132d48fe
allow each prover to specify its own formula kind for symbols occurring in the conjecture
 blanchet parents: 
42659diff
changeset | 323 | (NONE, NONE) => "" | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 324 | | (SOME tm, NONE) => ", " ^ string_for_term format tm | 
| 42709 
e7af132d48fe
allow each prover to specify its own formula kind for symbols occurring in the conjecture
 blanchet parents: 
42659diff
changeset | 325 | | (_, SOME tm) => | 
| 43692 | 326 | ", " ^ string_for_term format (the_source source) ^ | 
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 327 | ", " ^ string_for_term format tm) ^ ").\n" | 
| 43224 | 328 | fun tptp_lines_for_atp_problem format problem = | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 329 | "% This file was generated by Isabelle (most likely Sledgehammer)\n\ | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 330 | \% " ^ timestamp () ^ "\n" :: | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 331 | maps (fn (_, []) => [] | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 332 | | (heading, lines) => | 
| 41491 | 333 |            "\n% " ^ heading ^ " (" ^ string_of_int (length lines) ^ ")\n" ::
 | 
| 42709 
e7af132d48fe
allow each prover to specify its own formula kind for symbols occurring in the conjecture
 blanchet parents: 
42659diff
changeset | 334 | map (string_for_problem_line format) lines) | 
| 38631 
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
 blanchet parents: 
38613diff
changeset | 335 | problem | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 336 | |
| 42939 | 337 | |
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 338 | (** CNF (Metis) and CNF UEQ (Waldmeister) **) | 
| 42939 | 339 | |
| 340 | fun is_problem_line_negated (Formula (_, _, AConn (ANot, _), _, _)) = true | |
| 341 | | is_problem_line_negated _ = false | |
| 342 | ||
| 43193 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 343 | fun is_problem_line_cnf_ueq (Formula (_, _, AAtom (ATerm ((s, _), _)), _, _)) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 344 | is_tptp_equal s | 
| 42939 | 345 | | is_problem_line_cnf_ueq _ = false | 
| 346 | ||
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 347 | fun open_conjecture_term (ATerm ((s, s'), tms)) = | 
| 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 | 348 | ATerm (if is_tptp_variable s then (s |> Name.desymbolize false, s') | 
| 
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 | 349 | else (s, s'), tms |> map open_conjecture_term) | 
| 
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 | 350 | | open_conjecture_term _ = raise Fail "unexpected higher-order term" | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 351 | fun open_formula conj = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 352 | let | 
| 43193 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 353 | (* 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 | 354 | 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 | 355 | 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 | 356 | | 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 | 357 | | 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 | 358 | | opn pos (AConn (c, [phi1, phi2])) = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 359 | let val (pos1, pos2) = polarities_of_conn pos c in | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 360 | AConn (c, [opn pos1 phi1, opn pos2 phi2]) | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 361 | end | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 362 | | 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 | 363 | | opn _ phi = phi | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 364 | in opn (SOME (not conj)) end | 
| 42944 
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
 blanchet parents: 
42942diff
changeset | 365 | 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 | 366 | 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 | 367 | | open_formula_line line = line | 
| 42939 | 368 | |
| 369 | fun negate_conjecture_line (Formula (ident, Conjecture, phi, source, info)) = | |
| 42942 | 370 | Formula (ident, Hypothesis, mk_anot phi, source, info) | 
| 42939 | 371 | | negate_conjecture_line line = line | 
| 372 | ||
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 373 | exception CLAUSIFY of unit | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 374 | |
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 375 | (* This "clausification" only expands syntactic sugar, such as "phi => psi" to | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 376 | "~ 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 | 377 | attempt to distribute conjunctions over disjunctions. *) | 
| 43193 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 378 | 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 | 379 | | 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 | 380 | | clausify_formula true (AConn (AOr, [phi1, phi2])) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 381 | (phi1, phi2) |> pairself (clausify_formula true) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 382 | |> uncurry (map_product (mk_aconn AOr)) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 383 | | clausify_formula false (AConn (AAnd, [phi1, phi2])) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 384 | (phi1, phi2) |> pairself (clausify_formula false) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 385 | |> uncurry (map_product (mk_aconn AOr)) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 386 | | clausify_formula true (AConn (AImplies, [phi1, phi2])) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 387 | 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 | 388 | | clausify_formula true (AConn (AIff, phis)) = | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 389 | clausify_formula true (AConn (AImplies, phis)) @ | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 390 | clausify_formula true (AConn (AImplies, rev phis)) | 
| 
e11bd628f1a5
improved ATP clausifier so it can deal with "x => (y <=> z)"
 blanchet parents: 
43163diff
changeset | 391 | | clausify_formula _ _ = raise CLAUSIFY () | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 392 | |
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 393 | fun clausify_formula_line (Formula (ident, kind, phi, source, info)) = | 
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 394 | let | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 395 | val (n, phis) = phi |> try (clausify_formula true) |> these |> `length | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 396 | in | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 397 | 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 | 398 | 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 | 399 | info)) | 
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 400 | phis (1 upto n) | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 401 | end | 
| 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 402 | | clausify_formula_line _ = [] | 
| 43098 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 403 | |
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 404 | fun ensure_cnf_problem_line line = | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 405 | line |> open_formula_line |> negate_conjecture_line |> clausify_formula_line | 
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 406 | |
| 
e88e974c4846
proper handling of type variable classes in new Metis
 blanchet parents: 
43092diff
changeset | 407 | fun ensure_cnf_problem problem = | 
| 43126 
a7db0afd5200
clausify "<=>" (needed for some type information)
 blanchet parents: 
43098diff
changeset | 408 | problem |> map (apsnd (maps ensure_cnf_problem_line)) | 
| 43092 
93ec303e1917
more work on new metis that exploits the powerful new type encodings
 blanchet parents: 
43085diff
changeset | 409 | |
| 42962 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 410 | fun filter_cnf_ueq_problem problem = | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 411 | problem | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 412 | |> map (apsnd (map open_formula_line | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 413 | #> filter is_problem_line_cnf_ueq | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 414 | #> map negate_conjecture_line)) | 
| 
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
 blanchet parents: 
42961diff
changeset | 415 | |> (fn problem => | 
| 42939 | 416 | let | 
| 43824 
0234156d3fbe
don't generate Waldmeister problems with only a conjecture, since it makes it crash sometimes
 blanchet parents: 
43692diff
changeset | 417 | val lines = problem |> maps snd | 
| 
0234156d3fbe
don't generate Waldmeister problems with only a conjecture, since it makes it crash sometimes
 blanchet parents: 
43692diff
changeset | 418 | val conjs = lines |> filter is_problem_line_negated | 
| 
0234156d3fbe
don't generate Waldmeister problems with only a conjecture, since it makes it crash sometimes
 blanchet parents: 
43692diff
changeset | 419 | 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 | 420 | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 421 | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 422 | (** Symbol declarations **) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 423 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 424 | (* TFF allows implicit declarations of types, function symbols, and predicate | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 425 | symbols (with "$i" as the type of individuals), but some provers (e.g., | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 426 | SNARK) require explicit declarations. The situation is similar for THF. *) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 427 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 428 | val atype_of_types = AType (`I tptp_type_of_types) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 429 | val bool_atype = AType (`I tptp_bool_type) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 430 | val individual_atype = AType (`I tptp_individual_type) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 431 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 432 | fun default_type pred_sym = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 433 | let | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 434 | fun typ 0 = if pred_sym then bool_atype else individual_atype | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 435 | | typ ary = AFun (individual_atype, typ (ary - 1)) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 436 | in typ end | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 437 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 438 | fun add_declared_syms_in_problem_line (Decl (_, sym, _)) = insert (op =) sym | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 439 | | add_declared_syms_in_problem_line _ = I | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 440 | fun declared_syms_in_problem problem = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 441 | fold (fold add_declared_syms_in_problem_line o snd) problem [] | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 442 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 443 | fun undeclared_syms_in_problem declared problem = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 444 | let | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 445 | fun do_sym name ty = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 446 | if member (op =) declared name then I else AList.default (op =) (name, ty) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 447 | fun do_type (AFun (ty1, ty2)) = fold do_type [ty1, ty2] | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 448 | | do_type (AType name) = do_sym name (K atype_of_types) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 449 | fun do_term pred_sym (ATerm (name as (s, _), tms)) = | 
| 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 | 450 | is_tptp_user_symbol s | 
| 
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 | 451 | ? do_sym name (fn _ => default_type pred_sym (length tms)) | 
| 
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 | 452 | #> fold (do_term false) tms | 
| 
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 | 453 | | do_term _ (AAbs ((_, ty), tm)) = do_type ty #> do_term false tm | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 454 | fun do_formula (AQuant (_, xs, phi)) = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 455 | fold do_type (map_filter snd xs) #> do_formula phi | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 456 | | do_formula (AConn (_, phis)) = fold do_formula phis | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 457 | | do_formula (AAtom tm) = do_term true tm | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 458 | fun do_problem_line (Decl (_, _, ty)) = do_type ty | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 459 | | do_problem_line (Formula (_, _, phi, _, _)) = do_formula phi | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 460 | in | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 461 | fold (fold do_problem_line o snd) problem [] | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 462 | |> filter_out (is_built_in_tptp_symbol o fst o fst) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 463 | end | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 464 | |
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 465 | fun declare_undeclared_syms_in_atp_problem prefix heading problem = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 466 | let | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 467 | fun decl_line (x as (s, _), ty) = Decl (prefix ^ s, x, ty ()) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 468 | val declared = problem |> declared_syms_in_problem | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 469 | val decls = | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 470 | problem |> undeclared_syms_in_problem declared | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 471 | |> sort_wrt (fst o fst) | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 472 | |> map decl_line | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 473 | in (heading, decls) :: problem end | 
| 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 474 | |
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 475 | (** Nice names **) | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 476 | |
| 37624 | 477 | fun empty_name_pool readable_names = | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 478 | if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE | 
| 37624 | 479 | |
| 480 | fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs | |
| 481 | fun pool_map f xs = | |
| 482 | pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs [] | |
| 483 | ||
| 42227 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 484 | val no_qualifiers = | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 485 | let | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 486 | fun skip [] = [] | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 487 | | skip (#"." :: cs) = skip cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 488 | | 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 | 489 | and keep [] = [] | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 490 | | keep (#"." :: cs) = skip cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 491 | | keep (c :: cs) = c :: keep cs | 
| 
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
 blanchet parents: 
41769diff
changeset | 492 | 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 | 493 | |
| 42761 
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
 blanchet parents: 
42752diff
changeset | 494 | (* 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 | 495 | 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 | 496 | |
| 43000 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 497 | (* "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 | 498 | 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 | 499 | 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 | 500 | is still necessary). *) | 
| 
bd424c3dde46
cleaner handling of equality and proxies (esp. for THF)
 blanchet parents: 
42998diff
changeset | 501 | val reserved_nice_names = [tptp_old_equal, "op", "eq"] | 
| 42939 | 502 | |
| 37624 | 503 | fun readable_name full_name s = | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 504 | if s = full_name then | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 505 | s | 
| 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 506 | else | 
| 42567 
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
 blanchet parents: 
42543diff
changeset | 507 | s |> no_qualifiers | 
| 44407 | 508 | |> perhaps (try (unprefix "'")) | 
| 42567 
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
 blanchet parents: 
42543diff
changeset | 509 | |> Name.desymbolize (Char.isUpper (String.sub (full_name, 0))) | 
| 42583 
84b134118616
avoid trailing digits for SNARK (type) names -- grr...
 blanchet parents: 
42577diff
changeset | 510 | |> (fn s => | 
| 42659 | 511 | if size s > max_readable_name_size then | 
| 512 | String.substring (s, 0, max_readable_name_size div 2 - 4) ^ | |
| 43827 
62d64709af3b
added option to control which lambda translation to use (for experiments)
 blanchet parents: 
43824diff
changeset | 513 | string_of_int (hash_string full_name) ^ | 
| 42659 | 514 | String.extract (s, size s - max_readable_name_size div 2 + 4, | 
| 515 | NONE) | |
| 42583 
84b134118616
avoid trailing digits for SNARK (type) names -- grr...
 blanchet parents: 
42577diff
changeset | 516 | else | 
| 
84b134118616
avoid trailing digits for SNARK (type) names -- grr...
 blanchet parents: 
42577diff
changeset | 517 | s) | 
| 42567 
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
 blanchet parents: 
42543diff
changeset | 518 | |> (fn s => if member (op =) reserved_nice_names s then full_name else s) | 
| 37624 | 519 | |
| 520 | fun nice_name (full_name, _) NONE = (full_name, NONE) | |
| 521 | | nice_name (full_name, desired_name) (SOME the_pool) = | |
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 522 | if is_built_in_tptp_symbol full_name then | 
| 39384 | 523 | (full_name, SOME the_pool) | 
| 524 | else case Symtab.lookup (fst the_pool) full_name of | |
| 37624 | 525 | SOME nice_name => (nice_name, SOME the_pool) | 
| 526 | | NONE => | |
| 527 | let | |
| 528 | val nice_prefix = readable_name full_name desired_name | |
| 529 | fun add j = | |
| 530 | let | |
| 42644 | 531 | val nice_name = | 
| 44407 | 532 | nice_prefix ^ (if j = 0 then "" else string_of_int j) | 
| 37624 | 533 | in | 
| 534 | case Symtab.lookup (snd the_pool) nice_name of | |
| 535 | SOME full_name' => | |
| 536 | if full_name = full_name' then (nice_name, the_pool) | |
| 537 | else add (j + 1) | |
| 538 | | NONE => | |
| 539 | (nice_name, | |
| 540 | (Symtab.update_new (full_name, nice_name) (fst the_pool), | |
| 541 | Symtab.update_new (nice_name, full_name) (snd the_pool))) | |
| 542 | end | |
| 543 | in add 0 |> apsnd SOME end | |
| 544 | ||
| 42963 | 545 | fun nice_type (AType name) = nice_name name #>> AType | 
| 546 | | nice_type (AFun (ty1, ty2)) = nice_type ty1 ##>> nice_type ty2 #>> AFun | |
| 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 | 547 | fun nice_term (ATerm (name, ts)) = | 
| 
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 | 548 | nice_name name ##>> pool_map nice_term ts #>> ATerm | 
| 
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 | 549 | | nice_term (AAbs ((name, ty), tm)) = | 
| 
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 | 550 | nice_name name ##>> nice_type ty ##>> nice_term tm #>> AAbs | 
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 551 | fun nice_formula (AQuant (q, xs, phi)) = | 
| 42526 | 552 | pool_map nice_name (map fst xs) | 
| 553 | ##>> pool_map (fn NONE => pair NONE | |
| 42963 | 554 | | SOME ty => nice_type ty #>> SOME) (map snd xs) | 
| 42526 | 555 | ##>> nice_formula phi | 
| 556 | #>> (fn ((ss, ts), phi) => AQuant (q, ss ~~ ts, phi)) | |
| 37961 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 557 | | nice_formula (AConn (c, phis)) = | 
| 
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
 blanchet parents: 
37931diff
changeset | 558 | pool_map nice_formula phis #>> curry AConn c | 
| 38034 | 559 | | nice_formula (AAtom tm) = nice_term tm #>> AAtom | 
| 42963 | 560 | fun nice_problem_line (Decl (ident, sym, ty)) = | 
| 42998 
1c80902d0456
fully support all type system encodings in typed formats (TFF, THF)
 blanchet parents: 
42994diff
changeset | 561 | nice_name sym ##>> nice_type ty #>> (fn (sym, ty) => Decl (ident, sym, ty)) | 
| 42939 | 562 | | nice_problem_line (Formula (ident, kind, phi, source, info)) = | 
| 563 | nice_formula phi #>> (fn phi => Formula (ident, kind, phi, source, info)) | |
| 37931 | 564 | fun nice_problem problem = | 
| 37643 
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
 blanchet parents: 
37642diff
changeset | 565 | pool_map (fn (heading, lines) => | 
| 37931 | 566 | pool_map nice_problem_line lines #>> pair heading) problem | 
| 39452 | 567 | fun nice_atp_problem readable_names problem = | 
| 38017 
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
 blanchet parents: 
38014diff
changeset | 568 | nice_problem problem (empty_name_pool readable_names) | 
| 37509 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 569 | |
| 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
 blanchet parents: diff
changeset | 570 | end; |