Document Open Access Logo

Verified Compilation and Optimization of Floating-Point Programs in CakeML

Authors Heiko Becker , Robert Rabe, Eva Darulova , Magnus O. Myreen , Zachary Tatlock , Ramana Kumar , Yong Kiam Tan , Anthony Fox

Thumbnail PDF


  • Filesize: 0.96 MB
  • 28 pages

Document Identifiers

Author Details

Heiko Becker
  • MPI-SWS, Saarland Informatics Campus, (SIC), Saarbrücken, Germany
Robert Rabe
  • TU München, Germany
Eva Darulova
  • Uppsala University, Sweden
Magnus O. Myreen
  • Chalmers University of Technology, Gothenburg, Sweden
Zachary Tatlock
  • University of Washington, Seattle, WA, USA
Ramana Kumar
  • DeepMind, London, UK
Yong Kiam Tan
  • Carnegie Mellon University, Pittsburgh, PA, USA
Anthony Fox
  • Arm Limited, Cambridge, UK

Cite AsGet BibTex

Heiko Becker, Robert Rabe, Eva Darulova, Magnus O. Myreen, Zachary Tatlock, Ramana Kumar, Yong Kiam Tan, and Anthony Fox. Verified Compilation and Optimization of Floating-Point Programs in CakeML. In 36th European Conference on Object-Oriented Programming (ECOOP 2022). Leibniz International Proceedings in Informatics (LIPIcs), Volume 222, pp. 1:1-1:28, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2022)


