author | blanchet |
Sun, 01 May 2011 18:37:24 +0200 | |
changeset 42530 | f64c546efe8c |
parent 42529 | 747736d8b47e |
child 42531 | a462dbaa584f |
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 |
|
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
13 |
datatype ('a, 'b) formula = |
42530 | 14 |
AQuant of quantifier * ('a * 'b option) list * ('a, 'b) formula | |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
15 |
AConn of connective * ('a, 'b) formula list | |
38034 | 16 |
AAtom of 'b |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
17 |
type 'a uniform_formula = ('a, 'a fo_term) formula |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
18 |
|
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 = |
42528 | 21 |
Type_Decl of string * 'a * 'a list * 'a | |
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 |
Formula of string * formula_kind * ('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 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
26 |
val timestamp : unit -> string |
39452 | 27 |
val is_atp_variable : string -> bool |
28 |
val tptp_strings_for_atp_problem : |
|
38631
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
29 |
bool -> (string * string problem_line list) list -> string list |
39452 | 30 |
val nice_atp_problem : |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
31 |
bool -> ('a * (string * string) problem_line list) list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
32 |
-> ('a * string problem_line list) list |
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
33 |
* (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
|
34 |
end; |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
35 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
36 |
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
|
37 |
struct |
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
38 |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
39 |
(** ATP problem **) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
40 |
|
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
41 |
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
|
42 |
datatype quantifier = AForall | AExists |
37992 | 43 |
datatype connective = ANot | AAnd | AOr | AImplies | AIf | AIff | ANotIff |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
44 |
datatype ('a, 'b) formula = |
42530 | 45 |
AQuant of quantifier * ('a * 'b option) list * ('a, 'b) formula | |
37994
b04307085a09
make TPTP generator accept full first-order formulas
blanchet
parents:
37993
diff
changeset
|
46 |
AConn of connective * ('a, 'b) formula list | |
38034 | 47 |
AAtom of 'b |
39453
1740a2d6bef9
use the same TSTP/Vampire/SPASS parser for one-liners as for Isar proofs
blanchet
parents:
39452
diff
changeset
|
48 |
type 'a uniform_formula = ('a, 'a fo_term) formula |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
49 |
|
42525
7a506b0b644f
distinguish FOF and TFF (typed first-order) in ATP abstract syntax tree
blanchet
parents:
42449
diff
changeset
|
50 |
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
|
51 |
datatype 'a problem_line = |
42528 | 52 |
Type_Decl of string * 'a * 'a list * 'a | |
42527
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
53 |
Formula of string * formula_kind * ('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
|
54 |
* 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
|
55 |
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
|
56 |
|
38019
e207a64e1e0b
complete renaming of "Sledgehammer_TPTP_Format" to "ATP_Problem"
blanchet
parents:
38018
diff
changeset
|
57 |
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
|
58 |
|
38631
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
59 |
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
|
60 |
| 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
|
61 |
| string_for_kind Lemma = "lemma" |
38631
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
62 |
| string_for_kind Hypothesis = "hypothesis" |
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
63 |
| string_for_kind Conjecture = "conjecture" |
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
64 |
|
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
65 |
fun string_for_term (ATerm (s, [])) = s |
38088
a9847fb539dd
fix bug with "=" vs. "fequal" introduced by last change (dddb8ba3a1ce)
blanchet
parents:
38047
diff
changeset
|
66 |
| string_for_term (ATerm ("equal", ts)) = |
a9847fb539dd
fix bug with "=" vs. "fequal" introduced by last change (dddb8ba3a1ce)
blanchet
parents:
38047
diff
changeset
|
67 |
space_implode " = " (map string_for_term ts) |
41769
eb2e39555f98
extended ATP problem syntax to support other applications than Sledgehammer, e.g. experiments with ATPs
blanchet
parents:
41491
diff
changeset
|
68 |
| string_for_term (ATerm ("[]", ts)) = |
eb2e39555f98
extended ATP problem syntax to support other applications than Sledgehammer, e.g. experiments with ATPs
blanchet
parents:
41491
diff
changeset
|
69 |
(* used for lists in the optional "source" field of a derivation *) |
eb2e39555f98
extended ATP problem syntax to support other applications than Sledgehammer, e.g. experiments with ATPs
blanchet
parents:
41491
diff
changeset
|
70 |
"[" ^ commas (map string_for_term ts) ^ "]" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
71 |
| string_for_term (ATerm (s, ts)) = |
38088
a9847fb539dd
fix bug with "=" vs. "fequal" introduced by last change (dddb8ba3a1ce)
blanchet
parents:
38047
diff
changeset
|
72 |
s ^ "(" ^ commas (map string_for_term ts) ^ ")" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
73 |
fun string_for_quantifier AForall = "!" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
74 |
| string_for_quantifier AExists = "?" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
75 |
fun string_for_connective ANot = "~" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
76 |
| string_for_connective AAnd = "&" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
77 |
| string_for_connective AOr = "|" |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
78 |
| string_for_connective AImplies = "=>" |
37992 | 79 |
| string_for_connective AIf = "<=" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
80 |
| string_for_connective AIff = "<=>" |
37992 | 81 |
| string_for_connective ANotIff = "<~>" |
42526 | 82 |
fun string_for_bound_var (s, NONE) = s |
42530 | 83 |
| string_for_bound_var (s, SOME ty) = s ^ " : " ^ string_for_term ty |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
84 |
fun string_for_formula (AQuant (q, xs, phi)) = |
42526 | 85 |
"(" ^ string_for_quantifier q ^ |
86 |
"[" ^ commas (map string_for_bound_var xs) ^ "] : " ^ |
|
38489 | 87 |
string_for_formula phi ^ ")" |
38034 | 88 |
| string_for_formula (AConn (ANot, [AAtom (ATerm ("equal", ts))])) = |
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
|
89 |
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
|
90 |
| string_for_formula (AConn (c, [phi])) = |
38489 | 91 |
"(" ^ string_for_connective c ^ " " ^ string_for_formula phi ^ ")" |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
92 |
| string_for_formula (AConn (c, phis)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
93 |
"(" ^ space_implode (" " ^ string_for_connective c ^ " ") |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
94 |
(map string_for_formula phis) ^ ")" |
38034 | 95 |
| string_for_formula (AAtom tm) = string_for_term tm |
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
96 |
|
42527
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
97 |
fun formula_needs_typed_logic (AQuant (_, xs, phi)) = |
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
98 |
exists (is_some o snd) xs orelse formula_needs_typed_logic phi |
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
99 |
| formula_needs_typed_logic (AConn (_, phis)) = |
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
100 |
exists formula_needs_typed_logic phis |
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
101 |
| formula_needs_typed_logic (AAtom _) = false |
6a9458524f01
reintroduced constructor for formulas, and automatically detect which logic to use (TFF or FOF) to avoid clutter
blanchet
parents:
42526
diff
changeset
|
102 |
|
42528 | 103 |
fun string_for_symbol_type [] res_ty = res_ty |
104 |
| string_for_symbol_type [arg_ty] res_ty = arg_ty ^ " > " ^ res_ty |
|
105 |
| string_for_symbol_type arg_tys res_ty = |
|
106 |
string_for_symbol_type ["(" ^ space_implode " * " arg_tys ^ ")"] res_ty |
|
107 |
||
108 |
fun string_for_problem_line _ (Type_Decl (ident, sym, arg_tys, res_ty)) = |
|
109 |
"tff(" ^ ident ^ ", type, " ^ sym ^ " : " ^ |
|
110 |
string_for_symbol_type arg_tys res_ty ^ ").\n" |
|
111 |
| string_for_problem_line use_conjecture_for_hypotheses |
|
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
|
112 |
(Formula (ident, kind, phi, source, useful_info)) = |
42528 | 113 |
let |
114 |
val (kind, phi) = |
|
115 |
if kind = Hypothesis andalso use_conjecture_for_hypotheses then |
|
116 |
(Conjecture, AConn (ANot, [phi])) |
|
117 |
else |
|
118 |
(kind, phi) |
|
119 |
in |
|
120 |
(if formula_needs_typed_logic phi then "tff" else "fof") ^ |
|
121 |
"(" ^ ident ^ ", " ^ string_for_kind kind ^ ",\n (" ^ |
|
122 |
string_for_formula phi ^ ")" ^ |
|
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
|
123 |
(case (source, useful_info) of |
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
|
124 |
(NONE, NONE) => "" |
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
|
125 |
| (SOME tm, NONE) => ", " ^ string_for_term tm |
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
|
126 |
| (_, SOME tm) => |
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
|
127 |
", " ^ string_for_term (source |> the_default (ATerm ("[]", []))) ^ |
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
|
128 |
", " ^ string_for_term tm) ^ ").\n" |
42528 | 129 |
end |
39452 | 130 |
fun tptp_strings_for_atp_problem use_conjecture_for_hypotheses problem = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
131 |
"% 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
|
132 |
\% " ^ timestamp () ^ "\n" :: |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
133 |
maps (fn (_, []) => [] |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
134 |
| (heading, lines) => |
41491 | 135 |
"\n% " ^ heading ^ " (" ^ string_of_int (length lines) ^ ")\n" :: |
38631
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
136 |
map (string_for_problem_line use_conjecture_for_hypotheses) lines) |
979a0b37f981
prefer TPTP "conjecture" tag to "hypothesis" on ATPs where this is possible;
blanchet
parents:
38613
diff
changeset
|
137 |
problem |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
138 |
|
39452 | 139 |
fun is_atp_variable s = Char.isUpper (String.sub (s, 0)) |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
140 |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
141 |
|
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
142 |
(** Nice names **) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
143 |
|
37624 | 144 |
fun empty_name_pool readable_names = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
145 |
if readable_names then SOME (Symtab.empty, Symtab.empty) else NONE |
37624 | 146 |
|
147 |
fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs |
|
148 |
fun pool_map f xs = |
|
149 |
pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs [] |
|
150 |
||
42227
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
151 |
val no_qualifiers = |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
152 |
let |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
153 |
fun skip [] = [] |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
154 |
| skip (#"." :: cs) = skip cs |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
155 |
| 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
|
156 |
and keep [] = [] |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
157 |
| keep (#"." :: cs) = skip cs |
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
158 |
| 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
|
159 |
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
|
160 |
|
39109 | 161 |
(* "op" is also reserved, to avoid the unreadable "op_1", "op_2", etc., in the |
162 |
problem files. "equal" is reserved by some ATPs. "eq" is reserved to ensure |
|
163 |
that "HOL.eq" is correctly mapped to equality. *) |
|
164 |
val reserved_nice_names = ["op", "equal", "eq"] |
|
37624 | 165 |
fun readable_name full_name s = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
166 |
if s = full_name then |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
167 |
s |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
168 |
else |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
169 |
let |
42227
662b50b7126f
if "monomorphize" is enabled, mangle the type information in the names by default
blanchet
parents:
41769
diff
changeset
|
170 |
val s = s |> no_qualifiers |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
171 |
|> 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
|
172 |
in if member (op =) reserved_nice_names s then full_name else s end |
37624 | 173 |
|
174 |
fun nice_name (full_name, _) NONE = (full_name, NONE) |
|
175 |
| nice_name (full_name, desired_name) (SOME the_pool) = |
|
39384 | 176 |
if String.isPrefix "$" full_name then |
177 |
(full_name, SOME the_pool) |
|
178 |
else case Symtab.lookup (fst the_pool) full_name of |
|
37624 | 179 |
SOME nice_name => (nice_name, SOME the_pool) |
180 |
| NONE => |
|
181 |
let |
|
182 |
val nice_prefix = readable_name full_name desired_name |
|
183 |
fun add j = |
|
184 |
let |
|
185 |
val nice_name = nice_prefix ^ |
|
41491 | 186 |
(if j = 0 then "" else "_" ^ string_of_int j) |
37624 | 187 |
in |
188 |
case Symtab.lookup (snd the_pool) nice_name of |
|
189 |
SOME full_name' => |
|
190 |
if full_name = full_name' then (nice_name, the_pool) |
|
191 |
else add (j + 1) |
|
192 |
| NONE => |
|
193 |
(nice_name, |
|
194 |
(Symtab.update_new (full_name, nice_name) (fst the_pool), |
|
195 |
Symtab.update_new (nice_name, full_name) (snd the_pool))) |
|
196 |
end |
|
197 |
in add 0 |> apsnd SOME end |
|
198 |
||
37961
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
199 |
fun nice_term (ATerm (name, ts)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
200 |
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
|
201 |
fun nice_formula (AQuant (q, xs, phi)) = |
42526 | 202 |
pool_map nice_name (map fst xs) |
203 |
##>> pool_map (fn NONE => pair NONE |
|
42530 | 204 |
| SOME ty => nice_term ty #>> SOME) (map snd xs) |
42526 | 205 |
##>> nice_formula phi |
206 |
#>> (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
|
207 |
| nice_formula (AConn (c, phis)) = |
6a48c85a211a
first step in using "fof" rather than "cnf" in TPTP problems
blanchet
parents:
37931
diff
changeset
|
208 |
pool_map nice_formula phis #>> curry AConn c |
38034 | 209 |
| nice_formula (AAtom tm) = nice_term tm #>> AAtom |
42528 | 210 |
fun nice_problem_line (Type_Decl (ident, sym, arg_tys, res_ty)) = |
211 |
nice_name sym |
|
212 |
##>> pool_map nice_name arg_tys |
|
213 |
##>> nice_name res_ty |
|
214 |
#>> (fn ((sym, arg_tys), res_ty) => Type_Decl (ident, sym, arg_tys, res_ty)) |
|
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
|
215 |
| nice_problem_line (Formula (ident, kind, phi, source, useful_info)) = |
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
|
216 |
nice_formula phi |
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
|
217 |
#>> (fn phi => Formula (ident, kind, phi, source, useful_info)) |
37931 | 218 |
fun nice_problem problem = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37642
diff
changeset
|
219 |
pool_map (fn (heading, lines) => |
37931 | 220 |
pool_map nice_problem_line lines #>> pair heading) problem |
39452 | 221 |
fun nice_atp_problem readable_names problem = |
38017
3ad3e3ca2451
move Sledgehammer-specific code out of "Sledgehammer_TPTP_Format"
blanchet
parents:
38014
diff
changeset
|
222 |
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
|
223 |
|
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
diff
changeset
|
224 |
end; |