Oscar
Oscar

Reputation: 111

Sympy: "propagate" conjugate into sum

Is there a way to "propagate" a conjugate into a sum?

from sympy import *

k = symbols('k', cls=Idx)
K = symbols('K', type=Integer)
g = IndexedBase('g')
omega = symbols('\omega', real=True)

s = summation(exp(I*omega*k)*g[k], (k,0,K))
sconj=s.conjugate()

Now sconj is

Summation with conjugate

How can I turn this expression into the one below? That is, apply the conjugate on the terms rather than the sum.

Summation with conjugate of the terms

(Which I off course can obtain by taking the conjugate of the terms when creating the summation

summation((exp(I*omega*k)*g[k]).conjugate(), (k,0,K))

but think of the general case where this may be not so straightforward.)

Upvotes: 0

Views: 40

Answers (1)

Oscar
Oscar

Reputation: 111

Just in case someone else runs into this.

It is required to set the summation bound as Real, so changing the definition of K to

K = symbols('K', type=Integer, real=True)

did the trick.

Upvotes: 1

Related Questions