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)p(n) of n=nhiB+nlon = n_{\mathit{hi}} B + n_{\mathit{lo}} (first function) or of any fmpz nn (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)p(n) from a table for n<128n < 128, uses the pentagonal recurrence while p(n)p(n) fits a word (n<417n < 417 on 64-bit machines), and otherwise the Hardy–Ramanujan–Rademacher formula [Rademacher1937] [Joh2012]

p(n)=∑k=1NAk(n)3k424n−1(cosh⁡zk−sinh⁡zkzk)+RN,zk=π24n−16k,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 Ak(n)A_k(n) from arith_hrr_expsum_factored, NN and the bound for RNR_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⁡(zk)\exp(z_k) obtained as the kk-th root of exp⁡(z1)\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=108n = 10^8) the constants are computed once with the whole thread budget, and the terms are summed in ranges of kk 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≥2n \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 nn), 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-11-02).