mirror of
https://github.com/Z3Prover/z3
synced 2025-05-13 10:44:43 +00:00
add recfun to API
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
c5cbf985ca
commit
51a0022450
11 changed files with 191 additions and 42 deletions
|
@ -38,6 +38,8 @@ Revision History:
|
|||
#include "util/cancel_eh.h"
|
||||
#include "util/scoped_timer.h"
|
||||
#include "ast/pp_params.hpp"
|
||||
#include "ast/expr_abstract.h"
|
||||
|
||||
|
||||
extern bool is_numeral_sort(Z3_context c, Z3_sort ty);
|
||||
|
||||
|
@ -110,6 +112,54 @@ extern "C" {
|
|||
Z3_CATCH_RETURN(nullptr);
|
||||
}
|
||||
|
||||
Z3_func_decl Z3_API Z3_mk_rec_func_decl(Z3_context c, Z3_symbol s, unsigned domain_size, Z3_sort const* domain,
|
||||
Z3_sort range) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_rec_func_decl(c, s, domain_size, domain, range);
|
||||
RESET_ERROR_CODE();
|
||||
//
|
||||
recfun::promise_def def =
|
||||
mk_c(c)->recfun().get_plugin().mk_def(to_symbol(s),
|
||||
domain_size,
|
||||
to_sorts(domain),
|
||||
to_sort(range));
|
||||
func_decl* d = def.get_def()->get_decl();
|
||||
mk_c(c)->save_ast_trail(d);
|
||||
RETURN_Z3(of_func_decl(d));
|
||||
Z3_CATCH_RETURN(nullptr);
|
||||
}
|
||||
|
||||
void Z3_API Z3_add_rec_def(Z3_context c, Z3_func_decl f, unsigned n, Z3_ast args[], Z3_ast body) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_add_rec_def(c, f, n, args, body);
|
||||
func_decl* d = to_func_decl(f);
|
||||
ast_manager& m = mk_c(c)->m();
|
||||
recfun::decl::plugin& p = mk_c(c)->recfun().get_plugin();
|
||||
expr_ref abs_body(m);
|
||||
expr_ref_vector _args(m);
|
||||
var_ref_vector _vars(m);
|
||||
for (unsigned i = 0; i < n; ++i) {
|
||||
_args.push_back(to_expr(args[i]));
|
||||
_vars.push_back(m.mk_var(n - i - 1, m.get_sort(_args.back())));
|
||||
if (m.get_sort(_args.back()) != d->get_domain(i)) {
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
expr_abstract(m, 0, n, _args.c_ptr(), to_expr(body), abs_body);
|
||||
recfun::promise_def pd = p.get_promise_def(d);
|
||||
if (!pd.get_def()) {
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
||||
return;
|
||||
}
|
||||
if (m.get_sort(abs_body) != d->get_range()) {
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG, nullptr);
|
||||
return;
|
||||
}
|
||||
p.set_definition(pd, n, _vars.c_ptr(), abs_body);
|
||||
Z3_CATCH;
|
||||
}
|
||||
|
||||
Z3_ast Z3_API Z3_mk_app(Z3_context c, Z3_func_decl d, unsigned num_args, Z3_ast const * args) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_mk_app(c, d, num_args, args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue