'How to set the BaseScalars of a CoordSys3D() to be real in Sympy?

I am trying to symbolically calculate the inner product of two spatially dependent quantum states using sympy. For example (in Jupyter Notebook):

import numpy as np
from sympy import *
from sympy.vector import  CoordSys3D, gradient

phi_l, k = symbols('\phi_l k', real=True)
k1, k2, k3, k4, k5 = np.eye(5) # Basis states of the Hilbert space states are in.
R = CoordSys3D('R')
psi = sin(phi_l)*exp(-1j*4*k*R.x)*k1 - cos(phi_l)*exp(-1j*(3*R.x+R.y)*k)*k2
# R.x, R.y, R.z are the BaseScalars of the Coordinate system
np.dot(psi.conjugate(), psi)

outputs

enter image description here

Though this is correct and suffices for me, I'd like to know how to set the BaseScalars R.x, R.y and R.z as real. This will simplify my expression to 1. I checked the source of CoordSys3D. It seems like I have to inherit this class and modify the __init__ method myself. Is there a simpler way to do this?

Thanks.



Solution 1:[1]

As far as I am aware, it is not possible to set assumptions on base scalars. In your case, going with OOP and implement a different behaviour might end up to be a nightmare.

This is how I would do it: substitute the base scalar with ordinary symbols with assumptions:

expr = np.dot(psi.conjugate(), psi)
xr, yr, zr = R.base_scalars()
x, y, z = symbols("x:z", real=True)
expr.subs({xr:x , yr:y, zr: z}).simplify()

# out: 1.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Davide_sd