-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Add display mode capability #115
Conversation
Nice idea! I'll check the details later today (hopefully). |
1cf23b2
to
1232793
Compare
1232793
to
7fa8552
Compare
This is now ready to be looked at @lbenet. |
I'm starting to look on this now. A quick question: in your examples above, I am surprised that |
Sorry... I didn't noticed |
I've done some very preliminary tests. Here are some comments about them:
julia> Interval(pi)
[3.1415926535897931159979634685441, 3.1415926535897931159979634685442]
julia> BigFloat(pi)
3.141592653589793238462643383279502884197169399375105820974944592307816406286198
julia> ValidatedNumerics.display_params
ValidatedNumerics.DisplayParameters(:standard,false,6)
julia> a = @biginterval(pi)
[3.141592653589793238462643383279502884197169399375105820974944592307816406286198, 3.141592653589793238462643383279502884197169399375105820974944592307816406286233]₂₅₆
|
julia> a = @floatinterval(pi)
[3.14159, 3.1416]
julia> displaymode(sigfigs=10)
10
julia> a
[3.141592653, 3.141592654]
julia> displaymode(sigfigs=20)
20
julia> a
[3.1415926535897931159, 3.1415926535897935601]
julia> big(a)
[3.1415926535897931159, 3.1415926535897935601]₂₅₆
julia> displaymode(format=:full)
julia> a
Interval(3.141592653589793, 3.1415926535897936)
julia> big(a)
Interval(3.141592653589793115997963468544185161590576171875000000000000000000000000000000, 3.141592653589793560087173318606801331043243408203125000000000000000000000000000)
julia> a
[3.14159, 3.1416]
julia> showall(a)
Interval(3.141592653589793, 3.1415926535897936) This makes it very quick to see all of the digits. I think we're used to immediately seeing all the digits but I don't think it's usually actually useful (except for the authors of the library to check weird corner cases ;) ). I think for the user, a default of 6 (or whatever) sig figs is actually much more useful. In any case, it's a single command to change the default if you don't like it. |
(By "reasonable" I meant that using more sig figs gives the same answer as converting the |
I am not convinced that there is no need for an upper bound on the significant figures displayed. Let's get back to the example with julia> displaymode(sigfigs=32)
32
julia> Interval(pi)
[3.1415926535897931159979634685441, 3.1415926535897931159979634685442]
julia> ans.lo, ans.hi
(3.141592653589793,3.141592653589793)
julia> big(pi)
3.141592653589793238462643383279502884197169399375105820974944592307816406286198 We know the distinction between precision and accuracy. My point is that, since we care about the accuracy of the interval (to a given precision) bounding a result, we should not allow any ambiguity coming from displaying "more significant digits" than what it makes sense. In the example above,
I fully agree! It does makes sense to reduce the number of significant digits, but not increasing it! |
Incidentally, tests for Julia 0.4 are not passing! The problem is in |
That is a nice example! The point is that 20 significant figures is not enough to express julia> displaymode(sigfigs=49)
julia> p = Interval(pi)
[3.141592653589793115997963468544185161590576171875, 3.141592653589793115997963468544185161590576171875]
julia> showall(big(p))
Interval(3.141592653589793115997963468544185161590576171875000000000000000000000000000000, 3.141592653589793115997963468544185161590576171875000000000000000000000000000000) I will fix the failing test and add more for all these display capabilities. |
Are you happy for this to be merged, @lbenet? |
Current coverage is 92.75%@@ master #115 diff @@
==========================================
Files 18 19 +1
Lines 857 897 +40
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 797 832 +35
- Misses 60 65 +5
Partials 0 0
|
I still do not agree; you may indeed need to go to 49 significant figures or simply stay with 16, which is the correct amount for I agree that the binary representation of julia> Interval(BigFloat(pi))
[3.14159, 3.1416]₂₅₆
julia> displaymode(format=:full)
julia> Interval(BigFloat(pi))
Interval(3.141592653589793238462643383279502884197169399375105820974944592307816406286198, 3.141592653589793238462643383279502884197169399375105820974944592307816406286198)
julia> displaymode(sigfigs=1000)
1000
julia> Interval(BigFloat(pi))
Interval(3.141592653589793238462643383279502884197169399375105820974944592307816406286198, 3.141592653589793238462643383279502884197169399375105820974944592307816406286198)
The point is that we have not changed the precision of mpfr ( |
Following with the same example: julia> displaymode(format=:standard)
julia> ValidatedNumerics.display_params
ValidatedNumerics.DisplayParameters(:standard,false,1000)
julia> set_bigfloat_precision(64);
julia> Interval(BigFloat(pi))
[3.14159265358979323851280895940618620443274267017841339111328125, 3.14159265358979323851280895940618620443274267017841339111328125]₆₄
julia> ans.lo
3.14159265358979323851
julia> set_bigfloat_precision(53);
julia> Interval(BigFloat(pi))
[3.141592653589793115997963468544185161590576171875, 3.141592653589793115997963468544185161590576171875]₅₃
julia> ans.lo
3.1415926535897931 How do I understand the figures beyond the precision of the calculation? |
EDIT: Removed the comment; forgot |
|
||
- `:standard`: `[1, 2]` | ||
- `:full`: `Interval(1, 2)` | ||
- `:midpoint`: 1.5 ± 0.5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using Interval(0.1,0.2)
yields clearer examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or any other which is not an Interval
with integers.
I did not explain properly what the different
In this representation, an interval is thin (diameter=0) if and only if the two outputs are exactly the same.
This decimal expansion always has a finite number of non-zero digits, but that number of non-zero digits may be large. If e.g. julia> a = float(pi)
3.141592653589793
julia> a = big(float(pi))
3.141592653589793115997963468544185161590576171875000000000000000000000000000000 Note the trailing zeros showing where the exact decimal representation ends. But: julia> displaymode(format=:standard, sigfigs=10000)
10000
julia> Interval(float(pi))
[3.141592653589793115997963468544185161590576171875, 3.141592653589793115997963468544185161590576171875] Here the trailing zeros are not shown. julia> displaymode(format=:full)
julia> Interval(float(pi))
Interval(3.141592653589793, 3.141592653589793) This is the behaviour previous to this PR -- it recognises that 3.141592653589793 is sufficient to reconstruct the corresponding I hope this clarifies the situation? I guess all this should go in the docs... :/ |
I think I had grasped already the ideas behind, though your detailed explanation is certainly welcome! Thanks! (Use it for the docs!) My concern is related to having more figures that what is compatible with the actual precision (call it 53 bits for |
I think that is the point: the idea of the Note that this is not the case before this PR: what you see in julia> Interval(pi)
[3.141592653589793, 3.141592653589793] or more explicitly after this PR with julia> displaymode(format=:full)
julia> Interval(pi)
Interval(3.141592653589793, 3.141592653589793) is a string that, due to some floating-point / Julia magic, enables you to reproduce the original interval by copying and pasting it in the REPL (basically because there is a hard-coded "precision" in 3.141592653589793115997963468544185161590576171875 In order to show such a containing interval, you either must show this long string, or show only some of its digits, in which case you must round at that number of displayed digits to get a containing interval. [Previously we had no way of displaying this true value; now we do. (Although you would probably only rarely, if ever, actually want to display this!)] |
Arguably there should be another mode that automatically calculates this true string and immediately displays it, without fiddling around finding what |
Ok, though somewhat hesitating, let's go for it! I'm merging this! |
Thanks a lot! Specially to patiently deal with my objections! |
Incidentally, have you check what it says the standard about the output? |
Thanks! I haven't checked what the standard says. In any case this is useful functionality I think |
The idea is to be able to do the following. Of course, the syntax etc. is not nice at the moment.
We can add output precision, output or not decorations, etc.
Now it also does the following: