-
Notifications
You must be signed in to change notification settings - Fork 100
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 lbinomial function based on lbeta #99
Conversation
src/gamma.jl
Outdated
S = float(T) | ||
(k < 0) && return typemin(S) | ||
if n < 0 | ||
n = -n + k - 1 |
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.
Incorrect indentation here (needs one more space)
src/gamma.jl
Outdated
(k == 0 || k == n) && return zero(S) | ||
(k == 1) && return log(abs(n)) | ||
if k > (n>>1) | ||
k = n - k |
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.
Here too
src/gamma.jl
Outdated
end | ||
lbinomial(n::Integer, k::Integer) = lbinomial(promote(n, k)...) | ||
|
||
export lbinomial |
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 go with the other exports.
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 put it now with cosint
. Not sure if this is the "normal" place or not.
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.
Yeah, that's fine.
test/runtests.jl
Outdated
@@ -636,3 +636,17 @@ end | |||
|
|||
@test beta(big(1.0),big(1.2)) ≈ beta(1.0,1.2) rtol=4*eps() | |||
end | |||
|
|||
@testset "lbinomial" begin | |||
lbfixed(n) = k -> lbinomial(n, k) |
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.
Why is this necessary? You can write lbfixed(200).(0:200)
below as lbinomial.(200, 0:200)
.
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.
Note that the same applies to the function defined directly below this line.
Rebased with the corrections, dropped the lambdas in testing. |
Thanks! |
Is it intentional that this function is not documented? Should it be considered public API? |
It's deprecated in favor of SpecialFunctions.jl/src/deprecated.jl Line 14 in 8136181
|
This was originally submitted to base in JuliaLang/julia#27419, but JuliaLang/julia#27473 moved
special/gamma.jl
things here, so I'm making the same PR here now. Details are copied over:This implementation of
lbinomial
uses the fact thatbinomial(n,k) = 1/( (n+1) * B(n - k + 1, k + 1) )
. I have added tests for some simple cases, and then also comparing for very largen
withbinomial(::BigInt, ::BigInt)
.The main motivation is evaluating
log(binomial(n,k))
for largen
withk
nearn/2
without approximating with Poisson:In R, this function is available as
lchoose(n, k)
and is a builtin.