# Operators

Definition of operators used across Q-CTRL package.

## Projection matrix

Let $\mathcal{H}$ be a $D$-dimensional Hilbert space, and $L(\mathcal{H},\mathcal{H})$ be the $D\times D$ space of operators from $\mathcal{H}\rightarrow\mathcal{H}$. The projection matrix $P\in L(\mathcal{H},\mathcal{H})$ is defined as the square diagonal matrix with elements

\begin{align} P_{ij} = \delta_{ij}p_{j}, \hspace{1cm} p_{j}\in\text{{0,1}} \end{align}

where $\delta_{ij}$ is the Kronecker delta and $p_{j}$ is the $j$th diagonal element of $P$. Alternatively,

\begin{align} P = \text{diag}\left(p\right) \end{align}

where $p = (p_{1},…,p_{D})$ is the $D$-element vector defining the diagonal elements of $P$. The complement projection matrix $P^{c}$ is then defined by

\begin{align} P^{c} = \mathbb{I} - P \end{align}

where $\mathbb{I}$ is the $D\times D$ identity, such $P^{c}$ is also diagonal, with opposite-valued diagonal elements as $P$. Taking the trace of both sides yields the relation $D = \text{Tr}\left(P\right)+\text{Tr}\left(P^{c}\right)$, illustrating how the dimensions of $\mathcal{H}$ are partitioned under $P$ and $P^{c}$.

The matrices $P$ and $P^{c}$ induce projections onto disjoint subspaces of $\mathcal{H}$, of dimension $\text{Tr}\left(P\right)$ and $\text{Tr}\left(P^{c}\right)$ respectively. In particular, for any state $\psi\in\mathcal{H}$ and any operator $\Phi\in L(\mathcal{H},\mathcal{H})$ we may write \begin{align} \psi & = P\psi + P^{c}\psi,\\ \\ \text{Tr}\left(\Phi\right) & = \text{Tr}\left(P\Phi P\right) +\text{Tr}\left(P^{c}\Phi P^{c}\right)\\ &=\text{Tr}\left(P\Phi P + P^{c}\Phi P^{c} \right) \end{align} That is, the transformation $\Phi\rightarrow P\Phi P + P^{c}\Phi P^{c}$ is trace-preserving so that $P\Phi P$ is the projection of $\Phi$ onto the subspace associated with $P$, as measured by the trace operation.