示例#1
0
文件: api_solver.cpp 项目: levnach/z3
 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);
 }
示例#2
0
 virtual void execute(cmd_context & ctx) {
     if (m_target == 0)
         throw cmd_exception("invalid simplify command, argument expected");
     expr_ref r(ctx.m());
     proof_ref pr(ctx.m());
     if (m_params.get_bool("som", false))
         m_params.set_bool("flat", true);
     th_rewriter s(ctx.m(), m_params);
     unsigned cache_sz;
     unsigned num_steps = 0;
     unsigned timeout   = m_params.get_uint("timeout", UINT_MAX);
     unsigned rlimit    = m_params.get_uint("rlimit", UINT_MAX);
     bool failed = false;
     cancel_eh<reslimit> eh(ctx.m().limit());
     { 
         scoped_rlimit _rlimit(ctx.m().limit(), rlimit);
         scoped_ctrl_c ctrlc(eh);
         scoped_timer timer(timeout, &eh);
         cmd_context::scoped_watch sw(ctx);
         try {
             s(m_target, r, pr);
         }
         catch (z3_error & ex) {
             throw ex;
         }
         catch (z3_exception & ex) {
             ctx.regular_stream() << "(error \"simplifier failed: " << ex.msg() << "\")" << std::endl;
             failed = true;
             r = m_target;
         }
         cache_sz  = s.get_cache_size();
         num_steps = s.get_num_steps();
         s.cleanup();
     }
     if (m_params.get_bool("print", true)) {
         ctx.display(ctx.regular_stream(), r);
         ctx.regular_stream() << std::endl; 
     }
     if (!failed && m_params.get_bool("print_proofs", false)) {
         ast_smt_pp pp(ctx.m());
         pp.set_logic(ctx.get_logic().str().c_str());
         pp.display_expr_smt2(ctx.regular_stream(), pr.get());
         ctx.regular_stream() << std::endl;
     }
     if (m_params.get_bool("print_statistics", false)) {
         shared_occs s1(ctx.m());
         if (!failed)
             s1(r);
         unsigned long long max_mem = memory::get_max_used_memory();
         unsigned long long mem = memory::get_allocation_size();
         ctx.regular_stream() << "(:time " << std::fixed << std::setprecision(2) << ctx.get_seconds() << " :num-steps " << num_steps
                              << " :memory " << std::fixed << std::setprecision(2) << static_cast<double>(mem)/static_cast<double>(1024*1024)
                              << " :max-memory " << std::fixed << std::setprecision(2) << static_cast<double>(max_mem)/static_cast<double>(1024*1024)
                              << " :cache-size: " << cache_sz
                              << " :num-nodes-before " << get_num_exprs(m_target);
         if (!failed)
             ctx.regular_stream() << " :num-shared " << s1.num_shared() << " :num-nodes " << get_num_exprs(r);
         ctx.regular_stream() << ")" << std::endl;
     }
 }
示例#3
0
文件: api_solver.cpp 项目: levnach/z3
 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);        
 }
示例#4
0
文件: api_solver.cpp 项目: levnach/z3
 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);
 }
示例#5
0
 Z3_lbool Z3_API Z3_fixedpoint_query(Z3_context c,Z3_fixedpoint d, Z3_ast q) {
     Z3_TRY;
     LOG_Z3_fixedpoint_query(c, d, q);
     RESET_ERROR_CODE();
     lbool r = l_undef;
     unsigned timeout = to_fixedpoint(d)->m_params.get_uint("timeout", mk_c(c)->get_timeout());
     unsigned rlimit  = to_fixedpoint(d)->m_params.get_uint("rlimit", mk_c(c)->get_rlimit());
     {
         scoped_rlimit _rlimit(mk_c(c)->m().limit(), rlimit);
         cancel_eh<reslimit> eh(mk_c(c)->m().limit());
         api::context::set_interruptable si(*(mk_c(c)), eh);
         scoped_timer timer(timeout, &eh);
         try {
             r = to_fixedpoint_ref(d)->ctx().query(to_expr(q));
         }
         catch (z3_exception& ex) {
             mk_c(c)->handle_exception(ex);
             r = l_undef;
         }
         to_fixedpoint_ref(d)->ctx().cleanup();
     }
     return of_lbool(r);
     Z3_CATCH_RETURN(Z3_L_UNDEF);
 }