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 [Graphics:Images/TrigLarge_gr_1.gif] 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

[Graphics:Images/TrigLarge_gr_2.gif]
[Graphics:Images/TrigLarge_gr_3.gif]

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

[Graphics:Images/TrigLarge_gr_4.gif]
[Graphics:Images/TrigLarge_gr_5.gif]
[Graphics:Images/TrigLarge_gr_6.gif]
[Graphics:Images/TrigLarge_gr_7.gif]

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.

[Graphics:Images/TrigLarge_gr_8.gif]
[Graphics:Images/TrigLarge_gr_9.gif]

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 [Graphics:Images/TrigLarge_gr_10.gif] 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([Graphics:Images/TrigLarge_gr_11.gif]), starting with a value for [Graphics:Images/TrigLarge_gr_12.gif] that has 22 significant digits.

[Graphics:Images/TrigLarge_gr_13.gif]
[Graphics:Images/TrigLarge_gr_14.gif]

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

[Graphics:Images/TrigLarge_gr_15.gif]
[Graphics:Images/TrigLarge_gr_16.gif]
[Graphics:Images/TrigLarge_gr_17.gif]
[Graphics:Images/TrigLarge_gr_18.gif]

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

[Graphics:Images/TrigLarge_gr_19.gif]
[Graphics:Images/TrigLarge_gr_20.gif]

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

[Graphics:Images/TrigLarge_gr_21.gif]
[Graphics:Images/TrigLarge_gr_22.gif]
[Graphics:Images/TrigLarge_gr_23.gif]
[Graphics:Images/TrigLarge_gr_24.gif]

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

[Graphics:Images/TrigLarge_gr_25.gif]
[Graphics:Images/TrigLarge_gr_26.gif]

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  Math Homepage  Davidson Homepage