Group Abstract Group Abstract

Message Boards Message Boards

2
|
20.5K Views
|
25 Replies
|
27 Total Likes
View groups...
Share
Share this post:

[?] Change the default number of digits to display in the output?

Posted 6 years ago
POSTED BY: Doug Lerner
25 Replies

The questions of this thread has been answered more than sufficiently. Please keep discussion contained within the bounds of the original questions and Wolfram technologies. Please make sure you know the rules: https://wolfr.am/READ-1ST

POSTED BY: EDITORIAL BOARD

Try

   N[Rationalize[1.0000000000000001`20, 0], 1000]`

Out[144]= \ 1.00000000000000010000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000

Doug, it's not quite clear to me what your aim is with these posts.

Do you have a practical problem that you need help solving? If yes, can you clarify what you are trying to accomplish that you need help with?

Or are you trying to argue that fundamental behaviours of the Wolfram Language should be changed? When people do this, they often have only a few very narrow use cases in mind, but the Mathematica must be usable for many different tasks, and they do not immediately see that the proposed changes would cause countless inconveniences (or worse), not to mention break most existing programs.

Unless I say otherwise, 1.000001 is an exact number.

Well, then you're not speaking the Wolfram Language, but another language. The correct way to say that is 1000001/1000000. But you already knew that, so what is your point?

But what does it actually do?

Daniel explained what it does in detail, including that MachinePrecision is treated as the lowest. Do you have any questions regarding that explanation?

If that's not the definition of what it does then change the definition.

You seem to want SetPrecision, which you are already aware of. Why don't you just use it?


It seems to me that you may not be realizing what the use of machine precision is, or why it behaves so differently from arbitrary precision arithmetic in Mathematica. Its purpose is performance. "Machine precision" is not about a certain precision but about using the same floating point format that is natively supported by the CPU. It also comes with tradeoffs such as the lack of precision tracking—this is why it necessarily behaves differently.

You are setting the precision progressively higher

This is not the case. As explained in other posts, MachinePrecision is not just a precision of 16 (or rather $MachinePrecision) digits. It is qualitatively different.


Well I know it's not because I've seen it done differently, and better, in other software.

I do not see a proposal for a better system for arbitrary precision arithmetic in your posts, nor a serious comparison with an existing alternative and an analysis of pros and cons.

But let us come back to something concrete and practical. What is it that you are trying to accomplish with Mathematica and cannot? What specific task can be done in another system (which?) that cannot be done in Mathematica reasonably conveniently?

Your original complaint was that machine precision numbers are only displayed with 6 digits of precision by default. Many easy solutions have been offered. Do you have any other practical problems?

Posted 6 years ago

Unless I say otherwise, 1.000001 is an exact number. I am well aware that by convention Mathematica doesn't treat it as that, so I don't want to get into that discussion as well. But I just find it strange that for instance:

In[1]:= N[1.00000000000000010, 1000]
Out[1]= 1.0000000000000001

with the remaining 983 0's on the end just assumed. And yet it doesn't assume there are any zeros after the number when I write it.

I just can't understand why nobody seems to see what is staring me in the face. Let's look at the common example of Pi:

In[2]:= N[Pi, 15]
Out[2]= 3.14159265358979

In[3]:= N[Pi, 16]
Out[3]= 3.141592653589793

In[4]:= N[Pi, 17]
Out[4]= 3.1415926535897932

In[5]:= N[Pi, 18]
Out[5]= 3.14159265358979324

In[6]:= N[Pi, 19]
Out[6]= 3.141592653589793238

In[7]:= N[Pi, 20]
Out[7]= 3.1415926535897932385

Beautiful. Exactly what I would want it to do. Exactly what I would expect it to do. Exactly what I want to know. Here is something else I would like it to do:

N[1.0000000000000001, 15]
1.00000000000000

N[1.0000000000000001, 16]
1.000000000000000

N[1.0000000000000001, 17]
1.0000000000000001

N[1.0000000000000001, 18]
1.00000000000000010

N[1.0000000000000001, 19]
1.000000000000000100

N[1.0000000000000001, 20]
1.0000000000000001000

But what does it actually do?

In[8]:= N[1.0000000000000001, 15]
Out[8]= 1.

In[9]:= N[1.0000000000000001, 16]
Out[9]= 1.

In[10]:= N[1.0000000000000001, 17]
Out[10]= 1.

In[11]:= N[1.0000000000000001, 18]
Out[11]= 1.

In[12]:= N[1.0000000000000001, 19]
Out[12]= 1.

In[13]:= N[1.0000000000000001, 20]
Out[13]= 1.

In[14]:= N[1.0000000000000001, 1000]
Out[14]= 1.

If that's not the definition of what it does then change the definition.

While I'm at it, what's wrong with this picture?

In[15]:= SetPrecision[10000.04, 7]
Out[15]= 10000.04

In[16]:= SetPrecision[10000.04, MachinePrecision]
Out[16]= 10000.

In[17]:= SetPrecision[10000.04, 17]
Out[17]= 10000.040000000001

You are setting the precision progressively higher and get different results at each stage. I understand the extra digits on the last one, but that's not what I'm talking about. I'm talking about the fact that it prints any decimals at all. Ok, I've got an explanation of why this happens, but I still don't agree that it's right.

Even though it has been acknowledge that there are stylistic choices here, most people seem to be justifying Mathematica's behavior by implying it's inevitable. Well I know it's not because I've seen it done differently, and better, in other software. I just think there's room for improvement here.

POSTED BY: Doug Lerner

Doug,

I think the problem is that the underlying assumption of your previous posts is that

N[1.000001, 1000]

means "give me 1.000001 to 1000 digits of precision". That is not the meaning of "N[]" according to the documentation nor the design of MMA. The N function is for converting exact numbers to floating point numbers with a certain precision. If the number already has a lower precision (such as a machine float) then N does nothing except return the number unchanged. Once the float is returned, it is subject to the same printing rules I discussed in my earlier post.

Another way to look at it is that the printing format is a user preference to help maintain screen clutter. You set your preferences to only display 6 digits and then round numbers off for display. From my perspective I do not think it is fair to set the preference to 6 digits and then use the fact that you do not get 10 digits of display as evidence of a bug.

I hope this helps.

Regards,

Neil

POSTED BY: Neil Singer
POSTED BY: Michael Rogers
Posted 6 years ago

Thank you for clearing that up. I'm glad my comments got through to someone who seems to have some influence on the direction of Mathematica so that maybe these issues can be considered in future improvements.

As I suggested, I've been using Mathematica for many years and it's one of my core software tools. The things I've been able to do over the years would be unthinkable without it. I suppose I started off this thread being a bit critical, but I hope I'm ending it with some ideas for improvement.

POSTED BY: Doug Lerner
POSTED BY: Daniel Lichtblau
Posted 6 years ago
POSTED BY: Doug Lerner
Posted 6 years ago
POSTED BY: Doug Lerner
POSTED BY: Daniel Lichtblau
POSTED BY: Neil Singer
Posted 6 years ago

Wow, good answer, Thanks.

That solves the problem, but I still feel like there are inconsistencies. Like why does 5000.01`7 + 5000.03`7 = 10000.04 with display digits set to 6, but N[5000.01 + 5000.03, 1000] = 1000. using the same settings?

POSTED BY: Doug Lerner
POSTED BY: Neil Singer

Doug,

This is a function of your preferences. Go to preferences and change the default number of digits to display in the output from 6 to 10, or something else. Now it will show 10 digits of precision (while keeping any extra digits hidden). This rounding behavior is only for display and was done to make big expressions with lots of numbers manageable but if you change your preference, you can have what you want.

enter image description here

Alternatively, you can do this change for only one notebook and leave your global settings alone by going to the options inspector and changing PrintPrecision option for that notebook or executing this one time for a particular notebook:

SetOptions[SelectedNotebook[], PrintPrecision -> 10]

Regards,

Neil

POSTED BY: Neil Singer

So "1000." is the correct answer to 1000 digits, even when it knows internally that the .04 is there?

No, one sees here just the same displaying behavior:

N[5000.01 + 5000.03, 1000] // FullForm
(*  Out:   10000.04`   *)
POSTED BY: Henrik Schachner
Posted 6 years ago
POSTED BY: Doug Lerner

This discussion is somewhat hard to understand. I anyone really thinking that there is a miscalculation?

enter image description here

POSTED BY: Henrik Schachner
Posted 6 years ago
POSTED BY: Doug Lerner
POSTED BY: Claudio Chaib

If you insist on copying and pasting data that is used elsewhere, try

 SetPrecision[5000.01 + 5000.03, 7]

(* 10000.04.*)

.

Posted 6 years ago

I was aware of this method and should have mentioned it. In fact, it's the way I worked around the problem in my notebook. But adding `x on the end of every number is just as tedious as adding 0's, especially when you have a long list of numbers possibly copied from somewhere else.

Another issue with that is why doesn't 5000.01`7 behave the same as 5000.010 or even 5000.0100000? What does the 7 even mean?

POSTED BY: Doug Lerner

Yes! This method is perfect! Works for many many decimal places! Thanks a lot, Marvin, I learned something new!

5000.0000000000000000000000000000001`36 + 5000.0000000000000000000000000000003`36

( * 10000.0000000000000000000000000000004 * )

POSTED BY: Claudio Chaib

You can try

5000.01`7 + 5000.03`7

 (* 10000.04   . *) 

I think maybe this is not the perfect solution, because it is visual and also has limitations... but it might slightly improve your visualization if using AccountingForm []

AccountingForm[5000.01 + 5000.03, 7]
AccountingForm[5000.00000001 + 5000.00000003, 13]
AccountingForm[5000.00000000001 + 5000.00000000003, 16]

imag1

...I think maybe there's still another better way...

POSTED BY: Claudio Chaib