]> matita.cs.unibo.it Git - helm.git/blob - helm/papers/calculemus-2003/hbugs-calculemus-2003.tex
- Introduction changed.
[helm.git] / helm / papers / calculemus-2003 / hbugs-calculemus-2003.tex
1 \documentclass[runningheads]{llncs}
2 \pagestyle{headings}
3 \setcounter{page}{1}
4 \usepackage{graphicx}
5 \usepackage{amsfonts}
6
7 % \myincludegraphics{filename}{place}{width}{caption}{label}
8 \newcommand{\myincludegraphics}[5]{
9    \begin{figure}[#2]
10    \begin{center}
11    \includegraphics[width=#3]{XFIG-EPS/#1.eps}
12    \caption[#4]{#5}
13    \label{#1}
14    \end{center}
15    \end{figure}
16 }
17
18 \usepackage[show]{ed}
19 \usepackage{draftstamp}
20
21 \newcommand{\ws}{Web-Service}
22 \newcommand{\wss}{Web-Services}
23 \newcommand{\hbugs}{H-Bugs}
24 \newcommand{\helm}{HELM}
25
26 \title{Brokers and Web-Services for Automatic Deduction: a Case Study}
27
28 \author{Claudio Sacerdoti Coen \and Stefano Zacchiroli}
29
30 \institute{
31   Department of Computer Science\\
32   University of Bologna\\
33   Via di Mura Anteo Zamboni 7, 40127 Bologna, ITALY\\
34   \email{sacerdot@cs.unibo.it}
35   \and
36   Department of Computer Science\\
37   \'Ecole Normale Sup\'erieure\\
38   45, Rue d'Ulm, F-75230 Paris Cedex 05, FRANCE\\
39   \email{zack@cs.unibo.it}
40 }
41
42 \date{ }
43
44 \begin{document}
45 \sloppy
46 \maketitle
47
48 \begin{abstract}
49   We present a planning broker and several Web-Services for automatic deduction.
50   Each Web-Service implements one of the tactics usually available in an
51   interactive proof-assistant. When the broker is submitted a "proof status" (an
52   unfinished proof tree and a focus on an open goal) it dispatches the proof to
53   the Web-Services, collects the successfull results, and send them back to the
54   client as "hints" as soon as they are available.
55   
56   In our experience this architecture turns out to be helpful both for
57   experienced users (who can take benefit of distributing heavy computations)
58   and beginners (who can learn from it).
59 \end{abstract}
60
61 \section{Introduction}
62   The \ws\ approach at software development seems to be a working solution for
63   getting rid of a wide range of incompatibilities between communicating
64   software applications. W3C's efforts in standardizing related technologies
65   grant longevity and implementations availability for frameworks based on \wss\
66   for information exchange. As a direct conseguence, the number of such
67   frameworks is increasing and the World Wide Web is moving from a disorganized
68   repository of human-understandable HTML documents to a disorganized repository
69   of applications working on machine-understandable XML documents both for input
70   and output.
71   
72 \oldpart
73 {Di effetto la prima fase. La seconda era troppo fuori-tema e dettagliata per
74  un abstract}
75 {
76   This lack of organization along with the huge amount of documents available,
77   have posed not a few problems for data location. If this limitation could be
78   overcome using heuristic-based search engine for HTML pages, a satisfying
79   solution has yet to be found for \ws\ location \ednote{location non mi piace, ma
80   "localization" e' anche peggio, "retrieval"?}. A promising architecture seems
81   to be the use of \emph{brokers}, which access point (usually an URI) is known
82   by the potential clients or by \emph{registries}, to which the \wss\ subscribe
83   to publish their functionalities.
84 }
85 \begin{newpart}{Questa \'e la mia contro-proposta. Nella mia idea originale
86 dovrebbe essere una versione pi\'u fluida e leggera. Boh.}
87 The big challenge for the next future is to provide stable and reliable
88 services over this disorganized, unreliable and ever-evolving architecture.
89 The standard solution is providing a further level of stable services
90 (called \emph{brokers}) that behave as common gateway/address for client
91 applications to access a wide variety of services and abstract over them.
92
93 Since the \emph{Declaration of Linz}, the MONET Consortium \cite{MONET},
94 following the guidelines of the \wss/brokers approach, is
95 \end{newpart}
96   working on the development of a framework aimed at providing a set of software
97   tools for the advertisement and discovering of mathematical web services.
98 %CSC This framework turns out to be strongly based on both \wss\ and brokers.
99 \oldpart
100 {Hhhmm. Chiaro il punto, ma CAS and Theorem Prover related web-services non
101  \'e molto preciso.}
102 {
103   Several examples of CAS (Computer Algebra System) and Theorem Prover related
104   \wss\ have been shown to be useful and to fit well in the MONET Architecture
105   \ednote{citarne qualcuno: CSC???}. On the other hand \ednote{troppo informale?}
106   the set of \wss\ related to Proof Assistants tends to be ... rather ...
107   empty!\ednote{gia' mi immagino il tuo commento: BUHM! :-)}
108 }
109 \begin{newpart}{riformulo}
110  Several groups have already developed \wss\ providing both computational
111  and reasoning capabilities \cite{???,???,???}\ednote{trovare dei puntatori
112  carini dalle conferenze calculemus}: the first ones are implemented
113  on top of Computer Algebra Systems; the last ones provide interfaces to
114  well-known theorem provers. Proof-planners, proof-assistants, CAS and
115  domain-specific problem solvers are natural candidates to be client
116  of these services. Nevertheless, so far the number of examples in the
117  literature has been extremely low and the concrete benefits are still
118  to be assessed.\ednote{A questo punto bisogna venire al
119  sodo prima che il lettore passi al caff\'e}
120 \end{newpart}
121
122   In this paper we present an architecture, namely \hbugs\, implementing a
123   \emph{suggestion engine} for the proof assistant developed on behalf of the
124   \helm\ project. We provide several \wss (called \emph{tutors}) able to
125   suggest possible ways to proceed in a proof. The tutors are orchestrated
126   by a broker (a \ws\ itself) that is able to distribute a proof
127   status from a client (the proof-assistant) to the tutors;
128   each tutor try to make progress in the proof and, in case
129   of success, notify the client that shows and \emph{hint} to the user.
130   Both the broker and the tutors are instances of the homonymous entities of
131   the MONET framework.
132
133   A precursor of \hbugs is the $\Omega$-Ants project \cite{???},
134   which provided similar functionalities to the
135   Omega proof-planner \cite{Omega}. The main architectural difference
136   between \hbugs and $\Omega$-Ants is that the latter is based on a
137   black-board architecture and it is not implemented using \wss and
138   brokers. Other differences will be detailed in Sect. \ref{conclusions}.
139
140   In Sect. \ref{architecture} we present the architecture of \hbugs.
141   Further implementation details are given in Sect. \ref{implementation}.
142   Sect. \ref{tutors} is an overview of the tutors that have been implemented.
143   Finally, the last section is left for the conclusions and future works.
144   
145 \oldpart
146 {Non so se/dove mettere queste parti}
147 {
148   Despite of that the proof assistant case seems to be well suited to
149   investigate the usage of many different mathematical \wss. Indeed: most proof
150   assistants are still based on non-client/server architectures, are
151   application-centric instead of document-centric, offer a scarce level of
152   automation leaving entirely to the user the choice of which macro (usually
153   called \emph{tactic}) to use in order to make progress in a proof.
154
155   The average proof assistant can be, for example, a client of a \ws\
156   interfacing a specific or generic purpose theorem prover, or a client of a
157   \ws\ interfacing a CAS to simplify expressions in a particular mathematical
158   domain.
159 }
160
161
162 % \section{Introduction}
163 % Since the development of the first proof-assistants based on the
164 % Curry-Howard isomorphism, it became clear that directly writing
165 % lambda-terms (henceforth called simply terms) was a difficult, repetitive,
166 % time-expensive and error prone activity; hence the introduction of
167 % meta-languages to describe procedures that are able to automatically
168 % generate the low-level terms.
169 % Nowadays, almost all the proof-assistants
170 % using terms description of proofs have many levels of abstractions, i.e.
171 % meta-languages, to create the terms, with the only remarkable exception
172 % of the ALF family \cite{ALF} in which terms are still directly written
173 % without any over-standing level of abstraction.
174
175 % In particular, there are
176 % usually at least two levels, that of tactics and that of the language in
177 % which the whole system and hence the tactics are written; once the tactics
178 % are implemented, to do a proof the user enters to the system a sequence of
179 % tactics, called a script; the script is then executed to create the term
180 % encoding of the proof, which is type-checked by the kernel of the
181 % proof-assistant. Writing a script interactively is much simpler than
182 % writing the term by hands; once written, though, it becomes impossible
183 % to understand a script without replaying it interactively. For this reason,
184 % we can hardly speak of the language of tactics as a high level language,
185 % even if it is ``compiled'' to the language of terms.
186
187 % To avoid confusion, in the rest of this paper we will
188 % avoid the use of the term ``proof'', using only ``script'' and ``term'';
189 % moreover, we will avoid also the terms ``proof-checking'' and ``type-checking'',
190 % replacing them with ``retyping'' to mean the type-checking of an already
191 % generated term; finally, we will use the term ``compiling'' to mean the
192 % execution of a script. Usually, compilation ends with
193 % the type-checking of the generated term; hence the choice of ``retyping'' for
194 % the type-checking of an already generated term.
195
196 % A long term consequence of the introduction of tactics has been the
197 % progressive lowering of interest in terms. In particular, users of
198 % modern proof-assistants as Coq \cite{Coq} may even ignore the existence of
199 % commands to show the terms generated by their scripts. These terms are
200 % usually very huge and quite unreadable, so they don't add any easily
201 % accessible information to the scripts. Hence implementors have loosed
202 % interest in terms too, as far as their size and compilation time are
203 % small enough to make the system response-time acceptable.
204 % When this is not the case, it is sometimes possible to trade space
205 % with time using reflexive tactics, in which the potentiality of complex
206 % type-systems to speak about themselves are exploited: reflexive tactics
207 % usually leads to a polynomial asympotical reduction in the size of the
208 % terms, at the cost of an increased reduction time during retyping and
209 % compilation. Often, though, reflexive tactics could not be used; moreover,
210 % reflexive tactics suffer of the same implementative problems of other tactics
211 % and so could be implemented in such a way to create huger than
212 % needed terms, even if asymptotically smaller than the best ones created
213 % without reflection.
214
215 % The low level of interest in terms of the implementors of
216 % tactics often leads to naive implementations (``If it works, it is OK'') and
217 % this to low-quality terms, which:
218 % \begin{enumerate}
219 %  \item are huger than needed because particular cases are not taken
220 %   into account during tactic development
221 %  \item require more time than needed for retyping due to
222 %   their size
223 %  \item are particularly unreadable because they don't
224 %   correspond to the ``natural'' way of writing the proof by hand
225 % \end{enumerate}
226 % To cope with the second problem, retyping is usually avoided allowing
227 % systems to reload saved terms without retyping them and using a
228 % checksum to ensure that the saved file has not been modified. This is
229 % perfectly reasonable accordingly to the traditional application-centric
230 % architecture of proof-assistants in which you have only one tool integrating
231 % all the functionalities and so you are free to use a proprietary format for data
232 % representation.
233
234 % In the last months, though, an ever increasing number of people and projects
235 % (see, for example, HELM \cite{EHELM}, MathWeb \cite{MATHWEB} and
236 % Formavie \cite{FORMAVIE})
237 % have been interested to switch from the application-centric model to the
238 % newer content-centric one, in which information is stored in
239 % standard formats (that is, XML based) to allow different applications to work
240 % on the same set of data. As a consequence, term size really becomes an
241 % important issue, due to the redundancy of standard formats, and retyping
242 % is needed because the applications can not trust each other, hence needing
243 % retyping and making retyping time critical.
244 % Moreover, as showed by Yann Coscoy in its PhD.
245 % thesis \cite{YANNTHESIS} or by the Alfa interface to the Agda system
246 % \cite{ALFA}, it is perfectly reasonable and also feasible to try
247 % to produce descriptions in natural languages of formal proofs encoded as
248 % terms.
249 % This approach, combined with the further possibility of applying the usual
250 % two-dimensional mathematic notation to the formulas that appears in the
251 % terms, is being followed by projects HELM \cite{HELM}, PCOQ \cite{PCOQ} and
252 % MathWeb \cite{MATHWEB} with promising results. It must be understood, though,
253 % that the quality (in terms of naturality and readability) of this kind of
254 % proofs rendering heavily depends on the quality of terms, making also
255 % the third characteristic of low-quality terms a critical issue.
256
257 % A totally different scenario in which term size and retyping time are
258 % critical is the one introduced by Necula and Lee \cite{Necula} under
259 % the name Proof Carrying Code (PCC). PCC is a technique that can be used
260 % for safe execution of untrusted code. In a typical instance of PCC, a code
261 % receiver establishes a set of safety rules that guarantee safe behavior
262 % of programs, and the code producer creates a formal safety proof that
263 % proves, for the untrusted code, adherence to the safety rules. Then, the
264 % proof is transmitted to the receiver together with the code and it is
265 % retyped before code execution. While very compact representation of the
266 % terms, highly based on type-inference and unification, could be used
267 % to reduce the size and retyping time \cite{Necula2}, designing proof-assistants
268 % to produce terms characterized by an high level of quality is still necessary.
269
270 % In the next section we introduce a particular class of metrics for
271 % tactics evaluation. In section \ref{equivalence} we consider the
272 % notion of tactics equivalence and we describe one of the bad habits
273 % of tactics implementors, which is overkilling; we also provide and analyze
274 % a simple example of overkilling tactic. In the last section we describe
275 % a concrete experience of fixing overkilling in the implementation of a
276 % reflexive tactic in system Coq and we analyze the gain with respect to
277 % term-size, retyping time and term readability.
278
279 % \section{From Metrics for Terms Evaluation to Metrics for Tactics Evaluation}
280 % The aim of this section is to show how metrics for term evaluation could
281 % induce metrics for tactic evaluation. Roughly speaking, this allows us to
282 % valuate tactics in terms of the quality of the terms produced. Even if
283 % we think that these kinds of metrics are interesting and worth studying,
284 % it must be understood that many other valuable forms of metrics could be
285 % defined on tactics, depending on what we are interested in. For example,
286 % we could be interested on compilation time, that is the sum of the time
287 % required to generate the term and the retyping time for it. Clearly, only
288 % the second component could be measured with a term metric and a good
289 % implementation of a tactic with respect to the metric considered could
290 % effectively decide to sacrifice term quality (and hence retyping time) to
291 % minimize the time spent to generate the term. The situation is very close to
292 % the one already encountered in compilers implementation, where there is
293 % always a compromise, usually user configurable, between minimizing compiling
294 % time and maximizing code quality.
295
296 % The section is organized as follows: first we recall the definition of
297 % tactic and we introduce metrics on terms; then we give the definition
298 % of some metrics induced by term metrics on tactics.
299
300 % \begin{definition}[Of tactic]
301 % We define a \emph{tactic} as a function that, given a goal $G$ (that is, a local
302 % context plus a type to inhabit) that satisfies a list of assumptions
303 % (preconditions) $P$,
304 % returns a couple $(L,t)$ where
305 % $L = {L_1,\ldots,L_n}$ is a (possible empty) list of proof-obligations
306 % (i.e. goals) and $t$ is a function that, given a list $l = {l_1,\ldots,l_n}$
307 % of terms such that $l_i$ inhabits\footnote{We say, with a small abuse of
308 % language, that a term $t$ inhabits a goal $G=(\Gamma,T)$ when $t$ is of type
309 % $T$ in the context $\Gamma$.} $L_i$ for each $i$ in ${1,\ldots,n}$, returns a
310 % term $t(l)$ inhabiting $G$.
311 % \end{definition}
312
313 % % You can get another looser definition of tactic just saying that a tactic
314 % % is a partial function instead than a total one. In this paper when referring
315 % % to tactics we always refer to the first definition.
316
317 % \begin{definition}[Of term metric]
318 % For any goal $G$, a term metric $\mu_G$ is any function in
319 % $\mathbb{N}^{\{t/t\;\mbox{inhabits}\;G\}}$.
320 % Two important class of term metrics are functional metrics and monotone
321 % metrics:
322 % \begin{enumerate}
323 % \item {\bf Functional metrics:} a metric $\mu_G$ is \emph{functional}
324 %  if for each term context (=term with an hole) $C[]$ and for all terms
325 %  $t_1$,$t_2$ if $\mu_G(t_1)=\mu_G(t_2)$ then $\mu_G(C[t_1])=\mu_G(C[t_2])$.
326 %  An equivalent definition is that a metric $\mu_G$ is functional
327 %  if for each term context $C[]$ the function
328 %  $\lambda t.\mu_G(C[\mu_G^{-1}(t)])$ is well defined.
329 % \item {\bf Monotone metrics:} a metric $\mu_G$ is \emph{monotone} if for
330 %  each term context $C[]$ and for all terms $t_1$,$t_2$ if
331 %  $\mu_G(t_1)\le\mu_G(t_2)$ then $\mu_G(C[t_1])\le\mu_G(C[t_2])$.
332 %  An equivalent definition is that a metric $\mu_G$ is functional if
333 %  for each term context $C[]$ the function
334 %  $\lambda t.\mu_G(C[\mu_G^{-1}(t)])$ is well defined and monotone.
335 % \end{enumerate}
336
337 % % Vecchie definizioni
338 % %\begin{enumerate}
339 % %\item {\bf Monotony:} a metric $\mu_G$ is \emph{monotone} if for each term
340 %  %context (=term with an hole) $C[]$ and for all terms $t_1$,$t_2$ if
341 %  %$\mu_G(t_1)\le\mu_G(t_2)$ then $\mu_G(C[t_1])\le\mu_G(C[t_2])$
342 % %\item {\bf Strict monotony:} a monotone metric $\mu_G$ is \emph{strictly
343 %  %monotone} if for each term context $C[]$ and
344 %  %for all terms $t_1$,$t_2$ if $\mu_G(t_1)=\mu_G(t_2)$ then
345 %  %$\mu_G(C[t_1])=\mu_G(C[t_2])$
346 % %\end{enumerate}
347 % \end{definition}
348
349 % Typical examples of term metrics are the size of a term, the time required
350 % to retype it or even an estimate of its ``naturality'' (or simplicity) to be
351 % defined somehow; the first two are also examples of monotone metrics
352 % and the third one could probably be defined as to be. So, in the rest
353 % of this paper, we will restrict to monotone metrics, even if the
354 % following definitions also work with weaker properties for general metrics.
355 % Here, however, we are not interested in defining such metrics, but in showing
356 % how they naturally induce metrics for tactics.
357
358 % Once a term metric is chosen, we get the notion of a best term (not unique!)
359 % inhabiting a goal:
360 % \begin{definition}[Of best terms inhabiting a goal]
361 % the term $t$ inhabiting a goal $G$ is said to be a best term inhabiting $G$
362 % w.r.t. the metric $\mu_G$ when
363 % $\mu_G(t) = min\{\mu_G(t') / t'\;\mbox{inhabits}\;G\}$.
364 % \end{definition}
365
366 % Using the previous notion, we can confront the behavior of two tactics
367 % on the same goal:
368
369 % \begin{definition}
370 % Let $\tau_1$ and $\tau_2$ be two tactics both applyable to a goal $G$
371 % such that $\tau_1(G) = (L_1,t_1)$ and $\tau_2(G) = (L_2,t_2)$.
372 % We say that $\tau_1$ is better or equal than $\tau_2$ for the goal $G$
373 % with respect to $\mu_G$ if, for all $l_1$ and $l_2$ lists of best terms
374 % inhabiting respectively $L_1$ and $L_2$, $\mu_G(t_1(l_1)) \le \mu_G(t_2(l_2))$
375 % holds.
376 % \end{definition}
377 % Note that confronting in this way ``equivalent'' tactics
378 % (whose definition is precised in the next section) gives us information
379 % on which implementation is better; doing the same thing on tactics that
380 % are not equivalent, instead, gives us information about what tactic to
381 % apply to obtain the best proof.
382
383 % A (functional) metric to confront two tactics only on a particular goal
384 % has the nice property to be a total order, but is quite useless. Hence,
385 % we will now
386 % define a bunch of different tactic metrics induced by term metrics
387 % that can be used to confront the behavior of tactics when applied to
388 % a generic goal. Some of them will be \emph{deterministic} partial orders;
389 % others will be total orders, but will provide only a \emph{probabilistic}
390 % estimate of the behavior. Both kinds of metrics are useful in practice
391 % when rating tactics implementation.
392 % \begin{definition}[Of locally deterministic better or equal tactic]
393 % $\tau_1$ is a locally deterministic (or locally
394 % uniform) better or equal tactic
395 % than $\tau_2$ w.r.t. $\mu$ (and in that case we write $\tau_1 \le_{\mu} \tau_2$
396 % or simply $\tau_1 \le \tau_2$), when
397 % for all goals $G$ satisfying the preconditions of both tactics we have that
398 % $\tau_1$ is better or equal than $\tau_2$ w.r.t. the metric $\mu_G$.
399 % \end{definition}
400
401 % \begin{definition}[Of locally deterministic better tactic]
402 % $\tau_1$ is a locally deterministic (or locally uniform)
403 % better tactic than $\tau_2$ 
404 % w.r.t. $\mu$ (and in that case we write $\tau_1 <_{\mu} \tau_2$
405 % or simply $\tau_1 < \tau_2$), when $\tau_1 \le_{\mu} \tau_2$ and
406 % exists a goal $G$ satisfying the preconditions of both tactics such that
407 % $\tau_1$ is better (but not equal!) than $\tau_2$ w.r.t. the metric $\mu_G$.
408 % \end{definition}
409
410 % \begin{definition}[Of locally probabilistic better or equal tactic of a factor K]
411 % $\tau_1$ is said to be a tactic locally probabilistic better or equal of a
412 % factor $0.5 \le K \le 1$ than $\tau_2$ w.r.t. $\mu$ and a particular expected
413 % goals distribution when the probability of having $\tau_1$ better or equal than
414 % $\tau_2$ w.r.t. the metric $\mu_G$ is greater or equal to $K$ when $G$ is
415 % chosen randomly according to the distribution.
416 % \end{definition}
417 % The set of terms being discrete, you can note that a deterministically better
418 % or equal tactic is a tactic probabilistically better or equal of a factor 1.
419
420
421 % To end this section, we can remark the strong dependence of the $\le$
422 % relation on the choice of metric $\mu$, so that it is easy to find
423 % two metrics $\mu_1,\mu_2$ such that $\tau_1 <_{\mu_1} \tau_2$ and
424 % $\tau_2 <_{\mu_2} \tau_1$. Luckily, tough, the main interesting metrics,
425 % term size, retyping time and naturality, are in practice highly correlated,
426 % though the correlation of the third one with the previous two could be a
427 % bit surprising. So, in the following section, we
428 % will not state what is the chosen term metric; you may think as
429 % any of them or even at some kind of weighted mean.
430
431
432 % \section{Equivalent Tactics and Overkilling}
433 % \label{equivalence}
434 % We are now interested in using the metrics defined in the previous section
435 % to confront tactics implementation. Before doing so, though, we have to
436 % identify what we consider to be different implementations of the
437 % same tactic. Our approach consists in identifying every implementation
438 % with the tactic it implements and then defining appropriate notions of
439 % equivalence for tactics: two equivalent tactics will then be considered
440 % as equivalent implementations and will be confronted using metrics.
441
442 % Defining two tactics as equivalent when they can solve exactly the same
443 % set of goals generating the same set of proof-obligations seems quite natural,
444 % but is highly unsatisfactory if not completely wrong. The reason is that, for
445 % equivalent tactics, we would like to have the \emph{property of substitutivity},
446 % that is substituting a tactic for an equivalent one in a script should give
447 % back an error-free script\footnote{A weaker notion of substitutivity is that
448 % substituting the term generated by a tactic for the term generated by an
449 % equivalent one in a generic well-typed term should always give back a
450 % well-typed term.}. In logical frameworks with dependent types,
451 % without proof-irrelevance and with universes as CIC \cite{Werner} though,
452 % it is possible for a term to inspect the term of a previous proof, behaving
453 % in a different way, for example, if the constructive proof of a conjunction
454 % is made proving the left or right side.
455 % So, two tactics, equivalent w.r.t.  the previous
456 % definition, that prove $A \vee A$ having at their disposal an
457 % hypothesis $A$ proving the first one the left and the second one
458 % the right part of the conjunction, could not be substituted one for the
459 % other if a subsequent term inspects the form of the generated proof.
460
461 % Put in another way, it seems quite reasonable to derive equivalence for
462 % tactics from the definition of an underlying equivalence for terms.
463 % The simplest form of such an equivalence relation is convertibility
464 % (up to proof-irrelevance) of closed terms and this is the relation
465 % we will use in this section and the following one. In particular,
466 % we will restrict ourselves to CIC and hence to
467 % $\beta\delta\iota$-convertibility\footnote{The Coq proof-assistant
468 % introduces the notion of \emph{opaque} and \emph{transparent} terms,
469 % differing only for the possibility of being inspected. Because the
470 % user could change the opacity status at any time, the notion of
471 % convertibility we must conservatively choose for the terms of Coq is
472 % $\beta\delta\iota$-convertibility after having set all the definitions
473 % as transparent.}.
474 % Convertibility, though, is a too restrictive notion that does not take
475 % in account, for example, commuting conversions. Looking for more suitable
476 % notions of equivalence is our main open issue for future work.
477
478 % \begin{definition}[Of terms closed in a local environment]
479 % A term $t$ is \emph{closed} in a local environment $\Gamma$ when $\Gamma$
480 % is defined on any free variable of $t$.
481 % \end{definition}
482
483 % \begin{definition}[Of equivalent tactics]
484 % We define two tactics $\tau_1$ and $\tau_2$ to be equivalent (and
485 % we write $\tau_1 \approx \tau_2$) when for each goal $G = (\Gamma,T)$ and for
486 % each list of terms closed in $\Gamma$ and inhabiting the proof-obligations
487 % generated respectively by $\tau_1$ and $\tau_2$, we have that the result terms
488 % produced by $\tau_1$ and $\tau_2$ are $\beta\delta\iota$-convertible.
489 % \end{definition}
490
491 % Once we have the definition of equivalent tactics, we can use metrics,
492 % either deterministic or probabilistic, to confront them. In particular,
493 % in the rest of this section and in the following one we will focus on the
494 % notion of deterministically overkilling tactic, defined as follows:
495
496 % \begin{definition}[Of overkilling tactics]
497 % A tactic $\tau_1$ is (deterministically) overkilling w.r.t. a metric
498 % $\mu$ when there exists another tactic $\tau_2$ such that
499 % $\tau_1 \approx \tau_2$ and $\tau_2 <_\mu \tau_1$.
500 % \end{definition}
501
502 % Fixing an overkilling tactic $\tau_1$ means replacing it with the
503 % tactic $\tau_2$ which is the witness of $\tau_1$ being overkilling.
504 % Note that the fixed tactic could still be overkilling.
505
506 % The name overkilling has been chosen because most of the time overkilling
507 % tactics are tactics that do not consider special cases, following the general
508 % algorithm. While in computer science it is often a good design pattern to
509 % prefer general solutions to ad-hoc ones, this is not a silver bullet:
510 % an example comes another time from compiler technology, where
511 % ad-hoc cases, i.e. optimizations, are greatly valuable if not necessary.
512 % In our context, ad-hoc cases could be considered either as optimizations,
513 % or as applications of Occam's razor to proofs to keep the simplest one.
514
515 % \subsection{A Simple Example of Overkilling Tactic}
516 % A first example of overkilling tactic in system Coq is
517 % \emph{Replace}, that works in this way: when the current goal
518 % is $G = (\Gamma,T)$, the
519 % tactic ``{\texttt Replace E$_1$ with E$_2$.}'' always produces a new
520 % principal proof-obligation $(\Gamma, T\{E_2/E_1\})$ and an auxiliary
521 % proof-obligation $(\Gamma, E_1=E_2)$ and uses the elimination scheme
522 % of equality on the term $E_1 = E_2$ and the two terms that inhabit the
523 % obligations to prove the current goal.
524
525 % To show that this tactic is overkilling, we will provide an example
526 % in which the tactic fails to find the best term, we will
527 % propose a different implementation that produces the best term and we will
528 % show the equivalence with the actual one.
529
530 % The example consists in applying the tactic in the case in which $E_1$ is
531 % convertible to $E_2$: the tactic proposes to the user the two
532 % proof-obligations and then builds the term as described above. We claim
533 % that the term inhabiting the principal proof-obligation also inhabits
534 % the goal and, used as the generated term, is surely smaller
535 % and quicker to retype than the one that is generated in the
536 % implementation; moreover, it
537 % is also as natural as the previous one, in the sense that the apparently
538 % lost information has simply become implicit in the reduction and could
539 % be easily rediscovered using type-inference algorithms as the one described
540 % in Coscoy's thesis \cite{YANNTHESIS}. So, a new implementation could
541 % simply recognize this special case and generate the better term.
542
543 % We will now show that the terms provided by the two implementations are
544 % $\beta\delta\iota$-convertible.
545 % Each closed terms in $\beta\delta\iota$-normal form
546 % inhabiting the proof that $E_1$ is equal to $E_2$ is equal to the only
547 % constructor of equality applied to a term convertible to the type of
548 % $E_1$ and to another term convertible to $E_1$; hence, once the principle
549 % of elimination of equality is applied to this term, we can first apply
550 % $\beta$-reduction and then $\iota$-reduction to obtain the term inhabiting
551 % the principal proof-obligation in which $E_1$ has been replaced by $E_2$.
552 % Since $E_1$ and $E_2$ are $\beta\delta\iota$-convertible by hypothesis and
553 % for the congruence properties of convertibility in CIC, we have that the
554 % generated term is $\beta\delta\iota$-convertible to the one inhabiting the
555 % principal proof-obligation.
556
557 % %The simplest example is when $E_1$ and $E_2$ are syntactically equal:
558 % %in this case the principal obligation proposed is identical to the current goal
559 % %and the equality elimination introduced could be replaced by the proof of
560 % %this obligation, leading to a smaller, quicker to retype and also more
561 % %natural\footnote{Even if naturality is in some way a subjective metric,
562 % %who would dare say that a proof in which you rewrite an expression with
563 % %itself is natural?} term. To show that handling this special case in this
564 % %way is equivalent to the current solution, we have to show that the two
565 % %terms are $\beta\delta\iota$-convertible when so are the subterms inhabiting
566 % %the obligations.
567 % %The only closed term in $\beta\delta\iota$-normal form
568 % %inhabiting the proof that $E_1$ is equal to $E_1$ is the only constructor
569 % %of equality applied to the type of $E_1$ and to $E_1$; hence we can
570 % %first apply $\beta$-reduction and then $\iota$-reduction to obtain
571 % %the second proof in which $E_1$ has been replaced by $E_1$, i.e. the
572 % %second proof.
573
574 % %So, for this example, the simple fix to avoid overkilling is checking
575 % %if $E_1$ and $E_2$ are syntactically equal and in case omitting the elimination;
576 % %curiously, this is done in Coq in the implementation of a very similar tactic
577 % %called \emph{Rewriting}.
578
579
580 % %A second, more involved, example is when $E_1$ and $E_2$ are not
581 % %syntactically equal, but $E_1$ reduces to $E_2$. Even in this case
582 % %the elimination could simply be avoided because the typing rules of
583 % %the logical system ensures us that a term that inhabits the principal
584 % %obligation also inhabits the current goal: the proof is equivalent to the
585 % %previous one, but for the last step in which $E_2$ is actually substituted for
586 % %$E_1$; by hypothesis, though, the two terms are $\beta\delta\iota$-convertible
587 % %and hence the thesis.
588
589 % %Surely smaller and faster to retype, the new term is also as natural
590 % %as the previous one, in the sense that the apparently lost information has
591 % %simply become implicit in the reduction and could be easily rediscovered
592 % %using type-inference algorithms as the one described in chapter ???
593 % %of Coscoy's thesis \ref{YANNTHESIS}.
594
595 % This example may seem quite stupid because, if the user is already able to
596 % prove the principal proof-obligation and because this new goal is totally
597 % equivalent to the original one, the user could simply redo the same steps
598 % without applying the rewriting at all. Most of the time, though, the
599 % convertibility of the two terms could be really complex to understand,
600 % greatly depending on the exact definitions given; indeed, the user could
601 % often be completely unaware of the convertibility of the two terms. Moreover,
602 % even in the cases in which the user understands the convertibility, the
603 % tactic has the important effect of changing the form of the current
604 % goal in order to simplify the task of completing the proof, which is the reason
605 % for the user to apply it.
606
607 % ~\\
608
609 % The previous example shows only a very small improvement in the produced
610 % term and could make you wonder if the effort of fixing overkilling and
611 % more in general if putting more attention to terms when implementing
612 % tactics is really worth the trouble. In the next section we describe as
613 % another example a concrete experience of fixing a complex reflexive tactic
614 % in system Coq that has lead to really significant improvements in term
615 % size, retyping time and naturality.
616
617 % \section{Fixing Overkilling: a Concrete Experience}
618 % Coq provides a reflexive tactic called \emph{Ring} to do associative-commutative
619 % rewriting in ring and semi-ring structures. The usual usage is,
620 % given the goal $E_1 = E_2$ where $E_1$ and $E_2$ are two expressions defined
621 % on the ring-structure, to prove the goal reducing it to proving
622 % $E'_1 = E'_2$ where $E'_i$ is the normal form of $E_i$. In fact, once
623 % obtained the goal $E'_1 = E'_2$, the tactic also tries to apply simple
624 % heuristics to automatically solve the goal.
625
626 % The actual implementation of the tactic by reflexion is quite complex and
627 % is described in \cite{Ring}. The main idea is described in Fig. \ref{ring1}:
628 % first of all, an inductive data type to describe abstract polynomial is
629 % made available. On this abstract polynomial, using well-founded recursion in
630 % Coq, a normalization function named $apolynomial\_normalize$ is defined;
631 % for technical reasons, the abstract data type of normalized polynomials
632 % is different from the one of un-normalized polynomials. Then, two
633 % interpretation functions, named $interp\_ap$ and $interp\_sacs$ are given
634 % to map the two forms of abstract polynomials to the concrete one. Finally,
635 % a theorem named $apolynomial\_normalize\_ok$ stating the equality of
636 % the interpretation of an abstract polynomial and the interpretation of
637 % its normal form is defined in Coq using well-founded induction. The above
638 % machinery could be used in this way: to prove that $E^I$ is equal to its
639 % normal form $E^{IV}$, the tactic computes an abstract polynomial $E^{II}$ that,
640 % once interpreted, reduces to $E^{I}$, and such that the interpretation
641 % of $E^{III} = (apolynomial\_normalize E^{II})$ could be shown to be equal
642 % to $E^{IV}$ applying $apolynomial\_normalize\_ok$.
643
644 % %such that $(interp\_ap\;E^{II})$ could be proved (theorem
645 % %$apolynomial\_normalize\_ok$) in Coq to be equal to
646 % %$(interp\_sacs\;E^{III})$ where
647 % %$E^{III} = (apolynomial\_normalize E^{II})$ is another abstract polynomial
648 % %in normal form and the three functions $interp\_ap$, $interp\_sacs$ and
649 % %$apolynomial\_normalize$ could all be defined inside Coq using well-founded
650 % %recursion/induction on the abstract polynomial definition.
651
652 % % \myincludegraphics{ring1}{t}{12cm}{Reflexion in Ring}{Reflexion in Ring}
653 % % \myincludegraphics{ring2}{t}{10cm}{Ring implementation (first half)}{Ring implementation (first half)}
654
655 % In Fig. \ref{ring2} the first half of the steps taken
656 % by the Ring tactic to prove $E_1 = E_2$ are shown\footnote{Here $E_1$
657 % stands for $E^I$.}.
658 % The first step is replacing $E_1 = E_2$ with $(interp\_ap\;E^{II}_1) = E_2$,
659 % justifying the rewriting using the only one constructor of equality due to
660 % the $\beta\delta\iota$-convertibility of $(interp\_ap\;E^{II}_1)$ with $E_1$.
661 % The second one is replacing $(interp\_ap\;E^{II})$ with
662 % $(interp\_sacs\;E^{III})$, justifying the rewriting using
663 % $apolynomial\_normalize\_ok$.
664
665 % Next, the two steps are done again on the left part of the equality,
666 % obtaining $(interp\_sacs\;E^{III}_1) = (interp\_sacs\;E^{III}_2)$,
667 % that is eventually solved trying simpler tactics as \emph{Reflexivity} or left
668 % to the user.
669
670 % The tactic is clearly overkilling, at least due to the usage of rewriting for
671 % convertible terms. Let's consider as a simple example the session in Fig.
672 % \ref{session}:
673 % \begin{figure}[t]
674 % %\begin{verbatim}
675 % \mbox{\hspace{3cm}\tt Coq $<$ Goal ``0*0==0``.}\\
676 % \mbox{\hspace{3cm}\tt 1 subgoal}\\
677 % ~\\
678 % \mbox{\hspace{3cm}\tt ~~=================}\\
679 % \mbox{\hspace{3cm}\tt ~~~~``0*0 == 0``}\\
680 % ~\\
681 % \mbox{\hspace{3cm}\tt Unnamed\_thm $<$ Ring.}\\
682 % \mbox{\hspace{3cm}\tt Subtree proved!}
683 % %\end{verbatim}
684 % \caption{A Coq session.}
685 % \label{session}
686 % \end{figure}
687 % in Fig. \ref{before} the $\lambda$-term created by the
688 % original overkilling implementation of Ring is shown. Following the previous
689 % explanation, it should be easily understandable. In particular, the
690 % four rewritings are clearly visible as applications of $eqT\_ind$, as
691 % are the two applications of $apolynomial\_normalize\_ok$ and the
692 % three usage of reflexivity, i.e. the two applications of $refl\_eqT$
693 % to justify the rewritings on the left and right members of the equality
694 % and the one that ends the proof.
695
696 % Let's start the analysis of overkilling in this implementation:
697 % \begin{description}
698 % \item[Always overkilling rewritings:] as already stated, four of the rewriting
699 %  steps are always overkilling because the rewritten term is convertible to
700 %  the original one due to the tactic implementation.
701 %  As proved in the previous section, all these rewritings could be simply
702 %  removed obtaining an equivalent tactic.
703 % \item[Overkilling rewritings due to members already normalized:] it may happen,
704 %  as in our example, that one (or even both) of the two members is already in
705 %  normal form. In this case the two rewriting steps for that member could be
706 %  simply removed obtaining an equivalent tactic as shown in the previous section.
707 % \item[Rewriting followed by reflexivity:] after having removed all
708 %  the overkilling rewritings, the general form of the $\lambda$-term produced
709 %  for $E_1 = E_2$ is the application of two rewritings ($E'_1$ for $E_1$ and
710 %  $E'_2$ for $E_2$), followed by a proof of $E'_1 = E'_2$. In many cases,
711 %  $E'_1$ and $E'_2$ are simply convertible and so the tactic finishes the
712 %  proof with an application of reflexivity to prove the equivalent goal
713 %  $E'_1 = E'_1$.
714 %  A smaller and also more natural solution is just to
715 %  rewrite $E'_1$ for $E_1$ and then proving $E'_1 = E_2$ applying the lemma
716 %  stating the symmetry of equality to the proof of $E_2 = E'_2$.
717 %  The equivalence to the original
718 %  tactic is trivial by $\beta\iota$-reduction because the lemma is proved
719 %  exactly doing the rewriting and then applying reflexivity:
720 %  $$
721 %  \begin{array}{l}
722 %  \lambda A:Type.\\
723 %  \hspace{0.2cm}\lambda x,y:A.\\
724 %  \hspace{0.4cm}\lambda H:(x==y).\\
725 %  \hspace{0.6cm}(eqT\_ind~A~x~ [x:A]a==x~(refl\_eqT~A~x)~y~H)
726 %  \end{array}
727 %  $$
728 % \end{description}
729 % In Fig. \ref{after} is shown the $\lambda$-term created by the same
730 % tactic after having fixed all the overkilling problems described above.
731
732 % \begin{figure}
733 % \begin{verbatim}
734 % Unnamed_thm < Show Proof.
735 % LOC: 
736 % Subgoals
737 % Proof:
738 % (eqT_ind R
739 %   (interp_ap R Rplus Rmult ``1`` ``0`` Ropp (Empty_vm R)
740 %     (APmult AP0 AP0)) [r:R]``r == 0``
741 %   (eqT_ind R
742 %     (interp_sacs R Rplus Rmult ``1`` ``0`` Ropp (Empty_vm R)
743 %       Nil_varlist) [r:R]``r == 0``
744 %     (eqT_ind R
745 %       (interp_ap R Rplus Rmult ``1`` ``0`` Ropp (Empty_vm R) AP0)
746 %       [r:R]
747 %        ``(interp_sacs R Rplus Rmult 1 r Ropp (Empty_vm R) Nil_varlist)
748 %        == r``
749 %       (eqT_ind R
750 %         (interp_sacs R Rplus Rmult ``1`` ``0`` Ropp (Empty_vm R)
751 %           Nil_varlist)
752 %         [r:R]
753 %          ``(interp_sacs R Rplus Rmult 1 r Ropp (Empty_vm R)
754 %            Nil_varlist) == r`` (refl_eqT R ``0``)
755 %         (interp_ap R Rplus Rmult ``1`` ``0`` Ropp (Empty_vm R) AP0)
756 %         (apolynomial_normalize_ok R Rplus Rmult ``1`` ``0`` Ropp
757 %           [_,_:R]false (Empty_vm R) RTheory AP0)) ``0``
758 %       (refl_eqT R ``0``))
759 %     (interp_ap R Rplus Rmult ``1`` ``0`` Ropp (Empty_vm R)
760 %       (APmult AP0 AP0))
761 %     (apolynomial_normalize_ok R Rplus Rmult ``1`` ``0`` Ropp
762 %       [_,_:R]false (Empty_vm R) RTheory (APmult AP0 AP0))) ``0*0``
763 %   (refl_eqT R ``0*0``))
764 % \end{verbatim}
765 % \caption{The $\lambda$-term created by the original overkilling implementation}
766 % \label{before}
767 % \end{figure}
768
769 % \begin{figure}
770 % \begin{verbatim}
771 % Unnamed_thm < Show Proof.
772 % LOC: 
773 % Subgoals
774 % Proof:
775 % (sym_eqT R ``0`` ``0*0``
776 %   (apolynomial_normalize_ok R Rplus Rmult ``1`` ``0`` Ropp
777 %     [_,_:R]false (Empty_vm R) RTheory (APmult AP0 AP0)))
778 % \end{verbatim}
779 % \caption{The $\lambda$-term created by the new implementation}
780 % \label{after}
781 % \end{figure}
782
783 % \clearpage
784 % \subsection{A Quantitative Analysis of the Gain Obtained}
785 % Let's now try a quantitative analysis of the gain with respect to term size,
786 % retyping time and naturality, considering the two interesting cases of
787 % no member or only one member already in normal form\footnote{If the two
788 % members are already in normal form, the new implementation simply applies
789 % once the only constructor of the equality to one of the two members. The tactic
790 % is also implemented to do the same thing also when the two members are not yet
791 % in normal forms, but are already convertible. We omit this other improvement
792 % in our analysis.}.
793
794 % \subsubsection{Term Size.}
795 % \paragraph{Terms metric definition:} given a term $t$, the metric $|.|$ associates to it its number of nodes $|t|$.
796 % \paragraph{Notation}: $|T|$ stands for the number of nodes in the actual parameters
797 %  given to $interp\_ap$, $interp\_sacs$ and $apolynomial\_normalize\_ok$ to
798 %  describe the concrete (semi)ring theory and the list of non-primitive
799 %  terms occurring in the goal to solve. In the example in figures \ref{before}
800 %  and \ref{after}, $|T|$ is the number of nodes in
801 %  \begin{texttt}[R Rplus Rmult ``1`` ``0`` Ropp (Empty\_vm R)]\end{texttt}.
802 %  $|R|$ stands for the number of nodes in the term which is the carrier
803 %  of the ring structure. In the same examples, $|R|$ is simply 1, i.e.
804 %  the number of nodes in \begin{texttt}R\end{texttt}.
805
806 % \begin{displaymath}
807 % \begin{array}{l}
808 % \mbox{\bf Original version:}\\
809 % \begin{array}{ll}
810 % 1 + (|E^{II}_1| + |T| + 1) + |E_2| + |E_1| + &
811 % \mbox{(I rewriting Left)} \\
812 % 1 + |E_1| +  &
813 % \mbox{(justification)} \\
814 % 1 + (|E^{III}_1| + |T| + 1) + |E_2| + (|E^{II}_1| + |T| + 1) + &
815 % \mbox{(II rewriting Left)} \\
816 % (|E^{II}_1| + |T| + 1) + &
817 % \mbox{(justification)} \\
818 % 1 + (|E^{II}_2| + |T| + 1) + (|E^{III}_1| + |T| + 1) + |E_2| + &
819 % \mbox{(I rewriting Right)} \\
820 % 1 + |E_2| + &
821 % \mbox{(justification)} \\
822 % 1 + (|E^{III}_2| + |T| + 1) + (|E^{III}_1| + |T| + 1) + &
823 % \mbox{(II rewriting Right)} \\
824 % ~(|E^{II}_2| + |T| + 1) +& \\
825 % (|E^{II}_2| + |T| + 1) + &
826 % \mbox{(justification)} \\
827 % 1 + |E_1| = &
828 % \mbox{(reflexivity application)} \\
829 % \hline
830 % 4|E_1| + 2|E_2| + 3|E^{II}_1| + 3|E^{II}_2| + 3|E^{III}_1| + |E^{III}_2| +~ &
831 % \mbox{\bf Total number} \\
832 % ~10|T| + 17 &
833 % \end{array}
834 % \end{array}
835 % \end{displaymath}
836
837 % \begin{displaymath}
838 % \begin{array}{l}
839 % \mbox{\bf New version, both members not in normal form:}\\
840 % \begin{array}{ll}
841 % 1 + |R| + |E_1| + |E'_2| + &
842 % \mbox{(Rewriting Right)} \\
843 % 1 + |T| + |E^{II}_2| + &
844 % \mbox{(justification)} \\
845 % 1 + |R| + |E'_2| + |E'_1| + |E_2| + &
846 % \mbox{(Symmetry application)} \\
847 % 1 + |T| + |E^{II}_1| = &
848 % \mbox{(justification)} \\
849 % \hline
850 % 2|E_1| + |E_2| + |E^{II}_1| + |E^{II}_2| + 2|E'_2| + 2|T| +~ &
851 % \mbox{\bf Total number} \\
852 % ~2|R| + 4  & \\
853 % ~ &
854 % \end{array}
855 % \end{array}
856 % \end{displaymath}
857 % \begin{displaymath}
858 % \begin{array}{l}
859 % \mbox{\bf New version, only the first member not in normal form:}\\
860 % \begin{array}{ll}
861 % 1 + |R| + |E_1| + |E'_2| + &
862 % \mbox{(Rewriting)} \\
863 % 1 + |T| + |E^{II}_2| = &
864 % \mbox{(justification)} \\
865 % \hline
866 % |E_1| + |E'_2| + |E^{II}_2| + |T| + |R| + 2~~~  &
867 % \mbox{\bf Total number} \\
868 % ~ &
869 % \end{array}
870 % \end{array}
871 % \end{displaymath}
872
873 % While the overall space complexity of the terms generated by the new
874 % implementation is asymptotically equal to the one of the old implementation,
875 % all the constants involved are much smaller, but for the one of
876 % $E'_2$ (the two normal forms) that before was 0 and now is
877 % equal to 2. Is it possible to have goals for which the new implementation
878 % behaves worst than the old one? Unfortunately, yes. This happens when
879 % the size of the two normal forms $E'_1$ and $E'_2$ is greatly huger than
880 % ($E^{II}_1 + |T| + 1)$ and $(E^{II}_2 + |T| + 1)$. This happens when
881 % the number of occurrences of non-primitive terms is much higher than
882 % the number of non-primitive terms and the size of them is big. More
883 % formally, being $m$ the number of non-primitive terms, $d$ the average
884 % size and $n$ the number of occurrences, the new implementation creates bigger
885 % terms than the previous one if
886 % \begin{displaymath}
887 % n \log_2 m + m  d < n  d
888 % \end{displaymath}
889 % where the difference between the two members is great enough to hide the gain
890 % achieved lowering all the other constants.
891 % The logarithmic factor in the previous
892 % formula derives from the implementation of the map of variables to
893 % non-primitive terms as a tree and the representation of occurrences with
894 % the path inside the tree to retrieve the term.
895
896 % To fix the problem, for each non-primitive term occurring more than once
897 % inside the normal forms, we can use a \emph{let \ldots in} local definition
898 % to bind it to a fresh identifier; then we replace every occurrence of
899 % the term inside the normal forms with the appropriate
900 % identifier\footnote{This has not yet been implemented in Coq.}.
901 % In this way, the above inequation becomes
902 % \begin{displaymath}
903 % n \log_2 m + m  d < n + m  d
904 % \end{displaymath}
905 % that is never satisfied.
906
907 % Here it is important to stress how the latest problem was easily
908 % overlooked during the implementation and has been discovered
909 % only during the previous analysis, strengthening our belief in
910 % the importance of this kind of analysis for tactic implementations.
911
912 % In the next two paragraphs we will consider only the new implementation
913 % with the above fixing.
914
915 % \subsubsection{Retyping Time.}
916 % \paragraph{Terms metric definition:} given a term $t$, the metric $|.|$ associates to it the time $|t|$ required to retype it.
917
918 % Due to lack of space, we will omit a detailed analysis as the one given
919 % for terms size. Nevertheless, we can observe that the retyping time required
920 % is surely smaller because all the type-checking operations required for
921 % the new implementation are already present in the old one, but for the
922 % type-checking of the two normal forms, that have fewer complexity
923 % than the type-checking of the two abstract normal forms, and the
924 % \emph{let \ldots in} definitions that have the same complexity of the
925 % type-checking of the variable map. Moreover, the quite expensive operation
926 % of computing the two normal forms is already done during proof construction.
927
928 % %In the case in which both the members of the equality are not in normal form,
929 % %we can't expect a great improvement in retyping time but for very cheap
930 % %normalizations; this because retyping time is dominated by the factor due to
931 % %$apolynomial\_normalize$ that is present in both implementations and is
932 % %usually much higher than the factor due to the removed applications of
933 % %$interp\_ap$, $interp\_sacs$ and the eliminations of equality.
934
935 % %The situation is very different if one of the two members is already
936 % %convertible to its normal form and the reduction involved in the normalization
937 % %is expensive. In this rather unlikely case, the new implementation
938 % %avoids the reduction at all, roughly halving the overall retyping time.
939
940 % In section \ref{benchmarks} we present some benchmarks to give an idea of
941 % the real gain obtained.
942
943 % \subsubsection{Naturality.}~\\~\\
944 % The idea behind the \emph{Ring} tactic is to be able to prove
945 % an equality showing that both members have the same normal form.
946 % This simply amounts to show that each member is equal to the same
947 % normal form, that is exactly what is done in the new implementation.
948 % Indeed, every step that belonged to the old implementation and has been
949 % changed or removed to fix overkilling used to lead to some unnatural step:
950 % \begin{enumerate}
951 % \item The fact that the normalization is not done on the concrete
952 %  representation, but passing through two abstract ones that are
953 %  interpreted on the concrete terms is an implementative detail that
954 %  was not hidden as much as possible as it should be.
955 % \item Normalizing a member of the equality that is already in normal form,
956 %  is illogical and so unnatural. Hence it should be avoided, but it was not.
957 % \item The natural way to show $A=B$ under the hypothesis $B=A$ is just
958 %  to use the symmetric property of equality. Instead, the old implementation
959 %  rewrote $B$ with $A$ using the hypothesis and proved the goal by reflexivity.
960 % \item Using local definitions (\emph{let \ldots in}) as abbreviations
961 %  rises the readability of the proof by shrinking its size removing
962 %  subexpressions that are not involved in the computation.
963 % \end{enumerate}
964
965 % \subsection{Some Benchmarks}
966 % \label{benchmarks}To understand the actual gain in term size and retyping
967 % time on real-life examples, we have done some benchmarks on the whole set
968 % of theorems in the standard library of Coq that use the Ring tactic. The
969 % results are shown in table~\ref{benchs}.
970
971 % Term size is the size of the disk dump of the terms. Re-typing time is the
972 % user time spent by Coq in proof-checking already parsed terms. The reduction
973 % of the terms size implies also a reduction in Coq parsing time, that is
974 % difficult to compute because Coq files do not hold single terms, but whole
975 % theories. Hence, the parsing time shown is really the user time spent by Coq
976 % to parse not only the terms on which we are interested, but also all the
977 % terms in their theories and the theories on which they depend. So, this last
978 % measure greatly under-estimates the actual gain.
979
980 % Every benchmark has been repeated 100 times under different load conditions on
981 % a 600Mhz Pentium III bi-processor equipped with 256Mb RAM. The timings shown
982 % are mean values.
983
984 % \begin{table}
985 % \begin{center}
986 % \begin{tabular}{|l|c|c|c|}
987 % \hline
988 %  & ~Term size~ & Re-typing time & Parsing time\\
989 % \hline
990 % Old implementation & 20.27Mb & 4.59s & 2.425s \\
991 % \hline
992 % New implementation & 12.99Mb & 2.94s & 2.210s \\
993 % \hline
994 % Percentage reduction & 35.74\% & 35.95\% & 8.87\% \\
995 % \hline
996 % \end{tabular}
997 % \end{center}
998 % \caption{Some benchmarks}
999 % \label{benchs}
1000 % \end{table}
1001
1002 % \section{Conclusions and Future Work}
1003 % Naive ways of implementing tactics lead to low quality terms that are
1004 % difficult to inspect and process. To improve the situation, we show
1005 % how metrics defined for terms naturally induce metrics for tactics and
1006 % tactics implementation and we advocate the usage of such metrics for
1007 % tactics evaluation and implementation. In particular, metrics could
1008 % be used to analyze the quality of an implementation or could be used at run
1009 % time by a tactic to choose what is the best way to proceed.
1010
1011 % To safely replace a tactic implementation with another one, it is important
1012 % to define when two tactics are equivalent, i.e. generate equivalent terms.
1013 % In this work, the equivalence relation chosen for terms has simply been 
1014 % $\beta\delta\iota$-convertibility, that in many situations seems too strong.
1015 % Hence, an important future work is the study of weaker forms of term
1016 % equivalence and the equivalence relations they induce on tactics. In particular,
1017 % it seems that proof-irrelevance, $\eta$-conversion and commuting conversions
1018 % must all be considered in the definition of a suitable equivalence relation.
1019
1020 \begin{thebibliography}{01}
1021
1022 % \bibitem{ALF} The ALF family of proof-assistants:\\
1023 % {\tt http://www.cs.chalmers.se/ComputingScience/Research/\\Logic/implementation.mhtml}
1024
1025 % \bibitem{Coq} The Coq proof-assistant:\\
1026 %  {\tt http://coq.inria.fr/}
1027
1028 % \bibitem{FORMAVIE} The Formavie project:\\
1029 %  {\tt http://http://www-sop.inria.fr/oasis/Formavie/}
1030
1031 % \bibitem{EHELM} The HELM project:\\
1032 %  {\tt http://www.cs.unibo.it/helm/}
1033
1034 % \bibitem{MATHWEB} The MathWeb project:\\
1035 %  {\tt http://www.mathweb.org/}
1036
1037 % \bibitem{PCOQ} The PCoq project:\\
1038 %  {\tt http://www-sop.inria.fr/lemme/pcoq/}
1039
1040 % \bibitem{HELM} A.Asperti, L.Padovani, C.Sacerdoti Coen, I.Schena.
1041 % Towards a library of formal mathematics. Panel session of
1042 % the 13th International Conference on Theorem Proving in Higher Order Logics (TPHOLS'2000),
1043 % Portland, Oregon, USA.
1044
1045 % \bibitem{Ring} S. Boutin. Using reflection to build efficient and certified
1046 %  decision procedures. In Martin Abadi and Takahashi Ito, editors, TACS'97,
1047 %  volume 1281. LNCS, Springer-Verlag, 1997.
1048
1049 % \bibitem{YANNTHESIS} Y.Coscoy. \emph{Explication textuelle de preuves pour le
1050 % Calcul des Constructions Inductives}, PhD. Thesis, Universit\'e de Nice-Sophia
1051 % Antipolis, 2000.
1052
1053 % \bibitem{ALFA} T. Hallgreen, Aarne Ranta. An Extensible Proof Text Editor.
1054 % Presented at LPAR2000.
1055
1056 % \bibitem{Necula} G. Necula, P. Lee. Safe Kernel Extensions Without Run-Time
1057 %  Checking. Presented at OSDI'96, October 1996.
1058
1059 % \bibitem{Necula2} G. Necula, P. Lee. Efficient Representation and Validation of Proofs. Presented at LICS'98, June 1998
1060
1061 % \bibitem{Werner} B. Werner. \emph{Une Th\'eorie des Constructions Inductives},
1062 %  PhD. Thesis, Universit\'e Paris VII, May 1994.
1063
1064 \end{thebibliography}
1065  
1066 \end{document}