-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Complex special functions #30
base: master
Are you sure you want to change the base?
Conversation
and complex erf and Fresnel-integrals |
@@ -56,11 +56,11 @@ The most general type @racket[Real -> (U Zero Flonum)] is used to generate | |||
@racket[lambert]'s contract when it is used in untyped code. Except for this discussion, | |||
this the only type documented for @racket[lambert]. | |||
|
|||
@section[#:tag "real-functions"]{Real Functions} | |||
@section[#:tag "complex-real-functions"]{Complex and real Functions} |
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.
Capitalize Real in title?
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.
I'm largely unqualified to review this...
Computes the @hyperlink["http://en.wikipedia.org/wiki/Gamma_function"]{gamma function}, | ||
a generalization of the factorial function to the entire real line, except nonpositive integers. | ||
a generalization of the factorial function to the entire complex plane, except nonpositive exact integers. |
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.
This suggests that (gamma -13.0) works; is this correct?
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.
this was already the case previously. (gamma -13.0) -> +nan.0
Error is no more than 10 @tech{ulps} everywhere that has been tested, and is usually no more than 4 | ||
ulps. | ||
On the real line the error is no more than 10 @tech{ulps} everywhere that has been tested, and is usually no more than 4 | ||
ulps. In the rest of the complex plane the relative error is smaller than 1e-13 (@tech{ulps}=450). |
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.
I'm confused by this comment. Does the parenthetical mean "smaller than 450 ulps"?
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.
I don't remember why I wrote that. I think I should just drop the part about ulps.
Also I did some extra testing and in the very close region around negative integers the error will be bigger.
I need to think on how to write this down
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.
It may be better to leave a vaguer "Outside the real line, errors are significantly higher". If we're not certain of the guarantees we shouldn't give them, and should warn users that they are higher.
|
||
@defproc[(gamma [x Real]) (U Positive-Integer Flonum)]{ | ||
@defproc[(gamma [x Number]) Number]{ |
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.
Could the result type be more specific? For instance, something including Float-Complex but not all complex numbers?
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 this a question about the documentation, or making the type of my function more specific?
ulps. Error reaches its maximum near negative roots. | ||
} | ||
|
||
@defproc[(psi0 [x Real]) Flonum]{ | ||
@defproc[(psi0 [x Number]) Number]{ |
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.
cf earlier comment about output types
For @racket[erf], error is no greater than 2 @tech{ulps} everywhere that has been tested, and | ||
is almost always no greater than 1. For @racket[erfc], observed error is no greater than 4 ulps, | ||
For @racket[erf], on the real line the error is no greater than 2 @tech{ulps} everywhere that has been tested, and | ||
is almost always no greater than 1. In the complex plane the relative error is smaller 1e-12. For @racket[erfc], observed error is no greater than 4 ulps, |
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.
ITYM "smaller than 1e-12".
@@ -2,7 +2,7 @@ | |||
|
|||
(require "../../flonum.rkt") | |||
|
|||
(provide lanczos-sum lanczos-g) | |||
(provide (all-defined-out)) |
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.
I hate to see a specific provide turn into a generic (all-defined-out), unless... does it really make sense here?
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.
The module had only 2 definitions, which were provided. I added 2 more, which will also be provided. Instead of writing all 4, I thought to use the generic. If this is not the right way, I see no problem to spelling everything out.
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.
We should spell them out. (all-defined-out)
is a code smell, since it fails to even describe the interface provided.
Algorithms for calculating gamma, log-gamma and digamma in the complex field
I'm interested in @soegaard's thoughts here -- I think he knows this code/area the best. |
I'm doing some automated checking of my implementation's results against Wolfram-alpha and I found some problems. I will try to fix them next week. |
@bdeket If you are looking for way to write some randomized tests, here are some ideas. For a real nummer kappa, the following holds [1]: This can be used to test
/Jens Axel [1] https://en.wikipedia.org/wiki/Particular_values_of_the_gamma_function |
I tried to get a general idea of the error in Results: some figures: digamma: (larger errors are near the negative real axis ±0.1i) In conclusion, I don't think this should be merged. But if you have any tips on what would be the minimum to be acceptable, please tell. |
Really nice diagrams. Your comments about using Wolfram Alpha to compute test https://gist.github.com/soegaard/cdba96801778b37713b4cf3add497316 Could you make a similar diagram comparing your gamma with Maxima? If your gamma and Maxima differs more or less the same from Wolfram, |
If you need more digits from Maxima, I have just found out how to activate bigfloats:
|
I don't really have the math background all loaded in, so this is a kind of a shot in the dark, but in computing How can I run your WolframAlpha tests to see if that works? |
Maybe this PR should be changed to draft. |
Sounds good, looking forward to it! |
Ping. |
Well, I'm not totally sure what to do about this PR. IIUC, these implementations have pretty high error on some inputs (bad) and @bdeket was thinking about rewriting them but hasn't. I suppose, given the time elapsed, we shouldn't wait on that. Perhaps the error is not so bad and we should just merge these implementations—though @bdeket disagrees. Fixing up the remaining errors—including some underflows and possibly some cancellations—might fix it, but to be honest I don't really have the mathematical background to be sure it will. |
From what i remember when I started looking into improving it, one hurdle I encountered was: racket/racket#3324. I'll spend some time on these complex special functions in the next weeks to better see the error margins, and report back. |
Algorithms for calculating gamma, log-gamma and digamma in the complex field