arith_sum_of_squares
#include <flint/arith.h>For k = 1 the result is 2 or 0. For k = 2 and k = 4 the function factors n and uses Jacobi's formulas r_2(n) = 4 \sum_{d \mid n,\, d \text{ odd}} (-1)^{(d-1)/2} and r_4(n) = 8 \sum_{d \mid n,\, 4 \nmid d} d [Grosswald1985]. For k = 3 and k = 5 it uses the recursion r_k(n) = \sum_{j \in \mathbb{Z}} r_{k-1}(n - j^2), with O(\sqrt n) calls for k - 1 \in \{2, 4\}; n is then assumed to fit in a ulong. For other k it computes the coefficients of \vartheta_3(q)^k up to q^n with arith_sum_of_squares_vec, which requires n to fit in a slong and throws otherwise.
References#
- [Grosswald1985] E. Grosswald, Representations of Integers as Sums of Squares, Springer, 1985. https://doi.org/10.1007/978-1-4613-8566-0
The FLINT team, “arith_sum_of_squares (arith.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/arith/arith_sum_of_squares.html (generated 2026-10-20).
@misc{flint-doc-arith-arith-sum-of-squares,
author = {{The FLINT team}},
title = {{arith\_sum\_of\_squares (arith.h)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/arith/arith_sum_of_squares.html},
note = {Generated 2026-10-20}
}