# Imaginary hyperelliptic curve

A hyperelliptic curve is a particular kind of algebraic curve. There exist hyperelliptic curves of every genus $g\geq 1$. If the genus of a hyperelliptic curve equals 1, we simply call the curve an elliptic curve. Hence we can see hyperelliptic curves as generalizations of elliptic curves. There is a well-known group structure on the set of points lying on an elliptic curve over some field $K$, which we can describe geometrically with chords and tangents. Generalizing this group structure to the hyperelliptic case is not straightforward. We cannot define the same group law on the set of points lying on a hyperelliptic curve, instead a group structure can be defined on the so-called Jacobian of a hyperelliptic curve. The computations differ depending on the number of points at infinity. Imaginary hyperelliptic curves are hyperelliptic curves with exactly 1 point at infinity: real hyperelliptic curves have two points at infinity.

## Formal definition

Hyperelliptic curves can be defined over fields of any characteristic. Hence we consider an arbitrary field $K$ and its algebraic closure ${\overline {K}}$. An (imaginary) hyperelliptic curve of genus $g$ over $K$ is given by an equation of the form $C:y^{2}+h(x)y=f(x)\in K[x,y]$ where $h(x)\in K[x]$ is a polynomial of degree not larger than $g$ and $f(x)\in K[x]$ is a monic polynomial of degree $2g+1$. Furthermore, we require the curve to have no singular points. In our setting, this entails that no point $(x,y)\in {\overline {K}}\times {\overline {K}}$ satisfies both $y^{2}+h(x)y=f(x)$ and the equations $2y+h(x)=0$ and $h'(x)y=f'(x)$. This definition differs from the definition of a general hyperelliptic curve in the fact that $f$ can also have degree $2g+2$ in the general case. From now on we drop the adjective imaginary and simply talk about hyperelliptic curves, as is often done in literature. Note that the case $g=1$ corresponds to $f$ being a cubic polynomial, agreeing with the definition of an elliptic curve. If we view the curve as lying in the projective plane $\mathbb {P} ^{2}(K)$ with coordinates $(X:Y:Z)$, we see that there is a particular point lying on the curve, namely the point at infinity $(0:1:0)$ denoted by $O$. So we could write $C=\{(x,y)\in K^{2}|y^{2}+h(x)y=f(x)\}\cup \{O\}$.
Suppose the point $P=(a,b)$ not equal to $O$ lies on the curve and consider ${\overline {P}}=(a,-b-h(a))$. As $(-b-h(a))^{2}+h(a)(-b-h(a))$ can be simplified to $b^{2}+h(a)b$, we see that ${\overline {P}}$ is also a point on the curve. ${\overline {P}}$ is called the opposite of $P$ and $P$ is called a Weierstrass point if $P={\overline {P}}$, i.e. $h(a)=-2b$. Furthermore, the opposite of $O$ is simply defined as ${\overline {O}}=O$.

### Alternative definition

The definition of a hyperelliptic curve can be slightly simplified if we require that the characteristic of $K$ is not equal to 2. To see this we consider the change of variables $x\rightarrow x$ and $y\rightarrow y-{\frac {h(x)}{2}}$, which makes sense if char$(K)\not =2$. Under this change of variables we rewrite $y^{2}+h(x)y=f(x)$ to (y−h(x)/2 )$^2$+h(x)(y−h(x)/2 )=f(x){\textstyle \left(y-{\frac {h(x)}{2}}\right)^{2}+h(x)\left(y-{\frac {h(x)}{2}}\right)=f(x)} which, in turn, can be rewritten to $y^{2}=f(x)+{\frac {h(x)^{2}}{4}}$. As $\deg(h)\leq g$ we know that $\deg(h^{2})\leq 2g$ and hence $f(x)+{\frac {h(x)^{2}}{4}}$ is a monic polynomial of degree $2g+1$. This means that over a field $K$ with char$(K)\not =2$ every hyperelliptic curve of genus $g$ is isomorphic to one given by an equation of the form $C:y^{2}=f(x)$ where $f$ is a monic polynomial of degree $2g+1$ and the curve has no singular points. Note that for curves of this form it is easy to check whether the non-singularity criterion is met. A point $P=(a,b)$ on the curve is singular if and only if $b=0$ and $f'(a)=0$. As $b=0$ and $b^{2}=f(a)$, it must be the case that $f(a)=0$ and thus $a$ is a multiple root of $f$. We conclude that the curve $C:y^{2}=f(x)$ has no singular points if and only if $f$ has no multiple roots. Even though the definition of a hyperelliptic curve is quite easy when char$(K)\not =2$, we should not forget about fields of characteristic 2 as hyperelliptic curve cryptography makes extensive use of such fields.

