---
title: "Toric Codes"
canonical: "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/decode-2.html"
source: "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/decode-2.md"
part: "Coding Theory"
chapter: "Algebraic-Geometric Codes"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Coding Theory", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/index-coding-theory.md"}
  - {"title": "Algebraic-Geometric Codes", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/index-algebraic-geometric-codes.md"}
prev: {"title": "Decoding AG Codes", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/decode.md"}
next: {"title": "Bibliography", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/bibliography.md"}
intrinsics:
  - {"name": "ToricCode", "signature": "ToricCode(P, q): TorPol, RngIntElt -> Code"}
  - {"name": "ToricCode", "signature": "ToricCode(S, q): SeqEnum[TorLatElt], RngIntElt -> Code"}
  - {"name": "ToricCode", "signature": "ToricCode(S, q): SetEnum[TorLatElt], RngIntElt -> Code"}
examples:
  - "ex-deddf3"
---

# Toric Codes

<a id="function-toriccode-torpol-rngintelt"></a>
## `ToricCode(P, q): TorPol, RngIntElt -> Code`

The linear code $C$ over the finite field ${\bf F}_{q}$ associated with the lattice points of the polygon $P$.

To achieve this, after a translation so that the lattice points of $P$ lie in the first quadrant, as close to the origin as possible, these points must lie in the box $[0,q-2] \times [0,q-2]$. Then the code is the monomial evaluation code where each point $(a,b)$ corresponds to the monomial $x^ay^b$, and these monomials are evaluated at the points of the torus $({\bf F}_{q}^*)^2$.

<a id="function-toriccode-seqenum-torlatelt-rngintelt"></a>
## `ToricCode(S, q): SeqEnum[TorLatElt], RngIntElt -> Code`

<a id="function-toriccode-setenum-torlatelt-rngintelt"></a>
## `ToricCode(S, q): SetEnum[TorLatElt], RngIntElt -> Code`

The linear code $C$ over the finite field ${\bf F}_{q}$ associated with the lattice points in $S$. (Note that the points will be translated to lie within a box at the origin of the first quadrant, as is usual.)

<a id="example-ex-deddf3"></a>
## `Example: Toric Code from a Polygon (ex-deddf3)`

We construct the toric code based on the lattice points in the polygon with vertices $(3,0)$, $(5,0)$, $(3,3)$, $(1,5)$, $(0,3)$, $(0,1)$.

```magma
> P := Polytope( [[3,0], [5,0], [3,3], [1,5], [0,3], [0,1]] );
> C := ToricCode(P, 7);
> [ Length(C), Dimension(C), MinimumDistance(C) ];
[ 36, 19, 12 ]
```

We can compare this with the current database of best known linear codes.

```magma
> BKLCLowerBound(Field(C), Length(C), Dimension(C));
12
```
