mirror of
https://github.com/Z3Prover/z3
synced 2025-08-17 08:42:15 +00:00
fix tree-order, change API for special relations to produce function declarations
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
b4ba44ce9d
commit
6158ea61c8
8 changed files with 92 additions and 91 deletions
|
@ -28,22 +28,22 @@ Revision History:
|
|||
extern "C" {
|
||||
|
||||
|
||||
#define MK_TERN(NAME, FID) \
|
||||
Z3_ast Z3_API NAME(Z3_context c, unsigned index, Z3_ast a, Z3_ast b) { \
|
||||
LOG_ ##NAME(c, index, a, b); \
|
||||
#define MK_SPECIAL_R(NAME, FID) \
|
||||
Z3_func_decl Z3_API NAME(Z3_context c, Z3_sort s, unsigned index) { \
|
||||
LOG_ ##NAME(c, s, index); \
|
||||
Z3_TRY; \
|
||||
expr* args[2] = { to_expr(a), to_expr(b) }; \
|
||||
parameter p(index); \
|
||||
ast* a = mk_c(c)->m().mk_app(mk_c(c)->get_special_relations_fid(), FID, 1, &p, 2, args); \
|
||||
mk_c(c)->save_ast_trail(a); \
|
||||
RETURN_Z3(of_ast(a)); \
|
||||
sort* domain[2] = { to_sort(s), to_sort(s) }; \
|
||||
func_decl* f = mk_c(c)->m().mk_func_decl(mk_c(c)->get_special_relations_fid(), FID, 1, &p, 2, domain, mk_c(c)->m().mk_bool_sort()); \
|
||||
mk_c(c)->save_ast_trail(f); \
|
||||
RETURN_Z3(of_func_decl(f)); \
|
||||
Z3_CATCH_RETURN(nullptr); \
|
||||
}
|
||||
|
||||
MK_TERN(Z3_mk_linear_order, OP_SPECIAL_RELATION_LO);
|
||||
MK_TERN(Z3_mk_partial_order, OP_SPECIAL_RELATION_PO);
|
||||
MK_TERN(Z3_mk_piecewise_linear_order, OP_SPECIAL_RELATION_PLO);
|
||||
MK_TERN(Z3_mk_tree_order, OP_SPECIAL_RELATION_TO);
|
||||
MK_SPECIAL_R(Z3_mk_linear_order, OP_SPECIAL_RELATION_LO);
|
||||
MK_SPECIAL_R(Z3_mk_partial_order, OP_SPECIAL_RELATION_PO);
|
||||
MK_SPECIAL_R(Z3_mk_piecewise_linear_order, OP_SPECIAL_RELATION_PLO);
|
||||
MK_SPECIAL_R(Z3_mk_tree_order, OP_SPECIAL_RELATION_TO);
|
||||
|
||||
|
||||
#define MK_DECL(NAME, FID) \
|
||||
|
|
|
@ -1715,25 +1715,17 @@ namespace z3 {
|
|||
*/
|
||||
inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
|
||||
|
||||
typedef Z3_ast Z3_apply_order(Z3_context, unsigned, Z3_ast, Z3_ast);
|
||||
|
||||
inline expr apply_order(Z3_apply_order app, unsigned index, expr const& a, expr const& b) {
|
||||
check_context(a, b);
|
||||
Z3_ast r = app(a.ctx(), index, a, b);
|
||||
a.check_error();
|
||||
return expr(a.ctx(), r);
|
||||
inline func_decl linear_order(sort const& a, unsigned index) {
|
||||
return to_func_decl(a.ctx(), Z3_mk_linear_order(a.ctx(), a, index));
|
||||
}
|
||||
inline expr linear_order(unsigned index, expr const& a, expr const& b) {
|
||||
return apply_order(Z3_mk_linear_order, index, a, b);
|
||||
inline func_decl partial_order(sort const& a, unsigned index) {
|
||||
return to_func_decl(a.ctx(), Z3_mk_partial_order(a.ctx(), a, index));
|
||||
}
|
||||
inline expr partial_order(unsigned index, expr const& a, expr const& b) {
|
||||
return apply_order(Z3_mk_partial_order, index, a, b);
|
||||
inline func_decl piecewise_linear_order(sort const& a, unsigned index) {
|
||||
return to_func_decl(a.ctx(), Z3_mk_piecewise_linear_order(a.ctx(), a, index));
|
||||
}
|
||||
inline expr piecewise_linear_order(unsigned index, expr const& a, expr const& b) {
|
||||
return apply_order(Z3_mk_piecewise_linear_order, index, a, b);
|
||||
}
|
||||
inline expr tree_order(unsigned index, expr const& a, expr const& b) {
|
||||
return apply_order(Z3_mk_tree_order, index, a, b);
|
||||
inline func_decl tree_order(sort const& a, unsigned index) {
|
||||
return to_func_decl(a.ctx(), Z3_mk_tree_order(a.ctx(), a, index));
|
||||
}
|
||||
|
||||
template<typename T> class cast_ast;
|
||||
|
|
|
@ -10379,6 +10379,18 @@ def Range(lo, hi, ctx = None):
|
|||
|
||||
# Special Relations
|
||||
|
||||
def PartialOrder(a, index):
|
||||
return FuncDeclRef(Z3_mk_partial_order(a.ctx_ref(), a.ast, index), a.ctx);
|
||||
|
||||
def LinearOrder(a, index):
|
||||
return FuncDeclRef(Z3_mk_linear_order(a.ctx_ref(), a.ast, index), a.ctx);
|
||||
|
||||
def TreeOrder(a, index):
|
||||
return FuncDeclRef(Z3_mk_tree_order(a.ctx_ref(), a.ast, index), a.ctx);
|
||||
|
||||
def PiecewiseLinearOrder(a, index):
|
||||
return FuncDeclRef(Z3_mk_piecewise_linear_order(a.ctx_ref(), a.ast, index), a.ctx);
|
||||
|
||||
def TransitiveClosure(f):
|
||||
"""Given a binary relation R, such that the two arguments have the same sort
|
||||
create the transitive closure relation R+.
|
||||
|
|
|
@ -3627,36 +3627,30 @@ extern "C" {
|
|||
\pre a and b are of same type.
|
||||
|
||||
|
||||
def_API('Z3_mk_linear_order', AST ,(_in(CONTEXT), _in(UINT), _in(AST), _in(AST)))
|
||||
def_API('Z3_mk_linear_order', FUNC_DECL ,(_in(CONTEXT), _in(SORT), _in(UINT)))
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_linear_order(Z3_context c, unsigned id, Z3_ast a, Z3_ast b);
|
||||
Z3_func_decl Z3_API Z3_mk_linear_order(Z3_context c, Z3_sort a, unsigned id);
|
||||
|
||||
/**
|
||||
\brief declare \c a and \c b are in partial order over a relation indexed by \c id.
|
||||
\brief create a partial ordering relation over signature \c a and index \c id.
|
||||
|
||||
\pre a and b are of same type.
|
||||
|
||||
def_API('Z3_mk_partial_order', AST ,(_in(CONTEXT), _in(UINT), _in(AST), _in(AST)))
|
||||
def_API('Z3_mk_partial_order', FUNC_DECL ,(_in(CONTEXT), _in(SORT), _in(UINT)))
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_partial_order(Z3_context c, unsigned id, Z3_ast a, Z3_ast b);
|
||||
Z3_func_decl Z3_API Z3_mk_partial_order(Z3_context c, Z3_sort a, unsigned id);
|
||||
|
||||
/**
|
||||
\brief declare \c a and \c b are in piecewise linear order indexed by relation \c id.
|
||||
\brief create a piecewise linear ordering relation over signature \c a and index \c id.
|
||||
|
||||
\pre a and b are of same type.
|
||||
|
||||
def_API('Z3_mk_piecewise_linear_order', AST ,(_in(CONTEXT), _in(UINT), _in(AST), _in(AST)))
|
||||
def_API('Z3_mk_piecewise_linear_order', FUNC_DECL ,(_in(CONTEXT), _in(SORT), _in(UINT)))
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_piecewise_linear_order(Z3_context c, unsigned id, Z3_ast a, Z3_ast b);
|
||||
Z3_func_decl Z3_API Z3_mk_piecewise_linear_order(Z3_context c, Z3_sort a, unsigned id);
|
||||
|
||||
/**
|
||||
\brief declare \c a and \c b are in tree order indexed by \c id.
|
||||
\brief create a tree ordering lreation over signature \c a identified using index \c id.
|
||||
|
||||
\pre a and b are of same type.
|
||||
|
||||
def_API('Z3_mk_tree_order', AST ,(_in(CONTEXT), _in(UINT), _in(AST), _in(AST)))
|
||||
def_API('Z3_mk_tree_order', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT)))
|
||||
*/
|
||||
Z3_ast Z3_API Z3_mk_tree_order(Z3_context c, unsigned id, Z3_ast a, Z3_ast b);
|
||||
Z3_func_decl Z3_API Z3_mk_tree_order(Z3_context c, Z3_sort a, unsigned id);
|
||||
|
||||
/**
|
||||
\brief create transitive closure of binary relation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue