Hello. I have the function binomCoeff defined (from Wikipedia) as:

def binomCoeff ( n, k ) :
        if k < 0 or k > n : return 0
        if k > n - k : k = n - k # take advantage of symmetry
        c = 1
        for i in range ( 1, k + 1 ) : # 1 to k
                c = c * ( n - ( k - i ) )
                c = c // i
        return c

but when I try to use it as part of the definition of a symbolic
function, I get a TypeError:

from sympy import *
var('lamb mu')
l, i = symbols('l i',integer=True)
f=symbols('f',cls=Function)
f = lamb * ( 1 + (-mu)**(l+i) ) * binomCoeff ( l + i, i )
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-da625a708ef7> in <module>()
----> 1 f = lamb * ( 1 + (-mu)**(l+i) ) * binomCoeff ( l + i, i )

<ipython-input-2-f9467fac1a48> in binomCoeff(n, k)
      3         if k > n - k : k = n - k # take advantage of symmetry
      4         c = 1
----> 5         for i in range ( 1, k + 1 ) : # 1 to k
      6                 c = c * ( n - ( k - i ) )
      7                 c = c // i

TypeError: 'Add' object cannot be interpreted as an integer

Obviously it is trying to evaluate the function binomCoeff at the time
of defining of the function f, and I have to tell it to delay the
evaluation of binomCoeff because it is also a symbolic function, but
even if I do binomCoeff=symbols('binomCoeff',cls=Function) and then do
the def binomCoeff stuff, I still get the same error.

I would most appreciate it if anyone could advise me on what to do. Thanks!

-- 
Shriramana Sharma

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to