Expand description
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.
https://en.wikipedia.org/wiki/P-adic_number
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!("2314._5", uadic!(5, [4, 1, 3, 2]).to_string());
assert_eq!("(4)11._5", iadic_neg!(5, [1, 1]).to_string());
assert_eq!("(233)4._5", radic!(5, [4], [3, 3, 2]).to_string());
assert_eq!("...004123._5", zadic_approx!(5, 6, [3, 2, 1, 4]).to_string());
assert_eq!("...0041.23_5", qadic!(zadic_approx!(5, 6, [3, 2, 1, 4]), -2).to_string());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.
In the p-adics, the size is the inverse of how many powers of p are in the number: |x| = |a/b * p^v| = p^(-v).
When you represent these numbers as (base-p) digital expansions, the numbers further to the left are SMALLER, not bigger.
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, including:
- Adic integers of various types:
QAdic, an adic number, to include powers of p in the denominator- Rootfinding, through use of hensel lifting
Other important objects:
AdicInteger- Trait for adic integers, including e.g. norm, certainty, n-th root calculationsAdicPolynomial- Polynomial with adic integer coefficientsLazyIntDiv/LazyQDiv- Lazily calculate adic number divisionQAdicValuation/ZAdicValuation- Valuation for adic numbers and integers, respectivelyZAdicVariety- A collection ofZAdics representing the roots of a polynomial
§Example: calculate the two varieties for 7-adic sqrt(2) to 6 digits:
use adic::{uadic, zadic_variety, AdicInteger};
// Create the 7-adic number 2
let seven_adic_two = uadic!(7, [2]);
// Take the square root of seven_adic_two, to 6 "decimal places"
let sqrt_two_variety = seven_adic_two.nth_root(2, 6);
assert_eq!(Ok(zadic_variety!(7, 6, [
[3, 1, 2, 6, 1, 2],
[4, 5, 4, 0, 5, 4],
])), sqrt_two_variety);§Example: 5-adic arithmetic
use adic::{uadic, radic, AdicInteger};
// 3 is a single digit (3) and no repeating digits
let three = radic![5, [3], []];
// -1/6 consists only of repeating ...040404.
let neg_one_sixth = radic![5, [], [4, 0]];
// 3 - 1/6 = 17/6 is two digits 12. and then repeating 04
let seventeen_sixth = three + neg_one_sixth;
assert_eq!(radic![5, [2, 1], [4, 0]], seventeen_sixth);
assert_eq!(uadic![5, [2, 1, 4, 0, 4, 0]], seventeen_sixth.truncation(6));§Example: 5-adic fourth roots of unity
use num::traits::Pow;
use adic::{roots_of_unity, zadic_approx, zadic_variety, AdicInteger};
// Every (odd) p-adic number space has p-1 roots of unity
let roots = roots_of_unity(5, 6)?;
assert_eq!(
zadic_variety!(5, 6, [[1], [2, 1, 2, 1, 3, 4], [3, 3, 2, 3, 1, 0], [4, 4, 4, 4, 4, 4]]),
roots
);
let approx_one = zadic_approx!(5, 6, [1]);
for root in roots.into_roots() {
assert_eq!(approx_one, root.pow(4));
}§TODO
AdicNumber, a trait forQAdicand anyAdicIntegerQXAdicfor a number from a finite extension ofQAdicQCAdicfor a number in the algebraic closure ofQAdicCAdic, a “complex adic number”, in the norm completion ofQCAdicSAdic, a “spherically complete adic number”, in the spherical completion ofQCAdic/CAdic
Re-exports§
pub use num_adic::AdicInteger;pub use num_adic::AdicSign;pub use num_adic::IAdic;pub use num_adic::LazyIntDiv;pub use num_adic::LazyQDiv;pub use num_adic::RAdic;pub use num_adic::SignedAdicInteger;pub use num_adic::UAdic;pub use num_adic::QAdic;pub use num_adic::QAdicValuation;pub use num_adic::ZAdic;pub use num_adic::ZAdicValuation;pub use poly_adic::nth_root;pub use poly_adic::polynomial_variety;pub use poly_adic::roots_of_unity;pub use poly_adic::AdicPolynomial;pub use poly_adic::ZAdicVariety;
Modules§
- Adic number structs and traits
- Adic polynomials
- Adic utility methods
Macros§
- Create a negative
IAdicnumber more concisely - Create a positive
IAdicnumber more concisely - Create a
QAdicmore concisely - Create a
RAdicnumber more concisely - Create a
UAdicnumber more concisely - Create an approximate
ZAdicnumber more concisely - Create a negative exact
ZAdicnumber more concisely - Create a positive exact
ZAdicnumber more concisely - Create a
ZAdicVarietymore concisely
Enums§
- Error from adic operations