Skip to main content
Top
Published in: Journal of Automated Reasoning 4/2020

03-10-2019

An Assertional Proof of Red–Black Trees Using Dafny

Author: Ricardo Peña

Published in: Journal of Automated Reasoning | Issue 4/2020

Log in

Activate our intelligent search to find suitable subject content or patents.

search-config
loading …

Abstract

Red–black trees are convenient data structures for inserting, searching, and deleting keys with logarithmic costs. However, keeping them balanced requires careful programming, and sometimes to deal with a high number of cases. In this paper, we present a functional version of a red–black tree variant called left-leaning, due to R. Sedgewick, which reduces the number of cases to be dealt with to a few ones. The code is rather concise, but reasoning about its correctness requires a rather large effort. We provide formal preconditions and postconditions for all the functions, prove their termination, and that the code satisfies its specifications. The proof is assertional, and consists of interspersing enough assertions among the code in order to help the verification tool to discharge the proof obligations. We have used the Dafny verification platform, which provides the programming language, the assertion language, and the verifier. To our knowledge, this is the first assertional proof of this data structure, and also one of the few ones including deletion.

Dont have a licence yet? Then find out more about our products and how to get one now:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Literature
1.
go back to reference Adelson-Velskii, U.M., Landis, E.M.: An algorithm for the organization of information. In: Soviet Mathematics Doklady pp. 1259–1263 (1962) Adelson-Velskii, U.M., Landis, E.M.: An algorithm for the organization of information. In: Soviet Mathematics Doklady pp. 1259–1263 (1962)
2.
go back to reference Andersson, A.: Balanced search trees made simple. In: Dehne F., Sack JR., Santoro N., Whitesides S. (eds) Algorithms and Data Structures. WADS 1993. Lecture Notes in Computer Science, vol 709, pp 60–71. Springer, Berlin (1993) Andersson, A.: Balanced search trees made simple. In: Dehne F., Sack JR., Santoro N., Whitesides S. (eds) Algorithms and Data Structures. WADS 1993. Lecture Notes in Computer Science, vol 709, pp 60–71. Springer, Berlin (1993)
4.
go back to reference Arge, L., Sedgewick, R., Seidel, R.: 08081 Abstracts collection-data structures. In: Arge, L., Sedgewick, R., Seidel, R. (eds.) Data Structures, 17.02.-22.02.2008, Dagstuhl Seminar Proceedings, vol. 08081. Internationales Begegnungs- und Forschungszentrum für Informatik (IBFI), Schloss Dagstuhl, Germany (2008). http://drops.dagstuhl.de/opus/volltexte/2008/1532/ Arge, L., Sedgewick, R., Seidel, R.: 08081 Abstracts collection-data structures. In: Arge, L., Sedgewick, R., Seidel, R. (eds.) Data Structures, 17.02.-22.02.2008, Dagstuhl Seminar Proceedings, vol. 08081. Internationales Begegnungs- und Forschungszentrum für Informatik (IBFI), Schloss Dagstuhl, Germany (2008). http://​drops.​dagstuhl.​de/​opus/​volltexte/​2008/​1532/​
7.
go back to reference Bertot, Y., Casteran, P.: Interactive Theorem Proving and Program Development Coq’Art: The Calculus of Inductive Constructions. Texts in Theoretical Computer Science. An EATCS Series. Springer, New York (2004)CrossRef Bertot, Y., Casteran, P.: Interactive Theorem Proving and Program Development Coq’Art: The Calculus of Inductive Constructions. Texts in Theoretical Computer Science. An EATCS Series. Springer, New York (2004)CrossRef
8.
go back to reference Bobot, F., Filliâtre, J.C., Marché, C., Melquiond, G., Paskevich, A.: The Why3 platform. Version 0.86.1. University Paris-Sud, CNRS, Inria (2015) Bobot, F., Filliâtre, J.C., Marché, C., Melquiond, G., Paskevich, A.: The Why3 platform. Version 0.86.1. University Paris-Sud, CNRS, Inria (2015)
9.
go back to reference Bobot, F., Filliâtre, J.C., Marché, C., Paskevich, A.: Why3: shepherd your herd of provers. In: Boogie 2011: First International Workshop on Intermediate Verification Languages, pp. 53–64. Wroclaw, Poland (2011). https://hal.inria.fr/hal-00790310 Bobot, F., Filliâtre, J.C., Marché, C., Paskevich, A.: Why3: shepherd your herd of provers. In: Boogie 2011: First International Workshop on Intermediate Verification Languages, pp. 53–64. Wroclaw, Poland (2011). https://​hal.​inria.​fr/​hal-00790310
10.
go back to reference Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 2nd edn. MIT Press, Cambridge (2001)MATH Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 2nd edn. MIT Press, Cambridge (2001)MATH
11.
go back to reference de Moura, L.M., Bjørner, N.: Z3: an efficient SMT solver. In: Ramakrishnan, C.R., Rehof, J. (eds.) Tools and Algorithms for the Construction and Analysis of Systems, 14th International Conference, TACAS 2008, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2008, Budapest, Hungary, March 29–April 6, 2008 Proceedings. Lecture Notes in Computer Science, vol. 4963, pp. 337–340. Springer, New York (2008). https://doi.org/10.1007/978-3-540-78800-3-24 de Moura, L.M., Bjørner, N.: Z3: an efficient SMT solver. In: Ramakrishnan, C.R., Rehof, J. (eds.) Tools and Algorithms for the Construction and Analysis of Systems, 14th International Conference, TACAS 2008, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2008, Budapest, Hungary, March 29–April 6, 2008 Proceedings. Lecture Notes in Computer Science, vol. 4963, pp. 337–340. Springer, New York (2008). https://​doi.​org/​10.​1007/​978-3-540-78800-3-24
12.
go back to reference Filliâtre, J., Letouzey, P.: Functors for proofs and programs. In: Schmidt, D.A. (ed.) Programming Languages and Systems, 13th European Symposium on Programming, ESOP 2004, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2004, Barcelona, Spain, March 29–April 2, 2004, Proceedings. Lecture Notes in Computer Science, vol. 2986, pp. 370–384. Springer, New York (2004). https://doi.org/10.1007/978-3-540-24725-8-26 Filliâtre, J., Letouzey, P.: Functors for proofs and programs. In: Schmidt, D.A. (ed.) Programming Languages and Systems, 13th European Symposium on Programming, ESOP 2004, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2004, Barcelona, Spain, March 29–April 2, 2004, Proceedings. Lecture Notes in Computer Science, vol. 2986, pp. 370–384. Springer, New York (2004). https://​doi.​org/​10.​1007/​978-3-540-24725-8-26
13.
go back to reference Guibas, L.J., Sedgewick, R.: A dichromatic framework for balanced trees. In: 19th Annual Symposium on Foundations of Computer Science, Ann Arbor, Michigan, USA, 16–18 October 1978, pp. 8–21. IEEE Computer Society (1978). https://doi.org/10.1109/SFCS.1978.3 Guibas, L.J., Sedgewick, R.: A dichromatic framework for balanced trees. In: 19th Annual Symposium on Foundations of Computer Science, Ann Arbor, Michigan, USA, 16–18 October 1978, pp. 8–21. IEEE Computer Society (1978). https://​doi.​org/​10.​1109/​SFCS.​1978.​3
16.
go back to reference Jones, C.B.: Systematic Software Development Using VDM. Prentice Hall International Series in Computer Science, 2nd edn. Prentice Hall, Upper Saddle River (1991)MATH Jones, C.B.: Systematic Software Development Using VDM. Prentice Hall International Series in Computer Science, 2nd edn. Prentice Hall, Upper Saddle River (1991)MATH
17.
go back to reference Leino, K.R.M.: Dafny: an automatic program verifier for functional correctness. In: Clarke, E.M., Voronkov, A. (eds.) Logic for Programming, Artificial Intelligence, and Reasoning—16th International Conference, LPAR-16, Dakar, Senegal, April 25–May 1, 2010, Revised Selected Papers. Lecture Notes in Computer Science, vol. 6355, pp. 348–370. Springer, New York (2010). https://doi.org/10.1007/978-3-642-17511-4-20 Leino, K.R.M.: Dafny: an automatic program verifier for functional correctness. In: Clarke, E.M., Voronkov, A. (eds.) Logic for Programming, Artificial Intelligence, and Reasoning—16th International Conference, LPAR-16, Dakar, Senegal, April 25–May 1, 2010, Revised Selected Papers. Lecture Notes in Computer Science, vol. 6355, pp. 348–370. Springer, New York (2010). https://​doi.​org/​10.​1007/​978-3-642-17511-4-20
18.
go back to reference Leino, K.R.M.: Developing verified programs with Dafny. In: Brosgol, B., Boleng, J., Taft, S.T. (eds.) ACM Conference on High Integrity Language Technology, HILT’12, pp. 9–10. ACM (2012) Leino, K.R.M.: Developing verified programs with Dafny. In: Brosgol, B., Boleng, J., Taft, S.T. (eds.) ACM Conference on High Integrity Language Technology, HILT’12, pp. 9–10. ACM (2012)
20.
go back to reference Nipkow, T.: Automatic functional correctness proofs for functional search trees. In: Blanchette, J., Merz, S. (eds) Interactive Theorem Proving. ITP 2016. Lecture Notes in Computer Science, vol. 9807, pp. 307–322. Springer, Cham (2016) Nipkow, T.: Automatic functional correctness proofs for functional search trees. In: Blanchette, J., Merz, S. (eds) Interactive Theorem Proving. ITP 2016. Lecture Notes in Computer Science, vol. 9807, pp. 307–322. Springer, Cham (2016)
21.
go back to reference Nipkow, T., Paulson, L., Wenzel, M.: Isabelle/HOL. A Proof Assistant for Higher-Order Logic. LNCS, vol. 2283. Springer, New York (2002)MATH Nipkow, T., Paulson, L., Wenzel, M.: Isabelle/HOL. A Proof Assistant for Higher-Order Logic. LNCS, vol. 2283. Springer, New York (2002)MATH
22.
go back to reference Okasaki, C.: Red–black trees in a functional setting. J. Funct. Program. 9(4), 471–477 (1999)CrossRef Okasaki, C.: Red–black trees in a functional setting. J. Funct. Program. 9(4), 471–477 (1999)CrossRef
23.
go back to reference Polikarpova, N., Tschannen, J., Furia, C.A.: A fully verified container library. In: Bjørner, N., de Boer, F.S. (eds.) FM 2015: Formal Methods—20th International Symposium, Oslo, Norway, June 24–26, 2015 Proceedings. Lecture Notes in Computer Science, vol. 9109, pp. 414–434. Springer, New York (2015). https://doi.org/10.1007/978-3-319-19249-9-26 Polikarpova, N., Tschannen, J., Furia, C.A.: A fully verified container library. In: Bjørner, N., de Boer, F.S. (eds.) FM 2015: Formal Methods—20th International Symposium, Oslo, Norway, June 24–26, 2015 Proceedings. Lecture Notes in Computer Science, vol. 9109, pp. 414–434. Springer, New York (2015). https://​doi.​org/​10.​1007/​978-3-319-19249-9-26
24.
go back to reference Reade, C.M.P.: Balanced trees with removals: an exercise in rewriting and proof. Sci. Comput. Program. 18, 181–204 (1992)MathSciNetCrossRef Reade, C.M.P.: Balanced trees with removals: an exercise in rewriting and proof. Sci. Comput. Program. 18, 181–204 (1992)MathSciNetCrossRef
25.
go back to reference Sedgewick, R., Wayne, K.: Algorithms, 4th edn. Addison-Wesley, Boston (2011) Sedgewick, R., Wayne, K.: Algorithms, 4th edn. Addison-Wesley, Boston (2011)
26.
go back to reference Stepney, S., Cooper, D., Woodcock, J.: More powerful Z data refinement: pushing the state of the art in industrial refinement. In: Bowen, J.P., Fett, A., Hinchey, M.G. (eds.) ZUM ’98: The Z Formal Specification Notation, 11th International Conference of Z Users, Berlin, Germany, September 24–26, 1998 Proceedings. Lecture Notes in Computer Science, vol. 1493, pp. 284–307. Springer, New York (1998). https://doi.org/10.1007/978-3-540-49676-2-20 Stepney, S., Cooper, D., Woodcock, J.: More powerful Z data refinement: pushing the state of the art in industrial refinement. In: Bowen, J.P., Fett, A., Hinchey, M.G. (eds.) ZUM ’98: The Z Formal Specification Notation, 11th International Conference of Z Users, Berlin, Germany, September 24–26, 1998 Proceedings. Lecture Notes in Computer Science, vol. 1493, pp. 284–307. Springer, New York (1998). https://​doi.​org/​10.​1007/​978-3-540-49676-2-20
27.
go back to reference Weiss, M.A.: Data Structures and Problem Solving Using Java. Addison Wesley, Boston (1998)CrossRef Weiss, M.A.: Data Structures and Problem Solving Using Java. Addison Wesley, Boston (1998)CrossRef
Metadata
Title
An Assertional Proof of Red–Black Trees Using Dafny
Author
Ricardo Peña
Publication date
03-10-2019
Publisher
Springer Netherlands
Published in
Journal of Automated Reasoning / Issue 4/2020
Print ISSN: 0168-7433
Electronic ISSN: 1573-0670
DOI
https://doi.org/10.1007/s10817-019-09534-y

Other articles of this Issue 4/2020

Journal of Automated Reasoning 4/2020 Go to the issue

Premium Partner