mirror of
https://github.com/Z3Prover/z3
synced 2025-06-19 04:13:38 +00:00
Merge branch 'unstable' into contrib
This commit is contained in:
commit
fbce816025
164 changed files with 2619 additions and 4128 deletions
|
@ -106,11 +106,11 @@ namespace api {
|
|||
m_error_handler = &default_error_handler;
|
||||
|
||||
m_basic_fid = m().get_basic_family_id();
|
||||
m_arith_fid = m().get_family_id("arith");
|
||||
m_bv_fid = m().get_family_id("bv");
|
||||
m_array_fid = m().get_family_id("array");
|
||||
m_dt_fid = m().get_family_id("datatype");
|
||||
m_datalog_fid = m().get_family_id("datalog_relation");
|
||||
m_arith_fid = m().mk_family_id("arith");
|
||||
m_bv_fid = m().mk_family_id("bv");
|
||||
m_array_fid = m().mk_family_id("array");
|
||||
m_dt_fid = m().mk_family_id("datatype");
|
||||
m_datalog_fid = m().mk_family_id("datalog_relation");
|
||||
m_dt_plugin = static_cast<datatype_decl_plugin*>(m().get_plugin(m_dt_fid));
|
||||
|
||||
if (!m_user_ref_count) {
|
||||
|
|
|
@ -55,6 +55,7 @@ namespace api {
|
|||
std::string get_last_status();
|
||||
std::string to_string(unsigned num_queries, expr*const* queries);
|
||||
void cancel() { m_context.cancel(); }
|
||||
void reset_cancel() { m_context.reset_cancel(); }
|
||||
|
||||
unsigned get_num_levels(func_decl* pred);
|
||||
expr_ref get_cover_delta(int level, func_decl* pred);
|
||||
|
|
|
@ -252,42 +252,6 @@ extern "C" {
|
|||
// ---------------
|
||||
// Support for SMTLIB2
|
||||
|
||||
class z3_context_solver : public solver_na2as {
|
||||
api::context & m_ctx;
|
||||
smt::kernel & ctx() const { return m_ctx.get_smt_kernel(); }
|
||||
public:
|
||||
virtual ~z3_context_solver() {}
|
||||
z3_context_solver(api::context& c) : m_ctx(c) {}
|
||||
virtual void init_core(ast_manager & m, symbol const & logic) {}
|
||||
virtual void collect_statistics(statistics & st) const {}
|
||||
virtual void reset_core() { ctx().reset(); }
|
||||
virtual void assert_expr(expr * t) { ctx().assert_expr(t); }
|
||||
virtual void push_core() { ctx().push(); }
|
||||
virtual void pop_core(unsigned n) { ctx().pop(n); }
|
||||
virtual lbool check_sat_core(unsigned num_assumptions, expr * const * assumptions) {
|
||||
return ctx().check(num_assumptions, assumptions);
|
||||
}
|
||||
virtual void get_unsat_core(ptr_vector<expr> & r) {
|
||||
unsigned sz = ctx().get_unsat_core_size();
|
||||
for (unsigned i = 0; i < sz; i++)
|
||||
r.push_back(ctx().get_unsat_core_expr(i));
|
||||
}
|
||||
virtual void get_model(model_ref & m) { ctx().get_model(m); }
|
||||
virtual proof * get_proof() { return ctx().get_proof(); }
|
||||
virtual std::string reason_unknown() const { return ctx().last_failure_as_string(); }
|
||||
virtual void get_labels(svector<symbol> & r) {
|
||||
buffer<symbol> tmp;
|
||||
ctx().get_relevant_labels(0, tmp);
|
||||
r.append(tmp.size(), tmp.c_ptr());
|
||||
}
|
||||
|
||||
// These are controlled by the main API
|
||||
virtual void set_cancel(bool f) { }
|
||||
void cancel() { set_cancel(true); }
|
||||
void reset_cancel() { set_cancel(false); }
|
||||
virtual void set_progress_callback(progress_callback * callback) {}
|
||||
};
|
||||
|
||||
Z3_ast parse_smtlib2_stream(bool exec, Z3_context c, std::istream& is,
|
||||
unsigned num_sorts,
|
||||
Z3_symbol const sort_names[],
|
||||
|
@ -298,9 +262,6 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
cmd_context ctx(false, &(mk_c(c)->m()));
|
||||
ctx.set_ignore_check(true);
|
||||
if (exec) {
|
||||
ctx.set_solver(alloc(z3_context_solver, *mk_c(c)));
|
||||
}
|
||||
for (unsigned i = 0; i < num_decls; ++i) {
|
||||
ctx.insert(to_symbol(decl_names[i]), to_func_decl(decls[i]));
|
||||
}
|
||||
|
@ -353,39 +314,4 @@ extern "C" {
|
|||
RETURN_Z3(r);
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_exec_smtlib2_string(Z3_context c, Z3_string str,
|
||||
unsigned num_sorts,
|
||||
Z3_symbol sort_names[],
|
||||
Z3_sort sorts[],
|
||||
unsigned num_decls,
|
||||
Z3_symbol decl_names[],
|
||||
Z3_func_decl decls[]) {
|
||||
Z3_TRY;
|
||||
cmd_context ctx(false, &(mk_c(c)->m()));
|
||||
std::string s(str);
|
||||
std::istringstream is(s);
|
||||
// No logging for this one, since it private.
|
||||
return parse_smtlib2_stream(true, c, is, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_exec_smtlib2_file(Z3_context c, Z3_string file_name,
|
||||
unsigned num_sorts,
|
||||
Z3_symbol sort_names[],
|
||||
Z3_sort sorts[],
|
||||
unsigned num_decls,
|
||||
Z3_symbol decl_names[],
|
||||
Z3_func_decl decls[]) {
|
||||
Z3_TRY;
|
||||
std::ifstream is(file_name);
|
||||
if (!is) {
|
||||
SET_ERROR_CODE(Z3_PARSER_ERROR);
|
||||
return 0;
|
||||
}
|
||||
// No logging for this one, since it private.
|
||||
return parse_smtlib2_stream(true, c, is, num_sorts, sort_names, sorts, num_decls, decl_names, decls);
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -30,19 +30,20 @@ Revision History:
|
|||
#include"scoped_timer.h"
|
||||
#include"smt_strategic_solver.h"
|
||||
#include"smt_solver.h"
|
||||
#include"smt_implied_equalities.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static void init_solver_core(Z3_context c, Z3_solver _s) {
|
||||
ast_manager & m = mk_c(c)->m();
|
||||
Z3_solver_ref * s = to_solver(_s);
|
||||
mk_c(c)->params().init_solver_params(mk_c(c)->m(), *(s->m_solver), s->m_params);
|
||||
s->m_solver->init(m, s->m_logic);
|
||||
s->m_initialized = true;
|
||||
bool proofs_enabled, models_enabled, unsat_core_enabled;
|
||||
params_ref p = s->m_params;
|
||||
mk_c(c)->params().get_solver_params(mk_c(c)->m(), p, proofs_enabled, models_enabled, unsat_core_enabled);
|
||||
s->m_solver = (*(s->m_solver_factory))(mk_c(c)->m(), p, proofs_enabled, models_enabled, unsat_core_enabled, s->m_logic);
|
||||
}
|
||||
|
||||
static void init_solver(Z3_context c, Z3_solver s) {
|
||||
if (!to_solver(s)->m_initialized)
|
||||
if (to_solver(s)->m_solver.get() == 0)
|
||||
init_solver_core(c, s);
|
||||
}
|
||||
|
||||
|
@ -50,8 +51,7 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
LOG_Z3_mk_simple_solver(c);
|
||||
RESET_ERROR_CODE();
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref);
|
||||
s->m_solver = mk_smt_solver();
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_smt_solver_factory());
|
||||
mk_c(c)->save_object(s);
|
||||
Z3_solver r = of_solver(s);
|
||||
RETURN_Z3(r);
|
||||
|
@ -62,8 +62,7 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
LOG_Z3_mk_solver(c);
|
||||
RESET_ERROR_CODE();
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref);
|
||||
s->m_solver = mk_smt_strategic_solver();
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_smt_strategic_solver_factory());
|
||||
mk_c(c)->save_object(s);
|
||||
Z3_solver r = of_solver(s);
|
||||
RETURN_Z3(r);
|
||||
|
@ -74,8 +73,7 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
LOG_Z3_mk_solver_for_logic(c, logic);
|
||||
RESET_ERROR_CODE();
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref, to_symbol(logic));
|
||||
s->m_solver = mk_smt_strategic_solver(true /* force solver to use tactics even when auto_config is disabled */);
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_smt_strategic_solver_factory(to_symbol(logic)));
|
||||
mk_c(c)->save_object(s);
|
||||
Z3_solver r = of_solver(s);
|
||||
RETURN_Z3(r);
|
||||
|
@ -86,8 +84,7 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
LOG_Z3_mk_solver_from_tactic(c, t);
|
||||
RESET_ERROR_CODE();
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref);
|
||||
s->m_solver = alloc(tactic2solver, to_tactic_ref(t));
|
||||
Z3_solver_ref * s = alloc(Z3_solver_ref, mk_tactic2solver_factory(to_tactic_ref(t)));
|
||||
mk_c(c)->save_object(s);
|
||||
Z3_solver r = of_solver(s);
|
||||
RETURN_Z3(r);
|
||||
|
@ -100,7 +97,12 @@ extern "C" {
|
|||
RESET_ERROR_CODE();
|
||||
std::ostringstream buffer;
|
||||
param_descrs descrs;
|
||||
bool initialized = to_solver(s)->m_solver.get() != 0;
|
||||
if (!initialized)
|
||||
init_solver(c, s);
|
||||
to_solver_ref(s)->collect_param_descrs(descrs);
|
||||
if (!initialized)
|
||||
to_solver(s)->m_solver = 0;
|
||||
descrs.display(buffer);
|
||||
return mk_c(c)->mk_external_string(buffer.str());
|
||||
Z3_CATCH_RETURN("");
|
||||
|
@ -112,7 +114,12 @@ extern "C" {
|
|||
RESET_ERROR_CODE();
|
||||
Z3_param_descrs_ref * d = alloc(Z3_param_descrs_ref);
|
||||
mk_c(c)->save_object(d);
|
||||
bool initialized = to_solver(s)->m_solver.get() != 0;
|
||||
if (!initialized)
|
||||
init_solver(c, s);
|
||||
to_solver_ref(s)->collect_param_descrs(d->m_descrs);
|
||||
if (!initialized)
|
||||
to_solver(s)->m_solver = 0;
|
||||
Z3_param_descrs r = of_param_descrs(d);
|
||||
RETURN_Z3(r);
|
||||
Z3_CATCH_RETURN(0);
|
||||
|
@ -122,7 +129,7 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
LOG_Z3_solver_set_params(c, s, p);
|
||||
RESET_ERROR_CODE();
|
||||
if (to_solver(s)->m_initialized) {
|
||||
if (to_solver(s)->m_solver) {
|
||||
bool old_model = to_solver(s)->m_params.get_bool("model", true);
|
||||
bool new_model = to_param_ref(p).get_bool("model", true);
|
||||
if (old_model != new_model)
|
||||
|
@ -176,8 +183,7 @@ extern "C" {
|
|||
Z3_TRY;
|
||||
LOG_Z3_solver_reset(c, s);
|
||||
RESET_ERROR_CODE();
|
||||
to_solver_ref(s)->reset();
|
||||
to_solver(s)->m_initialized = false;
|
||||
to_solver(s)->m_solver = 0;
|
||||
Z3_CATCH;
|
||||
}
|
||||
|
||||
|
@ -352,4 +358,22 @@ extern "C" {
|
|||
return mk_c(c)->mk_external_string(buffer.str());
|
||||
Z3_CATCH_RETURN("");
|
||||
}
|
||||
|
||||
|
||||
Z3_lbool Z3_API Z3_get_implied_equalities(Z3_context c,
|
||||
Z3_solver s,
|
||||
unsigned num_terms,
|
||||
Z3_ast const terms[],
|
||||
unsigned class_ids[]) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_get_implied_equalities(c, s, num_terms, terms, class_ids);
|
||||
ast_manager& m = mk_c(c)->m();
|
||||
RESET_ERROR_CODE();
|
||||
CHECK_SEARCHING(c);
|
||||
init_solver(c, s);
|
||||
lbool result = smt::implied_equalities(m, *to_solver_ref(s), num_terms, to_exprs(terms), class_ids);
|
||||
return static_cast<Z3_lbool>(result);
|
||||
Z3_CATCH_RETURN(Z3_L_UNDEF);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -22,17 +22,16 @@ Revision History:
|
|||
#include"solver.h"
|
||||
|
||||
struct Z3_solver_ref : public api::object {
|
||||
solver * m_solver;
|
||||
params_ref m_params;
|
||||
bool m_initialized;
|
||||
symbol m_logic;
|
||||
Z3_solver_ref():m_solver(0), m_initialized(false), m_logic(symbol::null) {}
|
||||
Z3_solver_ref(symbol const & logic):m_solver(0), m_initialized(false), m_logic(logic) {}
|
||||
virtual ~Z3_solver_ref() { dealloc(m_solver); }
|
||||
scoped_ptr<solver_factory> m_solver_factory;
|
||||
ref<solver> m_solver;
|
||||
params_ref m_params;
|
||||
symbol m_logic;
|
||||
Z3_solver_ref(solver_factory * f):m_solver_factory(f), m_solver(0), m_logic(symbol::null) {}
|
||||
virtual ~Z3_solver_ref() {}
|
||||
};
|
||||
|
||||
inline Z3_solver_ref * to_solver(Z3_solver s) { return reinterpret_cast<Z3_solver_ref *>(s); }
|
||||
inline Z3_solver of_solver(Z3_solver_ref * s) { return reinterpret_cast<Z3_solver>(s); }
|
||||
inline solver * to_solver_ref(Z3_solver s) { return to_solver(s)->m_solver; }
|
||||
inline solver * to_solver_ref(Z3_solver s) { return to_solver(s)->m_solver.get(); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,6 @@ Revision History:
|
|||
#include"api_log_macros.h"
|
||||
#include"api_context.h"
|
||||
#include"api_model.h"
|
||||
#include"smt_implied_equalities.h"
|
||||
#include"cancel_eh.h"
|
||||
|
||||
extern "C" {
|
||||
|
@ -112,19 +111,6 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(Z3_L_UNDEF);
|
||||
}
|
||||
|
||||
Z3_lbool Z3_API Z3_get_implied_equalities(Z3_context c,
|
||||
unsigned num_terms,
|
||||
Z3_ast const terms[],
|
||||
unsigned class_ids[]) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_get_implied_equalities(c, num_terms, terms, class_ids);
|
||||
RESET_ERROR_CODE();
|
||||
CHECK_SEARCHING(c);
|
||||
lbool result = smt::implied_equalities(mk_c(c)->get_smt_kernel(), num_terms, to_exprs(terms), class_ids);
|
||||
return static_cast<Z3_lbool>(result);
|
||||
Z3_CATCH_RETURN(Z3_L_UNDEF);
|
||||
}
|
||||
|
||||
|
||||
Z3_lbool Z3_API Z3_check_assumptions(Z3_context c,
|
||||
unsigned num_assumptions, Z3_ast const assumptions[],
|
||||
|
|
|
@ -13,7 +13,7 @@ XCDBG=-g $(CFLAGS)
|
|||
XCOPT=-ccopt -Ox -ccopt -Oy- $(CFLAGS)
|
||||
# ole32 is needed by camlidl (COM support)
|
||||
XLIB=-cclib ole32.lib
|
||||
AR=lib /nologo /LIBPATH:../../build ../../z3.lib /out:
|
||||
AR=lib /nologo /LIBPATH:../../build ../../libz3.lib /out:
|
||||
O=obj
|
||||
A=lib
|
||||
else
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
The OCaml API for Z3 was tested using OCaml 3.12.1.
|
||||
You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- To build the OCaml API for Z3:
|
||||
./build-lib.sh
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
Remark: Building the OCaml API copies some pathnames into files,
|
||||
so the OCaml API must be recompiled if the Z3 library files are moved.
|
||||
|
||||
See ../examples/ocaml/build-test.sh for an example of how to compile and link with Z3.
|
||||
|
||||
Acknowledgements:
|
||||
The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg.
|
||||
Many thanks to them!
|
||||
The OCaml API for Z3 was tested using OCaml 3.12.1.
|
||||
You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- To build the OCaml API for Z3:
|
||||
./build-lib.sh
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
Remark: Building the OCaml API copies some pathnames into files,
|
||||
so the OCaml API must be recompiled if the Z3 library files are moved.
|
||||
|
||||
See ../examples/ocaml/build-test.sh for an example of how to compile and link with Z3.
|
||||
|
||||
Acknowledgements:
|
||||
The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg.
|
||||
Many thanks to them!
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
The OCaml API for Z3 was tested using OCaml 3.12.1.
|
||||
You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- To build the OCaml API for Z3:
|
||||
./build-lib.sh
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
Remark: Building the OCaml API copies some pathnames into files,
|
||||
so the OCaml API must be recompiled if the Z3 library files are moved.
|
||||
|
||||
See ../examples/ocaml/build-test.sh for an example of how to compile and link with Z3.
|
||||
|
||||
Acknowledgements:
|
||||
The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg.
|
||||
Many thanks to them!
|
||||
The OCaml API for Z3 was tested using OCaml 3.12.1.
|
||||
You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- To build the OCaml API for Z3:
|
||||
./build-lib.sh
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
Remark: Building the OCaml API copies some pathnames into files,
|
||||
so the OCaml API must be recompiled if the Z3 library files are moved.
|
||||
|
||||
See ../examples/ocaml/build-test.sh for an example of how to compile and link with Z3.
|
||||
|
||||
Acknowledgements:
|
||||
The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg.
|
||||
Many thanks to them!
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
This directory contains scripts to build the test application using
|
||||
OCaml. You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- One must build the OCaml library before compiling the example.
|
||||
Go to directory ../ocaml
|
||||
|
||||
- Use 'build-test.sh' to build the test application using the OCaml compiler.
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
- Use 'exec.sh' to execute test_mlapi. The script sets LD_LIBRARY_PATH, and invokes test_mlapi.
|
||||
This directory contains scripts to build the test application using
|
||||
OCaml. You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- One must build the OCaml library before compiling the example.
|
||||
Go to directory ../ocaml
|
||||
|
||||
- Use 'build-test.sh' to build the test application using the OCaml compiler.
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
- Use 'exec.sh' to execute test_mlapi. The script sets LD_LIBRARY_PATH, and invokes test_mlapi.
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
This directory contains scripts to build the test application using
|
||||
OCaml. You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- One must build the OCaml library before compiling the example.
|
||||
Go to directory ../ocaml
|
||||
|
||||
- Use 'build-test.sh' to build the test application using the OCaml compiler.
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
- Use 'exec.sh' to execute test_mlapi. The script sets DYLD_LIBRARY_PATH, and invokes test_mlapi.
|
||||
This directory contains scripts to build the test application using
|
||||
OCaml. You also need CamlIDL to be able to generate the OCaml API.
|
||||
|
||||
- To download OCaml:
|
||||
http://caml.inria.fr/ocaml/
|
||||
|
||||
- To download CamlIDL:
|
||||
http://forge.ocamlcore.org/projects/camlidl/
|
||||
|
||||
- One must build the OCaml library before compiling the example.
|
||||
Go to directory ../ocaml
|
||||
|
||||
- Use 'build-test.sh' to build the test application using the OCaml compiler.
|
||||
|
||||
Remark: The OCaml and C compiler tool chains must be configured in your environment.
|
||||
|
||||
- Use 'exec.sh' to execute test_mlapi. The script sets DYLD_LIBRARY_PATH, and invokes test_mlapi.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
export LD_LIBRARY_PATH=../../lib:$LD_LIBRARY_PATH # for linux
|
||||
export DYLD_LIBRARY_PATH=../../lib:$DYLD_LIBRARY_PATH # for osx
|
||||
./test_mlapi
|
||||
#!/bin/sh
|
||||
export LD_LIBRARY_PATH=../../lib:$LD_LIBRARY_PATH # for linux
|
||||
export DYLD_LIBRARY_PATH=../../lib:$DYLD_LIBRARY_PATH # for osx
|
||||
./test_mlapi
|
||||
|
|
|
@ -229,16 +229,6 @@ and param_kind =
|
|||
| PK_OTHER
|
||||
| PK_INVALID
|
||||
|
||||
and search_failure =
|
||||
| NO_FAILURE
|
||||
| UNKNOWN
|
||||
| TIMEOUT
|
||||
| MEMOUT_WATERMARK
|
||||
| CANCELED
|
||||
| NUM_CONFLICTS
|
||||
| THEORY
|
||||
| QUANTIFIERS
|
||||
|
||||
and ast_print_mode =
|
||||
| PRINT_SMTLIB_FULL
|
||||
| PRINT_LOW_LEVEL
|
||||
|
@ -1596,6 +1586,9 @@ external stats_get_uint_value : context -> stats -> int -> int
|
|||
external stats_get_double_value : context -> stats -> int -> float
|
||||
= "camlidl_z3_Z3_stats_get_double_value"
|
||||
|
||||
external get_implied_equalities : context -> solver -> ast array -> lbool * int array
|
||||
= "camlidl_z3_Z3_get_implied_equalities"
|
||||
|
||||
|
||||
|
||||
(* Internal auxiliary functions: *)
|
||||
|
@ -3027,9 +3020,6 @@ external check : context -> lbool
|
|||
external check_assumptions : context -> ast array -> int -> ast array -> lbool * model * ast * int * ast array
|
||||
= "camlidl_z3V3_Z3_check_assumptions"
|
||||
|
||||
external get_implied_equalities : context -> ast array -> lbool * int array
|
||||
= "camlidl_z3V3_Z3_get_implied_equalities"
|
||||
|
||||
external del_model : context -> model -> unit
|
||||
= "camlidl_z3V3_Z3_del_model"
|
||||
|
||||
|
|
|
@ -229,16 +229,6 @@ and param_kind =
|
|||
| PK_OTHER
|
||||
| PK_INVALID
|
||||
|
||||
and search_failure =
|
||||
| NO_FAILURE
|
||||
| UNKNOWN
|
||||
| TIMEOUT
|
||||
| MEMOUT_WATERMARK
|
||||
| CANCELED
|
||||
| NUM_CONFLICTS
|
||||
| THEORY
|
||||
| QUANTIFIERS
|
||||
|
||||
and ast_print_mode =
|
||||
| PRINT_SMTLIB_FULL
|
||||
| PRINT_LOW_LEVEL
|
||||
|
@ -1013,37 +1003,22 @@ and goal_prec =
|
|||
- PK_INVALID invalid parameter.
|
||||
*)
|
||||
(**
|
||||
{!search_failure}
|
||||
The different kinds of search failure types.
|
||||
|
||||
- NO_FAILURE: The last search was successful
|
||||
- UNKNOWN: Undocumented failure reason
|
||||
- TIMEOUT: Timeout
|
||||
- MEMOUT_WATERMAK: Search hit a memory high-watermak limit
|
||||
- CANCELED: External cancel flag was set
|
||||
- NUM_CONFLICTS: Maximum number of conflicts was reached
|
||||
- THEORY: Theory is incomplete
|
||||
- QUANTIFIERS: Logical context contains universal quantifiers
|
||||
*)
|
||||
(**
|
||||
{!ast_print_mode}
|
||||
{!ast_print_mode}
|
||||
Z3 pretty printing modes (See {!set_ast_print_mode}).
|
||||
|
||||
- PRINT_SMTLIB_FULL: Print AST nodes in SMTLIB verbose format.
|
||||
- PRINT_LOW_LEVEL: Print AST nodes using a low-level format.
|
||||
- PRINT_SMTLIB_FULL: Print AST nodes in SMTLIB verbose format.
|
||||
- PRINT_LOW_LEVEL: Print AST nodes using a low-level format.
|
||||
- PRINT_SMTLIB_COMPLIANT: Print AST nodes in SMTLIB 1.x compliant format.
|
||||
- PRINT_SMTLIB2_COMPLIANT: Print AST nodes in SMTLIB 2.x compliant format.
|
||||
*)
|
||||
(**
|
||||
{!error_code}
|
||||
Z3 error codes
|
||||
|
||||
- OK: No error.
|
||||
- SORT_ERROR: User tried to build an invalid (type incorrect) AST.
|
||||
- IOB: Index out of bounds.
|
||||
- INVALID_ARG: Invalid argument was provided.
|
||||
- PARSER_ERROR: An error occurred when parsing a string or file.
|
||||
- NO_PARSER: Parser output is not available, that is, user didn't invoke {!parse_smtlib_string} or {!parse_smtlib_file}.
|
||||
{!error_code}
|
||||
Z3 error codes
|
||||
- OK: No error.
|
||||
- SORT_ERROR: User tried to build an invalid (type incorrect) AST.
|
||||
- IOB: Index out of bounds.
|
||||
- INVALID_ARG: Invalid argument was provided.
|
||||
- PARSER_ERROR: An error occurred when parsing a string or file.
|
||||
- NO_PARSER: Parser output is not available, that is, user didn't invoke {!parse_smtlib_string} or {!parse_smtlib_file}.
|
||||
- INVALID_PATTERN: Invalid pattern was used to build a quantifier.
|
||||
- MEMOUT_FAIL: A memory allocation failure was encountered.
|
||||
- FILE_ACCESS_ERRROR: A file could not be accessed.
|
||||
|
@ -1054,17 +1029,16 @@ and goal_prec =
|
|||
*)
|
||||
(**
|
||||
Definitions for update_api.py
|
||||
|
||||
def_Type('CONFIG', 'config', 'Config')
|
||||
def_Type('CONTEXT', 'context', 'ContextObj')
|
||||
def_Type('AST', 'ast', 'Ast')
|
||||
def_Type('APP', 'app', 'Ast')
|
||||
def_Type('SORT', 'sort', 'Sort')
|
||||
def_Type('FUNC_DECL', 'func_decl', 'FuncDecl')
|
||||
def_Type('PATTERN', 'pattern', 'Pattern')
|
||||
def_Type('MODEL', 'model', 'Model')
|
||||
def_Type('LITERALS', 'literals', 'Literals')
|
||||
def_Type('CONSTRUCTOR', 'constructor', 'Constructor')
|
||||
def_Type('CONFIG', 'config', 'Config')
|
||||
def_Type('CONTEXT', 'context', 'ContextObj')
|
||||
def_Type('AST', 'ast', 'Ast')
|
||||
def_Type('APP', 'app', 'Ast')
|
||||
def_Type('SORT', 'sort', 'Sort')
|
||||
def_Type('FUNC_DECL', 'func_decl', 'FuncDecl')
|
||||
def_Type('PATTERN', 'pattern', 'Pattern')
|
||||
def_Type('MODEL', 'model', 'Model')
|
||||
def_Type('LITERALS', 'literals', 'Literals')
|
||||
def_Type('CONSTRUCTOR', 'constructor', 'Constructor')
|
||||
def_Type('CONSTRUCTOR_LIST', 'constructor_list', 'ConstructorList')
|
||||
def_Type('THEORY', 'theory', 'ctypes.c_void_p')
|
||||
def_Type('THEORY_DATA', 'theory_data', 'ctypes.c_void_p')
|
||||
|
@ -6050,6 +6024,30 @@ external stats_get_uint_value : context -> stats -> int -> int
|
|||
external stats_get_double_value : context -> stats -> int -> float
|
||||
= "camlidl_z3_Z3_stats_get_double_value"
|
||||
|
||||
(**
|
||||
{2 {L Deprecated Constraints API}}
|
||||
*)
|
||||
(**
|
||||
Summary: Retrieve congruence class representatives for terms.
|
||||
The function can be used for relying on Z3 to identify equal terms under the current
|
||||
set of assumptions. The array of terms and array of class identifiers should have
|
||||
the same length. The class identifiers are numerals that are assigned to the same
|
||||
value for their corresponding terms if the current context forces the terms to be
|
||||
equal. You cannot deduce that terms corresponding to different numerals must be all different,
|
||||
(especially when using non-convex theories).
|
||||
All implied equalities are returned by this call.
|
||||
This means that two terms map to the same class identifier if and only if
|
||||
the current context implies that they are equal.
|
||||
A side-effect of the function is a satisfiability check on the assertions on the solver that is passed in.
|
||||
The function return L_FALSE if the current assertions are not satisfiable.
|
||||
- {b See also}: {!check_and_get_model}
|
||||
- {b See also}: {!check}
|
||||
@deprecated To be moved outside of API.
|
||||
def_API('get_implied_equalities', UINT, (_in(CONTEXT), _in(SOLVER), _in(UINT), _in_array(2, AST), _out_array(2, UINT)))
|
||||
*)
|
||||
external get_implied_equalities : context -> solver -> ast array -> lbool * int array
|
||||
= "camlidl_z3_Z3_get_implied_equalities"
|
||||
|
||||
|
||||
(**
|
||||
{2 {L Legacy V3 API}}
|
||||
|
@ -10595,32 +10593,6 @@ external check : context -> lbool
|
|||
external check_assumptions : context -> ast array -> int -> ast array -> lbool * model * ast * int * ast array
|
||||
= "camlidl_z3V3_Z3_check_assumptions"
|
||||
|
||||
(**
|
||||
Summary: Retrieve congruence class representatives for terms.
|
||||
|
||||
The function can be used for relying on Z3 to identify equal terms under the current
|
||||
set of assumptions. The array of terms and array of class identifiers should have
|
||||
the same length. The class identifiers are numerals that are assigned to the same
|
||||
value for their corresponding terms if the current context forces the terms to be
|
||||
equal. You cannot deduce that terms corresponding to different numerals must be all different,
|
||||
(especially when using non-convex theories).
|
||||
All implied equalities are returned by this call.
|
||||
This means that two terms map to the same class identifier if and only if
|
||||
the current context implies that they are equal.
|
||||
|
||||
A side-effect of the function is a satisfiability check.
|
||||
The function return L_FALSE if the current assertions are not satisfiable.
|
||||
|
||||
- {b See also}: {!check_and_get_model}
|
||||
- {b See also}: {!check}
|
||||
|
||||
@deprecated Subsumed by solver API
|
||||
|
||||
def_API('get_implied_equalities', UINT, (_in(CONTEXT), _in(UINT), _in_array(1, AST), _out_array(1, UINT)))
|
||||
*)
|
||||
external get_implied_equalities : context -> ast array -> lbool * int array
|
||||
= "camlidl_z3V3_Z3_get_implied_equalities"
|
||||
|
||||
(**
|
||||
Summary: Delete a model object.
|
||||
|
||||
|
|
|
@ -605,30 +605,7 @@ value _v1;
|
|||
return _v1;
|
||||
}
|
||||
|
||||
int camlidl_transl_table_z3_enum_8[8] = {
|
||||
Z3_NO_FAILURE,
|
||||
Z3_UNKNOWN,
|
||||
Z3_TIMEOUT,
|
||||
Z3_MEMOUT_WATERMARK,
|
||||
Z3_CANCELED,
|
||||
Z3_NUM_CONFLICTS,
|
||||
Z3_THEORY,
|
||||
Z3_QUANTIFIERS,
|
||||
};
|
||||
|
||||
void camlidl_ml2c_z3_Z3_search_failure(value _v1, Z3_search_failure * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
(*_c2) = camlidl_transl_table_z3_enum_8[Int_val(_v1)];
|
||||
}
|
||||
|
||||
value camlidl_c2ml_z3_Z3_search_failure(Z3_search_failure * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
value _v1;
|
||||
_v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_8, 8, "typedef Z3_search_failure: bad enum value");
|
||||
return _v1;
|
||||
}
|
||||
|
||||
int camlidl_transl_table_z3_enum_9[4] = {
|
||||
int camlidl_transl_table_z3_enum_8[4] = {
|
||||
Z3_PRINT_SMTLIB_FULL,
|
||||
Z3_PRINT_LOW_LEVEL,
|
||||
Z3_PRINT_SMTLIB_COMPLIANT,
|
||||
|
@ -637,7 +614,7 @@ int camlidl_transl_table_z3_enum_9[4] = {
|
|||
|
||||
void camlidl_ml2c_z3_Z3_ast_print_mode(value _v1, Z3_ast_print_mode * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
(*_c2) = camlidl_transl_table_z3_enum_9[Int_val(_v1)];
|
||||
(*_c2) = camlidl_transl_table_z3_enum_8[Int_val(_v1)];
|
||||
}
|
||||
|
||||
value camlidl_c2ml_z3_Z3_ast_print_mode(Z3_ast_print_mode * _c2, camlidl_ctx _ctx)
|
||||
|
@ -653,7 +630,7 @@ value _v1;
|
|||
return _v1;
|
||||
}
|
||||
|
||||
int camlidl_transl_table_z3_enum_10[13] = {
|
||||
int camlidl_transl_table_z3_enum_9[13] = {
|
||||
Z3_OK,
|
||||
Z3_SORT_ERROR,
|
||||
Z3_IOB,
|
||||
|
@ -671,13 +648,13 @@ int camlidl_transl_table_z3_enum_10[13] = {
|
|||
|
||||
void camlidl_ml2c_z3_Z3_error_code(value _v1, Z3_error_code * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
(*_c2) = camlidl_transl_table_z3_enum_10[Int_val(_v1)];
|
||||
(*_c2) = camlidl_transl_table_z3_enum_9[Int_val(_v1)];
|
||||
}
|
||||
|
||||
value camlidl_c2ml_z3_Z3_error_code(Z3_error_code * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
value _v1;
|
||||
_v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_10, 13, "typedef Z3_error_code: bad enum value");
|
||||
_v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_9, 13, "typedef Z3_error_code: bad enum value");
|
||||
return _v1;
|
||||
}
|
||||
|
||||
|
@ -707,7 +684,7 @@ void check_error_code (Z3_context c)
|
|||
|
||||
void* error_handler_static = NULL;
|
||||
|
||||
int camlidl_transl_table_z3_enum_11[4] = {
|
||||
int camlidl_transl_table_z3_enum_10[4] = {
|
||||
Z3_GOAL_PRECISE,
|
||||
Z3_GOAL_UNDER,
|
||||
Z3_GOAL_OVER,
|
||||
|
@ -716,7 +693,7 @@ int camlidl_transl_table_z3_enum_11[4] = {
|
|||
|
||||
void camlidl_ml2c_z3_Z3_goal_prec(value _v1, Z3_goal_prec * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
(*_c2) = camlidl_transl_table_z3_enum_11[Int_val(_v1)];
|
||||
(*_c2) = camlidl_transl_table_z3_enum_10[Int_val(_v1)];
|
||||
}
|
||||
|
||||
value camlidl_c2ml_z3_Z3_goal_prec(Z3_goal_prec * _c2, camlidl_ctx _ctx)
|
||||
|
@ -11072,7 +11049,56 @@ check_error_code(c);
|
|||
return _vres;
|
||||
}
|
||||
|
||||
void caml_z3_error_handler(Z3_context c, Z3_error_code e) { static char buffer[128]; char * msg = Z3_get_error_msg_ex(c, e); if (strlen(msg) > 100) { failwith("Z3: error message is too big to fit in buffer"); } else { sprintf(buffer, "Z3: %s", msg); failwith(buffer); } }
|
||||
value camlidl_z3_Z3_get_implied_equalities(
|
||||
value _v_c,
|
||||
value _v_s,
|
||||
value _v_terms)
|
||||
{
|
||||
Z3_context c; /*in*/
|
||||
Z3_solver s; /*in*/
|
||||
unsigned int num_terms; /*in*/
|
||||
Z3_ast const *terms; /*in*/
|
||||
unsigned int *class_ids; /*out*/
|
||||
Z3_lbool _res;
|
||||
struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };
|
||||
camlidl_ctx _ctx = &_ctxs;
|
||||
mlsize_t _c1;
|
||||
mlsize_t _c2;
|
||||
value _v3;
|
||||
mlsize_t _c4;
|
||||
value _v5;
|
||||
value _vresult;
|
||||
value _vres[2] = { 0, 0, };
|
||||
|
||||
camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx);
|
||||
camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx);
|
||||
_c1 = Wosize_val(_v_terms);
|
||||
terms = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx);
|
||||
for (_c2 = 0; _c2 < _c1; _c2++) {
|
||||
_v3 = Field(_v_terms, _c2);
|
||||
camlidl_ml2c_z3_Z3_ast(_v3, &terms[_c2], _ctx);
|
||||
}
|
||||
num_terms = _c1;
|
||||
class_ids = camlidl_malloc(num_terms * sizeof(unsigned int ), _ctx);
|
||||
_res = Z3_get_implied_equalities(c, s, num_terms, terms, class_ids);
|
||||
Begin_roots_block(_vres, 2)
|
||||
_vres[0] = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx);
|
||||
_vres[1] = camlidl_alloc(num_terms, 0);
|
||||
for (_c4 = 0; _c4 < num_terms; _c4++) {
|
||||
_v5 = Val_int(class_ids[_c4]);
|
||||
modify(&Field(_vres[1], _c4), _v5);
|
||||
}
|
||||
_vresult = camlidl_alloc_small(2, 0);
|
||||
Field(_vresult, 0) = _vres[0];
|
||||
Field(_vresult, 1) = _vres[1];
|
||||
End_roots()
|
||||
camlidl_free(_ctx);
|
||||
/* begin user-supplied deallocation sequence */
|
||||
check_error_code(c);
|
||||
/* end user-supplied deallocation sequence */
|
||||
return _vresult;
|
||||
}
|
||||
|
||||
void camlidl_ml2c_z3V3_Z3_symbol(value _v1, Z3_symbol * _c2, camlidl_ctx _ctx)
|
||||
{
|
||||
*_c2 = *((Z3_symbol *) Bp_val(_v1));
|
||||
|
@ -18250,50 +18276,6 @@ value camlidl_z3V3_Z3_check_assumptions(
|
|||
return _vresult;
|
||||
}
|
||||
|
||||
value camlidl_z3V3_Z3_get_implied_equalities(
|
||||
value _v_c,
|
||||
value _v_terms)
|
||||
{
|
||||
Z3_context c; /*in*/
|
||||
unsigned int num_terms; /*in*/
|
||||
Z3_ast const *terms; /*in*/
|
||||
unsigned int *class_ids; /*out*/
|
||||
Z3_lbool _res;
|
||||
struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };
|
||||
camlidl_ctx _ctx = &_ctxs;
|
||||
mlsize_t _c1;
|
||||
mlsize_t _c2;
|
||||
value _v3;
|
||||
mlsize_t _c4;
|
||||
value _v5;
|
||||
value _vresult;
|
||||
value _vres[2] = { 0, 0, };
|
||||
|
||||
camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx);
|
||||
_c1 = Wosize_val(_v_terms);
|
||||
terms = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx);
|
||||
for (_c2 = 0; _c2 < _c1; _c2++) {
|
||||
_v3 = Field(_v_terms, _c2);
|
||||
camlidl_ml2c_z3V3_Z3_ast(_v3, &terms[_c2], _ctx);
|
||||
}
|
||||
num_terms = _c1;
|
||||
class_ids = camlidl_malloc(num_terms * sizeof(unsigned int ), _ctx);
|
||||
_res = Z3_get_implied_equalities(c, num_terms, terms, class_ids);
|
||||
Begin_roots_block(_vres, 2)
|
||||
_vres[0] = camlidl_c2ml_z3V3_Z3_lbool(&_res, _ctx);
|
||||
_vres[1] = camlidl_alloc(num_terms, 0);
|
||||
for (_c4 = 0; _c4 < num_terms; _c4++) {
|
||||
_v5 = Val_int(class_ids[_c4]);
|
||||
modify(&Field(_vres[1], _c4), _v5);
|
||||
}
|
||||
_vresult = camlidl_alloc_small(2, 0);
|
||||
Field(_vresult, 0) = _vres[0];
|
||||
Field(_vresult, 1) = _vres[1];
|
||||
End_roots()
|
||||
camlidl_free(_ctx);
|
||||
return _vresult;
|
||||
}
|
||||
|
||||
value camlidl_z3V3_Z3_del_model(
|
||||
value _v_c,
|
||||
value _v_m)
|
||||
|
|
|
@ -37,15 +37,23 @@ Z3 exceptions:
|
|||
... # the expression x + y is type incorrect
|
||||
... n = x + y
|
||||
... except Z3Exception as ex:
|
||||
... print "failed:", ex
|
||||
... print("failed: %s" % ex)
|
||||
failed: 'sort mismatch'
|
||||
"""
|
||||
from z3core import *
|
||||
from z3types import *
|
||||
from z3consts import *
|
||||
from z3printer import *
|
||||
import sys
|
||||
import io
|
||||
|
||||
if sys.version < '3':
|
||||
def _is_int(v):
|
||||
return isinstance(v, int) or isinstance(v, long)
|
||||
else:
|
||||
def _is_int(v):
|
||||
return isinstance(v, int)
|
||||
|
||||
def enable_trace(msg):
|
||||
Z3_enable_trace(msg)
|
||||
|
||||
|
@ -102,12 +110,12 @@ _error_handler_fptr = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_uint)
|
|||
# list of arguments.
|
||||
def _get_args(args):
|
||||
try:
|
||||
if len(args) == 1 and (isinstance(args[0], tuple) or isinstance(args[0], list)):
|
||||
return args[0]
|
||||
else:
|
||||
return args
|
||||
if len(args) == 1 and (isinstance(args[0], tuple) or isinstance(args[0], list)):
|
||||
return args[0]
|
||||
else:
|
||||
return args
|
||||
except: # len is not necessarily defined when args is not a sequence (use reflection?)
|
||||
return args
|
||||
return args
|
||||
|
||||
def _Z3python_error_handler_core(c, e):
|
||||
# Do nothing error handler, just avoid exit(0)
|
||||
|
@ -140,7 +148,8 @@ class Context:
|
|||
if __debug__:
|
||||
_z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
|
||||
conf = Z3_mk_config()
|
||||
for key, value in kws.iteritems():
|
||||
for key in kws:
|
||||
value = kws[key]
|
||||
Z3_set_param_value(conf, str(key).upper(), _to_param_value(value))
|
||||
prev = None
|
||||
for a in args:
|
||||
|
@ -209,10 +218,12 @@ def set_param(*args, **kws):
|
|||
if __debug__:
|
||||
_z3_assert(len(args) % 2 == 0, "Argument list must have an even number of elements.")
|
||||
new_kws = {}
|
||||
for k, v in kws.iteritems():
|
||||
for k in kws:
|
||||
v = kws[k]
|
||||
if not set_pp_option(k, v):
|
||||
new_kws[k] = v
|
||||
for key, value in new_kws.iteritems():
|
||||
for key in new_kws:
|
||||
value = new_kws[key]
|
||||
Z3_global_param_set(str(key).upper(), _to_param_value(value))
|
||||
prev = None
|
||||
for a in args:
|
||||
|
@ -240,7 +251,7 @@ def get_param(name):
|
|||
"""
|
||||
ptr = (ctypes.c_char_p * 1)()
|
||||
if Z3_global_param_get(str(name), ptr):
|
||||
r = str(ptr[0])
|
||||
r = z3core._to_pystr(ptr[0])
|
||||
return r
|
||||
raise Z3Exception("failed to retrieve value for '%s'" % name)
|
||||
|
||||
|
@ -899,11 +910,22 @@ def _coerce_exprs(a, b, ctx=None):
|
|||
b = s.cast(b)
|
||||
return (a, b)
|
||||
|
||||
def _reduce(f, l, a):
|
||||
r = a
|
||||
for e in l:
|
||||
r = f(r, e)
|
||||
return r
|
||||
|
||||
def _coerce_expr_list(alist, ctx=None):
|
||||
if filter(is_expr, alist) == []:
|
||||
alist = map(lambda a: _py2expr(a, ctx), alist)
|
||||
s = reduce(_coerce_expr_merge, alist, None)
|
||||
return map(lambda a: s.cast(a), alist)
|
||||
has_expr = False
|
||||
for a in alist:
|
||||
if is_expr(a):
|
||||
has_expr = True
|
||||
break
|
||||
if not has_expr:
|
||||
alist = [ _py2expr(a, ctx) for a in alist ]
|
||||
s = _reduce(_coerce_expr_merge, alist, None)
|
||||
return [ s.cast(a) for a in alist ]
|
||||
|
||||
def is_expr(a):
|
||||
"""Return `True` if `a` is a Z3 expression.
|
||||
|
@ -1518,7 +1540,7 @@ def MultiPattern(*args):
|
|||
"""
|
||||
if __debug__:
|
||||
_z3_assert(len(args) > 0, "At least one argument expected")
|
||||
_z3_assert(all(map(is_expr, args)), "Z3 expressions expected")
|
||||
_z3_assert(all([ is_expr(a) for a in args ]), "Z3 expressions expected")
|
||||
ctx = args[0].ctx
|
||||
args, sz = _to_ast_array(args)
|
||||
return PatternRef(Z3_mk_pattern(ctx.ref(), sz, args), ctx)
|
||||
|
@ -1695,9 +1717,9 @@ def is_quantifier(a):
|
|||
def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[], no_patterns=[]):
|
||||
if __debug__:
|
||||
_z3_assert(is_bool(body), "Z3 expression expected")
|
||||
_z3_assert(is_const(vs) or (len(vs) > 0 and all(map(is_const, vs))), "Invalid bounded variable(s)")
|
||||
_z3_assert(all(map(lambda a: is_pattern(a) or is_expr(a), patterns)), "Z3 patterns expected")
|
||||
_z3_assert(all(map(is_expr, no_patterns)), "no patterns are Z3 expressions")
|
||||
_z3_assert(is_const(vs) or (len(vs) > 0 and all([ is_const(v) for v in vs])), "Invalid bounded variable(s)")
|
||||
_z3_assert(all([is_pattern(a) or is_expr(a) for a in patterns]), "Z3 patterns expected")
|
||||
_z3_assert(all([is_expr(p) for p in no_patterns]), "no patterns are Z3 expressions")
|
||||
ctx = body.ctx
|
||||
if is_app(vs):
|
||||
vs = [vs]
|
||||
|
@ -1706,7 +1728,7 @@ def _mk_quantifier(is_forall, vs, body, weight=1, qid="", skid="", patterns=[],
|
|||
for i in range(num_vars):
|
||||
## TODO: Check if is constant
|
||||
_vs[i] = vs[i].as_ast()
|
||||
patterns = map(_to_pattern, patterns)
|
||||
patterns = [ _to_pattern(p) for p in patterns ]
|
||||
num_pats = len(patterns)
|
||||
_pats = (Pattern * num_pats)()
|
||||
for i in range(num_pats):
|
||||
|
@ -2008,7 +2030,7 @@ class ArithRef(ExprRef):
|
|||
|
||||
def __truediv__(self, other):
|
||||
"""Create the Z3 expression `other/self`."""
|
||||
self.__div__(other)
|
||||
return self.__div__(other)
|
||||
|
||||
def __rdiv__(self, other):
|
||||
"""Create the Z3 expression `other/self`.
|
||||
|
@ -2029,7 +2051,7 @@ class ArithRef(ExprRef):
|
|||
|
||||
def __rtruediv__(self, other):
|
||||
"""Create the Z3 expression `other/self`."""
|
||||
self.__rdiv__(other)
|
||||
return self.__rdiv__(other)
|
||||
|
||||
def __mod__(self, other):
|
||||
"""Create the Z3 expression `other%self`.
|
||||
|
@ -2413,11 +2435,11 @@ class IntNumRef(ArithRef):
|
|||
>>> v + 1
|
||||
1 + 1
|
||||
>>> v.as_long() + 1
|
||||
2L
|
||||
2
|
||||
"""
|
||||
if __debug__:
|
||||
_z3_assert(self.is_int(), "Integer value expected")
|
||||
return long(self.as_string())
|
||||
return int(self.as_string())
|
||||
|
||||
def as_string(self):
|
||||
"""Return a Z3 integer numeral as a Python string.
|
||||
|
@ -2464,8 +2486,8 @@ class RatNumRef(ArithRef):
|
|||
10000000000
|
||||
>>> v + 1
|
||||
10000000000 + 1
|
||||
>>> v.numerator_as_long() + 1
|
||||
10000000001L
|
||||
>>> v.numerator_as_long() + 1 == 10000000001
|
||||
True
|
||||
"""
|
||||
return self.numerator().as_long()
|
||||
|
||||
|
@ -2476,7 +2498,7 @@ class RatNumRef(ArithRef):
|
|||
>>> v
|
||||
1/3
|
||||
>>> v.denominator_as_long()
|
||||
3L
|
||||
3
|
||||
"""
|
||||
return self.denominator().as_long()
|
||||
|
||||
|
@ -2529,7 +2551,7 @@ class AlgebraicNumRef(ArithRef):
|
|||
def _py2expr(a, ctx=None):
|
||||
if isinstance(a, bool):
|
||||
return BoolVal(a, ctx)
|
||||
if isinstance(a, int) or isinstance(a, long):
|
||||
if _is_int(a):
|
||||
return IntVal(a, ctx)
|
||||
if isinstance(a, float):
|
||||
return RealVal(a, ctx)
|
||||
|
@ -2576,9 +2598,7 @@ def _to_int_str(val):
|
|||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
elif isinstance(val, int):
|
||||
return str(val)
|
||||
elif isinstance(val, long):
|
||||
elif _is_int(val):
|
||||
return str(val)
|
||||
elif isinstance(val, str):
|
||||
return val
|
||||
|
@ -2625,8 +2645,8 @@ def RatVal(a, b, ctx=None):
|
|||
Real
|
||||
"""
|
||||
if __debug__:
|
||||
_z3_assert(isinstance(a, int) or isinstance(a, str) or isinstance(a, long), "First argument cannot be converted into an integer")
|
||||
_z3_assert(isinstance(b, int) or isinstance(b, str) or isinstance(a, long), "Second argument cannot be converted into an integer")
|
||||
_z3_assert(_is_int(a) or isinstance(a, str), "First argument cannot be converted into an integer")
|
||||
_z3_assert(_is_int(b) or isinstance(b, str), "Second argument cannot be converted into an integer")
|
||||
return simplify(RealVal(a, ctx)/RealVal(b, ctx))
|
||||
|
||||
def Q(a, b, ctx=None):
|
||||
|
@ -3078,7 +3098,7 @@ class BitVecRef(ExprRef):
|
|||
|
||||
def __truediv__(self, other):
|
||||
"""Create the Z3 expression (signed) division `self / other`."""
|
||||
self.__div__(other)
|
||||
return self.__div__(other)
|
||||
|
||||
def __rdiv__(self, other):
|
||||
"""Create the Z3 expression (signed) division `other / self`.
|
||||
|
@ -3098,7 +3118,7 @@ class BitVecRef(ExprRef):
|
|||
|
||||
def __rtruediv__(self, other):
|
||||
"""Create the Z3 expression (signed) division `other / self`."""
|
||||
self.__rdiv__(other)
|
||||
return self.__rdiv__(other)
|
||||
|
||||
def __mod__(self, other):
|
||||
"""Create the Z3 expression (signed) mod `self % other`.
|
||||
|
@ -3218,9 +3238,9 @@ class BitVecRef(ExprRef):
|
|||
>>> BitVecVal(4, 3)
|
||||
4
|
||||
>>> BitVecVal(4, 3).as_signed_long()
|
||||
-4L
|
||||
-4
|
||||
>>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
|
||||
-2L
|
||||
-2
|
||||
>>> simplify(BitVecVal(4, 3) >> 1)
|
||||
6
|
||||
>>> simplify(LShR(BitVecVal(4, 3), 1))
|
||||
|
@ -3284,32 +3304,32 @@ class BitVecNumRef(BitVecRef):
|
|||
>>> v = BitVecVal(0xbadc0de, 32)
|
||||
>>> v
|
||||
195936478
|
||||
>>> print "0x%.8x" % v.as_long()
|
||||
>>> print("0x%.8x" % v.as_long())
|
||||
0x0badc0de
|
||||
"""
|
||||
return long(self.as_string())
|
||||
return int(self.as_string())
|
||||
|
||||
def as_signed_long(self):
|
||||
"""Return a Z3 bit-vector numeral as a Python long (bignum) numeral. The most significant bit is assumed to be the sign.
|
||||
|
||||
>>> BitVecVal(4, 3).as_signed_long()
|
||||
-4L
|
||||
-4
|
||||
>>> BitVecVal(7, 3).as_signed_long()
|
||||
-1L
|
||||
-1
|
||||
>>> BitVecVal(3, 3).as_signed_long()
|
||||
3L
|
||||
>>> BitVecVal(2L**32 - 1, 32).as_signed_long()
|
||||
-1L
|
||||
>>> BitVecVal(2L**64 - 1, 64).as_signed_long()
|
||||
-1L
|
||||
3
|
||||
>>> BitVecVal(2**32 - 1, 32).as_signed_long()
|
||||
-1
|
||||
>>> BitVecVal(2**64 - 1, 64).as_signed_long()
|
||||
-1
|
||||
"""
|
||||
sz = long(self.size())
|
||||
sz = self.size()
|
||||
val = self.as_long()
|
||||
if val >= 2L**(sz - 1):
|
||||
val = val - 2L**sz
|
||||
if val < -2L**(sz - 1):
|
||||
val = val + 2L**sz
|
||||
return val
|
||||
if val >= 2**(sz - 1):
|
||||
val = val - 2**sz
|
||||
if val < -2**(sz - 1):
|
||||
val = val + 2**sz
|
||||
return int(val)
|
||||
|
||||
def as_string(self):
|
||||
return Z3_get_numeral_string(self.ctx_ref(), self.as_ast())
|
||||
|
@ -3379,7 +3399,7 @@ def BitVecVal(val, bv, ctx=None):
|
|||
>>> v = BitVecVal(10, 32)
|
||||
>>> v
|
||||
10
|
||||
>>> print "0x%.8x" % v.as_long()
|
||||
>>> print("0x%.8x" % v.as_long())
|
||||
0x0000000a
|
||||
"""
|
||||
if is_bv_sort(bv):
|
||||
|
@ -3440,12 +3460,12 @@ def Concat(*args):
|
|||
Concat(Concat(1, 1 + 1), 1)
|
||||
>>> simplify(Concat(v, v+1, v))
|
||||
289
|
||||
>>> print "%.3x" % simplify(Concat(v, v+1, v)).as_long()
|
||||
>>> print("%.3x" % simplify(Concat(v, v+1, v)).as_long())
|
||||
121
|
||||
"""
|
||||
args = _get_args(args)
|
||||
if __debug__:
|
||||
_z3_assert(all(map(is_bv, args)), "All arguments must be Z3 bit-vector expressions.")
|
||||
_z3_assert(all([is_bv(a) for a in args]), "All arguments must be Z3 bit-vector expressions.")
|
||||
_z3_assert(len(args) >= 2, "At least two arguments expected.")
|
||||
ctx = args[0].ctx
|
||||
r = args[0]
|
||||
|
@ -3615,9 +3635,9 @@ def LShR(a, b):
|
|||
>>> BitVecVal(4, 3)
|
||||
4
|
||||
>>> BitVecVal(4, 3).as_signed_long()
|
||||
-4L
|
||||
-4
|
||||
>>> simplify(BitVecVal(4, 3) >> 1).as_signed_long()
|
||||
-2L
|
||||
-2
|
||||
>>> simplify(BitVecVal(4, 3) >> 1)
|
||||
6
|
||||
>>> simplify(LShR(BitVecVal(4, 3), 1))
|
||||
|
@ -3682,7 +3702,7 @@ def SignExt(n, a):
|
|||
254
|
||||
>>> v.size()
|
||||
8
|
||||
>>> print "%.x" % v.as_long()
|
||||
>>> print("%.x" % v.as_long())
|
||||
fe
|
||||
"""
|
||||
if __debug__:
|
||||
|
@ -3727,12 +3747,12 @@ def RepeatBitVec(n, a):
|
|||
>>> n.size()
|
||||
32
|
||||
>>> v0 = BitVecVal(10, 4)
|
||||
>>> print "%.x" % v0.as_long()
|
||||
>>> print("%.x" % v0.as_long())
|
||||
a
|
||||
>>> v = simplify(RepeatBitVec(4, v0))
|
||||
>>> v.size()
|
||||
16
|
||||
>>> print "%.x" % v.as_long()
|
||||
>>> print("%.x" % v.as_long())
|
||||
aaaa
|
||||
"""
|
||||
if __debug__:
|
||||
|
@ -4006,7 +4026,7 @@ def Map(f, *args):
|
|||
if __debug__:
|
||||
_z3_assert(len(args) > 0, "At least one Z3 array expression expected")
|
||||
_z3_assert(is_func_decl(f), "First argument must be a Z3 function declaration")
|
||||
_z3_assert(all(map(is_array, args)), "Z3 array expected expected")
|
||||
_z3_assert(all([is_array(a) for a in args]), "Z3 array expected expected")
|
||||
_z3_assert(len(args) == f.arity(), "Number of arguments mismatch")
|
||||
_args, sz = _to_ast_array(args)
|
||||
ctx = f.ctx
|
||||
|
@ -4100,7 +4120,7 @@ class Datatype:
|
|||
if __debug__:
|
||||
_z3_assert(isinstance(name, str), "String expected")
|
||||
_z3_assert(isinstance(rec_name, str), "String expected")
|
||||
_z3_assert(all(map(_valid_accessor, args)), "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
|
||||
_z3_assert(all([_valid_accessor(a) for a in args]), "Valid list of accessors expected. An accessor is a pair of the form (String, Datatype|Sort)")
|
||||
self.constructors.append((name, rec_name, args))
|
||||
|
||||
def declare(self, name, *args):
|
||||
|
@ -4187,9 +4207,9 @@ def CreateDatatypes(*ds):
|
|||
ds = _get_args(ds)
|
||||
if __debug__:
|
||||
_z3_assert(len(ds) > 0, "At least one Datatype must be specified")
|
||||
_z3_assert(all(map(lambda d: isinstance(d, Datatype), ds)), "Arguments must be Datatypes")
|
||||
_z3_assert(all(map(lambda d: d.ctx == ds[0].ctx, ds)), "Context mismatch")
|
||||
_z3_assert(all(map(lambda d: d.constructors != [], ds)), "Non-empty Datatypes expected")
|
||||
_z3_assert(all([isinstance(d, Datatype) for d in ds]), "Arguments must be Datatypes")
|
||||
_z3_assert(all([d.ctx == ds[0].ctx for d in ds]), "Context mismatch")
|
||||
_z3_assert(all([d.constructors != [] for d in ds]), "Non-empty Datatypes expected")
|
||||
ctx = ds[0].ctx
|
||||
num = len(ds)
|
||||
names = (Symbol * num)()
|
||||
|
@ -4355,7 +4375,7 @@ def EnumSort(name, values, ctx=None):
|
|||
"""
|
||||
if __debug__:
|
||||
_z3_assert(isinstance(name, str), "Name must be a string")
|
||||
_z3_assert(all(map(lambda v: isinstance(v, str), values)), "Eumeration sort values must be strings")
|
||||
_z3_assert(all([isinstance(v, str) for v in values]), "Eumeration sort values must be strings")
|
||||
_z3_assert(len(values) > 0, "At least one value expected")
|
||||
ctx = _get_ctx(ctx)
|
||||
num = len(values)
|
||||
|
@ -4369,7 +4389,7 @@ def EnumSort(name, values, ctx=None):
|
|||
V = []
|
||||
for i in range(num):
|
||||
V.append(FuncDeclRef(_values[i], ctx))
|
||||
V = map(lambda a: a(), V)
|
||||
V = [a() for a in V]
|
||||
return S, V
|
||||
|
||||
#########################################
|
||||
|
@ -4432,7 +4452,8 @@ def args2params(arguments, keywords, ctx=None):
|
|||
else:
|
||||
r.set(prev, a)
|
||||
prev = None
|
||||
for k, v in keywords.iteritems():
|
||||
for k in keywords:
|
||||
v = keywords[k]
|
||||
r.set(k, v)
|
||||
return r
|
||||
|
||||
|
@ -4469,7 +4490,7 @@ class ParamDescrsRef:
|
|||
return Z3_param_descrs_get_kind(self.ctx.ref(), self.descr, to_symbol(n, self.ctx))
|
||||
|
||||
def __getitem__(self, arg):
|
||||
if isinstance(arg, int) or isinstance(arg, long):
|
||||
if _is_int(arg):
|
||||
return self.get_name(arg)
|
||||
else:
|
||||
return self.get_kind(arg)
|
||||
|
@ -5057,7 +5078,7 @@ class FuncEntry:
|
|||
>>> try:
|
||||
... e.arg_value(2)
|
||||
... except IndexError:
|
||||
... print "index error"
|
||||
... print("index error")
|
||||
index error
|
||||
"""
|
||||
if idx >= self.num_args():
|
||||
|
@ -5122,7 +5143,10 @@ class FuncInterp(Z3PPObject):
|
|||
Z3_func_interp_dec_ref(self.ctx.ref(), self.f)
|
||||
|
||||
def else_value(self):
|
||||
"""Return the `else` value for a function interpretation.
|
||||
"""
|
||||
Return the `else` value for a function interpretation.
|
||||
Return None if Z3 did not specify the `else` value for
|
||||
this object.
|
||||
|
||||
>>> f = Function('f', IntSort(), IntSort())
|
||||
>>> s = Solver()
|
||||
|
@ -5135,7 +5159,11 @@ class FuncInterp(Z3PPObject):
|
|||
>>> m[f].else_value()
|
||||
1
|
||||
"""
|
||||
return _to_expr_ref(Z3_func_interp_get_else(self.ctx.ref(), self.f), self.ctx)
|
||||
r = Z3_func_interp_get_else(self.ctx.ref(), self.f)
|
||||
if r:
|
||||
return _to_expr_ref(r, self.ctx)
|
||||
else:
|
||||
return None
|
||||
|
||||
def num_entries(self):
|
||||
"""Return the number of entries/points in the function interpretation `self`.
|
||||
|
@ -5428,7 +5456,7 @@ class ModelRef(Z3PPObject):
|
|||
1
|
||||
>>> m[f]
|
||||
[1 -> 0, else -> 0]
|
||||
>>> for d in m: print "%s -> %s" % (d, m[d])
|
||||
>>> for d in m: print("%s -> %s" % (d, m[d]))
|
||||
x -> 1
|
||||
f -> [1 -> 0, else -> 0]
|
||||
"""
|
||||
|
@ -5499,16 +5527,16 @@ class Statistics:
|
|||
if in_html_mode():
|
||||
out = io.StringIO()
|
||||
even = True
|
||||
out.write(u'<table border="1" cellpadding="2" cellspacing="0">')
|
||||
out.write(u('<table border="1" cellpadding="2" cellspacing="0">'))
|
||||
for k, v in self:
|
||||
if even:
|
||||
out.write(u'<tr style="background-color:#CFCFCF">')
|
||||
out.write(u('<tr style="background-color:#CFCFCF">'))
|
||||
even = False
|
||||
else:
|
||||
out.write(u'<tr>')
|
||||
out.write(u('<tr>'))
|
||||
even = True
|
||||
out.write(u'<td>%s</td><td>%s</td></tr>' % (k, v))
|
||||
out.write(u'</table>')
|
||||
out.write(u('<td>%s</td><td>%s</td></tr>' % (k, v)))
|
||||
out.write(u('</table>'))
|
||||
return out.getvalue()
|
||||
else:
|
||||
return Z3_stats_to_string(self.ctx.ref(), self.stats)
|
||||
|
@ -5806,7 +5834,7 @@ class Solver(Z3PPObject):
|
|||
>>> s.assert_and_track(x > 0, 'p1')
|
||||
>>> s.assert_and_track(x != 1, 'p2')
|
||||
>>> s.assert_and_track(x < 0, p3)
|
||||
>>> print s.check()
|
||||
>>> print(s.check())
|
||||
unsat
|
||||
>>> c = s.unsat_core()
|
||||
>>> len(c)
|
||||
|
@ -5954,7 +5982,7 @@ class Solver(Z3PPObject):
|
|||
|
||||
def help(self):
|
||||
"""Display a string describing all available options."""
|
||||
print Z3_solver_get_help(self.ctx.ref(), self.solver)
|
||||
print(Z3_solver_get_help(self.ctx.ref(), self.solver))
|
||||
|
||||
def param_descrs(self):
|
||||
"""Return the parameter description set."""
|
||||
|
@ -6025,7 +6053,7 @@ class Fixedpoint(Z3PPObject):
|
|||
else:
|
||||
self.fixedpoint = fixedpoint
|
||||
Z3_fixedpoint_inc_ref(self.ctx.ref(), self.fixedpoint)
|
||||
self.vars = []
|
||||
self.vars = []
|
||||
|
||||
def __del__(self):
|
||||
if self.fixedpoint != None:
|
||||
|
@ -6039,8 +6067,8 @@ class Fixedpoint(Z3PPObject):
|
|||
|
||||
def help(self):
|
||||
"""Display a string describing all available options."""
|
||||
print Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint)
|
||||
|
||||
print(Z3_fixedpoint_get_help(self.ctx.ref(), self.fixedpoint))
|
||||
|
||||
def param_descrs(self):
|
||||
"""Return the parameter description set."""
|
||||
return ParamDescrsRef(Z3_fixedpoint_get_param_descrs(self.ctx.ref(), self.fixedpoint), self.ctx)
|
||||
|
@ -6052,11 +6080,11 @@ class Fixedpoint(Z3PPObject):
|
|||
for arg in args:
|
||||
if isinstance(arg, Goal) or isinstance(arg, AstVector):
|
||||
for f in arg:
|
||||
f = self.abstract(f)
|
||||
f = self.abstract(f)
|
||||
Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, f.as_ast())
|
||||
else:
|
||||
arg = s.cast(arg)
|
||||
arg = self.abstract(arg)
|
||||
arg = self.abstract(arg)
|
||||
Z3_fixedpoint_assert(self.ctx.ref(), self.fixedpoint, arg.as_ast())
|
||||
|
||||
def add(self, *args):
|
||||
|
@ -6072,38 +6100,38 @@ class Fixedpoint(Z3PPObject):
|
|||
self.assert_exprs(*args)
|
||||
|
||||
def add_rule(self, head, body = None, name = None):
|
||||
"""Assert rules defining recursive predicates to the fixedpoint solver.
|
||||
"""Assert rules defining recursive predicates to the fixedpoint solver.
|
||||
>>> a = Bool('a')
|
||||
>>> b = Bool('b')
|
||||
>>> b = Bool('b')
|
||||
>>> s = Fixedpoint()
|
||||
>>> s.register_relation(a.decl())
|
||||
>>> s.register_relation(b.decl())
|
||||
>>> s.fact(a)
|
||||
>>> s.register_relation(a.decl())
|
||||
>>> s.register_relation(b.decl())
|
||||
>>> s.fact(a)
|
||||
>>> s.rule(b, a)
|
||||
>>> s.query(b)
|
||||
sat
|
||||
"""
|
||||
if name == None:
|
||||
name = ""
|
||||
>>> s.query(b)
|
||||
sat
|
||||
"""
|
||||
if name == None:
|
||||
name = ""
|
||||
name = to_symbol(name, self.ctx)
|
||||
if body == None:
|
||||
head = self.abstract(head)
|
||||
Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
|
||||
else:
|
||||
body = _get_args(body)
|
||||
f = self.abstract(Implies(And(body),head))
|
||||
Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
|
||||
|
||||
if body == None:
|
||||
head = self.abstract(head)
|
||||
Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, head.as_ast(), name)
|
||||
else:
|
||||
body = _get_args(body)
|
||||
f = self.abstract(Implies(And(body),head))
|
||||
Z3_fixedpoint_add_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
|
||||
|
||||
def rule(self, head, body = None, name = None):
|
||||
"""Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
|
||||
self.add_rule(head, body, name)
|
||||
|
||||
"""Assert rules defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
|
||||
self.add_rule(head, body, name)
|
||||
|
||||
def fact(self, head, name = None):
|
||||
"""Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
|
||||
self.add_rule(head, None, name)
|
||||
"""Assert facts defining recursive predicates to the fixedpoint solver. Alias for add_rule."""
|
||||
self.add_rule(head, None, name)
|
||||
|
||||
def query(self, *query):
|
||||
"""Query the fixedpoint engine whether formula is derivable.
|
||||
"""Query the fixedpoint engine whether formula is derivable.
|
||||
You can also pass an tuple or list of recursive predicates.
|
||||
"""
|
||||
query = _get_args(query)
|
||||
|
@ -6134,17 +6162,17 @@ class Fixedpoint(Z3PPObject):
|
|||
|
||||
def update_rule(self, head, body, name):
|
||||
"""update rule"""
|
||||
if name == None:
|
||||
name = ""
|
||||
if name == None:
|
||||
name = ""
|
||||
name = to_symbol(name, self.ctx)
|
||||
body = _get_args(body)
|
||||
f = self.abstract(Implies(And(body),head))
|
||||
Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
|
||||
Z3_fixedpoint_update_rule(self.ctx.ref(), self.fixedpoint, f.as_ast(), name)
|
||||
|
||||
def get_answer(self):
|
||||
"""Retrieve answer from last query call."""
|
||||
r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
|
||||
return _to_expr_ref(r, self.ctx)
|
||||
def get_answer(self):
|
||||
"""Retrieve answer from last query call."""
|
||||
r = Z3_fixedpoint_get_answer(self.ctx.ref(), self.fixedpoint)
|
||||
return _to_expr_ref(r, self.ctx)
|
||||
|
||||
def get_num_levels(self, predicate):
|
||||
"""Retrieve number of levels used for predicate in PDR engine"""
|
||||
|
@ -6160,40 +6188,40 @@ class Fixedpoint(Z3PPObject):
|
|||
Z3_fixedpoint_add_cover(self.ctx.ref(), self.fixedpoint, level, predicate.ast, property.ast)
|
||||
|
||||
def register_relation(self, *relations):
|
||||
"""Register relation as recursive"""
|
||||
relations = _get_args(relations)
|
||||
for f in relations:
|
||||
Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
|
||||
"""Register relation as recursive"""
|
||||
relations = _get_args(relations)
|
||||
for f in relations:
|
||||
Z3_fixedpoint_register_relation(self.ctx.ref(), self.fixedpoint, f.ast)
|
||||
|
||||
def set_predicate_representation(self, f, *representations):
|
||||
"""Control how relation is represented"""
|
||||
representations = _get_args(representations)
|
||||
representations = map(to_symbol, representations)
|
||||
sz = len(representations)
|
||||
args = (Symbol * sz)()
|
||||
for i in range(sz):
|
||||
args[i] = representations[i]
|
||||
Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
|
||||
"""Control how relation is represented"""
|
||||
representations = _get_args(representations)
|
||||
representations = [to_symbol(s) for s in representations]
|
||||
sz = len(representations)
|
||||
args = (Symbol * sz)()
|
||||
for i in range(sz):
|
||||
args[i] = representations[i]
|
||||
Z3_fixedpoint_set_predicate_representation(self.ctx.ref(), self.fixedpoint, f.ast, sz, args)
|
||||
|
||||
def parse_string(self, s):
|
||||
"""Parse rules and queries from a string"""
|
||||
return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
|
||||
|
||||
"""Parse rules and queries from a string"""
|
||||
return AstVector(Z3_fixedpoint_from_string(self.ctx.ref(), self.fixedpoint, s), self.ctx)
|
||||
|
||||
def parse_file(self, f):
|
||||
"""Parse rules and queries from a file"""
|
||||
return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
|
||||
"""Parse rules and queries from a file"""
|
||||
return AstVector(Z3_fixedpoint_from_file(self.ctx.ref(), self.fixedpoint, f), self.ctx)
|
||||
|
||||
def get_rules(self):
|
||||
"""retrieve rules that have been added to fixedpoint context"""
|
||||
return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
|
||||
"""retrieve rules that have been added to fixedpoint context"""
|
||||
return AstVector(Z3_fixedpoint_get_rules(self.ctx.ref(), self.fixedpoint), self.ctx)
|
||||
|
||||
def get_assertions(self):
|
||||
"""retrieve assertions that have been added to fixedpoint context"""
|
||||
return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
|
||||
"""retrieve assertions that have been added to fixedpoint context"""
|
||||
return AstVector(Z3_fixedpoint_get_assertions(self.ctx.ref(), self.fixedpoint), self.ctx)
|
||||
|
||||
def __repr__(self):
|
||||
"""Return a formatted string with all added rules and constraints."""
|
||||
return self.sexpr()
|
||||
return self.sexpr()
|
||||
|
||||
def sexpr(self):
|
||||
"""Return a formatted string (in Lisp-like format) with all added constraints. We say the string is in s-expression format.
|
||||
|
@ -6201,16 +6229,16 @@ class Fixedpoint(Z3PPObject):
|
|||
return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, 0, (Ast * 0)())
|
||||
|
||||
def to_string(self, queries):
|
||||
"""Return a formatted string (in Lisp-like format) with all added constraints.
|
||||
"""Return a formatted string (in Lisp-like format) with all added constraints.
|
||||
We say the string is in s-expression format.
|
||||
Include also queries.
|
||||
Include also queries.
|
||||
"""
|
||||
args, len = _to_ast_array(queries)
|
||||
args, len = _to_ast_array(queries)
|
||||
return Z3_fixedpoint_to_string(self.ctx.ref(), self.fixedpoint, len, args)
|
||||
|
||||
def statistics(self):
|
||||
"""Return statistics for the last `query()`.
|
||||
"""
|
||||
"""
|
||||
return Statistics(Z3_fixedpoint_get_statistics(self.ctx.ref(), self.fixedpoint), self.ctx)
|
||||
|
||||
def reason_unknown(self):
|
||||
|
@ -6219,21 +6247,21 @@ class Fixedpoint(Z3PPObject):
|
|||
return Z3_fixedpoint_get_reason_unknown(self.ctx.ref(), self.fixedpoint)
|
||||
|
||||
def declare_var(self, *vars):
|
||||
"""Add variable or several variables.
|
||||
The added variable or variables will be bound in the rules
|
||||
and queries
|
||||
"""
|
||||
vars = _get_args(vars)
|
||||
for v in vars:
|
||||
self.vars += [v]
|
||||
|
||||
"""Add variable or several variables.
|
||||
The added variable or variables will be bound in the rules
|
||||
and queries
|
||||
"""
|
||||
vars = _get_args(vars)
|
||||
for v in vars:
|
||||
self.vars += [v]
|
||||
|
||||
def abstract(self, fml, is_forall=True):
|
||||
if self.vars == []:
|
||||
return fml
|
||||
if is_forall:
|
||||
return ForAll(self.vars, fml)
|
||||
else:
|
||||
return Exists(self.vars, fml)
|
||||
if self.vars == []:
|
||||
return fml
|
||||
if is_forall:
|
||||
return ForAll(self.vars, fml)
|
||||
else:
|
||||
return Exists(self.vars, fml)
|
||||
|
||||
#########################################
|
||||
#
|
||||
|
@ -6425,7 +6453,7 @@ class Tactic:
|
|||
|
||||
def help(self):
|
||||
"""Display a string containing a description of the available options for the `self` tactic."""
|
||||
print Z3_tactic_get_help(self.ctx.ref(), self.tactic)
|
||||
print(Z3_tactic_get_help(self.ctx.ref(), self.tactic))
|
||||
|
||||
def param_descrs(self):
|
||||
"""Return the parameter description set."""
|
||||
|
@ -6521,7 +6549,7 @@ def ParOr(*ts, **ks):
|
|||
if __debug__:
|
||||
_z3_assert(len(ts) >= 2, "At least two arguments expected")
|
||||
ctx = _get_ctx(ks.get('ctx', None))
|
||||
ts = map(lambda t: _to_tactic(t, ctx), ts)
|
||||
ts = [ _to_tactic(t, ctx) for t in ts ]
|
||||
sz = len(ts)
|
||||
_args = (TacticObj * sz)()
|
||||
for i in range(sz):
|
||||
|
@ -6566,7 +6594,7 @@ def Repeat(t, max=4294967295, ctx=None):
|
|||
>>> c = And(Or(x == 0, x == 1), Or(y == 0, y == 1), x > y)
|
||||
>>> t = Repeat(OrElse(Tactic('split-clause'), Tactic('skip')))
|
||||
>>> r = t(c)
|
||||
>>> for subgoal in r: print subgoal
|
||||
>>> for subgoal in r: print(subgoal)
|
||||
[x == 0, y == 0, x > y]
|
||||
[x == 0, y == 1, x > y]
|
||||
[x == 1, y == 0, x > y]
|
||||
|
@ -6608,19 +6636,19 @@ def describe_tactics():
|
|||
"""Display a (tabular) description of all available tactics in Z3."""
|
||||
if in_html_mode():
|
||||
even = True
|
||||
print '<table border="1" cellpadding="2" cellspacing="0">'
|
||||
print('<table border="1" cellpadding="2" cellspacing="0">')
|
||||
for t in tactics():
|
||||
if even:
|
||||
print '<tr style="background-color:#CFCFCF">'
|
||||
print('<tr style="background-color:#CFCFCF">')
|
||||
even = False
|
||||
else:
|
||||
print '<tr>'
|
||||
print('<tr>')
|
||||
even = True
|
||||
print '<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40))
|
||||
print '</table>'
|
||||
print('<td>%s</td><td>%s</td></tr>' % (t, insert_line_breaks(tactic_description(t), 40)))
|
||||
print('</table>')
|
||||
else:
|
||||
for t in tactics():
|
||||
print '%s : %s' % (t, tactic_description(t))
|
||||
print('%s : %s' % (t, tactic_description(t)))
|
||||
|
||||
class Probe:
|
||||
"""Probes are used to inspect a goal (aka problem) and collect information that may be used to decide which solver and/or preprocessing step will be used."""
|
||||
|
@ -6631,7 +6659,7 @@ class Probe:
|
|||
self.probe = probe
|
||||
elif isinstance(probe, float):
|
||||
self.probe = Z3_probe_const(self.ctx.ref(), probe)
|
||||
elif isinstance(probe, int) or isinstance(probe, long):
|
||||
elif _is_int(probe):
|
||||
self.probe = Z3_probe_const(self.ctx.ref(), float(probe))
|
||||
elif isinstance(probe, bool):
|
||||
if probe:
|
||||
|
@ -6796,19 +6824,19 @@ def describe_probes():
|
|||
"""Display a (tabular) description of all available probes in Z3."""
|
||||
if in_html_mode():
|
||||
even = True
|
||||
print '<table border="1" cellpadding="2" cellspacing="0">'
|
||||
print('<table border="1" cellpadding="2" cellspacing="0">')
|
||||
for p in probes():
|
||||
if even:
|
||||
print '<tr style="background-color:#CFCFCF">'
|
||||
print('<tr style="background-color:#CFCFCF">')
|
||||
even = False
|
||||
else:
|
||||
print '<tr>'
|
||||
print('<tr>')
|
||||
even = True
|
||||
print '<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40))
|
||||
print '</table>'
|
||||
print('<td>%s</td><td>%s</td></tr>' % (p, insert_line_breaks(probe_description(p), 40)))
|
||||
print('</table>')
|
||||
else:
|
||||
for p in probes():
|
||||
print '%s : %s' % (p, probe_description(p))
|
||||
print('%s : %s' % (p, probe_description(p)))
|
||||
|
||||
def _probe_nary(f, args, ctx):
|
||||
if __debug__:
|
||||
|
@ -6904,7 +6932,7 @@ def simplify(a, *arguments, **keywords):
|
|||
|
||||
def help_simplify():
|
||||
"""Return a string describing all options available for Z3 `simplify` procedure."""
|
||||
print Z3_simplify_get_help(main_ctx().ref())
|
||||
print(Z3_simplify_get_help(main_ctx().ref()))
|
||||
|
||||
def simplify_param_descrs():
|
||||
"""Return the set of parameter descriptions for Z3 `simplify` procedure."""
|
||||
|
@ -6927,7 +6955,7 @@ def substitute(t, *m):
|
|||
m = _get_args(m1)
|
||||
if __debug__:
|
||||
_z3_assert(is_expr(t), "Z3 expression expected")
|
||||
_z3_assert(all(map(lambda p: isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) and p[0].sort().eq(p[1].sort()), m)), "Z3 invalid substitution, expression pairs expected.")
|
||||
_z3_assert(all([isinstance(p, tuple) and is_expr(p[0]) and is_expr(p[1]) and p[0].sort().eq(p[1].sort()) for p in m]), "Z3 invalid substitution, expression pairs expected.")
|
||||
num = len(m)
|
||||
_from = (Ast * num)()
|
||||
_to = (Ast * num)()
|
||||
|
@ -6949,7 +6977,7 @@ def substitute_vars(t, *m):
|
|||
"""
|
||||
if __debug__:
|
||||
_z3_assert(is_expr(t), "Z3 expression expected")
|
||||
_z3_assert(all(map(is_expr, m)), "Z3 invalid substitution, list of expressions expected.")
|
||||
_z3_assert(all([is_expr(n) for n in m]), "Z3 invalid substitution, list of expressions expected.")
|
||||
num = len(m)
|
||||
_to = (Ast * num)()
|
||||
for i in range(num):
|
||||
|
@ -6976,7 +7004,7 @@ def Sum(*args):
|
|||
_z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression")
|
||||
args = _coerce_expr_list(args, ctx)
|
||||
if is_bv(args[0]):
|
||||
return reduce(lambda a, b: a + b, args, 0)
|
||||
return _reduce(lambda a, b: a + b, args, 0)
|
||||
else:
|
||||
_args, sz = _to_ast_array(args)
|
||||
return ArithRef(Z3_mk_add(ctx.ref(), sz, _args), ctx)
|
||||
|
@ -7001,7 +7029,7 @@ def Product(*args):
|
|||
_z3_assert(ctx != None, "At least one of the arguments must be a Z3 expression")
|
||||
args = _coerce_expr_list(args, ctx)
|
||||
if is_bv(args[0]):
|
||||
return reduce(lambda a, b: a * b, args, 1)
|
||||
return _reduce(lambda a, b: a * b, args, 1)
|
||||
else:
|
||||
_args, sz = _to_ast_array(args)
|
||||
return ArithRef(Z3_mk_mul(ctx.ref(), sz, _args), ctx)
|
||||
|
@ -7021,18 +7049,18 @@ def solve(*args, **keywords):
|
|||
s.set(**keywords)
|
||||
s.add(*args)
|
||||
if keywords.get('show', False):
|
||||
print s
|
||||
print(s)
|
||||
r = s.check()
|
||||
if r == unsat:
|
||||
print "no solution"
|
||||
print("no solution")
|
||||
elif r == unknown:
|
||||
print "failed to solve"
|
||||
print("failed to solve")
|
||||
try:
|
||||
print s.model()
|
||||
print(s.model())
|
||||
except Z3Exception:
|
||||
return
|
||||
else:
|
||||
print s.model()
|
||||
print(s.model())
|
||||
|
||||
def solve_using(s, *args, **keywords):
|
||||
"""Solve the constraints `*args` using solver `s`.
|
||||
|
@ -7047,21 +7075,21 @@ def solve_using(s, *args, **keywords):
|
|||
s.set(**keywords)
|
||||
s.add(*args)
|
||||
if keywords.get('show', False):
|
||||
print "Problem:"
|
||||
print s
|
||||
print("Problem:")
|
||||
print(s)
|
||||
r = s.check()
|
||||
if r == unsat:
|
||||
print "no solution"
|
||||
print("no solution")
|
||||
elif r == unknown:
|
||||
print "failed to solve"
|
||||
print("failed to solve")
|
||||
try:
|
||||
print s.model()
|
||||
print(s.model())
|
||||
except Z3Exception:
|
||||
return
|
||||
else:
|
||||
if keywords.get('show', False):
|
||||
print "Solution:"
|
||||
print s.model()
|
||||
print("Solution:")
|
||||
print(s.model())
|
||||
|
||||
def prove(claim, **keywords):
|
||||
"""Try to prove the given claim.
|
||||
|
@ -7079,16 +7107,16 @@ def prove(claim, **keywords):
|
|||
s.set(**keywords)
|
||||
s.add(Not(claim))
|
||||
if keywords.get('show', False):
|
||||
print s
|
||||
print(s)
|
||||
r = s.check()
|
||||
if r == unsat:
|
||||
print "proved"
|
||||
print("proved")
|
||||
elif r == unknown:
|
||||
print "failed to prove"
|
||||
print s.model()
|
||||
print("failed to prove")
|
||||
print(s.model())
|
||||
else:
|
||||
print "counterexample"
|
||||
print s.model()
|
||||
print("counterexample")
|
||||
print(s.model())
|
||||
|
||||
def _solve_html(*args, **keywords):
|
||||
"""Version of funcion `solve` used in RiSE4Fun."""
|
||||
|
@ -7096,21 +7124,21 @@ def _solve_html(*args, **keywords):
|
|||
s.set(**keywords)
|
||||
s.add(*args)
|
||||
if keywords.get('show', False):
|
||||
print "<b>Problem:</b>"
|
||||
print s
|
||||
print("<b>Problem:</b>")
|
||||
print(s)
|
||||
r = s.check()
|
||||
if r == unsat:
|
||||
print "<b>no solution</b>"
|
||||
print("<b>no solution</b>")
|
||||
elif r == unknown:
|
||||
print "<b>failed to solve</b>"
|
||||
print("<b>failed to solve</b>")
|
||||
try:
|
||||
print s.model()
|
||||
print(s.model())
|
||||
except Z3Exception:
|
||||
return
|
||||
else:
|
||||
if keywords.get('show', False):
|
||||
print "<b>Solution:</b>"
|
||||
print s.model()
|
||||
print("<b>Solution:</b>")
|
||||
print(s.model())
|
||||
|
||||
def _solve_using_html(s, *args, **keywords):
|
||||
"""Version of funcion `solve_using` used in RiSE4Fun."""
|
||||
|
@ -7119,21 +7147,21 @@ def _solve_using_html(s, *args, **keywords):
|
|||
s.set(**keywords)
|
||||
s.add(*args)
|
||||
if keywords.get('show', False):
|
||||
print "<b>Problem:</b>"
|
||||
print s
|
||||
print("<b>Problem:</b>")
|
||||
print(s)
|
||||
r = s.check()
|
||||
if r == unsat:
|
||||
print "<b>no solution</b>"
|
||||
print("<b>no solution</b>")
|
||||
elif r == unknown:
|
||||
print "<b>failed to solve</b>"
|
||||
print("<b>failed to solve</b>")
|
||||
try:
|
||||
print s.model()
|
||||
print(s.model())
|
||||
except Z3Exception:
|
||||
return
|
||||
else:
|
||||
if keywords.get('show', False):
|
||||
print "<b>Solution:</b>"
|
||||
print s.model()
|
||||
print("<b>Solution:</b>")
|
||||
print(s.model())
|
||||
|
||||
def _prove_html(claim, **keywords):
|
||||
"""Version of funcion `prove` used in RiSE4Fun."""
|
||||
|
@ -7143,23 +7171,24 @@ def _prove_html(claim, **keywords):
|
|||
s.set(**keywords)
|
||||
s.add(Not(claim))
|
||||
if keywords.get('show', False):
|
||||
print s
|
||||
print(s)
|
||||
r = s.check()
|
||||
if r == unsat:
|
||||
print "<b>proved</b>"
|
||||
print("<b>proved</b>")
|
||||
elif r == unknown:
|
||||
print "<b>failed to prove</b>"
|
||||
print s.model()
|
||||
print("<b>failed to prove</b>")
|
||||
print(s.model())
|
||||
else:
|
||||
print "<b>counterexample</b>"
|
||||
print s.model()
|
||||
print("<b>counterexample</b>")
|
||||
print(s.model())
|
||||
|
||||
def _dict2sarray(sorts, ctx):
|
||||
sz = len(sorts)
|
||||
_names = (Symbol * sz)()
|
||||
_sorts = (Sort * sz) ()
|
||||
i = 0
|
||||
for k, v in sorts.iteritems():
|
||||
for k in sorts:
|
||||
v = sorts[k]
|
||||
if __debug__:
|
||||
_z3_assert(isinstance(k, str), "String expected")
|
||||
_z3_assert(is_sort(v), "Z3 sort expected")
|
||||
|
@ -7173,7 +7202,8 @@ def _dict2darray(decls, ctx):
|
|||
_names = (Symbol * sz)()
|
||||
_decls = (FuncDecl * sz) ()
|
||||
i = 0
|
||||
for k, v in decls.iteritems():
|
||||
for k in decls:
|
||||
v = decls[k]
|
||||
if __debug__:
|
||||
_z3_assert(isinstance(k, str), "String expected")
|
||||
_z3_assert(is_func_decl(v) or is_const(v), "Z3 declaration or constant expected")
|
||||
|
|
|
@ -74,6 +74,15 @@ def _is_add(k):
|
|||
def _is_sub(k):
|
||||
return k == Z3_OP_SUB or k == Z3_OP_BSUB
|
||||
|
||||
import sys
|
||||
if sys.version < '3':
|
||||
import codecs
|
||||
def u(x):
|
||||
return codecs.unicode_escape_decode(x)[0]
|
||||
else:
|
||||
def u(x):
|
||||
return x
|
||||
|
||||
_z3_infix_compact = [ Z3_OP_MUL, Z3_OP_BMUL, Z3_OP_POWER, Z3_OP_DIV, Z3_OP_IDIV, Z3_OP_MOD, Z3_OP_BSDIV, Z3_OP_BSMOD ]
|
||||
|
||||
_ellipses = '...'
|
||||
|
@ -161,15 +170,19 @@ def _get_precedence(k):
|
|||
return _z3_precedence.get(k, 100000)
|
||||
|
||||
_z3_html_op_to_str = {}
|
||||
for _k, _v in _z3_op_to_str.iteritems():
|
||||
for _k in _z3_op_to_str:
|
||||
_v = _z3_op_to_str[_k]
|
||||
_z3_html_op_to_str[_k] = _v
|
||||
for _k, _v in _z3_pre_html_op_to_str.iteritems():
|
||||
for _k in _z3_pre_html_op_to_str:
|
||||
_v = _z3_pre_html_op_to_str[_k]
|
||||
_z3_html_op_to_str[_k] = _v
|
||||
|
||||
_z3_html_precedence = {}
|
||||
for _k, _v in _z3_precedence.iteritems():
|
||||
for _k in _z3_precedence:
|
||||
_v = _z3_precedence[_k]
|
||||
_z3_html_precedence[_k] = _v
|
||||
for _k, _v in _z3_pre_html_precedence.iteritems():
|
||||
for _k in _z3_pre_html_precedence:
|
||||
_v = _z3_pre_html_precedence[_k]
|
||||
_z3_html_precedence[_k] = _v
|
||||
|
||||
_html_infix_map = {}
|
||||
|
@ -237,7 +250,7 @@ class FormatObject:
|
|||
|
||||
class NAryFormatObject(FormatObject):
|
||||
def __init__(self, fs):
|
||||
assert all(map(lambda a: isinstance(a, FormatObject), fs))
|
||||
assert all([isinstance(a, FormatObject) for a in fs])
|
||||
self.children = fs
|
||||
def children(self):
|
||||
return self.children
|
||||
|
@ -246,7 +259,7 @@ class ComposeFormatObject(NAryFormatObject):
|
|||
def is_compose(sef):
|
||||
return True
|
||||
def as_tuple(self):
|
||||
return ('compose', map(lambda a: a.as_tuple(), self.children))
|
||||
return ('compose', [ a.as_tuple() for a in self.children ])
|
||||
def space_upto_nl(self):
|
||||
r = 0
|
||||
for child in self.children:
|
||||
|
@ -256,13 +269,13 @@ class ComposeFormatObject(NAryFormatObject):
|
|||
return (r, True)
|
||||
return (r, False)
|
||||
def flat(self):
|
||||
return compose(map(lambda a: a.flat(), self.children))
|
||||
return compose([a.flat() for a in self.children ])
|
||||
|
||||
class ChoiceFormatObject(NAryFormatObject):
|
||||
def is_choice(sef):
|
||||
return True
|
||||
def as_tuple(self):
|
||||
return ('choice', map(lambda a: a.as_tuple(), self.children))
|
||||
return ('choice', [ a.as_tuple() for a in self.children ])
|
||||
def space_upto_nl(self):
|
||||
return self.children[0].space_upto_nl()
|
||||
def flat(self):
|
||||
|
@ -388,11 +401,11 @@ class PP:
|
|||
if not self.bounded or self.pos <= self.max_width:
|
||||
sz = _len(f)
|
||||
if self.bounded and self.pos + sz > self.max_width:
|
||||
self.out.write(_ellipses)
|
||||
self.out.write(u(_ellipses))
|
||||
else:
|
||||
self.pos = self.pos + sz
|
||||
self.ribbon_pos = self.ribbon_pos + sz
|
||||
self.out.write(unicode(f.string))
|
||||
self.out.write(u(f.string))
|
||||
|
||||
def pp_compose(self, f, indent):
|
||||
for c in f.children:
|
||||
|
@ -410,11 +423,11 @@ class PP:
|
|||
self.ribbon_pos = 0
|
||||
self.line = self.line + 1
|
||||
if self.line < self.max_lines:
|
||||
self.out.write(unicode('\n'))
|
||||
self.out.write(u('\n'))
|
||||
for i in range(indent):
|
||||
self.out.write(unicode(' '))
|
||||
self.out.write(u(' '))
|
||||
else:
|
||||
self.out.write(unicode('\n...'))
|
||||
self.out.write(u('\n...'))
|
||||
raise StopPPException()
|
||||
|
||||
def pp(self, f, indent):
|
||||
|
@ -791,7 +804,11 @@ class Formatter:
|
|||
r.append(self.pp_ellipses())
|
||||
break
|
||||
if sz <= self.max_args:
|
||||
else_pp = self.pp_expr(f.else_value(), 0, [])
|
||||
else_val = f.else_value()
|
||||
if else_val == None:
|
||||
else_pp = to_format('#unspecified')
|
||||
else:
|
||||
else_pp = self.pp_expr(else_val, 0, [])
|
||||
r.append(group(seq((to_format('else'), else_pp), self.pp_arrow())))
|
||||
return seq3(r, '[', ']')
|
||||
|
||||
|
@ -953,23 +970,23 @@ def in_html_mode():
|
|||
|
||||
def pp(a):
|
||||
if _support_pp(a):
|
||||
print obj_to_string(a)
|
||||
print(obj_to_string(a))
|
||||
else:
|
||||
print a
|
||||
print(a)
|
||||
|
||||
def print_matrix(m):
|
||||
z3._z3_assert(isinstance(m, list) or isinstance(m, tuple), "matrix expected")
|
||||
if not in_html_mode():
|
||||
print obj_to_string(m)
|
||||
print(obj_to_string(m))
|
||||
else:
|
||||
print '<table cellpadding="2", cellspacing="0", border="1">'
|
||||
print('<table cellpadding="2", cellspacing="0", border="1">')
|
||||
for r in m:
|
||||
z3._z3_assert(isinstance(r, list) or isinstance(r, tuple), "matrix expected")
|
||||
print '<tr>'
|
||||
print('<tr>')
|
||||
for c in r:
|
||||
print '<td>%s</td>' % c
|
||||
print '</tr>'
|
||||
print '</table>'
|
||||
print('<td>%s</td>' % c)
|
||||
print('</tr>')
|
||||
print('</table>')
|
||||
|
||||
def insert_line_breaks(s, width):
|
||||
"""Break s in lines of size width (approx)"""
|
||||
|
@ -980,9 +997,9 @@ def insert_line_breaks(s, width):
|
|||
w = 0
|
||||
for i in range(sz):
|
||||
if w > width and s[i] == ' ':
|
||||
new_str.write(u'<br />')
|
||||
new_str.write(u('<br />'))
|
||||
w = 0
|
||||
else:
|
||||
new_str.write(unicode(s[i]))
|
||||
new_str.write(u(s[i]))
|
||||
w = w + 1
|
||||
return new_str.getvalue()
|
||||
|
|
|
@ -1080,6 +1080,7 @@ typedef enum {
|
|||
Z3_PK_INVALID
|
||||
} Z3_param_kind;
|
||||
|
||||
#ifdef CorML3
|
||||
/**
|
||||
\mlonly {!search_failure} \endmlonly \conly \brief
|
||||
The different kinds of search failure types.
|
||||
|
@ -1103,6 +1104,7 @@ typedef enum {
|
|||
Z3_THEORY,
|
||||
Z3_QUANTIFIERS
|
||||
} Z3_search_failure;
|
||||
#endif
|
||||
|
||||
/**
|
||||
\mlonly {!ast_print_mode} \endmlonly \conly \brief
|
||||
|
@ -6922,12 +6924,15 @@ END_MLAPI_EXCLUDE
|
|||
);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
@name Deprecated Constraints API
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
#ifdef CorML3
|
||||
/**
|
||||
\brief Set the SMTLIB logic to be used in the given logical context.
|
||||
It is incorrect to invoke this function after invoking
|
||||
|
@ -7109,7 +7114,9 @@ END_MLAPI_EXCLUDE
|
|||
__out Z3_model * m, __out Z3_ast* proof,
|
||||
__inout unsigned* core_size, __inout_ecount(num_assumptions) Z3_ast core[]
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef CorML4
|
||||
/**
|
||||
\brief Retrieve congruence class representatives for terms.
|
||||
|
||||
|
@ -7123,23 +7130,26 @@ END_MLAPI_EXCLUDE
|
|||
This means that two terms map to the same class identifier if and only if
|
||||
the current context implies that they are equal.
|
||||
|
||||
A side-effect of the function is a satisfiability check.
|
||||
A side-effect of the function is a satisfiability check on the assertions on the solver that is passed in.
|
||||
The function return Z3_L_FALSE if the current assertions are not satisfiable.
|
||||
|
||||
\sa Z3_check_and_get_model
|
||||
\sa Z3_check
|
||||
|
||||
\deprecated Subsumed by Z3_solver API
|
||||
\deprecated To be moved outside of API.
|
||||
|
||||
def_API('Z3_get_implied_equalities', UINT, (_in(CONTEXT), _in(UINT), _in_array(1, AST), _out_array(1, UINT)))
|
||||
def_API('Z3_get_implied_equalities', UINT, (_in(CONTEXT), _in(SOLVER), _in(UINT), _in_array(2, AST), _out_array(2, UINT)))
|
||||
*/
|
||||
Z3_lbool Z3_API Z3_get_implied_equalities(
|
||||
__in Z3_context c,
|
||||
__in Z3_solver s,
|
||||
__in unsigned num_terms,
|
||||
__in_ecount(num_terms) Z3_ast const terms[],
|
||||
__out_ecount(num_terms) unsigned class_ids[]
|
||||
);
|
||||
#endif
|
||||
|
||||
#ifdef CorML3
|
||||
/**
|
||||
\brief Delete a model object.
|
||||
|
||||
|
|
|
@ -36,38 +36,6 @@ extern "C" {
|
|||
|
||||
Z3_bool Z3_API Z3_get_numeral_rational(__in Z3_context c, __in Z3_ast a, rational& r);
|
||||
|
||||
/**
|
||||
\brief \mlh exec_smtlib2_string c str \endmlh
|
||||
Parse the given string using the SMT-LIB2 parser and execute its commands.
|
||||
|
||||
It returns a formula comprising of the conjunction of assertions in the scope
|
||||
(up to push/pop) at the end of the string.
|
||||
The returned formula is also asserted to the logical context on return.
|
||||
*/
|
||||
Z3_ast Z3_API Z3_exec_smtlib2_string(__in Z3_context c,
|
||||
__in Z3_string str,
|
||||
__in unsigned num_sorts,
|
||||
__in_ecount(num_sorts) Z3_symbol sort_names[],
|
||||
__in_ecount(num_sorts) Z3_sort sorts[],
|
||||
__in unsigned num_decls,
|
||||
__in_ecount(num_decls) Z3_symbol decl_names[],
|
||||
__in_ecount(num_decls) Z3_func_decl decls[]
|
||||
);
|
||||
|
||||
/**
|
||||
\brief Similar to #Z3_exec_smtlib2_string, but reads the commands from a file.
|
||||
*/
|
||||
Z3_ast Z3_API Z3_exec_smtlib2_file(__in Z3_context c,
|
||||
__in Z3_string file_name,
|
||||
__in unsigned num_sorts,
|
||||
__in_ecount(num_sorts) Z3_symbol sort_names[],
|
||||
__in_ecount(num_sorts) Z3_sort sorts[],
|
||||
__in unsigned num_decls,
|
||||
__in_ecount(num_decls) Z3_symbol decl_names[],
|
||||
__in_ecount(num_decls) Z3_func_decl decls[]
|
||||
);
|
||||
|
||||
|
||||
#ifndef CAMLIDL
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue