# Constructing Mathlets using JavaMath

## Abstract and Introduction

### Abstract

Sophisticated mathlets and Internet accessible mathematical services sometimes require server-side support from a computer algebra system, and the JavaMath API provides the necessary infrastructure. In this article, the use of JavaMath is explained via an example and ideas for new types of web service are discussed.

### Introduction

There are many Web pages with interactive mathematical content, but most such pages are limited to interactivity which can be achieved entirely at the browser side. The few applets, such as various CECM interfaces, the Tübingen Parallel Gröbner Bases service [link no longer exists, 12/10/04], the Mathematica-based Integrator and Mathserv, which have employed sophisticated interaction with a compute engine on a server, have generally not promoted their techniques in the form of a published API (application programming interface). The one early attempt we are aware of to present these techniques as a reusable library is the Interactive Mathematics Server WIMS. Characteristic of all these applications, using CGI scripts has allowed only batch- rather than session-based interaction with a compute engine. Therefore, the only way to perform a multi-step calculation is to represent intermediate results in the CGI script and feed them back into the compute engine when it is restarted.

In 2001 the situation has begun to improve with the release of WebMathematica and JavaMath. Both tools employ Java Servlet Technology to make routine the construction of server interactive mathematical Web resources. The sequel is a guide to the use of JavaMath once it is installed on the server and an explanation, in practical terms, of the issues encountered when constructing mathematical web services which make a system such as JavaMath necessary.

For information on getting started with JavaMath refer to the installation instructions and the on-line tutorial. To learn about the technology behind JavaMath refer to this report on the architecture of JavaMath.

## Server Interactive Web Pages I

### Adding Symbolic Computation to the Graph Explorer

An important feature of the JavaMath API is the ease with which it permits calls to a compute engine to be incorporated into an applet. To demonstrate this, we took as a starting point the first named author's mathlet, Graph Explorer.

The existing Graph Explorer has been used to support on-line labs for secondary school and college precalculus students. It accepts user input of the formulae for functions, uses Java code to parse the formulae, and plots their graph in a panel with various controls for zooming and panning. It also recognizes and gives user control over variable parameters in the equation, but it does not have any symbolic manipulation capability. By adding Maple calls via JavaMath, we were able to quickly add the code needed to obtain the exact formula of each root and display it as a label on the x-axis. Click here to try the new version of Graph Explorer.

The key to this was the provision by JavaMath of appropriate supporting classes. In particular, after having imported the package

import javamath.proxycas.*;



ProxyCAServer proxyCAServer =
new ProxyCAServer("http://dev.camel.math.ca/ProxyCAS");

proxyMapleSession = proxyCAServer.createSession("Maple");



we were able to evaluate any Maple expression with a line of the form

resultString = proxyMapleSession.nativeEvaluate(inputString);



To enable the reader to gain confidence with using the JavaMath API, we have made available the source code and jars for this applet, which the user may run as a stand-alone Java application and experiment with the JavaMath server.

These pages also contain another applet that uses JavaMath to call the Maple-based RevEng for generating exact expressions for special points that fall within a user-chosen segment of the number line. The Maple session is called repeatedly as the user zooms and pans along the line.

## Server Interactive Web Pages II

### Group Character Tables on the Web

This section discusses the complex design issues encountered when creating the Character Table web service, a project initiated by the second named author. [The project link no longer exists. Contact the author for more information. Ed., 12/13/04. ]

A great deal of information about a group can be gleaned from the character table, while character values are needed in many applications of group theory, for instance in computing non-abelian Fourier transforms used in statistics. Other applications are in physics, crystallography and chemistry where low dimensional group representations are of especial interest since they control the ways in which a group might appear as the symmetries of a physical system.

The computer algebra system GAP contains a powerful implementation of the Dixon-Schneider algorithm for computing the character table of a concrete group, given for instance by permutations, and also a very large library of known character tables, including all those in the Atlas of Finite Simple Groups. The format of the tables is derived from that used in the Atlas, and is described in detail in the GAP documentation. The Dixon-Schneider implementation draws on all of GAP's general group theoretic machinery, and also on its capabilities in linear algebra and finite fields.

The aim of this project was to make GAP's character tables available on the Web to researchers outside the core of computational group theory who don't want to spend the time downloading and installing GAP and learning its syntax.

The Web pages have two types of input. You may enter a list of permutation generators for the group whose character table you wish to retrieve, or simply the name of the character table. When the go' button is pressed, a new browser window is opened in which the character table is displayed.

This application required two attempts to write. In the first attempt, the applet in the client's browser directly accessed the compute server creating a group in OpenMath, and retrieving its character table in OpenMath. Then it called on a MathML rendering engine to display the character table in the browser in a Swing table.

The problems with this implementation were twofold. Firstly, because it accessed the server and session classes directly using Java RMI, it depended on having an implementation of RMI in the browser's JVM which Internet Explorer 5 doesn't have. The second problem was that rendering the character table in the applet made use of the PolyMath OpenMath phrasebooks, an XML library, WebEQ -- a MathML rendering engine and Java's Swing libraries which meant loading several megabytes of jar files along with the applet into the client's JVM, making it very slow to load on an Ethernet connection, and virtually impossible over a 56k dial-up connection.

The solution to these problems reflects the reality of the Web at the moment and not the possibilities for the future, however it has proven that the Web is already a feasible medium for delivering dynamically generated mathematical content.

Firstly we scaled back our aspirations for presentation from MathML embedded in a Swing table to a choice of HTML or XML/OpenMath in case the user wants to paste the object into other applications. MathML rendering will be feasible once browsers have MathML rendering engines built in, rather than having to load rendering classes across the internet. This is already realized in the experimental browsers Amaya and Mozilla but is not yet in the mainstream browsers Netscape and Internet Explorer.

Even with our retreat from MathML, the XML library was required to render the character table, so we decided not to render it in the browser but in a servlet on the server, where the XML libraries were already installed. Further, the default jar files for the PolyMath Java Library are unnecessarily bloated for simply representing permutations, so the permutations were represented in the applet as Java vectors.

In the following paragraph we describe the dataflow, which is complicated by the need to minimize the amount of code which is transferred to the client side. However, we feel it is justified given a reduction in code transferred from several megabytes to under 20 kilobytes.

The applet stores the permutations on the server using an HTTP proxy to an RMI accessible hash table (this functionality is built into JavaMath). Then the servlet converts the vectors into OpenMath represented permutations, constructs a permutation group as an OpenMath object, and sends that to the GAP session to compute the character table. The character table is returned to the servlet as an OpenMath object which the servlet then renders according to the user's choice.

The code for this web service may be inspected at the Sourceforge CVS repository.

## Services to Augment a Computer Algebra System

Instead of interacting with web pages, it is often preferable to use the familiar interface of our favourite computer algebra system (for instance Maple or GAP) to perform a mathematical computation. This means that the mathematical software developer has to choose between writing a piece of software once making it available in a web page (thus creating a less convenient product), or writing it separately for each computer algebra system in use by the target audience.

With JavaMath there is a "middle road", to wit, one can construct an internet service accessed via a computer algebra system using the HTTP protocol, requiring only a light-weight interface between the computer algebra system and the internet service.

Ralph Freese's LatDraw applet renders a Hasse diagram in 3-space when presented with a file in a special input format. We have used LatDraw as a starting point to create the internet service Hasse. [The project link no longer exists. Contact the authors  for more information. Ed., 12/13/04. ]  In addition to the original functionality, Hasse provides a Web service enabling users of Maple and GAP to visualize Hasse diagrams with a single command. For example, executing the following Maple code, opens a browser window in which the Hasse diagram is displayed.

read("om-lite.mpl");

# a basic hasse diagram
h := [[0,[a,b]],[a,[1]],[b,[1]],[1,[]]];
DrawHasse(h);

`

One might wonder why this needs to be a web service rather than installing it as a Java application on the client's machine. The answer is twofold. As a web service, it is automatically updated when improvements are made, and due to the use of OpenMath/XML (see below) it would require quite a complicated Java installation on the client machine.

The reason we had to move from using the special file format above to the XML/OpenMath standard is that vertex names generated by a computer algebra system will often fall outside the range of those permissible in the special file format. But then, an XML/OpenMath parsing package is required to deal with the input to the applet. This is both difficult to install (making it infeasible to distribute) and too large to include in an applet's jar.

The solution we were forced to construct appears rather gymnastic, but the steps below are quite straightforward when using JavaMath.

• client (e.g Maple) displays the Hasse diagram (as OpenMath) in a web page for the user to inspect and assign a name to the diagram;
• when the user submits the form, the diagram is sent to a servlet on the server. This servlet: