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.
![[Graphics:Images/TrigLarge_gr_2.gif]](Images/TrigLarge_gr_2.gif)
The following answers were computed in Mathematica 4.0 -- and are totally WRONG!
![[Graphics:Images/TrigLarge_gr_4.gif]](Images/TrigLarge_gr_4.gif)
![[Graphics:Images/TrigLarge_gr_6.gif]](Images/TrigLarge_gr_6.gif)
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]](Images/TrigLarge_gr_8.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
as we explain below. The incorrect values of the previous section can be traced to this hardware restriction.
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.
![[Graphics:Images/TrigLarge_gr_13.gif]](Images/TrigLarge_gr_13.gif)
First, let's find n so that (n 2 Pi) < Exp[40] < ((n+1)2 Pi).
![[Graphics:Images/TrigLarge_gr_15.gif]](Images/TrigLarge_gr_15.gif)
![[Graphics:Images/TrigLarge_gr_17.gif]](Images/TrigLarge_gr_17.gif)
This is the exact integer n. Let's compute (n 2 Pi) with 22 significant digits.
![[Graphics:Images/TrigLarge_gr_19.gif]](Images/TrigLarge_gr_19.gif)
Now, subtract Exp[40] - (n 2 Pi). Notice that e40 and n2pi agree to 17 digits.
![[Graphics:Images/TrigLarge_gr_21.gif]](Images/TrigLarge_gr_21.gif)
![[Graphics:Images/TrigLarge_gr_23.gif]](Images/TrigLarge_gr_23.gif)
See the loss of significant digits! But we still get 5 reliable digits in the answer.
![[Graphics:Images/TrigLarge_gr_25.gif]](Images/TrigLarge_gr_25.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.