Skip to main content

RationalVector

Struct RationalVector 

Source
pub struct RationalVector {
    pub elements: Vec<Rational>,
}
Expand description

A vector whose elements are Rationals.

Its dimension is the number of elements, and the 0-dimensional vector has none. The field is public, since every Vec of Rationals 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.

The elements are held entrywise, each as a Rational of its own. This is the representation FLINT uses for its fmpq_vec and fmpq_mat, rather than the single common denominator of a RationalPolynomial: a vector’s elements are read and written one at a time, and a common denominator would make every element as large as the least common multiple of all their denominators. to_numerators_and_denominator gives the common-denominator form when it is wanted.

A RationalVector is serialized as the list of its elements, each serialized the way a Rational is.

§Examples

use malachite_base::num::basic::traits::{One, Two};
use malachite_base::vector::Vector;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector {
    elements: vec![Rational::ONE, Rational::TWO, Rational::from(3u32)],
};
assert_eq!(v.dimension(), 3);

Fields§

§elements: Vec<Rational>

Implementations§

Source§

impl RationalVector

Source

pub fn from_numerators_and_denominator( numerators: &IntegerVector, denominator: &Natural, ) -> Self

Builds a RationalVector from a vector of Integer numerators and a single Natural denominator, dividing each numerator by it.

Each element is reduced to lowest terms, so the numerators and denominator need not be. This is the inverse of to_numerators_and_denominator.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the numerators plus the dimension times the number of bits of the denominator.

§Panics

Panics if denominator is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer_vector::IntegerVector;
use malachite_nz::natural::Natural;
use malachite_q::rational_vector::RationalVector;

let ns = IntegerVector::from_str("(3, -4, 30)").unwrap();
assert_eq!(
    RationalVector::from_numerators_and_denominator(&ns, &Natural::from(6u32)).to_string(),
    "(1/2, -2/3, 5)"
);
Source§

impl RationalVector

Source

pub fn to_numerators_and_denominator(&self) -> (IntegerVector, Natural)

Clears the denominators of a RationalVector, returning a vector of Integer numerators and a single positive Natural denominator whose quotients are the elements.

The denominator is the least common multiple of the elements’ denominators, the smallest that works, and each numerator is its element times that denominator. Because the elements are in lowest terms, so is the result: no prime divides the denominator and every numerator. The 0-dimensional vector gives the denominator 1. This is FLINT’s _fmpq_vec_get_fmpz_vec_fmpz.

This is the form in which a sequence of vector operations over one denominator can be done in integer arithmetic; from_numerators_and_denominator converts back.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension. The denominator can have nearly $n$ bits, and each numerator is scaled up to it.

§Examples
use core::str::FromStr;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 5)").unwrap();
let (ns, d) = v.to_numerators_and_denominator();
assert_eq!(ns.to_string(), "(3, -4, 30)");
assert_eq!(d, 6);

// The denominator is the least common multiple, not the product.
let v = RationalVector::from_str("(1/4, 1/6)").unwrap();
let (ns, d) = v.to_numerators_and_denominator();
assert_eq!(ns.to_string(), "(3, 2)");
assert_eq!(d, 12);

let v = RationalVector::from_str("()").unwrap();
let (ns, d) = v.to_numerators_and_denominator();
assert_eq!(ns.to_string(), "()");
assert_eq!(d, 1);
Source

pub fn into_numerators_and_denominator(self) -> (IntegerVector, Natural)

Clears the denominators of a RationalVector, taking the vector by value and returning a vector of Integer numerators and a single positive Natural denominator whose quotients are the elements.

This is to_numerators_and_denominator, except that each numerator is scaled in place rather than cloned first, and an element whose denominator is already the common one is moved over unchanged.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 5)").unwrap();
let (ns, d) = v.into_numerators_and_denominator();
assert_eq!(ns.to_string(), "(3, -4, 30)");
assert_eq!(d, 6);

let v = RationalVector::from_str("()").unwrap();
let (ns, d) = v.into_numerators_and_denominator();
assert_eq!(ns.to_string(), "()");
assert_eq!(d, 1);

Trait Implementations§

Source§

impl AbsSquared for RationalVector

Source§

fn abs_squared(self) -> Rational

Computes the squared norm of a RationalVector, the sum of the squares of its elements, taking the vector by value.

This is the dot product of the vector with itself, $|v|^2$. The squared norm of the 0-dimensional vector is 0. The vector is written as integer numerators over a common denominator, as in Dot, so that one integer squared norm and one reduction suffice.

$$ f(v) = |v|^2 = \sum_{i=0}^{n-1} v_i^2, $$

where $n$ is the dimension of $v$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(m) = O(m \log m)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vector, and $m$ is the largest number of significant bits of any element.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3)").unwrap();
assert_eq!(v.abs_squared().to_string(), "25/36");
let v = RationalVector::from_str("()").unwrap();
assert_eq!(v.abs_squared(), 0);
Source§

type Output = Rational

Source§

impl AbsSquared for &RationalVector

Source§

fn abs_squared(self) -> Rational

Computes the squared norm of a RationalVector, the sum of the squares of its elements, taking the vector by reference.

This is the dot product of the vector with itself, $|v|^2$. The squared norm of the 0-dimensional vector is 0. The vector is written as integer numerators over a common denominator, as in Dot, so that one integer squared norm and one reduction suffice.

$$ f(v) = |v|^2 = \sum_{i=0}^{n-1} v_i^2, $$

where $n$ is the dimension of $v$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(m) = O(m \log m)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vector, and $m$ is the largest number of significant bits of any element.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3)").unwrap();
assert_eq!((&v).abs_squared().to_string(), "25/36");
let v = RationalVector::from_str("()").unwrap();
assert_eq!((&v).abs_squared(), 0);
Source§

type Output = Rational

Source§

impl Add for RationalVector

Source§

fn add(self, other: Self) -> Self

Adds two RationalVectors, taking both by value.

The sum is taken element by element, so the result has the same dimension as the summands.

$$ f(v, w) = v + w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((v + w).to_string(), "(5/6, 3, 0)");
Source§

type Output = RationalVector

The resulting type after applying the + operator.
Source§

impl Add<&RationalVector> for RationalVector

Source§

fn add(self, other: &Self) -> Self

Adds two RationalVectors, taking the first by value and the second by reference.

The sum is taken element by element, so the result has the same dimension as the summands.

$$ f(v, w) = v + w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((v + &w).to_string(), "(5/6, 3, 0)");
Source§

type Output = RationalVector

The resulting type after applying the + operator.
Source§

impl Add<&RationalVector> for &RationalVector

Source§

fn add(self, other: &RationalVector) -> RationalVector

Adds two RationalVectors, taking both by reference.

The sum is taken element by element, so the result has the same dimension as the summands.

$$ f(v, w) = v + w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((&v + &w).to_string(), "(5/6, 3, 0)");
Source§

type Output = RationalVector

The resulting type after applying the + operator.
Source§

impl Add<RationalVector> for &RationalVector

Source§

fn add(self, other: RationalVector) -> RationalVector

Adds two RationalVectors, taking the first by reference and the second by value.

The sum is taken element by element, so the result has the same dimension as the summands.

$$ f(v, w) = v + w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((&v + w).to_string(), "(5/6, 3, 0)");
Source§

type Output = RationalVector

The resulting type after applying the + operator.
Source§

impl AddAssign for RationalVector

Source§

fn add_assign(&mut self, other: Self)

Adds a RationalVector to a RationalVector in place, taking the RationalVector on the right-hand side by value.

The sum is taken element by element, so the result has the same dimension as the summands.

$$ f(v, w) = v + w. $$

§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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
v += RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!(v.to_string(), "(5/6, 3, 0)");
Source§

impl AddAssign<&RationalVector> for RationalVector

Source§

fn add_assign(&mut self, other: &Self)

Adds a RationalVector to a RationalVector in place, taking the RationalVector on the right-hand side by reference.

The sum is taken element by element, so the result has the same dimension as the summands.

$$ f(v, w) = v + w. $$

§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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
v += &RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!(v.to_string(), "(5/6, 3, 0)");
Source§

impl<'a, 'b> AddMul<&'a RationalVector, &'b Rational> for RationalVector

Source§

fn add_mul(self, w: &'a Self, c: &'b Rational) -> Self

Adds the product of a RationalVector and a Rational to a RationalVector, taking the first vector by value, the second vector by reference, and the scalar by reference.

See the documentation for the AddMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl<'a> AddMul<&'a RationalVector, Rational> for RationalVector

Source§

fn add_mul(self, w: &'a Self, c: Rational) -> Self

Adds the product of a RationalVector and a Rational to a RationalVector, taking the first vector by value, the second vector by reference, and the scalar by value.

See the documentation for the AddMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl AddMul<&RationalVector, &Rational> for &RationalVector

Source§

fn add_mul(self, w: &RationalVector, c: &Rational) -> RationalVector

Adds the product of a RationalVector and a Rational to a RationalVector, taking all three by reference.

See the documentation for the AddMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl<'b> AddMul<RationalVector, &'b Rational> for RationalVector

Source§

fn add_mul(self, w: Self, c: &'b Rational) -> Self

Adds the product of a RationalVector and a Rational to a RationalVector, taking the first vector by value, the second vector by value, and the scalar by reference.

See the documentation for the AddMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl AddMul<RationalVector, Rational> for RationalVector

Source§

fn add_mul(self, w: Self, c: Rational) -> Self

Adds the product of a RationalVector and a Rational to a RationalVector, taking all three by value.

The operation is taken element by element, so the result has the same dimension as the vectors. This special-cases multiplication by 0, 1, and $-1$.

$$ f(v, w, c) = v + cw = (v_0 + cw_0, v_1 + cw_1, \ldots, v_{n-1} + cw_{n-1}). $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl<'a, 'b> AddMulAssign<&'a RationalVector, &'b Rational> for RationalVector

Source§

fn add_mul_assign(&mut self, w: &'a Self, c: &'b Rational)

Adds the product of a RationalVector and a Rational to a RationalVector in place, taking the vector and the scalar on the right-hand side by reference.

See the documentation for the AddMulAssign implementation that takes both by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl<'a> AddMulAssign<&'a RationalVector, Rational> for RationalVector

Source§

fn add_mul_assign(&mut self, w: &'a Self, c: Rational)

Adds the product of a RationalVector and a Rational to a RationalVector in place, taking the vector on the right-hand side by reference and the scalar by value.

See the documentation for the AddMulAssign implementation that takes both by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl<'b> AddMulAssign<RationalVector, &'b Rational> for RationalVector

Source§

fn add_mul_assign(&mut self, w: Self, c: &'b Rational)

Adds the product of a RationalVector and a Rational to a RationalVector in place, taking the vector on the right-hand side by value and the scalar by reference.

See the documentation for the AddMulAssign implementation that takes both by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl AddMulAssign<RationalVector, Rational> for RationalVector

Source§

fn add_mul_assign(&mut self, w: Self, c: Rational)

Adds the product of a RationalVector and a Rational to a RationalVector in place, taking the vector and the scalar on the right-hand side by value.

The operation is taken element by element. This special-cases multiplication by 0, 1, and $-1$.

$$ v \gets v + cw. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl AddMulShl<&RationalVector, &Rational> for RationalVector

Source§

fn add_mul_shl(self, w: &Self, c: &Rational, bits: u64) -> Self

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, taking the first vector by value, the second by reference, and the scalar by reference.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.add_mul_shl(&w, &Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(49/2, 0, -33)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.add_mul_shl(&w, &Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl AddMulShl<&RationalVector, &Rational> for &RationalVector

Source§

fn add_mul_shl( self, w: &RationalVector, c: &Rational, bits: u64, ) -> RationalVector

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, taking both vectors and the scalar by reference.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    (&v).add_mul_shl(&w, &Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(49/2, 0, -33)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    (&v).add_mul_shl(&w, &Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl AddMulShl<&RationalVector, Rational> for RationalVector

Source§

fn add_mul_shl(self, w: &Self, c: Rational, bits: u64) -> Self

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, taking the first vector by value, the second by reference, and the scalar by value.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.add_mul_shl(&w, Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(49/2, 0, -33)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.add_mul_shl(&w, Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl AddMulShl<RationalVector, &Rational> for RationalVector

Source§

fn add_mul_shl(self, w: Self, c: &Rational, bits: u64) -> Self

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, taking the first vector by value, the second by value, and the scalar by reference.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.add_mul_shl(w, &Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(49/2, 0, -33)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.add_mul_shl(w, &Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl AddMulShl<RationalVector, Rational> for RationalVector

Source§

fn add_mul_shl(self, w: Self, c: Rational, bits: u64) -> Self

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, taking both vectors and the scalar by value.

The operation is taken element by element, so the result has the same dimension as the vectors. This special-cases multiplication by 0, 1, and $-1$, and a shift by 0.

$$ f(v, w, c, k) = v + cw2^k. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.add_mul_shl(w, Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(49/2, 0, -33)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.add_mul_shl(w, Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl AddMulShlAssign<&RationalVector, &Rational> for RationalVector

Source§

fn add_mul_shl_assign(&mut self, w: &Self, c: &Rational, bits: u64)

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, in place, taking the vector and the scalar on the right-hand side by reference.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.add_mul_shl_assign(&w, &Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(49/2, 0, -33)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.add_mul_shl_assign(&w, &Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

impl AddMulShlAssign<&RationalVector, Rational> for RationalVector

Source§

fn add_mul_shl_assign(&mut self, w: &Self, c: Rational, bits: u64)

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, in place, taking the vector on the right-hand side by reference and the scalar by value.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.add_mul_shl_assign(&w, Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(49/2, 0, -33)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.add_mul_shl_assign(&w, Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

impl AddMulShlAssign<RationalVector, &Rational> for RationalVector

Source§

fn add_mul_shl_assign(&mut self, w: Self, c: &Rational, bits: u64)

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, in place, taking the vector on the right-hand side by value and the scalar by reference.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.add_mul_shl_assign(w, &Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(49/2, 0, -33)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.add_mul_shl_assign(w, &Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

impl AddMulShlAssign<RationalVector, Rational> for RationalVector

Source§

fn add_mul_shl_assign(&mut self, w: Self, c: Rational, bits: u64)

Adds a scalar multiple of a RationalVector, shifted left by bits, to a RationalVector, in place, taking the vector and the scalar on the right-hand side by value.

See the documentation for the AddMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::AddMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.add_mul_shl_assign(w, Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(49/2, 0, -33)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.add_mul_shl_assign(w, Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(2722258935367507707706996859454145691641, -147573952589676412936)"
);
Source§

impl CanonicalPrimitivePart for RationalVector

Source§

fn canonical_primitive_part(self) -> IntegerVector

Computes the canonical primitive part of a RationalVector, taking the vector by value.

This is the primitive_part, negated if its first nonzero element is negative, so that the first nonzero element is positive: the canonical primitive part of the numerators that to_numerators_and_denominator gives. A vector and its negation have the same canonical primitive part.

$$ v = \pm \operatorname{cont}(v) \operatorname{cpp}(v). $$

The canonical primitive part of a vector of zeros is a vector of zeros of the same dimension.

Taking the vector by value saves nothing, since the numerators are built afresh either way.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalPrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
assert_eq!(v.canonical_primitive_part().to_string(), "(3, -4, 30)");
Source§

type Output = IntegerVector

Source§

impl CanonicalPrimitivePart for &RationalVector

Source§

fn canonical_primitive_part(self) -> IntegerVector

Computes the canonical primitive part of a RationalVector, taking the vector by reference.

This is the primitive_part, negated if its first nonzero element is negative, so that the first nonzero element is positive: the canonical primitive part of the numerators that to_numerators_and_denominator gives. A vector and its negation have the same canonical primitive part.

$$ v = \pm \operatorname{cont}(v) \operatorname{cpp}(v). $$

The canonical primitive part of a vector of zeros is a vector of zeros of the same dimension.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalPrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
assert_eq!((&v).canonical_primitive_part().to_string(), "(3, -4, 30)");
Source§

type Output = IntegerVector

Source§

impl CanonicalizeSign for RationalVector

Source§

fn canonicalize_sign(self) -> Self

Brings a RationalVector into canonical sign form, taking the vector by value: negates it if its pivot, its first nonzero element, is negative.

A vector and its negation are the same up to multiplication by $\pm 1$, the units of the integers acting on it, and this picks the one whose pivot is positive to represent both. A vector of zeros has no pivot and is left alone.

§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::CanonicalizeSign;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(0, -2/3, 3)").unwrap();
assert_eq!(v.canonicalize_sign().to_string(), "(0, 2/3, -3)");
let v = RationalVector::from_str("(0, 2/3, -3)").unwrap();
assert_eq!(v.canonicalize_sign().to_string(), "(0, 2/3, -3)");
Source§

type Output = RationalVector

Source§

impl CanonicalizeSign for &RationalVector

Source§

fn canonicalize_sign(self) -> RationalVector

Brings a RationalVector into canonical sign form, taking the vector by reference: negates it if its pivot, its first nonzero element, is negative.

See the documentation for the CanonicalizeSign implementation on RationalVector.

§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.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalizeSign;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(0, -2/3, 3)").unwrap();
assert_eq!((&v).canonicalize_sign().to_string(), "(0, 2/3, -3)");
Source§

type Output = RationalVector

Source§

impl CanonicalizeSignAssign for RationalVector

Source§

fn canonicalize_sign_assign(&mut self)

Replaces a RationalVector with its canonical sign form: negates it if its pivot, its first nonzero element, is negative.

See the documentation for the CanonicalizeSign implementation on RationalVector.

§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::CanonicalizeSignAssign;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(0, -2/3, 3)").unwrap();
v.canonicalize_sign_assign();
assert_eq!(v.to_string(), "(0, 2/3, -3)");
Source§

impl Clone for RationalVector

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl Content for RationalVector

Source§

fn content(self) -> Rational

Computes the content of a RationalVector, taking the vector by value.

The content is the unique non-negative rational $c$ such that the vector is $c$ times a vector of coprime integers. It is the GCD of the numerators that to_numerators_and_denominator gives, divided by the denominator, the least common multiple of the elements’ denominators; that fraction is already in lowest terms. The content of a vector of zeros, and of the 0-dimensional vector, is zero.

$$ f(v) = \frac{\gcd(a_0, a_1, \ldots, a_{m-1})}{d}, \quad \text{where} \quad v_i = \frac{a_i}{d} \text{ and } d = \operatorname{lcm}(\operatorname{den}(v_0), \ldots, \operatorname{den}(v_{m-1})). $$

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Content;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
assert_eq!(v.content().to_string(), "1/6");

let v = RationalVector::from_str("(2/3, 4/3)").unwrap();
assert_eq!(v.content().to_string(), "2/3");
Source§

type Output = Rational

Source§

impl Content for &RationalVector

Source§

fn content(self) -> Rational

Computes the content of a RationalVector, taking the vector by reference.

The content is the unique non-negative rational $c$ such that the vector is $c$ times a vector of coprime integers. It is the GCD of the numerators that to_numerators_and_denominator gives, divided by the denominator, the least common multiple of the elements’ denominators; that fraction is already in lowest terms. The content of a vector of zeros, and of the 0-dimensional vector, is zero.

$$ f(v) = \frac{\gcd(a_0, a_1, \ldots, a_{m-1})}{d}, \quad \text{where} \quad v_i = \frac{a_i}{d} \text{ and } d = \operatorname{lcm}(\operatorname{den}(v_0), \ldots, \operatorname{den}(v_{m-1})). $$

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Content;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
assert_eq!((&v).content().to_string(), "1/6");

let v = RationalVector::from_str("(2/3, 4/3)").unwrap();
assert_eq!((&v).content().to_string(), "2/3");
Source§

type Output = Rational

Source§

impl ContentAndCanonicalPrimitivePart for RationalVector

Source§

fn content_and_canonical_primitive_part(self) -> (Rational, IntegerVector)

Computes the content and the canonical primitive part of a RationalVector together, taking the vector by value.

See content and canonical_primitive_part; the numerators are cleared and the content found once rather than twice.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
let (content, primitive_part) = v.content_and_canonical_primitive_part();
assert_eq!(content.to_string(), "1/6");
assert_eq!(primitive_part.to_string(), "(3, -4, 30)");
Source§

type Content = Rational

Source§

type CanonicalPrimitivePart = IntegerVector

Source§

impl ContentAndCanonicalPrimitivePart for &RationalVector

Source§

fn content_and_canonical_primitive_part(self) -> (Rational, IntegerVector)

Computes the content and the canonical primitive part of a RationalVector together, taking the vector by reference.

See content and canonical_primitive_part; the numerators are cleared and the content found once rather than twice.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndCanonicalPrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
let (content, primitive_part) = (&v).content_and_canonical_primitive_part();
assert_eq!(content.to_string(), "1/6");
assert_eq!(primitive_part.to_string(), "(3, -4, 30)");
Source§

type Content = Rational

Source§

type CanonicalPrimitivePart = IntegerVector

Source§

impl ContentAndPrimitivePart for RationalVector

Source§

fn content_and_primitive_part(self) -> (Rational, IntegerVector)

Computes the content and the primitive part of a RationalVector together, taking the vector by value.

See content and primitive_part; the numerators are cleared and the content found once rather than twice.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndPrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
let (content, primitive_part) = v.content_and_primitive_part();
assert_eq!(content.to_string(), "1/6");
assert_eq!(primitive_part.to_string(), "(-3, 4, -30)");
Source§

type Content = Rational

Source§

type PrimitivePart = IntegerVector

Source§

impl ContentAndPrimitivePart for &RationalVector

Source§

fn content_and_primitive_part(self) -> (Rational, IntegerVector)

Computes the content and the primitive part of a RationalVector together, taking the vector by reference.

See content and primitive_part; the numerators are cleared and the content found once rather than twice.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentAndPrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
let (content, primitive_part) = (&v).content_and_primitive_part();
assert_eq!(content.to_string(), "1/6");
assert_eq!(primitive_part.to_string(), "(-3, 4, -30)");
Source§

type Content = Rational

Source§

type PrimitivePart = IntegerVector

Source§

impl ContentChained<&Rational> for RationalVector

Source§

fn content_chained(self, x: &Rational) -> Rational

Computes the GCD of x and the elements of a RationalVector, taking the vector by value and x 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of x.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentChained;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -3/4)").unwrap();
assert_eq!(
    v.clone()
        .content_chained(&Rational::from_str("1/6").unwrap())
        .to_string(),
    "1/12"
);
assert_eq!(
    v.content_chained(&Rational::from_str("0").unwrap())
        .to_string(),
    "1/4"
);
let v = RationalVector::from_str("()").unwrap();
assert_eq!(
    v.content_chained(&Rational::from_str("1/3").unwrap())
        .to_string(),
    "1/3"
);
Source§

type Output = Rational

Source§

impl ContentChained<&Rational> for &RationalVector

Source§

fn content_chained(self, x: &Rational) -> Rational

Computes the GCD of x and the elements of a RationalVector, taking the vector by reference and x 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of x.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentChained;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -3/4)").unwrap();
assert_eq!(
    (&v).content_chained(&Rational::from_str("1/6").unwrap())
        .to_string(),
    "1/12"
);
assert_eq!(
    (&v).content_chained(&Rational::from_str("0").unwrap())
        .to_string(),
    "1/4"
);
let v = RationalVector::from_str("()").unwrap();
assert_eq!(
    (&v).content_chained(&Rational::from_str("1/3").unwrap())
        .to_string(),
    "1/3"
);
Source§

type Output = Rational

Source§

impl ContentChained<Rational> for RationalVector

Source§

fn content_chained(self, x: Rational) -> Rational

Computes the GCD of x and the elements of a RationalVector, taking the vector by value and x 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of x.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentChained;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -3/4)").unwrap();
assert_eq!(
    v.clone()
        .content_chained(Rational::from_str("1/6").unwrap())
        .to_string(),
    "1/12"
);
assert_eq!(
    v.content_chained(Rational::from_str("0").unwrap())
        .to_string(),
    "1/4"
);
let v = RationalVector::from_str("()").unwrap();
assert_eq!(
    v.content_chained(Rational::from_str("1/3").unwrap())
        .to_string(),
    "1/3"
);
Source§

type Output = Rational

Source§

impl ContentChained<Rational> for &RationalVector

Source§

fn content_chained(self, x: Rational) -> Rational

Computes the GCD of x and the elements of a RationalVector, taking the vector by reference and x 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of x.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ContentChained;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -3/4)").unwrap();
assert_eq!(
    (&v).content_chained(Rational::from_str("1/6").unwrap())
        .to_string(),
    "1/12"
);
assert_eq!(
    (&v).content_chained(Rational::from_str("0").unwrap())
        .to_string(),
    "1/4"
);
let v = RationalVector::from_str("()").unwrap();
assert_eq!(
    (&v).content_chained(Rational::from_str("1/3").unwrap())
        .to_string(),
    "1/3"
);
Source§

type Output = Rational

Source§

impl ConvertibleFrom<&RationalVector> for IntegerVector

Source§

fn convertible_from(v: &RationalVector) -> bool

Determines whether a RationalVector can be converted to an IntegerVector (when every element is an integer). Takes the RationalVector by reference.

Unlike checking whether TryFrom succeeds, this allocates nothing.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

impl ConvertibleFrom<&RationalVector> for NaturalVector

Source§

fn convertible_from(v: &RationalVector) -> bool

Determines whether a RationalVector can be converted to a NaturalVector (when every element is a nonnegative integer). Takes the RationalVector by reference.

Unlike checking whether TryFrom succeeds, this allocates nothing.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

impl<T: PrimitiveUnsigned + for<'a> ConvertibleFrom<&'a Rational>> ConvertibleFrom<&RationalVector> for UnsignedVector<T>

Source§

fn convertible_from(v: &RationalVector) -> bool

Determines whether a RationalVector can be converted to an UnsignedVector (when every element is representable as a T). Takes the RationalVector by reference.

Unlike checking whether TryFrom succeeds, this allocates nothing.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

impl Debug for RationalVector

Source§

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

Converts a RationalVector to a String.

This is the same as the Display::fmt implementation, so that a collection of RationalVectors is written the same way its elements are displayed.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the elements.

§Examples
use malachite_base::strings::ToDebugString;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let xs = vec![
    RationalVector {
        elements: vec![Rational::from(1u32), Rational::from(2u32)],
    },
    RationalVector {
        elements: Vec::new(),
    },
];
assert_eq!(xs[0].to_debug_string(), "(1, 2)");
assert_eq!(xs.to_debug_string(), "[(1, 2), ()]");
Source§

impl Display for RationalVector

Source§

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

Converts a RationalVector to a String.

The elements are written in order, 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 (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the elements.

§Examples
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector {
    elements: vec![Rational::from(1u32), Rational::from(2u32), Rational::from(3u32)],
};
assert_eq!(v.to_string(), "(1, 2, 3)");
assert_eq!(
    RationalVector {
        elements: vec![Rational::from(5u32)]
    }
    .to_string(),
    "(5)"
);
assert_eq!(
    RationalVector {
        elements: Vec::new()
    }
    .to_string(),
    "()"
);
Source§

impl Div<&Rational> for RationalVector

Source§

fn div(self, c: &Rational) -> Self

Divides every element of a RationalVector by a Rational, taking the vector by value and the scalar by reference.

See the documentation for the Div implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Panics

Panics if c is zero.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((v / &c).to_string(), "(2/3, -8/9, 4)");
Source§

type Output = RationalVector

The resulting type after applying the / operator.
Source§

impl Div<&Rational> for &RationalVector

Source§

fn div(self, c: &Rational) -> RationalVector

Divides every element of a RationalVector by a Rational, taking the vector by reference and the scalar by reference.

See the documentation for the Div implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Panics

Panics if c is zero.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((&v / &c).to_string(), "(2/3, -8/9, 4)");
Source§

type Output = RationalVector

The resulting type after applying the / operator.
Source§

impl Div<Rational> for RationalVector

Source§

fn div(self, c: Rational) -> Self

Divides every element of a RationalVector by a Rational, taking the vector by value and the scalar by value.

The quotient is taken element by element, so the result has the same dimension as the vector.

$$ f(v, c) = \frac{v}{c} = (v_0/c, v_1/c, \ldots, v_{n-1}/c). $$

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Panics

Panics if c is zero.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((v / c).to_string(), "(2/3, -8/9, 4)");
Source§

type Output = RationalVector

The resulting type after applying the / operator.
Source§

impl Div<Rational> for &RationalVector

Source§

fn div(self, c: Rational) -> RationalVector

Divides every element of a RationalVector by a Rational, taking the vector by reference and the scalar by value.

See the documentation for the Div implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Panics

Panics if c is zero.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((&v / c).to_string(), "(2/3, -8/9, 4)");
Source§

type Output = RationalVector

The resulting type after applying the / operator.
Source§

impl DivAssign<&Rational> for RationalVector

Source§

fn div_assign(&mut self, c: &Rational)

Divides every element of a RationalVector by a Rational in place, taking the scalar by reference.

See the documentation for the Div implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Panics

Panics if c is zero.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
v /= &Rational::from_signeds(3, 4);
assert_eq!(v.to_string(), "(2/3, -8/9, 4)");
Source§

impl DivAssign<Rational> for RationalVector

Source§

fn div_assign(&mut self, c: Rational)

Divides every element of a RationalVector by a Rational in place, taking the scalar by value.

See the documentation for the Div implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Panics

Panics if c is zero.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
v /= Rational::from_signeds(3, 4);
assert_eq!(v.to_string(), "(2/3, -8/9, 4)");
Source§

impl Dot for RationalVector

Source§

fn dot(self, other: Self) -> Rational

Computes the dot product of two RationalVectors, taking the first by value and the second by value.

The dot product is the sum of the products of corresponding elements, and is 0 for two 0-dimensional vectors.

$$ f(v, w) = \sum_{i=0}^{n-1} v_iw_i, $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Dot;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3)").unwrap();
let w = RationalVector::from_str("(4/5, 3/2)").unwrap();
assert_eq!(v.clone().dot(w.clone()).to_string(), "-3/5");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .dot(RationalVector::from_str("()").unwrap()),
    0
);

This is equivalent to _fmpq_vec_dot from fmpq_vec/dot.c, FLINT 3.6.0.

Source§

type Output = Rational

Source§

impl Dot<&RationalVector> for RationalVector

Source§

fn dot(self, other: &Self) -> Rational

Computes the dot product of two RationalVectors, taking the first by value and the second by reference.

The dot product is the sum of the products of corresponding elements, and is 0 for two 0-dimensional vectors.

$$ f(v, w) = \sum_{i=0}^{n-1} v_iw_i, $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Dot;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3)").unwrap();
let w = RationalVector::from_str("(4/5, 3/2)").unwrap();
assert_eq!(v.clone().dot(&w).to_string(), "-3/5");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .dot(RationalVector::from_str("()").unwrap()),
    0
);

This is equivalent to _fmpq_vec_dot from fmpq_vec/dot.c, FLINT 3.6.0.

Source§

type Output = Rational

Source§

impl Dot<&RationalVector> for &RationalVector

Source§

fn dot(self, other: &RationalVector) -> Rational

Computes the dot product of two RationalVectors, taking the first by reference and the second by reference.

The dot product is the sum of the products of corresponding elements, and is 0 for two 0-dimensional vectors.

$$ f(v, w) = \sum_{i=0}^{n-1} v_iw_i, $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Dot;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3)").unwrap();
let w = RationalVector::from_str("(4/5, 3/2)").unwrap();
assert_eq!((&v).dot(&w).to_string(), "-3/5");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .dot(RationalVector::from_str("()").unwrap()),
    0
);

This is equivalent to _fmpq_vec_dot from fmpq_vec/dot.c, FLINT 3.6.0.

Source§

type Output = Rational

Source§

impl Dot<RationalVector> for &RationalVector

Source§

fn dot(self, other: RationalVector) -> Rational

Computes the dot product of two RationalVectors, taking the first by reference and the second by value.

The dot product is the sum of the products of corresponding elements, and is 0 for two 0-dimensional vectors.

$$ f(v, w) = \sum_{i=0}^{n-1} v_iw_i, $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Dot;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3)").unwrap();
let w = RationalVector::from_str("(4/5, 3/2)").unwrap();
assert_eq!((&v).dot(w.clone()).to_string(), "-3/5");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .dot(RationalVector::from_str("()").unwrap()),
    0
);

This is equivalent to _fmpq_vec_dot from fmpq_vec/dot.c, FLINT 3.6.0.

Source§

type Output = Rational

Source§

impl DotSign for RationalVector

Source§

fn dot_sign(self, other: Self) -> Ordering

Determines the sign of the dot product of two RationalVectors, taking the first by value and the second by value.

The result is the ordering of the dot product against 0, found with as little arithmetic as possible. For two-dimensional vectors it is Rational::cmp_products_neg on the two pairs of elements. Otherwise the terms are split by sign, and when one side is empty, when there is one term on each side (also compared through cmp_products_neg), or when the sizes of the largest terms on the two sides are far enough apart, no product is formed. Only then are the vectors written as integer numerators over common denominators, whose dot product has the same sign, as in Dot; its sign is found by IntegerVector::dot_sign.

$$ f(v, w) = \operatorname{sgn}\left ( \sum_{i=0}^{n-1} v_iw_i \right ), $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::cmp::Ordering::*;
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DotSign;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, 1/3, 1/6)").unwrap();
let w = RationalVector::from_str("(1, 1, -4)").unwrap();
assert_eq!(v.clone().dot_sign(w.clone()), Greater);
let w = RationalVector::from_str("(1, 1, -5)").unwrap();
assert_eq!(v.clone().dot_sign(w.clone()), Equal);
Source§

impl DotSign<&RationalVector> for RationalVector

Source§

fn dot_sign(self, other: &Self) -> Ordering

Determines the sign of the dot product of two RationalVectors, taking the first by value and the second by reference.

The result is the ordering of the dot product against 0, found with as little arithmetic as possible. For two-dimensional vectors it is Rational::cmp_products_neg on the two pairs of elements. Otherwise the terms are split by sign, and when one side is empty, when there is one term on each side (also compared through cmp_products_neg), or when the sizes of the largest terms on the two sides are far enough apart, no product is formed. Only then are the vectors written as integer numerators over common denominators, whose dot product has the same sign, as in Dot; its sign is found by IntegerVector::dot_sign.

$$ f(v, w) = \operatorname{sgn}\left ( \sum_{i=0}^{n-1} v_iw_i \right ), $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::cmp::Ordering::*;
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DotSign;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, 1/3, 1/6)").unwrap();
let w = RationalVector::from_str("(1, 1, -4)").unwrap();
assert_eq!(v.clone().dot_sign(&w), Greater);
let w = RationalVector::from_str("(1, 1, -5)").unwrap();
assert_eq!(v.clone().dot_sign(&w), Equal);
Source§

impl DotSign<&RationalVector> for &RationalVector

Source§

fn dot_sign(self, other: &RationalVector) -> Ordering

Determines the sign of the dot product of two RationalVectors, taking the first by reference and the second by reference.

The result is the ordering of the dot product against 0, found with as little arithmetic as possible. For two-dimensional vectors it is Rational::cmp_products_neg on the two pairs of elements. Otherwise the terms are split by sign, and when one side is empty, when there is one term on each side (also compared through cmp_products_neg), or when the sizes of the largest terms on the two sides are far enough apart, no product is formed. Only then are the vectors written as integer numerators over common denominators, whose dot product has the same sign, as in Dot; its sign is found by IntegerVector::dot_sign.

$$ f(v, w) = \operatorname{sgn}\left ( \sum_{i=0}^{n-1} v_iw_i \right ), $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::cmp::Ordering::*;
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DotSign;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, 1/3, 1/6)").unwrap();
let w = RationalVector::from_str("(1, 1, -4)").unwrap();
assert_eq!((&v).dot_sign(&w), Greater);
let w = RationalVector::from_str("(1, 1, -5)").unwrap();
assert_eq!((&v).dot_sign(&w), Equal);
Source§

impl DotSign<RationalVector> for &RationalVector

Source§

fn dot_sign(self, other: RationalVector) -> Ordering

Determines the sign of the dot product of two RationalVectors, taking the first by reference and the second by value.

The result is the ordering of the dot product against 0, found with as little arithmetic as possible. For two-dimensional vectors it is Rational::cmp_products_neg on the two pairs of elements. Otherwise the terms are split by sign, and when one side is empty, when there is one term on each side (also compared through cmp_products_neg), or when the sizes of the largest terms on the two sides are far enough apart, no product is formed. Only then are the vectors written as integer numerators over common denominators, whose dot product has the same sign, as in Dot; its sign is found by IntegerVector::dot_sign.

$$ f(v, w) = \operatorname{sgn}\left ( \sum_{i=0}^{n-1} v_iw_i \right ), $$

where $n$ is the dimension of $v$ and $w$.

§Worst-case complexity

$T(n, m) = O(nm \log m \log\log m)$

$M(n, m) = O(nm)$

where $T$ is time, $M$ is additional memory, $n$ is the dimension of the vectors, and $m$ is the largest number of significant bits of the numerators the elements take over each vector’s common denominator.

§Panics

Panics if the vectors have different dimensions.

§Examples
use core::cmp::Ordering::*;
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DotSign;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, 1/3, 1/6)").unwrap();
let w = RationalVector::from_str("(1, 1, -4)").unwrap();
assert_eq!((&v).dot_sign(w.clone()), Greater);
let w = RationalVector::from_str("(1, 1, -5)").unwrap();
assert_eq!((&v).dot_sign(w.clone()), Equal);
Source§

impl ElementProduct for RationalVector

Source§

fn to_element_product(&self) -> Rational

Returns the product of the elements of a RationalVector, taking the vector by reference.

The 0-dimensional vector has no elements, and their product is 1. The elements are multiplied in a balanced tree, so that the operands of each multiplication have similar sizes, and multiplication stops as soon as a zero element is found.

$$ f(v) = \prod_i v_i. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

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::num::arithmetic::traits::ElementProduct;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -2/3)")
        .unwrap()
        .to_element_product()
        .to_string(),
    "-1/3"
);
assert_eq!(
    RationalVector::from_str("()").unwrap().to_element_product(),
    1
);
Source§

fn into_element_product(self) -> Rational

Returns the product of the elements of a RationalVector, taking the vector by value.

The 0-dimensional vector has no elements, and their product is 1. The elements are multiplied in a balanced tree, so that the operands of each multiplication have similar sizes, and multiplication stops as soon as a zero element is found.

$$ f(v) = \prod_i v_i. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

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::num::arithmetic::traits::ElementProduct;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -2/3)")
        .unwrap()
        .into_element_product()
        .to_string(),
    "-1/3"
);
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .into_element_product(),
    1
);
Source§

type Output = Rational

Source§

impl ElementSum for RationalVector

Source§

fn to_element_sum(&self) -> Rational

Returns the sum of the elements of a RationalVector, taking the vector by reference.

The 0-dimensional vector has no elements, and their sum is 0.

$$ f(v) = \sum_i v_i. $$

§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.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ElementSum;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .to_element_sum()
        .to_string(),
    "1/6"
);
assert_eq!(RationalVector::from_str("()").unwrap().to_element_sum(), 0);
Source§

fn into_element_sum(self) -> Rational

Returns the sum of the elements of a RationalVector, taking the vector by value.

The 0-dimensional vector has no elements, and their sum is 0.

$$ f(v) = \sum_i v_i. $$

§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.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ElementSum;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .into_element_sum()
        .to_string(),
    "1/6"
);
assert_eq!(
    RationalVector::from_str("()").unwrap().into_element_sum(),
    0
);
Source§

type Output = Rational

Source§

impl EntrywiseAbs for RationalVector

Source§

fn entrywise_abs(self) -> Self

Replaces every element of a RationalVector by its absolute value, taking the vector by value.

The dimension is unchanged. This is not Abs, which for a vector would be its Euclidean length.

$$ f(v) = (|v_0|, |v_1|, \ldots, |v_{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.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseAbs;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 0, -3)").unwrap();
assert_eq!(v.clone().entrywise_abs().to_string(), "(1/2, 2/3, 0, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseAbs for &RationalVector

Source§

fn entrywise_abs(self) -> RationalVector

Replaces every element of a RationalVector by its absolute value, taking the vector by reference.

See the documentation for the EntrywiseAbs implementation on RationalVector 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 the total number of bits of the elements.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseAbs;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 0, -3)").unwrap();
assert_eq!((&v).entrywise_abs().to_string(), "(1/2, 2/3, 0, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseAbsAssign for RationalVector

Source§

fn entrywise_abs_assign(&mut self)

Replaces every element of a RationalVector by its absolute value, in place.

See the documentation for the EntrywiseAbs implementation on RationalVector 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 the total number of bits of the elements.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::EntrywiseAbsAssign;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2/3, 0, -3)").unwrap();
v.entrywise_abs_assign();
assert_eq!(v.to_string(), "(1/2, 2/3, 0, 3)");
Source§

impl EntrywiseMax for RationalVector

Source§

fn entrywise_max(self, other: Self) -> Self

Takes the entrywise maximum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!(v.entrywise_max(w).to_string(), "(1/2, 2, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMax<&RationalVector> for RationalVector

Source§

fn entrywise_max(self, other: &Self) -> Self

Takes the entrywise maximum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!(v.entrywise_max(&w).to_string(), "(1/2, 2, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMax<&RationalVector> for &RationalVector

Source§

fn entrywise_max(self, other: &RationalVector) -> RationalVector

Takes the entrywise maximum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!((&v).entrywise_max(&w).to_string(), "(1/2, 2, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMax<RationalVector> for &RationalVector

Source§

fn entrywise_max(self, other: RationalVector) -> RationalVector

Takes the entrywise maximum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!((&v).entrywise_max(w).to_string(), "(1/2, 2, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMaxAssign for RationalVector

Source§

fn entrywise_max_assign(&mut self, other: Self)

Replaces a RationalVector by its entrywise maximum with another RationalVector, 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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
v.entrywise_max_assign(w);
assert_eq!(v.to_string(), "(1/2, 2, 3)");
Source§

impl EntrywiseMaxAssign<&RationalVector> for RationalVector

Source§

fn entrywise_max_assign(&mut self, other: &Self)

Replaces a RationalVector by its entrywise maximum with another RationalVector, 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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
v.entrywise_max_assign(&w);
assert_eq!(v.to_string(), "(1/2, 2, 3)");
Source§

impl EntrywiseMin for RationalVector

Source§

fn entrywise_min(self, other: Self) -> Self

Takes the entrywise minimum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!(v.entrywise_min(w).to_string(), "(1/3, -5, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMin<&RationalVector> for RationalVector

Source§

fn entrywise_min(self, other: &Self) -> Self

Takes the entrywise minimum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!(v.entrywise_min(&w).to_string(), "(1/3, -5, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMin<&RationalVector> for &RationalVector

Source§

fn entrywise_min(self, other: &RationalVector) -> RationalVector

Takes the entrywise minimum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!((&v).entrywise_min(&w).to_string(), "(1/3, -5, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMin<RationalVector> for &RationalVector

Source§

fn entrywise_min(self, other: RationalVector) -> RationalVector

Takes the entrywise minimum of two RationalVectors, 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
assert_eq!((&v).entrywise_min(w).to_string(), "(1/3, -5, 3)");
Source§

type Output = RationalVector

Source§

impl EntrywiseMinAssign for RationalVector

Source§

fn entrywise_min_assign(&mut self, other: Self)

Replaces a RationalVector by its entrywise minimum with another RationalVector, 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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
v.entrywise_min_assign(w);
assert_eq!(v.to_string(), "(1/3, -5, 3)");
Source§

impl EntrywiseMinAssign<&RationalVector> for RationalVector

Source§

fn entrywise_min_assign(&mut self, other: &Self)

Replaces a RationalVector by its entrywise minimum with another RationalVector, 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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -5, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 2, 3)").unwrap();
v.entrywise_min_assign(&w);
assert_eq!(v.to_string(), "(1/3, -5, 3)");
Source§

impl Eq for RationalVector

Source§

impl Extend<Rational> for RationalVector

Source§

fn extend<I: IntoIterator<Item = Rational>>(&mut self, xs: I)

Appends the elements produced by an iterator to the end of a RationalVector, 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_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1, 2)").unwrap();
v.extend([-3, 4].map(Rational::from));
assert_eq!(v.to_string(), "(1, 2, -3, 4)");
Source§

fn extend_one(&mut self, item: T)

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

fn extend_reserve(&mut self, additional: usize)

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

impl From<IntegerVector> for RationalVector

Source§

fn from(v: IntegerVector) -> Self

Converts an IntegerVector to a RationalVector.

Every Integer is a Rational, so nothing is lost and nothing can fail. The elements are converted one by one, each with denominator 1, so the dimension is unchanged.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples
use core::str::FromStr;
use malachite_nz::integer_vector::IntegerVector;
use malachite_q::rational_vector::RationalVector;

let v = IntegerVector::from_str("(1, -2, 3)").unwrap();
assert_eq!(RationalVector::from(v).to_string(), "(1, -2, 3)");

assert_eq!(
    RationalVector::from(IntegerVector::from_str("()").unwrap()).to_string(),
    "()"
);
Source§

impl From<NaturalVector> for RationalVector

Source§

fn from(v: NaturalVector) -> Self

Converts a NaturalVector to a RationalVector.

Every Natural is a Rational, so nothing is lost and nothing can fail. The elements are converted one by one, each with denominator 1, so the dimension is unchanged.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples
use core::str::FromStr;
use malachite_nz::natural_vector::NaturalVector;
use malachite_q::rational_vector::RationalVector;

let v = NaturalVector::from_str("(1, 2, 3)").unwrap();
assert_eq!(RationalVector::from(v).to_string(), "(1, 2, 3)");

assert_eq!(
    RationalVector::from(NaturalVector::from_str("()").unwrap()).to_string(),
    "()"
);
Source§

impl<T: PrimitiveUnsigned> From<UnsignedVector<T>> for RationalVector
where Rational: From<T>,

Source§

fn from(v: UnsignedVector<T>) -> Self

Converts an UnsignedVector to a RationalVector.

Every unsigned primitive is a Rational, so nothing is lost and nothing can fail. The elements are converted one by one, each with denominator 1, so the dimension is unchanged.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::UnsignedVector;
use malachite_q::rational_vector::RationalVector;

let v = UnsignedVector::<u64>::from_str("(1, 2, 3)").unwrap();
assert_eq!(RationalVector::from(v).to_string(), "(1, 2, 3)");

assert_eq!(
    RationalVector::from(UnsignedVector::<u8>::from_str("()").unwrap()).to_string(),
    "()"
);
Source§

impl FromIterator<Rational> for RationalVector

Source§

fn from_iter<I: IntoIterator<Item = Rational>>(xs: I) -> Self

Collects an iterator of Rationals into a RationalVector.

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_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v: RationalVector = (1u32..=3).map(|d| Rational::from_unsigneds(1, d)).collect();
assert_eq!(v.to_string(), "(1, 1/2, 1/3)");
let v: RationalVector = core::iter::empty().collect();
assert_eq!(v.to_string(), "()");
Source§

impl FromStr for RationalVector

Source§

fn from_str(s: &str) -> Result<Self, ()>

Converts a string to a RationalVector.

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 Rational::from_str reads one, so it need not be in lowest terms, and may have leading zeros and a single leading '-' or '+'. Any other spacing, such as (1,2) or ( 1, 2 ), is rejected, as is an empty element.

If the string does not represent a RationalVector, an Err is returned.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is s.len().

§Examples
use core::str::FromStr;
use malachite_base::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1, 2, 3)").unwrap().to_string(),
    "(1, 2, 3)"
);
assert_eq!(RationalVector::from_str("(5)").unwrap().to_string(), "(5)");
assert_eq!(RationalVector::from_str("()").unwrap().dimension(), 0);

// An element may be written as `Rational::from_str` accepts it.
assert_eq!(
    RationalVector::from_str("(-1, 2/4, +6/3)")
        .unwrap()
        .to_string(),
    "(-1, 1/2, 2)"
);
assert_eq!(
    RationalVector::from_str("(007, +8)").unwrap().to_string(),
    "(7, 8)"
);

assert!(RationalVector::from_str("").is_err());
assert!(RationalVector::from_str("1, 2").is_err());
assert!(RationalVector::from_str("(1,2)").is_err());
assert!(RationalVector::from_str("( 1, 2 )").is_err());
assert!(RationalVector::from_str("(1, )").is_err());
assert!(RationalVector::from_str("(--1)").is_err());
assert!(RationalVector::from_str("(1/0)").is_err());
Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

impl Hash for RationalVector

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Height for RationalVector

Source§

fn to_height(&self) -> Natural

Returns the height of a RationalVector: the largest of the heights of its elements, taking the vector by reference and cloning.

The 0-dimensional vector has no elements, and its height is 0. Every other vector has height at least 1, since every denominator is at least 1; in particular, a nonzero-dimensional vector of zeros has height 1, the height of $0 = 0/1$.

$$ f(v) = H(v) = \max_i H(v_i), \quad H(p/q) = \max(|p|, q). $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the number of bits of the height.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -3, 1/4)")
        .unwrap()
        .to_height(),
    4
);
assert_eq!(RationalVector::from_str("()").unwrap().to_height(), 0);

This is equivalent to _fmpq_vec_max_height from fmpq_vec/max_height.c, FLINT 3.6.0.

Source§

fn into_height(self) -> Natural

Returns the height of a RationalVector: the largest of the heights of its elements, taking the vector by value.

The element of largest height, or the part of it that is the height, is moved out of the vector rather than cloned.

§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’ numerators and denominators.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -3, 1/4)")
        .unwrap()
        .into_height(),
    4
);
assert_eq!(RationalVector::from_str("()").unwrap().into_height(), 0);
Source§

fn height_significant_bits(&self) -> u64

Returns the number of significant bits of the height of a RationalVector.

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 total number of bits of the elements’ numerators and denominators.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -3, 1/4)")
        .unwrap()
        .height_significant_bits(),
    3
);
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .height_significant_bits(),
    0
);

This is equivalent to _fmpq_vec_max_height_bits from fmpq_vec/max_height_bits.c, FLINT 3.6.0.

Source§

type Output = Natural

Source§

impl HeightRef for RationalVector

Source§

fn height_ref(&self) -> &Natural

Returns a reference to the height of a RationalVector: the largest of the heights of its elements.

The height is one of the magnitudes the vector already holds, so it is lent rather than built. For the 0-dimensional vector, a reference to 0 is returned.

§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’ numerators and denominators.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::HeightRef;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    *RationalVector::from_str("(1/2, -3, 1/4)")
        .unwrap()
        .height_ref(),
    4
);
assert_eq!(*RationalVector::from_str("()").unwrap().height_ref(), 0);
Source§

impl Index<usize> for RationalVector

Source§

fn index(&self, i: usize) -> &Rational

Gets a reference to the element of a RationalVector 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1, 2, 3)").unwrap();
assert_eq!(v[0], 1);
assert_eq!(v[2], 3);
Source§

type Output = Rational

The returned type after indexing.
Source§

impl IndexMut<usize> for RationalVector

Source§

fn index_mut(&mut self, i: usize) -> &mut Rational

Gets a mutable reference to the element of a RationalVector 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_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1, 2, 3)").unwrap();
v[1] = Rational::from(10u32);
v[2] += Rational::from(4u32);
assert_eq!(v.to_string(), "(1, 10, 7)");
Source§

impl IntoIterator for RationalVector

Source§

fn into_iter(self) -> IntoIter<Rational> ⓘ

Converts a RationalVector 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
assert_eq!(
    v.into_iter().map(|x| x.to_string()).collect::<Vec<_>>(),
    ["1/2", "-2", "3"]
);
Source§

type Item = Rational

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Rational>

Which kind of iterator are we turning this into?
Source§

impl<'a> IntoIterator for &'a RationalVector

Source§

fn into_iter(self) -> Iter<'a, Rational> ⓘ

Converts a reference to a RationalVector 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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let mut strings = Vec::new();
for x in &v {
    strings.push(x.to_string());
}
assert_eq!(strings, ["1/2", "-2", "3"]);
Source§

type Item = &'a Rational

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Rational>

Which kind of iterator are we turning this into?
Source§

impl<'a> IntoIterator for &'a mut RationalVector

Source§

fn into_iter(self) -> IterMut<'a, Rational> ⓘ

Converts a mutable reference to a RationalVector 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::num::basic::traits::One;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
for x in &mut v {
    *x += Rational::ONE;
}
assert_eq!(v.to_string(), "(3/2, -1, 4)");
Source§

type Item = &'a mut Rational

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Rational>

Which kind of iterator are we turning this into?
Source§

impl L1Norm for RationalVector

Source§

fn to_l1_norm(&self) -> Rational

Returns the $\ell^1$ norm of a RationalVector: the sum of the absolute values of its elements, taking the vector by reference.

The 0-dimensional vector has no elements, and its norm is 0.

$$ f(v) = |v|_1 = \sum_i |v_i|. $$

§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.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::L1Norm;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .to_l1_norm()
        .to_string(),
    "5/6"
);
assert_eq!(RationalVector::from_str("()").unwrap().to_l1_norm(), 0);
Source§

fn into_l1_norm(self) -> Rational

Returns the $\ell^1$ norm of a RationalVector: the sum of the absolute values of its elements, taking the vector by value.

§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.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::L1Norm;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .into_l1_norm()
        .to_string(),
    "5/6"
);
assert_eq!(RationalVector::from_str("()").unwrap().into_l1_norm(), 0);
Source§

fn l1_norm_significant_bits(&self) -> u64

Returns the number of significant bits of the $\ell^1$ norm of a RationalVector.

As for a single Rational, the count is the sum of the numbers of significant bits of the norm’s numerator and denominator. So a norm of 0, which is $0/1$, has 1 significant bit, even for 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 the total number of bits of the elements.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::L1Norm;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .l1_norm_significant_bits(),
    6
);
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .l1_norm_significant_bits(),
    1
);
Source§

type Output = Rational

Source§

impl Mul<&Rational> for RationalVector

Source§

fn mul(self, c: &Rational) -> Self

Multiplies every element of a RationalVector by a Rational, taking the vector by value and the scalar by reference.

See the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((v * &c).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<&Rational> for &RationalVector

Source§

fn mul(self, c: &Rational) -> RationalVector

Multiplies every element of a RationalVector by a Rational, taking the vector by reference and the scalar by reference.

See the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((&v * &c).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<&RationalVector> for Rational

Source§

fn mul(self, v: &RationalVector) -> RationalVector

Multiplies a Rational by every element of a RationalVector, taking the scalar by value and the vector by reference.

Scalar multiplication is commutative, so this is v * c; see the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((c * &v).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<&RationalVector> for &Rational

Source§

fn mul(self, v: &RationalVector) -> RationalVector

Multiplies a Rational by every element of a RationalVector, taking the scalar by reference and the vector by reference.

Scalar multiplication is commutative, so this is v * c; see the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((&c * &v).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<Rational> for RationalVector

Source§

fn mul(self, c: Rational) -> Self

Multiplies every element of a RationalVector by a Rational, taking the vector by value and the scalar by value.

The product is taken element by element, so the result has the same dimension as the vector.

$$ f(v, c) = cv = (cv_0, cv_1, \ldots, cv_{n-1}). $$

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((v * c).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<Rational> for &RationalVector

Source§

fn mul(self, c: Rational) -> RationalVector

Multiplies every element of a RationalVector by a Rational, taking the vector by reference and the scalar by value.

See the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((&v * c).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<RationalVector> for Rational

Source§

fn mul(self, v: RationalVector) -> RationalVector

Multiplies a Rational by every element of a RationalVector, taking the scalar by value and the vector by value.

Scalar multiplication is commutative, so this is v * c; see the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((c * v).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl Mul<RationalVector> for &Rational

Source§

fn mul(self, v: RationalVector) -> RationalVector

Multiplies a Rational by every element of a RationalVector, taking the scalar by reference and the vector by value.

Scalar multiplication is commutative, so this is v * c; see the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
let c = Rational::from_signeds(3, 4);
assert_eq!((&c * v).to_string(), "(3/8, -1/2, 9/4)");
Source§

type Output = RationalVector

The resulting type after applying the * operator.
Source§

impl MulAssign<&Rational> for RationalVector

Source§

fn mul_assign(&mut self, c: &Rational)

Multiplies every element of a RationalVector by a Rational in place, taking the scalar by reference.

See the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
v *= &Rational::from_signeds(3, 4);
assert_eq!(v.to_string(), "(3/8, -1/2, 9/4)");
Source§

impl MulAssign<Rational> for RationalVector

Source§

fn mul_assign(&mut self, c: Rational)

Multiplies every element of a RationalVector by a Rational in place, taking the scalar by value.

See the documentation for the Mul implementation that takes the vector and the scalar by value for details.

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements and of the scalar.

§Examples
use core::str::FromStr;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2/3, 3)").unwrap();
v *= Rational::from_signeds(3, 4);
assert_eq!(v.to_string(), "(3/8, -1/2, 9/4)");
Source§

impl Named for RationalVector

Source§

const NAME: &'static str = "RationalVector"

The name of this type, as given by the stringify macro.

See the documentation for impl_named for more details.

Source§

impl Neg for RationalVector

Source§

fn neg(self) -> Self

Negates a RationalVector, taking it by value.

Every element is negated, so the dimension is unchanged.

$$ f(v) = -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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -3, 2/3)").unwrap();
assert_eq!((-v).to_string(), "(-1/2, 3, -2/3)");
assert_eq!((-RationalVector::from_str("()").unwrap()).to_string(), "()");
Source§

type Output = RationalVector

The resulting type after applying the - operator.
Source§

impl Neg for &RationalVector

Source§

fn neg(self) -> RationalVector

Negates a RationalVector, taking it by reference.

Every element is negated, so the dimension is unchanged.

$$ f(v) = -v. $$

§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’ numerators and denominators.

§Examples
use core::str::FromStr;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -3, 2/3)").unwrap();
assert_eq!((-&v).to_string(), "(-1/2, 3, -2/3)");
Source§

type Output = RationalVector

The resulting type after applying the - operator.
Source§

impl NegAssign for RationalVector

Source§

fn neg_assign(&mut self)

Negates a RationalVector in place.

$$ v \gets -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::NegAssign;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -3, 2/3)").unwrap();
v.neg_assign();
assert_eq!(v.to_string(), "(-1/2, 3, -2/3)");
Source§

impl PartialEq for RationalVector

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerVector> for RationalVector

Source§

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

Determines whether a RationalVector is equal to an IntegerVector.

The two are equal when they have the same dimension and equal elements in each position. So the 0-dimensional vectors are equal, and a RationalVector with an element that is not an integer is equal to no IntegerVector.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). Vectors of different dimensions are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<NaturalVector> for RationalVector

Source§

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

Determines whether a RationalVector is equal to a NaturalVector.

The two are equal when they have the same dimension and equal elements in each position. So the 0-dimensional vectors are equal, and a RationalVector with an element that is negative or not an integer is equal to no NaturalVector.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). Vectors of different dimensions are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<RationalVector> for IntegerVector

Source§

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

Determines whether an IntegerVector is equal to a RationalVector.

The two are equal when they have the same dimension and equal elements in each position, so the 0-dimensional vectors are equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). Vectors of different dimensions are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<RationalVector> for NaturalVector

Source§

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

Determines whether a NaturalVector is equal to a RationalVector.

The two are equal when they have the same dimension and equal elements in each position, so the 0-dimensional vectors are equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). Vectors of different dimensions are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PrimitiveUnsigned> PartialEq<RationalVector> for UnsignedVector<T>
where Rational: PartialEq<T>,

Source§

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

Determines whether an UnsignedVector is equal to a RationalVector.

The two are equal when they have the same dimension and equal elements in each position, so the 0-dimensional vectors are equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). Vectors of different dimensions are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PrimitiveUnsigned> PartialEq<UnsignedVector<T>> for RationalVector
where Rational: PartialEq<T>,

Source§

fn eq(&self, other: &UnsignedVector<T>) -> bool

Determines whether a RationalVector is equal to an UnsignedVector.

The two are equal when they have the same dimension and equal elements in each position. So the 0-dimensional vectors are equal, and a RationalVector with an element that is negative, not an integer, or too large for T is equal to no UnsignedVector<T>.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.dimension(). Vectors of different dimensions are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PrimitivePart for RationalVector

Source§

fn primitive_part(self) -> IntegerVector

Computes the primitive part of a RationalVector, taking the vector by value.

