3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-19 20:33:38 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2019-03-25 17:42:27 -07:00
parent e3a2168a20
commit 5536834019
10 changed files with 223 additions and 27 deletions

View file

@ -61,6 +61,7 @@ z3_add_component(api
api_rcf.cpp
api_seq.cpp
api_solver.cpp
api_special_relations.cpp
api_stats.cpp
api_tactic.cpp
z3_replayer.cpp

View file

@ -1052,6 +1052,18 @@ extern "C" {
}
}
if (mk_c(c)->get_special_relations_fid() == _d->get_family_id()) {
switch(_d->get_decl_kind()) {
case OP_SPECIAL_RELATION_LO : return Z3_OP_SPECIAL_RELATION_LO;
case OP_SPECIAL_RELATION_PO : return Z3_OP_SPECIAL_RELATION_PO;
case OP_SPECIAL_RELATION_PO_AO : return Z3_OP_SPECIAL_RELATION_PO_AO;
case OP_SPECIAL_RELATION_PLO: return Z3_OP_SPECIAL_RELATION_PLO;
case OP_SPECIAL_RELATION_TO : return Z3_OP_SPECIAL_RELATION_TO;
default: UNREACHABLE();
}
}
if (mk_c(c)->get_bv_fid() == _d->get_family_id()) {
switch(_d->get_decl_kind()) {
case OP_BV_NUM: return Z3_OP_BNUM;

View file

@ -101,6 +101,7 @@ namespace api {
m_datalog_fid = m().mk_family_id("datalog_relation");
m_fpa_fid = m().mk_family_id("fpa");
m_seq_fid = m().mk_family_id("seq");
m_special_relations_fid = m().mk_family_id("special_relations");
m_dt_plugin = static_cast<datatype_decl_plugin*>(m().get_plugin(m_dt_fid));
install_tactics(*this);

View file

@ -30,6 +30,7 @@ Revision History:
#include "ast/dl_decl_plugin.h"
#include "ast/fpa_decl_plugin.h"
#include "ast/recfun_decl_plugin.h"
#include "ast/special_relations_decl_plugin.h"
#include "smt/smt_kernel.h"
#include "smt/params/smt_params.h"
#include "util/event_handler.h"
@ -106,6 +107,7 @@ namespace api {
family_id m_pb_fid;
family_id m_fpa_fid;
family_id m_seq_fid;
family_id m_special_relations_fid;
datatype_decl_plugin * m_dt_plugin;
std::string m_string_buffer; // temporary buffer used to cache strings sent to the "external" world.
@ -162,6 +164,7 @@ namespace api {
family_id get_fpa_fid() const { return m_fpa_fid; }
family_id get_seq_fid() const { return m_seq_fid; }
datatype_decl_plugin * get_dt_plugin() const { return m_dt_plugin; }
family_id get_special_relations_fid() const { return m_special_relations_fid; }
Z3_error_code get_error_code() const { return m_error_code; }
void reset_error_code();

View file

@ -0,0 +1,78 @@
/*++
Copyright (c) 2019 Microsoft Corporation
Module Name:
api_special_relations.cpp
Abstract:
Basic API for Special relations
Author:
Nikolaj Bjorner (nbjorner) 2019-03-25
Ashutosh Gupta 2016
Revision History:
--*/
#include <iostream>
#include "api/z3.h"
#include "api/api_log_macros.h"
#include "api/api_context.h"
#include "api/api_util.h"
#include "ast/ast_pp.h"
#include "ast/special_relations_decl_plugin.h"
extern "C" {
#if 0
bool Z3_API Z3_is_sr_lo(Z3_context c, Z3_ast s) {
Z3_TRY;
LOG_Z3_is_sr_lo(c, s);
RESET_ERROR_CODE();
RETURN_Z3(mk_c(c)->sr_util().is_lo( to_expr(s) ));
Z3_CATCH_RETURN(false);
}
bool Z3_API Z3_is_sr_po(Z3_context c, Z3_ast s) {
Z3_TRY;
LOG_Z3_is_sr_po(c, s);
RESET_ERROR_CODE();
RETURN_Z3(mk_c(c)->sr_util().is_po( to_expr(s) ));
Z3_CATCH_RETURN(false);
}
bool Z3_API Z3_is_sr_po_ao(Z3_context c, Z3_ast s) {
Z3_TRY;
LOG_Z3_is_sr_po_ao(c, s);
RESET_ERROR_CODE();
RETURN_Z3(mk_c(c)->sr_util().is_po_ao( to_expr(s) ));
Z3_CATCH_RETURN(false);
}
bool Z3_API Z3_is_sr_plo(Z3_context c, Z3_ast s) {
Z3_TRY;
LOG_Z3_is_sr_plo(c, s);
RESET_ERROR_CODE();
RETURN_Z3(mk_c(c)->sr_util().is_plo( to_expr(s) ));
Z3_CATCH_RETURN(false);
}
bool Z3_API Z3_is_sr_to(Z3_context c, Z3_ast s) {
Z3_TRY;
LOG_Z3_is_sr_to(c, s);
RESET_ERROR_CODE();
RETURN_Z3(mk_c(c)->sr_util().is_to( to_expr(s) ));
Z3_CATCH_RETURN(false);
}
#endif
MK_BINARY(Z3_mk_sr_lo , mk_c(c)->get_special_relations_fid(), OP_SPECIAL_RELATION_LO, SKIP);
MK_BINARY(Z3_mk_sr_po , mk_c(c)->get_special_relations_fid(), OP_SPECIAL_RELATION_PO, SKIP);
MK_BINARY(Z3_mk_sr_po_ao,mk_c(c)->get_special_relations_fid(), OP_SPECIAL_RELATION_PO_AO,SKIP);
MK_BINARY(Z3_mk_sr_plo, mk_c(c)->get_special_relations_fid(), OP_SPECIAL_RELATION_PLO, SKIP);
MK_BINARY(Z3_mk_sr_to , mk_c(c)->get_special_relations_fid(), OP_SPECIAL_RELATION_TO, SKIP);
};

View file

@ -1707,6 +1707,42 @@ namespace z3 {
*/
inline expr sext(expr const & a, unsigned i) { return to_expr(a.ctx(), Z3_mk_sign_ext(a.ctx(), i, a)); }
inline expr sr_lo(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r = Z3_mk_sr_lo(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
}
inline expr sr_po(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r = Z3_mk_sr_po(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
}
inline expr sr_po_ao(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r = Z3_mk_sr_po_ao(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
}
inline expr sr_plo(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r = Z3_mk_sr_plo(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
}
inline expr sr_to(expr const& a, expr const& b) {
check_context(a, b);
Z3_ast r = Z3_mk_sr_to(a.ctx(), a, b);
a.check_error();
return expr(a.ctx(), r);
}
template<typename T> class cast_ast;
template<> class cast_ast<ast> {

View file

@ -1101,6 +1101,13 @@ typedef enum {
Z3_OP_BUREM_I,
Z3_OP_BSMOD_I,
// Special relations
Z3_OP_SPECIAL_RELATION_LO,
Z3_OP_SPECIAL_RELATION_PO,
Z3_OP_SPECIAL_RELATION_PO_AO,
Z3_OP_SPECIAL_RELATION_PLO,
Z3_OP_SPECIAL_RELATION_TO,
// Proofs
Z3_OP_PR_UNDEF = 0x500,
Z3_OP_PR_TRUE,
@ -3595,10 +3602,58 @@ extern "C" {
*/
Z3_ast Z3_API Z3_mk_re_full(Z3_context c, Z3_sort re);
/*@}*/
/** @name Special relations */
/*@{*/
/**
\brief declare \c a and \c b are in linear order.
\pre a and b are of same type.
def_API('Z3_mk_sr_lo', AST ,(_in(CONTEXT), _in(AST), _in(AST)))
*/
Z3_ast Z3_API Z3_mk_sr_lo(Z3_context c, Z3_ast a, Z3_ast b);
/**
\brief declare \c a and \c b are in partial order.
\pre a and b are of same type.
def_API('Z3_mk_sr_po', AST ,(_in(CONTEXT), _in(AST), _in(AST)))
*/
Z3_ast Z3_API Z3_mk_sr_po(Z3_context c, Z3_ast a, Z3_ast b);
/**
\brief declare \c a and \c b are already partial ordered.
\pre a and b are of same type.
def_API('Z3_mk_sr_po_ao', AST ,(_in(CONTEXT), _in(AST), _in(AST)))
*/
Z3_ast Z3_API Z3_mk_sr_po_ao(Z3_context c, Z3_ast a, Z3_ast b);
/**
\brief declare \c a and \c b are in piecewise linear order.
\pre a and b are of same type.
def_API('Z3_mk_sr_plo', AST ,(_in(CONTEXT), _in(AST), _in(AST)))
*/
Z3_ast Z3_API Z3_mk_sr_plo(Z3_context c, Z3_ast a, Z3_ast b);
/**
\brief declare \c a and \c b are in total order.
\pre a and b are of same type.
def_API('Z3_mk_sr_to', AST ,(_in(CONTEXT), _in(AST), _in(AST)))
*/
Z3_ast Z3_API Z3_mk_sr_to(Z3_context c, Z3_ast a, Z3_ast b);
/*@}*/
/** @name Quantifiers */
/*@{*/
/**