SymEngine::Basic Class Referenceabstract

The lowest unit of symbolic representation. More...

#include <basic.h>

+ Inheritance diagram for SymEngine::Basic:
+ Collaboration diagram for SymEngine::Basic:

Public Member Functions

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.
 
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.
 
virtual int compare (const Basic &o) const =0
 
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
 
virtual vec_basic get_args () const =0
 Returns the list of arguments.
 
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)
 
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
 

Data Fields

TypeID type_code_
 

Private Attributes

hash_t hash_
 Private variables.
 

Detailed Description

The lowest unit of symbolic representation.

Classes like Add, Mul, Pow are initialized through their constructor using their internal representation. Add, Mul have a 'coeff' and 'dict', while Pow has 'base' and 'exp'. There are restrictions on what 'coeff' and 'dict' can be (for example 'coeff' cannot be zero in Mul, and if Mul is used inside Add, then Mul's coeff must be one, etc.). All these restrictions are checked when WITH_SYMENGINE_ASSERT is enabled inside the constructors using the is_canonical() method. That way, you don't have to worry about creating Add / Mul / Pow with wrong arguments, as it will be caught by the tests. In the Release mode no checks are done, so you can construct Add / Mul / Pow very quickly. The idea is that depending on the algorithm, you sometimes know that things are already canonical, so you simply pass it directly to the constructors of the Basic classes and you avoid expensive type checking and canonicalization. At the same time, you need to make sure that tests are still running with WITH_SYMENGINE_ASSERT enabled, so that the Basic classes are never in an inconsistent state.

Summary: always try to construct the expressions Add / Mul / Pow directly using their constructors and all the knowledge that you have for the given algorithm, that way things will be very fast. If you want slower but simpler code, you can use the add(), mul(), pow() functions that peform general and possibly slow canonicalization first.

Note
Any Basic class can be used in a "dictionary", due to the methods:
 __hash__()
 __eq__(o)
Warning
Subclasses must implement __hash__() and __eq__()

Definition at line 94 of file basic.h.

Member Function Documentation

◆ __eq__()

◆ __hash__()

◆ __neq__()

bool SymEngine::Basic::__neq__ ( const Basic o) const
inline

true if this is not equal to o.

Returns
true if not equal

Definition at line 15 of file basic-inl.h.

16 {
17  return not(eq(*this, o));
18 }
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21

◆ __str__()

std::string SymEngine::Basic::__str__ ( ) const

Returns string representation of self.

Definition at line 22 of file basic.cpp.

23 {
24  return str(*this);
25 }

◆ compare()

◆ hash()

hash_t SymEngine::Basic::hash ( ) const
inline

Returns the hash of the SymEngine class: This method caches the value

Use std::hash to get the hash. Example:

     RCP<const Symbol> x = symbol("x");
  std::hash<Basic> hash_fn;
  std::cout << hash_fn(*x);
Returns
64-bit integer value for the hash

Definition at line 7 of file basic-inl.h.

8 {
9  if (hash_ == 0)
10  hash_ = __hash__();
11  return hash_;
12 }
virtual hash_t __hash__() const =0
hash_t hash_
Private variables.
Definition: basic.h:105

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