## Example

As an example consider $C:y^{2}=f(x)$ where $f(x)=x^{5}-2x^{4}-7x^{3}+8x^{2}+12x=x(x+1)(x-3)(x+2)(x-2)$ over $\mathbb {R}$. As $f$ has degree 5 and the roots are all distinct, $C$ is a curve of genus $g=2$. Its graph is depicted in Figure 1.
From this picture it is immediately clear that we cannot use the chords and tangents method to define a group law on the set of points of a hyperelliptic curve. The group law on elliptic curves is based on the fact that a straight line through two points lying on an elliptic curve has a unique third intersection point with the curve. Note that this is always true since $O$ lies on the curve. From the graph of $C$ it is clear that this does not need to hold for an arbitrary hyperelliptic curve. Actually, Bézout's theorem states that a straight line and a hyperelliptic curve of genus 2 intersect in 5 points. So, a straight line through two point lying on $C$ does not have a unique third intersection point, it has three other intersection points.

## Coordinate ring

The coordinate ring of C over K is defined as
    $K[C]=K[x,y]/(y^{2}+h(x)y-f(x)).$
The polynomial $r(x,y)=y^{2}+h(x)y-f(x)$ is irreducible over ${\overline {K}}$, so
    ${\overline {K}}[C]={\overline {K}}[x,y]/(y^{2}+h(x)y-f(x))$
is an integral domain.
If r (x,y) were reducible over ${\overline {K}}$, it would factor as (y − u(x))⋅(y − v(x)) for some $u,v\in {\overline {K}}$. But then u(x)⋅v(x) = f(x) so it has degree 2g + 1, and u(x) + v(x) = h(x) so it has degree not larger than g, which is impossible.
Note that any polynomial function $G(x,y)\in {\overline {K}}[C]$ can be written uniquely as
    $G(x,y)=u(x)-v(x)y$ with $u(x),v(x)\in {\overline {K}}[x]$

## Norm and degree

The conjugate of a polynomial function G(x, y) = u(x) − v(x)y in ${\overline {K}}[C]$ is defined to be
    ${\overline {G}}(x,y)=u(x)+v(x)(h(x)+y).$
The norm of G is the polynomial function $N(G)=G{\overline {G}}$. Note that N(G) = u(x)$^2$ + u(x)v(x)h(x) − v(x)$^2$f(x), so N(G) is a polynomial in only one variable.
If G(x, y) = u(x) − v(x) ⋅ y, then the degree of G is defined as
    $\deg(G)=\max[2\deg(u),2g+1+2\deg(v)].$
Properties:
    $\deg(G)=\deg _{x}(N(G))$
    $\deg(GH)=\deg(G)+\deg(H)$
    $\deg(G)=\deg({\overline {G}})$

## Function field

The function field K(C) of C over K is the field of fractions of K[C], and the function field ${\overline {K}}(C)$ of C over ${\overline {K}}$ is the field of fractions of ${\overline {K}}[C]$. The elements of ${\overline {K}}(C)$ are called rational functions on C. For R such a rational function, and P a finite point on C, R is said to be defined at P if there exist polynomial functions G, H such that R = G/H and H(P) ≠ 0, and then the value of R at P is
    $R(P)=G(P)/H(P).$
For P a point on C that is not finite, i.e. P = $O$, we define R(P) as:
    If $\deg(G)<\deg(H)$ then $R(O)=0$, i.e. R has a zero at O.
    If $\deg(G)>\deg(H)$ then $R(O)$ is not defined, i.e. R has a pole at O.
    If $\deg(G)=\deg(H)$ then $R(O)$ is the ratio of the leading coefficients of G and H.
For $R\in {\overline {K}}(C)^{*}$ and $P\in C$,
    If $R(P)=0$ then R is said to have a zero at P,
    If R is not defined at P then R is said to have a pole at P, and we write $R(P)=\infty$.

## Order of a polynomial function at a point

For $G=u(x)-v(x)\cdot y\in {\overline {K}}[C]^{2}$ and $P\in C$, the order of G at P is defined as:
    $\mathrm {ord} _{P}(G)=r+s$ if P = (a,b) is a finite point which is not Weierstrass. Here r is the highest power of (x − a) which divides both u(x) and v(x). Write G(x,y) = (x − a)$^r$(u$_0$(x) − v$_0$(x)y) and if u$_0$(a) − v$_0$(a)b = 0, then s is the highest power of (x − a) which divides N(u$_0$(x) − v$_0$(x)y) = u$_0$$^2$ + u$_0$v$_0$h − v$_0$$^2$f, otherwise, s = 0.
    $\mathrm {ord} _{P}(G)=2r+s$ if P = (a,b) is a finite Weierstrass point, with r and s as above.
    $\mathrm {ord} _{P}(G)=-\deg(G)$ if P = O.

## The divisor and the Jacobian

In order to define the Jacobian, we first need the notion of a divisor. Consider a hyperelliptic curve $C$ over some field $K$. Then we define a divisor $D$ to be a formal sum of points in $C$, i.e. D=∑$_{P∈C}$c$_P$[P]{\textstyle D=\sum _{P\in C}{c_{P}[P]}} where $c_{P}\in \mathbb {Z}$ and furthermore $\{c_{P}\mid c_{P}\neq 0\}$ is a finite set. This means that a divisor is a finite formal sum of scalar multiples of points. Note that there is no simplification of $c_{P}[P]$ given by a single point (as one might expect from the analogy with elliptic curves). Furthermore, we define the degree of $D$ as deg⁡(D)=∑$_{P∈C}$c$_P$∈Z{\textstyle \deg(D)=\sum _{P\in C}{c_{P}}\in \mathbb {Z} }. The set of all divisors $\mathrm {Div} (C)$ of the curve $C$ forms an Abelian group where the addition is defined pointwise as follows ∑$_{P∈C}$c$_P$[P]+∑$_{P∈C}$d$_P$[P]=∑$_{P∈C}$(c$_P$+d$_P$)[P]{\textstyle \sum _{P\in C}{c_{P}[P]}+\sum _{P\in C}{d_{P}[P]}=\sum _{P\in C}{(c_{P}+d_{P})[P]}}. It is easy to see that 0=∑$_{P∈C}$0[P]{\textstyle 0=\sum _{P\in C}{0[P]}} acts as the identity element and that the inverse of ∑$_{P∈C}$c$_P$[P]{\textstyle \sum _{P\in C}{c_{P}[P]}} equals ∑$_{P∈C}$−c$_P$[P]{\textstyle \sum _{P\in C}{-c_{P}[P]}}. The set $\mathrm {Div} ^{0}(C)=\{D\in \mathrm {Div} (C)\mid \deg(D)=0\}$ of all divisors of degree 0 can easily be checked to be a subgroup of $\mathrm {Div} (C)$.
Proof. Consider the map $\varphi :\mathrm {Div} (C)\rightarrow \mathbb {Z}$ defined by $\varphi (D)=\deg(D)$, note that $\mathbb {Z}$ forms a group under the usual addition. Then φ(∑$_{P∈C}$c$_P$[P]+∑$_{P∈C}$d$_P$[P])=φ(∑$_{P∈C}$(c$_P$+d$_P$)[P])=∑$_{P∈C}$c$_P$+d$_P$=∑$_{P∈C}$c$_p$+∑$_{P∈C}$d$_p$=φ(∑$_{P∈C}$c$_P$[P])+φ(∑$_{P∈C}$d$_P$[P]){\textstyle \varphi (\sum _{P\in C}{c_{P}[P]}+\sum _{P\in C}{d_{P}[P]})=\varphi (\sum _{P\in C}{(c_{P}+d_{P})[P]})=\sum _{P\in C}{c_{P}+d_{P}}=\sum _{P\in C}{c_{p}}+\sum _{P\in C}{d_{p}}=\varphi (\sum _{P\in C}{c_{P}[P]})+\varphi (\sum _{P\in C}{d_{P}[P]})} and hence $\varphi$ is a group homomorphism. Now, $\mathrm {Div} ^{0}(C)$ is the kernel of this homomorphism and thus it is a subgroup of $\mathrm {Div} (C)$.
Consider a function $f\in {\overline {K}}(C)^{*}$, then we can look at the formal sum div (f)=∑$_{P∈C}$ord$_P$(f)[P]{\textstyle (f)=\sum _{P\in C}{\mathrm {ord} _{P}(f)[P]}}. Here $\mathrm {ord} _{P}(f)$ denotes the order of $f$ at $P$. We have that ord$_{P}(f)<0$ if $f$ has a pole of order $-\mathrm {ord} _{P}(f)$ at $P$, $\mathrm {ord} _{P}(f)=0$ if $f$ is defined and non-zero at $P$ and $\mathrm {ord} _{P}(f)>0$ if $f$ has a zero of order $\mathrm {ord} _{P}(f)$ at $P$. It can be shown that $f$ has only a finite number of zeroes and poles, and thus only finitely many of the ord$_{P}(f)$ are non-zero. This implies that div$(f)$ is a divisor. Moreover, as ∑$_{P∈C}$ord$_P$(f)=0{\textstyle \sum _{P\in C}{\mathrm {ord} _{P}(f)}=0}, it is the case that $\operatorname {div} (f)$ is a divisor of degree 0. Such divisors, i.e. divisors coming from some rational function $f$, are called principal divisors and the set of all principal divisors $\mathrm {Princ} (C)$ is a subgroup of $\mathrm {Div} ^{0}(C)$.
Proof. The identity element 0=∑$_{P∈C}$0[P]{\textstyle 0=\sum _{P\in C}{0[P]}} comes from a constant function which is non-zero. Suppose D$_1$=∑$_{P∈C}$ord$_P$(f)[P], D$_2$=∑$_{P∈C}$ord$_P$(g)[P]∈Princ(C){\textstyle D_{1}=\sum _{P\in C}{\mathrm {ord} _{P}(f)[P]}, D_{2}=\sum _{P\in C}{\mathrm {ord} _{P}(g)[P]}\in \mathrm {Princ} (C)} are two principal divisors coming from $f$ and $g$ respectively. Then D$_1$−D$_2$=∑$_{P∈C}$(ord$_P$(f)−ord$_P$(g))[P]{\textstyle D_{1}-D_{2}=\sum _{P\in C}{(\mathrm {ord} _{P}(f)-\mathrm {ord} _{P}(g))[P]}} comes from the function $f/g$, and thus $D_{1}-D_{2}$ is a principal divisor, too. We conclude that $\mathrm {Princ} (C)$ is closed under addition and inverses, making it into a subgroup.
We can now define the quotient group $J(C):=\mathrm {Div} ^{0}(C)/\mathrm {Princ} (C)$ which is called the Jacobian or the Picard group of $C$. Two divisors $D_{1},D_{2}\in \mathrm {Div} ^{0}(C)$ are called equivalent if they belong to the same element of $J(C)$, this is the case if and only if $D_{1}-D_{2}$ is a principal divisor. Consider for example a hyperelliptic curve $C:y^{2}+h(x)y=f(x)$ over a field $K$ and a point $P=(a,b)$ on $C$. For $n\in \mathbb {Z} _{>0}$ the rational function $f(x)=(x-a)^{n}$ has a zero of order $n$ at both $P$ and ${\overline {P}}$ and it has a pole of order $2n$ at $O$. Therefore, we find $\operatorname {div} (f)=nP+n{\overline {P}}-2nO$ and we can simplify this to $\operatorname {div} (f)=2nP-2nO$ if $P$ is a Weierstrass point.

