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

#include <infinity.h>

+ Inheritance diagram for SymEngine::Infty:
+ Collaboration diagram for SymEngine::Infty:

Public Member Functions

virtual void accept (Visitor &v) const
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const
 
 Infty (const RCP< const Number > &direction)
 Constructs Infty using the sign of _direction More...
 
 Infty (const Infty &inf)
 Copy Constructor. More...
 
bool is_canonical (const RCP< const Number > &num) const
 Canonical when the direction is -1, 0 or 1. More...
 
hash_t __hash__ () const
 
bool __eq__ (const Basic &o) const
 
int compare (const Basic &o) const
 
virtual vec_basic get_args () const
 Returns the list of arguments. More...
 
bool is_zero () const
 
bool is_one () const
 
bool is_minus_one () const
 
virtual bool is_exact () const
 
virtual Evaluateget_eval () const
 Get Evaluate singleton to evaluate numerically. More...
 
RCP< const Numberget_direction () const
 
bool is_unsigned_infinity () const
 
bool is_positive_infinity () const
 
bool is_negative_infinity () const
 
bool is_positive () const
 
bool is_negative () const
 
bool is_complex () const
 
virtual RCP< const Basicconjugate () const
 
RCP< const Numberadd (const Number &other) const
 Addition. More...
 
RCP< const Numbermul (const Number &other) const
 Multiplication. More...
 
RCP< const Numberdiv (const Number &other) const
 Division. More...
 
RCP< const Numberpow (const Number &other) const
 Power. More...
 
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 Member Functions

static RCP< const Inftyfrom_direction (const RCP< const Number > &direction)
 
static RCP< const Inftyfrom_int (const int val)
 Constructs Infty using sign of val More...
 
- Static Public Member Functions inherited from SymEngine::Basic
static RCP< const Basicloads (const std::string &)
 Creates an instance of a serialized string. More...
 

Static Public Attributes

static const TypeID type_code_id = SYMENGINE_INFTY
 

Private Attributes

RCP< const Number_direction
 

Additional Inherited Members

- Data Fields inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

This class holds "infinity" It includes a direction (like -infinity).

Definition at line 20 of file infinity.h.

Constructor & Destructor Documentation

◆ Infty() [1/2]

SymEngine::Infty::Infty ( const RCP< const Number > &  direction)

Constructs Infty using the sign of _direction

Definition at line 14 of file infinity.cpp.

15{
16 SYMENGINE_ASSIGN_TYPEID()
17 _direction = direction;
18 SYMENGINE_ASSERT(is_canonical(_direction));
19}
bool is_canonical(const RCP< const Number > &num) const
Canonical when the direction is -1, 0 or 1.
Definition: infinity.cpp:40

◆ Infty() [2/2]

SymEngine::Infty::Infty ( const Infty inf)

Copy Constructor.

Definition at line 21 of file infinity.cpp.

22{
23 SYMENGINE_ASSIGN_TYPEID()
24 _direction = inf.get_direction();
25 SYMENGINE_ASSERT(is_canonical(_direction))
26}

Member Function Documentation

◆ __eq__()

bool SymEngine::Infty::__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 58 of file infinity.cpp.

59{
60 if (is_a<Infty>(o)) {
61 const Infty &s = down_cast<const Infty &>(o);
62 return eq(*_direction, *(s.get_direction()));
63 }
64
65 return false;
66}
Infty(const RCP< const Number > &direction)
Constructs Infty using the sign of _direction
Definition: infinity.cpp:14
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ __hash__()

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

Implements SymEngine::Basic.

Definition at line 51 of file infinity.cpp.

52{
53 hash_t seed = SYMENGINE_INFTY;
54 hash_combine<Basic>(seed, *_direction);
55 return seed;
56}

◆ accept() [1/2]

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

Implements SymEngine::Basic.

◆ accept() [2/2]

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

Implements SymEngine::Basic.

◆ add()

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

Addition.

Implements SymEngine::Number.

Definition at line 98 of file infinity.cpp.

99{
100 if (not is_a<Infty>(other))
101 return rcp_from_this_cast<Number>();
102
103 const Infty &s = down_cast<const Infty &>(other);
104
105 if (not eq(*s.get_direction(), *_direction))
106 return Nan;
107 else if (is_unsigned_infinity())
108 return Nan;
109 else
110 return rcp_from_this_cast<Number>();
111}

