I am having a lot of trouble working with summations in Mathematica, and this is unfortunate as it is my main use case for the application My latest summation issue is the following. I am trying to determine a summation expression of the form: $$f(x) = \sum_{j=0}^\infty \cdots$$ for the function $$f(x) = (y-x)^k \log(y-x),$$ where $x$ is expanded around $0$ and $k$ is an integer that is greater than or equal to $1$.

My code is as follows:

expr = Series[(y - x)^k*Log[y - x], {x, 0, 5}] // Normal

I attempted to use this code as it was suggested in a previous question. I believe the first line determines the summation and the second line puts it in the required form. However it doesn't work and I get the following output (which I have truncated at second order):

Out[1]: y^j Log[y]-x y^(-1+j) (1+j Log[y])+1/2 x^2 y^(-2+j) (-1+2 j-j Log[y]+j^2 Log[y])

Out[2]: toΣ[y^j Log[y]-x y^(-1+j) (1+j Log[y])+1/2 x^2 y^(-2+j) (-1+2 j-j Log[y]+j^2 Log[y])]

So what can I do to convert this expression into a clear and concise representation of the following form: $$f(x) = \sum_{j=0}^\infty \cdots$$

  • $\begingroup$ Your results suggest that you have not defined toΣ. However, note that toΣ relies on FindSequenceFunction, which is returning unevaluated. In general, FindSequenceFunction only works for fairly simple sequences, which this is not. $\endgroup$
    – bbgodfrey
    Commented Apr 20, 2017 at 19:32
  • $\begingroup$ See my alternative answer. $\endgroup$ Commented Jan 16, 2018 at 12:45

2 Answers 2


Complete rewrite of answer

The expression to be expanded as a series is the argument of

ser = Series[(y - x)^k*Log[y - x], {x, 0, 5}]

I attempted to obtain the result in an earlier version of this answer by means of SeriesCoefficient but obtain an incorrect result, because I failed specify that k is a nonnegative integer. The answer provided by Carl Woll in a comment below, which does specify k as a nonnegative integer, involves a DifferenceRoot that does not evaluate for n > 1. Here is a workaround. The Log and Power terms of the expression can be expanded separately and then combined as follows.

sc1 = SeriesCoefficient[(y - x)^k, {x, 0, n1}]
(* Piecewise[{{(-1)^n1*y^(k - n1)*Binomial[k, n1], n1 >= 0}}, 0] *)

sc2 = SeriesCoefficient[Log[y - x], {x, 0, n2}]
(* Piecewise[{{(-1)^(1 + n2)/(n2*(-y)^n2), n2 >= 1}, {Log[y], n2 == 0}}, 0] *)

The corresponding series coefficient of the product then is

c[n_] := Sum[sc1 sc2 /. n2 -> n - n1, {n1, 0, n}]

and Sum for the original expression is

Sum[c[n] x^n, {n, 0, Infinity}]

To test the validity of this expression, compare it with ser.

Simplify[Sum[c[n] x^n, {n, 0, 5}] == ser // Normal]
(* True *)

Note that Sum will try to recover the original expression, so it may be necessary to use Inactivate to prevent this, depending on how the Sum is to be used. (My thanks to MaTECmatica for suggesting that Inactivate is superior to Hold in this instance.)


The Sum in the formula for c can be performed symbolically, although the result is complicated.

innersum = FullSimplify[c[n], k >= 0 && k ∈ Integers && n >= 0 && n ∈ Integers];
innersum[[1, 1, 1]] = Simplify[innersum[[1, 1, 1]] /. n -> 0];
innersum[[1, 1, 2]] = n == 0; innersum
(* Piecewise[{{y^k*Log[y], n == 0}, {-(y^(-1 + k)*(1 + k*Log[y])), n == 1}}, 
   ((-1)^n*y^(-1 + k - n)*((1 + k - n)*y*Binomial[k, -1 + n]*(HarmonicNumber[k] - 
   HarmonicNumber[k - n]) + n*(y*Binomial[k, n]*Hypergeometric2F1[1, -k + n, 1 + n, y^(-1)]
   + Binomial[k, 1 + n]*Hypergeometric2F1[1, 1 - k + n, 2 + n, y^(-1)])*Log[y]))/n] *)

The second and third lines of code perform further simplification for n == 0.

  • 4
    $\begingroup$ Instead of Hold, the op might want to use Inactivate[Sum[c[n] x^n, {n, 0, Infinity}], Sum] so that c[n] is replaced in the expression without calculating the Sum $\endgroup$ Commented Apr 20, 2017 at 20:10
  • 1
    $\begingroup$ @MaTECmatica Excellent point. Thanks. $\endgroup$
    – bbgodfrey
    Commented Apr 20, 2017 at 20:20
  • 4
    $\begingroup$ I would use Assuming[k>0 && Element[k, Integers], SeriesCoefficient[..]] instead, as the result you give doesn't work for positive integer k (as requested by the OP). $\endgroup$
    – Carl Woll
    Commented Apr 20, 2017 at 20:21
  • $\begingroup$ @bbgodfrey I really appreciate the help, I can use this approach for other summations now and it will save me so much time not having to manually derive these series like I had been doing! $\endgroup$ Commented Apr 21, 2017 at 5:50

You can use a old trick: $$\frac{\partial (y-x)^{t+k}}{\partial t}\text{/.}\, t\to 0=(-x+y)^k \log (-x+y)$$

The corresponding series coefficient is:

sc = SeriesCoefficient[(y - x)^(t + k), {x, 0, n}]
(* Piecewise[{{(-1)^n*y^(k - n + t)*Binomial[k + t, n], n >= 0}}, 0]*)

Compute derivative respect to t and t=0:

FullSimplify[(D[sc[[1, 1, 1]], t] /. t -> 0), Assumptions -> 
n >= 0 && n \[Element] Integers && k >= 0 && k \[Element] Integers]
(* (-1)^n y^(k - n)Binomial[k, n] (HarmonicNumber[k] - HarmonicNumber[k - n] + Log[y]) *)

c[n_] := (-1)^n y^(k - n)*Binomial[k, n] (HarmonicNumber[k] - HarmonicNumber[k - n] + Log[y])

Series coefficient is simpler as previously presented by bbgodfrey.

and Sum for the expression is:

 Sum[c[n] x^n, {n, 0, Infinity}]

$$\sum _{n=0}^{\infty } (-1)^n x^n y^{k-n} \binom{k}{n} \left(H_k-H_{k-n}+\log (y)\right)$$

To test the validity of this expression, compare it for k=1:

 Series[(y - x)^k*Log[y - x] /. k -> 1, {x, 0, 5}] // Normal // Expand

$-x+\frac{x^5}{20 y^4}+\frac{x^4}{12 y^3}+\frac{x^3}{6 y^2}+\frac{x^2}{2 y}-x \log (y)+y \log (y)$

 Sum[Limit[c[n]*x^n, k -> 1], {n, 0, 5}] // FullSimplify // Expand

$-x+\frac{x^5}{20 y^4}+\frac{x^4}{12 y^3}+\frac{x^3}{6 y^2}+\frac{x^2}{2 y}-x \log (y)+y \log (y)$

 (* True *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.