FLINT3.7.0-dev
Algorithm

Fraction-free elimination

Cost
O(mnr)O(mnr) ring operations for an m×nm \times n matrix of rank rr; over Z\mathbb{Z} with bb-bit entries the operands have O(n(b+log⁡n))O(n(b + \log n)) bits, giving O(n3M(n(b+log⁡n)))O(n^3 M(n(b + \log n))) word operations for an n×nn \times n matrix.

Let RR be an integral domain, such as Z\mathbb{Z}, Z[x]\mathbb{Z}[x] or Fp[x]\mathbb{F}_p[x], and AA an m×nm \times n matrix over RR. Gaussian elimination over the fraction field creates quotients whose numerators and denominators grow; removing common factors needs gcd computations, which are expensive or unavailable. Fraction-free elimination keeps all entries in RR, uses only exact divisions, and bounds every intermediate entry by a minor of AA [Bar1968; NakTurWil1997]. It is the method of choice for small matrices over Z\mathbb{Z} and for matrices over polynomial rings, where modular methods are less developed.

Generic version#

gr_mat_fflu implements the algorithm below over any ring with exact division, and gr_mat_det_fflu, gr_mat_rank_fflu, gr_mat_nonsingular_solve_fflu, gr_mat_nonsingular_solve_den_fflu and gr_mat_rref_den_fflu build on it. The specialised versions are separate implementations with the same structure:

  • fmpz_mat_fflu over Z\mathbb{Z} chooses the first nonzero pivot, and while the entries fit in a word computes the updates in two-word arithmetic with a precomputed inverse of the previous pivot;
  • fmpz_poly_mat_fflu and nmod_poly_mat_fflu over Z[x]\mathbb{Z}[x] and (Z/nZ)[x](\mathbb{Z}/n\mathbb{Z})[x] choose, among the nonzero entries of the column, one of least degree and, over Z[x]\mathbb{Z}[x], with the smallest coefficients (fmpz_poly_mat_find_pivot_partial), which keeps the entries small;
  • ca_mat_fflu over exact real and complex numbers chooses pivots with zero tests that may fail (linear algebra over exact numbers).

Bareiss' algorithm#

Algorithm 1: Fraction-free elimination

Input: A∈Rm×nA \in R^{m \times n}.

Output: the rank rr, a row permutation, and the matrix BB described below; den =pr−1= p_{r-1}.

  1. B←AB \gets A, p−1←1p_{-1} \gets 1, k←0k \gets 0 (pivot row), c←0c \gets 0 (column).
  2. While k<mk < m and c<nc < n:

    1. find a row i≥ki \ge k with Bic≠0B_{ic} \ne 0; if there is none, c←c+1c \gets c + 1 and continue; otherwise swap rows ii and kk;
    2. pk←Bkcp_k \gets B_{kc}, ck←cc_k \gets c;
    3. for all i>ki > k and j>cj > c: Bij←(pkBij−BicBkj)/pk−1B_{ij} \gets (p_k B_{ij} - B_{ic} B_{kj}) / p_{k-1};
    4. k←k+1k \gets k + 1, c←c+1c \gets c + 1.
  3. Return r=kr = k.

The divisions in step 2.3 are exact. This follows from Sylvester's identity.

Theorem 1. Assume that no row exchanges are needed and that the pivot columns are 0,1,…,r−10, 1, \ldots, r - 1. After the pivots p0,…,pk−1p_0, \ldots, p_{k-1} have been processed, for i,j≥ki, j \ge k,

Bij=det⁡A[{0,…,k−1,i},{0,…,k−1,j}],B_{ij} = \det A[\{0, \ldots, k - 1, i\}, \{0, \ldots, k - 1, j\}],

the minor of AA formed by the leading kk rows and columns bordered by row ii and column jj. In particular pkp_k is the leading principal (k+1)×(k+1)(k+1) \times (k+1) minor of AA.

Proof. By induction on kk; for k=0k = 0 the claim is Bij=AijB_{ij} = A_{ij}. Suppose it holds before pivot kk is processed, and let T0T_0 be the leading k×kk \times k submatrix of AA, with det⁡T0=pk−1\det T_0 = p_{k-1} (1 if k=0k = 0), and T=A[{0,…,k,i},{0,…,k,j}]T = A[\{0, \ldots, k, i\}, \{0, \ldots, k, j\}]. The four (k+1)×(k+1)(k+1) \times (k+1) minors of TT that contain T0T_0 are, by induction, pkp_k, BkjB_{kj}, BikB_{ik} and BijB_{ij}, and Sylvester's determinant identity states

det⁡(T)det⁡(T0)=pkBij−BikBkj.\det(T) \det(T_0) = p_k B_{ij} - B_{ik} B_{kj}.

Hence the update of step 2.3 produces det⁡T\det T, which is the claim for k+1k + 1.

With row exchanges, the same holds for the row-permuted matrix, and with skipped columns for the matrix restricted to the pivot columns and the column jj. Consequently every intermediate entry is a minor of AA: over Z\mathbb{Z} it is bounded by Hadamard's inequality (Bounds), with about n(b+12log⁡2n)n(b + \frac12 \log_2 n) bits for bb-bit entries, and over K[x]K[x] its degree is at most nn times the largest degree. Gaussian elimination over Q\mathbb{Q} without gcds would instead produce entries whose sizes grow exponentially with kk.

