1 Introduction

Let \(\mathbb {F}_q\) denote the finite field of characteristic p and cardinality \(q=p^a\). Let \({\widetilde{X}}\) be a nonsingular projective curve of genus g over \(\mathbb {F}_q\). Recall that the zeta function of \({\widetilde{X}}\) is defined by

$$\begin{aligned}Z({\widetilde{X}}, T) = \exp \left( \sum \limits _{r=1}^\infty \frac{|{\widetilde{X}}(\mathbb {F}_{q^r}) |}{r} T^r\right) .\end{aligned}$$

It follows from the Weil conjectures [18, Ch. VIII] that \(Z({\widetilde{X}}, T)\) is a rational function of the form \(P(T)/(1-T)(1-qT)\) where \(P(T) \in \mathbb {Z}[T]\) is a polynomial of degree 2g whose roots all have absolute value \(q^{-\frac{1}{2}}\). Furthermore \(Z({\widetilde{X}},T)\) satisfies the functional equation

$$\begin{aligned} Z({\widetilde{X}}, q^{-1} T^{-1}) = q^{1-g} T^{2-2g} Z({\widetilde{X}}, T). \end{aligned}$$
(1.1)

It follows from these facts that to compute \(Z({\widetilde{X}}, T)\) it suffices to compute \(|{\widetilde{X}}(\mathbb {F}_{q^r})|\) for \(r=1,\dots ,g\).

The main purpose of this paper is to describe a practical, efficient algorithm for the problem of computing the zeta function of an arbitrary nonsingular curve.

Theorem 1.1

There exists an explicit deterministic algorithm with the following properties. The input consists of a prime p, a positive integer a, a monic irreducible polynomial \({\bar{b}} \in \mathbb {F}_p[t]\) of degree a defining the finite field \(\mathbb {F}_q \cong \mathbb {F}_p[t]/{\bar{b}}\), and an absolutely irreducible polynomial \({\overline{F}} \in \mathbb {F}_q[x,y]\) of degree \(d \ge 2\). The output is \(Z({\widetilde{X}}, T)\) where \({\widetilde{X}}\) is the nonsingular projective curve with function field \(\mathbb {F}_q(x)[y]/\langle {\overline{F}} \rangle \). The algorithm has time complexity

$$\begin{aligned}a^{O(1)} d^{O(1)} p^{\frac{1}{2}+o(1)}.\end{aligned}$$

We do not provide a complete proof of this theorem. We will give an outline of all of the steps involved in the algorithm, from which one could deduce the time complexity of \(a^{O(1)} d^{O(1)} p^{\frac{1}{2}+o(1)}\) by referring to the detailed time complexity estimates provided in [14] and [2]. We have not worked out the exponents in the time complexity stated in Theorem 1.1, but intend to present a thorough analysis in a future paper. In Sect. 4 we present concrete examples that demonstrate the utility and generality of our algorithm.

Schoof in [21] was the first to demonstrate a deterministic polynomial-time algorithm for computing the zeta function of an arbitrary genus \(g=1\) curve \(E/\mathbb {F}_q\). The algorithm involves computing the trace of the Frobenius endomorphism modulo a number of small primes \(\ell \), followed by using the Chinese remainder theorem to determine the exact value of \((q+1 - \#E(\mathbb {F}_q))\). Schoof’s algorithm, and higher genus variants of it such as [19] and [1], are known today as \(\ell \)-adic algorithms for computing the zeta function. These \(\ell \)-adic algorithms have time complexity polynomial in \(\log q\) for fixed g, but unfortunately they are badly exponential in g. Extensions of Schoof’s algorithm are frequently used for the case of \(g=1\), and specialised \(\ell \)-adic algorithms for the case of \(g=2\) have been useful in practice [11], but as yet \(\ell \)-adic algorithms have been impractical for the case of an arbitrary curve of genus \(g \ge 3\).

Kedlaya in [16] demonstrated an efficient p-adic algorithm for the problem of computing the zeta function of an hyperelliptic curve \({\widetilde{X}}\) over a finite field of odd characteristic. Kedlaya showed how one could apply the machinery of Monsky–Washnitzer cohomology to this problem, computing the zeta function by explicitly computing the action of Frobenius on this p-adic cohomology of \({\widetilde{X}}\). This method proved to be fruitful for extension and generalisation to larger classes of curves, resulting in the development of p-adic point-counting algorithms for the case of superelliptic curves [10], \(C_{ab}\) curves [9] and nondegenerate curves [8]. These Kedlaya-style algorithms have time complexity polynomial in g but exponential in \(\log p\), and they are used in practice for curves of genus \(g \ge 2\).

The most general algorithm among the descendants of [16] is Tuitman’s algorithm [23], which can handle almost all inputs \({\overline{F}} \in \mathbb {F}_q[x,y]\). The main drawback of Tuitman’s algorithm is that it requires as input a “good” characteristic zero lift of the polynomial \({\overline{F}} \in \mathbb {F}_q[x,y]\). The properties this lift must have are rather technical; they are described in [23, Ass. 1]. Such a lift always exists (provided that \(p > 2\) and allowing for extension of the base field), but the problem of efficiently computing a good lift for arbitrary \({\overline{F}} \in \mathbb {F}_q[x,y]\) is difficult. Castryck, Tuitman and Vermeulen have shown in [6, 7, 23] how one can compute a suitable lift for inputs \({\overline{F}}\) that are nondegenerate with respect to their Newton polytope, or that define a curve of geometric genus at most 5, or that define a curve of arithmetic gonality at most 5.

There are more general p-adic algorithms that can be used to compute the zeta function of an arbitrary n-dimensional variety over \(\mathbb {F}_q\) and that have polynomial time complexity for fixed p. Lauder and Wan were the first to demonstrate an algorithm having these properties; they achieved this by using ideas originally presented by Dwork in his proof of the rationality of the zeta function. For fixed n, in the case of an n-dimensional hypersurface over \(\mathbb {F}_q\), Lauder and Wan achieved a time complexity polynomial in a, p and the degree d of the defining polynomial [17, Thm. 37]. In [14], Harvey developed an algorithm similar in nature to that of [17] but with asymptotically superior time complexity [14, Thm. 1.2].

Our algorithm is based on the trace formula for counting points on a hypersurface from [14, §3]. We present a modified version of this trace formula in Sect. 2. In [14], Harvey suggested that one could compute the zeta function of a nonsingular curve by using the trace formula to count points on a plane model, which gives the right result except possibly at the singularities of that model, and afterwards making corrections for these singularities. We make explicit in Sect. 3 how one does this.

Let \({\overline{F}}\) and \({\widetilde{X}}\) be as in Theorem 1.1, and let \(X_0\) be the affine curve cut out by \({\overline{F}}\), with projective closure X. By using Harvey’s trace formula we can count the points on X in any extension \(\mathbb {F}_{q^r}/\mathbb {F}_q\). If X happens to be nonsingular, then we actually have that X is isomorphic to \({\widetilde{X}}\) over \(\mathbb {F}_q\), and by counting points on X in extensions of \(\mathbb {F}_q\) of degree up to g we succeed in computing \(Z({\widetilde{X}}, T)\).

If X is singular, a naive approach to computing \(Z({\widetilde{X}}, T)\) using the trace formula would be to compute Z(XT) and then remove extraneous factors from the numerator, i.e., remove factors whose roots have absolute value 1 rather than \(q^{-\frac{1}{2}}\). One can compute Z(XT) by bounding the degree of the numerator using Bombieri’s bound [4, Thm.  1A], and then counting points on X in extensions of \(\mathbb {F}_q\) of degree up to this bound.

Our algorithm does better than the naive approach — it avoids costly computations of point-counts on X that are performed when using the naive approach in the case that X is singular. In our algorithm we count only the \(\mathbb {F}_{q^r}\)-rational points on X for \(r=1,\dots ,g\), and we determine using the Montes algorithm [13] precisely how \({\widetilde{X}}\) differs from X by factoring ideals related to the singular points of X in maximal orders \({\mathcal {O}}\) of \(\mathbb {F}_q({\widetilde{X}})\). With the point-counts on X for \(r=1,\dots ,g\) and the extra information about how \({\widetilde{X}}\) and X differ we determine the values \(|{\widetilde{X}}(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,g\), and hence compute \(Z({\widetilde{X}}, T)\).

The main advantage our algorithm has over Tuitman’s is that we require no assumptions about the lift F of \({\overline{F}}\) to characteristic zero. To apply Harvey’s trace formula we must lift \({\overline{F}} \in \mathbb {F}_q[x,y]\) to some \(F \in \mathbb {Z}_q[x,y]\), but any lift suffices. We have implemented our algorithm in the \(q=p\) case in the computer algebra system MAGMA [5] and made the code publicly available. In Sect. 4 we compare the performance of our implementation against the MAGMA implementation of Tuitman’s algorithm.

2 Harvey’s trace formula

In this section, we shall present a generalisation of the trace formula given in Theorem 3.1 of [14]. This version allows us to take into account the shape of the polynomial defining a curve (or more generally, hypersurface), and therefore results in a more efficient computation of point-counts than if one were to use a straightforward implementation of the formula from [14]. Our version works with the actual Newton polytope of the polynomial, whereas [14, Thm. 3.1] works with a dilation of the standard simplex that contains that Newton polytope. For our point-counting purposes we only need the case of curves, but we shall present the general hypersurface case as it is no harder to state or prove.

For any domain R, we denote the Laurent polynomial ring \(R[x_1, x_1^{-1}, \dots , x_n, x_n^{-1}]\) by \(R[x^{\pm }]\), and for \(F \in R[x^{\pm }]\) and \(u = (u_1, \dots , u_n) \in \mathbb {Z}^n\), we denote by \([F]_u\) the coefficient of \(x^u = x_1^{u_1} \cdots x_n^{u_n}\) in F. Throughout, we shall use K to denote a convex polytope in \(\mathbb {R}^n\) with integral vertices. We will denote by \(K_\mathbb {Z}\) the set of integral points in K, i.e., \(K_\mathbb {Z}:= K \cap \mathbb {Z}^n\). For \(F \in R[x^{\pm }]\), we denote by \(\Delta (F)\) the Newton polytope of F, by which we mean the convex hull in \(\mathbb {R}^n\) of the finite set \(\{u \in \mathbb {Z}^n : [F]_u \ne 0\} \subseteq \mathbb {Z}^n\). We denote by \(P_K\) the free R-module on the set of monomials with exponents in \(K \cap \mathbb {Z}^n\):

$$\begin{aligned}P_{K} := \bigoplus \limits _{u \in K_\mathbb {Z}} R \, x^u.\end{aligned}$$

For \(s \in \mathbb {Z}^+\), let sK denote the s-fold dilation of K. For two convex polytopes \(K_1, K_2\) denote by \(K_1 \oplus K_2\) the Minkowski sum \(\{v_1 + v_2 : v_1 \in K_1, v_2 \in K_2\}\). One can show that for \(F, G \in R[x^{\pm }]\) and \(s \in \mathbb {Z}^+\), we have \(\Delta (FG) = \Delta (F) \oplus \Delta (G)\) and \(\Delta (F^s) = s \Delta (F)\).

For \(n \ge 1\), let \({\mathbb {A}}^n_{\mathbb {F}_q}\) denote affine n-space over \(\mathbb {F}_q\) with coordinates \(x_1, \dots , x_n\). Let \({\mathbb {T}}_{\mathbb {F}_{q}}^n\) be the affine torus \(\{x_1 \cdots x_n \ne 0 \} \subseteq {\mathbb {A}}^n_{\mathbb {F}_{q}}\). When we refer to a hypersurface V in \({\mathbb {T}}_{\mathbb {F}_{q}}^n\) cut out by \({\overline{F}} \in \mathbb {F}_q[x^{\pm }]\), we mean the variety with geometric points

$$\begin{aligned}\{(c_1, \dots , c_n) \in (\overline{\mathbb {F}_q}^*)^n : {\overline{F}}(c_1, \dots , c_n) = 0\}\end{aligned}$$

where \(\overline{\mathbb {F}_q}\) is an algebraic closure of \(\mathbb {F}_q\). We denote by \(V(\mathbb {F}_{q^r})\) the set of \(\mathbb {F}_{q^r}\)-rational points on V, i.e., the geometric points

$$\begin{aligned}\{(c_1, \dots , c_n) \in (\mathbb {F}_{q^r}^*)^n : {\overline{F}}(c_1, \dots , c_n) = 0\}.\end{aligned}$$

For \(q = p^a\), let \(\mathbb {Q}_q\) denote the unique unramified extension of degree a of \(\mathbb {Q}_p\), and let \(\mathbb {Z}_q\) denote the ring of integers of \(\mathbb {Q}_q\). Let \(\phi : \mathbb {F}_q \rightarrow \mathbb {F}_q\) be the absolute Frobenius map \(x \mapsto x^p\). We shall also denote by \(\phi \) the unique lift of the Frobenius map to a continuous ring automorphism \(\mathbb {Z}_q \rightarrow \mathbb {Z}_q\).

We now define maps \(\phi , \psi , T_H, A_H\) analogous to the maps \(\phi , \psi , T_H, A_H\) in [14, §3.1]. Define \(\phi , \psi : \mathbb {Z}_q[x^{\pm }] \rightarrow \mathbb {Z}_q[x^{\pm }]\) by

$$\begin{aligned}\phi (G) = \sum \limits _{u \in \mathbb {Z}^n} \phi ([G]_u) x^{pu}, \psi (G) = \sum \limits _{u \in \mathbb {Z}^n} \phi ^{-1}([G]_{pu}) x^u.\end{aligned}$$

For \(H \in \mathbb {Z}_q[x^{\pm }]\), let \(T_H : \mathbb {Z}_q[x^{\pm }] \rightarrow \mathbb {Z}_q[x^{\pm }]\) be the multiplication operator \(G \mapsto HG\), and let

$$\begin{aligned}A_H = \psi \circ T_{H^{p-1}}.\end{aligned}$$

Note that \(A_H\) is a \(\phi ^{-1}\)-semilinear map. For \(m \ge 1\), we also define

$$\begin{aligned}H^{(m)} = (H \cdot \phi (H) \cdots \phi ^{m-1}(H))^{p-1}. \end{aligned}$$

It is straightforward to check that

$$\begin{aligned}A_H^m = \psi ^m \circ T_{H^{(m)}}\end{aligned}$$

for any \(m \ge 1\), and that \(A_H\) maps \(P_{K}\) into \(P_{K}\) for \(K \supseteq \Delta (H)\). Note that \(A_H^a = \psi ^a \circ T_{H^{(a)}}\) is a linear map, it is not just \(\phi ^{-1}\)-semilinear.

The following theorem directly generalises [14, Thm.  3.1].

Theorem 2.1

Let \(K \subseteq \mathbb {R}^n\) be a convex polytope with integral vertices, and let \({\overline{F}} \in \mathbb {F}_q[x^{\pm }]\) be a non-zero Laurent polynomial with \(\Delta ({\overline{F}}) \subseteq K\). Let V be the hypersurface in \({\mathbb {T}}_{\mathbb {F}_q}^n\) cut out by \({\overline{F}}\). Let \(F \in \mathbb {Z}_q[x^{\pm }]\) be any lift of \({\overline{F}}\) with \(\Delta (F) \subseteq K\). Let \(r, \lambda , \tau \) be positive integers satisfying

$$\begin{aligned}\tau \ge \frac{\lambda }{(p-1)ar}.\end{aligned}$$

Then

$$\begin{aligned}|V(\mathbb {F}_{q^r}) | = (q^r-1)^n \sum \limits _{s = 0}^{\lambda + \tau - 1} \alpha _s \textrm{tr}(A_{F^s}^{ar}) \pmod {p^\lambda },\end{aligned}$$

where

$$\begin{aligned}\alpha _s = (-1)^s \sum \limits _{t=0}^{\tau -1} \left( {\begin{array}{c}-\lambda \\ t\end{array}}\right) \left( {\begin{array}{c}\lambda \\ s-t\end{array}}\right) \in \mathbb {Z},\end{aligned}$$

and where \(A_{F^s}^a\) is regarded as a linear operator on the \(\mathbb {Z}_q\)-module \(P_{sK}\).

Remark 2.2

Harvey mistakenly described the map \(A_{F^s}\) as a \(\mathbb {Z}_q\)-linear operator in [14, Thm.  3.1]. The map \(A_{F^s}^a\) is a \(\mathbb {Z}_q\)-linear operator, but in general \(A_{F^s}\) is only \(\phi ^{-1}\)-semilinear.

We do not give a proof of this theorem. The proof is identical to the one provided by Harvey for [14, Thm.  3.1], except that we remove all references to degree and replace them with the application of the results \(\Delta (G^s) = s \Delta (G)\) and \(\Delta (G_1 G_2) = \Delta (G_1) \oplus \Delta (G_2)\). The key idea of Harvey’s proof is to construct an indicator function J on \((\mathbb {Z}_{q^r}^*)^n\) that takes the value \(1 \in \mathbb {Z}/p^\lambda \mathbb {Z}\) if the input \(c \in (\mathbb {Z}_{q^r}^*)^n\) reduces mod p to a zero of \({\overline{F}}\), and takes the value 0 otherwise.

As in [14, Lem. 3.2], we now give a more computationally explicit description of \(A_{F^s}^{ar}\).

Lemma 2.3

Let \(F \in \mathbb {Z}_q[x^\pm ]\) be as in Theorem 2.1. The matrix of \(A_{F^s}^a\) on \(P_{sK}\), with respect to the basis \(\{x^u : u \in (sK)_\mathbb {Z}\}\), is given by

$$\begin{aligned}\phi ^{a-1}(M_s) \cdots \phi (M_s) M_s\end{aligned}$$

where \(M_s\) is the square matrix defined by

$$\begin{aligned}(M_s)_{v,u} = [F^{(p-1)s}]_{pv-u}\end{aligned}$$

for \(u,v \in (sK)_\mathbb {Z}\), and where \(\phi \) acts component-wise on matrices.

The proof of this lemma is identical to the one provided in [14]. The difference between our Theorem 2.1 and Lemma 2.3 and Harvey’s Theorem 3.1 and Lemma 3.2 is that Harvey works with homogeneous \({\overline{F}}\) in \(\mathbb {F}_q[x_0,\dots ,x_n]\) rather than Laurent polynomials in \(\mathbb {F}_q[x_1, x_1^{-1},\dots ,x_n, x_n^{-1}]\). In Harvey’s proof of Theorem 3.1, homogenous polynomials act as a convenient book-keeping device — the extra variable \(x_0\) serves as a way to keep track of relations between Newton polytopes. However, given that the trace formula counts points on a hypersurface in an affine torus it is in fact more appropriate to work with Laurent polynomials, and thus our Theorem 2.1 is a more natural way to state Harvey’s trace formula.

3 The algorithm

Let \(\mathbb {F}_q\), \({\overline{F}}\) and \({\widetilde{X}}\) be as in Theorem 1.1. Here we shall present an algorithm based on [14] that takes \({\overline{F}}\) as input and outputs \(Z({\widetilde{X}}, T)\). Our algorithm consists of two independent subroutines. The first subroutine counts the number of \(\mathbb {F}_{q^r}\)-rational points on the projective plane model X defined by \({\overline{F}}\) for \(r =1, \dots , g\); the second subroutine determines the errors \(|{\widetilde{X}}(\mathbb {F}_{q^r}) |- |X(\mathbb {F}_{q^r}) |\) for each r. We refer to the former subroutine as CountPlaneModel, and the latter as ComputeCorrections. We expect the asymptotic time complexity of CountPlaneModel to dominate that of ComputeCorrections.

3.1 Counting points on a plane model

Here we describe the CountPlane Model algorithm. It takes as input a non-zero polynomial \({\overline{F}} \in \mathbb {F}_q[x,y]\), a positive integer D, and a positive integer \(\lambda \). The polynomial \({\overline{F}}\) cuts out an affine plane curve \(X_0\), whose projective closure we denote by X. The algorithm outputs a list of the point-counts \(|X(\mathbb {F}_{q^r}) |\pmod {p^\lambda }\) for \(r = 1, \dots , D\).

The idea of the algorithm is to first count the points on \(X \cap {\mathbb {T}}^2\) by applying the trace formula from Theorem 2.1 to \({\overline{F}}\), followed by locating and counting the points on \(X \setminus {\mathbb {T}}^2\).

Given the input \({\overline{F}}, \lambda , D\), the first step in CountPlaneModel is to choose an \(F \in (\mathbb {Z}_q/p^\lambda \mathbb {Z}_q)[x,y]\) satisfying \(F \pmod p = {\overline{F}}\) and \(\Delta (F) = \Delta ({\overline{F}})\) to which we can apply the trace formula. Here the ring \(\mathbb {Z}_q/p^\lambda \mathbb {Z}_q\) is represented as \((\mathbb {Z}/p^\lambda \mathbb {Z})[t]/b\), where \(b \in (\mathbb {Z}/p^\lambda \mathbb {Z})[t]\) is a monic, degree a lift of the irreducible degree a polynomial \({\bar{b}} \in \mathbb {F}_p[t]\) defining the extension \(\mathbb {F}_q/\mathbb {F}_p\). In our application of the trace formula, we will ultimately evaluate

$$\begin{aligned} |(X \cap {\mathbb {T}}^2)(\mathbb {F}_{q^r}) |\pmod {p^\lambda } = (q^r-1)^2 \sum \limits _{s=0}^{S} \alpha _s \text {tr}(A_{F^s}^{ar}) \pmod {p^\lambda } \end{aligned}$$
(3.1)

for all \(r=1,\dots ,D\). In each of these sums we take \(S := \lambda + \tau -1\) with \(\tau := \lceil \lambda /(a(p-1)) \rceil \); by Theorem 2.1 this choice of \(\tau \) guarantees the correct result modulo \(p^\lambda \) for every \(r \in \mathbb {Z}^+\). We can do these evaluations of (3.1) efficiently in the manner described below — this is the same as what is described in [14, §3], with a slight modification to account for the fact that we are working with the Newton polygon \(\Delta (F)\) of F rather than the polygon \(\text {Conv}\{(0,0), (0,d), (d,0)\} \supseteq \Delta (F)\).

As in [14, §3], we iterate s over \(1,\dots ,S\): for each s we first construct the matrix \(M_s\) modulo \(p^\lambda \) where \(M_s\) is the matrix described in Lemma 2.3, then we compute the traces \(\text {tr}(A_{F^s}^{ar}) \pmod {p^\lambda }\) for \(r=1,\dots ,D\). We compute \(M_s\) by expanding \(F^{(p-1)s}\) and reading off coefficients at monomials \(pv-u\) where \(u,v \in s \Delta (F) \cap \mathbb {Z}^2\). We compute the traces \(\text {tr}(A_{F^s}^{ar}) \pmod {p^\lambda }\) for \(r=1,\dots ,D\) exactly as in [14, Lemma 3.4]. That is, we compute the matrix of \(A_{F^s}^a\) using a modified binary powering algorithm in accordance with Lemma 2.3, and we naively compute the required traces by computing D successive powers of that matrix. Having computed all of the required traces \(\text {tr}(A_{F^s}^{ar}) \pmod {p^\lambda }\) for \(1 \le r \le D\) and \(1 \le s \le S\), we iterate r over \(1, \dots , D\) and use (3.1) to compute \(|(X \cap {\mathbb {T}}^2)(\mathbb {F}_{q^r}) |\pmod {p^\lambda } \) for each r.

Computing \(|(X \setminus {\mathbb {T}}^2)(\mathbb {F}_{q^r}) |\pmod {p^\lambda }\) for \(r=1,\dots ,D\) can be done by factoring three univariate polynomials over \(\mathbb {F}_q\). We count the points on X in \({\mathbb {P}}^2 \setminus {\mathbb {T}}^2\) by factoring the polynomials \({\overline{F}}_0, {\overline{F}}_1, {\overline{F}}_2 \in \mathbb {F}_q[t]\) defined by \({\overline{F}}_0(t) := {\overline{F}}_{h}(t, 1, 0)\), \({\overline{F}}_1(t) := {\overline{F}}_h(0,t,1)\), and \({\overline{F}}_2(t) := {\overline{F}}_h(1,0,t)\), where \({\overline{F}}_h \in \mathbb {F}_q[x_0, x_1, x_2]\) denotes the homogenisation of \({\overline{F}}\).

For simplicity of exposition we have described an unoptimised version of the CountPlaneModel algorithm, whose time complexity has a dependence in p of \(p^{2+o(1)}\) rather than \(p^{\frac{1}{2} + o(1)}\). To achieve the time complexity stated in Theorem 1.1, one can use the deformation recurrence technique from [14, §4] to compute the required matrices \(M_s\) rather than using the naive approach of expanding powers of F and reading off the required coefficients. Another optimisation arises from using an individual precision \(\lambda _r\) and upper limit \(S_r\) for each r rather than the global precision \(\lambda \) and upper limit \(S = \lambda + \lceil \lambda /(a(p-1)) \rceil - 1\).

The most computationally expensive parts of applying the algorithm described above are: (1) the computation of the coefficients of the powers \(F^{(p-1)s}\) that are required to construct the matrices \(M_s\), and (2) the computation of the matrix powers \(A_{F^s}^{ar}\) and their traces. On (2), note that the dimension of the matrix \(M_s\) is roughly \(s^2 \text {vol}(\Delta (F))\) as by construction the matrix \(M_s\) has dimension equal to the number of integral points in \(s \Delta (F)\), and in \(\mathbb {R}^2\) the polygon \(s \Delta (F)\) has \(s^2\) times the volume of \(\Delta (F)\).

3.2 Computing corrections for miscounted points

Here we describe the ComputeCorrections algorithm. It takes as input an absolutely irreducible polynomial \({\overline{F}} \in \mathbb {F}_q[x,y]\) of degree \(d \ge 2\) and a positive integer D, and it outputs a list of the differences \(|{\widetilde{X}}(\mathbb {F}_{q^r}) |- |X(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,D\), where X is the projective closure of the affine plane curve cut out by \({\overline{F}}\).

The idea of the algorithm is to reduce the problem of computing the differences \(|{\widetilde{X}}(\mathbb {F}_{q^r}) |- |X(\mathbb {F}_{q^r}) |\) to the problem of counting points on \({\widetilde{X}}\) and X above a certain set of points on \({\mathbb {P}}^1\). To do this, we rely on the following theorem.

Theorem 3.1

Let \(\pi : {\widetilde{X}} \rightarrow X\) be the normalisation of X. Let S be the singular subscheme of X. Let Z be any subscheme of X containing S, and let \({\widetilde{Z}} = \pi ^{-1}(Z)\). Then we have

$$\begin{aligned}|{\widetilde{X}}(\mathbb {F}_{q^r}) |- |X(\mathbb {F}_{q^r}) |= |{\widetilde{Z}}(\mathbb {F}_{q^r}) |- |Z(\mathbb {F}_{q^r}) |.\end{aligned}$$

Sketch proof

Theorem 3.1 follows from: (1) the fact that for any closed point \({\mathfrak {p}}\) on X, we have

$$\begin{aligned}\widetilde{\mathcal {O}_{X, \, {\mathfrak {p}} }} = \bigcap \limits _{{\mathfrak {q}} \in \pi ^{-1}({\mathfrak {p}})} \mathcal {O}_{{\widetilde{X}}, \, {\mathfrak {q}} }\end{aligned}$$

where \(\mathcal {O}_{X, \, {\mathfrak {p}} } \subseteq \mathbb {F}_q({\widetilde{X}})\) is the ring of rational functions on X that are regular at \({\mathfrak {p}}\), \(\widetilde{\mathcal {O}_{X, \, {\mathfrak {p}} }}\) is the integral closure in \(\mathbb {F}_q({\widetilde{X}})\) of that ring, and \(\mathcal {O}_{{\widetilde{X}}, \, {\mathfrak {q}} } \subseteq \mathbb {F}_q({\widetilde{X}})\) is the ring of rational functions on \({\widetilde{X}}\) that are regular at \({\mathfrak {q}}\) [22, Thm. III.2.6], and (2) the fact that \(\mathcal {O}_{X, \, {\mathfrak {p}} }\) is integrally closed if \({\mathfrak {p}}\) is a nonsingular closed point on X [18, Prop. VII.2.6]. \(\square \)

We will compute the differences by choosing a subscheme Z of X containing S and counting points on both Z and \({\widetilde{Z}} = \pi ^{-1}(Z)\). Our ComputeCorrections algorithm will consist of three subroutines: ComputeY, CountPointsOnZ and CountPointsAboveZ, which we describe below.

3.2.1 Counting points on Z

Let \(a_0(x), \dots , a_n(x)\) be the coefficients of \({\overline{F}}\) when regarded as a polynomial in y over \(\mathbb {F}_q[x]\), i.e., when we write \({\overline{F}} = a_n(x) y^n + \dots + a_0(x)\) with \(a_n(x) \ne 0\). Let \(X_0\) be the affine plane curve cut out by \({\overline{F}}\), and let \(S_0\) be the singular subscheme of \(X_0\). Let \(\varphi : X_0 \rightarrow {\mathbb {A}}^1\) be the morphism of curves \((x,y) \mapsto x\). Let A be the closed set of \({\mathbb {A}}^1\) where \(a_n(x)\) vanishes.

We define subschemes \(Y_0, Y\) of \({\mathbb {P}}^1\) and \(Z_0, Z\) of X as follows:

$$\begin{aligned} \begin{aligned} Y_0&:= \varphi (S_0) \cup A, \\ Z_0&:= \varphi ^{-1}(Y_0), \\ Y&:= Y_0 \cup \{\infty \}, \\ Z&:= Z_0 \cup (X \setminus X_0).\\ \end{aligned} \end{aligned}$$
(3.2)

That is, the points of \(Y_0\) are the x-coordinates of singular points on \(X_0\) together with the x-coordinates of “vertical asymptotes” of \(X_0\). The points on \(Z_0\) are those points on \(X_0\) that share an x-coordinate with a singular point, along with those points at which \(a_n(x)\) vanishes. The points on \(Z \subseteq X\) are all of the points on \(Z_0 \subseteq X_0\) together with all of the points on \(X \setminus {\mathbb {A}}^2 \subseteq {\mathbb {P}}^2\). Note that by construction, Z contains S. An illustration of the schemes \(Z_0\) and \(Y_0\) is shown below in Fig. 1.

Fig. 1
figure 1

An example showing \(Y_0 \subseteq {\mathbb {A}}^1\) (black square) and \(Z_0 \subseteq X_0\) (black circle)

Based on the discussion above we now introduce the subroutine ComputeY. It takes as input the polynomial \({\overline{F}}\) and outputs a list of irreducible polynomials in \(\mathbb {F}_q[x]\) representing the closed set \(Y_0 \subseteq {\mathbb {A}}^1\). This subroutine amounts to finding the distinct irreducible factors of the polynomial \(a_n(x) \cdot \gcd (\text {res}_y({\overline{F}}, \frac{\partial {\overline{F}}}{\partial y}), \, \text {res}_y({\overline{F}}, \frac{\partial {\overline{F}}}{\partial x} ) )\). Note that \(\text {res}_y(\cdot , \cdot )\) denotes the resultant where the polynomials are regarded as univariate polynomials in y whose coefficients are polynomials in x, and hence the set of roots of \(\gcd (\text {res}_y({\overline{F}}, \frac{\partial {\overline{F}}}{\partial y}), \, \text {res}_y({\overline{F}}, \frac{\partial {\overline{F}}}{\partial x} ) )\in \mathbb {F}_q[x]\) includes all of the x-coordinates of common zeroes of \({\overline{F}}, \frac{\partial {\overline{F}}}{\partial x}\) and \(\frac{\partial {\overline{F}}}{\partial y}\), i.e., it includes the x-coordinates of singular points on \(X_0\).

The algorithm CountPointsOnZ takes as input the polynomial \({\overline{F}}\), the list of irreducible polynomials representing \(Y_0\), and a positive integer D, and outputs the list of point-counts \(|Z(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,D\). CountPointsOnZ obtains the desired list of point-counts by:

  1. (1)

    counting the points on \(Z \cap {\mathbb {A}}^2 = Z_0\) by computing the distinct factors in the factorisation of \({\overline{F}}\) modulo each of the irreducibles in \(\mathbb {F}_q[x]\) that represent \(Y_0\), and

  2. (2)

    counting the points on \(Z \setminus {\mathbb {A}}^2 = X \setminus {\mathbb {A}}^2\) by computing the distinct factors in the factorisation of the degree d homogeneous part of \({\overline{F}}\).

More precisely, we count points on \(Z_0\) by constructing the field \(\mathbb {F}_q[x]/{\bar{h}}(x)\) for each irreducible \({\bar{h}} \in \mathbb {F}_q[x]\) representing \(Y_0\), then factoring the univariate in y polynomial \({\overline{F}} \pmod {{\bar{h}}}\) over \(\mathbb {F}_q[x]/{\bar{h}}(x)\); each distinct irreducible factor in such a factorisation corresponds to a \(\text {Gal}(\overline{\mathbb {F}_q}/\mathbb {F}_q)\)-orbit of points on \(X_0\) whose x-coordinates are roots of \({\bar{h}}(x)\).

3.2.2 Counting points on \({\widetilde{Z}}\)

Let \({\widetilde{\varphi }} : {\widetilde{X}} \rightarrow {\mathbb {P}}^1\) be the morphism of curves defined by the rational function \(x \in \mathbb {F}_q(x)[y]/\langle {\overline{F}} \rangle \). Note that when \({\overline{F}}\) is absolutely irreducible and of degree \(d \ge 2\) this morphism is surjective.

The following proposition allows us to count points on \({\widetilde{Z}} = \pi ^{-1}(Z)\) by counting the points on \({\widetilde{X}}\) that lie above the scheme \(Y \subseteq {\mathbb {P}}^1\) defined in  (3.2).

Proposition 3.2

The subscheme \({\widetilde{Z}} = \pi ^{-1}(Z)\) of \({\widetilde{X}}\) satisfies

$$\begin{aligned}{\widetilde{Z}} = {\widetilde{\varphi }}^{\,-1}(Y).\end{aligned}$$

Sketch proof

We claim that if \({\mathfrak {q}} \in {\widetilde{X}}\) satisfies \(\pi ({\mathfrak {q}}) \in X_0\) then \({\widetilde{\varphi }}({\mathfrak {q}}) = \varphi (\pi ({\mathfrak {q}}))\), otherwise if \(\pi ({\mathfrak {q}}) \not \in X_0\) then \({\widetilde{\varphi }}({\mathfrak {q}}) \in A \cup \{\infty \}\). The equality \({\widetilde{\varphi }}({\mathfrak {q}}) = \varphi (\pi ({\mathfrak {q}}))\) for \(\pi ({\mathfrak {q}}) \in X_0\) follows from the fact that the morphisms \(\varphi \) and \({\widetilde{\varphi }}\) are induced by the same rational function \(x \in \mathbb {F}_q(x)[y]/\langle {\overline{F}} \rangle \); this is illustrated below in Fig. 2. The inclusion \({\widetilde{\varphi }}(\pi ^{-1}(X \setminus X_0)) \subseteq \{\infty \} \cup A\) follows from: (1) if \(\frac{1}{x}\) vanishes at \({\mathfrak {p}} = \pi ({\mathfrak {q}})\) then \({\widetilde{\varphi }}({\mathfrak {q}}) = \infty \), and (2) if \(\frac{1}{x}\) does not vanish at \({\mathfrak {p}}= \pi ({\mathfrak {q}})\) but \(\frac{1}{y}\) does vanish at \({\mathfrak {p}}\), then \(\frac{1}{y} \in {\mathfrak {m}}_{{\widetilde{X}},\, {\mathfrak {q}}}\), and since \(a_n(x) y\) is integral over \(\mathbb {F}_q[x]\) it follows that \(a_n(x) \in {\mathfrak {m}}_{{\mathbb {P}}^1, \, {\widetilde{\varphi }}({\mathfrak {q}})}\). \(\square \)

Fig. 2
figure 2

An example showing \({\widetilde{\varphi }} = \varphi \circ \pi \)

To count the points on \({\widetilde{X}}\) lying above Y, we rely on the Montes algorithm [13], which we shall refer to as Montes. For details on the time complexity of Montes see [2]. Montes takes as input a monic irreducible separable polynomial \({\overline{F}} \in \mathbb {F}_q[x][y]\) defining the function field \(\mathbb {F}_q(x)[y]/\langle {\overline{F}} \rangle \) and an irreducible polynomial \({\bar{h}}(x) \in \mathbb {F}_q[x]\), and outputs the list of closed points on \({\widetilde{X}}\) that lie above the closed point defined by \({\bar{h}}(x)\) on \({\mathbb {A}}^1 = \text {Spec}(\mathbb {F}_q[x])\).

Note that in Theorem 1.1 we do not assume that the input \({\overline{F}}\) is monic in y, but Montes does require an input which is monic in y. Fortunately this is not an issue as it will suffice to apply Montes to the polynomial \({\overline{F}}' = y^n + a_{n-1}(x) y^{n-1} + \dots + a_0(x) a_n(x)^{n-1}\) instead. This works because \({\overline{F}}\) and \({\overline{F}}'\) define the same extension of \(\mathbb {F}_q(x)\) via the isomorphism \(y \mapsto a_n(x) y\).

The algorithm CountPointsAboveZ takes as input the polynomial \({\overline{F}}\), the list of irreducible polynomials representing \(Y_0\) and a positive integer D, and outputs the list of point-counts \(|{\widetilde{Z}}(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,D\). In accordance with Proposition 3.2, CountPointsAboveZ obtains the desired list of point-counts by:

  1. (1)

    counting the points on \({\widetilde{\varphi }}^{-1}(Y_0)\) via applying Montes to \({\overline{F}}'\) for each of the irreducibles \({\bar{h}}(x)\) in \(\mathbb {F}_q[x]\) that represent \(Y_0\), and

  2. (2)

    counting the points on \({\widetilde{\varphi }}^{-1}(\infty )\) via applying Montes to a polynomial \({\overline{F}}''\) and \({\bar{h}}(x) = x\), where \({\overline{F}}''\) is the polynomial that we get from \({\overline{F}}'\) via the change of variables \((x,y) \mapsto (\frac{1}{x}, \frac{y}{x^{m}})\) with \(m := \deg _x({\overline{F}}')\).

3.2.3 Computing the corrections

We can now describe the algorithm ComputeCorrections. Given the input \({\overline{F}} \in \mathbb {F}_q[x,y]\) and D, the algorithm first runs the subroutine ComputeY to obtain a representation L of the points in \(Y \subseteq {\mathbb {P}}^1\). It then runs the subroutines CountPointsOnZ and CountPointsAboveZ with arguments \({\overline{F}}, D\) and L to obtain the point-counts \(|Z(\mathbb {F}_{q^r}) |\) and \(|{\widetilde{Z}}(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,D\), from which we obtain the differences \(|{\widetilde{X}}(\mathbb {F}_{q^r}) |- |X(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,D\) by computing \(|{\widetilde{X}}(\mathbb {F}_{q^r}) |- |X(\mathbb {F}_{q^r}) |= |{\widetilde{Z}}(\mathbb {F}_{q^r}) |- |Z(\mathbb {F}_{q^r}) |\) in accordance with Theorem 3.1.

3.3 The main algorithm

We may now outline an efficient algorithm for computing \(Z({\widetilde{X}}, T)\). Given an absolutely irreducible \({\overline{F}} \in \mathbb {F}_q[x,y]\) of degree \(d \ge 2\), we can compute the genus g of \(\mathbb {F}_q(x)[y]/\langle {\overline{F}} \rangle \) using existing efficient algorithms [15]. From the Weil conjectures, we have the Hasse–Weil bound

$$\begin{aligned} \big |q^{r}+1 - |{\widetilde{X}}(\mathbb {F}_{q^r}) |\big |\le 2g q^{r/2}, \end{aligned}$$
(3.3)

hence we can recover the value \(| {\widetilde{X}}(\mathbb {F}_{q^r}) |\) from its reduction modulo any integer strictly larger than \(4gq^{r/2}\). Based on this, we take \(\lambda = \lceil \log _p(4g q^{g/2} + 1) \rceil \), and run CountPlaneModel with arguments \({\overline{F}}\), \(\lambda \) and g. We get a list of point-counts \(|X(\mathbb {F}_{q^r}) | \pmod {p^\lambda }\) for \(r=1,\dots ,g\) as output. We then run ComputeCorrections with arguments \({\overline{F}}\) and g to obtain a list of the differences \(|{\widetilde{X}}(\mathbb {F}_{q^r}) | - |X(\mathbb {F}_{q^r}) |\) for \(r=1,\dots ,g\). Adding these lists together modulo \(p^\lambda \) gives us the point-counts \(|{\widetilde{X}}(\mathbb {F}_{q^r}) | \pmod {p^\lambda }\) for \(r=1,\dots ,g\). We then recover the exact values \(|{\widetilde{X}}(\mathbb {F}_{q^r}) | \in \mathbb {Z}\) using (3.3). From the power series expansion of

$$\begin{aligned}(1-T)(1-qT) \exp \left( \sum \limits _{r=1}^g \frac{|{\widetilde{X}}(\mathbb {F}_{q^r}) |}{r} T^r \right) \end{aligned}$$

we obtain the coefficients of the numerator of \(Z({\widetilde{X}}, T)\) up to the monomial \(T^g\). We obtain the remaining coefficients by using the functional equation  (1.1) for \(Z({\widetilde{X}}, T)\).

4 Implementation and examples

We have implemented the algorithm described in this paper for prime fields \(\mathbb {F}_p\) in the computer algebra system MAGMA [5]. We have implemented a version with time complexity \(p^{2 + o(1)} d^{O(1)}\). Note that this differs from the time complexity given in Theorem 1.1 — the dependence in p here is \(p^2\) instead of \(p^{1/2}\). The reason for this difference is that the current implementation involves computing the polynomials \(F^{(p-1)s}\) mentioned in Lemma 2.3 instead of using the deformation-recurrence technique from [14] to obtain only the coefficients that we need. In the future we hope to make available an updated implementation which incorporates the deformation-recurrence technique and which works for arbitrary finite fields \(\mathbb {F}_q\).

In this section we present and discuss data we have collected about the implementation of our algorithm and the MAGMA implementation of Tuitman’s algorithm. In Sect. 4.1 we provide examples comparing the runtime of our code to that of the MAGMA implementation of Tuitman’s algorithm, and in Sect. 4.2 we present some data on example computations of our code on inputs that cannot be readily dealt with by existing methods.

Our implementation takes as input an absolutely irreducible \({\overline{F}} \in \mathbb {F}_p[x,y]\). Tuitman’s implementation takes as input a pair (Fp) where \(F \in K[x,y]\), F is monic in y, p is a prime, and K is a number field in which p is inert. The polynomial F fed into Tuitman’s code must define a “good” lift of the curve defined by \(F \pmod p\) over the field \(\mathbb {Z}_K/p \mathbb {Z}_K\), i.e., F must define a lift satisfying [23, Ass. 1]. Tuitman’s algorithm has time complexity \({\widetilde{O}}(p d_x^6 d_y^4 a^3 )\), where \(a = [\mathbb {Z}_K / p \mathbb {Z}_K : \mathbb {Z}/p\mathbb {Z}]\), \(d_y\) is the degree of F in x, and \(d_x\) is the degree of F in y.

As mentioned in the introduction, the main advantage of our algorithm over Tuitman’s is that it does not require the computation of a “good” lift of an input \({\overline{F}} \in \mathbb {F}_q[x,y]\) to characteristic zero. Our code is capable of handling arbitrary absolutely irreducible inputs \({\overline{F}} \in \mathbb {F}_p[x,y]\), including those for which one cannot readily compute a lift \(F \in \mathbb {Q}[x,y]\) of \({\overline{F}}\) satisfying Assumption 1 of [23]. Furthermore, even when it is feasible to compute a good lift of an input \({\overline{F}}\), the lift one obtains may have properties that cause Tuitman’s code to run slowly when compared to the execution of our code on the original \({\overline{F}}\).

The inputs \({\overline{F}}\) for which our code is most likely to outperform Tuitman’s are those where \({\overline{F}}\) does not meet Baker’s bound on the genus [3, Thm. 2.4], i.e., inputs \({\overline{F}}\) for which the geometric genus of the curve defined by \({\overline{F}}\) is strictly less than the number of integral interior points of \(\Delta ({\overline{F}})\). Note that these are precisely those \({\overline{F}}\) that define a singular curve in the projective toric surface associated with \(\Delta ({\overline{F}})\). When \({\overline{F}}\) meets Baker’s bound, one can almost always take a naive Newton polygon preserving lift of \({\overline{F}}\) to obtain a good lift for Tuitman’s algorithm [6, §2.2].

When \({\overline{F}}\) does not meet Baker’s bound, determining a lift satisfying [23, Ass. 1] is a difficult problem. In some cases this problem can be dealt with by using the methods of [6] or [7]—these methods apply to inputs \({\overline{F}}\) that define curves of geometric genus at most 5 or whose Newton polygon \(\Delta ({\overline{F}}) \) has lattice width at most 5. The width of a convex polytope \(K \subseteq \mathbb {R}^n\) along a direction \({\textbf{d}} \in {\mathbb {R}}^n\) is defined to be

$$\begin{aligned}w_{{\textbf{d}}}(K) = \max \limits _{{\textbf{x}} \in K} {\textbf{d}} \cdot {\textbf{x}} - \min \limits _{{\textbf{x}} \in K} {\textbf{d}} \cdot {\textbf{x}}.\end{aligned}$$

The lattice width of a convex polytope \(K \subseteq \mathbb {R}^n\) with integral vertices is defined to be

$$\begin{aligned}\text {lw}(K) = \min \limits _{ \mathbf {d \in \mathbb {Z}^n \setminus \{{\textbf{0}} \}}} \,\, w_{{\textbf{d}}}(K).\end{aligned}$$

For \(K \subseteq \mathbb {R}^2\) one can equivalently define the lattice width as the minimal height of a horizontal strip inside which K can be mapped by a unimodular transformation.

The timings obtained in this section were obtained using MAGMA V2.25-7 on a computer with an Nvidia RTX 3090 GPU and an Intel Core i9-12900K CPU with 128GB of memory running Ubuntu 20.04. These timings show what is achievable in practice when running a straightforward MAGMA implementation of our algorithm on high-end consumer hardware. The MAGMA supported linear algebra on an RTX 3090 GPU allows for very fast matrix multiplication, making it feasible to apply our algorithm to a large range of curves.

It should be noted that the MAGMA implementation of Tuitman’s algorithm may be able to be significantly improved. Improvements that appeared in MAGMA V2.25-7 were made by MAGMA developer Allan Steel after being sent test inputs from the present author that were found during the writing of this paper. An advantage of our algorithm (particularly the subroutine CountPlaneModel) is that it is comparatively simple and straightforward to implement, and its current implementation has the potential to be sped up substantially through simple low-level optimisations.

The code for the implementation of our algorithm is available at https://github.com/Maddels/zeta_function_. Along with the implementation of our algorithm we provide code for testing the correctness of the output that our code produces. The functions provided for testing correctness do not guarantee that the output is correct — failing a test indicates that an error has occurred; passing a test gives partial evidence that the output is consistent with the correct result. We test for correctness by: (1) comparing the point-count that is predicted by the output zeta function for an extension \(\mathbb {F}_{p^{i}}\) where \(i > g\) with the point-count that is computed by applying the trace formula (2.1) for the extension \(\mathbb {F}_{p^i}\), and (2) comparing the point-counts that are predicted by the output zeta function for small extensions \(\mathbb {F}_{p^{i}}\) with point-counts that are computed by naive enumeration. These tests were applied for each of the inputs appearing in Sect. 4.2. Correctness was checked for the inputs in Sect. 4.1 by comparing the output obtained by our implementation to the output obtained by the MAGMA implementation of Tuitman’s algorithm.

4.1 Comparison with Tuitman’s algorithm

We now provide examples where we compare the runtime of our implementation with that of the MAGMA implementation of Tuitman’s algorithm. More precisely, we compare the runtime of our algorithm on an input \({\overline{F}}\) against the combined time of computing a “good” lift F of \({\overline{F}}\) followed by running Tuitman’s algorithm on input F. For the examples below, we further provide a breakdown of the runtime of both implementations into the runtimes of their key steps. For our implementation, the key steps are:

  1. (A1)

    Computing the powers \(F^{(p-1)s}\) needed for the construction of the matrices \(M_s\).

  2. (A2)

    Computing the matrix powers \(M_s^r\) and their traces.

  3. (A3)

    All other required computations in the algorithm, including computing the corrections to the point-counts for the plane model.

For the MAGMA implementation of Tuitman’s algorithm combined with lifting to obtain a valid input for Tuitman’s code, the key steps are:

  1. (B1)

    Computing a good lift F of \({\overline{F}}\) to feed into Tuitman’s algorithm.

  2. (B2)

    Computing the objects \(\Delta , r(x), s(x,y), W^0, W^\infty , G^0, G^\infty \) described in [23, §2].

  3. (B3)

    Computing the basis of \(H^1({\widetilde{X}})\).

  4. (B4)

    Computing the Frobenius lift.

  5. (B5)

    Computing reduction matrices.

  6. (B6)

    Computing the Frobenius matrix, from which the zeta function is computed by computing the characteristic polynomial.

Note that steps (B3)–(B6) above correspond to steps I–IV described in [23]. To perform (B1) for a given \({\overline{F}}\), we used MAGMA implementations of the methods described in [6, 7], and when those methods were not applicable we instead tried computing a lift whose singular points are lifts of the singular points on the input plane model. That is, for an input \({\overline{F}}\) to which the methods of [6, 7] do not apply, we attempted to compute an \(F \in \mathbb {Z}[x,y]\) that: (1) reduces mod p to \({\overline{F}}\), and (2) defines a plane curve over \(\mathbb {Q}\) whose singularities reduce mod p to the singularities of X. This method does not guarantee a lift satisfying [23, Ass. 1], but in the case where the input \({\overline{F}}\) defines a nodal plane curve we often succeed in finding such a lift.

Below we present the runtimes for a selection of 10 inputs \({\overline{F}}\) that have a variety of features. These 10 inputs along with our code for performing step (B1) can be found on the webpage https://github.com/Maddels/zeta_function_ in the MAGMA files runtime_comparison_examples.m and lift_curve.m. Inputs 1 and 2 are examples that were made available by Tuitman at the webpage https://github.com/jtuitman/pcc/blob/master/pcc_p/example_p.m, inputs 3 and 4 were the examples explicitly given in [7, §6] for \(d=4\) and \(d=5\), input 5 was generated by specifying its Newton polygon and singular behaviour, and the remaining 5 inputs were generated using the MAGMA function RandomCurveByGenus.

Table 1 gives information on the nature of these inputs \({\overline{F}}\) and the curves they define, as well as which lifting strategy was applied for each input. In Table 1 we denote a naive lift by N, a lift obtained using the methods of [6] by CT, a lift obtained using the methods of [7] by CV, and a singular-point-preserving lift by S. Table 2 gives information on the runtime and memory usage of the implementations of each algorithm on each of these inputs, and Table 3 provides a breakdown of these runtimes into steps A1-A3 and B1-B6. In Table 2 we denote the new algorithm by HK, and Tuitman’s algorithm by T. If the runtime for an example exceeded 12 hours then the computation was terminated, with information provided on the runtimes of completed key steps up until the point of termination.

Table 1 Inputs for runtime comparison
Table 2 Runtime and memory comparison
Table 3 HK and T runtime breakdown (in seconds)

4.2 Examples presently beyond Tuitman’s algorithm

We now provide example computations of our algorithm on inputs \({\overline{F}}\) that cannot be readily dealt with by existing methods. We selected our examples based on the lifting strategies described in §4.1, in the sense that we selected examples for which these methods cannot be readily applied. One important consideration in the selection of our examples was the lattice width of the Newton polygon \(\Delta {\overline{F}}\). We selected inputs \({\overline{F}}\) for which it is difficult (or impossible) to find a polynomial \({\bar{G}} \in \mathbb {F}_q[x,y]\) that both satisfies \(\text {lw}(\Delta ({\bar{G}})) \le 5\) and defines the same nonsingular curve as \({\overline{F}}\).

The arithmetic gonality of a curve \({\widetilde{X}}\) over \(\mathbb {F}_q\) is the minimal degree of the extension \(\mathbb {F}_q({\widetilde{X}})/\mathbb {F}_q(\alpha )\) over all \(\alpha \in \mathbb {F}_q({\widetilde{X}}) \setminus \mathbb {F}_q\). In the case where \(g({\widetilde{X}}) \ge 1\), the arithmetic gonality of \({\widetilde{X}}\) coincides with the minimum lattice width \(\text {lw}(\Delta ({\bar{G}}))\) among all \({\bar{G}} \in \mathbb {F}_q[x,y]\) that define a function field isomorphic to \(\mathbb {F}_q({\widetilde{X}})\).

We chose examples \({\overline{F}}\) with \(\text {lw}(\Delta ({\overline{F}})) \ge 6\) and \(g({\widetilde{X}}) \ge 9\) as these are likely to have arithmetic gonality exceeding 5, in which case it would be impossible to find a polynomial \({\bar{G}} \in \mathbb {F}_q[x,y]\) defining the same function field as \({\overline{F}}\) to which the methods of [7] apply. The restriction \(g({\widetilde{X}}) \ge 9\) is based on the statements about gonality given in [6, §2.1]. The \(\overline{\mathbb {F}_q}\)-gonality (i.e., geometric gonality) of a curve over \(\overline{\mathbb {F}_q}\) of genus \(g \ge 2\) must lie in the range \(2, \dots , \lceil g/2 \rceil + 1\), and inside the moduli space \({\mathcal {M}}_g\) of curves of genus g the dimension of the locus of curves having fixed \(\overline{\mathbb {F}_q}\)-gonality \( \gamma \in \{2,\dots ,\lceil g/2 \rceil + 1\}\) is \(\min \{2g + 2 \gamma -5, 3g-3\}\) — here we are assuming as in [6] that this result holds in finite characteristic as well as over \(\mathbb {C}\). Thus for \(g \ge 9\) the dimension of a locus of curves with an \(\overline{\mathbb {F}_q}\)-gonality of \(\gamma \le 5\) in \({\mathcal {M}}_g\) is strictly smaller than that of a locus of curves with an \(\overline{\mathbb {F}_q}\)-gonality of \(\gamma \in \{6,\dots , \lceil g/2 \rceil + 1\}\).

Furthermore, even for those \({\overline{F}}\) that define a curve \({\widetilde{X}}\) of genus \(g({\widetilde{X}}) \ge 9\) with arithmetic gonality at most 5, if the lattice width of \(\Delta ({\overline{F}})\) exceeds 5 then establishing that the curve has smaller gonality is a difficult problem. One can use the algorithm from [20] to compute geometric gonality, but as explained in [12] this becomes impractical beyond genus 7, and even if the geometric gonality is at most 5 it may be the case that the arithmetic gonality is larger.

Another important consideration in the selection of examples \({\overline{F}}\) was the singular nature of the associated plane curve X. We chose examples with complicated singular behaviour, in particular those with non-ordinary singularities. For these inputs it should be more difficult to compute a lift F of \({\overline{F}}\) that defines a curve of equal genus.

Ultimately, we selected examples \({\overline{F}} \in \mathbb {F}_p[x,y]\) with the following properties:

  • \(\text {lw}(\Delta ({\overline{F}})) \ge 6\),

  • \(g({\widetilde{X}}) \ge 9\),

  • \({\overline{F}}\) does not meet Baker’s bound,

  • the plane curve cut out by \({\overline{F}}\) has non-ordinary singularities,

  • the naive lift \(F \in \mathbb {Z}[x,y]\) of \({\overline{F}}\), obtained by lifting each coefficient \({\bar{c}} \in \mathbb {F}_p\) of \({\overline{F}}\) to an integer \(0 \le c < p\), defines a curve over \(\mathbb {Q}\) of genus larger than \(g({\widetilde{X}})\).

In Table 5 we present the runtimes of our implementation on a selection of 7 inputs having the above properties. All of the inputs below have a Newton polygon of the form \(\text {Conv}\{(0,0), (0,w), (v w, 0)\}\) where \(w \ge 6\) and \(v \ge 2\). These examples were found by random search among polynomials that: (1) have a Newton polygon that is equal to a specified convex polygon of the form \(\text {Conv}\{(0,0), (0,w), (v w, 0)\}\), and (2) define a curve with specified singular behaviour (e.g. having a non-ordinary singularity that takes several blow-ups to resolve). These 7 inputs can be found on the webpage https://github.com/Maddels/zeta_function_ in the MAGMA file examples_beyond_tuitman.m (https://github.com/Maddels/zeta_function_/blob/main/examples_beyond_tuitman.m).

Table 4 Input curves
Table 5 Runtime and memory usage