The Bra-Ket Notation & Principles
====================
In quantum mechanics, braket notation is a way of representing the wavefunction and the operators that act on it. It is a powerful tool that allows us to mathematically describe the behavior of particles in a quantum system.
Here, we examine the case of a single particle in 3D space for simplicity. Nevertheless, all we discuss below can be extended to the case of multiple particles.
In quantum mechanics, a state of a physical system is described by a **wavefunction**
$\displaystyle \boldsymbol{\Psi}: \mathbb{R}^{3} \to \mathbb{C}$, a complex-valued function of the position $\displaystyle \boldsymbol r$ of the system.
The wavefunction has a property that the integral of the square of its amplitude should be 1. We call it the normalization condition:
$$
\int_{\mathbb{R}^3} |\boldsymbol \Psi(\boldsymbol r)|^2 d\boldsymbol r=1.
$$
Therefore, it is natural to see $|\boldsymbol \Psi(\boldsymbol r)|^2$ as a probability density. It has a physical interpretation: This probability density corresponds to the position of the particle. For a region $D$, $\int_{D} |\boldsymbol \Psi(\boldsymbol r)|^2 d\boldsymbol r$ measures the probability of finding the particle in that region.
For example, in 1D case, wave function tells the probability that a particle will be in the interval $a<r<b$:
$$
P\left( a<r<b \right) = \int_a^b | \boldsymbol \Psi(\boldsymbol r) |^2 d\boldsymbol r.
$$

Mathematically, we say that the wavefunction is a **vector** in a Hilbert space $\displaystyle \mathcal{H}$. For AI folks, dealing with vectors is a familiar concept (like in CV, NLP, etc.), and we can think of the Hilbert space as a vector space that is infinite-dimensional.
From now on, we may use the term *wavefunction* and *state vector* interchangeably.
By using the language of Hilbert space, we can work with the functions in a similar way to how we work with vectors.
First, let's introduce a familiar concept, inner-product.
### Inner-product
The inner-product is a commonly-used operation when we deal with vectors. For 2 vectors $a$ and $b$, the inner-product is nothing but $a^{\mathsf{T}}b$. In some places, you might encounter the notation $\langle a, b \rangle$ to denote the inner-product. In most cases(for real-value vector), it is the same thing as $a^{\mathsf{T}}b$.
Things might be a slightly different when the vector is complex-value. Here, you need to tweak a little bit to consider also the conjugate of complex number.
> A conjugate of $z = a + ib$ is $\bar z = a - ib$. It flips the imagine part. Alternatively, you can think of replacing all $i$ with $-i$.
The inner product is $\langle a, b \rangle = \bar a^{\mathsf{T}}b$. To give a quick sense of why we need to change $a$ to $\bar a$, think of $\langle z, z\rangle = |z|^2 = \bar zz$ for a single-value case.
Now we are working on a space where a wavefunction is also regarded as a vector. It is interesting to see what is the inner-product between wavefunction.
We can finally introduce the braket notation: The braket notation is composed of two part: the *ket* and the *bra*. They are just the right-part and the left-part of the inner-product. When *bra* and *ket* comes together, they denote the inner-product of wavefunction(vector).

