-
Notifications
You must be signed in to change notification settings - Fork 3
/
leancop.sh
executable file
·162 lines (142 loc) · 4.89 KB
/
leancop.sh
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
#!/bin/sh
#-----------
# File: leancop.sh
# Version: 2.1
# Date: 3 July 2009
#-----------
# Purpose: Invokes the leanCoP prover
# Usage: ./leancop.sh <problem file> [<time limit>]
# Author: Jens Otten
# Web: www.leancop.de
# Copyright: (c) 2007-2009 by Jens Otten
# License: GNU General Public License
#-----------
#-----------
# Parameters
# set leanCoP prover path
PROVER_PATH=.
# set Prolog system, path, and options
#PROLOG=eclipse
#PROLOG_PATH=/usr/bin/eclipse
#PROLOG_OPTIONS='-e'
PROLOG=swi
PROLOG_PATH=/opt/local/bin/swipl
PROLOG_OPTIONS='-nodebug -L120M -G120M -T100M -q -t'
#PROLOG=sicstus
#PROLOG_PATH=/usr/bin/sicstus
#PROLOG_OPTIONS='--nologo --noinfo --goal'
# print proof [yes|no]
PRINT_PROOF=yes
# save proof [yes|no]
SAVE_PROOF=no
# proof layout [compact|connect|readable]
PROOF_LAYOUT=readable
# set TPTP library path
# TPTP=.
#----------
# Functions
leancop()
{
# Input: $SET, $COMP, $TIME_PC
TLIMIT=`expr $TIME_PC '*' $TIMELIMIT / 111`
if [ $TLIMIT -eq 0 ]; then TLIMIT=1; fi
$PROLOG_PATH $PROLOG_OPTIONS \
"assert(prolog('$PROLOG')),\
assert(proof('$PROOF_LAYOUT')),\
['$PROVER_PATH/leancop_main.pl'],\
leancop_main('$FILE',$SET,_),\
halt."\
> $OUTPUT &
PID=$!
CPU_SEC=0
trap "rm $OUTPUT; kill $PID >/dev/null 2>&1; exit 2"\
ALRM XCPU INT QUIT TERM
while [ $CPU_SEC -lt $TLIMIT ]
do
sleep 1
CPUTIME=`ps -p $PID -o time | grep :`
if [ ! -n "$CPUTIME" ]; then break; fi
CPU_H=`expr 1\`echo $CPUTIME | cut -d':' -f1\` - 100`
CPU_M=`expr 1\`echo $CPUTIME | cut -d':' -f2\` - 100`
CPU_S=`expr 1\`echo $CPUTIME | cut -d':' -f3\` - 100`
CPU_SEC=`expr 3600 '*' $CPU_H + 60 '*' $CPU_M + $CPU_S`
done
if [ -n "$CPUTIME" ]
then rm $OUTPUT; kill $PID >/dev/null 2>&1
else
RESULT1=`egrep ' Theorem| Unsatisfiable' $OUTPUT`
RESULT2=`egrep ' Non-Theorem| Satisfiable' $OUTPUT`
if [ -n "$RESULT1" -o -n "$RESULT2" ]
then
if [ $PRINT_PROOF = yes ]
then if [ -n "$RESULT1" -o $COMP = y ]; then cat $OUTPUT; fi
else if [ -n "$RESULT1" ]
then echo $RESULT1
else if [ -n "$RESULT2" -a $COMP = y ]
then echo $RESULT2; fi
fi
fi
if [ $SAVE_PROOF != yes -o -n "$RESULT2" -a $COMP = n ]
then rm $OUTPUT; else mv $OUTPUT $PROOF_FILE; fi
if [ -n "$RESULT1" ]; then exit 0; fi
if [ -n "$RESULT2" -a $COMP = y ]; then exit 1; fi
else rm $OUTPUT
fi
fi
}
#-------------
# Main Program
if [ $# -eq 0 -o $# -gt 2 ]; then
echo "Usage: $0 <problem file> [<time limit>]"
exit 2
fi
if [ ! -r "$1" ]; then
echo "Error: File $1 not found" >&2
exit 2
fi
if [ -n "`echo "$2" | grep '[^0-9]'`" ]; then
echo "Error: Time $2 is not a number" >&2
exit 2
fi
if [ $# -eq 1 ]
then TIMELIMIT=600
else TIMELIMIT=$2
fi
FILE=$1
PROOF_FILE=$FILE.proof
OUTPUT=TMP_OUTPUT_leancop_`date +%F_%T_%N`
set +m
# invoke leanCoP core prover with different settings SET
# for time TIME_PC [%]; COMP=y iff settings are complete
SET="[cut,comp(7)]"; COMP=y; TIME_PC=10; leancop
SET="[conj,def,cut]"; COMP=n; TIME_PC=15; leancop
SET="[nodef,scut,cut]"; COMP=n; TIME_PC=15; leancop
SET="[scut]"; COMP=n; TIME_PC=10; leancop
SET="[def,cut]"; COMP=n; TIME_PC=5; leancop
SET="[conj,nodef,cut]"; COMP=n; TIME_PC=4; leancop
SET="[def,scut,cut]"; COMP=n; TIME_PC=2; leancop
SET="[scut,cut]"; COMP=n; TIME_PC=2; leancop
SET="[conj,def]"; COMP=n; TIME_PC=1; leancop
SET="[reo(40),conj,nodef,scut,cut]"; COMP=n; TIME_PC=4; leancop
SET="[reo(42),def,scut,cut]"; COMP=n; TIME_PC=4; leancop
SET="[reo(12),def,scut,cut]"; COMP=n; TIME_PC=2; leancop
SET="[reo(72),def,scut,cut]"; COMP=n; TIME_PC=2; leancop
SET="[reo(39),nodef,cut]"; COMP=n; TIME_PC=2; leancop
SET="[reo(38),conj,def,cut]"; COMP=n; TIME_PC=2; leancop
SET="[reo(15),conj,def,cut]"; COMP=n; TIME_PC=2; leancop
SET="[reo(73),conj,def,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(57),conj,def,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(13),conj,nodef,scut,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(59),conj,nodef,scut,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(75),conj,nodef,scut,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(36),conj,nodef,scut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(16),conj,nodef,scut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(71),def,scut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(58),def,scut,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(76),def,scut,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(74),nodef,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(14),nodef,cut]"; COMP=n; TIME_PC=1; leancop
SET="[reo(37),nodef,scut]"; COMP=n; TIME_PC=1; leancop
SET="[def]"; COMP=y; TIME_PC=99; leancop
echo Timeout
exit 2