#!/bin/bash

# This script is taken from the CVC4 GitHub Repo and was slightly modified.
#
# CVC4 is copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 by its
# authors and contributors (see the file AUTHORS) and their institutional
# affiliations.  All rights reserved.
# 
# The source code of CVC4 is open and available to students, researchers,
# software companies, and everyone else to study, to modify, and to redistribute
# original or modified versions; distribution is under the terms of the modified
# BSD license (reproduced below).  Please note that CVC4 can be configured
# (however, by default it is not) to link against some GPLed libraries, and
# therefore the use of these builds may be restricted in non-GPL-compatible
# projects.  See below for a discussion of CLN, GLPK, and Readline (the three
# GPLed optional library dependences for CVC4), and how to ensure you have a
# build that doesn't link against GPLed libraries.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# 3. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT OWNERS AND CONTRIBUTORS
# ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cvc4="$1"
bench="$2"

echo "cvc4 is $cvc4"
echo "bench is $bench"

file=${bench##*/}
filename=${file%.*}

echo "------- cvc4-tfa casc j8 : $bench at ..."

# use: trywith [params..]
# to attempt a run.  If an SZS ontology result is printed, then
# the run script terminates immediately.  Otherwise, this
# function returns normally.
function trywith {
  limit=$1; shift;
  echo "--- Run $@ at $limit...";
  (ulimit -S -t "$limit";$cvc4 --lang=tptp --no-checking --no-interactive --force-logic="UFNIRA" --dump-instantiations --inst-format=szs --force-no-limit-cpu-while-dump "$@" $bench) 2>/dev/null |
  (read w1 w2 w3 result w4 w5;
  case "$result" in
  Unsatisfiable) echo "$w1 $w2 $w3 $result $w4 $w5";cat;exit 0;;
  Theorem) echo "$w1 $w2 $w3 $result $w4 $w5";cat;exit 0;;
  esac; exit 1)
  if [ ${PIPESTATUS[1]} -eq 0 ]; then exit 0; fi
}
function finishwith {
  echo "--- Run $@...";
  $cvc4 --lang=tptp --no-checking --no-interactive --force-logic="UFNIRA" --dump-instantiations --inst-format=szs --force-no-limit-cpu-while-dump "$@" $bench
}

trywith 5 --decision=internal --full-saturate-quant
trywith 5 --finite-model-find --decision=internal
trywith 5 --purify-quant --full-saturate-quant
trywith 5 --partial-triggers --full-saturate-quant
trywith 5 --no-e-matching --full-saturate-quant
trywith 5 --cbqi-all --purify-triggers --full-saturate-quant
trywith 5 --cbqi-all --fs-inst --full-saturate-quant
finishwith --full-saturate-quant
# echo "% SZS status" "GaveUp for $filename"