◆ compare()

int SymEngine::Infty::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 68 of file infinity.cpp.

69{
70 SYMENGINE_ASSERT(is_a<Infty>(o))
71 const Infty &s = down_cast<const Infty &>(o);
72 return _direction->compare(*(s.get_direction()));
73}

◆ conjugate()

RCP< const Basic > SymEngine::Infty::conjugate ( ) const
virtual
Returns
the conjugate if the class is complex

Reimplemented from SymEngine::Number.

Definition at line 90 of file infinity.cpp.

91{
92 if (is_positive_infinity() or is_negative_infinity()) {
93 return infty(_direction);
94 }
95 return make_rcp<const Conjugate>(ComplexInf);
96}

◆ div()

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

Division.

Reimplemented from SymEngine::Number.

Definition at line 132 of file infinity.cpp.

133{
134 if (is_a<Infty>(other)) {
135 return Nan;
136 } else {
137 if (other.is_positive())
138 return rcp_from_this_cast<Number>();
139 else if (other.is_zero())
140 return infty(0);
141 else
142 return infty(this->_direction->mul(*minus_one));
143 }
144}

◆ from_direction()

RCP< const Infty > SymEngine::Infty::from_direction ( const RCP< const Number > &  direction)
static

Definition at line 28 of file infinity.cpp.

29{
30 return make_rcp<Infty>(direction);
31}

◆ from_int()

RCP< const Infty > SymEngine::Infty::from_int ( const int  val)
static

Constructs Infty using sign of val

Definition at line 33 of file infinity.cpp.

34{
35 SYMENGINE_ASSERT(val >= -1 && val <= 1)
36 return make_rcp<Infty>(integer(val));
37}
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)
Definition: integer.h:200

◆ get_args()

virtual vec_basic SymEngine::Infty::get_args ( ) const
inlinevirtual

Returns the list of arguments.

Reimplemented from SymEngine::Number.

Definition at line 47 of file infinity.h.

48 {
49 return {_direction};
50 }

◆ get_direction()

RCP< const Number > SymEngine::Infty::get_direction ( ) const
inline

Definition at line 76 of file infinity.h.

77 {
78 return _direction;
79 }

◆ get_eval()

Evaluate & SymEngine::Infty::get_eval ( ) const
virtual

Get Evaluate singleton to evaluate numerically.

Reimplemented from SymEngine::Number.

Definition at line 531 of file infinity.cpp.

532{
533 static EvaluateInfty evaluate_infty;
534 return evaluate_infty;
535}

◆ is_canonical()

bool SymEngine::Infty::is_canonical ( const RCP< const Number > &  num) const

Canonical when the direction is -1, 0 or 1.

Returns
true if canonical

Definition at line 40 of file infinity.cpp.

41{
42 if (is_a<Complex>(*num) || is_a<ComplexDouble>(*num))
43 throw NotImplementedError("Not implemented for all directions");
44
45 if (num->is_one() || num->is_zero() || num->is_minus_one())
46 return true;
47
48 return false;
49}

◆ is_complex()

bool SymEngine::Infty::is_complex ( ) const
inlinevirtual
Returns
true if a complex number

Implements SymEngine::Number.

Definition at line 95 of file infinity.h.

96 {
97 return is_unsigned_infinity();
98 }

◆ is_exact()

virtual bool SymEngine::Infty::is_exact ( ) const
inlinevirtual
Returns
true if this number is an exact number

Reimplemented from SymEngine::Number.

Definition at line 69 of file infinity.h.

70 {
71 return false;
72 }

◆ is_minus_one()

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

Implements SymEngine::Number.

Definition at line 63 of file infinity.h.

64 {
65 return false;
66 }

◆ is_negative()

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

Implements SymEngine::Number.

Definition at line 90 of file infinity.h.

91 {
92 return is_negative_infinity();
93 }

◆ is_negative_infinity()

bool SymEngine::Infty::is_negative_infinity ( ) const

Definition at line 85 of file infinity.cpp.

86{
87 return _direction->is_negative();
88}

◆ is_one()

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

Implements SymEngine::Number.

Definition at line 58 of file infinity.h.

59 {
60 return false;
61 }

