Skip to main content

A Sound and Complete Hoare Logic for Dynamically-Typed, Object-Oriented Programs

  • Chapter
  • First Online:
Theory and Practice of Formal Methods

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

Abstract

A simple dynamically-typed, (purely) object-oriented language is defined. A structural operational semantics as well as a Hoare-style program logic for reasoning about programs in the language in multiple notions of correctness are given. The Hoare logic is proved to be both sound and (relative) complete and is – to the best of our knowledge – the first such logic presented for a dynamically-typed language.

This work is supported by the German Research Foundation through the Research Training Group (DFG GRK 1765) SCARE (www.scare.uni-oldenburg.de).

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

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

Notes

  1. 1.

    One may ask whether it is at all possible to obtain a sound and relatively complete Hoare logic for dyn in light of Clarke’s incompleteness result [5]. However, Clarke’s argument is not applicable to dyn for various reasons elaborated in [7, Appendix C].

  2. 2.

    Assuming an infinite sequence of already existing, but deactivated objects, object creation boils down to picking the next one and marking it as “activated”.

  3. 3.

    Other methods to distinguish the values true and false are conceivable.

  4. 4.

    The predicate \(\mathbb {N}(o,n)\) is recursive. However, the technique used for proving the case for primitive recursion in [7, Lemma 5], allows expressing it in AL.

  5. 5.

    \(@\mathrm {pred}\) and \(@\mathrm {to\_ref}\) are instance variables of the classes num and bool, respectively.

  6. 6.

    We use the polymorphic version for the sake of readability although the type system of AL does not allow polymorphism. However, polymorphic functions can be emulated using one version for each element type.

References

  1. Apt, K.R.: Ten years of hoare’s logic: a survey - Part I. ACM Trans. Program. Lang. Syst. 3(4), 431–483 (1981). http://www.cs.cornell.edu/Courses/cs6860/2010fa/Handouts/Apt10years.pdf

    Article  MATH  Google Scholar 

  2. Apt, K.R., de Boer, F.S., Olderog, E.R.: Verification of Sequential and Concurrent Programs. Texts in Computer Science, 3rd edn., p. 502. Springer, New York (2009)

    Google Scholar 

  3. de Boer, F.S., de Gouw, S.: Being and change: reasoning about invariance. In: Meyer, R., Platzer, A., Wehrheim, H. (eds.) Correct System Design. LNCS, vol. 9360, pp. 191–204. Springer, Heidelberg (2015). doi:10.1007/978-3-319-23506-6_13

    Chapter  Google Scholar 

  4. de Boer, F.S., Pierik, C.: How to cook a complete hoare logic for your pet OO language. In: de Boer, F.S., Bonsangue, M.M., Graf, S., de Roever, W.-P. (eds.) FMCO 2003. LNCS, vol. 3188, pp. 111–133. Springer, Heidelberg (2004)

    Chapter  Google Scholar 

  5. Clarke Jr., E.M.: Programming language constructs for which it is impossible to obtain good hoare axiom systems. J. ACM 26(1), 129–147 (1979). http://www.cs.cmu.edu/~emc/papers/Papers%20In%20Refereed%20Journals/79_impossible_hoareaxiom.pdf

    Google Scholar 

  6. Cook, S.A.: Soundness and completeness of an axiom system for program verification. SIAM J. Comput. 7(1), 70–90 (1978). http://www.cs.toronto.edu/~sacook/homepage/soundness.pdf

    Google Scholar 

  7. Engelmann, B., Olderog, E.: A Sound and Complete Hoare Logic for Dynamically-Typed, Object-Oriented Programs - Extended Version. CoRR abs/1509.08605 (2015). http://arxiv.org/abs/1509.08605

  8. Engelmann, B., Olderog, E., Flick, N.E.: Closing the Gap - Formally Verifying Dynamically Typed Programs like Statically Typed Ones Using Hoare Logic - Extended Version. CoRR abs/1501.02699 (2015). http://arxiv.org/abs/1501.02699

  9. Gardner, P., Maffeis, S., Smith, G.D.: Towards a program logic for JavaScript. In: Field, J., Hicks, M. (eds.) POPL, pp. 31–44. ACM (2012). http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.221.302

    Google Scholar 

  10. Gorelick, G.A.: A Complete Axiomatic System for Proving Assertions about Recursive and Non-Recursive Programs. Technical report 75, Department of Computer Science, University of Toronto, Canada (1975)

    Google Scholar 

  11. Hennessy, M.C.B., Plotkin, G.D.: Full abstraction for a simple programming language. Proceedings of Mathematical Foundations of Computer Science. LNCS, vol. 74, pp. 108–120. Springer, New York (1979)

    Google Scholar 

  12. Hoare, C.A.R.: An axiomatic basis for computer programming. Commun. ACM 12, 576–580, 583 (1969). https://www.cs.cmu.edu/~crary/819-f09/Hoare69.pdf

    Google Scholar 

  13. Olderog, E.R.: On the notion of expressiveness and the rule of adaptation. Theoret. Comput. Sci. 24(3), 337–347 (1983). http://www.sciencedirect.com/science/article/pii/0304397583900099

    Article  MathSciNet  MATH  Google Scholar 

  14. Plotkin, G.D.: A structural approach to operational semantics. J. Logic Algebraic Program. 60–61, 17–139 (2004). http://homepages.inf.ed.ac.uk/gdp/publications/sos_jlap.pdf

    MathSciNet  MATH  Google Scholar 

  15. Qin, S., Chawdhary, A., Xiong, W., Munro, M., Qiu, Z., Zhu, H.: Towards an Axiomatic Verification System for JavaScript. In: Proceedings of the TASE 2011, Washington, DC, pp. 133–141. IEEE (2011)

    Google Scholar 

Download references

Acknowledgements

We thank Dennis Kregel for noticing that restricting \(\mathbf {r}\) causes incompleteness and him, Nils-Erik Flick and the anonymous referees for many useful comments on prior versions of this paper.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Björn Engelmann .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this chapter

Cite this chapter

Engelmann, B., Olderog, ER. (2016). A Sound and Complete Hoare Logic for Dynamically-Typed, Object-Oriented Programs. In: Ábrahám, E., Bonsangue, M., Johnsen, E. (eds) Theory and Practice of Formal Methods. Lecture Notes in Computer Science(), vol 9660. Springer, Cham. https://doi.org/10.1007/978-3-319-30734-3_13

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-30734-3_13

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-30733-6

  • Online ISBN: 978-3-319-30734-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics