SymEngine::Pow Class Reference
+ Inheritance diagram for SymEngine::Pow:
+ Collaboration diagram for SymEngine::Pow:

Public Member Functions

void accept (Visitor &v) const override
 
void accept (EvalRealDoubleVisitorFinal &v) const override
 
 Pow (const RCP< const Basic > &base, const RCP< const Basic > &exp)
 Pow Constructor.
 
hash_t __hash__ () const override
 
bool __eq__ (const Basic &o) const override
 
int compare (const Basic &o) const override
 
bool is_canonical (const Basic &base, const Basic &exp) const
 
RCP< const Basicget_base () const
 
RCP< const Basicget_exp () const
 
vec_basic get_args () const override
 Returns the list of arguments.
 
- Public Member Functions inherited from SymEngine::Basic
TypeID get_type_code () const
 
 Basic ()
 Constructor.
 
 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.
 
hash_t hash () const
 
bool __neq__ (const Basic &o) const
 true if this is not equal to o. More...
 
int __cmp__ (const Basic &o) const
 Comparison operator.
 
std::string __str__ () const
 
std::string dumps () const
 Returns a string of the instance serialized.
 
RCP< const Basicsubs (const map_basic_basic &subs_dict) const
 Substitutes 'subs_dict' into 'self'.
 
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
 
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)
 
RCP< const Basicrcp_from_this () const
 Get RCP<const T> pointer to self (it will cast the pointer to const T)
 
RCP< const T2 > rcp_from_this_cast () const
 Get RCP<T2> pointer to self (it will cast the pointer to T2)
 
unsigned int use_count () const
 

Static Public Attributes

static const TypeID type_code_id = SYMENGINE_POW
 base**exp More...
 

Private Attributes

RCP< const Basicbase_
 
RCP< const Basicexp_
 

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.
 
- Data Fields inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

Definition at line 17 of file pow.h.

Member Function Documentation

◆ __eq__()

bool SymEngine::Pow::__eq__ ( const Basic o) const
overridevirtual

Equality comparator

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

Implements SymEngine::Basic.

Definition at line 72 of file pow.cpp.

73 {
74  if (is_a<Pow>(o) and eq(*base_, *(down_cast<const Pow &>(o).base_))
75  and eq(*exp_, *(down_cast<const Pow &>(o).exp_)))
76  return true;
77 
78  return false;
79 }
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ __hash__()

hash_t SymEngine::Pow::__hash__ ( ) const
overridevirtual
Returns
Size of the hash

Implements SymEngine::Basic.

Definition at line 64 of file pow.cpp.

65 {
66  hash_t seed = SYMENGINE_POW;
67  hash_combine<Basic>(seed, *base_);
68  hash_combine<Basic>(seed, *exp_);
69  return seed;
70 }

◆ compare()

int SymEngine::Pow::compare ( const Basic o) const
overridevirtual

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 81 of file pow.cpp.

82 {
83  SYMENGINE_ASSERT(is_a<Pow>(o))
84  const Pow &s = down_cast<const Pow &>(o);
85  int base_cmp = base_->__cmp__(*s.base_);
86  if (base_cmp == 0)
87  return exp_->__cmp__(*s.exp_);
88  else
89  return base_cmp;
90 }
Pow(const RCP< const Basic > &base, const RCP< const Basic > &exp)
Pow Constructor.
Definition: pow.cpp:10

◆ get_base()

RCP<const Basic> SymEngine::Pow::get_base ( ) const
inline
Returns
base of base**exp

Definition at line 37 of file pow.h.

38  {
39  return base_;
40  }

◆ get_exp()

RCP<const Basic> SymEngine::Pow::get_exp ( ) const
inline
Returns
exp of base**exp

Definition at line 42 of file pow.h.

43  {
44  return exp_;
45  }

◆ is_canonical()

bool SymEngine::Pow::is_canonical ( const Basic base,
const Basic exp 
) const
Returns
true if canonical

Definition at line 17 of file pow.cpp.

18 {
19  // e.g. 0**x
20  if (is_a<Integer>(base) and down_cast<const Integer &>(base).is_zero()) {
21  if (is_a_Number(exp)) {
22  return false;
23  } else {
24  return true;
25  }
26  }
27  // e.g. 1**x
28  if (is_a<Integer>(base) and down_cast<const Integer &>(base).is_one())
29  return false;
30  // e.g. x**0.0
32  return false;
33  // e.g. x**1
34  if (is_a<Integer>(exp) and down_cast<const Integer &>(exp).is_one())
35  return false;
36  // e.g. 2**3, (2/3)**4
37  if ((is_a<Integer>(base) or is_a<Rational>(base)) and is_a<Integer>(exp))
38  return false;
39  // e.g. (x*y)**2, should rather be x**2*y**2
40  if (is_a<Mul>(base) and is_a<Integer>(exp))
41  return false;
42  // e.g. (x**y)**2, should rather be x**(2*y)
43  if (is_a<Pow>(base) and is_a<Integer>(exp))
44  return false;
45  // If exp is a rational, it should be between 0 and 1, i.e. we don't
46  // allow things like 2**(-1/2) or 2**(3/2)
47  if ((is_a<Rational>(base) or is_a<Integer>(base)) and is_a<Rational>(exp)
48  and (down_cast<const Rational &>(exp).as_rational_class() < 0
49  or down_cast<const Rational &>(exp).as_rational_class() > 1))
50  return false;
51  // Purely Imaginary complex numbers with integral powers are expanded
52  // e.g (2I)**3
53  if (is_a<Complex>(base) and down_cast<const Complex &>(base).is_re_zero()
54  and is_a<Integer>(exp))
55  return false;
56  // e.g. 0.5^2.0 should be represented as 0.25
57  if (is_a_Number(base) and is_a_Number(exp)
58  and (not down_cast<const Number &>(base).is_exact()
59  or not down_cast<const Number &>(exp).is_exact()))
60  return false;
61  return true;
62 }
bool is_a_Number(const Basic &b)
Definition: number.h:130
bool is_number_and_zero(const Basic &b)
Definition: number.h:139
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
Definition: pow.cpp:271

Field Documentation

◆ type_code_id

const TypeID SymEngine::Pow::type_code_id = SYMENGINE_POW
static

base**exp

Type_code_id shared by all instances

Definition at line 23 of file pow.h.


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