1
$\begingroup$

I need a good approximations for $H_p$, for $p \in (0,1) \cap \mathbb{Q}$, the generalization of $H_n=\sum_{i=1}^n \frac{1}{i}$ to the real numbers.

I tried $H_p = p \sum_{k=1}^\infty \frac{1}{k (k + p)}$ and $H_p = \sum_{k=0}^\infty \sum_{j=0}^\infty (-1)^j (1 + k)^{-2 - j} p^{1 + j}$ for $-\frac{1}{2}<p<\frac{1}{2}$, both converge very slow, just five digit of $H_\frac{1}{2}$ take ~1,000,000 iterations.

$\endgroup$
5
  • 1
    $\begingroup$ What do you mean with $H(p)$? $\endgroup$
    – Wojowu
    Commented Jun 11, 2023 at 11:08
  • 2
    $\begingroup$ Possibly the generalization of the harmonic number $H_n=1+1/2+\dots+1/n$ to noninteger $n$ given by $H_x=\sum_{n\ge1}(1/n-1/(n+x))$? $\endgroup$ Commented Jun 11, 2023 at 11:20
  • $\begingroup$ If so, for rational $0<p<1$ you can look at en.wikipedia.org/wiki/… $\endgroup$ Commented Jun 11, 2023 at 11:24
  • $\begingroup$ en.wikipedia.org/wiki/… has an explicit formular for $H_\frac{p}{q}$, though the approximations for cos, ln,... will be annoying, I'll update the question once I implemented it $\endgroup$ Commented Jun 11, 2023 at 11:51
  • 5
    $\begingroup$ Doesn't the Wikipedia section on computing the digamma function (together with an approximation of the Euler-Mascheroni constant) contain all the information you need on how to compute $H(p) = \psi(p+1) + \gamma$ to any given precision? $\endgroup$
    – Gro-Tsen
    Commented Jun 11, 2023 at 13:44

1 Answer 1

5
$\begingroup$

We can compute $H_p = p \sum_{k=1}^\infty \frac{1}{k (k + p)}$ very fast and very accurately as follows. Let \begin{equation*} f(x):=\frac p{(x+1)(x+1 + p)}=\frac{1}{x+1}-\frac{1}{x+1+p}, \end{equation*} so that \begin{equation*} H_p=\sum_{k=0}^c f(k)+\sum_{k=1}^\infty f_c(k), \end{equation*} where $c$ is a natural number and $f_c(x):=f(c+x)$.

If $c$ is large enough, then $\sum_{k=1}^\infty f_c(k)$ can be evaluated fast with high precision by the Euler--Maclaurin (EM) formula: \begin{equation*} \sum_{k=1}^\infty f_c(k)=-G_{m,c}+R_{m,c}, \end{equation*} where \begin{equation*} G_{m,c}:= F(c) + \frac{f(c)}2 + \sum_{j=1}^{m-1}\frac{B_{2j}}{(2j)!}f^{(2j-1)}(c), \end{equation*} \begin{equation*} F(x):=\ln\frac{x+1}{x+1+p} \end{equation*} (so that $F$ is the antiderivative of $f$ with $F(\infty-)=0$), $m$ is a natural number, the $B_k$'s are the Bernoulli numbers, and \begin{equation*} |R_{m,c}|<\frac{2.02}{(2\pi)^{2m-1}}f^{(2m-2)}(c) \\ =\frac{2.02(2m-2)!}{(2\pi)^{2m-1}}((c+1)^{1-2m}-((c+1+p)^{1-2m}) \end{equation*} if $m\ge4$.

If we want to get $H(p)$ with $d$ correct decimal digits after the decimal point, then good choices for $m$ and $c$ are as follows: \begin{equation*} m=\Big\lceil\frac d{2\log_{10}d}\Big\rceil,\quad c=\Big\lceil\frac1{\pi e}\,m\,10^{d/(2m)}\Big\rceil; \end{equation*} see Section 6.1 for details or Section 6.1 for more details.

E.g., if we want to get $H(2/3)$ with $1000$ correct decimal digits after the decimal point, then we can choose $m=167$ and $c=19288$, so that the error $|R_{m,c}|$ of the corresponding approximation \begin{equation*} H_{2/3;m,c}:=\sum_{k=0}^c f(k)-G_{m,c} \end{equation*} of $H(2/3)$ is $<3\times10^{-1002}$. This approximation, $H_{2/3;m,c}$, of $H(2/3)$ was computed by Mathematica in just about $0.11$ sec. Since $H_{2/3}=\frac{3}{2}+\frac{\pi }{2 \sqrt{3}}-\frac{3 \ln3}{2}$, we find that the actual difference $H_{2/3;m,c}-H_{2/3}$ between the approximate and true values is $\approx-3.08\times10^{-1003}$. The corresponding Mathematica notebook can be viewed here.


Using the summation formula alternative to the EM formula, we can parallelize calculations and thus further reduce the execution time if the desired number $d$ of correct digits is large enough (such as $2000$ or more).

$\endgroup$
2
  • 1
    $\begingroup$ For p=2/3 you should test H(2/3) against the closed form value 3/2+1/6*Pi*3^(1/2)-3/2*ln(3). This gives 0.75898124911494438820 ... which is different from 0.758981249114928906960 ... $\endgroup$ Commented Jun 12, 2023 at 1:18
  • $\begingroup$ @JorgeZuniga : Thank you for your comment. There were two typos in my Mathematica notebook, which are now fixed, so that all the $1000$ digits are now correct. $\endgroup$ Commented Jun 12, 2023 at 2:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .