pub struct QAdic<A>where
A: AdicInteger,{ /* private fields */ }Expand description
Fractional adic number
The struct holds an adic integer and a valuation.
Digitally, there are -valuation digits to the right of the decimal.
With this, you can represent any adic number.
The adic integer is generic and so can be e.g.
let twenty_three_and_11_25 = QAdic::new(UAdic::new(5, vec![1, 2, 3, 4]), Valuation::Finite(-2));
assert_eq!("43.21_5", twenty_three_and_11_25.to_string());
let fifty = QAdic::new(UAdic::new(5, vec![0, 2]), 1);
assert_eq!("200._5", fifty.to_string());
let neg_one_tenth = QAdic::new(EAdic::new_repeating(5, vec![], vec![2]), -1);
assert_eq!("(2).2_5", neg_one_tenth.to_string());
assert_eq!(
QAdic::new(UAdic::new(5, vec![1, 2, 4, 1, 1]), -2),
QAdic::new(UAdic::new(5, vec![1, 2, 3, 4]), -2) + QAdic::new(UAdic::new(5, vec![1, 2]), 0)
);
assert_eq!(
QAdic::new(UAdic::new(5, vec![2, 2]), -3),
QAdic::new(UAdic::new(5, vec![3]), -2) * QAdic::new(UAdic::new(5, vec![4]), -1)
);
assert_eq!(Ratio::new(1, 1), QAdic::new(UAdic::new(5, vec![4, 1, 3, 2]), 0).norm());
assert_eq!(Ratio::new(1, 25), QAdic::new(UAdic::new(5, vec![4, 1, 3, 2]), 2).norm());
assert_eq!(Ratio::new(25, 1), QAdic::new(UAdic::new(5, vec![4, 1, 3, 2]), -2).norm());This struct represents adic numbers as base-p digital expansions, with a possibly-infinite number of digits to the left of a decimal point and a finite number of digits to the right.
AdicIntegers are similar, but without digits to the right of the decimal.
QAdics can represent all rational numbers as well as many irrational (distinct from the real number irrationals).
Using the p-adic norm, these numbers have valuation -inf < v <= inf, i.e. |x| = p^(-v).
let neg_one = -EAdic::one(5);
let neg_one_fifth = QAdic::new(neg_one.clone(), -1);
let neg_one_twenty_fifth = QAdic::new(neg_one.clone(), -2);
let sqrt_neg_one = ZAdic::new_approx(5, 6, vec![2, 1, 2, 1, 3, 4]);
assert_eq!("...431212._5", sqrt_neg_one.to_string());
let sqrt_neg_one_twenty_fifth = QAdic::new(sqrt_neg_one.clone(), -1);
assert_eq!("...43121.2_5", sqrt_neg_one_twenty_fifth.to_string());
assert_eq!(
Ok(Variety::new(vec![sqrt_neg_one.clone(), -sqrt_neg_one.clone()])),
neg_one.nth_root(2, 6)
);
assert!(neg_one_fifth.nth_root(2, 5).is_ok_and(|variety| variety.is_empty()));
assert_eq!(
Ok(Variety::new(vec![sqrt_neg_one_twenty_fifth.clone(), -sqrt_neg_one_twenty_fifth])),
neg_one_twenty_fifth.nth_root(2, 5)
);https://en.wikipedia.org/wiki/P-adic_number
§Panics
Many methods will panic if a provided prime p is not prime or digits are outside of [0, p).
Implementations§
Source§impl<A> QAdic<A>where
A: AdicInteger,
impl<A> QAdic<A>where
A: AdicInteger,
Sourcepub fn new<V>(adic_int: A, valuation: V) -> Self
pub fn new<V>(adic_int: A, valuation: V) -> Self
Create an adic number with the given digits and valuation
Sourcepub fn frac_and_int(&self) -> (QAdic<UAdic>, A)
pub fn frac_and_int(&self) -> (QAdic<UAdic>, A)
Split QAdic into fraction (as QAdic<UAdic>) and integer (as A)
let r = EAdic::new_repeating(7, vec![1, 2], vec![3, 4, 5]);
assert_eq!("(543)21._7", r.to_string());
let q = QAdic::new(r, -6);
assert_eq!("(354).354321_7", q.to_string());
let (q_frac, q_int) = q.frac_and_int();
assert_eq!("0.354321_7", q_frac.to_string());
assert_eq!("(354)._7", q_int.to_string());Sourcepub fn from_integer(adic_int: A) -> Self
pub fn from_integer(adic_int: A) -> Self
Create an adic number with the given digits and zero valuation
Sourcepub fn try_into_integer(self) -> AdicResult<A>
pub fn try_into_integer(self) -> AdicResult<A>
Try to convert into an AdicInteger, returning error if there are fractional digits
let r = EAdic::new_repeating(7, vec![1, 2], vec![3, 4, 5]);
assert_eq!("(543)21._7", r.to_string());
let q = QAdic::new(r.clone(), 3);
assert_eq!("(543)21000._7", q.to_string());
let q_int = q.try_into_integer();
assert_eq!(Ok("(543)21000._7".to_string()), q_int.map(|a| a.to_string()));
let q = QAdic::new(r, -3);
assert_eq!("(354).321_7", q.to_string());
let q_int = q.try_into_integer();
assert_eq!(Err(AdicError::AdicIntegerExpected), q_int);Sourcepub fn nth_root(
&self,
n: u32,
precision: isize,
) -> AdicResult<Variety<QAdic<ZAdic>>>
pub fn nth_root( &self, n: u32, precision: isize, ) -> AdicResult<Variety<QAdic<ZAdic>>>
Calculate the n-th root, to precision digits,
using Hensel lifting.
This is a specific case of Polynomial::variety,
for the polynomial f(x) = x^n - a = 0.
If n has a factor of p, then the algorithm is more complicated because you have to take into account more digits.
7-adic sqrt(1/98) has two solutions, starting with 3 and with 4
let seven_adic_2_49 = QAdic::new(UAdic::new(7, vec![2]), -2);
let variety = seven_adic_2_49.nth_root(2, 6).unwrap();
let expected = Variety::new(vec![
QAdic::new(ZAdic::new_approx(7, 7, vec![3, 1, 2, 6, 1, 2, 1]), -1),
QAdic::new(ZAdic::new_approx(7, 7, vec![4, 5, 4, 0, 5, 4, 5]), -1),
]);
assert_eq!(expected, variety);
assert_eq!("variety(...121621.3_7, ...545045.4_7)", variety.to_string());§Errors
QAdic’scertaintyis not high enough for desiredprecision- n == 0
§Panics
Panics if certainty does not behave as expected
Sourcepub fn num_nth_roots(&self, n: u32) -> AdicResult<usize>
pub fn num_nth_roots(&self, n: u32) -> AdicResult<usize>
Return the number of n-th roots of this QAdic
let two_49ths = QAdic::<EAdic>::primed_from(7, Rational32::new(2, 49));
assert_eq!(Ok(0), two_49ths.num_nth_roots(0));
assert_eq!(Ok(1), two_49ths.num_nth_roots(1));
assert_eq!(Ok(2), two_49ths.num_nth_roots(2));
assert_eq!(Ok(0), two_49ths.num_nth_roots(3));
assert_eq!(Ok(0), two_49ths.num_nth_roots(4));
assert_eq!(Ok(0), two_49ths.num_nth_roots(5));
assert_eq!(Ok(0), two_49ths.num_nth_roots(6));
assert_eq!(Ok(0), two_49ths.num_nth_roots(7));§Errors
Errors if rootfinding encounters problems, e.g. heavily degenerate roots
Trait Implementations§
Source§impl<A> Add for QAdic<A>where
A: AdicInteger,
impl<A> Add for QAdic<A>where
A: AdicInteger,
Source§impl<A> AddAssign for QAdic<A>where
A: AdicInteger,
impl<A> AddAssign for QAdic<A>where
A: AdicInteger,
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<A> AdicPrimitive for QAdic<A>where
A: AdicInteger,
impl<A> AdicPrimitive for QAdic<A>where
A: AdicInteger,
Source§fn from_prime<P>(p: P) -> Self
fn from_prime<P>(p: P) -> Self
Source§fn from_prime_power<PP>(pp: PP) -> Selfwhere
PP: Into<PrimePower>,
fn from_prime_power<PP>(pp: PP) -> Selfwhere
PP: Into<PrimePower>,
Source§impl<A> CanApproximate for QAdic<A>where
A: AdicInteger,
impl<A> CanApproximate for QAdic<A>where
A: AdicInteger,
Source§type Approximation = QAdic<ZAdic>
type Approximation = QAdic<ZAdic>
Source§fn approximation(&self, n: isize) -> Self::Approximation
fn approximation(&self, n: isize) -> Self::Approximation
Source§fn into_approximation(self, n: isize) -> Self::Approximationwhere
A: HasApproximateDigits,
fn into_approximation(self, n: isize) -> Self::Approximationwhere
A: HasApproximateDigits,
Source§impl<A> CanTruncate for QAdic<A>where
A: AdicInteger,
impl<A> CanTruncate for QAdic<A>where
A: AdicInteger,
Source§type Truncation = QAdic<UAdic>
type Truncation = QAdic<UAdic>
Source§fn split(&self, n: Self::DigitIndex) -> (Self::Truncation, Self::Quotient)
fn split(&self, n: Self::DigitIndex) -> (Self::Truncation, Self::Quotient)
into_split Read moreSource§fn into_split(self, n: Self::DigitIndex) -> (Self::Truncation, Self::Quotient)
fn into_split(self, n: Self::DigitIndex) -> (Self::Truncation, Self::Quotient)
Source§fn truncation(&self, n: Self::DigitIndex) -> Self::Truncationwhere
Self: Sized,
fn truncation(&self, n: Self::DigitIndex) -> Self::Truncationwhere
Self: Sized,
a % p^n.
See also: into_truncation Read moreSource§fn into_truncation(self, n: Self::DigitIndex) -> Self::Truncationwhere
Self: Sized,
fn into_truncation(self, n: Self::DigitIndex) -> Self::Truncationwhere
Self: Sized,
a % p^n.
See also: truncation Read moreSource§fn quotient(&self, n: Self::DigitIndex) -> Self::Quotientwhere
Self: Sized,
fn quotient(&self, n: Self::DigitIndex) -> Self::Quotientwhere
Self: Sized,
into_quotient Read moreSource§fn into_quotient(self, n: Self::DigitIndex) -> Self::Quotientwhere
Self: Sized,
fn into_quotient(self, n: Self::DigitIndex) -> Self::Quotientwhere
Self: Sized,
Source§impl CheckedDiv for QAdic<EAdic>
impl CheckedDiv for QAdic<EAdic>
Source§fn checked_div(&self, v: &Self) -> Option<Self>
fn checked_div(&self, v: &Self) -> Option<Self>
None is returned.Source§impl CheckedDiv for QAdic<ZAdic>
impl CheckedDiv for QAdic<ZAdic>
Source§fn checked_div(&self, v: &Self) -> Option<Self>
fn checked_div(&self, v: &Self) -> Option<Self>
None is returned.impl<A> Eq for QAdic<A>where
A: AdicInteger + Eq,
Source§impl<A> HasApproximateDigits for QAdic<A>where
A: AdicInteger,
impl<A> HasApproximateDigits for QAdic<A>where
A: AdicInteger,
Source§fn certainty(&self) -> Valuation<isize>
fn certainty(&self) -> Valuation<isize>
v(...0021.30_5) = 4 Read moreSource§fn has_no_certainty(&self) -> bool
fn has_no_certainty(&self) -> bool
Source§fn is_certain(&self) -> bool
fn is_certain(&self) -> bool
Source§fn significance(&self) -> Valuation<Self::ValuationRing>where
Self: UltraNormed<ValuationRing = Self::DigitIndex>,
Self::ValuationRing: Sub<Output = Self::ValuationRing>,
fn significance(&self) -> Valuation<Self::ValuationRing>where
Self: UltraNormed<ValuationRing = Self::DigitIndex>,
Self::ValuationRing: Sub<Output = Self::ValuationRing>,
Source§impl<A> HasDigits for QAdic<A>where
A: AdicInteger,
impl<A> HasDigits for QAdic<A>where
A: AdicInteger,
Source§fn min_index(&self) -> Valuation<Self::DigitIndex>
fn min_index(&self) -> Valuation<Self::DigitIndex>
[digits](Self::digits) starts. Read moreSource§fn num_digits(&self) -> Valuation<usize>
fn num_digits(&self) -> Valuation<usize>
num-valuation if valuation is negative and num if it is positive. Read moreSource§fn digit(&self, n: isize) -> AdicResult<u32>
fn digit(&self, n: isize) -> AdicResult<u32>
Source§fn has_finite_digits(&self) -> bool
fn has_finite_digits(&self) -> bool
Source§fn digit0(&self) -> AdicResult<u32>
fn digit0(&self) -> AdicResult<u32>
Source§fn real_projection(&self) -> AdicResult<f64>
fn real_projection(&self) -> AdicResult<f64>
f64.
E.g. if this is an adic number, it flips the digits around its decimal point and
returns the value as a real number. Read moreSource§impl<A> LocalOne for QAdic<A>where
A: AdicInteger,
impl<A> LocalOne for QAdic<A>where
A: AdicInteger,
Source§fn is_local_one(&self) -> bool
fn is_local_one(&self) -> bool
self is equivalent to its local oneSource§fn set_local_one(&mut self)
fn set_local_one(&mut self)
Source§impl<A> LocalZero for QAdic<A>where
A: AdicInteger,
impl<A> LocalZero for QAdic<A>where
A: AdicInteger,
Source§fn local_zero(&self) -> Self
fn local_zero(&self) -> Self
selfSource§fn is_local_zero(&self) -> bool
fn is_local_zero(&self) -> bool
self is equivalent to its local zeroSource§fn set_local_zero(&mut self)
fn set_local_zero(&mut self)
Source§impl<A> Mul for QAdic<A>where
A: AdicInteger,
impl<A> Mul for QAdic<A>where
A: AdicInteger,
Source§impl<A> MulAssign for QAdic<A>where
A: AdicInteger,
impl<A> MulAssign for QAdic<A>where
A: AdicInteger,
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl<A> Normed for QAdic<A>where
A: AdicInteger,
impl<A> Normed for QAdic<A>where
A: AdicInteger,
Source§fn from_norm_and_unit(norm: Self::Norm, u: Self::Unit) -> Self
fn from_norm_and_unit(norm: Self::Norm, u: Self::Unit) -> Self
Source§impl<T> PrimedFrom<Ratio<BigInt>> for QAdic<T>
impl<T> PrimedFrom<Ratio<BigInt>> for QAdic<T>
Source§fn primed_from<P>(p: P, n: BigRational) -> Self
fn primed_from<P>(p: P, n: BigRational) -> Self
Source§impl<T> PrimedFrom<Ratio<i32>> for QAdic<T>
impl<T> PrimedFrom<Ratio<i32>> for QAdic<T>
Source§fn primed_from<P>(p: P, n: Rational32) -> Self
fn primed_from<P>(p: P, n: Rational32) -> Self
impl<A> StructuralPartialEq for QAdic<A>where
A: AdicInteger + PartialEq,
Source§impl<A> SubAssign for QAdic<A>where
A: AdicInteger + Neg<Output = A>,
impl<A> SubAssign for QAdic<A>where
A: AdicInteger + Neg<Output = A>,
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<A> UltraNormed for QAdic<A>where
A: AdicInteger,
impl<A> UltraNormed for QAdic<A>where
A: AdicInteger,
Source§type ValuationRing = isize
type ValuationRing = isize
a/b p^vSource§fn from_unit_and_valuation(
u: Self::Unit,
v: Valuation<Self::ValuationRing>,
) -> Self
fn from_unit_and_valuation( u: Self::Unit, v: Valuation<Self::ValuationRing>, ) -> Self
Source§fn valuation(&self) -> Valuation<isize>
fn valuation(&self) -> Valuation<isize>
v(a/b p^v) = v Read moreSource§fn unit_and_valuation(
&self,
) -> (Option<Self::Unit>, Valuation<Self::ValuationRing>)
fn unit_and_valuation( &self, ) -> (Option<Self::Unit>, Valuation<Self::ValuationRing>)
(None, PosInf) Read moreSource§fn into_unit_and_valuation(
self,
) -> (Option<Self::Unit>, Valuation<Self::ValuationRing>)where
Self: Sized,
fn into_unit_and_valuation(
self,
) -> (Option<Self::Unit>, Valuation<Self::ValuationRing>)where
Self: Sized,
(None, PosInf) Read moreAuto Trait Implementations§
impl<A> Freeze for QAdic<A>where
A: Freeze,
impl<A> RefUnwindSafe for QAdic<A>where
A: RefUnwindSafe,
impl<A> Send for QAdic<A>where
A: Send,
impl<A> Sync for QAdic<A>where
A: Sync,
impl<A> Unpin for QAdic<A>where
A: Unpin,
impl<A> UnsafeUnpin for QAdic<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for QAdic<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more