In FLINT and python-flint, one has access to the harmonic numbers via fmpq.harmonic(n). When looking up the efficient computation of these numbers, I ran into a blog post by the current maintainer of FLINT! I see that the computation in FLINT is done via a balanced-sum, and I was wondering two things:
(1) is there a cache anywhere in the current computation/would it be beneficial to have one in practice? One could for instance define in python my_harmonic() to return the output of the fmpq.harmonic() function, while including e.g. a functools lru_cache before this.
(2) is there a way to access computations of the generalized harmonic numbers harmonic(n,m) such that harmonic(n,1) = harmonic(n)? Namely, $$H_{n,m}=\sum_{k=1}^{n}\frac{1}{k^m}$$, which pops up for instance when rewriting polylogarithms in terms of the Hurwitz zeta function.
I am looking for a way to efficiently compute these generalized harmonic numbers, but am initially unsure as to whether it would be beneficial to implement them from scratch in an analogous way for their own sake, or to use relations such as e.g. $$H_{n,m}=\sum_{k=1}^{n-1}\frac{H_{k,m-1}}{k(k+1)}+\frac{H_{n,m-1}}{n}$$ to reduce the order of the computation to eventually have $H_{n,m}$ written in terms of a sum consisting of $\sim nm$ terms of numbers $H_{1,1},\dots,H_{n,1}$ the ordinary harmonic numbers; therefore, if these numbers are cached, it seems that $H_{n,m}$ and $H_{n,1}$ would require roughly the same amount of computation.
I could be totally off the mark in which case I would appreciate any advice! For instance, the mere rewriting of the summation to decrease the order could be a non-significant computational step when compared to the naive computation itself, as we are again summing over various rational linear combinations. Thank you for any comments!