Loading...
Searching...
No Matches
SymEngine::Integer Class Reference

Integer Class. More...

#include <integer.h>

+ Inheritance diagram for SymEngine::Integer:
+ Collaboration diagram for SymEngine::Integer:

Public Member Functions

virtual void accept (Visitor &v) const
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const
 
 Integer (const integer_class &_i)
 Constructor of Integer using integer_class More...
 
 Integer (integer_class &&_i)
 
virtual hash_t __hash__ () const
 
virtual bool __eq__ (const Basic &o) const
 
virtual int compare (const Basic &o) const
 
signed long int as_int () const
 Convert to int, raise an exception if it does not fit. More...
 
unsigned long int as_uint () const
 Convert to uint, raise an exception if it does not fit. More...
 
const integer_class & as_integer_class () const
 Convert to integer_class. More...
 
virtual bool is_zero () const
 
virtual bool is_one () const
 
virtual bool is_minus_one () const
 
virtual bool is_positive () const
 
virtual bool is_negative () const
 
virtual bool is_complex () const
 
RCP< const Integeraddint (const Integer &other) const
 Fast Integer Addition. More...
 
RCP< const Integersubint (const Integer &other) const
 Fast Integer Subtraction. More...
 
RCP< const Integermulint (const Integer &other) const
 Fast Integer Multiplication. More...
 
RCP< const Numberdivint (const Integer &other) const
 Integer Division. More...
 
RCP< const Numberpow_negint (const Integer &other) const
 Fast Negative Power Evaluation. More...
 
RCP< const Numberpowint (const Integer &other) const
 Fast Power Evaluation. More...
 
RCP< const Integerneg () const
 
virtual RCP< const Numberadd (const Number &other) const
 Slower Addition. More...
 
virtual RCP< const Numbersub (const Number &other) const
 Slower Subtraction. More...
 
virtual RCP< const Numberrsub (const Number &other) const
 
virtual RCP< const Numbermul (const Number &other) const
 Slower Multiplication. More...
 
virtual RCP< const Numberdiv (const Number &other) const
 Slower Division. More...
 
virtual RCP< const Numberrdiv (const Number &other) const
 
virtual RCP< const Numberpow (const Number &other) const
 Slower power evaluation. More...
 
virtual RCP< const Numberrpow (const Number &other) const
 
- Public Member Functions inherited from SymEngine::Number
virtual bool is_zero () const =0
 
virtual bool is_one () const =0
 
virtual bool is_minus_one () const =0
 
virtual bool is_negative () const =0
 
virtual bool is_positive () const =0
 
virtual bool is_complex () const =0
 
virtual RCP< const Basicconjugate () const
 
virtual bool is_exact () const
 return true if the number is an exact representation More...
 
bool is_exact_zero () const
 
virtual Evaluateget_eval () const
 Get Evaluate singleton to evaluate numerically. More...
 
virtual RCP< const Numberadd (const Number &other) const =0
 Addition. More...
 
virtual RCP< const Numbersub (const Number &other) const
 Subtraction. More...
 
virtual RCP< const Numberrsub (const Number &other) const
 
virtual RCP< const Numbermul (const Number &other) const =0
 Multiplication. More...
 
virtual RCP< const Numberdiv (const Number &other) const
 Division. More...
 
virtual RCP< const Numberrdiv (const Number &other) const
 
virtual RCP< const Numberpow (const Number &other) const =0
 Power. More...
 
virtual RCP< const Numberrpow (const Number &other) const =0
 
virtual vec_basic get_args () const
 Returns the list of arguments. More...
 
virtual bool is_perfect_power (bool is_expected=false) const
 
virtual bool nth_root (const Ptr< RCP< const Number > > &, unsigned long n) const
 
- Public Member Functions inherited from SymEngine::Basic
TypeID get_type_code () const
 
 Basic ()
 Constructor. More...
 
 Basic (const Basic &)=delete
 Delete the copy constructor and assignment.
 
Basicoperator= (const Basic &)=delete
 Assignment operator in continuation with above.
 
 Basic (Basic &&)=delete
 Delete the move constructor and assignment.
 
Basicoperator= (Basic &&)=delete
 Assignment operator in continuation with above.
 
virtual hash_t __hash__ () const =0
 
hash_t hash () const
 
virtual bool __eq__ (const Basic &o) const =0
 Test equality. More...
 
bool __neq__ (const Basic &o) const
 true if this is not equal to o. More...
 
int __cmp__ (const Basic &o) const
 Comparison operator. More...
 
virtual int compare (const Basic &o) const =0
 
std::string __str__ () const
 
std::string dumps () const
 Returns a string of the instance serialized. More...
 
RCP< const Basicsubs (const map_basic_basic &subs_dict) const
 Substitutes 'subs_dict' into 'self'. More...
 
