Example #1
0
 Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, 
                                     Z3_solver s,
                                     Z3_ast_vector assumptions,
                                     Z3_ast_vector variables,
                                     Z3_ast_vector consequences) {
     Z3_TRY;
     LOG_Z3_solver_get_consequences(c, s, assumptions, variables, consequences);
     ast_manager& m = mk_c(c)->m();
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     init_solver(c, s);
     expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
     ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
     for (ast* e : __assumptions) {
         if (!is_expr(e)) {
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             SET_ERROR_CODE(Z3_INVALID_USAGE, "assumption is not an expression");
             return Z3_L_UNDEF;
         }
         _assumptions.push_back(to_expr(e));
     }
     ast_ref_vector const& __variables = to_ast_vector_ref(variables);
     for (ast* a : __variables) {
         if (!is_expr(a)) {
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             SET_ERROR_CODE(Z3_INVALID_USAGE, "variable is not an expression");
             return Z3_L_UNDEF;
         }
         _variables.push_back(to_expr(a));
     }
     lbool result = l_undef;
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result = to_solver_ref(s)->get_consequences(_assumptions, _variables, _consequences);
         }
         catch (z3_exception & ex) {
             to_solver_ref(s)->set_reason_unknown(eh);
             _assumptions.finalize(); _consequences.finalize(); _variables.finalize();
             mk_c(c)->handle_exception(ex);
             return Z3_L_UNDEF;
         }
     }
     if (result == l_undef) {
         to_solver_ref(s)->set_reason_unknown(eh);
     }
     for (expr* e : _consequences) {
         to_ast_vector_ref(consequences).push_back(e);
     }
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);        
 }
Example #2
0
 static Z3_lbool _solver_check(Z3_context c, Z3_solver s, unsigned num_assumptions, Z3_ast const assumptions[]) {
     for (unsigned i = 0; i < num_assumptions; i++) {
         if (!is_expr(to_ast(assumptions[i]))) {
             SET_ERROR_CODE(Z3_INVALID_ARG, "assumption is not an expression");
             return Z3_L_UNDEF;
         }
     }
     expr * const * _assumptions = to_exprs(assumptions);
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     lbool result;
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result = to_solver_ref(s)->check_sat(num_assumptions, _assumptions);
         }
         catch (z3_exception & ex) {
             to_solver_ref(s)->set_reason_unknown(eh);
             if (!mk_c(c)->m().canceled()) {
                 mk_c(c)->handle_exception(ex);
             }
             return Z3_L_UNDEF;
         }
     }
     if (result == l_undef) {
         to_solver_ref(s)->set_reason_unknown(eh);
     }
     return static_cast<Z3_lbool>(result);
 }
Example #3
0
 bool Z3_API Z3_is_as_array(Z3_context c, Z3_ast a) {
     Z3_TRY;
     LOG_Z3_is_as_array(c, a);
     RESET_ERROR_CODE();
     return a && is_expr(to_ast(a)) && is_app_of(to_expr(a), mk_c(c)->get_array_fid(), OP_AS_ARRAY);
     Z3_CATCH_RETURN(false);
 }
Example #4
0
 bool Z3_algebraic_is_value_core(Z3_context c, Z3_ast a) {
     api::context * _c = mk_c(c);
     return 
         is_expr(a) && 
         (_c->autil().is_numeral(to_expr(a)) || 
          _c->autil().is_irrational_algebraic_numeral(to_expr(a)));
 }
Example #5
0
 Z3_func_decl Z3_API Z3_get_as_array_func_decl(Z3_context c, Z3_ast a) {
     Z3_TRY;
     LOG_Z3_get_as_array_func_decl(c, a);
     RESET_ERROR_CODE();
     if (a && is_expr(to_ast(a)) && is_app_of(to_expr(a), mk_c(c)->get_array_fid(), OP_AS_ARRAY)) {
         RETURN_Z3(of_func_decl(to_func_decl(to_app(a)->get_decl()->get_parameter(0).get_ast())));
     }
     else {
         SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
         RETURN_Z3(nullptr);
     }
     Z3_CATCH_RETURN(nullptr);
 }
Example #6
0
 Z3_bool Z3_API Z3_fpa_is_numeral_negative(Z3_context c, Z3_ast t) {
     Z3_TRY;
     LOG_Z3_fpa_is_numeral_negative(c, t);
     RESET_ERROR_CODE();
     api::context * ctx = mk_c(c);
     fpa_util & fu = ctx->fpautil();
     if (!is_expr(t) || !fu.is_numeral(to_expr(t))) {
         SET_ERROR_CODE(Z3_INVALID_ARG);
         return 0;
     }
     return fu.is_negative(to_expr(t));
     Z3_CATCH_RETURN(Z3_FALSE);
 }
