# Determinant and Other Properties

## `Determinant(A: parameters): Mtrx -> RngElt`

```magma
MonteCarloLevel: RngIntElt                    Default: 0
Proof          : BoolElt                      Default: true
pAdic          : BoolElt                      Default: true
Divisor        : RngIntElt                    Default: 0
```

Given a square matrix $A$ over the ring $R$, return the determinant of $A$ as an element of $R$. $R$ may be any commutative ring. The determinant of the $0 \times 0$ matrix over $R$ is defined to be `R!1`. If the coefficient ring is the integer ring ${\mathbb{Z}}$ or the rational field ${\mathbb{Q}}$ then a modular algorithm based on that of Abbott et al. [[Abbott *et al.*, 1999](../../references.md#cite-abm-det)] is used, which first computes a divisor $d$ of the determinant $D$ using a fast $p$-adic nullspace computation, and then computes the quotient $D/d$ by computing the determinant $D$ modulo enough small primes to cover the Hadamard bound divided by $d$. This always yields a correct answer. If the parameter `MonteCarloLevel` is set to a small positive integer $s$, then a probabilistic Monte-Carlo modular technique is used. Rather than using sufficient primes to cover the Hadamard bound divided by the divisor $d$, this version of the algorithm terminates when the constructed residue remains constant for $s$ steps. The probability of this being wrong is non-zero but extremely small, even if $s$ is only 1 or 2. If the level is set to 0, then the normal deterministic algorithm is used. Setting the parameter `Proof` to `false` is equivalent to setting `MonteCarloLevel` to 2. If the coefficient ring is ${\mathbb{Z}}$ and the parameter `Divisor` is set to an integer $d$, then $d$ must be a known exact divisor of the determinant (the sign does not matter), and the algorithm may be sped up because of this knowledge.

## `Trace(A): Mtrx -> RngElt`

Given a square matrix $A$ over the ring $R$, return the trace of $A$ as an element of $R$, which is simply the sum of the diagonal elements of $A$.

## `TraceOfProduct(A, B): Mtrx, Mtrx -> RngElt`

Given square matrices $A$ and $B$ over the ring $R$, with the same size, return the trace of $A\cdot B$ as an element of $R$. This is in general much faster than the call `Trace(A*B)`.

## `Rank(A): Mtrx -> RngIntElt`

Given an $m \times n$ matrix $A$ over a ring $R$, return the rank of $A$. This is defined to be the largest $r$ such that there exists a non-zero $r \times r$ subdeterminant of $A$, so $r\leq m$ and $r \leq n$. The rank may have to be obtained by computing the Smith form or echelon form of $A$, and this computation may be quite expensive over some rings.

## `Minor(M, i, j): Mtrx, RngIntElt, RngIntElt -> RngElt`

The determinant of the submatrix of $M$ (which must be square) formed by removing the $i$-th row and $j$-th column.

## `Minor(M, I, J): Mtrx, [RngIntElt], [RngIntElt] -> RngElt`

The determinant of the submatrix of $M$ given by the row indices in $I$ and the column indices in $J$.

## `Minors(M, r): Mtrx, RngIntElt -> SeqEnum`

Returns a sequence of all the $r$ by $r$ minors of the matrix $M$.

## `Cofactor(M, i, j): Mtrx, RngIntElt, RngIntElt -> RngElt`

The appropriate cofactor of $M$, equal to $(-1)^{i+j}$ times the corresponding minor.

## `Cofactors(M): Mtrx -> SeqEnum`

Returns a sequence of all the cofactors of the matrix $M$.

## `Cofactors(M, r): Mtrx, RngIntElt -> SeqEnum`

Returns a sequence of all the $r$ by $r$ cofactors of the matrix $M$.

## `Pfaffian(M): Mtrx -> RngElt`

## `Pfaffian(M, I, J): Mtrx, [RngIntElt], [RngIntElt] -> RngElt`

## `Pfaffians(M, r): Mtrx, RngIntElt -> SeqEnum`

Let $M$ be an anti-symmetric square matrix. Then its determinant is always a square and a particular square-root of this, which can be described by a universal polynomial in its entries, is called the Pfaffian of $M$. The first function returns this. The second function returns the Pfaffian of the submatrix of $M$ described by the indices in $I$ and $J$. The third function returns the sequence of Pfaffians of the ${n \choose r}$ principal $r$ by $r$ submatrices of $M$ ($n=$ the number of rows of $M$).

These are primarily convenience functions and are computed naively by Pfaffian row-expansion.
