FLINT3.7.0-dev
Tutorial

The example programs

The directory examples of the FLINT source tree contains about fifty complete programs. Some are short demonstrations of a module, others are command-line tools and benchmarks that were used for record computations. They are good starting points for one's own programs.

Building and running#

In a configured FLINT source tree,

make examples

builds the library and all example programs, placing the executables in build/examples; for example, build/examples/partitions 1000000000 computes the number of partitions of 10^9. make checkexamples runs some of them and checks their output. A single example can also be compiled against an installed FLINT, since the examples include the headers as <flint/...>:

gcc -O2 examples/crt.c -o crt -lflint -lmpfr -lgmp -lm

(with -I, -L and -Wl,-rpath options for a nonstandard prefix, as in A first program). Most programs print a usage message when called without arguments, and many accept -threads n to use n threads. Several print their running time and memory usage with the functions of profiler.h.

Integers and number theory#

ProgramWhat it doesExample
crtReconstructs an integer from its residues modulo 2, 3, 5, \ldots with fmpz_CRT_ui, printing each stepcrt 10382788
multi_crtThe same with all residues at once, using fmpz_multi_mod_ui and fmpz_multi_CRT_ui with a precomputed fmpz_comb_tmulti_crt 100493287498239 13
factor_integerFactors an integer, given as an expression such as 2^128+1, with fmpz_factor; -certify proves the primality of the large factors with ECPP and prints the certificatesfactor_integer -timing "2^128+1"
AKSTests the primality of an integer with the AKS algorithm (fmpz_is_prime_AKS) and compares with fmpz_is_primeAKS 1000003
primegenPrints the primes up to N using the prime iterator of ulong_extras.h, or with -c only counts themprimegen -c 1000000
check_n_is_primeChecks n_is_prime against a file of all base-2 Fermat pseudoprimes below 2^{64} (not included)check_n_is_prime psps.txt
partitionsComputes the number of partitions p(n) with partitions_fmpz_fmpzpartitions 1000000000 -threads 4
bernoulliComputes the Bernoulli number B_n exactlybernoulli 1000000 -threads 8
delta_qexpComputes the coefficient \tau(n) of q^n in the q-expansion of the modular discriminant \Delta, with arith_ramanujan_taudelta_qexp 1000000
class_polyComputes the Hilbert class polynomial of a discriminantclass_poly -1000004 -threads 8
mfcoefsComputes many Fourier coefficients of a few built-in modular forms (named 11, 23, 41, 131 and 13_4 after their level) from products of Eisenstein series; needs fft_small.hmfcoefs 23 100000

For example:

> build/examples/crt 10382788
residue mod 2 = 0; reconstruction = 0
residue mod 3 = 1; reconstruction = -2
residue mod 5 = 3; reconstruction = -2
residue mod 7 = 3; reconstruction = -32
residue mod 11 = 9; reconstruction = -662
residue mod 13 = 0; reconstruction = -7592
residue mod 17 = 4; reconstruction = 172588
residue mod 19 = 10; reconstruction = 683098
residue mod 23 = 13; reconstruction = 10382788
> build/examples/factor_integer "2^128+1"
340282366920938463463374607431768211457 =
59649589127497217 * 5704689200685129054721

Polynomials#

ProgramWhat it doesExample
fmpq_polyMultiplies two polynomials with rational coefficients; a minimal demonstration of fmpq_poly.hfmpq_poly
fmpz_poly_qMultiplies two rational functions with fmpz_poly_q.hfmpz_poly_q
fmpz_mod_polySquares a polynomial modulo 7 with fmpz_mod_poly.hfmpz_mod_poly
fmpz_poly_factor_zassenhausFactors a polynomial of degree 62 over \mathbb{Z} with the Zassenhaus algorithm; a small change makes it read a larger polynomial from the file fmpz_poly_hensel_P1fmpz_poly_factor_zassenhaus
factor_polynomialFactors a polynomial in x, y, z over \mathbb{Z}, given as an expression, with fmpz_mpoly_factorfactor_polynomial "(1+x+2*y+3*z)^3+1"
minimal_irreduciblesPrints the minimal irreducible polynomials (nmod_poly_minimal_irreducible) of degrees n_{\min} to n_{\max} over \mathbb{F}_p, in parallel with flint_parallel_dominimal_irreducibles 2 1 8
fq_polyTimes the multiplication of polynomials over three finite fields with the classical, reordering and Kronecker substitution algorithmsfq_poly
radixTimes the radix conversion of a polynomial modulo 17^{26} with fmpz_mod_poly_radixradix
groebnerComputes Gröbner bases over \mathbb{Z} or \mathbb{Z}/p\mathbb{Z} with Buchberger's algorithm for built-in or user-given systems, with timings and verificationgroebner -vars x,y -input "x^2+y^2-1,x-y"
swinnerton_dyer_polyComputes the Swinnerton-Dyer polynomial S_n exactly, using exact real numbersswinnerton_dyer_poly 10
poly_rootsIsolates all complex roots of an integer polynomial (arb_fmpz_poly_complex_roots)poly_roots -print 15 t 100