For a nonsingular n×nn \times n matrix, the last pivot is pn−1=det⁡(PA)=sgn⁡(P)det⁡Ap_{n-1} = \det(PA) = \operatorname{sgn}(P) \det A, so fmpz_mat_det_bareiss returns den with the sign of the permutation. Each of the O(mnr)O(mnr) updates costs two multiplications and one exact division of minors, so over Z\mathbb{Z} the cost is O(n3M(n(b+log⁡n)))O(n^3 M(n(b + \log n))) word operations for an n×nn \times n matrix, that is O(n5b2)O(n^5 b^2) with classical integer multiplication. This is competitive with the modular methods of Multimodular and p-adic linear algebra over the integers only for small nn (FLINT's crossovers are n≈15n \approx 15 to 25).

The fraction-free LU decomposition#

FLINT stores the result in place, like an LU decomposition: the upper part of BB, from the pivot of each row on, holds the fraction-free echelon form UU, and below each pivot pkp_k the entries of column ckc_k are kept as they were when pkp_k was chosen (step 2.3 does not change column cc). Let LL be the lower triangular matrix formed by these columns, with the pivots pkp_k on its diagonal.

Proposition 2. For a nonsingular n×nn \times n matrix AA with row permutation PP,

PA=L D−1 U,D=diag⁡(p−1p0, p0p1, …, pn−2pn−1).PA = L \, D^{-1} \, U, \qquad D = \operatorname{diag}(p_{-1} p_0, \, p_0 p_1, \, \ldots, \, p_{n-2} p_{n-1}).

This is the fraction-free LU decomposition of [NakTurWil1997; Jef2010]. For the 4×44 \times 4 example of Example, with pivots 2,5,18,822, 5, 18, 82, one checks A=Ldiag⁡(2,10,90,1476)−1UA = L \operatorname{diag}(2, 10, 90, 1476)^{-1} U.

Solving#

To solve AX=BAX = B for nonsingular AA, fmpz_mat_solve_fflu_precomp applies to PBPB the same fraction-free updates as step 2.3 (forward substitution: the column jj of the right-hand side is updated like a column of AA), which yields the last column of the elimination of the augmented matrix (A∣B)(A \mid B), and then performs back substitution

xi=pn−1yi−∑j>iUijxjUii,i=n−1,…,0,x_i = \frac{p_{n-1} y_i - \sum_{j > i} U_{ij} x_j}{U_{ii}}, \qquad i = n - 1, \ldots, 0,

where yy is the transformed right-hand side. The result is X=pn−1A−1BX = p_{n-1} A^{-1} B, which is integral by Cramer's rule since pn−1=±det⁡Ap_{n-1} = \pm \det A, so all divisions are exact. fmpz_mat_solve_fflu then fixes the sign, returning den=det⁡A\mathit{den} = \det A. For a rank-deficient AA the same procedure, with the non-pivot unknowns set to zero, either produces a candidate or meets an inexact division and reports failure; fmpz_mat_can_solve_fflu then checks the remaining equations exactly.

Reduced echelon form#

Let the first rr rows of the echelon form be (U∣V)(U \mid V) up to a permutation of the columns, where UU is the r×rr \times r upper triangular matrix of pivot columns, with the pivots p0,…,pr−1p_0, \ldots, p_{r-1} on its diagonal. The reduced echelon form over the fraction field is (I∣U−1V)(I \mid U^{-1} V) in the original column order. Since (U∣V)(U \mid V) is obtained from the pivot rows (AP∣AN)(A_P \mid A_N) of AA by invertible row operations, U−1V=AP−1ANU^{-1} V = A_P^{-1} A_N, and pr−1U−1V=±det⁡(AP)AP−1ANp_{r-1} U^{-1} V = \pm \det(A_P) A_P^{-1} A_N is integral by Cramer's rule. fmpz_mat_rref_fflu and fmpz_poly_mat_rref compute it by back substitution with exact divisions by the pivots, one non-pivot column at a time, and set the pivot columns to pr−1p_{r-1} times unit vectors. This is fraction-free Gauss–Jordan elimination [NakTurWil1997] restricted to the non-pivot columns, which are all that change.

Use in FLINT#

Referenced from#

References#

  • [Bar1968] E. H. Bareiss, "Sylvester's identity and multistep integer-preserving Gaussian elimination", Mathematics of Computation 22 (1968), 565–578. https://doi.org/10.1090/S0025-5718-1968-0226829-0
  • [NakTurWil1997] Nakos, George and Turner, Peter and Williams, Robert : Fraction-free algorithms for linear and polynomial equations, ACM SIGSAM Bull. 31 (1997) 3 11–19
  • [Jef2010] D. J. Jeffrey, "LU factoring of non-invertible matrices", ACM Communications in Computer Algebra 44:1 (2010), 1–8. https://doi.org/10.1145/1838599.1838602
Cite this page

The FLINT team, “Fraction-free elimination,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/linear-algebra/fraction-free.html (generated 2026-11-02).