Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in sympy.physics.quantum "qapply" #6073

Closed
asmeurer opened this issue Jan 10, 2012 · 1 comment · Fixed by #24164
Closed

Bug in sympy.physics.quantum "qapply" #6073

asmeurer opened this issue Jan 10, 2012 · 1 comment · Fixed by #24164

Comments

@asmeurer
Copy link
Member

asmeurer commented Jan 10, 2012

(Note: this was originally reported at #945 )

There seems to be a bug in qapply, both in 0.7.1 and in the current git HEAD.
I was triggering it when trying qapply(vacuum.dual*A) , where vacuum.dual is a custom Bra-class that I'm hacking on, and A is a quantum operator. I am not sure if my Bra-class does indeed conform to what is required for such, but I believe the bug is independent from that. The main requirements are that the two objects are non-commutative things that do not know how to be applied to each other (i.e. lhs._apply_operator(rhs) and vice versa fails). In this case qapply_Mul will continue to try the previous pair in the multiplication via line 166 of qapply.py:

    return qapply_Mul(e._new_rawargs(*(args+[lhs])), **options)*rhs

Now if this was actually the first pair of the multiplication, e._new_rawargs(*(args+[lhs])) will return lhs itself (might this be the bug indeed?). The new call of qapply_Mul will then work on the lhs object, assuming it is Mul, which it isn't. It probably most often goes unnoticed since it has a high chance of bailing out early either due to lhs not having two arguments or one of them being commutative.
The solution should probably be simple, just check for for an empty args at that line.
A testcase will need a lefthandside object that is not commutative and at least two non-commutative arguments. I was unable to find a good example, and my quick try at a simple example Bra-class was not successful.

@oscarbenjamin
Copy link
Contributor

@Costor should this one be reopened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants