3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-27 19:05:51 +00:00

merge with Z3Prover/master

This commit is contained in:
Thai Trinh 2018-06-25 19:44:46 +08:00
parent 57845d4809
commit aacb7289be
1147 changed files with 59004 additions and 63575 deletions

View file

@ -84,7 +84,7 @@ matrix:
- os: osx
osx_image: xcode8.3
# Note: Apple Clang does not support OpenMP
env: Z3_BUILD_TYPE=RelWithDebInfo USE_OPENMP=0
env: Z3_BUILD_TYPE=RelWithDebInfo USE_OPENMP=0 DOTNET_BINDINGS=0
script:
# Use `travis_wait` when doing LTO builds because this configuration will
# have long link times during which it will not show any output which

View file

@ -33,7 +33,7 @@ endif()
# Project version
################################################################################
set(Z3_VERSION_MAJOR 4)
set(Z3_VERSION_MINOR 6)
set(Z3_VERSION_MINOR 8)
set(Z3_VERSION_PATCH 0)
set(Z3_VERSION_TWEAK 0)
set(Z3_VERSION "${Z3_VERSION_MAJOR}.${Z3_VERSION_MINOR}.${Z3_VERSION_PATCH}.${Z3_VERSION_TWEAK}")
@ -218,12 +218,17 @@ include(${CMAKE_SOURCE_DIR}/cmake/z3_add_cxx_flag.cmake)
################################################################################
# C++ language version
################################################################################
# FIXME: Use CMake's own mechanism for selecting language version
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
z3_add_cxx_flag("-std=c++11" REQUIRED)
else()
message(AUTHOR_WARNING "Not setting C++ language version for compiler")
endif()
if ("${CMAKE_VERSION}" VERSION_LESS "3.1")
# FIXME: Drop this when we upgrade to newer CMake versions.
if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
z3_add_cxx_flag("-std=c++11" REQUIRED)
else()
message(AUTHOR_WARNING "Not setting C++ language version for compiler")
endif()
else ()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif ()
################################################################################
# Platform detection
@ -240,6 +245,9 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
message(STATUS "Platform: FreeBSD")
list(APPEND Z3_COMPONENT_CXX_DEFINES "-D_FREEBSD_")
elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "NetBSD")
message(STATUS "Platform: NetBSD")
list(APPEND Z3_COMPONENT_CXX_DEFINES "-D_NetBSD_")
elseif ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
message(STATUS "Platform: OpenBSD")
list(APPEND Z3_COMPONENT_CXX_DEFINES "-D_OPENBSD_")
@ -257,6 +265,46 @@ list(APPEND Z3_COMPONENT_EXTRA_INCLUDE_DIRS
"${CMAKE_BINARY_DIR}/src"
"${CMAKE_SOURCE_DIR}/src"
)
################################################################################
# Linux specific configuration
################################################################################
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# Try to detect if it is necessary to link against librt.
# Note that glibc < 2.17 required librt to be linked to use clock_gettime()
# and friends.
set(CLOCK_GETTIME_REQUIRES_LIBRT_TEST_CODE
"
#include <time.h>
int main() {
timespec res;
int result = clock_gettime(CLOCK_REALTIME, &res);
return result == 0;
}
"
)
check_cxx_source_compiles(
"${CLOCK_GETTIME_REQUIRES_LIBRT_TEST_CODE}"
CLOCK_GETTIME_NO_REQUIRE_LIBRT
)
if (NOT CLOCK_GETTIME_NO_REQUIRE_LIBRT)
# Try again with librt
message(STATUS "Failed to link against clock_gettime(), trying with librt")
set(CMAKE_REQUIRED_LIBRARIES_OLD "${CMAKE_REQUIRED_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} rt")
check_cxx_source_compiles(
"${CLOCK_GETTIME_REQUIRES_LIBRT_TEST_CODE}"
CLOCK_GETTIME_REQUIRES_LIBRT
)
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_OLD}")
if (CLOCK_GETTIME_REQUIRES_LIBRT)
list(APPEND Z3_DEPENDENT_LIBS "rt")
else()
message(FATAL_ERROR "Failed to link against clock_gettime()")
endif()
endif()
endif()
################################################################################
# GNU multiple precision library support
################################################################################
@ -369,6 +417,20 @@ list(APPEND Z3_DEPENDENT_LIBS ${CMAKE_THREAD_LIBS_INIT})
################################################################################
include(${CMAKE_SOURCE_DIR}/cmake/compiler_warnings.cmake)
################################################################################
# If using Ninja, force color output for Clang (and gcc, disabled to check build).
################################################################################
if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
endif()
# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color")
# endif()
endif()
################################################################################
# Option to control what type of library we build
################################################################################
@ -394,7 +456,7 @@ else()
endif()
################################################################################
# Postion independent code
# Position independent code
################################################################################
# This is required because code built in the components will end up in a shared
# library. If not building a shared library ``-fPIC`` isn't needed and would add

View file

@ -5,7 +5,7 @@ of the project written in the ``CMakeLists.txt`` files and emits a build
system for that project of your choice using one of CMake's "generators".
This allows CMake to support many different platforms and build tools.
You can run ``cmake --help`` to see the list of supported "generators"
on your platform. Example generators include "UNIX Makfiles" and "Visual Studio
on your platform. Example generators include "UNIX Makefiles" and "Visual Studio
12 2013".
## Getting started
@ -44,7 +44,7 @@ cmake -G "Unix Makefiles" ../
make -j4 # Replace 4 with an appropriate number
```
Note that on some platforms "Unix Makesfiles" is the default generator so on those
Note that on some platforms "Unix Makefiles" is the default generator so on those
platforms you don't need to pass ``-G "Unix Makefiles"`` command line option to
``cmake``.

View file

@ -12,9 +12,9 @@ See the [release notes](RELEASE_NOTES) for notes on various stable releases of Z
## Build status
| Windows x86 | Windows x64 | Ubuntu x64 | Debian x64 | OSX | TravisCI |
| ----------- | ----------- | ---------- | ---------- | --- | -------- |
[![win32-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/4/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=4) | [![win64-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/7/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=7) | [![ubuntu-x64-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/3/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=3) | [![debian-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/5/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=5) | [![osx-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/2/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=2) | [![Build Status](https://travis-ci.org/Z3Prover/z3.svg?branch=master)](https://travis-ci.org/Z3Prover/z3)
| Windows x64 | Windows x86 | Windows x64 | Ubuntu x64 | Debian x64 | OSX | TravisCI |
| ----------- | ----------- | ----------- | ---------- | ---------- | --- | -------- |
[![win64-badge](https://z3build.visualstudio.com/_apis/public/build/definitions/2e0aa542-a22c-4b1a-8dcd-3ebae8e12db4/4/badge)](https://z3build.visualstudio.com/Z3Build/_build/index?definitionId=4) | [![win32-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/4/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=4) | [![win64-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/7/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=7) | [![ubuntu-x64-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/3/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=3) | [![debian-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/5/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=5) | [![osx-badge](https://cz3.visualstudio.com/_apis/public/build/definitions/bf14bcc7-ebd4-4240-812c-5972fa59e0ad/2/badge)](https://cz3.visualstudio.com/Z3/_build/index?definitionId=2) | [![Build Status](https://travis-ci.org/Z3Prover/z3.svg?branch=master)](https://travis-ci.org/Z3Prover/z3)
[1]: #building-z3-on-windows-using-visual-studio-command-prompt
[2]: #building-z3-using-make-and-gccclang
@ -189,3 +189,6 @@ python -c 'import z3; print(z3.get_version_string())'
See [``examples/python``](examples/python) for examples.
### ``Web Assembly``
[WebAssembly](https://github.com/cpitclaudel/z3.wasm) bindings are provided by Clément Pit-Claudel.

View file

@ -1,7 +1,62 @@
RELEASE NOTES
Version 4.8.0
=============
- New requirements:
- A breaking change to the API is that parsers for SMT-LIB2 formulas return a vector of
formulas as opposed to a conjunction of formulas. The vector of formulas correspond to
the set of "assert" instructions in the SMT-LIB input.
- New features
- A parallel mode is available for select theories, including QF_BV.
By setting parallel.enable=true Z3 will spawn a number of worker threads proportional to the
number of available CPU cores to apply cube and conquer solving on the goal.
- The SAT solver by default handle cardinality and PB constraints using a custom plugin
that operates directly on cardinality and PB constraints.
- A "cube" interface is exposed over the solver API.
- Model conversion is first class over the textual API, such that subgoals created from running a
solver can be passed in text files and a model for the original formula can be recreated from the result.
- This has also led to changes in how models are tracked over tactic subgoals. The API for
extracting models from apply_result have been replaced.
- An optional mode handles xor constraints using a custom xor propagator.
It is off by default and its value not demonstrated.
- The SAT solver includes new inprocessing technques that are available during simplification.
It performs asymmetric tautology elimination by default, and one can turn on more powerful inprocessing techniques
(known as ACCE, ABCE, CCE). Asymmetric branching also uses features introduced in Lingeling by exploiting binary implication graphs.
Use sat.acce=true to enable the full repertoire of inprocessing methods. By default, clauses that are "eliminated" by acce are tagged
as lemmas (redundant) and are garbage collected if their glue level is high.
- Substantial overhaul of the spacer horn clause engine.
- Removed features:
- interpolation API
- duality engine for constrained Horn clauses.
- pdr engine for constrained Horn clauses. The engine's functionality has been
folded into spacer as one of optional strategies.
- long deprecated API functions have been removed from z3_api.h
Version 4.7.1
=============
- New requirements:
- uses stdbool and stdint as part of z3.
- New features:
- none
- Removed features:
- none
- Notes:
This is a minor release prior to a set of planned major updates.
It uses minor version 7 to indicate that the use of stdbool and
stdint are breaking changes to consumers of the C-based API.
Version 4.6.0
=============
- New requirements:
- C++11 capable compiler to build Z3.
- C++ API now requires C++11 or newer.
@ -14,6 +69,10 @@ Version 4.6.0
issuing the command (get-objectives). Pareto front objectives are accessed by
issuing multiple (check-sat) calls until it returns unsat.
- Removed features:
- Removed support for SMT-LIB 1.x
Version 4.5.0
=============
@ -49,10 +108,9 @@ Version 4.5.0
over compound formulas, introduce a fresh predicate whose
arguments are the relevant free variables in the formula and add a rule
that uses the fresh predicate in the head and formula in the body.
- minimization of unsat cores is avaialble as an option for the SAT and SMT cores.
- Minimization of unsat cores is available as an option for the SAT and SMT cores.
By setting smt.core.minimize=true resp. sat.core.minimize=true
cores produced by these modules are minimized.
cores produced by these modules are minimized.
- A multitude of bugs has been fixed.
@ -423,11 +481,11 @@ Version 3.0
- New Bitvector (QF_BV) solver. The new solver is only available when using the new SMT2 front-end.
- Major performace improvements.
- Major performance improvements.
- New preprocessing stack.
- Performance improvements for linear and nonlinear arithmetic. The improvements are only available when using the the SMT2 front-end.
- Performance improvements for linear and nonlinear arithmetic. The improvements are only available when using the SMT2 front-end.
- Added API for parsing SMT2 files.
@ -708,7 +766,7 @@ The following bugs are fixed in this release:
bvshl when using a shift amount that evaluates to the length
of the bit-vector. Thanks to Trevor Hansen and Robert Brummayer.
- Incorrect NNF conversion in linear quantifier elimniation routines.
- Incorrect NNF conversion in linear quantifier elimination routines.
Thanks to Josh Berdine.
- Missing constant folding of extraction for large bit-vectors.
@ -768,7 +826,7 @@ This release also introduces some new preprocessing features:
- More efficient destructive equality resolution DER=true.
- DISTRIBUTE_FORALL=true (distributes universal quatifiers over conjunctions, this transformation may affect pattern inference).
- DISTRIBUTE_FORALL=true (distributes universal quantifiers over conjunctions, this transformation may affect pattern inference).
- Rewriter that uses universally quantified equations PRE_DEMODULATOR=true (yes, the option name is not good, we will change it in a future release).
@ -838,7 +896,7 @@ This release introduces the following features:
It fixes the following bugs:
- Incorrect simplification of map over store in the extendted array theory. Reported by Catalin Hritcu.
- Incorrect simplification of map over store in the extended array theory. Reported by Catalin Hritcu.
- Incomplete handling of equality propagation with constant arrays. Reported by Catalin Hritcu.
@ -882,7 +940,7 @@ Version 2.0
proof object.
- Proof Objects.
The #Z3_check_assumptions retuns a proof object if
The #Z3_check_assumptions returns a proof object if
the configuration flag PROOF_MODE is set to 1 or 2.
- Partial support for non-linear arithmetic.
@ -895,4 +953,4 @@ Version 2.0
The theory of well-founded recursive data-types is supported
over the binary APIs. It supports ground satisfiability checking
for tuples, enumeration types (scalars),
lists and mututally recursive data-types.
lists and mutually recursive data-types.

View file

@ -2,7 +2,7 @@
# @AUTO_GEN_MSG@
#
# This file is intended to be consumed by clients who wish to use Z3 from CMake.
# It can be use by doing `find_package(Z3 config)` from within a
# It can be used by doing `find_package(Z3 config)` from within a
# `CMakeLists.txt` file. If CMake doesn't find this package automatically you
# can give it a hint by passing `-DZ3_DIR=<path>` to the CMake invocation where
# `<path>` is the path to the directory containing this file.

View file

@ -33,13 +33,18 @@ if (DOTNET_CSC_EXECUTABLE)
set(DOTNET_TOOLCHAIN_IS_MONO TRUE)
set(DOTNET_TOOLCHAIN_IS_WINDOWS FALSE)
message(STATUS ".NET toolchain is Mono")
elseif ("${CSC_STD_OUT}" MATCHES "^Turbo[ ]+C#")
set(DOTNET_DETERMINED_VENDOR TRUE)
set(DOTNET_TOOLCHAIN_IS_MONO TRUE)
set(DOTNET_TOOLCHAIN_IS_WINDOWS FALSE)
message(STATUS ".NET toolchain is Mono")
elseif ("${CSC_STD_OUT}" MATCHES "^Microsoft.+Visual[ ]+C#")
set(DOTNET_DETERMINED_VENDOR TRUE)
set(DOTNET_TOOLCHAIN_IS_MONO FALSE)
set(DOTNET_TOOLCHAIN_IS_WINDOWS TRUE)
message(STATUS ".NET toolchain is Windows native")
else()
message(STATUS ".NET toolchain is unknown")
message(STATUS ".NET toolchain is unknown: ${CSC_STD_OUT}")
endif()
endif()
endif()

2
configure vendored
View file

@ -14,4 +14,4 @@ if ! $PYTHON -c "print('testing')" > /dev/null ; then
exit 1
fi
$PYTHON scripts/mk_make.py $*
$PYTHON scripts/mk_make.py "$@"

View file

@ -0,0 +1,6 @@
add_executable(lp_tst lp_main.cpp lp.cpp $<TARGET_OBJECTS:util> $<TARGET_OBJECTS:polynomial> $<TARGET_OBJECTS:nlsat> $<TARGET_OBJECTS:lp> )
target_compile_definitions(lp_tst PRIVATE ${Z3_COMPONENT_CXX_DEFINES})
target_compile_options(lp_tst PRIVATE ${Z3_COMPONENT_CXX_FLAGS})
target_include_directories(lp_tst PRIVATE ${Z3_COMPONENT_EXTRA_INCLUDE_DIRS})
target_link_libraries(lp_tst PRIVATE ${Z3_DEPENDENT_LIBS})
z3_append_linker_flag_list_to_target(lp_tst ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})

View file

@ -1,4 +1,4 @@
# Sanitizer supression files
# Sanitizer suppression files
This directory contains files used to suppress
ASan/LSan/UBSan warnings/errors.

View file

@ -226,12 +226,14 @@ try:
website_dox_substitutions = {}
bullet_point_prefix='\n - '
if Z3PY_ENABLED:
print("Python documentation enabled")
website_dox_substitutions['PYTHON_API'] = (
'{prefix}<a class="el" href="namespacez3py.html">Python API</a> '
'(also available in <a class="el" href="z3.html">pydoc format</a>)'
).format(
prefix=bullet_point_prefix)
else:
print("Python documentation disabled")
website_dox_substitutions['PYTHON_API'] = ''
if DOTNET_ENABLED:
website_dox_substitutions['DOTNET_API'] = (
@ -250,7 +252,7 @@ try:
website_dox_substitutions['JAVA_API'] = ''
if ML_ENABLED:
website_dox_substitutions['OCAML_API'] = (
'<a class="el" href="ml/index.html">ML/OCaml API</a>'
'{prefix}<a class="el" href="ml/index.html">ML/OCaml API</a>'
).format(
prefix=bullet_point_prefix)
else:
@ -270,7 +272,6 @@ try:
cleanup_API(doc_path('../src/api/z3_rcf.h'), temp_path('z3_rcf.h'))
cleanup_API(doc_path('../src/api/z3_fixedpoint.h'), temp_path('z3_fixedpoint.h'))
cleanup_API(doc_path('../src/api/z3_optimization.h'), temp_path('z3_optimization.h'))
cleanup_API(doc_path('../src/api/z3_interp.h'), temp_path('z3_interp.h'))
cleanup_API(doc_path('../src/api/z3_fpa.h'), temp_path('z3_fpa.h'))
print("Removed annotations from z3_api.h.")
@ -316,7 +317,7 @@ try:
if ML_ENABLED:
ml_output_dir = os.path.join(OUTPUT_DIRECTORY, 'html', 'ml')
mk_dir(ml_output_dir)
if subprocess.call(['ocamldoc', '-html', '-d', ml_output_dir, '-sort', '-hide', 'Z3', '-I', '%s/api/ml' % BUILD_DIR, doc_path('../src/api/ml/z3enums.mli'), doc_path('../src/api/ml/z3.mli')]) != 0:
if subprocess.call(['ocamldoc', '-html', '-d', ml_output_dir, '-sort', '-hide', 'Z3', '-I', '%s/api/ml' % BUILD_DIR, '%s/api/ml/z3enums.mli' % BUILD_DIR, '%s/api/ml/z3.mli' % BUILD_DIR]) != 0:
print("ERROR: ocamldoc failed.")
exit(1)
print("Generated ML/OCaml documentation.")
@ -326,3 +327,4 @@ except Exception:
exctype, value = sys.exc_info()[:2]
print("ERROR: failed to generate documentation: %s" % value)
exit(1)

View file

@ -470,7 +470,7 @@ void unsat_core_example2() {
// The solver s already contains p1 => F
// To disable F, we add (not p1) as an additional assumption
qs.push_back(!p1);
std::cout << s.check((unsigned)qs.size(), &qs[0]) << "\n";
std::cout << s.check(static_cast<unsigned>(qs.size()), &qs[0]) << "\n";
expr_vector core2 = s.unsat_core();
std::cout << core2 << "\n";
std::cout << "size: " << core2.size() << "\n";
@ -707,7 +707,7 @@ void tactic_example7() {
std::cout << s.check() << "\n";
model m = s.get_model();
std::cout << "model for subgoal:\n" << m << "\n";
std::cout << "model for original goal:\n" << r.convert_model(m) << "\n";
std::cout << "model for original goal:\n" << subgoal.convert_model(m) << "\n";
}
void tactic_example8() {
@ -920,6 +920,19 @@ void enum_sort_example() {
std::cout << "2: " << result_goal.as_expr() << std::endl;
}
void tuple_example() {
std::cout << "tuple example\n";
context ctx;
const char * names[] = { "first", "second" };
sort sorts[2] = { ctx.int_sort(), ctx.bool_sort() };
func_decl_vector projs(ctx);
func_decl pair = ctx.tuple_sort("pair", 2, names, sorts, projs);
sorts[1] = pair.range();
func_decl pair2 = ctx.tuple_sort("pair2", 2, names, sorts, projs);
std::cout << pair2 << "\n";
}
void expr_vector_example() {
std::cout << "expr_vector example\n";
context c;
@ -1136,7 +1149,7 @@ static void parse_example() {
func_decl_vector decls(c);
sort B = c.bool_sort();
decls.push_back(c.function("a", 0, 0, B));
expr a = c.parse_string("(assert a)", sorts, decls);
expr_vector a = c.parse_string("(assert a)", sorts, decls);
std::cout << a << "\n";
// expr b = c.parse_string("(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))");
@ -1179,6 +1192,7 @@ int main() {
incremental_example2(); std::cout << "\n";
incremental_example3(); std::cout << "\n";
enum_sort_example(); std::cout << "\n";
tuple_example(); std::cout << "\n";
expr_vector_example(); std::cout << "\n";
exists_expr_vector_example(); std::cout << "\n";
substitute_example(); std::cout << "\n";

View file

@ -378,7 +378,7 @@ void assert_comm_axiom(Z3_context ctx, Z3_solver s, Z3_func_decl f)
{
Z3_sort t;
Z3_symbol f_name, t_name;
Z3_ast q;
Z3_ast_vector q;
t = Z3_get_range(ctx, f);
@ -394,13 +394,14 @@ void assert_comm_axiom(Z3_context ctx, Z3_solver s, Z3_func_decl f)
/* Inside the parser, type t will be referenced using the symbol 'T'. */
t_name = Z3_mk_string_symbol(ctx, "T");
q = Z3_parse_smtlib2_string(ctx,
"(assert (forall ((x T) (y T)) (= (f x y) (f y x))))",
1, &t_name, &t,
1, &f_name, &f);
printf("assert axiom:\n%s\n", Z3_ast_to_string(ctx, q));
Z3_solver_assert(ctx, s, q);
printf("assert axiom:\n%s\n", Z3_ast_vector_to_string(ctx, q));
for (unsigned i = 0; i < Z3_ast_vector_size(ctx, q); ++i) {
Z3_solver_assert(ctx, s, Z3_ast_vector_get(ctx, q, i));
}
}
/**
@ -1546,7 +1547,7 @@ void two_contexts_example1()
}
/**
\brief Demonstrates how error codes can be read insted of registering an error handler.
\brief Demonstrates how error codes can be read instead of registering an error handler.
*/
void error_code_example1()
{
@ -1642,7 +1643,7 @@ void parser_example2()
Z3_ast x, y;
Z3_symbol names[2];
Z3_func_decl decls[2];
Z3_ast f;
Z3_ast_vector f;
printf("\nparser_example2\n");
LOG_MSG("parser_example2");
@ -1665,8 +1666,11 @@ void parser_example2()
0, 0, 0,
/* 'x' and 'y' declarations are inserted as 'a' and 'b' into the parser symbol table. */
2, names, decls);
printf("formula: %s\n", Z3_ast_to_string(ctx, f));
Z3_solver_assert(ctx, s, f);
printf("formula: %s\n", Z3_ast_vector_to_string(ctx, f));
printf("assert axiom:\n%s\n", Z3_ast_vector_to_string(ctx, f));
for (unsigned i = 0; i < Z3_ast_vector_size(ctx, f); ++i) {
Z3_solver_assert(ctx, s, Z3_ast_vector_get(ctx, f, i));
}
check(ctx, s, Z3_L_TRUE);
del_solver(ctx, s);
@ -1685,7 +1689,7 @@ void parser_example3()
Z3_symbol g_name;
Z3_sort g_domain[2];
Z3_func_decl g;
Z3_ast thm;
Z3_ast_vector thm;
printf("\nparser_example3\n");
LOG_MSG("parser_example3");
@ -1710,8 +1714,8 @@ void parser_example3()
"(assert (forall ((x Int) (y Int)) (=> (= x y) (= (g x 0) (g 0 y)))))",
0, 0, 0,
1, &g_name, &g);
printf("formula: %s\n", Z3_ast_to_string(ctx, thm));
prove(ctx, s, thm, Z3_TRUE);
printf("formula: %s\n", Z3_ast_vector_to_string(ctx, thm));
prove(ctx, s, Z3_ast_vector_get(ctx, thm, 0), Z3_TRUE);
del_solver(ctx, s);
Z3_del_context(ctx);
@ -2286,46 +2290,6 @@ void unsat_core_and_proof_example() {
Z3_del_context(ctx);
}
void interpolation_example() {
Z3_context ctx = mk_context();
Z3_ast pa = mk_bool_var(ctx, "PredA");
Z3_ast pb = mk_bool_var(ctx, "PredB");
Z3_ast pc = mk_bool_var(ctx, "PredC");
Z3_ast args1[2] = {pa,pb}, args2[2] = {Z3_mk_not(ctx,pb),pc};
Z3_ast args3[2] = {Z3_mk_interpolant(ctx,Z3_mk_and(ctx,2,args1)),Z3_mk_and(ctx,2,args2)};
Z3_ast f = Z3_mk_and(ctx,2,args3);
Z3_ast_vector interpolant = 0;
Z3_model m = 0;
Z3_lbool result = Z3_L_UNDEF;
printf("\ninterpolation_example\n");
LOG_MSG("interpolation_example");
result = Z3_compute_interpolant(ctx,f,0,&interpolant,&m);
switch (result) {
case Z3_L_FALSE:
printf("unsat\n");
printf("interpolant: %s\n", Z3_ast_to_string(ctx, Z3_ast_vector_get(ctx, interpolant, 0)));
printf("\n");
break;
case Z3_L_UNDEF:
printf("unknown\n");
printf("potential model:\n");
if (m) Z3_model_inc_ref(ctx, m);
display_model(ctx, stdout, m);
break;
case Z3_L_TRUE:
printf("sat\n");
if (m) Z3_model_inc_ref(ctx, m);
display_model(ctx, stdout, m);
break;
}
/* delete logical context */
if (m) Z3_model_dec_ref(ctx, m);
Z3_del_context(ctx);
}
#define MAX_RETRACTABLE_ASSERTIONS 1024
@ -2452,7 +2416,6 @@ Z3_lbool ext_check(Z3_ext_context ctx) {
}
printf("\n");
}
return result;
}
@ -2464,7 +2427,7 @@ void incremental_example1() {
Z3_context ctx = ext_ctx->m_context;
Z3_ast x, y, z, two, one;
unsigned c1, c2, c3, c4;
Z3_bool result;
Z3_lbool result;
printf("\nincremental_example1\n");
LOG_MSG("incremental_example1");
@ -2485,7 +2448,7 @@ void incremental_example1() {
c4 = assert_retractable_cnstr(ext_ctx, Z3_mk_lt(ctx, y, one));
result = ext_check(ext_ctx);
if (result != Z3_L_FALSE)
if (result != Z3_L_FALSE)
exitf("bug in Z3");
printf("unsat\n");
@ -2533,7 +2496,7 @@ void reference_counter_example() {
cfg = Z3_mk_config();
Z3_set_param_value(cfg, "model", "true");
// Create a Z3 context where the user is reponsible for managing
// Create a Z3 context where the user is responsible for managing
// Z3_ast reference counters.
ctx = Z3_mk_context_rc(cfg);
Z3_del_config(cfg);
@ -2577,13 +2540,15 @@ void reference_counter_example() {
*/
void smt2parser_example() {
Z3_context ctx;
Z3_ast fs;
Z3_ast_vector fs;
printf("\nsmt2parser_example\n");
LOG_MSG("smt2parser_example");
ctx = mk_context();
fs = Z3_parse_smtlib2_string(ctx, "(declare-fun a () (_ BitVec 8)) (assert (bvuge a #x10)) (assert (bvule a #xf0))", 0, 0, 0, 0, 0, 0);
printf("formulas: %s\n", Z3_ast_to_string(ctx, fs));
Z3_ast_vector_inc_ref(ctx, fs);
printf("formulas: %s\n", Z3_ast_vector_to_string(ctx, fs));
Z3_ast_vector_dec_ref(ctx, fs);
Z3_del_context(ctx);
}
@ -3009,7 +2974,6 @@ int main() {
binary_tree_example();
enum_example();
unsat_core_and_proof_example();
interpolation_example();
incremental_example1();
reference_counter_example();
smt2parser_example();

View file

@ -175,7 +175,7 @@ namespace test_mapi
string bench = string.Format("(assert (forall ((x {0}) (y {1})) (= ({2} x y) ({3} y x))))",
t.Name, t.Name, f.Name, f.Name);
return ctx.ParseSMTLIB2String(bench, new Symbol[] { t.Name }, new Sort[] { t }, new Symbol[] { f.Name }, new FuncDecl[] { f });
return ctx.ParseSMTLIB2String(bench, new Symbol[] { t.Name }, new Sort[] { t }, new Symbol[] { f.Name }, new FuncDecl[] { f })[0];
}
/// <summary>
@ -322,7 +322,6 @@ namespace test_mapi
Status q = s.Check();
Console.WriteLine("Solver says: " + q);
Console.WriteLine("Model: \n" + s.Model);
Console.WriteLine("Converted Model: \n" + ar.ConvertModel(0, s.Model));
if (q != Status.SATISFIABLE)
throw new TestFailedException();
}
@ -612,7 +611,6 @@ namespace test_mapi
Expr f_x = ctx.MkApp(f, x);
Expr f_y = ctx.MkApp(f, y);
Expr g_y = ctx.MkApp(g, y);
Pattern[] pats = new Pattern[] { ctx.MkPattern(new Expr[] { f_x, g_y }) };
Expr[] no_pats = new Expr[] { f_y };
Expr[] bound = new Expr[2] { x, y };
Expr body = ctx.MkAnd(ctx.MkEq(f_x, f_y), ctx.MkEq(f_y, g_y));
@ -622,14 +620,13 @@ namespace test_mapi
Console.WriteLine("{0}", q1);
}
// Quantifier with de-Brujin indices.
// Quantifier with de-Bruijn indices.
{
Expr x = ctx.MkBound(1, ctx.IntSort);
Expr y = ctx.MkBound(0, ctx.IntSort);
Expr f_x = ctx.MkApp(f, x);
Expr f_y = ctx.MkApp(f, y);
Expr g_y = ctx.MkApp(g, y);
Pattern[] pats = new Pattern[] { ctx.MkPattern(new Expr[] { f_x, g_y }) };
Expr[] no_pats = new Expr[] { f_y };
Symbol[] names = new Symbol[] { ctx.MkSymbol("x"), ctx.MkSymbol("y") };
Sort[] sorts = new Sort[] { ctx.IntSort, ctx.IntSort };
@ -730,7 +727,6 @@ namespace test_mapi
{
Console.WriteLine("BasicTests");
Symbol qi = ctx.MkSymbol(1);
Symbol fname = ctx.MkSymbol("f");
Symbol x = ctx.MkSymbol("x");
Symbol y = ctx.MkSymbol("y");
@ -977,7 +973,8 @@ namespace test_mapi
using (Context ctx = new Context(new Dictionary<string, string>() { { "MODEL", "true" } }))
{
Expr a = ctx.ParseSMTLIB2File(filename);
BoolExpr[] fmls = ctx.ParseSMTLIB2File(filename);
BoolExpr a = ctx.MkAnd(fmls);
Console.WriteLine("SMT2 file read time: " + (System.DateTime.Now - before).TotalSeconds + " sec");
@ -1319,7 +1316,7 @@ namespace test_mapi
new Sort[] { int_type, int_type } // types of projection operators
);
FuncDecl first = tuple.FieldDecls[0]; // declarations are for projections
FuncDecl second = tuple.FieldDecls[1];
// FuncDecl second = tuple.FieldDecls[1];
Expr x = ctx.MkConst("x", int_type);
Expr y = ctx.MkConst("y", int_type);
Expr n1 = tuple.MkDecl[x, y];
@ -1383,7 +1380,9 @@ namespace test_mapi
{
Console.WriteLine("ParserExample1");
var fml = ctx.ParseSMTLIB2String("(declare-const x Int) (declare-const y Int) (assert (> x y)) (assert (> x 0))");
var fmls = ctx.ParseSMTLIB2String("(declare-const x Int) (declare-const y Int) (assert (> x y)) (assert (> x 0))");
var fml = ctx.MkAnd(fmls);
Console.WriteLine("formula {0}", fml);
Model m = Check(ctx, fml, Status.SATISFIABLE);
@ -1399,7 +1398,7 @@ namespace test_mapi
FuncDecl a = ctx.MkConstDecl(declNames[0], ctx.MkIntSort());
FuncDecl b = ctx.MkConstDecl(declNames[1], ctx.MkIntSort());
FuncDecl[] decls = new FuncDecl[] { a, b };
BoolExpr f = ctx.ParseSMTLIB2String("(assert (> a b))", null, null, declNames, decls);
BoolExpr f = ctx.ParseSMTLIB2String("(assert (> a b))", null, null, declNames, decls)[0];
Console.WriteLine("formula: {0}", f);
Check(ctx, f, Status.SATISFIABLE);
}
@ -1420,7 +1419,7 @@ namespace test_mapi
BoolExpr thm = ctx.ParseSMTLIB2String("(assert (forall ((x Int) (y Int)) (=> (= x y) (= (gg x 0) (gg 0 y)))))",
null, null,
new Symbol[] { ctx.MkSymbol("gg") },
new FuncDecl[] { g });
new FuncDecl[] { g })[0];
Console.WriteLine("formula: {0}", thm);
Prove(ctx, thm, false, ca);

View file

@ -167,12 +167,12 @@ class JavaExample
"function must be binary, and argument types must be equal to return type");
}
String bench = "(benchmark comm :formula (forall (x " + t.getName()
String bench = "(assert (forall (x " + t.getName()
+ ") (y " + t.getName() + ") (= (" + f.getName() + " x y) ("
+ f.getName() + " y x))))";
return ctx.parseSMTLIB2String(bench, new Symbol[] { t.getName() },
new Sort[] { t }, new Symbol[] { f.getName() },
new FuncDecl[] { f });
new FuncDecl[] { f })[0];
}
// / "Hello world" example: create a Z3 logical context, and delete it.
@ -344,8 +344,6 @@ class JavaExample
Status q = s.check();
System.out.println("Solver says: " + q);
System.out.println("Model: \n" + s.getModel());
System.out.println("Converted Model: \n"
+ ar.convertModel(0, s.getModel()));
if (q != Status.SATISFIABLE)
throw new TestFailedException();
}
@ -660,7 +658,7 @@ class JavaExample
System.out.println(q1);
}
// Quantifier with de-Brujin indices.
// Quantifier with de-Bruijn indices.
{
Expr x = ctx.mkBound(1, ctx.getIntSort());
Expr y = ctx.mkBound(0, ctx.getIntSort());
@ -1041,7 +1039,7 @@ class JavaExample
HashMap<String, String> cfg = new HashMap<String, String>();
cfg.put("model", "true");
Context ctx = new Context(cfg);
Expr a = ctx.parseSMTLIB2File(filename, null, null, null, null);
BoolExpr a = ctx.mkAnd(ctx.parseSMTLIB2File(filename, null, null, null, null));
long t_diff = ((new Date()).getTime() - before.getTime()) / 1000;
@ -1445,7 +1443,7 @@ class JavaExample
BoolExpr f = ctx.parseSMTLIB2String(
"(declare-const x Int) (declare-const y Int) (assert (and (> x y) (> x 0)))",
null, null, null, null);
null, null, null, null)[0];
System.out.println("formula " + f);
@SuppressWarnings("unused")
@ -1465,7 +1463,7 @@ class JavaExample
FuncDecl[] decls = new FuncDecl[] { a, b };
BoolExpr f = ctx.parseSMTLIB2String("(assert (> a b))", null, null,
declNames, decls);
declNames, decls)[0];
System.out.println("formula: " + f);
check(ctx, f, Status.SATISFIABLE);
}
@ -1486,7 +1484,7 @@ class JavaExample
BoolExpr thm = ctx.parseSMTLIB2String(
"(assert (forall ((x Int) (y Int)) (=> (= x y) (= (gg x 0) (gg 0 y)))))",
null, null, new Symbol[] { ctx.mkSymbol("gg") },
new FuncDecl[] { g });
new FuncDecl[] { g })[0];
System.out.println("formula: " + thm);
prove(ctx, thm, false, ca);
}

View file

@ -9,4 +9,4 @@ On OSX and Linux, you must install z3 first using
sudo make install
OR update LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX) with the build directory. You need that to be able to find the Z3 shared library.
This directory contains a test file (ex.smt) that can be use as input for the maxsat test application.
This directory contains a test file (ex.smt) that can be used as input for the maxsat test application.

View file

@ -8,6 +8,8 @@ from __future__ import print_function
from z3 import *
import time
set_option("sat.gc.burst", False) # disable GC at every search. It is wasteful for these small queries.
def diff_at_j_is_i(xs, j, i):
assert(0 <= j and j + 1 < len(xs))
assert(1 <= i and i < len(xs))

View file

@ -0,0 +1,36 @@
from z3 import *
from multiprocessing.pool import ThreadPool
from copy import deepcopy
pool = ThreadPool(8)
x = Int('x')
assert x.ctx == main_ctx()
def calculate(x, n, ctx):
""" Do a simple computation with a context"""
assert x.ctx == ctx
assert x.ctx != main_ctx()
# Parallel creation of z3 object
condition = And(x < 2, x > n, ctx)
# Parallel solving
solver = Solver(ctx=ctx)
solver.add(condition)
solver.check()
for i in range(100):
# Create new context for the computation
# Note that we need to do this sequentially, as parallel access to the current context or its objects
# will result in a segfault
i_context = Context()
x_i = deepcopy(x).translate(i_context)
# Kick off parallel computation
pool.apply_async(calculate, [x_i, i, i_context])
pool.close()
pool.join()

View file

@ -1609,7 +1609,6 @@ public:
display_inference(out, "rewrite", "thm", p);
break;
case Z3_OP_PR_PULL_QUANT:
case Z3_OP_PR_PULL_QUANT_STAR:
display_inference(out, "pull_quant", "thm", p);
break;
case Z3_OP_PR_PUSH_QUANT:
@ -1669,12 +1668,6 @@ public:
case Z3_OP_PR_NNF_NEG:
display_inference(out, "nnf_neg", "sab", p);
break;
case Z3_OP_PR_NNF_STAR:
display_inference(out, "nnf", "sab", p);
break;
case Z3_OP_PR_CNF_STAR:
display_inference(out, "cnf", "sab", p);
break;
case Z3_OP_PR_SKOLEMIZE:
display_inference(out, "skolemize", "sab", p);
break;
@ -1706,10 +1699,6 @@ public:
return display_hyp_inference(out, "modus_ponens", "thm", conclusion, hyp, hyp2);
}
case Z3_OP_PR_NNF_POS:
case Z3_OP_PR_NNF_STAR:
return display_hyp_inference(out, "nnf", "sab", conclusion, hyp);
case Z3_OP_PR_CNF_STAR:
return display_hyp_inference(out, "cnf", "sab", conclusion, hyp);
case Z3_OP_PR_SKOLEMIZE:
return display_hyp_inference(out, "skolemize", "sab", conclusion, hyp);
case Z3_OP_PR_TRANSITIVITY:
@ -2214,9 +2203,8 @@ static void check_error(z3::context& ctx) {
static void display_tptp(std::ostream& out) {
// run SMT2 parser, pretty print TFA format.
z3::context ctx;
Z3_ast _fml = Z3_parse_smtlib2_file(ctx, g_input_file, 0, 0, 0, 0, 0, 0);
check_error(ctx);
z3::expr fml(ctx, _fml);
z3::expr_vector fmls = ctx.parse_file(g_input_file);
z3::expr fml = z3::mk_and(fmls);
pp_tptp pp(ctx);
pp.collect_decls(fml);

View file

@ -72,7 +72,7 @@ def main(args):
if count == 0:
logging.info('No files generated. You need to specific an output directory'
' for the relevant langauge bindings')
' for the relevant language bindings')
# TODO: Add support for other bindings
return 0

View file

@ -9,12 +9,12 @@ from mk_util import *
# Z3 Project definition
def init_project_def():
set_version(4, 6, 0, 0)
set_version(4, 8, 0, 0)
add_lib('util', [])
add_lib('lp', ['util'], 'util/lp')
add_lib('polynomial', ['util'], 'math/polynomial')
add_lib('sat', ['util'])
add_lib('nlsat', ['polynomial', 'sat'])
add_lib('lp', ['util','nlsat'], 'util/lp')
add_lib('hilbert', ['util'], 'math/hilbert')
add_lib('simplex', ['util'], 'math/simplex')
add_lib('automata', ['util'], 'math/automata')
@ -32,17 +32,15 @@ def init_project_def():
add_lib('grobner', ['ast'], 'math/grobner')
add_lib('euclid', ['util'], 'math/euclid')
add_lib('core_tactics', ['tactic', 'macros', 'normal_forms', 'rewriter'], 'tactic/core')
add_lib('sat_tactic', ['tactic', 'sat'], 'sat/tactic')
add_lib('proofs', ['rewriter', 'util'], 'ast/proofs')
add_lib('solver', ['model', 'tactic', 'proofs'])
add_lib('sat_tactic', ['tactic', 'sat', 'solver'], 'sat/tactic')
add_lib('arith_tactics', ['core_tactics', 'sat'], 'tactic/arith')
add_lib('nlsat_tactic', ['nlsat', 'sat_tactic', 'arith_tactics'], 'nlsat/tactic')
add_lib('subpaving_tactic', ['core_tactics', 'subpaving'], 'math/subpaving/tactic')
add_lib('aig_tactic', ['tactic'], 'tactic/aig')
add_lib('proofs', ['rewriter', 'util'], 'ast/proofs')
add_lib('solver', ['model', 'tactic', 'proofs'])
add_lib('ackermannization', ['model', 'rewriter', 'ast', 'solver', 'tactic'], 'ackermannization')
add_lib('interp', ['solver'])
add_lib('cmd_context', ['solver', 'rewriter', 'interp'])
add_lib('extra_cmds', ['cmd_context', 'subpaving_tactic', 'arith_tactics'], 'cmd_context/extra_cmds')
add_lib('cmd_context', ['solver', 'rewriter'])
add_lib('smt2parser', ['cmd_context', 'parser_util'], 'parsers/smt2')
add_lib('fpa', ['ast', 'util', 'rewriter', 'model'], 'ast/fpa')
add_lib('pattern', ['normal_forms', 'smt2parser', 'rewriter'], 'ast/pattern')
@ -56,29 +54,26 @@ def init_project_def():
add_lib('smt_tactic', ['smt'], 'smt/tactic')
add_lib('sls_tactic', ['tactic', 'normal_forms', 'core_tactics', 'bv_tactics'], 'tactic/sls')
add_lib('qe', ['smt','sat','nlsat','tactic','nlsat_tactic'], 'qe')
add_lib('duality', ['smt', 'interp', 'qe'])
add_lib('muz', ['smt', 'sat', 'smt2parser', 'aig_tactic', 'qe'], 'muz/base')
add_lib('dataflow', ['muz'], 'muz/dataflow')
add_lib('transforms', ['muz', 'hilbert', 'dataflow'], 'muz/transforms')
add_lib('rel', ['muz', 'transforms'], 'muz/rel')
add_lib('pdr', ['muz', 'transforms', 'arith_tactics', 'core_tactics', 'smt_tactic'], 'muz/pdr')
add_lib('spacer', ['muz', 'transforms', 'arith_tactics', 'smt_tactic'], 'muz/spacer')
add_lib('clp', ['muz', 'transforms'], 'muz/clp')
add_lib('tab', ['muz', 'transforms'], 'muz/tab')
add_lib('bmc', ['muz', 'transforms'], 'muz/bmc')
add_lib('ddnf', ['muz', 'transforms', 'rel'], 'muz/ddnf')
add_lib('duality_intf', ['muz', 'transforms', 'duality'], 'muz/duality')
add_lib('fp', ['muz', 'pdr', 'clp', 'tab', 'rel', 'bmc', 'duality_intf', 'ddnf', 'spacer'], 'muz/fp')
add_lib('nlsat_smt_tactic', ['nlsat_tactic', 'smt_tactic'], 'tactic/nlsat_smt')
add_lib('fp', ['muz', 'clp', 'tab', 'rel', 'bmc', 'ddnf', 'spacer'], 'muz/fp')
add_lib('ufbv_tactic', ['normal_forms', 'core_tactics', 'macros', 'smt_tactic', 'rewriter'], 'tactic/ufbv')
add_lib('sat_solver', ['solver', 'core_tactics', 'aig_tactic', 'bv_tactics', 'arith_tactics', 'sat_tactic'], 'sat/sat_solver')
add_lib('smtlogic_tactics', ['ackermannization', 'sat_solver', 'arith_tactics', 'bv_tactics', 'nlsat_tactic', 'smt_tactic', 'aig_tactic', 'fp', 'muz','qe','nlsat_smt_tactic'], 'tactic/smtlogics')
add_lib('smtlogic_tactics', ['ackermannization', 'sat_solver', 'arith_tactics', 'bv_tactics', 'nlsat_tactic', 'smt_tactic', 'aig_tactic', 'fp', 'muz','qe'], 'tactic/smtlogics')
add_lib('fpa_tactics', ['fpa', 'core_tactics', 'bv_tactics', 'sat_tactic', 'smt_tactic', 'arith_tactics', 'smtlogic_tactics'], 'tactic/fpa')
add_lib('portfolio', ['smtlogic_tactics', 'sat_solver', 'ufbv_tactic', 'fpa_tactics', 'aig_tactic', 'fp', 'qe','sls_tactic', 'subpaving_tactic'], 'tactic/portfolio')
add_lib('opt', ['smt', 'smtlogic_tactics', 'sls_tactic', 'sat_solver'], 'opt')
API_files = ['z3_api.h', 'z3_ast_containers.h', 'z3_algebraic.h', 'z3_polynomial.h', 'z3_rcf.h', 'z3_fixedpoint.h', 'z3_optimization.h', 'z3_interp.h', 'z3_fpa.h', 'z3_spacer.h']
add_lib('api', ['portfolio', 'realclosure', 'interp', 'opt'],
API_files = ['z3_api.h', 'z3_ast_containers.h', 'z3_algebraic.h', 'z3_polynomial.h', 'z3_rcf.h', 'z3_fixedpoint.h', 'z3_optimization.h', 'z3_fpa.h', 'z3_spacer.h']
add_lib('api', ['portfolio', 'realclosure', 'opt'],
includes2install=['z3.h', 'z3_v1.h', 'z3_macros.h'] + API_files)
add_lib('extra_cmds', ['cmd_context', 'subpaving_tactic', 'qe', 'arith_tactics'], 'cmd_context/extra_cmds')
add_exe('shell', ['api', 'sat', 'extra_cmds','opt'], exe_name='z3')
add_exe('test', ['api', 'fuzzing', 'simplex'], exe_name='test-z3', install=False)
_libz3Component = add_dll('api_dll', ['api', 'sat', 'extra_cmds'], 'api/dll',

View file

@ -69,6 +69,7 @@ IS_WINDOWS=False
IS_LINUX=False
IS_OSX=False
IS_FREEBSD=False
IS_NETBSD=False
IS_OPENBSD=False
IS_CYGWIN=False
IS_CYGWIN_MINGW=False
@ -141,6 +142,9 @@ def is_linux():
def is_freebsd():
return IS_FREEBSD
def is_netbsd():
return IS_NETBSD
def is_openbsd():
return IS_OPENBSD
@ -604,6 +608,8 @@ elif os.name == 'posix':
IS_LINUX=True
elif os.uname()[0] == 'FreeBSD':
IS_FREEBSD=True
elif os.uname()[0] == 'NetBSD':
IS_NETBSD=True
elif os.uname()[0] == 'OpenBSD':
IS_OPENBSD=True
elif os.uname()[0][:6] == 'CYGWIN':
@ -889,8 +895,13 @@ def is_CXX_gpp():
return is_compiler(CXX, 'g++')
def is_clang_in_gpp_form(cc):
version_string = check_output([cc, '--version']).encode('utf-8').decode('utf-8')
return version_string.find('clang') != -1
str = check_output([cc, '--version'])
try:
version_string = str.encode('utf-8')
except:
version_string = str
clang = 'clang'.encode('utf-8')
return version_string.find(clang) != -1
def is_CXX_clangpp():
if is_compiler(CXX, 'g++'):
@ -1240,7 +1251,7 @@ def get_so_ext():
sysname = os.uname()[0]
if sysname == 'Darwin':
return 'dylib'
elif sysname == 'Linux' or sysname == 'FreeBSD' or sysname == 'OpenBSD':
elif sysname == 'Linux' or sysname == 'FreeBSD' or sysname == 'NetBSD' or sysname == 'OpenBSD':
return 'so'
elif sysname == 'CYGWIN' or sysname.startswith('MSYS_NT') or sysname.startswith('MINGW'):
return 'dll'
@ -1790,6 +1801,8 @@ class JavaDLLComponent(Component):
t = t.replace('PLATFORM', 'linux')
elif IS_FREEBSD:
t = t.replace('PLATFORM', 'freebsd')
elif IS_NETBSD:
t = t.replace('PLATFORM', 'netbsd')
elif IS_OPENBSD:
t = t.replace('PLATFORM', 'openbsd')
elif IS_CYGWIN:
@ -1919,8 +1932,14 @@ class MLComponent(Component):
OCAML_FLAGS = ''
if DEBUG_MODE:
OCAML_FLAGS += '-g'
OCAMLCF = OCAMLC + ' ' + OCAML_FLAGS
OCAMLOPTF = OCAMLOPT + ' ' + OCAML_FLAGS
if OCAMLFIND:
# Load Big_int, which is no longer part of the standard library, via the num package: https://github.com/ocaml/num
OCAMLCF = OCAMLFIND + ' ' + 'ocamlc -package num' + ' ' + OCAML_FLAGS
OCAMLOPTF = OCAMLFIND + ' ' + 'ocamlopt -package num' + ' ' + OCAML_FLAGS
else:
OCAMLCF = OCAMLC + ' ' + OCAML_FLAGS
OCAMLOPTF = OCAMLOPT + ' ' + OCAML_FLAGS
src_dir = self.to_src_dir
mk_dir(os.path.join(BUILD_DIR, self.sub_dir))
@ -2492,6 +2511,7 @@ def mk_config():
LDFLAGS = '%s -lrt' % LDFLAGS
SLIBFLAGS = '-shared'
SLIBEXTRAFLAGS = '%s -lrt' % SLIBEXTRAFLAGS
SLIBEXTRAFLAGS = '%s -Wl,-soname,libz3.so' % SLIBEXTRAFLAGS
elif sysname == 'FreeBSD':
CXXFLAGS = '%s -D_FREEBSD_' % CXXFLAGS
OS_DEFINES = '-D_FREEBSD_'
@ -2499,6 +2519,13 @@ def mk_config():
LDFLAGS = '%s -lrt' % LDFLAGS
SLIBFLAGS = '-shared'
SLIBEXTRAFLAGS = '%s -lrt' % SLIBEXTRAFLAGS
elif sysname == 'NetBSD':
CXXFLAGS = '%s -D_NETBSD_' % CXXFLAGS
OS_DEFINES = '-D_NETBSD_'
SO_EXT = '.so'
LDFLAGS = '%s -lrt' % LDFLAGS
SLIBFLAGS = '-shared'
SLIBEXTRAFLAGS = '%s -lrt' % SLIBEXTRAFLAGS
elif sysname == 'OpenBSD':
CXXFLAGS = '%s -D_OPENBSD_' % CXXFLAGS
OS_DEFINES = '-D_OPENBSD_'
@ -2783,6 +2810,7 @@ def get_header_files_for_components(component_src_dirs):
def mk_install_tactic_cpp(cnames, path):
component_src_dirs = []
for cname in cnames:
print("Component %s" % cname)
c = get_component(cname)
component_src_dirs.append(c.src_dir)
h_files_full_path = get_header_files_for_components(component_src_dirs)

View file

@ -60,7 +60,7 @@ FIRST_OBJ_ID = 100
def is_obj(ty):
return ty >= FIRST_OBJ_ID
Type2Str = { VOID : 'void', VOID_PTR : 'void*', INT : 'int', UINT : 'unsigned', INT64 : '__int64', UINT64 : '__uint64', DOUBLE : 'double',
Type2Str = { VOID : 'void', VOID_PTR : 'void*', INT : 'int', UINT : 'unsigned', INT64 : 'int64_t', UINT64 : 'uint64_t', DOUBLE : 'double',
FLOAT : 'float', STRING : 'Z3_string', STRING_PTR : 'Z3_string_ptr', BOOL : 'Z3_bool', SYMBOL : 'Z3_symbol',
PRINT_MODE : 'Z3_ast_print_mode', ERROR_CODE : 'Z3_error_code'
}
@ -577,9 +577,6 @@ def mk_java(java_dir, package_name):
java_wrapper = open(java_wrapperf, 'w')
pkg_str = package_name.replace('.', '_')
java_wrapper.write('// Automatically generated file\n')
java_wrapper.write('#ifdef _CYGWIN\n')
java_wrapper.write('typedef long long __int64;\n')
java_wrapper.write('#endif\n')
java_wrapper.write('#include<jni.h>\n')
java_wrapper.write('#include<stdlib.h>\n')
java_wrapper.write('#include"z3.h"\n')
@ -957,11 +954,16 @@ def def_API(name, result, params):
log_c.write(" }\n")
log_c.write(" Au(a%s);\n" % sz)
exe_c.write("in.get_uint_array(%s)" % i)
elif ty == INT or ty == BOOL:
elif ty == INT:
log_c.write("U(a%s[i]);" % i)
log_c.write(" }\n")
log_c.write(" Au(a%s);\n" % sz)
exe_c.write("in.get_int_array(%s)" % i)
elif ty == BOOL:
log_c.write("U(a%s[i]);" % i)
log_c.write(" }\n")
log_c.write(" Au(a%s);\n" % sz)
exe_c.write("in.get_bool_array(%s)" % i)
else:
error ("unsupported parameter for %s, %s, %s" % (ty, name, p))
elif kind == OUT_ARRAY:
@ -1655,7 +1657,7 @@ else:
if hasattr(builtins, "Z3_LIB_DIRS"):
_all_dirs = builtins.Z3_LIB_DIRS
for v in ('Z3_LIBRARY_PATH', 'PATH'):
for v in ('Z3_LIBRARY_PATH', 'PATH', 'PYTHONPATH'):
if v in os.environ:
lp = os.environ[v];
lds = lp.split(';') if sys.platform in ('win32') else lp.split(':')
@ -1696,7 +1698,11 @@ if _lib is None:
def _to_ascii(s):
if isinstance(s, str):
return s.encode('ascii')
try:
return s.encode('ascii')
except:
# kick the bucket down the road. :-J
return s
else:
return s

18
scripts/vsts-mac.sh Normal file
View file

@ -0,0 +1,18 @@
#!/bin/sh
cd ..
mkdir build
CSC=/usr/bin/csc GACUTIL=/usr/bin/gacutil CXX=clang++ CC=clang python scripts/mk_make.py --java --python
cd build
make
make test-z3
make cpp_example
make c_example
# make java_example
# make python_example
./cpp_example
./test_capi
git clone https://github.com/z3prover/z3test.git z3test
ls
python z3test/scripts/test_benchmarks.py ./z3 ./z3test/regressions/smt2

49
scripts/vsts-vs2013.cmd Normal file
View file

@ -0,0 +1,49 @@
set
echo "Build"
md build
cd build
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64
cmake -DBUILD_DOTNET_BINDINGS=True -DBUILD_JAVA_BINDINGS=True -DBUILD_PYTHON_BINDINGS=True -G "NMake Makefiles" ../
nmake
if ERRORLEVEL 1 exit 1
rem echo "Test python bindings"
rem pushd python
rem python z3test.py z3
rem if ERRORLEVEL 1 exit 1
rem python z3test.py z3num
rem if ERRORLEVEL 1 exit 1
rem popd
echo "Build and run examples"
nmake cpp_example
examples\cpp_example_build_dir\cpp_example.exe
if ERRORLEVEL 1 exit 1
nmake c_example
examples\c_example_build_dir\c_example.exe
if ERRORLEVEL 1 exit 1
rem nmake java_example
rem java_example.exe
if ERRORLEVEL 1 exit 1
rem nmake dotnet_example
rem dotnet_example.exe
if ERRORLEVEL 1 exit 1
echo "Build and run unit tests"
nmake test-z3
rem TBD: test error level
rem test-z3.exe -a
cd ..
echo "Run regression tests"
git clone https://github.com/z3prover/z3test z3test
echo "test-benchmarks"
python z3test\scripts\test_benchmarks.py build\z3.exe z3test\regressions\smt2
if ERRORLEVEL 1 exit 1
echo "benchmarks tested"

51
scripts/vsts-vs2017.cmd Normal file
View file

@ -0,0 +1,51 @@
rem Supply argument x64 or x86
echo "Build"
md build
cd build
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %1
cmake -DBUILD_DOTNET_BINDINGS=True -DBUILD_JAVA_BINDINGS=True -DBUILD_PYTHON_BINDINGS=True -G "NMake Makefiles" ../
nmake
if ERRORLEVEL 1 exit 1
if %1 == "x86" goto :BUILD_EXAMPLES
echo "Test python bindings"
pushd python
python z3test.py z3
if ERRORLEVEL 1 exit 1
python z3test.py z3num
if ERRORLEVEL 1 exit 1
popd
:BUILD_EXAMPLES
echo "Build and run examples"
nmake cpp_example
examples\cpp_example_build_dir\cpp_example.exe
if ERRORLEVEL 1 exit 1
nmake c_example
examples\c_example_build_dir\c_example.exe
if ERRORLEVEL 1 exit 1
rem nmake java_example
rem java_example.exe
if ERRORLEVEL 1 exit 1
rem nmake dotnet_example
rem dotnet_example.exe
if ERRORLEVEL 1 exit 1
echo "Build and run unit tests"
nmake test-z3
rem TBD: test error level
rem test-z3.exe -a
cd ..
echo "Run regression tests"
git clone https://github.com/z3prover/z3test z3test
echo "test-benchmarks"
python z3test\scripts\test_benchmarks.py build\z3.exe z3test\regressions\smt2
if ERRORLEVEL 1 exit 1
echo "benchmarks tested"

View file

@ -12,7 +12,6 @@ set(Z3_API_HEADER_FILES_TO_SCAN
z3_rcf.h
z3_fixedpoint.h
z3_optimization.h
z3_interp.h
z3_fpa.h
z3_spacer.h
)
@ -36,10 +35,10 @@ endforeach()
# raised if you try to declare a component is dependent on another component
# that has not yet been declared.
add_subdirectory(util)
add_subdirectory(util/lp)
add_subdirectory(math/polynomial)
add_subdirectory(sat)
add_subdirectory(nlsat)
add_subdirectory(util/lp)
add_subdirectory(math/hilbert)
add_subdirectory(math/simplex)
add_subdirectory(math/automata)
@ -56,14 +55,13 @@ add_subdirectory(parsers/util)
add_subdirectory(math/grobner)
add_subdirectory(math/euclid)
add_subdirectory(tactic/core)
add_subdirectory(sat/tactic)
add_subdirectory(tactic/arith)
add_subdirectory(nlsat/tactic)
add_subdirectory(math/subpaving/tactic)
add_subdirectory(tactic/aig)
add_subdirectory(solver)
add_subdirectory(sat/tactic)
add_subdirectory(tactic/arith)
add_subdirectory(nlsat/tactic)
add_subdirectory(ackermannization)
add_subdirectory(interp)
add_subdirectory(cmd_context)
add_subdirectory(cmd_context/extra_cmds)
add_subdirectory(parsers/smt2)
@ -79,20 +77,16 @@ add_subdirectory(tactic/bv)
add_subdirectory(smt/tactic)
add_subdirectory(tactic/sls)
add_subdirectory(qe)
add_subdirectory(duality)
add_subdirectory(muz/base)
add_subdirectory(muz/dataflow)
add_subdirectory(muz/transforms)
add_subdirectory(muz/rel)
add_subdirectory(muz/pdr)
add_subdirectory(muz/clp)
add_subdirectory(muz/tab)
add_subdirectory(muz/bmc)
add_subdirectory(muz/ddnf)
add_subdirectory(muz/duality)
add_subdirectory(muz/spacer)
add_subdirectory(muz/fp)
add_subdirectory(tactic/nlsat_smt)
add_subdirectory(tactic/ufbv)
add_subdirectory(sat/sat_solver)
add_subdirectory(tactic/smtlogics)
@ -160,7 +154,6 @@ set (libz3_public_headers
z3_fpa.h
z3.h
c++/z3++.h
z3_interp.h
z3_macros.h
z3_optimization.h
z3_polynomial.h

View file

@ -27,14 +27,9 @@ public:
: m(m), m_p(p)
{}
virtual ~ackermannize_bv_tactic() { }
~ackermannize_bv_tactic() override { }
virtual void operator()(goal_ref const & g,
goal_ref_buffer & result,
model_converter_ref & mc,
proof_converter_ref & pc,
expr_dependency_ref & core) {
mc = 0;
void operator()(goal_ref const & g, goal_ref_buffer & result) override {
tactic_report report("ackermannize", *g);
fail_if_unsat_core_generation("ackermannize", g);
fail_if_proof_generation("ackermannize", g);
@ -43,7 +38,7 @@ public:
expr_ref_vector flas(m);
const unsigned sz = g->size();
for (unsigned i = 0; i < sz; i++) flas.push_back(g->form(i));
lackr lackr(m, m_p, m_st, flas, NULL);
lackr lackr(m, m_p, m_st, flas, nullptr);
// mk result
goal_ref resg(alloc(goal, *g, true));
@ -52,41 +47,38 @@ public:
TRACE("ackermannize", tout << "ackermannize not run due to limit" << std::endl;);
result.reset();
result.push_back(g.get());
mc = 0;
pc = 0;
core = 0;
return;
}
result.push_back(resg.get());
// report model
if (g->models_enabled()) {
mc = mk_ackermannize_bv_model_converter(m, lackr.get_info());
resg->add(mk_ackermannize_bv_model_converter(m, lackr.get_info()));
}
resg->inc_depth();
TRACE("ackermannize", resg->display(tout << "out\n"););
SASSERT(resg->is_well_sorted());
}
void updt_params(params_ref const & _p) {
void updt_params(params_ref const & _p) override {
ackermannize_bv_tactic_params p(_p);
m_lemma_limit = p.div0_ackermann_limit();
}
virtual void collect_param_descrs(param_descrs & r) {
void collect_param_descrs(param_descrs & r) override {
ackermannize_bv_tactic_params::collect_param_descrs(r);
}
virtual void collect_statistics(statistics & st) const {
void collect_statistics(statistics & st) const override {
st.update("ackr-constraints", m_st.m_ackrs_sz);
}
virtual void reset_statistics() { m_st.reset(); }
void reset_statistics() override { m_st.reset(); }
virtual void cleanup() { }
void cleanup() override { }
virtual tactic* translate(ast_manager& m) {
tactic* translate(ast_manager& m) override {
return alloc(ackermannize_bv_tactic, m, m_p);
}
private:

View file

@ -45,7 +45,7 @@ class ackr_bound_probe : public probe {
if (a->get_num_args() == 0) return;
if (!m_ackr_helper.should_ackermannize(a)) return;
func_decl* const fd = a->get_decl();
app_set* ts = 0;
app_set* ts = nullptr;
if (!m_fun2terms.find(fd, ts)) {
ts = alloc(app_set);
m_fun2terms.insert(fd, ts);
@ -57,7 +57,7 @@ class ackr_bound_probe : public probe {
public:
ackr_bound_probe() {}
virtual result operator()(goal const & g) {
result operator()(goal const & g) override {
proc p(g.m());
unsigned sz = g.size();
expr_fast_mark1 visited;

View file

@ -65,7 +65,7 @@ class ackr_info {
}
inline app* find_term(func_decl* c) const {
app * rv = 0;
app * rv = nullptr;
m_c2t.find(c,rv);
return rv;
}

View file

@ -37,10 +37,11 @@ public:
, fixed_model(false)
{ }
virtual ~ackr_model_converter() { }
~ackr_model_converter() override { }
virtual void operator()(model_ref & md, unsigned goal_idx) {
SASSERT(goal_idx == 0);
void get_units(obj_map<expr, bool>& units) override { units.reset(); }
void operator()(model_ref & md) override {
SASSERT(!fixed_model || md.get() == 0 || (!md->get_num_constants() && !md->get_num_functions()));
model_ref& old_model = fixed_model ? abstr_model : md;
SASSERT(old_model.get());
@ -49,9 +50,7 @@ public:
md = new_model;
}
virtual void operator()(model_ref & md) { operator()(md, 0); }
virtual model_converter * translate(ast_translation & translator) {
model_converter * translate(ast_translation & translator) override {
ackr_info_ref retv_info = info->translate(translator);
if (fixed_model) {
model_ref retv_mod_ref = abstr_model->translate(translator);
@ -62,6 +61,10 @@ public:
}
}
void display(std::ostream & out) override {
out << "(ackr-model-converter)\n";
}
protected:
ast_manager & m;
const ackr_info_ref info;
@ -116,7 +119,7 @@ void ackr_model_converter::add_entry(model_evaluator & evaluator,
<< mk_ismt2_pp(value, m, 2) << "\n";
);
func_interp * fi = 0;
func_interp * fi = nullptr;
func_decl * const declaration = term->get_decl();
const unsigned sz = declaration->get_arity();
SASSERT(sz == term->get_num_args());
@ -133,7 +136,7 @@ void ackr_model_converter::add_entry(model_evaluator & evaluator,
evaluator(aarg, arg_value);
args.push_back(arg_value);
}
if (fi->get_entry(args.c_ptr()) == 0) {
if (fi->get_entry(args.c_ptr()) == nullptr) {
TRACE("ackr_model",
tout << mk_ismt2_pp(declaration, m) << " args: " << std::endl;
for (unsigned i = 0; i < args.size(); i++)
@ -144,6 +147,7 @@ void ackr_model_converter::add_entry(model_evaluator & evaluator,
else {
TRACE("ackr_model", tout << "entry already present\n";);
}
}
model_converter * mk_ackr_model_converter(ast_manager & m, const ackr_info_ref& info) {

View file

@ -185,7 +185,7 @@ void lackr::add_term(app* a) {
if (a->get_num_args() == 0) return;
if (!m_ackr_helper.should_ackermannize(a)) return;
func_decl* const fd = a->get_decl();
app_set* ts = 0;
app_set* ts = nullptr;
if (!m_fun2terms.find(fd, ts)) {
ts = alloc(app_set);
m_fun2terms.insert(fd, ts);
@ -205,7 +205,7 @@ lbool lackr::eager() {
SASSERT(m_is_init);
push_abstraction();
TRACE("lackr", tout << "run sat 0\n"; );
const lbool rv0 = m_sat->check_sat(0, 0);
const lbool rv0 = m_sat->check_sat(0, nullptr);
if (rv0 == l_false) return l_false;
eager_enc();
expr_ref all(m_m);
@ -213,7 +213,7 @@ lbool lackr::eager() {
m_simp(all);
m_sat->assert_expr(all);
TRACE("lackr", tout << "run sat all\n"; );
return m_sat->check_sat(0, 0);
return m_sat->check_sat(0, nullptr);
}
lbool lackr::lazy() {
@ -225,7 +225,7 @@ lbool lackr::lazy() {
m_st.m_it++;
checkpoint();
TRACE("lackr", tout << "lazy check: " << m_st.m_it << "\n";);
const lbool r = m_sat->check_sat(0, 0);
const lbool r = m_sat->check_sat(0, nullptr);
if (r == l_undef) return l_undef; // give up
if (r == l_false) return l_false; // abstraction unsat
// reconstruct model

View file

@ -34,7 +34,7 @@ struct lackr_model_constructor::imp {
, m_conflicts(conflicts)
, m_b_rw(m)
, m_bv_rw(m)
, m_evaluator(NULL)
, m_evaluator(nullptr)
, m_empty_model(m)
, m_ackr_helper(m)
{}
@ -121,7 +121,7 @@ struct lackr_model_constructor::imp {
void add_entry(app* term, expr* value,
obj_map<func_decl, func_interp*>& interpretations) {
func_interp* fi = 0;
func_interp* fi = nullptr;
func_decl * const declaration = term->get_decl();
const unsigned sz = declaration->get_arity();
SASSERT(sz == term->get_num_args());
@ -169,7 +169,7 @@ struct lackr_model_constructor::imp {
// Stops upon the first failure.
// Returns true if and only if all congruence checks succeeded.
bool _check_stack() {
if (m_evaluator == NULL) m_evaluator = alloc(model_evaluator, m_empty_model);
if (m_evaluator == nullptr) m_evaluator = alloc(model_evaluator, m_empty_model);
expr * curr;
while (!m_stack.empty()) {
curr = m_stack.back();
@ -276,7 +276,7 @@ struct lackr_model_constructor::imp {
SASSERT(a->get_num_args() == 0);
func_decl * const fd = a->get_decl();
expr * val = m_abstr_model->get_const_interp(fd);
if (val == 0) { // TODO: avoid model completetion?
if (val == nullptr) { // TODO: avoid model completetion?
sort * s = fd->get_range();
val = m_abstr_model->get_some_value(s);
}
@ -295,7 +295,7 @@ struct lackr_model_constructor::imp {
expr_ref value(m_m);
value = m_abstr_model->get_const_interp(ac->get_decl());
// get ackermann constant's interpretation
if (value.get() == 0) { // TODO: avoid model completion?
if (value.get() == nullptr) { // TODO: avoid model completion?
sort * s = a_fd->get_range();
value = m_abstr_model->get_some_value(s);
}
@ -362,7 +362,7 @@ struct lackr_model_constructor::imp {
};
lackr_model_constructor::lackr_model_constructor(ast_manager& m, ackr_info_ref info)
: m_imp(0)
: m_imp(nullptr)
, m_m(m)
, m_state(UNKNOWN)
, m_info(info)
@ -377,7 +377,7 @@ bool lackr_model_constructor::check(model_ref& abstr_model) {
m_conflicts.reset();
if (m_imp) {
dealloc(m_imp);
m_imp = 0;
m_imp = nullptr;
}
m_imp = alloc(lackr_model_constructor::imp, m_m, m_info, abstr_model, m_conflicts);
const bool rv = m_imp->check();

View file

@ -28,10 +28,9 @@ public:
, model_constructor(lmc)
{ }
virtual ~lackr_model_converter_lazy() { }
~lackr_model_converter_lazy() override { }
virtual void operator()(model_ref & md, unsigned goal_idx) {
SASSERT(goal_idx == 0);
void operator()(model_ref & md) override {
SASSERT(md.get() == 0 || (!md->get_num_constants() && !md->get_num_functions()));
SASSERT(model_constructor.get());
model * new_model = alloc(model, m);
@ -39,15 +38,18 @@ public:
model_constructor->make_model(md);
}
virtual void operator()(model_ref & md) {
operator()(md, 0);
}
void get_units(obj_map<expr, bool>& units) override { units.reset(); }
//void display(std::ostream & out);
virtual model_converter * translate(ast_translation & translator) {
model_converter * translate(ast_translation & translator) override {
NOT_IMPLEMENTED_YET();
}
void display(std::ostream & out) override {
out << "(lackr-model-converter)\n";
}
protected:
ast_manager& m;
const lackr_model_constructor_ref model_constructor;

View file

@ -48,7 +48,6 @@ z3_add_component(api
api_datatype.cpp
api_fpa.cpp
api_goal.cpp
api_interp.cpp
api_log.cpp
api_model.cpp
api_numeral.cpp
@ -67,7 +66,6 @@ z3_add_component(api
z3_replayer.cpp
${full_path_generated_files}
COMPONENT_DEPENDENCIES
interp
opt
portfolio
realclosure

View file

@ -162,57 +162,57 @@ extern "C" {
Z3_TRY;
LOG_Z3_algebraic_add(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
CHECK_IS_ALGEBRAIC_X(a, nullptr);
CHECK_IS_ALGEBRAIC_X(b, nullptr);
BIN_OP(+,add);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_algebraic_sub(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_sub(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
CHECK_IS_ALGEBRAIC_X(a, nullptr);
CHECK_IS_ALGEBRAIC_X(b, nullptr);
BIN_OP(-,sub);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_algebraic_mul(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_mul(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
CHECK_IS_ALGEBRAIC_X(a, nullptr);
CHECK_IS_ALGEBRAIC_X(b, nullptr);
BIN_OP(*,mul);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_algebraic_div(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_div(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(b, 0);
CHECK_IS_ALGEBRAIC_X(a, nullptr);
CHECK_IS_ALGEBRAIC_X(b, nullptr);
if ((is_rational(c, b) && get_rational(c, b).is_zero()) ||
(!is_rational(c, b) && am(c).is_zero(get_irrational(c, b)))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
BIN_OP(/,div);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_algebraic_root(Z3_context c, Z3_ast a, unsigned k) {
Z3_TRY;
LOG_Z3_algebraic_root(c, a, k);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(a, nullptr);
if (k % 2 == 0) {
if ((is_rational(c, a) && get_rational(c, a).is_neg()) ||
(!is_rational(c, a) && am(c).is_neg(get_irrational(c, a)))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
algebraic_numbers::manager & _am = am(c);
@ -229,14 +229,14 @@ extern "C" {
expr * r = au(c).mk_numeral(_r, false);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_algebraic_power(Z3_context c, Z3_ast a, unsigned k) {
Z3_TRY;
LOG_Z3_algebraic_power(c, a, k);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC_X(a, 0);
CHECK_IS_ALGEBRAIC_X(a, nullptr);
algebraic_numbers::manager & _am = am(c);
scoped_anum _r(_am);
if (is_rational(c, a)) {
@ -251,7 +251,7 @@ extern "C" {
expr * r = au(c).mk_numeral(_r, false);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
#define BIN_PRED(RAT_PRED, IRAT_PRED) \
@ -345,9 +345,9 @@ extern "C" {
public:
vector_var2anum(scoped_anum_vector & as):m_as(as) {}
virtual ~vector_var2anum() {}
virtual algebraic_numbers::manager & m() const { return m_as.m(); }
virtual bool contains(polynomial::var x) const { return static_cast<unsigned>(x) < m_as.size(); }
virtual algebraic_numbers::anum const & operator()(polynomial::var x) const { return m_as.get(x); }
algebraic_numbers::manager & m() const override { return m_as.m(); }
bool contains(polynomial::var x) const override { return static_cast<unsigned>(x) < m_as.size(); }
algebraic_numbers::anum const & operator()(polynomial::var x) const override { return m_as.get(x); }
};
Z3_ast_vector Z3_API Z3_algebraic_roots(Z3_context c, Z3_ast p, unsigned n, Z3_ast a[]) {
@ -357,17 +357,17 @@ extern "C" {
polynomial::manager & pm = mk_c(c)->pm();
polynomial_ref _p(pm);
polynomial::scoped_numeral d(pm.m());
expr2polynomial converter(mk_c(c)->m(), pm, 0, true);
expr2polynomial converter(mk_c(c)->m(), pm, nullptr, true);
if (!converter.to_polynomial(to_expr(p), _p, d) ||
static_cast<unsigned>(max_var(_p)) >= n + 1) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
algebraic_numbers::manager & _am = am(c);
scoped_anum_vector as(_am);
if (!to_anum_vector(c, n, a, as)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
scoped_anum_vector roots(_am);
{
@ -383,7 +383,7 @@ extern "C" {
result->m_ast_vector.push_back(au(c).mk_numeral(roots.get(i), false));
}
RETURN_Z3(of_ast_vector(result));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
int Z3_API Z3_algebraic_eval(Z3_context c, Z3_ast p, unsigned n, Z3_ast a[]) {
@ -393,7 +393,7 @@ extern "C" {
polynomial::manager & pm = mk_c(c)->pm();
polynomial_ref _p(pm);
polynomial::scoped_numeral d(pm.m());
expr2polynomial converter(mk_c(c)->m(), pm, 0, true);
expr2polynomial converter(mk_c(c)->m(), pm, nullptr, true);
if (!converter.to_polynomial(to_expr(p), _p, d) ||
static_cast<unsigned>(max_var(_p)) >= n) {
SET_ERROR_CODE(Z3_INVALID_ARG);

View file

@ -34,7 +34,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_sort r = of_sort(mk_c(c)->m().mk_sort(mk_c(c)->get_arith_fid(), INT_SORT));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_real_sort(Z3_context c) {
@ -43,7 +43,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_sort r = of_sort(mk_c(c)->m().mk_sort(mk_c(c)->get_arith_fid(), REAL_SORT));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_real(Z3_context c, int num, int den) {
@ -52,12 +52,12 @@ extern "C" {
RESET_ERROR_CODE();
if (den == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
sort* s = mk_c(c)->m().mk_sort(mk_c(c)->get_arith_fid(), REAL_SORT);
ast* a = mk_c(c)->mk_numeral_core(rational(num, den), s);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
MK_ARITH_OP(Z3_mk_add, OP_ADD);
@ -77,11 +77,11 @@ extern "C" {
k = OP_DIV;
}
expr * args[2] = { to_expr(n1), to_expr(n2) };
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_arith_fid(), k, 0, 0, 2, args);
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_arith_fid(), k, 0, nullptr, 2, args);
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
MK_ARITH_PRED(Z3_mk_lt, OP_LT);
@ -98,17 +98,17 @@ extern "C" {
RESET_ERROR_CODE();
if (num_args == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr* r = to_expr(args[0]);
for (unsigned i = 1; i < num_args; ++i) {
expr* args1[2] = { r, to_expr(args[i]) };
r = mk_c(c)->m().mk_app(mk_c(c)->get_arith_fid(), OP_SUB, 0, 0, 2, args1);
r = mk_c(c)->m().mk_app(mk_c(c)->get_arith_fid(), OP_SUB, 0, nullptr, 2, args1);
check_sorts(c, r);
}
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_unary_minus(Z3_context c, Z3_ast n) {
@ -116,7 +116,7 @@ extern "C" {
LOG_Z3_mk_unary_minus(c, n);
RESET_ERROR_CODE();
MK_UNARY_BODY(Z3_mk_unary_minus, mk_c(c)->get_arith_fid(), OP_UMINUS, SKIP);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a) {
@ -134,7 +134,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!Z3_is_algebraic_number(c, a)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr * e = to_expr(a);
algebraic_numbers::anum const & val = mk_c(c)->autil().to_irrational_algebraic_numeral(e);
@ -143,7 +143,7 @@ extern "C" {
expr * r = mk_c(c)->autil().mk_numeral(l, false);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_get_algebraic_number_upper(Z3_context c, Z3_ast a, unsigned precision) {
@ -152,7 +152,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!Z3_is_algebraic_number(c, a)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr * e = to_expr(a);
algebraic_numbers::anum const & val = mk_c(c)->autil().to_irrational_algebraic_numeral(e);
@ -161,7 +161,7 @@ extern "C" {
expr * r = mk_c(c)->autil().mk_numeral(l, false);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_get_numerator(Z3_context c, Z3_ast a) {
@ -172,12 +172,12 @@ extern "C" {
ast * _a = to_ast(a);
if (!is_expr(_a) || !mk_c(c)->autil().is_numeral(to_expr(_a), val)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr * r = mk_c(c)->autil().mk_numeral(numerator(val), true);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a) {
@ -188,12 +188,12 @@ extern "C" {
ast * _a = to_ast(a);
if (!is_expr(_a) || !mk_c(c)->autil().is_numeral(to_expr(_a), val)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr * r = mk_c(c)->autil().mk_numeral(denominator(val), true);
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -31,7 +31,7 @@ extern "C" {
sort * ty = mk_c(c)->m().mk_sort(mk_c(c)->get_array_fid(), ARRAY_SORT, 2, params);
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_array_sort_n(Z3_context c, unsigned n, Z3_sort const* domain, Z3_sort range) {
@ -44,7 +44,7 @@ extern "C" {
sort * ty = mk_c(c)->m().mk_sort(mk_c(c)->get_array_fid(), ARRAY_SORT, params.size(), params.c_ptr());
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_select(Z3_context c, Z3_ast a, Z3_ast i) {
@ -58,7 +58,7 @@ extern "C" {
sort * i_ty = m.get_sort(_i);
if (a_ty->get_family_id() != mk_c(c)->get_array_fid()) {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
sort * domain[2] = {a_ty, i_ty};
func_decl * d = m.mk_func_decl(mk_c(c)->get_array_fid(), OP_SELECT, 2, a_ty->get_parameters(), 2, domain);
@ -67,7 +67,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_select_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const* idxs) {
@ -81,7 +81,7 @@ extern "C" {
// sort * i_ty = m.get_sort(_i);
if (a_ty->get_family_id() != mk_c(c)->get_array_fid()) {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<sort> domain;
ptr_vector<expr> args;
@ -96,7 +96,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_store(Z3_context c, Z3_ast a, Z3_ast i, Z3_ast v) {
@ -112,7 +112,7 @@ extern "C" {
sort * v_ty = m.get_sort(_v);
if (a_ty->get_family_id() != mk_c(c)->get_array_fid()) {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
sort * domain[3] = {a_ty, i_ty, v_ty};
func_decl * d = m.mk_func_decl(mk_c(c)->get_array_fid(), OP_STORE, 2, a_ty->get_parameters(), 3, domain);
@ -121,7 +121,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_store_n(Z3_context c, Z3_ast a, unsigned n, Z3_ast const* idxs, Z3_ast v) {
@ -135,7 +135,7 @@ extern "C" {
sort * v_ty = m.get_sort(_v);
if (a_ty->get_family_id() != mk_c(c)->get_array_fid()) {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<sort> domain;
ptr_vector<expr> args;
@ -152,7 +152,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_map(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast const* args) {
@ -161,7 +161,7 @@ extern "C" {
RESET_ERROR_CODE();
if (n == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ast_manager & m = mk_c(c)->m();
func_decl* _f = to_func_decl(f);
@ -177,7 +177,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_const_array(Z3_context c, Z3_sort domain, Z3_ast v) {
@ -196,7 +196,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_array_default(Z3_context c, Z3_ast array) {
@ -206,12 +206,12 @@ extern "C" {
ast_manager & m = mk_c(c)->m();
expr * _a = to_expr(array);
func_decl * f = m.mk_func_decl(mk_c(c)->get_array_fid(), OP_ARRAY_DEFAULT, 0, 0, 1, &_a);
func_decl * f = m.mk_func_decl(mk_c(c)->get_array_fid(), OP_ARRAY_DEFAULT, 0, nullptr, 1, &_a);
app * r = m.mk_app(f, 1, &_a);
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast mk_app_array_core(Z3_context c, Z3_sort domain, Z3_ast v) {
@ -233,7 +233,7 @@ extern "C" {
Z3_sort Z3_API Z3_mk_set_sort(Z3_context c, Z3_sort ty) {
Z3_TRY;
return Z3_mk_array_sort(c, ty, Z3_mk_bool_sort(c));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_empty_set(Z3_context c, Z3_sort domain) {
@ -242,7 +242,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_ast r = mk_app_array_core(c, domain, Z3_mk_false(c));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_full_set(Z3_context c, Z3_sort domain) {
@ -251,7 +251,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_ast r = mk_app_array_core(c, domain, Z3_mk_true(c));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
MK_NARY(Z3_mk_set_union, mk_c(c)->get_array_fid(), OP_SET_UNION, SKIP);
@ -270,7 +270,7 @@ extern "C" {
app * r = a.mk_as_array(to_func_decl(f));
mk_c(c)->save_ast_trail(r);
return of_ast(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_mk_set_member(Z3_context c, Z3_ast elem, Z3_ast set) {
@ -289,22 +289,22 @@ extern "C" {
Z3_TRY;
LOG_Z3_get_array_sort_domain(c, t);
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
CHECK_VALID_AST(t, nullptr);
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
to_sort(t)->get_decl_kind() == ARRAY_SORT) {
Z3_sort r = reinterpret_cast<Z3_sort>(to_sort(t)->get_parameter(0).get_ast());
RETURN_Z3(r);
}
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
Z3_CATCH_RETURN(0);
RETURN_Z3(nullptr);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_get_array_sort_range(Z3_context c, Z3_sort t) {
Z3_TRY;
LOG_Z3_get_array_sort_range(c, t);
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
CHECK_VALID_AST(t, nullptr);
if (to_sort(t)->get_family_id() == mk_c(c)->get_array_fid() &&
to_sort(t)->get_decl_kind() == ARRAY_SORT) {
unsigned n = to_sort(t)->get_num_parameters();
@ -312,8 +312,8 @@ extern "C" {
RETURN_Z3(r);
}
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
Z3_CATCH_RETURN(0);
RETURN_Z3(nullptr);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -49,11 +49,11 @@ extern "C" {
RESET_ERROR_CODE();
if (i < 0 || (size_t)i >= (SIZE_MAX >> PTR_ALIGNMENT)) {
SET_ERROR_CODE(Z3_IOB);
return 0;
return nullptr;
}
Z3_symbol result = of_symbol(symbol(i));
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_symbol Z3_API Z3_mk_string_symbol(Z3_context c, char const * str) {
@ -61,13 +61,13 @@ extern "C" {
LOG_Z3_mk_string_symbol(c, str);
RESET_ERROR_CODE();
symbol s;
if (str == 0 || *str == 0)
if (str == nullptr || *str == 0)
s = symbol::null;
else
s = symbol(str);
Z3_symbol result = of_symbol(s);
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2) {
@ -82,7 +82,7 @@ extern "C" {
sort* ty = mk_c(c)->m().mk_uninterpreted_sort(to_symbol(name));
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast s1, Z3_ast s2) {
@ -107,7 +107,7 @@ extern "C" {
mk_c(c)->save_ast_trail(d);
RETURN_Z3(of_func_decl(d));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const * args) {
@ -123,7 +123,7 @@ extern "C" {
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_const(Z3_context c, Z3_symbol s, Z3_sort ty) {
@ -133,7 +133,7 @@ extern "C" {
app* a = mk_c(c)->m().mk_const(mk_c(c)->m().mk_const_decl(to_symbol(s), to_sort(ty)));
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
@ -142,7 +142,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_fresh_func_decl(c, prefix, domain_size, domain, range);
RESET_ERROR_CODE();
if (prefix == 0) {
if (prefix == nullptr) {
prefix = "";
}
@ -153,20 +153,20 @@ extern "C" {
mk_c(c)->save_ast_trail(d);
RETURN_Z3(of_func_decl(d));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fresh_const(Z3_context c, const char * prefix, Z3_sort ty) {
Z3_TRY;
LOG_Z3_mk_fresh_const(c, prefix, ty);
RESET_ERROR_CODE();
if (prefix == 0) {
if (prefix == nullptr) {
prefix = "";
}
app* a = mk_c(c)->m().mk_fresh_const(prefix, to_sort(ty));
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_true(Z3_context c) {
@ -175,7 +175,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_ast r = of_ast(mk_c(c)->m().mk_true());
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_false(Z3_context c) {
@ -184,18 +184,17 @@ extern "C" {
RESET_ERROR_CODE();
Z3_ast r = of_ast(mk_c(c)->m().mk_false());
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
MK_UNARY(Z3_mk_not, mk_c(c)->get_basic_fid(), OP_NOT, SKIP);
MK_BINARY(Z3_mk_eq, mk_c(c)->get_basic_fid(), OP_EQ, SKIP);
MK_NARY(Z3_mk_distinct, mk_c(c)->get_basic_fid(), OP_DISTINCT, SKIP);
MK_BINARY(Z3_mk_iff, mk_c(c)->get_basic_fid(), OP_IFF, SKIP);
MK_BINARY(Z3_mk_iff, mk_c(c)->get_basic_fid(), OP_EQ, SKIP);
MK_BINARY(Z3_mk_implies, mk_c(c)->get_basic_fid(), OP_IMPLIES, SKIP);
MK_BINARY(Z3_mk_xor, mk_c(c)->get_basic_fid(), OP_XOR, SKIP);
MK_NARY(Z3_mk_and, mk_c(c)->get_basic_fid(), OP_AND, SKIP);
MK_NARY(Z3_mk_or, mk_c(c)->get_basic_fid(), OP_OR, SKIP);
MK_UNARY(Z3_mk_interpolant, mk_c(c)->get_basic_fid(), OP_INTERP, SKIP);
Z3_ast mk_ite_core(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_ast t3) {
expr * result = mk_c(c)->m().mk_ite(to_expr(t1), to_expr(t2), to_expr(t3));
@ -210,7 +209,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_ast r = mk_ite_core(c, t1, t2, t3);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_bool_sort(Z3_context c) {
@ -219,7 +218,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_sort r = of_sort(mk_c(c)->m().mk_sort(mk_c(c)->m().get_basic_family_id(), BOOL_SORT));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_app_to_ast(Z3_context c, Z3_app a) {
@ -335,7 +334,7 @@ extern "C" {
Z3_bool Z3_API Z3_is_app(Z3_context c, Z3_ast a) {
LOG_Z3_is_app(c, a);
RESET_ERROR_CODE();
return a != 0 && is_app(reinterpret_cast<ast*>(a));
return a != nullptr && is_app(reinterpret_cast<ast*>(a));
}
Z3_app Z3_API Z3_to_app(Z3_context c, Z3_ast a) {
@ -357,7 +356,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_app(reinterpret_cast<ast*>(a))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
RETURN_Z3(of_func_decl(to_app(a)->get_decl()));
}
@ -373,11 +372,11 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_app(reinterpret_cast<ast*>(a))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
if (i >= to_app(a)->get_num_args()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
RETURN_Z3(of_ast(to_app(a)->get_arg(i)));
}
@ -466,15 +465,15 @@ extern "C" {
RESET_ERROR_CODE();
if (idx >= to_func_decl(d)->get_num_parameters()) {
SET_ERROR_CODE(Z3_IOB);
return 0;
return nullptr;
}
parameter const& p = to_func_decl(d)->get_parameters()[idx];
if (!p.is_symbol()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
return of_symbol(p.get_symbol());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_get_decl_sort_parameter(Z3_context c, Z3_func_decl d, unsigned idx) {
@ -483,15 +482,15 @@ extern "C" {
RESET_ERROR_CODE();
if (idx >= to_func_decl(d)->get_num_parameters()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
parameter const& p = to_func_decl(d)->get_parameters()[idx];
if (!p.is_ast() || !is_sort(p.get_ast())) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
RETURN_Z3(of_sort(to_sort(p.get_ast())));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_get_decl_ast_parameter(Z3_context c, Z3_func_decl d, unsigned idx) {
@ -500,15 +499,15 @@ extern "C" {
RESET_ERROR_CODE();
if (idx >= to_func_decl(d)->get_num_parameters()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
parameter const& p = to_func_decl(d)->get_parameters()[idx];
if (!p.is_ast()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
RETURN_Z3(of_ast(p.get_ast()));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_func_decl Z3_API Z3_get_decl_func_decl_parameter(Z3_context c, Z3_func_decl d, unsigned idx) {
@ -517,15 +516,15 @@ extern "C" {
RESET_ERROR_CODE();
if (idx >= to_func_decl(d)->get_num_parameters()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
parameter const& p = to_func_decl(d)->get_parameters()[idx];
if (!p.is_ast() || !is_func_decl(p.get_ast())) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
RETURN_Z3(of_func_decl(to_func_decl(p.get_ast())));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_get_decl_rational_parameter(Z3_context c, Z3_func_decl d, unsigned idx) {
@ -551,17 +550,17 @@ extern "C" {
LOG_Z3_get_sort_name(c, t);
RESET_ERROR_CODE();
return of_symbol(to_sort(t)->get_name());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_get_sort(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_get_sort(c, a);
RESET_ERROR_CODE();
CHECK_IS_EXPR(a, 0);
CHECK_IS_EXPR(a, nullptr);
Z3_sort r = of_sort(mk_c(c)->m().get_sort(to_expr(a)));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_get_arity(Z3_context c, Z3_func_decl d) {
@ -586,21 +585,21 @@ extern "C" {
RESET_ERROR_CODE();
if (i >= to_func_decl(d)->get_arity()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_sort r = of_sort(to_func_decl(d)->get_domain(i));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_get_range(Z3_context c, Z3_func_decl d) {
Z3_TRY;
LOG_Z3_get_range(c, d);
RESET_ERROR_CODE();
CHECK_VALID_AST(d, 0);
CHECK_VALID_AST(d, nullptr);
Z3_sort r = of_sort(to_func_decl(d)->get_range());
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort_kind Z3_get_sort_kind(Z3_context c, Z3_sort t) {
@ -688,17 +687,17 @@ extern "C" {
}
catch (z3_exception & ex) {
mk_c(c)->handle_exception(ex);
return 0;
return nullptr;
}
}
mk_c(c)->save_ast_trail(result);
return of_ast(result.get());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_simplify(Z3_context c, Z3_ast _a) {
LOG_Z3_simplify(c, _a);
RETURN_Z3(simplify(c, _a, 0));
RETURN_Z3(simplify(c, _a, nullptr));
}
Z3_ast Z3_API Z3_simplify_ex(Z3_context c, Z3_ast _a, Z3_params p) {
@ -727,7 +726,7 @@ extern "C" {
th_rewriter::get_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_update_term(Z3_context c, Z3_ast _a, unsigned num_args, Z3_ast const _args[]) {
@ -762,7 +761,7 @@ extern "C" {
}
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_substitute(Z3_context c,
@ -777,11 +776,11 @@ extern "C" {
expr * a = to_expr(_a);
expr * const * from = to_exprs(_from);
expr * const * to = to_exprs(_to);
expr * r = 0;
expr * r = nullptr;
for (unsigned i = 0; i < num_exprs; i++) {
if (m.get_sort(from[i]) != m.get_sort(to[i])) {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(of_expr(0));
RETURN_Z3(of_expr(nullptr));
}
SASSERT(from[i]->get_ref_count() > 0);
SASSERT(to[i]->get_ref_count() > 0);
@ -795,7 +794,7 @@ extern "C" {
mk_c(c)->save_ast_trail(new_a);
r = new_a.get();
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_substitute_vars(Z3_context c,
@ -813,7 +812,7 @@ extern "C" {
subst(a, num_exprs, to, new_a);
mk_c(c)->save_ast_trail(new_a);
RETURN_Z3(of_expr(new_a.get()));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_API char const * Z3_ast_to_string(Z3_context c, Z3_ast a) {
@ -839,7 +838,7 @@ extern "C" {
UNREACHABLE();
}
return mk_c(c)->mk_external_string(buffer.str());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_API char const * Z3_sort_to_string(Z3_context c, Z3_sort s) {
@ -895,12 +894,10 @@ extern "C" {
case OP_ITE: return Z3_OP_ITE;
case OP_AND: return Z3_OP_AND;
case OP_OR: return Z3_OP_OR;
case OP_IFF: return Z3_OP_IFF;
case OP_XOR: return Z3_OP_XOR;
case OP_NOT: return Z3_OP_NOT;
case OP_IMPLIES: return Z3_OP_IMPLIES;
case OP_OEQ: return Z3_OP_OEQ;
case OP_INTERP: return Z3_OP_INTERP;
case PR_UNDEF: return Z3_OP_PR_UNDEF;
case PR_TRUE: return Z3_OP_PR_TRUE;
@ -919,7 +916,6 @@ extern "C" {
case PR_REWRITE: return Z3_OP_PR_REWRITE;
case PR_REWRITE_STAR: return Z3_OP_PR_REWRITE_STAR;
case PR_PULL_QUANT: return Z3_OP_PR_PULL_QUANT;
case PR_PULL_QUANT_STAR: return Z3_OP_PR_PULL_QUANT_STAR;
case PR_PUSH_QUANT: return Z3_OP_PR_PUSH_QUANT;
case PR_ELIM_UNUSED_VARS: return Z3_OP_PR_ELIM_UNUSED_VARS;
case PR_DER: return Z3_OP_PR_DER;
@ -936,9 +932,7 @@ extern "C" {
case PR_IFF_OEQ: return Z3_OP_PR_IFF_OEQ;
case PR_NNF_POS: return Z3_OP_PR_NNF_POS;
case PR_NNF_NEG: return Z3_OP_PR_NNF_NEG;
case PR_NNF_STAR: return Z3_OP_PR_NNF_STAR;
case PR_SKOLEMIZE: return Z3_OP_PR_SKOLEMIZE;
case PR_CNF_STAR: return Z3_OP_PR_CNF_STAR;
case PR_MODUS_PONENS_OEQ: return Z3_OP_PR_MODUS_PONENS_OEQ;
case PR_TH_LEMMA: return Z3_OP_PR_TH_LEMMA;
case PR_HYPER_RESOLVE: return Z3_OP_PR_HYPER_RESOLVE;
@ -1059,6 +1053,7 @@ extern "C" {
switch(_d->get_decl_kind()) {
case OP_DT_CONSTRUCTOR: return Z3_OP_DT_CONSTRUCTOR;
case OP_DT_RECOGNISER: return Z3_OP_DT_RECOGNISER;
case OP_DT_IS: return Z3_OP_DT_IS;
case OP_DT_ACCESSOR: return Z3_OP_DT_ACCESSOR;
case OP_DT_UPDATE_FIELD: return Z3_OP_DT_UPDATE_FIELD;
default:
@ -1115,7 +1110,7 @@ extern "C" {
case _OP_STRING_SUBSTR: return Z3_OP_SEQ_EXTRACT;
case _OP_STRING_STRIDOF: return Z3_OP_SEQ_INDEX;
case _OP_REGEXP_EMPTY: return Z3_OP_RE_EMPTY_SET;
case _OP_REGEXP_FULL: return Z3_OP_RE_FULL_SET;
case _OP_REGEXP_FULL_CHAR: return Z3_OP_RE_FULL_SET;
case OP_STRING_STOI: return Z3_OP_STR_TO_INT;
case OP_STRING_ITOS: return Z3_OP_INT_TO_STR;
@ -1127,7 +1122,8 @@ extern "C" {
case OP_RE_UNION: return Z3_OP_RE_UNION;
case OP_RE_INTERSECT: return Z3_OP_RE_INTERSECT;
case OP_RE_LOOP: return Z3_OP_RE_LOOP;
case OP_RE_FULL_SET: return Z3_OP_RE_FULL_SET;
// case OP_RE_FULL_SEQ_SET: return Z3_OP_RE_FULL_SET;
case OP_RE_FULL_CHAR_SET: return Z3_OP_RE_FULL_SET;
case OP_RE_EMPTY_SET: return Z3_OP_RE_EMPTY_SET;
default:
return Z3_OP_INTERNAL;
@ -1232,17 +1228,17 @@ extern "C" {
Z3_TRY;
LOG_Z3_translate(c, a, target);
RESET_ERROR_CODE();
CHECK_VALID_AST(a, 0);
CHECK_VALID_AST(a, nullptr);
if (c == target) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
SASSERT(mk_c(c)->m().contains(to_ast(a)));
ast_translation translator(mk_c(c)->m(), mk_c(target)->m());
ast * _result = translator(to_ast(a));
mk_c(target)->save_ast_trail(_result);
RETURN_Z3(of_ast(_result));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -38,7 +38,7 @@ extern "C" {
mk_c(c)->save_object(m);
Z3_ast_map r = of_ast_map(m);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_ast_map_inc_ref(Z3_context c, Z3_ast_map m) {
@ -70,15 +70,15 @@ extern "C" {
LOG_Z3_ast_map_find(c, m, k);
RESET_ERROR_CODE();
obj_map<ast, ast*>::obj_map_entry * entry = to_ast_map_ref(m).find_core(to_ast(k));
if (entry == 0) {
if (entry == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
else {
ast * r = entry->get_data().m_value;
RETURN_Z3(of_ast(r));
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_ast_map_insert(Z3_context c, Z3_ast_map m, Z3_ast k, Z3_ast v) {
@ -115,7 +115,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_ast_map_erase(c, m, k);
RESET_ERROR_CODE();
ast * v = 0;
ast * v = nullptr;
if (to_ast_map_ref(m).find(to_ast(k), v)) {
to_ast_map_ref(m).erase(to_ast(k));
ast_manager & mng = to_ast_map(m)->m;
@ -146,7 +146,7 @@ extern "C" {
}
Z3_ast_vector r = of_ast_vector(v);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_ast_map_to_string(Z3_context c, Z3_ast_map m) {
@ -163,7 +163,7 @@ extern "C" {
}
buffer << ")";
return mk_c(c)->mk_external_string(buffer.str());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -25,7 +25,7 @@ struct Z3_ast_map_ref : public api::object {
ast_manager & m;
obj_map<ast, ast*> m_map;
Z3_ast_map_ref(api::context& c, ast_manager & _m): api::object(c), m(_m) {}
virtual ~Z3_ast_map_ref();
~Z3_ast_map_ref() override;
};
inline Z3_ast_map_ref * to_ast_map(Z3_ast_map v) { return reinterpret_cast<Z3_ast_map_ref *>(v); }

View file

@ -33,7 +33,7 @@ extern "C" {
mk_c(c)->save_object(v);
Z3_ast_vector r = of_ast_vector(v);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_ast_vector_inc_ref(Z3_context c, Z3_ast_vector v) {
@ -66,12 +66,12 @@ extern "C" {
RESET_ERROR_CODE();
if (i >= to_ast_vector_ref(v).size()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
// Remark: Don't need to invoke save_object.
ast * r = to_ast_vector_ref(v).get(i);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_ast_vector_set(Z3_context c, Z3_ast_vector v, unsigned i, Z3_ast a) {
@ -108,7 +108,7 @@ extern "C" {
RESET_ERROR_CODE();
if (c == t) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ast_translation translator(mk_c(c)->m(), mk_c(t)->m());
Z3_ast_vector_ref * new_v = alloc(Z3_ast_vector_ref, *mk_c(t), mk_c(t)->m());
@ -119,7 +119,7 @@ extern "C" {
new_v->m_ast_vector.push_back(new_ast);
}
RETURN_Z3(of_ast_vector(new_v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_ast_vector_to_string(Z3_context c, Z3_ast_vector v) {
@ -134,7 +134,7 @@ extern "C" {
}
buffer << ")";
return mk_c(c)->mk_external_string(buffer.str());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -27,7 +27,7 @@ namespace api {
struct Z3_ast_vector_ref : public api::object {
ast_ref_vector m_ast_vector;
Z3_ast_vector_ref(api::context& c, ast_manager & m): api::object(c), m_ast_vector(m) {}
virtual ~Z3_ast_vector_ref() {}
~Z3_ast_vector_ref() override {}
};
inline Z3_ast_vector_ref * to_ast_vector(Z3_ast_vector v) { return reinterpret_cast<Z3_ast_vector_ref *>(v); }

View file

@ -33,7 +33,7 @@ extern "C" {
parameter p(sz);
Z3_sort r = of_sort(mk_c(c)->m().mk_sort(mk_c(c)->get_bv_fid(), BV_SORT, 1, &p));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
#define MK_BV_UNARY(NAME, OP) MK_UNARY(NAME, mk_c(c)->get_bv_fid(), OP, SKIP)
@ -85,7 +85,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_ast r = mk_extract_core(c, high, low, n);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
#define MK_BV_PUNARY(NAME, OP) \
@ -146,7 +146,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
check_sorts(c, a);
RETURN_Z3(of_ast(a));
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
/**
@ -164,7 +164,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
unsigned sz = Z3_get_bv_sort_size(c, s);
if (sz == 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
Z3_ast x = Z3_mk_int64(c, 1, s);
Z3_inc_ref(c, x);
@ -174,7 +174,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_dec_ref(c, x);
Z3_dec_ref(c, y);
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_mk_bvsmin(Z3_context c, Z3_sort s) {
@ -229,7 +229,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_dec_ref(c, r);
return result;
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// only for signed machine integers
@ -257,7 +257,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_dec_ref(c, args_neg);
Z3_dec_ref(c, zero);
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// only for signed machine integers
@ -286,7 +286,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_dec_ref(c, z);
Z3_dec_ref(c, zero);
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_bool is_signed) {
@ -311,7 +311,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
else {
return Z3_mk_bvule(c, t2, t1);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast n1, Z3_ast n2, Z3_bool is_signed) {
@ -336,11 +336,11 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_TRY;
RESET_ERROR_CODE();
Z3_ast min = Z3_mk_bvsmin(c, Z3_get_sort(c, t));
if (Z3_get_error_code(c) != Z3_OK) return 0;
if (Z3_get_error_code(c) != Z3_OK) return nullptr;
Z3_ast eq = Z3_mk_eq(c, t, min);
if (Z3_get_error_code(c) != Z3_OK) return 0;
if (Z3_get_error_code(c) != Z3_OK) return nullptr;
return Z3_mk_not(c, eq);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// only for signed machine integers
@ -366,7 +366,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
Z3_dec_ref(c, z);
Z3_dec_ref(c, u);
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_bvsub(Z3_context c, Z3_ast n1, Z3_ast n2) {
@ -374,7 +374,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
LOG_Z3_mk_bvsub(c, n1, n2);
RESET_ERROR_CODE();
MK_BINARY_BODY(Z3_mk_bvsub, mk_c(c)->get_bv_fid(), OP_BSUB, SKIP);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_bvneg(Z3_context c, Z3_ast n) {
@ -382,7 +382,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
LOG_Z3_mk_bvneg(c, n);
RESET_ERROR_CODE();
MK_UNARY_BODY(Z3_mk_bvneg, mk_c(c)->get_bv_fid(), OP_BNEG, SKIP);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_get_bv_sort_size(Z3_context c, Z3_sort t) {

View file

@ -53,7 +53,7 @@ extern "C" {
Z3_bool_opt Z3_API Z3_global_param_get(Z3_string param_id, Z3_string_ptr param_value) {
memory::initialize(UINT_MAX);
LOG_Z3_global_param_get(param_id, param_value);
*param_value = 0;
*param_value = nullptr;
try {
g_Z3_global_param_get_buffer = gparams::get_value(param_id);
*param_value = g_Z3_global_param_get_buffer.c_str();

View file

@ -70,7 +70,7 @@ namespace api {
// ------------------------
context::context(context_params * p, bool user_ref_count):
m_params(p != 0 ? *p : context_params()),
m_params(p != nullptr ? *p : context_params()),
m_user_ref_count(user_ref_count),
m_manager(m_params.mk_ast_manager()),
m_plugins(m()),
@ -78,7 +78,6 @@ namespace api {
m_bv_util(m()),
m_datalog_util(m()),
m_fpa_util(m()),
m_dtutil(m()),
m_sutil(m()),
m_last_result(m()),
m_ast_trail(m()),
@ -89,7 +88,7 @@ namespace api {
m_searching = false;
m_interruptable = 0;
m_interruptable = nullptr;
m_error_handler = &default_error_handler;
m_basic_fid = m().get_basic_family_id();
@ -108,7 +107,7 @@ namespace api {
context::~context() {
m_last_obj = 0;
m_last_obj = nullptr;
u_map<api::object*>::iterator it = m_allocated_objects.begin();
while (it != m_allocated_objects.end()) {
api::object* val = it->m_value;
@ -131,7 +130,7 @@ namespace api {
context::set_interruptable::~set_interruptable() {
#pragma omp critical (set_interruptable)
{
m_ctx.m_interruptable = 0;
m_ctx.m_interruptable = nullptr;
}
}
@ -152,6 +151,12 @@ namespace api {
}
}
void context::reset_error_code() {
m_error_code = Z3_OK;
}
void context::check_searching() {
if (m_searching) {
set_error_code(Z3_INVALID_USAGE); // TBD: error code could be fixed.
@ -169,7 +174,7 @@ namespace api {
}
expr * context::mk_numeral_core(rational const & n, sort * s) {
expr* e = 0;
expr* e = nullptr;
family_id fid = s->get_family_id();
if (fid == m_arith_fid) {
e = m_arith_util.mk_numeral(n, s);
@ -178,7 +183,7 @@ namespace api {
e = m_bv_util.mk_numeral(n, s);
}
else if (fid == get_datalog_fid() && n.is_uint64()) {
uint64 sz;
uint64_t sz;
if (m_datalog_util.try_get_size(s, sz) &&
sz <= n.get_uint64()) {
invoke_error_handler(Z3_INVALID_ARG);
@ -233,7 +238,7 @@ namespace api {
void context::reset_last_result() {
if (m_user_ref_count)
m_last_result.reset();
m_last_obj = 0;
m_last_obj = nullptr;
}
void context::save_object(object * r) {
@ -307,7 +312,7 @@ namespace api {
//
// -----------------------
realclosure::manager & context::rcfm() {
if (m_rcf_manager.get() == 0) {
if (m_rcf_manager.get() == nullptr) {
m_rcf_manager = alloc(realclosure::manager, m_limit, m_rcf_qm);
}
return *(m_rcf_manager.get());
@ -330,7 +335,7 @@ extern "C" {
memory::initialize(UINT_MAX);
Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<context_params*>(c), false));
RETURN_Z3(r);
Z3_CATCH_RETURN_NO_HANDLE(0);
Z3_CATCH_RETURN_NO_HANDLE(nullptr);
}
Z3_context Z3_API Z3_mk_context_rc(Z3_config c) {
@ -339,7 +344,7 @@ extern "C" {
memory::initialize(UINT_MAX);
Z3_context r = reinterpret_cast<Z3_context>(alloc(api::context, reinterpret_cast<context_params*>(c), true));
RETURN_Z3(r);
Z3_CATCH_RETURN_NO_HANDLE(0);
Z3_CATCH_RETURN_NO_HANDLE(nullptr);
}
void Z3_API Z3_del_context(Z3_context c) {
@ -453,7 +458,7 @@ extern "C" {
case Z3_INTERNAL_FATAL: return "internal error";
case Z3_INVALID_USAGE: return "invalid usage";
case Z3_DEC_REF_ERROR: return "invalid dec_ref command";
case Z3_EXCEPTION: return c == 0 ? "Z3 exception" : mk_c(c)->get_exception_msg();
case Z3_EXCEPTION: return c == nullptr ? "Z3 exception" : mk_c(c)->get_exception_msg();
default: return "unknown";
}
}

View file

@ -34,6 +34,7 @@ Revision History:
#include "util/event_handler.h"
#include "cmd_context/tactic_manager.h"
#include "cmd_context/context_params.h"
#include "cmd_context/cmd_context.h"
#include "api/api_polynomial.h"
#include "util/hashtable.h"
@ -51,15 +52,15 @@ namespace api {
class context : public tactic_manager {
struct add_plugins { add_plugins(ast_manager & m); };
context_params m_params;
bool m_user_ref_count; //!< if true, the user is responsible for managing referenc counters.
bool m_user_ref_count; //!< if true, the user is responsible for managing reference counters.
scoped_ptr<ast_manager> m_manager;
scoped_ptr<cmd_context> m_cmd;
add_plugins m_plugins;
arith_util m_arith_util;
bv_util m_bv_util;
datalog::dl_decl_util m_datalog_util;
fpa_util m_fpa_util;
datatype_util m_dtutil;
seq_util m_sutil;
// Support for old solver API
@ -113,18 +114,19 @@ namespace api {
~context();
ast_manager & m() const { return *(m_manager.get()); }
context_params & params() { return m_params; }
context_params & params() { m_params.updt_params(); return m_params; }
scoped_ptr<cmd_context>& cmd() { return m_cmd; }
bool produce_proofs() const { return m().proofs_enabled(); }
bool produce_models() const { return m_params.m_model; }
bool produce_unsat_cores() const { return m_params.m_unsat_core; }
bool use_auto_config() const { return m_params.m_auto_config; }
unsigned get_timeout() const { return m_params.m_timeout; }
unsigned get_rlimit() const { return m_params.m_rlimit; }
unsigned get_rlimit() const { return m_params.rlimit(); }
arith_util & autil() { return m_arith_util; }
bv_util & bvutil() { return m_bv_util; }
datalog::dl_decl_util & datalog_util() { return m_datalog_util; }
fpa_util & fpautil() { return m_fpa_util; }
datatype_util& dtutil() { return m_dtutil; }
datatype_util& dtutil() { return m_dt_plugin->u(); }
seq_util& sutil() { return m_sutil; }
family_id get_basic_fid() const { return m_basic_fid; }
family_id get_array_fid() const { return m_array_fid; }
@ -138,7 +140,7 @@ namespace api {
datatype_decl_plugin * get_dt_plugin() const { return m_dt_plugin; }
Z3_error_code get_error_code() const { return m_error_code; }
void reset_error_code() { m_error_code = Z3_OK; }
void reset_error_code();
void set_error_code(Z3_error_code err);
void set_error_handler(Z3_error_handler h) { m_error_handler = h; }
// Sign an error if solver is searching
@ -158,7 +160,7 @@ namespace api {
// Create a numeral of the given sort
expr * mk_numeral_core(rational const & n, sort * s);
// Return a conjuction that will be exposed to the "external" world.
// Return a conjunction that will be exposed to the "external" world.
expr * mk_and(unsigned num_exprs, expr * const * exprs);
// Hack for preventing an AST for being GC when ref-count is not used

View file

@ -45,14 +45,14 @@ namespace api {
ast_ref_vector m_trail;
public:
fixedpoint_context(ast_manager& m, smt_params& p):
m_state(0),
m_reduce_app(0),
m_reduce_assign(0),
m_state(nullptr),
m_reduce_app(nullptr),
m_reduce_assign(nullptr),
m_context(m, m_register_engine, p),
m_trail(m) {}
virtual ~fixedpoint_context() {}
family_id get_family_id() const { return const_cast<datalog::context&>(m_context).get_decl_util().get_family_id(); }
~fixedpoint_context() override {}
family_id get_family_id() const override { return const_cast<datalog::context&>(m_context).get_decl_util().get_family_id(); }
void set_state(void* state) {
SASSERT(!m_state);
m_state = state;
@ -73,8 +73,8 @@ namespace api {
void set_reduce_assign(reduce_assign_callback_fptr f) {
m_reduce_assign = f;
}
virtual void reduce(func_decl* f, unsigned num_args, expr * const* args, expr_ref& result) {
expr* r = 0;
void reduce(func_decl* f, unsigned num_args, expr * const* args, expr_ref& result) override {
expr* r = nullptr;
if (m_reduce_app) {
m_reduce_app(m_state, f, num_args, args, &r);
result = r;
@ -85,12 +85,12 @@ namespace api {
m_trail.push_back(r);
}
// allow fallthrough.
if (r == 0) {
if (r == nullptr) {
ast_manager& m = m_context.get_manager();
result = m.mk_app(f, num_args, args);
}
}
virtual void reduce_assign(func_decl* f, unsigned num_args, expr * const* args, unsigned num_out, expr* const* outs) {
void reduce_assign(func_decl* f, unsigned num_args, expr * const* args, unsigned num_out, expr* const* outs) override {
if (m_reduce_assign) {
m_trail.push_back(f);
for (unsigned i = 0; i < num_args; ++i) {
@ -171,35 +171,35 @@ extern "C" {
sort * r = to_sort(s);
if (Z3_get_sort_kind(c, s) != Z3_RELATION_SORT) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
if (col >= r->get_num_parameters()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
parameter const& p = r->get_parameter(col);
if (!p.is_ast() || !is_sort(p.get_ast())) {
UNREACHABLE();
warning_msg("Sort parameter expected at %d", col);
SET_ERROR_CODE(Z3_INTERNAL_FATAL);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_sort res = of_sort(to_sort(p.get_ast()));
RETURN_Z3(res);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, __uint64 size) {
Z3_sort Z3_API Z3_mk_finite_domain_sort(Z3_context c, Z3_symbol name, uint64_t size) {
Z3_TRY;
LOG_Z3_mk_finite_domain_sort(c, name, size);
RESET_ERROR_CODE();
sort* s = mk_c(c)->datalog_util().mk_sort(to_symbol(name), size);
mk_c(c)->save_ast_trail(s);
RETURN_Z3(of_sort(s));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, __uint64 * out) {
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t * out) {
Z3_TRY;
if (out) {
*out = 0;
@ -215,7 +215,6 @@ extern "C" {
RESET_ERROR_CODE();
VERIFY(mk_c(c)->datalog_util().try_get_size(to_sort(s), *out));
return Z3_TRUE;
Z3_CATCH_RETURN(Z3_FALSE);
}
@ -228,7 +227,7 @@ extern "C" {
mk_c(c)->save_object(d);
Z3_fixedpoint r = of_datalog(d);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_fixedpoint_inc_ref(Z3_context c, Z3_fixedpoint s) {
@ -331,7 +330,7 @@ extern "C" {
expr* e = to_fixedpoint_ref(d)->ctx().get_answer_as_formula();
mk_c(c)->save_ast_trail(e);
RETURN_Z3(of_expr(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_fixedpoint_get_reason_unknown(Z3_context c,Z3_fixedpoint d) {
@ -366,7 +365,7 @@ extern "C" {
ctx.set_ignore_check(true);
if (!parse_smt2_commands(ctx, s)) {
SET_ERROR_CODE(Z3_PARSER_ERROR);
return 0;
return nullptr;
}
Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, *mk_c(c), m);
@ -398,7 +397,7 @@ extern "C" {
std::string str(s);
std::istringstream is(str);
RETURN_Z3(Z3_fixedpoint_from_stream(c, d, is));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_fixedpoint_from_file(
@ -410,10 +409,10 @@ extern "C" {
std::ifstream is(s);
if (!is) {
SET_ERROR_CODE(Z3_PARSER_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
RETURN_Z3(Z3_fixedpoint_from_stream(c, d, is));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
@ -426,7 +425,7 @@ extern "C" {
mk_c(c)->save_object(st);
Z3_stats r = of_stats(st);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_fixedpoint_register_relation(Z3_context c,Z3_fixedpoint d, Z3_func_decl f) {
@ -473,7 +472,7 @@ extern "C" {
v->m_ast_vector.push_back(m.mk_not(queries[i].get()));
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions(
@ -490,7 +489,7 @@ extern "C" {
v->m_ast_vector.push_back(to_fixedpoint_ref(d)->ctx().get_assertion(i));
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_fixedpoint_set_reduce_assign_callback(
@ -541,7 +540,7 @@ extern "C" {
expr_ref r = to_fixedpoint_ref(d)->get_cover_delta(level, to_func_decl(pred));
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r.get()));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_fixedpoint_add_cover(Z3_context c, Z3_fixedpoint d, int level, Z3_func_decl pred, Z3_ast property) {
@ -573,7 +572,7 @@ extern "C" {
to_fixedpoint_ref(f)->collect_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_fixedpoint_set_params(Z3_context c, Z3_fixedpoint d, Z3_params p) {
@ -604,7 +603,26 @@ extern "C" {
Z3_CATCH;
}
void Z3_API Z3_fixedpoint_add_callback(Z3_context c, Z3_fixedpoint d,
void *state,
Z3_fixedpoint_new_lemma_eh new_lemma_eh,
Z3_fixedpoint_predecessor_eh predecessor_eh,
Z3_fixedpoint_unfold_eh unfold_eh){
Z3_TRY;
// not logged
to_fixedpoint_ref(d)->ctx().add_callback(state,
reinterpret_cast<datalog::t_new_lemma_eh>(new_lemma_eh),
reinterpret_cast<datalog::t_predecessor_eh>(predecessor_eh),
reinterpret_cast<datalog::t_unfold_eh>(unfold_eh));
Z3_CATCH;
}
void Z3_API Z3_fixedpoint_add_constraint (Z3_context c, Z3_fixedpoint d, Z3_ast e, unsigned lvl){
to_fixedpoint_ref(d)->ctx().add_constraint(to_expr(e), lvl);
}
#include "api_datalog_spacer.inc"
};

View file

@ -37,8 +37,8 @@ namespace api {
struct Z3_fixedpoint_ref : public api::object {
api::fixedpoint_context * m_datalog;
params_ref m_params;
Z3_fixedpoint_ref(api::context& c): api::object(c), m_datalog(0) {}
virtual ~Z3_fixedpoint_ref() { dealloc(m_datalog); }
Z3_fixedpoint_ref(api::context& c): api::object(c), m_datalog(nullptr) {}
~Z3_fixedpoint_ref() override { dealloc(m_datalog); }
};
inline Z3_fixedpoint_ref * to_fixedpoint(Z3_fixedpoint s) { return reinterpret_cast<Z3_fixedpoint_ref *>(s); }

View file

@ -49,7 +49,7 @@ Notes:
expr* e = to_fixedpoint_ref(d)->ctx().get_ground_sat_answer();
mk_c(c)->save_ast_trail(e);
RETURN_Z3(of_expr(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules_along_trace(
@ -69,7 +69,7 @@ Notes:
v->m_ast_vector.push_back(rules[i].get());
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_symbol Z3_API Z3_fixedpoint_get_rule_names_along_trace(
@ -90,7 +90,7 @@ Notes:
ss << ";" << names[i].str();
}
RETURN_Z3(of_symbol(symbol(ss.str().substr(1).c_str())));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_fixedpoint_add_invariant(Z3_context c, Z3_fixedpoint d, Z3_func_decl pred, Z3_ast property) {
@ -108,6 +108,6 @@ Notes:
expr_ref r = to_fixedpoint_ref(d)->ctx().get_reachable(to_func_decl(pred));
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r.get()));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}

View file

@ -52,12 +52,12 @@ extern "C" {
{
datatype_decl * dt = mk_datatype_decl(dt_util, to_symbol(name), 0, nullptr, 1, constrs);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &dt, 0, 0, tuples);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &dt, 0, nullptr, tuples);
del_datatype_decl(dt);
if (!is_ok) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
@ -82,7 +82,7 @@ extern "C" {
proj_decls[i] = of_func_decl(_accs[i]);
}
RETURN_Z3_mk_tuple_sort(of_sort(tuple));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_enumeration_sort(Z3_context c,
@ -108,18 +108,18 @@ extern "C" {
recognizer_s += e_name.str();
symbol recognizer(recognizer_s.c_str());
constrs.push_back(mk_constructor_decl(e_name, recognizer, 0, 0));
constrs.push_back(mk_constructor_decl(e_name, recognizer, 0, nullptr));
}
{
datatype_decl * dt = mk_datatype_decl(dt_util, to_symbol(name), 0, 0, n, constrs.c_ptr());
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &dt, 0, 0, sorts);
datatype_decl * dt = mk_datatype_decl(dt_util, to_symbol(name), 0, nullptr, n, constrs.c_ptr());
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &dt, 0, nullptr, sorts);
del_datatype_decl(dt);
if (!is_ok) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
@ -137,13 +137,13 @@ extern "C" {
func_decl* decl = (decls)[i];
mk_c(c)->save_multiple_ast_trail(decl);
enum_consts[i] = of_func_decl(decl);
decl = dt_util.get_constructor_recognizer(decl);
decl = dt_util.get_constructor_is(decl);
mk_c(c)->save_multiple_ast_trail(decl);
enum_testers[i] = of_func_decl(decl);
}
RETURN_Z3_mk_enumeration_sort(of_sort(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_list_sort(Z3_context c,
@ -168,7 +168,7 @@ extern "C" {
mk_accessor_decl(m, symbol("tail"), type_ref(0))
};
constructor_decl* constrs[2] = {
mk_constructor_decl(symbol("nil"), symbol("is_nil"), 0, 0),
mk_constructor_decl(symbol("nil"), symbol("is_nil"), 0, nullptr),
// Leo: SMT 2.0 document uses 'insert' instead of cons
mk_constructor_decl(symbol("cons"), symbol("is_cons"), 2, head_tail)
};
@ -176,12 +176,12 @@ extern "C" {
sort_ref_vector sorts(m);
{
datatype_decl * decl = mk_datatype_decl(dt_util, to_symbol(name), 0, nullptr, 2, constrs);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &decl, 0, 0, sorts);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &decl, 0, nullptr, sorts);
del_datatype_decl(decl);
if (!is_ok) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
sort * s = sorts.get(0);
@ -196,7 +196,7 @@ extern "C" {
*nil_decl = of_func_decl(f);
}
if (is_nil_decl) {
f = data_util.get_constructor_recognizer(cnstrs[0]);
f = data_util.get_constructor_is(cnstrs[0]);
mk_c(c)->save_multiple_ast_trail(f);
*is_nil_decl = of_func_decl(f);
}
@ -206,7 +206,7 @@ extern "C" {
*cons_decl = of_func_decl(f);
}
if (is_cons_decl) {
f = data_util.get_constructor_recognizer(cnstrs[1]);
f = data_util.get_constructor_is(cnstrs[1]);
mk_c(c)->save_multiple_ast_trail(f);
*is_cons_decl = of_func_decl(f);
}
@ -225,7 +225,7 @@ extern "C" {
*tail_decl = of_func_decl(f);
}
RETURN_Z3_mk_list_sort(of_sort(s));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
struct constructor {
@ -259,7 +259,7 @@ extern "C" {
cnstr->m_sort_refs.push_back(sort_refs[i]);
}
RETURN_Z3(reinterpret_cast<Z3_constructor>(cnstr));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
@ -290,7 +290,7 @@ extern "C" {
*constructor_decl = of_func_decl(f);
}
if (tester) {
func_decl* f2 = data_util.get_constructor_recognizer(f);
func_decl* f2 = data_util.get_constructor_is(f);
mk_c(c)->save_multiple_ast_trail(f2);
*tester = of_func_decl(f2);
}
@ -349,12 +349,12 @@ extern "C" {
sort_ref_vector sorts(m);
{
datatype_decl * data = mk_datatype_decl(c, name, num_constructors, constructors);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &data, 0, 0, sorts);
bool is_ok = mk_c(c)->get_dt_plugin()->mk_datatypes(1, &data, 0, nullptr, sorts);
del_datatype_decl(data);
if (!is_ok) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
sort * s = sorts.get(0);
@ -367,7 +367,7 @@ extern "C" {
cn->m_constructor = cnstrs[i];
}
RETURN_Z3_mk_datatype(of_sort(s));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
typedef ptr_vector<constructor> constructor_list;
@ -383,7 +383,7 @@ extern "C" {
result->push_back(reinterpret_cast<constructor*>(constructors[i]));
}
RETURN_Z3(reinterpret_cast<Z3_constructor_list>(result));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_del_constructor_list(Z3_context c, Z3_constructor_list clist) {
@ -412,7 +412,7 @@ extern "C" {
datas.push_back(mk_datatype_decl(c, sort_names[i], cl->size(), reinterpret_cast<Z3_constructor*>(cl->c_ptr())));
}
sort_ref_vector _sorts(m);
bool ok = mk_c(c)->get_dt_plugin()->mk_datatypes(datas.size(), datas.c_ptr(), 0, 0, _sorts);
bool ok = mk_c(c)->get_dt_plugin()->mk_datatypes(datas.size(), datas.c_ptr(), 0, nullptr, _sorts);
del_datatype_decls(datas.size(), datas.c_ptr());
if (!ok) {
@ -454,17 +454,17 @@ extern "C" {
Z3_func_decl get_datatype_sort_constructor_core(Z3_context c, Z3_sort t, unsigned idx) {
RESET_ERROR_CODE();
CHECK_VALID_AST(t, 0);
CHECK_VALID_AST(t, nullptr);
sort * _t = to_sort(t);
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(_t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
ptr_vector<func_decl> const & decls = *dt_util.get_datatype_constructors(_t);
if (idx >= decls.size()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
func_decl* decl = (decls)[idx];
mk_c(c)->save_ast_trail(decl);
@ -477,7 +477,7 @@ extern "C" {
RESET_ERROR_CODE();
Z3_func_decl r = get_datatype_sort_constructor_core(c, t, idx);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_func_decl Z3_API Z3_get_datatype_sort_recognizer(Z3_context c, Z3_sort t, unsigned idx) {
@ -489,18 +489,18 @@ extern "C" {
if (!dt_util.is_datatype(_t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<func_decl> const & decls = *dt_util.get_datatype_constructors(_t);
if (idx >= decls.size()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
func_decl* decl = (decls)[idx];
decl = dt_util.get_constructor_recognizer(decl);
decl = dt_util.get_constructor_is(decl);
mk_c(c)->save_ast_trail(decl);
RETURN_Z3(of_func_decl(decl));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_func_decl Z3_API Z3_get_datatype_sort_constructor_accessor(Z3_context c, Z3_sort t, unsigned idx_c, unsigned idx_a) {
@ -512,28 +512,28 @@ extern "C" {
if (!dt_util.is_datatype(_t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<func_decl> const & decls = *dt_util.get_datatype_constructors(_t);
if (idx_c >= decls.size()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
func_decl* decl = (decls)[idx_c];
if (decl->get_arity() <= idx_a) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<func_decl> const & accs = *dt_util.get_constructor_accessors(decl);
SASSERT(accs.size() == decl->get_arity());
if (accs.size() <= idx_a) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
decl = (accs)[idx_a];
mk_c(c)->save_ast_trail(decl);
RETURN_Z3(of_func_decl(decl));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_func_decl Z3_API Z3_get_tuple_sort_mk_decl(Z3_context c, Z3_sort t) {
@ -544,11 +544,11 @@ extern "C" {
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(tuple) || dt_util.is_recursive(tuple) || dt_util.get_datatype_num_constructors(tuple) != 1) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_func_decl r = get_datatype_sort_constructor_core(c, t, 0);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_get_tuple_sort_num_fields(Z3_context c, Z3_sort t) {
@ -579,22 +579,22 @@ extern "C" {
datatype_util& dt_util = mk_c(c)->dtutil();
if (!dt_util.is_datatype(tuple) || dt_util.is_recursive(tuple) || dt_util.get_datatype_num_constructors(tuple) != 1) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<func_decl> const & decls = *dt_util.get_datatype_constructors(tuple);
if (decls.size() != 1) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<func_decl> const & accs = *dt_util.get_constructor_accessors((decls)[0]);
if (accs.size() <= i) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
func_decl* acc = (accs)[i];
mk_c(c)->save_ast_trail(acc);
RETURN_Z3(of_func_decl(acc));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_datatype_update_field(
@ -614,7 +614,7 @@ extern "C" {
mk_c(c)->save_ast_trail(r);
check_sorts(c, r);
RETURN_Z3(of_ast(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}

View file

@ -56,7 +56,7 @@ extern "C" {
sort * s = ctx->fpautil().mk_rm_sort();
mk_c(c)->save_ast_trail(s);
RETURN_Z3(of_sort(s));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_even(Z3_context c) {
@ -67,7 +67,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_nearest_ties_to_even();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_rne(Z3_context c) {
@ -78,7 +78,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_nearest_ties_to_even();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_round_nearest_ties_to_away(Z3_context c) {
@ -89,7 +89,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_nearest_ties_to_away();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_rna(Z3_context c) {
@ -100,7 +100,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_nearest_ties_to_away();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_round_toward_positive(Z3_context c) {
@ -111,7 +111,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_toward_positive();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_rtp(Z3_context c) {
@ -122,7 +122,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_toward_positive();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_round_toward_negative(Z3_context c) {
@ -133,7 +133,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_toward_negative();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_rtn(Z3_context c) {
@ -144,7 +144,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_toward_negative();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_round_toward_zero(Z3_context c) {
@ -155,7 +155,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_toward_zero();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_rtz(Z3_context c) {
@ -166,7 +166,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_round_toward_zero();
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
@ -181,7 +181,7 @@ extern "C" {
sort * s = ctx->fpautil().mk_float_sort(ebits, sbits);
ctx->save_ast_trail(s);
RETURN_Z3(of_sort(s));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_fpa_sort_half(Z3_context c) {
@ -220,50 +220,50 @@ extern "C" {
Z3_TRY;
LOG_Z3_mk_fpa_nan(c, s);
RESET_ERROR_CODE();
CHECK_VALID_AST(s, 0);
CHECK_VALID_AST(s, nullptr);
if (!is_fp_sort(c, s)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_nan(to_sort(s));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative) {
Z3_TRY;
LOG_Z3_mk_fpa_inf(c, s, negative);
RESET_ERROR_CODE();
CHECK_VALID_AST(s, 0);
CHECK_VALID_AST(s, nullptr);
if (!is_fp_sort(c, s)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = negative != 0 ? ctx->fpautil().mk_ninf(to_sort(s)) :
ctx->fpautil().mk_pinf(to_sort(s));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, Z3_bool negative) {
Z3_TRY;
LOG_Z3_mk_fpa_inf(c, s, negative);
RESET_ERROR_CODE();
CHECK_VALID_AST(s, 0);
CHECK_VALID_AST(s, nullptr);
if (!is_fp_sort(c, s)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = negative != 0 ? ctx->fpautil().mk_nzero(to_sort(s)) :
ctx->fpautil().mk_pzero(to_sort(s));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_fp(Z3_context c, Z3_ast sgn, Z3_ast exp, Z3_ast sig) {
@ -272,13 +272,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_bv(c, sgn) || !is_bv(c, exp) || !is_bv(c, sig)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_fp(to_expr(sgn), to_expr(exp), to_expr(sig));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_numeral_float(Z3_context c, float v, Z3_sort ty) {
@ -287,7 +287,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp_sort(c, ty)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
scoped_mpf tmp(ctx->fpautil().fm());
@ -298,7 +298,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_value(tmp);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_numeral_double(Z3_context c, double v, Z3_sort ty) {
@ -307,7 +307,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp_sort(c, ty)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
scoped_mpf tmp(ctx->fpautil().fm());
@ -315,7 +315,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_value(tmp);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_numeral_int(Z3_context c, signed v, Z3_sort ty) {
@ -324,7 +324,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp_sort(c, ty)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
scoped_mpf tmp(ctx->fpautil().fm());
@ -335,7 +335,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_value(tmp);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_numeral_int_uint(Z3_context c, Z3_bool sgn, signed exp, unsigned sig, Z3_sort ty) {
@ -344,7 +344,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp_sort(c, ty)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
scoped_mpf tmp(ctx->fpautil().fm());
@ -355,16 +355,16 @@ extern "C" {
expr * a = ctx->fpautil().mk_value(tmp);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_numeral_int64_uint64(Z3_context c, Z3_bool sgn, __int64 exp, __uint64 sig, Z3_sort ty) {
Z3_ast Z3_API Z3_mk_fpa_numeral_int64_uint64(Z3_context c, Z3_bool sgn, int64_t exp, uint64_t sig, Z3_sort ty) {
Z3_TRY;
LOG_Z3_mk_fpa_numeral_int64_uint64(c, sgn, exp, sig, ty);
RESET_ERROR_CODE();
if (!is_fp_sort(c, ty)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
scoped_mpf tmp(ctx->fpautil().fm());
@ -375,7 +375,7 @@ extern "C" {
expr * a = ctx->fpautil().mk_value(tmp);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_abs(Z3_context c, Z3_ast t) {
@ -384,13 +384,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_abs(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_neg(Z3_context c, Z3_ast t) {
@ -399,13 +399,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_neg(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_add(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2) {
@ -414,13 +414,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_add(to_expr(rm), to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_sub(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2) {
@ -429,13 +429,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_sub(to_expr(rm), to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_mul(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2) {
@ -444,13 +444,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_mul(to_expr(rm), to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_div(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2) {
@ -459,13 +459,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_div(to_expr(rm), to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_fma(Z3_context c, Z3_ast rm, Z3_ast t1, Z3_ast t2, Z3_ast t3) {
@ -474,13 +474,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t1) || !is_fp(c, t2) || !is_fp(c, t3)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_fma(to_expr(rm), to_expr(t1), to_expr(t2), to_expr(t3));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_sqrt(Z3_context c, Z3_ast rm, Z3_ast t) {
@ -489,13 +489,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_sqrt(to_expr(rm), to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_rem(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -504,13 +504,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_rem(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_round_to_integral(Z3_context c, Z3_ast rm, Z3_ast t) {
@ -519,13 +519,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_round_to_integral(to_expr(rm), to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_min(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -534,13 +534,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_min(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_max(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -549,13 +549,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_max(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_leq(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -564,13 +564,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_le(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_lt(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -579,13 +579,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_lt(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_geq(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -594,13 +594,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_ge(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_gt(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -609,13 +609,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_gt(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_eq(Z3_context c, Z3_ast t1, Z3_ast t2) {
@ -624,13 +624,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t1) || !is_fp(c, t2)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_float_eq(to_expr(t1), to_expr(t2));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_normal(Z3_context c, Z3_ast t) {
@ -639,13 +639,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_normal(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_subnormal(Z3_context c, Z3_ast t) {
@ -654,13 +654,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_subnormal(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_zero(Z3_context c, Z3_ast t) {
@ -669,13 +669,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_zero(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_infinite(Z3_context c, Z3_ast t) {
@ -684,13 +684,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_inf(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_nan(Z3_context c, Z3_ast t) {
@ -699,13 +699,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_nan(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_negative(Z3_context c, Z3_ast t) {
@ -714,13 +714,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_negative(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_is_positive(Z3_context c, Z3_ast t) {
@ -729,13 +729,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_is_positive(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
@ -745,19 +745,19 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_bv(c, bv) || !is_fp_sort(c, s)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
fpa_util & fu = ctx->fpautil();
if (!ctx->bvutil().is_bv(to_expr(bv)) ||
!fu.is_float(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
expr * a = fu.mk_to_fp(to_sort(s), to_expr(bv));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_fp_float(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s) {
@ -770,12 +770,12 @@ extern "C" {
!fu.is_float(to_expr(t)) ||
!fu.is_float(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
expr * a = fu.mk_to_fp(to_sort(s), to_expr(rm), to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_fp_real(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s) {
@ -788,12 +788,12 @@ extern "C" {
!ctx->autil().is_real(to_expr(t)) ||
!fu.is_float(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
expr * a = fu.mk_to_fp(to_sort(s), to_expr(rm), to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_fp_signed(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s) {
@ -806,12 +806,12 @@ extern "C" {
!ctx->bvutil().is_bv(to_expr(t)) ||
!fu.is_float(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
expr * a = fu.mk_to_fp(to_sort(s), to_expr(rm), to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_fp_unsigned(Z3_context c, Z3_ast rm, Z3_ast t, Z3_sort s) {
@ -824,12 +824,12 @@ extern "C" {
!ctx->bvutil().is_bv(to_expr(t)) ||
!fu.is_float(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
expr * a = fu.mk_to_fp_unsigned(to_sort(s), to_expr(rm), to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_ubv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz) {
@ -838,13 +838,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_to_ubv(to_expr(rm), to_expr(t), sz);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_sbv(Z3_context c, Z3_ast rm, Z3_ast t, unsigned sz) {
@ -853,13 +853,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_rm(c, rm) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_to_sbv(to_expr(rm), to_expr(t), sz);
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_real(Z3_context c, Z3_ast t) {
@ -868,13 +868,13 @@ extern "C" {
RESET_ERROR_CODE();
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
expr * a = ctx->fpautil().mk_to_real(to_expr(t));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_fpa_get_ebits(Z3_context c, Z3_sort s) {
@ -911,7 +911,7 @@ extern "C" {
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (sgn == 0) {
if (sgn == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
@ -939,8 +939,8 @@ extern "C" {
Z3_TRY;
LOG_Z3_fpa_get_numeral_sign_bv(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
CHECK_NON_NULL(t, nullptr);
CHECK_VALID_AST(t, nullptr);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
@ -949,13 +949,13 @@ extern "C" {
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(to_expr(t), val);
if (!r || mpfm.is_nan(val)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
app * a;
if (mpfm.is_pos(val))
@ -964,15 +964,15 @@ extern "C" {
a = ctx->bvutil().mk_numeral(1, 1);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_fpa_get_numeral_significand_bv(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_bv(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
CHECK_NON_NULL(t, nullptr);
CHECK_VALID_AST(t, nullptr);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpq_manager & mpqm = mpfm.mpq_manager();
@ -982,13 +982,13 @@ extern "C" {
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
unsigned sbits = val.get().get_sbits();
scoped_mpq q(mpqm);
@ -997,15 +997,15 @@ extern "C" {
app * a = mk_c(c)->bvutil().mk_numeral(q.get(), sbits-1);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_fpa_get_numeral_significand_string(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_string(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
CHECK_NON_NULL(t, nullptr);
CHECK_VALID_AST(t, nullptr);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
unsynch_mpq_manager & mpqm = mpfm.mpq_manager();
@ -1035,13 +1035,13 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, __uint64 * n) {
Z3_bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t * n) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_significand_uint64(c, t, n);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (n == 0) {
if (n == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
@ -1076,8 +1076,8 @@ extern "C" {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_string(c, t, biased);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
CHECK_NON_NULL(t, nullptr);
CHECK_VALID_AST(t, nullptr);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
@ -1113,13 +1113,13 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, __int64 * n, Z3_bool biased) {
Z3_bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t * n, Z3_bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_int64(c, t, n, biased);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
if (n == 0) {
if (n == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
}
@ -1161,8 +1161,8 @@ extern "C" {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_bv(c, t, biased);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
CHECK_NON_NULL(t, nullptr);
CHECK_VALID_AST(t, nullptr);
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
family_id fid = mk_c(c)->get_fpa_fid();
@ -1170,13 +1170,13 @@ extern "C" {
expr * e = to_expr(t);
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
if (!r || !(mpfm.is_normal(val) || mpfm.is_denormal(val) || mpfm.is_zero(val) || mpfm.is_inf(val))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
unsigned ebits = val.get().get_ebits();
mpf_exp_t exp;
@ -1194,23 +1194,23 @@ extern "C" {
app * a = mk_c(c)->bvutil().mk_numeral(exp, ebits);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_ieee_bv(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_mk_fpa_to_ieee_bv(c, t);
RESET_ERROR_CODE();
CHECK_NON_NULL(t, 0);
CHECK_VALID_AST(t, 0);
CHECK_NON_NULL(t, nullptr);
CHECK_VALID_AST(t, nullptr);
if (!is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
api::context * ctx = mk_c(c);
Z3_ast r = of_ast(ctx->fpautil().mk_to_ieee_bv(to_expr(t)));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_to_fp_int_real(Z3_context c, Z3_ast rm, Z3_ast exp, Z3_ast sig, Z3_sort s) {
@ -1224,12 +1224,12 @@ extern "C" {
!ctx->autil().is_real(to_expr(sig)) ||
!fu.is_float(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
expr * a = fu.mk_to_fp(to_sort(s), to_expr(rm), to_expr(exp), to_expr(sig));
ctx->save_ast_trail(a);
RETURN_Z3(of_expr(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t) {

View file

@ -21,6 +21,7 @@ Revision History:
#include "api/api_context.h"
#include "api/api_goal.h"
#include "ast/ast_translation.h"
#include "api/api_model.h"
extern "C" {
@ -30,14 +31,14 @@ extern "C" {
RESET_ERROR_CODE();
if (proofs != 0 && !mk_c(c)->m().proofs_enabled()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_goal_ref * g = alloc(Z3_goal_ref, *mk_c(c));
g->m_goal = alloc(goal, mk_c(c)->m(), proofs != 0, models != 0, unsat_cores != 0);
mk_c(c)->save_object(g);
Z3_goal r = of_goal(g);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_goal_inc_ref(Z3_context c, Z3_goal g) {
@ -119,12 +120,12 @@ extern "C" {
RESET_ERROR_CODE();
if (idx >= to_goal_ref(g)->size()) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr * result = to_goal_ref(g)->form(idx);
mk_c(c)->save_ast_trail(result);
RETURN_Z3(of_ast(result));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_goal_num_exprs(Z3_context c, Z3_goal g) {
@ -151,6 +152,20 @@ extern "C" {
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m) {
Z3_TRY;
LOG_Z3_goal_convert_model(c, g, m);
RESET_ERROR_CODE();
model_ref new_m;
Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c));
mk_c(c)->save_object(m_ref);
if (m) m_ref->m_model = to_model_ref(m)->copy();
if (to_goal_ref(g)->mc())
(*to_goal_ref(g)->mc())(m_ref->m_model);
RETURN_Z3(of_model(m_ref));
Z3_CATCH_RETURN(0);
}
Z3_goal Z3_API Z3_goal_translate(Z3_context c, Z3_goal g, Z3_context target) {
Z3_TRY;
LOG_Z3_goal_translate(c, g, target);
@ -161,7 +176,7 @@ extern "C" {
mk_c(target)->save_object(_r);
Z3_goal r = of_goal(_r);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_goal_to_string(Z3_context c, Z3_goal g) {
@ -178,4 +193,18 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_string Z3_API Z3_goal_to_dimacs_string(Z3_context c, Z3_goal g) {
Z3_TRY;
LOG_Z3_goal_to_dimacs_string(c, g);
RESET_ERROR_CODE();
std::ostringstream buffer;
to_goal_ref(g)->display_dimacs(buffer);
// Hack for removing the trailing '\n'
std::string result = buffer.str();
SASSERT(result.size() > 0);
result.resize(result.size()-1);
return mk_c(c)->mk_external_string(result);
Z3_CATCH_RETURN("");
}
};

View file

@ -24,11 +24,11 @@ Revision History:
struct Z3_goal_ref : public api::object {
goal_ref m_goal;
Z3_goal_ref(api::context& c) : api::object(c) {}
virtual ~Z3_goal_ref() {}
~Z3_goal_ref() override {}
};
inline Z3_goal_ref * to_goal(Z3_goal g) { return reinterpret_cast<Z3_goal_ref *>(g); }
inline Z3_goal of_goal(Z3_goal_ref * g) { return reinterpret_cast<Z3_goal>(g); }
inline goal_ref to_goal_ref(Z3_goal g) { return g == 0 ? goal_ref() : to_goal(g)->m_goal; }
inline goal_ref to_goal_ref(Z3_goal g) { return g == nullptr ? goal_ref() : to_goal(g)->m_goal; }
#endif

View file

@ -1,728 +0,0 @@
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
api_interp.cpp
Abstract:
API for interpolation
Author:
Ken McMillan
Revision History:
--*/
#include<sstream>
#include<vector>
#include "api/z3.h"
#include "api/api_log_macros.h"
#include "api/api_context.h"
#include "api/api_tactic.h"
#include "api/api_solver.h"
#include "api/api_model.h"
#include "api/api_stats.h"
#include "api/api_ast_vector.h"
#include "solver/tactic2solver.h"
#include "util/scoped_ctrl_c.h"
#include "util/cancel_eh.h"
#include "util/scoped_timer.h"
#include "tactic/portfolio/smt_strategic_solver.h"
#include "smt/smt_solver.h"
#include "smt/smt_implied_equalities.h"
#include "interp/iz3interp.h"
#include "interp/iz3profiling.h"
#include "interp/iz3hash.h"
#include "interp/iz3pp.h"
#include "interp/iz3checker.h"
#include "ast/scoped_proof.h"
using namespace stl_ext;
// WARNING: don't make a hash_map with this if the range type
// has a destructor: you'll get an address dependency!!!
namespace stl_ext {
template <>
class hash < Z3_ast > {
public:
size_t operator()(const Z3_ast p) const {
return (size_t)p;
}
};
}
typedef interpolation_options_struct *Z3_interpolation_options;
extern "C" {
Z3_context Z3_mk_interpolation_context(Z3_config cfg){
if (!cfg) cfg = Z3_mk_config();
Z3_set_param_value(cfg, "PROOF", "true");
Z3_set_param_value(cfg, "MODEL", "true");
// Z3_set_param_value(cfg, "PRE_SIMPLIFIER","false");
// Z3_set_param_value(cfg, "SIMPLIFY_CLAUSES","false");
Z3_context ctx = Z3_mk_context(cfg);
return ctx;
}
void Z3_interpolate_proof(Z3_context ctx,
Z3_ast proof,
int num,
Z3_ast *cnsts,
unsigned *parents,
Z3_params options,
Z3_ast *interps,
int num_theory,
Z3_ast *theory)
{
if (num > 1){ // if we have interpolants to compute
ptr_vector<ast> pre_cnsts_vec(num); // get constraints in a vector
for (int i = 0; i < num; i++){
ast *a = to_ast(cnsts[i]);
pre_cnsts_vec[i] = a;
}
::vector<int> pre_parents_vec; // get parents in a vector
if (parents){
pre_parents_vec.resize(num);
for (int i = 0; i < num; i++)
pre_parents_vec[i] = parents[i];
}
ptr_vector<ast> theory_vec; // get background theory in a vector
if (theory){
theory_vec.resize(num_theory);
for (int i = 0; i < num_theory; i++)
theory_vec[i] = to_ast(theory[i]);
}
ptr_vector<ast> interpolants(num - 1); // make space for result
ast_manager &_m = mk_c(ctx)->m();
iz3interpolate(_m,
to_ast(proof),
pre_cnsts_vec,
pre_parents_vec,
interpolants,
theory_vec,
0); // ignore params for now FIXME
// copy result back
for (unsigned i = 0; i < interpolants.size(); i++){
mk_c(ctx)->save_ast_trail(interpolants[i]);
interps[i] = of_ast(interpolants[i]);
_m.dec_ref(interpolants[i]);
}
}
}
static std::ostringstream itp_err;
int Z3_check_interpolant(Z3_context ctx,
unsigned num,
Z3_ast *cnsts,
unsigned *parents,
Z3_ast *itp,
Z3_string *error,
unsigned num_theory,
Z3_ast *theory){
ast_manager &_m = mk_c(ctx)->m();
itp_err.clear();
// need a solver -- make one here, but how?
params_ref p = params_ref::get_empty(); //FIXME
scoped_ptr<solver_factory> sf(mk_smt_solver_factory());
scoped_ptr<solver> sp((*(sf))(_m, p, false, true, false, symbol("AUFLIA")));
ptr_vector<ast> cnsts_vec(num); // get constraints in a vector
for (unsigned i = 0; i < num; i++){
ast *a = to_ast(cnsts[i]);
cnsts_vec[i] = a;
}
ptr_vector<ast> itp_vec(num); // get interpolants in a vector
for (unsigned i = 0; i < num - 1; i++){
ast *a = to_ast(itp[i]);
itp_vec[i] = a;
}
::vector<int> parents_vec; // get parents in a vector
if (parents){
parents_vec.resize(num);
for (unsigned i = 0; i < num; i++)
parents_vec[i] = parents[i];
}
ptr_vector<ast> theory_vec; // get background theory in a vector
if (theory){
theory_vec.resize(num_theory);
for (unsigned i = 0; i < num_theory; i++)
theory_vec[i] = to_ast(theory[i]);
}
bool res = iz3check(_m,
sp.get(),
itp_err,
cnsts_vec,
parents_vec,
itp_vec,
theory_vec);
*error = res ? 0 : itp_err.str().c_str();
return res;
}
static std::string Z3_profile_string;
Z3_string Z3_interpolation_profile(Z3_context ctx){
std::ostringstream f;
profiling::print(f);
Z3_profile_string = f.str();
return Z3_profile_string.c_str();
}
Z3_interpolation_options
Z3_mk_interpolation_options(){
return (Z3_interpolation_options) new interpolation_options_struct;
}
void
Z3_del_interpolation_options(Z3_interpolation_options opts){
delete opts;
}
void
Z3_set_interpolation_option(Z3_interpolation_options opts,
Z3_string name,
Z3_string value){
opts->map[name] = value;
}
Z3_ast_vector Z3_API Z3_get_interpolant(Z3_context c, Z3_ast pf, Z3_ast pat, Z3_params p){
Z3_TRY;
LOG_Z3_get_interpolant(c, pf, pat, p);
RESET_ERROR_CODE();
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
ast *_pf = to_ast(pf);
ast *_pat = to_ast(pat);
ptr_vector<ast> interp;
ptr_vector<ast> cnsts; // to throw away
ast_manager &_m = mk_c(c)->m();
iz3interpolate(_m,
_pf,
cnsts,
_pat,
interp,
(interpolation_options_struct *)0 // ignore params for now
);
// copy result back
for (unsigned i = 0; i < interp.size(); i++){
v->m_ast_vector.push_back(interp[i]);
_m.dec_ref(interp[i]);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
Z3_lbool Z3_API Z3_compute_interpolant(Z3_context c, Z3_ast pat, Z3_params p, Z3_ast_vector *out_interp, Z3_model *model){
Z3_TRY;
LOG_Z3_compute_interpolant(c, pat, p, out_interp, model);
RESET_ERROR_CODE();
// params_ref &_p = to_params(p)->m_params;
params_ref _p;
_p.set_bool("proof", true); // this is currently useless
scoped_proof_mode spm(mk_c(c)->m(), PGM_ENABLED);
scoped_ptr<solver_factory> sf = mk_smt_solver_factory();
scoped_ptr<solver> m_solver((*sf)(mk_c(c)->m(), _p, true, true, true, ::symbol::null));
m_solver.get()->updt_params(_p); // why do we have to do this?
// some boilerplate stolen from Z3_solver_check
unsigned timeout = p?to_params(p)->m_params.get_uint("timeout", mk_c(c)->get_timeout()):UINT_MAX;
unsigned rlimit = p?to_params(p)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit()):0;
bool use_ctrl_c = p?to_params(p)->m_params.get_bool("ctrl_c", false): false;
cancel_eh<reslimit> eh(mk_c(c)->m().limit());
api::context::set_interruptable si(*(mk_c(c)), eh);
ast *_pat = to_ast(pat);
ptr_vector<ast> interp;
ptr_vector<ast> cnsts; // to throw away
ast_manager &_m = mk_c(c)->m();
model_ref m;
lbool _status;
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);
scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
try {
_status = iz3interpolate(_m,
*(m_solver.get()),
_pat,
cnsts,
interp,
m,
0 // ignore params for now
);
}
catch (z3_exception & ex) {
mk_c(c)->handle_exception(ex);
RETURN_Z3_compute_interpolant Z3_L_UNDEF;
}
}
for (unsigned i = 0; i < cnsts.size(); i++)
_m.dec_ref(cnsts[i]);
Z3_lbool status = of_lbool(_status);
Z3_ast_vector_ref *v = 0;
*model = 0;
if (_status == l_false){
// copy result back
v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < interp.size(); i++){
v->m_ast_vector.push_back(interp[i]);
_m.dec_ref(interp[i]);
}
}
else {
model_ref mr;
m_solver.get()->get_model(mr);
if(mr.get()){
Z3_model_ref *tmp_val = alloc(Z3_model_ref, *mk_c(c));
tmp_val->m_model = mr.get();
mk_c(c)->save_object(tmp_val);
*model = of_model(tmp_val);
}
}
*out_interp = of_ast_vector(v);
RETURN_Z3_compute_interpolant status;
Z3_CATCH_RETURN(Z3_L_UNDEF);
}
};
static void tokenize(const std::string &str, std::vector<std::string> &tokens){
for (unsigned i = 0; i < str.size();){
if (str[i] == ' '){ i++; continue; }
unsigned beg = i;
while (i < str.size() && str[i] != ' ')i++;
if (i > beg)
tokens.push_back(str.substr(beg, i - beg));
}
}
static void get_file_params(const char *filename, hash_map<std::string, std::string> &params){
std::ifstream f(filename);
if (f){
std::string first_line;
std::getline(f, first_line);
// std::cout << "first line: '" << first_line << "'" << std::endl;
if (first_line.size() >= 2 && first_line[0] == ';' && first_line[1] == '!'){
std::vector<std::string> tokens;
tokenize(first_line.substr(2, first_line.size() - 2), tokens);
for (unsigned i = 0; i < tokens.size(); i++){
std::string &tok = tokens[i];
size_t eqpos = tok.find('=');
if (eqpos != std::string::npos){
std::string left = tok.substr(0, eqpos);
std::string right = tok.substr(eqpos + 1, tok.size() - eqpos - 1);
params[left] = right;
}
}
}
f.close();
}
}
extern "C" {
#if 0
static void iZ3_write_seq(Z3_context ctx, int num, Z3_ast *cnsts, const char *filename, int num_theory, Z3_ast *theory){
int num_fmlas = num+num_theory;
std::vector<Z3_ast> fmlas(num_fmlas);
if(num_theory)
std::copy(theory,theory+num_theory,fmlas.begin());
for(int i = 0; i < num_theory; i++)
fmlas[i] = Z3_mk_implies(ctx,Z3_mk_true(ctx),fmlas[i]);
std::copy(cnsts,cnsts+num,fmlas.begin()+num_theory);
Z3_string smt = Z3_benchmark_to_smtlib_string(ctx,"none","AUFLIA","unknown","",num_fmlas-1,&fmlas[0],fmlas[num_fmlas-1]);
std::ofstream f(filename);
if(num_theory)
f << ";! THEORY=" << num_theory << "\n";
f << smt;
f.close();
}
void Z3_write_interpolation_problem(Z3_context ctx, int num, Z3_ast *cnsts, unsigned *parents, const char *filename, int num_theory, Z3_ast *theory){
if(!parents){
iZ3_write_seq(ctx,num,cnsts,filename,num_theory,theory);
return;
}
std::vector<Z3_ast> tcnsts(num);
hash_map<int,Z3_ast> syms;
for(int j = 0; j < num - 1; j++){
std::ostringstream oss;
oss << "$P" << j;
std::string name = oss.str();
Z3_symbol s = Z3_mk_string_symbol(ctx, name.c_str());
Z3_ast symbol = Z3_mk_const(ctx, s, Z3_mk_bool_sort(ctx));
syms[j] = symbol;
tcnsts[j] = Z3_mk_implies(ctx,cnsts[j],symbol);
}
tcnsts[num-1] = Z3_mk_implies(ctx,cnsts[num-1],Z3_mk_false(ctx));
for(int j = num-2; j >= 0; j--){
int parent = parents[j];
// assert(parent >= 0 && parent < num);
tcnsts[parent] = Z3_mk_implies(ctx,syms[j],tcnsts[parent]);
}
iZ3_write_seq(ctx,num,&tcnsts[0],filename,num_theory,theory);
}
#else
static Z3_ast and_vec(Z3_context ctx, svector<Z3_ast> &c){
return (c.size() > 1) ? Z3_mk_and(ctx, c.size(), &c[0]) : c[0];
}
static Z3_ast parents_vector_to_tree(Z3_context ctx, int num, Z3_ast *cnsts, unsigned *parents){
Z3_ast res;
if (!parents){
res = Z3_mk_interpolant(ctx, cnsts[0]);
for (int i = 1; i < num - 1; i++){
Z3_ast bar[2] = { res, cnsts[i] };
res = Z3_mk_interpolant(ctx, Z3_mk_and(ctx, 2, bar));
}
if (num > 1){
Z3_ast bar[2] = { res, cnsts[num - 1] };
res = Z3_mk_and(ctx, 2, bar);
}
}
else {
std::vector<svector<Z3_ast> > chs(num);
for (int i = 0; i < num - 1; i++){
svector<Z3_ast> &c = chs[i];
c.push_back(cnsts[i]);
Z3_ast foo = Z3_mk_interpolant(ctx, and_vec(ctx, c));
chs[parents[i]].push_back(foo);
}
{
svector<Z3_ast> &c = chs[num - 1];
c.push_back(cnsts[num - 1]);
res = and_vec(ctx, c);
}
}
Z3_inc_ref(ctx, res);
return res;
}
void Z3_write_interpolation_problem(Z3_context ctx, unsigned num, Z3_ast *cnsts, unsigned *parents, const char *filename, unsigned num_theory, Z3_ast *theory){
std::ofstream f(filename);
if (num > 0){
#if 0
// Suggested shorthand:
ptr_vector<expr> cnsts_vec;
cnsts_vec.append(num, to_exprs(cnsts));
cnsts_vec.append(num_theory, to_exprs(theory));
#endif
ptr_vector<expr> cnsts_vec(num); // get constraints in a vector
for (unsigned i = 0; i < num; i++){
expr *a = to_expr(cnsts[i]);
cnsts_vec[i] = a;
}
for (unsigned i = 0; i < num_theory; i++){
expr *a = to_expr(theory[i]);
cnsts_vec.push_back(a);
}
Z3_ast tree = parents_vector_to_tree(ctx, num, cnsts, parents);
iz3pp(mk_c(ctx)->m(), cnsts_vec, to_expr(tree), f);
Z3_dec_ref(ctx, tree);
}
f.close();
#if 0
if(!parents){
iZ3_write_seq(ctx,num,cnsts,filename,num_theory,theory);
return;
}
std::vector<Z3_ast> tcnsts(num);
hash_map<int,Z3_ast> syms;
for(int j = 0; j < num - 1; j++){
std::ostringstream oss;
oss << "$P" << j;
std::string name = oss.str();
Z3_symbol s = Z3_mk_string_symbol(ctx, name.c_str());
Z3_ast symbol = Z3_mk_const(ctx, s, Z3_mk_bool_sort(ctx));
syms[j] = symbol;
tcnsts[j] = Z3_mk_implies(ctx,cnsts[j],symbol);
}
tcnsts[num-1] = Z3_mk_implies(ctx,cnsts[num-1],Z3_mk_false(ctx));
for(int j = num-2; j >= 0; j--){
int parent = parents[j];
// assert(parent >= 0 && parent < num);
tcnsts[parent] = Z3_mk_implies(ctx,syms[j],tcnsts[parent]);
}
iZ3_write_seq(ctx,num,&tcnsts[0],filename,num_theory,theory);
#endif
}
#endif
static std::vector<Z3_ast> read_cnsts;
static std::vector<unsigned> read_parents;
static std::ostringstream read_error;
static std::string read_msg;
static std::vector<Z3_ast> read_theory;
static bool iZ3_parse(Z3_context ctx, const char *filename, const char **error, svector<Z3_ast> &assertions){
read_error.clear();
try {
std::string foo(filename);
Z3_ast assrts = Z3_parse_smtlib2_file(ctx, filename, 0, 0, 0, 0, 0, 0);
Z3_app app = Z3_to_app(ctx, assrts);
int nconjs = Z3_get_app_num_args(ctx, app);
assertions.resize(nconjs);
for (int k = 0; k < nconjs; k++)
assertions[k] = Z3_get_app_arg(ctx, app, k);
}
catch (...) {
read_error << "SMTLIB parse error: " << Z3_get_parser_error(ctx);
read_msg = read_error.str();
*error = read_msg.c_str();
return false;
}
Z3_set_error_handler(ctx, 0);
return true;
}
int Z3_read_interpolation_problem(Z3_context ctx, unsigned *_num, Z3_ast *cnsts[], unsigned *parents[], const char *filename, Z3_string_ptr error, unsigned *ret_num_theory, Z3_ast *theory[]){
hash_map<std::string, std::string> file_params;
get_file_params(filename, file_params);
unsigned num_theory = 0;
if (file_params.find("THEORY") != file_params.end())
num_theory = atoi(file_params["THEORY"].c_str());
svector<Z3_ast> assertions;
if (!iZ3_parse(ctx, filename, error, assertions))
return false;
if (num_theory > assertions.size())
num_theory = assertions.size();
unsigned num = assertions.size() - num_theory;
read_cnsts.resize(num);
read_parents.resize(num);
read_theory.resize(num_theory);
for (unsigned j = 0; j < num_theory; j++)
read_theory[j] = assertions[j];
for (unsigned j = 0; j < num; j++)
read_cnsts[j] = assertions[j + num_theory];
if (ret_num_theory)
*ret_num_theory = num_theory;
if (theory)
*theory = &read_theory[0];
if (!parents){
*_num = num;
*cnsts = &read_cnsts[0];
return true;
}
for (unsigned j = 0; j < num; j++)
read_parents[j] = SHRT_MAX;
hash_map<Z3_ast, int> pred_map;
for (unsigned j = 0; j < num; j++){
Z3_ast lhs = 0, rhs = read_cnsts[j];
if (Z3_get_decl_kind(ctx, Z3_get_app_decl(ctx, Z3_to_app(ctx, rhs))) == Z3_OP_IMPLIES){
Z3_app app1 = Z3_to_app(ctx, rhs);
Z3_ast lhs1 = Z3_get_app_arg(ctx, app1, 0);
Z3_ast rhs1 = Z3_get_app_arg(ctx, app1, 1);
if (Z3_get_decl_kind(ctx, Z3_get_app_decl(ctx, Z3_to_app(ctx, lhs1))) == Z3_OP_AND){
Z3_app app2 = Z3_to_app(ctx, lhs1);
int nconjs = Z3_get_app_num_args(ctx, app2);
for (int k = nconjs - 1; k >= 0; --k)
rhs1 = Z3_mk_implies(ctx, Z3_get_app_arg(ctx, app2, k), rhs1);
rhs = rhs1;
}
}
while (1){
Z3_app app = Z3_to_app(ctx, rhs);
Z3_func_decl func = Z3_get_app_decl(ctx, app);
Z3_decl_kind dk = Z3_get_decl_kind(ctx, func);
if (dk == Z3_OP_IMPLIES){
if (lhs){
Z3_ast child = lhs;
if (pred_map.find(child) == pred_map.end()){
read_error << "formula " << j + 1 << ": unknown: " << Z3_ast_to_string(ctx, child);
goto fail;
}
int child_num = pred_map[child];
if (read_parents[child_num] != SHRT_MAX){
read_error << "formula " << j + 1 << ": multiple reference: " << Z3_ast_to_string(ctx, child);
goto fail;
}
read_parents[child_num] = j;
}
lhs = Z3_get_app_arg(ctx, app, 0);
rhs = Z3_get_app_arg(ctx, app, 1);
}
else {
if (!lhs){
read_error << "formula " << j + 1 << ": should be (implies {children} fmla parent)";
goto fail;
}
read_cnsts[j] = lhs;
Z3_ast name = rhs;
if (pred_map.find(name) != pred_map.end()){
read_error << "formula " << j + 1 << ": duplicate symbol";
goto fail;
}
pred_map[name] = j;
break;
}
}
}
for (unsigned j = 0; j < num - 1; j++)
if (read_parents[j] == SHRT_MAX){
read_error << "formula " << j + 1 << ": unreferenced";
goto fail;
}
*_num = num;
*cnsts = &read_cnsts[0];
*parents = &read_parents[0];
return true;
fail:
read_msg = read_error.str();
*error = read_msg.c_str();
return false;
}
}
#if 0
/** Constant reprepresenting a root of a formula tree for tree interpolation */
#define IZ3_ROOT SHRT_MAX
/** This function uses Z3 to determine satisfiability of a set of
constraints. If UNSAT, an interpolant is returned, based on the
refutation generated by Z3. If SAT, a model is returned.
If "parents" is non-null, computes a tree interpolant. The tree is
defined by the array "parents". This array maps each formula in
the tree to its parent, where formulas are indicated by their
integer index in "cnsts". The parent of formula n must have index
greater than n. The last formula is the root of the tree. Its
parent entry should be the constant IZ3_ROOT.
If "parents" is null, computes a sequence interpolant.
\param ctx The Z3 context. Must be generated by iz3_mk_context
\param num The number of constraints in the sequence
\param cnsts Array of constraints (AST's in context ctx)
\param parents The parents vector defining the tree structure
\param options Interpolation options (may be NULL)
\param interps Array to return interpolants (size at least num-1, may be NULL)
\param model Returns a Z3 model if constraints SAT (may be NULL)
\param labels Returns relevant labels if SAT (may be NULL)
\param incremental
VERY IMPORTANT: All the Z3 formulas in cnsts must be in Z3
context ctx. The model and interpolants returned are also
in this context.
The return code is as in Z3_check_assumptions, that is,
Z3_L_FALSE = constraints UNSAT (interpolants returned)
Z3_L_TRUE = constraints SAT (model returned)
Z3_L_UNDEF = Z3 produced no result, or interpolation not possible
Currently, this function supports integer and boolean variables,
as well as arrays over these types, with linear arithmetic,
uninterpreted functions and quantifiers over integers (that is
AUFLIA). Interpolants are produced in AULIA. However, some
uses of array operations may cause quantifiers to appear in the
interpolants even when there are no quantifiers in the input formulas.
Although quantifiers may appear in the input formulas, Z3 may give up in
this case, returning Z3_L_UNDEF.
If "incremental" is true, cnsts must contain exactly the set of
formulas that are currently asserted in the context. If false,
there must be no formulas currently asserted in the context.
Setting "incremental" to true makes it posisble to incrementally
add and remove constraints from the context until the context
becomes UNSAT, at which point an interpolant is computed. Caution
must be used, however. Before popping the context, if you wish to
keep the interolant formulas, you *must* preserve them by using
Z3_persist_ast. Also, if you want to simplify the interpolant
formulas using Z3_simplify, you must first pop all of the
assertions in the context (or use a different context). Otherwise,
the formulas will be simplified *relative* to these constraints,
which is almost certainly not what you want.
Current limitations on tree interpolants. In a tree interpolation
problem, each constant (0-ary function symbol) must occur only
along one path from root to leaf. Function symbols (of arity > 0)
are considered to have global scope (i.e., may appear in any
interpolant formula).
def_API('Z3_interpolate', BOOL, (_in(CONTEXT), _in(UINT), _in_array(1, AST), _in_array(1, UINT), _in(PARAMS), _out_array(1, AST), _out(MODEL), _out(LITERALS), _in(UINT), _in(UINT), _in_array(9, AST)))
*/
Z3_lbool Z3_API Z3_interpolate(Z3_context ctx,
unsigned num,
Z3_ast *cnsts,
unsigned *parents,
Z3_params options,
Z3_ast *interps,
Z3_model *model,
Z3_literals *labels,
unsigned incremental,
unsigned num_theory,
Z3_ast *theory);
#endif

View file

@ -21,15 +21,15 @@ Revision History:
#include "util/util.h"
#include "util/version.h"
std::ostream * g_z3_log = 0;
std::ostream * g_z3_log = nullptr;
bool g_z3_log_enabled = false;
extern "C" {
void Z3_close_log_unsafe(void) {
if (g_z3_log != 0) {
if (g_z3_log != nullptr) {
dealloc(g_z3_log);
g_z3_log_enabled = false;
g_z3_log = 0;
g_z3_log = nullptr;
}
}
@ -40,12 +40,12 @@ extern "C" {
#pragma omp critical (z3_log)
{
#endif
if (g_z3_log != 0)
if (g_z3_log != nullptr)
Z3_close_log_unsafe();
g_z3_log = alloc(std::ofstream, filename);
if (g_z3_log->bad() || g_z3_log->fail()) {
dealloc(g_z3_log);
g_z3_log = 0;
g_z3_log = nullptr;
res = Z3_FALSE;
}
else {
@ -61,13 +61,13 @@ extern "C" {
}
void Z3_API Z3_append_log(Z3_string str) {
if (g_z3_log == 0)
if (g_z3_log == nullptr)
return;
#ifdef Z3_LOG_SYNC
#pragma omp critical (z3_log)
{
#endif
if (g_z3_log != 0)
if (g_z3_log != nullptr)
_Z3_append_log(static_cast<char const *>(str));
#ifdef Z3_LOG_SYNC
}
@ -75,7 +75,7 @@ extern "C" {
}
void Z3_API Z3_close_log(void) {
if (g_z3_log != 0) {
if (g_z3_log != nullptr) {
#ifdef Z3_LOG_SYNC
#pragma omp critical (z3_log)
{

View file

@ -38,7 +38,7 @@ extern "C" {
m_ref->m_model = alloc(model, mk_c(c)->m());
mk_c(c)->save_object(m_ref);
RETURN_Z3(of_model(m_ref));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_model_inc_ref(Z3_context c, Z3_model m) {
@ -65,14 +65,14 @@ extern "C" {
Z3_TRY;
LOG_Z3_model_get_const_interp(c, m, a);
RESET_ERROR_CODE();
CHECK_NON_NULL(m, 0);
CHECK_NON_NULL(m, nullptr);
expr * r = to_model_ref(m)->get_const_interp(to_func_decl(a));
if (!r) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
mk_c(c)->save_ast_trail(r);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_model_has_interp(Z3_context c, Z3_model m, Z3_func_decl a) {
@ -91,17 +91,17 @@ extern "C" {
Z3_TRY;
LOG_Z3_model_get_func_interp(c, m, f);
RESET_ERROR_CODE();
CHECK_NON_NULL(m, 0);
CHECK_NON_NULL(m, nullptr);
func_interp * _fi = to_model_ref(m)->get_func_interp(to_func_decl(f));
if (!_fi) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_func_interp_ref * fi = alloc(Z3_func_interp_ref, *mk_c(c), to_model_ref(m));
fi->m_func_interp = _fi;
mk_c(c)->save_object(fi);
RETURN_Z3(of_func_interp(fi));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_model_get_num_consts(Z3_context c, Z3_model m) {
@ -117,16 +117,16 @@ extern "C" {
Z3_TRY;
LOG_Z3_model_get_const_decl(c, m, i);
RESET_ERROR_CODE();
CHECK_NON_NULL(m, 0);
CHECK_NON_NULL(m, nullptr);
model * _m = to_model_ref(m);
if (i < _m->get_num_constants()) {
RETURN_Z3(of_func_decl(_m->get_constant(i)));
}
else {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_model_get_num_funcs(Z3_context c, Z3_model m) {
@ -139,11 +139,11 @@ extern "C" {
}
Z3_func_decl get_model_func_decl_core(Z3_context c, Z3_model m, unsigned i) {
CHECK_NON_NULL(m, 0);
CHECK_NON_NULL(m, nullptr);
model * _m = to_model_ref(m);
if (i >= _m->get_num_functions()) {
SET_ERROR_CODE(Z3_IOB);
return 0;
return nullptr;
}
return of_func_decl(_m->get_function(i));
}
@ -154,19 +154,20 @@ extern "C" {
RESET_ERROR_CODE();
Z3_func_decl r = get_model_func_decl_core(c, m, i);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, Z3_bool model_completion, Z3_ast * v) {
Z3_TRY;
LOG_Z3_model_eval(c, m, t, model_completion, v);
if (v) *v = 0;
if (v) *v = nullptr;
RESET_ERROR_CODE();
CHECK_NON_NULL(m, Z3_FALSE);
CHECK_IS_EXPR(t, Z3_FALSE);
model * _m = to_model_ref(m);
expr_ref result(mk_c(c)->m());
_m->eval(to_expr(t), result, model_completion == Z3_TRUE);
model::scoped_model_completion _scm(*_m, model_completion == Z3_TRUE);
result = (*_m)(to_expr(t));
mk_c(c)->save_ast_trail(result.get());
*v = of_ast(result.get());
RETURN_Z3_model_eval Z3_TRUE;
@ -187,11 +188,11 @@ extern "C" {
RESET_ERROR_CODE();
if (i >= to_model_ref(m)->get_num_uninterpreted_sorts()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
sort * s = to_model_ref(m)->get_uninterpreted_sort(i);
RETURN_Z3(of_sort(s));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s) {
@ -200,7 +201,7 @@ extern "C" {
RESET_ERROR_CODE();
if (!to_model_ref(m)->has_uninterpreted_sort(to_sort(s))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ptr_vector<expr> const & universe = to_model_ref(m)->get_universe(to_sort(s));
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
@ -210,7 +211,19 @@ extern "C" {
v->m_ast_vector.push_back(universe[i]);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_model Z3_API Z3_model_translate(Z3_context c, Z3_model m, Z3_context target) {
Z3_TRY;
LOG_Z3_model_translate(c, m, target);
RESET_ERROR_CODE();
Z3_model_ref* dst = alloc(Z3_model_ref, *mk_c(target));
ast_translation tr(mk_c(c)->m(), mk_c(target)->m());
dst->m_model = to_model_ref(m)->translate(tr);
mk_c(target)->save_object(dst);
RETURN_Z3(of_model(dst));
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a) {
@ -230,9 +243,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_func_interp Z3_API Z3_add_func_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast else_val) {
@ -247,7 +260,7 @@ extern "C" {
mdl->register_decl(d, f_ref->m_func_interp);
f_ref->m_func_interp->set_else(to_expr(else_val));
RETURN_Z3(of_func_interp(f_ref));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_add_const_interp(Z3_context c, Z3_model m, Z3_func_decl f, Z3_ast a) {
@ -298,30 +311,30 @@ extern "C" {
Z3_TRY;
LOG_Z3_func_interp_get_entry(c, f, i);
RESET_ERROR_CODE();
CHECK_NON_NULL(f, 0);
CHECK_NON_NULL(f, nullptr);
if (i >= to_func_interp_ref(f)->num_entries()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_func_entry_ref * e = alloc(Z3_func_entry_ref, *mk_c(c), to_func_interp(f)->m_model.get());
e->m_func_interp = to_func_interp_ref(f);
e->m_func_entry = to_func_interp_ref(f)->get_entry(i);
mk_c(c)->save_object(e);
RETURN_Z3(of_func_entry(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_func_interp_get_else(Z3_context c, Z3_func_interp f) {
Z3_TRY;
LOG_Z3_func_interp_get_else(c, f);
RESET_ERROR_CODE();
CHECK_NON_NULL(f, 0);
CHECK_NON_NULL(f, nullptr);
expr * e = to_func_interp_ref(f)->get_else();
if (e) {
mk_c(c)->save_ast_trail(e);
}
RETURN_Z3(of_expr(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_func_interp_set_else(Z3_context c, Z3_func_interp f, Z3_ast else_value) {
@ -387,7 +400,7 @@ extern "C" {
expr * v = to_func_entry_ref(e)->get_result();
mk_c(c)->save_ast_trail(v);
RETURN_Z3(of_expr(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_func_entry_get_num_args(Z3_context c, Z3_func_entry e) {
@ -404,39 +417,12 @@ extern "C" {
RESET_ERROR_CODE();
if (i >= to_func_entry(e)->m_func_interp->get_arity()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr * r = to_func_entry(e)->m_func_entry->get_arg(i);
RETURN_Z3(of_expr(r));
Z3_CATCH_RETURN(0);
}
// ----------------------------
//
// DEPRECATED API
//
// ----------------------------
void Z3_API Z3_del_model(Z3_context c, Z3_model m) {
Z3_model_dec_ref(c, m);
}
unsigned Z3_API Z3_get_model_num_constants(Z3_context c, Z3_model m) {
return Z3_model_get_num_consts(c, m);
}
Z3_func_decl Z3_API Z3_get_model_constant(Z3_context c, Z3_model m, unsigned i) {
return Z3_model_get_const_decl(c, m, i);
}
unsigned Z3_API Z3_get_model_num_funcs(Z3_context c, Z3_model m) {
return Z3_model_get_num_funcs(c, m);
}
Z3_func_decl Z3_API Z3_get_model_func_decl(Z3_context c, Z3_model m, unsigned i) {
return Z3_model_get_func_decl(c, m, i);
}
Z3_CATCH_RETURN(nullptr);
}
unsigned get_model_func_num_entries_core(Z3_context c, Z3_model m, unsigned i) {
RESET_ERROR_CODE();
@ -479,7 +465,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_model_to_string(c, m);
RESET_ERROR_CODE();
CHECK_NON_NULL(m, 0);
CHECK_NON_NULL(m, nullptr);
std::ostringstream buffer;
std::string result;
if (mk_c(c)->get_print_mode() == Z3_PRINT_SMTLIB2_COMPLIANT) {
@ -495,7 +481,7 @@ extern "C" {
result = buffer.str();
}
return mk_c(c)->mk_external_string(result);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -24,7 +24,7 @@ Revision History:
struct Z3_model_ref : public api::object {
model_ref m_model;
Z3_model_ref(api::context& c): api::object(c) {}
virtual ~Z3_model_ref() {}
~Z3_model_ref() override {}
};
inline Z3_model_ref * to_model(Z3_model s) { return reinterpret_cast<Z3_model_ref *>(s); }
@ -34,8 +34,8 @@ inline model * to_model_ref(Z3_model s) { return to_model(s)->m_model.get(); }
struct Z3_func_interp_ref : public api::object {
model_ref m_model; // must have it to prevent reference to m_func_interp to be killed.
func_interp * m_func_interp;
Z3_func_interp_ref(api::context& c, model * m): api::object(c), m_model(m), m_func_interp(0) {}
virtual ~Z3_func_interp_ref() {}
Z3_func_interp_ref(api::context& c, model * m): api::object(c), m_model(m), m_func_interp(nullptr) {}
~Z3_func_interp_ref() override {}
};
inline Z3_func_interp_ref * to_func_interp(Z3_func_interp s) { return reinterpret_cast<Z3_func_interp_ref *>(s); }
@ -46,8 +46,8 @@ struct Z3_func_entry_ref : public api::object {
model_ref m_model; // must have it to prevent reference to m_func_entry to be killed.
func_interp * m_func_interp;
func_entry const * m_func_entry;
Z3_func_entry_ref(api::context& c, model * m):api::object(c), m_model(m), m_func_interp(0), m_func_entry(0) {}
virtual ~Z3_func_entry_ref() {}
Z3_func_entry_ref(api::context& c, model * m):api::object(c), m_model(m), m_func_interp(nullptr), m_func_entry(nullptr) {}
~Z3_func_entry_ref() override {}
};
inline Z3_func_entry_ref * to_func_entry(Z3_func_entry s) { return reinterpret_cast<Z3_func_entry_ref *>(s); }

View file

@ -52,11 +52,11 @@ extern "C" {
LOG_Z3_mk_numeral(c, n, ty);
RESET_ERROR_CODE();
if (!check_numeral_sort(c, ty)) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
if (!n) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
sort * _ty = to_sort(ty);
bool is_float = mk_c(c)->fpautil().is_float(_ty);
@ -73,11 +73,11 @@ extern "C" {
('P' == *m) ||
('+' == *m))))) {
SET_ERROR_CODE(Z3_PARSER_ERROR);
return 0;
RETURN_Z3(nullptr);
}
++m;
}
ast * a = 0;
ast * a = nullptr;
if (_ty->get_family_id() == mk_c(c)->get_fpa_fid()) {
// avoid expanding floats into huge rationals.
fpa_util & fu = mk_c(c)->fpautil();
@ -89,7 +89,7 @@ extern "C" {
else
a = mk_c(c)->mk_numeral_core(rational(n), _ty);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_int(Z3_context c, int value, Z3_sort ty) {
@ -97,11 +97,11 @@ extern "C" {
LOG_Z3_mk_int(c, value, ty);
RESET_ERROR_CODE();
if (!check_numeral_sort(c, ty)) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ast * a = mk_c(c)->mk_numeral_core(rational(value), to_sort(ty));
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_unsigned_int(Z3_context c, unsigned value, Z3_sort ty) {
@ -109,37 +109,37 @@ extern "C" {
LOG_Z3_mk_unsigned_int(c, value, ty);
RESET_ERROR_CODE();
if (!check_numeral_sort(c, ty)) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
ast * a = mk_c(c)->mk_numeral_core(rational(value), to_sort(ty));
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_int64(Z3_context c, long long value, Z3_sort ty) {
Z3_ast Z3_API Z3_mk_int64(Z3_context c, int64_t value, Z3_sort ty) {
Z3_TRY;
LOG_Z3_mk_int64(c, value, ty);
RESET_ERROR_CODE();
if (!check_numeral_sort(c, ty)) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
rational n(value, rational::i64());
ast* a = mk_c(c)->mk_numeral_core(n, to_sort(ty));
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_unsigned_int64(Z3_context c, unsigned long long value, Z3_sort ty) {
Z3_ast Z3_API Z3_mk_unsigned_int64(Z3_context c, uint64_t value, Z3_sort ty) {
Z3_TRY;
LOG_Z3_mk_unsigned_int64(c, value, ty);
RESET_ERROR_CODE();
if (!check_numeral_sort(c, ty)) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
rational n(value, rational::ui64());
ast * a = mk_c(c)->mk_numeral_core(n, to_sort(ty));
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a) {
@ -172,7 +172,7 @@ extern "C" {
if (mk_c(c)->bvutil().is_numeral(e, r, bv_size)) {
return Z3_TRUE;
}
uint64 v;
uint64_t v;
if (mk_c(c)->datalog_util().is_numeral(e, v)) {
r = rational(v, rational::ui64());
return Z3_TRUE;
@ -262,7 +262,7 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_get_numeral_small(Z3_context c, Z3_ast a, long long* num, long long* den) {
Z3_bool Z3_API Z3_get_numeral_small(Z3_context c, Z3_ast a, int64_t* num, int64_t* den) {
Z3_TRY;
// This function invokes Z3_get_numeral_rational, but it is still ok to add LOG command here because it does not return a Z3 object.
LOG_Z3_get_numeral_small(c, a, num, den);
@ -296,7 +296,7 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_ARG);
return Z3_FALSE;
}
long long l;
int64_t l;
if (Z3_get_numeral_int64(c, v, &l) && l >= INT_MIN && l <= INT_MAX) {
*i = static_cast<int>(l);
return Z3_TRUE;
@ -314,7 +314,7 @@ extern "C" {
SET_ERROR_CODE(Z3_INVALID_ARG);
return Z3_FALSE;
}
unsigned long long l;
uint64_t l;
if (Z3_get_numeral_uint64(c, v, &l) && (l <= 0xFFFFFFFF)) {
*u = static_cast<unsigned>(l);
return Z3_TRUE;
@ -323,7 +323,7 @@ extern "C" {
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_get_numeral_uint64(Z3_context c, Z3_ast v, unsigned long long* u) {
Z3_bool Z3_API Z3_get_numeral_uint64(Z3_context c, Z3_ast v, uint64_t* u) {
Z3_TRY;
// This function invokes Z3_get_numeral_rational, but it is still ok to add LOG command here because it does not return a Z3 object.
LOG_Z3_get_numeral_uint64(c, v, u);
@ -343,7 +343,7 @@ extern "C" {
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_get_numeral_int64(Z3_context c, Z3_ast v, long long* i) {
Z3_bool Z3_API Z3_get_numeral_int64(Z3_context c, Z3_ast v, int64_t* i) {
Z3_TRY;
// This function invokes Z3_get_numeral_rational, but it is still ok to add LOG command here because it does not return a Z3 object.
LOG_Z3_get_numeral_int64(c, v, i);
@ -362,7 +362,7 @@ extern "C" {
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_bool Z3_API Z3_get_numeral_rational_int64(Z3_context c, Z3_ast v, long long* num, long long* den) {
Z3_bool Z3_API Z3_get_numeral_rational_int64(Z3_context c, Z3_ast v, int64_t* num, int64_t* den) {
Z3_TRY;
// This function invokes Z3_get_numeral_rational, but it is still ok to add LOG command here because it does not return a Z3 object.
LOG_Z3_get_numeral_rational_int64(c, v, num, den);
@ -397,7 +397,7 @@ extern "C" {
}
ast * a = mk_c(c)->mk_numeral_core(r, mk_c(c)->bvutil().mk_sort(sz));
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -17,8 +17,8 @@ Revision History:
--*/
#include<iostream>
#include "util/cancel_eh.h"
#include "util/file_path.h"
#include "util/scoped_timer.h"
#include "util/file_path.h"
#include "parsers/smt2/smt2parser.h"
#include "opt/opt_context.h"
#include "opt/opt_cmds.h"
@ -31,12 +31,13 @@ Revision History:
#include "api/api_model.h"
#include "api/api_ast_vector.h"
extern "C" {
struct Z3_optimize_ref : public api::object {
opt::context* m_opt;
Z3_optimize_ref(api::context& c): api::object(c), m_opt(0) {}
virtual ~Z3_optimize_ref() { dealloc(m_opt); }
Z3_optimize_ref(api::context& c): api::object(c), m_opt(nullptr) {}
~Z3_optimize_ref() override { dealloc(m_opt); }
};
inline Z3_optimize_ref * to_optimize(Z3_optimize o) { return reinterpret_cast<Z3_optimize_ref *>(o); }
inline Z3_optimize of_optimize(Z3_optimize_ref * o) { return reinterpret_cast<Z3_optimize>(o); }
@ -50,7 +51,7 @@ extern "C" {
o->m_opt = alloc(opt::context,mk_c(c)->m());
mk_c(c)->save_object(o);
RETURN_Z3(of_optimize(o));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize o) {
@ -139,8 +140,16 @@ extern "C" {
r = to_optimize_ptr(o)->optimize();
}
catch (z3_exception& ex) {
mk_c(c)->handle_exception(ex);
if (!mk_c(c)->m().canceled()) {
mk_c(c)->handle_exception(ex);
}
r = l_undef;
if (ex.msg() == std::string("canceled") && mk_c(c)->m().canceled()) {
to_optimize_ptr(o)->set_reason_unknown(ex.msg());
}
else {
mk_c(c)->handle_exception(ex);
}
}
// to_optimize_ref(d).cleanup();
}
@ -171,7 +180,7 @@ extern "C" {
}
mk_c(c)->save_object(m_ref);
RETURN_Z3(of_model(m_ref));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p) {
@ -195,7 +204,7 @@ extern "C" {
to_optimize_ptr(o)->collect_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// get lower value or current approximation
@ -206,7 +215,7 @@ extern "C" {
expr_ref e = to_optimize_ptr(o)->get_lower(idx);
mk_c(c)->save_ast_trail(e);
RETURN_Z3(of_expr(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// get upper or current approximation
@ -217,7 +226,7 @@ extern "C" {
expr_ref e = to_optimize_ptr(o)->get_upper(idx);
mk_c(c)->save_ast_trail(e);
RETURN_Z3(of_expr(e));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// get lower value or current approximation
@ -231,7 +240,7 @@ extern "C" {
mk_c(c)->save_object(v);
v->m_ast_vector.append(es.size(), (ast*const*)es.c_ptr());
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
// get upper or current approximation
@ -245,7 +254,7 @@ extern "C" {
mk_c(c)->save_object(v);
v->m_ast_vector.append(es.size(), (ast*const*)es.c_ptr());
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o) {
@ -277,7 +286,7 @@ extern "C" {
mk_c(c)->save_object(st);
Z3_stats r = of_stats(st);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
static void Z3_optimize_from_stream(
@ -296,6 +305,11 @@ extern "C" {
parse_wcnf(*to_optimize_ptr(opt), s, h);
return;
}
if (ext && std::string("lp") == ext) {
unsigned_vector h;
parse_lp(*to_optimize_ptr(opt), s, h);
return;
}
scoped_ptr<cmd_context> ctx = alloc(cmd_context, false, &m);
install_opt_cmds(*ctx.get(), to_optimize_ptr(opt));
std::stringstream errstrm;
@ -367,7 +381,7 @@ extern "C" {
v->m_ast_vector.push_back(h);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o) {
@ -381,7 +395,7 @@ extern "C" {
v->m_ast_vector.push_back(to_optimize_ptr(o)->get_objective(i));
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}

View file

@ -34,7 +34,7 @@ extern "C" {
mk_c(c)->save_object(p);
Z3_params r = of_params(p);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
/**
@ -172,11 +172,11 @@ extern "C" {
RESET_ERROR_CODE();
if (i >= to_param_descrs_ptr(p)->size()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_symbol result = of_symbol(to_param_descrs_ptr(p)->get_param_name(i));
return result;
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_param_descrs_get_documentation(Z3_context c, Z3_param_descrs p, Z3_symbol s) {
@ -184,12 +184,12 @@ extern "C" {
LOG_Z3_param_descrs_get_documentation(c, p, s);
RESET_ERROR_CODE();
char const* result = to_param_descrs_ptr(p)->get_descr(to_symbol(s));
if (result == 0) {
if (result == nullptr) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
return mk_c(c)->mk_external_string(result);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_param_descrs_to_string(Z3_context c, Z3_param_descrs p) {

View file

@ -20,9 +20,13 @@ Revision History:
#include "api/api_log_macros.h"
#include "api/api_context.h"
#include "api/api_util.h"
#include "api/api_ast_vector.h"
#include "cmd_context/cmd_context.h"
#include "smt/smt_solver.h"
#include "parsers/smt2/smt2parser.h"
#include "solver/solver_na2as.h"
#include "tactic/portfolio/smt_strategic_solver.h"
extern "C" {
@ -38,7 +42,7 @@ extern "C" {
// ---------------
// Support for SMTLIB2
Z3_ast parse_smtlib2_stream(bool exec, Z3_context c, std::istream& is,
Z3_ast_vector parse_smtlib2_stream(bool exec, Z3_context c, std::istream& is,
unsigned num_sorts,
Z3_symbol const sort_names[],
Z3_sort const sorts[],
@ -48,6 +52,8 @@ extern "C" {
Z3_TRY;
scoped_ptr<cmd_context> ctx = alloc(cmd_context, false, &(mk_c(c)->m()));
ctx->set_ignore_check(true);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < num_decls; ++i) {
ctx->insert(to_symbol(decl_names[i]), to_func_decl(decls[i]));
}
@ -66,7 +72,7 @@ extern "C" {
ctx = nullptr;
mk_c(c)->m_parser_error_buffer = errstrm.str();
SET_ERROR_CODE(Z3_PARSER_ERROR);
return of_ast(mk_c(c)->m().mk_true());
return of_ast_vector(v);
}
}
catch (z3_exception& e) {
@ -74,16 +80,18 @@ extern "C" {
mk_c(c)->m_parser_error_buffer = errstrm.str();
ctx = nullptr;
SET_ERROR_CODE(Z3_PARSER_ERROR);
return of_ast(mk_c(c)->m().mk_true());
return of_ast_vector(v);
}
ptr_vector<expr>::const_iterator it = ctx->begin_assertions();
ptr_vector<expr>::const_iterator end = ctx->end_assertions();
unsigned size = static_cast<unsigned>(end - it);
return of_ast(mk_c(c)->mk_and(size, it));
Z3_CATCH_RETURN(0);
for (; it != end; ++it) {
v->m_ast_vector.push_back(*it);
}
return of_ast_vector(v);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str,
Z3_ast_vector Z3_API Z3_parse_smtlib2_string(Z3_context c, Z3_string str,
unsigned num_sorts,
Z3_symbol const sort_names[],
Z3_sort const sorts[],
@ -94,12 +102,12 @@ extern "C" {
LOG_Z3_parse_smtlib2_string(c, str, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
std::string s(str);
std::istringstream is(s);
Z3_ast r = parse_smtlib2_stream(false, c, is, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
Z3_ast_vector r = parse_smtlib2_stream(false, c, is, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name,
Z3_ast_vector Z3_API Z3_parse_smtlib2_file(Z3_context c, Z3_string file_name,
unsigned num_sorts,
Z3_symbol const sort_names[],
Z3_sort const sorts[],
@ -110,11 +118,41 @@ extern "C" {
LOG_Z3_parse_smtlib2_string(c, file_name, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
std::ifstream is(file_name);
if (!is) {
SET_ERROR_CODE(Z3_PARSER_ERROR);
return 0;
SET_ERROR_CODE(Z3_FILE_ACCESS_ERROR);
return nullptr;
}
Z3_ast r = parse_smtlib2_stream(false, c, is, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
Z3_ast_vector r = parse_smtlib2_stream(false, c, is, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_eval_smtlib2_string(Z3_context c, Z3_string str) {
std::stringstream ous;
Z3_TRY;
LOG_Z3_eval_smtlib2_string(c, str);
if (!mk_c(c)->cmd()) {
mk_c(c)->cmd() = alloc(cmd_context, false, &(mk_c(c)->m()));
mk_c(c)->cmd()->set_solver_factory(mk_smt_strategic_solver_factory());
}
scoped_ptr<cmd_context>& ctx = mk_c(c)->cmd();
std::string s(str);
std::istringstream is(s);
ctx->set_regular_stream(ous);
ctx->set_diagnostic_stream(ous);
try {
if (!parse_smt2_commands(*ctx.get(), is)) {
mk_c(c)->m_parser_error_buffer = ous.str();
SET_ERROR_CODE(Z3_PARSER_ERROR);
RETURN_Z3(mk_c(c)->mk_external_string(ous.str()));
}
}
catch (z3_exception& e) {
if (ous.str().empty()) ous << e.msg();
mk_c(c)->m_parser_error_buffer = ous.str();
SET_ERROR_CODE(Z3_PARSER_ERROR);
RETURN_Z3(mk_c(c)->mk_external_string(ous.str()));
}
RETURN_Z3(mk_c(c)->mk_external_string(ous.str()));
Z3_CATCH_RETURN(mk_c(c)->mk_external_string(ous.str()));
}
};

View file

@ -34,7 +34,7 @@ extern "C" {
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_atleast(Z3_context c, unsigned num_args,
@ -48,7 +48,7 @@ extern "C" {
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_pble(Z3_context c, unsigned num_args,
@ -66,7 +66,7 @@ extern "C" {
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_pbge(Z3_context c, unsigned num_args,
@ -84,7 +84,7 @@ extern "C" {
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_pbeq(Z3_context c, unsigned num_args,
@ -102,7 +102,7 @@ extern "C" {
mk_c(c)->save_ast_trail(a);
check_sorts(c, a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}

View file

@ -50,7 +50,7 @@ extern "C" {
if (!converter.to_polynomial(to_expr(p), _p, d) ||
!converter.to_polynomial(to_expr(q), _q, d)) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return 0;
return nullptr;
}
Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(result);
@ -74,7 +74,7 @@ extern "C" {
}
}
RETURN_Z3(of_ast_vector(result));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -52,21 +52,21 @@ extern "C"
Z3_TRY;
LOG_Z3_qe_model_project (c, m, num_bounds, bound, body);
RESET_ERROR_CODE();
app_ref_vector vars(mk_c(c)->m ());
if (!to_apps(num_bounds, bound, vars)) {
SET_ERROR_CODE (Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr_ref result (mk_c(c)->m ());
result = to_expr (body);
model_ref model (to_model_ref (m));
spacer::qe_project (mk_c(c)->m (), vars, result, model);
spacer::qe_project (mk_c(c)->m (), vars, result, *model);
mk_c(c)->save_ast_trail (result.get ());
return of_expr (result.get ());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_qe_model_project_skolem (Z3_context c,
@ -83,7 +83,7 @@ extern "C"
ast_manager& man = mk_c(c)->m ();
app_ref_vector vars(man);
if (!to_apps(num_bounds, bound, vars)) {
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
expr_ref result (mk_c(c)->m ());
@ -103,7 +103,7 @@ extern "C"
}
return of_expr (result.get ());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_model_extrapolate (Z3_context c,
@ -119,18 +119,15 @@ extern "C"
facts.push_back (to_expr (fml));
flatten_and (facts);
spacer::model_evaluator_util mev (mk_c(c)->m());
mev.set_model (*model);
expr_ref_vector lits (mk_c(c)->m());
spacer::compute_implicant_literals (mev, facts, lits);
spacer::compute_implicant_literals (*model, facts, lits);
expr_ref result (mk_c(c)->m ());
result = mk_and (lits);
mk_c(c)->save_ast_trail (result.get ());
return of_expr (result.get ());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_qe_lite (Z3_context c, Z3_ast_vector vars, Z3_ast body)
@ -145,7 +142,7 @@ extern "C"
app *a = to_app (vVars.get (i));
if (a->get_kind () != AST_APP) {
SET_ERROR_CODE (Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
vApps.push_back (a);
}
@ -167,7 +164,7 @@ extern "C"
mk_c(c)->save_ast_trail (result.get ());
return of_expr (result);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
}

View file

@ -37,10 +37,10 @@ extern "C" {
c,
is_forall,
weight,
0,
0,
nullptr,
nullptr,
num_patterns, patterns,
0, 0,
0, nullptr,
num_decls, sorts,
decl_names,
body
@ -104,7 +104,7 @@ extern "C" {
}
mk_c(c)->save_ast_trail(result.get());
return of_ast(result.get());
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_quantifier_ex(
@ -166,17 +166,17 @@ extern "C" {
ptr_vector<expr> bound_asts;
if (num_patterns > 0 && num_no_patterns > 0) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
if (num_bound == 0) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
for (unsigned i = 0; i < num_bound; ++i) {
app* a = to_app(bound[i]);
if (a->get_kind() != AST_APP) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
symbol s(to_app(a)->get_decl()->get_name());
names.push_back(of_symbol(s));
@ -184,7 +184,7 @@ extern "C" {
bound_asts.push_back(a);
if (a->get_family_id() != null_family_id || a->get_num_args() != 0) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
// Abstract patterns
@ -205,7 +205,7 @@ extern "C" {
expr_ref result(mk_c(c)->m());
if (!is_app(to_expr(no_patterns[i]))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
app* pat = to_app(to_expr(no_patterns[i]));
expr_abstract(mk_c(c)->m(), 0, num_bound, bound_asts.c_ptr(), pat, result);
@ -224,7 +224,7 @@ extern "C" {
names.size(), types.c_ptr(), names.c_ptr(),
of_ast(abs_body.get()));
RETURN_Z3(result);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_quantifier_const(Z3_context c,
@ -235,10 +235,10 @@ extern "C" {
unsigned num_patterns,
Z3_pattern const patterns[],
Z3_ast body) {
return Z3_mk_quantifier_const_ex(c, is_forall, weight, 0, 0,
return Z3_mk_quantifier_const_ex(c, is_forall, weight, nullptr, nullptr,
num_bound, bound,
num_patterns, patterns,
0, 0,
0, nullptr,
body);
}
@ -269,13 +269,13 @@ extern "C" {
for (unsigned i = 0; i < num_patterns; ++i) {
if (!is_app(to_expr(terms[i]))) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
}
app* a = mk_c(c)->m().mk_pattern(num_patterns, reinterpret_cast<app*const*>(to_exprs(terms)));
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_pattern(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_bound(Z3_context c, unsigned index, Z3_sort ty) {
@ -285,7 +285,7 @@ extern "C" {
ast* a = mk_c(c)->m().mk_var(index, to_sort(ty));
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a) {
@ -344,9 +344,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
@ -376,9 +376,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_symbol Z3_API Z3_get_quantifier_bound_name(Z3_context c, Z3_ast a, unsigned i) {
@ -391,9 +391,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
return 0;
return nullptr;
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_get_quantifier_bound_sort(Z3_context c, Z3_ast a, unsigned i) {
@ -407,9 +407,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_get_quantifier_body(Z3_context c, Z3_ast a) {
@ -423,9 +423,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_get_quantifier_num_bound(Z3_context c, Z3_ast a) {
@ -470,9 +470,9 @@ extern "C" {
}
else {
SET_ERROR_CODE(Z3_SORT_ERROR);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_pattern_to_ast(Z3_context c, Z3_pattern p) {

View file

@ -62,7 +62,7 @@ extern "C" {
rcnumeral r;
rcfm(c).set(r, q);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_mk_small_int(Z3_context c, int val) {
@ -73,7 +73,7 @@ extern "C" {
rcnumeral r;
rcfm(c).set(r, val);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_mk_pi(Z3_context c) {
@ -84,7 +84,7 @@ extern "C" {
rcnumeral r;
rcfm(c).mk_pi(r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_mk_e(Z3_context c) {
@ -95,7 +95,7 @@ extern "C" {
rcnumeral r;
rcfm(c).mk_e(r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(Z3_context c) {
@ -106,7 +106,7 @@ extern "C" {
rcnumeral r;
rcfm(c).mk_infinitesimal(r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_rcf_mk_roots(Z3_context c, unsigned n, Z3_rcf_num const a[], Z3_rcf_num roots[]) {
@ -145,7 +145,7 @@ extern "C" {
rcnumeral r;
rcfm(c).add(to_rcnumeral(a), to_rcnumeral(b), r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_sub(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
@ -156,7 +156,7 @@ extern "C" {
rcnumeral r;
rcfm(c).sub(to_rcnumeral(a), to_rcnumeral(b), r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_mul(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
@ -167,7 +167,7 @@ extern "C" {
rcnumeral r;
rcfm(c).mul(to_rcnumeral(a), to_rcnumeral(b), r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_div(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
@ -178,7 +178,7 @@ extern "C" {
rcnumeral r;
rcfm(c).div(to_rcnumeral(a), to_rcnumeral(b), r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_neg(Z3_context c, Z3_rcf_num a) {
@ -189,7 +189,7 @@ extern "C" {
rcnumeral r;
rcfm(c).neg(to_rcnumeral(a), r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_inv(Z3_context c, Z3_rcf_num a) {
@ -200,7 +200,7 @@ extern "C" {
rcnumeral r;
rcfm(c).inv(to_rcnumeral(a), r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_rcf_num Z3_API Z3_rcf_power(Z3_context c, Z3_rcf_num a, unsigned k) {
@ -211,7 +211,7 @@ extern "C" {
rcnumeral r;
rcfm(c).power(to_rcnumeral(a), k, r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {

View file

@ -31,7 +31,7 @@ extern "C" {
sort * ty = mk_c(c)->sutil().str.mk_seq(to_sort(domain));
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_re_sort(Z3_context c, Z3_sort domain) {
@ -41,7 +41,7 @@ extern "C" {
sort * ty = mk_c(c)->sutil().re.mk_re(to_sort(domain));
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_string(Z3_context c, Z3_string str) {
@ -52,7 +52,7 @@ extern "C" {
app* a = mk_c(c)->sutil().str.mk_string(s);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_sort Z3_API Z3_mk_string_sort(Z3_context c) {
@ -62,7 +62,7 @@ extern "C" {
sort* ty = mk_c(c)->sutil().str.mk_string_sort();
mk_c(c)->save_ast_trail(ty);
RETURN_Z3(of_sort(ty));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_seq_sort(Z3_context c, Z3_sort s) {
@ -152,7 +152,7 @@ extern "C" {
app* a = hi == 0 ? mk_c(c)->sutil().re.mk_loop(to_expr(r), lo) : mk_c(c)->sutil().re.mk_loop(to_expr(r), lo, hi);
mk_c(c)->save_ast_trail(a);
RETURN_Z3(of_ast(a));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
MK_UNARY(Z3_mk_re_plus, mk_c(c)->get_seq_fid(), OP_RE_PLUS, SKIP);
@ -165,7 +165,7 @@ extern "C" {
MK_BINARY(Z3_mk_re_range, mk_c(c)->get_seq_fid(), OP_RE_RANGE, SKIP);
MK_SORTED(Z3_mk_re_empty, mk_c(c)->sutil().re.mk_empty);
MK_SORTED(Z3_mk_re_full, mk_c(c)->sutil().re.mk_full);
MK_SORTED(Z3_mk_re_full, mk_c(c)->sutil().re.mk_full_seq);

View file

@ -17,6 +17,11 @@ Revision History:
--*/
#include<iostream>
#include "util/scoped_ctrl_c.h"
#include "util/cancel_eh.h"
#include "util/file_path.h"
#include "util/scoped_timer.h"
#include "ast/ast_pp.h"
#include "api/z3.h"
#include "api/api_log_macros.h"
#include "api/api_context.h"
@ -28,8 +33,8 @@ Revision History:
#include "solver/tactic2solver.h"
#include "util/scoped_ctrl_c.h"
#include "util/cancel_eh.h"
#include "util/file_path.h"
#include "util/scoped_timer.h"
#include "util/file_path.h"
#include "tactic/portfolio/smt_strategic_solver.h"
#include "smt/smt_solver.h"
#include "smt/smt_implied_equalities.h"
@ -40,6 +45,7 @@ Revision History:
#include "sat/sat_solver.h"
#include "sat/tactic/goal2sat.h"
extern "C" {
static void init_solver_core(Z3_context c, Z3_solver _s) {
@ -57,7 +63,7 @@ extern "C" {
}
static void init_solver(Z3_context c, Z3_solver s) {
if (to_solver(s)->m_solver.get() == 0)
if (to_solver(s)->m_solver.get() == nullptr)
init_solver_core(c, s);
}
@ -69,7 +75,7 @@ extern "C" {
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_solver Z3_API Z3_mk_solver(Z3_context c) {
@ -80,7 +86,7 @@ extern "C" {
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_solver Z3_API Z3_mk_solver_for_logic(Z3_context c, Z3_symbol logic) {
@ -91,7 +97,7 @@ extern "C" {
std::ostringstream strm;
strm << "logic '" << to_symbol(logic) << "' is not recognized";
throw default_exception(strm.str());
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
else {
Z3_solver_ref * s = alloc(Z3_solver_ref, *mk_c(c), mk_smt_strategic_solver_factory(to_symbol(logic)));
@ -99,7 +105,7 @@ extern "C" {
Z3_solver r = of_solver(s);
RETURN_Z3(r);
}
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_solver Z3_API Z3_mk_solver_from_tactic(Z3_context c, Z3_tactic t) {
@ -110,7 +116,7 @@ extern "C" {
mk_c(c)->save_object(s);
Z3_solver r = of_solver(s);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_solver Z3_API Z3_solver_translate(Z3_context c, Z3_solver s, Z3_context target) {
@ -118,13 +124,22 @@ extern "C" {
LOG_Z3_solver_translate(c, s, target);
RESET_ERROR_CODE();
params_ref const& p = to_solver(s)->m_params;
Z3_solver_ref * sr = alloc(Z3_solver_ref, *mk_c(target), 0);
Z3_solver_ref * sr = alloc(Z3_solver_ref, *mk_c(target), nullptr);
init_solver(c, s);
sr->m_solver = to_solver(s)->m_solver->translate(mk_c(target)->m(), p);
mk_c(target)->save_object(sr);
Z3_solver r = of_solver(sr);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_solver_import_model_converter(Z3_context c, Z3_solver src, Z3_solver dst) {
Z3_TRY;
LOG_Z3_solver_import_model_converter(c, src, dst);
model_converter_ref mc = to_solver_ref(src)->get_model_converter();
to_solver_ref(dst)->set_model_converter(mc.get());
Z3_CATCH;
}
void solver_from_stream(Z3_context c, Z3_solver s, std::istream& is) {
@ -137,7 +152,7 @@ extern "C" {
return;
}
bool initialized = to_solver(s)->m_solver.get() != 0;
bool initialized = to_solver(s)->m_solver.get() != nullptr;
if (!initialized)
init_solver(c, s);
ptr_vector<expr>::const_iterator it = ctx->begin_assertions();
@ -145,7 +160,7 @@ extern "C" {
for (; it != end; ++it) {
to_solver_ref(s)->assert_expr(*it);
}
// to_solver_ref(s)->set_model_converter(ctx->get_model_converter());
to_solver_ref(s)->set_model_converter(ctx->get_model_converter());
}
void Z3_API Z3_solver_from_string(Z3_context c, Z3_solver s, Z3_string c_str) {
@ -167,10 +182,10 @@ extern "C" {
}
else if (ext && std::string("dimacs") == ext) {
ast_manager& m = to_solver_ref(s)->get_manager();
sat::solver solver(to_solver_ref(s)->get_params(), m.limit(), nullptr);
sat::solver solver(to_solver_ref(s)->get_params(), m.limit());
parse_dimacs(is, solver);
sat2goal s2g;
model_converter_ref mc;
ref<sat2goal::mc> mc;
atom2bool_var a2b(m);
goal g(m);
s2g(solver, a2b, to_solver_ref(s)->get_params(), g, mc);
@ -190,13 +205,13 @@ extern "C" {
RESET_ERROR_CODE();
std::ostringstream buffer;
param_descrs descrs;
bool initialized = to_solver(s)->m_solver.get() != 0;
bool initialized = to_solver(s)->m_solver.get() != nullptr;
if (!initialized)
init_solver(c, s);
to_solver_ref(s)->collect_param_descrs(descrs);
context_params::collect_solver_param_descrs(descrs);
if (!initialized)
to_solver(s)->m_solver = 0;
to_solver(s)->m_solver = nullptr;
descrs.display(buffer);
return mk_c(c)->mk_external_string(buffer.str());
Z3_CATCH_RETURN("");
@ -208,16 +223,16 @@ extern "C" {
RESET_ERROR_CODE();
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref, *mk_c(c));
mk_c(c)->save_object(d);
bool initialized = to_solver(s)->m_solver.get() != 0;
bool initialized = to_solver(s)->m_solver.get() != nullptr;
if (!initialized)
init_solver(c, s);
to_solver_ref(s)->collect_param_descrs(d->m_descrs);
context_params::collect_solver_param_descrs(d->m_descrs);
if (!initialized)
to_solver(s)->m_solver = 0;
to_solver(s)->m_solver = nullptr;
Z3_param_descrs r = of_param_descrs(d);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_solver_set_params(Z3_context c, Z3_solver s, Z3_params p) {
@ -288,7 +303,7 @@ extern "C" {
Z3_TRY;
LOG_Z3_solver_reset(c, s);
RESET_ERROR_CODE();
to_solver(s)->m_solver = 0;
to_solver(s)->m_solver = nullptr;
Z3_CATCH;
}
@ -321,6 +336,7 @@ extern "C" {
to_solver_ref(s)->assert_expr(to_expr(a), to_expr(p));
Z3_CATCH;
}
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s) {
Z3_TRY;
@ -334,6 +350,22 @@ extern "C" {
v->m_ast_vector.push_back(to_solver_ref(s)->get_assertion(i));
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_solver_get_units(Z3_context c, Z3_solver s) {
Z3_TRY;
LOG_Z3_solver_get_units(c, s);
RESET_ERROR_CODE();
init_solver(c, s);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
expr_ref_vector fmls = to_solver_ref(s)->get_units(mk_c(c)->m());
for (expr* f : fmls) {
v->m_ast_vector.push_back(f);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
@ -360,7 +392,9 @@ extern "C" {
}
catch (z3_exception & ex) {
to_solver_ref(s)->set_reason_unknown(eh);
mk_c(c)->handle_exception(ex);
if (!mk_c(c)->m().canceled()) {
mk_c(c)->handle_exception(ex);
}
return Z3_L_UNDEF;
}
}
@ -375,7 +409,7 @@ extern "C" {
LOG_Z3_solver_check(c, s);
RESET_ERROR_CODE();
init_solver(c, s);
return _solver_check(c, s, 0, 0);
return _solver_check(c, s, 0, nullptr);
Z3_CATCH_RETURN(Z3_L_UNDEF);
}
@ -397,13 +431,13 @@ extern "C" {
to_solver_ref(s)->get_model(_m);
if (!_m) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c));
m_ref->m_model = _m;
mk_c(c)->save_object(m_ref);
RETURN_Z3(of_model(m_ref));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_solver_get_proof(Z3_context c, Z3_solver s) {
@ -414,11 +448,11 @@ extern "C" {
proof * p = to_solver_ref(s)->get_proof();
if (!p) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
mk_c(c)->save_ast_trail(p);
RETURN_Z3(of_ast(p));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s) {
@ -426,15 +460,15 @@ extern "C" {
LOG_Z3_solver_get_unsat_core(c, s);
RESET_ERROR_CODE();
init_solver(c, s);
ptr_vector<expr> core;
expr_ref_vector core(mk_c(c)->m());
to_solver_ref(s)->get_unsat_core(core);
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (unsigned i = 0; i < core.size(); i++) {
v->m_ast_vector.push_back(core[i]);
for (expr* e : core) {
v->m_ast_vector.push_back(e);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_solver_get_reason_unknown(Z3_context c, Z3_solver s) {
@ -458,7 +492,7 @@ extern "C" {
mk_c(c)->save_object(st);
Z3_stats r = of_stats(st);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_solver_to_string(Z3_context c, Z3_solver s) {
@ -502,24 +536,22 @@ extern "C" {
init_solver(c, s);
expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
unsigned sz = __assumptions.size();
for (unsigned i = 0; i < sz; ++i) {
if (!is_expr(__assumptions[i])) {
for (ast* e : __assumptions) {
if (!is_expr(e)) {
_assumptions.finalize(); _consequences.finalize(); _variables.finalize();
SET_ERROR_CODE(Z3_INVALID_USAGE);
return Z3_L_UNDEF;
}
_assumptions.push_back(to_expr(__assumptions[i]));
_assumptions.push_back(to_expr(e));
}
ast_ref_vector const& __variables = to_ast_vector_ref(variables);
sz = __variables.size();
for (unsigned i = 0; i < sz; ++i) {
if (!is_expr(__variables[i])) {
for (ast* a : __variables) {
if (!is_expr(a)) {
_assumptions.finalize(); _consequences.finalize(); _variables.finalize();
SET_ERROR_CODE(Z3_INVALID_USAGE);
return Z3_L_UNDEF;
}
_variables.push_back(to_expr(__variables[i]));
_variables.push_back(to_expr(a));
}
lbool result = l_undef;
unsigned timeout = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
@ -544,11 +576,55 @@ extern "C" {
if (result == l_undef) {
to_solver_ref(s)->set_reason_unknown(eh);
}
for (unsigned i = 0; i < _consequences.size(); ++i) {
to_ast_vector_ref(consequences).push_back(_consequences[i].get());
for (expr* e : _consequences) {
to_ast_vector_ref(consequences).push_back(e);
}
return static_cast<Z3_lbool>(result);
Z3_CATCH_RETURN(Z3_L_UNDEF);
}
Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vs, unsigned cutoff) {
Z3_TRY;
LOG_Z3_solver_cube(c, s, vs, cutoff);
ast_manager& m = mk_c(c)->m();
expr_ref_vector result(m), vars(m);
for (ast* a : to_ast_vector_ref(vs)) {
if (!is_expr(a)) {
SET_ERROR_CODE(Z3_INVALID_USAGE);
}
else {
vars.push_back(to_expr(a));
}
}
unsigned timeout = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
unsigned rlimit = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
bool use_ctrl_c = to_solver(s)->m_params.get_bool("ctrl_c", false);
cancel_eh<reslimit> eh(mk_c(c)->m().limit());
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);
scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
try {
result.append(to_solver_ref(s)->cube(vars, cutoff));
}
catch (z3_exception & ex) {
mk_c(c)->handle_exception(ex);
return 0;
}
}
Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
mk_c(c)->save_object(v);
for (expr* e : result) {
v->m_ast_vector.push_back(e);
}
to_ast_vector_ref(vs).reset();
for (expr* a : vars) {
to_ast_vector_ref(vs).push_back(a);
}
RETURN_Z3(of_ast_vector(v));
Z3_CATCH_RETURN(0);
}
};

View file

@ -26,8 +26,8 @@ struct Z3_solver_ref : public api::object {
ref<solver> m_solver;
params_ref m_params;
symbol m_logic;
Z3_solver_ref(api::context& c, solver_factory * f): api::object(c), m_solver_factory(f), m_solver(0), m_logic(symbol::null) {}
virtual ~Z3_solver_ref() {}
Z3_solver_ref(api::context& c, solver_factory * f): api::object(c), m_solver_factory(f), m_solver(nullptr), m_logic(symbol::null) {}
~Z3_solver_ref() override {}
};
inline Z3_solver_ref * to_solver(Z3_solver s) { return reinterpret_cast<Z3_solver_ref *>(s); }

View file

@ -130,7 +130,7 @@ extern "C" {
Z3_CATCH_RETURN(0.0);
}
__uint64 Z3_API Z3_get_estimated_alloc_size(void) {
uint64_t Z3_API Z3_get_estimated_alloc_size(void) {
return memory::get_allocation_size();
}

View file

@ -24,7 +24,7 @@ Revision History:
struct Z3_stats_ref : public api::object {
statistics m_stats;
Z3_stats_ref(api::context& c): api::object(c) {}
virtual ~Z3_stats_ref() {}
~Z3_stats_ref() override {}
};
inline Z3_stats_ref * to_stats(Z3_stats s) { return reinterpret_cast<Z3_stats_ref *>(s); }

View file

@ -25,25 +25,25 @@ Revision History:
#include "util/cancel_eh.h"
#include "util/scoped_timer.h"
Z3_apply_result_ref::Z3_apply_result_ref(api::context& c, ast_manager & m): api::object(c), m_core(m) {
Z3_apply_result_ref::Z3_apply_result_ref(api::context& c, ast_manager & m): api::object(c) {
}
extern "C" {
#define RETURN_TACTIC(_t_) { \
#define RETURN_TACTIC(_t_) { \
Z3_tactic_ref * _ref_ = alloc(Z3_tactic_ref, *mk_c(c)); \
_ref_->m_tactic = _t_; \
mk_c(c)->save_object(_ref_); \
Z3_tactic _result_ = of_tactic(_ref_); \
RETURN_Z3(_result_); \
_ref_->m_tactic = _t_; \
mk_c(c)->save_object(_ref_); \
Z3_tactic _result_ = of_tactic(_ref_); \
RETURN_Z3(_result_); \
}
#define RETURN_PROBE(_t_) { \
#define RETURN_PROBE(_t_) { \
Z3_probe_ref * _ref_ = alloc(Z3_probe_ref, *mk_c(c)); \
_ref_->m_probe = _t_; \
mk_c(c)->save_object(_ref_); \
Z3_probe _result_ = of_probe(_ref_); \
RETURN_Z3(_result_); \
_ref_->m_probe = _t_; \
mk_c(c)->save_object(_ref_); \
Z3_probe _result_ = of_probe(_ref_); \
RETURN_Z3(_result_); \
}
Z3_tactic Z3_API Z3_mk_tactic(Z3_context c, Z3_string name) {
@ -51,13 +51,13 @@ extern "C" {
LOG_Z3_mk_tactic(c, name);
RESET_ERROR_CODE();
tactic_cmd * t = mk_c(c)->find_tactic_cmd(symbol(name));
if (t == 0) {
if (t == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
tactic * new_t = t->mk(mk_c(c)->m());
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_tactic_inc_ref(Z3_context c, Z3_tactic t) {
@ -81,13 +81,13 @@ extern "C" {
LOG_Z3_mk_probe(c, name);
RESET_ERROR_CODE();
probe_info * p = mk_c(c)->find_probe(symbol(name));
if (p == 0) {
if (p == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
probe * new_p = p->get();
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_probe_inc_ref(Z3_context c, Z3_probe p) {
@ -112,7 +112,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = and_then(to_tactic_ref(t1), to_tactic_ref(t2));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_or_else(Z3_context c, Z3_tactic t1, Z3_tactic t2) {
@ -121,7 +121,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = or_else(to_tactic_ref(t1), to_tactic_ref(t2));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_par_or(Z3_context c, unsigned num, Z3_tactic const ts[]) {
@ -134,7 +134,7 @@ extern "C" {
}
tactic * new_t = par(num, _ts.c_ptr());
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_par_and_then(Z3_context c, Z3_tactic t1, Z3_tactic t2) {
@ -143,7 +143,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = par_and_then(to_tactic_ref(t1), to_tactic_ref(t2));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_try_for(Z3_context c, Z3_tactic t, unsigned ms) {
@ -152,7 +152,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = try_for(to_tactic_ref(t), ms);
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_when(Z3_context c, Z3_probe p, Z3_tactic t) {
@ -161,7 +161,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = when(to_probe_ref(p), to_tactic_ref(t));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_cond(Z3_context c, Z3_probe p, Z3_tactic t1, Z3_tactic t2) {
@ -170,7 +170,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = cond(to_probe_ref(p), to_tactic_ref(t1), to_tactic_ref(t2));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_repeat(Z3_context c, Z3_tactic t, unsigned max) {
@ -179,7 +179,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = repeat(to_tactic_ref(t), max);
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_skip(Z3_context c) {
@ -188,7 +188,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = mk_skip_tactic();
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_fail(Z3_context c) {
@ -197,7 +197,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = mk_fail_tactic();
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_fail_if(Z3_context c, Z3_probe p) {
@ -206,7 +206,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = fail_if(to_probe_ref(p));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_fail_if_not_decided(Z3_context c) {
@ -215,7 +215,7 @@ extern "C" {
RESET_ERROR_CODE();
tactic * new_t = mk_fail_if_undecided_tactic();
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_tactic Z3_API Z3_tactic_using_params(Z3_context c, Z3_tactic t, Z3_params p) {
@ -227,7 +227,7 @@ extern "C" {
to_param_ref(p).validate(r);
tactic * new_t = using_params(to_tactic_ref(t), to_param_ref(p));
RETURN_TACTIC(new_t);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_const(Z3_context c, double val) {
@ -236,7 +236,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_const_probe(val);
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_lt(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -245,7 +245,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_lt(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_gt(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -254,7 +254,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_gt(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_le(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -263,7 +263,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_le(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_ge(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -272,7 +272,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_ge(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_eq(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -281,7 +281,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_eq(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_and(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -290,7 +290,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_and(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_or(Z3_context c, Z3_probe p1, Z3_probe p2) {
@ -299,7 +299,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_or(to_probe_ref(p1), to_probe_ref(p2));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_probe Z3_API Z3_probe_not(Z3_context c, Z3_probe p) {
@ -308,7 +308,7 @@ extern "C" {
RESET_ERROR_CODE();
probe * new_p = mk_not(to_probe_ref(p));
RETURN_PROBE(new_p);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
unsigned Z3_API Z3_get_num_tactics(Z3_context c) {
@ -372,7 +372,7 @@ extern "C" {
to_tactic_ref(t)->collect_param_descrs(d->m_descrs);
Z3_param_descrs r = of_param_descrs(d);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_string Z3_API Z3_tactic_get_descr(Z3_context c, Z3_string name) {
@ -380,7 +380,7 @@ extern "C" {
LOG_Z3_tactic_get_descr(c, name);
RESET_ERROR_CODE();
tactic_cmd * t = mk_c(c)->find_tactic_cmd(symbol(name));
if (t == 0) {
if (t == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
@ -393,7 +393,7 @@ extern "C" {
LOG_Z3_probe_get_descr(c, name);
RESET_ERROR_CODE();
probe_info * p = mk_c(c)->find_probe(symbol(name));
if (p == 0) {
if (p == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG);
return "";
}
@ -418,12 +418,14 @@ extern "C" {
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);
try {
exec(*to_tactic_ref(t), new_goal, ref->m_subgoals, ref->m_mc, ref->m_pc, ref->m_core);
exec(*to_tactic_ref(t), new_goal, ref->m_subgoals);
ref->m_pc = new_goal->pc();
ref->m_mc = new_goal->mc();
return of_apply_result(ref);
}
catch (z3_exception & ex) {
mk_c(c)->handle_exception(ex);
return 0;
return nullptr;
}
}
}
@ -443,7 +445,7 @@ extern "C" {
params_ref p;
Z3_apply_result r = _tactic_apply(c, t, g, p);
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_apply_result Z3_API Z3_tactic_apply_ex(Z3_context c, Z3_tactic t, Z3_goal g, Z3_params p) {
@ -455,7 +457,7 @@ extern "C" {
to_param_ref(p).validate(pd);
Z3_apply_result r = _tactic_apply(c, t, g, to_param_ref(p));
RETURN_Z3(r);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_apply_result_inc_ref(Z3_context c, Z3_apply_result r) {
@ -503,32 +505,15 @@ extern "C" {
RESET_ERROR_CODE();
if (i > to_apply_result(r)->m_subgoals.size()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
RETURN_Z3(nullptr);
}
Z3_goal_ref * g = alloc(Z3_goal_ref, *mk_c(c));
g->m_goal = to_apply_result(r)->m_subgoals[i];
mk_c(c)->save_object(g);
Z3_goal result = of_goal(g);
RETURN_Z3(result);
Z3_CATCH_RETURN(0);
Z3_CATCH_RETURN(nullptr);
}
Z3_model Z3_API Z3_apply_result_convert_model(Z3_context c, Z3_apply_result r, unsigned i, Z3_model m) {
Z3_TRY;
LOG_Z3_apply_result_convert_model(c, r, i, m);
RESET_ERROR_CODE();
if (i > to_apply_result(r)->m_subgoals.size()) {
SET_ERROR_CODE(Z3_IOB);
RETURN_Z3(0);
}
model_ref new_m = to_model_ref(m)->copy();
if (to_apply_result(r)->m_mc)
to_apply_result(r)->m_mc->operator()(new_m, i);
Z3_model_ref * m_ref = alloc(Z3_model_ref, *mk_c(c));
m_ref->m_model = new_m;
mk_c(c)->save_object(m_ref);
RETURN_Z3(of_model(m_ref));
Z3_CATCH_RETURN(0);
}
};

View file

@ -29,30 +29,29 @@ namespace api {
struct Z3_tactic_ref : public api::object {
tactic_ref m_tactic;
Z3_tactic_ref(api::context& c): api::object(c) {}
virtual ~Z3_tactic_ref() {}
~Z3_tactic_ref() override {}
};
struct Z3_probe_ref : public api::object {
probe_ref m_probe;
Z3_probe_ref(api::context& c):api::object(c) {}
virtual ~Z3_probe_ref() {}
~Z3_probe_ref() override {}
};
inline Z3_tactic_ref * to_tactic(Z3_tactic g) { return reinterpret_cast<Z3_tactic_ref *>(g); }
inline Z3_tactic of_tactic(Z3_tactic_ref * g) { return reinterpret_cast<Z3_tactic>(g); }
inline tactic * to_tactic_ref(Z3_tactic g) { return g == 0 ? 0 : to_tactic(g)->m_tactic.get(); }
inline tactic * to_tactic_ref(Z3_tactic g) { return g == nullptr ? nullptr : to_tactic(g)->m_tactic.get(); }
inline Z3_probe_ref * to_probe(Z3_probe g) { return reinterpret_cast<Z3_probe_ref *>(g); }
inline Z3_probe of_probe(Z3_probe_ref * g) { return reinterpret_cast<Z3_probe>(g); }
inline probe * to_probe_ref(Z3_probe g) { return g == 0 ? 0 : to_probe(g)->m_probe.get(); }
inline probe * to_probe_ref(Z3_probe g) { return g == nullptr ? nullptr : to_probe(g)->m_probe.get(); }
struct Z3_apply_result_ref : public api::object {
goal_ref_buffer m_subgoals;
model_converter_ref m_mc;
proof_converter_ref m_pc;
expr_dependency_ref m_core;
Z3_apply_result_ref(api::context& c, ast_manager & m);
virtual ~Z3_apply_result_ref() {}
~Z3_apply_result_ref() override {}
};
inline Z3_apply_result_ref * to_apply_result(Z3_apply_result g) { return reinterpret_cast<Z3_apply_result_ref *>(g); }

View file

@ -88,22 +88,22 @@ inline lbool to_lbool(Z3_lbool b) { return static_cast<lbool>(b); }
struct Z3_params_ref : public api::object {
params_ref m_params;
Z3_params_ref(api::context& c): api::object(c) {}
virtual ~Z3_params_ref() {}
~Z3_params_ref() override {}
};
inline Z3_params_ref * to_params(Z3_params p) { return reinterpret_cast<Z3_params_ref *>(p); }
inline Z3_params of_params(Z3_params_ref * p) { return reinterpret_cast<Z3_params>(p); }
inline params_ref to_param_ref(Z3_params p) { return p == 0 ? params_ref() : to_params(p)->m_params; }
inline params_ref to_param_ref(Z3_params p) { return p == nullptr ? params_ref() : to_params(p)->m_params; }
struct Z3_param_descrs_ref : public api::object {
param_descrs m_descrs;
Z3_param_descrs_ref(api::context& c): api::object(c) {}
virtual ~Z3_param_descrs_ref() {}
~Z3_param_descrs_ref() override {}
};
inline Z3_param_descrs_ref * to_param_descrs(Z3_param_descrs p) { return reinterpret_cast<Z3_param_descrs_ref *>(p); }
inline Z3_param_descrs of_param_descrs(Z3_param_descrs_ref * p) { return reinterpret_cast<Z3_param_descrs>(p); }
inline param_descrs * to_param_descrs_ptr(Z3_param_descrs p) { return p == 0 ? 0 : &(to_param_descrs(p)->m_descrs); }
inline param_descrs * to_param_descrs_ptr(Z3_param_descrs p) { return p == nullptr ? nullptr : &(to_param_descrs(p)->m_descrs); }
#define SKIP ((void) 0)

View file

@ -147,20 +147,12 @@ namespace z3 {
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
}
void init_interp(config & c) {
m_ctx = Z3_mk_interpolation_context(c);
m_enable_exceptions = true;
Z3_set_error_handler(m_ctx, 0);
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
}
context(context const & s);
context & operator=(context const & s);
public:
struct interpolation {};
context() { config c; init(c); }
context(config & c) { init(c); }
context(config & c, interpolation) { init_interp(c); }
~context() { Z3_del_context(m_ctx); }
operator Z3_context() const { return m_ctx; }
@ -187,8 +179,8 @@ namespace z3 {
\brief The C++ API uses by defaults exceptions on errors.
For applications that don't work well with exceptions (there should be only few)
you have the ability to turn off exceptions. The tradeoffs are that applications
have to very careful about using check_error() after calls that may result in an errornous
state.
have to be very careful about using check_error() after calls that may result in an
erroneous state.
*/
void set_enable_exceptions(bool f) { m_enable_exceptions = f; }
@ -213,7 +205,7 @@ namespace z3 {
/**
\brief Interrupt the current procedure being executed by any object managed by this context.
This is a soft interruption: there is no guarantee the object will actualy stop.
This is a soft interruption: there is no guarantee the object will actually stop.
*/
void interrupt() { Z3_interrupt(m_ctx); }
@ -267,6 +259,15 @@ namespace z3 {
and in \c ts the predicates for testing if terms of the enumeration sort correspond to an enumeration.
*/
sort enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts);
/**
\brief Return a tuple constructor.
\c name is the name of the returned constructor,
\c n are the number of arguments, \c names and \c sorts are their projected sorts.
\c projs is an output paramter. It contains the set of projection functions.
*/
func_decl tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs);
/**
\brief create an uninterpreted sort with the name given by the string or symbol.
*/
@ -294,21 +295,21 @@ namespace z3 {
expr int_val(int n);
expr int_val(unsigned n);
expr int_val(__int64 n);
expr int_val(__uint64 n);
expr int_val(int64_t n);
expr int_val(uint64_t n);
expr int_val(char const * n);
expr real_val(int n, int d);
expr real_val(int n);
expr real_val(unsigned n);
expr real_val(__int64 n);
expr real_val(__uint64 n);
expr real_val(int64_t n);
expr real_val(uint64_t n);
expr real_val(char const * n);
expr bv_val(int n, unsigned sz);
expr bv_val(unsigned n, unsigned sz);
expr bv_val(__int64 n, unsigned sz);
expr bv_val(__uint64 n, unsigned sz);
expr bv_val(int64_t n, unsigned sz);
expr bv_val(uint64_t n, unsigned sz);
expr bv_val(char const * n, unsigned sz);
expr bv_val(unsigned n, bool const* bits);
@ -320,17 +321,12 @@ namespace z3 {
/**
\brief parsing
*/
expr parse_string(char const* s);
expr parse_file(char const* file);
expr_vector parse_string(char const* s);
expr_vector parse_file(char const* file);
expr parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
expr parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
expr_vector parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
expr_vector parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls);
/**
\brief Interpolation support
*/
check_result compute_interpolant(expr const& pat, params const& p, expr_vector& interp, model& m);
expr_vector get_interpolant(expr const& proof, expr const& pat, params const& p);
};
@ -431,6 +427,7 @@ namespace z3 {
void set(char const * k, unsigned n) { Z3_params_set_uint(ctx(), m_params, ctx().str_symbol(k), n); }
void set(char const * k, double n) { Z3_params_set_double(ctx(), m_params, ctx().str_symbol(k), n); }
void set(char const * k, symbol const & s) { Z3_params_set_symbol(ctx(), m_params, ctx().str_symbol(k), s); }
void set(char const * k, char const* s) { Z3_params_set_symbol(ctx(), m_params, ctx().str_symbol(k), ctx().str_symbol(s)); }
friend std::ostream & operator<<(std::ostream & out, params const & p);
};
@ -660,8 +657,8 @@ namespace z3 {
small integers, 64 bit integers or rational or decimal strings.
*/
bool is_numeral() const { return kind() == Z3_NUMERAL_AST; }
bool is_numeral_i64(__int64& i) const { bool r = 0 != Z3_get_numeral_int64(ctx(), m_ast, &i); check_error(); return r;}
bool is_numeral_u64(__uint64& i) const { bool r = 0 != Z3_get_numeral_uint64(ctx(), m_ast, &i); check_error(); return r;}
bool is_numeral_i64(int64_t& i) const { bool r = 0 != Z3_get_numeral_int64(ctx(), m_ast, &i); check_error(); return r;}
bool is_numeral_u64(uint64_t& i) const { bool r = 0 != Z3_get_numeral_uint64(ctx(), m_ast, &i); check_error(); return r;}
bool is_numeral_i(int& i) const { bool r = 0 != Z3_get_numeral_int(ctx(), m_ast, &i); check_error(); return r;}
bool is_numeral_u(unsigned& i) const { bool r = 0 != Z3_get_numeral_uint(ctx(), m_ast, &i); check_error(); return r;}
bool is_numeral(std::string& s) const { if (!is_numeral()) return false; s = Z3_get_numeral_string(ctx(), m_ast); check_error(); return true; }
@ -709,7 +706,7 @@ namespace z3 {
It only makes sense to use this function if the caller can ensure that
the result is an integer or if exceptions are enabled.
If exceptions are disabled, then use the the is_numeral_i function.
If exceptions are disabled, then use the is_numeral_i function.
\pre is_numeral()
*/
@ -729,7 +726,7 @@ namespace z3 {
It only makes sense to use this function if the caller can ensure that
the result is an integer or if exceptions are enabled.
If exceptions are disabled, then use the the is_numeral_u function.
If exceptions are disabled, then use the is_numeral_u function.
\pre is_numeral()
*/
unsigned get_numeral_uint() const {
@ -744,35 +741,35 @@ namespace z3 {
}
/**
\brief Return __int64 value of numeral, throw if result cannot fit in
__int64
\brief Return \c int64_t value of numeral, throw if result cannot fit in
\c int64_t.
\pre is_numeral()
*/
__int64 get_numeral_int64() const {
int64_t get_numeral_int64() const {
assert(is_numeral());
__int64 result = 0;
int64_t result = 0;
if (!is_numeral_i64(result)) {
assert(ctx().enable_exceptions());
if (!ctx().enable_exceptions()) return 0;
Z3_THROW(exception("numeral does not fit in machine __int64"));
Z3_THROW(exception("numeral does not fit in machine int64_t"));
}
return result;
}
/**
\brief Return __uint64 value of numeral, throw if result cannot fit in
__uint64
\brief Return \c uint64_t value of numeral, throw if result cannot fit in
\c uint64_t.
\pre is_numeral()
*/
__uint64 get_numeral_uint64() const {
uint64_t get_numeral_uint64() const {
assert(is_numeral());
__uint64 result = 0;
uint64_t result = 0;
if (!is_numeral_u64(result)) {
assert(ctx().enable_exceptions());
if (!ctx().enable_exceptions()) return 0;
Z3_THROW(exception("numeral does not fit in machine __uint64"));
Z3_THROW(exception("numeral does not fit in machine uint64_t"));
}
return result;
}
@ -835,7 +832,6 @@ namespace z3 {
*/
friend expr operator!(expr const & a);
/**
\brief Return an expression representing <tt>a and b</tt>.
@ -892,6 +888,16 @@ namespace z3 {
friend expr ite(expr const & c, expr const & t, expr const & e);
bool is_true() const { return is_app() && Z3_OP_TRUE == decl().decl_kind(); }
bool is_false() const { return is_app() && Z3_OP_FALSE == decl().decl_kind(); }
bool is_not() const { return is_app() && Z3_OP_NOT == decl().decl_kind(); }
bool is_and() const { return is_app() && Z3_OP_AND == decl().decl_kind(); }
bool is_or() const { return is_app() && Z3_OP_OR == decl().decl_kind(); }
bool is_xor() const { return is_app() && Z3_OP_XOR == decl().decl_kind(); }
bool is_implies() const { return is_app() && Z3_OP_IMPLIES == decl().decl_kind(); }
bool is_eq() const { return is_app() && Z3_OP_EQ == decl().decl_kind(); }
bool is_ite() const { return is_app() && Z3_OP_ITE == decl().decl_kind(); }
friend expr distinct(expr_vector const& args);
friend expr concat(expr const& a, expr const& b);
friend expr concat(expr_vector const& args);
@ -989,7 +995,7 @@ namespace z3 {
/**
\brief sequence and regular expression operations.
+ is overloaeded as sequence concatenation and regular expression union.
+ is overloaded as sequence concatenation and regular expression union.
concat is overloaded to handle sequences and regular expressions
*/
expr extract(expr const& offset, expr const& length) const {
@ -1809,9 +1815,11 @@ namespace z3 {
Z3_model_inc_ref(ctx(), m);
}
public:
struct translate {};
model(context & c):object(c) { init(Z3_mk_model(c)); }
model(context & c, Z3_model m):object(c) { init(m); }
model(model const & s):object(s) { init(s.m_model); }
model(model& src, context& dst, translate) : object(dst) { init(Z3_model_translate(src.ctx(), src, dst)); }
~model() { Z3_model_dec_ref(ctx(), m_model); }
operator Z3_model() const { return m_model; }
model & operator=(model const & s) {
@ -1904,7 +1912,7 @@ namespace z3 {
bool is_uint(unsigned i) const { Z3_bool r = Z3_stats_is_uint(ctx(), m_stats, i); check_error(); return r != 0; }
bool is_double(unsigned i) const { Z3_bool r = Z3_stats_is_double(ctx(), m_stats, i); check_error(); return r != 0; }
unsigned uint_value(unsigned i) const { unsigned r = Z3_stats_get_uint_value(ctx(), m_stats, i); check_error(); return r; }
double double_value(unsigned i) const { double r = Z3_stats_get_double_value(ctx(), m_stats, i); check_error(); return r; }
double double_value(unsigned i) const { double r = Z3_stats_get_double_value(ctx(), m_stats, i); check_error(); return r; }
friend std::ostream & operator<<(std::ostream & out, stats const & s);
};
inline std::ostream & operator<<(std::ostream & out, stats const & s) { out << Z3_stats_to_string(s.ctx(), s); return out; }
@ -2022,6 +2030,97 @@ namespace z3 {
param_descrs get_param_descrs() { return param_descrs(ctx(), Z3_solver_get_param_descrs(ctx(), m_solver)); }
expr_vector cube(expr_vector& vars, unsigned cutoff) {
Z3_ast_vector r = Z3_solver_cube(ctx(), m_solver, vars, cutoff);
check_error();
return expr_vector(ctx(), r);
}
class cube_iterator {
solver& m_solver;
unsigned& m_cutoff;
expr_vector& m_vars;
expr_vector m_cube;
bool m_end;
bool m_empty;
void inc() {
assert(!m_end && !m_empty);
m_cube = m_solver.cube(m_vars, m_cutoff);
m_cutoff = 0xFFFFFFFF;
if (m_cube.size() == 1 && m_cube[0].is_false()) {
m_cube = z3::expr_vector(m_solver.ctx());
m_end = true;
}
else if (m_cube.empty()) {
m_empty = true;
}
}
public:
cube_iterator(solver& s, expr_vector& vars, unsigned& cutoff, bool end):
m_solver(s),
m_cutoff(cutoff),
m_vars(vars),
m_cube(s.ctx()),
m_end(end),
m_empty(false) {
if (!m_end) {
inc();
}
}
cube_iterator& operator++() {
assert(!m_end);
if (m_empty) {
m_end = true;
}
else {
inc();
}
return *this;
}
cube_iterator operator++(int) { assert(false); return *this; }
expr_vector const * operator->() const { return &(operator*()); }
expr_vector const& operator*() const { return m_cube; }
bool operator==(cube_iterator const& other) {
return other.m_end == m_end;
};
bool operator!=(cube_iterator const& other) {
return other.m_end != m_end;
};
};
class cube_generator {
solver& m_solver;
unsigned m_cutoff;
expr_vector m_default_vars;
expr_vector& m_vars;
public:
cube_generator(solver& s):
m_solver(s),
m_cutoff(0xFFFFFFFF),
m_default_vars(s.ctx()),
m_vars(m_default_vars)
{}
cube_generator(solver& s, expr_vector& vars):
m_solver(s),
m_cutoff(0xFFFFFFFF),
m_default_vars(s.ctx()),
m_vars(vars)
{}
cube_iterator begin() { return cube_iterator(m_solver, m_vars, m_cutoff, false); }
cube_iterator end() { return cube_iterator(m_solver, m_vars, m_cutoff, true); }
void set_cutoff(unsigned c) { m_cutoff = c; }
};
cube_generator cubes() { return cube_generator(*this); }
cube_generator cubes(expr_vector& vars) { return cube_generator(*this, vars); }
};
inline std::ostream & operator<<(std::ostream & out, solver const & s) { out << Z3_solver_to_string(s.ctx(), s); return out; }
@ -2045,7 +2144,6 @@ namespace z3 {
return *this;
}
void add(expr const & f) { check_context(*this, f); Z3_goal_assert(ctx(), m_goal, f); check_error(); }
// fails for some compilers:
// void add(expr_vector const& v) { check_context(*this, v); for (expr e : v) add(e); }
unsigned size() const { return Z3_goal_size(ctx(), m_goal); }
expr operator[](int i) const { assert(0 <= i); Z3_ast r = Z3_goal_formula(ctx(), m_goal, i); check_error(); return expr(ctx(), r); }
@ -2056,6 +2154,17 @@ namespace z3 {
unsigned num_exprs() const { return Z3_goal_num_exprs(ctx(), m_goal); }
bool is_decided_sat() const { return Z3_goal_is_decided_sat(ctx(), m_goal) != 0; }
bool is_decided_unsat() const { return Z3_goal_is_decided_unsat(ctx(), m_goal) != 0; }
model convert_model(model const & m) const {
check_context(*this, m);
Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, m);
check_error();
return model(ctx(), new_m);
}
model get_model() const {
Z3_model new_m = Z3_goal_convert_model(ctx(), m_goal, 0);
check_error();
return model(ctx(), new_m);
}
expr as_expr() const {
unsigned n = size();
if (n == 0)
@ -2069,6 +2178,7 @@ namespace z3 {
return expr(ctx(), Z3_mk_and(ctx(), n, args.ptr()));
}
}
std::string dimacs() const { return std::string(Z3_goal_to_dimacs_string(ctx(), m_goal)); }
friend std::ostream & operator<<(std::ostream & out, goal const & g);
};
inline std::ostream & operator<<(std::ostream & out, goal const & g) { out << Z3_goal_to_string(g.ctx(), g); return out; }
@ -2093,12 +2203,6 @@ namespace z3 {
}
unsigned size() const { return Z3_apply_result_get_num_subgoals(ctx(), m_apply_result); }
goal operator[](int i) const { assert(0 <= i); Z3_goal r = Z3_apply_result_get_subgoal(ctx(), m_apply_result, i); check_error(); return goal(ctx(), r); }
model convert_model(model const & m, unsigned i = 0) const {
check_context(*this, m);
Z3_model new_m = Z3_apply_result_convert_model(ctx(), m_apply_result, i, m);
check_error();
return model(ctx(), new_m);
}
friend std::ostream & operator<<(std::ostream & out, apply_result const & r);
};
inline std::ostream & operator<<(std::ostream & out, apply_result const & r) { out << Z3_apply_result_to_string(r.ctx(), r); return out; }
@ -2268,6 +2372,7 @@ namespace z3 {
class optimize : public object {
Z3_optimize m_opt;
public:
class handle {
unsigned m_h;
@ -2276,6 +2381,17 @@ namespace z3 {
unsigned h() const { return m_h; }
};
optimize(context& c):object(c) { m_opt = Z3_mk_optimize(c); Z3_optimize_inc_ref(c, m_opt); }
optimize(optimize& o):object(o) {
Z3_optimize_inc_ref(o.ctx(), o.m_opt);
m_opt = o.m_opt;
}
optimize& operator=(optimize const& o) {
Z3_optimize_inc_ref(o.ctx(), o.m_opt);
Z3_optimize_dec_ref(ctx(), m_opt);
m_opt = o.m_opt;
m_ctx = o.m_ctx;
return *this;
}
~optimize() { Z3_optimize_dec_ref(ctx(), m_opt); }
operator Z3_optimize() const { return m_opt; }
void add(expr const& e) {
@ -2417,6 +2533,19 @@ namespace z3 {
for (unsigned i = 0; i < n; i++) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
return s;
}
inline func_decl context::tuple_sort(char const * name, unsigned n, char const * const * names, sort const* sorts, func_decl_vector & projs) {
array<Z3_symbol> _names(n);
array<Z3_sort> _sorts(n);
for (unsigned i = 0; i < n; i++) { _names[i] = Z3_mk_string_symbol(*this, names[i]); _sorts[i] = sorts[i]; }
array<Z3_func_decl> _projs(n);
Z3_symbol _name = Z3_mk_string_symbol(*this, name);
Z3_func_decl tuple;
sort _ignore_s = to_sort(*this, Z3_mk_tuple_sort(*this, _name, n, _names.ptr(), _sorts.ptr(), &tuple, _projs.ptr()));
check_error();
for (unsigned i = 0; i < n; i++) { projs.push_back(func_decl(*this, _projs[i])); }
return func_decl(*this, tuple);
}
inline sort context::uninterpreted_sort(char const* name) {
Z3_symbol _name = Z3_mk_string_symbol(*this, name);
return to_sort(*this, Z3_mk_uninterpreted_sort(*this, _name));
@ -2511,22 +2640,22 @@ namespace z3 {
inline expr context::int_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::int_val(unsigned n) { Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::int_val(__int64 n) { Z3_ast r = Z3_mk_int64(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::int_val(__uint64 n) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::int_val(int64_t n) { Z3_ast r = Z3_mk_int64(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::int_val(uint64_t n) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::int_val(char const * n) { Z3_ast r = Z3_mk_numeral(m_ctx, n, int_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(int n, int d) { Z3_ast r = Z3_mk_real(m_ctx, n, d); check_error(); return expr(*this, r); }
inline expr context::real_val(int n) { Z3_ast r = Z3_mk_int(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(unsigned n) { Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(__int64 n) { Z3_ast r = Z3_mk_int64(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(__uint64 n) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(int64_t n) { Z3_ast r = Z3_mk_int64(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(uint64_t n) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::real_val(char const * n) { Z3_ast r = Z3_mk_numeral(m_ctx, n, real_sort()); check_error(); return expr(*this, r); }
inline expr context::bv_val(int n, unsigned sz) { Z3_ast r = Z3_mk_int(m_ctx, n, bv_sort(sz)); check_error(); return expr(*this, r); }
inline expr context::bv_val(unsigned n, unsigned sz) { Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, bv_sort(sz)); check_error(); return expr(*this, r); }
inline expr context::bv_val(__int64 n, unsigned sz) { Z3_ast r = Z3_mk_int64(m_ctx, n, bv_sort(sz)); check_error(); return expr(*this, r); }
inline expr context::bv_val(__uint64 n, unsigned sz) { Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, bv_sort(sz)); check_error(); return expr(*this, r); }
inline expr context::bv_val(char const * n, unsigned sz) { Z3_ast r = Z3_mk_numeral(m_ctx, n, bv_sort(sz)); check_error(); return expr(*this, r); }
inline expr context::bv_val(int n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_int(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::bv_val(unsigned n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_unsigned_int(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::bv_val(int64_t n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_int64(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::bv_val(uint64_t n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_unsigned_int64(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::bv_val(char const * n, unsigned sz) { sort s = bv_sort(sz); Z3_ast r = Z3_mk_numeral(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::bv_val(unsigned n, bool const* bits) {
array<Z3_bool> _bits(n);
for (unsigned i = 0; i < n; ++i) _bits[i] = bits[i] ? 1 : 0;
@ -2643,6 +2772,12 @@ namespace z3 {
inline func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & d5, sort const & range) {
return range.ctx().function(name, d1, d2, d3, d4, d5, range);
}
inline func_decl function(char const* name, sort_vector const& domain, sort const& range) {
return range.ctx().function(name, domain, range);
}
inline func_decl function(std::string const& name, sort_vector const& domain, sort const& range) {
return range.ctx().function(name.c_str(), domain, range);
}
inline expr select(expr const & a, expr const & i) {
check_context(a, i);
@ -2821,22 +2956,19 @@ namespace z3 {
inline expr interpolant(expr const& a) {
return expr(a.ctx(), Z3_mk_interpolant(a.ctx(), a));
inline expr_vector context::parse_string(char const* s) {
Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, 0, 0, 0, 0, 0, 0);
check_error();
return expr_vector(*this, r);
}
inline expr_vector context::parse_file(char const* s) {
Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, 0, 0, 0, 0, 0, 0);
check_error();
return expr_vector(*this, r);
}
inline expr context::parse_string(char const* s) {
Z3_ast r = Z3_parse_smtlib2_string(*this, s, 0, 0, 0, 0, 0, 0);
check_parser_error();
return expr(*this, r);
}
inline expr context::parse_file(char const* s) {
Z3_ast r = Z3_parse_smtlib2_file(*this, s, 0, 0, 0, 0, 0, 0);
check_parser_error();
return expr(*this, r);
}
inline expr context::parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
inline expr_vector context::parse_string(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
array<Z3_symbol> sort_names(sorts.size());
array<Z3_symbol> decl_names(decls.size());
array<Z3_sort> sorts1(sorts);
@ -2847,12 +2979,13 @@ namespace z3 {
for (unsigned i = 0; i < decls.size(); ++i) {
decl_names[i] = decls[i].name();
}
Z3_ast r = Z3_parse_smtlib2_string(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
check_parser_error();
return expr(*this, r);
Z3_ast_vector r = Z3_parse_smtlib2_string(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
check_error();
return expr_vector(*this, r);
}
inline expr context::parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
inline expr_vector context::parse_file(char const* s, sort_vector const& sorts, func_decl_vector const& decls) {
array<Z3_symbol> sort_names(sorts.size());
array<Z3_symbol> decl_names(decls.size());
array<Z3_sort> sorts1(sorts);
@ -2863,33 +2996,12 @@ namespace z3 {
for (unsigned i = 0; i < decls.size(); ++i) {
decl_names[i] = decls[i].name();
}
Z3_ast r = Z3_parse_smtlib2_file(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
check_parser_error();
return expr(*this, r);
Z3_ast_vector r = Z3_parse_smtlib2_file(*this, s, sorts.size(), sort_names.ptr(), sorts1.ptr(), decls.size(), decl_names.ptr(), decls1.ptr());
check_error();
return expr_vector(*this, r);
}
inline check_result context::compute_interpolant(expr const& pat, params const& p, expr_vector& i, model& m) {
Z3_ast_vector interp = 0;
Z3_model mdl = 0;
Z3_lbool r = Z3_compute_interpolant(*this, pat, p, &interp, &mdl);
switch (r) {
case Z3_L_FALSE:
i = expr_vector(*this, interp);
break;
case Z3_L_TRUE:
m = model(*this, mdl);
break;
case Z3_L_UNDEF:
break;
}
return to_check_result(r);
}
inline expr_vector context::get_interpolant(expr const& proof, expr const& pat, params const& p) {
return expr_vector(*this, Z3_get_interpolant(*this, proof, pat, p));
}
inline expr expr::substitute(expr_vector const& src, expr_vector const& dst) {
assert(src.size() == dst.size());
array<Z3_ast> _src(src.size());

View file

@ -3,11 +3,11 @@ Copyright (c) 2012 Microsoft Corporation
Module Name:
IntNum.cs
AlgebraicNum.cs
Abstract:
Z3 Managed API: Int Numerals
Z3 Managed API: Algebraic Numerals
Author:

View file

@ -55,19 +55,6 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Convert a model for the subgoal <paramref name="i"/> into a model for the original
/// goal <c>g</c>, that the ApplyResult was obtained from.
/// </summary>
/// <returns>A model for <c>g</c></returns>
public Model ConvertModel(uint i, Model m)
{
Contract.Requires(m != null);
Contract.Ensures(Contract.Result<Model>() != null);
return new Model(Context, Native.Z3_apply_result_convert_model(Context.nCtx, NativeObject, i, m.NativeObject));
}
/// <summary>
/// A string representation of the ApplyResult.
/// </summary>

View file

@ -3,11 +3,11 @@ Copyright (c) 2012 Microsoft Corporation
Module Name:
IntNum.cs
BitVecNum.cs
Abstract:
Z3 Managed API: Int Numerals
Z3 Managed API: BitVec Numerals
Author:

View file

@ -80,7 +80,6 @@ set(Z3_DOTNET_ASSEMBLY_SOURCES_IN_SRC_TREE
Global.cs
Goal.cs
IDecRefQueue.cs
InterpolationContext.cs
IntExpr.cs
IntNum.cs
IntSort.cs

View file

@ -2262,7 +2262,7 @@ namespace Microsoft.Z3
/// Maps f on the argument arrays.
/// </summary>
/// <remarks>
/// Eeach element of <c>args</c> must be of an array sort <c>[domain_i -> range_i]</c>.
/// Each element of <c>args</c> must be of an array sort <c>[domain_i -> range_i]</c>.
/// The function declaration <c>f</c> must have type <c> range_1 .. range_n -> range</c>.
/// <c>v</c> must have sort range. The sort of the result is <c>[domain_i -> range]</c>.
/// <seealso cref="MkArraySort(Sort, Sort)"/>
@ -2515,7 +2515,7 @@ namespace Microsoft.Z3
/// <summary>
/// Concatentate sequences.
/// Concatenate sequences.
/// </summary>
public SeqExpr MkConcat(params SeqExpr[] t)
{
@ -2862,7 +2862,7 @@ namespace Microsoft.Z3
}
/// <summary>
/// Create a Term of a given sort. This function can be use to create numerals that fit in a machine integer.
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than <c>MakeNumeral</c> since it is not necessary to parse a string.
/// </summary>
/// <param name="v">Value of the numeral</param>
@ -2878,7 +2878,7 @@ namespace Microsoft.Z3
}
/// <summary>
/// Create a Term of a given sort. This function can be use to create numerals that fit in a machine integer.
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than <c>MakeNumeral</c> since it is not necessary to parse a string.
/// </summary>
/// <param name="v">Value of the numeral</param>
@ -2894,7 +2894,7 @@ namespace Microsoft.Z3
}
/// <summary>
/// Create a Term of a given sort. This function can be use to create numerals that fit in a machine integer.
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than <c>MakeNumeral</c> since it is not necessary to parse a string.
/// </summary>
/// <param name="v">Value of the numeral</param>
@ -2910,7 +2910,7 @@ namespace Microsoft.Z3
}
/// <summary>
/// Create a Term of a given sort. This function can be use to create numerals that fit in a machine integer.
/// Create a Term of a given sort. This function can be used to create numerals that fit in a machine integer.
/// It is slightly faster than <c>MakeNumeral</c> since it is not necessary to parse a string.
/// </summary>
/// <param name="v">Value of the numeral</param>
@ -3211,7 +3211,7 @@ namespace Microsoft.Z3
/// Create an existential Quantifier.
/// </summary>
/// <remarks>
/// Creates an existential quantifier using de-Brujin indexed variables.
/// Creates an existential quantifier using de-Bruijn indexed variables.
/// (<see cref="MkForall(Sort[], Symbol[], Expr, uint, Pattern[], Expr[], Symbol, Symbol)"/>).
/// </remarks>
public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null)
@ -3325,7 +3325,7 @@ namespace Microsoft.Z3
/// Parse the given string using the SMT-LIB2 parser.
/// </summary>
/// <returns>A conjunction of assertions in the scope (up to push/pop) at the end of the string.</returns>
public BoolExpr ParseSMTLIB2String(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, FuncDecl[] decls = null)
public BoolExpr[] ParseSMTLIB2String(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, FuncDecl[] decls = null)
{
Contract.Ensures(Contract.Result<BoolExpr>() != null);
@ -3335,16 +3335,17 @@ namespace Microsoft.Z3
uint cd = AST.ArrayLength(decls);
if (csn != cs || cdn != cd)
throw new Z3Exception("Argument size mismatch");
return (BoolExpr)Expr.Create(this, Native.Z3_parse_smtlib2_string(nCtx, str,
ASTVector assertions = new ASTVector(this, Native.Z3_parse_smtlib2_string(nCtx, str,
AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts),
AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)));
return assertions.ToBoolExprArray();
}
/// <summary>
/// Parse the given file using the SMT-LIB2 parser.
/// </summary>
/// <seealso cref="ParseSMTLIB2String"/>
public BoolExpr ParseSMTLIB2File(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, FuncDecl[] decls = null)
public BoolExpr[] ParseSMTLIB2File(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, FuncDecl[] decls = null)
{
Contract.Ensures(Contract.Result<BoolExpr>() != null);
@ -3354,9 +3355,10 @@ namespace Microsoft.Z3
uint cd = AST.ArrayLength(decls);
if (csn != cs || cdn != cd)
throw new Z3Exception("Argument size mismatch");
return (BoolExpr)Expr.Create(this, Native.Z3_parse_smtlib2_file(nCtx, fileName,
ASTVector assertions = new ASTVector(this, Native.Z3_parse_smtlib2_file(nCtx, fileName,
AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts),
AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)));
return assertions.ToBoolExprArray();
}
#endregion
@ -3597,7 +3599,7 @@ namespace Microsoft.Z3
}
/// <summary>
/// Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty)
/// Create a tactic that fails if the goal is not trivially satisfiable (i.e., empty)
/// or trivially unsatisfiable (i.e., contains `false').
/// </summary>
public Tactic FailIfNotDecided()
@ -4656,7 +4658,7 @@ namespace Microsoft.Z3
/// Conversion of a floating-point term into a bit-vector.
/// </summary>
/// <remarks>
/// Produces a term that represents the conversion of the floating-poiunt term t into a
/// Produces a term that represents the conversion of the floating-point term t into a
/// bit-vector term of size sz in 2's complement format (signed when signed==true). If necessary,
/// the result will be rounded according to rounding mode rm.
/// </remarks>
@ -4677,7 +4679,7 @@ namespace Microsoft.Z3
/// Conversion of a floating-point term into a real-numbered term.
/// </summary>
/// <remarks>
/// Produces a term that represents the conversion of the floating-poiunt term t into a
/// Produces a term that represents the conversion of the floating-point term t into a
/// real number. Note that this type of conversion will often result in non-linear
/// constraints over real terms.
/// </remarks>
@ -4696,7 +4698,7 @@ namespace Microsoft.Z3
/// <remarks>
/// The size of the resulting bit-vector is automatically determined. Note that
/// IEEE 754-2008 allows multiple different representations of NaN. This conversion
/// knows only one NaN and it will always produce the same bit-vector represenatation of
/// knows only one NaN and it will always produce the same bit-vector representation of
/// that NaN.
/// </remarks>
/// <param name="t">FloatingPoint term.</param>

View file

@ -317,14 +317,6 @@ namespace Microsoft.Z3
#endregion
#region Interpolation
/// <summary>
/// Indicates whether the term is marked for interpolation.
/// </summary>
/// <remarks></remarks>
public bool IsInterpolant { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_INTERP; } }
#endregion
#region Arithmetic Terms
/// <summary>
/// Indicates whether the term is of integer sort.
@ -932,7 +924,7 @@ namespace Microsoft.Z3
/// Indicates whether the term is a proof by condensed transitivity of a relation
/// </summary>
/// <remarks>
/// Condensed transitivity proof. This proof object is only used if the parameter PROOF_MODE is 1.
/// Condensed transitivity proof.
/// It combines several symmetry and transitivity proofs.
/// Example:
/// T1: (R a b)
@ -959,7 +951,7 @@ namespace Microsoft.Z3
/// Tn: (R t_n s_n)
/// [monotonicity T1 ... Tn]: (R (f t_1 ... t_n) (f s_1 ... s_n))
/// Remark: if t_i == s_i, then the antecedent Ti is suppressed.
/// That is, reflexivity proofs are supressed to save space.
/// That is, reflexivity proofs are suppressed to save space.
/// </remarks>
public bool IsProofMonotonicity { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_MONOTONICITY; } }
@ -1002,7 +994,7 @@ namespace Microsoft.Z3
public bool IsProofAndElimination { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_AND_ELIM; } }
/// <summary>
/// Indicates whether the term is a proof by eliminiation of not-or
/// Indicates whether the term is a proof by elimination of not-or
/// </summary>
/// <remarks>
/// Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i).
@ -1035,14 +1027,11 @@ namespace Microsoft.Z3
/// </summary>
/// <remarks>
/// A proof for rewriting an expression t into an expression s.
/// This proof object is used if the parameter PROOF_MODE is 1.
/// This proof object can have n antecedents.
/// The antecedents are proofs for equalities used as substitution rules.
/// The object is also used in a few cases if the parameter PROOF_MODE is 2.
/// The cases are:
/// The object is used in a few cases:
/// - When applying contextual simplification (CONTEXT_SIMPLIFIER=true)
/// - When converting bit-vectors to Booleans (BIT2BOOL=true)
/// - When pulling ite expression up (PULL_CHEAP_ITE_TREES=true)
/// </remarks>
public bool IsProofRewriteStar { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_REWRITE_STAR; } }
@ -1054,15 +1043,6 @@ namespace Microsoft.Z3
/// </remarks>
public bool IsProofPullQuant { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_PULL_QUANT; } }
/// <summary>
/// Indicates whether the term is a proof for pulling quantifiers out.
/// </summary>
/// <remarks>
/// A proof for (iff P Q) where Q is in prenex normal form.
/// This proof object is only used if the parameter PROOF_MODE is 1.
/// This proof object has no antecedents
/// </remarks>
public bool IsProofPullQuantStar { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_PULL_QUANT_STAR; } }
/// <summary>
/// Indicates whether the term is a proof for pushing quantifiers in.
@ -1112,7 +1092,7 @@ namespace Microsoft.Z3
public bool IsProofQuantInst { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_QUANT_INST; } }
/// <summary>
/// Indicates whether the term is a hypthesis marker.
/// Indicates whether the term is a hypothesis marker.
/// </summary>
/// <remarks>Mark a hypothesis in a natural deduction style proof.</remarks>
public bool IsProofHypothesis { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_HYPOTHESIS; } }
@ -1304,28 +1284,6 @@ namespace Microsoft.Z3
/// </remarks>
public bool IsProofNNFNeg { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_NNF_NEG; } }
/// <summary>
/// Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form.
/// </summary>
/// <remarks>
/// A proof for (~ P Q) where Q is in negation normal form.
///
/// This proof object is only used if the parameter PROOF_MODE is 1.
///
/// This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO.
/// </remarks>
public bool IsProofNNFStar { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_NNF_STAR; } }
/// <summary>
/// Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form.
/// </summary>
/// <remarks>
/// A proof for (~ P Q) where Q is in conjunctive normal form.
/// This proof object is only used if the parameter PROOF_MODE is 1.
/// This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO.
/// </remarks>
public bool IsProofCNFStar { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_PR_CNF_STAR; } }
/// <summary>
/// Indicates whether the term is a proof for a Skolemization step
/// </summary>
@ -1433,7 +1391,7 @@ namespace Microsoft.Z3
/// <remarks>
/// Filter (restrict) a relation with respect to a predicate.
/// The first argument is a relation.
/// The second argument is a predicate with free de-Brujin indices
/// The second argument is a predicate with free de-Bruijn indices
/// corresponding to the columns of the relation.
/// So the first column in the relation has index 0.
/// </remarks>
@ -1649,7 +1607,7 @@ namespace Microsoft.Z3
public bool IsFPMul { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_MUL; } }
/// <summary>
/// Indicates whether the term is a floating-point divison term
/// Indicates whether the term is a floating-point division term
/// </summary>
public bool IsFPDiv { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_DIV; } }
@ -1709,7 +1667,7 @@ namespace Microsoft.Z3
public bool IsFPLe { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_LE; } }
/// <summary>
/// Indicates whether the term is a floating-point greater-than or erqual term
/// Indicates whether the term is a floating-point greater-than or equal term
/// </summary>
public bool IsFPGe { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_FPA_GE; } }
@ -1789,7 +1747,7 @@ namespace Microsoft.Z3
#region Bound Variables
/// <summary>
/// The de-Burijn index of a bound variable.
/// The de-Bruijn index of a bound variable.
/// </summary>
/// <remarks>
/// Bound variables are indexed by de-Bruijn indices. It is perhaps easiest to explain

View file

@ -174,6 +174,21 @@ namespace Microsoft.Z3
get { return Native.Z3_goal_is_decided_unsat(Context.nCtx, NativeObject) != 0; }
}
/// <summary>
/// Convert a model for the goal into a model of the
/// original goal from which this goal was derived.
/// </summary>
/// <returns>A model for <c>g</c></returns>
public Model ConvertModel(Model m)
{
Contract.Ensures(Contract.Result<Model>() != null);
if (m != null)
return new Model(Context, Native.Z3_goal_convert_model(Context.nCtx, NativeObject, m.NativeObject));
else
return new Model(Context, Native.Z3_goal_convert_model(Context.nCtx, NativeObject, IntPtr.Zero));
}
/// <summary>
/// Translates (copies) the Goal to the target Context <paramref name="ctx"/>.
/// </summary>
@ -208,6 +223,15 @@ namespace Microsoft.Z3
return Native.Z3_goal_to_string(Context.nCtx, NativeObject);
}
/// <summary>
/// Goal to DIMACS formatted string conversion.
/// </summary>
/// <returns>A string representation of the Goal.</returns>
public string ToDimacs()
{
return Native.Z3_goal_to_dimacs_string(Context.nCtx, NativeObject);
}
/// <summary>
/// Goal to BoolExpr conversion.
/// </summary>

View file

@ -1,164 +0,0 @@
/*++
Copyright (c) 2015 Microsoft Corporation
--*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
namespace Microsoft.Z3
{
/// <summary>
/// The InterpolationContext is suitable for generation of interpolants.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the C/C++ API, which is well documented.</remarks>
[ContractVerification(true)]
public class InterpolationContext : Context
{
/// <summary>
/// Constructor.
/// </summary>
public InterpolationContext() : base() { }
/// <summary>
/// Constructor.
/// </summary>
/// <remarks><seealso cref="Context"/></remarks>
public InterpolationContext(Dictionary<string, string> settings) : base(settings) { }
#region Terms
/// <summary>
/// Create an expression that marks a formula position for interpolation.
/// </summary>
public BoolExpr MkInterpolant(BoolExpr a)
{
Contract.Requires(a != null);
Contract.Ensures(Contract.Result<BoolExpr>() != null);
CheckContextMatch(a);
return new BoolExpr(this, Native.Z3_mk_interpolant(nCtx, a.NativeObject));
}
#endregion
/// <summary>
/// Computes an interpolant.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_get_interpolant in the C/C++ API, which is
/// well documented.</remarks>
public BoolExpr[] GetInterpolant(Expr pf, Expr pat, Params p)
{
Contract.Requires(pf != null);
Contract.Requires(pat != null);
Contract.Requires(p != null);
Contract.Ensures(Contract.Result<Expr>() != null);
CheckContextMatch(pf);
CheckContextMatch(pat);
CheckContextMatch(p);
ASTVector seq = new ASTVector(this, Native.Z3_get_interpolant(nCtx, pf.NativeObject, pat.NativeObject, p.NativeObject));
return seq.ToBoolExprArray();
}
/// <summary>
/// Computes an interpolant.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_compute_interpolant in the C/C++ API, which is
/// well documented.</remarks>
public Z3_lbool ComputeInterpolant(Expr pat, Params p, out BoolExpr[] interp, out Model model)
{
Contract.Requires(pat != null);
Contract.Requires(p != null);
Contract.Ensures(Contract.ValueAtReturn(out interp) != null);
Contract.Ensures(Contract.ValueAtReturn(out model) != null);
CheckContextMatch(pat);
CheckContextMatch(p);
IntPtr i = IntPtr.Zero, m = IntPtr.Zero;
int r = Native.Z3_compute_interpolant(nCtx, pat.NativeObject, p.NativeObject, ref i, ref m);
interp = new ASTVector(this, i).ToBoolExprArray();
model = new Model(this, m);
return (Z3_lbool)r;
}
/// <summary>
/// Return a string summarizing cumulative time used for interpolation.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_interpolation_profile in the C/C++ API, which is
/// well documented.</remarks>
public string InterpolationProfile()
{
return Native.Z3_interpolation_profile(nCtx);
}
/// <summary>
/// Checks the correctness of an interpolant.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_check_interpolant in the C/C++ API, which is
/// well documented.</remarks>
public int CheckInterpolant(Expr[] cnsts, uint[] parents, BoolExpr[] interps, out string error, Expr[] theory)
{
Contract.Requires(cnsts.Length == parents.Length);
Contract.Requires(cnsts.Length == interps.Length + 1);
IntPtr n_err_str;
int r = Native.Z3_check_interpolant(nCtx,
(uint)cnsts.Length,
Expr.ArrayToNative(cnsts),
parents,
Expr.ArrayToNative(interps),
out n_err_str,
(uint)theory.Length,
Expr.ArrayToNative(theory));
error = Marshal.PtrToStringAnsi(n_err_str);
return r;
}
/// <summary>
/// Reads an interpolation problem from a file.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_read_interpolation_problem in the C/C++ API, which is
/// well documented.</remarks>
public int ReadInterpolationProblem(string filename, out Expr[] cnsts, out uint[] parents, out string error, out Expr[] theory)
{
uint num = 0, num_theory = 0;
IntPtr[] n_cnsts;
IntPtr[] n_theory;
IntPtr n_err_str;
int r = Native.Z3_read_interpolation_problem(nCtx, ref num, out n_cnsts, out parents, filename, out n_err_str, ref num_theory, out n_theory);
error = Marshal.PtrToStringAnsi(n_err_str);
cnsts = new Expr[num];
parents = new uint[num];
theory = new Expr[num_theory];
for (int i = 0; i < num; i++)
cnsts[i] = Expr.Create(this, n_cnsts[i]);
for (int i = 0; i < num_theory; i++)
theory[i] = Expr.Create(this, n_theory[i]);
return r;
}
/// <summary>
/// Writes an interpolation problem to a file.
/// </summary>
/// <remarks>For more information on interpolation please refer
/// too the function Z3_write_interpolation_problem in the C/C++ API, which is
/// well documented.</remarks>
public void WriteInterpolationProblem(string filename, Expr[] cnsts, uint[] parents, Expr[] theory)
{
Contract.Requires(cnsts.Length == parents.Length);
Native.Z3_write_interpolation_problem(nCtx, (uint)cnsts.Length, Expr.ArrayToNative(cnsts), parents, filename, (uint)theory.Length, Expr.ArrayToNative(theory));
}
}
}

View file

@ -253,7 +253,7 @@ namespace Microsoft.Z3
/// The uninterpreted sorts that the model has an interpretation for.
/// </summary>
/// <remarks>
/// Z3 also provides an intepretation for uninterpreted sorts used in a formula.
/// Z3 also provides an interpretation for uninterpreted sorts used in a formula.
/// The interpretation for a sort is a finite set of distinct values. We say this finite set is
/// the "universe" of the sort.
/// </remarks>

View file

@ -91,7 +91,7 @@ namespace Microsoft.Z3
public Params Add(string name, bool value)
{
Native.Z3_params_set_bool(Context.nCtx, NativeObject, Context.MkSymbol(name).NativeObject, (value) ? 1 : 0);
return this;
return this;
}
/// <summary>
@ -100,7 +100,7 @@ namespace Microsoft.Z3
public Params Add(string name, uint value)
{
Native.Z3_params_set_uint(Context.nCtx, NativeObject, Context.MkSymbol(name).NativeObject, value);
return this;
return this;
}
/// <summary>

View file

@ -57,7 +57,7 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// <summary>
/// Sets parameter on the solver
/// </summary>
public void Set(string name, bool value) { Parameters = Context.MkParams().Add(name, value); }
@ -266,6 +266,20 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Currently inferred units.
/// </summary>
public BoolExpr[] Units
{
get
{
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector assertions = new ASTVector(Context, Native.Z3_solver_get_units(Context.nCtx, NativeObject));
return assertions.ToBoolExprArray();
}
}
/// <summary>
/// Checks whether the assertions in the solver are consistent or not.
/// </summary>
@ -331,10 +345,10 @@ namespace Microsoft.Z3
}
/// <summary>
/// The model of the last <c>Check</c>.
/// The model of the last <c>Check(params Expr[] assumptions)</c>.
/// </summary>
/// <remarks>
/// The result is <c>null</c> if <c>Check</c> was not invoked before,
/// The result is <c>null</c> if <c>Check(params Expr[] assumptions)</c> was not invoked before,
/// if its results was not <c>SATISFIABLE</c>, or if model production is not enabled.
/// </remarks>
public Model Model
@ -350,10 +364,10 @@ namespace Microsoft.Z3
}
/// <summary>
/// The proof of the last <c>Check</c>.
/// The proof of the last <c>Check(params Expr[] assumptions)</c>.
/// </summary>
/// <remarks>
/// The result is <c>null</c> if <c>Check</c> was not invoked before,
/// The result is <c>null</c> if <c>Check(params Expr[] assumptions)</c> was not invoked before,
/// if its results was not <c>UNSATISFIABLE</c>, or if proof production is disabled.
/// </remarks>
public Expr Proof
@ -400,6 +414,42 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Backtrack level that can be adjusted by conquer process
/// </summary>
public uint BacktrackLevel { get; set; }
/// <summary>
/// Variables available and returned by the cuber.
/// </summary>
public BoolExpr[] CubeVariables { get; set; }
/// <summary>
/// Return a set of cubes.
/// </summary>
public IEnumerable<BoolExpr[]> Cube()
{
ASTVector cv = new ASTVector(Context);
if (CubeVariables != null)
foreach (var b in CubeVariables) cv.Push(b);
while (true) {
var lvl = BacktrackLevel;
BacktrackLevel = uint.MaxValue;
ASTVector r = new ASTVector(Context, Native.Z3_solver_cube(Context.nCtx, NativeObject, cv.NativeObject, lvl));
var v = r.ToBoolExprArray();
CubeVariables = cv.ToBoolExprArray();
if (v.Length == 1 && v[0].IsFalse) {
break;
}
yield return v;
if (v.Length == 0) {
break;
}
}
}
/// <summary>
/// Create a clone of the current solver with respect to <c>ctx</c>.
/// </summary>
@ -410,6 +460,13 @@ namespace Microsoft.Z3
return new Solver(ctx, Native.Z3_solver_translate(Context.nCtx, NativeObject, ctx.nCtx));
}
/// <summary>
/// Import model converter from other solver.
/// </summary>
public void ImportModelConverter(Solver src)
{
Native.Z3_solver_import_model_converter(Context.nCtx, src.NativeObject, NativeObject);
}
/// <summary>
/// Solver statistics.
@ -437,6 +494,7 @@ namespace Microsoft.Z3
: base(ctx, obj)
{
Contract.Requires(ctx != null);
this.BacktrackLevel = uint.MaxValue;
}
internal class DecRefQueue : IDecRefQueue

View file

@ -56,7 +56,7 @@ namespace Microsoft.Z3
public bool IsDouble { get { return m_is_double; } }
/// <summary>
/// The string representation of the the entry's value.
/// The string representation of the entry's value.
/// </summary>
public string Value
{

View file

@ -46,19 +46,6 @@ public class ApplyResult extends Z3Object {
return res;
}
/**
* Convert a model for the subgoal {@code i} into a model for the
* original goal {@code g}, that the ApplyResult was obtained from.
*
* @return A model for {@code g}
* @throws Z3Exception
**/
public Model convertModel(int i, Model m)
{
return new Model(getContext(),
Native.applyResultConvertModel(getContext().nCtx(), getNativeObject(), i, m.getNativeObject()));
}
/**
* A string representation of the ApplyResult.
**/

View file

@ -137,7 +137,6 @@ set(Z3_JAVA_JAR_SOURCE_FILES
GoalDecRefQueue.java
Goal.java
IDecRefQueue.java
InterpolationContext.java
IntExpr.java
IntNum.java
IntSort.java

View file

@ -934,7 +934,7 @@ public class Context implements AutoCloseable {
* exposed. It follows the semantics prescribed by the SMT-LIB standard.
*
* You can take the floor of a real by creating an auxiliary integer Term
* {@code k} and and asserting
* {@code k} and asserting
* {@code MakeInt2Real(k) &lt;= t1 &lt; MkInt2Real(k)+1}. The argument
* must be of integer sort.
**/
@ -1978,7 +1978,7 @@ public class Context implements AutoCloseable {
}
/**
* Concatentate sequences.
* Concatenate sequences.
*/
public SeqExpr mkConcat(SeqExpr... t)
{
@ -2234,7 +2234,7 @@ public class Context implements AutoCloseable {
}
/**
* Create a Term of a given sort. This function can be use to create
* Create a Term of a given sort. This function can be used to create
* numerals that fit in a machine integer. It is slightly faster than
* {@code MakeNumeral} since it is not necessary to parse a string.
*
@ -2250,7 +2250,7 @@ public class Context implements AutoCloseable {
}
/**
* Create a Term of a given sort. This function can be use to create
* Create a Term of a given sort. This function can be used to create
* numerals that fit in a machine integer. It is slightly faster than
* {@code MakeNumeral} since it is not necessary to parse a string.
*
@ -2438,7 +2438,7 @@ public class Context implements AutoCloseable {
}
/**
* Creates an existential quantifier using de-Brujin indexed variables.
* Creates an existential quantifier using de-Bruijn indexed variables.
* @see #mkForall(Sort[],Symbol[],Expr,int,Pattern[],Expr[],Symbol,Symbol)
**/
public Quantifier mkExists(Sort[] sorts, Symbol[] names, Expr body,
@ -2543,14 +2543,16 @@ public class Context implements AutoCloseable {
/**
* Parse the given string using the SMT-LIB2 parser.
*
* @return A conjunction of assertions in the scope (up to push/pop) at the
* end of the string.
* @return A conjunction of assertions.
*
* If the string contains push/pop commands, the
* set of assertions returned are the ones in the
* last scope level.
**/
public BoolExpr parseSMTLIB2String(String str, Symbol[] sortNames,
public BoolExpr[] parseSMTLIB2String(String str, Symbol[] sortNames,
Sort[] sorts, Symbol[] declNames, FuncDecl[] decls)
{
int csn = Symbol.arrayLength(sortNames);
int cs = Sort.arrayLength(sorts);
int cdn = Symbol.arrayLength(declNames);
@ -2558,17 +2560,18 @@ public class Context implements AutoCloseable {
if (csn != cs || cdn != cd) {
throw new Z3Exception("Argument size mismatch");
}
return (BoolExpr) Expr.create(this, Native.parseSmtlib2String(nCtx(),
ASTVector v = new ASTVector(this, Native.parseSmtlib2String(nCtx(),
str, AST.arrayLength(sorts), Symbol.arrayToNative(sortNames),
AST.arrayToNative(sorts), AST.arrayLength(decls),
Symbol.arrayToNative(declNames), AST.arrayToNative(decls)));
return v.ToBoolExprArray();
}
/**
* Parse the given file using the SMT-LIB2 parser.
* @see #parseSMTLIB2String
**/
public BoolExpr parseSMTLIB2File(String fileName, Symbol[] sortNames,
public BoolExpr[] parseSMTLIB2File(String fileName, Symbol[] sortNames,
Sort[] sorts, Symbol[] declNames, FuncDecl[] decls)
{
@ -2578,11 +2581,12 @@ public class Context implements AutoCloseable {
int cd = AST.arrayLength(decls);
if (csn != cs || cdn != cd)
throw new Z3Exception("Argument size mismatch");
return (BoolExpr) Expr.create(this, Native.parseSmtlib2File(nCtx(),
ASTVector v = new ASTVector(this, Native.parseSmtlib2File(nCtx(),
fileName, AST.arrayLength(sorts),
Symbol.arrayToNative(sortNames), AST.arrayToNative(sorts),
AST.arrayLength(decls), Symbol.arrayToNative(declNames),
AST.arrayToNative(decls)));
return v.ToBoolExprArray();
}
/**
@ -2781,7 +2785,7 @@ public class Context implements AutoCloseable {
}
/**
* Create a tactic that fails if the goal is not triviall satisfiable (i.e.,
* Create a tactic that fails if the goal is not trivially satisfiable (i.e.,
* empty) or trivially unsatisfiable (i.e., contains `false').
**/
public Tactic failIfNotDecided()
@ -3769,7 +3773,7 @@ public class Context implements AutoCloseable {
* @param sz Size of the resulting bit-vector.
* @param signed Indicates whether the result is a signed or unsigned bit-vector.
* Remarks:
* Produces a term that represents the conversion of the floating-poiunt term t into a
* Produces a term that represents the conversion of the floating-point term t into a
* bit-vector term of size sz in 2's complement format (signed when signed==true). If necessary,
* the result will be rounded according to rounding mode rm.
* @throws Z3Exception
@ -3786,7 +3790,7 @@ public class Context implements AutoCloseable {
* Conversion of a floating-point term into a real-numbered term.
* @param t FloatingPoint term
* Remarks:
* Produces a term that represents the conversion of the floating-poiunt term t into a
* Produces a term that represents the conversion of the floating-point term t into a
* real number. Note that this type of conversion will often result in non-linear
* constraints over real terms.
* @throws Z3Exception
@ -3802,7 +3806,7 @@ public class Context implements AutoCloseable {
* Remarks:
* The size of the resulting bit-vector is automatically determined. Note that
* IEEE 754-2008 allows multiple different representations of NaN. This conversion
* knows only one NaN and it will always produce the same bit-vector represenatation of
* knows only one NaN and it will always produce the same bit-vector representation of
* that NaN.
* @throws Z3Exception
**/

View file

@ -1398,8 +1398,7 @@ public class Expr extends AST
/**
* Indicates whether the term is a proof by condensed transitivity of a
* relation
* Remarks: Condensed transitivity proof. This proof object is
* only used if the parameter PROOF_MODE is 1. It combines several symmetry
* Remarks: Condensed transitivity proof. It combines several symmetry
* and transitivity proofs. Example: T1: (R a b) T2: (R c b) T3: (R c d)
* [trans* T1 T2 T3]: (R a d) R must be a symmetric and transitive relation.
*
@ -1421,7 +1420,7 @@ public class Expr extends AST
* Remarks: T1:
* (R t_1 s_1) ... Tn: (R t_n s_n) [monotonicity T1 ... Tn]: (R (f t_1 ...
* t_n) (f s_1 ... s_n)) Remark: if t_i == s_i, then the antecedent Ti is
* suppressed. That is, reflexivity proofs are supressed to save space.
* suppressed. That is, reflexivity proofs are suppressed to save space.
*
* @throws Z3Exception on error
* @return a boolean
@ -1473,7 +1472,7 @@ public class Expr extends AST
}
/**
* Indicates whether the term is a proof by eliminiation of not-or
* Indicates whether the term is a proof by elimination of not-or
* Remarks: * Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i). * T1: (not (or l_1 ... l_n)) [not-or-elim T1]: (not l_i)
* @throws Z3Exception on error
* @return a boolean
@ -1506,14 +1505,11 @@ public class Expr extends AST
/**
* Indicates whether the term is a proof by rewriting
* Remarks: A proof for
* rewriting an expression t into an expression s. This proof object is used
* if the parameter PROOF_MODE is 1. This proof object can have n
* rewriting an expression t into an expression s. This proof object can have n
* antecedents. The antecedents are proofs for equalities used as
* substitution rules. The object is also used in a few cases if the
* parameter PROOF_MODE is 2. The cases are: - When applying contextual
* substitution rules. The object is used in a few cases . The cases are: - When applying contextual
* simplification (CONTEXT_SIMPLIFIER=true) - When converting bit-vectors to
* Booleans (BIT2BOOL=true) - When pulling ite expression up
* (PULL_CHEAP_ITE_TREES=true)
* Booleans (BIT2BOOL=true)
* @throws Z3Exception on error
* @return a boolean
**/
@ -1534,17 +1530,6 @@ public class Expr extends AST
return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_PULL_QUANT;
}
/**
* Indicates whether the term is a proof for pulling quantifiers out.
*
* Remarks: A proof for (iff P Q) where Q is in prenex normal form. This * proof object is only used if the parameter PROOF_MODE is 1. This proof * object has no antecedents
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isProofPullQuantStar()
{
return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_PULL_QUANT_STAR;
}
/**
* Indicates whether the term is a proof for pushing quantifiers in.
@ -1605,7 +1590,7 @@ public class Expr extends AST
}
/**
* Indicates whether the term is a hypthesis marker.
* Indicates whether the term is a hypothesis marker.
* Remarks: Mark a
* hypothesis in a natural deduction style proof.
* @throws Z3Exception on error
@ -1804,38 +1789,6 @@ public class Expr extends AST
return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_NEG;
}
/**
* Indicates whether the term is a proof for (~ P Q) here Q is in negation
* normal form.
* Remarks: A proof for (~ P Q) where Q is in negation normal
* form.
*
* This proof object is only used if the parameter PROOF_MODE is 1.
*
* This proof object may have n antecedents. Each antecedent is a
* PR_DEF_INTRO.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isProofNNFStar()
{
return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_NNF_STAR;
}
/**
* Indicates whether the term is a proof for (~ P Q) where Q is in
* conjunctive normal form.
* Remarks: A proof for (~ P Q) where Q is in
* conjunctive normal form. This proof object is only used if the parameter
* PROOF_MODE is 1. This proof object may have n antecedents. Each
* antecedent is a PR_DEF_INTRO.
* @throws Z3Exception on error
* @return a boolean
**/
public boolean isProofCNFStar()
{
return isApp() && getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_CNF_STAR;
}
/**
* Indicates whether the term is a proof for a Skolemization step
@ -1987,7 +1940,7 @@ public class Expr extends AST
* Indicates whether the term is a relation filter
* Remarks: Filter
* (restrict) a relation with respect to a predicate. The first argument is
* a relation. The second argument is a predicate with free de-Brujin
* a relation. The second argument is a predicate with free de-Bruijn
* indices corresponding to the columns of the relation. So the first column
* in the relation has index 0.
* @throws Z3Exception on error
@ -2094,7 +2047,7 @@ public class Expr extends AST
}
/**
* The de-Burijn index of a bound variable.
* The de-Bruijn index of a bound variable.
* Remarks: Bound variables are
* indexed by de-Bruijn indices. It is perhaps easiest to explain the
* meaning of de-Bruijn indices by indicating the compilation process from

View file

@ -240,6 +240,21 @@ public class Goal extends Z3Object {
(unsatCores), (proofs)));
}
/**
* Convert a model for the goal into a model of the
* original goal from which this goal was derived.
*
* @return A model for {@code g}
* @throws Z3Exception
**/
public Model convertModel(Model m)
{
return new Model(getContext(),
Native.goalConvertModel(getContext().nCtx(), getNativeObject(), m.getNativeObject()));
}
@Override
void incRef() {
Native.goalIncRef(getContext().nCtx(), getNativeObject());

View file

@ -1,216 +0,0 @@
/**
Copyright (c) 2012-2014 Microsoft Corporation
Module Name:
InterpolationContext.java
Abstract:
Author:
@author Christoph Wintersteiger (cwinter) 2012-03-15
Notes:
**/
package com.microsoft.z3;
import com.microsoft.z3.enumerations.Z3_lbool;
import java.util.Map;
/**
* The InterpolationContext is suitable for generation of interpolants.
*
* Remarks: For more information on interpolation please refer
* too the C/C++ API, which is well documented.
**/
public class InterpolationContext extends Context
{
/**
* Constructor.
**/
public static InterpolationContext mkContext()
{
long m_ctx;
synchronized(creation_lock) {
m_ctx = Native.mkInterpolationContext(0);
}
return new InterpolationContext(m_ctx);
}
/**
* Constructor.
*
*
* Remarks:
* @see Context#Context
**/
public static InterpolationContext mkContext(Map<String, String> settings)
{
long m_ctx;
synchronized(creation_lock) {
long cfg = Native.mkConfig();
for (Map.Entry<String, String> kv : settings.entrySet())
Native.setParamValue(cfg, kv.getKey(), kv.getValue());
m_ctx = Native.mkInterpolationContext(cfg);
Native.delConfig(cfg);
}
return new InterpolationContext(m_ctx);
}
private InterpolationContext(long m_ctx) {
super(m_ctx);
}
/**
* Create an expression that marks a formula position for interpolation.
* @throws Z3Exception
**/
public BoolExpr MkInterpolant(BoolExpr a)
{
checkContextMatch(a);
return new BoolExpr(this, Native.mkInterpolant(nCtx(), a.getNativeObject()));
}
/**
* Computes an interpolant.
* Remarks: For more information on interpolation please refer
* too the function Z3_get_interpolant in the C/C++ API, which is
* well documented.
* @throws Z3Exception
**/
public BoolExpr[] GetInterpolant(Expr pf, Expr pat, Params p)
{
checkContextMatch(pf);
checkContextMatch(pat);
checkContextMatch(p);
ASTVector seq = new ASTVector(this, Native.getInterpolant(nCtx(), pf.getNativeObject(), pat.getNativeObject(), p.getNativeObject()));
return seq.ToBoolExprArray();
}
public class ComputeInterpolantResult
{
public Z3_lbool status = Z3_lbool.Z3_L_UNDEF;
public BoolExpr[] interp = null;
public Model model = null;
};
/**
* Computes an interpolant.
* Remarks: For more information on interpolation please refer
* too the function Z3_compute_interpolant in the C/C++ API, which is
* well documented.
* @throws Z3Exception
**/
public ComputeInterpolantResult ComputeInterpolant(Expr pat, Params p)
{
checkContextMatch(pat);
checkContextMatch(p);
ComputeInterpolantResult res = new ComputeInterpolantResult();
Native.LongPtr n_i = new Native.LongPtr();
Native.LongPtr n_m = new Native.LongPtr();
res.status = Z3_lbool.fromInt(Native.computeInterpolant(nCtx(), pat.getNativeObject(), p.getNativeObject(), n_i, n_m));
if (res.status == Z3_lbool.Z3_L_FALSE)
res.interp = (new ASTVector(this, n_i.value)).ToBoolExprArray();
if (res.status == Z3_lbool.Z3_L_TRUE)
res.model = new Model(this, n_m.value);
return res;
}
///
/// Return a string summarizing cumulative time used for interpolation.
///
/// Remarks: For more information on interpolation please refer
/// too the function Z3_interpolation_profile in the C/C++ API, which is
/// well documented.
public String InterpolationProfile()
{
return Native.interpolationProfile(nCtx());
}
public class CheckInterpolantResult
{
public int return_value = 0;
public String error = null;
}
///
/// Checks the correctness of an interpolant.
///
/// Remarks: For more information on interpolation please refer
/// too the function Z3_check_interpolant in the C/C++ API, which is
/// well documented.
public CheckInterpolantResult CheckInterpolant(Expr[] cnsts, int[] parents, BoolExpr[] interps, String error, Expr[] theory)
{
CheckInterpolantResult res = new CheckInterpolantResult();
Native.StringPtr n_err_str = new Native.StringPtr();
res.return_value = Native.checkInterpolant(nCtx(),
cnsts.length,
Expr.arrayToNative(cnsts),
parents,
Expr.arrayToNative(interps),
n_err_str,
theory.length,
Expr.arrayToNative(theory));
res.error = n_err_str.value;
return res;
}
public class ReadInterpolationProblemResult
{
public int return_value = 0;
public Expr[] cnsts;
public int[] parents;
public String error;
public Expr[] theory;
};
///
/// Reads an interpolation problem from a file.
///
/// Remarks: For more information on interpolation please refer
/// too the function Z3_read_interpolation_problem in the C/C++ API, which is
/// well documented.
public ReadInterpolationProblemResult ReadInterpolationProblem(String filename, Expr[] cnsts, int[] parents, String error, Expr[] theory)
{
ReadInterpolationProblemResult res = new ReadInterpolationProblemResult();
Native.IntPtr n_num = new Native.IntPtr();
Native.IntPtr n_num_theory = new Native.IntPtr();
Native.ObjArrayPtr n_cnsts = new Native.ObjArrayPtr();
Native.UIntArrayPtr n_parents = new Native.UIntArrayPtr();
Native.ObjArrayPtr n_theory = new Native.ObjArrayPtr();
Native.StringPtr n_err_str = new Native.StringPtr();
res.return_value = Native.readInterpolationProblem(nCtx(), n_num, n_cnsts, n_parents, filename, n_err_str, n_num_theory, n_theory);
int num = n_num.value;
int num_theory = n_num_theory.value;
res.error = n_err_str.value;
res.cnsts = new Expr[num];
res.parents = new int[num];
theory = new Expr[num_theory];
for (int i = 0; i < num; i++)
{
res.cnsts[i] = Expr.create(this, n_cnsts.value[i]);
res.parents[i] = n_parents.value[i];
}
for (int i = 0; i < num_theory; i++)
res.theory[i] = Expr.create(this, n_theory.value[i]);
return res;
}
///
/// Writes an interpolation problem to a file.
///
/// Remarks: For more information on interpolation please refer
/// too the function Z3_write_interpolation_problem in the C/C++ API, which is
/// well documented.
public void WriteInterpolationProblem(String filename, Expr[] cnsts, int[] parents, String error, Expr[] theory)
{
Native.writeInterpolationProblem(nCtx(), cnsts.length, Expr.arrayToNative(cnsts), parents, filename, theory.length, Expr.arrayToNative(theory));
}
}

View file

@ -239,7 +239,7 @@ public class Model extends Z3Object {
/**
* The uninterpreted sorts that the model has an interpretation for.
* Remarks: Z3 also provides an intepretation for uninterpreted sorts used
* Remarks: Z3 also provides an interpretation for uninterpreted sorts used
* in a formula. The interpretation for a sort is a finite set of distinct
* values. We say this finite set is the "universe" of the sort.
*

View file

@ -121,22 +121,6 @@ public class Solver extends Z3Object {
}
}
/**
* Load solver assertions from a file.
*/
public void fromFile(String file)
{
Native.solverFromFile(getContext().nCtx(), getNativeObject(), file);
}
/**
* Load solver assertions from a string.
*/
public void fromString(String str)
{
Native.solverFromString(getContext().nCtx(), getNativeObject(), str);
}
/**
* Assert multiple constraints into the solver, and track them (in the
@ -188,6 +172,23 @@ public class Solver extends Z3Object {
constraint.getNativeObject(), p.getNativeObject());
}
/// <summary>
/// Load solver assertions from a file.
/// </summary>
public void fromFile(String file)
{
Native.solverFromFile(getContext().nCtx(), getNativeObject(), file);
}
/// <summary>
/// Load solver assertions from a string.
/// </summary>
public void fromString(String str)
{
Native.solverFromString(getContext().nCtx(), getNativeObject(), str);
}
/**
* The number of assertions in the solver.
*

View file

@ -65,7 +65,7 @@ public class Statistics extends Z3Object {
}
/**
* The string representation of the the entry's value.
* The string representation of the entry's value.
*
* @throws Z3Exception
**/

View file

@ -1402,7 +1402,6 @@ struct
let is_rewrite (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_REWRITE)
let is_rewrite_star (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_REWRITE_STAR)
let is_pull_quant (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_PULL_QUANT)
let is_pull_quant_star (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_PULL_QUANT_STAR)
let is_push_quant (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_PUSH_QUANT)
let is_elim_unused_vars (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_ELIM_UNUSED_VARS)
let is_der (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_DER)
@ -1419,8 +1418,6 @@ struct
let is_iff_oeq (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_IFF_OEQ)
let is_nnf_pos (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_NNF_POS)
let is_nnf_neg (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_NNF_NEG)
let is_nnf_star (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_NNF_STAR)
let is_cnf_star (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_CNF_STAR)
let is_skolemize (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_SKOLEMIZE)
let is_modus_ponens_oeq (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_MODUS_PONENS_OEQ)
let is_theory_lemma (x:expr) = (AST.is_app x) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) = OP_PR_TH_LEMMA)
@ -1657,7 +1654,6 @@ struct
mk_list f n
let get_subgoal (x:apply_result) (i:int) = Z3native.apply_result_get_subgoal (gc x) x i
let convert_model (x:apply_result) (i:int) (m:Model.model) = Z3native.apply_result_convert_model (gc x) x i m
let to_string (x:apply_result) = Z3native.apply_result_to_string (gc x) x
end
@ -1994,56 +1990,10 @@ struct
if csn <> cs || cdn <> cd then
raise (Error "Argument size mismatch")
else
Z3native.parse_smtlib2_string ctx file_name
Z3native.parse_smtlib2_file ctx file_name
cs sort_names sorts cd decl_names decls
end
module Interpolation =
struct
let mk_interpolant = Z3native.mk_interpolant
let mk_interpolation_context (settings:(string * string) list) =
let cfg = Z3native.mk_config () in
let f e = Z3native.set_param_value cfg (fst e) (snd e) in
List.iter f settings;
let res = Z3native.mk_interpolation_context cfg in
Z3native.del_config cfg;
Z3native.set_ast_print_mode res (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT);
Z3native.set_internal_error_handler res;
res
let get_interpolant (ctx:context) (pf:expr) (pat:expr) (p:Params.params) =
let av = Z3native.get_interpolant ctx pf pat p in
AST.ASTVector.to_expr_list av
let compute_interpolant (ctx:context) (pat:expr) (p:Params.params) =
let (r, interp, model) = Z3native.compute_interpolant ctx pat p in
let res = lbool_of_int r in
match res with
| L_TRUE -> (res, None, Some model)
| L_FALSE -> (res, Some (AST.ASTVector.to_expr_list interp), None)
| _ -> (res, None, None)
let get_interpolation_profile = Z3native.interpolation_profile
let read_interpolation_problem (ctx:context) (filename:string) =
let (r, num, cnsts, parents, error, num_theory, theory) =
Z3native.read_interpolation_problem ctx filename
in
match r with
| 0 -> raise (Error "Interpolation problem could not be read.")
| _ -> (cnsts, parents, theory)
let check_interpolant (ctx:context) (num:int) (cnsts:Expr.expr list) (parents:int list) (interps:Expr.expr list) (num_theory:int) (theory:Expr.expr list) =
let (r, str) = Z3native.check_interpolant ctx num cnsts parents interps num_theory theory in
match (lbool_of_int r) with
| L_UNDEF -> raise (Error "Interpolant could not be verified.")
| L_FALSE -> raise (Error "Interpolant could not be verified.")
| _ -> ()
let write_interpolation_problem (ctx:context) (num:int) (cnsts:Expr.expr list) (parents:int list) (filename:string) (num_theory:int) (theory:Expr.expr list) =
Z3native.write_interpolation_problem ctx num cnsts parents filename num_theory theory
end
let set_global_param = Z3native.global_param_set

View file

@ -536,7 +536,7 @@ sig
@return A Term with the given value and sort *)
val mk_numeral_string : context -> string -> Sort.sort -> expr
(** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer.
(** Create a numeral of a given sort. This function can be used to create numerals that fit in a machine integer.
It is slightly faster than [MakeNumeral] since it is not necessary to parse a string.
@return A Term with the given value and sort *)
val mk_numeral_int : context -> int -> Sort.sort -> expr
@ -667,7 +667,7 @@ sig
end
(** The de-Burijn index of a bound variable.
(** The de-Bruijn index of a bound variable.
Bound variables are indexed by de-Bruijn indices. It is perhaps easiest to explain
the meaning of de-Bruijn indices by indicating the compilation process from
@ -830,7 +830,7 @@ sig
(** Maps f on the argument arrays.
Eeach element of [args] must be of an array sort [[domain_i -> range_i]].
Each element of [args] must be of an array sort [[domain_i -> range_i]].
The function declaration [f] must have type [ range_1 .. range_n -> range].
[v] must have sort range. The sort of the result is [[domain_i -> range]].
{!Z3Array.mk_sort}
@ -962,7 +962,7 @@ sig
Filter (restrict) a relation with respect to a predicate.
The first argument is a relation.
The second argument is a predicate with free de-Brujin indices
The second argument is a predicate with free de-Bruijn indices
corresponding to the columns of the relation.
So the first column in the relation has index 0. *)
val is_filter : Expr.expr -> bool
@ -2085,7 +2085,7 @@ sig
(** Indicates whether an expression is a floating-point lt expression *)
val is_lt : Expr.expr -> bool
(** Indicates whether an expression is a floating-point geqexpression *)
(** Indicates whether an expression is a floating-point geq expression *)
val is_geq : Expr.expr -> bool
(** Indicates whether an expression is a floating-point gt expression *)
@ -2233,7 +2233,7 @@ sig
(** Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort. *)
val mk_to_fp_unsigned : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr
(** C1onversion of a floating-point term into an unsigned bit-vector. *)
(** Conversion of a floating-point term into an unsigned bit-vector. *)
val mk_to_ubv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr
(** Conversion of a floating-point term into a signed bit-vector. *)
@ -2362,7 +2362,7 @@ sig
(** Indicates whether the term is a proof by condensed transitivity of a relation
Condensed transitivity proof. This proof object is only used if the parameter PROOF_MODE is 1.
Condensed transitivity proof.
It combines several symmetry and transitivity proofs.
Example:
T1: (R a b)
@ -2385,7 +2385,7 @@ sig
Tn: (R t_n s_n)
[monotonicity T1 ... Tn]: (R (f t_1 ... t_n) (f s_1 ... s_n))
Remark: if t_i == s_i, then the antecedent Ti is suppressed.
That is, reflexivity proofs are supressed to save space. *)
That is, reflexivity proofs are suppressed to save space. *)
val is_monotonicity : Expr.expr -> bool
(** Indicates whether the term is a quant-intro proof
@ -2417,7 +2417,7 @@ sig
[and-elim T1]: l_i *)
val is_and_elimination : Expr.expr -> bool
(** Indicates whether the term is a proof by eliminiation of not-or
(** Indicates whether the term is a proof by elimination of not-or
Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i).
T1: (not (or l_1 ... l_n))
@ -2443,14 +2443,11 @@ sig
(** Indicates whether the term is a proof by rewriting
A proof for rewriting an expression t into an expression s.
This proof object is used if the parameter PROOF_MODE is 1.
This proof object can have n antecedents.
The antecedents are proofs for equalities used as substitution rules.
The object is also used in a few cases if the parameter PROOF_MODE is 2.
The cases are:
The object is also used in a few cases. The cases are:
- When applying contextual simplification (CONTEXT_SIMPLIFIER=true)
- When converting bit-vectors to Booleans (BIT2BOOL=true)
- When pulling ite expression up (PULL_CHEAP_ITE_TREES=true) *)
- When converting bit-vectors to Booleans (BIT2BOOL=true) *)
val is_rewrite_star : Expr.expr -> bool
(** Indicates whether the term is a proof for pulling quantifiers out.
@ -2458,13 +2455,6 @@ sig
A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) r))). This proof object has no antecedents. *)
val is_pull_quant : Expr.expr -> bool
(** Indicates whether the term is a proof for pulling quantifiers out.
A proof for (iff P Q) where Q is in prenex normal form.
This proof object is only used if the parameter PROOF_MODE is 1.
This proof object has no antecedents *)
val is_pull_quant_star : Expr.expr -> bool
(** Indicates whether the term is a proof for pushing quantifiers in.
A proof for:
@ -2500,7 +2490,7 @@ sig
A proof of (or (not (forall (x) (P x))) (P a)) *)
val is_quant_inst : Expr.expr -> bool
(** Indicates whether the term is a hypthesis marker.
(** Indicates whether the term is a hypothesis marker.
Mark a hypothesis in a natural deduction style proof. *)
val is_hypothesis : Expr.expr -> bool
@ -2658,22 +2648,6 @@ sig
(and (or r_1 r_2) (or r_1' r_2'))) *)
val is_nnf_neg : Expr.expr -> bool
(** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form.
A proof for (~ P Q) where Q is in negation normal form.
This proof object is only used if the parameter PROOF_MODE is 1.
This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. *)
val is_nnf_star : Expr.expr -> bool
(** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form.
A proof for (~ P Q) where Q is in conjunctive normal form.
This proof object is only used if the parameter PROOF_MODE is 1.
This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. *)
val is_cnf_star : Expr.expr -> bool
(** Indicates whether the term is a proof for a Skolemization step
Proof for:
@ -2882,7 +2856,7 @@ sig
(** The uninterpreted sorts that the model has an interpretation for.
Z3 also provides an intepretation for uninterpreted sorts used in a formula.
Z3 also provides an interpretation for uninterpreted sorts used in a formula.
The interpretation for a sort is a finite set of distinct values. We say this finite set is
the "universe" of the sort.
{!get_num_sorts}
@ -2990,11 +2964,6 @@ sig
(** Retrieves a subgoal from the apply_result. *)
val get_subgoal : apply_result -> int -> Goal.goal
(** Convert a model for a subgoal into a model for the original
goal [g], that the ApplyResult was obtained from.
#return A model for [g] *)
val convert_model : apply_result -> int -> Model.model -> Model.model
(** A string representation of the ApplyResult. *)
val to_string : apply_result -> string
end
@ -3056,7 +3025,7 @@ sig
(** Create a tactic that fails if the probe evaluates to false. *)
val fail_if : context -> Probe.probe -> tactic
(** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty)
(** Create a tactic that fails if the goal is not trivially satisfiable (i.e., empty)
or trivially unsatisfiable (i.e., contains `false'). *)
val fail_if_not_decided : context -> tactic
@ -3105,7 +3074,7 @@ sig
(** True if the entry is float-valued. *)
val is_float : statistics_entry -> bool
(** The string representation of the the entry's value. *)
(** The string representation of the entry's value. *)
val to_string_value : statistics_entry -> string
(** The string representation of the entry (key and value) *)
@ -3370,7 +3339,7 @@ sig
(** Assert a constraints into the optimize solver. *)
val add : optimize -> Expr.expr list -> unit
(** Asssert a soft constraint.
(** Assert a soft constraint.
Supply integer weight and string that identifies a group
of soft constraints. *)
val add_soft : optimize -> Expr.expr -> string -> Symbol.symbol -> handle
@ -3443,60 +3412,13 @@ sig
(** Parse the given string using the SMT-LIB2 parser.
{!parse_smtlib_string}
@return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *)
val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr
(** Parse the given file using the SMT-LIB2 parser.
{!parse_smtlib2_string} *)
(** Parse the given file using the SMT-LIB2 parser. *)
val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr
end
(** Interpolation *)
module Interpolation :
sig
(** Create an AST node marking a formula position for interpolation.
The expression must have Boolean sort. *)
val mk_interpolant : context -> Expr.expr -> Expr.expr
(** The interpolation context is suitable for generation of interpolants.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val mk_interpolation_context : (string * string) list -> context
(** Gets an interpolant.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val get_interpolant : context -> Expr.expr -> Expr.expr -> Params.params -> Expr.expr list
(** Computes an interpolant.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val compute_interpolant : context -> Expr.expr -> Params.params -> (Z3enums.lbool * Expr.expr list option * Model.model option)
(** Retrieves an interpolation profile.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val get_interpolation_profile : context -> string
(** Read an interpolation problem from file.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val read_interpolation_problem : context -> string -> (Expr.expr list * int list * Expr.expr list)
(** Check the correctness of an interpolant.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val check_interpolant : context -> int -> Expr.expr list -> int list -> Expr.expr list -> int -> Expr.expr list -> unit
(** Write an interpolation problem to file suitable for reading with
Z3_read_interpolation_problem.
For more information on interpolation please refer
too the C/C++ API, which is well documented. *)
val write_interpolation_problem : context -> int -> Expr.expr list -> int list -> string -> int -> Expr.expr list -> unit
end
(** Set a global (or module) parameter, which is shared by all Z3 contexts.

View file

@ -90,6 +90,9 @@ def _z3_assert(cond, msg):
if not cond:
raise Z3Exception(msg)
def _z3_check_cint_overflow(n, name):
_z3_assert(ctypes.c_int(n).value == n, name + " is too large")
def open_log(fname):
"""Log interaction to a file. This function must be invoked immediately after init(). """
Z3_open_log(fname)
@ -114,15 +117,26 @@ def _symbol2py(ctx, s):
# Hack for having nary functions that can receive one argument that is the
# list of arguments.
# Use this when function takes a single list of arguments
def _get_args(args):
try:
if len(args) == 1 and (isinstance(args[0], tuple) or isinstance(args[0], list)):
try:
if len(args) == 1 and (isinstance(args[0], tuple) or isinstance(args[0], list)):
return args[0]
elif len(args) == 1 and (isinstance(args[0], set) or isinstance(args[0], AstVector)):
elif len(args) == 1 and (isinstance(args[0], set) or isinstance(args[0], AstVector)):
return [arg for arg in args[0]]
else:
return args
except: # len is not necessarily defined when args is not a sequence (use reflection?)
return args
# Use this when function takes multiple arguments
def _get_args_ast_list(args):
try:
if isinstance(args, set) or isinstance(args, AstVector) or isinstance(args, tuple):
return [arg for arg in args]
else:
return args
except: # len is not necessarily defined when args is not a sequence (use reflection?)
except:
return args
def _to_param_value(val):
@ -182,7 +196,7 @@ class Context:
"""Interrupt a solver performing a satisfiability test, a tactic processing a goal, or simplify functions.
This method can be invoked from a thread different from the one executing the
interruptable procedure.
interruptible procedure.
"""
Z3_interrupt(self.ref())
@ -365,6 +379,9 @@ class AstRef(Z3PPObject):
_z3_assert(isinstance(target, Context), "argument must be a Z3 context")
return _to_ast_ref(Z3_translate(self.ctx.ref(), self.as_ast(), target.ref()), target)
def __copy__(self):
return self.translate(self.ctx)
def hash(self):
"""Return a hashcode for the `self`.
@ -596,7 +613,7 @@ def _sort(ctx, a):
return _to_sort_ref(Z3_get_sort(ctx.ref(), a), ctx)
def DeclareSort(name, ctx=None):
"""Create a new uninterpred sort named `name`.
"""Create a new uninterpreted sort named `name`.
If `ctx=None`, then the new sort is declared in the global Z3Py context.
@ -718,7 +735,7 @@ class FuncDeclRef(AstRef):
The arguments must be Z3 expressions. This method assumes that
the sorts of the elements in `args` match the sorts of the
domain. Limited coersion is supported. For example, if
domain. Limited coercion is supported. For example, if
args[0] is a Python integer, and the function expects a Z3
integer, then the argument is automatically converted into a
Z3 integer.
@ -1401,6 +1418,17 @@ def is_or(a):
"""
return is_app_of(a, Z3_OP_OR)
def is_implies(a):
"""Return `True` if `a` is a Z3 implication expression.
>>> p, q = Bools('p q')
>>> is_implies(Implies(p, q))
True
>>> is_implies(And(p, q))
False
"""
return is_app_of(a, Z3_OP_IMPLIES)
def is_not(a):
"""Return `True` if `a` is a Z3 not expression.
@ -1873,13 +1901,17 @@ def is_quantifier(a):
def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
if __debug__:
_z3_assert(is_bool(body), "Z3 expression expected")
_z3_assert(is_bool(body) or is_app(vs) or (len(vs) > 0 and is_app(vs[0])), "Z3 expression expected")
_z3_assert(is_const(vs) or (len(vs) > 0 and all([ is_const(v) for v in vs])), "Invalid bounded variable(s)")
_z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
_z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
ctx = body.ctx
_z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
if is_app(vs):
ctx = vs.ctx
vs = [vs]
else:
ctx = vs[0].ctx
if not is_expr(body):
body = BoolVal(body, ctx)
num_vars = len(vs)
if num_vars == 0:
return body
@ -2422,7 +2454,7 @@ def is_rational_value(a):
return is_arith(a) and a.is_real() and _is_numeral(a.ctx, a.as_ast())
def is_algebraic_value(a):
"""Return `True` if `a` is an algerbraic value of sort Real.
"""Return `True` if `a` is an algebraic value of sort Real.
>>> is_algebraic_value(RealVal("3/5"))
False
@ -2740,6 +2772,8 @@ def _py2expr(a, ctx=None):
return IntVal(a, ctx)
if isinstance(a, float):
return RealVal(a, ctx)
if is_expr(a):
return a
if __debug__:
_z3_assert(False, "Python bool, int, long or float expected")
@ -3568,6 +3602,14 @@ def BV2Int(a, is_signed=False):
## investigate problem with bv2int
return ArithRef(Z3_mk_bv2int(ctx.ref(), a.as_ast(), is_signed), ctx)
def Int2BV(a, num_bits):
"""Return the z3 expression Int2BV(a, num_bits).
It is a bit-vector of width num_bits and represents the
modulo of a by 2^num_bits
"""
ctx = a.ctx
return BitVecRef(Z3_mk_int2bv(ctx.ref(), num_bits, a.as_ast()), ctx)
def BitVecSort(sz, ctx=None):
"""Return a Z3 bit-vector sort of the given size. If `ctx=None`, then the global context is used.
@ -4366,6 +4408,117 @@ def is_store(a):
"""
return is_app_of(a, Z3_OP_STORE)
#########################################
#
# Sets
#
#########################################
def SetSort(s):
""" Create a set sort over element sort s"""
return ArraySort(s, BoolSort())
def EmptySet(s):
"""Create the empty set
>>> EmptySet(IntSort())
K(Int, False)
"""
ctx = s.ctx
return ArrayRef(Z3_mk_empty_set(ctx.ref(), s.ast), ctx)
def FullSet(s):
"""Create the full set
>>> FullSet(IntSort())
K(Int, True)
"""
ctx = s.ctx
return ArrayRef(Z3_mk_full_set(ctx.ref(), s.ast), ctx)
def SetUnion(*args):
""" Take the union of sets
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> SetUnion(a, b)
union(a, b)
"""
args = _get_args(args)
ctx = _ctx_from_ast_arg_list(args)
_args, sz = _to_ast_array(args)
return ArrayRef(Z3_mk_set_union(ctx.ref(), sz, _args), ctx)
def SetIntersect(*args):
""" Take the union of sets
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> SetIntersect(a, b)
intersect(a, b)
"""
args = _get_args(args)
ctx = _ctx_from_ast_arg_list(args)
_args, sz = _to_ast_array(args)
return ArrayRef(Z3_mk_set_intersect(ctx.ref(), sz, _args), ctx)
def SetAdd(s, e):
""" Add element e to set s
>>> a = Const('a', SetSort(IntSort()))
>>> SetAdd(a, 1)
Store(a, 1, True)
"""
ctx = _ctx_from_ast_arg_list([s,e])
e = _py2expr(e, ctx)
return ArrayRef(Z3_mk_set_add(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
def SetDel(s, e):
""" Remove element e to set s
>>> a = Const('a', SetSort(IntSort()))
>>> SetDel(a, 1)
Store(a, 1, False)
"""
ctx = _ctx_from_ast_arg_list([s,e])
e = _py2expr(e, ctx)
return ArrayRef(Z3_mk_set_del(ctx.ref(), s.as_ast(), e.as_ast()), ctx)
def SetComplement(s):
""" The complement of set s
>>> a = Const('a', SetSort(IntSort()))
>>> SetComplement(a)
complement(a)
"""
ctx = s.ctx
return ArrayRef(Z3_mk_set_complement(ctx.ref(), s.as_ast()), ctx)
def SetDifference(a, b):
""" The set difference of a and b
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> SetDifference(a, b)
difference(a, b)
"""
ctx = _ctx_from_ast_arg_list([a, b])
return ArrayRef(Z3_mk_set_difference(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
def IsMember(e, s):
""" Check if e is a member of set s
>>> a = Const('a', SetSort(IntSort()))
>>> IsMember(1, a)
a[1]
"""
ctx = _ctx_from_ast_arg_list([s,e])
e = _py2expr(e, ctx)
return BoolRef(Z3_mk_set_member(ctx.ref(), e.as_ast(), s.as_ast()), ctx)
def IsSubset(a, b):
""" Check if a is a subset of b
>>> a = Const('a', SetSort(IntSort()))
>>> b = Const('b', SetSort(IntSort()))
>>> IsSubset(a, b)
subset(a, b)
"""
ctx = _ctx_from_ast_arg_list([a, b])
return BoolRef(Z3_mk_set_subset(ctx.ref(), a.as_ast(), b.as_ast()), ctx)
#########################################
#
# Datatypes
@ -4423,7 +4576,7 @@ class Datatype:
"""Declare constructor named `name` with the given accessors `args`.
Each accessor is a pair `(name, sort)`, where `name` is a string and `sort` a Z3 sort or a reference to the datatypes being declared.
In the followin example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
In the following example `List.declare('cons', ('car', IntSort()), ('cdr', List))`
declares the constructor named `cons` that builds a new List using an integer and a List.
It also declares the accessors `car` and `cdr`. The accessor `car` extracts the integer of a `cons` cell,
and `cdr` the list of a `cons` cell. After all constructors were declared, we use the method create() to create
@ -4437,13 +4590,13 @@ class Datatype:
if __debug__:
_z3_assert(isinstance(name, str), "String expected")
_z3_assert(name != "", "Constructor name cannot be empty")
return self.declare_core(name, "is_" + name, *args)
return self.declare_core(name, "is-" + name, *args)
def __repr__(self):
return "Datatype(%s, %s)" % (self.name, self.constructors)
def create(self):
"""Create a Z3 datatype based on the constructors declared using the mehtod `declare()`.
"""Create a Z3 datatype based on the constructors declared using the method `declare()`.
The function `CreateDatatypes()` must be used to define mutually recursive datatypes.
@ -4561,7 +4714,7 @@ def CreateDatatypes(*ds):
cref = cref()
setattr(dref, cref_name, cref)
rref = dref.recognizer(j)
setattr(dref, rref.name(), rref)
setattr(dref, "is_" + cref_name, rref)
for k in range(cref_arity):
aref = dref.accessor(j, k)
setattr(dref, aref.name(), aref)
@ -4615,16 +4768,16 @@ class DatatypeSortRef(SortRef):
>>> List.num_constructors()
2
>>> List.recognizer(0)
is_cons
is(cons)
>>> List.recognizer(1)
is_nil
is(nil)
>>> simplify(List.is_nil(List.cons(10, List.nil)))
False
>>> simplify(List.is_cons(List.cons(10, List.nil)))
True
>>> l = Const('l', List)
>>> simplify(List.is_cons(l))
is_cons(l)
is(cons, l)
"""
if __debug__:
_z3_assert(idx < self.num_constructors(), "Invalid recognizer index")
@ -5010,6 +5163,35 @@ class Goal(Z3PPObject):
"""
self.assert_exprs(*args)
def convert_model(self, model):
"""Retrieve model from a satisfiable goal
>>> a, b = Ints('a b')
>>> g = Goal()
>>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
>>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
>>> r = t(g)
>>> r[0]
[Or(b == 0, b == 1), Not(0 <= b)]
>>> r[1]
[Or(b == 0, b == 1), Not(1 <= b)]
>>> # Remark: the subgoal r[0] is unsatisfiable
>>> # Creating a solver for solving the second subgoal
>>> s = Solver()
>>> s.add(r[1])
>>> s.check()
sat
>>> s.model()
[b = 0]
>>> # Model s.model() does not assign a value to `a`
>>> # It is a model for subgoal `r[1]`, but not for goal `g`
>>> # The method convert_model creates a model for `g` from a model for `r[1]`.
>>> r[1].convert_model(s.model())
[b = 0, a = 1]
"""
if __debug__:
_z3_assert(isinstance(model, ModelRef), "Z3 Model expected")
return ModelRef(Z3_goal_convert_model(self.ctx.ref(), self.goal, model.model), self.ctx)
def __repr__(self):
return obj_to_string(self)
@ -5017,6 +5199,10 @@ class Goal(Z3PPObject):
"""Return a textual representation of the s-expression representing the goal."""
return Z3_goal_to_string(self.ctx.ref(), self.goal)
def dimacs(self):
"""Return a textual representation of the goal in DIMACS format."""
return Z3_goal_to_dimacs_string(self.ctx.ref(), self.goal)
def translate(self, target):
"""Copy goal `self` to context `target`.
@ -5040,6 +5226,12 @@ class Goal(Z3PPObject):
_z3_assert(isinstance(target, Context), "target must be a context")
return Goal(goal=Z3_goal_translate(self.ctx.ref(), self.goal, target.ref()), ctx=target)
def __copy__(self):
return self.translate(self.ctx)
def __deepcopy__(self):
return self.translate(self.ctx)
def simplify(self, *arguments, **keywords):
"""Return a new simplified goal.
@ -5132,9 +5324,18 @@ class AstVector(Z3PPObject):
>>> A[1]
y
"""
if i >= self.__len__():
raise IndexError
return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
if isinstance(i, int):
if i < 0:
i += self.__len__()
if i >= self.__len__():
raise IndexError
return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)
elif isinstance(i, slice):
return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
def __setitem__(self, i, v):
"""Update AST at position `i`.
@ -5213,6 +5414,12 @@ class AstVector(Z3PPObject):
"""
return AstVector(Z3_ast_vector_translate(self.ctx.ref(), self.vector, other_ctx.ref()), other_ctx)
def __copy__(self):
return self.translate(self.ctx)
def __deepcopy__(self):
return self.translate(self.ctx)
def __repr__(self):
return obj_to_string(self)
@ -5550,6 +5757,17 @@ class FuncInterp(Z3PPObject):
raise IndexError
return FuncEntry(Z3_func_interp_get_entry(self.ctx.ref(), self.f, idx), self.ctx)
def translate(self, other_ctx):
"""Copy model 'self' to context 'other_ctx'.
"""
return ModelRef(Z3_model_translate(self.ctx.ref(), self.model, other_ctx.ref()), other_ctx)
def __copy__(self):
return self.translate(self.ctx)
def __deepcopy__(self):
return self.translate(self.ctx)
def as_list(self):
"""Return the function interpretation as a Python list.
>>> f = Function('f', IntSort(), IntSort())
@ -5579,9 +5797,6 @@ class ModelRef(Z3PPObject):
self.ctx = ctx
Z3_model_inc_ref(self.ctx.ref(), self.model)
def __deepcopy__(self, memo={}):
return ModelRef(self.m, self.ctx)
def __del__(self):
if self.ctx.ref() is not None:
Z3_model_dec_ref(self.ctx.ref(), self.model)
@ -5698,7 +5913,7 @@ class ModelRef(Z3PPObject):
return None
def num_sorts(self):
"""Return the number of unintepreted sorts that contain an interpretation in the model `self`.
"""Return the number of uninterpreted sorts that contain an interpretation in the model `self`.
>>> A = DeclareSort('A')
>>> a, b = Consts('a b', A)
@ -5713,7 +5928,7 @@ class ModelRef(Z3PPObject):
return int(Z3_model_get_num_sorts(self.ctx.ref(), self.model))
def get_sort(self, idx):
"""Return the unintepreted sort at position `idx` < self.num_sorts().
"""Return the uninterpreted sort at position `idx` < self.num_sorts().
>>> A = DeclareSort('A')
>>> B = DeclareSort('B')
@ -5753,7 +5968,7 @@ class ModelRef(Z3PPObject):
return [ self.get_sort(i) for i in range(self.num_sorts()) ]
def get_universe(self, s):
"""Return the intepretation for the uninterpreted sort `s` in the model `self`.
"""Return the interpretation for the uninterpreted sort `s` in the model `self`.
>>> A = DeclareSort('A')
>>> a, b = Consts('a b', A)
@ -5773,7 +5988,7 @@ class ModelRef(Z3PPObject):
return None
def __getitem__(self, idx):
"""If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpreation is returned.
"""If `idx` is an integer, then the declaration at position `idx` in the model `self` is returned. If `idx` is a declaration, then the actual interpretation is returned.
The elements can be retrieved using position or the actual declaration.
@ -5817,7 +6032,7 @@ class ModelRef(Z3PPObject):
return None
def decls(self):
"""Return a list with all symbols that have an interpreation in the model `self`.
"""Return a list with all symbols that have an interpretation in the model `self`.
>>> f = Function('f', IntSort(), IntSort())
>>> x = Int('x')
>>> s = Solver()
@ -5835,6 +6050,20 @@ class ModelRef(Z3PPObject):
r.append(FuncDeclRef(Z3_model_get_func_decl(self.ctx.ref(), self.model, i), self.ctx))
return r
def translate(self, target):
"""Translate `self` to the context `target`. That is, return a copy of `self` in the context `target`.
"""
if __debug__:
_z3_assert(isinstance(target, Context), "argument must be a Z3 context")
model = Z3_model_translate(self.ctx.ref(), self.model, target.ref())
return Model(model, target)
def __copy__(self):
return self.translate(self.ctx)
def __deepcopy__(self):
return self.translate(self.ctx)
def is_as_array(n):
"""Return true if n is a Z3 expression of the form (_ as-array f)."""
return isinstance(n, ExprRef) and Z3_is_as_array(n.ctx.ref(), n.as_ast())
@ -6030,6 +6259,7 @@ class Solver(Z3PPObject):
def __init__(self, solver=None, ctx=None):
assert solver is None or ctx is not None
self.ctx = _get_ctx(ctx)
self.backtrack_level = 4000000000
self.solver = None
if solver is None:
self.solver = Z3_mk_solver(self.ctx.ref())
@ -6037,9 +6267,6 @@ class Solver(Z3PPObject):
self.solver = solver
Z3_solver_inc_ref(self.ctx.ref(), self.solver)
def __deepcopy__(self, memo={}):
return Solver(self.solver, self.ctx)
def __del__(self):
if self.solver is not None and self.ctx.ref() is not None:
Z3_solver_dec_ref(self.ctx.ref(), self.solver)
@ -6339,10 +6566,37 @@ class Solver(Z3PPObject):
except Z3Exception as e:
_handle_parse_error(e, self.ctx)
def cube(self, vars = None):
"""Get set of cubes"""
self.cube_vs = AstVector(None, self.ctx)
if vars is not None:
for v in vars:
self.cube_vs.push(v)
while True:
lvl = self.backtrack_level
self.backtrack_level = 4000000000
r = AstVector(Z3_solver_cube(self.ctx.ref(), self.solver, self.cube_vs.vector, lvl), self.ctx)
if (len(r) == 1 and is_false(r[0])):
return
yield r
if (len(r) == 0):
return
def cube_vars(self):
return self.cube_vs
def proof(self):
"""Return a proof for the last `check()`. Proof construction must be enabled."""
return _to_expr_ref(Z3_solver_get_proof(self.ctx.ref(), self.solver), self.ctx)
def from_file(self, filename):
"""Parse assertions from a file"""
Z3_solver_from_file(self.ctx.ref(), self.solver, filename)
def from_string(self, s):
"""Parse assertions from a string"""
Z3_solver_from_string(self.ctx.ref(), self.solver, s)
def assertions(self):
"""Return an AST vector containing all added constraints.
@ -6357,6 +6611,11 @@ class Solver(Z3PPObject):
"""
return AstVector(Z3_solver_get_assertions(self.ctx.ref(), self.solver), self.ctx)
def units(self):
"""Return an AST vector containing all currently inferred units.
"""
return AstVector(Z3_solver_get_units(self.ctx.ref(), self.solver), self.ctx)
def statistics(self):
"""Return statistics for the last `check()`.
@ -6413,6 +6672,12 @@ class Solver(Z3PPObject):
solver = Z3_solver_translate(self.ctx.ref(), self.solver, target.ref())
return Solver(solver, target)
def __copy__(self):
return self.translate(self.ctx)
def __deepcopy__(self):
return self.translate(self.ctx)
def sexpr(self):
"""Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
@ -6758,8 +7023,8 @@ class FiniteDomainSortRef(SortRef):
def size(self):
"""Return the size of the finite domain sort"""
r = (ctype.c_ulonglong * 1)()
if Z3_get_finite_domain_sort_size(self.ctx_ref(), self.ast(), r):
r = (ctypes.c_ulonglong * 1)()
if Z3_get_finite_domain_sort_size(self.ctx_ref(), self.ast, r):
return r[0]
else:
raise Z3Exception("Failed to retrieve finite domain sort size")
@ -7119,36 +7384,6 @@ class ApplyResult(Z3PPObject):
"""Return a textual representation of the s-expression representing the set of subgoals in `self`."""
return Z3_apply_result_to_string(self.ctx.ref(), self.result)
def convert_model(self, model, idx=0):
"""Convert a model for a subgoal into a model for the original goal.
>>> a, b = Ints('a b')
>>> g = Goal()
>>> g.add(Or(a == 0, a == 1), Or(b == 0, b == 1), a > b)
>>> t = Then(Tactic('split-clause'), Tactic('solve-eqs'))
>>> r = t(g)
>>> r[0]
[Or(b == 0, b == 1), Not(0 <= b)]
>>> r[1]
[Or(b == 0, b == 1), Not(1 <= b)]
>>> # Remark: the subgoal r[0] is unsatisfiable
>>> # Creating a solver for solving the second subgoal
>>> s = Solver()
>>> s.add(r[1])
>>> s.check()
sat
>>> s.model()
[b = 0]
>>> # Model s.model() does not assign a value to `a`
>>> # It is a model for subgoal `r[1]`, but not for goal `g`
>>> # The method convert_model creates a model for `g` from a model for `r[1]`.
>>> r.convert_model(s.model(), 1)
[b = 0, a = 1]
"""
if __debug__:
_z3_assert(idx < len(self), "index out of bounds")
_z3_assert(isinstance(model, ModelRef), "Z3 Model expected")
return ModelRef(Z3_apply_result_convert_model(self.ctx.ref(), self.result, idx, model.model), self.ctx)
def as_expr(self):
"""Return a Z3 expression consisting of all subgoals.
@ -7387,6 +7622,19 @@ def With(t, *args, **keys):
p = args2params(args, keys, t.ctx)
return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
def WithParams(t, p):
"""Return a tactic that applies tactic `t` using the given configuration options.
>>> x, y = Ints('x y')
>>> p = ParamsRef()
>>> p.set("som", True)
>>> t = WithParams(Tactic('simplify'), p)
>>> t((x + 1)*(y + 2) == 0)
[[2*x + y + x*y == -2]]
"""
t = _to_tactic(t, None)
return Tactic(Z3_tactic_using_params(t.ctx.ref(), t.tactic, p.params), t.ctx)
def Repeat(t, max=4294967295, ctx=None):
"""Return a tactic that keeps applying `t` until the goal is not modified anymore or the maximum number of iterations `max` is reached.
@ -7873,8 +8121,10 @@ def AtLeast(*args):
return BoolRef(Z3_mk_atleast(ctx.ref(), sz, _args, k), ctx)
def _pb_args_coeffs(args):
args = _get_args(args)
def _pb_args_coeffs(args, default_ctx = None):
args = _get_args_ast_list(args)
if len(args) == 0:
return _get_ctx(default_ctx), 0, (Ast * 0)(), (ctypes.c_int * 0)()
args, coeffs = zip(*args)
if __debug__:
_z3_assert(len(args) > 0, "Non empty list of arguments expected")
@ -7885,6 +8135,7 @@ def _pb_args_coeffs(args):
_args, sz = _to_ast_array(args)
_coeffs = (ctypes.c_int * len(coeffs))()
for i in range(len(coeffs)):
_z3_check_cint_overflow(coeffs[i], "coefficient")
_coeffs[i] = coeffs[i]
return ctx, sz, _args, _coeffs
@ -7894,6 +8145,7 @@ def PbLe(args, k):
>>> a, b, c = Bools('a b c')
>>> f = PbLe(((a,1),(b,3),(c,2)), 3)
"""
_z3_check_cint_overflow(k, "k")
ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
return BoolRef(Z3_mk_pble(ctx.ref(), sz, _args, _coeffs, k), ctx)
@ -7903,15 +8155,17 @@ def PbGe(args, k):
>>> a, b, c = Bools('a b c')
>>> f = PbGe(((a,1),(b,3),(c,2)), 3)
"""
_z3_check_cint_overflow(k, "k")
ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
return BoolRef(Z3_mk_pbge(ctx.ref(), sz, _args, _coeffs, k), ctx)
def PbEq(args, k):
def PbEq(args, k, ctx = None):
"""Create a Pseudo-Boolean inequality k constraint.
>>> a, b, c = Bools('a b c')
>>> f = PbEq(((a,1),(b,3),(c,2)), 3)
"""
_z3_check_cint_overflow(k, "k")
ctx, sz, _args, _coeffs = _pb_args_coeffs(args)
return BoolRef(Z3_mk_pbeq(ctx.ref(), sz, _args, _coeffs, k), ctx)
@ -8110,19 +8364,19 @@ def parse_smt2_string(s, sorts={}, decls={}, ctx=None):
the symbol table used for the SMT 2.0 parser.
>>> parse_smt2_string('(declare-const x Int) (assert (> x 0)) (assert (< x 10))')
And(x > 0, x < 10)
[x > 0, x < 10]
>>> x, y = Ints('x y')
>>> f = Function('f', IntSort(), IntSort())
>>> parse_smt2_string('(assert (> (+ foo (g bar)) 0))', decls={ 'foo' : x, 'bar' : y, 'g' : f})
x + f(y) > 0
[x + f(y) > 0]
>>> parse_smt2_string('(declare-const a U) (assert (> a 0))', sorts={ 'U' : IntSort() })
a > 0
[a > 0]
"""
ctx = _get_ctx(ctx)
ssz, snames, ssorts = _dict2sarray(sorts, ctx)
dsz, dnames, ddecls = _dict2darray(decls, ctx)
try:
return _to_expr_ref(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
return AstVector(Z3_parse_smtlib2_string(ctx.ref(), s, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
except Z3Exception as e:
_handle_parse_error(e, ctx)
@ -8134,151 +8388,11 @@ def parse_smt2_file(f, sorts={}, decls={}, ctx=None):
ctx = _get_ctx(ctx)
ssz, snames, ssorts = _dict2sarray(sorts, ctx)
dsz, dnames, ddecls = _dict2darray(decls, ctx)
try:
return _to_expr_ref(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
try:
return AstVector(Z3_parse_smtlib2_file(ctx.ref(), f, ssz, snames, ssorts, dsz, dnames, ddecls), ctx)
except Z3Exception as e:
_handle_parse_error(e, ctx)
def Interpolant(a,ctx=None):
"""Create an interpolation operator.
The argument is an interpolation pattern (see tree_interpolant).
>>> x = Int('x')
>>> print(Interpolant(x>0))
interp(x > 0)
"""
ctx = _get_ctx(_ctx_from_ast_arg_list([a], ctx))
s = BoolSort(ctx)
a = s.cast(a)
return BoolRef(Z3_mk_interpolant(ctx.ref(), a.as_ast()), ctx)
def tree_interpolant(pat,p=None,ctx=None):
"""Compute interpolant for a tree of formulas.
The input is an interpolation pattern over a set of formulas C.
The pattern pat is a formula combining the formulas in C using
logical conjunction and the "interp" operator (see Interp). This
interp operator is logically the identity operator. It marks the
sub-formulas of the pattern for which interpolants should be
computed. The interpolant is a map sigma from marked subformulas
to formulas, such that, for each marked subformula phi of pat
(where phi sigma is phi with sigma(psi) substituted for each
subformula psi of phi such that psi in dom(sigma)):
1) phi sigma implies sigma(phi), and
2) sigma(phi) is in the common uninterpreted vocabulary between
the formulas of C occurring in phi and those not occurring in
phi
and moreover pat sigma implies false. In the simplest case
an interpolant for the pattern "(and (interp A) B)" maps A
to an interpolant for A /\ B.
The return value is a vector of formulas representing sigma. This
vector contains sigma(phi) for each marked subformula of pat, in
pre-order traversal. This means that subformulas of phi occur before phi
in the vector. Also, subformulas that occur multiply in pat will
occur multiply in the result vector.
If pat is satisfiable, raises an object of class ModelRef
that represents a model of pat.
If neither a proof of unsatisfiability nor a model is obtained
(for example, because of a timeout, or because models are disabled)
then None is returned.
If parameters p are supplied, these are used in creating the
solver that determines satisfiability.
>>> x = Int('x')
>>> y = Int('y')
>>> print(tree_interpolant(And(Interpolant(x < 0), Interpolant(y > 2), x == y)))
[Not(x >= 0), Not(y <= 2)]
# >>> g = And(Interpolant(x<0),x<2)
# >>> try:
# ... print tree_interpolant(g).sexpr()
# ... except ModelRef as m:
# ... print m.sexpr()
(define-fun x () Int
(- 1))
"""
f = pat
ctx = _get_ctx(_ctx_from_ast_arg_list([f], ctx))
ptr = (AstVectorObj * 1)()
mptr = (Model * 1)()
if p is None:
p = ParamsRef(ctx)
res = Z3_compute_interpolant(ctx.ref(),f.as_ast(),p.params,ptr,mptr)
if res == Z3_L_FALSE:
return AstVector(ptr[0],ctx)
if mptr[0]:
raise ModelRef(mptr[0], ctx)
return None
def binary_interpolant(a,b,p=None,ctx=None):
"""Compute an interpolant for a binary conjunction.
If a & b is unsatisfiable, returns an interpolant for a & b.
This is a formula phi such that
1) a implies phi
2) b implies not phi
3) All the uninterpreted symbols of phi occur in both a and b.
If a & b is satisfiable, raises an object of class ModelRef
that represents a model of a &b.
If neither a proof of unsatisfiability nor a model is obtained
(for example, because of a timeout, or because models are disabled)
then None is returned.
If parameters p are supplied, these are used in creating the
solver that determines satisfiability.
x = Int('x')
print(binary_interpolant(x<0,x>2))
Not(x >= 0)
"""
f = And(Interpolant(a),b)
ti = tree_interpolant(f,p,ctx)
return ti[0] if ti is not None else None
def sequence_interpolant(v,p=None,ctx=None):
"""Compute interpolant for a sequence of formulas.
If len(v) == N, and if the conjunction of the formulas in v is
unsatisfiable, the interpolant is a sequence of formulas w
such that len(w) = N-1 and v[0] implies w[0] and for i in 0..N-1:
1) w[i] & v[i+1] implies w[i+1] (or false if i+1 = N)
2) All uninterpreted symbols in w[i] occur in both v[0]..v[i]
and v[i+1]..v[n]
Requires len(v) >= 1.
If a & b is satisfiable, raises an object of class ModelRef
that represents a model of a & b.
If neither a proof of unsatisfiability nor a model is obtained
(for example, because of a timeout, or because models are disabled)
then None is returned.
If parameters p are supplied, these are used in creating the
solver that determines satisfiability.
x = Int('x')
y = Int('y')
print(sequence_interpolant([x < 0, y == x , y > 2]))
[Not(x >= 0), Not(y >= 0)]
"""
f = v[0]
for i in range(1,len(v)):
f = And(Interpolant(f),v[i])
return tree_interpolant(f,p,ctx)
#########################################
#
@ -8744,7 +8858,10 @@ class FPNumRef(FPRef):
1.25
"""
def significand_as_long(self):
return Z3_fpa_get_numeral_significand_uint64(self.ctx.ref(), self.as_ast())
ptr = (ctypes.c_ulonglong * 1)()
if not Z3_fpa_get_numeral_significand_uint64(self.ctx.ref(), self.as_ast(), ptr):
raise Z3Exception("error retrieving the significand of a numeral.")
return ptr[0]
"""The significand of the numeral as a bit-vector expression.
@ -8801,7 +8918,7 @@ class FPNumRef(FPRef):
def isSubnormal(self):
return Z3_fpa_is_numeral_subnormal(self.ctx.ref(), self.as_ast())
"""Indicates whether the numeral is postitive."""
"""Indicates whether the numeral is positive."""
def isPositive(self):
return Z3_fpa_is_numeral_positive(self.ctx.ref(), self.as_ast())
@ -9183,7 +9300,7 @@ def fpMul(rm, a, b, ctx=None):
return _mk_fp_bin(Z3_mk_fpa_mul, rm, a, b, ctx)
def fpDiv(rm, a, b, ctx=None):
"""Create a Z3 floating-point divison expression.
"""Create a Z3 floating-point division expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
@ -9210,7 +9327,7 @@ def fpRem(a, b, ctx=None):
return _mk_fp_bin_norm(Z3_mk_fpa_rem, a, b, ctx)
def fpMin(a, b, ctx=None):
"""Create a Z3 floating-point minimium expression.
"""Create a Z3 floating-point minimum expression.
>>> s = FPSort(8, 24)
>>> rm = RNE()
@ -9597,7 +9714,7 @@ def fpToIEEEBV(x, ctx=None):
The size of the resulting bit-vector is automatically determined.
Note that IEEE 754-2008 allows multiple different representations of NaN. This conversion
knows only one NaN and it will always produce the same bit-vector represenatation of
knows only one NaN and it will always produce the same bit-vector representation of
that NaN.
>>> x = FP('x', FPSort(8, 24))
@ -9743,6 +9860,14 @@ def String(name, ctx=None):
ctx = _get_ctx(ctx)
return SeqRef(Z3_mk_const(ctx.ref(), to_symbol(name, ctx), StringSort(ctx).ast), ctx)
def SubString(s, offset, length):
"""Extract substring or subsequence starting at offset"""
return Extract(s, offset, length)
def SubSeq(s, offset, length):
"""Extract substring or subsequence starting at offset"""
return Extract(s, offset, length)
def Strings(names, ctx=None):
"""Return a tuple of String constants. """
ctx = _get_ctx(ctx)
@ -9772,13 +9897,13 @@ def Empty(s):
raise Z3Exception("Non-sequence, non-regular expression sort passed to Empty")
def Full(s):
"""Create the regular expression that accepts the universal langauge
"""Create the regular expression that accepts the universal language
>>> e = Full(ReSort(SeqSort(IntSort())))
>>> print(e)
re.all
>>> e1 = Full(ReSort(StringSort()))
>>> print(e1)
re.allchar
re.all
"""
if isinstance(s, ReSortRef):
return ReRef(Z3_mk_re_full(s.ctx_ref(), s.ast), s.ctx)

Some files were not shown because too many files have changed in this diff Show more