Loading...
Searching...
No Matches
SymEngine::SeriesVisitor< Poly, Coeff, Series > Class Template Reference
+ Inheritance diagram for SymEngine::SeriesVisitor< Poly, Coeff, Series >:
+ Collaboration diagram for SymEngine::SeriesVisitor< Poly, Coeff, Series >:

Public Member Functions

 SeriesVisitor (const Poly &var_, const std::string &varname_, const unsigned prec_)
 
RCP< const Series > series (const RCP< const Basic > &x)
 
Poly apply (const RCP< const Basic > &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Pow &x)
 
void bvisit (const Function &x)
 
void bvisit (const Gamma &x)
 
void bvisit (const Series &x)
 
void bvisit (const Integer &x)
 
void bvisit (const Rational &x)
 
void bvisit (const Complex &x)
 
void bvisit (const RealDouble &x)
 
void bvisit (const ComplexDouble &x)
 
void bvisit (const Sin &x)
 
void bvisit (const Cos &x)
 
void bvisit (const Tan &x)
 
void bvisit (const Cot &x)
 
void bvisit (const Csc &x)
 
void bvisit (const Sec &x)
 
void bvisit (const Log &x)
 
void bvisit (const ASin &x)
 
void bvisit (const ACos &x)
 
void bvisit (const ATan &x)
 
void bvisit (const Sinh &x)
 
void bvisit (const Cosh &x)
 
void bvisit (const Tanh &x)
 
void bvisit (const ASinh &x)
 
void bvisit (const ATanh &x)
 
void bvisit (const LambertW &x)
 
void bvisit (const Symbol &x)
 
void bvisit (const Constant &x)
 
void bvisit (const Basic &x)
 

Private Attributes

Poly p
 
const Poly var
 
const std::string varname
 
const unsigned prec
 

Detailed Description

template<typename Poly, typename Coeff, typename Series>
class SymEngine::SeriesVisitor< Poly, Coeff, Series >

Definition at line 10 of file series_visitor.h.

Constructor & Destructor Documentation

◆ SeriesVisitor()

template<typename Poly , typename Coeff , typename Series >
SymEngine::SeriesVisitor< Poly, Coeff, Series >::SeriesVisitor ( const Poly &  var_,
const std::string varname_,
const unsigned  prec_ 
)
inline

Definition at line 19 of file series_visitor.h.

21 : var(var_), varname(varname_), prec(prec_)
22 {
23 }

Member Function Documentation

◆ apply()

template<typename Poly , typename Coeff , typename Series >
Poly SymEngine::SeriesVisitor< Poly, Coeff, Series >::apply ( const RCP< const Basic > &  x)
inline

Definition at line 29 of file series_visitor.h.

30 {
31 x->accept(*this);
32 Poly temp(std::move(p));
33 return temp;
34 }
T move(T... args)

◆ bvisit() [1/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const ACos x)
inline

Definition at line 229 of file series_visitor.h.

230 {
231 x.get_arg()->accept(*this);
232 p = Series::series_acos(p, var, prec);
233 }

◆ bvisit() [2/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Add x)
inline

Definition at line 36 of file series_visitor.h.

37 {
38 Poly temp(apply(x.get_coef()));
39 for (const auto &term : x.get_dict()) {
40 temp += apply(term.first) * apply(term.second);
41 }
42 p = temp;
43 }

◆ bvisit() [3/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const ASin x)
inline

Definition at line 224 of file series_visitor.h.

225 {
226 x.get_arg()->accept(*this);
227 p = Series::series_asin(p, var, prec);
228 }

◆ bvisit() [4/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const ASinh x)
inline

Definition at line 254 of file series_visitor.h.

255 {
256 x.get_arg()->accept(*this);
257 p = Series::series_asinh(p, var, prec);
258 }

◆ bvisit() [5/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const ATan x)
inline

Definition at line 234 of file series_visitor.h.

235 {
236 x.get_arg()->accept(*this);
237 p = Series::series_atan(p, var, prec);
238 }

◆ bvisit() [6/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const ATanh x)
inline

Definition at line 259 of file series_visitor.h.

260 {
261 x.get_arg()->accept(*this);
262 p = Series::series_atanh(p, var, prec);
263 }

◆ bvisit() [7/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Basic x)
inline

Definition at line 281 of file series_visitor.h.

282 {
283 if (!has_symbol(x, *symbol(varname))) {
284 p = Series::convert(x);
285 } else {
286 throw NotImplementedError("Not Implemented");
287 }
288 }
RCP< const Symbol > symbol(const std::string &name)
inline version to return Symbol
Definition: symbol.h:82

◆ bvisit() [8/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Complex x)
inline

Definition at line 165 of file series_visitor.h.

166 {
167 p = Series::convert(x);
168 }

◆ bvisit() [9/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const ComplexDouble x)
inline

Definition at line 173 of file series_visitor.h.

174 {
175 p = Series::convert(x);
176 }

◆ bvisit() [10/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Constant x)
inline

Definition at line 277 of file series_visitor.h.

278 {
279 p = Series::convert(x);
280 }

◆ bvisit() [11/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Cos x)
inline

Definition at line 194 of file series_visitor.h.

195 {
196 x.get_arg()->accept(*this);
197 p = Series::series_cos(p, var, prec);
198 }

◆ bvisit() [12/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Cosh x)
inline

Definition at line 244 of file series_visitor.h.

245 {
246 x.get_arg()->accept(*this);
247 p = Series::series_cosh(p, var, prec);
248 }

◆ bvisit() [13/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Cot x)
inline

Definition at line 204 of file series_visitor.h.

205 {
206 x.get_arg()->accept(*this);
207 p = Series::series_cot(p, var, prec);
208 }

◆ bvisit() [14/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Csc x)
inline

Definition at line 209 of file series_visitor.h.

210 {
211 x.get_arg()->accept(*this);
212 p = Series::series_csc(p, var, prec);
213 }

◆ bvisit() [15/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Function x)
inline

Definition at line 104 of file series_visitor.h.

105 {
106 RCP<const Basic> d = x.rcp_from_this();
107 RCP<const Symbol> s = symbol(varname);
108
109 map_basic_basic m({{s, zero}});
110 RCP<const Basic> const_term = d->subs(m);
111 if (const_term == d) {
112 p = Series::convert(*d);
113 return;
114 }
115 Poly res_p(apply(expand(const_term)));
116 Coeff prod, t;
117 prod = 1;
118
119 for (unsigned int i = 1; i < prec; i++) {
120 // Workaround for flint
121 t = i;
122 prod /= t;
123 d = d->diff(s);
124 res_p += Series::pow(var, i, prec)
125 * (prod * apply(expand(d->subs(m))));
126 }
127 p = res_p;
128 }
RCP< const Basic > expand(const RCP< const Basic > &self, bool deep=true)
Expands self
Definition: expand.cpp:369

◆ bvisit() [16/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Gamma x)
inline

Definition at line 130 of file series_visitor.h.

131 {
132 RCP<const Symbol> s = symbol(varname);
133 RCP<const Basic> arg = x.get_args()[0];
134 if (eq(*arg->subs({{s, zero}}), *zero)) {
135 RCP<const Basic> g = gamma(add(arg, one));
136 if (is_a<Gamma>(*g)) {
137 bvisit(down_cast<const Function &>(*g));
138 p *= Series::pow(var, -1, prec);
139 } else {
140 g->accept(*this);
141 }
142 } else {
143 bvisit(implicit_cast<const Function &>(x));
144 }
145 }
bool eq(const Basic &a, const Basic &b)
Checks equality for a and b
Definition: basic-inl.h:21
RCP< const Basic > gamma(const RCP< const Basic > &arg)
Canonicalize Gamma:
Definition: functions.cpp:3014
RCP< const Basic > add(const RCP< const Basic > &a, const RCP< const Basic > &b)
Adds two objects (safely).
Definition: add.cpp:425

◆ bvisit() [17/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Integer x)
inline

Definition at line 157 of file series_visitor.h.

158 {
159 p = Series::convert(x);
160 }

◆ bvisit() [18/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const LambertW x)
inline

Definition at line 264 of file series_visitor.h.

265 {
266 x.get_arg()->accept(*this);
267 p = Series::series_lambertw(p, var, prec);
268 }

◆ bvisit() [19/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Log x)
inline

Definition at line 219 of file series_visitor.h.

220 {
221 x.get_arg()->accept(*this);
222 p = Series::series_log(p, var, prec);
223 }

◆ bvisit() [20/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Mul x)
inline

Definition at line 44 of file series_visitor.h.

45 {
46 Poly temp(apply(x.get_coef()));
47 for (const auto &term : x.get_dict()) {
48 temp = Series::mul(temp, apply(pow(term.first, term.second)), prec);
49 }
50 p = temp;
51 }
T pow(T... args)

◆ bvisit() [21/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Pow x)
inline

Definition at line 52 of file series_visitor.h.

53 {
54 const RCP<const Basic> &base = x.get_base(), exp = x.get_exp();
55 if (is_a<Integer>(*exp)) {
56 const Integer &ii = (down_cast<const Integer &>(*exp));
57 if (not mp_fits_slong_p(ii.as_integer_class()))
58 throw SymEngineException("series power exponent size");
59 const int sh = numeric_cast<int>(mp_get_si(ii.as_integer_class()));
60 base->accept(*this);
61 if (sh == 1) {
62 return;
63 } else if (sh > 0) {
64 p = Series::pow(p, sh, prec);
65 } else if (sh == -1) {
66 p = Series::series_invert(p, var, prec);
67 } else {
68 // Invert and then exponentiate to give the correct behavior
69 // when expanding 1/x**(prec), which should return x**(-prec),
70 // not 0.
71 p = Series::pow(Series::series_invert(p, var, prec), -sh, prec);
72 }
73
74 } else if (is_a<Rational>(*exp)) {
75 const Rational &rat = (down_cast<const Rational &>(*exp));
76 const integer_class &expnumz = get_num(rat.as_rational_class());
77 const integer_class &expdenz = get_den(rat.as_rational_class());
78 if (not mp_fits_slong_p(expnumz) or not mp_fits_slong_p(expdenz))
79 throw SymEngineException("series rational power exponent size");
80 const int num = numeric_cast<int>(mp_get_si(expnumz));
81 const int den = numeric_cast<int>(mp_get_si(expdenz));
82 base->accept(*this);
83 const Poly proot(
84 Series::series_nthroot(apply(base), den, var, prec));
85 if (num == 1) {
86 p = proot;
87 } else if (num > 0) {
88 p = Series::pow(proot, num, prec);
89 } else if (num == -1) {
90 p = Series::series_invert(proot, var, prec);
91 } else {
92 p = Series::series_invert(Series::pow(proot, -num, prec), var,
93 prec);
94 }
95 } else if (eq(*E, *base)) {
96 p = Series::series_exp(apply(exp), var, prec);
97 } else {
98 p = Series::series_exp(
99 Poly(apply(exp) * Series::series_log(apply(base), var, prec)),
100 var, prec);
101 }
102 }
RCP< const Basic > exp(const RCP< const Basic > &x)
Returns the natural exponential function E**x = pow(E, x)
Definition: pow.cpp:271

◆ bvisit() [22/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Rational x)
inline

Definition at line 161 of file series_visitor.h.

162 {
163 p = Series::convert(x);
164 }

◆ bvisit() [23/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const RealDouble x)
inline

Definition at line 169 of file series_visitor.h.

170 {
171 p = Series::convert(x);
172 }

◆ bvisit() [24/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Sec x)
inline

Definition at line 214 of file series_visitor.h.

215 {
216 x.get_arg()->accept(*this);
217 p = Series::series_sec(p, var, prec);
218 }

◆ bvisit() [25/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Series &  x)
inline

Definition at line 147 of file series_visitor.h.

148 {
149 if (x.get_var() != varname) {
150 throw NotImplementedError("Multivariate Series not implemented");
151 }
152 if (x.get_degree() < prec) {
153 throw SymEngineException("Series with lesser prec found");
154 }
155 p = x.get_poly();
156 }

◆ bvisit() [26/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Sin x)
inline

Definition at line 189 of file series_visitor.h.

190 {
191 x.get_arg()->accept(*this);
192 p = Series::series_sin(p, var, prec);
193 }

◆ bvisit() [27/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Sinh x)
inline

Definition at line 239 of file series_visitor.h.

240 {
241 x.get_arg()->accept(*this);
242 p = Series::series_sinh(p, var, prec);
243 }

◆ bvisit() [28/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Symbol x)
inline

Definition at line 269 of file series_visitor.h.

270 {
271 if (x.get_name() == varname) {
272 p = Series::var(x.get_name());
273 } else {
274 p = Series::convert(x);
275 }
276 }

◆ bvisit() [29/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Tan x)
inline

Definition at line 199 of file series_visitor.h.

200 {
201 x.get_arg()->accept(*this);
202 p = Series::series_tan(p, var, prec);
203 }

◆ bvisit() [30/30]

template<typename Poly , typename Coeff , typename Series >
void SymEngine::SeriesVisitor< Poly, Coeff, Series >::bvisit ( const Tanh x)
inline

Definition at line 249 of file series_visitor.h.

250 {
251 x.get_arg()->accept(*this);
252 p = Series::series_tanh(p, var, prec);
253 }

◆ series()

template<typename Poly , typename Coeff , typename Series >
RCP< const Series > SymEngine::SeriesVisitor< Poly, Coeff, Series >::series ( const RCP< const Basic > &  x)
inline

Definition at line 24 of file series_visitor.h.

25 {
26 return make_rcp<Series>(apply(x), varname, prec);
27 }

Field Documentation

◆ p

template<typename Poly , typename Coeff , typename Series >
Poly SymEngine::SeriesVisitor< Poly, Coeff, Series >::p
private

Definition at line 13 of file series_visitor.h.

◆ prec

template<typename Poly , typename Coeff , typename Series >
const unsigned SymEngine::SeriesVisitor< Poly, Coeff, Series >::prec
private

Definition at line 16 of file series_visitor.h.

◆ var

template<typename Poly , typename Coeff , typename Series >
const Poly SymEngine::SeriesVisitor< Poly, Coeff, Series >::var
private

Definition at line 14 of file series_visitor.h.

◆ varname

template<typename Poly , typename Coeff , typename Series >
const std::string SymEngine::SeriesVisitor< Poly, Coeff, Series >::varname
private

Definition at line 15 of file series_visitor.h.


The documentation for this class was generated from the following file: