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