Intances of the BraketLab ket
-class are able to do most of the things you would expect if them: they can be added and subtracted, multiplied in various ways with scalars and each other, projected into other bases, formed into inner products, acted upon by operators and much more. In addition, they have a .view()
, which yields a visualization in the representation they were defined. (BraketLab kets are defined in a given representation, not from operators, and as such may have a conceptual difference from the Dirac-kets you find in books).
Let's defined two harmonic oscillator functions in position representation to illustrate the algebra:
import braketlab as bk
p = bk.basisbank.get_harmonic_oscillator_function(1)
q = bk.basisbank.get_harmonic_oscillator_function(2)
(p+q).view(web = True)
(p-q).view(web = True)
(2.0*p).view(web = True)
The inner product can be defined in various ways. In BraketLab it is either the dot product for vectors in Euclidean space:
\begin{equation} \langle p \vert q \rangle := \sum_{i} p_i q_i, \end{equation}or the Hermitian inner product for the vector space of complex functions of arbitrary dimensionality:
\begin{equation} \langle p \vert q \rangle := \int_{\mathbb{R}^N} p(\mathbf{x})^* q(\mathbf{x}) d\mathbf{x}. \end{equation}You may compute it as follows:*
p.bra@q #should be zero for the orthogonal eigenstates of the Harmonic Oscillator
0.0
Note that the inner-product of BraketLab is approximated numerically for complex functions, using quadrature in one dimension and Monte Carlo-integration in higher dimensions.
The pointwise product for two functions $p$ and $q$ is
\begin{equation} (p \cdot q)(x) = p(x) \cdot q(x) \end{equation}In BraketLab, the corresponding operation is
(p*q).view(web = True)
For convenience, the direct product in BraketLab is defined to be
\begin{equation} p(\mathbf{x}) \times q(\mathbf{x}) = p(\mathbf{x}_1) q(\mathbf{x}_2). \end{equation}The forking of the variable $\mathbf{x}$ is done to simplify treatment of many-body systems and separable Hamiltonians, which was some of the original focus of BraketLab. It is computed as follows:
(p@q).view()
The outer product is special to linear algebra, but is still useful within BraketLab for many reasons. For our purpose, you may view it as
\begin{equation} \vert p \rangle \langle q \vert \end{equation}and compute it by
P = p@q.bra
P
The bra in the expression above is more than simply a complex conjugate ket - it is an instruction to integrate whatever it encounter to its right. This can be understood from the following operations (make sure you agree that the first operation yields a blank window while the second do not:
(P*p).view(web = True)
(P*q).view(web = True)