FLINT3.7.0-dev
Module · 49 functions

padic_mat.h

#include <flint/padic_mat.h>

This module implements dense matrices over \mathbf{Q}_p in the fixed-precision model of padic.h. A matrix is stored as p^v M with v \in \mathbb{Z} and M an fmpz_mat_t, together with one precision N for all entries; it represents the class of p^v M modulo p^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 \mathbb{Z} by fmpz_mat_mul. Linear algebra over \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 p^v M over \mathbf{Q}_p. The fields are mat (an fmpz_mat_struct), val (v) and N (the precision). A padic_mat_t is an array of one padic_mat_struct.

The matrix is canonical if some entry of M is not divisible by p, or if M = 0 and v = 0; then v is the minimum valuation of the entries. It is reduced if it is canonical and all entries of M lie in [0, p^{N - v}), so that a reduced matrix with v \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 > v is stored to relative precision N - w only.

Returns a pointer to the integer matrix M, 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) of M, which is not necessarily a unit.

The valuation v and the precision N of A, as lvalues.

Return the valuation v and the precision N of A.

Return the number of rows and columns of A.

Memory management#

Initialise A as the zero matrix with r rows and c columns and precision PADIC_DEFAULT_PREC (that is, 20), respectively prec.

Clears A.

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

Reduces the canonical matrix A modulo p^N, setting it to zero if v \ge N.

Canonicalises and reduces A.

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

Returns whether A is in canonical form.

Returns whether A is reduced: empty, or zero with v = 0, or canonical with v < N and all entries less than p^{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 B to A, reduced to the precision of B.

Swaps A and B, 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 A to the zero matrix.

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

Sets B to the rational matrix A, reduced to the precision of B. The valuation of B is the minimum valuation of the entries of A.

Sets the rational matrix B to p^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), that is, to p^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) of rop to op and restores canonical form. If op has smaller valuation than rop, all entries are multiplied by a power of p. 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 A is the zero matrix (with v = 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 A 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 A to a random reduced matrix, with valuation drawn as for padic_randtest.

Transpose#

Sets B to the transpose of A. The precision of B 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 C to A + B, reduced, for nonempty matrices with \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 C to A + 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 C to A - 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 C to A - B, reduced.

Sets B to -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 B to -A, reduced.

Scalar operations#

Set B to cA in canonical form, without reduction. For an integer c its power of p is moved into the valuation.

Set B to cA, reduced.

Sets B to A/c, reduced. The power of p in c is subtracted from the valuation and the rest of c is inverted modulo p^{N - v}. Throws if c = 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 C to AB, 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 p. 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-10-20).