### Example: the Jacobian of an elliptic curve

For elliptic curves the Jacobian turns out to simply be isomorphic to the usual group on the set of points on this curve, this is basically a corollary of the Abel-Jacobi theorem. To see this consider an elliptic curve $E$ over a field $K$. The first step is to relate a divisor $D$ to every point $P$ on the curve. To a point $P$ on $E$ we associate the divisor $D_{P}=1[P]-1[O]$, in particular $O$ in linked to the identity element $O-O=0$. In a straightforward fashion we can now relate an element of $J(E)$ to each point $P$ by linking $P$ to the class of $D_{P}$, denoted by $[D_{P}]$. Then the map $\varphi :E\to J(E)$ from the group of points on $E$ to the Jacobian of $E$ defined by $\varphi (P)=[D_{P}]$ is a group homomorphism. This can be shown by looking at three points on $E$ adding up to $O$, i.e. we take $P,Q,R\in E$ with $P+Q+R=O$ or $P+Q=-R$. We now relate the addition law on the Jacobian to the geometric group law on elliptic curves. Adding $P$ and $Q$ geometrically means drawing a straight line through $P$ and $Q$, this line intersects the curve in one other point. We then define $P+Q$ as the opposite of this point. Hence in the case $P+Q+R=O$ we have that these three points are collinear, thus there is some linear $f\in K[x,y]$ such that $P$, $Q$ and $R$ satisfy $f(x,y)=0$. Now, $\varphi (P)+\varphi (Q)+\varphi (R)=[D_{P}]+[D_{Q}]+[D_{R}]=[[P]+[Q]+[R]-3[O]]$ which is the identity element of $J(E)$ as $[P]+[Q]+[R]-3[O]$ is the divisor on the rational function $f$ and thus it is a principal divisor. We conclude that $\varphi (P)+\varphi (Q)+\varphi (R)=\varphi (O)=\varphi (P+Q+R)$.
The Abel-Jacobi theorem states that a divisor D=∑$_{P∈E}$c$_P$[P]{\textstyle D=\sum _{P\in E}{c_{P}[P]}} is principal if and only if $D$ has degree 0 and ∑$_{P∈E}$c$_P$P=O{\textstyle \sum _{P\in E}{c_{P}P}=O} under the usual addition law for points on cubic curves. As two divisors $D_{1},D_{2}\in \mathrm {Div} ^{0}(E)$ are equivalent if and only if $D_{1}-D_{2}$ is principal, we conclude that D$_1$=∑$_{P∈E}$c$_P$[P]{\textstyle D_{1}=\sum _{P\in E}{c_{P}[P]}} and D$_2$=∑$_{P∈E}$d$_P$[P]{\textstyle D_{2}=\sum _{P\in E}{d_{P}[P]}} are equivalent if and only if ∑$_{P∈E}$c$_P$P=∑$_{P∈E}$d$_P$P{\textstyle \sum _{P\in E}{c_{P}P}=\sum _{P\in E}{d_{P}P}}. Now, every nontrivial divisor of degree 0 is equivalent to a divisor of the form $[P]-[O]$, this implies that we have found a way to ascribe a point on $E$ to every class $[D_{P}]$. Namely, to $[D_{P}]=[1[P]-1[O]]$ we ascribe the point $(P-O)+O=P$. This maps extends to the neutral element 0 which is maped to $0+O=O$. As such the map $\psi :J(E)\rightarrow E$ defined by $\psi ([D_{P}])=P$ is the inverse of $\varphi$. So $\varphi$ is in fact a group isomorphism, proving that $E$ and $J(E)$ are isomorphic.

## The Jacobian of a hyperelliptic curve

The general hyperelliptic case is a bit more complicated. Consider a hyperelliptic curve $C:y^{2}+h(x)y=f(x)$ of genus $g$ over a field $K$. A divisor $D$ of $C$ is called reduced if it has the form D=∑$_{i=1}$$^k$[P$_i$]−k[O]{\textstyle D=\sum _{i=1}^{k}{[P_{i}]}-k[O]} where $k\leq g$, $P_{i}\not =O$ for all $i=1,\dots ,k$ and $P_{i}\not ={\overline {P_{j}}}$ for $i\not =j$. Note that a reduced divisor always has degree 0, also it is possible that $P_{i}=P_{j}$ if $i\not =j$, but only if $P_{i}$ is not a Weierstrass point. It can be proven that for each divisor $D\in \mathrm {Div} ^{0}(C)$ there is a unique reduced divisor $D'$ such that $D$ is equivalent to $D'$. Hence every class of the quotient group $J(C)$ has precisely one reduced divisor. Instead of looking at $J(C)$ we can thus look at the set of all reduced divisors.

### Reduced divisors and their Mumford representation

A convenient way to look at reduced divisors is via their Mumford representation. A divisor in this representation consists of a pair of polynomials $u,v\in K[x]$ such that $u$ is monic, $\deg(v)<\deg(u)\leq g$ and $u|v^{2}+vh-f$. Every non-trivial reduced divisor can be represented by a unique pair of such polynomials. This can be seen by factoring u(x)=∏$_{i=1}$$^k$(x−x$_i$){\textstyle u(x)=\prod _{i=1}^{k}{(x-x_{i})}} in ${\overline {K}}$ which can be done as such as $u$ is monic. The last condition on $u$ and $v$ then implies that the point $P_{i}=(x_{i},v(x_{i}))$ lies on $C$ for every $i=1,...,k$. Thus D=∑$_{i=1}$$^k$[P$_i$]−k[O]{\textstyle D=\sum _{i=1}^{k}{[P_{i}]}-k[O]} is a divisor and in fact it can be shown to be a reduced divisor. For example, the condition $\deg(u)\leq g$ ensures that $k\leq g$. This gives the 1-1 correspondence between reduced divisors and divisors in Mumford representation. As an example, 0=∑$_{P∈C}$0[P]{\textstyle 0=\sum _{P\in C}{0[P]}} is the unique reduced divisor belonging to the identity element of $J(C)$. Its Mumford representation is $u(x)=1$ and $v(x)=0$. Going back and forth between reduced divisors and their Mumford representation is now an easy task. For example, consider the hyperelliptic curve $C:y^{2}=x^{5}-4x^{4}-14x^{3}+36x^{2}+45x=x(x+1)(x-3)(x+3)(x-5)$ of genus 2 over the real numbers. We can find the following points on the curve $P=(1,8)$, $Q=(3,0)$ and $R=(5,0)$. Then we can define reduced divisors $D=[P]+[Q]-2[O]$ and $D'=[P]+[R]-2[O]$. The Mumford representation of $D$ consists of polynomials $u$ and $v$ with $\deg(v)<\deg(u)\leq g=2$ and we know that the first coordinates of $P$ and $Q$, i.e. 1 and 3, must be zeroes of $u$. Hence we have $u(x)=(x-1)(x-3)=x^{2}-4x+3$. As $P=(1,v(1))$ and $Q=(3,v(3))$ it must be the case that $v(1)=8$ and $v(3)=0$ and thus $v$ has degree 1. There is exactly one polynomial of degree 1 with these properties, namely $v(x)=-4x+12$. Thus the Mumford representation of $D$ is $u(x)=x^{2}-4x+3$ and $v(x)=-4x+12$. In a similar fashion we can find the Mumford representation $(u',v')$ of $D'$, we have $u'(x)=(x-1)(x-5)=x^{2}-6x+5$ and $v(x)=-2x+10$. If a point $P_{i}=(x_{i},y_{i})$ appears with multiplicity n, the polynomial v needs to satisfy (d/dx)$^j$[v(x)$^2$+v(x)h(x)−f(x)]|$_{x=xi}$=0{\textstyle \left.\left({\frac {d}{dx}}\right)^{j}\left[v(x)^{2}+v(x)h(x)-f(x)\right]\right|_{x=x_{i}}=0} for $0\leq j\leq n_{i}-1$.

### Cantor's algorithm

There is an algorithm which takes two reduced divisors $D_{1}$ and $D_{2}$ in their Mumford representation and produces the unique reduced divisor $D$, again in its Mumford representation, such that $D$ is equivalent to $D_{1}+D_{2}$. As every element of the Jacobian can be represented by the one reduced divisor it contains, the algorithm allows to perform the group operation on these reduced divisors given in their Mumford representation. The algorithm was originally developed by David G. Cantor (not to be confused with Georg Cantor), explaining the name of the algorithm. Cantor only looked at the case $h(x)=0$, the general case is due to Koblitz. The input is two reduced divisors $D_{1}=(u_{1},v_{1})$ and $D_{2}=(u_{2},v_{2})$ in their Mumford representation of the hyperelliptic curve $C:y^{2}+h(x)y=f(x)$ of genus $g$ over the field $K$. The algorithm works as follows
* Using the extended Euclidean algorithm compute the polynomials $d_{1},e_{1},e_{2}\in K[x]$ such that $d_{1}=\gcd(u_{1},u_{2})$ and $d_{1}=e_{1}u_{1}+e_{2}u_{2}$.
* Again with the use of the extended Euclidean algorithm compute the polynomials $d,c_{1},c_{2}\in K[x]$ with $d=\gcd(d_{1},v_{1}+v_{2}+h)$ and $d=c_{1}d_{1}+c_{2}(v_{1}+v_{2}+h)$.
* Put $s_{1}=c_{1}e_{1}$, $s_{2}=c_{1}e_{2}$ and $s_{3}=c_{2}$, which gives $d=s_{1}u_{1}+s_{2}u_{2}+s_{3}(v_{1}+v_{2}+h)$.
* Set $u={\frac {u_{1}u_{2}}{d^{2}}}$ and $v={\frac {s_{1}u_{1}v_{2}+s_{2}u_{2}v_{1}+s_{3}(v_{1}v_{2}+f)}{d}}\mod u$.
* Set $u'={\frac {f-vh-v^{2}}{u}}$ and $v'=-h-v\mod u'$.
* If $\deg(u')>g$, then set $u=u'$ and $v=v'$ and repeat step 5 until $\deg(u')\leq g$.
* Make $u'$ monic by dividing through its leading coefficient.
* Output $D=(u',v')$.
The proof that the algorithm is correct can be found in.

#### Example

As an example consider the curve
    $C:y^{2}=x^{5}-4x^{4}-14x^{3}+36x^{2}+45x=x(x+1)(x-3)(x+3)(x-5)$
of genus 2 over the real numbers. For the points
    $P=(1,8)$, $Q=(3,0)$ and $R=(5,0)$
and the reduced divisors
    $D_{1}=[P]+[Q]-2[O]$ and $D_{2}=[P]+[R]-2[O]$
we know that
    $(u_{1}=x^{2}-4x+3,v_{1}=-4x+12)$, and
    $(u_{2}=x^{2}-6x+5,v_{2}=-2x+10)$
are the Mumford representations of $D_{1}$ and $D_{2}$ respectively.
We can compute their sum using Cantor's algorithm. We begin by computing
    $d_{1}=\gcd(u_{1},u_{2})=x-1$, and
    $d_{1}=e_{1}u_{1}+e_{2}u_{2}$
for $e_{1}={\frac {1}{2}}$, and $e_{2}=-{\frac {1}{2}}$.
In the second step we find
    $d=\gcd(d_{1},v_{1}+v_{2}+h)=\gcd(x-1,-6x+22)=1$ and
    $1=c_{1}d_{1}+c_{2}(v_{1}+v_{2}+h)$
