On Sun, Nov 18, 2012 at 10:03 PM, Chris Smith <smi...@gmail.com> wrote:
>>>> _.replace(f, lambda x: x**2)

No I mean: I have individual values for lamb0, lamb1, lamb2, lamb3. So
what I did was:

from sympy import *
var('i j n')
lamb=Function('lamb')
f=Sum(lamb(i)*(-1)**(n-j)*binomial(i,n-j),(i,n-j,n))
mylamb=list(var('lamb:4'))
nval=3
for jval in range(nval+1):
        print(f.subs(((j,jval),(n,nval))).doit().replace(lamb,lambda
x:mylamb[x]))

which gave the "desired" output of:

-lamb3
lamb2 + 3*lamb3
-lamb1 - 2*lamb2 - 3*lamb3
lamb0 + lamb1 + lamb2 + lamb3

Obviously I'll have to have a proper mylamb list (containing floats)
for my application, but this is just experimentation...

But what's with so many ((( with the subs method?

> I'm not sure what you mean. Using summation is ding it with sympy semantics.
> Perhaps you can post the way you think is un-sympy-ish.

What I considered *unsympyish* is to do instead of summation(f,(i,a,b)):

s=0
for ival in range(a,b+1): s+=f.subs(i,ival)

BTW can you please clarify the difference between Sum and summation?
The doc says "represents unevaluated summation". So is it just that
until I say doit() it doesn't give me the output but remains a
symbolic function or such?

Another curious thing which I came across in the process of the above:

In [1]: from sympy import *
In [2]: lamb=list(var('lamb:4'))
In [3]: lamb
Out[3]: [lamb0, lamb1, lamb2, lamb3]
In [4]: lamb0=4
In [5]: lamb
Out[5]: [lamb0, lamb1, lamb2, lamb3]
In [6]: lamb[0]
Out[6]: lamb0
In [7]: type(lamb[0])
Out[7]: sympy.core.symbol.Symbol
In [8]: type(lamb0)
Out[8]: builtins.int

I don't get it -- there are *two* objects with name lamb0 in the
current namespace? How can that be?

Thanks as ever!

-- 
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