RCP< const Basicxreplace (const map_basic_basic &subs_dict) const
 
virtual RCP< const Basicexpand_as_exp () const
 expands the special function in terms of exp function More...
 
virtual vec_basic get_args () const =0
 Returns the list of arguments. More...
 
virtual void accept (Visitor &v) const =0
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const =0
 
RCP< const Basicdiff (const RCP< const Symbol > &x, bool cache=true) const
 
- Public Member Functions inherited from SymEngine::EnableRCPFromThis< Basic >
RCP< Basicrcp_from_this ()
 Get RCP<T> pointer to self (it will cast the pointer to T) More...
 
RCP< const Basicrcp_from_this () const
 Get RCP<const T> pointer to self (it will cast the pointer to const T) More...
 
RCP< const T2 > rcp_from_this_cast () const
 Get RCP<T2> pointer to self (it will cast the pointer to T2) More...
 
unsigned int use_count () const
 

Static Public Attributes

static const TypeID type_code_id = SYMENGINE_INTEGER
 

Private Attributes

integer_class i
 i : object of integer_class More...
 

Additional Inherited Members

- Static Public Member Functions inherited from SymEngine::Basic
static RCP< const Basicloads (const std::string &)
 Creates an instance of a serialized string. More...
 
- Data Fields inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

Integer Class.

Definition at line 18 of file integer.h.

Constructor & Destructor Documentation

◆ Integer() [1/2]

SymEngine::Integer::Integer ( const integer_class &  _i)
inline

Constructor of Integer using integer_class

Definition at line 28 of file integer.h.

29 : i(_i){SYMENGINE_ASSIGN_TYPEID()} Integer(integer_class && _i)
Integer(const integer_class &_i)
Constructor of Integer using integer_class
Definition: integer.h:28
integer_class i
i : object of integer_class
Definition: integer.h:22

◆ Integer() [2/2]

SymEngine::Integer::Integer ( integer_class &&  _i)
inline

Definition at line 29 of file integer.h.

29 : i(_i){SYMENGINE_ASSIGN_TYPEID()} Integer(integer_class && _i)
30 : i(std::move(_i))
31 {
32 SYMENGINE_ASSIGN_TYPEID()
33 }
T move(T... args)
STL namespace.

Member Function Documentation

◆ __eq__()

bool SymEngine::Integer::__eq__ ( const Basic o) const
virtual

Equality comparator

Parameters
o- Object to be compared with
Returns
whether the 2 objects are equal

Implements SymEngine::Basic.

Definition at line 16 of file integer.cpp.

17{
18 if (is_a<Integer>(o)) {
19 const Integer &s = down_cast<const Integer &>(o);
20 return this->i == s.i;
21 }
22 return false;
23}

◆ __hash__()

hash_t SymEngine::Integer::__hash__ ( ) const
virtual
Returns
size of the hash

Implements SymEngine::Basic.

Definition at line 9 of file integer.cpp.

10{
11 // only the least significant bits that fit into "long long int" are
12 // hashed:
13 return ((hash_t)mp_get_ui(this->i)) * (hash_t)(mp_sign(this->i));
14}

◆ accept() [1/2]

virtual void SymEngine::Integer::accept ( EvalRealDoubleVisitorFinal v) const
virtual

Implements SymEngine::Basic.

◆ accept() [2/2]

virtual void SymEngine::Integer::accept ( Visitor v) const
virtual

Implements SymEngine::Basic.

◆ add()

virtual RCP< const Number > SymEngine::Integer::add ( const Number other) const
inlinevirtual

Slower Addition.

Implements SymEngine::Number.

Definition at line 127 of file integer.h.

128 {
129 if (is_a<Integer>(other)) {
130 return addint(down_cast<const Integer &>(other));
131 } else {
132 return other.add(*this);
133 }
134 };
RCP< const Integer > addint(const Integer &other) const
Fast Integer Addition.
Definition: integer.h:86

◆ addint()

RCP< const Integer > SymEngine::Integer::addint ( const Integer other) const
inline

Fast Integer Addition.

Definition at line 86 of file integer.h.

87 {
88 return make_rcp<const Integer>(this->i + other.i);
89 }

◆ as_int()

signed long int SymEngine::Integer::as_int ( ) const

Convert to int, raise an exception if it does not fit.

Definition at line 34 of file integer.cpp.

35{
36 // mp_get_si() returns "signed long int", so that's what we return from
37 // "as_int()" and we leave it to the user to do any possible further integer
38 // conversions.
39 if (not(mp_fits_slong_p(this->i))) {
40 throw SymEngineException("as_int: Integer larger than int");
41 }
42 return mp_get_si(this->i);
43}

◆ as_integer_class()

