10.1145/3385412.3386037acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections

Towards an API for the real numbers

Published:11 June 2020Publication History

ABSTRACT

The real numbers are pervasive, both in daily life, and in mathematics. Students spend much time studying their properties. Yet computers and programming languages generally provide only an approximation geared towards performance, at the expense of many of the nice properties we were taught in high school.

Although this is entirely appropriate for many applications, particularly those that are sensitive to arithmetic performance in the usual sense, we argue that there are others where it is a poor choice. If arithmetic computations and result are directly exposed to human users who are not floating point experts, floating point approximations tend to be viewed as bugs. For applications such as calculators, spreadsheets, and various verification tasks, the cost of precision sacrifices is high, and the performance benefit is often not critical. We argue that previous attempts to provide accurate and understandable results for such applications using the recursive reals were great steps in the right direction, but they do not suffice. Comparing recursive reals diverges if they are equal. In many cases, comparison of numbers, including equal ones, is both important, particularly in simple cases, and intractable in the general case.

We propose an API for a real number type that explicitly provides decidable equality in the easy common cases, in which it is often unnatural not to. We describe a surprisingly compact and simple implementation in detail. The approach relies heavily on classical number theory results. We demonstrate the utility of such a facility in two applications: testing floating point functions, and to implement arithmetic in Google's Android calculator application.

