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
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 = uadic!;
let two = uadic!;
let three = uadic!;
let five = uadic!;
let ten = uadic!;
let twenty_five = uadic!;
let six_hundred_twenty_five = uadic!;
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
- Idempotent computation for
AdicCompositezero divisors
Adic number structs:
- Adic integers of various types:
- [
UAdic]/[uadic]for natural numbers - [
IAdic]/[iadic_pos]/[iadic_neg] for ordinary integers - [
RAdic]/[radic] for (most) rationals - [
ZAdic]/[zadic_approx] for approximate numbers
- [
- [
QAdic]/[qadic], an adic number, to include powers of p in the denominator - [
AdicPower]/[apow] for numbers with a base that is powers of a prime: p^n - [
AdicComposite] for numbers with a non-prime-power base (built from severalAdicPowertogether)
Related adic structs:
- [
AdicValuation] - Valuation for adic numbers - [
LazyDiv] - Lazily calculate adic number division
Adic number traits:
- [
AdicNumber] - A number with a prime and Add/Mul arithmetic - [
SignedAdicNumber] - AnAdicNumberthat includes Neg and Sub - [
AdicInteger] - An adic number without p-fractional digits - [
AdicFraction] - An adic number with p-fractional digits - [
AdicSized] - An adic number with valuation and norm - [
AdicApproximate] - An adic number with certainty and significance - [
HasDigits] - A structure with indexed digits
Polynomials:
- [
AdicPolynomial] - Polynomial with adic integer coefficients - [
AdicVariety] - A collection of approximate [AdicNumber]s representing the roots of a polynomial
Divisible:
- [
Divisible] - A trait for structures made of prime decompositions - [
Prime] - A prime number - [
PrimePower] - The power of aPrime - [
Composite] - A combination ofPrimePowers - [
Natural] -Compositeor zero (note: NOT aDivisiblestruct)
Example: calculate the two varieties for 7-adic sqrt(2) to 6 digits:
use ;
// Create the 7-adic number 2
let seven_adic_two = uadic!;
// 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 = radic!;
// -1/6 consists only of repeating ...040404.
let neg_one_sixth = radic!;
// 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!;
let approx_one = zadic_approx!;
for root in roots.into_roots
TODO
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