3 #include <symengine/series_visitor.h>
4 #include <symengine/symengine_exception.h>
6 using SymEngine::make_rcp;
12 RCP<const UnivariateSeries> UnivariateSeries::series(
const RCP<const Basic> &t,
16 UExprDict p({{1, Expression(1)}});
17 SeriesVisitor<UExprDict, Expression, UnivariateSeries> visitor(
std::move(p),
19 return visitor.series(t);
24 hash_t seed = SYMENGINE_UEXPRPOLY;
26 for (
const auto &it : p_.dict_) {
27 hash_t temp = SYMENGINE_UEXPRPOLY;
28 hash_combine<unsigned int>(temp, it.first);
29 hash_combine<Basic>(temp, *(it.second.get_basic()));
37 SYMENGINE_ASSERT(is_a<UnivariateSeries>(other))
39 return p_.compare(o_.get_poly());
42 RCP<const Basic> UnivariateSeries::as_basic()
const
44 return p_.get_basic(var_);
47 umap_int_basic UnivariateSeries::as_dict()
const
50 for (
const auto &it : p_.get_dict())
52 map[it.first] = it.second.get_basic();
56 RCP<const Basic> UnivariateSeries::get_coeff(
int deg)
const
58 if (p_.get_dict().count(deg) == 0)
61 return p_.get_dict().at(deg).get_basic();
64 UExprDict UnivariateSeries::var(
const std::string &s)
66 return UExprDict({{1, Expression(1)}});
69 Expression UnivariateSeries::convert(
const Basic &x)
71 return Expression(x.rcp_from_this());
74 int UnivariateSeries::ldegree(
const UExprDict &s)
76 return s.get_dict().begin()->first;
79 UExprDict UnivariateSeries::mul(
const UExprDict &a,
const UExprDict &b,
83 for (
auto &it1 : a.get_dict()) {
84 for (
auto &it2 : b.get_dict()) {
85 int exp = it1.first + it2.first;
86 if (exp < (
int)prec) {
87 p[
exp] += it1.second * it2.second;
96 UExprDict UnivariateSeries::pow(
const UExprDict &base,
int exp,
unsigned prec)
99 SYMENGINE_ASSERT(base.size() == 1)
101 dict[-(base.get_dict().begin()->first)]
102 = 1 / base.get_dict().begin()->second;
103 return pow(UExprDict(dict), -exp, prec);
106 if (base == 0 or base.get_dict().size() == 0) {
107 throw DomainError(
"Error: 0**0 is undefined.");
125 return mul(x, y, prec);
128 Expression UnivariateSeries::find_cf(
const UExprDict &s,
const UExprDict &var,
131 if (s.get_dict().count(deg) == 0)
132 return Expression(0);
134 return (s.get_dict()).at(deg);
137 Expression UnivariateSeries::root(Expression &c,
unsigned n)
139 return SymEngine::pow(c, 1 / Expression(n));
142 UExprDict UnivariateSeries::diff(
const UExprDict &s,
const UExprDict &var)
144 if (var.get_dict().size() == 1 and var.get_dict().at(1) == Expression(1)) {
146 for (
const auto &p : s.get_dict()) {
148 d[p.first - 1] = p.second * p.first;
152 return UExprDict({{0, Expression(0)}});
156 UExprDict UnivariateSeries::integrate(
const UExprDict &s,
const UExprDict &var)
159 for (
auto &it : s.get_dict()) {
160 if (it.first != -1) {
162 it.second / (it.first + 1)));
164 throw NotImplementedError(
"Not Implemented");
168 return UExprDict(dict);
171 UExprDict UnivariateSeries::subs(
const UExprDict &s,
const UExprDict &var,
172 const UExprDict &r,
unsigned prec)
174 UExprDict result({{1, Expression(1)}});
176 for (
auto &i : s.get_dict())
177 result += i.second * pow(r, i.first, prec);
182 Expression UnivariateSeries::sin(
const Expression &c)
187 Expression UnivariateSeries::cos(
const Expression &c)
192 Expression UnivariateSeries::tan(
const Expression &c)
197 Expression UnivariateSeries::asin(
const Expression &c)
202 Expression UnivariateSeries::acos(
const Expression &c)
207 Expression UnivariateSeries::atan(
const Expression &c)
212 Expression UnivariateSeries::sinh(
const Expression &c)
217 Expression UnivariateSeries::cosh(
const Expression &c)
222 Expression UnivariateSeries::tanh(
const Expression &c)
227 Expression UnivariateSeries::asinh(
const Expression &c)
232 Expression UnivariateSeries::atanh(
const Expression &c)
237 Expression UnivariateSeries::exp(
const Expression &c)
242 Expression UnivariateSeries::log(
const Expression &c)
The lowest unit of symbolic representation.
int compare(const Basic &o) const override
hash_t __hash__() const override
Main namespace for SymEngine package.
RCP< const Basic > acos(const RCP< const Basic > &arg)
Canonicalize ACos:
void hash_combine(hash_t &seed, const T &v)
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
RCP< const Basic > asin(const RCP< const Basic > &arg)
Canonicalize ASin:
RCP< const Basic > tan(const RCP< const Basic > &arg)
Canonicalize Tan:
RCP< const Basic > cosh(const RCP< const Basic > &arg)
Canonicalize Cosh:
RCP< const Basic > atan(const RCP< const Basic > &arg)
Canonicalize ATan:
RCP< const Basic > asinh(const RCP< const Basic > &arg)
Canonicalize ASinh:
RCP< const Basic > tanh(const RCP< const Basic > &arg)
Canonicalize Tanh:
RCP< const Basic > atanh(const RCP< const Basic > &arg)
Canonicalize ATanh:
RCP< const Basic > cos(const RCP< const Basic > &arg)
Canonicalize Cos:
RCP< const Basic > log(const RCP< const Basic > &arg)
Returns the Natural Logarithm from argument arg
RCP< const Basic > sinh(const RCP< const Basic > &arg)
Canonicalize Sinh:
RCP< const Basic > sin(const RCP< const Basic > &arg)
Canonicalize Sin: