# Replace variable in Series expression

I am trying to generate a series expansion in terms of the variable t then substitute a value in for it. However it seems that something about the SeriesData object returned by Series doesn't permit a standard slashdot replacement.

Series[(a^4 - (a - t)^4), {t, 0, 4}] // Normal /. t -> a/20


returns

4 a^3 t - 6 a^2 t^2 + 4 a t^3 - t^4


which is the same result as though the slashdot isn't even there.

On the other hand, replacing prior to Normal results in an undesirable output.

Series[a^4 - (a - t)^4 , {t, 0, i}] /. t -> a/20 // Normal


returns

(4 a^3 a)/20 - 6 a^2 (a/20)^2 + 4 a (a/20)^3 - (a/20)^4 + O[a/20]^6


This is on the right track, but I am left with the BigO and no amount of Simplify or its related functions can get the expression to condense to C*a^4.

To further complicate things, I am trying to run this within a For loop where I increment the number of kept terms.

For[i = 1, i <= 4, i++,
Print[Series[a^4 - (a - t)^4), {t, 0, i}] // Normal /. t -> a/20]]


So, how can I do the Series expansion, substitute a/20 in for t, and get a nice output that is, ideally, some constant times a^4. Much thanks.

• Normal@Series[(a^4 - (a - t)^4), {t, 0, 4}] /. t -> a/20. Operator precedence. in other words, implicitly, your original expression is interpreted like this: Series[(a^4 - (a - t)^4), {t, 0, 4}] // (Normal /. t -> a/20). Commented Sep 20, 2017 at 22:00
• That's a notation with which I am unfamiliar. But thank you. Commented Sep 20, 2017 at 22:05

(As march beat me to comment) I think you have a precedence problem with the postfix application //. Try this:

(Series[(a^4 - (a - t)^4), {t, 0, 4}] // Normal) /. t -> a/20

(29679 a^4)/160000

• Unbelievable. So that I fully understand and never repeat this mistake: Without the parenthesis, Mathematica is trying to do the replacement within Normal itself? Commented Sep 20, 2017 at 22:09
• @saintsfan342000 Yes! I realize this is probably annoying but it follows from standard precedence rules. This is actually useful in other cases, once you know to expect it. Commented Sep 20, 2017 at 22:37
• @Mr.Wizard From a software design standpoint I find this precedence choice to be a flaw. On no occasion have I ever wanted to do a replacement only on the suffixed function; I always want to replace on the entire thing to the left. Do you know why it is designed this way? Commented Sep 21, 2017 at 0:19
• @QuantumDot I am very tired from exercise and probably not thinking at my best. However if I am not mistaken the explanation is easy: each operator only has one binding power, i.e. the left and right sides are treated similarly. (continued) Commented Sep 21, 2017 at 6:39
• If /. had a lower binding power then things like {1, 2, 3} /. {2 -> 7} // Print would group like {1, 2, 3} /. ({2 -> 7} // Print) which is totally undesirable in most cases in my experience. // is specifically useful because of its low binding power allowing most things on the left-hand-side to "stay together." That the right hand side, e.g. // Normal /. t -> a/20 is also grouped together is merely an unfortunate consequence, though this too can at least occasionally be exploited usefully. Commented Sep 21, 2017 at 6:39