Formal Power Series¶
Methods for computing and manipulating Formal Power Series.

class
sympy.series.formal.
FormalPowerSeries
[source]¶ Represents Formal Power Series of a function.
No computation is performed. This class should only to be used to represent a series. No checks are performed.
For computing a series use
fps()
.See also

infinite
¶ Returns an infinite representation of the series

integrate
(x=None)[source]¶ Integrate Formal Power Series.
Examples
>>> from sympy import fps, sin >>> from sympy.abc import x >>> f = fps(sin(x)) >>> f.integrate(x).truncate() 1 + x**2/2  x**4/24 + O(x**6) >>> f.integrate((x, 0, 1)) cos(1) + 1


sympy.series.formal.
fps
(f, x=None, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)[source]¶ Generates Formal Power Series of f.
Returns the formal series expansion of
f
aroundx = x0
with respect tox
in the form of aFormalPowerSeries
object.Formal Power Series is represented using an explicit formula computed using different algorithms.
See
compute_fps()
for the more details regarding the computation of formula.Parameters: x : Symbol, optional
If x is None and
f
is univariate, the univariate symbols will be supplied, otherwise an error will be raised.x0 : number, optional
Point to perform series expansion about. Default is 0.
dir : {1, 1, ‘+’, ‘‘}, optional
If dir is 1 or ‘+’ the series is calculated from the right and for 1 or ‘‘ the series is calculated from the left. For smooth functions this flag will not alter the results. Default is 1.
hyper : {True, False}, optional
Set hyper to False to skip the hypergeometric algorithm. By default it is set to False.
order : int, optional
Order of the derivative of
f
, Default is 4.rational : {True, False}, optional
Set rational to False to skip rational algorithm. By default it is set to True.
full : {True, False}, optional
Set full to True to increase the range of rational algorithm. See
rational_algorithm()
for details. By default it is set to False.Examples
>>> from sympy import fps, O, ln, atan >>> from sympy.abc import x
Rational Functions
>>> fps(ln(1 + x)).truncate() x  x**2/2 + x**3/3  x**4/4 + x**5/5 + O(x**6)
>>> fps(atan(x), full=True).truncate() x  x**3/3 + x**5/5 + O(x**6)

sympy.series.formal.
compute_fps
(f, x, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)[source]¶ Computes the formula for Formal Power Series of a function.
Tries to compute the formula by applying the following techniques (in order):
 rational_algorithm
 Hypergeomitric algorithm
Parameters: x : Symbol
x0 : number, optional
Point to perform series expansion about. Default is 0.
dir : {1, 1, ‘+’, ‘‘}, optional
If dir is 1 or ‘+’ the series is calculated from the right and for 1 or ‘‘ the series is calculated from the left. For smooth functions this flag will not alter the results. Default is 1.
hyper : {True, False}, optional
Set hyper to False to skip the hypergeometric algorithm. By default it is set to False.
order : int, optional
Order of the derivative of
f
, Default is 4.rational : {True, False}, optional
Set rational to False to skip rational algorithm. By default it is set to True.
full : {True, False}, optional
Set full to True to increase the range of rational algorithm. See
rational_algorithm()
for details. By default it is set to False.Returns: ak : sequence
Sequence of coefficients.
xk : sequence
Sequence of powers of x.
ind : Expr
Independent terms.
mul : Pow
Common terms.
Rational Algorithm¶

sympy.series.formal.
rational_independent
(terms, x)[source]¶ Returns a list of all the rationally independent terms.
Examples
>>> from sympy import sin, cos >>> from sympy.series.formal import rational_independent >>> from sympy.abc import x
>>> rational_independent([cos(x), sin(x)], x) [cos(x), sin(x)] >>> rational_independent([x**2, sin(x), x*sin(x), x**3], x) [x**3 + x**2, x*sin(x) + sin(x)]

sympy.series.formal.
rational_algorithm
(f, x, k, order=4, full=False)[source]¶ Rational algorithm for computing formula of coefficients of Formal Power Series of a function.
Applicable when f(x) or some derivative of f(x) is a rational function in x.
rational_algorithm()
usesapart()
function for partial fraction decomposition.apart()
by default uses ‘undetermined coefficients method’. By settingfull=True
, ‘Bronstein’s algorithm’ can be used instead.Looks for derivative of a function up to 4’th order (by default). This can be overriden using order option.
Returns: formula : Expr
ind : Expr
Independent terms.
order : int
See also
Notes
By setting
full=True
, range of admissible functions to be solved usingrational_algorithm
can be increased. This option should be used carefully as it can signifcantly slow down the computation asdoit
is performed on theRootSum
object returned by theapart
function. Usefull=False
whenever possible.References
[R446] Formal Power Series  Dominik Gruntz, Wolfram Koepf [R447] Power Series in Computer Algebra  Wolfram Koepf Examples
>>> from sympy import log, atan, I >>> from sympy.series.formal import rational_algorithm as ra >>> from sympy.abc import x, k
>>> ra(1 / (1  x), x, k) (1, 0, 0) >>> ra(log(1 + x), x, k) ((1)**(k)/k, 0, 1)
>>> ra(atan(x), x, k, full=True) ((I*(I)**(k)/2 + I*I**(k)/2)/k, 0, 1)
Hypergeometric Algorithm¶

sympy.series.formal.
simpleDE
(f, x, g, order=4)[source]¶ Generates simple DE.
DE is of the form
\[f^k(x) + \sum\limits_{j=0}^{k1} A_j f^j(x) = 0\]where \(A_j\) should be rational function in x.
Generates DE’s upto order 4 (default). DE’s can also have free parameters.
By increasing order, higher order DE’s can be found.
Yields a tuple of (DE, order).

sympy.series.formal.
exp_re
(DE, r, k)[source]¶ Converts a DE with constant coefficients (explike) into a RE.
Performs the substitution:
\[f^j(x) \to r(k + j)\]Normalises the terms so that lowest order of a term is always r(k).
See also
Examples
>>> from sympy import Function, Derivative >>> from sympy.series.formal import exp_re >>> from sympy.abc import x, k >>> f, r = Function('f'), Function('r')
>>> exp_re(f(x) + Derivative(f(x)), r, k) r(k) + r(k + 1) >>> exp_re(Derivative(f(x), x) + Derivative(f(x), x, x), r, k) r(k) + r(k + 1)

sympy.series.formal.
hyper_re
(DE, r, k)[source]¶ Converts a DE into a RE.
Performs the substitution:
\[x^l f^j(x) \to (k + 1  l)_j . a_{k + j  l}\]Normalises the terms so that lowest order of a term is always r(k).
See also
Examples
>>> from sympy import Function, Derivative >>> from sympy.series.formal import hyper_re >>> from sympy.abc import x, k >>> f, r = Function('f'), Function('r')
>>> hyper_re(f(x) + Derivative(f(x)), r, k) (k + 1)*r(k + 1)  r(k) >>> hyper_re(x*f(x) + Derivative(f(x), x, x), r, k) (k + 2)*(k + 3)*r(k + 3)  r(k)

sympy.series.formal.
rsolve_hypergeometric
(f, x, P, Q, k, m)[source]¶ Solves RE of hypergeometric type.
Attempts to solve RE of the form
Q(k)*a(k + m)  P(k)*a(k)
Transformations that preserve Hypergeometric type:
 x**n*f(x): b(k + m) = R(k  n)*b(k)
 f(A*x): b(k + m) = A**m*R(k)*b(k)
 f(x**n): b(k + n*m) = R(k/n)*b(k)
 f(x**(1/m)): b(k + 1) = R(k*m)*b(k)
 f’(x): b(k + m) = ((k + m + 1)/(k + 1))*R(k + 1)*b(k)
Some of these transformations have been used to solve the RE.
Returns: formula : Expr
ind : Expr
Independent terms.
order : int
References
[R448] Formal Power Series  Dominik Gruntz, Wolfram Koepf [R449] Power Series in Computer Algebra  Wolfram Koepf Examples
>>> from sympy import exp, ln, S >>> from sympy.series.formal import rsolve_hypergeometric as rh >>> from sympy.abc import x, k
>>> rh(exp(x), x, S.One, (k + 1), k, 1) (Piecewise((1/factorial(k), Eq(Mod(k, 1), 0)), (0, True)), 1, 1)
>>> rh(ln(1 + x), x, k**2, k*(k + 1), k, 1) (Piecewise(((1)**(k  1)*factorial(k  1)/RisingFactorial(2, k  1), Eq(Mod(k, 1), 0)), (0, True)), x, 2)

sympy.series.formal.
solve_de
(f, x, DE, order, g, k)[source]¶ Solves the DE.
Tries to solve DE by either converting into a RE containing two terms or converting into a DE having constant coefficients.
Returns: formula : Expr
ind : Expr
Independent terms.
order : int
Examples
>>> from sympy import Derivative as D >>> from sympy import exp, ln >>> from sympy.series.formal import solve_de >>> from sympy.abc import x, k, f
>>> solve_de(exp(x), x, D(f(x), x)  f(x), 1, f, k) (Piecewise((1/factorial(k), Eq(Mod(k, 1), 0)), (0, True)), 1, 1)
>>> solve_de(ln(1 + x), x, (x + 1)*D(f(x), x, 2) + D(f(x)), 2, f, k) (Piecewise(((1)**(k  1)*factorial(k  1)/RisingFactorial(2, k  1), Eq(Mod(k, 1), 0)), (0, True)), x, 2)

sympy.series.formal.
hyper_algorithm
(f, x, k, order=4)[source]¶ Hypergeometric algorithm for computing Formal Power Series.
 Steps:
 Generates DE
 Convert the DE into RE
 Solves the RE
Examples
>>> from sympy import exp, ln >>> from sympy.series.formal import hyper_algorithm
>>> from sympy.abc import x, k
>>> hyper_algorithm(exp(x), x, k) (Piecewise((1/factorial(k), Eq(Mod(k, 1), 0)), (0, True)), 1, 1)
>>> hyper_algorithm(ln(1 + x), x, k) (Piecewise(((1)**(k  1)*factorial(k  1)/RisingFactorial(2, k  1), Eq(Mod(k, 1), 0)), (0, True)), x, 2)