# Set Precision- digits and rationals?

Posted 5 months ago
671 Views
|
2 Replies
|
2 Total Likes
|
 Hey guys,I am bit confused with the Precision in Mathematica. I first set Precision at 50. Then I set up two tables one starts from 0.5 with gap 1/2 until 9 and the other starts from 1/2 with gap 1/2 until 9 too. However, the first table stops at 8.5 while the second one stops at 9. The key part focus on the difference between 8.5 with precision 51.23044892137827 and 8.5 with precision 50, the 17th item in each table. If you simply check by "==" then the answer is True. So I am wondering how to check their difference.Please see my attachment. Commend are pasted in the following. $PreRead = (# /. s_String /; StringMatchQ[s, NumberString] && Precision@ToExpression@s == MachinePrecision :> s <> "50." &); T1 = Table[z, {z, 0.5, 9, 1/2}] % // FullForm T2 = Table[z, {z, 1/2, 9, 1/2}] T1[[17]] == T2[[17]] Thanks in advance. Attachments: Answer 2 Replies Sort By: Posted 5 months ago  The arbitrary-precision model represents a number xp by an ordered pair, a value$x$and an uncertainty$dx>0$. When$x \ne 0$, the uncertainty appears as the machine-precision number equal to$p=- \log_{10} |dx/x|$, where$p$is called the precision; when$x = 0$, the uncertainty appears as the machine-precision number equal to$a=- \log_{10} dx$, where$a$is called the accuracy. When$x = 0$, the FullForm[] looks like 0a instead of xp. Whether the uncertainty$dx$or the precision$p$or accuracy$a$is stored internally is immaterial to understanding how it works. Perhaps the only thing to realize about the internal representation is that it is probably in terms of a finite-precision binary number, and that's only helpful in explaining things that are usually unimportant, such as why SetPrecision[0.150, Infinity] is not exactly 1/10 and why its denominator is a power of 2.There are rules for computing how the uncertainties are combined and propagate throughout a computation. Mathematica uses these rules to calculate the new uncertainty/precision/accuracy of the result. I don't know for certain what exactly is done, but a first-order approximation is that in computing$y = F(x_1, x_2,\dots, x_n)$on the inputs$x_j$with uncertainties$dx_j$, the uncertainty will be approximately $$dy = \left| \nabla F(x_1, x_2,\dots, x_n) \cdot (dx_1, dx_2,\dots, dx_n) \right|\,,$$ or in terms of a single-variable computation$y = F(x)$, $$dy = \left| F'(x)\, dx \right| \,.$$Another rule is that if$dy > |y|$, then$y$is replaced by$0$. Finally, it is sometimes helpful to understand that the value for$x$carries several extra guard digits beyond the precision. This is so that the roundoff error in computing$y$is negligible compared to the uncertainty$dy$.As for equality, two pairs$(x, dx)$and$(y, dy)$are considered equal if the difference$|x - y|$is less than their combined uncertainty$dx + dy$.Now to the problem in the OP: In both cases, the value of$x$is exactly$8.5$or$17/2$, which is exactly representable in binary. The only difference in 8.550 and 8.551.23 is the uncertainty$dx$. To understand why$x=$8.5 arises exactly in each table, one should think about the Table[] iterators. All the values constructed are exactly representable in binary with just a few bits, so there is no roundoff error. Further the increment 1/2 has an uncertainty of 0, so that the uncertainties of the all the entries that start with precision 50 are the same. And if$x$increases and$dx$stays constant, the precision$- \log_{10} |dx/x|\$ increases.