Class HarmonicNumbers


  • public class HarmonicNumbers
    extends Object
    Computation of harmonic and "hyper-harmonic" numbers.
    Author:
    Tilman Neumann
    • Method Detail

      • harmonic

        public static BigRational harmonic​(int n)
        Simple series computation of harmonic numbers H_{n} = 1/1 + 1/2 + 1/3 + ... + 1/n.
        Parameters:
        n -
        Returns:
        harmonic number H_{n}
      • harmonic_dbl

        public static double harmonic_dbl​(int n)
        Simple series computation of harmonic numbers H_{n} = 1/1 + 1/2 + 1/3 + ... + 1/n.
        Parameters:
        n -
        Returns:
        harmonic number H_{n}
      • harmonic_upperBound

        public static BigDecimal harmonic_upperBound​(BigInteger n,
                                                     Scale scale)
        Upper bound for the harmonic number H_n. From http://fredrik-j.blogspot.com/2009/02/how-not-to-compute-harmonic-numbers.html: H_n = ln(n) + gamma + 1/2*n^-1 - 1/12*n^-2 + 1/120*n^-4 + O(n^-6)
        Parameters:
        n -
        scale - number of exact after-komma digits
        Returns:
        upper bound for the harmonic number H_n
      • harmonic_lowerBound

        public static BigDecimal harmonic_lowerBound​(BigInteger n,
                                                     Scale scale)
        Lower bound for the harmonic number H_n. From https://math.stackexchange.com/questions/306371/simple-proof-of-showing-the-harmonic-number-h-n-theta-log-n: H_n = ln(n) + gamma + 1/2*n^-1 - 1/12*n^-2 + 1/120*n^-4 - 1/252*n^-6 + O(n^-8)
        Parameters:
        n -
        scale - number of exact after-komma digits
        Returns:
        lower bound for the harmonic number H_n
      • hyperharmonic_closedForm

        public static BigRational hyperharmonic_closedForm​(int n,
                                                           int r)
        Closed-form evaluation of "hyper-harmonic numbers" defined by
        H_{n,1} = sum_{i=1..n} 1/i
        H_{n,r} = sum_{i=1..n} H_{i,r-1}; r>1
        Parameters:
        n - principal argument
        r - order
        Returns:
        hyper-harmonic number H_{n,r}
      • hyperharmonic_recurrent

        public static BigRational hyperharmonic_recurrent​(int n,
                                                          int r)
        Recurrent computation of "hyper-harmonic numbers" defined by
        H_{n,1} = sum_{i=1..n} 1/i
        H_{n,r} = sum_{i=1..n} H_{i,r-1}; r>1
        Parameters:
        n - principal argument
        r - order
        Returns:
        hyper-harmonic number H_{n,r}
      • harmonicPower

        public static BigRational harmonicPower​(int n,
                                                int r)
        Harmonic power series H_{n,r} = sum_{i=1..n} 1/i^r. Can also be understood as a finite version of Riemanns zeta function.
        Parameters:
        n -
        r -
        Returns:
        H_{n,r}
      • main

        public static void main​(String[] args)