Loading...
Searching...
No Matches
SymEngine::UExprDict Class Reference
+ Inheritance diagram for SymEngine::UExprDict:
+ Collaboration diagram for SymEngine::UExprDict:

Public Member Functions

 UExprDict (UExprDict &&other) SYMENGINE_NOEXCEPT
 
 UExprDict (const int &i)
 
 UExprDict (const map_int_Expr &p)
 
 UExprDict (const Expression &expr)
 
 UExprDict (const std::string &s)
 
 UExprDict (const UExprDict &)=default
 
UExprDictoperator= (const UExprDict &)=default
 
UExprDictoperator/= (const Expression &other)
 
std::string __str__ (const std::string name) const
 
const RCP< const Basicget_basic (std::string var) const
 
int compare (const UExprDict &other) const
 
Expression find_cf (int deg) const
 
- Public Member Functions inherited from SymEngine::ODictWrapper< int, Expression, UExprDict >
 ODictWrapper (const int &i)
 
 ODictWrapper (const std::map< int, Expression > &p)
 
 ODictWrapper (std::map< int, Expression > &&p)
 
 ODictWrapper (const Expression &p)
 
 ODictWrapper (std::string s)
 
UExprDictoperator= (UExprDict &&other) SYMENGINE_NOEXCEPT
 
UExprDictoperator+= (const UExprDict &other)
 
UExprDict operator- () const
 
UExprDictoperator-= (const UExprDict &other)
 
UExprDictoperator*= (const UExprDict &other)
 
bool operator!= (const UExprDict &other) const
 
const std::map< int, Expression > & get_dict () const
 
size_t size () const
 
bool empty () const
 
int degree () const
 
Expression get_coeff (int x) const
 
Expression get_lc () const
 

Friends

std::ostreamoperator<< (std::ostream &os, const UExprDict &expr)
 
UExprDict operator/ (const UExprDict &a, const Expression &b)
 

Additional Inherited Members

- Public Types inherited from SymEngine::ODictWrapper< int, Expression, UExprDict >
typedef int key_type
 
- Static Public Member Functions inherited from SymEngine::ODictWrapper< int, Expression, UExprDict >
static UExprDict from_vec (const std::vector< Expression > &v)
 
static UExprDict mul (const UExprDict &a, const UExprDict &b)
 
static UExprDict pow (const UExprDict &a, unsigned int p)
 
static UExprDict from_poly (const FromPoly &p)
 
- Data Fields inherited from SymEngine::ODictWrapper< int, Expression, UExprDict >
std::map< int, Expressiondict_
 

Detailed Description

Definition at line 15 of file uexprpoly.h.

Constructor & Destructor Documentation

◆ UExprDict() [1/6]

SymEngine::UExprDict::UExprDict ( )
inline

Definition at line 19 of file uexprpoly.h.

19{}

◆ ~UExprDict()

SymEngine::UExprDict::~UExprDict ( )
inline

Definition at line 20 of file uexprpoly.h.

20{}

◆ UExprDict() [2/6]

SymEngine::UExprDict::UExprDict ( UExprDict &&  other)
inline

Definition at line 21 of file uexprpoly.h.

22 : ODictWrapper(std::move(other))
23 {
24 }
T move(T... args)
void hash_combine(hash_t &seed, const T &v)
Definition basic-inl.h:95

◆ UExprDict() [3/6]

SymEngine::UExprDict::UExprDict ( const int i)
inline

Definition at line 25 of file uexprpoly.h.

25: ODictWrapper(i) {}

◆ UExprDict() [4/6]

SymEngine::UExprDict::UExprDict ( const map_int_Expr p)
inline

Definition at line 26 of file uexprpoly.h.

26: ODictWrapper(p) {}

◆ UExprDict() [5/6]

SymEngine::UExprDict::UExprDict ( const Expression expr)
inline

Definition at line 27 of file uexprpoly.h.

27: ODictWrapper(expr) {}

◆ UExprDict() [6/6]

SymEngine::UExprDict::UExprDict ( const std::string s)
inline

Definition at line 29 of file uexprpoly.h.

29: ODictWrapper(s) {}

Member Function Documentation

◆ __str__()

std::string SymEngine::UExprDict::__str__ ( const std::string  name) const
inline

Definition at line 51 of file uexprpoly.h.

52 {
54 bool first = true;
55 for (auto it = dict_.rbegin(); it != dict_.rend(); ++it) {
57 // if exponent is 0, then print only coefficient
58 if (it->first == 0) {
59 if (first) {
60 o << it->second;
61 } else {
62 t = detail::poly_print(it->second);
63 if (t[0] == '-') {
64 o << " - " << t.substr(1);
65 } else {
66 o << " + " << t;
67 }
68 }
69 first = false;
70 continue;
71 }
72 // if the coefficient of a term is +1 or -1
73 if (it->second == 1 or it->second == -1) {
74 // in cases of -x, print -x
75 // in cases of x**2 - x, print - x
76 if (first) {
77 if (it->second == -1)
78 o << "-";
79 } else {
80 if (down_cast<const Integer &>(*it->second.get_basic())
81 .as_integer_class()
82 < 0) {
83 o << " "
84 << "-"
85 << " ";
86 } else {
87 o << " "
88 << "+"
89 << " ";
90 }
91 }
92 }
93 // if the coefficient of a term is 0, skip
94 else if (it->second == 0)
95 continue;
96 // same logic is followed as above
97 else {
98 // in cases of -2*x, print -2*x
99 // in cases of x**2 - 2*x, print - 2*x
100 if (first) {
101 o << detail::poly_print(it->second) << "*";
102 } else {
103 t = detail::poly_print(it->second);
104 if (t[0] == '-') {
105 o << " - " << t.substr(1);
106 } else {
107 o << " + " << t;
108 }
109 o << "*";
110 }
111 }
112 o << name;
113 // if exponent is not 1, print the exponent;
114 if (it->first > 1) {
115 o << "**" << it->first;
116 } else if (it->first < 0) {
117 o << "**(" << it->first << ")";
118 }
119 // corner cases of only first term handled successfully, switch the
120 // bool
121 first = false;
122 }
123 return o.str();
124 }
T rbegin(T... args)
T rend(T... args)
T substr(T... args)

◆ compare()

int SymEngine::UExprDict::compare ( const UExprDict other) const
inline

Definition at line 146 of file uexprpoly.h.

147 {
148 return unified_compare(dict_, other.dict_);
149 }
int unified_compare(const T &a, const T &b)
Definition dict.h:205

◆ find_cf()

Expression SymEngine::UExprDict::find_cf ( int  deg) const
inline

Definition at line 151 of file uexprpoly.h.

152 {
153 if (dict_.find(deg) != dict_.end())
154 return dict_.at(deg);
155 else
156 return Expression(0);
157 }
T at(T... args)
T end(T... args)
T find(T... args)

◆ get_basic()

const RCP< const Basic > SymEngine::UExprDict::get_basic ( std::string  var) const
inline

Definition at line 127 of file uexprpoly.h.

128 {
129 RCP<const Symbol> x = symbol(var);
130 umap_basic_num dict;
131 RCP<const Number> coeff = zero;
132 for (const auto &it : dict_) {
133 if (it.first != 0) {
134 auto term
135 = SymEngine::mul(it.second.get_basic(),
136 SymEngine::pow(x, integer(it.first)));
137 Add::coef_dict_add_term(outArg(coeff), dict, one, term);
138 } else {
139 Add::coef_dict_add_term(outArg(coeff), dict, one,
140 it.second.get_basic());
141 }
142 }
143 return Add::from_dict(coeff, std::move(dict));
144 }
static RCP< const Basic > from_dict(const RCP< const Number > &coef, umap_basic_num &&d)
Create an appropriate instance from dictionary quickly.
Definition add.cpp:140
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)
Updates the numerical coefficient and the dictionary.
Definition add.cpp:261
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
Definition mul.cpp:352
RCP< const Symbol > symbol(const std::string &name)
inline version to return Symbol
Definition symbol.h:82
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)
Definition integer.h:197

◆ operator/=()

UExprDict & SymEngine::UExprDict::operator/= ( const Expression other)
inline

Definition at line 45 of file uexprpoly.h.

46 {
47 *this *= (1 / other);
48 return *this;
49 }

Friends And Related Symbol Documentation

◆ operator/

UExprDict operator/ ( const UExprDict a,
const Expression b 
)
friend

Definition at line 40 of file uexprpoly.h.

41 {
42 return a * (1 / b);
43 }

◆ operator<<

std::ostream & operator<< ( std::ostream os,
const UExprDict expr 
)
friend

Definition at line 34 of file uexprpoly.h.

35 {
36 os << expr.dict_;
37 return os;
38 }

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