~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to doc/tools/Translator.tex

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\ifx\pdfoutput\undefined   % si on est pas en pdflatex
 
2
\documentclass[11pt,a4paper]{article}
 
3
\else
 
4
\documentclass[11pt,a4paper,pdftex]{article}
 
5
\fi
 
6
\usepackage[latin1]{inputenc}
 
7
\usepackage[T1]{fontenc}
 
8
\usepackage{pslatex}
 
9
\usepackage{url}
 
10
\usepackage{verbatim}
 
11
\usepackage{amsmath}
 
12
\usepackage{amssymb}
 
13
\usepackage{array}
 
14
\usepackage{fullpage}
 
15
 
 
16
\title{Translation from Coq V7 to V8}
 
17
\author{The Coq Development Team}
 
18
 
 
19
%% Macros etc.
 
20
\catcode`\_=13
 
21
\let\subscr=_
 
22
\def_{\ifmmode\sb\else\subscr\fi}
 
23
 
 
24
\def\NT#1{\langle\textit{#1}\rangle}
 
25
\def\NTL#1#2{\langle\textit{#1}\rangle_{#2}}
 
26
%\def\TERM#1{\textsf{\bf #1}}
 
27
\def\TERM#1{\texttt{#1}}
 
28
\newenvironment{transbox}
 
29
  {\begin{center}\tt\begin{tabular}{l|ll} \hfil\textrm{V7} & \hfil\textrm{V8} \\ \hline}
 
30
  {\end{tabular}\end{center}}
 
31
\def\TRANS#1#2
 
32
  {\begin{tabular}[t]{@{}l@{}}#1\end{tabular} & 
 
33
   \begin{tabular}[t]{@{}l@{}}#2\end{tabular} \\}
 
34
\def\TRANSCOM#1#2#3
 
35
  {\begin{tabular}[t]{@{}l@{}}#1\end{tabular} & 
 
36
   \begin{tabular}[t]{@{}l@{}}#2\end{tabular} & #3 \\}
 
37
 
 
38
%%
 
39
%%
 
40
%%
 
41
\begin{document}
 
42
\maketitle
 
43
 
 
44
\section{Introduction}
 
45
 
 
46
Coq version 8.0 is a major version and carries major changes: the
 
47
concrete syntax was redesigned almost from scratch, and many notions
 
48
of the libraries were renamed for uniformisation purposes. We felt
 
49
that these changes could discourage users with large theories from
 
50
switching to the new version.
 
51
 
 
52
The goal of this document is to introduce these changes on simple
 
53
examples (mainly the syntactic changes), and describe the automated
 
54
tools to help moving to V8.0. Essentially, it consists of a translator
 
55
that takes as input a Coq source file in old syntax and produces a
 
56
file in new syntax and adapted to the new standard library. The main
 
57
extra features of this translator is that it keeps comments, even
 
58
those within expressions\footnote{The position of those comment might
 
59
differ slightly since there is no exact matching of positions between
 
60
old and new syntax.}.
 
61
 
 
62
The document is organised as follows: first section describes the new
 
63
syntax on simple examples. It is very translation-oriented. This
 
64
should give users of older versions the flavour of the new syntax, and
 
65
allow them to make translation manually on small
 
66
examples. Section~\ref{Translation} explains how the translation
 
67
process can be automatised for the most part (the boring one: applying
 
68
similar changes over thousands of lines of code). We strongly advise
 
69
users to follow these indications, in order to avoid many potential
 
70
complications of the translation process.
 
71
 
 
72
 
 
73
\section{The new syntax on examples}
 
74
 
 
75
The goal of this section is to introduce to the new syntax of Coq on
 
76
simple examples, rather than just giving the new grammar. It is
 
77
strongly recommended to read first the definition of the new syntax
 
78
(in the reference manual), but this document should also be useful for
 
79
the eager user who wants to start with the new syntax quickly.
 
80
 
 
81
The toplevel has an option {\tt -translate} which allows to
 
82
interactively translate commands. This toplevel translator accepts a
 
83
command, prints the translation on standard output (after a %
 
84
\verb+New syntax:+ balise), executes the command, and waits for another
 
85
command. The only requirements is that they should be syntactically
 
86
correct, but they do not have to be well-typed.
 
87
 
 
88
This interactive translator proved to be useful in two main
 
89
usages. First as a ``debugger'' of the translation. Before the
 
90
translation, it may help in spotting possible conflicts between the
 
91
new syntax and user notations. Or when the translation fails for some
 
92
reason, it makes it easy to find the exact reason why it failed and
 
93
make attempts in fixing the problem.
 
94
 
 
95
The second usage of the translator is when trying to make the first
 
96
proofs in new syntax. Well trained users will automatically think
 
97
their scripts in old syntax and might waste much time (and the
 
98
intuition of the proof) if they have to search the translation in a
 
99
document. Running a translator in the background will allow the user
 
100
to instantly have the answer.
 
101
 
 
102
The rest of this section is a description of all the aspects of the
 
103
syntax that changed and how they were translated. All the examples
 
104
below can be tested by entering the V7 commands in the toplevel
 
105
translator.
 
106
 
 
107
 
 
108
%%
 
109
 
 
110
\subsection{Changes in lexical conventions w.r.t. V7}
 
111
 
 
112
\subsubsection{Identifiers}
 
113
 
 
114
The lexical conventions changed: \TERM{_} is not a regular identifier
 
115
anymore. It is used in terms as a placeholder for subterms to be inferred
 
116
at type-checking, and in patterns as a non-binding variable.
 
117
 
 
118
Furthermore, only letters (Unicode letters), digits, single quotes and
 
119
_ are allowed after the first character.
 
120
 
 
121
\subsubsection{Quoted string}
 
122
 
 
123
Quoted strings are used typically to give a filename (which may not
 
124
be a regular identifier). As before they are written between double
 
125
quotes ("). Unlike for V7, there is no escape character: characters
 
126
are written normally except the double quote which is doubled.
 
127
 
 
128
\begin{transbox}
 
129
\TRANS{"abcd$\backslash\backslash$efg"}{"abcd$\backslash$efg"}
 
130
\TRANS{"abcd$\backslash$"efg"}{"abcd""efg"}
 
131
\end{transbox}
 
132
 
 
133
 
 
134
\subsection{Main changes in terms w.r.t. V7}
 
135
 
 
136
 
 
137
\subsubsection{Precedence of application}
 
138
 
 
139
In the new syntax, parentheses are not really part of the syntax of
 
140
application. The precedence of application (10) is tighter than all
 
141
prefix and infix notations. It makes it possible to remove parentheses
 
142
in many contexts.
 
143
 
 
144
\begin{transbox}
 
145
\TRANS{(A x)->(f x)=(g y)}{A x -> f x = g y}
 
146
\TRANS{(f [x]x)}{f (fun x => x)}
 
147
\end{transbox}
 
148
 
 
149
 
 
150
\subsubsection{Arithmetics and scopes}
 
151
 
 
152
The specialized notation for \TERM{Z} and \TERM{R} (introduced by
 
153
symbols \TERM{`} and \TERM{``}) have disappeared. They have been
 
154
replaced by the general notion of scope.
 
155
 
 
156
\begin{center}
 
157
\begin{tabular}{l|l|l}
 
158
type & scope name & delimiter \\
 
159
\hline
 
160
types & type_scope & \TERM{type} \\
 
161
\TERM{bool} & bool_scope & \\
 
162
\TERM{nat} & nat_scope & \TERM{nat} \\
 
163
\TERM{Z} & Z_scope & \TERM{Z} \\
 
164
\TERM{R} & R_scope & \TERM{R} \\
 
165
\TERM{positive} & positive_scope & \TERM{P}
 
166
\end{tabular}
 
167
\end{center}
 
168
 
 
169
In order to use notations of arithmetics on \TERM{Z}, its scope must
 
170
be opened with command \verb+Open Scope Z_scope.+ Another possibility
 
171
is using the scope change notation (\TERM{\%}). The latter notation is
 
172
to be used when notations of several scopes appear in the same
 
173
expression.
 
174
 
 
175
In examples below, scope changes are not needed if the appropriate scope
 
176
has been opened. Scope \verb|nat_scope| is opened in the initial state of Coq.
 
177
\begin{transbox}
 
178
\TRANSCOM{`0+x=x+0`}{0+x=x+0}{\textrm{Z_scope}}
 
179
\TRANSCOM{``0 + [if b then ``1`` else ``2``]``}{0 + if b then 1 else 2}{\textrm{R_scope}}
 
180
\TRANSCOM{(0)}{0}{\textrm{nat_scope}}
 
181
\end{transbox}
 
182
 
 
183
Below is a table that tells which notation is available in which
 
184
scope. The relative precedences and associativity of operators is the
 
185
same as in usual mathematics. See the reference manual for more
 
186
details. However, it is important to remember that unlike V7, the type
 
187
operators for product and sum are left-associative, in order not to
 
188
clash with arithmetic operators.
 
189
 
 
190
\begin{center}
 
191
\begin{tabular}{l|l}
 
192
scope & notations \\
 
193
\hline
 
194
nat_scope & \texttt{+ - * < <= > >=} \\
 
195
Z_scope & \texttt{+ - * / mod < <= > >= ?=} \\
 
196
R_scope & \texttt{+ - * / < <= > >=} \\
 
197
type_scope & \texttt{* +} \\
 
198
bool_scope & \texttt{\&\& || -} \\
 
199
list_scope & \texttt{:: ++}
 
200
\end{tabular}
 
201
\end{center}
 
202
 
 
203
 
 
204
 
 
205
\subsubsection{Notation for implicit arguments}
 
206
 
 
207
The explicitation of arguments is closer to the \emph{bindings}
 
208
notation in tactics. Argument positions follow the argument names of
 
209
the head constant. The example below assumes \verb+f+ is a function
 
210
with two implicit dependent arguments named \verb+x+ and \verb+y+.
 
211
\begin{transbox}
 
212
\TRANS{f 1!t1 2!t2 t3}{f (x:=t1) (y:=t2) t3}
 
213
\TRANS{!f t1 t2}{@f t1 t2}
 
214
\end{transbox}
 
215
 
 
216
 
 
217
\subsubsection{Inferred subterms}
 
218
 
 
219
Subterms that can be automatically inferred by the type-checker is now
 
220
written {\tt _}
 
221
 
 
222
\begin{transbox}
 
223
\TRANS{?}{_}
 
224
\end{transbox}
 
225
 
 
226
\subsubsection{Universal quantification}
 
227
 
 
228
The universal quantification and dependent product types are now
 
229
introduced by the \texttt{forall} keyword before the binders and a
 
230
comma after the binders.
 
231
 
 
232
The syntax of binders also changed significantly. A binder can simply be
 
233
a name when its type can be inferred. In other cases, the name and the type
 
234
of the variable are put between parentheses. When several consecutive
 
235
variables have the same type, they can be grouped. Finally, if all variables
 
236
have the same type, parentheses can be omitted.
 
237
 
 
238
\begin{transbox}
 
239
\TRANS{(x:A)B}{forall (x:~A), B ~~\textrm{or}~~ forall x:~A, B}
 
240
\TRANS{(x,y:nat)P}{forall (x y :~nat), P ~~\textrm{or}~~ forall x y :~nat, P}
 
241
\TRANS{(x,y:nat;z:A)P}{forall (x y :~nat) (z:A), P}
 
242
\TRANS{(x,y,z,t:?)P}{forall x y z t, P}
 
243
\TRANS{(x,y:nat;z:?)P}{forall (x y :~nat) z, P}
 
244
\end{transbox}
 
245
 
 
246
\subsubsection{Abstraction}
 
247
 
 
248
The notation for $\lambda$-abstraction follows that of universal
 
249
quantification. The binders are surrounded by keyword \texttt{fun}
 
250
and \verb+=>+.
 
251
 
 
252
\begin{transbox}
 
253
\TRANS{[x,y:nat; z](f a b c)}{fun (x y:nat) z => f a b c}
 
254
\end{transbox}
 
255
 
 
256
 
 
257
\subsubsection{Pattern-matching}
 
258
 
 
259
Beside the usage of the keyword pair \TERM{match}/\TERM{with} instead of
 
260
\TERM{Cases}/\TERM{of}, the main change is the notation for the type of
 
261
branches and return type. It is no longer written between \TERM{$<$ $>$} before
 
262
the \TERM{Cases} keyword, but interleaved with the destructured objects.
 
263
 
 
264
The idea is that for each destructured object, one may specify a
 
265
variable name (after the \TERM{as} keyword) to tell how the branches
 
266
types depend on this destructured objects (case of a dependent
 
267
elimination), and also how they depend on the value of the arguments
 
268
of the inductive type of the destructured objects (after the \TERM{in}
 
269
keyword). The type of branches is then given after the keyword
 
270
\TERM{return}, unless it can be inferred.
 
271
 
 
272
Moreover, when the destructured object is a variable, one may use this
 
273
variable in the return type.
 
274
 
 
275
\begin{transbox}
 
276
\TRANS{Cases n of\\~~ O => O \\| (S k) => (1) end}{match n with\\~~ 0 => 0 \\| S k => 1 end}
 
277
\TRANS{Cases m n of \\~~0 0 => t \\| ... end}{match m, n with \\~~0, 0 => t \\| ... end}
 
278
\TRANS{<[n:nat](P n)>Cases T of ... end}{match T as n return P n with ... end}
 
279
\TRANS{<[n:nat][p:(even n)]\~{}(odd n)>Cases p of\\~~ ... \\end}{match p in even n return \~{} odd n with\\~~ ...\\end}
 
280
\end{transbox}
 
281
 
 
282
The annotations of the special pattern-matching operators
 
283
(\TERM{if}/\TERM{then}/\TERM{else}) and \TERM{let()} also changed. The
 
284
only restriction is that the destructuring \TERM{let} does not allow
 
285
dependent case analysis.
 
286
 
 
287
\begin{transbox}
 
288
\TRANS{
 
289
 \begin{tabular}{@{}l}
 
290
 <[n:nat;x:(I n)](P n x)>if t then t1 \\
 
291
 else t2
 
292
 \end{tabular}}%
 
293
{\begin{tabular}{@{}l}
 
294
 if t as x in I n return P n x then t1 \\
 
295
 else t2
 
296
 \end{tabular}}
 
297
\TRANS{<[n:nat](P n)>let (p,q) = t1 in t2}%
 
298
{let (p,q) in I n return P n := t1 in t2}
 
299
\end{transbox}
 
300
 
 
301
 
 
302
\subsubsection{Fixpoints and cofixpoints}
 
303
 
 
304
An simpler syntax for non-mutual fixpoints is provided, making it very close
 
305
to the usual notation for non-recursive functions. The decreasing argument
 
306
is now indicated by an annotation between curly braces, regardless of the
 
307
binders grouping. The annotation can be omitted if the binders introduce only
 
308
one variable. The type of the result can be omitted if inferable.
 
309
 
 
310
\begin{transbox}
 
311
\TRANS{Fix plus\{plus [n:nat] : nat -> nat :=\\~~ [m]...\}}{fix plus (n m:nat) \{struct n\}: nat := ...}
 
312
\TRANS{Fix fact\{fact [n:nat]: nat :=\\
 
313
~~Cases n of\\~~~~ O => (1) \\~~| (S k) => (mult n (fact k)) end\}}{fix fact
 
314
  (n:nat) :=\\
 
315
~~match n with \\~~~~0 => 1 \\~~| (S k) => n * fact k end}
 
316
\end{transbox}
 
317
 
 
318
There is a syntactic sugar for single fixpoints (defining one
 
319
variable) associated to a local definition:
 
320
 
 
321
\begin{transbox}
 
322
\TRANS{let f := Fix f \{f [x:A] : T := M\} in\\(g (f y))}{let fix f (x:A) : T := M in\\g (f x)}
 
323
\end{transbox}
 
324
 
 
325
The same applies to cofixpoints, annotations are not allowed in that case.
 
326
 
 
327
\subsubsection{Notation for type cast}
 
328
 
 
329
\begin{transbox}
 
330
\TRANS{O :: nat}{0 : nat}
 
331
\end{transbox}
 
332
 
 
333
\subsection{Main changes in tactics w.r.t. V7}
 
334
 
 
335
The main change is that all tactic names are lowercase. This also holds for
 
336
Ltac keywords.
 
337
 
 
338
\subsubsection{Renaming of induction tactics}
 
339
 
 
340
\begin{transbox}
 
341
\TRANS{NewDestruct}{destruct}
 
342
\TRANS{NewInduction}{induction}
 
343
\TRANS{Induction}{simple induction}
 
344
\TRANS{Destruct}{simple destruct}
 
345
\end{transbox}
 
346
 
 
347
\subsubsection{Ltac}
 
348
 
 
349
Definitions of macros are introduced by \TERM{Ltac} instead of
 
350
\TERM{Tactic Definition}, \TERM{Meta Definition} or \TERM{Recursive
 
351
Definition}. They are considered recursive by default.
 
352
 
 
353
\begin{transbox}
 
354
\TRANS{Meta Definition my_tac t1 t2 := t1; t2.}%
 
355
{Ltac my_tac t1 t2 := t1; t2.}
 
356
\end{transbox}
 
357
 
 
358
Rules of a match command are not between square brackets anymore.
 
359
 
 
360
Context (understand a term with a placeholder) instantiation \TERM{inst}
 
361
became \TERM{context}. Syntax is unified with subterm matching.
 
362
 
 
363
\begin{transbox}
 
364
\TRANS{Match t With [C[x=y]] -> Inst C[y=x]}%
 
365
{match t with context C[x=y] => context C[y=x] end}
 
366
\end{transbox}
 
367
 
 
368
Arguments of macros use the term syntax. If a general Ltac expression
 
369
is to be passed, it must be prefixed with ``{\tt ltac :}''. In other
 
370
cases, when a \'{} was necessary, it is replaced by ``{\tt constr :}''
 
371
 
 
372
\begin{transbox}
 
373
\TRANS{my_tac '(S x)}{my_tac (S x)}
 
374
\TRANS{my_tac (Let x=tac In x)}{my_tac ltac:(let x:=tac in x)}
 
375
\TRANS{Let x = '[x](S (S x)) In Apply x}%
 
376
{let x := constr:(fun x => S (S x)) in apply x}
 
377
\end{transbox}
 
378
 
 
379
{\tt Match Context With} is now called {\tt match goal with}. Its
 
380
argument is an Ltac expression by default.
 
381
 
 
382
 
 
383
\subsubsection{Named arguments of theorems ({\em bindings})}
 
384
 
 
385
\begin{transbox}
 
386
\TRANS{Apply thm with x:=t 1:=u}{apply thm with (x:=t) (1:=u)}
 
387
\end{transbox}
 
388
 
 
389
 
 
390
\subsubsection{Occurrences}
 
391
 
 
392
To avoid ambiguity between a numeric literal and the optional
 
393
occurrence numbers of this term, the occurrence numbers are put after
 
394
the term itself and after keyword \TERM{as}.
 
395
\begin{transbox}
 
396
\TRANS{Pattern 1 2 (f x) 3 4 d y z}{pattern f x at 1 2, d at 3 4, y, z}
 
397
\end{transbox}
 
398
 
 
399
 
 
400
\subsubsection{{\tt LetTac} and {\tt Pose}}
 
401
 
 
402
Tactic {\tt LetTac} was renamed into {\tt set}, and tactic {\tt Pose}
 
403
was a particular case of {\tt LetTac} where the abbreviation is folded
 
404
in the conclusion\footnote{There is a tactic called {\tt pose} in V8,
 
405
but its behaviour is not to fold the abbreviation at all.}.
 
406
 
 
407
\begin{transbox}
 
408
\TRANS{LetTac x = t in H}{set (x := t) in H}
 
409
\TRANS{Pose x := t}{set (x := t)}
 
410
\end{transbox}
 
411
 
 
412
{\tt LetTac} could be followed by a specification (called a clause) of
 
413
the places where the abbreviation had to be folded (hypothese and/or
 
414
conclusion). Clauses are the syntactic notion to denote in which parts
 
415
of a goal a given transformation shold occur. Its basic notation is
 
416
either \TERM{*} (meaning everywhere), or {\tt\textrm{\em hyps} |-
 
417
\textrm{\em concl}} where {\em hyps} is either \TERM{*} (to denote all
 
418
the hypotheses), or a comma-separated list of either hypothesis name,
 
419
or {\tt (value of $H$)} or {\tt (type of $H$)}. Moreover, occurrences
 
420
can be specified after every hypothesis after the {\TERM{at}}
 
421
keyword. {\em concl} is either empty or \TERM{*}, and can be followed
 
422
by occurences.
 
423
 
 
424
\begin{transbox}
 
425
\TRANS{in Goal}{in |- *}
 
426
\TRANS{in H H1}{in H1, H2 |-}
 
427
\TRANS{in H H1 ...}{in * |-}
 
428
\TRANS{in H H1 Goal}{in H1, H2 |- *}
 
429
\TRANS{in H H1 H2 ... Goal}{in *}
 
430
\TRANS{in 1 2 H 3 4 H0 1 3 Goal}{in H at 1 2, H0 at 3 4 |- * at 1 3}
 
431
\end{transbox}
 
432
 
 
433
\subsection{Main changes in vernacular commands w.r.t. V7}
 
434
 
 
435
 
 
436
\subsubsection{Require}
 
437
 
 
438
The default behaviour of {\tt Require} is not to open the loaded
 
439
module.
 
440
 
 
441
\begin{transbox}
 
442
\TRANS{Require Arith}{Require Import Arith}
 
443
\end{transbox}
 
444
 
 
445
\subsubsection{Binders}
 
446
 
 
447
The binders of vernacular commands changed in the same way as those of
 
448
fixpoints. This also holds for parameters of inductive definitions.
 
449
 
 
450
 
 
451
\begin{transbox}
 
452
\TRANS{Definition x [a:A] : T := M}{Definition x (a:A) : T := M}
 
453
\TRANS{Inductive and [A,B:Prop]: Prop := \\~~conj : A->B->(and A B)}%
 
454
      {Inductive and (A B:Prop): Prop := \\~~conj : A -> B -> and A B}
 
455
\end{transbox}
 
456
 
 
457
\subsubsection{Hints}
 
458
 
 
459
Both {\tt Hints} and {\tt Hint} commands are beginning with {\tt Hint}.
 
460
 
 
461
Command {\tt HintDestruct} has disappeared.
 
462
 
 
463
 
 
464
The syntax of \emph{Extern} hints changed: the pattern and the tactic
 
465
to be applied are separated by a {\tt =>}.
 
466
\begin{transbox}
 
467
\TRANS{Hint name := Resolve (f ? x)}%
 
468
{Hint Resolve (f _ x)}
 
469
\TRANS{Hint name := Extern 4 (toto ?) Apply lemma}%
 
470
{Hint Extern 4 (toto _) => apply lemma}
 
471
\TRANS{Hints Resolve x y z}{Hint Resolve x y z}
 
472
\TRANS{Hints Resolve f : db1 db2}{Hint Resolve f : db1 db2}
 
473
\TRANS{Hints Immediate x y z}{Hint Immediate x y z}
 
474
\TRANS{Hints Unfold x y z}{Hint Unfold x y z}
 
475
%% \TRANS{\begin{tabular}{@{}l}
 
476
%%   HintDestruct Local Conclusion \\
 
477
%%   ~~name (f ? ?) 3 [Apply thm]
 
478
%%   \end{tabular}}%
 
479
%% {\begin{tabular}{@{}l}
 
480
%%  Hint Local Destuct name := \\
 
481
%%  ~~3 Conclusion (f _ _) => apply thm
 
482
%%  \end{tabular}}
 
483
\end{transbox}
 
484
 
 
485
 
 
486
\subsubsection{Implicit arguments}
 
487
 
 
488
 
 
489
{\tt Set Implicit Arguments} changed its meaning in V8: the default is
 
490
to turn implicit only the arguments that are {\em strictly} implicit
 
491
(or rigid), i.e. that remains inferable whatever the other arguments
 
492
are. For instance {\tt x} inferable from {\tt P x} is not strictly
 
493
inferable since it can disappears if {\tt P} is instanciated by a term
 
494
which erases {\tt x}.
 
495
 
 
496
\begin{transbox}
 
497
\TRANS{Set Implicit Arguments}%
 
498
{\begin{tabular}{l}
 
499
 Set Implicit Arguments. \\
 
500
 Unset Strict Implicits.
 
501
 \end{tabular}}
 
502
\end{transbox}
 
503
 
 
504
However, you may wish to adopt the new semantics of {\tt Set Implicit
 
505
Arguments} (for instance because you think that the choice of
 
506
arguments it sets implicit is more ``natural'' for you).
 
507
 
 
508
 
 
509
\subsection{Changes in standard library}
 
510
 
 
511
Many lemmas had their named changed to improve uniformity. The user
 
512
generally do not have to care since the translators performs the
 
513
renaming.
 
514
 
 
515
  Type {\tt entier} from fast_integer.v is renamed into {\tt N} by the
 
516
translator. As a consequence, user-defined objects of same name {\tt N}
 
517
are systematically qualified even tough it may not be necessary.  The
 
518
following table lists the main names with which the same problem
 
519
arises:
 
520
\begin{transbox}
 
521
\TRANS{IF}{IF_then_else}
 
522
\TRANS{ZERO}{Z0}
 
523
\TRANS{POS}{Zpos}
 
524
\TRANS{NEG}{Zneg}
 
525
\TRANS{SUPERIEUR}{Gt}
 
526
\TRANS{EGAL}{Eq}
 
527
\TRANS{INFERIEUR}{Lt}
 
528
\TRANS{add}{Pplus}
 
529
\TRANS{true_sub}{Pminus}
 
530
\TRANS{entier}{N}
 
531
\TRANS{Un_suivi_de}{Ndouble_plus_one}
 
532
\TRANS{Zero_suivi_de}{Ndouble}
 
533
\TRANS{Nul}{N0}
 
534
\TRANS{Pos}{Npos}
 
535
\end{transbox}
 
536
 
 
537
 
 
538
\subsubsection{Implicit arguments}
 
539
 
 
540
%% Hugo: 
 
541
Main definitions of standard library have now implicit
 
542
arguments. These arguments are dropped in the translated files. This
 
543
can exceptionally be a source of incompatibilities which has to be
 
544
solved by hand (it typically happens for polymorphic functions applied
 
545
to {\tt nil} or {\tt None}).
 
546
%% preciser: avant ou apres trad ?
 
547
 
 
548
\subsubsection{Logic about {\tt Type}}
 
549
 
 
550
Many notations that applied to {\tt Set} have been extended to {\tt
 
551
Type}, so several definitions in {\tt Type} are superseded by them.
 
552
 
 
553
\begin{transbox}
 
554
\TRANS{x==y}{x=y}
 
555
\TRANS{(EXT x:Prop | Q)}{exists x:Prop, Q}
 
556
\TRANS{identityT}{identity}
 
557
\end{transbox}
 
558
 
 
559
 
 
560
 
 
561
%% Doc of the translator
 
562
\section{A guide to translation}
 
563
\label{Translation}
 
564
 
 
565
%%\subsection{Overview of the translation process}
 
566
 
 
567
Here is a short description of the tools involved in the translation process:
 
568
\begin{description}
 
569
\item{\tt coqc -translate}
 
570
is the automatic translator. It is a parser/pretty-printer. This means
 
571
that the translation is made by parsing every command using a parser
 
572
of old syntax, which is printed using the new syntax. Many efforts
 
573
were made to preserve as much as possible of the quality of the
 
574
presentation: it avoids expansion of syntax extensions, comments are
 
575
not discarded and placed at the same place.
 
576
\item{\tt translate-v8} (in the translation package) is a small
 
577
shell-script that will help translate developments that compile with a
 
578
Makefile with minimum requirements.
 
579
\end{description}
 
580
 
 
581
\subsection{Preparation to translation}
 
582
 
 
583
This step is very important because most of work shall be done before
 
584
translation. If a problem occurs during translation, it often means
 
585
that you will have to modify the original source and restart the
 
586
translation process. This also means that it is recommended not to
 
587
edit the output of the translator since it would be overwritten if
 
588
the translation has to be restarted.
 
589
 
 
590
\subsubsection{Compilation with {\tt coqc -v7}}
 
591
 
 
592
First of all, it is mandatory that files compile with the current
 
593
version of Coq (8.0) with option {\tt -v7}. Translation is a
 
594
complicated task that involves the full compilation of the
 
595
development. If your development was compiled with older versions,
 
596
first upgrade to Coq V8.0 with option {\tt -v7}. If you use a Makefile
 
597
similar to those produced by {\tt coq\_makefile}, you probably just
 
598
have to do
 
599
 
 
600
{\tt make OPT="-opt -v7"} ~~~or~~~ {\tt make OPT="-byte -v7"}
 
601
 
 
602
When the development compiles successfully, there are several changes
 
603
that might be necessary for the translation. Essentially, this is
 
604
about syntax extensions (see section below dedicated to porting syntax
 
605
extensions). If you do not use such features, then you are ready to
 
606
try and make the translation.
 
607
 
 
608
\subsection{Translation}
 
609
 
 
610
\subsubsection{The general case}
 
611
 
 
612
The preferred way is to use script {\tt translate-v8} if your development
 
613
is compiled by a Makefile with the following constraints:
 
614
\begin{itemize}
 
615
\item compilation is achieved by invoking make without specifying a target
 
616
\item options are passed to Coq with make variable COQFLAGS that
 
617
  includes variables OPT, COQLIBS, OTHERFLAGS and COQ_XML.
 
618
\end{itemize}
 
619
These constraints are met by the makefiles produced by {\tt coq\_makefile}
 
620
 
 
621
Otherwise, modify your build program so as to pass option {\tt
 
622
-translate} to program {\tt coqc}. The effect of this option is to
 
623
ouptut the translated source of any {\tt .v} file in a file with
 
624
extension {\tt .v8} located in the same directory than the original
 
625
file.
 
626
 
 
627
\subsubsection{What may happen during the translation}
 
628
 
 
629
This section describes events that may happen during the
 
630
translation and measures to adopt.
 
631
 
 
632
These are the warnings that may arise during the translation, but they
 
633
generally do not require any modification for the user:
 
634
Warnings:
 
635
\begin{itemize}
 
636
\item {\tt Unable to detect if $id$ denotes a local definition}\\
 
637
This is due to a semantic change in clauses. In a command such as {\tt
 
638
simpl in H}, the old semantics were to perform simplification in the
 
639
type of {\tt H}, or in its body if it is defined. With the new
 
640
semantics, it is performed both in the type and the body (if any). It
 
641
might lead to incompatibilities
 
642
 
 
643
\item {\tt Forgetting obsolete module}\\
 
644
Some modules have disappeared in V8.0 (new syntax). The user does not
 
645
need to worry about it, since the translator deals with it.
 
646
 
 
647
\item {\tt Replacing obsolete module}\\
 
648
Same as before but with the module that were renamed. Here again, the
 
649
translator deals with it.
 
650
\end{itemize}
 
651
 
 
652
\subsection{Verification of the translation}
 
653
 
 
654
The shell-script {\tt translate-v8} also renames {\tt .v8} files into
 
655
{\tt .v} files (older {\tt .v} files are put in a subdirectory called
 
656
{\tt v7}) and tries to recompile them. To do so it invokes {\tt make}
 
657
without option (which should cause the compilation using {\tt coqc}
 
658
without particular option).
 
659
 
 
660
If compilation fails at this stage, you should refrain from repairing
 
661
errors manually on the new syntax, but rather modify the old syntax
 
662
script and restart the translation. We insist on that because the
 
663
problem encountered can show up in many instances (especially if the
 
664
problem comes from a syntactic extension), and fixing the original
 
665
sources (for instance the {\tt V8only} parts of notations) once will
 
666
solve all occurrences of the problem.
 
667
 
 
668
%%\subsubsection{Errors occurring after translation}
 
669
%%Equality in {\tt Z} or {\tt R}...
 
670
 
 
671
\subsection{Particular cases}
 
672
 
 
673
\subsubsection{Lexical conventions}
 
674
 
 
675
The definition of identifiers changed. Most of those changes are
 
676
handled by the translator. They include:
 
677
\begin{itemize}
 
678
\item {\tt \_} is not an identifier anymore: it is tranlated to {\tt
 
679
x\_}
 
680
\item avoid clash with new keywords by adding a trailing {\tt \_}
 
681
\end{itemize}
 
682
 
 
683
If the choices made by translation is not satisfactory 
 
684
or in the following cases:
 
685
\begin{itemize}
 
686
\item use of latin letters
 
687
\item use of iso-latin characters in notations
 
688
\end{itemize}
 
689
the user should change his development prior to translation.
 
690
 
 
691
\subsubsection{{\tt Case} and {\tt Match}}
 
692
 
 
693
These very low-level case analysis are no longer supported. The
 
694
translator tries hard to translate them into a user-friendly one, but
 
695
it might lack type information to do so\footnote{The translator tries
 
696
to typecheck terms before printing them, but it is not always possible
 
697
to determine the context in which terms appearing in tactics
 
698
live.}. If this happens, it is preferable to transform it manually
 
699
before translation.
 
700
 
 
701
\subsubsection{Syntax extensions with {\tt Grammar} and {\tt Syntax}}
 
702
 
 
703
 
 
704
{\tt Grammar} and {\tt Syntax} are no longer supported. They
 
705
should be replaced by an equivalent {\tt Notation} command and be
 
706
processed as described above. Before attempting translation, users
 
707
should verify that compilation with option {\tt -v7} succeeds.
 
708
 
 
709
In the cases where {\tt Grammar} and {\tt Syntax} cannot be emulated
 
710
by {\tt Notation}, users have to change manually they development as
 
711
they wish to avoid the use of {\tt Grammar}. If this is not done, the
 
712
translator will simply expand the notations and the output of the
 
713
translator will use the regular Coq syntax.
 
714
 
 
715
\subsubsection{Syntax extensions with {\tt Notation} and {\tt Infix}}
 
716
 
 
717
These commands do not necessarily need to be changed.
 
718
 
 
719
Some work will have to be done manually if the notation conflicts with
 
720
the new syntax (for instance, using keywords like {\tt fun} or {\tt
 
721
exists}, overloading of symbols of the old syntax, etc.) or if the
 
722
precedences are not right.
 
723
 
 
724
  Precedence levels are now from 0 to 200. In V8, the precedence and
 
725
associativity of an operator cannot be redefined. Typical level are
 
726
(refer to the chapter on notations in the Reference Manual for the
 
727
full list):
 
728
 
 
729
\begin{center}
 
730
\begin{tabular}{|cll|}
 
731
\hline
 
732
Notation & Precedence & Associativity \\
 
733
\hline
 
734
\verb!_ <-> _! & 95 & no \\
 
735
\verb!_ \/ _!  & 85 & right \\
 
736
\verb!_ /\ _!  & 80 & right \\
 
737
\verb!~ _!   & 75 & right \\
 
738
\verb!_ = _!, \verb!_ <> _!, \verb!_ < _!, \verb!_ > _!,
 
739
  \verb!_ <= _!, \verb!_ >= _!   & 70 & no \\
 
740
\verb!_ + _!, \verb!_ - _!   & 50 & left \\
 
741
\verb!_ * _!, \verb!_ / _!   & 40 & left \\
 
742
\verb!- _!  & 35 & right \\
 
743
\verb!_ ^ _!   & 30 & left \\
 
744
\hline
 
745
\end{tabular}
 
746
\end{center}
 
747
 
 
748
 
 
749
  By default, the translator keeps the associativity given in V7 while
 
750
the levels are mapped according to the following table:
 
751
 
 
752
\begin{center}
 
753
\begin{tabular}{l|l|l}
 
754
V7 level & mapped to & associativity \\
 
755
\hline
 
756
0 & 0 & no \\
 
757
1 & 20 & left \\
 
758
2 & 30 & right \\
 
759
3 & 40 & left \\
 
760
4 & 50 & left \\
 
761
5 & 70 & no \\
 
762
6 & 80 & right \\
 
763
7 & 85 & right \\
 
764
8 & 90 & right \\
 
765
9 & 95 & no \\
 
766
10 & 100 & left
 
767
\end{tabular}
 
768
\end{center}
 
769
 
 
770
If this is OK, just simply apply the translator.
 
771
 
 
772
 
 
773
\paragraph{Associativity conflict}
 
774
 
 
775
  Since the associativity of the levels obtained by translating a V7
 
776
level (as shown on table above) cannot be changed, you have to choose
 
777
another level with a compatible associativity.
 
778
 
 
779
  You can choose any level between 0 and 200, knowing that the
 
780
standard operators are already set at the levels shown on the list
 
781
above. 
 
782
 
 
783
Assume you have a notation
 
784
\begin{verbatim}
 
785
Infix NONA 2 "=_S" my_setoid_eq.
 
786
\end{verbatim}
 
787
By default, the translator moves it to level 30 which is right
 
788
associative, hence a conflict with the expected no associativity.
 
789
 
 
790
To solve the problem, just add the "V8only" modifier to reset the
 
791
level and enforce the associativity as follows:
 
792
\begin{verbatim}
 
793
Infix NONA 2 "=_S" my_setoid_eq V8only (at level 70, no associativity).
 
794
\end{verbatim}
 
795
The translator now knows that it has to translate "=_S" at level 70
 
796
with no associativity.
 
797
 
 
798
Remark: 70 is the "natural" level for relations, hence the choice of 70
 
799
here, but any other level accepting a no-associativity would have been
 
800
OK.
 
801
 
 
802
Second example: assume you have a notation
 
803
\begin{verbatim}
 
804
Infix RIGHTA 1 "o" my_comp.
 
805
\end{verbatim}
 
806
By default, the translator moves it to level 20 which is left
 
807
associative, hence a conflict with the expected right associativity.
 
808
 
 
809
To solve the problem, just add the "V8only" modifier to reset the
 
810
level and enforce the associativity as follows:
 
811
\begin{verbatim}
 
812
Infix RIGHTA 1 "o" my_comp V8only (at level 20, right associativity).
 
813
\end{verbatim}
 
814
The translator now knows that it has to translate "o" at level 20
 
815
which has the correct "right associativity".
 
816
 
 
817
Remark: we assumed here that the user wants a strong precedence for
 
818
composition, in such a way, say, that "f o g + h" is parsed as
 
819
"(f o g) + h". To get "o" binding less than the arithmetical operators,
 
820
an appropriated level would have been close of 70, and below, e.g. 65.
 
821
 
 
822
 
 
823
\paragraph{Conflict: notation hides another notation}
 
824
 
 
825
Remark: use {\tt Print Grammar constr} in V8 to diagnose the overlap
 
826
and see the section on factorization in the chapter on notations of
 
827
the Reference Manual for hints on how to factorize.
 
828
 
 
829
Example:
 
830
\begin{verbatim}
 
831
Notation "{ x }" := (my_embedding x) (at level 1).
 
832
\end{verbatim}
 
833
overlaps in V8 with notation \verb#{ x : A & P }# at level 0 and with
 
834
x at level 99. The conflicts can be solved by left-factorizing the
 
835
notation as follows:
 
836
\begin{verbatim}
 
837
Notation "{ x }" := (my_embedding x) (at level 1)
 
838
  V8only (at level 0, x at level 99).
 
839
\end{verbatim}
 
840
 
 
841
\paragraph{Conflict: a notation conflicts with the V8 grammar}
 
842
 
 
843
Again, use the {\tt V8only} modifier to tell the translator to
 
844
automatically take in charge the new syntax.
 
845
 
 
846
Example:
 
847
\begin{verbatim}
 
848
Infix 3 "@" app.
 
849
\end{verbatim}
 
850
Since {\tt @} is used in the new syntax for deactivating the implicit
 
851
arguments, another symbol has to be used, e.g. {\tt @@}. This is done via
 
852
the {\tt V8only} option as follows:
 
853
\begin{verbatim}
 
854
Infix 3 "@" app V8only "@@" (at level 40, left associativity).
 
855
\end{verbatim}
 
856
or, alternatively by
 
857
\begin{verbatim}
 
858
Notation "x @ y" := (app x y) (at level 3, left associativity)
 
859
  V8only "x @@ y" (at level 40, left associativity).
 
860
\end{verbatim}
 
861
 
 
862
\paragraph{Conflict: my notation is already defined at another level
 
863
  (or with another associativity)}
 
864
 
 
865
In V8, the level and associativity of a given notation can no longer
 
866
be changed. Then, either you adopt the standard reserved levels and
 
867
associativity for this notation (as given on the list above) or you
 
868
change your notation.
 
869
\begin{itemize}
 
870
\item To change the notation, follow the directions in the previous
 
871
paragraph
 
872
\item To adopt the standard level, just use {\tt V8only} without any
 
873
argument.
 
874
\end{itemize}
 
875
 
 
876
Example:
 
877
\begin{verbatim}
 
878
Infix 6 "*" my_mult.
 
879
\end{verbatim}
 
880
is not accepted as such in V8. Write
 
881
\begin{verbatim}
 
882
Infix 6 "*" my_mult V8only.
 
883
\end{verbatim}
 
884
to tell the translator to use {\tt *} at the reserved level (i.e. 40
 
885
with left associativity). Even better, use interpretation scopes (look
 
886
at the Reference Manual).
 
887
 
 
888
 
 
889
\subsubsection{Strict implicit arguments}
 
890
 
 
891
In the case you want to adopt the new semantics of {\tt Set Implicit
 
892
 Arguments} (only setting rigid arguments as implicit), add the option
 
893
{\tt -strict-implicit} to the translator.
 
894
 
 
895
Warning: changing the number of implicit arguments can break the
 
896
notations.  Then use the {\tt V8only} modifier of {\tt Notation}.
 
897
 
 
898
\end{document}