padic_mat.h
#include <flint/padic_mat.h>This module implements dense matrices over in the fixed-precision model of padic.h. A matrix is stored as with and an fmpz_mat_t, together with one precision for all entries; it represents the class of modulo 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 by fmpz_mat_mul. Linear algebra over with error tracking (determinants, solving) is available through the generic rings, as gr_mat over padic_radix.
Representation#
A matrix over . The fields are mat (an fmpz_mat_struct), val () and N (the precision). A padic_mat_t is an array of one padic_mat_struct.
The matrix is canonical if some entry of is not divisible by , or if and ; then is the minimum valuation of the entries. It is reduced if it is canonical and all entries of lie in , so that a reduced matrix with 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 is stored to relative precision only.
fmpz_mat_struct * padic_mat(const padic_mat_t A)Returns a pointer to the integer matrix , 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 of , which is not necessarily a unit.
slong padic_mat_get_val(const padic_mat_t A)slong padic_mat_get_prec(const padic_mat_t A)Return the valuation and the precision of .
slong padic_mat_nrows(const padic_mat_t A)slong padic_mat_ncols(const padic_mat_t A)Return the number of rows and columns of .
Memory management#
void padic_mat_init(padic_mat_t A, slong r, slong c)void padic_mat_init2(padic_mat_t A, slong r, slong c, slong prec)Initialise as the zero matrix with rows and columns and precision PADIC_DEFAULT_PREC (that is, 20), respectively prec.
void padic_mat_clear(padic_mat_t A)Clears .
void _padic_mat_canonicalise(padic_mat_t A, const padic_ctx_t ctx)Brings into canonical form by dividing by the largest power of dividing all entries; sets if . No reduction.
void _padic_mat_reduce(padic_mat_t A, const padic_ctx_t ctx)Reduces the canonical matrix modulo , setting it to zero if .
void padic_mat_reduce(padic_mat_t A, const padic_ctx_t ctx)Canonicalises and reduces .
int padic_mat_is_empty(const padic_mat_t A)int padic_mat_is_square(const padic_mat_t A)Return whether has zero rows or zero columns, respectively as many rows as columns.
int padic_mat_is_canonical(const padic_mat_t A, const padic_ctx_t ctx)Returns whether is in canonical form.
int padic_mat_is_reduced(const padic_mat_t A, const padic_ctx_t ctx)Returns whether is reduced: empty, or zero with , or canonical with and all entries less than . 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 to , reduced to the precision of .
void padic_mat_swap(padic_mat_t A, padic_mat_t B)Swaps and , including dimensions, valuations and precisions, in constant time.
void padic_mat_swap_entrywise(padic_mat_t mat1, padic_mat_t mat2)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.
void padic_mat_zero(padic_mat_t A)Sets to the zero matrix.
void padic_mat_one(padic_mat_t A)Sets the square matrix to the identity matrix, or to zero if its precision is not positive.
void padic_mat_set_fmpq_mat(padic_mat_t B, const fmpq_mat_t A, const padic_ctx_t ctx)Sets to the rational matrix , reduced to the precision of . The valuation of is the minimum valuation of the entries of .
void padic_mat_get_fmpq_mat(fmpq_mat_t B, const padic_mat_t A, const padic_ctx_t ctx)Sets the rational matrix to .
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 , that is, to 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 of rop to op and restores canonical form. If op has smaller valuation than rop, all entries are multiplied by a power of . 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#
int padic_mat_equal(const padic_mat_t A, const padic_mat_t B)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.
int padic_mat_is_zero(const padic_mat_t A)Returns whether is the zero matrix (with ).
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)int padic_mat_print_pretty(const padic_mat_t A, const padic_ctx_t ctx)Print 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#
void padic_mat_randtest(padic_mat_t A, flint_rand_t state, const padic_ctx_t ctx)Sets to a random reduced matrix, with valuation drawn as for padic_randtest.
Transpose#
void padic_mat_transpose(padic_mat_t B, const padic_mat_t A)Sets to the transpose of . The precision of 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 to , reduced, for nonempty matrices with , 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 to , 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 to 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 to , reduced.
void _padic_mat_neg(padic_mat_t B, const padic_mat_t A)Sets to 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 to , reduced.
Scalar operations#
void _padic_mat_scalar_mul_padic(padic_mat_t B, const padic_mat_t A, const padic_t c, const padic_ctx_t ctx)void _padic_mat_scalar_mul_fmpz(padic_mat_t B, const padic_mat_t A, const fmpz_t c, const padic_ctx_t ctx)Set to in canonical form, without reduction. For an integer its power of is moved into the valuation.
void padic_mat_scalar_mul_padic(padic_mat_t B, const padic_mat_t A, const padic_t c, const padic_ctx_t ctx)void padic_mat_scalar_mul_fmpz(padic_mat_t B, const padic_mat_t A, const fmpz_t c, const padic_ctx_t ctx)Set to , reduced.
void padic_mat_scalar_div_fmpz(padic_mat_t B, const padic_mat_t A, const fmpz_t c, const padic_ctx_t ctx)Sets to , reduced. The power of in is subtracted from the valuation and the rest of is inverted modulo . Throws if .
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 to , 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 . Allows aliasing.
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).
@misc{flint-doc-padic-mat-index,
author = {{The FLINT team}},
title = {{padic\_mat.h (module overview)}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/padic_mat/index.html},
note = {Generated 2026-11-02}
}