Theodore Gray

The Secret behind the Computational Engine in Wolfram|Alpha

May 1, 2009 —

Although it’s tempting to think of Wolfram|Alpha as a place to look up facts, that’s only part of the story. The thing that truly sets Wolfram|Alpha apart is that it is able to do sophisticated computations for you, both pure computations involving numbers or formulas you enter, and computations applied automatically to data called up from its repositories.

Why does computation matter? Because computation is what turns generic information into specific answers.

To give an amusing example, every school child has at one time or another written a report on the moon, and they probably included the wrong figure for how far the moon is from the earth. Why wrong? Because the distance from the earth to the moon is not constant: it changes by as much as a mile a minute. If you ask Wolfram|Alpha the distance to the moon, it tells you not only the conventionally quoted average distance, but also the actual distance right now, which can at times be well over ten thousand miles off the average. The actual distance is a figure that can be arrived at only by computation based on the moon’s known orbital parameters. It’s rocket science, if you will.

For a more down-to-earth example, consider the number of calories in a recipe. The underlying data are the calories per gram of each of the ingredients. But turning that generic information into the actual total calories for a specific recipe requires computation, first unit conversions (cups of flour into grams of flour, “one egg” into the default weight of a standard egg, etc.), then computation to multiply out the calories per ingredient and add them up. It may not be rocket science, but it sure is nice to have someone do the grunt work for you.

Each such computation requires a specific algorithm, and each of those algorithms has to be explicitly created. Of course many can be reused: units conversion or orbital mechanics, once implemented, can cover any unit or any planet. But nevertheless, enabling Wolfram|Alpha to do real, serious computations, covering a wide range of subject matters, required implementing literally tens of thousands of algorithms. Some are as simple as the quadratic formula; others are among the most sophisticated intellectual endeavors of our time.

The secret weapon that has allowed us, and no one else, to assemble such a vast library of algorithms, in such a diverse range of fields, is Mathematica.

Mathematica is familiar to scientists and engineers as the most powerful, most general tool for scientific computation, a role it has played since Version 1 was released in 1988.

Advanced Mathematica users appreciate that, aside from being an extremely powerful tool for one-off calculations, Mathematica is also a remarkably efficient programming language in which to implement complex algorithms.

The Mathematica symbolic language allows the user to express complex computational processes in a fluid, intuitive way, without having to worry about the ugly details of data structures, memory allocation, or confusing and inconsistent subroutine libraries. It is a language that feels very comfortable to subject-matter experts: people who know chemistry or economics, but not programming.

Mathematica‘s language is uniquely powerful in its ability to represent data of all kinds using arbitrarily structured symbolic expressions. Mathematica programs are not restricted to working with a limited set of data types, such as arrays or strings: creating expressions that represent the logical structure of non-numerical data, or even expressions that represent other programs, is possible more easily, uniformly, and deeply than anywhere else.

The fundamentally symbolic nature of the Mathematica language allows an unprecedented degree of interoperability between different parts of the system, and between different algorithms and data sources.

As a result, the five million lines of Mathematica code that make up Wolfram|Alpha are equivalent to many tens of millions of lines of code in a lower-level language like C, Java, or Python.

Mathematica is a very tall starting point from which to begin building Wolfram|Alpha (or anything else, for that matter). While Wolfram|Alpha contains tens of thousands of original algorithms, it also makes use of a comparable number already built into Mathematica.

The algorithms built into Mathematica include some of the most sophisticated ever developed, and they cover not just mathematical computation, but the whole spectrum of logical, numerical, graphical, symbolic, and other computation.

What can you do with such a wealth of algorithms?

For example, if you give Wolfram|Alpha a mathematical formula, a polynomial say, or something involving sines and cosines, it will give you back a number of useful results: a graph of the function, a list of its zeros, factored and expanded forms, and more.

And it will give you the derivative and integral of the function you entered. Now, computing the derivative of an arbitrary function is a straightforward process, but computing integrals can be among the most difficult problems in mathematics.

The general symbolic integration algorithm in Mathematica alone represents hundreds of man-years of development work by the world’s top experts in automated integration. Wolfram|Alpha shares this algorithm, and as a result there is literally no place on earth where you can get more functions integrated than in Wolfram|Alpha (except, of course, our own older service,, or Mathematica itself).

On top of this world-class algorithm, Wolfram|Alpha adds a very nice touch: a “Show steps” button that gives you a step-by-step explanation of how to arrive at the answer. This enhancement, like the underlying integration algorithm, is written in Mathematica language code, and it’s frankly hard to think of any other way it could have been done, given reasonable time and resources.

This is the essence of what has made Wolfram|Alpha possible. It’s not so much that it would have been impossible to do without Mathematica, but that it would have been impractically difficult. In fact, the easiest way to create Wolfram|Alpha without Mathematica would have been to write Mathematica first, then use it. Which is precisely what we have spent the past 23 years doing.

Wolfram|Alpha is in a sense the “killer app” for Mathematica. It is a chance for Mathematica to show off the astonishing range of things it is capable of doing when it is deployed, not against a specific problem, but against all problems.