---
title: "Operations on Matrices"
canonical: "https://docs.magma-maths.org/v2.30-1/FiniteGroups/MatrixGroupsOverGeneralRings/operation-element.html"
source: "https://docs.magma-maths.org/v2.30-1/FiniteGroups/MatrixGroupsOverGeneralRings/operation-element.md"
part: "Finite Groups"
chapter: "Matrix Groups over General Rings"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Finite Groups", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/index-finite-groups.md"}
  - {"title": "Matrix Groups over General Rings", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/MatrixGroupsOverGeneralRings/index-matrix-groups-over-general-rings.md"}
prev: {"title": "Homomorphisms", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/MatrixGroupsOverGeneralRings/homomorphism.md"}
next: {"title": "Global Properties", "source": "https://docs.magma-maths.org/v2.30-1/FiniteGroups/MatrixGroupsOverGeneralRings/global-properties.md"}
intrinsics:
  - {"name": "*", "signature": "g * h: GrpMatElt, GrpMatElt -> GrpMatElt"}
  - {"name": "^", "signature": "g ^ n: GrpMatElt, RngIntElt -> GrpMatElt"}
  - {"name": "/", "signature": "g / h: GrpMatElt, GrpMatElt -> GrpMatElt"}
  - {"name": "^", "signature": "g ^ h: GrpMatElt, GrpMatElt -> GrpMatElt"}
  - {"name": "(g, h)", "signature": "(g, h): GrpMatElt, GrpMatElt -> GrpMatElt"}
  - {"name": "(g₁, ..., gᵣ)", "signature": "(g₁, ..., gᵣ): GrpMatElt, ..., GrpMatElt -> GrpMatElt"}
  - {"name": "eq", "signature": "g eq h: GrpMatElt, GrpMatElt -> BoolElt"}
  - {"name": "ne", "signature": "g ne h: GrpMatElt, GrpMatElt -> BoolElt"}
  - {"name": "IsIdentity", "signature": "IsIdentity(g): GrpMatElt -> BoolElt"}
  - {"name": "IsId", "signature": "IsId(g): GrpMatElt -> BoolElt"}
  - {"name": "IsScalar", "signature": "IsScalar(g): GrpMatElt -> BoolElt"}
  - {"name": "Degree", "signature": "Degree(g): GrpMatElt -> RngIntElt"}
  - {"name": "HasFiniteOrder", "signature": "HasFiniteOrder(g): GrpMatElt -> BoolElt, RngIntElt"}
  - {"name": "Order", "signature": "Order(g): GrpMatElt -> RngIntElt, BoolElt"}
  - {"name": "FactoredOrder", "signature": "FactoredOrder(g): GrpMatElt -> [ <RngIntElt, RngIntElt> ], BoolElt"}
  - {"name": "ProjectiveOrder", "signature": "ProjectiveOrder(g): GrpMatElt -> RngIntElt, RngElt"}
  - {"name": "FactoredProjectiveOrder", "signature": "FactoredProjectiveOrder(A): AlgMatElt -> [ <RngIntElt, RngIntElt> ], RngElt"}
  - {"name": "CentralOrder", "signature": "CentralOrder(g : parameters): GrpMatElt -> RngIntElt, BoolElt"}
  - {"name": "CentralOrder", "signature": "CentralOrder(g): GrpPermElt -> RngIntElt"}
  - {"name": "Determinant", "signature": "Determinant(g): GrpMatElt -> RngElt"}
  - {"name": "Trace", "signature": "Trace(g): GrpMatElt -> RngElt"}
  - {"name": "CharacteristicPolynomial", "signature": "CharacteristicPolynomial(g: parameters): GrpMatElt -> RngPolElt"}
  - {"name": "MinimalPolynomial", "signature": "MinimalPolynomial(g): GrpMatElt -> RngPolElt"}
examples:
  - "ex-383e92"
  - "ex-cc263c"
---

# Operations on Matrices

## Arithmetic with Matrices

<a id="operation-op-times-grpmatelt-grpmatelt"></a>
### `g * h: GrpMatElt, GrpMatElt -> GrpMatElt`

The product of matrix $g$ and matrix $h$, where $g$ and $h$ belong to the same generic group $U$. If $g$ and $h$ both belong to the same proper subgroup $G$ of $U$, then the result will be returned as an element of $G$; if $g$ and $h$ belong to subgroups $H$ and $K$ of a subgroup $G$ of $U$ then the product is returned as an element of $G$. Otherwise, the product is returned as an element of $U$.

<a id="operation-op-pow-grpmatelt-rngintelt"></a>
### `g ^ n: GrpMatElt, RngIntElt -> GrpMatElt`

The $n$-th power of the matrix $g$, where $n$ is a positive or negative integer.

<a id="operation-op-div-grpmatelt-grpmatelt"></a>
### `g / h: GrpMatElt, GrpMatElt -> GrpMatElt`

The product of the matrix $g$ by the inverse of the matrix $h$, i.e. the element $g*h^{-1}$. Here $g$ and $h$ must belong to the same generic group $U$. The rules for determining the parent group of $g / h$ are the same as for $g*h$.

<a id="operation-op-pow-grpmatelt-grpmatelt"></a>
### `g ^ h: GrpMatElt, GrpMatElt -> GrpMatElt`

The conjugate of the matrix $g$ by the matrix $h$, i.e. the element $h^{-1}*g*h$. Here $g$ and $h$ must belong to the same generic group $U$. The rules for determining the parent group of $g^h$ are the same as for $g*h$.

<a id="literal-literal-g-h-grpmatelt-grpmatelt-grpmatelt"></a>
### `(g, h): GrpMatElt, GrpMatElt -> GrpMatElt`

The commutator of the matrices $g$ and $h$, i.e. the element $g^{-1}*h^{-1}*g*h$. Here $g$ and $h$ must belong to the same generic group $U$. The rules for determining the parent group of $(g, h)$ are the same as those for $g*h$.

<a id="literal-literal-g1-gr-grpmatelt-grpmatelt-grpmatelt"></a>
### `(g₁, ..., gᵣ): GrpMatElt, ..., GrpMatElt -> GrpMatElt`

Given $r$ matrices $g_1, \ldots, g_r$ belonging to a common group, return their commutator. Commutators are *left-normed*, so they are evaluated from left to right.

<a id="example-ex-383e92"></a>
### `Example: Arithmetic with Matrices in GL(3, 4) (ex-383e92)`

These operations will be illustrated using the group ${\operatorname{GL}}(3, 4)$.

```magma
> K<w> := FiniteField(4);
> GL34 := GeneralLinearGroup(3, K);
> x := GL34 ! [1,w,0, 0,w,1, w^2,0,1];
> y := GL34 ! [1,0,0, 1,w,0, 1,1,w];
> x;
[  1   w   0]
[  0   w   1]
[w^2   0   1]
> y;
[1 0 0]
[1 w 0]
[1 1 w]
> x*y;
[w^2 w^2   0]
[w^2   w   w]
[  w   1   w]
> x^10;
[  w   w   1]
[  w   1   1]
[  w w^2   w]
> x^-1;
[w^2 w^2 w^2]
[  1   w   w]
[  w   w w^2]
> x^y;
[w^2 w^2   0]
[  0 w^2   1]
[w^2 w^2   w]
> x/y;
[  0   1   0]
[  0 w^2 w^2]
[  w   w w^2]
> (x, y);
[  0   w   w]
[  w w^2   1]
[w^2   w w^2]
> (x,y,y);
[w^2   w w^2]
[w^2   w   0]
[w^2   1   w]
```

Arithmetic with group elements is not limited to elements of finite groups. We illustrate with a group of degree 3 over a function field.

```magma
> P<a,b,c,m,x,y,z> := FunctionField(RationalField(), 7);
> S := MatrixGroup< 3, P | [1,a,b,0,1,c,0,0,1],
>                          [1,0,m,0,1,0,0,0,1],
>                          [1,x,y,0,1,z,0,0,1] >;
>
> t := S.1 * S.2;
> t;
[    1     a b + m]
[    0     1     c]
[    0     0     1]
> t^-1;
[          1          -a a*c - b - m]
[          0           1          -c]
[          0           0           1]
> Determinant(t);
1
> t^2;
[              1             2*a a*c + 2*b + 2*m]
[              0               1             2*c]
[              0               0               1]
```

## Predicates for Matrices

<a id="operation-op-eq-grpmatelt-grpmatelt"></a>
### `g eq h: GrpMatElt, GrpMatElt -> BoolElt`

Given matrices $g$ and $h$ belonging to the same generic group, return `true` if $g$ and $h$ are the same element, `false` otherwise.

<a id="operation-op-ne-grpmatelt-grpmatelt"></a>
### `g ne h: GrpMatElt, GrpMatElt -> BoolElt`

Given matrices $g$ and $h$ belonging to the same generic group, return `true` if $g$ and $h$ are distinct elements, `false` otherwise.

<a id="function-isidentity-grpmatelt"></a>
### `IsIdentity(g): GrpMatElt -> BoolElt`

<a id="function-isid-grpmatelt"></a>
### `IsId(g): GrpMatElt -> BoolElt`

Returns `true` if the matrix $g$ is the identity matrix.

<a id="function-isscalar-grpmatelt"></a>
### `IsScalar(g): GrpMatElt -> BoolElt`

Returns `true` if the matrix $g$ is a scalar matrix.

## Matrix Invariants

All of the functions for computing invariants of a square matrix apply to the elements of a matrix group. Here only operations of interest in the context of group elements are described. The reader is referred to Chapter [Matrices](https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/Matrices/index-matrices.md#chapmat) for a complete list of functions applicable to matrices.

<a id="function-degree-grpmatelt"></a>
### `Degree(g): GrpMatElt -> RngIntElt`

The degree of the matrix $g$, i.e. the number of rows/columns of $g$.

<a id="function-hasfiniteorder"></a>
### `HasFiniteOrder(g): GrpMatElt -> BoolElt, RngIntElt`

Returns `true` iff the matrix $g$ has finite order. The second return value is the order if it is finite. The function rigorously proves its result (i.e., the result is not probable). Let $R$ be the ring over which $g$ is defined, and let the degree of the group in which $g$ lies be $n$. If $R$ is finite, then the first return value is trivially `true`. If $R$ is the integer ring then the function works as follows. Suppose first that $g$ has finite order $o$. By a theorem of Minkowski (see Theorem 1.4 [[KP02](https://docs.magma-maths.org/v2.30-1/references.md#cite-kuzpav2002)]), for any odd prime $p$, the reduction mod $p$ of $g$ has order $o$. Let $f(x)\in R[x]$ be the minimal polynomial of $g$. The matrix subalgebra generated by $g$ is isomorphic to the quotient ring $R[x]/\langle f(x) \rangle$, so the order $o$ of $g$ equals the order of $x$ mod $f(x)$. For arbitrary $g$, the algorithm computes the order, $\bar{o}$, of the reduction of $g$ modulo a small odd prime. If $\bar{o}$ is a possible order of an integer matrix of $g$’s dimensions (see Theorem 2.7 *op. cit.*) then this is repeated with a larger prime. If this gives a different order, or the first attempt gave an impossible order, then $g$ has infinite order. We now compute $x^{\bar{o}}\bmod f(x)$. If this is 1, then $\bar{o}$ is the order of $g$, otherwise $g$ has infinite order. If $R$ is the rational field then a necessary condition for $g$ to have finite order is that $f(x)$ has integer coefficients, thus the above algorithm applies in this case. If $R$ is an algebraic number field of degree $d$ over ${\mathbb{Q}}$ (including cyclotomic and quadratic fields), then the standard companion matrix blowup is applied to $g$ to obtain a $(nd)\times(nd)$ matrix over ${\mathbb{Q}}$, and the above algorithm is then applied to this matrix.

<a id="function-order-grpmatelt"></a>
### `Order(g): GrpMatElt -> RngIntElt, BoolElt`

```magma
Proof: BoolElt                    Default: true
```

Given an element $g$ of finite order belonging to a matrix group, this function returns the order of $g$. If $g$ has infinite order, a runtime error results. In the case of a matrix group over a finite field, the algorithm described in [[CLG97b](https://docs.magma-maths.org/v2.30-1/references.md#cite-clg-order)] is used. In all other cases, simple powering of $g$ is used.

The parameter `Proof` is associated with the case when the coefficient ring for $g$ is a finite field. In that case, if `Proof` is set to `false`, then difficult integer factorizations will not attempted. In this situation two values are returned of which the first is a multiple $n$ of the order of $g$. and the second value indicates whether $n$ is known to be the exact order of $g$.

<a id="function-factoredorder-grpmatelt"></a>
### `FactoredOrder(g): GrpMatElt -> [ <RngIntElt, RngIntElt> ], BoolElt`

```magma
Proof: BoolElt                    Default: true
```

Given an element $g$ of finite order belonging to a matrix group, this function returns the order of $g$ as a factored integer. If $g$ has infinite order, a runtime error results. If $g$ has infinite order, the function generates a runtime error. In the case of a matrix group over a finite field, the algorithm described in [[CLG97b](https://docs.magma-maths.org/v2.30-1/references.md#cite-clg-order)] is used. In all other cases, simple powering of $g$ is used. In that case it is more efficient to use this function rather than factorizing the integer returned by `Order(g)`. If $g$ has infinite order, an error ensues.

If the parameter `Proof` is `false`, then difficult integer factorizations are not attempted and the first return value $F$ may contain composite numbers (so that the factorization expands to a multiple of the order of $g$); in any case the second return value indicates whether $F$ is known to be the exact factored order of $g$.

<a id="function-projectiveorder-grpmatelt"></a>
### `ProjectiveOrder(g): GrpMatElt -> RngIntElt, RngElt`

```magma
Proof: BoolElt                    Default: true
```

The projective order $n$ of the matrix $g$, and a scalar $s$ such that $g^n = sI$. The projective order of $g$ is the smallest $n$ such that $g^n$ is a scalar matrix (not just the identity matrix), and it always divides the true order of $A$. The parameter `Proof` is as for `Order`.

<a id="function-factoredprojectiveorder-algmatelt"></a>
### `FactoredProjectiveOrder(A): AlgMatElt -> [ <RngIntElt, RngIntElt> ], RngElt`

```magma
Proof: BoolElt                    Default: true
```

Given a square invertible matrix $A$ over a finite field $K$, return the projective order $n$ of $A$ in factored form and a scalar $s\in K$ such that $A^n = sI$. The parameter `Proof` is as for `FactoredOrder`.

<a id="function-centralorder-grpmatelt"></a>
### `CentralOrder(g : parameters): GrpMatElt -> RngIntElt, BoolElt`

<a id="function-centralorder-grppermelt"></a>
### `CentralOrder(g): GrpPermElt -> RngIntElt`

```magma
Proof: BoolElt                    Default: true
```

Return the smallest $n$ such that $g^n$ is central in its parent group. If $g$ is a matrix and the optional parameter `Proof` is `false`, then accept a multiple of this value; the second value returned is `true` if the answer is exact.

<a id="function-determinant-grpmatelt"></a>
### `Determinant(g): GrpMatElt -> RngElt`

The determinant of the matrix $g$.

<a id="function-trace-grpmatelt"></a>
### `Trace(g): GrpMatElt -> RngElt`

The trace of the matrix $g$.

<a id="function-characteristicpolynomial-grpmatelt"></a>
### `CharacteristicPolynomial(g: parameters): GrpMatElt -> RngPolElt`

```magma
Al   : MonStgElt                    Default: "Modular"
Proof: BoolElt                      Default: true
```

Given a matrix $g$ belonging to a subgroup of ${\operatorname{GL}}(n, R)$, where $R$ is a field or Euclidean Domain, return the characteristic polynomial of $g$ as an element of the univariate polynomial ring over $R$. For details on the parameters, see the function `CharacteristicPolynomial` in the chapter on matrices.

<a id="function-minimalpolynomial-grpmatelt"></a>
### `MinimalPolynomial(g): GrpMatElt -> RngPolElt`

Given a matrix $g$ belonging to a subgroup of ${\operatorname{GL}}(n, R)$, where $R$ is a field or $Z$, return the minimal polynomial of $g$ as an element of the univariate polynomial ring over $R$.

<a id="example-ex-cc263c"></a>
### `Example: Invariants of Matrices in GL(3, 4) (ex-cc263c)`

We illustrate the matrix operations by applying them to some elements of ${\operatorname{GL}}(3, 4)$.

```magma
> K<w> := FiniteField(4);
> GL34 := GeneralLinearGroup(3, K);
> x := GL34 ! [w,0,1, 0,1,0, 1,0,1];
> x;
[w 0 1]
[0 1 0]
[1 0 1]
> Degree(x);
3
> Determinant(x);
w^2
> Trace(x);
w
> Order(x);
15
> m<t> := MinimalPolynomial(x);
> m;
t^3 + w*t^2 + w^2
> Factorization(m);
[
    <t + 1, 1>,
    <t^2 + w^2*t + w^2, 1>
]
> c<t> := CharacteristicPolynomial(x);
> c;
t^3 + w*t^2 + w^2
```
