@@ -7,88 +7,126 @@ import lisa.utils.ProofsConverter.*
7
7
import lisa .utils .RunSolver .*
8
8
import lisa .utils .tptp .*
9
9
import lisa .utils .tptp .KernelParser .*
10
- import lisa .utils .tptp .ProblemGatherer .*
11
10
import lisa .kernel .proof .SCProof
12
11
import lisa .kernel .proof .SequentCalculus .Sequent
13
- import lisa .kernel . proof . SCProofChecker . checkSCProof
12
+ import lisa .utils . ProofsShrink . optimizeProofIteratively
14
13
15
14
object TPTPSolver extends lisa.Main {
16
- try {
17
- val spc = Seq (" PRP" , " FOF" ) // type of problems we want to extract and solve
18
- // val spc = Seq("PRP", "FOF", "CNF") // almost no CNF problems are solved by Tableau, TODO: investigate why
19
-
20
- // val d = new File(TPTPProblemPath)
21
- // val libraries = d.listFiles.filter(_.isDirectory)
22
- // val probfiles = libraries.flatMap(_.listFiles).filter(_.isFile)
23
-
24
- val d = new File (TPTPProblemPath + " SYN/" )
25
- val probfiles = d.listFiles.filter(_.isFile)
26
-
27
- // We limit the execution time to solve each problem
28
- val timeoutTableau = .1 .second
29
- val timeoutTautology = .1 .second
30
-
31
- var nbProblemsExtracted = 0
32
- var nbProblemsSolvedByTableau = 0
33
- var nbProblemsSolvedByTautology = 0
34
-
35
- for ((probfile, i) <- probfiles.zipWithIndex) {
36
- // Progress bar
37
- if ((i + 1 ) % 10 == 0 || i + 1 == probfiles.size) {
38
- val pbarLength = 30
39
- var pbarContent = " =" * (((i + 1 ) * pbarLength) / probfiles.size)
40
- pbarContent += " " * (pbarLength - pbarContent.length)
41
- print(s " [ $pbarContent] " )
42
- print(s " -- ${i + 1 }/ ${probfiles.size} processed files " )
43
- print(s " -- $nbProblemsExtracted extracted problems " )
44
- print(s " -- Tableau: $nbProblemsSolvedByTableau solved " )
45
- println(s " -- Tautology: $nbProblemsSolvedByTautology solved " )
46
- }
15
+ sealed trait ProofType
16
+ case object BySolver extends ProofType
17
+ case object Kernel extends ProofType
18
+ case object KernelOptimized extends ProofType
19
+
20
+ class ProblemSolverResults (val problem : Problem , val solverName : String , val solverStatus : String , val proofCode : String , val proofType : ProofType )
21
+
22
+ val exportOnlySolvedProblems = true
23
+ val exportOptimizedProofs = true
24
+ val exportBySolverProofs = true
25
+
26
+ val jsonResultsPath : String = " /home/auguste/Documents/EPFL/PhD/Projects/lisa/lisa-examples/src/main/resources/TPTPResults.json"
27
+ val TPTPProblemPath : String = " /home/auguste/Documents/EPFL/PhD/Projects/TPTP-v8.2.0/Problems/"
28
+
29
+ val spc = Seq (" PRP" , " FOF" ) // type of problems we want to extract and solve
30
+ // val spc = Seq("CNF") // almost no CNF problems are solved by Tableau, TODO: investigate why
31
+
32
+ // val d = new File(TPTPProblemPath)
33
+ // val libraries = d.listFiles.filter(_.isDirectory)
34
+ // val probfiles = libraries.flatMap(_.listFiles).filter(_.isFile)
35
+
36
+ val d = new File (TPTPProblemPath + " SYN/" )
37
+ val probfiles = d.listFiles.filter(_.isFile)
38
+
39
+ // We limit the execution time to solve each problem
40
+ val timeoutTableau = .1 .second
41
+ val timeoutTautology = .1 .second
47
42
48
- // Try to extract and solve the problem
49
- try {
50
- val md = getProblemInfos(probfile)
43
+ var nbProblemsExtracted = 0
44
+ var nbProblemsSolved = Map (" Tableau" -> 0 , " Tautology" -> 0 )
45
+ var nbInvalidProofs = Map (" Tableau" -> 0 , " Tautology" -> 0 )
46
+ var results = Seq .empty[ProblemSolverResults ]
47
+
48
+ for ((probfile, i) <- probfiles.zipWithIndex) {
49
+ // Progress bar
50
+ if ((i + 1 ) % 10 == 0 || i + 1 == probfiles.size) {
51
+ val pbarLength = 20
52
+ var pbarContent = " =" * (((i + 1 ) * pbarLength) / probfiles.size)
53
+ pbarContent += " " * (pbarLength - pbarContent.length)
54
+ print(s " [ $pbarContent] " )
55
+ print(s " -- ${i + 1 }/ ${probfiles.size} processed files " )
56
+ print(s " -- $nbProblemsExtracted extracted problems " )
57
+ print(s " -- Tableau: ${nbProblemsSolved(" Tableau" )} solved + ${nbInvalidProofs(" Tableau" )} invalid " )
58
+ println(s " -- Tautology: ${nbProblemsSolved(" Tautology" )} solved + ${nbInvalidProofs(" Tautology" )} invalid " )
59
+ }
60
+
61
+ // Try to extract and solve the problem
62
+ try {
63
+ val md = getProblemInfos(probfile)
64
+ if (! (md.spc.contains(" SAT" ))) {
51
65
if (md.spc.exists(spc.contains)) {
52
- val p = problemToKernel(probfile, md)
53
- val seq = problemToSequent(p )
66
+ val problem = problemToKernel(probfile, md)
67
+ val seq = problemToSequent(problem )
54
68
nbProblemsExtracted += 1
55
69
70
+ def exportResults (problem : Problem , solverName : String , solverResult : SolverResult ): Unit =
71
+ val solverStatus = solverResult.getClass.getSimpleName.stripSuffix(" $" )
72
+ solverResult match
73
+ case Solved (proof) =>
74
+ nbProblemsSolved += (solverName -> (nbProblemsSolved(solverName) + 1 ))
75
+ results :+= new ProblemSolverResults (problem, solverName, solverStatus, generateStandaloneTheoremFileContent(problem.name, proof), Kernel )
76
+ if (exportOptimizedProofs)
77
+ results :+= new ProblemSolverResults (problem, solverName, solverStatus, generateStandaloneTheoremFileContent(problem.name, optimizeProofIteratively(proof)), KernelOptimized )
78
+ if (exportBySolverProofs)
79
+ val statementString = any2code(seq)
80
+ val proofCode = s " have(thesis) by $solverName"
81
+ val symbolDeclarations = generateSymbolDeclarationCode(Set (K .sequentToFormula(seq)), " private" )
82
+ results :+= new ProblemSolverResults (problem, solverName, solverStatus, generateStandaloneTheoremFileContent(problem.name, statementString, proofCode, symbolDeclarations), BySolver )
83
+ case InvalidProof (proof) =>
84
+ nbInvalidProofs += (solverName -> (nbInvalidProofs(solverName) + 1 ))
85
+ if (! exportOnlySolvedProblems)
86
+ results :+= new ProblemSolverResults (problem, solverName, solverStatus, generateStandaloneTheoremFileContent(problem.name, proof), Kernel )
87
+ case _ =>
88
+ if (! exportOnlySolvedProblems)
89
+ results :+= new ProblemSolverResults (problem, solverName, solverStatus, " " , Kernel )
90
+
56
91
// Attempting proof by Tableau
57
- proveSequent(seq, timeoutTableau, Tableau .solve) match {
58
- case Solved (proof) =>
59
- if (checkSCProof(proof).isValid)
60
- nbProblemsSolvedByTableau += 1
61
- // writeProof(p, proof, "examples/proofs/tableau/")
62
- else throw new Exception (" Tableau proof is not valid" )
63
- case _ => ()
64
- }
92
+ val tableauResult = proveSequent(seq, timeoutTableau, Tableau .solve)
93
+ exportResults(problem, " Tableau" , tableauResult)
65
94
66
95
// Attempting proof by Tautology
67
96
def tautologySolver (s : lisa.utils.K .Sequent ): Option [SCProof ] = Tautology .solveSequent(s) match
68
97
case Left (proof) => Some (proof)
69
98
case _ => None
70
- proveSequent(seq, timeoutTautology, tautologySolver) match {
71
- case Solved (proof) =>
72
- if (checkSCProof(proof).isValid)
73
- nbProblemsSolvedByTautology += 1
74
- // writeProof(p, proof, "examples/proofs/tautology/")
75
- else throw new Exception (" Tautology proof is not valid" )
76
- case _ => ()
77
- }
99
+ val tautologyResult = proveSequent(seq, timeoutTautology, tautologySolver)
100
+ exportResults(problem, " Tautology" , tautologyResult)
78
101
}
79
- } catch {
80
- case e => println(s " Error while processing $probfile: $e" )
102
+ // } else println(s"Problem $probfile not extracted because of its type: ${md.spc.mkString(",")}")
81
103
}
82
- }
83
- } catch {
84
- case error : NullPointerException => println(" You can download the tptp library at http://www.tptp.org/ and put it in main/resources" )
104
+ } catch case e => println(s " Error while processing $probfile (index $i): $e" )
85
105
}
86
- }
87
106
88
- def writeProof (problem : Problem , proof : SCProof , path : String ): Unit = {
89
- val file = new File (path + problem.name + " .sc" )
90
- val bw = new FileWriter (file)
91
- val fileContent = generateStandaloneTheoremFileContent(problem.name, proof)
92
- bw.write(fileContent)
93
- bw.close()
107
+ // Write results to a JSON file
108
+ val jsonResultsFile = new File (jsonResultsPath)
109
+ if (! jsonResultsFile.getParentFile.exists())
110
+ jsonResultsFile.getParentFile.mkdirs()
111
+ val jsonWriter = new java.io.PrintWriter (jsonResultsPath)
112
+ ujson.writeTo(
113
+ results.map(r =>
114
+ ujson.Obj (
115
+ " problemName" -> r.problem.name,
116
+ " problemDomain" -> r.problem.domain,
117
+ " problemStatus" -> r.problem.status,
118
+ " problemSPC" -> r.problem.spc.mkString(" ," ),
119
+ " problemSequent" -> any2code(problemToSequent(r.problem)),
120
+ " problemFile" -> r.problem.file,
121
+ " solver" -> r.solverName,
122
+ " solverStatus" -> r.solverStatus,
123
+ " solverProofCode" -> r.proofCode,
124
+ " proofType" -> r.proofType.getClass.getSimpleName.stripSuffix(" $" )
125
+ )
126
+ ),
127
+ jsonWriter,
128
+ indent = 2
129
+ )
130
+ jsonWriter.close()
131
+
94
132
}
0 commit comments