Search code examples
pythonsympysymbolic-mathequation-solving

Why won't SymPy directly solve for the normalization of this wavefunction?


Here is some minimal code demonstrating the problem.

from sympy import *

x = Symbol('x', real=True)
t = Symbol('t', real=True)
A = Symbol('A', real=True, positive=True)
λ = Symbol('λ', real=True, positive=True)
ω = Symbol('ω', real=True, positive=True)

# Define wavefunction
psi_x_t = A * exp(-λ * Abs(x)) * exp(-I*ω*t)

# Normalize
print(solve(integrate(psi_x_t**2, (x, -oo, oo)) - 1))
print(solve(integrate(psi_x_t**2, (x, -oo, oo)) - 1, A))

Where I simply call solve it returns [{t: 0, λ: A**2}]. What I am looking for is actually A=sqrt(λ). But when I include A as the symbol I am solving for I don't get a plus/minus sqrt(λ) but rather an empty collection [].

Why is solve giving me an empty list of solutions, and is there a way to make it directly return the solution for A?


Solution

  • You are not getting a solution because you have declared assumptions on your variables and those assumptions are inconsistent with the solution. Let's try without those assumptions:

    In [20]: from sympy import *
        ...: 
        ...: x = Symbol('x')
        ...: t = Symbol('t')
        ...: A = Symbol('A')
        ...: λ = Symbol('λ')
        ...: ω = Symbol('ω')
        ...: 
        ...: # Define wavefunction
        ...: psi_x_t = A * exp(-λ * Abs(x)) * exp(-I*ω*t)
    
    In [21]: psi_x_t
    Out[21]: 
       -λ⋅│x│  -ⅈ⋅t⋅ω
    A⋅ℯ      ⋅ℯ      
    
    In [22]: eq = integrate(psi_x_t**2, (x, -oo, oo)) - 1
    
    In [23]: eq
    Out[23]: 
    ⎛⎧         2  -2⋅ⅈ⋅t⋅ω                          ⎞    
    ⎜⎪        A ⋅ℯ                                 π⎟    
    ⎜⎪        ────────────          for │arg(λ)│ < ─⎟    
    ⎜⎪             λ                               2⎟    
    ⎜⎪                                              ⎟    
    ⎜⎨∞                                             ⎟ - 1
    ⎜⎪⌠                                             ⎟    
    ⎜⎪⎮   2  -2⋅λ⋅│x│  -2⋅ⅈ⋅t⋅ω                     ⎟    
    ⎜⎪⎮  A ⋅ℯ        ⋅ℯ         dx     otherwise    ⎟    
    ⎜⎪⌡                                             ⎟    
    ⎝⎩-∞                                            ⎠   
    

    I'm guessing that this Piecewise is the reason that you set those assumptions. Let's just manually select the first case of the Piecewise and work from there:

    In [26]: eq1 = piecewise_fold(eq).args[0][0]
    
    In [27]: eq1
    Out[27]: 
     2  -2⋅ⅈ⋅t⋅ω    
    A ⋅ℯ            
    ──────────── - 1
         λ 
    

    Now we solve this:

    In [28]: solve([eq1], [A])
    Out[28]: 
    ⎡⎛     ⅈ⋅t⋅ω ⎞  ⎛    ⅈ⋅t⋅ω ⎞⎤
    ⎣⎝-√λ⋅ℯ     ,⎠, ⎝√λ⋅ℯ     ,⎠⎦
    

    Now for almost all possible values of omega this is not going to be real which is a violation of the assumptions you stated that A should be positive.

    Presumably the equation you actually wanted comes from integrating abs(psi)^2:

    In [34]: from sympy import *
        ...: 
        ...: x = Symbol('x', real=True)
        ...: t = Symbol('t', real=True)
        ...: A = Symbol('A', real=True, positive=True)
        ...: λ = Symbol('λ', real=True, positive=True)
        ...: ω = Symbol('ω', real=True, positive=True)
        ...: 
        ...: # Define wavefunction
        ...: psi_x_t = A * exp(-λ * Abs(x)) * exp(-I*ω*t)
    
    In [35]: eq = integrate(abs(psi_x_t)**2, (x, -oo, oo)) - 1
    
    In [36]: eq
    Out[36]: 
     2    
    A     
    ── - 1
    λ     
    
    In [37]: solve([eq], [A])
    Out[37]: [(√λ,)]
    

    Here only the positive root is returned because we assumed A to be positive.