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