Coverage for /usr/lib/python3/dist-packages/sympy/series/series.py: 50%
4 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1from sympy.core.sympify import sympify
4def series(expr, x=None, x0=0, n=6, dir="+"):
5 """Series expansion of expr around point `x = x0`.
7 Parameters
8 ==========
10 expr : Expression
11 The expression whose series is to be expanded.
13 x : Symbol
14 It is the variable of the expression to be calculated.
16 x0 : Value
17 The value around which ``x`` is calculated. Can be any value
18 from ``-oo`` to ``oo``.
20 n : Value
21 The number of terms upto which the series is to be expanded.
23 dir : String, optional
24 The series-expansion can be bi-directional. If ``dir="+"``,
25 then (x->x0+). If ``dir="-", then (x->x0-). For infinite
26 ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined
27 from the direction of the infinity (i.e., ``dir="-"`` for
28 ``oo``).
30 Examples
31 ========
33 >>> from sympy import series, tan, oo
34 >>> from sympy.abc import x
35 >>> f = tan(x)
36 >>> series(f, x, 2, 6, "+")
37 tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +
38 (x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +
39 5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +
40 2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))
42 >>> series(f, x, 2, 3, "-")
43 tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))
44 + O((x - 2)**3, (x, 2))
46 >>> series(f, x, 2, oo, "+")
47 Traceback (most recent call last):
48 ...
49 TypeError: 'Infinity' object cannot be interpreted as an integer
51 Returns
52 =======
54 Expr
55 Series expansion of the expression about x0
57 See Also
58 ========
60 sympy.core.expr.Expr.series: See the docstring of Expr.series() for complete details of this wrapper.
61 """
62 expr = sympify(expr)
63 return expr.series(x, x0, n, dir)