Skip to main content

Graded Hoare Logic and its Categorical Semantics

Part of the Lecture Notes in Computer Science book series (LNTCS,volume 12648)

Abstract

Deductive verification techniques based on program logics (i.e., the family of Floyd-Hoare logics) are a powerful approach for program reasoning. Recently, there has been a trend of increasing the expressive power of such logics by augmenting their rules with additional information to reason about program side-effects. For example, general program logics have been augmented with cost analyses, logics for probabilistic computations have been augmented with estimate measures, and logics for differential privacy with indistinguishability bounds. In this work, we unify these various approaches via the paradigm of grading, adapted from the world of functional calculi and semantics. We propose Graded Hoare Logic (GHL), a parameterisable framework for augmenting program logics with a preordered monoidal analysis. We develop a semantic framework for modelling GHL such that grading, logical assertions (pre- and post-conditions) and the underlying effectful semantics of an imperative language can be integrated together. Central to our framework is the notion of a graded category which we extend here, introducing graded Freyd categories which provide a semantics that can interpret many examples of augmented program logics from the literature. We leverage coherent fibrations to model the base assertion language, and thus the overall setting is also fibrational.

References

  1. Atkey, R.: Parameterised notions of computation. J. Funct. Program. 19(3-4), 335–376 (2009). https://doi.org/10.1017/S095679680900728X

  2. Barthe, G., Gaboardi, M., Grégoire, B., Hsu, J., Strub, P.: Proving differential privacy via probabilistic couplings. In: 2016 31st Annual ACM/IEEE Symposium on Logic in Computer Science (LICS). pp. 1–10 (2016). https://doi.org/10.1145/2933575.2934554

  3. Barthe, G.: An introduction to relational program verification (2020), http://software.imdea.org/~gbarthe/__introrelver.pdf, working Draft

  4. Barthe, G., Gaboardi, M., Arias, E.J.G., Hsu, J., Roth, A., Strub, P.: Higher-order approximate relational refinement types for mechanism design and differential privacy. In: Rajamani, S.K., Walker, D. (eds.) Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015. pp. 55–68. ACM (2015). https://doi.org/10.1145/2676726.2677000

  5. Barthe, G., Gaboardi, M., Grégoire, B., Hsu, J., Strub, P.: A Program Logic for Union Bounds. In: 43rd International Colloquium on Automata, Languages, and Programming, ICALP 2016, July 11-15, 2016, Rome, Italy. pp. 107:1–107:15 (2016). https://doi.org/10.4230/LIPIcs.ICALP.2016.107

  6. Barthe, G., Köpf, B., Olmedo, F., Zanella-Béguelin, S.: Probabilistic relational reasoning for differential privacy. ACM Trans. Progr. Lang. Syst. 35(3), 9:1–9:49 (Nov 2013). https://doi.org/10.1145/2492061

  7. Brunel, A., Gaboardi, M., Mazza, D., Zdancewic, S.: A core quantitative coeffect calculus. In: Shao, Z. (ed.) Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014, ETAPS 2014, Grenoble, France, April 5-13, 2014, Proceedings. Lecture Notes in Computer Science, vol. 8410, pp. 351–370. Springer (2014). https://doi.org/10.1007/978-3-642-54833-8_19

  8. Carbonneaux, Q., Hoffmann, J., Shao, Z.: Compositional certified resource bounds. In: Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, Portland, OR, USA, June 15-17, 2015. pp. 467–478 (2015). https://doi.org/10.1145/2737924.2737955

  9. Crole, R.L.: Categories for types. Cambridge University Press (1993)

    Google Scholar 

  10. Day, B.: Construction of Biclosed Categories. Ph.D. thesis, School of Mathematics of the University of New South Wales (1970)

    Google Scholar 

  11. Filinski, A.: Controlling Effects. Ph.D. thesis, Carnegie Mellon University (1996)

    Google Scholar 

  12. Floyd, R.W.: Assigning meanings to programs. Proceedings of Symposium on Applied Mathematics 19, 19–32 (1967). https://doi.org/10.1007/978-94-011-1793-7_4

  13. Fujii, S., Katsumata, S.y., Mellies, P.A.: Towards a formal theory of graded monads. In: International Conference on Foundations of Software Science and Computation Structures. pp. 513–530. Springer (2016). https://doi.org/10.1007/978-3-662-49630-5_30

  14. Gaboardi, M., Katsumata, S., Orchard, D., Sato, T.: Graded Hoare Logic and its Categorical Semantics. CoRR abs/2007.11235 (2020), https://arxiv.org/abs/2007.11235

  15. Gaboardi, M., Katsumata, S., Orchard, D.A., Breuvart, F., Uustalu, T.: Combining effects and coeffects via grading. In: Garrigue, J., Keller, G., Sumii, E. (eds.) Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP 2016, Nara, Japan, September 18-22, 2016. pp. 476–489. ACM (2016). https://doi.org/10.1145/2951913.2951939

  16. Ghica, D.R., Smith, A.I.: Bounded linear types in a resource semiring. In: Shao, Z. (ed.) Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2014, Grenoble, France, April 5-13, 2014, Proceedings. Lecture Notes in Computer Science, vol. 8410, pp. 331–350. Springer (2014). https://doi.org/10.1007/978-3-642-54833-8_18

  17. Gibbons, J.: Comprehending ringads - for phil wadler, on the occasion of his 60th birthday. In: Lindley, S., McBride, C., Trinder, P.W., Sannella, D. (eds.) A List of Successes That Can Change the World - Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday. Lecture Notes in Computer Science, vol. 9600, pp. 132–151. Springer (2016). https://doi.org/10.1007/978-3-319-30936-1_7

  18. Goncharov, S., Schröder, L.: A Relatively Complete Generic Hoare Logic for Order-Enriched Effects. In: 28th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2013, New Orleans, LA, USA, June 25-28, 2013. pp. 273–282. IEEE Computer Society (2013). https://doi.org/10.1109/LICS.2013.33

  19. Goubault-Larrecq, J., Lasota, S., Nowak, D.: Logical relations for monadic types. Mathematical Structures in Computer Science 18(6), 1169–1217 (2008). https://doi.org/10.1017/S0960129508007172

  20. Hasuo, I.: Generic weakest precondition semantics from monads enriched with order. Theoretical Computer Science 604, 2 – 29 (2015). https://doi.org/10.1016/j.tcs.2015.03.047, coalgebraic Methods in Computer Science

  21. Ivašković, A., Mycroft, A., Orchard, D.: Data-Flow Analyses as Effects and Graded Monads. In: Ariola, Z.M. (ed.) 5th International Conference on Formal Structures for Computation and Deduction (FSCD 2020). Leibniz International Proceedings in Informatics (LIPIcs), vol. 167, pp. 15:1–15:23. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany (2020). https://doi.org/10.4230/LIPIcs.FSCD.2020.15

  22. Jacobs, B.: Categorical Logic and Type Theory. Elsevier (1999)

    Google Scholar 

  23. Jacobs, B.: Dijkstra and Hoare monads in monadic computation. Theor. Comput. Sci. 604, 30–45 (2015). https://doi.org/10.1016/j.tcs.2015.03.020

  24. Katsumata, S.: Parametric effect monads and semantics of effect systems. In: Jagannathan, S., Sewell, P. (eds.) The 41st Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, San Diego, CA, USA, January 20-21, 2014. pp. 633–646. ACM (2014). https://doi.org/10.1145/2535838.2535846

  25. Katsumata, S.: A Double Category Theoretic Analysis of Graded Linear Exponential Comonads. In: Baier, C., Lago, U.D. (eds.) Foundations of Software Science and Computation Structures - 21st International Conference, FOSSACS 2018, ETAPS 2018, Thessaloniki, Greece, April 14-20, 2018, Proceedings. Lecture Notes in Computer Science, vol. 10803, pp. 110–127. Springer (2018). https://doi.org/10.1007/978-3-319-89366-2_6

  26. Katsumata, S., Sato, T., Uustalu, T.: Codensity lifting of monads and its dual. Logical Methods in Computer Science 14(4) (2018). https://doi.org/10.23638/LMCS-14(4:6)2018

  27. Kura, S.: Graded Algebraic Theories. In: International Conference on Foundations of Software Science and Computation Structures. pp. 401–421. Springer (2020). https://doi.org/10.1007/978-3-030-45231-5_21

  28. Levy, P.B.: Locally graded categories. Slides available at http://www.cs.bham.ac.uk/~pbl/papers/locgrade.pdf (2019)

  29. Maillard, K., Ahman, D., Atkey, R., Martínez, G., Hritcu, C., Rivas, E., Tanter, É.: Dijkstra monads for all. Proc. ACM Program. Lang. 3(ICFP), 104:1–104:29 (2019). https://doi.org/10.1145/3341708

  30. Maillard, K., Hritcu, C., Rivas, E., Muylder, A.V.: The next 700 relational program logics. Proc. ACM Program. Lang. 4(POPL), 4:1–4:33 (2020). https://doi.org/10.1145/3371072

  31. Martin, U., Mathiesen, E.A., Oliva, P.: Hoare Logic in the Abstract. In: Ésik, Z. (ed.) Computer Science Logic. pp. 501–515. Springer Berlin Heidelberg, Berlin, Heidelberg (2006). https://doi.org/10.1007/11874683_33

  32. Melliès, P., Zeilberger, N.: Functors are Type Refinement Systems. In: Rajamani, S.K., Walker, D. (eds.) Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015. pp. 3–16. ACM (2015). https://doi.org/10.1145/2676726.2676970

  33. Milius, S., Pattinson, D., Schröder, L.: Generic Trace Semantics and Graded Monads. In: Moss, L.S., Sobocinski, P. (eds.) 6th Conference on Algebra and Coalgebra in Computer Science (CALCO 2015). Leibniz International Proceedings in Informatics (LIPIcs), vol. 35, pp. 253–269. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik (2015). https://doi.org/10.4230/LIPIcs.CALCO.2015.253

  34. Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991). https://doi.org/10.1016/0890-5401(91)90052-4

  35. Molnar, D., Piotrowski, M., Schultz, D., Wagner, D.A.: The program counter security model: Automatic detection and removal of control-flow side channel attacks. In: Won, D., Kim, S. (eds.) Information Security and Cryptology - ICISC 2005, 8th International Conference, Seoul, Korea, December 1-2, 2005, Revised Selected Papers. Lecture Notes in Computer Science, vol. 3935, pp. 156–168. Springer (2005). https://doi.org/10.1007/11734727_14

  36. Mycroft, A., Orchard, D.A., Petricek, T.: Effect Systems Revisited - Control-Flow Algebra and Semantics. In: Probst, C.W., Hankin, C., Hansen, R.R. (eds.) Semantics, Logics, and Calculi - Essays Dedicated to Hanne Riis Nielson and Flemming Nielson on the Occasion of Their 60th Birthdays. Lecture Notes in Computer Science, vol. 9560, pp. 1–32. Springer (2016). https://doi.org/10.1007/978-3-319-27810-0_1

  37. Nielson, H.R.: A Hoare-like proof system for analysing the computation time of programs. Science of Computer Programming 9(2), 107–136 (1987). https://doi.org/10.1016/0167-6423(87)90029-3

  38. Nielson, H.R., Nielson, F.: Semantics with applications, vol. 104. Springer (1992)

    Google Scholar 

  39. Olmedo, F.: Approximate Relational Reasoning for Probabilistic Programs. Ph.D. thesis, Technical University of Madrid (2014)

    Google Scholar 

  40. Orchard, D., Liepelt, V., III, H.E.: Quantitative program reasoning with graded modal types. Proc. ACM Program. Lang. 3(ICFP), 110:1–110:30 (2019). https://doi.org/10.1145/3341714

  41. Orchard, D., Wadler, P., III, H.E.: Unifying graded and parameterised monads. In: New, M.S., Lindley, S. (eds.) Proceedings Eighth Workshop on Mathematically Structured Functional Programming, MSFP@ETAPS 2020, Dublin, Ireland, 25th April 2020. EPTCS, vol. 317, pp. 18–38 2020). https://doi.org/10.4204/EPTCS.317.2

  42. Orchard, D.A., Petricek, T., Mycroft, A.: The semantic marriage of monads and effects. CoRR abs/1401.5391 (2014), http://arxiv.org/abs/1401.5391

  43. Petricek, T., Orchard, D.A., Mycroft, A.: Coeffects: Unified static analysis of context-dependence. In: Fomin, F.V., Freivalds, R., Kwiatkowska, M.Z., Peleg, D. (eds.) Automata, Languages, and Programming - 40th International Colloquium, ICALP 2013, Riga, Latvia, July 8-12, 2013, Proceedings, Part II. Lecture Notes in Computer Science, vol. 7966, pp. 385–397. Springer (2013). https://doi.org/10.1007/978-3-642-39212-2_35

  44. Petricek, T., Orchard, D.A., Mycroft, A.: Coeffects: a calculus of context-dependent computation. In: Jeuring, J., Chakravarty, M.M.T. (eds.) Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014. pp. 123–135. ACM (2014). https://doi.org/10.1145/2628136.2628160

  45. Pitts, A.M.: Categorical logic. Tech. rep., University of Cambridge, Computer Laboratory (1995)

    Google Scholar 

  46. Power, J.: Generic models for computational effects. Theoretical Computer Science 364(2), 254–269 (2006). https://doi.org/10.1016/j.tcs.2006.08.006

  47. Power, J., Thielecke, H.: Environments, continuation semantics and indexed categories. In: Abadi, M., Ito, T. (eds.) Theoretical Aspects of Computer Software. pp. 391–414. Springer Berlin Heidelberg, Berlin, Heidelberg (1997)

    Google Scholar 

  48. Sato, T.: Approximate Relational Hoare Logic for Continuous Random Samplings. In: Birkedal, L. (ed.) The Thirty-second Conference on the Mathematical Foundations of Programming Semantics, MFPS 2016, Carnegie Mellon University, Pittsburgh, PA, USA, May 23-26, 2016. Electronic Notes in Theoretical Computer Science, vol. 325, pp. 277–298. Elsevier (2016). https://doi.org/10.1016/j.entcs.2016.09.043

  49. Sato, T., Barthe, G., Gaboardi, M., Hsu, J., Katsumata, S.: Approximate Span Liftings: Compositional Semantics for Relaxations of Differential Privacy. In: 34th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2019, Vancouver, BC, Canada, June 24-27, 2019. pp. 1–14 (2019). https://doi.org/10.1109/LICS.2019.8785668

  50. Smirnov, A.: Graded monads and rings of polynomials. J. Math. Sci. 151(3), 3032–3051 (2008). https://doi.org/10.1007/s10958-008-9013-7

  51. Staton, S.: Freyd categories are Enriched Lawvere Theories. Electronic Notes in Theoretical Computer Science 303, 197 – 206 (2014). https://doi.org/10.1016/j.entcs.2014.02.010, proceedings of the Workshop on Algebra, Coalgebra and Topology (WACT 2013)

  52. Staton, S.: Commutative semantics for probabilistic programming. In: Yang, H. (ed.) Programming Languages and Systems - 26th European Symposium on Programming, ESOP 2017, ETAPS 2017, Uppsala, Sweden, April 22-29, 2017, Proceedings. Lecture Notes in Computer Science, vol. 10201, pp. 855–879. Springer (2017). https://doi.org/10.1007/978-3-662-54434-1_32

  53. Tate, R.: The sequential semantics of producer effect systems. In: Giacobazzi, R., Cousot, R. (eds.) The 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’13, Rome, Italy - January 23 - 25, 2013. pp. 15–26. ACM (2013). https://doi.org/10.1145/2429069.2429074

  54. Wood, R.J.: V-indexed categories, chap. 2, pp. 126–140. No. 661 in Lecture Notes in Mathematics, Springer (1978). https://doi.org/10.1007/BFb0061362

  55. Zhang, J.J.: Twisted graded algebras and equivalences of graded categories. Proceedings of the London Mathematical Society 3(2), 281–311 (1996). https://doi.org/10.1112/plms/s3-72.2.281

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Marco Gaboardi .

Editor information

Editors and Affiliations

Rights and permissions

Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.

The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

Reprints and Permissions

Copyright information

© 2021 The Author(s)

About this paper

Verify currency and authenticity via CrossMark

Cite this paper

Gaboardi, M., Katsumata, Sy., Orchard, D., Sato, T. (2021). Graded Hoare Logic and its Categorical Semantics. In: Yoshida, N. (eds) Programming Languages and Systems. ESOP 2021. Lecture Notes in Computer Science(), vol 12648. Springer, Cham. https://doi.org/10.1007/978-3-030-72019-3_9

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-72019-3_9

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-72018-6

  • Online ISBN: 978-3-030-72019-3

  • eBook Packages: Computer ScienceComputer Science (R0)