# How to calculate this expression?

evaluate the expression [1]: $$\sum\limits_{n = 1}^\infty {\left( {\frac{1}{n} - \frac{1}{{n + x}}} \right)}$$

where $x$ is a real number, $0\le x\le1$, and $x$ is rounded to 3 digits.

For example, when $x=0.500$, the expression is [2]:

$$\left(\frac11 -\frac1{1.5}\right)+\left(\frac12 -\frac1{2.5}\right)+\left(\frac13 -\frac 1{3.5}\right) + ...$$

For a given $x$, how can I evaluate it? The answer must be rounded to more than 12 digits.

• No chance. If $x$ is rounded to 3 digits, the request to provide the 12 digit precision in the answer is absurd. – fedja Aug 14 '13 at 13:52
• x is a given constant, range from 0.000 to 1.000 – user2682564 Aug 14 '13 at 13:54
• the key is to note this is $\sum\limits_{k=1}^\infty\left(\frac1k-\frac1{k+x}\right)$... for positive integer $x$ it is trivial to see it telescopes to give $\sum\limits_{k=0}^x\frac1k=H_x\approx \log x+\gamma$ – oldrinb Aug 14 '13 at 13:56
• Given with only 3 digit precision according to what you've written ;) Anyway, read about Euler-Maclaurin formula on Wikipedia. It is a great way to boost the convergence of anyting like this. – fedja Aug 14 '13 at 13:57
• @oldrinb How does this help? – fedja Aug 14 '13 at 13:58

$$\sum\limits_{n = 1}^\infty {\left( {\frac{1}{n} - \frac{1}{{n + x}}} \right)}=\sum\limits_{n = 1}^\infty \frac{x}{n(n+x)}$$

It is known that the sum is

$$\sum\limits_{n = 1}^\infty \frac{x}{n(n+x)}=\psi(x+1)+\gamma$$

where $\psi$ is the digamma function

$\gamma$ is the Euler constant .

We can easily prove that for $x=0.5$ we have

$$\psi(1.5)=2-\gamma -\log(4)$$

Hence the sum is equal to

$$2-\log(4)$$

• Thank you. I got it. To evaluate ψ(x), "Gauss's digamma theorem" is very helpful to this problem. – user2682564 Aug 14 '13 at 14:32

It may be interesting to observe that this sum is an example of a harmonic sum that is often used in textbooks to illustrate the use of Mellin transforms on these sums, where the trick is to compute the Mellin transform of the sum and thereafter use Mellin inversion to get an asymptotic expansion of the latter. Introduce $$f(x) = \sum_{k\ge 1} \left(\frac{1}{k} - \frac{1}{x+k}\right).$$ The reason this is very useful is the fact that $$f(n) = H_n,$$ which should be obvious. Here $H_n$ denotes the $n$-th harmonic number. So if we expand $f(x)$ at infinity we get the asymptotic expansion of harmonic numbers.

Now to do the harmonic analysis we rewrite the sum as follows: $$f(x) = \sum_{k\ge 1} \frac{x}{k(x+k)} = \sum_{k\ge 1} \frac{1}{k} \frac{x}{x+k} = \sum_{k\ge 1} \frac{1}{k} \frac{x/k}{x/k+1}.$$

Comparing this with the equation for the Mellin transform of a harmonic sum, which we recall is $$\mathfrak{M}\left(\sum_{k\ge 1} \lambda_k g(\mu_k x); s\right) = \left(\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} \right) g^*(s),$$ where $g^*(s)$ is the Mellin transform of $g(x),$ we see that in the present case $$\lambda_k = \frac{1}{k}, \quad \mu_k = \frac{1}{k} \quad \text{and} \quad g(x) = \frac{x}{1+x}.$$ This gives $$\sum_{k\ge 1} \frac{\lambda_k}{\mu_k^s} = \zeta(1-s).$$ We use a keyhole contour for the Mellin transform of $g(x)$ and take into account the pole at $x=-1$, obtaining $$\left(1-e^{2\pi i (s-1)}\right) \int_0^\infty g(x) x^{s-1} dx = 2\pi i(-1)^s$$ which implies that $$g^*(s) = 2\pi i\frac{e^{i\pi s}}{1-e^{2\pi i s}} = \pi \frac{2i}{e^{-\pi i s} - e^{\pi i s}} = -\frac{\pi}{\sin(\pi s)}.$$ We may now conclude that the Mellin transform $f^*(s)$ of $f(x)$ is given by $$\mathfrak{M}(f(x); s) = - \zeta(1-s) \frac{\pi}{\sin(\pi s)}.$$

We are ready to apply Mellin inversion to $f^*(s)$, shifting the inversion integral, which is $$\frac{1}{2\pi i}\int_{-1/2-i\infty}^{-1/2+i\infty} f^*(s)/x^s\, ds,$$ to the right for an expansion at infinity.

We get $$\operatorname{Res}(f^*(s)/x^s; s=0) = -\gamma -\log x$$ $$\operatorname{Res}(f^*(s)/x^s; s=1) = -\frac{1}{2x}$$ and from then on $$\operatorname{Res}(f^*(s)/x^s; s=m) = - \zeta(1-m) \frac{(-1)^m}{x^m} = \frac{(-1)^m B_m}{m}\frac{1}{x^m}$$ where the $B_m$ are Bernoulli numbers.

