---
title: "Elementary Arithmetic"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/arithmetic.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/arithmetic.md"
part: "Matrices and Linear Algebra"
chapter: "Sparse Matrices"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Matrices and Linear Algebra", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/index-matrices-linear-algebra.md"}
  - {"title": "Sparse Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/index-sparse-matrices.md"}
prev: {"title": "Predicates", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/predicates.md"}
next: {"title": "Multiplying Vectors or Matrices by Sparse Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/multiply.md"}
intrinsics:
  - {"name": "+", "signature": "A + B: MtrxSprs, MtrxSprs -> MtrxSprs"}
  - {"name": "-", "signature": "A - B: MtrxSprs, MtrxSprs -> MtrxSprs"}
  - {"name": "*", "signature": "A * B: MtrxSprs, MtrxSprs -> MtrxSprs"}
  - {"name": "*", "signature": "x * A: RngElt, MtrxSprs -> MtrxSprs"}
  - {"name": "*", "signature": "A * x: MtrxSprs, RngElt -> MtrxSprs"}
  - {"name": "-", "signature": "-A: MtrxSprs -> MtrxSprs"}
  - {"name": "^-1", "signature": "A ^-1: MtrxSprs, RngIntElt -> MtrxSprs"}
  - {"name": "^", "signature": "A ^ n: MtrxSprs, RngIntElt -> MtrxSprs"}
  - {"name": "Transpose", "signature": "Transpose(A): MtrxSprs -> MtrxSprs"}
---

# Elementary Arithmetic

<a id="operation-op-plus-mtrxsprs-mtrxsprs"></a>
## `A + B: MtrxSprs, MtrxSprs -> MtrxSprs`

Given $m \times n$ sparse matrices $A$ and $B$ over a ring $R$, return $A+B$.

<a id="operation-op-minus-mtrxsprs-mtrxsprs"></a>
## `A - B: MtrxSprs, MtrxSprs -> MtrxSprs`

Given $m \times n$ sparse matrices $A$ and $B$ over a ring $R$, return $A-B$.

<a id="operation-op-times-mtrxsprs-mtrxsprs"></a>
## `A * B: MtrxSprs, MtrxSprs -> MtrxSprs`

Given an $m \times n$ sparse matrix $A$ over a ring $R$ and an $n \times p$ sparse matrix $B$ over $R$, return the $m \times p$ sparse matrix $A\cdot B$ over $R$.

<a id="operation-op-times-rngelt-mtrxsprs"></a>
## `x * A: RngElt, MtrxSprs -> MtrxSprs`

<a id="operation-op-times-mtrxsprs-rngelt"></a>
## `A * x: MtrxSprs, RngElt -> MtrxSprs`

Given an $m \times n$ sparse matrix $A$ over a ring $R$ and a ring element $x$ coercible into $R$, return the scalar product $x\cdot A$.

<a id="operation-operation-mtrxsprs-mtrxsprs"></a>
## `-A: MtrxSprs -> MtrxSprs`

Given a sparse matrix $A$, return $-A$.

<a id="operation-operation-1-mtrxsprs-rngintelt-mtrxsprs"></a>
## `A ^-1: MtrxSprs, RngIntElt -> MtrxSprs`

Given a invertible square sparse matrix $A$ over a ring $R$, return the inverse $B$ of $A$ so that $A\cdot B = B\cdot A = 1$. The coefficient ring $R$ must be either a field, a Euclidean domain, or a ring with an exact division algorithm and having characteristic equal to zero or greater than $m$ (this includes most commutative rings).

<a id="operation-op-pow-mtrxsprs-rngintelt"></a>
## `A ^ n: MtrxSprs, RngIntElt -> MtrxSprs`

Given a square sparse matrix $A$ over a ring $R$ and an integer $n$, return the matrix power $A^n$. $A^0$ is defined to be the identity matrix for any square matrix $A$ (even if $A$ is zero). If $n$ is negative, $A$ must be invertible (see the previous function), and the result is $(A^{-1})^{-n}$.

<a id="function-transpose-mtrxsprs"></a>
## `Transpose(A): MtrxSprs -> MtrxSprs`

Given an $m \times n$ sparse matrix $A$ over a ring $R$, return the transpose of $A$, which is simply the $n \times m$ sparse matrix over $R$ whose $(i,j)$-th entry is the $(j,i)$-th entry of $A$.