for $c_{1}={\frac {3}{8}}$ and $c_{2}={\frac {1}{16}}$.
Now we can compute
    $s_{1}=c_{1}e_{1}={\frac {3}{16}}$,
    $s_{2}=c_{1}e_{2}=-{\frac {3}{16}}$ and
    $s_{3}=c_{2}={\frac {1}{16}}$.
So
    $u={\frac {u_{1}u_{2}}{d^{2}}}=u_{1}u_{2}=x^{4}-10x^{3}+32x^{2}-38x+15$ and
    ${\begin{aligned}v&={\frac {s_{1}u_{1}v_{2}+s_{2}u_{2}v_{1}+s_{3}(v_{1}v_{2}+f)}{d}}\mod u\\&={\frac {1}{16}}(x^{5}-4x^{4}-8x^{3}-10x^{2}+119x+30)\mod u\\&={\frac {1}{4}}(5x^{3}-41x^{2}+83x-15).\end{aligned}}$
Lastly we find
    $u'={\frac {f-v^{2}}{u}}={\frac {1}{16}}(-25x^{2}+176x-15)$ and
    $v'=-v\mod u'=-{\frac {72}{125}}(17x-5)$.
After making $u'$ monic we conclude that
    $D=(-25x^{2}+176x-15,-{\frac {72}{125}}(17x-5))$
is equivalent to $D_{1}+D_{2}$.

#### More on Cantor's algorithm

Cantor's algorithm as presented here has a general form, it holds for hyperelliptic curves of any genus and over any field. However, the algorithm is not very efficient. For example, it requires the use of the extended Euclidean algorithm. If we fix the genus of the curve or the characteristic of the field (or both), we can make the algorithm more efficient. For some special cases we even get explicit addition and doubling formulas which are very fast. For example, there are explicit formulas for hyperelliptic curves of genus 2
and genus 3.
For hyperelliptic curves it is also fairly easy to visualize the adding of two reduced divisors. Suppose we have a hyperelliptic curve of genus 2 over the real numbers of the form
    $C:y^{2}=f(x)$
and two reduced divisors
    $D_{1}=[P]+[Q]-2[O]$ and
    $D_{2}=[R]+[S]-2[O]$.
Assume that
    $P,Q\not ={\overline {R}},{\overline {S}}$,
this case has to be treated separately. There is exactly 1 cubic polynomial
    $a(x)=a_{0}x^{3}+a_{1}x^{2}+a_{2}x+a_{3}$
going through the four points
    $P,Q,R,S$.
Note here that it could be possible that for example $P=Q$, hence we must take multiplicities into account. Putting $y=a(x)$ we find that
    $y^{2}=f(x)=a^{2}(x)$
and hence
    $f(x)-a^{2}(x)=0$.
As $f(x)-a^{2}(x)$ is a polynomial of degree 6, we have that $f(x)-a^{2}(x)$ has six zeroes and hence $a(x)$ has besides $P,Q,R,S$ two more intersection points with $C$, call them $T$ and $U$, with $T\not ={\overline {U}}$. Now, $P,Q,R,S,T,U$ are intersection points of $C$ with an algebraic curve. As such we know that the divisor
    $D=[P]+[Q]+[R]+[S]+[T]+[U]-6[O]$
is principal which implies that the divisor
    $[P]+[Q]+[R]+[S]-4[O]$
is equivalent to the divisor
    $-([T]+[U]-2[O])$.
Furthermore, the divisor
    $[P]+[{\overline {P}}]-2[O]$
is principal for every point $P=(a,b)$ on $C$ as it comes from the rational function $b(x)=x-a$. This gives that $-([P]-[O])$ and $[{\overline {P}}]-[O]$ are equivalent. Combining these two properties we conclude that
    $D_{1}+D_{2}=([P]+[Q]-2[O])+([R]+[S]-2[O])$
is equivalent to the reduced divisor
    $[{\overline {T}}]+[{\overline {U}}]-2[O]$.
In a picture this looks like Figure 2. It is possible to explicitly compute the coefficients of $a(x)$, in this way we can arrive at explicit formulas for adding two reduced divisors.