webMathematica Basics

Tom Wickham-Jones
Director of Kernel Technology
Wolfram Research

This talk provides an introduction to webMathematica. It will discuss the basics of webMathematica, including installation, getting started, and developing basic material.

Please note that this notebook is optimized for display by Mathematica 4.2. Also that it may refer to hyperlinks that are not included in the file archive.

Initialization

Off[General::spell];
Off[General::spell1];

SetDirectory[
        DirectoryName[
          ToFileName["FileName" /. 
              NotebookInformation[ SelectedNotebook[]]]]];

What is webMathematica?

Allows computations and visualizations to be added to web sites. It integrates Mathematica with a web server.

Built on a Java web technology called Java servlets.

Servlets: special Java programs that run on a web server machine. Support is provided by a separate program called a servlet container (or sometimes a "servlet engine").

Essentially all modern web servers support servlets natively or through a plug-in servlet container. This includes Apache, Microsoft's IIS and PWS, Netscape Enterprise Server, iPlanet, and application servers  (such as IBM WebSphere).

One particular way to run servlets is Apache Tomcat, the reference implementation of servlets and JSPs. Can run as a standalone HTTP server or via some other server.

Some basic examples of webMathematica.

Mathematica Server Pages

webMathematica driven by a technology called Mathematica Server Pages (MSPs). Inserting Mathematica commands into HTML pages, a form of HTML templating.

MSP scripts, easy to write, fit well with HTML development tools such as editors.

<form action="Expand" method="post">
      Enter a polynomial (eg x+y): 
      <input type="text" name="expr" size="10">
      Enter a positive integer (eg 4):
      <input type="text" name="num" size="3">
      <br/>
      
      <%Mathlet
             MSPBlock[{$$expr,$$num},
                     Expand[$$expr^$$num]] %>
                     
      <br/>
      <input type="submit" name="button" value="Evaluate">
	</form>

Standard HTML except for Mathlet tag (uses FORM/INPUT elements).

Many Mathematica commands for web requests and responses for plotting, formatting and typesetting, embedding applets, returning general content.

Technology Overview

An overview of a request.

Session Manager. Launches and initializes Mathematica. Shuts down sessions that exceed some preset limit for computations. Highly configurable.

Security. Typical web security, security system for Mathematica, prevents 'dangerous input'.

Input. HTTP input, set name/value pairs, on the URL or in HTTP header.

Results. Any result that Mathematica can generate: HTML, MathML, XML, images, Mathematica notebooks. Integrate with applets, javascript, plug-ins, Active-X controls, and rich web clients.

Equipment

In order to run a webMathematica site the minimum technical components are:

○ A Servlet Container supporting the 2.0 API (or higher)

○ A Java Runtime Environment (JRE) 1.1 (or higher)

different combinations of hardware and operating systems:  most systems that run Mathematica will support webMathematica. Focus on Intel/Windows, Intel/Linux and Sun/Solaris. Other platforms possible but less tested.

Setting Up/Contents

Setting up webMathematica: install and configure a server that supports Java servlets. Then install webMathematica tools on the server.

Tools contain all material for site, including:

○ A Mathematica application. Support for the Mathematica commands.

○ A Mathematica session manager. Software for launching and shutting down Mathematica sessions, as well as support for configuring and monitoring.

○ A Web Application. An application for loading into the servlet container.

○ Example MSP scripts (many).

○ Sample configuration files.

○ Extensive Documentation.

○ Applets.

○ Images.

Uses of webMathematica

Puts Mathematica on the Web

Features include, computation, visualization, programming, connectivity, the Mathematica frontend and mathematical typesetting. We should see examples of these today.

Mathematica contains large collection of functions for calculating in many areas: all available over the web. Important since many web technologies are not focussed on scientific/mathematical computation. Mathematica designed for this work.

Mathematica visualization functions offer a quick and simple way to get plotting done on a web site.

Mathematica contains a high level, interactive, functional programming language. Good for rapid prototyping but scales to large computations. Carry over to web content generation: significantly reduce the time spent developing site.

Mathematica premium system for interactive mathematical typesetting. Also a powerful system for working with MathML. As MathML becomes important Mathematica will benefit from features.

Integrate Mathematica notebook interface as a document mechanism into web sites.

Web Interface Benefits

Ease of use. People typically learn web technology at early stage, need less training with web based applications.

Web applications can provide a very structured interface.

Configuration benefits from  server arrangement; everything on server, updates and fixes in one central location. In addition.

Installation considerably simpler, delivery HTML, JavaScript functions or Java applets standard solutions.

Lots of standard technologies, for controlling and monitoring access and in general developing web sites.

Current Applications

Some of the current application areas of webMathematica include:

Many of the early adopters had educational applications. Use to deliver sophisticated courses over the web, important for distance learning.

Naval Postgraduate school, US Naval Academy, University of Texas system, UC-Davis, University of Ohualu Finland, University of Arizona (optics).

Also important for early adopters. Researchers and scientists can showcase their Mathematica-based work using interactive web calculators.

University of Newcastle (UK) gerontology dept., Technical University of Berlin, many others.

Authors and publishers can publish live interactive technical books,  supplements and journals over the web with webMathematica.

Addison-Wesley are the biggest actors here, they are about to release a site built around webMathematica technology.

New element in computational tools, any institution that uses a tool such as Mathematica can deploy computations with web access for forecasting, modelling, and so on.

Sun Microsystems, Merck, Zeneca, EADS all working with webMathematica technology.

Similar for on-line computation.

Norwich Union (3rd insurance co in the UK), Nomura, UBS Warburg, Reuters Consulting. Also consider the webUnRisk application. Also Enron and Andersen!

webMathematica vs Mathematica?

Based on same technology, but fundamentally different user interfaces and aimed at different users.

webMathematica offers access to Mathematica through a web browser. Calls on all of Mathematica.

webMathematica gives familiar (web) interface that requires little training to use effectively. Users do not need any familiarity with Mathematica.

webMathematica obviously very suited to highly distributed environments. (Benefit of web technology.)

Mathematica is like a development environment for webMathematica. For example, analysts would use Mathematica to develop models, engineers would run these using webMathematica.

Developing for webMathematica

The ease of MSP technology is one of the strengths of webMathematica.

Requires an understanding of HTML, eg HTML forms.

Requires an application for webMathematica.

A computation for Mathematica to deliver over the web.

Writting a new MSP

Here is an example that I worked on recently.

First, find an example...

Basic formula for a loan after n months, principle, prin, repayments, pay, annual rate, r.

(E^(n r/12)) prin - (((-1 + (E^(n r/12))) pay)/(-1 + (E^(r/12))))

Amount ⟹ zero,  compute  monthly payments.

Solve[(E^(n r/12)) prin - (((-1 + (E^(n r/12))) pay)/(-1 + (E^(r/12)))) == 0, pay]

Basic mortgage formula, easy to compute. Many on-line web tools that do this.

Suppose know the monthly payments, want to solve for rate of return.

Solve[(E^(n r/12)) prin - (((-1 + (E^(n r/12))) pay)/(-1 + (E^(r/12)))) == 0, r]

E.g. evaluate an annuity product...  compute a notional rate of return.

Mathematical techniques:  a Newton method, in Mathematica done with FindRoot.

returnRate[prin_, pay_, n_] := 
  FindRoot[E^((n*r)/12)*prin - ((-1 + E^((n*r)/12))*pay)/
      (-1 + E^(r/12)) == 0, {r, 0.5}]

If the annuity comes to an end in 10 years, you get

returnRate[100000,  1000. , 120]

Visualize return.

Plot[r /. returnRate[100000, 1000. , 12 x], {x, 5, 20}, 
        PlotRange -> {-0.1, 0.15}];

Put Code into an MSP

Now, we can put this computation into an MSP.

Here is a complete example: http://localhost/webMathematica/MSP/Finance/Annuity.

I've added some web design, by modifying one of the page templates. A quick way to make good looking pages.

Further Examples of webMathematica

Star charts

Blackbody Radiation

Epidemic

Option Computation

Chemical Reaction Rates

Field Pattern

Signal Averaging

webMathematica Licensing

There are two licenses for webMathematica. Note that the number of users of your web site does not influence the license.

This is a low-cost version intended for non-commercial use. Web sites must display a webMathematica banner and must be freely accessible.

The Amateur license is provided as a benefit of Mathematica subscription, premier service. Certain special purchase programs provide a number of webMathematica Amateur licenses.

This is for restricted web sites, commercial or in some type of intranet. If the site is part of the materials for an on-line course restricted to particular students, this would need the Professional version.

The professional license also has some restrictions: sites cannot allow general Mathematica access and cannot replicate Mathematica 'look and feel'.

The cost of a professional license is a premium over regular Mathematica, but remember that volume discounts apply. If you are part of a special purchase program with discounts, which can be significant, these will apply to webMathematica.

The Number of Processes

Automatic Mathematica pooling: requests take Mathematica sessions until none are available; further requests wait. Several computations done at the same time.

Works with multiple Mathematica processes, the optimal number very difficult to determine: many different parameters and no simple formula.

On a single CPU if you run one Mathematica calculation that takes 20 seconds, the same calculation run simultaneously on 10 Mathematica processes will take 200 seconds.

Multi-processor machines benefit from as many Mathematica licenses as processors.

Major factor is the time for computation in Mathematica, measure the Timing command. webMathematica gives very efficient access to the Mathematica.

Scales linearly with the time for computations and the number of computations. Thus no hidden bottle necks and performance problems solved by improving hardware.

Using webMathematica

People ask 'How easy is webMathematica to use?'

Simple answer, the more you know about web technology the more you can do.

You must learn about HTML, and forms.

If you want to use JavaScript you must learn about JavaScript.

Most of the best webMathematica sites are built by people who have learnt web basics.

Summary

Allows a web server to generate computations and visualizations with Mathematica. Rare to find server technology from a computation application.

Driven by a technology called Mathematica Server Pages technology. Easy to mix Mathematica and HTML.

Quick and simple way to add plotting to your web site.

Generate results of many different formats (not only HTML). Generate a document format, eg Mathematica notebooks.

webMathematica contains everything to add into a Java servlet enabled web server.

More information on webMathematica:   http://www.wolfram.com/products/webmathematica