Skip to content
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

Problem with small values #136

Closed
lbenet opened this issue May 17, 2016 · 15 comments
Closed

Problem with small values #136

lbenet opened this issue May 17, 2016 · 15 comments

Comments

@lbenet
Copy link
Member

lbenet commented May 17, 2016

I just came across the following:

julia> using ValidatedNumerics

julia> const epsilon = 1.0e-20
1.0e-20

julia> @interval(epsilon)
Interval(0.0, 0.0)

julia> Interval(epsilon)
Interval(1.0e-20, 1.0e-20)

The problem seems to be in convert (after expanding the macro):

julia> convert(Interval{Float64},epsilon)
Interval(0.0, 0.0)
@lbenet
Copy link
Member Author

lbenet commented May 17, 2016

The problem is related to the use of rationalize in the convert method (line 49 of src/conversion.jl:

julia> rationalize(epsilon)
0//1

@dpsanders
Copy link
Member

Ouch. Do you have a suggestion as to how to solve this?
@interval("1e-20") works.

I do not want to go back to using a string representation for the conversion, since that is very slow.
Maybe we can check if the resulting interval contains the starting float.

@lbenet
Copy link
Member Author

lbenet commented May 17, 2016

No suggestion yet...

@dpsanders
Copy link
Member

dpsanders commented May 17, 2016

I mean something like

julia> function make_interval(x)
       II = convert(Interval{Float64}, x)
       if !(x ∈ II)
              II = convert(Interval{Float64}, string(x))
       end
       end
make_interval (generic function with 1 method)

julia> make_interval(1e-20)
[9.99999e-21, 1.00001e-20]

@lbenet
Copy link
Member Author

lbenet commented May 17, 2016

Using a small variation of your code, all but one test pass; the failing test is: x^(1//3) --> x^(1 / 3)

@dpsanders
Copy link
Member

I don't understand why that test would fail.

@dpsanders
Copy link
Member

Do you have a branch with this change?

@lbenet
Copy link
Member Author

lbenet commented May 18, 2016

I've pushed it only until now, sorry; its called "Iss136".

@dpsanders
Copy link
Member

Nice catch. The problem is here:

julia> convert(Interval{BigFloat}, 1/3)
Interval(3.333333333333332999999999999999999999999999999999999999999999999999999999999968e-01, 3.333333333333333000000000000000000000000000000000000000000000000000000000000012e-01)

julia> convert(Interval{BigFloat}, 1//3)
Interval(3.333333333333333333333333333333333333333333333333333333333333333333333333333305e-01, 3.333333333333333333333333333333333333333333333333333333333333333333333333333348e-01)

Clearly the first is wrong.

@dpsanders
Copy link
Member

Not sure how to find a solution that works for 1/3 and for 1e-20, though. It's possible that for BigFloat we'll just have to use the conversion via a string?

@lbenet
Copy link
Member Author

lbenet commented May 18, 2016

Not sure how to solve it. I'm still, playing, but I've been bouncing myself against a wall...

One possibility is leave it as it is, with a note in the documentation and the docstrings.

@lbenet
Copy link
Member Author

lbenet commented May 18, 2016

I didn't notice it before, but there are more failing tests...

@lbenet
Copy link
Member Author

lbenet commented May 19, 2016

Pushed a new commit; not sure why, but locally few tests related to IntervalBox are not passing (also in master); probably something related to FixedSizeArrays...

@lbenet
Copy link
Member Author

lbenet commented May 19, 2016

... but not what was problematic before.

@lbenet lbenet changed the title Problem with small constants Problem with small values May 21, 2016
dpsanders pushed a commit that referenced this issue May 21, 2016
* Change a convert method, addressin Issue 136

This implements an idea of David to solve Issue 136; it does
solve it, but a test is now failing.

* Prevent case when rationalize(x) is zero, for non-zero x

* Add tests for intervals with small values
@dpsanders
Copy link
Member

Fixed by #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants