# How to replace variable in result of Series? [closed]

I am trying to replace $$\text{xn}$$ in

$$\qquad O(\epsilon )^3+\left(\text{xn}^2+2 \text{xn}\right) \epsilon +\left(-2 \text{xn}^3-4 \text{xn}^2\right) \epsilon ^2-1$$

with $$O(\epsilon )^2+\epsilon +1$$.

I want an output like a simplified series of $$\epsilon$$: $$-1+3 \epsilon -2 \epsilon ^2+O\left(\epsilon ^3\right)$$.

When I evaluate

-1+(2 xn + xn^2) ϵ + (-4 xn^2 - 2 xn^3) ϵ^2 + O[ϵ]^3 /. xn -> 1 + ϵ + O[ϵ]^2


I get

and Simplify doesn't work on this output.

The solution I am using now applies Normal then adds the O[ϵ]^3.

temp = -1 + (2 xn + xn^2) ϵ + (-4 xn^2 - 2 xn^3) ϵ^2 + O[ϵ]^3
Normal[temp /. xn -> 1 + ϵ + O[ϵ]^2] + O[ϵ]^temp[[5]]


I'd to know is there a more efficient way to solve this problem.

• temp /. xn -> 1 + \[Epsilon] seems to give what you seek. Is that correct? – Michael E2 Jul 29 '19 at 18:37
• In MMA v11.0.1 temp /. xn -> 1 + \[Epsilon] + O[\[Epsilon]]^2 does the job as expected! – Ulrich Neumann Jul 30 '19 at 6:44
• my version is MMA v11.1, and temp /. xn -> 1 + [Epsilon] + O[[Epsilon]]^2, temp /. xn -> 1 + [Epsilon] give the output $-1+\epsilon \left(3+4 \epsilon +O\left(\epsilon ^2\right)\right)+\epsilon ^2 \left(-6-14 \epsilon +O\left(\epsilon ^2\right)\right)+O\left(\epsilon ^3\right)$ which is not i expected. – Leon.D Jul 30 '19 at 22:57
• I get what you expected: see i.stack.imgur.com/iWoMn.png (I'm using V12.0, but the behavior of SeriesData has been stable through several version, I think. Perhaps try restarting your kernel) -- Site tip: Use @user to be sure a user is notified of your reply (e.g. @MichaelE2 or @UlrichNeuman); the author of a post (you in this case) is always notified of comments on the post. Also if you put code between backticks in a comment, it will be formatted properly. – Michael E2 Jul 31 '19 at 15:05
• This might be from a buglet that will be addressed in the next release. I believe it was reported a few months ago in this forum but I cannot seem to find the right thread. – Daniel Lichtblau Aug 3 '19 at 19:20