mirror of
https://github.com/Z3Prover/z3
synced 2025-04-15 13:28:47 +00:00
Add html pretty printing mode for RCF package
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
8e2298c327
commit
77f58269ed
|
@ -98,13 +98,13 @@ extern "C" {
|
||||||
Z3_CATCH_RETURN(0);
|
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;
|
Z3_TRY;
|
||||||
LOG_Z3_rcf_mk_infinitesimal(c, name);
|
LOG_Z3_rcf_mk_infinitesimal(c);
|
||||||
RESET_ERROR_CODE();
|
RESET_ERROR_CODE();
|
||||||
reset_rcf_cancel(c);
|
reset_rcf_cancel(c);
|
||||||
rcnumeral r;
|
rcnumeral r;
|
||||||
rcfm(c).mk_infinitesimal(name, r);
|
rcfm(c).mk_infinitesimal(r);
|
||||||
RETURN_Z3(from_rcnumeral(r));
|
RETURN_Z3(from_rcnumeral(r));
|
||||||
Z3_CATCH_RETURN(0);
|
Z3_CATCH_RETURN(0);
|
||||||
}
|
}
|
||||||
|
@ -268,13 +268,13 @@ extern "C" {
|
||||||
Z3_CATCH_RETURN(Z3_FALSE);
|
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;
|
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_ERROR_CODE();
|
||||||
reset_rcf_cancel(c);
|
reset_rcf_cancel(c);
|
||||||
std::ostringstream buffer;
|
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());
|
return mk_c(c)->mk_external_string(buffer.str());
|
||||||
Z3_CATCH_RETURN("");
|
Z3_CATCH_RETURN("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,10 @@ def E(ctx=None):
|
||||||
return RCFNum(Z3_rcf_mk_e(ctx.ref()), ctx)
|
return RCFNum(Z3_rcf_mk_e(ctx.ref()), ctx)
|
||||||
|
|
||||||
def MkInfinitesimal(name="eps", ctx=None):
|
def MkInfinitesimal(name="eps", ctx=None):
|
||||||
|
# Todo: remove parameter name.
|
||||||
|
# For now, we keep it for backward compatibility.
|
||||||
ctx = z3._get_ctx(ctx)
|
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):
|
def MkRoots(p, ctx=None):
|
||||||
ctx = z3._get_ctx(ctx)
|
ctx = z3._get_ctx(ctx)
|
||||||
|
@ -49,6 +51,7 @@ def MkRoots(p, ctx=None):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
class RCFNum:
|
class RCFNum:
|
||||||
|
html = False
|
||||||
def __init__(self, num, ctx=None):
|
def __init__(self, num, ctx=None):
|
||||||
# TODO: add support for converting AST numeral values into RCFNum
|
# TODO: add support for converting AST numeral values into RCFNum
|
||||||
if isinstance(num, RCFNumObj):
|
if isinstance(num, RCFNumObj):
|
||||||
|
@ -65,10 +68,10 @@ class RCFNum:
|
||||||
return self.ctx.ref()
|
return self.ctx.ref()
|
||||||
|
|
||||||
def __repr__(self):
|
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):
|
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):
|
def __add__(self, other):
|
||||||
v = _to_rcfnum(other, self.ctx)
|
v = _to_rcfnum(other, self.ctx)
|
||||||
|
|
|
@ -64,9 +64,9 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
\brief Return a new infinitesimal that is smaller than all elements in the Z3 field.
|
\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>.
|
\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.
|
\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.
|
\brief Convert the RCF numeral into a string in decimal notation.
|
||||||
|
|
|
@ -231,6 +231,7 @@ public:
|
||||||
bool contains(interval const & n, numeral const & v) const;
|
bool contains(interval const & n, numeral const & v) const;
|
||||||
|
|
||||||
void display(std::ostream & out, interval const & n) const;
|
void display(std::ostream & out, interval const & n) const;
|
||||||
|
void display_pp(std::ostream & out, interval const & n) const;
|
||||||
|
|
||||||
bool check_invariant(interval const & n) const;
|
bool check_invariant(interval const & n) const;
|
||||||
|
|
||||||
|
|
|
@ -643,6 +643,15 @@ void interval_manager<C>::display(std::ostream & out, interval const & n) const
|
||||||
out << (upper_is_open(n) ? ")" : "]");
|
out << (upper_is_open(n) ? ")" : "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename C>
|
||||||
|
void interval_manager<C>::display_pp(std::ostream & out, interval const & n) const {
|
||||||
|
out << (lower_is_open(n) ? "(" : "[");
|
||||||
|
::display_pp(out, m(), lower(n), lower_kind(n));
|
||||||
|
out << ", ";
|
||||||
|
::display_pp(out, m(), upper(n), upper_kind(n));
|
||||||
|
out << (upper_is_open(n) ? ")" : "]");
|
||||||
|
}
|
||||||
|
|
||||||
template<typename C>
|
template<typename C>
|
||||||
bool interval_manager<C>::check_invariant(interval const & n) const {
|
bool interval_manager<C>::check_invariant(interval const & n) const {
|
||||||
if (::eq(m(), lower(n), lower_kind(n), upper(n), upper_kind(n))) {
|
if (::eq(m(), lower(n), lower_kind(n), upper(n), upper_kind(n))) {
|
||||||
|
|
|
@ -298,26 +298,41 @@ namespace realclosure {
|
||||||
|
|
||||||
struct transcendental : public extension {
|
struct transcendental : public extension {
|
||||||
symbol m_name;
|
symbol m_name;
|
||||||
|
symbol m_pp_name;
|
||||||
unsigned m_k;
|
unsigned m_k;
|
||||||
mk_interval & m_proc;
|
mk_interval & m_proc;
|
||||||
|
|
||||||
transcendental(unsigned idx, symbol const & n, mk_interval & p):extension(TRANSCENDENTAL, idx), m_name(n), m_k(0), m_proc(p) {}
|
transcendental(unsigned idx, symbol const & n, symbol const & pp_n, mk_interval & p):
|
||||||
|
extension(TRANSCENDENTAL, idx), m_name(n), m_pp_name(pp_n), m_k(0), m_proc(p) {}
|
||||||
|
|
||||||
void display(std::ostream & out) const {
|
void display(std::ostream & out, bool pp = false) const {
|
||||||
out << m_name;
|
if (pp)
|
||||||
|
out << m_pp_name;
|
||||||
|
else
|
||||||
|
out << m_name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct infinitesimal : public extension {
|
struct infinitesimal : public extension {
|
||||||
symbol m_name;
|
symbol m_name;
|
||||||
|
symbol m_pp_name;
|
||||||
|
|
||||||
infinitesimal(unsigned idx, symbol const & n):extension(INFINITESIMAL, idx), m_name(n) {}
|
infinitesimal(unsigned idx, symbol const & n, symbol const & pp_n):extension(INFINITESIMAL, idx), m_name(n), m_pp_name(pp_n) {}
|
||||||
|
|
||||||
void display(std::ostream & out) const {
|
void display(std::ostream & out, bool pp = false) const {
|
||||||
if (m_name.is_numerical())
|
if (pp) {
|
||||||
out << "eps!" << m_name.get_num();
|
if (m_pp_name.is_numerical())
|
||||||
else
|
out << "ε<sub>" << m_pp_name.get_num() << "</sub>";
|
||||||
out << m_name;
|
else
|
||||||
|
out << m_pp_name;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (m_name.is_numerical())
|
||||||
|
out << "eps!" << m_name.get_num();
|
||||||
|
else
|
||||||
|
out << m_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1266,9 +1281,9 @@ namespace realclosure {
|
||||||
/**
|
/**
|
||||||
\brief Create a new infinitesimal.
|
\brief Create a new infinitesimal.
|
||||||
*/
|
*/
|
||||||
void mk_infinitesimal(symbol const & n, numeral & r) {
|
void mk_infinitesimal(symbol const & n, symbol const & pp_n, numeral & r) {
|
||||||
unsigned idx = next_infinitesimal_idx();
|
unsigned idx = next_infinitesimal_idx();
|
||||||
infinitesimal * eps = alloc(infinitesimal, idx, n);
|
infinitesimal * eps = alloc(infinitesimal, idx, n, pp_n);
|
||||||
m_extensions[extension::INFINITESIMAL].push_back(eps);
|
m_extensions[extension::INFINITESIMAL].push_back(eps);
|
||||||
|
|
||||||
set_lower(eps->interval(), mpbq(0));
|
set_lower(eps->interval(), mpbq(0));
|
||||||
|
@ -1280,12 +1295,12 @@ namespace realclosure {
|
||||||
SASSERT(depends_on_infinitesimals(r));
|
SASSERT(depends_on_infinitesimals(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mk_infinitesimal(char const * n, numeral & r) {
|
void mk_infinitesimal(char const * n, char const * pp_n, numeral & r) {
|
||||||
mk_infinitesimal(symbol(n), r);
|
mk_infinitesimal(symbol(n), symbol(pp_n), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mk_infinitesimal(numeral & r) {
|
void mk_infinitesimal(numeral & r) {
|
||||||
mk_infinitesimal(symbol(next_infinitesimal_idx()), r);
|
mk_infinitesimal(symbol(next_infinitesimal_idx()), symbol(next_infinitesimal_idx()), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void refine_transcendental_interval(transcendental * t) {
|
void refine_transcendental_interval(transcendental * t) {
|
||||||
|
@ -1318,9 +1333,9 @@ namespace realclosure {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mk_transcendental(symbol const & n, mk_interval & proc, numeral & r) {
|
void mk_transcendental(symbol const & n, symbol const & pp_n, mk_interval & proc, numeral & r) {
|
||||||
unsigned idx = next_transcendental_idx();
|
unsigned idx = next_transcendental_idx();
|
||||||
transcendental * t = alloc(transcendental, idx, n, proc);
|
transcendental * t = alloc(transcendental, idx, n, pp_n, proc);
|
||||||
m_extensions[extension::TRANSCENDENTAL].push_back(t);
|
m_extensions[extension::TRANSCENDENTAL].push_back(t);
|
||||||
|
|
||||||
while (contains_zero(t->interval())) {
|
while (contains_zero(t->interval())) {
|
||||||
|
@ -1332,12 +1347,12 @@ namespace realclosure {
|
||||||
SASSERT(!depends_on_infinitesimals(r));
|
SASSERT(!depends_on_infinitesimals(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mk_transcendental(char const * p, mk_interval & proc, numeral & r) {
|
void mk_transcendental(char const * p, char const * pp_n, mk_interval & proc, numeral & r) {
|
||||||
mk_transcendental(symbol(p), proc, r);
|
mk_transcendental(symbol(p), symbol(pp_n), proc, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mk_transcendental(mk_interval & proc, numeral & r) {
|
void mk_transcendental(mk_interval & proc, numeral & r) {
|
||||||
mk_transcendental(symbol(next_transcendental_idx()), proc, r);
|
mk_transcendental(symbol(next_transcendental_idx()), symbol(next_transcendental_idx()), proc, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mk_pi(numeral & r) {
|
void mk_pi(numeral & r) {
|
||||||
|
@ -1345,7 +1360,7 @@ namespace realclosure {
|
||||||
set(r, m_pi);
|
set(r, m_pi);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mk_transcendental(symbol("pi"), m_mk_pi_interval, r);
|
mk_transcendental(symbol("pi"), symbol("π"), m_mk_pi_interval, r);
|
||||||
m_pi = r.m_value;
|
m_pi = r.m_value;
|
||||||
inc_ref(m_pi);
|
inc_ref(m_pi);
|
||||||
}
|
}
|
||||||
|
@ -1356,7 +1371,7 @@ namespace realclosure {
|
||||||
set(r, m_e);
|
set(r, m_e);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mk_transcendental(symbol("e"), m_mk_e_interval, r);
|
mk_transcendental(symbol("e"), symbol("e"), m_mk_e_interval, r);
|
||||||
m_e = r.m_value;
|
m_e = r.m_value;
|
||||||
inc_ref(m_e);
|
inc_ref(m_e);
|
||||||
}
|
}
|
||||||
|
@ -5762,7 +5777,7 @@ namespace realclosure {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename DisplayVar>
|
template<typename DisplayVar>
|
||||||
void display_polynomial(std::ostream & out, unsigned sz, value * const * p, DisplayVar const & display_var, bool compact) const {
|
void display_polynomial(std::ostream & out, unsigned sz, value * const * p, DisplayVar const & display_var, bool compact, bool pp) const {
|
||||||
if (sz == 0) {
|
if (sz == 0) {
|
||||||
out << "0";
|
out << "0";
|
||||||
return;
|
return;
|
||||||
|
@ -5778,33 +5793,44 @@ namespace realclosure {
|
||||||
else
|
else
|
||||||
out << " + ";
|
out << " + ";
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
display(out, p[i], compact);
|
display(out, p[i], compact, pp);
|
||||||
else {
|
else {
|
||||||
if (!is_rational_one(p[i])) {
|
if (!is_rational_one(p[i])) {
|
||||||
if (use_parenthesis(p[i])) {
|
if (use_parenthesis(p[i])) {
|
||||||
out << "(";
|
out << "(";
|
||||||
display(out, p[i], compact);
|
display(out, p[i], compact, pp);
|
||||||
out << ")*";
|
out << ")";
|
||||||
|
if (pp)
|
||||||
|
out << " ";
|
||||||
|
else
|
||||||
|
out << "*";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
display(out, p[i], compact);
|
display(out, p[i], compact, pp);
|
||||||
out << "*";
|
if (pp)
|
||||||
|
out << " ";
|
||||||
|
else
|
||||||
|
out << "*";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
display_var(out, compact);
|
display_var(out, compact, pp);
|
||||||
if (i > 1)
|
if (i > 1) {
|
||||||
out << "^" << i;
|
if (pp)
|
||||||
|
out << "<sup>" << i << "</sup>";
|
||||||
|
else
|
||||||
|
out << "^" << i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename DisplayVar>
|
template<typename DisplayVar>
|
||||||
void display_polynomial(std::ostream & out, polynomial const & p, DisplayVar const & display_var, bool compact) const {
|
void display_polynomial(std::ostream & out, polynomial const & p, DisplayVar const & display_var, bool compact, bool pp) const {
|
||||||
display_polynomial(out, p.size(), p.c_ptr(), display_var, compact);
|
display_polynomial(out, p.size(), p.c_ptr(), display_var, compact, pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct display_free_var_proc {
|
struct display_free_var_proc {
|
||||||
void operator()(std::ostream & out, bool compact) const {
|
void operator()(std::ostream & out, bool compact, bool pp) const {
|
||||||
out << "x";
|
out << "x";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5813,13 +5839,13 @@ namespace realclosure {
|
||||||
imp const & m;
|
imp const & m;
|
||||||
extension * m_ref;
|
extension * m_ref;
|
||||||
display_ext_proc(imp const & _m, extension * r):m(_m), m_ref(r) {}
|
display_ext_proc(imp const & _m, extension * r):m(_m), m_ref(r) {}
|
||||||
void operator()(std::ostream & out, bool compact) const {
|
void operator()(std::ostream & out, bool compact, bool pp) const {
|
||||||
m.display_ext(out, m_ref, compact);
|
m.display_ext(out, m_ref, compact, pp);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void display_polynomial_expr(std::ostream & out, polynomial const & p, extension * ext, bool compact) const {
|
void display_polynomial_expr(std::ostream & out, polynomial const & p, extension * ext, bool compact, bool pp) const {
|
||||||
display_polynomial(out, p, display_ext_proc(*this, ext), compact);
|
display_polynomial(out, p, display_ext_proc(*this, ext), compact, pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void display_poly_sign(std::ostream & out, int s) {
|
static void display_poly_sign(std::ostream & out, int s) {
|
||||||
|
@ -5846,7 +5872,7 @@ namespace realclosure {
|
||||||
out << "}";
|
out << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_sign_conditions(std::ostream & out, sign_condition * sc, array<polynomial> const & qs, bool compact) const {
|
void display_sign_conditions(std::ostream & out, sign_condition * sc, array<polynomial> const & qs, bool compact, bool pp) const {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
out << "{";
|
out << "{";
|
||||||
while (sc) {
|
while (sc) {
|
||||||
|
@ -5854,21 +5880,28 @@ namespace realclosure {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
else
|
||||||
out << ", ";
|
out << ", ";
|
||||||
display_polynomial(out, qs[sc->qidx()], display_free_var_proc(), compact);
|
display_polynomial(out, qs[sc->qidx()], display_free_var_proc(), compact, pp);
|
||||||
display_poly_sign(out, sc->sign());
|
display_poly_sign(out, sc->sign());
|
||||||
sc = sc->prev();
|
sc = sc->prev();
|
||||||
}
|
}
|
||||||
out << "}";
|
out << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_algebraic_def(std::ostream & out, algebraic * a, bool compact) const {
|
void display_interval(std::ostream & out, mpbqi const & i, bool pp) const {
|
||||||
|
if (pp)
|
||||||
|
bqim().display_pp(out, i);
|
||||||
|
else
|
||||||
|
bqim().display(out, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_algebraic_def(std::ostream & out, algebraic * a, bool compact, bool pp) const {
|
||||||
out << "root(";
|
out << "root(";
|
||||||
display_polynomial(out, a->p(), display_free_var_proc(), compact);
|
display_polynomial(out, a->p(), display_free_var_proc(), compact, pp);
|
||||||
out << ", ";
|
out << ", ";
|
||||||
bqim().display(out, a->iso_interval());
|
display_interval(out, a->iso_interval(), pp);
|
||||||
out << ", ";
|
out << ", ";
|
||||||
if (a->sdt() != 0)
|
if (a->sdt() != 0)
|
||||||
display_sign_conditions(out, a->sdt()->sc(a->sc_idx()), a->sdt()->qs(), compact);
|
display_sign_conditions(out, a->sdt()->sc(a->sc_idx()), a->sdt()->qs(), compact, pp);
|
||||||
else
|
else
|
||||||
out << "{}";
|
out << "{}";
|
||||||
out << ")";
|
out << ")";
|
||||||
|
@ -5878,28 +5911,33 @@ namespace realclosure {
|
||||||
collect_algebraic_refs c;
|
collect_algebraic_refs c;
|
||||||
for (unsigned i = 0; i < n; i++)
|
for (unsigned i = 0; i < n; i++)
|
||||||
c.mark(p[i]);
|
c.mark(p[i]);
|
||||||
display_polynomial(out, n, p, display_free_var_proc(), true);
|
display_polynomial(out, n, p, display_free_var_proc(), true, false);
|
||||||
std::sort(c.m_found.begin(), c.m_found.end(), rank_lt_proc());
|
std::sort(c.m_found.begin(), c.m_found.end(), rank_lt_proc());
|
||||||
for (unsigned i = 0; i < c.m_found.size(); i++) {
|
for (unsigned i = 0; i < c.m_found.size(); i++) {
|
||||||
algebraic * ext = c.m_found[i];
|
algebraic * ext = c.m_found[i];
|
||||||
out << "\n r!" << ext->idx() << " := ";
|
out << "\n r!" << ext->idx() << " := ";
|
||||||
display_algebraic_def(out, ext, true);
|
display_algebraic_def(out, ext, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_ext(std::ostream & out, extension * r, bool compact) const {
|
void display_ext(std::ostream & out, extension * r, bool compact, bool pp) const {
|
||||||
switch (r->knd()) {
|
switch (r->knd()) {
|
||||||
case extension::TRANSCENDENTAL: to_transcendental(r)->display(out); break;
|
case extension::TRANSCENDENTAL: to_transcendental(r)->display(out, pp); break;
|
||||||
case extension::INFINITESIMAL: to_infinitesimal(r)->display(out); break;
|
case extension::INFINITESIMAL: to_infinitesimal(r)->display(out, pp); break;
|
||||||
case extension::ALGEBRAIC:
|
case extension::ALGEBRAIC:
|
||||||
if (compact)
|
if (compact) {
|
||||||
out << "r!" << r->idx();
|
if (pp)
|
||||||
else
|
out << "α<sub>" << r->idx() << "</sub>";
|
||||||
display_algebraic_def(out, to_algebraic(r), compact);
|
else
|
||||||
|
out << "r!" << r->idx();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
display_algebraic_def(out, to_algebraic(r), compact, pp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(std::ostream & out, value * v, bool compact) const {
|
void display(std::ostream & out, value * v, bool compact, bool pp=false) const {
|
||||||
if (v == 0)
|
if (v == 0)
|
||||||
out << "0";
|
out << "0";
|
||||||
else if (is_nz_rational(v))
|
else if (is_nz_rational(v))
|
||||||
|
@ -5907,51 +5945,50 @@ namespace realclosure {
|
||||||
else {
|
else {
|
||||||
rational_function_value * rf = to_rational_function(v);
|
rational_function_value * rf = to_rational_function(v);
|
||||||
if (is_denominator_one(rf)) {
|
if (is_denominator_one(rf)) {
|
||||||
display_polynomial_expr(out, rf->num(), rf->ext(), compact);
|
display_polynomial_expr(out, rf->num(), rf->ext(), compact, pp);
|
||||||
}
|
}
|
||||||
else if (is_rational_one(rf->num())) {
|
else if (is_rational_one(rf->num())) {
|
||||||
out << "1/(";
|
out << "1/(";
|
||||||
display_polynomial_expr(out, rf->den(), rf->ext(), compact);
|
display_polynomial_expr(out, rf->den(), rf->ext(), compact, pp);
|
||||||
out << ")";
|
out << ")";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
out << "(";
|
out << "(";
|
||||||
display_polynomial_expr(out, rf->num(), rf->ext(), compact);
|
display_polynomial_expr(out, rf->num(), rf->ext(), compact, pp);
|
||||||
out << ")/(";
|
out << ")/(";
|
||||||
display_polynomial_expr(out, rf->den(), rf->ext(), compact);
|
display_polynomial_expr(out, rf->den(), rf->ext(), compact, pp);
|
||||||
out << ")";
|
out << ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_compact(std::ostream & out, value * a) const {
|
void display_compact(std::ostream & out, value * a, bool pp=false) const {
|
||||||
collect_algebraic_refs c;
|
collect_algebraic_refs c;
|
||||||
c.mark(a);
|
c.mark(a);
|
||||||
if (c.m_found.empty()) {
|
if (c.m_found.empty()) {
|
||||||
display(out, a, true);
|
display(out, a, true, pp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::sort(c.m_found.begin(), c.m_found.end(), rank_lt_proc());
|
std::sort(c.m_found.begin(), c.m_found.end(), rank_lt_proc());
|
||||||
out << "[";
|
out << "[";
|
||||||
display(out, a, true);
|
display(out, a, true, pp);
|
||||||
for (unsigned i = 0; i < c.m_found.size(); i++) {
|
for (unsigned i = 0; i < c.m_found.size(); i++) {
|
||||||
algebraic * ext = c.m_found[i];
|
algebraic * ext = c.m_found[i];
|
||||||
out << "; r!" << ext->idx() << " := ";
|
if (pp)
|
||||||
display_algebraic_def(out, ext, true);
|
out << "; α<sub>" << ext->idx() << "</sub> := ";
|
||||||
|
else
|
||||||
|
out << "; r!" << ext->idx() << " := ";
|
||||||
|
display_algebraic_def(out, ext, true, pp);
|
||||||
}
|
}
|
||||||
out << "]";
|
out << "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_compact(std::ostream & out, numeral const & a) const {
|
void display(std::ostream & out, numeral const & a, bool compact=false, bool pp=false) const {
|
||||||
display_compact(out, a.m_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void display(std::ostream & out, numeral const & a, bool compact=false) const {
|
|
||||||
if (compact)
|
if (compact)
|
||||||
display_compact(out, a);
|
display_compact(out, a.m_value, pp);
|
||||||
else
|
else
|
||||||
display(out, a.m_value, false);
|
display(out, a.m_value, false, pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_non_rational_in_decimal(std::ostream & out, numeral const & a, unsigned precision) {
|
void display_non_rational_in_decimal(std::ostream & out, numeral const & a, unsigned precision) {
|
||||||
|
@ -5989,7 +6026,7 @@ namespace realclosure {
|
||||||
if (is_zero(a))
|
if (is_zero(a))
|
||||||
out << "[0, 0]";
|
out << "[0, 0]";
|
||||||
else
|
else
|
||||||
bqim().display(out, interval(a.m_value));
|
display_interval(out, interval(a.m_value), false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6029,16 +6066,16 @@ namespace realclosure {
|
||||||
m_imp->del(a);
|
m_imp->del(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::mk_infinitesimal(char const * n, numeral & r) {
|
void manager::mk_infinitesimal(char const * n, char const * pp_n, numeral & r) {
|
||||||
m_imp->mk_infinitesimal(n, r);
|
m_imp->mk_infinitesimal(n, pp_n, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::mk_infinitesimal(numeral & r) {
|
void manager::mk_infinitesimal(numeral & r) {
|
||||||
m_imp->mk_infinitesimal(r);
|
m_imp->mk_infinitesimal(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::mk_transcendental(char const * n, mk_interval & proc, numeral & r) {
|
void manager::mk_transcendental(char const * n, char const * pp_n, mk_interval & proc, numeral & r) {
|
||||||
m_imp->mk_transcendental(n, proc, r);
|
m_imp->mk_transcendental(n, pp_n, proc, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::mk_transcendental(mk_interval & proc, numeral & r) {
|
void manager::mk_transcendental(mk_interval & proc, numeral & r) {
|
||||||
|
@ -6212,9 +6249,9 @@ namespace realclosure {
|
||||||
return gt(a, _b);
|
return gt(a, _b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::display(std::ostream & out, numeral const & a, bool compact) const {
|
void manager::display(std::ostream & out, numeral const & a, bool compact, bool pp) const {
|
||||||
save_interval_ctx ctx(this);
|
save_interval_ctx ctx(this);
|
||||||
m_imp->display(out, a, compact);
|
m_imp->display(out, a, compact, pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::display_decimal(std::ostream & out, numeral const & a, unsigned precision) const {
|
void manager::display_decimal(std::ostream & out, numeral const & a, unsigned precision) const {
|
||||||
|
@ -6234,7 +6271,7 @@ namespace realclosure {
|
||||||
};
|
};
|
||||||
|
|
||||||
void pp(realclosure::manager::imp * imp, realclosure::polynomial const & p, realclosure::extension * ext) {
|
void pp(realclosure::manager::imp * imp, realclosure::polynomial const & p, realclosure::extension * ext) {
|
||||||
imp->display_polynomial_expr(std::cout, p, ext, false);
|
imp->display_polynomial_expr(std::cout, p, ext, false, false);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6278,6 +6315,6 @@ void pp(realclosure::manager::imp * imp, mpq const & n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pp(realclosure::manager::imp * imp, realclosure::extension * x) {
|
void pp(realclosure::manager::imp * imp, realclosure::extension * x) {
|
||||||
imp->display_ext(std::cout, x, false);
|
imp->display_ext(std::cout, x, false, false);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace realclosure {
|
||||||
/**
|
/**
|
||||||
\brief Add a new infinitesimal to the current field. The new infinitesimal is smaller than any positive element in the field.
|
\brief Add a new infinitesimal to the current field. The new infinitesimal is smaller than any positive element in the field.
|
||||||
*/
|
*/
|
||||||
void mk_infinitesimal(char const * name, numeral & r);
|
void mk_infinitesimal(char const * name, char const * pp_name, numeral & r);
|
||||||
void mk_infinitesimal(numeral & r);
|
void mk_infinitesimal(numeral & r);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ namespace realclosure {
|
||||||
Then, we extend the field F with 1 - Pi. 1 - Pi is transcendental with respect to algebraic real numbers, but it is NOT transcendental
|
Then, we extend the field F with 1 - Pi. 1 - Pi is transcendental with respect to algebraic real numbers, but it is NOT transcendental
|
||||||
with respect to F, since F contains Pi.
|
with respect to F, since F contains Pi.
|
||||||
*/
|
*/
|
||||||
void mk_transcendental(char const * name, mk_interval & proc, numeral & r);
|
void mk_transcendental(char const * name, char const * pp_name, mk_interval & proc, numeral & r);
|
||||||
void mk_transcendental(mk_interval & proc, numeral & r);
|
void mk_transcendental(mk_interval & proc, numeral & r);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,7 +252,7 @@ namespace realclosure {
|
||||||
bool ge(numeral const & a, mpq const & b) { return !lt(a, b); }
|
bool ge(numeral const & a, mpq const & b) { return !lt(a, b); }
|
||||||
bool ge(numeral const & a, mpz const & b) { return !lt(a, b); }
|
bool ge(numeral const & a, mpz const & b) { return !lt(a, b); }
|
||||||
|
|
||||||
void display(std::ostream & out, numeral const & a, bool compact=false) const;
|
void display(std::ostream & out, numeral const & a, bool compact=false, bool pp=false) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\brief Display a real number in decimal notation.
|
\brief Display a real number in decimal notation.
|
||||||
|
|
|
@ -332,4 +332,16 @@ void display(std::ostream & out,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename numeral_manager>
|
||||||
|
void display_pp(std::ostream & out,
|
||||||
|
numeral_manager & m,
|
||||||
|
typename numeral_manager::numeral const & a,
|
||||||
|
ext_numeral_kind ak) {
|
||||||
|
switch (ak) {
|
||||||
|
case EN_MINUS_INFINITY: out << "-∞"; break;
|
||||||
|
case EN_NUMERAL: m.display(out, a); break;
|
||||||
|
case EN_PLUS_INFINITY: out << "+∞"; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue