Skip to main content

Verifying the Conversion into CNF in Dafny

  • Conference paper
  • First Online:
Logic, Language, Information, and Computation (WoLLIC 2021)

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

Abstract

We present two computer-verified implementations of the CNF conversion for propositional logic. The two implementations are fully verified: functional correctness and termination is machine-checked using the Dafny language for both. The first approach is based on repeatedly applying a set of equivalences and is often presented in logic textbooks. The second approach is based on Tseitin’s transformation and is more efficient. We present the main ideas behind our formalization and we discuss the main difficulties in verifying the two algorithms.

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 59.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 79.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.

    We assume some familiarity with a system such as Dafny [15] or Why3 [6]. We give a very brief overview of Dafny in Appendix A for readers unfamiliar with Dafny.

  2. 2.

    Also spelled Tseytin.

  3. 3.

    Tseitin [24] proposes to add the negation of this literal, the initial formula being valid iff the resulting formula is unsatisfiable; modern treatments diverge [12].

References

  1. Andrici, C.-C., Ciobâcă, Ş.: Verifying the DPLL algorithm in Dafny. In: Marin, M., Craciun, A. (eds.) Proceedings Third Symposium on Working Formal Methods, FROM 2019, Timişoara, Romania, 3–5 September 2019. EPTCS, vol. 303, pp. 3–15 (2019)

    Google Scholar 

  2. Andrici, C.-C., Ciobâcă, Ş.: Who verifies the verifiers? A computer-checked implementation of the DPLL algorithm in Dafny. CoRR, arXiv:2007.10842 (2020)

  3. Barroso, P., Pereira, M., Ravara, A.: Animated logic: correct functional conversion to conjunctive normal form. In: PAAR 2020/SC-Square 2020. CEUR Workshop Proceedings, vol. 2752, pp. 1–20. CEUR-WS.org (2020)

    Google Scholar 

  4. Berger, U., Lawrence, A., Forsberg, F.N., Seisenberger, M.: Extracting verified decision procedures: DPLL and resolution. Log. Methods Comput. Sci. 11(1) (2015)

    Google Scholar 

  5. Blanchette, J.C., Fleury, M., Lammich, P., Weidenbach, C.: A verified SAT solver framework with learn, forget, restart, and incrementality. J. Autom. Reason. 61(1–4), 333–365 (2018)

    Article  Google Scholar 

  6. 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, Wrocław, Poland, pp. 53–64, August 2011. https://hal.inria.fr/hal-00790310

  7. Cohen, E., et al.: VCC: a practical system for verifying concurrent C. In: Berghofer, S., Nipkow, T., Urban, C., Wenzel, M. (eds.) TPHOLs 2009. LNCS, vol. 5674, pp. 23–42. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03359-9_2

    Chapter  Google Scholar 

  8. de la Tour, T.B.: An optimality result for clause form translation. J. Symb. Comput. 14(4), 283–302 (1992)

    Google Scholar 

  9. Fleury, M.: Optimizing a verified SAT solver. In: Badger, J.M., Rozier, K.Y. (eds.) NFM 2019. LNCS, vol. 11460, pp. 148–165. Springer, Cham (2019). https://doi.org/10.1007/978-3-030-20652-9_10

    Chapter  Google Scholar 

  10. Ford, R.L., Leino, K.R.M.: Dafny Reference Manual (2017)

    Google Scholar 

  11. Gäher, L., Kunze, F.: Mechanising complexity theory: the cook-Levin theorem in Coq. In: Cohen, L., Kaliszyk, C. (eds.) 12th International Conference on Interactive Theorem Proving (ITP 2021). Leibniz International Proceedings in Informatics (LIPIcs), Dagstuhl, Germany, vol. 193, pp. 20:1–20:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2021)

    Google Scholar 

  12. Harrison, J.: Handbook of Practical Logic and Automated Reasoning. Cambridge University Press, Cambridge (2009)

    Book  Google Scholar 

  13. Hawblitzel, C., et al.: Ironclad apps: end-to-end security via automated full-system verification. In: 11th USENIX Symposium on Operating Systems Design and Implementation, OSDI 2014, Broomfield, CO, USA, 6–8 October 2014, pp. 165–181 (2014)

    Google Scholar 

  14. Hoang, D., Moy, Y., Wallenburg, A., Chapman, R.: SPARK 2014 and gnatprove - a competition report from builders of an industrial-strength verifying compiler. Int. J. Softw. Tools Technol. Transf. 17(6), 695–707 (2015)

    Article  Google Scholar 

  15. Rustan, K., Leino, M.: Developing verified programs with Dafny. In: 35th International Conference on Software Engineering, ICSE 2013, San Francisco, CA, USA, 18–26 May 2013, pp. 1488–1490 (2013)

    Google Scholar 

  16. Rustan, K., Leino, M.: Accessible software verification with dafny. IEEE Softw. 34(6), 94–97 (2017)

    Article  Google Scholar 

  17. Lescuyer, S.: Formalizing and Implementing a Reflexive Tactic for Automated Deduction in Coq. Theses, Université Paris Sud - Paris XI, January 2011

    Google Scholar 

  18. Marić, F.: Formalization and implementation of modern SAT solvers. J. Autom. Reason. 43(1), 81–119 (2009)

    Article  Google Scholar 

  19. Marić, F., Janičić, P.: Formalization of abstract state transition systems for SAT. Log. Methods Comput. Sci. 7(3) (2011)

    Google Scholar 

  20. Michaelis, J., Nipkow, T.: Formalized proof systems for propositional logic. In: TYPES 2017. LIPIcs, vol. 104, pp. 5:1–5:16. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2017)

    Google Scholar 

  21. Michaelis, J., Nipkow, T.: Propositional proof systems. Archive of Formal Proofs, June 2017. Formal proof development. https://isa-afp.org/entries/Propositional_Proof_Systems.html

  22. Oe, D., Stump, A., Oliver, C., Clancy, K.: versat: a verified modern SAT solver. In: Kuncak, V., Rybalchenko, A. (eds.) VMCAI 2012. LNCS, vol. 7148, pp. 363–378. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-27940-9_24

    Chapter  Google Scholar 

  23. Shankar, N., Vaucher, M.: The mechanical verification of a DPLL-based satisfiability solver. Electr. Notes Theor. Comput. Sci. 269, 3–17 (2011)

    Article  Google Scholar 

  24. Tseitin, G.S.: On the complexity of derivations in the propositional calculus. Studies in Mathematics and Mathematical Logic, Part II, pp. 115–125 (1968)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Appendices

