Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
  • Loading branch information
NikolajBjorner committed Dec 9, 2022
1 parent 96a2c04 commit 1434c7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/api/c++/z3++.h
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,11 @@ namespace z3 {
*/
expr substitute(expr_vector const& dst);

/**
\brief Apply function substitution by macro definitions.
*/
expr substitute(func_decl_vector const& funs, expr_vector const& bodies);


class iterator {
expr& e;
Expand Down Expand Up @@ -4059,6 +4064,22 @@ namespace z3 {
return expr(ctx(), r);
}

inline expr expr::substitute(func_decl_vector const& funs, expr_vector const& dst) {
array<Z3_ast> _dst(dst.size());
array<Z3_func_decl> _funs(funs.size());
if (dst.size() != funs.size()) {
Z3_THROW(exception("length of argument lists don't align"));
return expr(ctx(), nullptr);
}
for (unsigned i = 0; i < dst.size(); ++i) {
_dst[i] = dst[i];
_funs[i] = funs[i];
}
Z3_ast r = Z3_substitute_funs(ctx(), m_ast, dst.size(), _funs.ptr(), _dst.ptr());
check_error();
return expr(ctx(), r);
}

typedef std::function<void(expr const& proof, expr_vector const& clause)> on_clause_eh_t;

class on_clause {
Expand Down
2 changes: 1 addition & 1 deletion src/api/python/z3/z3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8837,7 +8837,7 @@ def substitute_vars(t, *m):
return _to_expr_ref(Z3_substitute_vars(t.ctx.ref(), t.as_ast(), num, _to), t.ctx)

def substitute_funs(t, *m):
"""Apply subistitution m on t, m is a list of pairs of a function and expression (from, to)
"""Apply substitution m on t, m is a list of pairs of a function and expression (from, to)
Every occurrence in to of the function from is replaced with the expression to.
The expression to can have free variables, that refer to the arguments of from.
For examples, see
Expand Down

0 comments on commit 1434c7d

Please sign in to comment.