úÎ{»uöU      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST(c) 2014 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone 0:<=DR ¹Kahan summation. This is the least accurate of the compensated summation methods. In practice, it only beats naive summation for inputs with large magnitude. Kahan summation can be less; accurate than naive summation for small-magnitude inputs._This summation method is included for completeness. Its use is not recommended. In practice,  ' is both 30% faster and more accurate.0A class for summation of floating point numbers.The identity for summation.Add a value to a sum.Sum a collection of values. Example: foo =   [1,2,3] sKahan-Babuaka-Neumaier summation. This is a little more computationally costly than plain Kahan summation, but is always at least as accurate. !Return the result of a Kahan sum.éSecond-order Kahan-Babuaka summation. This is more computationally costly than Kahan-Babuaka-Neumaier summation, running at about a third the speed. Its advantage is that it can lose less precision (in admittedly obscure cases).‡This method compensates for error in both the sum and the first-order compensation term, hence the use of "second order" in the name.2Return the result of a Kahan-Babuaka-Neumaier sum. 2Return the result of an order-2 Kahan-Babuaka sum.!O(n) Sum a vector of values."O(n)1 Sum a vector of values using pairwise summation.)This approach is perhaps 10% faster than  ¹, but has poorer bounds on its error growth. Instead of having roughly constant error regardless of the size of the input vector, in the worst case its accumulated error grows with O(log n)." UVW XYZ[\]^_ !"#$`  !"!   "  W XVU[\ZY_ !"#$`^](c) 2009, 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone:(NEvaluate a Chebyshev polynomial of the first kind. Uses Clenshaw's algorithm.)§Evaluate a Chebyshev polynomial of the first kind. Uses Broucke's ECHEB algorithm, and his convention for coefficient handling. It treat 0th coefficient different so =chebyshev x [a0,a1,a2...] == chebyshevBroucke [2*a0,a1,a2...]abcd(Parameter of each function.:Coefficients of each polynomial term, in increasing order.)Parameter of each function.:Coefficients of each polynomial term, in increasing order.()()abcd()(c) 2012 Aleksey KhudyakovBSD3bos@serpentine.com experimentalportableNone*[Evaluate polynomial using Horner's method. Coefficients starts from lowest. In pseudocode: 1evaluateOddPolynomial x [1,2,3] = 1 + 2*x + 3*x^2+qEvaluate polynomial with only even powers using Horner's method. Coefficients starts from lowest. In pseudocode: 3evaluateOddPolynomial x [1,2,3] = 1 + 2*x^2 + 3*x^4,pEvaluate polynomial with only odd powers using Horner's method. Coefficients starts from lowest. In pseudocode: 5evaluateOddPolynomial x [1,2,3] = 1*x + 2*x^3 + 3*x^5*x Coefficients+x Coefficients,x Coefficients-./*+,-./*+,-./*+,-./(c) 2009, 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableSafe 0A very large number.2 The largest e x such that 2**(x)-1) is approximately representable as a f.3Positive infinity.4Negative infinity.5 Not a number.6 sqrt 27  sqrt (2 * pi)8  2 / sqrt pi9  1 / sqrt 2: The smallest f µ such that 1 + µ "` 1.; log(sqrt((2*pi))<*Euler Mascheroni constant (³ = 0.57721...) 0123456789:;< 0123456789:;< :01234598;67< 0123456789:;<%(c) 2009, 2011, 2012 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNoneT=Error function. #erf -" = -1 erf 0 = 0 erf +" = 1>Complementary error function. #erfc -" = 2 erfc 0 = 1 errc +" = 0? Inverse of =.@ Inverse of >.A.Compute the logarithm of the gamma function “(x&). Uses Algorithm AS 245 by Macleod.XGives an accuracy of 10-12 significant decimal digits, except for small regions around x = 1 and xC = 2, where the function goes to zero. For greater accuracy, use B.4Returns " if the input is outside of the range (0 < x "d 1e305).B/Compute the logarithm of the gamma function, “(x"). Uses a Lanczos approximation.This function is slower than AN, but gives 14 or more significant decimal digits of accuracy, except around x = 1 and x& = 2, where the function goes to zero.4Returns " if the input is outside of the range (0 < x "d 1e305).g,Compute the log gamma correction factor for xl "e 10. This correction factor is suitable for an alternate (but less numerically accurate) definition of A: Dlgg x = 0.5 * log(2*pi) + (x-0.5) * log x - x + logGammaCorrection xC:Compute the normalized lower incomplete gamma function ³(s,x). Normalization means that ³(s%,")=1. Uses Algorithm AS 239 by Shea.DDInverse incomplete gamma function. It's approximately inverse of C for the same s/. So following equality approximately holds: -invIncompleteGamma s . incompleteGamma s = idE3Compute the natural logarithm of the beta function.F€Regularized incomplete beta function. Uses algorithm AS63 by Majumder and Bhattachrjee and quadrature approximation for large p and q.G.Regularized incomplete beta function. Same as F9 but also takes logarithm of beta function as parameter.H‹Compute inverse of regularized incomplete beta function. Uses initial approximation from AS109, AS64 and Halley method to solve equation.ICompute sinc function sin(x)/xJ%Compute the natural logarithm of 1 + x(. This is accurate even for values of x near zero, where use of log(1+x) would lose precision.KO(log n)4 Compute the logarithm in base 2 of the given value.LCompute the factorial function ne!. Returns +" if the input is above 170 (above which the result cannot be represented by a 64-bit f).M`Compute the natural logarithm of the factorial function. Gives 16 decimal digits of precision.NgCalculate the error term of the Stirling approximation. This is only defined for non-negative values. 8stirlingError @n@ = @log(n!) - log(sqrt(2*pi*n)*(n/e)^n)O)Quickly compute the natural logarithm of n R k, with no checking.Less numerically stable: Kexp $ lg (n+1) - lg (k+1) - lg (n-k+1) where lg = logGamma . fromIntegralP2Calculate binomial coefficient using exact formulaQ.Compute logarithm of the binomial coefficient.R!Compute the binomial coefficient n `R` k. For values of k‚ > 50, this uses an approximation for performance reasons. The approximation is accurate to 12 decimal places in the worst caseExample: 7 `choose` 3 == 35S Compute È0(x‚), the first logarithmic derivative of the gamma function. Uses Algorithm AS 103 by Bernardo, based on Minka's C implementation.!hi=>?p " [-1,1]@p " [0,2]ABgCs " (0,")x " (0,")Ds " (0,")p " [0,1]EFp > 0q > 0x, must lie in [0,1] rangeG%logarithm of beta function for given p and qp > 0q > 0x, must lie in [0,1] rangejkHp > 0q > 0a " [0,1]lIJKLMNOPQRSmnop!hi=>?@ABgCDEFGjkHlIJKLMNOPQRSmnop hi=>?@ABgCDEFGjkHlIJKLMNOPQRSmnop%(c) 2009, 2011, 2012 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNoneT=>?@ABCDEFGHIJKLMNQRS=>?@ABCDSEFGHIJKLMNRQ(c) 2009, 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNoneTEvaluate the deviance term x log(x/np) + np - x.T x npOPTTPOTq      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdeffgghijhiklmmnopqrstu-math-functions-0.1.6.0-7kB95POXsAZ9xlvezXDgZX Numeric.SumNumeric.Polynomial.ChebyshevNumeric.PolynomialNumeric.MathFunctions.ConstantsNumeric.SpecFunctionsNumeric.SpecFunctions.ExtraNumeric.SpecFunctions.InternalKahanSum Summationzeroaddsum$fSummationDouble $fEqKahanSum$fShowKahanSum$fDataKahanSumKBNSumkahan$fNFDataKahanSum$fSummationKahanSum$fVectorVectorKahanSum$fMVectorMVectorKahanSum$fUnboxKahanSum $fEqKBNSum $fShowKBNSum $fDataKBNSumKB2Sumkbn$fNFDataKBNSum$fSummationKBNSum$fVectorVectorKBNSum$fMVectorMVectorKBNSum $fUnboxKBNSum $fEqKB2Sum $fShowKB2Sum $fDataKB2Sumkb2 sumVector pairwiseSum$fNFDataKB2Sum$fSummationKB2Sum$fVectorVectorKB2Sum$fMVectorMVectorKB2Sum $fUnboxKB2Sum chebyshevchebyshevBrouckeevaluatePolynomialevaluateEvenPolynomialevaluateOddPolynomialevaluatePolynomialLevaluateEvenPolynomialLevaluateOddPolynomialLm_hugem_tiny m_max_exp m_pos_inf m_neg_infm_NaNm_sqrt_2 m_sqrt_2_pi m_2_sqrt_pi m_1_sqrt_2 m_epsilonm_ln_sqrt_2_pim_eulerMascheronierferfcinvErfinvErfclogGamma logGammaLincompleteGammainvIncompleteGammalogBetaincompleteBetaincompleteBeta_invIncompleteBetasinclog1plog2 factorial logFactorial stirlingError logChooseFast chooseExact logChoosechoosedigammabd0 V_KahanSum MV_KahanSumkahanAddD:R:VectorKahanSum0V_KBNSum MV_KBNSumkbnAddD:R:VectorKBNSum0V_KB2Sum MV_KB2Sumkb2AddD:R:VectorKB2Sum0BCghc-prim GHC.TypesIntDoublelogGammaCorrectionLincompleteBetaApproxincompleteBetaWorkerinvIncompleteBetaWorkercoefWcoefY trigamma1modErr