pub struct Variety<T> { /* private fields */ }Expand description
An algebraic variety, often a set of “roots” to an algebraic equation
let z = Variety::new(vec![
ZAdic::new_approx(5, 6, vec![0, 1, 2, 3]),
ZAdic::from(EAdic::new(5, vec![4, 3])),
]);
assert_eq!(ZAdic::new_approx(5, 6, vec![0, 1, 2, 3]), z[0]);
assert_eq!(Some(&ZAdic::from(EAdic::new(5, vec![4, 3]))), z.get(1));
assert_eq!(None, z.get(2));
assert_eq!("variety(...003210._5, 34._5)", z.to_string());Often known as the “solutions” of the equation.
E.g. x^2 - 4 = 0 has an associated variety of {2, -2} (in both the reals and all p-adics).
E.g. x^2 - 2 = 0 has a non-integer variety {1.414..., -1.414...} in the reals,
integer variety {...6213._5, ...0454._5} in the 7-adics,
and no solutions/variety in the 5-adics (indecomposable and irreducible).
Note that the roots are not sorted in any way, and multiplicity/degeneracy is allowed.
If sorting is desired, the adic_sort and adic_sorted
methods will sort adic numbers by digit.
Implementations§
Source§impl<A> Variety<A>where
A: AdicPrimitive,
impl<A> Variety<A>where
A: AdicPrimitive,
Sourcepub fn p(&self) -> AdicResult<Prime>
pub fn p(&self) -> AdicResult<Prime>
Prime for this adic variety, or error if the variety is empty
Sourcepub fn primed_from_roots<P, B, IB>(p: P, roots: IB) -> Self
pub fn primed_from_roots<P, B, IB>(p: P, roots: IB) -> Self
Create a Variety from a Vec of roots that can be primed into A
Sourcepub fn try_primed_from_roots<P, B, IB>(p: P, roots: IB) -> AdicResult<Self>
pub fn try_primed_from_roots<P, B, IB>(p: P, roots: IB) -> AdicResult<Self>
Create a Variety from a Vec of roots that can attempt to be primed into A
Sourcepub fn approximation(&self, n: A::DigitIndex) -> Variety<A::Approximation>
pub fn approximation(&self, n: A::DigitIndex) -> Variety<A::Approximation>
Approximate all members of this variety to certainty n
let av = Variety::new(vec![UAdic::new(5, vec![]), UAdic::new(5, vec![1]), UAdic::new(5, vec![1, 2, 3, 4])]);
let zv = Variety::new(vec![ZAdic::new_approx(5, 2, vec![]), ZAdic::new_approx(5, 2, vec![1]), ZAdic::new_approx(5, 2, vec![1, 2])]);
assert_eq!(zv, av.approximation(2));Sourcepub fn into_approximation(self, n: A::DigitIndex) -> Variety<A::Approximation>
pub fn into_approximation(self, n: A::DigitIndex) -> Variety<A::Approximation>
Approximate all members of this variety to certainty n
let av = Variety::new(vec![UAdic::new(5, vec![]), UAdic::new(5, vec![1]), UAdic::new(5, vec![1, 2, 3, 4])]);
let zv = Variety::new(vec![ZAdic::new_approx(5, 2, vec![]), ZAdic::new_approx(5, 2, vec![1]), ZAdic::new_approx(5, 2, vec![1, 2])]);
assert_eq!(zv, av.into_approximation(2));Sourcepub fn adic_sort(&mut self)where
A: HasApproximateDigits,
pub fn adic_sort(&mut self)where
A: HasApproximateDigits,
Sort (in-place) this adic Variety, using digits from least to most significance
Sourcepub fn adic_sorted(self) -> Selfwhere
A: HasApproximateDigits,
pub fn adic_sorted(self) -> Selfwhere
A: HasApproximateDigits,
Sort this adic Variety, using digits from least to most significance
Source§impl<A> Variety<A>where
A: AdicPrimitive + AdicInteger,
impl<A> Variety<A>where
A: AdicPrimitive + AdicInteger,
Sourcepub fn into_fractional(self) -> Variety<QAdic<A>>
pub fn into_fractional(self) -> Variety<QAdic<A>>
Convert adic integer variety into QAdic variety
Source§impl<A> Variety<QAdic<A>>where
A: AdicPrimitive + AdicInteger,
impl<A> Variety<QAdic<A>>where
A: AdicPrimitive + AdicInteger,
Sourcepub fn try_into_integer(self) -> AdicResult<Variety<A>>
pub fn try_into_integer(self) -> AdicResult<Variety<A>>
Convert QAdic variety into adic integer variety, throwing an error if any root is fractional
Source§impl<T> Variety<T>
impl<T> Variety<T>
Sourcepub fn roots(&self) -> impl Iterator<Item = &T>
pub fn roots(&self) -> impl Iterator<Item = &T>
Iterator reference for the roots of this variety
let v = Variety::<ZAdic>::primed_from_roots(5, [86, 38, 42]);
let v = v.into_approximation(3).adic_sorted();
assert_eq!(
vec![
&ZAdic::new_approx(5, 3, vec![1, 2, 3]),
&ZAdic::new_approx(5, 3, vec![2, 3, 1]),
&ZAdic::new_approx(5, 3, vec![3, 2, 1]),
],
v.roots().collect::<Vec<_>>()
);Sourcepub fn into_roots(self) -> impl Iterator<Item = T>
pub fn into_roots(self) -> impl Iterator<Item = T>
Iterator for the roots of this variety
let v = Variety::<ZAdic>::primed_from_roots(5, [86, 38, 42]);
let v = v.into_approximation(3).adic_sorted();
assert_eq!(
vec![
ZAdic::new_approx(5, 3, vec![1, 2, 3]),
ZAdic::new_approx(5, 3, vec![2, 3, 1]),
ZAdic::new_approx(5, 3, vec![3, 2, 1]),
],
v.into_roots().collect::<Vec<_>>()
);Trait Implementations§
impl<T> Eq for Variety<T>
Source§impl<T> Extend<T> for Variety<T>
impl<T> Extend<T> for Variety<T>
Source§fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)
fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<A, B> PrimedFrom<Variety<B>> for Variety<A>where
A: AdicPrimitive + PrimedFrom<B>,
impl<A, B> PrimedFrom<Variety<B>> for Variety<A>where
A: AdicPrimitive + PrimedFrom<B>,
Auto Trait Implementations§
impl<T> Freeze for Variety<T>
impl<T> RefUnwindSafe for Variety<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for Variety<T>
impl<T> Sync for Variety<T>
impl<T> Unpin for Variety<T>
impl<T> UnsafeUnpin for Variety<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for Variety<T>where
Vec<T>: 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