qapply on "(number times operator otimes operator) (vector otimes vector)"

15 views
Skip to first unread message

Uğur Güney

unread,
Aug 25, 2012, 11:13:46 AM8/25/12
to sy...@googlegroups.com
Hi All!

I am working on a research problem and wanted to use sympy's quantum module to do the calculations, because sympy has abstract Ket objects on which one can do many operations without assigning them actual values. I come up with a difficulty

Say I have two Hilbert spaces U and V and on each space I have two vectors

from sympy import *
from sympy.physics.quantum import *

u1=Ket('u1')
u2=Ket('u2')
v1=Ket('v1')
v2=Ket('v2')

projU = u1*u1.dual # a projection operator on u1
print qapply(2*projU*u2) # qapply works as expected
projV = v1*v1.dual # an operator on V
projUV = TensorProduct(projU, projV) # operator on UV
vecUV = TensorProduct(u2,v2) # vector in UV
print qapply(tensor_product_simp(projUV*vecUV)) # works as expected again
print qapply(tensor_product_simp(2*projUV*vecUV)) # the number stops the machinery

outputs:
2*<u1|u2>*|u1>
<u1|u2>*<v1|v2>*|u1>x|v1>
2*(|u1><u1|*|u2>)x(|v1><v1|*|v2>)

I'll be glad if you can tell me how I can qapply on expressions in the form x*projUV*vecUV.

Have a good day!
ugur




Aaron Meurer

unread,
Aug 25, 2012, 2:29:58 PM8/25/12
to sy...@googlegroups.com
I'd say this is a bug. It looks like it's been fixed at
https://github.com/sympy/sympy/pull/1053. That PR seems to have been
stalled, so maybe you could see what needs to be done.

An obvious work-around is to pull out the 2 from the qapply:

In [19]: print 2*qapply(tensor_product_simp(projUV*vecUV)) # the
number stops the machinery
2*<u1|u2>*<v1|v2>*|u1>x|v1>

You can use args_cnc to help automate this:

In [22]: a = (2*projUV*vecUV)

In [24]: a.args_cnc()
Out[24]: [[2], [❘u₁⟩⟨u₁❘⨂ ❘v₁⟩⟨v₁❘, ❘u₂⟩⨂ ❘v₂⟩]]

In [26]: c, nc = a.args_cnc()

In [27]: Mul(*c)*qapply(tensor_product_simp(Mul(*nc)))
Out[27]: 2⋅⟨u₁❘u₂⟩⋅⟨v₁❘v₂⟩⋅❘u₁⟩⨂ ❘v₁⟩

(by the way, we should have an as_commutative_noncommutative method)

I guess that won't work if you need to do factorization, but there are
other methods that can help you there too (like factor_terms).

I hope someone who actually knows the quantum stuff will point it out
if something I said above is wrong.

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

Uğur Güney

unread,
Aug 27, 2012, 1:35:54 PM8/27/12
to sy...@googlegroups.com
Dear Aaron,

Thanks for your help on automation! Because I've a big operator in the form:

c_1*projUV_1* + c_2*projUV_2 + ...

Now I can apply the Mul(*c)*qapply(tensor_product_simp(Mul(*nc))) on each term in a loop. ^_^ I'll try it tonight. I think it would be better if qapply handles this stuff by itself but the workaround is fine with me.

Have a good day!

vug

Aaron Meurer

unread,
Aug 27, 2012, 4:47:37 PM8/27/12
to sy...@googlegroups.com
In that case I would use Add.make_args. But really you are right that apply should be doing this, so hopefully someone will finish that pull request I mentioned. 

Aaron Meurer 
To unsubscribe from this group, send email to sympy+unsubscribe@google

Brian Granger

unread,
Aug 27, 2012, 4:52:32 PM8/27/12
to sy...@googlegroups.com
This pull request definitely needs some attention. I don't have any
time to work on it right now, but it shouldn't be too difficult to
finish.
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgra...@calpoly.edu and elli...@gmail.com

Guru Devanla

unread,
Aug 29, 2012, 9:22:52 AM8/29/12
to sy...@googlegroups.com, elli...@gmail.com
Ok. let me take a look at it and fix the merge conflicts.
Reply all
Reply to author
Forward
0 new messages