author | blanchet |
Tue, 24 May 2011 00:01:33 +0200 | |
changeset 42962 | 3b50fdeb6cfc |
parent 42961 | f30ae82cb62e |
child 42963 | 5725deb11ae7 |
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 |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
18 |
datatype format = CNF_UEQ | FOF | TFF | THF |
42525
7a506b0b644f
distinguish FOF and TFF (typed first-order) in ATP abstract syntax tree
blanchet
parents:
42449
diff
changeset
|
19 |
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
|
20 |
datatype 'a problem_line = |
42543
f9d402d144d4
declare TFF types so that SNARK can be used with types
blanchet
parents:
42538
diff
changeset
|
21 |
Decl of string * 'a * 'a list * 'a | |
42577
78414ec6fa4e
made the format (TFF or FOF) of the TPTP problem a global argument of the problem again and have the ATPs report which formats they support
blanchet
parents:
42567
diff
changeset
|
22 |
Formula of string * formula_kind * ('a, 'a, '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
|
23 |
* string fo_term option * string fo_term option |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
24 |
type 'a problem = (string * 'a problem_line list) list |
37992 | 25 |
|
42939 | 26 |
(* official TPTP syntax *) |
42752 | 27 |
val tptp_special_prefix : string |
28 |
val tptp_false : string |
|
29 |
val tptp_true : string |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
30 |
val tptp_type_of_types : string |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
31 |
val tptp_bool_type : string |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
32 |
val tptp_individual_type : string |
42939 | 33 |
val is_atp_variable : string -> bool |
42942 | 34 |
val mk_anot : ('a, 'b, 'c) formula -> ('a, 'b, 'c) formula |
35 |
val mk_aconn : |
|
36 |
connective -> ('a, 'b, 'c) formula -> ('a, 'b, 'c) formula |
|
37 |
-> ('a, 'b, 'c) formula |
|
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42942
diff
changeset
|
38 |
val formula_map : ('c -> 'd) -> ('a, 'b, 'c) formula -> ('a, 'b, 'd) formula |
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
39 |
val timestamp : unit -> string |
42567
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
40 |
val hashw : word * word -> word |
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
41 |
val hashw_string : string * word -> word |
42709
e7af132d48fe
allow each prover to specify its own formula kind for symbols occurring in the conjecture
blanchet
parents:
42659
diff
changeset
|
42 |
val tptp_strings_for_atp_problem : format -> string problem -> string list |
42939 | 43 |
val filter_cnf_ueq_problem : |
44 |
(string * string) problem -> (string * string) problem |
|
39452 | 45 |
val nice_atp_problem : |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
46 |
bool -> ('a * (string * string) problem_line list) list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
47 |
-> ('a * string problem_line list) list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
48 |
* (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
|
49 |
end; |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
50 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
51 |
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
|
52 |
struct |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
53 |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
54 |
(** ATP problem **) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
55 |
|
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
56 |
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
|
57 |
datatype quantifier = AForall | AExists |
37992 | 58 |
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
|
59 |
datatype ('a, 'b, 'c) formula = |
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
blanchet
parents:
42530
diff
changeset
|
60 |
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
|
61 |
AConn of connective * ('a, 'b, 'c) formula list | |
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
blanchet
parents:
42530
diff
changeset
|
62 |
AAtom of 'c |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
63 |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
64 |
datatype format = CNF_UEQ | FOF | TFF | THF |
42525
7a506b0b644f
distinguish FOF and TFF (typed first-order) in ATP abstract syntax tree
blanchet
parents:
42449
diff
changeset
|
65 |
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
|
66 |
datatype 'a problem_line = |
42543
f9d402d144d4
declare TFF types so that SNARK can be used with types
blanchet
parents:
42538
diff
changeset
|
67 |
Decl of string * 'a * 'a list * 'a | |
42577
78414ec6fa4e
made the format (TFF or FOF) of the TPTP problem a global argument of the problem again and have the ATPs report which formats they support
blanchet
parents:
42567
diff
changeset
|
68 |
Formula of string * formula_kind * ('a, 'a, '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
|
69 |
* 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
|
70 |
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
|
71 |
|
42722 | 72 |
(* official TPTP syntax *) |
42752 | 73 |
val tptp_special_prefix = "$" |
74 |
val tptp_false = "$false" |
|
75 |
val tptp_true = "$true" |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
76 |
val tptp_type_of_types = "$tType" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
77 |
val tptp_bool_type = "$o" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
78 |
val tptp_individual_type = "$i" |
42722 | 79 |
|
42939 | 80 |
fun is_atp_variable s = Char.isUpper (String.sub (s, 0)) |
81 |
||
42942 | 82 |
fun mk_anot (AConn (ANot, [phi])) = phi |
83 |
| mk_anot phi = AConn (ANot, [phi]) |
|
84 |
fun mk_aconn c phi1 phi2 = AConn (c, [phi1, phi2]) |
|
85 |
||
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42942
diff
changeset
|
86 |
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
|
87 |
| 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
|
88 |
| 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
|
89 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
90 |
val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" o Date.fromTimeLocal o Time.now |
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
91 |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
92 |
(* This hash function is recommended in "Compilers: Principles, Techniques, and |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
93 |
Tools" by Aho, Sethi, and Ullman. The "hashpjw" function, which they |
42567
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
94 |
particularly recommend, triggers a bug in versions of Poly/ML up to 4.2.0. *) |
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
95 |
fun hashw (u, w) = Word.+ (u, Word.* (0w65599, w)) |
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
96 |
fun hashw_char (c, w) = hashw (Word.fromInt (Char.ord c), w) |
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
97 |
fun hashw_string (s : string, w) = CharVector.foldl hashw_char w s |
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
98 |
|
38631
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
99 |
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
|
100 |
| 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
|
101 |
| string_for_kind Lemma = "lemma" |
38631
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
102 |
| string_for_kind Hypothesis = "hypothesis" |
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
103 |
| string_for_kind Conjecture = "conjecture" |
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
104 |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
105 |
fun string_for_term _ (ATerm (s, [])) = s |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
106 |
| string_for_term format (ATerm ("equal", ts)) = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
107 |
space_implode " = " (map (string_for_term format) ts) |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
108 |
|> format = THF ? enclose "(" ")" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
109 |
| string_for_term format (ATerm ("[]", ts)) = |
41769
eb2e39555f98
extended ATP problem syntax to support other applications than Sledgehammer, e.g. experiments with ATPs
blanchet
parents:
41491
diff
changeset
|
110 |
(* used for lists in the optional "source" field of a derivation *) |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
111 |
"[" ^ commas (map (string_for_term format) ts) ^ "]" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
112 |
| string_for_term format (ATerm (s, ts)) = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
113 |
let val ss = map (string_for_term format) ts in |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
114 |
if format = THF then "(" ^ space_implode " @ " (s :: ss) ^ ")" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
115 |
else s ^ "(" ^ commas ss ^ ")" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
116 |
end |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
117 |
fun string_for_quantifier AForall = "!" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
118 |
| string_for_quantifier AExists = "?" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
119 |
fun string_for_connective ANot = "~" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
120 |
| string_for_connective AAnd = "&" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
121 |
| string_for_connective AOr = "|" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
122 |
| string_for_connective AImplies = "=>" |
37992 | 123 |
| string_for_connective AIf = "<=" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
124 |
| string_for_connective AIff = "<=>" |
37992 | 125 |
| string_for_connective ANotIff = "<~>" |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
126 |
fun string_for_bound_var format (s, ty) = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
127 |
s ^ (if format = TFF orelse format = THF then |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
128 |
" : " ^ (ty |> the_default tptp_individual_type) |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
129 |
else |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
130 |
"") |
42722 | 131 |
fun string_for_formula format (AQuant (q, xs, phi)) = |
42526 | 132 |
"(" ^ string_for_quantifier q ^ |
42722 | 133 |
"[" ^ commas (map (string_for_bound_var format) xs) ^ "] : " ^ |
134 |
string_for_formula format phi ^ ")" |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
135 |
| string_for_formula format (AConn (ANot, [AAtom (ATerm ("equal", ts))])) = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
136 |
space_implode " != " (map (string_for_term format) ts) |
42722 | 137 |
| string_for_formula format (AConn (c, [phi])) = |
138 |
"(" ^ string_for_connective c ^ " " ^ string_for_formula format phi ^ ")" |
|
139 |
| string_for_formula format (AConn (c, phis)) = |
|
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
140 |
"(" ^ space_implode (" " ^ string_for_connective c ^ " ") |
42722 | 141 |
(map (string_for_formula format) phis) ^ ")" |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
142 |
| 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
|
143 |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
144 |
fun string_for_symbol_type THF arg_tys res_ty = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
145 |
space_implode " > " (arg_tys @ [res_ty]) |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
146 |
| string_for_symbol_type _ [] res_ty = res_ty |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
147 |
| string_for_symbol_type _ [arg_ty] res_ty = arg_ty ^ " > " ^ res_ty |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
148 |
| string_for_symbol_type format arg_tys res_ty = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
149 |
string_for_symbol_type format ["(" ^ space_implode " * " arg_tys ^ ")"] |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
150 |
res_ty |
42528 | 151 |
|
42639 | 152 |
val default_source = |
153 |
ATerm ("inference", ATerm ("isabelle", []) :: replicate 2 (ATerm ("[]", []))) |
|
154 |
||
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
155 |
fun string_for_format CNF_UEQ = "cnf" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
156 |
| string_for_format FOF = "fof" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
157 |
| string_for_format TFF = "tff" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
158 |
| string_for_format THF = "thf" |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
159 |
|
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
160 |
fun string_for_problem_line format (Decl (ident, sym, arg_tys, res_ty)) = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
161 |
string_for_format format ^ "(" ^ ident ^ ", type,\n " ^ sym ^ " : " ^ |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
162 |
string_for_symbol_type format arg_tys res_ty ^ ").\n" |
42939 | 163 |
| 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
|
164 |
string_for_format format ^ "(" ^ ident ^ ", " ^ string_for_kind kind ^ |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
165 |
",\n (" ^ string_for_formula format phi ^ ")" ^ |
42939 | 166 |
(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
|
167 |
(NONE, NONE) => "" |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
168 |
| (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
|
169 |
| (_, SOME tm) => |
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
170 |
", " ^ string_for_term format (source |> the_default default_source) ^ |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
171 |
", " ^ 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
|
172 |
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
|
173 |
"% 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
|
174 |
\% " ^ timestamp () ^ "\n" :: |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
175 |
maps (fn (_, []) => [] |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
176 |
| (heading, lines) => |
41491 | 177 |
"\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
|
178 |
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
|
179 |
problem |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
180 |
|
42939 | 181 |
|
182 |
(** CNF UEQ (Waldmeister) **) |
|
183 |
||
184 |
exception LOST_CONJECTURE of unit |
|
185 |
||
186 |
fun is_problem_line_negated (Formula (_, _, AConn (ANot, _), _, _)) = true |
|
187 |
| is_problem_line_negated _ = false |
|
188 |
||
189 |
fun is_problem_line_cnf_ueq |
|
190 |
(Formula (_, _, AAtom (ATerm (("equal", _), _)), _, _)) = true |
|
191 |
| is_problem_line_cnf_ueq _ = false |
|
192 |
||
42944
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42942
diff
changeset
|
193 |
fun open_conjecture_term (ATerm ((s, s'), tms)) = |
42961 | 194 |
ATerm (if is_atp_variable s then (s |> Name.desymbolize false, s') |
195 |
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
|
196 |
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
|
197 |
| 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
|
198 |
| open_formula _ phi = phi |
9e620869a576
improved Waldmeister support -- even run it by default on unit equational goals
blanchet
parents:
42942
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
| open_formula_line line = line |
42939 | 202 |
|
203 |
fun negate_conjecture_line (Formula (ident, Conjecture, phi, source, info)) = |
|
42942 | 204 |
Formula (ident, Hypothesis, mk_anot phi, source, info) |
42939 | 205 |
| negate_conjecture_line line = line |
206 |
||
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
207 |
fun filter_cnf_ueq_problem problem = |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
208 |
problem |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
209 |
|> map (apsnd (map open_formula_line |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
210 |
#> filter is_problem_line_cnf_ueq |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
211 |
#> map negate_conjecture_line)) |
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
212 |
|> (fn problem => |
42939 | 213 |
let |
214 |
val conjs = problem |> maps snd |> filter is_problem_line_negated |
|
215 |
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
|
216 |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
217 |
|
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
218 |
(** Nice names **) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
219 |
|
37624 | 220 |
fun empty_name_pool readable_names = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
221 |
if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
37624 | 222 |
|
223 |
fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs |
|
224 |
fun pool_map f xs = |
|
225 |
pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs [] |
|
226 |
||
42227
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
227 |
val no_qualifiers = |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
228 |
let |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
229 |
fun skip [] = [] |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
230 |
| skip (#"." :: cs) = skip cs |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
231 |
| 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
|
232 |
and keep [] = [] |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
233 |
| keep (#"." :: cs) = skip cs |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
234 |
| 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
|
235 |
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
|
236 |
|
42761
8ea9c6fa8b53
fixed several bugs in Isar proof reconstruction, in particular w.r.t. mangled types and hAPP
blanchet
parents:
42752
diff
changeset
|
237 |
(* 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
|
238 |
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
|
239 |
|
39109 | 240 |
(* "op" is also reserved, to avoid the unreadable "op_1", "op_2", etc., in the |
241 |
problem files. "equal" is reserved by some ATPs. "eq" is reserved to ensure |
|
242 |
that "HOL.eq" is correctly mapped to equality. *) |
|
243 |
val reserved_nice_names = ["op", "equal", "eq"] |
|
42939 | 244 |
|
37624 | 245 |
fun readable_name full_name s = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
246 |
if s = full_name then |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
247 |
s |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
248 |
else |
42567
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
249 |
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
|
250 |
|> Name.desymbolize (Char.isUpper (String.sub (full_name, 0))) |
42583
84b134118616
avoid trailing digits for SNARK (type) names -- grr...
blanchet
parents:
42577
diff
changeset
|
251 |
|> (fn s => |
42659 | 252 |
if size s > max_readable_name_size then |
253 |
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
|
254 |
Word.toString (hashw_string (full_name, 0w0)) ^ |
42659 | 255 |
String.extract (s, size s - max_readable_name_size div 2 + 4, |
256 |
NONE) |
|
42583
84b134118616
avoid trailing digits for SNARK (type) names -- grr...
blanchet
parents:
42577
diff
changeset
|
257 |
else |
84b134118616
avoid trailing digits for SNARK (type) names -- grr...
blanchet
parents:
42577
diff
changeset
|
258 |
s) |
42567
d012947edd36
shorten readable names -- they can get really long with monomorphization, which actually slows down the ATPs
blanchet
parents:
42543
diff
changeset
|
259 |
|> (fn s => if member (op =) reserved_nice_names s then full_name else s) |
37624 | 260 |
|
261 |
fun nice_name (full_name, _) NONE = (full_name, NONE) |
|
262 |
| nice_name (full_name, desired_name) (SOME the_pool) = |
|
42962
3b50fdeb6cfc
started adding support for THF output (but no lambdas)
blanchet
parents:
42961
diff
changeset
|
263 |
if String.isPrefix tptp_special_prefix full_name then |
39384 | 264 |
(full_name, SOME the_pool) |
265 |
else case Symtab.lookup (fst the_pool) full_name of |
|
37624 | 266 |
SOME nice_name => (nice_name, SOME the_pool) |
267 |
| NONE => |
|
268 |
let |
|
269 |
val nice_prefix = readable_name full_name desired_name |
|
270 |
fun add j = |
|
271 |
let |
|
42644 | 272 |
val nice_name = |
42942 | 273 |
nice_prefix ^ (if j = 0 then "" else "_" ^ string_of_int j) |
37624 | 274 |
in |
275 |
case Symtab.lookup (snd the_pool) nice_name of |
|
276 |
SOME full_name' => |
|
277 |
if full_name = full_name' then (nice_name, the_pool) |
|
278 |
else add (j + 1) |
|
279 |
| NONE => |
|
280 |
(nice_name, |
|
281 |
(Symtab.update_new (full_name, nice_name) (fst the_pool), |
|
282 |
Symtab.update_new (nice_name, full_name) (snd the_pool))) |
|
283 |
end |
|
284 |
in add 0 |> apsnd SOME end |
|
285 |
||
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
286 |
fun nice_term (ATerm (name, ts)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
287 |
nice_name name ##>> pool_map nice_term ts #>> ATerm |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
288 |
fun nice_formula (AQuant (q, xs, phi)) = |
42526 | 289 |
pool_map nice_name (map fst xs) |
290 |
##>> pool_map (fn NONE => pair NONE |
|
42531
a462dbaa584f
added more rudimentary type support to Sledgehammer's ATP encoding
blanchet
parents:
42530
diff
changeset
|
291 |
| SOME ty => nice_name ty #>> SOME) (map snd xs) |
42526 | 292 |
##>> nice_formula phi |
293 |
#>> (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
|
294 |
| nice_formula (AConn (c, phis)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
295 |
pool_map nice_formula phis #>> curry AConn c |
38034 | 296 |
| nice_formula (AAtom tm) = nice_term tm #>> AAtom |
42543
f9d402d144d4
declare TFF types so that SNARK can be used with types
blanchet
parents:
42538
diff
changeset
|
297 |
fun nice_problem_line (Decl (ident, sym, arg_tys, res_ty)) = |
42528 | 298 |
nice_name sym |
299 |
##>> pool_map nice_name arg_tys |
|
300 |
##>> nice_name res_ty |
|
42543
f9d402d144d4
declare TFF types so that SNARK can be used with types
blanchet
parents:
42538
diff
changeset
|
301 |
#>> (fn ((sym, arg_tys), res_ty) => Decl (ident, sym, arg_tys, res_ty)) |
42939 | 302 |
| nice_problem_line (Formula (ident, kind, phi, source, info)) = |
303 |
nice_formula phi #>> (fn phi => Formula (ident, kind, phi, source, info)) |
|
37931 | 304 |
fun nice_problem problem = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
305 |
pool_map (fn (heading, lines) => |
37931 | 306 |
pool_map nice_problem_line lines #>> pair heading) problem |
39452 | 307 |
fun nice_atp_problem readable_names problem = |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
308 |
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
|
309 |
|
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
310 |
end; |