# Get interval of series

It seems to be a stupid question but I wonder how to get an interval of a series expansion. The current series command

Series[f, {x, x0, n}]


only give series expansion up to $x^n$, where I want something like

Series[f, {x, x0, h, t}]


which gives me the series expansion from $x^h$ to $x^t$. Obviously I can get it by doing

Series[f, {x, x0, t}] - Series[f, {x, x0, h-1}]


However, I believe that it takes longer time than it should take.

-
Differencing will give you O[x]^h. You must remove the big O term to take the difference. –  tchronis Nov 27 '13 at 8:14

I will use the function Exp[x] to demonstrate in a simple way how you can do it.

If you try FullForm[Series[Exp[x], {x, x0, 5}]] you will get

SeriesData[x,x0,List[Power[E,x0], Power[E,x0], Times[ Rational[1,2], Power[E,x0]],
Times[ Rational[1,6], Power[E,x0]],Times[ Rational[1,24],Power[E,x0]],
Times[ Rational[1,120], Power[E,x0]]],0,6,1]


which you can decompose taking parts. Some series as well mentioned by @Michael E2 begin with higher powers and the is stated as a 4th argument in the FullForm (nmin in the code below).

Update (thanks @KennyColnago and @Michael E2)

seriespart[f_, {x_, x0_, h_, t_}] := Module[{s, nmin},
s = Series[f, {x, x0, t}];
nmin = s[[4]];
s[[3, (h - nmin + 1) ;; (t - nmin + 1)]].Table[(x - x0)^i, {i, h, t}]
]


h and t must be positive integers with t >= h and h >= 0.

So seriespart gives

seriespart[Exp[x], {x, 1, 5, 9}]

1/120 E (-1 + x)^5 + 1/720 E (-1 + x)^6 + (E (-1 + x)^7)/5040 +
(E (-1 + x)^8)/40320 + (E (-1 + x)^9)/362880


as wanted.

-
@Artes thanks for your edit. It is a lot nicer now. –  tchronis Nov 27 '13 at 15:18
@Artes yes you are right i had left f[x] instead of just f. I fixed it , thanks. Your method works but it needs adjustment on the lower degree - it doesn't output the x^3 term. –  tchronis Nov 27 '13 at 16:32
Are not the powers of (x-x0) in seriespart one more than they should be? In the Table command try (x-x0)^(i-1). –  KennyColnago Nov 27 '13 at 16:35
@KennyColnago , in Loi.Luu's original question he asked the series expansion from x^h to x^t so i fixed it that way. –  tchronis Nov 27 '13 at 17:03
To put KennyCoinago's comment another way, the coefficients in your example do not agree with the coefficients in Series[Exp[x], {x, 1, 9}] -- shouldn't they? Also this gives errors: seriespart[x^2 Exp[x], {x, 0, 5, 9}]. –  Michael E2 Nov 29 '13 at 13:16

The built-inSeriesCoefficientis useful to give directly the desired expansion coefficient, for not too complicated functionsf[x].

ExpandSeries[f_, {x0_, h_, t_}] :=
With[{s=SeriesCoefficient[f, {x, x0, n}, Assumptions :> n>=0], r=Range[h, t]},
(s /. n -> r).(x - x0)^r]


Try

Expand[ExpandSeries[x / (1 - x - x^2), {0, 8, 13}]]


to see some familiar terms.

-

(Updated to handle fractional powers)

Here's another way to take advantage of SeriesData. The data has the format

SeriesData[x, x0, {a0, a1,...}, min, max, den]


The coefficient a0 corresponds to the power (x - x0)^(min/den), a1 to the power (x - x0)^((min+1)/den), etc. To get the terms from some point start, drop the initial coefficients and change the min power.

seriesTail[f_, {x_, x0_, start_, end_}] :=
With[{s = Series[f, {x, x0, end}]}, seriesTail[s, start, end]];
seriesTail[sd : SeriesData[x_, x0_, coeffs_, min_, max_, den_], start_, end_] /;
start > min/den :=
SeriesData[x,
x0,
Drop[coeffs, Ceiling[start*den - min, den]],
min + Ceiling[start*den - min, den],
max,
den];
seriesTail[sd_SeriesData, start_, end_] := sd


Examples:

seriesTail[Exp[x], {x, 0, 5, 9}]


seriesTail[x^6 Exp[x], {x, 0, 5, 9}]


seriesTail[x/(1 - x - x^2), {x, 0, 3, 7}]


Another example (of updated code):

seriesTail[Sqrt[x] Exp[x], {x, 0, 5, 9}]


If you don't want the big-O part, use Normal @ seriesTail[f, {x, x0, start, end}].

-