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

nC doc example in sympy live shows TypeError: 'Integer' object is not iterable #52

Closed
snowch opened this issue Nov 15, 2021 · 1 comment

Comments

@snowch
Copy link

snowch commented Nov 15, 2021

The first code block for nC shows an error:

Python console for SymPy 1.5.1 (Python 2.7.12)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)

>>> from sympy.functions.combinatorial.numbers import nC
>>> from sympy.utilities.iterables import multiset_combinations
>>> nC(3, 2)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/base/data/home/apps/s~sympy-live-hrd/66.426491309333028408/sympy/sympy/functions/combinatorial/numbers.py", line 1715, in nC
    return nC(_multiset_histogram(n), k, replacement)
  File "/base/data/home/apps/s~sympy-live-hrd/66.426491309333028408/sympy/sympy/functions/combinatorial/numbers.py", line 1435, in _multiset_histogram
    n = list(n)
TypeError: 'Integer' object is not iterable
>>> nC('abc', 2)
3

>>> nC('aab', 2)
2

Also the last code block errors too:

>>> sum(nC(4, i) for i in range(5))
Exception in SymPy Live of type 
<type 'exceptions.TypeError'>
for reference the last 5 stack trace entries are
Traceback (most recent call last):
  File "/base/data/home/apps/s~sympy-live-hrd/66.426491309333028408/app/handlers.py", line 271, in post
    live.evaluate(statement, session, printer, stream)
  File "/base/data/home/apps/s~sympy-live-hrd/66.426491309333028408/app/shell.py", line 280, in evaluate
    exec code in statement_module.__dict__
  File "<string>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
@snowch snowch changed the title nC example in sympy live shows TypeError: 'Integer' object is not iterable nC doc example in sympy live shows TypeError: 'Integer' object is not iterable Nov 15, 2021
@oscarbenjamin
Copy link
Contributor

This is because sympy-live is running an older version of sympy: sympy/sympy-live#175

SymPy master gives:

In [1]: from sympy.functions.combinatorial.numbers import nC

In [2]: nC(3, 2)
Out[2]: 3

In [3]: sum(nC(4, i) for i in range(5))
Out[3]: 16

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

No branches or pull requests

2 participants