const integer_class & SymEngine::Integer::as_integer_class ( ) const
inline

Convert to integer_class.

Definition at line 48 of file integer.h.

49 {
50 return this->i;
51 }

◆ as_uint()

unsigned long int SymEngine::Integer::as_uint ( ) const

Convert to uint, raise an exception if it does not fit.

Definition at line 45 of file integer.cpp.

46{
47 // mp_get_ui() returns "unsigned long int", so that's what we return from
48 // "as_uint()" and we leave it to the user to do any possible further
49 // integer
50 // conversions.
51 if (this->i < 0u) {
52 throw SymEngineException("as_uint: negative Integer");
53 }
54 if (not(mp_fits_ulong_p(this->i))) {
55 throw SymEngineException("as_uint: Integer larger than uint");
56 }
57 return mp_get_ui(this->i);
58}

◆ compare()

int SymEngine::Integer::compare ( const Basic o) const
virtual

Returns -1, 0, 1 for this < o, this == o, this > o. This method is used when you want to sort things like x+y+z into canonical order. This function assumes that o is the same type as this. Use __cmp__ if you want general comparison.

Implements SymEngine::Basic.

Definition at line 25 of file integer.cpp.

26{
27 SYMENGINE_ASSERT(is_a<Integer>(o))
28 const Integer &s = down_cast<const Integer &>(o);
29 if (i == s.i)
30 return 0;
31 return i < s.i ? -1 : 1;
32}

◆ div()

virtual RCP< const Number > SymEngine::Integer::div ( const Number other) const
inlinevirtual

Slower Division.

Reimplemented from SymEngine::Number.

Definition at line 160 of file integer.h.

161 {
162 if (is_a<Integer>(other)) {
163 return divint(down_cast<const Integer &>(other));
164 } else {
165 return other.rdiv(*this);
166 }
167 };
RCP< const Number > divint(const Integer &other) const
Integer Division.
Definition: integer.cpp:60

◆ divint()

RCP< const Number > SymEngine::Integer::divint ( const Integer other) const

Integer Division.

Definition at line 60 of file integer.cpp.

61{
62 if (other.i == 0) {
63 if (this->i == 0) {
64 return Nan;
65 } else {
66 return ComplexInf;
67 }
68 }
69 rational_class q(this->i, other.i);
70
71 // This is potentially slow, but has to be done, since q might not
72 // be in canonical form.
73 canonicalize(q);
74
76}
static RCP< const Number > from_mpq(const rational_class &i)
Definition: rational.cpp:23

◆ is_complex()

virtual bool SymEngine::Integer::is_complex ( ) const
inlinevirtual
Returns
false

Implements SymEngine::Number.

Definition at line 79 of file integer.h.

80 {
81 return false;
82 }

◆ is_minus_one()

virtual bool SymEngine::Integer::is_minus_one ( ) const
inlinevirtual
Returns
true if -1

Implements SymEngine::Number.

Definition at line 63 of file integer.h.

64 {
65 return this->i == -1;
66 }

◆ is_negative()

virtual bool SymEngine::Integer::is_negative ( ) const
inlinevirtual
Returns
true if negative

Implements SymEngine::Number.

Definition at line 73 of file integer.h.

74 {
75 return this->i < 0u;
76 }

◆ is_one()

virtual bool SymEngine::Integer::is_one ( ) const
inlinevirtual
Returns
true if 1

Implements SymEngine::Number.

Definition at line 58 of file integer.h.

59 {
60 return this->i == 1u;
61 }

◆ is_positive()

virtual bool SymEngine::Integer::is_positive ( ) const
inlinevirtual
Returns
true if positive

Implements SymEngine::Number.

Definition at line 68 of file integer.h.

69 {
70 return this->i > 0u;
71 }

◆ is_zero()

virtual bool SymEngine::Integer::is_zero ( ) const
inlinevirtual
Returns
true if 0

Implements SymEngine::Number.

Definition at line 53 of file integer.h.

54 {
55 return this->i == 0u;
56 }

◆ mul()

virtual RCP< const Number > SymEngine::Integer::mul ( const Number other) const
inlinevirtual

Slower Multiplication.

Implements SymEngine::Number.

Definition at line 151 of file integer.h.

152 {
153 if (is_a<Integer>(other)) {
154 return mulint(down_cast<const Integer &>(other));
155 } else {
156 return other.mul(*this);
157 }
158 };
RCP< const Integer > mulint(const Integer &other) const
Fast Integer Multiplication.
Definition: integer.h:96

◆ mulint()

RCP< const Integer > SymEngine::Integer::mulint ( const Integer other) const
inline

Fast Integer Multiplication.

Definition at line 96 of file integer.h.

97 {
98 return make_rcp<const Integer>(this->i * other.i);
99 }

