You have a faulty understanding of Mathematica's arbitrary precision arithmetic facility. N
given a 2nd argument does not round or truncate a machine precision number (which essentially exist in their own numeric facility separate from the arbitrary precision facility) given as its 1st argument.
a = Tan[10 °];
Precision[N[N[a], 4]]
MachinePrecision
This explains the result you see as Out[22]
and Out[23]
. Now let's examine why N
won't work for estimating errors.
b16 = N[a, 16]; b4 = N[a, 4]; Precision[b16 - b4]
0.
Because b4
has no significant digits in the part where it might be thought to differ from b16
, there is no precision in the difference.
Here is how to estimate the relative error of rounding to four places:
a4 = Round[a, 1*^-4]; N[1 - a4/a]
0.000153015
Update
A comment to this answer made by the OP persuades me to add this addendum to shed some light on what may be common misconceptions concerning Mathematica's arbitrary precision arithmetic.
First let us look at the internal forms of a
, a
evaluated with machine arithmetic, and a
evaluated with arbitrary precision arithmetic with various setting for precision.
FullForm /@ Join[{a, N[a]}, Table[N[a, p], {p, Range[4, 20, 4]}]]
{
Tan[Times[10,Degree]],
0.17632698070846498`,
0.17632698070846497347109038686861898612`4.,
0.17632698070846497347109038686861898612`8.,
0.17632698070846497347109038686861898612`12.,
0.17632698070846497347109038686861898612`16.,
0.1763269807084649734710903868686189861216330623480986602149`20.
}
It may come as a surprise that Mathematica retains many more digits than the precision specification called for; it retains the extra digits as guard digits to preserve accuracy during computation. It may be even more surprising that Mathematica retains the same large number of guard digits for 4-digit precision as for 16-digit precision, and that the lower precision number only differs in its terminating precision tag, but that is the case. However, that tag makes all the difference when it comes to the way numerical functions treat such numbers.
For example, let's look at Rationalize
.
Consider rationalizing b16
in a smaller and smaller rational interval.
Rationalize[b16, #] & /@ (10^-Range[4, 16, 4])
{43/244, 1950/11059, 168214/953989, 15657047/88795526}
The rational approximation becomes more and more accurate, as it should.
But now consider, rationalizing b4
in the same environment.
Rationalize[b4, #] & /@ (10^-Range[4, 16, 4])
{70/397, 70/397, 70/397, 70/397}
This time the rational approximation doesn't improve, because b4
, despite having the same internal digits as b16
, is treated by Rationalize
exactly like the low precision number it designated to be.
So don't take N
for granted and treat it as if it were a simple numerical evaluator that truncates or round results. It is not that at all; it is a sophisticated tool that should be used with understanding and respect.
I strongly urge anybody new to Mathematica and who wants to do more than school-level numerics to take the time to familiarize themselves with its extensive and rather good Documentation Center articles on numerics, starting with this one.
0.*10^-5
on my machine (Mathematica 10.3 on Win7-64), which seems reasonable to me. Alternatively, try the following:Tan[10 Degree] - Round[Tan[10 Degree], 0.0001]
. $\endgroup$4
in line 22 with one of1
, you would expect a significant value, but you still get that0.*10^-5
$\endgroup$