%15th draft
\documentclass{amsart} %{llncs}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsgen}
\usepackage{amsfonts}
\usepackage{amscd}
\usepackage{hyperref}
%\usepackage{makeidx}  % allows for index generation
\usepackage{url}
\usepackage{xspace}

\usepackage{fancyvrb}
%\usepackage{moreverb}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{axiom}{Axiom}
\newtheorem{remark}{Remark}

\newcommand{\comment}[1]{}
\numberwithin{equation}{section}

\def\ppp{{\mathbb{P}}}
\def\aaa{{\mathbb{A}}}
\def\fff{{\mathbb{F}}}
\def\qqq{\mathbb{Q}}
\def\rrr{\mathbb{R}}
\def\ccc{\mathbb{C}}
\def\zzz{\mathbb{Z}}
\def\nnn{\mathbb{N}}
\def\Aut{{\rm{Aut}}}
\def\supp{{\rm{Supp}}}
\def\Stab{{\rm{Stab}}}
\def\ddiv{{\rm{div}}}
\def\Div{{\rm{Div}}}
\def\eval{{\rm{eval}}}
\def\wt{{\rm{wt}}}
\def\pf{\noindent {\bf Proof}:\ }

\def\X{C}
\def\Aut{\mbox{Aut} }
\def\C{\mathbb C}
\def\a{\alpha}
\def\<{\langle}
\def\>{\rangle}
\def\e{\xi}

\newcommand{\SAGE}{{\sf SAGE}\,}
\newcommand{\sage}{\SAGE}

\begin{document}

\title{Bases for Riemann-Roch spaces of cyclic curves}

\author{D. Joyner}


\address{Mathematics Department, United States Naval Academy, Annapolis, MD 21402}


\email{wdj@usna.edu}

\author{A. Ksir}

\address{Mathematics Department, United States Naval Academy, Annapolis, MD 21402}

\email{ksir@usna.edu}

\author{T. Shaska}

\address{546 Science and Engineering  Building, Department of Mathematics, 
Oakland University, Rochester,
MI, 48309}

\email{shaska@oakland.edu}

\begin{abstract}
Let $C$ denote an algebraic curve with equation $y^n=f(x)$ and  $D$  
an effective divisor on $C$. We give an
explicit constructive method for computing a basis $B$ of $L(D)$. 
In particular, it is done in such a way
that if $E<D$ is another effective divisor, the basis $B_E$ of $L(E)$ 
so constructed will be a subset of $B$.
We plan to use this in future work to compute quotient representations, 
with applications to AG codes.  We
use \SAGE to compute an example in some detail for a hyperelliptic curve.

\end{abstract}

\maketitle

In this paper\footnote{This paper
is licensed under the
Attribution-ShareAlike Creative Commons license,
\url{http://creativecommons.org/about/licenses/meet-the-licenses}.},
 we give a simple procedure for computing bases of Riemann-Roch 
spaces of divisors on cyclic
curves, which we call the ``pivot method''.  The method does not depend on 
the size of the genus of the
curve, and strongly resembles the Gauss elimination method for matrices. 
Though it is probably known to
experts, the formulation we present does not seem to have appeared explicitly 
in the literature.  It seems to
be a very specific version of Coates' algorithm (see Coates \cite{C}, 
Davenport \cite{D}, and Berry
\cite{B1}). Also, there are strong similarities to ideas discussed in 
\S 3 of Berry \cite{B2}, though our
calculations allow a more general class of divisors. 
%This works generalizes previous work of the first two
%authors on hyperelliptic curves.


A cyclic curve is an algebraic curve $\X$ such that there exist a normal 
cyclic subgroup $C_m \triangleleft
\,\Aut(\X)$ such that $g( \X / {C_m}) = 0.$  An equation of such curve 
can be given by $y^n = f(x)$. In the
first section, we give a brief introduction to normal cyclic curves 
and describe  a simple algorithm to
construct functions with prescribed poles on such curves. This generalizes 
previous work of the first two
authors for hyperelliptic curves.

In the second section we use this construction to compute bases for 
Riemann-Roch spaces on cyclic curves. In
particular, for effective divisors $D$ and $E$ with $E<D$, we compute 
bases $B_1$ of $L(E)$ and $B_2$ of
$L(D)$ such that $B_1 \subset B_2$.

The third section discusses the implementation of such algorithm 
in \SAGE. Furthermore, it contains two
examples for hyperelliptic curves: one general example on an 
interesting curve, and one more specific example
where the calculations are partially done using \SAGE \cite{S}. 
The algorithm described here is included in
the file {\tt rrbasis3.sage} 
(implemented by the first author \cite{J}), in the case of hyperelliptic 
curves where
the divisors are effective and the support of $D$ does not 
contain any points fixed by the hyperelliptic
involution. We intend to implement the full version of the algorithm in \SAGE.

\medskip

\noindent \textbf{Notation:} Throughout this paper $C$ denotes a 
cyclic curve defined over a field $k$ of
characteristic not equal to $2$. $\Aut (C)$ denotes the group of 
automorphisms defined over the algebraic
closure of $k$.


\section{General background}
This section  both defines notation and recalls well-known facts about 
cyclic curves.

A cyclic curve is an algebraic curve $\X$ such that there exist a 
normal cyclic subgroup $C_m \triangleleft
\,\Aut(\X)$ such that $g( \X / {C_m}) = 0.$  Then $\bar{G} = G/ C_m$ 
embeds as a finite subgroup of
$PGL(2,\C).$ The equation of cyclic curve can be given by the following
%
\begin{equation}\label{cyclic}
y^m = h(x) = \prod_{i=1}^s (x-\a_i)^{d_i} , 0<d_i <m.
\end{equation}

Specifically, let $C$ be a smooth curve defined in affine coordinates by 
$y^m=h(x)$, where $h(x)$ is a
polynomial of degree $d>3$. Then the discriminant of $h(x)$ is non-zero. 
We denote by $n$ be the projective
degree of the curve.

Let $\iota:C\rightarrow C$ denote the order $m$ normal automorphism 
such that $C_m = \< \iota \>$, sending a
point $P=(x,y)\in C$ to $\iota(P)=P^*=(x, \e_m y)$, where $\e_m$ is 
the $m$-th primitive root of unity. Let
$\rho:C\rightarrow \ppp^1= C / C^\iota$ denote the projection defined 
in affine coordinates by
$(x,y)\longmapsto x$, so $\rho^{-1}(\rho(P))=\{P,\iota(P)\}$. 
A point $P$ on $C$ is ramified with respect to
$\rho$ if and only if it is a fixed point of $\iota$.

When we say ``ramification point'', we always mean ramification point 
with respect to $\rho$, and when we say
a point is ``unramified'', we always mean that it is not a ramification 
point with respect to $\rho$.


%%%%%%%% ketu

If $h(x)$ has odd degree, then there is one ramified point at infinity, 
which we label $P_0$; if $h(x)$ has
even degree then there are two unramified points at infinity, which we 
label $P_0$ and $P_0^*$. For
simplicity of notation, let $P_0^*=P_0$ in the odd degree case.

The following result summarizes some of what is known about the function 
field $F(C)$ and the affine
coordinate ring $F[C]=F[x,y]/(y^m-h(x))$.

\begin{proposition}
\begin{itemize}
\item[(a)]
$F[C]$ is finitely generated as an $F[x]$-module and is integral 
over $F[x]$. Moreover, as an $F$-vector
space

\[
F(C) = F(x)\oplus y F(x).
\]

\item[(b)]
$F[C]$ is finitely generated as an $F[y]$-module and is integral over 
$F[y]$. Moreover, as an $F$-vector
space

\[
F(C) = F(y)\oplus x F(y)\oplus \dots \oplus x^{d-1} F(y).
\]
\item[(c)]
If $d$ is odd, the pole $x_0$ of $y \in F(y)$ has a unique extension $P_0$ to a totally ramified place of
degree 1 of $C$ with ramification index $e(P_0/x_0)=d$. Moreover,

\[
\ddiv_\infty(x)=2P_0,\ \ \ \ \ddiv_{P_0}(y)=dP_0.
\]

\item[(d)]
If $d$ is even, the pole $x_0$ of $y \in F(y)$ has two extensions 
$P_0,P_0^*$ to unramified places of degree
1 of $C$ with ramification indices $e(P_0^*/x_0)=e(P_0/x_0)=d/2$. 
Moreover,

\[
\ddiv_{\infty}(x)=P_0+P_0^*,\ \ \ \ \ddiv_{\infty}(y)=(d/2)P_0+(d/2)P_0^* .
\]

\item[(e)]
If $d$ is odd,

\[
L(rP_0)=Span\{x^iy^j\ |\ 2i+dj\leq r,\ 0\geq i,\ 0\geq j\geq d-1\}.
\]

\end{itemize}
\end{proposition}

\section{Functions with prescribed poles on cyclic curves }\label{sec:poles}

We use the notation of the previous section.
 Let ${\mathcal P}=\{x_0,x_1,...,x_r,x_{r+1},...,x_{r+s}\}\subset
\ppp^1$ denote a finite set, where $x_{r+1},...,x_{r+s}$ are branch 
points of $\rho$, $x_{1},...,x_{r}$ are
not branch points, and $x_0=\infty\in \ppp^1$. For each 
$p\in \rho^{-1}({\mathcal P})$, let $e_p\geq 0$ be an
integer. Let $D$ be the effective divisor on $C$ defined by

\begin{equation*}
D = \sum_{x\in {\mathcal P}} \sum_{p\in \rho^{-1}(x)} e_p\cdot p.
\end{equation*}
If $x = x_i\in {\mathcal P}$ and if $\rho^{-1}(x)$ contains two points, let $e_i^*= \min_{p \in
\rho^{-1}(x)}e_p$ and let $e_i= \max_{p \in \rho^{-1}(x)}e_p$. If $\rho^{-1}(x_i)=\{p\}$ is a singleton, let
$e_i^*=0$ and $e_i=e_p$. In this case, we have

\begin{equation*}
\begin{array}{c}
D= e_0P_0+e_1P_1...+e_{r}P_{r}
\ +e^*_0P^*_0\, +e_1^*P_1^*...+e^*_{r}P^*_{r}\\
\ \ \ +e_{r+1}P_{r+1}+ ...+e_{r+s}P_{r+s}
\end{array}
\end{equation*}
where $P_1, \ldots, P_r$ are finite unramified points, $e_i \geq e_i^*$ 
for $i = 0, \ldots r$, and $P_{r+1} ,
\ldots P_{r+s}$ are finite ramified points.  (Recall $e_0^*=0$ if $d$ 
is odd.) Let $(x_i, y_i)$ be the
coordinates of $P_i$, $1 \leq i \leq r$. Note if $1 \leq i \leq r$ 
then $(x_i, -y_i)$ are the coordinates of
$P_i^*$, and if $i > r$ then $y_i=0$.

\begin{proposition}
\label{prop:main} Let $C$ be as above. Let $D$ be an effective 
divisor on $C$ as above with the following
properties:
\begin{enumerate}
\item  $y_1, \ldots, y_r$ are all distinct
\item  $e_i \geq e_i^*$ for $i = 0, \ldots r$
\item  $e_1 + \ldots + e_r \geq d/2$
\item  $e_{r+1}, \ldots, e_{r+s}$, and $e_0$ if $d$ is odd, are 
either all even or all odd.
\end{enumerate}

Then there is a function $g$ with polar divisor $D$ which is a 
linear combination of functions of the form:

(a) $\frac{y}{\prod_{i=0}^{s-1}(x-x_i)^{e_i} } $,

(b) $\frac{1}{(x-x_i)^{m} }$ ($0<m\leq e_i$),

(c) the monomial functions $x^iy^j$ ($i\geq 0$, $j=0,1$),

(d) the ``mixed'' functions $\frac{yx^a}{\prod_{i=0}^{s-1}(x-x_i)^{d_i} }$ ($d_i<e_i$).
\end{proposition}



\begin{remark}
\begin{itemize}

\item[(a)]
If $P=(a,b)$ is an affine ramification point for $\rho$ then

\subitem (i) $b=0$ and $a$ is a root of $h$,

\subitem (ii) $1/(x-a)$ has a pole of order $2$ at $P$.

If $P=(a,b)$ is an unramified affine point for $\rho$ then

\subitem  (i) $b\not= 0$ and $a$ is not a root of $h$,

\subitem  (ii) $1/(x-a)$ has a pole of order $1$ at $P$ and a pole 
of order $1$ at $P^*$.

\item[(b)]
When $d$ is even, $C$ embeds into projective space using the 
$(1,g+1,1)$-weighted projective model with
coordinates $(X,Y,Z)$ and equation
%
\[
Y^2=h(X/Z)Z^d,
\]
where $x=X/Z$, $y=Y/Z^{d/2}$. Assume $h(x)$ is monic. 
Let $\infty_+=[1:1:0]$ and $\infty_-=[1:-1:0]$ denote
the two points at infinity. The coordinate $x$ has a pole of order 
$1$ at $\infty_+$ and $\infty_-$; $y$ has
a pole of order $d/2$ at each of these points. In particular,
%
\[
g_+(x,y)=\frac{y-x^{d/2}}{x^{d/2}}
\]
has a zero of order $1$ at $\infty_+$ and
%
\[
g_-(x,y)=\frac{y+x^{d/2}}{x^{d/2}}
\]
has a zero of order $1$ at $\infty_-$.

\item[(c)]
When $d$ is odd, $C$ has equation

\[
Y^2=h(X/Z)Z^{d+1},
\]
where $x=X/Z$, $y=Y/Z^{\frac{d+1}{2}}$. In this case,
%
\[
g(x,y)=\frac{y}{x^{\frac{d+1}{2}}},
\]
has a zero of order $1$ at $\infty$. Let $\infty =[1:0:0]$ denote 
the point at infinity. At $\infty$, $x$ has
a pole of order $2$ and $y$ has a pole of order~$d$.

\item[(d)] If $d$ is odd, the ramification divisor $R$ has degree 
$d+1$ (it is the effective divisor given by the sum of
the point at infinity plus all the affine points $(x,y)=(\alpha,0)$, 
where $\alpha$ denotes a root of
$h(x)=0$). In this case, the canonical divisor has degree $d-3$.

\item[(e)] If $d$ is even, the ramification divisor $R$ has degree $d$ 
(it is the same as in the odd case above, but
without the point at infinity). In this case, the canonical divisor 
has degree $d-4$.

\end{itemize}

\end{remark}


\pf Properties (1) and (3) ensure that for any point $P$, 
$\dim L(D-P) = \dim L(D) - 1$, so there is a
function with polar divisor $D$. We will construct such a function 
out of the types of functions mentioned in
the statement of the theorem. Our method is reminiscent of row reduction for matrices.

First we consider some special cases.

\begin{itemize}

\item If (a) the support of $D$ does not contain a point at infinity,
(b) $e_i = e_i^*$ for all unramified points and (c) $e_i$ is even 
for all ramified points (except possibly at
infinity), then $D$ is the pullback (via $\rho$) of a divisor on 
$\ppp^1$. Indeed, let

\begin{equation*}
a = \sum_{P_i \text{ unramified}} e_i + \sum_{P_i \text{ ramified}} 
\frac{e_i}{2},
\end{equation*}
and let $p(x)$ be a polynomial of degree $a$ with no roots 
among $x_1, \ldots, x_{r+s}$. Then the function

\begin{equation}
\label{eqn1} f(x,y) =\frac{p(x)}{\prod_{i=1}^{r}(x-x_i)^{e_i} 
\prod_{i=r+1}^{r+s}(x-x_i)^{e_i/2}}
\end{equation}
will have polar divisor $D$.

\item If (a) the support of $D$ does not contain a point at infinity,
(b) $e_i = e_i^*$ for all unramified points and (c) $e_i$ is odd 
for all ramified points (except possibly at
infinity), then let

\begin{equation*}
a = \sum_{P_i \text{ unramified}} e_i + \sum_{P_i \text{ ramified}} 
\frac{e_i+1}{2} - \frac{d}{2},
\end{equation*}
if $d$ is even, and

\begin{equation*}
a = \sum_{P_i \text{ unramified}} e_i + \sum_{P_i \text{ ramified}} 
\frac{e_i+1}{2} - \frac{d+1}{2},
\end{equation*}
if $d$ is odd.  Let $p(x)$ be a polynomial of degree $a$ with 
no roots among $x_1, \ldots, x_{r+s}$. Then the
function

\begin{equation}
\label{eqn2} f(x,y) =\frac{p(x)y}{\prod_{i=1}^{r}(x-x_i)^{e_i} 
\prod_{i=r+1}^{r+s}(x-x_i)^{(e_i+1)/2}}
\end{equation}
will have polar divisor $D$.
\end{itemize}

In the general case, where $e_i > e_i^*$ for at least one 
unramified point $P_i$, let

\[
a= \left\{
\begin{array}{ll}
\sum_{i=1}^r e_i + \frac{e_0-d}{2}, 
& \ \ d \text{ odd and } e_0 \text{ even,}\\
\ &\ \\
\sum_{i=1}^r e_i + \frac{e_0+1-d}{2}, 
& \ \ d \text{ odd and } e_0 \text{ odd,}\\
\ &\ \\
\sum_{i=0}^r e_i - \frac{d}{2}, 
& \ \ d \text{ even,}\\
\end{array}
\right.
\]
and let $p(x)$ be a polynomial of degree $a$ in $x$ with no 
roots among the $x$-coordinates of the points in
the support of $D$. Let

\[
\beta_i(x)= \left\{
\begin{array}{ll}
(x-x_i)^{e_i}, &\ \ 1\leq i\leq r,\\
\ &\ \\
(x-x_i)^{e_i/2}, &\ \ i\geq r,\ e_i\ {\rm even},\\
\ &\ \\
(x-x_i)^{(e_i+1)/2}, &\ \ i\geq r,\ e_i\ {\rm odd.}
\end{array}
\right.
\]


We define a \textbf{seed function} as follows. Choose an initial 
index $i_0>0$ such that $P_{i_0}$ is an
affine unramified point on $C$ and $e_{i_0} > e_{i_0}^*$\footnote{For 
future reference, by analogy with Gauss
elimination/row reduction, we call the point $P^*_{i_0}$ 
a {\bf pivot point}.}. Let
\[
f_{0,D }(x,y) =\frac{(y+y_{i_0})p(x)}{\prod_{i=1}^{r+s}\beta_i(x) }.
\]

Because of this, if $e_i$ is even for all ramified $P_i$ then 
$\ddiv_\infty (f_{0,D}(x,y))$ is

\begin{eqnarray*}
\ddiv_\infty (f_{0,D}(x,y)) & = 
& e_0 P_0 (+e_0 P^*_0) + e_1 P_1 + e_1 P_1^* + \dots \\
& & +e_{i_0} P_{i_0}+(e_{i_0}-1) P^*_{i_0}+...+e_{r} P_{r}+e_{r} P^*_{r}\\
& & + \sum_{i=1}^{s} e_{r+i}P_{r+i}.
\end{eqnarray*}
If $e_i$ is odd for all ramified $P_i$, then $\ddiv_\infty (f_{0,D}(x,y))$ is

\begin{eqnarray*}
\ddiv_\infty (f_{0,D}(x,y)) & = 
& e_0 P_0 (+e_0 P^*_0) + e_1 P_1 + e_1 P_1^* + \dots \\
& & +e_{i_0} P_{i_0}+(e_{i_0}-1) P^*_{i_0}+...+e_{r} P_{r}+e_{r} P^*_{r}\\
& & + \sum_{i=1}^{s} (e_{r+i}+1)P_{r+i}.
\end{eqnarray*}

Now if $e_{i_0}^* < e_{i_0} -1$, we will 
\textbf{pivot} until the pole at $P_{i_0}^*$ is $e_{i_0}^*$. Observe
that the function

\[
f_{i,m}(x,y) =\frac{1}{(x-x_i)^{m}}
\]
has
\[
\ddiv_\infty (f_{i,m}(x,y)) = m P_i+m P^*_i.
\]

We call the $f_{i_0,m}$ the {\bf pivot functions} ($m>0$).


It follows from an expansion in terms of a local coordinate 
or from the usual partial fraction decomposition
of rational functions (see for example \S 5.11 in \cite{GG}) 
that there is a constant $c\not= 0$ such that
the divisor of $g=f_{0,D}-cf_{i_0,e_{i_0}-1}$ is

\begin{eqnarray*}
\ddiv_\infty (g) & = 
& e_0 P_0 (+e_0 P^*_0) + e_1 P_1 + e_1 P_1^* + \dots \\
& & +e_{i_0} P_{i_0}+(e_{i_0}-2) P^*_{i_0}+...+e_{r} P_{r}+e_{r} P^*_{r}\\
& & + \sum_{i=1}^{s} e_{r+i}P_{r+i}.
\end{eqnarray*}
if $e_{r+i}$ is even, or

\begin{eqnarray*}
\ddiv_\infty (g) & = 
& e_0 P_0 (+e_0 P^*_0) + e_1 P_1 + e_1 P_1^* + \dots \\
& & +e_{i_0} P_{i_0}+(e_{i_0}-2) P^*_{i_0}+...+e_{r} P_{r}+e_{r} P^*_{r}\\
& & + \sum_{i=1}^{s} (e_{r+i}+1)P_{r+i}.
\end{eqnarray*}
if $e_{r+i}$ is odd. Thus we have reduced the multiplicity 
of the pole at $P^*_{i_0}$ by one.

The constant $c$ is determined by the following calculation: 
choose a local parameter $t$ such that $t=0$
when $(x,y)=P^*_{i_0}$; for example $t=x-x_{i_0}$.   
Expand $f_{0,D}$ and $f_{i_0,e_{i_0}-1}$ as power series
in $t$, so $f_{0,D}(x,y)=a\cdot t^{-e_{i_0}+1}+$ higher order 
terms, and $f_{i_0,e_{i_0}-1}(x,y)=b\cdot
t^{-e_{i_0}+1}+...$ then $c=a/b$.

Using the other pivot functions, we may compute constants 
$c_i$ such that the function

\[
\begin{array}{ll}
f_{1,D}(x,y)\ \ =&f_0(x,y)-c_1f_{i_0,e_{i_0}-1}(x,y)\\
&\ \ -c_2f_{i_0,e_{i_0}-2}(x,y)-...-c_{e_{i_0}}f_{i_0,0}(x,y)
\end{array}
\]
has divisor

\begin{eqnarray*}
\ddiv_\infty (f_{1,D}(x,y)) & = 
& e_0 P_0 (+e_0 P^*_0) + e_1 P_1 + e_1 P_1^* + \dots \\
& & +e_{i_0} P_{i_0}+(e_{i_0}^*) P^*_{i_0}+...+e_{r} P_{r}+e_{r} P^*_{r}\\
& & + \sum_{i=1}^{s} e_{r+i}P_{r+i},
\end{eqnarray*}
if $e_{r+i}$ is even, or

\begin{eqnarray*}
\ddiv_\infty (f_{1,D}(x,y)) & = 
& e_0 P_0 (+e_0 P^*_0) + e_1 P_1 + e_1 P_1^* + \dots \\
& & +e_{i_0} P_{i_0}+(e_{i_0}^*) P^*_{i_0}+...+e_{r} P_{r}+e_{r} P^*_{r}\\
& & + \sum_{i=1}^{s} (e_{r+i}+1)P_{r+i},
\end{eqnarray*}
if $e_{r+i}$ is odd. In other words, we have reduced the order 
of the pole at the pivot point $P^*_{i_0}$
from $e_{i_0}$ to $e^*_{i_0}$.

Now, if there is one, choose a new index $i_1$, $1 \leq i_1 \leq r$, 
where $P_{i_1}$ is unramified and
$e_{i_1}\not= e^*_{i_1}$.  Using $f_{1,D}$ and proceeding 
as above, we may compute $f_{2,D}$, reducing the
order of the pole at the new pivot point $P^*_{i_1}$ to $e^*_{i_1}$. 
Proceeding inductively, in this way we
may reduce the orders of all of the poles at the finite 
unramified pivot points. If $d$ is even, and $e_0^*
\not= e_0$, then we may use $P_0^*$ as a pivot point with 
powers of $x$ as the pivot functions.  By this
procedure, we find a function which we will call $f_{r,D}$ such that

\begin{eqnarray*}
\ddiv_\infty (f_{r,D}(x,y)) & = 
& e_0 P_0 (+e_0^* P^*_0) + e_1 P_1 + e_1^* P_1^* + \dots \\
& & +e_{r} P_{r}+e_{r}^* P^*_{r} + \sum_{i=1}^{s} e_{r+i}P_{r+i},
\end{eqnarray*}
if $e_{r+i}$ is even, or

\begin{eqnarray*}
\ddiv_\infty (f_{r,D}(x,y)) & = 
& e_0 P_0 (+e_0^* P^*_0) + e_1 P_1 + e_1^* P_1^* + \dots \\
& & +e_{r} P_{r}+e_{r}^* P^*_{r} + \sum_{i=1}^{s}(e_{r+i}+1)P_{r+i},
\end{eqnarray*}
if $e_{r+i}$ is odd.  In the first case, we are done: 
$\ddiv_\infty (f_{r,D}(x,y)) = D$.  In the second case,
we pivot once at each of the ramified points $P_{r+1}, \ldots, P_{r+s}$ 
using the pivot function
$f_{r+i,\frac{e_{r+i}+1}{2}}$ to remove the one excess pole.

Summarizing, we have constructed an element $g_D\in L(D)$ with 
pole divisor $D$, as desired.

\qed

\section{Bases of Riemann-Roch spaces for cyclic curves}\label{sec:bases}

Let $C$ be a smooth hyperelliptic curve $y^2=h(x)$, 
as in section \ref{sec:poles} and
%
\[ D =e_0P_0+e_1P_1...+e_{r}P_{r} (+e^*_0P^*_0)+e_1^*P_1^*...
+e^*_{r}P^*_{r}(+e_{r+1}P_{r+1}) \]
%
be a divisor on $C$, where as in section \ref{sec:poles}, 
$P_1, \ldots, P_r$ are finite unramified points,
and $e_i \geq e_i^*$ for $i = 0, \ldots , r$.  
In this section we only consider divisors $D$ with at most one
ramified point in the support of $D$.  Thus if the degree $d$ of 
$h(x)$ is even, we may have one finite
ramified point $P_{r+1}$ in the support of $D$; otherwise if 
$d$ is odd, omit both terms in parentheses in
the above expression.


If $D$ satisfies the conditions of Proposition~\ref{prop:main}, 
then $D$ is non-special, so by the
Riemann-Roch theorem, we have
\begin{equation*}
\dim L(D) = \deg(D) + 1 - g.
\end{equation*}

\begin{theorem}\label{thrm:main2}
Let $C$ and $D$ be as above, and assume that $D$ satisfies the 
conditions of Proposition \ref{prop:main}.
Then there is a basis of $L(D)$ consisting of functions which 
are linear combinations of

(a) $\frac{y}{\prod_{i=0}^{s-1}(x-x_i)^{f_i} } $,

(b) $\frac{1}{(x-x_i)^{m} }$ ($0<m\leq f_i$),

(c) the monomial functions $x^iy^j$ ($i\geq 0$, $j=0,1$),

(d) the "mixed" functions $\frac{yx^a}{\prod_{i=0}^{s-1}(x-x_i)^{f_i} }$.
\end{theorem}

\pf By Proposition \ref{prop:main}, we can construct an element 
$b_0$ in $L(D)$ of the required form with
polar divisor $D$.  Now suppose that
\begin{enumerate}
\item  $e_i^*=0$ for $i = 0, \ldots r$,
\item  $e_{r+1}=0$, and
\item  $e_1 + \ldots + e_r = \lfloor \frac{d+1}{2} \rfloor$.
\end{enumerate}
We will call such a divisor ``minimal."  If $D$ is minimal, 
$\deg(D) = \lfloor \frac{d+1}{2} \rfloor = g+1$,
so $\dim L(D)=2$.  The functions ${b_0, 1}$ form a basis for $L(D)$.

Now suppose that $D$ is not minimal.  Then we can subtract a 
point $P$ from $D$ in such a way that $D-P$
still satisfies the conditions of Proposition \ref{prop:main}.  
Then there is a function $b_1$ with polar
divisor $D-P$.  Because $b_0$ and $b_1$ have different polar 
divisors, they are independent.  Now if $D-P$ is
minimal, $\deg(D) = 1+ \lfloor \frac{d+1}{2} \rfloor = g+2$, so 
$\dim L(D)=3$.  In this case the functions
${b_0, b_1, 1}$ form a basis for $L(D)$.  If $D-P$ is not minimal, 
we again subtract a point and continue in
the same manner. In the end, if 
$\deg D = m + \lfloor \frac{d+1}{2} \rfloor$, we will have subtracted $m$
points and constructed $m+1$ independent functions $b_0, \ldots , b_m$. 
Since $\dim L(D) = m + 2$, the
function ${b_0, \ldots , b_m, 1}$ form a basis for $L(D)$.

\qed

As an immediate consequence of the above proof, we have the 
following results.

\begin{corollary}
Let $C$ and $D$ be as above, so
\begin{equation*}
D =e_0P_0+e_1P_1...+e_{r}P_{r} (+e^*_0P^*_0)+e_1^*P_1^*...
+e^*_{r}P^*_{r}(+e_{r+1}P_{r+1}).
\end{equation*}
Let $E<D$ be an effective divisor, so that 
$\supp(E) \subseteq \supp(D)$, and if $E$ is written as
\begin{equation*}
E =a_0P_0+a_1P_1...+a_{r}P_{r} (+a^*_0P^*_0)+a_1^*P_1^*...+a^*_{r}P^*_{r}(+a_{r+1}P_{r+1}),
\end{equation*}
assume that $a_i \geq a_i^*$ for $i = 0, \ldots, r$.   
Then we can find bases $B_1$ of $L(E)$ and $B_2$ of
$L(D)$ such that $B_1 \subset B_2$ and each function is of 
the form described in Theorem \ref{thrm:main2}.
\end{corollary}

\begin{remark}
Note that the condition $a_i \geq a_i^*$ may not be true a priori, 
even if $E$ satisfies the conditions of
Proposition~\ref{prop:main}.
\end{remark}

\pf  Construct a basis of $L(D)$ as in the proof of 
Theorem \ref{thrm:main2}, but subtracting the points in
$D-E$ first.

\qed


\section{Implementation and examples}

In this section we explicitly compute both by hand and using \SAGE, 
showing how the syntax can be used. You
need the file {\tt rrbasis3.sage}, which also has examples included.

\subsection{$y^2=x^9+x$ over $GF(5)$}


Consider %affine points $P_1=(x_0,y_0)$, $P_2=(x_1,y_1)$ on
the genus $g=4$ curve

\begin{equation}
\label{eqn:eqn} C:\ \ y^2=x^9+x,\ \ \ F=GF(5),
\end{equation}
which %are not ramification points, and let $P^*_1=(x_0,-y_0)$,
%$P^*_2=(x_1,-y_1)$. Since
has rational points

\[
C(F)=\{\infty,(0,0),(2,2),(2,3),(3,1),(3,4)\}.
\]
Let $P_1=(2,2)$, $P^*_1=(2,3)$, $P_2=(3,1)$, $P^*_2=(3,4)$. 
Consider the divisors $D=4P_1+2P_2$ and
$E=3P_1+2P_2$. We will use the above construction to compute a 
basis of $L(D)$ which contains a basis of
$L(E)$.

Taking $P^*_1$ as our pivot point, we use the local coordinate 
$t=x-2$, which vanishes at $P^*_1$. We can
compute the expansion of $y$ in two ways: (a) from the power series 
of $y=-(x+x^9)^{1/2}$ or (b) by plugging
a general power series expansion with unknown coefficients into 
(\ref{eqn:eqn}) and solving the ``upper
triangular'' system of equations recursively for the coefficients. 
This can be done using method (b) in \SAGE
\cite{S}, as is shown below.

We will need local parameters about $P^*_1$ and $P^*_2$.

\begin{lemma}
\begin{itemize}
\item
Local parameters about $P^*_1=(2,3)$: We have

\begin{equation}
\label{eqn:local1} x=t+2,\ \ \ y=3+3t^2+t^3+3t^4+3t^6+3t^7+t^8+2t^9+O(t^{10})\ .
\end{equation}

\item
Local parameters about $P^*_2=(3,4)$: We have

\begin{equation}
\label{eqn:local2} x=t+3,\ \ \ y=4+3t^2+t^3+3t^4+3t^6+3t^7+t^8+2t^9+O(t^{10})\ .
\end{equation}

\end{itemize}

\end{lemma}

\pf This can be verified by a direct computation, plugging each 
set of equations into $y^2-x^9-x$.

\qed

Using method (b) and \SAGE we have: 

\vskip .2in

\begin{Verbatim}[fontsize=\tiny,fontfamily=courier,fontshape=tt,frame=single,label=\sage]

sage: attach "rrbasis3.sage"
sage: F = GF(5) 
sage: pt = (2,3)
sage: A2 = AffineSpace(2, F, names = 'xy')
sage: R = A2.coordinate_ring()
sage: x, y = R.gens()
sage: f = y^2 - x^9 - x
sage: C = AffineCurve_GF(A2,f)
sage: C.local_coordinates(pt,9)
      [2 + t, 3 + 3*t^2 + t^3 + 3*t^4 + 3*t^6 + 3*t^7 + t^8 + 2*t^9 + 3*t^11 + 3*t^12]
sage: pt=(3,4) 
sage: C.local_coordinates(pt,9)
      [3 + t, 4 + 4*t^2 + 2*t^3 + 4*t^4 + 4*t^6 + t^7 + 3*t^8 + 4*t^9 + t^11 + t^12]

\end{Verbatim}

\noindent 
This is obtained by plugging in a power series with arbitrary 
coefficients into $f(x,y)=0$, thus
obtaining an ``upper triangular'' system of non-linear equations. 
This system can be imported into Singular
\cite{Si}, which comes with \SAGE, and solved using 
Gr\"obner bases techniques.

Now that we have computed the local coordinates, we proceed 
to find
 bases of $L(D)$ and $L(E)$.  We have $\dim L(D)=\dim L(4P_1+2P_2)=3$ 
and $\dim L(E)=\dim L(3P_1+2P_2)=2$, so we need to find one function with polar divisor 
$D$ and one function with polar divisor $E$.

First we find a function with polar divisor $D$.  With $P^*_1$ as the 
pivot point, the seed function is

\[
f_0(x,y)=f_{0,D}(x,y)=\frac{y-3}{(x-2)^4(x-3)^{2} },
\]
with polar divisor $\ddiv_\infty (f_0)=4 P_1+3P^*_1+2P_2+2P^*_2$, and the 
pivot functions are
\[
f_{2,m}(x,y)=\frac{1}{(x-2)^{m}},
\]
each with polar divisor $m P_1+mP^*_1$, for $m=1,2,3$.

We use the previously calculated local coordinates and \SAGE to calculate
\[
\ddiv(f_{0,D}-3f_{2,2}-2f_{2,1})=4P_1+2P_2+2P^*_2,
\]
eliminating the excess pole at $P^*_1$.  Now we pivot at the point 
$P^*_2$.  Let the new seed be

\[
f_{1,D}(x,y)=f_{0,D}(x,y)-3f_{2,2}(x,y)-2f_{2,1}(x,y).
\]
The new pivot functions are $f_{3,m}(x,y)=\frac{1}{(x-3)^{m}}$, 
which has divisor $m P_2+mP^*_2$, for
$i=1,2$. A similar \SAGE calculation implies
\[
\ddiv (f_{1,D}(x,y)-f_{3,2}(x,y)-f_{3,1}(x,y))= 4P_1+2P_2.
\]
This has eliminated the excess pole at $P_2^*$.  We take
%
\[
\begin{split}
b_0(x,y)&=f_{0,D}(x,y)-3f_{2,2}(x,y)-2f_{2,3}(x,y)-f_{3,2}(x,y)-f_{3,1}(x,y)\\
& = \frac{y-3}{(x-2)^4(x-3)^2}-\frac{3}{(x-2)^2} -
\frac{2}{x-2}-\frac{1}{(x-3)^2}-\frac{1}{x-3}
\end{split}
\]
%
to be our first basis element in $L(D) = L(4P_1+2P_2)$.

Now, we wish to find a function $b_1$ with polar divisor $E$. 
Again we will first pivot on $P_1^*$.  Let
\[
f_{0,E}(x,y)=\frac{y-3}{(x-2)^3(x-3)^{2} } \in L(3 P_1+2P^*_1+2P_1+2P^*_2),
\]
be the seed function and let $f_{2,m}(x,y)=\frac{1}{(x-2)^{m}}$ 
be the pivot functions.  We again use the
expansion for $x$ and $y$ in terms of $t$ given in (\ref{eqn:local2}). 
A \SAGE calculation (omitted) shows
that $\ddiv(f_{0,E}-f_{2,m})=3 P_1+2P_1+2P^*_2$, so we have removed 
the excess pole at $P_1^*$.  We now pivot
around the point $P_2^*$.  Let the new seed be
\[
f_{1,E}(x,y)=f_{0,E}(x,y)-f_{2,1}(x,y)\in  L(3 P_1+2P_1+2P^*_2)
\]
and let $f_{3,m}(x,y)=\frac{1}{(x-3)^{m}}$ be the new pivot functions.  
Another \SAGE calculation (omitted)
shows that

\[
f_{1,E}(x,y)-4f_{3,2}(x,y)-f_{3,1}(x,y)\in  L(3P_1+2P_2).
\]
This has removed the excess pole at $P_2^*$, so we are done.  
The new basis element is
\[
\begin{array}{ll}
b_1(x,y)&=f_{0,E}(x,y)-f_{2,1}(x,y)-4f_{3,2}(x,y)-f_{3,1}(x,y)\\
& = \frac{y-3}{(x-2)^3(x-3)^2}-\frac{1}{x-2} -\frac{4}{(x-3)^2}-\frac{1}{x-3}.
\end{array}
\]
Since the dimension of $L(4P_1+2P_2)$ is $3$, we have only the 
constants left, so we take $\{b_0,b_1,1\}$ as
a basis for $L(D)$. As a consequence of the method, the subset 
$\{b_1, 1\}$ is a basis for for $L(E)$.

In fact, this can be computed in \SAGE using the commands:

\vskip .2in

\begin{Verbatim}[fontsize=\tiny,fontfamily=courier,fontshape=tt,frame=single,label=\sage]

sage: F = GF(5)
sage: A2 = AffineSpace(2, F, names = 'xy')
sage: R = A2.coordinate_ring()
sage: x, y =R.gens()
sage: f = y^2 - x^9 - x
sage: C = AffineCurve_GF(A2,f)
sage: pts = C.rational_points(); pts
      [(0, 0), (2, 2), (2, 3), (3, 1), (3, 4)]
sage: D = C.divisor([(0,pts[1]),(0,pts[3])])
sage: E = C.divisor([(2,pts[1]),(4,pts[3])])
sage: b = riemann_roch_space(C,D,E)
sage: b

[(2 + y + x + x^2 + 2*x^3 + 3*x^4)/(4 + 4*x + 4*x^2 + 3*x^3 + x^4 + 4*x^5 + x^6),
 (2 + y + x + x^2 + 2*x^3 + 3*x^4)/(2 + x + 4*x^2 + 2*x^3 + 2*x^4 + x^5)]
sage: C.divisor_of_function(b[0])
      -2*(3 + y, 3 + x) - 4*(2 + x, 4 + y)
sage: C.divisor_of_function(b[1])
      (1 + y, 2 + x) - 2*(3 + y, 3 + x) - 3*(2 + x, 4 + y)

\end{Verbatim}

\noindent
The functions in {\tt b} represent the basis elements of 
$L(4P_1+2P_2)$ given by the functions $b_0$ and
$b_1$ above. In future versions of \SAGE, some of these commands may have 
a different syntax.

\section{Concluding remarks}

We thank T. Berry for useful email communications and the NARC for
partial research support.


\begin{thebibliography}{99}

\bibitem[A]{A} J. Alperin, {\bf Local representation theory}
Cambridge Univ. Press, 1986.

\bibitem[B1]{B1} T. Berry, {\it On Coates' algorithm,}
ACM SIGSAM Bulletin, Volume 17 ,  Issue 2, May (1983)12 - 17.
\newline
\url{http://portal.acm.org/citation.cfm?id=1089330.1089333}

\bibitem[B2]{B2} ------, {\it Construction of linear systems
on hyperelliptic curves}, J. Symbolic Comp. \underline{26}(1998)315-327.

%\bibitem[B]{B} N. Borne, ``Une formule de Riemann-Roch
%equivariante pour des courbes,'' Can. J. Math. \textbf{55}(2003)693-710.

\bibitem[C]{C} J. Coates, {\it Construction of rational functions on a
curve}, Proc. Cambridge Phil. Soc. 68 (1970)105-123.

\bibitem[D]{D} H. J. Davenport, {\bf On the integration of algebraic
functions}, Lecture Notes in Comp. Sci., vol 102 (1981), Springer-Verlag.

\bibitem[G]{G} N. G\"ob, {\it Computing the automorphism groups of
hyperelliptic function fields,} available at 
\url{http://front.math.ucdavis.edu/math.NT/0305284}.

\bibitem[GG]{GG} J. von zur Gathen and J. Gerhard,
{\bf Modern computer algebra}, $2^{nd}$ ed., Cambridge Univ. Press, 2003.

\bibitem[GJK]{GJK} D. Glass, D. Joyner and A. Ksir,
{\it Basis of Riemann-Roch $G$-modules for $y^2=x^p-x$ over $GF(p)$,} preprint, 2007.

\bibitem[J]{J} D. Joyner, {\tt rrbasis3.sage}, at
\url{http://sage.math.washington.edu/home/wdj/research/rrbasis3.sage}.

\bibitem[JK]{JK} D. Joyner and A. Ksir,
{\it Decomposing representations of finite groups on Riemann-Roch spaces}, 
Proc. Amer. Math. Soc.  135  (2007), 3465-3476. 

\bibitem[Si]{Si}
G.-M.~Greuel, G.~Pfister, and H.~Sch\"onemann.
\newblock {{\sc Singular} 3.0}. A Computer Algebra System for Polynomial Computations.
\newblock Centre for Computer Algebra, University of Kaiserslautern (2005).
\newblock \url{http://www.singular.uni-kl.de}.

\bibitem[S]{S}
William Stein, \SAGE: {\it An open source mathematical software package},
\newline
\url{http://www.sagemath.org/}, \url{http://sage.scipy.org/}

\bibitem[Sti]{Sti} H. Stichtenoth, {\bf Algebraic function
fields and codes}, Springer-Verlag, 1993.

\end{thebibliography}

\end{document}