For a wavefunction $\displaystyle \boldsymbol{\Psi}$, we note it as $\displaystyle | \boldsymbol{\Psi} \rangle$ to represent it as a vector in $\displaystyle \mathcal{H}$. Dirac, the physician, called these elements *kets*.
A *bra* is of the form $\displaystyle \langle \boldsymbol{\Phi}|$. It acts on the left-hand side of the inner-product in $\displaystyle \mathcal{H}$. Mathematically it denotes a linear form $\displaystyle \mathcal{H} \to \mathbb {C}$, i.e. **a linear map** that maps each wavefunction in $\displaystyle \mathcal{H}$ to a scalar. Letting the *bra* $\displaystyle \langle \boldsymbol{\Phi}|$ act on a *ket* $\displaystyle |\boldsymbol{\Psi}\rangle$ is written as $\displaystyle \langle \boldsymbol{\Phi}|\boldsymbol{\Psi}\rangle \in \mathbb {C}$.
To perform calculations using braket notation, we use the inner product. The inner product is a mathematical operation that takes two wave functions and produces a scalar value. It is used to find the overlap between two wave functions or to calculate the expectation value of an operator.
Braket notation, or Dirac notation, is a shorthanded notation for the inner-product of the wavefunction. Writing $\displaystyle \langle \boldsymbol{\Phi}|\boldsymbol{\Psi}\rangle$ just means you are doing $\displaystyle \langle \boldsymbol{\Phi}|\boldsymbol{\Psi}\rangle = \int \boldsymbol{\Phi}^*( \boldsymbol r)\boldsymbol{\Psi} ( \boldsymbol r) d \boldsymbol r$.
For example, the normalization condition can be rewritten as $\langle \Psi | \Psi\rangle = 1$.
### Bras and kets as row and column vectors
Ideally, we would like to work on the Hilbert space $\displaystyle \mathcal{H}$ directly, but its infinite-dimensional nature
makes it difficult for machine computation[^1].
[^1]: to compute on today's von Neumann architecture computers
Instead, we would like to work on a finite-dimensional subspace, which is spanned by a set of basis function $\displaystyle \{ |g_i\rangle \}$, where $\displaystyle |g_i\rangle$ is a basis vector in $\displaystyle \mathcal{H}$. In this subspace, we can represent the wavefunction $\displaystyle \boldsymbol{\Psi}$ as a linear combination of the basis functions.
For example, if we have a system with $N$ basis functions $g_i$, the wavefunction $\displaystyle \boldsymbol{\Psi}$ can be written as:
$$
\begin{equation}
| \boldsymbol{\Psi} \rangle = \sum_{i=1}^N a_i | g_i \rangle.
\end{equation}
$$
Here, $a_i$ are the coefficients. Ideally, we want the **basis** vectors $|g_i\rangle$ to be orthonormal. Under this basis, the state vector $|\mathbb{\Psi}\rangle$ can be written as a column vector:
$$
\begin{equation}
| \boldsymbol{\Psi} \rangle=\begin{pmatrix}
a_1 \\
a_2\\
\vdots \\
a_N
\\
\end{pmatrix}.
\end{equation}
$$
and the bra notation $\langle \boldsymbol{\Psi} |$ denotes the conjugate transpose[^2] of $| \boldsymbol{\Psi} \rangle$, which is
$$
\langle \boldsymbol{\Psi} | = (\bar a_1, \bar a_2, \dots, \bar a_N).
$$
[^2]: The conjugate transpose of $\Psi$ are often noted as $\Psi^*$ or $\Psi^\dagger$.
The inner product of two state vectors can be therefore written as
$$
\begin{align}
\langle \boldsymbol{\Psi}_a | \boldsymbol{\Psi}_b \rangle &= \int_{\mathbb{R}^3} \boldsymbol{\Psi}^*_a(\boldsymbol r)\boldsymbol{\Psi}_b( \boldsymbol x)d\boldsymbol{r}\\
&= \int_{\mathbb{R}^3} \sum_i \sum_j \bar a_i b_j g_i(\boldsymbol{r}) g_j(\boldsymbol{r}) d\boldsymbol{r} \\
&= \sum_i \bar a_i b_i.
\end{align}
$$
This is quite similar to the inner product of two vectors in $\mathbb{R}^N$. The simplicity of the result is due to the fact that the basis functions are orthonormal.
### Operator and Measurement
In quantum mechanics, operators are mathematical functions that act on the wavefunction of a quantum system to produce a new wavefunction.
When an operator acts on a wavefunction, it is written as a product of the operator and the wavefunction. For example, $\hat A |\boldsymbol{\Psi}\rangle$ represents the action of the operator $\hat A$ on the wave function $|\boldsymbol{\Psi}\rangle$.
Similar to linear algebra, you can think of the operator as a matrix, and the wave function as a column vector.
Each physical quantity is associated with a self-adjoint (some people call this property Hermitian) **operator** $\hat A$ (physicians call it *observable*, we will see the reason why it is called this way very soon), which is a linear map from $\mathcal{H}$ to $\mathcal{H}$, *i.e.* $\hat A: \mathcal{H} \to \mathcal{H}$. There is a theorem says that from the property of self-adjointness, we can know that the eigenvalues of $\hat A$ are real numbers.
Similar to the eigenvalues and eigenvectors of a matrix, the eigenvalues of an operator are called **eigenvalues** and the corresponding eigenvectors are called **eigenstates**. The **eigenstates** is a set of speicial wavefunctions that are orthogonal to each other.
We just mention above that each physical quantity is associated with an operator, whose eigenvalues are all real numbers. For example, we associate the position operator $\hat x$ with the position of a particle, and the momentum operator $\hat p$ with the momentum of a particle, the energy operator(more commonly called Hamiltonian) $\hat H$ with the energy of a particle, etc.
The fundamental principle of quantum mechanics states that after a measurement of the physical quantity (e.g. energy), the system will be in one of the eigenstates of the operator $\hat A$(e.g. $\hat H$) with the corresponding eigenvalue (e.g. measured energy). This is the reason why we need the eigenvalues to be real: You can never measure a physical quantity and get a result as a complex number! In other words, only real-eigenvalue operators are physically observable.
The probability of the system being in the eigenstate $| \boldsymbol{\Psi} \rangle$ is proportional to the square of the amplitude of the state vector in that component. Let's see an example below:
Suppose in our case that the Hamiltonian operator $\hat H$ has only two eigenvalues $E_1$ and $E_2$, and the corresponding eigenstates are $| \boldsymbol{\Psi}_1 \rangle$ and $| \boldsymbol{\Psi}_2 \rangle$. It means that for any state, after a measurement of the energy, the system will be in one of the two states $| \boldsymbol{\Psi}_1 \rangle$ or $| \boldsymbol{\Psi}_2 \rangle$. The measured energy will be either $E_1$ or $E_2$ and no other value is possible. This reveals the discrete nature of physical quantity in quantum mechanics.
For a particle in a state $a_1 | \boldsymbol{\Psi}_1 \rangle + a_2 | \boldsymbol{\Psi}_2 \rangle$, (we assume that it is already normalized, *i.e.* $|a_1|^2 + |a_2|^2 = 1$), the probability of the particle being in the state $| \boldsymbol{\Psi}_1 \rangle$ is $|a_1|^2$, and the probability of the particle being in the state $| \boldsymbol{\Psi}_2 \rangle$ is $|a_2|^2$.
In other words, after a measurement of the energy, the probability of getting the energy $E_1$ is $|a_1|^2$, and the probability of we get the energy $E_2$ is $|a_2|^2$.
However, if the particle is in one of the eigenstates, the probability of getting the corresponding eigenvalue is 1, and the probability of getting the other eigenvalue is 0. Only when the particle is in one of the eigenstates, we know *a priori* the value of the energy obtained from the measurement. Otherwise, the god rolls the dice!
### Expectation of a physical quantity
Due to the probabilistic nature of quantum mechanics, we do not talk about the exact value of a physical quantity, but the **expectation** of the physical quantity, given a state $| \boldsymbol{\Psi} \rangle$.
To obtain the expectation of the operator $\hat A$ with respect to $| \boldsymbol{\Psi} \rangle$, we need to calculate the inner product of $\langle \boldsymbol{\Psi} |$ and $\hat A | \boldsymbol{\Psi} \rangle$, that is, $\langle \boldsymbol{\Psi} | \hat A | \boldsymbol{\Psi} \rangle$.
Suppose we have an operator $\hat A$, the **expectation** of $\hat A$ is defined as,
$$
\begin{align}
\langle \hat A \rangle_\Psi := \langle \boldsymbol{\Psi} | \hat A | \boldsymbol{\Psi} \rangle
= \int_{\mathbb{R}^3} \boldsymbol{\Psi}^*(\boldsymbol r) \left( \hat A\boldsymbol{\Psi}( \boldsymbol r) \right) d\boldsymbol{r}.
\end{align}
$$
If $| \boldsymbol{\Psi} \rangle$ happens to be an eigenstate of $\hat A$, then the expectation value of $\hat A$ is simply the eigenvalue of $\hat A$ in that state.
Still take the above example, for the wavefunction in the state $a_1 | \boldsymbol{\Psi}_1 \rangle + a_2 | \boldsymbol{\Psi}_2 \rangle$, the expectation of its energy is $a_1^2 E_1 + a_2^2 E_1$.