2

Let there be the following program

from sympy import *

n,m=symbols('n m')

print(binomial(n,m).subs([(m,0),(n,-1)]))

print(binomial(n,m).subs([(n,-1),(m,0)]))

result:

1
zoo

Why is the result different?

Vladimir
  • 21
  • 1
  • Unrelated with the 'zoo' tag, in sympy zoo is the complex infinity. That said, pretty good question, I can imagine how sympy tried to simplify the first substitution *then* the second, and failed, but it's clearly a bug. The first is correct, with usual definitions of binomial coefficients for negative n. –  Sep 26 '21 at 20:52
  • Not sure what the conclusion is but this PR shows a length discussion about binomial coefficients at negative integers: https://github.com/sympy/sympy/pull/18960 – Oscar Benjamin Sep 26 '21 at 21:45
  • 1
    @OscarBenjamin I don't think it's related. The question there is about binomial(n,k) for negative k. For negative n and nonnegative k there is no problem, using the usual binomial(x,k)=x(x-1)...(x-k+1)/k!, for all x (even noninteger). –  Sep 26 '21 at 22:13

0 Answers0