-
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
Rationalize Float64
when creating intervals?
#14
Comments
It may be a good idea to use
and the interval does not contain the true However,
works correctly. |
An alternative would just be to grow the interval slightly:
which gives a slightly better answer, but maybe is more dangerous? |
I would be more in favor of the first option, though it also has some caveats: julia> a = 1/factorial(5)
0.008333333333333333
julia> rationalize(a) # this is fine
1//120
julia> convert(Rational{Int64},a) # this doesn't, I don't understand why...
4803839602528529//576460752303423488 The reason I don't like the second option is that it may lead to ever growing intervals. If this is somehow controlled, in the sense that the interval obtained is thin in the extended sense ( |
In
|
Somehow it should be trying to "guess" the rational by finding the repeating string in the binary expansion. |
I don't see why you say that my option 2 (widen the interval slightly) will lead to ever-growing intervals. This is just when the interval is first created from a float (which, ideally, will never happen, so maybe we should just throw an error if this happens!) |
Regarding Regarding option 2, the question is if it yields a thin interval or not, in the extended sense. If it doesn't, I fear that the "extra diameter" will propagate further due to interval arithmetics |
Oh, apologies, you're right. But it uses I understand your worry about the "extra diameter". The problem is that we are trying to infer what the user wanted, instead of what they wrote... (Just to record the relevant discussion: JuliaLang/julia#4278) |
Related (EDIT: really the same) problem:
|
Can it be ensured that julia> Interval(prevfloat(1/3),nextfloat(1/3)) # answer is not OK
[0.33333333333333326, 0.33333333333333337]
julia> ValidatedNumerics.isthin(ans)
false The second case is what I fear. |
I edited my previous comment.... julia> @interval(prevfloat(1/3), nextfloat(1/3))
ERROR: MethodError: `prevfloat` has no method matching prevfloat(::ValidatedNumerics.Interval{Base.MPFR.BigFloat}) |
You were right to use No, it cannot be guaranteed to be a thin interval. The reason is that the float is already rounded, either down or up, so it is already one of the endpoints of the true thin interval. I do not see any way around this except to round it again. |
In a way, this discussion is parallel to the proposal for |
Maybe we should merge #11 and document the caveats, and carry on... |
How about:
Note that if it gets a |
Interestingly, in the context of interval arithmetic, we are in some sense safer than the discussion referred to above, since we just need to guarantee that the resulting interval really contains the original |
Have you tested your proposal about Regarding the second one, I remember that the idea of implementing it as it is, was to avoid re-rounding |
I was checking other parts of the code, and just realized that |
It is used as |
|
You are right... |
I was not aware of JuliaLang/julia#8845. Is this helpful? |
It's basically just nicer syntax (and perhaps slightly more performant). It doesn't change the mathematics. |
|
No description provided.
The text was updated successfully, but these errors were encountered: