Adic number math
Adic numbers
p-adic numbers are an alternate number system to the reals. This system is p-periodic and hierarchical. It is used throughout number theory, but it not well-known outside of pure math. This crate is partially an attempt to change that.
Links
- crates.io/adic
- docs/adic
- gitlab/adic
- adicmath.com - our site, to learn about and play with adic numbers
- crates.io/adic-shape - crate for visualizations and charts of adic numbers
- wiki/P-adic_number - wikipedia for p-adic numbers
References
- Murty: Introduction to p-adic... - Introduces p-adics starting from Bernoulli numbers and interpolation; good first book
- Koblitz: p-adic Numbers... - Introduces p-adics slowly while analyzing zeta functions; good first book
- Gouveau: p-adic Numbers Widely recommended; likely a good first book
- Roberts: A Course in p-adic Analysis - p-adics from Z_p through analytical functions; formal and thorough, fantastic
Motivation
Adic numbers can represent any rational number as well as many numbers between them, just like the real numbers.
They can be represented similarly to the reals as infinite digital expansions.
Except where the reals have a finite number of digits to the left of the decimal and possibly infinite to the right
(1.414...), the adics have finite digits to the right and infinite to the left (...4132.13).
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
You might think this means they are "infinite" numbers, but they are not. The key difference is how a number's size is measured.
For a number, its size is its norm, its absolute value.
In the reals, the size of 4 is 4, the size of -2.31 is 2.31, etc.
Each p-adic space is linked to a prime, p.
In the p-adics, the size of a number is the inverse of how many powers of p are in it: |x| = |a/b * p^v| = p^(-v).
So in the 5-adics, 1, 2, 3, and 4 are all size 1, while 5, 10, 15, and 20 are size 1/5.
When you represent these numbers as digital expansions in base-p, the numbers further to the left are smaller, not bigger.
let one = new;
let two = new;
let three = new;
let five = new;
let ten = new;
let twenty_five = new;
let six_hundred_twenty_five = new;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Adic numbers are used:
- to solve diophantine equations
- as fundamental examples of ultrametric spaces
- to form combined local/global structures, e.g. adeles and ideles
- in glassy physical systems, like in replica/cavity theory
- in tropical geometry
Crate
This crate handles adic numbers, arithmetic, and calculations.
Calculations:
- Adic arithmetic: Add, Sub, Mul, Div, Pow, Neg
- Rootfinding, through use of hensel lifting
- Polynomial, power series, and sequence manipulations
- Idempotent computation for
MAdiczero divisors
Adic number structs:
| Struct | Type | Represents | Example |
|---|---|---|---|
[UAdic] |
Integer | Unsigned ordinary integers | 86 = 321._5 |
[EAdic] |
Integer | Exact p-adic integers | -7/6 = (31)2._5 |
[ZAdic] |
Integer | Approximate p-adic integers | sqrt(6) ~= ...24031._5 |
[QAdic<A>] |
Fraction | p-fractional numbers | 86/5 = 32.1_5 |
PowAdic<A> |
Composite | p^n-adic numbers | 86 = 3b._25 |
MAdic |
Composite | Non-prime adic numbers | 86 = ...0086._10 |
Functions:
- [
Polynomial] - Polynomial, enhanced with adic integer or adic number coefficients e.g. with rootfinding - [
PowerSeries] - A power series, useful for expressing special functions e.g. the Iwasawa Log function - [
Variety] - A collection of approximate items representing the roots of a polynomial
Example: calculate the two varieties for 7-adic sqrt(2) to 6 digits:
use ;
// Create the 7-adic number 2
let seven_adic_two = new;
// Take the square root of seven_adic_two, to 6 "decimal places"
let sqrt_two_variety = seven_adic_two.nth_root;
assert_eq!;
let roots = sqrt_two_variety?.into_roots.;
assert_eq!;
assert_eq!;
Example: 5-adic arithmetic
use ;
// 3 is a single digit (3) and no repeating digits
let three = new_repeating;
// -1/6 consists only of repeating ...040404.
let neg_one_sixth = new_repeating;
// 3 - 1/6 = 17/6 is two digits 12. and then repeating 04
let seventeen_sixth = three + neg_one_sixth;
assert_eq!;
assert_eq!;
Example: 5-adic fourth roots of unity
use Pow;
use ;
// Every (odd) p-adic number space has p-1 roots of unity
let roots = roots_of_unity?;
assert_eq!;
// Each root taken to the (5-1)-th power is approximately one
for root in roots.into_roots
Future
QXAdicfor a number from a finite extension of [QAdic]QCAdicfor a number in the algebraic closure of [QAdic]CAdic, a "complex adic number", in the norm completion ofQCAdicSAdic, a "spherically complete adic number", in the spherical completion ofQCAdic/CAdic
License: MIT OR Apache-2.0