References

  1. Oliver Aberth. 1974. A Precise Numerical Analysis Program. Commun. ACM 17, 9 (September 1974), 509–513.Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Oliver Aberth. 1988. Precise Numerical Analysis. Wm. C. Brown.Google ScholarGoogle Scholar
  3. annymous. 2014. Odd bug in calculator app. https://www.reddit.com/ r/Android/comments/2ph1wk/odd_bug_in_calculator_app/ 18 With occurrence frequency determined by e.g. what expressions users enter into a calculator. Towards an API for the Real Numbers PLDI ’20, June 15–20, 2020, London, UKGoogle ScholarGoogle Scholar
  4. ASKVG. 2012. Microsoft Windows Calculator Bug, Sqrt(4) – 2 != 0. https://www.askvg.com/microsoft-windows-calculator-bug/Google ScholarGoogle Scholar
  5. Alan Baker. 1990. Transcendental number theory, Cambridge Mathematical Library (2nd ed.). Cambridge University Press.Google ScholarGoogle Scholar
  6. Erret Bishop. 1967. Foundations of Constructive Real Analysis. McGraw-Hill.Google ScholarGoogle Scholar
  7. Erret Bishop and Douglas Bridges. 1985. Constructive Analysis. Springer-Verlag.Google ScholarGoogle Scholar
  8. Jens Blanck. 2000. Exact Real Arithmetic Systems: Results of Competition. In Proceedings of the Workshop on Computability and Complexity in Analysis, Springer LNCS 2064. 389–393.Google ScholarGoogle Scholar
  9. Hans-J. Boehm. 2019. Floating point precision test. https://androidreview.googlesource.com/c/platform/art/+/1012109Google ScholarGoogle Scholar
  10. Hans-J. Boehm. 1987. Constructive Real Interpretation of Numerical Programs. In Proceedings of the SIGPLAN ’87 Symposium on Interpreters and Interpretive Techniques. 214–221.Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Hans-J. Boehm. 2005. The constructive reals as a Java library. J. Logic and Algebraic Programming 64 (2005), 3––11. Issue 1.Google ScholarGoogle ScholarCross RefCross Ref
  12. Hans-J. Boehm. 2017. Small-Data Computing: Correct Calculator Arithmetic. Commun. ACM 60, 8 (July 2017), 44–49. 10.1145/2911981 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Hans-J. Boehm, Robert Cartwright, Michael J. O’Donnell, and Mark Riggle. 1986. Exact Real Arithmetic: A Case Study in Higher Order Programming. In Proceedings of the 1986 ACM Conference on Lisp and Functional Programming. 162–173.Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Keith Briggs. 2006. Implementing Exact Real Arithmetic in Python, C++ and C. Theor. Comput. Sci. 351, 1 (Feb. 2006), 74–81. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Raymond Chen. 2016. Why does the Windows calculator generate tiny errors when calculating the square root of a perfect square? https://devblogs.microsoft.com/oldnewthing/?p=93765Google ScholarGoogle Scholar
  16. M Coste and M. F. Roy. 1988. Thom’s Lemma, the Coding of Real Algebraic Numbers and the Computation of the Topology of Semialgebraic Sets. Journal of Symbolic Computation 5 (1988), 121–129.Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Sicun Gao, Jeremy Avigad, and Edmund M. Clarke. 2012. Delta-Decidability over the Reals. In Proceedings of the 27th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS ’12). IEEE Computer Society Press, 305–314.Google ScholarGoogle Scholar
  18. David Goldberg. 1991. What Every Computer Scientist Should Know About Floating-point Arithmetic. ACM Comput. Surv. 23, 1 (March 1991), 5–48. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Google Play. 2020. Google Calculator Reviews. https://play.google.com/store/apps/details?id=com.google.android. calculator&showAllReviews=trueGoogle ScholarGoogle Scholar
  20. James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Alex Buckley, and Daniel Smith. 2008.Google ScholarGoogle Scholar
  21. The Java Language Specification: Java SE 11 Edition. Oracle.Google ScholarGoogle Scholar
  22. Paul Gowland and David Lester. 2000. A Survey of Exact Arithmetic Implementations. In Proceedings of the Workshop on Computability and Complexity in Analysis, Springer LNCS 2064. 30–47.Google ScholarGoogle Scholar
  23. John L. Gustafson and Isaac T. Yonemoto. 2017. Beating floating point at its own game: Posit arithmetic. Supercomputing Frontiers and Innovations 4, 2 (2017), 71–86.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. M. Haselman, M. Beauchamp, A. Wood, S. Hauck, K. Underwood, and K.S. Hemmert. 2005. A comparison of floating point and logarithmic number systems for FPGAs. In 13th Annual IEEE Symposium on Field-Programmable Custom Computing Machines (FCCM’05). 181–190.Google ScholarGoogle Scholar
  25. IEEE CS. 2008. 754-2008 - IEEE Standard for Floating-Point Arithmetic.Google ScholarGoogle Scholar
  26. M. Laczkovich. 2003. The removal of π from some undecidable problems involving elementary functions. Proc. Amer. Math. Soc. 131, 7 (2003), 2235?2240.Google ScholarGoogle Scholar
  27. Vernon Lee and Hans-J. Boehm. 1990. Optimizing Programs over the Constructive Reals. In Proceedings of the SIGPLAN 1990 Conference on Programming Language Design and Implementation. 102–111.Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Valérie Ménissier-Morain. 1994. Arithmétique exacte, conception, algorithmique et performances d’une implémentation informatique en précision arbitraire. Thèse. Université Paris 7.Google ScholarGoogle Scholar
  29. David Monniaux. 2008. The Pitfalls of Verifying Floating-point Computations. ACM Trans. Program. Lang. Syst. 30, 3, Article 12 (May 2008), 41 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Norbert Th. Mueller. 2000. The iRRAM: Exact Real Arithmetic in C++. In Proceedings of the Workshop on Computability and Complexity in Analysis, Springer LNCS 2064. 222–252.Google ScholarGoogle Scholar
  31. Pavel Panchekha, Alex Sanchez-Stern, James R. Wilcox, and Zachary Tatlock. 2015. Automatically Improving Accuracy for Floating Point Expressions. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation (Portland, OR, USA) (PLDI ’15). ACM, New York, NY, USA, 1–11. 2737924.2737959 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Dan Richardson and John Fitch. 1994. The Idenitity Problem for Elementary Functions and Constants. In ISSAC ’94 Proceedings of the international symposium on Symbolic and algebraic computation. 285– 290.Google ScholarGoogle Scholar
  33. Alex Sanchez-Stern, Pavel Panchekha, Sorin Lerner, and Zachary Tatlock. 2018. Finding Root Causes of Floating Point Error. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (Philadelphia, PA, USA) (PLDI 2018). ACM, New York, NY, USA, 256–269. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Stephen Shankland. 2008. Google’s calculator muffs some math problems. https://www.cnet.com/news/googles-calculator-muffs-somemath-problemsGoogle ScholarGoogle Scholar
  35. Benjamin Sherman, Jesse Michael, and Michael Carbin. 2019. Sound and Robust Solid Modeling via Exact Real Arithmetic and Continuity. Proceedings, ACM Program. Lang., ICFP 3, Article 99 (8 2019), 29 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Benjamin Sherman, Luke Sciarappa, Adam Chlipala, and Michael Carbin. 2018. Computable Decision Making on the Reals and Other Spaces: Via Partiality and Nondeterminism. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (Oxford, United Kingdom) (LICS ’18). ACM, New York, NY, USA, 859–868. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. A. K. Simpson. 1998. Lazy functional algorithms for Exact Real Functionals. In Mathematical Foundations of Computer Science, Springer LNCS 1450. 456–464.Google ScholarGoogle Scholar
  38. Jean Vuillemin. 1990. Exact Real Arithmetic with Continued Fractions. IEEE Trans. Comput. 39, 8 (1990), 1087–1105.Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. K. Weirauch and C. Kreitz. 1987. Representations of the Real Numbers and of the open subsets of the real numbers. Annals of Pure and Applied Logic 35, 3 (1987), 247–260.Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Towards an API for the real numbers

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!