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

Public Member Functions

virtual void accept (Visitor &v) const
 
virtual void accept (EvalRealDoubleVisitorFinal &v) const
 
 Pow (const RCP< const Basic > &base, const RCP< const Basic > &exp)
 Pow Constructor.
 
virtual hash_t __hash__ () const
 
virtual bool __eq__ (const Basic &o) const
 
virtual int compare (const Basic &o) const
 
bool is_canonical (const Basic &base, const Basic &exp) const
 
RCP< const Basicget_base () const
 
RCP< const Basicget_exp () const
 
virtual vec_basic get_args () const
 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
 
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

- 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
virtual

Equality comparator

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

Implements SymEngine::Basic.

Definition at line 71 of file pow.cpp.

72 {
73  if (is_a<Pow>(o) and eq(*base_, *(down_cast<const Pow &>(o).base_))
74  and eq(*exp_, *(down_cast<const Pow &>(o).exp_)))
75  return true;
76 
77  return false;
78 }
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
virtual
Returns
Size of the hash

Implements SymEngine::Basic.

Definition at line 63 of file pow.cpp.

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

◆ compare()

int SymEngine::Pow::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 80 of file pow.cpp.

81 {
82  SYMENGINE_ASSERT(is_a<Pow>(o))
83  const Pow &s = down_cast<const Pow &>(o);
84  int base_cmp = base_->__cmp__(*s.base_);
85  if (base_cmp == 0)
86  return exp_->__cmp__(*s.exp_);
87  else
88  return base_cmp;
89 }
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 not down_cast<const Number &>(base).is_exact()
58  and is_a_Number(exp) and not down_cast<const Number &>(exp).is_exact())
59  return false;
60  return true;
61 }
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:270
tribool is_zero(const Basic &b, const Assumptions *assumptions=nullptr)
Check if a number is zero.

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: