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.