WorksComputer Science
Class Numbers of Imaginary Quadratic Orders in the Polynomial Hierarchy
Abstract
For with , let be the number of classes of primitive positive definite binary quadratic forms of discriminant . We prove that is computable in deterministic polynomial time with an oracle for a language in the second level of the polynomial hierarchy. The proof uses only reduction theory of binary quadratic forms, Lagrange's theorem and Hermite normal forms; it does not assume the generalized Riemann hypothesis, does not take a generating set of the class group as input, and uses no randomness. A oracle finds a generating set of forms, and an NP oracle then determines the lattice of relations, whose index is . Consequently, if , class numbers of imaginary quadratic fields are computable in polynomial time. As an application, the number of representations of by the ternary form in Tunnell's congruent number criterion equals for square-free and vanishes for square-free ; hence lies in on even square-free , and an exact counting reduction from to would collapse the polynomial hierarchy to .
Introduction
For an integer with , let be the number of -classes of primitive positive definite binary quadratic forms of discriminant ; when is a fundamental discriminant, is the class number of . Computing from the binary encoding of is a classical problem of computational number theory. Shanks’s baby-step giant-step method and its refinements compute it in time exponential in [1]; under the generalized Riemann hypothesis (GRH), Hafner and McCurley gave a subexponential algorithm [2]; and under GRH the class group is generated by forms of norm [3], so that Watrous’s quantum algorithm for the order of a solvable black-box group [4] computes in quantum polynomial time.
The form class group is an abelian group whose elements have unique polynomial-size encodings, the reduced forms, and whose operation is computable in polynomial time. For black-box groups given by a list of generators, Babai and Szemerédi [5] proved that membership lies in NP, and Babai [6] proved that order verification lies in AM coAM. These results take a generating set as part of the input. No small generating set of is known to be computable without GRH.
In this paper we prove that is computable in deterministic polynomial time with an oracle for a language in (Theorem 3.1). The proof is elementary: it uses only reduction theory of binary quadratic forms, Lagrange’s theorem, and Hermite normal forms of integer matrices. It does not assume GRH, does not take a generating set as input, and uses no interactive proofs or randomness. Its consequences are the following.
If P = NP, then class numbers of imaginary quadratic orders are computable in deterministic polynomial time (Corollary 3.2).
Let be the number of representations of by the ternary form that appears in Tunnell’s congruent number criterion [7]. For square-free one has (Proposition 4.2), and for square-free (Lemma 4.1). Hence on even square-free lies in (Corollary 4.3).
An exact counting reduction from #SAT to , computable in polynomial time with an NP oracle, would imply and, by Toda’s theorem [8], the collapse of the polynomial hierarchy to (Theorem 4.4). Thus, unless the polynomial hierarchy collapses, Tunnell’s count cannot carry #P-hardness, although it is a #P function of .
Section 2 fixes notation. Section 3 proves the main theorem and its first consequences. Section 4 applies it to Tunnell’s count. Section 5 relates the results to prior work, and Section 6 concludes.
Preliminaries
For an integer we write for its bit length. and are levels of the polynomial hierarchy PH; for a class of languages, is the class of functions computable in deterministic polynomial time with an oracle for a language in . If P = NP, then PH = P, so . A function is in #P if is the number of strings of length accepted by a polynomial-time verifier , for some polynomial [9, 10]; #SAT, the number of satisfying assignments of a Boolean formula , is #P-complete under parsimonious reductions [11].
denotes the Hurwitz class number, which counts all, not necessarily primitive, classes of positive definite binary forms of discriminant , weighted by and for classes of forms equivalent to multiples of and respectively, and which is zero unless [12]. For a fundamental discriminant one has .
Class Numbers in the Polynomial Hierarchy
We use the standard facts [1 Section 5.4] that every class of primitive positive definite forms of discriminant contains exactly one reduced form , with , if or , and ; that reduced forms have encoding length ; and that composition followed by reduction, the group operation of the form class group , is computable in time polynomial in . Consequently can be computed by repeated squaring in time polynomial in and in the bit lengths of the exponents. We also use the crude bound
and the polynomial-time computability of Hermite normal forms of integer matrices [13].
Theorem 3.1 (Class numbers in ). The function , defined for with , lies in . In particular, if P = NP, then is computable in deterministic polynomial time.
Proof. Let , write for the class of the principal form, and put by (1). If the procedure below terminates immediately with the empty generating set and outputs 1.
Step 1: a small generating set. For a list of reduced forms, every element of has the form with . Hence the language
is in , because never exceeds and all quantified objects have polynomial length. Starting from , we use with prefix search to find a reduced form , append it to , and repeat until no such exists. Each step at least doubles by Lagrange’s theorem, so the loop stops after steps with .
Step 2: the relation lattice. Let , , and . Since is surjective, , and . The Hermite normal form basis of is triangular with positive diagonal entries whose product is and with off-diagonal entries bounded by the diagonal ones; hence all its entries lie in . Step 3: lattice completion. For a finite list of integer vectors, membership in the lattice spanned by is decidable in polynomial time via Hermite normal forms [13]. Hence
is in NP. Starting from , we use with prefix search to find such , append it to , and repeat until none exists. Each appended vector strictly enlarges . At most additions increase the rank. Between two rank increases, while has rank and spans the rational subspace , the index is a positive integer bounded by the determinant of , which is at most by Hadamard’s inequality applied to independent vectors of ; each addition that does not increase the rank replaces this index by a proper divisor. Hence the loop stops after at most additions. Full rank is reached because the vectors are available to the search. When the loop stops, every vector of , in particular every vector of the Hermite normal form basis of , lies in , so . We output , where is the Hermite normal form basis of ; this equals .
All steps run in time polynomial in with queries to and . Under P = NP both languages are in P.
Corollary 3.2 (Class numbers under P = NP). If P = NP, then is computable in deterministic polynomial time; in particular, the class number of every imaginary quadratic field is computable in time polynomial in .
Proof. Under P = NP, , and Theorem 3.1 applies.
Remark 3.3 (The oracle queries). Step 1 of the proof makes queries to the language , and Step 3 makes queries to the NP language , since each of its prefix searches determines a vector of bits. The only queries are those that certify that a list of reduced forms generates . Given a generating set of forms, for instance the one provided under GRH by [3], Steps 2 and 3 alone compute in .
Application to Tunnell’s Count
For a positive integer let
Tunnell [7] proved that if an even square-free is congruent, then , and that the converse holds if the Birch–Swinnerton-Dyer conjecture holds for the curve . Both counts are #P functions of : a witness is a triple of bit length , checked in polynomial time. Let .
Lemma 4.1 (Local vanishing). Let be an even square-free positive integer. If , then ; in particular Tunnell’s identity holds trivially.
Proof. Write with odd; means . A representation gives , while or , a contradiction. The same argument applies to .
Proposition 4.2 (Class-number formula). For every ,
where is the class number of . Consequently , , and for Tunnell’s identity is equivalent to .
Proof. Write , so is odd and square-free. Dividing by shows that , the number of representations of by . The form has class number one (its genus consists of a single class), and for such forms the Siegel–Weil average collapses to the representation number itself; on this basis Bringmann and Kane proved [12 Lemma 4.2] that, for every ,
with the constant tabulated in [12 Appendix B]: it equals for , for , for , and in the remaining classes. The proof in [12] is unconditional: both sides are modular forms of weight on an explicit congruence subgroup, and the identity is verified on the number of coefficients prescribed by the valence formula. For our we obtain . Since is odd, is not a discriminant, so . Since is odd and square-free, is a fundamental discriminant, and it is smaller than , so . Hence . Dirichlet’s class number formula and the elementary bound give , and gives . The last assertion is immediate.
Corollary 4.3 (Complexity of Tunnell’s count). The function on even square-free lies in . If , it is computable in deterministic polynomial time.
Proof. An even square-free satisfies or , and square-freeness and are decidable in , since integer factorization is: the predicate “ has a divisor in ” is in , and prime factors are found by binary search. If output (Lemma 4.1); if output (Proposition 4.2), computed by Theorem 3.1.
Theorem 4.4 (No exact counting reduction to ). Suppose there are functions , , , computable in polynomial time with an oracle, such that for every Boolean formula , is an even square-free integer, and are integers, and . Then and .
Proof. On input , compute , and with the oracle, compute by Corollary 4.3, and output . Every oracle used is in , so . Every reduces parsimoniously to , so , and hence . By Toda’s theorem [8], .
Corollary 4.5 (Quantum computation of Tunnell’s count). Assume GRH. Then on even square-free is computable with bounded error in quantum polynomial time.
Proof. Under GRH, is generated by the classes of prime forms of norm less than [3], which can be listed in polynomial time. Reduced forms give a unique encoding of group elements and the group operation is polynomial-time, so Watrous’s quantum algorithm for the order of a solvable black-box group [4] computes with bounded error in polynomial time. Square-freeness and are decided with Shor’s factoring algorithm [14], and Lemma 4.1 and Proposition 4.2 give .
The identity of Proposition 4.2 has also been confirmed by exhaustive computation for all with and for 1500 random with , in exact integer arithmetic by enumeration of representations and of reduced binary quadratic forms; for every square-free with (20267 integers), .
Relationship to Prior Work
The theory of black-box groups gives complexity bounds for problems on finite groups whose elements have unique encodings and whose operations are computable in polynomial time, when a generating set is part of the input: membership is in [5], and order verification is in [6]. Theorem 3.1 concerns the class group of a single discriminant, given only ; Step 1 of its proof finds a generating set of forms with a oracle, and Steps 2 and 3 compute the order of the group they generate with an oracle, deterministically. Under GRH, a generating set of polynomial size is available directly [3], and the order can be computed in subexponential classical time [2] or in quantum polynomial time [4]. Tunnell’s criterion has been studied computationally on a large scale [15]. The class-number formula for is an instance of the theory of ternary forms with one class in their genus [12].
Conclusion
The class number of every imaginary quadratic order is computable in , without GRH and without a given generating set, and hence in polynomial time if P = NP. For square-free , Tunnell’s count equals , so it lies in on all even square-free , and an exact counting reduction from #SAT to would collapse the polynomial hierarchy to . Two questions remain open: whether is computable in without GRH, which by Remark 3.3 reduces to certifying a generating set of with an NP oracle; and whether the other Tunnell count , which differs from by a coefficient of a weight-3/2 cusp form, lies in the polynomial hierarchy.
Acknowledgements
The author would like to thank Iris, Marilin, Sonia, Yoselin, and Arelis for their support.
Statements and Declarations
Declaration of interests
The author declares no competing interests.
Funding sources
This research did not receive any specific grant from funding agencies in the public, commercial, or not-for-profit sectors.
Declaration of generative AI in scientific writing
The author designed the results of this article, and used Claude Opus 5.5 to improve the readability of this manuscript; the author ran all the computations. After using this tool, the author reviewed and edited the content as needed and takes full responsibility for the content of the publication.
Data availability
All numerical data used in this article are reported in § 4.
References
- [1]H. Cohen, A Course in Computational Algebraic Number Theory, Vol. 138 of Graduate Texts in Mathematics, Springer-Verlag, Berlin, 1993. doi:10.1007/978-3-662-02945-9.DOI
- [2]J. L. Hafner, K. S. McCurley, A rigorous subexponential algorithm for computation of class groups, Journal of the American Mathematical Society 2 (4) (1989) 837–850. doi:10.1090/S0894-0347-1989-1002631-0.DOI
- [3]E. Bach, Explicit bounds for primality testing and related problems, Mathematics of Computation 55 (191) (1990) 355–380. doi:10.1090/S0025-5718-1990-1023756-8.DOI
- [4]J. Watrous, Quantum algorithms for solvable groups, in: Proceedings of the Thirty-Third Annual ACM Symposium on Theory of Computing, ACM, New York, NY, USA, 2001, pp. 60–67. doi:10.1145/380752.380759.DOI
- [5]L. Babai, E. Szemerédi, On the complexity of matrix groups in finite groups, SIAM Journal on Discrete Mathematics 1 (1) (1984) 229–240. doi:10.1109/SFCS.1984.715919.
- [6]L. Babai, Bounded round interactive proofs in finite groups, SIAM Journal on Discrete Mathematics 5 (1) (1992) 88–111. doi:10.1137/0405008.DOI
- [7]J. B. Tunnell, A classical Diophantine problem and modular forms of weight 3/2, Inventiones Mathematicae 72 (2) (1983) 323–334. doi:10.1007/BF01389327.DOI
- [8]S. Toda, PP is as hard as the polynomial-time hierarchy, SIAM Journal on Computing 20 (5) (1991) 865–877. doi:10.1137/0220053.DOI
- [9]L. G. Valiant, The complexity of computing the permanent, Theoretical Computer Science 8 (2) (1979) 189–201. doi:10.1016/0304-3975(79)90044-6.DOI
- [10]L. G. Valiant, The complexity of enumeration and reliability problems, SIAM Journal on Computing 8 (3) (1979) 410–421. doi:10.1137/0208032.DOI
- [11]S. Arora, B. Barak, Computational Complexity: A Modern Approach, Cambridge University Press, Cambridge, UK, 2009. doi:10.1017/CBO9780511804090.DOI
- [12]K. Bringmann, B. Kane, Class numbers and representations by ternary quadratic forms with congruence conditions, Mathematics of Computation 91 (333) (2022) 295–329. doi:10.1090/mcom/3648.DOI
- [13]R. Kannan, A. Bachem, Polynomial algorithms for computing the Smith and Hermite normal forms of an integer matrix, SIAM Journal on Computing 8 (4) (1979) 499–507. doi:10.1137/0208040.
- [14]P. W. Shor, Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer, SIAM Journal on Computing 26 (5) (1997) 1484–1509. doi:10.1137/S0097539795293172.DOI
- [15]W. B. Hart, G. Tornaría, M. Watkins, Congruent number theta coefficients to 10¹², in: Algorithmic Number Theory (ANTS-IX), Vol. 6197 of Lecture Notes in Computer Science, Springer, Berlin, 2010, pp. 186–200. doi:10.1007/978-3-642-14518-6_17.DOI