Skip to content

Commit

Permalink
Merge branch 'development' into 'master'
Browse files Browse the repository at this point in the history
Development

See merge request ths/smt/carl!28
  • Loading branch information
derjasper committed Apr 26, 2024
2 parents 64b7e0c + 45a2501 commit b67f7ca
Show file tree
Hide file tree
Showing 35 changed files with 1,147 additions and 920 deletions.
6 changes: 3 additions & 3 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mkdir -p build || return 1
cd build/ || return 1
cmake -D DEVELOPER=ON -D USE_BLISS=ON -D USE_COCOA=ON ../ || return 1
cmake -D DEVELOPER=ON -D USE_BLISS=ON -D USE_COCOA=ON -D USE_LIBPOLY=ON ../ || return 1

function keep_waiting() {
while true; do
Expand Down Expand Up @@ -61,11 +61,11 @@ elif [[ ${TASK} == "documentation" ]]; then
git push -f origin master || return 1

elif [[ ${TASK} == "tidy" ]]; then

/usr/bin/time make ${MAKE_PARALLEL} tidy || return 1

elif [[ ${TASK} == "parallel" ]]; then
elif [[ ${TASK} == "all" ]]; then
/usr/bin/time make ${MAKE_PARALLEL} || return 1

else
/usr/bin/time make || return 1
fi
29 changes: 16 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,71 @@ cache:
#policy: pull-push

stages:
- build-gcc
- build-clang
- build
- test
- documentation

build-gcc12:
dependencies: []
stage: build-gcc
stage: build
script:
- export CC=/usr/bin/gcc-12 && export CXX=/usr/bin/g++-12
- MAKE_PARALLEL=-j8 TASK=parallel source .ci/build.sh
- MAKE_PARALLEL=-j8 TASK=all source .ci/build.sh
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- build/
- cmake/
- src/
expire_in: 1 week

build-gcc11:
.build-gcc11:
dependencies: []
stage: build-gcc
stage: build
script:
- export CC=/usr/bin/gcc-11 && export CXX=/usr/bin/g++-11
- MAKE_PARALLEL=-j8 TASK=parallel source .ci/build.sh
- MAKE_PARALLEL=-j8 TASK=all source .ci/build.sh
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- build/
- cmake/
- src/
expire_in: 1 week
only:
- development

build-clang14:
dependencies: []
stage: build-clang
stage: build
script:
- export CC=/usr/bin/clang-14 && export CXX=/usr/bin/clang++-14
- MAKE_PARALLEL=-j8 TASK=parallel source .ci/build.sh
- MAKE_PARALLEL=-j8 TASK=all source .ci/build.sh
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- build/
- cmake/
- src/
expire_in: 1 week

build-clang13:
.build-clang13:
dependencies: []
stage: build-clang
stage: build
script:
- export CC=/usr/bin/clang-13 && export CXX=/usr/bin/clang++-13
- MAKE_PARALLEL=-j8 TASK=parallel source .ci/build.sh
- MAKE_PARALLEL=-j8 TASK=all source .ci/build.sh
artifacts:
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- build/
- cmake/
- src/
expire_in: 1 week
only:
- development

test-clang:
.test-clang:
dependencies: [build-clang14]
stage: test
script:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include(carlmacros)

set(PROJECT_FULLNAME "carl")
set(PROJECT_DESCRIPTION "Computer ARithmetic Library")
set_version(24 02)
set_version(24 04)
message(STATUS "Version: ${PROJECT_FULLNAME} ${PROJECT_VERSION_FULL}")

# # # # # # # # # # # # # # # # # # # # # #
Expand Down
62 changes: 33 additions & 29 deletions cmake/FindPoly.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ if(NOT FORCE_SHIPPED_RESOURCES)
find_path(LIBPOLY_INCLUDE_DIR NAMES poly/poly.h)
find_library(LIBPOLY_SHARED NAMES poly${DYNAMIC_EXT})
find_library(LIBPOLY_STATIC NAMES poly${STATIC_EXT})
find_library(LIBPOLYXX_SHARED NAMES polyxx${DYNAMIC_EXT})
find_library(LIBPOLYXX_STATIC NAMES polyxx${STATIC_EXT})
# find_library(LIBPOLYXX_SHARED NAMES polyxx${DYNAMIC_EXT})
# find_library(LIBPOLYXX_STATIC NAMES polyxx${STATIC_EXT})
endif()

set(LIBPOLY_FOUND_SYSTEM FALSE)

if(LIBPOLY_INCLUDE_DIR AND LIBPOLY_SHARED AND LIBPOLY_STATIC AND LIBPOLYXX_SHARED AND LIBPOLYXX_STATIC)
if(LIBPOLY_INCLUDE_DIR AND LIBPOLY_SHARED AND LIBPOLY_STATIC) # AND LIBPOLYXX_SHARED AND LIBPOLYXX_STATIC)
#message(STATUS "Found libpoly: ${LIBPOLY_INCLUDE_DIR} ${LIBPOLY_SHARED} ${LIBPOLY_STATIC} ${LIBPOLYXX_SHARED} ${LIBPOLYXX_STATIC}")
#set(LIBPOLY_FOUND_SYSTEM TRUE)
#TODO: Somehow this does not work, so we use the shipped version for now
Expand All @@ -21,8 +21,11 @@ if(NOT LIBPOLY_FOUND_SYSTEM)
ExternalProject_Add(
LIBPOLY-EP
GIT_REPOSITORY https://github.com/SRI-CSL/libpoly
GIT_TAG v0.1.13
PATCH_COMMAND git reset --hard
COMMAND git apply ${CMAKE_SOURCE_DIR}/cmake/patches/libpoly_variable_db.patch
# UPDATE_COMMAND ""
COMMAND git apply ${CMAKE_SOURCE_DIR}/cmake/patches/libpoly.patch
# PATCH_COMMAND git apply ${CMAKE_SOURCE_DIR}/cmake/patches/libpoly.patch
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DLIBPOLY_BUILD_PYTHON_API=OFF
Expand All @@ -31,13 +34,13 @@ if(NOT LIBPOLY_FOUND_SYSTEM)
-DGMP_INCLUDE_DIR=${GMP_LIBRARY_DIR}
-DGMP_LIBRARY=${GMP_LIB}
BUILD_COMMAND ${CMAKE_COMMAND} <SOURCE_DIR>
COMMAND ${CMAKE_MAKE_PROGRAM} poly polyxx static_poly static_polyxx static_pic_poly static_pic_polyxx
COMMAND ${CMAKE_MAKE_PROGRAM} poly static_poly static_pic_poly polyxx static_polyxx static_pic_polyxx
COMMAND ${CMAKE_MAKE_PROGRAM} install
BUILD_BYPRODUCTS
<INSTALL_DIR>/lib/libpoly${STATIC_EXT}
<INSTALL_DIR>/lib/libpoly${DYNAMIC_EXT}
<INSTALL_DIR>/lib/libpolyxx${STATIC_EXT}
<INSTALL_DIR>/lib/libpolyxx${DYNAMIC_EXT}
# <INSTALL_DIR>/lib/libpolyxx${STATIC_EXT}
# <INSTALL_DIR>/lib/libpolyxx${DYNAMIC_EXT}
)
# ExternalProject_Add_Step(
# LIBPOLY-EP cleanup
Expand All @@ -53,8 +56,8 @@ if(NOT LIBPOLY_FOUND_SYSTEM)

set(LIBPOLY_SHARED "${CMAKE_BINARY_DIR}/resources/lib/libpoly${DYNAMIC_EXT}")
set(LIBPOLY_STATIC "${CMAKE_BINARY_DIR}/resources/lib/libpoly${STATIC_EXT}")
set(LIBPOLYXX_SHARED "${CMAKE_BINARY_DIR}/resources/lib/libpolyxx${DYNAMIC_EXT}")
set(LIBPOLYXX_STATIC "${CMAKE_BINARY_DIR}/resources/lib/libpolyxx${STATIC_EXT}")
# set(LIBPOLYXX_SHARED "${CMAKE_BINARY_DIR}/resources/lib/libpolyxx${DYNAMIC_EXT}")
# set(LIBPOLYXX_STATIC "${CMAKE_BINARY_DIR}/resources/lib/libpolyxx${STATIC_EXT}")

add_dependencies(LIBPOLY-EP GMP_SHARED GMPXX_SHARED)

Expand All @@ -78,34 +81,35 @@ set_target_properties(LIBPOLY_STATIC PROPERTIES
INTERFACE_LINK_LIBRARIES "${GMP_STATIC}"
)

add_library(LIBPOLYXX_SHARED SHARED IMPORTED GLOBAL)
target_link_libraries(LIBPOLY_STATIC INTERFACE GMPXX_SHARED)
set_target_properties(LIBPOLYXX_SHARED PROPERTIES
IMPORTED_LOCATION ${LIBPOLYXX_SHARED}
INTERFACE_INCLUDE_DIRECTORIES ${LIBPOLY_INCLUDE_DIR}
INTERFACE_LINK_LIBRARIES "${LIBPOLY_SHARED}"
)

add_library(LIBPOLYXX_STATIC STATIC IMPORTED GLOBAL)
target_link_libraries(LIBPOLY_STATIC INTERFACE GMPXX_STATIC)
set_target_properties(LIBPOLYXX_STATIC PROPERTIES
IMPORTED_LOCATION ${LIBPOLYXX_STATIC}
INTERFACE_INCLUDE_DIRECTORIES ${LIBPOLY_INCLUDE_DIR}
INTERFACE_LINK_LIBRARIES "${LIBPOLY_STATIC}"
)
# add_library(LIBPOLYXX_SHARED SHARED IMPORTED GLOBAL)
# target_link_libraries(LIBPOLY_STATIC INTERFACE GMPXX_SHARED)
# set_target_properties(LIBPOLYXX_SHARED PROPERTIES
# IMPORTED_LOCATION ${LIBPOLYXX_SHARED}
# INTERFACE_INCLUDE_DIRECTORIES ${LIBPOLY_INCLUDE_DIR}
# INTERFACE_LINK_LIBRARIES "${LIBPOLY_SHARED}"
# )
#
# add_library(LIBPOLYXX_STATIC STATIC IMPORTED GLOBAL)
# target_link_libraries(LIBPOLY_STATIC INTERFACE GMPXX_STATIC)
# set_target_properties(LIBPOLYXX_STATIC PROPERTIES
# IMPORTED_LOCATION ${LIBPOLYXX_STATIC}
# INTERFACE_INCLUDE_DIRECTORIES ${LIBPOLY_INCLUDE_DIR}
# INTERFACE_LINK_LIBRARIES "${LIBPOLY_STATIC}"
# )

add_dependencies(LIBPOLY_SHARED GMP_SHARED)
add_dependencies(LIBPOLY_STATIC GMP_STATIC)
add_dependencies(LIBPOLYXX_SHARED GMPXX_SHARED)
add_dependencies(LIBPOLYXX_STATIC GMPXX_STATIC)
# add_dependencies(LIBPOLYXX_SHARED GMPXX_SHARED)
# add_dependencies(LIBPOLYXX_STATIC GMPXX_STATIC)

if(NOT LIBPOLY_FOUND_SYSTEM)
add_dependencies(LIBPOLY_SHARED LIBPOLY-EP)
add_dependencies(LIBPOLY_STATIC LIBPOLY-EP)
add_dependencies(LIBPOLYXX_SHARED LIBPOLY-EP)
add_dependencies(LIBPOLYXX_STATIC LIBPOLY-EP)
# add_dependencies(LIBPOLYXX_SHARED LIBPOLY-EP)
# add_dependencies(LIBPOLYXX_STATIC LIBPOLY-EP)
endif()

set(LIBPOLY_FOUND TRUE)

mark_as_advanced(LIBPOLY_INCLUDE_DIR LIBPOLY_SHARED LIBPOLY_STATIC LIBPOLYXX_SHARED LIBPOLYXX_STATIC LIBPOLY_FOUND)
# mark_as_advanced(LIBPOLY_INCLUDE_DIR LIBPOLY_SHARED LIBPOLY_STATIC LIBPOLYXX_SHARED LIBPOLYXX_STATIC LIBPOLY_FOUND)
mark_as_advanced(LIBPOLY_INCLUDE_DIR LIBPOLY_SHARED LIBPOLY_STATIC LIBPOLY_FOUND)
4 changes: 2 additions & 2 deletions cmake/export.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ endif()
if(USE_LIBPOLY)
export_target(DEP_TARGETS LIBPOLY_SHARED GMPXX_SHARED GMP_SHARED)
export_target(DEP_TARGETS LIBPOLY_STATIC GMPXX_STATIC GMP_STATIC)
export_target(DEP_TARGETS LIBPOLYXX_SHARED GMPXX_SHARED GMP_SHARED)
export_target(DEP_TARGETS LIBPOLYXX_STATIC GMPXX_STATIC GMP_STATIC)
# export_target(DEP_TARGETS LIBPOLYXX_SHARED GMPXX_SHARED GMP_SHARED)
# export_target(DEP_TARGETS LIBPOLYXX_STATIC GMPXX_STATIC GMP_STATIC)
endif()
export_target(DEP_TARGETS GMP_SHARED)
export_target(DEP_TARGETS GMP_STATIC)
Expand Down
103 changes: 103 additions & 0 deletions cmake/patches/libpoly.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
diff --git a/include/polynomial.h b/include/polynomial.h
index 8a9533f..2905513 100644
--- a/include/polynomial.h
+++ b/include/polynomial.h
@@ -109,6 +109,8 @@ int lp_polynomial_lc_sgn(const lp_polynomial_t* A);
/** Get the context of the given polynomial */
const lp_polynomial_context_t* lp_polynomial_get_context(const lp_polynomial_t* A);

+void lp_polynomial_set_context(lp_polynomial_t* A, const lp_polynomial_context_t* ctx);
+
/** Returns all the variables (it will not clear the output list vars) */
void lp_polynomial_get_variables(const lp_polynomial_t* A, lp_variable_list_t* vars);

@@ -337,6 +339,8 @@ lp_polynomial_t* lp_polynomial_constraint_explain_infer_bounds(const lp_polynomi
*/
int lp_polynomial_constraint_evaluate(const lp_polynomial_t* A, lp_sign_condition_t sgn_condition, const lp_assignment_t* M);

+int lp_polynomial_constraint_evaluate_subs(const lp_polynomial_t* A, lp_sign_condition_t sgn_condition, const lp_assignment_t* M);
+
/**
* Given a polynomial A(x1, ..., xn, y) with y being the top variable, a root index,
* a sign condition, and an assignment M that assigns x1, ..., xn, the function
diff --git a/src/polynomial/polynomial.c b/src/polynomial/polynomial.c
index 11d948f..7468ab6 100644
--- a/src/polynomial/polynomial.c
+++ b/src/polynomial/polynomial.c
@@ -1031,6 +1031,18 @@ void lp_polynomial_roots_isolate(const lp_polynomial_t* A, const lp_assignment_t
lp_value_construct_none(&x_value_backup);
}

+ lp_polynomial_t* B;
+ {
+ coefficient_t A_rat;
+ lp_integer_t multiplier;
+ integer_construct(&multiplier);
+ coefficient_construct(A->ctx, &A_rat);
+ coefficient_evaluate_rationals(A->ctx, &A->data, M, &A_rat, &multiplier);
+ B = lp_polynomial_new_from_coefficient(A->ctx, &A_rat);
+ coefficient_destruct(&A_rat);
+ integer_destruct(&multiplier);
+ }
+
size_t i;

lp_polynomial_t** factors = 0;
@@ -1044,11 +1056,13 @@ void lp_polynomial_roots_isolate(const lp_polynomial_t* A, const lp_assignment_t
// Get the reduced polynomial
lp_polynomial_t A_r;
lp_polynomial_construct(&A_r, A->ctx);
- lp_polynomial_reductum_m(&A_r, A, M);
- assert(x == lp_polynomial_top_variable(A));
-
- // Get the square-free factorization
- lp_polynomial_factor_square_free(&A_r, &factors, &multiplicities, &factors_size);
+ if (x == lp_polynomial_top_variable(B)) {
+ lp_polynomial_reductum_m(&A_r, B, M);
+ assert(x == lp_polynomial_top_variable(B));
+ // Get the square-free factorization
+ lp_polynomial_factor_square_free(&A_r, &factors, &multiplicities, &factors_size);
+ }
+ lp_polynomial_delete(B);

// Count the max number of roots
size_t total_degree = 0;
@@ -1943,6 +1957,22 @@ int lp_polynomial_constraint_evaluate(const lp_polynomial_t* A, lp_sign_conditio
return lp_sign_condition_consistent(sgn_condition, p_sign);
}

+int lp_polynomial_constraint_evaluate_subs(const lp_polynomial_t* A, lp_sign_condition_t sgn_condition, const lp_assignment_t* M) {
+ coefficient_t A_rat;
+ lp_integer_t multiplier;
+ integer_construct(&multiplier);
+ coefficient_construct(A->ctx, &A_rat);
+ coefficient_evaluate_rationals(A->ctx, &A->data, M, &A_rat, &multiplier);
+ integer_destruct(&multiplier);
+ int res = -1;
+ if (A_rat.type == COEFFICIENT_NUMERIC) {
+ int sgn = integer_sgn(lp_Z, &A_rat.value.num);
+ res = lp_sign_condition_consistent(sgn_condition, sgn);
+ }
+ coefficient_destruct(&A_rat);
+ return res;
+}
+
int lp_polynomial_root_constraint_evaluate(const lp_polynomial_t* A, size_t root_index, lp_sign_condition_t sgn_condition, const lp_assignment_t* M) {

int eval;
diff --git a/src/variable/variable_db.c b/src/variable/variable_db.c
index 60f3df4..33866c4 100644
--- a/src/variable/variable_db.c
+++ b/src/variable/variable_db.c
@@ -63,9 +63,11 @@ void lp_variable_db_add_variable(lp_variable_db_t* var_db, lp_variable_t var, co
assert(var_db);
while (var >= var_db->capacity) {
lp_variable_db_resize(var_db, 2*var_db->capacity);
+ var_db->size = var_db->capacity < var ? var_db->capacity : var;
}
assert(var_db->variable_names[var] == 0);
var_db->variable_names[var] = strdup(name);
+ var_db->size = var_db->size < var ? var : var_db->size;
}

void lp_variable_db_construct(lp_variable_db_t* var_db) {
16 changes: 0 additions & 16 deletions cmake/patches/libpoly_variable_db.patch

This file was deleted.

4 changes: 2 additions & 2 deletions resources/resources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ endif()
IF(USE_LIBPOLY)
set(LIBPOLY_VERSION "0.1.11")
find_package(Poly ${LIBPOLY_VERSION} REQUIRED QUIET)
print_resource_info("LibPoly" LIBPOLYXX_STATIC ${LIBPOLY_VERSION})
print_resource_info("LibPoly" LIBPOLY_STATIC ${LIBPOLY_VERSION})
add_dependencies(resources LIBPOLY_SHARED LIBPOLY_STATIC)
add_dependencies(resources LIBPOLYXX_SHARED LIBPOLYXX_STATIC)
# add_dependencies(resources LIBPOLYXX_SHARED LIBPOLYXX_STATIC)
else()
message(STATUS "LibPoly is disabled")
endif()
Expand Down
6 changes: 3 additions & 3 deletions src/carl-arith/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ if(USE_MPFR_FLOAT)
target_link_libraries(carl-arith-static PUBLIC MPFR_STATIC)
endif()
if(USE_LIBPOLY)
target_include_dirs_from(carl-arith-objects SYSTEM PUBLIC LIBPOLYXX_SHARED LIBPOLYXX_STATIC LIBPOLY_SHARED LIBPOLY_STATIC)
target_link_libraries(carl-arith-shared PUBLIC LIBPOLYXX_SHARED LIBPOLY_SHARED)
target_link_libraries(carl-arith-static PUBLIC LIBPOLYXX_STATIC LIBPOLY_STATIC)
target_include_dirs_from(carl-arith-objects SYSTEM PUBLIC LIBPOLY_SHARED LIBPOLY_STATIC) # LIBPOLYXX_SHARED LIBPOLYXX_STATIC
target_link_libraries(carl-arith-shared PUBLIC LIBPOLY_SHARED) # LIBPOLYXX_SHARED
target_link_libraries(carl-arith-static PUBLIC LIBPOLY_STATIC) # LIBPOLYXX_STATIC
endif()

include(install)
Expand Down
Loading

0 comments on commit b67f7ca

Please sign in to comment.