Arithmetic Matrix Operations



[A,B] and {A, B}

Matrix Commutator and Anticommutator

There are several definitions of the matrix commutator. The commutator defined on the group of nonsingular endomorphisms of an n-dimensional vector space V is defined as ABA-1B-1 where A and B are nonsingular endomorphisms; while the commutator defined on the endomorphism ring of linear transformations of an n-dimensional vector space V is defined as [A,B] = AB - BA, where A and B are endomorphisms. Given a basis of the vector space V, the endomorphisms can be represented as n×n matrices in which the composition of endomorphisms corresponds to the product of their corresponding matrices.

The routines below uses the second definition for the commutator of a matrix, i.e. [A,B] = AB - BA, where A and B are n×n square matrices. The routines below assume that the matrices are either real and the components of which are of type double or complex of which the components are of type double complex.

The anticommutator defined on the endomorphism ring of linear transformations of an n-dimensional vector space V is defined as {A,B} = AB + BA, where A and B are endomorphisms. Again the routines below assume that the matrices are either real and the components of which are of type double or complex of which the components are of type double complex.

Function List

  • void Matrix_Commutator( double *C, double *A, double *B, int n)

    Calculate the commutator C of the n×n square matrix A and the n×n square matrix B, i.e. C = [A,B]. The matrix C should be declared as double C[n][n] in the calling routine. The memory allocated to C should not include any memory allocated to A or B.

  • void cMatrix_Commutator( double complex *C, double complex *A, double complex *B, int n)

    Calculate the commutator C of the n×n square matrix A and the n×n square matrix B, i.e. C = [A,B]. The matrix C should be declared as double complex C[n][n] in the calling routine. The memory allocated to C should not include any memory allocated to A or B.

  • void Matrix_Anticommutator( double *C, double *A, double *B, int n)

    Calculate the anticommutator C of the n×n square matrix A and the n×n square matrix B, i.e. C = {A,B}. The matrix C should be declared as double C[n][n] in the calling routine. The memory allocated to C should not include any memory allocated to A or B.

  • void cMatrix_Anticommutator( double complex *C, double complex *A, double complex *B, int n)

    Calculate the anticommutator C of the n×n square matrix A and the n×n square matrix B, i.e. C = {A,B}. The matrix C should be declared as double complex C[n][n] in the calling routine. The memory allocated to C should not include any memory allocated to A or B.

C Source Code


C Test Code, Test Results, and Build Shell Script

  • The file, testmatrixcommutator.c, contains a test program of Matrix_Commutator( ). This test program requires the file matrix_commutator.c listed above.

  • The file, MatrixCommutatorTests_C.txt, contains the results of the test program testmatrixcommutator.c.

  • The file, testmatrixcommutator.sh, contains the shell script used to compile, link, and execute the test program testmatrixcommutator.c.


  • The file, testcmatrixcommutator.c, contains a test program of cMatrix_Commutator( ). This test program requires the file cmatrix_commutator.c listed above.

  • The file, CMatrixCommutatorTests_C.txt, contains the results of the test program testcmatrixcommutator.c.

  • The file, testcmatrixcommutator.sh, contains the shell script used to compile, link, and execute the test program testcmatrixcommutator.c.


  • The file, testmatrixanticommutator.c, contains a test program of Matrix_Anticommutator( ). This test program requires the file matrix_anticommutator.c listed above.

  • The file, MatrixAnticommutatorTests_C.txt, contains the results of the test program testmatrixanticommutator.c.

  • The file, testmatrixanticommutator.sh, contains the shell script used to compile, link, and execute the test program testmatrixanticommutator.c.


  • The file, testcmatrixanticommutator.c, contains a test program of cMatrix_Anticommutator( ). This test program requires the file cmatrix_anticommutator.c listed above.

  • The file, CMatrixAnticommutatorTests_C.txt, contains the results of the test program testcmatrixanticommutator.c.

  • The file, testcmatrixanticommutator.sh, contains the shell script used to compile, link, and execute the test program testcmatrixanticommutator.c.