Loading...
Searching...
No Matches
series.cpp
1
7#include <symengine/series_visitor.h>
8
9namespace SymEngine
10{
11
12bool needs_symbolic_constants(const RCP<const Basic> &ex,
13 const RCP<const Symbol> &var)
14{
15 NeedsSymbolicExpansionVisitor v;
16 return v.apply(*ex, var);
17}
18
19RCP<const SeriesCoeffInterface> series(const RCP<const Basic> &ex,
20 const RCP<const Symbol> &var,
21 unsigned int prec)
22{
23 auto syms = free_symbols(*ex);
24#ifdef HAVE_SYMENGINE_PIRANHA
25 if (prec == 0)
26 return make_rcp<const UPSeriesPiranha>(p_expr{Expression()},
27 var->get_name(), prec);
28 if (not has_symbol(*ex, *var))
29 return make_rcp<const UPSeriesPiranha>(p_expr{Expression(ex)},
30 var->get_name(), prec);
31 if (is_a<Symbol>(*ex))
32 return make_rcp<const UPSeriesPiranha>(p_expr{Expression(ex)},
33 var->get_name(), prec);
34
35 if (syms.size() == 1) {
36 if (needs_symbolic_constants(ex, var))
37 return UPSeriesPiranha::series(ex, var->get_name(), prec);
38#ifdef HAVE_SYMENGINE_FLINT
39 return URatPSeriesFlint::series(ex, var->get_name(), prec);
40#else
41 return URatPSeriesPiranha::series(ex, var->get_name(), prec);
42#endif
43 }
44
45 return UPSeriesPiranha::series(ex, var->get_name(), prec);
46#elif defined(HAVE_SYMENGINE_FLINT)
48 if (prec == 0)
49 return URatPSeriesFlint::series(integer(0), var->get_name(), prec);
50
51 if (syms.size() > 1)
52 return UnivariateSeries::series(ex, var->get_name(), prec);
53
54 if (needs_symbolic_constants(ex, var))
55 return UnivariateSeries::series(ex, var->get_name(), prec);
56 return URatPSeriesFlint::series(ex, var->get_name(), prec);
57#else
58 return UnivariateSeries::series(ex, var->get_name(), prec);
59#endif
60}
61
62RCP<const SeriesCoeffInterface> series_invfunc(const RCP<const Basic> &ex,
63 const RCP<const Symbol> &var,
64 unsigned int prec)
65{
66#ifdef HAVE_SYMENGINE_PIRANHA
67 if (prec == 0)
68 return make_rcp<const UPSeriesPiranha>(p_expr{Expression()},
69 var->get_name(), prec);
70 if (is_a<Symbol>(*ex))
71 return make_rcp<const UPSeriesPiranha>(p_expr{Expression(ex)},
72 var->get_name(), prec);
73
74 return make_rcp<const UPSeriesPiranha>(
75 UPSeriesPiranha::series_reverse(
76 UPSeriesPiranha::series(ex, var->get_name(), prec)->get_poly(),
77 p_expr(var->get_name()), prec),
78 var->get_name(), prec);
79
80#else
81 throw SymEngineException("Series reversion is supported only with Piranha");
82#endif
83}
84
85} // namespace SymEngine
Main namespace for SymEngine package.
Definition: add.cpp:19
std::enable_if< std::is_integral< T >::value, RCP< constInteger > >::type integer(T i)
Definition: integer.h:200