Ticket #7562 (closed defect: fixed)
Another (new?) binomial bug
| Reported by: | kcrisman | Owned by: | AlexGhitza |
|---|---|---|---|
| Priority: | major | Milestone: | sage-4.3 |
| Component: | basic arithmetic | Keywords: | |
| Cc: | hgranath | Work issues: | |
| Report Upstream: | N/A | Reviewers: | Karl-Dieter Crisman |
| Authors: | Håkan Granath | Merged in: | sage-4.3.rc0 |
| Dependencies: | Stopgaps: |
Description
From sage-devel:
In [143]: [binomial(1,1),binomial(1,2),binomial(1,3),binomial(1,4)] Out[143]: [1, 0, 0, 0] In [144]: [binomial(1.0,1),binomial(1.0,2),binomial(1.0,3),binomial (1.0,4)] Out[144]: [1.00000000000000, 0.000000000000000, NaN, NaN]
The problem is this:
sage: x = RealNumber('1.0')
sage: P = x.parent()
sage: P
Real Field with 53 bits of precision
sage: gamma(x+1)/gamma(P(Integer(4)+1))/gamma(x-Integer(4)+1)
NaN
sage: gamma(x-Integer(4)+1)
NaN
So we'll have to put in yet another check...
Attachments
Change History
comment:2 Changed 3 years ago by hgranath
- Status changed from needs_review to needs_work
Sorry, my patch is off for negative x. I will send an updated patch later.
comment:3 in reply to: ↑ 1 ; follow-up: ↓ 4 Changed 3 years ago by kcrisman
By the way, is the cc field above supposed to notify me by mail? I did not get any.
Yes, and it does usually work, but perhaps you don't have a correct email associated to your account. I don't know how to fix this, you may want to ask on sage-devel.
comment:4 in reply to: ↑ 3 Changed 3 years ago by hgranath
Replying to kcrisman:
Yes, and it does usually work, but perhaps you don't have a correct email associated to your account. I don't know how to fix this, you may want to ask on sage-devel.
Thanks for the info, I found some place to enter my email so probably it will work now.
comment:6 Changed 3 years ago by kcrisman
- Status changed from needs_review to needs_work
- Reviewers set to Karl-Dieter Crisman
- Authors set to Hakan Granath
This seems to work fine, and agrees with integer calculations. Obviously passes tests.
But:
sage: binomial(0,0) 1 sage: binomial(0.,0) NaN
I don't know which is the usual convention, but they should probably agree.
comment:7 Changed 3 years ago by hgranath
- Status changed from needs_work to needs_review
- Authors changed from Hakan Granath to Håkan Granath
Thanks for spotting this, new version is up.


Here is a patch that should fix this issue. Note that for x a negative floating point integer we hit gamma function poles both in the numerator and denominator. An alternative formula is used in the patch to avoid this.
By the way, is the cc field above supposed to notify me by mail? I did not get any.