-
Notifications
You must be signed in to change notification settings - Fork 27
Make pochhammer more robust #72
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
Conversation
Added function newgamma which is identical to gamma but returns Inf at negative integers.
Update specialfunctions.jl
Make sure your tests pass on Travis. I believe you forgot an Also, it would be more natural to have a special function specifically for |
Thanks for taking a look at this! Special functions are always tricky to implement and my early version of the Pochhammer symbol is quite naive. While we're at it, we may as well consider all cases. Let me start mapping out some cases that come to mind for real numbers. Formally, (x)n = gamma(x+n)/gamma(x), but this runs into trouble when For (-x)n = sinpi(x)/sinpi(x-n) (x-n+1)n This formula is a start, but more details arise in the implementation of the ratio of sines (or cardinal sines), especially as Now, if julia> log2(-1.0)
ERROR: DomainError with -1.0:
NaN result for non-NaN input. because Finally, if |
Codecov Report
@@ Coverage Diff @@
## master #72 +/- ##
=========================================
+ Coverage 52.3% 52.41% +0.1%
=========================================
Files 33 33
Lines 3185 3188 +3
=========================================
+ Hits 1666 1671 +5
+ Misses 1519 1517 -2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #72 +/- ##
===========================================
+ Coverage 52.3% 72.35% +20.04%
===========================================
Files 33 33
Lines 3185 2308 -877
===========================================
+ Hits 1666 1670 +4
+ Misses 1519 638 -881
Continue to review full report at Codecov.
|
src/specialfunctions.jl
Outdated
@@ -61,6 +61,14 @@ function pochhammer(x::Number,n::UnitRange{T}) where T<:Real | |||
ret | |||
end | |||
|
|||
function ogamma(x::Number) | |||
if isinteger(x) && x<0 | |||
0.0 |
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 should be type stable: zero(float(x))
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.
Also, why not x ≤ 0
?
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.
Because the original gamma
already returns Inf
gamma(0.0)=Inf
gamma(-0.0)=-Inf
src/specialfunctions.jl
Outdated
if isinteger(x) && x<0 | ||
0.0 | ||
else | ||
1.0/gamma(x) |
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.
inv(gamma(x))
is cleaner.
@test pochhammer(-1,2) == 0 | ||
@test pochhammer(-5,3) == -60 | ||
@test pochhammer(-1,-0.5) == 0 | ||
@test 1.0/pochhammer(-0.5,-0.5) == 0 |
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.
Add complex tests?
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.
gamma
is nonzero and holomorphic except the singularities, so complex tests don't make any difference, I suppose. I skipped array tests, though. Maybe add some array tests
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 mean complex types but at integers: ogamma(-1+0im)
test/specialfunctionstests.jl
Outdated
@test pochhammer(-1,-0.5) == 0 | ||
@test 1.0/pochhammer(-0.5,-0.5) == 0 | ||
@test pochhammer(-1+0im,-1) == -2 | ||
@test pochhammer([2,-5,-1],3) == [24,-60,0] |
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.
vector-valued arguments should be deprecated in favour of pochhammer.([2,-5,-1],3)
, so perhaps remove this test.
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.
So can pochhammer(x::AbstractArray{T},n::Integer)
be removed? Do abstractarrays work with dot operations?
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 can be deprecated, though that can be done separately. Yes abstract arrays support broadcastibg
Merge pull request JuliaApproximation#72 from putianyi889/master
pochhammer
can now deal with arbitrary::Number
without throwing unexpected errors.I did this by adding a modified version of
gamma
function namednewgamma
which returnsInf
at negative integers.Added a test file.
Edit: following @dlfivefifty 's suggestion, I used
ogamma
which returns 0 at negative integers.