◆ neg()

RCP< const Integer > SymEngine::Integer::neg ( ) const
inline
Returns
negative of self.

Definition at line 119 of file integer.h.

120 {
121 return make_rcp<const Integer>(-i);
122 }

◆ pow()

virtual RCP< const Number > SymEngine::Integer::pow ( const Number other) const
inlinevirtual

Slower power evaluation.

Implements SymEngine::Number.

Definition at line 172 of file integer.h.

173 {
174 if (is_a<Integer>(other)) {
175 return powint(down_cast<const Integer &>(other));
176 } else {
177 return other.rpow(*this);
178 }
179 };
RCP< const Number > powint(const Integer &other) const
Fast Power Evaluation.
Definition: integer.h:105

◆ pow_negint()

RCP< const Number > SymEngine::Integer::pow_negint ( const Integer other) const

Fast Negative Power Evaluation.

Definition at line 100 of file integer.cpp.

101{
102 RCP<const Number> tmp = powint(*other.neg());
103 if (is_a<Integer>(*tmp)) {
104 const integer_class &j = down_cast<const Integer &>(*tmp).i;
105#if SYMENGINE_INTEGER_CLASS == SYMENGINE_BOOSTMP
106 // boost::multiprecision::cpp_rational lacks an (int, cpp_int)
107 // constructor. must use cpp_rational(cpp_int,cpp_int)
108 rational_class q(integer_class(mp_sign(j)), mp_abs(j));
109#else
110 rational_class q(mp_sign(j), mp_abs(j));
111#endif
112 return Rational::from_mpq(std::move(q));
113 } else {
114 throw SymEngineException("powint returned non-integer");
115 }
116}

◆ powint()

RCP< const Number > SymEngine::Integer::powint ( const Integer other) const
inline

Fast Power Evaluation.

Definition at line 105 of file integer.h.

106 {
107 if (not(mp_fits_ulong_p(other.i))) {
108 if (other.i > 0u)
109 throw SymEngineException(
110 "powint: 'exp' does not fit unsigned long.");
111 else
112 return pow_negint(other);
113 }
114 integer_class tmp;
115 mp_pow_ui(tmp, i, mp_get_ui(other.i));
116 return make_rcp<const Integer>(std::move(tmp));
117 }
RCP< const Number > pow_negint(const Integer &other) const
Fast Negative Power Evaluation.
Definition: integer.cpp:100

◆ rdiv()

RCP< const Number > SymEngine::Integer::rdiv ( const Number other) const
virtual

Reimplemented from SymEngine::Number.

Definition at line 78 of file integer.cpp.

79{
80 if (is_a<Integer>(other)) {
81 if (this->i == 0) {
82 if (other.is_zero()) {
83 return Nan;
84 } else {
85 return ComplexInf;
86 }
87 }
88 rational_class q((down_cast<const Integer &>(other)).i, this->i);
89
90 // This is potentially slow, but has to be done, since q might not
91 // be in canonical form.
92 canonicalize(q);
93
95 } else {
96 throw NotImplementedError("Not Implemented");
97 }
98}

◆ rpow()

virtual RCP< const Number > SymEngine::Integer::rpow ( const Number other) const
inlinevirtual

Implements SymEngine::Number.

Definition at line 181 of file integer.h.

182 {
183 throw NotImplementedError("Not Implemented");
184 };

◆ rsub()

virtual RCP< const Number > SymEngine::Integer::rsub ( const Number other) const
inlinevirtual

Reimplemented from SymEngine::Number.

Definition at line 145 of file integer.h.

146 {
147 throw NotImplementedError("Not Implemented");
148 };

◆ sub()

virtual RCP< const Number > SymEngine::Integer::sub ( const Number other) const
inlinevirtual

Slower Subtraction.

Reimplemented from SymEngine::Number.

Definition at line 136 of file integer.h.

137 {
138 if (is_a<Integer>(other)) {
139 return subint(down_cast<const Integer &>(other));
140 } else {
141 return other.rsub(*this);
142 }
143 };
RCP< const Integer > subint(const Integer &other) const
Fast Integer Subtraction.
Definition: integer.h:91

◆ subint()

RCP< const Integer > SymEngine::Integer::subint ( const Integer other) const
inline

Fast Integer Subtraction.

Definition at line 91 of file integer.h.

92 {
93 return make_rcp<const Integer>(this->i - other.i);
94 }

Field Documentation

◆ i

integer_class SymEngine::Integer::i
private

i : object of integer_class

Definition at line 22 of file integer.h.

◆ type_code_id

const TypeID SymEngine::Integer::type_code_id = SYMENGINE_INTEGER
static

Type_code_id shared by all instances

Definition at line 25 of file integer.h.


The documentation for this class was generated from the following files: