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