toqito.matrix_props.is_commuting
- toqito.matrix_props.is_commuting(mat_1, mat_2)[source]
Determine if two linear operators commute with each other [WikCom].
For any pair of operators \(X, Y \in \text{L}(\mathcal{X})\), the Lie bracket \(\left[X, Y\right] \in \text{L}(\mathcal{X})\) is defined as
\[\left[X, Y\right] = XY - YX.\]It holds that \(\left[X,Y\right]=0\) if and only if \(X\) and \(Y\) commute [WatCom18].
Examples
Consider the following matrices:
\[\begin{split}A = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}, \quad \text{and} \quad B = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}.\end{split}\]It holds that \(AB=0\), however
\[\begin{split}BA = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} = A,\end{split}\]and hence, do not commute.
>>> from toqito.matrix_props import is_commuting >>> import numpy as np >>> mat_1 = np.array([[0, 1], [0, 0]]) >>> mat_2 = np.array([[1, 0], [0, 0]]) >>> is_commuting(mat_1, mat_2) False
Consider the following pair of matrices:
\[\begin{split}A = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 1 & 0 & 2 \end{pmatrix} \quad \text{and} \quad B = \begin{pmatrix} 2 & 4 & 0 \\ 3 & 1 & 0 \\ -1 & -4 & 1 \end{pmatrix}.\end{split}\]It may be verified that \(AB = BA = 0\), and therefore \(A\) and \(B\) commute.
>>> from toqito.matrix_props import is_commuting >>> import numpy as np >>> mat_1 = np.array([[1, 0, 0], [0, 1, 0], [1, 0, 2]]) >>> mat_2 = np.array([[2, 4, 0], [3, 1, 0], [-1, -4, 1]]) >>> is_commuting(mat_1, mat_2) True
References
[WikCom]Wikipedia: Commuting matrices https://en.wikipedia.org/wiki/Commuting_matrices
[WatCom18]Watrous, John. “The theory of quantum information.” Section: “Lie brackets and commutants”. Cambridge University Press, 2018.
- Parameters:
mat_1 – First matrix to check.
mat_2 – Second matrix to check.
- Returns:
Return True if
mat_1commutes withmat_2and False otherwise.