Z3_ast_vector Z3_API Z3_algebraic_roots(Z3_context c, Z3_ast p, unsigned n, Z3_ast a[]) { Z3_TRY; LOG_Z3_algebraic_roots(c, p, n, a); RESET_ERROR_CODE(); polynomial::manager & pm = mk_c(c)->pm(); polynomial_ref _p(pm); polynomial::scoped_numeral d(pm.m()); expr2polynomial converter(mk_c(c)->m(), pm, 0, true); if (!converter.to_polynomial(to_expr(p), _p, d) || static_cast<unsigned>(max_var(_p)) >= n + 1) { SET_ERROR_CODE(Z3_INVALID_ARG); return 0; } algebraic_numbers::manager & _am = am(c); scoped_anum_vector as(_am); if (!to_anum_vector(c, n, a, as)) { SET_ERROR_CODE(Z3_INVALID_ARG); return 0; } scoped_anum_vector roots(_am); { cancel_eh<algebraic_numbers::manager> eh(_am); 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); } Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, mk_c(c)->m()); mk_c(c)->save_object(result); for (unsigned i = 0; i < roots.size(); i++) { result->m_ast_vector.push_back(au(c).mk_numeral(roots.get(i), false)); } RETURN_Z3(of_ast_vector(result)); Z3_CATCH_RETURN(0); }
Z3_ast_vector Z3_fixedpoint_from_stream( Z3_context c, Z3_fixedpoint d, std::istream& s) { ast_manager& m = mk_c(c)->m(); dl_collected_cmds coll(m); cmd_context ctx(false, &m); install_dl_collect_cmds(coll, ctx); ctx.set_ignore_check(true); if (!parse_smt2_commands(ctx, s)) { SET_ERROR_CODE(Z3_PARSER_ERROR); return 0; } Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, m); mk_c(c)->save_object(v); for (unsigned i = 0; i < coll.m_queries.size(); ++i) { 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(), 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]); } ptr_vector<expr>::const_iterator it = ctx.begin_assertions(); ptr_vector<expr>::const_iterator end = ctx.end_assertions(); for (; it != end; ++it) { to_fixedpoint_ref(d)->ctx().assert_expr(*it); } return of_ast_vector(v); }
Z3_ast_vector Z3_API Z3_solver_get_trail(Z3_context c, Z3_solver s) { Z3_TRY; LOG_Z3_solver_get_trail(c, s); RESET_ERROR_CODE(); init_solver(c, s); Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m()); mk_c(c)->save_object(v); expr_ref_vector trail = to_solver_ref(s)->get_trail(); for (expr* f : trail) { v->m_ast_vector.push_back(f); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(nullptr); }
Z3_ast_vector Z3_API Z3_solver_get_assertions(Z3_context c, Z3_solver s) { Z3_TRY; LOG_Z3_solver_get_assertions(c, s); RESET_ERROR_CODE(); init_solver(c, s); Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, *mk_c(c), mk_c(c)->m()); mk_c(c)->save_object(v); unsigned sz = to_solver_ref(s)->get_num_assertions(); for (unsigned i = 0; i < sz; i++) { v->m_ast_vector.push_back(to_solver_ref(s)->get_assertion(i)); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(nullptr); }
Z3_ast_vector Z3_API Z3_ast_map_keys(Z3_context c, Z3_ast_map m) { Z3_TRY; LOG_Z3_ast_map_keys(c, m); RESET_ERROR_CODE(); Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, to_ast_map(m)->m); mk_c(c)->save_object(v); obj_map<ast, ast*>::iterator it = to_ast_map_ref(m).begin(); obj_map<ast, ast*>::iterator end = to_ast_map_ref(m).end(); for (; it != end; ++it) { v->m_ast_vector.push_back(it->m_key); } Z3_ast_vector r = of_ast_vector(v); RETURN_Z3(r); Z3_CATCH_RETURN(0); }
Z3_ast_vector Z3_API Z3_solver_get_unsat_core(Z3_context c, Z3_solver s) { Z3_TRY; LOG_Z3_solver_get_unsat_core(c, s); RESET_ERROR_CODE(); init_solver(c, s); ptr_vector<expr> core; to_solver_ref(s)->get_unsat_core(core); Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m()); mk_c(c)->save_object(v); for (unsigned i = 0; i < core.size(); i++) { v->m_ast_vector.push_back(core[i]); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(0); }
Z3_ast_vector Z3_API Z3_fixedpoint_get_assertions( Z3_context c, Z3_fixedpoint d) { Z3_TRY; LOG_Z3_fixedpoint_get_assertions(c, d); ast_manager& m = mk_c(c)->m(); Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, m); mk_c(c)->save_object(v); unsigned num_asserts = to_fixedpoint_ref(d)->ctx().get_num_assertions(); for (unsigned i = 0; i < num_asserts; ++i) { v->m_ast_vector.push_back(to_fixedpoint_ref(d)->ctx().get_assertion(i)); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(0); }
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s) { Z3_TRY; LOG_Z3_model_get_sort_universe(c, m, s); RESET_ERROR_CODE(); if (!to_model_ref(m)->has_uninterpreted_sort(to_sort(s))) { SET_ERROR_CODE(Z3_INVALID_ARG, nullptr); RETURN_Z3(nullptr); } ptr_vector<expr> const & universe = to_model_ref(m)->get_universe(to_sort(s)); 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 : universe) { v->m_ast_vector.push_back(e); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(nullptr); }
Z3_ast_vector Z3_API Z3_model_get_sort_universe(Z3_context c, Z3_model m, Z3_sort s) { Z3_TRY; LOG_Z3_model_get_sort_universe(c, m, s); RESET_ERROR_CODE(); if (!to_model_ref(m)->has_uninterpreted_sort(to_sort(s))) { SET_ERROR_CODE(Z3_INVALID_ARG); RETURN_Z3(0); } ptr_vector<expr> const & universe = to_model_ref(m)->get_universe(to_sort(s)); Z3_ast_vector_ref * v = alloc(Z3_ast_vector_ref, mk_c(c)->m()); mk_c(c)->save_object(v); unsigned sz = universe.size(); for (unsigned i = 0; i < sz; i++) { v->m_ast_vector.push_back(universe[i]); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(0); }
Z3_ast_vector Z3_API Z3_fixedpoint_get_rules_along_trace( Z3_context c, Z3_fixedpoint d) { Z3_TRY; LOG_Z3_fixedpoint_get_rules_along_trace(c, d); ast_manager& m = mk_c(c)->m(); Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, *mk_c(c), m); mk_c(c)->save_object(v); expr_ref_vector rules(m); svector<symbol> names; to_fixedpoint_ref(d)->ctx().get_rules_along_trace_as_formulas(rules, names); for (unsigned i = 0; i < rules.size(); ++i) { v->m_ast_vector.push_back(rules[i].get()); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(nullptr); }
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); }
Z3_ast_vector Z3_API Z3_fixedpoint_simplify_rules( Z3_context c, Z3_fixedpoint d, unsigned num_rules, Z3_ast _rules[], unsigned num_outputs, Z3_func_decl _outputs[]) { Z3_TRY; LOG_Z3_fixedpoint_simplify_rules(c, d, num_rules, _rules, num_outputs, _outputs); RESET_ERROR_CODE(); expr** rules = (expr**)_rules; func_decl** outputs = (func_decl**)_outputs; ast_manager& m = mk_c(c)->m(); expr_ref_vector result(m); to_fixedpoint_ref(d)->simplify_rules(num_rules, rules, num_outputs, outputs, result); Z3_ast_vector_ref* v = alloc(Z3_ast_vector_ref, mk_c(c)->m()); mk_c(c)->save_object(v); for (unsigned i = 0; i < result.size(); ++i) { v->m_ast_vector.push_back(result[i].get()); } RETURN_Z3(of_ast_vector(v)); Z3_CATCH_RETURN(0) }
Z3_ast_vector Z3_API Z3_polynomial_subresultants(Z3_context c, Z3_ast p, Z3_ast q, Z3_ast x) { Z3_TRY; LOG_Z3_polynomial_subresultants(c, p, q, x); RESET_ERROR_CODE(); polynomial::manager & pm = mk_c(c)->pm(); polynomial_ref _p(pm), _q(pm); polynomial::scoped_numeral d(pm.m()); default_expr2polynomial converter(mk_c(c)->m(), pm); if (!converter.to_polynomial(to_expr(p), _p, d) || !converter.to_polynomial(to_expr(q), _q, d)) { SET_ERROR_CODE(Z3_INVALID_ARG); return 0; } Z3_ast_vector_ref* result = alloc(Z3_ast_vector_ref, mk_c(c)->m()); mk_c(c)->save_object(result); if (converter.is_var(to_expr(x))) { expr2var const & mapping = converter.get_mapping(); unsigned v_x = mapping.to_var(to_expr(x)); polynomial_ref_vector rs(pm); polynomial_ref r(pm); expr_ref _r(mk_c(c)->m()); { cancel_eh<polynomial::manager> eh(pm); 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); } for (unsigned i = 0; i < rs.size(); i++) { r = rs.get(i); converter.to_expr(r, true, _r); result->m_ast_vector.push_back(_r); } } RETURN_Z3(of_ast_vector(result)); Z3_CATCH_RETURN(0); }