Verified compilers such as CompCert and CakeML have become increasingly realistic over the last few years, but their support for floating-point arithmetic has thus far been limited. In particular, they lack the "fast-math-style" optimizations that unverified mainstream compilers perform. Supporting such optimizations in the setting of verified compilers is challenging because these optimizations, for the most part, do not preserve the IEEE-754 floating-point semantics. However, IEEE-754 floating-point numbers are finite approximations of the real numbers, and we argue that any compiler correctness result for fast-math optimizations should appeal to a real-valued semantics rather than the rigid IEEE-754 floating-point numbers. This paper presents RealCake, an extension of CakeML that achieves end-to-end correctness results for fast-math-style optimized compilation of floating-point arithmetic. This result is achieved by giving CakeML a flexible floating-point semantics and integrating an external proof-producing accuracy analysis. RealCake’s end-to-end theorems relate the I/O behavior of the original source program under real-number semantics to the observable I/O behavior of the compiler generated and fast-math-optimized machine code.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Formal software verification
  • Software and its engineering → Compilers
  • Software and its engineering → Software performance
  • compiler verification
  • compiler optimization
  • floating-point arithmetic


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Oskar Abrahamsson. A Verified Proof Checker for Higher-Order Logic. Journal of Logical and Algebraic Methods in Programming, 112, 2020. URL:
  2. Oskar Abrahamsson, Son Ho, Hrutvik Kanabar, Ramana Kumar, Magnus O. Myreen, Michael Norrish, and Yong Kiam Tan. Proof-Producing Synthesis of CakeML from Monadic HOL Functions. J. Autom. Reason., 64(7), 2020. URL:
  3. A. Anta and P. Tabuada. To Sample or not to Sample: Self-Triggered Control for Nonlinear Systems. IEEE Transactions on Automatic Control, 55(9):2030-2042, 2010. URL:
  4. Apache Software Foundation. The LLVM Compiler Infrastructure, 2020. URL:
  5. Heiko Becker, Eva Darulova, Magnus O Myreen, and Zachary Tatlock. Icing: Supporting Fast-Math Style Optimizations in a Verified Compiler. In Computer Aided Verification (CAV), 2019. URL:
  6. Heiko Becker, Nikita Zyuzin, Raphaël Monat, Eva Darulova, Magnus O Myreen, and Anthony Fox. A Verified Certificate Checker for Finite-Precision Error Bounds in Coq and HOL4. In Formal Methods in Computer Aided Design (FMCAD), 2018. URL:
  7. Michael Berg. LLVM Numerics Blog, 2019. URL:
  8. Hans-J. Boehm. Towards an API for the Real Numbers. In Programming Language Design and Implementation (PLDI), 2020. URL:
  9. Sylvie Boldo, François Clément, Jean-Christophe Filliâtre, Micaela Mayero, Guillaume Melquiond, and Pierre Weis. Wave Equation Numerical Resolution: A Comprehensive Mechanized Proof of a C Program. Journal of Automated Reasoning, 50(4), 2013. URL:
  10. Sylvie Boldo, Jacques-Henri Jourdan, Xavier Leroy, and Guillaume Melquiond. Verified Compilation of Floating-Point Computations. Journal of Automated Reasoning, 54(2):135-163, 2015. URL:
  11. Wei-Fan Chiang, Mark Baranowski, Ian Briggs, Alexey Solovyev, Ganesh Gopalakrishnan, and Zvonimir Rakamarić. Rigorous Floating-Point Mixed-Precision Tuning. In Principles of Programming Languages (POPL), 2017. URL:
  12. G. A. Constantinides, P. Y. K. Cheung, and W. Luk. Wordlength Optimization for Linear Digital Signal Processing. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems, 22(10), 2003. URL:
  13. Nasrine Damouche, Matthieu Martel, and Alexandre Chapoutot. Improving the Numerical Accuracy of Programs by Automatic Transformation. International Journal on Software Tools for Technology Transfer, 19(4), 2017. URL:
  14. Nasrine Damouche, Matthieu Martel, Pavel Panchekha, Chen Qiu, Alexander Sanchez-Stern, and Zachary Tatlock. Toward a Standard Benchmark Format and Suite for Floating-Point Analysis. In Numerical Software Verification (NSV), 2016. URL:
  15. Eva Darulova and Viktor Kuncak. Towards a Compiler for Reals. ACM Transactions on Programming Languages and Systems (TOPLAS), 39(2), 2017. URL:
  16. Eva Darulova, Saksham Sharma, and Einar Horn. Sound Mixed-Precision Optimization with Rewriting. In International Conference on Cyber-Physical Systems (ICCPS), 2018. URL:
  17. Florent De Dinechin, Christoph Quirin Lauter, and Guillaume Melquiond. Assisted Verification of Elementary Functions Using Gappa. In ACM Symposium on Applied Computing (SAC), 2006. URL:
  18. Anthony Fox. Improved Tool Support for Machine-Code Decompilation in HOL4. In International Conference on Interactive Theorem Proving. Springer, 2015. URL:
  19. Free Software Foundation. The GNU Compiler Collection, 2020. URL:
  20. GCC Developers. GCC Wiki: Floating-point Math, 2020. URL:
  21. Alejandro Gomez-Londono, Johannes Åman Pohjola, Hira Taqdees Syeda, Magnus O. Myreen, and Yong Kiam Tan. Do You Have Space for Dessert? A Verified Space Cost Semantics for CakeML Programs. Proceedings of the ACM on Programming Languages (OOPSLA), 4, 2020. URL:
  22. Armaël Guéneau, Magnus O Myreen, Ramana Kumar, and Michael Norrish. Verified Characteristic Formulae for CakeML. In European Symposium on Programming (ESOP), 2017. URL:
  23. Suyog Gupta, Ankur Agrawal, Kailash Gopalakrishnan, and Pritish Narayanan. Deep learning with limited numerical precision. In International Conference on Machine Learning (ICML), 2015. Google Scholar
  24. John Harrison. Floating Point Verification in HOL. In Proceedings of the 8th International Workshop on Higher Order Logic Theorem Proving and Its Applications, 1995. URL:
  25. Nicholas J. Higham. Accuracy and Stability of Numerical Algorithms. Society for Industrial and Applied Mathematics, 2nd edition, 2002. URL:
  26. IEEE. IEEE Standard for Floating-Point Arithmetic. IEEE Std 754-2019 (Revision of IEEE 754-2008), 2019. URL:
  27. Bertrand Jeannet and Antoine Miné. Apron: A Library of Numerical Abstract Domains for Static Analysis. In Computer Aided Verification (CAV), 2009. URL:
  28. Jacques-Henri Jourdan, Vincent Laporte, Sandrine Blazy, Xavier Leroy, and David Pichardie. A Formally-Verified C Static Analyzer. In Principles of Programming Languages (POPL), 2015. URL:
  29. Ramana Kumar. Self-Compilation and Self-Verification. PhD thesis, University of Cambridge, 2015. Google Scholar
  30. Juneyoung Lee, Chung-Kil Hur, and Nuno P Lopes. AliveInLean: a Verified LLVM Peephole Optimization Verifier. In International Conference on Computer Aided Verification. Springer, 2019. URL:
  31. Xavier Leroy. Formal Certification of a Compiler Back-end, or: Programming a Compiler with a Proof Assistant. In Principles of Programming Languages (POPL), 2006. URL:
  32. Xavier Leroy. A Formally Verified Compiler Back-end. Journal of Automated Reasoning, 43(4), 2009. URL:
  33. LLVM Developers. LLVM Language Reference: Fast-Math Flags, 2020. URL:
  34. Nuno P. Lopes, David Menendez, Santosh Nagarakatte, and John Regehr. Provably Correct Peephole Optimizations with Alive. In Programming Language Design and Implementation (PLDI), 2015. URL:
  35. Andreas Lööw, Ramana Kumar, Yong Kiam Tan, Magnus O. Myreen, Michael Norrish, Oskar Abrahamsson, and Anthony Fox. Verified Compilation on a Verified Processor. In Programming Language Design and Implementation (PLDI), 2019. URL:
  36. Victor Magron, George Constantinides, and Alastair Donaldson. Certified Roundoff Error Bounds Using Semidefinite Programming. ACM Transactions on Mathematical Software, 43(4), 2017. URL:
  37. Rupak Majumdar, Indranil Saha, and Majid Zamani. Synthesis of Minimal-Error Control Software. In International Conference on Embedded Software (EMSOFT), 2012. URL:
  38. Adolfo Anta Martinez, Rupak Majumdar, Indranil Saha, and Paulo Tabuada. Automatic Verification of Control System Implementations. In International Conference on Embedded software (EMSOFT), 2010. URL:
  39. David Menendez, Santosh Nagarakatte, and Aarti Gupta. Alive-FP: Automated Verification of Floating Point Based Peephole Optimizations in LLVM. In Static Analysis Symposium (SAS), 2016. URL:
  40. Ramon E. Moore, R. Baker Kearfott, and Michael J. Cloud. Introduction to Interval Analysis. Society for Industrial and Applied Mathematics, 2009. URL:
  41. Mariano M. Moscato, Laura Titolo, Aaron Dutle, and César A. Muñoz. Automatic Estimation of Verified Floating-Point Round-Off Errors via Static Analysis. In Computer Safety, Reliability, and Security (SAFECOMP), 2017. URL:
  42. Andres Nötzli and Fraser Brown. LifeJacket: Verifying Precise Floating-Point Optimizations in LLVM. In International Workshop on State Of the Art in Program Analysis (SOAP), 2016. URL:
  43. Scott Owens, Magnus O Myreen, Ramana Kumar, and Yong Kiam Tan. Functional Big-Step Semantics. In European Symposium on Programming (ESOP), 2016. URL:
  44. Pavel Panchekha, Alex Sanchez-Stern, James R Wilcox, and Zachary Tatlock. Automatically Improving Accuracy for Floating Point Expressions. In Conference on Programming Language Design and Implementation (PLDI), 2015. URL:
  45. A. Pnueli, M. Siegel, and E. Singerman. Translation Validation. In Tools and Algorithms for the Construction and Analysis of Systems (TACAS), 1998. URL:
  46. Johannes Aman Pohjola, Henrik Rostedt, and Magnus O. Myreen. Characteristic Formulae for Liveness Properties of Non-terminating CakeML Programs. In Interactive Theorem Proving (ITP), 2019. URL:
  47. Markus Püschel, José M F Moura, Bryan Singer, Jianxin Xiong, Jeremy R Johnson, David A Padua, Manuela M Veloso, and Robert W Johnson. Spiral - A Generator for Platform-Adapted Libraries of Signal Processing Algorithms. International Journal of High Performance Computing Applications, 18(1), 2004. Google Scholar
  48. Tahina Ramananandro, Paul Mountcastle, Benoît Meister, and Richard Lethin. A Unified Coq Framework for Verifying C Programs with Floating-Point Computations. In Certified Programs and Proofs (CPP), 2016. URL:
  49. Talia Ringer, Karl Palmskog, Ilya Sergey, Milos Gligoric, and Zachary Tatlock. QED at Large: A Survey of Engineering of Formally Verified Software. Foundations and Trends in Programming Languages, 5, 2019. URL:
  50. Cindy Rubio-González, Cuong Nguyen, Hong Diep Nguyen, James Demmel, William Kahan, Koushik Sen, David H. Bailey, Costin Iancu, and David Hough. Precimonious: Tuning Assistant for Floating-Point Precision. In International Conference for High Performance Computing, Networking, Storage and Analysis (SC), 2013. URL:
  51. Hanan Samet. Proving the Correctness of Heuristically Optimized Code. Communications of the ACM, 21(7), 1978. URL:
  52. Eric Schkufza, Rahul Sharma, and Alex Aiken. Stochastic Optimization of Floating-point Programs with Tunable Precision. In Programming Language Design and Implementation (PLDI), 2014. URL:
  53. Konrad Slind and Michael Norrish. A Brief Overview of HOL4. In International Conference on Theorem Proving in Higher Order Logics (TPHOL), 2008. URL:
  54. Alexey Solovyev, Charles Jacobsen, Zvonimir Rakamaric, and Ganesh Gopalakrishnan. Rigorous Estimation of Floating-Point Round-off Errors with Symbolic Taylor Expansions. In International Symposium on Formal Methods (FM), 2015. URL:
  55. Yong Kiam Tan, Magnus O. Myreen, Ramana Kumar, Anthony Fox, Scott Owens, and Michael Norrish. The Verified CakeML Compiler Backend. Journal of Functional Programming, 29, 2019. URL:
  56. Laura Titolo, Marco A Feliú, Mariano Moscato, and César A Munoz. An Abstract Interpretation Framework for the Round-off Error Analysis of Floating-Point Programs. In Verification, Model Checking, and Abstract Interpretation (VMCAI), 2018. URL:
  57. Linus Torvalds. What is acceptable for -ffast-math?, 2001. URL:
  58. Vadim Zaliva. HELIX: From Math to Verified Code. PhD thesis, Carnegie Mellon University, 2020. Google Scholar
  59. Jianzhou Zhao, Santosh Nagarakatte, Milo MK Martin, and Steve Zdancewic. Formalizing the LLVM Intermediate Representation for Verified Program Transformations. In Principles of Programming Languages (POPL), 2012. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail