FLINT3.7.0-dev
Module · 49 functions

padic_mat.h

#include <flint/padic_mat.h>

This module implements dense matrices over Qp\mathbf{Q}_p in the fixed-precision model of padic.h. A matrix is stored as pvMp^v M with v∈Zv \in \mathbb{Z} and MM an fmpz_mat_t, together with one precision NN for all entries; it represents the class of pvMp^v M modulo pNZpp^N \mathbf{Z}_p entrywise. Every function computes its result exactly from the stored inputs and reduces it to the precision of the output. The module provides conversions, entry access, addition, scalar multiplication and matrix multiplication; multiplication is done over Z\mathbb{Z} by fmpz_mat_mul. Linear algebra over Qp\mathbf{Q}_p with error tracking (determinants, solving) is available through the generic rings, as gr_mat over padic_radix.

Overviewp-adic arithmetic in FLINTThe modules for p-adic numbers, their precision models and representations, and which algorithm each function uses for inversion, square roots, the exponential and logarithm, Teichmüller lifts, the Frobenius map, norms and traces.

Representation#

A matrix pvMp^v M over Qp\mathbf{Q}_p. The fields are mat (an fmpz_mat_struct), val (vv) and N (the precision). A padic_mat_t is an array of one padic_mat_struct.

The matrix is canonical if some entry of MM is not divisible by pp, or if M=0M = 0 and v=0v = 0; then vv is the minimum valuation of the entries. It is reduced if it is canonical and all entries of MM lie in [0,pN−v)[0, p^{N - v}), so that a reduced matrix with v≥Nv \ge N is zero. Functions require canonical inputs and produce reduced outputs unless stated otherwise; dimensions must be compatible, which is not checked. One precision for all entries means that an entry of valuation w>vw > v is stored to relative precision N−wN - w only.

Returns a pointer to the integer matrix MM, for use with the functions of fmpz_mat.h.

fmpz * padic_mat_entry(const padic_mat_t A, slong i, slong j)

Returns a pointer to the entry (i,j)(i, j) of MM, which is not necessarily a unit.

The valuation vv and the precision NN of AA, as lvalues.

Return the valuation vv and the precision NN of AA.

Return the number of rows and columns of AA.

Memory management#

Initialise AA as the zero matrix with rr rows and cc columns and precision PADIC_DEFAULT_PREC (that is, 20), respectively prec.

Clears AA.

Brings AA into canonical form by dividing MM by the largest power of pp dividing all entries; sets v=0v = 0 if M=0M = 0. No reduction.

Reduces the canonical matrix AA modulo pNp^N, setting it to zero if v≥Nv \ge N.

Canonicalises and reduces AA.

Return whether AA has zero rows or zero columns, respectively as many rows as columns.

Returns whether AA is in canonical form.

Returns whether AA is reduced: empty, or zero with v=0v = 0, or canonical with v<Nv < N and all entries less than pN−vp^{N - v}. The entries are not checked to be nonnegative.

Assignment and conversion#

void padic_mat_set(padic_mat_t B, const padic_mat_t A, const padic_ctx_t ctx)

Sets BB to AA, reduced to the precision of BB.

Swaps AA and BB, including dimensions, valuations and precisions, in constant time.

Swaps the entries of the integer matrices of mat1 and mat2, which must have the same dimensions, one by one. The valuations and precisions are not swapped, so the result is meaningful only if they agree.

Sets AA to the zero matrix.

Sets the square matrix AA to the identity matrix, or to zero if its precision is not positive.

Sets BB to the rational matrix AA, reduced to the precision of BB. The valuation of BB is the minimum valuation of the entries of AA.

Sets the rational matrix BB to pvMp^v M.

Entries#

Because all entries share one valuation, setting an entry may rescale the whole matrix, and an entry is not directly available as a padic_t.

void padic_mat_get_entry_padic(padic_t rop, const padic_mat_t op, slong i, slong j, const padic_ctx_t ctx)

Sets rop to the entry (i,j)(i, j), that is, to pvMijp^v M_{ij} reduced to the precision of rop.

void padic_mat_set_entry_padic(padic_mat_t rop, slong i, slong j, const padic_t op, const padic_ctx_t ctx)

Sets the entry (i,j)(i, j) of rop to op and restores canonical form. If op has smaller valuation than rop, all entries are multiplied by a power of pp. The value is not reduced to the precision of rop; call padic_mat_reduce afterwards if op may have a higher precision than rop.

Comparison#

Returns whether the stored values are equal, that is, whether the valuations and the integer matrices agree. The matrices must be canonical; the precisions are not compared.

Returns whether AA is the zero matrix (with v=0v = 0).

Input and output#

int padic_mat_fprint(FILE * file, const padic_mat_t A, const padic_ctx_t ctx)
int padic_mat_print(const padic_mat_t A, const padic_ctx_t ctx)

Print the number of rows, a space, the number of columns, two spaces and the entries row by row, separated by spaces. In the mode PADIC_TERSE the entries are printed as rationals, in PADIC_VAL_UNIT in the form p^w*u; the mode PADIC_SERIES is not supported and throws. Return 1.

int padic_mat_fprint_pretty(FILE * file, const padic_mat_t A, const padic_ctx_t ctx)

Print AA as a list of rows in square brackets, one row per line, each entry in the printing mode of the context. Return 1.

Random generation#

Sets AA to a random reduced matrix, with valuation drawn as for padic_randtest.

Transpose#

Sets BB to the transpose of AA. The precision of BB is not applied. Aliasing is allowed for square matrices.

Addition and subtraction#

void _padic_mat_add(padic_mat_t C, const padic_mat_t A, const padic_mat_t B, const padic_ctx_t ctx)

Sets CC to A+BA + B, reduced, for nonempty matrices with ord⁡p(A)≥ord⁡p(B)\operatorname{ord}_p(A) \ge \operatorname{ord}_p(B), which is not checked.

void padic_mat_add(padic_mat_t C, const padic_mat_t A, const padic_mat_t B, const padic_ctx_t ctx)

Sets CC to A+BA + B, reduced.

void _padic_mat_sub(padic_mat_t C, const padic_mat_t A, const padic_mat_t B, const padic_ctx_t ctx)

Sets CC to A−BA - B in canonical form, for nonempty matrices. The result is not reduced in general.

void padic_mat_sub(padic_mat_t C, const padic_mat_t A, const padic_mat_t B, const padic_ctx_t ctx)

Sets CC to A−BA - B, reduced.

Sets BB to −A-A in canonical form; the entries are negated and not reduced.

void padic_mat_neg(padic_mat_t B, const padic_mat_t A, const padic_ctx_t ctx)

Sets BB to −A-A, reduced.

Scalar operations#

Set BB to cAcA in canonical form, without reduction. For an integer cc its power of pp is moved into the valuation.

Set BB to cAcA, reduced.

Sets BB to A/cA/c, reduced. The power of pp in cc is subtracted from the valuation and the rest of cc is inverted modulo pN−vp^{N - v}. Throws if c=0c = 0.

Multiplication#

void padic_mat_mul(padic_mat_t C, const padic_mat_t A, const padic_mat_t B, const padic_ctx_t ctx)

Sets CC to ABAB, reduced. The integer matrices are multiplied with fmpz_mat_mul (Multiplying matrices over the integers), the valuations are added, and the product is canonicalised and reduced: unlike for polynomials, the product of two canonical matrices may be divisible by pp. Allows aliasing.

Cite this page

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