Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What guarantees simplify()?

How to convert (n!/k!)*binomial(k,n-k) to factorials? From an answer of tmonteil in question 30394:

expr = n.factorial()/k.factorial()*binomial(k,n-k)

factorial(n)/(factorial(2*k - n)*factorial(-k + n))

The new question is: what is the contract of simplify() (or factorial_simplify())?

I think a simplification is only useful if it returns an equivalent expression. Is this is guaranteed?

In our example: Take n=1 and k=0. expr is 0 in this case but expr.factorial_simplify() is not defined (or gives an ValueError if executed) because factorial(2*k-n) = factorial(-1).

So my question might be rephrased: Is this an accidental bug or a systematic unreliability which renders simplify() essentially useless?