author | blanchet |
Tue, 27 Jul 2010 17:43:11 +0200 | |
changeset 38019 | e207a64e1e0b |
parent 38018 | ee6c11ae8077 |
child 38024 | e4a95eb5530e |
permissions | -rw-r--r-- |
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
1 |
(* Title: HOL/Tools/ATP_Manager/atp_problem.ML |
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
2 |
Author: Jia Meng, NICTA |
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 |
|
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
5 |
TPTP syntax. |
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 |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
10 |
type kind = Metis_Clauses.kind |
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
11 |
|
37992 | 12 |
datatype 'a fo_term = ATerm of 'a * 'a fo_term list |
13 |
datatype quantifier = AForall | AExists |
|
14 |
datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff |
|
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
15 |
datatype ('a, 'b) formula = |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
16 |
AQuant of quantifier * 'a list * ('a, 'b) formula | |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
17 |
AConn of connective * ('a, 'b) formula list | |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
18 |
APred of 'b |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
19 |
|
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
20 |
datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
21 |
type 'a problem = (string * 'a problem_line list) list |
37992 | 22 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
23 |
val timestamp : unit -> string |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
24 |
val is_tptp_variable : string -> bool |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
25 |
val strings_for_tptp_problem : |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
26 |
(string * string problem_line list) list -> string list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
27 |
val nice_tptp_problem : |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
28 |
bool -> ('a * (string * string) problem_line list) list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
29 |
-> ('a * string problem_line list) list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
30 |
* (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
|
31 |
end; |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
32 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
33 |
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
|
34 |
struct |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
35 |
|
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
36 |
open Sledgehammer_Util |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
37 |
|
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
38 |
type kind = Metis_Clauses.kind |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
39 |
|
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
40 |
(** ATP problem **) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
41 |
|
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
42 |
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
|
43 |
datatype quantifier = AForall | AExists |
37992 | 44 |
datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
45 |
datatype ('a, 'b) formula = |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
46 |
AQuant of quantifier * 'a list * ('a, 'b) formula | |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
47 |
AConn of connective * ('a, 'b) formula list | |
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
48 |
APred of 'b |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
49 |
|
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
50 |
datatype 'a problem_line = Fof of string * kind * ('a, 'a fo_term) formula |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
51 |
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
|
52 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
53 |
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
|
54 |
|
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
55 |
fun string_for_term (ATerm (s, [])) = s |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
56 |
| string_for_term (ATerm (s, ts)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
57 |
if s = "equal" then space_implode " = " (map string_for_term ts) |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
58 |
else s ^ "(" ^ commas (map string_for_term ts) ^ ")" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
59 |
fun string_for_quantifier AForall = "!" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
60 |
| string_for_quantifier AExists = "?" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
61 |
fun string_for_connective ANot = "~" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
62 |
| string_for_connective AAnd = "&" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
63 |
| string_for_connective AOr = "|" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
64 |
| string_for_connective AImplies = "=>" |
37992 | 65 |
| string_for_connective AIf = "<=" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
66 |
| string_for_connective AIff = "<=>" |
37992 | 67 |
| string_for_connective ANotIff = "<~>" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
68 |
fun string_for_formula (AQuant (q, xs, phi)) = |
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
69 |
string_for_quantifier q ^ "[" ^ commas xs ^ "] : " ^ |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
70 |
string_for_formula phi |
38005
b6555e9c5de4
prevent schematic variable clash in combinator-introduction code, when invoked from Sledgehammer (another consequence of the CNF -> FOF transition)
blanchet
parents:
38004
diff
changeset
|
71 |
| string_for_formula (AConn (ANot, [APred (ATerm ("equal", ts))])) = |
b6555e9c5de4
prevent schematic variable clash in combinator-introduction code, when invoked from Sledgehammer (another consequence of the CNF -> FOF transition)
blanchet
parents:
38004
diff
changeset
|
72 |
space_implode " != " (map string_for_term ts) |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
73 |
| string_for_formula (AConn (c, [phi])) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
74 |
string_for_connective c ^ " " ^ string_for_formula phi |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
75 |
| string_for_formula (AConn (c, phis)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
76 |
"(" ^ space_implode (" " ^ string_for_connective c ^ " ") |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
77 |
(map string_for_formula phis) ^ ")" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
78 |
| string_for_formula (APred tm) = string_for_term tm |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
79 |
|
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
80 |
fun string_for_problem_line (Fof (ident, kind, phi)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
81 |
"fof(" ^ ident ^ ", " ^ |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
82 |
(case kind of Axiom => "axiom" | Conjecture => "conjecture") ^ ",\n" ^ |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
83 |
" (" ^ string_for_formula phi ^ ")).\n" |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
84 |
fun strings_for_tptp_problem problem = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
85 |
"% 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
|
86 |
\% " ^ timestamp () ^ "\n" :: |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
87 |
maps (fn (_, []) => [] |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
88 |
| (heading, lines) => |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
89 |
"\n% " ^ heading ^ " (" ^ Int.toString (length lines) ^ ")\n" :: |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
90 |
map string_for_problem_line lines) problem |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
91 |
|
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
92 |
fun is_tptp_variable s = Char.isUpper (String.sub (s, 0)) |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
93 |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
94 |
|
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
95 |
(** Nice names **) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
96 |
|
37624 | 97 |
fun empty_name_pool readable_names = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
98 |
if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
37624 | 99 |
|
100 |
fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs |
|
101 |
fun pool_map f xs = |
|
102 |
pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs [] |
|
103 |
||
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
104 |
(* "equal" is reserved by some ATPs. "op" is also reserved, to avoid the |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
105 |
unreadable "op_1", "op_2", etc., in the problem files. *) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
106 |
val reserved_nice_names = ["equal", "op"] |
37624 | 107 |
fun readable_name full_name s = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
108 |
if s = full_name then |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
109 |
s |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
110 |
else |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
111 |
let |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
112 |
val s = s |> Long_Name.base_name |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
113 |
|> Name.desymbolize (Char.isUpper (String.sub (full_name, 0))) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
114 |
in if member (op =) reserved_nice_names s then full_name else s end |
37624 | 115 |
|
116 |
fun nice_name (full_name, _) NONE = (full_name, NONE) |
|
117 |
| nice_name (full_name, desired_name) (SOME the_pool) = |
|
118 |
case Symtab.lookup (fst the_pool) full_name of |
|
119 |
SOME nice_name => (nice_name, SOME the_pool) |
|
120 |
| NONE => |
|
121 |
let |
|
122 |
val nice_prefix = readable_name full_name desired_name |
|
123 |
fun add j = |
|
124 |
let |
|
125 |
val nice_name = nice_prefix ^ |
|
126 |
(if j = 0 then "" else "_" ^ Int.toString j) |
|
127 |
in |
|
128 |
case Symtab.lookup (snd the_pool) nice_name of |
|
129 |
SOME full_name' => |
|
130 |
if full_name = full_name' then (nice_name, the_pool) |
|
131 |
else add (j + 1) |
|
132 |
| NONE => |
|
133 |
(nice_name, |
|
134 |
(Symtab.update_new (full_name, nice_name) (fst the_pool), |
|
135 |
Symtab.update_new (nice_name, full_name) (snd the_pool))) |
|
136 |
end |
|
137 |
in add 0 |> apsnd SOME end |
|
138 |
||
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
139 |
|
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
140 |
fun nice_term (ATerm (name, ts)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
141 |
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
|
142 |
fun nice_formula (AQuant (q, xs, phi)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
143 |
pool_map nice_name xs ##>> nice_formula phi |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
144 |
#>> (fn (xs, phi) => AQuant (q, xs, phi)) |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
145 |
| nice_formula (AConn (c, phis)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
146 |
pool_map nice_formula phis #>> curry AConn c |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
147 |
| nice_formula (APred tm) = nice_term tm #>> APred |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
148 |
fun nice_problem_line (Fof (ident, kind, phi)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
149 |
nice_formula phi #>> (fn phi => Fof (ident, kind, phi)) |
37931 | 150 |
fun nice_problem problem = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
151 |
pool_map (fn (heading, lines) => |
37931 | 152 |
pool_map nice_problem_line lines #>> pair heading) problem |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
153 |
fun nice_tptp_problem readable_names problem = |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
154 |
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
|
155 |
|
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
156 |
end; |