---
title: "Elements of Residue Class Rings"
canonical: "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/elements.html"
source: "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/elements.md"
part: "Basic Rings"
chapter: "Integer Residue Class Rings"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Basic Rings", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/index-basic-rings.md"}
  - {"title": "Integer Residue Class Rings", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/index-residue-class-rings.md"}
prev: {"title": "Residue Class Rings", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/residue-class-rings.md"}
next: {"title": "Ideal Operations", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/ideal-ops.md"}
intrinsics:
  - {"name": "elt", "signature": "elt< R | k >: RngIntRes, RngIntElt -> RngIntResElt"}
  - {"name": "!", "signature": "R ! k: RngIntRes, RngIntElt -> RngIntResElt"}
  - {"name": "One", "signature": "One(R): RngIntRes -> RngIntResElt"}
  - {"name": "Identity", "signature": "Identity(R): RngIntRes -> RngIntResElt"}
  - {"name": "Zero", "signature": "Zero(R): RngIntRes -> RngIntResElt"}
  - {"name": "Representative", "signature": "Representative(R): RngIntRes -> RngIntResElt"}
  - {"name": "Random", "signature": "Random(R): RngIntRes -> RngIntResElt"}
  - {"name": "+", "signature": "+ n: RngIntResElt -> RngIntResElt"}
  - {"name": "-", "signature": "- n: RngIntResElt -> RngIntResElt"}
  - {"name": "+", "signature": "m + n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "-", "signature": "m - n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "*", "signature": "m * n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "^", "signature": "n ^ k: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "/", "signature": "m / n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "div", "signature": "m div n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "+:=", "signature": "m +:= n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "-:=", "signature": "m -:= n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "*:=", "signature": "m *:= n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "/:=", "signature": "m /:= n: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "^:=", "signature": "m ^:= k: RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "eq", "signature": "m eq n: RngIntResElt, RngIntResElt -> BoolElt"}
  - {"name": "ne", "signature": "m ne n: RngIntResElt, RngIntResElt -> BoolElt"}
  - {"name": "in", "signature": "n in R: RngIntResElt, Rng -> BoolElt"}
  - {"name": "notin", "signature": "n notin R: RngIntResElt, Rng -> BoolElt"}
  - {"name": "Parent", "signature": "Parent(n): RngIntResElt -> RngIntRes"}
  - {"name": "Category", "signature": "Category(n): RngIntResElt -> Cat"}
  - {"name": "IsZero", "signature": "IsZero(n): RngIntResElt -> BoolElt"}
  - {"name": "IsOne", "signature": "IsOne(n): RngIntResElt -> BoolElt"}
  - {"name": "IsMinusOne", "signature": "IsMinusOne(n): RngIntResElt -> BoolElt"}
  - {"name": "IsNilpotent", "signature": "IsNilpotent(n): RngIntResElt -> BoolElt"}
  - {"name": "IsIdempotent", "signature": "IsIdempotent(n): RngIntResElt -> BoolElt"}
  - {"name": "IsUnit", "signature": "IsUnit(n): RngIntResElt -> BoolElt"}
  - {"name": "IsZeroDivisor", "signature": "IsZeroDivisor(n): RngIntResElt -> BoolElt"}
  - {"name": "IsRegular", "signature": "IsRegular(n): RngIntRes -> BoolElt"}
  - {"name": "IsIrreducible", "signature": "IsIrreducible(n): RngIntResElt -> BoolElt"}
  - {"name": "IsPrime", "signature": "IsPrime(n): RngIntResElt -> BoolElt"}
  - {"name": "Solution", "signature": "Solution(a, b): RngIntResElt, RngIntResElt -> RngIntResElt"}
  - {"name": "IsSquare", "signature": "IsSquare(n): RngIntResElt -> BoolElt, RngIntResElt"}
  - {"name": "Sqrt", "signature": "Sqrt(a): RngIntResElt -> RngIntResElt"}
  - {"name": "SquareRoot", "signature": "SquareRoot(a): RngIntResElt -> RngIntResElt"}
  - {"name": "AllSquareRoots", "signature": "AllSquareRoots(a): RngIntResElt -> [ RngIntResElt ]"}
  - {"name": "AllSqrts", "signature": "AllSqrts(a): RngIntResElt -> [ RngIntResElt ]"}
examples:
  - "ex-c52d75"
---

# Elements of Residue Class Rings

## Creation

<a id="constructor-constructor-elt-rngintres-rngintelt-rngintreselt"></a>
### `elt< R | k >: RngIntRes, RngIntElt -> RngIntResElt`

Create the residue class containing the integer $k$ in residue class ring $R$.

<a id="operation-op-rngintres-rngintelt"></a>
### `R ! k: RngIntRes, RngIntElt -> RngIntResElt`

Create the residue class containing $k$ in the residue class ring $R$. Here $k$ is allowed to be either an integer, or an element of the finite field ${\mathbb{F}}_p$ in the case $R = {\mathbb{Z}}/p{\mathbb{Z}}$, or an element of $S = {\mathbb{Z}}/n{\mathbb{Z}}$ for a multiple or divisor $n$ of $m$ (with $R = {{\mathbb{Z}}/m{\mathbb{Z}}}$).

<a id="function-one-rngintres"></a>
### `One(R): RngIntRes -> RngIntResElt`

<a id="function-identity-rngintres"></a>
### `Identity(R): RngIntRes -> RngIntResElt`

<a id="function-zero-rngintres"></a>
### `Zero(R): RngIntRes -> RngIntResElt`

<a id="function-representative-rngintres"></a>
### `Representative(R): RngIntRes -> RngIntResElt`

These generic functions (cf. Chapter [Introduction to Rings](https://docs.magma-maths.org/v2.30-1/BasicRings/IntroductionToRings/index-introduction-to-rings.md#rngintro)) create $1$, $1$, $0$, and $0$ respectively, in any ${{\mathbb{Z}}/m{\mathbb{Z}}}$.

<a id="function-random-rngintres"></a>
### `Random(R): RngIntRes -> RngIntResElt`

Create a “random” residue class in $R$.

## Arithmetic Operators

<a id="operation-operation-rngintreselt-rngintreselt"></a>
### `+ n: RngIntResElt -> RngIntResElt`

<a id="operation-operation-rngintreselt-rngintreselt-2"></a>
### `- n: RngIntResElt -> RngIntResElt`

<a id="operation-op-plus-rngintreselt-rngintreselt"></a>
### `m + n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-op-minus-rngintreselt-rngintreselt"></a>
### `m - n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-op-times-rngintreselt-rngintreselt"></a>
### `m * n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-op-pow-rngintreselt-rngintreselt"></a>
### `n ^ k: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-op-div-rngintreselt-rngintreselt"></a>
### `m / n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-operation-div-rngintreselt-rngintreselt-rngintreselt"></a>
### `m div n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-operation-rngintreselt-rngintreselt-rngintreselt"></a>
### `m +:= n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-operation-rngintreselt-rngintreselt-rngintreselt-2"></a>
### `m -:= n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-operation-rngintreselt-rngintreselt-rngintreselt-3"></a>
### `m *:= n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-operation-rngintreselt-rngintreselt-rngintreselt-4"></a>
### `m /:= n: RngIntResElt, RngIntResElt -> RngIntResElt`

<a id="operation-operation-rngintreselt-rngintreselt-rngintreselt-5"></a>
### `m ^:= k: RngIntResElt, RngIntResElt -> RngIntResElt`

## Equality and Membership

<a id="operation-op-eq-rngintreselt-rngintreselt"></a>
### `m eq n: RngIntResElt, RngIntResElt -> BoolElt`

<a id="operation-op-ne-rngintreselt-rngintreselt"></a>
### `m ne n: RngIntResElt, RngIntResElt -> BoolElt`

<a id="operation-op-in-rngintreselt-rng"></a>
### `n in R: RngIntResElt, Rng -> BoolElt`

<a id="operation-op-notin-rngintreselt-rng"></a>
### `n notin R: RngIntResElt, Rng -> BoolElt`

## Parent and Category

<a id="function-parent-rngintreselt"></a>
### `Parent(n): RngIntResElt -> RngIntRes`

<a id="function-category-rngintreselt"></a>
### `Category(n): RngIntResElt -> Cat`

## Predicates on Ring Elements

<a id="function-iszero-rngintreselt"></a>
### `IsZero(n): RngIntResElt -> BoolElt`

<a id="function-isone-rngintreselt"></a>
### `IsOne(n): RngIntResElt -> BoolElt`

<a id="function-isminusone-rngintreselt"></a>
### `IsMinusOne(n): RngIntResElt -> BoolElt`

<a id="function-isnilpotent-rngintreselt"></a>
### `IsNilpotent(n): RngIntResElt -> BoolElt`

<a id="function-isidempotent-rngintreselt"></a>
### `IsIdempotent(n): RngIntResElt -> BoolElt`

<a id="function-isunit-rngintreselt"></a>
### `IsUnit(n): RngIntResElt -> BoolElt`

<a id="function-iszerodivisor-rngintreselt"></a>
### `IsZeroDivisor(n): RngIntResElt -> BoolElt`

<a id="function-isregular-rngintres"></a>
### `IsRegular(n): RngIntRes -> BoolElt`

<a id="function-isirreducible-rngintreselt"></a>
### `IsIrreducible(n): RngIntResElt -> BoolElt`

<a id="function-isprime-rngintreselt"></a>
### `IsPrime(n): RngIntResElt -> BoolElt`

<a id="solving-equations-over-mathbb-z-m-mathbb-z"></a>
## Solving Equations over ${\mathbb{Z}}/m{\mathbb{Z}}$

<a id="function-solution-rngintreselt-rngintreselt"></a>
### `Solution(a, b): RngIntResElt, RngIntResElt -> RngIntResElt`

Given elements $a$ and $b$ of ${\mathbb{Z}}/m{\mathbb{Z}}$, return a solution $x$ to the linear congruence $a\cdot x=b \in {{\mathbb{Z}}/m{\mathbb{Z}}}$. An error is signalled if no solution exists.

<a id="function-issquare-rngintreselt"></a>
### `IsSquare(n): RngIntResElt -> BoolElt, RngIntResElt`

```magma
Factorization: [<RngIntElt, RngIntElt>]                    Default: [ ]
```

Given an element $n\in{{\mathbb{Z}}/m{\mathbb{Z}}}$ this function returns `true` if there exists $a\in{{\mathbb{Z}}/m{\mathbb{Z}}}$ such that $a^2=n\in{{\mathbb{Z}}/m{\mathbb{Z}}}$, `false` otherwise. If $n$ is a square, a square root $a$ is also returned. If $m$ is large and its prime factorization is known, the computation may be speeded up by assigning the factorization sequence for $m$ to the optional argument `Factorization`.

<a id="function-sqrt-rngintreselt"></a>
### `Sqrt(a): RngIntResElt -> RngIntResElt`

<a id="function-squareroot-rngintreselt"></a>
### `SquareRoot(a): RngIntResElt -> RngIntResElt`

```magma
Factorization: [<RngIntElt, RngIntElt>]                    Default: [ ]
```

Given an element $a$ of the ring ${\mathbb{Z}}/m{\mathbb{Z}}$, this function returns an element $b$ of ${\mathbb{Z}}/m{\mathbb{Z}}$ such that $b^2=a\in{{\mathbb{Z}}/m{\mathbb{Z}}}$, if such an element exists, and an error otherwise. If $m$ is large and its prime factorization is known, the computation may be speeded up by assigning the factorization sequence for $m$ to the optional argument `Factorization`.

<a id="function-allsquareroots-rngintreselt"></a>
### `AllSquareRoots(a): RngIntResElt -> [ RngIntResElt ]`

<a id="function-allsqrts-rngintreselt"></a>
### `AllSqrts(a): RngIntResElt -> [ RngIntResElt ]`

```magma
Factorization: [<RngIntElt, RngIntElt>]                    Default: [ ]
```

Return a sequence containing all square roots of the element $a$ in a residue class ring ${\mathbb{Z}}/m{\mathbb{Z}}$. If the modulus $m$ is large and its prime factorization is known, the computation may be speeded up by assigning the factorization sequence for $m$ to the optional argument `Factorization`.

<a id="example-ex-c52d75"></a>
### `Example: Square Roots Modulo 2340 (ex-c52d75)`

We construct the residue class ring having modulus $2340$ and find all the square roots of $1404$.

```magma
> R := ResidueClassRing(2340);
Residue class ring of integers modulo 2340
> x := R!1404;
> sqrts := AllSquareRoots(x);
> sqrts;
[ 78, 312, 468, 702, 858, 1092, 1248, 1482, 1638,
  1872, 2028, 2262 ]
> [ y^2 : y in sqrts ];
[ 1404, 1404, 1404, 1404, 1404, 1404, 1404, 1404,
  1404, 1404, 1404, 1404 ]
```

So 1404 has 12 square roots!
