-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Gamma function and related functions.
--   
--   Approximations of the gamma function, incomplete gamma functions, and
--   factorials.
@package gamma
@version 0.9.0.2

module Math.Factorial

-- | Factorial function
class Num a => Factorial a
factorial :: (Factorial a, Integral b) => b -> a
instance Math.Factorial.Factorial GHC.Integer.Type.Integer
instance Math.Factorial.Factorial GHC.Types.Float
instance Math.Factorial.Factorial (Data.Complex.Complex GHC.Types.Float)
instance Math.Factorial.Factorial GHC.Types.Double
instance Math.Factorial.Factorial (Data.Complex.Complex GHC.Types.Double)

module Math.Gamma.Incomplete

-- | Continued fraction representation of the lower incomplete gamma
--   function.
lowerGammaCF :: (Floating a, Ord a) => a -> a -> CF a

-- | Continued fraction representation of the regularized lower incomplete
--   gamma function.
pCF :: (Gamma a, Ord a, Enum a) => a -> a -> CF a

-- | Lower incomplete gamma function, computed using Kummer's confluent
--   hypergeometric function M(a;b;x). Specifically, this uses the
--   identity:
--   
--   gamma(s,x) = x**s * exp (-x) / s * M(1; 1+s; x)
--   
--   From Abramowitz &amp; Stegun (6.5.12).
--   
--   Recommended for use when x &lt; s+1
lowerGammaHypGeom :: (Eq b, Floating b) => b -> b -> b

-- | Natural logarithm of lower gamma function, based on the same identity
--   as <a>lowerGammaHypGeom</a> and evaluated carefully to avoid overflow
--   and underflow. Recommended for use when x &lt; s+1
lnLowerGammaHypGeom :: (Eq a, Floating a) => a -> a -> a

-- | Regularized lower incomplete gamma function, computed using Kummer's
--   confluent hypergeometric function. Uses same identity as
--   <a>lowerGammaHypGeom</a>.
--   
--   Recommended for use when x &lt; s+1
pHypGeom :: (Gamma a, Ord a) => a -> a -> a

-- | Continued fraction representation of the upper incomplete gamma
--   function. Recommended for use when x &gt;= s+1
upperGammaCF :: (Floating a, Ord a) => a -> a -> CF a

-- | Natural logarithms of the convergents of the upper gamma function,
--   evaluated carefully to avoid overflow and underflow. Recommended for
--   use when x &gt;= s+1
lnUpperGammaConvergents :: (Eq a, Floating a) => a -> a -> [a]

-- | Continued fraction representation of the regularized upper incomplete
--   gamma function. Recommended for use when x &gt;= s+1
qCF :: (Gamma a, Ord a, Enum a) => a -> a -> CF a


-- | Lanczos' approximation to the gamma function, as described at
--   http://en.wikipedia.org/wiki/Lanczos_approximation (fetched 11 June
--   2010).
--   
--   Constants to be supplied by user. There is a file
--   "extras/LanczosConstants.hs" in the source repository that implements
--   a technique by Paul Godfrey for calculating the coefficients. It is
--   not included in the distribution yet because it makes use of a linear
--   algebra library I have not yet released (though I eventually intend
--   to).
module Math.Gamma.Lanczos

-- | Compute Lanczos' approximation to the gamma function, using the
--   specified constants. Valid for Re(x) &gt; 0.5. Use <a>reflect</a> or
--   <a>reflectC</a> to extend to the whole real line or complex plane,
--   respectively.
gammaLanczos :: Floating a => a -> [a] -> a -> a

-- | Compute Lanczos' approximation to the natural logarithm of the gamma
--   function, using the specified constants. Valid for Re(x) &gt; 0.5. Use
--   <a>reflectLn</a> or <a>reflectLnC</a> to extend to the whole real line
--   or complex plane, respectively.
lnGammaLanczos :: Floating a => a -> [a] -> a -> a

-- | Extend an approximation of the gamma function from the domain x &gt;
--   0.5 to the whole real line.
reflect :: (RealFloat a, Ord a) => (a -> a) -> a -> a

-- | Extend an approximation of the gamma function from the domain Re(x)
--   &gt; 0.5 to the whole complex plane.
reflectC :: RealFloat a => (Complex a -> Complex a) -> Complex a -> Complex a

-- | Extend an approximation of the natural logarithm of the gamma function
--   from the domain x &gt; 0.5 to the whole real line.
reflectLn :: (RealFloat a, Ord a) => (a -> a) -> a -> a

-- | Extend an approximation of the natural logarithm of the gamma function
--   from the domain Re(x) &gt; 0.5 to the whole complex plane.
reflectLnC :: RealFloat a => (Complex a -> Complex a) -> Complex a -> Complex a

module Math.Gamma

-- | Gamma function. Minimal definition is ether <a>gamma</a> or
--   <a>lnGamma</a>.
class (Eq a, Floating a, Factorial a) => Gamma a

-- | The gamma function: gamma z == integral from 0 to infinity of <tt>t
--   -&gt; t**(z-1) * exp (negate t)</tt>
gamma :: Gamma a => a -> a

-- | Natural log of the gamma function
lnGamma :: Gamma a => a -> a

-- | Natural log of the factorial function
lnFactorial :: (Gamma a, Integral b) => b -> a

-- | Factorial function
class Num a => Factorial a
factorial :: (Factorial a, Integral b) => b -> a

-- | Incomplete gamma functions.
class Gamma a => IncGamma a

-- | Lower gamma function: lowerGamma s x == integral from 0 to x of <tt>t
--   -&gt; t**(s-1) * exp (negate t)</tt>
lowerGamma :: IncGamma a => a -> a -> a

-- | Natural log of lower gamma function
lnLowerGamma :: IncGamma a => a -> a -> a

-- | Regularized lower incomplete gamma function: lowerGamma s x / gamma s
p :: IncGamma a => a -> a -> a

-- | Upper gamma function: lowerGamma s x == integral from x to infinity of
--   <tt>t -&gt; t**(s-1) * exp (negate t)</tt>
upperGamma :: IncGamma a => a -> a -> a

-- | Natural log of upper gamma function
lnUpperGamma :: IncGamma a => a -> a -> a

-- | Regularized upper incomplete gamma function: upperGamma s x / gamma s
q :: IncGamma a => a -> a -> a
instance Math.Gamma.IncGamma GHC.Types.Float
instance Math.Gamma.IncGamma GHC.Types.Double
instance Math.Gamma.Gamma GHC.Types.Float
instance Math.Gamma.Gamma GHC.Types.Double
instance Math.Gamma.Gamma (Data.Complex.Complex GHC.Types.Float)
instance Math.Gamma.Gamma (Data.Complex.Complex GHC.Types.Double)


-- | Stirling's approximation to the gamma function and utility functions
--   for selecting coefficients.
module Math.Gamma.Stirling

-- | Convergent when Re(z) &gt; 0. The first argument is the c_n series to
--   use (<a>cs</a> is an ineffecient but generic definition of the full
--   infinite series. Some precomputed finite prefix of <a>cs</a> should be
--   fed to this function, the length of which will determine the accuracy
--   achieved.)
lnGammaStirling :: Floating a => [a] -> a -> a

-- | The c_n series in the convergent version of Stirling's approximation
--   given on wikipedia at
--   http://en.wikipedia.org/wiki/Stirling%27s_approximation#A_convergent_version_of_Stirling.27s_formula
--   as fetched on 11 June 2010.
cs :: (Fractional a, Ord a) => [a]

-- | The (signed) Stirling numbers of the first kind.
s :: Int -> Int -> Integer

-- | The (unsigned) Stirling numbers of the first kind.
abs_s :: Int -> Int -> Integer

-- | Compute the number of terms required to achieve a given precision for
--   a given value of z. The mamimum will typically (always?) be around 1,
--   and seems to be more or less independent of the precision desired
--   (though not of the machine epsilon - essentially, near zero I think
--   this method is extremely numerically unstable).
terms :: (Num t, Floating a, Ord a) => a -> a -> t
