-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
improve cosc(::Float32)
and cosc(::Float64)
accuracy
#59087
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
improve cosc(::Float32)
and cosc(::Float64)
accuracy
#59087
Conversation
To clarify: the above plots show the error in ULPs. In each case, the plot happens after downsampling by taking the maximum. Also see the linked issue. |
The failing test is just flaky CI, issue #59073 |
4f6ee4e
to
b4b9f26
Compare
Test failure seems surely unrelated. |
7d11d2c
to
bfb32aa
Compare
I've read the pr 3 time by now, and I'm still unsure whether the struct it introduces is worth it. I feel like I n better read the more function based approach in exp.jl, but some portion of that is that I'm the author of those. |
5995cf9
to
8f5a476
Compare
The latest commit ("improve style") improves the style a bit. I wonder if it addresses your concerns somewhat? |
To be clear, is this the minimax polynomial that minimizes the maximum absolute error over the interval, or which minimizes the maximum relative error? Presumably the latter, I hope? I'm a bit concerned that your plot seems to show 1ulp error at Or am I deceived and your plot doesn't actually have the (I'm also not entirely clear on what precisely you are plotting. I'm imagining a plot of relative error |approx–exact|/|exact|, divided by |
Also, you might want to check that |
The idea for this addition to the test suite originates here, where stevengj suggested to do this test for `cosc` specifically: * JuliaLang#59087 (comment) This PR instead tests all applicable functions I could find.
It minimizes relative error. The Anyway if I had chosen to minimize the absolute error with the polynomial, the ULP error plots would have looked quite different.
At Each point on the plot is the result of many evaluations in the same neighborhood, which are aggregated basically by taking the maximum value. Trying to plot every evaluation would result in an unreadably noisy plot, so the idea is basically to get rid of the downward spikes of the noise. Thus the plot visualizes the maximum error in the neighborhood of each point, but not the minimum error. The justification is that the worst case is exactly what is interesting. As an additional explanation, I'll copy over a paragraph from my message on this PR:
If you want I can also share the code I use for plotting. The ULP error itself is calculated using the same code included in this PR, see module
IMO it is fine to minimize the maximum relative error over the entire interval, there's no need to treat the immediate neighborhood of the root specially. (In fact, Sollya is not able to do that in the first place. My own package FindMinimaxPolynomial is able to do that, however it lacks Sollya's functionality for optimizing the coefficients of the polynomial in machine precision.)
An exhaustive comparison of the maximum ULP errors between zero and
See the module abs((approximate - acc) / eps(approximate)) I believe this corresponds exactly to one of the definitions of ULP error, so it's not merely "ULP-like"? |
…59265) The idea for this addition to the test suite originates here, where stevengj suggested to do this test for `cosc` specifically: * #59087 (comment) This PR instead tests all applicable functions I could find. Also fix the sign of `cosc(::BigFloat)` for zero input, thanks to stevengj. --------- Co-authored-by: Steven G. Johnson <[email protected]>
Improve accuracy for `cosc(::Float32)` and `cosc(::Float64)`. This is accomplished by: * Using minimax instead of Taylor polynomials. They're more efficient. The minimax polynomials are found using Sollya. * Using multiple polynomials for different subintervals of the domain. Known as "domain splitting". Enables good accuracy for a wider region around the origin than possible with only a single polynomial. The polynomial degrees are kept as-is. Fixes JuliaLang#59065
Should not be necessary now we have some tests in the test suite.
This reverts commit 33eca5f.
Trust the precision of `accurate` is great enough, unless it's one of the known-imprecise types.
As suggested by devmotion on a PR to LogExpFunctions.jl: * JuliaStats/LogExpFunctions.jl#99
As suggested by devmotion on a PR to LogExpFunctions.jl: * JuliaStats/LogExpFunctions.jl#99
Specialization on the callable argument types should happen anyway.
dc3d649
to
e933115
Compare
bump |
@stevengj, if that addresses your concerns and @oscardssmith is happy, can we merge this? |
I don't think |
Accomplished by:
Using minimax instead of Taylor polynomials. They're more efficient. The minimax polynomials are found using Sollya.
Using multiple polynomials for different subintervals of the domain. Known as "domain splitting". Enables good accuracy for a wider region around the origin than possible with only a single polynomial.
The polynomial degrees are kept as-is.
Fixes #59065