Opened 8 years ago
Closed 8 years ago
#14247 closed defect (duplicate)
bell numbers in mpmath is incorrect
Reported by: | tscrim | Owned by: | sage-combinat |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | combinatorics | Keywords: | |
Cc: | fredrik.johansson | Merged in: | |
Authors: | Reviewers: | Travis Scrimshaw | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #10170 | Stopgaps: |
Description
With #10170, for at least n >= 30
, mpmath's bell(n)
is incorrect:
sage: bell_number(30, 'mpmath') 846749014511809388871680 sage: bell_number(30, 'gap') 846749014511809332450147
The GAP implementation is the correct one (it agrees with OEIS and the implementation in #10170 for n > 200
). I don't know if this is a me (i.e. this is fixed in an upgrade of mpmath not yet merged as of 5.8.beta1
), sage, or an mpmath issue.
Attachments (1)
Change History (9)
comment:1 Changed 8 years ago by
- Cc fredrik.johansson added
comment:2 Changed 8 years ago by
Changed 8 years ago by
comment:3 Changed 8 years ago by
- Status changed from new to needs_review
Ah okay. Thank you.
I've uploaded a patch which gives bell_number()
an optional argument to temporarily set mpmath's precision higher (thus bell_number()
[with the algorithm set to 'mpmath'] effectively just wraps mpmath's bell
).
comment:4 Changed 8 years ago by
It doesn't make sense to return an incorrect value by default.
A better solution would be to set the precision to say 10 bits, compute p = mpmath.mag(mpmath.bell(n)) + 10, set mpmath.prec = p, then compute ret = ZZ(int(bell(n))).
comment:5 Changed 8 years ago by
- Milestone changed from sage-5.9 to sage-duplicate/invalid/wontfix
comment:6 Changed 8 years ago by
- Status changed from needs_review to positive_review
(so that Jeroen sees it and closes it)
Nathann
comment:7 Changed 8 years ago by
Could you also add this to the description of #10170 and check that the bug is fixed with a doctest there ?
Nathann
comment:8 Changed 8 years ago by
- Resolution set to duplicate
- Reviewers set to Travis Scrimshaw
- Status changed from positive_review to closed
It's not enough to call mpmath.bell(n) and convert to an integer since it gives a floating-point approximation; you need to set the precision to slightly more than log_2(B_n) bits.