Exact $p$-adic computation in Magma
We describe a new arithmetic system for the Magma computer algebra system for working with $p$-adic numbers exactly, in the sense that numbers are represented lazily to infinite $p$-adic precision. This is the first highly featured such implementation. This has the benefits of increasing user-friendliness and speeding up some computations, as well as forcibly producing provable results. We give theoretical and practical justification for its design and describe some use cases. The intention is that this article will be of benefit to anyone wanting to implement similar functionality in other languages.
💡 Research Summary
The paper presents a novel arithmetic subsystem for the Magma computer algebra system that implements exact p‑adic computation using a lazy evaluation model. In this model, p‑adic numbers are represented not by a fixed finite precision but by an infinite sequence of increasingly precise approximations that are computed on demand. This contrasts with the traditional “zealous” approach used in Magma, Sage, FLINT, and other systems, where a user must choose a precision up front and all subsequent operations are performed at that precision, often leading to unnecessary recomputation and potential loss of accuracy when the chosen precision is insufficient.
The authors first motivate the need for exact p‑adic arithmetic by discussing two main drawbacks of zealous computation: (1) the burden on users to guess an appropriate precision and the inefficiency of restarting calculations with higher precision, and (2) the global nature of precision, which forces expensive high‑precision work to be repeated for cheap downstream steps. They illustrate these issues with concrete examples such as polynomial factorisation followed by Hensel lifting, where the expensive factorisation step would be redundantly repeated at each precision level in a zealous setting.
The core of the implementation is a uniform data model that describes every exact p‑adic object X by three components: type, dependencies, and kind. The type corresponds to Magma’s internal type system (e.g., FldXPad for fields, FldXPadElt for elements). The dependencies are a list of other objects (which may be exact or inexact) that X depends on; for instance, a field element coerced from an integer depends on the field and the integer itself. The kind is an integer index into a static table that encodes how to compute approximations for objects of that kind. Each table entry specifies the number of dependencies, the expected types of those dependencies, and a GetApprox routine that, given the n‑th approximations of the dependencies, produces the n‑th approximation of X.
In practice, an exact object is thus an infinite stream `
Comments & Academic Discussion
Loading comments...
Leave a Comment