sympy icon indicating copy to clipboard operation
sympy copied to clipboard

sympy can't handle symbolic Sum of JzKets

Open James471 opened this issue 2 years ago • 2 comments

I tried to create a linear combination of sympy.physics.quantum.spin.JzKets using state = sm.Sum((2**m)*qt.spin.JzKet(J, m), (m, -J, J)) and tried to find it's norm using (sympy.physics.quantum.qapply(qt.Dagger(state)*state).doit()) The output is image which is clearly incorrect. Cleary qapply() doesn't understand a Sum object.

James471 avatar Jul 23 '22 12:07 James471

Can you show a complete code example to reproduce this including imports? What should the correct answer be?

It might be a bug in Sum rather than qapply.

The quantum module is currently unmaintained. Feel free to submit a PR to fix this.

oscarbenjamin avatar Jul 24 '22 14:07 oscarbenjamin

Following are the imports I used to reproduce this issue:

import sympy as sp
from sympy.abc import k,m,J

import sympy.physics.quantum as qt

import sympy.concrete.summations as sm

The OP's statement state = sm.Sum((2**m)*qt.spin.JzKet(J, m), (m, -J, J)) produces the output to be: Screenshot 2023-05-15 at 6 47 43 PM which, while "looks" correct to our expectation, is not, as is indicated by: Screenshot 2023-05-15 at 6 51 36 PM

This shows that the object is not behaving as a quantum state, but instead the $\sum_m 2^m$ chunk of the expression is being interpreted by sympy as a separate, geometric summation. The kets $|J,m\rangle$ ought to be part of the summation as well.

Hence, I do believe that it's an inadequacy of Sum, as suggested—an incompatibility of Sum and Quantum objects' implementations.

Above,state is a <class 'sympy.concrete.summations.Sum'> object, while one would expect a correct implementation to return an object of perhaps some subclass of <class 'sympy.physics.quantum.state'>.

These seem to be the reasons (or more) for the OP's issue, hereby seen reproduced with a slight deviation (suspected to be from some update ever since): Screenshot 2023-05-15 at 7 37 48 PM

Attempting to calculate OP's desired norm expression by alternatively using the innerproduct method, hints that we should perhaps somehow try to implement returning a sympy.physics.quantum.state.KetBase object. Screenshot 2023-05-15 at 8 03 50 PM

kushagrasachan avatar May 15 '23 14:05 kushagrasachan

I am wondering if this issue can be solved, because I also confront the same problem when I want to define a thermal state in Fock basis. image The problem here is that the summation function cannot recognize the dummy index inside the braket notation like sum over k for |k><k|.

travlight avatar Mar 05 '24 17:03 travlight