-
Notifications
You must be signed in to change notification settings - Fork 70
Add extension for Arblib.jl #723
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
Add extension for Arblib.jl #723
Conversation
This looks great! In #721, we also mentioned special functions; do you think doing something like for f ∈ list_of_special_functions
@eval Arblib.$f(x::Interval) = interval($f(Arblib.Arb(x)))
end is worth it? In the same spirit, maybe we can address #717 as well, which is to add the Arblib routines for multiprecision matrix product. I am not sure what is the best way of doing so, maybe function IA._mul!(::IntervalArithmetic.MatMulMode{:fast}, C::AbstractVecOrMat{<:RealOrComplexI{<:BigFloat}}, A, B, α, β)
# perform the fast Arblib algorithm in extended precision
end is ok? One thing that could be puzzling is that loading Arblib will change the result (though still a rigorous enclosure) of the matrix product when |
Yes, so the conversion to I think directly wrapping the special functions come with some issues. Ball arithmetic (like Arb uses) and infsup interval arithmetic (which IntervalArithmetic uses) tend to have fairly different assumptions about how in particular wide inputs are handled. As an example consider evaluating the gamma function on the interval julia> using Arblib, IntervalArithmetic
julia> interval(Arblib.SpecialFunctions.gamma(Arb((2, 20))))
[-1.67773e+09, 1.21646e+17]₂₅₆_com whereas most user would probably expect something more like julia> interval(Arblib.SpecialFunctions.gamma(Arb(2)), Arblib.SpecialFunctions.gamma(Arb(20)))
[1.0, 1.21646e+17]₂₅₆_com If the user explicitly converts to Arb, calls the special functions and then converts back it would hopefully be more clear to them where this discrepancy is coming from. For #717 I'm not sure what the best approach is, it is certainly a bit awkward to have to different package extensions interact in this way. That I was thinking that I could add some page to the documentation, something like "Interfacing with Arblib.jl", and write something about the discussions here. Then users would at least be aware of the existence of these tools. Then we could leave any direct implementations to the future. Does that sound reasonable to you? In that case I should hopefully be able to write some sort of documentation by the beginning of next week. |
I think that this should never happen. I would prefer to disable the
Improving the tightness of our results is not considering breaking, so it not too much of a problem: we can have loose support right now for convenience's sake, and improve it latter. In particular, in the future, we could change the definition of monotonous special functions to do the smarter thing, and (now that we have piecewise functions) we could even do it for piecewise monotonous ones :D That being said, I don't have a strong opinion either way. In fact, it may be more fitting for a SpecialFunctions.jl extension. |
I think adding a documentation page with short descriptions of all our package extensions is a great idea. Since we haven’t done this before, @Joel-Dahne, feel free to get it started in whatever format you think works best. |
8fe2ad4
to
b3611b2
Compare
I have now added some documentation for the interface. The goal was to give users some ideas of what type of computations could be reasonable to use Arblib.jl for. In the future we might add a similar page of the documentation to Arblib.jl to discuss what type of computations it could be reasonable to use IntervalArithmetic.jl for. I have also added conversion between complex intervals and Let me know if you have any comments, in particular regarding the documentation! Otherwise I think this should in principle be ready to merge. I had some issues building the documentation locally, it didn't load the package extension as I expected. It seems to work in the CI though. |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #723 +/- ##
==========================================
+ Coverage 78.02% 78.16% +0.14%
==========================================
Files 30 31 +1
Lines 2930 2977 +47
==========================================
+ Hits 2286 2327 +41
- Misses 644 650 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b3611b2
to
9b0eb66
Compare
Added some more tests, hopefully Codecov is happier now! |
ext/IntervalArithmeticArblibExt.jl
Outdated
::Type{T}, | ||
a::Arblib.AcbOrRef, | ||
b::Arblib.AcbOrRef, | ||
d::IA.Decoration = com, |
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.
Is a default value for the decoration really needed? And if so, shouldn't that be IA.com
?
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.
Good point, it should be IA.com
. Indeed, it is probably not needed. I copied it from the here and I see now that the these have default values for d
but the versions above don't. I'll remove the default value.
9b0eb66
to
e5ba176
Compare
I removed the default argument for |
This adds support for construction of Interval from Arb and of Arb from Interval. It also handling of some ambiguities related to ExactReal.
e5ba176
to
81c4166
Compare
As discussed in #721, it would be nice to make the Arblib.jl and IntervalArithmetic.jl packages talk to each other. This is an attempt at making basic conversion between
Interval
andArb
work.It is also possible to construct matrices and do basic linear algebra
Implementation
Construction of
Arb
fromInterval
is straightforward. It only requires overloadingArblib.set!
to handle inputs of typeInterval
. To make some of the internal precision handling correct, I also updatedArblib._precision
to be aware of theInterval
type.I realized my first attempt at the construction of
Interval
fromArb
was incorrect. The second attempt was super complicated and used a lot of internals of IntervalArithmetic. The final attempt ended up being fairly simple. For construction, we basically want to treatArb
as equivalent toInterval{BigFloat}
. For this, we defineand make sure that
IntervalArithmetic.promote_numtype
handles promotion withArb
in the way we want. Note that this generates quite a lot of allocation, to compute_inf(x)
it first computes the lower bound as andArf
, then converts it to aBigFloat
and then further converts it to whatever type the interval should be. I could however note figure out a better way to do it at this point.I also made the following updates:
Base.promote_rule
explicitly throw an error for promotion betweenArb
andInterval
.ExactReal
as well asArf
.I added a lot of tests. This was partially because my first few attempts of implementing the constructor were fairly complicated and I wanted to make sure that I checked all edge cases. The final implementation is a lot simpler and maybe doesn't warrant quite as many tests. But testing more never hurts!
Note that a few of the implemented tests are marked as broken. While doing the implementation, I noticed some issues with the
Arblib.getinterval
function for infinite intervals with infinite endpoints. This is due to an issue in Flint that I reported.