Z3
Loading...
Searching...
No Matches
rcf_num Class Reference

Wrapper for Z3 Real Closed Field (RCF) numerals. More...

#include <z3++.h>

Public Member Functions

 rcf_num (context &c, Z3_rcf_num n)
 rcf_num (context &c, int val)
 rcf_num (context &c, char const *val)
 rcf_num (rcf_num const &other)
rcf_num & operator= (rcf_num const &other)
 ~rcf_num ()
 operator Z3_rcf_num () const
Z3_context ctx () const
std::string to_string (bool compact=false) const
 Return string representation of the RCF numeral.
std::string to_decimal (unsigned precision=10) const
 Return decimal string representation with given precision.
rcf_num operator+ (rcf_num const &other) const
rcf_num operator- (rcf_num const &other) const
rcf_num operator* (rcf_num const &other) const
rcf_num operator/ (rcf_num const &other) const
rcf_num operator- () const
rcf_num power (unsigned k) const
 Return the power of this number raised to k.
rcf_num inv () const
 Return the multiplicative inverse (1/this).
bool operator< (rcf_num const &other) const
bool operator> (rcf_num const &other) const
bool operator<= (rcf_num const &other) const
bool operator>= (rcf_num const &other) const
bool operator== (rcf_num const &other) const
bool operator!= (rcf_num const &other) const
bool is_rational () const
bool is_algebraic () const
bool is_infinitesimal () const
bool is_transcendental () const

Friends

std::ostream & operator<< (std::ostream &out, rcf_num const &n)

Detailed Description

Wrapper for Z3 Real Closed Field (RCF) numerals.

RCF numerals can represent:

  • Rational numbers
  • Algebraic numbers (roots of polynomials)
  • Transcendental extensions (e.g., pi, e)
  • Infinitesimal extensions

Definition at line 5076 of file z3++.h.

Constructor & Destructor Documentation

◆ rcf_num() [1/4]

◆ rcf_num() [2/4]

rcf_num ( context & c,
int val )
inline

Definition at line 5089 of file z3++.h.

5089 : m_ctx(c) {
5090 m_num = Z3_rcf_mk_small_int(c, val);
5091 }
Z3_rcf_num Z3_API Z3_rcf_mk_small_int(Z3_context c, int val)
Return a RCF small integer.

◆ rcf_num() [3/4]

rcf_num ( context & c,
char const * val )
inline

Definition at line 5093 of file z3++.h.

5093 : m_ctx(c) {
5094 m_num = Z3_rcf_mk_rational(c, val);
5095 }
Z3_rcf_num Z3_API Z3_rcf_mk_rational(Z3_context c, Z3_string val)
Return a RCF rational using the given string.

◆ rcf_num() [4/4]

rcf_num ( rcf_num const & other)
inline

Definition at line 5097 of file z3++.h.

5097 : m_ctx(other.m_ctx) {
5098 // Create a copy by converting to string and back
5099 std::string str = Z3_rcf_num_to_string(m_ctx, other.m_num, false, false);
5100 m_num = Z3_rcf_mk_rational(m_ctx, str.c_str());
5101 }
Z3_string Z3_API Z3_rcf_num_to_string(Z3_context c, Z3_rcf_num a, bool compact, bool html)
Convert the RCF numeral into a string.

◆ ~rcf_num()

~rcf_num ( )
inline

Definition at line 5113 of file z3++.h.

5113 {
5114 Z3_rcf_del(m_ctx, m_num);
5115 }
void Z3_API Z3_rcf_del(Z3_context c, Z3_rcf_num a)
Delete a RCF numeral created using the RCF API.

Member Function Documentation

◆ ctx()

Z3_context ctx ( ) const
inline

Definition at line 5118 of file z3++.h.

5118{ return m_ctx; }

◆ inv()

rcf_num inv ( ) const
inline

Return the multiplicative inverse (1/this).

Definition at line 5175 of file z3++.h.

5175 {
5176 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5177 Z3_rcf_inv(m_ctx, m_num));
5178 }
Z3_rcf_num Z3_API Z3_rcf_inv(Z3_context c, Z3_rcf_num a)
Return the value 1/a.

◆ is_algebraic()

bool is_algebraic ( ) const
inline

Definition at line 5216 of file z3++.h.

5216 {
5217 return Z3_rcf_is_algebraic(m_ctx, m_num);
5218 }
bool Z3_API Z3_rcf_is_algebraic(Z3_context c, Z3_rcf_num a)
Return true if a represents an algebraic number.

◆ is_infinitesimal()

bool is_infinitesimal ( ) const
inline

Definition at line 5220 of file z3++.h.

5220 {
5221 return Z3_rcf_is_infinitesimal(m_ctx, m_num);
5222 }
bool Z3_API Z3_rcf_is_infinitesimal(Z3_context c, Z3_rcf_num a)
Return true if a represents an infinitesimal.

◆ is_rational()

bool is_rational ( ) const
inline

Definition at line 5212 of file z3++.h.

5212 {
5213 return Z3_rcf_is_rational(m_ctx, m_num);
5214 }
bool Z3_API Z3_rcf_is_rational(Z3_context c, Z3_rcf_num a)
Return true if a represents a rational number.

◆ is_transcendental()

bool is_transcendental ( ) const
inline

Definition at line 5224 of file z3++.h.

5224 {
5225 return Z3_rcf_is_transcendental(m_ctx, m_num);
5226 }
bool Z3_API Z3_rcf_is_transcendental(Z3_context c, Z3_rcf_num a)
Return true if a represents a transcendental number.

◆ operator Z3_rcf_num()

operator Z3_rcf_num ( ) const
inline

