Skip to main content

The Matrix Reproved (Verification Pearl)

  • Conference paper
  • First Online:
Verified Software. Theories, Tools, and Experiments (VSTTE 2016)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 9971))

  • 527 Accesses

Abstract

In this paper we describe a complete solution for the first challenge of the VerifyThis 2016 competition held at the 18th ETAPS Forum. We present the proof of two variants for the multiplication of matrices: a naive version using three nested loops and the Strassen’s algorithm. The proofs are conducted using the Why3 platform for deductive program verification, and automated theorem provers to discharge proof obligations. In order to specify and prove the two multiplication algorithms, we develop a new Why3 theory of matrices and apply the proof by reflection methodology.

This work is partly supported by the Bware (ANR-12-INSE-0010, http://bware.lri.fr/) and VOCAL (ANR-15-CE25-008, https://vocal.lri.fr/) projects of the French national research organization (ANR) and by the Portuguese Foundation for the Sciences and Technology (grant FCT-SFRH/BD/99432/2014).

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

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    http://toccata.lri.fr/gallery/verifythis_2016_matrix_multiplication.en.html.

References

  1. Bertot, Y., Castéran, P.: Interactive Theorem Proving and Program Development. Springer, Heidelberg (2004)

    Book  MATH  Google Scholar 

  2. Clochard, M., Filliâtre, J.-C., Marché, C., Paskevich, A.: Formalizing semantics with an automatic program verifier. In: Giannakopoulou, D., Kroening, D. (eds.) VSTTE 2014. LNCS, vol. 8471, pp. 37–51. Springer, Heidelberg (2014). doi:10.1007/978-3-319-12154-3_3

    Google Scholar 

  3. Dénès, M., Mörtberg, A., Siles, V.: A refinement-based approach to computational algebra in Coq. In: Beringer, L., Felty, A. (eds.) ITP 2012. LNCS, vol. 7406, pp. 83–98. Springer, Heidelberg (2012). doi:10.1007/978-3-642-32347-8_7

    Chapter  Google Scholar 

  4. Filliâtre, J.-C.: One logic to use them all. In: Bonacina, M.P. (ed.) CADE 2013. LNCS (LNAI), vol. 7898, pp. 1–20. Springer, Heidelberg (2013). doi:10.1007/978-3-642-38574-2_1

    Chapter  Google Scholar 

  5. Filliâtre, J.-C., Gondelman, L., Paskevich, A.: The spirit of ghost code. In: Biere, A., Bloem, R. (eds.) CAV 2014. LNCS, vol. 8559, pp. 1–16. Springer, Heidelberg (2014). doi:10.1007/978-3-319-08867-9_1

    Google Scholar 

  6. Filliâtre, J.-C., Paskevich, A.: Why3 — where programs meet provers. In: Felleisen, M., Gardner, P. (eds.) ESOP 2013. LNCS, vol. 7792, pp. 125–128. Springer, Heidelberg (2013). doi:10.1007/978-3-642-37036-6_8

    Chapter  Google Scholar 

  7. Palomo-Lozano, F., Medina-Bulo, I., Alonso-Jiménez, J.: Certification of matrix multiplication algorithms. Strassen’s algorithm in ACL2. In: Supplemental Proceedings of the 14th International Conference on Theorem Proving in Higher Order Logics, pp. 283–298. Edinburgh, Scotland (2001)

    Google Scholar 

  8. Srivastava, S., Gulwani, S., Foster, J.S.: From program verification to program synthesis. In: Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2010, pp. 313–326. ACM, New York (2010). doi:10.1145/1706299.1706337

Download references

Acknowledgements

We thank Arthur Charguéraud, Jean-Christophe Filliâtre, and Claude Marché for their comments and remarks.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Léon Gondelman .

Editor information

Editors and Affiliations

Appendices

A Challenge 1 Original Text

Consider the following pseudocode algorithm, which is naive implementation of matrix multiplication. For simplicity we assume that the matrices are square.

figure s

Tasks.

  1. 1.

    Provide a specification to describe the behaviour of this algorithm, and prove that it correctly implements its specification.

  2. 2.

    Show that matrix multiplication is associative, i.e., the order in which matrices are multiplied can be disregarded: \(A(BC) = (AB)C\). To show this, you should write a program that performs the two different computations, and then prove that the result of the two computations is always the same.

  3. 3.

    [Optional, if time permits] In the literature, there exist many proposals for more efficient matrix multiplication algorithms. Strassen’s algorithm was one of the first. The key idea of the algorithm is to use a recursive algorithm that reduces the number of multiplications on submatrices (from 8 to 7), see Strassen_algorithm on wikipedia for an explanation. A relatively clean Java implementation (and Python and C++) can be found here. Prove that the naive algorithm above has the same behaviour as Strassen’s algorithm. Proving it for a restricted case, like a \(2\times 2\) matrix should be straightforward, the challenge is to prove it for arbitrary matrices with size \(2^n\).

B Strassen Recursion Scheme

Given three matrices A, B and \(M=AB\) partitioned as:

$$\begin{aligned} \begin{array}{ccc} A= \left[ \begin{array}{c|c} A_{1,1} &{} A_{1,2}\\ \hline A_{2,1} &{} A_{2,2} \\ \end{array} \right] &{} B= \left[ \begin{array}{c|c} B_{1,1} &{} B_{1,2}\\ \hline B_{2,1} &{} B_{2,2} \\ \end{array} \right] &{} M= \left[ \begin{array}{c|c} M_{1,1} &{} M_{1,2}\\ \hline M_{2,1} &{} M_{2,2} \\ \end{array} \right] \end{array} \end{aligned}$$

Then we can compute the partition of M from the two others as follow:

$$\begin{aligned} \begin{array}{lllrll} M_{1,1} &{} = &{} X_1 + X_4 - X_5 + X_7 &{} M_{2,1} &{} = &{} X_2 + X_4 \\ M_{1,2} &{} = &{} X_3 + X_5 &{} M_{2,2} &{} = &{} X_1 - X_2 + X_3 + X_6 \\ \end{array} \end{aligned}$$

With

$$\begin{aligned} \begin{array}{llrlrlrl} X_1 &{} = &{} (A_{1,1}+A_{2,2})&{}(B_{1,1}+B_{2,2}) &{} X_2 &{} = &{} (A_{2,1}+A_{2,2})&{}B_{1,1} \\ X_3 &{} = &{} A_{1,1}&{}(B_{1,2}-B_{2,2}) &{} X_4 &{} = &{} A_{2,2}&{}(B_{2,1} - B_{1,1}) \\ X_5 &{} = &{} (A_{1,1}+A_{1,2})&{}B_{2,2} &{} X_6 &{} = &{} (A_{2,1}-A_{1,1})&{}(B_{1,1}+B_{1,2}) \\ X_7 &{} = &{} (A_{1,2} - A_{2,2})&{}(B_{2,1}+B_{2,2}) &{} &{} &{} &{} \end{array} \end{aligned}$$

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing AG

About this paper

Cite this paper

Clochard, M., Gondelman, L., Pereira, M. (2016). The Matrix Reproved (Verification Pearl). In: Blazy, S., Chechik, M. (eds) Verified Software. Theories, Tools, and Experiments. VSTTE 2016. Lecture Notes in Computer Science(), vol 9971. Springer, Cham. https://doi.org/10.1007/978-3-319-48869-1_8

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-48869-1_8

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-48868-4

  • Online ISBN: 978-3-319-48869-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics