matrix_props.is_unitary

Checks if the matrix is a unitary matrix.

Functions

is_unitary(mat[, rtol, atol])

Check if matrix is unitary [1].

Module Contents

matrix_props.is_unitary.is_unitary(mat, rtol=1e-05, atol=1e-08)

Check if matrix is unitary [1].

A matrix is unitary if its inverse is equal to its conjugate transpose.

Alternatively, a complex square matrix \(U\) is unitary if its conjugate transpose \(U^*\) is also its inverse, that is, if

\[\begin{equation} U^* U = U U^* = \mathbb{I}, \end{equation}\]

where \(\mathbb{I}\) is the identity matrix.

Examples

Consider the following matrix

\[\begin{split}X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\end{split}\]

our function indicates that this is indeed a unitary matrix.

>>> from toqito.matrix_props import is_unitary
>>> import numpy as np
>>> A = np.array([[0, 1], [1, 0]])
>>> is_unitary(A)
True

We may also use the random_unitary function from toqito, and can verify that a randomly generated matrix is unitary

>>> from toqito.matrix_props import is_unitary
>>> from toqito.rand import random_unitary
>>> mat = random_unitary(2)
>>> is_unitary(mat)
True

Alternatively, the following example matrix \(B\) defined as

\[\begin{split}B = \begin{pmatrix} 1 & 0 \\ 1 & 1 \end{pmatrix}\end{split}\]

is not unitary.

>>> from toqito.matrix_props import is_unitary
>>> import numpy as np
>>> B = np.array([[1, 0], [1, 1]])
>>> is_unitary(B)
False

References

[1] (1,2)

Wikipedia. Unitary matrix. URL: https://en.wikipedia.org/wiki/Unitary_matrix.

Parameters:
  • mat (numpy.ndarray) – Matrix to check.

  • rtol (float) – The relative tolerance parameter (default 1e-05).

  • atol (float) – The absolute tolerance parameter (default 1e-08).

Returns:

Return True if matrix is unitary, and False otherwise.

Return type:

bool