Skip to main content

Variety

Struct Variety 

Source
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,

Source

pub fn p(&self) -> AdicResult<Prime>

Prime for this adic variety, or error if the variety is empty

Source

pub fn primed_from_roots<P, B, IB>(p: P, roots: IB) -> Self
where P: Into<Prime>, A: PrimedFrom<B>, IB: IntoIterator<Item = B>,

Create a Variety from a Vec of roots that can be primed into A

Source

pub fn try_primed_from_roots<P, B, IB>(p: P, roots: IB) -> AdicResult<Self>
where P: Into<Prime>, A: TryPrimedFrom<B>, IB: IntoIterator<Item = B>, AdicError: From<A::Error>,

Create a Variety from a Vec of roots that can attempt to be primed into A

Source

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));
Source

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));
Source

pub fn adic_sort(&mut self)

Sort (in-place) this adic Variety, using digits from least to most significance

Source

pub fn adic_sorted(self) -> Self

Sort this adic Variety, using digits from least to most significance

Source§

impl<A> Variety<A>

Source

pub fn into_fractional(self) -> Variety<QAdic<A>>

Convert adic integer variety into QAdic variety

Source§

impl<A> Variety<QAdic<A>>

Source

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>

Source

pub fn new(roots: Vec<T>) -> Self

Create a variety with the given roots/solutions

Source

pub fn num_roots(&self) -> usize

Number of roots in variety

Source

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<_>>()
);
Source

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<_>>()
);
Source

pub fn is_empty(&self) -> bool

Do no roots exist

let v = Variety::new(vec![
    ZAdic::new_approx(5, 3, vec![1, 2, 3]),
    ZAdic::new_approx(5, 3, vec![3, 2, 1]),
]);
assert!(!v.is_empty());
let v = Variety::<ZAdic>::new(vec![]);
assert!(v.is_empty());
Source

pub fn empty() -> Self

Create an empty adic variety

Source

pub const fn len(&self) -> usize

Returns the number of roots in the variety

Source

pub fn get(&self, idx: usize) -> Option<&T>

Returns a reference to an element or None if out of bounds

Trait Implementations§

Source§

impl<T: Clone> Clone for Variety<T>

Source§

fn clone(&self) -> Variety<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Variety<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for Variety<T>
where T: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Eq for Variety<T>
where T: Eq + Hash,

Source§

impl<T> Extend<T> for Variety<T>

Source§

fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> Index<usize> for Variety<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> PartialEq for Variety<T>
where T: Eq + Hash,

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<A, B> PrimedFrom<Variety<B>> for Variety<A>
where A: AdicPrimitive + PrimedFrom<B>,

Source§

fn primed_from<P>(p: P, n: Variety<B>) -> Self
where P: Into<Prime>,

Convert from N to Self with Prime p Read more

Auto Trait Implementations§

§

impl<T> Freeze for Variety<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for Variety<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for Variety<T>
where Vec<T>: Send,

§

impl<T> Sync for Variety<T>
where Vec<T>: Sync,

§

impl<T> Unpin for Variety<T>
where Vec<T>: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<A, N> PrimedInto<A> for N
where A: PrimedFrom<N>,

Source§

fn primed_into<P>(self, p: P) -> A
where P: Into<Prime>,

Convert from Self to A with Prime p Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<A, N> TryPrimedFrom<N> for A
where A: PrimedFrom<N>,

Source§

type Error = !

The type returned in the event of a conversion error
Source§

fn try_primed_from<P>(p: P, n: N) -> Result<A, <A as TryPrimedFrom<N>>::Error>
where P: Into<Prime>,

Convert from N to Self with Prime p Read more
Source§

impl<A, N> TryPrimedInto<A> for N
where A: TryPrimedFrom<N>,

Source§

type Error = <A as TryPrimedFrom<N>>::Error

The type returned in the event of a conversion error
Source§

fn try_primed_into<P>(self, p: P) -> Result<A, <N as TryPrimedInto<A>>::Error>
where P: Into<Prime>,

Convert from Self to A with Prime p Read more