Disable regression if poly is not available (#7981)
[cvc5.git] / contrib / get-lfsc-checker
1 #!/usr/bin/env bash
2
3 # utility function to download a file
4 function download {
5 if [ -x "$(command -v wget)" ]; then
6 wget -c -O "$2" "$1"
7 elif [ -x "$(command -v curl)" ]; then
8 curl -L "$1" >"$2"
9 else
10 echo "Can't figure out how to download from web. Please install wget or curl." >&2
11 exit 1
12 fi
13 }
14
15 CVC_DIR=$(dirname $(dirname "$0"))
16 mkdir -p $CVC_DIR/deps
17 pushd $CVC_DIR/deps
18
19 BASE_DIR=`pwd`
20 mkdir -p $BASE_DIR/tmp/
21
22 ##### LFSC
23 LFSC_DIR="$BASE_DIR/lfsc-checker"
24 mkdir -p $LFSC_DIR
25
26 # download and unpack LFSC
27 version="15f53d6feb84e4ddb41deaf2b5630f5c1303b06d"
28 download "https://github.com/cvc5/LFSC/archive/$version.tar.gz" $BASE_DIR/tmp/lfsc.tgz
29 tar --strip 1 -xzf $BASE_DIR/tmp/lfsc.tgz -C $LFSC_DIR
30
31 # build and install LFSC
32 pushd $LFSC_DIR
33 mkdir -p build && cd build
34 cmake -DCMAKE_INSTALL_PREFIX="$BASE_DIR" ..
35 make install
36 popd
37
38 ##### signatures
39
40 # The LFSC signatures live in the main cvc5 repository
41 SIG_DIR="$BASE_DIR/../proofs/lfsc/signatures"
42
43 # install signatures and scripts
44 mkdir -p $BASE_DIR/share/lfsc
45 cp -r $SIG_DIR $BASE_DIR/share/lfsc
46
47 # based on https://github.com/CVC4/signatures/blob/master/lfsc/new/scripts/cvc4_gen_and_check.sh
48 cat << EOF > $BASE_DIR/bin/cvc5-lfsc-check.sh
49 #!/bin/bash
50
51 echo "=== Generate proof: \$@"
52 $BASE_DIR/bin/cvc5-proof.sh \$@ > proof.plf
53
54 echo "=== Check proof with LFSC"
55 $BASE_DIR/bin/lfsc-check.sh proof.plf
56 EOF
57 chmod +x $BASE_DIR/bin/cvc5-lfsc-check.sh
58
59 # based on https://github.com/CVC4/signatures/blob/master/lfsc/new/scripts/cvc4_gen.sh
60 cat << EOF > $BASE_DIR/bin/cvc5-proof.sh
61 #!/bin/bash
62
63 # call cvc5 and remove the first line of the output (should be "unsat")
64 \$@ --dump-proofs --proof-format=lfsc | tail -n +2
65 EOF
66 chmod +x $BASE_DIR/bin/cvc5-proof.sh
67
68 # based on https://github.com/CVC4/signatures/blob/master/lfsc/new/scripts/lfsc_check.sh
69 cat << EOF > $BASE_DIR/bin/lfsc-check.sh
70 #!/bin/bash
71
72 cat \$@ | grep WARNING
73 CHECK=\$(cat \$@ | grep check)
74 [ -z "\$CHECK" ] && echo "; WARNING: Empty proof!!!"
75
76 SIG_DIR=$BASE_DIR/share/lfsc/signatures
77 SIGS="\$SIG_DIR/core_defs.plf \\
78 \$SIG_DIR/util_defs.plf \\
79 \$SIG_DIR/theory_def.plf \\
80 \$SIG_DIR/nary_programs.plf \\
81 \$SIG_DIR/boolean_programs.plf \\
82 \$SIG_DIR/boolean_rules.plf \\
83 \$SIG_DIR/cnf_rules.plf \\
84 \$SIG_DIR/equality_rules.plf \\
85 \$SIG_DIR/arith_programs.plf \\
86 \$SIG_DIR/arith_rules.plf \\
87 \$SIG_DIR/strings_programs.plf \\
88 \$SIG_DIR/strings_rules.plf \\
89 \$SIG_DIR/quantifiers_rules.plf"
90 $BASE_DIR/bin/lfscc \$SIGS \$@ >& lfsc.out
91
92 # recover macros for applications of arity 1,2,3, and simplify builtin syntax for constants
93 #sed -i.orig 's/(f_ite [^ \)]*)/f_ite/g' lfsc.out
94 sed -i.orig 's/(\\ [^ ]* (\\ [^ ]* (\\ [^ ]* (apply (apply (apply f_\([^ ]*\) [^ ]*) [^ ]*) [^ ]*))))/\1/g; s/(\\ [^ ]* (\\ [^ ]* (apply (apply f_\([^ ]*\) [^ ]*) [^ ]*)))/\1/g; s/(\\ [^ ]* (apply f_\([^ ]*\) [^ ]*))/\1/g; s/(var \([^ ]*\) [^ \)]*)/var_\1/g; s/(int \([^ \)]*\))/\1/g; s/emptystr/""/g; s/int\.//g' lfsc.out
95
96 cat lfsc.out
97 rm lfsc.out
98 EOF
99 chmod +x $BASE_DIR/bin/lfsc-check.sh
100
101 popd
102
103 echo ""
104 echo "========== How to use LFSC =========="
105 echo "Generate a LFSC proof with cvc5:"
106 echo " $CVC_DIR/deps/bin/cvc5-proof.sh cvc5 <options> <input file>"
107 echo "Check a generated proof:"
108 echo " $CVC_DIR/deps/bin/lfsc-check.sh <proof file>"
109 echo "Run cvc5 and check the generated proof:"
110 echo " $CVC_DIR/deps/bin/cvc5-lfsc-check.sh cvc5 <options> <input file>"