# Doing computations on the server

(Excerpt from "The MathML Handbook" by Pavi Sandhu)

All the examples discussed in this chapter so far have involved programs running on the client machine. We saw that by using one of the MathML rendering applications in combination with JavaScript and HTML, you can implement many different types of interactive behavior. However, client-side processing has its limitations. It is hard to do any serious mathematical operations (such as solving equations, calculating integrals, or plotting graphs) on the client side since this is beyond the scope of simple scripting languages that can be run in a browser. If you want to do any type of advanced computation on mathematical content, it is necessary to do some processing on the server side.

There are many well-established technologies for server-side programming, such as CGI scripting, Active Server Pages, Perl, Python, PHP, and Java servlets. However, the focus of these scripting and programming languages is on processing textual data, not on doing mathematical computations. These languages play a key role in any type of server-side programming, since they are well suited for the tasks of receiving input from the client, launching executable programs, and then transforming and returning output back to the client. However, the task of doing the core computations is best left to a dedicated mathematical software package, such as *Mathematica* or *Maple*. The advantage of having the mathematical software application do the work is that you have access to the full computational power of the application, and you can usethis power for performing a wide range of symbolic, numeric, or graphical calculations.

As we saw under Using MathML for computations, both *Mathematica* and *Maple* offer excellent support for MathML. Both can import data in the form of MathML, do arbitrary computations on the data, and then return the result back as MathML. This makes *Mathematica* and *Maple* well suited for integration with the Web. They can act as back-end applications that run on the Web server and perform computations in response to requests from client machines. Of course, some initial work has to be done to connect the various processes on the client and server sides. The typical steps involved in implementing this type of behavior are as follows:

- Create a Web page that allows a user to enter the data for a specific mathematical problem. You can specify the user input either via a forms-based interface that involves text areas, buttons, or menus, or via an equation editor-type applet (such as
*WebEQ*Input Control) that can translate mathematical notation entered by the user into MathML. - Set up the Web page so that the mathematical data is submitted to a Web server when the user performs some action such as clicking a button.
- Install a mathematical software application such as
*Mathematica*or*Maple*on the server. You then configure the application to receive the data submitted by the client and perform the desired computations on it. Some preprocessing may have to be done on the data to turn it into a form suitable for evaluation by*Mathematica*or*Maple*. - Return the result of the evaluation back to the client in a form suitable for display in a browser. Before the output received from the mathematical software can be displayed, some post-processing may have to be done on it. For example, if the result of the computation is a mathematical expression, the expression may have to be converted into MathML for display in the browser. Alternatively, if the computation involves generating a plot, the resulting graphic may have to be converted into a GIF or JPEG image and a link to the image inserted into the Web page.

Developing a Web site that allows users to do general mathematical computations is clearly a challenging task. Implementing all these steps starting from scratch would require a great deal of complex programming. A simpler option is to use a product such as *webMathematica* or *MapleNET* that provides a pre-built solution for delivering mathematical computations over the Web. These products provide a simple way to integrate an existing mathematical software package with a Web server to make computations accessible via a Web browser. The next two sections provide detailed examples of how to set up interactive Web pages using these products.

<< back | next >> |

**Copyright © CHARLES RIVER MEDIA, INC., Massachusetts (USA) 2003**

Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "The MathML Handbook" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

CHARLES RIVER MEDIA, INC., 20 Downer Avenue, Suite 3, Hingham, Massachusetts 02043, United States of America