Computer Science with Mathematica - Preface

This book provides an introduction to computer science, and shows how modern computer-based tools can be used in science, mathematics, and engineering. Computer-aided mathematics has reached a level where it can support effectively many computations in science and engineering. In addition to treating traditional computer-science topics, an introductory book should show scientists and engineers how these computer-based tools can be used to do scientific computations. Students must get to know these possibilities, and they must gain practical experience. Learning a traditional programming language becomes less important, just as learning arithmetic is not a main topic of mathematics education. In an introductory book, it is clearly necessary to limit ourselves to a small part of the huge field of computer science. We emphasize topics that are related to possible applications in mathematics and the sciences. Technical and practical computer science have therefore been neglected.

It is certainly worthwhile to combine an introductory computer-science course with exercises. In the same way as we learn a foreign language by speaking the language and by studying literature in that language, we should apply algorithmic knowledge by studying programs and writing our own. If we can solve an interesting problem from mathematics or the sciences at the same time, all the better! Traditionally, such introductory courses use languages such as Pascal, C, or Fortran. These languages have in common that the effort to develop even a small program (one that adds two numbers, for example) is considerable. One has to write a main program that deals with input and output, and to compile the program. Furthermore, these languages cannot be used easily to solve nonnumerical problems. Leaving aside these practical difficulties gives us room to look at other topics in computer science, an extension that is not offered in traditional programming courses. In this way, we gain insight into computer science, which consists of much more than writing small programs.

Another disadvantage of traditional languages is that they support only procedural programming. This style is an important one, but it is not the only option and it is not always the best approach. I prefer a language that does not force this programming style on programmers. The programming style should be chosen to fit the problem to be solved, rather than vice versa. The language should be interactive, to encourage experimentation and to allow us to call individual functions without having to write a whole program.

Mathematica was first released in 1988, and it is being used with increasing frequency in teaching, research, and industry. A by-product of the symbolic computation system, it is a programming language that differs from traditional languages in many important ways. Conventional languages are not well suited to expressing mathematical formulae and algorithms. Lisp and other functional languages showed alternatives. An important aspect of scientific computation is an easy way to express mathematical rules. Application of rules by machine requires good pattern-matching capabilities of the kind found in Prolog. Another prerequisite is that it be simple to manipulate structured data. Such structural operations have been pioneered by APL. Object-oriented elements and modularization are important tools for developing larger projects. Ideas were taken from Simula, Smalltalk, and C++. We also want to support traditional procedural programming in the style of Pascal and C. All these objectives lead to a large language with many built-in functions. It nevertheless has a consistent and uniform style, made possible through the use of rewrite rules, which underly all other programming constructs. Such a language is also interactive and therefore easy to use. It is not necessary to compile functions or to embed them into a main program to use them. The additional step of compilation increases the difficulty of program development and requires special tools (debuggers) to study the behavior of programs.

Because Mathematica also contains most operations needed in mathematics and physics, it is especially well suited for an introductory course in computer science for readers interested primarily in the sciences and engineering. It allows us to treat interesting examples easily. There is no good reason, for example, to restrict the range of integers to $2,147,483,647$, as is done in most programming languages. This restriction makes no sense in mathematics. Programming with recursively defined functions is often treated as extraordinary and difficult. We can express naturally many mathematical algorithms, however, by using recursion, and it should be possible to formulate recursion easily in a language. For example, the properties of the greatest common divisor of two integers leading directly to Euclid's algorithm,

GCD(a, b) = GCD(b, a mod b)
GCD(a, 0) = a
can be expressed verbatim in Mathematica and tried out immediately. As in Lisp, the technique of tail-recursion elimination in Mathematica ensures that the corresponding program runs as fast as the loop that is normally used (which is not the case in most procedural languages). Deriving the loop invariant and programming the same function as a loop leads naturally to systematic programming and considerations of program correctness.

Mathematica is helpful in all areas of computer use in mathematics, in the sciences, and in engineering:

This book grew out of class notes for a course given at the Department of Mathematics and Physics at the Swiss Federal Institute of Technology, Zurich. It was originally published in my native German language, and I am glad to present now my own English translation and adaptation.

I am thankful to Erwin Engeler, John Gray, and Stephen Wolfram for their inspiration and many interesting discussions. Helpful suggestions on particular topics came from R. Marti and H. Mössenböck. Lyn Dupré proofread an early version of the manuscript, and Karen Tongish copyedited the final version. The publishers of the German and English editions, Ekkehard Hundt and Alan Harvey, helped me to keep going. Many thanks to the anonymous reviewer whose favorable comments and useful suggestions motivated me to finish this project.

R.E.M
Wollerau, March 1999

Back to book's home page
Rev. 1.0, REM, © 2000 Roman E. Maeder