# How can I make Mathematica return a series expansion in the form $\sum_{j=0}^\infty \dots$ instead of $a_0 + a_1x^1 + \dots + a_{n-1}x^{n-1}+ O(x^n)$

I have a function $$\phi(x) = \sqrt{(x-t)^2 + c^2},$$ and I want an asymptotic expression for it as $x \to \infty$.

Using the following code I can calculated such an expression:

Series[Sqrt[c^2 + (t - x)^2], {x, Infinity, 4}]


and the result is $$x-t+c^2/(2 x)+(c^2 t)/(2 x^2)+(-(c^4/8)+(c^2 t^2)/2)/x^3+(-((3 c^4 t)/8)+(c^2 t^3)/2)/x^4+O[1/x]^5$$

However I don't want the answer to be expressed as several terms up to some order. I want it it to be expressed as a summation formula. Mathematica obviously has calculated this formula as it is using it to give me back the function up to a certain order. How can I make it return the actual summation formula? That is, how can I make it give me back the expression in the form?

$\sum_{j=0}^\infty \dots$

• I have an answer in the Form of a DifferenceRoot. It evaluates to rather large formulas for concrete n's. But i can show it if you want. (But I don't think, this will help you) – Julien Kluge Apr 2 '17 at 12:52
• @JulienKluge How do you obtain the DifferenceRoot answer? I can obtain that for expansion about 0 but not for expansion about Infinity. – bbgodfrey Apr 2 '17 at 12:55
• Ah sorry I made a mistake in my code. It now returns a Indeterminate...it fails to do the Limit of a general DifferenceRoot answer obtained by the new MMA11.1 feature to make parameterized multiple derivatives. – Julien Kluge Apr 2 '17 at 13:04
• @bbgodfrey SeriesCoefficient[Sqrt[c^2 + (u)^2], {u, Infinity, n}] returns a formula (binomial series). Not equivalent, but perhaps useful. – Michael E2 Apr 2 '17 at 13:10
• @bbgodfrey Yep, they seemed to have messed the formula up. This seems correct: SeriesCoefficient[Sqrt[1 + y], {y, 0, n}], and you can get the u series with y == c^2/u^2 and multiplying the y series by u. – Michael E2 Apr 2 '17 at 16:00

The following result is based on comments above exchanged between Michael E2 and me. Because

SeriesCoefficient[Sqrt[(x - t)^2 + c^2], {x, Infinity, n}]


returns unevaluated, and

SeriesCoefficient[Sqrt[u^2 + c^2], {u, Infinity, n}]
(* Piecewise[{{(c^2)^((1 + n)/2)*Binomial[1/2, -n/2], Mod[n, -2] == 0 && n <= 0}}, 0] *)


is manifestly incorrect (i.e., a bug), begin instead with

SeriesCoefficient[Sqrt[1 + z], {z, 0, n}];
s1 = %[[1, 1, 1]] (x - t) (c/(x - t))^(2 n)
(* (c/(-t + x))^(2 n) (-t + x) Binomial[1/2, n] *)


To test the correctness of this result, perform

Sum[s1, {n, 0, Infinity}] // Simplify
(* Sqrt[1 + c^2/(t - x)^2] (-t + x) *)


which is correct. However, it is not the desired result, because the terms are functions of x - t instead of x. So, expand s1 in t.

SeriesCoefficient[(t - x)^(1 - 2 n), {t, 0, m}, Assumptions -> n >= 0];
s2 = Simplify[%[[1, 1, 1]] s1 (t - x)^-(1 - 2 n), x - t > 0 && n ∈ Integers] t^m
(* c^(2 n) t^m (-x)^(-m - 2 n) x Binomial[1/2, n] Binomial[1 - 2 n, m] *)


Again, a test produces the correct result.

Sum[s2, {n, 0, Infinity}, {m, 0, Infinity}] // Simplify
(* Sqrt[1 + c^2/(t - x)^2] (-t + x) *)


Finally, all terms of a given order in x^-j must be summed to obtain the desired result. Doing so yields

f[j_] = Piecewise[{{x - t, j == 0}, {Sum[If[Mod[j + 1 - m, 2] == 0,
s2 /. x -> 1 /. n -> (j + 1 - m)/2, 0], {m, 0, j}] x^-j, j > 0}}];


To test its accuracy, compare it with the series expansion provided in the question.

Series[Sqrt[c^2 + (t - x)^2], {x, Infinity, 5}] // Normal
(* -t + (c^6 - 12 c^4 t^2 + 8 c^2 t^4)/(16 x^5) + (-3 c^4 t + 4 c^2 t^3)/(8 x^4) +
(-c^4 + 4 c^2 t^2)/(8 x^3) + (c^2 t)/(2 x^2) + c^2/(2 x) + x *)
FullSimplify[Sum[f[j], {j, 0, 5}] == %]
(* True *)


Thus, the sum of f[j] is the desired result.

All calculations were performed with

