author  blanchet 
Mon, 26 Jul 2010 14:14:24 +0200  
changeset 37994  b04307085a09 
parent 37989  ca3041b0f445 
child 37995  06f02b15ef8a 
permissions  rwrr 
36376  1 
(* Title: HOL/Tools/ATP_Manager/atp_systems.ML 
28592  2 
Author: Fabian Immler, TU Muenchen 
36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

3 
Author: Jasmin Blanchette, TU Muenchen 
28592  4 

36376  5 
Setup for supported ATPs. 
28592  6 
*) 
7 

36376  8 
signature ATP_SYSTEMS = 
28592  9 
sig 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

10 
val trace : bool Unsynchronized.ref 
36376  11 
val dest_dir : string Config.T 
35867  12 
val problem_prefix : string Config.T 
13 
val measure_runtime : bool Config.T 

14 
val refresh_systems_on_tptp : unit > unit 

36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

15 
val default_atps_param_value : unit > string 
35867  16 
val setup : theory > theory 
28592  17 
end; 
18 

36376  19 
structure ATP_Systems : ATP_SYSTEMS = 
28592  20 
struct 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

21 

37578
9367cb36b1c4
renamed "Sledgehammer_FOL_Clauses" to "Metis_Clauses", so that Metis doesn't depend on Sledgehammer
blanchet
parents:
37577
diff
changeset

22 
open Metis_Clauses 
36187  23 
open Sledgehammer_Util 
35865  24 
open Sledgehammer_Fact_Filter 
37578
9367cb36b1c4
renamed "Sledgehammer_FOL_Clauses" to "Metis_Clauses", so that Metis doesn't depend on Sledgehammer
blanchet
parents:
37577
diff
changeset

25 
open Sledgehammer_TPTP_Format 
35865  26 
open Sledgehammer_Proof_Reconstruct 
35867  27 
open ATP_Manager 
35826  28 

37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

29 
val trace = Unsynchronized.ref false 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

30 
fun trace_msg msg = if !trace then tracing (msg ()) else () 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

31 

36376  32 
(** generic ATP **) 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

33 

32944
ecc0705174c2
clarified File.platform_path vs. File.shell_path;
wenzelm
parents:
32942
diff
changeset

34 
(* external problem files *) 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

35 

36376  36 
val (dest_dir, dest_dir_setup) = Attrib.config_string "atp_dest_dir" (K ""); 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

37 
(*Empty string means create files in Isabelle's temporary files directory.*) 
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

38 

a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

39 
val (problem_prefix, problem_prefix_setup) = 
36001  40 
Attrib.config_string "atp_problem_prefix" (K "prob"); 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

41 

33247  42 
val (measure_runtime, measure_runtime_setup) = 
36001  43 
Attrib.config_bool "atp_measure_runtime" (K false); 
33247  44 

32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

45 

35867  46 
(* prover configuration *) 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

47 

32941
72d48e333b77
eliminated extraneous wrapping of public records;
wenzelm
parents:
32936
diff
changeset

48 
type prover_config = 
36917
8674cdb0b8cc
query _HOME environment variables at runtime, not at buildtime
blanchet
parents:
36910
diff
changeset

49 
{home_var: string, 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

50 
executable: string, 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

51 
arguments: bool > Time.time > string, 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

52 
proof_delims: (string * string) list, 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

53 
known_failures: (failure * string) list, 
36382  54 
max_axiom_clauses: int, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

55 
prefers_theory_relevant: bool, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

56 
explicit_forall: bool} 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

57 

fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

58 

fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

59 
(* basic template *) 
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

60 

36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

61 
val remotify = prefix "remote_" 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

62 

32458
de6834b20e9e
sledgehammer's temporary files are removed properly (even in case of an exception occurs)
boehmes
parents:
32451
diff
changeset

63 
fun with_path cleanup after f path = 
de6834b20e9e
sledgehammer's temporary files are removed properly (even in case of an exception occurs)
boehmes
parents:
32451
diff
changeset

64 
Exn.capture f path 
de6834b20e9e
sledgehammer's temporary files are removed properly (even in case of an exception occurs)
boehmes
parents:
32451
diff
changeset

65 
> tap (fn _ => cleanup path) 
de6834b20e9e
sledgehammer's temporary files are removed properly (even in case of an exception occurs)
boehmes
parents:
32451
diff
changeset

66 
> Exn.release 
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

67 
> tap (after path) 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

68 

d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

69 
(* Splits by the first possible of a list of delimiters. *) 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

70 
fun extract_proof delims output = 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

71 
case pairself (find_first (fn s => String.isSubstring s output)) 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

72 
(ListPair.unzip delims) of 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

73 
(SOME begin_delim, SOME end_delim) => 
36549  74 
(output > first_field begin_delim > the > snd 
75 
> first_field end_delim > the > fst 

76 
> first_field "\n" > the > snd 

77 
handle Option.Option => "") 

36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

78 
 _ => "" 
32458
de6834b20e9e
sledgehammer's temporary files are removed properly (even in case of an exception occurs)
boehmes
parents:
32451
diff
changeset

79 

37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

80 
fun extract_proof_and_outcome complete res_code proof_delims known_failures 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

81 
output = 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

82 
case map_filter (fn (failure, pattern) => 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

83 
if String.isSubstring pattern output then SOME failure 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

84 
else NONE) known_failures of 
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

85 
[] => (case extract_proof proof_delims output of 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

86 
"" => ("", SOME UnknownError) 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

87 
 proof => if res_code = 0 then (proof, NONE) 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

88 
else ("", SOME UnknownError)) 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

89 
 (failure :: _) => 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

90 
("", SOME (if failure = IncompleteUnprovable andalso complete then 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

91 
Unprovable 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

92 
else 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

93 
failure)) 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

94 

a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

95 
fun string_for_failure Unprovable = "The ATP problem is unprovable." 
37413  96 
 string_for_failure IncompleteUnprovable = 
97 
"The ATP cannot prove the problem." 

37627  98 
 string_for_failure CantConnect = "Can't connect to remote ATP." 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

99 
 string_for_failure TimedOut = "Timed out." 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

100 
 string_for_failure OutOfResources = "The ATP ran out of resources." 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

101 
 string_for_failure OldSpass = 
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled  useful for debugging
blanchet
parents:
36382
diff
changeset

102 
(* FIXME: Change the error message below to point to the Isabelle download 
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled  useful for debugging
blanchet
parents:
36382
diff
changeset

103 
page once the package is there (around the Isabelle2010 release). *) 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

104 
"Warning: Sledgehammer requires a more recent version of SPASS with \ 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

105 
\support for the TPTP syntax. To install it, download and untar the \ 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

106 
\package \"http://isabelle.in.tum.de/~blanchet/spass3.7.tgz\" and add the \ 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

107 
\\"spass3.7\" directory's full path to \"" ^ 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

108 
Path.implode (Path.expand (Path.appends 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

109 
(Path.variable "ISABELLE_HOME_USER" :: 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

110 
map Path.basic ["etc", "components"]))) ^ 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

111 
"\" on a line of its own." 
36965  112 
 string_for_failure MalformedInput = 
113 
"Internal Sledgehammer error: The ATP problem is malformed. Please report \ 

114 
\this to the Isabelle developers." 

36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

115 
 string_for_failure MalformedOutput = "Error: The ATP output is malformed." 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

116 
 string_for_failure UnknownError = "Error: An unknown ATP error occurred." 
35865  117 

36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

118 
fun shape_of_clauses _ [] = [] 
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

119 
 shape_of_clauses j ([] :: clauses) = [] :: shape_of_clauses j clauses 
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37480
diff
changeset

120 
 shape_of_clauses j ((_ :: lits) :: clauses) = 
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

121 
let val shape = shape_of_clauses (j + 1) (lits :: clauses) in 
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

122 
(j :: hd shape) :: tl shape 
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

123 
end 
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

124 

37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

125 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

126 
(* Clause preparation *) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

127 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

128 
fun make_clause_table xs = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

129 
fold (Termtab.update o `(prop_of o snd)) xs Termtab.empty 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

130 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

131 
(* Remove existing axiom clauses from the conjecture clauses, as this can 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

132 
dramatically boost an ATP's performance (for some reason). *) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

133 
fun subtract_cls ax_clauses = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

134 
filter_out (Termtab.defined (make_clause_table ax_clauses) o prop_of) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

135 

37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

136 
(* FIXME: kill *) 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

137 
fun mk_anot phi = AConn (ANot, [phi]) 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

138 
fun mk_aconn c phi1 phi2 = AConn (c, [phi1, phi2]) 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

139 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

140 
(* making axiom and conjecture clauses *) 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

141 
fun make_clause thy (formula_id, formula_name, kind, th) skolems = 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

142 
let 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

143 
val (skolems, t) = th > prop_of > conceal_skolem_terms formula_id skolems 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

144 
val (lits, ctypes_sorts) = literals_of_term thy t 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

145 
(* FIXME: avoid "literals_of_term *) 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

146 
val combformula = 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

147 
case lits of 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

148 
[] => APred (CombConst (("c_False", "False"), CombType (("bool", "bool"), []), [])) 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

149 
 _ => 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

150 
let val phis = lits > map (fn FOLLiteral (pos, tm) => APred tm > not pos ? mk_anot) in 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

151 
fold (mk_aconn AOr) (tl phis) (hd phis) 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

152 
> kind = Conjecture ? mk_anot 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

153 
end 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

154 
in 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

155 
(skolems, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

156 
FOLFormula {formula_name = formula_name, formula_id = formula_id, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

157 
combformula = combformula, kind = kind, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

158 
ctypes_sorts = ctypes_sorts}) 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

159 
end 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

160 

37625
35eeb95c5bee
rename "skolem_somes" to "skolems", now that there's only one flavor of Skolems
blanchet
parents:
37623
diff
changeset

161 
fun add_axiom_clause thy ((name, k), th) (skolems, clss) = 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

162 
let 
37625
35eeb95c5bee
rename "skolem_somes" to "skolems", now that there's only one flavor of Skolems
blanchet
parents:
37623
diff
changeset

163 
val (skolems, cls) = make_clause thy (k, name, Axiom, th) skolems 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

164 
in (skolems, (name, cls) :: clss) end 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

165 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

166 
fun make_axiom_clauses thy clauses = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

167 
([], []) > fold_rev (add_axiom_clause thy) clauses > snd 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

168 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

169 
fun make_conjecture_clauses thy = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

170 
let 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

171 
fun aux _ _ [] = [] 
37625
35eeb95c5bee
rename "skolem_somes" to "skolems", now that there's only one flavor of Skolems
blanchet
parents:
37623
diff
changeset

172 
 aux n skolems (th :: ths) = 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

173 
let 
37625
35eeb95c5bee
rename "skolem_somes" to "skolems", now that there's only one flavor of Skolems
blanchet
parents:
37623
diff
changeset

174 
val (skolems, cls) = 
35eeb95c5bee
rename "skolem_somes" to "skolems", now that there's only one flavor of Skolems
blanchet
parents:
37623
diff
changeset

175 
make_clause thy (n, "conjecture", Conjecture, th) skolems 
35eeb95c5bee
rename "skolem_somes" to "skolems", now that there's only one flavor of Skolems
blanchet
parents:
37623
diff
changeset

176 
in cls :: aux (n + 1) skolems ths end 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

177 
in aux 0 [] end 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

178 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

179 
(** Helper clauses **) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

180 

37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

181 
fun count_combterm (CombConst ((s, _), _, _)) = 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

182 
Symtab.map_entry s (Integer.add 1) 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

183 
 count_combterm (CombVar _) = I 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

184 
 count_combterm (CombApp (t1, t2)) = fold count_combterm [t1, t2] 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

185 
fun count_combformula (AQuant (_, _, phi)) = count_combformula phi 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

186 
 count_combformula (AConn (_, phis)) = fold count_combformula phis 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

187 
 count_combformula (APred tm) = count_combterm tm 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

188 
fun count_fol_formula (FOLFormula {combformula, ...}) = 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

189 
count_combformula combformula 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

190 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

191 
fun cnf_helper_thms thy raw = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

192 
map (`Thm.get_name_hint) 
37926
e6ff246c0cdb
renamings + only need second component of name pool to reconstruct proofs
blanchet
parents:
37925
diff
changeset

193 
#> (if raw then map (apfst (rpair 0)) else Clausifier.cnf_rules_pairs thy true) 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

194 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

195 
val optional_helpers = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

196 
[(["c_COMBI", "c_COMBK"], (false, @{thms COMBI_def COMBK_def})), 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

197 
(["c_COMBB", "c_COMBC"], (false, @{thms COMBB_def COMBC_def})), 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

198 
(["c_COMBS"], (false, @{thms COMBS_def}))] 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

199 
val optional_typed_helpers = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

200 
[(["c_True", "c_False"], (true, @{thms True_or_False})), 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

201 
(["c_If"], (true, @{thms if_True if_False True_or_False}))] 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

202 
val mandatory_helpers = @{thms fequal_imp_equal equal_imp_fequal} 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

203 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

204 
val init_counters = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

205 
Symtab.make (maps (maps (map (rpair 0) o fst)) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

206 
[optional_helpers, optional_typed_helpers]) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

207 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

208 
fun get_helper_clauses thy is_FO full_types conjectures axcls = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

209 
let 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

210 
val axclauses = map snd (make_axiom_clauses thy axcls) 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

211 
val ct = fold (fold count_fol_formula) [conjectures, axclauses] 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

212 
init_counters 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

213 
fun is_needed c = the (Symtab.lookup ct c) > 0 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

214 
val cnfs = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

215 
(optional_helpers 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

216 
> full_types ? append optional_typed_helpers 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

217 
> maps (fn (ss, (raw, ths)) => 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

218 
if exists is_needed ss then cnf_helper_thms thy raw ths 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

219 
else [])) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

220 
@ (if is_FO then [] else cnf_helper_thms thy false mandatory_helpers) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

221 
in map snd (make_axiom_clauses thy cnfs) end 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

222 

295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

223 
(* prepare for passing to writer, 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

224 
create additional clauses based on the information from extra_cls *) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

225 
fun prepare_clauses full_types goal_cls axcls extra_cls thy = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

226 
let 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

227 
val is_FO = forall (Meson.is_fol_term thy o prop_of) goal_cls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

228 
val ccls = subtract_cls extra_cls goal_cls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

229 
val _ = app (fn th => trace_msg (fn _ => Display.string_of_thm_global thy th)) ccls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

230 
val ccltms = map prop_of ccls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

231 
and axtms = map (prop_of o snd) extra_cls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

232 
val subs = tfree_classes_of_terms ccltms 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

233 
and supers = tvar_classes_of_terms axtms 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

234 
and tycons = type_consts_of_terms thy (ccltms @ axtms) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

235 
(*TFrees in conjecture clauses; TVars in axiom clauses*) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

236 
val conjectures = make_conjecture_clauses thy ccls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

237 
val (_, extra_clauses) = ListPair.unzip (make_axiom_clauses thy extra_cls) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

238 
val (clnames, axiom_clauses) = ListPair.unzip (make_axiom_clauses thy axcls) 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

239 
val helper_clauses = 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

240 
get_helper_clauses thy is_FO full_types conjectures extra_cls 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

241 
val (supers', arity_clauses) = make_arity_clauses thy tycons supers 
37925  242 
val class_rel_clauses = make_class_rel_clauses thy subs supers' 
37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

243 
in 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

244 
(Vector.fromList clnames, 
37925  245 
(conjectures, axiom_clauses, extra_clauses, helper_clauses, 
246 
class_rel_clauses, arity_clauses)) 

37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

247 
end 
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

248 

37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

249 
fun extract_clause_sequence output = 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

250 
let 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

251 
val tokens_of = String.tokens (not o Char.isAlphaNum) 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

252 
fun extract_num ("clause" :: (ss as _ :: _)) = 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

253 
Int.fromString (List.last ss) 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

254 
 extract_num _ = NONE 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

255 
in output > split_lines > map_filter (extract_num o tokens_of) end 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

256 

d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

257 
val set_ClauseFormulaRelationN = "set_ClauseFormulaRelation" 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

258 

d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

259 
val parse_clause_formula_pair = 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

260 
$$ "("  scan_integer  $$ ","  Symbol.scan_id  $$ ")" 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

261 
 Scan.option ($$ ",") 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

262 
val parse_clause_formula_relation = 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

263 
Scan.this_string set_ClauseFormulaRelationN  $$ "(" 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

264 
 Scan.repeat parse_clause_formula_pair 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

265 
val extract_clause_formula_relation = 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

266 
Substring.full 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

267 
#> Substring.position set_ClauseFormulaRelationN 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

268 
#> snd #> Substring.string #> strip_spaces #> explode 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

269 
#> parse_clause_formula_relation #> fst 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

270 

37989
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

271 
fun repair_conjecture_shape_and_theorem_names output conjecture_shape 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

272 
thm_names = 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

273 
if String.isSubstring set_ClauseFormulaRelationN output then 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

274 
let 
37989
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

275 
(* FIXME: hd of head once clausification is left to the ATP *) 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

276 
val j0 = hd (List.concat conjecture_shape) 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

277 
val seq = extract_clause_sequence output 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

278 
val name_map = extract_clause_formula_relation output 
37989
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

279 
fun renumber_conjecture j = 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

280 
AList.find (op =) name_map (conjecture_prefix ^ Int.toString (j  j0)) 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

281 
> the_single 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

282 
> (fn s => find_index (curry (op =) s) seq + 1) 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

283 
in 
37989
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

284 
(conjecture_shape > map (map renumber_conjecture), 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

285 
seq > map (the o AList.lookup (op =) name_map) 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

286 
> map (fn s => case try (unprefix axiom_prefix) s of 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

287 
SOME s' => undo_ascii_of s' 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

288 
 NONE => "") 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

289 
> Vector.fromList) 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

290 
end 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

291 
else 
37989
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

292 
(conjecture_shape, thm_names) 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

293 

37623
295f3a9b44b6
move functions not needed by Metis out of "Metis_Clauses"
blanchet
parents:
37621
diff
changeset

294 

37499
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

295 
(* generic TPTPbased provers *) 
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

296 

5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

297 
fun generic_tptp_prover 
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

298 
(name, {home_var, executable, arguments, proof_delims, known_failures, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

299 
max_axiom_clauses, prefers_theory_relevant, explicit_forall}) 
37580
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset

300 
({debug, overlord, full_types, explicit_apply, relevance_threshold, 
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset

301 
relevance_convergence, theory_relevant, defs_relevant, isar_proof, 
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset

302 
isar_shrink_factor, ...} : params) 
37499
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

303 
minimize_command timeout 
35969  304 
({subgoal, goal, relevance_override, axiom_clauses, filtered_clauses} 
305 
: problem) = 

28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

306 
let 
31750  307 
(* get clauses and prepare them for writing *) 
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37480
diff
changeset

308 
val (ctxt, (_, th)) = goal; 
32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

309 
val thy = ProofContext.theory_of ctxt; 
37926
e6ff246c0cdb
renamings + only need second component of name pool to reconstruct proofs
blanchet
parents:
37925
diff
changeset

310 
val goal_clss = #1 (Clausifier.neg_conjecture_clauses ctxt th subgoal) 
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

311 
val goal_cls = List.concat goal_clss 
31752
19a5f1c8a844
use results of relevancefilter to determine additional clauses;
immler@in.tum.de
parents:
31751
diff
changeset

312 
val the_filtered_clauses = 
37621  313 
case filtered_clauses of 
314 
SOME fcls => fcls 

315 
 NONE => relevant_facts full_types relevance_threshold 

37499
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

316 
relevance_convergence defs_relevant max_axiom_clauses 
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

317 
(the_default prefers_theory_relevant theory_relevant) 
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

318 
relevance_override goal goal_cls 
37926
e6ff246c0cdb
renamings + only need second component of name pool to reconstruct proofs
blanchet
parents:
37925
diff
changeset

319 
> Clausifier.cnf_rules_pairs thy true 
37506
32a1ee39c49b
missing "Unsynchronized" + make exception take a unit
blanchet
parents:
37499
diff
changeset

320 
val the_axiom_clauses = axiom_clauses > the_default the_filtered_clauses 
35969  321 
val (internal_thm_names, clauses) = 
37499
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

322 
prepare_clauses full_types goal_cls the_axiom_clauses the_filtered_clauses 
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

323 
thy 
31750  324 

32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

325 
(* path to unique problem file *) 
36376  326 
val the_dest_dir = if overlord then getenv "ISABELLE_HOME_USER" 
327 
else Config.get ctxt dest_dir; 

328 
val the_problem_prefix = Config.get ctxt problem_prefix; 

32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

329 
fun prob_pathname nr = 
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset

330 
let 
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset

331 
val probfile = 
36568
d495d2e1f0a6
in "overlord" mode: ignore problem prefix specified in the .thy file
blanchet
parents:
36552
diff
changeset

332 
Path.basic ((if overlord then "prob_" ^ name 
d495d2e1f0a6
in "overlord" mode: ignore problem prefix specified in the .thy file
blanchet
parents:
36552
diff
changeset

333 
else the_problem_prefix ^ serial_string ()) 
36143
6490319b1703
added "overlord" option (to get easy access to output files for debugging) + systematically use "raw_goal" rather than an inconsistent mixture
blanchet
parents:
36142
diff
changeset

334 
^ "_" ^ string_of_int nr) 
32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

335 
in 
36376  336 
if the_dest_dir = "" then File.tmp_path probfile 
337 
else if File.exists (Path.explode the_dest_dir) 

338 
then Path.append (Path.explode the_dest_dir) probfile 

339 
else error ("No such directory: " ^ the_dest_dir ^ ".") 

32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

340 
end; 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

341 

36917
8674cdb0b8cc
query _HOME environment variables at runtime, not at buildtime
blanchet
parents:
36910
diff
changeset

342 
val home = getenv home_var 
36289
f75b6a3e1450
set "atps" reference's default value to "(remote_)e (remote_)spass (remote_)vampire", based on what is installed
blanchet
parents:
36287
diff
changeset

343 
val command = Path.explode (home ^ "/" ^ executable) 
31750  344 
(* write out problem file and call prover *) 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

345 
fun command_line complete probfile = 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

346 
let 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

347 
val core = File.shell_path command ^ " " ^ arguments complete timeout ^ 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

348 
" " ^ File.shell_path probfile 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

349 
in 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

350 
(if Config.get ctxt measure_runtime then 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

351 
"TIMEFORMAT='%3U'; { time " ^ core ^ " ; }" 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

352 
else 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

353 
"exec " ^ core) ^ " 2>&1" 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

354 
end 
32510  355 
fun split_time s = 
356 
let 

32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

357 
val split = String.tokens (fn c => str c = "\n"); 
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

358 
val (output, t) = s > split > split_last > apfst cat_lines; 
32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

359 
fun as_num f = f >> (fst o read_int); 
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

360 
val num = as_num (Scan.many1 Symbol.is_ascii_digit); 
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

361 
val digit = Scan.one Symbol.is_ascii_digit; 
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

362 
val num3 = as_num (digit ::: digit ::: (digit >> single)); 
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

363 
val time = num  Scan.$$ "."  num3 >> (fn (a, b) => a * 1000 + b); 
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

364 
val as_time = the_default 0 o Scan.read Symbol.stopper time o explode; 
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

365 
in (output, as_time t) end; 
32458
de6834b20e9e
sledgehammer's temporary files are removed properly (even in case of an exception occurs)
boehmes
parents:
32451
diff
changeset

366 
fun run_on probfile = 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

367 
if home = "" then 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

368 
error ("The environment variable " ^ quote home_var ^ " is not set.") 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

369 
else if File.exists command then 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

370 
let 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

371 
fun do_run complete = 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

372 
let 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

373 
val command = command_line complete probfile 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

374 
val ((output, msecs), res_code) = 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

375 
bash_output command 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

376 
>> (if overlord then 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

377 
prefix ("% " ^ command ^ "\n% " ^ timestamp () ^ "\n") 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

378 
else 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

379 
I) 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

380 
>> (if Config.get ctxt measure_runtime then split_time 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

381 
else rpair 0) 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

382 
val (proof, outcome) = 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

383 
extract_proof_and_outcome complete res_code proof_delims 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

384 
known_failures output 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

385 
in (output, msecs, proof, outcome) end 
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37628
diff
changeset

386 
val readable_names = debug andalso overlord 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

387 
val (pool, conjecture_offset) = 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

388 
write_tptp_file thy readable_names explicit_forall full_types 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

389 
explicit_apply probfile clauses 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

390 
val conjecture_shape = shape_of_clauses (conjecture_offset + 1) goal_clss 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

391 
val result = 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

392 
do_run false 
37550
fc2f979b9a08
split SPASS time slot between SOS and nonSOS, in case SOS times out
blanchet
parents:
37514
diff
changeset

393 
> (fn (_, msecs0, _, SOME _) => 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

394 
do_run true 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

395 
> (fn (output, msecs, proof, outcome) => 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

396 
(output, msecs0 + msecs, proof, outcome)) 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

397 
 result => result) 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

398 
in ((pool, conjecture_shape), result) end 
36382  399 
else 
400 
error ("Bad executable: " ^ Path.implode command ^ "."); 

28592  401 

36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36143
diff
changeset

402 
(* If the problem file has not been exported, remove it; otherwise, export 
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
36143
diff
changeset

403 
the proof file too. *) 
36376  404 
fun cleanup probfile = 
405 
if the_dest_dir = "" then try File.rm probfile else NONE 

37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

406 
fun export probfile (_, (output, _, _, _)) = 
36376  407 
if the_dest_dir = "" then 
36187  408 
() 
409 
else 

37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

410 
File.write (Path.explode (Path.implode probfile ^ "_proof")) output 
32257
bad5a99c16d8
neg_conjecture_clauses, neg_clausify_tac: proper context, eliminated METAHYPS;
wenzelm
parents:
32091
diff
changeset

411 

37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

412 
val ((pool, conjecture_shape), (output, msecs, proof, outcome)) = 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

413 
with_path cleanup export run_on (prob_pathname subgoal) 
37989
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

414 
val (conjecture_shape, internal_thm_names) = 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

415 
repair_conjecture_shape_and_theorem_names output conjecture_shape 
ca3041b0f445
reorder SPASS conjectures correctly, based on Flotter output
blanchet
parents:
37962
diff
changeset

416 
internal_thm_names 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

417 

35969  418 
val (message, relevant_thm_names) = 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

419 
case outcome of 
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

420 
NONE => 
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

421 
proof_text isar_proof 
37480  422 
(pool, debug, isar_shrink_factor, ctxt, conjecture_shape) 
423 
(full_types, minimize_command, proof, internal_thm_names, th, 

424 
subgoal) 

36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

425 
 SOME failure => (string_for_failure failure ^ "\n", []) 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

426 
in 
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled  useful for debugging
blanchet
parents:
36382
diff
changeset

427 
{outcome = outcome, message = message, pool = pool, 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

428 
relevant_thm_names = relevant_thm_names, atp_run_time_in_msecs = msecs, 
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

429 
output = output, proof = proof, internal_thm_names = internal_thm_names, 
36400
c5bae529f967
rename options and keep track of conjecture shape (to facilitate proof reconstruction)
blanchet
parents:
36393
diff
changeset

430 
conjecture_shape = conjecture_shape, 
35969  431 
filtered_clauses = the_filtered_clauses} 
37499
5ff37037fbec
merge "generic_prover" and "generic_tptp_prover"
blanchet
parents:
37498
diff
changeset

432 
end 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

433 

35969  434 
fun tptp_prover name p = (name, generic_tptp_prover (name, p)); 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

435 

36382  436 
fun to_generous_secs time = (Time.toMilliseconds time + 999) div 1000 
36142
f5e15e9aae10
make Sledgehammer "minimize" output less confusing + round up (not down) time limits to nearest second
blanchet
parents:
36064
diff
changeset

437 

28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

438 
(* E prover *) 
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

439 

36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

440 
val tstp_proof_delims = 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

441 
("# SZS output start CNFRefutation.", "# SZS output end CNFRefutation") 
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

442 

35969  443 
val e_config : prover_config = 
36917
8674cdb0b8cc
query _HOME environment variables at runtime, not at buildtime
blanchet
parents:
36910
diff
changeset

444 
{home_var = "E_HOME", 
36289
f75b6a3e1450
set "atps" reference's default value to "(remote_)e (remote_)spass (remote_)vampire", based on what is installed
blanchet
parents:
36287
diff
changeset

445 
executable = "eproof", 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

446 
arguments = fn _ => fn timeout => 
36382  447 
"tstpin tstpout l5 xAutoDev tAutoDev silent cpulimit=" ^ 
448 
string_of_int (to_generous_secs timeout), 

36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

449 
proof_delims = [tstp_proof_delims], 
36265
41c9e755e552
distinguish between the different ATP errors in the user interface;
blanchet
parents:
36264
diff
changeset

450 
known_failures = 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

451 
[(Unprovable, "SZS status: Satisfiable"), 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

452 
(Unprovable, "SZS status Satisfiable"), 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

453 
(TimedOut, "Failure: Resource limit exceeded (time)"), 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

454 
(TimedOut, "time limit exceeded"), 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

455 
(OutOfResources, 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

456 
"# Cannot determine problem status within resource limit"), 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

457 
(OutOfResources, "SZS status: ResourceOut"), 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

458 
(OutOfResources, "SZS status ResourceOut")], 
36382  459 
max_axiom_clauses = 100, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

460 
prefers_theory_relevant = false, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

461 
explicit_forall = false} 
35969  462 
val e = tptp_prover "e" e_config 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

463 

fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

464 

36219
16670b4f0baa
set SPASS option on the commandline, so that it doesn't vanish when moving to TPTP format
blanchet
parents:
36190
diff
changeset

465 
(* The "VarWeight=3" option helps the higherorder problems, probably by 
16670b4f0baa
set SPASS option on the commandline, so that it doesn't vanish when moving to TPTP format
blanchet
parents:
36190
diff
changeset

466 
counteracting the presence of "hAPP". *) 
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37480
diff
changeset

467 
val spass_config : prover_config = 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

468 
{home_var = "ISABELLE_ATP_MANAGER", 
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

469 
executable = "SPASS_TPTP", 
37550
fc2f979b9a08
split SPASS time slot between SOS and nonSOS, in case SOS times out
blanchet
parents:
37514
diff
changeset

470 
(* "div 2" accounts for the fact that SPASS is often run twice. *) 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

471 
arguments = fn complete => fn timeout => 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

472 
("Auto PGiven=0 PProblem=0 Splits=0 FullRed=0 DocProof \ 
37550
fc2f979b9a08
split SPASS time slot between SOS and nonSOS, in case SOS times out
blanchet
parents:
37514
diff
changeset

473 
\VarWeight=3 TimeLimit=" ^ 
fc2f979b9a08
split SPASS time slot between SOS and nonSOS, in case SOS times out
blanchet
parents:
37514
diff
changeset

474 
string_of_int (to_generous_secs timeout div 2)) 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

475 
> not complete ? prefix "SOS=1 ", 
36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

476 
proof_delims = [("Here is a proof", "Formulae used in the proof")], 
36289
f75b6a3e1450
set "atps" reference's default value to "(remote_)e (remote_)spass (remote_)vampire", based on what is installed
blanchet
parents:
36287
diff
changeset

477 
known_failures = 
37413  478 
[(IncompleteUnprovable, "SPASS beiseite: Completion found"), 
36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

479 
(TimedOut, "SPASS beiseite: Ran out of time"), 
36965  480 
(OutOfResources, "SPASS beiseite: Maximal number of loops exceeded"), 
37413  481 
(MalformedInput, "Undefined symbol"), 
37414
d0cea0796295
expect SPASS 3.7, and give a friendly warning if an older version is used
blanchet
parents:
37413
diff
changeset

482 
(MalformedInput, "Free Variable"), 
37962
d7dbe01f48d7
keep track of clause numbers for SPASS now that we generate FOF rather than CNF problems;
blanchet
parents:
37926
diff
changeset

483 
(OldSpass, "tptp2dfg")], 
36382  484 
max_axiom_clauses = 40, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

485 
prefers_theory_relevant = true, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

486 
explicit_forall = true} 
37414
d0cea0796295
expect SPASS 3.7, and give a friendly warning if an older version is used
blanchet
parents:
37413
diff
changeset

487 
val spass = tptp_prover "spass" spass_config 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

488 

37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

489 
(* Vampire *) 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

490 

f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

491 
val vampire_config : prover_config = 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

492 
{home_var = "VAMPIRE_HOME", 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

493 
executable = "vampire", 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

494 
arguments = fn _ => fn timeout => 
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

495 
"output_syntax tptp mode casc t " ^ 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

496 
string_of_int (to_generous_secs timeout), 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

497 
proof_delims = 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

498 
[("=========== Refutation ==========", 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

499 
"======= End of refutation ======="), 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

500 
("% SZS output start Refutation", "% SZS output end Refutation")], 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

501 
known_failures = 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

502 
[(Unprovable, "UNPROVABLE"), 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

503 
(IncompleteUnprovable, "CANNOT PROVE"), 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

504 
(Unprovable, "Satisfiability detected"), 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

505 
(OutOfResources, "Refutation not found")], 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

506 
max_axiom_clauses = 60, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

507 
prefers_theory_relevant = false, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

508 
explicit_forall = false} 
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

509 
val vampire = tptp_prover "vampire" vampire_config 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

510 

f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

511 
(* Remote prover invocation via SystemOnTPTP *) 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

512 

36376  513 
val systems = Synchronized.var "atp_systems" ([]: string list); 
31835  514 

515 
fun get_systems () = 

36370
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

516 
case bash_output "\"$ISABELLE_ATP_MANAGER/SystemOnTPTP\" w" of 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

517 
(answer, 0) => split_lines answer 
a4f601daa175
centralized ATPspecific error handling in "atp_wrapper.ML"
blanchet
parents:
36369
diff
changeset

518 
 (answer, _) => 
37627  519 
error ("Failed to get available systems at SystemOnTPTP:\n" ^ 
520 
perhaps (try (unsuffix "\n")) answer) 

31835  521 

35867  522 
fun refresh_systems_on_tptp () = 
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

523 
Synchronized.change systems (fn _ => get_systems ()) 
31835  524 

525 
fun get_system prefix = Synchronized.change_result systems (fn systems => 

32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

526 
(if null systems then get_systems () else systems) 
32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

527 
> `(find_first (String.isPrefix prefix))); 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

528 

32948  529 
fun the_system prefix = 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

530 
(case get_system prefix of 
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

531 
NONE => error ("System " ^ quote prefix ^ " not available at SystemOnTPTP.") 
32942
b6711ec9de26
misc tuning and recovery of Isabelle coding style;
wenzelm
parents:
32941
diff
changeset

532 
 SOME sys => sys); 
31835  533 

36265
41c9e755e552
distinguish between the different ATP errors in the user interface;
blanchet
parents:
36264
diff
changeset

534 
val remote_known_failures = 
37627  535 
[(CantConnect, "HTTPError"), 
536 
(TimedOut, "says Timeout"), 

36377
b3dce4c715d0
now rename the file "atp_wrapper.ML" to "atp_systems.ML" + fix typo in "SystemOnTPTP" script
blanchet
parents:
36376
diff
changeset

537 
(MalformedOutput, "Remote script could not extract proof")] 
35865  538 

37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

539 
fun remote_config atp_prefix args 
36382  540 
({proof_delims, known_failures, max_axiom_clauses, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

541 
prefers_theory_relevant, explicit_forall, ...} : prover_config) 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

542 
: prover_config = 
36917
8674cdb0b8cc
query _HOME environment variables at runtime, not at buildtime
blanchet
parents:
36910
diff
changeset

543 
{home_var = "ISABELLE_ATP_MANAGER", 
36289
f75b6a3e1450
set "atps" reference's default value to "(remote_)e (remote_)spass (remote_)vampire", based on what is installed
blanchet
parents:
36287
diff
changeset

544 
executable = "SystemOnTPTP", 
37514
b147d01b8ebc
if SPASS fails at finding a proof with the SOS option turned on, turn it off and try again
blanchet
parents:
37509
diff
changeset

545 
arguments = fn _ => fn timeout => 
36382  546 
args ^ " t " ^ string_of_int (to_generous_secs timeout) ^ " s " ^ 
547 
the_system atp_prefix, 

36369
d2cd0d04b8e6
handle ATP proof delimiters in a cleaner, more extensible fashion
blanchet
parents:
36289
diff
changeset

548 
proof_delims = insert (op =) tstp_proof_delims proof_delims, 
36265
41c9e755e552
distinguish between the different ATP errors in the user interface;
blanchet
parents:
36264
diff
changeset

549 
known_failures = remote_known_failures @ known_failures, 
36382  550 
max_axiom_clauses = max_axiom_clauses, 
37994
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

551 
prefers_theory_relevant = prefers_theory_relevant, 
b04307085a09
make TPTP generator accept full firstorder formulas
blanchet
parents:
37989
diff
changeset

552 
explicit_forall = explicit_forall} 
28596
fcd463a6b6de
tuned interfaces  plain prover function, without thread;
wenzelm
parents:
28592
diff
changeset

553 

37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

554 
fun remote_tptp_prover prover atp_prefix args config = 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

555 
tptp_prover (remotify (fst prover)) (remote_config atp_prefix args config) 
32864
a226f29d4bdc
reorganized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32740
diff
changeset

556 

37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

557 
val remote_e = remote_tptp_prover e "EP" "" e_config 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

558 
val remote_spass = remote_tptp_prover spass "SPASS" "x" spass_config 
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

559 
val remote_vampire = remote_tptp_prover vampire "Vampire9" "" vampire_config 
28592  560 

36917
8674cdb0b8cc
query _HOME environment variables at runtime, not at buildtime
blanchet
parents:
36910
diff
changeset

561 
fun maybe_remote (name, _) ({home_var, ...} : prover_config) = 
8674cdb0b8cc
query _HOME environment variables at runtime, not at buildtime
blanchet
parents:
36910
diff
changeset

562 
name > getenv home_var = "" ? remotify 
36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

563 

8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

564 
fun default_atps_param_value () = 
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

565 
space_implode " " [maybe_remote e e_config, maybe_remote spass spass_config, 
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

566 
remotify (fst vampire)] 
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

567 

37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37506
diff
changeset

568 
val provers = [e, spass, vampire, remote_e, remote_spass, remote_vampire] 
35867  569 
val prover_setup = fold add_prover provers 
570 

571 
val setup = 

36376  572 
dest_dir_setup 
35867  573 
#> problem_prefix_setup 
574 
#> measure_runtime_setup 

36371
8c83ea1a7740
move the Sledgehammer menu options to "sledgehammer_isar.ML"
blanchet
parents:
36370
diff
changeset

575 
#> prover_setup 
35867  576 

28592  577 
end; 