matrix_props.is_density

Checks if the matrix is a density matrix.

Functions

is_density(mat)

Check if matrix is a density matrix [1].

Module Contents

matrix_props.is_density.is_density(mat)

Check if matrix is a density matrix [1].

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)
np.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 toqito as 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

[1] (1,2)

Wikipedia. Density matrix. URL: https://en.wikipedia.org/wiki/Density_matrix.

Parameters:

mat (numpy.ndarray) – Matrix to check.

Returns:

Return True if matrix is a density matrix, and False otherwise.

Return type:

bool