From 0a7e733a5cee4733ca8ca9fff1f6eab6fc22a549 Mon Sep 17 00:00:00 2001 From: Gereon Kremer Date: Fri, 17 Jul 2020 09:06:31 +0200 Subject: [PATCH] Integration of libpoly (#4679) This commit integrates LibPoly into CVC4. It adds `contrib/get-poly`, adds it to the configure script, cmake and places where CVC4 inspects its own build configuration. Furthermore, it adds `CVC4::RealAlgebraicNumber` (which wraps `poly::AlgebraicNumber`) including some basic unit tests and some utilities. --- .github/workflows/ci.yml | 2 + CMakeLists.txt | 17 ++ COPYING | 2 +- INSTALL.md | 8 +- cmake/FindPoly.cmake | 24 ++ configure.sh | 14 + contrib/get-poly | 31 ++ src/CMakeLists.txt | 7 + src/base/configuration.cpp | 13 +- src/base/configuration.h | 2 + src/base/configuration_private.h | 6 + src/options/options_handler.cpp | 1 + src/util/CMakeLists.txt | 7 + src/util/poly_util.cpp | 282 +++++++++++++++++++ src/util/poly_util.h | 136 +++++++++ src/util/real_algebraic_number.h.in | 25 ++ src/util/real_algebraic_number_poly_imp.cpp | 175 ++++++++++++ src/util/real_algebraic_number_poly_imp.h | 160 +++++++++++ test/unit/CMakeLists.txt | 4 + test/unit/util/CMakeLists.txt | 3 + test/unit/util/real_algebraic_number_black.h | 83 ++++++ 21 files changed, 998 insertions(+), 4 deletions(-) create mode 100644 cmake/FindPoly.cmake create mode 100755 contrib/get-poly create mode 100644 src/util/poly_util.cpp create mode 100644 src/util/poly_util.h create mode 100644 src/util/real_algebraic_number.h.in create mode 100644 src/util/real_algebraic_number_poly_imp.cpp create mode 100644 src/util/real_algebraic_number_poly_imp.h create mode 100644 test/unit/util/real_algebraic_number_black.h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da97a2cd2..7dd080f71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,6 +99,7 @@ jobs: if: steps.restore-deps.outputs.cache-hit != 'true' run: | ./contrib/get-antlr-3.4 + ./contrib/get-poly ./contrib/get-symfpu ./contrib/get-cadical ./contrib/get-cryptominisat @@ -136,6 +137,7 @@ jobs: run: | ${{ matrix.env }} ./configure.sh ${{ matrix.config }} \ --python3 \ + --poly \ --prefix=$(pwd)/build/install \ --unit-testing diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d5ffc68f..f4aa6c611 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,9 @@ endif() if(LFSC_DIR) list(APPEND CMAKE_PREFIX_PATH "${LFSC_DIR}") endif() +if(POLY_DIR) + list(APPEND CMAKE_PREFIX_PATH "${POLY_DIR}") +endif() if(SYMFPU_DIR) list(APPEND CMAKE_PREFIX_PATH "${SYMFPU_DIR}") endif() @@ -141,6 +144,7 @@ cvc4_option(USE_READLINE "Use readline for better interactive support") # > for options where we don't need to detect if set by user (default: OFF) option(USE_DRAT2ER "Include drat2er for making eager BV proofs") option(USE_LFSC "Use LFSC proof checker") +option(USE_POLY "Use LibPoly for polynomial arithmetic") option(USE_SYMFPU "Use SymFPU for floating point support") option(USE_PYTHON2 "Prefer using Python 2 (for Python bindings)") option(USE_PYTHON3 "Prefer using Python 3 (for Python bindings)") @@ -160,6 +164,7 @@ set(GLPK_DIR "" CACHE STRING "Set GLPK install directory") set(GMP_DIR "" CACHE STRING "Set GMP install directory") set(KISSAT_DIR "" CACHE STRING "Set Kissat install directory") set(LFSC_DIR "" CACHE STRING "Set LFSC install directory") +set(POLY_DIR "" CACHE STRING "Set LibPoly install directory") set(SYMFPU_DIR "" CACHE STRING "Set SymFPU install directory") # Prepend binaries with prefix on make install @@ -501,6 +506,14 @@ if(USE_LFSC) add_definitions(-DCVC4_USE_LFSC) endif() +if(USE_POLY) + find_package(Poly REQUIRED) + add_definitions(-DCVC4_USE_POLY) + set(CVC4_USE_POLY_IMP 1) +else() + set(CVC4_USE_POLY_IMP 0) +endif() + if(USE_READLINE) set(GPL_LIBS "${GPL_LIBS} readline") find_package(Readline REQUIRED) @@ -687,6 +700,7 @@ print_config("drat2er :" USE_DRAT2ER) print_config("GLPK :" USE_GLPK) print_config("Kissat :" USE_KISSAT) print_config("LFSC :" USE_LFSC) +print_config("LibPoly :" USE_POLY) if(CVC4_USE_CLN_IMP) message("MP library : cln") @@ -723,6 +737,9 @@ endif() if(LFSC_DIR) message("LFSC dir : ${LFSC_DIR}") endif() +if(POLY_DIR) + message("LibPoly dir : ${POLY_DIR}") +endif() if(SYMFPU_DIR) message("SYMFPU dir : ${SYMFPU_DIR}") endif() diff --git a/COPYING b/COPYING index d4fc07ed2..e0d15cf03 100644 --- a/COPYING +++ b/COPYING @@ -79,6 +79,7 @@ CVC4 optionally links against the following libraries: CaDiCaL (https://github.com/arminbiere/cadical) CryptoMiniSat (https://github.com/msoos/cryptominisat) LFSC checker (https://github.com/CVC4/LFSC) + LibPoly (https://github.com/SRI-CSL/libpoly) Linking CVC4 against these libraries does not affect the license terms of the CVC4 code. See the respective projects for copyright and licensing @@ -111,4 +112,3 @@ CVC4 can be optionally configured to link against GNU Readline for improved text-editing support in interactive mode. GNU Readline is available here: http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html - diff --git a/INSTALL.md b/INSTALL.md index ae22e2d71..2c73827c1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -129,6 +129,12 @@ dependency. with --check-proofs. It can be installed using the `contrib/get-lfsc` script. Configure CVC4 with `configure.sh --lfsc` to build with this dependency. +### LibPoly (Optional polynomial library) + +[LibPoly](https://github.com/SRI-CSL/libpoly) is required for CAD-based nonlinear reasoning. +It can be installed using the `contrib/get-poly` script. +Configure CVC4 with `configure.sh --poly` to build with this dependency. + ### CLN >= v1.3 (Class Library for Numbers) [CLN](http://www.ginac.de/CLN) @@ -317,5 +323,3 @@ are configured to **run** in parallel with the maximum number of threads available on the system. Override with `ARGS=-jN`. Use `-jN` for parallel **building** with `N` threads. - - diff --git a/cmake/FindPoly.cmake b/cmake/FindPoly.cmake new file mode 100644 index 000000000..5f4383732 --- /dev/null +++ b/cmake/FindPoly.cmake @@ -0,0 +1,24 @@ +# Find LibPoly +# POLY_FOUND - system has LibPoly +# POLY_INCLUDE_DIR - the LibPoly include directory +# POLY_LIBRARIES - Libraries needed to use LibPoly + +# Note: contrib/get-poly copies header files to deps/install/include/poly. +# However, includes in LibPoly headers are not prefixed with "poly/" and therefore +# we have to look for headers in include/poly instead of include/. +find_path(POLY_INCLUDE_DIR NAMES poly/poly.h PATH_SUFFIXES poly) +find_library(POLY_LIB NAMES poly) +find_library(POLY_LIBXX NAMES polyxx) +set(POLY_LIBRARIES "${POLY_LIBXX};${POLY_LIB}") +unset(POLY_LIB CACHE) +unset(POLY_LIBXX CACHE) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Poly + DEFAULT_MSG + POLY_INCLUDE_DIR POLY_LIBRARIES) + +mark_as_advanced(POLY_INCLUDE_DIR POLY_LIBRARIES) +if(POLY_LIBRARIES) + message(STATUS "Found LibPoly: ${POLY_LIBRARIES}") +endif() diff --git a/configure.sh b/configure.sh index 988b7a392..f720e67c2 100755 --- a/configure.sh +++ b/configure.sh @@ -62,6 +62,7 @@ The following flags enable optional packages (disable with --no-