Operators¶
Operators $\hat{\Omega}$ in quantum theory comes in many flavours, but in all cases they act on kets to produce new kets:
\begin{equation} \hat{\Omega} \vert p \rangle = \vert q \rangle. \end{equation}import braketlab as bk
import numpy as np
import sympy as sp
x = sp.symbols("x") # we'll need a variable for the following examples
Identity¶
For a given space $\mathbf{S}$ spanned by a basis $\{ \vert s \rangle \}$, the identity operator is
\begin{equation} \mathbb{1} := \sum_i \vert s_i \rangle \langle s_i \vert \end{equation}The corresponding operator
Translation¶
psi = bk.ket( sp.exp(-1*x**2))
psi.view(web = True)
T = bk.get_translation_operator(np.array([2.1]))
(T*psi).view(web = True)
Differentials¶
Differential operators $\hat{D}^{o}_{\{ i \}}$ of order $o$ with respect to variables $i$ acting on kets yields their derivatives of the given order with respect to the relevant variables:
\begin{equation} \hat{D}^o_{\{i \}} \vert p \rangle := \sum_i \big{(} \frac{\partial}{\partial x_i} \big{)}^o p(\mathbf{x}) \end{equation}If no variables are provided when initializing the operator, BraketLab will assume that the differential operator acts on all variables in the ket (note that this can give inconsistent behavior - it just differentiates everything it encounters).
a = bk.ket( sp.exp(-x**2), name = "a(x)")
a.view(web = True)
D = bk.get_differential_operator(order = [1])
(D*a).view(web = True)
(D*(D*a)).view(web = True)
Cartesian moments¶
The cartesian n'th moment operators $\hat{X}^n_i$ are
\begin{equation} \hat{X}^n_i = x_n^i \end{equation}Since BraketLab is largely based on sympy, they can be defined simply as
x = bk.get_default_variables(0, 1)[0]
X = x**1.0 # for n=1
Let's center a one dimensional Gaussian distribution in $x_0 = .25$, normalize it, and compute the expectation value $\langle x \rangle$:
psi = bk.ket( sp.exp(-(x-.25)**2))
psi = psi*(psi.bra@psi)**-.5 # normalize so that <psi|psi> = 1.0
psi.bra@(X*psi) #should be zero for n=1
0.25
You may then construct arbitrary higher order moments:
x, y = bk.get_default_variables(0, 2)
psi = bk.ket( sp.exp(-.5*((x-.25)**2 + (y+0.3)**2 )) )
psi = psi*(psi.bra@psi)**-.5 # normalize so that <psi|psi> = 1.0
X2Y = x**2*y
psi.bra@(X2Y*psi) # will be computed using Monte-Carlo integration
-0.1683970226816998
Coulomb operator¶
The Coulomb operator is
\begin{equation} \hat{V} = \frac{1}{\hat{x}}, \end{equation}and may be obtained in BraketLab from
V = bk.get_onebody_coulomb_operator()
psi.bra@(V*psi)
-1.6408515032825146
Kinetic operator¶
The kinetic operator is
\begin{equation} \hat{V} = - \frac{1}{2} \nabla^2, \end{equation}and may be obtained in BraketLab from
T = bk.get_kinetic_operator()
psi.bra@(T*psi)
0.4996613505912549