Richard Neidinger
5/31/01

Do you think you understand enough about how computers and calculators find numerical solutions for real number problems?  Try to compute on your favorite calculator or computer.  If you are lucky, it will indicate an error.  Even Mathematica 4.0 reports wrong answers as witnessed below.

### Trig Functions of very large arguments

The following answers were computed in Mathematica 4.0 -- and are totally WRONG!

#### Neither of the above are reliable, here's the correct value:

The following asks that the exact value Sin[Exp[40]] be computed with the ANSWER precise to 18 digits.

Mathematica operation N[___, m] will give reliable answers by using advanced software algorithms to compute to the desired precision for any m>16.  If the m argument is missing (N[___]), or for m<=16, Mathematica will use hardware computations where each value is restricted by hardware to have about 16 significant digits.  This is not enough digits to compute as we explain below.  The incorrect values of the previous section can be traced to this hardware restriction.

#### You must start with many more digits because of the subtraction of near equals.  Let's do it step by step to see the numerical difficulty.

How would you find a sin value for a large argument, such as 181π / 6?  Subtract off multiples of 2π.  Since 180π / 6 is 30π, this leaves only 1π / 6 and sin(181π / 6) = sin(181π / 6 - 30π) = sin(π / 6) = 1/2.  Let's try the same thing with sin(), starting with a value for that has 22 significant digits.

First, let's find n so that (n 2 Pi) < Exp[40] < ((n+1)2 Pi).

This is the exact integer n.  Let's compute (n 2 Pi) with 22 significant digits.

Now, subtract Exp[40] - (n 2 Pi).  Notice that e40 and n2pi agree to 17 digits.

See the loss of significant digits!  But we still get 5 reliable digits in the answer.

The problem with most calculators and computers, including decimals in Mathematica, is that only about 16 digits are saved in each calculation, so that subtraction of e40 and n2pi leaves only incorrect noise.

Converted by Mathematica      May 31, 2001
Neidinger Homepage