úÎÊQÂ6      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghi jklmnopqrstuvwx y z{|} ~ (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)." € ‚ƒ„…†‡ˆ‰ !"#$Š  !"!   "  ‚€…†„ƒ‰ !"#$Šˆ‡(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...]‹ŒŽ(Parameter of each function.:Coefficients of each polynomial term, in increasing order.)Parameter of each function.:Coefficients of each polynomial term, in increasing order.()()‹ŒŽ()(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) 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone0(Calculate relative error of two numbers: \frac{|a - b|}{\max(|a|,|b|)} ÙIt lies in [0,1) interval for numbers with same sign and (1,2] for numbers with different sign. If both arguments are zero or negative zero function returns 0. If at least one argument is transfinite it returns NaN1.Check that relative error between two numbers a and b. If 0 returns NaN it returns False.2)Add N ULPs (units of least precision) to Double number.3Measure distance between two DoubleEs in ULPs (units of least precision). Note that it's different from abs (ulpDelta a b), since it returns correct result even when 4 overflows.4$Measure signed distance between two Double8s in ULPs (units of least precision). Note that unlike 3 it can overflow.  >>> ulpDelta 1 (1 + m_epsilon) 15 Compare two 9 values for approximate equality, using Dawson's method.ŸThe required accuracy is specified in ULPs (units of least precision). If the two numbers differ by the given number of ULPs or less, this function returns True.01eps( relative error should be in [0,1) rangeab2345#Number of ULPs of accuracy desired.012345012345012345(c) 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone056>The result of searching for a root of a mathematical function.7fThe function does not have opposite signs when evaluated at the lower and upper bounds of the search.8hThe search failed to converge to within the given error tolerance after the given number of iterations.9A root was successfully found.:]Returns either the result of a search for a root, or the default value if the search failed.;:Use the method of Ridders to compute a root of a function.„The function must have opposite signs when evaluated at the lower and upper bounds of the search (i.e. the root must be bracketed).</Solve equation using Newton-Raphson iterations.ŠThis method require both initial guess and bounds for root. If Newton step takes us out of bounds on root function reverts to bisection. 6789:Default value.Result of search for a root.;Absolute error tolerance.&Lower and upper bounds for the search.Function to find the roots of.<Required precisionY(lower bound, initial guess, upper bound). Iterations will no go outside of the intervalNFunction to finds roots. It returns pair of function value and its derivative=>?@A6978:;<6789:;< 6789:;<=>?@A(c) 2009, 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableSafeG#Largest representable finite value.H5The smallest representable positive normalized value.I The largest  x such that 2**(x)-1) is approximately representable as a .JPositive infinity.KNegative infinity.L Not a number.M!Maximum possible finite value of log xN)Logarithm of smallest normalized double (H)O sqrt 2P  sqrt (2 * pi)Q  2 / sqrt piR  1 / sqrt 2S The smallest  µ such that 1 + µ "` 1.T log(sqrt((2*pi))U*Euler Mascheroni constant (³ = 0.57721...)GHIJKLMNOPQRSTUGHIJKLMNOPQRSTUSGHIJKLMNRQTOPUGHIJKLMNOPQRSTU(c) 2016 Alexey KhudyakovBSD3-alexey.skladnoy@gmail.com, bos@serpentine.com experimentalportableSafeAT VGInfinite series. It's represented as opaque state and step function.XenumSequenceFrom x generate sequence: a_n = x + n YenumSequenceFromStep x d generate sequence: a_n = x + nd Z Analog of ‘ for sequence.[Calculate sum of series \sum_{i=0}^\infty a_i Summation is stopped when' a_{n+1} < \varepsilon\sum_{i=0}^n a_i where µ is machine precision (S)\Calculate sum of series \sum_{i=0}^\infty x^ia_i ECalculation is stopped when next value in series is less than µ·sum.]Convert series to infinite list^€Evaluate continued fraction using modified Lentz algorithm. Sequence contain pairs (a[i],b[i]) which form following expression:B b_0 + \frac{a_1}{b_1+\frac{a_2}{b_2+\frac{a_3}{b_3 + \cdots}}} cModified Lentz algorithm is described in Numerical recipes 5.2 "Evaluation of Continued Fractions"_%Elementwise operations with sequences`%Elementwise operations with sequences VWXYZ[\]^_`ab VWXYZ[\]^ VWXYZ[\]^ VWXYZ[\]^_`ab %(c) 2009, 2011, 2012 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNoneTcError function.K \operatorname{erf}(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} \exp(-t^2) dt Function limits are:µ \begin{aligned} &\operatorname{erf}(-\infty) &=& -1 \\ &\operatorname{erf}(0) &=& \phantom{-}\,0 \\ &\operatorname{erf}(+\infty) &=& \phantom{-}\,1 \\ \end{aligned} dComplementary error function.6 \operatorname{erfc}(x) = 1 - \operatorname{erf}(x) Function limits are:  \begin{aligned} &\operatorname{erf}(-\infty) &=&\, 2 \\ &\operatorname{erf}(0) &=&\, 1 \\ &\operatorname{erf}(+\infty) &=&\, 0 \\ \end{aligned} e Inverse of c.f Inverse of d.g/Compute the logarithm of the gamma function, “(x).; \Gamma(x) = \int_0^{\infty}t^{x-1}e^{-t}\,dt = (x - 1)! oThis implementation uses Lanczos approximation. It gives 14 or more significant decimal digits, 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).h Synonym for g. Retained for compatibilityiHCompute the log gamma correction factor for Stirling approximation for xl "e 10. This correction factor is suitable for an alternate (but less numerically accurate) definition of g:l \log\Gamma(x) = \frac{1}{2}\log(2\pi) + (x-\frac{1}{2})\log x - x + \operatorname{logGammaCorrection}(x) j:Compute the normalized lower incomplete gamma function ³(z,x). Normalization means that ³(z,")=1@ \gamma(z,x) = \frac{1}{\Gamma(z)}\int_0^{x}t^{z-1}e^{-t}\,dt Uses Algorithm AS 239 by Shea.kDInverse incomplete gamma function. It's approximately inverse of j for the same z/. So following equality approximately holds: -invIncompleteGamma z . incompleteGamma z "H idl3Compute the natural logarithm of the beta function.U B(a,b) = \int_0^1 t^{a-1}(1-t)^{1-b}\,dt = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)} m%Regularized incomplete beta function.? I(x;a,b) = \frac{1}{B(a,b)} \int_0^x t^{a-1}(1-t)^{1-b}\,dt YUses algorithm AS63 by Majumder and Bhattachrjee and quadrature approximation for large p and q.n.Regularized incomplete beta function. Same as m9 but also takes logarithm of beta function as parameter.o‹Compute inverse of regularized incomplete beta function. Uses initial approximation from AS109, AS64 and Halley method to solve equation.pCompute sinc function sin(x)/xq%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.rCompute log(1+x)-x:sCompute  exp x - 1* without loss of accuracy for x near zero.tO(log n)4 Compute the logarithm in base 2 of the given value.uCompute the factorial function ne!. Returns +" if the input is above 170 (above which the result cannot be represented by a 64-bit ).v`Compute the natural logarithm of the factorial function. Gives 16 decimal digits of precision.wgCalculate the error term of the Stirling approximation. This is only defined for non-negative values.Q \operatorname{stirlingError}(n) = \log(n!) - \log(\sqrt{2\pi n}\frac{n}{e}^n) x)Quickly compute the natural logarithm of n { k, with no checking.Less numerically stable: Kexp $ lg (n+1) - lg (k+1) - lg (n-k+1) where lg = logGamma . fromIntegraly2Calculate binomial coefficient using exact formulaz.Compute logarithm of the binomial coefficient.{!Compute the binomial coefficient n `{` 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 == 35| Compute È(x=), the first logarithmic derivative of the gamma function.T \psi(x) = \frac{d}{dx} \ln \left(\Gamma(x)\right) = \frac{\Gamma'(x)}{\Gamma(x)} EUses Algorithm AS 103 by Bernardo, based on Minka's C implementation.'’“”•–cdep " [-1,1]fp " [0,2]ghijz " (0,")x " (0,")kz " (0,")p " [0,1]la > 0b > 0ma > 0b > 0x, must lie in [0,1] rangen%logarithm of beta function for given p and qa > 0b > 0x, must lie in [0,1] range—˜oa > 0b > 0x " [0,1]™špqrstuvwxyz{|›œž'’“”•–cdefghijklmn—˜o™špqrstuvwxyz{|›œž&’“”•–cdefghijklmn—˜o™špqrstuvwxyz{|›œž%(c) 2009, 2011, 2012 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNonecdefghjklmnopqrstuvwz{|cdefghjk|lmnopqrtsuvw{z (c) 2009, 2011 Bryan O'SullivanBSD3bos@serpentine.com experimentalportableNone}Evaluate the deviance term x log(x/np) + np - x.~.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  logGammaL.4Returns " if the input is outside of the range (0 < x "d 1e305).} x np~ixy}~}yx~i}~Ÿ     !"#$%&'()*+,-./0123456789:;<=>?@>ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]]^_`abcdefgh i j k l m n o p q r s t u v w x y z { | } ~  € ‚ ƒ „…†‡ˆ‰Š‹ŒŽ‘‘’’“”•“”–—˜™ š š › œ ž Ÿ   ¡ ¢ £ ¤ ¥¦-math-functions-0.2.0.1-5a7TAmALZ356fcJFgrBqk5 Numeric.SumNumeric.Polynomial.ChebyshevNumeric.Polynomial Numeric.MathFunctions.ComparisonNumeric.RootFindingNumeric.MathFunctions.ConstantsNumeric.SeriesNumeric.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 chebyshevchebyshevBrouckeevaluatePolynomialevaluateEvenPolynomialevaluateOddPolynomialevaluatePolynomialLevaluateEvenPolynomialLevaluateOddPolynomialL relativeErroreqRelErraddUlps ulpDistanceulpDeltawithinRoot NotBracketed SearchFailedfromRootridders newtonRaphson$fAlternativeRoot$fApplicativeRoot$fMonadPlusRoot $fMonadRoot $fFunctorRoot$fEqRoot $fReadRoot $fShowRoot $fDataRoot $fGenericRootm_hugem_tiny m_max_exp m_pos_inf m_neg_infm_NaN m_max_log m_min_logm_sqrt_2 m_sqrt_2_pi m_2_sqrt_pi m_1_sqrt_2 m_epsilonm_ln_sqrt_2_pim_eulerMascheroniSequenceenumSequenceFromenumSequenceFromStep scanSequence sumSeriessumPowerSeriessequenceToListevalContFractionB$fFractionalSequence $fNumSequence$fApplicativeSequence$fFunctorSequenceerferfcinvErfinvErfclogGamma logGammaLlogGammaCorrectionincompleteGammainvIncompleteGammalogBetaincompleteBetaincompleteBeta_invIncompleteBetasinclog1plog1pmxexpm1log2 factorial logFactorial stirlingError logChooseFast chooseExact logChoosechoosedigammabd0 logGammaAS245 V_KahanSum MV_KahanSumkahanAddD:R:VectorKahanSum0V_KBNSum MV_KBNSumkbnAddD:R:VectorKBNSum0V_KB2Sum MV_KB2Sumkb2AddD:R:VectorKB2Sum0BCghc-prim GHC.TypesDoubleIntbaseGHC.ListscanlLc_expm1c_erfcc_erfincompleteBetaApproxincompleteBetaWorkerinvIncompleteBetaWorkerinvIncBetaGuesscoefWcoefY trigamma1modErr