uexprpoly.cpp
1 #include <symengine/visitor.h>
2 
3 namespace SymEngine
4 {
5 
6 UExprPoly::UExprPoly(const RCP<const Basic> &var, UExprDict &&dict)
8  var, std::move(dict)){SYMENGINE_ASSIGN_TYPEID()
9  SYMENGINE_ASSERT(is_canonical(get_poly()))}
10 
11  hash_t UExprPoly::__hash__() const
12 {
13  hash_t seed = SYMENGINE_UEXPRPOLY;
14 
15  seed += get_var()->hash();
16  for (const auto &it : get_poly().dict_) {
17  hash_t temp = SYMENGINE_UEXPRPOLY;
18  hash_combine<unsigned int>(temp, it.first);
19  hash_combine<Basic>(temp, *(it.second.get_basic()));
20  seed += temp;
21  }
22  return seed;
23 }
24 
25 Expression UExprPoly::max_coef() const
26 {
27  Expression curr = get_poly().get_dict().begin()->second;
28  for (const auto &it : get_poly().get_dict())
29  if (curr.get_basic()->__cmp__(*it.second.get_basic()))
30  curr = it.second;
31  return curr;
32 }
33 
35 {
36  Expression ans = 0;
37  for (const auto &p : get_poly().get_dict()) {
38  Expression temp;
39  temp = pow(x, Expression(p.first));
40  ans += p.second * temp;
41  }
42  return ans;
43 }
44 
45 bool UExprPoly::is_zero() const
46 {
47  return get_poly().empty();
48 }
49 
50 bool UExprPoly::is_one() const
51 {
52  return get_poly().size() == 1 and get_poly().get_dict().begin()->second == 1
53  and get_poly().get_dict().begin()->first == 0;
54 }
55 
57 {
58  return get_poly().size() == 1
59  and get_poly().get_dict().begin()->second == -1
60  and get_poly().get_dict().begin()->first == 0;
61 }
62 
64 {
65  if (get_poly().empty())
66  return true;
67  return get_poly().size() == 1 and get_poly().get_dict().begin()->first == 0;
68 }
69 
71 {
72  return get_poly().size() == 1 and get_poly().get_dict().begin()->first == 1
73  and get_poly().get_dict().begin()->second == 1;
74 }
75 
76 bool UExprPoly::is_mul() const
77 {
78  return get_poly().size() == 1 and get_poly().get_dict().begin()->first != 0
79  and get_poly().get_dict().begin()->second != 1
80  and get_poly().get_dict().begin()->second != 0;
81 }
82 
83 bool UExprPoly::is_pow() const
84 {
85  return get_poly().size() == 1 and get_poly().get_dict().begin()->second == 1
86  and get_poly().get_dict().begin()->first != 1
87  and get_poly().get_dict().begin()->first != 0;
88 }
89 
90 } // namespace SymEngine
const RCP< const Basic > & get_basic() const
Method to get Basic from Expression.
Definition: expression.h:259
bool is_zero() const
Definition: uexprpoly.cpp:45
bool is_mul() const
Definition: uexprpoly.cpp:76
bool is_symbol() const
Definition: uexprpoly.cpp:70
hash_t __hash__() const override
Definition: uexprpoly.cpp:11
bool is_integer() const
Definition: uexprpoly.cpp:63
bool is_minus_one() const
Definition: uexprpoly.cpp:56
UExprPoly(const RCP< const Basic > &var, UExprDict &&dict)
Constructor of UExprPoly class.
Definition: uexprpoly.cpp:6
Expression eval(const Expression &x) const
Evaluates the UExprPoly at value x.
Definition: uexprpoly.cpp:34
bool is_one() const
Definition: uexprpoly.cpp:50
bool is_pow() const
Definition: uexprpoly.cpp:83
Main namespace for SymEngine package.
Definition: add.cpp:19
STL namespace.