Algorithms
Function documentation says what a function computes. This part of the documentation says how. Overview pages compare the methods FLINT uses for one task and say which functions use which; algorithm pages state a single method precisely, prove it correct where the proof fits on a page, and give references to the literature. Every algorithm page lists the functions and pages that refer to it.
Modular arithmetic
Arithmetic modulo word-size and multiword integers: division with precomputed inverses, Shoup, Montgomery, Barrett and Lemire reduction, divisibility tests, simultaneous inversion, multiword modular multiplication and delayed reduction, and how to choose among them.
fmpz residues in fmpz_mod and with fixed-length limb arrays in the generic ring mpn_mod. This page compares the representations, the reductions they use, and how they relate to nmod and to the generic rings.AlgorithmModular multiplication with a multiword modulusReduces a product of two residues modulo an \ell-limb n with a precomputed \ell-limb inverse, using one high and one low product and at most a few subtractions; also the two-limb Barrett reduction of fmpz_mod, Shoup's method and the matrix method for a fixed multiplier, and the fused ab + cd.AlgorithmDelayed reduction for multiword moduliHow mpn_mod evaluates sums of products modulo an \ell-limb n exactly in 2\ell - 1 to 2\ell + 1 limbs and reduces once, in dot products, polynomial multiplication and division, Euclid's algorithm, Gaussian elimination and matrix multiplication, and how this plugs into the generic algorithms.Integer arithmetic
Multiplication, division, GCDs, roots and radix conversion of multiprecision integers, and binary splitting.
Primes and number theory
Primality testing and proving, integer factoring, square roots and discrete logarithms modulo primes, Dirichlet characters, rational reconstruction and continued fractions, number fields, Gaussian integers, binary quadratic forms, and Bernoulli, partition, Stirling and Bell numbers.
n_is_prime proves primality of any 64-bit integer with at most two strong probable prime tests, using table lookups, vectorised trial division and a hashed table of witnesses.OverviewFactoring word-size integersHow n_factor combines trial division, primality testing, perfect power detection, Pollard–Brent rho, Hart's one-line method and SQUFOF to factor any 64-bit integer.AlgorithmPrimality proving: APRCL and ECPPHow FLINT proves the primality of large integers, by n \pm 1 tests when the factorisations allow it, by the APRCL test with Jacobi sums, and by elliptic curve primality proving with verifiable certificates.OverviewFactoring integersThe factoring methods available in FLINT (trial division, Pollard rho, p \pm 1, ECM, SQUFOF and the quadratic sieve), their running times, and how fmpz_factor combines them.AlgorithmSquare roots modulo a primeHow nmod_sqrt finds a square root modulo a word-size prime n. It uses one exponentiation when n \equiv 3 \pmod 4 or n \equiv 5 \pmod 8, and otherwise Tonelli–Shanks in two forms or Müller's variant of Cipolla–Lehmer, depending on the power of 2 dividing n - 1. Every candidate root is checked by squaring.AlgorithmThe elliptic curve methodLenstra's elliptic curve method for finding a prime factor p of N, with Montgomery curves, Suyama's parametrisation, the Montgomery ladder in stage 1 and the standard continuation in stage 2.AlgorithmThe quadratic sieveFactoring N by finding a congruence of squares from many smooth values of quadratic polynomials, with self-initialising polynomials, a block and bucket sieve, the large prime variation and block Lanczos linear algebra.AlgorithmDiscrete logarithms modulo a prime (Pohlig–Hellman)Computes x with g^x = y modulo a prime p by solving the problem in each subgroup of prime-power order of (\mathbb{Z}/p\mathbb{Z})^\times, one base-q digit at a time, and combining the results by the Chinese remainder theorem. Fast when p - 1 has only small prime factors.AlgorithmDiscrete logarithm tablesPrecomputations for many discrete logarithms in a fixed cyclic group modulo a word-size prime power, combining baby-step giant-step tables sized for the number of queries, the Pohlig–Hellman decomposition and p-adic logarithms, and a sieve for the logarithms of all small integers.AlgorithmStrong probable prime testThe Miller–Rabin test for a single base. Every odd prime passes it, at most a quarter of the bases let a composite pass, and with tabulated pseudoprimes it becomes a proof of primality for word-size integers.AlgorithmComputing the partition functionComputes p(n) exactly by the Hardy–Ramanujan–Rademacher series, truncated with Rademacher's error bound, with the exponential sums factored into products of cosines and each term evaluated in ball arithmetic at the precision it needs; small values come from Euler's pentagonal recurrence.AlgorithmGaussian integersDivision with remainder, the canonical associate, and the four GCD algorithms of fmpzi (Euclidean in exact and floating-point arithmetic, the (1+i)-ary binary algorithm, and a lattice algorithm), together with primality testing and the removal of factors 1+i.AlgorithmBernoulli numbersComputes exact Bernoulli numbers from the zeta function (numerically, with the denominator from von Staudt–Clausen), from Harvey's multimodular algorithm, by a reverse zeta iterator with a table of powers for ranges, and by Ramanujan's recursion or power series modulo primes for short vectors.AlgorithmArithmetic in number fieldsHow nf_elem represents elements of Q[x]/(f) with special cases for degrees 1 and 2 and for Q(i), multiplies with reduction by precomputed powers of the generator, inverts by the extended Euclidean algorithm, and computes norms as resultants and traces from power sums of the roots.AlgorithmRational reconstructionRecovers a fraction n/d with |n| \le N and 0 < d \le D from its residue modulo m > 2ND by stopping the extended Euclidean algorithm at the first remainder below N. Used to return rational results from multimodular and p-adic algorithms.AlgorithmContinued fractions of rational numbersComputes the continued fraction of a rational number with a half-GCD algorithm that finds the terms from leading bits, evaluates continued fractions by balanced matrix products, and uses the same machinery for the simplest fraction in an interval, Farey neighbours and Dedekind sums.AlgorithmDirichlet charactersRepresents the Dirichlet characters modulo q through the decomposition of the unit group into cyclic components with Conrey's generators, so that characters, values, conductors, parities and orders are computed from discrete logarithms in each component or directly from the Conrey number.AlgorithmStirling and Bell numbersIsolated Stirling numbers by binary splitting of rising factorials, power sums or power series, chosen by k/n; rows by convolution; Bell numbers by Dobiński's formula, a multimodular sum, the Bell triangle or generating functions modulo primes.AlgorithmBinary quadratic forms and class groupsReduction of positive definite binary quadratic forms, enumeration of the reduced forms of a discriminant (the class number), composition by Shanks' NUCOMP, and the computation of orders and of the exponent of the form class group by a two-stage method in the style of Pollard and Sutherland.Generic algorithms
How the generic rings framework is designed: contexts and method tables, the three levels of operations and specialisation, inexact elements and truth values, domain and unable errors, and randomised testing of ring axioms.
Vectors and matrices
Dot products and matrix multiplication modulo word-size integers, over \mathbb{Z} and in floating point; Gaussian elimination, fraction-free and multimodular algorithms, characteristic polynomials, lattice reduction, Hermite and Smith normal forms and matrices of polynomials, over generic rings and their specialisations.
nmod_mat_mul chooses among them.AlgorithmDot products modulo a word-size integerHow FLINT computes \sum a_i b_i \bmod n with a single final reduction, accumulating the exact sum in one, two or three words, or in SIMD lanes, depending on n, the length and the processor.AlgorithmStrassen–Winograd multiplicationThe 7-multiplication scheme FLINT uses for large matrix products over \mathbb{Z}/n\mathbb{Z}, with Bodrato's operation sequence, a schedule with two temporaries, and odd dimensions handled by virtual zero padding.AlgorithmMatrix multiplication kernels modulo nThe blocked SIMD kernels nmod_mat_mul_u32, _u52, _k52 and _fp50, which multiply matrices modulo moduli up to 2^{52} in one pass with delayed reduction, and the floating-point route of nmod_mat_mul_blas with Chinese remaindering.AlgorithmMatrix multiplication modulo small integersHow nmod_mat_mul_u8 multiplies matrices modulo N \le 255 with entries in bytes, replacing multiplications by in-register table lookups for N \le 16, and with bit-packed Strassen–Winograd and the method of four Russians for N = 2 and N = 3.AlgorithmFloating-point matrix multiplication (gemm)How FLINT's own sgemm and dgemm kernels block, pack and thread a matrix product around a register-tile micro-kernel, and when floating-point matrix products of integers are exact.OverviewMultiplying matrices over the integersThe methods FLINT uses to multiply integer matrices — word-size dot products, Waksman and Strassen–Winograd on multiprecision entries, multimodular products through nmod_mat, floating-point gemm modulo small primes, and transforming each entry once with the small-prime FFT — their costs, and when fmpz_mat_mul uses which.AlgorithmGaussian elimination and LU decompositionLU decomposition with row pivoting over \mathbb{Z}/p\mathbb{Z} in its classical, delayed-reduction and recursive forms, and how FLINT derives triangular solving, linear system solving, inverses, determinants, ranks, echelon forms and nullspaces from it; plus division-free determinants and the Howell form over \mathbb{Z}/n\mathbb{Z}.AlgorithmFraction-free eliminationBareiss' fraction-free Gaussian elimination over integral domains, Sylvester's identity, the fraction-free LU decomposition and how FLINT uses it for determinants, ranks, linear systems and echelon forms over \mathbb{Z}, \mathbb{Z}[x] and (\mathbb{Z}/p\mathbb{Z})[x].AlgorithmCharacteristic and minimal polynomialsBerkowitz's division-free algorithm and Danilevsky's reduction to companion form for the characteristic polynomial over \mathbb{Z}/n\mathbb{Z}, and the Krylov method with least common multiples that FLINT uses for the minimal polynomial.AlgorithmMultimodular and p-adic linear algebra over the integersHow FLINT computes determinants, solutions of linear systems, ranks, echelon forms, characteristic and minimal polynomials and products of integer matrices by working modulo word-size primes or prime powers, with Hadamard bounds, rational reconstruction, output-sensitive termination and exact certificates for every answer.AlgorithmLattice reduction (LLL)LLL-reduced bases and the algorithms FLINT implements for them — the original rational LLL, Storjohann's integral variant, and the floating-point L² algorithm of Nguyen and Stehlé in fmpz_lll with Gram–Schmidt data in doubles, heuristic exact dot products or multiprecision floats, certified reducedness tests, removals for van Hoeij's factoring, and the truncation strategy (ULLL) used by fmpz_lll.AlgorithmHermite and Smith normal formsThe Hermite and Smith normal forms of integer matrices and the algorithms FLINT implements for them — classical and gcd-based elimination, Kannan–Bachem, Domich–Kannan–Trotter and other computations modulo a determinant, the Pernet–Stein algorithm, Iliopoulos' algorithm, iterated Hermite forms, and Lübeck's p-adic method for elementary divisors — with the choices made by fmpz_mat_hnf and fmpz_mat_snf.AlgorithmMatrices of polynomialsHow FLINT multiplies matrices over \mathbb{Z}[x] and (\mathbb{Z}/n\mathbb{Z})[x] — classical products of polynomials, Kronecker substitution into one integer matrix product, evaluation and interpolation, and transforming each entry once with the small-prime FFT — and how it computes determinants, ranks, inverses and solutions by fraction-free elimination or by evaluation and interpolation.Univariate polynomials
Dense univariate polynomials over generic rings, \mathbb{Z}/n\mathbb{Z}, \mathbb{Z} and finite fields: multiplication, Newton iteration, GCDs and resultants, evaluation, interpolation and composition, Hensel lifting, squarefree factorisation, factoring over finite fields and over \mathbb{Z}, and roots.
nmod_poly multiplies: classical products built on modular dot products, Kronecker substitution (KS, KS2, KS4), and the small-prime FFT of fft_small, with the length and modulus-size cutoffs that choose between them for full, low, middle and high products.OverviewMultiplying polynomials over ZHow fmpz_poly multiplies, depending on the length and the coefficient size - word-size accumulation, classical and packed-limb products, Karatsuba with Toom-Cook interpolation in the polynomial variable, Kronecker substitution, the multimodular small-prime FFT, Schönhage-Strassen convolutions and classical multiplication in transform space - with the exactness lemmas and the dispatcher that chooses among them.AlgorithmKronecker substitutionMultiplies polynomials over \mathbb{Z}/n\mathbb{Z} by packing their coefficients into large integers, multiplying the integers and unpacking; Harvey's KS2 and KS4 variants evaluate at ±2^b and ±2^(-b) to split the integer product into two or four smaller ones.AlgorithmNewton iteration for power series and divisionInverse, quotient, square root, reciprocal square root, exponential and logarithm of power series by Newton iteration with middle products and the Karp–Markstein trick, and polynomial division with remainder via reversed polynomials, as implemented for nmod_poly.AlgorithmMiddle products and the transposition principleThe middle product, a window of coefficients of a product, is the transpose of polynomial multiplication and costs no more than an ordinary product of the corresponding size; FLINT computes it with dot products, a cyclic convolution whose wrap-around misses the window, or transposed FFTs, and uses it in Newton iteration and geometric evaluation.OverviewPolynomial GCDs and resultantsThe Euclidean algorithm, the half-gcd algorithm and the subresultant pseudo-remainder sequence as implemented generically in gr_poly, how the generic code chooses between them from the properties of the coefficient ring, how resultants are derived from the same sequences, and the specialised algorithms of nmod_poly, fmpz_mod_poly, fq_poly and fmpz_poly.AlgorithmGCDs of polynomials over ZThe three GCD algorithms of fmpz_poly - the subresultant pseudo-remainder sequence, the heuristic GCD through one integer GCD, and the multimodular algorithm with adaptive termination and certification by multimodular division - with the proofs that make their results correct, and the multimodular extended GCD.AlgorithmResultants and discriminants over ZResultants of integer polynomials by the subresultant pseudo-remainder sequence and by the multimodular algorithm with Hadamard's bound, discriminants as resultants with the derivative, and resultants with a known divisor, as implemented in fmpz_poly.AlgorithmHalf-GCDThe half-gcd algorithm computes the quotients of the first half of the Euclidean remainder sequence from the top halves of the inputs, recursively, giving GCDs, extended GCDs and resultants in O(M(n) \log n) operations; with a correctness proof and FLINT's cutoffs for nmod_poly.AlgorithmMultipoint evaluation and interpolationEvaluation of a polynomial at many points and interpolation through many points in O(M(n) \log n) operations with the subproduct tree and the remainder tree, and in O(M(n)) for points in geometric progression with Bluestein's chirp transform and the method of Bostan and Schost.AlgorithmComposition and modular compositionComputing f(g), f(g) \bmod x^n and f(g) \bmod h by Horner's rule, divide and conquer, Taylor shifts, the baby-step giant-step method of Brent and Kung, and the algorithm of Kinoshita and Li, with the choices made by nmod_poly.AlgorithmHensel liftingLifting a factorisation modulo a prime p into coprime monic factors to a factorisation modulo p^N, for two factors with the Bézout cofactors and for many factors along a factor tree, with quadratic convergence; the correctness proof and the fused tree nodes used by fmpz_poly.AlgorithmFactoring polynomials over the integersThe Zassenhaus algorithm (factor modulo a prime, Hensel lift, recombine subsets of the modular factors) and van Hoeij's knapsack method with CLD data and gradual feeding to LLL, as implemented in fmpz_poly_factor, with the reductions that come first (content, powers of x, deflation with Capelli certificates, squarefree factorisation), the choice of the prime and the bounds that make the result provable.AlgorithmSquarefree factorisationYun's algorithm in characteristic zero and the gcd iteration with p-th roots over finite fields, which split a polynomial into squarefree, pairwise coprime factors with distinct multiplicities using only gcds and exact divisions.AlgorithmFactoring polynomials over finite fieldsSquarefree, distinct-degree and equal-degree factorisation over \mathbb{F}_q; the Cantor–Zassenhaus, Berlekamp and Kaltofen–Shoup algorithms, the baby-step giant-step distinct-degree factorisation with modular composition, the trace and minimal-polynomial splittings, and how the generic implementation in gr_poly chooses between them.AlgorithmIrreducibility testing over finite fieldsRabin's test, Ben-Or's test and the distinct-degree test for irreducibility over \mathbb{F}_q, their costs on irreducible and on random inputs, how FLINT combines them, and the construction of irreducible polynomials.AlgorithmRoots of polynomials over finite fieldsRoots in \mathbb{F}_q by squarefree factorisation, the split \gcd(f, x^{(q-1)/2} \pm 1) and random shifts, with powers of x + c computed through Taylor shifts; roots modulo prime powers by Hensel lifting of all roots, and modulo composite n by the Chinese remainder theorem.AlgorithmCounting and isolating real roots over ZRoot bounds, Descartes' rule of signs and the Vincent-Collins-Akritas bisection algorithm, Sturm sequences computed as subresultant or primitive remainder sequences, and sign-change isolation for real-rooted polynomials, as used by fmpz_poly to count and isolate the real roots of squarefree integer polynomials exactly.Multivariate polynomials
Sparse multivariate polynomials: the packed representation, heap and dense multiplication and division, powering and square roots, modular GCD algorithms with dense and sparse interpolation, Hensel lifting, and factorisation over the integers and over finite fields.
nmod_mpoly_gcd chooses among Brown's, Zippel's and Hensel-lifting algorithms.AlgorithmSparse interpolationRecovering a sparse polynomial from its values at a few points: Zippel's method for a known support (transposed Vandermonde systems solved in quadratic time, with extra unknowns for scaled images), and the method of Ben-Or and Tiwari for an unknown support (Berlekamp–Massey, roots of the recurrence polynomial, discrete logarithms modulo a smooth prime after Kronecker substitution) with the Berlekamp–Massey algorithm computed incrementally by half-gcd steps, as used by FLINT's sparse GCD and factoring algorithms.AlgorithmMultivariate Hensel liftingLifting a factorisation of A(x_0, \alpha_1, \ldots, \alpha_m) to a factorisation of A one variable at a time: uniqueness given the leading coefficients, the multivariate partial fraction (diophantine) equations solved by Taylor expansion, the quartic and quintic error updates of FLINT's fmpz_mpoly_hlift, bivariate lifting modulo prime powers, sparse lifting, and the leading coefficient methods of Wang and Kaltofen.AlgorithmFactorisationHow FLINT factors multivariate polynomials over the integers: removal of contents and powers of variables, squarefree decomposition by Yun's algorithm, compression of the exponents by unimodular changes of variables, irreducibility certificates from Newton polytopes, direct formulas for low degree, dense bivariate factorisation with Hensel lifting and recombination, degree pruning with univariate images, and the three lifting strategies of Wang, Zippel and Zassenhaus.AlgorithmFactoring over finite fieldsThe multivariate factorisation pipeline of nmod_mpoly_factor and fq_nmod_mpoly_factor, with what is specific to characteristic p: separable factorisation with p-th roots, deflation by powers of p, factoring over extension fields with recombination of Frobenius orbits when the field is too small for good evaluation points, quadratic equations in characteristic 2, bivariate factorisation with recombination by linear algebra, and Wang's leading coefficients along random curves.AlgorithmBivariate resultants by evaluation and interpolationThe resultant \mathrm{Res}_y(A, B) \in \mathbb{F}_p[x] of two bivariate polynomials, computed from univariate resultants at many values of x (a geometric progression or roots of unity) and interpolation, with the degree bound, the correction for specialisations that lower the degree, and FLINT's cutoffs.Fast Fourier transforms
The FFTs behind fast multiplication of integers and polynomials: Schönhage–Strassen, small-prime FFTs in floating point, and generic DFTs over any ring.
fft_small modulo primes p < 2^{50}, on integers stored in doubles: the order of the roots, radix-4 butterflies with lazy reduction, blocking and truncation, and proofs that every value stays in range.AlgorithmMultiplication with several primes and CRTHow fft_small multiplies integers and polynomials whose product coefficients exceed one prime: chunk sizes and the number of primes, the two-prime and multi-prime pipelines, Chinese remaindering with the normalisation folded in, windows computed with wrap-around, sums of products in transform space, precomputed and shared operands, and transposed products for middle products.AlgorithmDiscrete Fourier transforms over a generic ringThe DFT algorithms of gr_dft (naive, radix-2 and split-radix Cooley–Tukey, four-step, mixed-radix with direct prime kernels, Good–Thomas and Bluestein), the conditions each one needs on the root of unity, and their costs.AlgorithmRigorous numerical DFTs in fixed pointHow gr_dft computes complex DFTs in multi-limb fixed-point arithmetic with an a priori bound on every intermediate value and on the output error, and how this yields ball enclosures for transforms of acb vectors.Finite fields
Arithmetic in finite fields of non-prime order: the polynomial and Zech logarithm representations, reduction modulo sparse defining polynomials, the Frobenius map, norm and trace, embeddings between fields, and the choice of defining polynomials.
fq_default chooses among them, and lists the algorithms for reduction, inversion, powering, Frobenius, norm, trace, embeddings and defining polynomials.AlgorithmReduction modulo the defining polynomialElements of \mathbb{F}_p[x]/(f) are reduced after each product either by eliminating the high coefficients with the few nonzero terms of a sparse f, or by Newton division with a precomputed inverse of the reversal of f; sums of products are reduced only once.AlgorithmZech logarithmsIn a small field \mathbb{F}_q with a primitive element g, storing each element as its discrete logarithm turns multiplication into an addition modulo q - 1, and a table of the Zech logarithms Z(k) with 1 + g^k = g^{Z(k)} turns addition into one lookup; the table is built in O(q) operations, which also tests whether g is primitive.AlgorithmFrobenius map, norm, trace and rootsHow FLINT applies the Frobenius automorphism a \mapsto a^{p^e}, computes the trace from power sums given by Newton's identities and the norm as a resultant, and computes p-th roots, square roots (Tonelli–Shanks) and multiplicative orders in \mathbb{F}_{p^d}.AlgorithmEmbeddings of finite fieldsTo embed \mathbb{F}_{p^m} into \mathbb{F}_{p^n} given by unrelated defining polynomials, FLINT finds a root of the smaller field's polynomial in the larger field and expresses the embedding, and a left inverse built from the trace and the dual basis, as matrices over \mathbb{F}_p.AlgorithmDefining polynomialsWhich irreducible polynomial defines \mathbb{F}_{p^d} in FLINT: Conway polynomials from Lübeck's tables when available, otherwise polynomials with as few terms as possible (fq_nmod), random sparse irreducible polynomials (fq) or random primitive polynomials (fq_zech); with the facts about their existence that these choices rely on.p-adic numbers
Arithmetic with p-adic numbers and unramified extensions: precision models, Newton and Hensel lifting, exponentials and logarithms, Frobenius and Teichmüller lifts, norms and traces.
Ball arithmetic
Rigorous real and complex arithmetic with midpoint-radius balls: representation and error propagation, dot products, polynomial and matrix multiplication, power series, roots of polynomials and real functions, linear systems, eigenvalues and integration.
Special functions
Rigorous evaluation of elementary functions, constants, the gamma function, hypergeometric functions and their special cases, zeta and L-functions, and elliptic, modular and theta functions in ball arithmetic.
Floating-point arithmetic
Fixed-precision multiprecision floating-point and decimal arithmetic, double-word and interval arithmetic with machine doubles.
Exact real and complex numbers
Algebraic numbers and exact real and complex numbers: representations, arithmetic and decision procedures.
SIMD and floating-point arithmetic
Arithmetic on vectors of machine words and doubles, including exact modular arithmetic carried out in floating point.
Parallel computation
How FLINT distributes work over threads: the thread pool, parallel loops and parallel binary splitting.
The FLINT team, “Algorithms,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/index.html (generated 2026-10-20).
@misc{flint-doc-algorithms-index,
author = {{The FLINT team}},
title = {{Algorithms}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/index.html},
note = {Generated 2026-10-20}
}