# Series expansion: taylor series

### 5.36.2 Series expansion: taylor series

The taylor command finds Taylor expansions.
series is a synonym for taylor.

- taylor takes one mandatory and four optional arguments:
  - expr, an expression depending on a variable.
  - Optionally, x, the variable (by default x).
  - Optionally n, an integer, the order of the series expansion (by default 5).
  - Optionally, a, the center of the Taylor expansion (by default 0). This can be combined with the optional x by replacing x by x=a.
  - dir, a direction, which can be -1 or 1, for unidirectional series expansion, or 0 (for bidirectional series expansion) (by default 0).
- taylor(expr,x ⟨,a,ndir⟩) returns the Taylor expansion of expr about a or order n; consisting of a polynomial in x−a plus a remainder of the form of the form:
  (x−a)^n * order_size(x−a)
  where order_size is a function such that,

  ∀ r>0,

  lim
  x→ 0

  xr order_size(x) = 0

For regular series expansion, order_size is a bounded function, but for non regular series expansion, it might tend slowly to infinity, for example like a power of ln(x).

#### Example.

Input:

taylor(sin(x),x=1,2)

or:

series(sin(x),x=1,2)

or (be careful with the order of the arguments!):

taylor(sin(x),x,2,1)

or:

series(sin(x),x,2,1)

Output:

sin

⎛
⎝

1

⎞
⎠

+cos

⎛
⎝

1

⎞
⎠

⎛
⎝

x−1

⎞
⎠

−

1
2

sin

⎛
⎝

1

⎞
⎠

⎛
⎝

x−1

⎞
⎠

2+

⎛
⎝

x−1

⎞
⎠

3 order_size

⎛
⎝

x−1

⎞
⎠

Remark.
The order returned by taylor may be smaller than n if cancellations between numerator and denominator occur, for example consider

x3+sin(x)3
x−sin(x)

Input:

taylor(x^3+sin(x)^3/(x-sin(x)),x=0,5)

Output:

6−

27
10

x2+x3+

711
1400

x4+x6 order_size

⎛
⎝

x

⎞
⎠

6+-27/10*x^2+x^3*order_size(x)

which is only a 2nd degree expansion. Indeed the numerator and denominator valuation is 3, hence you lose 3 orders. To get order 4, you should use n=7.
Input:

taylor(x^3+sin(x)^3/(x-sin(x)),x=0,7)

Output:

6−

27
10

x2+x3+

711
1400

x4−

737
14000

x6+x8 order_size

⎛
⎝

x

⎞
⎠

6+-27/10*x^2+x^3+711/1400*x^4+x^5*order_size(x)

a fourth degree expansion.

#### Examples.

- Find a 4th-order expansion of cos(2x)2 in the vicinity of x=π/6.
  Input:
  taylor(cos(2*x)^2,x=pi/6, 4)
  Output:

  1
  4

  −

  √

  3

  ⎛
  ⎜
  ⎜
  ⎝

  x−

  π
  6

  ⎞
  ⎟
  ⎟
  ⎠

  +2

  ⎛
  ⎜
  ⎜
  ⎝

  x−

  π
  6

  ⎞
  ⎟
  ⎟
  ⎠

  2

  +

  8
  3

  √

  3

  ⎛
  ⎜
  ⎜
  ⎝

  x−

  π
  6

  ⎞
  ⎟
  ⎟
  ⎠

  3

  −

  8
  3

  ⎛
  ⎜
  ⎜
  ⎝

  x−

  π
  6

  ⎞
  ⎟
  ⎟
  ⎠

  4

  +

  ⎛
  ⎜
  ⎜
  ⎝

  x−

  π
  6

  ⎞
  ⎟
  ⎟
  ⎠

  5

  order_size

  ⎛
  ⎜
  ⎜
  ⎝

  x−

  π
  6

  ⎞
  ⎟
  ⎟
  ⎠

- Find a 5th-order series expansion of arctan(x) in the vicinity of x=+∞.
  Input:
  series(atan(x),x=+infinity,5)
  Output:

  π
  2

  −

  1
  x

  +

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  3

  3

  −

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  5

  5

  +

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  6

  order_size

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  Note that the expansion variable and the argument of the order_size function is h=1/x →x→ + ∞ 0 .
- Find a 2nd-order expansion of (2x−1)e1/x−1 in the vicinity of x=+∞.
  Input:
  series((2*x-1)*exp(1/(x-1)),x=+infinity,3)
  Output (only a 1st-order series expansion):

  2

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  −1

  +1+

  2
  x

  +

  17
  6

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  2

  +

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  3

  order_size

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  Note that this is only a 1st order expansion. To get a 2nd-order series expansion in 1/x:
  Input:
  series((2*x-1)*exp(1/(x-1)),x=+infinity,4)
  Output:

  2

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  −1

  +1+

  2
  x

  +

  17
  6

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  2

  +

  47
  12

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  3

  +

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  4

  order_size

  ⎛
  ⎜
  ⎜
  ⎝

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

- Find a 2nd-order series expansion of (2x−1)e1/x−1 in the vicinity of x=-∞.
  Input:
  series((2*x-1)*exp(1/(x-1)),x=-infinity,4)
  Output:

  −2

  ⎛
  ⎜
  ⎜
  ⎝

  −

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  −1

  +1+

  2
  x

  +

  17
  6

  ⎛
  ⎜
  ⎜
  ⎝

  −

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  2

  −

  47
  12

  ⎛
  ⎜
  ⎜
  ⎝

  −

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  3

  +

  ⎛
  ⎜
  ⎜
  ⎝

  −

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

  4

  order_size

  ⎛
  ⎜
  ⎜
  ⎝

  −

  1
  x

  ⎞
  ⎟
  ⎟
  ⎠

- Find a 2nd-order series expansion of (1+x)1/x/x3 in the vicinity of x=0+.
  Input:
  series((1+x)^(1/x)/x^3,x=0,2,1)
  (Note that this is a one-sided series expansion, since dir=1.) Output:

  e x−3−

  1
  2

  e x−2+x−1 order_size

  ⎛
  ⎝

  x

  ⎞
  ⎠