@@ -2,71 +2,108 @@ import scala.concurrent.duration._
2
2
import scala .concurrent .ExecutionContext .Implicits .global
3
3
import scala .concurrent ._
4
4
import java .util .concurrent .CancellationException
5
+ import java .io .File
5
6
6
- import lisa .utils .tptp .Example .*
7
- import lisa .utils .tptp .KernelParser .annotatedFormulaToKernel
8
- import lisa .utils .tptp .KernelParser .parseToKernel
9
- import lisa .utils .tptp .KernelParser .problemToSequent
10
- import lisa .utils .tptp .ProblemGatherer .getPRPproblems
7
+ import lisa .utils .tptp .*
8
+ import lisa .utils .tptp .KernelParser .*
9
+ import lisa .utils .tptp .KernelParser .getProblemInfos
10
+ import lisa .utils .tptp .ProblemGatherer .*
11
11
import lisa .utils .ProofsConverter .*
12
+ import lisa .kernel .proof .SCProof
13
+ import java .io .FileWriter
14
+ import lisa .kernel .proof .SequentCalculus .Sequent
12
15
13
16
object TPTPSolver extends lisa.Main {
14
17
try {
15
- println( " Fetching problems from TPTP library... " )
16
- val probs = getPRPproblems
18
+ val spc = Seq ( " PRP " , " FOF " ) // type of problems we want to extract and solve
19
+ // val spc = Seq("PRP", "FOF", "CNF") // almost no CNF problems are solved by Tableau, TODO: investigate why
17
20
18
- println(" Number of problems found: " + probs.size)
21
+ // val d = new File(TPTPProblemPath)
22
+ // val libraries = d.listFiles.filter(_.isDirectory)
23
+ // val probfiles = libraries.flatMap(_.listFiles).filter(_.isFile)
24
+
25
+ val d = new File (TPTPProblemPath + " SYN/" )
26
+ val probfiles = d.listFiles.filter(_.isFile)
19
27
20
28
// We limit the execution time to solve each problem
21
- val timeoutTableau = 1 .second
22
- val timeoutTautology = 1 .second
29
+ val timeoutTableau = .2 .second
30
+ val timeoutTautology = .2 .second
23
31
24
- var tableauProofs = List [Option [SCProof ]]()
25
- var tautologyProofs = List [Option [SCProof ]]()
32
+ var problems = List [Problem ]()
33
+ var tableauProofs = List [SolverResult ]()
34
+ var tautologyProofs = List [SolverResult ]()
26
35
27
- for ((p , i) <- probs .zipWithIndex) {
36
+ for ((probfile , i) <- probfiles .zipWithIndex) {
28
37
// Progress bar
29
- if ((i + 1 ) % 10 == 0 || i + 1 == probs .size) {
38
+ if ((i + 1 ) % 10 == 0 || i + 1 == probfiles .size) {
30
39
val pbarLength = 30
31
- var pbarContent = " =" * (((i + 1 ) * pbarLength) / probs .size)
40
+ var pbarContent = " =" * (((i + 1 ) * pbarLength) / probfiles .size)
32
41
pbarContent += " " * (pbarLength - pbarContent.length)
33
42
print(" [" + pbarContent + " ]" )
34
- print(" -- Processed " + (i + 1 ) + " /" + probs.size)
35
- print(" -- " + tableauProofs.count(_.isDefined) + " solved by Tableau" )
36
- println(" -- " + tautologyProofs.count(_.isDefined) + " solved by Tautology" )
43
+ print(" -- " + (i + 1 ) + " /" + probfiles.size + " processed files" )
44
+ print(" -- " + problems.size + " extracted problems" )
45
+ print(" -- Tableau: " + tableauProofs.count(_.isInstanceOf [Solved ]) + " solved" )
46
+ println(" -- Tautology: " + tautologyProofs.count(_.isInstanceOf [Solved ]) + " solved" )
37
47
}
38
48
39
- val seq = problemToSequent(p)
40
-
41
- // Attempting proof by Tableau
42
- val (futureTableau, cancelTableau) = Future .interruptibly { Tableau .solve(seq) }
43
- tableauProofs = tableauProofs :+ (
44
- try Await .result(futureTableau, timeoutTableau)
45
- catch
46
- case _ =>
47
- cancelTableau()
48
- None
49
- )
50
-
51
- // Attempting proof by Tautology
52
- val (futureTautology, cancelTautology) = Future .interruptibly {
53
- Tautology .solveSequent(seq) match
54
- case Left (proof) => Some (proof)
55
- case _ => None
49
+ // Try to extract the problem
50
+ try {
51
+ val md = getProblemInfos(probfile)
52
+ if (md.spc.exists(spc.contains)) {
53
+ val p = problemToKernel(probfile, md)
54
+ problems = problems :+ p
55
+ val seq = problemToSequent(p)
56
+
57
+ // Attempting proof by Tableau
58
+ tableauProofs = tableauProofs :+ solveProblem(p, timeoutTableau, Tableau .solve)
59
+
60
+ // Attempting proof by Tautology
61
+ def tautologySolver (s : lisa.utils.K .Sequent ): Option [SCProof ] = Tautology .solveSequent(s) match
62
+ case Left (proof) => Some (proof)
63
+ case _ => None
64
+ tautologyProofs = tautologyProofs :+ solveProblem(p, timeoutTautology, tautologySolver)
65
+ }
66
+ } catch {
67
+ case _ => ()
56
68
}
57
- tautologyProofs = tautologyProofs :+ (
58
- try Await .result(futureTautology, timeoutTautology)
59
- catch
60
- case _ =>
61
- cancelTautology()
62
- None
63
- )
69
+
64
70
}
65
71
} catch {
66
72
case error : NullPointerException => println(" You can download the tptp library at http://www.tptp.org/ and put it in main/resources" )
67
73
}
68
74
}
69
75
76
+ sealed trait SolverResult
77
+ case class Solved (proof : SCProof ) extends SolverResult
78
+ case object Unsolved extends SolverResult
79
+ case object Timeout extends SolverResult
80
+ case object Error extends SolverResult
81
+
82
+ def solveProblem (problem : Problem , timeout : FiniteDuration , solver : Sequent => Option [SCProof ]): SolverResult = {
83
+ val seq = problemToSequent(problem)
84
+ val (futureSolver, cancelSolver) = Future .interruptibly { solver(seq) }
85
+ try
86
+ Await .result(futureSolver, timeout) match
87
+ case Some (proof) => Solved (proof)
88
+ case None => Unsolved
89
+ catch
90
+ case e : TimeoutException =>
91
+ cancelSolver()
92
+ Timeout
93
+ case _ =>
94
+ cancelSolver()
95
+ Error
96
+ }
97
+
98
+ def writeProof (problem : Problem , proof : SCProof , path : String ): Unit = {
99
+ // TODO
100
+ val file = new File (path + problem.name + " .sc" )
101
+ val bw = new FileWriter (file)
102
+ val proofCode = scproof2code(proof)
103
+ bw.write(proof.toString)
104
+ bw.close()
105
+ }
106
+
70
107
final class Interrupt extends (() => Boolean ) {
71
108
// We need a state-machine to track the progress.
72
109
// It can have the following states:
0 commit comments