pub trait Sequence {
type Term;
Show 19 methods
// Required methods
fn terms(&self) -> Box<dyn Iterator<Item = Self::Term> + '_>;
fn approx_num_terms(&self) -> Option<usize>;
// Provided methods
fn is_finite_sequence(&self) -> bool { ... }
fn is_empty(&self) -> bool { ... }
fn term(&self, n: usize) -> Option<Self::Term>
where Self: Sized { ... }
fn first_term(&self) -> Option<Self::Term> { ... }
fn term_local_zero(&self) -> Option<Self::Term>
where Self::Term: LocalZero { ... }
fn term_local_one(&self) -> Option<Self::Term>
where Self::Term: LocalOne { ... }
fn term_local_prime(&self) -> Option<Prime>
where Self::Term: AdicPrimitive { ... }
fn truncation(&self, len: usize) -> Vec<Self::Term> { ... }
fn enumerate(self) -> EnumeratedSequence<Self>
where Self: Sized { ... }
fn skip(self, n: usize) -> SkippedSequence<Self>
where Self: Sized { ... }
fn term_map<F, U>(self, op: F) -> MappedSequence<Self, F, U>
where Self: Sized,
F: Fn(Self::Term) -> U { ... }
fn term_scan<St, F, U>(
self,
initial: St,
op: F,
) -> ScannedSequence<Self, St, F, U>
where St: Clone,
Self: Sized,
F: Fn(&mut St, Self::Term) -> U { ... }
fn term_add<S>(self, other: S) -> TermAddSequence<Self, S>
where Self: Sized,
S: Sequence<Term = Self::Term>,
Self::Term: Clone + Add<Output = Self::Term> { ... }
fn term_mul<S>(
self,
other: S,
trailing_ones: bool,
) -> TermMulSequence<Self, S>
where Self: Sized,
S: Sequence<Term = Self::Term>,
Self::Term: Clone + Mul<Output = Self::Term> { ... }
fn term_compose<S, F, U>(
self,
other: S,
default: (Self::Term, S::Term),
op: F,
) -> TermComposedSequence<Self, S, F, U>
where Self::Term: Clone,
Self: Sized,
S: Sequence,
S::Term: Clone,
F: Fn(Self::Term, S::Term) -> U { ... }
fn foil_mul<S>(self, other: S) -> FoilMulSequence<Self, S>
where Self: Sized,
Self::Term: Clone + Mul<Output = Self::Term> + Add<Output = Self::Term>,
S: Sequence<Term = Self::Term> { ... }
fn carry_with(self, modulus: Self::Term) -> CarrySequence<Self>
where Self: Sized,
Self::Term: LocalZero + LocalOne + PartialOrd + Add<Output = Self::Term> + Sub<Output = Self::Term> { ... }
}Expand description
A general sequence of terms
Can be combined with other Sequences with e.g. term_add or foil_mul.
Designed to do iterator-like tasks, but Sequence is a collection, not an iterator.
Note: This trait will likely change in adic 0.6.
Required Associated Types§
Required Methods§
Sourcefn terms(&self) -> Box<dyn Iterator<Item = Self::Term> + '_>
fn terms(&self) -> Box<dyn Iterator<Item = Self::Term> + '_>
Returns an iterator of Sequence terms
Sourcefn approx_num_terms(&self) -> Option<usize>
fn approx_num_terms(&self) -> Option<usize>
How many terms are in the Sequence or None if it is infinite
Note: do not expect this to be an exact measure of the number of terms.
Do not even expect it to match None when infinite, although it should.
Provided Methods§
Sourcefn is_finite_sequence(&self) -> bool
fn is_finite_sequence(&self) -> bool
Is a finite sequence
Sourcefn first_term(&self) -> Option<Self::Term>
fn first_term(&self) -> Option<Self::Term>
First term; None if Sequence is empty
Sourcefn term_local_zero(&self) -> Option<Self::Term>
fn term_local_zero(&self) -> Option<Self::Term>
Retrieve a local zero from first term; None if Sequence is empty
Sourcefn term_local_one(&self) -> Option<Self::Term>
fn term_local_one(&self) -> Option<Self::Term>
Retrieve a local zero from first term; None if Sequence is empty
Sourcefn term_local_prime(&self) -> Option<Prime>where
Self::Term: AdicPrimitive,
fn term_local_prime(&self) -> Option<Prime>where
Self::Term: AdicPrimitive,
Retrieve a prime from first term; None if Sequence is empty
Sourcefn truncation(&self, len: usize) -> Vec<Self::Term>
fn truncation(&self, len: usize) -> Vec<Self::Term>
Truncates a Sequence and returns a Vec
Sourcefn enumerate(self) -> EnumeratedSequence<Self>where
Self: Sized,
fn enumerate(self) -> EnumeratedSequence<Self>where
Self: Sized,
Enumerate a Sequence
Sourcefn skip(self, n: usize) -> SkippedSequence<Self>where
Self: Sized,
fn skip(self, n: usize) -> SkippedSequence<Self>where
Self: Sized,
Skip n terms of a Sequence
Sourcefn term_map<F, U>(self, op: F) -> MappedSequence<Self, F, U>
fn term_map<F, U>(self, op: F) -> MappedSequence<Self, F, U>
Map a Sequence to another with the given op, term by term
Sourcefn term_scan<St, F, U>(
self,
initial: St,
op: F,
) -> ScannedSequence<Self, St, F, U>
fn term_scan<St, F, U>( self, initial: St, op: F, ) -> ScannedSequence<Self, St, F, U>
Scans a Sequence, mutating initial and returning it, term by term
Sourcefn term_add<S>(self, other: S) -> TermAddSequence<Self, S>
fn term_add<S>(self, other: S) -> TermAddSequence<Self, S>
Add two Sequences, term by term
Sourcefn term_mul<S>(self, other: S, trailing_ones: bool) -> TermMulSequence<Self, S>
fn term_mul<S>(self, other: S, trailing_ones: bool) -> TermMulSequence<Self, S>
Multiply two Sequences, term by term
If trailing_ones is true, the Sequence continues with 1 after it ends.
If trailing_ones is false, the Sequence terminates with 0 after it ends.
Sourcefn term_compose<S, F, U>(
self,
other: S,
default: (Self::Term, S::Term),
op: F,
) -> TermComposedSequence<Self, S, F, U>
fn term_compose<S, F, U>( self, other: S, default: (Self::Term, S::Term), op: F, ) -> TermComposedSequence<Self, S, F, U>
Compose two Sequences with the given op, term by term
default gives the term that should be used after one of the sequences terminates.
Sourcefn foil_mul<S>(self, other: S) -> FoilMulSequence<Self, S>
fn foil_mul<S>(self, other: S) -> FoilMulSequence<Self, S>
Multiply two Sequences by FOIL,
i.e. (a, b, c...).foil_mul(d, e, f...) = (ad, ae + bd, af + be + cd...)
Sourcefn carry_with(self, modulus: Self::Term) -> CarrySequence<Self>
fn carry_with(self, modulus: Self::Term) -> CarrySequence<Self>
Rectify Sequence terms to be 0 <= term < modulus, carrying remainders
Trait Implementations§
Source§impl<T> Sequence for Box<dyn Sequence<Term = T> + '_>
impl<T> Sequence for Box<dyn Sequence<Term = T> + '_>
Source§fn terms(&self) -> Box<dyn Iterator<Item = Self::Term> + '_>
fn terms(&self) -> Box<dyn Iterator<Item = Self::Term> + '_>
Source§fn approx_num_terms(&self) -> Option<usize>
fn approx_num_terms(&self) -> Option<usize>
Source§fn is_finite_sequence(&self) -> bool
fn is_finite_sequence(&self) -> bool
Source§fn term(&self, n: usize) -> Option<Self::Term>where
Self: Sized,
fn term(&self, n: usize) -> Option<Self::Term>where
Self: Sized,
Source§fn first_term(&self) -> Option<Self::Term>
fn first_term(&self) -> Option<Self::Term>
Sequence is emptySource§fn term_local_zero(&self) -> Option<Self::Term>
fn term_local_zero(&self) -> Option<Self::Term>
Sequence is emptySource§fn term_local_one(&self) -> Option<Self::Term>
fn term_local_one(&self) -> Option<Self::Term>
Sequence is emptySource§fn term_local_prime(&self) -> Option<Prime>where
Self::Term: AdicPrimitive,
fn term_local_prime(&self) -> Option<Prime>where
Self::Term: AdicPrimitive,
Sequence is emptySource§fn enumerate(self) -> EnumeratedSequence<Self>where
Self: Sized,
fn enumerate(self) -> EnumeratedSequence<Self>where
Self: Sized,
Source§fn term_map<F, U>(self, op: F) -> MappedSequence<Self, F, U>
fn term_map<F, U>(self, op: F) -> MappedSequence<Self, F, U>
op, term by termSource§fn term_scan<St, F, U>(
self,
initial: St,
op: F,
) -> ScannedSequence<Self, St, F, U>
fn term_scan<St, F, U>( self, initial: St, op: F, ) -> ScannedSequence<Self, St, F, U>
initial and returning it, term by termSource§fn term_add<S>(self, other: S) -> TermAddSequence<Self, S>
fn term_add<S>(self, other: S) -> TermAddSequence<Self, S>
Source§fn term_mul<S>(self, other: S, trailing_ones: bool) -> TermMulSequence<Self, S>
fn term_mul<S>(self, other: S, trailing_ones: bool) -> TermMulSequence<Self, S>
Source§fn term_compose<S, F, U>(
self,
other: S,
default: (Self::Term, S::Term),
op: F,
) -> TermComposedSequence<Self, S, F, U>
fn term_compose<S, F, U>( self, other: S, default: (Self::Term, S::Term), op: F, ) -> TermComposedSequence<Self, S, F, U>
op, term by term Read moreSource§fn foil_mul<S>(self, other: S) -> FoilMulSequence<Self, S>
fn foil_mul<S>(self, other: S) -> FoilMulSequence<Self, S>
(a, b, c...).foil_mul(d, e, f...) = (ad, ae + bd, af + be + cd...)Source§fn carry_with(self, modulus: Self::Term) -> CarrySequence<Self>
fn carry_with(self, modulus: Self::Term) -> CarrySequence<Self>
0 <= term < modulus, carrying remainders