SymEngine
Public Member Functions | Static Public Member Functions | List of all members
SymEngine::Add Class Reference

#include <add.h>

Inheritance diagram for SymEngine::Add:
SymEngine::Basic SymEngine::EnableRCPFromThis< Basic >

Public Member Functions

 Add (const RCP< const Number > &coef, umap_basic_num &&dict)
 The dictionary of the rest (e.g. x+y in 2+x+y) More...
 
virtual hash_t __hash__ () const
 
virtual bool __eq__ (const Basic &o) const
 
virtual int compare (const Basic &o) const
 
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
 
virtual vec_basic get_args () const
 
const RCP< const Number > & get_coef () const
 
const umap_basic_num & get_dict () const
 
- Public Member Functions inherited from SymEngine::Basic
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.
 
hash_t hash () const
 
bool __neq__ (const Basic &o) const
 true if this is not equal to o. More...
 
int __cmp__ (const Basic &o) const
 Comparison operator.
 
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
 
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
 

Static Public Member Functions

static RCP< const Basicfrom_dict (const RCP< const Number > &coef, umap_basic_num &&d)
 
static void dict_add_term (umap_basic_num &d, const RCP< const Number > &coef, const RCP< const Basic > &t)
 
static 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)
 
static 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
 

Additional Inherited Members

- Public Attributes inherited from SymEngine::Basic
TypeID type_code_
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Add()

SymEngine::Add::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

Member Function Documentation

◆ __eq__()

virtual bool SymEngine::Add::__eq__ ( const Basic o) const
virtual

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

Implements SymEngine::Basic.

◆ __hash__()

virtual hash_t SymEngine::Add::__hash__ ( ) const
virtual

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

Returns
64-bit integer value for the hash

Implements SymEngine::Basic.

◆ coef_dict_add_term()

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

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.

◆ compare()

virtual int SymEngine::Add::compare ( const Basic o) const
virtual

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.

Implements SymEngine::Basic.

◆ dict_add_term()

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

Adds (coeff*t) to the dict d

◆ from_dict()

static RCP<const Basic> SymEngine::Add::from_dict ( const RCP< const Number > &  coef,
umap_basic_num &&  d 
)
static

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

◆ get_args()

virtual vec_basic SymEngine::Add::get_args ( ) const
virtual

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, ... }
Returns
list of arguments

Implements SymEngine::Basic.

◆ get_coef()

const RCP<const Number>& SymEngine::Add::get_coef ( ) const
inline
Returns
const reference to the coefficient of the Add

◆ get_dict()

const umap_basic_num& SymEngine::Add::get_dict ( ) const
inline
Returns
const reference to the dictionary of the Add

◆ is_canonical()

bool SymEngine::Add::is_canonical ( const RCP< const Number > &  coef,
const umap_basic_num &  dict 
) const
Returns
true if a given dictionary and a coefficient is in canonical form

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