◆ is_positive()

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

Implements SymEngine::Number.

Definition at line 85 of file infinity.h.

86 {
87 return is_positive_infinity();
88 }

◆ is_positive_infinity()

bool SymEngine::Infty::is_positive_infinity ( ) const

Definition at line 80 of file infinity.cpp.

81{
82 return _direction->is_positive();
83}

◆ is_unsigned_infinity()

bool SymEngine::Infty::is_unsigned_infinity ( ) const

Definition at line 75 of file infinity.cpp.

76{
77 return _direction->is_zero();
78}

◆ is_zero()

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

Implements SymEngine::Number.

Definition at line 53 of file infinity.h.

54 {
55 return false;
56 }

◆ mul()

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

Multiplication.

Implements SymEngine::Number.

Definition at line 113 of file infinity.cpp.

114{
115 if (is_a<Complex>(other))
116 throw NotImplementedError(
117 "Multiplication with Complex not implemented");
118
119 if (is_a<Infty>(other)) {
120 const Infty &s = down_cast<const Infty &>(other);
121 return make_rcp<const Infty>(this->_direction->mul(*(s._direction)));
122 } else {
123 if (other.is_positive())
124 return rcp_from_this_cast<Number>();
125 else if (other.is_negative())
126 return make_rcp<const Infty>(this->_direction->mul(*minus_one));
127 else
128 return Nan;
129 }
130}

◆ pow()

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

Power.

Implements SymEngine::Number.

Definition at line 146 of file infinity.cpp.

147{
148 if (is_a<Infty>(other)) {
149 if (is_positive_infinity()) {
150 if (other.is_negative()) {
151 return zero;
152 } else if (other.is_positive()) {
153 return rcp_from_this_cast<Number>();
154 } else {
155 return Nan;
156 }
157 } else if (is_negative_infinity()) {
158 return Nan;
159 } else {
160 if (other.is_positive()) {
161 return infty(0);
162 } else if (other.is_negative()) {
163 return zero;
164 } else {
165 return Nan;
166 }
167 }
168 } else if (is_a<Complex>(other)) {
169 throw NotImplementedError(
170 "Raising to the Complex powers not yet implemented");
171 } else {
172 if (other.is_negative()) {
173 return zero;
174 } else if (other.is_zero()) {
175 return one;
176 } else {
177 if (is_positive_infinity()) {
178 return rcp_from_this_cast<Number>();
179 } else if (is_negative_infinity()) {
180 throw NotImplementedError("Raising Negative Infty to the "
181 "Positive Real powers not yet "
182 "implemented");
183 } else {
184 return infty(0);
185 }
186 }
187 }
188}

◆ rpow()

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

Implements SymEngine::Number.

Definition at line 190 of file infinity.cpp.

191{
192 if (is_a_Complex(other)) {
193 throw NotImplementedError(
194 "Raising Complex powers to Infty not yet implemented");
195 } else {
196 if (other.is_negative()) {
197 throw NotImplementedError("Raising Negative numbers to infinite "
198 "powers not yet implemented");
199 } else if (other.is_zero()) {
200 throw SymEngineException("Indeterminate Expression: `0 ** +- "
201 "unsigned Infty` encountered");
202 } else {
203 const Number &s = down_cast<const Number &>(other);
204 if (s.is_one()) {
205 return Nan;
206 } else if (is_positive_infinity()) {
207 if (s.sub(*one)->is_negative()) {
208 return zero;
209 } else {
210 return rcp_from_this_cast<Number>();
211 }
212 } else if (is_negative_infinity()) {
213 if (s.sub(*one)->is_negative()) {
214 return infty(0);
215 } else {
216 return zero;
217 }
218 } else {
219 throw SymEngineException("Indeterminate Expression: `Positive "
220 "Real Number ** unsigned Infty` "
221 "encountered");
222 }
223 }
224 }
225}
bool is_a_Complex(const Basic &b)
Definition: complex.h:24

Field Documentation

◆ _direction

RCP<const Number> SymEngine::Infty::_direction
private

Definition at line 22 of file infinity.h.

◆ type_code_id

const TypeID SymEngine::Infty::type_code_id = SYMENGINE_INFTY
static

Type_code_id shared by all instances

Definition at line 25 of file infinity.h.


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