Expression UExprPoly::max_coef() const { Expression curr = get_poly().get_dict().begin()->second; for (const auto &it : get_poly().get_dict()) if (curr.get_basic()->__cmp__(*it.second.get_basic())) curr = it.second; return curr; }
Expression UExprPoly::eval(const Expression &x) const { Expression ans = 0; for (const auto &p : get_poly().get_dict()) { Expression temp; temp = pow_ex(x, Expression(p.first)); ans += p.second * temp; } return ans; }
int main() { int degree; printf("Enter the degree of the polynomial: "); scanf("%d", °ree); printf("Enter each coefficient: "); double coeff[degree]; get_poly(coeff[degree], degree); double x; printf("Enter the value for x: "); scanf("%lf", &x); eval_poly(coeff[degree], degree, x); system("pause"); return 0; }
bool UExprPoly::is_pow() const { return get_poly().size() == 1 and get_poly().get_dict().begin()->second == 1 and get_poly().get_dict().begin()->first != 1 and get_poly().get_dict().begin()->first != 0; }
bool UExprPoly::is_symbol() const { return get_poly().size() == 1 and get_poly().get_dict().begin()->first == 1 and get_poly().get_dict().begin()->second == 1; }
bool UExprPoly::is_integer() const { if (get_poly().empty()) return true; return get_poly().size() == 1 and get_poly().get_dict().begin()->first == 0; }
bool UExprPoly::is_minus_one() const { return get_poly().size() == 1 and get_poly().get_dict().begin()->second == -1 and get_poly().get_dict().begin()->first == 0; }
bool UExprPoly::is_zero() const { return get_poly().empty(); }