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 On Sat, Aug 25, 2012 at 2:29 PM, Aaron Meurer <[email protected]> wrote: > 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 > > On Sat, Aug 25, 2012 at 9:13 AM, Uğur Güney <[email protected]> wrote: > > 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 > > > > > > > > > > -- > > You received this message because you are subscribed to the Google Groups > > "sympy" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > > http://groups.google.com/group/sympy?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
