Class Add

Inheritance Relationships

Base Type

Class Documentation

class SymEngine::Add : public SymEngine::Basic

Add class keeps an addition of symbolic expressions. Internal representation of an Add is a numeric coefficient coef_ and a dictionary dict_ of key-value pairs.

 Add(coef_, {{key1, value1}, {key2, value2}, ... })

This represents the following expression,

 coef_ + key1*value1 + key2*value2 + ...

coef_ and the values of dictionary are numeric coefficients like Integer, RealDouble, Complex keys can be any symbolic expression except numeric coefficients and Mul objects with coefficient != 1.

For example, the following are valid representations

 Add(1, {{x, 2}, {y, 5}})
 Add(0, {{x, 1}, {y, 4}, {z, 3}})

Following are invalid representations. (valid equivalent is shown next to them)

 Add(1, {{x, 1}, {2*y, 3})   -> Add(1, {{x, 1}, {y, 6}})
 Add(0, {{x, 2}})             -> Mul(2, {{x, 1}})
 Add(1, {{x, 2}, {4, 6}})    -> Add(25, {{x, 2}})

Public Functions

Add(const RCP<const Number> &coef, umap_basic_num &&dict)

The dictionary of the rest (e.g. x+y in 2+x+y)

Constructs Add from a dictionary by copying the contents of the dictionary. Assumes that the input is in canonical form

hash_t __hash__() const

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

bool __eq__(const Basic &o) const

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

int compare(const Basic &o) const

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.

void as_two_terms(const Ptr<RCP<const Basic>> &a, const Ptr<RCP<const Basic>> &b) const

Converts the Add into a sum of two Basic objects and returns them.

bool is_canonical(const RCP<const Number> &coef, const umap_basic_num &dict) const

Return

true if a given dictionary and a coefficient is in canonical form

vec_basic get_args() const

Returns the arguments of the Add. For an Add of the form,

Add(coef_, {{key1, value1}, {key2, value2}, ... })

if coef_ is non-zero it returns,

{coef_, key1*value1, key2*value2, ... }

otherwise it returns,

{key1*value1, key2*value2, ... }

Return

list of arguments

const RCP<const Number> &get_coef() const

Return

const reference to the coefficient of the Add

const umap_basic_num &get_dict() const

Return

const reference to the dictionary of the Add

Public Static Functions

RCP<const Basic> from_dict(const RCP<const Number> &coef, umap_basic_num &&d)

Creates appropriate instance (i.e Add , Symbol, Integer, Mul) depending on the size of dictionary d.

void dict_add_term(umap_basic_num &d, const RCP<const Number> &coef, const RCP<const Basic> &t)

Adds (coeff*t) to the dict d

void coef_dict_add_term(const Ptr<RCP<const Number>> &coef, umap_basic_num &d, const RCP<const Number> &c, const RCP<const Basic> &term)

Adds (c*term) to the number coeff (in case both are numbers) or dict d (as a pair c, term). In case term is Add and c=1, expands the Add into the coeff and d.

void as_coef_term(const RCP<const Basic> &self, const Ptr<RCP<const Number>> &coef, const Ptr<RCP<const Basic>> &term)

Converts a Basic self into the form of coefficient * term