Class BoostGamma.Lanczos

  • Enclosing class:
    BoostGamma

    static final class BoostGamma.Lanczos
    extends java.lang.Object
    53-bit precision implementation of the Lanczos approximation.

    This implementation is in partial fraction form with the leading constant of \( \sqrt{2\pi} \) absorbed into the sum.

    It is related to the Gamma function by the following equation \[ \Gamma(z) = \frac{(z + g - 0.5)^{z - 0.5}}{e^{z + g - 0.5}} \mathrm{lanczos}(z) \] where \( g \) is the Lanczos constant.

    Warning

    This is not a substitute for LanczosApproximation. The approximation is written in partial fraction form with the leading constants absorbed by the coefficients in the sum.

    See Also:
    Boost Lanczos Approximation
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int[] DENOM
      Common denominator used for the rational evaluation.
      (package private) static double G
      Lanczos constant G.
      (package private) static double GMH
      Lanczos constant G - half.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Lanczos()
      Private constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static double evaluateRational​(double[] a, int[] b, double x)
      Evaluate the rational number as two polynomials.
      (package private) static double lanczosSum​(double z)
      Computes the Lanczos approximation.
      (package private) static double lanczosSumExpGScaled​(double z)
      Computes the Lanczos approximation scaled by exp(g).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GMH

        static final double GMH
        Lanczos constant G - half.

        Note: The form (g - 0.5) is used when computing the gamma function.

        See Also:
        Constant Field Values
      • DENOM

        private static final int[] DENOM
        Common denominator used for the rational evaluation.
    • Constructor Detail

      • Lanczos

        private Lanczos()
        Private constructor.
    • Method Detail

      • lanczosSum

        static double lanczosSum​(double z)
        Computes the Lanczos approximation.
        Parameters:
        z - Argument.
        Returns:
        the Lanczos approximation.
      • lanczosSumExpGScaled

        static double lanczosSumExpGScaled​(double z)
        Computes the Lanczos approximation scaled by exp(g).
        Parameters:
        z - Argument.
        Returns:
        the scaled Lanczos approximation.
      • evaluateRational

        private static double evaluateRational​(double[] a,
                                               int[] b,
                                               double x)
        Evaluate the rational number as two polynomials.

        Adapted from boost/math/tools/detail/rational_horner3_13.hpp. Note: There are 3 variations of the unrolled rational evaluation. These methods change the order based on the sign of x. This should be used for the Lanczos code as this comment in boost/math/tools/rational.hpp notes:

        However, there are some tricks we can use to prevent overflow that might otherwise occur in polynomial evaluation, if z is large. This is important in our Lanczos code for example.
        Parameters:
        a - Coefficients of the numerator polynomial
        b - Coefficients of the denominator polynomial
        x - Value
        Returns:
        the rational number