Class Basic

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class SymEngine::Basic : public SymEngine::EnableRCPFromThis<Basic>

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.

Any Basic class can be used in a “dictionary”, due to the methods:

__hash__()
__eq__(o)
Subclasses must implement these.

Subclassed by SymEngine::Add, SymEngine::Boolean, SymEngine::Constant, SymEngine::Derivative, SymEngine::Function, SymEngine::Mul, SymEngine::Number, SymEngine::Piecewise, SymEngine::Pow, SymEngine::Set, SymEngine::Subs, SymEngine::Symbol

Public Functions

TypeID get_type_code() const
Basic()

Constructor.

~Basic()
Basic(const Basic&) = delete

Delete the copy constructor and assignment.

Basic &operator=(const Basic&) = delete

Assignment operator in continuation with above.

Basic(Basic&&) = delete

Delete the move constructor and assignment.

Basic &operator=(Basic&&) = delete

Assignment operator in continuation with above.

hash_t __hash__() const = 0

Calculates the hash of the given SymEngine class. Use Basic.hash() which gives a cached version of the hash.

Return

64-bit integer value for the hash

hash_t hash() const

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);

Return

64-bit integer value for the hash

bool __eq__(const Basic &o) const = 0

true if this is equal to o. Deprecated: Use eq(const Basic &a, const Basic &b) non-member method

bool __neq__(const Basic &o) const

true if this is not equal to o.

Return

true if not equal

int __cmp__(const Basic &o) const

Comparison operator.

int compare(const Basic &o) const = 0

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.

std::string __str__() const

Returns string representation of self.

RCP<const Basic> subs(const map_basic_basic &subs_dict) const

Substitutes ‘subs_dict’ into ‘self’.

RCP<const Basic> xreplace(const map_basic_basic &subs_dict) const
RCP<const Basic> expand_as_exp() const

expands the special function in terms of exp function

vec_basic get_args() const = 0

Returns the list of arguments.

RCP<const Basic> diff(const RCP<const Symbol> &x, bool cache = true) const

Public Members

TypeID type_code_