skip to main content
10.1145/3385412.3386037acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article
Open access

Towards an API for the real numbers

Published: 11 June 2020 Publication 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.
[2]
Oliver Aberth. 1988. Precise Numerical Analysis. Wm. C. Brown.
[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, UK
[4]
ASKVG. 2012. Microsoft Windows Calculator Bug, Sqrt(4) – 2 != 0. https://www.askvg.com/microsoft-windows-calculator-bug/
[5]
Alan Baker. 1990. Transcendental number theory, Cambridge Mathematical Library (2nd ed.). Cambridge University Press.
[6]
Erret Bishop. 1967. Foundations of Constructive Real Analysis. McGraw-Hill.
[7]
Erret Bishop and Douglas Bridges. 1985. Constructive Analysis. Springer-Verlag.
[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.
[9]
Hans-J. Boehm. 2019. Floating point precision test. https://androidreview.googlesource.com/c/platform/art/+/1012109
[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.
[11]
Hans-J. Boehm. 2005. The constructive reals as a Java library. J. Logic and Algebraic Programming 64 (2005), 3––11. Issue 1.
[12]
Hans-J. Boehm. 2017. Small-Data Computing: Correct Calculator Arithmetic. Commun. ACM 60, 8 (July 2017), 44–49. 10.1145/2911981
[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.
[14]
Keith Briggs. 2006. Implementing Exact Real Arithmetic in Python, C++ and C. Theor. Comput. Sci. 351, 1 (Feb. 2006), 74–81.
[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=93765
[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.
[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.
[18]
David Goldberg. 1991. What Every Computer Scientist Should Know About Floating-point Arithmetic. ACM Comput. Surv. 23, 1 (March 1991), 5–48.
[19]
Google Play. 2020. Google Calculator Reviews. https://play.google.com/store/apps/details?id=com.google.android. calculator&showAllReviews=true
[20]
James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Alex Buckley, and Daniel Smith. 2008.
[21]
The Java Language Specification: Java SE 11 Edition. Oracle.
[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.
[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.
[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.
[25]
IEEE CS. 2008. 754-2008 - IEEE Standard for Floating-Point Arithmetic.
[26]
M. Laczkovich. 2003. The removal of π from some undecidable problems involving elementary functions. Proc. Amer. Math. Soc. 131, 7 (2003), 2235?2240.
[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.
[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.
[29]
David Monniaux. 2008. The Pitfalls of Verifying Floating-point Computations. ACM Trans. Program. Lang. Syst. 30, 3, Article 12 (May 2008), 41 pages.
[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.
[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
[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.
[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.
[34]
Stephen Shankland. 2008. Google’s calculator muffs some math problems. https://www.cnet.com/news/googles-calculator-muffs-somemath-problems
[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.
[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.
[37]
A. K. Simpson. 1998. Lazy functional algorithms for Exact Real Functionals. In Mathematical Foundations of Computer Science, Springer LNCS 1450. 456–464.
[38]
Jean Vuillemin. 1990. Exact Real Arithmetic with Continued Fractions. IEEE Trans. Comput. 39, 8 (1990), 1087–1105.
[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.

Cited By

View all
  • (2024)Implementation and Synthesis of Math Library FunctionsProceedings of the ACM on Programming Languages10.1145/36328748:POPL(942-969)Online publication date: 5-Jan-2024
  • (2023)Equality Saturation Theory Exploration à la CarteProceedings of the ACM on Programming Languages10.1145/36228347:OOPSLA2(1034-1062)Online publication date: 16-Oct-2023
  • (2023)Making Interval Arithmetic Robust to Overflow2023 IEEE 30th Symposium on Computer Arithmetic (ARITH)10.1109/ARITH58626.2023.00022(44-47)Online publication date: 4-Sep-2023
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
PLDI 2020: Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation
June 2020
1174 pages
ISBN:9781450376136
DOI:10.1145/3385412
This work is licensed under a Creative Commons Attribution International 4.0 License.

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 11 June 2020

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. API design
  2. comparison
  3. decidability
  4. real numbers

Qualifiers

  • Research-article

Conference

PLDI '20
Sponsor:

Acceptance Rates

Overall Acceptance Rate 406 of 2,067 submissions, 20%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)658
  • Downloads (Last 6 weeks)84
Reflects downloads up to 10 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Implementation and Synthesis of Math Library FunctionsProceedings of the ACM on Programming Languages10.1145/36328748:POPL(942-969)Online publication date: 5-Jan-2024
  • (2023)Equality Saturation Theory Exploration à la CarteProceedings of the ACM on Programming Languages10.1145/36228347:OOPSLA2(1034-1062)Online publication date: 16-Oct-2023
  • (2023)Making Interval Arithmetic Robust to Overflow2023 IEEE 30th Symposium on Computer Arithmetic (ARITH)10.1109/ARITH58626.2023.00022(44-47)Online publication date: 4-Sep-2023
  • (2021)Regime Inference for Sound Floating-Point OptimizationsACM Transactions on Embedded Computing Systems10.1145/347701220:5s(1-23)Online publication date: 17-Sep-2021

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media