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

Document PowerMode #674

Open
dpsanders opened this issue Jul 21, 2024 · 11 comments
Open

Document PowerMode #674

dpsanders opened this issue Jul 21, 2024 · 11 comments
Labels
1.0 Planned for the major 1.0 release doc

Comments

@dpsanders
Copy link
Member

Currently to compute (1..2)^(1//7) we are converting the rational to an interval. This loses accuracy.

We should instead use the corresponding MPFR function, mpfr_rootn_si. Unfortunately Julia does not seem to do this yet; issue here.

For rationals whose denominator is a power of 2, we can alternatively use iterated sqrt to get a fast version that avoids BigFloats (but may not be correctly rounded).

As an example, tests in IntervalContractors.jl (which are originally based on ITF1788, IIRC) are failing due to this. For example,

interval(8.673020346900622e8, 8.673020346900623e8)^(1//8)

has a sup of 13.100000000000005, whereas it should be 13.100000000000001 (i.e. the result is 2 floats too large).

@dpsanders
Copy link
Member Author

Possibly we need ExactReal(1//8) for the rational power.

@dpsanders
Copy link
Member Author

This was implemented in a previous version. See https://github.com/JuliaIntervals/IntervalArithmetic.jl/pull/286/files

@OlivierHnt
Copy link
Member

Yep it's still in the library I believe.
I think you just ran into an issue with the "power mode"

The default is IntervalArithmetic.PowerMode{:fast}(), and this is controlled by overwriting IntervalArithmetic.power_mode.

@OlivierHnt
Copy link
Member

OlivierHnt commented Jul 22, 2024

Unless you think we can improve the performance of the more accurate version, then I think we can close this issue.

@dpsanders
Copy link
Member Author

Ah, I see 🤦 Thank you! Is this documented?

@OlivierHnt
Copy link
Member

No it does not seem to be in the docs.

@OlivierHnt OlivierHnt changed the title More accurate rational powers of intervals Document PowerMode Jul 22, 2024
@OlivierHnt OlivierHnt added 1.0 Planned for the major 1.0 release doc labels Jul 22, 2024
@dpsanders
Copy link
Member Author

I don't see any mechanism to get the current power mode?

I need this so that I can save the current power mode before fixing it to run the IntervalContractor.jl tests, then reset it to the previous value.

@dpsanders
Copy link
Member Author

dpsanders commented Jul 27, 2024

Usage:

julia> setdisplay(:full);

julia> interval(8.673020346900622e8, 8.673020346900623e8)^(1//8)
Interval{Float64}(13.099999999999998, 13.100000000000005, com, NG)

julia> IntervalArithmetic.power_mode() = IntervalArithmetic.PowerMode{:slow}()

julia> interval(8.673020346900622e8, 8.673020346900623e8)^(1//8)
Interval{Float64}(13.099999999999998, 13.100000000000001, com, NG)

@dpsanders
Copy link
Member Author

Ah, to get the current value you just do

julia> IntervalArithmetic.power_mode()
IntervalArithmetic.PowerMode{:slow}()

!

@dpsanders
Copy link
Member Author

When trying to change the power mode in the IntervalContractors.jl tests and then running ]test IntervalContractors, I get the warning

WARNING: Method definition power_mode() in module Main at /Users/dsanders/Dropbox/packages/IntervalContractors/test/runtests.jl:9 overwritten at /Users/dsanders/Dropbox/packages/IntervalContractors/test/runtests.jl:40.

Is this expected / normal?

@OlivierHnt
Copy link
Member

Yes, that's just a warning emitted by Julia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0 Planned for the major 1.0 release doc
Projects
None yet
Development

No branches or pull requests

2 participants