Formal Power Series¶
Methods for computing and manipulating Formal Power Series.
- class sympy.series.formal.FormalPowerSeries(*args)[source]¶
Represents Formal Power Series of a function.
Explanation
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
- coeff_bell(n)[source]¶
self.coeff_bell(n) returns a sequence of Bell polynomials of the second kind. Note that
n
should be a integer.The second kind of Bell polynomials (are sometimes called “partial” Bell polynomials or incomplete Bell polynomials) are defined as
\[B_{n,k}(x_1, x_2,\dotsc x_{n-k+1}) = \sum_{j_1+j_2+j_2+\dotsb=k \atop j_1+2j_2+3j_2+\dotsb=n} \frac{n!}{j_1!j_2!\dotsb j_{n-k+1}!} \left(\frac{x_1}{1!} \right)^{j_1} \left(\frac{x_2}{2!} \right)^{j_2} \dotsb \left(\frac{x_{n-k+1}}{(n-k+1)!} \right) ^{j_{n-k+1}}.\]bell(n, k, (x1, x2, ...))
gives Bell polynomials of the second kind, \(B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})\).
- compose(other, x=None, n=6)[source]¶
Returns the truncated terms of the formal power series of the composed function, up to specified
n
.- Parameters:
n : Number, optional
Specifies the order of the term up to which the polynomial should be truncated.
Explanation
If
f
andg
are two formal power series of two different functions, then the coefficient sequenceak
of the composed formal power series \(fp\) will be as follows.\[\sum\limits_{k=0}^{n} b_k B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})\]Examples
>>> from sympy import fps, sin, exp >>> from sympy.abc import x >>> f1 = fps(exp(x)) >>> f2 = fps(sin(x))
>>> f1.compose(f2, x).truncate() 1 + x + x**2/2 - x**4/8 - x**5/15 + O(x**6)
>>> f1.compose(f2, x).truncate(8) 1 + x + x**2/2 - x**4/8 - x**5/15 - x**6/240 + x**7/90 + O(x**8)
References
[R824]Comtet, Louis: Advanced combinatorics; the art of finite and infinite expansions. Reidel, 1974.
- property infinite¶
Returns an infinite representation of the series
- integrate(x=None, **kwargs)[source]¶
Integrate Formal Power Series.
Examples
>>> from sympy import fps, sin, integrate >>> from sympy.abc import x >>> f = fps(sin(x)) >>> f.integrate(x).truncate() -1 + x**2/2 - x**4/24 + O(x**6) >>> integrate(f, (x, 0, 1)) 1 - cos(1)
- inverse(x=None, n=6)[source]¶
Returns the truncated terms of the inverse of the formal power series, up to specified
n
.- Parameters:
n : Number, optional
Specifies the order of the term up to which the polynomial should be truncated.
Explanation
If
f
andg
are two formal power series of two different functions, then the coefficient sequenceak
of the composed formal power seriesfp
will be as follows.\[\sum\limits_{k=0}^{n} (-1)^{k} x_0^{-k-1} B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1})\]Examples
>>> from sympy import fps, exp, cos >>> from sympy.abc import x >>> f1 = fps(exp(x)) >>> f2 = fps(cos(x))
>>> f1.inverse(x).truncate() 1 - x + x**2/2 - x**3/6 + x**4/24 - x**5/120 + O(x**6)
>>> f2.inverse(x).truncate(8) 1 + x**2/2 + 5*x**4/24 + 61*x**6/720 + O(x**8)
References
[R825]Comtet, Louis: Advanced combinatorics; the art of finite and infinite expansions. Reidel, 1974.
- polynomial(n=6)[source]¶
Truncated series as polynomial.
Explanation
Returns series expansion of
f
upto orderO(x**n)
as a polynomial(withoutO
term).
- product(other, x=None, n=6)[source]¶
Multiplies two Formal Power Series, using discrete convolution and return the truncated terms upto specified order.
- Parameters:
n : Number, optional
Specifies the order of the term up to which the polynomial should be truncated.
Examples
>>> from sympy import fps, sin, exp >>> from sympy.abc import x >>> f1 = fps(sin(x)) >>> f2 = fps(exp(x))
>>> f1.product(f2, x).truncate(4) x + x**2 + x**3/3 + O(x**4)
- 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
.- 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.
Explanation
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.Examples
>>> from sympy import fps, ln, atan, sin >>> from sympy.abc import x, n
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)
Symbolic Functions
>>> fps(x**n*sin(x**2), x).truncate(8) -x**(n + 6)/6 + x**(n + 2) + O(x**(n + 8))
- 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.
- 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.
Explanation
Tries to compute the formula by applying the following techniques (in order):
rational_algorithm
Hypergeometric algorithm
- class sympy.series.formal.FormalPowerSeriesCompose(*args)[source]¶
Represents the composed formal power series of two functions.
Explanation
No computation is performed. Terms are calculated using a term by term logic, instead of a point by point logic.
There are two differences between a
FormalPowerSeries
object and aFormalPowerSeriesCompose
object. The first argument contains the outer function and the inner function involved in the omposition. Also, the coefficient sequence contains the generic sequence which is to be multiplied by a custombell_seq
finite sequence. The finite terms will then be added up to get the final terms.- property function¶
Function for the composed formal power series.
- class sympy.series.formal.FormalPowerSeriesInverse(*args)[source]¶
Represents the Inverse of a formal power series.
Explanation
No computation is performed. Terms are calculated using a term by term logic, instead of a point by point logic.
There is a single difference between a
FormalPowerSeries
object and aFormalPowerSeriesInverse
object. The coefficient sequence contains the generic sequence which is to be multiplied by a custombell_seq
finite sequence. The finite terms will then be added up to get the final terms.- property function¶
Function for the inverse of a formal power series.
- class sympy.series.formal.FormalPowerSeriesProduct(*args)[source]¶
Represents the product of two formal power series of two functions.
Explanation
No computation is performed. Terms are calculated using a term by term logic, instead of a point by point logic.
There are two differences between a
FormalPowerSeries
object and aFormalPowerSeriesProduct
object. The first argument contains the two functions involved in the product. Also, the coefficient sequence contains both the coefficient sequence of the formal power series of the involved functions.- property function¶
Function of the product of two formal power series.
- class sympy.series.formal.FiniteFormalPowerSeries(*args)[source]¶
Base Class for Product, Compose and Inverse classes
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.
- Parameters:
x : Symbol
order : int, optional
Order of the derivative of
f
, Default is 4.full : bool
- Returns:
formula : Expr
ind : Expr
Independent terms.
order : int
full : bool
Explanation
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 overridden using order option.
Examples
>>> from sympy import log, atan >>> 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/((-1)**k*k), 0, 1)
>>> ra(atan(x), x, k, full=True) ((-I/(2*(-I)**k) + I/(2*I**k))/k, 0, 1)
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 significantly slow down the computation asdoit
is performed on theRootSum
object returned by theapart()
function. Usefull=False
whenever possible.See also
References
Hypergeometric Algorithm¶
- sympy.series.formal.simpleDE(f, x, g, order=4)[source]¶
Generates simple DE.
Explanation
DE is of the form
\[f^k(x) + \sum\limits_{j=0}^{k-1} 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.
Explanation
Performs the substitution:
\[f^j(x) \to r(k + j)\]Normalises the terms so that lowest order of a term is always r(k).
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, 2)), r, k) r(k) + r(k + 1)
See also
- sympy.series.formal.hyper_re(DE, r, k)[source]¶
Converts a DE into a RE.
Explanation
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).
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, 2)), r, k) (k + 2)*(k + 3)*r(k + 3) - r(k)
See also
- sympy.series.formal.rsolve_hypergeometric(f, x, P, Q, k, m)[source]¶
Solves RE of hypergeometric type.
- Returns:
formula : Expr
ind : Expr
Independent terms.
order : int
Explanation
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.
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)
References
- sympy.series.formal.solve_de(f, x, DE, order, g, k)[source]¶
Solves the DE.
- Returns:
formula : Expr
ind : Expr
Independent terms.
order : int
Explanation
Tries to solve DE by either converting into a RE containing two terms or converting into a DE having constant coefficients.
Examples
>>> from sympy import Derivative as D, Function >>> from sympy import exp, ln >>> from sympy.series.formal import solve_de >>> from sympy.abc import x, k >>> f = Function('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.
Explanation
- 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)