3
0
Fork 0
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:
Leonardo de Moura 2013-04-09 08:44:57 -07:00
commit f773f35517
177 changed files with 8165 additions and 2548 deletions

View file

@ -373,7 +373,7 @@ extern "C" {
scoped_anum_vector roots(_am);
{
cancel_eh<algebraic_numbers::manager> eh(_am);
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
scoped_timer timer(mk_c(c)->params().m_timeout, &eh);
vector_var2anum v2a(as);
_am.isolate_roots(_p, v2a, roots);
@ -408,7 +408,7 @@ extern "C" {
}
{
cancel_eh<algebraic_numbers::manager> eh(_am);
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
scoped_timer timer(mk_c(c)->params().m_timeout, &eh);
vector_var2anum v2a(as);
int r = _am.eval_sign_at(_p, v2a);

View file

@ -681,7 +681,7 @@ extern "C" {
th_rewriter m_rw(m, p);
expr_ref result(m);
cancel_eh<th_rewriter> eh(m_rw);
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);

View file

@ -266,7 +266,7 @@ extern "C" {
lbool r = l_undef;
cancel_eh<api::fixedpoint_context> eh(*to_fixedpoint_ref(d));
unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_timer timer(timeout, &eh);
try {
@ -291,7 +291,7 @@ extern "C" {
lbool r = l_undef;
unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
cancel_eh<api::fixedpoint_context> eh(*to_fixedpoint_ref(d));
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_timer timer(timeout, &eh);
try {
@ -358,7 +358,7 @@ extern "C" {
v->m_ast_vector.push_back(coll.m_queries[i].get());
}
for (unsigned i = 0; i < coll.m_rels.size(); ++i) {
to_fixedpoint_ref(d)->ctx().register_predicate(coll.m_rels[i].get());
to_fixedpoint_ref(d)->ctx().register_predicate(coll.m_rels[i].get(), true);
}
for (unsigned i = 0; i < coll.m_rules.size(); ++i) {
to_fixedpoint_ref(d)->add_rule(coll.m_rules[i].get(), coll.m_names[i]);
@ -415,7 +415,7 @@ extern "C" {
void Z3_API Z3_fixedpoint_register_relation(Z3_context c,Z3_fixedpoint d, Z3_func_decl f) {
Z3_TRY;
LOG_Z3_fixedpoint_register_relation(c, d, f);
to_fixedpoint_ref(d)->ctx().register_predicate(to_func_decl(f));
to_fixedpoint_ref(d)->ctx().register_predicate(to_func_decl(f), true);
Z3_CATCH;
}

View file

@ -67,7 +67,7 @@ extern "C" {
expr_ref _r(mk_c(c)->m());
{
cancel_eh<polynomial::manager> eh(pm);
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
scoped_timer timer(mk_c(c)->params().m_timeout, &eh);
pm.psc_chain(_p, _q, v_x, rs);
}

View file

@ -243,7 +243,7 @@ extern "C" {
unsigned timeout = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
bool use_ctrl_c = to_solver(s)->m_params.get_bool("ctrl_c", false);
cancel_eh<solver> eh(*to_solver_ref(s));
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
lbool result;
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);

View file

@ -73,7 +73,7 @@ extern "C" {
RESET_ERROR_CODE();
CHECK_SEARCHING(c);
cancel_eh<smt::kernel> eh(mk_c(c)->get_smt_kernel());
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
flet<bool> _model(mk_c(c)->fparams().m_model, true);
lbool result;
try {
@ -123,7 +123,7 @@ extern "C" {
expr * const* _assumptions = to_exprs(assumptions);
flet<bool> _model(mk_c(c)->fparams().m_model, true);
cancel_eh<smt::kernel> eh(mk_c(c)->get_smt_kernel());
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
lbool result;
result = mk_c(c)->get_smt_kernel().check(num_assumptions, _assumptions);
if (result != l_false && m) {

View file

@ -410,7 +410,7 @@ extern "C" {
to_tactic_ref(t)->updt_params(p);
api::context::set_interruptable(*(mk_c(c)), eh);
api::context::set_interruptable si(*(mk_c(c)), eh);
{
scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
scoped_timer timer(timeout, &eh);

View file

@ -63,6 +63,11 @@ namespace z3 {
class statistics;
class apply_result;
class fixedpoint;
template<typename T> class ast_vector_tpl;
typedef ast_vector_tpl<ast> ast_vector;
typedef ast_vector_tpl<expr> expr_vector;
typedef ast_vector_tpl<sort> sort_vector;
typedef ast_vector_tpl<func_decl> func_decl_vector;
inline void set_param(char const * param, char const * value) { Z3_global_param_set(param, value); }
inline void set_param(char const * param, bool value) { Z3_global_param_set(param, value ? "true" : "false"); }
@ -190,7 +195,13 @@ namespace z3 {
Example: Given a context \c c, <tt>c.array_sort(c.int_sort(), c.bool_sort())</tt> is an array sort from integer to Boolean.
*/
sort array_sort(sort d, sort r);
/**
\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,
and in \c ts the predicates for testing if terms of the enumeration sort correspond to an enumeration.
*/
sort enumeration_sort(char const * name, unsigned n, char const * const * enum_names, func_decl_vector & cs, func_decl_vector & ts);
func_decl function(symbol const & name, unsigned arity, sort const * domain, sort const & range);
func_decl function(char const * name, unsigned arity, sort const * domain, sort const & range);
func_decl function(char const * name, sort const & domain, sort const & range);
@ -240,8 +251,8 @@ namespace z3 {
array(unsigned sz):m_size(sz) { m_array = new T[sz]; }
~array() { delete[] m_array; }
unsigned size() const { return m_size; }
T & operator[](unsigned i) { assert(i < m_size); return m_array[i]; }
T const & operator[](unsigned i) const { assert(i < m_size); return m_array[i]; }
T & operator[](int i) { assert(0 <= i); assert(static_cast<unsigned>(i) < m_size); return m_array[i]; }
T const & operator[](int i) const { assert(0 <= i); assert(static_cast<unsigned>(i) < m_size); return m_array[i]; }
T const * ptr() const { return m_array; }
T * ptr() { return m_array; }
};
@ -414,6 +425,7 @@ namespace z3 {
bool is_const() const { return arity() == 0; }
expr operator()() const;
expr operator()(unsigned n, expr const * args) const;
expr operator()(expr const & a) const;
expr operator()(int a) const;
@ -1004,7 +1016,7 @@ namespace z3 {
~ast_vector_tpl() { Z3_ast_vector_dec_ref(ctx(), m_vector); }
operator Z3_ast_vector() const { return m_vector; }
unsigned size() const { return Z3_ast_vector_size(ctx(), m_vector); }
T operator[](unsigned i) const { Z3_ast r = Z3_ast_vector_get(ctx(), m_vector, i); check_error(); return cast_ast<T>()(ctx(), r); }
T operator[](int i) const { assert(0 <= i); Z3_ast r = Z3_ast_vector_get(ctx(), m_vector, i); check_error(); return cast_ast<T>()(ctx(), r); }
void push_back(T const & e) { Z3_ast_vector_push(ctx(), m_vector, e); check_error(); }
void resize(unsigned sz) { Z3_ast_vector_resize(ctx(), m_vector, sz); check_error(); }
T back() const { return operator[](size() - 1); }
@ -1020,11 +1032,6 @@ namespace z3 {
friend std::ostream & operator<<(std::ostream & out, ast_vector_tpl const & v) { out << Z3_ast_vector_to_string(v.ctx(), v); return out; }
};
typedef ast_vector_tpl<ast> ast_vector;
typedef ast_vector_tpl<expr> expr_vector;
typedef ast_vector_tpl<sort> sort_vector;
typedef ast_vector_tpl<func_decl> func_decl_vector;
class func_entry : public object {
Z3_func_entry m_entry;
void init(Z3_func_entry e) {
@ -1105,7 +1112,10 @@ namespace z3 {
func_decl get_const_decl(unsigned i) const { Z3_func_decl r = Z3_model_get_const_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
func_decl get_func_decl(unsigned i) const { Z3_func_decl r = Z3_model_get_func_decl(ctx(), m_model, i); check_error(); return func_decl(ctx(), r); }
unsigned size() const { return num_consts() + num_funcs(); }
func_decl operator[](unsigned i) const { return i < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts()); }
func_decl operator[](int i) const {
assert(0 <= i);
return static_cast<unsigned>(i) < num_consts() ? get_const_decl(i) : get_func_decl(i - num_consts());
}
expr get_const_interp(func_decl c) const {
check_context(*this, c);
@ -1253,7 +1263,7 @@ namespace z3 {
}
void add(expr const & f) { check_context(*this, f); Z3_goal_assert(ctx(), m_goal, f); check_error(); }
unsigned size() const { return Z3_goal_size(ctx(), m_goal); }
expr operator[](unsigned i) const { Z3_ast r = Z3_goal_formula(ctx(), m_goal, i); check_error(); return expr(ctx(), r); }
expr operator[](int i) const { assert(0 <= i); Z3_ast r = Z3_goal_formula(ctx(), m_goal, i); check_error(); return expr(ctx(), r); }
Z3_goal_prec precision() const { return Z3_goal_precision(ctx(), m_goal); }
bool inconsistent() const { return Z3_goal_inconsistent(ctx(), m_goal) != 0; }
unsigned depth() const { return Z3_goal_depth(ctx(), m_goal); }
@ -1261,6 +1271,19 @@ namespace z3 {
unsigned num_exprs() const { return Z3_goal_num_exprs(ctx(), m_goal); }
bool is_decided_sat() const { return Z3_goal_is_decided_sat(ctx(), m_goal) != 0; }
bool is_decided_unsat() const { return Z3_goal_is_decided_unsat(ctx(), m_goal) != 0; }
expr as_expr() const {
unsigned n = size();
if (n == 0)
return ctx().bool_val(false);
else if (n == 1)
return operator[](0);
else {
array<Z3_ast> args(n);
for (unsigned i = 0; i < n; i++)
args[i] = operator[](i);
return expr(ctx(), Z3_mk_and(ctx(), n, args.ptr()));
}
}
friend std::ostream & operator<<(std::ostream & out, goal const & g) { out << Z3_goal_to_string(g.ctx(), g); return out; }
};
@ -1283,8 +1306,7 @@ namespace z3 {
return *this;
}
unsigned size() const { return Z3_apply_result_get_num_subgoals(ctx(), m_apply_result); }
goal operator[](unsigned i) const { Z3_goal r = Z3_apply_result_get_subgoal(ctx(), m_apply_result, i); check_error(); return goal(ctx(), r); }
goal operator[](int i) const { assert(i >= 0); return this->operator[](static_cast<unsigned>(i)); }
goal operator[](int i) const { assert(0 <= i); Z3_goal r = Z3_apply_result_get_subgoal(ctx(), m_apply_result, i); check_error(); return goal(ctx(), r); }
model convert_model(model const & m, unsigned i = 0) const {
check_context(*this, m);
Z3_model new_m = Z3_apply_result_convert_model(ctx(), m_apply_result, i, m);
@ -1437,6 +1459,17 @@ namespace z3 {
inline sort context::real_sort() { Z3_sort s = Z3_mk_real_sort(m_ctx); check_error(); return sort(*this, s); }
inline sort context::bv_sort(unsigned sz) { Z3_sort s = Z3_mk_bv_sort(m_ctx, sz); check_error(); return sort(*this, s); }
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::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);
for (unsigned i = 0; i < n; i++) { _enum_names[i] = Z3_mk_string_symbol(*this, enum_names[i]); }
array<Z3_func_decl> _cs(n);
array<Z3_func_decl> _ts(n);
Z3_symbol _name = Z3_mk_string_symbol(*this, name);
sort s = to_sort(*this, Z3_mk_enumeration_sort(*this, _name, n, _enum_names.ptr(), _cs.ptr(), _ts.ptr()));
check_error();
for (unsigned i = 0; i < n; i++) { cs.push_back(func_decl(*this, _cs[i])); ts.push_back(func_decl(*this, _ts[i])); }
return s;
}
inline func_decl context::function(symbol const & name, unsigned arity, sort const * domain, sort const & range) {
array<Z3_sort> args(arity);
@ -1538,6 +1571,11 @@ namespace z3 {
return expr(ctx(), r);
}
inline expr func_decl::operator()() const {
Z3_ast r = Z3_mk_app(ctx(), *this, 0, 0);
ctx().check_error();
return expr(ctx(), r);
}
inline expr func_decl::operator()(expr const & a) const {
check_context(*this, a);
Z3_ast args[1] = { a };

View file

@ -34,8 +34,7 @@ namespace Microsoft.Z3
public uint NumFields
{
get
{
init();
{
return n;
}
}
@ -48,8 +47,11 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
init();
return m_constructorDecl;
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
Native.Z3_query_constructor(Context.nCtx, NativeObject, n, ref constructor, ref tester, accessors);
return new FuncDecl(Context, constructor);
}
}
@ -61,8 +63,11 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
init();
return m_testerDecl;
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
Native.Z3_query_constructor(Context.nCtx, NativeObject, n, ref constructor, ref tester, accessors);
return new FuncDecl(Context, tester);
}
}
@ -74,8 +79,14 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
init();
return m_accessorDecls;
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
Native.Z3_query_constructor(Context.nCtx, NativeObject, n, ref constructor, ref tester, accessors);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
t[i] = new FuncDecl(Context, accessors[i]);
return t;
}
}
@ -85,25 +96,11 @@ namespace Microsoft.Z3
~Constructor()
{
Native.Z3_del_constructor(Context.nCtx, NativeObject);
}
#region Object invariant
[ContractInvariantMethod]
private void ObjectInvariant()
{
Contract.Invariant(m_testerDecl == null || m_constructorDecl != null);
Contract.Invariant(m_testerDecl == null || m_accessorDecls != null);
}
#endregion
}
#region Internal
readonly private uint n = 0;
private FuncDecl m_testerDecl = null;
private FuncDecl m_constructorDecl = null;
private FuncDecl[] m_accessorDecls = null;
private uint n = 0;
internal Constructor(Context ctx, Symbol name, Symbol recognizer, Symbol[] fieldNames,
Sort[] sorts, uint[] sortRefs)
: base(ctx)
@ -129,24 +126,6 @@ namespace Microsoft.Z3
}
private void init()
{
Contract.Ensures(m_constructorDecl != null);
Contract.Ensures(m_testerDecl != null);
Contract.Ensures(m_accessorDecls != null);
if (m_testerDecl != null) return;
IntPtr constructor = IntPtr.Zero;
IntPtr tester = IntPtr.Zero;
IntPtr[] accessors = new IntPtr[n];
Native.Z3_query_constructor(Context.nCtx, NativeObject, n, ref constructor, ref tester, accessors);
m_constructorDecl = new FuncDecl(Context, constructor);
m_testerDecl = new FuncDecl(Context, tester);
m_accessorDecls = new FuncDecl[n];
for (uint i = 0; i < n; i++)
m_accessorDecls[i] = new FuncDecl(Context, accessors[i]);
}
#endregion
}
}

View file

@ -36,8 +36,11 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
return _constdecls;
uint n = Native.Z3_get_datatype_sort_num_constructors(Context.nCtx, NativeObject);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
t[i] = new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor(Context.nCtx, NativeObject, i));
return t;
}
}
@ -49,8 +52,11 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<Expr[]>() != null);
return _consts;
FuncDecl[] cds = ConstDecls;
Expr[] t = new Expr[cds.Length];
for (uint i = 0; i < t.Length; i++)
t[i] = Context.MkApp(cds[i]);
return t;
}
}
@ -62,28 +68,15 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl[]>() != null);
return _testerdecls;
uint n = Native.Z3_get_datatype_sort_num_constructors(Context.nCtx, NativeObject);
FuncDecl[] t = new FuncDecl[n];
for (uint i = 0; i < n; i++)
t[i] = new FuncDecl(Context, Native.Z3_get_datatype_sort_recognizer(Context.nCtx, NativeObject, i));
return t;
}
}
#region Object Invariant
[ContractInvariantMethod]
private void ObjectInvariant()
{
Contract.Invariant(this._constdecls != null);
Contract.Invariant(this._testerdecls != null);
Contract.Invariant(this._consts != null);
}
#endregion
#region Internal
readonly private FuncDecl[] _constdecls = null, _testerdecls = null;
readonly private Expr[] _consts = null;
internal EnumSort(Context ctx, Symbol name, Symbol[] enumNames)
: base(ctx)
{
@ -96,15 +89,6 @@ namespace Microsoft.Z3
IntPtr[] n_testers = new IntPtr[n];
NativeObject = Native.Z3_mk_enumeration_sort(ctx.nCtx, name.NativeObject, (uint)n,
Symbol.ArrayToNative(enumNames), n_constdecls, n_testers);
_constdecls = new FuncDecl[n];
for (uint i = 0; i < n; i++)
_constdecls[i] = new FuncDecl(ctx, n_constdecls[i]);
_testerdecls = new FuncDecl[n];
for (uint i = 0; i < n; i++)
_testerdecls[i] = new FuncDecl(ctx, n_testers[i]);
_consts = new Expr[n];
for (uint i = 0; i < n; i++)
_consts[i] = ctx.MkApp(_constdecls[i]);
}
#endregion
};

View file

@ -78,6 +78,14 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Alias for Assert.
/// </summary>
public void Add(params BoolExpr[] constraints)
{
Assert(constraints);
}
/// <summary>
/// Register predicate as recursive relation.
/// </summary>

View file

@ -90,6 +90,14 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Alias for Assert.
/// </summary>
public void Add(params BoolExpr[] constraints)
{
Assert(constraints);
}
/// <summary>
/// Indicates whether the goal contains `false'.
/// </summary>

View file

@ -36,7 +36,7 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return nilDecl;
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor(Context.nCtx, NativeObject, 0));
}
}
@ -48,7 +48,7 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<Expr>() != null);
return nilConst;
return Context.MkApp(NilDecl);
}
}
@ -60,7 +60,7 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return isNilDecl;
return new FuncDecl(Context, Native.Z3_get_datatype_sort_recognizer(Context.nCtx, NativeObject, 0));
}
}
@ -72,7 +72,7 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return consDecl;
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor(Context.nCtx, NativeObject, 1));
}
}
@ -85,7 +85,7 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return isConsDecl;
return new FuncDecl(Context, Native.Z3_get_datatype_sort_recognizer(Context.nCtx, NativeObject, 1));
}
}
@ -97,7 +97,7 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return headDecl;
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor_accessor(Context.nCtx, NativeObject, 1, 0));
}
}
@ -109,31 +109,11 @@ namespace Microsoft.Z3
get
{
Contract.Ensures(Contract.Result<FuncDecl>() != null);
return tailDecl;
return new FuncDecl(Context, Native.Z3_get_datatype_sort_constructor_accessor(Context.nCtx, NativeObject, 1, 1));
}
}
#region Object Invariant
[ContractInvariantMethod]
private void ObjectInvariant()
{
Contract.Invariant(nilConst != null);
Contract.Invariant(nilDecl != null);
Contract.Invariant(isNilDecl != null);
Contract.Invariant(consDecl != null);
Contract.Invariant(isConsDecl != null);
Contract.Invariant(headDecl != null);
Contract.Invariant(tailDecl != null);
}
#endregion
#region Internal
readonly private FuncDecl nilDecl, isNilDecl, consDecl, isConsDecl, headDecl, tailDecl;
readonly private Expr nilConst;
#region Internal
internal ListSort(Context ctx, Symbol name, Sort elemSort)
: base(ctx)
{
@ -141,22 +121,12 @@ namespace Microsoft.Z3
Contract.Requires(name != null);
Contract.Requires(elemSort != null);
IntPtr inil = IntPtr.Zero,
iisnil = IntPtr.Zero,
icons = IntPtr.Zero,
iiscons = IntPtr.Zero,
ihead = IntPtr.Zero,
itail = IntPtr.Zero;
IntPtr inil = IntPtr.Zero, iisnil = IntPtr.Zero,
icons = IntPtr.Zero, iiscons = IntPtr.Zero,
ihead = IntPtr.Zero, itail = IntPtr.Zero;
NativeObject = Native.Z3_mk_list_sort(ctx.nCtx, name.NativeObject, elemSort.NativeObject,
ref inil, ref iisnil, ref icons, ref iiscons, ref ihead, ref itail);
nilDecl = new FuncDecl(ctx, inil);
isNilDecl = new FuncDecl(ctx, iisnil);
consDecl = new FuncDecl(ctx, icons);
isConsDecl = new FuncDecl(ctx, iiscons);
headDecl = new FuncDecl(ctx, ihead);
tailDecl = new FuncDecl(ctx, itail);
nilConst = ctx.MkConst(nilDecl);
ref inil, ref iisnil, ref icons, ref iiscons, ref ihead, ref itail);
}
#endregion
};

View file

@ -117,6 +117,14 @@ namespace Microsoft.Z3
}
}
/// <summary>
/// Alias for Assert.
/// </summary>
public void Add(params BoolExpr[] constraints)
{
Assert(constraints);
}
/// <summary>
/// Assert multiple constraints into the solver, and track them (in the unsat) core
/// using the Boolean constants in ps.

View file

@ -16,8 +16,7 @@ public class Constructor extends Z3Object
* @throws Z3Exception
**/
public int getNumFields() throws Z3Exception
{
init();
{
return n;
}
@ -27,8 +26,11 @@ public class Constructor extends Z3Object
**/
public FuncDecl ConstructorDecl() throws Z3Exception
{
init();
return m_constructorDecl;
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n, constructor, tester, accessors);
return new FuncDecl(getContext(), constructor.value);
}
/**
@ -37,8 +39,11 @@ public class Constructor extends Z3Object
**/
public FuncDecl getTesterDecl() throws Z3Exception
{
init();
return m_testerDecl;
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n, constructor, tester, accessors);
return new FuncDecl(getContext(), tester.value);
}
/**
@ -47,8 +52,14 @@ public class Constructor extends Z3Object
**/
public FuncDecl[] getAccessorDecls() throws Z3Exception
{
init();
return m_accessorDecls;
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n, constructor, tester, accessors);
FuncDecl[] t = new FuncDecl[n];
for (int i = 0; i < n; i++)
t[i] = new FuncDecl(getContext(), accessors[i]);
return t;
}
/**
@ -60,9 +71,6 @@ public class Constructor extends Z3Object
}
private int n = 0;
private FuncDecl m_testerDecl = null;
private FuncDecl m_constructorDecl = null;
private FuncDecl[] m_accessorDecls = null;
Constructor(Context ctx, Symbol name, Symbol recognizer,
Symbol[] fieldNames, Sort[] sorts, int[] sortRefs)
@ -87,21 +95,4 @@ public class Constructor extends Z3Object
Sort.arrayToNative(sorts), sortRefs));
}
private void init() throws Z3Exception
{
if (m_testerDecl != null)
return;
Native.LongPtr constructor = new Native.LongPtr();
Native.LongPtr tester = new Native.LongPtr();
long[] accessors = new long[n];
Native.queryConstructor(getContext().nCtx(), getNativeObject(), n,
constructor, tester, accessors);
m_constructorDecl = new FuncDecl(getContext(), constructor.value);
m_testerDecl = new FuncDecl(getContext(), tester.value);
m_accessorDecls = new FuncDecl[n];
for (int i = 0; i < n; i++)
m_accessorDecls[i] = new FuncDecl(getContext(), accessors[i]);
}
}

View file

@ -14,30 +14,39 @@ public class EnumSort extends Sort
/**
* The function declarations of the constants in the enumeration.
**/
public FuncDecl[] getConstDecls()
public FuncDecl[] getConstDecls() throws Z3Exception
{
return _constdecls;
int n = Native.getDatatypeSortNumConstructors(getContext().nCtx(), getNativeObject());
FuncDecl[] t = new FuncDecl[n];
for (int i = 0; i < n; i++)
t[i] = new FuncDecl(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), i));
return t;
}
/**
* The constants in the enumeration.
**/
public Expr[] getConsts()
{
return _consts;
public Expr[] getConsts() throws Z3Exception
{
FuncDecl[] cds = getConstDecls();
Expr[] t = new Expr[cds.length];
for (int i = 0; i < t.length; i++)
t[i] = getContext().mkApp(cds[i]);
return t;
}
/**
* The test predicates for the constants in the enumeration.
**/
public FuncDecl[] getTesterDecls()
public FuncDecl[] getTesterDecls() throws Z3Exception
{
return _testerdecls;
int n = Native.getDatatypeSortNumConstructors(getContext().nCtx(), getNativeObject());
FuncDecl[] t = new FuncDecl[n];
for (int i = 0; i < n; i++)
t[i] = new FuncDecl(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), i));
return t;
}
private FuncDecl[] _constdecls = null, _testerdecls = null;
private Expr[] _consts = null;
EnumSort(Context ctx, Symbol name, Symbol[] enumNames) throws Z3Exception
{
super(ctx);
@ -47,15 +56,6 @@ public class EnumSort extends Sort
long[] n_testers = new long[n];
setNativeObject(Native.mkEnumerationSort(ctx.nCtx(),
name.getNativeObject(), (int) n, Symbol.arrayToNative(enumNames),
n_constdecls, n_testers));
_constdecls = new FuncDecl[n];
for (int i = 0; i < n; i++)
_constdecls[i] = new FuncDecl(ctx, n_constdecls[i]);
_testerdecls = new FuncDecl[n];
for (int i = 0; i < n; i++)
_testerdecls[i] = new FuncDecl(ctx, n_testers[i]);
_consts = new Expr[n];
for (int i = 0; i < n; i++)
_consts[i] = ctx.mkApp(_constdecls[i], (Expr[])null);
n_constdecls, n_testers));
}
};

View file

@ -51,7 +51,7 @@ public class Fixedpoint extends Z3Object
*
* @throws Z3Exception
**/
public void assert_(BoolExpr ... constraints) throws Z3Exception
public void add(BoolExpr ... constraints) throws Z3Exception
{
getContext().checkContextMatch(constraints);
for (BoolExpr a : constraints)

View file

@ -65,7 +65,7 @@ public class Goal extends Z3Object
*
* @throws Z3Exception
**/
public void assert_(BoolExpr ... constraints) throws Z3Exception
public void add(BoolExpr ... constraints) throws Z3Exception
{
getContext().checkContextMatch(constraints);
for (BoolExpr c : constraints)

View file

@ -13,65 +13,68 @@ public class ListSort extends Sort
{
/**
* The declaration of the nil function of this list sort.
* @throws Z3Exception
**/
public FuncDecl getNilDecl()
public FuncDecl getNilDecl() throws Z3Exception
{
return nilDecl;
return new FuncDecl(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), 0));
}
/**
* The empty list.
* @throws Z3Exception
**/
public Expr getNil()
public Expr getNil() throws Z3Exception
{
return nilConst;
return getContext().mkApp(getNilDecl());
}
/**
* The declaration of the isNil function of this list sort.
* @throws Z3Exception
**/
public FuncDecl getIsNilDecl()
public FuncDecl getIsNilDecl() throws Z3Exception
{
return isNilDecl;
return new FuncDecl(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), 0));
}
/**
* The declaration of the cons function of this list sort.
* @throws Z3Exception
**/
public FuncDecl getConsDecl()
public FuncDecl getConsDecl() throws Z3Exception
{
return consDecl;
return new FuncDecl(getContext(), Native.getDatatypeSortConstructor(getContext().nCtx(), getNativeObject(), 1));
}
/**
* The declaration of the isCons function of this list sort.
* @throws Z3Exception
*
**/
public FuncDecl getIsConsDecl()
public FuncDecl getIsConsDecl() throws Z3Exception
{
return isConsDecl;
return new FuncDecl(getContext(), Native.getDatatypeSortRecognizer(getContext().nCtx(), getNativeObject(), 1));
}
/**
* The declaration of the head function of this list sort.
* @throws Z3Exception
**/
public FuncDecl getHeadDecl()
public FuncDecl getHeadDecl() throws Z3Exception
{
return headDecl;
return new FuncDecl(getContext(), Native.getDatatypeSortConstructorAccessor(getContext().nCtx(), getNativeObject(), 1, 0));
}
/**
* The declaration of the tail function of this list sort.
* @throws Z3Exception
**/
public FuncDecl getTailDecl()
public FuncDecl getTailDecl() throws Z3Exception
{
return tailDecl;
return new FuncDecl(getContext(), Native.getDatatypeSortConstructorAccessor(getContext().nCtx(), getNativeObject(), 1, 1));
}
private FuncDecl nilDecl, isNilDecl, consDecl, isConsDecl, headDecl,
tailDecl;
private Expr nilConst;
ListSort(Context ctx, Symbol name, Sort elemSort) throws Z3Exception
{
super(ctx);
@ -83,12 +86,5 @@ public class ListSort extends Sort
setNativeObject(Native.mkListSort(ctx.nCtx(), name.getNativeObject(),
elemSort.getNativeObject(), inil, iisnil, icons, iiscons, ihead,
itail));
nilDecl = new FuncDecl(ctx, inil.value);
isNilDecl = new FuncDecl(ctx, iisnil.value);
consDecl = new FuncDecl(ctx, icons.value);
isConsDecl = new FuncDecl(ctx, iiscons.value);
headDecl = new FuncDecl(ctx, ihead.value);
tailDecl = new FuncDecl(ctx, itail.value);
nilConst = ctx.mkConst(nilDecl);
}
};

View file

@ -94,7 +94,7 @@ public class Solver extends Z3Object
*
* @throws Z3Exception
**/
public void assert_(BoolExpr... constraints) throws Z3Exception
public void add(BoolExpr... constraints) throws Z3Exception
{
getContext().checkContextMatch(constraints);
for (BoolExpr a : constraints)

View file

@ -701,7 +701,7 @@ typedef enum
over Boolean connectives 'and' and 'or'.
- Z3_OP_PR_NFF_NEG: Proof for a (negative) NNF step. Examples:
- Z3_OP_PR_NNF_NEG: Proof for a (negative) NNF step. Examples:
\nicebox{
T1: (not s_1) ~ r_1
...