1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
"http://www.w3.org/TR/REC-html40/loose.dtd">
6
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7
<META name="GENERATOR" content="hevea 1.07">
10
<!--HEVEA command line is: hevea -fix -nosymb main.v.tex -->
13
<!--PREFIX <ARG ></ARG>-->
14
<!--CUT DEF section 1 -->
23
<H1 ALIGN=center>Coq Version 8.0 for the Clueless<BR>
24
<FONT SIZE=4>(</FONT><A HREF="#lastquestion"><FONT SIZE=4>174</FONT></A><FONT SIZE=4>
28
<H3 ALIGN=center>Hugo Herbelin Florent Kirchner Benjamin Monate Julien Narboux</H3>
30
<BLOCKQUOTE><B>Abstract: </B>
31
This note intends to provide an easy way to get acquainted with the
32
<FONT COLOR=navy>Coq</FONT> theorem prover. It tries to formulate appropriate answers
33
to some of the questions any newcomers will face, and to give
34
pointers to other references when possible.
36
<!--TOC section Table of Contents-->
38
<H2>Table of Contents</H2><!--SEC END -->
41
<A HREF="#htoc1">1 Introduction</A>
42
<LI><A HREF="#htoc2">2 Presentation</A>
45
<A HREF="#htoc3">1 What is <FONT COLOR=navy>Coq</FONT>?</A>
46
<LI><A HREF="#htoc4">2 Did you really need to name it like that?</A>
47
<LI><A HREF="#htoc5">3 Is <FONT COLOR=navy>Coq</FONT> a theorem prover?</A>
48
<LI><A HREF="#htoc6">4 What are the other theorem provers?</A>
49
<LI><A HREF="#htoc7">5 Who do I have to trust when I see a proof checked by Coq?</A>
50
<LI><A HREF="#htoc8">6 Where can I find information about the theory behind <FONT COLOR=navy>Coq</FONT>?</A>
51
<LI><A HREF="#htoc9">7 How can I use <FONT COLOR=navy>Coq</FONT> to prove programs?</A>
52
<LI><A HREF="#htoc10">8 How many <FONT COLOR=navy>Coq</FONT> users are there?</A>
53
<LI><A HREF="#htoc11">9 How old is <FONT COLOR=navy>Coq</FONT>?</A>
54
<LI><A HREF="#htoc12">10 What are the <FONT COLOR=navy>Coq</FONT>-related tools?</A>
55
<LI><A HREF="#htoc13">11 What are the high-level tactics of <FONT COLOR=navy>Coq</FONT></A>
56
<LI><A HREF="#htoc14">12 What are the main libraries available for <FONT COLOR=navy>Coq</FONT></A>
57
<LI><A HREF="#htoc15">13 What are the academic applications for <FONT COLOR=navy>Coq</FONT>?</A>
58
<LI><A HREF="#htoc16">14 What are the industrial applications for <FONT COLOR=navy>Coq</FONT>?</A>
61
<LI><A HREF="#htoc17">3 Documentation</A>
64
<A HREF="#htoc18">15 Where can I find documentation about <FONT COLOR=navy>Coq</FONT>?</A>
65
<LI><A HREF="#htoc19">16 Where can I find this FAQ on the web?</A>
66
<LI><A HREF="#htoc20">17 How can I submit suggestions / improvements / additions for this FAQ?</A>
67
<LI><A HREF="#htoc21">18 Is there any mailing list about <FONT COLOR=navy>Coq</FONT>?</A>
68
<LI><A HREF="#htoc22">19 Where can I find an archive of the list?</A>
69
<LI><A HREF="#htoc23">20 How can I be kept informed of new releases of <FONT COLOR=navy>Coq</FONT>?</A>
70
<LI><A HREF="#htoc24">21 Is there any book about <FONT COLOR=navy>Coq</FONT>?</A>
71
<LI><A HREF="#htoc25">22 Where can I find some <FONT COLOR=navy>Coq</FONT> examples?</A>
72
<LI><A HREF="#htoc26">23 How can I report a bug?</A>
75
<LI><A HREF="#htoc27">4 Installation</A>
78
<A HREF="#htoc28">24 What is the license of <FONT COLOR=navy>Coq</FONT>?</A>
79
<LI><A HREF="#htoc29">25 Where can I find the sources of <FONT COLOR=navy>Coq</FONT>?</A>
80
<LI><A HREF="#htoc30">26 On which platform is <FONT COLOR=navy>Coq</FONT> available?</A>
83
<LI><A HREF="#htoc31">5 The logic of <FONT COLOR=navy>Coq</FONT></A>
85
<A HREF="#htoc32">5.1 General</A>
87
<A HREF="#htoc33">27 What is the logic of <FONT COLOR=navy>Coq</FONT>?</A>
88
<LI><A HREF="#htoc34">28 Is <FONT COLOR=navy>Coq</FONT>'s logic intuitionistic or classical?</A>
89
<LI><A HREF="#htoc35">29 Can I define non-terminating programs in <FONT COLOR=navy>Coq</FONT>?</A>
90
<LI><A HREF="#htoc36">30 How is equational reasoning working in <FONT COLOR=navy>Coq</FONT>?</A>
92
<LI><A HREF="#htoc37">5.2 Axioms</A>
94
<A HREF="#htoc38">31 What axioms can be safely added to <FONT COLOR=navy>Coq</FONT>?</A>
95
<LI><A HREF="#htoc39">32 What standard axioms are inconsistent with <FONT COLOR=navy>Coq</FONT>?</A>
96
<LI><A HREF="#htoc40">33 What is Streicher's axiom <I>K</I></A>
97
<LI><A HREF="#htoc41">34 What is proof-irrelevance</A>
98
<LI><A HREF="#htoc42">35 What about functional extensionality?</A>
99
<LI><A HREF="#htoc43">36 Is <TT>Prop</TT> impredicative?</A>
100
<LI><A HREF="#htoc44">37 Is <TT>Set</TT> impredicative?</A>
101
<LI><A HREF="#htoc45">38 Is <TT>Type</TT> impredicative?</A>
102
<LI><A HREF="#htoc46">39 I have two proofs of the same proposition. Can I prove they are equal?</A>
103
<LI><A HREF="#htoc47">40 I have two proofs of an equality statement. Can I prove they are
105
<LI><A HREF="#htoc48">41 Can I prove that the second components of equal dependent
108
<LI><A HREF="#htoc49">5.3 Impredicativity</A>
110
<A HREF="#htoc50">42 Why <TT>injection</TT> does not work on impredicative <TT>Set</TT>?</A>
111
<LI><A HREF="#htoc51">43 What is a "large inductive definition"?</A>
114
<LI><A HREF="#htoc52">6 Talkin' with the Rooster</A>
116
<A HREF="#htoc53">6.1 My goal is ..., how can I prove it?</A>
118
<A HREF="#htoc54">44 My goal is a conjunction, how can I prove it?</A>
119
<LI><A HREF="#htoc55">45 My goal contains a conjunction as an hypothesis, how can I use it?</A>
120
<LI><A HREF="#htoc56">46 My goal is a disjunction, how can I prove it?</A>
121
<LI><A HREF="#htoc57">47 My goal is an universally quantified statement, how can I prove it?</A>
122
<LI><A HREF="#htoc58">48 My goal is an existential, how can I prove it?</A>
123
<LI><A HREF="#htoc59">49 My goal is solvable by some lemma, how can I prove it?</A>
124
<LI><A HREF="#htoc60">50 My goal contains False as an hypotheses, how can I prove it?</A>
125
<LI><A HREF="#htoc61">51 My goal is an equality of two convertible terms, how can I prove it?</A>
126
<LI><A HREF="#htoc62">52 My goal is a <TT>let x := a in ...</TT>, how can I prove it?</A>
127
<LI><A HREF="#htoc63">53 My goal is a <TT>let (a, ..., b) := c in</TT>, how can I prove it?</A>
128
<LI><A HREF="#htoc64">54 My goal contains some existential hypotheses, how can I use it?</A>
129
<LI><A HREF="#htoc65">55 My goal contains some existential hypotheses, how can I use it and decompose my knowledge about this new thing into different hypotheses?</A>
130
<LI><A HREF="#htoc66">56 My goal is an equality, how can I swap the left and right hand terms?</A>
131
<LI><A HREF="#htoc67">57 My hypothesis is an equality, how can I swap the left and right hand terms?</A>
132
<LI><A HREF="#htoc68">58 My goal is an equality, how can I prove it by transitivity?</A>
133
<LI><A HREF="#htoc69">59 My goal would be solvable using <TT>apply;assumption</TT> if it would not create meta-variables, how can I prove it?</A>
134
<LI><A HREF="#htoc70">60 My goal is solvable by some lemma within a set of lemmas and I don't want to remember which one, how can I prove it?</A>
135
<LI><A HREF="#htoc71">61 My goal is one of the hypotheses, how can I prove it?</A>
136
<LI><A HREF="#htoc72">62 My goal appears twice in the hypotheses and I want to choose which one is used, how can I do it?</A>
137
<LI><A HREF="#htoc73">63 What can be the difference between applying one hypothesis or another in the context of the last question?</A>
138
<LI><A HREF="#htoc74">64 My goal is a propositional tautology, how can I prove it?</A>
139
<LI><A HREF="#htoc75">65 My goal is a first order formula, how can I prove it?</A>
140
<LI><A HREF="#htoc76">66 My goal is solvable by a sequence of rewrites, how can I prove it?</A>
141
<LI><A HREF="#htoc77">67 My goal is a disequality solvable by a sequence of rewrites, how can I prove it?</A>
142
<LI><A HREF="#htoc78">68 My goal is an equality on some ring (e.g. natural numbers), how can I prove it?</A>
143
<LI><A HREF="#htoc79">69 My goal is an equality on some field (e.g. real numbers), how can I prove it?</A>
144
<LI><A HREF="#htoc80">70 My goal is an inequality on integers in Presburger's arithmetic (an expression build from +,-,constants and variables), how can I prove it?</A>
145
<LI><A HREF="#htoc81">71 My goal is an equation solvable using equational hypothesis on some ring (e.g. natural numbers), how can I prove it?</A>
147
<LI><A HREF="#htoc82">6.2 Tactics usage</A>
149
<A HREF="#htoc83">72 I want to state a fact that I will use later as an hypothesis, how can I do it?</A>
150
<LI><A HREF="#htoc84">73 I want to state a fact that I will use later as an hypothesis and prove it later, how can I do it?</A>
151
<LI><A HREF="#htoc85">74 What is the difference between <TT>Qed</TT> and <TT>Defined</TT>?</A>
152
<LI><A HREF="#htoc86">75 How can I know what a tactic does?</A>
153
<LI><A HREF="#htoc87">76 Why <TT>auto</TT> does not work? How can I fix it?</A>
154
<LI><A HREF="#htoc88">77 What is <TT>eauto</TT>?</A>
155
<LI><A HREF="#htoc89">78 How can I speed up <TT>auto</TT>?</A>
156
<LI><A HREF="#htoc90">79 What is the equivalent of <TT>tauto</TT> for classical logic?</A>
157
<LI><A HREF="#htoc91">80 I want to replace some term with another in the goal, how can I do it?</A>
158
<LI><A HREF="#htoc92">81 I want to replace some term with another in an hypothesis, how can I do it?</A>
159
<LI><A HREF="#htoc93">82 I want to replace some symbol with its definition, how can I do it?</A>
160
<LI><A HREF="#htoc94">83 How can I reduce some term?</A>
161
<LI><A HREF="#htoc95">84 How can I declare a shortcut for some term?</A>
162
<LI><A HREF="#htoc96">85 How can I perform case analysis?</A>
163
<LI><A HREF="#htoc97">86 Why should I name my intros?</A>
164
<LI><A HREF="#htoc98">87 How can I automatize the naming?</A>
165
<LI><A HREF="#htoc99">88 I want to automatize the use of some tactic, how can I do it?</A>
166
<LI><A HREF="#htoc100">89 I want to execute the <TT>p</TT>roof with tactic only if it solves the goal, how can I do it?</A>
167
<LI><A HREF="#htoc101">90 How can I do the opposite of the <TT>intro</TT> tactic?</A>
168
<LI><A HREF="#htoc102">91 One of the hypothesis is an equality between a variable and some term, I want to get rid of this variable, how can I do it?</A>
169
<LI><A HREF="#htoc103">92 What can I do if I get ``<TT>generated subgoal term has metavariables in it </TT>''?</A>
170
<LI><A HREF="#htoc104">93 How can I instantiate some metavariable?</A>
171
<LI><A HREF="#htoc105">94 What is the use of the <TT>pattern</TT> tactic?</A>
172
<LI><A HREF="#htoc106">95 What is the difference between assert, cut and generalize?</A>
173
<LI><A HREF="#htoc107">96 What can I do if <FONT COLOR=navy>Coq</FONT>can not infer some implicit argument ?</A>
174
<LI><A HREF="#htoc108">97 How can I explicit some implicit argument ?</A>
176
<LI><A HREF="#htoc109">6.3 Proof management</A>
178
<A HREF="#htoc110">98 How can I change the order of the subgoals?</A>
179
<LI><A HREF="#htoc111">99 How can I change the order of the hypothesis?</A>
180
<LI><A HREF="#htoc112">100 How can I change the name of an hypothesis?</A>
181
<LI><A HREF="#htoc113">101 How can I delete some hypothesis?</A>
182
<LI><A HREF="#htoc114">102 How can use a proof which is not finished?</A>
183
<LI><A HREF="#htoc115">103 How can I state a conjecture?</A>
184
<LI><A HREF="#htoc116">104 What is the difference between a lemma, a fact and a theorem?</A>
185
<LI><A HREF="#htoc117">105 How can I organize my proofs?</A>
188
<LI><A HREF="#htoc118">7 Inductive and Co-inductive types</A>
190
<A HREF="#htoc119">7.1 General</A>
192
<A HREF="#htoc120">106 How can I prove that two constructors are different?</A>
193
<LI><A HREF="#htoc121">107 During an inductive proof, how to get rid of impossible cases of an inductive definition?</A>
194
<LI><A HREF="#htoc122">108 How can I prove that 2 terms in an inductive set are equal? Or different?</A>
195
<LI><A HREF="#htoc123">109 Why is the proof of <TT>0+n=n</TT> on natural numbers
196
trivial but the proof of <TT>n+0=n</TT> is not?</A>
197
<LI><A HREF="#htoc124">110 Why is dependent elimination in Prop not
198
available by default?</A>
200
<LI><A HREF="#htoc125">7.2 Recursion</A>
202
<A HREF="#htoc126">111 Why can't I define a non terminating program?</A>
203
<LI><A HREF="#htoc127">112 Why only structurally well-founded loops are allowed?</A>
204
<LI><A HREF="#htoc128">113 How to define loops based on non structurally smaller
206
<LI><A HREF="#htoc129">114 What is behind the accessibility and well-foundedness proofs?</A>
207
<LI><A HREF="#htoc130">115 How to perform double induction?</A>
208
<LI><A HREF="#htoc131">116 How to define a function by double recursion?</A>
209
<LI><A HREF="#htoc132">117 How to perform nested induction?</A>
210
<LI><A HREF="#htoc133">118 How to define a function by nested recursion?</A>
212
<LI><A HREF="#htoc134">7.3 Co-inductive types</A>
214
<A HREF="#htoc135">119 I have a cofixpoint <I>t</I>:=<I>F</I>(<I>t</I>) and I want to prove <I>t</I>=<I>F</I>(<I>t</I>). How to do it?</A>
217
<LI><A HREF="#htoc136">8 Syntax and notations</A>
220
<A HREF="#htoc137">120 I do not want to type ``forall'' because it is too long, what can I do?</A>
221
<LI><A HREF="#htoc138">121 How can I define a notation for square?</A>
222
<LI><A HREF="#htoc139">122 Why ``no associativity'' and ``left associativity'' at the same level does not work?</A>
223
<LI><A HREF="#htoc140">123 How can I know the associativity associated with a level?</A>
226
<LI><A HREF="#htoc141">9 Modules</A>
227
<LI><A HREF="#htoc142">10 <FONT COLOR=navy>Ltac</FONT></A>
230
<A HREF="#htoc143">124 What is <FONT COLOR=navy>Ltac</FONT>?</A>
231
<LI><A HREF="#htoc144">125 Why do I always get the same error message?</A>
232
<LI><A HREF="#htoc145">126 Is there any printing command in <FONT COLOR=navy>Ltac</FONT>?</A>
233
<LI><A HREF="#htoc146">127 What is the syntax for let in <FONT COLOR=navy>Ltac</FONT>?</A>
234
<LI><A HREF="#htoc147">128 What is the syntax for pattern matching in <FONT COLOR=navy>Ltac</FONT>?</A>
235
<LI><A HREF="#htoc148">129 What is the semantics for match goal?</A>
236
<LI><A HREF="#htoc149">130 How can I generate a new name?</A>
237
<LI><A HREF="#htoc150">131 How can I define static and dynamic code?</A>
240
<LI><A HREF="#htoc151">11 Tactics written in Ocaml</A>
243
<A HREF="#htoc152">132 Can you show me an example of a tactic written in OCaml?</A>
246
<LI><A HREF="#htoc153">12 Case studies</A>
249
<A HREF="#htoc154">133 How can I define vectors or lists of size n?</A>
250
<LI><A HREF="#htoc155">134 How to prove that 2 sets are different?</A>
251
<LI><A HREF="#htoc156">135 Is there an axiom-free proof of Streicher's axiom <I>K</I> for
252
the equality on <TT>nat</TT>?</A>
253
<LI><A HREF="#htoc157">136 How to prove that two proofs of <TT>n<=m</TT> on <TT>nat</TT> are equal?</A>
254
<LI><A HREF="#htoc158">137 How to exploit equalities on sets</A>
255
<LI><A HREF="#htoc159">138 I have a problem of dependent elimination on
256
proofs, how to solve it?</A>
257
<LI><A HREF="#htoc160">139 And what if I want to prove the following?</A>
260
<LI><A HREF="#htoc161">13 Publishing tools</A>
263
<A HREF="#htoc162">140 How can I generate some latex from my development?</A>
264
<LI><A HREF="#htoc163">141 How can I generate some HTML from my development?</A>
265
<LI><A HREF="#htoc164">142 How can I generate some dependency graph from my development?</A>
266
<LI><A HREF="#htoc165">143 How can I cite some <FONT COLOR=navy>Coq</FONT> in my latex document?</A>
267
<LI><A HREF="#htoc166">144 How can I cite the <FONT COLOR=navy>Coq</FONT> reference manual?</A>
268
<LI><A HREF="#htoc167">145 Where can I publish my developments in <FONT COLOR=navy>Coq</FONT>?</A>
269
<LI><A HREF="#htoc168">146 How can I read my proof in natural language?</A>
272
<LI><A HREF="#htoc169">14 <FONT COLOR=navy>CoqIde</FONT></A>
275
<A HREF="#htoc170">147 What is <FONT COLOR=navy>CoqIde</FONT>?</A>
276
<LI><A HREF="#htoc171">148 How to enable Emacs keybindings?</A>
277
<LI><A HREF="#htoc172">149 How to enable antialiased fonts?</A>
278
<LI><A HREF="#htoc173">150 How to use those Forall and Exists pretty symbols?</A>
279
<LI><A HREF="#htoc174">151 How to define an input method for non ASCII symbols?</A>
280
<LI><A HREF="#htoc175">152 How to build a custom <FONT COLOR=navy>CoqIde</FONT> with user ml code?</A>
281
<LI><A HREF="#htoc176">153 How to customize the shortcuts for menus?</A>
282
<LI><A HREF="#htoc177">154 What encoding should I use? What is this \x{iiii} in my file?</A>
285
<LI><A HREF="#htoc178">15 Extraction</A>
288
<A HREF="#htoc179">155 What is program extraction?</A>
289
<LI><A HREF="#htoc180">156 Which language can I extract to?</A>
290
<LI><A HREF="#htoc181">157 How can I extract an incomplete proof?</A>
293
<LI><A HREF="#htoc182">16 Glossary</A>
296
<A HREF="#htoc183">158 Can you explain me what an evaluable constant is?</A>
297
<LI><A HREF="#htoc184">159 What is a goal?</A>
298
<LI><A HREF="#htoc185">160 What is a meta variable?</A>
299
<LI><A HREF="#htoc186">161 What is Gallina?</A>
300
<LI><A HREF="#htoc187">162 What is The Vernacular?</A>
301
<LI><A HREF="#htoc188">163 What is a dependent type?</A>
302
<LI><A HREF="#htoc189">164 What is a proof by reflection?</A>
303
<LI><A HREF="#htoc190">165 What is intuitionistic logic?</A>
304
<LI><A HREF="#htoc191">166 What is proof-irrelevance?</A>
305
<LI><A HREF="#htoc192">167 What is the difference between opaque and transparent?</A>
308
<LI><A HREF="#htoc193">17 Troubleshooting</A>
311
<A HREF="#htoc194">168 What can I do when <TT>Qed.</TT> is slow?</A>
312
<LI><A HREF="#htoc195">169 Why <TT>Reset Initial.</TT> does not work when using <TT>coqc</TT>?</A>
313
<LI><A HREF="#htoc196">170 What can I do if I get ``No more subgoals but non-instantiated existential variables''?</A>
314
<LI><A HREF="#htoc197">171 What can I do if I get ``Cannot solve a second-order unification problem''?</A>
315
<LI><A HREF="#htoc198">172 Why does <FONT COLOR=navy>Coq</FONT> tell me that <TT>{x:A|(P x)}</TT> is not convertible with <TT>(sig A P)</TT>?</A>
316
<LI><A HREF="#htoc199">173 I copy-paste a term and <FONT COLOR=navy>Coq</FONT> says it is not convertible
317
to the original term. Sometimes it even says the copied term is not
321
<LI><A HREF="#htoc200">18 Conclusion and Farewell.</A>
324
<A HREF="#htoc201">174 What if my question isn't answered here?</A>
329
<!--TOC section Introduction-->
331
<H2><A NAME="htoc1">1</A> Introduction</H2><!--SEC END -->
333
This FAQ is the sum of the questions that came to mind as we developed
334
proofs in <FONT COLOR=navy>Coq</FONT>. Since we are singularly short-minded, we wrote the
335
answers we found on bits of papers to have them at hand whenever the
336
situation occurs again. This is pretty much the result of that: a
337
collection of tips one can refer to when proofs become intricate. Yes,
338
this means we won't take the blame for the shortcomings of this
339
FAQ. But if you want to contribute and send in your own question and
340
answers, feel free to write to us...<BR>
342
<!--TOC section Presentation-->
344
<H2><A NAME="htoc2">2</A> Presentation</H2><!--SEC END -->
346
<!--TOC subsubsection What is <FONT COLOR=navy>Coq</FONT>?-->
348
<H4><A NAME="htoc3">1</A> What is <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
349
<A NAME="whatiscoq"></A>
350
The <FONT COLOR=navy>Coq</FONT> tool is a formal proof management system: a proof done with <FONT COLOR=navy>Coq</FONT> is mechanically checked by the machine.
351
In particular, <FONT COLOR=navy>Coq</FONT> allows:
353
the definition of functions or predicates,
354
<LI>to state mathematical theorems and software specifications,
355
<LI>to develop interactively formal proofs of these theorems,
356
<LI>to check these proofs by a small certification "kernel".
358
<FONT COLOR=navy>Coq</FONT> is based on a logical framework called "Calculus of Inductive Constructions" extended by a modular development system for theories.<BR>
360
<!--TOC subsubsection Did you really need to name it like that?-->
362
<H4><A NAME="htoc4">2</A> Did you really need to name it like that?</H4><!--SEC END -->
364
Some French computer scientists have a tradition of naming their
365
software as animal species: Caml, Elan, Foc or Phox are examples
366
of this tacit convention. In French, ``coq'' means rooster, and it
367
sounds like the initials of the Calculus of Constructions CoC on which
370
<!--TOC subsubsection Is <FONT COLOR=navy>Coq</FONT> a theorem prover?-->
372
<H4><A NAME="htoc5">3</A> Is <FONT COLOR=navy>Coq</FONT> a theorem prover?</H4><!--SEC END -->
374
<FONT COLOR=navy>Coq</FONT> comes with a few decision procedures (on propositional
375
calculus, Presburger's arithmetic, ring and field simplification,
376
resolution, ...) but the main style for proving theorems is
377
interactively by using LCF-style tactics.<BR>
379
<!--TOC subsubsection What are the other theorem provers?-->
381
<H4><A NAME="htoc6">4</A> What are the other theorem provers?</H4><!--SEC END -->
383
Many other theorem provers are available for use nowadays.
384
Isabelle, HOL, HOL Light, Lego, Nuprl, PVS are examples of provers that are fairly similar
385
to <FONT COLOR=navy>Coq</FONT> by the way they interact with the user. Other relatives of
386
<FONT COLOR=navy>Coq</FONT> are ACL2, Alfa, Elf, Kiv, Mizar, NqThm,
390
<!--TOC subsubsection Who do I have to trust when I see a proof checked by Coq?-->
392
<H4><A NAME="htoc7">5</A> Who do I have to trust when I see a proof checked by Coq?</H4><!--SEC END -->
395
<DL COMPACT=compact><DT>
396
<B>The theory behind Coq</B><DD> The theory of <FONT COLOR=navy>Coq</FONT> version 8.0 is
397
generally admitted to be consistent wrt Zermelo-Fraenkel set theory +
398
inaccessibles cardinals. Proofs of consistency of subsystems of the
399
theory of Coq can be found in the literature.
400
<DT><B>The Coq kernel implementation</B><DD> You have to trust that the
401
implementation of the <FONT COLOR=navy>Coq</FONT> kernel mirrors the theory behind <FONT COLOR=navy>Coq</FONT>. The
402
kernel is intentionally small to limit the risk of conceptual or
403
accidental implementation bugs.
404
<DT><B>The Objective Caml compiler</B><DD> The <FONT COLOR=navy>Coq</FONT> kernel is written using the
405
Objective Caml language but it uses only the most standard features
406
(no object, no label ...), so that it is highly unprobable that an
407
Objective Caml bug breaks the consistency of <FONT COLOR=navy>Coq</FONT> without breaking all
408
other kinds of features of <FONT COLOR=navy>Coq</FONT> or of other software compiled with
410
<DT><B>Your hardware</B><DD> In theory, if your hardware does not work
411
properly, it can accidentally be the case that False becomes
412
provable. But it is more likely the case that the whole <FONT COLOR=navy>Coq</FONT> system
413
will be unusable. You can check your proof using different computers
414
if you feel the need to.
415
<DT><B>Your axioms</B><DD> Your axioms must be consistent with the theory
416
behind <FONT COLOR=navy>Coq</FONT>.
418
<!--TOC subsubsection Where can I find information about the theory behind <FONT COLOR=navy>Coq</FONT>?-->
420
<H4><A NAME="htoc8">6</A> Where can I find information about the theory behind <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
422
<DL COMPACT=compact><DT>
423
<B>The Calculus of Inductive Constructions</B><DD> The
424
<A HREF="http://coq.inria.fr/doc/Reference-Manual006.html">corresponding</A>
425
chapter and the chapter on
426
<A HREF="http://coq.inria.fr/doc/Reference-Manual007.html">modules</A> in
427
the <FONT COLOR=navy>Coq</FONT> Reference Manual.
428
<DT><B>Type theory</B><DD> A book [<A HREF="#ProofsTypes"><CITE>10</CITE></A>] or some lecture
429
notes [<A HREF="#Types:Dowek"><CITE>7</CITE></A>].
430
<DT><B>Inductive types</B><DD>
431
Christine Paulin-Mohring's habilitation thesis [<A HREF="#Pau96b"><CITE>17</CITE></A>].
432
<DT><B>Co-Inductive types</B><DD>
433
Eduardo Gim�nez' thesis [<A HREF="#EGThese"><CITE>8</CITE></A>].
434
<DT><B>Miscellaneous</B><DD> A
435
<A HREF="http://coq.inria.fr/doc/biblio.html">bibliography</A> about Coq
437
<!--TOC subsubsection How can I use <FONT COLOR=navy>Coq</FONT> to prove programs?-->
439
<H4><A NAME="htoc9">7</A> How can I use <FONT COLOR=navy>Coq</FONT> to prove programs?</H4><!--SEC END -->
441
You can either extract a program from a proof by using the extraction
442
mechanism or use dedicated tools, such as
443
<A HREF="http://why.lri.fr"><FONT COLOR=navy>Why</FONT></A>,
444
<A HREF="http://krakatoa.lri.fr"><FONT COLOR=navy>Krakatoa</FONT></A>,
445
<A HREF="http://why.lri.fr/caduceus/index.en.html"><FONT COLOR=navy>Caduceus</FONT></A>, to prove
446
annotated programs written in other languages.<BR>
448
<!--TOC subsubsection How many <FONT COLOR=navy>Coq</FONT> users are there?-->
450
<H4><A NAME="htoc10">8</A> How many <FONT COLOR=navy>Coq</FONT> users are there?</H4><!--SEC END -->
452
An estimation is about 100 regular users.<BR>
454
<!--TOC subsubsection How old is <FONT COLOR=navy>Coq</FONT>?-->
456
<H4><A NAME="htoc11">9</A> How old is <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
458
The first implementation is from 1985 (it was named <FONT COLOR=purple>CoC</FONT> which is
459
the acronym of the name of the logic it implemented: the Calculus of
460
Constructions). The first official release of <FONT COLOR=navy>Coq</FONT> (version 4.10)
461
was distributed in 1989.<BR>
463
<!--TOC subsubsection What are the <FONT COLOR=navy>Coq</FONT>-related tools?-->
465
<H4><A NAME="htoc12">10</A> What are the <FONT COLOR=navy>Coq</FONT>-related tools?</H4><!--SEC END -->
467
<DL COMPACT=compact><DT>
468
<B>Coqide</B><DD> A GTK based GUI for <FONT COLOR=navy>Coq</FONT>.
469
<DT><B>Pcoq</B><DD> A GUI for <FONT COLOR=navy>Coq</FONT> with proof by pointing and pretty printing.
470
<DT><B>Helm/Mowgli</B><DD> A rendering, searching and publishing tool.
471
<DT><B>Why</B><DD> A back-end generator of verification conditions.
472
<DT><B>Krakatoa</B><DD> A Java code certification tool that uses both <FONT COLOR=navy>Coq</FONT> and <FONT COLOR=navy>Why</FONT> to verify the soundness of implementations with regards to the specifications.
473
<DT><B>Caduceus</B><DD> A C code certification tool that uses both <FONT COLOR=navy>Coq</FONT> and <FONT COLOR=navy>Why</FONT>.
474
<DT><B>coqwc</B><DD> A tool similar to <TT>wc</TT> to count lines in <FONT COLOR=navy>Coq</FONT> files.
475
<DT><B>coq-tex</B><DD> A tool to insert <FONT COLOR=navy>Coq</FONT> examples within .tex files.
476
<DT><B>coqdoc</B><DD> A documentation tool for <FONT COLOR=navy>Coq</FONT>.
477
<DT><B>Proof General</B><DD> A emacs mode for <FONT COLOR=navy>Coq</FONT> and many other proof assistants.
478
<DT><B>Foc</B><DD> The <A HREF="http://www-spi.lip6.fr/foc/index-en.html">Foc</A> project aims at building an environment to develop certified computer algebra libraries.
480
<!--TOC subsubsection What are the high-level tactics of <FONT COLOR=navy>Coq</FONT>-->
482
<H4><A NAME="htoc13">11</A> What are the high-level tactics of <FONT COLOR=navy>Coq</FONT></H4><!--SEC END -->
485
Decision of quantifier-free Presburger's Arithmetic
486
<LI>Simplification of expressions on rings and fields
487
<LI>Decision of closed systems of equations
488
<LI>Semi-decision of first-order logic
489
<LI>Prolog-style proof search, possibly involving equalities
491
<!--TOC subsubsection What are the main libraries available for <FONT COLOR=navy>Coq</FONT>-->
493
<H4><A NAME="htoc14">12</A> What are the main libraries available for <FONT COLOR=navy>Coq</FONT></H4><!--SEC END -->
496
Basic Peano's arithmetic, binary integer numbers, rational numbers,
498
<LI>Libraries for lists, boolean, maps, floating-point numbers,
499
<LI>Libraries for relations, sets and constructive algebra,
502
<!--TOC subsubsection What are the academic applications for <FONT COLOR=navy>Coq</FONT>?-->
504
<H4><A NAME="htoc15">13</A> What are the academic applications for <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
506
<FONT COLOR=navy>Coq</FONT> is used for formalizing mathematical theories, for teaching,
507
and for proving properties of algorithms or programs libraries.<BR>
509
The largest mathematical formalization has been done at the University
511
<A HREF="http://vacuumcleaner.cs.kun.nl/c-corn">Constructive Coq
512
Repository at Nijmegen</A>).<BR>
514
<!--TOC subsubsection What are the industrial applications for <FONT COLOR=navy>Coq</FONT>?-->
516
<H4><A NAME="htoc16">14</A> What are the industrial applications for <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
518
<FONT COLOR=navy>Coq</FONT> is used e.g. to prove properties of the JavaCard system
519
(especially by the companies Schlumberger and Trusted Logic). It has
520
also been used to formalize the semantics of the Lucid-Synchrone
521
data-flow synchronous calculus used by Esterel-Technologies.<BR>
523
<!--TOC section Documentation-->
525
<H2><A NAME="htoc17">3</A> Documentation</H2><!--SEC END -->
527
<!--TOC subsubsection Where can I find documentation about <FONT COLOR=navy>Coq</FONT>?-->
529
<H4><A NAME="htoc18">15</A> Where can I find documentation about <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
531
All the documentation about <FONT COLOR=navy>Coq</FONT>, from the reference manual [<A HREF="#Coq:manual"><CITE>15</CITE></A>] to
532
friendly tutorials [<A HREF="#Coq:Tutorial"><CITE>14</CITE></A>] and documentation of the standard library, is available
533
<A HREF="http://coq.inria.fr/doc-eng.html">online</A>.
534
All these documents are viewable either in browsable HTML, or as
535
downloadable postscripts.<BR>
537
<!--TOC subsubsection Where can I find this FAQ on the web?-->
539
<H4><A NAME="htoc19">16</A> Where can I find this FAQ on the web?</H4><!--SEC END -->
541
This FAQ is available online at <A HREF="http://coq.inria.fr/doc/faq.html"><TT>http://coq.inria.fr/doc/faq.html</TT></A>.<BR>
543
<!--TOC subsubsection How can I submit suggestions / improvements / additions for this FAQ?-->
545
<H4><A NAME="htoc20">17</A> How can I submit suggestions / improvements / additions for this FAQ?</H4><!--SEC END -->
547
This FAQ is unfinished (in the sense that there are some obvious
548
sections that are missing). Please send contributions to <TT>Florent.Kirchner at lix.polytechnique.fr</TT> and <TT>Julien.Narboux at inria.fr</TT>.<BR>
550
<!--TOC subsubsection Is there any mailing list about <FONT COLOR=navy>Coq</FONT>?-->
552
<H4><A NAME="htoc21">18</A> Is there any mailing list about <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
554
The main <FONT COLOR=navy>Coq</FONT> mailing list is <TT>coq-club@coq.inria.fr</TT>, which
555
broadcasts questions and suggestions about the implementation, the
556
logical formalism or proof developments. See
557
<A HREF="http://coq.inria.fr/mailman/listinfo/coq-club"><TT>http://coq.inria.fr/mailman/listinfo/coq-club</TT></A> for
558
subscription. For bugs reports see question <A HREF="#coqbug">23</A>.<BR>
560
<!--TOC subsubsection Where can I find an archive of the list?-->
562
<H4><A NAME="htoc22">19</A> Where can I find an archive of the list?</H4><!--SEC END -->
564
The archives of the <FONT COLOR=navy>Coq</FONT> mailing list are available at
565
<A HREF="http://coq.inria.fr/pipermail/coq-club"><TT>http://coq.inria.fr/pipermail/coq-club</TT></A>.<BR>
567
<!--TOC subsubsection How can I be kept informed of new releases of <FONT COLOR=navy>Coq</FONT>?-->
569
<H4><A NAME="htoc23">20</A> How can I be kept informed of new releases of <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
571
New versions of <FONT COLOR=navy>Coq</FONT> are announced on the coq-club mailing list. If you only want to receive information about new releases, you can subscribe to <FONT COLOR=navy>Coq</FONT> on <A HREF="http://freshmeat.net/projects/coq/"><TT>http://freshmeat.net/projects/coq/</TT></A>.<BR>
573
<!--TOC subsubsection Is there any book about <FONT COLOR=navy>Coq</FONT>?-->
575
<H4><A NAME="htoc24">21</A> Is there any book about <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
577
The first book on <FONT COLOR=navy>Coq</FONT>, Yves Bertot and Pierre Cast�ran's Coq'Art has been published by Springer-Verlag in 2004:
579
``This book provides a pragmatic introduction to the development of
580
proofs and certified programs using <FONT COLOR=navy>Coq</FONT>. With its large collection of
581
examples and exercises it is an invaluable tool for researchers,
582
students, and engineers interested in formal methods and the
583
development of zero-default software.''
585
<!--TOC subsubsection Where can I find some <FONT COLOR=navy>Coq</FONT> examples?-->
587
<H4><A NAME="htoc25">22</A> Where can I find some <FONT COLOR=navy>Coq</FONT> examples?</H4><!--SEC END -->
589
There are examples in the manual [<A HREF="#Coq:manual"><CITE>15</CITE></A>] and in the
590
Coq'Art [<A HREF="#Coq:coqart"><CITE>1</CITE></A>] exercises <A HREF="http://www.labri.fr/Perso/ casteran/CoqArt/index.html"><TT>http://www.labri.fr/Perso/~casteran/CoqArt/index.html</TT></A>.
591
You can also find large developments using
592
<FONT COLOR=navy>Coq</FONT> in the <FONT COLOR=navy>Coq</FONT> user contributions:
593
<A HREF="http://coq.inria.fr/contrib-eng.html"><TT>http://coq.inria.fr/contrib-eng.html</TT></A>.<BR>
595
<!--TOC subsubsection How can I report a bug?-->
597
<H4><A NAME="htoc26">23</A> How can I report a bug?</H4><!--SEC END -->
598
<A NAME="coqbug"></A>
599
You can use the web interface at <A HREF="http://coq.inria.fr/bin/coq-bugs"><TT>http://coq.inria.fr/bin/coq-bugs</TT></A>.<BR>
601
<!--TOC section Installation-->
603
<H2><A NAME="htoc27">4</A> Installation</H2><!--SEC END -->
605
<!--TOC subsubsection What is the license of <FONT COLOR=navy>Coq</FONT>?-->
607
<H4><A NAME="htoc28">24</A> What is the license of <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
609
The main files are distributed under the GNU Lesser General License
610
(LGPL). A few contributions are GPL.<BR>
612
<!--TOC subsubsection Where can I find the sources of <FONT COLOR=navy>Coq</FONT>?-->
614
<H4><A NAME="htoc29">25</A> Where can I find the sources of <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
616
The sources of <FONT COLOR=navy>Coq</FONT> can be found online in the tar.gz'ed packages
617
(<A HREF="http://coq.inria.fr/distrib-eng.html"><TT>http://coq.inria.fr/distrib-eng.html</TT></A>). Development sources can
618
be accessed via anonymous CVS: <A HREF="http://coqcvs.inria.fr/"><TT>http://coqcvs.inria.fr/</TT></A><BR>
620
<!--TOC subsubsection On which platform is <FONT COLOR=navy>Coq</FONT> available?-->
622
<H4><A NAME="htoc30">26</A> On which platform is <FONT COLOR=navy>Coq</FONT> available?</H4><!--SEC END -->
624
Compiled binaries are available for Linux, MacOS X, Solaris, and
625
Windows. The sources can be easily compiled on all platforms supporting Objective Caml.<BR>
627
<!--TOC section The logic of <FONT COLOR=navy>Coq</FONT>-->
629
<H2><A NAME="htoc31">5</A> The logic of <FONT COLOR=navy>Coq</FONT></H2><!--SEC END -->
631
<!--TOC subsection General-->
633
<H3><A NAME="htoc32">5.1</A> General</H3><!--SEC END -->
635
<!--TOC subsubsection What is the logic of <FONT COLOR=navy>Coq</FONT>?-->
637
<H4><A NAME="htoc33">27</A> What is the logic of <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
639
<FONT COLOR=navy>Coq</FONT> is based on an axiom-free type theory called
640
the Calculus of Inductive Constructions (see Coquand [<A HREF="#CoHu86"><CITE>5</CITE></A>]
641
and Coquand--Paulin-Mohring [<A HREF="#CoPa89"><CITE>6</CITE></A>]). It includes higher-order
642
functions and predicates, inductive and co-inductive datatypes and
643
predicates, and a stratified hierarchy of sets.<BR>
645
<!--TOC subsubsection Is <FONT COLOR=navy>Coq</FONT>'s logic intuitionistic or classical?-->
647
<H4><A NAME="htoc34">28</A> Is <FONT COLOR=navy>Coq</FONT>'s logic intuitionistic or classical?</H4><!--SEC END -->
649
<FONT COLOR=navy>Coq</FONT> theory is basically intuitionistic
650
(i.e. excluded-middle <I>A</I>\/� <I>A</I> is not granted by default) with
651
the possibility to reason classically on demand by requiring an
652
optional axiom stating <I>A</I>\/� <I>A</I>.<BR>
654
<!--TOC subsubsection Can I define non-terminating programs in <FONT COLOR=navy>Coq</FONT>?-->
656
<H4><A NAME="htoc35">29</A> Can I define non-terminating programs in <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
658
No, all programs in <FONT COLOR=navy>Coq</FONT> are terminating. Especially, loops
659
must come with an evidence of their termination.<BR>
661
<!--TOC subsubsection How is equational reasoning working in <FONT COLOR=navy>Coq</FONT>?-->
663
<H4><A NAME="htoc36">30</A> How is equational reasoning working in <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
665
<FONT COLOR=navy>Coq</FONT> comes with an internal notion of computation called
666
<EM>conversion</EM> (e.g. (<I>x</I>+1)+<I>y</I> is internally equivalent to
667
(<I>x</I>+<I>y</I>)+1; similarly applying argument <I>a</I> to a function mapping <I>x</I>
668
to some expression <I>t</I> converts to the expression <I>t</I> where <I>x</I> is
669
replaced by <I>a</I>). This notion of conversion (which is decidable
670
because <FONT COLOR=navy>Coq</FONT> programs are terminating) covers a certain part of
671
equational reasoning but is limited to sequential evaluation of
672
expressions of (not necessarily closed) programs. Besides conversion,
673
equations have to be treated by hand or using specialised tactics.<BR>
675
<!--TOC subsection Axioms-->
677
<H3><A NAME="htoc37">5.2</A> Axioms</H3><!--SEC END -->
679
<!--TOC subsubsection What axioms can be safely added to <FONT COLOR=navy>Coq</FONT>?-->
681
<H4><A NAME="htoc38">31</A> What axioms can be safely added to <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
683
There are a few typical useful axioms that are independent from the
684
Calculus of Inductive Constructions and that can be safely added to
685
<FONT COLOR=navy>Coq</FONT>. These axioms are stated in the directory <TT>Logic</TT> of the
686
standard library of <FONT COLOR=navy>Coq</FONT>. The most interesting ones are
688
Excluded-middle: for all <I>A</I>:<I>Prop</I>, <I>A</I> \/ � <I>A</I>
689
<LI>Proof-irrelevance: for all <I>A</I>:<I>Prop</I>, for all <I>p</I><SUB><FONT SIZE=2>1</FONT></SUB> <I>p</I><SUB><FONT SIZE=2>2</FONT></SUB>:<I>A</I>, <I>p</I><SUB><FONT SIZE=2>1</FONT></SUB>=<I>p</I><SUB><FONT SIZE=2>2</FONT></SUB>
690
<LI>Unicity of equality proofs (or equivalently Streicher's axiom <I>K</I>)
691
<LI>The principle of description: for all <I>x</I>, there exists! <I>y</I>, <I>R</I>(<I>x</I>,<I>y</I>) -> there exists <I>f</I>, for all <I>x</I>, <I>R</I>(<I>x</I>,<I>f</I>(<I>x</I>))
692
<LI>The functional axiom of choice: for all <I>x</I>, there exists <I>y</I>, <I>R</I>(<I>x</I>,<I>y</I>) -> there exists <I>f</I>, for all <I>x</I>, <I>R</I>(<I>x</I>,<I>f</I>(<I>x</I>))
693
<LI>Extensionality of predicates: for all <I>P</I> <I>Q</I>:<I>A</I>-> <I>Prop</I>, (for all <I>x</I>, <I>P</I>(<I>x</I>) <-> <I>Q</I>(<I>x</I>)) -> <I>P</I>=<I>Q</I>
694
<LI>Extensionality of functions: for all <I>f</I> <I>g</I>:<I>A</I>-> <I>B</I>, (for all <I>x</I>, <I>f</I>(<I>x</I>)=<I>g</I>(<I>x</I>)) -> <I>f</I>=<I>g</I>
696
Here is a summary of the relative strength of these axioms, most
697
proofs can be found in directory <TT>Logic</TT> of the standard library.<BR>
699
<IMG SRC="main.v001.gif"><BR>
701
<!--TOC subsubsection What standard axioms are inconsistent with <FONT COLOR=navy>Coq</FONT>?-->
703
<H4><A NAME="htoc39">32</A> What standard axioms are inconsistent with <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
705
The axiom of description together with classical logic
706
(e.g. excluded-middle) are inconsistent in the variant of the Calculus
707
of Inductive Constructions where <TT>Set</TT> is impredicative.<BR>
709
As a consequence, the functional form of the axiom of choice and
710
excluded-middle, or any form of the axiom of choice together with
711
predicate extensionality are inconsistent in the <TT>Set</TT>-impredicative
712
version of the Calculus of Inductive Constructions.<BR>
714
The main purpose of the <TT>Set</TT>-predicative restriction of the Calculus
715
of Inductive Constructions is precisely to accommodate these axioms
716
which are quite standard in mathematical usage.<BR>
718
The <TT><I>Set</I></TT>-predicative system is commonly considered consistent by
719
interpreting it in a standard set-theoretic boolean model, even with
720
classical logic, axiom of choice and predicate extensionality added.<BR>
722
<!--TOC subsubsection What is Streicher's axiom <I>K</I>-->
724
<H4><A NAME="htoc40">33</A> What is Streicher's axiom <I>K</I></H4><!--SEC END -->
726
<A NAME="Streicher"></A>
727
Streicher's axiom <I>K</I> [<A HREF="#HofStr98"><CITE>12</CITE></A>] asserts dependent
728
elimination of reflexive equality proofs.<BR>
732
<TT>Coq < Axiom Streicher_K :</TT><BR>
733
<TT>Coq < forall (A:Type) (x:A) (P: x=x -> Prop),</TT><BR>
734
<TT>Coq < P (refl_equal x) -> forall p: x=x, P p.</TT><BR>
737
In the general case, axiom <I>K</I> is an independent statement of the
738
Calculus of Inductive Constructions. However, it is true on decidable
739
domains (see file <A HREF="http://coq.inria.fr/library/Coq.Logic.Eqdep_dec.html
740
"><TT>Eqdep_dec.v</TT></A>). It is also
741
trivially a consequence of proof-irrelevance (see
742
<A HREF="#proof-irrelevance">34</A>) hence of classical logic.<BR>
744
Axiom <I>K</I> is equivalent to <EM>Uniqueness of Identity Proofs</EM> [<A HREF="#HofStr98"><CITE>12</CITE></A>]<BR>
748
<TT>Coq < Axiom UIP : forall (A:Set) (x y:A) (p1 p2: x=y), p1 = p2.</TT><BR>
751
Axiom <I>K</I> is also equivalent to <EM>Uniqueness of Reflexive Identity Proofs</EM> [<A HREF="#HofStr98"><CITE>12</CITE></A>]<BR>
755
<TT>Coq < Axiom UIP_refl : forall (A:Set) (x:A) (p: x=x), p = refl_equal x.</TT><BR>
758
Axiom <I>K</I> is also equivalent to <BR>
762
<TT>Coq < Axiom</TT><BR>
763
<TT>Coq < eq_rec_eq :</TT><BR>
764
<TT>Coq < forall (A:Set) (x:A) (P: A->Set) (p:P x) (h: x=x),</TT><BR>
765
<TT>Coq < p = eq_rect x P p x h.</TT><BR>
768
It is also equivalent to the injectivity of dependent equality (dependent equality is itself equivalent to equality of dependent pairs).<BR>
772
<TT>Coq < Inductive eq_dep (U:Set) (P:U -> Set) (p:U) (x:P p) :</TT><BR>
773
<TT>Coq < forall q:U, P q -> Prop :=</TT><BR>
774
<TT>Coq < eq_dep_intro : eq_dep U P p x p x.</TT><BR>
776
<TT>Coq < Axiom</TT><BR>
777
<TT>Coq < eq_dep_eq :</TT><BR>
778
<TT>Coq < forall (U:Set) (u:U) (P:U -> Set) (p1 p2:P u),</TT><BR>
779
<TT>Coq < eq_dep U P u p1 u p2 -> p1 = p2.</TT><BR>
782
<!--TOC subsubsection What is proof-irrelevance-->
784
<H4><A NAME="htoc41">34</A> What is proof-irrelevance</H4><!--SEC END -->
786
<A NAME="proof-irrelevance"></A>
787
A specificity of the Calculus of Inductive Constructions is to permit
788
statements about proofs. This leads to the question of comparing two
789
proofs of the same proposition. Identifying all proofs of the same
790
proposition is called <EM>proof-irrelevance</EM>:
791
<DIV ALIGN=center>for all <I>A</I>:<TT><I>Prop</I></TT>, for all <I>p</I> <I>q</I>:<I>A</I>, <I>p</I>=<I>q</I>
793
Proof-irrelevance (in <TT>Prop</TT>) can be assumed without contradiction in
794
<FONT COLOR=navy>Coq</FONT>. It corresponds to a model where provability, whatever the
795
proof is, is more important than the computational content of the
796
proof. This is in harmony with the common purely logical
797
interpretation of <TT>Prop</TT>. Contrastingly, proof-irrelevance is
798
inconsistent in <TT>Set</TT> in harmony with the computational meaning of
799
the sort <TT>Set</TT>.<BR>
801
Proof-irrelevance (in <TT>Prop</TT>) is a consequence of classical logic
802
(see proofs in file <A HREF="http://coq.inria.fr/library/Coq.Logic.Classical.html
803
"><TT>Classical.v</TT></A> and
804
<A HREF="http://coq.inria.fr/library/Coq.Logic.Berardi.html
805
"><TT>Berardi.v</TT></A>). Proof-irrelevance is also a
806
consequence of propositional extensionality (i.e. <TT>(A <-> B)
807
-> A=B</TT>, see the proof in file
808
<A HREF="http://coq.inria.fr/library/Coq.Logic.ClassicalFacts.html
809
"><TT>ClassicalFacts.v</TT></A>).<BR>
811
Conversely, proof-irrelevance directly implies Streicher's axiom <I>K</I>.<BR>
813
<!--TOC subsubsection What about functional extensionality?-->
815
<H4><A NAME="htoc42">35</A> What about functional extensionality?</H4><!--SEC END -->
817
Extensionality of functions is an axiom in, say set theory, but from a
818
programing point of view, extensionality cannot be <EM>a priori</EM>
819
accepted since it would identify, say programs such as mergesort and
822
Let <TT>A</TT>, <TT>B</TT> be types. To deal with extensionality on
823
<CODE>A->B</CODE>, the recommended approach is to define one's
824
own extensional equality on <CODE>A->B</CODE>.<BR>
828
<TT>Coq < Definition ext_eq (f g: A->B) := forall x:A, f x = g x.</TT><BR>
831
and to reason on <CODE>A->B</CODE> as a setoid (see the Chapter on
832
Setoids in the Reference Manual).<BR>
834
<!--TOC subsubsection Is <TT>Prop</TT> impredicative?-->
836
<H4><A NAME="htoc43">36</A> Is <TT>Prop</TT> impredicative?</H4><!--SEC END -->
838
Yes, the sort <TT>Prop</TT> of propositions is <EM>impredicative</EM>. Otherwise said, a statement of the form for all
839
<I>A</I>:<I>Prop</I>, <I>P</I>(<I>A</I>) can be instantiated by itself: if for all <I>A</I>:<TT><I>Prop</I></TT>, <I>P</I>(<I>A</I>)
840
is provable, then <I>P</I>(for all <I>A</I>:<TT><I>Prop</I></TT>, <I>P</I>(<I>A</I>)) is.<BR>
842
<!--TOC subsubsection Is <TT>Set</TT> impredicative?-->
844
<H4><A NAME="htoc44">37</A> Is <TT>Set</TT> impredicative?</H4><!--SEC END -->
846
No, the sort <TT>Set</TT> lying at the bottom of the hierarchy of
847
computational types is <EM>predicative</EM> in the basic <FONT COLOR=navy>Coq</FONT> system.
848
This means that a family of types in <TT>Set</TT>, e.g. for all <I>A</I>:<TT><I>Set</I></TT>, <I>A</I>
849
-> <I>A</I>, is not a type in <TT>Set</TT> and it cannot be applied on
852
However, the sort <TT>Set</TT> was impredicative in the original versions of
853
<FONT COLOR=navy>Coq</FONT>. For backward compatibility, or for experiments by
854
knowledgeable users, the logic of <FONT COLOR=navy>Coq</FONT> can be set impredicative for
855
<TT>Set</TT> by calling <FONT COLOR=navy>Coq</FONT> with the option <TT>-impredicative-set</TT>.<BR>
857
<TT>Set</TT> has been made predicative from version 8.0 of <FONT COLOR=navy>Coq</FONT>. The main
858
reason is to interact smoothly with a classical mathematical world
859
where both excluded-middle and the axiom of description are valid (see
860
file <A HREF="http://coq.inria.fr/library/Coq.Logic.ClassicalDescription.html
861
"><TT>ClassicalDescription.v</TT></A> for a
862
proof that excluded-middle and description implies the double negation
863
of excluded-middle in <TT>Set</TT> and file <TT>Hurkens_Set.v</TT> from the
864
user contribution <TT>Rocq/PARADOXES</TT> for a proof that
865
impredicativity of <TT>Set</TT> implies the simple negation of
866
excluded-middle in <TT>Set</TT>).<BR>
868
<!--TOC subsubsection Is <TT>Type</TT> impredicative?-->
870
<H4><A NAME="htoc45">38</A> Is <TT>Type</TT> impredicative?</H4><!--SEC END -->
872
No, <TT>Type</TT> is stratified. This is hidden for the
873
user, but <FONT COLOR=navy>Coq</FONT> internally maintains a set of constraints ensuring
876
If <TT>Type</TT> were impredicative then it would be possible to encode
877
Girard's systems <I>U</I>- and <I>U</I> in <FONT COLOR=navy>Coq</FONT> and it is known from Girard,
878
Coquand, Hurkens and Miquel that systems <I>U</I>- and <I>U</I> are inconsistent
879
[Girard 1972, Coquand 1991, Hurkens 1993, Miquel 2001]. This encoding
880
can be found in file <TT>Logic/Hurkens.v</TT> of <FONT COLOR=navy>Coq</FONT> standard library.<BR>
882
For instance, when the user see <TT>for all X:Type, X->X : Type</TT>, each
883
occurrence of <TT>Type</TT> is implicitly bound to a different level, say
884
alpha and beta and the actual statement is <TT>forall X:Type(alpha), X->X : Type(beta)</TT> with the constraint
887
When a statement violates a constraint, the message <TT>Universe
888
inconsistency</TT> appears. Example: <TT>fun (x:Type) (y:for all X:Type, X
889
-> X) => y x x</TT>.<BR>
891
<!--TOC subsubsection I have two proofs of the same proposition. Can I prove they are equal?-->
893
<H4><A NAME="htoc46">39</A> I have two proofs of the same proposition. Can I prove they are equal?</H4><!--SEC END -->
895
In the base <FONT COLOR=navy>Coq</FONT> system, the answer is generally no. However, if
896
classical logic is set, the answer is yes for propositions in <TT>Prop</TT>.
897
The answer is also yes if proof irrelevance holds (see question
898
<A HREF="#proof-irrelevance">34</A>).<BR>
900
There are also ``simple enough'' propositions for which you can prove
901
the equality without requiring any extra axioms. This is typically
902
the case for propositions defined deterministically as a first-order
903
inductive predicate on decidable sets. See for instance in question
904
<A HREF="#le-uniqueness">136</A> an axiom-free proof of the unicity of the proofs of
905
the proposition <TT>le m n</TT> (less or equal on <TT>nat</TT>).<BR>
907
<!--TOC subsubsection I have two proofs of an equality statement. Can I prove they are
910
<H4><A NAME="htoc47">40</A> I have two proofs of an equality statement. Can I prove they are
911
equal?</H4><!--SEC END -->
913
Yes, if equality is decidable on the domain considered (which
914
is the case for <TT>nat</TT>, <TT>bool</TT>, etc): see <FONT COLOR=navy>Coq</FONT> file
915
<CODE>Eqdep_dec.v</CODE>). No otherwise, unless
916
assuming Streicher's axiom <I>K</I> (see [<A HREF="#HofStr98"><CITE>12</CITE></A>]) or a more general
917
assumption such as proof-irrelevance (see <A HREF="#proof-irrelevance">34</A>) or
920
All of these statements can be found in file <A HREF="http://coq.inria.fr/library/Coq.Logic.Eqdep.html
921
"><TT>Eqdep.v</TT></A>.<BR>
923
<!--TOC subsubsection Can I prove that the second components of equal dependent
926
<H4><A NAME="htoc48">41</A> Can I prove that the second components of equal dependent
927
pairs are equal?</H4><!--SEC END -->
929
The answer is the same as for proofs of equality
930
statements. It is provable if equality on the domain of the first
931
component is decidable (look at <CODE>inj_right_pair</CODE> from file
932
<A HREF="http://coq.inria.fr/library/Coq.Logic.Eqdep_dec.html
933
"><TT>Eqdep_dec.v</TT></A>), but not provable in the general
934
case. However, it is consistent (with the Calculus of Constructions)
935
to assume it is true. The file <A HREF="http://coq.inria.fr/library/Coq.Logic.Eqdep.html
936
"><TT>Eqdep.v</TT></A> actually
937
provides an axiom (equivalent to Streicher's axiom <I>K</I>) which entails
938
the result (look at <CODE>inj_pair2</CODE> in <A HREF="http://coq.inria.fr/library/Coq.Logic.Eqdep.html
939
"><TT>Eqdep.v</TT></A>).<BR>
941
<!--TOC subsection Impredicativity-->
943
<H3><A NAME="htoc49">5.3</A> Impredicativity</H3><!--SEC END -->
945
<!--TOC subsubsection Why <TT>injection</TT> does not work on impredicative <TT>Set</TT>?-->
947
<H4><A NAME="htoc50">42</A> Why <TT>injection</TT> does not work on impredicative <TT>Set</TT>?</H4><!--SEC END -->
949
E.g. in this case (this occurs only in the <TT>Set</TT>-impredicative
950
variant of <FONT COLOR=navy>Coq</FONT>):<BR>
954
<TT>Coq < Inductive I : Type :=</TT><BR>
955
<TT>Coq < intro : forall k:Set, k -> I.</TT><BR>
957
<TT>Coq < Lemma eq_jdef : </TT><BR>
958
<TT>Coq < forall x y:nat, intro _ x = intro _ y -> x = y.</TT><BR>
960
<TT>Coq < Proof.</TT><BR>
962
<TT>Coq < intros x y H; injection H.</TT><BR>
965
Injectivity of constructors is restricted to predicative types. If
966
injectivity on large inductive types were not restricted, we would be
967
allowed to derive an inconsistency (e.g. following the lines of
968
Burali-Forti paradox). The question remains open whether injectivity
969
is consistent on some large inductive types not expressive enough to
970
encode known paradoxes (such as type I above).<BR>
972
<!--TOC subsubsection What is a "large inductive definition"?-->
974
<H4><A NAME="htoc51">43</A> What is a "large inductive definition"?</H4><!--SEC END -->
976
An inductive definition in <TT>Prop</TT> pr <TT>Set</TT> is called large
977
if its constructors embed sets or propositions. As an example, here is
978
a large inductive type:<BR>
982
<TT>Coq < Inductive sigST (P:Set -> Set) : Type :=</TT><BR>
983
<TT>Coq < existST : forall X:Set, P X -> sigST P.</TT><BR>
986
In the <TT>Set</TT> impredicative variant of <FONT COLOR=navy>Coq</FONT>, large inductive
987
definitions in <TT>Set</TT> have restricted elimination schemes to
988
prevent inconsistencies. Especially, projecting the set or the
989
proposition content of a large inductive definition is forbidden. If
990
it were allowed, it would be possible to encode e.g. Burali-Forti
991
paradox [<A HREF="#Gir70"><CITE>9</CITE></A><CITE>, </CITE><A HREF="#Coq85"><CITE>4</CITE></A>].<BR>
993
<!--TOC section Talkin' with the Rooster-->
995
<H2><A NAME="htoc52">6</A> Talkin' with the Rooster</H2><!--SEC END -->
997
<!--TOC subsection My goal is ..., how can I prove it?-->
999
<H3><A NAME="htoc53">6.1</A> My goal is ..., how can I prove it?</H3><!--SEC END -->
1001
<!--TOC subsubsection My goal is a conjunction, how can I prove it?-->
1003
<H4><A NAME="htoc54">44</A> My goal is a conjunction, how can I prove it?</H4><!--SEC END -->
1005
Use some theorem or assumption or use the <TT>split</TT> tactic.
1008
<TT>Coq < Goal forall A B:Prop, A->B-> A/\B.</TT><BR>
1009
<TT><I>1 subgoal</I></TT><BR>
1010
<TT><I> </I></TT><BR>
1011
<TT><I> ============================</I></TT><BR>
1012
<TT><I> forall A B : Prop, A -> B -> A /\ B</I></TT><BR>
1014
<TT>Coq < intros.</TT><BR>
1015
<TT><I>1 subgoal</I></TT><BR>
1016
<TT><I> </I></TT><BR>
1017
<TT><I> A : Prop</I></TT><BR>
1018
<TT><I> B : Prop</I></TT><BR>
1019
<TT><I> H : A</I></TT><BR>
1020
<TT><I> H0 : B</I></TT><BR>
1021
<TT><I> ============================</I></TT><BR>
1022
<TT><I> A /\ B</I></TT><BR>
1024
<TT>Coq < split.</TT><BR>
1025
<TT><I>2 subgoals</I></TT><BR>
1026
<TT><I> </I></TT><BR>
1027
<TT><I> A : Prop</I></TT><BR>
1028
<TT><I> B : Prop</I></TT><BR>
1029
<TT><I> H : A</I></TT><BR>
1030
<TT><I> H0 : B</I></TT><BR>
1031
<TT><I> ============================</I></TT><BR>
1032
<TT><I> A</I></TT><BR>
1033
<TT><I>subgoal 2 is:</I></TT><BR>
1034
<TT><I> B</I></TT><BR>
1036
<TT>Coq < assumption.</TT><BR>
1037
<TT><I>1 subgoal</I></TT><BR>
1038
<TT><I> </I></TT><BR>
1039
<TT><I> A : Prop</I></TT><BR>
1040
<TT><I> B : Prop</I></TT><BR>
1041
<TT><I> H : A</I></TT><BR>
1042
<TT><I> H0 : B</I></TT><BR>
1043
<TT><I> ============================</I></TT><BR>
1044
<TT><I> B</I></TT><BR>
1046
<TT>Coq < assumption.</TT><BR>
1047
<TT><I>Proof completed.</I></TT><BR>
1049
<TT>Coq < Qed.</TT><BR>
1050
<TT><I>intros.</I></TT><BR>
1051
<TT><I>split.</I></TT><BR>
1052
<TT><I> assumption.</I></TT><BR>
1053
<TT><I> assumption.</I></TT><BR>
1054
<TT><I>Unnamed_thm is defined</I></TT><BR>
1057
<!--TOC subsubsection My goal contains a conjunction as an hypothesis, how can I use it?-->
1059
<H4><A NAME="htoc55">45</A> My goal contains a conjunction as an hypothesis, how can I use it?</H4><!--SEC END -->
1061
If you want to decompose your hypothesis into other hypothesis you can use the <TT>decompose</TT> tactic:<BR>
1065
<TT>Coq < Goal forall A B:Prop, A/\B-> B.</TT><BR>
1066
<TT><I>1 subgoal</I></TT><BR>
1067
<TT><I> </I></TT><BR>
1068
<TT><I> ============================</I></TT><BR>
1069
<TT><I> forall A B : Prop, A /\ B -> B</I></TT><BR>
1071
<TT>Coq < intros.</TT><BR>
1072
<TT><I>1 subgoal</I></TT><BR>
1073
<TT><I> </I></TT><BR>
1074
<TT><I> A : Prop</I></TT><BR>
1075
<TT><I> B : Prop</I></TT><BR>
1076
<TT><I> H : A /\ B</I></TT><BR>
1077
<TT><I> ============================</I></TT><BR>
1078
<TT><I> B</I></TT><BR>
1080
<TT>Coq < decompose [and] H.</TT><BR>
1081
<TT><I>1 subgoal</I></TT><BR>
1082
<TT><I> </I></TT><BR>
1083
<TT><I> A : Prop</I></TT><BR>
1084
<TT><I> B : Prop</I></TT><BR>
1085
<TT><I> H : A /\ B</I></TT><BR>
1086
<TT><I> H0 : A</I></TT><BR>
1087
<TT><I> H1 : B</I></TT><BR>
1088
<TT><I> ============================</I></TT><BR>
1089
<TT><I> B</I></TT><BR>
1091
<TT>Coq < assumption.</TT><BR>
1092
<TT><I>Proof completed.</I></TT><BR>
1094
<TT>Coq < Qed.</TT><BR>
1095
<TT><I>intros.</I></TT><BR>
1096
<TT><I>decompose [and] H.</I></TT><BR>
1097
<TT><I>assumption.</I></TT><BR>
1098
<TT><I>Unnamed_thm0 is defined</I></TT><BR>
1101
<!--TOC subsubsection My goal is a disjunction, how can I prove it?-->
1103
<H4><A NAME="htoc56">46</A> My goal is a disjunction, how can I prove it?</H4><!--SEC END -->
1105
You can prove the left part or the right part of the disjunction using
1106
<TT>left</TT> or <TT>right</TT> tactics. If you want to do a classical
1107
reasoning step, use the <TT>classic</TT> axiom to prove the right part with the assumption
1108
that the left part of the disjunction is false.<BR>
1112
<TT>Coq < Goal forall A B:Prop, A-> A\/B.</TT><BR>
1113
<TT><I>1 subgoal</I></TT><BR>
1114
<TT><I> </I></TT><BR>
1115
<TT><I> ============================</I></TT><BR>
1116
<TT><I> forall A B : Prop, A -> A \/ B</I></TT><BR>
1118
<TT>Coq < intros.</TT><BR>
1119
<TT><I>1 subgoal</I></TT><BR>
1120
<TT><I> </I></TT><BR>
1121
<TT><I> A : Prop</I></TT><BR>
1122
<TT><I> B : Prop</I></TT><BR>
1123
<TT><I> H : A</I></TT><BR>
1124
<TT><I> ============================</I></TT><BR>
1125
<TT><I> A \/ B</I></TT><BR>
1127
<TT>Coq < left.</TT><BR>
1128
<TT><I>1 subgoal</I></TT><BR>
1129
<TT><I> </I></TT><BR>
1130
<TT><I> A : Prop</I></TT><BR>
1131
<TT><I> B : Prop</I></TT><BR>
1132
<TT><I> H : A</I></TT><BR>
1133
<TT><I> ============================</I></TT><BR>
1134
<TT><I> A</I></TT><BR>
1136
<TT>Coq < assumption.</TT><BR>
1137
<TT><I>Proof completed.</I></TT><BR>
1139
<TT>Coq < Qed.</TT><BR>
1140
<TT><I>intros.</I></TT><BR>
1141
<TT><I>left.</I></TT><BR>
1142
<TT><I>assumption.</I></TT><BR>
1143
<TT><I>Unnamed_thm1 is defined</I></TT><BR>
1146
An example using classical reasoning:<BR>
1150
<TT>Coq < Require Import Classical.</TT><BR>
1152
<TT>Coq < </TT><BR>
1153
<TT>Coq < Ltac classical_right := </TT><BR>
1154
<TT>Coq < match goal with </TT><BR>
1155
<TT>Coq < | _:_ |-?X1 \/ _ => (elim (classic X1);intro;[left;trivial|right])</TT><BR>
1156
<TT>Coq < end.</TT><BR>
1157
<TT><I>classical_right is defined</I></TT><BR>
1159
<TT>Coq < </TT><BR>
1160
<TT>Coq < Ltac classical_left := </TT><BR>
1161
<TT>Coq < match goal with </TT><BR>
1162
<TT>Coq < | _:_ |- _ \/?X1 => (elim (classic X1);intro;[right;trivial|left])</TT><BR>
1163
<TT>Coq < end.</TT><BR>
1164
<TT><I>classical_left is defined</I></TT><BR>
1166
<TT>Coq < </TT><BR>
1167
<TT>Coq < </TT><BR>
1168
<TT>Coq < Goal forall A B:Prop, (~A -> B) -> A\/B.</TT><BR>
1169
<TT><I>1 subgoal</I></TT><BR>
1170
<TT><I> </I></TT><BR>
1171
<TT><I> ============================</I></TT><BR>
1172
<TT><I> forall A B : Prop, (~ A -> B) -> A \/ B</I></TT><BR>
1174
<TT>Coq < intros.</TT><BR>
1175
<TT><I>1 subgoal</I></TT><BR>
1176
<TT><I> </I></TT><BR>
1177
<TT><I> A : Prop</I></TT><BR>
1178
<TT><I> B : Prop</I></TT><BR>
1179
<TT><I> H : ~ A -> B</I></TT><BR>
1180
<TT><I> ============================</I></TT><BR>
1181
<TT><I> A \/ B</I></TT><BR>
1183
<TT>Coq < classical_right.</TT><BR>
1184
<TT><I>1 subgoal</I></TT><BR>
1185
<TT><I> </I></TT><BR>
1186
<TT><I> A : Prop</I></TT><BR>
1187
<TT><I> B : Prop</I></TT><BR>
1188
<TT><I> H : ~ A -> B</I></TT><BR>
1189
<TT><I> H0 : ~ A</I></TT><BR>
1190
<TT><I> ============================</I></TT><BR>
1191
<TT><I> B</I></TT><BR>
1193
<TT>Coq < auto.</TT><BR>
1194
<TT><I>Proof completed.</I></TT><BR>
1196
<TT>Coq < Qed.</TT><BR>
1197
<TT><I>intros.</I></TT><BR>
1198
<TT><I>classical_right.</I></TT><BR>
1199
<TT><I>auto.</I></TT><BR>
1200
<TT><I>Unnamed_thm2 is defined</I></TT><BR>
1203
<!--TOC subsubsection My goal is an universally quantified statement, how can I prove it?-->
1205
<H4><A NAME="htoc57">47</A> My goal is an universally quantified statement, how can I prove it?</H4><!--SEC END -->
1207
Use some theorem or assumption or introduce the quantified variable in
1208
the context using the <TT>intro</TT> tactic. If there are several
1209
variables you can use the <TT>intros</TT> tactic. A good habit is to
1210
provide names for these variables: <FONT COLOR=navy>Coq</FONT> will do it anyway, but such
1211
automatic naming decreases legibility and robustness.<BR>
1213
<!--TOC subsubsection My goal is an existential, how can I prove it?-->
1215
<H4><A NAME="htoc58">48</A> My goal is an existential, how can I prove it?</H4><!--SEC END -->
1217
Use some theorem or assumption or exhibit the witness using the <TT>exists</TT> tactic.
1220
<TT>Coq < Goal exists x:nat, forall y, x+y=y.</TT><BR>
1221
<TT><I>1 subgoal</I></TT><BR>
1222
<TT><I> </I></TT><BR>
1223
<TT><I> ============================</I></TT><BR>
1224
<TT><I> exists x : nat, (forall y : nat, x + y = y)</I></TT><BR>
1226
<TT>Coq < exists 0.</TT><BR>
1227
<TT><I>1 subgoal</I></TT><BR>
1228
<TT><I> </I></TT><BR>
1229
<TT><I> ============================</I></TT><BR>
1230
<TT><I> forall y : nat, 0 + y = y</I></TT><BR>
1232
<TT>Coq < intros.</TT><BR>
1233
<TT><I>1 subgoal</I></TT><BR>
1234
<TT><I> </I></TT><BR>
1235
<TT><I> y : nat</I></TT><BR>
1236
<TT><I> ============================</I></TT><BR>
1237
<TT><I> 0 + y = y</I></TT><BR>
1239
<TT>Coq < auto.</TT><BR>
1240
<TT><I>Proof completed.</I></TT><BR>
1242
<TT>Coq < Qed.</TT><BR>
1243
<TT><I>exists 0.</I></TT><BR>
1244
<TT><I>intros.</I></TT><BR>
1245
<TT><I>auto.</I></TT><BR>
1246
<TT><I>Unnamed_thm3 is defined</I></TT><BR>
1249
<!--TOC subsubsection My goal is solvable by some lemma, how can I prove it?-->
1251
<H4><A NAME="htoc59">49</A> My goal is solvable by some lemma, how can I prove it?</H4><!--SEC END -->
1253
Just use the <TT>apply</TT> tactic.<BR>
1257
<TT>Coq < Lemma mylemma : forall x, x+0 = x.</TT><BR>
1258
<TT><I>1 subgoal</I></TT><BR>
1259
<TT><I> </I></TT><BR>
1260
<TT><I> ============================</I></TT><BR>
1261
<TT><I> forall x : nat, x + 0 = x</I></TT><BR>
1263
<TT>Coq < auto.</TT><BR>
1264
<TT><I>Proof completed.</I></TT><BR>
1266
<TT>Coq < Qed.</TT><BR>
1267
<TT><I>auto.</I></TT><BR>
1268
<TT><I>mylemma is defined</I></TT><BR>
1270
<TT>Coq < </TT><BR>
1271
<TT>Coq < Goal 3+0 = 3.</TT><BR>
1272
<TT><I>1 subgoal</I></TT><BR>
1273
<TT><I> </I></TT><BR>
1274
<TT><I> ============================</I></TT><BR>
1275
<TT><I> 3 + 0 = 3</I></TT><BR>
1277
<TT>Coq < apply mylemma.</TT><BR>
1278
<TT><I>Proof completed.</I></TT><BR>
1280
<TT>Coq < Qed.</TT><BR>
1281
<TT><I>apply mylemma.</I></TT><BR>
1282
<TT><I>Unnamed_thm is defined</I></TT><BR>
1285
<!--TOC subsubsection My goal contains False as an hypotheses, how can I prove it?-->
1287
<H4><A NAME="htoc60">50</A> My goal contains False as an hypotheses, how can I prove it?</H4><!--SEC END -->
1289
You can use the <TT>contradiction</TT> or <TT>intuition</TT> tactics.<BR>
1291
<!--TOC subsubsection My goal is an equality of two convertible terms, how can I prove it?-->
1293
<H4><A NAME="htoc61">51</A> My goal is an equality of two convertible terms, how can I prove it?</H4><!--SEC END -->
1295
Just use the <TT>reflexivity</TT> tactic.<BR>
1299
<TT>Coq < Goal forall x, 0+x = x.</TT><BR>
1300
<TT><I>1 subgoal</I></TT><BR>
1301
<TT><I> </I></TT><BR>
1302
<TT><I> ============================</I></TT><BR>
1303
<TT><I> forall x : nat, 0 + x = x</I></TT><BR>
1305
<TT>Coq < intros.</TT><BR>
1306
<TT><I>1 subgoal</I></TT><BR>
1307
<TT><I> </I></TT><BR>
1308
<TT><I> x : nat</I></TT><BR>
1309
<TT><I> ============================</I></TT><BR>
1310
<TT><I> 0 + x = x</I></TT><BR>
1312
<TT>Coq < reflexivity.</TT><BR>
1313
<TT><I>Proof completed.</I></TT><BR>
1315
<TT>Coq < Qed.</TT><BR>
1316
<TT><I>intros.</I></TT><BR>
1317
<TT><I>reflexivity.</I></TT><BR>
1318
<TT><I>Unnamed_thm0 is defined</I></TT><BR>
1321
<!--TOC subsubsection My goal is a <TT>let x := a in ...</TT>, how can I prove it?-->
1323
<H4><A NAME="htoc62">52</A> My goal is a <TT>let x := a in ...</TT>, how can I prove it?</H4><!--SEC END -->
1325
Just use the <TT>intro</TT> tactic.<BR>
1327
<!--TOC subsubsection My goal is a <TT>let (a, ..., b) := c in</TT>, how can I prove it?-->
1329
<H4><A NAME="htoc63">53</A> My goal is a <TT>let (a, ..., b) := c in</TT>, how can I prove it?</H4><!--SEC END -->
1331
Just use the <TT>destruct</TT> c as (a,...,b) tactic.<BR>
1333
<!--TOC subsubsection My goal contains some existential hypotheses, how can I use it?-->
1335
<H4><A NAME="htoc64">54</A> My goal contains some existential hypotheses, how can I use it?</H4><!--SEC END -->
1337
You can use the tactic <TT>elim</TT> with you hypotheses as an argument.<BR>
1339
<!--TOC subsubsection My goal contains some existential hypotheses, how can I use it and decompose my knowledge about this new thing into different hypotheses?-->
1341
<H4><A NAME="htoc65">55</A> My goal contains some existential hypotheses, how can I use it and decompose my knowledge about this new thing into different hypotheses?</H4><!--SEC END -->
1344
Ltac DecompEx H P := elim H;intro P;intro TO;decompose [and] TO;clear TO;clear H.
1346
<!--TOC subsubsection My goal is an equality, how can I swap the left and right hand terms?-->
1348
<H4><A NAME="htoc66">56</A> My goal is an equality, how can I swap the left and right hand terms?</H4><!--SEC END -->
1350
Just use the <TT>symmetry</TT> tactic.
1353
<TT>Coq < Goal forall x y : nat, x=y -> y=x.</TT><BR>
1354
<TT><I>1 subgoal</I></TT><BR>
1355
<TT><I> </I></TT><BR>
1356
<TT><I> ============================</I></TT><BR>
1357
<TT><I> forall x y : nat, x = y -> y = x</I></TT><BR>
1359
<TT>Coq < intros.</TT><BR>
1360
<TT><I>1 subgoal</I></TT><BR>
1361
<TT><I> </I></TT><BR>
1362
<TT><I> x : nat</I></TT><BR>
1363
<TT><I> y : nat</I></TT><BR>
1364
<TT><I> H : x = y</I></TT><BR>
1365
<TT><I> ============================</I></TT><BR>
1366
<TT><I> y = x</I></TT><BR>
1368
<TT>Coq < symmetry.</TT><BR>
1369
<TT><I>1 subgoal</I></TT><BR>
1370
<TT><I> </I></TT><BR>
1371
<TT><I> x : nat</I></TT><BR>
1372
<TT><I> y : nat</I></TT><BR>
1373
<TT><I> H : x = y</I></TT><BR>
1374
<TT><I> ============================</I></TT><BR>
1375
<TT><I> x = y</I></TT><BR>
1377
<TT>Coq < assumption.</TT><BR>
1378
<TT><I>Proof completed.</I></TT><BR>
1380
<TT>Coq < Qed.</TT><BR>
1381
<TT><I>intros.</I></TT><BR>
1382
<TT><I>symmetry in |- *.</I></TT><BR>
1383
<TT><I>assumption.</I></TT><BR>
1384
<TT><I>Unnamed_thm1 is defined</I></TT><BR>
1387
<!--TOC subsubsection My hypothesis is an equality, how can I swap the left and right hand terms?-->
1389
<H4><A NAME="htoc67">57</A> My hypothesis is an equality, how can I swap the left and right hand terms?</H4><!--SEC END -->
1391
Just use the <TT>symmetryin</TT> tactic.<BR>
1395
<TT>Coq < Goal forall x y : nat, x=y -> y=x.</TT><BR>
1396
<TT><I>1 subgoal</I></TT><BR>
1397
<TT><I> </I></TT><BR>
1398
<TT><I> ============================</I></TT><BR>
1399
<TT><I> forall x y : nat, x = y -> y = x</I></TT><BR>
1401
<TT>Coq < intros.</TT><BR>
1402
<TT><I>1 subgoal</I></TT><BR>
1403
<TT><I> </I></TT><BR>
1404
<TT><I> x : nat</I></TT><BR>
1405
<TT><I> y : nat</I></TT><BR>
1406
<TT><I> H : x = y</I></TT><BR>
1407
<TT><I> ============================</I></TT><BR>
1408
<TT><I> y = x</I></TT><BR>
1410
<TT>Coq < symmetry in H.</TT><BR>
1411
<TT><I>1 subgoal</I></TT><BR>
1412
<TT><I> </I></TT><BR>
1413
<TT><I> x : nat</I></TT><BR>
1414
<TT><I> y : nat</I></TT><BR>
1415
<TT><I> H : y = x</I></TT><BR>
1416
<TT><I> ============================</I></TT><BR>
1417
<TT><I> y = x</I></TT><BR>
1419
<TT>Coq < assumption.</TT><BR>
1420
<TT><I>Proof completed.</I></TT><BR>
1422
<TT>Coq < Qed.</TT><BR>
1423
<TT><I>intros.</I></TT><BR>
1424
<TT><I>symmetry in H.</I></TT><BR>
1425
<TT><I>assumption.</I></TT><BR>
1426
<TT><I>Unnamed_thm2 is defined</I></TT><BR>
1429
<!--TOC subsubsection My goal is an equality, how can I prove it by transitivity?-->
1431
<H4><A NAME="htoc68">58</A> My goal is an equality, how can I prove it by transitivity?</H4><!--SEC END -->
1433
Just use the <TT>transitivity</TT> tactic.
1436
<TT>Coq < Goal forall x y z : nat, x=y -> y=z -> x=z.</TT><BR>
1437
<TT><I>1 subgoal</I></TT><BR>
1438
<TT><I> </I></TT><BR>
1439
<TT><I> ============================</I></TT><BR>
1440
<TT><I> forall x y z : nat, x = y -> y = z -> x = z</I></TT><BR>
1442
<TT>Coq < intros.</TT><BR>
1443
<TT><I>1 subgoal</I></TT><BR>
1444
<TT><I> </I></TT><BR>
1445
<TT><I> x : nat</I></TT><BR>
1446
<TT><I> y : nat</I></TT><BR>
1447
<TT><I> z : nat</I></TT><BR>
1448
<TT><I> H : x = y</I></TT><BR>
1449
<TT><I> H0 : y = z</I></TT><BR>
1450
<TT><I> ============================</I></TT><BR>
1451
<TT><I> x = z</I></TT><BR>
1453
<TT>Coq < transitivity y.</TT><BR>
1454
<TT><I>2 subgoals</I></TT><BR>
1455
<TT><I> </I></TT><BR>
1456
<TT><I> x : nat</I></TT><BR>
1457
<TT><I> y : nat</I></TT><BR>
1458
<TT><I> z : nat</I></TT><BR>
1459
<TT><I> H : x = y</I></TT><BR>
1460
<TT><I> H0 : y = z</I></TT><BR>
1461
<TT><I> ============================</I></TT><BR>
1462
<TT><I> x = y</I></TT><BR>
1463
<TT><I>subgoal 2 is:</I></TT><BR>
1464
<TT><I> y = z</I></TT><BR>
1466
<TT>Coq < assumption.</TT><BR>
1467
<TT><I>1 subgoal</I></TT><BR>
1468
<TT><I> </I></TT><BR>
1469
<TT><I> x : nat</I></TT><BR>
1470
<TT><I> y : nat</I></TT><BR>
1471
<TT><I> z : nat</I></TT><BR>
1472
<TT><I> H : x = y</I></TT><BR>
1473
<TT><I> H0 : y = z</I></TT><BR>
1474
<TT><I> ============================</I></TT><BR>
1475
<TT><I> y = z</I></TT><BR>
1477
<TT>Coq < assumption.</TT><BR>
1478
<TT><I>Proof completed.</I></TT><BR>
1480
<TT>Coq < Qed.</TT><BR>
1481
<TT><I>intros.</I></TT><BR>
1482
<TT><I>transitivity y.</I></TT><BR>
1483
<TT><I> assumption.</I></TT><BR>
1484
<TT><I> assumption.</I></TT><BR>
1485
<TT><I>Unnamed_thm3 is defined</I></TT><BR>
1488
<!--TOC subsubsection My goal would be solvable using <TT>apply;assumption</TT> if it would not create meta-variables, how can I prove it?-->
1490
<H4><A NAME="htoc69">59</A> My goal would be solvable using <TT>apply;assumption</TT> if it would not create meta-variables, how can I prove it?</H4><!--SEC END -->
1492
You can use <TT>eapply yourtheorem;eauto</TT> but it won't work in all cases ! (for example if more than one hypothesis match one of the subgoals generated by <TT>eapply</TT>) so you should rather use <TT>try solve [eapply yourtheorem;eauto]</TT>, otherwise some metavariables may be incorrectly instantiated.<BR>
1496
<TT>Coq < Lemma trans : forall x y z : nat, x=y -> y=z -> x=z.</TT><BR>
1497
<TT><I>1 subgoal</I></TT><BR>
1498
<TT><I> </I></TT><BR>
1499
<TT><I> ============================</I></TT><BR>
1500
<TT><I> forall x y z : nat, x = y -> y = z -> x = z</I></TT><BR>
1502
<TT>Coq < intros.</TT><BR>
1503
<TT><I>1 subgoal</I></TT><BR>
1504
<TT><I> </I></TT><BR>
1505
<TT><I> x : nat</I></TT><BR>
1506
<TT><I> y : nat</I></TT><BR>
1507
<TT><I> z : nat</I></TT><BR>
1508
<TT><I> H : x = y</I></TT><BR>
1509
<TT><I> H0 : y = z</I></TT><BR>
1510
<TT><I> ============================</I></TT><BR>
1511
<TT><I> x = z</I></TT><BR>
1513
<TT>Coq < transitivity y;assumption.</TT><BR>
1514
<TT><I>Proof completed.</I></TT><BR>
1516
<TT>Coq < Qed.</TT><BR>
1517
<TT><I>intros.</I></TT><BR>
1518
<TT><I>transitivity y; assumption.</I></TT><BR>
1519
<TT><I>trans is defined</I></TT><BR>
1521
<TT>Coq < </TT><BR>
1522
<TT>Coq < Goal forall x y z : nat, x=y -> y=z -> x=z.</TT><BR>
1523
<TT><I>1 subgoal</I></TT><BR>
1524
<TT><I> </I></TT><BR>
1525
<TT><I> ============================</I></TT><BR>
1526
<TT><I> forall x y z : nat, x = y -> y = z -> x = z</I></TT><BR>
1528
<TT>Coq < intros.</TT><BR>
1529
<TT><I>1 subgoal</I></TT><BR>
1530
<TT><I> </I></TT><BR>
1531
<TT><I> x : nat</I></TT><BR>
1532
<TT><I> y : nat</I></TT><BR>
1533
<TT><I> z : nat</I></TT><BR>
1534
<TT><I> H : x = y</I></TT><BR>
1535
<TT><I> H0 : y = z</I></TT><BR>
1536
<TT><I> ============================</I></TT><BR>
1537
<TT><I> x = z</I></TT><BR>
1539
<TT>Coq < eapply trans;eauto.</TT><BR>
1540
<TT><I>Proof completed.</I></TT><BR>
1542
<TT>Coq < Qed.</TT><BR>
1543
<TT><I>intros.</I></TT><BR>
1544
<TT><I>eapply trans; eauto.</I></TT><BR>
1545
<TT><I>Unnamed_thm4 is defined</I></TT><BR>
1547
<TT>Coq < </TT><BR>
1548
<TT>Coq < Goal forall x y z t : nat, x=y -> x=t -> y=z -> x=z.</TT><BR>
1549
<TT><I>1 subgoal</I></TT><BR>
1550
<TT><I> </I></TT><BR>
1551
<TT><I> ============================</I></TT><BR>
1552
<TT><I> forall x y z t : nat, x = y -> x = t -> y = z -> x = z</I></TT><BR>
1554
<TT>Coq < intros.</TT><BR>
1555
<TT><I>1 subgoal</I></TT><BR>
1556
<TT><I> </I></TT><BR>
1557
<TT><I> x : nat</I></TT><BR>
1558
<TT><I> y : nat</I></TT><BR>
1559
<TT><I> z : nat</I></TT><BR>
1560
<TT><I> t : nat</I></TT><BR>
1561
<TT><I> H : x = y</I></TT><BR>
1562
<TT><I> H0 : x = t</I></TT><BR>
1563
<TT><I> H1 : y = z</I></TT><BR>
1564
<TT><I> ============================</I></TT><BR>
1565
<TT><I> x = z</I></TT><BR>
1567
<TT>Coq < eapply trans;eauto.</TT><BR>
1568
<TT><I>1 subgoal</I></TT><BR>
1569
<TT><I> </I></TT><BR>
1570
<TT><I> x : nat</I></TT><BR>
1571
<TT><I> y : nat</I></TT><BR>
1572
<TT><I> z : nat</I></TT><BR>
1573
<TT><I> t : nat</I></TT><BR>
1574
<TT><I> H : x = y</I></TT><BR>
1575
<TT><I> H0 : x = t</I></TT><BR>
1576
<TT><I> H1 : y = z</I></TT><BR>
1577
<TT><I> ============================</I></TT><BR>
1578
<TT><I> t = z</I></TT><BR>
1580
<TT>Coq < Undo.</TT><BR>
1581
<TT><I>1 subgoal</I></TT><BR>
1582
<TT><I> </I></TT><BR>
1583
<TT><I> x : nat</I></TT><BR>
1584
<TT><I> y : nat</I></TT><BR>
1585
<TT><I> z : nat</I></TT><BR>
1586
<TT><I> t : nat</I></TT><BR>
1587
<TT><I> H : x = y</I></TT><BR>
1588
<TT><I> H0 : x = t</I></TT><BR>
1589
<TT><I> H1 : y = z</I></TT><BR>
1590
<TT><I> ============================</I></TT><BR>
1591
<TT><I> x = z</I></TT><BR>
1593
<TT>Coq < eapply trans.</TT><BR>
1594
<TT><I>2 subgoals</I></TT><BR>
1595
<TT><I> </I></TT><BR>
1596
<TT><I> x : nat</I></TT><BR>
1597
<TT><I> y : nat</I></TT><BR>
1598
<TT><I> z : nat</I></TT><BR>
1599
<TT><I> t : nat</I></TT><BR>
1600
<TT><I> H : x = y</I></TT><BR>
1601
<TT><I> H0 : x = t</I></TT><BR>
1602
<TT><I> H1 : y = z</I></TT><BR>
1603
<TT><I> ============================</I></TT><BR>
1604
<TT><I> x = ?47</I></TT><BR>
1605
<TT><I>subgoal 2 is:</I></TT><BR>
1606
<TT><I> ?47 = z</I></TT><BR>
1608
<TT>Coq < apply H.</TT><BR>
1609
<TT><I>1 subgoal</I></TT><BR>
1610
<TT><I> </I></TT><BR>
1611
<TT><I> x : nat</I></TT><BR>
1612
<TT><I> y : nat</I></TT><BR>
1613
<TT><I> z : nat</I></TT><BR>
1614
<TT><I> t : nat</I></TT><BR>
1615
<TT><I> H : x = y</I></TT><BR>
1616
<TT><I> H0 : x = t</I></TT><BR>
1617
<TT><I> H1 : y = z</I></TT><BR>
1618
<TT><I> ============================</I></TT><BR>
1619
<TT><I> y = z</I></TT><BR>
1621
<TT>Coq < auto.</TT><BR>
1622
<TT><I>Proof completed.</I></TT><BR>
1624
<TT>Coq < Qed.</TT><BR>
1625
<TT><I>intros.</I></TT><BR>
1626
<TT><I>eapply trans.</I></TT><BR>
1627
<TT><I> apply H.</I></TT><BR>
1628
<TT><I> </I></TT><BR>
1629
<TT><I> auto.</I></TT><BR>
1630
<TT><I>Unnamed_thm5 is defined</I></TT><BR>
1632
<TT>Coq < </TT><BR>
1633
<TT>Coq < Goal forall x y z t : nat, x=y -> x=t -> y=z -> x=z.</TT><BR>
1634
<TT><I>1 subgoal</I></TT><BR>
1635
<TT><I> </I></TT><BR>
1636
<TT><I> ============================</I></TT><BR>
1637
<TT><I> forall x y z t : nat, x = y -> x = t -> y = z -> x = z</I></TT><BR>
1639
<TT>Coq < intros.</TT><BR>
1640
<TT><I>1 subgoal</I></TT><BR>
1641
<TT><I> </I></TT><BR>
1642
<TT><I> x : nat</I></TT><BR>
1643
<TT><I> y : nat</I></TT><BR>
1644
<TT><I> z : nat</I></TT><BR>
1645
<TT><I> t : nat</I></TT><BR>
1646
<TT><I> H : x = y</I></TT><BR>
1647
<TT><I> H0 : x = t</I></TT><BR>
1648
<TT><I> H1 : y = z</I></TT><BR>
1649
<TT><I> ============================</I></TT><BR>
1650
<TT><I> x = z</I></TT><BR>
1652
<TT>Coq < eapply trans;eauto.</TT><BR>
1653
<TT><I>1 subgoal</I></TT><BR>
1654
<TT><I> </I></TT><BR>
1655
<TT><I> x : nat</I></TT><BR>
1656
<TT><I> y : nat</I></TT><BR>
1657
<TT><I> z : nat</I></TT><BR>
1658
<TT><I> t : nat</I></TT><BR>
1659
<TT><I> H : x = y</I></TT><BR>
1660
<TT><I> H0 : x = t</I></TT><BR>
1661
<TT><I> H1 : y = z</I></TT><BR>
1662
<TT><I> ============================</I></TT><BR>
1663
<TT><I> t = z</I></TT><BR>
1665
<TT>Coq < Undo.</TT><BR>
1666
<TT><I>1 subgoal</I></TT><BR>
1667
<TT><I> </I></TT><BR>
1668
<TT><I> x : nat</I></TT><BR>
1669
<TT><I> y : nat</I></TT><BR>
1670
<TT><I> z : nat</I></TT><BR>
1671
<TT><I> t : nat</I></TT><BR>
1672
<TT><I> H : x = y</I></TT><BR>
1673
<TT><I> H0 : x = t</I></TT><BR>
1674
<TT><I> H1 : y = z</I></TT><BR>
1675
<TT><I> ============================</I></TT><BR>
1676
<TT><I> x = z</I></TT><BR>
1678
<TT>Coq < try solve [eapply trans;eauto].</TT><BR>
1679
<TT><I>1 subgoal</I></TT><BR>
1680
<TT><I> </I></TT><BR>
1681
<TT><I> x : nat</I></TT><BR>
1682
<TT><I> y : nat</I></TT><BR>
1683
<TT><I> z : nat</I></TT><BR>
1684
<TT><I> t : nat</I></TT><BR>
1685
<TT><I> H : x = y</I></TT><BR>
1686
<TT><I> H0 : x = t</I></TT><BR>
1687
<TT><I> H1 : y = z</I></TT><BR>
1688
<TT><I> ============================</I></TT><BR>
1689
<TT><I> x = z</I></TT><BR>
1691
<TT>Coq < eapply trans.</TT><BR>
1692
<TT><I>2 subgoals</I></TT><BR>
1693
<TT><I> </I></TT><BR>
1694
<TT><I> x : nat</I></TT><BR>
1695
<TT><I> y : nat</I></TT><BR>
1696
<TT><I> z : nat</I></TT><BR>
1697
<TT><I> t : nat</I></TT><BR>
1698
<TT><I> H : x = y</I></TT><BR>
1699
<TT><I> H0 : x = t</I></TT><BR>
1700
<TT><I> H1 : y = z</I></TT><BR>
1701
<TT><I> ============================</I></TT><BR>
1702
<TT><I> x = ?54</I></TT><BR>
1703
<TT><I>subgoal 2 is:</I></TT><BR>
1704
<TT><I> ?54 = z</I></TT><BR>
1706
<TT>Coq < apply H.</TT><BR>
1707
<TT><I>1 subgoal</I></TT><BR>
1708
<TT><I> </I></TT><BR>
1709
<TT><I> x : nat</I></TT><BR>
1710
<TT><I> y : nat</I></TT><BR>
1711
<TT><I> z : nat</I></TT><BR>
1712
<TT><I> t : nat</I></TT><BR>
1713
<TT><I> H : x = y</I></TT><BR>
1714
<TT><I> H0 : x = t</I></TT><BR>
1715
<TT><I> H1 : y = z</I></TT><BR>
1716
<TT><I> ============================</I></TT><BR>
1717
<TT><I> y = z</I></TT><BR>
1719
<TT>Coq < auto.</TT><BR>
1720
<TT><I>Proof completed.</I></TT><BR>
1722
<TT>Coq < Qed.</TT><BR>
1723
<TT><I>intros.</I></TT><BR>
1724
<TT><I>try solve [ eapply trans; eauto ].</I></TT><BR>
1725
<TT><I>eapply trans.</I></TT><BR>
1726
<TT><I> apply H.</I></TT><BR>
1727
<TT><I> </I></TT><BR>
1728
<TT><I> auto.</I></TT><BR>
1729
<TT><I>Unnamed_thm6 is defined</I></TT><BR>
1731
<TT>Coq < </TT><BR>
1734
<!--TOC subsubsection My goal is solvable by some lemma within a set of lemmas and I don't want to remember which one, how can I prove it?-->
1736
<H4><A NAME="htoc70">60</A> My goal is solvable by some lemma within a set of lemmas and I don't want to remember which one, how can I prove it?</H4><!--SEC END -->
1738
You can use a what is called a hints' base.<BR>
1742
<TT>Coq < Require Import ZArith.</TT><BR>
1743
<TT><I>Coq < </I></TT><BR>
1745
<TT>Coq < Require Ring.</TT><BR>
1747
<TT>Coq < Open Local Scope Z_scope.</TT><BR>
1749
<TT>Coq < Lemma toto1 : 1+1 = 2.</TT><BR>
1750
<TT><I>1 subgoal</I></TT><BR>
1751
<TT><I> </I></TT><BR>
1752
<TT><I> ============================</I></TT><BR>
1753
<TT><I> 1 + 1 = 2</I></TT><BR>
1755
<TT>Coq < ring.</TT><BR>
1756
<TT><I>Proof completed.</I></TT><BR>
1758
<TT>Coq < Qed.</TT><BR>
1759
<TT><I>ring.</I></TT><BR>
1760
<TT><I>toto1 is defined</I></TT><BR>
1762
<TT>Coq < Lemma toto2 : 2+2 = 4.</TT><BR>
1763
<TT><I>1 subgoal</I></TT><BR>
1764
<TT><I> </I></TT><BR>
1765
<TT><I> ============================</I></TT><BR>
1766
<TT><I> 2 + 2 = 4</I></TT><BR>
1768
<TT>Coq < ring.</TT><BR>
1769
<TT><I>Proof completed.</I></TT><BR>
1771
<TT>Coq < Qed.</TT><BR>
1772
<TT><I>ring.</I></TT><BR>
1773
<TT><I>toto2 is defined</I></TT><BR>
1775
<TT>Coq < Lemma toto3 : 2+1 = 3.</TT><BR>
1776
<TT><I>1 subgoal</I></TT><BR>
1777
<TT><I> </I></TT><BR>
1778
<TT><I> ============================</I></TT><BR>
1779
<TT><I> 2 + 1 = 3</I></TT><BR>
1781
<TT>Coq < ring.</TT><BR>
1782
<TT><I>Proof completed.</I></TT><BR>
1784
<TT>Coq < Qed.</TT><BR>
1785
<TT><I>ring.</I></TT><BR>
1786
<TT><I>toto3 is defined</I></TT><BR>
1788
<TT>Coq < </TT><BR>
1789
<TT>Coq < Hint Resolve toto1 toto2 toto3 : mybase.</TT><BR>
1791
<TT>Coq < </TT><BR>
1792
<TT>Coq < Goal 2+(1+1)=4. </TT><BR>
1793
<TT><I>1 subgoal</I></TT><BR>
1794
<TT><I> </I></TT><BR>
1795
<TT><I> ============================</I></TT><BR>
1796
<TT><I> 2 + (1 + 1) = 4</I></TT><BR>
1798
<TT>Coq < auto with mybase.</TT><BR>
1799
<TT><I>Proof completed.</I></TT><BR>
1801
<TT>Coq < Qed.</TT><BR>
1802
<TT><I>auto with mybase.</I></TT><BR>
1803
<TT><I>Unnamed_thm7 is defined</I></TT><BR>
1806
<!--TOC subsubsection My goal is one of the hypotheses, how can I prove it?-->
1808
<H4><A NAME="htoc71">61</A> My goal is one of the hypotheses, how can I prove it?</H4><!--SEC END -->
1810
Use the <TT>assumption</TT> tactic.<BR>
1814
<TT>Coq < Goal 1=1 -> 1=1.</TT><BR>
1815
<TT><I>1 subgoal</I></TT><BR>
1816
<TT><I> </I></TT><BR>
1817
<TT><I> ============================</I></TT><BR>
1818
<TT><I> 1 = 1 -> 1 = 1</I></TT><BR>
1820
<TT>Coq < intro.</TT><BR>
1821
<TT><I>1 subgoal</I></TT><BR>
1822
<TT><I> </I></TT><BR>
1823
<TT><I> H : 1 = 1</I></TT><BR>
1824
<TT><I> ============================</I></TT><BR>
1825
<TT><I> 1 = 1</I></TT><BR>
1827
<TT>Coq < assumption.</TT><BR>
1828
<TT><I>Proof completed.</I></TT><BR>
1830
<TT>Coq < Qed.</TT><BR>
1831
<TT><I>intro.</I></TT><BR>
1832
<TT><I>assumption.</I></TT><BR>
1833
<TT><I>Unnamed_thm8 is defined</I></TT><BR>
1836
<!--TOC subsubsection My goal appears twice in the hypotheses and I want to choose which one is used, how can I do it?-->
1838
<H4><A NAME="htoc72">62</A> My goal appears twice in the hypotheses and I want to choose which one is used, how can I do it?</H4><!--SEC END -->
1840
Use the <TT>exact</TT> tactic.
1843
<TT>Coq < Goal 1=1 -> 1=1 -> 1=1.</TT><BR>
1844
<TT><I>1 subgoal</I></TT><BR>
1845
<TT><I> </I></TT><BR>
1846
<TT><I> ============================</I></TT><BR>
1847
<TT><I> 1 = 1 -> 1 = 1 -> 1 = 1</I></TT><BR>
1849
<TT>Coq < intros.</TT><BR>
1850
<TT><I>1 subgoal</I></TT><BR>
1851
<TT><I> </I></TT><BR>
1852
<TT><I> H : 1 = 1</I></TT><BR>
1853
<TT><I> H0 : 1 = 1</I></TT><BR>
1854
<TT><I> ============================</I></TT><BR>
1855
<TT><I> 1 = 1</I></TT><BR>
1857
<TT>Coq < exact H0.</TT><BR>
1858
<TT><I>Proof completed.</I></TT><BR>
1860
<TT>Coq < Qed.</TT><BR>
1861
<TT><I>intros.</I></TT><BR>
1862
<TT><I>exact H0.</I></TT><BR>
1863
<TT><I>Unnamed_thm9 is defined</I></TT><BR>
1866
<!--TOC subsubsection What can be the difference between applying one hypothesis or another in the context of the last question?-->
1868
<H4><A NAME="htoc73">63</A> What can be the difference between applying one hypothesis or another in the context of the last question?</H4><!--SEC END -->
1870
From a proof point of view it is equivalent but if you want to extract
1871
a program from your proof, the two hypotheses can lead to different
1874
<!--TOC subsubsection My goal is a propositional tautology, how can I prove it?-->
1876
<H4><A NAME="htoc74">64</A> My goal is a propositional tautology, how can I prove it?</H4><!--SEC END -->
1878
Just use the <TT>tauto</TT> tactic.
1881
<TT>Coq < Goal forall A B:Prop, A-> (A\/B) /\ A.</TT><BR>
1882
<TT><I>1 subgoal</I></TT><BR>
1883
<TT><I> </I></TT><BR>
1884
<TT><I> ============================</I></TT><BR>
1885
<TT><I> forall A B : Prop, A -> (A \/ B) /\ A</I></TT><BR>
1887
<TT>Coq < intros.</TT><BR>
1888
<TT><I>1 subgoal</I></TT><BR>
1889
<TT><I> </I></TT><BR>
1890
<TT><I> A : Prop</I></TT><BR>
1891
<TT><I> B : Prop</I></TT><BR>
1892
<TT><I> H : A</I></TT><BR>
1893
<TT><I> ============================</I></TT><BR>
1894
<TT><I> (A \/ B) /\ A</I></TT><BR>
1896
<TT>Coq < tauto.</TT><BR>
1897
<TT><I>Proof completed.</I></TT><BR>
1899
<TT>Coq < Qed.</TT><BR>
1900
<TT><I>intros.</I></TT><BR>
1901
<TT><I>tauto.</I></TT><BR>
1902
<TT><I>Unnamed_thm10 is defined</I></TT><BR>
1905
<!--TOC subsubsection My goal is a first order formula, how can I prove it?-->
1907
<H4><A NAME="htoc75">65</A> My goal is a first order formula, how can I prove it?</H4><!--SEC END -->
1909
Just use the semi-decision tactic: <TT>firstorder</TT>.<BR>
1911
<!--TOC subsubsection My goal is solvable by a sequence of rewrites, how can I prove it?-->
1913
<H4><A NAME="htoc76">66</A> My goal is solvable by a sequence of rewrites, how can I prove it?</H4><!--SEC END -->
1915
Just use the <TT>congruence</TT> tactic.
1918
<TT>Coq < Goal forall a b c d e, a=d -> b=e -> c+b=d -> c+e=a.</TT><BR>
1919
<TT><I>1 subgoal</I></TT><BR>
1920
<TT><I> </I></TT><BR>
1921
<TT><I> ============================</I></TT><BR>
1922
<TT><I> forall a b c d e : Z, a = d -> b = e -> c + b = d -> c + e = a</I></TT><BR>
1924
<TT>Coq < intros.</TT><BR>
1925
<TT><I>1 subgoal</I></TT><BR>
1926
<TT><I> </I></TT><BR>
1927
<TT><I> a : Z</I></TT><BR>
1928
<TT><I> b : Z</I></TT><BR>
1929
<TT><I> c : Z</I></TT><BR>
1930
<TT><I> d : Z</I></TT><BR>
1931
<TT><I> e : Z</I></TT><BR>
1932
<TT><I> H : a = d</I></TT><BR>
1933
<TT><I> H0 : b = e</I></TT><BR>
1934
<TT><I> H1 : c + b = d</I></TT><BR>
1935
<TT><I> ============================</I></TT><BR>
1936
<TT><I> c + e = a</I></TT><BR>
1938
<TT>Coq < congruence.</TT><BR>
1939
<TT><I>Proof completed.</I></TT><BR>
1941
<TT>Coq < Qed.</TT><BR>
1942
<TT><I>intros.</I></TT><BR>
1943
<TT><I>congruence.</I></TT><BR>
1944
<TT><I>Unnamed_thm11 is defined</I></TT><BR>
1947
<!--TOC subsubsection My goal is a disequality solvable by a sequence of rewrites, how can I prove it?-->
1949
<H4><A NAME="htoc77">67</A> My goal is a disequality solvable by a sequence of rewrites, how can I prove it?</H4><!--SEC END -->
1951
Just use the <TT>congruence</TT> tactic.<BR>
1955
<TT>Coq < Goal forall a b c d, a<>d -> b=a -> d=c+b -> b<>c+b.</TT><BR>
1956
<TT><I>1 subgoal</I></TT><BR>
1957
<TT><I> </I></TT><BR>
1958
<TT><I> ============================</I></TT><BR>
1959
<TT><I> forall a b c d : Z, a <> d -> b = a -> d = c + b -> b <> c + b</I></TT><BR>
1961
<TT>Coq < intros.</TT><BR>
1962
<TT><I>1 subgoal</I></TT><BR>
1963
<TT><I> </I></TT><BR>
1964
<TT><I> a : Z</I></TT><BR>
1965
<TT><I> b : Z</I></TT><BR>
1966
<TT><I> c : Z</I></TT><BR>
1967
<TT><I> d : Z</I></TT><BR>
1968
<TT><I> H : a <> d</I></TT><BR>
1969
<TT><I> H0 : b = a</I></TT><BR>
1970
<TT><I> H1 : d = c + b</I></TT><BR>
1971
<TT><I> ============================</I></TT><BR>
1972
<TT><I> b <> c + b</I></TT><BR>
1974
<TT>Coq < congruence.</TT><BR>
1975
<TT><I>Proof completed.</I></TT><BR>
1977
<TT>Coq < Qed.</TT><BR>
1978
<TT><I>intros.</I></TT><BR>
1979
<TT><I>congruence.</I></TT><BR>
1980
<TT><I>Unnamed_thm12 is defined</I></TT><BR>
1983
<!--TOC subsubsection My goal is an equality on some ring (e.g. natural numbers), how can I prove it?-->
1985
<H4><A NAME="htoc78">68</A> My goal is an equality on some ring (e.g. natural numbers), how can I prove it?</H4><!--SEC END -->
1987
Just use the <TT>ring</TT> tactic.<BR>
1991
<TT>Coq < Require Import ZArith.</TT><BR>
1993
<TT>Coq < Require Ring.</TT><BR>
1995
<TT>Coq < Open Local Scope Z_scope.</TT><BR>
1997
<TT>Coq < Goal forall a b : Z, (a+b)*(a+b) = a*a + 2*a*b + b*b. </TT><BR>
1998
<TT><I>1 subgoal</I></TT><BR>
1999
<TT><I> </I></TT><BR>
2000
<TT><I> ============================</I></TT><BR>
2001
<TT><I> forall a b : Z, (a + b) * (a + b) = a * a + 2 * a * b + b * b</I></TT><BR>
2003
<TT>Coq < intros.</TT><BR>
2004
<TT><I>1 subgoal</I></TT><BR>
2005
<TT><I> </I></TT><BR>
2006
<TT><I> a : Z</I></TT><BR>
2007
<TT><I> b : Z</I></TT><BR>
2008
<TT><I> ============================</I></TT><BR>
2009
<TT><I> (a + b) * (a + b) = a * a + 2 * a * b + b * b</I></TT><BR>
2011
<TT>Coq < ring.</TT><BR>
2012
<TT><I>Proof completed.</I></TT><BR>
2014
<TT>Coq < Qed.</TT><BR>
2015
<TT><I>intros.</I></TT><BR>
2016
<TT><I>ring.</I></TT><BR>
2017
<TT><I>Unnamed_thm13 is defined</I></TT><BR>
2020
<!--TOC subsubsection My goal is an equality on some field (e.g. real numbers), how can I prove it?-->
2022
<H4><A NAME="htoc79">69</A> My goal is an equality on some field (e.g. real numbers), how can I prove it?</H4><!--SEC END -->
2024
Just use the <TT>field</TT> tactic.<BR>
2028
<TT>Coq < Require Import Reals.</TT><BR>
2030
<TT>Coq < Require Ring.</TT><BR>
2032
<TT>Coq < Open Local Scope R_scope.</TT><BR>
2034
<TT>Coq < Goal forall a b : R, b*a<>0 -> (a/b) * (b/a) = 1. </TT><BR>
2035
<TT><I>1 subgoal</I></TT><BR>
2036
<TT><I> </I></TT><BR>
2037
<TT><I> ============================</I></TT><BR>
2038
<TT><I> forall a b : R, b * a <> 0 -> a / b * (b / a) = 1</I></TT><BR>
2040
<TT>Coq < intros.</TT><BR>
2041
<TT><I>1 subgoal</I></TT><BR>
2042
<TT><I> </I></TT><BR>
2043
<TT><I> a : R</I></TT><BR>
2044
<TT><I> b : R</I></TT><BR>
2045
<TT><I> H : b * a <> 0</I></TT><BR>
2046
<TT><I> ============================</I></TT><BR>
2047
<TT><I> a / b * (b / a) = 1</I></TT><BR>
2049
<TT>Coq < field.</TT><BR>
2050
<TT><I>1 subgoal</I></TT><BR>
2051
<TT><I> </I></TT><BR>
2052
<TT><I> a : R</I></TT><BR>
2053
<TT><I> b : R</I></TT><BR>
2054
<TT><I> H : b * a <> 0</I></TT><BR>
2055
<TT><I> ============================</I></TT><BR>
2056
<TT><I> b * a <> 0</I></TT><BR>
2058
<TT>Coq < assumption.</TT><BR>
2059
<TT><I>Proof completed.</I></TT><BR>
2061
<TT>Coq < Qed.</TT><BR>
2062
<TT><I>intros.</I></TT><BR>
2063
<TT><I>field.</I></TT><BR>
2064
<TT><I>assumption.</I></TT><BR>
2065
<TT><I>Unnamed_thm14 is defined</I></TT><BR>
2068
<!--TOC subsubsection My goal is an inequality on integers in Presburger's arithmetic (an expression build from +,-,constants and variables), how can I prove it?-->
2070
<H4><A NAME="htoc80">70</A> My goal is an inequality on integers in Presburger's arithmetic (an expression build from +,-,constants and variables), how can I prove it?</H4><!--SEC END -->
2074
<TT>Coq < Require Import ZArith.</TT><BR>
2076
<TT>Coq < Require Omega.</TT><BR>
2078
<TT>Coq < Open Local Scope Z_scope.</TT><BR>
2080
<TT>Coq < Goal forall a : Z, a>0 -> a+a > a. </TT><BR>
2081
<TT><I>1 subgoal</I></TT><BR>
2082
<TT><I> </I></TT><BR>
2083
<TT><I> ============================</I></TT><BR>
2084
<TT><I> forall a : Z, a > 0 -> a + a > a</I></TT><BR>
2086
<TT>Coq < intros.</TT><BR>
2087
<TT><I>1 subgoal</I></TT><BR>
2088
<TT><I> </I></TT><BR>
2089
<TT><I> a : Z</I></TT><BR>
2090
<TT><I> H : a > 0</I></TT><BR>
2091
<TT><I> ============================</I></TT><BR>
2092
<TT><I> a + a > a</I></TT><BR>
2094
<TT>Coq < omega.</TT><BR>
2095
<TT><I>Proof completed.</I></TT><BR>
2097
<TT>Coq < Qed.</TT><BR>
2098
<TT><I>intros.</I></TT><BR>
2099
<TT><I>omega.</I></TT><BR>
2100
<TT><I>Unnamed_thm15 is defined</I></TT><BR>
2103
<!--TOC subsubsection My goal is an equation solvable using equational hypothesis on some ring (e.g. natural numbers), how can I prove it?-->
2105
<H4><A NAME="htoc81">71</A> My goal is an equation solvable using equational hypothesis on some ring (e.g. natural numbers), how can I prove it?</H4><!--SEC END -->
2107
You need the <TT>gb</TT> tactic (see Lo�c Pottier's homepage).<BR>
2109
<!--TOC subsection Tactics usage-->
2111
<H3><A NAME="htoc82">6.2</A> Tactics usage</H3><!--SEC END -->
2113
<!--TOC subsubsection I want to state a fact that I will use later as an hypothesis, how can I do it?-->
2115
<H4><A NAME="htoc83">72</A> I want to state a fact that I will use later as an hypothesis, how can I do it?</H4><!--SEC END -->
2117
If you want to use forward reasoning (first proving the fact and then
2118
using it) you just need to use the <TT>assert</TT> tactic. If you want to use
2119
backward reasoning (proving your goal using an assumption and then
2120
proving the assumption) use the <TT>cut</TT> tactic.<BR>
2124
<TT>Coq < Goal forall A B C D : Prop, (A -> B) -> (B->C) -> A -> C. </TT><BR>
2125
<TT><I>1 subgoal</I></TT><BR>
2126
<TT><I> </I></TT><BR>
2127
<TT><I> ============================</I></TT><BR>
2128
<TT><I> forall A B C : Prop, Prop -> (A -> B) -> (B -> C) -> A -> C</I></TT><BR>
2130
<TT>Coq < intros.</TT><BR>
2131
<TT><I>1 subgoal</I></TT><BR>
2132
<TT><I> </I></TT><BR>
2133
<TT><I> A : Prop</I></TT><BR>
2134
<TT><I> B : Prop</I></TT><BR>
2135
<TT><I> C : Prop</I></TT><BR>
2136
<TT><I> D : Prop</I></TT><BR>
2137
<TT><I> H : A -> B</I></TT><BR>
2138
<TT><I> H0 : B -> C</I></TT><BR>
2139
<TT><I> H1 : A</I></TT><BR>
2140
<TT><I> ============================</I></TT><BR>
2141
<TT><I> C</I></TT><BR>
2143
<TT>Coq < assert (A->C).</TT><BR>
2144
<TT><I>2 subgoals</I></TT><BR>
2145
<TT><I> </I></TT><BR>
2146
<TT><I> A : Prop</I></TT><BR>
2147
<TT><I> B : Prop</I></TT><BR>
2148
<TT><I> C : Prop</I></TT><BR>
2149
<TT><I> D : Prop</I></TT><BR>
2150
<TT><I> H : A -> B</I></TT><BR>
2151
<TT><I> H0 : B -> C</I></TT><BR>
2152
<TT><I> H1 : A</I></TT><BR>
2153
<TT><I> ============================</I></TT><BR>
2154
<TT><I> A -> C</I></TT><BR>
2155
<TT><I>subgoal 2 is:</I></TT><BR>
2156
<TT><I> C</I></TT><BR>
2158
<TT>Coq < intro;apply H0;apply H;assumption.</TT><BR>
2159
<TT><I>1 subgoal</I></TT><BR>
2160
<TT><I> </I></TT><BR>
2161
<TT><I> A : Prop</I></TT><BR>
2162
<TT><I> B : Prop</I></TT><BR>
2163
<TT><I> C : Prop</I></TT><BR>
2164
<TT><I> D : Prop</I></TT><BR>
2165
<TT><I> H : A -> B</I></TT><BR>
2166
<TT><I> H0 : B -> C</I></TT><BR>
2167
<TT><I> H1 : A</I></TT><BR>
2168
<TT><I> H2 : A -> C</I></TT><BR>
2169
<TT><I> ============================</I></TT><BR>
2170
<TT><I> C</I></TT><BR>
2172
<TT>Coq < apply H2.</TT><BR>
2173
<TT><I>1 subgoal</I></TT><BR>
2174
<TT><I> </I></TT><BR>
2175
<TT><I> A : Prop</I></TT><BR>
2176
<TT><I> B : Prop</I></TT><BR>
2177
<TT><I> C : Prop</I></TT><BR>
2178
<TT><I> D : Prop</I></TT><BR>
2179
<TT><I> H : A -> B</I></TT><BR>
2180
<TT><I> H0 : B -> C</I></TT><BR>
2181
<TT><I> H1 : A</I></TT><BR>
2182
<TT><I> H2 : A -> C</I></TT><BR>
2183
<TT><I> ============================</I></TT><BR>
2184
<TT><I> A</I></TT><BR>
2186
<TT>Coq < assumption.</TT><BR>
2187
<TT><I>Proof completed.</I></TT><BR>
2189
<TT>Coq < Qed.</TT><BR>
2190
<TT><I>intros.</I></TT><BR>
2191
<TT><I>assert (A -> C).</I></TT><BR>
2192
<TT><I> intro; apply H0; apply H; assumption.</I></TT><BR>
2193
<TT><I> apply H2.</I></TT><BR>
2194
<TT><I> assumption.</I></TT><BR>
2195
<TT><I>Unnamed_thm16 is defined</I></TT><BR>
2197
<TT>Coq < </TT><BR>
2198
<TT>Coq < Goal forall A B C D : Prop, (A -> B) -> (B->C) -> A -> C. </TT><BR>
2199
<TT><I>1 subgoal</I></TT><BR>
2200
<TT><I> </I></TT><BR>
2201
<TT><I> ============================</I></TT><BR>
2202
<TT><I> forall A B C : Prop, Prop -> (A -> B) -> (B -> C) -> A -> C</I></TT><BR>
2204
<TT>Coq < intros.</TT><BR>
2205
<TT><I>1 subgoal</I></TT><BR>
2206
<TT><I> </I></TT><BR>
2207
<TT><I> A : Prop</I></TT><BR>
2208
<TT><I> B : Prop</I></TT><BR>
2209
<TT><I> C : Prop</I></TT><BR>
2210
<TT><I> D : Prop</I></TT><BR>
2211
<TT><I> H : A -> B</I></TT><BR>
2212
<TT><I> H0 : B -> C</I></TT><BR>
2213
<TT><I> H1 : A</I></TT><BR>
2214
<TT><I> ============================</I></TT><BR>
2215
<TT><I> C</I></TT><BR>
2217
<TT>Coq < cut (A->C).</TT><BR>
2218
<TT><I>2 subgoals</I></TT><BR>
2219
<TT><I> </I></TT><BR>
2220
<TT><I> A : Prop</I></TT><BR>
2221
<TT><I> B : Prop</I></TT><BR>
2222
<TT><I> C : Prop</I></TT><BR>
2223
<TT><I> D : Prop</I></TT><BR>
2224
<TT><I> H : A -> B</I></TT><BR>
2225
<TT><I> H0 : B -> C</I></TT><BR>
2226
<TT><I> H1 : A</I></TT><BR>
2227
<TT><I> ============================</I></TT><BR>
2228
<TT><I> (A -> C) -> C</I></TT><BR>
2229
<TT><I>subgoal 2 is:</I></TT><BR>
2230
<TT><I> A -> C</I></TT><BR>
2232
<TT>Coq < intro.</TT><BR>
2233
<TT><I>2 subgoals</I></TT><BR>
2234
<TT><I> </I></TT><BR>
2235
<TT><I> A : Prop</I></TT><BR>
2236
<TT><I> B : Prop</I></TT><BR>
2237
<TT><I> C : Prop</I></TT><BR>
2238
<TT><I> D : Prop</I></TT><BR>
2239
<TT><I> H : A -> B</I></TT><BR>
2240
<TT><I> H0 : B -> C</I></TT><BR>
2241
<TT><I> H1 : A</I></TT><BR>
2242
<TT><I> H2 : A -> C</I></TT><BR>
2243
<TT><I> ============================</I></TT><BR>
2244
<TT><I> C</I></TT><BR>
2245
<TT><I>subgoal 2 is:</I></TT><BR>
2246
<TT><I> A -> C</I></TT><BR>
2248
<TT>Coq < apply H2;assumption.</TT><BR>
2249
<TT><I>1 subgoal</I></TT><BR>
2250
<TT><I> </I></TT><BR>
2251
<TT><I> A : Prop</I></TT><BR>
2252
<TT><I> B : Prop</I></TT><BR>
2253
<TT><I> C : Prop</I></TT><BR>
2254
<TT><I> D : Prop</I></TT><BR>
2255
<TT><I> H : A -> B</I></TT><BR>
2256
<TT><I> H0 : B -> C</I></TT><BR>
2257
<TT><I> H1 : A</I></TT><BR>
2258
<TT><I> ============================</I></TT><BR>
2259
<TT><I> A -> C</I></TT><BR>
2261
<TT>Coq < intro;apply H0;apply H;assumption.</TT><BR>
2262
<TT><I>Proof completed.</I></TT><BR>
2264
<TT>Coq < Qed.</TT><BR>
2265
<TT><I>intros.</I></TT><BR>
2266
<TT><I>cut (A -> C).</I></TT><BR>
2267
<TT><I> intro.</I></TT><BR>
2268
<TT><I> apply H2; assumption.</I></TT><BR>
2269
<TT><I> intro; apply H0; apply H; assumption.</I></TT><BR>
2270
<TT><I>Unnamed_thm17 is defined</I></TT><BR>
2273
<!--TOC subsubsection I want to state a fact that I will use later as an hypothesis and prove it later, how can I do it?-->
2275
<H4><A NAME="htoc84">73</A> I want to state a fact that I will use later as an hypothesis and prove it later, how can I do it?</H4><!--SEC END -->
2277
You can use <TT>cut</TT> followed by <TT>intro</TT> or you can use the following <FONT COLOR=navy>Ltac</FONT> command:
2279
Ltac assert_later t := cut t;[intro|idtac].
2281
<!--TOC subsubsection What is the difference between <TT>Qed</TT> and <TT>Defined</TT>?-->
2283
<H4><A NAME="htoc85">74</A> What is the difference between <TT>Qed</TT> and <TT>Defined</TT>?</H4><!--SEC END -->
2285
These two commands perform type checking, but when <TT>Defined</TT> is used the new definition is set as transparent, otherwise it is defined as opaque (see <A HREF="#opaque">167</A>).<BR>
2287
<!--TOC subsubsection How can I know what a tactic does?-->
2289
<H4><A NAME="htoc86">75</A> How can I know what a tactic does?</H4><!--SEC END -->
2291
You can use the <TT>info</TT> command.<BR>
2293
<!--TOC subsubsection Why <TT>auto</TT> does not work? How can I fix it?-->
2295
<H4><A NAME="htoc87">76</A> Why <TT>auto</TT> does not work? How can I fix it?</H4><!--SEC END -->
2297
You can increase the depth of the proof search or add some lemmas in the base of hints.
2298
Perhaps you may need to use <TT>eauto</TT>.<BR>
2300
<!--TOC subsubsection What is <TT>eauto</TT>?-->
2302
<H4><A NAME="htoc88">77</A> What is <TT>eauto</TT>?</H4><!--SEC END -->
2304
This is the same tactic as <TT>auto</TT>, but it relies on <TT>eapply</TT> instead of <TT>apply</TT>.<BR>
2306
<!--TOC subsubsection How can I speed up <TT>auto</TT>?-->
2308
<H4><A NAME="htoc89">78</A> How can I speed up <TT>auto</TT>?</H4><!--SEC END -->
2310
You can use <TT>info </TT><TT>auto</TT>to replace <TT>auto</TT> by the tactics it generates.
2311
You can split your hint bases into smaller ones.<BR>
2313
<!--TOC subsubsection What is the equivalent of <TT>tauto</TT> for classical logic?-->
2315
<H4><A NAME="htoc90">79</A> What is the equivalent of <TT>tauto</TT> for classical logic?</H4><!--SEC END -->
2317
Currently there are no equivalent tactic for classical logic. You can use G�del's ``not not'' translation.<BR>
2319
<!--TOC subsubsection I want to replace some term with another in the goal, how can I do it?-->
2321
<H4><A NAME="htoc91">80</A> I want to replace some term with another in the goal, how can I do it?</H4><!--SEC END -->
2323
If one of your hypothesis (say <TT>H</TT>) states that the terms are equal you can use the <TT>rewrite</TT> tactic. Otherwise you can use the <TT>replace</TT> <TT>with</TT> tactic. <BR>
2325
<!--TOC subsubsection I want to replace some term with another in an hypothesis, how can I do it?-->
2327
<H4><A NAME="htoc92">81</A> I want to replace some term with another in an hypothesis, how can I do it?</H4><!--SEC END -->
2329
You can use the <TT>rewrite</TT> <TT>in</TT> tactic.<BR>
2331
<!--TOC subsubsection I want to replace some symbol with its definition, how can I do it?-->
2333
<H4><A NAME="htoc93">82</A> I want to replace some symbol with its definition, how can I do it?</H4><!--SEC END -->
2335
You can use the <TT>unfold</TT> tactic.<BR>
2337
<!--TOC subsubsection How can I reduce some term?-->
2339
<H4><A NAME="htoc94">83</A> How can I reduce some term?</H4><!--SEC END -->
2341
You can use the <TT>simpl</TT> tactic.<BR>
2343
<!--TOC subsubsection How can I declare a shortcut for some term?-->
2345
<H4><A NAME="htoc95">84</A> How can I declare a shortcut for some term?</H4><!--SEC END -->
2347
You can use the <TT>set</TT> or <TT>pose</TT> tactics.<BR>
2349
<!--TOC subsubsection How can I perform case analysis?-->
2351
<H4><A NAME="htoc96">85</A> How can I perform case analysis?</H4><!--SEC END -->
2353
You can use the <TT>case</TT> or <TT>destruct</TT> tactics.<BR>
2355
<!--TOC subsubsection Why should I name my intros?-->
2357
<H4><A NAME="htoc97">86</A> Why should I name my intros?</H4><!--SEC END -->
2359
When you use the <TT>intro</TT> tactic you don't have to give a name to your
2360
hypothesis. If you do so the name will be generated by <FONT COLOR=navy>Coq</FONT> but your
2361
scripts may be less robust. If you add some hypothesis to your theorem
2362
(or change their order), you will have to change your proof to adapt
2363
to the new names.<BR>
2365
<!--TOC subsubsection How can I automatize the naming?-->
2367
<H4><A NAME="htoc98">87</A> How can I automatize the naming?</H4><!--SEC END -->
2369
You can use the <TT>Show Intro.</TT> or <TT>Show Intros.</TT> commands to generate the names and use your editor to generate a fully named <TT>intro</TT> tactic.
2370
This can be automatized within <TT>xemacs</TT>.<BR>
2374
<TT>Coq < Goal forall A B C : Prop, A -> B -> C -> A/\B/\C.</TT><BR>
2375
<TT><I>1 subgoal</I></TT><BR>
2376
<TT><I> </I></TT><BR>
2377
<TT><I> ============================</I></TT><BR>
2378
<TT><I> forall A B C : Prop, A -> B -> C -> A /\ B /\ C</I></TT><BR>
2380
<TT>Coq < Show Intros.</TT><BR>
2381
<TT><I>A B C H H0</I></TT><BR>
2382
<TT><I>H1</I></TT><BR>
2384
<TT>Coq < (*</TT><BR>
2385
<TT>Coq < A B C H H0</TT><BR>
2386
<TT>Coq < H1</TT><BR>
2387
<TT>Coq < *)</TT><BR>
2388
<TT>Coq < intros A B C H H0 H1.</TT><BR>
2389
<TT><I>1 subgoal</I></TT><BR>
2390
<TT><I> </I></TT><BR>
2391
<TT><I> A : Prop</I></TT><BR>
2392
<TT><I> B : Prop</I></TT><BR>
2393
<TT><I> C : Prop</I></TT><BR>
2394
<TT><I> H : A</I></TT><BR>
2395
<TT><I> H0 : B</I></TT><BR>
2396
<TT><I> H1 : C</I></TT><BR>
2397
<TT><I> ============================</I></TT><BR>
2398
<TT><I> A /\ B /\ C</I></TT><BR>
2400
<TT>Coq < repeat split;assumption.</TT><BR>
2401
<TT><I>Proof completed.</I></TT><BR>
2403
<TT>Coq < Qed.</TT><BR>
2404
<TT><I>intros A B C H H0 H1.</I></TT><BR>
2405
<TT><I>repeat split; assumption.</I></TT><BR>
2406
<TT><I>Unnamed_thm18 is defined</I></TT><BR>
2409
<!--TOC subsubsection I want to automatize the use of some tactic, how can I do it?-->
2411
<H4><A NAME="htoc99">88</A> I want to automatize the use of some tactic, how can I do it?</H4><!--SEC END -->
2413
You need to use the <TT>proof with T</TT> command and add ... at the
2414
end of your sentences.<BR>
2419
<TT>Coq < Goal forall A B C : Prop, A -> B/\C -> A/\B/\C.</TT><BR>
2420
<TT><I>1 subgoal</I></TT><BR>
2421
<TT><I> </I></TT><BR>
2422
<TT><I> ============================</I></TT><BR>
2423
<TT><I> forall A B C : Prop, A -> B /\ C -> A /\ B /\ C</I></TT><BR>
2425
<TT>Coq < Proof with assumption.</TT><BR>
2427
<TT>Coq < intros.</TT><BR>
2428
<TT><I>1 subgoal</I></TT><BR>
2429
<TT><I> </I></TT><BR>
2430
<TT><I> A : Prop</I></TT><BR>
2431
<TT><I> B : Prop</I></TT><BR>
2432
<TT><I> C : Prop</I></TT><BR>
2433
<TT><I> H : A</I></TT><BR>
2434
<TT><I> H0 : B /\ C</I></TT><BR>
2435
<TT><I> ============================</I></TT><BR>
2436
<TT><I> A /\ B /\ C</I></TT><BR>
2438
<TT>Coq < split...</TT><BR>
2439
<TT><I>Proof completed.</I></TT><BR>
2441
<TT>Coq < Qed.</TT><BR>
2442
<TT><I>intros.</I></TT><BR>
2443
<TT><I>split.</I></TT><BR>
2444
<TT><I>Unnamed_thm19 is defined</I></TT><BR>
2447
<!--TOC subsubsection I want to execute the <TT>p</TT>roof with tactic only if it solves the goal, how can I do it?-->
2449
<H4><A NAME="htoc100">89</A> I want to execute the <TT>p</TT>roof with tactic only if it solves the goal, how can I do it?</H4><!--SEC END -->
2451
You need to use the <TT>try</TT> and <TT>solve</TT> tactics. For instance:
2454
<TT>Coq < Require Import ZArith.</TT><BR>
2456
<TT>Coq < Require Ring.</TT><BR>
2458
<TT>Coq < Open Local Scope Z_scope.</TT><BR>
2460
<TT>Coq < Goal forall a b c : Z, a+b=b+a.</TT><BR>
2461
<TT><I>1 subgoal</I></TT><BR>
2462
<TT><I> </I></TT><BR>
2463
<TT><I> ============================</I></TT><BR>
2464
<TT><I> forall a b : Z, Z -> a + b = b + a</I></TT><BR>
2466
<TT>Coq < Proof with try solve [ring].</TT><BR>
2468
<TT>Coq < intros...</TT><BR>
2469
<TT><I>Proof completed.</I></TT><BR>
2471
<TT>Coq < Qed.</TT><BR>
2472
<TT><I>intros.</I></TT><BR>
2473
<TT><I>Unnamed_thm20 is defined</I></TT><BR>
2476
<!--TOC subsubsection How can I do the opposite of the <TT>intro</TT> tactic?-->
2478
<H4><A NAME="htoc101">90</A> How can I do the opposite of the <TT>intro</TT> tactic?</H4><!--SEC END -->
2480
You can use the <TT>generalize</TT> tactic.<BR>
2484
<TT>Coq < Goal forall A B : Prop, A->B-> A/\B.</TT><BR>
2485
<TT><I>1 subgoal</I></TT><BR>
2486
<TT><I> </I></TT><BR>
2487
<TT><I> ============================</I></TT><BR>
2488
<TT><I> forall A B : Prop, A -> B -> A /\ B</I></TT><BR>
2490
<TT>Coq < intros.</TT><BR>
2491
<TT><I>1 subgoal</I></TT><BR>
2492
<TT><I> </I></TT><BR>
2493
<TT><I> A : Prop</I></TT><BR>
2494
<TT><I> B : Prop</I></TT><BR>
2495
<TT><I> H : A</I></TT><BR>
2496
<TT><I> H0 : B</I></TT><BR>
2497
<TT><I> ============================</I></TT><BR>
2498
<TT><I> A /\ B</I></TT><BR>
2500
<TT>Coq < generalize H.</TT><BR>
2501
<TT><I>1 subgoal</I></TT><BR>
2502
<TT><I> </I></TT><BR>
2503
<TT><I> A : Prop</I></TT><BR>
2504
<TT><I> B : Prop</I></TT><BR>
2505
<TT><I> H : A</I></TT><BR>
2506
<TT><I> H0 : B</I></TT><BR>
2507
<TT><I> ============================</I></TT><BR>
2508
<TT><I> A -> A /\ B</I></TT><BR>
2510
<TT>Coq < intro.</TT><BR>
2511
<TT><I>1 subgoal</I></TT><BR>
2512
<TT><I> </I></TT><BR>
2513
<TT><I> A : Prop</I></TT><BR>
2514
<TT><I> B : Prop</I></TT><BR>
2515
<TT><I> H : A</I></TT><BR>
2516
<TT><I> H0 : B</I></TT><BR>
2517
<TT><I> H1 : A</I></TT><BR>
2518
<TT><I> ============================</I></TT><BR>
2519
<TT><I> A /\ B</I></TT><BR>
2521
<TT>Coq < auto.</TT><BR>
2522
<TT><I>Proof completed.</I></TT><BR>
2524
<TT>Coq < Qed.</TT><BR>
2525
<TT><I>intros.</I></TT><BR>
2526
<TT><I>generalize H.</I></TT><BR>
2527
<TT><I>intro.</I></TT><BR>
2528
<TT><I>auto.</I></TT><BR>
2529
<TT><I>Unnamed_thm21 is defined</I></TT><BR>
2532
<!--TOC subsubsection One of the hypothesis is an equality between a variable and some term, I want to get rid of this variable, how can I do it?-->
2534
<H4><A NAME="htoc102">91</A> One of the hypothesis is an equality between a variable and some term, I want to get rid of this variable, how can I do it?</H4><!--SEC END -->
2536
You can use the <TT>subst</TT> tactic. This will rewrite the equality everywhere and clear the assumption.<BR>
2538
<!--TOC subsubsection What can I do if I get ``<TT>generated subgoal term has metavariables in it </TT>''?-->
2540
<H4><A NAME="htoc103">92</A> What can I do if I get ``<TT>generated subgoal term has metavariables in it </TT>''?</H4><!--SEC END -->
2542
You should use the <TT>eapply</TT> tactic, this will generate some goals containing metavariables. <BR>
2544
<!--TOC subsubsection How can I instantiate some metavariable?-->
2546
<H4><A NAME="htoc104">93</A> How can I instantiate some metavariable?</H4><!--SEC END -->
2548
Just use the <TT>instantiate</TT> tactic.<BR>
2550
<!--TOC subsubsection What is the use of the <TT>pattern</TT> tactic?-->
2552
<H4><A NAME="htoc105">94</A> What is the use of the <TT>pattern</TT> tactic?</H4><!--SEC END -->
2554
The <TT>pattern</TT> tactic transforms the current goal, performing
2555
beta-expansion on all the applications featuring this tactic's
2556
argument. For instance, if the current goal includes a subterm <TT>phi(t)</TT>, then <TT>pattern t</TT> transforms the subterm into <TT>(fun
2557
x:A => phi(x)) t</TT>. This can be useful when <TT>apply</TT> fails on matching,
2558
to abstract the appropriate terms.<BR>
2560
<!--TOC subsubsection What is the difference between assert, cut and generalize?-->
2562
<H4><A NAME="htoc106">95</A> What is the difference between assert, cut and generalize?</H4><!--SEC END -->
2564
PS: Notice for people that are interested in proof rendering that <TT>assert</TT>and <TT>pose</TT> (and <TT>cut</TT>) are not rendered the same as <TT>generalize</TT> (see the
2565
HELM experimental rendering tool at <A HREF="http://helm.cs.unibo.it/library.html"><TT>http://helm.cs.unibo.it</TT></A>, link
2566
HELM, link COQ Online). Indeed <TT>generalize</TT> builds a beta-expanded term
2567
while <TT>assert</TT>, <TT>pose</TT> and <TT>cut</TT> uses a let-in.
2571
(* Goal is A->T *)
2572
... a proof of A->T ...
2574
is rendered into something like
2576
(h) ... the proof of A->T ...
2578
(h0) by (H1 H2) we proved A
2579
by (h h0) we proved T
2583
assert q := (H1 H2).
2585
... a proof of A ...
2586
(* Goal is A |- T *)
2587
... a proof of T ...
2588
</PRE>is rendered into something like
2590
(q) ... the proof of A ...
2592
... the proof of T ...
2594
</PRE>Otherwise said, <TT>generalize</TT> is not rendered in a forward-reasoning way,
2595
while <TT>assert</TT> is.<BR>
2597
<!--TOC subsubsection What can I do if <FONT COLOR=navy>Coq</FONT>can not infer some implicit argument ?-->
2599
<H4><A NAME="htoc107">96</A> What can I do if <FONT COLOR=navy>Coq</FONT>can not infer some implicit argument ?</H4><!--SEC END -->
2601
You can state explicitely what this implicit argument is. See <A HREF="#implicit">97</A>.<BR>
2603
<!--TOC subsubsection How can I explicit some implicit argument ?-->
2605
<H4><A NAME="htoc108">97</A> How can I explicit some implicit argument ?</H4><!--SEC END -->
2606
<A NAME="implicit"></A>
2607
Just use <TT>A:=term</TT> where <TT>A</TT> is the argument.<BR>
2609
For instance if you want to use the existence of ``nil'' on nat*nat lists:
2611
exists (nil (A:=(nat*nat))).
2613
<!--TOC subsection Proof management-->
2615
<H3><A NAME="htoc109">6.3</A> Proof management</H3><!--SEC END -->
2617
<!--TOC subsubsection How can I change the order of the subgoals?-->
2619
<H4><A NAME="htoc110">98</A> How can I change the order of the subgoals?</H4><!--SEC END -->
2621
You can use the <TT>Focus</TT> command to concentrate on some goal. When the goal is proved you will see the remaining goals.<BR>
2623
<!--TOC subsubsection How can I change the order of the hypothesis?-->
2625
<H4><A NAME="htoc111">99</A> How can I change the order of the hypothesis?</H4><!--SEC END -->
2627
You can use the <TT>Move ... after</TT> command.<BR>
2629
<!--TOC subsubsection How can I change the name of an hypothesis?-->
2631
<H4><A NAME="htoc112">100</A> How can I change the name of an hypothesis?</H4><!--SEC END -->
2633
You can use the <TT>Rename ... into</TT> command.<BR>
2635
<!--TOC subsubsection How can I delete some hypothesis?-->
2637
<H4><A NAME="htoc113">101</A> How can I delete some hypothesis?</H4><!--SEC END -->
2639
You can use the <TT>Clear</TT> command.<BR>
2641
<!--TOC subsubsection How can use a proof which is not finished?-->
2643
<H4><A NAME="htoc114">102</A> How can use a proof which is not finished?</H4><!--SEC END -->
2645
You can use the <TT>Admitted</TT> command to state your current proof as an axiom.<BR>
2647
<!--TOC subsubsection How can I state a conjecture?-->
2649
<H4><A NAME="htoc115">103</A> How can I state a conjecture?</H4><!--SEC END -->
2651
You can use the <TT>Admitted</TT> command to state your current proof as an axiom.<BR>
2653
<!--TOC subsubsection What is the difference between a lemma, a fact and a theorem?-->
2655
<H4><A NAME="htoc116">104</A> What is the difference between a lemma, a fact and a theorem?</H4><!--SEC END -->
2657
From <FONT COLOR=navy>Coq</FONT> point of view there are no difference. But some tools can
2658
have a different behavior when you use a lemma rather than a
2659
theorem. For instance <TT>coqdoc</TT> will not generate documentation for
2660
the lemmas within your development.<BR>
2662
<!--TOC subsubsection How can I organize my proofs?-->
2664
<H4><A NAME="htoc117">105</A> How can I organize my proofs?</H4><!--SEC END -->
2666
You can organize your proofs using the section mechanism of <FONT COLOR=navy>Coq</FONT>. Have
2667
a look at the manual for further information.<BR>
2669
<!--TOC section Inductive and Co-inductive types-->
2671
<H2><A NAME="htoc118">7</A> Inductive and Co-inductive types</H2><!--SEC END -->
2673
<!--TOC subsection General-->
2675
<H3><A NAME="htoc119">7.1</A> General</H3><!--SEC END -->
2677
<!--TOC subsubsection How can I prove that two constructors are different?-->
2679
<H4><A NAME="htoc120">106</A> How can I prove that two constructors are different?</H4><!--SEC END -->
2681
You can use the <TT>discriminate</TT> tactic.<BR>
2685
<TT>Coq < Inductive toto : Set := | C1 : toto | C2 : toto.</TT><BR>
2686
<TT><I>toto is defined</I></TT><BR>
2687
<TT><I>toto_rect is defined</I></TT><BR>
2688
<TT><I>toto_ind is defined</I></TT><BR>
2689
<TT><I>toto_rec is defined</I></TT><BR>
2691
<TT>Coq < Goal C1 <> C2.</TT><BR>
2692
<TT><I>1 subgoal</I></TT><BR>
2693
<TT><I> </I></TT><BR>
2694
<TT><I> ============================</I></TT><BR>
2695
<TT><I> C1 <> C2</I></TT><BR>
2697
<TT>Coq < discriminate.</TT><BR>
2698
<TT><I>Proof completed.</I></TT><BR>
2700
<TT>Coq < Qed.</TT><BR>
2701
<TT><I>discriminate.</I></TT><BR>
2702
<TT><I>Unnamed_thm22 is defined</I></TT><BR>
2705
<!--TOC subsubsection During an inductive proof, how to get rid of impossible cases of an inductive definition?-->
2707
<H4><A NAME="htoc121">107</A> During an inductive proof, how to get rid of impossible cases of an inductive definition?</H4><!--SEC END -->
2709
Use the <TT>inversion</TT> tactic.<BR>
2711
<!--TOC subsubsection How can I prove that 2 terms in an inductive set are equal? Or different?-->
2713
<H4><A NAME="htoc122">108</A> How can I prove that 2 terms in an inductive set are equal? Or different?</H4><!--SEC END -->
2715
Have a look at "decide equality" and "discriminate" in the <A HREF="http://coq.inria.fr/doc/main.html">Reference Manual</A>.<BR>
2717
<!--TOC subsubsection Why is the proof of <TT>0+n=n</TT> on natural numbers
2718
trivial but the proof of <TT>n+0=n</TT> is not?-->
2720
<H4><A NAME="htoc123">109</A> Why is the proof of <TT>0+n=n</TT> on natural numbers
2721
trivial but the proof of <TT>n+0=n</TT> is not?</H4><!--SEC END -->
2723
Since <TT>+</TT> (<TT>plus</TT>) on natural numbers is defined by analysis on its first argument<BR>
2727
<TT>Coq < Print plus.</TT><BR>
2728
<TT><I>plus = </I></TT><BR>
2729
<TT><I>(fix plus (n m : nat) {struct n} : nat :=</I></TT><BR>
2730
<TT><I> match n with</I></TT><BR>
2731
<TT><I> | O => m</I></TT><BR>
2732
<TT><I> | S p => S (plus p m)</I></TT><BR>
2733
<TT><I> end)</I></TT><BR>
2734
<TT><I> : nat -> nat -> nat</I></TT><BR>
2735
<TT><I>Argument scopes are [nat_scope nat_scope]</I></TT><BR>
2738
The expression <TT>0+n</TT> evaluates to <TT>n</TT>. As <FONT COLOR=navy>Coq</FONT> reasons
2739
modulo evaluation of expressions, <TT>0+n</TT> and <TT>n</TT> are
2740
considered equal and the theorem <TT>0+n=n</TT> is an instance of the
2741
reflexivity of equality. On the other side, <TT>n+0</TT> does not
2742
evaluate to <TT>n</TT> and a proof by induction on <TT>n</TT> is
2743
necessary to trigger the evaluation of <TT>+</TT>.<BR>
2745
<!--TOC subsubsection Why is dependent elimination in Prop not
2746
available by default?-->
2748
<H4><A NAME="htoc124">110</A> Why is dependent elimination in Prop not
2749
available by default?</H4><!--SEC END -->
2751
This is just because most of the time it is not needed. To derive a
2752
dependent elimination principle in <TT>Prop</TT>, use the command <TT>Scheme</TT> and
2753
apply the elimination scheme using the <CODE>using</CODE> option of
2754
<CODE>elim</CODE>, <CODE>destruct</CODE> or <CODE>induction</CODE>.<BR>
2756
<!--TOC subsection Recursion-->
2758
<H3><A NAME="htoc125">7.2</A> Recursion</H3><!--SEC END -->
2760
<!--TOC subsubsection Why can't I define a non terminating program?-->
2762
<H4><A NAME="htoc126">111</A> Why can't I define a non terminating program?</H4><!--SEC END -->
2764
Because otherwise the decidability of the type-checking
2765
algorithm (which involves evaluation of programs) is not ensured. On
2766
another side, if non terminating proofs were allowed, we could get a
2767
proof of <TT>False</TT>:<BR>
2771
<TT>Coq < (* This is fortunately not allowed! *)</TT><BR>
2772
<TT>Coq < Fixpoint InfiniteProof (n:nat) : False := InfiniteProof n.</TT><BR>
2774
<TT>Coq < Theorem Paradox : False.</TT><BR>
2776
<TT>Coq < Proof (InfiniteProof O).</TT><BR>
2779
<!--TOC subsubsection Why only structurally well-founded loops are allowed?-->
2781
<H4><A NAME="htoc127">112</A> Why only structurally well-founded loops are allowed?</H4><!--SEC END -->
2783
The structural order on inductive types is a simple and
2784
powerful notion of termination. The consistency of the Calculus of
2785
Inductive Constructions relies on it and another consistency proof
2786
would have to be made for stronger termination arguments (such
2787
as the termination of the evaluation of CIC programs themselves!).<BR>
2789
In spite of this, all non-pathological termination orders can be mapped
2790
to a structural order. Tools to do this are provided in the file
2791
<A HREF="http://coq.inria.fr/library/Coq.Init.Wf.html
2792
"><TT>Wf.v</TT></A> of the standard library of <FONT COLOR=navy>Coq</FONT>.<BR>
2794
<!--TOC subsubsection How to define loops based on non structurally smaller
2797
<H4><A NAME="htoc128">113</A> How to define loops based on non structurally smaller
2798
recursive calls?</H4><!--SEC END -->
2800
The procedure is as follows (we consider the definition of <TT>mergesort</TT> as an example).
2801
<UL><LI>Define the termination order, say <TT>R</TT> on the type <TT>A</TT> of
2802
the arguments of the loop.<BR>
2806
<TT>Coq < Definition R (a b:list nat) := length a < length b.</TT><BR>
2810
<LI>Prove that this order is well-founded (in fact that all elements in <TT>A</TT> are accessible along <TT>R</TT>).<BR>
2814
<TT>Coq < Lemma Rwf : well_founded (A:=R).</TT><BR>
2818
<LI>Define the step function (which needs proofs that recursive
2819
calls are on smaller arguments).<BR>
2823
<TT>Coq < Definition split (l : list nat) </TT><BR>
2824
<TT>Coq < : {l1: list nat | R l1 l} * {l2 : list nat | R l2 l}</TT><BR>
2825
<TT>Coq < := (* ... *) .</TT><BR>
2827
<TT>Coq < Definition concat (l1 l2 : list nat) : list nat := (* ... *) .</TT><BR>
2829
<TT>Coq < Definition merge_step (l : list nat) (f: forall l':list nat, R l' l -> list nat) :=</TT><BR>
2830
<TT>Coq < let (lH1,lH2) := (split l) in</TT><BR>
2831
<TT>Coq < let (l1,H1) := lH1 in</TT><BR>
2832
<TT>Coq < let (l2,H2) := lH2 in</TT><BR>
2833
<TT>Coq < concat (f l1 H1) (f l2 H2).</TT><BR>
2837
<LI>Define the recursive function by fixpoint on the step function.<BR>
2841
<TT>Coq < Definition merge := Fix Rwf (fun _ => list nat) merge_step.</TT><BR>
2844
<!--TOC subsubsection What is behind the accessibility and well-foundedness proofs?-->
2846
<H4><A NAME="htoc129">114</A> What is behind the accessibility and well-foundedness proofs?</H4><!--SEC END -->
2848
Well-foundedness of some relation <TT>R</TT> on some type <TT>A</TT>
2849
is defined as the accessibility of all elements of <TT>A</TT> along <TT>R</TT>.<BR>
2853
<TT>Coq < Print well_founded.</TT><BR>
2854
<TT><I>well_founded = </I></TT><BR>
2855
<TT><I>fun (A : Set) (R : A -> A -> Prop) => forall a : A, Acc R a</I></TT><BR>
2856
<TT><I> : forall A : Set, (A -> A -> Prop) -> Prop</I></TT><BR>
2857
<TT><I>Argument A is implicit</I></TT><BR>
2858
<TT><I>Argument scopes are [type_scope _]</I></TT><BR>
2860
<TT>Coq < Print Acc.</TT><BR>
2861
<TT><I>Inductive Acc (A : Set) (R : A -> A -> Prop) : A -> Prop :=</I></TT><BR>
2862
<TT><I> Acc_intro : forall x : A, (forall y : A, R y x -> Acc R y) -> Acc R x</I></TT><BR>
2863
<TT><I>For Acc: Argument A is implicit</I></TT><BR>
2864
<TT><I>For Acc_intro: Arguments A, R are implicit</I></TT><BR>
2865
<TT><I>For Acc: Argument scopes are [type_scope _ _]</I></TT><BR>
2866
<TT><I>For Acc_intro: Argument scopes are [type_scope _ _ _]</I></TT><BR>
2869
The structure of the accessibility predicate is a well-founded tree
2870
branching at each node <TT>x</TT> in <TT>A</TT> along all the nodes <TT>x'</TT>
2871
less than <TT>x</TT> along <TT>R</TT>. Any sequence of elements of <TT>A</TT>
2872
decreasing along the order <TT>R</TT> are branches in the accessibility
2873
tree. Hence any decreasing along <TT>R</TT> is mapped into a structural
2874
decreasing in the accessibility tree of <TT>R</TT>. This is emphasised in
2875
the definition of <TT>fix</TT> which recurs not on its argument <TT>x:A</TT>
2876
but on the accessibility of this argument along <TT>R</TT>.<BR>
2878
See file <A HREF="http://coq.inria.fr/library/Coq.Init.Wf.html
2879
"><TT>Wf.v</TT></A>.<BR>
2881
<!--TOC subsubsection How to perform double induction?-->
2883
<H4><A NAME="htoc130">115</A> How to perform double induction?</H4><!--SEC END -->
2885
In general a double induction is simply solved by an induction on the
2886
first hypothesis followed by an inversion over the second
2887
hypothesis. Here is an example<BR>
2891
<TT>Coq < Inductive even : nat -> Prop :=</TT><BR>
2892
<TT>Coq < | even_O : even 0</TT><BR>
2893
<TT>Coq < | even_S : forall n:nat, even n -> even (S (S n)).</TT><BR>
2894
<TT><I>even is defined</I></TT><BR>
2895
<TT><I>even_ind is defined</I></TT><BR>
2897
<TT>Coq < </TT><BR>
2898
<TT>Coq < Inductive odd : nat -> Prop :=</TT><BR>
2899
<TT>Coq < | odd_SO : odd 1</TT><BR>
2900
<TT>Coq < | odd_S : forall n:nat, odd n -> odd (S (S n)).</TT><BR>
2901
<TT><I>odd is defined</I></TT><BR>
2902
<TT><I>odd_ind is defined</I></TT><BR>
2904
<TT>Coq < </TT><BR>
2905
<TT>Coq < Goal forall n:nat, even n -> odd n -> False.</TT><BR>
2906
<TT><I>1 subgoal</I></TT><BR>
2907
<TT><I> </I></TT><BR>
2908
<TT><I> ============================</I></TT><BR>
2909
<TT><I> forall n : nat, even n -> odd n -> False</I></TT><BR>
2911
<TT>Coq < induction 1.</TT><BR>
2912
<TT><I>2 subgoals</I></TT><BR>
2913
<TT><I> </I></TT><BR>
2914
<TT><I> ============================</I></TT><BR>
2915
<TT><I> odd 0 -> False</I></TT><BR>
2916
<TT><I>subgoal 2 is:</I></TT><BR>
2917
<TT><I> odd (S (S n)) -> False</I></TT><BR>
2919
<TT>Coq < inversion 1.</TT><BR>
2920
<TT><I>1 subgoal</I></TT><BR>
2921
<TT><I> </I></TT><BR>
2922
<TT><I> n : nat</I></TT><BR>
2923
<TT><I> H : even n</I></TT><BR>
2924
<TT><I> IHeven : odd n -> False</I></TT><BR>
2925
<TT><I> ============================</I></TT><BR>
2926
<TT><I> odd (S (S n)) -> False</I></TT><BR>
2928
<TT>Coq < inversion 1. apply IHeven; trivial.</TT><BR>
2929
<TT><I>1 subgoal</I></TT><BR>
2930
<TT><I> </I></TT><BR>
2931
<TT><I> n : nat</I></TT><BR>
2932
<TT><I> H : even n</I></TT><BR>
2933
<TT><I> IHeven : odd n -> False</I></TT><BR>
2934
<TT><I> H0 : odd (S (S n))</I></TT><BR>
2935
<TT><I> n0 : nat</I></TT><BR>
2936
<TT><I> H2 : odd n</I></TT><BR>
2937
<TT><I> H1 : n0 = n</I></TT><BR>
2938
<TT><I> ============================</I></TT><BR>
2939
<TT><I> False</I></TT><BR>
2940
<TT><I>Proof completed.</I></TT><BR>
2942
<TT>Coq < Qed.</TT><BR>
2943
<TT><I>induction 1.</I></TT><BR>
2944
<TT><I> inversion 1.</I></TT><BR>
2945
<TT><I> inversion 1.</I></TT><BR>
2946
<TT><I> apply IHeven; trivial.</I></TT><BR>
2947
<TT><I>Unnamed_thm is defined</I></TT><BR>
2950
In case the type of the second induction hypothesis is not
2951
dependent, <TT>inversion</TT> can just be replaced by <TT>destruct</TT>.<BR>
2953
<!--TOC subsubsection How to define a function by double recursion?-->
2955
<H4><A NAME="htoc131">116</A> How to define a function by double recursion?</H4><!--SEC END -->
2957
The same trick applies, you can even use the pattern-matching
2958
compilation algorithm to do the work for you. Here is an example:<BR>
2962
<TT>Coq < Fixpoint minus (n m:nat) {struct n} : nat :=</TT><BR>
2963
<TT>Coq < match n, m with</TT><BR>
2964
<TT>Coq < | O, _ => 0</TT><BR>
2965
<TT>Coq < | S k, O => S k</TT><BR>
2966
<TT>Coq < | S k, S l => minus k l</TT><BR>
2967
<TT>Coq < end.</TT><BR>
2968
<TT><I>minus is recursively defined</I></TT><BR>
2970
<TT>Coq < Print minus.</TT><BR>
2971
<TT><I>minus = </I></TT><BR>
2972
<TT><I>(fix minus (n m : nat) {struct n} : nat :=</I></TT><BR>
2973
<TT><I> match n with</I></TT><BR>
2974
<TT><I> | O => 0</I></TT><BR>
2975
<TT><I> | S k => match m with</I></TT><BR>
2976
<TT><I> | O => S k</I></TT><BR>
2977
<TT><I> | S l => minus k l</I></TT><BR>
2978
<TT><I> end</I></TT><BR>
2979
<TT><I> end)</I></TT><BR>
2980
<TT><I> : nat -> nat -> nat</I></TT><BR>
2981
<TT><I>Argument scopes are [nat_scope nat_scope]</I></TT><BR>
2984
In case of dependencies in the type of the induction objects
2985
<I>t</I><SUB><FONT SIZE=2>1</FONT></SUB> and <I>t</I><SUB><FONT SIZE=2>2</FONT></SUB>, an extra argument stating <I>t</I><SUB><FONT SIZE=2>1</FONT></SUB>=<I>t</I><SUB><FONT SIZE=2>2</FONT></SUB> must be given to
2986
the fixpoint definition<BR>
2988
<!--TOC subsubsection How to perform nested induction?-->
2990
<H4><A NAME="htoc132">117</A> How to perform nested induction?</H4><!--SEC END -->
2992
To reason by nested induction, just reason by induction on the
2993
successive components.<BR>
2997
<TT>Coq < Infix "<" := lt (at level 70, no associativity).</TT><BR>
2999
<TT>Coq < Infix "<=" := le (at level 70, no associativity).</TT><BR>
3001
<TT>Coq < Lemma le_or_lt : forall n n0:nat, n0 < n \/ n <= n0.</TT><BR>
3002
<TT><I>1 subgoal</I></TT><BR>
3003
<TT><I> </I></TT><BR>
3004
<TT><I> ============================</I></TT><BR>
3005
<TT><I> forall n n0 : nat, n0 < n \/ n <= n0</I></TT><BR>
3007
<TT>Coq < induction n; destruct n0; auto with arith.</TT><BR>
3008
<TT><I>1 subgoal</I></TT><BR>
3009
<TT><I> </I></TT><BR>
3010
<TT><I> n : nat</I></TT><BR>
3011
<TT><I> IHn : forall n0 : nat, n0 < n \/ n <= n0</I></TT><BR>
3012
<TT><I> n0 : nat</I></TT><BR>
3013
<TT><I> ============================</I></TT><BR>
3014
<TT><I> S n0 < S n \/ S n <= S n0</I></TT><BR>
3016
<TT>Coq < destruct (IHn n0); auto with arith.</TT><BR>
3017
<TT><I>Proof completed.</I></TT><BR>
3020
<!--TOC subsubsection How to define a function by nested recursion?-->
3022
<H4><A NAME="htoc133">118</A> How to define a function by nested recursion?</H4><!--SEC END -->
3024
The same trick applies. Here is the example of Ackermann
3029
<TT>Coq < Fixpoint ack (n:nat) : nat -> nat :=</TT><BR>
3030
<TT>Coq < match n with</TT><BR>
3031
<TT>Coq < | O => S</TT><BR>
3032
<TT>Coq < | S n' =></TT><BR>
3033
<TT>Coq < (fix ack' (m:nat) : nat :=</TT><BR>
3034
<TT>Coq < match m with</TT><BR>
3035
<TT>Coq < | O => ack n' 1</TT><BR>
3036
<TT>Coq < | S m' => ack n' (ack' m')</TT><BR>
3037
<TT>Coq < end)</TT><BR>
3038
<TT>Coq < end.</TT><BR>
3039
<TT><I>ack is recursively defined</I></TT><BR>
3042
<!--TOC subsection Co-inductive types-->
3044
<H3><A NAME="htoc134">7.3</A> Co-inductive types</H3><!--SEC END -->
3046
<!--TOC subsubsection I have a cofixpoint <I>t</I>:=<I>F</I>(<I>t</I>) and I want to prove <I>t</I>=<I>F</I>(<I>t</I>). How to do it?-->
3048
<H4><A NAME="htoc135">119</A> I have a cofixpoint <I>t</I>:=<I>F</I>(<I>t</I>) and I want to prove <I>t</I>=<I>F</I>(<I>t</I>). How to do it?</H4><!--SEC END -->
3050
Just case-expand <I>F</I>(<TT><I>t</I></TT>) then complete by a trivial case analysis.
3051
Here is what it gives on e.g. the type of streams on naturals<BR>
3055
<TT>Coq < CoInductive Stream (A:Set) : Set :=</TT><BR>
3056
<TT>Coq < Cons : A -> Stream A -> Stream A.</TT><BR>
3057
<TT><I>Stream is defined</I></TT><BR>
3059
<TT>Coq < CoFixpoint nats (n:nat) : Stream nat := Cons n (nats (S n)).</TT><BR>
3060
<TT><I>nats is corecursively defined</I></TT><BR>
3062
<TT>Coq < Lemma Stream_unfold : </TT><BR>
3063
<TT>Coq < forall n:nat, nats n = Cons n (nats (S n)).</TT><BR>
3064
<TT><I>1 subgoal</I></TT><BR>
3065
<TT><I> </I></TT><BR>
3066
<TT><I> ============================</I></TT><BR>
3067
<TT><I> forall n : nat, nats n = Cons n (nats (S n))</I></TT><BR>
3069
<TT>Coq < Proof.</TT><BR>
3071
<TT>Coq < intro;</TT><BR>
3072
<TT>Coq < change (nats n = match nats n with</TT><BR>
3073
<TT>Coq < | Cons x s => Cons x s</TT><BR>
3074
<TT>Coq < end).</TT><BR>
3075
<TT><I>1 subgoal</I></TT><BR>
3076
<TT><I> </I></TT><BR>
3077
<TT><I> n : nat</I></TT><BR>
3078
<TT><I> ============================</I></TT><BR>
3079
<TT><I> nats n = match nats n with</I></TT><BR>
3080
<TT><I> | Cons x s => Cons x s</I></TT><BR>
3081
<TT><I> end</I></TT><BR>
3083
<TT>Coq < case (nats n); reflexivity.</TT><BR>
3084
<TT><I>Proof completed.</I></TT><BR>
3086
<TT>Coq < Qed.</TT><BR>
3087
<TT><I>intro; change (nats n = match nats n with</I></TT><BR>
3088
<TT><I> | Cons x s => Cons x s</I></TT><BR>
3089
<TT><I> end) in |- *.</I></TT><BR>
3090
<TT><I>case (nats n); reflexivity.</I></TT><BR>
3091
<TT><I>Stream_unfold is defined</I></TT><BR>
3094
<!--TOC section Syntax and notations-->
3096
<H2><A NAME="htoc136">8</A> Syntax and notations</H2><!--SEC END -->
3098
<!--TOC subsubsection I do not want to type ``forall'' because it is too long, what can I do?-->
3100
<H4><A NAME="htoc137">120</A> I do not want to type ``forall'' because it is too long, what can I do?</H4><!--SEC END -->
3102
You can define your own notation for forall:
3104
Notation "fa x : t, P" := (forall x:t, P) (at level 200, x ident).
3105
</PRE>or if your are using <FONT COLOR=navy>CoqIde</FONT> you can define a pretty symbol for for all and an input method (see <A HREF="#forallcoqide">150</A>).<BR>
3107
<!--TOC subsubsection How can I define a notation for square?-->
3109
<H4><A NAME="htoc138">121</A> How can I define a notation for square?</H4><!--SEC END -->
3111
You can use for instance:
3113
Notation "x ^2" := (Rmult x x) (at level 20).
3114
</PRE>Note that you can not use:
3115
<TT>N</TT>otation "x <SUP><FONT SIZE=2>�</FONT></SUP>" := (Rmult x x) (at level 20).
3117
because ``<SUP><FONT SIZE=2>2</FONT></SUP>'' is an iso-latin character. If you really want this kind of notation you should use UTF-8.<BR>
3119
<!--TOC subsubsection Why ``no associativity'' and ``left associativity'' at the same level does not work?-->
3121
<H4><A NAME="htoc139">122</A> Why ``no associativity'' and ``left associativity'' at the same level does not work?</H4><!--SEC END -->
3123
Because we relie on camlp4 for syntactical analysis and camlp4 does not really implement no associativity. By default, non associative operators are defined as right associative.<BR>
3125
<!--TOC subsubsection How can I know the associativity associated with a level?-->
3127
<H4><A NAME="htoc140">123</A> How can I know the associativity associated with a level?</H4><!--SEC END -->
3129
You can do ``Print Grammar constr'', and decode the output from camlp4, good luck !<BR>
3131
<!--TOC section Modules-->
3133
<H2><A NAME="htoc141">9</A> Modules</H2><!--SEC END -->
3135
<!--TOC section <FONT COLOR=navy>Ltac</FONT>-->
3137
<H2><A NAME="htoc142">10</A> <FONT COLOR=navy>Ltac</FONT></H2><!--SEC END -->
3139
<!--TOC subsubsection What is <FONT COLOR=navy>Ltac</FONT>?-->
3141
<H4><A NAME="htoc143">124</A> What is <FONT COLOR=navy>Ltac</FONT>?</H4><!--SEC END -->
3143
<FONT COLOR=navy>Ltac</FONT> is the tactic language for <FONT COLOR=navy>Coq</FONT>. It provides the user with a
3144
high-level ``toolbox'' for tactic creation.<BR>
3146
<!--TOC subsubsection Why do I always get the same error message?-->
3148
<H4><A NAME="htoc144">125</A> Why do I always get the same error message?</H4><!--SEC END -->
3150
<!--TOC subsubsection Is there any printing command in <FONT COLOR=navy>Ltac</FONT>?-->
3152
<H4><A NAME="htoc145">126</A> Is there any printing command in <FONT COLOR=navy>Ltac</FONT>?</H4><!--SEC END -->
3154
You can use the <TT>idtac</TT> tactic with a string argument. This string
3155
will be printed out. The same applies to the <TT>fail</TT> tactic<BR>
3157
<!--TOC subsubsection What is the syntax for let in <FONT COLOR=navy>Ltac</FONT>?-->
3159
<H4><A NAME="htoc146">127</A> What is the syntax for let in <FONT COLOR=navy>Ltac</FONT>?</H4><!--SEC END -->
3161
If <I>x</I><SUB><FONT SIZE=2><I>i</I></FONT></SUB> are identifiers and <I>e</I><SUB><FONT SIZE=2><I>i</I></FONT></SUB> and <I>expr</I> are tactic expressions, then let reads:
3163
<TT>let <I>x</I></TT><SUB><TT><FONT SIZE=2>1</FONT></TT></SUB><TT>:=<I>e</I></TT><SUB><TT><FONT SIZE=2>1</FONT></TT></SUB><TT> with <I>x</I></TT><SUB><TT><FONT SIZE=2>2</FONT></TT></SUB><TT>:=<I>e</I></TT><SUB><TT><FONT SIZE=2>2</FONT></TT></SUB><TT>...with <I>x</I></TT><SUB><TT><FONT SIZE=2><I>n</I></FONT></TT></SUB><TT>:=<I>e</I></TT><SUB><TT><FONT SIZE=2><I>n</I></FONT></TT></SUB><TT> in
3166
Beware that if <I>expr</I> is complex (i.e. features at least a sequence) parenthesis
3167
should be added around it. For example:
3170
<TT>Coq < Ltac twoIntro := let x:=intro in (x;x).</TT><BR>
3171
<TT><I>twoIntro is defined</I></TT><BR>
3174
<!--TOC subsubsection What is the syntax for pattern matching in <FONT COLOR=navy>Ltac</FONT>?-->
3176
<H4><A NAME="htoc147">128</A> What is the syntax for pattern matching in <FONT COLOR=navy>Ltac</FONT>?</H4><!--SEC END -->
3178
Pattern matching on a term <I>expr</I> (non-linear first order unification)
3179
with patterns <I>p</I><SUB><FONT SIZE=2><I>i</I></FONT></SUB> and tactic expressions <I>e</I><SUB><FONT SIZE=2><I>i</I></FONT></SUB> reads:
3181
3182
<TT>match <I>expr</I> with
3183
<I>p</I></TT><SUB><TT><FONT SIZE=2>1</FONT></TT></SUB><TT> => <I>e</I></TT><SUB><TT><FONT SIZE=2>1</FONT></TT></SUB><TT>
3184
|<I>p</I></TT><SUB><TT><FONT SIZE=2>2</FONT></TT></SUB><TT> => <I>e</I></TT><SUB><TT><FONT SIZE=2>2</FONT></TT></SUB><TT>
3185
... |<I>p</I></TT><SUB><TT><FONT SIZE=2><I>n</I></FONT></TT></SUB><TT> => <I>e</I></TT><SUB><TT><FONT SIZE=2><I>n</I></FONT></TT></SUB><TT>
3186
| _ => <I>e</I></TT><SUB><TT><FONT SIZE=2><I>n</I>+1</FONT></TT></SUB><TT>
3190
Underscore matches all terms.<BR>
3192
<!--TOC subsubsection What is the semantics for match goal?-->
3194
<H4><A NAME="htoc148">129</A> What is the semantics for match goal?</H4><!--SEC END -->
3196
<TT>match goal</TT> matches the current goal against a series of
3197
patterns: <I>hyp</I><SUB><FONT SIZE=2>1</FONT></SUB> ... <I>hyp</I><SUB><FONT SIZE=2><I>n</I></FONT></SUB> |- <I>ccl</I>. It uses a
3198
first-order unification algorithm, and tries all the possible
3199
combinations of <I>hyp</I><SUB><FONT SIZE=2><I>i</I></FONT></SUB> before dropping the branch and moving to the
3200
next one. Underscore matches all terms.<BR>
3202
<!--TOC subsubsection How can I generate a new name?-->
3204
<H4><A NAME="htoc149">130</A> How can I generate a new name?</H4><!--SEC END -->
3206
You can use the following syntax:
3207
<TT>let id:=fresh in ...</TT><BR>
3211
<TT>Coq < Ltac introIdGen := let id:=fresh in intro id.</TT><BR>
3212
<TT><I>introIdGen is defined</I></TT><BR>
3215
<!--TOC subsubsection How can I define static and dynamic code?-->
3217
<H4><A NAME="htoc150">131</A> How can I define static and dynamic code?</H4><!--SEC END -->
3219
<!--TOC section Tactics written in Ocaml-->
3221
<H2><A NAME="htoc151">11</A> Tactics written in Ocaml</H2><!--SEC END -->
3223
<!--TOC subsubsection Can you show me an example of a tactic written in OCaml?-->
3225
<H4><A NAME="htoc152">132</A> Can you show me an example of a tactic written in OCaml?</H4><!--SEC END -->
3227
You have some examples of tactics written in Ocaml in the ``contrib'' directory of <FONT COLOR=navy>Coq</FONT> sources. <BR>
3229
<!--TOC section Case studies-->
3231
<H2><A NAME="htoc153">12</A> Case studies</H2><!--SEC END -->
3233
<!--TOC subsubsection How can I define vectors or lists of size n?-->
3235
<H4><A NAME="htoc154">133</A> How can I define vectors or lists of size n?</H4><!--SEC END -->
3237
<!--TOC subsubsection How to prove that 2 sets are different?-->
3239
<H4><A NAME="htoc155">134</A> How to prove that 2 sets are different?</H4><!--SEC END -->
3241
You need to find a property true on one set and false on the
3242
other one. As an example we show how to prove that <TT>bool</TT> and <TT>nat</TT> are discriminable. As discrimination property we take the
3243
property to have no more than 2 elements.<BR>
3247
<TT>Coq < Theorem nat_bool_discr : bool <> nat.</TT><BR>
3249
<TT>Coq < Proof.</TT><BR>
3251
<TT>Coq < pose (discr :=</TT><BR>
3252
<TT>Coq < fun X:Set =></TT><BR>
3253
<TT>Coq < ~ (forall a b:X, ~ (forall x:X, x <> a -> x <> b -> False))).</TT><BR>
3255
<TT>Coq < intro Heq; assert (H: discr bool).</TT><BR>
3257
<TT>Coq < intro H; apply (H true false); destruct x; auto.</TT><BR>
3259
<TT>Coq < rewrite Heq in H; apply H; clear H.</TT><BR>
3261
<TT>Coq < destruct a; destruct b as [|n]; intro H0; eauto.</TT><BR>
3263
<TT>Coq < destruct n; [ apply (H0 2); discriminate | eauto ].</TT><BR>
3265
<TT>Coq < Qed.</TT><BR>
3268
<!--TOC subsubsection Is there an axiom-free proof of Streicher's axiom <I>K</I> for
3269
the equality on <TT>nat</TT>?-->
3271
<H4><A NAME="htoc156">135</A> Is there an axiom-free proof of Streicher's axiom <I>K</I> for
3272
the equality on <TT>nat</TT>?</H4><!--SEC END -->
3274
<A NAME="K-nat"></A>
3275
Yes, because equality is decidable on <TT>nat</TT>. Here is the proof.<BR>
3279
<TT>Coq < Require Import Eqdep_dec.</TT><BR>
3281
<TT>Coq < Require Import Peano_dec.</TT><BR>
3283
<TT>Coq < Theorem K_nat :</TT><BR>
3284
<TT>Coq < forall (x:nat) (P:x = x -> Prop), P (refl_equal x) -> forall p:x = x, P p.</TT><BR>
3286
<TT>Coq < Proof.</TT><BR>
3288
<TT>Coq < intros; apply K_dec_set with (p := p).</TT><BR>
3290
<TT>Coq < apply eq_nat_dec.</TT><BR>
3292
<TT>Coq < assumption.</TT><BR>
3294
<TT>Coq < Qed.</TT><BR>
3297
Similarly, we have<BR>
3301
<TT>Coq < Theorem eq_rect_eq_nat :</TT><BR>
3302
<TT>Coq < forall (p:nat) (Q:nat->Type) (x:Q p) (h:p=p), x = eq_rect p Q x p h.</TT><BR>
3304
<TT>Coq < Proof.</TT><BR>
3306
<TT>Coq < intros; apply K_nat with (p := h); reflexivity.</TT><BR>
3308
<TT>Coq < Qed.</TT><BR>
3311
<!--TOC subsubsection How to prove that two proofs of <TT>n<=m</TT> on <TT>nat</TT> are equal?-->
3313
<H4><A NAME="htoc157">136</A> How to prove that two proofs of <TT>n<=m</TT> on <TT>nat</TT> are equal?</H4><!--SEC END -->
3315
<A NAME="le-uniqueness"></A>
3316
This is provable without requiring any axiom because axiom <I>K</I>
3317
directly holds on <TT>nat</TT>. Here is a proof using question <A HREF="#K-nat">135</A>.<BR>
3321
<TT>Coq < Scheme le_ind' := Induction for le Sort Prop.</TT><BR>
3323
<TT>Coq < Theorem le_uniqueness_proof : forall (n m : nat) (p q : n <= m), p = q.</TT><BR>
3325
<TT>Coq < Proof.</TT><BR>
3327
<TT>Coq < induction p using le_ind'; intro q.</TT><BR>
3329
<TT>Coq < replace (le_n n) with</TT><BR>
3330
<TT>Coq < (eq_rect _ (fun n0 => n <= n0) (le_n n) _ (refl_equal n)).</TT><BR>
3332
<TT>Coq < 2:reflexivity.</TT><BR>
3334
<TT>Coq < generalize (refl_equal n).</TT><BR>
3336
<TT>Coq < pattern n at 2 4 6 10, q; case q; [intro | intros m l e].</TT><BR>
3338
<TT>Coq < rewrite <- eq_rect_eq_nat; trivial.</TT><BR>
3340
<TT>Coq < contradiction (le_Sn_n m); rewrite <- e; assumption.</TT><BR>
3342
<TT>Coq < replace (le_S n m p) with</TT><BR>
3343
<TT>Coq < (eq_rect _ (fun n0 => n <= n0) (le_S n m p) _ (refl_equal (S m))).</TT><BR>
3345
<TT>Coq < 2:reflexivity.</TT><BR>
3347
<TT>Coq < generalize (refl_equal (S m)).</TT><BR>
3349
<TT>Coq < pattern (S m) at 1 3 4 6, q; case q; [intro Heq | intros m0 l HeqS].</TT><BR>
3351
<TT>Coq < contradiction (le_Sn_n m); rewrite Heq; assumption.</TT><BR>
3353
<TT>Coq < injection HeqS; intro Heq; generalize l HeqS.</TT><BR>
3355
<TT>Coq < rewrite <- Heq; intros; rewrite <- eq_rect_eq_nat.</TT><BR>
3357
<TT>Coq < rewrite (IHp l0); reflexivity.</TT><BR>
3359
<TT>Coq < Qed.</TT><BR>
3362
<!--TOC subsubsection How to exploit equalities on sets-->
3364
<H4><A NAME="htoc158">137</A> How to exploit equalities on sets</H4><!--SEC END -->
3366
To extract information from an equality on sets, you need to
3367
find a predicate of sets satisfied by the elements of the sets. As an
3368
example, let's consider the following theorem.<BR>
3372
<TT>Coq < Theorem interval_discr :</TT><BR>
3373
<TT>Coq < forall m n:nat,</TT><BR>
3374
<TT>Coq < {x : nat | x <= m} = {x : nat | x <= n} -> m = n.</TT><BR>
3377
We have a proof requiring the axiom of proof-irrelevance. We
3378
conjecture that proof-irrelevance can be circumvented by introducing a
3379
primitive definition of discrimination of the proofs of
3380
<CODE>{x : nat | x <= m}</CODE>.<BR>
3382
<A HREF="./interval_discr.v">Here</A> is the proof.
3385
<!--TOC subsubsection I have a problem of dependent elimination on
3386
proofs, how to solve it?-->
3388
<H4><A NAME="htoc159">138</A> I have a problem of dependent elimination on
3389
proofs, how to solve it?</H4><!--SEC END -->
3393
<TT>Coq < Inductive Def1 : Set := c1 : Def1.</TT><BR>
3395
<TT>Coq < Inductive DefProp : Def1 -> Prop :=</TT><BR>
3396
<TT>Coq < c2 : forall d:Def1, DefProp d.</TT><BR>
3398
<TT>Coq < Inductive Comb : Set :=</TT><BR>
3399
<TT>Coq < c3 : forall d:Def1, DefProp d -> Comb.</TT><BR>
3401
<TT>Coq < Lemma eq_comb :</TT><BR>
3402
<TT>Coq < forall (d1 d1':Def1) (d2:DefProp d1) (d2':DefProp d1'),</TT><BR>
3403
<TT>Coq < d1 = d1' -> c3 d1 d2 = c3 d1' d2'.</TT><BR>
3406
You need to derive the dependent elimination
3407
scheme for DefProp by hand using <TT>S</TT>cheme.<BR>
3411
<TT>Coq < Scheme DefProp_elim := Induction for DefProp Sort Prop.</TT><BR>
3413
<TT>Coq < Lemma eq_comb :</TT><BR>
3414
<TT>Coq < forall d1 d1':Def1,</TT><BR>
3415
<TT>Coq < d1 = d1' -></TT><BR>
3416
<TT>Coq < forall (d2:DefProp d1) (d2':DefProp d1'), c3 d1 d2 = c3 d1' d2'.</TT><BR>
3418
<TT>Coq < intros.</TT><BR>
3420
<TT>Coq < destruct H.</TT><BR>
3422
<TT>Coq < destruct d2 using DefProp_elim.</TT><BR>
3424
<TT>Coq < destruct d2' using DefProp_elim.</TT><BR>
3426
<TT>Coq < reflexivity.</TT><BR>
3428
<TT>Coq < Qed.</TT><BR>
3431
<!--TOC subsubsection And what if I want to prove the following?-->
3433
<H4><A NAME="htoc160">139</A> And what if I want to prove the following?</H4><!--SEC END -->
3437
<TT>Coq < Inductive natProp : nat -> Prop :=</TT><BR>
3438
<TT>Coq < | p0 : natProp 0</TT><BR>
3439
<TT>Coq < | pS : forall n:nat, natProp n -> natProp (S n).</TT><BR>
3441
<TT>Coq < Inductive package : Set :=</TT><BR>
3442
<TT>Coq < pack : forall n:nat, natProp n -> package.</TT><BR>
3444
<TT>Coq < Lemma eq_pack :</TT><BR>
3445
<TT>Coq < forall n n':nat,</TT><BR>
3446
<TT>Coq < n = n' -></TT><BR>
3447
<TT>Coq < forall (np:natProp n) (np':natProp n'), pack n np = pack n' np'.</TT><BR>
3452
<TT>Coq < Scheme natProp_elim := Induction for natProp Sort Prop.</TT><BR>
3454
<TT>Coq < Definition pack_S : package -> package.</TT><BR>
3456
<TT>Coq < destruct 1.</TT><BR>
3458
<TT>Coq < apply (pack (S n)).</TT><BR>
3460
<TT>Coq < apply pS; assumption.</TT><BR>
3462
<TT>Coq < Defined.</TT><BR>
3464
<TT>Coq < Lemma eq_pack :</TT><BR>
3465
<TT>Coq < forall n n':nat,</TT><BR>
3466
<TT>Coq < n = n' -></TT><BR>
3467
<TT>Coq < forall (np:natProp n) (np':natProp n'), pack n np = pack n' np'.</TT><BR>
3469
<TT>Coq < intros n n' Heq np np'.</TT><BR>
3471
<TT>Coq < generalize dependent n'.</TT><BR>
3473
<TT>Coq < induction np using natProp_elim.</TT><BR>
3475
<TT>Coq < induction np' using natProp_elim; intros; auto.</TT><BR>
3477
<TT>Coq < discriminate Heq.</TT><BR>
3479
<TT>Coq < induction np' using natProp_elim; intros; auto.</TT><BR>
3481
<TT>Coq < discriminate Heq.</TT><BR>
3483
<TT>Coq < change (pack_S (pack n np) = pack_S (pack n0 np')).</TT><BR>
3485
<TT>Coq < apply (f_equal (A:=package)).</TT><BR>
3487
<TT>Coq < apply IHnp.</TT><BR>
3489
<TT>Coq < auto.</TT><BR>
3491
<TT>Coq < Qed.</TT><BR>
3494
<!--TOC section Publishing tools-->
3496
<H2><A NAME="htoc161">13</A> Publishing tools</H2><!--SEC END -->
3498
<!--TOC subsubsection How can I generate some latex from my development?-->
3500
<H4><A NAME="htoc162">140</A> How can I generate some latex from my development?</H4><!--SEC END -->
3502
You can use <TT>coqdoc</TT>.<BR>
3504
<!--TOC subsubsection How can I generate some HTML from my development?-->
3506
<H4><A NAME="htoc163">141</A> How can I generate some HTML from my development?</H4><!--SEC END -->
3508
You can use <TT>coqdoc</TT>.<BR>
3510
<!--TOC subsubsection How can I generate some dependency graph from my development?-->
3512
<H4><A NAME="htoc164">142</A> How can I generate some dependency graph from my development?</H4><!--SEC END -->
3514
<!--TOC subsubsection How can I cite some <FONT COLOR=navy>Coq</FONT> in my latex document?-->
3516
<H4><A NAME="htoc165">143</A> How can I cite some <FONT COLOR=navy>Coq</FONT> in my latex document?</H4><!--SEC END -->
3518
You can use <TT>coq_tex</TT>.<BR>
3520
<!--TOC subsubsection How can I cite the <FONT COLOR=navy>Coq</FONT> reference manual?-->
3522
<H4><A NAME="htoc166">144</A> How can I cite the <FONT COLOR=navy>Coq</FONT> reference manual?</H4><!--SEC END -->
3524
You can use this bibtex entry:
3527
title = {The Coq proof assistant reference manual},
3528
author = {\mbox{The Coq development team}},
3529
organization = {LogiCal Project},
3530
note = {Version 8.0},
3532
url = "http://coq.inria.fr"
3535
<!--TOC subsubsection Where can I publish my developments in <FONT COLOR=navy>Coq</FONT>?-->
3537
<H4><A NAME="htoc167">145</A> Where can I publish my developments in <FONT COLOR=navy>Coq</FONT>?</H4><!--SEC END -->
3539
You can submit your developments as a user contribution to the <FONT COLOR=navy>Coq</FONT>
3540
development team. This ensures its liveness along the evolution and
3541
possible changes of <FONT COLOR=navy>Coq</FONT>.<BR>
3543
You can also submit your developments to the HELM/MoWGLI repository at
3544
the University of Bologna (see
3545
<A HREF="http://mowgli.cs.unibo.it"><TT>http://mowgli.cs.unibo.it</TT></A>). For
3546
developments submitted in this database, it is possible to visualize
3547
the developments in natural language and execute various retrieving
3550
<!--TOC subsubsection How can I read my proof in natural language?-->
3552
<H4><A NAME="htoc168">146</A> How can I read my proof in natural language?</H4><!--SEC END -->
3554
You can submit your proof to the HELM/MoWGLI repository and use the
3555
rendering tool provided by the server (see
3556
<A HREF="http://mowgli.cs.unibo.it"><TT>http://mowgli.cs.unibo.it</TT></A>).<BR>
3558
<!--TOC section <FONT COLOR=navy>CoqIde</FONT>-->
3560
<H2><A NAME="htoc169">14</A> <FONT COLOR=navy>CoqIde</FONT></H2><!--SEC END -->
3562
<!--TOC subsubsection What is <FONT COLOR=navy>CoqIde</FONT>?-->
3564
<H4><A NAME="htoc170">147</A> What is <FONT COLOR=navy>CoqIde</FONT>?</H4><!--SEC END -->
3566
<FONT COLOR=navy>CoqIde</FONT> is a gtk based GUI for <FONT COLOR=navy>Coq</FONT>.<BR>
3568
<!--TOC subsubsection How to enable Emacs keybindings?-->
3570
<H4><A NAME="htoc171">148</A> How to enable Emacs keybindings?</H4><!--SEC END -->
3572
Insert <TT>gtk-key-theme-name = "Emacs"</TT>
3573
in your <TT>.coqide-gtk2rc</TT> file. It may be in the current dir
3574
or in <CODE>$HOME</CODE> dir. This is done by default.<BR>
3576
<!--TOC subsubsection How to enable antialiased fonts?-->
3578
<H4><A NAME="htoc172">149</A> How to enable antialiased fonts?</H4><!--SEC END -->
3580
Set the <CODE>GDK_USE_XFT</CODE> variable to <CODE>1</CODE>. This is by default with <CODE>Gtk >= 2.2</CODE>.
3581
If some of your fonts are not available, set <CODE>GDK_USE_XFT</CODE> to <CODE>0</CODE>.<BR>
3583
<!--TOC subsubsection How to use those Forall and Exists pretty symbols?-->
3585
<H4><A NAME="htoc173">150</A> How to use those Forall and Exists pretty symbols?</H4><!--SEC END -->
3586
<A NAME="forallcoqide"></A>
3587
Thanks to the notation features in <FONT COLOR=navy>Coq</FONT>, you just need to insert these
3588
lines in your <FONT COLOR=navy>Coq</FONT> buffer:<BR>
3589
<TT>N</TT>otation "for all x : t, P" := (forall x:t, P) (at level 200, x ident).
3591
<TT>N</TT>otation "there exists x : t, P" := (exists x:t, P) (at level 200, x ident).
3594
Copy/Paste of these lines from this file will not work outside of <FONT COLOR=navy>CoqIde</FONT>.
3595
You need to load a file containing these lines or to enter the for all
3596
using an input method (see <A HREF="#inputmeth">151</A>). To try it just use <CODE>Require Import utf8</CODE> from inside
3597
<FONT COLOR=navy>CoqIde</FONT>.
3598
To enable these notations automatically start coqide with
3601
</PRE>In the ide subdir of <FONT COLOR=navy>Coq</FONT> library, you will find a sample utf8.v with some
3602
pretty simple notations.<BR>
3604
<!--TOC subsubsection How to define an input method for non ASCII symbols?-->
3606
<H4><A NAME="htoc174">151</A> How to define an input method for non ASCII symbols?</H4><!--SEC END -->
3607
<A NAME="inputmeth"></A>
3609
First solution: type <CODE><CONTROL><SHIFT>2200</CODE> to enter a forall in the script widow.
3610
2200 is the hexadecimal code for forall in unicode charts and is encoded as
3612
2203 is for exists. See <A HREF="http://www.unicode.org"><TT>http://www.unicode.org</TT></A> for more codes.
3613
<LI>Second solution: rebind <CODE><AltGr>a</CODE> to forall and <CODE><AltGr>e</CODE> to exists.
3614
Under X11, you need to use something like
3616
xmodmap -e "keycode 24 = a A F13 F13"
3617
xmodmap -e "keycode 26 = e E F14 F14"
3618
</PRE> and then to add
3620
bind "F13" {"insert-at-cursor" ("")}
3621
bind "F14" {"insert-at-cursor" ("")}
3622
</PRE> to your "binding "text"" section in <CODE>.coqiderc-gtk2rc.</CODE>
3623
The strange ("") argument is the UTF-8 encoding for
3625
You can compute these encodings using the lablgtk2 toplevel with
3627
Glib.Utf8.from_unichar 0x2200;;
3628
</PRE> Further symbols can be bound on higher Fxx keys or on even on other keys you
3631
<!--TOC subsubsection How to build a custom <FONT COLOR=navy>CoqIde</FONT> with user ml code?-->
3633
<H4><A NAME="htoc175">152</A> How to build a custom <FONT COLOR=navy>CoqIde</FONT> with user ml code?</H4><!--SEC END -->
3636
coqmktop -ide -byte m1.cmo...mi.cmo
3638
coqmktop -ide -opt m1.cmx...mi.cmx<BR>
3640
<!--TOC subsubsection How to customize the shortcuts for menus?-->
3642
<H4><A NAME="htoc176">153</A> How to customize the shortcuts for menus?</H4><!--SEC END -->
3644
Two solutions are offered:
3646
Edit $HOME/.coqide.keys by hand or
3647
<LI>Add "gtk-can-change-accels = 1" in your .coqide-gtk2rc file. Then
3648
from <FONT COLOR=navy>CoqIde</FONT>, you may select a menu entry and press the desired
3651
<!--TOC subsubsection What encoding should I use? What is this \x{iiii} in my file?-->
3653
<H4><A NAME="htoc177">154</A> What encoding should I use? What is this \x{iiii} in my file?</H4><!--SEC END -->
3655
The encoding option is related to the way files are saved.
3656
Keep it as UTF-8 until it becomes important for you to exchange files
3657
with non UTF-8 aware applications.
3658
If you choose something else than UTF-8, then missing characters will
3659
be encoded by \x{....} or \x{........}
3660
where each dot is an hex. digit.
3661
The number between braces is the hexadecimal UNICODE index for the
3662
missing character.<BR>
3664
<!--TOC section Extraction-->
3666
<H2><A NAME="htoc178">15</A> Extraction</H2><!--SEC END -->
3668
<!--TOC subsubsection What is program extraction?-->
3670
<H4><A NAME="htoc179">155</A> What is program extraction?</H4><!--SEC END -->
3672
Program extraction consist in generating a program from a constructive proof.<BR>
3674
<!--TOC subsubsection Which language can I extract to?-->
3676
<H4><A NAME="htoc180">156</A> Which language can I extract to?</H4><!--SEC END -->
3678
You can extract your programs to Objective Caml and Haskell.<BR>
3680
<!--TOC subsubsection How can I extract an incomplete proof?-->
3682
<H4><A NAME="htoc181">157</A> How can I extract an incomplete proof?</H4><!--SEC END -->
3684
You can provide programs for your axioms.<BR>
3686
<!--TOC section Glossary-->
3688
<H2><A NAME="htoc182">16</A> Glossary</H2><!--SEC END -->
3690
<!--TOC subsubsection Can you explain me what an evaluable constant is?-->
3692
<H4><A NAME="htoc183">158</A> Can you explain me what an evaluable constant is?</H4><!--SEC END -->
3694
An evaluable constant is a constant which is unfoldable.<BR>
3696
<!--TOC subsubsection What is a goal?-->
3698
<H4><A NAME="htoc184">159</A> What is a goal?</H4><!--SEC END -->
3700
The goal is the statement to be proved.<BR>
3702
<!--TOC subsubsection What is a meta variable?-->
3704
<H4><A NAME="htoc185">160</A> What is a meta variable?</H4><!--SEC END -->
3706
A meta variable in <FONT COLOR=navy>Coq</FONT> represents a ``hole'', i.e. a part of a proof
3707
that is still unknown. <BR>
3709
<!--TOC subsubsection What is Gallina?-->
3711
<H4><A NAME="htoc186">161</A> What is Gallina?</H4><!--SEC END -->
3713
Gallina is the specification language of <FONT COLOR=navy>Coq</FONT>. Complete documentation
3714
of this language can be found in the Reference Manual.<BR>
3716
<!--TOC subsubsection What is The Vernacular?-->
3718
<H4><A NAME="htoc187">162</A> What is The Vernacular?</H4><!--SEC END -->
3720
It is the language of commands of Gallina i.e. definitions, lemmas, ... <BR>
3722
<!--TOC subsubsection What is a dependent type?-->
3724
<H4><A NAME="htoc188">163</A> What is a dependent type?</H4><!--SEC END -->
3726
A dependant type is a type which depends on some term. For instance
3727
``vector of size n'' is a dependant type representing all the vectors
3728
of size <I>n</I>. Its type depends on <I>n</I><BR>
3730
<!--TOC subsubsection What is a proof by reflection?-->
3732
<H4><A NAME="htoc189">164</A> What is a proof by reflection?</H4><!--SEC END -->
3734
This is a proof generated by some computation which is done using the
3735
internal reduction of <FONT COLOR=navy>Coq</FONT> (not using the tactic language of <FONT COLOR=navy>Coq</FONT>
3736
(<FONT COLOR=navy>Ltac</FONT>) nor the implementation language for <FONT COLOR=navy>Coq</FONT>). An example of
3737
tactic using the reflection mechanism is the <TT>ring</TT> tactic. The
3738
reflection method consist in reflecting a subset of <FONT COLOR=navy>Coq</FONT> language (for
3739
example the arithmetical expressions) into an object of the <FONT COLOR=navy>Coq</FONT>language itself (in this case an inductive type denoting arithmetical
3740
expressions). For more information see [<A HREF="#howe"><CITE>13</CITE></A><CITE>, </CITE><A HREF="#harrison"><CITE>11</CITE></A><CITE>, </CITE><A HREF="#boutin"><CITE>2</CITE></A>]
3741
and the last chapter of the Coq'Art.<BR>
3743
<!--TOC subsubsection What is intuitionistic logic?-->
3745
<H4><A NAME="htoc190">165</A> What is intuitionistic logic?</H4><!--SEC END -->
3747
This is any logic which does not assume that ``A or not A''.<BR>
3749
<!--TOC subsubsection What is proof-irrelevance?-->
3751
<H4><A NAME="htoc191">166</A> What is proof-irrelevance?</H4><!--SEC END -->
3753
See question <A HREF="#proof-irrelevance">34</A><BR>
3755
<!--TOC subsubsection What is the difference between opaque and transparent?-->
3757
<H4><A NAME="htoc192">167</A> What is the difference between opaque and transparent?</H4><!--SEC END -->
3758
<A NAME="opaque"></A> <BR>
3760
Opaque definitions can not be unfolded but transparent ones can.<BR>
3762
<!--TOC section Troubleshooting-->
3764
<H2><A NAME="htoc193">17</A> Troubleshooting</H2><!--SEC END -->
3766
<!--TOC subsubsection What can I do when <TT>Qed.</TT> is slow?-->
3768
<H4><A NAME="htoc194">168</A> What can I do when <TT>Qed.</TT> is slow?</H4><!--SEC END -->
3770
Sometime you can use the <TT>abstract</TT> tactic, which makes as if you had
3771
stated some local lemma, this speeds up the typing process.<BR>
3773
<!--TOC subsubsection Why <TT>Reset Initial.</TT> does not work when using <TT>coqc</TT>?-->
3775
<H4><A NAME="htoc195">169</A> Why <TT>Reset Initial.</TT> does not work when using <TT>coqc</TT>?</H4><!--SEC END -->
3777
The initial state corresponds to the state of coqtop when the interactive
3778
session began. It does not make sense in files to compile.<BR>
3780
<!--TOC subsubsection What can I do if I get ``No more subgoals but non-instantiated existential variables''?-->
3782
<H4><A NAME="htoc196">170</A> What can I do if I get ``No more subgoals but non-instantiated existential variables''?</H4><!--SEC END -->
3784
This means that <TT>eauto</TT> or <TT>eapply</TT> didn't instantiate an
3785
existential variable which eventually got erased by some computation.
3786
You have to backtrack to the faulty occurrence of <TT>eauto</TT> or
3787
<TT>eapply</TT> and give the missing argument an explicit value.<BR>
3789
<!--TOC subsubsection What can I do if I get ``Cannot solve a second-order unification problem''?-->
3791
<H4><A NAME="htoc197">171</A> What can I do if I get ``Cannot solve a second-order unification problem''?</H4><!--SEC END -->
3793
You can help <FONT COLOR=navy>Coq</FONT> using the <TT>pattern</TT> tactic.<BR>
3795
<!--TOC subsubsection Why does <FONT COLOR=navy>Coq</FONT> tell me that <TT>{x:A|(P x)}</TT> is not convertible with <TT>(sig A P)</TT>?-->
3797
<H4><A NAME="htoc198">172</A> Why does <FONT COLOR=navy>Coq</FONT> tell me that <TT>{x:A|(P x)}</TT> is not convertible with <TT>(sig A P)</TT>?</H4><!--SEC END -->
3799
This is because <TT>{x:A|P x}</TT> is a notation for
3800
<TT>sig (fun x:A => P x)</TT>. Since <FONT COLOR=navy>Coq</FONT> does not reason up to
3801
eta-conversion, this is different from <TT>sig P</TT>.<BR>
3803
<!--TOC subsubsection I copy-paste a term and <FONT COLOR=navy>Coq</FONT> says it is not convertible
3804
to the original term. Sometimes it even says the copied term is not
3807
<H4><A NAME="htoc199">173</A> I copy-paste a term and <FONT COLOR=navy>Coq</FONT> says it is not convertible
3808
to the original term. Sometimes it even says the copied term is not
3809
well-typed.</H4><!--SEC END -->
3811
This is probably due to invisible implicit information (implicit
3812
arguments, coercions and Cases annotations) in the printed term, which
3813
is not re-synthesised from the copied-pasted term in the same way as
3814
it is in the original term.<BR>
3816
Consider for instance <TT>(@eq Type True True)</TT>. This term is
3817
printed as <TT>True=True</TT> and re-parsed as <TT>(@eq Prop True
3818
True)</TT>. The two terms are not convertible (hence they fool tactics
3819
like <TT>pattern</TT>).<BR>
3821
There is currently no satisfactory answer to the problem. However,
3822
the command <TT>Set Printing All</TT> is useful for diagnosing the
3825
Due to coercions, one may even face type-checking errors. In some
3826
rare cases, the criterion to hide coercions is a bit too loose, which
3827
may result in a typing error message if the parser is not able to find
3828
again the missing coercion.<BR>
3830
<!--TOC section Conclusion and Farewell.-->
3832
<H2><A NAME="htoc200">18</A> Conclusion and Farewell.</H2><!--SEC END -->
3835
<!--TOC subsubsection What if my question isn't answered here?-->
3837
<H4><A NAME="htoc201">174</A> What if my question isn't answered here?</H4><!--SEC END -->
3839
<A NAME="lastquestion"></A>
3840
Don't panic <CODE>:-)</CODE>. You can try the <FONT COLOR=navy>Coq</FONT> manual [<A HREF="#Coq:manual"><CITE>15</CITE></A>] for a technical
3841
description of the prover. The Coq'Art [<A HREF="#Coq:coqart"><CITE>1</CITE></A>] is the first
3842
book written on <FONT COLOR=navy>Coq</FONT> and provides a comprehensive review of the
3843
theorem prover as well as a number of example and exercises. Finally,
3844
the tutorial [<A HREF="#Coq:Tutorial"><CITE>14</CITE></A>] provides a smooth introduction to
3845
theorem proving in <FONT COLOR=navy>Coq</FONT>.<BR>
3849
<!--TOC section References-->
3851
<H2>References</H2><!--SEC END -->
3852
<DL COMPACT=compact><DT><A NAME="Coq:coqart"><FONT COLOR=purple>[1]</FONT></A><DD>
3853
Yves Bertot and Pierre Cast�ran.
3854
<EM>Interactive Theorem Proving and Program Development, Coq'Art:
3855
The Calculus of Inductive Constructions</EM>.
3856
Texts in Theoretical Computer Science. An EATCS series. Springer
3859
<DT><A NAME="boutin"><FONT COLOR=purple>[2]</FONT></A><DD>
3861
Using reflection to build efficient and certified decision pro
3863
In M. Abadi and T. Ito, editors, <EM>Proceedings of TACS'97</EM>, volume
3864
1281 of <EM>LNCS</EM>. Springer-Verlag, 1997.<BR>
3866
<DT><A NAME="LaTeX:symb"><FONT COLOR=purple>[3]</FONT></A><DD>
3867
David Carlisle, Scott Pakin, and Alexander Holt.
3868
<EM>The Great, Big List of L<sup>A</sup>T<sub>E</sub>X Symbols</EM>, February 2001.<BR>
3870
<DT><A NAME="Coq85"><FONT COLOR=purple>[4]</FONT></A><DD>
3872
<EM>Une Th�orie des Constructions</EM>.
3873
PhD thesis, Universit� Paris 7, January 1985.<BR>
3875
<DT><A NAME="CoHu86"><FONT COLOR=purple>[5]</FONT></A><DD>
3876
Thierry Coquand and G�rard Huet.
3877
The Calculus of Constructions.
3878
<EM>Information and Computation</EM>, 76(2/3), 1988.<BR>
3880
<DT><A NAME="CoPa89"><FONT COLOR=purple>[6]</FONT></A><DD>
3881
Thierry Coquand and Christine Paulin-Mohring.
3882
Inductively defined types.
3883
In P. Martin-L�f and G. Mints, editors, <EM>Proceedings of
3884
Colog'88</EM>, volume 417 of <EM>Lecture Notes in Computer Science</EM>.
3885
Springer-Verlag, 1990.<BR>
3887
<DT><A NAME="Types:Dowek"><FONT COLOR=purple>[7]</FONT></A><DD>
3890
Lecture notes, 2002.<BR>
3892
<DT><A NAME="EGThese"><FONT COLOR=purple>[8]</FONT></A><DD>
3894
<EM>Un Calcul de Constructions Infinies et son application a la
3895
v�rification de syst�mes communicants</EM>.
3896
th�se d'universit�, Ecole Normale Sup�rieure de Lyon, December 1996.<BR>
3898
<DT><A NAME="Gir70"><FONT COLOR=purple>[9]</FONT></A><DD>
3900
Une extension de l'interpr�tation de G�del � l'analyse, et
3901
son application � l'�limination des coupures dans l'analyse et la
3903
In <EM>Proceedings of the 2nd Scandinavian Logic Symposium</EM>.
3904
North-Holland, 1970.<BR>
3906
<DT><A NAME="ProofsTypes"><FONT COLOR=purple>[10]</FONT></A><DD>
3907
Jean-Yves Girard, Yves Lafont, and Paul Taylor.
3908
<EM>Proofs and Types</EM>.
3909
Cambrige Tracts in Theoretical Computer Science, Cambridge University
3912
<DT><A NAME="harrison"><FONT COLOR=purple>[11]</FONT></A><DD>
3914
Meta theory and reflection in theorem proving:a survey and cri tique.
3915
Technical Report CRC-053, SRI International Cambridge Computer
3916
Science Research Center, 1995.<BR>
3918
<DT><A NAME="HofStr98"><FONT COLOR=purple>[12]</FONT></A><DD>
3919
Martin Hofmann and Thomas Streicher.
3920
The groupoid interpretation of type theory.
3921
In <EM>Proceedings of the meeting Twenty-five years of constructive
3922
type theory</EM>. Oxford University Press, 1998.<BR>
3924
<DT><A NAME="howe"><FONT COLOR=purple>[13]</FONT></A><DD>
3926
Computation meta theory in nuprl.
3927
In E. Lusk and R. Overbeek, editors, <EM>The Proceedings of the
3928
Ninth International Conference of Autom ated Deduction</EM>, volume 310, pages
3929
238--257. Springer-Verlag, 1988.<BR>
3931
<DT><A NAME="Coq:Tutorial"><FONT COLOR=purple>[14]</FONT></A><DD>
3932
G�rard Huet, Gilles Kahn, and Christine Paulin-Mohring.
3933
<EM>The Coq Proof Assistant A Tutorial</EM>, 2004.<BR>
3935
<DT><A NAME="Coq:manual"><FONT COLOR=purple>[15]</FONT></A><DD>
3936
The Coq development team.
3937
<EM>The Coq proof assistant reference manual</EM>.
3938
LogiCal Project, 2004.
3941
<DT><A NAME="LaTeX:intro"><FONT COLOR=purple>[16]</FONT></A><DD>
3943
<EM>The Not So Short Introduction to L<sup>A</sup>T<sub>E</sub>X2e</EM>, January 1999.<BR>
3945
<DT><A NAME="Pau96b"><FONT COLOR=purple>[17]</FONT></A><DD>
3946
Christine Paulin-Mohring.
3947
<EM>D�finitions Inductives en Th�orie des Types d'Ordre Sup�rieur</EM>.
3948
Habilitation � diriger les recherches, Universit� Claude Bernard Lyon
3949
I, December 1996.</DL>
3959
<BLOCKQUOTE><EM>This document was translated from L<sup>A</sup>T<sub>E</sub>X by
3960
</EM><A HREF="http://pauillac.inria.fr/~maranget/hevea/index.html"><EM>H<FONT SIZE=2><sup>E</sup></FONT>V<FONT SIZE=2><sup>E</sup></FONT>A</EM></A><EM>.