# Replace expression in series expansion [duplicate]

This question already has an answer here:

A test case:

I'm trying to replace an expression inside a series expansion:

Series[f[x],{x,x0,4}] ./ (x-x0)->h


but it still returns

f[x0]+f'[x0](x-x0)+.....


What am I screwing up here?

## marked as duplicate by Artes, m_goldberg, bbgodfrey, Mr.Wizard♦Feb 12 '15 at 8:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• Related: (71542) – Mr.Wizard Feb 11 '15 at 21:55
• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Feb 11 '15 at 22:07

## 2 Answers

Here is something which works:

Normal@Series[f[x], {x, x0, 4}] /. (x - x0) -> h


The reason your attempt doesn't work can be determined by examining the FullForm:

FullForm@Series[f[x], {x, x0, 4}]

(*SeriesData[x, x0,
List[f[x0], Derivative[f][x0],
Times[Rational[1, 2], Derivative[f][x0]],
Times[Rational[1, 6], Derivative[f][x0]],
Times[Rational[1, 24], Derivative[f][x0]]], 0, 5, 1]*)


Series returns a SeriesData object which doesn't look anything like what the display output looks like (as can be seen from above), and applying (x - x0) -> h doesn't change anything because there is no (x - x0) expression inside of the above expression.

Applying Normal converts the SeriesData object into a normal-looking expression, which then gets substituted using the rule (x - x0) -> h, giving what you want.

Not the safest way:

s = Series[f[x], {x, x0, 4}];
s[] = x - h;
s // Normal


$\frac{1}{24} h^4 f^{(4)}(\text{x0})+\frac{1}{6} h^3 f^{(3)}(\text{x0})+\frac{1}{2} h^2 f''(\text{x0})+h f'(\text{x0})+f(\text{x0})$