The Sympy documentation says that the attribute expr extracts the expression of a Wavefunction object. However, that doesn't seem to work when dealing with linear combinations of wavefunctions.
Consider this example:
import sympy as spfrom sympy.physics.quantum.state import WavefunctionR = sp.Function('R')Z = sp.Function('Z')x,y = sp.symbols('x y', real=True)ϕ = Wavefunction(R(x)*Z(y), x, y)(ϕ+ϕ).exprThe expected behavior would be for it to return the expression inside of ϕ times 2. However, it returns an error:
---------------------------------------------------------------------------AttributeError Traceback (most recent call last)Cell In[316], line 7 3 x,y = sp.symbols('x y', real=True) 5 ϕ = Wavefunction(R(x)*Z(y), x, y)----> 7 (ϕ+ϕ).exprAttributeError: 'Mul' object has no attribute 'expr'So, what is the right approach to extract the resulting expression out of a linear combination of Wavefunction objects?