Skip to main content
Log in

Fast computation of binomial coefficients

  • Original Paper
  • Published:
Numerical Algorithms Aims and scope Submit manuscript

Abstract

One problem that arises in computation involving large numbers is precision. In certain situations, the result might be represented by the standard data type, but arithmetic precision might be compromised when dealing with large numbers in the course to the result. Binomial coefficients are an example that suffer from this torment. In the present paper, we review numerical methods to compute the binomial coefficients: Pascal’s recursive method; prime factorization to cancel out terms; gamma function approximation; and a simplified iterative method that avoids loss in precision. Acknowledging that the binomial coefficients might be obtained by a successive convolution of a simple discrete rectangular function, we propose a different approach based on the discrete Fourier transform and another based on its fast implementation. We analyze and compare performance and precision of all of them. The proposed methods overcome the previous ones when computing all coefficients for a given level n, attaining better precision for large values of n.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7

Similar content being viewed by others

Notes

  1. https://github.com/leolca/bincoeff

  2. We have also tested the minimum, which gave similar result.

  3. Octave documentation states that “by default numeric constants are represented within Octave by IEEE 754 double precision (binary64) floating-point format” [1] which uses 1 bit for sign, 11 to represent the exponent and 52 to the significant (53-bit precision) [12].

  4. The bigfloat package in Python is a wrapper for the GNU MPFR library for arbitrary-precision floating-point reliable arithmetic.

References

  1. Eaton, J.W.: Gnu octave (version 5.1.0). https://octave.org/doc/v5.1.0/Numeric-Data-Types.html (2018)

  2. Goetgheluck, P.: Computing binomial coefficients. Am. Math. Mon. 94(4), 360 (1987)

    Article  MathSciNet  Google Scholar 

  3. Wolfram Research, Inc. Wolfram—alpha. https://www.wolframalpha.com/

  4. Keprt, A.: Simple and fast computation of binomial coefficients. In: Wofex 2006, pp. 346–351, VŠB Technical University, Ostrava, Czech Republic, ISBN 80-248-1152-9 (2006)

  5. Knuth, D.E.: The Art of Computer Programming: Volume 1: Fundamental Algorithms. Addison Wesley. ISBN 0-201-89683-4 (1997)

  6. Koepf, W.: Hypergeometric Summation: An Algorithmic Approach to Summation and Special Function Identities (Advanced Lectures in Mathematics). Vieweg Teubner Verlag. ISBN 3528069503 (1998)

  7. Manolopoulos, Y.: Binomial coefficient computation: recursion or iteration?. ACM SIGCSE Bullet. 34(4), 65 (2002). https://doi.org/10.1145/820127.820168

    Article  Google Scholar 

  8. McKeeman, B.: Matlab performance measurement. Technical report, Mathworks. https://www.mathworks.com/matlabcentral/fileexchange/18510-matlab-performance-measurement. [Online; accessed 03-Feb-2020] (2008)

  9. Rolfe, T.: Binomial coefficient recursion. ACM SIGCSE Bullet. 33(2), 35 (2001). https://doi.org/10.1145/571922.571950

    Article  Google Scholar 

  10. Wells, D.: The Penguin Dictionary of Curious and Interesting Numbers. Penguin Books. ISBN 0140080295 (1987)

  11. Widrow, B., Kollár, I.: Quantization Noise: Roundoff Error in Digital Computation, Signal Processing, Control, and Communications. Cambridge University Press. ISBN 9780521886710 (2008)

  12. Wikipedia contributors. Double-precision floating-point format - Wikipedia, the free encyclopedia. https://en.wikipedia.org/wiki/Double-precision_floating-point_format. [Online; accessed 17-May-2019] (2019)

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Leonardo C. Araujo.

Additional information

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Araujo, L.C., Sansão, J.P.H. & Vale-Cardoso, A.S. Fast computation of binomial coefficients. Numer Algor 86, 799–812 (2021). https://doi.org/10.1007/s11075-020-00912-x

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s11075-020-00912-x

Keywords

Navigation