This is the vector divided by its content, with every element keeping its sign. Its elements are coprime integers, so it is an IntegerVector: the primitive part of the numerators that to_numerators_and_denominator gives, the denominator playing no part. For the one whose first nonzero element is positive, see canonical_primitive_part.

$$ v = \operatorname{cont}(v) \operatorname{pp}(v). $$

The primitive part of a vector of zeros is a vector of zeros of the same dimension.

Taking the vector by value saves nothing, since the numerators are built afresh either way.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::PrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
assert_eq!(v.primitive_part().to_string(), "(-3, 4, -30)");
Source§

type Output = IntegerVector

Source§

impl PrimitivePart for &RationalVector

Source§

fn primitive_part(self) -> IntegerVector

Computes the primitive part of a RationalVector, taking the vector by reference.

This is the vector divided by its content, with every element keeping its sign. Its elements are coprime integers, so it is an IntegerVector: the primitive part of the numerators that to_numerators_and_denominator gives, the denominator playing no part. For the one whose first nonzero element is positive, see canonical_primitive_part.

$$ v = \operatorname{cont}(v) \operatorname{pp}(v). $$

The primitive part of a vector of zeros is a vector of zeros of the same dimension.

§Worst-case complexity

$T(n, m) = O(mn (\log n)^2 \log\log n)$

$M(n, m) = O(mn)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements’ numerators and denominators, and $m$ is the dimension.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::PrimitivePart;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(-1/2, 2/3, -5)").unwrap();
assert_eq!((&v).primitive_part().to_string(), "(-3, 4, -30)");
Source§

type Output = IntegerVector

Source§

impl SelectCoordinates for RationalVector

Source§

fn select_coordinates(self, indices: &[u64]) -> Self

Selects coordinates of a RationalVector 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(), plus the total size of the elements that are cloned.

§Panics

Panics if any index is greater than or equal to self.dimension().

§Examples
use core::str::FromStr;
use malachite_base::vector::SelectCoordinates;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
assert_eq!(
    v.clone().select_coordinates(&[2, 0]).to_string(),
    "(3, 1/2)"
);
assert_eq!(
    v.clone().select_coordinates(&[1, 1, 1]).to_string(),
    "(-2, -2, -2)"
);
assert_eq!(v.select_coordinates(&[0, 2]).to_string(), "(1/2, 3)");
Source§

type Output = RationalVector

Source§

impl SelectCoordinates for &RationalVector

Source§

fn select_coordinates(self, indices: &[u64]) -> RationalVector

Selects coordinates of a RationalVector 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() plus the total size of the selected elements.

§Panics

Panics if any index is greater than or equal to self.dimension().

§Examples
use core::str::FromStr;
use malachite_base::vector::SelectCoordinates;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
assert_eq!((&v).select_coordinates(&[2, 0]).to_string(), "(3, 1/2)");
assert_eq!(
    (&v).select_coordinates(&[1, 1, 1]).to_string(),
    "(-2, -2, -2)"
);
assert_eq!((&v).select_coordinates(&[]).to_string(), "()");
Source§

type Output = RationalVector

Source§

impl SelectCoordinatesAssign for RationalVector

Source§

fn select_coordinates_assign(&mut self, indices: &[u64])

Selects coordinates of a RationalVector 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(), plus the total size of the elements that are cloned.

§Panics

Panics if any index is greater than or equal to self.dimension().

§Examples
use core::str::FromStr;
use malachite_base::vector::SelectCoordinatesAssign;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
v.select_coordinates_assign(&[2, 0]);
assert_eq!(v.to_string(), "(3, 1/2)");
v.select_coordinates_assign(&[1, 1]);
assert_eq!(v.to_string(), "(1/2, 1/2)");
Source§

impl Shl<i8> for RationalVector

Source§

fn shl(self, bits: i8) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i8> for &RationalVector

Source§

fn shl(self, bits: i8) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i16> for RationalVector

Source§

fn shl(self, bits: i16) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i16> for &RationalVector

Source§

fn shl(self, bits: i16) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i32> for RationalVector

Source§

fn shl(self, bits: i32) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i32> for &RationalVector

Source§

fn shl(self, bits: i32) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i64> for RationalVector

Source§

fn shl(self, bits: i64) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i64> for &RationalVector

Source§

fn shl(self, bits: i64) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i128> for RationalVector

Source§

fn shl(self, bits: i128) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<i128> for &RationalVector

Source§

fn shl(self, bits: i128) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<isize> for RationalVector

Source§

fn shl(self, bits: isize) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<isize> for &RationalVector

Source§

fn shl(self, bits: isize) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u8> for RationalVector

Source§

fn shl(self, bits: u8) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u8> for &RationalVector

Source§

fn shl(self, bits: u8) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u16> for RationalVector

Source§

fn shl(self, bits: u16) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u16> for &RationalVector

Source§

fn shl(self, bits: u16) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u32> for RationalVector

Source§

fn shl(self, bits: u32) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u32> for &RationalVector

Source§

fn shl(self, bits: u32) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u64> for RationalVector

Source§

fn shl(self, bits: u64) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u64> for &RationalVector

Source§

fn shl(self, bits: u64) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u128> for RationalVector

Source§

fn shl(self, bits: u128) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<u128> for &RationalVector

Source§

fn shl(self, bits: u128) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<usize> for RationalVector

Source§

fn shl(self, bits: usize) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl Shl<usize> for &RationalVector

Source§

fn shl(self, bits: usize) -> RationalVector

Left-shifts a RationalVector (multiplies it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the << operator.
Source§

impl ShlAssign<i8> for RationalVector

Source§

fn shl_assign(&mut self, bits: i8)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<i16> for RationalVector

Source§

fn shl_assign(&mut self, bits: i16)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<i32> for RationalVector

Source§

fn shl_assign(&mut self, bits: i32)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<i64> for RationalVector

Source§

fn shl_assign(&mut self, bits: i64)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<i128> for RationalVector

Source§

fn shl_assign(&mut self, bits: i128)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<isize> for RationalVector

Source§

fn shl_assign(&mut self, bits: isize)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

A negative bits shifts right, dividing every element by $2^{-k}$; each element stays in lowest terms.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<u8> for RationalVector

Source§

fn shl_assign(&mut self, bits: u8)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<u16> for RationalVector

Source§

fn shl_assign(&mut self, bits: u16)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<u32> for RationalVector

Source§

fn shl_assign(&mut self, bits: u32)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<u64> for RationalVector

Source§

fn shl_assign(&mut self, bits: u64)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<u128> for RationalVector

Source§

fn shl_assign(&mut self, bits: u128)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShlAssign<usize> for RationalVector

Source§

fn shl_assign(&mut self, bits: usize)

Left-shifts a RationalVector (multiplies it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets 2^kv$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl Shr<i8> for RationalVector

Source§

fn shr(self, bits: i8) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i8> for &RationalVector

Source§

fn shr(self, bits: i8) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i16> for RationalVector

Source§

fn shr(self, bits: i16) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i16> for &RationalVector

Source§

fn shr(self, bits: i16) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i32> for RationalVector

Source§

fn shr(self, bits: i32) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i32> for &RationalVector

Source§

fn shr(self, bits: i32) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i64> for RationalVector

Source§

fn shr(self, bits: i64) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i64> for &RationalVector

Source§

fn shr(self, bits: i64) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i128> for RationalVector

Source§

fn shr(self, bits: i128) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<i128> for &RationalVector

Source§

fn shr(self, bits: i128) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<isize> for RationalVector

Source§

fn shr(self, bits: isize) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<isize> for &RationalVector

Source§

fn shr(self, bits: isize) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u8> for RationalVector

Source§

fn shr(self, bits: u8) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u8> for &RationalVector

Source§

fn shr(self, bits: u8) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u16> for RationalVector

Source§

fn shr(self, bits: u16) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u16> for &RationalVector

Source§

fn shr(self, bits: u16) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u32> for RationalVector

Source§

fn shr(self, bits: u32) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u32> for &RationalVector

Source§

fn shr(self, bits: u32) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u64> for RationalVector

Source§

fn shr(self, bits: u64) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u64> for &RationalVector

Source§

fn shr(self, bits: u64) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u128> for RationalVector

Source§

fn shr(self, bits: u128) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<u128> for &RationalVector

Source§

fn shr(self, bits: u128) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<usize> for RationalVector

Source§

fn shr(self, bits: usize) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by value. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl Shr<usize> for &RationalVector

Source§

fn shr(self, bits: usize) -> RationalVector

Right-shifts a RationalVector (divides it by a power of 2), taking it by reference. Every element is shifted, and the dimension is unchanged.

$f(v, k) = v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

type Output = RationalVector

The resulting type after applying the >> operator.
Source§

impl ShrAssign<i8> for RationalVector

Source§

fn shr_assign(&mut self, bits: i8)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<i16> for RationalVector

Source§

fn shr_assign(&mut self, bits: i16)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<i32> for RationalVector

Source§

fn shr_assign(&mut self, bits: i32)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<i64> for RationalVector

Source§

fn shr_assign(&mut self, bits: i64)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<i128> for RationalVector

Source§

fn shr_assign(&mut self, bits: i128)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<isize> for RationalVector

Source§

fn shr_assign(&mut self, bits: isize)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

A negative bits shifts left, multiplying every element by $2^{-k}$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits.unsigned_abs(), and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<u8> for RationalVector

Source§

fn shr_assign(&mut self, bits: u8)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<u16> for RationalVector

Source§

fn shr_assign(&mut self, bits: u16)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<u32> for RationalVector

Source§

fn shr_assign(&mut self, bits: u32)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<u64> for RationalVector

Source§

fn shr_assign(&mut self, bits: u64)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<u128> for RationalVector

Source§

fn shr_assign(&mut self, bits: u128)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl ShrAssign<usize> for RationalVector

Source§

fn shr_assign(&mut self, bits: usize)

Right-shifts a RationalVector (divides it by a power of 2), in place. Every element is shifted, and the dimension is unchanged.

$v \gets v/2^k$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the elements, $m$ is bits, and $k$ is self.dimension().

§Examples

See here.

Source§

impl SignificantBits for &RationalVector

Source§

fn significant_bits(self) -> u64

Returns the sum of the numbers of significant bits of the elements of a RationalVector, each element’s count being the sum of the bits of its numerator and denominator, as for Rational.

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_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .significant_bits(),
    6
);
assert_eq!(
    RationalVector::from_str("()").unwrap().significant_bits(),
    0
);
Source§

impl StructuralPartialEq for RationalVector

Source§

impl Sub for RationalVector

Source§

fn sub(self, other: Self) -> Self

Subtracts two RationalVectors, taking both by value.

The difference is taken element by element, so the result has the same dimension as the operands.

$$ f(v, w) = v - w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((v - w).to_string(), "(1/6, -7, 6)");
Source§

type Output = RationalVector

The resulting type after applying the - operator.
Source§

impl Sub<&RationalVector> for RationalVector

Source§

fn sub(self, other: &Self) -> Self

Subtracts two RationalVectors, taking the first by value and the second by reference.

The difference is taken element by element, so the result has the same dimension as the operands.

$$ f(v, w) = v - w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((v - &w).to_string(), "(1/6, -7, 6)");
Source§

type Output = RationalVector

The resulting type after applying the - operator.
Source§

impl Sub<&RationalVector> for &RationalVector

Source§

fn sub(self, other: &RationalVector) -> RationalVector

Subtracts two RationalVectors, taking both by reference.

The difference is taken element by element, so the result has the same dimension as the operands.

$$ f(v, w) = v - w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((&v - &w).to_string(), "(1/6, -7, 6)");
Source§

type Output = RationalVector

The resulting type after applying the - operator.
Source§

impl Sub<RationalVector> for &RationalVector

Source§

fn sub(self, other: RationalVector) -> RationalVector

Subtracts two RationalVectors, taking the first by reference and the second by value.

The difference is taken element by element, so the result has the same dimension as the operands.

$$ f(v, w) = v - w. $$

§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_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!((&v - w).to_string(), "(1/6, -7, 6)");
Source§

type Output = RationalVector

The resulting type after applying the - operator.
Source§

impl SubAssign for RationalVector

Source§

fn sub_assign(&mut self, other: Self)

Subtracts a RationalVector from a RationalVector in place, taking the RationalVector on the right-hand side by value.

The difference is taken element by element, so the result has the same dimension as the operands.

$$ f(v, w) = v - w. $$

§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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
v -= RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!(v.to_string(), "(1/6, -7, 6)");
Source§

impl SubAssign<&RationalVector> for RationalVector

Source§

fn sub_assign(&mut self, other: &Self)

Subtracts a RationalVector from a RationalVector in place, taking the RationalVector on the right-hand side by reference.

The difference is taken element by element, so the result has the same dimension as the operands.

$$ f(v, w) = v - w. $$

§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_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
v -= &RationalVector::from_str("(1/3, 5, -3)").unwrap();
assert_eq!(v.to_string(), "(1/6, -7, 6)");
Source§

impl<'a, 'b> SubMul<&'a RationalVector, &'b Rational> for RationalVector

Source§

fn sub_mul(self, w: &'a Self, c: &'b Rational) -> Self

Subtracts the product of a RationalVector and a Rational from a RationalVector, taking the first vector by value, the second vector by reference, and the scalar by reference.

See the documentation for the SubMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl<'a> SubMul<&'a RationalVector, Rational> for RationalVector

Source§

fn sub_mul(self, w: &'a Self, c: Rational) -> Self

Subtracts the product of a RationalVector and a Rational from a RationalVector, taking the first vector by value, the second vector by reference, and the scalar by value.

See the documentation for the SubMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl SubMul<&RationalVector, &Rational> for &RationalVector

Source§

fn sub_mul(self, w: &RationalVector, c: &Rational) -> RationalVector

Subtracts the product of a RationalVector and a Rational from a RationalVector, taking all three by reference.

See the documentation for the SubMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl<'b> SubMul<RationalVector, &'b Rational> for RationalVector

Source§

fn sub_mul(self, w: Self, c: &'b Rational) -> Self

Subtracts the product of a RationalVector and a Rational from a RationalVector, taking the first vector by value, the second vector by value, and the scalar by reference.

See the documentation for the SubMul implementation that takes all three by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl SubMul<RationalVector, Rational> for RationalVector

Source§

fn sub_mul(self, w: Self, c: Rational) -> Self

Subtracts the product of a RationalVector and a Rational from a RationalVector, taking all three by value.

The operation is taken element by element, so the result has the same dimension as the vectors. This special-cases multiplication by 0, 1, and $-1$.

$$ f(v, w, c) = v - cw = (v_0 - cw_0, v_1 - cw_1, \ldots, v_{n-1} - cw_{n-1}). $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

type Output = RationalVector

Source§

impl<'a, 'b> SubMulAssign<&'a RationalVector, &'b Rational> for RationalVector

Source§

fn sub_mul_assign(&mut self, w: &'a Self, c: &'b Rational)

Subtracts the product of a RationalVector and a Rational from a RationalVector in place, taking the vector and the scalar on the right-hand side by reference.

See the documentation for the SubMulAssign implementation that takes both by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl<'a> SubMulAssign<&'a RationalVector, Rational> for RationalVector

Source§

fn sub_mul_assign(&mut self, w: &'a Self, c: Rational)

Subtracts the product of a RationalVector and a Rational from a RationalVector in place, taking the vector on the right-hand side by reference and the scalar by value.

See the documentation for the SubMulAssign implementation that takes both by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl<'b> SubMulAssign<RationalVector, &'b Rational> for RationalVector

Source§

fn sub_mul_assign(&mut self, w: Self, c: &'b Rational)

Subtracts the product of a RationalVector and a Rational from a RationalVector in place, taking the vector on the right-hand side by value and the scalar by reference.

See the documentation for the SubMulAssign implementation that takes both by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl SubMulAssign<RationalVector, Rational> for RationalVector

Source§

fn sub_mul_assign(&mut self, w: Self, c: Rational)

Subtracts the product of a RationalVector and a Rational from a RationalVector in place, taking the vector and the scalar on the right-hand side by value.

The operation is taken element by element. This special-cases multiplication by 0, 1, and $-1$.

$$ v \gets v - cw. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c.

§Panics

Panics if self and w have different dimensions.

§Examples

See here.

Source§

impl SubMulShl<&RationalVector, &Rational> for RationalVector

Source§

fn sub_mul_shl(self, w: &Self, c: &Rational, bits: u64) -> Self

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, taking the first vector by value, the second by reference, and the scalar by reference.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.sub_mul_shl(&w, &Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(-47/2, -4, 39)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.sub_mul_shl(&w, &Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl SubMulShl<&RationalVector, &Rational> for &RationalVector

Source§

fn sub_mul_shl( self, w: &RationalVector, c: &Rational, bits: u64, ) -> RationalVector

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, taking both vectors and the scalar by reference.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    (&v).sub_mul_shl(&w, &Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(-47/2, -4, 39)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    (&v).sub_mul_shl(&w, &Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl SubMulShl<&RationalVector, Rational> for RationalVector

Source§

fn sub_mul_shl(self, w: &Self, c: Rational, bits: u64) -> Self

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, taking the first vector by value, the second by reference, and the scalar by value.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.sub_mul_shl(&w, Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(-47/2, -4, 39)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.sub_mul_shl(&w, Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl SubMulShl<RationalVector, &Rational> for RationalVector

Source§

fn sub_mul_shl(self, w: Self, c: &Rational, bits: u64) -> Self

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, taking the first vector by value, the second by value, and the scalar by reference.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.sub_mul_shl(w, &Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(-47/2, -4, 39)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.sub_mul_shl(w, &Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl SubMulShl<RationalVector, Rational> for RationalVector

Source§

fn sub_mul_shl(self, w: Self, c: Rational, bits: u64) -> Self

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, taking both vectors and the scalar by value.

The operation is taken element by element, so the result has the same dimension as the vectors. This special-cases multiplication by 0, 1, and $-1$, and a shift by 0.

$$ f(v, w, c, k) = v - cw2^k. $$

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShl;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
assert_eq!(
    v.sub_mul_shl(w, Rational::from_signeds(3, 2), 2)
        .to_string(),
    "(-47/2, -4, 39)"
);

let v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
assert_eq!(
    v.sub_mul_shl(w, Rational::from_str("18446744073709551617").unwrap(), 3)
        .to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

type Output = RationalVector

Source§

impl SubMulShlAssign<&RationalVector, &Rational> for RationalVector

Source§

fn sub_mul_shl_assign(&mut self, w: &Self, c: &Rational, bits: u64)

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, in place, taking the vector and the scalar on the right-hand side by reference.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.sub_mul_shl_assign(&w, &Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(-47/2, -4, 39)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.sub_mul_shl_assign(&w, &Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

impl SubMulShlAssign<&RationalVector, Rational> for RationalVector

Source§

fn sub_mul_shl_assign(&mut self, w: &Self, c: Rational, bits: u64)

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, in place, taking the vector on the right-hand side by reference and the scalar by value.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.sub_mul_shl_assign(&w, Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(-47/2, -4, 39)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.sub_mul_shl_assign(&w, Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

impl SubMulShlAssign<RationalVector, &Rational> for RationalVector

Source§

fn sub_mul_shl_assign(&mut self, w: Self, c: &Rational, bits: u64)

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, in place, taking the vector on the right-hand side by value and the scalar by reference.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.sub_mul_shl_assign(w, &Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(-47/2, -4, 39)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.sub_mul_shl_assign(w, &Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

impl SubMulShlAssign<RationalVector, Rational> for RationalVector

Source§

fn sub_mul_shl_assign(&mut self, w: Self, c: Rational, bits: u64)

Subtracts a scalar multiple of a RationalVector, shifted left by bits, from a RationalVector, in place, taking the vector and the scalar on the right-hand side by value.

See the documentation for the SubMulShl implementation that takes everything by value for details.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of both vectors and of c, plus bits times self.dimension().

§Panics

Panics if self and w have different dimensions.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SubMulShlAssign;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
let w = RationalVector::from_str("(4, 1/3, -6)").unwrap();
v.sub_mul_shl_assign(w, Rational::from_signeds(3, 2), 2);
assert_eq!(v.to_string(), "(-47/2, -4, 39)");

let mut v = RationalVector::from_str("(1, 0)").unwrap();
let w = RationalVector::from_str("(18446744073709551615, -1)").unwrap();
v.sub_mul_shl_assign(w, Rational::from_str("18446744073709551617").unwrap(), 3);
assert_eq!(
    v.to_string(),
    "(-2722258935367507707706996859454145691639, 147573952589676412936)"
);
Source§

impl Sum for RationalVector

Source§

fn sum<I>(xs: I) -> Self
where I: Iterator<Item = Self>,

Adds up all the RationalVectors in an iterator, entry by entry.

The vectors must all have the same dimension, which is also the dimension of the sum. Since the dimension of the zero vector cannot be inferred from an empty iterator, an empty iterator panics rather than summing to zero.

$$ f((v_i)_ {i=0}^{n-1}) = \sum_ {i=0}^{n-1} v_i. $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of all the vectors.

§Panics

Panics if the iterator is empty or if the vectors do not all have the same dimension.

§Examples
use core::iter::Sum;
use core::str::FromStr;
use malachite_q::rational_vector::RationalVector;

let vs = ["(1/2, -2, 3)", "(1/3, 5, -1/6)", "(1/6, 0, 1/2)"]
    .map(|s| RationalVector::from_str(s).unwrap());
assert_eq!(
    RationalVector::sum(vs.into_iter()).to_string(),
    "(1, 3, 10/3)"
);

let vs = ["(18446744073709551615/2, -1/3)", "(1/2, 1/3)"]
    .map(|s| RationalVector::from_str(s).unwrap());
assert_eq!(
    RationalVector::sum(vs.into_iter()).to_string(),
    "(9223372036854775808, 0)"
);
Source§

impl<'a> Sum<&'a RationalVector> for RationalVector

Source§

fn sum<I>(xs: I) -> Self
where I: Iterator<Item = &'a Self>,

Adds up all the RationalVectors in an iterator of references, entry by entry.

The vectors must all have the same dimension, which is also the dimension of the sum. Since the dimension of the zero vector cannot be inferred from an empty iterator, an empty iterator panics rather than summing to zero.

$$ f((v_i)_ {i=0}^{n-1}) = \sum_ {i=0}^{n-1} v_i. $$

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the elements of all the vectors.

§Panics

Panics if the iterator is empty or if the vectors do not all have the same dimension.

§Examples
use core::iter::Sum;
use core::str::FromStr;
use malachite_q::rational_vector::RationalVector;

let vs = ["(1/2, -2, 3)", "(1/3, 5, -1/6)", "(1/6, 0, 1/2)"]
    .map(|s| RationalVector::from_str(s).unwrap());
assert_eq!(RationalVector::sum(vs.iter()).to_string(), "(1, 3, 10/3)");

let vs = ["(18446744073709551615/2, -1/3)", "(1/2, 1/3)"]
    .map(|s| RationalVector::from_str(s).unwrap());
assert_eq!(
    RationalVector::sum(vs.iter()).to_string(),
    "(9223372036854775808, 0)"
);
Source§

impl ToLatex for RationalVector

Source§

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

Writes a RationalVector as a LaTeX math-mode fragment.

The elements’ fragments 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 (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the elements.

§Examples
use core::str::FromStr;
use malachite_base::strings::latex::ToLatex;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector {
    elements: vec![Rational::from(1u32), Rational::from(2u32), Rational::from(3u32)],
};
assert_eq!(v.to_latex_string(), "\\left(1, 2, 3\\right)");
assert_eq!(
    RationalVector::from_str("(1/2)").unwrap().to_latex_string(),
    "\\left(\\frac{1}{2}\\right)"
);
assert_eq!(
    RationalVector {
        elements: vec![Rational::from(5u32)]
    }
    .to_latex_string(),
    "\\left(5\\right)"
);
assert_eq!(
    RationalVector {
        elements: Vec::new()
    }
    .to_latex_string(),
    "\\left(\\right)"
);

The value column holds each vector as Display writes it.

valuefragmentrenders as
(1/2)\left(\frac{1}{2}\right)$\left(\frac{1}{2}\right)$
(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§

fn to_latex(&self) -> LatexWrapper<'_, Self>
where Self: Sized,

Converts a value to a LaTeX math-mode fragment. Read more
Source§

fn to_latex_string(&self) -> String
where Self: Sized,

Converts a value to a LaTeX math-mode fragment, as a String. Read more
Source§

impl ToTypst for RationalVector

Source§

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

Writes a RationalVector as a Typst math-mode fragment.

The elements’ fragments 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 (\log n)^2 \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the elements.

§Examples
use core::str::FromStr;
use malachite_base::strings::typst::ToTypst;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector {
    elements: vec![Rational::from(1u32), Rational::from(2u32), Rational::from(3u32)],
};
assert_eq!(v.to_typst_string(), "(1, 2, 3)");
assert_eq!(
    RationalVector::from_str("(1/2)").unwrap().to_typst_string(),
    "(frac(1, 2))"
);
assert_eq!(
    RationalVector {
        elements: vec![Rational::from(5u32)]
    }
    .to_typst_string(),
    "(5)"
);
assert_eq!(
    RationalVector {
        elements: Vec::new()
    }
    .to_typst_string(),
    "()"
);

The value column holds each vector as Display writes it.

valuefragment
(1/2)(frac(1, 2))
(1, 2, 3)(1, 2, 3)
(5)(5)
()()
Source§

fn to_typst(&self) -> TypstWrapper<'_, Self>
where Self: Sized,

Converts a value to a Typst math-mode fragment. Read more
Source§

fn to_typst_string(&self) -> String
where Self: Sized,

Converts a value to a Typst math-mode fragment, as a String. Read more
Source§

impl TryFrom<&RationalVector> for IntegerVector

Source§

fn try_from(v: &RationalVector) -> Result<Self, Self::Error>

Converts a RationalVector to an IntegerVector, taking the RationalVector by reference and returning an error if any element is not an integer.

A successful conversion keeps the dimension.

§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 limbs of the elements’ numerators.

§Examples

See here.

Source§

type Error = IntegerVectorFromRationalVectorError

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

impl TryFrom<&RationalVector> for NaturalVector

Source§

fn try_from(v: &RationalVector) -> Result<Self, Self::Error>

Converts a RationalVector to a NaturalVector, taking the RationalVector by reference and returning an error if any element is negative or not an integer.

A successful conversion keeps the dimension.

§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 limbs of the elements’ numerators.

§Examples

See here.

Source§

type Error = NaturalVectorFromRationalVectorError

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

impl<T: PrimitiveUnsigned + for<'a> TryFrom<&'a Rational>> TryFrom<&RationalVector> for UnsignedVector<T>

Source§

fn try_from(v: &RationalVector) -> Result<Self, Self::Error>

Converts a RationalVector to an UnsignedVector, taking the RationalVector by reference and returning an error if any element is negative, not an integer, or too large for T.

No element is ever rounded or wrapped, and no negative element is ever reinterpreted as unsigned. A successful conversion keeps the dimension.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

type Error = UnsignedVectorFromRationalVectorError

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

impl TryFrom<RationalVector> for IntegerVector

Source§

fn try_from(v: RationalVector) -> Result<Self, Self::Error>

Converts a RationalVector to an IntegerVector, taking the RationalVector by value and returning an error if any element is not an integer.

Each element’s numerator limbs are reused rather than copied. A successful conversion keeps the dimension.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

type Error = IntegerVectorFromRationalVectorError

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

impl TryFrom<RationalVector> for NaturalVector

Source§

fn try_from(v: RationalVector) -> Result<Self, Self::Error>

Converts a RationalVector to a NaturalVector, taking the RationalVector by value and returning an error if any element is negative or not an integer.

Each element’s numerator limbs are reused rather than copied. A successful conversion keeps the dimension.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

type Error = NaturalVectorFromRationalVectorError

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

impl<T: PrimitiveUnsigned + for<'a> TryFrom<&'a Rational>> TryFrom<RationalVector> for UnsignedVector<T>

Source§

fn try_from(v: RationalVector) -> Result<Self, Self::Error>

Converts a RationalVector to an UnsignedVector, taking the RationalVector by value and returning an error if any element is negative, not an integer, or too large for T.

Taking the vector by value saves nothing, since the elements are copied into new storage either way; this is here so that a conversion can be written without a borrow.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is v.dimension().

§Examples

See here.

Source§

type Error = UnsignedVectorFromRationalVectorError

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

impl Vector for RationalVector

Source§

fn from_elements(xs: &[Rational]) -> Self

Converts a slice of Rationals to a RationalVector, cloning them.

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 the total number of bits of the elements.

§Examples
use malachite_base::num::basic::traits::{One, Two};
use malachite_base::vector::Vector;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_elements(&[Rational::ONE, Rational::TWO]).to_string(),
    "(1, 2)"
);
assert_eq!(RationalVector::from_elements(&[]).to_string(), "()");
Source§

fn from_owned_elements(xs: Vec<Rational>) -> Self

Converts a Vec of Rationals to a RationalVector, 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::num::basic::traits::{One, Two};
use malachite_base::vector::Vector;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_owned_elements(vec![Rational::ONE, Rational::TWO]).to_string(),
    "(1, 2)"
);
assert_eq!(
    RationalVector::from_owned_elements(Vec::new()).to_string(),
    "()"
);
Source§

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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(RationalVector::zero(3).to_string(), "(0, 0, 0)");
assert_eq!(RationalVector::zero(0).to_string(), "()");

This is equivalent to _fmpq_vec_init from fmpq_vec/init.c, FLINT 3.6.0.

Source§

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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::standard_basis_vector(3, 1).to_string(),
    "(0, 1, 0)"
);
assert_eq!(
    RationalVector::standard_basis_vector(1, 0).to_string(),
    "(1)"
);
Source§

fn push(&mut self, x: Rational)

Appends an element to the end of a RationalVector, 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::vector::Vector;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1, 2)").unwrap();
v.push(Rational::from_unsigneds(1u32, 3));
assert_eq!(v.to_string(), "(1, 2, 1/3)");

let mut v = RationalVector::zero(0);
v.push(Rational::from(5));
assert_eq!(v.to_string(), "(5)");
Source§

fn set_dimension(&mut self, dimension: u64)

Sets the dimension of a RationalVector, 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::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)

Sets every element of a RationalVector 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -2, 3)").unwrap();
v.set_zero();
assert_eq!(v.to_string(), "(0, 0, 0)");

let mut v = RationalVector::from_str("()").unwrap();
v.set_zero();
assert_eq!(v.to_string(), "()");
Source§

fn sort(&mut self)

Sorts the elements of a RationalVector 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

let mut v = RationalVector::from_str("(1/2, -1, 1/3, 0)").unwrap();
v.sort();
assert_eq!(v.to_string(), "(-1, 0, 1/3, 1/2)");

This is equivalent to _fmpq_vec_sort from fmpq_vec/sort.c, FLINT 3.6.0.

Source§

fn to_elements(&self) -> Vec<Rational>

Returns a RationalVector’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 the total number of bits of the elements.

§Examples
use core::str::FromStr;
use malachite_base::strings::ToDebugString;
use malachite_base::vector::Vector;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.to_elements().to_debug_string(), "[1, 2, 3]");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .to_elements()
        .to_debug_string(),
    "[]"
);
Source§

fn into_elements(self) -> Vec<Rational>

Returns a RationalVector’s elements as a Vec, taking ownership of the RationalVector.

Nothing is copied or allocated.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::str::FromStr;
use malachite_base::strings::ToDebugString;
use malachite_base::vector::Vector;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.into_elements().to_debug_string(), "[1, 2, 3]");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .into_elements()
        .to_debug_string(),
    "[]"
);
Source§

fn elements_ref(&self) -> &[Rational]

Returns a reference to a RationalVector’s elements, as a slice.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::str::FromStr;
use malachite_base::strings::ToDebugString;
use malachite_base::vector::Vector;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector::from_str("(1, 2, 3)").unwrap();
assert_eq!(v.elements_ref().to_debug_string(), "[1, 2, 3]");

// A slice of the elements can be taken directly.
let tail = &v.elements_ref()[1..];
assert_eq!(tail.to_debug_string(), "[2, 3]");
assert_eq!(
    RationalVector::from_str("()")
        .unwrap()
        .elements_ref()
        .to_debug_string(),
    "[]"
);
Source§

fn dimension(&self) -> u64

Returns the dimension of a RationalVector: the number of its elements.

§Worst-case complexity

Constant time and additional memory.

§Examples
use malachite_base::vector::Vector;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

let v = RationalVector {
    elements: vec![Rational::from(4u32), Rational::from(5u32)],
};
assert_eq!(v.dimension(), 2);
assert_eq!(
    RationalVector {
        elements: Vec::new()
    }
    .dimension(),
    0
);
Source§

fn pivot(&self) -> Option<&Rational>

Returns the pivot of a RationalVector: 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 reference to 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::vector::Vector;
use malachite_q::Rational;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(0, 0, -3/4, 0, 5)")
        .unwrap()
        .pivot(),
    Some(&Rational::from_signeds(-3, 4))
);
assert_eq!(RationalVector::from_str("(0, 0)").unwrap().pivot(), None);
assert_eq!(RationalVector::from_str("()").unwrap().pivot(), None);
Source§

fn pivot_index(&self) -> Option<u64>

Returns the index of the pivot of a RationalVector: 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(0, 0, -3/4, 0, 5)")
        .unwrap()
        .pivot_index(),
    Some(2)
);
assert_eq!(
    RationalVector::from_str("(0, 0)").unwrap().pivot_index(),
    None
);
assert_eq!(RationalVector::from_str("()").unwrap().pivot_index(), None);
Source§

fn height_index(&self) -> Option<u64>

Returns the index of an element of largest height of a RationalVector: 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -3, 1/4)")
        .unwrap()
        .height_index(),
    Some(2)
);
assert_eq!(
    RationalVector::from_str("(3, -1/3)")
        .unwrap()
        .height_index(),
    Some(0)
);
assert_eq!(RationalVector::from_str("()").unwrap().height_index(), None);
Source§

fn is_zero(&self) -> bool

Determines whether every element of a RationalVector 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert!(RationalVector::from_str("(0, 0)").unwrap().is_zero());
assert!(RationalVector::from_str("()").unwrap().is_zero());
assert!(!RationalVector::from_str("(0, 1, 0)").unwrap().is_zero());
Source§

fn standard_basis_index(&self) -> Option<u64>

Determines whether a RationalVector 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::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(0, 1, 0)")
        .unwrap()
        .standard_basis_index(),
    Some(1)
);
assert_eq!(
    RationalVector::from_str("(0, 1/2, 0)")
        .unwrap()
        .standard_basis_index(),
    None
);
assert_eq!(
    RationalVector::from_str("(1, 0, 1)")
        .unwrap()
        .standard_basis_index(),
    None
);
assert_eq!(
    RationalVector::from_str("(0, 0)")
        .unwrap()
        .standard_basis_index(),
    None
);
Source§

fn max_bits(&self) -> (u64, bool)

Returns the number of significant bits of the height of a RationalVector, together with whether any of its elements is negative.

The bit count is that of the largest of the elements’ heights, $\max(|p|, q)$ for $p/q$ in lowest terms.

§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’ numerators and denominators.

§Examples
use core::str::FromStr;
use malachite_base::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/4, -2)").unwrap().max_bits(),
    (3, true)
);
assert_eq!(
    RationalVector::from_str("()").unwrap().max_bits(),
    (0, false)
);
Source§

fn sum_max_bits(&self) -> (u64, u64)

Returns the number of significant bits of the sum of the absolute values of the elements of a RationalVector (its $\ell^1$ norm), together with the number of significant bits of its height.

The $\ell^1$ norm is a rational number, and, as for a single Rational, its number of significant bits is the sum of those of its numerator and denominator. So a norm of 0, which is $0/1$, has 1 significant bit, even for 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 the total number of bits of the elements’ numerators and denominators.

§Examples
use core::str::FromStr;
use malachite_base::vector::Vector;
use malachite_q::rational_vector::RationalVector;

assert_eq!(
    RationalVector::from_str("(1/2, -1/3)")
        .unwrap()
        .sum_max_bits(),
    (6, 2)
);
assert_eq!(
    RationalVector::from_str("()").unwrap().sum_max_bits(),
    (1, 0)
);
Source§

type Element = Rational

The type of an element.
Source§

type ElementOutput<'a> = &'a Rational where Self: 'a

What pivot returns. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

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

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

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

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

fn to_string(&self) -> String

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

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

Source§

type Error = !

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U