The conclusion is that $$f(x) \sim \gamma + \log x + \frac{1}{2x} - \sum_{m\ge 2} \frac{(-1)^m B_m}{m}\frac{1}{x^m}$$ and in particular $$H_n \sim \gamma + \log n + \frac{1}{2n} - \frac{1}{12n^2} + \frac{1}{120n^4} - \cdots.$$

• Shifting the Mellin transform integral to the left instead of the right for an expansion at zero, we have $$\operatorname{Res}(f^*(s)/x^s; s=-m) = - \zeta(1+m) (-1)^m x^m$$ with $m\ge 1$, which gives $$x\zeta(2)-x^2\zeta(3)+x^3\zeta(4)-\cdots,$$ as noted by the other poster. – Marko Riedel Aug 14 '13 at 21:34

If we define $$f(x)=\sum_{k=1}^\infty\left(\frac1k-\frac1{k+x}\right)\tag{1}$$ then when $n$ is a non-negative integer, $f(n)=H_n$, the $n^{\text{th}}$ Harmonic Number. This generalizes to the Digamma function for general $x$: $$\psi(x)=\frac{\Gamma'(x)}{\Gamma(x)}=f(x-1)-\gamma\tag{2}$$ The reflection formula $$\psi(1-x)-\psi(x)=\pi\cot(\pi x)\tag{3}$$ follows from the identity (proven in this answer) $$\sum_{k\in\mathbb{Z}}\frac1{k+z}=\pi\cot(\pi z)\tag{4}$$ Furthermore, for all $x$, $$f(x)=f(x-1)+\frac1x\tag{5}$$ We can get an asymptotic expansion for $f$ using the Euler-Maclaurin Sum Formula $$f(x)=\log(x)+\gamma+\frac1{2x}-\frac1{12x^2}+\frac1{120x^4}-\frac1{252x^6}+\frac1{240x^8}-\frac1{132x^{10}}+\dots\tag6{}$$ Asymptotic expansions become more accurate as $x\to\infty$. For example, the series in $(6)$ has an error of less than $\dfrac1{47x^{12}}$. To compute $f(x)$ accurately for $x\in[0,1]$, we can use the asymptotic expansion in $(6)$ to compute $f(x+n)$ for some large integer $n$, then use $(5)$ to get $f(x)$.

For the particular case you ask about, \begin{align} f\left(\frac12\right) &=\frac11-\frac1{1.5}+\frac12-\frac1{2.5}+\frac13-\frac1{3.5}+\dots\\ &=2\left(\frac12-\frac13+\frac14-\frac15+\frac16-\frac17+\dots\right)\\[6pt] &=2(1-\log(2))\tag{7} \end{align}

Examples

Using $(6)$ to compute $f(x+300)$ to $30$ places, then $(5)$ to compute $f(x)$, we get $$\begin{array}{} x\text{ (exact)}&f(x)\text{ (to 30 places)}\\ 0.1&0.153460724490456065438295871072\\ 0.2&0.288175768309344565059304127632\\ 0.3&0.408024776034733204975350916044\\ 0.4&0.515831120316416714875836608035\\ 0.5&0.613705638880109381165535757084\\ 0.6&0.703263117675009112512514807943\\ 0.7&0.785763539775026817286476274092\\ 0.8&0.862207098195394401215214456926\\ 0.9&0.933399826065592579831239174011\\ 1.0&1.000000000000000000000000000000 \end{array}$$ To get $5$ places for $x\in[0,1]$, use $(6)$ to compute $f(x+2)$ then $(5)$ to get $f(x)$. $f(x+1)$ gives less than $2$ places near $x=0$.

I don't get why you self-limit yourself to $x$ rounded to 3 digits, work with real numbers and then choose something more specific.

So for $x\in \mathbb R, x\in[0,1]$, let $$S_N = \sum_{n = 1}^N \frac 1n - \frac1{n+x} = \sum_{n=1}^N \frac x{n(n+x)}$$ $$S_N - S_{N-1} = \frac x{n(n+x)}$$ Solution to this difference equation uses the Harmonic function, see wolframalpha.

Then use the property that $H_n \approx \log n + \gamma + \frac1{2n} - \frac1{12n^2} + ...$ where $\gamma$ is the Euler Mascheroni constant. You should use as many terms as you need to round up to 12 digits. Th rest of the sequence can be found here.

I guess that from here you could find an appropriate limit for special cases of $x$, perhaps not for general $x$.

For $x=0$, the sum evaluates to $0$, and for $x=1$, it is $1$.

For $0<x<1$, you can derive a power series expression for the given sum as below:

\begin{align} \sum_{n=1}^{\infty}\left(\frac{1}{n}-\frac{1}{x+n}\right)=&\sum_{n=1}^{\infty}\left(\frac{1}{n}-\frac{1}{n}\left(1+\frac{x}{n}\right)^{-1}\right)\\ \ =& \sum_{n=1}^{\infty}\left(\frac{1}{n}-\frac{1}{n}\left(1-\frac{x}{n}+\frac{x^2}{n^2}-\frac{x^3}{n^3}+\cdots\right)\right)\\ \ =&\sum_{n=1}^{\infty}\left(\frac{x}{n^2}-\frac{x^2}{n^3}+\frac{x^3}{n^4}-\cdots\right)\\ \ =&\zeta(2)x-\zeta(3)x^2+\zeta(4)x^3-\cdots\\ \ =&\sum_{k=1}^{\infty}\zeta(k+1)x^k \end{align}