toqito.matrix_props.is_density
- toqito.matrix_props.is_density(mat)[source]
Check if matrix is a density matrix [WikDensity].
A matrix is a density matrix if its trace is equal to one and it has the property of being positive semidefinite (PSD).
Examples
Consider the Bell state:
\[u = \frac{1}{\sqrt{2}} |00 \rangle + \frac{1}{\sqrt{2}} |11 \rangle.\]Constructing the matrix \(\rho = u u^*\) defined as
\[\begin{split}\rho = \frac{1}{2} \begin{pmatrix} 1 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 1 \end{pmatrix}\end{split}\]our function indicates that this is indeed a density operator as the trace of \(\rho\) is equal to \(1\) and the matrix is positive semidefinite:
>>> from toqito.matrix_props import is_density >>> from toqito.states import bell >>> import numpy as np >>> rho = bell(0) * bell(0).conj().T >>> is_density(rho) True
Alternatively, the following example matrix \(\sigma\) defined as
\[\begin{split}\sigma = \frac{1}{2} \begin{pmatrix} 1 & 2 \\ 3 & 1 \end{pmatrix}\end{split}\]does satisfy \(\text{Tr}(\sigma) = 1\), however fails to be positive semidefinite, and is therefore not a density operator. This can be illustrated using
toqitoas follows.>>> from toqito.matrix_props import is_density >>> from toqito.states import bell >>> import numpy as np >>> sigma = 1/2 * np.array([[1, 2], [3, 1]]) >>> is_density(sigma) False
References
[WikDensity]Wikipedia: Density matrix https://en.wikipedia.org/wiki/Density_matrix
- Parameters:
mat – Matrix to check.
- Returns:
Return
Trueif matrix is a density matrix, andFalseotherwise.