FLINT3.7.0-dev
Algorithm

Simplification and closed forms

Cost
The automatic rules cost a few exact or numerical tests per operation; recognising an algebraic number of degree dd costs LLL reductions of dimension d+1d + 1 at increasing precision, each followed by an exact verification.

Simplification has no canonical meaning for exact real and complex numbers: a "simplest" form is not defined in general, and finding one would require at least deciding equality. FLINT therefore aims at a weaker goal: keep representations small and recognise equal numbers as often as possible, so that zero tests succeed and results are readable.

Canonical forms where available#

Rational numbers are stored as reduced fractions, and an element of a field Q(a)\mathbb{Q}(a) with a single algebraic generator as a polynomial in aa of degree less than deg⁡a\deg a; both are canonical once the field is fixed. ca_set_qqbar chooses the field: a quadratic number is placed in Q(N)\mathbb{Q}(\sqrt{N}) with NN the discriminant of its minimal polynomial divided by its small square factors (found by smooth factorisation), so that all quadratic numbers of one field share it, and other algebraic numbers generate their own field. After every operation, ca_condense_field moves results to the smallest of these fields that the representation allows (rational results to Q\mathbb{Q}).

Rewriting rules#

The functions of ca.h apply rewriting rules when they create new extension numbers. The most important ones are:

  • Exponentials: e0=1e^0 = 1, elog⁡z=ze^{\log z} = z, e(p/q)log⁡z=zp/qe^{(p/q)\log z} = z^{p/q}, ealog⁡z+s=zaese^{a \log z + s} = z^a e^{s} for rational aa, and eπip/qe^{\pi i p/q} becomes an algebraic root of unity (for moderate qq).
  • Logarithms: log⁡1=0\log 1 = 0, log⁡(ez)=z+2πik\log(e^z) = z + 2\pi i k, log⁡za=alog⁡z+2πik\log z^a = a \log z + 2 \pi i k and log⁡z=12log⁡z+2πik\log \sqrt{z} = \frac{1}{2} \log z + 2\pi i k, with the integer kk determined by a numerical evaluation (which is exact here, since kk is an integer and the error is small), log⁡(−x)=log⁡x+πi\log(-x) = \log x + \pi i for x>0x > 0, and logarithms of roots of unity become rational multiples of πi\pi i.
  • Powers and roots: integer powers are expanded when small, (za)b=zab(z^a)^b = z^{ab} when the branches allow it, and x\sqrt{x} is computed by writing x=A2Bx = A^2 B with a heuristic factorisation of the representation of xx (rational content and polynomial factors in the generators, with smooth factorisation of integers), giving ±AB\pm A \sqrt{B}; square roots of algebraic numbers are computed exactly when the degree does not grow, and −x=ix\sqrt{-x} = i \sqrt{x} for x>0x > 0.
  • Complex parts: ∣x∣|x|, sgn⁡x\operatorname{sgn} x, Re⁡x\operatorname{Re} x, Im⁡x\operatorname{Im} x and arg⁡x\arg x are computed exactly when xx is algebraic (within the degree limit), and arg⁡x\arg x is a rational multiple of π\pi when sgn⁡x\operatorname{sgn} x is a root of unity.
  • Trigonometric functions: with the default exponential form, values at rational multiples of π\pi become elements of cyclotomic fields; inverse trigonometric functions of simple algebraic numbers become rational multiples of π\pi.

Each rule either is an identity valid for all arguments or is applied only after the conditions on branches have been checked exactly.

Relations between generators#

When several generators meet in one field, the relations between them are found and used to reduce elements (see Formal fields and the ideal of relations). This simplifies, for example, exe−xe^{x} e^{-x} to 1, log⁡8−3log⁡2\log 8 - 3 \log 2 to 0 and 23\sqrt{2}\sqrt{3} to 6\sqrt{6} when 6\sqrt{6} occurs in the same field. For the zero test, the generators are additionally rewritten in a normal form based on complex exponentials and logarithms (see Proving equality); this rewriting is not applied to the results of ordinary operations, because it tends to make them less readable.

Recognising algebraic numbers#

Several operations on algebraic numbers search for an integer relation c0v0+⋯+ckvk=0c_0 v_0 + \cdots + c_k v_k = 0 between numerical values vjv_j given as balls, with the LLL algorithm [LLL1982] applied to the lattice spanned by the rows of

(Ik+1v~),\begin{pmatrix} I_{k+1} & \tilde v \end{pmatrix},

where the columns v~\tilde v hold the real parts (and, for nonreal input, the imaginary parts) scaled by 2p2^p and rounded to integers (FLINT uses fmpz_lll, see fmpz_lll). The first vector of the reduced basis gives candidate coefficients cjc_j; the remaining 5% of the precision is used to check that ∑cjvj\sum c_j v_j contains zero (_qqbar_acb_lindep). If a relation with coefficients of bb bits exists, it is found once pp is somewhat larger than (k+1)b(k+1) b; but a relation found by LLL is only a candidate, which may be spurious, so every use is followed by an exact verification:

  • qqbar_guess looks for an annihilating polynomial of a number zz with vj=zjv_j = z^j, factors it and selects the factor vanishing at zz; the result is not verified (the input is only a ball), so it is a guess.
  • qqbar_express_in_field looks for x=f(α)x = f(\alpha) with vj=αjv_j = \alpha^j for j<deg⁡αj < \deg \alpha and vdeg⁡α=xv_{\deg \alpha} = x, and verifies the result exactly with qqbar_equal_fmpq_poly_val. If x∈Q(α)x \in \mathbb{Q}(\alpha), a sufficiently high precision always finds it.
  • Within arithmetic, the same searches express one operand in the field of the other or both in a cyclotomic field, and guess minimal polynomials of results, which are then proved with an explicit separation bound (see Operands in a common field).

Closed forms#

qqbar_get_fexpr_formula converts an algebraic number to an expression with radicals and trigonometric functions when it can (see Symbolic expressions and closed forms). Quadratic numbers are written as (a+bc)/q(a + b \sqrt{c})/q with cc made small by smooth factorisation (qqbar_get_quadratic). For a number xx of degree dd whose field may be contained in a cyclotomic field Q(ζn)\mathbb{Q}(\zeta_n) (by the Kronecker–Weber theorem, these are exactly the numbers with an abelian Galois group [Was1997]), candidate nn with d∣φ(n)d \mid \varphi(n) are tried, xx is expressed in Q(ζn)\mathbb{Q}(\zeta_n) with LLL and the expression is verified exactly; then xx is written with e2πik/ne^{2\pi i k/n} or with cos⁡\cos and sin⁡\sin of rational multiples of π\pi. Numbers whose minimal polynomial is P(tk)P(t^k) are reduced to xkx^k (deflation), and nonreal numbers can be split into real and imaginary parts or modulus and sign. General solutions of cubics and quartics by radicals are not implemented.

Use in FLINT#

Referenced from#

References#

Cite this page

The FLINT team, “Simplification and closed forms,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/exact/simplification.html (generated 2026-11-02).