adamc@4: (* Copyright (c) 2008, Adam Chlipala adamc@4: * adamc@4: * This work is licensed under a adamc@4: * Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 adamc@4: * Unported License. adamc@4: * The license text is available at: adamc@4: * http://creativecommons.org/licenses/by-nc-nd/3.0/ adamc@4: *) adamc@4: adamc@4: (** adamc@4: adamc@4: This work is licensed under a adamc@4: Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 adamc@4: Unported License. adamc@4: The license text is available at: adamc@4: %\begin{center} \url{http://creativecommons.org/licenses/by-nc-nd/3.0/} \end{center}% adamc@4: #http://creativecommons.org/licenses/by-nc-nd/3.0/# adamc@4: adamc@4: *) adamc@4: adamc@4: adamc@4: (** * Whence This Book? *) adamc@4: adamc@4: (** adamc@4: adamc@4: We would all like to have programs check that our programs are correct. Due in no small part to some bold but unfulfilled promises in the history of computer science, today most people who write software, practitioners and academics alike, assume that the costs of formal program verification outweigh the associated benefits. The purpose of this book is to convince you that the technology of program verification is mature enough today that it makes sense to use it in a support role in many kinds of research projects in computer science. Beyond the convincing, I also want to provide a handbook on practical engineering of certified programs with the Coq proof assistant. adamc@4: adamc@4: There are a good number of (though definitely not "many") tools that are in wide use today for building machine-checked mathematical proofs and machine-certified programs. This is my attempt at an exhaustive list of interactive "proof assistants" satisfying a few criteria. First, the authors of each tool must intend for it to be put to use for software-related applications. Second, there must have been enough engineering effort put into the tool that someone not doing research on the tool itself would feel his time was well spent using it. A third criterion is more of an empirical validation of the second: the tool must have a significant user community outside of its own development team. adamc@4: adamc@4: % adamc@4: \begin{tabular}{rl} adamc@4: \textbf{ACL2} & \url{http://www.cs.utexas.edu/users/moore/acl2/} \\ adamc@4: \textbf{Coq} & \url{http://coq.inria.fr/} \\ adamc@4: \textbf{Isabelle/HOL} & \url{http://isabelle.in.tum.de/} \\ adamc@4: \textbf{PVS} & \url{http://pvs.csl.sri.com/} \\ adamc@4: \textbf{Twelf} & \url{http://www.twelf.org/} \\ adamc@4: \end{tabular} adamc@4: % adamc@4: # adamc@4: adamc@4: adamc@4: adamc@4: adamc@4: adamc@4: adamc@4:
ACL2 http://www.cs.utexas.edu/users/moore/acl2/
Coq http://coq.inria.fr/
Isabelle/HOL http://isabelle.in.tum.de/
PVS http://pvs.csl.sri.com/
Twelf http://www.twelf.org/
adamc@4: # adamc@4: adamc@4: Isabelle/HOL, implemented with the "proof assistant development framework" Isabelle, is the most popular proof assistant for the HOL logic. The other implementations of HOL can be considered equivalent for purposes of the discussion here. adamc@4: adamc@4: *) adamc@4: adamc@4: adamc@4: (** * Why Coq? *) adamc@4: adamc@4: (** adamc@4: This book is going to be about certified programming using Coq, and I am convinced that it is the best tool for the job. Coq has a number of very attractive properties, which I will summarize here, mentioning which of the other candidate tools lack each property. adamc@4: *) adamc@4: adamc@4: adamc@4: (** ** Based on a Higher-Order Functional Programming Language *) adamc@4: adamc@4: (** adamc@4: There is no reason to give up the familiar comforts of functional programming when you start writing certified programs. All of the tools I listed are based on functional programming languages, which means you can use them without their proof-related aspects to write and run regular programs. adamc@4: adamc@4: ACL2 is notable in this field for having only a %\textit{%##first-order##%}% language at its foundation. That is, you cannot work with functions over functions and all those other treats that functional programmers love. By giving up this facility, ACL2 can make broader assumptions about how well its proof automation will work, but we can generally recover the same advantages in other proof assistants when we happen to be programming in first-order fragments. adamc@4: *) adamc@4: adamc@4: adamc@4: (** ** Dependent Types *) adamc@4: adamc@4: (** adamc@4: A language of %\textit{%##dependent types##%}% may include references to programs inside of types. For instance, the type of an array might include a program expression giving the size of the array, making it possible to verify lack of out-of-bounds accesses statically. Dependent types can go even further than this, effectively capturing any correctness property in a type. For instance, later in this book, we will see how to give a Mini-ML compiler a type that guarantees that it maps well-typed source programs to well-typed target programs. adamc@4: adamc@4: ACL2 and HOL lack dependent types outright. PVS and Twelf each supports a different strict subset of Coq's dependent type language. Twelf's type language is restricted to a bare-bones, monomorphic lambda calculus, which places serious restrictions on how complicated %\textit{%##computations inside types##%}% can be. This restriction is important for the soundness argument behind Twelf's approach to representing and checking proofs. adamc@4: adamc@4: In contrast, PVS's dependent types are much more general, but they are squeezed inside the single mechanism of %\textit{%##subset types##%}%, where a normal type is refined by attaching a predicate over its elements. Each member of the subset type is an element of the base type that satisfies the predicate. adamc@4: adamc@4: Dependent types are not just useful because they help you express correctness properties in types. Dependent types also often let you write certified programs %\textit{%##without writing anything that looks like a proof##%}%. Even with subset types, which for many contexts can be used to express any relevant property with enough acrobatics, the human driving the proof assistant usually has to build some proofs explicitly. Writing formal proofs is hard, so we want to avoid it as far as possible, so dependent types are invaluable. adamc@4: adamc@4: *) adamc@4: adamc@4: (** ** An Easy-to-Check Kernel Proof Language *) adamc@4: adamc@4: (** adamc@4: Scores of automated decision procedures are useful in practical theorem proving, but it is unfortunate to have to trust in the correct implementation of each procedure. Proof assistants satisfying the "de Bruijn criterion" may use complicated and extensible procedures to seek out proofs, but in the end they produce %\textit{%##proof terms##%}% in kernel languages. These core languages have feature complexity on par with what you find in proposals for formal foundations for mathematics. To believe a proof, we can ignore the possibility of bugs during %\textit{%##search##%}% and just rely on a (relatively small) proof-checking kernel that we apply to the %\textit{%##result##%}% of the search. adamc@4: adamc@4: ACL2 and PVS do not meet the de Bruijn criterion, employing fancy decision procedures that produce no "evidence trails" justifying their results. adamc@4: *) adamc@4: adamc@4: (** ** Convenient Programmable Proof Automation *) adamc@4: adamc@4: (** adamc@4: A commitment to a kernel proof language opens up wide possibilities for user extension of proof automation systems, without allowing user mistakes to trick the overall system into accepting invalid proofs. Almost any interesting verification problem is undecidable, so it is important to help users build their own procedures for solving the restricted problems that they encounter in particular implementations. adamc@4: adamc@4: Twelf features no proof automation marked as a bonafide part of the latest release; there is some code included for testing purposes. The Twelf style is based on writing out all proofs in full detail. Because Twelf is specialized to the domain of syntactic metatheory proofs about programming languages and logics, it is feasible to use it to write those kinds of proofs manually. Outside that domain, the lack of automation can be a serious obstacle to productivity. Most kinds of program verification fall outside Twelf's forte. adamc@4: adamc@4: Of the remaining tools, all can support user extension with new decision procedures by hacking directly in the tool's implementation language (such as OCaml for Coq). Since ACL2 and PVS do not satisfy the de Bruijn criterion, overall correctness is at the mercy of the authors of new procedures. adamc@4: adamc@4: Isabelle/HOL and Coq both support coding new proof manipulations in ML in ways that cannot lead to the acceptance of invalid proofs. Additionally, Coq includes a domain-specific language for coding decision procedures in normal Coq source code, with no need to break out into ML. This language is called Ltac, and I think of it as the unsung hero of the proof assistant world. Not only does Ltac prevent you from making fatal mistakes, it also includes a number of novel programming constructs which combine to make a "proof by decision procedure" style very pleasant. We will meet these features in the chapters to come. adamc@4: *) adamc@4: adamc@4: (** ** Proof by Reflection *) adamc@4: adamc@4: (** adamc@4: A surprising wealth of benefits follow from choosing a proof language that integrates a rich notion of computation. Coq includes programs and proof terms in the same syntactic class. This makes it easy to write programs that compute proofs. With rich enough dependent types, such programs are %\textit{%##certified decision procedures##%}%. In such cases, these certified procedures can be put to good use %\textit{%##without ever running them##%}%! Their types guarantee that, if we did bother to run them, we would receive proper "ground" proofs. adamc@4: adamc@4: The critical ingredient for this technique, many of whose instances are referred to as %\textit{%##proof by reflection##%}%, is a way of inducing non-trivial computation inside of logical propositions during proof checking. Further, most of these instances require dependent types to make it possible to state the appropriate theorems. Of the proof assistants I listed, only Coq really provides this support. adamc@4: *)