bpo-35431: Add a function computing binomial numbers to the math module#11018
bpo-35431: Add a function computing binomial numbers to the math module#11018KellerFuchs wants to merge 20 commits intopython:masterfrom
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Our records indicate we have not received your CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
|
Note that this is a work in progress; currently, it only contains tests specifying the behaviour of the function, so we can more easily discuss what's the desired behaviour. |
bf9a912 to
88c6229
Compare
|
Let's name this comb() instead of binomial() please (as requested by me, Mark, and Tim). |
ff01b25 to
d236eb5
Compare
This is the result of merging python#11018 and python#11414
|
Can we work on PR #11414 since it already passes all tests? Added you as a collaborator. |
| } | ||
| else if (overflow == 1) { | ||
| PyErr_Format(PyExc_OverflowError, | ||
| "(n - k) and k must not exceed %lld", |
There was a problem hiding this comment.
It has to be minimum of the two since the algorithm uses symmetry to reduce no of iterations
|
Also, Is it okay to have multiple methods for tests of a single function? All other function in math have their tests encased in a single method which seems easier to maintain. |
I would assume as much: I modelled those tests after the ones for |
|
@FR4NKESTI3N The main reasons tests are failing is that the I had to reconcile the testsuite in one branch with the implemented behavior in the other, which would have to be done regardless of which branch we are pushing with. I pushed to this PR rather than #11414 because this was the one I had write access to :) |
|
@csabella, @pablogsal, @scoder: Taking the liberty to ping you, since you commented on #11414 This is the PR and testsuite I started during the discussion on
|
|
#11414 was already conflict free and had function name as comb, you needlessly worked by naming and renaming etc. The changes that you made in last 7-8 commits were already there. You were already invited as collaborator. |
Regarding “the last 7-8 commits” you talk of, I have no idea what you are going off, given that all I added since the initial merge 4 days ago (before you commented on this PR or added me as a collaborator) were commits afb3d36 (trivial changes, fixes the testsuite) and e4942bf (trivial rename). Not sure either what you mean by “conflict-free” since there's no conflict between this and On the other hand, recreating all that work on your PR would indeed be unnecessary work.
Not sure that's entirely necessary, but I just did that to avoid having an argument, since it's a quick search-and-replace.
I am absolutely counfunded why you would expect a single function, testing a bunch of unrelated properties, to be more maintainable than separate tests. I assure you, cramming everything into a single test does not make for maintainable testsuites.
Which ones? I am pretty sure I kept them all when merging both testsuites.
Clearly not:
All the things you mentionned existed all along (with the exception of a single search-and-replace for test names), so I'm not sure why you want me to recreate all that on the other PR.
There were changes to the testsuite, which was the whole point of that merge in the first place. |
|
Hmm yeah, I just wanted to say said that it was wasteful. I think I was looking at an earlier commit, so I though that re-merging would be better. |
|
@FR4NKESTI3N I think Also thanks for noticing I had missed the documentation page :) |
|
PS: Just pushed a commit documenting under which circumstances |
|
Having LLONG_MAX doesn't seem right in documentation, maybe we can use something along the lines of "size of long long provided by compiler". This detail is purely implementation based anyway, so I don't know if it should even be there in documentation. Edit: its minimum of the two btw |
|
@FR4NKESTI3N Good point; we might just mention there is a size beyond which The documentation for the |
There was a problem hiding this comment.
| are too large (beyond `LLONG_MAX`). | |
| are too large; the max. value is implementation- and platform-dependent. |
There was a problem hiding this comment.
@FR4NKESTI3N Does that seem like reasonable wording?
|
@KellerFuchs R.Hettinger reviewed the other PR so I have made the changes there. There was some change in implementation so I haven't written anything in docs about OverflowError for until Hettinger decides on implementation. |
|
Please note that the CLA has still not been signed. Without it we cannot accept this PR. |
This is the result of merging python#11018 and python#11414
Search-and-replace to make Yash happy
26691b8 to
bf49e8a
Compare
|
@brettcannon Oh, thanks for the reminder, looks like the CLA signing thing didn't go through properly the first time around (I had some issues with DocuSign); I just redid the thing, so it should be good tomorrow. |
|
PS: Also rebased the branch to deal with the merge conflict. |
| Return the binomial coefficient indexed by the pair of integers n >= k >= 0. | ||
|
|
||
| It is the coefficient of kth term in polynomial expansion of the expression | ||
| (1 + x)^n. It is also known as the number of ways to choose an unordered |
There was a problem hiding this comment.
Other parts of this file use double asterisks (**) for exponentiation, which is less likely to be confused with other meanings such as the XOR operator.
|
Closing in favor of PR 11414. Any remaining ideas from this PR can be brought up in a separate PR. Thanks for the parallel efforts. |
math.binomial(k, n):0 <= k <= n;k > n;kornare negative or non-integral;kornare neitherintnorfloat.math.binomialin C; done by @FR4NKESTI3NProfile/benchmark and optimize if needed.@rhettinger suggested optimizing this, if needed, in a later PR.
https://bugs.python.org/issue35431