# Explain behavior of N function displayed precision?

Posted 9 months ago
867 Views
|
4 Replies
|
3 Total Likes
|
 I noticed an anomaly when using different ways to calculate square roots. For good or bad over the years I have fallen into a habit of calculating square roots as raising a number to .5. Doing this in Mathematica has caused an unexplained behavior.If I use Sqrt[5] or (5^(1/2) I get the same results and displayed precision If I use (5^.5) I get the same result but less displayed precision. See the below example . For phi1 and phi 2 I can see 20 decimal places. For phi3 I can see at most 5 decimal places. However phi1-phi3 is zero so I am getting the same resultWhy am I only seeing 5 decimal places for phi3? ClearAll \$Version phi1 = (1 + Sqrt[5])/2; N[phi1, 20] (* <——— Shows 20 decimal places*) phi2 = (1 + 5^(1/2))/2; N[phi2, 20] (* <——— Shows 20 decimal places*) phi3 = (1 + 5^(.5))/2; N[phi3, 20] (* <——— Shows only 5 decimal places*) phi1-phi3 ClearAll "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)" 1.6180339887498948482 1.6180339887498948482 1.61803 0. 
4 Replies
Sort By:
Posted 9 months ago
 It's not a unexplained behavior it is a normal behavior (not a bug). phi1 = (1 + Sqrt[5])/2; N[phi1, 20] phi2 = (1 + 5^(1/2))/2; N[phi2, 20] phi3 = (1 + 5^(SetPrecision[0.5, 20]))/2; N[phi3, 20] (* 1.6180339887498948482 *) (* 1.6180339887498948482 *) (* 1.6180339887498948482 *) because: {Precision[(1 + 5^(.5))/2], Precision[(1 + 5^(1/2))/2]} (* {MachinePrecision, \[Infinity]} *) This is very well explained in this book
Posted 9 months ago
 wow !! ... Thank you .... so it's the default behavior of Machine Precision vs setting a precision. Based on your answer I changed .5 to .50000000000000000000 and got the same result you did with SetPrecissionAre there best practice guidelines on how to introduce precision. Using .5 vs 1/2 while arithmetically correct may not give me the result I expect. It seems that I should enter the accuracy I want (.50000000000000000000) or enter a calculation (1/2) allowing Mathematica to use its internal precision