Debian Codegraph @

contrib/get-lfsc-checker

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