# Wrong computation with N

I was trying to solve this problem using Mathematica 8.04. I did this:

f[n_] := 2 Cos[2^(-1 + n) ArcCos[5/2]]
Table[{n, N[f[n+1]/Product[f[k], {k, 1, n}]]}, {n, 1, 20}]


and I got

{{1, 4.6 + 0. I}, {2, 4.58261 + 0. I}, {3, 4.58258 + 0. I}, {4,
4.58258 + 0. I}, {5, 4.58258 + 0. I}, {6, 4.58258 + 0. I}, {7,
4.58258 + 0. I}, {8, 4.58258 + 0. I}, {9, 0. + 0. I}, {10,
0. + 0. I}, {11, 0. + 0. I}, {12, 0. + 0. I}, {13, 0. + 0. I}, {14,
0. + 0. I}, {15, 0. + 0. I}, {16, 0. + 0. I}, {17, 0. + 0. I}, {18,
0. + 0. I}, {19, 0. + 0. I}, {20, 0. + 0. I}}


There is something wrong after n=9:

N[f[10]/Product[f[k], {k, 1, 9}]]
0. + 0. I
N[f[10]]/N[Product[f[k], {k, 1, 9}]]
4.58258 + 0. I


What is the problem here? I think the first input should be more accurate than the last one.

-
I am not exactly clear about who these things work, but Mathematica can keep track of the precision of results and increase precision as necessary to obtain a good enough result. I think this mechanism only works if you don't use machine numbers (don't use the FPU), but instead use Mathematica's arbitrary precision floating point numbers. To do this, you need to specify the precision explicitly---it can be greater or less than machine precision but it needs to be given explicitly. This is what Vitaliy suggests as well. – Szabolcs Mar 18 '12 at 9:24

This will fix the problem:

Partition[
Table[{n, N[f[n + 1]/Product[f[k], {k, 1, n}], 10]}, {n, 1, 20}],
2] // Grid


with output:

The fix I added is precision 10 specification to the function N[... , 10]. If you read Documentation for N in section "More Information" you find:

"N[expr] gives a machine-precision number, so long as its magnitude is between $MinMachineNumber and $MaxMachineNumber."

Evaluating this:

In[1]:= $MaxMachineNumber Out[1]= 1.79769*10^308  tells us that when your Table reaches n=9 you hit the greater than $MaxMachineNumber case:

In[2]:= N[f[9 + 1]]
Out[2]= 2.463534156527763*10^348 + 0. I


note 348 > 308 exponent. So now you should explicitly specify the precision you want, like I did with N[... , 10] for example.

Also, to clarify the nature of repeating 4.5826..., I played a bit with Mathematica to come up with a "conjecture":

$$\frac{2\cos\left(2^n \cos^{-1}\frac52\right)}{\prod_{k=1}^n 2\cos\left(2^{k-1} \cos^{-1}\frac52\right)}=\sqrt{21}\coth\left(2^n \cosh^{-1}\frac52\right)$$

So because Coth saturates quickly at 1 we have our limit for large arguments

In[3]:= N@Sqrt[21]
Out[3]= 4.58258


yet the numbers in your Table should of course decrease very slowly in "not printed" after-decimal-point part due to decreasing Coth function. And this is why the 1st number is 4.6:

In[4]:= TrigExpand[Sqrt[21] Coth[2 ArcCosh[5/2]]]
Out[4]= 23/5

-
How did you use Mathematica to come up with the conjecture? – Michael Wijaya Mar 18 '12 at 13:01

Yes, this seems to be a bug,

f[n_] := 2 Cos[2^(-1 + n) ArcCos[5/2]]

a = f[10]/Product[f[k], {k, 1, 9}];

Accuracy[N[a]]


Gives an accuracy of about 300, which clearly is not true. However, Accuracy[N[a,2]] gives a correct output. Also, using TrigExpand[a]//N works.

-
The reason that Accuracy[0.] returns 307.653 has been explained before but I cannot find the post, and I cannot remember the explanation. – Mr.Wizard Mar 18 '12 at 13:00