3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-28 19:35:50 +00:00
This commit is contained in:
nilsbecker 2018-11-25 16:58:09 +01:00
commit 1e4f524a22
392 changed files with 9183 additions and 4268 deletions

View file

@ -34,7 +34,7 @@ endif()
################################################################################
set(Z3_VERSION_MAJOR 4)
set(Z3_VERSION_MINOR 8)
set(Z3_VERSION_PATCH 0)
set(Z3_VERSION_PATCH 4)
set(Z3_VERSION_TWEAK 0)
set(Z3_VERSION "${Z3_VERSION_MAJOR}.${Z3_VERSION_MINOR}.${Z3_VERSION_PATCH}.${Z3_VERSION_TWEAK}")
set(Z3_FULL_VERSION_STR "${Z3_VERSION}") # Note this might be modified
@ -99,7 +99,7 @@ set(GIT_DIR "${CMAKE_SOURCE_DIR}/.git")
if (EXISTS "${GIT_DIR}")
# Try to make CMake configure depend on the current git HEAD so that
# a re-configure is triggered when the HEAD changes.
add_git_dir_dependency("${GIT_DIR}" ADD_GIT_DEP_SUCCESS)
add_git_dir_dependency("${CMAKE_SOURCE_DIR}" ADD_GIT_DEP_SUCCESS)
if (ADD_GIT_DEP_SUCCESS)
if (INCLUDE_GIT_HASH)
get_git_head_hash("${GIT_DIR}" Z3GITHASH)

View file

