2 #include <symengine/complex_double.h>
6 #include <symengine/symengine_exception.h>
7 #include <symengine/complex_mpc.h>
16 SYMENGINE_ASSIGN_TYPEID()
17 _direction = direction;
23 SYMENGINE_ASSIGN_TYPEID()
24 _direction = inf.get_direction();
28 RCP<const Infty> Infty::from_direction(
const RCP<const Number> &direction)
30 return make_rcp<Infty>(direction);
35 SYMENGINE_ASSERT(val >= -1 && val <= 1)
36 return make_rcp<Infty>(
integer(val));
42 if (is_a<Complex>(*num) || is_a<ComplexDouble>(*num))
43 throw NotImplementedError(
"Not implemented for all directions");
45 if (num->is_one() || num->is_zero() || num->is_minus_one())
53 hash_t seed = SYMENGINE_INFTY;
54 hash_combine<Basic>(seed, *_direction);
61 const Infty &s = down_cast<const Infty &>(o);
62 return eq(*_direction, *(s.get_direction()));
70 SYMENGINE_ASSERT(is_a<Infty>(o))
71 const Infty &s = down_cast<const Infty &>(o);
72 return _direction->compare(*(s.get_direction()));
75 bool Infty::is_unsigned_infinity()
const
77 return _direction->is_zero();
80 bool Infty::is_positive_infinity()
const
82 return _direction->is_positive();
85 bool Infty::is_negative_infinity()
const
87 return _direction->is_negative();
92 if (is_positive_infinity() or is_negative_infinity()) {
93 return infty(_direction);
95 return make_rcp<const Conjugate>(ComplexInf);
100 if (not is_a<Infty>(other))
101 return rcp_from_this_cast<Number>();
103 const Infty &s = down_cast<const Infty &>(other);
105 if (not
eq(*s.get_direction(), *_direction))
107 else if (is_unsigned_infinity())
110 return rcp_from_this_cast<Number>();
115 if (is_a<Complex>(other))
116 throw NotImplementedError(
117 "Multiplication with Complex not implemented");
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)));
124 return rcp_from_this_cast<Number>();
126 return make_rcp<const Infty>(this->_direction->mul(*minus_one));
134 if (is_a<Infty>(other)) {
138 return rcp_from_this_cast<Number>();
142 return infty(this->_direction->mul(*minus_one));
148 if (is_a<Infty>(other)) {
149 if (is_positive_infinity()) {
153 return rcp_from_this_cast<Number>();
157 }
else if (is_negative_infinity()) {
168 }
else if (is_a<Complex>(other)) {
169 throw NotImplementedError(
170 "Raising to the Complex powers not yet implemented");
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 "
190 RCP<const Number> Infty::rpow(
const Number &other)
const
193 throw NotImplementedError(
194 "Raising Complex powers to Infty not yet implemented");
197 throw NotImplementedError(
"Raising Negative numbers to infinite "
198 "powers not yet implemented");
200 throw SymEngineException(
"Indeterminate Expression: `0 ** +- "
201 "unsigned Infty` encountered");
203 const Number &s = down_cast<const Number &>(other);
206 }
else if (is_positive_infinity()) {
207 if (s.sub(*one)->is_negative()) {
210 return rcp_from_this_cast<Number>();
212 }
else if (is_negative_infinity()) {
213 if (s.sub(*one)->is_negative()) {
219 throw SymEngineException(
"Indeterminate Expression: `Positive "
220 "Real Number ** unsigned Infty` "
227 inline RCP<const Infty> infty(
const RCP<const Number> &direction)
229 return make_rcp<Infty>(direction);
234 RCP<const Basic> sin(
const Basic &x)
const override
236 SYMENGINE_ASSERT(is_a<Infty>(x))
237 throw DomainError(
"sin is not defined for infinite values");
239 RCP<const Basic> cos(
const Basic &x)
const override
241 SYMENGINE_ASSERT(is_a<Infty>(x))
242 throw DomainError(
"cos is not defined for infinite values");
244 RCP<const Basic> tan(
const Basic &x)
const override
246 SYMENGINE_ASSERT(is_a<Infty>(x))
247 throw DomainError(
"tan is not defined for infinite values");
249 RCP<const Basic> cot(
const Basic &x)
const override
251 SYMENGINE_ASSERT(is_a<Infty>(x))
252 throw DomainError(
"cot is not defined for infinite values");
254 RCP<const Basic> sec(
const Basic &x)
const override
256 SYMENGINE_ASSERT(is_a<Infty>(x))
257 throw DomainError(
"sec is not defined for infinite values");
259 RCP<const Basic> csc(
const Basic &x)
const override
261 SYMENGINE_ASSERT(is_a<Infty>(x))
262 throw DomainError(
"csc is not defined for infinite values");
264 RCP<const Basic> asin(
const Basic &x)
const override
266 SYMENGINE_ASSERT(is_a<Infty>(x))
267 throw DomainError(
"asin is not defined for infinite values");
269 RCP<const Basic> acos(
const Basic &x)
const override
271 SYMENGINE_ASSERT(is_a<Infty>(x))
272 throw DomainError(
"acos is not defined for infinite values");
274 RCP<const Basic> acsc(
const Basic &x)
const override
276 SYMENGINE_ASSERT(is_a<Infty>(x))
277 throw DomainError(
"acsc is not defined for infinite values");
279 RCP<const Basic> asec(
const Basic &x)
const override
281 SYMENGINE_ASSERT(is_a<Infty>(x))
282 throw DomainError(
"asec is not defined for infinite values");
284 RCP<const Basic> atan(
const Basic &x)
const override
286 SYMENGINE_ASSERT(is_a<Infty>(x))
287 const Infty &s = down_cast<const Infty &>(x);
293 throw DomainError(
"atan is not defined for Complex Infinity");
296 RCP<const Basic> acot(
const Basic &x)
const override
298 SYMENGINE_ASSERT(is_a<Infty>(x))
299 const Infty &s = down_cast<const Infty &>(x);
303 throw DomainError(
"acot is not defined for Complex Infinity");
306 RCP<const Basic> sinh(
const Basic &x)
const override
308 SYMENGINE_ASSERT(is_a<Infty>(x))
309 const Infty &s = down_cast<const Infty &>(x);
311 return infty(s.get_direction());
313 throw DomainError(
"sinh is not defined for Complex Infinity");
316 RCP<const Basic> csch(
const Basic &x)
const override
318 SYMENGINE_ASSERT(is_a<Infty>(x))
319 const Infty &s = down_cast<const Infty &>(x);
323 throw DomainError(
"csch is not defined for Complex Infinity");
326 RCP<const Basic> cosh(
const Basic &x)
const override
328 SYMENGINE_ASSERT(is_a<Infty>(x))
329 const Infty &s = down_cast<const Infty &>(x);
333 throw DomainError(
"cosh is not defined for Complex Infinity");
336 RCP<const Basic> sech(
const Basic &x)
const override
338 SYMENGINE_ASSERT(is_a<Infty>(x))
339 const Infty &s = down_cast<const Infty &>(x);
343 throw DomainError(
"sech is not defined for Complex Infinity");
346 RCP<const Basic> tanh(
const Basic &x)
const override
348 SYMENGINE_ASSERT(is_a<Infty>(x))
349 const Infty &s = down_cast<const Infty &>(x);
355 throw DomainError(
"tanh is not defined for Complex Infinity");
358 RCP<const Basic> coth(
const Basic &x)
const override
360 SYMENGINE_ASSERT(is_a<Infty>(x))
361 const Infty &s = down_cast<const Infty &>(x);
367 throw DomainError(
"coth is not defined for Complex Infinity");
370 RCP<const Basic> asinh(
const Basic &x)
const override
372 SYMENGINE_ASSERT(is_a<Infty>(x))
373 const Infty &s = down_cast<const Infty &>(x);
375 return infty(s.get_direction());
377 throw DomainError(
"asinh is not defined for Complex Infinity");
380 RCP<const Basic> acosh(
const Basic &x)
const override
382 SYMENGINE_ASSERT(is_a<Infty>(x))
383 const Infty &s = down_cast<const Infty &>(x);
387 throw DomainError(
"acosh is not defined for Complex Infinity");
390 RCP<const Basic> acsch(
const Basic &x)
const override
392 SYMENGINE_ASSERT(is_a<Infty>(x))
393 const Infty &s = down_cast<const Infty &>(x);
397 throw DomainError(
"acsch is not defined for Complex Infinity");
400 RCP<const Basic> asech(
const Basic &x)
const override
402 SYMENGINE_ASSERT(is_a<Infty>(x))
403 const Infty &s = down_cast<const Infty &>(x);
407 throw DomainError(
"asech is not defined for Complex Infinity");
410 RCP<const Basic> atanh(
const Basic &x)
const override
412 SYMENGINE_ASSERT(is_a<Infty>(x))
413 const Infty &s = down_cast<const Infty &>(x);
419 throw DomainError(
"atanh is not defined for Complex Infinity");
422 RCP<const Basic> acoth(
const Basic &x)
const override
424 SYMENGINE_ASSERT(is_a<Infty>(x))
425 const Infty &s = down_cast<const Infty &>(x);
429 throw DomainError(
"acoth is not defined for Complex Infinity");
432 RCP<const Basic> abs(
const Basic &x)
const override
434 SYMENGINE_ASSERT(is_a<Infty>(x))
437 RCP<const Basic> log(
const Basic &x)
const override
439 SYMENGINE_ASSERT(is_a<Infty>(x))
440 const Infty &s = down_cast<const Infty &>(x);
447 RCP<const Basic> gamma(
const Basic &x)
const override
449 SYMENGINE_ASSERT(is_a<Infty>(x))
450 const Infty &s = down_cast<const Infty &>(x);
457 RCP<const Basic> exp(
const Basic &x)
const override
459 SYMENGINE_ASSERT(is_a<Infty>(x))
460 const Infty &s = down_cast<const Infty &>(x);
466 throw DomainError(
"exp is not defined for Complex Infinity");
469 RCP<const Basic> floor(
const Basic &x)
const override
471 SYMENGINE_ASSERT(is_a<Infty>(x))
472 const Infty &s = down_cast<const Infty &>(x);
478 throw DomainError(
"floor is not defined for Complex Infinity");
481 RCP<const Basic> ceiling(
const Basic &x)
const override
483 SYMENGINE_ASSERT(is_a<Infty>(x))
484 const Infty &s = down_cast<const Infty &>(x);
490 throw DomainError(
"ceiling is not defined for Complex Infinity");
493 RCP<const Basic> truncate(
const Basic &x)
const override
495 SYMENGINE_ASSERT(is_a<Infty>(x))
496 const Infty &s = down_cast<const Infty &>(x);
502 throw DomainError(
"truncate is not defined for Complex Infinity");
505 RCP<const Basic> erf(
const Basic &x)
const override
507 SYMENGINE_ASSERT(is_a<Infty>(x))
508 const Infty &s = down_cast<const Infty &>(x);
514 throw DomainError(
"erf is not defined for Complex Infinity");
517 RCP<const Basic> erfc(
const Basic &x)
const override
519 SYMENGINE_ASSERT(is_a<Infty>(x))
520 const Infty &s = down_cast<const Infty &>(x);
526 throw DomainError(
"erfc is not defined for Complex Infinity");
534 return evaluate_infty;
The lowest unit of symbolic representation.
A class that will evaluate functions numerically.
RCP< const Number > pow(const Number &other) const override
Power.
bool __eq__(const Basic &o) const override
RCP< const Number > div(const Number &other) const override
Division.
bool is_negative() const override
hash_t __hash__() const override
bool is_canonical(const RCP< const Number > &num) const
Canonical when the direction is -1, 0 or 1.
Evaluate & get_eval() const override
Get Evaluate singleton to evaluate numerically.
bool is_positive() const override
static RCP< const Infty > from_int(const int val)
Constructs Infty using sign of val
RCP< const Number > mul(const Number &other) const override
Multiplication.
RCP< const Basic > conjugate() const override
int compare(const Basic &o) const override
Infty(const RCP< const Number > &direction)
Constructs Infty using the sign of _direction
RCP< const Number > add(const Number &other) const override
Addition.
virtual bool is_negative() const =0
virtual bool is_positive() const =0
virtual bool is_zero() const =0
Main namespace for SymEngine package.
RCP< const Basic > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
std::enable_if< std::is_integral< T >::value, RCP< const Integer > >::type integer(T i)
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
bool is_a_Complex(const Basic &b)