FLINT3.7.0-dev
Module · 61 functions

fmpz_poly_mat.h

#include <flint/fmpz_poly_mat.h>

This module implements dense matrices whose entries are polynomials in Z[x]\mathbb{Z}[x] (fmpz_poly_t). Besides arithmetic, it provides multiplication by Kronecker substitution, which turns a product of polynomial matrices into one product of integer matrices handled by fmpz_mat_mul, and linear algebra over the integral domain Z[x]\mathbb{Z}[x] by fraction-free elimination: determinants (also by evaluation and interpolation), ranks, inverses, solutions of linear systems and nullspaces, with results expressed over a common polynomial denominator. The algorithms are described in Matrices of polynomials and Fraction-free elimination.

AlgorithmMatrices of polynomialsHow FLINT multiplies matrices over Z[x]\mathbb{Z}[x] and (Z/nZ)[x](\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.

Types and conventions#

An fmpz_poly_mat_struct has the fields entries (a pointer to the entry in row 0, column 0), r and c (the numbers of rows and columns) and stride (the distance between the starts of consecutive rows). An fmpz_poly_mat_t is an array of one fmpz_poly_mat_struct.

Matrices with zero rows or columns are allowed. Outputs must be initialised with the dimensions of the result; dimensions are not checked. Unless stated otherwise, outputs may be aliased with inputs only for entrywise operations.

Memory management#

Initialises mat as a rows by cols matrix of zero polynomials. Throws if rows⋅cols\mathit{rows} \cdot \mathit{cols} overflows an slong.

Initialises mat as a copy of src.

Frees the memory used by mat. Must not be called on a window.

Swaps two matrices in constant time by swapping their structs (not for windows), respectively swaps the entries of two matrices of the same dimensions one by one.

Entries and dimensions#

fmpz_poly_struct * fmpz_poly_mat_entry(const fmpz_poly_mat_t mat, slong i, slong j)

Returns a pointer to the entry in row ii and column jj, which can be used with the functions of fmpz_poly.h.

Returns the number of rows, respectively columns, of mat.

Returns 1 if mat has no rows or no columns, respectively as many rows as columns, and 0 otherwise.

Returns ±b\pm b, where bb is the largest bit size of the absolute value of a coefficient of an entry of AA, negative if some coefficient is negative.

Returns the largest length of an entry of AA (0 if all entries are zero).

Windows and concatenation#

Initialises window as the submatrix of mat formed by rows r1r_1 to r2−1r_2 - 1 and columns c1c_1 to c2−1c_2 - 1, sharing its entries with mat. The bounds are checked only by FLINT_ASSERT.

Releases a window. This does nothing at present.

Sets res to mat1 placed to the left of, respectively above, mat2, whose dimensions must be compatible; res must have the dimensions of the result.

Input and output#

void fmpz_poly_mat_print(const fmpz_poly_mat_t mat, const char * x)

Prints mat to stdout: a header <r x c matrix over Z[x]> (with the variable name x), then each row in square brackets with the entries printed by fmpz_poly_print_pretty and separated by commas, then an empty line.

Random matrices#

Sets each entry to a random polynomial of length up to len with signed, respectively nonnegative, coefficients of up to bits bits.

Sets each entry, with probability density, to a random nonzero polynomial of length up to len with coefficients of up to bits bits, and to zero otherwise.

Comparison and special matrices#

Returns 1 if the matrices have the same dimensions and entries, and 0 otherwise.

Returns 1 if mat is zero, respectively has the constant 1 on the main diagonal and zeros elsewhere (it need not be square), and 0 otherwise.

Sets mat to the zero matrix, respectively to the matrix with the constant 1 on the main diagonal and zeros elsewhere.

Basic arithmetic#

Copies mat2 to mat1, which must have the same dimensions.

Sets BB to the transpose of AA; BB may be AA if it is square.

Truncates every entry of AA to length len (reduces it modulo xlenx^{\mathit{len}}), in place.

Sets the integer matrix BB to AA evaluated at xx.

Sets C=A+BC = A + B, C=A−BC = A - B, respectively B=−AB = -A. Aliasing is allowed.

Sets B=cAB = cA for a polynomial, respectively integer, cc. Aliasing is allowed.

Sets trace to the sum of the diagonal entries of the square matrix mat. Throws if mat is not square.

Multiplication#

Sets C=ABC = AB. CC may be AA or BB. fmpz_poly_mat_mul_classical computes each entry as a sum of polynomial products; fmpz_poly_mat_mul_KS packs the entries into integers by Kronecker substitution and multiplies the integer matrices with fmpz_mat_mul. fmpz_poly_mat_mul uses the classical algorithm if a dimension is less than 8 and Kronecker substitution otherwise. See Multiplication.

Sets CC to ABAB with every entry truncated to length len, computing only the needed coefficients of each polynomial product. CC may be AA or BB.

Sets B=A2B = A^2 for a square matrix AA; BB may be AA. The classical version uses five polynomial products for 2×22 \times 2 matrices; fmpz_poly_mat_sqr uses it for dimension less than 8 and Kronecker substitution otherwise.

Sets BB to A2A^2 with every entry truncated to length len.

Sets B=AexpB = A^{\mathit{exp}} for a square matrix AA by binary powering. A0A^0 is the identity. BB may be AA but must not be a window.

Sets BB to AexpA^{\mathit{exp}} with every entry truncated to length len, truncating after every multiplication. BB may be AA but must not be a window.

Sets res to the product of the nn matrices factors[0], ..., factors[n-1], all of the same square dimension, computed by a balanced product tree. The empty product is the identity.

Row reduction#

Returns the index of the first row rr with start_row ≤r<\le r < end_row whose entry in column cc is nonzero, or −1-1 if there is none.

Returns the index of a row rr with start_row ≤r<\le r < end_row whose entry in column cc is nonzero, choosing one of least length and, among those, with coefficients of least bit size; returns −1-1 if all entries are zero. Small pivots keep the entries of fraction-free elimination small.

slong fmpz_poly_mat_fflu(fmpz_poly_mat_t B, fmpz_poly_t den, slong * perm, const fmpz_poly_mat_t A, int rank_check)

Computes a fraction-free LU decomposition of AA in BB and returns the rank rr of AA over Q(x)\mathbb{Q}(x). den is set to the last pivot, a nonzero r×rr \times r minor of AA (1 if r=0r = 0). Row exchanges are applied to perm if it is not NULL. Pivots are chosen with fmpz_poly_mat_find_pivot_partial. If rank_check is set, the function returns 0 with den = 0 as soon as a column without pivot is found. BB may be AA.

More

Sets (BB, den) to the reduced row echelon form of AA over Q(x)\mathbb{Q}(x) and returns the rank: B/denB/\mathit{den} is in reduced row echelon form, with den on the pivot positions. Uses fraction-free elimination followed by fraction-free back substitution. BB may be AA.

Determinant, rank and trace#

Sets det to the determinant of the square matrix AA. fmpz_poly_mat_det_fflu uses fraction-free elimination; fmpz_poly_mat_det_interpolate evaluates AA at L=n(ℓ−1)+1L = n(\ell - 1) + 1 consecutive integers around 0, where ℓ\ell is the largest length of an entry, computes the integer determinants with fmpz_mat_det, and interpolates. fmpz_poly_mat_det uses explicit formulas for n≤2n \le 2, fraction-free elimination for n<15n < 15 and interpolation otherwise.

Full documentation

Returns the rank of AA over Q(x)\mathbb{Q}(x), computed by fraction-free elimination.

Full documentation

Solving and inversion#

For a square AA of dimension nn and an n×kn \times k matrix BB, sets (XX, den) with AX=den⋅BAX = \mathit{den} \cdot B and den=det⁡A\mathit{den} = \det A, and returns 1 if AA is nonsingular; returns 0 with den = 0 if AA is singular. Both use fraction-free elimination (fmpz_poly_mat_solve calls fmpz_poly_mat_solve_fflu). XX may be AA but not BB.

Solves AX=den⋅BAX = \mathit{den} \cdot B given the output FFLU, den, perm of fmpz_poly_mat_fflu for a nonsingular AA, with fraction-free forward and back substitution. The sign of the permutation is not taken into account. perm must not be NULL, and XX must not be BB; both raise an exception.

Sets (Ainv, den) to the inverse of the square matrix AA, so that A⋅Ainv=den⋅IA \cdot \mathit{Ainv} = \mathit{den} \cdot I with den=det⁡A\mathit{den} = \det A, and returns 1 if AA is nonsingular; returns 0 if it is singular. Ainv may be AA.

Sets the first n−rn - r columns of the n×nn \times n matrix res to a basis of the right nullspace of the m×nm \times n matrix mat over Q(x)\mathbb{Q}(x), with polynomial entries, and returns n−rn - r; the other columns are set to zero. The basis is read off from fmpz_poly_mat_rref.

Cite this page

The FLINT team, “fmpz_poly_mat.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/fmpz_poly_mat/index.html (generated 2026-11-02).