FLINT3.7.0-dev

mp_real_partitions_hrr, _mp_real_partitions_hrr

Synopsis#include <flint/mp_real.h>
void mp_real_partitions_hrr(mp_real_t res, ulong nhi, ulong nlo)source
void _mp_real_partitions_hrr(mp_real_t res, const fmpz_t n, int flags)source

Set res to the exact number of partitions p(n) of n = n_{\mathit{hi}} B + n_{\mathit{lo}} (first function) or of any fmpz n (second function), as an exact mp_real_t. The size of the result is not limited by that of an fmpz_t.

mp_real_partitions_hrr reads p(n) from a table for n < 128, uses the pentagonal recurrence while p(n) fits a word (n < 417 on 64-bit machines), and otherwise the Hardy–Ramanujan–Rademacher formula [Rademacher1937] [Joh2012]

p(n) = \sum_{k=1}^N A_k(n) \sqrt{\frac{3}{k}} \frac{4}{24n - 1} \left(\cosh z_k - \frac{\sinh z_k}{z_k}\right) + R_N, \qquad z_k = \frac{\pi\sqrt{24n - 1}}{6k},

with A_k(n) from arith_hrr_expsum_factored, N and the bound for R_N from partitions_rademacher_bound, and each term at the precision it contributes at. Terms of at most about 200 bits are evaluated in batches of dfloat balls, the others in mp_real balls, with \exp(z_k) obtained as the k-th root of \exp(z_1) (computed by mp_real_exp_notab_squaring or, at huge precision, mp_real_exp_agm). The resulting ball is resolved by mp_real_unique_integer (Integers from balls).

With several threads (flint_set_num_threads, from n = 10^8) the constants are computed once with the whole thread budget, and the terms are summed in ranges of k of about equal cost, each into its own accumulator. The peak memory is about that of computing \pi to the same precision.

_mp_real_partitions_hrr uses the formula for every n \ge 2; flags is a combination of MP_REAL_PARTITIONS_NO_DFLOAT (all terms in mp_real) and MP_REAL_PARTITIONS_TEST (the rarely taken paths at any n), for testing. partitions_fmpz_fmpz in partitions.h calls these functions. The method is described in Computing the partition function.

References#

Cite this page

The FLINT team, “mp_real_partitions_hrr, _mp_real_partitions_hrr (mp_real.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/mp_real/mp_real_partitions_hrr.html (generated 2026-10-20).