Class Basic¶
Defined in File basic.h
Inheritance Relationships¶
Base Type¶
public SymEngine::EnableRCPFromThis< Basic >
(Template Class EnableRCPFromThis)
Derived Types¶
public SymEngine::Add
(Class Add)public SymEngine::Boolean
(Class Boolean)public SymEngine::Constant
(Class Constant)public SymEngine::Derivative
(Class Derivative)public SymEngine::Function
(Class Function)public SymEngine::Mul
(Class Mul)public SymEngine::Number
(Class Number)public SymEngine::Piecewise
(Class Piecewise)public SymEngine::Pow
(Class Pow)public SymEngine::Set
(Class Set)public SymEngine::Subs
(Class Subs)public SymEngine::Symbol
(Class Symbol)
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:
Subclasses must implement these.__hash__() __eq__(o)
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
-
Basic
()¶ Constructor.
-
~Basic
()¶
-
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 too
. Deprecated: Use eq(const Basic &a, const Basic &b) non-member method
-
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 likex+y+z
into canonical order. This function assumes thato
is the same type asthis
. 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¶
-