Class Mul

Inheritance Relationships

Base Type

Class Documentation

class SymEngine::Mul : public SymEngine::Basic

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

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

This represents the following expression,

 coef_ * key1^value1 * key2^value2 * ...

coef_ is an objecct of type Number, i.e. a numeric coefficient like Integer, RealDouble, Complex.

For example, the following are valid representations

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

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

When key is a numeric and value is an integers,

Mul(2, {{3, 2}, {x, 2}}) -> Mul(18, {{x, 2}}) Mul(2, {{I, 3}, {x, 2}}) -> Mul(-2*I, {{x, 2}})

When key is an integer and value is a Rational not in the range (0, 1)

Mul(2, {{3, 3/2}, {x, 2}}) -> Mul(6, {{3, 1/2}, {x, 2}}) Mul(2, {{3, -1/2}, {x, 2}}) -> Mul(2/3, {{3, 1/2}, {x, 2}})

When the value is zero

Mul(3, {{x, 0}, {y, 2}}) -> Mul(3, {{y, 2}})

When key and value are numeric and one of them is inexact

Mul(2, {{3, 0.5}, {x, 2}}) -> Mul(3.464…, {x, 2}})

When coef_ is one and the dictionary is of size 1

Mul(1, {{x, 2}}) -> Pow(x, 2)

When coef_ is zero

Mul(0, {{x, 2}}) -> Integer(0) Mul(0.0, {{x, 2}}) -> RealDouble(0.0)

When key is 1

Mul(2, {{1, x}, {x, 2}}) -> Mul(2, {{x, 2}})

When value is zero

Mul(2, {{1, x}, {x, 2}}) -> Mul(2, {{x, 2}})

Public Functions

Mul(const RCP<const Number> &coef, map_basic_basic &&dict)

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

Constructs Mul from a dictionary by copying the contents of the dictionary:

hash_t __hash__() const

Return

size of the hash

bool __eq__(const Basic &o) const

Equality comparator

Return

whether the 2 objects are equal

Parameters
  • o: - Object to be compared with

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

Rewrite as 2 terms.

Example: if this=3*x**2*y**2*z**2, thena=x**2andb=3*y**2*z**2`

void power_num(const Ptr<RCP<const Number>> &coef, map_basic_basic &d, const RCP<const Number> &exp) const

Power all terms with the exponent exp

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

Return

true if both coef and dict are in canonical form

vec_basic get_args() const

Returns the list of arguments.

const RCP<const Number> &get_coef() const
const map_basic_basic &get_dict() const

Public Static Functions

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

Create a Mul from a dict.

void dict_add_term(map_basic_basic &d, const RCP<const Basic> &exp, const RCP<const Basic> &t)

Add terms to dict.

void dict_add_term_new(const Ptr<RCP<const Number>> &coef, map_basic_basic &d, const RCP<const Basic> &exp, const RCP<const Basic> &t)
void as_base_exp(const RCP<const Basic> &self, const Ptr<RCP<const Basic>> &exp, const Ptr<RCP<const Basic>> &base)

Convert to a base and exponent form.