@ -5,8 +5,11 @@ under the [MIT license](LICENSE.txt).
If you are not familiar with Z3, you can start [here](https://github.com/Z3Prover/z3/wiki#background).
Pre-built binaries for releases are available from [here](https://github.com/Z3Prover/z3/releases),
and nightly builds from [here](https://github.com/Z3Prover/bin/tree/master/nightly).
Z3 can be built using [Visual Studio][1], a [Makefile][2] or using [CMake][3]. It provides
[bindings for several programming languages][4].
[bindings for several programming languages][4].
See the [release notes](RELEASE_NOTES) for notes on various stable releases of Z3.
@ -14,7 +17,7 @@ See the [release notes](RELEASE_NOTES) for notes on various stable releases of Z
| Windows x64 | Windows x86 | Windows x64 | Ubuntu x64 | Debian x64 | macOS | 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)
[![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) | [![Build status](https://cz3.visualstudio.com/Z3/_apis/build/status/OSX)](https://cz3.visualstudio.com/Z3/_build/latest?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

View file

@ -1,5 +1,23 @@
RELEASE NOTES
Version 4.8.3
=============
- New features
- Native handling of recursive function definitions, thanks to Simon Cruanes
- PB rounding based option for conflict resolution when reasoning about PB constraints.
- Access to numeral constants as a double from the native API.
- Notes
- fixes several bugs discovered since the 4.8.1 release.
Version 4.8.2
=============
- Post-Release.
Version 4.8.1
=============
- Release. Bug-fix for 4.8.0
Version 4.8.0
=============
@ -21,7 +39,7 @@ Version 4.8.0
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.
- The SAT solver includes new inprocessing techniques 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
@ -318,7 +336,7 @@ First source code release (October 2, 2012)
- Added support for numbers in scientific notation at Z3_ast Z3_mk_numeral(__in Z3_context c, __in Z3_string numeral, __in Z3_sort ty).
- New builtin symbols in the arithmetic theory: pi, euler, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh. The first two are constants, and the others are unary functions. These symbols are not available if the a SMT 2.0 logic is specified (e.g., QF_LRA, QF_NRA, QF_LIA, etc) because these symbols are not defined in these logics. That is, the new symbols are only available if the logic is not specified.
- New builtin symbols in the arithmetic theory: pi, euler, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh. The first two are constants, and the others are unary functions. These symbols are not available if a SMT 2.0 logic is specified (e.g., QF_LRA, QF_NRA, QF_LIA, etc) because these symbols are not defined in these logics. That is, the new symbols are only available if the logic is not specified.
Version 4.1
===========

View file

@ -8,13 +8,13 @@
# FIXME: All the commented out defines should be removed once
# we are confident it is correct to not set them.
set(Z3_MSVC_LEGACY_DEFINES
# Don't set `_DEBUG`. The old build sytem sets this but this
# Don't set `_DEBUG`. The old build system sets this but this
# is wrong. MSVC will set this depending on which runtime is being used.
# See https://msdn.microsoft.com/en-us/library/b0084kay.aspx
# _DEBUG
# The old build system only set `UNICODE` and `_UNICODE` for x86_64 release.
# That seems completly wrong so set it for all configurations.
# That seems completely wrong so set it for all configurations.
# According to https://blogs.msdn.microsoft.com/oldnewthing/20040212-00/?p=40643/
# `UNICODE` affects Windows headers and `_UNICODE` affects C runtime header files.
# There is some discussion of this define at https://msdn.microsoft.com/en-us/library/dybsewaf.aspx
@ -116,7 +116,7 @@ z3_add_cxx_flag("/analyze-" REQUIRED)
################################################################################
# By default CMake enables incremental linking for Debug and RelWithDebInfo
# builds. The old build sytem disables it for all builds so try to do the same
# builds. The old build system disables it for all builds so try to do the same
# by changing all configurations if necessary
string(TOUPPER "${available_build_types}" _build_types_as_upper)
foreach (_build_type ${_build_types_as_upper})

View file

@ -7,7 +7,7 @@ function(z3_expand_dependencies output_var)
if (ARGC LESS 2)
message(FATAL_ERROR "Invalid number of arguments")
endif()
# Remaing args should be component names
# Remaining args should be component names
set(_expanded_deps ${ARGN})
set(_old_number_of_deps 0)
list(LENGTH _expanded_deps _number_of_deps)
@ -33,7 +33,7 @@ function(z3_add_component_dependencies_to_target target_name)
if (NOT (TARGET ${target_name}))
message(FATAL_ERROR "Target \"${target_name}\" does not exist")
endif()
# Remaing args should be component names
# Remaining args should be component names
set(_expanded_deps ${ARGN})
foreach (dependency ${_expanded_deps})
# Ensure this component's dependencies are built before this component.
@ -219,7 +219,7 @@ macro(z3_add_component component_name)
# Record this component's dependencies
foreach (dependency ${Z3_MOD_COMPONENT_DEPENDENCIES})
if (NOT (TARGET ${dependency}))
message(FATAL_ERROR "Component \"${component_name}\" depends on a non existant component \"${dependency}\"")
message(FATAL_ERROR "Component \"${component_name}\" depends on a non existent component \"${dependency}\"")
endif()
set_property(GLOBAL APPEND PROPERTY Z3_${component_name}_DEPS "${dependency}")
endforeach()

View file

@ -1,4 +1,4 @@
# Continous integration scripts
# Continuous integration scripts
## TravisCI
@ -45,7 +45,7 @@ the future.
* `Z3_VERBOSE_BUILD_OUTPUT` - Show compile commands in CMake builds (`0` or `1`)
* `Z3_STATIC_BUILD` - Build Z3 binaries and libraries statically (`0` or `1`)
* `Z3_SYSTEM_TEST_GIT_REVISION` - Git revision of [z3test](https://github.com/Z3Prover/z3test). If empty lastest revision will be used.
* `Z3_WARNINGS_AS_ERRORS` - Set the `WARNINGS_AS_ERRORS` CMake option pased to Z3 (`OFF`, `ON`, or `SERIOUS_ONLY`)
* `Z3_WARNINGS_AS_ERRORS` - Set the `WARNINGS_AS_ERRORS` CMake option passed to Z3 (`OFF`, `ON`, or `SERIOUS_ONLY`)
### Linux

93
doc/design_recfuns.md Normal file
View file

@ -0,0 +1,93 @@
# Design for handling recursive functions
Main source of inspiration is [Sutter, Köksal & Kuncak 2011],
as implemented in Leon, but the main
differences is that we should unroll function definitions directly from the
inside of Z3, in a backtracking way. Termination and fairness are ensured by
iterative-deepening on the maximum number of unrollings in a given branch.
## Unfolding
The idea is that every function definition `f(x1…xn) := rhs[x1…xn]` is
compiled into:
- a list of cases `A_f_i[x1…xn] => f(x1…xn) = rhs_i[x1…xn]`.
When `A_f_i[t1…tn]` becomes true in the model, `f(t1…tn)` is said to be
*unfolded* and the clause `A_f_i[t1…tn] => f(t1…tn) = rhs_i[t1…tn]`
is added as an auxiliary clause.
- a list of constraints `Γ_f_i[x1…xn] <=> A_f_i[x1…xn]`
that states when `A_f_i[x1…xn]` should be true, depending on inputs `x1…xn`.
For every term `f(t1…tn)` present in congruence closure, we
immediately add all the `Γ_f_i[t1…tn] <=> A_f_i[t1…tn]` as auxiliary clauses
(maybe during internalization of `f(t1…tn)`?).
where each `A_f_i[x1…xn]` is a special new predicate representing the
given case of `f`, and `rhs_i` does not contain any `ite`.
We assume pattern matching has been compiled to `ite` beforehand.
For example, `fact(n) := if n<2 then 1 else n * fact(n-1)` is compiled into:
- `A_fact_0[n] => fact(n) = 1`
- `A_fact_1[n] => fact(n) = n * fact(n-1)`
- `A_fact_0[n] <=> n < 2`
- `A_fact_1[n] <=> ¬(n < 2)`
The 2 first clauses are only added when `A_fact_0[t]` is true
(respectively `A_fact_1[t]` is true).
The 2 other clauses are added as soon as `fact(t)` is internalized.
## Termination
To ensure termination, we define variables:
- `unfold_depth: int`
- `current_max_unfold_depth: int`
- `global_max_unfold_depth: int`
and a special literal `[max_depth=$n]` for each `n:int`.
Solving is done under the local assumption
`[max_depth=$current_max_unfold_depth]` (this should be handled in some outer
loop, e.g. in a custom tactic).
Whenever `A_f_i[t1…tn]` becomes true (for any `f`), we increment
`unfold_depth`. If `unfold_depth > current_max_unfold_depth`, then
the conflict clause `[max_depth=$current_max_unfold_depth] => Γ => false`
where `Γ` is the conjunction of all `A_f_i[t1…tn]` true in the trail.
For non-recursive functions, we don't have to increment `unfold_depth`. Some other functions that are known
If the solver answers "SAT", we have a model.
Otherwise, if `[max_depth=$current_max_unfold_depth]` is part of the
unsat-core, then we increase `current_max_unfold_depth`.
If `current_max_unfold_depth == global_max_unfold_depth` then
we report "UNKNOWN" (reached global depth limit), otherwise we can
try to `solve()` again with the new assumption (higher depth limit).
## Tactic
there should be a parametrized tactic `funrec(t, n)` where `t` is the tactic
used to solve (under assumption that depth is limited to `current_max_unfold_depth`)
and `n` is an integer that is assigned to `global_max_unfold_depth`.
This way, to try and find models for a problem with recursive functions + LIA,
one could use something like `(funrec (then simplify dl smt) 100)`.
## Expected benefits
This addition to Z3 would bring many benefits compared to current alternatives (Leon, quantifiers, …)
- should be very fast and lightweight
(compared to Leon or quantifiers).
In particular, every function call is very lightweight even compared to Leon (no need for full model building, followed by unsat core extraction)
- possibility of answering "SAT" for any `QF_*` fragment +
recursive functions
- makes `define-funs-rec` a first-class citizen of the language, usable to model user-defined theories or to analyze functional
programs directly
## Optimizations
- maybe `C_f_i` literals should never be decided on
(they can always be propagated).
Even stronger: they should not be part of conflicts?
(i.e. tune conflict resolution to always resolve
these literals away, disregarding their level)

View file

@ -944,7 +944,7 @@ HTML_STYLESHEET =
# user-defined cascading style sheet that is included after the standard
# style sheets created by doxygen. Using this option one can overrule
# certain style aspects. This is preferred over using HTML_STYLESHEET
# since it does not replace the standard style sheet and is therefor more
# since it does not replace the standard style sheet and is therefore more
# robust against future updates. Doxygen will copy the style sheet file to
# the output directory.
@ -1711,7 +1711,7 @@ UML_LOOK = NO
# the class node. If there are many fields or methods and many nodes the
# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS
# threshold limits the number of items for each type to make the size more
# managable. Set this to 0 for no limit. Note that the threshold may be
# manageable. Set this to 0 for no limit. Note that the threshold may be
# exceeded by 50% before the limit is enforced.
UML_LIMIT_NUM_FIELDS = 10

View file

@ -7,8 +7,8 @@ find_package(Z3
REQUIRED
CONFIG
# `NO_DEFAULT_PATH` is set so that -DZ3_DIR has to be passed to find Z3.
# This should prevent us from accidently picking up an installed
# copy of Z3. This is here to benefit Z3's build sytem when building
# This should prevent us from accidentally picking up an installed
# copy of Z3. This is here to benefit Z3's build system when building
# this project. When making your own project you probably shouldn't
# use this option.
NO_DEFAULT_PATH

View file

@ -835,6 +835,17 @@ void tst_visit() {
visit(f);
}
void tst_numeral() {
context c;
expr x = c.real_val("1/3");
double d = 0;
if (!x.is_numeral(d)) {
std::cout << x << " is not recognized as a numeral\n";
return;
}
std::cout << x << " is " << d << "\n";
}
void incremental_example1() {
std::cout << "incremental example1\n";
context c;
@ -1179,6 +1190,20 @@ void mk_model_example() {
std::cout << m.eval(a + b < 2)<< std::endl;
}
void recfun_example() {
std::cout << "recfun example\n";
context c;
expr x = c.int_const("x");
expr y = c.int_const("y");
expr b = c.bool_const("b");
sort I = c.int_sort();
sort B = c.bool_sort();
func_decl f = recfun("f", I, B, I);
expr_vector args(c);
args.push_back(x); args.push_back(b);
c.recdef(f, args, ite(b, x, f(x + 1, !b)));
prove(f(x,c.bool_val(false)) > x);
}
int main() {
@ -1212,6 +1237,7 @@ int main() {
tactic_example9(); std::cout << "\n";
tactic_qe(); std::cout << "\n";
tst_visit(); std::cout << "\n";
tst_numeral(); std::cout << "\n";
incremental_example1(); std::cout << "\n";
incremental_example2(); std::cout << "\n";
incremental_example3(); std::cout << "\n";
@ -1227,6 +1253,7 @@ int main() {
consequence_example(); std::cout << "\n";
parse_example(); std::cout << "\n";
mk_model_example(); std::cout << "\n";
recfun_example(); std::cout << "\n";
std::cout << "done\n";
}
catch (exception & ex) {

View file

@ -24,8 +24,8 @@ find_package(Z3
REQUIRED
CONFIG
# `NO_DEFAULT_PATH` is set so that -DZ3_DIR has to be passed to find Z3.
# This should prevent us from accidently picking up an installed
# copy of Z3. This is here to benefit Z3's build sytem when building
# This should prevent us from accidentally picking up an installed
# copy of Z3. This is here to benefit Z3's build system when building
# this project. When making your own project you probably shouldn't
# use this option.
NO_DEFAULT_PATH

View file

@ -241,7 +241,7 @@ void check(Z3_context ctx, Z3_solver s, Z3_lbool expected_result)
The context \c ctx is not modified by this function.
*/
void prove(Z3_context ctx, Z3_solver s, Z3_ast f, Z3_bool is_valid)
void prove(Z3_context ctx, Z3_solver s, Z3_ast f, bool is_valid)
{
Z3_model m = 0;
Z3_ast not_f;
@ -379,6 +379,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_vector q;
unsigned i;
t = Z3_get_range(ctx, f);
@ -399,7 +400,7 @@ void assert_comm_axiom(Z3_context ctx, Z3_solver s, Z3_func_decl f)
1, &t_name, &t,
1, &f_name, &f);
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) {
for (i = 0; i < Z3_ast_vector_size(ctx, q); ++i) {
Z3_solver_assert(ctx, s, Z3_ast_vector_get(ctx, q, i));
}
}
@ -638,7 +639,7 @@ void display_model(Z3_context c, FILE * out, Z3_model m)
Z3_symbol name;
Z3_func_decl cnst = Z3_model_get_const_decl(c, m, i);
Z3_ast a, v;
Z3_bool ok;
bool ok;
name = Z3_get_decl_name(c, cnst);
display_symbol(c, out, name);
fprintf(out, " = ");
@ -898,7 +899,7 @@ void prove_example1()
/* prove g(x) = g(y) */
f = Z3_mk_eq(ctx, gx, gy);
printf("prove: x = y implies g(x) = g(y)\n");
prove(ctx, s, f, Z3_TRUE);
prove(ctx, s, f, true);
/* create g(g(x)) */
ggx = mk_unary_app(ctx, g, gx);
@ -906,7 +907,7 @@ void prove_example1()
/* disprove g(g(x)) = g(y) */
f = Z3_mk_eq(ctx, ggx, gy);
printf("disprove: x = y implies g(g(x)) = g(y)\n");
prove(ctx, s, f, Z3_FALSE);
prove(ctx, s, f, false);
del_solver(ctx, s);
Z3_del_context(ctx);
@ -978,13 +979,13 @@ void prove_example2()
/* prove z < 0 */
f = Z3_mk_lt(ctx, z, zero);
printf("prove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0\n");
prove(ctx, s, f, Z3_TRUE);
prove(ctx, s, f, true);
/* disprove z < -1 */
minus_one = mk_int(ctx, -1);
f = Z3_mk_lt(ctx, z, minus_one);
printf("disprove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < -1\n");
prove(ctx, s, f, Z3_FALSE);
prove(ctx, s, f, false);
del_solver(ctx, s);
Z3_del_context(ctx);
@ -1130,7 +1131,7 @@ void quantifier_example1()
/* prove f(x, y) = f(w, v) implies y = v */
p2 = Z3_mk_eq(ctx, y, v);
printf("prove: f(x, y) = f(w, v) implies y = v\n");
prove(ctx, s, p2, Z3_TRUE);
prove(ctx, s, p2, true);
/* disprove f(x, y) = f(w, v) implies x = w */
/* using check2 instead of prove */
@ -1197,7 +1198,7 @@ void array_example1()
thm = Z3_mk_implies(ctx, antecedent, consequent);
printf("prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))\n");
printf("%s\n", Z3_ast_to_string(ctx, thm));
prove(ctx, s, thm, Z3_TRUE);
prove(ctx, s, thm, true);
del_solver(ctx, s);
Z3_del_context(ctx);
@ -1338,13 +1339,13 @@ void tuple_example1()
eq2 = Z3_mk_eq(ctx, x, one);
thm = Z3_mk_implies(ctx, eq1, eq2);
printf("prove: get_x(mk_pair(x, y)) = 1 implies x = 1\n");
prove(ctx, s, thm, Z3_TRUE);
prove(ctx, s, thm, true);
/* disprove that get_x(mk_pair(x,y)) == 1 implies y = 1*/
eq3 = Z3_mk_eq(ctx, y, one);
thm = Z3_mk_implies(ctx, eq1, eq3);
printf("disprove: get_x(mk_pair(x, y)) = 1 implies y = 1\n");
prove(ctx, s, thm, Z3_FALSE);
prove(ctx, s, thm, false);
}
{
@ -1365,12 +1366,12 @@ void tuple_example1()
consequent = Z3_mk_eq(ctx, p1, p2);
thm = Z3_mk_implies(ctx, antecedent, consequent);
printf("prove: get_x(p1) = get_x(p2) and get_y(p1) = get_y(p2) implies p1 = p2\n");
prove(ctx, s, thm, Z3_TRUE);
prove(ctx, s, thm, true);
/* disprove that get_x(p1) = get_x(p2) implies p1 = p2 */
thm = Z3_mk_implies(ctx, antecedents[0], consequent);
printf("disprove: get_x(p1) = get_x(p2) implies p1 = p2\n");
prove(ctx, s, thm, Z3_FALSE);
prove(ctx, s, thm, false);
}
{
@ -1389,14 +1390,14 @@ void tuple_example1()
consequent = Z3_mk_eq(ctx, x, ten);
thm = Z3_mk_implies(ctx, antecedent, consequent);
printf("prove: p2 = update(p1, 0, 10) implies get_x(p2) = 10\n");
prove(ctx, s, thm, Z3_TRUE);
prove(ctx, s, thm, true);
/* disprove that p2 = update(p1, 0, 10) implies get_y(p2) = 10 */
y = mk_unary_app(ctx, get_y_decl, p2);
consequent = Z3_mk_eq(ctx, y, ten);
thm = Z3_mk_implies(ctx, antecedent, consequent);
printf("disprove: p2 = update(p1, 0, 10) implies get_y(p2) = 10\n");
prove(ctx, s, thm, Z3_FALSE);
prove(ctx, s, thm, false);
}
del_solver(ctx, s);
@ -1428,7 +1429,7 @@ void bitvector_example1()
c2 = Z3_mk_bvsle(ctx, x_minus_ten, zero);
thm = Z3_mk_iff(ctx, c1, c2);
printf("disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers\n");
prove(ctx, s, thm, Z3_FALSE);
prove(ctx, s, thm, false);
del_solver(ctx, s);
Z3_del_context(ctx);
@ -1644,6 +1645,7 @@ void parser_example2()
Z3_symbol names[2];
Z3_func_decl decls[2];
Z3_ast_vector f;
unsigned i;
printf("\nparser_example2\n");
LOG_MSG("parser_example2");
@ -1668,7 +1670,7 @@ void parser_example2()
2, names, decls);
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) {
for (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);
@ -1715,7 +1717,7 @@ void parser_example3()
0, 0, 0,
1, &g_name, &g);
printf("formula: %s\n", Z3_ast_vector_to_string(ctx, thm));
prove(ctx, s, Z3_ast_vector_get(ctx, thm, 0), Z3_TRUE);
prove(ctx, s, Z3_ast_vector_get(ctx, thm, 0), true);
del_solver(ctx, s);
Z3_del_context(ctx);
@ -1779,13 +1781,13 @@ void numeral_example() {
n2 = Z3_mk_numeral(ctx, "0.5", real_ty);
printf("Numerals n1:%s", Z3_ast_to_string(ctx, n1));
printf(" n2:%s\n", Z3_ast_to_string(ctx, n2));
prove(ctx, s, Z3_mk_eq(ctx, n1, n2), Z3_TRUE);
prove(ctx, s, Z3_mk_eq(ctx, n1, n2), true);
n1 = Z3_mk_numeral(ctx, "-1/3", real_ty);
n2 = Z3_mk_numeral(ctx, "-0.33333333333333333333333333333333333333333333333333", real_ty);
printf("Numerals n1:%s", Z3_ast_to_string(ctx, n1));
printf(" n2:%s\n", Z3_ast_to_string(ctx, n2));
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, n1, n2)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, n1, n2)), true);
del_solver(ctx, s);
Z3_del_context(ctx);
}
@ -1850,14 +1852,14 @@ void enum_example() {
orange = Z3_mk_app(ctx, enum_consts[2], 0, 0);
/* Apples are different from oranges */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, apple, orange)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, apple, orange)), true);
/* Apples pass the apple test */
prove(ctx, s, Z3_mk_app(ctx, enum_testers[0], 1, &apple), Z3_TRUE);
prove(ctx, s, Z3_mk_app(ctx, enum_testers[0], 1, &apple), true);
/* Oranges fail the apple test */
prove(ctx, s, Z3_mk_app(ctx, enum_testers[0], 1, &orange), Z3_FALSE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_app(ctx, enum_testers[0], 1, &orange)), Z3_TRUE);
prove(ctx, s, Z3_mk_app(ctx, enum_testers[0], 1, &orange), false);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_app(ctx, enum_testers[0], 1, &orange)), true);
fruity = mk_var(ctx, "fruity", fruit);
@ -1866,7 +1868,7 @@ void enum_example() {
ors[1] = Z3_mk_eq(ctx, fruity, banana);
ors[2] = Z3_mk_eq(ctx, fruity, orange);
prove(ctx, s, Z3_mk_or(ctx, 3, ors), Z3_TRUE);
prove(ctx, s, Z3_mk_or(ctx, 3, ors), true);
/* delete logical context */
del_solver(ctx, s);
@ -1898,41 +1900,41 @@ void list_example() {
l2 = mk_binary_app(ctx, cons_decl, mk_int(ctx, 2), nil);
/* nil != cons(1, nil) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil, l1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil, l1)), true);
/* cons(2,nil) != cons(1, nil) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, l1, l2)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, l1, l2)), true);
/* cons(x,nil) = cons(y, nil) => x = y */
x = mk_var(ctx, "x", int_ty);
y = mk_var(ctx, "y", int_ty);
l1 = mk_binary_app(ctx, cons_decl, x, nil);
l2 = mk_binary_app(ctx, cons_decl, y, nil);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), true);
/* cons(x,u) = cons(x, v) => u = v */
u = mk_var(ctx, "u", int_list);
v = mk_var(ctx, "v", int_list);
l1 = mk_binary_app(ctx, cons_decl, x, u);
l2 = mk_binary_app(ctx, cons_decl, y, v);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, u, v)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, u, v)), true);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), true);
/* is_nil(u) or is_cons(u) */
ors[0] = Z3_mk_app(ctx, is_nil_decl, 1, &u);
ors[1] = Z3_mk_app(ctx, is_cons_decl, 1, &u);
prove(ctx, s, Z3_mk_or(ctx, 2, ors), Z3_TRUE);
prove(ctx, s, Z3_mk_or(ctx, 2, ors), true);
/* occurs check u != cons(x,u) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, u, l1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, u, l1)), true);
/* destructors: is_cons(u) => u = cons(head(u),tail(u)) */
fml1 = Z3_mk_eq(ctx, u, mk_binary_app(ctx, cons_decl, mk_unary_app(ctx, head_decl, u), mk_unary_app(ctx, tail_decl, u)));
fml = Z3_mk_implies(ctx, Z3_mk_app(ctx, is_cons_decl, 1, &u), fml1);
printf("Formula %s\n", Z3_ast_to_string(ctx, fml));
prove(ctx, s, fml, Z3_TRUE);
prove(ctx, s, fml, true);
prove(ctx, s, fml1, Z3_FALSE);
prove(ctx, s, fml1, false);
/* delete logical context */
del_solver(ctx, s);
@ -1980,7 +1982,7 @@ void tree_example() {
l2 = mk_binary_app(ctx, cons_decl, l1, nil);
/* nil != cons(nil, nil) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil, l1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil, l1)), true);
/* cons(x,u) = cons(x, v) => u = v */
u = mk_var(ctx, "u", cell);
@ -1989,24 +1991,24 @@ void tree_example() {
y = mk_var(ctx, "y", cell);
l1 = mk_binary_app(ctx, cons_decl, x, u);
l2 = mk_binary_app(ctx, cons_decl, y, v);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, u, v)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, u, v)), true);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), true);
/* is_nil(u) or is_cons(u) */
ors[0] = Z3_mk_app(ctx, is_nil_decl, 1, &u);
ors[1] = Z3_mk_app(ctx, is_cons_decl, 1, &u);
prove(ctx, s, Z3_mk_or(ctx, 2, ors), Z3_TRUE);
prove(ctx, s, Z3_mk_or(ctx, 2, ors), true);
/* occurs check u != cons(x,u) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, u, l1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, u, l1)), true);
/* destructors: is_cons(u) => u = cons(car(u),cdr(u)) */
fml1 = Z3_mk_eq(ctx, u, mk_binary_app(ctx, cons_decl, mk_unary_app(ctx, car_decl, u), mk_unary_app(ctx, cdr_decl, u)));
fml = Z3_mk_implies(ctx, Z3_mk_app(ctx, is_cons_decl, 1, &u), fml1);
printf("Formula %s\n", Z3_ast_to_string(ctx, fml));
prove(ctx, s, fml, Z3_TRUE);
prove(ctx, s, fml, true);
prove(ctx, s, fml1, Z3_FALSE);
prove(ctx, s, fml1, false);
/* delete logical context */
del_solver(ctx, s);
@ -2098,8 +2100,8 @@ void forest_example() {
/* nil != cons(nil,nil) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil1, f1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil2, t1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil1, f1)), true);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil2, t1)), true);
/* cons(x,u) = cons(x, v) => u = v */
@ -2109,16 +2111,16 @@ void forest_example() {
y = mk_var(ctx, "y", tree);
l1 = mk_binary_app(ctx, cons1_decl, x, u);
l2 = mk_binary_app(ctx, cons1_decl, y, v);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, u, v)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), Z3_TRUE);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, u, v)), true);
prove(ctx, s, Z3_mk_implies(ctx, Z3_mk_eq(ctx,l1,l2), Z3_mk_eq(ctx, x, y)), true);
/* is_nil(u) or is_cons(u) */
ors[0] = Z3_mk_app(ctx, is_nil1_decl, 1, &u);
ors[1] = Z3_mk_app(ctx, is_cons1_decl, 1, &u);
prove(ctx, s, Z3_mk_or(ctx, 2, ors), Z3_TRUE);
prove(ctx, s, Z3_mk_or(ctx, 2, ors), true);
/* occurs check u != cons(x,u) */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, u, l1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, u, l1)), true);
/* delete logical context */
del_solver(ctx, s);
@ -2191,19 +2193,19 @@ void binary_tree_example() {
Z3_ast node3 = Z3_mk_app(ctx, node_decl, 3, args3);
/* prove that nil != node1 */
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil, node1)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, Z3_mk_eq(ctx, nil, node1)), true);
/* prove that nil = left(node1) */
prove(ctx, s, Z3_mk_eq(ctx, nil, mk_unary_app(ctx, left_decl, node1)), Z3_TRUE);
prove(ctx, s, Z3_mk_eq(ctx, nil, mk_unary_app(ctx, left_decl, node1)), true);
/* prove that node1 = right(node3) */
prove(ctx, s, Z3_mk_eq(ctx, node1, mk_unary_app(ctx, right_decl, node3)), Z3_TRUE);
prove(ctx, s, Z3_mk_eq(ctx, node1, mk_unary_app(ctx, right_decl, node3)), true);
/* prove that !is-nil(node2) */
prove(ctx, s, Z3_mk_not(ctx, mk_unary_app(ctx, is_nil_decl, node2)), Z3_TRUE);
prove(ctx, s, Z3_mk_not(ctx, mk_unary_app(ctx, is_nil_decl, node2)), true);
/* prove that value(node2) >= 0 */
prove(ctx, s, Z3_mk_ge(ctx, mk_unary_app(ctx, value_decl, node2), mk_int(ctx, 0)), Z3_TRUE);
prove(ctx, s, Z3_mk_ge(ctx, mk_unary_app(ctx, value_decl, node2), mk_int(ctx, 0)), true);
}
/* delete logical context */
@ -2302,7 +2304,7 @@ typedef struct {
// IMPORTANT: the fields m_answer_literals, m_retracted and m_num_answer_literals must be saved/restored
// if push/pop operations are performed on m_context.
Z3_ast m_answer_literals[MAX_RETRACTABLE_ASSERTIONS];
Z3_bool m_retracted[MAX_RETRACTABLE_ASSERTIONS]; // true if the assertion was retracted.
bool m_retracted[MAX_RETRACTABLE_ASSERTIONS]; // true if the assertion was retracted.
unsigned m_num_answer_literals;
} Z3_ext_context_struct;
@ -2345,7 +2347,7 @@ unsigned assert_retractable_cnstr(Z3_ext_context ctx, Z3_ast c) {
ans_lit = Z3_mk_fresh_const(ctx->m_context, "k", ty);
result = ctx->m_num_answer_literals;
ctx->m_answer_literals[result] = ans_lit;
ctx->m_retracted[result] = Z3_FALSE;
ctx->m_retracted[result] = false;
ctx->m_num_answer_literals++;
// assert: c OR (not ans_lit)
args[0] = c;
@ -2361,7 +2363,7 @@ void retract_cnstr(Z3_ext_context ctx, unsigned id) {
if (id >= ctx->m_num_answer_literals) {
exitf("invalid constraint id.");
}
ctx->m_retracted[id] = Z3_TRUE;
ctx->m_retracted[id] = true;
}
/**
@ -2371,7 +2373,7 @@ void reassert_cnstr(Z3_ext_context ctx, unsigned id) {
if (id >= ctx->m_num_answer_literals) {
exitf("invalid constraint id.");
}
ctx->m_retracted[id] = Z3_FALSE;
ctx->m_retracted[id] = false;
}
/**
@ -2385,7 +2387,7 @@ Z3_lbool ext_check(Z3_ext_context ctx) {
unsigned core_size;
unsigned i;
for (i = 0; i < ctx->m_num_answer_literals; i++) {
if (ctx->m_retracted[i] == Z3_FALSE) {
if (ctx->m_retracted[i] == false) {
// Since the answer literal was not retracted, we added it as an assumption.
// Recall that we assert (C \/ (not ans_lit)). Therefore, adding ans_lit as an assumption has the effect of "asserting" C.
// If the constraint was "retracted" (ctx->m_retracted[i] == Z3_true), then we don't really need to add (not ans_lit) as an assumption.
@ -2870,19 +2872,19 @@ void mk_model_example() {
/*num_args=*/2,
/*args=*/addArgs);
Z3_ast aPlusBEval = NULL;
Z3_bool aPlusBEvalSuccess =
bool aPlusBEvalSuccess =
Z3_model_eval(ctx, m, aPlusB,
/*model_completion=*/Z3_FALSE, &aPlusBEval);
if (aPlusBEvalSuccess != Z3_TRUE) {
/*model_completion=*/false, &aPlusBEval);
if (aPlusBEvalSuccess != true) {
printf("Failed to evaluate model\n");
exit(1);
}
{
int aPlusBValue = 0;
Z3_bool getAPlusBValueSuccess =
bool getAPlusBValueSuccess =
Z3_get_numeral_int(ctx, aPlusBEval, &aPlusBValue);
if (getAPlusBValueSuccess != Z3_TRUE) {
if (getAPlusBValueSuccess != true) {
printf("Failed to get integer value for a+b\n");
exit(1);
}
@ -2904,18 +2906,18 @@ void mk_model_example() {
/*num_args=*/3,
/*args=*/arrayAddArgs);
Z3_ast arrayAddEval = NULL;
Z3_bool arrayAddEvalSuccess =
bool arrayAddEvalSuccess =
Z3_model_eval(ctx, m, arrayAdd,
/*model_completion=*/Z3_FALSE, &arrayAddEval);
if (arrayAddEvalSuccess != Z3_TRUE) {
/*model_completion=*/false, &arrayAddEval);
if (arrayAddEvalSuccess != true) {
printf("Failed to evaluate model\n");
exit(1);
}
{
int arrayAddValue = 0;
Z3_bool getArrayAddValueSuccess =
bool getArrayAddValueSuccess =
Z3_get_numeral_int(ctx, arrayAddEval, &arrayAddValue);
if (getArrayAddValueSuccess != Z3_TRUE) {
if (getArrayAddValueSuccess != true) {
printf("Failed to get integer value for c[0] + c[1] + c[2]\n");
exit(1);
}

View file

@ -363,10 +363,10 @@ namespace test_mapi
Console.WriteLine("Model = " + s.Model);
Console.WriteLine("Interpretation of MyArray:\n" + s.Model.FuncInterp(aex.FuncDecl));
//Console.WriteLine("Interpretation of MyArray:\n" + s.Model.ConstInterp(aex.FuncDecl));
Console.WriteLine("Interpretation of x:\n" + s.Model.ConstInterp(xc));
Console.WriteLine("Interpretation of f:\n" + s.Model.FuncInterp(fd));
Console.WriteLine("Interpretation of MyArray as Term:\n" + s.Model.FuncInterp(aex.FuncDecl));
//Console.WriteLine("Interpretation of MyArray as Term:\n" + s.Model.ConstInterp(aex.FuncDecl));
}
/// <summary>

View file

@ -11,8 +11,8 @@ find_package(Z3
REQUIRED
CONFIG
# `NO_DEFAULT_PATH` is set so that -DZ3_DIR has to be passed to find Z3.
# This should prevent us from accidently picking up an installed
# copy of Z3. This is here to benefit Z3's build sytem when building
# This should prevent us from accidentally picking up an installed
# copy of Z3. This is here to benefit Z3's build system when building
# this project. When making your own project you probably shouldn't
# use this option.
NO_DEFAULT_PATH

View file

@ -138,7 +138,7 @@ void assert_hard_constraints(Z3_context ctx, Z3_solver s, unsigned num_cnstrs, Z
/**
\brief Assert soft constraints stored in the given array.
This funtion will assert each soft-constraint C_i as (C_i or k_i) where k_i is a fresh boolean variable.
This function will assert each soft-constraint C_i as (C_i or k_i) where k_i is a fresh boolean variable.
It will also return an array containing these fresh variables.
*/
Z3_ast * assert_soft_constraints(Z3_context ctx, Z3_solver s, unsigned num_cnstrs, Z3_ast * cnstrs)
@ -382,7 +382,7 @@ unsigned get_num_disabled_soft_constraints(Z3_context ctx, Z3_model m, unsigned
Z3_ast t = Z3_mk_true(ctx);
for (i = 0; i < num_soft_cnstrs; i++) {
Z3_ast val;
if (Z3_model_eval(ctx, m, aux_vars[i], 1, &val) == Z3_TRUE) {
if (Z3_model_eval(ctx, m, aux_vars[i], 1, &val) == true) {
// printf("%s", Z3_ast_to_string(ctx, aux_vars[i]));
// printf(" -> %s\n", Z3_ast_to_string(ctx, val));
if (Z3_is_eq_ast(ctx, val, t)) {
@ -565,7 +565,7 @@ int fu_malik_maxsat(Z3_context ctx, Z3_solver s, unsigned num_hard_cnstrs, Z3_as
/**
\brief Finds the maximal number of assumptions that can be satisfied.
An assumption is any formula preceeded with the :assumption keyword.
An assumption is any formula preceded with the :assumption keyword.
"Hard" constraints can be supported by using the :formula keyword.
Input: file in SMT-LIB format, and MaxSAT algorithm to be used: 0 - Naive, 1 - Fu&Malik's algo.

View file

@ -226,7 +226,7 @@ namespace Microsoft.SolverFoundation.Plugin.Z3
}
/// <summary>
/// Adds a MSF variable with the coresponding assertion to the Z3 variables.
/// Adds a MSF variable with the corresponding assertion to the Z3 variables.
/// </summary>
/// <param name="vid">The MSF id of the variable</param>
internal void AddVariable(int vid)

149
examples/python/rc2.py Normal file
View file

@ -0,0 +1,149 @@
# RC2 algorithm
# basic version with some optimizations
# - process soft constraints in order of highest values first.
# - extract multiple cores, not just one
# - use built-in cardinality constraints, cheap core minimization.
#
# See also https://github.com/pysathq/pysat and papers in CP 2014, JSAT 2015.
from z3 import *
def tt(s, f):
return is_true(s.model().eval(f))
def add(Ws, f, w):
Ws[f] = w + (Ws[f] if f in Ws else 0)
def sub(Ws, f, w):
w1 = Ws[f]
if w1 > w:
Ws[f] = w1 - w
else:
del(Ws[f])
class RC2:
def __init__(self, s):
self.bounds = {}
self.names = {}
self.solver = s
self.solver.set("sat.cardinality.solver", True)
self.solver.set("sat.core.minimize", True)
self.solver.set("sat.core.minimize_partial", True)
def at_most(self, S, k):
fml = simplify(AtMost(S + [k]))
if fml in self.names:
return self.names[fml]
name = Bool("%s" % fml)
self.solver.add(Implies(name, fml))
self.bounds[name] = (S, k)
sel.names[fml] = name
return name
def print_cost(self):
print("cost [", self.min_cost, ":", self.max_cost, "]")
def update_max_cost(self):
self.max_cost = min(self.max_cost, self.get_cost())
self.print_cost()
# sort W, and incrementally add elements of W
# in sorted order to prefer cores with high weight.
def check(self, Ws):
ws = sorted(list(Ws), lambda f,w : -w)
# print(ws)
i = 0
while i < len(ws):
j = i
# increment j until making 5% progress or exhausting equal weight entries
while (j < len(ws) and ws[j][1] == ws[i][1]) or (i > 0 and (i - j)*20 < len(ws)):
j += 1
i = j
r = self.solver.check(ws[j][0] for j in range(i))
if r == sat:
self.update_max_cost()
else:
return r
return sat
def get_cost(self):
return sum(self.Ws0[c] for c in self.Ws0 if not tt(self.solver, c))
# Retrieve independendent cores from Ws
def get_cores(self, Ws):
cores = []
while unsat == self.check(Ws):
core = list(self.solver.unsat_core())
print (self.solver.statistics())
if not core:
return unsat
w = min([Ws[c] for c in core])
for f in core:
sub(Ws, f, w)
cores += [(core, w)]
self.update_max_cost()
return cores
# Add new soft constraints to replace core
# with weight w. Allow to weaken at most
# one element of core. Elements that are
# cardinality constraints are weakened by
# increasing their bounds. Non-cardinality
# constraints are weakened to "true". They
# correspond to the constraint Not(s) <= 0,
# so weakening produces Not(s) <= 1, which
# is a tautology.
def update_bounds(self, Ws, core, w):
for f in core:
if f in self.bounds:
S, k = self.bounds[f]
if k + 1 < len(S):
add(Ws, self.at_most(S, k + 1), w)
add(Ws, self.at_most([mk_not(f) for f in core], 1), w)
# Ws are weighted soft constraints
# Whenever there is an unsatisfiable core over ws
# increase the limit of each soft constraint from a bound
# and create a soft constraint that limits the number of
# increased bounds to be at most one.
def maxsat(self, Ws):
self.min_cost = 0
self.max_cost = sum(Ws[c] for c in Ws)
self.Ws0 = Ws.copy()
while True:
cores = self.get_cores(Ws)
if not cores:
break
if cores == unsat:
return unsat
for (core, w) in cores:
self.min_cost += w
self.print_cost()
self.update_bounds(Ws, core, w)
return sel.min_cost, { f for f in self.Ws0 if not tt(self.solver, f) }
def from_file(self, file):
opt = Optimize()
opt.from_file(file)
self.solver.add(opt.assertions())
obj = opt.objectives()[0]
Ws = {}
for f in obj.children():
assert(f.arg(1).as_long() == 0)
add(Ws, f.arg(0), f.arg(2).as_long())
return self.maxsat(Ws)
def main(file):
s = SolverFor("QF_FD")
rc2 = RC2(s)
set_param(verbose=0)
cost, falses = rc2.from_file(file)
print(cost)
print(s.statistics())
if len(sys.argv) > 1:
main(sys.argv[1])
# main(<myfile>)

View file

@ -7,8 +7,8 @@ find_package(Z3
REQUIRED
CONFIG
# `NO_DEFAULT_PATH` is set so that -DZ3_DIR has to be passed to find Z3.
# This should prevent us from accidently picking up an installed
# copy of Z3. This is here to benefit Z3's build sytem when building
# This should prevent us from accidentally picking up an installed
# copy of Z3. This is here to benefit Z3's build system when building
# this project. When making your own project you probably shouldn't
# use this option.
NO_DEFAULT_PATH

View file

@ -233,7 +233,7 @@ class env {
void check_arity(unsigned num_args, unsigned arity) {
if (num_args != arity) {
throw failure_ex("arity missmatch");
throw failure_ex("arity mismatch");
}
}
@ -1337,7 +1337,7 @@ public:
}
}
else if (e.is_quantifier()) {
Z3_bool is_forall = Z3_is_quantifier_forall(ctx, e);
bool is_forall = Z3_is_quantifier_forall(ctx, e);
unsigned nb = Z3_get_quantifier_num_bound(ctx, e);
out << (is_forall?"!":"?") << "[";

0
noarch/repodata.json Normal file
View file

BIN
noarch/repodata.json.bz2 Normal file

Binary file not shown.

View file

@ -3,20 +3,20 @@
<metadata>
<id>Microsoft.Z3.x64</id>
<version>$(releaseVersion)</version>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<authors>Microsoft</authors>
<owners>Microsoft,Z3Prover</owners>
<iconUrl>$(iconUrlFromReleaseCommit)</iconUrl>
<projectUrl>https://github.com/Z3Prover/z3</projectUrl>
<licenseUrl>$(licenseUrlFromReleaseCommit)</licenseUrl>
<repository
type="git"
url="https://github.com/Z3Prover/z3.git"
branch="master"
commit="$(releaseCommitHash)"
/>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Z3 is a constraint/SMT solver and theorem prover from Microsoft Research.</description>
<tags>smt constraint solver theorem prover</tags>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<authors>Microsoft</authors>
<iconUrl>https://raw.githubusercontent.com/Z3Prover/z3/$(releaseCommitHash)/package/icon.jpg</iconUrl>
<projectUrl>https://github.com/Z3Prover/z3</projectUrl>
<licenseUrl>https://raw.githubusercontent.com/Z3Prover/z3/$(releaseCommitHash)/LICENSE.txt</licenseUrl>
<repository
type="git"
url="https://github.com/Z3Prover/z3.git"
branch="master"
commit="$(releaseCommitHash)"
/>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Z3 is a satisfiability modulo theories solver from Microsoft Research.</description>
<tags>smt constraint solver theorem prover</tags>
<language>en</language>
</metadata>
</package>

View file

@ -15,11 +15,9 @@
| +-- Microsoft.Z3.x64.targets
| +-- libz3.dll
```
4. Open the nuspec file and fill in the appropriate macro values (note that for all URLs, preserve link integrity by linking to a specific commit):
4. Open the nuspec file and fill in the appropriate macro values:
* $(releaseVersion) - the Z3 version being released in this package
* $(iconUrlFromReleaseCommit) - URL for the Z3 icon file
* $(licenseUrlFromReleaseCommit) - URL for the Z3 repo license
* $(releaseCommitHash) - hash of the release commit
* $(releaseCommitHash) - hash of the release commit (there are several of these)
5. Run `nuget pack Microsoft.Z3.x64\Microsoft.Z3.x64.nuspec`
6. Test the resulting nupkg file (described below) then submit the package for signing before uploading to NuGet.org

View file

@ -692,31 +692,35 @@ def mk_install_tactic_cpp_internal(h_files_full_path, path):
fout.write('#include "cmd_context/tactic_cmds.h"\n')
fout.write('#include "cmd_context/cmd_context.h"\n')
tactic_pat = re.compile('[ \t]*ADD_TACTIC\(.*\)')
probe_pat = re.compile('[ \t]*ADD_PROBE\(.*\)')
probe_pat = re.compile('[ \t]*ADD_PROBE\(.*\)')
for h_file in sorted_headers_by_component(h_files_full_path):
added_include = False
with open(h_file, 'r') as fin:
for line in fin:
if tactic_pat.match(line):
if not added_include:
added_include = True
fout.write('#include "%s"\n' % path_after_src(h_file))
try:
eval(line.strip('\n '), eval_globals, None)
except Exception as e:
_logger.error("Failed processing ADD_TACTIC command at '{}'\n{}".format(
fullname, line))
raise e
if probe_pat.match(line):
if not added_include:
added_include = True
fout.write('#include "%s"\n' % path_after_src(h_file))
try:
eval(line.strip('\n '), eval_globals, None)
except Exception as e:
_logger.error("Failed processing ADD_PROBE command at '{}'\n{}".format(
fullname, line))
raise e
try:
with open(h_file, 'r') as fin:
for line in fin:
if tactic_pat.match(line):
if not added_include:
added_include = True
fout.write('#include "%s"\n' % path_after_src(h_file))
try:
eval(line.strip('\n '), eval_globals, None)
except Exception as e:
_logger.error("Failed processing ADD_TACTIC command at '{}'\n{}".format(
fullname, line))
raise e
if probe_pat.match(line):
if not added_include:
added_include = True
fout.write('#include "%s"\n' % path_after_src(h_file))
try:
eval(line.strip('\n '), eval_globals, None)
except Exception as e:
_logger.error("Failed processing ADD_PROBE command at '{}'\n{}".format(
fullname, line))
raise e
except Exception as e:
_loggeer.error("Failed to read file {}\n".format(h_file))
raise e
# First pass will just generate the tactic factories
fout.write('#define ADD_TACTIC_CMD(NAME, DESCR, CODE) ctx.insert(alloc(tactic_cmd, symbol(NAME), DESCR, [](ast_manager &m, const params_ref &p) { return CODE; }))\n')
fout.write('#define ADD_PROBE(NAME, DESCR, PROBE) ctx.insert(alloc(probe_info, symbol(NAME), DESCR, PROBE))\n')

118
scripts/mk_nuget_release.py Normal file
View file

@ -0,0 +1,118 @@
#
# Copyright (c) 2018 Microsoft Corporation
#
# 1. download releases from github
# 2. copy over libz3.dll for the different architectures
# 3. copy over Microsoft.Z3.dll from suitable distribution
# 4. copy nuspec file from packages
# 5. call nuget pack
import json
import os
import urllib.request
import zipfile
import sys
import os.path
import shutil
import subprocess
import mk_util
import mk_project
data = json.loads(urllib.request.urlopen("https://api.github.com/repos/Z3Prover/z3/releases/latest").read().decode())
version_str = data['tag_name']
print(version_str)
def mk_dir(d):
if not os.path.exists(d):
os.makedirs(d)
def download_installs():
for asset in data['assets']:
url = asset['browser_download_url']
name = asset['name']
print("Downloading ", url)
sys.stdout.flush()
urllib.request.urlretrieve(url, "packages/%s" % name)
os_info = {"z64-ubuntu-14" : ('so', 'ubuntu.14.04-x64'),
'ubuntu-16' : ('so', 'ubuntu.16.04-x64'),
'x64-win' : ('dll', 'win-x64'),
'x86-win' : ('dll', 'win-x86'),
'osx' : ('dylib', 'macos'),
'debian' : ('so', 'debian.8-x64') }
def classify_package(f):
for os_name in os_info:
if os_name in f:
ext, dst = os_info[os_name]
return os_name, f[:-4], ext, dst
return None
def unpack():
shutil.rmtree("out")
# unzip files in packages
# out
# +- runtimes
# +- win-x64
# +- win-x86
# +- ubuntu.16.04-x64
# +- ubuntu.14.04-x64
# +- debian.8-x64
# +- macos
# +
for f in os.listdir("packages"):
print(f)
if f.endswith(".zip") and classify_package(f):
os_name, package_dir, ext, dst = classify_package(f)
path = os.path.abspath(os.path.join("packages", f))
zip_ref = zipfile.ZipFile(path, 'r')
zip_ref.extract("%s/bin/libz3.%s" % (package_dir, ext), "tmp")
mk_dir("out/runtimes/%s" % dst)
shutil.move("tmp/%s/bin/libz3.%s" % (package_dir, ext), "out/runtimes/%s/." % dst, "/y")
if "win" in f:
mk_dir("out/lib/netstandard1.4/")
for b in ["Microsoft.Z3.dll"]:
zip_ref.extract("%s/bin/%s" % (package_dir, b), "tmp")
shutil.move("tmp/%s/bin/%s" % (package_dir, b), "out/lib/netstandard1.4/%s" % b)
def create_nuget_spec():
contents = """<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Microsoft.Z3</id>
<version>%s</version>
<authors>Microsoft</authors>
<description>Z3 is a satisfiability modulo theories solver from Microsoft Research.</description>
<copyright>Copyright Microsoft Corporation. All rights reserved.</copyright>
<tags>smt constraint solver theorem prover</tags>
<iconUrl>https://raw.githubusercontent.com/Z3Prover/z3/master/package/icon.jpg</iconUrl>
<projectUrl>https://github.com/Z3Prover/z3</projectUrl>
<licenseUrl>https://raw.githubusercontent.com/Z3Prover/z3/master/LICENSE.txt</licenseUrl>
<repository
type="git"
url="https://github.com/Z3Prover/z3.git"
branch="master"
/>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<language>en</language>
</metadata>
</package>"""
with open("out/Microsoft.Z3.nuspec", 'w') as f:
f.write(contents % version_str[3:])
def create_nuget_package():
subprocess.call(["nuget", "pack"], cwd="out")
def main():
mk_dir("packages")
download_installs()
unpack()
create_nuget_spec()
create_nuget_package()
main()

View file

@ -7,9 +7,12 @@
############################################
from mk_util import *
def init_version():
set_version(4, 8, 4, 0)
# Z3 Project definition
def init_project_def():
set_version(4, 8, 0, 0)
init_version()
add_lib('util', [], includes2install = ['z3_version.h'])
add_lib('polynomial', ['util'], 'math/polynomial')
add_lib('sat', ['util'])
@ -84,6 +87,7 @@ def init_project_def():
export_files=API_files,
staging_link='python')
add_dot_net_dll('dotnet', ['api_dll'], 'api/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties', default_key_file='src/api/dotnet/Microsoft.Z3.snk')
add_dot_net_core_dll('dotnetcore', ['api_dll'], 'api/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties', default_key_file='src/api/dotnet/Microsoft.Z3.snk')
add_java_dll('java', ['api_dll'], 'api/java', dll_name='libz3java', package_name="com.microsoft.z3", manifest_file='manifest')
add_ml_lib('ml', ['api_dll'], 'api/ml', lib_name='libz3ml')
add_hlib('cpp', 'api/c++', includes2install=['z3++.h'])

View file

@ -23,6 +23,7 @@ VERBOSE=True
DIST_DIR='dist'
FORCE_MK=False
DOTNET_ENABLED=True
DOTNET_CORE_ENABLED=False
DOTNET_KEY_FILE=None
JAVA_ENABLED=True
GIT_HASH=False
@ -55,6 +56,7 @@ def display_help():
print(" -b <sudir>, --build=<subdir> subdirectory where x86 and x64 Z3 versions will be built (default: build-dist).")
print(" -f, --force force script to regenerate Makefiles.")
print(" --nodotnet do not include .NET bindings in the binary distribution files.")
print(" --dotnetcore build for dotnet core.")
print(" --dotnet-key=<file> sign the .NET assembly with the private key in <file>.")
print(" --nojava do not include Java bindings in the binary distribution files.")
print(" --nopython do not include Python bindings in the binary distribution files.")
@ -63,7 +65,7 @@ def display_help():
# Parse configuration option for mk_make script
def parse_options():
global FORCE_MK, JAVA_ENABLED, GIT_HASH, DOTNET_ENABLED, DOTNET_KEY_FILE
global FORCE_MK, JAVA_ENABLED, GIT_HASH, DOTNET_ENABLED, DOTNET_CORE_ENABLED, DOTNET_KEY_FILE
path = BUILD_DIR
options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:hsf', ['build=',
'help',
@ -71,6 +73,7 @@ def parse_options():
'force',
'nojava',
'nodotnet',
'dotnetcore',
'dotnet-key=',
'githash',
'nopython'
@ -88,6 +91,9 @@ def parse_options():
FORCE_MK = True
elif opt == '--nodotnet':
DOTNET_ENABLED = False
elif opt == '--dotnetcore':
DOTNET_CORE_ENABLED = True
DOTNET_ENABLED = False
elif opt == '--nopython':
PYTHON_ENABLED = False
elif opt == '--dotnet-key':
@ -108,7 +114,11 @@ def check_build_dir(path):
def mk_build_dir(path):
if not check_build_dir(path) or FORCE_MK:
opts = ["python", os.path.join('scripts', 'mk_make.py'), "-b", path, "--staticlib"]
if DOTNET_ENABLED:
if DOTNET_CORE_ENABLED:
opts.append('--dotnetcore')
if not DOTNET_KEY_FILE is None:
opts.append('--dotnet-key=' + DOTNET_KEY_FILE)
elif DOTNET_ENABLED:
opts.append('--dotnet')
if not DOTNET_KEY_FILE is None:
opts.append('--dotnet-key=' + DOTNET_KEY_FILE)
@ -186,7 +196,8 @@ def mk_dist_dir():
build_path = BUILD_DIR
dist_path = os.path.join(DIST_DIR, get_z3_name())
mk_dir(dist_path)
mk_util.DOTNET_ENABLED = DOTNET_ENABLED
mk_util.DOTNET_CORE_ENABLED = DOTNET_CORE_ENABLED
mk_util.DOTNET_ENABLED = DOTNET_ENABLED
mk_util.DOTNET_KEY_FILE = DOTNET_KEY_FILE
mk_util.JAVA_ENABLED = JAVA_ENABLED
mk_util.PYTHON_ENABLED = PYTHON_ENABLED

View file

@ -37,6 +37,7 @@ OCAMLOPT=getenv("OCAMLOPT", "ocamlopt")
OCAML_LIB=getenv("OCAML_LIB", None)
OCAMLFIND=getenv("OCAMLFIND", "ocamlfind")
CSC=getenv("CSC", None)
DOTNET="dotnet"
GACUTIL=getenv("GACUTIL", 'gacutil')
# Standard install directories relative to PREFIX
INSTALL_BIN_DIR=getenv("Z3_INSTALL_BIN_DIR", "bin")
@ -60,6 +61,7 @@ PATTERN_COMPONENT='pattern'
UTIL_COMPONENT='util'
API_COMPONENT='api'
DOTNET_COMPONENT='dotnet'
DOTNET_CORE_COMPONENT='dotnetcore'
JAVA_COMPONENT='java'
ML_COMPONENT='ml'
CPP_COMPONENT='cpp'
@ -87,6 +89,7 @@ VS_PROJ = False
TRACE = False
PYTHON_ENABLED=False
DOTNET_ENABLED=False
DOTNET_CORE_ENABLED=False
DOTNET_KEY_FILE=getenv("Z3_DOTNET_KEY_FILE", None)
JAVA_ENABLED=False
ML_ENABLED=False
@ -396,7 +399,7 @@ def check_java():
libdirs = m.group(1).split(',')
for libdir in libdirs:
q = os.path.dirname(libdir)
if cdirs.count(q) == 0:
if cdirs.count(q) == 0 and len(q) > 0:
cdirs.append(q)
t.close()
@ -452,6 +455,13 @@ def check_dotnet():
if r != 0:
raise MKException('Failed testing gacutil. Set environment variable GACUTIL with the path to gacutil.')
def check_dotnet_core():
if not IS_WINDOWS:
return
r = exec_cmd([DOTNET, '--help'])
if r != 0:
raise MKException('Failed testing dotnet. Make sure to install and configure dotnet core utilities')
def check_ml():
t = TempFile('hello.ml')
t.add('print_string "Hello world!\n";;')
@ -553,6 +563,11 @@ def set_version(major, minor, build, revision):
def get_version():
return (VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION)
def get_version_string(n):
if n == 3:
return "{}.{}.{}".format(VER_MAJOR,VER_MINOR,VER_BUILD)
return "{}.{}.{}.{}".format(VER_MAJOR,VER_MINOR,VER_BUILD,VER_REVISION)
def build_static_lib():
return STATIC_LIB
@ -652,6 +667,7 @@ def display_help(exit_code):
if IS_WINDOWS:
print(" -v, --vsproj generate Visual Studio Project Files.")
print(" --optimize generate optimized code during linking.")
print(" --dotnetcore generate .NET platform bindings.")
print(" --dotnet generate .NET bindings.")
print(" --dotnet-key=<file> sign the .NET assembly using the private key in <file>.")
print(" --java generate Java bindings.")
@ -690,14 +706,14 @@ def display_help(exit_code):
# Parse configuration option for mk_make script
def parse_options():
global VERBOSE, DEBUG_MODE, IS_WINDOWS, VS_X64, ONLY_MAKEFILES, SHOW_CPPS, VS_PROJ, TRACE, VS_PAR, VS_PAR_NUM
global DOTNET_ENABLED, DOTNET_KEY_FILE, JAVA_ENABLED, ML_ENABLED, JS_ENABLED, STATIC_LIB, STATIC_BIN, PREFIX, GMP, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH, GIT_DESCRIBE, PYTHON_INSTALL_ENABLED, PYTHON_ENABLED
global DOTNET_ENABLED, DOTNET_CORE_ENABLED, DOTNET_KEY_FILE, JAVA_ENABLED, ML_ENABLED, JS_ENABLED, STATIC_LIB, STATIC_BIN, PREFIX, GMP, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH, GIT_DESCRIBE, PYTHON_INSTALL_ENABLED, PYTHON_ENABLED
global LINUX_X64, SLOW_OPTIMIZE, USE_OMP, LOG_SYNC
global GUARD_CF, ALWAYS_DYNAMIC_BASE
try:
options, remainder = getopt.gnu_getopt(sys.argv[1:],
'b:df:sxhmcvtnp:gj',
['build=', 'debug', 'silent', 'x64', 'help', 'makefiles', 'showcpp', 'vsproj', 'guardcf',
'trace', 'dotnet', 'dotnet-key=', 'staticlib', 'prefix=', 'gmp', 'java', 'parallel=', 'gprof', 'js',
'trace', 'dotnet', 'dotnetcore', 'dotnet-key=', 'staticlib', 'prefix=', 'gmp', 'java', 'parallel=', 'gprof', 'js',
'githash=', 'git-describe', 'x86', 'ml', 'optimize', 'noomp', 'pypkgdir=', 'python', 'staticbin', 'log-sync'])
except:
print("ERROR: Invalid command line option")
@ -731,6 +747,8 @@ def parse_options():
TRACE = True
elif opt in ('-.net', '--dotnet'):
DOTNET_ENABLED = True
elif opt in ('--dotnetcore',):
DOTNET_CORE_ENABLED = True
elif opt in ('--dotnet-key'):
DOTNET_KEY_FILE = arg
elif opt in ('--staticlib'):
@ -887,6 +905,9 @@ def is_js_enabled():
def is_dotnet_enabled():
return DOTNET_ENABLED
def is_dotnet_core_enabled():
return DOTNET_CORE_ENABLED
def is_python_enabled():
return PYTHON_ENABLED
@ -1606,6 +1627,23 @@ class PythonInstallComponent(Component):
def mk_makefile(self, out):
return
def set_key_file(self):
global DOTNET_KEY_FILE
# We need to give the assembly a strong name so that it
# can be installed into the GAC with ``make install``
if not DOTNET_KEY_FILE is None:
self.key_file = DOTNET_KEY_FILE
if not self.key_file is None:
if os.path.isfile(self.key_file):
self.key_file = os.path.abspath(self.key_file)
elif os.path.isfile(os.path.join(self.src_dir, self.key_file)):
self.key_file = os.path.abspath(os.path.join(self.src_dir, self.key_file))
else:
print("Keyfile '%s' could not be found; %s.dll will be unsigned." % (self.key_file, self.dll_name))
self.key_file = None
class DotNetDLLComponent(Component):
def __init__(self, name, dll_name, path, deps, assembly_info_dir, default_key_file):
Component.__init__(self, name, path, deps)
@ -1625,11 +1663,7 @@ class DotNetDLLComponent(Component):
pkg_config_template = os.path.join(self.src_dir, '{}.pc.in'.format(self.gac_pkg_name()))
substitutions = { 'PREFIX': PREFIX,
'GAC_PKG_NAME': self.gac_pkg_name(),
'VERSION': "{}.{}.{}.{}".format(
VER_MAJOR,
VER_MINOR,
VER_BUILD,
VER_REVISION)
'VERSION': get_version_string(4)
}
pkg_config_output = os.path.join(BUILD_DIR,
self.build_dir,
@ -1671,19 +1705,7 @@ class DotNetDLLComponent(Component):
]
)
# We need to give the assembly a strong name so that it
# can be installed into the GAC with ``make install``
if not DOTNET_KEY_FILE is None:
self.key_file = DOTNET_KEY_FILE
if not self.key_file is None:
if os.path.isfile(self.key_file):
self.key_file = os.path.abspath(self.key_file)
elif os.path.isfile(os.path.join(self.src_dir, self.key_file)):
self.key_file = os.path.abspath(os.path.join(self.src_dir, self.key_file))
else:
print("Keyfile '%s' could not be found; %s.dll will be unsigned." % (self.key_file, self.dll_name))
self.key_file = None
set_key_file(self)
if not self.key_file is None:
print("%s.dll will be signed using key '%s'." % (self.dll_name, self.key_file))
@ -1811,6 +1833,134 @@ class DotNetDLLComponent(Component):
pkg_config_file = os.path.join('lib','pkgconfig','{}.pc'.format(self.gac_pkg_name()))
MakeRuleCmd.remove_installed_files(out, pkg_config_file)
# build for dotnet core
class DotNetCoreDLLComponent(Component):
def __init__(self, name, dll_name, path, deps, assembly_info_dir, default_key_file):
Component.__init__(self, name, path, deps)
if dll_name is None:
dll_name = name
if assembly_info_dir is None:
assembly_info_dir = "."
self.dll_name = dll_name
self.assembly_info_dir = assembly_info_dir
self.key_file = default_key_file
def mk_makefile(self, out):
if not is_dotnet_core_enabled():
return
cs_fp_files = []
for cs_file in get_cs_files(self.src_dir):
cs_fp_files.append(os.path.join(self.to_src_dir, cs_file))
if self.assembly_info_dir != '.':
for cs_file in get_cs_files(os.path.join(self.src_dir, self.assembly_info_dir)):
cs_fp_files.append(os.path.join(self.to_src_dir, self.assembly_info_dir, cs_file))
dllfile = '%s.dll' % self.dll_name
out.write('%s: %s$(SO_EXT)' % (dllfile, get_component(Z3_DLL_COMPONENT).dll_name))
for cs_file in cs_fp_files:
out.write(' ')
out.write(cs_file)
out.write('\n')
set_key_file(self)
key = ""
if not self.key_file is None:
key = "<AssemblyOriginatorKeyFile>%s</AssemblyOriginatorKeyFile>" % self.key_file
if VS_X64:
platform = 'x64'
elif VS_ARM:
platform = 'ARM'
else:
platform = 'x86'
version = get_version_string(3)
core_csproj_str = """<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<PlatformTarget>%s</PlatformTarget>
<DefineConstants>$(DefineConstants);DOTNET_CORE</DefineConstants>
<DebugType>portable</DebugType>
<AssemblyName>Microsoft.Z3</AssemblyName>
<OutputType>Library</OutputType>
<PackageId>Microsoft.Z3</PackageId>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
<Version>%s</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Microsoft</Authors>
<Company>Microsoft</Company>
<Description>Z3 is a satisfiability modulo theories solver from Microsoft Research.</Description>
<Copyright>Copyright Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>smt constraint solver theorem prover</PackageTags>
%s
</PropertyGroup>
<ItemGroup>
<Compile Include="..\%s\*.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
</ItemGroup>
</Project>""" % (platform, version, key, self.to_src_dir)
mk_dir(os.path.join(BUILD_DIR, 'dotnet'))
csproj = os.path.join('dotnet', 'z3.csproj')
with open(os.path.join(BUILD_DIR, csproj), 'w') as ous:
ous.write(core_csproj_str)
dotnetCmdLine = [DOTNET, "build", csproj]
dotnetCmdLine.extend(['-c'])
if DEBUG_MODE:
dotnetCmdLine.extend(['Debug'])
else:
dotnetCmdLine.extend(['Release'])
path = os.path.join(os.path.abspath(BUILD_DIR), ".")
dotnetCmdLine.extend(['-o', path])
MakeRuleCmd.write_cmd(out, ' '.join(dotnetCmdLine))
out.write('\n')
out.write('%s: %s\n\n' % (self.name, dllfile))
def main_component(self):
return is_dotnet_core_enabled()
def has_assembly_info(self):
# TBD: is this required for dotnet core given that version numbers are in z3.csproj file?
return True
def mk_win_dist(self, build_path, dist_path):
if is_dotnet_core_enabled():
mk_dir(os.path.join(dist_path, INSTALL_BIN_DIR))
shutil.copy('%s.dll' % os.path.join(build_path, self.dll_name),
'%s.dll' % os.path.join(dist_path, INSTALL_BIN_DIR, self.dll_name))
shutil.copy('%s.deps.json' % os.path.join(build_path, self.dll_name),
'%s.deps.json' % os.path.join(dist_path, INSTALL_BIN_DIR, self.dll_name))
if DEBUG_MODE:
shutil.copy('%s.pdb' % os.path.join(build_path, self.dll_name),
'%s.pdb' % os.path.join(dist_path, INSTALL_BIN_DIR, self.dll_name))
def mk_unix_dist(self, build_path, dist_path):
if is_dotnet_core_enabled():
mk_dir(os.path.join(dist_path, INSTALL_BIN_DIR))
shutil.copy('%s.dll' % os.path.join(build_path, self.dll_name),
'%s.dll' % os.path.join(dist_path, INSTALL_BIN_DIR, self.dll_name))
shutil.copy('%s.deps.json' % os.path.join(build_path, self.dll_name),
'%s.deps.json' % os.path.join(dist_path, INSTALL_BIN_DIR, self.dll_name))
def mk_install_deps(self, out):
pass
def mk_install(self, out):
pass
def mk_uninstall(self, out):
pass
class JavaDLLComponent(Component):
def __init__(self, name, dll_name, package_name, manifest_file, path, deps):
Component.__init__(self, name, path, deps)
@ -2201,7 +2351,7 @@ class DotNetExampleComponent(ExampleComponent):
ExampleComponent.__init__(self, name, path)
def is_example(self):
return is_dotnet_enabled()
return is_dotnet_enabled() or is_dotnet_core_enabled()
def mk_makefile(self, out):
if is_dotnet_enabled():
@ -2229,6 +2379,48 @@ class DotNetExampleComponent(ExampleComponent):
out.write(os.path.join(relative_path, csfile))
out.write('\n')
out.write('_ex_%s: %s\n\n' % (self.name, exefile))
if is_dotnet_core_enabled():
proj_name = 'dotnet_example.csproj'
out.write('_ex_%s:' % self.name)
for csfile in get_cs_files(self.ex_dir):
out.write(' ')
out.write(os.path.join(self.to_ex_dir, csfile))
mk_dir(os.path.join(BUILD_DIR, 'dotnet_example'))
csproj = os.path.join('dotnet_example', proj_name)
if VS_X64:
platform = 'x64'
elif VS_ARM:
platform = 'ARM'
else:
platform = 'x86'
dotnet_proj_str = """<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PlatformTarget>%s</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\%s/*.cs" />
<Reference Include="Microsoft.Z3">
<HintPath>..\Microsoft.Z3.dll</HintPath>
</Reference>
</ItemGroup>
</Project>""" % (platform, self.to_ex_dir)
with open(os.path.join(BUILD_DIR, csproj), 'w') as ous:
ous.write(dotnet_proj_str)
out.write('\n')
dotnetCmdLine = [DOTNET, "build", csproj]
dotnetCmdLine.extend(['-c'])
if DEBUG_MODE:
dotnetCmdLine.extend(['Debug'])
else:
dotnetCmdLine.extend(['Release'])
MakeRuleCmd.write_cmd(out, ' '.join(dotnetCmdLine))
out.write('\n')
class JavaExampleComponent(ExampleComponent):
def __init__(self, name, path):
@ -2347,6 +2539,10 @@ def add_dot_net_dll(name, deps=[], path=None, dll_name=None, assembly_info_dir=N
c = DotNetDLLComponent(name, dll_name, path, deps, assembly_info_dir, default_key_file)
reg_component(name, c)
def add_dot_net_core_dll(name, deps=[], path=None, dll_name=None, assembly_info_dir=None, default_key_file=None):
c = DotNetCoreDLLComponent(name, dll_name, path, deps, assembly_info_dir, default_key_file)
reg_component(name, c)
def add_java_dll(name, deps=[], path=None, dll_name=None, package_name=None, manifest_file=None):
c = JavaDLLComponent(name, dll_name, package_name, manifest_file, path, deps)
reg_component(name, c)
@ -2654,6 +2850,8 @@ def mk_config():
if is_dotnet_enabled():
print('C# Compiler: %s' % CSC)
print('GAC utility: %s' % GACUTIL)
if is_dotnet_core_enabled():
print('C# Compiler: %s' % DOTNET)
config.close()
@ -2979,6 +3177,9 @@ def mk_bindings(api_files):
dotnet_output_dir = None
if is_dotnet_enabled():
dotnet_output_dir = get_component('dotnet').src_dir
elif is_dotnet_core_enabled():
dotnet_output_dir = os.path.join(BUILD_DIR, 'dotnet')
mk_dir(dotnet_output_dir)
java_output_dir = None
java_package_name = None
if is_java_enabled():
@ -3007,7 +3208,10 @@ def mk_bindings(api_files):
mk_z3consts_ml(api_files)
if is_dotnet_enabled():
check_dotnet()
mk_z3consts_dotnet(api_files)
mk_z3consts_dotnet(api_files, dotnet_output_dir)
if is_dotnet_core_enabled():
check_dotnet_core()
mk_z3consts_dotnet(api_files, dotnet_output_dir)
# Extract enumeration types from API files, and add python definitions.
def mk_z3consts_py(api_files):
@ -3024,14 +3228,16 @@ def mk_z3consts_py(api_files):
print("Generated '{}".format(generated_file))
# Extract enumeration types from z3_api.h, and add .Net definitions
def mk_z3consts_dotnet(api_files):
def mk_z3consts_dotnet(api_files, output_dir):
dotnet = get_component(DOTNET_COMPONENT)
if not dotnet:
dotnet = get_component(DOTNET_CORE_COMPONENT)
full_path_api_files = []
for api_file in api_files:
api_file_c = dotnet.find_file(api_file, dotnet.name)
api_file = os.path.join(api_file_c.src_dir, api_file)
full_path_api_files.append(api_file)
generated_file = mk_genfile_common.mk_z3consts_dotnet_internal(full_path_api_files, dotnet.src_dir)
generated_file = mk_genfile_common.mk_z3consts_dotnet_internal(full_path_api_files, output_dir)
if VERBOSE:
print("Generated '{}".format(generated_file))
@ -3276,7 +3482,7 @@ class MakeRuleCmd(object):
needed commands used in Makefile rules
Note that several of the method are meant for use during ``make
install`` and ``make uninstall``. These methods correctly use
``$(PREFIX)`` and ``$(DESTDIR)`` and therefore are preferrable
``$(PREFIX)`` and ``$(DESTDIR)`` and therefore are preferable
to writing commands manually which can be error prone.
"""
@classmethod

View file

@ -25,6 +25,7 @@ VERBOSE=True
DIST_DIR='dist'
FORCE_MK=False
DOTNET_ENABLED=True
DOTNET_CORE_ENABLED=False
DOTNET_KEY_FILE=None
JAVA_ENABLED=True
GIT_HASH=False
@ -62,6 +63,7 @@ def display_help():
print(" -b <sudir>, --build=<subdir> subdirectory where x86 and x64 Z3 versions will be built (default: build-dist).")
print(" -f, --force force script to regenerate Makefiles.")
print(" --nodotnet do not include .NET bindings in the binary distribution files.")
print(" --dotnetcore build for dotnet core.")
print(" --dotnet-key=<file> sign the .NET assembly with the private key in <file>.")
print(" --nojava do not include Java bindings in the binary distribution files.")
print(" --nopython do not include Python bindings in the binary distribution files.")
@ -72,7 +74,7 @@ def display_help():
# Parse configuration option for mk_make script
def parse_options():
global FORCE_MK, JAVA_ENABLED, GIT_HASH, DOTNET_ENABLED, DOTNET_KEY_FILE, PYTHON_ENABLED, X86ONLY, X64ONLY
global FORCE_MK, JAVA_ENABLED, GIT_HASH, DOTNET_ENABLED, DOTNET_CORE_ENABLED, DOTNET_KEY_FILE, PYTHON_ENABLED, X86ONLY, X64ONLY
path = BUILD_DIR
options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:hsf', ['build=',
'help',
@ -80,6 +82,7 @@ def parse_options():
'force',
'nojava',
'nodotnet',
'dotnetcore',
'dotnet-key=',
'githash',
'nopython',
@ -99,6 +102,9 @@ def parse_options():
FORCE_MK = True
elif opt == '--nodotnet':
DOTNET_ENABLED = False
elif opt == '--dotnetcore':
DOTNET_CORE_ENABLED = True
DOTNET_ENABLED = False
elif opt == '--nopython':
PYTHON_ENABLED = False
elif opt == '--dotnet-key':
@ -124,7 +130,11 @@ def mk_build_dir(path, x64):
if not check_build_dir(path) or FORCE_MK:
parallel = '--parallel=' + MAKEJOBS
opts = ["python", os.path.join('scripts', 'mk_make.py'), parallel, "-b", path]
if DOTNET_ENABLED:
if DOTNET_CORE_ENABLED:
opts.append('--dotnetcore')
if not DOTNET_KEY_FILE is None:
opts.append('--dotnet-key=' + DOTNET_KEY_FILE)
elif DOTNET_ENABLED:
opts.append('--dotnet')
if not DOTNET_KEY_FILE is None:
opts.append('--dotnet-key=' + DOTNET_KEY_FILE)
@ -208,7 +218,10 @@ def mk_dist_dir(x64):
build_path = BUILD_X86_DIR
dist_path = os.path.join(DIST_DIR, get_z3_name(x64))
mk_dir(dist_path)
mk_util.DOTNET_ENABLED = DOTNET_ENABLED
if DOTNET_CORE_ENABLED:
mk_util.DOTNET_CORE_ENABLED = True
else:
mk_util.DOTNET_ENABLED = DOTNET_ENABLED
mk_util.DOTNET_KEY_FILE = DOTNET_KEY_FILE
mk_util.JAVA_ENABLED = JAVA_ENABLED
mk_util.PYTHON_ENABLED = PYTHON_ENABLED
@ -257,19 +270,30 @@ def cp_vs_runtime(x64):
else:
platform = "x86"
vcdir = os.environ['VCINSTALLDIR']
path = '%sredist\\%s' % (vcdir, platform)
VS_RUNTIME_FILES = []
path = '%sredist' % vcdir
vs_runtime_files = []
print("Walking %s" % path)
# Everything changes with every release of VS
# Prior versions of VS had DLLs under "redist\x64"
# There are now several variants of redistributables
# The naming convention defies my understanding so
# we use a "check_root" filter to find some hopefully suitable
# redistributable.
def check_root(root):
return platform in root and ("CRT" in root or "MP" in root) and "onecore" not in root and "debug" not in root
for root, dirs, files in os.walk(path):
for filename in files:
if fnmatch(filename, '*.dll'):
if fnmatch(filename, '*.dll') and check_root(root):
print("Checking %s %s" % (root, filename))
for pat in VS_RUNTIME_PATS:
if pat.match(filename):
fname = os.path.join(root, filename)
if not os.path.isdir(fname):
VS_RUNTIME_FILES.append(fname)
vs_runtime_files.append(fname)
if not vs_runtime_files:
raise MKException("Did not find any runtime files to include")
bin_dist_path = os.path.join(DIST_DIR, get_dist_path(x64), 'bin')
for f in VS_RUNTIME_FILES:
for f in vs_runtime_files:
shutil.copy(f, bin_dist_path)
if is_verbose():
print("Copied '%s' to '%s'" % (f, bin_dist_path))

View file

@ -61,7 +61,7 @@ def is_obj(ty):
return ty >= FIRST_OBJ_ID
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',
FLOAT : 'float', STRING : 'Z3_string', STRING_PTR : 'Z3_string_ptr', BOOL : 'bool', SYMBOL : 'Z3_symbol',
PRINT_MODE : 'Z3_ast_print_mode', ERROR_CODE : 'Z3_error_code'
}
@ -1227,7 +1227,7 @@ def ml_has_plus_type(ts):
def ml_unwrap(t, ts, s):
if t == STRING:
return '(' + ts + ') String_val(' + s + ')'
elif t == BOOL or (type2str(t) == 'Z3_bool'):
elif t == BOOL or (type2str(t) == 'bool'):
return '(' + ts + ') Bool_val(' + s + ')'
elif t == INT or t == PRINT_MODE or t == ERROR_CODE:
return '(' + ts + ') Int_val(' + s + ')'
@ -1248,7 +1248,7 @@ def ml_unwrap(t, ts, s):
def ml_set_wrap(t, d, n):
if t == VOID:
return d + ' = Val_unit;'
elif t == BOOL or (type2str(t) == 'Z3_bool'):
elif t == BOOL or (type2str(t) == 'bool'):
return d + ' = Val_bool(' + n + ');'
elif t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE:
return d + ' = Val_int(' + n + ');'
@ -1263,7 +1263,7 @@ def ml_set_wrap(t, d, n):
return '*(' + pts + '*)Data_custom_val(' + d + ') = ' + n + ';'
def ml_alloc_and_store(t, lhs, rhs):
if t == VOID or t == BOOL or t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE or t == INT64 or t == UINT64 or t == DOUBLE or t == STRING or (type2str(t) == 'Z3_bool'):
if t == VOID or t == BOOL or t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE or t == INT64 or t == UINT64 or t == DOUBLE or t == STRING or (type2str(t) == 'bool'):
return ml_set_wrap(t, lhs, rhs)
else:
pts = ml_plus_type(type2str(t))
@ -1328,6 +1328,13 @@ def mk_ml(ml_src_dir, ml_output_dir):
mk_z3native_stubs_c(ml_src_dir, ml_output_dir)
z3_long_funs = frozenset([
'Z3_solver_check',
'Z3_solver_check_assumptions',
'Z3_simplify',
'Z3_simplify_ex',
])
def mk_z3native_stubs_c(ml_src_dir, ml_output_dir): # C interface
ml_wrapperf = os.path.join(ml_output_dir, 'z3native_stubs.c')
ml_wrapper = open(ml_wrapperf, 'w')
@ -1491,6 +1498,10 @@ def mk_z3native_stubs_c(ml_src_dir, ml_output_dir): # C interface
ml_wrapper.write(' assert(_iter == Val_emptylist);\n\n')
i = i + 1
release_caml_gc= name in z3_long_funs
if release_caml_gc:
ml_wrapper.write('\n caml_release_runtime_system();\n')
ml_wrapper.write('\n /* invoke Z3 function */\n ')
if result != VOID:
ts = type2str(result)
@ -1499,6 +1510,7 @@ def mk_z3native_stubs_c(ml_src_dir, ml_output_dir): # C interface
else:
ml_wrapper.write('z3rv = ')
# invoke procedure
ml_wrapper.write('%s(' % name)
i = 0
@ -1516,6 +1528,9 @@ def mk_z3native_stubs_c(ml_src_dir, ml_output_dir): # C interface
i = i + 1
ml_wrapper.write(');\n')
if release_caml_gc:
ml_wrapper.write('\n caml_acquire_runtime_system();\n')
if have_context and name not in Unwrapped:
ml_wrapper.write(' ec = Z3_get_error_code(ctx_p->ctx);\n')
ml_wrapper.write(' if (ec != Z3_OK) {\n')
@ -1868,7 +1883,7 @@ def generate_files(api_files,
mk_dotnet_wrappers(dotnet_file)
if mk_util.is_verbose():
print("Generated '{}'".format(dotnet_file.name))
if java_output_dir:
mk_java(java_output_dir, java_package_name)

View file

@ -220,7 +220,7 @@ lbool lackr::lazy() {
lackr_model_constructor mc(m_m, m_info);
push_abstraction();
unsigned ackr_head = 0;
while (1) {
while (true) {
m_st.m_it++;
checkpoint();
TRACE("lackr", tout << "lazy check: " << m_st.m_it << "\n";);

View file

@ -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 == nullptr) { // TODO: avoid model completetion?
if (val == nullptr) { // TODO: avoid model completion?
sort * s = fd->get_range();
val = m_abstr_model->get_some_value(s);
}

View file

@ -79,23 +79,23 @@ extern "C" {
_c->autil().is_irrational_algebraic_numeral(to_expr(a)));
}
Z3_bool Z3_API Z3_algebraic_is_value(Z3_context c, Z3_ast a) {
bool Z3_API Z3_algebraic_is_value(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_algebraic_is_value(c, a);
RESET_ERROR_CODE();
return Z3_algebraic_is_value_core(c, a) ? Z3_TRUE : Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return Z3_algebraic_is_value_core(c, a);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_algebraic_is_pos(Z3_context c, Z3_ast a) {
bool Z3_API Z3_algebraic_is_pos(Z3_context c, Z3_ast a) {
return Z3_algebraic_sign(c, a) > 0;
}
Z3_bool Z3_API Z3_algebraic_is_neg(Z3_context c, Z3_ast a) {
bool Z3_API Z3_algebraic_is_neg(Z3_context c, Z3_ast a) {
return Z3_algebraic_sign(c, a) < 0;
}
Z3_bool Z3_API Z3_algebraic_is_zero(Z3_context c, Z3_ast a) {
bool Z3_API Z3_algebraic_is_zero(Z3_context c, Z3_ast a) {
return Z3_algebraic_sign(c, a) == 0;
}
@ -283,32 +283,32 @@ extern "C" {
r = _am.IRAT_PRED(av, bv); \
} \
} \
return r ? Z3_TRUE : Z3_FALSE;
return r;
Z3_bool Z3_API Z3_algebraic_lt(Z3_context c, Z3_ast a, Z3_ast b) {
bool Z3_API Z3_algebraic_lt(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_lt(c, a, b);
RESET_ERROR_CODE();
CHECK_IS_ALGEBRAIC(a, 0);
CHECK_IS_ALGEBRAIC(b, 0);
BIN_PRED(<,lt);
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_algebraic_gt(Z3_context c, Z3_ast a, Z3_ast b) {
bool Z3_API Z3_algebraic_gt(Z3_context c, Z3_ast a, Z3_ast b) {
return Z3_algebraic_lt(c, b, a);
}
Z3_bool Z3_API Z3_algebraic_le(Z3_context c, Z3_ast a, Z3_ast b) {
bool Z3_API Z3_algebraic_le(Z3_context c, Z3_ast a, Z3_ast b) {
return !Z3_algebraic_lt(c, b, a);
}
Z3_bool Z3_API Z3_algebraic_ge(Z3_context c, Z3_ast a, Z3_ast b) {
bool Z3_API Z3_algebraic_ge(Z3_context c, Z3_ast a, Z3_ast b) {
return !Z3_algebraic_lt(c, a, b);
}
Z3_bool Z3_API Z3_algebraic_eq(Z3_context c, Z3_ast a, Z3_ast b) {
bool Z3_API Z3_algebraic_eq(Z3_context c, Z3_ast a, Z3_ast b) {
Z3_TRY;
LOG_Z3_algebraic_eq(c, a, b);
RESET_ERROR_CODE();
@ -318,7 +318,7 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_bool Z3_API Z3_algebraic_neq(Z3_context c, Z3_ast a, Z3_ast b) {
bool Z3_API Z3_algebraic_neq(Z3_context c, Z3_ast a, Z3_ast b) {
return !Z3_algebraic_eq(c, a, b);
}

View file

@ -119,9 +119,9 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_algebraic_number(Z3_context c, Z3_ast a) {
LOG_Z3_is_algebraic_number(c, a);
return mk_c(c)->autil().is_irrational_algebraic_numeral(to_expr(a)) ? Z3_TRUE : Z3_FALSE;
return mk_c(c)->autil().is_irrational_algebraic_numeral(to_expr(a));
}
Z3_ast Z3_API Z3_get_algebraic_number_lower(Z3_context c, Z3_ast a, unsigned precision) {

View file

@ -33,11 +33,14 @@ Revision History:
#include "ast/rewriter/th_rewriter.h"
#include "ast/rewriter/var_subst.h"
#include "ast/rewriter/expr_safe_replace.h"
#include "ast/rewriter/recfun_replace.h"
#include "ast/pp.h"
#include "util/scoped_ctrl_c.h"
#include "util/cancel_eh.h"
#include "util/scoped_timer.h"
#include "ast/pp_params.hpp"
#include "ast/expr_abstract.h"
extern bool is_numeral_sort(Z3_context c, Z3_sort ty);
@ -70,7 +73,7 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2) {
bool Z3_API Z3_is_eq_sort(Z3_context c, Z3_sort s1, Z3_sort s2) {
RESET_ERROR_CODE();
return s1 == s2;
}
@ -85,12 +88,12 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast s1, Z3_ast s2) {
bool Z3_API Z3_is_eq_ast(Z3_context c, Z3_ast s1, Z3_ast s2) {
RESET_ERROR_CODE();
return s1 == s2;
}
Z3_bool Z3_API Z3_is_eq_func_decl(Z3_context c, Z3_func_decl s1, Z3_func_decl s2) {
bool Z3_API Z3_is_eq_func_decl(Z3_context c, Z3_func_decl s1, Z3_func_decl s2) {
RESET_ERROR_CODE();
return s1 == s2;
}
@ -110,6 +113,55 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const* domain,
Z3_sort range) {
Z3_TRY;
LOG_Z3_mk_rec_func_decl(c, s, domain_size, domain, range);
RESET_ERROR_CODE();
//
recfun::promise_def def =
mk_c(c)->recfun().get_plugin().mk_def(to_symbol(s),
domain_size,
to_sorts(domain),
to_sort(range));
func_decl* d = def.get_def()->get_decl();
mk_c(c)->save_ast_trail(d);
RETURN_Z3(of_func_decl(d));
Z3_CATCH_RETURN(nullptr);
}
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body) {
Z3_TRY;
LOG_Z3_add_rec_def(c, f, n, args, body);
func_decl* d = to_func_decl(f);
ast_manager& m = mk_c(c)->m();
recfun::decl::plugin& p = mk_c(c)->recfun().get_plugin();
expr_ref abs_body(m);
expr_ref_vector _args(m);
var_ref_vector _vars(m);
for (unsigned i = 0; i < n; ++i) {
_args.push_back(to_expr(args[i]));
_vars.push_back(m.mk_var(n - i - 1, m.get_sort(_args.back())));
if (m.get_sort(_args.back()) != d->get_domain(i)) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return;
}
}
expr_abstract(m, 0, n, _args.c_ptr(), to_expr(body), abs_body);
recfun::promise_def pd = p.get_promise_def(d);
if (!pd.get_def()) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return;
}
if (m.get_sort(abs_body) != d->get_range()) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return;
}
recfun_replace replace(m);
p.set_definition(replace, pd, n, _vars.c_ptr(), abs_body);
Z3_CATCH;
}
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const * args) {
Z3_TRY;
LOG_Z3_mk_app(c, d, num_args, args);
@ -256,12 +308,12 @@ extern "C" {
return to_sort(s)->get_id();
}
Z3_bool Z3_API Z3_is_well_sorted(Z3_context c, Z3_ast t) {
bool Z3_API Z3_is_well_sorted(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_is_well_sorted(c, t);
RESET_ERROR_CODE();
return is_well_sorted(mk_c(c)->m(), to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_symbol_kind Z3_API Z3_get_symbol_kind(Z3_context c, Z3_symbol s) {
@ -331,7 +383,7 @@ extern "C" {
return to_ast(a)->hash();
}
Z3_bool Z3_API Z3_is_app(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_app(Z3_context c, Z3_ast a) {
LOG_Z3_is_app(c, a);
RESET_ERROR_CODE();
return a != nullptr && is_app(reinterpret_cast<ast*>(a));

View file

@ -57,12 +57,12 @@ extern "C" {
Z3_CATCH;
}
Z3_bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k) {
bool Z3_API Z3_ast_map_contains(Z3_context c, Z3_ast_map m, Z3_ast k) {
Z3_TRY;
LOG_Z3_ast_map_contains(c, m, k);
RESET_ERROR_CODE();
return to_ast_map_ref(m).contains(to_ast(k));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_ast Z3_API Z3_ast_map_find(Z3_context c, Z3_ast_map m, Z3_ast k) {

View file

@ -106,7 +106,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
MK_BV_PUNARY(Z3_mk_rotate_right, OP_ROTATE_RIGHT);
MK_BV_PUNARY(Z3_mk_int2bv, OP_INT2BV);
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast n, Z3_bool is_signed) {
Z3_ast Z3_API Z3_mk_bv2int(Z3_context c, Z3_ast n, bool is_signed) {
Z3_TRY;
LOG_Z3_mk_bv2int(c, n, is_signed);
RESET_ERROR_CODE();
@ -186,7 +186,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
return Z3_mk_int(c, -1, s);
}
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, Z3_bool is_signed) {
Z3_ast Z3_API Z3_mk_bvadd_no_overflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed) {
Z3_TRY;
RESET_ERROR_CODE();
if (is_signed) {
@ -286,7 +286,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
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) {
Z3_ast Z3_API Z3_mk_bvsub_no_underflow(Z3_context c, Z3_ast t1, Z3_ast t2, bool is_signed) {
Z3_TRY;
RESET_ERROR_CODE();
if (is_signed) {
@ -311,7 +311,7 @@ Z3_ast Z3_API NAME(Z3_context c, unsigned i, Z3_ast n) { \
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) {
Z3_ast Z3_API Z3_mk_bvmul_no_overflow(Z3_context c, Z3_ast n1, Z3_ast n2, bool is_signed) {
LOG_Z3_mk_bvmul_no_overflow(c, n1, n2, is_signed);
RESET_ERROR_CODE();
if (is_signed) {

View file

@ -57,13 +57,13 @@ extern "C" {
try {
g_Z3_global_param_get_buffer = gparams::get_value(param_id);
*param_value = g_Z3_global_param_get_buffer.c_str();
return Z3_TRUE;
return true;
}
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
warning_msg("%s", ex.msg());
return Z3_FALSE;
return false;
}
}

View file

@ -79,6 +79,7 @@ namespace api {
m_datalog_util(m()),
m_fpa_util(m()),
m_sutil(m()),
m_recfun(m()),
m_last_result(m()),
m_ast_trail(m()),
m_pmanager(m_limit) {
@ -219,7 +220,7 @@ namespace api {
if (m_user_ref_count) {
// Corner case bug: n may be in m_last_result, and this is the only reference to n.
// When, we execute reset() it is deleted
// To avoid this bug, I bump the reference counter before reseting m_last_result
// To avoid this bug, I bump the reference counter before resetting m_last_result
ast_ref node(n, m());
m_last_result.reset();
m_last_result.push_back(std::move(node));
@ -362,7 +363,7 @@ extern "C" {
Z3_CATCH;
}
void Z3_API Z3_toggle_warning_messages(Z3_bool enabled) {
void Z3_API Z3_toggle_warning_messages(bool enabled) {
LOG_Z3_toggle_warning_messages(enabled);
enable_warning_messages(enabled != 0);
}
@ -439,7 +440,6 @@ extern "C" {
void Z3_API Z3_set_error_handler(Z3_context c, Z3_error_handler h) {
RESET_ERROR_CODE();
mk_c(c)->set_error_handler(h);
// [Leo]: using exception handling, we don't need global error handlers anymore
}
void Z3_API Z3_set_error(Z3_context c, Z3_error_code e) {

View file

@ -29,6 +29,7 @@ Revision History:
#include "ast/datatype_decl_plugin.h"
#include "ast/dl_decl_plugin.h"
#include "ast/fpa_decl_plugin.h"
#include "ast/recfun_decl_plugin.h"
#include "smt/smt_kernel.h"
#include "smt/params/smt_params.h"
#include "util/event_handler.h"
@ -62,6 +63,7 @@ namespace api {
datalog::dl_decl_util m_datalog_util;
fpa_util m_fpa_util;
seq_util m_sutil;
recfun::util m_recfun;
// Support for old solver API
smt_params m_fparams;
@ -128,6 +130,7 @@ namespace api {
fpa_util & fpautil() { return m_fpa_util; }
datatype_util& dtutil() { return m_dt_plugin->u(); }
seq_util& sutil() { return m_sutil; }
recfun::util& recfun() { return m_recfun; }
family_id get_basic_fid() const { return m_basic_fid; }
family_id get_array_fid() const { return m_array_fid; }
family_id get_arith_fid() const { return m_arith_fid; }

View file

@ -199,23 +199,23 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t * out) {
bool Z3_API Z3_get_finite_domain_sort_size(Z3_context c, Z3_sort s, uint64_t * out) {
Z3_TRY;
if (out) {
*out = 0;
}
if (Z3_get_sort_kind(c, s) != Z3_FINITE_DOMAIN_SORT) {
return Z3_FALSE;
return false;
}
if (!out) {
return Z3_FALSE;
return false;
}
// must start loggging here, since function uses Z3_get_sort_kind above
// must start logging here, since function uses Z3_get_sort_kind above
LOG_Z3_get_finite_domain_sort_size(c, s, out);
RESET_ERROR_CODE();
VERIFY(mk_c(c)->datalog_util().try_get_size(to_sort(s), *out));
return Z3_TRUE;
Z3_CATCH_RETURN(Z3_FALSE);
return true;
Z3_CATCH_RETURN(false);
}
Z3_fixedpoint Z3_API Z3_mk_fixedpoint(Z3_context c) {
@ -715,6 +715,4 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
};

View file

@ -232,7 +232,7 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, Z3_bool negative) {
Z3_ast Z3_API Z3_mk_fpa_inf(Z3_context c, Z3_sort s, bool negative) {
Z3_TRY;
LOG_Z3_mk_fpa_inf(c, s, negative);
RESET_ERROR_CODE();
@ -249,7 +249,7 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, Z3_bool negative) {
Z3_ast Z3_API Z3_mk_fpa_zero(Z3_context c, Z3_sort s, bool negative) {
Z3_TRY;
LOG_Z3_mk_fpa_inf(c, s, negative);
RESET_ERROR_CODE();
@ -338,7 +338,7 @@ extern "C" {
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) {
Z3_ast Z3_API Z3_mk_fpa_numeral_int_uint(Z3_context c, bool sgn, signed exp, unsigned sig, Z3_sort ty) {
Z3_TRY;
LOG_Z3_mk_fpa_numeral_int64_uint64(c, sgn, exp, sig, ty);
RESET_ERROR_CODE();
@ -358,7 +358,7 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
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_ast Z3_API Z3_mk_fpa_numeral_int64_uint64(Z3_context c, 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();
@ -905,7 +905,7 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int * sgn) {
bool Z3_API Z3_fpa_get_numeral_sign(Z3_context c, Z3_ast t, int * sgn) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_sign(c, t, sgn);
RESET_ERROR_CODE();
@ -913,7 +913,7 @@ extern "C" {
CHECK_VALID_AST(t, 0);
if (sgn == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG, "sign cannot be a nullpointer");
return 0;
return false;
}
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
@ -922,13 +922,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, "invalid expression argument, expecting a valid fp, not a NaN");
return 0;
return false;
}
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, "invalid expression argument, expecting a valid fp, not a NaN");
return 0;
return false;
}
*sgn = mpfm.sgn(val);
return r;
@ -1035,7 +1035,7 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_fpa_get_numeral_significand_uint64(Z3_context c, Z3_ast t, uint64_t * n) {
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();
@ -1043,7 +1043,7 @@ extern "C" {
CHECK_VALID_AST(t, 0);
if (n == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG, "invalid nullptr argument");
return 0;
return false;
}
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
@ -1055,7 +1055,7 @@ extern "C" {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG, "invalid expression argument, expecting a valid fp, not a NaN");
*n = 0;
return 0;
return false;
}
scoped_mpf val(mpfm);
bool r = plugin->is_numeral(e, val);
@ -1065,14 +1065,14 @@ extern "C" {
!mpzm.is_uint64(z)) {
SET_ERROR_CODE(Z3_INVALID_ARG, "invalid expression argument, expecting a valid fp, not a NaN");
*n = 0;
return 0;
return false;
}
*n = mpzm.get_uint64(z);
return 1;
return true;
Z3_CATCH_RETURN(0);
}
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, Z3_bool biased) {
Z3_string Z3_API Z3_fpa_get_numeral_exponent_string(Z3_context c, Z3_ast t, bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_string(c, t, biased);
RESET_ERROR_CODE();
@ -1113,7 +1113,7 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t * n, Z3_bool biased) {
bool Z3_API Z3_fpa_get_numeral_exponent_int64(Z3_context c, Z3_ast t, int64_t * n, bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_int64(c, t, n, biased);
RESET_ERROR_CODE();
@ -1121,7 +1121,7 @@ extern "C" {
CHECK_VALID_AST(t, 0);
if (n == nullptr) {
SET_ERROR_CODE(Z3_INVALID_ARG, "invalid null argument");
return 0;
return false;
}
ast_manager & m = mk_c(c)->m();
mpf_manager & mpfm = mk_c(c)->fpautil().fm();
@ -1132,14 +1132,14 @@ extern "C" {
if (!is_app(e) || is_app_of(e, fid, OP_FPA_NAN) || !is_fp(c, t)) {
SET_ERROR_CODE(Z3_INVALID_ARG, "invalid expression argument, expecting a valid fp, not a NaN");
*n = 0;
return 0;
return false;
}
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, "invalid expression argument, expecting a valid fp, not a NaN");
*n = 0;
return 0;
return false;
}
unsigned ebits = val.get().get_ebits();
if (biased) {
@ -1153,11 +1153,11 @@ extern "C" {
mpfm.is_denormal(val) ? mpfm.mk_min_exp(ebits) :
mpfm.exp(val);
}
return 1;
return true;
Z3_CATCH_RETURN(0);
}
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, Z3_bool biased) {
Z3_ast Z3_API Z3_fpa_get_numeral_exponent_bv(Z3_context c, Z3_ast t, bool biased) {
Z3_TRY;
LOG_Z3_fpa_get_numeral_exponent_bv(c, t, biased);
RESET_ERROR_CODE();
@ -1232,7 +1232,7 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_nan(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_nan(c, t);
RESET_ERROR_CODE();
@ -1240,13 +1240,13 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_nan(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_inf(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_inf(c, t);
RESET_ERROR_CODE();
@ -1254,13 +1254,13 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_inf(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_zero(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_zero(c, t);
RESET_ERROR_CODE();
@ -1268,13 +1268,13 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_zero(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_normal(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_normal(c, t);
RESET_ERROR_CODE();
@ -1282,13 +1282,13 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_normal(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_subnormal(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_subnormal(c, t);
RESET_ERROR_CODE();
@ -1296,13 +1296,13 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_subnormal(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_positive(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_positive(c, t);
RESET_ERROR_CODE();
@ -1310,13 +1310,13 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_positive(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t) {
bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t) {
Z3_TRY;
LOG_Z3_fpa_is_numeral_negative(c, t);
RESET_ERROR_CODE();
@ -1324,10 +1324,10 @@ extern "C" {
fpa_util & fu = ctx->fpautil();
if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return 0;
return false;
}
return fu.is_negative(to_expr(t));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
};

View file

@ -25,7 +25,7 @@ Revision History:
extern "C" {
Z3_goal Z3_API Z3_mk_goal(Z3_context c, Z3_bool models, Z3_bool unsat_cores, Z3_bool proofs) {
Z3_goal Z3_API Z3_mk_goal(Z3_context c, bool models, bool unsat_cores, bool proofs) {
Z3_TRY;
LOG_Z3_mk_goal(c, models, unsat_cores, proofs);
RESET_ERROR_CODE();
@ -82,12 +82,12 @@ extern "C" {
Z3_CATCH;
}
Z3_bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g) {
bool Z3_API Z3_goal_inconsistent(Z3_context c, Z3_goal g) {
Z3_TRY;
LOG_Z3_goal_inconsistent(c, g);
RESET_ERROR_CODE();
return to_goal_ref(g)->inconsistent();
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
unsigned Z3_API Z3_goal_depth(Z3_context c, Z3_goal g) {
@ -136,20 +136,20 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_bool Z3_API Z3_goal_is_decided_sat(Z3_context c, Z3_goal g) {
bool Z3_API Z3_goal_is_decided_sat(Z3_context c, Z3_goal g) {
Z3_TRY;
LOG_Z3_goal_is_decided_sat(c, g);
RESET_ERROR_CODE();
return to_goal_ref(g)->is_decided_sat();
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_goal_is_decided_unsat(Z3_context c, Z3_goal g) {
bool Z3_API Z3_goal_is_decided_unsat(Z3_context c, Z3_goal g) {
Z3_TRY;
LOG_Z3_goal_is_decided_unsat(c, g);
RESET_ERROR_CODE();
return to_goal_ref(g)->is_decided_unsat();
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_model Z3_API Z3_goal_convert_model(Z3_context c, Z3_goal g, Z3_model m) {

View file

@ -33,8 +33,8 @@ extern "C" {
}
}
Z3_bool Z3_API Z3_open_log(Z3_string filename) {
Z3_bool res = Z3_TRUE;
bool Z3_API Z3_open_log(Z3_string filename) {
bool res = true;
#ifdef Z3_LOG_SYNC
#pragma omp critical (z3_log)
@ -46,7 +46,7 @@ extern "C" {
if (g_z3_log->bad() || g_z3_log->fail()) {
dealloc(g_z3_log);
g_z3_log = nullptr;
res = Z3_FALSE;
res = false;
}
else {
*g_z3_log << "V \"" << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "." << Z3_REVISION_NUMBER << " " << __DATE__ << "\"\n";

View file

@ -75,16 +75,16 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_model_has_interp(Z3_context c, Z3_model m, Z3_func_decl a) {
bool Z3_API Z3_model_has_interp(Z3_context c, Z3_model m, Z3_func_decl a) {
Z3_TRY;
LOG_Z3_model_has_interp(c, m, a);
CHECK_NON_NULL(m, 0);
if (to_model_ref(m)->has_interpretation(to_func_decl(a))) {
return Z3_TRUE;
return true;
} else {
return Z3_FALSE;
return false;
}
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_func_interp Z3_API Z3_model_get_func_interp(Z3_context c, Z3_model m, Z3_func_decl f) {
@ -157,20 +157,20 @@ extern "C" {
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) {
bool Z3_API Z3_model_eval(Z3_context c, Z3_model m, Z3_ast t, bool model_completion, Z3_ast * v) {
Z3_TRY;
LOG_Z3_model_eval(c, m, t, model_completion, v);
if (v) *v = nullptr;
RESET_ERROR_CODE();
CHECK_NON_NULL(m, Z3_FALSE);
CHECK_IS_EXPR(t, Z3_FALSE);
CHECK_NON_NULL(m, false);
CHECK_IS_EXPR(t, false);
model * _m = to_model_ref(m);
expr_ref result(mk_c(c)->m());
model::scoped_model_completion _scm(*_m, model_completion == Z3_TRUE);
model::scoped_model_completion _scm(*_m, model_completion);
result = (*_m)(to_expr(t));
mk_c(c)->save_ast_trail(result.get());
*v = of_ast(result.get());
RETURN_Z3_model_eval Z3_TRUE;
RETURN_Z3_model_eval true;
Z3_CATCH_RETURN(0);
}
@ -225,12 +225,12 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_is_as_array(c, a);
RESET_ERROR_CODE();
return a && is_expr(to_ast(a)) && is_app_of(to_expr(a), mk_c(c)->get_array_fid(), OP_AS_ARRAY);
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a) {

View file

@ -142,11 +142,11 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_numeral_ast(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_is_numeral_ast(c, a);
RESET_ERROR_CODE();
CHECK_IS_EXPR(a, Z3_FALSE);
CHECK_IS_EXPR(a, false);
expr* e = to_expr(a);
return
mk_c(c)->autil().is_numeral(e) ||
@ -154,29 +154,29 @@ extern "C" {
mk_c(c)->fpautil().is_numeral(e) ||
mk_c(c)->fpautil().is_rm_numeral(e) ||
mk_c(c)->datalog_util().is_numeral_ext(e);
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_get_numeral_rational(Z3_context c, Z3_ast a, rational& r) {
bool Z3_API Z3_get_numeral_rational(Z3_context c, Z3_ast a, rational& r) {
Z3_TRY;
// This function is not part of the public API
RESET_ERROR_CODE();
CHECK_IS_EXPR(a, Z3_FALSE);
CHECK_IS_EXPR(a, false);
expr* e = to_expr(a);
if (mk_c(c)->autil().is_numeral(e, r)) {
return Z3_TRUE;
return true;
}
unsigned bv_size;
if (mk_c(c)->bvutil().is_numeral(e, r, bv_size)) {
return Z3_TRUE;
return true;
}
uint64_t v;
if (mk_c(c)->datalog_util().is_numeral(e, v)) {
r = rational(v, rational::ui64());
return Z3_TRUE;
return true;
}
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
@ -187,8 +187,8 @@ extern "C" {
RESET_ERROR_CODE();
CHECK_IS_EXPR(a, "");
rational r;
Z3_bool ok = Z3_get_numeral_rational(c, a, r);
if (ok == Z3_TRUE) {
bool ok = Z3_get_numeral_rational(c, a, r);
if (ok) {
return mk_c(c)->mk_external_string(r.to_string());
}
else {
@ -227,6 +227,11 @@ extern "C" {
Z3_CATCH_RETURN("");
}
double Z3_API Z3_get_numeral_double(Z3_context c, Z3_ast a) {
Z3_string s = Z3_get_numeral_decimal_string(c, a, 12);
return std::stod(std::string(s));
}
Z3_string Z3_API Z3_get_numeral_decimal_string(Z3_context c, Z3_ast a, unsigned precision) {
Z3_TRY;
LOG_Z3_get_numeral_decimal_string(c, a, precision);
@ -247,8 +252,8 @@ extern "C" {
am.display_decimal(buffer, n, precision);
return mk_c(c)->mk_external_string(buffer.str());
}
Z3_bool ok = Z3_get_numeral_rational(c, a, r);
if (ok == Z3_TRUE) {
bool ok = Z3_get_numeral_rational(c, a, r);
if (ok) {
return mk_c(c)->mk_external_string(r.to_string());
}
else {
@ -258,124 +263,124 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_get_numeral_small(Z3_context c, Z3_ast a, int64_t* num, int64_t* den) {
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);
RESET_ERROR_CODE();
CHECK_IS_EXPR(a, Z3_FALSE);
CHECK_IS_EXPR(a, false);
rational r;
Z3_bool ok = Z3_get_numeral_rational(c, a, r);
if (ok == Z3_TRUE) {
bool ok = Z3_get_numeral_rational(c, a, r);
if (ok) {
rational n = numerator(r);
rational d = denominator(r);
if (n.is_int64() && d.is_int64()) {
*num = n.get_int64();
*den = d.get_int64();
return Z3_TRUE;
return true;
}
else {
return Z3_FALSE;
return false;
}
}
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_get_numeral_int(Z3_context c, Z3_ast v, int* i) {
bool Z3_API Z3_get_numeral_int(Z3_context c, Z3_ast v, int* i) {
Z3_TRY;
// This function invokes Z3_get_numeral_int64, but it is still ok to add LOG command here because it does not return a Z3 object.
LOG_Z3_get_numeral_int(c, v, i);
RESET_ERROR_CODE();
CHECK_IS_EXPR(v, Z3_FALSE);
CHECK_IS_EXPR(v, false);
if (!i) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return Z3_FALSE;
return false;
}
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;
return true;
}
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_get_numeral_uint(Z3_context c, Z3_ast v, unsigned* u) {
bool Z3_API Z3_get_numeral_uint(Z3_context c, Z3_ast v, unsigned* u) {
Z3_TRY;
// This function invokes Z3_get_numeral_uint64, but it is still ok to add LOG command here because it does not return a Z3 object.
LOG_Z3_get_numeral_uint(c, v, u);
RESET_ERROR_CODE();
CHECK_IS_EXPR(v, Z3_FALSE);
CHECK_IS_EXPR(v, false);
if (!u) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return Z3_FALSE;
return false;
}
uint64_t l;
if (Z3_get_numeral_uint64(c, v, &l) && (l <= 0xFFFFFFFF)) {
*u = static_cast<unsigned>(l);
return Z3_TRUE;
return true;
}
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_get_numeral_uint64(Z3_context c, Z3_ast v, uint64_t* u) {
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);
RESET_ERROR_CODE();
CHECK_IS_EXPR(v, Z3_FALSE);
CHECK_IS_EXPR(v, false);
if (!u) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return Z3_FALSE;
return false;
}
rational r;
Z3_bool ok = Z3_get_numeral_rational(c, v, r);
bool ok = Z3_get_numeral_rational(c, v, r);
SASSERT(u);
if (ok == Z3_TRUE && r.is_uint64()) {
if (ok && r.is_uint64()) {
*u = r.get_uint64();
return ok;
}
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_get_numeral_int64(Z3_context c, Z3_ast v, int64_t* i) {
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);
RESET_ERROR_CODE();
CHECK_IS_EXPR(v, Z3_FALSE);
CHECK_IS_EXPR(v, false);
if (!i) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return Z3_FALSE;
return false;
}
rational r;
Z3_bool ok = Z3_get_numeral_rational(c, v, r);
if (ok == Z3_TRUE && r.is_int64()) {
bool ok = Z3_get_numeral_rational(c, v, r);
if (ok && r.is_int64()) {
*i = r.get_int64();
return ok;
}
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_get_numeral_rational_int64(Z3_context c, Z3_ast v, int64_t* num, int64_t* den) {
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);
RESET_ERROR_CODE();
CHECK_IS_EXPR(v, Z3_FALSE);
CHECK_IS_EXPR(v, false);
if (!num || !den) {
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
return Z3_FALSE;
return false;
}
rational r;
Z3_bool ok = Z3_get_numeral_rational(c, v, r);
if (ok != Z3_TRUE) {
bool ok = Z3_get_numeral_rational(c, v, r);
if (ok != true) {
return ok;
}
rational n = numerator(r);
@ -385,11 +390,11 @@ extern "C" {
*den = d.get_int64();
return ok;
}
return Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return false;
Z3_CATCH_RETURN(false);
}
Z3_ast Z3_API Z3_mk_bv_numeral(Z3_context c, unsigned sz, Z3_bool const* bits) {
Z3_ast Z3_API Z3_mk_bv_numeral(Z3_context c, unsigned sz, bool const* bits) {
Z3_TRY;
LOG_Z3_mk_bv_numeral(c, sz, bits);
RESET_ERROR_CODE();

View file

@ -62,7 +62,7 @@ extern "C" {
/**
\brief Add a Boolean parameter \c k with value \c v to the parameter set \c p.
*/
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, Z3_bool v) {
void Z3_API Z3_params_set_bool(Z3_context c, Z3_params p, Z3_symbol k, bool v) {
Z3_TRY;
LOG_Z3_params_set_bool(c, p, k, v);
RESET_ERROR_CODE();

View file

@ -1,5 +1,5 @@
/*++
Copyright (c) Microsoft Corporation, Arive Gurfinkel 2017
Copyright (c) Microsoft Corporation, Arie Gurfinkel 2017
Module Name:

View file

@ -26,7 +26,7 @@ extern "C" {
Z3_ast Z3_API Z3_mk_quantifier(
Z3_context c,
Z3_bool is_forall,
bool is_forall,
unsigned weight,
unsigned num_patterns, Z3_pattern const patterns[],
unsigned num_decls, Z3_sort const sorts[],
@ -50,7 +50,7 @@ extern "C" {
Z3_ast mk_quantifier_ex_core(
Z3_context c,
Z3_bool is_forall,
bool is_forall,
unsigned weight,
Z3_symbol quantifier_id,
Z3_symbol skolem_id,
@ -109,7 +109,7 @@ extern "C" {
Z3_ast Z3_API Z3_mk_quantifier_ex(
Z3_context c,
Z3_bool is_forall,
bool is_forall,
unsigned weight,
Z3_symbol quantifier_id,
Z3_symbol skolem_id,
@ -132,7 +132,7 @@ extern "C" {
unsigned num_decls, Z3_sort const types[],
Z3_symbol const decl_names[],
Z3_ast body) {
return Z3_mk_quantifier(c, 1, weight, num_patterns, patterns, num_decls, types, decl_names, body);
return Z3_mk_quantifier(c, true, weight, num_patterns, patterns, num_decls, types, decl_names, body);
}
Z3_ast Z3_API Z3_mk_exists(Z3_context c,
@ -141,7 +141,7 @@ extern "C" {
unsigned num_decls, Z3_sort const types[],
Z3_symbol const decl_names[],
Z3_ast body) {
return Z3_mk_quantifier(c, 0, weight, num_patterns, patterns, num_decls, types, decl_names, body);
return Z3_mk_quantifier(c, false, weight, num_patterns, patterns, num_decls, types, decl_names, body);
}
Z3_ast Z3_API Z3_mk_lambda(Z3_context c,
@ -201,7 +201,7 @@ extern "C" {
Z3_ast Z3_API Z3_mk_quantifier_const_ex(Z3_context c,
Z3_bool is_forall,
bool is_forall,
unsigned weight,
Z3_symbol quantifier_id,
Z3_symbol skolem_id,
@ -283,7 +283,7 @@ extern "C" {
}
Z3_ast Z3_API Z3_mk_quantifier_const(Z3_context c,
Z3_bool is_forall,
bool is_forall,
unsigned weight,
unsigned num_bound,
Z3_app const bound[],
@ -343,28 +343,28 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_quantifier_forall(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_is_quantifier_forall(c, a);
RESET_ERROR_CODE();
return ::is_forall(to_ast(a)) ? Z3_TRUE : Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return ::is_forall(to_ast(a));
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_quantifier_exists(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_is_quantifier_exists(c, a);
RESET_ERROR_CODE();
return ::is_exists(to_ast(a)) ? Z3_TRUE : Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return ::is_exists(to_ast(a));
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a) {
bool Z3_API Z3_is_lambda(Z3_context c, Z3_ast a) {
Z3_TRY;
LOG_Z3_is_lambda(c, a);
RESET_ERROR_CODE();
return ::is_lambda(to_ast(a)) ? Z3_TRUE : Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return ::is_lambda(to_ast(a));
Z3_CATCH_RETURN(false);
}

View file

@ -214,61 +214,61 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
Z3_TRY;
LOG_Z3_rcf_lt(c, a, b);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
return rcfm(c).lt(to_rcnumeral(a), to_rcnumeral(b));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_rcf_gt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
bool Z3_API Z3_rcf_gt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
Z3_TRY;
LOG_Z3_rcf_gt(c, a, b);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
return rcfm(c).gt(to_rcnumeral(a), to_rcnumeral(b));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_rcf_le(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
bool Z3_API Z3_rcf_le(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
Z3_TRY;
LOG_Z3_rcf_le(c, a, b);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
return rcfm(c).le(to_rcnumeral(a), to_rcnumeral(b));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_rcf_ge(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
bool Z3_API Z3_rcf_ge(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
Z3_TRY;
LOG_Z3_rcf_ge(c, a, b);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
return rcfm(c).ge(to_rcnumeral(a), to_rcnumeral(b));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_rcf_eq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
bool Z3_API Z3_rcf_eq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
Z3_TRY;
LOG_Z3_rcf_eq(c, a, b);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
return rcfm(c).eq(to_rcnumeral(a), to_rcnumeral(b));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_rcf_neq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
bool Z3_API Z3_rcf_neq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
Z3_TRY;
LOG_Z3_rcf_neq(c, a, b);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
return rcfm(c).neq(to_rcnumeral(a), to_rcnumeral(b));
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, Z3_bool compact, Z3_bool html) {
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, bool compact, bool html) {
Z3_TRY;
LOG_Z3_rcf_num_to_string(c, a, compact, html);
RESET_ERROR_CODE();

View file

@ -65,40 +65,36 @@ extern "C" {
Z3_CATCH_RETURN(nullptr);
}
Z3_bool Z3_API Z3_is_seq_sort(Z3_context c, Z3_sort s) {
bool Z3_API Z3_is_seq_sort(Z3_context c, Z3_sort s) {
Z3_TRY;
LOG_Z3_is_seq_sort(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().is_seq(to_sort(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return mk_c(c)->sutil().is_seq(to_sort(s));
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_is_re_sort(Z3_context c, Z3_sort s) {
bool Z3_API Z3_is_re_sort(Z3_context c, Z3_sort s) {
Z3_TRY;
LOG_Z3_is_re_sort(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().is_re(to_sort(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return mk_c(c)->sutil().is_re(to_sort(s));
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s) {
bool Z3_API Z3_is_string_sort(Z3_context c, Z3_sort s) {
Z3_TRY;
LOG_Z3_is_string_sort(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().is_string(to_sort(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return mk_c(c)->sutil().is_string(to_sort(s));
Z3_CATCH_RETURN(false);
}
Z3_bool Z3_API Z3_is_string(Z3_context c, Z3_ast s) {
bool Z3_API Z3_is_string(Z3_context c, Z3_ast s) {
Z3_TRY;
LOG_Z3_is_string(c, s);
RESET_ERROR_CODE();
bool result = mk_c(c)->sutil().str.is_string(to_expr(s));
return result?Z3_TRUE:Z3_FALSE;
Z3_CATCH_RETURN(Z3_FALSE);
return mk_c(c)->sutil().str.is_string(to_expr(s));
Z3_CATCH_RETURN(false);
}
Z3_string Z3_API Z3_get_string(Z3_context c, Z3_ast s) {

View file

@ -183,11 +183,18 @@ extern "C" {
}
else if (ext && std::string("dimacs") == ext) {
ast_manager& m = to_solver_ref(s)->get_manager();
std::stringstream err;
sat::solver solver(to_solver_ref(s)->get_params(), m.limit());
parse_dimacs(is, solver);
if (!parse_dimacs(is, err, solver)) {
SET_ERROR_CODE(Z3_PARSER_ERROR, err.str().c_str());
return;
}
sat2goal s2g;
ref<sat2goal::mc> mc;
atom2bool_var a2b(m);
for (unsigned v = 0; v < solver.num_vars(); ++v) {
a2b.insert(m.mk_const(symbol(v), m.mk_bool_sort()), v);
}
goal g(m);
s2g(solver, a2b, to_solver_ref(s)->get_params(), g, mc);
for (unsigned i = 0; i < g.size(); ++i) {

View file

@ -74,28 +74,28 @@ extern "C" {
Z3_CATCH_RETURN("");
}
Z3_bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx) {
bool Z3_API Z3_stats_is_uint(Z3_context c, Z3_stats s, unsigned idx) {
Z3_TRY;
LOG_Z3_stats_is_uint(c, s, idx);
RESET_ERROR_CODE();
if (idx >= to_stats_ref(s).size()) {
SET_ERROR_CODE(Z3_IOB, nullptr);
return Z3_FALSE;
return false;
}
return to_stats_ref(s).is_uint(idx);
Z3_CATCH_RETURN(0);
}
Z3_bool Z3_API Z3_stats_is_double(Z3_context c, Z3_stats s, unsigned idx) {
bool Z3_API Z3_stats_is_double(Z3_context c, Z3_stats s, unsigned idx) {
Z3_TRY;
LOG_Z3_stats_is_double(c, s, idx);
RESET_ERROR_CODE();
if (idx >= to_stats_ref(s).size()) {
SET_ERROR_CODE(Z3_IOB, nullptr);
return Z3_FALSE;
return false;
}
return !to_stats_ref(s).is_uint(idx);
Z3_CATCH_RETURN(Z3_FALSE);
Z3_CATCH_RETURN(false);
}
unsigned Z3_API Z3_stats_get_uint_value(Z3_context c, Z3_stats s, unsigned idx) {

View file

@ -28,6 +28,9 @@ Notes:
#include<z3.h>
#include<limits.h>
#undef min
#undef max
/**
\defgroup cppapi C++ API
@ -127,6 +130,14 @@ namespace z3 {
unsat, sat, unknown
};
enum rounding_mode {
RNA,
RNE,
RTP,
RTN,
RTZ
};
inline check_result to_check_result(Z3_lbool l) {
if (l == Z3_L_TRUE) return sat;
else if (l == Z3_L_FALSE) return unsat;
@ -137,12 +148,17 @@ namespace z3 {
/**
\brief A Context manages all other Z3 objects, global configuration options, etc.
*/
class context {
private:
bool m_enable_exceptions;
rounding_mode m_rounding_mode;
Z3_context m_ctx;
void init(config & c) {
m_ctx = Z3_mk_context_rc(c);
m_enable_exceptions = true;
m_rounding_mode = RNA;
Z3_set_error_handler(m_ctx, 0);
Z3_set_ast_print_mode(m_ctx, Z3_PRINT_SMTLIB2_COMPLIANT);
}
@ -171,7 +187,7 @@ namespace z3 {
}
/**
\brief The C++ API uses by defaults exceptions on errors.
\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 be very careful about using check_error() after calls that may result in an
@ -247,6 +263,26 @@ namespace z3 {
*/
sort array_sort(sort d, sort r);
sort array_sort(sort_vector const& d, sort r);
/**
\brief Return a floating point sort.
\c ebits is a number of exponent bits,
\c sbits is a number of significand bits,
\pre where ebits must be larger than 1 and sbits must be larger than 2.
*/
sort fpa_sort(unsigned ebits, unsigned sbits);
/**
\brief Return a FloatingPoint sort with given precision bitwidth (16, 32, 64 or 128).
*/
template<size_t precision>
sort fpa_sort();
/**
\brief Return a RoundingMode sort.
*/
sort fpa_rounding_mode();
/**
\brief Sets RoundingMode of FloatingPoints.
*/
void set_rounding_mode(rounding_mode rm);
/**
\brief Return an enumeration sort: enum_names[0], ..., enum_names[n-1].
\c cs and \c ts are output parameters. The method stores in \c cs the constants corresponding to the enumerated elements,
@ -258,7 +294,7 @@ namespace z3 {
\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.
\c projs is an output parameter. 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);
@ -278,12 +314,23 @@ namespace z3 {
func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & range);
func_decl function(char const * name, sort const & d1, sort const & d2, sort const & d3, sort const & d4, sort const & d5, sort const & range);
func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range);
func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range);
func_decl recfun(char const * name, sort const & domain, sort const & range);
func_decl recfun(char const * name, sort const & d1, sort const & d2, sort const & range);
void recdef(func_decl, expr_vector const& args, expr const& body);
expr constant(symbol const & name, sort const & s);
expr constant(char const * name, sort const & s);
expr bool_const(char const * name);
expr int_const(char const * name);
expr real_const(char const * name);
expr bv_const(char const * name, unsigned sz);
expr fpa_const(char const * name, unsigned ebits, unsigned sbits);
template<size_t precision>
expr fpa_const(char const * name);
expr bool_val(bool b);
@ -307,6 +354,9 @@ namespace z3 {
expr bv_val(char const * n, unsigned sz);
expr bv_val(unsigned n, bool const* bits);
expr fpa_val(double n);
expr fpa_val(float n);
expr string_val(char const* s);
expr string_val(std::string const& s);
@ -465,6 +515,7 @@ namespace z3 {
public:
sort(context & c):ast(c) {}
sort(context & c, Z3_sort s):ast(c, reinterpret_cast<Z3_ast>(s)) {}
sort(context & c, Z3_ast a):ast(c, a) {}
sort(sort const & s):ast(s) {}
operator Z3_sort() const { return reinterpret_cast<Z3_sort>(m_ast); }
/**
@ -523,6 +574,10 @@ namespace z3 {
\brief Return true if this sort is a Finite domain sort.
*/
bool is_finite_domain() const { return sort_kind() == Z3_FINITE_DOMAIN_SORT; }
/**
\brief Return true if this sort is a Floating point sort.
*/
bool is_fpa() const { return sort_kind() == Z3_FLOATING_POINT_SORT; }
/**
\brief Return the size of this Bit-vector sort.
@ -531,6 +586,9 @@ namespace z3 {
*/
unsigned bv_size() const { assert(is_bv()); unsigned r = Z3_get_bv_sort_size(ctx(), *this); check_error(); return r; }
unsigned fpa_ebits() const { assert(is_fpa()); unsigned r = Z3_fpa_get_ebits(ctx(), *this); check_error(); return r; }
unsigned fpa_sbits() const { assert(is_fpa()); unsigned r = Z3_fpa_get_sbits(ctx(), *this); check_error(); return r; }
/**
\brief Return the domain of this Array sort.
@ -634,7 +692,7 @@ namespace z3 {
\brief Return true if this is a regular expression.
*/
bool is_re() const { return get_sort().is_re(); }
/**
\brief Return true if this is a Finite-domain expression.
@ -644,6 +702,10 @@ namespace z3 {
*/
bool is_finite_domain() const { return get_sort().is_finite_domain(); }
/**
\brief Return true if this is a FloatingPoint expression. .
*/
bool is_fpa() const { return get_sort().is_fpa(); }
/**
\brief Return true if this expression is a numeral.
@ -657,6 +719,7 @@ namespace z3 {
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; }
bool is_numeral(std::string& s, unsigned precision) const { if (!is_numeral()) return false; s = Z3_get_numeral_decimal_string(ctx(), m_ast, precision); check_error(); return true; }
bool is_numeral(double& d) const { if (!is_numeral()) return false; d = Z3_get_numeral_double(ctx(), m_ast); check_error(); return true; }
/**
\brief Return true if this expression is an application.
*/
@ -696,29 +759,29 @@ namespace z3 {
\brief Return true if this expression is well sorted (aka type correct).
*/
bool is_well_sorted() const { bool r = Z3_is_well_sorted(ctx(), m_ast) != 0; check_error(); return r; }
/**
\brief Return string representation of numeral or algebraic number
This method assumes the expression is numeral or algebraic
\pre is_numeral() || is_algebraic()
*/
std::string get_decimal_string(int precision) const {
assert(is_numeral() || is_algebraic());
return std::string(Z3_get_numeral_decimal_string(ctx(), m_ast, precision));
}
/**
\brief Return int value of numeral, throw if result cannot fit in
machine int
It only makes sense to use this function if the caller can ensure that
the result is an integer or if exceptions are enabled.
the result is an integer or if exceptions are enabled.
If exceptions are disabled, then use the is_numeral_i function.
\pre is_numeral()
*/
int get_numeral_int() const {
int get_numeral_int() const {
int result = 0;
if (!is_numeral_i(result)) {
assert(ctx().enable_exceptions());
@ -727,13 +790,13 @@ namespace z3 {
}
return result;
}
/**
\brief Return uint value of numeral, throw if result cannot fit in
machine uint
It only makes sense to use this function if the caller can ensure that
the result is an integer or if exceptions are enabled.
the result is an integer or if exceptions are enabled.
If exceptions are disabled, then use the is_numeral_u function.
\pre is_numeral()
*/
@ -747,11 +810,11 @@ namespace z3 {
}
return result;
}
/**
\brief Return \c int64_t value of numeral, throw if result cannot fit in
\c int64_t.
\pre is_numeral()
*/
int64_t get_numeral_int64() const {
@ -764,11 +827,11 @@ namespace z3 {
}
return result;
}
/**
\brief Return \c uint64_t value of numeral, throw if result cannot fit in
\c uint64_t.
\pre is_numeral()
*/
uint64_t get_numeral_uint64() const {
@ -786,7 +849,7 @@ namespace z3 {
return Z3_get_bool_value(ctx(), m_ast);
}
expr numerator() const {
expr numerator() const {
assert(is_numeral());
Z3_ast r = Z3_get_numerator(ctx(), m_ast);
check_error();
@ -794,7 +857,7 @@ namespace z3 {
}
expr denominator() const {
expr denominator() const {
assert(is_numeral());
Z3_ast r = Z3_get_denominator(ctx(), m_ast);
check_error();
@ -803,6 +866,17 @@ namespace z3 {
operator Z3_app() const { assert(is_app()); return reinterpret_cast<Z3_app>(m_ast); }
/**
\brief Return a RoundingMode sort.
*/
sort fpa_rounding_mode() {
assert(is_fpa());
Z3_sort s = ctx().fpa_rounding_mode();
check_error();
return sort(ctx(), s);
}
/**
\brief Return the declaration associated with this application.
This method assumes the expression is an application.
@ -905,7 +979,7 @@ namespace z3 {
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);
@ -992,23 +1066,34 @@ namespace z3 {
friend expr nor(expr const& a, expr const& b);
friend expr xnor(expr const& a, expr const& b);
friend expr min(expr const& a, expr const& b);
friend expr max(expr const& a, expr const& b);
expr rotate_left(unsigned i) { Z3_ast r = Z3_mk_rotate_left(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
expr rotate_right(unsigned i) { Z3_ast r = Z3_mk_rotate_right(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
expr repeat(unsigned i) { Z3_ast r = Z3_mk_repeat(ctx(), i, *this); ctx().check_error(); return expr(ctx(), r); }
friend expr abs(expr const & a);
friend expr sqrt(expr const & a, expr const & rm);
friend expr operator~(expr const & a);
expr extract(unsigned hi, unsigned lo) const { Z3_ast r = Z3_mk_extract(ctx(), hi, lo, *this); ctx().check_error(); return expr(ctx(), r); }
expr extract(unsigned hi, unsigned lo) const { Z3_ast r = Z3_mk_extract(ctx(), hi, lo, *this); ctx().check_error(); return expr(ctx(), r); }
unsigned lo() const { assert (is_app() && Z3_get_decl_num_parameters(ctx(), decl()) == 2); return static_cast<unsigned>(Z3_get_decl_int_parameter(ctx(), decl(), 1)); }
unsigned hi() const { assert (is_app() && Z3_get_decl_num_parameters(ctx(), decl()) == 2); return static_cast<unsigned>(Z3_get_decl_int_parameter(ctx(), decl(), 0)); }
/**
\brief FloatingPoint fused multiply-add.
*/
friend expr fma(expr const& a, expr const& b, expr const& c);
/**
\brief sequence and regular expression operations.
+ 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 {
expr extract(expr const& offset, expr const& length) const {
check_context(*this, offset); check_context(offset, length);
Z3_ast r = Z3_mk_seq_extract(ctx(), *this, offset, length); check_error(); return expr(ctx(), r);
Z3_ast r = Z3_mk_seq_extract(ctx(), *this, offset, length); check_error(); return expr(ctx(), r);
}
expr replace(expr const& src, expr const& dst) const {
check_context(*this, src); check_context(src, dst);
@ -1049,19 +1134,19 @@ namespace z3 {
return expr(ctx(), r);
}
friend expr range(expr const& lo, expr const& hi);
friend expr range(expr const& lo, expr const& hi);
/**
\brief create a looping regular expression.
*/
expr loop(unsigned lo) {
Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, 0);
check_error();
return expr(ctx(), r);
Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, 0);
check_error();
return expr(ctx(), r);
}
expr loop(unsigned lo, unsigned hi) {
Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, hi);
check_error();
return expr(ctx(), r);
Z3_ast r = Z3_mk_re_loop(ctx(), m_ast, lo, hi);
check_error();
return expr(ctx(), r);
}
@ -1094,7 +1179,7 @@ namespace z3 {
inline expr implies(expr const & a, expr const & b) {
assert(a.is_bool() && b.is_bool());
assert(a.is_bool() && b.is_bool());
_Z3_MK_BIN_(a, b, Z3_mk_implies);
}
inline expr implies(expr const & a, bool b) { return implies(a, a.ctx().bool_val(b)); }
@ -1109,7 +1194,13 @@ namespace z3 {
inline expr mod(expr const & a, int b) { return mod(a, a.ctx().num_val(b, a.get_sort())); }
inline expr mod(int a, expr const & b) { return mod(b.ctx().num_val(a, b.get_sort()), b); }
inline expr rem(expr const& a, expr const& b) { _Z3_MK_BIN_(a, b, Z3_mk_rem); }
inline expr rem(expr const& a, expr const& b) {
if (a.is_fpa() && b.is_fpa()) {
_Z3_MK_BIN_(a, b, Z3_mk_fpa_rem);
} else {
_Z3_MK_BIN_(a, b, Z3_mk_rem);
}
}
inline expr rem(expr const & a, int b) { return rem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr rem(int a, expr const & b) { return rem(b.ctx().num_val(a, b.get_sort()), b); }
@ -1158,8 +1249,8 @@ namespace z3 {
a.check_error();
return expr(a.ctx(), r);
}
inline expr operator==(expr const & a, int b) { assert(a.is_arith() || a.is_bv()); return a == a.ctx().num_val(b, a.get_sort()); }
inline expr operator==(int a, expr const & b) { assert(b.is_arith() || b.is_bv()); return b.ctx().num_val(a, b.get_sort()) == b; }
inline expr operator==(expr const & a, int b) { assert(a.is_arith() || a.is_bv() || a.is_fpa()); return a == a.ctx().num_val(b, a.get_sort()); }
inline expr operator==(int a, expr const & b) { assert(b.is_arith() || b.is_bv() || b.is_fpa()); return b.ctx().num_val(a, b.get_sort()) == b; }
inline expr operator!=(expr const & a, expr const & b) {
check_context(a, b);
@ -1168,8 +1259,8 @@ namespace z3 {
a.check_error();
return expr(a.ctx(), r);
}
inline expr operator!=(expr const & a, int b) { assert(a.is_arith() || a.is_bv()); return a != a.ctx().num_val(b, a.get_sort()); }
inline expr operator!=(int a, expr const & b) { assert(b.is_arith() || b.is_bv()); return b.ctx().num_val(a, b.get_sort()) != b; }
inline expr operator!=(expr const & a, int b) { assert(a.is_arith() || a.is_bv() || a.is_fpa()); return a != a.ctx().num_val(b, a.get_sort()); }
inline expr operator!=(int a, expr const & b) { assert(b.is_arith() || b.is_bv() || b.is_fpa()); return b.ctx().num_val(a, b.get_sort()) != b; }
inline expr operator+(expr const & a, expr const & b) {
check_context(a, b);
@ -1188,6 +1279,9 @@ namespace z3 {
Z3_ast _args[2] = { a, b };
r = Z3_mk_re_union(a.ctx(), 2, _args);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_add(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1208,6 +1302,9 @@ namespace z3 {
else if (a.is_bv() && b.is_bv()) {
r = Z3_mk_bvmul(a.ctx(), a, b);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_mul(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1245,6 +1342,9 @@ namespace z3 {
else if (a.is_bv() && b.is_bv()) {
r = Z3_mk_bvsdiv(a.ctx(), a, b);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_div(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1263,6 +1363,9 @@ namespace z3 {
else if (a.is_bv()) {
r = Z3_mk_bvneg(a.ctx(), a);
}
else if (a.is_fpa()) {
r = Z3_mk_fpa_neg(a.ctx(), a);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1281,6 +1384,9 @@ namespace z3 {
else if (a.is_bv() && b.is_bv()) {
r = Z3_mk_bvsub(a.ctx(), a, b);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_sub(a.ctx(), a.ctx().fpa_rounding_mode(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1300,6 +1406,9 @@ namespace z3 {
else if (a.is_bv() && b.is_bv()) {
r = Z3_mk_bvsle(a.ctx(), a, b);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_leq(a.ctx(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1322,6 +1431,9 @@ namespace z3 {
else if (a.is_bv() && b.is_bv()) {
r = Z3_mk_bvslt(a.ctx(), a, b);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_lt(a.ctx(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1341,6 +1453,9 @@ namespace z3 {
else if (a.is_bv() && b.is_bv()) {
r = Z3_mk_bvsgt(a.ctx(), a, b);
}
else if (a.is_fpa() && b.is_fpa()) {
r = Z3_mk_fpa_gt(a.ctx(), a, b);
}
else {
// operator is not supported by given arguments.
assert(false);
@ -1366,17 +1481,72 @@ namespace z3 {
inline expr nand(expr const& a, expr const& b) { check_context(a, b); Z3_ast r = Z3_mk_bvnand(a.ctx(), a, b); return expr(a.ctx(), r); }
inline expr nor(expr const& a, expr const& b) { check_context(a, b); Z3_ast r = Z3_mk_bvnor(a.ctx(), a, b); return expr(a.ctx(), r); }
inline expr xnor(expr const& a, expr const& b) { check_context(a, b); Z3_ast r = Z3_mk_bvxnor(a.ctx(), a, b); return expr(a.ctx(), r); }
inline expr min(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r;
if (a.is_arith()) {
r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), b, a);
}
else if (a.is_bv()) {
r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), b, a);
}
else {
assert(a.is_fpa());
r = Z3_mk_fpa_min(a.ctx(), a, b);
}
return expr(a.ctx(), r);
}
inline expr max(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r;
if (a.is_arith()) {
r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, b), a, b);
}
else if (a.is_bv()) {
r = Z3_mk_ite(a.ctx(), Z3_mk_bvuge(a.ctx(), a, b), a, b);
}
else {
assert(a.is_fpa());
r = Z3_mk_fpa_max(a.ctx(), a, b);
}
return expr(a.ctx(), r);
}
inline expr abs(expr const & a) {
Z3_ast r;
if (a.is_int()) {
expr zero = a.ctx().int_val(0);
r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, zero), a, -a);
}
else if (a.is_real()) {
expr zero = a.ctx().real_val(0);
r = Z3_mk_ite(a.ctx(), Z3_mk_ge(a.ctx(), a, zero), a, -a);
}
else {
r = Z3_mk_fpa_abs(a.ctx(), a);
}
return expr(a.ctx(), r);
}
inline expr sqrt(expr const & a, expr const& rm) {
check_context(a, rm);
assert(a.is_fpa());
Z3_ast r = Z3_mk_fpa_sqrt(a.ctx(), rm, a);
return expr(a.ctx(), r);
}
inline expr operator~(expr const & a) { Z3_ast r = Z3_mk_bvnot(a.ctx(), a); return expr(a.ctx(), r); }
inline expr fma(expr const& a, expr const& b, expr const& c, expr const& rm) {
check_context(a, b); check_context(a, c); check_context(a, rm);
assert(a.is_fpa() && b.is_fpa() && c.is_fpa());
Z3_ast r = Z3_mk_fpa_fma(a.ctx(), rm, a, b, c);
a.check_error();
return expr(a.ctx(), r);
}
/**
\brief Create the if-then-else expression <tt>ite(c, t, e)</tt>
\pre c.is_bool()
*/
inline expr ite(expr const & c, expr const & t, expr const & e) {
check_context(c, t); check_context(c, e);
assert(c.is_bool());
@ -1453,45 +1623,45 @@ namespace z3 {
inline expr smod(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvsmod(a.ctx(), a, b)); }
inline expr smod(expr const & a, int b) { return smod(a, a.ctx().num_val(b, a.get_sort())); }
inline expr smod(int a, expr const & b) { return smod(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief unsigned reminder operator for bitvectors
*/
inline expr urem(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvurem(a.ctx(), a, b)); }
inline expr urem(expr const & a, int b) { return urem(a, a.ctx().num_val(b, a.get_sort())); }
inline expr urem(int a, expr const & b) { return urem(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief shift left operator for bitvectors
*/
inline expr shl(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvshl(a.ctx(), a, b)); }
inline expr shl(expr const & a, int b) { return shl(a, a.ctx().num_val(b, a.get_sort())); }
inline expr shl(int a, expr const & b) { return shl(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief logic shift right operator for bitvectors
*/
inline expr lshr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvlshr(a.ctx(), a, b)); }
inline expr lshr(expr const & a, int b) { return lshr(a, a.ctx().num_val(b, a.get_sort())); }
inline expr lshr(int a, expr const & b) { return lshr(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief arithmetic shift right operator for bitvectors
*/
inline expr ashr(expr const & a, expr const & b) { return to_expr(a.ctx(), Z3_mk_bvashr(a.ctx(), a, b)); }
inline expr ashr(expr const & a, int b) { return ashr(a, a.ctx().num_val(b, a.get_sort())); }
inline expr ashr(int a, expr const & b) { return ashr(b.ctx().num_val(a, b.get_sort()), b); }
/**
\brief Extend the given bit-vector with zeros to the (unsigned) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
*/
inline expr zext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_zero_ext(a.ctx(), i, a)); }
/**
\brief Sign-extend of the given bit-vector to the (signed) equivalent bitvector of size m+i, where m is the size of the given bit-vector.
*/
inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
template<typename T> class cast_ast;
template<> class cast_ast<ast> {
@ -1563,7 +1733,7 @@ namespace z3 {
unsigned m_index;
public:
iterator(ast_vector_tpl const* v, unsigned i): m_vector(v), m_index(i) {}
iterator(iterator& other): m_vector(other.m_vector), m_index(other.m_index) {}
iterator(iterator& other): m_vector(other.m_vector), m_index(other.m_index) {}
iterator operator=(iterator const& other) { m_vector = other.m_vector; m_index = other.m_index; return *this; }
bool operator==(iterator const& other) {
@ -1773,7 +1943,7 @@ namespace z3 {
return expr(ctx, r);
}
inline expr mk_or(expr_vector const& args) {
inline expr mk_or(expr_vector const& args) {
array<Z3_ast> _args(args);
Z3_ast r = Z3_mk_or(args.ctx(), _args.size(), _args.ptr());
args.check_error();
@ -1852,7 +2022,7 @@ namespace z3 {
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(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) {
@ -1866,9 +2036,9 @@ namespace z3 {
expr eval(expr const & n, bool model_completion=false) const {
check_context(*this, n);
Z3_ast r = 0;
Z3_bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
bool status = Z3_model_eval(ctx(), m_model, n, model_completion, &r);
check_error();
if (status == Z3_FALSE && ctx().enable_exceptions())
if (status == false && ctx().enable_exceptions())
Z3_THROW(exception("failed to evaluate expression"));
return expr(ctx(), r);
}
@ -1884,7 +2054,7 @@ namespace z3 {
}
// returns interpretation of constant declaration c.
// If c is not assigned any value in the model it returns
// If c is not assigned any value in the model it returns
// an expression with a null ast reference.
expr get_const_interp(func_decl c) const {
check_context(*this, c);
@ -1898,7 +2068,7 @@ namespace z3 {
check_error();
return func_interp(ctx(), r);
}
// returns true iff the model contains an interpretation
// for function f.
bool has_interp(func_decl f) const {
@ -1942,10 +2112,10 @@ namespace z3 {
}
unsigned size() const { return Z3_stats_size(ctx(), m_stats); }
std::string key(unsigned i) const { Z3_string s = Z3_stats_get_key(ctx(), m_stats, i); check_error(); return s; }
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; }
bool is_uint(unsigned i) const { bool r = Z3_stats_is_uint(ctx(), m_stats, i); check_error(); return r != 0; }
bool is_double(unsigned i) const { 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; }
@ -2001,7 +2171,7 @@ namespace z3 {
void add(expr const & e, char const * p) {
add(e, ctx().bool_const(p));
}
// fails for some compilers:
// fails for some compilers:
// void add(expr_vector const& v) { check_context(*this, v); for (expr e : v) add(e); }
void from_file(char const* file) { Z3_solver_from_file(ctx(), m_solver, file); ctx().check_parser_error(); }
void from_string(char const* s) { Z3_solver_from_string(ctx(), m_solver, s); ctx().check_parser_error(); }
@ -2066,11 +2236,11 @@ 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);
}
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;
@ -2118,7 +2288,7 @@ namespace z3 {
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;
};
@ -2407,7 +2577,7 @@ namespace z3 {
class optimize : public object {
Z3_optimize m_opt;
public:
class handle {
unsigned m_h;
@ -2456,16 +2626,16 @@ namespace z3 {
Z3_optimize_pop(ctx(), m_opt);
}
check_result check() { Z3_lbool r = Z3_optimize_check(ctx(), m_opt, 0, 0); check_error(); return to_check_result(r); }
check_result check(expr_vector const& asms) {
check_result check(expr_vector const& asms) {
unsigned n = asms.size();
array<Z3_ast> _asms(n);
for (unsigned i = 0; i < n; i++) {
check_context(*this, asms[i]);
_asms[i] = asms[i];
}
Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
check_error();
return to_check_result(r);
Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
check_error();
return to_check_result(r);
}
model get_model() const { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }
expr_vector unsat_core() const { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
@ -2495,25 +2665,25 @@ namespace z3 {
public:
fixedpoint(context& c):object(c) { m_fp = Z3_mk_fixedpoint(c); Z3_fixedpoint_inc_ref(c, m_fp); }
~fixedpoint() { Z3_fixedpoint_dec_ref(ctx(), m_fp); }
operator Z3_fixedpoint() const { return m_fp; }
operator Z3_fixedpoint() const { return m_fp; }
void from_string(char const* s) { Z3_fixedpoint_from_string(ctx(), m_fp, s); check_error(); }
void from_file(char const* s) { Z3_fixedpoint_from_file(ctx(), m_fp, s); check_error(); }
void add_rule(expr& rule, symbol const& name) { Z3_fixedpoint_add_rule(ctx(), m_fp, rule, name); check_error(); }
void add_fact(func_decl& f, unsigned * args) { Z3_fixedpoint_add_fact(ctx(), m_fp, f, f.arity(), args); check_error(); }
check_result query(expr& q) { Z3_lbool r = Z3_fixedpoint_query(ctx(), m_fp, q); check_error(); return to_check_result(r); }
check_result query(func_decl_vector& relations) {
check_result query(func_decl_vector& relations) {
array<Z3_func_decl> rs(relations);
Z3_lbool r = Z3_fixedpoint_query_relations(ctx(), m_fp, rs.size(), rs.ptr());
check_error();
return to_check_result(r);
Z3_lbool r = Z3_fixedpoint_query_relations(ctx(), m_fp, rs.size(), rs.ptr());
check_error();
return to_check_result(r);
}
expr get_answer() { Z3_ast r = Z3_fixedpoint_get_answer(ctx(), m_fp); check_error(); return expr(ctx(), r); }
std::string reason_unknown() { return Z3_fixedpoint_get_reason_unknown(ctx(), m_fp); }
void update_rule(expr& rule, symbol const& name) { Z3_fixedpoint_update_rule(ctx(), m_fp, rule, name); check_error(); }
unsigned get_num_levels(func_decl& p) { unsigned r = Z3_fixedpoint_get_num_levels(ctx(), m_fp, p); check_error(); return r; }
expr get_cover_delta(int level, func_decl& p) {
Z3_ast r = Z3_fixedpoint_get_cover_delta(ctx(), m_fp, level, p);
check_error();
expr get_cover_delta(int level, func_decl& p) {
Z3_ast r = Z3_fixedpoint_get_cover_delta(ctx(), m_fp, level, p);
check_error();
return expr(ctx(), r);
}
void add_cover(int level, func_decl& p, expr& property) { Z3_fixedpoint_add_cover(ctx(), m_fp, level, p, property); check_error(); }
@ -2527,7 +2697,7 @@ namespace z3 {
std::string to_string() { return Z3_fixedpoint_to_string(ctx(), m_fp, 0, 0); }
std::string to_string(expr_vector const& queries) {
array<Z3_ast> qs(queries);
return Z3_fixedpoint_to_string(ctx(), m_fp, qs.size(), qs.ptr());
return Z3_fixedpoint_to_string(ctx(), m_fp, qs.size(), qs.ptr());
}
void push() { Z3_fixedpoint_push(ctx(), m_fp); check_error(); }
void pop() { Z3_fixedpoint_pop(ctx(), m_fp); check_error(); }
@ -2562,11 +2732,37 @@ namespace z3 {
inline sort context::string_sort() { Z3_sort s = Z3_mk_string_sort(m_ctx); check_error(); return sort(*this, s); }
inline sort context::seq_sort(sort& s) { Z3_sort r = Z3_mk_seq_sort(m_ctx, s); check_error(); return sort(*this, r); }
inline sort context::re_sort(sort& s) { Z3_sort r = Z3_mk_re_sort(m_ctx, s); check_error(); return sort(*this, r); }
inline sort context::fpa_sort(unsigned ebits, unsigned sbits) { Z3_sort s = Z3_mk_fpa_sort(m_ctx, ebits, sbits); check_error(); return sort(*this, s); }
template<>
inline sort context::fpa_sort<16>() { return fpa_sort(5, 11); }
template<>
inline sort context::fpa_sort<32>() { return fpa_sort(8, 24); }
template<>
inline sort context::fpa_sort<64>() { return fpa_sort(11, 53); }
template<>
inline sort context::fpa_sort<128>() { return fpa_sort(15, 113); }
inline sort context::fpa_rounding_mode() {
switch (m_rounding_mode) {
case RNA: return sort(*this, Z3_mk_fpa_rna(m_ctx));
case RNE: return sort(*this, Z3_mk_fpa_rne(m_ctx));
case RTP: return sort(*this, Z3_mk_fpa_rtp(m_ctx));
case RTN: return sort(*this, Z3_mk_fpa_rtn(m_ctx));
case RTZ: return sort(*this, Z3_mk_fpa_rtz(m_ctx));
default: return sort(*this);
}
}
inline void context::set_rounding_mode(rounding_mode rm) { m_rounding_mode = rm; }
inline sort context::array_sort(sort d, sort r) { Z3_sort s = Z3_mk_array_sort(m_ctx, d, r); check_error(); return sort(*this, s); }
inline sort context::array_sort(sort_vector const& d, sort r) {
array<Z3_sort> dom(d);
Z3_sort s = Z3_mk_array_sort_n(m_ctx, dom.size(), dom.ptr(), r); check_error(); return sort(*this, s);
Z3_sort s = Z3_mk_array_sort_n(m_ctx, dom.size(), dom.ptr(), r); check_error(); return sort(*this, s);
}
inline sort context::enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts) {
array<Z3_symbol> _enum_names(n);
@ -2671,6 +2867,37 @@ namespace z3 {
return func_decl(*this, f);
}
inline func_decl context::recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
array<Z3_sort> args(arity);
for (unsigned i = 0; i < arity; i++) {
check_context(domain[i], range);
args[i] = domain[i];
}
Z3_func_decl f = Z3_mk_rec_func_decl(m_ctx, name, arity, args.ptr(), range);
check_error();
return func_decl(*this, f);
}
inline func_decl context::recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
return recfun(str_symbol(name), arity, domain, range);
}
inline func_decl context::recfun(char const * name, sort const& d1, sort const & range) {
return recfun(str_symbol(name), 1, &d1, range);
}
inline func_decl context::recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
sort dom[2] = { d1, d2 };
return recfun(str_symbol(name), 2, dom, range);
}
inline void context::recdef(func_decl f, expr_vector const& args, expr const& body) {
check_context(f, args); check_context(f, body);
array<Z3_ast> vars(args);
Z3_add_rec_def(f.ctx(), f, vars.size(), vars.ptr(), body);
}
inline expr context::constant(symbol const & name, sort const & s) {
Z3_ast r = Z3_mk_const(m_ctx, name, s);
check_error();
@ -2681,6 +2908,10 @@ namespace z3 {
inline expr context::int_const(char const * name) { return constant(name, int_sort()); }
inline expr context::real_const(char const * name) { return constant(name, real_sort()); }
inline expr context::bv_const(char const * name, unsigned sz) { return constant(name, bv_sort(sz)); }
inline expr context::fpa_const(char const * name, unsigned ebits, unsigned sbits) { return constant(name, fpa_sort(ebits, sbits)); }
template<size_t precision>
inline expr context::fpa_const(char const * name) { return constant(name, fpa_sort<precision>()); }
inline expr context::bool_val(bool b) { return b ? expr(*this, Z3_mk_true(m_ctx)) : expr(*this, Z3_mk_false(m_ctx)); }
@ -2702,12 +2933,15 @@ namespace z3 {
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);
inline expr context::bv_val(unsigned n, bool const* bits) {
array<bool> _bits(n);
for (unsigned i = 0; i < n; ++i) _bits[i] = bits[i] ? 1 : 0;
Z3_ast r = Z3_mk_bv_numeral(m_ctx, n, _bits.ptr()); check_error(); return expr(*this, r);
Z3_ast r = Z3_mk_bv_numeral(m_ctx, n, _bits.ptr()); check_error(); return expr(*this, r);
}
inline expr context::fpa_val(double n) { sort s = fpa_sort<64>(); Z3_ast r = Z3_mk_fpa_numeral_double(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::fpa_val(float n) { sort s = fpa_sort<32>(); Z3_ast r = Z3_mk_fpa_numeral_float(m_ctx, n, s); check_error(); return expr(*this, r); }
inline expr context::string_val(char const* s) { Z3_ast r = Z3_mk_string(m_ctx, s); check_error(); return expr(*this, r); }
inline expr context::string_val(std::string const& s) { Z3_ast r = Z3_mk_string(m_ctx, s.c_str()); check_error(); return expr(*this, r); }
@ -2825,14 +3059,27 @@ namespace z3 {
return range.ctx().function(name.c_str(), domain, range);
}
inline func_decl recfun(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
return range.ctx().recfun(name, arity, domain, range);
}
inline func_decl recfun(char const * name, unsigned arity, sort const * domain, sort const & range) {
return range.ctx().recfun(name, arity, domain, range);
}
inline func_decl recfun(char const * name, sort const& d1, sort const & range) {
return range.ctx().recfun(name, d1, range);
}
inline func_decl recfun(char const * name, sort const& d1, sort const& d2, sort const & range) {
return range.ctx().recfun(name, d1, d2, range);
}
inline expr select(expr const & a, expr const & i) {
check_context(a, i);
Z3_ast r = Z3_mk_select(a.ctx(), a, i);
a.check_error();
return expr(a.ctx(), r);
}
inline expr select(expr const & a, int i) {
return select(a, a.ctx().num_val(i, a.get_sort().array_domain()));
inline expr select(expr const & a, int i) {
return select(a, a.ctx().num_val(i, a.get_sort().array_domain()));
}
inline expr select(expr const & a, expr_vector const & i) {
check_context(a, i);
@ -2862,10 +3109,10 @@ namespace z3 {
return expr(a.ctx(), r);
}
inline expr as_array(func_decl & f) {
Z3_ast r = Z3_mk_as_array(f.ctx(), f);
f.check_error();
return expr(f.ctx(), r);
inline expr as_array(func_decl & f) {
Z3_ast r = Z3_mk_as_array(f.ctx(), f);
f.check_error();
return expr(f.ctx(), r);
}
#define MK_EXPR1(_fn, _arg) \
@ -2897,21 +3144,21 @@ namespace z3 {
inline expr set_del(expr const& s, expr const& e) {
MK_EXPR2(Z3_mk_set_del, s, e);
}
}
inline expr set_union(expr const& a, expr const& b) {
check_context(a, b);
check_context(a, b);
Z3_ast es[2] = { a, b };
Z3_ast r = Z3_mk_set_union(a.ctx(), 2, es);
a.check_error();
a.check_error();
return expr(a.ctx(), r);
}
inline expr set_intersect(expr const& a, expr const& b) {
check_context(a, b);
check_context(a, b);
Z3_ast es[2] = { a, b };
Z3_ast r = Z3_mk_set_intersect(a.ctx(), 2, es);
a.check_error();
a.check_error();
return expr(a.ctx(), r);
}
@ -2995,10 +3242,10 @@ namespace z3 {
MK_EXPR1(Z3_mk_re_complement, a);
}
inline expr range(expr const& lo, expr const& hi) {
check_context(lo, hi);
Z3_ast r = Z3_mk_re_range(lo.ctx(), lo, hi);
lo.check_error();
return expr(lo.ctx(), r);
check_context(lo, hi);
Z3_ast r = Z3_mk_re_range(lo.ctx(), lo, hi);
lo.check_error();
return expr(lo.ctx(), r);
}
@ -3009,7 +3256,7 @@ namespace z3 {
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);

View file

@ -17,17 +17,16 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// The abstract syntax tree (AST) class.
/// </summary>
[ContractVerification(true)]
public class AST : Z3Object, IComparable
{
/// <summary>
@ -114,8 +113,7 @@ namespace Microsoft.Z3
/// <returns>A copy of the AST which is associated with <paramref name="ctx"/></returns>
public AST Translate(Context ctx)
{
Contract.Requires(ctx != null);
Contract.Ensures(Contract.Result<AST>() != null);
Debug.Assert(ctx != null);
if (ReferenceEquals(Context, ctx))
return this;
@ -202,14 +200,13 @@ namespace Microsoft.Z3
/// </summary>
public string SExpr()
{
Contract.Ensures(Contract.Result<string>() != null);
return Native.Z3_ast_to_string(Context.nCtx, NativeObject);
}
#region Internal
internal AST(Context ctx) : base(ctx) { Contract.Requires(ctx != null); }
internal AST(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal AST(Context ctx) : base(ctx) { Debug.Assert(ctx != null); }
internal AST(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal class DecRefQueue : IDecRefQueue
{
@ -246,8 +243,7 @@ namespace Microsoft.Z3
internal static AST Create(Context ctx, IntPtr obj)
{
Contract.Requires(ctx != null);
Contract.Ensures(Contract.Result<AST>() != null);
Debug.Assert(ctx != null);
switch ((Z3_ast_kind)Native.Z3_get_ast_kind(ctx.nCtx, obj))
{

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Map from AST to AST
/// </summary>
[ContractVerification(true)]
internal class ASTMap : Z3Object
{
/// <summary>
@ -35,7 +34,7 @@ namespace Microsoft.Z3
/// <returns>True if <paramref name="k"/> is a key in the map, false otherwise.</returns>
public bool Contains(AST k)
{
Contract.Requires(k != null);
Debug.Assert(k != null);
return 0 != Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject);
}
@ -49,8 +48,7 @@ namespace Microsoft.Z3
/// <param name="k">An AST</param>
public AST Find(AST k)
{
Contract.Requires(k != null);
Contract.Ensures(Contract.Result<AST>() != null);
Debug.Assert(k != null);
return new AST(Context, Native.Z3_ast_map_find(Context.nCtx, NativeObject, k.NativeObject));
}
@ -62,8 +60,8 @@ namespace Microsoft.Z3
/// <param name="v">The value AST</param>
public void Insert(AST k, AST v)
{
Contract.Requires(k != null);
Contract.Requires(v != null);
Debug.Assert(k != null);
Debug.Assert(v != null);
Native.Z3_ast_map_insert(Context.nCtx, NativeObject, k.NativeObject, v.NativeObject);
}
@ -74,7 +72,7 @@ namespace Microsoft.Z3
/// <param name="k">An AST</param>
public void Erase(AST k)
{
Contract.Requires(k != null);
Debug.Assert(k != null);
Native.Z3_ast_map_erase(Context.nCtx, NativeObject, k.NativeObject);
}
@ -119,12 +117,12 @@ namespace Microsoft.Z3
internal ASTMap(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal ASTMap(Context ctx)
: base(ctx, Native.Z3_mk_ast_map(ctx.nCtx))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal class DecRefQueue : IDecRefQueue

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -45,13 +45,12 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<AST>() != null);
return new AST(Context, Native.Z3_ast_vector_get(Context.nCtx, NativeObject, i));
}
set
{
Contract.Requires(value != null);
Debug.Assert(value != null);
Native.Z3_ast_vector_set(Context.nCtx, NativeObject, i, value.NativeObject);
}
@ -73,7 +72,7 @@ namespace Microsoft.Z3
/// <param name="a">An AST</param>
public void Push(AST a)
{
Contract.Requires(a != null);
Debug.Assert(a != null);
Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
}
@ -85,8 +84,7 @@ namespace Microsoft.Z3
/// <returns>A new ASTVector</returns>
public ASTVector Translate(Context ctx)
{
Contract.Requires(ctx != null);
Contract.Ensures(Contract.Result<ASTVector>() != null);
Debug.Assert(ctx != null);
return new ASTVector(Context, Native.Z3_ast_vector_translate(Context.nCtx, NativeObject, ctx.nCtx));
}
@ -232,8 +230,8 @@ namespace Microsoft.Z3
}
#region Internal
internal ASTVector(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal ASTVector(Context ctx) : base(ctx, Native.Z3_mk_ast_vector(ctx.nCtx)) { Contract.Requires(ctx != null); }
internal ASTVector(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal ASTVector(Context ctx) : base(ctx, Native.Z3_mk_ast_vector(ctx.nCtx)) { Debug.Assert(ctx != null); }
internal class DecRefQueue : IDecRefQueue
{

View file

@ -16,8 +16,8 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
#if !FRAMEWORK_LT_4
using System.Numerics;
@ -28,7 +28,6 @@ namespace Microsoft.Z3
/// <summary>
/// Algebraic numbers
/// </summary>
[ContractVerification(true)]
public class AlgebraicNum : ArithExpr
{
/// <summary>
@ -40,7 +39,6 @@ namespace Microsoft.Z3
/// <returns>A numeral Expr of sort Real</returns>
public RatNum ToUpper(uint precision)
{
Contract.Ensures(Contract.Result<RatNum>() != null);
return new RatNum(Context, Native.Z3_get_algebraic_number_upper(Context.nCtx, NativeObject, precision));
}
@ -54,7 +52,6 @@ namespace Microsoft.Z3
/// <returns>A numeral Expr of sort Real</returns>
public RatNum ToLower(uint precision)
{
Contract.Ensures(Contract.Result<RatNum>() != null);
return new RatNum(Context, Native.Z3_get_algebraic_number_lower(Context.nCtx, NativeObject, precision));
}
@ -65,7 +62,6 @@ namespace Microsoft.Z3
/// <remarks>The result has at most <paramref name="precision"/> decimal places.</remarks>
public string ToDecimal(uint precision)
{
Contract.Ensures(Contract.Result<string>() != null);
return Native.Z3_get_numeral_decimal_string(Context.nCtx, NativeObject, precision);
}
@ -74,7 +70,7 @@ namespace Microsoft.Z3
internal AlgebraicNum(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -26,7 +26,6 @@ namespace Microsoft.Z3
/// ApplyResult objects represent the result of an application of a
/// tactic to a goal. It contains the subgoals that were produced.
/// </summary>
[ContractVerification(true)]
public class ApplyResult : Z3Object
{
/// <summary>
@ -44,8 +43,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Goal[]>() != null);
Contract.Ensures(Contract.Result<Goal[]>().Length == this.NumSubgoals);
uint n = NumSubgoals;
Goal[] res = new Goal[n];
@ -67,7 +64,7 @@ namespace Microsoft.Z3
internal ApplyResult(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal class DecRefQueue : IDecRefQueue

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -35,7 +35,7 @@ namespace Microsoft.Z3
internal ArithExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
@ -45,7 +45,7 @@ namespace Microsoft.Z3
private static ArithExpr MkNum(ArithExpr e, double d) { return (ArithExpr)e.Context.MkNumeral(d.ToString(), e.Context.MkRealSort()); }
/// <summary> Operator overloading for arithmetical divsion operator (over reals) </summary>
/// <summary> Operator overloading for arithmetical division operator (over reals) </summary>
public static ArithExpr operator /(ArithExpr a, ArithExpr b) { return a.Context.MkDiv(a, b); }
/// <summary> Operator overloading for arithmetical operator </summary>

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -28,7 +28,7 @@ namespace Microsoft.Z3
public class ArithSort : Sort
{
#region Internal
internal ArithSort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal ArithSort(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#endregion
};
}

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -35,7 +35,7 @@ namespace Microsoft.Z3
internal ArrayExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Array sorts.
/// </summary>
[ContractVerification(true)]
public class ArraySort : Sort
{
/// <summary>
@ -35,7 +34,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort>() != null);
return Sort.Create(Context, Native.Z3_get_array_sort_domain(Context.nCtx, NativeObject));
}
@ -48,27 +46,26 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort>() != null);
return Sort.Create(Context, Native.Z3_get_array_sort_range(Context.nCtx, NativeObject));
}
}
#region Internal
internal ArraySort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal ArraySort(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal ArraySort(Context ctx, Sort domain, Sort range)
: base(ctx, Native.Z3_mk_array_sort(ctx.nCtx, domain.NativeObject, range.NativeObject))
{
Contract.Requires(ctx != null);
Contract.Requires(domain != null);
Contract.Requires(range != null);
Debug.Assert(ctx != null);
Debug.Assert(domain != null);
Debug.Assert(range != null);
}
internal ArraySort(Context ctx, Sort[] domain, Sort range)
: base(ctx, Native.Z3_mk_array_sort_n(ctx.nCtx, (uint)domain.Length, AST.ArrayToNative(domain), range.NativeObject))
{
Contract.Requires(ctx != null);
Contract.Requires(domain != null);
Contract.Requires(range != null);
Debug.Assert(ctx != null);
Debug.Assert(domain != null);
Debug.Assert(range != null);
}
#endregion
};

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -41,7 +41,7 @@ namespace Microsoft.Z3
#region Internal
/// <summary> Constructor for BitVecExpr </summary>
internal BitVecExpr(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal BitVecExpr(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#endregion
}
}

View file

@ -16,8 +16,8 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
#if !FRAMEWORK_LT_4
using System.Numerics;
@ -28,7 +28,6 @@ namespace Microsoft.Z3
/// <summary>
/// Bit-vector numerals
/// </summary>
[ContractVerification(true)]
public class BitVecNum : BitVecExpr
{
/// <summary>
@ -109,7 +108,7 @@ namespace Microsoft.Z3
}
#region Internal
internal BitVecNum(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal BitVecNum(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#endregion
}
}

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -36,7 +36,7 @@ namespace Microsoft.Z3
}
#region Internal
internal BitVecSort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal BitVecSort(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#endregion
};
}

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -32,7 +32,7 @@ namespace Microsoft.Z3
{
#region Internal
/// <summary> Constructor for BoolExpr </summary>
internal BoolExpr(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal BoolExpr(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#endregion
#region Operators

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -28,8 +28,8 @@ namespace Microsoft.Z3
public class BoolSort : Sort
{
#region Internal
internal BoolSort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal BoolSort(Context ctx) : base(ctx, Native.Z3_mk_bool_sort(ctx.nCtx)) { Contract.Requires(ctx != null); }
internal BoolSort(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal BoolSort(Context ctx) : base(ctx, Native.Z3_mk_bool_sort(ctx.nCtx)) { Debug.Assert(ctx != null); }
#endregion
};
}

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Constructors are used for datatype sorts.
/// </summary>
[ContractVerification(true)]
public class Constructor : Z3Object
{
/// <summary>
@ -46,7 +45,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
@ -62,7 +60,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
@ -78,7 +75,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
@ -105,9 +101,9 @@ namespace Microsoft.Z3
Sort[] sorts, uint[] sortRefs)
: base(ctx)
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Contract.Requires(recognizer != null);
Debug.Assert(ctx != null);
Debug.Assert(name != null);
Debug.Assert(recognizer != null);
n = AST.ArrayLength(fieldNames);

View file

@ -17,12 +17,12 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -43,14 +43,14 @@ namespace Microsoft.Z3
internal ConstructorList(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal ConstructorList(Context ctx, Constructor[] constructors)
: base(ctx)
{
Contract.Requires(ctx != null);
Contract.Requires(constructors != null);
Debug.Assert(ctx != null);
Debug.Assert(constructors != null);
NativeObject = Native.Z3_mk_constructor_list(Context.nCtx, (uint)constructors.Length, Constructor.ArrayToNative(constructors));
}

File diff suppressed because it is too large Load diff

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -35,7 +35,7 @@ namespace Microsoft.Z3
internal DatatypeExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Datatype sorts.
/// </summary>
[ContractVerification(true)]
public class DatatypeSort : Sort
{
/// <summary>
@ -43,7 +42,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = NumConstructors;
FuncDecl[] res = new FuncDecl[n];
@ -60,7 +58,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = NumConstructors;
FuncDecl[] res = new FuncDecl[n];
@ -77,7 +74,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[][]>() != null);
uint n = NumConstructors;
FuncDecl[][] res = new FuncDecl[n][];
@ -95,14 +91,14 @@ namespace Microsoft.Z3
}
#region Internal
internal DatatypeSort(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal DatatypeSort(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal DatatypeSort(Context ctx, Symbol name, Constructor[] constructors)
: base(ctx, Native.Z3_mk_datatype(ctx.nCtx, name.NativeObject, (uint)constructors.Length, ArrayToNative(constructors)))
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Contract.Requires(constructors != null);
Debug.Assert(ctx != null);
Debug.Assert(name != null);
Debug.Assert(constructors != null);
}
#endregion
};

View file

@ -17,17 +17,16 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// The main interaction with Z3 happens via the Context.
/// </summary>
[ContractVerification(true)]
public class Deprecated
{

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Enumeration sorts.
/// </summary>
[ContractVerification(true)]
public class EnumSort : Sort
{
/// <summary>
@ -35,7 +34,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = Native.Z3_get_datatype_sort_num_constructors(Context.nCtx, NativeObject);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
@ -61,7 +59,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Expr[]>() != null);
FuncDecl[] cds = ConstDecls;
Expr[] t = new Expr[cds.Length];
for (uint i = 0; i < t.Length; i++)
@ -87,7 +84,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = Native.Z3_get_datatype_sort_num_constructors(Context.nCtx, NativeObject);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
@ -110,9 +106,9 @@ namespace Microsoft.Z3
internal EnumSort(Context ctx, Symbol name, Symbol[] enumNames)
: base(ctx, IntPtr.Zero)
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Contract.Requires(enumNames != null);
Debug.Assert(ctx != null);
Debug.Assert(name != null);
Debug.Assert(enumNames != null);
int n = enumNames.Length;
IntPtr[] n_constdecls = new IntPtr[n];

View file

@ -17,15 +17,16 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
using System.Linq;
namespace Microsoft.Z3
{
/// <summary>
/// Expressions are terms.
/// </summary>
[ContractVerification(true)]
public class Expr : AST
{
/// <summary>
@ -35,7 +36,6 @@ namespace Microsoft.Z3
/// <seealso cref="Context.SimplifyHelp"/>
public Expr Simplify(Params p = null)
{
Contract.Ensures(Contract.Result<Expr>() != null);
if (p == null)
return Expr.Create(Context, Native.Z3_simplify(Context.nCtx, NativeObject));
@ -50,7 +50,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_app_decl(Context.nCtx, NativeObject));
}
}
@ -79,7 +78,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Expr[]>() != null);
uint n = NumArgs;
Expr[] res = new Expr[n];
@ -94,7 +92,6 @@ namespace Microsoft.Z3
/// </summary>
public Expr Arg(uint i)
{
Contract.Ensures(Contract.Result<Expr>() != null);
return Expr.Create(Context, Native.Z3_get_app_arg(Context.nCtx, NativeObject, i));
}
@ -104,8 +101,8 @@ namespace Microsoft.Z3
/// </summary>
public void Update(Expr[] args)
{
Contract.Requires(args != null);
Contract.Requires(Contract.ForAll(args, a => a != null));
Debug.Assert(args != null);
Debug.Assert(args.All(a => a != null));
Context.CheckContextMatch<Expr>(args);
if (IsApp && args.Length != NumArgs)
@ -123,11 +120,10 @@ namespace Microsoft.Z3
/// </remarks>
public Expr Substitute(Expr[] from, Expr[] to)
{
Contract.Requires(from != null);
Contract.Requires(to != null);
Contract.Requires(Contract.ForAll(from, f => f != null));
Contract.Requires(Contract.ForAll(to, t => t != null));
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(from != null);
Debug.Assert(to != null);
Debug.Assert(from.All(f => f != null));
Debug.Assert(to.All(t => t != null));
Context.CheckContextMatch<Expr>(from);
Context.CheckContextMatch<Expr>(to);
@ -142,9 +138,8 @@ namespace Microsoft.Z3
/// <seealso cref="Substitute(Expr[],Expr[])"/>
public Expr Substitute(Expr from, Expr to)
{
Contract.Requires(from != null);
Contract.Requires(to != null);
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(from != null);
Debug.Assert(to != null);
return Substitute(new Expr[] { from }, new Expr[] { to });
}
@ -157,9 +152,8 @@ namespace Microsoft.Z3
/// </remarks>
public Expr SubstituteVars(Expr[] to)
{
Contract.Requires(to != null);
Contract.Requires(Contract.ForAll(to, t => t != null));
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(to != null);
Debug.Assert(to.All(t => t != null));
Context.CheckContextMatch<Expr>(to);
return Expr.Create(Context, Native.Z3_substitute_vars(Context.nCtx, NativeObject, (uint)to.Length, Expr.ArrayToNative(to)));
@ -207,7 +201,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort>() != null);
return Sort.Create(Context, Native.Z3_get_sort(Context.nCtx, NativeObject));
}
}
@ -332,7 +325,7 @@ namespace Microsoft.Z3
/// <summary>
/// Retrieve bound of at-most
/// </summary>
public uint AtMostBound { get { Contract.Requires(IsAtMost); return (uint)FuncDecl.Parameters[0].Int; } }
public uint AtMostBound { get { Debug.Assert(IsAtMost); return (uint)FuncDecl.Parameters[0].Int; } }
/// <summary>
/// Indicates whether the term is at-least
@ -342,7 +335,7 @@ namespace Microsoft.Z3
/// <summary>
/// Retrieve bound of at-least
/// </summary>
public uint AtLeastBound { get { Contract.Requires(IsAtLeast); return (uint)FuncDecl.Parameters[0].Int; } }
public uint AtLeastBound { get { Debug.Assert(IsAtLeast); return (uint)FuncDecl.Parameters[0].Int; } }
/// <summary>
/// Indicates whether the term is pbeq
@ -842,7 +835,7 @@ namespace Microsoft.Z3
public string String { get { return Native.Z3_get_string(Context.nCtx, NativeObject); } }
/// <summary>
/// Check whether expression is a concatentation.
/// Check whether expression is a concatenation.
/// </summary>
/// <returns>a Boolean</returns>
public bool IsConcat { get { return IsApp && FuncDecl.DeclKind == Z3_decl_kind.Z3_OP_SEQ_CONCAT; } }
@ -1816,8 +1809,6 @@ namespace Microsoft.Z3
if (!IsVar)
throw new Z3Exception("Term is not a bound variable.");
Contract.EndContractBlock();
return Native.Z3_get_index_value(Context.nCtx, NativeObject);
}
}
@ -1827,10 +1818,9 @@ namespace Microsoft.Z3
/// <summary>
/// Constructor for Expr
/// </summary>
internal protected Expr(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal protected Expr(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#if DEBUG
[Pure]
internal override void CheckNativeObject(IntPtr obj)
{
if (Native.Z3_is_app(Context.nCtx, obj) == 0 &&
@ -1841,12 +1831,10 @@ namespace Microsoft.Z3
}
#endif
[Pure]
internal static Expr Create(Context ctx, FuncDecl f, params Expr[] arguments)
{
Contract.Requires(ctx != null);
Contract.Requires(f != null);
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(ctx != null);
Debug.Assert(f != null);
IntPtr obj = Native.Z3_mk_app(ctx.nCtx, f.NativeObject,
AST.ArrayLength(arguments),
@ -1854,11 +1842,9 @@ namespace Microsoft.Z3
return Create(ctx, obj);
}
[Pure]
new internal static Expr Create(Context ctx, IntPtr obj)
{
Contract.Requires(ctx != null);
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(ctx != null);
Z3_ast_kind k = (Z3_ast_kind)Native.Z3_get_ast_kind(ctx.nCtx, obj);
if (k == Z3_ast_kind.Z3_QUANTIFIER_AST)

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -45,7 +45,7 @@ namespace Microsoft.Z3
internal FPExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -16,15 +16,14 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// FloatiungPoint Numerals
/// </summary>
[ContractVerification(true)]
public class FPNum : FPExpr
{
/// <summary>
@ -175,7 +174,7 @@ namespace Microsoft.Z3
internal FPNum(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -35,7 +35,7 @@ namespace Microsoft.Z3
internal FPRMExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -93,7 +93,7 @@ namespace Microsoft.Z3
internal FPRMNum(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -31,12 +31,12 @@ namespace Microsoft.Z3
internal FPRMSort(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal FPRMSort(Context ctx)
: base(ctx, Native.Z3_mk_fpa_rounding_mode_sort(ctx.nCtx))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -16,8 +16,8 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -40,12 +40,12 @@ namespace Microsoft.Z3
internal FPSort(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal FPSort(Context ctx, uint ebits, uint sbits)
: base(ctx, Native.Z3_mk_fpa_sort(ctx.nCtx, ebits, sbits))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -16,8 +16,8 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -31,7 +31,7 @@ namespace Microsoft.Z3
internal FiniteDomainExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -16,8 +16,8 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
#if !FRAMEWORK_LT_4
using System.Numerics;
@ -28,7 +28,6 @@ namespace Microsoft.Z3
/// <summary>
/// Finite-domain numerals
/// </summary>
[ContractVerification(true)]
public class FiniteDomainNum : FiniteDomainExpr
{
/// <summary>
@ -109,7 +108,7 @@ namespace Microsoft.Z3
}
#region Internal
internal FiniteDomainNum(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal FiniteDomainNum(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#endregion
}
}

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Finite domain sorts.
/// </summary>
[ContractVerification(true)]
public class FiniteDomainSort : Sort
{
/// <summary>
@ -45,13 +44,13 @@ namespace Microsoft.Z3
internal FiniteDomainSort(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal FiniteDomainSort(Context ctx, Symbol name, ulong size)
: base(ctx, Native.Z3_mk_finite_domain_sort(ctx.nCtx, name.NativeObject, size))
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Debug.Assert(ctx != null);
Debug.Assert(name != null);
}
#endregion

View file

@ -18,14 +18,14 @@ Notes:
--*/
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
namespace Microsoft.Z3
{
/// <summary>
/// Object for managing fixedpoints
/// </summary>
[ContractVerification(true)]
public class Fixedpoint : Z3Object
{
@ -36,7 +36,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<string>() != null);
return Native.Z3_fixedpoint_get_help(Context.nCtx, NativeObject);
}
}
@ -48,7 +47,7 @@ namespace Microsoft.Z3
{
set
{
Contract.Requires(value != null);
Debug.Assert(value != null);
Context.CheckContextMatch(value);
Native.Z3_fixedpoint_set_params(Context.nCtx, NativeObject, value.NativeObject);
}
@ -68,8 +67,8 @@ namespace Microsoft.Z3
/// </summary>
public void Assert(params BoolExpr[] constraints)
{
Contract.Requires(constraints != null);
Contract.Requires(Contract.ForAll(constraints, c => c != null));
Debug.Assert(constraints != null);
Debug.Assert(constraints.All(c => c != null));
Context.CheckContextMatch<BoolExpr>(constraints);
foreach (BoolExpr a in constraints)
@ -91,7 +90,7 @@ namespace Microsoft.Z3
/// </summary>
public void RegisterRelation(FuncDecl f)
{
Contract.Requires(f != null);
Debug.Assert(f != null);
Context.CheckContextMatch(f);
Native.Z3_fixedpoint_register_relation(Context.nCtx, NativeObject, f.NativeObject);
@ -102,7 +101,7 @@ namespace Microsoft.Z3
/// </summary>
public void AddRule(BoolExpr rule, Symbol name = null)
{
Contract.Requires(rule != null);
Debug.Assert(rule != null);
Context.CheckContextMatch(rule);
Native.Z3_fixedpoint_add_rule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name));
@ -113,8 +112,8 @@ namespace Microsoft.Z3
/// </summary>
public void AddFact(FuncDecl pred, params uint[] args)
{
Contract.Requires(pred != null);
Contract.Requires(args != null);
Debug.Assert(pred != null);
Debug.Assert(args != null);
Context.CheckContextMatch(pred);
Native.Z3_fixedpoint_add_fact(Context.nCtx, NativeObject, pred.NativeObject, (uint)args.Length, args);
@ -128,7 +127,7 @@ namespace Microsoft.Z3
/// </summary>
public Status Query(BoolExpr query)
{
Contract.Requires(query != null);
Debug.Assert(query != null);
Context.CheckContextMatch(query);
Z3_lbool r = (Z3_lbool)Native.Z3_fixedpoint_query(Context.nCtx, NativeObject, query.NativeObject);
@ -148,8 +147,8 @@ namespace Microsoft.Z3
/// </summary>
public Status Query(params FuncDecl[] relations)
{
Contract.Requires(relations != null);
Contract.Requires(Contract.ForAll(0, relations.Length, i => relations[i] != null));
Debug.Assert(relations != null);
Debug.Assert(relations.All(rel => rel != null));
Context.CheckContextMatch<FuncDecl>(relations);
Z3_lbool r = (Z3_lbool)Native.Z3_fixedpoint_query_relations(Context.nCtx, NativeObject,
@ -187,7 +186,7 @@ namespace Microsoft.Z3
/// </summary>
public void UpdateRule(BoolExpr rule, Symbol name)
{
Contract.Requires(rule != null);
Debug.Assert(rule != null);
Context.CheckContextMatch(rule);
Native.Z3_fixedpoint_update_rule(Context.nCtx, NativeObject, rule.NativeObject, AST.GetNativeObject(name));
@ -208,7 +207,6 @@ namespace Microsoft.Z3
/// </summary>
public string GetReasonUnknown()
{
Contract.Ensures(Contract.Result<string>() != null);
return Native.Z3_fixedpoint_get_reason_unknown(Context.nCtx, NativeObject);
}
@ -252,7 +250,7 @@ namespace Microsoft.Z3
/// </summary>
public void SetPredicateRepresentation(FuncDecl f, Symbol[] kinds)
{
Contract.Requires(f != null);
Debug.Assert(f != null);
Native.Z3_fixedpoint_set_predicate_representation(Context.nCtx, NativeObject,
f.NativeObject, AST.ArrayLength(kinds), Symbol.ArrayToNative(kinds));
@ -276,7 +274,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector av = new ASTVector(Context, Native.Z3_fixedpoint_get_rules(Context.nCtx, NativeObject));
return av.ToBoolExprArray();
@ -290,7 +287,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
ASTVector av = new ASTVector(Context, Native.Z3_fixedpoint_get_assertions(Context.nCtx, NativeObject));
return av.ToBoolExprArray();
@ -304,7 +300,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Statistics>() != null);
return new Statistics(Context, Native.Z3_fixedpoint_get_statistics(Context.nCtx, NativeObject));
}
@ -335,12 +330,12 @@ namespace Microsoft.Z3
internal Fixedpoint(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal Fixedpoint(Context ctx)
: base(ctx, Native.Z3_mk_fixedpoint(ctx.nCtx))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal class DecRefQueue : IDecRefQueue

View file

@ -18,14 +18,15 @@ Notes:
--*/
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
namespace Microsoft.Z3
{
/// <summary>
/// Function declarations.
/// </summary>
[ContractVerification(true)]
public class FuncDecl : AST
{
/// <summary>
@ -108,7 +109,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort[]>() != null);
uint n = DomainSize;
@ -126,7 +126,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort>() != null);
return Sort.Create(Context, Native.Z3_get_range(Context.nCtx, NativeObject));
}
}
@ -146,7 +145,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Symbol>() != null);
return Symbol.Create(Context, Native.Z3_get_decl_name(Context.nCtx, NativeObject));
}
}
@ -166,7 +164,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Parameter[]>() != null);
uint num = NumParameters;
Parameter[] res = new Parameter[num];
@ -287,24 +284,33 @@ namespace Microsoft.Z3
internal FuncDecl(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range)
: base(ctx, Native.Z3_mk_func_decl(ctx.nCtx, name.NativeObject, AST.ArrayLength(domain), AST.ArrayToNative(domain), range.NativeObject))
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Contract.Requires(range != null);
Debug.Assert(ctx != null);
Debug.Assert(name != null);
Debug.Assert(range != null);
}
internal FuncDecl(Context ctx, string prefix, Sort[] domain, Sort range)
: base(ctx, Native.Z3_mk_fresh_func_decl(ctx.nCtx, prefix, AST.ArrayLength(domain), AST.ArrayToNative(domain), range.NativeObject))
{
Contract.Requires(ctx != null);
Contract.Requires(range != null);
Debug.Assert(ctx != null);
Debug.Assert(range != null);
}
internal FuncDecl(Context ctx, Symbol name, Sort[] domain, Sort range, bool is_rec)
: base(ctx, Native.Z3_mk_rec_func_decl(ctx.nCtx, name.NativeObject, AST.ArrayLength(domain), AST.ArrayToNative(domain), range.NativeObject))
{
Debug.Assert(ctx != null);
Debug.Assert(name != null);
Debug.Assert(range != null);
}
#if DEBUG
internal override void CheckNativeObject(IntPtr obj)
{
@ -335,7 +341,7 @@ namespace Microsoft.Z3
{
get
{
Contract.Requires(args == null || Contract.ForAll(args, a => a != null));
Debug.Assert(args == null || args.All(a => a != null));
return Apply(args);
}
@ -348,7 +354,7 @@ namespace Microsoft.Z3
/// <returns></returns>
public Expr Apply(params Expr[] args)
{
Contract.Requires(args == null || Contract.ForAll(args, a => a != null));
Debug.Assert(args == null || args.All(a => a != null));
Context.CheckContextMatch<Expr>(args);
return Expr.Create(Context, this, args);

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -26,7 +26,6 @@ namespace Microsoft.Z3
/// A function interpretation is represented as a finite map and an 'else' value.
/// Each entry in the finite map represents the value of a function given a set of arguments.
/// </summary>
[ContractVerification(true)]
public class FuncInterp : Z3Object
{
/// <summary>
@ -42,7 +41,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Expr>() != null);
return Expr.Create(Context, Native.Z3_func_entry_get_value(Context.nCtx, NativeObject));
}
}
@ -62,8 +60,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Expr[]>() != null);
Contract.Ensures(Contract.Result<Expr[]>().Length == this.NumArgs);
uint n = NumArgs;
Expr[] res = new Expr[n];
@ -87,7 +83,7 @@ namespace Microsoft.Z3
}
#region Internal
internal Entry(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal Entry(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal class DecRefQueue : IDecRefQueue
{
@ -133,8 +129,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Entry[]>() != null);
Contract.Ensures(Contract.ForAll(0, Contract.Result<Entry[]>().Length, j => Contract.Result<Entry[]>()[j] != null));
uint n = NumEntries;
Entry[] res = new Entry[n];
@ -151,7 +145,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Expr>() != null);
return Expr.Create(Context, Native.Z3_func_interp_get_else(Context.nCtx, NativeObject));
}
@ -194,7 +187,7 @@ namespace Microsoft.Z3
internal FuncInterp(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal class DecRefQueue : IDecRefQueue

View file

@ -17,9 +17,9 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Runtime.InteropServices;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{

View file

@ -18,7 +18,8 @@ Notes:
--*/
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
namespace Microsoft.Z3
{
@ -27,7 +28,6 @@ namespace Microsoft.Z3
/// of formulas, that can be solved and/or transformed using
/// tactics and solvers.
/// </summary>
[ContractVerification(true)]
public class Goal : Z3Object
{
/// <summary>
@ -79,13 +79,13 @@ namespace Microsoft.Z3
/// </summary>
public void Assert(params BoolExpr[] constraints)
{
Contract.Requires(constraints != null);
Contract.Requires(Contract.ForAll(constraints, c => c != null));
Debug.Assert(constraints != null);
Debug.Assert(constraints.All(c => c != null));
Context.CheckContextMatch<BoolExpr>(constraints);
foreach (BoolExpr c in constraints)
{
Contract.Assert(c != null); // It was an assume, now made an assert just to be sure we do not regress
Debug.Assert(c != null); // It was an assume, now made an assert just to be sure we do not regress
Native.Z3_goal_assert(Context.nCtx, NativeObject, c.NativeObject);
}
}
@ -140,7 +140,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<BoolExpr[]>() != null);
uint n = Size;
BoolExpr[] res = new BoolExpr[n];
@ -181,7 +180,6 @@ namespace Microsoft.Z3
/// <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
@ -194,7 +192,7 @@ namespace Microsoft.Z3
/// </summary>
public Goal Translate(Context ctx)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
return new Goal(ctx, Native.Z3_goal_translate(Context.nCtx, NativeObject, ctx.nCtx));
}
@ -248,12 +246,12 @@ namespace Microsoft.Z3
}
#region Internal
internal Goal(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal Goal(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
internal Goal(Context ctx, bool models, bool unsatCores, bool proofs)
: base(ctx, Native.Z3_mk_goal(ctx.nCtx, (byte)(models ? 1 : 0), (byte)(unsatCores ? 1 : 0), (byte)(proofs ? 1 : 0)))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal class DecRefQueue : IDecRefQueue

View file

@ -17,26 +17,24 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// DecRefQueue interface
/// </summary>
[ContractClass(typeof(DecRefQueueContracts))]
public abstract class IDecRefQueue
{
#region Object invariant
[ContractInvariantMethod]
private void ObjectInvariant()
{
Contract.Invariant(this.m_queue != null);
Debug.Assert(this.m_queue != null);
}
#endregion
@ -61,7 +59,7 @@ namespace Microsoft.Z3
internal void IncAndClear(Context ctx, IntPtr o)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
IncRef(ctx, o);
if (m_queue.Count >= m_move_limit) Clear(ctx);
@ -79,7 +77,7 @@ namespace Microsoft.Z3
internal void Clear(Context ctx)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
lock (m_lock)
{
@ -90,17 +88,16 @@ namespace Microsoft.Z3
}
}
[ContractClassFor(typeof(IDecRefQueue))]
abstract class DecRefQueueContracts : IDecRefQueue
{
internal override void IncRef(Context ctx, IntPtr obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal override void DecRef(Context ctx, IntPtr obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
}
}

View file

@ -16,12 +16,12 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -35,7 +35,7 @@ namespace Microsoft.Z3
internal IntExpr(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -16,8 +16,8 @@ Author:
Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
#if !FRAMEWORK_LT_4
using System.Numerics;
@ -28,7 +28,6 @@ namespace Microsoft.Z3
/// <summary>
/// Integer Numerals
/// </summary>
[ContractVerification(true)]
public class IntNum : IntExpr
{
@ -36,7 +35,7 @@ namespace Microsoft.Z3
internal IntNum(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -31,12 +31,12 @@ namespace Microsoft.Z3
internal IntSort(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal IntSort(Context ctx)
: base(ctx, Native.Z3_mk_int_sort(ctx.nCtx))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#endregion
}

View file

@ -18,15 +18,14 @@ Notes:
--*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// Numbered symbols
/// </summary>
[ContractVerification(true)]
public class IntSymbol : Symbol
{
/// <summary>
@ -47,12 +46,12 @@ namespace Microsoft.Z3
internal IntSymbol(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal IntSymbol(Context ctx, int i)
: base(ctx, Native.Z3_mk_int_symbol(ctx.nCtx, i))
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
#if DEBUG

View file

@ -18,14 +18,14 @@ Notes:
--*/
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Linq;
namespace Microsoft.Z3
{
/// <summary>
/// Lambda expressions.
/// </summary>
[ContractVerification(true)]
public class Lambda : ArrayExpr
{
/// <summary>
@ -43,7 +43,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Symbol[]>() != null);
uint n = NumBound;
Symbol[] res = new Symbol[n];
@ -60,7 +59,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort[]>() != null);
uint n = NumBound;
Sort[] res = new Sort[n];
@ -77,7 +75,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<BoolExpr>() != null);
return new BoolExpr(Context, Native.Z3_get_quantifier_body(Context.nCtx, NativeObject));
}
@ -94,17 +91,16 @@ namespace Microsoft.Z3
}
#region Internal
[ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
internal Lambda(Context ctx, Sort[] sorts, Symbol[] names, Expr body)
: base(ctx, IntPtr.Zero)
{
Contract.Requires(ctx != null);
Contract.Requires(sorts != null);
Contract.Requires(names != null);
Contract.Requires(body != null);
Contract.Requires(sorts.Length == names.Length);
Contract.Requires(Contract.ForAll(sorts, s => s != null));
Contract.Requires(Contract.ForAll(names, n => n != null));
Debug.Assert(ctx != null);
Debug.Assert(sorts != null);
Debug.Assert(names != null);
Debug.Assert(body != null);
Debug.Assert(sorts.Length == names.Length);
Debug.Assert(sorts.All(s => s != null));
Debug.Assert(names.All(n => n != null));
Context.CheckContextMatch<Sort>(sorts);
Context.CheckContextMatch<Symbol>(names);
Context.CheckContextMatch(body);
@ -119,14 +115,13 @@ namespace Microsoft.Z3
}
[ContractVerification(false)] // F: Clousot ForAll decompilation gets confused below. Setting verification off until I fixed the bug
internal Lambda(Context ctx, Expr[] bound, Expr body)
: base(ctx, IntPtr.Zero)
{
Contract.Requires(ctx != null);
Contract.Requires(body != null);
Debug.Assert(ctx != null);
Debug.Assert(body != null);
Contract.Requires(bound != null && bound.Length > 0 && Contract.ForAll(bound, n => n != null));
Debug.Assert(bound != null && bound.Length > 0 && bound.All(n => n != null));
Context.CheckContextMatch<Expr>(bound);
Context.CheckContextMatch(body);
@ -137,7 +132,7 @@ namespace Microsoft.Z3
}
internal Lambda(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal Lambda(Context ctx, IntPtr obj) : base(ctx, obj) { Debug.Assert(ctx != null); }
#if DEBUG
internal override void CheckNativeObject(IntPtr obj)

View file

@ -17,15 +17,14 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
/// <summary>
/// List sorts.
/// </summary>
[ContractVerification(true)]
public class ListSort : Sort
{
/// <summary>
@ -35,7 +34,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor(Context.nCtx, NativeObject, 0));
}
}
@ -47,7 +45,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Expr>() != null);
return Context.MkApp(NilDecl);
}
}
@ -59,7 +56,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_datatype_sort_recognizer(Context.nCtx, NativeObject, 0));
}
}
@ -71,7 +67,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor(Context.nCtx, NativeObject, 1));
}
}
@ -84,7 +79,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_datatype_sort_recognizer(Context.nCtx, NativeObject, 1));
}
}
@ -96,7 +90,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor_accessor(Context.nCtx, NativeObject, 1, 0));
}
}
@ -108,7 +101,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor_accessor(Context.nCtx, NativeObject, 1, 1));
}
}
@ -117,9 +109,9 @@ namespace Microsoft.Z3
internal ListSort(Context ctx, Symbol name, Sort elemSort)
: base(ctx, IntPtr.Zero)
{
Contract.Requires(ctx != null);
Contract.Requires(name != null);
Contract.Requires(elemSort != null);
Debug.Assert(ctx != null);
Debug.Assert(name != null);
Debug.Assert(elemSort != null);
IntPtr inil = IntPtr.Zero, iisnil = IntPtr.Zero,
icons = IntPtr.Zero, iiscons = IntPtr.Zero,

View file

@ -17,8 +17,8 @@ Notes:
--*/
using System.Diagnostics;
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
@ -29,7 +29,6 @@ namespace Microsoft.Z3
/// Note that this is a global, static log and if multiple Context
/// objects are created, it logs the interaction with all of them.
/// </remarks>
[ContractVerification(true)]
public static class Log
{
private static bool m_is_open = false;
@ -59,7 +58,7 @@ namespace Microsoft.Z3
/// </summary>
public static void Append(string s)
{
Contract.Requires(isOpen());
Debug.Assert(isOpen());
if (!m_is_open)
throw new Z3Exception("Log cannot be closed.");
@ -70,7 +69,6 @@ namespace Microsoft.Z3
/// Checks whether the interaction log is opened.
/// </summary>
/// <returns>True if the interaction log is open, false otherwise.</returns>
[Pure]
public static bool isOpen()
{
return m_is_open;

View file

@ -342,6 +342,7 @@
<Compile Include="ConstructorList.cs" />
<Compile Include="DatatypeExpr.cs" />
<Compile Include="DatatypeSort.cs" />
<Compile Include="Deprecated.cs" />
<Compile Include="FiniteDomainExpr.cs" />
<Compile Include="FiniteDomainNum.cs" />
<Compile Include="FPExpr.cs" />
@ -360,11 +361,11 @@
<Compile Include="FuncDecl.cs" />
<Compile Include="FuncInterp.cs" />
<Compile Include="Goal.cs" />
<Compile Include="InterpolationContext.cs" />
<Compile Include="IntExpr.cs" />
<Compile Include="IntNum.cs" />
<Compile Include="IntSort.cs" />
<Compile Include="IntSymbol.cs" />
<Compile Include="Lambda.cs" />
<Compile Include="ListSort.cs" />
<Compile Include="Model.cs" />
<Compile Include="Optimize.cs" />

View file

@ -18,7 +18,7 @@ Notes:
--*/
using System;
using System.Diagnostics.Contracts;
using System.Diagnostics;
using System.Collections.Generic;
namespace Microsoft.Z3
@ -26,7 +26,6 @@ namespace Microsoft.Z3
/// <summary>
/// A Model contains interpretations (assignments) of constants and functions.
/// </summary>
[ContractVerification(true)]
public class Model : Z3Object
{
/// <summary>
@ -36,7 +35,7 @@ namespace Microsoft.Z3
/// <returns>An expression if the constant has an interpretation in the model, null otherwise.</returns>
public Expr ConstInterp(Expr a)
{
Contract.Requires(a != null);
Debug.Assert(a != null);
Context.CheckContextMatch(a);
return ConstInterp(a.FuncDecl);
@ -49,7 +48,7 @@ namespace Microsoft.Z3
/// <returns>An expression if the function has an interpretation in the model, null otherwise.</returns>
public Expr ConstInterp(FuncDecl f)
{
Contract.Requires(f != null);
Debug.Assert(f != null);
Context.CheckContextMatch(f);
if (f.Arity != 0 ||
@ -70,7 +69,7 @@ namespace Microsoft.Z3
/// <returns>A FunctionInterpretation if the function has an interpretation in the model, null otherwise.</returns>
public FuncInterp FuncInterp(FuncDecl f)
{
Contract.Requires(f != null);
Debug.Assert(f != null);
Context.CheckContextMatch(f);
@ -122,7 +121,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = NumConsts;
FuncDecl[] res = new FuncDecl[n];
@ -165,7 +163,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint n = NumFuncs;
FuncDecl[] res = new FuncDecl[n];
@ -182,7 +179,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
uint nFuncs = NumFuncs;
uint nConsts = NumConsts;
@ -223,8 +219,7 @@ namespace Microsoft.Z3
/// <returns>The evaluation of <paramref name="t"/> in the model.</returns>
public Expr Eval(Expr t, bool completion = false)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(t != null);
IntPtr v = IntPtr.Zero;
if (Native.Z3_model_eval(Context.nCtx, NativeObject, t.NativeObject, (byte)(completion ? 1 : 0), ref v) == (byte)0)
@ -238,12 +233,19 @@ namespace Microsoft.Z3
/// </summary>
public Expr Evaluate(Expr t, bool completion = false)
{
Contract.Requires(t != null);
Contract.Ensures(Contract.Result<Expr>() != null);
Debug.Assert(t != null);
return Eval(t, completion);
}
/// <summary>
/// Evaluate expression to a double, assuming it is a numeral already.
/// </summary>
public double Double(Expr t) {
var r = Eval(t, true);
return Native.Z3_get_numeral_double(Context.nCtx, r.NativeObject);
}
/// <summary>
/// The number of uninterpreted sorts that the model has an interpretation for.
/// </summary>
@ -263,7 +265,6 @@ namespace Microsoft.Z3
{
get
{
Contract.Ensures(Contract.Result<Sort[]>() != null);
uint n = NumSorts;
Sort[] res = new Sort[n];
@ -281,8 +282,7 @@ namespace Microsoft.Z3
/// <returns>An array of expressions, where each is an element of the universe of <paramref name="s"/></returns>
public Expr[] SortUniverse(Sort s)
{
Contract.Requires(s != null);
Contract.Ensures(Contract.Result<Expr[]>() != null);
Debug.Assert(s != null);
ASTVector av = new ASTVector(Context, Native.Z3_model_get_sort_universe(Context.nCtx, NativeObject, s.NativeObject));
return av.ToExprArray();
@ -301,7 +301,7 @@ namespace Microsoft.Z3
internal Model(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Contract.Requires(ctx != null);
Debug.Assert(ctx != null);
}
internal class DecRefQueue : IDecRefQueue

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