In the course of doing mathematics, I make extensive use of computer-based calculations. There's one CAS that I use mostly, even though I occasionally come across out-and-out wrong answers.

After googling around a bit, I am unable to find a list of such bugs. Having such a list would help us remain skeptical and help our students become skeptical. So here's the question:

What are some mathematical bugs in computer algebra systems?

Please include a specific version of the software that has the bug. Please note that I'm not asking for bad design decisions, and I'm not asking for a discussion of the relative merits of different CAS's.

Judging by the answers below, maybe a better question would be not "What are some bugs?" but "Which websites have the most useful/comprehensive lists of bugs?".
–
David SpeyerJan 12 '10 at 15:36

11

This is possibly some sort of record: Richard Parker told me that he once typed "isprime(2)" as his first ever query to a certain computer algebra system, and got the reply "2 is not prime". He also claimed, probably correctly, that he could find a bug in any computer algebra system within 5 minutes.
–
Richard BorcherdsAug 9 '10 at 14:27

3

Richard's story is really surprising, because all systems I know will look up small primes in a table, so someone left off 2 from that table. It's possible, I guess, but really a silly goof.
–
Thierry ZellApr 27 '11 at 16:51

@fedja I disagree. It merely shows the reasonable state of affairs that someone expert in one field, having to borrow theorems from another field, may get a surprise.
–
Dan PiponiFeb 16 '10 at 19:29

133

The actual person at that "poor vendor" was me. I must have spent 3 days on this problem before I figured out that Jon had tricked me. And, indeed, I am an expert in computer algebra, but do not know much Fourier analysis. But Jon's proof for why this is 'correct' is quite geometrical.
–
Jacques CaretteFeb 17 '10 at 4:03

Because the most popular systems are all commercial, they tend to guard their bug database rather closely -- making them public would seriously cut their sales. For example, for the open source project Sage (which is quite young), you can get a list of all the known bugs from this page. 1582 known issues on Feb.16th 2010 (which includes feature requests, problems with documentation, etc).

That is an order of magnitude less than the commercial systems. And it's not because it is better, it is because it is younger and smaller. It might be better, but until SAGE does a lot of analysis (about 40% of CAS bugs are there) and a fancy user interface (another 40%), it is too hard to compare.

I once ran a graduate course whose core topic was studying the fundamental disconnect between the algebraic nature of CAS and the analytic nature of the what it is mostly used for. There are issues of logic -- CASes work more or less in an intensional logic, while most of analysis is stated in a purely extensional fashion. There is no well-defined 'denotational semantics' for expressions-as-functions, which strongly contributes to the deeper bugs in CASes.

I'm not claiming Sage is bug-free, but a lot of those bugs aren't mathematical errors -- there are plenty of compilation issues, documentation problems, etc., not to mention nearly 700 tickets classified as "enhancement" rather than "defect" -- so claiming 1582 known bugs is a little misleading.
–
Steven SivekFeb 17 '10 at 14:38

8

That is why SAGE and other OPEN SOURCE initiatives works great here: because implementation detail are publicly available ( as well as binaries, which allows testing for free). No secret methods, no unproven improvements without peer review...
–
kakazFeb 25 '10 at 15:20

10

But 'peer review' has essentially established (over 15 years ago) that the fundamental design of using untyped expressions when doing symbolic calculus (i.e. computing closed-forms) is unsound. SAGE does not fix that - so the fact that it is open source and publicly available changes that how? SAGE is, by explicit design, just as bad as the closed-source systems at analysis. While I am a definite fan of open source, I do not see how, in this case, that is actually relevant.
–
Jacques CaretteFeb 26 '10 at 18:07

In 1999, when I first bought an HP49G, whose major selling point was a CAS, I thought I'd try summing the harmonic series $\sum_{n=1}^\infty \frac{1}{n}$. I was a bit surprised to see the result 1151.8697216.

It turned out that it knew how to numerically compute the discrete antiderivative $\Psi(m) := \sum_{n=1}^m \frac{1}{n} \approx \ln m + \gamma$, and in the particular mode that it happened to be in, it would replace $\infty$ with the largest floating-point number it could represent, which was just under $10^{500}$. Indeed, $\Psi(10^{500}) \approx 500\ln 10 + \gamma \approx 1151.8697216$.

The story has a happy ending: after changing some flags, it returned $+\infty$.

A quite serious error in Mathematica 7 in my opinion is that it thinks $ \sqrt{x^2} =x$, not $|x|$, leading for example to 2 solutions to the following differential equation:
$$ y'(x) = 2 y(x) (x \sqrt{y(x)} - 1) \quad y(0) =1$$
Mathematica happily gives the following solutions:
$$ y(x) \rightarrow \frac{1}{(1-2 e^x +x)^2}, \quad y(x) \rightarrow \frac{1}{(1+x)^2} $$
Of course, it is a theorem that there is a unique solution to a differential equation of this type, but that doesn't mean my students hand in the wrong answer in droves...

Maple gets that one right. If the issues really is sqrt(x^2)=x, then Maple gets it right because I am the one who removed that assumption for the library in fall 1994 (Mike Monagan removed the buggy transformation from the kernel earlier that summer).
–
Jacques CaretteFeb 26 '10 at 16:36

3

Mathematica also gets it right: Simplify[Sqrt[z^2], Element[z, Reals]] returns Abs[z], while Simplify[Sqrt[z^2]] returns Sqrt[z^2] unevaluated. The bug must be in the code of Dsolve, that somehow does not use this fact.
–
Julián AguirreFeb 27 '10 at 9:10

A friend of mine told me about his experience with Maple (version 5 or 6, I think) when dealing with matrices over $\mathbb{Q}(\sqrt{2},\sqrt{3})$. When he computed the rank and the determinant for one particular $3\times3$-matrix, he was told that the rank was 3, and the determinant was equal to zero. The answer to this paradox is, that by default, for determinants the symbolic computation methods were used for radicals, and for ranks, the floating point representations of matrix elements!

This can be thought of as either a bug or his naiveness (for not checking out how to represent elements of number fields so that floating point representations never appear), but in any case is a serious argument for treating the computer algebra software with care...

Wait a minute, how the hell can a software written by someone with at least half a brain even try to compute rank using float computations?
–
darij grinbergFeb 26 '10 at 15:51

5

I wish I knew of this example when I was teaching linear algebra! I like to emphasize that someone must write all that magic software that makes the world go round, and it may well be them. Students nod sagely. Some of them later become programmers...
–
Victor ProtsakMay 25 '10 at 5:41

5

Just this week I graded a paper where a student started out with a 3x3 matrix with 2 repeated rows, very resourcefully did some row operations including division by 3, used rounding from a calculator, and managed to find an inverse for the original matrix... I had to go back to find out what the mistake was!
–
Pietro KCJun 10 '10 at 9:33

Correct: this is an unsolved problem. There is no theory of 'analytic' integration in closed-form, the only theory that exists is purely algebraic. And these algebraic theories all ignore branch cuts.
–
Jacques CaretteMar 3 '10 at 21:36

1

It does not seem to have been mentioned in the paper linked above that one reason behind the mishandling of these trigonometric integrals is in mishandling the Weierstrass substitution. I have seen the following paper: doi.acm.org/10.1145/174603.174409 but I have no idea what the state of the art is nowadays for such things.
–
J. M.Aug 2 '10 at 2:07

3

@J.M.: as far as I know, David's paper that you refer to above is the 'most recent' on this topic.
–
Jacques CaretteApr 27 '11 at 12:49

This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what letter is chosen for argument when calling it. In the simplest case it can be illustrated as follows:

in:

$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $

$A[k]$

$A[z]$

out:

$1/2 (-1 + k) k$

$z^2$

The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult. The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:

This story heard from Enrico Bombieri. I do not know if it qualifies, since it is not a CAS bug, and in addition it is second-hand. However it might be quite effective in casting doubt in the mind of your students, if that's your purpose :)

E.B. was doing some Riemann zeta zero crunching on his PC some years ago, the software he wrote seemed ok, and the next step was to run it on a mainframe to get some serious data. He was given the privilege to try it on the first Cray supercomputer. Most of the time results were nice, but every now and then he got really weird results. He and his coworkers spent some awful weeks trying to catch the bug. In the end, they cornered the problem: when the Cray divided 1 by 12 the result was a negative number...

