annotate src/Intro.v @ 512:6b3fb6672cfa

Addressing some inaccuracies of comparison with PVS
author Adam Chlipala <adam@chlipala.net>
date Sun, 12 May 2013 12:50:27 -0400
parents da576746c3ba
children ed829eaa91b2
rev   line source
adam@512 1 (* Copyright (c) 2008-2013, Adam Chlipala
adamc@4 2 *
adamc@4 3 * This work is licensed under a
adamc@4 4 * Creative Commons Attribution-Noncommercial-No Derivative Works 3.0
adamc@4 5 * Unported License.
adamc@4 6 * The license text is available at:
adamc@4 7 * http://creativecommons.org/licenses/by-nc-nd/3.0/
adamc@4 8 *)
adamc@4 9
adam@311 10 (** %\chapter{Introduction}% *)
adamc@21 11
adamc@21 12
adamc@4 13 (** * Whence This Book? *)
adamc@4 14
adamc@4 15 (**
adamc@4 16
adam@306 17 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 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. Almost every subject covered is also relevant to interactive computer theorem-proving in general, such as for traditional mathematical theorems. In fact, I hope to demonstrate how verified programs are useful as building blocks in all sorts of formalizations.
adamc@4 18
adam@471 19 Research into mechanized theorem proving began in the second half of the 20th century, and some of the earliest practical work involved Nqthm%~\cite{Nqthm}\index{Nqthm}%, the "Boyer-Moore Theorem Prover," which was used to prove such theorems as correctness of a complete hardware and software stack%~\cite{Piton}%. ACL2%~\cite{CAR}\index{ACL2}%, Nqthm's successor, has seen significant industry adoption, for instance, by AMD to verify correctness of floating-point division units%~\cite{AMD}%.
adam@306 20
adam@475 21 Around the beginning of the 21st century, the pace of progress in practical applications of interactive theorem proving accelerated significantly. Several well-known formal developments have been carried out in Coq, the system that this book deals with. In the realm of pure mathematics, Georges Gonthier built a machine-checked proof of the four-color theorem%~\cite{4C}%, a mathematical problem first posed more than a hundred years before, where the only previous proofs had required trusting ad-hoc software to do brute-force checking of key facts. In the realm of program verification, Xavier Leroy led the CompCert project to produce a verified C compiler back-end%~\cite{CompCert}% robust enough to use with real embedded software.
adam@306 22
adam@469 23 Many other recent projects have attracted attention by proving important theorems using computer proof assistant software. For instance, the L4.verified project%~\cite{seL4}% led by Gerwin Klein has given a mechanized proof of correctness for a realistic microkernel, using the Isabelle/HOL proof assistant%~\cite{Isabelle/HOL}\index{Isabelle/HOL}%. The amount of ongoing work in the area is so large that I cannot hope to list all the recent successes, so from this point I will assume that the reader is convinced both that we ought to want machine-checked proofs and that they seem to be feasible to produce. (To readers not yet convinced, I suggest a Web search for "machine-checked proof"!)
adam@306 24
adam@475 25 The idea of %\index{certified program}% _certified program_ features prominently in this book's title. Here the word "certified" does _not_ refer to governmental rules for how the reliability of engineered systems may be demonstrated to sufficiently high standards. Rather, this concept of certification, a standard one in the programming languages and formal methods communities, has to do with the idea of a _certificate_, or formal mathematical artifact proving that a program meets its specification. Government certification procedures rarely provide strong mathematical guarantees, while certified programming provides guarantees about as strong as anything we could hope for. We trust the definition of a foundational mathematical logic, we trust an implementation of that logic, and we trust that we have encoded our informal intent properly in formal specifications, but few other opportunities remain to certify incorrect software. For compilers and other programs that run in batch mode, the notion of a %\index{certifying program}% _certifying_ program is also common, where each run of the program outputs both an answer and a proof that the answer is correct. Any certifying program can be composed with a proof checker to produce a certified program, and this book focuses on the certified case, while also introducing principles and techniques of general interest for stating and proving theorems in Coq.
adam@393 26
adam@393 27 %\medskip%
adam@393 28
adam@418 29 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. The following 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 30
adamc@4 31 %
adamc@244 32 \medskip
adamc@244 33
adamc@4 34 \begin{tabular}{rl}
adamc@4 35 \textbf{ACL2} & \url{http://www.cs.utexas.edu/users/moore/acl2/} \\
adamc@4 36 \textbf{Coq} & \url{http://coq.inria.fr/} \\
adamc@4 37 \textbf{Isabelle/HOL} & \url{http://isabelle.in.tum.de/} \\
adamc@4 38 \textbf{PVS} & \url{http://pvs.csl.sri.com/} \\
adamc@4 39 \textbf{Twelf} & \url{http://www.twelf.org/} \\
adamc@4 40 \end{tabular}
adamc@244 41
adamc@244 42 \medskip
adamc@4 43 %
adamc@4 44 #
adamc@4 45 <table align="center">
adamc@4 46 <tr><td align="right"><b>ACL2</b></td> <td><a href="http://www.cs.utexas.edu/users/moore/acl2/">http://www.cs.utexas.edu/users/moore/acl2/</a></td></tr>
adamc@4 47 <tr><td align="right"><b>Coq</b></td> <td><a href="http://coq.inria.fr/">http://coq.inria.fr/</a></td></tr>
adamc@4 48 <tr><td align="right"><b>Isabelle/HOL</b></td> <td><a href="http://isabelle.in.tum.de/">http://isabelle.in.tum.de/</a></td></tr>
adamc@4 49 <tr><td align="right"><b>PVS</b></td> <td><a href="http://pvs.csl.sri.com/">http://pvs.csl.sri.com/</a></td></tr>
adamc@4 50 <tr><td align="right"><b>Twelf</b></td> <td><a href="http://www.twelf.org/">http://www.twelf.org/</a></td></tr>
adamc@4 51 </table>
adamc@4 52 #
adamc@4 53
adam@418 54 Isabelle/HOL, implemented with the "proof assistant development framework" Isabelle%~\cite{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 55
adamc@4 56 *)
adamc@4 57
adamc@4 58
adamc@4 59 (** * Why Coq? *)
adamc@4 60
adamc@4 61 (**
adam@475 62 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 which properties.
adamc@4 63 *)
adamc@4 64
adamc@4 65
adamc@4 66 (** ** Based on a Higher-Order Functional Programming Language *)
adamc@4 67
adamc@4 68 (**
adam@475 69 %\index{higher-order vs. first-order languages}%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 features to write and run regular programs.
adamc@4 70
adam@398 71 %\index{ACL2}%ACL2 is notable in this field for having only a _first-order_ language at its foundation. That is, you cannot work with functions over functions and all those other treats of functional programming. 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 72 *)
adamc@4 73
adamc@4 74
adamc@4 75 (** ** Dependent Types *)
adamc@4 76
adamc@4 77 (**
adam@491 78 A language with _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 absence 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 compiler a type that guarantees that it maps well-typed source programs to well-typed target programs.
adamc@4 79
adam@475 80 %\index{ACL2}%ACL2 and %\index{HOL}%HOL lack dependent types outright. Each of %\index{PVS}%PVS and %\index{Twelf}%Twelf 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 _computations inside types_ can be. This restriction is important for the soundness argument behind Twelf's approach to representing and checking proofs.
adamc@4 81
adam@469 82 In contrast, %\index{PVS}%PVS's dependent types are much more general, but they are squeezed inside the single mechanism of _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. Chapter 6 of this book introduces that style of programming in Coq, while the remaining chapters of Part II deal with features of dependent typing in Coq that go beyond what PVS supports.
adamc@4 83
adam@475 84 Dependent types are useful not only because they help you express correctness properties in types. Dependent types also often let you write certified programs _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. Dependent types are invaluable for this purpose.
adamc@4 85
adamc@4 86 *)
adamc@4 87
adamc@4 88 (** ** An Easy-to-Check Kernel Proof Language *)
adamc@4 89
adamc@4 90 (**
adam@418 91 %\index{de Bruijn criterion}%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 satisfy the "de Bruijn criterion" when they produce _proof terms_ in small kernel languages, even when they use complicated and extensible procedures to seek out proofs in the first place. These core languages have feature complexity on par with what you find in proposals for formal foundations for mathematics (e.g., ZF set theory). To believe a proof, we can ignore the possibility of bugs during _search_ and just rely on a (relatively small) proof-checking kernel that we apply to the _result_ of the search.
adamc@4 92
adam@512 93 Coq meets the de Bruijn criterion, while %\index{ACL2}%ACL2 does not, as it employs fancy decision procedures that produce no "evidence trails" justifying their results. %\index{PVS}%PVS supports _strategies_ that implement fancier proof procedures in terms of a set of primitive proof steps, where the primitive steps are less primitive than in Coq. For instance, a propositional tautology solver is included as a primitive, so it is a question of taste whether such a system meets the de Bruijn criterion. The HOL implementations meet the de Bruijn criterion more manifestly; for Twelf, the situation is murkier.
adamc@4 94 *)
adamc@4 95
adamc@4 96 (** ** Convenient Programmable Proof Automation *)
adamc@4 97
adamc@4 98 (**
adam@307 99 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 theorems.
adamc@4 100
adam@465 101 %\index{Twelf}%Twelf features no proof automation marked as a bona fide part of the latest release; there is some automation 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 102
adam@307 103 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 %\index{ACL2}%ACL2 and %\index{PVS}%PVS do not satisfy the de Bruijn criterion, overall correctness is at the mercy of the authors of new procedures.
adamc@4 104
adam@418 105 %\index{Isabelle/HOL}%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 %\index{Ltac}%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 106 *)
adamc@4 107
adamc@4 108 (** ** Proof by Reflection *)
adamc@4 109
adamc@4 110 (**
adam@469 111 %\index{reflection}\index{proof by reflection}%A surprising wealth of benefits follows 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 _certified decision procedures_. In such cases, these certified procedures can be put to good use _without ever running them_! Their types guarantee that, if we did bother to run them, we would receive proper "ground" proofs.
adamc@4 112
adam@512 113 The critical ingredient for this technique, many of whose instances are referred to as _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 support for the type-level computation style of reflection, though PVS supports very similar functionality via refinement types.
adamc@4 114 *)
adamc@5 115
adamc@5 116
adam@306 117 (** * Why Not a Different Dependently Typed Language? *)
adamc@7 118
adamc@7 119 (**
adam@418 120 The logic and programming language behind Coq belongs to a type-theory ecosystem with a good number of other thriving members. %\index{Agda}%{{http://appserv.cs.chalmers.se/users/ulfn/wiki/agda.php}Agda} and %\index{Epigram}%{{http://www.e-pig.org/}Epigram} are the most developed tools among the alternatives to Coq, and there are others that are earlier in their lifecycles. All of the languages in this family feel sort of like different historical offshoots of Latin. The hardest conceptual epiphanies are, for the most part, portable among all the languages. Given this, why choose Coq for certified programming?
adamc@7 121
adam@306 122 I think the answer is simple. None of the competition has well-developed systems for tactic-based theorem proving. Agda and Epigram are designed and marketed more as programming languages than proof assistants. Dependent types are great, because they often help you prove deep theorems without doing anything that feels like proving. Nonetheless, almost any interesting certified programming project will benefit from some activity that deserves to be called proving, and many interesting projects absolutely require semi-automated proving, to protect the sanity of the programmer. Informally, proving is unavoidable when any correctness proof for a program has a structure that does not mirror the structure of the program itself. An example is a compiler correctness proof, which probably proceeds by induction on program execution traces, which have no simple relationship with the structure of the compiler or the structure of the programs it compiles. In building such proofs, a mature system for scripted proof automation is invaluable.
adamc@7 123
adam@418 124 On the other hand, Agda, Epigram, and similar tools have less implementation baggage associated with them, and so they tend to be the default first homes of innovations in practical type theory. Some significant kinds of dependently typed programs are much easier to write in Agda and Epigram than in Coq. The former tools may very well be superior choices for projects that do not involve any "proving." Anecdotally, I have gotten the impression that manual proving is orders of magnitudes more costly than manual coping with Coq's lack of programming bells and whistles. In this book, I will devote significant space to patterns for programming with dependent types in Coq as it is today. We can hope that the type theory community is tending towards convergence on the right set of features for practical programming with dependent types, and that we will eventually have a single tool embodying those features.
adamc@7 125 *)
adamc@7 126
adamc@7 127
adamc@5 128 (** * Engineering with a Proof Assistant *)
adamc@5 129
adamc@5 130 (**
adam@418 131 In comparisons with its competitors, Coq is often derided for promoting unreadable proofs. It is very easy to write proof scripts that manipulate proof goals imperatively, with no structure to aid readers. Such developments are nightmares to maintain, and they certainly do not manage to convey "why the theorem is true" to anyone but the original author. One additional (and not insignificant) purpose of this book is to show why it is unfair and unproductive to dismiss Coq based on the existence of such developments.
adamc@5 132
adam@471 133 I will go out on a limb and guess that the reader is a fan of some programming language and may even have been involved in teaching that language to undergraduates. I want to propose an analogy between two attitudes: coming to a negative conclusion about Coq after reading common Coq developments in the wild, and coming to a negative conclusion about Your Favorite Language after looking at the programs undergraduates write in it in the first week of class. The pragmatics of mechanized proving and program verification have been under serious study for much less time than the pragmatics of programming have been. The computer theorem proving community is still developing the key insights that correspond to those that programming texts and instructors impart to their students, to help those students get over that critical hump where using the language stops being more trouble than it is worth. Most of the insights for Coq are barely even disseminated among the experts, let alone set down in a tutorial form. I hope to use this book to go a long way towards remedying that.
adamc@5 134
adam@418 135 If I do that job well, then this book should be of interest even to people who have participated in classes or tutorials specifically about Coq. The book should even be useful to people who have been using Coq for years but who are mystified when their Coq developments prove impenetrable by colleagues. The crucial angle in this book is that there are "design patterns" for reliably avoiding the really grungy parts of theorem proving, and consistent use of these patterns can get you over the hump to the point where it is worth your while to use Coq to prove your theorems and certify your programs, even if formal verification is not your main concern in a project. We will follow this theme by pursuing two main methods for replacing manual proofs with more understandable artifacts: dependently typed functions and custom Ltac decision procedures.
adamc@5 136 *)
adamc@5 137
adamc@5 138
adamc@20 139 (** * Prerequisites *)
adamc@5 140
adamc@5 141 (**
adam@307 142 I try to keep the required background knowledge to a minimum in this book. I will assume familiarity with the material from usual discrete math and logic courses taken by undergraduate computer science majors, and I will assume that readers have significant experience programming in one of the ML dialects, in Haskell, or in some other, closely related language. Experience with only dynamically typed functional languages might lead to befuddlement in some places, but a reader who has come to understand Scheme deeply will probably be fine.
adamc@5 143
adam@398 144 My background is in programming languages, formal semantics, and program verification. I sometimes use examples from that domain. As a reference on these topics, I recommend _Types and Programming Languages_ %\cite{TAPL}%, by Benjamin C. Pierce; however, I have tried to choose examples so that they may be understood without background in semantics.
adamc@5 145 *)
adamc@8 146
adamc@8 147
adamc@8 148 (** * Using This Book *)
adamc@8 149
adamc@8 150 (**
adam@306 151 This book is generated automatically from Coq source files using the wonderful coqdoc program. The latest PDF version, with hyperlinks from identifier uses to the corresponding definitions, is available at:
adamc@8 152 %\begin{center}\url{http://adam.chlipala.net/cpdt/cpdt.pdf}\end{center}%#<blockquote><tt><a href="http://adam.chlipala.net/cpdt/cpdt.pdf">http://adam.chlipala.net/cpdt/cpdt.pdf</a></tt></blockquote>#
adam@306 153 There is also an online HTML version available, which of course also provides hyperlinks:
adamc@39 154 %\begin{center}\url{http://adam.chlipala.net/cpdt/html/toc.html}\end{center}%#<blockquote><tt><a href="http://adam.chlipala.net/cpdt/html/toc.html">http://adam.chlipala.net/cpdt/html/toc.html</a></tt></blockquote>#
adamc@8 155 The source code to the book is also freely available at:
adamc@8 156 %\begin{center}\url{http://adam.chlipala.net/cpdt/cpdt.tgz}\end{center}%#<blockquote><tt><a href="http://adam.chlipala.net/cpdt/cpdt.tgz">http://adam.chlipala.net/cpdt/cpdt.tgz</a></tt></blockquote>#
adamc@8 157
adam@418 158 There, you can find all of the code appearing in this book, with prose interspersed in comments, in exactly the order that you find in this document. You can step through the code interactively with your chosen graphical Coq interface. The code also has special comments indicating which parts of the chapters make suitable starting points for interactive class sessions, where the class works together to construct the programs and proofs. The included Makefile has a target <<templates>> for building a fresh set of class template files automatically from the book source.
adamc@8 159
adam@306 160 A traditional printed version of the book is slated to appear from MIT Press in the future. The online versions will remain available at no cost even after the printed book is released, and I intend to keep the source code up-to-date with bug fixes and compatibility changes to track new Coq releases.
adam@306 161
adam@477 162 %\index{graphical interfaces to Coq}%I believe that a good graphical interface to Coq is crucial for using it productively. I use the %\index{Proof General}%{{http://proofgeneral.inf.ed.ac.uk/}Proof General} mode for Emacs, which supports a number of other proof assistants besides Coq. There is also the standalone %\index{CoqIDE}%CoqIDE program developed by the Coq team. I like being able to combine certified programming and proving with other kinds of work inside the same full-featured editor. In the initial part of this book, I will reference Proof General procedures explicitly, in introducing how to use Coq, but most of the book will be interface-agnostic, so feel free to use CoqIDE if you prefer it. The one issue with CoqIDE before version 8.4, regarding running through the book source, is that I will sometimes begin a proof attempt but cancel it with the Coq [Abort] or #<span class="inlinecode"><span class="id" type="keyword">#%\coqdockw{%Restart%}%#</span></span># commands, which CoqIDE did not support until recently. It would be bad form to leave such commands lying around in a real, finished development, but I find these commands helpful in writing single source files that trace a user's thought process in designing a proof.
adamc@8 163 *)
adamc@25 164
adam@307 165 (** ** Reading This Book *)
adam@307 166
adam@307 167 (**
adam@471 168 For experts in functional programming or formal methods, learning to use Coq is not hard, in a sense. The Coq manual%~\cite{CoqManual}%, the textbook by Bertot and Cast%\'%eran%~\cite{CoqArt}%, and Pierce et al.'s %\emph{%Software Foundations%}\footnote{\url{http://www.cis.upenn.edu/~bcpierce/sf/}}% have helped many people become productive Coq users. However, I believe that the best ways to manage significant Coq developments are far from settled. In this book, I mean to propose my own techniques, and, rather than treating them as advanced material for a final chapter or two, I employ them from the very beginning. After a first chapter showing off what can be done with dependent types, I retreat into simpler programming styles for the first part of the book. I adopt the other main thrust of the book, Ltac proof automation, more or less from the very start of the technical exposition.
adam@307 169
adam@307 170 Some readers have suggested that I give multiple recommended reading orders in this introduction, targeted at people with different levels of Coq expertise. It is certainly true that Part I of the book devotes significant space to basic concepts that most Coq users already know quite well. However, as I am introducing these concepts, I am also developing my preferred automated proof style, so I think even the chapters on basics are worth reading for experienced Coq hackers.
adam@307 171
adam@307 172 Readers with no prior Coq experience can ignore the preceding discussion! I hope that my heavy reliance on proof automation early on will seem like the most natural way to go, such that you may wonder why others are spending so much time entering sequences of proof steps manually.
adam@307 173
adam@471 174 Coq is a very complex system, with many different commands driven more by pragmatic concerns than by any overarching aesthetic principle. When I use some construct for the first time, I try to give a one-sentence intuition for what it accomplishes, but I leave the details to the Coq reference manual%~\cite{CoqManual}%. I expect that readers interested in complete understanding will be consulting that manual frequently; in that sense, this book is not meant to be completely standalone. I often use constructs in code snippets without first introducing them at all, but explanations should always follow in the prose paragraphs immediately after the offending snippets.
adam@318 175
adam@489 176 Previous versions of the book included some suggested exercises at the ends of chapters. Since then, I have decided to remove the exercises and focus on the main book exposition. A database of exercises proposed by various readers of the book is #<a href="http://adam.chlipala.net/cpdt/ex/">#available on the Web#</a>#%\footnote{\url{http://adam.chlipala.net/cpdt/ex/}}%. I do want to suggest, though, that the best way to learn Coq is to get started applying it in a real project, rather than focusing on artificial exercises. *)
adam@307 177
adam@307 178 (** ** On the Tactic Library *)
adam@307 179
adam@307 180 (**
adam@398 181 To make it possible to start from fancy proof automation, rather than working up to it, I have included with the book source a library of _tactics_, or programs that find proofs, since the built-in Coq tactics do not support a high enough level of automation. I use these tactics even from the first chapter with code examples.
adam@307 182
adam@418 183 Some readers have asked about the pragmatics of using this tactic library in their own developments. My position there is that this tactic library was designed with the specific examples of the book in mind; I do not recommend using it in other settings. Part III should impart the necessary skills to reimplement these tactics and beyond. One generally deals with undecidable problems in interactive theorem proving, so there can be no tactic that solves all goals, though the %\index{tactics!crush}%[crush] tactic that we will meet soon may sometimes feel like that! There are still very useful tricks found in the implementations of [crush] and its cousins, so it may be useful to examine the commented source file <<CpdtTactics.v>>. I implement a new tactic library for each new project, since each project involves a different mix of undecidable theories where a different set of heuristics turns out to work well; and that is what I recommend others do, too.
adam@307 184 *)
adam@307 185
adam@307 186 (** ** Installation and Emacs Set-Up *)
adam@307 187
adam@307 188 (**
adam@487 189 At the start of the next chapter, I assume that you have installed Coq and Proof General. The code in this book is tested with Coq versions 8.4 and 8.4pl1. Though parts may work with other versions, it is expected that the book source will fail to build with _earlier_ versions.
adam@307 190
adam@491 191 %\index{Proof General|(}%To set up your Proof General environment to process the source to the next chapter, a few simple steps are required.
adam@307 192
adam@307 193 %\begin{enumerate}%#<ol>#
adam@307 194
adam@307 195 %\item %#<li>#Get the book source from
adam@307 196 %\begin{center}\url{http://adam.chlipala.net/cpdt/cpdt.tgz}\end{center}%#<blockquote><tt><a href="http://adam.chlipala.net/cpdt/cpdt.tgz">http://adam.chlipala.net/cpdt/cpdt.tgz</a></tt></blockquote></li>#
adam@307 197
adam@418 198 %\item %#<li>#Unpack the tarball to some directory <<DIR>>.#</li>#
adam@307 199
adam@491 200 %\item %#<li>#Run <<make>> in <<DIR>> (ideally with a <<-j>> flag to use multiple processor cores, if you have them).#</li>#
adam@307 201
adam@418 202 %\item %#<li>#There are some minor headaches associated with getting Proof General to pass the proper command line arguments to the <<coqtop>> program, which provides the interactive Coq toplevel. One way to add settings that will be shared by many source files is to add a custom variable setting to your %\index{.emacs file@\texttt{.emacs} file}%<<.emacs>> file, like this:
adam@418 203 <<
adam@418 204 (custom-set-variables
adam@307 205 ...
adam@307 206 '(coq-prog-args '("-I" "DIR/src"))
adam@307 207 ...
adam@418 208 )
adam@418 209 >>
adam@418 210 The extra arguments demonstrated here are the proper choices for working with the code for this book. The ellipses stand for other Emacs customization settings you may already have. It can be helpful to save several alternate sets of flags in your <<.emacs>> file, with all but one commented out within the <<custom-set-variables>> block at any given time.
adam@397 211
adam@418 212 Alternatively, Proof General configuration can be set on a per-directory basis, using a %\index{.dir-locals.el file@\texttt{.dir-locals.el} file}%<<.dir-locals.el>> file in the directory of the source files for which you want the settings to apply. Here is an example that could be written in such a file to enable use of the book source. Note the need to include an argument that starts Coq in Emacs support mode.
adam@437 213 <<
adam@437 214 ((coq-mode . ((coq-prog-args . ("-emacs-U" "-I" "DIR/src")))))
adam@437 215 >>
adam@397 216 #</li>#
adam@307 217
adam@307 218 #</ol>#%\end{enumerate}%
adam@307 219
adam@418 220 Every chapter of this book is generated from a commented Coq source file. You can load these files and run through them step-by-step in Proof General. Be sure to run the Coq binary <<coqtop>> with the command-line argument <<-I DIR/src>>. If you have installed Proof General properly, the Coq mode should start automatically when you visit a <<.v>> buffer in Emacs, and the above advice on <<.emacs>> settings should ensure that the proper arguments are passed to <<coqtop>> by Emacs.
adam@307 221
adam@307 222 With Proof General, the portion of a buffer that Coq has processed is highlighted in some way, like being given a blue background. You step through Coq source files by positioning the point at the position you want Coq to run to and pressing C-C C-RET. This can be used both for normal step-by-step coding, by placing the point inside some command past the end of the highlighted region; and for undoing, by placing the point inside the highlighted region.
adam@307 223 %\index{Proof General|)}% *)
adamc@25 224
adamc@25 225 (** %\section{Chapter Source Files}
adamc@25 226
adamc@25 227 \begin{center} \begin{tabular}{|r|l|}
adamc@25 228 \hline
adamc@25 229 \textbf{Chapter} & \textbf{Source} \\
adamc@25 230 \hline
adamc@25 231 Some Quick Examples & \texttt{StackMachine.v} \\
adamc@25 232 \hline
adamc@43 233 Introducing Inductive Types & \texttt{InductiveTypes.v} \\
adamc@26 234 \hline
adamc@49 235 Inductive Predicates & \texttt{Predicates.v} \\
adamc@49 236 \hline
adamc@62 237 Infinite Data and Proofs & \texttt{Coinductive.v} \\
adamc@62 238 \hline
adam@353 239 Subset Types and Variations & \texttt{Subset.v} \\
adam@353 240 \hline
adam@350 241 General Recursion & \texttt{GeneralRec.v} \\
adam@350 242 \hline
adamc@83 243 More Dependent Types & \texttt{MoreDep.v} \\
adamc@83 244 \hline
adamc@105 245 Dependent Data Structures & \texttt{DataStruct.v} \\
adamc@105 246 \hline
adamc@118 247 Reasoning About Equality Proofs & \texttt{Equality.v} \\
adamc@118 248 \hline
adamc@219 249 Generic Programming & \texttt{Generic.v} \\
adamc@219 250 \hline
adamc@227 251 Universes and Axioms & \texttt{Universes.v} \\
adamc@227 252 \hline
adam@324 253 Proof Search by Logic Programming & \texttt{LogicProg.v} \\
adam@324 254 \hline
adamc@132 255 Proof Search in Ltac & \texttt{Match.v} \\
adamc@132 256 \hline
adamc@142 257 Proof by Reflection & \texttt{Reflection.v} \\
adamc@142 258 \hline
adamc@235 259 Proving in the Large & \texttt{Large.v} \\
adamc@235 260 \hline
adam@382 261 A Taste of Reasoning About Programming Language Syntax & \texttt{ProgLang.v} \\
adam@381 262 \hline
adamc@25 263 \end{tabular} \end{center}
adamc@25 264
adamc@25 265 % *)