For example, minimal_irreducibles 2 1 8 prints the polynomials x, x^2 + x + 1, x^3 + x + 1, x^4 + x + 1, x^5 + x^2 + 1, x^6 + x + 1, x^7 + x + 1 and x^8 + x^4 + x^3 + x + 1, and

> build/examples/factor_polynomial "(1+x+2*y+3*z)^3+1"
x^3+6*x^2*y+9*x^2*z+3*x^2+12*x*y^2+36*x*y*z+12*x*y+27*x*z^2+18*x*z+3*x+8*y^3+36*y^2*z+12*y^2+54*y*z^2+36*y*z+6*y+27*z^3+27*z^2+9*z+2 =
1*(x+2*y+3*z+2)^1*(x^2+4*x*y+6*x*z+x+4*y^2+12*y*z+2*y+9*z^2+3*z+1)^1

Matrices#

ProgramWhat it doesExample
stirling_matrixBuilds the n \times n matrices of Stirling numbers of the first and second kind and multiplies them, which gives the identity matrixstirling_matrix 10
hilbert_matrixComputes the determinant (or with -eig the eigenvalues) of the n \times n Hilbert matrix in ball arithmetic, doubling the precision until the result is accuratehilbert_matrix 200
hilbert_matrix_caComputes the eigenvalues of the Hilbert matrix as exact algebraic numbers and verifies the trace and determinanthilbert_matrix_ca 5

p-adic numbers#

ProgramWhat it doesExample
padicDemonstrates conversion and printing of p-adic numbers in the different print modes, and the logarithm, with padic.hpadic
qadicDemonstrates powers, sums, Teichmüller lifts, inverses, Frobenius images and square roots in unramified extensions with qadic.hqadic

Real and complex numbers#

These programs use ball arithmetic (arb.h, acb.h and the modules built on them) and are described in Rigorous numerics.

ProgramWhat it doesExample
piComputes \pi (or e, \gamma and other constants with -constant) to n digitspi 1000000 -threads 4
pi_agmComputes \pi with the Brent–Salamin AGM iterationpi_agm 100000
logisticIterates the logistic map x_{k+1} = r x_k (1 - x_k), restarting with doubled precision until the result is accuratelogistic 10000
real_rootsIsolates and refines the real roots of a function on an interval with arb_calc.hreal_roots 0 0.0 50.0 -verbose
zeta_zerosComputes consecutive zeros of the Riemann zeta function on the critical linezeta_zeros -n 1 -count 10
keiper_liComputes the Keiper–Li coefficients \lambda_0, \ldots, \lambda_nkeiper_li 1000 -threads 2
lvalueEvaluates Dirichlet L-functions and their derivativeslvalue -character 4 3 -re 2
lcentralComputes the central values L(1/2, \chi) for all characters \chi modulo q in a rangelcentral 1 8
complex_plotPlots a function of a complex variable by domain colouring to a PPM imagecomplex_plot zeta -range -10 10 0 40
integralsComputes a list of difficult integrals with rigorous error bounds using acb_calc_integrateintegrals -i 4
integrals_double_expComputes integrals with the double exponential (tanh-sinh) quadratureintegrals_double_exp -p 333
taylor_integralsComputes integrals (an elliptic integral and others) with the Taylor series method of acb_calc.htaylor_integrals 50
fpwrapDemonstrates the floating-point wrappers of arb_fpwrap.hfpwrap
functions_benchmarkTimes standard elementary and special functions at several precisionsfunctions_benchmark

Exact real and complex numbers#

These programs use ca.h and qqbar.h and are described in Exact computation: elementary and machin in Proving identities, binet (with swinnerton_dyer_poly) in Computing in number fields, huge_expr in Large algebraic expressions, and dft (with hilbert_matrix_ca) in Exact linear algebra.

ProgramWhat it doesExample
elementaryEvaluates and simplifies elementary expressions exactly, and decides whether some are zeroelementary
binetComputes Fibonacci numbers with Binet's formula in exact arithmeticbinet 250
machinVerifies variations of Machin's formula for \pimachin
huge_exprProves the equality of two algebraic numbers given by large expressions with nested square rootshuge_expr
dftVerifies the identity \mathrm{DFT}^{-1}(\mathrm{DFT}(x)) = x exactly for vectors of exact real numbers such as x_k = \sqrt{k + 2} or \log(k + 2)dft 8
Cite this page

The FLINT team, “The example programs,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/tutorials/getting-started/example-programs.html (generated 2026-10-20).