pub struct IAdic { /* private fields */ }
Expand description
Adic that represents a signed integer (iadic_pos
, iadic_neg
)
An AdicInteger
.
This can represent any real, signed integer.
The struct holds a finite list of digits, from the “zero” digit place to the max.
After this, it holds either all zeros or all (p-1)s, aka -1 in F_p.
This second-most basic Adic struct, has a finite number of digits and a sign.
With this, you can represent exactly the real integers.
assert_eq!("4321._5", IAdic::new_pos(5, vec![1, 2, 3, 4]).to_string());
let two = IAdic::new_pos(5, vec![2]);
assert_eq!(2, two.i32_value());
let neg_two = IAdic::new_neg(5, vec![3]);
assert_eq!("(4)3._5", neg_two.to_string());
assert_eq!(-2, neg_two.i32_value());
assert!((two + neg_two).is_zero());
This representation EXACTLY matches the real number base-p digits for a positive real integer.
2 = 2._5, 123 (base 5) = 123._5
You can perform the same arithmetic on these numbers.
However, as a signed number, we can also represent negative numbers.
-2 = (4)3._5 = ...4443._5, -123 (base 5) = (4)322._5
These numbers can be subtracted but not divided.
Instead, look to rationals, RAdic
, or if they can be approximate, ZAdic
.
ZAdic
internally uses IAdic
for the exact case.
Implementations§
Source§impl IAdic
impl IAdic
Sourcepub fn new<P>(p: P, init_digits: Vec<u32>, sign: Sign) -> Self
pub fn new<P>(p: P, init_digits: Vec<u32>, sign: Sign) -> Self
Create an adic number with the given digits and sign
§Panics
Panics if p
is not prime or digits are outside of [0, p)
Sourcepub fn new_pos<P>(p: P, init_digits: Vec<u32>) -> Self
pub fn new_pos<P>(p: P, init_digits: Vec<u32>) -> Self
Create a positive adic number with the given digits
§Panics
Panics if p
is not prime or digits are outside of [0, p)
Sourcepub fn new_neg<P>(p: P, init_digits: Vec<u32>) -> Self
pub fn new_neg<P>(p: P, init_digits: Vec<u32>) -> Self
Create a negative adic number with the given digits
§Panics
Panics if p
is not prime or digits are outside of [0, p)
Sourcepub fn into_abs(self) -> UAdic
pub fn into_abs(self) -> UAdic
Consume IAdic
and get the real absolute value UAdic
let i = iadic_pos!(5, [1, 2, 3, 4, 0]);
assert_eq!(uadic!(5, [1, 2, 3, 4]), i.into_abs());
let i = iadic_neg!(5, [1, 2, 3, 4, 0]);
assert_eq!(uadic!(5, [4, 2, 1, 0, 4]), i.into_abs());
Sourcepub fn abs(&self) -> UAdic
pub fn abs(&self) -> UAdic
Real absolute value UAdic
let i = iadic_pos!(5, [1, 2, 3, 4, 0]);
assert_eq!(uadic!(5, [1, 2, 3, 4]), i.abs());
let i = iadic_neg!(5, [1, 2, 3, 4, 0]);
assert_eq!(uadic!(5, [4, 2, 1, 0, 4]), i.abs());
Sourcepub fn is_non_negative(&self) -> bool
pub fn is_non_negative(&self) -> bool
Does the IAdic
repesent a non-negative integer
Sourcepub fn num_non_trailing(&self) -> usize
pub fn num_non_trailing(&self) -> usize
Number of non-trailing digits
assert_eq!(2, iadic_pos!(5, [2, 4, 0]).num_non_trailing());
assert_eq!(1, iadic_neg!(5, [2, 4, 4]).num_non_trailing());
Sourcepub fn trailing_digit(&self) -> u32
pub fn trailing_digit(&self) -> u32
Trailing digit for IAdic
, either 0 or (p-1)
assert_eq!(0, iadic_pos!(5, [4, 2]).trailing_digit());
assert_eq!(4, iadic_neg!(5, [4, 2]).trailing_digit());
Sourcepub fn i32_value(&self) -> i32
pub fn i32_value(&self) -> i32
The natural number value of the number, e.g. 5-adic 123 is 25+10+3=38
Warning: This can overflow; use signed_bigint_value
if unsure
§Panics
Panics if u32 -> i32 conversion fails
assert_eq!(38, iadic_pos!(5, [3, 2, 1]).i32_value());
assert_eq!(-38, iadic_neg!(5, [2, 2, 3]).i32_value());
Sourcepub fn signed_bigint_value(&self) -> BigInt
pub fn signed_bigint_value(&self) -> BigInt
The bigint representation for the natural number value of the number (i32_value
)
assert_eq!(BigInt::from(38), iadic_pos!(5, [3, 2, 1]).signed_bigint_value());
assert_eq!(BigInt::from(-38), iadic_neg!(5, [2, 2, 3]).signed_bigint_value());
Trait Implementations§
Source§impl AdicApproximate for IAdic
impl AdicApproximate for IAdic
Source§fn certainty(&self) -> AdicValuation<Self::DigitIndex>
fn certainty(&self) -> AdicValuation<Self::DigitIndex>
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) -> AdicValuation<Self::ValuationRing>where
Self: AdicSized<ValuationRing = Self::DigitIndex>,
Self::ValuationRing: Sub<Output = Self::ValuationRing>,
fn significance(&self) -> AdicValuation<Self::ValuationRing>where
Self: AdicSized<ValuationRing = Self::DigitIndex>,
Self::ValuationRing: Sub<Output = Self::ValuationRing>,
Source§impl AdicInteger for IAdic
impl AdicInteger for IAdic
Source§fn digit_str(&self) -> String
fn digit_str(&self) -> String
Source§fn into_split(self, n: usize) -> (UAdic, Self)
fn into_split(self, n: usize) -> (UAdic, Self)
Source§fn p_power<P, I>(p: P, n: I) -> Self
fn p_power<P, I>(p: P, n: I) -> Self
AdicInteger
representing a power of p Read moreSource§fn padded_digits(&self, n: usize) -> Vec<u32>
fn padded_digits(&self, n: usize) -> Vec<u32>
into_padded_digits
Read moreSource§fn into_padded_digits(self, n: usize) -> Vec<u32>where
Self: Sized,
fn into_padded_digits(self, n: usize) -> Vec<u32>where
Self: Sized,
padded_digits
Read moreSource§fn truncation(&self, n: usize) -> UAdic
fn truncation(&self, n: usize) -> UAdic
a % p^n
.
See also: into_truncation
Read moreSource§fn into_truncation(self, n: usize) -> UAdic
fn into_truncation(self, n: usize) -> UAdic
Source§fn approximation(&self, n: usize) -> ZAdicwhere
Self: AdicApproximate,
fn approximation(&self, n: usize) -> ZAdicwhere
Self: AdicApproximate,
into_approximation
Read moreSource§fn into_approximation(self, n: usize) -> ZAdicwhere
Self: AdicApproximate,
fn into_approximation(self, n: usize) -> ZAdicwhere
Self: AdicApproximate,
Source§fn split(&self, n: usize) -> (UAdic, Self)
fn split(&self, n: usize) -> (UAdic, Self)
into_split
Read moreSource§fn quotient(&self, n: usize) -> Self
fn quotient(&self, n: usize) -> Self
Source§fn into_quotient(self, n: usize) -> Self
fn into_quotient(self, n: usize) -> Self
Source§fn nth_root(&self, n: u32, precision: usize) -> AdicResult<ZAdicVariety>
fn nth_root(&self, n: u32, precision: usize) -> AdicResult<ZAdicVariety>
Source§fn num_nth_roots(&self, n: u32) -> AdicResult<usize>
fn num_nth_roots(&self, n: u32) -> AdicResult<usize>
AdicInteger
Read moreSource§impl AdicNumber for IAdic
impl AdicNumber for IAdic
Source§impl HasDigits for IAdic
impl HasDigits for IAdic
Source§type DigitIndex = usize
type DigitIndex = usize
a/b p^v
Source§fn min_index(&self) -> AdicValuation<Self::DigitIndex>
fn min_index(&self) -> AdicValuation<Self::DigitIndex>
[digits](Self::digits)
starts. Read moreSource§fn num_digits(&self) -> AdicValuation<usize>
fn num_digits(&self) -> AdicValuation<usize>
(num+|valuation|)
if valuation
is negative and (num)
if it is positive. Read moreSource§fn digit(&self, n: usize) -> AdicResult<u32>
fn digit(&self, n: usize) -> AdicResult<u32>
Source§fn digits(&self) -> impl Iterator<Item = u32>
fn digits(&self) -> impl Iterator<Item = u32>
Source§fn into_digits(self) -> impl Iterator<Item = u32>
fn into_digits(self) -> impl Iterator<Item = u32>
AdicInteger
and get the digits iterator Read moreSource§fn has_finite_digits(&self) -> bool
fn has_finite_digits(&self) -> bool
impl Eq for IAdic
impl StructuralPartialEq for IAdic
Auto Trait Implementations§
impl Freeze for IAdic
impl RefUnwindSafe for IAdic
impl Send for IAdic
impl Sync for IAdic
impl Unpin for IAdic
impl UnwindSafe for IAdic
Blanket Implementations§
Source§impl<A> AdicSized for Awhere
A: AdicInteger,
impl<A> AdicSized for Awhere
A: AdicInteger,
Source§type ValuationRing = usize
type ValuationRing = usize
a/b p^v
Source§type AdicUnit = A
type AdicUnit = A
UAdic
if the AdicSized
is QAdic<UAdic>
Source§fn valuation(&self) -> AdicValuation<usize>
fn valuation(&self) -> AdicValuation<usize>
v(a/b p^v) = v
Read moreSource§fn unit(&self) -> Option<<A as AdicSized>::AdicUnit>
fn unit(&self) -> Option<<A as AdicSized>::AdicUnit>
u(a/b p^v) = a/b
Read moreSource§fn into_unit(self) -> Option<<A as AdicSized>::AdicUnit>
fn into_unit(self) -> Option<<A as AdicSized>::AdicUnit>
u(a/b p^v) = a/b
Read moreSource§fn is_unit(&self) -> bool
fn is_unit(&self) -> bool
Source§fn unit_and_valuation(
&self,
) -> (Option<Self::AdicUnit>, AdicValuation<Self::ValuationRing>)
fn unit_and_valuation( &self, ) -> (Option<Self::AdicUnit>, AdicValuation<Self::ValuationRing>)
(None, PosInf)
Read moreSource§fn into_unit_and_valuation(
self,
) -> (Option<Self::AdicUnit>, AdicValuation<Self::ValuationRing>)where
Self: Sized,
fn into_unit_and_valuation(
self,
) -> (Option<Self::AdicUnit>, AdicValuation<Self::ValuationRing>)where
Self: Sized,
(None, PosInf)
Read moreSource§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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> SignedAdicNumber for T
impl<T> SignedAdicNumber for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.