diff --git a/ksmt-bitwuzla/bindings-native/CMakeLists.txt b/ksmt-bitwuzla/bindings-native/CMakeLists.txt index 28bbfccc8..d4031b098 100644 --- a/ksmt-bitwuzla/bindings-native/CMakeLists.txt +++ b/ksmt-bitwuzla/bindings-native/CMakeLists.txt @@ -5,24 +5,24 @@ PROJECT(bitwuzla_jni) FIND_PACKAGE(JNI REQUIRED) SET(CXX_STANDARD 17) +SET(BITWUZLA_ROOT "${PROJECT_SOURCE_DIR}/bitwuzla") -# Path to bitwuzla.h -SET(BITWUZLA_INCLUDE "${PROJECT_SOURCE_DIR}/bitwuzla/include") +# Path to bitwuzla.h, enums.h, option.h +SET(BITWUZLA_INCLUDE "${BITWUZLA_ROOT}/include") -# Path to Bitwuzla sources root (required for extensions) -SET(BITWUZLA_SRC_ROOT "${PROJECT_SOURCE_DIR}/bitwuzla/src") +# Path to bitwuzla library (libbitwuzla.so) +SET(BITWUZLA_LIB "${BITWUZLA_ROOT}/build/src/${CMAKE_SHARED_LIBRARY_PREFIX}bitwuzla${CMAKE_SHARED_LIBRARY_SUFFIX}") -# Path to bitwuzla library (libbitwuzla.so) -SET(BITWUZLA_LIB "${PROJECT_SOURCE_DIR}/bitwuzla/lib/${CMAKE_SHARED_LIBRARY_PREFIX}bitwuzla${CMAKE_SHARED_LIBRARY_SUFFIX}") +ADD_LIBRARY (bitwuzla_jni SHARED bitwuzla_jni.cpp bitwuzla_extension.cpp) -ADD_LIBRARY (bitwuzla_jni SHARED bitwuzla_jni.cpp bitwuzla_extension.c) +message(${BITWUZLA_INCLUDE}) TARGET_INCLUDE_DIRECTORIES(bitwuzla_jni PRIVATE ${JNI_INCLUDE_DIRS}) +TARGET_INCLUDE_DIRECTORIES(bitwuzla_jni PRIVATE "./include"}) TARGET_INCLUDE_DIRECTORIES(bitwuzla_jni PRIVATE ${BITWUZLA_INCLUDE}) -SET(BITWUZLA_SRC_INCLUDE "${BITWUZLA_SRC_ROOT}/bitwuzla/src") -TARGET_INCLUDE_DIRECTORIES(bitwuzla_jni PRIVATE ${BITWUZLA_SRC_INCLUDE}) - SET(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +# For Windows build, comment the first line, and uncomment the second one (link statically with libstdc++, ligbcc, lpthreads) TARGET_LINK_LIBRARIES(bitwuzla_jni PRIVATE ${BITWUZLA_LIB}) +#TARGET_LINK_LIBRARIES(bitwuzla_jni PRIVATE ${BITWUZLA_LIB} -static-libstdc++ -static-libgcc -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic) diff --git a/ksmt-bitwuzla/bindings-native/bitwuzla_extension.c b/ksmt-bitwuzla/bindings-native/bitwuzla_extension.c deleted file mode 100644 index 9c1771184..000000000 --- a/ksmt-bitwuzla/bindings-native/bitwuzla_extension.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include "bitwuzla_extension.h" - -Bzla* bitwuzla_extension_get_bzla(Bitwuzla* bitwuzla) { - return bitwuzla_get_bzla(bitwuzla); -} - -BzlaMemMgr* bitwuzla_extension_get_bzla_memory(Bzla* bitwuzla) { - return bitwuzla->mm; -} - -void bitwuzla_extension_bzla_node_inc_ext_ref_counter(Bzla* bzla, BzlaNode* e) { - bzla_node_inc_ext_ref_counter(bzla, e); -} - -void bitwuzla_extension_bzla_bv_free(BzlaMemMgr* mm, BzlaBitVector* bv) { - bzla_bv_free(mm, bv); -} - -BzlaNode* bitwuzla_extension_bzla_exp_bv_const(Bzla* bzla, const BzlaBitVector* bits) { - return bzla_exp_bv_const(bzla, bits); -} - -BzlaBitVector* bitwuzla_extension_bzla_bv_concat(BzlaMemMgr* mm, const BzlaBitVector* a, const BzlaBitVector* b) { - return bzla_bv_concat(mm, a, b); -} - -BzlaBitVector* -bitwuzla_extension_bzla_bv_slice(BzlaMemMgr* mm, const BzlaBitVector* bv, uint32_t upper, uint32_t lower) { - return bzla_bv_slice(mm, bv, upper, lower); -} - -BzlaBitVector* bitwuzla_extension_bzla_bv_uint64_to_bv(BzlaMemMgr* mm, uint64_t value, uint32_t bw) { - return bzla_bv_uint64_to_bv(mm, value, bw); -} - -uint32_t bitwuzla_extension_bv_get_width(const BzlaBitVector* bv) { - return bzla_bv_get_width(bv); -} - -uint64_t bitwuzla_extension_bv_to_uint64(const BzlaBitVector* bv) { - return bzla_bv_to_uint64(bv); -} - -BzlaBitVector* bitwuzla_extension_node_bv_const_get_bits(BitwuzlaTerm* exp) { - return bzla_node_bv_const_get_bits((BzlaNode*) exp); -} - -BzlaFloatingPoint* bitwuzla_extension_node_fp_const_get_fp(BitwuzlaTerm* exp) { - return bzla_node_fp_const_get_fp((BzlaNode*) exp); -} - -BzlaBitVector* bitwuzla_extension_fp_bits_as_bv_bits(Bzla* bzla, BzlaFloatingPoint* fp) { - return bzla_fp_as_bv(bzla, fp); -} - diff --git a/ksmt-bitwuzla/bindings-native/bitwuzla_extension.cpp b/ksmt-bitwuzla/bindings-native/bitwuzla_extension.cpp new file mode 100644 index 000000000..e2b1da556 --- /dev/null +++ b/ksmt-bitwuzla/bindings-native/bitwuzla_extension.cpp @@ -0,0 +1,27 @@ +#include "bitwuzla/c/bitwuzla.h" +#include + + +#if __cplusplus +extern "C" { +#endif + +void bitwuzla_extension_sort_dec_ref(BitwuzlaSort sort_id) { + bitwuzla_sort_dec_ref(sort_id); +} + +void bitwuzla_extension_term_dec_ref(BitwuzlaTerm term_id) { + bitwuzla_term_dec_ref(term_id); +} + +uint64_t bitwuzla_extension_bv_value_uint64(BitwuzlaTerm term) { + return bitwuzla_bv_value_uint64(term); +} + +const char *bitwuzla_extension_bv_value_str(BitwuzlaTerm term, uint32_t base) { + return bitwuzla_bv_value_str(term, base); +} + +#if __cplusplus +} +#endif diff --git a/ksmt-bitwuzla/bindings-native/bitwuzla_extension.h b/ksmt-bitwuzla/bindings-native/bitwuzla_extension.h deleted file mode 100644 index 279eb6ea4..000000000 --- a/ksmt-bitwuzla/bindings-native/bitwuzla_extension.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include -#include -#include - -/** Get Bitwuzla core. */ -Bzla* bitwuzla_get_bzla(Bitwuzla* bitwuzla); - -BzlaNode *bzla_exp_bv_const(Bzla *bzla, const BzlaBitVector *bits); - -#if __cplusplus -extern "C" { -#endif - -Bzla* bitwuzla_extension_get_bzla(Bitwuzla* bitwuzla); - -BzlaMemMgr* bitwuzla_extension_get_bzla_memory(Bzla* bitwuzla); - -void bitwuzla_extension_bzla_node_inc_ext_ref_counter(Bzla* bzla, BzlaNode* e); - -void bitwuzla_extension_bzla_bv_free(BzlaMemMgr* mm, BzlaBitVector* bv); - -BzlaNode* bitwuzla_extension_bzla_exp_bv_const(Bzla* bzla, const BzlaBitVector* bits); - -BzlaBitVector* -bitwuzla_extension_bzla_bv_concat(BzlaMemMgr* mm, const BzlaBitVector* a, const BzlaBitVector* b); - -BzlaBitVector* -bitwuzla_extension_bzla_bv_slice(BzlaMemMgr* mm, - const BzlaBitVector* bv, - uint32_t upper, - uint32_t lower); - -BzlaBitVector* -bitwuzla_extension_bzla_bv_uint64_to_bv(BzlaMemMgr* mm, uint64_t value, uint32_t bw); - -uint32_t bitwuzla_extension_bv_get_width(const BzlaBitVector* bv); - -uint64_t bitwuzla_extension_bv_to_uint64(const BzlaBitVector* bv); - - -BzlaBitVector* bitwuzla_extension_node_bv_const_get_bits(BitwuzlaTerm* exp); - -BzlaFloatingPoint * bitwuzla_extension_node_fp_const_get_fp(BitwuzlaTerm* exp); - -BzlaBitVector* bitwuzla_extension_fp_bits_as_bv_bits(Bzla* bzla, BzlaFloatingPoint* fp); - -#if __cplusplus -} -#endif diff --git a/ksmt-bitwuzla/bindings-native/bitwuzla_jni.cpp b/ksmt-bitwuzla/bindings-native/bitwuzla_jni.cpp index 2c9cc5874..e70e37bad 100644 --- a/ksmt-bitwuzla/bindings-native/bitwuzla_jni.cpp +++ b/ksmt-bitwuzla/bindings-native/bitwuzla_jni.cpp @@ -1,12 +1,9 @@ #include #include -#include -#include -#include -#include #include -#include "bitwuzla_jni.hpp" -#include "bitwuzla_extension.h" +#include +#include +#include #define BITWUZLA_JNI_EXCEPTION_CLS "org/ksmt/solver/bitwuzla/bindings/BitwuzlaNativeException" #define BITWUZLA_CATCH_STATEMENT catch (const std::exception& e) @@ -105,8 +102,9 @@ void set_ptr_array(JNIEnv* env, jlongArray array, T* ptr_array, size_t size) { } #define BZLA (Bitwuzla*) bitwuzla -#define TERM(t) (BitwuzlaTerm*) t -#define SORT(s) (BitwuzlaSort*) s +#define BZLA_OPTIONS(opts) (BitwuzlaOptions*) opts +#define TERM(t) (BitwuzlaTerm) t +#define SORT(s) (BitwuzlaSort) s void abort_callback(const char* msg) { throw std::runtime_error(msg); @@ -186,1411 +184,969 @@ struct ScopedTimeout { } }; -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaInit(JNIEnv* env, jobject native_class) { +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaInit(JNIEnv *env, jclass native_class) { bitwuzla_set_abort_callback(abort_callback); } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaNew(JNIEnv* env, jobject native_class) { - BZLA_TRY_OR_ZERO({ - Bitwuzla* bzla = bitwuzla_new(); - - auto termination_state = new BitwuzlaTerminationCallbackState(); - termination_state->reset(); - bitwuzla_set_termination_callback(bzla, termination_callback, termination_state); - - return (jlong) bzla; - }) +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermDecRef(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_VOID({ + bitwuzla_extension_term_dec_ref(TERM(term)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaDelete(JNIEnv* env, jobject native_class, jlong bitwuzla) { +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortDecRef(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_VOID({ - - auto termination_state = get_termination_state(BZLA); - delete termination_state; - - bitwuzla_delete(BZLA); - }) + bitwuzla_extension_sort_dec_ref(SORT(sort)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaReset(JNIEnv* env, jobject native_class, jlong bitwuzla) { +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaForceTerminate(JNIEnv* env, jclass native_class, jlong bitwuzla) { BZLA_TRY_VOID({ - auto termination_state = get_termination_state(BZLA); - delete termination_state; - - bitwuzla_reset(BZLA); - - auto new_termination_state = new BitwuzlaTerminationCallbackState(); - new_termination_state->reset(); - bitwuzla_set_termination_callback(BZLA, termination_callback, new_termination_state); - }) + auto termination_state = get_termination_state(BZLA); + termination_state->terminate(); + }) } -jstring -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCopyright(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCopyright(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_NULL({ - const char* c = bitwuzla_copyright(BZLA); - jstring result = env->NewStringUTF(c); - return result; - }) + const char *c = bitwuzla_copyright(); + jstring result = env->NewStringUTF(c); + return result; + }) } -jstring -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaVersion(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaVersion(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_NULL({ - const char* c = bitwuzla_version(BZLA); - jstring result = env->NewStringUTF(c); - return result; - }) + const char* c = bitwuzla_version(); + jstring result = env->NewStringUTF(c); + return result; + }) } -jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGitId(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGitId(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_NULL({ - const char* c = bitwuzla_git_id(BZLA); - jstring result = env->NewStringUTF(c); - return result; - }) + const char* c = bitwuzla_git_id(); + jstring result = env->NewStringUTF(c); + return result; + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOption(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint bitwuzla_option, jint value) { - BZLA_TRY_VOID({ - bitwuzla_set_option(BZLA, BitwuzlaOption(bitwuzla_option), value); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionsNew(JNIEnv *env, jclass native_class) { + BZLA_TRY_OR_ZERO({ + BitwuzlaOptions *bitwuzla_options = bitwuzla_options_new(); + return (jlong) bitwuzla_options; + }) } -void -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOptionStr(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint bitwuzla_option, jstring value) { +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionsDelete(JNIEnv *env, jclass native_class, jlong options) { BZLA_TRY_VOID({ - GET_STRING(nativeString, value); - bitwuzla_set_option_str(BZLA, BitwuzlaOption(bitwuzla_option), nativeString); - }) + BitwuzlaOptions * bitwuzla_options_delete(BZLA_OPTIONS(options)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOption(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint bitwuzla_option) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionIsNumeric(JNIEnv *env, jclass native_class, jlong options, jint option) { BZLA_TRY_OR_ZERO({ - return (jint) bitwuzla_get_option(BZLA, BitwuzlaOption(bitwuzla_option)); - }) + return (jboolean) bitwuzla_option_is_numeric(BZLA_OPTIONS(options), BitwuzlaOption(option)); + }) } -jstring -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOptionStr(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint bitwuzla_option) { - BZLA_TRY_OR_NULL({ - const char* value = bitwuzla_get_option_str(BZLA, BitwuzlaOption(bitwuzla_option)); - return env->NewStringUTF(value); - }) -} - -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkArraySort(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong index, jlong element) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionIsMode(JNIEnv *env, jclass native_class, jlong options, jint option) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_array_sort(BZLA, SORT(index), SORT(element)); - }) + return (jboolean) bitwuzla_option_is_mode(BZLA_OPTIONS(options), BitwuzlaOption(option)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBoolSort(JNIEnv* env, jobject native_class, jlong bitwuzla) { - BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bool_sort(BZLA); - }) +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOption(JNIEnv *env, jclass native_class, jlong options, jint option, jlong value) { + BZLA_TRY_VOID({ + bitwuzla_set_option(BZLA_OPTIONS(options), BitwuzlaOption(option), (uint64_t) value); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvSort(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint size) { - BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bv_sort(BZLA, size); - }) +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOptionMode(JNIEnv *env, jclass native_class, jlong options, jint option, jstring value) { + BZLA_TRY_VOID({ + GET_STRING(nativeString, value); + bitwuzla_set_option_mode(BZLA_OPTIONS(options), BitwuzlaOption(option), nativeString); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpSort(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint exp_size, jint sig_size) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOption(JNIEnv *env, jclass native_class, jlong options, jint option) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* value = bitwuzla_mk_fp_sort(BZLA, exp_size, sig_size); - return (jlong) value; - }) + return (jlong) bitwuzla_get_option(BZLA_OPTIONS(options), BitwuzlaOption(option)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFunSort(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint arity, jlongArray domain, jlong codomain) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOptionMode(JNIEnv *env, jclass native_class, jlong options, jint option) { BZLA_TRY_OR_ZERO({ - GET_PTR_ARRAY(BitwuzlaSort const*, domain_ptr, domain); - jsize len = env->GetArrayLength(domain); - const BitwuzlaSort* value = bitwuzla_mk_fun_sort(BZLA, arity, domain_ptr, SORT(codomain)); - return (jlong) value; - }) + const char* value = bitwuzla_get_option_mode(BZLA_OPTIONS(options), BitwuzlaOption(option)); + return env->NewStringUTF(value); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmSort(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortHash(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* value = bitwuzla_mk_rm_sort(BZLA); - return (jlong) value; - }) + return (jlong) bitwuzla_sort_hash(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTrue(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortBvGetSize(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_true(BZLA); - }) + return (jlong) bitwuzla_sort_bv_get_size(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFalse(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetExpSize(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_false(BZLA); - }) + return (jlong) bitwuzla_sort_fp_get_exp_size(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvZero(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetSigSize(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bv_zero(BZLA, SORT(bitwuzla_sort)); - }) + return (jlong) bitwuzla_sort_fp_get_sig_size(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOne(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetIndex(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bv_one(BZLA, SORT(bitwuzla_sort)); - }) + return (jlong) bitwuzla_sort_array_get_index(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOnes(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetElement(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bv_ones(BZLA, SORT(bitwuzla_sort)); - }) + return (jlong) bitwuzla_sort_array_get_element(SORT(sort)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMinSigned(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { - BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bv_min_signed(BZLA, SORT(bitwuzla_sort)); - }) +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetDomainSorts(JNIEnv *env, jclass native_class, jlong sort) { + BZLA_TRY_OR_NULL({ + size_t len = 0; + const BitwuzlaSort* array = bitwuzla_sort_fun_get_domain_sorts(SORT(sort), &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMaxSigned(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetCodomain(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_bv_max_signed(BZLA, SORT(bitwuzla_sort)); - }) + return (jlong) bitwuzla_sort_fun_get_codomain(SORT(sort)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosZero(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetArity(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_fp_pos_zero(BZLA, SORT(bitwuzla_sort)); - return (jlong) result; - }) + return (jlong) bitwuzla_sort_fun_get_arity(SORT(sort)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegZero(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortGetUninterpretedSymbol(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_fp_neg_zero(BZLA, SORT(bitwuzla_sort)); - return (jlong) result; - }) + const char *symbol = bitwuzla_sort_get_uninterpreted_symbol(SORT(sort)); + return env->NewStringUTF(symbol); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosInf(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsEqual(JNIEnv *env, jclass native_class, jlong sort0, jlong sort1) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_fp_pos_inf(BZLA, SORT(bitwuzla_sort)); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_equal(SORT(sort0), SORT(sort1)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegInf(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsArray(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_fp_neg_inf(BZLA, SORT(bitwuzla_sort)); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_array(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNan(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsBool(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_fp_nan(BZLA, SORT(bitwuzla_sort)); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_bool(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort, jstring value, jint base) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsBv(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - GET_STRING(native_value, value); - const BitwuzlaTerm* result = bitwuzla_mk_bv_value( - BZLA, SORT(bitwuzla_sort), native_value, BitwuzlaBVBase(base) - ); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_bv(SORT(sort)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueUint32(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort, jint value) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFp(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - // We can't use all 64 bits because of some problems on Windows - const BitwuzlaTerm* result = bitwuzla_mk_bv_value_uint64(BZLA, SORT(bitwuzla_sort), value); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_fp(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlong arg) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFun(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term1(BZLA, BitwuzlaKind(kind), TERM(arg)); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_fun(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlong arg0, jlong arg1) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsRm(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term2( - BZLA, BitwuzlaKind(kind), TERM(arg0), TERM(arg1) - ); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_rm(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm3(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlong arg0, jlong arg1, jlong arg2) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsUninterpreted(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term3( - BZLA, BitwuzlaKind(kind), TERM(arg0), TERM(arg1), TERM(arg2) - ); - return (jlong) result; - }) + return (jboolean) bitwuzla_sort_is_uninterpreted(SORT(sort)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlongArray args) { - BZLA_TRY_OR_ZERO({ - GET_PTR_ARRAY(BitwuzlaTerm const*, args_ptr, args); - jsize len = env->GetArrayLength(args); - const BitwuzlaTerm* result = bitwuzla_mk_term(BZLA, BitwuzlaKind(kind), len, args_ptr); - return (jlong) result; - }) +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortToString(JNIEnv *env, jclass native_class, jlong sort) { + BZLA_TRY_OR_NULL({ + const char* result = bitwuzla_sort_to_string(SORT(sort)); + return env->NewStringUTF(result); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed1(JNIEnv* env, jobject native_class, - jlong bitwuzla, jint kind, jlong term, jint idx) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermHash(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term1_indexed1( - BZLA, BitwuzlaKind(kind), TERM(term), idx - ); - return (jlong) result; - }) + return (jlong) bitwuzla_term_hash(TERM(term)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed2(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlong term, jint idx0, jint idx1) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetKindNative(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term1_indexed2( - BZLA, BitwuzlaKind(kind), TERM(term), idx0, idx1 - ); - return (jlong) result; - }) + return (jlong) bitwuzla_term_get_kind(TERM(term)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed1(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlong term0, jlong term1, jint idx0) { - BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term2_indexed1( - BZLA, BitwuzlaKind(kind), TERM(term0), TERM(term1), idx0 - ); - return (jlong) result; - }) +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetChildren(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_NULL({ + size_t len = 0; + const BitwuzlaTerm *array = bitwuzla_term_get_children(TERM(term), &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed2(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlong term0, jlong term1, jint idx0, - jint idx1) { - BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_term2_indexed2( - BZLA, BitwuzlaKind(kind), TERM(term0), TERM(term1), idx0, idx1 - ); - return (jlong) result; - }) +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetIndices(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_NULL({ + size_t len = 0; + const uint64_t *array = bitwuzla_term_get_indices(TERM(term), &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTermIndexed(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint kind, jlongArray args, jintArray idxs) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsIndexed(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - GET_PTR_ARRAY(BitwuzlaTerm const*, args_ptr, args); - jsize argc = env->GetArrayLength(args); - - JniIntArray indices_array(env, idxs); - auto indices = (uint32_t*) indices_array.elements; - jsize idxc = env->GetArrayLength(idxs); - - const BitwuzlaTerm* result = bitwuzla_mk_term_indexed( - BZLA, BitwuzlaKind(kind), argc, args_ptr, idxc, indices - ); - return (jlong) result; - }) + return (jboolean) bitwuzla_term_is_indexed(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConst(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort, jstring symbol) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSort(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - GET_STRING(native_symbol, symbol); - const BitwuzlaTerm* result = bitwuzla_mk_const(BZLA, SORT(bitwuzla_sort), native_symbol); - return (jlong) result; - }) + return (jlong) bitwuzla_term_get_sort(TERM(term)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConstArray(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort, jlong value) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetIndexSort(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* result = bitwuzla_mk_const_array(BZLA, SORT(bitwuzla_sort), TERM(value)); - return (jlong) result; - }) + return (jlong) bitwuzla_term_array_get_index_sort(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkVar(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_sort, jstring symbol) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetElementSort(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - GET_STRING(native_symbol, symbol); - const BitwuzlaTerm* result = bitwuzla_mk_var(BZLA, SORT(bitwuzla_sort), native_symbol); - return (jlong) result; - }) + return (jlong) bitwuzla_term_array_get_element_sort(TERM(term)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPush(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint n_levels) { - BZLA_TRY_VOID({ - bitwuzla_push(BZLA, n_levels); - }) +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetDomainSorts(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_NULL({ + size_t len = 0; + const uint64_t *array = bitwuzla_term_fun_get_domain_sorts(TERM(term), &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPop(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint n_levels) { - BZLA_TRY_VOID({ - bitwuzla_pop(BZLA, n_levels); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetCodomainSort(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_term_fun_get_codomain_sort(TERM(term)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaAssert(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong term) { - BZLA_TRY_VOID({ - bitwuzla_assert(BZLA, TERM(term)); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermBvGetSize(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_term_bv_get_size(TERM(term)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaAssume(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong term) { - BZLA_TRY_VOID({ - bitwuzla_assume(BZLA, TERM(term)); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetExpSize(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_term_fp_get_exp_size(TERM(term)); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaIsUnsatAssumption(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetSigSize(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_is_unsat_assumption(BZLA, TERM(term)); - if (result) { - return JNI_TRUE; - } else { - return JNI_FALSE; - } - }) + return (jlong) bitwuzla_term_fp_get_sig_size(TERM(term)); + }) } -jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatAssumptions(JNIEnv* env, jobject native_class, - jlong bitwuzla) { - BZLA_TRY_OR_NULL({ - size_t len = 0; - const BitwuzlaTerm** array = bitwuzla_get_unsat_assumptions(BZLA, &len); - jlongArray result = create_ptr_array(env, len); - set_ptr_array(env, result, array, len); - return result; - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetArity(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_term_fun_get_arity(TERM(term)); + }) } -jlongArray -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatCore(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSymbol(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_NULL({ - size_t len = 0; - const BitwuzlaTerm** array = bitwuzla_get_unsat_core(BZLA, &len); - jlongArray result = create_ptr_array(env, len); - set_ptr_array(env, result, array, len); - return result; - }) + const char *result = bitwuzla_term_get_symbol(TERM(term)); + return env->NewStringUTF(result); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaFixateAssumptions(JNIEnv* env, jobject native_class, - jlong bitwuzla) { - BZLA_TRY_VOID({ - bitwuzla_fixate_assumptions(BZLA); - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsEqualSort(JNIEnv *env, jclass native_class, jlong term0, jlong term1) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_equal_sort(TERM(term0), TERM(term1)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaResetAssumptions(JNIEnv* env, jobject native_class, - jlong bitwuzla) { - BZLA_TRY_VOID({ - bitwuzla_reset_assumptions(BZLA); - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsArray(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_array(TERM(term)); + }) } -jint -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSimplify(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsConst(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - BitwuzlaResult result = bitwuzla_simplify(BZLA); - return result; - }) + return (jboolean) bitwuzla_term_is_const(TERM(term)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSat(JNIEnv* env, jobject native_class, jlong bitwuzla) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFun(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - BitwuzlaResult result = bitwuzla_check_sat(BZLA); - return result; - }) + return (jboolean) bitwuzla_term_is_fun(TERM(term)); + }) } -jint -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatTimeout(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong timeout) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsVar(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - auto termination_state = get_termination_state(BZLA); - ScopedTimeout _timeout(termination_state, timeout); - - BitwuzlaResult result = bitwuzla_check_sat(BZLA); - return result; - }) + return (jboolean) bitwuzla_term_is_var(TERM(term)); + }) } -void -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaForceTerminate(JNIEnv* env, jobject native_class, - jlong bitwuzla) { - BZLA_TRY_VOID({ - auto termination_state = get_termination_state(BZLA); - termination_state->terminate(); - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsValue(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_value(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValue(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_get_value(BZLA, TERM(bitwuzla_term)); - }) + return (jboolean) bitwuzla_term_is_bv_value(TERM(term)); + }) } -jstring -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetBvValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - const char* c = bitwuzla_get_bv_value(BZLA, TERM(bitwuzla_term)); - jstring result = env->NewStringUTF(c); - return result; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValue(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_fp_value(TERM(term)); + }) } -jobject -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetFpValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - const char* sign; - const char* exponent; - const char* significand; - bitwuzla_get_fp_value(BZLA, TERM(bitwuzla_term), &sign, &exponent, &significand); - - jclass clazz = env->FindClass("org/ksmt/solver/bitwuzla/bindings/FpValue"); - jmethodID constructor = env->GetMethodID(clazz, "", "()V"); - jfieldID sign_id = env->GetFieldID(clazz, "sign", "Ljava/lang/String;"); - jfieldID exponent_id = env->GetFieldID(clazz, "exponent", "Ljava/lang/String;"); - jfieldID significand_id = env->GetFieldID(clazz, "significand", "Ljava/lang/String;"); - - jstring sign_string = env->NewStringUTF(sign); - jstring exponent_string = env->NewStringUTF(exponent); - jstring significandn_string = env->NewStringUTF(significand); - - jobject result_object = env->NewObject(clazz, constructor); - env->SetObjectField(result_object, sign_id, sign_string); - env->SetObjectField(result_object, exponent_id, exponent_string); - env->SetObjectField(result_object, significand_id, significandn_string); - - return result_object; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValue(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_rm_value(TERM(term)); + }) } -jstring -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetRmValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - const char* result = bitwuzla_get_rm_value(BZLA, TERM(bitwuzla_term)); - jstring result_str = env->NewStringUTF(result); - - return result_str; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBool(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_bool(TERM(term)); + }) } -jobject -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetArrayValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - size_t len = 0; - BitwuzlaTerm const** indices_ptr; - BitwuzlaTerm const** values_ptr; - BitwuzlaTerm const* default_value_ptr; - bitwuzla_get_array_value( - BZLA, TERM(bitwuzla_term), &indices_ptr, &values_ptr, &len, &default_value_ptr - ); - - jclass clazz = env->FindClass("org/ksmt/solver/bitwuzla/bindings/ArrayValue"); - jmethodID constructor = env->GetMethodID(clazz, "", "()V"); - jfieldID size_id = env->GetFieldID(clazz, "size", "I"); - jfieldID indices_id = env->GetFieldID(clazz, "indices", "[J"); - jfieldID values_id = env->GetFieldID(clazz, "values", "[J"); - jfieldID defaultValue_id = env->GetFieldID(clazz, "defaultValue", "J"); - - jlongArray indices_array = create_ptr_array(env, len); - set_ptr_array(env, indices_array, indices_ptr, len); - jlongArray values_array = create_ptr_array(env, len); - set_ptr_array(env, values_array, values_ptr, len); - - jobject result_object = env->NewObject(clazz, constructor); - env->SetIntField(result_object, size_id, (jint) len); - env->SetObjectField(result_object, indices_id, indices_array); - env->SetObjectField(result_object, values_id, values_array); - env->SetLongField(result_object, defaultValue_id, (jlong) default_value_ptr); - - return result_object; - }) -} - -jobject -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetFunValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - size_t size = 0; - size_t arity = 0; - BitwuzlaTerm const*** args_ptr; - BitwuzlaTerm const** values_ptr; - bitwuzla_get_fun_value(BZLA, TERM(bitwuzla_term), &args_ptr, &arity, &values_ptr, &size); - - jclass clazz = env->FindClass("org/ksmt/solver/bitwuzla/bindings/FunValue"); - jmethodID constructor = env->GetMethodID(clazz, "", "()V"); - jfieldID size_id = env->GetFieldID(clazz, "size", "I"); - jfieldID arity_id = env->GetFieldID(clazz, "arity", "I"); - jfieldID args_id = env->GetFieldID(clazz, "args", "[[J"); - jfieldID values_id = env->GetFieldID(clazz, "values", "[J"); - - jclass clazz_long_array = env->FindClass("[J"); - jobjectArray argsArray = env->NewObjectArray((jsize) size, clazz_long_array, nullptr); - for (unsigned int i = 0; i < size; i++) { - jlongArray args_i = create_ptr_array(env, arity); - set_ptr_array(env, args_i, args_ptr[i], arity); - env->SetObjectArrayElement(argsArray, (jsize) i, args_i); - } - jlongArray valuesArray = create_ptr_array(env, size); - set_ptr_array(env, valuesArray, values_ptr, size); - - jobject result_object = env->NewObject(clazz, constructor); - env->SetIntField(result_object, size_id, (jint) size); - env->SetIntField(result_object, arity_id, (jint) arity); - env->SetObjectField(result_object, args_id, argsArray); - env->SetObjectField(result_object, values_id, valuesArray); - return result_object; - }) -} - -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerm(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_term, jlongArray map_keys, - jlongArray map_values) { - BZLA_TRY_OR_ZERO({ - GET_PTR_ARRAY(BitwuzlaTerm const*, keys_ptr, map_keys); - GET_PTR_ARRAY(BitwuzlaTerm const*, values_ptr, map_values); - jsize num_keys = env->GetArrayLength(map_keys); - - const BitwuzlaTerm* result = bitwuzla_substitute_term( - BZLA, TERM(bitwuzla_term), num_keys, keys_ptr, values_ptr - ); - - return (jlong) result; - }) -} - -jlongArray -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerms(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlongArray terms, jlongArray map_keys, - jlongArray map_values) { - BZLA_TRY_OR_NULL({ - GET_PTR_ARRAY(BitwuzlaTerm const*, terms_ptr, terms); - jsize num_terms = env->GetArrayLength(terms); - - GET_PTR_ARRAY(BitwuzlaTerm const*, keys_ptr, map_keys); - GET_PTR_ARRAY(BitwuzlaTerm const*, values_ptr, map_values); - jsize num_keys = env->GetArrayLength(map_keys); - - bitwuzla_substitute_terms( - BZLA, num_terms, terms_ptr, num_keys, keys_ptr, values_ptr - ); - - jlongArray result_terms = create_ptr_array(env, num_terms); - set_ptr_array(env, result_terms, terms_ptr, num_terms); - - return result_terms; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBv(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_bv(TERM(term)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortHash(JNIEnv* env, jobject native_class, jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFp(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return bitwuzla_sort_hash(SORT(bitwuzla_sort)); - }) + return (jboolean) bitwuzla_term_is_fp(TERM(term)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetKind(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRm(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return bitwuzla_term_get_kind(TERM(bitwuzla_term)); - }) + return (jboolean) bitwuzla_term_is_rm(TERM(term)); + }) } -jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetChildren(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - size_t len = 0; - const BitwuzlaTerm** array = bitwuzla_term_get_children(TERM(bitwuzla_term), &len); - jlongArray result = create_ptr_array(env, len); - set_ptr_array(env, result, array, len); - return result; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsUninterpreted(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_uninterpreted(TERM(term)); + }) } -jintArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetIndices(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - size_t len = 0; - uint32_t* array = bitwuzla_term_get_indices(TERM(bitwuzla_term), &len); - jintArray result = env->NewIntArray((jsize) len); - env->SetIntArrayRegion(result, 0, len, (jint*) array); - return result; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsTrue(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_true(TERM(term)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortBvGetSize(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFalse(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return bitwuzla_sort_bv_get_size(SORT(bitwuzla_sort)); - }) + return (jboolean) bitwuzla_term_is_false(TERM(term)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetExpSize(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueZero(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return bitwuzla_sort_fp_get_exp_size(SORT(bitwuzla_sort)); - }) + return (jboolean) bitwuzla_term_is_bv_value_zero(TERM(term)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetSigSize(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOne(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return bitwuzla_sort_fp_get_sig_size(SORT(bitwuzla_sort)); - }) + return (jboolean) bitwuzla_term_is_bv_value_one(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetIndex(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOnes(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* bw_s = bitwuzla_sort_array_get_index(SORT(bitwuzla_sort)); - return (jlong) bw_s; - }) + return (jboolean) bitwuzla_term_is_bv_value_ones(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetElement(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMinSigned(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* bw_s = bitwuzla_sort_array_get_element(SORT(bitwuzla_sort)); - return (jlong) bw_s; - }) + return (jboolean) bitwuzla_term_is_bv_value_min_signed(TERM(term)); + }) } -jlongArray -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetDomainSorts(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { - BZLA_TRY_OR_NULL({ - size_t result_size = 0; - const BitwuzlaSort** result = bitwuzla_sort_fun_get_domain_sorts( - SORT(bitwuzla_sort), &result_size - ); - - jlongArray result_array = create_ptr_array(env, result_size); - set_ptr_array(env, result_array, result, result_size); - - return result_array; - }) +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMaxSigned(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_ZERO({ + return (jboolean) bitwuzla_term_is_bv_value_max_signed(TERM(term)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetCodomain(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosZero(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* result = bitwuzla_sort_fun_get_codomain(SORT(bitwuzla_sort)); - return (jlong) result; - }) + return (jboolean) bitwuzla_term_is_fp_value_pos_zero(TERM(term)); + }) } -jint -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetArity(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegZero(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - uint32_t result = bitwuzla_sort_fun_get_arity(SORT(bitwuzla_sort)); - return (jint) result; - }) + return (jboolean) bitwuzla_term_is_fp_value_neg_zero(TERM(term)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsEqual(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort_1, - jlong bitwuzla_sort_2) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosInf(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_sort_is_equal(SORT(bitwuzla_sort_1), SORT(bitwuzla_sort_2)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_fp_value_pos_inf(TERM(term)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsArray(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegInf(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_sort_is_array(SORT(bitwuzla_sort)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_fp_value_neg_inf(TERM(term)); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsBv(JNIEnv* env, jobject native_class, jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNan(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_sort_is_bv(SORT(bitwuzla_sort)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_fp_value_nan(TERM(term)); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFp(JNIEnv* env, jobject native_class, jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRna(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_sort_is_fp(SORT(bitwuzla_sort)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_rm_value_rna(TERM(term)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFun(JNIEnv* env, jobject native_class, - jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRne(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_sort_is_fun(SORT(bitwuzla_sort)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_rm_value_rne(TERM(term)); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsRm(JNIEnv* env, jobject native_class, jlong bitwuzla_sort) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtn(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_sort_is_rm(SORT(bitwuzla_sort)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_rm_value_rtn(TERM(term)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermHash(JNIEnv* env, jobject native_class, jlong bitwuzla_term) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtp(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - return bitwuzla_term_hash(TERM(bitwuzla_term)); - }) + return (jboolean) bitwuzla_term_is_rm_value_rtp(TERM(term)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsIndexed(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtz(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_indexed(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jboolean) bitwuzla_term_is_rm_value_rtz(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetBitwuzla(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetBool(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - Bitwuzla* bw = bitwuzla_term_get_bitwuzla(TERM(bitwuzla_term)); - return (jlong) bw; - }) + return (jboolean) bitwuzla_term_value_get_bool(TERM(term)); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSort(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* bw_sort = bitwuzla_term_get_sort(TERM(bitwuzla_term)); - return (jlong) bw_sort; - }) +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetStr(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_NULL({ + const char *result = bitwuzla_term_value_get_str(TERM(term)); + return env->NewStringUTF(result); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetIndexSort(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* bw_sort = bitwuzla_term_array_get_index_sort(TERM(bitwuzla_term)); - return (jlong) bw_sort; - }) +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetStrFmt(JNIEnv *env, jclass native_class, jlong term, jbyte base) { + BZLA_TRY_OR_NULL({ + const char *result = bitwuzla_term_value_get_str_fmt(TERM(term), (uint8_t) base); + return env->NewStringUTF(result); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetElementSort(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetRm(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* bw_sort = bitwuzla_term_array_get_element_sort(TERM(bitwuzla_term)); - return (jlong) bw_sort; - }) + return BitwuzlaRoundingMode(bitwuzla_term_value_get_rm(TERM(term))); + }) } -jlongArray -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetDomainSorts(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermToString(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_NULL({ - size_t result_size = 0; - const BitwuzlaSort** result = bitwuzla_term_fun_get_domain_sorts( - TERM(bitwuzla_term), &result_size - ); - - jlongArray result_array = create_ptr_array(env, result_size); - set_ptr_array(env, result_array, result, result_size); + const char *result = bitwuzla_term_to_string(TERM(term)); + return env->NewStringUTF(result); + }) +} - return result_array; - }) +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermToStringFmt(JNIEnv *env, jclass native_class, jlong term, jbyte base) { + BZLA_TRY_OR_NULL({ + const char *result = bitwuzla_term_to_string_fmt(TERM(term), (uint8_t) base); + return env->NewStringUTF(result); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetCodomainSort(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaNew(JNIEnv *env, jclass native_class, jlong options) { BZLA_TRY_OR_ZERO({ - const BitwuzlaSort* bw_sort = bitwuzla_term_fun_get_codomain_sort(TERM(bitwuzla_term)); - return (jlong) bw_sort; - }) + Bitwuzla *bzla = bitwuzla_new(BZLA_OPTIONS(options)); + + auto termination_state = new BitwuzlaTerminationCallbackState(); + termination_state->reset(); + bitwuzla_set_termination_callback(bzla, termination_callback, termination_state); + + return (jlong) bzla; + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermBvGetSize(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_ZERO({ - uint32_t result = bitwuzla_term_bv_get_size(TERM(bitwuzla_term)); - return (jint) result; - }) +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaDelete(JNIEnv *env, jclass native_class, jlong bitwuzla) { + BZLA_TRY_VOID({ + auto termination_state = get_termination_state(BZLA); + delete termination_state; + + bitwuzla_delete(BZLA); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetExpSize(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_ZERO({ - uint32_t result = bitwuzla_term_fp_get_exp_size(TERM(bitwuzla_term)); - return (jint) result; - }) +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPush(JNIEnv *env, jclass native_class, jlong bitwuzla, jlong nlevels) { + BZLA_TRY_VOID({ + bitwuzla_push(BZLA, (uint64_t) nlevels); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetSigSize(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_ZERO({ - uint32_t result = bitwuzla_term_fp_get_sig_size(TERM(bitwuzla_term)); - return (jint) result; - }) +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPop(JNIEnv *env, jclass native_class, jlong bitwuzla, jlong nlevels) { + BZLA_TRY_VOID({ + bitwuzla_pop(BZLA, (uint64_t) nlevels); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetArity(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaAssert(JNIEnv *env, jclass native_class, jlong bitwuzla, jlong term) { + BZLA_TRY_VOID({ + bitwuzla_assert(BZLA, TERM(term)); + }) +} + +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetAssertions(JNIEnv *env, jclass native_class, jlong bitwuzla) { + BZLA_TRY_OR_NULL({ + size_t len = 0; + const BitwuzlaTerm *array = bitwuzla_get_assertions(BZLA, &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) +} + +jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaIsUnsatAssumption(JNIEnv *env, jclass native_class, jlong bitwuzla, jlong term) { BZLA_TRY_OR_ZERO({ - uint32_t result = bitwuzla_term_fun_get_arity(TERM(bitwuzla_term)); - return (jint) result; - }) + return bitwuzla_is_unsat_assumption(BZLA, TERM(term)); + }) } -jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSymbol(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatAssumptions(JNIEnv *env, jclass native_class, jlong bitwuzla) { BZLA_TRY_OR_NULL({ - const char* c = bitwuzla_term_get_symbol(TERM(bitwuzla_term)); - jstring result = env->NewStringUTF(c); - return result; - }) + size_t len = 0; + const BitwuzlaTerm *array = bitwuzla_get_unsat_assumptions(BZLA, &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermSetSymbol(JNIEnv* env, jobject native_class, - jlong bitwuzla_term, jstring symbol) { +jlongArray Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatCore(JNIEnv *env, jclass native_class, jlong bitwuzla) { + BZLA_TRY_OR_NULL({ + size_t len = 0; + const BitwuzlaTerm *array = bitwuzla_get_unsat_core(BZLA, &len); + jlongArray result = create_ptr_array(env, len); + set_ptr_array(env, result, array, len); + return result; + }) +} + +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSimplify(JNIEnv *env, jclass native_class, jlong bitwuzla) { BZLA_TRY_VOID({ - GET_STRING(native_symbol, symbol); - bitwuzla_term_set_symbol(TERM(bitwuzla_term), native_symbol); - }) + bitwuzla_simplify(BZLA); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsEqualSort(JNIEnv* env, jobject native_class, - jlong bitwuzla_term_1, - jlong bitwuzla_term_2) { +jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatNative(JNIEnv *env, jclass native_class, jlong bitwuzla) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_equal_sort(TERM(bitwuzla_term_1), TERM(bitwuzla_term_2)); - return (jboolean) result; - }) + return (jint) bitwuzla_check_sat(BZLA); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsArray(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatAssumingNative(JNIEnv *env, jclass native_class, jlong bitwuzla, jlongArray args) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_array(TERM(bitwuzla_term)); - return (jboolean) result; - }) + GET_PTR_ARRAY(BitwuzlaTerm, args_ptr, args); + jsize len = env->GetArrayLength(args); + return (jint) bitwuzla_check_sat_assuming(BZLA, (uint32_t) len, args_ptr); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsConst(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatTimeout(JNIEnv* env, jobject native_class, jlong bitwuzla, jlongArray args, jlong timeout) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_const(TERM(bitwuzla_term)); - return (jboolean) result; - }) + auto termination_state = get_termination_state(BZLA); + ScopedTimeout _timeout(termination_state, timeout); + + GET_PTR_ARRAY(BitwuzlaTerm, args_ptr, args); + jsize len = env->GetArrayLength(args); + + return (jint) bitwuzla_check_sat_assuming(BZLA, (uint32_t) len, args_ptr); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFun(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetValue(JNIEnv *env, jclass native_class, jlong bitwuzla, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fun(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_get_value(BZLA, TERM(term)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsVar(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetBvValueUInt64(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_var(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_extension_bv_value_uint64(TERM(term)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBoundVar(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetBvValueString(JNIEnv *env, jclass native_class, jlong term) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bound_var(TERM(bitwuzla_term)); - return (jboolean) result; - }) + const char * str = bitwuzla_extension_bv_value_str(TERM(term), 2); + return env->NewStringUTF(str); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsValue(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { - BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_value(TERM(bitwuzla_term)); - return (jboolean) result; - }) +jobject Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetFpValue(JNIEnv *env, jclass native_class, jlong term) { + BZLA_TRY_OR_NULL({ + const char* sign; + const char* exponent; + const char* significand; + + bitwuzla_term_value_get_fp_ieee(term, &sign, &exponent, &significand, 2); + jclass clazz = env->FindClass("org/ksmt/solver/bitwuzla/bindings/FpValue"); + jmethodID constructor = env->GetMethodID(clazz, "", "()V"); + jfieldID sign_id = env->GetFieldID(clazz, "sign", "Ljava/lang/String;"); + jfieldID exponent_id = env->GetFieldID(clazz, "exponent", "Ljava/lang/String;"); + jfieldID significand_id = env->GetFieldID(clazz, "significand", "Ljava/lang/String;"); + + jstring sign_str = env->NewStringUTF(sign); + jstring exponent_str = env->NewStringUTF(exponent); + jstring significand_str = env->NewStringUTF(significand); + + jobject result = env->NewObject(clazz, constructor); + env->SetObjectField(result, sign_id, sign_str); + env->SetObjectField(result, exponent_id, exponent_str); + env->SetObjectField(result, significand_id, significand_str); + + return result; + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValue(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { + +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkArraySort(JNIEnv *env, jclass native_class, jlong index, jlong element) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv_value(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_array_sort(SORT(index), SORT(element)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValue(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBoolSort(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp_value(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bool_sort(); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValue(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvSort(JNIEnv *env, jclass native_class, jlong size) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm_value(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_sort((uint64_t) size); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBv(JNIEnv* env, jobject native_class, jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpSort(JNIEnv *env, jclass native_class, jlong expSize, jlong sigSize) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_fp_sort((uint64_t) expSize, (uint64_t) sigSize); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFp(JNIEnv* env, jobject native_class, jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFunSort(JNIEnv *env, jclass native_class, jlongArray domain, jlong codomain) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp(TERM(bitwuzla_term)); - return (jboolean) result; - }) + GET_PTR_ARRAY(BitwuzlaSort, domain_ptr, domain); + jsize arity = env->GetArrayLength(domain); + return (jlong) bitwuzla_mk_fun_sort((uint64_t) arity, domain_ptr, SORT(codomain)); + }) } -jboolean -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRm(JNIEnv* env, jobject native_class, jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmSort(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_rm_sort(); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueZero(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkUninterpretedSort(JNIEnv *env, jclass native_class, jstring symbol) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv_value_zero(TERM(bitwuzla_term)); - return (jboolean) result; - }) + GET_STRING(native_symbol, symbol); + return (jlong) bitwuzla_mk_uninterpreted_sort(native_symbol); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOne(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTrue(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv_value_one(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_true(); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOnes(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFalse(JNIEnv *env, jclass native_class) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv_value_ones(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_false(); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMinSigned(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvZero(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv_value_min_signed(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_zero(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMaxSigned(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOne(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_bv_value_max_signed(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_one(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosZero(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOnes(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp_value_pos_zero(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_ones(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegZero(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMinSigned(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp_value_neg_zero(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_min_signed(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosInf(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMaxSigned(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp_value_pos_inf(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_max_signed(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegInf(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosZero(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp_value_neg_inf(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_fp_pos_zero(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNan(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegZero(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_fp_value_nan(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_fp_neg_zero(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRna(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosInf(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm_value_rna(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_fp_pos_inf(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRne(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegInf(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm_value_rne(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_fp_neg_inf(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtn(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNan(JNIEnv *env, jclass native_class, jlong sort) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm_value_rtn(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_fp_nan(SORT(sort)); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtp(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValue(JNIEnv *env, jclass native_class, jlong sort, jstring value, jbyte base) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm_value_rtp(TERM(bitwuzla_term)); - return (jboolean) result; - }) + GET_STRING(native_value, value); + return (jlong) bitwuzla_mk_bv_value(SORT(sort), native_value, (uint8_t) base); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtz(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueUint64(JNIEnv *env, jclass native_class, jlong sort, jlong value) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_rm_value_rtz(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_value_uint64(SORT(sort), (uint64_t) value); + }) } -jboolean Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsConstArray(JNIEnv* env, jobject native_class, - jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueInt64(JNIEnv *env, jclass native_class, jlong sort, jlong value) { BZLA_TRY_OR_ZERO({ - bool result = bitwuzla_term_is_const_array(TERM(bitwuzla_term)); - return (jboolean) result; - }) + return (jlong) bitwuzla_mk_bv_value_int64(SORT(sort), (int64_t) value); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jlong bitwuzla_bvSign, jlong bitwuzla_bvExponent, - jlong bitwuzla_bvSignificand) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValue(JNIEnv *env, jclass native_class, jlong bvSign, jlong bvExponent, jlong bvSignificand) { BZLA_TRY_OR_ZERO({ - const BitwuzlaTerm* bv_sign = (BitwuzlaTerm*) bitwuzla_bvSign; - const BitwuzlaTerm* bv_exponent = (BitwuzlaTerm*) bitwuzla_bvExponent; - const BitwuzlaTerm* bv_significand = (BitwuzlaTerm*) bitwuzla_bvSignificand; - return (jlong) bitwuzla_mk_fp_value(BZLA, bv_sign, bv_exponent, bv_significand); - }) + return (jlong) bitwuzla_mk_fp_value(TERM(bvSign), TERM(bvExponent), TERM(bvSignificand)); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValueFromReal(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong sort, jlong rm, - jstring real) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpFromReal(JNIEnv *env, jclass native_class, jlong sort, jlong rm, jstring real) { BZLA_TRY_OR_ZERO({ - GET_STRING(real_str, real); - const BitwuzlaTerm* result = bitwuzla_mk_fp_value_from_real( - BZLA, SORT(sort), TERM(rm), real_str - ); - - return (jlong) result; - }) + GET_STRING(native_real, real); + return (jlong) bitwuzla_mk_fp_from_real(SORT(sort), TERM(rm), native_real); + }) } -jlong -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValueFromRational(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong sort, jlong rm, - jstring num, jstring den) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpFromRational(JNIEnv *env, jclass native_class, jlong sort, jlong rm, jstring num, jstring den) { BZLA_TRY_OR_ZERO({ - GET_STRING(num_str, num); - GET_STRING(den_str, den); - - const BitwuzlaTerm* result = bitwuzla_mk_fp_value_from_rational( - BZLA, SORT(sort), TERM(rm), num_str, den_str - ); - - return (jlong) result; - }) + GET_STRING(native_num, num); + GET_STRING(native_den, den); + return (jlong) bitwuzla_mk_fp_from_rational(SORT(sort), TERM(rm), native_num, native_den); + }) } -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmValue(JNIEnv* env, jobject native_class, jlong bitwuzla, - jint rm) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmValue(JNIEnv *env, jclass native_class, jint rm) { BZLA_TRY_OR_ZERO({ - return (jlong) bitwuzla_mk_rm_value(BZLA, (BitwuzlaRoundingMode) rm); - }) + return (jlong) bitwuzla_mk_rm_value(BitwuzlaRoundingMode(rm)); + }) } -void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPrintModel(JNIEnv* env, jobject native_class, jlong bitwuzla, - jstring format, jstring file_path) { - BZLA_TRY_VOID({ - GET_STRING(print_format, format); - GET_STRING(path, file_path); - - auto f = fopen(path, "w"); - bitwuzla_print_model(BZLA, print_format, f); - fclose(f); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1(JNIEnv *env, jclass native_class, jint kind, jlong arg) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_mk_term1(BitwuzlaKind(kind), TERM(arg)); + }) } -void -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaDumpFormula(JNIEnv* env, jobject native_class, jlong bitwuzla, - jstring format, jstring file_path) { - BZLA_TRY_VOID({ - GET_STRING(print_format, format); - GET_STRING(path, file_path); - - auto f = fopen(path, "w"); - bitwuzla_dump_formula(BZLA, print_format, f); - fclose(f); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2(JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_mk_term2(BitwuzlaKind(kind), TERM(arg0), TERM(arg1)); + }) } -jstring read_file_to_java_str(JNIEnv* env, FILE* file_ptr) { - std::vector result; - - int c; - while ((c = std::fgetc(file_ptr)) != EOF) { - result.push_back((char) c); - } - - std::string str(result.data(), result.size()); - return env->NewStringUTF(str.c_str()); +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm3(JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1, jlong arg2) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_mk_term3(BitwuzlaKind(kind), TERM(arg0), TERM(arg1), TERM(arg2)); + }) } -jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortDump(JNIEnv* env, jobject native_class, jlong sort, - jstring format) { - BZLA_TRY_OR_NULL({ - GET_STRING(print_format, format); - auto&& f = std::shared_ptr(tmpfile(), fclose); - - bitwuzla_sort_dump(SORT(sort), print_format, f.get()); - rewind(f.get()); - return read_file_to_java_str(env, f.get()); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm(JNIEnv *env, jclass native_class, jint kind, jlongArray args) { + BZLA_TRY_OR_ZERO({ + GET_PTR_ARRAY(BitwuzlaTerm, args_ptr, args); + jsize argc = env->GetArrayLength(args); + return (jlong) bitwuzla_mk_term(BitwuzlaKind(kind), (uint32_t) argc, args_ptr); + }) } -jstring Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermDump(JNIEnv* env, jobject native_class, jlong term, - jstring format) { - BZLA_TRY_OR_NULL({ - GET_STRING(print_format, format); - auto&& f = std::shared_ptr(tmpfile(), fclose); - - bitwuzla_term_dump(TERM(term), print_format, f.get()); - rewind(f.get()); - return read_file_to_java_str(env, f.get()); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed1(JNIEnv *env, jclass native_class, jint kind, jlong arg, jlong idx) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_mk_term1_indexed1(BitwuzlaKind(kind), TERM(arg), (uint64_t) idx); + }) } -// Bv bits utils - -jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueUint32Array(JNIEnv* env, jobject native_class, - jlong bitwuzla, jint bv_width, - jintArray value) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed2(JNIEnv *env, jclass native_class, jint kind, jlong arg, jlong idx0, jlong idx1) { BZLA_TRY_OR_ZERO({ - JniIntArray value_array(env, value); - unsigned int value_length = env->GetArrayLength(value); - - auto bzla_core = bitwuzla_extension_get_bzla(BZLA); - auto bzla_memory = bitwuzla_extension_get_bzla_memory(bzla_core); - - auto remaining_width = (int32_t) bv_width; - BzlaBitVector* bv = nullptr; - - unsigned int idx = 0; - while (remaining_width > 0) { - idx++; - uint32_t chunk_value = value_array.elements[value_length - idx]; - uint32_t chunk_width = remaining_width > 32 ? 32 : remaining_width; - remaining_width -= 32; - - auto chunk_bv = bitwuzla_extension_bzla_bv_uint64_to_bv( - bzla_memory, chunk_value, chunk_width - ); - - if (bv != nullptr) { - auto previous_chunk = bv; - bv = bitwuzla_extension_bzla_bv_concat(bzla_memory, chunk_bv, previous_chunk); - - bitwuzla_extension_bzla_bv_free(bzla_memory, previous_chunk); - bitwuzla_extension_bzla_bv_free(bzla_memory, chunk_bv); - } else { - bv = chunk_bv; - } - } - - BzlaNode* res = bitwuzla_extension_bzla_exp_bv_const(bzla_core, bv); - bitwuzla_extension_bzla_bv_free(bzla_memory, bv); - - bitwuzla_extension_bzla_node_inc_ext_ref_counter(bzla_core, res); - - return (jlong) res; - }) + return (jlong) bitwuzla_mk_term1_indexed2(BitwuzlaKind(kind), TERM(arg), (uint64_t) idx0, (uint64_t) idx1); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaBvConstNodeGetBitsUInt32(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed1(JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1, jlong idx) { BZLA_TRY_OR_ZERO({ - const BzlaBitVector* bw_vector = bitwuzla_extension_node_bv_const_get_bits( - TERM(bitwuzla_term)); - uint64_t bits = bitwuzla_extension_bv_to_uint64(bw_vector); - - return (jint) bits; - }) + return (jlong) bitwuzla_mk_term2_indexed1(BitwuzlaKind(kind), TERM(arg0), TERM(arg1), (uint64_t) idx); + }) } -jintArray get_bv_bits_as_jint_array(JNIEnv* env, jlong bitwuzla, const BzlaBitVector* bw_vector) { - auto bzla_core = bitwuzla_extension_get_bzla(BZLA); - auto bzla_memory = bitwuzla_extension_get_bzla_memory(bzla_core); - - uint32_t width = bitwuzla_extension_bv_get_width(bw_vector); - - uint32_t idx = 0; - int32_t remaining_width = width; - std::vector chunks; - - while (remaining_width > 0) { - uint32_t lower = idx * 32; - uint32_t upper = std::min(lower + 32, width); - idx++; - remaining_width -= 32; - - auto chunk_bv = bitwuzla_extension_bzla_bv_slice(bzla_memory, bw_vector, upper, lower); - uint64_t bits = bitwuzla_extension_bv_to_uint64(chunk_bv); - chunks.push_back(bits); +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed2(JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1, jlong idx0, jlong idx1) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_mk_term2_indexed2(BitwuzlaKind(kind), TERM(arg0), TERM(arg1), (uint64_t) idx0, (uint64_t) idx1); + }) +} - bitwuzla_extension_bzla_bv_free(bzla_memory, chunk_bv); - } +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTermIndexed(JNIEnv *env, jclass native_class, jint kind, jlongArray args, jlongArray idxs) { + BZLA_TRY_OR_ZERO({ + GET_PTR_ARRAY(BitwuzlaTerm, args_ptr, args); + jsize argc = env->GetArrayLength(args); - jintArray result = env->NewIntArray(chunks.size()); - env->SetIntArrayRegion(result, 0, chunks.size(), (jint*) chunks.data()); + GET_PTR_ARRAY(BitwuzlaTerm, idxs_ptr, idxs); + jsize idxc = env->GetArrayLength(idxs); - return result; + return (jlong) bitwuzla_mk_term_indexed(BitwuzlaKind(kind), (uint32_t) argc, args_ptr, (uint32_t) idxc, idxs_ptr); + }) } -jintArray -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaBvConstNodeGetBitsUIntArray(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - auto bzla_core = bitwuzla_extension_get_bzla(BZLA); - auto bzla_memory = bitwuzla_extension_get_bzla_memory(bzla_core); - - const BzlaBitVector* bw_vector = bitwuzla_extension_node_bv_const_get_bits( - TERM(bitwuzla_term)); +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConst(JNIEnv *env, jclass native_class, jlong sort, jstring symbol) { + BZLA_TRY_OR_ZERO({ + GET_STRING(native_symbol, symbol); + return (jlong) bitwuzla_mk_const(SORT(sort), native_symbol); + }) +} - return get_bv_bits_as_jint_array(env, bitwuzla, bw_vector); - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConstArray(JNIEnv *env, jclass native_class, jlong sort, jlong value) { + BZLA_TRY_OR_ZERO({ + return (jlong) bitwuzla_mk_const_array(SORT(sort), TERM(value)); + }) } -jint Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaFpConstNodeGetBitsUInt32(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong bitwuzla_term) { +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkVar(JNIEnv *env, jclass native_class, jlong sort, jstring symbol) { BZLA_TRY_OR_ZERO({ - auto bzla = bitwuzla_extension_get_bzla(BZLA); - auto fp = bitwuzla_extension_node_fp_const_get_fp(TERM(bitwuzla_term)); - const BzlaBitVector* bw_vector = bitwuzla_extension_fp_bits_as_bv_bits(bzla, fp); + GET_STRING(native_symbol, symbol); + return (jlong) bitwuzla_mk_var(SORT(sort), native_symbol); + }) +} - uint64_t bits = bitwuzla_extension_bv_to_uint64(bw_vector); - return (jint) bits; - }) +jlong Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerm(JNIEnv *env, jclass native_class, jlong term, jlongArray mapKeys, jlongArray mapValues) { + BZLA_TRY_OR_ZERO({ + GET_PTR_ARRAY(BitwuzlaTerm, mapKeys_ptr, mapKeys); + GET_PTR_ARRAY(BitwuzlaTerm, mapValues_ptr, mapValues); + jsize map_size = env->GetArrayLength(mapKeys); + return (jlong) bitwuzla_substitute_term(TERM(term), map_size, mapKeys_ptr, mapValues_ptr); + }) } -jintArray -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaFpConstNodeGetBitsUIntArray(JNIEnv* env, jobject native_class, - jlong bitwuzla, jlong bitwuzla_term) { - BZLA_TRY_OR_NULL({ - auto bzla = bitwuzla_extension_get_bzla(BZLA); - auto fp = bitwuzla_extension_node_fp_const_get_fp(TERM(bitwuzla_term)); - const BzlaBitVector* bw_vector = bitwuzla_extension_fp_bits_as_bv_bits(bzla, fp); +void Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerms(JNIEnv *env, jclass native_class, jlongArray terms, jlongArray mapKeys, jlongArray mapValues) { + BZLA_TRY_VOID({ + GET_PTR_ARRAY(BitwuzlaTerm, terms_ptr, terms); + jsize terms_size = env->GetArrayLength(terms); - return get_bv_bits_as_jint_array(env, bitwuzla, bw_vector); - }) -} + GET_PTR_ARRAY(BitwuzlaTerm, mapKeys_ptr, mapKeys); + GET_PTR_ARRAY(BitwuzlaTerm, mapValues_ptr, mapValues); + jsize map_size = env->GetArrayLength(mapKeys); + bitwuzla_substitute_terms((size_t) terms_size, terms_ptr, map_size, mapKeys_ptr, mapValues_ptr); + }) +} diff --git a/ksmt-bitwuzla/bindings-native/bitwuzla_jni.hpp b/ksmt-bitwuzla/bindings-native/bitwuzla_jni.hpp deleted file mode 100644 index 645862b77..000000000 --- a/ksmt-bitwuzla/bindings-native/bitwuzla_jni.hpp +++ /dev/null @@ -1,567 +0,0 @@ -#include - -#ifndef _Included_bitwuzla_jni -#define _Included_bitwuzla_jni -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaInit - (JNIEnv* env, jobject native_class); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaNew - (JNIEnv* env, jobject native_class); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaDelete - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaReset - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCopyright - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaVersion - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGitId - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOption - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint bitwuzla_option, jint value); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOptionStr - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint bitwuzla_option, jstring value); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOption - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint bitwuzla_option); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOptionStr - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint bitwuzla_option); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkArraySort - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong index, jlong element); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBoolSort - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvSort - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint size); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpSort - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint exp_size, jint sig_size); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFunSort - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint arity, jlongArray domain, jlong codomain); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmSort - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTrue - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFalse - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvZero - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOne - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOnes - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMinSigned - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMaxSigned - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosZero - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegZero - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosInf - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegInf - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNan - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort, jstring value, jint base); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueUint32 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort, jint value); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_bvSign, jlong bitwuzla_bvExponent, - jlong bitwuzla_bvSignificand); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValueFromReal - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong sort, jlong rm, jstring real); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValueFromRational - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong sort, jlong rm, jstring num, jstring den); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint rm); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong arg); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong arg0, jlong arg1); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm3 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong arg0, jlong arg1, jlong arg2); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlongArray args); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed1 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong term, jint idx); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed2 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong term, jint idx0, jint idx1); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed1 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong term0, jlong term1, jint idx0); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed2 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlong term0, jlong term1, jint idx0, jint idx1); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTermIndexed - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint kind, jlongArray args, jintArray idxs); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConst - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort, jstring symbol); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConstArray - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort, jlong value); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkVar - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_sort, jstring symbol); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPush - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint n_levels); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPop - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint n_levels); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaAssert - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong term); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaAssume - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaIsUnsatAssumption - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong term); - -JNIEXPORT jlongArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatAssumptions - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jlongArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatCore - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaFixateAssumptions - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaResetAssumptions - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSimplify - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSat - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatTimeout - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong timeout); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaForceTerminate - (JNIEnv* env, jobject native_class, jlong bitwuzla); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetBvValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jobject JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetFpValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetRmValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jobject JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetArrayValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jobject JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetFunValue - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerm - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term, - jlongArray map_keys, jlongArray map_values); - -JNIEXPORT jlongArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerms - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlongArray terms, - jlongArray map_keys, jlongArray map_values); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortHash - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetKind - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlongArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetChildren - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jintArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetIndices - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortBvGetSize - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetExpSize - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetSigSize - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetIndex - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetElement - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jlongArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetDomainSorts - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetCodomain - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetArity - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsEqual - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort_1, jlong bitwuzla_sort_2); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsArray - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsBv - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFp - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFun - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsRm - (JNIEnv* env, jobject native_class, jlong bitwuzla_sort); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermHash - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsIndexed - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetBitwuzla - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSort - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetIndexSort - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetElementSort - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlongArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetDomainSorts - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetCodomainSort - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermBvGetSize - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetExpSize - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetSigSize - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetArity - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSymbol - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermSetSymbol - (JNIEnv* env, jobject native_class, jlong bitwuzla_term, jstring symbol); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsEqualSort - (JNIEnv* env, jobject native_class, jlong bitwuzla_term_1, jlong bitwuzla_term_2); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsArray - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsConst - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFun - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsVar - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBoundVar - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsValue - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValue - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValue - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValue - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBv - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFp - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRm - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueZero - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOne - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOnes - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMinSigned - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMaxSigned - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosZero - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegZero - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosInf - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegInf - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNan - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRna - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRne - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtn - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtp - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtz - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT jboolean JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsConstArray - (JNIEnv* env, jobject native_class, jlong bitwuzla_term); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPrintModel - (JNIEnv* env, jobject native_class, jlong bitwuzla, jstring format, jstring file_path); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortDump - (JNIEnv* env, jobject native_class, jlong sort, jstring format); - -JNIEXPORT jstring JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermDump - (JNIEnv* env, jobject native_class, jlong term, jstring format); - -JNIEXPORT void JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaDumpFormula - (JNIEnv* env, jobject native_class, jlong bitwuzla, jstring format, jstring file_path); - -JNIEXPORT jlong JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueUint32Array - (JNIEnv* env, jobject native_class, jlong bitwuzla, jint bv_width, jintArray value); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaBvConstNodeGetBitsUInt32 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jintArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaBvConstNodeGetBitsUIntArray - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jint JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaFpConstNodeGetBitsUInt32 - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -JNIEXPORT jintArray JNICALL -Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaFpConstNodeGetBitsUIntArray - (JNIEnv* env, jobject native_class, jlong bitwuzla, jlong bitwuzla_term); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/ksmt-bitwuzla/bindings-native/bitwuzla_patch.patch b/ksmt-bitwuzla/bindings-native/bitwuzla_patch.patch new file mode 100644 index 000000000..e008e0f53 --- /dev/null +++ b/ksmt-bitwuzla/bindings-native/bitwuzla_patch.patch @@ -0,0 +1,159 @@ +diff --git a/include/bitwuzla/c/bitwuzla.h b/include/bitwuzla/c/bitwuzla.h +index 2870e868..007f9d58 100644 +--- a/include/bitwuzla/c/bitwuzla.h ++++ b/include/bitwuzla/c/bitwuzla.h +@@ -2007,6 +2007,14 @@ void bitwuzla_substitute_terms(size_t terms_size, + + /** @} */ + ++void bitwuzla_sort_dec_ref(BitwuzlaSort sort_id); ++ ++void bitwuzla_term_dec_ref(BitwuzlaTerm term_id); ++ ++uint64_t bitwuzla_bv_value_uint64(BitwuzlaTerm term); ++ ++const char *bitwuzla_bv_value_str(BitwuzlaTerm term, uint32_t base); ++ + #if __cplusplus + } + #endif +diff --git a/src/api/c/bitwuzla.cpp b/src/api/c/bitwuzla.cpp +index ece639cc..5c3175f7 100644 +--- a/src/api/c/bitwuzla.cpp ++++ b/src/api/c/bitwuzla.cpp +@@ -2069,3 +2069,56 @@ bitwuzla_term_print_fmt(BitwuzlaTerm term, FILE *file, uint8_t base) + } + + /* -------------------------------------------------------------------------- */ ++ ++#include "node/node.h" ++#include "bv/bitvector.h" ++ ++namespace bitwuzla { ++ template<> ++ bzla::BitVector ++ Term::value(uint8_t base) const { ++ (void) base; ++ BITWUZLA_CHECK_NOT_NULL(d_node); ++ BITWUZLA_CHECK_TERM_IS_BV_VALUE(*this); ++ return d_node->value(); ++ } ++} ++ ++void bitwuzla_sort_dec_ref(BitwuzlaSort sort_id) { ++ Bitwuzla::SortMap &sort_map = Bitwuzla::sort_map(); ++ const auto it = sort_map.find(sort_id); ++ it->second.second -= 1; ++ if (it->second.second == 0) { ++ it->second.first.reset(); ++ sort_map.erase(it); ++ } ++} ++ ++void bitwuzla_term_dec_ref(BitwuzlaTerm term_id) { ++ Bitwuzla::TermMap &term_map = Bitwuzla::term_map(); ++ const auto it = term_map.find(term_id); ++ it->second.second -= 1; ++ if (it->second.second == 0) { ++ it->second.first.reset(); ++ term_map.erase(it); ++ } ++} ++ ++uint64_t bitwuzla_bv_value_uint64(BitwuzlaTerm term) { ++ uint64_t res = false; ++ BITWUZLA_TRY_CATCH_BEGIN; ++ BITWUZLA_CHECK_TERM_ID(term); ++ bzla::BitVector bv = import_term(term).value(); ++ res = bv.to_uint64(); ++ BITWUZLA_TRY_CATCH_END; ++ return res; ++} ++ ++const char *bitwuzla_bv_value_str(BitwuzlaTerm term, uint32_t base) { ++ static thread_local std::string res; ++ BITWUZLA_TRY_CATCH_BEGIN; ++ BITWUZLA_CHECK_TERM_ID(term); ++ res = import_term(term).value().str(base); ++ BITWUZLA_TRY_CATCH_END; ++ return res.c_str(); ++} +diff --git a/src/api/c/checks.h b/src/api/c/checks.h +index 63a26fff..60be3ed8 100644 +--- a/src/api/c/checks.h ++++ b/src/api/c/checks.h +@@ -47,7 +47,7 @@ class BitwuzlaAbortStream + { + stream() << msg_prefix << " "; + } +- ~BitwuzlaAbortStream() ++ ~BitwuzlaAbortStream() noexcept(false) + { + flush(); + bitwuzla_abort(d_stream.str().c_str()); +diff --git a/src/lib/meson.build b/src/lib/meson.build +index 7380e24c..38fcb022 100644 +--- a/src/lib/meson.build ++++ b/src/lib/meson.build +@@ -32,19 +32,19 @@ rng_lib = static_library('bzlarng', + dependencies: gmp_dep) + + # Bitwuzla bit-vector, bit-blast and local search libraries +-bitvector_lib = library('bitwuzlabv', ++bitvector_lib = static_library('bitwuzlabv', + sources: bv_sources, + link_whole: rng_lib, + dependencies: gmp_dep, + install_rpath: install_rpath, + install: true) +-bitblast_lib = library('bitwuzlabb', ++bitblast_lib = static_library('bitwuzlabb', + sources: bb_sources, + link_with: bitvector_lib, + dependencies: gmp_dep, + install_rpath: install_rpath, + install: true) +-local_search_lib = library('bitwuzlals', ++local_search_lib = static_library('bitwuzlals', + sources: ls_sources, + link_with: [bitvector_lib], + link_whole: rng_lib, +diff --git a/src/meson.build b/src/meson.build +index ddabc8e8..2260419b 100644 +--- a/src/meson.build ++++ b/src/meson.build +@@ -9,7 +9,7 @@ cpp_compiler = meson.get_compiler('cpp') + gmp_dep = dependency('gmp', + version: '>=6.1', + required: true, +- static: build_static) ++ static: true) + + + # Subproject dependencies +@@ -195,15 +195,23 @@ endif + # Public header include directory + bitwuzla_inc = include_directories('../include', 'lib') + ++ ++link_args = [] ++if host_machine.system() == 'windows' ++ link_args += ['-static-libstdc++', '-static-libgcc', '-Wl,-Bstatic', '-lstdc++', '-lpthread', '-Wl,-Bdynamic'] ++endif ++ + bitwuzla_lib = library('bitwuzla', + sources, + include_directories: bitwuzla_inc, + link_with: support_libs, + dependencies: dependencies, +- soversion: bitwuzla_lib_soversion, ++ #soversion: bitwuzla_lib_soversion, + install_rpath: install_rpath, + install: true, +- cpp_args: cpp_args) ++ cpp_args: cpp_args, ++ link_args: link_args ++ ) + + # Create library dependency + bitwuzla_dep = declare_dependency(include_directories: bitwuzla_inc, diff --git a/ksmt-bitwuzla/bindings-native/build.sh b/ksmt-bitwuzla/bindings-native/build.sh new file mode 100644 index 000000000..8b50f7882 --- /dev/null +++ b/ksmt-bitwuzla/bindings-native/build.sh @@ -0,0 +1,65 @@ +# Below specified build under linux (lib + jni bindings). +# +# To build under Windows, we have to add "--win64" option to ./configure.py (it picks up the cross-compile file). +# As host, the lib can be built under linux using cross-compilation tools with mingw-w64 +# (Actually, the size of libbitwuzla.dll built under linux is terrible ~17 MB. +# Therefore, it's better to build bitwuzla in MSYS2 and Windows as host directly ~7 MB). +# As for jni bindings, we need MSYS2 with MinGW shell under Windows +# + +JAVA_HOME="/usr/lib/jvm/default" # or another path to Java 8 + +# https://github.com/bitwuzla/bitwuzla/commit/b655bc0cde570258367bf8f09a113bc7b95e46e9 +git clone https://github.com/bitwuzla/bitwuzla +cd bitwuzla +git checkout b655bc0cde570258367bf8f09a113bc7b95e46e9 + +# +# Patch description +# +# 1. Added noexcept(false) in BitwuzlaAbortStream destructor (src/api/c/checks.h) +# because there is abortion callback is called and it can throw any (see abort_callback impl in bitwuzla_jni.cpp). +# +# 2. Added extension functions (such as on sort/term dec external references, bitvector string/uint64 representation) +# declarations (include/bitwuzla/c/bitwuzla.h) and definitions (src/api/c/bitwuzla.cpp) +# +# 3. Meson build files: gmp, bitblast_lib, bitvector_lib, local_search_lib - static linkage specified, +# removed version of final .so lib (we will have libbitwuzla.so instead of libbitwuzla.so.0). +# Also added linker options for Windows build (static linkage with platform libs) +# + +git apply ../bitwuzla_patch.patch + + +# If you build bitwuzla for Windows, apply win_bv_gmp_long_patch.patch +# until [bitwuzla issue#85](https://github.com/bitwuzla/bitwuzla/issues/85) fixed. +# Patch description: +# 1. Replaced GMP functions that accept/return data of `long` type, which is actually 32-bits (LLP64 data model) +# because bitwuzla expects 64-bits data there. +#git apply ../win_bv_gmp_long_patch.patch + + +# build bitwuzla + +# uncomment if you want to build with python as venv (meson and ninja are needed) +python -m venv ./venv +source venv/bin/activate +pip install meson +# + +rm -r build +./configure.py release --shared +cd build && meson compile + +# build JNI + +cd ../.. +rm -r build +mkdir build && cd build +cmake .. +make + + +# Done +# look for libbitwuzla.so in ./bitwuzla/build/src/libbitwuzla.so +# look for libbitwuzla_jni.so in ./build/libbitwuzla_jni.so diff --git a/ksmt-bitwuzla/bindings-native/include/bitwuzla_extension.hpp b/ksmt-bitwuzla/bindings-native/include/bitwuzla_extension.hpp new file mode 100644 index 000000000..62c645107 --- /dev/null +++ b/ksmt-bitwuzla/bindings-native/include/bitwuzla_extension.hpp @@ -0,0 +1,17 @@ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +void bitwuzla_extension_sort_dec_ref(BitwuzlaSort sort_id); + +void bitwuzla_extension_term_dec_ref(BitwuzlaTerm term_id); + +uint64_t bitwuzla_extension_bv_value_uint64(BitwuzlaTerm term); + +const char *bitwuzla_extension_bv_value_str(BitwuzlaTerm term, uint32_t base); + +#if __cplusplus +} +#endif diff --git a/ksmt-bitwuzla/bindings-native/include/bitwuzla_jni.hpp b/ksmt-bitwuzla/bindings-native/include/bitwuzla_jni.hpp new file mode 100644 index 000000000..393908a40 --- /dev/null +++ b/ksmt-bitwuzla/bindings-native/include/bitwuzla_jni.hpp @@ -0,0 +1,1155 @@ +/* + * DO NOT EDIT THIS FILE - it is machine generated + * from org.ksmt.solver.bitwuzla.bindings.Native.kt (javac -h) +*/ +#include +/* Header for class org_ksmt_solver_bitwuzla_bindings_Native */ + +#ifndef _Included_org_ksmt_solver_bitwuzla_bindings_Native +#define _Included_org_ksmt_solver_bitwuzla_bindings_Native +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaInit + * Signature: ()J + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaInit + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermDecRef + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermDecRef +(JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortDecRef + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortDecRef +(JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaForceTerminate + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaForceTerminate +(JNIEnv* env, jobject native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaCopyright + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCopyright + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaVersion + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaVersion + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGitId + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGitId + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaOptionsNew + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionsNew + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaOptionsDelete + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionsDelete + (JNIEnv *env, jclass native_class, jlong); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaOptionIsNumeric + * Signature: (JI)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionIsNumeric + (JNIEnv *env, jclass native_class, jlong options, jint option); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaOptionIsMode + * Signature: (JI)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaOptionIsMode + (JNIEnv *env, jclass native_class, jlong options, jint option); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSetOption + * Signature: (JIJ)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOption + (JNIEnv *env, jclass native_class, jlong options, jint option, jlong value); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSetOptionMode + * Signature: (JILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSetOptionMode + (JNIEnv *env, jclass native_class, jlong options, jint option, jstring value); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetOption + * Signature: (JI)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOption + (JNIEnv *env, jclass native_class, jlong options, jint option); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetOptionMode + * Signature: (JI)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetOptionMode + (JNIEnv *env, jclass native_class, jlong options, jint option); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortHash + * Signature: (J)I + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortHash + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortBvGetSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortBvGetSize + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortFpGetExpSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetExpSize + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortFpGetSigSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFpGetSigSize + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortArrayGetIndex + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetIndex + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortArrayGetElement + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortArrayGetElement + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortFunGetDomainSorts + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetDomainSorts + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortFunGetCodomain + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetCodomain + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortFunGetArity + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortFunGetArity + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortGetUninterpretedSymbol + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortGetUninterpretedSymbol + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsEqual + * Signature: (JJ)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsEqual + (JNIEnv *env, jclass native_class, jlong sort0, jlong sort1); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsArray + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsArray + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsBool + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsBool + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsBv + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsBv + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsFp + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFp + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsFun + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsFun + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsRm + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsRm + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortIsUninterpreted + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortIsUninterpreted + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSortToString + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSortToString + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermHash + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermHash + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermGetKindNative + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetKindNative + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermGetChildren + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetChildren + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermGetIndices + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetIndices + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsIndexed + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsIndexed + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermGetSort + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSort + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermArrayGetIndexSort + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetIndexSort + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermArrayGetElementSort + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermArrayGetElementSort + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermFunGetDomainSorts + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetDomainSorts + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermFunGetCodomainSort + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetCodomainSort + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermBvGetSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermBvGetSize + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermFpGetExpSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetExpSize + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermFpGetSigSize + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFpGetSigSize + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermFunGetArity + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermFunGetArity + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermGetSymbol + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermGetSymbol + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsEqualSort + * Signature: (JJ)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsEqualSort + (JNIEnv *env, jclass native_class, jlong term0, jlong term1); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsArray + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsArray + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsConst + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsConst + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFun + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFun + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsVar + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsVar + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsValue + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsValue + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBvValue + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValue + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFpValue + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValue + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRmValue + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValue + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBool + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBool + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBv + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBv + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFp + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFp + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRm + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRm + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsUninterpreted + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsUninterpreted + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsTrue + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsTrue + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFalse + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFalse + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBvValueZero + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueZero + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBvValueOne + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOne + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBvValueOnes + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueOnes + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBvValueMinSigned + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMinSigned + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsBvValueMaxSigned + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsBvValueMaxSigned + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFpValuePosZero + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosZero + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFpValueNegZero + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegZero + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFpValuePosInf + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValuePosInf + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFpValueNegInf + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNegInf + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsFpValueNan + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsFpValueNan + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRmValueRna + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRna + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRmValueRne + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRne + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRmValueRtn + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtn + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRmValueRtp + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtp + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermIsRmValueRtz + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermIsRmValueRtz + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermValueGetBool + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetBool + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermValueGetStr + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetStr + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermValueGetStrFmt + * Signature: (JB)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetStrFmt + (JNIEnv *env, jclass native_class, jlong term, jbyte base); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermValueGetRm + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermValueGetRm + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermToString + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermToString + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaTermToStringFmt + * Signature: (JB)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaTermToStringFmt + (JNIEnv *env, jclass native_class, jlong term, jbyte base); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaNew + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaNew + (JNIEnv *env, jclass native_class, jlong options); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaDelete + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaDelete + (JNIEnv *env, jclass native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaPush + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPush + (JNIEnv *env, jclass native_class, jlong bitwuzla, jlong nlevels); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaPop + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaPop + (JNIEnv *env, jclass native_class, jlong bitwuzla, jlong nlevels); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaAssert + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaAssert + (JNIEnv *env, jclass native_class, jlong bitwuzla, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetAssertions + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetAssertions + (JNIEnv *env, jclass native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaIsUnsatAssumption + * Signature: (JJ)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaIsUnsatAssumption + (JNIEnv *env, jclass native_class, jlong bitwuzla, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetUnsatAssumptions + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatAssumptions + (JNIEnv *env, jclass native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetUnsatCore + * Signature: (J)[J + */ +JNIEXPORT jlongArray JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetUnsatCore + (JNIEnv *env, jclass native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSimplify + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSimplify + (JNIEnv *env, jclass native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaCheckSatNative + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatNative + (JNIEnv *env, jclass native_class, jlong bitwuzla); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaCheckSatAssumingNative + * Signature: (J[J)I + */ +JNIEXPORT jint JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatAssumingNative + (JNIEnv *env, jclass native_class, jlong bitwuzla, jlongArray args); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaCheckSatTimeout + * Signature: (J[JJ)I + */ +JNIEXPORT jint JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaCheckSatTimeout + (JNIEnv* env, jobject native_class, jlong bitwuzla, jlongArray args, jlong timeout); + + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetValue + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetValue + (JNIEnv *env, jclass native_class, jlong bitwuzla, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetBvValueUInt64 + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetBvValueUInt64 + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetBvValueString + */ +JNIEXPORT jstring JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetBvValueString + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaGetFpValue + */ +JNIEXPORT jobject JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaGetFpValue + (JNIEnv *env, jclass native_class, jlong term); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkArraySort + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkArraySort + (JNIEnv *env, jclass native_class, jlong index, jlong element); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBoolSort + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBoolSort + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvSort + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvSort + (JNIEnv *env, jclass native_class, jlong size); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpSort + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpSort + (JNIEnv *env, jclass native_class, jlong expSize, jlong sigSize); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFunSort + * Signature: ([JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFunSort + (JNIEnv *env, jclass native_class, jlongArray domain, jlong codomain); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkRmSort + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmSort + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkUninterpretedSort + * Signature: (Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkUninterpretedSort + (JNIEnv *env, jclass native_class, jstring symbol); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTrue + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTrue + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFalse + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFalse + (JNIEnv *env, jclass native_class); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvZero + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvZero + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvOne + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOne + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvOnes + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvOnes + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvMinSigned + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMinSigned + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvMaxSigned + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvMaxSigned + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpPosZero + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosZero + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpNegZero + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegZero + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpPosInf + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpPosInf + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpNegInf + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNegInf + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpNan + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpNan + (JNIEnv *env, jclass native_class, jlong sort); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvValue + * Signature: (JLjava/lang/String;B)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValue + (JNIEnv *env, jclass native_class, jlong sort, jstring value, jbyte base); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvValueUint64 + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueUint64 + (JNIEnv *env, jclass native_class, jlong sort, jlong value); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkBvValueInt64 + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkBvValueInt64 + (JNIEnv *env, jclass native_class, jlong sort, jlong value); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpValue + * Signature: (JJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpValue + (JNIEnv *env, jclass native_class, jlong bvSign, jlong bvExponent, jlong bvSignificand); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpFromReal + * Signature: (JJLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpFromReal + (JNIEnv *env, jclass native_class, jlong sort, jlong rm, jstring real); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkFpFromRational + * Signature: (JJLjava/lang/String;Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkFpFromRational + (JNIEnv *env, jclass native_class, jlong sort, jlong rm, jstring num, jstring den); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkRmValue + * Signature: (I)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkRmValue + (JNIEnv *env, jclass native_class, jint rm); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm1 + * Signature: (IJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1 + (JNIEnv *env, jclass native_class, jint kind, jlong arg); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm2 + * Signature: (IJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2 + (JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm3 + * Signature: (IJJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm3 + (JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1, jlong arg2); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm + * Signature: (I[J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm + (JNIEnv *env, jclass native_class, jint kind, jlongArray args); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm1Indexed1 + * Signature: (IJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed1 + (JNIEnv *env, jclass native_class, jint kind, jlong arg, jlong idx); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm1Indexed2 + * Signature: (IJJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm1Indexed2 + (JNIEnv *env, jclass native_class, jint kind, jlong arg, jlong idx0, jlong idx1); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm2Indexed1 + * Signature: (IJJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed1 + (JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1, jlong idx); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTerm2Indexed2 + * Signature: (IJJJJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTerm2Indexed2 + (JNIEnv *env, jclass native_class, jint kind, jlong arg0, jlong arg1, jlong idx0, jlong idx1); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkTermIndexed + * Signature: (I[J[J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkTermIndexed + (JNIEnv *env, jclass native_class, jint kind, jlongArray args, jlongArray idxs); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkConst + * Signature: (JLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConst + (JNIEnv *env, jclass native_class, jlong sort, jstring symbol); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkConstArray + * Signature: (JJ)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkConstArray + (JNIEnv *env, jclass native_class, jlong sort, jlong value); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaMkVar + * Signature: (JLjava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaMkVar + (JNIEnv *env, jclass native_class, jlong sort, jstring symbol); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSubstituteTerm + * Signature: (J[J[J)J + */ +JNIEXPORT jlong JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerm + (JNIEnv *env, jclass native_class, jlong term, jlongArray mapKeys, jlongArray mapValues); + +/* + * Class: org_ksmt_solver_bitwuzla_bindings_Native + * Method: bitwuzlaSubstituteTerms + * Signature: ([J[J[J)V + */ +JNIEXPORT void JNICALL Java_org_ksmt_solver_bitwuzla_bindings_Native_bitwuzlaSubstituteTerms + (JNIEnv *env, jclass native_class, jlongArray terms, jlongArray mapKeys, jlongArray mapValues); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ksmt-bitwuzla/bindings-native/win_bv_gmp_long_patch.patch b/ksmt-bitwuzla/bindings-native/win_bv_gmp_long_patch.patch new file mode 100644 index 000000000..10d67d8e4 --- /dev/null +++ b/ksmt-bitwuzla/bindings-native/win_bv_gmp_long_patch.patch @@ -0,0 +1,357 @@ +diff --git a/src/lib/bv/bitvector.cpp b/src/lib/bv/bitvector.cpp +index 5a895684..d83c0acc 100644 +--- a/src/lib/bv/bitvector.cpp ++++ b/src/lib/bv/bitvector.cpp +@@ -96,7 +96,15 @@ BitVector::fits_in_size(uint64_t size, const std::string& str, uint32_t base) + } + else + { ++ // We shouldn't pass uint64 as "unsigned long int" in mpz_cmp_ui on Windows, because it's truncated to 32 bits ++#ifdef __MINGW64__ ++ mpz_t min_int; ++ mpz_init_set_str(min_int, min.str(2).c_str(), 2); ++ res = mpz_cmp(tmp, min_int) <= 0; ++ mpz_clear(min_int); ++#else + res = mpz_cmp_ui(tmp, min.d_val_uint64) <= 0; ++#endif + } + } + else +@@ -108,7 +116,15 @@ BitVector::fits_in_size(uint64_t size, const std::string& str, uint32_t base) + } + else + { ++ // We shouldn't pass uint64 as "unsigned long int" in mpz_cmp_ui on Windows, because it's truncated to 32 bits ++#ifdef __MINGW64__ ++ mpz_t max_int; ++ mpz_init_set_str(max_int, max.str(2).c_str(), 2); ++ res = mpz_cmp(tmp, max_int) <= 0; ++ mpz_clear(max_int); ++#else + res = mpz_cmp_ui(tmp, max.d_val_uint64) <= 0; ++#endif + } + } + mpz_clear(tmp); +@@ -124,7 +140,12 @@ BitVector::fits_in_size(uint64_t size, uint64_t value, bool sign) + } + mpz_t tmp; + /* We do not want to normalize to 'size'. */ ++ // We shouldn't pass uint64 as "unsigned long int" in mpz_init_set_ui on Windows, because it's truncated to 32 bits ++#ifdef __MINGW64__ ++ mpz_init_set_str(tmp, std::to_string((uint64_t) value).c_str(), 10); ++#else + mpz_init_set_ui(tmp, value); ++#endif + bool res = size >= mpz_sizeinbase(tmp, 2); + mpz_clear(tmp); + return res; +@@ -311,7 +332,11 @@ BitVector::from_ui(uint64_t size, uint64_t value, bool truncate) + BitVector res(size); + if (res.is_gmp()) + { ++#ifdef __MINGW64__ ++ mpz_init_set_str(res.d_val_gmp, std::to_string(value).c_str(), 10); ++#else + mpz_init_set_ui(res.d_val_gmp, value); ++#endif + mpz_fdiv_r_2exp(res.d_val_gmp, res.d_val_gmp, size); + } + else +@@ -331,7 +356,11 @@ BitVector::from_si(uint64_t size, int64_t value, bool truncate) + BitVector res(size); + if (res.is_gmp()) + { ++#ifdef __MINGW64__ ++ mpz_init_set_str(res.d_val_gmp, std::to_string(value).c_str(), 10); ++#else + mpz_init_set_si(res.d_val_gmp, value); ++#endif + mpz_fdiv_r_2exp(res.d_val_gmp, res.d_val_gmp, size); + } + else +@@ -510,7 +539,11 @@ BitVector::iset(uint64_t value) + assert(d_size); + if (is_gmp()) + { ++#ifdef __MINGW64__ ++ mpz_init_set_str(d_val_gmp, std::to_string(value).c_str(), 10); ++#else + mpz_set_ui(d_val_gmp, value); ++#endif + mpz_fdiv_r_2exp(d_val_gmp, d_val_gmp, d_size); + } + else +@@ -644,7 +677,19 @@ BitVector::to_uint64(bool truncate) const + assert(truncate || d_size <= 64); + if (is_gmp()) + { ++#ifdef __MINGW64__ ++ char *tmp = mpz_get_str(nullptr, 10, d_val_gmp); ++ std::string val_str = tmp; ++ uint64_t ret_val = (uint64_t) std::stoll(val_str); ++ ++ void (*freefunc)(void *, size_t); ++ mp_get_memory_functions(nullptr, nullptr, &freefunc); ++ ++ freefunc(tmp, std::strlen(tmp) + 1); ++ return ret_val; ++#else + return mpz_get_ui(d_val_gmp); ++#endif + } + return d_val_uint64; + } +@@ -896,8 +941,16 @@ BitVector::is_uadd_overflow(const BitVector& bv) const + } + else + { ++#ifdef __MINGW64__ ++ mpz_init_set_str(add, std::to_string(d_val_uint64).c_str(), 10); ++ mpz_t bv_gmp; ++ mpz_init_set_str(bv_gmp, std::to_string(bv.d_val_uint64).c_str(), 10); ++ mpz_add(add, add, bv_gmp); ++ mpz_clear(bv_gmp); ++#else + mpz_init_set_ui(add, d_val_uint64); + mpz_add_ui(add, add, bv.d_val_uint64); ++#endif + } + mpz_fdiv_q_2exp(add, add, d_size); + bool res = mpz_cmp_ui(add, 0) != 0; +@@ -920,8 +973,18 @@ BitVector::is_umul_overflow(const BitVector& bv) const + } + else + { ++#ifdef __MINGW64__ ++ mpz_t bv_gmp; ++ mpz_init_set_str(bv_gmp, std::to_string(bv.d_val_uint64).c_str(), 10); ++ ++ mpz_init_set_str(mul, std::to_string(d_val_uint64).c_str(), 10); ++ mpz_mul(mul, mul, bv_gmp); ++ ++ mpz_clear(bv_gmp); ++#else + mpz_init_set_ui(mul, d_val_uint64); + mpz_mul_ui(mul, mul, bv.d_val_uint64); ++#endif + } + mpz_fdiv_q_2exp(mul, mul, d_size); + bool res = mpz_cmp_ui(mul, 0) != 0; +@@ -2345,7 +2408,11 @@ BitVector::ibvconcat(const BitVector& bv0, const BitVector& bv1) + } + else + { ++#ifdef __MINGW64__ ++ mpz_set_str(d_val_gmp, std::to_string(b0->d_val_uint64).c_str(), 10); ++#else + mpz_set_ui(d_val_gmp, b0->d_val_uint64); ++#endif + } + mpz_mul_2exp(d_val_gmp, d_val_gmp, b1->d_size); + if (b1->is_gmp()) +@@ -2354,7 +2421,14 @@ BitVector::ibvconcat(const BitVector& bv0, const BitVector& bv1) + } + else + { ++#ifdef __MINGW64__ ++ mpz_t b1_gmp; ++ mpz_init_set_str(b1_gmp, std::to_string(b1->d_val_uint64).c_str(), 10); ++ mpz_add(d_val_gmp, d_val_gmp, b1_gmp); ++ mpz_clear(b1_gmp); ++#else + mpz_add_ui(d_val_gmp, d_val_gmp, b1->d_val_uint64); ++#endif + } + mpz_fdiv_r_2exp(d_val_gmp, d_val_gmp, size); + } +@@ -2387,13 +2461,29 @@ BitVector::ibvextract(const BitVector& bv, uint64_t idx_hi, uint64_t idx_lo) + } + else + { ++#ifdef __MINGW64__ ++ mpz_set_str(d_val_gmp, std::to_string(bv.d_val_uint64).c_str(), 10); ++#else + mpz_set_ui(d_val_gmp, bv.d_val_uint64); ++#endif + } + mpz_fdiv_r_2exp(d_val_gmp, d_val_gmp, idx_hi + 1); + mpz_fdiv_q_2exp(d_val_gmp, d_val_gmp, idx_lo); + if (size <= 64) + { ++#ifdef __MINGW64__ ++ char *d_val_str_tmp = mpz_get_str(nullptr, 10, d_val_gmp); ++ std::string d_val_str = d_val_str_tmp; ++ ++ uint64_t val = (uint64_t) std::stoll(d_val_str); ++ ++ void (*freefunc)(void *, size_t); ++ mp_get_memory_functions(nullptr, nullptr, &freefunc); ++ ++ freefunc(d_val_str_tmp, std::strlen(d_val_str_tmp) + 1); ++#else + uint64_t val = mpz_get_ui(d_val_gmp); ++#endif + mpz_clear(d_val_gmp); + d_val_uint64 = val; + } +@@ -2409,7 +2499,11 @@ BitVector::ibvextract(const BitVector& bv, uint64_t idx_hi, uint64_t idx_lo) + } + else + { ++#ifdef __MINGW64__ ++ mpz_set_str(d_val_gmp, std::to_string(bv.d_val_uint64).c_str(), 10); ++#else + mpz_set_ui(d_val_gmp, bv.d_val_uint64); ++#endif + } + mpz_fdiv_r_2exp(d_val_gmp, d_val_gmp, idx_hi + 1); + mpz_fdiv_q_2exp(d_val_gmp, d_val_gmp, idx_lo); +@@ -2422,7 +2516,19 @@ BitVector::ibvextract(const BitVector& bv, uint64_t idx_hi, uint64_t idx_lo) + mpz_init_set(tmp, bv.d_val_gmp); + mpz_fdiv_r_2exp(tmp, tmp, idx_hi + 1); + mpz_fdiv_q_2exp(tmp, tmp, idx_lo); ++#ifdef __MINGW64__ ++ char *d_val_str_tmp = mpz_get_str(nullptr, 10, tmp); ++ std::string d_val_str = d_val_str_tmp; ++ ++ d_val_uint64 = (uint64_t) std::stoll(d_val_str); ++ ++ void (*freefunc)(void *, size_t); ++ mp_get_memory_functions(nullptr, nullptr, &freefunc); ++ ++ freefunc(d_val_str_tmp, std::strlen(d_val_str_tmp) + 1); ++#else + d_val_uint64 = mpz_get_ui(tmp); ++#endif + mpz_clear(tmp); + } + else +@@ -2453,11 +2559,27 @@ BitVector::ibvzext(const BitVector& bv, uint64_t n) + } + else + { ++#ifdef __MINGW64__ ++ mpz_set_str(d_val_gmp, std::to_string(bv.d_val_uint64).c_str(), 10); ++#else + mpz_set_ui(d_val_gmp, bv.d_val_uint64); ++#endif + } + if (size <= 64) + { ++#ifdef __MINGW64__ ++ char *d_val_str_tmp = mpz_get_str(nullptr, 10, d_val_gmp); ++ std::string d_val_str = d_val_str_tmp; ++ ++ uint64_t val = (uint64_t) std::stoll(d_val_str); ++ ++ void (*freefunc)(void *, size_t); ++ mp_get_memory_functions(nullptr, nullptr, &freefunc); ++ ++ freefunc(d_val_str_tmp, std::strlen(d_val_str_tmp) + 1); ++#else + uint64_t val = mpz_get_ui(d_val_gmp); ++#endif + mpz_clear(d_val_gmp); + d_val_uint64 = val; + } +@@ -2485,7 +2607,11 @@ BitVector::ibvzext(const BitVector& bv, uint64_t n) + } + else + { ++#ifdef __MINGW64__ ++ mpz_set_str(d_val_gmp, std::to_string(b->d_val_uint64).c_str(), 10); ++#else + mpz_set_ui(d_val_gmp, b->d_val_uint64); ++#endif + } + } + else +@@ -2532,12 +2658,31 @@ BitVector::ibvsext(const BitVector& bv, uint64_t n) + } + else + { ++#ifdef __MINGW64__ ++ mpz_t b_gmp; ++ mpz_init_set_str(b_gmp, std::to_string(b->d_val_uint64).c_str(), 10); ++ mpz_add(d_val_gmp, d_val_gmp, b_gmp); ++ mpz_clear(b_gmp); ++#else + mpz_add_ui(d_val_gmp, d_val_gmp, b->d_val_uint64); ++#endif + } + mpz_fdiv_r_2exp(d_val_gmp, d_val_gmp, size); + if (size <= 64) + { ++#ifdef __MINGW64__ ++ char *d_val_str_tmp = mpz_get_str(nullptr, 10, d_val_gmp); ++ std::string d_val_str = d_val_str_tmp; ++ ++ uint64_t val = (uint64_t) std::stoll(d_val_str); ++ ++ void (*freefunc)(void *, size_t); ++ mp_get_memory_functions(nullptr, nullptr, &freefunc); ++ ++ freefunc(d_val_str_tmp, std::strlen(d_val_str_tmp) + 1); ++#else + uint64_t val = mpz_get_ui(d_val_gmp); ++#endif + mpz_clear(d_val_gmp); + d_val_uint64 = val; + } +@@ -2556,7 +2701,14 @@ BitVector::ibvsext(const BitVector& bv, uint64_t n) + } + else + { ++#ifdef __MINGW64__ ++ mpz_t b_gmp; ++ mpz_init_set_str(b_gmp, std::to_string(b->d_val_uint64).c_str(), 10); ++ mpz_add(d_val_gmp, d_val_gmp, b_gmp); ++ mpz_clear(b_gmp); ++#else + mpz_add_ui(d_val_gmp, d_val_gmp, b->d_val_uint64); ++#endif + } + mpz_fdiv_r_2exp(d_val_gmp, d_val_gmp, size); + } +@@ -2735,7 +2887,11 @@ BitVector::ibvmodinv(const BitVector& bv) + /* b is this bit-vector extended to esize */ + if (esize > 64) + { ++#ifdef __MINGW64__ ++ mpz_set_str(b.d_val_gmp, std::to_string(pb->d_val_uint64).c_str(), 10); ++#else + mpz_set_ui(b.d_val_gmp, pb->d_val_uint64); ++#endif + } + else + { +@@ -2770,12 +2926,27 @@ BitVector::ibvmodinv(const BitVector& bv) + { + if (pb->is_gmp()) + { ++#ifdef __MINGW64__ ++ mpz_t d_val_gmp; ++ mpz_init_set_str(d_val_gmp, std::to_string(d_val_uint64).c_str(), 10); ++ mpz_mul(ty, pb->d_val_gmp, d_val_gmp); ++ mpz_clear(d_val_gmp); ++#else + mpz_mul_ui(ty, pb->d_val_gmp, d_val_uint64); ++#endif + } + else + { ++#ifdef __MINGW64__ ++ mpz_t d_val_gmp; ++ mpz_init_set_str(d_val_gmp, std::to_string(d_val_uint64).c_str(), 10); ++ mpz_set_str(ty, std::to_string(pb->d_val_uint64).c_str(), 10); ++ mpz_mul(ty, ty, d_val_gmp); ++ mpz_clear(d_val_gmp); ++#else + mpz_set_ui(ty, pb->d_val_uint64); + mpz_mul_ui(ty, ty, d_val_uint64); ++#endif + } + } + mpz_fdiv_r_2exp(ty, ty, size); diff --git a/ksmt-bitwuzla/dist/bitwuzla-linux64-0.2.0.zip b/ksmt-bitwuzla/dist/bitwuzla-linux64-0.2.0.zip new file mode 100644 index 000000000..f7ac243ca Binary files /dev/null and b/ksmt-bitwuzla/dist/bitwuzla-linux64-0.2.0.zip differ diff --git a/ksmt-bitwuzla/dist/bitwuzla-linux64-1.0.zip b/ksmt-bitwuzla/dist/bitwuzla-linux64-1.0.zip deleted file mode 100644 index 7991c7044..000000000 Binary files a/ksmt-bitwuzla/dist/bitwuzla-linux64-1.0.zip and /dev/null differ diff --git a/ksmt-bitwuzla/dist/bitwuzla-osx-arm64-1.0.zip b/ksmt-bitwuzla/dist/bitwuzla-osx-arm64-1.0.zip deleted file mode 100644 index d4e9c299e..000000000 Binary files a/ksmt-bitwuzla/dist/bitwuzla-osx-arm64-1.0.zip and /dev/null differ diff --git a/ksmt-bitwuzla/dist/bitwuzla-win64-0.2.0.zip b/ksmt-bitwuzla/dist/bitwuzla-win64-0.2.0.zip new file mode 100644 index 000000000..d5a062d1f Binary files /dev/null and b/ksmt-bitwuzla/dist/bitwuzla-win64-0.2.0.zip differ diff --git a/ksmt-bitwuzla/dist/bitwuzla-win64-1.0.zip b/ksmt-bitwuzla/dist/bitwuzla-win64-1.0.zip deleted file mode 100644 index 1af9fde28..000000000 Binary files a/ksmt-bitwuzla/dist/bitwuzla-win64-1.0.zip and /dev/null differ diff --git a/ksmt-bitwuzla/dist/build.md b/ksmt-bitwuzla/dist/build.md index 0df12ccfd..616405a64 100644 --- a/ksmt-bitwuzla/dist/build.md +++ b/ksmt-bitwuzla/dist/build.md @@ -2,15 +2,28 @@ We build Bitwuzla with the following configuration: ```shell -./configure production --shared --only-cadical +./configure.py release --shared ``` -To make our distribution portable we statically link Bitwuzla against `libgmp`. + +and for Windows: +```shell +./configure.py release --shared --win64 +``` + +To make our distribution portable we statically link Bitwuzla against: +* `gmp` - in [src/meson.build](https://github.com/dee-tree/bitwuzla/blob/main/src/meson.build) +* `bitwuzlabv` (`bitvector_lib`) - in [src/lib/meson.build](https://github.com/dee-tree/bitwuzla/blob/main/src/lib/meson.build) +* `bitwuzlabb` (`bitblast_lib`) - in [src/lib/meson.build](https://github.com/dee-tree/bitwuzla/blob/main/src/lib/meson.build) +* `bitwuzlals` (`local_search_lib`) - in [src/lib/meson.build](https://github.com/dee-tree/bitwuzla/blob/main/src/lib/meson.build) Jni bindings `bitwuzla_jni` are built without any tricks. ### Building on windows -To produce Windows builds we use MSYS2 environment prepared as described [here](https://github.com/aytey/bitwuzla/blob/refreshed_windows_instructions/docs/building_on_windows.rst). -Also, it is important to link statically with `libwinpthread`. +To produce Windows builds we use MSYS2 (MinGW) environment prepared as described [here](https://github.com/aytey/bitwuzla/blob/refreshed_windows_instructions/docs/building_on_windows.rst). + +Also, it is important to link statically with `libwinpthread`, `libgcc`, `libstdc++`. + +Besides, it is important to apply [patch](./../bindings-native/win_bv_gmp_long_patch.patch) ### Expected dynamic dependencies To ensure that our distribution is portable, we verify that the produced binaries have no dependencies that might not be present on the user's machine. @@ -18,20 +31,20 @@ To ensure that our distribution is portable, we verify that the produced binarie #### Linux x64 ```shell $ ldd libbitwuzla.so - linux-vdso.so.1 (0x00007ffce92d0000) - libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f2fdaa00000) - libm.so.6 => /usr/lib/libm.so.6 (0x00007f2fdad18000) - libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f2fdb192000) - libc.so.6 => /usr/lib/libc.so.6 (0x00007f2fda819000) - /usr/lib64/ld-linux-x86-64.so.2 (0x00007f2fdb1e0000) + linux-vdso.so.1 (0x00007fff453c9000) + libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f8ca6400000) + libm.so.6 => /usr/lib/libm.so.6 (0x00007f8ca6713000) + libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f8ca6c96000) + libc.so.6 => /usr/lib/libc.so.6 (0x00007f8ca621e000) + /usr/lib64/ld-linux-x86-64.so.2 (0x00007f8ca6ce9000) $ ldd libbitwuzla_jni.so - libbitwuzla.so => not found - linux-vdso.so.1 (0x00007ffd1ddc6000) - libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f6188800000) - libm.so.6 => /usr/lib/libm.so.6 (0x00007f6188b18000) - libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f6189006000) - libc.so.6 => /usr/lib/libc.so.6 (0x00007f6188619000) - /usr/lib64/ld-linux-x86-64.so.2 (0x00007f618906d000) + linux-vdso.so.1 (0x00007ffc53530000) + libbitwuzla.so => #PathToCompiledBitwuzlaLibrary + libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007fbeaec00000) + libm.so.6 => /usr/lib/libm.so.6 (0x00007fbeaef13000) + libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fbeaf486000) + libc.so.6 => /usr/lib/libc.so.6 (0x00007fbeaea1e000) + /usr/lib64/ld-linux-x86-64.so.2 (0x00007fbeaf4f2000) ``` #### Windows x64 @@ -49,8 +62,6 @@ $ ldd libbitwuzla_jni.dll KERNELBASE.dll => /c/Windows/System32/KERNELBASE.dll (0x7ffb77a70000) msvcrt.dll => /c/Windows/System32/msvcrt.dll (0x7ffb79410000) libbitwuzla.dll => not found - CRYPTBASE.DLL => /c/Windows/SYSTEM32/CRYPTBASE.DLL (0x7ffb77190000) - bcryptPrimitives.dll => /c/Windows/System32/bcryptPrimitives.dll (0x7ffb77de0000) ``` #### MacOS aarch64 diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaContext.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaContext.kt index 5fb618e35..397becf8e 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaContext.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaContext.kt @@ -1,8 +1,5 @@ package io.ksmt.solver.bitwuzla -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap -import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap import io.ksmt.KContext import io.ksmt.decl.KDecl import io.ksmt.decl.KFuncDecl @@ -15,13 +12,10 @@ import io.ksmt.expr.KExistentialQuantifier import io.ksmt.expr.KExpr import io.ksmt.expr.KFunctionApp import io.ksmt.expr.KFunctionAsArray +import io.ksmt.expr.KUninterpretedSortValue import io.ksmt.expr.KUniversalQuantifier import io.ksmt.expr.transformer.KNonRecursiveTransformer import io.ksmt.solver.KSolverException -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm -import org.ksmt.solver.bitwuzla.bindings.Native import io.ksmt.solver.util.KExprLongInternalizerBase.Companion.NOT_INTERNALIZED import io.ksmt.sort.KArray2Sort import io.ksmt.sort.KArray3Sort @@ -37,15 +31,37 @@ import io.ksmt.sort.KRealSort import io.ksmt.sort.KSort import io.ksmt.sort.KSortVisitor import io.ksmt.sort.KUninterpretedSort +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap +import it.unimi.dsi.fastutil.longs.LongSet +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap +import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaOption +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm +import org.ksmt.solver.bitwuzla.bindings.Native open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { private var isClosed = false - val bitwuzla = Native.bitwuzlaNew() + val bitwuzlaOptions = Native.bitwuzlaOptionsNew() + + val bitwuzla by lazy { Native.bitwuzlaNew(bitwuzlaOptions).also { bitwuzlaInitialized = true } } + private var bitwuzlaInitialized = false + + init { + Native.bitwuzlaSetOption(bitwuzlaOptions, BitwuzlaOption.BITWUZLA_OPTION_PRODUCE_MODELS, value = 1) + Native.bitwuzlaSetOption(bitwuzlaOptions, BitwuzlaOption.BITWUZLA_OPTION_PRODUCE_UNSAT_ASSUMPTIONS, value = 1) + Native.bitwuzlaSetOption(bitwuzlaOptions, BitwuzlaOption.BITWUZLA_OPTION_PRODUCE_UNSAT_CORES, value = 1) + } - val trueTerm: BitwuzlaTerm = Native.bitwuzlaMkTrue(bitwuzla) - val falseTerm: BitwuzlaTerm = Native.bitwuzlaMkFalse(bitwuzla) - val boolSort: BitwuzlaSort = Native.bitwuzlaMkBoolSort(bitwuzla) + val bv1Sort = Native.bitwuzlaMkBvSort(1) + val bv1OneTerm: BitwuzlaTerm = Native.bitwuzlaMkBvOne(bv1Sort) + val bv1ZeroTerm: BitwuzlaTerm = Native.bitwuzlaMkBvZero(bv1Sort) + + val trueTerm: BitwuzlaTerm = Native.bitwuzlaMkTrue() + val falseTerm: BitwuzlaTerm = Native.bitwuzlaMkFalse() + val boolSort: BitwuzlaSort = Native.bitwuzlaMkBoolSort() private val exprGlobalCache = mkTermCache>() private val bitwuzlaExpressions = mkTermReverseCache>() @@ -59,8 +75,6 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { private val declSorts = mkTermCache>() private val bitwuzlaSorts = mkTermReverseCache() - private val bitwuzlaValues = mkTermReverseCache>() - private val exprCacheLevel = Object2IntOpenHashMap>().apply { defaultReturnValue(Int.MAX_VALUE) // Level which is greater than any possible level } @@ -147,17 +161,6 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { return internalizedDeclSort } - /** - * Internalize and reverse cache Bv value to support Bv values conversion. - * - * Since [Native.bitwuzlaGetBvValue] is only available after check-sat call - * we must reverse cache Bv values to be able to convert all previously internalized - * expressions. - * */ - fun saveInternalizedValue(expr: KExpr<*>, term: BitwuzlaTerm) { - bitwuzlaValues.put(term, expr) - } - fun findConvertedExpr(expr: BitwuzlaTerm): KExpr<*>? = bitwuzlaExpressions.get(expr) fun saveConvertedExpr(expr: BitwuzlaTerm, converted: KExpr<*>) { @@ -183,8 +186,6 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { return convertedSort } - fun convertValue(value: BitwuzlaTerm): KExpr<*>? = bitwuzlaValues.get(value) - // Constant is known only if it was previously internalized fun convertConstantIfKnown(term: BitwuzlaTerm): KDecl<*>? = bitwuzlaConstants.get(term) @@ -239,7 +240,7 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { val value = constantsGlobalCache.getLong(decl) if (value != NOT_INTERNALIZED) return value - val term = Native.bitwuzlaMkConst(bitwuzla, sort, decl.name).also { + val term = Native.bitwuzlaMkConst(sort, decl.name).also { bitwuzlaConstants.put(it, decl) } constantsGlobalCache.put(decl, term) @@ -248,7 +249,7 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { } fun mkVar(decl: KDecl<*>, sort: BitwuzlaSort): BitwuzlaTerm = - Native.bitwuzlaMkVar(bitwuzla, sort, decl.name).also { + Native.bitwuzlaMkVar(sort, decl.name).also { bitwuzlaVars.put(it, decl) } @@ -302,9 +303,11 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { isClosed = true sorts.clear() + bitwuzlaSorts.keys.bitwuzlaSortDecRefAll() bitwuzlaSorts.clear() exprGlobalCache.clear() + bitwuzlaExpressions.keys.bitwuzlaTermDecRefAll() bitwuzlaExpressions.clear() constantsGlobalCache.clear() @@ -312,14 +315,25 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { exprCurrentLevelCache.clear() declSorts.clear() + bitwuzlaConstants.keys.bitwuzlaTermDecRefAll() bitwuzlaConstants.clear() + + bitwuzlaVars.keys.bitwuzlaTermDecRefAll() + bitwuzlaVars.clear() + Native.bitwuzlaDelete(bitwuzla) + Native.bitwuzlaOptionsDelete(bitwuzlaOptions) } fun ensureActive() { check(!isClosed) { "The context is already closed." } } + fun ensureBitwuzlaNotInitialized() = check(!bitwuzlaInitialized) { "Bitwuzla has already initialized." } + + private fun LongSet.bitwuzlaTermDecRefAll() = forEach(Native::bitwuzlaTermDecRef) + private fun LongSet.bitwuzlaSortDecRefAll() = forEach(Native::bitwuzlaSortDecRef) + private class UninterpretedSortRegisterer( private val register: MutableMap>> ) : KSortVisitor { @@ -433,6 +447,11 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { return super.transform(expr) } + override fun transform(expr: KUninterpretedSortValue): KExpr { + registerDeclIfNotIgnored(expr.decl) + return super.transform(expr) + } + private val quantifiedVarsScopeOwner = arrayListOf>() private val quantifiedVarsScope = arrayListOf>?>() @@ -474,7 +493,7 @@ open class KBitwuzlaContext(val ctx: KContext) : AutoCloseable { override fun transform(expr: KExistentialQuantifier): KExpr = expr.transformQuantifier(expr.bounds, expr.body) - override fun transform(expr: KUniversalQuantifier): KExpr = + override fun transform(expr: KUniversalQuantifier): KExpr = expr.transformQuantifier(expr.bounds, expr.body) } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprConverter.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprConverter.kt index 164ad78a8..2d3d07d3d 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprConverter.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprConverter.kt @@ -21,11 +21,6 @@ import io.ksmt.expr.printer.ExpressionPrinter import io.ksmt.expr.transformer.KNonRecursiveTransformer import io.ksmt.expr.transformer.KTransformerBase import io.ksmt.solver.KSolverUnsupportedFeatureException -import org.ksmt.solver.bitwuzla.bindings.Bitwuzla -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm -import org.ksmt.solver.bitwuzla.bindings.Native import io.ksmt.solver.util.ExprConversionResult import io.ksmt.solver.util.KExprLongConverterBase import io.ksmt.sort.KArray2Sort @@ -34,15 +29,16 @@ import io.ksmt.sort.KArrayNSort import io.ksmt.sort.KArraySort import io.ksmt.sort.KArraySortBase import io.ksmt.sort.KBoolSort -import io.ksmt.sort.KBv1Sort import io.ksmt.sort.KBvSort import io.ksmt.sort.KFpRoundingModeSort import io.ksmt.sort.KFpSort import io.ksmt.sort.KSort import io.ksmt.sort.KUninterpretedSort -import io.ksmt.utils.powerOfTwo import io.ksmt.utils.uncheckedCast -import java.math.BigInteger +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm +import org.ksmt.solver.bitwuzla.bindings.Native @Suppress("LargeClass") open class KBitwuzlaExprConverter( @@ -50,8 +46,6 @@ open class KBitwuzlaExprConverter( private val bitwuzlaCtx: KBitwuzlaContext, private val scopedVars: Map>? = null ) : KExprLongConverterBase() { - private val bitwuzla: Bitwuzla = bitwuzlaCtx.bitwuzla - private val adapterTermRewriter = AdapterTermRewriter(ctx) /** @@ -60,8 +54,7 @@ open class KBitwuzlaExprConverter( * @param expectedSort expected sort of resulting expression * * @see convertToExpectedIfNeeded - * @see convertToBoolIfNeeded - * */ + */ fun BitwuzlaTerm.convertExpr(expectedSort: T): KExpr = convertFromNative(this) .convertToExpectedIfNeeded(expectedSort) @@ -87,8 +80,7 @@ open class KBitwuzlaExprConverter( resetUninterpretedSortValueContext() } - override fun findConvertedNative(expr: BitwuzlaTerm): KExpr<*>? = - bitwuzlaCtx.findConvertedExpr(expr) + override fun findConvertedNative(expr: BitwuzlaTerm): KExpr<*>? = bitwuzlaCtx.findConvertedExpr(expr) override fun saveConvertedNative(native: BitwuzlaTerm, converted: KExpr<*>) { bitwuzlaCtx.saveConvertedExpr(native, converted) @@ -103,38 +95,44 @@ open class KBitwuzlaExprConverter( Native.bitwuzlaSortIsEqual(sort, bitwuzlaCtx.boolSort) -> { boolSort } + Native.bitwuzlaSortIsArray(sort) -> { val domain = Native.bitwuzlaSortArrayGetIndex(sort).convertSort() val range = Native.bitwuzlaSortArrayGetElement(sort).convertSort() mkArraySort(domain, range) } + Native.bitwuzlaSortIsFun(sort) -> { error("Fun sorts are not allowed for conversion") } + Native.bitwuzlaSortIsBv(sort) -> { val size = Native.bitwuzlaSortBvGetSize(sort) mkBvSort(size.toUInt()) } + Native.bitwuzlaSortIsFp(sort) -> { val exponent = Native.bitwuzlaSortFpGetExpSize(sort) val significand = Native.bitwuzlaSortFpGetSigSize(sort) mkFpSort(exponent.toUInt(), significand.toUInt()) } + Native.bitwuzlaSortIsRm(sort) -> { mkFpRoundingModeSort() } + else -> TODO("Given sort $sort is not supported yet") } } @Suppress("LongMethod", "ComplexMethod") override fun convertNativeExpr(expr: BitwuzlaTerm): ExprConversionResult = with(ctx) { - when (val kind = Native.bitwuzlaTermGetBitwuzlaKind(expr)) { + when (val kind = Native.bitwuzlaTermGetKind(expr)) { // constants, functions, values - BitwuzlaKind.BITWUZLA_KIND_CONST -> convertConst(expr) + BitwuzlaKind.BITWUZLA_KIND_CONSTANT -> convertConst(expr) BitwuzlaKind.BITWUZLA_KIND_APPLY -> convertFunctionApp(expr) - BitwuzlaKind.BITWUZLA_KIND_VAL -> convertValue(expr) - BitwuzlaKind.BITWUZLA_KIND_VAR -> convertVar(expr) + BitwuzlaKind.BITWUZLA_KIND_VALUE -> convertValue(expr) + BitwuzlaKind.BITWUZLA_KIND_VARIABLE -> convertVar(expr) // bool BitwuzlaKind.BITWUZLA_KIND_IFF, @@ -144,7 +142,7 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_ITE -> expr.convert(::convertIteExpr) BitwuzlaKind.BITWUZLA_KIND_IMPLIES -> expr.convert { p: KExpr, q: KExpr -> - mkImplies(p.ensureBoolExpr(), q.ensureBoolExpr()) + mkImplies(p, q) } // array @@ -161,25 +159,20 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_EXISTS, BitwuzlaKind.BITWUZLA_KIND_FORALL -> convertQuantifier(expr, kind) - // bit-vec or bool + // bool BitwuzlaKind.BITWUZLA_KIND_AND, BitwuzlaKind.BITWUZLA_KIND_OR, BitwuzlaKind.BITWUZLA_KIND_NOT, BitwuzlaKind.BITWUZLA_KIND_XOR -> convertBoolExpr(expr, kind) + + // bit-vec BitwuzlaKind.BITWUZLA_KIND_BV_NOR, BitwuzlaKind.BITWUZLA_KIND_BV_NOT, BitwuzlaKind.BITWUZLA_KIND_BV_OR, BitwuzlaKind.BITWUZLA_KIND_BV_AND, BitwuzlaKind.BITWUZLA_KIND_BV_NAND, BitwuzlaKind.BITWUZLA_KIND_BV_XOR, - BitwuzlaKind.BITWUZLA_KIND_BV_XNOR -> - if (Native.bitwuzlaTermGetSort(expr) == bitwuzlaCtx.boolSort) { - convertBoolExpr(expr, kind) - } else { - convertBVExpr(expr, kind) - } - - // bit-vec + BitwuzlaKind.BITWUZLA_KIND_BV_XNOR, BitwuzlaKind.BITWUZLA_KIND_BV_ADD, BitwuzlaKind.BITWUZLA_KIND_BV_ASHR, BitwuzlaKind.BITWUZLA_KIND_BV_COMP, @@ -227,7 +220,7 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_FP_ABS, BitwuzlaKind.BITWUZLA_KIND_FP_ADD, BitwuzlaKind.BITWUZLA_KIND_FP_DIV, - BitwuzlaKind.BITWUZLA_KIND_FP_EQ, + BitwuzlaKind.BITWUZLA_KIND_FP_EQUAL, BitwuzlaKind.BITWUZLA_KIND_FP_FMA, BitwuzlaKind.BITWUZLA_KIND_FP_FP, BitwuzlaKind.BITWUZLA_KIND_FP_GEQ, @@ -257,7 +250,7 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_FP_TO_UBV -> convertFpExpr(expr, kind) // unsupported - BitwuzlaKind.BITWUZLA_NUM_KINDS -> TODO("unsupported kind $kind") + BitwuzlaKind.BITWUZLA_KIND_NUM_KINDS -> TODO("unsupported kind $kind") } } @@ -267,7 +260,7 @@ open class KBitwuzlaExprConverter( check(children.isNotEmpty()) { "Apply has no function term" } val function = children[0] - val isFunctionDecl = Native.bitwuzlaTermGetBitwuzlaKind(function) == BitwuzlaKind.BITWUZLA_KIND_CONST + val isFunctionDecl = Native.bitwuzlaTermGetKind(function) == BitwuzlaKind.BITWUZLA_KIND_CONSTANT val appArgs = if (isFunctionDecl) { // convert function decl separately @@ -282,7 +275,7 @@ open class KBitwuzlaExprConverter( val funcDecl = convertFuncDecl(function) if (convertedArgs.isNotEmpty() && funcDecl is KConstDecl<*> && funcDecl.sort is KArraySortBase<*>) { val array: KExpr> = mkConstApp(funcDecl).uncheckedCast() - mkAnyArraySelect(array, convertedArgs).convertToBoolIfNeeded() + mkAnyArraySelect(array, convertedArgs) } else { applyFunction(funcDecl, convertedArgs) } @@ -290,7 +283,7 @@ open class KBitwuzlaExprConverter( val array: KExpr> = convertedArgs.first().uncheckedCast() val args = convertedArgs.drop(1) - mkAnyArraySelect(array, args).convertToBoolIfNeeded() + mkAnyArraySelect(array, args) } } } @@ -302,7 +295,7 @@ open class KBitwuzlaExprConverter( arg.convertToExpectedIfNeeded(expectedSort) } - return funcDecl.apply(wellSortedArgs).convertToBoolIfNeeded() + return funcDecl.apply(wellSortedArgs) } private fun KContext.convertFuncDecl(function: BitwuzlaTerm): KFuncDecl<*> { @@ -343,7 +336,7 @@ open class KBitwuzlaExprConverter( } @Suppress("UNCHECKED_CAST") - return@convert convertedExpr.convertToBoolIfNeeded() as KExpr + return@convert convertedExpr as KExpr } private fun KContext.rewriteFunctionAsArray(decl: KFuncDecl<*>): KExpr<*> { @@ -355,19 +348,9 @@ open class KBitwuzlaExprConverter( when { bitwuzlaCtx.trueTerm == expr -> trueExpr bitwuzlaCtx.falseTerm == expr -> falseExpr - /** - * Search for cached value first because [Native.bitwuzlaGetBvValue] - * is only available after check-sat call - * */ - Native.bitwuzlaTermIsBv(expr) -> bitwuzlaCtx.convertValue(expr) ?: run { - convertBvValue(expr) - } - Native.bitwuzlaTermIsFp(expr) -> bitwuzlaCtx.convertValue(expr) ?: run { - convertFpValue(expr) - } - Native.bitwuzlaTermIsRm(expr) -> bitwuzlaCtx.convertValue(expr) ?: run { - convertRmValue(expr) - } + Native.bitwuzlaTermIsBv(expr) -> convertBvValue(expr) + Native.bitwuzlaTermIsFp(expr) -> convertFpValue(expr) + Native.bitwuzlaTermIsRm(expr) -> convertRmValue(expr) else -> TODO("unsupported value $expr") } } @@ -380,76 +363,29 @@ open class KBitwuzlaExprConverter( private fun KContext.convertBvValue(expr: BitwuzlaTerm): KBitVecValue { val size = Native.bitwuzlaTermBvGetSize(expr) + val convertedValue = when { + size <= Long.SIZE_BITS -> { + val bits = Native.bitwuzlaGetBvValueUInt64(expr) + mkBv(bits, size.toUInt()) + } - val convertedValue = if (Native.bitwuzlaTermIsBvValue(expr)) { - // convert Bv value from native representation - when { - size <= Int.SIZE_BITS -> { - val bits = Native.bitwuzlaBvConstNodeGetBitsUInt32(bitwuzla, expr) - mkBv(bits, size.toUInt()) - } - else -> { - val intBits = Native.bitwuzlaBvConstNodeGetBitsUIntArray(bitwuzla, expr) - val bits = bvBitsToBigInteger(intBits) - mkBv(bits, size.toUInt()) - } + else -> { + val bits = Native.bitwuzlaGetBvValueString(expr) + mkBv(bits, size.toUInt()) } - } else { - val value = Native.bitwuzlaGetBvValue(bitwuzla, expr) - mkBv(value, size.toUInt()) } - bitwuzlaCtx.saveInternalizedValue(convertedValue, expr) - return convertedValue } private fun KContext.convertFpValue(expr: BitwuzlaTerm): KExpr { - val sort = Native.bitwuzlaTermGetSort(expr).convertSort() as KFpSort - - val convertedValue = if (Native.bitwuzlaTermIsFpValue(expr)) { - when (sort) { - fp32Sort -> { - val fpBits = Native.bitwuzlaFpConstNodeGetBitsUInt32(bitwuzla, expr) - mkFp(Float.fromBits(fpBits), sort) - } - fp64Sort -> { - val fpBitsArray = Native.bitwuzlaFpConstNodeGetBitsUIntArray(bitwuzla, expr) - val higherBits = fpBitsArray[1].toLong() shl Int.SIZE_BITS - val lowerBits = fpBitsArray[0].toUInt().toLong() - val fpBits = higherBits or lowerBits - mkFp(Double.fromBits(fpBits), sort) - } - else -> { - val fpBitsArray = Native.bitwuzlaFpConstNodeGetBitsUIntArray(bitwuzla, expr) - val fpBits = bvBitsToBigInteger(fpBitsArray) - - val significandMask = powerOfTwo(sort.significandBits - 1u) - BigInteger.ONE - val exponentMask = powerOfTwo(sort.exponentBits) - BigInteger.ONE - - val significandBits = fpBits.and(significandMask) - val exponentBits = fpBits.shiftRight(sort.significandBits.toInt() - 1).and(exponentMask) - val signBit = fpBits.testBit(sort.significandBits.toInt() + sort.exponentBits.toInt() - 1) - - mkFpBiased( - signBit = signBit, - biasedExponent = mkBv(exponentBits, sort.exponentBits), - significand = mkBv(significandBits, sort.significandBits - 1u), - sort = sort - ) - } - } - } else { - val value = Native.bitwuzlaGetFpValue(bitwuzla, expr) - - mkFpFromBvExpr( - sign = mkBv(value.sign, sizeBits = 1u).uncheckedCast(), - biasedExponent = mkBv(value.exponent, value.exponent.length.toUInt()), - significand = mkBv(value.significand, value.significand.length.toUInt()) - ) - } + val value = Native.bitwuzlaGetFpValue(expr) - bitwuzlaCtx.saveInternalizedValue(convertedValue, expr) + val convertedValue = mkFpFromBvExpr( + sign = mkBv(value.sign, sizeBits = 1u).uncheckedCast(), + biasedExponent = mkBv(value.exponent, value.exponent.length.toUInt()), + significand = mkBv(value.significand, value.significand.length.toUInt()) + ) return convertedValue } @@ -474,12 +410,15 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_BV_NAND -> expr.convertList { args: List> -> mkAnd(args).not() } + BitwuzlaKind.BITWUZLA_KIND_BV_NOR -> expr.convertList { args: List> -> mkOr(args).not() } + BitwuzlaKind.BITWUZLA_KIND_BV_XNOR -> expr.convert { arg0: KExpr, arg1: KExpr -> mkXor(arg0, arg1).not() } + else -> error("unexpected bool kind $kind") } @@ -508,6 +447,7 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_BV_SUB -> expr.convertBv(::mkBvSubExpr) BitwuzlaKind.BITWUZLA_KIND_BV_DEC, BitwuzlaKind.BITWUZLA_KIND_BV_INC -> TODO("$kind conversion is unsupported yet") + BitwuzlaKind.BITWUZLA_KIND_BV_MUL -> expr.convertBv(::mkBvMulExpr) BitwuzlaKind.BITWUZLA_KIND_BV_SDIV -> expr.convertBv(::mkBvSignedDivExpr) BitwuzlaKind.BITWUZLA_KIND_BV_SMOD -> expr.convertBv(::mkBvSignedModExpr) @@ -517,22 +457,28 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_BV_SADD_OVERFLOW -> expr.convertBv { arg0: KExpr, arg1: KExpr -> mkBvAddNoOverflowExpr(arg0, arg1, isSigned = true) } + BitwuzlaKind.BITWUZLA_KIND_BV_UADD_OVERFLOW -> expr.convertBv { arg0: KExpr, arg1: KExpr -> mkBvAddNoOverflowExpr(arg0, arg1, isSigned = false) } + BitwuzlaKind.BITWUZLA_KIND_BV_SSUB_OVERFLOW -> expr.convertBv { arg0: KExpr, arg1: KExpr -> mkBvSubNoOverflowExpr(arg0, arg1) } + BitwuzlaKind.BITWUZLA_KIND_BV_USUB_OVERFLOW -> TODO("$kind") BitwuzlaKind.BITWUZLA_KIND_BV_SMUL_OVERFLOW -> expr.convertBv { arg0: KExpr, arg1: KExpr -> mkBvMulNoOverflowExpr(arg0, arg1, isSigned = true) } + BitwuzlaKind.BITWUZLA_KIND_BV_UMUL_OVERFLOW -> expr.convertBv { arg0: KExpr, arg1: KExpr -> mkBvMulNoOverflowExpr(arg0, arg1, isSigned = false) } + BitwuzlaKind.BITWUZLA_KIND_BV_SDIV_OVERFLOW -> expr.convertBv { arg0: KExpr, arg1: KExpr -> mkBvDivNoOverflowExpr(arg0, arg1) } + BitwuzlaKind.BITWUZLA_KIND_BV_ROL -> expr.convertBv(::mkBvRotateLeftExpr) BitwuzlaKind.BITWUZLA_KIND_BV_ROR -> expr.convertBv(::mkBvRotateRightExpr) BitwuzlaKind.BITWUZLA_KIND_BV_ASHR -> expr.convertBv(::mkBvArithShiftRightExpr) @@ -540,35 +486,41 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_BV_SHL -> expr.convertBv(::mkBvShiftLeftExpr) BitwuzlaKind.BITWUZLA_KIND_BV_ROLI -> expr.convertBv { value: KExpr -> val indices = Native.bitwuzlaTermGetIndices(expr) - val i = indices.single() + val i = indices.single().toInt() mkBvRotateLeftIndexedExpr(i, value) } + BitwuzlaKind.BITWUZLA_KIND_BV_RORI -> expr.convertBv { value: KExpr -> val indices = Native.bitwuzlaTermGetIndices(expr) - val i = indices.single() + val i = indices.single().toInt() mkBvRotateRightIndexedExpr(i, value) } + BitwuzlaKind.BITWUZLA_KIND_BV_SIGN_EXTEND -> expr.convertBv { value: KExpr -> val indices = Native.bitwuzlaTermGetIndices(expr) - val i = indices.single() + val i = indices.single().toInt() mkBvSignExtensionExpr(i, value) } + BitwuzlaKind.BITWUZLA_KIND_BV_ZERO_EXTEND -> expr.convertBv { value: KExpr -> val indices = Native.bitwuzlaTermGetIndices(expr) - val i = indices.single() + val i = indices.single().toInt() mkBvZeroExtensionExpr(i, value) } + BitwuzlaKind.BITWUZLA_KIND_BV_REPEAT -> expr.convertBv { value: KExpr -> val indices = Native.bitwuzlaTermGetIndices(expr) - val i = indices.single() + val i = indices.single().toInt() mkBvRepeatExpr(i, value) } + BitwuzlaKind.BITWUZLA_KIND_BV_EXTRACT -> expr.convertBv { value: KExpr -> val indices = Native.bitwuzlaTermGetIndices(expr) check(indices.size == 2) { "unexpected extract indices: $indices" } val (high, low) = indices - mkBvExtractExpr(high, low, value) + mkBvExtractExpr(high.toInt(), low.toInt(), value) } + BitwuzlaKind.BITWUZLA_KIND_BV_CONCAT -> expr.convertBv(::mkBvConcatExpr) BitwuzlaKind.BITWUZLA_KIND_BV_COMP -> TODO("$kind") else -> error("unexpected BV kind $kind") @@ -595,38 +547,42 @@ open class KBitwuzlaExprConverter( BitwuzlaKind.BITWUZLA_KIND_FP_IS_NEG -> expr.convert(ctx::mkFpIsNegativeExpr) BitwuzlaKind.BITWUZLA_KIND_FP_IS_POS -> expr.convert(ctx::mkFpIsPositiveExpr) BitwuzlaKind.BITWUZLA_KIND_FP_IS_ZERO -> expr.convert(ctx::mkFpIsZeroExpr) - BitwuzlaKind.BITWUZLA_KIND_FP_EQ -> expr.convert(ctx::mkFpEqualExpr) + BitwuzlaKind.BITWUZLA_KIND_FP_EQUAL -> expr.convert(ctx::mkFpEqualExpr) BitwuzlaKind.BITWUZLA_KIND_FP_LEQ -> expr.convert(ctx::mkFpLessOrEqualExpr) BitwuzlaKind.BITWUZLA_KIND_FP_LT -> expr.convert(ctx::mkFpLessExpr) BitwuzlaKind.BITWUZLA_KIND_FP_GEQ -> expr.convert(ctx::mkFpGreaterOrEqualExpr) BitwuzlaKind.BITWUZLA_KIND_FP_GT -> expr.convert(ctx::mkFpGreaterExpr) BitwuzlaKind.BITWUZLA_KIND_FP_TO_SBV -> expr.convert { rm: KExpr, value: KExpr -> - val bvSize = Native.bitwuzlaTermGetIndices(expr).single() + val bvSize = Native.bitwuzlaTermGetIndices(expr).single().toInt() ctx.mkFpToBvExpr(rm, value, bvSize, isSigned = true) } + BitwuzlaKind.BITWUZLA_KIND_FP_TO_UBV -> expr.convert { rm: KExpr, value: KExpr -> - val bvSize = Native.bitwuzlaTermGetIndices(expr).single() + val bvSize = Native.bitwuzlaTermGetIndices(expr).single().toInt() ctx.mkFpToBvExpr(rm, value, bvSize, isSigned = false) } + BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_SBV -> expr.convert { rm: KExpr, value: KExpr -> val sort = Native.bitwuzlaTermGetSort(expr).convertSort() as KFpSort ctx.mkBvToFpExpr(sort, rm, value, signed = true) } + BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_UBV -> expr.convert { rm: KExpr, value: KExpr -> val sort = Native.bitwuzlaTermGetSort(expr).convertSort() as KFpSort ctx.mkBvToFpExpr(sort, rm, value, signed = false) } + BitwuzlaKind.BITWUZLA_KIND_FP_FP -> expr.convert(ctx::mkFpFromBvExpr) BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_BV -> expr.convert { bv: KExpr -> with(ctx) { val indices = Native.bitwuzlaTermGetIndices(expr) check(indices.size == 2) { "unexpected fp-from-bv indices: $indices" } - val exponentSize = indices.first() + val exponentSize = indices.first().toInt() val size = bv.sort.sizeBits.toInt() val sign = mkBvExtractExpr(size - 1, size - 1, bv) @@ -636,14 +592,29 @@ open class KBitwuzlaExprConverter( mkFpFromBvExpr(sign.uncheckedCast(), exponent, significand) } } + BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_FP -> expr.convert { rm: KExpr, value: KExpr -> val sort = Native.bitwuzlaTermGetSort(expr).convertSort() as KFpSort ctx.mkFpToFpExpr(sort, rm, value) } + else -> error("unexpected Fp kind $kind") } + private fun convertQuantifierBoundVar( + boundVar: BitwuzlaTerm, + nestedScope: MutableMap> + ): KDecl { + val decl = bitwuzlaCtx.findConvertedVar(boundVar) ?: run { + val sort = Native.bitwuzlaTermGetSort(boundVar) + val name = Native.bitwuzlaTermGetSymbol(boundVar) + ctx.mkFreshConstDecl(name ?: "var", sort.convertSort()) + } + nestedScope[boundVar] = decl + return decl + } + fun convertQuantifier(expr: BitwuzlaTerm, kind: BitwuzlaKind): ExprConversionResult = convert { val children = Native.bitwuzlaTermGetChildren(expr) val boundVars = children.dropLast(1) @@ -652,13 +623,7 @@ open class KBitwuzlaExprConverter( val nestedScope = scopedVars?.toMutableMap() ?: hashMapOf() val convertedBounds = boundVars.map { boundVar -> - val decl = bitwuzlaCtx.findConvertedVar(boundVar) ?: run { - val sort = Native.bitwuzlaTermGetSort(boundVar) - val name = Native.bitwuzlaTermGetSymbol(boundVar) - ctx.mkFreshConstDecl(name ?: "var", sort.convertSort()) - } - nestedScope[boundVar] = decl - decl + convertQuantifierBoundVar(boundVar, nestedScope) } val bodyConverter = KBitwuzlaExprConverter(ctx, bitwuzlaCtx, nestedScope) @@ -675,8 +640,22 @@ open class KBitwuzlaExprConverter( } BitwuzlaKind.BITWUZLA_KIND_LAMBDA -> { - val convertedBody = bodyConverter.convertFromNative(body) - ctx.convertArrayLambdaSimplified(convertedBounds, convertedBody) + val nestedBounds = mutableListOf() + var nestedBody = body + // In model lambda may be represented as inherited lambdas with 1 arg per each + while (Native.bitwuzlaTermGetKind(nestedBody) == BitwuzlaKind.BITWUZLA_KIND_LAMBDA) { + Native.bitwuzlaTermGetChildren(nestedBody).also { nestedChildren -> + nestedBounds += nestedChildren.dropLast(1) + nestedBody = nestedChildren.last() + } + } + + val convertedNestedBounds = nestedBounds.map { nestedBoundVar -> + convertQuantifierBoundVar(nestedBoundVar, nestedScope) + } + + val convertedBody = bodyConverter.convertFromNative(nestedBody) + ctx.convertArrayLambdaSimplified(convertedBounds + convertedNestedBounds, convertedBody) } else -> error("Unexpected quantifier: $kind") @@ -701,42 +680,78 @@ open class KBitwuzlaExprConverter( /** * In a case of multidimensional array store expressions in model are represented as: - * (lambda (i0 ... in) (ite (and (= i0 c0) .. (= in cn)) value (select array i0...in))) + * (lambda (i0) + * … (lambda (in) + * (ite (and (= i0 c0) … (= in cn)) value1 + * (ite (and (= i0 d0) … (= in dn)) value2 + * … + * (select array i0 … in) + * ) + * ) + * ) + * ) + * or as + * (lambda (i0)…((lambda (in) ite (and (= i0 c0) … (= in cn)) value (select array i0...in))) * We try to recognize this pattern and rewrite such lambda expressions as normal * array stores. * */ + @Suppress("ComplexMethod") private fun KContext.tryRecognizeArrayStore( body: KIteExpr<*>, bounds: List> ): KExpr<*>? { - val storedValue = body.trueBranch as? KInterpretedValue<*> ?: return null - val conditionArgs = (body.condition as? KAndExpr)?.args ?: return null + val indicesStack = mutableListOf>>() + val valueStack = mutableListOf>() + + var ite = body + var arrayStore: KExpr<*>? = null + do { + val storedValue = ite.trueBranch as? KInterpretedValue<*> ?: return null + val conditionArgs = (ite.condition as? KAndExpr)?.args ?: return null + + val boundConsts = bounds.map { it.apply(emptyList()) } + + val indexBindings = conditionArgs.associate { + val binding = it as? KEqExpr<*> ?: return null + val lhs = binding.lhs + val rhs = binding.rhs + + when { + lhs is KInterpretedValue<*> && rhs is KConst<*> -> rhs to lhs + lhs is KConst<*> && rhs is KInterpretedValue<*> -> lhs to rhs + else -> return null + } + } - val boundConsts = bounds.map { it.apply(emptyList()) } + val indices = boundConsts.map { indexBindings[it] ?: return null } - val indexBindings = conditionArgs.associate { - val binding = it as? KEqExpr<*> ?: return null - val lhs = binding.lhs - val rhs = binding.rhs + when (val nested = ite.falseBranch) { + is KArraySelectBase<*, *> -> { + if (boundConsts != nested.indices) return null + val nestedArray = nested.array + arrayStore = mkAnyArrayStore(nestedArray, indices.uncheckedCast(), storedValue.uncheckedCast()) + } + + is KIteExpr<*> -> { + indicesStack += indices + valueStack += storedValue + ite = nested + } - when { - lhs is KInterpretedValue<*> && rhs is KConst<*> -> rhs to lhs - lhs is KConst<*> && rhs is KInterpretedValue<*> -> lhs to rhs else -> return null } - } - val indices = boundConsts.map { indexBindings[it] ?: return null } + } while (arrayStore == null) - val nestedValue = body.falseBranch - if (nestedValue is KArraySelectBase<*, *>) { - if (boundConsts != nestedValue.indices) return null - - val nestedArray = nestedValue.array - return mkAnyArrayStore(nestedArray, indices.uncheckedCast(), storedValue.uncheckedCast()) + while (valueStack.isNotEmpty()) { + arrayStore = mkAnyArrayStore>( + arrayStore.uncheckedCast(), + indicesStack.removeLast().uncheckedCast(), + valueStack.removeLast().uncheckedCast() + ) } - return null + return arrayStore } fun convertEqExpr(lhs: KExpr, rhs: KExpr): KExpr = with(ctx) { @@ -897,48 +912,16 @@ open class KBitwuzlaExprConverter( return "uf$id" } - /** - * Bitwuzla does not distinguish between Bool and (BitVec 1). - * - * By default, we convert all Bitwuzla (BitVec 1) terms as Bool expressions, but: - * 1. user defined constant with (BitVec 1) sort may appear - * 2. user defined constant with (Array X (BitVec 1)) sort may appear - * 3. user defined function with (BitVec 1) in domain or range may appear - * - * Such user defined constants may be used in expressions, where we expect equal sorts. - * For example, `x: (BitVec 1) == y: Bool` or `x: (Array T (BitVec 1)) == y: (Array T Bool)`. - * For such reason, we introduce additional expressions - * to convert from (BitVec 1) to Bool and vice versa. - * - * @see ensureBoolExpr - * @see ensureBv1Expr - * @see ensureArrayExprSortMatch - * */ - @Suppress("UNCHECKED_CAST") - fun KExpr<*>.convertToBoolIfNeeded(): KExpr<*> = when (sort) { - ctx.bv1Sort -> ensureBoolExpr() - is KArraySort<*, *> -> (this as KExpr>) - .ensureArrayExprSortMatch( - domainExpected = { domain -> domain.map { if (it == ctx.bv1Sort) ctx.boolSort else it } }, - rangeExpected = { if (it == ctx.bv1Sort) ctx.boolSort else it } - ) - else -> this - } - /** * Convert expression to expected sort. * - * Mainly used for convert from Bool to (BitVec 1) or (BitVec 32) to Uninterpreted Sort: + * Mainly used for convert from (BitVec 32) to Uninterpreted Sort: * 1. In function app, when argument sort doesn't match * 2. When top level expression expectedSort doesn't match ([convertExpr]) * * Also works for Arrays. - * - * @see convertToBoolIfNeeded - * */ + */ fun KExpr<*>.convertToExpectedIfNeeded(expected: T): KExpr = when (expected) { - ctx.bv1Sort -> ensureBv1Expr().uncheckedCast() - ctx.boolSort -> ensureBoolExpr().uncheckedCast() is KArraySortBase<*> -> { val array: KExpr> = this.uncheckedCast() array.ensureArrayExprSortMatch( @@ -946,33 +929,18 @@ open class KBitwuzlaExprConverter( rangeExpected = { expected.range } ).uncheckedCast() } + is KUninterpretedSort -> ensureUninterpretedSortExpr(expected).uncheckedCast() else -> { - check(this.sort !is KUninterpretedSort) { - "Unexpected cast from ${this.sort} to $expected" - } + check(this.sort !is KUninterpretedSort) { "Unexpected cast from ${this.sort} to $expected" } this.uncheckedCast() } } - fun KExpr<*>.ensureBvExpr(): KExpr = with(ctx) { - val expr = if (sort == boolSort) { - ensureBv1Expr() - } else { - check(sort is KBvSort) { "Bv sort expected but $sort occurred" } - this@ensureBvExpr - } - - expr.uncheckedCast() - } - - private val bv1One: KExpr by lazy { ctx.mkBv(true) } - private val bv1Zero: KExpr by lazy { ctx.mkBv(false) } - /** * Convert expression from (Array A B) to (Array X Y), - * where A,B,X,Y are Bool or (BitVec 1), (BitVec 32) or Uninterpreted - * */ + * where A,B,X,Y are (BitVec 32) or Uninterpreted + */ private inline fun > KExpr.ensureArrayExprSortMatch( domainExpected: (List) -> List, rangeExpected: (KSort) -> KSort @@ -982,9 +950,10 @@ open class KBitwuzlaExprConverter( when { expectedDomain == sort.domainSorts && expectedRange == sort.range -> this@ensureArrayExprSortMatch - this@ensureArrayExprSortMatch is ArrayAdapterExpr<*, *> - && arg.sort.domainSorts == expectedDomain - && arg.sort.range == expectedRange -> arg + + this@ensureArrayExprSortMatch is ArrayAdapterExpr<*, *> && arg.sort.domainSorts == expectedDomain + && arg.sort.range == expectedRange -> arg + else -> { val expectedSort = mkAnyArraySort(expectedDomain, expectedRange) ArrayAdapterExpr(this@ensureArrayExprSortMatch, expectedSort) @@ -992,35 +961,9 @@ open class KBitwuzlaExprConverter( } } - /** - * Convert expression from (BitVec 1) to Bool. - * */ - private fun KExpr<*>.ensureBoolExpr(): KExpr = with(ctx) { - when { - sort == boolSort -> this@ensureBoolExpr.uncheckedCast() - this@ensureBoolExpr is BoolToBv1AdapterExpr -> arg - this@ensureBoolExpr == bv1One -> trueExpr - this@ensureBoolExpr == bv1Zero -> falseExpr - else -> Bv1ToBoolAdapterExpr(this@ensureBoolExpr.uncheckedCast()) - } - } - - /** - * Convert expression from Bool to (BitVec 1). - * */ - private fun KExpr<*>.ensureBv1Expr(): KExpr = with(ctx) { - when { - sort == bv1Sort -> this@ensureBv1Expr.uncheckedCast() - this@ensureBv1Expr is Bv1ToBoolAdapterExpr -> arg - this@ensureBv1Expr == trueExpr -> bv1One - this@ensureBv1Expr == falseExpr -> bv1Zero - else -> BoolToBv1AdapterExpr(this@ensureBv1Expr.uncheckedCast()) - } - } - /** * Convert expression from (BitVec 32) to uninterpreted sort. - * */ + */ private fun KExpr<*>.ensureUninterpretedSortExpr(expected: KUninterpretedSort): KExpr<*> { if (sort == expected) return this @@ -1034,42 +977,6 @@ open class KBitwuzlaExprConverter( return Bv32ToUninterpretedSortAdapterExpr(this, expected) } - private inner class BoolToBv1AdapterExpr(val arg: KExpr) : KExpr(ctx) { - override val sort: KBv1Sort = ctx.bv1Sort - - override fun print(printer: ExpressionPrinter) = with(printer) { - append("(toBV1 ") - append(arg) - append(")") - } - - override fun accept(transformer: KTransformerBase): KExpr { - check(transformer is AdapterTermRewriter) { "leaked adapter term" } - return transformer.transform(this) - } - - override fun internHashCode(): Int = hash(arg) - override fun internEquals(other: Any): Boolean = structurallyEqual(other, { arg }) - } - - private inner class Bv1ToBoolAdapterExpr(val arg: KExpr) : KExpr(ctx) { - override val sort: KBoolSort = ctx.boolSort - - override fun print(printer: ExpressionPrinter) = with(printer) { - append("(toBool ") - append(arg) - append(")") - } - - override fun accept(transformer: KTransformerBase): KExpr { - check(transformer is AdapterTermRewriter) { "leaked adapter term" } - return transformer.transform(this) - } - - override fun internHashCode(): Int = hash(arg) - override fun internEquals(other: Any): Boolean = structurallyEqual(other, { arg }) - } - private inner class Bv32ToUninterpretedSortAdapterExpr( val arg: KBitVec32Value, override val sort: KUninterpretedSort @@ -1112,41 +1019,13 @@ open class KBitwuzlaExprConverter( } /** - * Remove auxiliary terms introduced by [convertToBoolIfNeeded] and [convertToExpectedIfNeeded]. + * Remove auxiliary terms introduced by [convertToExpectedIfNeeded]. * */ private inner class AdapterTermRewriter(ctx: KContext) : KNonRecursiveTransformer(ctx) { // We can skip values transformation since values may not contain any adapter terms override fun exprTransformationRequired(expr: KExpr): Boolean = expr !is KInterpretedValue - /** - * x: Bool - * (toBv x) -> (ite x #b1 #b0) - * */ - fun transform(expr: BoolToBv1AdapterExpr): KExpr = with(ctx) { - transformExprAfterTransformed(expr, expr.arg) { transformedArg -> - when (transformedArg) { - trueExpr -> bv1Sort.trueValue() - falseExpr -> bv1Sort.falseValue() - else -> mkIte(transformedArg, bv1Sort.trueValue(), bv1Sort.falseValue()) - } - } - } - - /** - * x: (BitVec 1) - * (toBool x) -> (ite (x == #b1) true false) - * */ - fun transform(expr: Bv1ToBoolAdapterExpr): KExpr = with(ctx) { - transformExprAfterTransformed(expr, expr.arg) { transformedArg -> - when (transformedArg) { - bv1Sort.trueValue() -> trueExpr - bv1Sort.falseValue() -> falseExpr - else -> mkIte(transformedArg eq bv1Sort.trueValue(), trueExpr, falseExpr) - } - } - } - /** * Replace (BitVec 32) value with an uninterpreted constant. * */ @@ -1160,18 +1039,10 @@ open class KBitwuzlaExprConverter( * x: (Array A B) -> (Array X Y) * * Resolve sort mismatch between two arrays. - * For example, - * ``` - * val x: (Array T Bool) - * val y: (Array T (BitVec 1)) - * val expr = x eq y - * ``` - * In this example, we need to convert y from `(Array T (BitVec 1))` - * to `(Array T Bool)` because we need sort compatibility between x and y. * In general case the only way is to generate new array z such that * ``` - * convert: ((BitVec 1)) -> Bool - * z: (Array T Bool) + * convert: ((BitVec 32)) -> Uninterpreted + * z: (Array T Uninterpreted) * (forall (i: T) (select z i) == convert(select y i)) * ``` * This array generation procedure can be represented as [io.ksmt.expr.KArrayLambda] @@ -1202,30 +1073,18 @@ open class KBitwuzlaExprConverter( AdapterTermRewriter(ctx).apply(replacement) } - - private fun T.trueValue(): KExpr = when (this) { - is KBv1Sort -> bv1One.uncheckedCast() - is KBoolSort -> ctx.trueExpr.uncheckedCast() - else -> error("unexpected sort: $this") - } - - private fun T.falseValue(): KExpr = when (this) { - is KBv1Sort -> bv1Zero.uncheckedCast() - is KBoolSort -> ctx.falseExpr.uncheckedCast() - else -> error("unexpected sort: $this") - } } inline fun BitwuzlaTerm.convertBv( op: (KExpr, KExpr) -> KExpr - ) = convert { a0: KExpr, a1: KExpr -> - op(a0.ensureBvExpr(), a1.ensureBvExpr()).convertToBoolIfNeeded() + ) = convert { a0: KExpr, a1: KExpr -> + op(a0, a1) } inline fun BitwuzlaTerm.convertBv( op: (KExpr) -> KExpr - ) = convert { arg: KExpr -> - op(arg.ensureBvExpr()).convertToBoolIfNeeded() + ) = convert { arg: KExpr -> + op(arg) } inline fun BitwuzlaTerm.convert( diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprInternalizer.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprInternalizer.kt index 5938f1e19..b17641ba6 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprInternalizer.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaExprInternalizer.kt @@ -128,7 +128,6 @@ import io.ksmt.expr.KImpliesExpr import io.ksmt.expr.KInt32NumExpr import io.ksmt.expr.KInt64NumExpr import io.ksmt.expr.KIntBigNumExpr -import io.ksmt.expr.KInterpretedValue import io.ksmt.expr.KIsIntRealExpr import io.ksmt.expr.KIteExpr import io.ksmt.expr.KLeArithExpr @@ -151,17 +150,11 @@ import io.ksmt.expr.KUnaryMinusArithExpr import io.ksmt.expr.KUninterpretedSortValue import io.ksmt.expr.KUniversalQuantifier import io.ksmt.expr.KXorExpr -import io.ksmt.expr.rewrite.simplify.rewriteBvAddNoUnderflowExpr -import io.ksmt.expr.rewrite.simplify.rewriteBvMulNoUnderflowExpr import io.ksmt.expr.rewrite.simplify.rewriteBvNegNoOverflowExpr import io.ksmt.expr.rewrite.simplify.rewriteBvSubNoUnderflowExpr import io.ksmt.solver.KSolverUnsupportedFeatureException -import org.ksmt.solver.bitwuzla.bindings.Bitwuzla -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaRoundingMode -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm -import org.ksmt.solver.bitwuzla.bindings.Native +import io.ksmt.solver.bitwuzla.KBitwuzlaExprInternalizer.BvOverflowCheckMode.OVERFLOW +import io.ksmt.solver.bitwuzla.KBitwuzlaExprInternalizer.BvOverflowCheckMode.UNDERFLOW import io.ksmt.solver.util.KExprLongInternalizerBase import io.ksmt.sort.KArithSort import io.ksmt.sort.KArray2Sort @@ -186,15 +179,16 @@ import io.ksmt.sort.KRealSort import io.ksmt.sort.KSort import io.ksmt.sort.KSortVisitor import io.ksmt.sort.KUninterpretedSort +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaBVBase +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaRoundingMode +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaSort +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTermArray -import java.math.BigInteger +import org.ksmt.solver.bitwuzla.bindings.Native @Suppress("LargeClass") open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprLongInternalizerBase() { - - @JvmField - val bitwuzla: Bitwuzla = bitwuzlaCtx.bitwuzla - open val sortInternalizer: SortInternalizer by lazy { SortInternalizer(bitwuzlaCtx) } open val functionSortInternalizer: FunctionSortInternalizer by lazy { FunctionSortInternalizer(bitwuzlaCtx, sortInternalizer) @@ -213,8 +207,8 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } /** - * Create Bitwuzla term from KSMT expression - * */ + * Create Bitwuzla term from KSMT expression + */ fun KExpr.internalize(): BitwuzlaTerm = tryInternalize({ bitwuzlaCtx.ensureActive() internalizeExpr() @@ -271,41 +265,21 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } /** - * Create Bitwuzla sort from KSMT sort - * */ + * Create Bitwuzla sort from KSMT sort + */ fun T.internalizeSort(): BitwuzlaSort = sortInternalizer.internalizeSort(this) /** - * Create Bitwuzla function sort for KSMT declaration. + * Create Bitwuzla function sort for KSMT declaration. * - * If [this] declaration is a constant then non-function sort is returned - * */ + * If [this] declaration is a constant then non-function sort is returned + */ fun KDecl.bitwuzlaFunctionSort(): BitwuzlaSort = functionSortInternalizer.internalizeDeclSort(this) private fun saveExprInternalizationResult(expr: KExpr<*>, term: BitwuzlaTerm) { bitwuzlaCtx.saveExprTerm(expr, term) - - // Save only constants - if (expr !is KInterpretedValue<*>) return - - // Don't reverse cache uninterpreted values because we represent them as Bv32 - if (expr is KUninterpretedSortValue) return - - val kind = Native.bitwuzlaTermGetBitwuzlaKind(term) - - /* - * Save internalized values for [KBitwuzlaExprConverter] needs - * @see [KBitwuzlaContext.saveInternalizedValue] - */ - if (kind != BitwuzlaKind.BITWUZLA_KIND_VAL) return - - if (bitwuzlaCtx.convertValue(term) != null) return - - if (term != bitwuzlaCtx.trueTerm && term != bitwuzlaCtx.falseTerm) { - bitwuzlaCtx.saveInternalizedValue(expr, term) - } } private inline fun mkConstant(decl: KDecl<*>, sort: () -> BitwuzlaSort): BitwuzlaTerm { @@ -318,7 +292,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL val const = mkConstant(decl) { decl.bitwuzlaFunctionSort() } val termArgs = args.addFirst(const) - Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, termArgs) + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_APPLY, termArgs) } } @@ -333,9 +307,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL fun mkAndTerm(args: BitwuzlaTermArray): BitwuzlaTerm = when (args.size) { 0 -> bitwuzlaCtx.trueTerm 1 -> args[0] - else -> Native.bitwuzlaMkTerm( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_AND, args - ) + else -> Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_AND, args) } override fun transform(expr: KAndBinaryExpr) = with(expr) { @@ -349,9 +321,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL fun mkOrTerm(args: BitwuzlaTermArray): BitwuzlaTerm = when (args.size) { 0 -> bitwuzlaCtx.falseTerm 1 -> args[0] - else -> Native.bitwuzlaMkTerm( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_OR, args - ) + else -> Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_OR, args) } override fun transform(expr: KOrBinaryExpr) = with(expr) { @@ -362,8 +332,18 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL transform(arg, ::mkNotTerm) } - fun mkNotTerm(arg: BitwuzlaTerm): BitwuzlaTerm = - Native.bitwuzlaMkTerm1(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_NOT, arg) + fun mkNotTerm(arg: BitwuzlaTerm): BitwuzlaTerm = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_NOT, arg) + + fun mkBvNotTerm(arg: BitwuzlaTerm): BitwuzlaTerm = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_BV_NOT, arg) + + fun mkBvAndReducedBool(arg0: BitwuzlaTerm, arg1: BitwuzlaTerm): BitwuzlaTerm = mkEqTerm( + bitwuzlaCtx.ctx.bv1Sort, + bitwuzlaCtx.bv1OneTerm, + Native.bitwuzlaMkTerm( + BitwuzlaKind.BITWUZLA_KIND_BV_REDAND, + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_BV_AND, arg0, arg1) + ) + ) override fun transform(expr: KImpliesExpr) = with(expr) { transform(p, q, BitwuzlaKind.BITWUZLA_KIND_IMPLIES) @@ -403,11 +383,14 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL return mkArrayLambdaTerm(sort.domain) { boundVar -> val tValue = mkArraySelectTerm(tIsArray, t, boundVar) val fValue = mkArraySelectTerm(fIsArray, f, boundVar) - Native.bitwuzlaMkTerm3(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ITE, c, tValue, fValue) + Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_ITE, + arg0 = c, arg1 = tValue, arg2 = fValue + ) } } } - return Native.bitwuzlaMkTerm3(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ITE, c, t, f) + return Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_ITE, arg0 = c, arg1 = t, arg2 = f) } private fun mkEqTerm(sort: KSort, l: BitwuzlaTerm, r: BitwuzlaTerm): BitwuzlaTerm { @@ -416,7 +399,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL val rIsArray = Native.bitwuzlaTermIsArray(r) return mkArrayEqTerm(sort, l, lIsArray, r, rIsArray) } - return Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, l, r) + return Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_EQUAL, arg0 = l, arg1 = r) } private fun mkDistinctTerm(sort: KSort, args: LongArray): BitwuzlaTerm { @@ -424,9 +407,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL return blastArrayDistinct(sort, args) } - return Native.bitwuzlaMkTerm( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_DISTINCT, args - ) + return Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_DISTINCT, args) } private fun mkArrayEqTerm( @@ -434,39 +415,48 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL lhs: BitwuzlaTerm, lhsIsArray: Boolean, rhs: BitwuzlaTerm, rhsIsArray: Boolean ): BitwuzlaTerm { - if (lhsIsArray == rhsIsArray) { - return Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, lhs, rhs) + if (lhsIsArray && rhsIsArray) { + return Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_EQUAL, arg0 = lhs, arg1 = rhs) } - return if (lhsIsArray) { - mkArrayEqFunctionTerm(sort, rhs, lhs) - } else { - mkArrayEqFunctionTerm(sort, lhs, rhs) - } - } + /* Equality over lambdas (or arrays mixed with lambdas) in Bitwuzla is not supported, + therefore create equality term as quantifier over lambdas */ - private fun mkArrayEqFunctionTerm( - sort: KArraySort<*, *>, - functionTerm: BitwuzlaTerm, - arrayTerm: BitwuzlaTerm - ): BitwuzlaTerm { - val arrayKind = Native.bitwuzlaTermGetBitwuzlaKind(arrayTerm) - if (arrayKind == BitwuzlaKind.BITWUZLA_KIND_CONST) { - // It is incorrect to use array and function, but equality should work - return Native.bitwuzlaMkTerm2( - bitwuzla, - BitwuzlaKind.BITWUZLA_KIND_EQUAL, - arrayTerm, - functionTerm - ) + val lhsAsLambda = if (!lhsIsArray) lhs else mkArrayLambdaTerm(sort.domain) { boundVar -> + mkArraySelectTerm(isArray = true, array = lhs, idx = boundVar) } - val wrappedArray = mkArrayLambdaTerm(sort.domain) { boundVar -> - mkArraySelectTerm(isArray = true, array = arrayTerm, idx = boundVar) - }.also { - check(!Native.bitwuzlaTermIsArray(it)) { "Array term was not eliminated" } + val rhsAsLambda = if (!rhsIsArray) rhs else mkArrayLambdaTerm(sort.domain) { boundVar -> + mkArraySelectTerm(isArray = true, array = rhs, idx = boundVar) } - return Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, wrappedArray, functionTerm) + + return mkFunctionEqTerm(lhsAsLambda, rhsAsLambda) + } + + private fun mkFunctionEqTerm(term1: BitwuzlaTerm, term2: BitwuzlaTerm): BitwuzlaTerm { + val children1 = Native.bitwuzlaTermGetChildren(term1) + val children2 = Native.bitwuzlaTermGetChildren(term2) + + val args1 = children1.dropLast(1) + val args2 = children2.dropLast(1) + + check(args1.size == args2.size) { "Arity of functions is not equal" } + + val argsSorts = (args1.zip(args2) { arg1, arg2 -> + Native.bitwuzlaTermGetSort(arg1) to Native.bitwuzlaTermGetSort(arg2) + }) + + check(argsSorts.all { (s1, s2) -> Native.bitwuzlaSortIsEqual(s1, s2) }) { "Arguments sort mismatch" } + + val body1 = children1.last() + val body2 = children2.last().let { Native.bitwuzlaSubstituteTerm(it, args2.toLongArray(), args1.toLongArray()) } + + check(Native.bitwuzlaTermGetKind(body1) != BitwuzlaKind.BITWUZLA_KIND_LAMBDA + && Native.bitwuzlaTermGetKind(body1) != BitwuzlaKind.BITWUZLA_KIND_LAMBDA + ) { "Equality on inherited lambdas is not supported yet" } + + val bodiesEq = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_EQUAL, body1, body2) + return Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_FORALL, args1.toLongArray() + bodiesEq) } private fun blastArrayDistinct(sort: KArraySort<*, *>, arrays: LongArray): BitwuzlaTerm { @@ -480,7 +470,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL val isArrayJ = Native.bitwuzlaTermIsArray(arrayJ) val equality = mkArrayEqTerm(sort, arrayI, isArrayI, arrayJ, isArrayJ) - val inequality = Native.bitwuzlaMkTerm1(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_NOT, equality) + val inequality = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_NOT, equality) inequalities += inequality } @@ -490,51 +480,47 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } override fun transform(expr: KBitVec1Value) = with(expr) { - transform { if (value) bitwuzlaCtx.trueTerm else bitwuzlaCtx.falseTerm } - } - - override fun transform(expr: KBitVec8Value): KExpr = transformBv32Number(expr) - override fun transform(expr: KBitVec16Value): KExpr = transformBv32Number(expr) - override fun transform(expr: KBitVec32Value): KExpr = transformBv32Number(expr) - override fun transform(expr: KBitVec64Value): KExpr = transformBv64Number(expr) - - fun , S : KBvSort> transformBv32Number(expr: T): T = with(expr) { transform { - Native.bitwuzlaMkBvValueUint32( - bitwuzla, - sort.internalizeSort(), - numberValue.toInt() - ).also { bitwuzlaCtx.saveInternalizedValue(expr, it) } + if (value) bitwuzlaCtx.bv1OneTerm else bitwuzlaCtx.bv1ZeroTerm } } + override fun transform(expr: KBitVec8Value): KExpr = transformBv64Number(expr) + override fun transform(expr: KBitVec16Value): KExpr = transformBv64Number(expr) + override fun transform(expr: KBitVec32Value): KExpr = transformBv64Number(expr) + override fun transform(expr: KBitVec64Value): KExpr = transformBv64Number(expr) + fun , S : KBvSort> transformBv64Number(expr: T): T = with(expr) { transform { - transformBvLongNumber(numberValue.toLong(), sort.sizeBits.toInt()) - .also { bitwuzlaCtx.saveInternalizedValue(expr, it) } + transformBvLongValue( + numberValue.toLong(), + sort + ) } } + fun transformBvLongValue(value: Long, sort: KBvSort) = Native.bitwuzlaMkBvValueInt64( + sort.internalizeSort(), + value + ) + override fun transform(expr: KBitVecCustomValue) = with(expr) { transform { - transformCustomBvNumber(value, expr.sizeBits.toInt()) - .also { bitwuzlaCtx.saveInternalizedValue(expr, it) } + val internalized = if (sizeBits.toInt() <= Long.SIZE_BITS) { + transformBvLongValue(value.toLong(), sort) + } else { + transformBvBinaryString(stringValue, sort) + } + + internalized } } - private fun transformBvLongNumber(value: Long, size: Int): BitwuzlaTerm { - val intParts = intArrayOf((value ushr Int.SIZE_BITS).toInt(), value.toInt()) - return Native.bitwuzlaMkBvValueUint32Array(bitwuzla, size, intParts) + private fun transformBvBinaryString(value: String, sort: KBvSort): BitwuzlaTerm { + val bitwuzlaSort = sort.internalizeSort() + return Native.bitwuzlaMkBvValue(bitwuzlaSort, value, BitwuzlaBVBase.BINARY) } - private fun transformCustomBvNumber(value: BigInteger, size: Int): BitwuzlaTerm = - if (size <= Long.SIZE_BITS) { - transformBvLongNumber(value.toLong(), size) - } else { - val intParts = bigIntegerToBvBits(value, size) - Native.bitwuzlaMkBvValueUint32Array(bitwuzla, size, intParts) - } - override fun transform(expr: KBvNotExpr) = with(expr) { transform(value, BitwuzlaKind.BITWUZLA_KIND_BV_NOT) } @@ -645,40 +631,40 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvExtractExpr) = with(expr) { transform(value) { arg: BitwuzlaTerm -> - Native.bitwuzlaMkTerm1Indexed2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_EXTRACT, - arg, - high, low + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_EXTRACT, + arg = arg, + idx0 = high.toLong(), idx1 = low.toLong() ) } } override fun transform(expr: KBvSignExtensionExpr) = with(expr) { transform(value) { arg: BitwuzlaTerm -> - Native.bitwuzlaMkTerm1Indexed1( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_SIGN_EXTEND, - arg, - extensionSize + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_SIGN_EXTEND, + arg = arg, + idx = extensionSize.toLong() ) } } override fun transform(expr: KBvZeroExtensionExpr) = with(expr) { transform(value) { arg: BitwuzlaTerm -> - Native.bitwuzlaMkTerm1Indexed1( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_ZERO_EXTEND, - arg, - extensionSize + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_ZERO_EXTEND, + arg = arg, + idx = extensionSize.toLong() ) } } override fun transform(expr: KBvRepeatExpr) = with(expr) { transform(value) { arg: BitwuzlaTerm -> - Native.bitwuzlaMkTerm1Indexed1( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_REPEAT, - arg, - repeatNumber + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_REPEAT, + arg = arg, + idx = repeatNumber.toLong() ) } } @@ -705,20 +691,20 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvRotateLeftIndexedExpr) = with(expr) { transform(value) { arg: BitwuzlaTerm -> - Native.bitwuzlaMkTerm1Indexed1( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_ROLI, - arg, - rotationNumber + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_ROLI, + arg = arg, + idx = rotationNumber.toLong() ) } } override fun transform(expr: KBvRotateRightIndexedExpr) = with(expr) { transform(value) { arg: BitwuzlaTerm -> - Native.bitwuzlaMkTerm1Indexed1( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_RORI, - arg, - rotationNumber + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_RORI, + arg = arg, + idx = rotationNumber.toLong() ) } } @@ -726,10 +712,10 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvAddNoOverflowExpr) = with(expr) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> if (isSigned) { - mkBvAddSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, BvOverflowCheckMode.OVERFLOW) + mkBvAddSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, OVERFLOW) } else { - val overflowCheck = Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_UADD_OVERFLOW, a0, a1 + val overflowCheck = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_UADD_OVERFLOW, arg0 = a0, arg1 = a1 ) mkNotTerm(overflowCheck) } @@ -738,20 +724,20 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvAddNoUnderflowExpr) = with(expr) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> - mkBvAddSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, BvOverflowCheckMode.UNDERFLOW) + mkBvAddSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, UNDERFLOW) } } override fun transform(expr: KBvSubNoOverflowExpr) = with(expr) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> - mkBvSubSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, BvOverflowCheckMode.OVERFLOW) + mkBvSubSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, OVERFLOW) } } override fun transform(expr: KBvSubNoUnderflowExpr) = with(expr) { if (isSigned) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> - mkBvSubSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, BvOverflowCheckMode.UNDERFLOW) + mkBvSubSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, UNDERFLOW) } } else { transform { @@ -762,7 +748,9 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvDivNoOverflowExpr) = with(expr) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> - val overflowCheck = Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_SDIV_OVERFLOW, a0, a1) + val overflowCheck = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_SDIV_OVERFLOW, arg0 = a0, arg1 = a1 + ) mkNotTerm(overflowCheck) } } @@ -776,10 +764,10 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvMulNoOverflowExpr) = with(expr) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> if (isSigned) { - mkBvMulSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, BvOverflowCheckMode.OVERFLOW) + mkBvMulSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, OVERFLOW) } else { - val overflowCheck = Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_UMUL_OVERFLOW, a0, a1 + val overflowCheck = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_UMUL_OVERFLOW, arg0 = a0, arg1 = a1 ) mkNotTerm(overflowCheck) } @@ -788,7 +776,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KBvMulNoUnderflowExpr) = with(expr) { transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> - mkBvMulSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, BvOverflowCheckMode.UNDERFLOW) + mkBvMulSignedNoOverflowTerm(arg0.sort.sizeBits.toInt(), a0, a1, UNDERFLOW) } } @@ -813,12 +801,12 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL a1, BitwuzlaKind.BITWUZLA_KIND_BV_SADD_OVERFLOW ) { a0Sign, a1Sign -> - if (mode == BvOverflowCheckMode.OVERFLOW) { + if (mode == OVERFLOW) { // Both positive - mkAndTerm(longArrayOf(mkNotTerm(a0Sign), mkNotTerm(a1Sign))) + mkBvAndReducedBool(mkBvNotTerm(a0Sign), mkBvNotTerm(a1Sign)) } else { // Both negative - mkAndTerm(longArrayOf(a0Sign, a1Sign)) + mkBvAndReducedBool(a0Sign, a1Sign) } } @@ -833,12 +821,12 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL a1, BitwuzlaKind.BITWUZLA_KIND_BV_SSUB_OVERFLOW ) { a0Sign, a1Sign -> - if (mode == BvOverflowCheckMode.OVERFLOW) { + if (mode == OVERFLOW) { // Positive sub negative - mkAndTerm(longArrayOf(mkNotTerm(a0Sign), a1Sign)) + mkBvAndReducedBool(mkBvNotTerm(a0Sign), a1Sign) } else { // Negative sub positive - mkAndTerm(longArrayOf(a0Sign, mkNotTerm(a1Sign))) + mkBvAndReducedBool(a0Sign, mkBvNotTerm(a1Sign)) } } @@ -853,12 +841,12 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL a1, BitwuzlaKind.BITWUZLA_KIND_BV_SMUL_OVERFLOW ) { a0Sign, a1Sign -> - if (mode == BvOverflowCheckMode.OVERFLOW) { + if (mode == OVERFLOW) { // Overflow is possible when sign bits are equal - mkEqTerm(bitwuzlaCtx.ctx.boolSort, a0Sign, a1Sign) + mkEqTerm(bitwuzlaCtx.ctx.bv1Sort, a0Sign, a1Sign) } else { // Underflow is possible when sign bits are different - mkNotTerm(mkEqTerm(bitwuzlaCtx.ctx.boolSort, a0Sign, a1Sign)) + mkNotTerm(mkEqTerm(bitwuzlaCtx.ctx.bv1Sort, a0Sign, a1Sign)) } } @@ -873,7 +861,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL checkKind: BitwuzlaKind, checkSign: (BitwuzlaTerm, BitwuzlaTerm) -> BitwuzlaTerm ): BitwuzlaTerm { - val overflowCheck = Native.bitwuzlaMkTerm2(bitwuzla, checkKind, a0, a1) + val overflowCheck = Native.bitwuzlaMkTerm(kind = checkKind, arg0 = a0, arg1 = a1) val a0Sign = mkBvSignTerm(sizeBits, a0) val a1Sign = mkBvSignTerm(sizeBits, a1) @@ -884,26 +872,26 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } private fun mkBvSignTerm(sizeBits: Int, bvExpr: BitwuzlaTerm): BitwuzlaTerm { - return Native.bitwuzlaMkTerm1Indexed2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_BV_EXTRACT, - bvExpr, - sizeBits - 1, sizeBits - 1 + return Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_BV_EXTRACT, + arg = bvExpr, + idx0 = sizeBits.toLong() - 1, idx1 = sizeBits.toLong() - 1 ) } override fun transform(expr: KArrayStore) = with(expr) { transform(array, index, value) { a: BitwuzlaTerm, i: BitwuzlaTerm, v: BitwuzlaTerm -> if (Native.bitwuzlaTermIsArray(a)) { - Native.bitwuzlaMkTerm3(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ARRAY_STORE, a, i, v) + Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_ARRAY_STORE, arg0 = a, arg1 = i, arg2 = v) } else { mkArrayLambdaTerm(index.sort) { lambdaVar -> // (store a i v) ==> (ite (= x i) v (select a x)) val nestedValue = mkArraySelectTerm(array = a, idx = lambdaVar, isArray = false) - val condition = Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, lambdaVar, i + val condition = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_EQUAL, arg0 = lambdaVar, arg1 = i ) - Native.bitwuzlaMkTerm3( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ITE, condition, v, nestedValue + Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_ITE, arg0 = condition, arg1 = v, arg2 = nestedValue ) } } @@ -922,20 +910,20 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL // (store a i j v) ==> (ite (and (= x0 i) (= x1 j)) v (select a x0 x1)) mkArrayLambdaTerm(sort.domainSorts) { lambdaVars -> val selectArgs = lambdaVars.addFirst(a) - val nestedValue = Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, selectArgs) + val nestedValue = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_APPLY, selectArgs) - val condition0 = Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, lambdaVars[0], i0 + val condition0 = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_EQUAL, arg0 = lambdaVars[0], arg1 = i0 ) - val condition1 = Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, lambdaVars[1], i1 + val condition1 = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_EQUAL, arg0 = lambdaVars[1], arg1 = i1 ) - val condition = Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_AND, condition0, condition1 + val condition = Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_AND, arg0 = condition0, arg1 = condition1 ) - Native.bitwuzlaMkTerm3( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ITE, condition, v, nestedValue + Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_ITE, arg0 = condition, arg1 = v, arg2 = nestedValue ) } } @@ -975,22 +963,18 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL return mkArrayLambdaTerm(sort.domainSorts) { lambdaVars: LongArray -> val selectArgs = lambdaVars.addFirst(array) - val nestedValue = Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, selectArgs) + val nestedValue = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_APPLY, selectArgs) val conditions = LongArray(lambdaVars.size) { val index = args[it + 1] // +1 for array argument val lambdaIndex = lambdaVars[it] - Native.bitwuzlaMkTerm2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, lambdaIndex, index - ) + Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_EQUAL, arg0 = lambdaIndex, arg1 = index) } - val condition = Native.bitwuzlaMkTerm( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_AND, conditions - ) + val condition = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_AND, conditions) - Native.bitwuzlaMkTerm3( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ITE, condition, value, nestedValue + Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_ITE, arg0 = condition, arg1 = value, arg2 = nestedValue ) } } @@ -1003,16 +987,16 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL private fun mkArraySelectTerm(isArray: Boolean, array: BitwuzlaTerm, idx: BitwuzlaTerm): BitwuzlaTerm = if (isArray) { - Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_ARRAY_SELECT, array, idx) + Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_ARRAY_SELECT, arg0 = array, arg1 = idx) } else { - Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, array, idx) + Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_APPLY, arg0 = array, arg1 = idx) } override fun transform( expr: KArray2Select ): KExpr = with(expr) { transform(array, index0, index1) { a: BitwuzlaTerm, i0: BitwuzlaTerm, i1: BitwuzlaTerm -> - Native.bitwuzlaMkTerm3(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, a, i0, i1) + Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_APPLY, arg0 = a, arg1 = i0, arg2 = i1) } } @@ -1026,7 +1010,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL index2 ) { a: BitwuzlaTerm, i0: BitwuzlaTerm, i1: BitwuzlaTerm, i2: BitwuzlaTerm -> val args = longArrayOf(a, i0, i1, i2) - Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, args) + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_APPLY, args) } } @@ -1036,7 +1020,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL addAll(expr.indices) } return expr.transformList(exprArgs) { args -> - Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, args) + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_APPLY, args) } } @@ -1080,7 +1064,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL ): BitwuzlaTerm { if (sort is KArraySort<*, *>) { val internalizedSort = sort.internalizeSort() - return Native.bitwuzlaMkConstArray(bitwuzla, internalizedSort, value) + return Native.bitwuzlaMkConstArray(internalizedSort, value) } return mkArrayLambdaTerm(sort.domainSorts) { value } @@ -1109,26 +1093,26 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } private fun mkLambdaTerm(boundVar: BitwuzlaTerm, body: BitwuzlaTerm): BitwuzlaTerm = - Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_LAMBDA, boundVar, body) + Native.bitwuzlaMkTerm(kind = BitwuzlaKind.BITWUZLA_KIND_LAMBDA, arg0 = boundVar, arg1 = body) private fun mkLambdaTerm( bounds: LongArray, body: BitwuzlaTerm ): BitwuzlaTerm { val args = bounds.addLast(body) - return Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_LAMBDA, args) + return Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_LAMBDA, args) } override fun transform( expr: KExistentialQuantifier ): KExpr = expr.internalizeQuantifier { args -> - Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EXISTS, args) + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_EXISTS, args) } override fun transform( expr: KUniversalQuantifier ): KExpr = expr.internalizeQuantifier { args -> - Native.bitwuzlaMkTerm(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_FORALL, args) + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_FORALL, args) } override fun transform(expr: KBv2IntExpr): KExpr { @@ -1221,8 +1205,8 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL private fun > transformFpValue(expr: T): T = with(expr) { transform(biasedExponent, significand) { exponent: BitwuzlaTerm, significand: BitwuzlaTerm -> - val sign = if (signBit) bitwuzlaCtx.trueTerm else bitwuzlaCtx.falseTerm - Native.bitwuzlaMkFpValue(bitwuzla, sign, exponent, significand) + val sign = if (signBit) bitwuzlaCtx.bv1OneTerm else bitwuzlaCtx.bv1ZeroTerm + Native.bitwuzlaMkFpValue(sign, exponent, significand) } } @@ -1245,7 +1229,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL KFpRoundingMode.RoundTowardNegative -> BitwuzlaRoundingMode.BITWUZLA_RM_RTN KFpRoundingMode.RoundTowardZero -> BitwuzlaRoundingMode.BITWUZLA_RM_RTZ } - Native.bitwuzlaMkRmValue(bitwuzla, rmMode) + Native.bitwuzlaMkRmValue(rmMode) } } @@ -1314,7 +1298,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } override fun transform(expr: KFpEqualExpr): KExpr = with(expr) { - transform(arg0, arg1, BitwuzlaKind.BITWUZLA_KIND_FP_EQ) + transform(arg0, arg1, BitwuzlaKind.BITWUZLA_KIND_FP_EQUAL) } override fun transform(expr: KFpIsNormalExpr): KExpr = with(expr) { @@ -1348,7 +1332,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KFpToBvExpr): KExpr = with(expr) { transform(roundingMode, value) { rm: BitwuzlaTerm, value: BitwuzlaTerm -> val operation = if (isSigned) BitwuzlaKind.BITWUZLA_KIND_FP_TO_SBV else BitwuzlaKind.BITWUZLA_KIND_FP_TO_UBV - Native.bitwuzlaMkTerm2Indexed1(bitwuzla, operation, rm, value, bvSize) + Native.bitwuzlaMkTerm2Indexed(kind = operation, arg0 = rm, arg1 = value, idx = bvSize.toLong()) } } @@ -1358,13 +1342,10 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun transform(expr: KFpToFpExpr): KExpr = with(expr) { transform(roundingMode, value) { rm: BitwuzlaTerm, value: BitwuzlaTerm -> - Native.bitwuzlaMkTerm2Indexed2( - bitwuzla, - BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_FP, - rm, - value, - sort.exponentBits.toInt(), - sort.significandBits.toInt() + Native.bitwuzlaMkTermIndexed( + kind = BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_FP, + arg0 = rm, arg1 = value, + idx0 = sort.exponentBits.toLong(), idx1 = sort.significandBits.toLong() ) } } @@ -1375,8 +1356,8 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL biasedExponent, significand ) { sign: BitwuzlaTerm, exp: BitwuzlaTerm, significand: BitwuzlaTerm -> - Native.bitwuzlaMkTerm3( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_FP_FP, sign, exp, significand + Native.bitwuzlaMkTerm( + kind = BitwuzlaKind.BITWUZLA_KIND_FP_FP, arg0 = sign, arg1 = exp, arg2 = significand ) } } @@ -1388,8 +1369,10 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } else { BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_UBV } - Native.bitwuzlaMkTerm2Indexed2( - bitwuzla, operation, rm, value, sort.exponentBits.toInt(), sort.significandBits.toInt() + Native.bitwuzlaMkTermIndexed( + kind = operation, + arg0 = rm, arg1 = value, + idx0 = sort.exponentBits.toLong(), idx1 = sort.significandBits.toLong() ) } } @@ -1401,10 +1384,11 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } override fun transform(expr: KUninterpretedSortValue): KExpr = expr.transform { - Native.bitwuzlaMkBvValueUint32( - bitwuzla, + // register it for uninterpreted sort universe + bitwuzlaCtx.registerDeclaration(expr.decl) + Native.bitwuzlaMkBvValueUint64( expr.sort.internalizeSort(), - expr.valueIdx + expr.valueIdx.toLong() ) } @@ -1466,9 +1450,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL boundVars[idx] = bitwuzlaCtx.mkVar(boundDecl, boundSort) } - val internalizedBodyWithVars = Native.bitwuzlaSubstituteTerm( - bitwuzla, internalizedBody, boundConstants, boundVars - ) + val internalizedBodyWithVars = Native.bitwuzlaSubstituteTerm(internalizedBody, boundConstants, boundVars) /** * Body has not changed after substitution => quantified vars do not occur in the body @@ -1495,7 +1477,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL val domain = internalizeSort(sort.domain) val range = internalizeSort(sort.range) - internalizedSort = Native.bitwuzlaMkArraySort(bitwuzlaCtx.bitwuzla, domain, range) + internalizedSort = Native.bitwuzlaMkArraySort(domain, range) } override fun visit(sort: KArray2Sort) { @@ -1509,7 +1491,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL ) val range = internalizeSort(sort.range) - internalizedSort = Native.bitwuzlaMkFunSort(bitwuzlaCtx.bitwuzla, domain.size, domain, range) + internalizedSort = Native.bitwuzlaMkFunSort(domain, range) } override fun visit(sort: KArray3Sort) { @@ -1525,7 +1507,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL ) val range = internalizeSort(sort.range) - internalizedSort = Native.bitwuzlaMkFunSort(bitwuzlaCtx.bitwuzla, domain.size, domain, range) + internalizedSort = Native.bitwuzlaMkFunSort(domain, range) } override fun visit(sort: KArrayNSort) { @@ -1537,7 +1519,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } val range = internalizeSort(sort.range) - internalizedSort = Native.bitwuzlaMkFunSort(bitwuzlaCtx.bitwuzla, domain.size, domain, range) + internalizedSort = Native.bitwuzlaMkFunSort(domain, range) } private fun checkNoNestedArrays(sort: KSort) { @@ -1548,12 +1530,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun visit(sort: S) { val size = sort.sizeBits.toInt() - - internalizedSort = if (size == 1) { - bitwuzlaCtx.boolSort - } else { - Native.bitwuzlaMkBvSort(bitwuzlaCtx.bitwuzla, size) - } + internalizedSort = Native.bitwuzlaMkBvSort(size) } /** @@ -1565,24 +1542,19 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL override fun visit(sort: KRealSort) = throw KSolverUnsupportedFeatureException("Unsupported sort $sort") - /** - * Replace Uninterpreted sorts with (BitVec 32). - * The sort universe size is limited by 2^32 values which should be enough. - * */ override fun visit(sort: KUninterpretedSort) { - internalizedSort = Native.bitwuzlaMkBvSort(bitwuzlaCtx.bitwuzla, UNINTERPRETED_SORT_REPLACEMENT_BV_SIZE) + internalizedSort = Native.bitwuzlaMkBvSort(UNINTERPRETED_SORT_REPLACEMENT_BV_SIZE) } override fun visit(sort: S) { internalizedSort = Native.bitwuzlaMkFpSort( - bitwuzlaCtx.bitwuzla, - expSize = sort.exponentBits.toInt(), - sigSize = sort.significandBits.toInt() + expSize = sort.exponentBits.toLong(), + sigSize = sort.significandBits.toLong() ) } override fun visit(sort: KFpRoundingModeSort) { - internalizedSort = Native.bitwuzlaMkRmSort(bitwuzlaCtx.bitwuzla) + internalizedSort = Native.bitwuzlaMkRmSort() } fun internalizeSort(sort: KSort): BitwuzlaSort = bitwuzlaCtx.internalizeSort(sort) { @@ -1591,7 +1563,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL } companion object { - const val UNINTERPRETED_SORT_REPLACEMENT_BV_SIZE = 32 + const val UNINTERPRETED_SORT_REPLACEMENT_BV_SIZE = 32L } } @@ -1618,7 +1590,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL declSort = if (domain.isEmpty()) { range } else { - Native.bitwuzlaMkFunSort(bitwuzlaCtx.bitwuzla, domain.size, domain, range) + Native.bitwuzlaMkFunSort(domain, range) } } @@ -1635,7 +1607,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL fun > S.transform( arg: KExpr<*>, kind: BitwuzlaKind - ): S = transform(arg) { a0: BitwuzlaTerm -> Native.bitwuzlaMkTerm1(bitwuzla, kind, a0) } + ): S = transform(arg) { a0: BitwuzlaTerm -> Native.bitwuzlaMkTerm(kind, a0) } fun > S.transform( @@ -1643,7 +1615,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL arg1: KExpr<*>, kind: BitwuzlaKind ): S = transform(arg0, arg1) { a0: BitwuzlaTerm, a1: BitwuzlaTerm -> - Native.bitwuzlaMkTerm2(bitwuzla, kind, a0, a1) + Native.bitwuzlaMkTerm(kind = kind, arg0 = a0, arg1 = a1) } fun > S.transform( @@ -1652,7 +1624,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL arg2: KExpr<*>, kind: BitwuzlaKind ): S = transform(arg0, arg1, arg2) { a0: BitwuzlaTerm, a1: BitwuzlaTerm, a2: BitwuzlaTerm -> - Native.bitwuzlaMkTerm3(bitwuzla, kind, a0, a1, a2) + Native.bitwuzlaMkTerm(kind = kind, arg0 = a0, arg1 = a1, arg2 = a2) } fun > S.transform( @@ -1663,7 +1635,7 @@ open class KBitwuzlaExprInternalizer(val bitwuzlaCtx: KBitwuzlaContext) : KExprL kind: BitwuzlaKind ): S = transform(arg0, arg1, arg2, arg3) { a0: BitwuzlaTerm, a1: BitwuzlaTerm, a2: BitwuzlaTerm, a3: BitwuzlaTerm -> val args = longArrayOf(a0, a1, a2, a3) - Native.bitwuzlaMkTerm(bitwuzla, kind, args) + Native.bitwuzlaMkTerm(kind, args) } /** diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaModel.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaModel.kt index f36e43c99..dcc262c8c 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaModel.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaModel.kt @@ -2,18 +2,14 @@ package io.ksmt.solver.bitwuzla import io.ksmt.KContext import io.ksmt.decl.KDecl +import io.ksmt.decl.KUninterpretedSortValueDecl import io.ksmt.expr.KExpr import io.ksmt.expr.KUninterpretedSortValue +import io.ksmt.solver.KModel import io.ksmt.solver.model.KFuncInterp import io.ksmt.solver.model.KFuncInterpEntryVarsFree import io.ksmt.solver.model.KFuncInterpEntryVarsFreeOneAry import io.ksmt.solver.model.KFuncInterpVarsFree -import io.ksmt.solver.KModel -import io.ksmt.solver.KSolverUnsupportedFeatureException -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm -import org.ksmt.solver.bitwuzla.bindings.FunValue -import org.ksmt.solver.bitwuzla.bindings.Native import io.ksmt.solver.model.KFuncInterpWithVars import io.ksmt.solver.model.KModelEvaluator import io.ksmt.solver.model.KModelImpl @@ -21,13 +17,18 @@ import io.ksmt.sort.KArraySort import io.ksmt.sort.KArraySortBase import io.ksmt.sort.KSort import io.ksmt.sort.KUninterpretedSort +import io.ksmt.utils.mkFreshConst import io.ksmt.utils.mkFreshConstDecl import io.ksmt.utils.uncheckedCast +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm +import org.ksmt.solver.bitwuzla.bindings.Native open class KBitwuzlaModel( private val ctx: KContext, private val bitwuzlaCtx: KBitwuzlaContext, private val converter: KBitwuzlaExprConverter, + private val internalizer: KBitwuzlaExprInternalizer, assertedDeclarations: Set>, private val uninterpretedSortDependency: Map>> ) : KModel { @@ -77,7 +78,12 @@ open class KBitwuzlaModel( * to ensure that [uninterpretedSortValueContext] contains * all possible values for the given sort. * */ - sortDependency.forEach { interpretation(it) } + sortDependency.forEach { + if (it is KUninterpretedSortValueDecl) { + val value = ctx.mkUninterpretedSortValue(it.sort, it.valueIdx) + uninterpretedSortValueContext.registerValue(value) + } else interpretation(it) + } uninterpretedSortValueContext.currentSortUniverse(sort) } @@ -95,21 +101,12 @@ open class KBitwuzlaModel( val bitwuzlaConstant = bitwuzlaCtx.findConstant(decl) ?: return@interpretation null - getInterpretationSafe(decl, bitwuzlaConstant) + getInterpretation(decl, bitwuzlaConstant) } return interpretation.uncheckedCast() } - private fun getInterpretationSafe( - decl: KDecl, - term: BitwuzlaTerm - ): KFuncInterp = bitwuzlaCtx.bitwuzlaTry { - handleModelIsUnsupportedWithQuantifiers { - getInterpretation(decl, term) - } - } - private fun getInterpretation( decl: KDecl, term: BitwuzlaTerm @@ -132,39 +129,41 @@ open class KBitwuzlaModel( private fun functionInterpretation( decl: KDecl, term: BitwuzlaTerm - ): KFuncInterp { - val interp = Native.bitwuzlaGetFunValue(bitwuzlaCtx.bitwuzla, term) - return if (interp.size != 0) { - handleArrayFunctionDecl(decl) { functionDecl -> - functionValueInterpretation(functionDecl, interp) - } - } else { - /** - * Function has default value or bitwuzla can't retrieve its entries. - * Try parse function interpretation from value term. - * */ - converter.retrieveFunctionValue(decl, term) - } + ): KFuncInterp = if (decl.argSorts.isEmpty()) + converter.retrieveFunctionValue(decl, term) + else handleArrayFunctionDecl(decl) { functionDecl -> + val interp = Native.bitwuzlaGetValue(bitwuzlaCtx.bitwuzla, term) + functionValueInterpretation(functionDecl, interp) } - private fun KBitwuzlaExprConverter.functionValueInterpretation( + private fun functionValueInterpretation( decl: KDecl, - interp: FunValue - ): KFuncInterpVarsFree { - val entries = mutableListOf>() - - for (i in 0 until interp.size) { - // Don't substitute vars since arguments in Bitwuzla model are always constants - val args = interp.args!![i].zip(decl.argSorts) { arg, sort -> arg.convertExpr(sort) } - val value = interp.values!![i].convertExpr(decl.sort) - entries += KFuncInterpEntryVarsFree.create(args, value) + interp: BitwuzlaTerm + ): KFuncInterpWithVars { + val vars = decl.argSorts.map { it.mkFreshConst("x") } + + val (bitwuzlaInterpVars, bitwuzlaInterpValue) = let { + val varTerms = mutableListOf() + var (varTerm, lambdaTerm) = Native.bitwuzlaTermGetChildren(interp) + varTerms += varTerm + while (Native.bitwuzlaTermGetKind(lambdaTerm) == BitwuzlaKind.BITWUZLA_KIND_LAMBDA) { + val children = Native.bitwuzlaTermGetChildren(lambdaTerm) + varTerm = children[0] + varTerms += varTerm + lambdaTerm = children[1] + } + + varTerms.toLongArray() to lambdaTerm } - return KFuncInterpVarsFree( - decl = decl, - entries = entries, - default = null - ) + val bitwuzlaVars = vars.map { with(internalizer) { it.internalizeExpr() } }.toLongArray() + val bitwuzlaFreshInterp = Native.bitwuzlaSubstituteTerm(bitwuzlaInterpValue, bitwuzlaInterpVars, bitwuzlaVars) + + val varsToDecls = bitwuzlaVars.zip(vars).associate { (varTerm, varApp) -> varTerm to varApp.decl } + val c = KBitwuzlaExprConverter(ctx, bitwuzlaCtx, varsToDecls) + val defaultBody = with(c) { bitwuzlaFreshInterp.convertExpr(decl.sort) } + + return KFuncInterpWithVars(decl, vars.map { it.decl }, emptyList(), defaultBody) } private fun KBitwuzlaExprConverter.retrieveFunctionValue( @@ -182,21 +181,19 @@ open class KBitwuzlaModel( ): KFuncInterp = handleArrayFunctionDecl(decl) { arrayFunctionDecl -> val sort: KArraySort = decl.sort.uncheckedCast() val entries = mutableListOf>() - val interp = Native.bitwuzlaGetArrayValue(bitwuzlaCtx.bitwuzla, term) - for (i in 0 until interp.size) { - val index = interp.indices!![i].convertExpr(sort.domain) - val value = interp.values!![i].convertExpr(sort.range) + val interp = Native.bitwuzlaGetValue(bitwuzlaCtx.bitwuzla, term) + + var currentEntry = interp + while (Native.bitwuzlaTermGetKind(currentEntry) == BitwuzlaKind.BITWUZLA_KIND_ARRAY_STORE) { + val (array, bzlaIndex, bzlaValue) = Native.bitwuzlaTermGetChildren(currentEntry) + val index = bzlaIndex.convertExpr(sort.domain) + val value = bzlaValue.convertExpr(sort.range) entries += KFuncInterpEntryVarsFreeOneAry(index, value) + currentEntry = array } - - val default = interp.defaultValue.takeIf { it != 0L }?.convertExpr(sort.range) - - KFuncInterpVarsFree( - decl = arrayFunctionDecl, - entries = entries, - default = default - ) + val defaultValue = Native.bitwuzlaTermGetChildren(currentEntry)[0].convertExpr(sort.range) + KFuncInterpVarsFree(arrayFunctionDecl, entries, defaultValue) } private inline fun handleArrayFunctionDecl( @@ -273,35 +270,4 @@ open class KBitwuzlaModel( if (other !is KModel) return false return detach() == other } - - /** - * Models are currently not supported for formulas with quantifiers. - * Handle this case as unsupported feature rather than general solver failure. - * */ - private inline fun handleModelIsUnsupportedWithQuantifiers(body: () -> T): T = try { - body() - } catch (ex: BitwuzlaNativeException) { - if (isModelUnsupportedWithQuantifiers(ex)) { - throw KSolverUnsupportedFeatureException("Model are not supported for formulas with quantifiers") - } - throw ex - } - - companion object { - private const val MODEL_UNSUPPORTED_WITH_QUANTIFIERS = - "'get-value' is currently not supported with quantifiers\n" - - private fun isModelUnsupportedWithQuantifiers(ex: BitwuzlaNativeException): Boolean { - val message = ex.message ?: return false - /** - * Bitwuzla exception message has the following format: - * `[bitwuzla] 'get-value' is currently ....`. - * - * Since we don't know the actual api method name - * (we have multiple ways to trigger get-value), - * we use `endsWith`. - * */ - return message.endsWith(MODEL_UNSUPPORTED_WITH_QUANTIFIERS) - } - } } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolver.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolver.kt index 5d86b25b9..bf1d9d25f 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolver.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolver.kt @@ -1,22 +1,21 @@ package io.ksmt.solver.bitwuzla -import it.unimi.dsi.fastutil.longs.LongOpenHashSet import io.ksmt.KContext import io.ksmt.expr.KExpr import io.ksmt.solver.KModel import io.ksmt.solver.KSolver import io.ksmt.solver.KSolverStatus +import io.ksmt.sort.KBoolSort +import it.unimi.dsi.fastutil.longs.LongOpenHashSet +import kotlin.time.Duration import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaOption import org.ksmt.solver.bitwuzla.bindings.BitwuzlaResult import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTermArray import org.ksmt.solver.bitwuzla.bindings.Native -import io.ksmt.sort.KBoolSort -import kotlin.time.Duration open class KBitwuzlaSolver(private val ctx: KContext) : KSolver { - open val bitwuzlaCtx = KBitwuzlaContext(ctx) + open val bitwuzlaCtx by lazy { KBitwuzlaContext(ctx) } open val exprInternalizer: KBitwuzlaExprInternalizer by lazy { KBitwuzlaExprInternalizer(bitwuzlaCtx) } @@ -29,21 +28,15 @@ open class KBitwuzlaSolver(private val ctx: KContext) : KSolver, BitwuzlaTerm>>() private val trackVarsAssertionFrames = arrayListOf(trackedAssertions) override fun configure(configurator: KBitwuzlaSolverConfiguration.() -> Unit) { - KBitwuzlaSolverConfigurationImpl(bitwuzlaCtx.bitwuzla).configurator() + bitwuzlaCtx.ensureBitwuzlaNotInitialized() + KBitwuzlaSolverConfigurationImpl(bitwuzlaCtx.bitwuzlaOptions).configurator() } - override fun assert(expr: KExpr) = bitwuzlaCtx.bitwuzlaTry { - ctx.ensureContextMatch(expr) - + private fun internalizeAndAssertWithAxioms(expr: KExpr) { val assertionWithAxioms = with(exprInternalizer) { expr.internalizeAssertion() } assertionWithAxioms.axioms.forEach { @@ -52,6 +45,11 @@ open class KBitwuzlaSolver(private val ctx: KContext) : KSolver) = bitwuzlaCtx.bitwuzlaTry { + ctx.ensureContextMatch(expr) + internalizeAndAssertWithAxioms(expr) + } + override fun assertAndTrack(expr: KExpr) = bitwuzlaCtx.bitwuzlaTry { ctx.ensureContextMatch(expr) @@ -59,7 +57,6 @@ open class KBitwuzlaSolver(private val ctx: KContext) : KSolver + internalizedAssumptions[idx] = assumptions[idx].internalize() + currentAssumptions.assumeAssumption(assumption, internalizedAssumptions[idx]) + } + trackedAssertions.forEachIndexed { idx, (_, track) -> + internalizedAssumptions[assumptions.size + idx] = track } } - checkWithTimeout(timeout).processCheckResult() + checkWithTimeout(timeout, internalizedAssumptions).processCheckResult() } - private fun checkWithTimeout(timeout: Duration): BitwuzlaResult = if (timeout.isInfinite()) { - Native.bitwuzlaCheckSatResult(bitwuzlaCtx.bitwuzla) - } else { - Native.bitwuzlaCheckSatTimeoutResult(bitwuzlaCtx.bitwuzla, timeout.inWholeMilliseconds) + private fun checkWithTimeout(timeout: Duration, assumptions: BitwuzlaTermArray): BitwuzlaResult { + return Native.bitwuzlaCheckSatWithTimeout( + bitwuzlaCtx.bitwuzla, assumptions, + if (timeout == Duration.INFINITE) Long.MAX_VALUE / 2 else timeout.inWholeMilliseconds + ) } override fun model(): KModel = bitwuzlaCtx.bitwuzlaTry { require(lastCheckStatus == KSolverStatus.SAT) { "Model are only available after SAT checks" } val model = lastModel ?: KBitwuzlaModel( - ctx, bitwuzlaCtx, exprConverter, + ctx, bitwuzlaCtx, exprConverter, exprInternalizer, bitwuzlaCtx.declarations(), bitwuzlaCtx.uninterpretedSortsWithRelevantDecls() ) @@ -184,8 +189,7 @@ open class KBitwuzlaSolver(private val ctx: KContext) : KSolver, BitwuzlaTerm>>() fun assumeTrackedAssertion(trackedAssertion: Pair, BitwuzlaTerm>) { - assumedExprs.add(trackedAssertion) - Native.bitwuzlaAssume(bitwuzlaCtx.bitwuzla, trackedAssertion.second) + assumedExprs += trackedAssertion } fun assumeAssumption(expr: KExpr, term: BitwuzlaTerm) = diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolverConfiguration.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolverConfiguration.kt index a40ee8a60..1d8164d10 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolverConfiguration.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaSolverConfiguration.kt @@ -3,12 +3,13 @@ package io.ksmt.solver.bitwuzla import io.ksmt.solver.KSolverConfiguration import io.ksmt.solver.KSolverUniversalConfigurationBuilder import io.ksmt.solver.KSolverUnsupportedParameterException -import org.ksmt.solver.bitwuzla.bindings.Bitwuzla import org.ksmt.solver.bitwuzla.bindings.BitwuzlaOption +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaOptionsNative import org.ksmt.solver.bitwuzla.bindings.Native interface KBitwuzlaSolverConfiguration : KSolverConfiguration { - fun setBitwuzlaOption(option: BitwuzlaOption, value: Int) + fun setBitwuzlaOption(option: BitwuzlaOption, value: Long) + fun setBitwuzlaOption(option: BitwuzlaOption, value: Int) = setBitwuzlaOption(option, value.toLong()) fun setBitwuzlaOption(option: BitwuzlaOption, value: String) override fun setIntParameter(param: String, value: Int) { @@ -34,21 +35,23 @@ interface KBitwuzlaSolverConfiguration : KSolverConfiguration { } } -class KBitwuzlaSolverConfigurationImpl(private val bitwuzla: Bitwuzla) : KBitwuzlaSolverConfiguration { - override fun setBitwuzlaOption(option: BitwuzlaOption, value: Int) { - Native.bitwuzlaSetOption(bitwuzla, option, value) +class KBitwuzlaSolverConfigurationImpl( + private val bitwuzlaOptions: BitwuzlaOptionsNative +) : KBitwuzlaSolverConfiguration { + override fun setBitwuzlaOption(option: BitwuzlaOption, value: Long) { + Native.bitwuzlaSetOption(bitwuzlaOptions, option, value) } override fun setBitwuzlaOption(option: BitwuzlaOption, value: String) { - Native.bitwuzlaSetOptionStr(bitwuzla, option, value) + Native.bitwuzlaSetOptionMode(bitwuzlaOptions, option, value) } } class KBitwuzlaSolverUniversalConfiguration( private val builder: KSolverUniversalConfigurationBuilder ) : KBitwuzlaSolverConfiguration { - override fun setBitwuzlaOption(option: BitwuzlaOption, value: Int) { - builder.buildIntParameter(option.name, value) + override fun setBitwuzlaOption(option: BitwuzlaOption, value: Long) { + builder.buildIntParameter(option.name, value.toInt()) } override fun setBitwuzlaOption(option: BitwuzlaOption, value: String) { diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaUninterpretedSortValueContext.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaUninterpretedSortValueContext.kt index cd7e184ba..d0c4d8d9f 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaUninterpretedSortValueContext.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/io/ksmt/solver/bitwuzla/KBitwuzlaUninterpretedSortValueContext.kt @@ -10,10 +10,12 @@ class KBitwuzlaUninterpretedSortValueContext(private val ctx: KContext) { private val sortsUniverses = hashMapOf, KUninterpretedSortValue>>() fun mkValue(sort: KUninterpretedSort, value: KBitVec32Value): KUninterpretedSortValue { - val sortUniverse = sortsUniverses.getOrPut(sort) { hashMapOf() } - return sortUniverse.getOrPut(value) { - ctx.mkUninterpretedSortValue(sort, value.intValue) - } + return registerValue(ctx.mkUninterpretedSortValue(sort, value.intValue)) + } + + fun registerValue(value: KUninterpretedSortValue): KUninterpretedSortValue { + val sortsUniverse = sortsUniverses.getOrPut(value.sort) { hashMapOf() } + return sortsUniverse.getOrPut(value) { value } } fun currentSortUniverse(sort: KUninterpretedSort): Set = diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/ArrayValue.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/ArrayValue.kt deleted file mode 100644 index 094c62b1a..000000000 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/ArrayValue.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.ksmt.solver.bitwuzla.bindings - -/** - * @param indices List of indices of size `size`. 1:1 mapping to `values`, - * i.e., `index(i) -> value(i)`. - * @param values List of values of size `size`. - * @param size Size of `indices` and `values` list. - * @param defaultValue The value of all other indices not in `indices` and - * is set when base array is a constant array. - */ -class ArrayValue { - @JvmField - var size: Int = 0 - @JvmField - var indices: LongArray? = null //Array of BitwuzlaTerms - @JvmField - var values: LongArray? = null //Array of BitwuzlaTerms - @JvmField - var defaultValue: BitwuzlaTerm = 0 -} diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaBVBase.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaBVBase.kt index e5b4438d4..03f9fb549 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaBVBase.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaBVBase.kt @@ -6,17 +6,8 @@ package org.ksmt.solver.bitwuzla.bindings * The base for strings representing bit-vector values. */ enum class BitwuzlaBVBase(val value: Int) { - /** binary */ - BITWUZLA_BV_BASE_BIN(0), + BINARY(2), DECIMAL(10), HEXADECIMAL(16); - /** decimal */ - BITWUZLA_BV_BASE_DEC(1), - - /** hexadecimal */ - BITWUZLA_BV_BASE_HEX(2); - - companion object { - private val valueMapping = BitwuzlaBVBase.values().associateBy { it.value } - fun fromValue(value: Int): BitwuzlaBVBase = valueMapping.getValue(value) - } + val nativeValue: Byte + get() = value.toByte() } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaKind.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaKind.kt index e1015eb02..9f0c71d49 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaKind.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaKind.kt @@ -7,16 +7,16 @@ package org.ksmt.solver.bitwuzla.bindings */ enum class BitwuzlaKind(val value: Int) { /** First order constant. */ - BITWUZLA_KIND_CONST(0), + BITWUZLA_KIND_CONSTANT(0), /** Constant array. */ BITWUZLA_KIND_CONST_ARRAY(1), /** Value. */ - BITWUZLA_KIND_VAL(2), + BITWUZLA_KIND_VALUE(2), /** Bound variable. */ - BITWUZLA_KIND_VAR(3), + BITWUZLA_KIND_VARIABLE(3), /** * Boolean and. @@ -25,662 +25,895 @@ enum class BitwuzlaKind(val value: Int) { */ BITWUZLA_KIND_AND(4), - /** Function application. */ - BITWUZLA_KIND_APPLY(5), + /** + * Disequality. + * + * SMT-LIB: `distinct` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_DISTINCT(5), + + /** + * Equality. + * + * SMT-LIB: `=` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_EQUAL(6), + + /** + * Boolean if and only if. + * + * SMT-LIB: `=` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_IFF(7), + + /** + * Boolean implies. + * + * SMT-LIB: `=>` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_IMPLIES(8), + + /** + * Boolean not. + * + * SMT_LIB: `not` + * + * Number of Arguments: 1 + */ + BITWUZLA_KIND_NOT(9), + + /** + * Boolean or. + * + * SMT_LIB: `or` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_OR(10), + + /** + * Boolean xor. + * + * SMT_LIB: `xor` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_XOR(11), + + //// Core + /** + * If-then-else. + * + * SMT_LIB: `ite` + * + * Number of Arguments: 3 + */ + BITWUZLA_KIND_ITE(12), + + //// Quantifiers + /** + * Existential quantification. + * + * SMT_LIB: `exists` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_EXISTS(13), + + /** + * Universal quantification. + * + * SMT_LIB: `forall` + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_FORALL(14), + + //// Functions + /** + * Function application. + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_APPLY(15), + + /** + * Lambda. + * + * Number of Arguments: >= 2 + */ + BITWUZLA_KIND_LAMBDA(16), + //// Arrays /** * Array select. * - * SMT-LIB: `select` + * SMT_LIB: `select` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_ARRAY_SELECT(6), + BITWUZLA_KIND_ARRAY_SELECT(17), /** * Array store. * - * SMT-LIB: `store` + * SMT_LIB: `store` + * + * Number of Arguments: 3 */ - BITWUZLA_KIND_ARRAY_STORE(7), + BITWUZLA_KIND_ARRAY_STORE(18), + //// Bit-vectors /** * Bit-vector addition. * - * SMT-LIB: `bvadd` + * SMT_LIB: `bvadd` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_ADD(8), + BITWUZLA_KIND_BV_ADD(19), /** * Bit-vector and. * - * SMT-LIB: `bvand` + * SMT_LIB: `bvand` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_AND(9), + BITWUZLA_KIND_BV_AND(20), /** * Bit-vector arithmetic right shift. * - * SMT-LIB: `bvashr` + * SMT_LIB: `bvashr` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_ASHR(10), + BITWUZLA_KIND_BV_ASHR(21), /** * Bit-vector comparison. * - * SMT-LIB: `bvcomp` + * SMT_LIB: `bvcomp` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_COMP(11), + BITWUZLA_KIND_BV_COMP(22), /** * Bit-vector concat. * - * SMT-LIB: `concat` + * SMT_LIB: `concat` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_CONCAT(12), + BITWUZLA_KIND_BV_CONCAT(23), /** * Bit-vector decrement. * * Decrement by one. + * + * Number of arguments: 1 */ - BITWUZLA_KIND_BV_DEC(13), + BITWUZLA_KIND_BV_DEC(24), /** * Bit-vector increment. * * Increment by one. + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_BV_INC(14), + BITWUZLA_KIND_BV_INC(25), /** * Bit-vector multiplication. * - * SMT-LIB: `bvmul` + * SMT_LIB: `bvmul` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_MUL(15), + BITWUZLA_KIND_BV_MUL(26), /** * Bit-vector nand. * - * SMT-LIB: `bvnand` + * SMT_LIB: `bvnand` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_NAND(16), + BITWUZLA_KIND_BV_NAND(27), /** * Bit-vector negation (two's complement). * - * SMT-LIB: `bvneg` + * SMT_LIB: `bvneg` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_BV_NEG(17), + BITWUZLA_KIND_BV_NEG(28), /** * Bit-vector nor. * - * SMT-LIB: `bvnor` + * SMT_LIB: `bvnor` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_NOR(18), + BITWUZLA_KIND_BV_NOR(29), /** * Bit-vector not (one's complement). * - * SMT-LIB: `bvnot` + * SMT_LIB: `bvnot` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_BV_NOT(19), + BITWUZLA_KIND_BV_NOT(30), /** * Bit-vector or. * - * SMT-LIB: `bvor` + * SMT_LIB: `bvor` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_OR(20), + BITWUZLA_KIND_BV_OR(31), /** * Bit-vector and reduction. * - * Bit-wise *and* reduction, all bits are *and*'ed together into a single bit. + * Bit-wise `and` (reduction), all bits are `and`'ed together into a single + * bit. This corresponds to bit-wise `and` reduction as known from Verilog. * - * This corresponds to bit-wise *and* reduction as known from Verilog. + * Number of Arguments: 1 */ - BITWUZLA_KIND_BV_REDAND(21), + BITWUZLA_KIND_BV_REDAND(32), /** * Bit-vector reduce or. * - * Bit-wise *or* reduction, all bits are *or*'ed together into a single bit. + * Bit-wise `or` (reduction), all bits are `or`'ed together into a single + * bit. This corresponds to bit-wise `or` reduction as known from Verilog. * - * This corresponds to bit-wise *or* reduction as known from Verilog. + * Number of Arguments: 1 */ - BITWUZLA_KIND_BV_REDOR(22), + BITWUZLA_KIND_BV_REDOR(33), /** * Bit-vector reduce xor. * - * Bit-wise *xor* reduction, all bits are *xor*'ed together into a single bit. + * Bit-wise `xor` (reduction), all bits are `xor`'ed together into a single + * bit. This corresponds to bit-wise `xor` reduction as known from Verilog. * - * This corresponds to bit-wise *xor* reduction as known from Verilog. + * Number of Arguments: 1 */ - BITWUZLA_KIND_BV_REDXOR(23), + BITWUZLA_KIND_BV_REDXOR(34), /** * Bit-vector rotate left (not indexed). * - * This is a non-indexed variant of SMT-LIB \c rotate_left. + * This is a non-indexed variant of SMT-LIB `rotate_left`. + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_ROL(24), + BITWUZLA_KIND_BV_ROL(35), /** * Bit-vector rotate right. * - * This is a non-indexed variant of SMT-LIB \c rotate_right. + * This is a non-indexed variant of SMT-LIB `rotate_right`. + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_ROR(25), + BITWUZLA_KIND_BV_ROR(36), /** * Bit-vector signed addition overflow test. * - * Single bit to indicate if signed addition produces an overflow. + * Predicate indicating if signed addition produces an overflow. + * + * SMT_LIB: `bvsaddo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SADD_OVERFLOW(26), + BITWUZLA_KIND_BV_SADD_OVERFLOW(37), /** * Bit-vector signed division overflow test. * - * Single bit to indicate if signed division produces an overflow. + * Predicate indicating if signed division produces an overflow. + * + * SMT_LIB: `bvsdivo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SDIV_OVERFLOW(27), + BITWUZLA_KIND_BV_SDIV_OVERFLOW(38), /** * Bit-vector signed division. * - * SMT-LIB: `bvsdiv` + * SMT_LIB: `bvsdiv` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SDIV(28), + BITWUZLA_KIND_BV_SDIV(39), /** * Bit-vector signed greater than or equal. * - * SMT-LIB: `bvsle` + * SMT_LIB: `bvsle` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SGE(29), + BITWUZLA_KIND_BV_SGE(40), /** * Bit-vector signed greater than. * - * SMT-LIB: `bvslt` + * SMT_LIB: `bvslt` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SGT(30), + BITWUZLA_KIND_BV_SGT(41), /** * Bit-vector logical left shift. * - * SMT-LIB: `bvshl` + * SMT_LIB: `bvshl` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SHL(31), + BITWUZLA_KIND_BV_SHL(42), /** * Bit-vector logical right shift. * - * SMT-LIB: `bvshr` + * SMT_LIB: `bvshr` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SHR(32), + BITWUZLA_KIND_BV_SHR(43), /** * Bit-vector signed less than or equal. * - * SMT-LIB: `bvsle` + * SMT_LIB: `bvsle` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SLE(33), + BITWUZLA_KIND_BV_SLE(44), /** * Bit-vector signed less than. * - * SMT-LIB: `bvslt` + * SMT_LIB: `bvslt` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SLT(34), + BITWUZLA_KIND_BV_SLT(45), /** * Bit-vector signed modulo. * - * SMT-LIB: `bvsmod` + * SMT_LIB: `bvsmod` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SMOD(35), + BITWUZLA_KIND_BV_SMOD(46), /** * Bit-vector signed multiplication overflow test. * - * SMT-LIB: `bvsmod` + * Predicate indicating if signed multiplication produces an overflow. + * + * SMT_LIB: `bvsmulo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SMUL_OVERFLOW(36), + BITWUZLA_KIND_BV_SMUL_OVERFLOW(47), /** * Bit-vector signed remainder. * - * SMT-LIB: `bvsrem` + * SMT_LIB: `bvsrem` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SREM(37), + BITWUZLA_KIND_BV_SREM(48), /** * Bit-vector signed subtraction overflow test. * - * Single bit to indicate if signed subtraction produces an overflow. + * Predicate indicating if signed subtraction produces an overflow. + * + * SMT_LIB: `bvssubo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SSUB_OVERFLOW(38), + BITWUZLA_KIND_BV_SSUB_OVERFLOW(49), /** * Bit-vector subtraction. * - * SMT-LIB: `bvsub` + * SMT_LIB: `bvsub` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_SUB(39), + BITWUZLA_KIND_BV_SUB(50), /** * Bit-vector unsigned addition overflow test. * - * Single bit to indicate if unsigned addition produces an overflow. + * Predicate indicating if unsigned addition produces an overflow. + * + * SMT_LIB: `bvuaddo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_UADD_OVERFLOW(40), + BITWUZLA_KIND_BV_UADD_OVERFLOW(51), /** * Bit-vector unsigned division. * - * SMT-LIB: `bvudiv` + * SMT_LIB: `bvudiv` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_UDIV(41), + BITWUZLA_KIND_BV_UDIV(52), /** * Bit-vector unsigned greater than or equal. * - * SMT-LIB: `bvuge` + * SMT_LIB: `bvuge` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_UGE(42), + BITWUZLA_KIND_BV_UGE(53), /** * Bit-vector unsigned greater than. * - * SMT-LIB: `bvugt` + * SMT_LIB: `bvugt` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_UGT(43), + BITWUZLA_KIND_BV_UGT(54), /** * Bit-vector unsigned less than or equal. * - * SMT-LIB: `bvule` + * SMT_LIB: `bvule` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_ULE(44), + BITWUZLA_KIND_BV_ULE(55), /** * Bit-vector unsigned less than. * - * SMT-LIB: `bvult` + * SMT_LIB: `bvult` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_ULT(45), + BITWUZLA_KIND_BV_ULT(56), /** * Bit-vector unsigned multiplication overflow test. * - * Single bit to indicate if unsigned multiplication produces an overflow. + * Predicate indicating if unsigned multiplication produces an overflow. + * + * SMT_LIB: `bvumulo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_UMUL_OVERFLOW(46), + BITWUZLA_KIND_BV_UMUL_OVERFLOW(57), /** * Bit-vector unsigned remainder. * - * SMT-LIB: `bvurem` + * SMT_LIB: `bvurem` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_UREM(47), + BITWUZLA_KIND_BV_UREM(58), /** * Bit-vector unsigned subtraction overflow test. * - * Single bit to indicate if unsigned subtraction produces an overflow. + * Predicate indicating if unsigned subtraction produces an overflow. + * + * SMT_LIB: `bvusubo` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_USUB_OVERFLOW(48), + BITWUZLA_KIND_BV_USUB_OVERFLOW(59), /** * Bit-vector xnor. * - * SMT-LIB: `bvxnor` + * SMT_LIB: `bvxnor` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_XNOR(49), + BITWUZLA_KIND_BV_XNOR(60), /** * Bit-vector xor. * - * SMT-LIB: `bvxor` + * SMT_LIB: `bvxor` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_BV_XOR(50), + BITWUZLA_KIND_BV_XOR(61), /** - * Disequality. + * Bit-vector extract. * - * SMT-LIB: `distinct` + * SMT_LIB: `extract` (indexed) + * + * Number of Arguments: 1 + * + * Number of Indices: 2 (`u`, `l` with `u >= l`) */ - BITWUZLA_KIND_DISTINCT(51), + BITWUZLA_KIND_BV_EXTRACT(62), /** - * Equality. + * Bit-vector repeat. * - * SMT-LIB: `=` + * SMT_LIB: `repeat` (indexed) + * + * Number of Arguments: 1 + * + * Number of Indices: 1 (i s.t. `i * n` fits into [Long]) */ - BITWUZLA_KIND_EQUAL(52), + BITWUZLA_KIND_BV_REPEAT(63), /** - * Existential quantification. + * Bit-vector rotate left by integer. + * + * SMT_LIB: `rotate_left` (indexed) + * + * Number of Arguments: 1 * - * SMT-LIB: `exists` + * Number of Indices: 1 */ - BITWUZLA_KIND_EXISTS(53), + BITWUZLA_KIND_BV_ROLI(64), /** - * Universal quantification. + * Bit-vector rotate right by integer. + * + * SMT_LIB: `rotate_right` (indexed) + * + * Number of Arguments: 1 * - * SMT-LIB: `forall` + * Number of Indices: 1 */ - BITWUZLA_KIND_FORALL(54), + BITWUZLA_KIND_BV_RORI(65), + /** + * Bit-vector sign extend. + * + * SMT_LIB: `sign_extend` (indexed) + * + * Number of Arguments: 1 + * + * Number of Indices: 1 (`i` s.t. `i + n` fits into [Long]) + */ + BITWUZLA_KIND_BV_SIGN_EXTEND(66), + + /** + * Bit-vector zero extend. + * + * SMT_LIB: `zero_extend` (indexed) + * + * Number of Arguments: 1 + * + * Number of Indices: 1 (`i` s.t. `i + n` fits into [Long]) + */ + BITWUZLA_KIND_BV_ZERO_EXTEND(67), + + //// Floating-point arithmetic /** * Floating-point absolute value. * - * SMT-LIB: `fp.abs` + * SMT_LIB: `fp.abs` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_ABS(55), + BITWUZLA_KIND_FP_ABS(68), /** * Floating-point addition. * - * SMT-LIB: `fp.add` + * SMT_LIB: `fp.add` + * + * Number of Arguments: 3 */ - BITWUZLA_KIND_FP_ADD(56), + BITWUZLA_KIND_FP_ADD(69), /** * Floating-point division. * - * SMT-LIB: `fp.div` + * SMT_LIB: `fp.div` + * + * Number of Arguments: 3 */ - BITWUZLA_KIND_FP_DIV(57), + BITWUZLA_KIND_FP_DIV(70), /** * Floating-point equality. * - * SMT-LIB: `fp.eq` + * SMT_LIB: `fp.eq` + * + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_FP_EQ(58), + BITWUZLA_KIND_FP_EQUAL(71), /** * Floating-point fused multiplcation and addition. * - * SMT-LIB: `fp.fma` + * SMT_LIB: `fp.fma` + * + * Number of Arguments: 4 */ - BITWUZLA_KIND_FP_FMA(59), + BITWUZLA_KIND_FP_FMA(72), /** * Floating-point IEEE 754 value. * - * SMT-LIB: `fp` + * SMT_LIB: `fp` + * + * Number of Arguments: 3 */ - BITWUZLA_KIND_FP_FP(60), + BITWUZLA_KIND_FP_FP(73), /** * Floating-point greater than or equal. * - * SMT-LIB: `fp.geq` + * SMT_LIB: `fp.geq` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_FP_GEQ(61), + BITWUZLA_KIND_FP_GEQ(74), /** * Floating-point greater than. * - * SMT-LIB: `fp.gt` + * SMT_LIB: `fp.gt` + * + * Number of Arguments: 2 */ - BITWUZLA_KIND_FP_GT(62), + BITWUZLA_KIND_FP_GT(75), /** * Floating-point is infinity tester. * - * SMT-LIB: `fp.isInfinite` + * SMT_LIB: `fp.isInfinite` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_INF(63), + BITWUZLA_KIND_FP_IS_INF(76), /** * Floating-point is Nan tester. * - * SMT-LIB: `fp.isNaN` + * SMT_LIB: `fp.isNaN` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_NAN(64), + BITWUZLA_KIND_FP_IS_NAN(77), /** * Floating-point is negative tester. * - * SMT-LIB: `fp.isNegative` + * SMT_LIB: `fp.isNegative` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_NEG(65), + BITWUZLA_KIND_FP_IS_NEG(78), /** * Floating-point is normal tester. * - * SMT-LIB: `fp.isNormal` + * SMT_LIB: `fp.isNormal` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_NORMAL(66), + BITWUZLA_KIND_FP_IS_NORMAL(79), /** * Floating-point is positive tester. * - * SMT-LIB: `fp.isPositive` + * SMT_LIB: `fp.isPositive` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_POS(67), + BITWUZLA_KIND_FP_IS_POS(80), /** * Floating-point is subnormal tester. * - * SMT-LIB: `fp.isSubnormal` + * SMT_LIB: `fp.isSubnormal` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_SUBNORMAL(68), + BITWUZLA_KIND_FP_IS_SUBNORMAL(81), /** * Floating-point is zero tester. * - * SMT-LIB: `fp.isZero` + * SMT_LIB: `fp.isZero` + * + * Number of Arguments: 1 */ - BITWUZLA_KIND_FP_IS_ZERO(69), + BITWUZLA_KIND_FP_IS_ZERO(82), /** * Floating-point less than or equal. * - * SMT-LIB: `fp.leq` - */ - BITWUZLA_KIND_FP_LEQ(70), - - /** - * Floating-point less than. + * SMT_LIB: `fp.leq` * - * SMT-LIB: `fp.lt` + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_FP_LT(71), + BITWUZLA_KIND_FP_LEQ(83), /** - * Floating-point max. + * Floating-point less than. * - * SMT-LIB: `fp.max` - */ - BITWUZLA_KIND_FP_MAX(72), - - /** - * Floating-point min. + * SMT_LIB: `fp.lt` * - * SMT-LIB: `fp.min` + * Number of Arguments: >= 2 */ - BITWUZLA_KIND_FP_MIN(73), + BITWUZLA_KIND_FP_LT(84), /** - * Floating-point multiplcation. + * Floating-point max. * - * SMT-LIB: `fp.mul` - */ - BITWUZLA_KIND_FP_MUL(74), - - /** - * Floating-point negation. + * SMT_LIB: `fp.max` * - * SMT-LIB: `fp.neg` + * Number of Arguments: 2 */ - BITWUZLA_KIND_FP_NEG(75), + BITWUZLA_KIND_FP_MAX(85), /** - * Floating-point remainder. + * Floating-point min. * - * SMT-LIB: `fp.rem` - */ - BITWUZLA_KIND_FP_REM(76), - - /** - * Floating-point round to integral. + * SMT_LIB: `fp.min` * - * SMT-LIB: `fp.roundToIntegral` + * Number of Arguments: 2 */ - BITWUZLA_KIND_FP_RTI(77), + BITWUZLA_KIND_FP_MIN(86), /** - * Floating-point round to square root. + * Floating-point multiplcation. * - * SMT-LIB: `fp.sqrt` - */ - BITWUZLA_KIND_FP_SQRT(78), - - /** - * Floating-point round to subtraction. + * SMT_LIB: `fp.mul` * - * SMT-LIB: `fp.sqrt` + * Number of Arguments: 3 */ - BITWUZLA_KIND_FP_SUB(79), + BITWUZLA_KIND_FP_MUL(87), /** - * Boolean if and only if. + * Floating-point negation. * - * SMT-LIB: `=` - */ - BITWUZLA_KIND_IFF(80), - - /** - * Boolean implies. + * SMT_LIB: `fp.neg` * - * SMT-LIB: `=>` + * Number of Arguments: 1 */ - BITWUZLA_KIND_IMPLIES(81), + BITWUZLA_KIND_FP_NEG(88), /** - * If-then-else. + * Floating-point remainder. * - * SMT-LIB: `ite` - */ - BITWUZLA_KIND_ITE(82), - - /** Lambda. */ - BITWUZLA_KIND_LAMBDA(83), - - /** - * Boolean not. + * SMT_LIB: `fp.rem` * - * SMT-LIB: `not` + * Number of Arguments: 2 */ - BITWUZLA_KIND_NOT(84), + BITWUZLA_KIND_FP_REM(89), /** - * Boolean or. + * Floating-point round to integral. * - * SMT-LIB: `or` - */ - BITWUZLA_KIND_OR(85), - - /** - * Boolean xor. + * SMT_LIB: `fp.roundToIntegral` * - * SMT-LIB: `xor` + * Number of Arguments: 2 */ - BITWUZLA_KIND_XOR(86), + BITWUZLA_KIND_FP_RTI(90), /** - * Bit-vector extract. + * Floating-point square root. * - * SMT-LIB: `extract` (indexed) - */ - BITWUZLA_KIND_BV_EXTRACT(87), - - /** - * Bit-vector repeat. + * SMT_LIB: `fp.sqrt` * - * SMT-LIB: `repeat` (indexed) + * Number of Arguments: 2 */ - BITWUZLA_KIND_BV_REPEAT(88), + BITWUZLA_KIND_FP_SQRT(91), /** - * Bit-vector rotate left by integer. + * Floating-point subtraction. * - * SMT-LIB: `rotate_left` (indexed) - */ - BITWUZLA_KIND_BV_ROLI(89), - - /** - * Bit-vector rotate right by integer. + * SMT_LIB: `fp.sub` * - * SMT-LIB: `rotate_right` (indexed) + * Number of Arguments: 3 */ - BITWUZLA_KIND_BV_RORI(90), + BITWUZLA_KIND_FP_SUB(92), /** - * Bit-vector sign extend. + * Floating-point to_fp from IEEE 754 bit-vector. * - * SMT-LIB: `sign_extend` (indexed) - */ - BITWUZLA_KIND_BV_SIGN_EXTEND(91), - - /** - * Bit-vector zero extend. + * SMT_LIB: `to_fp` (indexed) * - * SMT-LIB: `zero_extend` (indexed) - */ - BITWUZLA_KIND_BV_ZERO_EXTEND(92), - - /** - * Floating-point to_fp from IEEE 754 bit-vector. + * Number of Arguments: 1 * - * SMT-LIB: `to_fp` (indexed) + * Number of Indices: 2 (`e`, `s`) */ BITWUZLA_KIND_FP_TO_FP_FROM_BV(93), /** * Floating-point to_fp from floating-point. * - * SMT-LIB: `to_fp` (indexed) + * SMT_LIB: `to_fp` (indexed) + * + * Number of Arguments: 2 + * + * Number of Indices: 2 (`e`, `s`) */ BITWUZLA_KIND_FP_TO_FP_FROM_FP(94), /** * Floating-point to_fp from signed bit-vector value. * - * SMT-LIB: `to_fp` (indexed) + * SMT_LIB: `to_fp` (indexed) + * + * Number of Arguments: 2 + * + * Number of Indices: 2 (`e`, `s`) */ BITWUZLA_KIND_FP_TO_FP_FROM_SBV(95), /** * Floating-point to_fp from unsigned bit-vector value. * - * SMT-LIB: `to_fp_unsigned` (indexed) + * SMT_LIB: `to_fp_unsigned` (indexed) + * + * Number of Arguments: 2 + * + * Number of Indices: 2 (`e`, `s`) */ BITWUZLA_KIND_FP_TO_FP_FROM_UBV(96), /** * Floating-point to_sbv. * - * SMT-LIB: `fp.to_sbv` (indexed) + * SMT_LIB: `fp.to_sbv` (indexed) + * + * Number of Arguments: 2 + * + * Number of Indices: 1 (`n`) */ BITWUZLA_KIND_FP_TO_SBV(97), /** * Floating-point to_ubv. * - * SMT-LIB: `fp.to_ubv` (indexed) + * SMT_LIB: `fp.to_ubv` (indexed) + * + * Number of Arguments: 2 + * + * Number of Indices: 1 (`n`) */ BITWUZLA_KIND_FP_TO_UBV(98), - BITWUZLA_NUM_KINDS(99); + BITWUZLA_KIND_NUM_KINDS(99); companion object { private val valueMapping = BitwuzlaKind.values().associateBy { it.value } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaOption.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaOption.kt index 4b6ef2db4..f8e4d360b 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaOption.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/BitwuzlaOption.kt @@ -6,961 +6,139 @@ package org.ksmt.solver.bitwuzla.bindings * The configuration options supported by Bitwuzla. * * Options that list string values can be configured via - * [Native.bitwuzlaSetOptionStr]. Options with integer configuration values are + * [Native.bitwuzlaSetOptionMode]. Options with integer configuration values are * configured via [Native.bitwuzlaSetOption]. * - * For all options, the current configuration value can be queried via - * [Native.bitwuzlaGetOption]. - * Options with string configuration values internally represent these - * values as enum values. + * For all options, the current configuration value can be queried via [Native.bitwuzlaGetOption]. + * Options with string configuration values internally represent these values as enum values. * For these options, [Native.bitwuzlaGetOption] will return such an enum value. - * Use [Native.bitwuzlaGetOptionStr] to query enum options for the corresponding + * Use [Native.bitwuzlaGetOptionMode] to query enum options for the corresponding * string representation. */ enum class BitwuzlaOption(val value: Int) { /* --------------------------- General Options --------------------------- */ - /** - * **Configure the solver engine.** - * - * Values: - * * **aigprop**: - * The propagation-based local search QF_BV engine that operates on the - * bit-blasted formula (the AIG circuit layer). - * * **fun** **(default)**: - * The default engine for all combinations of QF_AUFBVFP, uses lemmas on - * demand for QF_AUFBVFP, and eager bit-blasting (optionally with local - * searchin a sequential portfolio) for QF_BV. - * * **prop**: - * The propagation-based local search QF_BV engine. - * * **sls**: - * The stochastic local search QF_BV engine. - * * **quant**: - * The quantifier engine. - */ - BITWUZLA_OPT_ENGINE(0), - - /** - * **Use non-zero exit codes for sat and unsat results.** - * - * When enabled, use Bitwuzla exit codes: - * * [BitwuzlaResult.BITWUZLA_SAT] - * * [BitwuzlaResult.BITWUZLA_UNSAT] - * * [BitwuzlaResult.BITWUZLA_UNKNOWN] - * - * When disabled, return 0 on success (sat, unsat, unknown), and a non-zero - * exit code otherwise. - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - */ - BITWUZLA_OPT_EXIT_CODES(1), - - /** - * **Configure input file format.** - * - * If unspecified, Bitwuzla will autodetect the input file format. - * - * Values: - * * **none** **(default)**: Auto-detect input file format. - * * **btor**: BTOR format - * * **btor2**: BTOR2 format - * * **smt2**: SMT-LIB v2 format - */ - BITWUZLA_OPT_INPUT_FORMAT(2), - - /** - * **Incremental solving.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * Note: - * * Enabling this option turns off some optimization techniques. - * * Enabling/disabling incremental solving after bitwuzla_check_sat() - * has been called is not supported. - * * This option cannot be enabled in combination with option [BITWUZLA_OPT_PP_UNCONSTRAINED_OPTIMIZATION]. - */ - BITWUZLA_OPT_INCREMENTAL(3), - - /** - * **Log level.** - * - * Values: - * * An unsigned integer value (**default**: 0). - */ - BITWUZLA_OPT_LOGLEVEL(4), - - /** - * **Configure output number format for bit-vector values.** - * - * If unspecified, Bitwuzla will use BTOR format. - * - * Values: - * * **aiger**: AIGER ascii format - * * **aigerbin**: AIGER binary format - * * **btor** **(default)**: BTOR format - * * **smt2**: SMT-LIB v2 format - */ - BITWUZLA_OPT_OUTPUT_FORMAT(5), - - /** - * **Configure output number format for bit-vector values.** - * - * If unspecified, Bitwuzla will use binary representation. - * - * Values: - * * **bin** **(default)**: - * Binary number format. - * * **hex**: - * Hexadecimal number format. - * * **dec**: - * Decimal number format. - */ - BITWUZLA_OPT_OUTPUT_NUMBER_FORMAT(6), - - /** - * **Pretty printing.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - */ - BITWUZLA_OPT_PRETTY_PRINT(7), - - /** - * **Print DIMACS.** - * - * Print the CNF sent to the SAT solver in DIMACS format to stdout. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - */ - BITWUZLA_OPT_PRINT_DIMACS(8), - - /** - * **Model generation.** - * - * Values: - * * **1**: enable, generate model for assertions only - * * **2**: enable, generate model for all created terms - * * **0**: disable **(default)** - * - * **Note**: This option cannot be enabled in combination with option [BITWUZLA_OPT_PP_UNCONSTRAINED_OPTIMIZATION]. - */ - BITWUZLA_OPT_PRODUCE_MODELS(9), - - /** - * **Unsat core generation.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - */ - BITWUZLA_OPT_PRODUCE_UNSAT_CORES(10), - - /** - * **Configure the SAT solver engine.** - * - * Values: - * * **cadical** **(default)**: - * [CaDiCaL](https://github.com/arminbiere/cadical) - * * **cms**: - * [CryptoMiniSat](https://github.com/msoos/cryptominisat) - * * **gimsatul**: - * [Gimsatul](https://github.com/arminbiere/gimsatul) - * * **kissat**: - * [Kissat](https://github.com/arminbiere/kissat) - * * **lingeling**: - * [Lingeling](https://github.com/arminbiere/lingeling) - * * **minisat**: - * [MiniSat](https://github.com/niklasso/minisat) - * * **picosat**: - * [PicoSAT](http://fmv.jku.at/picosat/) - */ - BITWUZLA_OPT_SAT_ENGINE(11), - - /** - * **Seed for random number generator.** - * - * Values: - * * An unsigned integer value (**default**: 0). - */ - BITWUZLA_OPT_SEED(12), - - /** - * **Verbosity level.** - * - * Values: - * * An unsigned integer value <= 4 (**default**: 0). - */ - BITWUZLA_OPT_VERBOSITY(13), - - /* -------------- Rewriting/Preprocessing Options (Expert) --------------- */ - - /** - * **Ackermannization preprocessing.** - * - * Eager addition of Ackermann constraints for function applications. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_ACKERMANN(14), - - /** - * **Beta reduction preprocessing.** - * - * Eager elimination of lambda terms via beta reduction. - * - * Values: - * * **none** **(default)**: - * Disable beta reduction preprocessing. - * * **fun**: - * Only beta reduce functions that do not represent array stores. - * * **all**: - * Only beta reduce all functions, including array stores. - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_BETA_REDUCE(15), - - /** - * **Eliminate bit-vector extracts (preprocessing).** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_ELIMINATE_EXTRACTS(16), - - /** - * **Eliminate ITEs (preprocessing).** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_ELIMINATE_ITES(17), - - /** - * **Extract lambdas (preprocessing).** - * - * Extraction of common array patterns as lambda terms. - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_EXTRACT_LAMBDAS(18), - - /** - * **Merge lambda terms (preprocessing).** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_MERGE_LAMBDAS(19), - - /** - * **Non-destructive term substitutions.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_NONDESTR_SUBST(20), - - /** - * **Normalize bit-vector addition (global).** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_NORMALIZE_ADD(21), - - /** - * **Boolean skeleton preprocessing.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_SKELETON_PREPROC(22), - - /** - * **Unconstrained optimization (preprocessing).** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_UNCONSTRAINED_OPTIMIZATION(23), - - /** - * **Variable substitution preprocessing.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure preprocessing. - */ - BITWUZLA_OPT_PP_VAR_SUBST(24), - - /** - * **Propagate bit-vector extracts over arithmetic bit-vector operators.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_EXTRACT_ARITH(25), - - /** - * **Rewrite level.** - * - * Values: - * * **0**: no rewriting - * * **1**: term level rewriting - * * **2**: term level rewriting and basic preprocessing - * * **3**: term level rewriting and full preprocessing **(default)** - * - * **Note**: Configuring the rewrite level after terms have been created - * is not allowed. - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_LEVEL(26), - - /** - * **Normalize bit-vector operations.** - * - * Normalize bit-vector addition, multiplication and bit-wise and. - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_NORMALIZE(27), - - /** - * **Normalize bit-vector addition (local).** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_NORMALIZE_ADD(28), - - /** - * **Simplify constraints on construction.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_SIMPLIFY_CONSTRAINTS(29), - - /** - * **Eliminate bit-vector SLT nodes.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_SLT(30), - - /** - * **Sort the children of AIG nodes by id.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_SORT_AIG(31), - - /** - * **Sort the children of adder and multiplier circuits by id.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_SORT_AIGVEC(32), - - /** - * **Sort the children of commutative operations by id.** - * - * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure rewriting. - */ - BITWUZLA_OPT_RW_SORT_EXP(33), - -/* --------------------- Fun Engine Options (Expert) --------------------- */ - - /** - * **Function solver engine: - * Dual propagation optimization.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the fun solver engine. - */ - BITWUZLA_OPT_FUN_DUAL_PROP(34), - - /** - * **Function solver engine: - * Assumption order for dual propagation optimization.** - * - * Set order in which inputs are assumed in the dual propagation clone. - * - * Values: - * * **just** **(default)**: - * Order by score, highest score first. - * * **asc**: - * Order by input id, ascending. - * * **desc**: - * Order by input id, descending. - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_DUAL_PROP_QSORT(35), - - /** - * **Function solver engine: - * Eager lemmas.** - * - * Configure mode for eager lemma generation. - * - * Values: - * * **none**: - * Do not generate lemmas eagerly (generate one single lemma per - * refinement iteration). - * * **conf** **(default)**: - * Only generate lemmas eagerly until the first conflict dependent on - * another conflict is found. - * * **all**: - * In each refinement iteration, generate lemmas for all conflicts. - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_EAGER_LEMMAS(36), - - /** - * **Function solver engine: - * Lazy synthesis.** - * - * Configure lazy synthesis (to bit-level) of bit-vector expressions. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_LAZY_SYNTHESIZE(37), - - /** - * **Function solver engine: - * Justification optimization.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_JUST(38), - - /** - * **Function solver engine: - * Justification optimization heuristic.** - * - * Configure heuristic to determine path selection for justification - * optimization. - * - * Values: - * * **applies** **(default)**: - * Choose branch with minimum number of applies. - * * **depth**: - * Choose branch with minimum depth. - * * **left**: - * Always choose left branch. - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_JUST_HEURISTIC(39), - - /** - * **Function solver engine: - * Propagation-based local search sequential portfolio.** - * - * When function solver engine is enabled, configure propagation-based local - * search solver engine as preprocessing step within sequential portfolio - * setting. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_PREPROP(40), - - /** - * **Function solver engine: - * Stochastic local search sequential portfolio.** - * - * When function solver engine is enabled, configure stochastic local - * search solver engine as preprocessing step within sequential portfolio - * setting. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_PRESLS(41), - - /** - * **Function solver engine: - * Represent store as lambda.** - * - * Represent array stores as lambdas. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the func solver engine. - */ - BITWUZLA_OPT_FUN_STORE_LAMBDAS(42), - -/* --------------------- SLS Engine Options (Expert) --------------------- */ - - /** - * **Stochastic local search solver engine: - * Justification-based path selection.** - * - * Configure justification-based path selection for SLS engine. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_JUST(43), - - /** - * **Stochastic local search solver engine: - * Group-wise moves.** - * - * Configure group-wise moves for SLS engine. When enabled, rather than - * changing the assignment of one single candidate variable, all candidates - * are set at the same time (using the same strategy). - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_MOVE_GW(44), - - /** - * **Stochastic local search solver engine: - * Incremental move test.** - * - * Configure that during best move selection, the previous best neighbor - * for the current candidate is used for neighborhood exploration rather - * than its current assignment. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_MOVE_INC_MOVE_TEST(45), - - /** - * **Stochastic local search solver engine: - * Propagation moves.** - * - * Configure propagation moves, chosen with a ratio of number of propagation - * moves [BITWUZLA_OPT_SLS_MOVE_PROP_NPROPS] to regular SLS moves - * [BITWUZLA_OPT_SLS_MOVE_PROP_NSLSS]. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_MOVE_PROP(46), - - /** - * **Stochastic local search solver engine: - * Force random walks.** - * - * Configure that random walks are forcibly chosen as recovery moves in case - * of conflicts when a propagation move is performed (rather than performing - * a regular SLS move). - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_MOVE_PROP_FORCE_RW(47), - - /** - * **Stochastic local search solver engine: - * Number of propagation moves.** - * - * Configure the number of propagation moves to be performed when propagation - * moves are enabled. Propagation moves are chosen with a ratio of - * [BITWUZLA_OPT_SLS_MOVE_PROP_NPROPS] to - * [BITWUZLA_OPT_SLS_MOVE_PROP_NSLSS]. + /** + * **Log level.** * * Values: - * * An unsigned integer value (**default**: 1) - * - * @see BITWUZLA_OPT_SLS_MOVE_PROP - * @see BITWUZLA_OPT_SLS_MOVE_PROP_NSLSS - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * An unsigned integer value. (**default**: 0) */ - BITWUZLA_OPT_SLS_MOVE_PROP_NPROPS(48), + BITWUZLA_OPTION_LOGLEVEL(0), - /** - * **Stochastic local search solver engine: - * Number of regular SLS moves.** - * - * Configure the number of regular SLS moves to be performed when propagation - * moves are enabled. Propagation moves are chosen with a ratio of - * [BITWUZLA_OPT_SLS_MOVE_PROP_NPROPS] to - * [BITWUZLA_OPT_SLS_MOVE_PROP_NSLSS]. + /** + * **Model generation.** * * Values: - * * An unsigned integer value (**default**: 1) - * - * @see BITWUZLA_OPT_SLS_MOVE_PROP - * @see BITWUZLA_OPT_SLS_MOVE_PROP_NPROPS - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * **1**: enable, generate model for assertions only + * * **2**: enable, generate model for all created terms + * * **0**: disable (**default**) */ - BITWUZLA_OPT_SLS_MOVE_PROP_NSLSS(49), + BITWUZLA_OPTION_PRODUCE_MODELS(1), - /** - * **Stochastic local search solver engine: - * Randomize all candidates.** - * - * Configure the randomization of all candidate variables (rather than just - * a single randomly selected one) in case no best move has been found. + /** + * **Unsat assumptions generation.** * * Values: * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * **0**: disable (**default**) */ - BITWUZLA_OPT_SLS_MOVE_RAND_ALL(50), + BITWUZLA_OPTION_PRODUCE_UNSAT_ASSUMPTIONS(2), - /** - * **Stochastic local search solver engine: - * Randomize bit ranges.** - * - * Configure the randomization of bit ranges (rather than all bits) of - * candidate variable(s) in case no best move has been found. + /** + * **Unsat core generation.** * * Values: * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * **0**: disable (**default**) */ - BITWUZLA_OPT_SLS_MOVE_RAND_RANGE(51), + BITWUZLA_OPTION_PRODUCE_UNSAT_CORES(3), - /** - * **Stochastic local search solver engine: - * Random walk.** - * - * Configure random walk moves, where one out of all possible neighbors is - * randomly selected (with given probability - * [BITWUZLA_OPT_SLS_PROB_MOVE_RAND_WALK]) for a randomly selected - * candidate variable. + /** + * **Seed for random number generator.** * * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * @see BITWUZLA_OPT_SLS_PROB_MOVE_RAND_WALK - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * An unsigned integer value. (**default**: 0) */ - BITWUZLA_OPT_SLS_MOVE_RAND_WALK(52), + BITWUZLA_OPTION_SEED(4), - /** - * **Stochastic local search solver engine: - * Range-wise bit-flip moves.** - * - * Configure range-wise bit-flip moves for SLS engine. When enabled, try - * range-wise bit-flips when selecting moves, where bits within all ranges - * from 2 to the bit-width (starting from the LSB) are flipped at once. + /** + * **Verbosity level.** * * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * An unsigned integer value <= 4. (**default**: 0) */ - BITWUZLA_OPT_SLS_MOVE_RANGE(53), + BITWUZLA_OPTION_VERBOSITY(5), - /** - * **Stochastic local search solver engine: - * Segment-wise bit-flip moves.** - * - * Configure range-wise bit-flip moves for SLS engine. When enabled, try - * segment-wise bit-flips when selecting moves, where bits within segments - * of multiples of 2 are flipped at once. + /** + * **Time limit in milliseconds per satisfiability check.** * * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * An unsigned integer for the time limit in milliseconds. (**default**: 0) */ - BITWUZLA_OPT_SLS_MOVE_SEGMENT(54), + BITWUZLA_OPTION_TIME_LIMIT_PER(6), - /** - * **Stochastic local search solver engine: - * Probability for random walks.** - * - * Configure the probability with which a random walk is chosen if random - * walks are enabled. - * - * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 100) - * - * @see BITWUZLA_OPT_SLS_MOVE_RAND_WALK - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_PROB_MOVE_RAND_WALK(55), + /* ---------------- Bitwuzla-specific Options ----------------------------- */ - /** - * **Stochastic local search solver engine: - * Number of bit flips.** - * - * Configure the number of bit flips used as a limit for the SLS engine. + /** + * **Configure the bit-vector solver engine.** * * Values: - * * An unsigned integer value, no limit if 0 (**default**: 0). - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * **bitblast**: The classical bit-blasting approach. (**default**) + * * **prop**: Propagation-based local search (sat only). + * * **preprop**: Sequential portfolio combination of bit-blasting and propagation-based local search. */ - BITWUZLA_OPT_SLS_NFLIPS(56), + BITWUZLA_OPTION_BV_SOLVER(7), - /** - * **Stochastic local search solver engine: - * Move strategy.** - * - * Configure the move selection strategy for the SLS engine. + /** + * **Rewrite level.** * * Values: - * * **best** **(default)**: - * Choose best score improving move. - * * **walk**: - * Choose random walk weighted by score. - * * **first**: - * Choose first best move (no matter if any other move is better). - * * **same**: - * Determine move as best move even if its score is not better but the - * same as the score of the previous best move. - * * **prop**: - * Choose propagation move (and recover with SLS move in case of conflict). - * - * **Warning**: This is an expert option to configure the sls solver engine. - */ - BITWUZLA_OPT_SLS_STRATEGY(57), - - /** - * **Stochastic local search solver engine: - * Restarts.** + * * **0**: no rewriting + * * **1**: term level rewriting + * * **2**: term level rewriting and basic preprocessing + * * **3**: term level rewriting and full preprocessing (**default**) * - * Values: - * * **1**: enable **(default)** - * * **0**: disable + * **note:** Configuring the rewrite level after terms have been created + * is not allowed. * - * **Warning**: This is an expert option to configure the sls solver engine. + * **warning:** This is an expert option to configure rewriting. */ - BITWUZLA_OPT_SLS_USE_RESTARTS(58), + BITWUZLA_OPTION_REWRITE_LEVEL(8), - /** - * **Stochastic local search solver engine: - * Bandit scheme.** - * - * Configure bandit scheme heuristic for selecting root constraints. - * If disabled, root constraints are selected randomly. + /** + * **Configure the SAT solver engine.** * * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure the sls solver engine. + * * **cadical**: + * [CaDiCaL](https://github.com/arminbiere/cadical) (**default**) + * * **cms**: + * [CryptoMiniSat](https://github.com/msoos/cryptominisat) + * * **kissat**: + * [Kissat](https://github.com/arminbiere/kissat) + * * **lingeling**: + * [Lingeling](https://github.com/arminbiere/lingeling) */ - BITWUZLA_OPT_SLS_USE_BANDIT(59), + BITWUZLA_OPTION_SAT_SOLVER(9), - /* -------------------- Prop Engine Options (Expert) --------------------- */ - - /** - * **Propagation-based local search solver engine: - * Value computation for xor.** - * - * When enabled, detect arithmetic right shift operations (are rewritten on - * construction) and use value computation for ashr. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_ASHR(60), + /* ---------------- BV: Prop Engine Options (Expert) ---------------------- */ - /** + /** * **Propagation-based local search solver engine: * Constant bits.** * * Configure constant bit propagation (requries bit-blasting to AIG). * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_CONST_BITS(61), + BITWUZLA_OPTION_PROP_CONST_BITS(10), - /** - * **Propagation-based local search solver engine: - * Domain propagators.** - * - * Configure the use of domain propagators for determining constant bits - * (instead of bit-blastin to AIG). - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_CONST_DOMAINS(62), - - /** - * **Propagation-based local search solver engine: - * Entailed propagations.** - * - * Maintain a work queue with entailed propagations. - * If enabled, propagations from this queue are propagated before randomly - * choosing a yet unsatisfied path from the root. - * - * Values: - * - * * **off** **(default)**: - * Disable strategy. - * * **all**: - * Propagate all entailed propagations. - * * **first**: - * Process only the first entailed propagation. - * * **last**: - * Process only the last entailed propagation. - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_ENTAILED(63), - - /** - * **Propagation-based local search solver engine: - * Delta for flipping ite conditions with constant branches.** - * - * Configure the delta by which [BITWUZLA_OPT_PROP_PROB_FLIP_COND_CONST] is - * decreased or increased after a limit - * [BITWUZLA_OPT_PROP_FLIP_COND_CONST_NPATHSEL] is reached. - * - * Values: - * * A signed integer value (**default**: 100). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_FLIP_COND_CONST_DELTA(64), - - /** - * **Propagation-based local search solver engine: - * Limit for flipping ite conditions with constant branches.** - * - * Configure the limit for how often the path to the condition for ite - * operations with constant branches may be selected before - * [BITWUZLA_OPT_PROP_PROB_FLIP_COND_CONST] is decreased or increased by - * [BITWUZLA_OPT_PROP_FLIP_COND_CONST_DELTA]. - * - * Values: - * * A signed integer value (**default**: 500). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_FLIP_COND_CONST_NPATHSEL(65), - - /** + /** * **Propagation-based local search solver engine: * Infer bounds for inequalities for value computation.** * @@ -969,32 +147,13 @@ enum class BitwuzlaOption(val value: Int) { * * Values: * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_INFER_INEQ_BOUNDS(66), - - /** - * **Propagation-based local search solver engine: - * No move on conflict.** - * - * When enabled, no move is performed when running into a conflict during - * value computation. - * - * **Note**: This is the default behavior for the SLS engine when propagation - * moves are enabled, where a conflict triggers a recovery by means - * of a regular SLS move. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** + * * **0**: disable (**default**) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_NO_MOVE_ON_CONFLICT(67), + BITWUZLA_OPTION_PROP_INFER_INEQ_BOUNDS(11), - /** + /** * **Propagation-based local search solver engine: * Number of propagations.** * @@ -1002,13 +161,13 @@ enum class BitwuzlaOption(val value: Int) { * propagation-based local search solver engine. No limit if 0. * * Values: - * * An unsigned integer value (**default**: 0). + * * An unsigned integer value. (**default**: 0) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_NPROPS(68), + BITWUZLA_OPTION_PROP_NPROPS(12), - /** + /** * **Propagation-based local search solver engine: * Number of updates.** * @@ -1016,102 +175,43 @@ enum class BitwuzlaOption(val value: Int) { * propagation-based local search solver engine. No limit if 0. * * Values: - * * An unsigned integer value (**default**: 0). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_NUPDATES(69), - - /** - * **Propagation-based local search solver engine: - * Path selection.** - * - * Configure mode for path selection. - * - * Values: - * * **essential** **(default)**: - * Select path based on essential inputs. - * * **random**: - * Select path randomly. - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_PATH_SEL(70), - - /** - * **Propagation-based local search solver engine: - * Probability for producing inverse rather than consistent values.** - * - * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 0). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_PROB_FALLBACK_RANDOM_VALUE(71), - - /** - * **Propagation-based local search solver engine: - * Probability for flipping one of the don't care bits for ands.** - * - * Configure the probability with which to keep the current assignement of - * the operand to a bit-vector and with max one bit flipped (rather than - * fully randomizing the assignment) when selecting an inverse or consistent - * value. - * - * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 0). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_PROB_AND_FLIP(72), - - /** - * **Propagation-based local search solver engine: - * Probability for using the current assignment with one bit flipped for - * equalities.** - * - * Configure the probability with which the current assignment of an operand - * to a disequality is kept with just a single bit flipped (rather than fully - * randomizing the assignment) when selecting an inverse or consistent value. - * - * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 0). + * * An unsigned integer value. (**default**: 0) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_PROB_EQ_FLIP(73), + BITWUZLA_OPTION_PROP_NUPDATES(13), - /** + /** * **Propagation-based local search solver engine: - * Probability for flipping ite condition.** + * Optimization for inverse value computation of inequalities over concat and sign extension operands.** * - * Configure the probability with which to select the path to the condition - * (in case of an ite operation) rather than the enabled branch during down - * propagation). + * When enabled, use optimized inverse value computation over concats. * * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 100). + * * **1**: enable + * * **0**: disable (**default**) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_PROB_FLIP_COND(74), + BITWUZLA_OPTION_PROP_OPT_LT_CONCAT_SEXT(14), - /** + /** * **Propagation-based local search solver engine: - * Probability for flipping ite condition with constant branches.** + * Path selection.** * - * Configure the probability with which to select the path to the condition - * (in case of an ite operation) rather than the enabled branch during down - * propagation) if either the 'then' or 'else' branch is constant. + * Configure mode for path selection. * * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 100). + * * **essential**: + * Select path based on essential inputs. (**default**) + * * **random**: + * Select path randomly. * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_PROB_FLIP_COND_CONST(75), + BITWUZLA_OPTION_PROP_PATH_SEL(15), - /** + /** * **Propagation-based local search solver engine: * Probability for selecting random input.** * @@ -1119,45 +219,13 @@ enum class BitwuzlaOption(val value: Int) { * an essential input when selecting the path. * * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 0). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_PROB_RANDOM_INPUT(76), - - /** - * **Propagation-based local search solver engine: - * Probability for flipping one of the don't care bits for extracts.** - * - * Configure the probability with which to flip one of the don't care bits of - * the current assignment of the operand to a bit-vector extract (when the - * asignment is kept) when selecting an inverse or consistent value. - * - * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 0). - * - * @see BITWUZLA_OPT_PROP_PROB_SLICE_KEEP_DC - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_PROB_SLICE_FLIP(77), - - /** - * **Propagation-based local search solver engine: - * Probability for keeping the value of don't care bits for extracts.** - * - * Configure the probability with which to keep the current value of don't - * care bits of an extract operation (rather than fully randomizing them) - * when selecting an inverse or consistent value. - * - * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 500). + * * An unsigned integer value <= 1000 (= 100%). (**default**: 0) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_PROB_SLICE_KEEP_DC(78), + BITWUZLA_OPTION_PROP_PROB_RANDOM_INPUT(16), - /** + /** * **Propagation-based local search solver engine: * Probability for inverse values.** * @@ -1165,57 +233,13 @@ enum class BitwuzlaOption(val value: Int) { * consistent value when aninverse value exists. * * Values: - * * An unsigned integer value <= 1000 (= 100%) (**default**: 990). - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_PROB_USE_INV_VALUE(79), - - /** - * **Propagation-based local search solver engine: - * Bandit scheme.** - * - * Configure bandit scheme heuristic for selecting root constraints. - * If enabled, root constraint selection via bandit scheme is based on a - * scoring scheme similar to the one used in the SLS engine. - * If disabled, root constraints are selected randomly. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_USE_BANDIT(80), - - /** - * **Propagation-based local search solver engine: - * Inverse value computation for inequalities over concats.** - * - * When enabled, use special inverse value computation for inequality over - * concats. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_USE_INV_LT_CONCAT(81), - - /** - * **Propagation-based local search solver engine: - * Restarts.** - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** + * * An unsigned integer value <= 1000 (= 100%). (**default**: 990) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_USE_RESTARTS(82), + BITWUZLA_OPTION_PROP_PROB_USE_INV_VALUE(17), - /** + /** * **Propagation-based local search solver engine: * Value computation for sign extension.** * @@ -1224,363 +248,184 @@ enum class BitwuzlaOption(val value: Int) { * * Values: * * **1**: enable - * * **0**: disable **(default)** + * * **0**: disable (**default**) * - * **Warning**: This is an expert option to configure the prop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_PROP_SEXT(83), + BITWUZLA_OPTION_PROP_SEXT(18), - /** + /** * **Propagation-based local search solver engine: - * Skip if no progress.** - * - * When enabled, moves that make no progress, that is, that produce a target - * value that is the seame as the current assignment of a variable, are - * skipped. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_SKIP_NO_PROGRESS(84), - - /** - * **Propagation-based local search solver engine: - * Value computation for xor.** - * - * When enabled, detect xor operations (are rewritten on construction) and - * use value computation for xor. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option to configure the prop solver engine. - */ - BITWUZLA_OPT_PROP_XOR(85), - - /* ------------------- AigProp Engine Options (Expert) ------------------- */ - - /** - * **AIG-level propagation-based local search solver engine: - * Number of propagations.** - * - * Configure the number of propagations used as a limit for the - * propagation-based local search solver engine. No limit if 0. - * - * Values: - * * An unsigned integer value (**default**: 0). - * - * **Warning**: This is an expert option to configure the aigprop solver engine. - */ - BITWUZLA_OPT_AIGPROP_NPROPS(86), - - /** - * **AIG-level propagation-based local search solver engine: - * Bandit scheme.** - * - * Configure bandit scheme heuristic for selecting root constraints. - * If enabled, root constraint selection via bandit scheme is based on a - * scoring scheme similar to the one used in the SLS engine. - * If disabled, root constraints are selected randomly. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** + * Local search specific normalization.** * - * **Warning**: This is an expert option to configure the aigprop solver engine. - */ - BITWUZLA_OPT_AIGPROP_USE_BANDIT(87), - - /** - * **AIG-level propagation-based local search solver engine: - * Restarts.** + * When enabled, perform normalizations for local search, on the local search + * layer (does not affect node layer). * * Values: * * **1**: enable - * * **0**: disable **(default)** + * * **0**: disable (**default**) * - * **Warning**: This is an expert option to configure the aigprop solver engine. + * **warning:** This is an expert option to configure the prop solver engine. */ - BITWUZLA_OPT_AIGPROP_USE_RESTARTS(88), - - /* ----------------- Quantifier Eninge Options (Expert) ------------------ */ + BITWUZLA_OPTION_PROP_NORMALIZE(19), - /** - * **Quantifier solver engine: - * Constructive Equality Resolution.** + /** + * **Preprocessing** * - * Configure the use of Constructive Equality Resolution simplification in - * the quantifier solver engine. + * When enabled, applies all enabled preprocessing passes. * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. */ - BITWUZLA_OPT_QUANT_CER(89), + BITWUZLA_OPTION_PREPROCESS(20), - /** - * **Quantifier solver engine: - * Destructive Equality Resolution.** + /** + * **Preprocessing: Find contradicting bit-vector ands** * - * Configure the use of Destructive Equality Resolution simplification in - * the quantifier solver engine. + * When enabled, substitutes contradicting nodes of kind [BitwuzlaKind.BITWUZLA_KIND_BV_AND] with zero. * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. */ - BITWUZLA_OPT_QUANT_DER(90), + BITWUZLA_OPTION_PP_CONTRADICTING_ANDS(21), - /** - * **Quantifier solver engine: - * Dual solver.** + /** + * **Preprocessing: Eliminate bit-vector extracts on bit-vector constants** * - * Configure the use of the dual (negated) version of the quantified formula. + * When enabled, eliminates bit-vector extracts on constants. * * Values: - * * **1**: enable **(default)** - * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. + * * **1**: enable + * * **0**: disable (**default**) */ - BITWUZLA_OPT_QUANT_DUAL_SOLVER(91), + BITWUZLA_OPTION_PP_ELIM_BV_EXTRACTS(22), - /** - * **Quantifier solver engine: - * Miniscoping.** + /** + * **Preprocessing: Embedded constraint substitution** * - * Configure the use of miniscoping in the quantifier solver engine. + * When enabled, substitutes assertions that occur as sub-expression in the + * formula with their respective Boolean value. * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. - */ - BITWUZLA_OPT_QUANT_MINISCOPE(92), - - /** - * **Quantifier solver engine: - * Synthesis mode.** - * - * Configure mode for synthesizing Skolem functions. - * - * Values: - * * **none**: - * Do not synthesize skolem functions (use model values for instantiation). - * * **el**: - * Use enumerative learning to synthesize skolem functions. - * * **elmc**: - * Use enumerative learning modulo the predicates in the cone of influence - * of the existential variables to synthesize skolem functions. - * * **elelmc**: - * Chain `el` and `elmc` approaches to synthesize skolem functions. - * * **elmr** **(default)**: - * Use enumerative learning modulo the given root constraints to synthesize - * skolem functions. - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. */ - BITWUZLA_OPT_QUANT_SYNTH(93), + BITWUZLA_OPTION_PP_EMBEDDED_CONSTR(23), - /** - * **Quantifier solver engine: - * Update model with respect to synthesized skolem.** - * - * Configure to update the current model with respect to the synthesized - * skolem function if enabled. + /** + * **Preprocessing: AND flattening** * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. */ - BITWUZLA_OPT_QUANT_FIXSYNTH(94), + BITWUZLA_OPTION_PP_FLATTEN_AND(24), - /** - * **Quantifier solver engine: - * Base case for ITE model.** - * - * Configure the base case of a concrete model for ITEs. Constant if enabled, - * else undefined. + /** + * **Preprocessing: Normalization** * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. - */ - BITWUZLA_OPT_QUANT_SYNTH_ITE_COMPLETE(95), - - /** - * **Quantifier solver engine: - * Limit for synthesis.** - * - * Configure the limit of enumerated expressions for the enumerative learning - * synthesis algorithm implemented in the quantified solver engine. - * - * Values: - * * An unsigned integer value (**default**: 10000). - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. */ - BITWUZLA_OPT_QUANT_SYNTH_LIMIT(96), + BITWUZLA_OPTION_PP_NORMALIZE(25), - /** - * **Quantifier solver engine: - * Quantifier instantiation.** + /** + * **Preprocessing: Normalization: Enable share awareness normalization** * - * Configure the generalization of quantifier instantiations via enumerative - * learning. + * When enabled, this disables normalizations that may yield blow-up on the + * bit-level. * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option to configure the quantifier solver - * engine. */ - BITWUZLA_OPT_QUANT_SYNTH_QI(97), + BITWUZLA_OPTION_PP_NORMALIZE_SHARE_AWARE(26), - /* ------------------------ Other Expert Options ------------------------- */ - - /** - * **Check model (debug only).** + /** + * **Preprocessing: Boolean skeleton preprocessing** * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option. */ - BITWUZLA_OPT_CHECK_MODEL(98), + BITWUZLA_OPTION_PP_SKELETON_PREPROC(27), - /** - * **Check result when unconstrained optimization is enabled (debug only).** + /** + * **Preprocessing: Variable substitution** * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option. */ - BITWUZLA_OPT_CHECK_UNCONSTRAINED(99), + BITWUZLA_OPTION_PP_VARIABLE_SUBST(28), - /** - * **Check unsat assumptions (debug only).** + /** + * **Preprocessing: Variable substitution: Equality Normalization** * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option. - */ - BITWUZLA_OPT_CHECK_UNSAT_ASSUMPTIONS(100), - - /** - * **Interpret sorts introduced with declare-sort as bit-vectors of given - * width.** - * - * Disabled if zero. - * - * Values: - * * An unsigned integer value (**default**: 0). - * - * **Warning**: This is an expert option. */ - BITWUZLA_OPT_DECLSORT_BV_WIDTH(101), + BITWUZLA_OPTION_PP_VARIABLE_SUBST_NORM_EQ(29), - /** - * **Share partial models determined via local search with bit-blasting - * engine.** - * - * This option is only effective when local search engines are combined with - * the bit-blasting engine in a sequential portfolio. + /** + * **Preprocessing: Variable substitution: Disequality Normalization** * * Values: - * * **1**: enable - * * **0**: disable **(default)** - * - * **Warning**: This is an expert option. + * * **1**: enable (**default**) + * * **0**: disable */ - BITWUZLA_OPT_LS_SHARE_SAT(102), + BITWUZLA_OPTION_PP_VARIABLE_SUBST_NORM_DISEQ(30), - /** - * **Interactive parsing mode.** + /** + * **Preprocessing: Variable substitution: Bit-Vector Inequality + * Normalization** * * Values: - * * **1**: enable **(default)** + * * **1**: enable (**default**) * * **0**: disable - * - * **Warning**: This is an expert option. */ - BITWUZLA_OPT_PARSE_INTERACTIVE(103), + BITWUZLA_OPTION_PP_VARIABLE_SUBST_NORM_BV_INEQ(31), - /** - * **Use CaDiCaL's freeze/melt.** + /** + * **Debug: + * Threshold for number of new nodes introduced for recursive call of + * rewrite(). ** * - * Values: - * * **1**: enable - * * **0**: disable **(default)** + * Prints a warning number of newly introduced nodes is above threshold. * - * **Warning**: This is an expert option. + * **warning:** This is an expert debug option. */ - BITWUZLA_OPT_SAT_ENGINE_CADICAL_FREEZE(104), + BITWUZLA_OPTION_DBG_RW_NODE_THRESH(32), - /** - * **Lingeling fork mode.** + /** + * **Debug: + * Threshold for formula size increase after preprocessing in percent. ** * - * Values: - * * **1**: enable **(default)** - * * **0**: disable + * Prints a warning if formula size increase is above threshold. * - * **Warning**: This is an expert option. + * **warning:** This is an expert debug option. */ - BITWUZLA_OPT_SAT_ENGINE_LGL_FORK(105), + BITWUZLA_OPTION_DBG_PP_NODE_THRESH(33), - /** - * **Number of threads to use in the SAT solver.** - * - * This option is only effective for SAT solvers with support for - * multi-threading. - * - * Values: - * * An unsigned integer value > 0 (**default**: 1). + /** + * **Debug: Check models for each satisfiable query. ** * - * **Warning**: This is an expert option. + * **warning:** This is an expert debug option. */ - BITWUZLA_OPT_SAT_ENGINE_N_THREADS(106), + BITWUZLA_OPTION_DBG_CHECK_MODEL(34), - /** - * **Enable SMT-COMP mode.** - * - * Parser only option. Only effective when an SMT2 input file is parsed. - * - * Values: - * * **1**: enable - * * **0**: disable **(default)** + /** + * **Debug: Check unsat core for each unsatisfiable query. ** * - * **Warning**: This is an expert option. + * **warning:** This is an expert debug option. */ - BITWUZLA_OPT_SMT_COMP_MODE(107), + BITWUZLA_OPTION_DBG_CHECK_UNSAT_CORE(35), - BITWUZLA_OPT_NUM_OPTS(108); + BITWUZLA_OPTION_NUM_OPTS(36); companion object { private val valueMapping = BitwuzlaOption.values().associateBy { it.value } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FpValue.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FpValue.kt index 40ce1ae86..01b7a68c7 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FpValue.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FpValue.kt @@ -1,11 +1,10 @@ package org.ksmt.solver.bitwuzla.bindings /** - * @param sign Binary string representation of the sign bit. - * @param exponent Binary string representation of the exponent bit-vector value. - * @param significand Binary string representation of the significand bit-vector value. + * @property sign Binary string representation of the sign bit. + * @property exponent Binary string representation of the exponent bit-vector value. + * @property significand Binary string representation of the significand bit-vector value. * */ - class FpValue { @JvmField var sign: String = "" diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FunValue.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FunValue.kt deleted file mode 100644 index f5d916380..000000000 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/FunValue.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.ksmt.solver.bitwuzla.bindings - -/** - * @param args List of argument lists (nested lists) of size `size`. Each - * argument list is of size `arity`. - * @param arity Size of each argument list in `args`. - * @param values List of values of size `size`. - * @param size Size of `indices` and `values` list. - * - * **Usage** - * ``` - * for (int i = 0; i < size; ++i) - * { - * // args[i] are argument lists of size arity - * for (int j = 0; j < arity; ++j) - * { - * // args[i][j] corresponds to value of jth argument of function f - * } - * // values[i] corresponds to the value of - * // (f args[i][0] ... args[i][arity - 1]) - * } - * ``` - */ -class FunValue { - @JvmField - var size: Int = 0 - @JvmField - var arity: Int = 0 - @JvmField - var args: Array? = null //Array of BitwuzlaTerm - @JvmField - var values: LongArray? = null //Array of BitwuzlaTerm -} diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/Native.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/Native.kt index 44f828259..8440b10b9 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/Native.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/main/kotlin/org/ksmt/solver/bitwuzla/bindings/Native.kt @@ -10,6 +10,12 @@ typealias BitwuzlaSort = Long typealias BitwuzlaTermArray = LongArray typealias BitwuzlaSortArray = LongArray +typealias BitwuzlaOptionsNative = Long +typealias BitwuzlaOptionNative = Int +typealias BitwuzlaRoundingModeNative = Int +typealias BitwuzlaResultNative = Int +typealias BitwuzlaKindNative = Int + object Native { init { NativeLibraryLoaderUtils.load() @@ -18,110 +24,144 @@ object Native { /** * Initialize Bitwuzla native library. - * */ + */ @JvmStatic - private external fun bitwuzlaInit(): Bitwuzla + private external fun bitwuzlaInit() /** - * Create a new Bitwuzla instance. - * - * The returned instance must be deleted via [bitwuzlaDelete]. - * - * @return A pointer to the created Bitwuzla instance. - * - * @see bitwuzlaDelete + * decrement external references count to sort */ @JvmStatic - external fun bitwuzlaNew(): Bitwuzla + external fun bitwuzlaSortDecRef(sort: BitwuzlaSort) /** - * Delete a Bitwuzla instance. - * - * The given instance must have been created via [bitwuzlaNew]. - * - * @param bitwuzla The Bitwuzla instance to delete. - * - * @see bitwuzlaNew + * decrement external references count to term */ @JvmStatic - external fun bitwuzlaDelete(bitwuzla: Bitwuzla) + external fun bitwuzlaTermDecRef(term: BitwuzlaTerm) + + + /* -------------------------------------------------------------------------- */ + /* Library info */ + /* -------------------------------------------------------------------------- */ /** - * Reset a Bitwuzla instance. - * - * This deletes the given instance and creates a new instance in place. - * The given instance must have been created via [bitwuzlaNew]. + * Get copyright information. + */ + @JvmStatic + external fun bitwuzlaCopyright(): String + + /** + * Get version information. + */ + @JvmStatic + external fun bitwuzlaVersion(): String + + /** + * Get git information. + */ + @JvmStatic + external fun bitwuzlaGitId(): String + + + /* -------------------------------------------------------------------------- */ + /* Options */ + /* -------------------------------------------------------------------------- */ + + /** + * Create a new BitwuzlaOptionsNative instance. * - * Note: All sorts and terms associated with the given instance are released - * and thus invalidated. + * The returned instance must be deleted via [bitwuzlaOptionsDelete]. * - * @param bitwuzla The Bitwuzla instance to reset. + * @return A pointer to the created BitwuzlaOptionsNative instance. * - * @see bitwuzlaNew + * @see bitwuzlaOptionsDelete */ @JvmStatic - external fun bitwuzlaReset(bitwuzla: Bitwuzla) + external fun bitwuzlaOptionsNew(): BitwuzlaOptionsNative /** - * Get copyright information. + * Delete a BitwuzlaOptionsNative instance. * - * @param bitwuzla The Bitwuzla instance. + * The given instance must have been created via [bitwuzlaOptionsNew]. + * + * @param options The BitwuzlaOptionsNative instance to delete. + * + * @see [bitwuzlaOptionsNew] */ @JvmStatic - external fun bitwuzlaCopyright(bitwuzla: Bitwuzla): String + external fun bitwuzlaOptionsDelete(options: BitwuzlaOptionsNative) /** - * Get version information. - * - * @param bitwuzla The Bitwuzla instance. + * Determine if a given option is a numeric (or [Boolean]) option. + * @return `true` if the given option is a numeric or [Boolean] option. */ @JvmStatic - external fun bitwuzlaVersion(bitwuzla: Bitwuzla): String + fun bitwuzlaOptionIsNumeric(options: BitwuzlaOptionsNative, option: BitwuzlaOption) = bitwuzlaOptionIsNumeric( + options, option.value + ) + + @JvmStatic + private external fun bitwuzlaOptionIsNumeric(options: BitwuzlaOptionsNative, option: BitwuzlaOptionNative): Boolean /** - * Get git information. - * - * @param bitwuzla The Bitwuzla instance. + * Determine if a given option is an option with a mode + * @return `true` if the given option is an option with a mode. */ @JvmStatic - external fun bitwuzlaGitId(bitwuzla: Bitwuzla): String + fun bitwuzlaOptionIsMode(options: BitwuzlaOptionsNative, option: BitwuzlaOption): Boolean = bitwuzlaOptionIsMode( + options, option.value + ) + + @JvmStatic + private external fun bitwuzlaOptionIsMode(options: BitwuzlaOptionsNative, option: BitwuzlaOptionNative): Boolean /** * Set option. * - * @param bitwuzla The Bitwuzla instance. + * @param options The Bitwuzla options instance. * @param option The option. * @param value The option value. * * @see BitwuzlaOption + * @see bitwuzlaGetOption */ @JvmStatic - fun bitwuzlaSetOption(bitwuzla: Bitwuzla, option: BitwuzlaOption, value: Int) = - bitwuzlaSetOption(bitwuzla, option.value, value) + fun bitwuzlaSetOption(options: BitwuzlaOptionsNative, option: BitwuzlaOption, value: Long) = bitwuzlaSetOption( + options, option.value, value + ) @JvmStatic - external fun bitwuzlaSetOption(bitwuzla: Bitwuzla, option: Int, value: Int) + private external fun bitwuzlaSetOption(options: BitwuzlaOptionsNative, option: BitwuzlaOptionNative, value: Long) /** - * Set option value for string options. + * Set option mode for options with modes. * - * @param bitwuzla The Bitwuzla instance. + * @param options The Bitwuzla options instance. * @param option The option. * @param value The option string value. * * @see BitwuzlaOption + * @see bitwuzlaGetOptionMode */ @JvmStatic - fun bitwuzlaSetOptionStr(bitwuzla: Bitwuzla, option: BitwuzlaOption, value: String) = - bitwuzlaSetOptionStr(bitwuzla, option.value, value) + fun bitwuzlaSetOptionMode( + options: BitwuzlaOptionsNative, + option: BitwuzlaOption, + value: String + ) = bitwuzlaSetOptionMode(options, option.value, value) @JvmStatic - external fun bitwuzlaSetOptionStr(bitwuzla: Bitwuzla, option: Int, value: String) + private external fun bitwuzlaSetOptionMode( + options: BitwuzlaOptionsNative, + option: BitwuzlaOptionNative, + value: String + ) /** * Get the current value of an option. * - * @param bitwuzla The Bitwuzla instance. + * @param options The Bitwuzla options instance. * @param option The option. * * @return The option value. @@ -129,1843 +169,1739 @@ object Native { * @see BitwuzlaOption */ @JvmStatic - fun bitwuzlaGetOption(bitwuzla: Bitwuzla, option: BitwuzlaOption): Int = - bitwuzlaGetOption(bitwuzla, option.value) + fun bitwuzlaGetOption( + options: BitwuzlaOptionsNative, + option: BitwuzlaOption + ) = bitwuzlaGetOption(options, option.value) @JvmStatic - external fun bitwuzlaGetOption(bitwuzla: Bitwuzla, option: Int): Int + private external fun bitwuzlaGetOption(options: BitwuzlaOptionsNative, option: BitwuzlaOptionNative): Long /** - * Get the current value of an option as a string if option can be configured - * via a string value. + * Get the current mode of an option as a string if option has modes. * - * @param bitwuzla The Bitwuzla instance. + * @param options The Bitwuzla options instance. * @param option The option. * * @return The option value. * * @see BitwuzlaOption - * @see bitwuzlaSetOptionStr + * @see bitwuzlaSetOptionMode */ @JvmStatic - fun bitwuzlaGetOptionStr(bitwuzla: Bitwuzla, option: BitwuzlaOption): String = - bitwuzlaGetOptionStr(bitwuzla, option.value) + fun bitwuzlaGetOptionMode(options: BitwuzlaOptionsNative, option: BitwuzlaOption) = bitwuzlaGetOptionMode( + options, option.value + ) @JvmStatic - external fun bitwuzlaGetOptionStr(bitwuzla: Bitwuzla, option: Int): String + private external fun bitwuzlaGetOptionMode(options: BitwuzlaOptionsNative, option: BitwuzlaOptionNative): String + + + /* -------------------------------------------------------------------------- */ + /* BitwuzlaSort */ + /* -------------------------------------------------------------------------- */ /** - * Create an array sort. - * - * @param bitwuzla The Bitwuzla instance. - * @param index The index sort of the array sort. - * @param element The element sort of the array sort. + * Compute the hash value for a sort. * - * @return An array sort which maps sort `index` to sort `element`. + * @param sort The sort. * - * @see bitwuzlaSortIsArray - * @see bitwuzlaSortArrayGetIndex - * @see bitwuzlaSortArrayGetElement - * @see bitwuzlaTermIsArray - * @see bitwuzlaTermArrayGetIndexSort - * @see bitwuzlaTermArrayGetElementSort + * @return The hash value of the sort. */ @JvmStatic - external fun bitwuzlaMkArraySort(bitwuzla: Bitwuzla, index: BitwuzlaSort, element: BitwuzlaSort): BitwuzlaSort - + external fun bitwuzlaSortHash(sort: BitwuzlaSort): Long /** - * Create a Boolean sort. + * Get the size of a bit-vector sort. * - * Note: A Boolean sort is a bit-vector sort of size 1. + * Requires that given sort is a bit-vector sort. * - * @param bitwuzla The Bitwuzla instance. + * @param sort The sort. * - * @return A Boolean sort. + * @return The size of the bit-vector sort. */ @JvmStatic - external fun bitwuzlaMkBoolSort(bitwuzla: Bitwuzla): BitwuzlaSort + external fun bitwuzlaSortBvGetSize(sort: BitwuzlaSort): Long /** - * Create a bit-vector sort of given size. + * Get the exponent size of a floating-point sort. * - * @param bitwuzla The Bitwuzla instance. - * @param size The size of the bit-vector sort. + * Requires that given sort is a floating-point sort. * - * @return A bit-vector sort of given size. + * @param sort The sort. * - * @see bitwuzlaSortIsBv - * @see bitwuzlaSortBvGetSize - * @see bitwuzlaTermIsBv - * @see bitwuzlaTermBvGetSize + * @return The exponent size of the floating-point sort. */ @JvmStatic - external fun bitwuzlaMkBvSort(bitwuzla: Bitwuzla, size: Int): BitwuzlaSort + external fun bitwuzlaSortFpGetExpSize(sort: BitwuzlaSort): Long /** - * Create a floating-point sort of given exponent and significand size. + * Get the significand size of a floating-point sort. * - * @param bitwuzla The Bitwuzla instance. - * @param expSize The size of the exponent. - * @param sigSize The size of the significand (including sign bit). + * Requires that given sort is a floating-point sort. * - * @return A floating-point sort of given format. + * @param sort The sort. * - * @see bitwuzlaSortIsFp - * @see bitwuzlaSortFpGetExpSize - * @see bitwuzlaSortFpGetSigSize - * @see bitwuzlaTermIsFp - * @see bitwuzlaTermFpGetExpSize - * @see bitwuzlaTermFpGetSigSize + * @return The significand size of the floating-point sort. */ @JvmStatic - external fun bitwuzlaMkFpSort(bitwuzla: Bitwuzla, expSize: Int, sigSize: Int): BitwuzlaSort + external fun bitwuzlaSortFpGetSigSize(sort: BitwuzlaSort): Long /** - * Create a function sort. + * Get the index sort of an array sort. * - * @param bitwuzla The Bitwuzla instance. - * @param arity The number of arguments to the function. - * @param domain The domain sorts (the sorts of the arguments). The number of - * sorts in this vector must match `arity`. - * @param codomain The codomain sort (the sort of the return value). + * Requires that given sort is an array sort. * - * @return A function sort of given domain and codomain sorts. + * @param sort The sort. * - * @see bitwuzlaSortIsFun - * @see bitwuzlaSortFunGetArity - * @see bitwuzlaSortFunGetDomainSorts - * @see bitwuzlaSortFunGetCodomain - * @see bitwuzlaTermIsFun - * @see bitwuzlaTermFunGetArity - * @see bitwuzlaTermFunGetDomainSorts - * @see bitwuzlaTermFunGetCodomainSort + * @return The index sort of the array sort. */ @JvmStatic - external fun bitwuzlaMkFunSort( - bitwuzla: Bitwuzla, - arity: Int, - domain: BitwuzlaSortArray, - codomain: BitwuzlaSort - ): BitwuzlaSort + external fun bitwuzlaSortArrayGetIndex(sort: BitwuzlaSort): BitwuzlaSort /** - * Create a Roundingmode sort. + * Get the element sort of an array sort. * - * @param bitwuzla The Bitwuzla instance. + * Requires that given sort is an array sort. * - * @return A Roundingmode sort. + * @param sort The sort. * - * @see bitwuzlaSortIsRm - * @see bitwuzlaTermIsRm + * @return The element sort of the array sort. */ @JvmStatic - external fun bitwuzlaMkRmSort(bitwuzla: Bitwuzla): BitwuzlaSort + external fun bitwuzlaSortArrayGetElement(sort: BitwuzlaSort): BitwuzlaSort /** - * Create a true value. + * Get the domain sorts of a function sort. * - * Note: This creates a bit-vector value 1 of size 1. + * The domain sorts are returned as an array of sorts. + * Requires that given sort is a function sort. * - * @param bitwuzla The Bitwuzla instance. + * @param sort The sort. * - * @return A term representing the bit-vector value 1 of size 1. + * @return The domain sorts of the function sort. */ @JvmStatic - external fun bitwuzlaMkTrue(bitwuzla: Bitwuzla): BitwuzlaTerm + external fun bitwuzlaSortFunGetDomainSorts(sort: BitwuzlaSort): BitwuzlaSortArray /** - * Create a false value. + * Get the codomain sort of a function sort. * - * Note: This creates a bit-vector value 0 of size 1. + * Requires that given sort is a function sort. * - * @param bitwuzla The Bitwuzla instance. + * @param sort The sort. * - * @return A term representing the bit-vector value 0 of size 1. + * @return The codomain sort of the function sort. */ @JvmStatic - external fun bitwuzlaMkFalse(bitwuzla: Bitwuzla): BitwuzlaTerm + external fun bitwuzlaSortFunGetCodomain(sort: BitwuzlaSort): BitwuzlaSort /** - * Create a bit-vector value zero. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Get the arity of a function sort. * - * @return A term representing the bit-vector value 0 of given sort. + * @param sort The sort. * - * @see bitwuzlaMkBvSort + * @return The number of arguments of the function sort. */ @JvmStatic - external fun bitwuzlaMkBvZero(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm + external fun bitwuzlaSortFunGetArity(sort: BitwuzlaSort): Long /** - * Create a bit-vector value one. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. - * - * @return A term representing the bit-vector value 1 of given sort. - * - * @see bitwuzlaMkBvSort + * Get the symbol of an uninterpreted sort. + * @param sort The sort. + * @return The symbol; *null* if no symbol is defined. + * @note The returned string is only valid until the next [bitwuzlaSortGetUninterpretedSymbol] call. */ @JvmStatic - external fun bitwuzlaMkBvOne(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm + external fun bitwuzlaSortGetUninterpretedSymbol(sort: BitwuzlaSort): String? /** - * Create a bit-vector value where all bits are set to 1. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if two sorts are equal. * - * @return A term representing the bit-vector value of given sort - * where all bits are set to 1. + * @param sort0 The first sort. + * @param sort1 The second sort. * - * @see bitwuzlaMkBvSort + * @return `true` if the given sorts are equal. */ @JvmStatic - external fun bitwuzlaMkBvOnes(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm - + external fun bitwuzlaSortIsEqual(sort0: BitwuzlaSort, sort1: BitwuzlaSort): Boolean /** - * Create a bit-vector minimum signed value. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is an array sort. * - * @return A term representing the bit-vector value of given sort where the MSB - * is set to 1 and all remaining bits are set to 0. + * @param sort The sort. * - * @see bitwuzlaMkBvSort + * @return `true` if [sort] is an array sort. */ @JvmStatic - external fun bitwuzlaMkBvMinSigned(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm - + external fun bitwuzlaSortIsArray(sort: BitwuzlaSort): Boolean /** - * Create a bit-vector maximum signed value. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is a Boolean sort. * - * @return A term representing the bit-vector value of given sort where the MSB - * is set to 0 and all remaining bits are set to 1. + * @param sort The sort. * - * @see bitwuzlaMkBvSort + * @return `true` if [sort] is a Boolean sort. */ @JvmStatic - external fun bitwuzlaMkBvMaxSigned(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm - + external fun bitwuzlaSortIsBool(sort: BitwuzlaSort): Boolean /** - * Create a floating-point positive zero value (SMT-LIB: `+zero`). - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is a bit-vector sort. * - * @return A term representing the floating-point positive zero value of given - * floating-point sort. + * @param sort The sort. * - * @see bitwuzlaMkFpSort + * @return true if [sort] is a bit-vector sort. */ @JvmStatic - external fun bitwuzlaMkFpPosZero(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm - + external fun bitwuzlaSortIsBv(sort: BitwuzlaSort): Boolean /** - * Create a floating-point negative zero value (SMT-LIB: `-zero`). - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is a floating-point sort. * - * @return A term representing the floating-point negative zero value of given - * floating-point sort. + * @param sort The sort. * - * @see bitwuzlaMkFpSort + * @return `true` if [sort] is a floating-point sort. */ @JvmStatic - external fun bitwuzlaMkFpNegZero(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm - + external fun bitwuzlaSortIsFp(sort: BitwuzlaSort): Boolean /** - * Create a floating-point positive infinity value (SMT-LIB: `+oo`). - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is a function sort. * - * @return A term representing the floating-point positive infinity value of - * given floating-point sort. + * @param sort The sort. * - * @see bitwuzlaMkFpSort + * @return `true` if [sort] is a function sort. */ @JvmStatic - external fun bitwuzlaMkFpPosInf(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm - + external fun bitwuzlaSortIsFun(sort: BitwuzlaSort): Boolean /** - * Create a floating-point negative infinity value (SMT-LIB: `-oo`). - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is a Roundingmode sort. * - * @return A term representing the floating-point negative infinity value of - * given floating-point sort. + * @param sort The sort. * - * @see bitwuzlaMkFpSort + * @return `true` if [sort] is a Roundingmode sort. */ @JvmStatic - external fun bitwuzlaMkFpNegInf(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm + external fun bitwuzlaSortIsRm(sort: BitwuzlaSort): Boolean /** - * Create a floating-point NaN value. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. + * Determine if a sort is an uninterpreted sort. * - * @return A term representing the floating-point NaN value of given - * floating-point sort. + * @param sort The sort. * - * @see bitwuzlaMkFpSort + * @return `true` if [sort] is a uninterpreted sort. */ @JvmStatic - external fun bitwuzlaMkFpNan(bitwuzla: Bitwuzla, sort: BitwuzlaSort): BitwuzlaTerm + external fun bitwuzlaSortIsUninterpreted(sort: BitwuzlaSort): Boolean /** - * Create a bit-vector value from its string representation. - * - * Parameter `base` determines the base of the string representation. - * - * Note: Given value must fit into a bit-vector of given size (sort). - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. - * @param value A string representing the value. - * @param base The base in which the string is given. - * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAL], representing the bit-vector value - * of given sort. - * - * @see bitwuzlaMkBvSort - * @see BitwuzlaBVBase + * Get the SMT-LIBV v2 string representation of a sort. + * @return A string representation of the given sort. + * @note The returned [String] is only valid until the next [bitwuzlaSortToString] call. */ @JvmStatic - fun bitwuzlaMkBvValue( - bitwuzla: Bitwuzla, - sort: BitwuzlaSort, - value: String, - base: BitwuzlaBVBase - ): BitwuzlaTerm = bitwuzlaMkBvValue(bitwuzla, sort, value, base.value) + external fun bitwuzlaSortToString(sort: BitwuzlaSort): String - @JvmStatic - external fun bitwuzlaMkBvValue( - bitwuzla: Bitwuzla, - sort: BitwuzlaSort, - value: String, - base: Int - ): BitwuzlaTerm + /* -------------------------------------------------------------------------- */ + /* BitwuzlaTerm */ + /* -------------------------------------------------------------------------- */ /** - * Create a bit-vector value from its unsigned integer representation. + * Compute the hash value for a term. * - * Note: If given value does not fit into a bit-vector of given size (sort), - * the value is truncated to fit. + * @param term The term. * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. - * @param value The unsigned integer representation of the bit-vector value. - * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAL], representing the bit-vector value - * of given sort. - * - * @see bitwuzlaMkBvSort + * @return The hash value of the term. */ @JvmStatic - external fun bitwuzlaMkBvValueUint32(bitwuzla: Bitwuzla, sort: BitwuzlaSort, value: Int): BitwuzlaTerm + external fun bitwuzlaTermHash(term: BitwuzlaTerm): Long /** - * Create a floating-point value from its IEEE 754 standard representation - * given as three bit-vector values representing the sign bit, the exponent and - * the significand. + * Get the kind of a term. * - * @param bitwuzla The Bitwuzla instance. - * @param bvSign The sign bit. - * @param bvExponent The exponent bit-vector value. - * @param bvSignificand The significand bit-vector value. + * @param term The term. + * + * @return The kind of the given term. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAL], representing the floating-point - * value. + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaMkFpValue( - bitwuzla: Bitwuzla, - bvSign: BitwuzlaTerm, - bvExponent: BitwuzlaTerm, - bvSignificand: BitwuzlaTerm - ): BitwuzlaTerm + fun bitwuzlaTermGetKind(term: BitwuzlaTerm) = BitwuzlaKind.fromValue(bitwuzlaTermGetKindNative(term)) + + @JvmStatic + private external fun bitwuzlaTermGetKindNative(term: BitwuzlaTerm): BitwuzlaKindNative /** - * Create a floating-point value from its real representation, given as a - * decimal string, with respect to given rounding mode. + * Get the child terms of a term. * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. - * @param rm The rounding mode. - * @param value The decimal string representing a real value. + * Returns `null` if given term does not have children. + * + * @param term The term. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAL], representing the floating-point - * value of given sort. + * @return The children of [term] as an array of terms. */ @JvmStatic - external fun bitwuzlaMkFpValueFromReal( - bitwuzla: Bitwuzla, - sort: BitwuzlaSort, - rm: BitwuzlaTerm, - value: String - ): BitwuzlaTerm + external fun bitwuzlaTermGetChildren(term: BitwuzlaTerm): BitwuzlaTermArray /** - * Create a floating-point value from its rational representation, given as - * two decimal strings representing the numerator and denominator, with respect - * to given rounding mode. + * Get the indices of an indexed term. * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the value. - * @param rm The rounding mode. - * @param numerator The decimal string representing the numerator. - * @param denominator The decimal string representing the denominator. + * Requires that given term is an indexed term. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAL], representing the floating-point - * value of given sort. + * @param term The term. + * + * @return The indices of [term] as an array of indices. */ @JvmStatic - external fun bitwuzlaMkFpValueFromRational( - bitwuzla: Bitwuzla, - sort: BitwuzlaSort, - rm: BitwuzlaTerm, - numerator: String, - denominator: String - ): BitwuzlaTerm + external fun bitwuzlaTermGetIndices(term: BitwuzlaTerm): LongArray /** - * Create a rounding mode value. - * - * @param bitwuzla The Bitwuzla instance. - * @param rm The rounding mode value. + * Determine if a term is an indexed term. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAL], representing the rounding mode - * value. + * @param term The term. * - * @see BitwuzlaRoundingMode + * @return `true` if [term] is an indexed term. */ @JvmStatic - fun bitwuzlaMkRmValue(bitwuzla: Bitwuzla, rm: BitwuzlaRoundingMode): BitwuzlaTerm = - bitwuzlaMkRmValue(bitwuzla, rm.value) + external fun bitwuzlaTermIsIndexed(term: BitwuzlaTerm): Boolean + /** + * Get the sort of a term. + * + * @param term The term. + * + * @return The sort of the term. + */ @JvmStatic - external fun bitwuzlaMkRmValue(bitwuzla: Bitwuzla, rm: Int): BitwuzlaTerm + external fun bitwuzlaTermGetSort(term: BitwuzlaTerm): BitwuzlaSort /** - * Create a term of given kind with one argument term. + * Get the index sort of an array term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg The argument to the operator. + * Requires that given term is an array or an array store term. * - * @return A term representing an operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The index sort of the array term. */ @JvmStatic - fun bitwuzlaMkTerm1(bitwuzla: Bitwuzla, kind: BitwuzlaKind, arg: BitwuzlaTerm): BitwuzlaTerm = - bitwuzlaMkTerm1(bitwuzla, kind.value, arg) - - @JvmStatic - external fun bitwuzlaMkTerm1(bitwuzla: Bitwuzla, kind: Int, arg: BitwuzlaTerm): BitwuzlaTerm + external fun bitwuzlaTermArrayGetIndexSort(term: BitwuzlaTerm): BitwuzlaSort /** - * Create a term of given kind with two argument terms. + * Get the element sort of an array term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg0 The first argument to the operator. - * @param arg1 The second argument to the operator. + * Requires that given term is an array or an array store term. * - * @return A term representing an operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The element sort of the array term. */ @JvmStatic - fun bitwuzlaMkTerm2( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm - ): BitwuzlaTerm = bitwuzlaMkTerm2(bitwuzla, kind.value, arg0, arg1) - - @JvmStatic - external fun bitwuzlaMkTerm2( - bitwuzla: Bitwuzla, - kind: Int, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm - ): BitwuzlaTerm + external fun bitwuzlaTermArrayGetElementSort(term: BitwuzlaTerm): BitwuzlaSort /** - * Create a term of given kind with three argument terms. + * Get the domain sorts of a function term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg0 The first argument to the operator. - * @param arg1 The second argument to the operator. - * @param arg2 The third argument to the operator. + * The domain sorts are returned as an array of sorts. + * Requires that given term is an uninterpreted function, a lambda term, an + * array store term, or an ite term over function terms. * - * @return A term representing an operation of given kind. * - * @see BitwuzlaKind + * @param term The term. + * + * @return The domain sorts of the function term. */ @JvmStatic - fun bitwuzlaMkTerm3( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm, - arg2: BitwuzlaTerm - ): BitwuzlaTerm = bitwuzlaMkTerm3(bitwuzla, kind.value, arg0, arg1, arg2) - - @JvmStatic - external fun bitwuzlaMkTerm3( - bitwuzla: Bitwuzla, - kind: Int, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm, - arg2: BitwuzlaTerm - ): BitwuzlaTerm + external fun bitwuzlaTermFunGetDomainSorts(term: BitwuzlaTerm): BitwuzlaSortArray /** - * Create a term of given kind with the given argument terms. + * Get the codomain sort of a function term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param args The argument terms. + * Requires that given term is an uninterpreted function, a lambda term, an + * array store term, or an ite term over function terms. * - * @return A term representing an operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The codomain sort of the function term. */ @JvmStatic - fun bitwuzlaMkTerm(bitwuzla: Bitwuzla, kind: BitwuzlaKind, args: BitwuzlaTermArray): BitwuzlaTerm = - bitwuzlaMkTerm(bitwuzla, kind.value, args) - - @JvmStatic - external fun bitwuzlaMkTerm(bitwuzla: Bitwuzla, kind: Int, args: BitwuzlaTermArray): BitwuzlaTerm + external fun bitwuzlaTermFunGetCodomainSort(term: BitwuzlaTerm): BitwuzlaSort /** - * Create an indexed term of given kind with one argument term and one index. + * Get the bit-width of a bit-vector term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg The argument term. - * @param idx The index. + * Requires that given term is a bit-vector term. * - * @return A term representing an indexed operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The bit-width of the bit-vector term. */ @JvmStatic - fun bitwuzlaMkTerm1Indexed1( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - arg: BitwuzlaTerm, - idx: Int - ): BitwuzlaTerm = bitwuzlaMkTerm1Indexed1(bitwuzla, kind.value, arg, idx) - - @JvmStatic - external fun bitwuzlaMkTerm1Indexed1( - bitwuzla: Bitwuzla, - kind: Int, - arg: BitwuzlaTerm, - idx: Int - ): BitwuzlaTerm - + external fun bitwuzlaTermBvGetSize(term: BitwuzlaTerm): Long /** - * Create an indexed term of given kind with one argument term and two indices. + * Get the bit-width of the exponent of a floating-point term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg The argument term. - * @param idx0 The first index. - * @param idx1 The second index. + * Requires that given term is a floating-point term. * - * @return A term representing an indexed operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The bit-width of the exponent of the floating-point term. */ @JvmStatic - fun bitwuzlaMkTerm1Indexed2( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - arg: BitwuzlaTerm, - idx0: Int, - idx1: Int - ): BitwuzlaTerm = bitwuzlaMkTerm1Indexed2(bitwuzla, kind.value, arg, idx0, idx1) - - @JvmStatic - external fun bitwuzlaMkTerm1Indexed2( - bitwuzla: Bitwuzla, - kind: Int, - arg: BitwuzlaTerm, - idx0: Int, - idx1: Int - ): BitwuzlaTerm - + external fun bitwuzlaTermFpGetExpSize(term: BitwuzlaTerm): Long /** - * Create an indexed term of given kind with two argument terms and one index. + * Get the bit-width of the significand of a floating-point term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg0 The first argument term. - * @param arg1 The second argument term. - * @param idx The index. + * Requires that given term is a floating-point term. * - * @return A term representing an indexed operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The bit-width of the significand of the floating-point term. */ @JvmStatic - fun bitwuzlaMkTerm2Indexed1( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm, - idx: Int - ): BitwuzlaTerm = bitwuzlaMkTerm2Indexed1(bitwuzla, kind.value, arg0, arg1, idx) - - @JvmStatic - external fun bitwuzlaMkTerm2Indexed1( - bitwuzla: Bitwuzla, - kind: Int, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm, - idx: Int - ): BitwuzlaTerm - + external fun bitwuzlaTermFpGetSigSize(term: BitwuzlaTerm): Long /** - * Create an indexed term of given kind with two argument terms and two indices. + * Get the arity of a function term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param arg0 The first argument term. - * @param arg1 The second argument term. - * @param idx0 The first index. - * @param idx1 The second index. + * Requires that given term is a function term. * - * @return A term representing an indexed operation of given kind. + * @param term The term. * - * @see BitwuzlaKind + * @return The arity of the function term. */ - @Suppress("LongParameterList") - @JvmStatic - fun bitwuzlaMkTerm2Indexed2( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm, - idx0: Int, - idx1: Int - ): BitwuzlaTerm = bitwuzlaMkTerm2Indexed2(bitwuzla, kind.value, arg0, arg1, idx0, idx1) - - @Suppress("LongParameterList") @JvmStatic - external fun bitwuzlaMkTerm2Indexed2( - bitwuzla: Bitwuzla, - kind: Int, - arg0: BitwuzlaTerm, - arg1: BitwuzlaTerm, - idx0: Int, - idx1: Int - ): BitwuzlaTerm + external fun bitwuzlaTermFunGetArity(term: BitwuzlaTerm): Long /** - * Create an indexed term of given kind with the given argument terms and - * indices. + * Get the symbol of a term. * - * @param bitwuzla The Bitwuzla instance. - * @param kind The operator kind. - * @param args The argument terms. - * @param indices The indices. + * @param term The term. * - * @return A term representing an indexed operation of given kind. + * @return The symbol of [term]. `null` if no symbol is defined. */ @JvmStatic - fun bitwuzlaMkTermIndexed( - bitwuzla: Bitwuzla, - kind: BitwuzlaKind, - args: BitwuzlaTermArray, - indices: IntArray - ): BitwuzlaTerm = bitwuzlaMkTermIndexed(bitwuzla, kind.value, args, indices) - - @JvmStatic - external fun bitwuzlaMkTermIndexed( - bitwuzla: Bitwuzla, - kind: Int, - args: BitwuzlaTermArray, - indices: IntArray - ): BitwuzlaTerm + external fun bitwuzlaTermGetSymbol(term: BitwuzlaTerm): String? /** - * Create a (first-order) constant of given sort with given symbol. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the constant. - * @param symbol The symbol of the constant. + * Determine if the sorts of two terms are equal. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_CONST], representing the constant. + * @param term0 The first term. + * @param term1 The second term. * - * @see bitwuzlaMkArraySort - * @see bitwuzlaMkBoolSort - * @see bitwuzlaMkBvSort - * @see bitwuzlaMkFpSort - * @see bitwuzlaMkFunSort - * @see bitwuzlaMkRmSort + * @return `true` if the sorts of [term0] and [term1] are equal. */ @JvmStatic - external fun bitwuzlaMkConst(bitwuzla: Bitwuzla, sort: BitwuzlaSort, symbol: String): BitwuzlaTerm + external fun bitwuzlaTermIsEqualSort(term0: BitwuzlaTerm, term1: BitwuzlaTerm): Boolean /** - * Create a one-dimensional constant array of given sort, initialized with - * given value. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the array. - * @param value The term to initialize the elements of the array with. + * Determine if a term is an array term. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_CONST_ARRAY], representing a constant - * array of given sort. + * @param term The term. * - * @see bitwuzlaMkArraySort + * @return `true` if [term] is an array term. */ @JvmStatic - external fun bitwuzlaMkConstArray(bitwuzla: Bitwuzla, sort: BitwuzlaSort, value: BitwuzlaTerm): BitwuzlaTerm + external fun bitwuzlaTermIsArray(term: BitwuzlaTerm): Boolean /** - * Create a variable of given sort with given symbol. - * - * Note: This creates a variable to be bound by quantifiers or lambdas. - * - * @param bitwuzla The Bitwuzla instance. - * @param sort The sort of the variable. - * @param symbol The symbol of the variable. + * Determine if a term is a constant. * - * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VAR], representing the variable. + * @param term The term. * - * @see bitwuzlaMkBoolSort - * @see bitwuzlaMkBvSort - * @see bitwuzlaMkFpSort - * @see bitwuzlaMkFunSort - * @see bitwuzlaMkRmSort + * @return `true` if [term] is a constant. */ @JvmStatic - external fun bitwuzlaMkVar(bitwuzla: Bitwuzla, sort: BitwuzlaSort, symbol: String): BitwuzlaTerm + external fun bitwuzlaTermIsConst(term: BitwuzlaTerm): Boolean /** - * Push context levels. - * - * Requires that incremental solving has been enabled via - * [bitwuzlaSetOption]. - * - * Note: Assumptions added via this [bitwuzlaAssume] are not affected by - * context level changes and are only valid until the next - * [bitwuzlaCheckSat] call, no matter at which level they were - * assumed. + * Determine if a term is a function. * - * @param bitwuzla The Bitwuzla instance. - * @param nlevels The number of context levels to push. + * @param term The term. * - * @see bitwuzlaSetOption - * @see BitwuzlaOption.BITWUZLA_OPT_INCREMENTAL + * @return `true` if [term] is a function. */ @JvmStatic - external fun bitwuzlaPush(bitwuzla: Bitwuzla, nlevels: Int) + external fun bitwuzlaTermIsFun(term: BitwuzlaTerm): Boolean /** - * Pop context levels. - * - * Requires that incremental solving has been enabled via - * [bitwuzlaSetOption]. - * - * Note: Assumptions added via this [bitwuzlaAssume] are not affected by - * context level changes and are only valid until the next - * [bitwuzlaCheckSat] call, no matter at which level they were - * assumed. + * Determine if a term is a variable. * - * @param bitwuzla The Bitwuzla instance. - * @param nlevels The number of context levels to pop. + * @param term The term. * - * @see bitwuzlaSetOption - * @see BitwuzlaOption.BITWUZLA_OPT_INCREMENTAL + * @return True if `term` is a variable. */ @JvmStatic - external fun bitwuzlaPop(bitwuzla: Bitwuzla, nlevels: Int) + external fun bitwuzlaTermIsVar(term: BitwuzlaTerm): Boolean /** - * Assert formula. + * Determine if a term is a value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The formula to assert. + * @param term The term. + * + * @return True if `term` is a value. */ @JvmStatic - external fun bitwuzlaAssert(bitwuzla: Bitwuzla, term: BitwuzlaTerm) + external fun bitwuzlaTermIsValue(term: BitwuzlaTerm): Boolean /** - * Assume formula. - * - * Requires that incremental solving has been enabled via - * [bitwuzlaSetOption]. - * - * Note: Assumptions added via this function are not affected by context level - * changes and are only valid until the next [bitwuzlaCheckSat] call, - * no matter at which level they were assumed. + * Determine if a term is a bit-vector value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The formula to assume. + * @param term The term. * - * @see bitwuzlaSetOption - * @see bitwuzlaIsUnsatAssumption - * @see bitwuzlaGetUnsatAssumptions - * @see BitwuzlaOption.BITWUZLA_OPT_INCREMENTAL + * @return `true` if [term] is a bit-vector value. */ @JvmStatic - external fun bitwuzlaAssume(bitwuzla: Bitwuzla, term: BitwuzlaTerm) + external fun bitwuzlaTermIsBvValue(term: BitwuzlaTerm): Boolean /** - * Determine if an assumption is an unsat assumption. - * - * Unsat assumptions are assumptions that force an input formula to become - * unsatisfiable. Unsat assumptions handling in Bitwuzla is analogous to - * failed assumptions in MiniSAT. - * - * Requires that incremental solving has been enabled via - * [bitwuzlaSetOption]. - * - * Requires that the last [bitwuzlaCheckSat] query returned - * [BitwuzlaResult.BITWUZLA_UNSAT]. + * Determine if a term is a floating-point value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The assumption to check for. + * @param term The term. * - * @return True if given assumption is an unsat assumption. + * @return `true` if [term] is a floating-point value. */ @JvmStatic - external fun bitwuzlaIsUnsatAssumption(bitwuzla: Bitwuzla, term: BitwuzlaTerm): Boolean + external fun bitwuzlaTermIsFpValue(term: BitwuzlaTerm): Boolean /** - * Get the set of unsat assumptions. - * - * Unsat assumptions are assumptions that force an input formula to become - * unsatisfiable. Unsat assumptions handling in Bitwuzla is analogous to - * failed assumptions in MiniSAT. - * - * Requires that incremental solving has been enabled via - * [bitwuzlaSetOption]. - * - * Requires that the last [bitwuzlaCheckSat] query returned - * [BitwuzlaResult.BITWUZLA_UNSAT]. - * - * @param bitwuzla The Bitwuzla instance. + * Determine if a term is a rounding mode value. * - * @return An array with unsat assumptions. + * @param term The term. * - * @see bitwuzlaSetOption - * @see bitwuzlaAssume - * @see bitwuzlaCheckSat - * @see BitwuzlaOption.BITWUZLA_OPT_INCREMENTAL + * @return `true` if [term] is a rounding mode value. */ @JvmStatic - external fun bitwuzlaGetUnsatAssumptions(bitwuzla: Bitwuzla): BitwuzlaTermArray - + external fun bitwuzlaTermIsRmValue(term: BitwuzlaTerm): Boolean /** - * Get the set unsat core (unsat assertions). + * Determine if a term is a Boolean term. * - * The unsat core consists of the set of assertions that force an input formula - * to become unsatisfiable. - * - * Requires that the last [bitwuzlaCheckSat] query returned - * [BitwuzlaResult.BITWUZLA_UNSAT]. - * - * @param bitwuzla The Bitwuzla instance. - * - * @return An array with unsat assertions. + * @param term The term. * - * @see bitwuzlaAssert - * @see bitwuzlaCheckSat + * @return `true` if [term] is a Boolean term. */ @JvmStatic - external fun bitwuzlaGetUnsatCore(bitwuzla: Bitwuzla): BitwuzlaTermArray - + external fun bitwuzlaTermIsBool(term: BitwuzlaTerm): Boolean /** - * Assert all added assumptions. + * Determine if a term is a bit-vector term. * - * @param bitwuzla The Bitwuzla instance. + * @param term The term. * - * @see bitwuzlaAssume + * @return `true` if [term] is a bit-vector term. */ @JvmStatic - external fun bitwuzlaFixateAssumptions(bitwuzla: Bitwuzla) + external fun bitwuzlaTermIsBv(term: BitwuzlaTerm): Boolean /** - * Reset all added assumptions. + * Determine if a term is a floating-point term. * - * @param bitwuzla The Bitwuzla instance. + * @param term The term. * - * @see bitwuzlaAssume + * @return `true` if [term] is a floating-point term. */ @JvmStatic - external fun bitwuzlaResetAssumptions(bitwuzla: Bitwuzla) + external fun bitwuzlaTermIsFp(term: BitwuzlaTerm): Boolean /** - * Simplify the current input formula. - * - * @note Assumptions are not considered for simplification. + * Determine if a term is a rounding mode term. * - * @param bitwuzla The Bitwuzla instance. + * @param term The term. * - * @return [BitwuzlaResult.BITWUZLA_SAT] if the input formula was simplified to true - * [BitwuzlaResult.BITWUZLA_UNSAT] if it was simplified to false, and - * [BitwuzlaResult.BITWUZLA_UNKNOWN] otherwise. + * @return `true` if [term] is a rounding mode term. */ @JvmStatic - fun bitwuzlaSimplifyResult(bitwuzla: Bitwuzla): BitwuzlaResult = - bitwuzlaSimplify(bitwuzla).let { BitwuzlaResult.fromValue(it) } + external fun bitwuzlaTermIsRm(term: BitwuzlaTerm): Boolean + /** + * Determine if a term is a term of uninterpreted sort. + * + * @param term The term. + * + * @return `true` if [term] is a term of uninterpreted sort. + */ @JvmStatic - external fun bitwuzlaSimplify(bitwuzla: Bitwuzla): Int + external fun bitwuzlaTermIsUninterpreted(term: BitwuzlaTerm): Boolean /** - * Check satisfiability of current input formula. - * - * An input formula consists of assertions added via [bitwuzlaAssert]. - * The search for a solution can by guided by making assumptions via - * [bitwuzlaAssume]. + * Determine if a term is Boolean value true. * - * Note: Assertions and assumptions are combined via Boolean and. Multiple - * calls to this function require enabling incremental solving via - * [bitwuzlaSetOption]. + * @param term The term. * - * @param bitwuzla The Bitwuzla instance. + * @return `true` if [term] is a Boolean value true. + */ + @JvmStatic + external fun bitwuzlaTermIsTrue(term: BitwuzlaTerm): Boolean + + /** + * Determine if a term is Boolean value false. * - * @return [BitwuzlaResult.BITWUZLA_SAT] if the input formula is satisfiable and - * [BitwuzlaResult.BITWUZLA_UNSAT] if it is unsatisfiable, and [BitwuzlaResult.BITWUZLA_UNKNOWN] - * when neither satisfiability nor unsatisfiability was determined. - * This can happen when `bitwuzla` was terminated via a termination - * callback. + * @param term The term. * - * @see bitwuzlaAssert - * @see bitwuzlaAssume - * @see bitwuzlaSetOption - * @see BitwuzlaOption.BITWUZLA_OPT_INCREMENTAL - * @see BitwuzlaResult + * @return `false` if [term] is a Boolean value false. */ @JvmStatic - fun bitwuzlaCheckSatResult(bitwuzla: Bitwuzla): BitwuzlaResult = - bitwuzlaCheckSat(bitwuzla).let { BitwuzlaResult.fromValue(it) } - - @JvmStatic - external fun bitwuzlaCheckSat(bitwuzla: Bitwuzla): Int + external fun bitwuzlaTermIsFalse(term: BitwuzlaTerm): Boolean /** - * Check formula satisfiability with timeout. + * Determine if a term is a bit-vector value representing zero. * - * @param timeout Timeout in milliseconds. + * @param term The term. * - * @see bitwuzlaCheckSat - * */ - @JvmStatic - fun bitwuzlaCheckSatTimeoutResult(bitwuzla: Bitwuzla, timeout: Long): BitwuzlaResult = - bitwuzlaCheckSatTimeout(bitwuzla, timeout).let { BitwuzlaResult.fromValue(it) } - + * @return `true` if [term] is a bit-vector zero value. + */ @JvmStatic - external fun bitwuzlaCheckSatTimeout(bitwuzla: Bitwuzla, timeout: Long): Int + external fun bitwuzlaTermIsBvValueZero(term: BitwuzlaTerm): Boolean /** - * Cancel currently performing check. + * Determine if a term is a bit-vector value representing one. + * + * @param term The term. * - * Note: in current implementation check is cancelable only - * if it was a check with timeout [bitwuzlaCheckSatTimeout]. - * */ + * @return `true` if [term] is a bit-vector one value. + */ @JvmStatic - external fun bitwuzlaForceTerminate(bitwuzla: Bitwuzla) + external fun bitwuzlaTermIsBvValueOne(term: BitwuzlaTerm): Boolean /** - * Get a term representing the model value of a given term. - * - * Requires that the last [bitwuzlaCheckSat] query returned - * [BitwuzlaResult.BITWUZLA_SAT]. - * - * @param bitwuzla The Bitwuzla instance. - * @param term The term to query a model value for. + * Determine if a term is a bit-vector value with all bits set to one. * - * @return A term representing the model value of term `term`. + * @param term The term. * - * @see bitwuzlaCheckSat + * @return `true` if [term] is a bit-vector value with all bits set to one. */ @JvmStatic - external fun bitwuzlaGetValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): BitwuzlaTerm - + external fun bitwuzlaTermIsBvValueOnes(term: BitwuzlaTerm): Boolean /** - * Get string representation of the current model value of given bit-vector - * term. + * Determine if a term is a bit-vector minimum signed value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The term to query a model value for. + * @param term The term. * - * @return Binary string representation of current model value of term \p term. - * Return value is valid until next `bitwuzla_get_bv_value` call. + * @return `true` if [term] is a bit-vector value with the most significant bit + * set to 1 and all other bits set to 0. */ @JvmStatic - external fun bitwuzlaGetBvValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): String + external fun bitwuzlaTermIsBvValueMinSigned(term: BitwuzlaTerm): Boolean /** - * Get string of IEEE 754 standard representation of the current model value of - * given floating-point term. + * Determine if a term is a bit-vector maximum signed value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The term to query a model value for. + * @param term The term. * - * @see FpValue + * @return `true` if [term] is a bit-vector value with the most significant bit + * set to 0 and all other bits set to 1. */ @JvmStatic - external fun bitwuzlaGetFpValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): FpValue + external fun bitwuzlaTermIsBvValueMaxSigned(term: BitwuzlaTerm): Boolean /** - * Get string representation of the current model value of given rounding mode - * term. + * Determine if a term is a floating-point positive zero (+zero) value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The rounding mode term to query a model value for. + * @param term The term. * - * @return String representation of rounding mode (RNA, RNE, RTN, RTP, RTZ). + * @return `true` if [term] is a floating-point +zero value. */ @JvmStatic - external fun bitwuzlaGetRmValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): String + external fun bitwuzlaTermIsFpValuePosZero(term: BitwuzlaTerm): Boolean /** - * Get the current model value of given array term. - * - * The string representation of `indices` and `values` can be queried via - * [bitwuzla_get_bv_value], [bitwuzla_get_fp_value], and - * [bitwuzla_get_rm_value]. + * Determine if a term is a floating-point value negative zero (-zero). * - * @param bitwuzla The Bitwuzla instance. - * @param term The term to query a model value for. + * @param term The term. * - * @see ArrayValue + * @return `true` if [term] is a floating-point value negative zero. */ @JvmStatic - external fun bitwuzlaGetArrayValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): ArrayValue + external fun bitwuzlaTermIsFpValueNegZero(term: BitwuzlaTerm): Boolean /** - * Get the current model value of given function term. - * - * The string representation of `args` and `values` can be queried via - * [bitwuzla_get_bv_value], [bitwuzla_get_fp_value], and - * [bitwuzla_get_rm_value]. + * Determine if a term is a floating-point positive infinity (+oo) value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The term to query a model value for. + * @param term The term. * - * @see FunValue + * @return `true` if [term] is a floating-point +oo value. */ @JvmStatic - external fun bitwuzlaGetFunValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): FunValue + external fun bitwuzlaTermIsFpValuePosInf(term: BitwuzlaTerm): Boolean /** - * Substitute a set of keys with their corresponding values in the given term. + * Determine if a term is a floating-point negative infinity (-oo) value. * - * @param bitwuzla The Bitwuzla instance. - * @param term The term in which the keys are to be substituted. - * @param mapKeys The keys. - * @param mapValues The mapped values. + * @param term The term. * - * @return The resulting term from this substitution. + * @return `true` if [term] is a floating-point -oo value. */ @JvmStatic - external fun bitwuzlaSubstituteTerm( - bitwuzla: Bitwuzla, - term: BitwuzlaTerm, - mapKeys: BitwuzlaTermArray, - mapValues: BitwuzlaTermArray - ): BitwuzlaTerm + external fun bitwuzlaTermIsFpValueNegInf(term: BitwuzlaTerm): Boolean /** - * Substitute a set of keys with their corresponding values in the set of given - * terms. + * Determine if a term is a floating-point NaN value. * - * @param bitwuzla The Bitwuzla instance. - * @param terms The terms in which the keys are to be substituted. - * @param mapKeys The keys. - * @param mapValues The mapped values. + * @param term The term. * - * @return The resulting terms from this substitution. + * @return `true` if [term] is a floating-point NaN value. */ @JvmStatic - external fun bitwuzlaSubstituteTerms( - bitwuzla: Bitwuzla, - terms: BitwuzlaTermArray, - mapKeys: BitwuzlaTermArray, - mapValues: BitwuzlaTermArray - ): BitwuzlaTermArray + external fun bitwuzlaTermIsFpValueNan(term: BitwuzlaTerm): Boolean /** - * Compute the hash value for a sort. + * Determine if a term is a rounding mode RNA value. * - * @param sort The sort. + * @param term The term. * - * @return The hash value of the sort. + * @return `true` if [term] is a rounding mode RNA value. */ @JvmStatic - external fun bitwuzlaSortHash(sort: BitwuzlaSort): Long + external fun bitwuzlaTermIsRmValueRna(term: BitwuzlaTerm): Boolean /** - * Get the kind of a term. + * Determine if a term is a rounding mode RNE value. * * @param term The term. * - * @return The kind of the given term. - * - * @see BitwuzlaKind + * @return `true` if [term] is a rounding mode RNE value. */ @JvmStatic - fun bitwuzlaTermGetBitwuzlaKind(term: BitwuzlaTerm): BitwuzlaKind = - bitwuzlaTermGetKind(term).let { BitwuzlaKind.fromValue(it) } - - @JvmStatic - external fun bitwuzlaTermGetKind(term: BitwuzlaTerm): Int + external fun bitwuzlaTermIsRmValueRne(term: BitwuzlaTerm): Boolean /** - * Get the child terms of a term. - * - * Returns `null` if given term does not have children. + * Determine if a term is a rounding mode RTN value. * * @param term The term. * - * @return The children of `term` as an array of terms. + * @return `true` if [term] is a rounding mode RTN value. */ @JvmStatic - external fun bitwuzlaTermGetChildren(term: BitwuzlaTerm): BitwuzlaTermArray + external fun bitwuzlaTermIsRmValueRtn(term: BitwuzlaTerm): Boolean /** - * Get the indices of an indexed term. - * - * Requires that given term is an indexed term. + * Determine if a term is a rounding mode RTP value. * * @param term The term. * - * @return The children of `term` as an array of terms. + * @return `true` if [term] is a rounding mode RTP value. */ @JvmStatic - external fun bitwuzlaTermGetIndices(term: BitwuzlaTerm): IntArray + external fun bitwuzlaTermIsRmValueRtp(term: BitwuzlaTerm): Boolean /** - * Get the size of a bit-vector sort. - * - * Requires that given sort is a bit-vector sort. + * Determine if a term is a rounding mode RTZ value. * - * @param sort The sort. + * @param term The term. * - * @return The size of the bit-vector sort. + * @return `true` if [term] is a rounding mode RTZ value. */ @JvmStatic - external fun bitwuzlaSortBvGetSize(sort: BitwuzlaSort): Int + external fun bitwuzlaTermIsRmValueRtz(term: BitwuzlaTerm): Boolean /** - * Get the exponent size of a floating-point sort. - * - * Requires that given sort is a floating-point sort. + * Get Boolean representation of given Boolean value term. * - * @param sort The sort. - * - * @return The exponent size of the floating-point sort. + * @param term The Boolean value term. + * @return Boolean representation of value [term]. */ @JvmStatic - external fun bitwuzlaSortFpGetExpSize(sort: BitwuzlaSort): Int + external fun bitwuzlaTermValueGetBool(term: BitwuzlaTerm): Boolean /** - * Get the significand size of a floating-point sort. + * Get string representation of Boolean, bit-vector, floating-point, or + * rounding mode value term. * - * Requires that given sort is a floating-point sort. + * This returns the raw value string (as opposed to [bitwuzlaTermToString], + * which returns the SMT-LIB v2 representation of a term). + * For example, this function returns "010" for a bit-vector value 2 of size + * 3, while [bitwuzlaTermToString] returns "#b010". * - * @param sort The sort. + * @note This uses default binary format for bit-vector value strings. * - * @return The significand size of the floating-point sort. + * @param term The value term. + * @return The string representation of the value term. + * + * @note Return value is valid until next [bitwuzlaTermValueGetStr] call. */ @JvmStatic - external fun bitwuzlaSortFpGetSigSize(sort: BitwuzlaSort): Int + external fun bitwuzlaTermValueGetStr(term: BitwuzlaTerm): String /** - * Get the index sort of an array sort. + * Get string representation of Boolean, bit-vector, floating-point, or + * rounding mode value term. String representations of bit-vector values are + * printed in the given base. * - * Requires that given sort is an array sort. + * This returns the raw value string (as opposed to [bitwuzlaTermToString], + * which returns the SMT-LIB v2 representation of a term). + * For example, this function returns "010" for a bit-vector value 2 of size + * 3, while [bitwuzlaTermToString] returns "#b010". * - * @param sort The sort. + * @param term The value term. + * @param base The base of the string representation of bit-vector values; `2` + * for binary, `10` for decimal, and `16` for hexadecimal. Always + * ignored for Boolean and RoundingMode values. + * @return String representation of the value term. * - * @return The index sort of the array sort. + * @note The returned string for floating-point values is always the binary + * IEEE-754 representation of the value (parameter `base` is ignored). + * Parameter `base` always configures the numeric base for bit-vector + * values, and for floating-point values in case of the tuple of strings + * instantiation. It is always ignored for Boolean and RoundingMode + * values. + * + * @note Return value is valid until next [bitwuzlaTermValueGetStrFmt] + * call. */ @JvmStatic - external fun bitwuzlaSortArrayGetIndex(sort: BitwuzlaSort): BitwuzlaSort + external fun bitwuzlaTermValueGetStrFmt(term: BitwuzlaTerm, /*uint8_t*/ base: Byte): String /** - * Get the element sort of an array sort. - * - * Requires that given sort is an array sort. - * - * @param sort The sort. + * Get representation of given rounding mode value term. + * @param term The rounding mode value term. + * @return The [BitwuzlaRoundingMode] representation of the given rounding mode value. + */ + @JvmStatic + fun bitwuzlaTermValueGetRoundingMode(term: BitwuzlaTerm): BitwuzlaRoundingMode = BitwuzlaRoundingMode.fromValue( + bitwuzlaTermValueGetRm(term) + ) + + @JvmStatic + private external fun bitwuzlaTermValueGetRm(term: BitwuzlaTerm): BitwuzlaRoundingModeNative + + /** + * Get the SMT-LIB v2 string representation of a term. + * @note This uses default binary format for bit-vector value strings. + * @return A string representation of the given term. + * @note The returned [String] is only valid until the next [bitwuzlaTermToString] call. + */ + @JvmStatic + external fun bitwuzlaTermToString(term: BitwuzlaTerm): String + + /** + * Get the SMT-LIB v2 string representation of a term. String representations + * of bit-vector values are printed in the given base. + * @param base The base of the string representation of bit-vector values; `2` + * for binary, `10` for decimal, and `16` for hexadecimal. Always + * ignored for Boolean and RoundingMode values. + * @return A string representation of the given term. * - * @return The element sort of the array sort. + * @note The returned char* pointer is only valid until the next [bitwuzlaTermToString] call. */ @JvmStatic - external fun bitwuzlaSortArrayGetElement(sort: BitwuzlaSort): BitwuzlaSort + external fun bitwuzlaTermToStringFmt(term: BitwuzlaTerm, /*uint8_t*/ base: Byte): String + + + /* -------------------------------------------------------------------------- */ + /* Bitwuzla */ + /* -------------------------------------------------------------------------- */ /** - * Get the domain sorts of a function sort. + * Create a new Bitwuzla instance. * - * The domain sorts are returned as an array of sorts. - * Requires that given sort is a function sort. + * The returned instance must be deleted via [bitwuzlaDelete]. * - * @param sort The sort. + * @param options The associated options (optional). + * @return A pointer to the created Bitwuzla instance. * - * @return The domain sorts of the function sort. + * @see [bitwuzlaDelete] */ @JvmStatic - external fun bitwuzlaSortFunGetDomainSorts(sort: BitwuzlaSort): BitwuzlaSortArray + external fun bitwuzlaNew(options: BitwuzlaOptionsNative): Bitwuzla /** - * Get the codomain sort of a function sort. + * Delete a Bitwuzla instance. * - * Requires that given sort is a function sort. + * The given instance must have been created via [bitwuzlaNew]. * - * @param sort The sort. + * @param bitwuzla The Bitwuzla instance to delete. * - * @return The codomain sort of the function sort. + * @see [bitwuzlaNew] */ @JvmStatic - external fun bitwuzlaSortFunGetCodomain(sort: BitwuzlaSort): BitwuzlaSort + external fun bitwuzlaDelete(bitwuzla: Bitwuzla) /** - * Get the arity of a function sort. + * Push context levels. * - * @param sort The sort. + * @param bitwuzla The Bitwuzla instance. + * @param nlevels The number of context levels to push. * - * @return The number of arguments of the function sort. + * @see [bitwuzlaSetOption] */ @JvmStatic - external fun bitwuzlaSortFunGetArity(sort: BitwuzlaSort): Int + external fun bitwuzlaPush(bitwuzla: Bitwuzla, nlevels: Long) /** - * Determine if two sorts are equal. + * Pop context levels. * - * @param sort0 The first sort. - * @param sort1 The second sort. + * @param bitwuzla The Bitwuzla instance. + * @param nlevels The number of context levels to pop. * - * @return True if the given sorts are equal. + * @see [bitwuzlaSetOption] */ @JvmStatic - external fun bitwuzlaSortIsEqual(sort0: BitwuzlaSort, sort1: BitwuzlaSort): Boolean + external fun bitwuzlaPop(bitwuzla: Bitwuzla, nlevels: Long) /** - * Determine if a sort is an array sort. - * - * @param sort The sort. + * Assert formula. * - * @return True if `sort` is an array sort. + * @param bitwuzla The Bitwuzla instance. + * @param term The formula to assert. */ @JvmStatic - external fun bitwuzlaSortIsArray(sort: BitwuzlaSort): Boolean + external fun bitwuzlaAssert(bitwuzla: Bitwuzla, term: BitwuzlaTerm) /** - * Determine if a sort is a bit-vector sort. - * - * @param sort The sort. - * - * @return True if `sort` is a bit-vector sort. + * Get the set of currently asserted formulas. + * @return The asserted formulas. + * @return An array with the set of asserted formulas. Only + * valid until the next [bitwuzlaGetAssertions] call. */ @JvmStatic - external fun bitwuzlaSortIsBv(sort: BitwuzlaSort): Boolean + external fun bitwuzlaGetAssertions(bitwuzla: Bitwuzla): BitwuzlaTermArray /** - * Determine if a sort is a floating-point sort. + * Determine if an assumption is an unsat assumption. * - * @param sort The sort. + * Unsat assumptions are assumptions that force an input formula to become + * unsatisfiable. Unsat assumptions handling in Bitwuzla is analogous to + * failed assumptions in MiniSAT. + * + * Requires that the last [bitwuzlaCheckSat] query returned `::BITWUZLA_UNSAT`. + * + * @param bitwuzla The Bitwuzla instance. + * @param term The assumption to check for. + * + * @return `true` if given assumption is an unsat assumption. * - * @return True if `sort` is a floating-point sort. + * @see bitwuzlaSetOption + * @see bitwuzlaCheckSat */ @JvmStatic - external fun bitwuzlaSortIsFp(sort: BitwuzlaSort): Boolean + external fun bitwuzlaIsUnsatAssumption(bitwuzla: Bitwuzla, term: BitwuzlaTerm): Boolean /** - * Determine if a sort is a function sort. + * Get the set of unsat assumptions. * - * @param sort The sort. + * Unsat assumptions are assumptions that force an input formula to become + * unsatisfiable. Unsat assumptions handling in Bitwuzla is analogous to + * failed assumptions in MiniSAT. + * + * Requires that the last `bitwuzla_check_sat()` query returned [BitwuzlaResult.BITWUZLA_UNSAT]. + * + * @param bitwuzla The Bitwuzla instance. + * + * @return An array with unsat assumptions. Only valid until + * the next [bitwuzlaGetUnsatAssumptions] call. * - * @return True if `sort` is a function sort. + * @see bitwuzlaSetOption + * @see bitwuzlaCheckSat */ @JvmStatic - external fun bitwuzlaSortIsFun(sort: BitwuzlaSort): Boolean - + external fun bitwuzlaGetUnsatAssumptions(bitwuzla: Bitwuzla): BitwuzlaTermArray /** - * Determine if a sort is a Roundingmode sort. + * Get the unsat core (unsat assertions). * - * @param sort The sort. + * The unsat core consists of the set of assertions that force an input formula + * to become unsatisfiable. + * + * Requires that the last [bitwuzlaCheckSat] query returned [BitwuzlaResult.BITWUZLA_UNSAT]. * - * @return True if `sort` is a Roundingmode sort. + * @param bitwuzla The Bitwuzla instance. + * + * @return An array with unsat assertions. Only valid until + * the next [bitwuzlaGetUnsatCore] call. + * + * @see bitwuzlaAssert + * @see bitwuzlaCheckSat */ @JvmStatic - external fun bitwuzlaSortIsRm(sort: BitwuzlaSort): Boolean + external fun bitwuzlaGetUnsatCore(bitwuzla: Bitwuzla): BitwuzlaTermArray /** - * Compute the hash value for a term. + * Simplify the current input formula. * - * @param term The term. + * @param bitwuzla The Bitwuzla instance. * - * @return The hash value of the term. + * @note Each call to [bitwuzlaCheckSat] and [bitwuzlaCheckSatAssuming] + * simplifies the input formula as a preprocessing step. It is not + * necessary to call this function explicitly in the general case. + * + * @see bitwuzlaAssert */ @JvmStatic - external fun bitwuzlaTermHash(term: BitwuzlaTerm): Long + external fun bitwuzlaSimplify(bitwuzla: Bitwuzla) /** - * Determine if a term is an indexed term. + * Check satisfiability of current input formula. * - * @param term The term. + * An input formula consists of assertions added via [bitwuzlaAssert]. + * The search for a solution can by guided by additionally making assumptions + * (see [bitwuzlaCheckSatAssuming]). + * + * @note Assertions and assumptions are combined via Boolean and. + * + * @param bitwuzla The Bitwuzla instance. + * + * @return [BitwuzlaResult.BITWUZLA_SAT] if the input formula is satisfiable and + * [BitwuzlaResult.BITWUZLA_UNSAT] if it is unsatisfiable, + * and [BitwuzlaResult.BITWUZLA_UNKNOWN] when neither satisfiability nor unsatisfiability was determined. + * This can happen when [bitwuzla] was terminated via a termination callback. * - * @return True if `term` is an indexed term. + * @see bitwuzlaAssert + * @see bitwuzlaSetOption + * @see BitwuzlaResult */ @JvmStatic - external fun bitwuzlaTermIsIndexed(term: BitwuzlaTerm): Boolean + fun bitwuzlaCheckSat(bitwuzla: Bitwuzla): BitwuzlaResult = BitwuzlaResult.fromValue( + bitwuzlaCheckSatNative(bitwuzla) + ) /** - * Get the associated Bitwuzla instance of a term. - * - * @param term The term. + @return `::BITWUZLA_SAT` if the input formula is satisfiable and + * `::BITWUZLA_UNSAT` if it is unsatisfiable, and `::BITWUZLA_UNKNOWN` + * when neither satisfiability nor unsatisfiability was determined. + * This can happen when `bitwuzla` was terminated via a termination + * callback. * - * @return The associated Bitwuzla instance. + * *note*: api call: bitwuzla_check_sat */ @JvmStatic - external fun bitwuzlaTermGetBitwuzla(term: BitwuzlaTerm): Bitwuzla + external fun bitwuzlaCheckSatNative(bitwuzla: Bitwuzla): BitwuzlaResultNative /** - * Get the sort of a term. + * Check satisfiability of current input formula wrt to the given set of + * assumptions. * - * @param term The term. + * An input formula consists of assertions added via [bitwuzlaAssert]. + * The search for a solution can by guided by additionally making assumptions + * (the given set of assumptions [args]). * - * @return The sort of the term. - */ - @JvmStatic - external fun bitwuzlaTermGetSort(term: BitwuzlaTerm): BitwuzlaSort - - /** - * Get the index sort of an array term. + * @note Assertions and assumptions are combined via Boolean and. * - * Requires that given term is an array or an array store term. + * @param bitwuzla The Bitwuzla instance. + * @param args The assumptions. * - * @param term The term. + * @return [BitwuzlaResult.BITWUZLA_SAT] if the input formula is satisfiable and [BitwuzlaResult.BITWUZLA_UNSAT] + * if it is unsatisfiable, and [BitwuzlaResult.BITWUZLA_UNKNOWN] + * when neither satisfiability nor unsatisfiability was determined. + * This can happen when [bitwuzla] was terminated via a termination + * callback. * - * @return The index sort of the array term. + * @see bitwuzlaAssert + * @see bitwuzlaSetOption + * @see BitwuzlaResult */ @JvmStatic - external fun bitwuzlaTermArrayGetIndexSort(term: BitwuzlaTerm): BitwuzlaSort + fun bitwuzlaCheckSatAssuming(bitwuzla: Bitwuzla, args: BitwuzlaTermArray) = BitwuzlaResult.fromValue( + bitwuzlaCheckSatAssumingNative(bitwuzla, args) + ) /** - * Get the element sort of an array term. - * - * Requires that given term is an array or an array store term. - * - * @param term The term. - * - * @return The element sort of the array term. + * *note:* api call: bitwuzla_check_sat_assuming */ @JvmStatic - external fun bitwuzlaTermArrayGetElementSort(term: BitwuzlaTerm): BitwuzlaSort + external fun bitwuzlaCheckSatAssumingNative(bitwuzla: Bitwuzla, args: BitwuzlaTermArray): BitwuzlaResultNative + + fun bitwuzlaCheckSatWithTimeout( + bitwuzla: Bitwuzla, + args: BitwuzlaTermArray, + timeout: Long + ) = BitwuzlaResult.fromValue(bitwuzlaCheckSatTimeout(bitwuzla, args, timeout)) + + @JvmStatic + external fun bitwuzlaCheckSatTimeout( + bitwuzla: Bitwuzla, + args: BitwuzlaTermArray, + timeout: Long + ): BitwuzlaResultNative /** - * Get the domain sorts of a function term. - * - * The domain sorts are returned as an array of sorts of size `size. - * Requires that given term is an uninterpreted function, a lambda term, an - * array store term, or an ite term over function terms. + * Terminates current check-sat call * - * @param term The term. - * - * @return The domain sorts of the function term. + * @see bitwuzlaCheckSat + * @see bitwuzlaCheckSatAssuming */ @JvmStatic - external fun bitwuzlaTermFunGetDomainSorts(term: BitwuzlaTerm): BitwuzlaSortArray + external fun bitwuzlaForceTerminate(bitwuzla: Bitwuzla) /** - * Get the codomain sort of a function term. + * Get a term representing the model value of a given term. * - * Requires that given term is an uninterpreted function, a lambda term, an - * array store term, or an ite term over function terms. + * Requires that the last [bitwuzlaCheckSat] query returned [BitwuzlaResult.BITWUZLA_SAT]. * - * @param term The term. + * @param bitwuzla The Bitwuzla instance. + * @param term The term to query a model value for. * - * @return The codomain sort of the function term. + * @return A term representing the model value of term [term]. + * + * @see bitwuzlaCheckSat */ @JvmStatic - external fun bitwuzlaTermFunGetCodomainSort(term: BitwuzlaTerm): BitwuzlaSort + external fun bitwuzlaGetValue(bitwuzla: Bitwuzla, term: BitwuzlaTerm): BitwuzlaTerm + + @JvmStatic + external fun bitwuzlaGetBvValueUInt64(term: BitwuzlaTerm): Long + + @JvmStatic + external fun bitwuzlaGetBvValueString(term: BitwuzlaTerm): String + + @JvmStatic + external fun bitwuzlaGetFpValue(term: BitwuzlaTerm): FpValue + + /* -------------------------------------------------------------------------- */ + /* Sort creation */ + /* -------------------------------------------------------------------------- */ /** - * Get the bit-width of a bit-vector term. - * - * Requires that given term is a bit-vector term. + * Create an array sort. * - * @param term The term. + * @param index The index sort of the array sort. + * @param element The element sort of the array sort. + * @return An array sort which maps sort [index] to sort [element]. * - * @return The bit-width of the bit-vector term. + * @see bitwuzlaSortIsArray + * @see bitwuzlaSortArrayGetIndex + * @see bitwuzlaSortArrayGetElement + * @see bitwuzlaTermIsArray + * @see bitwuzlaTermArrayGetIndexSort + * @see bitwuzlaTermArrayGetElementSort */ @JvmStatic - external fun bitwuzlaTermBvGetSize(term: BitwuzlaTerm): Int + external fun bitwuzlaMkArraySort(index: BitwuzlaSort, element: BitwuzlaSort): BitwuzlaSort /** - * Get the bit-width of the exponent of a floating-point term. - * - * Requires that given term is a floating-point term. - * - * @param term The term. - * - * @return The bit-width of the exponent of the floating-point term. + * Create a Boolean sort. + * @return A Boolean sort. */ @JvmStatic - external fun bitwuzlaTermFpGetExpSize(term: BitwuzlaTerm): Int + external fun bitwuzlaMkBoolSort(): BitwuzlaSort /** - * Get the bit-width of the significand of a floating-point term. - * - * Requires that given term is a floating-point term. + * Create a bit-vector sort of given size. * - * @param term The term. + * @param size The size of the bit-vector sort. + * @return A bit-vector sort of given size. * - * @return The bit-width of the significand of the floating-point term. + * @see bitwuzlaSortIsBv + * @see bitwuzlaSortBvGetSize + * @see bitwuzlaTermIsBv + * @see bitwuzlaTermBvGetSize */ @JvmStatic - external fun bitwuzlaTermFpGetSigSize(term: BitwuzlaTerm): Int + external fun bitwuzlaMkBvSort(size: Long): BitwuzlaSort + + @JvmStatic + fun bitwuzlaMkBvSort(size: Int): BitwuzlaSort = bitwuzlaMkBvSort(size.toLong()) /** - * Get the arity of a function term. - * - * Requires that given term is a function term. + * Create a floating-point sort of given exponent and significand size. * - * @param term The term. + * @param expSize The size of the exponent. + * @param sigSize The size of the significand (including sign bit). + * @return A floating-point sort of given format. * - * @return The arity of the function term. + * @see bitwuzlaSortIsFp + * @see bitwuzlaSortFpGetExpSize + * @see bitwuzlaSortFpGetSigSize + * @see bitwuzlaTermIsFp + * @see bitwuzlaTermFpGetExpSize + * @see bitwuzlaTermFpGetSigSize */ @JvmStatic - external fun bitwuzlaTermFunGetArity(term: BitwuzlaTerm): Int + external fun bitwuzlaMkFpSort(expSize: Long, sigSize: Long): BitwuzlaSort /** - * Get the symbol of a term. + * Create a function sort. * - * @param term The term. + * @param domain The domain sorts (the sorts of the arguments). + * @param codomain The codomain sort (the sort of the return value). + * @return A function sort of given domain and codomain sorts. * - * @return The symbol of `term`. `null` if no symbol is defined. + * @see bitwuzlaSortIsFun + * @see bitwuzlaSortFunGetArity + * @see bitwuzlaSortFunGetDomainSorts + * @see bitwuzlaSortFunGetCodomain + * @see bitwuzlaTermIsFun + * @see bitwuzlaTermFunGetArity + * @see bitwuzlaTermFunGetDomainSorts + * @see bitwuzlaTermFunGetCodomainSort */ @JvmStatic - external fun bitwuzlaTermGetSymbol(term: BitwuzlaTerm): String? + external fun bitwuzlaMkFunSort(domain: BitwuzlaSortArray, codomain: BitwuzlaSort): BitwuzlaSort /** - * Set the symbol of a term. - * - * @param term The term. - * @param symbol The symbol. + * Create a Roundingmode sort. + * @return A RoundingMode sort. + * @see bitwuzlaSortIsRm + * @see bitwuzlaTermIsRm */ @JvmStatic - external fun bitwuzlaTermSetSymbol(term: BitwuzlaTerm, symbol: String) + external fun bitwuzlaMkRmSort(): BitwuzlaSort /** - * Determine if the sorts of two terms are equal. - * - * @param term0 The first term. - * @param term1 The second term. - * - * @return True if the sorts of `term0` and `term1` are equal. + * Create an uninterpreted sort. + * @param symbol The symbol of the sort. May be `null`. + * @return A uninterpreted sort. + * @see bitwuzlaSortIsUninterpreted + * @see bitwuzlaTermIsUninterpreted */ @JvmStatic - external fun bitwuzlaTermIsEqualSort(term0: BitwuzlaTerm, term1: BitwuzlaTerm): Boolean + external fun bitwuzlaMkUninterpretedSort(symbol: String?): BitwuzlaSort + + + /* -------------------------------------------------------------------------- */ + /* Term creation */ + /* -------------------------------------------------------------------------- */ /** - * Determine if a term is an array term. - * - * @param term The term. - * - * @return True if `term` is an array term. + * Create a true value. + * @return A term representing true. */ @JvmStatic - external fun bitwuzlaTermIsArray(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkTrue(): BitwuzlaTerm /** - * Determine if a term is a constant. - * - * @param term The term. - * - * @return True if `term` is a constant. + * Create a false value. + * @return A term representing false. */ @JvmStatic - external fun bitwuzlaTermIsConst(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFalse(): BitwuzlaTerm /** - * Determine if a term is a function. + * Create a bit-vector value zero. * - * @param term The term. + * @param sort The sort of the value. + * @return A term representing the bit-vector value 0 of given sort. * - * @return True if `term` is a function. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsFun(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvZero(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a variable. + * Create a bit-vector value one. * - * @param term The term. + * @param sort The sort of the value. + * @return A term representing the bit-vector value 1 of given sort. * - * @return True if `term` is a variable. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsVar(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvOne(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a bound variable. - * - * @param term The term. + * Create a bit-vector value where all bits are set to 1. * - * @return True if `term` is a variable and bound. + * @param sort The sort of the value. + * @return A term representing the bit-vector value of given sort where all bits are set to 1. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsBoundVar(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvOnes(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a value. - * - * @param term The term. + * Create a bit-vector minimum signed value. * - * @return True if `term` is a value. + * @param sort The sort of the value. + * @return A term representing the bit-vector value of given sort where the MSB + * is set to 1 and all remaining bits are set to 0. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsValue(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvMinSigned(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a bit-vector value. - * - * @param term The term. + * Create a bit-vector maximum signed value. * - * @return True if `term` is a bit-vector value. + * @param sort The sort of the value. + * @return A term representing the bit-vector value of given sort where the MSB + * is set to 0 and all remaining bits are set to 1. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsBvValue(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvMaxSigned(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a floating-point value. - * - * @param term The term. + * Create a floating-point positive zero value (SMT-LIB: `+zero`). * - * @return True if `term` is a floating-point value. + * @param sort The sort of the value. + * @return A term representing the floating-point positive zero value of given floating-point sort. + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsFpValue(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpPosZero(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a rounding mode value. - * - * @param term The term. + * Create a floating-point negative zero value (SMT-LIB: `-zero`). * - * @return True if `term` is a rounding mode value. + * @param sort The sort of the value. + * @return A term representing the floating-point negative zero value of given floating-point sort. + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsRmValue(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpNegZero(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a bit-vector term. - * - * @param term The term. + * Create a floating-point positive infinity value (SMT-LIB: `+oo`). * - * @return True if `term` is a bit-vector term. + * @param sort The sort of the value. + * @return A term representing the floating-point positive infinity value of given floating-point sort. + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsBv(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpPosInf(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a floating-point term. - * - * @param term The term. + * Create a floating-point negative infinity value (SMT-LIB: `-oo`). * - * @return True if `term` is a floating-point term. + * @param sort The sort of the value. + * @return A term representing the floating-point negative infinity value of given floating-point sort. + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsFp(term: BitwuzlaTerm): Boolean - + external fun bitwuzlaMkFpNegInf(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a rounding mode term. - * - * @param term The term. + * Create a floating-point NaN value. * - * @return True if `term` is a rounding mode term. + * @param sort The sort of the value. + * @return A term representing the floating-point NaN value of given floating-point sort. + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsRm(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpNan(sort: BitwuzlaSort): BitwuzlaTerm /** - * Determine if a term is a bit-vector value representing zero. + * Create a bit-vector value from its string representation. * - * @param term The term. + * Parameter [base] determines the base of the string representation. * - * @return True if `term` is a bit-vector zero value. - */ - @JvmStatic - external fun bitwuzlaTermIsBvValueZero(term: BitwuzlaTerm): Boolean - - /** - * Determine if a term is a bit-vector value representing one. + * @note Given value must fit into a bit-vector of given size (sort). * - * @param term The term. + * @param sort The sort of the value. + * @param value A string representing the value. + * @param base The base in which the string is given; `2` for binary, `10` for decimal, and `16` for hexadecimal. + * + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE], representing the bit-vector value + * of given sort. * - * @return True if `term` is a bit-vector one value. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsBvValueOne(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkBvValue(sort: BitwuzlaSort, value: String, /*uint8_t*/ base: BitwuzlaBVBase) = bitwuzlaMkBvValue( + sort, value, base.nativeValue + ) + + @JvmStatic + private external fun bitwuzlaMkBvValue(sort: BitwuzlaSort, value: String, /*uint8_t*/ base: Byte): BitwuzlaTerm /** - * Determine if a term is a bit-vector value with all bits set to one. + * Create a bit-vector value from its unsigned integer representation. * - * @param term The term. + * @note Given value must fit into a bit-vector of given size (sort). + * + * @param sort The sort of the value. + * @param value The unsigned integer representation of the bit-vector value. + * + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE], representing the bit-vector value + * of given sort. * - * @return True if `term` is a bit-vector value with all bits set to one. + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsBvValueOnes(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvValueUint64(sort: BitwuzlaSort, value: Long): BitwuzlaTerm /** - * Determine if a term is a bit-vector minimum signed value. + * Create a bit-vector value from its signed integer representation. * - * @param term The term. + * @note Given value must fit into a bit-vector of given size (sort). * - * @return True if `term` is a bit-vector value with the most significant bit - * set to 1 and all other bits set to 0. + * @param sort The sort of the value. + * @param value The unsigned integer representation of the bit-vector value. + * + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE], representing the bit-vector value of given sort. + * + * @see bitwuzlaMkBvSort */ @JvmStatic - external fun bitwuzlaTermIsBvValueMinSigned(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkBvValueInt64(sort: BitwuzlaSort, value: Long): BitwuzlaTerm /** - * Determine if a term is a bit-vector maximum signed value. + * Create a floating-point value from its IEEE 754 standard representation + * given as three bit-vector values representing the sign bit, the exponent and the significand. * - * @param term The term. + * @param bvSign The sign bit. + * @param bvExponent The exponent bit-vector value. + * @param bvSignificand The significand bit-vector value. * - * @return True if `term` is a bit-vector value with the most significant bit - * set to 0 and all other bits set to 1. + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE], representing the floating-point value. */ @JvmStatic - external fun bitwuzlaTermIsBvValueMaxSigned(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpValue( + bvSign: BitwuzlaTerm, + bvExponent: BitwuzlaTerm, + bvSignificand: BitwuzlaTerm + ): BitwuzlaTerm /** - * Determine if a term is a floating-point positive zero (+zero) value. + * Create a floating-point value from its real representation, given as a + * decimal string, with respect to given rounding mode. * - * @param term The term. + * @note Given rounding mode may be an arbitrary, non-value rounding mode term. + * If it is a value, the returned term will be a floating-point value, + * else a non-value floating-point term. + * + * @param sort The sort of the value. + * @param rm The rounding mode. + * @param real The decimal string representing a real value. * - * @return True if `term` is a floating-point +zero value. + * @return A floating-point representation of the given real string. If [rm] + * is of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE] the floating-point will be of kind + * [BitwuzlaKind.BITWUZLA_KIND_VALUE], else it will be a non-value term. + * + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsFpValuePosZero(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpFromReal(sort: BitwuzlaSort, rm: BitwuzlaTerm, real: String): BitwuzlaTerm /** - * Determine if a term is a floating-point value negative zero (-zero). + * Create a floating-point value from its rational representation, given as + * two decimal strings representing the numerator and denominator, with respect + * to given rounding mode. * - * @param term The term. + * @note Given rounding mode may be an arbitrary, non-value rounding mode term. + * If it is a value, the returned term will be a floating-point value, + * else a non-value floating-point term. * - * @return True if `term` is a floating-point value negative zero. + * @param sort The sort of the value. + * @param rm The rounding mode. + * @param num The decimal string representing the numerator. + * @param den The decimal string representing the denominator. + * + * @return A floating-point representation of the given rational string. If + * [rm] is of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE] the floating-point will be of + * kind [BitwuzlaKind.BITWUZLA_KIND_VALUE], else it will be a non-value term. + * + * @see bitwuzlaMkFpSort */ @JvmStatic - external fun bitwuzlaTermIsFpValueNegZero(term: BitwuzlaTerm): Boolean + external fun bitwuzlaMkFpFromRational(sort: BitwuzlaSort, rm: BitwuzlaTerm, num: String, den: String): BitwuzlaTerm /** - * Determine if a term is a floating-point positive infinity (+oo) value. + * Create a rounding mode value. * - * @param term The term. + * @param rm The rounding mode value. * - * @return True if `term` is a floating-point +oo value. + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VALUE], representing the rounding mode value. + * + * @see BitwuzlaRoundingMode */ @JvmStatic - external fun bitwuzlaTermIsFpValuePosInf(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkRmValue(rm: BitwuzlaRoundingMode): BitwuzlaTerm = bitwuzlaMkRmValue(rm.value) + + @JvmStatic + private external fun bitwuzlaMkRmValue(rm: BitwuzlaRoundingModeNative): BitwuzlaTerm /** - * Determine if a term is a floating-point negative infinity (-oo) value. + * Create a term of given kind with one argument term. * - * @param term The term. + * @param kind The operator kind. + * @param arg The argument to the operator. * - * @return True if `term` is a floating-point -oo value. + * @return A term representing an operation of given kind. + * + * @see [BitwuzlaKind] */ @JvmStatic - external fun bitwuzlaTermIsFpValueNegInf(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTerm(kind: BitwuzlaKind, arg: BitwuzlaTerm): BitwuzlaTerm = bitwuzlaMkTerm1(kind.value, arg) + + @JvmStatic + private external fun bitwuzlaMkTerm1(kind: BitwuzlaKindNative, arg: BitwuzlaTerm): BitwuzlaTerm /** - * Determine if a term is a floating-point NaN value. + * Create a term of given kind with two argument terms. * - * @param term The term. + * @param kind The operator kind. + * @param arg0 The first argument to the operator. + * @param arg1 The second argument to the operator. + * + * @return A term representing an operation of given kind. * - * @return True if `term` is a floating-point NaN value. + * @see [BitwuzlaKind] */ @JvmStatic - external fun bitwuzlaTermIsFpValueNan(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTerm(kind: BitwuzlaKind, arg0: BitwuzlaTerm, arg1: BitwuzlaTerm): BitwuzlaTerm = bitwuzlaMkTerm2( + kind.value, arg0, arg1 + ) + + @JvmStatic + private external fun bitwuzlaMkTerm2(kind: BitwuzlaKindNative, arg0: BitwuzlaTerm, arg1: BitwuzlaTerm): BitwuzlaTerm /** - * Determine if a term is a rounding mode RNA value. + * Create a term of given kind with three argument terms. * - * @param term The term. + * @param kind The operator kind. + * @param arg0 The first argument to the operator. + * @param arg1 The second argument to the operator. + * @param arg2 The third argument to the operator. + * + * @return A term representing an operation of given kind. * - * @return True if `term` is a roundindg mode RNA value. + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaTermIsRmValueRna(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTerm( + kind: BitwuzlaKind, + arg0: BitwuzlaTerm, + arg1: BitwuzlaTerm, + arg2: BitwuzlaTerm + ): BitwuzlaTerm = bitwuzlaMkTerm3(kind.value, arg0, arg1, arg2) + + @JvmStatic + private external fun bitwuzlaMkTerm3( + kind: BitwuzlaKindNative, + arg0: BitwuzlaTerm, + arg1: BitwuzlaTerm, + arg2: BitwuzlaTerm + ): BitwuzlaTerm /** - * Determine if a term is a rounding mode RNE value. + * Create a term of given kind with the given argument terms. * - * @param term The term. + * @param kind The operator kind. + * @param args The argument terms. + * + * @return A term representing an operation of given kind. * - * @return True if `term` is a rounding mode RNE value. + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaTermIsRmValueRne(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTerm(kind: BitwuzlaKind, args: BitwuzlaTermArray): BitwuzlaTerm = bitwuzlaMkTerm(kind.value, args) + + @JvmStatic + private external fun bitwuzlaMkTerm(kind: BitwuzlaKindNative, args: BitwuzlaTermArray): BitwuzlaTerm /** - * Determine if a term is a rounding mode RTN value. + * Create an indexed term of given kind with one argument term and one index. * - * @param term The term. + * @param kind The operator kind. + * @param arg The argument term. + * @param idx The index. + * + * @return A term representing an indexed operation of given kind. * - * @return True if `term` is a rounding mode RTN value. + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaTermIsRmValueRtn(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTermIndexed(kind: BitwuzlaKind, arg: BitwuzlaTerm, idx: Long): BitwuzlaTerm = bitwuzlaMkTerm1Indexed1( + kind.value, arg, idx + ) + + @JvmStatic + private external fun bitwuzlaMkTerm1Indexed1(kind: BitwuzlaKindNative, arg: BitwuzlaTerm, idx: Long): BitwuzlaTerm /** - * Determine if a term is a rounding mode RTP value. + * Create an indexed term of given kind with one argument term and two indices. * - * @param term The term. + * @param kind The operator kind. + * @param arg The argument term. + * @param idx0 The first index. + * @param idx1 The second index. + * + * @return A term representing an indexed operation of given kind. * - * @return True if `term` is a rounding mode RTP value. + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaTermIsRmValueRtp(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTermIndexed( + kind: BitwuzlaKind, + arg: BitwuzlaTerm, + idx0: Long, + idx1: Long + ): BitwuzlaTerm = bitwuzlaMkTerm1Indexed2(kind.value, arg, idx0, idx1) + + @JvmStatic + private external fun bitwuzlaMkTerm1Indexed2( + kind: BitwuzlaKindNative, + arg: BitwuzlaTerm, + idx0: Long, + idx1: Long + ): BitwuzlaTerm /** - * Determine if a term is a rounding mode RTZ value. + * Create an indexed term of given kind with two argument terms and one index. * - * @param term The term. + * @param kind The operator kind. + * @param arg0 The first argument term. + * @param arg1 The second argument term. + * @param idx The index. + * + * @return A term representing an indexed operation of given kind. * - * @return True if `term` is a rounding mode RTZ value. + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaTermIsRmValueRtz(term: BitwuzlaTerm): Boolean + fun bitwuzlaMkTerm2Indexed( + kind: BitwuzlaKind, + arg0: BitwuzlaTerm, + arg1: BitwuzlaTerm, + idx: Long + ): BitwuzlaTerm = bitwuzlaMkTerm2Indexed1(kind.value, arg0, arg1, idx) + + @JvmStatic + private external fun bitwuzlaMkTerm2Indexed1( + kind: BitwuzlaKindNative, + arg0: BitwuzlaTerm, + arg1: BitwuzlaTerm, + idx: Long + ): BitwuzlaTerm /** - * Determine if a term is a constant array. + * Create an indexed term of given kind with two argument terms and two indices. * - * @param term The term. + * @param kind The operator kind. + * @param arg0 The first argument term. + * @param arg1 The second argument term. + * @param idx0 The first index. + * @param idx1 The second index. * - * @return True if `term` is a constant array. + * @return A term representing an indexed operation of given kind. + * + * @see BitwuzlaKind */ @JvmStatic - external fun bitwuzlaTermIsConstArray(term: BitwuzlaTerm): Boolean - - /** - * Create Bv value of width [bvWidth] using bits from [value] array. - * Array should match Bv bits representation. array[0] = bv[0:31], array[1] = bv[32:64], ... - * */ - @JvmStatic - external fun bitwuzlaMkBvValueUint32Array(bitwuzla: Bitwuzla, bvWidth: Int, value: IntArray): BitwuzlaTerm + fun bitwuzlaMkTermIndexed( + kind: BitwuzlaKind, + arg0: BitwuzlaTerm, + arg1: BitwuzlaTerm, + idx0: Long, + idx1: Long + ): BitwuzlaTerm = bitwuzlaMkTerm2Indexed2(kind.value, arg0, arg1, idx0, idx1) - /** - * Get bv const bits. Only safe if [bitwuzlaTermIsBvValue] is true for [term] and - * bv width <= 32. - * */ @JvmStatic - external fun bitwuzlaBvConstNodeGetBitsUInt32(bitwuzla: Bitwuzla, term: BitwuzlaTerm): Int + private external fun bitwuzlaMkTerm2Indexed2( + kind: BitwuzlaKindNative, + arg0: BitwuzlaTerm, + arg1: BitwuzlaTerm, + idx0: Long, + idx1: Long + ): BitwuzlaTerm /** - * Get bv const bits. Only safe if [bitwuzlaTermIsBvValue] is true for [term]. - * Returned array matches Bv bits representation. array[0] = bv[0:31], array[1] = bv[32:64], ... - * */ + * Create an indexed term of given kind with the given argument terms and indices. + * + * @param kind The operator kind. + * @param args The argument terms. + * @param idxs The indices. + * + * @return A term representing an indexed operation of given kind. + * + * @see BitwuzlaKind + */ @JvmStatic - external fun bitwuzlaBvConstNodeGetBitsUIntArray(bitwuzla: Bitwuzla, term: BitwuzlaTerm): IntArray + fun bitwuzlaMkTermIndexed( + kind: BitwuzlaKind, + args: BitwuzlaTermArray, + idxs: LongArray + ): BitwuzlaTerm = bitwuzlaMkTermIndexed(kind.value, args, idxs) - /** - * Get fp const bits. Only safe if [bitwuzlaTermIsFpValue] is true for [term] and - * bits count <= 32. - * */ @JvmStatic - external fun bitwuzlaFpConstNodeGetBitsUInt32(bitwuzla: Bitwuzla, term: BitwuzlaTerm): Int + private external fun bitwuzlaMkTermIndexed( + kind: BitwuzlaKindNative, + args: BitwuzlaTermArray, + idxs: LongArray + ): BitwuzlaTerm /** - * Get fp const bits. Only safe if [bitwuzlaTermIsFpValue] is true for [term]. - * Returned array matches Fp bits representation. array[0] = fp[0:31], array[1] = fp[32:64], ... - * */ + * Create a (first-order) constant of given sort with given symbol. + * + * @param sort The sort of the constant. + * @param symbol The symbol of the constant. + * + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_CONSTANT], representing the constant. + * + * @see bitwuzlaMkArraySort + * @see bitwuzlaMkBoolSort + * @see bitwuzlaMkBvSort + * @see bitwuzlaMkFpSort + * @see bitwuzlaMkFunSort + * @see bitwuzlaMkRmSort + */ @JvmStatic - external fun bitwuzlaFpConstNodeGetBitsUIntArray(bitwuzla: Bitwuzla, term: BitwuzlaTerm): IntArray + external fun bitwuzlaMkConst(sort: BitwuzlaSort, symbol: String): BitwuzlaTerm /** - * Print a model for the current input formula. + * Create a one-dimensional constant array of given sort, initialized with + * given value. * - * Requires that the last [bitwuzlaCheckSat] query returned - * [BitwuzlaResult.BITWUZLA_SAT]. + * @param sort The sort of the array. + * @param value The term to initialize the elements of the array with. * - * @param bitwuzla The Bitwuzla instance. - * @param format The output format for printing the model. Either `"btor"` for - * the BTOR format, or `"smt2"` for the SMT-LIB v2 format. - * @param outputFilePath The file to print the model to. + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_CONST_ARRAY], representing a constant array of given sort. * - * @see bitwuzlaCheckSat + * @see bitwuzlaMkArraySort */ @JvmStatic - external fun bitwuzlaPrintModel(bitwuzla: Bitwuzla, format: String, outputFilePath: String) + external fun bitwuzlaMkConstArray(sort: BitwuzlaSort, value: BitwuzlaTerm): BitwuzlaTerm /** - * Print the current input formula. + * Create a variable of given sort with given symbol. * - * Requires that incremental solving is not enabled. + * @note This creates a variable to be bound by quantifiers or lambdas. * - * @param bitwuzla The Bitwuzla instance. - * @param format The output format for printing the formula. Either - * `"aiger_ascii"` for the AIGER ascii format, `"aiger_binary"` - * for the binary AIGER format, `"btor"` for the BTOR format, or - * `"smt2"` for the SMT-LIB v2 format. - * @param outputFilePath The file to print the formula to. + * @param sort The sort of the variable. + * @param symbol The symbol of the variable. + * + * @return A term of kind [BitwuzlaKind.BITWUZLA_KIND_VARIABLE], representing the variable. + * + * @see bitwuzlaMkBoolSort + * @see bitwuzlaMkBvSort + * @see bitwuzlaMkFpSort + * @see bitwuzlaMkFunSort + * @see bitwuzlaMkRmSort */ @JvmStatic - external fun bitwuzlaDumpFormula(bitwuzla: Bitwuzla, format: String, outputFilePath: String) + external fun bitwuzlaMkVar(sort: BitwuzlaSort, symbol: String): BitwuzlaTerm + + + /* -------------------------------------------------------------------------- */ + /* Term substitution */ + /* -------------------------------------------------------------------------- */ /** - * Print sort. + * Substitute a set of keys with their corresponding values in the given term. * - * @param sort The sort. - * @param format The output format for printing the term. Either `"btor"` for - * the BTOR format, or `"smt2"` for the SMT-LIB v2 format. Note - * for the `"btor"` this function won't do anything since BTOR - * sorts are printed when printing the term via - * bitwuzla_term_dump. + * @param term The term in which the keys are to be substituted. + * @param mapKeys The keys. + * @param mapValues The mapped values. + * + * @return The resulting term from this substitution. */ @JvmStatic - external fun bitwuzlaSortDump(sort: BitwuzlaSort, format: String): String + external fun bitwuzlaSubstituteTerm( + term: BitwuzlaTerm, + mapKeys: BitwuzlaTermArray, + mapValues: BitwuzlaTermArray + ): BitwuzlaTerm /** - * Print term . + * Substitute a set of keys with their corresponding values in the set of given + * terms. * - * @param term The term. - * @param format The output format for printing the term. Either `"btor"` for the - * BTOR format, or `"smt2"` for the SMT-LIB v2 format. + * The terms in [terms] are replaced with the terms resulting from this substitutions. + * + * @param terms The terms in which the keys are to be substituted. + * @param mapKeys The keys. + * @param mapValues The mapped values. */ @JvmStatic - external fun bitwuzlaTermDump(term: BitwuzlaTerm, format: String): String + external fun bitwuzlaSubstituteTerms( + terms: BitwuzlaTermArray, + mapKeys: BitwuzlaTermArray, + mapValues: BitwuzlaTermArray + ) } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/ConverterTest.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/ConverterTest.kt index 0b82d55bb..f3d19694a 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/ConverterTest.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/ConverterTest.kt @@ -6,12 +6,6 @@ import io.ksmt.expr.KBitVecValue import io.ksmt.expr.KExpr import io.ksmt.expr.rewrite.simplify.KExprSimplifier import io.ksmt.expr.transformer.KNonRecursiveTransformer -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaBVBase -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaOption -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaResult -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm -import org.ksmt.solver.bitwuzla.bindings.Native import io.ksmt.sort.KBv1Sort import io.ksmt.sort.KBvSort import io.ksmt.sort.KFpSort @@ -21,6 +15,11 @@ import kotlin.random.Random import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaBVBase +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaResult +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaTerm +import org.ksmt.solver.bitwuzla.bindings.Native class ConverterTest { private val ctx = KContext() @@ -29,11 +28,6 @@ class ConverterTest { private val converter = KBitwuzlaExprConverter(ctx, bitwuzlaCtx) private val sortChecker = SortChecker(ctx) - init { - Native.bitwuzlaSetOption(bitwuzlaCtx.bitwuzla, BitwuzlaOption.BITWUZLA_OPT_INCREMENTAL, 1) - Native.bitwuzlaSetOption(bitwuzlaCtx.bitwuzla, BitwuzlaOption.BITWUZLA_OPT_PRODUCE_MODELS, 1) - } - @Test fun testSimpleBoolExpr(): Unit = with(ctx) { val a by boolSort @@ -44,7 +38,6 @@ class ConverterTest { val term = with(internalizer) { expr.internalize() } val converted = with(converter) { term.convertExpr(boolSort) } converted.accept(sortChecker) - // compare with term instead of original expr due to internal Bitwuzla rewritings val convertedTerm = with(internalizer) { converted.internalize() } assertEquals(term, convertedTerm) } @@ -73,11 +66,11 @@ class ConverterTest { @Test fun testBoolArrayEquality(): Unit = with(ctx) { - val a by mkArraySort(bv1Sort, bv1Sort) + val a by mkArraySort(boolSort, boolSort) val b by mkArraySort(boolSort, boolSort) val aTerm = with(internalizer) { a.internalize() } val bTerm = with(internalizer) { b.internalize() } - val term = Native.bitwuzlaMkTerm2(bitwuzlaCtx.bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, aTerm, bTerm) + val term = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_EQUAL, aTerm, bTerm) val converted = with(converter) { term.convertExpr(boolSort) } converted.accept(sortChecker) val convertedTerm = with(internalizer) { converted.internalize() } @@ -124,11 +117,10 @@ class ConverterTest { val fTerm = Native.bitwuzlaTermGetChildren(fAppTerm)[0] val boolTerm = bool.internalize() val bv1Term = bv1.internalize() - val fAppTermInversed = Native.bitwuzlaMkTerm3( - bitwuzlaCtx.bitwuzla, BitwuzlaKind.BITWUZLA_KIND_APPLY, fTerm, bv1Term, boolTerm + val fAppTermInversed = Native.bitwuzlaMkTerm( + BitwuzlaKind.BITWUZLA_KIND_APPLY, fTerm, boolTerm, bv1Term ) - val term = Native.bitwuzlaMkTerm2( - bitwuzlaCtx.bitwuzla, + val term = Native.bitwuzlaMkTerm( BitwuzlaKind.BITWUZLA_KIND_EQUAL, fAppTerm, fAppTermInversed @@ -158,14 +150,10 @@ class ConverterTest { } private fun checkEquivalent(lhs: BitwuzlaTerm, rhs: BitwuzlaTerm): Boolean = with(bitwuzlaCtx) { - val checkExpr = Native.bitwuzlaMkTerm1( - bitwuzla, - BitwuzlaKind.BITWUZLA_KIND_NOT, - Native.bitwuzlaMkTerm2(bitwuzla, BitwuzlaKind.BITWUZLA_KIND_EQUAL, lhs, rhs) - ) + val checkExpr = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_DISTINCT, lhs, rhs) Native.bitwuzlaPush(bitwuzla, 1) Native.bitwuzlaAssert(bitwuzla, checkExpr) - val status = Native.bitwuzlaCheckSatResult(bitwuzla) + val status = Native.bitwuzlaCheckSat(bitwuzla) Native.bitwuzlaPop(bitwuzla, 1) status == BitwuzlaResult.BITWUZLA_UNSAT } @@ -175,11 +163,11 @@ class ConverterTest { val ctx = KContext() val converter = KBitwuzlaExprConverter(ctx, this) - val ones52 = Native.bitwuzlaMkBvOnes(bitwuzla, Native.bitwuzlaMkBvSort(bitwuzla, 52)) + val ones52 = Native.bitwuzlaMkBvOnes(Native.bitwuzlaMkBvSort(52)) val ksmtOnes52 = with(converter) { ones52.convertExpr(ctx.mkBvSort(52u)) } assertEquals(52, (ksmtOnes52 as KBitVecValue<*>).stringValue.count { it == '1' }) - val ones32 = Native.bitwuzlaMkBvOnes(bitwuzla, Native.bitwuzlaMkBvSort(bitwuzla, 32)) + val ones32 = Native.bitwuzlaMkBvOnes(Native.bitwuzlaMkBvSort(32)) val ksmtOnes32 = with(converter) { ones32.convertExpr(ctx.bv32Sort) } assertEquals(32, (ksmtOnes32 as KBitVecValue<*>).stringValue.count { it == '1' }) @@ -197,7 +185,7 @@ class ConverterTest { val nativeSort = with(internalizer) { sort.internalizeSort() } val randomBitsTerm = Native.bitwuzlaMkBvValue( - bitwuzla, nativeSort, randomBits, BitwuzlaBVBase.BITWUZLA_BV_BASE_BIN + nativeSort, randomBits, BitwuzlaBVBase.BINARY ) val randomBitsConverted = with(converter) { randomBitsTerm.convertExpr(sort) } val randomBitsKsmt = ctx.mkBv(randomBits, sort.sizeBits) @@ -242,8 +230,7 @@ class ConverterTest { val randomBitsKsmt = ctx.mkBv(randomBits, sort.sizeBits) val randomBitsInternalized = with(internalizer) { randomBitsKsmt.internalize() } - Native.bitwuzlaCheckSat(bitwuzla) // Get value is not available before check-sat - val internalizedBits = Native.bitwuzlaGetBvValue(bitwuzla, randomBitsInternalized) + val internalizedBits = Native.bitwuzlaGetBvValueString(randomBitsInternalized) assertEquals(randomBits, internalizedBits) } @@ -259,9 +246,9 @@ class ConverterTest { val fp64sort = with(internalizer) { ctx.fp64Sort.internalizeSort() } val fpCustomSort = with(internalizer) { fpCustom.internalizeSort() } - val fp32NegInf = Native.bitwuzlaMkFpNegInf(bitwuzla, fp32sort) - val fp64NegInf = Native.bitwuzlaMkFpNegInf(bitwuzla, fp64sort) - val fpCustomNegInf = Native.bitwuzlaMkFpNegInf(bitwuzla, fpCustomSort) + val fp32NegInf = Native.bitwuzlaMkFpNegInf(fp32sort) + val fp64NegInf = Native.bitwuzlaMkFpNegInf(fp64sort) + val fpCustomNegInf = Native.bitwuzlaMkFpNegInf(fpCustomSort) val converter = KBitwuzlaExprConverter(ctx, this) val ksmt32NegInf = with(converter) { fp32NegInf.convertExpr(ctx.fp32Sort) } @@ -279,11 +266,11 @@ class ConverterTest { val randomBits = randomBits(someBvSort.sizeBits) val nativeBvSort = with(internalizer) { someBvSort.internalizeSort() } val randomBitsTerm = Native.bitwuzlaMkBvValue( - bitwuzla, nativeBvSort, randomBits, BitwuzlaBVBase.BITWUZLA_BV_BASE_BIN + nativeBvSort, randomBits, BitwuzlaBVBase.BINARY ) - val randomBitsFp = Native.bitwuzlaMkTerm1Indexed2( - bitwuzla, BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_BV, - randomBitsTerm, someFpSort.exponentBits.toInt(), someFpSort.significandBits.toInt() + val randomBitsFp = Native.bitwuzlaMkTermIndexed( + BitwuzlaKind.BITWUZLA_KIND_FP_TO_FP_FROM_BV, + randomBitsTerm, someFpSort.exponentBits.toLong(), someFpSort.significandBits.toLong() ) val convertedRandomFp = with(converter) { randomBitsFp.convertExpr(someFpSort) } val convertedBvValue = KExprSimplifier(ctx).apply(ctx.mkFpToIEEEBvExpr(convertedRandomFp)) diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/SolverTest.kt b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/SolverTest.kt index e97104e62..4af98d56f 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/SolverTest.kt +++ b/ksmt-bitwuzla/ksmt-bitwuzla-core/src/test/kotlin/io/ksmt/solver/bitwuzla/SolverTest.kt @@ -2,19 +2,22 @@ package io.ksmt.solver.bitwuzla import io.ksmt.KContext import io.ksmt.expr.KExpr +import io.ksmt.expr.rewrite.KExprSubstitutor import io.ksmt.solver.KSolverStatus -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind -import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException -import org.ksmt.solver.bitwuzla.bindings.Native import io.ksmt.sort.KArray2Sort import io.ksmt.sort.KArraySort import io.ksmt.sort.KBv32Sort import io.ksmt.utils.getValue +import io.ksmt.utils.uncheckedCast import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith +import kotlin.test.assertFalse import kotlin.test.assertTrue import kotlin.time.Duration.Companion.milliseconds +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaKind +import org.ksmt.solver.bitwuzla.bindings.BitwuzlaNativeException +import org.ksmt.solver.bitwuzla.bindings.Native class SolverTest { private val ctx = KContext() @@ -24,7 +27,7 @@ class SolverTest { fun testAbortHandling() { assertFailsWith(BitwuzlaNativeException::class) { // Incorrect native expression with invalid term (0) - Native.bitwuzlaMkTerm1(solver.bitwuzlaCtx.bitwuzla, BitwuzlaKind.BITWUZLA_KIND_AND, 0) + Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_AND, 0) } } @@ -113,8 +116,9 @@ class SolverTest { var status = solver.checkWithAssumptions(listOf(a)) assertEquals(KSolverStatus.UNSAT, status) val core = solver.unsatCore() - assertEquals(1, core.size) - assertTrue(!a in core || a in core) + assertEquals(2, core.size) + assertTrue(!a in core) + assertTrue(a in core) solver.pop() status = solver.check() assertEquals(KSolverStatus.SAT, status) @@ -135,7 +139,8 @@ class SolverTest { for (i in 0..10000) { val selectedValue = array.select(mkBv(4198500 + i)) xoredX = mkBvXorExpr(xoredX, selectedValue) - xoredX = mkBvOrExpr(mkBvUnsignedDivExpr(xoredX, mkBv(3)), mkBvUnsignedRemExpr(xoredX, mkBv(3))) + // with expression below, bitwuzla can't stop on necessary timeout +// xoredX = mkBvOrExpr(mkBvUnsignedDivExpr(xoredX, mkBv(3)), mkBvUnsignedRemExpr(xoredX, mkBv(3))) } val someRandomValue = mkBv(42) val assertion = xoredX eq someRandomValue @@ -183,13 +188,35 @@ class SolverTest { assertEquals(KSolverStatus.SAT, status) } + @Test + fun testArrayLambdaSortNeq() { + val bv32Sort = Native.bitwuzlaMkBvSort(32) + val arraySort = Native.bitwuzlaMkArraySort(bv32Sort, bv32Sort) + + val varTerm = Native.bitwuzlaMkVar(bv32Sort, "var1") + val lambda = Native.bitwuzlaMkTerm(BitwuzlaKind.BITWUZLA_KIND_LAMBDA, varTerm, Native.bitwuzlaMkBvValueInt64(bv32Sort, 512)) + + assertFalse { Native.bitwuzlaSortIsEqual(arraySort, Native.bitwuzlaTermGetSort(lambda)) } + } + + @Test + fun testArrayFunSortNeq() { + val bv32Sort = Native.bitwuzlaMkBvSort(32) + val arraySort = Native.bitwuzlaMkArraySort(bv32Sort, bv32Sort) + + val fSort = Native.bitwuzlaMkFunSort(longArrayOf(bv32Sort), bv32Sort) + + assertFalse { Native.bitwuzlaSortIsEqual(arraySort, fSort) } + } + @Test fun testArrayLambdaEq(): Unit = with(ctx) { - val sort = mkArraySort(bv32Sort, bv32Sort) + val bvSort = mkBvSort(4u) + val sort = mkArraySort(bvSort, bvSort) val arrayVar by sort - val bias by bv32Sort - val idx by bv32Sort + val bias by bvSort + val idx by bvSort val lambdaBody = mkBvAddExpr(idx, bias) val lambda = mkArrayLambda(idx.decl, lambdaBody) @@ -219,7 +246,7 @@ class SolverTest { assertEquals(KSolverStatus.SAT, solver.check()) - solver.assert(lambdaSelectValue neq selectValue) + solver.assert(lambdaSelectValue neq selectValue) assertEquals(KSolverStatus.UNSAT, solver.check()) } @@ -256,7 +283,18 @@ class SolverTest { val model = solver.model() - assertEquals(10, model.interpretation(f)?.entries?.size) + val fInterpretation = model.interpretation(f) ?: error("Lack of interpretation of $f") + val default = fInterpretation.default ?: error("Lack of default of $fInterpretation") + + solver.assert(mkOr( + (0 until 10).map { i -> + f.apply(listOf(mkBv(i), mkBv(i))) neq KExprSubstitutor(ctx).apply { + fInterpretation.vars.forEach { v -> substitute(v.apply(emptyList()).uncheckedCast(), mkBv(i)) } + }.apply(default) + } + )) + + assertEquals(KSolverStatus.UNSAT, solver.check(), "Incorrect function interpretation: $fInterpretation") } } diff --git a/ksmt-bitwuzla/ksmt-bitwuzla-native/build.gradle.kts b/ksmt-bitwuzla/ksmt-bitwuzla-native/build.gradle.kts index 9657013ab..93fe1734c 100644 --- a/ksmt-bitwuzla/ksmt-bitwuzla-native/build.gradle.kts +++ b/ksmt-bitwuzla/ksmt-bitwuzla-native/build.gradle.kts @@ -32,9 +32,9 @@ bitwuzlaBinaries.keys.forEach { it.compileClasspath = compileConfig } dependencies { compileConfig(project(":ksmt-bitwuzla:ksmt-bitwuzla-core")) - bitwuzlaNativeLinuxX64("bitwuzla", "bitwuzla-linux64", "1.0", ext = "zip") - bitwuzlaNativeWindowsX64("bitwuzla", "bitwuzla-win64", "1.0", ext = "zip") - bitwuzlaNativeMacArm("bitwuzla", "bitwuzla-osx-arm64", "1.0", ext = "zip") + bitwuzlaNativeLinuxX64("bitwuzla", "bitwuzla-linux64", "0.2.0", ext = "zip") + bitwuzlaNativeWindowsX64("bitwuzla", "bitwuzla-win64", "0.2.0", ext = "zip") +// bitwuzlaNativeMacArm("bitwuzla", "bitwuzla-osx-arm64", "1.0", ext = "zip") } bitwuzlaBinaries.entries.forEach { (sourceSet, nativeConfig) ->