Optimal precision in p-adic linear algebra
- Cost
- Determinant and linear solving: the cost of a blocked LU decomposition with fast matrix multiplication, plus one rank-revealing LU decomposition over per valuation level. Characteristic polynomial: (Berkowitz) for matrices that are cyclic modulo , otherwise an Hessenberg reduction at doubled precision and matrix products modulo .
In the ball model (The ball model of padic_radix) every result comes with a guaranteed precision, but different algorithms for the same problem can guarantee very different precisions: the error terms propagated operation by operation may be much larger than the actual uncertainty of the result. Caruso, Roe and Vaccon [CRV2014; CRV2015; CRV2017] showed how to determine the actual uncertainty from the differential of the function computed, and studied which algorithms attain it; [Car2017] surveys these results. This page describes the methods padic_radix uses to attain the optimal precision for determinants, linear systems and characteristic polynomials.
Differential precision#
Lemma 1 (First- and second-order terms). Let be a polynomial with coefficients in , let , and let with . Then
Hence with , and if for the index attaining the minimum, no better precision holds for all such .
Proof. Expand by Taylor's formula: the coefficients of the terms of degree in are values at of divided derivatives , which are polynomials with coefficients in , so these terms have valuation at least . For the last claim take : the change is plus terms of valuation at least .
For a matrix function the partial derivatives are entries of a matrix: , and for the characteristic polynomial . Non-integral inputs are reduced to integral ones by scaling with a power of . The quantity is the optimal precision below.
Determinants and full pivoting#
Theorem 2 (Full pivoting attains the optimal precision). Let be known to entrywise, with elementary divisors , . Gaussian elimination in ball arithmetic in which each pivot has minimal valuation in the remaining submatrix (full pivoting on valuations) produces pivots of valuations and returns to precision , which is the optimal precision.
Proof. Let be the pivot of the current submatrix , of minimal valuation , and let and be entries of its row and column. An entry becomes , and all four inputs are known to absolute precision . By Proposition 1 of Precision and representation of p-adic numbers the error terms of the update come from (precision ), from and ( and likewise), and from (), so every Schur complement is again known to precision . Elimination is a sequence of row and column operations in followed by the removal of a pivot, so the elementary divisors of the Schur complement are ; since the minimal valuation of the entries of a matrix is its smallest elementary divisor, and makes the valuations visible at precision , the pivots have the valuations . The determinant is the product of the pivots up to sign; a product of balls of absolute precision and valuations has precision . Finally, with for and diagonal, , whose minimal valuation is that of , namely . This is the optimal precision of Lemma 1, attained since .
Other algorithms lose precision. A division-free algorithm (Berkowitz's algorithm, cofactor expansion) computes only sums of products of entries, each known to , so it can guarantee little more than precision , losing up to digits. Elimination that takes the first nonzero entry of a column as pivot loses digits whenever that entry is not of minimal valuation, which for small happens often even for random matrices. Choosing the entry of minimal valuation in the pivot column (partial pivoting) is optimal for matrices that are invertible modulo , where all pivots are units, and nearly optimal in general. Average digits lost against the optimal precision for , entries known to , and matrices with random :
| Berkowitz | first nonzero pivot | column pivoting | full pivoting | |
|---|---|---|---|---|
| 12 | 28 | 2.7 | 0.6 | 0 |
| 40 | 115 | 10.3 | 1.2 | 0 |
| 60 | 173 | 16 | 0.7 | 0 |
Blocked full pivoting#
Full pivoting needs the updated Schur complement before each pivot is chosen, which rules out the blocked algorithms that make LU decomposition fast. However, only valuations matter for the choice of pivots, and these can be read off modulo :
Input: a square matrix over .
Output: .
- If has no nonzero entry, return the determinant of the block of zeros (bounded by the precisions). Otherwise let be the minimal valuation of the entries of .
- Compute a rank-revealing LU decomposition of over ; it selects rows and columns such that the corresponding submatrix of is invertible. Permute them to the front: with , .
- Compute from an LU decomposition of (all of whose pivots have valuation ), and the Schur complement by triangular solves and one matrix product.
- Return , with computed recursively.
The entries of have valuation at least , because has rank and . The pivots of a level have the same valuation , which is minimal in every intermediate Schur complement, so the computation is a full pivoting elimination carried out in blocks, with the same precision. A matrix such that is invertible modulo for the minimal valuation of its entries (in particular a matrix invertible modulo ) needs a single level, that is, one blocked LU decomposition. The cost is that of the blocked LU decomposition, which uses the fast matrix products of Matrix products, plus word operations modulo per level.
Linear systems#
For the differential is , so for entries of and known to and the optimal precision of is
Gauss–Jordan elimination with full pivoting on valuations attains it in experiments, while LU decomposition with column pivoting followed by back substitution loses digits when is not invertible modulo (about 0.3 to 3.6 digits per entry of for and to 20). The difference lies in the order of operations: back substitution computes from the already rounded , whose errors are correlated with those of in a way the ball arithmetic cannot see, whereas Gauss–Jordan elimination eliminates the later pivots from the earlier pivot rows before any division by them.
padic_radix_mat_nonsingular_solve therefore runs Gauss–Jordan elimination by valuation levels on : at each level the pivot block of Algorithm 1 is applied to its rows (LU decomposition and triangular solves), and its columns are eliminated from all the other rows, including the pivot rows of the previous levels, by one matrix product. When is invertible modulo for the minimal valuation , all pivots have valuation and the LU solve with column pivoting is already optimal, so it is used directly. The cost is that of a blocked LU solve. gr_mat_nonsingular_solve and gr_mat_inv call these functions for padic_radix matrices.
Characteristic polynomials#
Write , so that and for . By Lemma 1, for an integral matrix with entries known to the coefficient is known to precision
and to no better precision when the minimum is attained by the first-order term. The higher-order terms are bounded by because their coefficients are minors of , which are integral.
Proposition 3 (Cyclic matrices). If is cyclic modulo (its minimal polynomial modulo has degree ) and all entries are known to , then the optimal precision of every coefficient of is , and any division-free algorithm, such as Berkowitz's, attains it.
Proof. for the monic polynomial of degree . Since are linearly independent modulo , , so some entry of is a unit and . A division-free algorithm computes the coefficients from integral entries known to by additions and multiplications, which preserve absolute precision (Proposition 1 of Precision and representation of p-adic numbers).
Matrices that are not cyclic modulo are where precision is lost: for with and , Berkowitz's algorithm loses 35 digits on the constant coefficient and 11 digits on average, and the division-based algorithms (Hessenberg reduction, Danilevsky's algorithm, see Characteristic and minimal polynomials) lose a few digits on every coefficient, even for generic matrices. padic_radix_mat_charpoly therefore uses a division-free algorithm only for matrices that are integral, of uniform precision and cyclic modulo (tested by the rank of a random Krylov basis over ). Even there it first runs the Hessenberg reduction, which costs operations instead of and loses nothing on matrices that are generic modulo : when all its coefficients come out with precision , they are optimal by Proposition 3, and only otherwise is Berkowitz's algorithm run (at digits and this is about 12 times faster for random matrices). Other matrices get the optimal precision by computing on an exact lift:
Input: with entries known to .
Output: , each coefficient to precision .
- Scale by a power of to make all entries and error terms integral, and let be the exact lift of the entries.
- Compute : run the Hessenberg reduction with pivots of minimal valuation (similarity transformations in , operations) in ball arithmetic on known to for some ; if a coefficient comes out with precision below , increase , and as a last resort use Berkowitz's algorithm, which loses nothing.
- Compute by the recurrence modulo one word (the largest power of below ), which gives when it is smaller; repeat modulo only if a valuation at that bound determines some . These are matrix products over (
nmod_matormpn_mod_mat). - Return the coefficients of with the precisions , scaled back.
Where the bound for the higher-order terms limits the result, Danilevsky's algorithm in ball arithmetic is also run, and the more precise of the two valid results is kept for each coefficient. In the experiments this gives the optimal precision up to a fraction of a digit on average for and . An exact matrix gives the exact characteristic polynomial (computed by fmpz_mat_charpoly), rounded to the context precision. The cost is about that of Berkowitz's algorithm for cyclic matrices and 1.5 to 5 times more for structured ones.
The lift works with digits, where is the scaling, and with entries of of any size. Entries of high valuation are harmless, since everything is computed modulo at most and can be reduced modulo it. A large is not: one entry of valuation among entries known to 20 digits gives , and the lift then works at a million digits for results that carry a few dozen. The lift gives up when exceeds for the largest relative precision of an inexact entry (and for exact matrices whose entries are dominated by powers of or exceed what the context keeps), and Berkowitz's algorithm in ball arithmetic, whose cost follows the precisions of the entries, is used instead.
Use in FLINT#
padic_radix_mat_find_nonzero_pivotchooses pivots of minimal valuation in a column for the generic algorithms ofgr_mat.padic_radix_mat_det_lu_fullandpadic_radix_mat_det_levelsimplement Theorem 2 and Algorithm 1;padic_radix_mat_det(thegr_mat_detmethod) uses the first for small matrices and the second above.padic_radix_mat_nonsingular_solveandpadic_radix_mat_invimplement Linear systems and are thegr_mat_nonsingular_solveandgr_mat_invmethods.padic_radix_mat_charpoly_lift,padic_radix_mat_charpoly_hessenbergand_padic_radix_mat_charpoly_berkowitzimplement the algorithms of Characteristic polynomials, andpadic_radix_mat_charpoly(thegr_mat_charpolymethod) chooses between them.- The context flag
PADIC_RADIX_FAST_LINALGselects the fastest algorithms instead of the optimal ones (the Hessenberg reduction for characteristic polynomials, LU decompositions for linear systems), for computations at high working precision where a few lost digits are cheaper than the optimal algorithms. - The tutorial Interpolation over the p-adic numbers: precision and Mahler's basis shows the optimal precision of a linear system at work.
Referenced from#
References#
- [CRV2014] X. Caruso, D. Roe and T. Vaccon. Tracking p-adic precision. LMS Journal of Computation and Mathematics 17A (2014), 274–294. https://doi.org/10.1112/S1461157014000357
- [CRV2015] X. Caruso, D. Roe and T. Vaccon. p-adic stability in linear algebra. In Proceedings of ISSAC 2015, ACM, 101–108. https://doi.org/10.1145/2755996.2756655
- [CRV2017] X. Caruso, D. Roe and T. Vaccon. Characteristic polynomials of p-adic matrices. In Proceedings of ISSAC 2017, ACM, 389–396. https://doi.org/10.1145/3087604.3087618
- [Car2017] X. Caruso. Computations with p-adic numbers. Les cours du CIRM 5 (2017), Journées Nationales de Calcul Formel. https://arxiv.org/abs/1701.06794
The FLINT team, “Optimal precision in p-adic linear algebra,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/p-adic/linear-algebra.html (generated 2026-11-02).
@misc{flint-doc-algorithms-p-adic-linear-algebra,
author = {{The FLINT team}},
title = {{Optimal precision in p-adic linear algebra}},
howpublished = {FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev},
year = {2026},
url = {https://flintlib.org/doc/algorithms/p-adic/linear-algebra.html},
note = {Generated 2026-11-02}
}