\"\" \"\" \"\"
Go backward to Embedding External Applications
Go up to Building CONCERT Instruments
Go forward to Mathematica as a CONCERT Instrument
RISC-Linz logo

Embedding Mathematica

The use of Mathematica in mathematical education sessions is twofold:

  1. Using the notebook facility to display mathematical hypertext documents on screen ("presenter"),
  2. Using the interpreter to run program demonstrations and support interactive exercises ("executor").

However, since Mathematica notebooks may embed executable code, ultimately these issues cannot be separated.

Mathematica's MathLink facility allows to establish communication channels to external processes (also on remote hosts) on the basis of the IP protocol. By two-way communication, a Mathematica program thus may request services from external programs and vice versa. Communication routines on the Mathematica side take care for the proper serialization of Mathematica objects into byte streams that can be transmitted via channels; corresponding facilities are available for C/C++ applications using an external library.

The Mathematica kernel itself uses MathLink to communicate with Mathematica front ends. If the Mathematica kernel is started from within a front end, the kernel will be thus controlled through a MathLink connection to this front end. It is even possible to change in the middle of a Mathematica session the front end to which the kernel is connected by resetting the corresponding communication link.

Normally, the standard notebook frontend is used in Mathematica presentations. Notebooks (Mathematica hypertext documents) are composed of individual cells that may contain text, images, executable Mathematica code, etc. A session typically consists in the manipulation of the notebook navigating between the various cells and running embedded Mathematica programs. However, cells and notebooks are also Mathematica objects that can be manipulated by Mathematica programs themselves. Available operations include

To use Mathematica as a concert instrument in leader mode, it suffices to pursue the strategy outlined in the following figure:

We place between the Mathematica notebook frontend and the Mathematica kernel a control interface as a separate process which communicates with both processes via MathLink presenting itself as the kernel to the frontend and as the frontend to the kernel. Indeed when executed in asynchronous mode the task of the interface is just to forward the messages received in both directions.

However, when executed in leader mode the interfaces of the followers block all messages received from their frontends; instead they forward to their kernels the messages from the interface of the leader i.e. ultimately from the leader frontend. The outputs of the Mathematica kernels on all hosts are forwarded to their respective frontends.

The net effect is that all Mathematica commands generated by the leader are executed and the resulting output are displayed by the followers. Since this includes all notebook manipulations, distributed Mathematica presentations become possible. Neither frontend nor kernel require any changes, only the interface processes have to be provided and the appropriate connections have to be established.

However, in case the Mathematica notebook session involves input or output from respectively to files appropriate measures have to be taken to redirect those to the network database. Thus an interface has to be established such that Mathematica programs can read and update files stored in the database. Such an interface can be implemented by an external program with the help of MathLink such that opening a "network file" results in a local file copy that can be read and updated in the conventional way and closing a modified network file results stores the result in the database under a name incorporating the identifier of the component instance as a variant (in order to keep the files from different users separate). The lecturer thus can retrieve the results of her students' exercises.


Maintainer: Wolfgang Schreiner
Last Modification: March 11, 1997

\"\" \"\" \"\"