next up previous contents
Next: Overview Up: Efficient Symbolic-Numeric Computations Using Mathematica. Previous: Contents

Introduction

This document is an introduction to the package Format.m. The main purpose of the package is to translate Mathematica expressions and assignments into C [10], FORTRAN77 [20], TEX[12] and Maple [17].

Mathematica has its intrinsic formatting rules, CForm, FortranForm and TeXForm etc. These often fail to give accurate and syntactically correct output and are somewhat limited in scope. These are compared and contrasted with output from the Assign functions of Format.m. It should be emphasised that some of the examples chosen to demonstrate shortcomings in the formatting rules are also valid for other symbolic packages. In fact, some of the features outlined are (as yet) unavailable in alternative symbolic environments.

There are traditional conceptions the roles and capabilities of compiled and symbolic languages. Commonly, symbolic computation programs are regarded as fairly limited in most of the following areas:

1.
Solving non-linear ODEs and PDEs
2.
Solving non-linear algebraic equations
3.
Solving non-linear optimization problems
These problems are the province of numerical computation, because adequate analytic solution methods may not exist and therefore may not be implemented in a symbolic computation package. However symbolic methods can be used to derive expressions necessary for performing numerical computations - such as gradients and Jacobian and Hessian matrices. Thus, the traditional roles of numeric and symbolic computation are not distinct and many benefits arise from merging the two.

Numerical computations in Mathematica (being an interpreted language) can be limited in use for large scale problems [30]. Mathematica is a useful tool for obtaining a quick formulation to a problem, but often involves high computational overhead when compared with compiled languages. Hence there is a need to translate symbolic code into a more efficient computational environment. It is believed that the integration of symbolic-compiled language environments will lead to many new approaches in areas of applied science and numerical mathematics [6,34].

There are two forms of communication process in Mathematica - structured and unstructured communication. Structured communication is achieved via MathLink [18]. The basic idea is to exchange complete Mathematica expressions to external programs which are specially set up to handle such objects. Structured communication via MathLink requires strong data typing for all information passed in the communication process and necessarily has a very complex syntax. Often there is no need to establish a two-way communication process, but what is required is the translation of symbolic code for use in an alternative environment.

Unstructured communication consists of sending and receiving ordinary text from external programs. The package Format.m is intended primarily for use with the Splice form of unstructured communication, but may also be used interactively within a Mathematica session. Splice is a one-way communication process which, the author feels, has not achieved it's full potential due to syntactical limitations in Mathematica's built-in formatting code. Format.m has been developed to address these issues.

The main ethos behind Splice is to set up a (generalised) template file containing a mixture of (active) Mathematica and (passive) compiled language source code. The template file is processed with Splice, which evaluates the active parts (the passive parts remain unaffected), producing a file consisting solely of compiled language code. It is important to emphasise the portability of the source code files. In general a template file to a problem is written, Mathematica then processes this file using Splice and the resulting file may be transferred to an alternative hardware platform for efficient execution.

By utilising the (numerous) available options, the functions defined in Format.m allow a high degree of user control. This enables precise formatting of expressions which eliminates the need for editing of the resulting code. The result facilitates the automation of code generation and the merging of symbolic-numeric environments built upon the existing interface and communication protocols.

The general design philosophy relies on attaching rules to functions in order to re-format them. This will ultimately result in longer execution times when compared with the built-in formatting functions. However, the goal is efficient and accurate compiled language code. It is anticipated that the compiled language code will be used extensively and may be executed many times. The small degradation in performance when translating code is a trade-off that is worth making, in order to provide more accurate and more flexible formatting tools. The current version of Format.m consists of over 1500 lines of code (including full on-line documentation) which is an indication of the complexity of the task involved.

There are several intended purposes for this documentation. Firstly it serves as a tutorial introduction to Format.m. Secondly it provides a comprehensive test suite which is used extensively in the development stages of the package. Thirdly, the package and examples are updated as new versions of Mathematica appear. The evolution spans several years including development and the documentation refers to the features and implementation strategies of the current version.

In the next section a summary of the main features of the Assign functions of Format.m is given along with the steps required for initialisation. The construction of the package is then briefly detailed, illustrating design decisions. Examples of interactive usage within a Mathematica session are given throughout and contrasted with the standard formatting rules. The implementation is broken down into several basic components which are outlined in detail in section 4. Extensions to other format types is demonstrated. A function with no current parallel in Mathematica, MapleAssign, has been added to translate basic expressions from one symbolic environment to another. The issue of optimization of computational sequences has also been addressed [29]. Optimization of the generated code can yield significant performance benefits and a brief introduction is given. Finally, some examples demonstrating practical usage of the symbolic-numeric environment are provided. The package has been developed and used extensively for research in numerical mathematics and examples are naturally taken from this area. There are many other potential applications.


next up previous contents
Next: Overview Up: Efficient Symbolic-Numeric Computations Using Mathematica. Previous: Contents

Jorge Romao
5/14/1998