Skip to content
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

Binomial coefficients are not expanded by default #1726

Merged
merged 6 commits into from
Feb 2, 2013

Conversation

prasoon2211
Copy link

Initial fix for issue 3544. Now,

>>> b = binomial(n, 8)

>>> print b
>>> binomial(n, 8)

>>> b.expand(func=True)
>>> n**8/40320 - n**7/1440 + 23*n**6/2880 - 7*n**5/144 + 967*n**4/5760 - 469*n**3/1440 + 363*n**2/1120 - n/8

>>> expand_func(b)
>>> n*(n - 7)*(n - 6)*(n - 5)*(n - 4)*(n - 3)*(n - 2)*(n - 1)/40320

Let me know if more changes are required.
I expect many tests to fail because of this change. I'll update them later.

@prasoon2211
Copy link
Author

It seems I'll have to do a lot of changes throughout the code so that binomial(n, r) is replaced with expand_func(binomial(n, r)). Same thing I'll have to do in the tests.

@asmeurer
Copy link
Member

binomial(-1, 1) should still auto-evaluate.

@asmeurer
Copy link
Member

And it looks like many of the other failures are similar. For example, binomial(S(1)/2, 1) should still auto-evaluate too.

@prasoon2211
Copy link
Author

Yes. You're right. I was checking for binomial(1/2, 1) but not binomial(S(1)/2, 1). The former does evaluate. In any case, I'll correct the errors.

@asmeurer
Copy link
Member

1/2 gives 0 in Python, because of integer division. That's why you have to use S(1)/2, to force it into a SymPy Rational.

@asmeurer
Copy link
Member

Also, please add tests.

@prasoon2211
Copy link
Author

I'll do that as soon as I can fix this.

@prasoon2211
Copy link
Author

I've made some fixes. I believe there shouldn't be any more failed tests. If there aren't, then I'll add some tests of my own. Otherwise, it'll require more fixing.

@prasoon2211
Copy link
Author

Fixed few errors in the doctest and added some documentation. Also, added some tests and doctests. I think things should work now.

@prasoon2211
Copy link
Author

Good to merge? Or changes required?

assert expand_func(binomial(n, 2)) == n*(n - 1)/2
assert expand_func(binomial(n, n - 2)) == n*(n - 1)/2
assert expand_func(binomial(n, n - 1)) == n
assert binomial(n, 3) == binomial(n, 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests like this do nothing. What you should do is test that binomial(n, 3) is still an instance of binomial. The best way to do this is assert binomial(n, 3).func == binomial.

@asmeurer
Copy link
Member

Just those comments. Also, my bot will eventually test this, though just Travis is fine too.

@asmeurer
Copy link
Member

SymPy Bot Summary: 🔴 Failed after merging prasoon2211/binomial-iss3544 (10fb4a5) into master (485b303).
@prasoon2211: Please fix the test failures.
✳️ Python 2.5.0-final-0: pass
✳️ Python 2.6.6-final-0: pass
✳️ Python 2.7.2-final-0: pass
✳️ Python 2.6.8-final-0: pass
✳️ Python 2.7.3-final-0: pass
✳️ PyPy 2.0.0-beta-1; 2.7.3-final-42: pass
✳️ Python 3.2.2-final-0: pass
✳️ Python 3.3.0-final-0: pass
✳️ Python 3.2.3-final-0: pass
✳️ Python 3.3.0-final-0: pass
🔴 Python 3.3.0-final-0: fail
✳️ Sphinx 1.1.3: pass

@prasoon2211
Copy link
Author

Tests are failing on 3.3 because one of them took too long.

@prasoon2211
Copy link
Author

@asmeurer I think this PR is good to merge. I has been lying around for some time now. Not trying to pester or anything .. just checking.

@asmeurer
Copy link
Member

SymPy Bot Summary: 🔴 Failed after merging prasoon2211/binomial-iss3544 (aba9b71) into master (485b303).
@prasoon2211: Please fix the test failures.
✳️ Python 2.5.0-final-0: pass
✳️ Python 2.6.6-final-0: pass
✳️ Python 2.7.2-final-0: pass
✳️ Python 2.6.8-final-0: pass
✳️ Python 2.7.3-final-0: pass
✳️ PyPy 2.0.0-beta-1; 2.7.3-final-42: pass
✳️ Python 3.2.2-final-0: pass
✳️ Python 3.3.0-final-0: pass
✳️ Python 3.2.3-final-0: pass
✳️ Python 3.3.0-final-0: pass
🔴 Python 3.3.0-final-0: fail
✳️ Sphinx 1.1.3: pass

@prasoon2211
Copy link
Author

So is it good enough to be merged? Seems that the bot is passing test for Python 3.3.0-final-0 once and failing at an other time.

@asmeurer
Copy link
Member

asmeurer commented Feb 2, 2013

Sorry, I've been busy. Yes, this looks ok to go.

asmeurer added a commit that referenced this pull request Feb 2, 2013
Binomial coefficients are not expanded by default
@asmeurer asmeurer merged commit b5a477a into sympy:master Feb 2, 2013
@prasoon2211 prasoon2211 deleted the binomial-iss3544 branch February 3, 2013 02:23
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling aba9b71 on prasoon2211:binomial-iss3544 into * on sympy:master*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants