3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

Add html pretty printing mode for RCF package

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-01-27 10:19:54 -08:00
parent 8e2298c327
commit 77f58269ed
8 changed files with 156 additions and 94 deletions

View file

@ -98,13 +98,13 @@ extern "C" {
Z3_CATCH_RETURN(0);
}
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(Z3_context c, Z3_string name) {
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(Z3_context c) {
Z3_TRY;
LOG_Z3_rcf_mk_infinitesimal(c, name);
LOG_Z3_rcf_mk_infinitesimal(c);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
rcnumeral r;
rcfm(c).mk_infinitesimal(name, r);
rcfm(c).mk_infinitesimal(r);
RETURN_Z3(from_rcnumeral(r));
Z3_CATCH_RETURN(0);
}
@ -268,13 +268,13 @@ extern "C" {
Z3_CATCH_RETURN(Z3_FALSE);
}
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, Z3_bool compact) {
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, Z3_bool compact, Z3_bool html) {
Z3_TRY;
LOG_Z3_rcf_num_to_string(c, a, compact);
LOG_Z3_rcf_num_to_string(c, a, compact, html);
RESET_ERROR_CODE();
reset_rcf_cancel(c);
std::ostringstream buffer;
rcfm(c).display(buffer, to_rcnumeral(a), compact != 0);
rcfm(c).display(buffer, to_rcnumeral(a), compact != 0, html != 0);
return mk_c(c)->mk_external_string(buffer.str());
Z3_CATCH_RETURN("");
}

View file

@ -29,8 +29,10 @@ def E(ctx=None):
return RCFNum(Z3_rcf_mk_e(ctx.ref()), ctx)
def MkInfinitesimal(name="eps", ctx=None):
# Todo: remove parameter name.
# For now, we keep it for backward compatibility.
ctx = z3._get_ctx(ctx)
return RCFNum(Z3_rcf_mk_infinitesimal(ctx.ref(), name), ctx)
return RCFNum(Z3_rcf_mk_infinitesimal(ctx.ref()), ctx)
def MkRoots(p, ctx=None):
ctx = z3._get_ctx(ctx)
@ -49,6 +51,7 @@ def MkRoots(p, ctx=None):
return r
class RCFNum:
html = False
def __init__(self, num, ctx=None):
# TODO: add support for converting AST numeral values into RCFNum
if isinstance(num, RCFNumObj):
@ -65,10 +68,10 @@ class RCFNum:
return self.ctx.ref()
def __repr__(self):
return Z3_rcf_num_to_string(self.ctx_ref(), self.num, False)
return Z3_rcf_num_to_string(self.ctx_ref(), self.num, False, RCFNum.html)
def compact_str(self):
return Z3_rcf_num_to_string(self.ctx_ref(), self.num, True)
return Z3_rcf_num_to_string(self.ctx_ref(), self.num, True, RCFNum.html)
def __add__(self, other):
v = _to_rcfnum(other, self.ctx)

View file

@ -64,9 +64,9 @@ extern "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)))
def_API('Z3_rcf_mk_infinitesimal', RCF_NUM, (_in(CONTEXT),))
*/
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(__in Z3_context c, __in Z3_string name);
Z3_rcf_num Z3_API Z3_rcf_mk_infinitesimal(__in Z3_context c);
/**
\brief Store in roots the roots of the polynomial <tt>a[n-1]*x^{n-1} + ... + a[0]</tt>.
@ -173,9 +173,9 @@ extern "C" {
/**
\brief Convert the RCF numeral into a string.
def_API('Z3_rcf_num_to_string', STRING, (_in(CONTEXT), _in(RCF_NUM), _in(BOOL)))
def_API('Z3_rcf_num_to_string', STRING, (_in(CONTEXT), _in(RCF_NUM), _in(BOOL), _in(BOOL)))
*/
Z3_string Z3_API Z3_rcf_num_to_string(__in Z3_context c, __in Z3_rcf_num a, __in Z3_bool compact);
Z3_string Z3_API Z3_rcf_num_to_string(__in Z3_context c, __in Z3_rcf_num a, __in Z3_bool compact, __in Z3_bool html);
/**
\brief Convert the RCF numeral into a string in decimal notation.