A Short Overview of Dafny

The Dafny programming language supports auto-active verification, a technique known since the 70s, but which has only become practical in the past decade, thanks to advances in both the usability of verification tools and computer processing power. Here is an example of a simple typical auto-actively verified Dafny method implementing binary search:

figure y

Auto-active verification is a mix of automatic verification and interactive verification. It means that the program is annotated by the programmer with specifications (such as preconditions, introduced by requires, and postconditions, introduced by ensures), which are automatically checked by the system to hold. The system verifies that the program implements the specification. If the postcondition cannot be proven to hold whenever the precondition holds, then the Dafny compiler fails with an error message. For example, the code above compiles (and verifies) without any issues; however, if we had made any mistake, like initializing right by a.Length instead of a.Length - 1 or reversing the comparison operators < and > inside the body of the while loop, then compilation would fail as the postcondition would not be provable.

For complicated post-conditions, Dafny cannot establish their validity automatically, and therefore additional help is required from the part of the programmer (the interactive part) in the form of invariants (in the example above, four invariants are given for the while loop), variants (introduced by the decreases keyword, used to establish termination), lemmas, or other helper annotations.

Auto-active verification is featured in frameworks such as Why3 [6], Dafny [16] or even programming languages such as Ada [14] or C [7]. It has been used successfully to develop trusted code for small and even average sized projects [13]. The main advantage of using auto-active verification in software development is that we obtain a high degree of confidence in the correctness of software projects that were developed in this style.

B The Dafny Development

The attached Dafny development consists of 8 source files:

  • utils.dfy contains generally useful definitions and lemmas, such as the definition of exponentiation (pow);

  • formula.dfy contains the definition of the FormulaT data type and related functions and lemmas such as validFormulaT, truthValue, maxVar;

  • cnf.dfy contains the verified implementation of the textbook algorithm for finding the CNF (with functions/methods such as convertToCNF or applyRule);

  • cnfformula.dfy contains various items concerning the representation of CNF formulae as elements of type seq<seq<int>>, such as the predicates validLiteral, validCnfFormula, truthValueCnfFormula;

  • tseitin.dfy contains the entry point (tseitin) to Tseitin’s transformation, together with the main implementatino tseitinCnf;

  • it relies on tseitinproofs.dfy, which contains lemmas that prove the invariant of tseitinCnf for all cases;

  • both of the modules above rely on tseitincore.dfy, which contains definitions useful in both the algorithm and its proof, such as the set of clauses orClauses to be added for disjunctions;

  • main.dfy exercises the CNF transformation in a Main method and can be used to obtain an executable;

  • Makefile to be used in the usual Unix-like manner. To compile (and verify) the development, it is sufficient to run:

  • dafny /verifySeparately *.dfy.

We have verified the source code with Dafny version 3.0.0.20820, but some earlier versions should work as well.

The Dafny development is available at

https://github.com/iordacheviorel/cnf-dafny.

Rights and permissions

Reprints and permissions

Copyright information

© 2021 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Iordache, V., Ciobâcă, Ş. (2021). Verifying the Conversion into CNF in Dafny. In: Silva, A., Wassermann, R., de Queiroz, R. (eds) Logic, Language, Information, and Computation. WoLLIC 2021. Lecture Notes in Computer Science(), vol 13038. Springer, Cham. https://doi.org/10.1007/978-3-030-88853-4_10

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-88853-4_10

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-88852-7

  • Online ISBN: 978-3-030-88853-4

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics