I've been wondering this for a while now: How was Mathematica built?

Is it written in Haskell? C++? I'd love to get a taste of the wizardry behind this incredible software.


1 Answer 1


In the Mathematica book (5th edition), Stephen Wolfram writes the following (sec. 1.12.4):

The Software Engineering of Mathematica

Mathematica is one of the more complex software systems ever constructed. Its source code is written in a combination of C and Mathematica, and for Version 5, the code for the kernel consists of about 1.5 million lines of C and 150,000 lines of Mathematica. This corresponds to roughly 50 megabytes of data, or some 50,000 printed pages.

The C code in Mathematica is actually written in a custom extension of C which supports certain memory management and object-oriented features. The Mathematica code is optimized using Share and DumpSave.

In the Mathematica kernel the breakdown of different parts of the code is roughly as follows:

  • language and system: 30%;
  • numerical computation: 25%;
  • algebraic computation: 25%;
  • graphics and kernel output: 20%.

Most of this code is fairly dense and algorithmic: those parts that are in effect simple procedures or tables use minimal code since they tend to be written at a higher level—often directly in Mathematica.

The source code for the kernel, save a fraction of a percent, is identical for all computer systems on which Mathematica runs.

For the front end, however, a significant amount of specialized code is needed to support each different type of user interface environment. The front end contains about 650,000 lines of system independent C source code, of which roughly 150,000 lines are concerned with expression formatting. Then there are between 50,000 and 100,000 lines of specific code customized for each user interface environment.

Mathematica uses a client-server model of computing. The front end and kernel are connected via MathLink—the same system as is used to communicate with other programs.

Within the C code portion of the Mathematica kernel, modularity and consistency are achieved by having different parts communicate primarily by exchanging complete Mathematica expressions. But it should be noted that even though different parts of the system are quite independent at the level of source code, they have many algorithmic interdependencies. Thus, for example, it is common for numerical functions to make extensive use of algebraic algorithms, or for graphics code to use fairly advanced mathematical algorithms embodied in quite different Mathematica functions.

Since the beginning of its development in 1986, the effort spent directly on creating the source code for Mathematica is a substantial fraction of a thousand man-years. In addition, a comparable or somewhat larger effort has been spent on testing and verification.

The source code of Mathematica has changed greatly since Version 1 was released. The total number of lines of code in the kernel grew from 150,000 in Version 1 to 350,000 in Version 2, 600,000 in Version 3, 800,000 in Version 4 and about 1.5 million in Version 5. In addition, at every stage existing code has been revised—so that Version 5 has only a few percent of its code in common with Version 1.

Of course, this is already quite some time ago, but much of this still holds. Line counts have increased tremendously, and parts in Java have been added.

  • 3
    $\begingroup$ The Import function uses Java for translation of data from foreign file formats. This can be frustrating if insufficient memory has been allocated to Java, or if other limitations prevent the JVM from working as expected. $\endgroup$ Feb 9, 2016 at 21:40
  • 4
    $\begingroup$ @Chet Mathematica is all about functional programming (and more), but that doesn't mean it should be necessarily be implemented using a functional programming language. C happened to be a very popular programming language at the time Mathematica was developed and it tends to produce fast compiled code too. "Kernel" refers to the part of a typical Mathematica installation that handles most of the calculations that the user instructs Mathematica to perform. Nowadays you may encounter it under the name of "Wolfram Engine" or so. The other part is the Frontend which deals with the GUI stuff. $\endgroup$ Feb 9, 2016 at 21:48
  • 6
    $\begingroup$ @Chet: the first version of Mathematica was released in 1988. At that time, C++ was practically unusable for developing highly portable multi-platform systems because of the extreme degree of incompatibilities between different compilers and platforms, Haskell, Java, C#, Python, Ruby, etc. didn't exist yet. The Self VM, the fastest Smalltalk VM ever created was released in 1987, and was actually able to beat the C++ implementations available at that time, but it took until the 1990s until that technology ended up in real-world Smalltalk systems with the Animorphic Smalltalk VM, which however … $\endgroup$ Feb 9, 2016 at 23:09
  • 4
    $\begingroup$ … was Windows-only. So, the only viable OO language at that time would have been Objective-C, but that was a niche language. C++ was unusable, Haskell didn't exist yet, Smalltalk was not very popular in the computer algebra / computer mathematics scene. The only two obvious choices would have been Lisp and C, but again: Common Lisp had only been specified in 1984 (and the ANSI version in 1990), and there weren't implementations available for many platforms. Other Lisps were usually tied to one platform. C was pretty much the only portable option besides Smalltalk. Prolog might have been an … $\endgroup$ Feb 9, 2016 at 23:14
  • 1
    $\begingroup$ … option, though, but probably too limited when it comes to GUI bindings(?). $\endgroup$ Feb 9, 2016 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.