mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
Merge branch 'realclosure' into unstable
This commit is contained in:
commit
93f37bdf9f
27 changed files with 7901 additions and 42 deletions
|
@ -25,6 +25,7 @@ Revision History:
|
|||
#include"api_log_macros.h"
|
||||
#include"api_util.h"
|
||||
#include"reg_decl_plugins.h"
|
||||
#include"realclosure.h"
|
||||
|
||||
// The install_tactics procedure is automatically generated
|
||||
void install_tactics(tactic_manager & ctx);
|
||||
|
@ -138,6 +139,8 @@ namespace api {
|
|||
if (m_interruptable)
|
||||
(*m_interruptable)();
|
||||
m().set_cancel(true);
|
||||
if (m_rcf_manager.get() == 0)
|
||||
m_rcf_manager->set_cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -391,6 +394,19 @@ namespace api {
|
|||
m_smtlib_parser_sorts.reset();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
//
|
||||
// RCF manager
|
||||
//
|
||||
// -----------------------
|
||||
realclosure::manager & context::rcfm() {
|
||||
if (m_rcf_manager.get() == 0) {
|
||||
m_rcf_manager = alloc(realclosure::manager, m_rcf_qm);
|
||||
}
|
||||
return *(m_rcf_manager.get());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -476,8 +492,11 @@ extern "C" {
|
|||
}
|
||||
|
||||
void Z3_API Z3_enable_trace(Z3_string tag) {
|
||||
memory::initialize(UINT_MAX);
|
||||
LOG_Z3_enable_trace(tag);
|
||||
enable_trace(tag);
|
||||
// Tag is a string that was probably not allocated by Z3. Create a copy using symbol.
|
||||
symbol tag_sym(tag);
|
||||
enable_trace(tag_sym.bare_str());
|
||||
}
|
||||
|
||||
void Z3_API Z3_disable_trace(Z3_string tag) {
|
||||
|
|
|
@ -38,6 +38,10 @@ namespace smtlib {
|
|||
class parser;
|
||||
};
|
||||
|
||||
namespace realclosure {
|
||||
class manager;
|
||||
};
|
||||
|
||||
namespace api {
|
||||
Z3_search_failure mk_Z3_search_failure(smt::failure f);
|
||||
|
||||
|
@ -83,7 +87,6 @@ namespace api {
|
|||
|
||||
event_handler * m_interruptable; // Reference to an object that can be interrupted by Z3_interrupt
|
||||
|
||||
pmanager m_pmanager;
|
||||
public:
|
||||
// Scoped obj for setting m_interruptable
|
||||
class set_interruptable {
|
||||
|
@ -175,8 +178,22 @@ namespace api {
|
|||
// Polynomial manager & caches
|
||||
//
|
||||
// -----------------------
|
||||
private:
|
||||
pmanager m_pmanager;
|
||||
public:
|
||||
polynomial::manager & pm() { return m_pmanager.pm(); }
|
||||
|
||||
// ------------------------
|
||||
//
|
||||
// RCF manager
|
||||
//
|
||||
// -----------------------
|
||||
private:
|
||||
unsynch_mpq_manager m_rcf_qm;
|
||||
scoped_ptr<realclosure::manager> m_rcf_manager;
|
||||
public:
|
||||
realclosure::manager & rcfm();
|
||||
|
||||
// ------------------------
|
||||
//
|
||||
// Solver interface for backward compatibility
|
||||
|
|
293
src/api/api_rcf.cpp
Normal file
293
src/api/api_rcf.cpp
Normal file
|
@ -0,0 +1,293 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
api_rcf.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Additional APIs for handling elements of the Z3 real closed field that contains:
|
||||
- transcendental extensions
|
||||
- infinitesimal extensions
|
||||
- algebraic extensions
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2012-01-05
|
||||
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
#include<iostream>
|
||||
#include"z3.h"
|
||||
#include"api_log_macros.h"
|
||||
#include"api_context.h"
|
||||
#include"realclosure.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
static rcmanager & rcfm(Z3_context c) {
|
||||
return mk_c(c)->rcfm();
|
||||
}
|
||||
|
||||
static void reset_rcf_cancel(Z3_context c) {
|
||||
rcfm(c).reset_cancel();
|
||||
}
|
||||
|
||||
static rcnumeral to_rcnumeral(Z3_rcf_num a) {
|
||||
return rcnumeral::mk(a);
|
||||
}
|
||||
|
||||
static Z3_rcf_num from_rcnumeral(rcnumeral a) {
|
||||
return reinterpret_cast<Z3_rcf_num>(a.c_ptr());
|
||||
}
|
||||
|
||||
void Z3_API Z3_rcf_del(Z3_context c, Z3_rcf_num a) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_del(c, a);
|
||||
RESET_ERROR_CODE();
|
||||
rcnumeral _a = to_rcnumeral(a);
|
||||
rcfm(c).del(_a);
|
||||
Z3_CATCH;
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_rational(Z3_context c, Z3_string val) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mk_rational(c, val);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
scoped_mpq q(rcfm(c).qm());
|
||||
rcfm(c).qm().set(q, val);
|
||||
rcnumeral r;
|
||||
rcfm(c).set(r, q);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_small_int(Z3_context c, int val) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mk_small_int(c, val);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).set(r, val);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_pi(Z3_context c) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mk_pi(c);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).mk_pi(r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_e(Z3_context c) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mk_e(c);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).mk_e(r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(Z3_context c, Z3_string name) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mk_infinitesimal(c, name);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).mk_infinitesimal(name, r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
unsigned Z3_API Z3_rcf_mk_roots(Z3_context c, unsigned n, Z3_rcf_num const a[], Z3_rcf_num roots[]) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mk_roots(c, n, a, roots);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral_vector av;
|
||||
unsigned rz = 0;
|
||||
for (unsigned i = 0; i < n; i++) {
|
||||
if (!rcfm(c).is_zero(to_rcnumeral(a[i])))
|
||||
rz = i + 1;
|
||||
av.push_back(to_rcnumeral(a[i]));
|
||||
}
|
||||
if (rz == 0) {
|
||||
// it is the zero polynomial
|
||||
SET_ERROR_CODE(Z3_INVALID_ARG);
|
||||
return 0;
|
||||
}
|
||||
av.shrink(rz);
|
||||
rcnumeral_vector rs;
|
||||
rcfm(c).isolate_roots(av.size(), av.c_ptr(), rs);
|
||||
unsigned num_roots = rs.size();
|
||||
for (unsigned i = 0; i < num_roots; i++) {
|
||||
roots[i] = from_rcnumeral(rs[i]);
|
||||
}
|
||||
RETURN_Z3_rcf_mk_roots num_roots;
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_add(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_add(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).add(to_rcnumeral(a), to_rcnumeral(b), r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_sub(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_sub(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).sub(to_rcnumeral(a), to_rcnumeral(b), r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_mul(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_mul(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).mul(to_rcnumeral(a), to_rcnumeral(b), r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_div(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_div(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).div(to_rcnumeral(a), to_rcnumeral(b), r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_neg(Z3_context c, Z3_rcf_num a) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_neg(c, a);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).neg(to_rcnumeral(a), r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_inv(Z3_context c, Z3_rcf_num a) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_inv(c, a);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).inv(to_rcnumeral(a), r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_rcf_num Z3_API Z3_rcf_power(Z3_context c, Z3_rcf_num a, unsigned k) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_power(c, a, k);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
rcnumeral r;
|
||||
rcfm(c).power(to_rcnumeral(a), k, r);
|
||||
RETURN_Z3(from_rcnumeral(r));
|
||||
Z3_CATCH_RETURN(0);
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_lt(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
return rcfm(c).lt(to_rcnumeral(a), to_rcnumeral(b));
|
||||
Z3_CATCH_RETURN(Z3_FALSE);
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_rcf_gt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_gt(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
return rcfm(c).gt(to_rcnumeral(a), to_rcnumeral(b));
|
||||
Z3_CATCH_RETURN(Z3_FALSE);
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_rcf_le(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_le(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
return rcfm(c).le(to_rcnumeral(a), to_rcnumeral(b));
|
||||
Z3_CATCH_RETURN(Z3_FALSE);
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_rcf_ge(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_ge(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
return rcfm(c).ge(to_rcnumeral(a), to_rcnumeral(b));
|
||||
Z3_CATCH_RETURN(Z3_FALSE);
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_rcf_eq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_eq(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
return rcfm(c).eq(to_rcnumeral(a), to_rcnumeral(b));
|
||||
Z3_CATCH_RETURN(Z3_FALSE);
|
||||
}
|
||||
|
||||
Z3_bool Z3_API Z3_rcf_neq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_neq(c, a, b);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
return rcfm(c).eq(to_rcnumeral(a), to_rcnumeral(b));
|
||||
Z3_CATCH_RETURN(Z3_FALSE);
|
||||
}
|
||||
|
||||
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_num_to_string(c, a);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
std::ostringstream buffer;
|
||||
rcfm(c).display(buffer, to_rcnumeral(a));
|
||||
return mk_c(c)->mk_external_string(buffer.str());
|
||||
Z3_CATCH_RETURN("");
|
||||
}
|
||||
|
||||
Z3_string Z3_API Z3_rcf_num_to_decimal_string(Z3_context c, Z3_rcf_num a, unsigned prec) {
|
||||
Z3_TRY;
|
||||
LOG_Z3_rcf_num_to_decimal_string(c, a, prec);
|
||||
RESET_ERROR_CODE();
|
||||
reset_rcf_cancel(c);
|
||||
std::ostringstream buffer;
|
||||
rcfm(c).display_decimal(buffer, to_rcnumeral(a), prec);
|
||||
return mk_c(c)->mk_external_string(buffer.str());
|
||||
Z3_CATCH_RETURN("");
|
||||
}
|
||||
|
||||
};
|
|
@ -37,6 +37,7 @@ namespace api {
|
|||
public:
|
||||
object():m_ref_count(0) {}
|
||||
virtual ~object() {}
|
||||
unsigned ref_count() const { return m_ref_count; }
|
||||
void inc_ref() { m_ref_count++; }
|
||||
void dec_ref() { SASSERT(m_ref_count > 0); m_ref_count--; if (m_ref_count == 0) dealloc(this); }
|
||||
};
|
||||
|
|
153
src/api/python/z3rcf.py
Normal file
153
src/api/python/z3rcf.py
Normal file
|
@ -0,0 +1,153 @@
|
|||
############################################
|
||||
# Copyright (c) 2013 Microsoft Corporation
|
||||
#
|
||||
# Z3 Python interface for Z3 Real Closed Fields
|
||||
# that may contain
|
||||
# - computable transcendentals
|
||||
# - infinitesimals
|
||||
# - algebraic extensions
|
||||
#
|
||||
# Author: Leonardo de Moura (leonardo)
|
||||
############################################
|
||||
from z3 import *
|
||||
from z3core import *
|
||||
from z3printer import *
|
||||
from fractions import Fraction
|
||||
|
||||
def _to_rcfnum(num, ctx=None):
|
||||
if isinstance(num, RCFNum):
|
||||
return num
|
||||
else:
|
||||
return RCFNum(num, ctx)
|
||||
|
||||
def Pi(ctx=None):
|
||||
ctx = z3._get_ctx(ctx)
|
||||
return RCFNum(Z3_rcf_mk_pi(ctx.ref()), ctx)
|
||||
|
||||
def E(ctx=None):
|
||||
ctx = z3._get_ctx(ctx)
|
||||
return RCFNum(Z3_rcf_mk_e(ctx.ref()), ctx)
|
||||
|
||||
def MkInfinitesimal(name="eps", ctx=None):
|
||||
ctx = z3._get_ctx(ctx)
|
||||
return RCFNum(Z3_rcf_mk_infinitesimal(ctx.ref(), name), ctx)
|
||||
|
||||
def MkRoots(p, ctx=None):
|
||||
ctx = z3._get_ctx(ctx)
|
||||
num = len(p)
|
||||
_tmp = []
|
||||
_as = (RCFNumObj * num)()
|
||||
_rs = (RCFNumObj * num)()
|
||||
for i in range(num):
|
||||
_a = _to_rcfnum(p[i], ctx)
|
||||
_tmp.append(_a) # prevent GC
|
||||
_as[i] = _a.num
|
||||
nr = Z3_rcf_mk_roots(ctx.ref(), num, _as, _rs)
|
||||
r = []
|
||||
for i in range(nr):
|
||||
r.append(RCFNum(_rs[i], ctx))
|
||||
return r
|
||||
|
||||
class RCFNum:
|
||||
def __init__(self, num, ctx=None):
|
||||
# TODO: add support for converting AST numeral values into RCFNum
|
||||
if isinstance(num, RCFNumObj):
|
||||
self.num = num
|
||||
self.ctx = z3._get_ctx(ctx)
|
||||
else:
|
||||
self.ctx = z3._get_ctx(ctx)
|
||||
self.num = Z3_rcf_mk_rational(self.ctx_ref(), str(num))
|
||||
|
||||
def __del__(self):
|
||||
Z3_rcf_del(self.ctx_ref(), self.num)
|
||||
|
||||
def ctx_ref(self):
|
||||
return self.ctx.ref()
|
||||
|
||||
def __repr__(self):
|
||||
return Z3_rcf_num_to_string(self.ctx_ref(), self.num)
|
||||
|
||||
def __add__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_add(self.ctx_ref(), self.num, v.num), self.ctx)
|
||||
|
||||
def __radd__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_add(self.ctx_ref(), v.num, self.num), self.ctx)
|
||||
|
||||
def __mul__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_mul(self.ctx_ref(), self.num, v.num), self.ctx)
|
||||
|
||||
def __rmul__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_mul(self.ctx_ref(), v.num, self.num), self.ctx)
|
||||
|
||||
def __sub__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_sub(self.ctx_ref(), self.num, v.num), self.ctx)
|
||||
|
||||
def __rsub__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_sub(self.ctx_ref(), v.num, self.num), self.ctx)
|
||||
|
||||
def __div__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_div(self.ctx_ref(), self.num, v.num), self.ctx)
|
||||
|
||||
def __rdiv__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return RCFNum(Z3_rcf_div(self.ctx_ref(), v.num, self.num), self.ctx)
|
||||
|
||||
def __neg__(self):
|
||||
return self.__rsub__(0)
|
||||
|
||||
def power(self, k):
|
||||
return RCFNum(Z3_rcf_power(self.ctx_ref(), self.num, k), self.ctx)
|
||||
|
||||
def __pow__(self, k):
|
||||
return self.power(k)
|
||||
|
||||
def decimal(self, prec=5):
|
||||
return Z3_rcf_num_to_decimal_string(self.ctx_ref(), self.num, prec)
|
||||
|
||||
def __lt__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_lt(self.ctx_ref(), self.num, v.num)
|
||||
|
||||
def __rlt__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_lt(self.ctx_ref(), v.num, self.num)
|
||||
|
||||
def __gt__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_gt(self.ctx_ref(), self.num, v.num)
|
||||
|
||||
def __rgt__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_gt(self.ctx_ref(), v.num, self.num)
|
||||
|
||||
def __le__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_le(self.ctx_ref(), self.num, v.num)
|
||||
|
||||
def __rle__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_le(self.ctx_ref(), v.num, self.num)
|
||||
|
||||
def __ge__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_ge(self.ctx_ref(), self.num, v.num)
|
||||
|
||||
def __rge__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_ge(self.ctx_ref(), v.num, self.num)
|
||||
|
||||
def __eq__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_eq(self.ctx_ref(), self.num, v.num)
|
||||
|
||||
def __ne__(self, other):
|
||||
v = _to_rcfnum(other, self.ctx)
|
||||
return Z3_rcf_neq(self.ctx_ref(), self.num, v.num)
|
||||
|
|
@ -106,3 +106,6 @@ class FuncEntryObj(ctypes.c_void_p):
|
|||
def __init__(self, e): self._as_parameter_ = e
|
||||
def from_param(obj): return obj
|
||||
|
||||
class RCFNumObj(ctypes.c_void_p):
|
||||
def __init__(self, e): self._as_parameter_ = e
|
||||
def from_param(obj): return obj
|
||||
|
|
|
@ -26,6 +26,7 @@ Notes:
|
|||
#include"z3_api.h"
|
||||
#include"z3_algebraic.h"
|
||||
#include"z3_polynomial.h"
|
||||
#include"z3_rcf.h"
|
||||
|
||||
#undef __in
|
||||
#undef __out
|
||||
|
|
|
@ -47,6 +47,7 @@ DEFINE_TYPE(Z3_func_interp);
|
|||
#define Z3_func_interp_opt Z3_func_interp
|
||||
DEFINE_TYPE(Z3_func_entry);
|
||||
DEFINE_TYPE(Z3_fixedpoint);
|
||||
DEFINE_TYPE(Z3_rcf_num);
|
||||
DEFINE_VOID(Z3_theory_data);
|
||||
#endif
|
||||
|
||||
|
@ -1190,6 +1191,7 @@ typedef enum
|
|||
def_Type('FUNC_ENTRY', 'Z3_func_entry', 'FuncEntryObj')
|
||||
def_Type('FIXEDPOINT', 'Z3_fixedpoint', 'FixedpointObj')
|
||||
def_Type('PARAM_DESCRS', 'Z3_param_descrs', 'ParamDescrs')
|
||||
def_Type('RCF_NUM', 'Z3_rcf_num', 'RCFNumObj')
|
||||
*/
|
||||
|
||||
#ifdef Conly
|
||||
|
|
191
src/api/z3_rcf.h
Normal file
191
src/api/z3_rcf.h
Normal file
|
@ -0,0 +1,191 @@
|
|||
/*++
|
||||
Copyright (c) 2013 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
z3_rcf.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Additional APIs for handling elements of the Z3 real closed field that contains:
|
||||
- transcendental extensions
|
||||
- infinitesimal extensions
|
||||
- algebraic extensions
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2012-01-05
|
||||
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
#ifndef _Z3_RCF_H_
|
||||
#define _Z3_RCF_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
/**
|
||||
\brief Delete a RCF numeral created using the RCF API.
|
||||
|
||||
def_API('Z3_rcf_del', VOID, (_in(CONTEXT), _in(RCF_NUM)))
|
||||
*/
|
||||
void Z3_API Z3_rcf_del(__in Z3_context c, __in Z3_rcf_num a);
|
||||
|
||||
/**
|
||||
\brief Return a RCF rational using the given string.
|
||||
|
||||
def_API('Z3_rcf_mk_rational', RCF_NUM, (_in(CONTEXT), _in(STRING)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_rational(__in Z3_context c, __in Z3_string val);
|
||||
|
||||
/**
|
||||
\brief Return a RCF small integer.
|
||||
|
||||
def_API('Z3_rcf_mk_small_int', RCF_NUM, (_in(CONTEXT), _in(INT)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_small_int(__in Z3_context c, __in int val);
|
||||
|
||||
/**
|
||||
\brief Return Pi
|
||||
|
||||
def_API('Z3_rcf_mk_pi', RCF_NUM, (_in(CONTEXT),))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_pi(__in Z3_context c);
|
||||
|
||||
/**
|
||||
\brief Return e (Euler's constant)
|
||||
|
||||
def_API('Z3_rcf_mk_e', RCF_NUM, (_in(CONTEXT),))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_e(__in Z3_context c);
|
||||
|
||||
/**
|
||||
\brief Return a new infinitesimal that is smaller than all elements in the Z3 field.
|
||||
|
||||
def_API('Z3_rcf_mk_infinitesimal', RCF_NUM, (_in(CONTEXT), _in(STRING)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(__in Z3_context c, __in Z3_string name);
|
||||
|
||||
/**
|
||||
\brief Store in roots the roots of the polynomial <tt>a[n-1]*x^{n-1} + ... + a[0]</tt>.
|
||||
The output vector \c roots must have size \c n.
|
||||
It returns the number of roots of the polynomial.
|
||||
|
||||
\pre The input polynomial is not the zero polynomial.
|
||||
|
||||
def_API('Z3_rcf_mk_roots', UINT, (_in(CONTEXT), _in(UINT), _in_array(1, RCF_NUM), _out_array(1, RCF_NUM)))
|
||||
*/
|
||||
unsigned Z3_API Z3_rcf_mk_roots(__in Z3_context c, __in unsigned n, __in_ecount(n) Z3_rcf_num const a[], __out_ecount(n) Z3_rcf_num roots[]);
|
||||
|
||||
/**
|
||||
\brief Return the value a + b.
|
||||
|
||||
def_API('Z3_rcf_add', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_add(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return the value a - b.
|
||||
|
||||
def_API('Z3_rcf_sub', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_sub(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return the value a * b.
|
||||
|
||||
def_API('Z3_rcf_mul', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_mul(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return the value a / b.
|
||||
|
||||
def_API('Z3_rcf_div', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_div(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return the value -a
|
||||
|
||||
def_API('Z3_rcf_neg', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_neg(__in Z3_context c, __in Z3_rcf_num a);
|
||||
|
||||
/**
|
||||
\brief Return the value 1/a
|
||||
|
||||
def_API('Z3_rcf_inv', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_inv(__in Z3_context c, __in Z3_rcf_num a);
|
||||
|
||||
/**
|
||||
\brief Return the value a^k
|
||||
|
||||
def_API('Z3_rcf_power', RCF_NUM, (_in(CONTEXT), _in(RCF_NUM), _in(UINT)))
|
||||
*/
|
||||
Z3_rcf_num Z3_API Z3_rcf_power(__in Z3_context c, __in Z3_rcf_num a, __in unsigned k);
|
||||
|
||||
/**
|
||||
\brief Return Z3_TRUE if a < b
|
||||
|
||||
def_API('Z3_rcf_lt', BOOL, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_bool Z3_API Z3_rcf_lt(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return Z3_TRUE if a > b
|
||||
|
||||
def_API('Z3_rcf_gt', BOOL, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_bool Z3_API Z3_rcf_gt(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return Z3_TRUE if a <= b
|
||||
|
||||
def_API('Z3_rcf_le', BOOL, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_bool Z3_API Z3_rcf_le(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return Z3_TRUE if a >= b
|
||||
|
||||
def_API('Z3_rcf_ge', BOOL, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_bool Z3_API Z3_rcf_ge(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return Z3_TRUE if a == b
|
||||
|
||||
def_API('Z3_rcf_eq', BOOL, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_bool Z3_API Z3_rcf_eq(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Return Z3_TRUE if a != b
|
||||
|
||||
def_API('Z3_rcf_neq', BOOL, (_in(CONTEXT), _in(RCF_NUM), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_bool Z3_API Z3_rcf_neq(__in Z3_context c, __in Z3_rcf_num a, __in Z3_rcf_num b);
|
||||
|
||||
/**
|
||||
\brief Convert the RCF numeral into a string.
|
||||
|
||||
def_API('Z3_rcf_num_to_string', STRING, (_in(CONTEXT), _in(RCF_NUM)))
|
||||
*/
|
||||
Z3_string Z3_API Z3_rcf_num_to_string(__in Z3_context c, __in Z3_rcf_num a);
|
||||
|
||||
/**
|
||||
\brief Convert the RCF numeral into a string in decimal notation.
|
||||
|
||||
def_API('Z3_rcf_num_to_decimal_string', STRING, (_in(CONTEXT), _in(RCF_NUM), _in(UINT)))
|
||||
*/
|
||||
Z3_string Z3_API Z3_rcf_num_to_decimal_string(__in Z3_context c, __in Z3_rcf_num a, __in unsigned prec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue