pub struct UnsignedVector<T: PrimitiveUnsigned> {
pub elements: Vec<T>,
}Expand description
A vector whose elements are primitive unsigned integers.
Its dimension is the number of elements, and the 0-dimensional vector has none. The field is
public, since every Vec of Ts is a valid vector: unlike a polynomial, a vector has no
normal form to maintain, and two vectors are equal exactly when their elements are.
An UnsignedVector is serialized as the list of its elements.
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let v = UnsignedVector {
elements: vec![1u32, 2, 3],
};
assert_eq!(v.dimension(), 3);
assert_eq!(v.to_string(), "(1, 2, 3)");Fields§
§elements: Vec<T>Trait Implementations§
Source§impl<T: PrimitiveUnsigned> CanonicalPrimitivePart for UnsignedVector<T>
impl<T: PrimitiveUnsigned> CanonicalPrimitivePart for UnsignedVector<T>
Source§fn canonical_primitive_part(self) -> Self
fn canonical_primitive_part(self) -> Self
Computes the canonical primitive part of an UnsignedVector, taking the vector by value.
The elements of an UnsignedVector are never negative, so it has only one associate with
coprime elements, and this is the same as primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalPrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!(v.canonical_primitive_part().to_string(), "(3, 2, 5)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> CanonicalPrimitivePart for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> CanonicalPrimitivePart for &UnsignedVector<T>
Source§fn canonical_primitive_part(self) -> UnsignedVector<T>
fn canonical_primitive_part(self) -> UnsignedVector<T>
Computes the canonical primitive part of an UnsignedVector, taking the vector by
reference.
The elements of an UnsignedVector are never negative, so it has only one associate with
coprime elements, and this is the same as primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalPrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!((&v).canonical_primitive_part().to_string(), "(3, 2, 5)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> CanonicalPrimitivePartAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> CanonicalPrimitivePartAssign for UnsignedVector<T>
Source§fn canonical_primitive_part_assign(&mut self)
fn canonical_primitive_part_assign(&mut self)
Replaces an UnsignedVector with its canonical primitive part.
The elements of an UnsignedVector are never negative, so it has only one associate with
coprime elements, and this is the same as primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalPrimitivePartAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
v.canonical_primitive_part_assign();
assert_eq!(v.to_string(), "(3, 2, 5)");Source§impl<T: Clone + PrimitiveUnsigned> Clone for UnsignedVector<T>
impl<T: Clone + PrimitiveUnsigned> Clone for UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> Content for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Content for UnsignedVector<T>
Source§fn content(self) -> T
fn content(self) -> T
Computes the content of an UnsignedVector, the GCD of its elements, taking the vector by
value.
The content of the 0-dimensional vector, and of a vector of zeros, is zero. The GCD is taken element by element, stopping early once it reaches 1.
$$ f(v) = \gcd(v_0, v_1, \ldots, v_{n-1}), $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Content;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!(v.content(), 2);
assert_eq!(UnsignedVector::<u8>::from_str("()").unwrap().content(), 0);This is equivalent to _fmpz_vec_content from fmpz_vec/content.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> Content for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Content for &UnsignedVector<T>
Source§fn content(self) -> T
fn content(self) -> T
Computes the content of an UnsignedVector, the GCD of its elements, taking the vector by
reference.
The content of the 0-dimensional vector, and of a vector of zeros, is zero. The GCD is taken element by element, stopping early once it reaches 1.
$$ f(v) = \gcd(v_0, v_1, \ldots, v_{n-1}), $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Content;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!((&v).content(), 2);
assert_eq!(
(&UnsignedVector::<u8>::from_str("(0, 0)").unwrap()).content(),
0
);This is equivalent to _fmpz_vec_content from fmpz_vec/content.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> ContentAndCanonicalPrimitivePart for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ContentAndCanonicalPrimitivePart for UnsignedVector<T>
Source§fn content_and_canonical_primitive_part(self) -> (T, Self)
fn content_and_canonical_primitive_part(self) -> (T, Self)
Computes the content and the canonical primitive part of an UnsignedVector together,
taking the vector by value.
The elements of an UnsignedVector are never negative, so it has only one associate with
coprime elements, and this is the same as primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
let (content, primitive_part) = v.content_and_canonical_primitive_part();
assert_eq!(content, 2);
assert_eq!(primitive_part.to_string(), "(3, 2, 5)");type Content = T
type CanonicalPrimitivePart = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ContentAndCanonicalPrimitivePart for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ContentAndCanonicalPrimitivePart for &UnsignedVector<T>
Source§fn content_and_canonical_primitive_part(self) -> (T, UnsignedVector<T>)
fn content_and_canonical_primitive_part(self) -> (T, UnsignedVector<T>)
Computes the content and the canonical primitive part of an UnsignedVector together,
taking the vector by reference.
The elements of an UnsignedVector are never negative, so it has only one associate with
coprime elements, and this is the same as primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
let (content, primitive_part) = (&v).content_and_canonical_primitive_part();
assert_eq!(content, 2);
assert_eq!(primitive_part.to_string(), "(3, 2, 5)");type Content = T
type CanonicalPrimitivePart = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for UnsignedVector<T>
Source§fn content_and_primitive_part(self) -> (T, Self)
fn content_and_primitive_part(self) -> (T, Self)
Computes the content and the primitive part of an UnsignedVector together, taking the
vector by value.
See content and primitive_part; the
content is found once rather than twice.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndPrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
let (content, primitive_part) = v.content_and_primitive_part();
assert_eq!(content, 2);
assert_eq!(primitive_part.to_string(), "(3, 2, 5)");type Content = T
type PrimitivePart = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for &UnsignedVector<T>
Source§fn content_and_primitive_part(self) -> (T, UnsignedVector<T>)
fn content_and_primitive_part(self) -> (T, UnsignedVector<T>)
Computes the content and the primitive part of an UnsignedVector together, taking the
vector by reference.
See content and primitive_part; the
content is found once rather than twice.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndPrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
let (content, primitive_part) = (&v).content_and_primitive_part();
assert_eq!(content, 2);
assert_eq!(primitive_part.to_string(), "(3, 2, 5)");type Content = T
type PrimitivePart = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ContentChained<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ContentChained<T> for UnsignedVector<T>
Source§fn content_chained(self, x: T) -> T
fn content_chained(self, x: T) -> T
Computes the GCD of x and the elements of an UnsignedVector, taking the vector by
value.
The GCD of x and the elements of the 0-dimensional vector, or of a vector of zeros, is
x. The computation stops as soon as the GCD reaches 1.
$$ f(v, x) = \gcd(x, v_0, v_1, \ldots, v_{n-1}), $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentChained;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!(v.clone().content_chained(4), 2);
assert_eq!(v.content_chained(0), 2);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.content_chained(6), 6);This is equivalent to _fmpz_vec_content_chained from fmpz_vec/content_chained.c, FLINT
3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> ContentChained<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ContentChained<T> for &UnsignedVector<T>
Source§fn content_chained(self, x: T) -> T
fn content_chained(self, x: T) -> T
Computes the GCD of x and the elements of an UnsignedVector, taking the vector by
reference.
The GCD of x and the elements of the 0-dimensional vector, or of a vector of zeros, is
x. The computation stops as soon as the GCD reaches 1.
$$ f(v, x) = \gcd(x, v_0, v_1, \ldots, v_{n-1}), $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentChained;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!((&v).content_chained(4), 2);
assert_eq!((&v).content_chained(0), 2);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!((&v).content_chained(6), 6);This is equivalent to _fmpz_vec_content_chained from fmpz_vec/content_chained.c, FLINT
3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> Debug for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Debug for UnsignedVector<T>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts an UnsignedVector to a String.
This is the same as the Display::fmt implementation, so that a collection of
UnsignedVectors is written the same way its elements are displayed.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use malachite_base::strings::ToDebugString;
use malachite_base::unsigned_vector::UnsignedVector;
let xs = vec![
UnsignedVector {
elements: vec![1u32, 2],
},
UnsignedVector {
elements: Vec::new(),
},
];
assert_eq!(xs[0].to_debug_string(), "(1, 2)");
assert_eq!(xs.to_debug_string(), "[(1, 2), ()]");Source§impl<T: PrimitiveUnsigned> Display for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Display for UnsignedVector<T>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts an UnsignedVector to a String.
The elements are written in order, as Display writes them, separated by , and
enclosed in parentheses, as a vector’s coordinates are written by hand. The 0-dimensional
vector is ().
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector {
elements: vec![1u32, 2, 3]
}
.to_string(),
"(1, 2, 3)"
);
assert_eq!(
UnsignedVector {
elements: vec![5u8]
}
.to_string(),
"(5)"
);
assert_eq!(
UnsignedVector::<u32> {
elements: Vec::new()
}
.to_string(),
"()"
);Source§impl<T: PrimitiveUnsigned> Div<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Div<T> for UnsignedVector<T>
Source§fn div(self, c: T) -> Self
fn div(self, c: T) -> Self
Divides every element of an UnsignedVector by a T, taking it by value.
The quotient is taken element by element, so the result has the same dimension as the vector.
Each quotient is rounded down.
$$ f(v, c)_i = \left\lfloor\frac{v_i}{c}\right\rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero.
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
/ operator.Source§impl<T: PrimitiveUnsigned> Div<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Div<T> for &UnsignedVector<T>
Source§fn div(self, c: T) -> UnsignedVector<T>
fn div(self, c: T) -> UnsignedVector<T>
Divides every element of an UnsignedVector by a T, taking it by reference.
The quotient is taken element by element, so the result has the same dimension as the vector.
Each quotient is rounded down.
$$ f(v, c)_i = \left\lfloor\frac{v_i}{c}\right\rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero.
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
/ operator.Source§impl<T: PrimitiveUnsigned> DivAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> DivAssign<T> for UnsignedVector<T>
Source§fn div_assign(&mut self, c: T)
fn div_assign(&mut self, c: T)
Divides every element of an UnsignedVector by a T, in place.
Every element is divided by c.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> DivExact<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> DivExact<T> for UnsignedVector<T>
Source§fn div_exact(self, c: T) -> Self
fn div_exact(self, c: T) -> Self
Divides every element of an UnsignedVector by a T, taking it by value. Every element
must be exactly divisible by the T.
If some element is not exactly divisible by c, this function may panic or return a
meaningless result. Dividing by 1 returns the vector unchanged.
$f(v, c) = v/c$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> DivExact<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> DivExact<T> for &UnsignedVector<T>
Source§fn div_exact(self, c: T) -> UnsignedVector<T>
fn div_exact(self, c: T) -> UnsignedVector<T>
Divides every element of an UnsignedVector by a T, taking it by reference. Every
element must be exactly divisible by the T.
If some element is not exactly divisible by c, this function may panic or return a
meaningless result. Dividing by 1 returns the vector unchanged.
$f(v, c) = v/c$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> DivExactAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> DivExactAssign<T> for UnsignedVector<T>
Source§fn div_exact_assign(&mut self, c: T)
fn div_exact_assign(&mut self, c: T)
Divides every element of an UnsignedVector by a T, in place. Every element must be
exactly divisible by the T.
If some element is not exactly divisible by c, this function may panic or return a
meaningless result. Dividing by 1 returns the vector unchanged.
$v \gets v/c$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseDivRound<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseDivRound<T> for UnsignedVector<T>
Source§fn entrywise_div_round(self, c: T, rm: RoundingMode) -> Self
fn entrywise_div_round(self, c: T, rm: RoundingMode) -> Self
Divides every element of an UnsignedVector by a T, taking it by value, and rounds
every quotient according to the specified rounding mode.
Each quotient is rounded as by DivRound, but
no Ordering is returned, since with Nearest different elements
may be rounded in different directions. Passing Floor or Down is equivalent to using
/.
$f(v, c, r)_i = \operatorname{round}(v_i/c)$, where $\operatorname{round}$ rounds according
to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero, or if rm is Exact and some element is not divisible by c.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseDivRound<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseDivRound<T> for &UnsignedVector<T>
Source§fn entrywise_div_round(self, c: T, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_div_round(self, c: T, rm: RoundingMode) -> UnsignedVector<T>
Divides every element of an UnsignedVector by a T, taking it by reference, and rounds
every quotient according to the specified rounding mode.
Each quotient is rounded as by DivRound, but
no Ordering is returned, since with Nearest different elements
may be rounded in different directions. Passing Floor or Down is equivalent to using
/.
$f(v, c, r)_i = \operatorname{round}(v_i/c)$, where $\operatorname{round}$ rounds according
to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero, or if rm is Exact and some element is not divisible by c.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseDivRoundAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseDivRoundAssign<T> for UnsignedVector<T>
Source§fn entrywise_div_round_assign(&mut self, c: T, rm: RoundingMode)
fn entrywise_div_round_assign(&mut self, c: T, rm: RoundingMode)
Divides every element of an UnsignedVector by a T, in place, and rounds every quotient
according to the specified rounding mode.
Each quotient is rounded as by DivRound, but
no Ordering is returned, since with Nearest different elements
may be rounded in different directions. Passing Floor or Down is equivalent to using
/.
$v_i \gets \operatorname{round}(v_i/c)$, where $\operatorname{round}$ rounds according to
rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if c is zero, or if rm is Exact and some element is not divisible by c.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseMax for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMax for UnsignedVector<T>
Source§fn entrywise_max(self, other: Self) -> Self
fn entrywise_max(self, other: Self) -> Self
Takes the entrywise maximum of two UnsignedVectors, taking the first by value and the
second by value.
Every element of the result is the larger of the corresponding elements of the two vectors, so the result has the same dimension as both.
$$ f(v, w) = (\max(v_0, w_0), \max(v_1, w_1), \ldots, \max(v_{n-1}, w_{n-1})). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMax;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!(v.entrywise_max(w).to_string(), "(4, 5, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMax<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMax<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn entrywise_max(self, other: &Self) -> Self
fn entrywise_max(self, other: &Self) -> Self
Takes the entrywise maximum of two UnsignedVectors, taking the first by value and the
second by reference.
See the documentation for the EntrywiseMax implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMax;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!(v.entrywise_max(&w).to_string(), "(4, 5, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMax<&UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMax<&UnsignedVector<T>> for &UnsignedVector<T>
Source§fn entrywise_max(self, other: &UnsignedVector<T>) -> UnsignedVector<T>
fn entrywise_max(self, other: &UnsignedVector<T>) -> UnsignedVector<T>
Takes the entrywise maximum of two UnsignedVectors, taking the first by reference and
the second by reference.
See the documentation for the EntrywiseMax implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMax;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!((&v).entrywise_max(&w).to_string(), "(4, 5, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMax<UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMax<UnsignedVector<T>> for &UnsignedVector<T>
Source§fn entrywise_max(self, other: UnsignedVector<T>) -> UnsignedVector<T>
fn entrywise_max(self, other: UnsignedVector<T>) -> UnsignedVector<T>
Takes the entrywise maximum of two UnsignedVectors, taking the first by reference and
the second by value.
See the documentation for the EntrywiseMax implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMax;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!((&v).entrywise_max(w).to_string(), "(4, 5, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMaxAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMaxAssign for UnsignedVector<T>
Source§fn entrywise_max_assign(&mut self, other: Self)
fn entrywise_max_assign(&mut self, other: Self)
Replaces an UnsignedVector by its entrywise maximum with another UnsignedVector,
taking the other by value.
Every element becomes the larger of itself and the corresponding element of other.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMaxAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
v.entrywise_max_assign(w);
assert_eq!(v.to_string(), "(4, 5, 3)");Source§impl<T: PrimitiveUnsigned> EntrywiseMaxAssign<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMaxAssign<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn entrywise_max_assign(&mut self, other: &Self)
fn entrywise_max_assign(&mut self, other: &Self)
Replaces an UnsignedVector by its entrywise maximum with another UnsignedVector,
taking the other by reference.
Every element becomes the larger of itself and the corresponding element of other.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMaxAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
v.entrywise_max_assign(&w);
assert_eq!(v.to_string(), "(4, 5, 3)");Source§impl<T: PrimitiveUnsigned> EntrywiseMin for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMin for UnsignedVector<T>
Source§fn entrywise_min(self, other: Self) -> Self
fn entrywise_min(self, other: Self) -> Self
Takes the entrywise minimum of two UnsignedVectors, taking the first by value and the
second by value.
Every element of the result is the smaller of the corresponding elements of the two vectors, so the result has the same dimension as both.
$$ f(v, w) = (\min(v_0, w_0), \min(v_1, w_1), \ldots, \min(v_{n-1}, w_{n-1})). $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMin;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!(v.entrywise_min(w).to_string(), "(1, 2, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMin<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMin<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn entrywise_min(self, other: &Self) -> Self
fn entrywise_min(self, other: &Self) -> Self
Takes the entrywise minimum of two UnsignedVectors, taking the first by value and the
second by reference.
See the documentation for the EntrywiseMin implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMin;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!(v.entrywise_min(&w).to_string(), "(1, 2, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMin<&UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMin<&UnsignedVector<T>> for &UnsignedVector<T>
Source§fn entrywise_min(self, other: &UnsignedVector<T>) -> UnsignedVector<T>
fn entrywise_min(self, other: &UnsignedVector<T>) -> UnsignedVector<T>
Takes the entrywise minimum of two UnsignedVectors, taking the first by reference and
the second by reference.
See the documentation for the EntrywiseMin implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMin;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!((&v).entrywise_min(&w).to_string(), "(1, 2, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMin<UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMin<UnsignedVector<T>> for &UnsignedVector<T>
Source§fn entrywise_min(self, other: UnsignedVector<T>) -> UnsignedVector<T>
fn entrywise_min(self, other: UnsignedVector<T>) -> UnsignedVector<T>
Takes the entrywise minimum of two UnsignedVectors, taking the first by reference and
the second by value.
See the documentation for the EntrywiseMin implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMin;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
assert_eq!((&v).entrywise_min(w).to_string(), "(1, 2, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseMinAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMinAssign for UnsignedVector<T>
Source§fn entrywise_min_assign(&mut self, other: Self)
fn entrywise_min_assign(&mut self, other: Self)
Replaces an UnsignedVector by its entrywise minimum with another UnsignedVector,
taking the other by value.
Every element becomes the smaller of itself and the corresponding element of other.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMinAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
v.entrywise_min_assign(w);
assert_eq!(v.to_string(), "(1, 2, 3)");Source§impl<T: PrimitiveUnsigned> EntrywiseMinAssign<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseMinAssign<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn entrywise_min_assign(&mut self, other: &Self)
fn entrywise_min_assign(&mut self, other: &Self)
Replaces an UnsignedVector by its entrywise minimum with another UnsignedVector,
taking the other by reference.
Every element becomes the smaller of itself and the corresponding element of other.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors.
§Panics
Panics if self and other have different dimensions.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseMinAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(1, 5, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 2, 3)").unwrap();
v.entrywise_min_assign(&w);
assert_eq!(v.to_string(), "(1, 2, 3)");Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u8> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u8> for UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u8, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u8, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by value,
and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u8> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u8> for &UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u8, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u8, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by
reference, and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u16> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u16> for UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u16, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u16, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by value,
and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u16> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u16> for &UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u16, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u16, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by
reference, and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u32> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u32> for UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u32, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u32, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by value,
and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u32> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u32> for &UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u32, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u32, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by
reference, and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u64> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u64> for UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u64, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u64, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by value,
and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u64> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u64> for &UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u64, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u64, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by
reference, and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u128> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u128> for UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u128, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u128, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by value,
and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<u128> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<u128> for &UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: u128, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: u128, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by
reference, and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<usize> for UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: usize, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: usize, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by value,
and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRound<usize> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRound<usize> for &UnsignedVector<T>
Source§fn entrywise_shr_round(self, bits: usize, rm: RoundingMode) -> UnsignedVector<T>
fn entrywise_shr_round(self, bits: usize, rm: RoundingMode) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2), taking it by
reference, and rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$f(v, k, r)_i = \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u8> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u8> for UnsignedVector<T>
Source§fn entrywise_shr_round_assign(&mut self, bits: u8, rm: RoundingMode)
fn entrywise_shr_round_assign(&mut self, bits: u8, rm: RoundingMode)
Right-shifts an UnsignedVector (divides it by a power of 2), in place, and
rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$v_i \gets \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u16> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u16> for UnsignedVector<T>
Source§fn entrywise_shr_round_assign(&mut self, bits: u16, rm: RoundingMode)
fn entrywise_shr_round_assign(&mut self, bits: u16, rm: RoundingMode)
Right-shifts an UnsignedVector (divides it by a power of 2), in place, and
rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$v_i \gets \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u32> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u32> for UnsignedVector<T>
Source§fn entrywise_shr_round_assign(&mut self, bits: u32, rm: RoundingMode)
fn entrywise_shr_round_assign(&mut self, bits: u32, rm: RoundingMode)
Right-shifts an UnsignedVector (divides it by a power of 2), in place, and
rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$v_i \gets \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u64> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u64> for UnsignedVector<T>
Source§fn entrywise_shr_round_assign(&mut self, bits: u64, rm: RoundingMode)
fn entrywise_shr_round_assign(&mut self, bits: u64, rm: RoundingMode)
Right-shifts an UnsignedVector (divides it by a power of 2), in place, and
rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$v_i \gets \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u128> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<u128> for UnsignedVector<T>
Source§fn entrywise_shr_round_assign(&mut self, bits: u128, rm: RoundingMode)
fn entrywise_shr_round_assign(&mut self, bits: u128, rm: RoundingMode)
Right-shifts an UnsignedVector (divides it by a power of 2), in place, and
rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$v_i \gets \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> EntrywiseShrRoundAssign<usize> for UnsignedVector<T>
Source§fn entrywise_shr_round_assign(&mut self, bits: usize, rm: RoundingMode)
fn entrywise_shr_round_assign(&mut self, bits: usize, rm: RoundingMode)
Right-shifts an UnsignedVector (divides it by a power of 2), in place, and
rounds every element according to the specified rounding mode.
Each element is rounded as by
ShrRound, but no
Ordering is returned, since with Nearest different
elements may be rounded in different directions. Passing Floor or Down is
equivalent to using >>. If bits is at least T::WIDTH, every element rounds to
0 or 1.
$v_i \gets \operatorname{round}(v_i/2^k)$, where $\operatorname{round}$ rounds
according to rm.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if rm is Exact and some element is not divisible by $2^k$.
§Examples
See here.
impl<T: Eq + PrimitiveUnsigned> Eq for UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> Extend<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Extend<T> for UnsignedVector<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, xs: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, xs: I)
Appends the elements produced by an iterator to the end of an UnsignedVector, increasing
its dimension by their number.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension() plus the number
of elements produced, not counting the cost of producing them.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(1, 2)").unwrap();
v.extend([3, 4]);
assert_eq!(v.to_string(), "(1, 2, 3, 4)");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<T: PrimitiveUnsigned> FromIterator<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> FromIterator<T> for UnsignedVector<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(xs: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(xs: I) -> Self
Collects an iterator of elements into an UnsignedVector.
The vector’s dimension is the number of elements the iterator produces, and every finite iterator gives a valid vector.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of elements produced, not counting the cost of producing them.
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
let v: UnsignedVector<u8> = (1..=3).collect();
assert_eq!(v.to_string(), "(1, 2, 3)");
let v: UnsignedVector<u8> = core::iter::empty().collect();
assert_eq!(v.to_string(), "()");Source§impl<T: PrimitiveUnsigned> FromStr for UnsignedVector<T>
impl<T: PrimitiveUnsigned> FromStr for UnsignedVector<T>
Source§fn from_str(s: &str) -> Result<Self, ()>
fn from_str(s: &str) -> Result<Self, ()>
Converts a string to an UnsignedVector.
This reads back what Display writes: the elements in order,
separated by ", " and enclosed in parentheses, with () for the 0-dimensional vector.
Each element is read the way T’s FromStr reads one, so it may have leading zeros or a
single leading '+'. Any other spacing, such as (1,2) or ( 1, 2 ), is rejected, as is
an empty element or one that is out of T’s range.
If the string does not represent an UnsignedVector, an Err is returned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is s.len().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u32>::from_str("(1, 2, 3)")
.unwrap()
.to_string(),
"(1, 2, 3)"
);
assert_eq!(
UnsignedVector::<u32>::from_str("(5)").unwrap().to_string(),
"(5)"
);
assert_eq!(
UnsignedVector::<u32>::from_str("()").unwrap().dimension(),
0
);
// An element may be written as `u32::from_str` accepts it.
assert_eq!(
UnsignedVector::<u32>::from_str("(007, +8)")
.unwrap()
.to_string(),
"(7, 8)"
);
assert!(UnsignedVector::<u32>::from_str("").is_err());
assert!(UnsignedVector::<u32>::from_str("1, 2").is_err());
assert!(UnsignedVector::<u32>::from_str("(1,2)").is_err());
assert!(UnsignedVector::<u32>::from_str("( 1, 2 )").is_err());
assert!(UnsignedVector::<u32>::from_str("(1, )").is_err());
assert!(UnsignedVector::<u32>::from_str("(-1)").is_err());
assert!(UnsignedVector::<u8>::from_str("(256)").is_err());Source§impl<T: Hash + PrimitiveUnsigned> Hash for UnsignedVector<T>
impl<T: Hash + PrimitiveUnsigned> Hash for UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> Height for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Height for UnsignedVector<T>
Source§fn to_height(&self) -> T
fn to_height(&self) -> T
Returns the height of an UnsignedVector: the largest of its elements, taking the vector
by reference.
The 0-dimensional vector has no elements, and its height is 0.
$$ f(v) = H(v) = \max_i v_i. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is the number of elements.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 3, 2)")
.unwrap()
.to_height(),
3
);
assert_eq!(UnsignedVector::<u8>::from_str("()").unwrap().to_height(), 0);Source§fn into_height(self) -> T
fn into_height(self) -> T
Returns the height of an UnsignedVector: the largest of its elements, taking the vector
by value.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of elements.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 3, 2)")
.unwrap()
.into_height(),
3
);
assert_eq!(
UnsignedVector::<u8>::from_str("()").unwrap().into_height(),
0
);Source§fn height_significant_bits(&self) -> u64
fn height_significant_bits(&self) -> u64
Returns the number of significant bits of the height of an UnsignedVector.
Since bit length is monotone, this is the largest of the elements’ heights’ bit lengths, and 0 for the 0-dimensional vector, without materializing the height.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of elements.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 3, 2)")
.unwrap()
.height_significant_bits(),
2
);
assert_eq!(
UnsignedVector::<u8>::from_str("()")
.unwrap()
.height_significant_bits(),
0
);This is equivalent to _nmod_vec_max_bits from nmod_vec/max_bits.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> Index<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Index<usize> for UnsignedVector<T>
Source§fn index(&self, i: usize) -> &T
fn index(&self, i: usize) -> &T
Gets a reference to the element of an UnsignedVector at an index.
Indices start at 0, as they do for a Vec.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if i is greater than or equal to the dimension of the vector.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
assert_eq!(v[0], 1);
assert_eq!(v[2], 3);Source§impl<T: PrimitiveUnsigned> IndexMut<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> IndexMut<usize> for UnsignedVector<T>
Source§fn index_mut(&mut self, i: usize) -> &mut T
fn index_mut(&mut self, i: usize) -> &mut T
Gets a mutable reference to the element of an UnsignedVector at an index.
Indices start at 0, as they do for a Vec.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if i is greater than or equal to the dimension of the vector.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
v[1] = 10;
v[2] += 4;
assert_eq!(v.to_string(), "(1, 10, 7)");Source§impl<T: PrimitiveUnsigned> IntoIterator for UnsignedVector<T>
impl<T: PrimitiveUnsigned> IntoIterator for UnsignedVector<T>
Source§fn into_iter(self) -> IntoIter<T> ⓘ
fn into_iter(self) -> IntoIter<T> ⓘ
Converts an UnsignedVector into an iterator over its elements, taking the vector by
value.
The elements are produced in order, starting with the element at index 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
assert_eq!(
v.into_iter().map(|x| x.to_string()).collect::<Vec<_>>(),
["1", "2", "3"]
);Source§impl<'a, T: PrimitiveUnsigned> IntoIterator for &'a UnsignedVector<T>
impl<'a, T: PrimitiveUnsigned> IntoIterator for &'a UnsignedVector<T>
Source§fn into_iter(self) -> Iter<'a, T> ⓘ
fn into_iter(self) -> Iter<'a, T> ⓘ
Converts a reference to an UnsignedVector into an iterator over references to its
elements.
The elements are produced in order, starting with the element at index 0. This is what for x in &v uses.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let mut strings = Vec::new();
for x in &v {
strings.push(x.to_string());
}
assert_eq!(strings, ["1", "2", "3"]);Source§impl<'a, T: PrimitiveUnsigned> IntoIterator for &'a mut UnsignedVector<T>
impl<'a, T: PrimitiveUnsigned> IntoIterator for &'a mut UnsignedVector<T>
Source§fn into_iter(self) -> IterMut<'a, T> ⓘ
fn into_iter(self) -> IterMut<'a, T> ⓘ
Converts a mutable reference to an UnsignedVector into an iterator over mutable
references to its elements.
The elements are produced in order, starting with the element at index 0. This is what for x in &mut v uses; since every list of elements is a valid vector, any element may be
changed.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
for x in &mut v {
*x += 1;
}
assert_eq!(v.to_string(), "(2, 3, 4)");Source§impl<T: PrimitiveUnsigned> Mod<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Mod<T> for UnsignedVector<T>
Source§fn mod_op(self, m: T) -> Self
fn mod_op(self, m: T) -> Self
Divides every element of an UnsignedVector by a T, keeping the remainders, taking the
vector by value.
An UnsignedVector’s elements are never negative, so this agrees with % everywhere; it
is the same operation under the name the mod-family traits use. See the documentation for
the Rem implementation on UnsignedVector that takes the vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u64>::from_str("(4, 4, 5)").unwrap();
assert_eq!(v.mod_op(3).to_string(), "(1, 1, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> Mod<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Mod<T> for &UnsignedVector<T>
Source§fn mod_op(self, m: T) -> UnsignedVector<T>
fn mod_op(self, m: T) -> UnsignedVector<T>
Divides every element of an UnsignedVector by a T, keeping the remainders, taking the
vector by reference.
An UnsignedVector’s elements are never negative, so this agrees with % everywhere; it
is the same operation under the name the mod-family traits use. See the documentation for
the Rem implementation on UnsignedVector that takes the vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u64>::from_str("(4, 4, 5)").unwrap();
assert_eq!((&v).mod_op(3).to_string(), "(1, 1, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAbsSquared<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAbsSquared<T> for UnsignedVector<T>
Source§fn mod_abs_squared(self, m: T) -> T
fn mod_abs_squared(self, m: T) -> T
Computes the squared norm of an UnsignedVector, the sum of the squares of its elements,
modulo $m$, taking the vector by value. The elements must already be reduced.
The squared norm of a 0-dimensional vector is 0.
$$ f(v, m) = \sum_{i=0}^{n-1} v_i^2 \bmod m, $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vector.
§Panics
Panics if m is zero or if any element is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAbsSquared;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.clone().mod_abs_squared(10), 4);type Output = T
Source§impl<T: PrimitiveUnsigned> ModAbsSquared<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAbsSquared<T> for &UnsignedVector<T>
Source§fn mod_abs_squared(self, m: T) -> T
fn mod_abs_squared(self, m: T) -> T
Computes the squared norm of an UnsignedVector, the sum of the squares of its elements,
modulo $m$, taking the vector by reference. The elements must already be reduced.
The squared norm of a 0-dimensional vector is 0.
$$ f(v, m) = \sum_{i=0}^{n-1} v_i^2 \bmod m, $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vector.
§Panics
Panics if m is zero or if any element is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAbsSquared;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
assert_eq!((&v).mod_abs_squared(10), 4);type Output = T
Source§impl<T: PrimitiveUnsigned> ModAdd<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAdd<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_add(self, other: &Self, m: T) -> Self
fn mod_add(self, other: &Self, m: T) -> Self
Adds two UnsignedVectors modulo $m$, taking the first by value and the second by
reference. The elements of both must already be reduced modulo $m$.
The sum is taken element by element, each reduced modulo $m$, so the result has the same dimension as the summands.
$$ f(v, w, m) = v + w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_add(&w, 8).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAdd<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_add(self, other: &UnsignedVector<T>, m: T) -> UnsignedVector<T>
fn mod_add(self, other: &UnsignedVector<T>, m: T) -> UnsignedVector<T>
Adds two UnsignedVectors modulo $m$, taking the first by reference and the second by
reference. The elements of both must already be reduced modulo $m$.
The sum is taken element by element, each reduced modulo $m$, so the result has the same dimension as the summands.
$$ f(v, w, m) = v + w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_add(&w, 8).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAdd<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_add(self, other: Self, m: T) -> Self
fn mod_add(self, other: Self, m: T) -> Self
Adds two UnsignedVectors modulo $m$, taking the first by value and the second by value.
The elements of both must already be reduced modulo $m$.
The sum is taken element by element, each reduced modulo $m$, so the result has the same dimension as the summands.
$$ f(v, w, m) = v + w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_add(w, 8).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAdd<UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_add(self, other: UnsignedVector<T>, m: T) -> UnsignedVector<T>
fn mod_add(self, other: UnsignedVector<T>, m: T) -> UnsignedVector<T>
Adds two UnsignedVectors modulo $m$, taking the first by reference and the second by
value. The elements of both must already be reduced modulo $m$.
The sum is taken element by element, each reduced modulo $m$, so the result has the same dimension as the summands.
$$ f(v, w, m) = v + w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_add(w, 8).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAddAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_add_assign(&mut self, other: &Self, m: T)
fn mod_add_assign(&mut self, other: &Self, m: T)
Adds an UnsignedVector to an UnsignedVector modulo $m$, in place, taking the
UnsignedVector on the right-hand side by reference. The elements of both must already be
reduced modulo $m$.
The sum is taken element by element, each reduced modulo $m$, so the result has the same dimension as the summands.
$$ f(v, w, m) = v + w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
v.mod_add_assign(&w, 8);
assert_eq!(v.to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAddAssign<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddAssign<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_add_assign(&mut self, other: Self, m: T)
fn mod_add_assign(&mut self, other: Self, m: T)
Adds an UnsignedVector to an UnsignedVector modulo $m$, in place, taking the
UnsignedVector on the right-hand side by value. The elements of both must already be
reduced modulo $m$.
The sum is taken element by element, each reduced modulo $m$, so the result has the same dimension as the summands.
$$ f(v, w, m) = v + w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
v.mod_add_assign(w, 8);
assert_eq!(v.to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAddMul<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddMul<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul(self, w: &Self, c: T, m: T) -> Self
fn mod_add_mul(self, w: &Self, c: T, m: T) -> Self
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $m$, taking
the first vector by value and the second by reference. The elements and the scalar must
already be reduced modulo $m$.
See the documentation for the ModAddMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_add_mul(&w, 3, 7).to_string(), "(4, 5, 1)");This is equivalent to _nmod_vec_scalar_addmul_nmod from nmod_vec/scalar.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAddMul<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddMul<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
Source§fn mod_add_mul(self, w: &UnsignedVector<T>, c: T, m: T) -> UnsignedVector<T>
fn mod_add_mul(self, w: &UnsignedVector<T>, c: T, m: T) -> UnsignedVector<T>
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $m$, taking
both vectors by reference. The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModAddMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!((&v).mod_add_mul(&w, 3, 7).to_string(), "(4, 5, 1)");This is equivalent to _nmod_vec_scalar_addmul_nmod from nmod_vec/scalar.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAddMul<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddMul<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul(self, w: Self, c: T, m: T) -> Self
fn mod_add_mul(self, w: Self, c: T, m: T) -> Self
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $m$, taking
both vectors by value. The elements and the scalar must already be reduced modulo $m$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, m) = (v + cw) \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_add_mul(w, 3, 7).to_string(), "(4, 5, 1)");This is equivalent to _nmod_vec_scalar_addmul_nmod from nmod_vec/scalar.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModAddMulAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddMulAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul_assign(&mut self, w: &Self, c: T, m: T)
fn mod_add_mul_assign(&mut self, w: &Self, c: T, m: T)
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $m$, in
place, taking the vector on the right-hand side by reference. The elements and the scalar
must already be reduced modulo $m$.
See the documentation for the ModAddMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_add_mul_assign(&w, 3, 7);
assert_eq!(v.to_string(), "(4, 5, 1)");This is equivalent to _nmod_vec_scalar_addmul_nmod from nmod_vec/scalar.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAddMulAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAddMulAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul_assign(&mut self, w: Self, c: T, m: T)
fn mod_add_mul_assign(&mut self, w: Self, c: T, m: T)
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $m$, in
place, taking the vector on the right-hand side by value. The elements and the scalar must
already be reduced modulo $m$.
See the documentation for the ModAddMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_add_mul_assign(w, 3, 7);
assert_eq!(v.to_string(), "(4, 5, 1)");This is equivalent to _nmod_vec_scalar_addmul_nmod from nmod_vec/scalar.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShl<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShl<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul_shl(self, w: &Self, c: T, bits: u64, m: T) -> Self
fn mod_add_mul_shl(self, w: &Self, c: T, bits: u64, m: T) -> Self
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $m$, taking the first vector by value and the second by reference.
The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModAddMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_add_mul_shl(&w, 3, 2, 7).to_string(), "(1, 3, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShl<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShl<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
Source§fn mod_add_mul_shl(
self,
w: &UnsignedVector<T>,
c: T,
bits: u64,
m: T,
) -> UnsignedVector<T>
fn mod_add_mul_shl( self, w: &UnsignedVector<T>, c: T, bits: u64, m: T, ) -> UnsignedVector<T>
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $m$, taking both vectors by reference. The elements and the scalar
must already be reduced modulo $m$.
See the documentation for the ModAddMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!((&v).mod_add_mul_shl(&w, 3, 2, 7).to_string(), "(1, 3, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShl<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShl<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul_shl(self, w: Self, c: T, bits: u64, m: T) -> Self
fn mod_add_mul_shl(self, w: Self, c: T, bits: u64, m: T) -> Self
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $m$, taking both vectors by value. The elements and the scalar
must already be reduced modulo $m$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, b, m) = (v + cw2^b) \bmod m. $$
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_add_mul_shl(w, 3, 2, 7).to_string(), "(1, 3, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShlAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShlAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul_shl_assign(&mut self, w: &Self, c: T, bits: u64, m: T)
fn mod_add_mul_shl_assign(&mut self, w: &Self, c: T, bits: u64, m: T)
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $m$, in place, taking the vector on the right-hand side by
reference. The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModAddMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_add_mul_shl_assign(&w, 3, 2, 7);
assert_eq!(v.to_string(), "(1, 3, 2)");Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShlAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModAddMulShlAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_add_mul_shl_assign(&mut self, w: Self, c: T, bits: u64, m: T)
fn mod_add_mul_shl_assign(&mut self, w: Self, c: T, bits: u64, m: T)
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $m$, in place, taking the vector on the right-hand side by value.
The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModAddMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_add_mul_shl_assign(w, 3, 2, 7);
assert_eq!(v.to_string(), "(1, 3, 2)");Source§impl<T: PrimitiveUnsigned> ModAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModAssign<T> for UnsignedVector<T>
Source§fn mod_assign(&mut self, m: T)
fn mod_assign(&mut self, m: T)
Divides every element of an UnsignedVector by a T, replacing each element by the
remainder.
An UnsignedVector’s elements are never negative, so this agrees with %= everywhere; it
is the same operation under the name the mod-family traits use. See the documentation for
the Rem implementation on UnsignedVector that takes the vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u64>::from_str("(4, 4, 5)").unwrap();
v.mod_assign(3);
assert_eq!(v.to_string(), "(1, 1, 2)");Source§impl<T: PrimitiveUnsigned> ModDot<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModDot<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_dot(self, other: &Self, m: T) -> T
fn mod_dot(self, other: &Self, m: T) -> T
Computes the dot product of two UnsignedVectors modulo $m$, taking the first by value
and the second by reference. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, m) = \sum_{i=0}^{n-1} v_iw_i \bmod m, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if m is zero, if the vectors have different dimensions, or if any element is
greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModDot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!(v.clone().mod_dot(&w, 10), 5);This is equivalent to _nmod_vec_dot from nmod_vec/dot.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> ModDot<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModDot<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_dot(self, other: &UnsignedVector<T>, m: T) -> T
fn mod_dot(self, other: &UnsignedVector<T>, m: T) -> T
Computes the dot product of two UnsignedVectors modulo $m$, taking the first by
reference and the second by reference. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, m) = \sum_{i=0}^{n-1} v_iw_i \bmod m, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if m is zero, if the vectors have different dimensions, or if any element is
greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModDot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!((&v).mod_dot(&w, 10), 5);This is equivalent to _nmod_vec_dot from nmod_vec/dot.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> ModDot<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModDot<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_dot(self, other: Self, m: T) -> T
fn mod_dot(self, other: Self, m: T) -> T
Computes the dot product of two UnsignedVectors modulo $m$, taking the first by value
and the second by value. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, m) = \sum_{i=0}^{n-1} v_iw_i \bmod m, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if m is zero, if the vectors have different dimensions, or if any element is
greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModDot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!(v.clone().mod_dot(w.clone(), 10), 5);This is equivalent to _nmod_vec_dot from nmod_vec/dot.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> ModDot<UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModDot<UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_dot(self, other: UnsignedVector<T>, m: T) -> T
fn mod_dot(self, other: UnsignedVector<T>, m: T) -> T
Computes the dot product of two UnsignedVectors modulo $m$, taking the first by
reference and the second by value. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, m) = \sum_{i=0}^{n-1} v_iw_i \bmod m, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if m is zero, if the vectors have different dimensions, or if any element is
greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModDot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!((&v).mod_dot(w.clone(), 10), 5);This is equivalent to _nmod_vec_dot from nmod_vec/dot.c, FLINT 3.6.0.
type Output = T
Source§impl<T: PrimitiveUnsigned> ModElementProduct<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModElementProduct<T> for UnsignedVector<T>
Source§fn to_mod_element_product(&self, m: T) -> T
fn to_mod_element_product(&self, m: T) -> T
Returns the product of the elements of an UnsignedVector modulo another number $m$,
taking the vector by reference. The elements must already be reduced.
The 0-dimensional vector has no elements, and their product is 1, reduced: 0 when $m = 1$.
$$ f(v, m) = \prod_i v_i \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element is greater than or equal to m. As soon as the
partial product is zero, the remaining elements are not examined, so an unreduced element
after that point is not detected.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModElementProduct;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(3, 5, 7)").unwrap();
assert_eq!(v.to_mod_element_product(10), 5);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.to_mod_element_product(10), 1);Source§fn into_mod_element_product(self, m: T) -> T
fn into_mod_element_product(self, m: T) -> T
Returns the product of the elements of an UnsignedVector modulo another number $m$,
taking the vector by value. The elements must already be reduced.
The 0-dimensional vector has no elements, and their product is 1, reduced: 0 when $m = 1$.
$$ f(v, m) = \prod_i v_i \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element is greater than or equal to m. As soon as the
partial product is zero, the remaining elements are not examined, so an unreduced element
after that point is not detected.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModElementProduct;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(3, 5, 7)").unwrap();
assert_eq!(v.into_mod_element_product(10), 5);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.into_mod_element_product(10), 1);type Output = T
Source§impl<T: PrimitiveUnsigned> ModElementSum<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModElementSum<T> for UnsignedVector<T>
Source§fn to_mod_element_sum(&self, m: T) -> T
fn to_mod_element_sum(&self, m: T) -> T
Returns the sum of the elements of an UnsignedVector modulo another number $m$, taking
the vector by reference. The elements must already be reduced.
The 0-dimensional vector has no elements, and their sum is 0.
$$ f(v, m) = \sum_i v_i \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements.
§Panics
Panics if m is zero, or if any element is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModElementSum;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 6, 7)").unwrap();
assert_eq!(v.to_mod_element_sum(10), 8);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.to_mod_element_sum(10), 0);Source§fn into_mod_element_sum(self, m: T) -> T
fn into_mod_element_sum(self, m: T) -> T
Returns the sum of the elements of an UnsignedVector modulo another number $m$, taking
the vector by value. The elements must already be reduced.
The 0-dimensional vector has no elements, and their sum is 0.
$$ f(v, m) = \sum_i v_i \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements.
§Panics
Panics if m is zero, or if any element is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModElementSum;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 6, 7)").unwrap();
assert_eq!(v.into_mod_element_sum(10), 8);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.into_mod_element_sum(10), 0);type Output = T
Source§impl<T: PrimitiveUnsigned> ModIsReduced<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModIsReduced<T> for UnsignedVector<T>
Source§fn mod_is_reduced(&self, m: &T) -> bool
fn mod_is_reduced(&self, m: &T) -> bool
Returns whether an UnsignedVector is reduced modulo a T $m$; in other words, whether
every one of its elements is less than $m$.
The 0-dimensional vector has no elements and is reduced modulo every $m$.
$m$ cannot be zero.
$f(v, m) = (\max_i v_i < m)$, with the maximum of no elements taken to be 0.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModIsReduced;
use malachite_base::unsigned_vector::UnsignedVector;
// The elements are 2, 3, and 1, so 4 is large enough and 3 is not.
let v = UnsignedVector::<u64>::from_str("(2, 3, 1)").unwrap();
assert_eq!(v.mod_is_reduced(&4), true);
assert_eq!(v.mod_is_reduced(&3), false);
// The 0-dimensional vector is reduced modulo everything.
assert_eq!(
UnsignedVector::<u64>::from_str("()")
.unwrap()
.mod_is_reduced(&1),
true
);Source§impl<T: PrimitiveUnsigned> ModMul<T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModMul<T, T> for UnsignedVector<T>
Source§fn mod_mul(self, c: T, m: T) -> Self
fn mod_mul(self, c: T, m: T) -> Self
Multiplies every element of an UnsignedVector by a scalar modulo $m$, taking the vector
by value. The elements and the scalar must already be reduced modulo $m$.
Each product is reduced modulo $m$, and the result has the same dimension as the vector. The data for multiplying modulo $m$ is precomputed once and shared by all the elements.
$$ f(v, c, m) = cv \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element of self, or c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
assert_eq!(v.mod_mul(3, 7).to_string(), "(1, 3, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModMul<T, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModMul<T, T> for &UnsignedVector<T>
Source§fn mod_mul(self, c: T, m: T) -> UnsignedVector<T>
fn mod_mul(self, c: T, m: T) -> UnsignedVector<T>
Multiplies every element of an UnsignedVector by a scalar modulo $m$, taking the vector
by reference. The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModMul implementation that takes the vector by value for
details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element of self, or c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
assert_eq!((&v).mod_mul(3, 7).to_string(), "(1, 3, 2)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModMulAssign<T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModMulAssign<T, T> for UnsignedVector<T>
Source§fn mod_mul_assign(&mut self, c: T, m: T)
fn mod_mul_assign(&mut self, c: T, m: T)
Multiplies every element of an UnsignedVector by a scalar modulo $m$, in place. The
elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModMul implementation that takes the vector by value for
details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element of self, or c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_mul_assign(3, 7);
assert_eq!(v.to_string(), "(1, 3, 2)");Source§impl<T: PrimitiveUnsigned> ModNeg<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModNeg<T> for UnsignedVector<T>
Source§fn mod_neg(self, m: T) -> Self
fn mod_neg(self, m: T) -> Self
Negates an UnsignedVector modulo $m$, taking the vector by value. The elements must
already be reduced modulo $m$.
Each element $x$ becomes $-x \bmod m$: $m - x$ if $x$ is nonzero, and 0 if it is zero. The dimension is unchanged.
$$ f(v, m) = -v \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModNeg;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 0)").unwrap();
assert_eq!(v.mod_neg(7).to_string(), "(2, 6, 0)");This is equivalent to _nmod_vec_neg from nmod_vec/neg.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModNeg<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModNeg<T> for &UnsignedVector<T>
Source§fn mod_neg(self, m: T) -> UnsignedVector<T>
fn mod_neg(self, m: T) -> UnsignedVector<T>
Negates an UnsignedVector modulo $m$, taking the vector by reference. The elements must
already be reduced modulo $m$.
Each element $x$ becomes $-x \bmod m$: $m - x$ if $x$ is nonzero, and 0 if it is zero. The dimension is unchanged.
$$ f(v, m) = -v \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModNeg;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 0)").unwrap();
assert_eq!((&v).mod_neg(7).to_string(), "(2, 6, 0)");This is equivalent to _nmod_vec_neg from nmod_vec/neg.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModNegAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModNegAssign<T> for UnsignedVector<T>
Source§fn mod_neg_assign(&mut self, m: T)
fn mod_neg_assign(&mut self, m: T)
Negates an UnsignedVector modulo $m$, in place. The elements must already be reduced
modulo $m$.
See mod_neg.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, or if any element of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModNegAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 0)").unwrap();
v.mod_neg_assign(7);
assert_eq!(v.to_string(), "(2, 6, 0)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2 for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2 for UnsignedVector<T>
Source§fn mod_power_of_2(self, pow: u64) -> Self
fn mod_power_of_2(self, pow: u64) -> Self
Divides every element of an UnsignedVector by $2^k$, keeping the remainders, taking the
vector by value.
The result is reduced modulo $2^k$, which is to say that mod_power_of_2_is_reduced returns
true for it. The dimension is unchanged: unlike a polynomial, a vector keeps the elements
that reduce to zero, so $(4, 3)$ modulo 4 is $(0, 3)$.
No T reaches $2^W$, where $W$ is T::WIDTH, so for $k \geq W$ this leaves the vector
alone.
$$ f(v, k) = w, \quad \text{where} \quad w_i = v_i - 2^k \left \lfloor \frac{v_i}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_base::unsigned_vector::UnsignedVector;
// Every element is taken modulo 2.
assert_eq!(
UnsignedVector::<u64>::from_str("(1, 3, 2)")
.unwrap()
.mod_power_of_2(1)
.to_string(),
"(1, 1, 0)"
);
// An element that reduces to zero stays, so the dimension is unchanged.
assert_eq!(
UnsignedVector::<u64>::from_str("(4, 3)")
.unwrap()
.mod_power_of_2(2)
.to_string(),
"(0, 3)"
);
// A power at least as wide as the element type leaves the vector alone.
assert_eq!(
UnsignedVector::<u8>::from_str("(255, 1)")
.unwrap()
.mod_power_of_2(8)
.to_string(),
"(255, 1)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2 for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2 for &UnsignedVector<T>
Source§fn mod_power_of_2(self, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2(self, pow: u64) -> UnsignedVector<T>
Divides every element of an UnsignedVector by $2^k$, keeping the remainders, taking the
vector by reference.
See the documentation for the ModPowerOf2 implementation on UnsignedVector for
details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u64>::from_str("(4, 3)").unwrap();
assert_eq!((&v).mod_power_of_2(2).to_string(), "(0, 3)");
// The vector is left alone.
assert_eq!(v.to_string(), "(4, 3)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AbsSquared for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AbsSquared for UnsignedVector<T>
Source§fn mod_power_of_2_abs_squared(self, pow: u64) -> T
fn mod_power_of_2_abs_squared(self, pow: u64) -> T
Computes the squared norm of an UnsignedVector, the sum of the squares of its elements,
modulo $2^k$, taking the vector by value. The elements must already be reduced.
The squared norm of a 0-dimensional vector is 0.
$$ f(v, k) = \sum_{i=0}^{n-1} v_i^2 \bmod 2^k, $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vector.
§Panics
Panics if pow is greater than T::WIDTH or if any element is greater than or equal to
$2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AbsSquared;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.clone().mod_power_of_2_abs_squared(3), 6);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AbsSquared for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AbsSquared for &UnsignedVector<T>
Source§fn mod_power_of_2_abs_squared(self, pow: u64) -> T
fn mod_power_of_2_abs_squared(self, pow: u64) -> T
Computes the squared norm of an UnsignedVector, the sum of the squares of its elements,
modulo $2^k$, taking the vector by reference. The elements must already be reduced.
The squared norm of a 0-dimensional vector is 0.
$$ f(v, k) = \sum_{i=0}^{n-1} v_i^2 \bmod 2^k, $$
where $n$ is the dimension of $v$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vector.
§Panics
Panics if pow is greater than T::WIDTH or if any element is greater than or equal to
$2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AbsSquared;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
assert_eq!((&v).mod_power_of_2_abs_squared(3), 6);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add for UnsignedVector<T>
Source§fn mod_power_of_2_add(self, other: Self, pow: u64) -> Self
fn mod_power_of_2_add(self, other: Self, pow: u64) -> Self
Adds two UnsignedVectors modulo $2^k$, taking both by value. The elements of both must
already be reduced modulo $2^k$.
The sum is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the summands.
$$ f(v, w, k) = v + w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_power_of_2_add(w, 3).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn mod_power_of_2_add(self, other: &Self, pow: u64) -> Self
fn mod_power_of_2_add(self, other: &Self, pow: u64) -> Self
Adds two UnsignedVectors modulo $2^k$, taking the first by value and the second by
reference. The elements of both must already be reduced modulo $2^k$.
The sum is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the summands.
$$ f(v, w, k) = v + w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_power_of_2_add(&w, 3).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedVector<T>> for &UnsignedVector<T>
Source§fn mod_power_of_2_add(
self,
other: &UnsignedVector<T>,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_add( self, other: &UnsignedVector<T>, pow: u64, ) -> UnsignedVector<T>
Adds two UnsignedVectors modulo $2^k$, taking both by reference. The elements of both
must already be reduced modulo $2^k$.
The sum is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the summands.
$$ f(v, w, k) = v + w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_power_of_2_add(&w, 3).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add<UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add<UnsignedVector<T>> for &UnsignedVector<T>
Source§fn mod_power_of_2_add(
self,
other: UnsignedVector<T>,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_add( self, other: UnsignedVector<T>, pow: u64, ) -> UnsignedVector<T>
Adds two UnsignedVectors modulo $2^k$, taking the first by reference and the second by
value. The elements of both must already be reduced modulo $2^k$.
The sum is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the summands.
$$ f(v, w, k) = v + w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_power_of_2_add(w, 3).to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign for UnsignedVector<T>
Source§fn mod_power_of_2_add_assign(&mut self, other: Self, pow: u64)
fn mod_power_of_2_add_assign(&mut self, other: Self, pow: u64)
Adds an UnsignedVector to an UnsignedVector modulo $2^k$, in place, taking the
UnsignedVector on the right-hand side by value. The elements of both must already be
reduced modulo $2^k$.
The sum is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the summands.
$$ f(v, w, k) = v + w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_power_of_2_add_assign(UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap(), 3);
assert_eq!(v.to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn mod_power_of_2_add_assign(&mut self, other: &Self, pow: u64)
fn mod_power_of_2_add_assign(&mut self, other: &Self, pow: u64)
Adds an UnsignedVector to an UnsignedVector modulo $2^k$, in place, taking the
UnsignedVector on the right-hand side by reference. The elements of both must already be
reduced modulo $2^k$.
The sum is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the summands.
$$ f(v, w, k) = v + w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_power_of_2_add_assign(&UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap(), 3);
assert_eq!(v.to_string(), "(1, 0, 3)");This is equivalent to _nmod_vec_add from nmod_vec/add.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMul<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMul<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul(self, w: &Self, c: T, pow: u64) -> Self
fn mod_power_of_2_add_mul(self, w: &Self, c: T, pow: u64) -> Self
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $2^k$,
taking the first vector by value and the second by reference. The elements and the scalar
must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(v.mod_power_of_2_add_mul(&w, 3, 3).to_string(), "(3, 6, 7)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMul<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMul<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_power_of_2_add_mul(
self,
w: &UnsignedVector<T>,
c: T,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_add_mul( self, w: &UnsignedVector<T>, c: T, pow: u64, ) -> UnsignedVector<T>
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $2^k$,
taking both vectors by reference. The elements and the scalar must already be reduced modulo
$2^k$.
See the documentation for the ModPowerOf2AddMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
(&v).mod_power_of_2_add_mul(&w, 3, 3).to_string(),
"(3, 6, 7)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMul<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMul<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul(self, w: Self, c: T, pow: u64) -> Self
fn mod_power_of_2_add_mul(self, w: Self, c: T, pow: u64) -> Self
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $2^k$,
taking both vectors by value. The elements and the scalar must already be reduced modulo
$2^k$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, k) = (v + cw) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(v.mod_power_of_2_add_mul(w, 3, 3).to_string(), "(3, 6, 7)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_assign(&mut self, w: &Self, c: T, pow: u64)
fn mod_power_of_2_add_mul_assign(&mut self, w: &Self, c: T, pow: u64)
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $2^k$, in
place, taking the vector on the right-hand side by reference. The elements and the scalar
must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_add_mul_assign(&w, 3, 3);
assert_eq!(v.to_string(), "(3, 6, 7)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulAssign<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulAssign<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_assign(&mut self, w: Self, c: T, pow: u64)
fn mod_power_of_2_add_mul_assign(&mut self, w: Self, c: T, pow: u64)
Adds a scalar multiple of an UnsignedVector to an UnsignedVector modulo $2^k$, in
place, taking the vector on the right-hand side by value. The elements and the scalar must
already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_add_mul_assign(w, 3, 3);
assert_eq!(v.to_string(), "(3, 6, 7)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShl<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShl<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_shl(self, w: &Self, c: T, bits: u64, pow: u64) -> Self
fn mod_power_of_2_add_mul_shl(self, w: &Self, c: T, bits: u64, pow: u64) -> Self
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $2^k$, taking the first vector by value and the second by
reference. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
v.mod_power_of_2_add_mul_shl(&w, 3, 1, 4).to_string(),
"(1, 11, 11)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShl<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShl<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_shl(
self,
w: &UnsignedVector<T>,
c: T,
bits: u64,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_add_mul_shl( self, w: &UnsignedVector<T>, c: T, bits: u64, pow: u64, ) -> UnsignedVector<T>
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $2^k$, taking both vectors by reference. The elements and the
scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
(&v).mod_power_of_2_add_mul_shl(&w, 3, 1, 4).to_string(),
"(1, 11, 11)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShl<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShl<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_shl(self, w: Self, c: T, bits: u64, pow: u64) -> Self
fn mod_power_of_2_add_mul_shl(self, w: Self, c: T, bits: u64, pow: u64) -> Self
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $2^k$, taking both vectors by value. The elements and the scalar
must already be reduced modulo $2^k$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, b, k) = (v + cw2^b) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
v.mod_power_of_2_add_mul_shl(w, 3, 1, 4).to_string(),
"(1, 11, 11)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShlAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShlAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_shl_assign(
&mut self,
w: &Self,
c: T,
bits: u64,
pow: u64,
)
fn mod_power_of_2_add_mul_shl_assign( &mut self, w: &Self, c: T, bits: u64, pow: u64, )
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $2^k$, in place, taking the vector on the right-hand side by
reference. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_add_mul_shl_assign(&w, 3, 1, 4);
assert_eq!(v.to_string(), "(1, 11, 11)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShlAssign<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddMulShlAssign<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_add_mul_shl_assign(
&mut self,
w: Self,
c: T,
bits: u64,
pow: u64,
)
fn mod_power_of_2_add_mul_shl_assign( &mut self, w: Self, c: T, bits: u64, pow: u64, )
Adds a scalar multiple of an UnsignedVector, shifted left by bits, to an
UnsignedVector modulo $2^k$, in place, taking the vector on the right-hand side by
value. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2AddMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_add_mul_shl_assign(w, 3, 1, 4);
assert_eq!(v.to_string(), "(1, 11, 11)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2Assign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Assign for UnsignedVector<T>
Source§fn mod_power_of_2_assign(&mut self, pow: u64)
fn mod_power_of_2_assign(&mut self, pow: u64)
Divides every element of an UnsignedVector by $2^k$, replacing each element by the
remainder.
See the documentation for the ModPowerOf2 implementation on UnsignedVector for
details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Assign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u64>::from_str("(1, 3, 2)").unwrap();
v.mod_power_of_2_assign(1);
assert_eq!(v.to_string(), "(1, 1, 0)");
let mut v = UnsignedVector::<u64>::from_str("(4, 3)").unwrap();
v.mod_power_of_2_assign(2);
assert_eq!(v.to_string(), "(0, 3)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2Dot for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Dot for UnsignedVector<T>
Source§fn mod_power_of_2_dot(self, other: Self, pow: u64) -> T
fn mod_power_of_2_dot(self, other: Self, pow: u64) -> T
Computes the dot product of two UnsignedVectors modulo $2^k$, taking the first by value
and the second by value. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, k) = \sum_{i=0}^{n-1} v_iw_i \bmod 2^k, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if pow is greater than T::WIDTH, if the vectors have different dimensions, or if
any element is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Dot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!(v.clone().mod_power_of_2_dot(w.clone(), 4), 3);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Dot<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Dot<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn mod_power_of_2_dot(self, other: &Self, pow: u64) -> T
fn mod_power_of_2_dot(self, other: &Self, pow: u64) -> T
Computes the dot product of two UnsignedVectors modulo $2^k$, taking the first by value
and the second by reference. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, k) = \sum_{i=0}^{n-1} v_iw_i \bmod 2^k, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if pow is greater than T::WIDTH, if the vectors have different dimensions, or if
any element is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Dot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!(v.clone().mod_power_of_2_dot(&w, 4), 3);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Dot<&UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Dot<&UnsignedVector<T>> for &UnsignedVector<T>
Source§fn mod_power_of_2_dot(self, other: &UnsignedVector<T>, pow: u64) -> T
fn mod_power_of_2_dot(self, other: &UnsignedVector<T>, pow: u64) -> T
Computes the dot product of two UnsignedVectors modulo $2^k$, taking the first by
reference and the second by reference. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, k) = \sum_{i=0}^{n-1} v_iw_i \bmod 2^k, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if pow is greater than T::WIDTH, if the vectors have different dimensions, or if
any element is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Dot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!((&v).mod_power_of_2_dot(&w, 4), 3);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Dot<UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Dot<UnsignedVector<T>> for &UnsignedVector<T>
Source§fn mod_power_of_2_dot(self, other: UnsignedVector<T>, pow: u64) -> T
fn mod_power_of_2_dot(self, other: UnsignedVector<T>, pow: u64) -> T
Computes the dot product of two UnsignedVectors modulo $2^k$, taking the first by
reference and the second by value. The elements of both must already be reduced.
The dot product of two 0-dimensional vectors is 0.
$$ f(v, w, k) = \sum_{i=0}^{n-1} v_iw_i \bmod 2^k, $$
where $n$ is the dimension of $v$ and $w$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the dimension of the vectors.
§Panics
Panics if pow is greater than T::WIDTH, if the vectors have different dimensions, or if
any element is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Dot;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 5, 7)").unwrap();
assert_eq!((&v).mod_power_of_2_dot(w.clone(), 4), 3);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ElementProduct for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ElementProduct for UnsignedVector<T>
Source§fn to_mod_power_of_2_element_product(&self, pow: u64) -> T
fn to_mod_power_of_2_element_product(&self, pow: u64) -> T
Returns the product of the elements of an UnsignedVector modulo $2^k$, taking the vector
by reference. The elements must already be reduced.
The 0-dimensional vector has no elements, and their product is 1, reduced: 0 when $2^k = 1$.
$$ f(v, k) = \prod_i v_i \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element is greater than or equal to
$2^k$. As soon as the partial product is zero, the remaining elements are not examined, so
an unreduced element after that point is not detected.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2ElementProduct;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(3, 5, 7)").unwrap();
assert_eq!(v.to_mod_power_of_2_element_product(4), 9);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.to_mod_power_of_2_element_product(3), 1);Source§fn into_mod_power_of_2_element_product(self, pow: u64) -> T
fn into_mod_power_of_2_element_product(self, pow: u64) -> T
Returns the product of the elements of an UnsignedVector modulo $2^k$, taking the vector
by value. The elements must already be reduced.
The 0-dimensional vector has no elements, and their product is 1, reduced: 0 when $2^k = 1$.
$$ f(v, k) = \prod_i v_i \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element is greater than or equal to
$2^k$. As soon as the partial product is zero, the remaining elements are not examined, so
an unreduced element after that point is not detected.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2ElementProduct;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(3, 5, 7)").unwrap();
assert_eq!(v.into_mod_power_of_2_element_product(4), 9);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.into_mod_power_of_2_element_product(3), 1);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ElementSum for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ElementSum for UnsignedVector<T>
Source§fn to_mod_power_of_2_element_sum(&self, pow: u64) -> T
fn to_mod_power_of_2_element_sum(&self, pow: u64) -> T
Returns the sum of the elements of an UnsignedVector modulo $2^k$, taking the vector by
reference. The elements must already be reduced.
The 0-dimensional vector has no elements, and their sum is 0.
$$ f(v, k) = \sum_i v_i \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements.
§Panics
Panics if pow is greater than T::WIDTH, or if any element is greater than or equal to
$2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2ElementSum;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 6, 7)").unwrap();
assert_eq!(v.to_mod_power_of_2_element_sum(3), 2);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.to_mod_power_of_2_element_sum(3), 0);Source§fn into_mod_power_of_2_element_sum(self, pow: u64) -> T
fn into_mod_power_of_2_element_sum(self, pow: u64) -> T
Returns the sum of the elements of an UnsignedVector modulo $2^k$, taking the vector by
value. The elements must already be reduced.
The 0-dimensional vector has no elements, and their sum is 0.
$$ f(v, k) = \sum_i v_i \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements.
§Panics
Panics if pow is greater than T::WIDTH, or if any element is greater than or equal to
$2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2ElementSum;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 6, 7)").unwrap();
assert_eq!(v.into_mod_power_of_2_element_sum(3), 2);
let v = UnsignedVector::<u8>::from_str("()").unwrap();
assert_eq!(v.into_mod_power_of_2_element_sum(3), 0);type Output = T
Source§impl<T: PrimitiveUnsigned> ModPowerOf2IsReduced for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2IsReduced for UnsignedVector<T>
Source§fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool
fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool
Returns whether an UnsignedVector is reduced modulo $2^k$; in other words, whether every
one of its elements has no more than $k$ significant bits.
The 0-dimensional vector has no elements and is reduced modulo every power of 2, including
$2^0$. A vector of zeros is too, and every vector is reduced modulo $2^k$ for $k \geq W$,
where $W$ is T::WIDTH.
$f(v, k) = (\max_i v_i < 2^k)$, with the maximum of no elements taken to be 0.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2IsReduced;
use malachite_base::unsigned_vector::UnsignedVector;
// The largest element is 3, which needs two bits.
let v = UnsignedVector::<u64>::from_str("(1, 3, 2)").unwrap();
assert_eq!(v.mod_power_of_2_is_reduced(2), true);
assert_eq!(v.mod_power_of_2_is_reduced(1), false);
// The 0-dimensional vector and a vector of zeros are reduced modulo every power of 2.
assert_eq!(
UnsignedVector::<u64>::from_str("()")
.unwrap()
.mod_power_of_2_is_reduced(0),
true
);
assert_eq!(
UnsignedVector::<u64>::from_str("(0, 0)")
.unwrap()
.mod_power_of_2_is_reduced(0),
true
);Source§impl<T: PrimitiveUnsigned> ModPowerOf2Mul<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Mul<T> for UnsignedVector<T>
Source§fn mod_power_of_2_mul(self, c: T, pow: u64) -> Self
fn mod_power_of_2_mul(self, c: T, pow: u64) -> Self
Multiplies every element of an UnsignedVector by a scalar modulo $2^k$, taking the
vector by value. The elements and the scalar must already be reduced modulo $2^k$.
Each product is reduced modulo $2^k$, and the result has the same dimension as the vector.
$$ f(v, c, k) = cv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self, or c, is greater
than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
assert_eq!(v.mod_power_of_2_mul(3, 3).to_string(), "(7, 3, 1)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Mul<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Mul<T> for &UnsignedVector<T>
Source§fn mod_power_of_2_mul(self, c: T, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_mul(self, c: T, pow: u64) -> UnsignedVector<T>
Multiplies every element of an UnsignedVector by a scalar modulo $2^k$, taking the
vector by reference. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Mul implementation that takes the vector by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self, or c, is greater
than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
assert_eq!((&v).mod_power_of_2_mul(3, 3).to_string(), "(7, 3, 1)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulAssign<T> for UnsignedVector<T>
Source§fn mod_power_of_2_mul_assign(&mut self, c: T, pow: u64)
fn mod_power_of_2_mul_assign(&mut self, c: T, pow: u64)
Multiplies every element of an UnsignedVector by a scalar modulo $2^k$, in place. The
elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Mul implementation that takes the vector by
value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self, or c, is greater
than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_power_of_2_mul_assign(3, 3);
assert_eq!(v.to_string(), "(7, 3, 1)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2Neg for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Neg for UnsignedVector<T>
Source§fn mod_power_of_2_neg(self, pow: u64) -> Self
fn mod_power_of_2_neg(self, pow: u64) -> Self
Negates an UnsignedVector modulo $2^k$, taking the vector by value. The elements must
already be reduced modulo $2^k$.
Each element $x$ becomes $-x \bmod 2^k$: $2^k - x$ if $x$ is nonzero, and 0 if it is zero. The dimension is unchanged.
$$ f(v, k) = -v \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater than or
equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
assert_eq!(v.mod_power_of_2_neg(3).to_string(), "(3, 7, 5)");
// A zero element stays zero.
let v = UnsignedVector::<u8>::from_str("(0, 1)").unwrap();
assert_eq!(v.mod_power_of_2_neg(8).to_string(), "(0, 255)");This is equivalent to _nmod_vec_neg from nmod_vec/neg.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Neg for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Neg for &UnsignedVector<T>
Source§fn mod_power_of_2_neg(self, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_neg(self, pow: u64) -> UnsignedVector<T>
Negates an UnsignedVector modulo $2^k$, taking the vector by reference. The elements
must already be reduced modulo $2^k$.
Each element $x$ becomes $-x \bmod 2^k$: $2^k - x$ if $x$ is nonzero, and 0 if it is zero. The dimension is unchanged.
$$ f(v, k) = -v \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater than or
equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
assert_eq!((&v).mod_power_of_2_neg(3).to_string(), "(3, 7, 5)");This is equivalent to _nmod_vec_neg from nmod_vec/neg.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2NegAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2NegAssign for UnsignedVector<T>
Source§fn mod_power_of_2_neg_assign(&mut self, pow: u64)
fn mod_power_of_2_neg_assign(&mut self, pow: u64)
Negates an UnsignedVector modulo $2^k$, in place. The elements must already be reduced
modulo $2^k$.
See mod_power_of_2_neg.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater than or
equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2NegAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_power_of_2_neg_assign(3);
assert_eq!(v.to_string(), "(3, 7, 5)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by value. The elements must already be reduced modulo $2^k$.
Every element is shifted and reduced, and the dimension is unchanged, so elements
can become zero; if bits is at least pow, every element is zero.
$$ f(v, m, k) = 2^mv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for &UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by reference. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by value. The elements must already be reduced modulo $2^k$.
Every element is shifted and reduced, and the dimension is unchanged, so elements
can become zero; if bits is at least pow, every element is zero.
$$ f(v, m, k) = 2^mv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for &UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by reference. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by value. The elements must already be reduced modulo $2^k$.
Every element is shifted and reduced, and the dimension is unchanged, so elements
can become zero; if bits is at least pow, every element is zero.
$$ f(v, m, k) = 2^mv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for &UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by reference. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by value. The elements must already be reduced modulo $2^k$.
Every element is shifted and reduced, and the dimension is unchanged, so elements
can become zero; if bits is at least pow, every element is zero.
$$ f(v, m, k) = 2^mv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for &UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by reference. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by value. The elements must already be reduced modulo $2^k$.
Every element is shifted and reduced, and the dimension is unchanged, so elements
can become zero; if bits is at least pow, every element is zero.
$$ f(v, m, k) = 2^mv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for &UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by reference. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by value. The elements must already be reduced modulo $2^k$.
Every element is shifted and reduced, and the dimension is unchanged, so elements
can become zero; if bits is at least pow, every element is zero.
$$ f(v, m, k) = 2^mv \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for &UnsignedVector<T>
Source§fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedVector<T>
fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$,
taking the vector by reference. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u8> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u8> for UnsignedVector<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u8, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u8, pow: u64)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$, in
place. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u16> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u16> for UnsignedVector<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u16, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u16, pow: u64)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$, in
place. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u32> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u32> for UnsignedVector<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u32, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u32, pow: u64)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$, in
place. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u64> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u64> for UnsignedVector<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u64, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u64, pow: u64)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$, in
place. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u128> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u128> for UnsignedVector<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u128, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u128, pow: u64)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$, in
place. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<usize> for UnsignedVector<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: usize, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: usize, pow: u64)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $2^k$, in
place. The elements must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2Shl implementation that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, or if any element of self is greater
than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub for UnsignedVector<T>
Source§fn mod_power_of_2_sub(self, other: Self, pow: u64) -> Self
fn mod_power_of_2_sub(self, other: Self, pow: u64) -> Self
Subtracts two UnsignedVectors modulo $2^k$, taking both by value. The elements of both
must already be reduced modulo $2^k$.
The difference is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the operands.
$$ f(v, w, k) = v - w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_power_of_2_sub(w, 3).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn mod_power_of_2_sub(self, other: &Self, pow: u64) -> Self
fn mod_power_of_2_sub(self, other: &Self, pow: u64) -> Self
Subtracts two UnsignedVectors modulo $2^k$, taking the first by value and the second by
reference. The elements of both must already be reduced modulo $2^k$.
The difference is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the operands.
$$ f(v, w, k) = v - w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_power_of_2_sub(&w, 3).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedVector<T>> for &UnsignedVector<T>
Source§fn mod_power_of_2_sub(
self,
other: &UnsignedVector<T>,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_sub( self, other: &UnsignedVector<T>, pow: u64, ) -> UnsignedVector<T>
Subtracts two UnsignedVectors modulo $2^k$, taking both by reference. The elements of
both must already be reduced modulo $2^k$.
The difference is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the operands.
$$ f(v, w, k) = v - w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_power_of_2_sub(&w, 3).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub<UnsignedVector<T>> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub<UnsignedVector<T>> for &UnsignedVector<T>
Source§fn mod_power_of_2_sub(
self,
other: UnsignedVector<T>,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_sub( self, other: UnsignedVector<T>, pow: u64, ) -> UnsignedVector<T>
Subtracts two UnsignedVectors modulo $2^k$, taking the first by reference and the second
by value. The elements of both must already be reduced modulo $2^k$.
The difference is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the operands.
$$ f(v, w, k) = v - w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_power_of_2_sub(w, 3).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign for UnsignedVector<T>
Source§fn mod_power_of_2_sub_assign(&mut self, other: Self, pow: u64)
fn mod_power_of_2_sub_assign(&mut self, other: Self, pow: u64)
Subtracts an UnsignedVector from an UnsignedVector modulo $2^k$, in place, taking
the UnsignedVector on the right-hand side by value. The elements of both must already be
reduced modulo $2^k$.
The difference is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the operands.
$$ f(v, w, k) = v - w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_power_of_2_sub_assign(UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap(), 3);
assert_eq!(v.to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign<&UnsignedVector<T>> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign<&UnsignedVector<T>> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_assign(&mut self, other: &Self, pow: u64)
fn mod_power_of_2_sub_assign(&mut self, other: &Self, pow: u64)
Subtracts an UnsignedVector from an UnsignedVector modulo $2^k$, in place, taking
the UnsignedVector on the right-hand side by reference. The elements of both must
already be reduced modulo $2^k$.
The difference is taken element by element, each reduced modulo $2^k$, so the result has the same dimension as the operands.
$$ f(v, w, k) = v - w \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and other have different dimensions,
or if any element of either is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
v.mod_power_of_2_sub_assign(&UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap(), 3);
assert_eq!(v.to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMul<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMul<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul(self, w: &Self, c: T, pow: u64) -> Self
fn mod_power_of_2_sub_mul(self, w: &Self, c: T, pow: u64) -> Self
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo
$2^k$, taking the first vector by value and the second by reference. The elements and the
scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(v.mod_power_of_2_sub_mul(&w, 3, 3).to_string(), "(7, 4, 7)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMul<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMul<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul(
self,
w: &UnsignedVector<T>,
c: T,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_sub_mul( self, w: &UnsignedVector<T>, c: T, pow: u64, ) -> UnsignedVector<T>
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo
$2^k$, taking both vectors by reference. The elements and the scalar must already be reduced
modulo $2^k$.
See the documentation for the ModPowerOf2SubMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
(&v).mod_power_of_2_sub_mul(&w, 3, 3).to_string(),
"(7, 4, 7)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMul<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMul<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul(self, w: Self, c: T, pow: u64) -> Self
fn mod_power_of_2_sub_mul(self, w: Self, c: T, pow: u64) -> Self
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo
$2^k$, taking both vectors by value. The elements and the scalar must already be reduced
modulo $2^k$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, k) = (v - cw) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(v.mod_power_of_2_sub_mul(w, 3, 3).to_string(), "(7, 4, 7)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_assign(&mut self, w: &Self, c: T, pow: u64)
fn mod_power_of_2_sub_mul_assign(&mut self, w: &Self, c: T, pow: u64)
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo
$2^k$, in place, taking the vector on the right-hand side by reference. The elements and the
scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_sub_mul_assign(&w, 3, 3);
assert_eq!(v.to_string(), "(7, 4, 7)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulAssign<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulAssign<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_assign(&mut self, w: Self, c: T, pow: u64)
fn mod_power_of_2_sub_mul_assign(&mut self, w: Self, c: T, pow: u64)
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo
$2^k$, in place, taking the vector on the right-hand side by value. The elements and the
scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMul implementation that takes both vectors
by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_sub_mul_assign(w, 3, 3);
assert_eq!(v.to_string(), "(7, 4, 7)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShl<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShl<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_shl(self, w: &Self, c: T, bits: u64, pow: u64) -> Self
fn mod_power_of_2_sub_mul_shl(self, w: &Self, c: T, bits: u64, pow: u64) -> Self
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $2^k$, taking the first vector by value and the second by
reference. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
v.mod_power_of_2_sub_mul_shl(&w, 3, 1, 4).to_string(),
"(9, 7, 11)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShl<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShl<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_shl(
self,
w: &UnsignedVector<T>,
c: T,
bits: u64,
pow: u64,
) -> UnsignedVector<T>
fn mod_power_of_2_sub_mul_shl( self, w: &UnsignedVector<T>, c: T, bits: u64, pow: u64, ) -> UnsignedVector<T>
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $2^k$, taking both vectors by reference. The elements and the
scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
(&v).mod_power_of_2_sub_mul_shl(&w, 3, 1, 4).to_string(),
"(9, 7, 11)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShl<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShl<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_shl(self, w: Self, c: T, bits: u64, pow: u64) -> Self
fn mod_power_of_2_sub_mul_shl(self, w: Self, c: T, bits: u64, pow: u64) -> Self
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $2^k$, taking both vectors by value. The elements and the scalar
must already be reduced modulo $2^k$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, b, k) = (v - cw2^b) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
assert_eq!(
v.mod_power_of_2_sub_mul_shl(w, 3, 1, 4).to_string(),
"(9, 7, 11)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShlAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShlAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_shl_assign(
&mut self,
w: &Self,
c: T,
bits: u64,
pow: u64,
)
fn mod_power_of_2_sub_mul_shl_assign( &mut self, w: &Self, c: T, bits: u64, pow: u64, )
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $2^k$, in place, taking the vector on the right-hand side by
reference. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_sub_mul_shl_assign(&w, 3, 1, 4);
assert_eq!(v.to_string(), "(9, 7, 11)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShlAssign<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubMulShlAssign<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_power_of_2_sub_mul_shl_assign(
&mut self,
w: Self,
c: T,
bits: u64,
pow: u64,
)
fn mod_power_of_2_sub_mul_shl_assign( &mut self, w: Self, c: T, bits: u64, pow: u64, )
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $2^k$, in place, taking the vector on the right-hand side by
value. The elements and the scalar must already be reduced modulo $2^k$.
See the documentation for the ModPowerOf2SubMulShl implementation that takes both
vectors by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if pow is greater than T::WIDTH, if self and w have different dimensions, or
if any element of self or w, or c, is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 7, 4)").unwrap();
v.mod_power_of_2_sub_mul_shl_assign(w, 3, 1, 4);
assert_eq!(v.to_string(), "(9, 7, 11)");Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sum for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sum for UnsignedVector<T>
Source§fn mod_power_of_2_sum<I: Iterator<Item = Self>>(xs: I, pow: u64) -> Self
fn mod_power_of_2_sum<I: Iterator<Item = Self>>(xs: I, pow: u64) -> Self
Adds up all the UnsignedVectors in an iterator, entry by entry, modulo $2^k$. The
vectors must all have the same dimension, and their elements must already be reduced modulo
$2^k$.
$f((v_i)_ {i=0}^{n-1}, k) = w$, where every element of $w$ is less than $2^k$ and $\sum_ {i=0}^{n-1} v_i \equiv w \mod 2^k$, entry by entry.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of elements of all the vectors, and $m$ is the dimension of the vectors.
§Panics
Panics if the iterator is empty, if the vectors do not all have the same dimension, if pow
is greater than T::WIDTH, or if any element is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sum;
use malachite_base::unsigned_vector::UnsignedVector;
let vs = ["(5, 1, 3)", "(2, 7, 4)", "(6, 6, 6)"]
.map(|s| UnsignedVector::<u8>::from_str(s).unwrap());
assert_eq!(
UnsignedVector::mod_power_of_2_sum(vs.into_iter(), 3).to_string(),
"(5, 6, 5)"
);Source§impl<'a, T: PrimitiveUnsigned> ModPowerOf2Sum<&'a UnsignedVector<T>> for UnsignedVector<T>
impl<'a, T: PrimitiveUnsigned> ModPowerOf2Sum<&'a UnsignedVector<T>> for UnsignedVector<T>
Source§fn mod_power_of_2_sum<I: Iterator<Item = &'a Self>>(xs: I, pow: u64) -> Self
fn mod_power_of_2_sum<I: Iterator<Item = &'a Self>>(xs: I, pow: u64) -> Self
Adds up all the UnsignedVectors in an iterator of references, entry by entry, modulo
$2^k$. The vectors must all have the same dimension, and their elements must already be
reduced modulo $2^k$.
$f((v_i)_ {i=0}^{n-1}, k) = w$, where every element of $w$ is less than $2^k$ and $\sum_ {i=0}^{n-1} v_i \equiv w \mod 2^k$, entry by entry.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of elements of all the vectors, and $m$ is the dimension of the vectors.
§Panics
Panics if the iterator is empty, if the vectors do not all have the same dimension, if pow
is greater than T::WIDTH, or if any element is greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sum;
use malachite_base::unsigned_vector::UnsignedVector;
let vs = ["(5, 1, 3)", "(2, 7, 4)", "(6, 6, 6)"]
.map(|s| UnsignedVector::<u8>::from_str(s).unwrap());
assert_eq!(
UnsignedVector::mod_power_of_2_sum(vs.iter(), 3).to_string(),
"(5, 6, 5)"
);Source§impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for UnsignedVector<T>
Source§fn mod_shl(self, bits: u8, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u8, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by value. The elements must already be reduced modulo $m$.
$2^k \bmod m$ is computed once, and every element is multiplied by it, with the data for multiplying modulo $m$ also computed once. Since $m$ need not be odd, elements can become zero; the dimension is unchanged.
$$ f(v, k, m) = 2^kv \bmod m. $$
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for &UnsignedVector<T>
Source§fn mod_shl(self, bits: u8, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u8, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by reference. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for UnsignedVector<T>
Source§fn mod_shl(self, bits: u16, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u16, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by value. The elements must already be reduced modulo $m$.
$2^k \bmod m$ is computed once, and every element is multiplied by it, with the data for multiplying modulo $m$ also computed once. Since $m$ need not be odd, elements can become zero; the dimension is unchanged.
$$ f(v, k, m) = 2^kv \bmod m. $$
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for &UnsignedVector<T>
Source§fn mod_shl(self, bits: u16, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u16, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by reference. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for UnsignedVector<T>
Source§fn mod_shl(self, bits: u32, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u32, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by value. The elements must already be reduced modulo $m$.
$2^k \bmod m$ is computed once, and every element is multiplied by it, with the data for multiplying modulo $m$ also computed once. Since $m$ need not be odd, elements can become zero; the dimension is unchanged.
$$ f(v, k, m) = 2^kv \bmod m. $$
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for &UnsignedVector<T>
Source§fn mod_shl(self, bits: u32, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u32, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by reference. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for UnsignedVector<T>
Source§fn mod_shl(self, bits: u64, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u64, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by value. The elements must already be reduced modulo $m$.
$2^k \bmod m$ is computed once, and every element is multiplied by it, with the data for multiplying modulo $m$ also computed once. Since $m$ need not be odd, elements can become zero; the dimension is unchanged.
$$ f(v, k, m) = 2^kv \bmod m. $$
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for &UnsignedVector<T>
Source§fn mod_shl(self, bits: u64, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u64, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by reference. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for UnsignedVector<T>
Source§fn mod_shl(self, bits: u128, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u128, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by value. The elements must already be reduced modulo $m$.
$2^k \bmod m$ is computed once, and every element is multiplied by it, with the data for multiplying modulo $m$ also computed once. Since $m$ need not be odd, elements can become zero; the dimension is unchanged.
$$ f(v, k, m) = 2^kv \bmod m. $$
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for &UnsignedVector<T>
Source§fn mod_shl(self, bits: u128, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: u128, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by reference. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for UnsignedVector<T>
Source§fn mod_shl(self, bits: usize, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: usize, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by value. The elements must already be reduced modulo $m$.
$2^k \bmod m$ is computed once, and every element is multiplied by it, with the data for multiplying modulo $m$ also computed once. Since $m$ need not be odd, elements can become zero; the dimension is unchanged.
$$ f(v, k, m) = 2^kv \bmod m. $$
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for &UnsignedVector<T>
Source§fn mod_shl(self, bits: usize, m: T) -> UnsignedVector<T>
fn mod_shl(self, bits: usize, m: T) -> UnsignedVector<T>
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, taking
the vector by reference. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShlAssign<u8, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShlAssign<u8, T> for UnsignedVector<T>
Source§fn mod_shl_assign(&mut self, bits: u8, m: T)
fn mod_shl_assign(&mut self, bits: u8, m: T)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, in
place. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShlAssign<u16, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShlAssign<u16, T> for UnsignedVector<T>
Source§fn mod_shl_assign(&mut self, bits: u16, m: T)
fn mod_shl_assign(&mut self, bits: u16, m: T)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, in
place. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShlAssign<u32, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShlAssign<u32, T> for UnsignedVector<T>
Source§fn mod_shl_assign(&mut self, bits: u32, m: T)
fn mod_shl_assign(&mut self, bits: u32, m: T)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, in
place. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShlAssign<u64, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShlAssign<u64, T> for UnsignedVector<T>
Source§fn mod_shl_assign(&mut self, bits: u64, m: T)
fn mod_shl_assign(&mut self, bits: u64, m: T)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, in
place. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShlAssign<u128, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShlAssign<u128, T> for UnsignedVector<T>
Source§fn mod_shl_assign(&mut self, bits: u128, m: T)
fn mod_shl_assign(&mut self, bits: u128, m: T)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, in
place. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShlAssign<usize, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShlAssign<usize, T> for UnsignedVector<T>
Source§fn mod_shl_assign(&mut self, bits: usize, m: T)
fn mod_shl_assign(&mut self, bits: usize, m: T)
Left-shifts an UnsignedVector (multiplies it by a power of 2) modulo $m$, in
place. The elements must already be reduced modulo $m$.
See the documentation for the ModShl implementation that takes everything by
value for details.
§Worst-case complexity
$T(n, k) = O(n + k)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $k$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any element of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModSub<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSub<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_sub(self, other: &Self, m: T) -> Self
fn mod_sub(self, other: &Self, m: T) -> Self
Subtracts two UnsignedVectors modulo $m$, taking the first by value and the second by
reference. The elements of both must already be reduced modulo $m$.
The difference is taken element by element, each reduced modulo $m$, so the result has the same dimension as the operands.
$$ f(v, w, m) = v - w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_sub(&w, 8).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSub<&UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSub<&UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_sub(self, other: &UnsignedVector<T>, m: T) -> UnsignedVector<T>
fn mod_sub(self, other: &UnsignedVector<T>, m: T) -> UnsignedVector<T>
Subtracts two UnsignedVectors modulo $m$, taking the first by reference and the second
by reference. The elements of both must already be reduced modulo $m$.
The difference is taken element by element, each reduced modulo $m$, so the result has the same dimension as the operands.
$$ f(v, w, m) = v - w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_sub(&w, 8).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSub<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSub<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_sub(self, other: Self, m: T) -> Self
fn mod_sub(self, other: Self, m: T) -> Self
Subtracts two UnsignedVectors modulo $m$, taking the first by value and the second by
value. The elements of both must already be reduced modulo $m$.
The difference is taken element by element, each reduced modulo $m$, so the result has the same dimension as the operands.
$$ f(v, w, m) = v - w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!(v.mod_sub(w, 8).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSub<UnsignedVector<T>, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSub<UnsignedVector<T>, T> for &UnsignedVector<T>
Source§fn mod_sub(self, other: UnsignedVector<T>, m: T) -> UnsignedVector<T>
fn mod_sub(self, other: UnsignedVector<T>, m: T) -> UnsignedVector<T>
Subtracts two UnsignedVectors modulo $m$, taking the first by reference and the second
by value. The elements of both must already be reduced modulo $m$.
The difference is taken element by element, each reduced modulo $m$, so the result has the same dimension as the operands.
$$ f(v, w, m) = v - w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
assert_eq!((&v).mod_sub(w, 8).to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0.
type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSubAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubAssign<&UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_sub_assign(&mut self, other: &Self, m: T)
fn mod_sub_assign(&mut self, other: &Self, m: T)
Subtracts an UnsignedVector from an UnsignedVector modulo $m$, in place, taking the
UnsignedVector on the right-hand side by reference. The elements of both must already be
reduced modulo $m$.
The difference is taken element by element, each reduced modulo $m$, so the result has the same dimension as the operands.
$$ f(v, w, m) = v - w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
v.mod_sub_assign(&w, 8);
assert_eq!(v.to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModSubAssign<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubAssign<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_sub_assign(&mut self, other: Self, m: T)
fn mod_sub_assign(&mut self, other: Self, m: T)
Subtracts an UnsignedVector from an UnsignedVector modulo $m$, in place, taking the
UnsignedVector on the right-hand side by value. The elements of both must already be
reduced modulo $m$.
The difference is taken element by element, each reduced modulo $m$, so the result has the same dimension as the operands.
$$ f(v, w, m) = v - w \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is zero, if self and other have different dimensions, or if any element of
either is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(4, 7, 0)").unwrap();
v.mod_sub_assign(w, 8);
assert_eq!(v.to_string(), "(1, 2, 3)");This is equivalent to _nmod_vec_sub from nmod_vec/sub.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModSubMul<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubMul<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul(self, w: &Self, c: T, m: T) -> Self
fn mod_sub_mul(self, w: &Self, c: T, m: T) -> Self
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo $m$,
taking the first vector by value and the second by reference. The elements and the scalar
must already be reduced modulo $m$.
See the documentation for the ModSubMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_sub_mul(&w, 3, 7).to_string(), "(6, 4, 5)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSubMul<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubMul<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
Source§fn mod_sub_mul(self, w: &UnsignedVector<T>, c: T, m: T) -> UnsignedVector<T>
fn mod_sub_mul(self, w: &UnsignedVector<T>, c: T, m: T) -> UnsignedVector<T>
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo $m$,
taking both vectors by reference. The elements and the scalar must already be reduced modulo
$m$.
See the documentation for the ModSubMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!((&v).mod_sub_mul(&w, 3, 7).to_string(), "(6, 4, 5)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSubMul<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubMul<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul(self, w: Self, c: T, m: T) -> Self
fn mod_sub_mul(self, w: Self, c: T, m: T) -> Self
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo $m$,
taking both vectors by value. The elements and the scalar must already be reduced modulo
$m$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, m) = (v - cw) \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMul;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_sub_mul(w, 3, 7).to_string(), "(6, 4, 5)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ModSubMulAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubMulAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul_assign(&mut self, w: &Self, c: T, m: T)
fn mod_sub_mul_assign(&mut self, w: &Self, c: T, m: T)
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo $m$,
in place, taking the vector on the right-hand side by reference. The elements and the scalar
must already be reduced modulo $m$.
See the documentation for the ModSubMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_sub_mul_assign(&w, 3, 7);
assert_eq!(v.to_string(), "(6, 4, 5)");Source§impl<T: PrimitiveUnsigned> ModSubMulAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSubMulAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul_assign(&mut self, w: Self, c: T, m: T)
fn mod_sub_mul_assign(&mut self, w: Self, c: T, m: T)
Subtracts a scalar multiple of an UnsignedVector from an UnsignedVector modulo $m$,
in place, taking the vector on the right-hand side by value. The elements and the scalar
must already be reduced modulo $m$.
See the documentation for the ModSubMul implementation that takes both vectors by value
for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_sub_mul_assign(w, 3, 7);
assert_eq!(v.to_string(), "(6, 4, 5)");Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShl<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShl<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul_shl(self, w: &Self, c: T, bits: u64, m: T) -> Self
fn mod_sub_mul_shl(self, w: &Self, c: T, bits: u64, m: T) -> Self
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $m$, taking the first vector by value and the second by reference.
The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModSubMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_sub_mul_shl(&w, 3, 2, 7).to_string(), "(2, 6, 4)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShl<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShl<&UnsignedVector<T>, T, T> for &UnsignedVector<T>
Source§fn mod_sub_mul_shl(
self,
w: &UnsignedVector<T>,
c: T,
bits: u64,
m: T,
) -> UnsignedVector<T>
fn mod_sub_mul_shl( self, w: &UnsignedVector<T>, c: T, bits: u64, m: T, ) -> UnsignedVector<T>
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $m$, taking both vectors by reference. The elements and the scalar
must already be reduced modulo $m$.
See the documentation for the ModSubMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!((&v).mod_sub_mul_shl(&w, 3, 2, 7).to_string(), "(2, 6, 4)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShl<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShl<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul_shl(self, w: Self, c: T, bits: u64, m: T) -> Self
fn mod_sub_mul_shl(self, w: Self, c: T, bits: u64, m: T) -> Self
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $m$, taking both vectors by value. The elements and the scalar
must already be reduced modulo $m$.
The operation is taken element by element, so the result has the same dimension as the vectors.
$$ f(v, w, c, b, m) = (v - cw2^b) \bmod m. $$
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulShl;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
assert_eq!(v.mod_sub_mul_shl(w, 3, 2, 7).to_string(), "(2, 6, 4)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShlAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShlAssign<&UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul_shl_assign(&mut self, w: &Self, c: T, bits: u64, m: T)
fn mod_sub_mul_shl_assign(&mut self, w: &Self, c: T, bits: u64, m: T)
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $m$, in place, taking the vector on the right-hand side by
reference. The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModSubMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_sub_mul_shl_assign(&w, 3, 2, 7);
assert_eq!(v.to_string(), "(2, 6, 4)");Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShlAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModSubMulShlAssign<UnsignedVector<T>, T, T> for UnsignedVector<T>
Source§fn mod_sub_mul_shl_assign(&mut self, w: Self, c: T, bits: u64, m: T)
fn mod_sub_mul_shl_assign(&mut self, w: Self, c: T, bits: u64, m: T)
Subtracts a scalar multiple of an UnsignedVector, shifted left by bits, from an
UnsignedVector modulo $m$, in place, taking the vector on the right-hand side by value.
The elements and the scalar must already be reduced modulo $m$.
See the documentation for the ModSubMulShl implementation that takes both vectors by
value for details.
§Worst-case complexity
$T(n, b) = O(n + \log b)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.dimension(), and $b$ is bits.
§Panics
Panics if self and w have different dimensions, or if any element of self or w, or
c, is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubMulShlAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(5, 1, 3)").unwrap();
let w = UnsignedVector::<u8>::from_str("(2, 6, 4)").unwrap();
v.mod_sub_mul_shl_assign(w, 3, 2, 7);
assert_eq!(v.to_string(), "(2, 6, 4)");Source§impl<'a, T: PrimitiveUnsigned> ModSum<&'a UnsignedVector<T>, T> for UnsignedVector<T>
impl<'a, T: PrimitiveUnsigned> ModSum<&'a UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_sum<I: Iterator<Item = &'a Self>>(xs: I, m: T) -> Self
fn mod_sum<I: Iterator<Item = &'a Self>>(xs: I, m: T) -> Self
Adds up all the UnsignedVectors in an iterator of references, entry by entry, modulo
another number $m$. The vectors must all have the same dimension, and their elements must
already be reduced modulo $m$.
$f((v_i)_ {i=0}^{n-1}, m) = w$, where every element of $w$ is less than $m$ and $\sum_ {i=0}^{n-1} v_i \equiv w \mod m$, entry by entry.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of elements of all the vectors, and $m$ is the dimension of the vectors.
§Panics
Panics if the iterator is empty, if the vectors do not all have the same dimension, or if
any element is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSum;
use malachite_base::unsigned_vector::UnsignedVector;
let vs = ["(5, 1, 3)", "(2, 6, 4)", "(6, 2, 5)"]
.map(|s| UnsignedVector::<u8>::from_str(s).unwrap());
assert_eq!(
UnsignedVector::mod_sum(vs.iter(), 7).to_string(),
"(6, 2, 5)"
);Source§impl<T: PrimitiveUnsigned> ModSum<UnsignedVector<T>, T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ModSum<UnsignedVector<T>, T> for UnsignedVector<T>
Source§fn mod_sum<I: Iterator<Item = Self>>(xs: I, m: T) -> Self
fn mod_sum<I: Iterator<Item = Self>>(xs: I, m: T) -> Self
Adds up all the UnsignedVectors in an iterator, entry by entry, modulo another number
$m$. The vectors must all have the same dimension, and their elements must already be
reduced modulo $m$.
$f((v_i)_ {i=0}^{n-1}, m) = w$, where every element of $w$ is less than $m$ and $\sum_ {i=0}^{n-1} v_i \equiv w \mod m$, entry by entry.
§Worst-case complexity
$T(n) = O(n)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, $n$ is the total number of elements of all the vectors, and $m$ is the dimension of the vectors.
§Panics
Panics if the iterator is empty, if the vectors do not all have the same dimension, or if
any element is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSum;
use malachite_base::unsigned_vector::UnsignedVector;
let vs = ["(5, 1, 3)", "(2, 6, 4)", "(6, 2, 5)"]
.map(|s| UnsignedVector::<u8>::from_str(s).unwrap());
assert_eq!(
UnsignedVector::mod_sum(vs.into_iter(), 7).to_string(),
"(6, 2, 5)"
);Source§impl Named for UnsignedVector<u8>
impl Named for UnsignedVector<u8>
Source§impl Named for UnsignedVector<u16>
impl Named for UnsignedVector<u16>
Source§impl Named for UnsignedVector<u32>
impl Named for UnsignedVector<u32>
Source§impl Named for UnsignedVector<u64>
impl Named for UnsignedVector<u64>
Source§impl Named for UnsignedVector<u128>
impl Named for UnsignedVector<u128>
Source§impl Named for UnsignedVector<usize>
impl Named for UnsignedVector<usize>
Source§impl<T: PartialEq + PrimitiveUnsigned> PartialEq for UnsignedVector<T>
impl<T: PartialEq + PrimitiveUnsigned> PartialEq for UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> PrimitivePart for UnsignedVector<T>
impl<T: PrimitiveUnsigned> PrimitivePart for UnsignedVector<T>
Source§fn primitive_part(self) -> Self
fn primitive_part(self) -> Self
Computes the primitive part of an UnsignedVector, taking the vector by value.
This is the vector divided by its content. The elements are non-negative, so this is also
the CanonicalPrimitivePart.
$$ v = \operatorname{cont}(v) \operatorname{pp}(v). $$
The primitive part of a vector of zeros is itself, keeping its dimension.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::PrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!(v.primitive_part().to_string(), "(3, 2, 5)");
assert_eq!(
UnsignedVector::<u8>::from_str("(0, 0)")
.unwrap()
.primitive_part()
.to_string(),
"(0, 0)"
);type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> PrimitivePart for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> PrimitivePart for &UnsignedVector<T>
Source§fn primitive_part(self) -> UnsignedVector<T>
fn primitive_part(self) -> UnsignedVector<T>
Computes the primitive part of an UnsignedVector, taking the vector by reference.
This is the vector divided by its content. The elements are non-negative, so this is also
the CanonicalPrimitivePart.
$$ v = \operatorname{cont}(v) \operatorname{pp}(v). $$
The primitive part of a vector of zeros is itself, keeping its dimension.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::PrimitivePart;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
assert_eq!((&v).primitive_part().to_string(), "(3, 2, 5)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> PrimitivePartAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> PrimitivePartAssign for UnsignedVector<T>
Source§fn primitive_part_assign(&mut self)
fn primitive_part_assign(&mut self)
Replaces an UnsignedVector with its primitive part, the vector divided by its content.
See primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::PrimitivePartAssign;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u8>::from_str("(6, 4, 10)").unwrap();
v.primitive_part_assign();
assert_eq!(v.to_string(), "(3, 2, 5)");Source§impl<T: PrimitiveUnsigned> Rem<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Rem<T> for UnsignedVector<T>
Source§fn rem(self, m: T) -> Self
fn rem(self, m: T) -> Self
Divides every element of an UnsignedVector by a T, keeping the remainders, taking the
vector by value.
$v \% m$ is the vector whose $i$th element is $v_i \% m$. The dimension is unchanged: unlike a polynomial, a vector keeps the elements that reduce to zero, so $(4, 3)$ modulo 4 is $(0, 3)$.
The result is reduced modulo $m$, which is to say that
mod_is_reduced returns
true for it.
$$ f(v, m) = w, \quad \text{where} \quad w_i = v_i - m \left \lfloor \frac{v_i}{m} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u64>::from_str("(5, 4, 1)").unwrap();
assert_eq!((v % 3).to_string(), "(2, 1, 1)");
// An element that reduces to zero stays, so the dimension is unchanged.
let v = UnsignedVector::<u64>::from_str("(4, 3)").unwrap();
assert_eq!((v % 4).to_string(), "(0, 3)");Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
% operator.Source§impl<T: PrimitiveUnsigned> Rem<T> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Rem<T> for &UnsignedVector<T>
Source§fn rem(self, m: T) -> UnsignedVector<T>
fn rem(self, m: T) -> UnsignedVector<T>
Divides every element of an UnsignedVector by a T, keeping the remainders, taking the
vector by reference.
See the documentation for the Rem implementation on UnsignedVector that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let v = UnsignedVector::<u64>::from_str("(5, 4, 1)").unwrap();
assert_eq!((&v % 3).to_string(), "(2, 1, 1)");
// An element that reduces to zero stays, so the dimension is unchanged.
let v = UnsignedVector::<u64>::from_str("(4, 3)").unwrap();
assert_eq!((&v % 4).to_string(), "(0, 3)");
// The vector is left alone.
assert_eq!(v.to_string(), "(4, 3)");Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
% operator.Source§impl<T: PrimitiveUnsigned> RemAssign<T> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> RemAssign<T> for UnsignedVector<T>
Source§fn rem_assign(&mut self, m: T)
fn rem_assign(&mut self, m: T)
Divides every element of an UnsignedVector by a T, replacing each element by the
remainder.
See the documentation for the Rem implementation on UnsignedVector that takes the
vector by value for details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
let mut v = UnsignedVector::<u64>::from_str("(5, 4, 1)").unwrap();
v %= 3;
assert_eq!(v.to_string(), "(2, 1, 1)");
let mut v = UnsignedVector::<u64>::from_str("(4, 3)").unwrap();
v %= 4;
assert_eq!(v.to_string(), "(0, 3)");Source§impl<T: PrimitiveUnsigned> SelectCoordinates for UnsignedVector<T>
impl<T: PrimitiveUnsigned> SelectCoordinates for UnsignedVector<T>
Source§fn select_coordinates(self, indices: &[u64]) -> Self
fn select_coordinates(self, indices: &[u64]) -> Self
Selects coordinates of an UnsignedVector by index, taking the vector by value.
Element $j$ of the result is element indices[j] of the original, so the result’s dimension
is the number of indices. The indices may repeat and may appear in any order.
Elements are moved rather than cloned wherever possible: when the indices are strictly increasing, nothing is cloned or allocated, and otherwise an element is cloned only once for each extra time it is selected.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension() plus
indices.len().
§Panics
Panics if any index is greater than or equal to self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::SelectCoordinates;
let v = UnsignedVector::<u8>::from_str("(10, 20, 30)").unwrap();
assert_eq!(
v.clone().select_coordinates(&[2, 0]).to_string(),
"(30, 10)"
);
assert_eq!(
v.clone().select_coordinates(&[1, 1, 1]).to_string(),
"(20, 20, 20)"
);
assert_eq!(v.select_coordinates(&[0, 2]).to_string(), "(10, 30)");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> SelectCoordinates for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> SelectCoordinates for &UnsignedVector<T>
Source§fn select_coordinates(self, indices: &[u64]) -> UnsignedVector<T>
fn select_coordinates(self, indices: &[u64]) -> UnsignedVector<T>
Selects coordinates of an UnsignedVector by index, taking the vector by reference.
Element $j$ of the result is element indices[j] of the original, so the result’s dimension
is the number of indices. The indices may repeat and may appear in any order.
The selected elements are cloned.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is indices.len().
§Panics
Panics if any index is greater than or equal to self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::SelectCoordinates;
let v = UnsignedVector::<u8>::from_str("(10, 20, 30)").unwrap();
assert_eq!((&v).select_coordinates(&[2, 0]).to_string(), "(30, 10)");
assert_eq!(
(&v).select_coordinates(&[1, 1, 1]).to_string(),
"(20, 20, 20)"
);
assert_eq!((&v).select_coordinates(&[]).to_string(), "()");type Output = UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> SelectCoordinatesAssign for UnsignedVector<T>
impl<T: PrimitiveUnsigned> SelectCoordinatesAssign for UnsignedVector<T>
Source§fn select_coordinates_assign(&mut self, indices: &[u64])
fn select_coordinates_assign(&mut self, indices: &[u64])
Selects coordinates of an UnsignedVector by index, in place.
Afterwards, element $j$ of the vector is what element indices[j] was before, so its
dimension is the number of indices. The indices may repeat and may appear in any order.
Elements are moved rather than cloned wherever possible: when the indices are strictly increasing, nothing is cloned or allocated, and otherwise an element is cloned only once for each extra time it is selected.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension() plus
indices.len().
§Panics
Panics if any index is greater than or equal to self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::SelectCoordinatesAssign;
let mut v = UnsignedVector::<u8>::from_str("(10, 20, 30)").unwrap();
v.select_coordinates_assign(&[2, 0]);
assert_eq!(v.to_string(), "(30, 10)");
v.select_coordinates_assign(&[1, 1]);
assert_eq!(v.to_string(), "(10, 10)");Source§impl<T: PrimitiveUnsigned> Shr<u8> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u8> for UnsignedVector<T>
Source§fn shr(self, bits: u8) -> UnsignedVector<T>
fn shr(self, bits: u8) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by value. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
There is no corresponding non-modular left shift, since it could overflow; use
mod_power_of_2_shl or
mod_shl instead.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u8> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u8> for &UnsignedVector<T>
Source§fn shr(self, bits: u8) -> UnsignedVector<T>
fn shr(self, bits: u8) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by reference. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u16> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u16> for UnsignedVector<T>
Source§fn shr(self, bits: u16) -> UnsignedVector<T>
fn shr(self, bits: u16) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by value. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
There is no corresponding non-modular left shift, since it could overflow; use
mod_power_of_2_shl or
mod_shl instead.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u16> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u16> for &UnsignedVector<T>
Source§fn shr(self, bits: u16) -> UnsignedVector<T>
fn shr(self, bits: u16) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by reference. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u32> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u32> for UnsignedVector<T>
Source§fn shr(self, bits: u32) -> UnsignedVector<T>
fn shr(self, bits: u32) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by value. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
There is no corresponding non-modular left shift, since it could overflow; use
mod_power_of_2_shl or
mod_shl instead.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u32> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u32> for &UnsignedVector<T>
Source§fn shr(self, bits: u32) -> UnsignedVector<T>
fn shr(self, bits: u32) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by reference. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u64> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u64> for UnsignedVector<T>
Source§fn shr(self, bits: u64) -> UnsignedVector<T>
fn shr(self, bits: u64) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by value. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
There is no corresponding non-modular left shift, since it could overflow; use
mod_power_of_2_shl or
mod_shl instead.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u64> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u64> for &UnsignedVector<T>
Source§fn shr(self, bits: u64) -> UnsignedVector<T>
fn shr(self, bits: u64) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by reference. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u128> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u128> for UnsignedVector<T>
Source§fn shr(self, bits: u128) -> UnsignedVector<T>
fn shr(self, bits: u128) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by value. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
There is no corresponding non-modular left shift, since it could overflow; use
mod_power_of_2_shl or
mod_shl instead.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<u128> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<u128> for &UnsignedVector<T>
Source§fn shr(self, bits: u128) -> UnsignedVector<T>
fn shr(self, bits: u128) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by reference. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<usize> for UnsignedVector<T>
Source§fn shr(self, bits: usize) -> UnsignedVector<T>
fn shr(self, bits: usize) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by value. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
There is no corresponding non-modular left shift, since it could overflow; use
mod_power_of_2_shl or
mod_shl instead.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> Shr<usize> for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> Shr<usize> for &UnsignedVector<T>
Source§fn shr(self, bits: usize) -> UnsignedVector<T>
fn shr(self, bits: usize) -> UnsignedVector<T>
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
taking it by reference. Every element is shifted, and the dimension is unchanged; if
bits is at least T::WIDTH, every element is zero.
$f(v, k) = \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round
differently, use
entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§type Output = UnsignedVector<T>
type Output = UnsignedVector<T>
>> operator.Source§impl<T: PrimitiveUnsigned> ShrAssign<u8> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ShrAssign<u8> for UnsignedVector<T>
Source§fn shr_assign(&mut self, bits: u8)
fn shr_assign(&mut self, bits: u8)
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
in place. Every element is shifted, and the dimension is unchanged; if bits is at
least T::WIDTH, every element becomes zero.
$v \gets \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round differently,
use entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ShrAssign<u16> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ShrAssign<u16> for UnsignedVector<T>
Source§fn shr_assign(&mut self, bits: u16)
fn shr_assign(&mut self, bits: u16)
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
in place. Every element is shifted, and the dimension is unchanged; if bits is at
least T::WIDTH, every element becomes zero.
$v \gets \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round differently,
use entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ShrAssign<u32> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ShrAssign<u32> for UnsignedVector<T>
Source§fn shr_assign(&mut self, bits: u32)
fn shr_assign(&mut self, bits: u32)
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
in place. Every element is shifted, and the dimension is unchanged; if bits is at
least T::WIDTH, every element becomes zero.
$v \gets \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round differently,
use entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ShrAssign<u64> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ShrAssign<u64> for UnsignedVector<T>
Source§fn shr_assign(&mut self, bits: u64)
fn shr_assign(&mut self, bits: u64)
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
in place. Every element is shifted, and the dimension is unchanged; if bits is at
least T::WIDTH, every element becomes zero.
$v \gets \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round differently,
use entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ShrAssign<u128> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ShrAssign<u128> for UnsignedVector<T>
Source§fn shr_assign(&mut self, bits: u128)
fn shr_assign(&mut self, bits: u128)
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
in place. Every element is shifted, and the dimension is unchanged; if bits is at
least T::WIDTH, every element becomes zero.
$v \gets \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round differently,
use entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ShrAssign<usize> for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ShrAssign<usize> for UnsignedVector<T>
Source§fn shr_assign(&mut self, bits: usize)
fn shr_assign(&mut self, bits: usize)
Right-shifts an UnsignedVector (divides it by a power of 2 and takes the floor),
in place. Every element is shifted, and the dimension is unchanged; if bits is at
least T::WIDTH, every element becomes zero.
$v \gets \lfloor v/2^k \rfloor$. The floor is taken entrywise; to round differently,
use entrywise_shr_round.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> SignificantBits for &UnsignedVector<T>
impl<T: PrimitiveUnsigned> SignificantBits for &UnsignedVector<T>
Source§fn significant_bits(self) -> u64
fn significant_bits(self) -> u64
Returns the sum of the numbers of significant bits of the elements of an UnsignedVector.
This is the number of bits needed to store all of the elements, and 0 for the 0-dimensional vector.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::num::logic::traits::SignificantBits;
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 5, 2)")
.unwrap()
.significant_bits(),
6
);
assert_eq!(
UnsignedVector::<u8>::from_str("()")
.unwrap()
.significant_bits(),
0
);impl<T: PartialEq + PrimitiveUnsigned> StructuralPartialEq for UnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> ToLatex for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ToLatex for UnsignedVector<T>
Source§fn fmt_latex(&self, f: &mut Formatter<'_>) -> Result
fn fmt_latex(&self, f: &mut Formatter<'_>) -> Result
Writes an UnsignedVector as a LaTeX math-mode fragment.
The elements, written in decimal, are separated by commas and enclosed in parentheses that
grow to fit their contents, as a vector’s coordinates are written by hand. The 0-dimensional
vector is \left(\right).
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use malachite_base::strings::latex::ToLatex;
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector {
elements: vec![1u32, 2, 3]
}
.to_latex_string(),
"\\left(1, 2, 3\\right)"
);
assert_eq!(
UnsignedVector {
elements: vec![5u8]
}
.to_latex_string(),
"\\left(5\\right)"
);
assert_eq!(
UnsignedVector::<u32> {
elements: Vec::new()
}
.to_latex_string(),
"\\left(\\right)"
);The value column holds each vector as Display writes it.
| value | fragment | renders as |
|---|---|---|
(1, 2, 3) | \left(1, 2, 3\right) | $\left(1, 2, 3\right)$ |
(5) | \left(5\right) | $\left(5\right)$ |
() | \left(\right) | $\left(\right)$ |
Source§impl<T: PrimitiveUnsigned> ToTypst for UnsignedVector<T>
impl<T: PrimitiveUnsigned> ToTypst for UnsignedVector<T>
Source§fn fmt_typst(&self, f: &mut Formatter<'_>) -> Result
fn fmt_typst(&self, f: &mut Formatter<'_>) -> Result
Writes an UnsignedVector as a Typst math-mode fragment.
The elements, written in decimal, are separated by commas and enclosed in parentheses, as a
vector’s coordinates are written by hand; Typst grows the parentheses to fit their contents.
The 0-dimensional vector is ().
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use malachite_base::strings::typst::ToTypst;
use malachite_base::unsigned_vector::UnsignedVector;
assert_eq!(
UnsignedVector {
elements: vec![1u32, 2, 3]
}
.to_typst_string(),
"(1, 2, 3)"
);
assert_eq!(
UnsignedVector {
elements: vec![5u8]
}
.to_typst_string(),
"(5)"
);
assert_eq!(
UnsignedVector::<u32> {
elements: Vec::new()
}
.to_typst_string(),
"()"
);The value column holds each vector as Display writes it.
| value | fragment |
|---|---|
(1, 2, 3) | (1, 2, 3) |
(5) | (5) |
() | () |
Source§impl<T: PrimitiveUnsigned> Vector for UnsignedVector<T>
impl<T: PrimitiveUnsigned> Vector for UnsignedVector<T>
Source§fn from_elements(xs: &[T]) -> Self
fn from_elements(xs: &[T]) -> Self
Converts a slice to an UnsignedVector, cloning the elements.
The vector’s dimension is the length of the slice. Every slice is a valid vector, so this cannot fail; the empty slice gives the 0-dimensional vector.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is xs.len().
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::from_elements(&[1u32, 2]).to_string(),
"(1, 2)"
);
assert_eq!(UnsignedVector::<u32>::from_elements(&[]).to_string(), "()");Source§fn from_owned_elements(xs: Vec<T>) -> Self
fn from_owned_elements(xs: Vec<T>) -> Self
Converts a Vec to an UnsignedVector, taking ownership of it.
The vector’s dimension is the length of the Vec. Every Vec is a valid vector, so
this cannot fail, and nothing is copied or allocated.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::from_owned_elements(vec![1u32, 2]).to_string(),
"(1, 2)"
);
assert_eq!(
UnsignedVector::<u32>::from_owned_elements(Vec::new()).to_string(),
"()"
);Source§fn zero(dimension: u64) -> Self
fn zero(dimension: u64) -> Self
Returns the zero vector of a given dimension: a vector of dimension zeros.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is dimension.
§Panics
Panics if dimension is greater than usize::MAX.
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(UnsignedVector::<u8>::zero(3).to_string(), "(0, 0, 0)");
assert_eq!(UnsignedVector::<u8>::zero(0).to_string(), "()");This is equivalent to _nmod_vec_init from nmod_vec.h, FLINT 3.6.0, followed by
_nmod_vec_zero, since _nmod_vec_init leaves the elements uninitialized.
Source§fn standard_basis_vector(dimension: u64, index: u64) -> Self
fn standard_basis_vector(dimension: u64, index: u64) -> Self
Returns the standard basis vector $e_i$ of a given dimension: the vector whose element at
index is 1 and whose other elements are 0.
Indices start at 0, as they do for Index.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is dimension.
§Panics
Panics if index is greater than or equal to dimension, or if dimension is greater than
usize::MAX.
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u8>::standard_basis_vector(3, 1).to_string(),
"(0, 1, 0)"
);
assert_eq!(
UnsignedVector::<u8>::standard_basis_vector(1, 0).to_string(),
"(1)"
);Source§fn push(&mut self, x: T)
fn push(&mut self, x: T)
Appends an element to the end of an UnsignedVector, increasing its dimension by 1.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). The capacity
grows geometrically, so pushing $n$ elements onto an empty vector takes $O(n)$ time in
total.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let mut v = UnsignedVector::<u8>::from_str("(1, 2)").unwrap();
v.push(3);
assert_eq!(v.to_string(), "(1, 2, 3)");
let mut v = UnsignedVector::<u8>::zero(0);
v.push(5);
assert_eq!(v.to_string(), "(5)");Source§fn set_dimension(&mut self, dimension: u64)
fn set_dimension(&mut self, dimension: u64)
Sets the dimension of an UnsignedVector, removing elements from the end if the new
dimension is smaller, and appending zeros if it is larger.
Reducing the dimension keeps the first dimension coordinates: it is the projection onto
them.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the larger of self.dimension() and
dimension.
§Panics
Panics if dimension is greater than usize::MAX.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let mut v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
v.set_dimension(5);
assert_eq!(v.to_string(), "(1, 2, 3, 0, 0)");
v.set_dimension(2);
assert_eq!(v.to_string(), "(1, 2)");
v.set_dimension(0);
assert_eq!(v.to_string(), "()");Source§fn set_zero(&mut self)
fn set_zero(&mut self)
Sets every element of an UnsignedVector to zero, keeping its dimension.
Afterwards the vector equals zero of the same dimension.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let mut v = UnsignedVector::<u8>::from_str("(1, 2, 3)").unwrap();
v.set_zero();
assert_eq!(v.to_string(), "(0, 0, 0)");
let mut v = UnsignedVector::<u8>::from_str("()").unwrap();
v.set_zero();
assert_eq!(v.to_string(), "()");This is equivalent to _nmod_vec_zero from nmod_vec.h, FLINT 3.6.0.
Source§fn sort(&mut self)
fn sort(&mut self)
Sorts the elements of an UnsignedVector in ascending order, keeping its dimension.
Equal elements are indistinguishable, so the sort does not need to be stable, and an unstable sort is used.
§Worst-case complexity
$T(n) = O(n \log n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(), assuming that
comparing two elements takes constant time; comparing large elements takes time proportional
to their sizes.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let mut v = UnsignedVector::<u8>::from_str("(3, 1, 2, 1)").unwrap();
v.sort();
assert_eq!(v.to_string(), "(1, 1, 2, 3)");Source§fn to_elements(&self) -> Vec<T>
fn to_elements(&self) -> Vec<T>
Returns an UnsignedVector’s elements as a Vec, cloning them.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.to_elements(), [1, 2, 3]);
assert!(
UnsignedVector::<u32>::from_str("()")
.unwrap()
.to_elements()
.is_empty()
);Source§fn into_elements(self) -> Vec<T>
fn into_elements(self) -> Vec<T>
Returns an UnsignedVector’s elements as a Vec, taking ownership of the
UnsignedVector.
Nothing is copied or allocated.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.into_elements(), [1, 2, 3]);
assert!(
UnsignedVector::<u32>::from_str("()")
.unwrap()
.into_elements()
.is_empty()
);Source§fn elements_ref(&self) -> &[T]
fn elements_ref(&self) -> &[T]
Returns a reference to an UnsignedVector’s elements, as a slice.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
let v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.elements_ref(), [1, 2, 3]);
// A slice of the elements can be taken directly.
assert_eq!(&v.elements_ref()[1..], [2, 3]);
assert!(
UnsignedVector::<u32>::from_str("()")
.unwrap()
.elements_ref()
.is_empty()
);Source§fn dimension(&self) -> u64
fn dimension(&self) -> u64
Returns the dimension of an UnsignedVector: the number of its elements.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector {
elements: vec![4u32, 5]
}
.dimension(),
2
);
assert_eq!(
UnsignedVector::<u32> {
elements: Vec::new()
}
.dimension(),
0
);Source§fn pivot(&self) -> Option<T>
fn pivot(&self) -> Option<T>
Returns the pivot of an UnsignedVector: its first nonzero element.
This is the element that leads the vector when it is a row of a matrix in echelon form. It
returns a copy of it, or None if every element is zero, which includes the 0-dimensional
vector.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u32>::from_str("(0, 0, 3, 0, 5)")
.unwrap()
.pivot(),
Some(3)
);
assert_eq!(
UnsignedVector::<u32>::from_str("(0, 0)").unwrap().pivot(),
None
);
assert_eq!(UnsignedVector::<u32>::from_str("()").unwrap().pivot(), None);Source§fn pivot_index(&self) -> Option<u64>
fn pivot_index(&self) -> Option<u64>
Returns the index of the pivot of an UnsignedVector: the position of its first nonzero
element.
Indices start at 0, as they do for Index. Returns None if every
element is zero, which includes the 0-dimensional vector. When it returns Some(i),
pivot is the element at i.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u32>::from_str("(0, 0, 3, 0, 5)")
.unwrap()
.pivot_index(),
Some(2)
);
assert_eq!(
UnsignedVector::<u32>::from_str("(0, 0)")
.unwrap()
.pivot_index(),
None
);
assert_eq!(
UnsignedVector::<u32>::from_str("()").unwrap().pivot_index(),
None
);Source§fn height_index(&self) -> Option<u64>
fn height_index(&self) -> Option<u64>
Returns the index of the largest element of an UnsignedVector: the first one, when
several are tied.
Indices start at 0, as they do for Index. Returns None for the
0-dimensional vector.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 3, 3, 2)")
.unwrap()
.height_index(),
Some(1)
);
assert_eq!(
UnsignedVector::<u8>::from_str("(5, 5)")
.unwrap()
.height_index(),
Some(0)
);
assert_eq!(
UnsignedVector::<u8>::from_str("()").unwrap().height_index(),
None
);Source§fn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Determines whether every element of an UnsignedVector is zero.
The 0-dimensional vector, which has no elements, counts as zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert!(UnsignedVector::<u8>::from_str("(0, 0)").unwrap().is_zero());
assert!(UnsignedVector::<u8>::from_str("()").unwrap().is_zero());
assert!(
!UnsignedVector::<u8>::from_str("(0, 1, 0)")
.unwrap()
.is_zero()
);Source§fn standard_basis_index(&self) -> Option<u64>
fn standard_basis_index(&self) -> Option<u64>
Determines whether an UnsignedVector is a standard basis vector, returning the index of
its 1 if it is.
A standard basis vector has a single element equal to 1 and every other element 0. Returns
None for every other vector, including the zero vectors and the 0-dimensional vector.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.dimension().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u8>::from_str("(0, 1, 0)")
.unwrap()
.standard_basis_index(),
Some(1)
);
assert_eq!(
UnsignedVector::<u8>::from_str("(0, 2, 0)")
.unwrap()
.standard_basis_index(),
None
);
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 0, 1)")
.unwrap()
.standard_basis_index(),
None
);
assert_eq!(
UnsignedVector::<u8>::from_str("(0, 0)")
.unwrap()
.standard_basis_index(),
None
);Source§fn max_bits(&self) -> (u64, bool)
fn max_bits(&self) -> (u64, bool)
Returns the number of significant bits of the height of an UnsignedVector, together with
whether any of its elements is negative.
Since no element is negative, the flag is always false. The bit count is the bit length of
the bitwise or of the elements.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of elements.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u8>::from_str("(1, 5, 2)")
.unwrap()
.max_bits(),
(3, false)
);
assert_eq!(
UnsignedVector::<u8>::from_str("()").unwrap().max_bits(),
(0, false)
);This is equivalent to _nmod_vec_max_bits from nmod_vec/max_bits.c, FLINT 3.6.0, together
with the flag.
Source§fn sum_max_bits(&self) -> (u64, u64)
fn sum_max_bits(&self) -> (u64, u64)
Returns the number of significant bits of the sum of the absolute values of the elements of
an UnsignedVector (its $\ell^1$ norm), together with the number of significant bits of
its height.
The sum may not fit in a T, so the carries out of the top bit are counted; no wider type
is needed.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of elements.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_base::vector::Vector;
assert_eq!(
UnsignedVector::<u8>::from_str("(255, 255)")
.unwrap()
.sum_max_bits(),
(9, 8)
);
assert_eq!(
UnsignedVector::<u8>::from_str("()").unwrap().sum_max_bits(),
(0, 0)
);Source§type ElementOutput<'a> = T
where
Self: 'a
type ElementOutput<'a> = T where Self: 'a
Auto Trait Implementations§
impl<T> Freeze for UnsignedVector<T>
impl<T> RefUnwindSafe for UnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
Vec<T>: RefUnwindSafe,
impl<T> Send for UnsignedVector<T>
impl<T> Sync for UnsignedVector<T>
impl<T> Unpin for UnsignedVector<T>
impl<T> UnsafeUnpin for UnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for UnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
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