Description
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,
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.
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!