Example #7
0
static int app_builder_mk_app(lua_State * L) {
    int nargs = lua_gettop(L);
    buffer<expr> args;
    app_builder & b = to_app_builder_ref(L, 1)->m_builder;
    bool use_cache  = true;
    name n          = to_name_ext(L, 2);
    for (int i = 3; i <= nargs; i++) {
        if (i < nargs || is_expr(L, i))
            args.push_back(to_expr(L, i));
        else
            use_cache = lua_toboolean(L, i);
    }
    return push_optional_expr(L, b.mk_app(n, args.size(), args.data(), use_cache));
}
Example #8
0
 Z3_lbool Z3_API Z3_solver_get_consequences(Z3_context c, 
                                     Z3_solver s,
                                     Z3_ast_vector assumptions,
                                     Z3_ast_vector variables,
                                     Z3_ast_vector consequences) {
     Z3_TRY;
     LOG_Z3_solver_get_consequences(c, s, assumptions, variables, consequences);
     ast_manager& m = mk_c(c)->m();
     RESET_ERROR_CODE();
     CHECK_SEARCHING(c);
     init_solver(c, s);
     expr_ref_vector _assumptions(m), _consequences(m), _variables(m);
     ast_ref_vector const& __assumptions = to_ast_vector_ref(assumptions);
     unsigned sz = __assumptions.size();
     for (unsigned i = 0; i < sz; ++i) {
         if (!is_expr(__assumptions[i])) {
             SET_ERROR_CODE(Z3_INVALID_USAGE);
             return Z3_L_UNDEF;
         }
         _assumptions.push_back(to_expr(__assumptions[i]));
     }
     ast_ref_vector const& __variables = to_ast_vector_ref(variables);
     sz = __variables.size();
     for (unsigned i = 0; i < sz; ++i) {
         if (!is_expr(__variables[i])) {
             SET_ERROR_CODE(Z3_INVALID_USAGE);
             return Z3_L_UNDEF;
         }
         _variables.push_back(to_expr(__variables[i]));
     }
     lbool result = to_solver_ref(s)->get_consequences(_assumptions, _variables, _consequences);
     for (unsigned i = 0; i < _consequences.size(); ++i) {
         to_ast_vector_ref(consequences).push_back(_consequences[i].get());
     }
     return static_cast<Z3_lbool>(result); 
     Z3_CATCH_RETURN(Z3_L_UNDEF);        
 }
Example #9
0
 Z3_ast Z3_API Z3_get_denominator(Z3_context c, Z3_ast a) {
     Z3_TRY;
     LOG_Z3_get_denominator(c, a);
     RESET_ERROR_CODE();
     rational val;
     ast * _a = to_ast(a);
     if (!is_expr(_a) || !mk_c(c)->autil().is_numeral(to_expr(_a), val)) {
         SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
         RETURN_Z3(nullptr);
     }
     expr * r = mk_c(c)->autil().mk_numeral(denominator(val), true);
     mk_c(c)->save_ast_trail(r);
     RETURN_Z3(of_expr(r));
     Z3_CATCH_RETURN(nullptr);
 }
Example #10
0
bool bv_decl_plugin::get_int2bv_size(unsigned num_parameters, parameter const * parameters, int & result) {
    if (num_parameters != 1) {
        m_manager->raise_exception("int2bv expects one parameter");
        return false;
    }
    const parameter &p = parameters[0];
    if (p.is_int()) {
        result = p.get_int();
        return true;
    }
    if (!p.is_ast() || !is_expr(p.get_ast())) {
        m_manager->raise_exception("int2bv expects one integer parameter");
        return false;
    }
    return get_bv_size(to_expr(p.get_ast()), result);
}
Example #11
0
 Z3_ast_vector Z3_API Z3_solver_cube(Z3_context c, Z3_solver s, Z3_ast_vector vs, unsigned cutoff) {
     Z3_TRY;
     LOG_Z3_solver_cube(c, s, vs, cutoff);
     ast_manager& m = mk_c(c)->m();
     expr_ref_vector result(m), vars(m);
     for (ast* a : to_ast_vector_ref(vs)) {
         if (!is_expr(a)) {
             SET_ERROR_CODE(Z3_INVALID_USAGE, "cube contains a non-expression");
         }
         else {
             vars.push_back(to_expr(a));
         }
     }
     unsigned timeout     = to_solver(s)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit      = to_solver(s)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     bool     use_ctrl_c  = to_solver(s)->m_params.get_bool("ctrl_c", false);
     cancel_eh<reslimit> eh(mk_c(c)->m().limit());
     api::context::set_interruptable si(*(mk_c(c)), eh);
     {
         scoped_ctrl_c ctrlc(eh, false, use_ctrl_c);
         scoped_timer timer(timeout, &eh);
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         try {
             result.append(to_solver_ref(s)->cube(vars, cutoff));
         }
         catch (z3_exception & ex) {
             mk_c(c)->handle_exception(ex);
             return nullptr;
         }
     }
     Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m());
     mk_c(c)->save_object(v);
     for (expr* e : result) {
         v->m_ast_vector.push_back(e);
     }
     to_ast_vector_ref(vs).reset();
     for (expr* a : vars) {
         to_ast_vector_ref(vs).push_back(a);
     }
     RETURN_Z3(of_ast_vector(v));
     Z3_CATCH_RETURN(nullptr);
 }
Example #12
0
expr * get_expr_ref(cmd_context & ctx, symbol const & v) {
    ast * r = get_ast_ref(ctx, v);
    if (!is_expr(r))
        throw cmd_exception("global variable does not reference a term");
    return to_expr(r);
}
Example #13
0
// true if ':-' operator expression
inline int Term::is_rule() const
{
	return is_expr(Operator::RULE);
}
Example #14
0
// true if ';' operator expression
inline int Term::is_or() const
{
	return is_expr(Operator::OR);
}
Example #15
0
// true if ',' operator expression
inline int Term::is_and() const
{
	return is_expr(Operator::AND);
}
Example #16
0
// true if ':-' unary operator expression
inline int Term::is_command() const
{
	return is_expr(Operator::RULEUNARY, 1);
}
Example #17
0
static int has_placeholder(lua_State * L) {
    if (is_expr(L, 1))
        return push_boolean(L, has_placeholder(to_expr(L, 1)));
    else
        return push_boolean(L, has_placeholder(to_level(L, 1)));
}
Example #18
0
// true if '?-' operator expression
inline int Term::is_query() const
{
	return is_expr(Operator::QUERY, 1);
}