pyAdic

The pyadic library is Python 3 package that provides number types for finite fields (ModP) and p-adic numbers (PAdic). The goal is mimic the flexible behavior of built-in types, such as int, float and complex. Thus, one can mix-and-match the different number types, as long as the operations are consistent. In particular, ModP and PAdic are compatible with fractions.Fraction.

Installation

Installation is easy with pip:

pip install pyadic

alternatively the package can be cloned from github at https://github.com/GDeLaurentis/pyadic.

Quick start

Instantiating number pyadic types
 1from pyadic import PAdic, ModP
 2from fractions import Fraction as Q
 3
 4# 7/13 as a 12-digit 2147483647-adic number
 5PAdic(Q(7, 13), 2147483647, 12)
 6> 1817101548 + 825955248*2147483647 + 1156337348*2147483647^2 + 330382099*2147483647^3 + 1321528398*2147483647^4 + 991146298*2147483647^5 + 1817101547*2147483647^6 + 825955248*2147483647^7 + 1156337348*2147483647^8 + 330382099*2147483647^9 + 1321528398*2147483647^10 + 991146298*2147483647^11 + O(2147483647^12)
 7
 8# 7/13 in F_2147483647
 9ModP(Q(7, 13), 2147483647)
10> 1817101548 % 2147483647
Mapping back to rational numbers
12from pyadic.finite_field import rationalise
13
14rationalise(ModP(Q(7, 13), 2147483647))
15> Fraction(7, 13)
16rationalise(PAdic(Q(7, 13), 2147483647, 12))
17> Fraction(7, 13)

Indices and tables