---
title: "Decoding AG Codes"
canonical: "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/decode.html"
source: "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/decode.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": "Access Functions", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/access.md"}
next: {"title": "Toric Codes", "source": "https://docs.magma-maths.org/v2.30-1/CodingTheory/AlgebraicGeometricCodes/decode-2.md"}
intrinsics:
  - {"name": "AGDecode", "signature": "AGDecode(C, v, Fd): CodeLinFld, ModTupFldElt, DivCrvElt -> ModTupFldElt"}
examples:
  - "ex-a1eda2"
---

# Decoding AG Codes

Specialized decoding algorithms exist for differential code, those which are the duals of the standard algebraic-geometric codes. These algorithms generally require as input another divisor on the curve whose support is disjoint from the divisor defining the code.

<a id="function-agdecode-codelinfld-modtupfldelt-divcrvelt"></a>
## `AGDecode(C, v, Fd): CodeLinFld, ModTupFldElt, DivCrvElt -> ModTupFldElt`

Decode the received vector $v$ of the dual algebraic geometric code $C$ using the divisor $Fd$.

<a id="example-ex-a1eda2"></a>
## `Example: Decoding an Algebraic Geometric Code (ex-a1eda2)`

An algebraic-geometric code with Goppa designated distance of $3$ is used to correct one error.

```magma
> q := 8;
> F<a> := GF(q);
> PS<x,y,z> := ProjectiveSpace(F, 2);
> W := x^3*y + y^3*z + x*z^3;
> Cv := Curve(PS, W);
> FF<X,Y> := FunctionField(Cv);
> Pl := Places(Cv, 1);
> plc := Place(Cv ! [0,1,0]);
> P := [ Pl[i] : i in [1..#Pl] | Pl[i] ne plc ];
> G := 11*plc;
> C := AGDualCode(P, G);
>
> v := Random(C);
> rec_vec := v;
> rec_vec[Random(1,Length(C))] +:= Random(F);
> res := AGDecode(C, v, 4*plc);
> res eq v;
true
```
