]> matita.cs.unibo.it Git - helm.git/blob - helm/papers/calculemus-2003/hbugs-calculemus-2003.tex
dd2ad61e8c13b7b29f752bffe71a5f13b939dda1
[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{\musing}{\texttt{musing}}
22 \newcommand{\musings}{\texttt{musings}}
23 \newcommand{\ws}{Web-Service}
24 \newcommand{\wss}{Web-Services}
25 \newcommand{\hbugs}{H-Bugs}
26 \newcommand{\helm}{HELM}
27 \newcommand{\Omegapp}{$\Omega$mega}
28 \newcommand{\OmegaAnts}{$\Omega$mega-Ants}
29
30 \title{Brokers and Web-Services for Automatic Deduction: a Case Study}
31
32 \author{Claudio Sacerdoti Coen \and Stefano Zacchiroli}
33
34 \institute{
35   Department of Computer Science\\
36   University of Bologna\\
37   Mura Anteo Zamboni 7, 40127 Bologna, ITALY\\
38   \email{sacerdot@cs.unibo.it}
39   \and
40   Department of Computer Science\\
41   \'Ecole Normale Sup\'erieure\\
42   45, Rue d'Ulm, F-75230 Paris Cedex 05, FRANCE\\
43   \email{zack@cs.unibo.it}
44 }
45
46 \date{ }
47
48 \begin{document}
49 \sloppy
50 \maketitle
51
52 \begin{abstract}
53   We present a planning broker and several Web-Services for automatic deduction.
54   Each Web-Service implements one of the tactics usually available in
55   interactive proof-assistants. When the broker is submitted a "proof status" (an
56   incomplete proof tree and a focus on an open goal) it dispatches the proof to
57   the Web-Services, collects the successful results, and send them back to the
58   client as "hints" as soon as they are available.
59   
60   In our experience this architecture turns out to be helpful both for
61   experienced users (who can take benefit of distributing heavy computations)
62   and beginners (who can learn from it).
63 \end{abstract}
64
65 \section{Introduction}
66   The \ws{} approach at software development seems to be a working solution for
67   getting rid of a wide range of incompatibilities between communicating
68   software applications. W3C's efforts in standardizing related technologies
69   grant longevity and implementations availability for frameworks based on
70   \wss{} for information exchange. As a direct consequence, the number of such
71   frameworks is increasing and the World Wide Web is moving from a disorganized
72   repository of human-understandable HTML documents to a disorganized repository
73   of applications working on machine-understandable XML documents both for input
74   and output.
75   
76   The big challenge for the next future is to provide stable and reliable
77   services over this disorganized, unreliable and ever-evolving architecture.
78   The standard solution is to provide a further level of
79   stable services (called \emph{brokers}) that behave as common gateways/addresses
80   for client applications to access a wide variety of services and abstract over
81   them.
82
83   Since the \emph{Declaration of Linz}, the MONET
84   Consortium\footnote{\url{http://monet.nag.co.uk/cocoon/monet/index.html}}
85   is working on the development of a framework, based on the
86   \wss{}/brokers approach, aimed at providing a set of software tools for the
87   advertisement and the discovery of mathematical \wss{}.
88   %CSC This framework turns out to be strongly based on both \wss{} and brokers.
89
90   Several groups have already developed software bus and
91   services\footnote{The most part of these systems predate the development of
92   \wss. Those systems whose development is still active are slowly being
93   reimplemented as \wss.} providing both computational and reasoning
94   capabilities \cite{ws1,ws2,ws3,ws4}: the first ones are implemented on top of
95   Computer Algebra Systems; the second ones provide interfaces to well-known
96   theorem provers.
97   Proof-planners, proof-assistants, CAS and
98   domain-specific problem solvers are natural candidates to be clients of these
99   services.  Nevertheless, so far the number of examples in the literature has
100   been extremely low and the concrete benefits are still to be assessed.
101
102   In this paper we present an architecture, namely \hbugs{}, implementing a
103   \emph{suggestion engine} for the proof assistant developed on behalf of the
104   \helm{}\footnote{Hypertextual Electronic Library of Mathematics,
105   \url{http://helm.cs.unibo.it}} project
106   \cite{helm}. We provide several \wss{} (called \emph{tutors}) able to
107   suggest possible ways to proceed in a proof. The tutors are orchestrated
108   by a broker (a \ws{} itself) that is able to dispatch a proof
109   status from a client (the proof-assistant) to the tutors;
110   each tutor try to make progress in the proof and, in case
111   of success, notify the client that shows an \emph{hint} to the user.
112   The broker is an instance of the homonymous entity of the MONET framework.
113   The tutors are MONET services. Another \ws{} (which is not described in this
114   paper and which is called Getter \cite{zack}) is used to locate and download
115   mathematical entities; the Getter plays the role of the Mathematical Object
116   Manager in the MONET framework.
117
118   A precursor of \hbugs{} is the \OmegaAnts{} project
119   \cite{omegaants1,omegaants2}, which provided similar functionalities to the
120   \Omegapp{} proof-planner \cite{omega}. The main architectural difference
121   between \hbugs{} and \OmegaAnts{} are that the latter is based on a
122   black-board architecture and it is not implemented using \wss{} and
123   brokers.
124
125   In Sect. \ref{architecture} we present the architecture of \hbugs{}.
126   An usage session is shown in Sect. \ref{usage}.
127   Further implementation details are given in Sect. \ref{implementation}.
128   Sect. \ref{tutors} is an overview of the tutors that have been implemented.
129   As usual, the final section of this paper is devoted to conclusions and future works.
130   
131 \section{An \hbugs{} Bird's Eye View}
132 \label{architecture}
133   \myincludegraphics{arch}{t}{8cm}{\hbugs{} architecture}{\hbugs{} architecture}
134
135   The \hbugs{} architecture (depicted in Fig. \ref{arch}) is based on three
136   different kinds of actors: \emph{clients}, \emph{brokers}, and \emph{tutors}.
137   Each actor present one or more \ws{} interfaces to its neighbors \hbugs{}
138   actors.
139
140   In this section we detail the role and requirements of each kind of
141   actors and discuss about the correspondences between them and the MONET
142   entities described in \cite{MONET-Overview}.
143
144   \paragraph{Clients}
145     An \hbugs{} client is a software component able to produce \emph{proof
146     status} and to consume \emph{hints}.
147
148     A proof status is a representation of an incomplete proof and is supposed to
149     be informative enough to be used by an interactive proof assistant. No
150     additional requirements exist on the proof status, but there should be an
151     agreement on its format between clients and tutors. An hint is an
152     encoding of a step that can be performed in order to proceed in an
153     incomplete proof. Usually it represents a reference to a tactic available
154     on some proof assistant along with an instantiation for its formal
155     parameters. More structured hints can also be used: an hint can be
156     as complex as a whole proof-plan.
157
158     Using W3C's terminology \cite{ws-glossary}, clients act both as \ws{}
159     providers and requesters, see Fig. \ref{interfaces}.
160     They act as providers for the broker (to receive hints)
161     and as requesters (to submit new status). Clients
162     additionally use broker service to know which tutors are available and to
163     subscribe to one or more of them.
164
165     Usually, when the client role is taken by an interactive proof assistant,
166     new status are sent to the broker as soon as the proof change (e.g. when the
167     user applies a tactic or when a new proof is started) and hints are shown to
168     the user be the means of some effect in the user interface (e.g. popping a
169     dialog box or enlightening a tactic button).
170
171     \hbugs{} clients act as MONET clients and ask brokers to provide access to a
172     set of services (the tutors). \hbugs{} has no actors corresponding to
173     MONET's Broker Locating Service (since the client is supposed to know the
174     URI of at least one broker). The \hbugs{} client and tutors contact the
175     Getter (a MONET Mathematical Object Manager) to locate and retrieve
176     mathematical items in the \helm{} library.
177     The proof status that are exchanged
178     by the \hbugs{} actors, instead, are built on the fly and are neither
179     stored nor given an unique identifier (URI) to be managed by the
180     Getter.
181
182   \paragraph{Brokers}
183     \myincludegraphics{interfaces}{t!}{10cm}{\hbugs{} \wss{} interfaces}
184      {\hbugs{} \wss{} interfaces}
185
186     Brokers are the key actors of the \hbugs{} architecture since they
187     act as intermediaries between clients and tutors. They behave as \wss{}
188     providers and requesters for \emph{both} clients and tutors, see Fig.
189     \ref{interfaces}.
190
191     With respect to the client, a broker acts as a \ws{} provider, receiving the
192     proof status and forwarding it to one or more tutors.
193     It also acts as a \ws{} requester sending
194     hints to the client as soon as they are available from the tutors.
195
196     With respect to the tutors, the \ws{} provider role is accomplished by
197     receiving hints as soon as they are produced; as a requester, it is
198     accomplished by asking for computations (\emph{musings} in \hbugs{}
199     terminology) on status received by clients and by stopping already late but
200     still ongoing \musings{}.
201
202     Additionally brokers keep track of available tutors and clients
203     subscriptions.
204
205     \hbugs{} brokers act as MONET brokers implementing the following components:
206     Client Manager, Service Registry Manager (keeping track of available
207     tutors), Planning Manager (choosing the available tutors among the ones to
208     which the client is subscribed), Execution Manager. The Service Manager
209     component is not required since the session handler, that identifies
210     a session between a service and a broker, is provided to the service by
211     the broker instead of being received from the service when the session is
212     initialized. In particular, a session is identified by an unique identifier
213     for the client (its URL) and an unique identifier for the broker (its
214     URL).
215
216     The MONET architecture specification does not state explicitly whether
217     the service and broker answers can be asynchronous. Nevertheless, the
218     described information flow implicitly suggests a synchronous implementation.
219     On the contrary, in \hbugs{} every request is asynchronous: the connection
220     used by an actor to issue a query is immediately closed; when a service
221     produces an answer, it gives it back to the issuer by calling the
222     appropriate actor's method.
223
224   \paragraph{Tutors}
225     Tutors are software component able to consume proof status producing hints.
226     \hbugs{} does not specify by which means hints should be produced: tutors
227     can use any means necessary (heuristics, external theorem prover or CAS,
228     etc.). The only requirement is that there exists an agreement on the
229     formats of proof status and hints.
230
231     Tutors act both as \ws{} providers and requesters for the broker, see Fig.
232     \ref{interfaces}. As
233     providers, they wait for commands requesting to start a new \musing{} on
234     a given proof status or to stop an old, out of date, \musing{}. As
235     requesters, they signal to the broker the end of a \musing{} along with its
236     outcome (an hint in case of success or a failure notification).
237
238     \hbugs{} tutors act as MONET services.
239
240 \section{An \hbugs{} Session Example}
241 \label{usage}
242 In this section we describe a typical \hbugs{} session. The aim of the
243 session is to solve the following easy exercise:
244 \begin{exercise}
245 Let $x$ be a generic real number. Using the \helm{} proof-engine,
246 prove that
247 \begin{displaymath}
248 x = \frac{(x+1)*(x+1) - 1 - x*x}{2}
249 \end{displaymath}
250 \end{exercise}
251
252 Let us suppose that the \hbugs{} broker is already running and that the
253 tutors already registered themselves to the broker.
254 When the user starts \texttt{gTopLevel}, the system registers itself to
255 the broker, that sends back the list of available tutors. By default,
256 \texttt{gTopLevel} notifies to the broker its intention of subscribing to every
257 tutor available. The user can always open a configuration window where she
258 is presented the list of available tutors and she can independently subscribe
259 and unsubscribe the system to each tutor.
260
261 \myincludegraphics{step1}{t}{12cm}{Example session.}
262   {Example session.}
263 %\myincludegraphics{step2}{t}{4cm}{Example session, snapshot 2.}
264 % {Example session, snapshot 2.}
265
266 The user can now insert into the system the statement of the theorem and start
267 proving it. Let us suppose that the first step of the user is proving
268 that the denominator 2 is different from 0. Once that this technical result
269 is proven, the user must prove the goal shown in the upper right corner
270 of the window in background in Fig. \ref{step1}.
271
272 While the user is wondering how to proceed in the proof, the tutors are
273 trying to progress in the proof. After a while, the tutors' suggestions
274 start to appear in the lower part of the \hbugs{} interface window
275 (the topmost window in Fig. \ref{step1}). In this case, the tutors are able
276 to produce 23 hints. The first and not very useful hint suggests to proceed in
277 the proof by exchanging the two sides of the equality.
278 The second hint suggests to reduce both sides of the equality to their normal
279 form by using only reductions which are justified by the ring structure of the
280 real numbers; the two normal forms, though, are so different that the proof is
281 not really simplified.
282 All the residual 21 hints suggest to apply one lemma from the distributed
283 library of \helm{}. The user can look at the statement of the lemma by clicking
284 on its URI.
285
286 The user can now look at the list of suggestions and realize that a good one is
287 applying the lemma \texttt{r\_Rmult\_mult} that allows to multiply both equality
288 members by the same scalar\footnote{Even if she does not receive the hint, the
289 user probably already knows that this is the right way to proceed. The
290 difficult part where the hint helps is guessing what is the name of the lemma
291 to apply.}.
292 Double-clicking on the hint automatically applies
293 the lemma, reducing the proof to closing three new goals. The first one asks
294 the user the scalar to use as an argument of the previous lemma; the second
295 one states that the scalar is different from 0; the third lemma (the main
296 one) asks to prove the equality between the two new members.
297 % is shown in Fig. \ref{step2} where $?_3[H;x]$ stands for
298 % the still unknown scalar argument, which can have only $H$ and $x$ as
299 % free variables.
300
301 The user proceeds by instantiating the scalar with the number 2. The
302 \texttt{Assumption} tutor now suggests to close the second goal (that
303 states that $2 \neq 0$) by applying the hypothesis $H$.
304 No useful suggestions, instead, are generated for the main goal
305 $2*x = 2*((x+1)*(x+1)-1-x*x)*2^{-1}$.
306 To proceed in the proof the user needs to simplify the
307 expression using the lemma $Rinv\_r\_simpl\_m$ that states that
308 $\forall x,y.\;y = x * y * x^{-1}$. Since we do not provide yet any tutor
309 suggesting simplifications, the user must find out this simplification by
310 himself. Once she founds it, the goal is reduced to proving that
311 $2*x = (x+1)*(x+1) - 1 - x*x$. This equality is easily solved by the
312 \texttt{Ring} tutor, that suggests\footnote{The \texttt{Ring} suggestion is
313 just one of the 22 hints that the user receives. It is the only hint that
314 does not open new goals, but the user right now does not have any way to know
315 that.} to the user how to directly finish the proof.
316
317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 %    Comandi da dare a gTopLevel    %
319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 % New proof:
321 %  !x.(not (eqT ? (Rplus R1 R1) R0)) -> (eqT ? x (Rdiv (Rminus (Rminus (Rmult (Rplus x R1) (Rplus x R1)) R1) (Rmult x x)) (Rplus R1 R1)))
322 % Intros x H
323 % Apply  r_Rmult_mult
324 % 3: Apply H
325 % Simpl   (per fare unfold di Rdiv)
326 % Rewrite <-
327 %  (Rmult_assoc (Rplus R1 R1) (Rplus (Rplus (Rmult (Rplus x R1) (Rplus x R1)) (Ropp R1)) (Ropp (Rmult x x))) (Rinv (Rplus R1 R1)))
328 % Rewrite ->
329 %  (Rinv_r_simpl_m (Rplus R1 R1) (Rplus (Rplus (Rmult (Rplus x R1) (Rplus x R1)) (Ropp R1)) (Ropp (Rmult x x))) H)
330 % *** Ring
331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332
333 \section{Implementation's Highlights}
334 \label{implementation}
335 In this section we present some of the most relevant implementation details of
336 the \hbugs{} architecture.
337
338
339   \paragraph{Proof status}
340     In our implementation of the \hbugs{} architecture we used the proof
341     assistant of the \helm{} project (codename ``gTopLevel'') as an \hbugs{}
342     client. Thus we have implemented serialization/deserialization capabilities
343     for its internal status. In order to be able to describe \wss{} that
344     exchange status in WSDL using the XML Schema type system, we have chosen an
345     XML format as the target format for the serialization.
346
347 %    A schematic representation of the gTopLevel internal status is depicted in
348 %    Fig. \ref{status}.
349     Each proof is represented by a tuple of four elements:
350     \emph{uri}, \emph{metasenv}, \emph{proof}, \emph{thesis}.
351
352 %    \myincludegraphics{status}{t}{8cm}{gTopLevel proof status}{gTopLevel proof
353 %    status}
354
355     \begin{description}
356       \item[uri]: an URI chosen by the user at the beginning of the proof
357         process. Once (and if) proved, that URI will globally identify the term
358         inside the \helm{} library (given that the user decides to save it).
359       \item[thesis]: the thesis of the ongoing proof
360       \item[proof]: the current incomplete proof tree. It can contain
361         \emph{metavariables} (holes) that stands for the parts of the proof
362         that are still to be completed. Each metavariable appearing in the
363         tree references one element of the metavariables environment
364         (\emph{metasenv}).
365       \item[metasenv]: the metavariables environment is a list of
366         \emph{goals} (unproved conjectures).
367         In order to complete the proof, the user has to instantiate every
368         metavariable in the proof with a proof of the corresponding goal.
369         Each goal is identified by an unique identifier and has a context
370         and a type (the goal thesis). The context is a list of named
371         hypotheses (declarations and definitions). Thus the context and the goal
372         thesis form a sequent, which is the statement of the proof that will
373         be used to instantiate the metavariable occurrences.
374     \end{description}
375
376     Each of these information is represented in XML as described in
377     \cite{mowglicic}. Additionally, an \hbugs{} status carry the unique
378     identifier of the current goal, which is the goal the user is currently
379     focused on. Using this value it is possible to implement different client
380     side strategies: the user could ask the tutors to work on the goal
381     she is considering or to work on the other ``background'' goals.
382
383   \paragraph{Hints}
384     An hint in the \hbugs{} architecture should carry enough information to
385     permit the client to progress in the current proof. In our
386     implementation each hint corresponds to either one of the tactics available
387     to the user in gTopLevel (together with its actual arguments) or a set
388     of alternative suggestions (a list of hints).
389
390     For tactics that don't require any particular argument (like tactics that
391     apply type constructors or decision procedures)
392     only the tactic name is represented in the hint. For tactics that need
393     terms as arguments (for example the \texttt{Apply} tactic that apply a
394     given lemma) the hint includes a textual representation of them, using the
395     same representation used by the interactive proof assistant when querying
396     user for terms. In order to be transmitted between \wss{}, hints are
397     serialized in XML.
398
399     It is also possible for a tutor to return more hints at once,
400     grouping them in a particular XML element.
401     This feature turns out to be particularly useful for the
402     \emph{searchPatternApply} tutor (see Sect. \ref{tutors}) that
403     query a lemma database and return to the client a list of all lemmas that
404     could be used to complete the proof. This particular hint is encoded as a
405     list of \texttt{Apply} hints, each of them having one of the results as term
406     argument.
407
408     We would like to stress that the \hbugs{} architecture has no dependency
409     on either the hint or the status representation: the only message parts
410     that are fixed are those representing the administrative messages
411     (the envelops in the \wss{} terminology). In particular, the broker can
412     manage at the same time several sessions working on different status/hints
413     formats. Of course, there must be an agreement between the clients
414     and the tutors on the format of the data exchanged.
415
416     In our implementation the client does not trust the tutors hints:
417     being encoded as references to available tactics imply
418     that an \hbugs{} client, on receipt of an hint, simply try to reply the work
419     done by a tutor on the local copy of the proof. The application of the hint
420     can even fail to type check and the client copy of the proof can be left
421     undamaged after spotting the error. Note, however, that it is still
422     possible to implement a complex tutor that looks for a proof doing
423     backtracking and
424     send back to the client an hint whose argument is a witness (a trace) of
425     the proof found: the client applies the hint reconstructing (and checking
426     the correctness of) the proof from the witness, without having to
427     re-discover the proof itself.
428
429     An alternative implementation where the tutors are trusted would simply
430     send back to the client a new proof-status. Upon receiving the
431     proof-status, the client would just override its current proof status with
432     the suggested one. In the case of those clients which are implemented
433     using proof-objects (as the Coq proof-assistant, for instance), it is
434     still possible for the client to type-check the proof-object and reject
435     wrong hints. The systems that are not based on proof-objects
436     (as PVS, NuPRL, etc.), instead, have to trust the new proof-status. In this
437     case the \hbugs{} architecture needs at least to be extended with
438     clients-tutors authentication.
439     
440   \paragraph{Registries}
441     Being central in the \hbugs{} architecture, the broker is also responsible
442     of housekeeping operations both for clients and tutors. These operations are
443     implemented using three different data structures called \emph{registries}:
444     clients registry, tutors registry and \musings{} registry.
445
446     In order to use the suggestion engine a client should register itself to the
447     broker and subscribe to one or more tutors. The registration phase is
448     triggered by the client using the \texttt{Register\_client} method of the
449     broker to send him an unique identifier and its base URI as a
450     \ws{}. After the registration, the client can use broker's
451     \texttt{List\_tutors} method to get a list of available tutors.
452     Eventually the client can subscribe to one or more of these using broker's
453     \texttt{Subscribe} method. Clients can also unregister from brokers using
454     \texttt{Unregister\_client} method.
455
456     The broker keeps track of both registered clients and clients' subscriptions
457     in the clients registry.
458
459     In order to be advertised to clients during the subscription phase, tutors
460     should register to the broker using the broker's \texttt{Register\_tutor}
461     method.  This method is really similar to \texttt{Register\_client}:
462     tutors are required to send an unique identify and a base URI for their
463     \ws{}.
464     Additionally tutors are required to send an human readable description of
465     their capabilities; this information could be used by client's user to
466     decide which tutors he needs to subscribe to. As the clients, tutors can
467     unregister from brokers using \texttt{Unregister\_broker} method.
468
469     Each time the client status change, it get sent sent to the
470     broker using its \texttt{Status} method. Using both clients registry (to
471     lookup client's subscription) and tutors registry (to check if some tutors
472     has unsubscribed), the broker is able to decide to which tutors the
473     new status have to be forwarded.
474 %   \ednote{CSC: qui o nei lavori futuri parlare
475 %    della possibilit\'a di avere un vero brocker che multiplexi le richieste
476 %    dei client localizzando i servizi, etc.}
477
478     The forwarding operation is performed using the \texttt{Start\_musing}
479     method of the tutors, that is a request to start a new computation
480     (\emph{\musing{}}) on a given status. The return value of
481     \texttt{Start\_musing} is a
482     \musing{} identifier that is saved in the \musings{} registry along with
483     the identifier of the client that triggered the \musing{}.
484
485     As soon as a tutor completes an \musing{}, it informs the broker
486     using its \texttt{Musing\_completed} method; the broker can now remove the
487     \musing{} entry from the \musings{} registry and, depending on its outcome,
488     inform the client. In case of success one of the \texttt{Musing\_completed}
489     arguments is an hint to be sent to the client, otherwise there's no need to
490     inform him and the \texttt{Musing\_completed} method is called
491     just to update the \musings{} registry.
492
493     Consulting the \musings{} registry, the broker is able to know, at each
494     time, which \musings{} are in execution on which tutor. This peculiarity is
495     exploited by the broker on invocation of the \texttt{Status} method.
496     Receiving a new status from the client implies indeed that the previous
497     status no longer exists and all \musings{} working on it should be stopped:
498     additionally to the already described behavior (i.e. starting new
499     \musings{} on the received status), the broker takes also care of stopping
500     ongoing computation invoking the \texttt{Stop\_musing} method of the tutors.
501
502   \paragraph{\wss{}}
503     As already discussed, all \hbugs{} actors act as \wss{} offering one or more
504     services to neighbor actors. To grant as most accessibility as possible to
505     our \wss{} we have chosen to bind them using the HTTP/POST\footnote{Given
506     that our proof assistant was entirely developed in the Objective Caml
507     language, we have chosen to develop also \hbugs{} in that language in order
508     to maximize code reuse. To develop \wss{} in Objective Caml we have
509     developed an auxiliary generic library (\emph{O'HTTP}) that can be used to
510     write HTTP 1.1 Web servers and abstract over GET/POST parsing. This library
511     supports different kinds of Web servers architecture, including
512     multi-process and multi-threaded ones.} bindings described in
513     \cite{wsdlbindings}.
514
515   \paragraph{Tutors}
516     Each tutor expose a \ws{} interface and should be able to work, not only for
517     many different clients referring to a common broker, but also for many
518     different brokers. The potential high number of concurrent clients imposes
519     a multi-threaded or multi-process architecture.
520
521     Our current implementation is based on a multi threaded architecture
522     exploiting the capabilities of the O'HTTP library. Each tutor is composed
523     by one thread always running plus
524     an additional thread for each running \musing{}. One thread is devoted to
525     listening for incoming \ws{} request; upon correct receiving requests it
526     pass the control to a second thread, created on the fly, to handle the
527     incoming request following the classical one-thread-per-request approach in
528     web servers design.
529     If the received request is \texttt{Start\_musing}, a new thread is
530     spawned to handle it; the thread in duty to handle the HTTP request
531     returns an HTTP response containing the identifier of the just started
532     \texttt{musing}, and then dyes. If the received request is
533     \texttt{Stop\_musing}, instead, the spawned thread kills the thread
534     responsible for the \texttt{musing} whose identifier is the argument
535     of the \texttt{Stop\_musing} method.
536     
537     This architecture turns out to be scalable and allows the running threads
538     to share the cache of loaded (and type-checked) theorems.
539     As we will explain in Sect. \ref{tutors}, this feature turns out to be
540     really useful for tactics that rely on a huge but fixed set of lemmas,
541     as every reflexive tactic.
542
543     The implementation of a tutor with the described architecture is not that
544     difficult having a language with good threading capabilities (as OCaml has)
545     and a pool of already implemented tactics (as gTopLevel has).
546     Still working with threads is known to be really error prone due to
547     concurrent programming intrinsic complexity. Moreover, there is a
548     non-neglectable part of code that needs to be duplicated in every tutor:
549     the code to register the tutor to the broker and to handle HTTP requests;
550     the code to manage the creation and termination of threads; and the code for
551     parsing the requests and serializing the answers. As a consequence we
552     have written a generic implementation of a tutor which is parameterized
553     over the code that actually propose the hint and some administrative
554     data (as the port the tutor will be listening to).
555
556     The generic tutor skeleton is really helpful in writing new tutors.
557     Nevertheless, the code obtained by converting existing tactics into tutors
558     is still quite repetitive: every tutor that wraps a tactic has to
559     instantiate its own copy of the proof-engine kernel and, for each request,
560     it has to override its status, guess the tactic arguments, apply the tactic
561     and, in case of success, send back an hint with the tactic name and the
562     chosen arguments. Of course, the complex part of the work is guessing the
563     right arguments. For the simple case of tactics that do not require
564     any argument, though, we are able to automatically generate the whole
565     tutor code given the tactic name. Concretely, we have written a
566     tactic-based tutor template and a script that parses an XML file with
567     the specification of the tutor and generates the tutor's code.
568     The XML file describes the tutor's port, the code to invoke the tactic,
569     the hint that is sent back upon successful application and a
570     human readable explanation of the tactic implemented by the tutor.
571
572 \section{The Implemented \hbugs Tutors}
573 \label{tutors}
574 To test the \hbugs{} architecture and to assess the utility of a suggestion
575 engine for the end user, we have implemented several tutors. In particular,
576 we have investigated three classes of tutors:
577 \begin{enumerate}
578  \item \emph{Tutors for beginners}. These are tutors that implement tactics
579    which are neither computationally expensive nor difficult to understand:
580    an expert user can always understand if the tactic can be applied or not
581    without having to try it. For example, the following implemented tutors
582    belong to this class:
583     \begin{itemize}
584      \item \emph{Assumption Tutor}: it ends the proof if the thesis is
585        equivalent\footnote{In our implementation, the equivalence relation
586        imposed by the logical framework is \emph{convertibility}. Two
587        expressions are convertible when they reduce to the same normal form.
588        Two ``equal'' terms depending on free variables can be non-convertible
589        since free variables stop the reduction. For example, $2x$ is convertible
590        with $(3-1)x$ because they both reduce to the same normal form
591        $x + x + 0$; but $2x$ is not convertible to $x2$ since the latter is
592        already in normal form.}
593        to one of the hypotheses\footnote{
594        In some cases, especially when non-trivial computations are involved,
595        the user is totally unable to figure out the convertibility of two terms.
596        In these cases the tutor becomes handy also for expert users.}.
597      \item \emph{Contradiction Tutor}: it ends the proof by \emph{reductio ad
598        adsurdum} if one hypothesis is equivalent to $False$.
599      \item \emph{Symmetry Tutor}: if the goal thesis is an equality, it
600        suggests to apply the commutative property.
601      \item \emph{Left/Right/Exists/Split/Reflexivity/Constructor Tutors}:
602        the Constructor Tutor suggests to proceed in the proof by applying one
603        or more constructors when the goal thesis is an inductive type or a
604        proposition inductively defined according to the declarative
605        style\footnote{An example of a proposition that can be given in
606        declarative style is the $\le$ relation over natural numbers:
607        $\le$ is the smallest relation
608        such that $n \le n$ for every $n$ and $n \le m$ for every $n,m$ such
609        that $n \le p$ where $p$ is the predecessor of $m$. Thus, a proof
610        of $n \le n$ is simply the application of the first constructor to
611        $n$ and a proof of $n \le m$ is the application of the second
612        constructor to $n,m$ and a proof of $n \le m$.}.
613        Since disjunction, conjunction, existential quantification and
614        Leibniz equality are particular cases of inductive propositions,
615        all the other tutors of this class are instantiations of the
616        the Constructor tactic. Left and Right suggest to prove a disjunction
617        by proving its left/right member; Split reduces the proof of a
618        conjunction to the two proof of its members; Exists suggests to
619        prove an existential quantification by providing a
620        witness\footnote{This task is left to the user.}; Reflexivity proves
621        an equality whenever the two sides are convertible.
622     \end{itemize}
623   Beginners, when first faced with a tactic-based proof-assistant, get
624   lost quite soon since the set of tactics is large and their names and
625   semantics must be remembered by heart. Tutorials are provided to guide
626   the user step-by-step in a few proofs, suggesting the tactics that must
627   be used. We believe that our beginners tutors can provide an auxiliary
628   learning tool: after the tutorial, the user is not suddenly left alone
629   with the system, but she can experiment with variations of the proof given
630   in the tutorial as much as she like, still getting useful suggestions.
631   Thus the user is allowed to focus on learning how to do a formal proof
632   instead of wasting efforts trying to remember the interface to the system.
633  \item{Tutors for Computationally Expensive Tactics}. Several tactics have
634   an unpredictable behavior, in the sense that it is unfeasible to understand
635   whether they will succeed or they will fail when applied and what will be
636   their result. Among them, there are several tactics either computationally
637   expensive or resources consuming. In the first case, the user is not
638   willing to try a tactic and wait for a long time just to understand its
639   outcome: she would prefer to keep on concentrating on the proof and
640   have the tactic applied in background and receive out-of-band notification
641   of its success. The second case is similar, but the tactic application must
642   be performed on a remote machine to avoid overloading the user host
643   with several concurrent resource consuming applications.
644
645   Finally, several complex tactics and in particular all the tactics based
646   on reflexive techniques depend on a pretty large set of definitions, lemmas
647   and theorems. When these tactics are applied, the system needs to retrieve
648   and load all the lemmas. Pre-loading all the material needed by every
649   tactic can quickly lead to long initialization times and to large memory
650   footstamps. A specialized tutor running on a remote machine, instead,
651   can easily pre-load the required theorems.
652
653   As an example of computationally expensive task, we have implemented
654   a tutor for the \emph{Ring} tactic \cite{ringboutin}.
655   The tutor is able to prove an equality over a ring by reducing both members
656   to a common normal form. The reduction, which may require some time in
657   complex cases,
658   is based on the usual commutative, associative and neutral element properties
659   of a ring. The tactic is implemented using a reflexive technique, which
660   means that the reduction trace is not stored in the proof-object itself:
661   the type-checker is able to perform the reduction on-the-fly thanks to
662   the conversion rules of the system. As a consequence, in the library there
663   must be stored both the algorithm used for the reduction and the proof of
664   correctness of the algorithm, based on the ring axioms. This big proof
665   and all of its lemmas must be retrieved and loaded in order to apply the
666   tactic. The Ring tutor loads and cache all the required theorems the
667   first time it is contacted.
668  \item{Intelligent Tutors}. Expert users can already benefit from the previous
669   class of tutors. Nevertheless, to achieve a significative production gain,
670   they need more intelligent tutors implementing domain-specific theorem
671   provers or able to perform complex computations. These tutors are not just
672   plain implementations of tactics or decision procedures, but can be
673   more complex software agents interacting with third-parties software,
674   such as proof-planners, CAS or theorem-provers.
675
676   To test the productivity impact of intelligent tutors, we have implemented
677   a tutor that is interfaced with the \helm{}
678   Search-Engine\footnote{\url{http://helm.cs.unibo.it/library.html}} and that
679   is able to look for every theorem in the distributed library that can
680   be applied to proceed in the proof. Even if the tutor deductive power
681   is extremely limited\footnote{We do not attempt to check if the new goals
682   obtained applying a lemma can be automatically proved or, even better,
683   automatically disproved to reject the lemma.}, it is not unusual for
684   the tutor to come up with precious hints that can save several minutes of
685   work that would be spent in proving again already proven results or
686   figuring out where the lemmas could have been stored in the library.
687 \end{enumerate}
688
689 \section{Conclusions and Future Work}
690 \label{conclusions}
691   In this paper we described a suggestion engine architecture for
692   proof-assistants: the client (a proof-assistant) sends the current proof
693   status to several distributed \wss{} (called tutors) that try to progress
694   in the proof and, in case of success, send back an appropriate hint
695   (a proof-plan) to the user. The user, that in the meantime was able to
696   reason and progress in the proof, is notified with the hints and can decide
697   to apply or ignore them. A broker is provided to decouple the clients and
698   the tutors and to allow the client to locate and invoke the available remote
699   services. The whole architecture is an instance of the MONET architecture
700   for Mathematical \wss{}.
701
702   A running prototype has been implemented as part of the
703   \helm{} project \cite{helm}
704   and we already provide several tutors. Some of them are simple tutors that
705   try to apply one or more tactics of the \helm{} Proof-Engine, which is also
706   our client. We also have a much more complex tutor that is interfaced
707   with the \helm{} Search-Engine and looks for lemmas that can be directly
708   applied.
709
710   We have many plans for further developing both the \hbugs{} architecture and
711   our prototype. Interesting results could be obtained
712   augmenting the informative content of each suggestion. We can for example
713   modify the broker so that also negative results are sent back to the client.
714   Those negative suggestions could be reflected in the user interface by
715   deactivating commands to narrow the choice of tactics available to the user.
716   This approach could be interesting especially for novice users, but require
717   the client to trust other actors a bit more than in the current approach.
718
719   We plan also to add some rating mechanism to the architecture. A first
720   improvement in this direction could be distinguishing between hints that, when
721   applied, are able to completely close one or more goals and
722   tactics that progress in the proof by reducing one or more goals to new goals:
723   the new goals could be false and the proof can be closed only by backtracking.
724
725   Other heuristics and/or measures could be added to rate
726   hints and show them to the user in a particular order: an interesting one
727   could be a measure that try to minimize the size of the generated proof,
728   privileging therefore non-overkilling solutions \cite{ring}.
729
730   We are also considering to follow the \OmegaAnts{} path more closely adding
731   ``recursion'' to the system so that the proof status resulting from the
732   application of old hints are cached somewhere and could be used as a starting
733   point for new hint searches. The approach is interesting, but it represents
734   a big shift towards automatic theorem proving: thus we must consider if it is
735   worth the effort given the increasing availability of automation in proof
736   assistants tactics and the ongoing development of \wss{} based on
737   already existent and well developed theorem provers.
738
739   Even if not strictly part of the \hbugs{} architecture, the graphical user
740   interface (GUI) of our prototype needs a lot of improvement if we would like
741   it to be really usable by novices. In particular, the user is too easily
742   distracted by the tutor's hints that are ``pushed'' to her.
743
744   Our \wss{} still lack a real integration in the MONET architecture,
745   since we do not provide the different ontologies to describe our problems,
746   solutions, queries and services. In the short term, completing this task
747   could provide a significative feedback to the MONET consortium and would
748   enlarge the current set of available MONET actors on the Web. In the long
749   term, new more intelligent tutors could be developed on top of already
750   existent MONET \wss{}.
751
752   To conclude, \hbugs{} is a nice experiment meant to understand whether the
753   current \wss{} technology is mature enough to have a concrete and useful
754   impact on the daily work of proof-assistants users. So far, only the tutor
755   that is interfaced with the \helm{} Search-Engine has effectively increased
756   the productivity of experts users. The usefulness of the tutors developed for
757   beginners, instead, need further assessment.
758
759 \begin{thebibliography}{01}
760
761 \bibitem{ws-glossary} Web Services Glossary, W3C Working Draft, 14 May 2003.\\
762  \url{http://www.w3.org/TR/ws-gloss/}
763
764 \bibitem{wsdlbindings} Web Services Description Language (WSDL)
765  Version 1.2: Bindings, W3C Working Draft, 24 January 2003.\\
766  \url{http://www.w3.org/TR/wsdl12-bindings/}
767
768 \bibitem{ws1}A. Armando, D. Zini. Interfacing Computer Algebra and
769  Deduction Systems via the Logic Broker Architecture. In Proceedings
770  of the Eighth Calculemus symphosium, St. Andrews, Scotland, 6--7 August 2000.
771
772 \bibitem{ws2} O. Caprotti. Symbolic Evaluator Service. Project Report of
773  the MathBrocker Project, RISC-Linz, Johannes Kepler University, Linz,
774  Austria, May 2002.
775
776 \bibitem{helm} A. Asperti, F. Guidi, L. Padovani, C. Sacerdoti Coen, I. Schena.
777  Mathematical Knowledge Management in HELM. In Annals of Mathematics and
778  Artificial Intelligence, 38(1): 27--46, May 2003.
779
780 \bibitem{omegaants1} C. Benzm\"uller, V. Sorge. O-Ants -- An Open Approach
781  at Combining Interactive and Automated Theorem Proving. In M. Kerber and
782  M. Kohlhase (eds.), Integration of Symbolic and Mechanized Reasoning, pp.
783  81--97, 2000.
784
785 \bibitem{omegaants2} C. Benzm\"uller, M. Jamnik, M. Kerber, V. Sorge.
786  Agent-based Mathematical Reasoning. In A. Armando and T. Jebelean (eds.),
787  Electronic Notes in Theoretical Computer Science, (1999) 23(3), Elsevier.
788
789 \bibitem{omega} C. Benzm\"uller, L. Cheikhrouhou, D. Fehrer, A. Fiedler,
790  X. Huang, M. Kerber, M. Kohlhase, K. Konrad, E. Melis, A. Meier,
791  W. Schaarschmidt, J. Siekmann, V. Sorge. OMEGA: Towards a Mathematical
792  Assistant. In W. McCune (ed), Proceedings of the 14th Conference on
793  Automated Deduction (CADE-14), Springer LNAI vol. 1249, pp. 252--255,
794  Townsville, Australia, 1997.
795
796 \bibitem{ringboutin} S. Boutin. Using reflection to build efficient and
797  certified decision procedures. In Martin Abadi and Takahashi Ito, editors,
798  TACS'97, volume 1281. LNCS, Springer-Verlag, 1997.
799
800 \bibitem{MONET-Overview} The MONET Consortium, MONET Architecture Overview,
801  Public Deliverable D04 of the MONET Project.\\
802  \url{http://monet.nag.co.uk/cocoon/monet/publicsdocs/monet-overview.pdf}
803
804 \bibitem{mowglicic} C. Sacerdoti Coen. Exportation Module, MoWGLI Deliverable
805  D2.a.\\
806  \url{http://mowgli.cs.unibo.it/html\_no\_frames/deliverables/transformation/d2a.html}
807
808 \bibitem{ring} C. Sacerdoti Coen. Tactics in Modern Proof-Assistants: the
809  Bad Habit of Overkilling. In Supplementary Proceedings of the 14th
810  International Conference TPHOLS 2001, pp. 352--367, Edinburgh.
811
812 \bibitem{zack} S. Zacchiroli. \emph{Web services per il supporto alla
813  dimostrazione interattiva}, Master Thesis, University of Bologna, 2002.
814
815 \bibitem{ws3} J. Zimmer and L. Dennis. Inductive Theorem Proving and
816  Computer Algebra in the MathWeb Software Bus. In Proceedings of the 10th
817  CALCULEMUS Symposium 2002, 3--5 July 2002.
818
819 \bibitem{ws4} R. Zippel. The MathBus. In Workshop on Internet Accessible
820  Mathematical Computation at ISSAC'99, Vancouver, Canada, July 28--31, 1999.
821
822 \end{thebibliography}
823  
824 \end{document}