EDIT: I double checked, it was not a Cray supercomputer but a computer based on an early iteration of the Pentium chip (I guess an IBM one), and the Pentium bug was also encountered by others of course. Sorry for the inaccuracy.

Here is an example in Wolfram Alpha.
A student had been given the assignment of finding the limit as $n$ tends to infinity of $\frac{1}{1+\frac{(-1)^n}{log(n)}}$. He had correctly arrived at the answer 1. Now he used WA to check if he was correct. WA returned 0 (the command lim n-> inf 1/(1-(-1)^n/log(n)) ). On examining the steps, it turned out that WA had manipulated a bit and used L'Hopital on the expression $\frac{log(n)}{(-1)^n+log(n)}$.

Note that if one instead asks for the limit of $\frac{1}{1-\frac{(-1)^n}{log(n)}}$ WA correctly returns 1, using the same method one usually would.

My advice is never to trust a single CAS. I only wrote one computer aided paper: I did the programming on Mathematica / Linux, and my collaborator did it on Magma / Solaris. We also made a point of not communicating while writing the programs.

Are you more trusting of Human Algebra Systems?
–
Kevin O'BryantJan 13 '10 at 4:33

14

Human errors when doing math tend to be very different then human errors when writing computer programs. The most famous example to how hard it is to write a correct program is binary search (see e.g. Bentley's "programming pearls", or Knuth TAOCP). It's a completely trivial algorithm, but try to code it - I promise you you'll get it wrong.
–
David LehaviJan 13 '10 at 7:34

7

I personally agree wholeheartedly here. Science grows on independent confirmation, as almost any part of the supply line can fail (software, compilers, hardware). As Mike Rubinstein put it (I think): Why do we trust software to compute zeros of $L$-functions? Well, we keep tweaking the program (that is, fixing bugs) until it gives $14.1347...$ for the Riemann $\zeta$-function, and then the same for all other cases... In other words, the answer it "correct" when it matches our expected reality. :)
–
JunkieMay 25 '10 at 6:17

If you are performing numerical computations, then a more likely source of error is in roundoff or over/underflow. In these cases, I wouldn't say that the CAS is necessarily in the wrong, just that you need to know the properties of the underlying algorithm and either recast your input or reimplement it in a more numerically robust way. In such cases, decent introductions to numerical analysis should give you a feel for the types of issues you need to worry about.

Of course, on the matter of symbolics, then there are no excuses for errors.

returns 0. But from the usual explicit formula for the Fibonacci numbers, which gives $F(n) \sim \phi^n/\sqrt{5}$, the output should be $\phi/\sqrt{5}$, or $(5+\sqrt{5})/10$. Replacing the built-in Fibonacci function with one that gives the explicit formula, and running the code

Actually, for any function unknown function P (where fibonacci is 'unknown' in this context since it returns unevaluated for symbolic arguments), <code>limit(P(n)*exp(-n),n=infinity)</code> returns 0. Polynomially descent to 0 is not enough, that will return unevaluated. I've reported the bug. The problem is that there is an implicit assumption in the implementation that unknown functions do not "grow too fast" (or go to 0 to fast or ...), which is clearly wrong. The theory for computing limits does not deal with unknown functions at all.
–
Jacques CaretteMar 3 '10 at 21:28

The functions Round, Floor, and Ceiling are the obvious functions, while "N" converts the infinite-precision expression to a floating point number (the last three lines are aimed at 2-digit precision, while the first three should be 16-digit).

The first three calculations turn up as "-480." The last three give more correct values of -$7.5*10^{-13}, 1.0, -7.5*10^{-13}$.

Very peculiar. So N[x] does its work with certain precision, while N[x,k] does its work aiming for a certain precision. I've been using Mathematica a long time, and never realized this.
–
Kevin O'BryantJun 11 '10 at 17:23

For all integers $n$, Coq proves $$n \mod 0 \equiv 0$$ and Isabelle proves $$n \mod 0 \equiv n$$ (The proofs are just stated in theorems, I can give the exact theorems if needed). Interesting, both proofs doesn't seem to lead to inconsistency though AFAICT they depict the usual mod.

The mod 0 example is interesting. One could argue that $mod 0$ is "not defined" and so one has a choice. E.g. some CA systems will raise an error if you use $mod 0$. Yet the definition I know is: $n \equiv m mod k$ iff $n + k\mathbb{Z} = m + k\mathbb{Z}$ (and $a mod k$ is the least integer $r\geq 0$ such that $a=kx+r$ for some $x$). This appears in many places, e.g. in group theory $C_k$ is the cyclic group of order $k$, but often $C_0$ then denotes the infinite cyclic group. Which makes sense if you set $C_k:=\mathbb{Z}/k\mathbb{Z}$. Isabelle agrees. Anybody know a why Coq does what it does?
–
Max HornOct 25 '11 at 11:35

Then integral[1,1] should be $1/2-2/\pi$, but Mathematica 8.0.1 returns $1/2+2/\pi$. Values for other $m$ and $n$ are also wrong (see the question linked above), as can be quickly verified by replacing the "Integrate" command with "NIntegrate".

Curiously, if one changes the limits of integration to {x,-1/2,1/2} and {y,-1/2,1/2}, then the correct answers appear.

I don't know how Mathematica handles this integral, but I wonder if it's somehow related to the problems mentioned in Kurt's answer in dealing with branch cuts symbolically...in this case the problem is at the point $(1/2, 1/2)$ and moving the limits around moves this to a corner instead of the middle of the interval.
–
Kevin P. CostelloMar 7 '12 at 20:56

The newsgroups may have hundreds of bugs, but they are buried in the midst of 10s of thousands of posts. Many are interface issues and most mathematical issues aren't bugs so much as behavior that was unexpected by a neophyte.
–
Kevin O'BryantJan 12 '10 at 13:36

Over the summer I came across an elementary bug in Magma when working with congruence subgroups of SL_2(Z). The isEquivalent function, which is supposed to tell whether two points are identified by a congruence subgroup, would miss a lot of identifications. For example:

G := CongruenceSubgroup(2); % \Gamma(2)

H := UpperHalfPlaneWithCusps();

(G! [-11,4,8,-3]) in G; % Cast this matrix into \Gamma(2)

true % It's really in \Gamma(2)!

(G! [-11,4,8,-3]) * (H! 3/8); % Have the matrix act on the point 3/8

oo % Magma correctly computes that it gets sent to infinity

IsEquivalent(G, H! 3/8, H! Infinity()); % Are 3/8 and infinity equivalent under the action of \Gamma(2), and specifically, can you given me a matrix representing an element of \Gamma(2) sending the former to the latter?

false
[1 0]
[0 1]
% Doh!

It's a pretty simple computation, and it was pretty clear what loop it was leaving out. We may have been running an old version of Magma, but anyway we reported the error to them, and they fixed it quickly, but I've never trusted computer algebra systems since!

My favorite Magma bug was when NthPrime(4) was 6. Supposedly, with NthPrime they implemented a system involving checkpoints and $x/log(x)$ estimations for $x\ge 10$, and then hard-coded the first few primes as: 2, 3, 5, 6. Oops...
–
JunkieMay 25 '10 at 6:20

As was noted for Sage, for any open source CAS you can just look up the issue tracker. For example, here's the list if all the issues in SymPy tracker with the WrongResult label: http://code.google.com/p/sympy/issues/list?q=label:WrongResult. Most of them are pretty rare. You're much more likely to hit a bug that just gives an error when it shouldn't, or that gives an unexpected, but not technically wrong (mathematically), result.

My advice is to double check your answer in some other way. The chances of the same bug manifesting itself in two different ways are almost zero. For example, you can check a result numerically, which will use a completely different algorithm from the symbolic version. Many CASs even have built in functions that do this for you.

David Bailey and Jonathan Borwein said in a talk yesterday that the most recent editions of both Maple and Mathematica give the nonsensical result $$\int_0^1\int_0^1|e^{2\pi ix}+e^{2\pi iy}|\,dx\,dy=0$$ I later verified this for Maple 17, entering int(int(abs(exp(2*Pi*I*x)+exp(2*Pi*I*y)),x=0..1),y=0..1).

During some experimentation on Mathematica, attempting to symbolically evaluate an alternating series for the Stieltjes constants (formula 16 in the link) returns "Indeterminate", apparently due to the software attempting to evaluate the derivative of Hurwitz zeta where it shouldn't.