6 #ifndef SYMENGINE_COMPLEX_H
7 #define SYMENGINE_COMPLEX_H
10 #include <symengine/symengine_exception.h>
18 virtual RCP<const Number> real_part()
const = 0;
19 virtual RCP<const Number> imaginary_part()
const = 0;
20 bool is_re_zero()
const;
26 return (b.get_type_code() == SYMENGINE_COMPLEX
27 || b.get_type_code() == SYMENGINE_COMPLEX_MPC
28 || b.get_type_code() == SYMENGINE_COMPLEX_DOUBLE);
39 rational_class imaginary_;
44 Complex(rational_class real, rational_class imaginary);
50 static RCP<const Number>
from_mpq(
const rational_class re,
51 const rational_class im);
54 const rational_class &imaginary)
const;
64 RCP<const Number>
real_part()
const override;
68 RCP<const Basic>
conjugate()
const override;
120 this->imaginary_ + other.imaginary_);
145 this->imaginary_ - other.imaginary_);
169 other.imaginary_ - this->imaginary_);
194 this->real_ * other.
real_ - this->imaginary_ * other.imaginary_,
195 this->real_ * other.imaginary_ + this->imaginary_ * other.
real_);
219 rational_class modulus_sq_other
220 = other.
real_ * other.
real_ + other.imaginary_ * other.imaginary_;
222 if (get_num(modulus_sq_other) == 0) {
223 rational_class modulus_sq_this
224 = this->real_ * this->real_
225 + this->imaginary_ * this->imaginary_;
226 if (get_num(modulus_sq_this) == 0) {
233 + this->imaginary_ * other.imaginary_)
235 (-this->real_ * other.imaginary_
236 + this->imaginary_ * other.
real_)
246 rational_class modulus_sq_this
247 = this->real_ * this->real_
248 + this->imaginary_ * this->imaginary_;
250 if (get_num(modulus_sq_this) == 0) {
266 rational_class modulus_sq_this
267 = this->real_ * this->real_
268 + this->imaginary_ * this->imaginary_;
270 if (get_num(modulus_sq_this) == 0) {
285 rational_class modulus_sq_this
286 = this->real_ * this->real_ + this->imaginary_ * this->imaginary_;
288 if (get_num(modulus_sq_this) == 0) {
307 RCP<const Number>
add(
const Number &other)
const override
309 if (is_a<Rational>(other)) {
310 return addcomp(down_cast<const Rational &>(other));
311 }
else if (is_a<Integer>(other)) {
312 return addcomp(down_cast<const Integer &>(other));
313 }
else if (is_a<Complex>(other)) {
314 return addcomp(down_cast<const Complex &>(other));
316 return other.
add(*
this);
320 RCP<const Number>
sub(
const Number &other)
const override
322 if (is_a<Rational>(other)) {
323 return subcomp(down_cast<const Rational &>(other));
324 }
else if (is_a<Integer>(other)) {
325 return subcomp(down_cast<const Integer &>(other));
326 }
else if (is_a<Complex>(other)) {
327 return subcomp(down_cast<const Complex &>(other));
329 return other.rsub(*
this);
335 if (is_a<Rational>(other)) {
336 return rsubcomp(down_cast<const Rational &>(other));
337 }
else if (is_a<Integer>(other)) {
338 return rsubcomp(down_cast<const Integer &>(other));
340 throw NotImplementedError(
"Not Implemented");
344 RCP<const Number>
mul(
const Number &other)
const override
346 if (is_a<Rational>(other)) {
347 return mulcomp(down_cast<const Rational &>(other));
348 }
else if (is_a<Integer>(other)) {
349 return mulcomp(down_cast<const Integer &>(other));
350 }
else if (is_a<Complex>(other)) {
351 return mulcomp(down_cast<const Complex &>(other));
353 return other.
mul(*
this);
357 RCP<const Number>
div(
const Number &other)
const override
359 if (is_a<Rational>(other)) {
360 return divcomp(down_cast<const Rational &>(other));
361 }
else if (is_a<Integer>(other)) {
362 return divcomp(down_cast<const Integer &>(other));
363 }
else if (is_a<Complex>(other)) {
364 return divcomp(down_cast<const Complex &>(other));
366 return other.rdiv(*
this);
372 if (is_a<Integer>(other)) {
373 return rdivcomp(down_cast<const Integer &>(other));
375 throw NotImplementedError(
"Not Implemented");
379 RCP<const Number>
pow(
const Number &other)
const override
381 if (is_a<Integer>(other)) {
382 return powcomp(down_cast<const Integer &>(other));
384 return other.rpow(*
this);
388 RCP<const Number> rpow(
const Number &other)
const override
390 throw NotImplementedError(
"Not Implemented");
#define IMPLEMENT_TYPEID(SYMENGINE_ID)
Inline members and functions.
The lowest unit of symbolic representation.
ComplexBase Class for deriving all complex classes.
Complex(rational_class real, rational_class imaginary)
Constructor of Complex class.
RCP< const Number > subcomp(const Complex &other) const
RCP< const Number > divcomp(const Rational &other) const
static RCP< const Number > from_mpq(const rational_class re, const rational_class im)
bool is_one() const override
RCP< const Number > imaginary_part() const override
Get the imaginary part of the complex number.
bool is_negative() const override
RCP< const Number > sub(const Number &other) const override
Converts the param other appropriately and then calls subcomp
RCP< const Number > mulcomp(const Complex &other) const
RCP< const Basic > conjugate() const override
Get the conjugate of the complex number.
RCP< const Number > divcomp(const Integer &other) const
RCP< const Number > powcomp(const Integer &other) const
RCP< const Number > mulcomp(const Rational &other) const
RCP< const Number > div(const Number &other) const override
Converts the param other appropriately and then calls divcomp
bool is_minus_one() const override
RCP< const Number > rsubcomp(const Complex &other) const
RCP< const Number > mulcomp(const Integer &other) const
RCP< const Number > subcomp(const Integer &other) const
RCP< const Number > addcomp(const Integer &other) const
RCP< const Number > rdivcomp(const Integer &other) const
RCP< const Number > pow(const Number &other) const override
Converts the param other appropriately and then calls powcomp
RCP< const Number > rsubcomp(const Integer &other) const
RCP< const Number > add(const Number &other) const override
Converts the param other appropriately and then calls addcomp
static RCP< const Number > from_two_rats(const Rational &re, const Rational &im)
bool is_canonical(const rational_class &real, const rational_class &imaginary) const
RCP< const Number > addcomp(const Complex &other) const
RCP< const Number > rdiv(const Number &other) const override
Converts the param other appropriately and then calls rdivcomp
RCP< const Number > addcomp(const Rational &other) const
int compare(const Basic &o) const override
hash_t __hash__() const override
RCP< const Number > rsub(const Number &other) const override
Converts the param other appropriately and then calls rsubcomp
bool is_zero() const override
static RCP< const Number > from_two_nums(const Number &re, const Number &im)
RCP< const Number > mul(const Number &other) const override
Converts the param other appropriately and then calls mulcomp
bool __eq__(const Basic &o) const override
RCP< const Number > divcomp(const Complex &other) const
bool is_complex() const override
RCP< const Number > rsubcomp(const Rational &other) const
RCP< const Number > subcomp(const Rational &other) const
bool is_positive() const override
RCP< const Number > real_part() const override
Get the real part of the complex number.
const integer_class & as_integer_class() const
Convert to integer_class.
bool is_zero() const override
virtual RCP< const Number > mul(const Number &other) const =0
Multiplication.
virtual RCP< const Number > add(const Number &other) const =0
Addition.
const rational_class & as_rational_class() const
Convert to rational_class.
bool is_zero() const override
Main namespace for SymEngine package.
bool is_a_Complex(const Basic &b)