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 5117 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 5130 of file z3++.h.

5130 : m_ctx(c) {
5131 m_num = Z3_rcf_mk_small_int(c, val);
5132 }
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 5134 of file z3++.h.

5134 : m_ctx(c) {
5135 m_num = Z3_rcf_mk_rational(c, val);
5136 }
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 5138 of file z3++.h.

5138 : m_ctx(other.m_ctx) {
5139 // Create a copy by converting to string and back
5140 std::string str = Z3_rcf_num_to_string(m_ctx, other.m_num, false, false);
5141 m_num = Z3_rcf_mk_rational(m_ctx, str.c_str());
5142 }
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 5154 of file z3++.h.

5154 {
5155 Z3_rcf_del(m_ctx, m_num);
5156 }
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 5159 of file z3++.h.

5159{ return m_ctx; }

◆ inv()

rcf_num inv ( ) const
inline

Return the multiplicative inverse (1/this).

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

5216 {
5217 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5218 Z3_rcf_inv(m_ctx, m_num));
5219 }
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 5257 of file z3++.h.

5257 {
5258 return Z3_rcf_is_algebraic(m_ctx, m_num);
5259 }
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 5261 of file z3++.h.

5261 {
5262 return Z3_rcf_is_infinitesimal(m_ctx, m_num);
5263 }
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 5253 of file z3++.h.

5253 {
5254 return Z3_rcf_is_rational(m_ctx, m_num);
5255 }
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 5265 of file z3++.h.

5265 {
5266 return Z3_rcf_is_transcendental(m_ctx, m_num);
5267 }
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 5158 of file z3++.h.

5158{ return m_num; }

◆ operator!=()

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

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

5247 {
5248 check_context(other);
5249 return Z3_rcf_neq(m_ctx, m_num, other.m_num);
5250 }
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:571

◆ operator*()

rcf_num operator* ( rcf_num const & other) const
inline

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

5188 {
5189 check_context(other);
5190 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5191 Z3_rcf_mul(m_ctx, m_num, other.m_num));
5192 }
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 5176 of file z3++.h.

5176 {
5177 check_context(other);
5178 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5179 Z3_rcf_add(m_ctx, m_num, other.m_num));
5180 }
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 5200 of file z3++.h.

5200 {
5201 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5202 Z3_rcf_neg(m_ctx, m_num));
5203 }
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 5182 of file z3++.h.

5182 {
5183 check_context(other);
5184 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5185 Z3_rcf_sub(m_ctx, m_num, other.m_num));
5186 }
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 5194 of file z3++.h.

5194 {
5195 check_context(other);
5196 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5197 Z3_rcf_div(m_ctx, m_num, other.m_num));
5198 }
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 5222 of file z3++.h.

5222 {
5223 check_context(other);
5224 return Z3_rcf_lt(m_ctx, m_num, other.m_num);
5225 }
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 5232 of file z3++.h.

5232 {
5233 check_context(other);
5234 return Z3_rcf_le(m_ctx, m_num, other.m_num);
5235 }
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 5144 of file z3++.h.

5144 {
5145 if (this != &other) {
5146 Z3_rcf_del(m_ctx, m_num);
5147 m_ctx = other.m_ctx;
5148 std::string str = Z3_rcf_num_to_string(m_ctx, other.m_num, false, false);
5149 m_num = Z3_rcf_mk_rational(m_ctx, str.c_str());
5150 }
5151 return *this;
5152 }

◆ operator==()

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

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

5242 {
5243 check_context(other);
5244 return Z3_rcf_eq(m_ctx, m_num, other.m_num);
5245 }
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 5227 of file z3++.h.

5227 {
5228 check_context(other);
5229 return Z3_rcf_gt(m_ctx, m_num, other.m_num);
5230 }
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 5237 of file z3++.h.

5237 {
5238 check_context(other);
5239 return Z3_rcf_ge(m_ctx, m_num, other.m_num);
5240 }
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 5208 of file z3++.h.

5208 {
5209 return rcf_num(*const_cast<context*>(reinterpret_cast<context const*>(&m_ctx)),
5210 Z3_rcf_power(m_ctx, m_num, k));
5211 }
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 5171 of file z3++.h.

5171 {
5172 return std::string(Z3_rcf_num_to_decimal_string(m_ctx, m_num, precision));
5173 }
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 5164 of file z3++.h.

5164 {
5165 return std::string(Z3_rcf_num_to_string(m_ctx, m_num, compact, false));
5166 }

Referenced by operator<<.

◆ operator<<

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

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

5269 {
5270 return out << n.to_string();
5271 }