1 #ifndef SYMENGINE_USYMENGINEPOLY_H
2 #define SYMENGINE_USYMENGINEPOLY_H
4 #include <symengine/polys/upolybase.h>
12 inline void mp_pow_ui_dispatch(T &res,
const T &base,
unsigned long exp)
14 mp_pow_ui(res, base,
exp);
18 template <
typename Container,
template <
typename X,
typename Y>
class BaseType,
23 using Cf =
typename BaseType<Container, Poly>::coef_type;
24 using Key =
typename Container::key_type;
27 : BaseType<Container, Poly>(var, std::move(dict))
31 int compare(
const Basic &o)
const
33 SYMENGINE_ASSERT(is_a<Poly>(o))
34 const Poly &s = down_cast<const Poly &>(o);
36 if (this->get_poly().size() != s.get_poly().size())
37 return (this->get_poly().size() < s.get_poly().size()) ? -1 : 1;
46 bool is_canonical(
const Container &dict)
const
49 for (
auto iter : dict.dict_)
55 static RCP<const Poly> from_vec(
const RCP<const Basic> &var,
56 const std::vector<Cf> &v)
58 return make_rcp<const Poly>(var, Container::from_vec(v));
61 static Container container_from_dict(
const RCP<const Basic> &var,
62 std::map<Key, Cf> &&d)
67 template <
typename FromPoly>
68 static enable_if_t<is_a_UPoly<FromPoly>::value, RCP<const Poly>>
69 from_poly(
const FromPoly &p)
71 return Poly::from_container(p.get_var(),
72 std::move(Container::from_poly(p)));
75 Cf eval(
const Cf &x)
const
77 Key last_deg = this->get_poly().dict_.rbegin()->first;
80 for (
auto it = this->get_poly().dict_.rbegin();
81 it != this->get_poly().dict_.rend(); ++it) {
82 detail::mp_pow_ui_dispatch(x_pow, x, last_deg - (*it).first);
83 last_deg = (*it).first;
84 result = (*it).second + x_pow * result;
86 detail::mp_pow_ui_dispatch(x_pow, x, last_deg);
92 inline const std::map<Key, Cf> &get_dict()
const
94 return this->get_poly().dict_;
97 inline Cf get_coeff(Key x)
const
99 return this->get_poly().get_coeff(x);
102 typedef typename std::map<Key, Cf>::const_iterator iterator;
103 typedef typename std::map<Key, Cf>::const_reverse_iterator r_iterator;
104 iterator begin()
const
106 return this->get_poly().dict_.begin();
110 return this->get_poly().dict_.end();
112 r_iterator obegin()
const
114 return this->get_poly().dict_.rbegin();
116 r_iterator oend()
const
118 return this->get_poly().dict_.rend();
123 if (this->get_poly().dict_.empty())
125 return this->get_degree() + 1;
129 template <
typename Container,
template <
typename X,
typename Y>
class BaseType,
134 auto dict = Poly::container_type::pow(a.get_poly(), p);
135 return Poly::from_container(a.get_var(), std::move(dict));
The lowest unit of symbolic representation.
Main namespace for SymEngine package.
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
int unified_compare(const T &a, const T &b)