$Version (* 11.1.0 for Microsoft Windows (64-bit) (March 13, 2017) *)  • But I don't want it expanded out. For example consider$g(x) = a + ax + ax^2 + ax^3 + \cdots$- I need Mathematica to give me this series in the form$g(x) = \sum_{k=0}^{n-1}ax^k$. That is what my question is about. Can this be done? – eurocoder Apr 20 '17 at 13:05 • @eurocoder Each of the answers gives an expression for a term in the series, which then can be summed. In this case, the sum is Sum[f[j], {j, 0, Infinity}]. – bbgodfrey Apr 20 '17 at 14:14 • Excellent, it outputs an actual summation expression cheers! These summations are giving me serious trouble..if you get a chance maybe you could take a look at my latest issue - mathematica.stackexchange.com/questions/144096/… – eurocoder Apr 20 '17 at 19:17 SeriesCoefficient will work if one adjusts the expression so that it is finite as x->Infinity. So: nthTerm = SeriesCoefficient[Sqrt[c^2+(t-x)^2]/x,{x,Infinity,n},Assumptions->n>=0]; nthTerm //InputForm (* DifferenceRoot[Function[{\[FormalY], \[FormalN]}, {(-1 + \[FormalN])*(c^2 + t^2)*\[FormalY][\[FormalN]] + (-t - 2*\[FormalN]*t)*\[FormalY][1 + \[FormalN]] + (2 + \[FormalN])*\[FormalY][2 + \[FormalN]] == 0, \[FormalY][0] == 1, \[FormalY][1] == -t}]][n] *)  Hence, the desired sum is: sum[t_] := Inactive[Sum][nthTerm x^(1-n), {n, 0, t}] sum[Infinity] //InputForm (* Inactive[Sum][x^(1 - n)*DifferenceRoot[Function[{\[FormalY], \[FormalN]}, {(-1 + \[FormalN])*(c^2 + t^2)*\[FormalY][\[FormalN]] + (-t - 2*\[FormalN]*t)*\[FormalY][1 + \[FormalN]] + (2 + \[FormalN])*\[FormalY][2 + \[FormalN]] == 0, \[FormalY][0] == 1, \[FormalY][1] == -t}]][n], {n, 0, Infinity}] *)  Check: Series[expr, {x, Infinity, 5}]//TeXForm $x-t+\frac{c^2}{2 x}+\frac{c^2 t}{2 x^2}+\frac{4 c^2 t^2-c^4}{8 x^3}+\frac{4 c^2 t^3-3 c^4 t}{8 x^4}+\frac{c^6-12 c^4 t^2+8 c^2 t^4}{16 x^5}+O\left(\left(\frac{1}{x}\right)^6\right)$Series[Activate@sum[6], {x, Infinity, 5}]//TeXForm $x-t+\frac{c^2}{2 x}+\frac{c^2 t}{2 x^2}+\frac{\frac{c^2 t^2}{2}-\frac{c^4}{8}}{x^3}+\frac{\frac{c^2 t^3}{2}-\frac{3 c^4 t}{8}}{x^4}+\frac{c^6-12 c^4 t^2+8 c^2 t^4}{16 x^5}+O\left(\left(\frac{1}{x}\right)^6\right)\$

• Executing the first line of your answer (with version 11.1 on Windows 10), I do not obtain the same expression for the DifferenceRoot. Specifically, the initial conditions within the DifferenceRoot that I obtain are \[FormalY][0] == 0, \[FormalY][1] == 0. As a consequence, DifferenceRoot evaluates to zero for all n. What version of Mathematica are you using? – bbgodfrey Apr 3 '17 at 6:02
• @bbgodfrey Maybe you have some lingering definitions? I get the above result in M9, M10.3.1 and some developmental version of M11.1. – Carl Woll Apr 3 '17 at 7:26
• I can reproduce your result with 10.4.1 but not with 11.1, both on Windows 10 (64 bit). In each case I rebooted my computer before running a fresh session of Mathematica, and the line of code in question was the first line of the notebook. I do not doubt your answer, which is excellent (+1), but I do suspect a bug in 11.1. – bbgodfrey Apr 3 '17 at 13:04
• The same is not true of the bug that @MichaelE2 and I identified in our comments above. It occurs for both 10.4.1 and 11.1. Just now, I also ran SeriesCoefficient[Sqrt[c^2 + (u)^2]/u, {u, Infinity, n}], patterned after your answer, but the incorrect answer persisted. – bbgodfrey Apr 3 '17 at 13:14
• @MichaelE2, Carl Woll - I have reported these issues to Wolfram, Inc as CASE:3873213. It is not clear to me that the question should be tagged as "bugs", however, because it is not central to the issues reported. – bbgodfrey Apr 3 '17 at 23:48

Still another approach is to use FindSequenceFunction, which should work whenever the series coefficients satisfy a recurrence relation that is not too complicated. Begin by obtaining the list of coefficients of the series.

coef = Series[Sqrt[c^2 + (t - x)^2], {x, Infinity, 8}][[3]]
(* {1, -t, c^2/2, (c^2 t)/2, 1/8 (-c^4 + 4 c^2 t^2), 1/8 (-3 c^4 t + 4 c^2 t^3),
1/16 (c^6 - 12 c^4 t^2 + 8 c^2 t^4), 1/16 (5 c^6 t - 20 c^4 t^3 + 8 c^2 t^5),
1/128 (-5 c^8 + 120 c^6 t^2 - 240 c^4 t^4 + 64 c^2 t^6),
1/128 (-35 c^8 t + 280 c^6 t^3 - 336 c^4 t^5 + 64 c^2 t^7)} *)


Then apply FindSequenceFunction and, since the result is a DifferenceRoot, discard any superfluous initial conditions.

FindSequenceFunction[coef];
ReplacePart[%, {1, 2} -> %[[1, 2, 1 ;; 3]]]
(* DifferenceRoot[Function[{\[FormalY], \[FormalN]}, {(-2 + \[FormalN]) (c^2 + t^2)
\[FormalY][\[FormalN]] + (t - 2 \[FormalN] t) \[FormalY][1 + \[FormalN]]
+ (1 + \[FormalN]) \[FormalY][2 + \[FormalN]] == 0,
\[FormalY][1] == 1, \[FormalY][2] == -t}]] *)


Not surprisingly, this result is equivalent to that in the earlier answer by Carl Woll. It is validated by

Simplify[Table[%[n], {n, 10}] == coef]
(* True *)