Repository navigation
Expand file tree
/
Copy pathInterpretByATP
More file actions
executable file
·216 lines (193 loc) · 6.78 KB
/
Copy pathInterpretByATP
File metadata and controls
executable file
·216 lines (193 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/perl -w
use strict "vars";
#--------------------------------------------------------------------------------------------------
my $TPTPDirectory = "/home/tptp";
if (exists($ENV{TPTP_HOME})) {
$TPTPDirectory = $ENV{TPTP_HOME};
}
if (! exists($ENV{TPTP})) {
$ENV{TPTP} = "$TPTPDirectory/TPTP";
}
if (! -d $ENV{TPTP}) {
die("ERROR: Cannot find TPTP directory\n");
}
my $TryToProve = "$TPTPDirectory/ServiceTools/TryToProve";
my $TPTP4X = "$TPTPDirectory/ServiceTools/tptp4X";
#----Global for use in END statements
my $GlobalTemporaryDirectory = "/tmp/InterpretByATP_$$";
my $GlobalInterrupted = 0;
my %GlobalOptions;
my $DefaultProver = "Vampire---4.0";
my $DefaultModelFinder = "iProver---SAT-2.0";
my $DefaultCPULimit = 10;
#--------------------------------------------------------------------------------------------------
DoMain();
#--------------------------------------------------------------------------------------------------
sub DoMain {
%GlobalOptions = (
"-q" => "1", #----Quietness
"-c" => "0", #----Be default the model is not complete
"-t" => $DefaultCPULimit,
"-p" => "1", #----Use prover
"-m" => "0", #----Use model finder
"-k" => undef, #----Don't keep temporary files
);
my $Key;
my $InterpretFile;
my $ConjectureFileOrFormula;
my $Prover;
my $ModelFinder;
#----Send QUIT signals to the right place
$SIG{'QUIT'} = 'QUITHandler';
$SIG{'XCPU'} = 'QUITHandler';
$SIG{'INT'} = 'QUITHandler';
$SIG{'ALRM'} = 'QUITHandler';
#----Send STDERR to STDOUT
close(STDERR);
open(STDERR,">&STDOUT");
#----Flush output
$| = 1;
#----Extract command line arguments
while (scalar(@ARGV) >= 2 && $ARGV[0] =~/-[a-z]/) {
$Key = shift(@ARGV);
if (length($Key) == 2) {
if (defined($ARGV[0])) {
$GlobalOptions{$Key} = shift(@ARGV);
} else {
Usage();
}
} else {
$GlobalOptions{substr($Key,0,2)} = substr($Key,2);
}
}
if (defined($GlobalOptions{'-k'})) {
$GlobalTemporaryDirectory = $GlobalOptions{'-k'};
}
system("mkdir -p $GlobalTemporaryDirectory");
END {
if (!defined($GlobalOptions{'-k'})) {
system("rm -rf $GlobalTemporaryDirectory");
}
}
#----Command line is interpretation file, problem file, optional ATP system
if (scalar(@ARGV) < 2 || ! -f ($InterpretFile = $ARGV[0])) {
Usage();
die("\n");
}
$ConjectureFileOrFormula = $ARGV[1];
#----Choose the prover and model finder
if ($GlobalOptions{'-p'} eq "0") {
$Prover = undef;
} elsif ($GlobalOptions{'-p'} eq "1") {
$Prover = $DefaultProver;
} else {
$Prover = $GlobalOptions{'-p'};
$GlobalOptions{'-p'} = "1";
}
if ($GlobalOptions{'-m'} eq "0") {
$ModelFinder = undef;
} elsif ($GlobalOptions{'-m'} eq "1") {
$ModelFinder = $DefaultModelFinder;
} else {
$ModelFinder = $GlobalOptions{'-m'};
$GlobalOptions{'-m'} = "1";
}
#----Convert all interpretation formulae to axioms
system("$TPTP4X -u machine $InterpretFile | sed -e '/^[cft][nofxh][f01](/s/,[^,]*,/,axiom,/' > $GlobalTemporaryDirectory/IBAInterpretationFile_$$");
Interpret("$GlobalTemporaryDirectory/IBAInterpretationFile_$$",$ConjectureFileOrFormula,
$Prover,$ModelFinder, $GlobalOptions{'-t'});
}
#--------------------------------------------------------------------------------------------------
sub Usage {
print("
Usage
InterpretByATP [-qN] [-c0/1] [-t N] [-p prover] [-m model_finder] [-k dir] model_file conjecture[_file]
");
}
#--------------------------------------------------------------------------------------------------
sub QUITHandler {
my ($Signal) = @_;
$GlobalInterrupted = 1;
if ($Signal eq 'INT' || $Signal eq 'QUIT') {
die("Terminated by ^C\n");
}
}
#--------------------------------------------------------------------------------------------------
sub Interpret {
my ($InterpretFile,$FileOrFormula,$Prover,$ModelFinder,$CPULimit) = @_;
my $FormulaName;
my $TryToProveCommand;
my $TryingLine;
my $ATPResult;
my $Result;
my $FromWhat;
my $AllResult = "Unknown";
my $NumberOfResults;
#----Set the role to conjecture
$TryToProveCommand = "$TryToProve -q0 -b1 -t $CPULimit ";
if (defined($Prover)) {
$TryToProveCommand .= " -p $Prover";
}
if (defined($ModelFinder)) {
$TryToProveCommand .= " -m $ModelFinder";
}
#----If complete then trust negative results
if ($GlobalOptions{'-c'}) {
$TryToProveCommand .= " -n 1";
}
$TryToProveCommand .= " $InterpretFile '$FileOrFormula'";
#DEBUG print("The command is ===$TryToProveCommand===\n");
open(TRYTOPROVE,"$TryToProveCommand |") || die("ERROR: Cannot start $TryToProveCommand\n");
$NumberOfResults = 0;
while (!$GlobalInterrupted && defined($TryingLine = <TRYTOPROVE>)) {
chomp($TryingLine);
QuietPrint($TryingLine,0);
#DEBUG print(">>>>=$TryingLine====\n");
if ($TryingLine =~ /SZS status/) {
$NumberOfResults++;
($ATPResult,$FormulaName,$FromWhat) =
($TryingLine =~ / SZS status ([^ ]*) for ([^ ]*) from ([^ ]*)/);
$Result = InterpretATPResult($ATPResult);
if ($FileOrFormula eq $FormulaName) {
$AllResult = $ATPResult;
} else {
QuietPrint("Proving result for $FormulaName is $Result",0);
print("% SZS status $Result for $FormulaName");
QuietPrint(" from $InterpretFile",0);
print("\n");
}
}
}
close(TRYTOPROVE);
if ($GlobalInterrupted) {
$AllResult = "Unknown";
}
if ($GlobalInterrupted || $NumberOfResults > 1) {
print("% SZS status $AllResult for $FileOrFormula");
QuietPrint(" from $InterpretFile",0);
print("\n");
}
}
#--------------------------------------------------------------------------------------------------
sub InterpretATPResult {
my ($Result) = @_;
if ($Result eq "Theorem") {
return("\$true");
} elsif ($Result eq "CounterSatisfiable" && $GlobalOptions{'-c'}) {
return("\$false");
} elsif ($Result eq "CounterTheorem") {
return("\$false");
} elsif ($Result eq "Satisfiable" && $GlobalOptions{'-c'}) {
return("\$true");
} else {
return("Unknown");
}
}
#--------------------------------------------------------------------------------------------------
sub QuietPrint {
my ($Message,$MaxQuietness) = @_;
if ($GlobalOptions{'-q'} <= $MaxQuietness) {
print("$Message\n");
}
}
#--------------------------------------------------------------------------------------------------