|
MathLink, J/Link, and webMathematica® |
webMathematica is a registered trademark of
Wolfram Research Inc.
(Return to Introduction to Mathematica)
(Go to webMathematica demos)
|
For tasks requiring interfaces to the external environment Mathematica provides MathLink, which allows Mathematica programs to communicate with external programs or vice versa. MathLink can be used with programs written in C, Java, or other languages. J/Link is an extension of MathLink providing additional power and ease-of-use to programmers using the Java language. Using J/Link and JSP (Java Server Pages), webMathematica provides the capability of creating pages with dynamic, interactive mathematical content on the Worldwide Web. Integrating Mathematica with other languages: MathLinkThe diagram below shows the overall architecture of Mathematica. "Lightning bolts"
show communications links, double-headed arrows indicate direct program calling:
MathLink is an open API, and it may be used for other purposes as well. For example, if someone wanted to create a different, perhaps enhanced, front end for Mathematica, this could be done using MathLink. A more common use of MathLink is to allow external programs access to Mathematica computational functions, or to allow Mathematica to access external functions. Typical uses might include:
Though MathLink is a C API, it can be used for other languages; even (with a small translation module written in assembler) languages that do not use the C calling conventions. For more information on MathLink, there is documentation and sample code in the /AddOns/MathLink directory that comes as part of Mathematica. There's also a good book, MathLink: Network Programming with Mathematica, by Chikara Miyaji and Paul Abbott. Extending MathLink: J/LinkWolfram Research developed a very nice integration of MathLink with Java, called J/Link. It has excellent facilities for linking Mathematica to Java, or vice versa, and is well-documented and easy to use. In addition to providing a high-level interface to MathLink, it also adds classes to Java for such things as displaying Mathematica graphics and typeset expressions in a Java window. This diagram shows the relationship of J/Link to Java, MathLink,
and other components:
Unless you really need C, J/Link is a better alternative for most of the things you might want to do with MathLink. More detailed information on J/Link can be found on the Wolfram Research web site. Mathematica on the web: webMathematica
The following diagram illustrates how webMathematica is supported by a web server/Java
servlet combination such as Apache Tomcat:
Similarly, a request from a web browser with the suffix .msp is directed to an instance of the MSP class (supplied as a component of webMathematica). The MSP instance acquires a Mathematica kernel instance from a shared pool, and uses J/Link to execute Mathematica functions coded in the MSP (Mathematica Server Pages) script language. The result is incorporated in the HTML response to the client browser. MSP looks a lot like standard Mathematica code imbedded in HTML. As an example, here is a fragment of code from an MSP script that fits a Weibull distribution to empirical data:
<%Mathlet Needs["Reliability`"]; %>
Anything between <%Mathlet and %> is MSP code executed by the Mathematica kernel; anything else is HTML which is passed unchanged to the client browser. There are webMathematica examples on this site. Additional examples and more detailed technical information on webMathematica can be found on the Wolfram Research web site. |