Definition at line 5117 of file z3++.h.

5117{ return m_num; }

◆ operator!=()

bool operator!= ( rcf_num const & other) const
inline

Definition at line 5206 of file z3++.h.

5206 {
5207 check_context(other);
5208 return Z3_rcf_neq(m_ctx, m_num, other.m_num);
5209 }
bool Z3_API Z3_rcf_neq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a != b.
void check_context(object const &a, object const &b)
Definition z3++.h:566

◆ operator*()

rcf_num operator* ( rcf_num const & other) const
inline

Definition at line 5147 of file z3++.h.

5147 {
5148 check_context(other);
5149 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5150 Z3_rcf_mul(m_ctx, m_num, other.m_num));
5151 }
Z3_rcf_num Z3_API Z3_rcf_mul(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a * b.

◆ operator+()

rcf_num operator+ ( rcf_num const & other) const
inline

Definition at line 5135 of file z3++.h.

5135 {
5136 check_context(other);
5137 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5138 Z3_rcf_add(m_ctx, m_num, other.m_num));
5139 }
Z3_rcf_num Z3_API Z3_rcf_add(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a + b.

◆ operator-() [1/2]

rcf_num operator- ( ) const
inline

Definition at line 5159 of file z3++.h.

5159 {
5160 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5161 Z3_rcf_neg(m_ctx, m_num));
5162 }
Z3_rcf_num Z3_API Z3_rcf_neg(Z3_context c, Z3_rcf_num a)
Return the value -a.

◆ operator-() [2/2]

rcf_num operator- ( rcf_num const & other) const
inline

Definition at line 5141 of file z3++.h.

5141 {
5142 check_context(other);
5143 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5144 Z3_rcf_sub(m_ctx, m_num, other.m_num));
5145 }
Z3_rcf_num Z3_API Z3_rcf_sub(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a - b.

◆ operator/()

rcf_num operator/ ( rcf_num const & other) const
inline

Definition at line 5153 of file z3++.h.

5153 {
5154 check_context(other);
5155 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5156 Z3_rcf_div(m_ctx, m_num, other.m_num));
5157 }
Z3_rcf_num Z3_API Z3_rcf_div(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return the value a / b.

◆ operator<()

bool operator< ( rcf_num const & other) const
inline

Definition at line 5181 of file z3++.h.

5181 {
5182 check_context(other);
5183 return Z3_rcf_lt(m_ctx, m_num, other.m_num);
5184 }
bool Z3_API Z3_rcf_lt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a < b.

◆ operator<=()

bool operator<= ( rcf_num const & other) const
inline

Definition at line 5191 of file z3++.h.

5191 {
5192 check_context(other);
5193 return Z3_rcf_le(m_ctx, m_num, other.m_num);
5194 }
bool Z3_API Z3_rcf_le(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a <= b.

◆ operator=()

rcf_num & operator= ( rcf_num const & other)
inline

Definition at line 5103 of file z3++.h.

5103 {
5104 if (this != &other) {
5105 Z3_rcf_del(m_ctx, m_num);
5106 m_ctx = other.m_ctx;
5107 std::string str = Z3_rcf_num_to_string(m_ctx, other.m_num, false, false);
5108 m_num = Z3_rcf_mk_rational(m_ctx, str.c_str());
5109 }
5110 return *this;
5111 }

◆ operator==()

bool operator== ( rcf_num const & other) const
inline

Definition at line 5201 of file z3++.h.

5201 {
5202 check_context(other);
5203 return Z3_rcf_eq(m_ctx, m_num, other.m_num);
5204 }
bool Z3_API Z3_rcf_eq(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a == b.

◆ operator>()

bool operator> ( rcf_num const & other) const
inline

Definition at line 5186 of file z3++.h.

5186 {
5187 check_context(other);
5188 return Z3_rcf_gt(m_ctx, m_num, other.m_num);
5189 }
bool Z3_API Z3_rcf_gt(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a > b.

◆ operator>=()

bool operator>= ( rcf_num const & other) const
inline

Definition at line 5196 of file z3++.h.

5196 {
5197 check_context(other);
5198 return Z3_rcf_ge(m_ctx, m_num, other.m_num);
5199 }
bool Z3_API Z3_rcf_ge(Z3_context c, Z3_rcf_num a, Z3_rcf_num b)
Return true if a >= b.

◆ power()

rcf_num power ( unsigned k) const
inline

Return the power of this number raised to k.

Definition at line 5167 of file z3++.h.

5167 {
5168 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5169 Z3_rcf_power(m_ctx, m_num, k));
5170 }
Z3_rcf_num Z3_API Z3_rcf_power(Z3_context c, Z3_rcf_num a, unsigned k)
Return the value a^k.

◆ to_decimal()

std::string to_decimal ( unsigned precision = 10) const
inline

Return decimal string representation with given precision.

Definition at line 5130 of file z3++.h.

5130 {
5131 return std::string(Z3_rcf_num_to_decimal_string(m_ctx, m_num, precision));
5132 }
Z3_string Z3_API Z3_rcf_num_to_decimal_string(Z3_context c, Z3_rcf_num a, unsigned prec)
Convert the RCF numeral into a string in decimal notation.

◆ to_string()

std::string to_string ( bool compact = false) const
inline

Return string representation of the RCF numeral.

Definition at line 5123 of file z3++.h.

5123 {
5124 return std::string(Z3_rcf_num_to_string(m_ctx, m_num, compact, false));
5125 }

Referenced by operator<<.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
rcf_num const & n )
friend

Definition at line 5228 of file z3++.h.

5228 {
5229 return out << n.to_string();
5230 }