34.1 Operations for Matrices

mat + scalar
scalar + mat

This forms evaluates to the sum of the matrix mat and the scalar scalar. The elements of mat and scalar must lie in a common field. The sum is a new matrix where each entry is the sum of the corresponding entry of mat and scalar.

mat1 + mat2

This form evaluates to the sum of the two matrices mat1 and mat2, which must have the same dimensions and whose elements must lie in a common field. The sum is a new matrix where each entry is the sum of the corresponding entries of mat1 and mat2.

mat - scalar
scalar - mat
mat1 - mat2

The definition for the - operator are similar to the above definitions for the + operator, except that - subtracts of course.

mat * scalar
scalar * mat

This forms evaluate to the product of the matrix mat and the scalar scalar. The elements of mat and scalar must lie in a common field. The product is a new matrix where each entry is the product of the corresponding entries of mat and scalar.

vec * mat

This form evaluates to the product of the vector vec and the matrix mat. The length of vec and the number of rows of mat must be equal. The elements of vec and mat must lie in a common field. If vec is a vector of length n and mat is a matrix with n rows and m columns, the product is a new vector of length m. The element at position i is the sum of vec[l] * mat[l][i] with l running from 1 to n.

mat * vec

This form evaluates to the product of the matrix mat and the vector vec. The number of columns of mat and the length of vec must be equal. The elements of mat and vec must lie in a common field. If mat is a matrix with m rows and n columns and vec is a vector of length n, the product is a new vector of length m. The element at position i is the sum of mat[i][l] * vec[l] with l running from 1 to n.

mat1 * mat2

This form evaluates to the product of the two matrices mat1 and mat2. The number of columns of mat1 and the number of rows of mat2 must be equal. The elements of mat1 and mat2 must lie in a common field. If mat1 is a matrix with m rows and n columns and mat2 is a matrix with n rows and o columns, the result is a new matrix with m rows and o columns. The element in row i at position k of the product is the sum of mat1[i][l] * mat2[l][k] with l running from 1 to n.

mat1 / mat2
scalar / mat
mat / scalar
vec / mat

In general left / right is defined as left * right^-1. Thus in the above forms the right operand must always be invertable.

mat ^ int

This form evaluates to the int-th power of the matrix mat. mat must be a square matrix, int must be an integer. If int is negative, mat must be invertible. If int is 0, the result is the identity matrix, even if mat is not invertible.

mat1 ^ mat2

This form evaluates to the conjugation of the matrix mat1 by the matrix mat2, i.e., to mat2^-1 * mat1 * mat2. mat2 must be invertible and mat1 must be such that these product can be computed.

vec ^ mat

This is in every respect equivalent to vec * mat. This operations reflects the fact that matrices operate on the vector space by multiplication from the right.

scalar + matlist
matlist + scalar
scalar - matlist
matlist - scalar
scalar * matlist
matlist * scalar
matlist / scalar

A scalar scalar may also be added, subtracted, multiplied with, or divide into a whole list of matrices matlist. The result is a new list of matrices where each matrix is the result of performing the operation with the corresponding matrix in matlist.

mat * matlist
matlist * mat

A matrix mat may also be multiplied with a whole list of matrices matlist. The result is a new list of matrices, where each matrix is the product of mat and the corresponding matrix in matlist.

matlist / mat

This form evaluates to matlist * mat^-1. mat must of course be invertable.

vec * matlist

This form evaluates to the product of the vector vec and the list of matrices mat. The length l of vec and matlist must be equal. All matrices in matlist must have the same dimensions. The elements of vec and the elements of the matrices in matlist must lie in a common field. The product is the sum of vec[i] * matlist[i] with i running from 1 to l.

Comm( mat1, mat2 )

Comm returns the commutator of the matrices mat1 and mat2, i.e., mat1^-1 * mat2^-1 * mat1 * mat2. mat1 and mat2 must be invertable and such that these product can be computed.

There is one exception to the rule that the operands or their elements must lie in common field. It is allowed that one operand is a finite field element, a finite field vector, a finite field matrix, or a list of finite field matrices, and the other operand is an integer, an integer vector, an integer matrix, or a list of integer matrices. In this case the integers are interpreted as int * GF.one, where GF is the finite field (see Operations for Finite Field Elements).

For all the above operations the result is new, i.e., not identical to any other list (see Identical Lists). This is the case even if the result is equal to one of the operands, e.g., if you add zero to a matrix.

Up Top Next
Index

GAP 3.4.4
April 1997