subs in a sum

21 views
Skip to first unread message

Thomas Ligon

unread,
Oct 8, 2020, 3:30:44 PM10/8/20
to sympy
Here is a code snippet (for test purposes):

from sympy import symbols, I, oo, Sum, exp
a, s, t, j = symbols('a s t j')
ex = Sum(a*exp((2*s + 1)*I*t), (s, -oo, oo))
print(ex)
ex = ex.subs(s, j)
print(ex)

The subs statement has no effect. Is there another way to do this?

Aaron Meurer

unread,
Oct 8, 2020, 3:33:57 PM10/8/20
to sympy
subs() doesn't replace s because it is a bound variable. You can use
replace or xreplace to do it.

>>> Sum(a*exp((2*s + 1)*I*t), (s, -oo, oo)).xreplace({s: j})
Sum(a*exp(I*t*(2*j + 1)), (j, -oo, oo))

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/57c9522d-7e3b-42be-88cb-1834a3d49efdn%40googlegroups.com.

Thomas Ligon

unread,
Oct 8, 2020, 4:03:45 PM10/8/20
to sympy
Thanks! I tried both replace and xreplace (to learn more) and they both worked for me, so I chose replace, since it looks simpler.
Reply all
Reply to author
Forward
0 new messages