1 #include <symengine/visitor.h> 2 3 namespace SymEngine 4 { 5 UExprPoly(const RCP<const Basic> & var,UExprDict && dict)6UExprPoly::UExprPoly(const RCP<const Basic> &var, UExprDict &&dict) 7 : USymEnginePoly( 8 var, std::move(dict)){SYMENGINE_ASSIGN_TYPEID() 9 SYMENGINE_ASSERT(is_canonical(get_poly()))} 10 __hash__() const11 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 max_coef() const25Expression 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 eval(const Expression & x) const34Expression UExprPoly::eval(const Expression &x) const 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 is_zero() const45bool UExprPoly::is_zero() const 46 { 47 return get_poly().empty(); 48 } 49 is_one() const50bool 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 is_minus_one() const56bool UExprPoly::is_minus_one() const 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 is_integer() const63bool UExprPoly::is_integer() const 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 is_symbol() const70bool UExprPoly::is_symbol() const 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 is_mul() const76bool 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 is_pow() const83bool 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 91